Merge
diff --git a/.hgignore b/.hgignore
index 8fde2ca..156055a 100644
--- a/.hgignore
+++ b/.hgignore
@@ -3,3 +3,4 @@
 /nbproject/private/
 ^webrev
 ^.hgtip
+.DS_Store
diff --git a/.hgtags-top-repo b/.hgtags-top-repo
index 6616236..6b824be 100644
--- a/.hgtags-top-repo
+++ b/.hgtags-top-repo
@@ -150,3 +150,4 @@
 2accafff224ae39caf5f532c305251ba624bf2c0 jdk8-b26
 1533dfab9903e4edcfead3b0192643f38c418b9b jdk8-b27
 6e2541d60f4e342b5b67140271d7611643929dc3 jdk8-b28
+41460de042580bc4a4ce3f863779c66f39cb8578 jdk8-b29
diff --git a/corba/.hgignore b/corba/.hgignore
index 83cef21..e05f093 100644
--- a/corba/.hgignore
+++ b/corba/.hgignore
@@ -2,3 +2,4 @@
 ^dist/
 /nbproject/private/
 ^.hgtip
+.DS_Store
diff --git a/corba/.hgtags b/corba/.hgtags
index 2a83825..ab2db95 100644
--- a/corba/.hgtags
+++ b/corba/.hgtags
@@ -150,3 +150,4 @@
 79f709a099f40c08f76567fa6d813f9009a69826 jdk8-b26
 4fffe75e4edd39a2517f10b743941bf94edb143d jdk8-b27
 2082eb35d49a9c2aab90b8d4fd31cefb7a23b82e jdk8-b28
+6117395d422682f89d228347e319fcaac7edc729 jdk8-b29
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/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/hotspot/.hgtags b/hotspot/.hgtags
index 707d07c..87ad31a 100644
--- a/hotspot/.hgtags
+++ b/hotspot/.hgtags
@@ -228,3 +228,4 @@
 975c4105f1e2ef1190a75b77124033f1fd4290b5 hs24-b01
 b183b0863611b85dbac16f3b08b40ba978756d19 jdk8-b28
 030b5306d60f140e822e4a6d301744cb110ff0c8 hs24-b02
+b45b5c564098c58ea69e7cff3f7d341f0254dd1d jdk8-b29
diff --git a/jaxp/.hgtags b/jaxp/.hgtags
index 92799ab..d16ff46 100644
--- a/jaxp/.hgtags
+++ b/jaxp/.hgtags
@@ -150,3 +150,4 @@
 dbb7283c197b27da1fc12ae8a83785c851b68c12 jdk8-b26
 80c47eb83d24fdd64bbb48f288bd6d4f03e0ec88 jdk8-b27
 f3244c1f04864d35c41fa8d13669faf4f65b81e2 jdk8-b28
+25099a745e1a43579b6af86b3e052b2e50958753 jdk8-b29
diff --git a/jaxws/.hgignore b/jaxws/.hgignore
index 970fc82..36b21b1 100644
--- a/jaxws/.hgignore
+++ b/jaxws/.hgignore
@@ -5,3 +5,4 @@
 ^webrev/
 /nbproject/private/
 ^.hgtip
+.DS_Store
diff --git a/jaxws/.hgtags b/jaxws/.hgtags
index 7bf6ccc..032b2c7 100644
--- a/jaxws/.hgtags
+++ b/jaxws/.hgtags
@@ -150,3 +150,4 @@
 3518639eab6ce5c7b482bdb0a60342c392ab97a8 jdk8-b26
 38c037af4127289de12efc67f45d19bb67abff69 jdk8-b27
 88b85470e72ce48515c802d2158f61cad198b935 jdk8-b28
+4897d9d2d04838e3479745efa238a99bacd939c9 jdk8-b29
diff --git a/jaxws/make/jprt.properties b/jaxws/make/jprt.properties
index 360b6b2..9106433 100644
--- a/jaxws/make/jprt.properties
+++ b/jaxws/make/jprt.properties
@@ -39,6 +39,7 @@
     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}
 
diff --git a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/EnvelopeStyle.java b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/EnvelopeStyle.java
index 84cbd36..5fb538b 100644
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/EnvelopeStyle.java
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/EnvelopeStyle.java
@@ -1,41 +1,26 @@
 /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
  *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
  *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
+ * Please contact 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.sun.xml.internal.org.jvnet.ws;
diff --git a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/EnvelopeStyleFeature.java b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/EnvelopeStyleFeature.java
index 5fadeb1..8e39ef3 100644
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/EnvelopeStyleFeature.java
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/EnvelopeStyleFeature.java
@@ -1,41 +1,26 @@
 /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
  *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
  *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
+ * Please contact 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.sun.xml.internal.org.jvnet.ws;
diff --git a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/Databinding.java b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/Databinding.java
index c7c54af..f1e1c50 100644
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/Databinding.java
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/Databinding.java
@@ -1,41 +1,26 @@
 /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
  *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
  *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
+ * Please contact 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.sun.xml.internal.org.jvnet.ws.databinding;
diff --git a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/DatabindingFactory.java b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/DatabindingFactory.java
index 9f0cdc1..ebfa686 100644
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/DatabindingFactory.java
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/DatabindingFactory.java
@@ -1,41 +1,26 @@
 /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
  *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
  *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
+ * Please contact 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.sun.xml.internal.org.jvnet.ws.databinding;
diff --git a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/DatabindingMode.java b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/DatabindingMode.java
index 80604ec..46d4a96 100644
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/DatabindingMode.java
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/DatabindingMode.java
@@ -1,42 +1,28 @@
 /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
  *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
  *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
+ * Please contact 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.sun.xml.internal.org.jvnet.ws.databinding;
 
 import java.lang.annotation.Retention;
diff --git a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/DatabindingModeFeature.java b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/DatabindingModeFeature.java
index 3cbc012..3bc6491 100644
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/DatabindingModeFeature.java
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/DatabindingModeFeature.java
@@ -1,41 +1,26 @@
 /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
  *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
  *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
+ * Please contact 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.sun.xml.internal.org.jvnet.ws.databinding;
diff --git a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/JavaCallInfo.java b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/JavaCallInfo.java
index a724996..221958b 100644
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/JavaCallInfo.java
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/databinding/JavaCallInfo.java
@@ -1,41 +1,26 @@
 /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
  *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
  *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
+ * Please contact 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.sun.xml.internal.org.jvnet.ws.databinding;
diff --git a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/ContentType.java b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/ContentType.java
index e3b0587..635705a 100644
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/ContentType.java
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/ContentType.java
@@ -1,41 +1,26 @@
 /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
  *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
  *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
+ * Please contact 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.sun.xml.internal.org.jvnet.ws.message;
diff --git a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/DistributedPropertySet.java b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/DistributedPropertySet.java
index 3970578..c44c7da 100644
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/DistributedPropertySet.java
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/DistributedPropertySet.java
@@ -1,41 +1,26 @@
 /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
  *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
  *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
+ * Please contact 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.sun.xml.internal.org.jvnet.ws.message;
diff --git a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/MessageContext.java b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/MessageContext.java
index 5369d48..0671455 100644
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/MessageContext.java
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/MessageContext.java
@@ -1,41 +1,26 @@
 /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
  *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
  *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
+ * Please contact 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.sun.xml.internal.org.jvnet.ws.message;
diff --git a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/MessageContextFactory.java b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/MessageContextFactory.java
index d61e730..de13129 100644
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/MessageContextFactory.java
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/MessageContextFactory.java
@@ -1,3 +1,28 @@
+/*
+ * 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.
+ */
+
 package com.sun.xml.internal.org.jvnet.ws.message;
 
 import java.io.IOException;
diff --git a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/PropertySet.java b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/PropertySet.java
index 9dc7682..179aaec 100644
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/PropertySet.java
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/ws/message/PropertySet.java
@@ -1,41 +1,26 @@
 /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
  *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
  *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
+ * Please contact 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.sun.xml.internal.org.jvnet.ws.message;
diff --git a/jdk/.hgignore b/jdk/.hgignore
index 67c8465..e849b9e 100644
--- a/jdk/.hgignore
+++ b/jdk/.hgignore
@@ -4,3 +4,4 @@
 ^make/netbeans/.*/build/
 ^make/netbeans/.*/dist/
 ^.hgtip
+.DS_Store
diff --git a/jdk/.hgtags b/jdk/.hgtags
index 45d75f7..d73a2f1 100644
--- a/jdk/.hgtags
+++ b/jdk/.hgtags
@@ -150,3 +150,4 @@
 5aca406e87cb9144a9405be312dadd728a9c6fe2 jdk8-b26
 c68342532e2e7deb3a25fc04ed3e4c142278f747 jdk8-b27
 1e1d41daaded291ab3a370ca6a27f7325701978e jdk8-b28
+c5b882dce0fe27e05dc64debc92b1fb9ebf880ec jdk8-b29
diff --git a/jdk/make/Makefile b/jdk/make/Makefile
index fd39aa4..ce89b45 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
 
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..c336c61
--- /dev/null
+++ b/jdk/make/com/apple/Makefile
@@ -0,0 +1,39 @@
+#
+# 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
+
+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..63d78d2
--- /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 \
+    -lawt_lwawt -L$(LIBDIR) -Xlinker -rpath -Xlinker @loader_path \
+    -framework Cocoa \
+    -framework Carbon \
+    -framework ApplicationServices \
+    -framework JavaNativeFoundation \
+    -framework JavaRuntimeSupport
diff --git a/jdk/make/com/sun/java/pack/Makefile b/jdk/make/com/sun/java/pack/Makefile
index e9cce3c..e97ac51 100644
--- a/jdk/make/com/sun/java/pack/Makefile
+++ b/jdk/make/com/sun/java/pack/Makefile
@@ -59,6 +59,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) \
@@ -75,6 +76,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 b3a20f0..ebca563 100644
--- a/jdk/make/com/sun/nio/Makefile
+++ b/jdk/make/com/sun/nio/Makefile
@@ -32,9 +32,13 @@
 SUBDIRS_MAKEFLAGS += JAVAC_WARNINGS_FATAL=true
 include $(BUILDDIR)/common/Defs.gmk
 
-SUBDIRS = sctp
 include $(BUILDDIR)/common/Subdirs.gmk
 
+ifneq ($(PLATFORM), macosx)
+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 2f6aaba..e695712 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 e5b455c..1f12824 100644
--- a/jdk/make/com/sun/tools/attach/Makefile
+++ b/jdk/make/com/sun/tools/attach/Makefile
@@ -39,6 +39,9 @@
 ifeq ($(PLATFORM), linux)
 FILES_m = mapfile-linux
 endif
+ifeq ($(PLATFORM), macosx)
+FILES_m = mapfile-bsd 
+endif
 include $(BUILDDIR)/common/Mapfile-vers.gmk
 
 #
@@ -55,7 +58,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-linux.gmk b/jdk/make/common/Defs-linux.gmk
index 026b180..499bcff 100644
--- a/jdk/make/common/Defs-linux.gmk
+++ b/jdk/make/common/Defs-linux.gmk
@@ -374,6 +374,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..d6b8307
--- /dev/null
+++ b/jdk/make/common/Defs-macosx.gmk
@@ -0,0 +1,402 @@
+#
+# 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
+
+PLATFORM_SRC_MACOS = $(BUILDDIR)/../src/macosx
+
+# 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 aae6929..9826b61 100644
--- a/jdk/make/common/Defs-solaris.gmk
+++ b/jdk/make/common/Defs-solaris.gmk
@@ -713,6 +713,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 7b8dfce..e92eed9 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
@@ -259,6 +270,10 @@
     LDLIBS_COMMON = -ldl
   endif
 
+  ifeq ($(PLATFORM), macosx)
+    LDLIBS_COMMON = -pthread
+  endif
+
 endif # PROGRAM
 
 LDLIBS_COMMON += $(EXTRA_LIBS)
@@ -399,7 +414,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 6c9b979..e952bb5 100644
--- a/jdk/make/common/Library.gmk
+++ b/jdk/make/common/Library.gmk
@@ -58,6 +58,14 @@
 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))))
+
+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 +225,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..8170453 100644
--- a/jdk/make/common/Program.gmk
+++ b/jdk/make/common/Program.gmk
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -38,12 +38,18 @@
   override COMPILE_APPROACH = normal
 endif
 
-ifndef LAUNCHER_PLATFORM_SRC
-LAUNCHER_PLATFORM_SRC = $(PLATFORM_SRC)
+# set the platform specific directory for macosx, also this platform shares
+# substantial family ties with its siblings (solaris and linux), thus we add
+# solaris src path to its compilation dependencies.
+ifeq ($(PLATFORM), macosx)
+  LAUNCHER_PLATFORM_SRC = $(BUILDDIR)/../src/macosx
+  LAUNCHER_SOLARIS_PLATFORM_SRC  = $(BUILDDIR)/../src/solaris
+else
+  LAUNCHER_PLATFORM_SRC = $(PLATFORM_SRC)
 endif
 
 ifndef LAUNCHER_SHARE_SRC
-LAUNCHER_SHARE_SRC = $(SHARE_SRC)
+  LAUNCHER_SHARE_SRC = $(SHARE_SRC)
 endif
 
 ACTUAL_PROGRAM_NAME = $(PROGRAM)$(EXE_SUFFIX)
@@ -66,7 +72,7 @@
 include $(JDK_TOPDIR)/make/common/Rules.gmk
 
 ifdef NEVER_ACT_AS_SERVER_CLASS_MACHINE
-OTHER_CPPFLAGS += -DNEVER_ACT_AS_SERVER_CLASS_MACHINE
+  OTHER_CPPFLAGS += -DNEVER_ACT_AS_SERVER_CLASS_MACHINE
 endif
 
 #
@@ -78,40 +84,51 @@
 # On Windows, this is done by using the same directory as the executable
 # itself, as with all the Windows libraries.
 #
-ifneq (,$(findstring $(PLATFORM), linux solaris))	# UNIX systems
-    LDFLAGS += -L $(LIBDIR)/$(LIBARCH)/jli
-    OTHER_LDLIBS += -ljli
-    ifeq ($(PLATFORM), solaris)
-	ifeq ($(ARCH_DATA_MODEL), 32)
-		LDFLAGS += -R \$$ORIGIN/../lib/$(LIBARCH)/jli
-		LDFLAGS += -R \$$ORIGIN/../jre/lib/$(LIBARCH)/jli
-	else
-		LDFLAGS += -R \$$ORIGIN/../../lib/$(LIBARCH)/jli
-		LDFLAGS += -R \$$ORIGIN/../../jre/lib/$(LIBARCH)/jli
-	endif
-    endif
-    ifeq ($(PLATFORM), linux)
-	LDFLAGS += $(LDFLAG_Z_ORIGIN)
-	LDFLAGS += -Wl,--allow-shlib-undefined
-	LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../lib/$(LIBARCH)/jli
-	LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../jre/lib/$(LIBARCH)/jli
-    endif
+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
+  ifeq ($(PLATFORM), solaris)
+    ifeq ($(ARCH_DATA_MODEL), 32)
+      LDFLAGS += -R \$$ORIGIN/../lib/$(LIBARCH)/jli
+      LDFLAGS += -R \$$ORIGIN/../jre/lib/$(LIBARCH)/jli
+    else
+      LDFLAGS += -R \$$ORIGIN/../../lib/$(LIBARCH)/jli
+      LDFLAGS += -R \$$ORIGIN/../../jre/lib/$(LIBARCH)/jli
+    endif
+  endif
+  ifeq ($(PLATFORM), linux)
+    LDFLAGS += $(LDFLAG_Z_ORIGIN)
+    LDFLAGS += -Wl,--allow-shlib-undefined
+    LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../lib/$(LIBARCH)/jli
+    LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../jre/lib/$(LIBARCH)/jli
+  endif
+endif
+
 ifeq ($(PLATFORM), windows)
-	JLI_LCF = $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/jli.lcf
-	ifdef STATIC_JLI
-	    LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static
-	else
-	    LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)
-	endif
-	OTHER_LDLIBS += jli.lib
+  JLI_LCF = $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/jli.lcf
+  ifdef STATIC_JLI
+    LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static
+  else
+    LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)
+  endif
+  OTHER_LDLIBS += jli.lib
 endif
 
 #
 # Launcher specific files.
 #
-FILES_o = \
-	$(OBJDIR)/main.$(OBJECT_SUFFIX)
+FILES_o = $(OBJDIR)/main.$(OBJECT_SUFFIX)
 
 $(ACTUAL_PROGRAM):: classes $(INIT) 
 
@@ -119,19 +136,18 @@
 # Windows only
 #
 ifeq ($(PLATFORM), windows)
+  # JDK name required here
+  RC_FLAGS += /D "JDK_FNAME=$(PROGRAM)$(EXE_SUFFIX)" \
+              /D "JDK_INTERNAL_NAME=$(PROGRAM)" \
+              /D "JDK_FTYPE=0x1L"
 
-# JDK name required here
-RC_FLAGS += /D "JDK_FNAME=$(PROGRAM)$(EXE_SUFFIX)" \
-	    /D "JDK_INTERNAL_NAME=$(PROGRAM)" \
-	    /D "JDK_FTYPE=0x1L"
-
-$(OBJDIR)/$(PROGRAM).res: $(VERSIONINFO_RESOURCE)
+  $(OBJDIR)/$(PROGRAM).res: $(VERSIONINFO_RESOURCE)
 	@$(prep-target)
-ifndef LOCAL_RESOURCE_FILE
+  ifndef LOCAL_RESOURCE_FILE
 	$(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(@) $(VERSIONINFO_RESOURCE)
-endif
+  endif
 
-$(OBJDIR)/$(PROGRAM).lcf: $(OBJDIR)/$(PROGRAM).res $(FILES_o)
+  $(OBJDIR)/$(PROGRAM).lcf: $(OBJDIR)/$(PROGRAM).res $(FILES_o)
 	@$(prep-target)
 	@$(ECHO) $(FILES_o) > $@ 
   ifndef LOCAL_RESOURCE_FILE
@@ -140,61 +156,78 @@
 	@$(ECHO) setargv.obj >> $@
 	@$(ECHO) Created $@ 
 
-$(ACTUAL_PROGRAM):: $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX)
+  $(ACTUAL_PROGRAM):: $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX)
 	@$(install-file)
 
-ifeq ($(ARCH_DATA_MODEL), 32)
-  STACK_SIZE=327680
-else
-# We need more Stack for Windows 64bit
-  STACK_SIZE=1048576
-endif
+  ifeq ($(ARCH_DATA_MODEL), 32)
+    STACK_SIZE=327680
+  else
+    # We need more Stack for Windows 64bit
+    STACK_SIZE=1048576
+  endif
 
-IMVERSION=$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VER).$(COOKED_BUILD_NUMBER)
-$(OBJDIR)/$(PROGRAM).exe.manifest: $(JDK_TOPDIR)/src/windows/resource/java.manifest
+  IMVERSION=$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VER).$(COOKED_BUILD_NUMBER)
+  $(OBJDIR)/$(PROGRAM).exe.manifest: $(JDK_TOPDIR)/src/windows/resource/java.manifest
 	@$(prep-target)
 	$(SED) 's%IMVERSION%$(IMVERSION)%g;s%PROGRAM%$(PROGRAM)%g' $< > $@
 
-# We used a hand-crafted manifest file for all executables.
-# It is tweaked to embed the build number and executable name.
-# Use ";#2" for .dll and ";#1" for .exe in the MT command below:
-$(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX):: $(OBJDIR)/$(PROGRAM).lcf $(FILES_o) $(JLI_LCF) $(OBJDIR)/$(PROGRAM).exe.manifest
+  # We used a hand-crafted manifest file for all executables.
+  # It is tweaked to embed the build number and executable name.
+  # Use ";#2" for .dll and ";#1" for .exe in the MT command below:
+  $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX):: $(OBJDIR)/$(PROGRAM).lcf $(FILES_o) $(JLI_LCF) $(OBJDIR)/$(PROGRAM).exe.manifest
 	@$(prep-target)
 	@set -- $?; \
 	    $(ECHO) Rebuilding $@ because of $$1 $$2 $$3 $$4 $$5 $$6 $${7:+...};
 	$(LINK) -out:$@ /STACK:$(STACK_SIZE) \
 	    -map:$(OBJDIR)/$(PROGRAM).map $(LFLAGS) $(LDFLAGS) \
 	    @$(OBJDIR)/$(PROGRAM).lcf $(LDLIBS)
-ifdef MT
+  ifdef MT
 	$(MT) /manifest $(OBJDIR)/$(PROGRAM).exe.manifest /outputresource:$@;#1
-endif
+  endif
 	@$(call binary_file_verification,$@)
+else
+  #
+  # Note that we have to link -lthread even when USE_PTHREADS is true.
+  # This is becuase checkForCorrectLibthread() croaks otherwise.
+  #
+  LIBTHREAD = -lthread
+  ifeq ($(USE_PTHREADS),true)
+    THREADLIBS = -lpthread $(LIBTHREAD)
+  else
+    THREADLIBS = $(LIBTHREAD)
+  endif
 
-else # PLATFORM
+  ifeq ($(PLATFORM), macosx)
+    THREADLIBS = -pthread
+    # Needed for linking the various launchers
+    LDFLAGS += -framework Cocoa -framework Security \
+               -framework ApplicationServices
+    OTHER_CPPFLAGS += -DPACKAGE_PATH='"$(PACKAGE_PATH)"'
 
-#
-# Note that we have to link -lthread even when USE_PTHREADS is true.
-# This is becuase checkForCorrectLibthread() croaks otherwise.
-#
-LIBTHREAD = -lthread
-ifeq ($(USE_PTHREADS),true)
-  THREADLIBS = -lpthread $(LIBTHREAD)
-else # USE_PTHREADS
-  THREADLIBS = $(LIBTHREAD)
-endif # USE_PTHREADS
+    # 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 
+    INFO_PLIST_FILE=
+  endif
 
-#
-# This rule only applies on unix.  It supports quantify and its ilk.
-#
-$(ACTUAL_PROGRAM):: $(FILES_o)
+  #
+  # This rule only applies on unix.  It supports quantify and its ilk.
+  #
+  $(ACTUAL_PROGRAM):: $(FILES_o)
 	@$(prep-target)
 	@set -- $?; \
-	    $(ECHO) Rebuilding $@ because of $$1 $$2 $$3 $$4 $$5 $$6 $${7:+...};
+	$(ECHO) Rebuilding $@ because of $$1 $$2 $$3 $$4 $$5 $$6 $${7:+...};
 	@$(MKDIR) -p $(TEMPDIR)
 	$(LINK_PRE_CMD) $(CC) $(CC_OBJECT_OUTPUT_FLAG)$@ $(LDFLAGS) \
-	    $(FILES_o) $(THREADLIBS) $(LDLIBS)
+	$(FILES_o) $(THREADLIBS) $(LDLIBS)
+  ifeq ($(findstring privileged, $(INFO_PLIST_FILE)), privileged)
+	-codesign -s openjdk_codesign $@
+  endif
 	@$(call binary_file_verification,$@)
-
 endif # PLATFORM
 
 clean:: 
@@ -218,42 +251,49 @@
 # Now include make dependencies (created during compilation, see Rules.gmk)
 #
 ifeq ($(INCREMENTAL_BUILD),true)
-# Workaround: gnumake sometimes says files is empty when it shouldn't
-#    was:  files := $(foreach file, $(wildcard */$(ARCH)/*.$(DEPEND_SUFFIX)), $(file))
-files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null)
-ifneq ($(strip $(files)),)
-include $(files)
-endif # files
-endif # INCREMENTAL_BUILD
+  # Workaround: gnumake sometimes says files is empty when it shouldn't
+  #    was:  files := $(foreach file, $(wildcard */$(ARCH)/*.$(DEPEND_SUFFIX)), $(file))
+  files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null)
+  ifneq ($(strip $(files)),)
+    include $(files)
+  endif
+endif
 
 ifdef JAVA_ARGS
-OTHER_CPPFLAGS += -DJAVA_ARGS='$(JAVA_ARGS)'
-OTHER_CPPFLAGS += -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"'
+  OTHER_CPPFLAGS += -DJAVA_ARGS='$(JAVA_ARGS)'
+  OTHER_CPPFLAGS += -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"'
 endif
 
 ifeq ($(PLATFORM), windows)
-ifdef RELEASE
-OTHER_CPPFLAGS += -DVERSION='"$(RELEASE)"'
-endif
+  ifdef RELEASE
+    OTHER_CPPFLAGS += -DVERSION='"$(RELEASE)"'
+  endif
 endif
 
 
 ifneq ($(PLATFORM), windows)
-HAVE_GETHRTIME=true
+  HAVE_GETHRTIME=true
 endif
 
 ifeq ($(HAVE_GETHRTIME),true)
-OTHER_CPPFLAGS += -DHAVE_GETHRTIME
+  OTHER_CPPFLAGS += -DHAVE_GETHRTIME
 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)
+  OTHER_INCLUDES += -I$(LAUNCHER_SOLARIS_PLATFORM_SRC)/bin
+  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)"'
+OTHER_CPPFLAGS  += -DPROGNAME='"$(PROGRAM)"'
 VERSION_DEFINES += -DFULL_VERSION='"$(FULL_VERSION)"'
 
 VERSION_DEFINES += -DJDK_MAJOR_VERSION='"$(JDK_MAJOR_VERSION)"' \
-		   -DJDK_MINOR_VERSION='"$(JDK_MINOR_VERSION)"'
+                   -DJDK_MINOR_VERSION='"$(JDK_MINOR_VERSION)"'
 
 
 
diff --git a/jdk/make/common/Release-macosx.gmk b/jdk/make/common/Release-macosx.gmk
new file mode 100644
index 0000000..9235afa
--- /dev/null
+++ b/jdk/make/common/Release-macosx.gmk
@@ -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.
+#
+
+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 $(JDK_MINOR_VERSION)
+BUNDLE_NAME_JRE ?= $(BUNDLE_NAME)
+BUNDLE_NAME_JDK ?= $(BUNDLE_NAME)
+
+BUNDLE_INFO ?= OpenJDK ($(JDK_VERSION))
+BUNDLE_INFO_JRE ?= $(BUNDLE_INFO)
+BUNDLE_INFO_JDK ?= $(BUNDLE_INFO)
+
+BUNDLE_PLATFORM_VERSION ?= $(JDK_MAJOR_VERSION).$(JDK_MINOR_VERSION)
+BUNDLE_VERSION ?= $(JDK_VERSION)
+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/
+	$(CP) -r $(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)/../
+
+jdk-bundle-files:
+	$(MKDIR) -p $(JDK_BUNDLE_DIR)/MacOS
+	ln -s ../Home/jre/lib/jli/libjli.dylib $(JDK_BUNDLE_DIR)/MacOS/
+	$(CP) -r $(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)/../
+
+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 be0a450..c7f55e3 100644
--- a/jdk/make/common/Release.gmk
+++ b/jdk/make/common/Release.gmk
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -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
@@ -230,11 +234,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
+	 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
@@ -810,6 +825,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
 ifeq ($(PLATFORM), windows)
 	@# Remove certain *.lib files
 	$(CD) $(JRE_IMAGE_DIR)/lib && \
@@ -946,12 +965,20 @@
           ($(CD) $(JDK_IMAGE_DIR)/db && $(UNZIP) -o $$d); \
 	done
 	$(CP) $(ABS_DB_PATH)/README-JDK.html $(JDK_IMAGE_DIR)/db
+ifndef NO_DEMOS
 	$(RM) -rf $(DEMODIR)/db
 	$(MV) $(JDK_IMAGE_DIR)/db/demo $(DEMODIR)/db
 	$(CP) $(ABS_DB_PATH)/README-JDK-DEMOS.html $(DEMODIR)/db/
+else
+	$(RM) -rf $(JDK_IMAGE_DIR)/db/demo
+endif
 	$(RM) $(JDK_IMAGE_DIR)/db/index.html $(JDK_IMAGE_DIR)/db/register.html
 endif
 
+# The launcher source files we need for src.zip
+FILES_launcher = $(wildcard $(SHARE_SRC)/bin/*) \
+                 $(wildcard $(PLATFORM_SRC)/bin/java_md*)
+
 # Standard jdk image
 initial-image-jdk:: initial-image-jdk-setup \
 		    initial-image-jdk-db \
@@ -1038,7 +1065,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 &&  \
@@ -1076,20 +1104,7 @@
 	$(RM) $(ABS_TEMPDIR)/src-files.list
 	$(CHMOD) -R +w $(JDK_IMAGE_DIR)/src
 	$(MKDIR) -p $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/java.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/java.h $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/manifest_info.h $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/parse_manifest.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/version_comp.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/version_comp.h $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/wildcard.h $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/wildcard.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/jli_util.h $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/jli_util.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/splashscreen_stubs.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/splashscreen.h $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(PLATFORM_SRC)/bin/java_md.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(PLATFORM_SRC)/bin/java_md.h $(JDK_IMAGE_DIR)/src/launcher
+	$(CP) $(FILES_launcher) $(JDK_IMAGE_DIR)/src/launcher
 	$(CD) $(JDK_IMAGE_DIR)/src && $(ZIPEXE) -qr ../src.zip *
 	$(RM) -r $(JDK_IMAGE_DIR)/src
 	@#
diff --git a/jdk/make/common/Rules.gmk b/jdk/make/common/Rules.gmk
index 65eda67..6da2f50 100644
--- a/jdk/make/common/Rules.gmk
+++ b/jdk/make/common/Rules.gmk
@@ -51,12 +51,22 @@
 #
 # 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
+    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 +210,14 @@
 
 $(CLASSDESTDIR)/%.class: $(GENSRCDIR)/%.java
 	@$(add-java-file)
+
+ifeq ($(PLATFORM), macosx)
+$(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-gcc.gmk b/jdk/make/common/shared/Compiler-gcc.gmk
index 092ec16..9dde0ba 100644
--- a/jdk/make/common/shared/Compiler-gcc.gmk
+++ b/jdk/make/common/shared/Compiler-gcc.gmk
@@ -67,7 +67,7 @@
     CXX            = $(COMPILER_PATH)g++
   endif
   # Option used to create a shared library
-  SHARED_LIBRARY_FLAG = -shared -mimpure-text
+  SHARED_LIBRARY_FLAG = -shared
   SUN_COMP_VER := $(shell $(CC) --verbose 2>&1 )
 
 endif
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 d98a87c..5002c28 100644
--- a/jdk/make/common/shared/Defs-java.gmk
+++ b/jdk/make/common/shared/Defs-java.gmk
@@ -66,7 +66,11 @@
    -XX:-PrintVMOptions -XX:+UnlockDiagnosticVMOptions -XX:-LogVMOutput
 
 # JVM options
-JAVA_JVM_FLAGS = $(JAVA_HOTSPOT_DISABLE_PRINT_VMOPTIONS)
+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 01aa7ee..fba7037 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 5c2f6ad..5923df3 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 a64c2b4..618fa0b 100644
--- a/jdk/make/common/shared/Platform.gmk
+++ b/jdk/make/common/shared/Platform.gmk
@@ -224,6 +224,85 @@
   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)
+#     ifdef OPENJDK -- when universal 32/64 binaries available in Hotspot
+#        mach := universal
+#     else
+        mach := x86_64
+#     endif
+   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 \
+                    ;; \
+                universal) \
+                    echo universal \
+                    ;; \
+                "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 +504,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 0891706..b9f4d2b 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 a4247e5..fcb461a 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 = 612
 endif
diff --git a/jdk/make/docs/NON_CORE_PKGS.gmk b/jdk/make/docs/NON_CORE_PKGS.gmk
index 8f4e36d..b68208b 100644
--- a/jdk/make/docs/NON_CORE_PKGS.gmk
+++ b/jdk/make/docs/NON_CORE_PKGS.gmk
@@ -83,6 +83,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) \
@@ -92,5 +99,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/fdlibm/Makefile b/jdk/make/java/fdlibm/Makefile
index 39346de..36a9611 100644
--- a/jdk/make/java/fdlibm/Makefile
+++ b/jdk/make/java/fdlibm/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -60,6 +60,12 @@
   FASTDEBUG_OPTIMIZATION_LEVEL = NONE
 endif
 
+ifeq ($(PLATFORM),macosx)
+  # Turn all optimizations off
+  OPTIMIZATION_LEVEL = NONE
+  FASTDEBUG_OPTIMIZATION_LEVEL = NONE
+endif
+
 #
 # Include path.
 #
diff --git a/jdk/make/java/instrument/Makefile b/jdk/make/java/instrument/Makefile
index 115d104..76a0553 100644
--- a/jdk/make/java/instrument/Makefile
+++ b/jdk/make/java/instrument/Makefile
@@ -105,6 +105,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 
@@ -117,6 +127,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 73aa81d..373f35b 100644
--- a/jdk/make/java/java/Makefile
+++ b/jdk/make/java/java/Makefile
@@ -97,6 +97,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'
 #
@@ -168,8 +177,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
@@ -208,8 +219,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
 
 #
@@ -246,8 +263,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..e6c0c5f 100644
--- a/jdk/make/java/java/localegen.sh
+++ b/jdk/make/java/java/localegen.sh
@@ -55,9 +55,9 @@
 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..1bc98d6 100644
--- a/jdk/make/java/jli/Makefile
+++ b/jdk/make/java/jli/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
 # 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,92 +44,121 @@
 
 include $(BUILDDIR)/common/Defs.gmk
 
-ZIP_SRC = $(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
+ifneq ($(SYSTEM_ZLIB),true)
+  ZIP_SRC = $(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
+endif #SYSTEM_ZLIB
 LAUNCHER_SHARE_SRC = $(SHARE_SRC)/bin
-LAUNCHER_PLATFORM_SRC = $(PLATFORM_SRC)/bin
+
+# set the platform specific directory for macosx, also this platform shares
+# substantial family ties with its siblings (solaris and linux), thus we add
+# solaris src path to its compilation dependencies.
+ifeq ($(PLATFORM), macosx)
+ LAUNCHER_PLATFORM_SRC = $(BUILDDIR)/../src/macosx/bin
+ LAUNCHER_SOLARIS_PLATFORM_SRC  = $(BUILDDIR)/../src/solaris/bin
+else # !MACOSX
+ LAUNCHER_PLATFORM_SRC = $(PLATFORM_SRC)/bin
+endif #PLATFORM
 
 ifeq ($(ZERO_BUILD), true)
-ERGO_FAMILY=zero
-else
-ifeq ($(ARCH_FAMILY), amd64)
-ERGO_FAMILY=i586
-else
-ERGO_FAMILY=$(ARCH_FAMILY)
-endif
-endif
-
+  ERGO_FAMILY=zero
+else # !ZERO_BUILD
+  ifneq (,$(findstring $(ARCH_FAMILY), amd64 x86_64))
+    ERGO_FAMILY=i586
+  else # !X86 FAMILY
+    ERGO_FAMILY=$(ARCH_FAMILY)
+  endif #ARCH_FAMILY
+endif # ZERO_BUILD
 
 #
 # Files to compile.
 #
-FILES_c = \
-	java.c \
-	splashscreen_stubs.c \
-	java_md.c \
-	parse_manifest.c \
-	version_comp.c \
-	wildcard.c \
-	jli_util.c \
-	inflate.c \
-	inftrees.c \
-	inffast.c \
-	zadler32.c \
-	zcrc32.c \
-	zutil.c
+FILES_c = java.c \
+          splashscreen_stubs.c \
+          parse_manifest.c \
+          version_comp.c \
+          wildcard.c \
+          jli_util.c
 
-ifneq ($(PLATFORM), windows)
-  FILES_c += ergo.c 
-  ERGO_ARCH_FILE = ergo_$(ERGO_FAMILY).c
-  # if the architecture specific ergo file exists then
-  # use it, else use the generic definitions from ergo.c
-  ifneq ($(wildcard $(LAUNCHER_PLATFORM_SRC)/$(ERGO_ARCH_FILE)),)
-    FILES_c += $(ERGO_ARCH_FILE)
-  else
-    OTHER_CPPFLAGS += -DUSE_GENERIC_ERGO
-  endif
-endif
+ifneq ($(SYSTEM_ZLIB),true)
+  FILES_c += inflate.c \
+             inftrees.c \
+             inffast.c \
+             zadler32.c \
+             zcrc32.c \
+             zutil.c
+endif # SYSTEM_ZLIB
+
+# add platform specific files
+ifeq ($(PLATFORM), windows)
+  FILES_c += java_md.c
+else # NIXES
+  FILES_c += java_md_common.c
+  ifeq ($(PLATFORM), macosx)
+    FILES_c += java_md_macosx.c
+  else # SOLARIS/LINUX
+    FILES_c += java_md_solinux.c
+    FILES_c += ergo.c 
+    ERGO_ARCH_FILE = ergo_$(ERGO_FAMILY).c
+    # if the architecture specific ergo file exists then
+    # use it, else use the generic definitions from ergo.c
+    ifneq ($(wildcard $(LAUNCHER_PLATFORM_SRC)/$(ERGO_ARCH_FILE)),)
+      FILES_c += $(ERGO_ARCH_FILE)
+    else # !ERGO_ARCH_FILE
+      OTHER_CPPFLAGS += -DUSE_GENERIC_ERGO
+    endif # ERGO_ARCH_FILE
+  endif #MACOSX
+endif #WINDOWS
 
 # Names of arch directories
 LIBARCH_DEFINES = -DLIBARCHNAME='"$(LIBARCH)"'
 ifeq ($(PLATFORM), solaris)
   LIBARCH_DEFINES += -DLIBARCH32NAME='"$(LIBARCH32)"'
   LIBARCH_DEFINES += -DLIBARCH64NAME='"$(LIBARCH64)"'
-endif
+endif # PLATFORM
 
-OTHER_CPPFLAGS += $(LIBARCH_DEFINES)
-
+ifeq ($(PLATFORM), macosx)
+  OTHER_CPPFLAGS += $(LIBARCH_DEFINES) -DPACKAGE_PATH=\"$(PACKAGE_PATH)\"
+else # ! MACOSX
+  OTHER_CPPFLAGS += $(LIBARCH_DEFINES)
+endif #PLATFORM
 
 ifneq ($(PLATFORM), windows)	# UNIX systems
-        LD_RUNPATH_EXTRAS += ..
-	LIB_LOCATION = $(LIBDIR)/$(LIBARCH)/jli
-	# Note: its important to keep this order meaning -lc is the
-	# last library otherwise it could cause compatibility issues
-	# by pulling in SUNW_private symbols from libc
-	LDLIBS = -ldl -lc
-ifeq ($(USE_PTHREADS),true)
-	LDLIBS += -lpthread
-endif # USE_PTHREADS 
+  ifeq ($(PLATFORM), macosx)
+    LIB_LOCATION = $(LIBDIR)/jli
+  else # SOLARIS/LINUX
+    LD_RUNPATH_EXTRAS += ..
+    LIB_LOCATION = $(LIBDIR)/$(LIBARCH)/jli
+    # Note: it is important to keep this order, meaning -lc as the
+    # last library, otherwise it could cause compatibility issues
+    # by pulling in SUNW_private symbols from libc
+    LDLIBS = -ldl -lc
+    ifeq ($(USE_PTHREADS),true)
+      LDLIBS += -lpthread
+    endif # USE_PTHREADS 
+  endif # PLATFORM
 endif # PLATFORM
 
 ifeq ($(PLATFORM), windows)
-	EXTRA_LIBS = advapi32.lib \
-		     comctl32.lib \
-		     user32.lib
-
-	JAVALIB =
-	OTHER_LCF =  -export:JLI_Launch \
-		     -export:JLI_ManifestIterate \
-		     -export:JLI_SetTraceLauncher \
-		     -export:JLI_ReportErrorMessage \
-		     -export:JLI_ReportErrorMessageSys \
-		     -export:JLI_ReportMessage \
-		     -export:JLI_ReportExceptionDescription
-
-endif
+  EXTRA_LIBS = advapi32.lib \
+               comctl32.lib \
+               user32.lib
+  JAVALIB =
+  OTHER_LCF = -export:JLI_Launch \
+              -export:JLI_ManifestIterate \
+              -export:JLI_SetTraceLauncher \
+              -export:JLI_ReportErrorMessage \
+              -export:JLI_ReportErrorMessageSys \
+              -export:JLI_ReportMessage \
+              -export:JLI_ReportExceptionDescription
+endif # PLATFORM
 
 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 # !SYSTEM_ZLIB
+  LDLIBS += -lz
+endif # SYSTEM_ZLIB
 
 #
 # Library to compile.
@@ -150,18 +179,52 @@
 # library.
 #
 ifeq ($(PLATFORM), windows)
+  STATIC_LIBRARY = $(OBJDIR)/static/$(LIBPREFIX)$(LIBRARY).lib
 
-STATIC_LIBRARY = $(OBJDIR)/static/$(LIBPREFIX)$(LIBRARY).lib
-
-$(STATIC_LIBRARY): $(FILES_o)
+  $(STATIC_LIBRARY): $(FILES_o)
 	@$(prep-target)
 	$(LIBEXE) -nologo -out:$@ $(FILES_o)
 
+  library:: $(STATIC_LIBRARY)
+endif # PLATFORM
+
+ifeq ($(PLATFORM), macosx)
+  # Some Obj-C code is embedded in java_md_macosx.c, we stipulate so, using
+  # "-x" option. Not doing so will cause the compiler to choose the language
+  # based on the filename suffix, also "-Os" optimizes the file for size.
+  CFLAGS_$(VARIANT)/java_md_macosx.o = -Os -x objective-c
+  # Needed for linking the various launchers
+  LDFLAGS += -framework Cocoa -framework Security \
+             -framework ApplicationServices
+  # Add solaris sources containing common logic to the header path
+  OTHER_INCLUDES += -I$(LAUNCHER_SOLARIS_PLATFORM_SRC)
+endif # PLATFORM
+
+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)
 
-endif	# PLATFORM
-
-#
-# Add to ambient vpath so we pick up the library files
-#
-vpath %.c $(LAUNCHER_SHARE_SRC) $(ZIP_SRC) $(LAUNCHER_PLATFORM_SRC)
+vpath %.c $(LAUNCHER_SHARE_SRC) $(LAUNCHER_PLATFORM_SRC)
+ifneq ($(SYSTEM_ZLIB),true)
+  vpath %.c $(ZIP_SRC)
+else # !SYSTEM_ZLIB
+  #
+  # Add to ambient vpath so we pick up the library files, for macos we add 
+  # solaris sources which contains the common logic for all nixes
+  #
+  ifeq ($(PLATFORM), macosx)
+    vpath %.c $(LAUNCHER_SHARE_SRC) $(ZIP_SRC) $(LAUNCHER_PLATFORM_SRC) \
+          $(LAUNCHER_SOLARIS_PLATFORM_SRC)
+  else # !MACOSX
+    vpath %.c $(LAUNCHER_SHARE_SRC) $(ZIP_SRC) $(LAUNCHER_PLATFORM_SRC)
+  endif # MACOSX
+endif # SYSTEM_LIB
diff --git a/jdk/make/java/jobjc/Makefile b/jdk/make/java/jobjc/Makefile
new file mode 100644
index 0000000..6996cbf
--- /dev/null
+++ b/jdk/make/java/jobjc/Makefile
@@ -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.
+#
+
+#
+# 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
+
+ABS_OUTPUTDIR=$(realpath $(OUTPUTDIR))
+ABS_STABLE_GEN_DIR=$(realpath $(STABLE_GEN_DIR))
+
+$(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="$(ABS_OUTPUTDIR)/JObjC.build" DSTROOT="$(ABS_OUTPUTDIR)/JObjC.dst" JAVA_HOME=${ALT_BOOTDIR} STABLE_GEN_DIR="$(ABS_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..0607242 100644
--- a/jdk/make/java/jvm/Makefile
+++ b/jdk/make/java/jvm/Makefile
@@ -43,7 +43,6 @@
 $(PLATFORM_INCLUDE)/%.h: $(PLATFORM_SRC)/javavm/export/%.h
 	$(install-file)
 
-JVMCFG_DIR = $(LIBDIR)/$(LIBARCH)
 JVMCFG = $(JVMCFG_DIR)/jvm.cfg
 
 #
@@ -55,6 +54,14 @@
 JVMCFG_ARCH = $(ARCH)
 endif
 
+ifeq ($(PLATFORM),macosx)
+  JVMCFG_SRC=$(PLATFORM_SRC_MACOS)/bin/$(JVMCFG_ARCH)/jvm.cfg
+  JVMCFG_DIR = $(LIBDIR)
+else
+  JVMCFG_SRC=$(PLATFORM_SRC)/bin/$(JVMCFG_ARCH)/jvm.cfg
+  JVMCFG_DIR = $(LIBDIR)/$(LIBARCH)
+endif
+
 ifdef BUILD_CLIENT_ONLY
 $(JVMCFG)::
 	$(MKDIR) -p $(JVMCFG_DIR)
@@ -67,7 +74,7 @@
 	$(ECHO) "-native ERROR">>$(JVMCFG)
 	$(ECHO) "-green ERROR">>$(JVMCFG)
 else
-$(JVMCFG): $(PLATFORM_SRC)/bin/$(JVMCFG_ARCH)/jvm.cfg
+$(JVMCFG): $(JVMCFG_SRC)
 	$(install-file)
 endif
 
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 83c885b..ba15900 100644
--- a/jdk/make/java/net/Makefile
+++ b/jdk/make/java/net/Makefile
@@ -94,16 +94,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 b72cfc1..76f746c 100644
--- a/jdk/make/java/nio/Makefile
+++ b/jdk/make/java/nio/Makefile
@@ -260,6 +260,91 @@
 	sun/nio/fs/UnixConstants.java
 endif # PLATFORM = linux
 
+ifeq ($(PLATFORM), macosx)
+FILES_java += \
+        sun/nio/ch/AbstractPollSelectorImpl.java \
+	sun/nio/ch/BsdAsynchronousChannelProvider.java \
+	sun/nio/ch/InheritedChannel.java \
+	sun/nio/ch/KQueue.java \
+	sun/nio/ch/KQueuePort.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 \
+	\
+	KQueue.c \
+	KQueuePort.c
+
+FILES_export += \
+	sun/nio/ch/InheritedChannel.java \
+	sun/nio/ch/KQueue.java \
+	sun/nio/ch/KQueuePort.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 +352,8 @@
 vpath %.c $(PLATFORM_SRC)/native/sun/nio/ch
 vpath %.c $(SHARE_SRC)/native/sun/nio/ch
 
+endif # PLATFORM = macosx
+
 #
 # Various variables
 #
@@ -292,10 +379,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 +406,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 +911,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
@@ -849,6 +948,7 @@
 
 GENUC_SRC = $(PLATFORM_SRC)/native/sun/nio/fs/genUnixConstants.c
 
+GENUC_OBJ = $(TEMPDIR)/genUnixConstants.o
 GENUC_EXE = $(TEMPDIR)/genUnixConstants
 
 GENUC_COPYRIGHT_YEARS = $(shell $(CAT) $(GENUC_SRC) | \
@@ -856,7 +956,8 @@
 
 $(GENUC_EXE) : $(GENUC_SRC)
 	$(prep-target)
-	$(CC) $(CPPFLAGS) -o $@ $(GENUC_SRC)
+	$(CC) $(CPPFLAGS) -c -o $(GENUC_OBJ) $(GENUC_SRC)
+	$(CC) $(CPPFLAGS) -o $@ $(GENUC_OBJ)
 
 ifdef NIO_PLATFORM_CLASSES_ROOT_DIR
 $(SFS_GEN)/UnixConstants.java: $(NIO_PLATFORM_CLASSES_ROOT_DIR)/sun/nio/fs/UnixConstants-$(PLATFORM)-$(ARCH).java
@@ -871,6 +972,7 @@
 
 GENSC_SRC = $(PLATFORM_SRC)/native/sun/nio/fs/genSolarisConstants.c
 
+GENSC_OBJ = $(TEMPDIR)/genSolarisConstants.o
 GENSC_EXE = $(TEMPDIR)/genSolarisConstants
 
 GENSC_COPYRIGHT_YEARS = $(shell $(CAT) $(GENSC_SRC) | \
@@ -878,7 +980,8 @@
 
 $(GENSC_EXE) : $(GENSC_SRC)
 	$(prep-target)
-	$(CC) $(CPPFLAGS) -o $@ $(GENSC_SRC)
+	$(CC) $(CPPFLAGS) -c -o $(GENSC_OBJ) $(GENSC_SRC)
+	$(CC) $(CPPFLAGS) -o $@ $(GENSC_OBJ)
 
 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..b3f50ff
--- /dev/null
+++ b/jdk/make/java/nio/mapfile-bsd
@@ -0,0 +1,179 @@
+#
+# 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_KQueue_kqueue;
+		Java_sun_nio_ch_KQueue_keventRegister;
+		Java_sun_nio_ch_KQueue_keventPoll;
+		Java_sun_nio_ch_KQueue_keventSize;
+		Java_sun_nio_ch_KQueue_identOffset;
+		Java_sun_nio_ch_KQueue_filterOffset;
+		Java_sun_nio_ch_KQueue_flagsOffset;
+		Java_sun_nio_ch_KQueuePort_socketpair;
+		Java_sun_nio_ch_KQueuePort_interrupt;
+		Java_sun_nio_ch_KQueuePort_drain1;
+		Java_sun_nio_ch_KQueuePort_close0;
+		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 60bcc75..e52fcaa 100644
--- a/jdk/make/java/security/Makefile
+++ b/jdk/make/java/security/Makefile
@@ -45,13 +45,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 a1d5e93..b6496b9 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 \
 	gzclose.c \
@@ -44,4 +47,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..cb455a7 100644
--- a/jdk/make/javax/sound/Makefile
+++ b/jdk/make/javax/sound/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -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 -framework AudioToolbox
+  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 9b4f188..2e4e0fb 100644
--- a/jdk/make/jprt.properties
+++ b/jdk/make/jprt.properties
@@ -39,6 +39,7 @@
     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}
 
@@ -53,6 +54,7 @@
     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
 
diff --git a/jdk/make/launchers/Makefile.launcher b/jdk/make/launchers/Makefile.launcher
index 6d98efc..4e32af5 100644
--- a/jdk/make/launchers/Makefile.launcher
+++ b/jdk/make/launchers/Makefile.launcher
@@ -82,12 +82,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 c3a8f18..9d58d54 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 099daf1..ed93612 100644
--- a/jdk/make/sun/awt/Makefile
+++ b/jdk/make/sun/awt/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -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 \
@@ -391,6 +425,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 cdb740b..cbf22d0 100644
--- a/jdk/make/sun/awt/mawt.gmk
+++ b/jdk/make/sun/awt/mawt.gmk
@@ -137,7 +137,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
@@ -148,7 +148,7 @@
 # !HEADLESS
 
 OTHER_LDLIBS += $(JVMLIB) $(LIBCXX) \
-                -lawt $(LIBM) -ldl
+                -lawt $(LIBM) $(LIBDL)
 
 #
 # Sun CC with -Xa misdefines __STDC__ to 0 (zero).
@@ -191,16 +191,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 1a280c7..385e202 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/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 82719b6..28cb54e 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 = -lawt_lwawt -L$(LIBDIR) -Xlinker -rpath -Xlinker @loader_path \
+               -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..43710d7
--- /dev/null
+++ b/jdk/make/sun/lwawt/FILES_export_macosx.gmk
@@ -0,0 +1,279 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please 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/CEmbeddedFrame.java \
+        sun/lwawt/macosx/CPlatformEmbeddedFrame.java \
+        sun/lwawt/macosx/CPlatformResponder.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..6c0742f
--- /dev/null
+++ b/jdk/make/sun/lwawt/Makefile
@@ -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.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please 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 = awt_lwawt
+PRODUCT = sun
+
+LIB_LOCATION = $(LIBDIR)
+
+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 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/rmi/cgi/Makefile b/jdk/make/sun/rmi/cgi/Makefile
index 0400417..48a0805 100644
--- a/jdk/make/sun/rmi/cgi/Makefile
+++ b/jdk/make/sun/rmi/cgi/Makefile
@@ -28,6 +28,8 @@
 #
 
 BUILDDIR = ../../..
+JAVAC_MAX_WARNINGS = true
+JAVAC_WARNINGS_FATAL = true
 # java-rmi.cgi is a JDK tool
 PACKAGE = sun.rmi
 PRODUCT = sun
diff --git a/jdk/make/sun/rmi/registry/Makefile b/jdk/make/sun/rmi/registry/Makefile
index bd5dffe..fbfa4b7 100644
--- a/jdk/make/sun/rmi/registry/Makefile
+++ b/jdk/make/sun/rmi/registry/Makefile
@@ -28,6 +28,9 @@
 #
 
 BUILDDIR = ../../..
+JAVAC_MAX_WARNINGS = true
+JAVAC_WARNINGS_FATAL = true
+JAVAC_LINT_OPTIONS = -Xlint:all,-deprecation
 PACKAGE = sun.rmi.registry
 PRODUCT = sun
 include $(BUILDDIR)/common/Defs.gmk
diff --git a/jdk/make/sun/rmi/rmi/Makefile b/jdk/make/sun/rmi/rmi/Makefile
index 1718329..4aecf02 100644
--- a/jdk/make/sun/rmi/rmi/Makefile
+++ b/jdk/make/sun/rmi/rmi/Makefile
@@ -28,6 +28,9 @@
 #
 
 BUILDDIR = ../../..
+JAVAC_MAX_WARNINGS = true
+JAVAC_WARNINGS_FATAL = true
+JAVAC_LINT_OPTIONS = -Xlint:all,-deprecation
 PACKAGE = sun.rmi
 PRODUCT = sun
 include $(BUILDDIR)/common/Defs.gmk
diff --git a/jdk/make/sun/rmi/rmi/mapfile-vers b/jdk/make/sun/rmi/rmi/mapfile-vers
new file mode 100644
index 0000000..dc33402
--- /dev/null
+++ b/jdk/make/sun/rmi/rmi/mapfile-vers
@@ -0,0 +1,33 @@
+#
+# 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 library interface.
+
+SUNWprivate_1.1 {
+	global:
+	    Java_sun_rmi_server_MarshalInputStream_latestUserDefinedLoader;
+	local:
+	    *;
+};
diff --git a/jdk/make/sun/rmi/rmid/Makefile b/jdk/make/sun/rmi/rmid/Makefile
index c8f3ce6..10f36ce 100644
--- a/jdk/make/sun/rmi/rmid/Makefile
+++ b/jdk/make/sun/rmi/rmid/Makefile
@@ -29,6 +29,8 @@
 #
 
 BUILDDIR = ../../..
+JAVAC_MAX_WARNINGS = true
+JAVAC_WARNINGS_FATAL = true
 PACKAGE = sun.rmi.activation
 PRODUCT = sun
 include $(BUILDDIR)/common/Defs.gmk
diff --git a/jdk/make/sun/security/jgss/wrapper/Makefile b/jdk/make/sun/security/jgss/wrapper/Makefile
index fead6e2..91fdf90 100644
--- a/jdk/make/sun/security/jgss/wrapper/Makefile
+++ b/jdk/make/sun/security/jgss/wrapper/Makefile
@@ -72,6 +72,6 @@
 # Libraries to link
 #
 ifneq ($(PLATFORM), windows)
-  OTHER_LDLIBS = -ldl
+  OTHER_LDLIBS = $(LIBDL)
 endif
 
diff --git a/jdk/make/sun/security/krb5/Makefile b/jdk/make/sun/security/krb5/Makefile
index 848a694..7c79f93 100644
--- a/jdk/make/sun/security/krb5/Makefile
+++ b/jdk/make/sun/security/krb5/Makefile
@@ -33,6 +33,12 @@
 #
 AUTO_FILES_JAVA_DIRS = sun/security/krb5
 
+ifeq ($(PLATFORM), macosx)
+FILES_export = sun/security/krb5/Credentials.java
+FILES_c = nativeccache.c
+LIBRARY = osxkrb5
+endif # PLATFORM
+
 ifeq ($(PLATFORM), windows)
 #
 # Java files that define native methods
@@ -52,8 +58,12 @@
 #
 # Find native code
 #
-vpath %.c \
-  $(PLATFORM_SRC)/native/sun/security/krb5
+ifeq ($PLATFORM), macosx)
+  vpath %.c $(call NativeSrcDirList,,native/sun/security/krb5)
+else
+  vpath %.c \
+    $(PLATFORM_SRC)/native/sun/security/krb5
+endif
 
 JGSS_NATIVE_SRC=$(PLATFORM_SRC)/native/sun/security/krb5
 JGSS_NATIVE_DIR_EXISTS := $(shell if [ -d $(JGSS_NATIVE_SRC) ] ; then echo true; else echo false; fi)
@@ -65,10 +75,20 @@
   ifeq ($(JGSS_NATIVE_DIR_EXISTS), true)
     include $(BUILDDIR)/common/Library.gmk
   endif
+else ifeq ($(PLATFORM), macosx)
+  include $(BUILDDIR)/common/Library.gmk
 else
 include $(BUILDDIR)/common/Classes.gmk
 endif # PLATFORM
 
+ifneq ($(PLATFORM), windows)
+  ifeq ($(PLATFORM), macosx)
+    OTHER_LDLIBS = $(LIBDL) -framework Kerberos
+  else
+    OTHER_LDLIBS = $(LIBDL)
+  endif
+endif
+  
 build:
 ifeq ($(PLATFORM),windows)
 	$(call make-launcher, kinit, sun.security.krb5.internal.tools.Kinit, , )
diff --git a/jdk/make/sun/security/pkcs11/Makefile b/jdk/make/sun/security/pkcs11/Makefile
index 0405776..7b31f20 100644
--- a/jdk/make/sun/security/pkcs11/Makefile
+++ b/jdk/make/sun/security/pkcs11/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -150,7 +150,7 @@
 # Rules
 #
 CLASSDESTDIR = $(TEMPDIR)/classes
-JAVAHFLAGS += -Xbootclasspath/p:$(CLASSDESTDIR)
+JAVAHFLAGS = -bootclasspath "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)"
 
 include $(BUILDDIR)/common/Mapfile-vers.gmk
 
@@ -160,7 +160,7 @@
 # Libraries to link
 #
 ifneq ($(PLATFORM), windows)
-  OTHER_LDLIBS = -ldl
+  OTHER_LDLIBS = $(LIBDL)
 endif
 
 # Other config files
diff --git a/jdk/make/sun/security/smartcardio/Makefile b/jdk/make/sun/security/smartcardio/Makefile
index 1dae7a1..c98e978 100644
--- a/jdk/make/sun/security/smartcardio/Makefile
+++ b/jdk/make/sun/security/smartcardio/Makefile
@@ -75,6 +75,6 @@
 ifeq ($(PLATFORM), windows)
   OTHER_LDLIBS = winscard.lib
 else
-  OTHER_LDLIBS = -ldl
+  OTHER_LDLIBS = $(LIBDL)
   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 b6e234f..f55b8d7 100644
--- a/jdk/make/sun/splashscreen/FILES_c.gmk
+++ b/jdk/make/sun/splashscreen/FILES_c.gmk
@@ -49,21 +49,6 @@
 	dgif_lib.c \
 	gif_err.c \
 	gifalloc.c \
-	compress.c \
-	deflate.c \
-	gzclose.c \
-	gzlib.c \
-	gzread.c \
-	gzwrite.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 \
@@ -109,3 +94,21 @@
 	jfdctfst.c \
 	jfdctint.c
 
+ifneq ($(SYSTEM_ZLIB),true)
+  FILES_c += \
+	compress.c \
+	deflate.c \
+	gzclose.c \
+	gzlib.c \
+	gzread.c \
+	gzwrite.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 460818a..f8918ea 100644
--- a/jdk/make/sun/xawt/Makefile
+++ b/jdk/make/sun/xawt/Makefile
@@ -56,6 +56,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.
@@ -90,7 +95,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)
@@ -161,6 +166,10 @@
  endif
 endif
 
+ifeq ($(PLATFORM), macosx)
+  CPPFLAGS += -DX11_PATH=\"$(X11_PATH)\" -DPACKAGE_PATH=\"$(PACKAGE_PATH)\"
+endif
+
 ifeq ($(MILESTONE), internal)
   CPPFLAGS += -DINTERNAL_BUILD
 endif
@@ -205,6 +214,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)
@@ -214,7 +230,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.
@@ -251,9 +267,11 @@
 $(SIZERS): $(SIZERS_C) 
 	$(prep-target)
 ifndef CROSS_COMPILE_ARCH
-	$(CC) $(CFLAGS_$(subst .,,$(suffix $@))) $(CPPFLAGS) -o $@ $(SIZER)$(suffix $@).c
+	$(CC) $(CFLAGS_$(subst .,,$(suffix $@))) $(CPPFLAGS) -c -o $(SIZER)$(suffix $@).o $(SIZER)$(suffix $@).c
+	$(CC) $(CFLAGS_$(subst .,,$(suffix $@))) -o $@ $(CPPFLAGS) $(SIZER)$(suffix $@).o
 else
-	$(HOST_CC) $(CPPFLAGS) -o $@ $(SIZER)$(suffix $@).c
+	$(HOST_CC) $(CPPFLAGS) -c -o $(SIZER)$(suffix $@).o $(SIZER)$(suffix $@).c
+	$(HOST_CC) $(CPPFLAGS) -o $@ $(SIZER)$(suffix $@).o
 endif
 
 $(WRAPPER_GENERATOR_CLASS): $(WRAPPER_GENERATOR_JAVA)
diff --git a/jdk/make/tools/freetypecheck/Makefile b/jdk/make/tools/freetypecheck/Makefile
index 101542f..0b18de0 100644
--- a/jdk/make/tools/freetypecheck/Makefile
+++ b/jdk/make/tools/freetypecheck/Makefile
@@ -47,12 +47,15 @@
   FT_OPTIONS  = $(CFLAGS)
   FT_LD_OPTIONS = -L$(FREETYPE_LIB_PATH)
   # Add runtime lib search path to ensure test will be runnable
-  ifeq ($(PLATFORM), linux)
-    FT_LD_OPTIONS += -Wl,-rpath -Wl,$(FREETYPE_LIB_PATH)
-  else # other unix
-    FT_LD_OPTIONS += -R $(FREETYPE_LIB_PATH)
+  ifeq ($(PLATFORM), solaris)
+    FT_LD_OPTIONS += -R $(FREETYPE_LIB_PATH) -lfreetype
+  else
+    ifeq ($(PLATFORM), macosx)
+      FT_LD_OPTIONS += -lfreetype -lz
+    else # linux
+      FT_LD_OPTIONS += -Wl,-rpath -Wl,$(FREETYPE_LIB_PATH) -lfreetype
+    endif
   endif
-  FT_LD_OPTIONS += -lfreetype
 endif
 FT_OPTIONS += -I$(FREETYPE_HEADERS_PATH)
 FT_OPTIONS += -I$(FREETYPE_HEADERS_PATH)/freetype2
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/bin/amd64/jvm.cfg b/jdk/src/macosx/bin/amd64/jvm.cfg
new file mode 100644
index 0000000..7239804
--- /dev/null
+++ b/jdk/src/macosx/bin/amd64/jvm.cfg
@@ -0,0 +1,38 @@
+# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please 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 IGNORE
+-hotspot ERROR
+-classic WARN
+-native ERROR
+-green ERROR
diff --git a/jdk/src/macosx/bin/java_md_macosx.c b/jdk/src/macosx/bin/java_md_macosx.c
new file mode 100644
index 0000000..14ae531
--- /dev/null
+++ b/jdk/src/macosx/bin/java_md_macosx.c
@@ -0,0 +1,1005 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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.h"
+#include "jvm_md.h"
+#include <dirent.h>
+#include <dlfcn.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include "manifest_info.h"
+#include "version_comp.h"
+
+/* Support Cocoa event loop on the main thread */
+#include <Cocoa/Cocoa.h>
+#include <objc/objc-runtime.h>
+#include <objc/objc-auto.h>
+#include <dispatch/dispatch.h>
+
+#include <errno.h>
+#include <spawn.h>
+
+struct NSAppArgs {
+    int argc;
+    char **argv;
+};
+
+#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"
+
+/*
+ * If a processor / os combination has the ability to run binaries of
+ * two data models and cohabitation of jre/jdk bits with both data
+ * models is supported, then DUAL_MODE is defined. MacOSX is a hybrid
+ * system in that, the universal library can contain all types of libraries
+ * 32/64 and client/server, thus the spawn is capable of linking with the
+ * appropriate library as requested.
+ *
+ * Notes:
+ * 1. VM. DUAL_MODE is disabled, and not supported, however, it is left here in
+ *    for experimentation and perhaps enable it in the future.
+ * 2. At the time of this writing, the universal library contains only
+ *    a server 64-bit server JVM.
+ * 3. "-client" command line option is supported merely as a command line flag,
+ *    for, compatibility reasons, however, a server VM will be launched.
+ */
+
+/*
+ * Flowchart of launcher execs and options processing on unix
+ *
+ * The selection of the proper vm shared library to open depends on
+ * several classes of command line options, including vm "flavor"
+ * options (-client, -server) and the data model options, -d32  and
+ * -d64, as well as a version specification which may have come from
+ * the command line or from the manifest of an executable jar file.
+ * The vm selection options are not passed to the running
+ * virtual machine; they must be screened out by the launcher.
+ *
+ * The version specification (if any) is processed first by the
+ * platform independent routine SelectVersion.  This may result in
+ * the exec of the specified launcher version.
+ *
+ * Now, in most cases,the launcher will dlopen the target libjvm.so. All
+ * required libraries are loaded by the runtime linker, using the known paths
+ * baked into the shared libraries at compile time. Therefore,
+ * in most cases, the launcher will only exec, if the data models are
+ * mismatched, and will not set any environment variables, regardless of the
+ * data models.
+ *
+ *
+ *
+ *  Main
+ *  (incoming argv)
+ *  |
+ * \|/
+ * SelectVersion
+ * (selects the JRE version, note: not data model)
+ *  |
+ * \|/
+ * CreateExecutionEnvironment
+ * (determines desired data model)
+ *  |
+ *  |
+ * \|/
+ *  Have Desired Model ? --> NO --> Is Dual-Mode ? --> NO --> Exit(with error)
+ *  |                                          |
+ *  |                                          |
+ *  |                                         \|/
+ *  |                                         YES
+ *  |                                          |
+ *  |                                          |
+ *  |                                         \|/
+ *  |                                CheckJvmType
+ *  |                               (removes -client, -server etc.)
+ *  |                                          |
+ *  |                                          |
+ * \|/                                        \|/
+ * YES                             Find the desired executable/library
+ *  |                                          |
+ *  |                                          |
+ * \|/                                        \|/
+ * CheckJvmType                             POINT A
+ * (removes -client, -server, etc.)
+ *  |
+ *  |
+ * \|/
+ * TranslateDashJArgs...
+ * (Prepare to pass args to vm)
+ *  |
+ *  |
+ * \|/
+ * ParseArguments
+ * (removes -d32 and -d64 if any,
+ *  processes version options,
+ *  creates argument list for vm,
+ *  etc.)
+ *   |
+ *   |
+ *  \|/
+ * POINT A
+ *   |
+ *   |
+ *  \|/
+ * Path is desired JRE ? YES --> Have Desired Model ? NO --> Re-exec --> Main
+ *  NO                               YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ * Paths have well known
+ * jvm paths ?       --> NO --> Have Desired Model ? NO --> Re-exec --> Main
+ *  YES                              YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ *  Does libjvm.so exist
+ *  in any of them ? --> NO --> Have Desired Model ? NO --> Re-exec --> Main
+ *   YES                             YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ * Re-exec / Spawn
+ *   |
+ *   |
+ *  \|/
+ * Main
+ */
+
+#define GetArch() GetArchPath(CURRENT_DATA_MODEL)
+
+/* Store the name of the executable once computed */
+static char *execname = NULL;
+
+/*
+ * execname accessor from other parts of platform dependent logic
+ */
+const char *
+GetExecName() {
+    return execname;
+}
+
+const char *
+GetArchPath(int nbits)
+{
+    switch(nbits) {
+        default:
+            return LIBARCHNAME;
+    }
+}
+
+
+/*
+ * 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();
+}
+
+void
+CreateExecutionEnvironment(int *pargc, char ***pargv,
+                           char jrepath[], jint so_jrepath,
+                           char jvmpath[], jint so_jvmpath,
+                           char jvmcfg[],  jint so_jvmcfg) {
+  /*
+   * First, determine if we are running the desired data model.  If we
+   * are running the desired data model, all the error messages
+   * associated with calling GetJREPath, ReadKnownVMs, etc. should be
+   * output.  However, if we are not running the desired data model,
+   * some of the errors should be suppressed since it is more
+   * informative to issue an error message based on whether or not the
+   * os/processor combination has dual mode capabilities.
+   */
+    jboolean jvmpathExists;
+
+    /* Compute/set the name of the executable */
+    SetExecname(*pargv);
+
+    /* Check data model flags, and exec process, if needed */
+    {
+      char *arch        = (char *)GetArch(); /* like sparc or sparcv9 */
+      char * jvmtype    = NULL;
+      int  argc         = *pargc;
+      char **argv       = *pargv;
+      int running       = CURRENT_DATA_MODEL;
+
+      int wanted        = running;      /* What data mode is being
+                                           asked for? Current model is
+                                           fine unless another model
+                                           is asked for */
+
+      char** newargv    = NULL;
+      int    newargc    = 0;
+
+      /*
+       * Starting in 1.5, all unix platforms accept the -d32 and -d64
+       * options.  On platforms where only one data-model is supported
+       * (e.g. ia-64 Linux), using the flag for the other data model is
+       * an error and will terminate the program.
+       */
+
+      { /* open new scope to declare local variables */
+        int i;
+
+        newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*));
+        newargv[newargc++] = argv[0];
+
+        /* scan for data model arguments and remove from argument list;
+           last occurrence determines desired data model */
+        for (i=1; i < argc; i++) {
+
+          if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) {
+            wanted = 64;
+            continue;
+          }
+          if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) {
+            wanted = 32;
+            continue;
+          }
+          newargv[newargc++] = argv[i];
+
+          if (IsJavaArgs()) {
+            if (argv[i][0] != '-') continue;
+          } else {
+            if (JLI_StrCmp(argv[i], "-classpath") == 0 || JLI_StrCmp(argv[i], "-cp") == 0) {
+              i++;
+              if (i >= argc) break;
+              newargv[newargc++] = argv[i];
+              continue;
+            }
+            if (argv[i][0] != '-') { i++; break; }
+          }
+        }
+
+        /* copy rest of args [i .. argc) */
+        while (i < argc) {
+          newargv[newargc++] = argv[i++];
+        }
+        newargv[newargc] = NULL;
+
+        /*
+         * newargv has all proper arguments here
+         */
+
+        argc = newargc;
+        argv = newargv;
+      }
+
+      /* If the data model is not changing, it is an error if the
+         jvmpath does not exist */
+      if (wanted == running) {
+        /* Find out where the JRE is that we will be using. */
+        if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) {
+          JLI_ReportErrorMessage(JRE_ERROR1);
+          exit(2);
+        }
+        JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg",
+          jrepath, FILESEP, FILESEP,  "", "");
+        /* Find the specified JVM type */
+        if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) {
+          JLI_ReportErrorMessage(CFG_ERROR7);
+          exit(1);
+        }
+
+        jvmpath[0] = '\0';
+        jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
+        if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
+            JLI_ReportErrorMessage(CFG_ERROR9);
+            exit(4);
+        }
+
+        if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch, wanted)) {
+          JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
+          exit(4);
+        }
+
+        /*
+         * 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);
+
+        /*
+         * we seem to have everything we need, so without further ado
+         * we return back, otherwise proceed to set the environment.
+         */
+        return;
+      } else {  /* do the same speculatively or exit */
+#if defined(DUAL_MODE)
+        if (running != wanted) {
+          /* Find out where the JRE is that we will be using. */
+          if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) {
+            /* give up and let other code report error message */
+            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
+            exit(1);
+          }
+          JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg",
+            jrepath, FILESEP, FILESEP,  "", "");
+          /*
+           * Read in jvm.cfg for target data model and process vm
+           * selection options.
+           */
+          if (ReadKnownVMs(jvmcfg, JNI_TRUE) < 1) {
+            /* give up and let other code report error message */
+            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
+            exit(1);
+          }
+          jvmpath[0] = '\0';
+          jvmtype = CheckJvmType(pargc, pargv, JNI_TRUE);
+          if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
+            JLI_ReportErrorMessage(CFG_ERROR9);
+            exit(4);
+          }
+
+          /* exec child can do error checking on the existence of the path */
+          jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted), wanted);
+        }
+#else /* ! DUAL_MODE */
+        JLI_ReportErrorMessage(JRE_ERROR2, wanted);
+        exit(1);
+#endif /* DUAL_MODE */
+        }
+        {
+            char *newexec = execname;
+            JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n");
+            (void) fflush(stdout);
+            (void) fflush(stderr);
+            /*
+            * 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 /* __i386 .. */
+
+                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);
+            }
+            JLI_ReportErrorMessageSys(JRE_ERROR4, newexec);
+
+#if defined(DUAL_MODE)
+            if (running != wanted) {
+                JLI_ReportErrorMessage(JRE_ERROR5, wanted, running);
+            }
+#endif /* DUAL_MODE */
+        }
+        exit(1);
+    }
+}
+
+/*
+ * VM choosing is done by the launcher (java.c).
+ */
+static jboolean
+GetJVMPath(const char *jrepath, const char *jvmtype,
+           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 {
+        /*
+         * 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);
+    }
+
+    JLI_TraceLauncher("Does `%s' exist ... ", jvmpath);
+
+    if (stat(jvmpath, &s) == 0) {
+        JLI_TraceLauncher("yes.\n");
+        return JNI_TRUE;
+    } else {
+        JLI_TraceLauncher("no.\n");
+        return JNI_FALSE;
+    }
+}
+
+/*
+ * Find path to JRE based on .exe's location or registry settings.
+ */
+static jboolean
+GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative)
+{
+    char libjava[MAXPATHLEN];
+
+    if (GetApplicationHome(path, pathsize)) {
+        /* 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;
+        }
+    }
+
+    /* 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;
+    }
+
+    if (!speculative)
+      JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
+    return JNI_FALSE;
+}
+
+jboolean
+LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
+{
+    Dl_info dlinfo;
+    void *libjvm;
+
+    JLI_TraceLauncher("JVM path is %s\n", jvmpath);
+
+    libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL);
+    if (libjvm == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR1, __LINE__);
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
+    ifn->CreateJavaVM = (CreateJavaVM_t)
+        dlsym(libjvm, "JNI_CreateJavaVM");
+    if (ifn->CreateJavaVM == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
+    ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t)
+        dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs");
+    if (ifn->GetDefaultJavaVMInitArgs == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        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;
+}
+
+/*
+ * Compute the name of the executable
+ *
+ * In order to re-exec securely we need the absolute path of the
+ * executable. On Solaris getexecname(3c) may not return an absolute
+ * path so we use dladdr to get the filename of the executable and
+ * then use realpath to derive an absolute path. From Solaris 9
+ * onwards the filename returned in DL_info structure from dladdr is
+ * an absolute pathname so technically realpath isn't required.
+ * On Linux we read the executable name from /proc/self/exe.
+ * As a fallback, and for platforms other than Solaris and Linux,
+ * we use FindExecName to compute the executable name.
+ */
+const char*
+SetExecname(char **argv)
+{
+    char* exec_path = NULL;
+    {
+        Dl_info dlinfo;
+        int (*fptr)();
+
+        fptr = (int (*)())dlsym(RTLD_DEFAULT, "main");
+        if (fptr == NULL) {
+            JLI_ReportErrorMessage(DLL_ERROR3, dlerror());
+            return JNI_FALSE;
+        }
+
+        if (dladdr((void*)fptr, &dlinfo)) {
+            char *resolved = (char*)JLI_MemAlloc(PATH_MAX+1);
+            if (resolved != NULL) {
+                exec_path = realpath(dlinfo.dli_fname, resolved);
+                if (exec_path == NULL) {
+                    JLI_MemFree(resolved);
+                }
+            }
+        }
+    }
+    if (exec_path == NULL) {
+        exec_path = FindExecName(argv[0]);
+    }
+    execname = exec_path;
+    return exec_path;
+}
+
+/*
+ * BSD's implementation of CounterGet()
+ */
+int64_t
+CounterGet()
+{
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    return (tv.tv_sec * 1000) + tv.tv_usec;
+}
+
+
+/* --- Splash Screen shared library support --- */
+
+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;
+}
+
+static const char* SPLASHSCREEN_SO = JNI_LIB_NAME("splashscreen");
+
+static void* hSplashLib = NULL;
+
+void* SplashProcAddress(const char* name) {
+    if (!hSplashLib) {
+        char jrePath[PATH_MAX];
+        if (!GetJREPath(jrePath, sizeof(jrePath), GetArch(), JNI_FALSE)) {
+            JLI_ReportErrorMessage(JRE_ERROR1);
+            return NULL;
+        }
+
+        char splashPath[PATH_MAX];
+        const int ret = JLI_Snprintf(splashPath, sizeof(splashPath),
+                "%s/lib/%s", jrePath, SPLASHSCREEN_SO);
+        if (ret >= (int)sizeof(splashPath)) {
+            JLI_ReportErrorMessage(JRE_ERROR11);
+            return NULL;
+        }
+        if (ret < 0) {
+            JLI_ReportErrorMessage(JRE_ERROR13);
+            return NULL;
+        }
+
+        hSplashLib = dlopen(splashPath, RTLD_LAZY | RTLD_GLOBAL);
+        // It's OK if dlopen() fails. The splash screen library binary file
+        // might have been stripped out from the JRE image to reduce its size
+        // (e.g. on embedded platforms).
+
+        if (hSplashLib) {
+            if (!SetJavaVMValue()) {
+                dlclose(hSplashLib);
+                hSplashLib = NULL;
+            }
+        }
+    }
+    if (hSplashLib) {
+        void* sym = dlsym(hSplashLib, name);
+        return sym;
+    } else {
+        return NULL;
+    }
+}
+
+void SplashFreeLibrary() {
+    if (hSplashLib) {
+        dlclose(hSplashLib);
+        hSplashLib = NULL;
+    }
+}
+
+/*
+ * Block current thread and continue execution in a new thread
+ */
+int
+ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
+    int rslt;
+    pthread_t tid;
+    pthread_attr_t attr;
+    pthread_attr_init(&attr);
+    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+
+    if (stack_size > 0) {
+      pthread_attr_setstacksize(&attr, stack_size);
+    }
+
+    if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) {
+      void * tmp;
+      pthread_join(tid, &tmp);
+      rslt = (int)tmp;
+    } else {
+     /*
+      * Continue execution in current thread if for some reason (e.g. out of
+      * memory/LWP)  a new thread can't be created. This will likely fail
+      * later in continuation as JNI_CreateJavaVM needs to create quite a
+      * few new threads, anyway, just give it a try..
+      */
+      rslt = continuation(args);
+    }
+
+    pthread_attr_destroy(&attr);
+    return rslt;
+}
+
+void SetJavaLauncherPlatformProps() {
+   /* Linux only */
+}
+
+jboolean
+ServerClassMachine(void) {
+    return JNI_TRUE;
+}
+
+static JavaVM* jvmInstance = NULL;
+static jboolean sameThread = JNI_FALSE; /* start VM in current thread */
+
+/*
+ * Note there is a callback on this function from the splashscreen logic,
+ * this as well SetJavaVMValue() needs to be simplified.
+ */
+JavaVM*
+JLI_GetJavaVMInstance()
+{
+    return jvmInstance;
+}
+
+void
+RegisterThread()
+{
+    objc_registerThreadWithCollector();
+}
+
+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
+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);
+}
+
+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
+
+    sameThread = 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);
+}
+
+// MacOSX we may continue in the same thread
+int
+JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
+                 int argc, char **argv,
+                 int mode, char *what, int ret) {
+    if (sameThread) {
+        JLI_TraceLauncher("In same thread\n");
+        // 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;
+    } else {
+        return ContinueInNewThread(ifn, threadStackSize, argc, argv, mode, what, ret);
+    }
+}
+
+/*
+ * Note the jvmInstance must be initialized first before entering into
+ * ShowSplashScreen, as there is a callback into the JLI_GetJavaVMInstance.
+ */
+void PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm) {
+    jvmInstance = vm;
+    SetMainClassForAWT(env, mainClass);
+    ShowSplashScreen();
+}
+
+jboolean
+ProcessPlatformOption(const char* arg)
+{
+    if (JLI_StrCmp(arg, "-XstartOnFirstThread") == 0) {
+       SetXStartOnFirstThreadArg();
+       return JNI_TRUE;
+    } else if (JLI_StrCCmp(arg, "-Xdock:") == 0) {
+       SetXDockArgForAWT(arg);
+       return JNI_TRUE;
+    }
+    // arguments we know not
+    return JNI_FALSE;
+}
diff --git a/jdk/src/macosx/bin/java_md_macosx.h b/jdk/src/macosx/bin/java_md_macosx.h
new file mode 100644
index 0000000..219fddf
--- /dev/null
+++ b/jdk/src/macosx/bin/java_md_macosx.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 JAVA_MD_MACOSX_H
+#define JAVA_MD_MACOSX_H
+
+/* CounterGet() is implemented in java_md.c */
+int64_t CounterGet(void);
+#define Counter2Micros(counts)    (counts)
+
+/* pointer to environment */
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
+
+/*
+ *      A collection of useful strings. One should think of these as #define
+ *      entries, but actual strings can be more efficient (with many compilers).
+ */
+static const char *system_dir  = PACKAGE_PATH "/openjdk7";
+static const char *user_dir    = "/java";
+
+#include <dlfcn.h>
+#include <pthread.h>
+
+#endif /* JAVA_MD_MACOSX_H */
diff --git a/jdk/src/macosx/bin/jexec.c b/jdk/src/macosx/bin/jexec.c
new file mode 100644
index 0000000..24df31f
--- /dev/null
+++ b/jdk/src/macosx/bin/jexec.c
@@ -0,0 +1,239 @@
+/*
+ * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * jexec for J2SE
+ *
+ * jexec is used by the system to allow execution of JAR files.
+ *    Essentially jexec needs to run java and
+ *    needs to be a native ISA executable (not a shell script), although
+ *    this native ISA executable requirement was a mistake that will be fixed.
+ *    (<ISA> is sparc or i386 or amd64).
+ *
+ *    When you execute a jar file, jexec is executed by the system as follows:
+ *      /usr/java/jre/lib/<ISA>/jexec -jar JARFILENAME
+ *    so this just needs to be turned into:
+ *      /usr/java/jre/bin/java -jar JARFILENAME
+ *
+ * Solaris systems (new 7's and all 8's) will be looking for jexec at:
+ *      /usr/java/jre/lib/<ISA>/jexec
+ * Older systems may need to add this to their /etc/system file:
+ *      set javaexec:jexec="/usr/java/jre/lib/<ISA>/jexec"
+ *     and reboot the machine for this to work.
+ *
+ * This source should be compiled as:
+ *      cc -o jexec jexec.c
+ *
+ * And jexec should be placed at the following location of the installation:
+ *      <INSTALLATIONDIR>/jre/lib/<ISA>/jexec  (for Solaris)
+ *      <INSTALLATIONDIR>/lib/jexec            (for Linux)
+ *
+ * NOTE: Unless <INSTALLATIONDIR> is the "default" JDK on the system
+ *       (i.e. /usr/java -> <INSTALLATIONDIR>), this jexec will not be
+ *       found.  The 1.2 java is only the default on Solaris 8 and
+ *       on systems where the 1.2 packages were installed and no 1.1
+ *       java was found.
+ *
+ * NOTE: You must use 1.2 jar to build your jar files. The system
+ *       doesn't seem to pick up 1.1 jar files.
+ *
+ * NOTE: We don't need to set LD_LIBRARY_PATH here, even though we
+ *       are running the actual java binary because the java binary will
+ *       look for it's libraries through it's own runpath, which uses
+ *       $ORIGIN.
+ *
+ * NOTE: This jexec should NOT have any special .so library needs because
+ *       it appears that this executable will NOT get the $ORIGIN of jexec
+ *       but the $ORIGIN of the jar file being executed. Be careful to keep
+ *       this program simple and with no .so dependencies.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <limits.h>
+#include <errno.h>
+
+static const int CRAZY_EXEC = ENOEXEC;
+static const int BAD_MAGIC  = ENOEXEC;
+
+static const char * BAD_EXEC_MSG     = "jexec failed";
+static const char * CRAZY_EXEC_MSG   = "missing args";
+static const char * MISSING_JAVA_MSG = "can't locate java";
+static const char * UNKNOWN_ERROR    = "unknown error";
+
+/* Define a constant that represents the number of directories to pop off the
+ * current location to find the java binary */
+static const int RELATIVE_DEPTH = 3;
+
+/* path to java after popping */
+static const char * BIN_PATH = "/bin/java";
+
+/* flag used when running JAR files */
+static const char * JAR_FLAG = "-jar";
+
+int main(int argc, const char * argv[]);
+void errorExit(int error, const char * message);
+int getJavaPath(const char * path, char * buf, int depth);
+
+/*
+ * This is the main entry point.  This program (jexec) will attempt to execute
+ * a JAR file by finding the Java program (java), relative to its own location.
+ * The exact location of the Java program depends on the platform, i.e.
+ *
+ *      <INSTALLATIONDIR>/jre/lib/<ISA>/jexec  (for Solaris)
+ *      <INSTALLATIONDIR>/lib/jexec            (for Linux JDK)
+ *
+ * Once the Java program is found, this program copies any remaining arguments
+ * into another array, which is then used to exec the Java program.
+ *
+ * On Linux this program does some additional steps.  When copying the array of
+ * args, it is necessary to insert the "-jar" flag between arg[0], the program
+ * name, and the original arg[1], which is presumed to be a path to a JAR file.
+ * It is also necessary to verify that the original arg[1] really is a JAR file.
+ * (These steps are unnecessary on Solaris because they are taken care of by
+ * the kernel.)
+ */
+int main(int argc, const char * argv[]) {
+    /* We need to exec the original arguments using java, instead of jexec.
+     * Also, for Linux, it is necessary to add the "-jar" argument between
+     * the new arg[0], and the old arg[1].  To do this we will create a new
+     * args array. */
+    char          java[PATH_MAX + 1];    /* path to java binary  */
+    const char ** nargv = NULL;          /* new args array       */
+    int           nargc = 0;             /* new args array count */
+    int           argi  = 0;             /* index into old array */
+
+    /* Make sure we have something to work with */
+    if ((argc < 1) || (argv == NULL)) {
+        /* Shouldn't happen... */
+        errorExit(CRAZY_EXEC, CRAZY_EXEC_MSG);
+    }
+
+    /* Get the path to the java binary, which is in a known position relative
+     * to our current position, which is in argv[0]. */
+    if (getJavaPath(argv[argi++], java, RELATIVE_DEPTH) != 0) {
+        errorExit(errno, MISSING_JAVA_MSG);
+    }
+
+    nargv = (const char **) malloc((argc + 2) * (sizeof (const char *)));
+    nargv[nargc++] = java;
+
+    if (argc >= 2) {
+        const char * jarfile = argv[argi++];
+        const char * message = NULL;
+
+        /* the next argument is the path to the JAR file */
+        nargv[nargc++] = jarfile;
+    }
+
+    /* finally copy any remaining arguments */
+    while (argi < argc) {
+        nargv[nargc++] = argv[argi++];
+    }
+
+    /* finally add one last terminating null */
+    nargv[nargc++] = NULL;
+
+    /* It's time to exec the java binary with the new arguments.  It
+     * is possible that we've reached this point without actually
+     * having a JAR file argument (i.e. if argc < 2), but we still
+     * want to exec the java binary, since that will take care of
+     * displaying the correct usage. */
+    execv(java, (char * const *) nargv);
+
+    /* If the exec worked, this process would have been replaced
+     * by the new process.  So any code reached beyond this point
+     * implies an error in the exec. */
+    free(nargv);
+    errorExit(errno, BAD_EXEC_MSG);
+    return 0; // keep the compiler happy
+}
+
+
+/*
+ * Exit the application by setting errno, and writing a message.
+ *
+ * Parameters:
+ *     error   - errno is set to this value, and it is used to exit.
+ *     message - the message to write.
+ */
+void errorExit(int error, const char * message) {
+    if (error != 0) {
+        errno = error;
+        perror((message != NULL) ? message : UNKNOWN_ERROR);
+    }
+
+    exit((error == 0) ? 0 : 1);
+}
+
+
+/*
+ * Get the path to the java binary that should be relative to the current path.
+ *
+ * Parameters:
+ *     path  - the input path that the java binary that should be relative to.
+ *     buf   - a buffer of size PATH_MAX or greater that the java path is
+ *             copied to.
+ *     depth - the number of names to trim off the current path, including the
+ *             name of this program.
+ *
+ * Returns:
+ *     This function returns 0 on success; otherwise it returns the value of
+ *     errno.
+ */
+int getJavaPath(const char * path, char * buf, int depth) {
+    int result = 0;
+
+    /* Get the full path to this program.  Depending on whether this is Solaris
+     * or Linux, this will be something like,
+     *
+     *     <FOO>/jre/lib/<ISA>/jexec  (for Solaris)
+     *     <FOO>/lib/jexec            (for Linux)
+     */
+    if (realpath(path, buf) != NULL) {
+        int count = 0;
+
+        /* Pop off the filename, and then subdirectories for each level of
+         * depth */
+        for (count = 0; count < depth; count++) {
+            *(strrchr(buf, '/')) = '\0';
+        }
+
+        /* Append the relative location of java, creating something like,
+         *
+         *     <FOO>/jre/bin/java  (for Solaris)
+         *     <FOO>/bin/java      (for Linux)
+         */
+        strcat(buf, BIN_PATH);
+    }
+    else {
+        /* Failed to get the path */
+        result = errno;
+    }
+
+    return (result);
+}
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..55290b6
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaCaret.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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);
+    }
+
+    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;
+        if (isMultiLineEditor) {
+            setVisible(false);
+            c.repaint();
+        } else {
+            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..fe8ea710c
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaImageFactory.java
@@ -0,0 +1,487 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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();
+        return new SystemColorProxy(SystemColor.window);
+    }
+
+    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..ea09bf8
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameUI.java
@@ -0,0 +1,960 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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 getPreferredSize(JComponent x) {
+        Dimension preferredSize = super.getMinimumSize(x);
+        Dimension minimumSize = frame.getMinimumSize();
+        if (preferredSize.width < minimumSize.width) {
+            preferredSize.width = minimumSize.width;
+        }
+        if (preferredSize.height < minimumSize.height) {
+            preferredSize.height = minimumSize.height;
+        }
+        return preferredSize;
+    }
+
+    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..0870ebe
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaSliderUI.java
@@ -0,0 +1,507 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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;
+
+            // We should recalculate geometry just before
+            // calculation of the thumb movement direction.
+            // It is important for the case, when JSlider
+            // is a cell editor in JTable. See 6348946.
+            calculateGeometry();
+
+            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..3256c96
--- /dev/null
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaSpinnerUI.java
@@ -0,0 +1,678 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getBaseline(JComponent c, int width, int height) {
+        super.getBaseline(c, width, height);
+        JComponent editor = spinner.getEditor();
+        Insets insets = spinner.getInsets();
+        width = width - insets.left - insets.right;
+        height = height - insets.top - insets.bottom;
+        if (width >= 0 && height >= 0) {
+            int baseline = editor.getBaseline(width, height);
+            if (baseline >= 0) {
+                return insets.top + baseline;
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
+            JComponent c) {
+        super.getBaselineResizeBehavior(c);
+        return spinner.getEditor().getBaselineResizeBehavior();
+    }
+
+    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();
+        if (editorTextField.getFont() instanceof UIResource) {
+            editorTextField.setFont(spinner.getFont());
+        }
+        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..b03527d
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java
@@ -0,0 +1,481 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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();
+
+            cfginfo = getCGLConfigInfo(device.getCoreGraphicsScreen(), pixfmt,
+                                       kOpenGLSwapInterval);
+
+            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);
+    }
+
+    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..e5d8362
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWCanvasPeer.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;
+
+import java.awt.BufferCapabilities;
+import java.awt.Canvas;
+import java.awt.Component;
+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);
+    }
+
+    // ---- 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;
+    }
+}
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..0f81d75
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java
@@ -0,0 +1,1395 @@
+/*
+ * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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.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;
+
+    private Color background;
+    private Color foreground;
+    private Font font;
+
+    // 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 final Object dropTargetLock = new Object();
+
+    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;
+        }
+    }
+
+    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) {
+                    if (SunToolkit.isDispatchThreadForAppContext(getTarget())) {
+                        synchronized (getDelegateLock()) {
+                            if (getDelegate().isPaintingForPrint()) {
+                                return;
+                            }
+                        }
+                    }
+                    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();
+        if (getDelegate() != null) {
+            synchronized (getDelegateLock()) {
+                resetColorsAndFont(delegate);
+                getDelegate().setOpaque(true);
+            }
+        }
+        setBackground(target.getBackground());
+        setForeground(target.getForeground());
+        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 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(final Color c) {
+        final Color oldBg = getBackground();
+        if (oldBg == c || (oldBg != null && oldBg.equals(c))) {
+            return;
+        }
+        synchronized (getStateLock()) {
+            background = c;
+        }
+        final D delegate = getDelegate();
+        if (delegate != null) {
+            synchronized (getDelegateLock()) {
+                // delegate will repaint the target
+                delegate.setBackground(c);
+            }
+        } else {
+            repaintPeer();
+        }
+    }
+
+    protected final Color getBackground() {
+        synchronized (getStateLock()) {
+            return background;
+        }
+    }
+
+    @Override
+    public void setForeground(final Color c) {
+        final Color oldFg = getForeground();
+        if (oldFg == c || (oldFg != null && oldFg.equals(c))) {
+            return;
+        }
+        synchronized (getStateLock()) {
+            foreground = c;
+        }
+        final D delegate = getDelegate();
+        if (delegate != null) {
+            synchronized (getDelegateLock()) {
+                // delegate will repaint the target
+                delegate.setForeground(c);
+            }
+        } else {
+            repaintPeer();
+        }
+    }
+
+    protected final Color getForeground() {
+        synchronized (getStateLock()) {
+            return foreground;
+        }
+    }
+
+    @Override
+    public void setFont(final Font f) {
+        final Font oldF = getFont();
+        if (oldF == f || (oldF != null && oldF.equals(f))) {
+            return;
+        }
+        synchronized (getStateLock()) {
+            font = f;
+        }
+        final D delegate = getDelegate();
+        if (delegate != null) {
+            synchronized (getDelegateLock()) {
+                // delegate will repaint the target
+                delegate.setFont(f);
+            }
+        } else {
+            repaintPeer();
+        }
+    }
+
+    protected final Font getFont() {
+        synchronized (getStateLock()) {
+            return font;
+        }
+    }
+
+    @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 final 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 final 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
+    @Override
+    public void addDropTarget(DropTarget dt) {
+        synchronized (dropTargetLock){
+            // 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
+    @Override
+    public void removeDropTarget(DropTarget dt) {
+        synchronized (dropTargetLock){
+            // 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:
+                handleJavaMouseEvent((MouseEvent)e);
+        }
+
+        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(),
+                    me.isPopupTrigger(),
+                    me.getScrollType(),
+                    me.getScrollAmount(),
+                    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;
+    }
+
+    protected void handleJavaMouseEvent(MouseEvent e) {
+        Component target = getTarget();
+        assert (e.getSource() == target);
+
+        if (!target.isFocusOwner() && LWKeyboardFocusManagerPeer.shouldFocusOnClick(target)) {
+            LWKeyboardFocusManagerPeer.requestFocusFor(target, CausedFocusEvent.Cause.MOUSE_EVENT);
+        } else {
+            // Anyway request focus to the toplevel.
+            getWindowPeerOrSelf().requestWindowFocus(CausedFocusEvent.Cause.MOUSE_EVENT);
+        }
+    }
+
+    /**
+     * 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);
+    }
+
+    /**
+     * All peers should clear background before paint.
+     *
+     * @return false on components that DO NOT require a clearRect() before
+     *         painting.
+     */
+    protected final boolean shouldClearRectBeforePaint() {
+        // TODO: sun.awt.noerasebackground
+        return true;
+    }
+
+    /**
+     * 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 final 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..dab0518
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWContainerPeer.java
@@ -0,0 +1,285 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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.Color;
+import java.awt.Container;
+import java.awt.Font;
+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 void setBackground(final Color c) {
+        for (final LWComponentPeer child : getChildren()) {
+            if (!child.getTarget().isBackgroundSet()) {
+                child.setBackground(c);
+            }
+        }
+        super.setBackground(c);
+    }
+
+    @Override
+    public void setForeground(final Color c) {
+        for (final LWComponentPeer child : getChildren()) {
+            if (!child.getTarget().isForegroundSet()) {
+                child.setForeground(c);
+            }
+        }
+        super.setForeground(c);
+    }
+
+    @Override
+    public void setFont(final Font f) {
+        for (final LWComponentPeer child : getChildren()) {
+            if (!child.getTarget().isFontSet()) {
+                child.setFont(f);
+            }
+        }
+        super.setFont(f);
+    }
+
+    @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..4263660
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWKeyboardFocusManagerPeer.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 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;
+        }
+    }
+
+    LWWindowPeer getFocusedWindow() {
+        synchronized (lock) {
+            return focusedWindow;
+        }
+    }
+
+    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..a37c1a6
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWLabelPeer.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 sun.lwawt;
+
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+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 {
+
+    private static final int TEXT_XPAD = 5;
+    private static final int TEXT_YPAD = 1;
+
+    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));
+        }
+    }
+
+    @Override
+    public Dimension getMinimumSize() {
+        int w = TEXT_XPAD;
+        int h = TEXT_YPAD;
+        final FontMetrics fm = getFontMetrics(getFont());
+        if (fm != null) {
+            final String text;
+            synchronized (getDelegateLock()) {
+                text = getDelegate().getText();
+            }
+            if (text != null) {
+                w += fm.stringWidth(text);
+            }
+            h += fm.getHeight();
+        }
+        return new Dimension(w, h);
+    }
+
+    /**
+     * 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..89a2ce9
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWListPeer.java
@@ -0,0 +1,290 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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);
+        if (!getTarget().isBackgroundSet()) {
+            getTarget().setBackground(SystemColor.text);
+        }
+    }
+
+    @Override
+    protected ScrollableJList createDelegate() {
+        return new ScrollableJList();
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        setMultipleMode(getTarget().isMultipleMode());
+        final int[] selectedIndices = getTarget().getSelectedIndexes();
+        synchronized (getDelegateLock()) {
+            getDelegate().setSkipStateChangedEvent(true);
+            getDelegate().getView().setSelectedIndices(selectedIndices);
+            getDelegate().setSkipStateChangedEvent(false);
+        }
+    }
+
+    @Override
+    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);
+            revalidate();
+        }
+    }
+
+    @Override
+    public void delItems(final int start, final int end) {
+        synchronized (getDelegateLock()) {
+            getDelegate().getModel().removeRange(start, end);
+            revalidate();
+        }
+    }
+
+    @Override
+    public void removeAll() {
+        synchronized (getDelegateLock()) {
+            getDelegate().getModel().removeAllElements();
+            revalidate();
+        }
+    }
+
+    @Override
+    public void select(final int index) {
+        synchronized (getDelegateLock()) {
+            getDelegate().setSkipStateChangedEvent(true);
+            getDelegate().getView().setSelectedIndex(index);
+            getDelegate().setSkipStateChangedEvent(false);
+        }
+    }
+
+    @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));
+        }
+    }
+
+    private void revalidate() {
+        synchronized (getDelegateLock()) {
+            getDelegate().getView().invalidate();
+            getDelegate().validate();
+        }
+    }
+
+    final class ScrollableJList extends JScrollPane implements ListSelectionListener {
+
+        private boolean skipStateChangedEvent;
+
+        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]);
+            }
+        }
+
+        public boolean isSkipStateChangedEvent() {
+            return skipStateChangedEvent;
+        }
+
+        public void setSkipStateChangedEvent(boolean skipStateChangedEvent) {
+            this.skipStateChangedEvent = skipStateChangedEvent;
+        }
+
+        @Override
+        public void valueChanged(final ListSelectionEvent e) {
+            if (!e.getValueIsAdjusting() && !isSkipStateChangedEvent()) {
+                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 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());
+                    if (0 <= index && index < getModel().getSize()) {
+                        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 Object selectedValue = getSelectedValue();
+                    if(selectedValue != null){
+                        LWListPeer.this.postEvent(new ActionEvent(getTarget(), ActionEvent.ACTION_PERFORMED,
+                            selectedValue.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..230cb89
--- /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 getBounds().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..d376a6b
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWScrollBarPeer.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 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().setValues(value, visible, minimum, 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) {
+        final int value = e.getValue();
+        synchronized (getDelegateLock()) {
+            if (currentValue == value) {
+                return;
+            }
+            currentValue = value;
+        }
+        getTarget().setValueIsAdjusting(e.getValueIsAdjusting());
+        getTarget().setValue(value);
+        postEvent(new AdjustmentEvent(getTarget(), e.getID(),
+                e.getAdjustmentType(), value,
+                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..a7a214f
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWTextAreaPeer.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.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);
+            revalidate();
+            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);
+            revalidate();
+            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..acc2e29
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.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 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.event.InputMethodListener;
+import java.awt.event.InputMethodEvent;
+import java.awt.im.InputMethodRequests;
+import java.awt.peer.TextComponentPeer;
+import sun.awt.AWTAccessor;
+
+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, InputMethodListener {
+
+    /**
+     * 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);
+        if (!getTarget().isBackgroundSet()) {
+            getTarget().setBackground(SystemColor.text);
+        }
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        synchronized (getDelegateLock()) {
+            // This listener should be added before setText().
+            getTextComponent().getDocument().addDocumentListener(this);
+        }
+        setEditable(getTarget().isEditable());
+        setText(getTarget().getText());
+        getTarget().addInputMethodListener(this);
+        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);
+            revalidate();
+            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() {
+        synchronized (getDelegateLock()) {
+            return getTextComponent().getInputMethodRequests();
+        }
+    }
+
+    @Override
+    public final boolean isFocusable() {
+        return getTarget().isFocusable();
+    }
+
+    protected final void revalidate() {
+        synchronized (getDelegateLock()) {
+            getTextComponent().invalidate();
+            getDelegate().validate();
+        }
+    }
+
+    private void sendTextEvent(final DocumentEvent e) {
+        postEvent(new TextEvent(getTarget(), TextEvent.TEXT_VALUE_CHANGED));
+        synchronized (getDelegateLock()) {
+            revalidate();
+        }
+    }
+
+    @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);
+    }
+
+    @Override
+    public void inputMethodTextChanged(InputMethodEvent event) {
+        synchronized (getDelegateLock()) {
+            AWTAccessor.getComponentAccessor().processEvent(getTextComponent(), event);
+        }
+    }
+
+    @Override
+    public void caretPositionChanged(InputMethodEvent event) {
+        synchronized (getDelegateLock()) {
+            AWTAccessor.getComponentAccessor().processEvent(getTextComponent(), event);
+        }
+    }
+}
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..b9f4641
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWToolkit.java
@@ -0,0 +1,549 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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;
+
+    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);
+        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);
+    }
+
+    public LWWindowPeer createEmbeddedFrame(CEmbeddedFrame target) {
+        PlatformComponent platformComponent = createPlatformComponent();
+        PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.EMBEDDEDFRAME);
+        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);
+
+    // ---- 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);
+    }
+
+    /*
+     * Returns true if the application (one of its windows) owns keyboard focus.
+     */
+    public abstract boolean isApplicationActive();
+
+    // use peer's back buffer to implement non-opaque windows.
+    @Override
+    public boolean needUpdateWindow() {
+        return true;
+    }
+
+    @Override
+    public void grab(Window w) {
+        if (w.getPeer() != null) {
+            ((LWWindowPeer)w.getPeer()).grab();
+        }
+    }
+
+    @Override
+    public void ungrab(Window w) {
+        if (w.getPeer() != null) {
+            ((LWWindowPeer)w.getPeer()).ungrab();
+        }
+    }
+}
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..bfdd10c
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java
@@ -0,0 +1,1241 @@
+/*
+ * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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;
+import sun.util.logging.PlatformLogger;
+
+public class LWWindowPeer
+    extends LWContainerPeer<Window, JComponent>
+    implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
+{
+    public static enum PeerType {
+        SIMPLEWINDOW,
+        FRAME,
+        DIALOG,
+        EMBEDDEDFRAME
+    }
+
+    private static final sun.util.logging.PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
+
+    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 final Object surfaceDataLock = new Object();
+
+    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];
+
+    // 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 volatile boolean isOpaque = true;
+
+    private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
+
+    private static LWWindowPeer grabbingWindow;
+
+    private volatile boolean skipNextFocusChange;
+
+    /**
+     * 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;
+        }
+
+        if (!target.isFontSet()) {
+            target.setFont(DEFAULT_FONT);
+        }
+
+        if (!target.isBackgroundSet()) {
+            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);
+        }
+
+        if (!target.isForegroundSet()) {
+            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.
+        }
+
+        platformWindow.initialize(target, this, ownerDelegate);
+    }
+
+    @Override
+    public void initialize() {
+        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());
+
+        super.initialize();
+
+        updateInsets(platformWindow.getInsets());
+    }
+
+    // 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();
+        synchronized (surfaceDataLock){
+            surfaceData = null;
+        }
+        if (oldData != null) {
+            oldData.invalidate();
+        }
+        if (isGrabbing()) {
+            ungrab();
+        }
+        destroyBuffers();
+        platformWindow.dispose();
+        super.disposeImpl();
+    }
+
+    @Override
+    public void setVisible(final boolean visible) {
+        if (getSurfaceData() == null) {
+            replaceSurfaceData();
+        }
+
+        if (isVisible() == visible) {
+            return;
+        }
+        super.setVisible(visible);
+
+        // 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(visible);
+                if (isSimpleWindow()) {
+                    LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
+                        getInstance(getAppContext());
+
+                    if (visible) {
+                        updateFocusableWindowState();
+                        changeFocusedWindow(true, true);
+
+                    // Focus the owner in case this window is focused.
+                    } else if (manager.getCurrentFocusedWindow() == getTarget()) {
+                        LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
+                        if (owner != null) {
+                            // KFM will do all the rest.
+                            owner.changeFocusedWindow(true, false);
+                        }
+                    }
+                }
+            }
+        });
+    }
+
+    @Override
+    public GraphicsConfiguration getGraphicsConfiguration() {
+        return graphicsConfig;
+    }
+
+    @Override
+    public boolean updateGraphicsData(GraphicsConfiguration gc) {
+        setGraphicsConfig(gc);
+        return false;
+    }
+
+    protected final 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 final Image getBackBuffer() {
+        synchronized (getStateLock()) {
+            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 final void destroyBuffers() {
+        final Image oldBB = getBackBuffer();
+        synchronized (getStateLock()) {
+            backBuffer = null;
+        }
+        if (oldBB != null) {
+            oldBB.flush();
+        }
+    }
+
+    @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);
+        repaintPeer();
+    }
+
+    @Override
+    public final void setOpaque(final boolean isOpaque) {
+        if (this.isOpaque != isOpaque) {
+            this.isOpaque = isOpaque;
+            getPlatformWindow().setOpaque(isOpaque);
+            replaceSurfaceData();
+            repaintPeer();
+        }
+    }
+
+    public final 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) {
+        setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK);
+    }
+
+    @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);
+    }
+
+    // MouseDown in non-client area
+    public void notifyNCMouseDown() {
+        // Ungrab except for a click on a Dialog with the grabbing owner
+        if (grabbingWindow != null &&
+            grabbingWindow != getOwnerFrameDialog(this))
+        {
+            grabbingWindow.ungrab();
+        }
+    }
+
+    // ---- 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
+
+            int eventButtonMask = (button > 0)? MouseEvent.getMaskForButton(button) : 0;
+            int otherButtonsPressed = modifiers & ~eventButtonMask;
+
+            // For pressed/dragged/released events OS X treats other
+            // mouse buttons as if they were BUTTON2, so we do the same
+            int targetIdx = (button > 3) ? 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) {
+
+                // Ungrab only if this window is not an owned window of the grabbing one.
+                if (!isGrabbing() && grabbingWindow != null &&
+                    grabbingWindow != getOwnerFrameDialog(this))
+                {
+                    grabbingWindow.ungrab();
+                }
+                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 &= ~modifiers;
+            } 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 ((modifiers & 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 SurfaceData getSurfaceData() {
+        synchronized (surfaceDataLock) {
+            return surfaceData;
+        }
+    }
+
+    private void replaceSurfaceData() {
+        replaceSurfaceData(backBufferCount, backBufferCaps);
+    }
+
+    private void replaceSurfaceData(int newBackBufferCount,
+                                                 BufferCapabilities newBackBufferCaps) {
+        synchronized (surfaceDataLock) {
+            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();
+            repaintPeer();
+        }
+
+        return changed;
+    }
+
+    public static LWWindowPeer getWindowUnderCursor() {
+        return lastMouseEventPeer != null ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
+    }
+
+    public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
+        if (focusLog.isLoggable(PlatformLogger.FINE)) {
+            focusLog.fine("requesting native focus to " + this);
+        }
+
+        if (!focusAllowedFor()) {
+            focusLog.fine("focus is not allowed");
+            return false;
+        }
+
+        // Cross-app activation requests are not allowed.
+        if (cause != CausedFocusEvent.Cause.MOUSE_EVENT &&
+            !((LWToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
+        {
+            focusLog.fine("the app is inactive, so the request is rejected");
+            return false;
+        }
+
+        Window currentActive = KeyboardFocusManager.
+            getCurrentKeyboardFocusManager().getActiveWindow();
+
+        // Make the owner active window.
+        if (isSimpleWindow()) {
+            LWWindowPeer owner = getOwnerFrameDialog(this);
+
+            // If owner is not natively active, request native
+            // activation on it w/o sending events up to java.
+            if (owner != null && !owner.platformWindow.isActive()) {
+                if (focusLog.isLoggable(PlatformLogger.FINE)) {
+                    focusLog.fine("requesting native focus to the owner " + owner);
+                }
+                LWWindowPeer currentActivePeer = (currentActive != null ?
+                    (LWWindowPeer)currentActive.getPeer() : null);
+
+                // Ensure the opposite is natively active and suppress sending events.
+                if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) {
+                    if (focusLog.isLoggable(PlatformLogger.FINE)) {
+                        focusLog.fine("the opposite is " + currentActivePeer);
+                    }
+                    currentActivePeer.skipNextFocusChange = true;
+                }
+                owner.skipNextFocusChange = true;
+
+                owner.platformWindow.requestWindowFocus();
+            }
+
+            // DKFM will synthesize all the focus/activation events correctly.
+            changeFocusedWindow(true, false);
+            return true;
+
+        // In case the toplevel is active but not focused, change focus directly,
+        // as requesting native focus on it will not have effect.
+        } else if (getTarget() == currentActive && !getTarget().hasFocus()) {
+
+            changeFocusedWindow(true, false);
+            return true;
+        }
+        return platformWindow.requestWindowFocus();
+    }
+
+    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 (focusLog.isLoggable(PlatformLogger.FINE)) {
+            focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this);
+        }
+        if (isShowing && !getTarget().isAutoRequestFocus() || skipNextFocusChange) {
+            focusLog.fine("skipping focus change");
+            skipNextFocusChange = false;
+            return;
+        }
+
+        if (!cachedFocusableWindow) {
+            return;
+        }
+        if (becomesFocused) {
+            synchronized (getPeerTreeLock()) {
+                if (blocker != null) {
+                    if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                        focusLog.finest("the window is blocked by " + blocker);
+                    }
+                    return;
+                }
+            }
+        }
+
+        LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
+            getInstance(getAppContext());
+
+        Window oppositeWindow = becomesFocused ? manager.getCurrentFocusedWindow() : null;
+
+        // Note, the method is not called:
+        // - when the opposite (gaining focus) window is an owned/owner window.
+        // - for a simple window in any case.
+        if (!becomesFocused &&
+            (isGrabbing() || getOwnerFrameDialog(grabbingWindow) == this))
+        {
+            focusLog.fine("ungrabbing on " + grabbingWindow);
+            // ungrab a simple window if its owner looses activation.
+            grabbingWindow.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);
+    }
+
+    private static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
+        Window owner = (peer != null ? peer.getTarget().getOwner() : null);
+        while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
+            owner = owner.getOwner();
+        }
+        return owner != null ? (LWWindowPeer)owner.getPeer() : null;
+    }
+
+    /**
+     * 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();
+    }
+
+    public long getLayerPtr() {
+        return getPlatformWindow().getLayerPtr();
+    }
+
+    void grab() {
+        if (grabbingWindow != null && !isGrabbing()) {
+            grabbingWindow.ungrab();
+        }
+        grabbingWindow = this;
+    }
+
+    void ungrab() {
+        if (isGrabbing()) {
+            grabbingWindow = null;
+            postEvent(new UngrabEvent(getTarget()));
+        }
+    }
+
+    private boolean isGrabbing() {
+        return this == grabbingWindow;
+    }
+
+    @Override
+    public String toString() {
+        return super.toString() + " [target is " + getTarget() + "]";
+    }
+}
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..aeee260
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.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 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();
+
+    /*
+     * Returns true only when called on a frame/dialog when it's natively focused.
+     */
+    public boolean isActive();
+
+    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);
+
+    public long getLayerPtr();
+
+    public LWWindowPeer getPeer();
+}
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..5dd1844
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CCustomCursor.java
@@ -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.
+ */
+
+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;
+    private boolean isImageOk = false;
+    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;
+            isImageOk = false;
+        } else {
+            isImageOk = true;
+        }
+
+        // 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) {
+            return fCImage.ptr;
+        }
+
+        if (isImageOk) {
+            try {
+                fCImage = CImage.getCreator().createFromImage(fImage);
+
+                if (fCImage == null) {
+                    isImageOk = false;
+                    return 0L;
+                } else {
+                    return fCImage.ptr;
+                }
+            } catch (IllegalArgumentException iae) {
+                // Silently return null - we want to hide cursor by providing an empty
+                // ByteArray or just null
+                return 0L;
+            }
+        }
+
+        return 0L;
+    }
+
+    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..98088fb
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CDropTarget.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 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;
+        if (model.getPlatformWindow() instanceof CPlatformWindow) {
+            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..181d084
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CDropTargetContextPeer.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 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();
+        Point screenPoint = event.getPoint();
+        SwingUtilities.convertPointToScreen(screenPoint, eventSource);
+        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;
+            }
+        } else {
+            if(screenBounds.contains(screenPoint)) {
+                processEnterMessage(event);
+                insideTarget = true;
+            } else {
+                return;
+            }
+        }
+        super.processMotionMessage(event, operationChanged);
+    }
+
+    @Override
+    protected void processDropMessage(SunDropTargetEvent event) {
+        Component eventSource = (Component)event.getComponent();
+        Point screenPoint = event.getPoint();
+        SwingUtilities.convertPointToScreen(screenPoint, eventSource);
+        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/CEmbeddedFrame.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java
new file mode 100644
index 0000000..147b127
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.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 sun.lwawt.macosx;
+
+import sun.lwawt.LWToolkit;
+import sun.lwawt.LWWindowPeer;
+import sun.lwawt.macosx.CocoaConstants;
+import sun.lwawt.macosx.event.NSEvent;
+
+import sun.awt.EmbeddedFrame;
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class CEmbeddedFrame extends EmbeddedFrame {
+
+    private CPlatformResponder responder;
+
+    public CEmbeddedFrame() {
+        show();
+    }
+
+    public void addNotify() {
+        if (getPeer() == null) {
+            LWToolkit toolkit = (LWToolkit)Toolkit.getDefaultToolkit();
+            LWWindowPeer peer = toolkit.createEmbeddedFrame(this);
+            setPeer(peer);
+            responder = new CPlatformResponder(peer, true);
+        }
+        super.addNotify();
+    }
+
+    public void registerAccelerator(AWTKeyStroke stroke) {}
+
+    public void unregisterAccelerator(AWTKeyStroke stroke) {}
+
+    protected long getLayerPtr() {
+        LWWindowPeer peer = (LWWindowPeer)getPeer();
+        return peer.getLayerPtr();
+    }
+
+    // -----------------------------------------------------------------------
+    //                          SYNTHETIC EVENT DELIVERY
+    // -----------------------------------------------------------------------
+
+    public void handleMouseEvent(int eventType, int modifierFlags, double pluginX,
+                                 double pluginY, int buttonNumber, int clickCount) {
+        int x = (int)pluginX;
+        int y = (int)pluginY;
+        Point locationOnScreen = getLocationOnScreen();
+        int screenX = locationOnScreen.x + x;
+        int screenY = locationOnScreen.y + y;
+
+        responder.handleMouseEvent(eventType, modifierFlags, buttonNumber,
+                                   clickCount, x, y, screenX, screenY);
+    }
+
+    public void handleScrollEvent(double pluginX, double pluginY, int modifierFlags,
+                                  double deltaX, double deltaY, double deltaZ) {
+        int x = (int)pluginX;
+        int y = (int)pluginY;
+
+        responder.handleScrollEvent(x, y, modifierFlags, deltaX, deltaY);
+    }
+
+    public void handleKeyEvent(int eventType, int modifierFlags, String characters,
+                               String charsIgnoringMods, boolean isRepeat, short keyCode) {
+        responder.handleKeyEvent(eventType, modifierFlags, charsIgnoringMods, keyCode);
+    }
+
+    public void handleInputEvent(String text) {
+        new RuntimeException("Not implemented");
+    }
+}
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..ecb2d52
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java
@@ -0,0 +1,817 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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) {
+        if (peer.getPlatformWindow() instanceof CPlatformWindow) {
+            CPlatformWindow platformWindow = (CPlatformWindow) peer.getPlatformWindow();
+            CPlatformView platformView = platformWindow.getContentView();
+            return platformView.getAWTView();
+        } else {
+            return 0;
+        }
+    }
+
+    /**
+        * 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..dec2547
--- /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;
+    PlatformWindow 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 = platformWindow;
+
+        long windowLayerPtr = platformWindow.getLayerPtr();
+        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/CPlatformEmbeddedFrame.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java
new file mode 100644
index 0000000..e4e9314
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java
@@ -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.
+ */
+
+package sun.lwawt.macosx;
+
+import sun.lwawt.PlatformWindow;
+import sun.lwawt.LWWindowPeer;
+
+import sun.java2d.opengl.CGLLayer;
+import sun.java2d.SurfaceData;
+
+import sun.awt.CGraphicsConfig;
+import sun.awt.CGraphicsDevice;
+
+import java.awt.*;
+import java.awt.BufferCapabilities.FlipContents;
+
+/*
+ * Provides a lightweight implementation of the EmbeddedFrame.
+ */
+public class CPlatformEmbeddedFrame implements PlatformWindow {
+
+    private CGLLayer windowLayer;
+    private LWWindowPeer peer;
+
+    private volatile int screenX = 0;
+    private volatile int screenY = 0;
+
+    @Override // PlatformWindow
+    public void initialize(Window target, final LWWindowPeer peer, PlatformWindow owner) {
+        this.peer = peer;
+        this.windowLayer = new CGLLayer(peer);
+    }
+
+    @Override
+    public LWWindowPeer getPeer() {
+        return peer;
+    }
+
+    @Override
+    public long getLayerPtr() {
+        return windowLayer.getPointer();
+    }
+
+    @Override
+    public void dispose() {
+        windowLayer.dispose();
+    }
+
+    @Override
+    public void setBounds(int x, int y, int w, int h) {
+        // This is a lightweight implementation of the EmbeddedFrame
+        // and we simply synthesize a reshape request.
+        screenX = x;
+        screenY = y;
+        peer.notifyReshape(x, y, w, h);
+    }
+
+    @Override
+    public int getScreenImOn() {
+        // REMIND: return the main screen for the initial implementation
+        CGraphicsConfig gc = (CGraphicsConfig)peer.getGraphicsConfiguration();
+        CGraphicsDevice device = gc.getDevice();
+        return device.getCoreGraphicsScreen();
+    }
+
+    @Override
+    public Point getLocationOnScreen() {
+        return new Point(screenX, screenY);
+    }
+
+    @Override
+    public FontMetrics getFontMetrics(Font f) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    @Override
+    public SurfaceData getScreenSurface() {
+        return windowLayer.getSurfaceData();
+    }
+
+    @Override
+    public SurfaceData replaceSurfaceData() {
+        return windowLayer.replaceSurfaceData();
+    }
+
+    @Override
+    public Image createBackBuffer() {
+        Rectangle r = peer.getBounds();
+        Image im = null;
+        if (!r.isEmpty()) {
+            int transparency = (peer.isOpaque() ? Transparency.OPAQUE : Transparency.TRANSLUCENT);
+            im = peer.getGraphicsConfiguration().createCompatibleImage(r.width, r.height, transparency);
+        }
+        return im;
+    }
+
+    @Override
+    public void flip(int x1, int y1, int x2, int y2, FlipContents flipAction) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    @Override
+    public void setVisible(boolean visible) {}
+
+    @Override
+    public void setTitle(String title) {}
+
+    @Override
+    public Insets getInsets() {
+        return new Insets(0, 0, 0, 0);
+    }
+
+    @Override
+    public void toFront() {}
+
+    @Override
+    public void toBack() {}
+
+    @Override
+    public void setMenuBar(MenuBar mb) {}
+
+    @Override
+    public void setAlwaysOnTop(boolean value) {}
+
+    @Override
+    public void updateFocusableWindowState() {}
+
+    @Override
+    public boolean requestWindowFocus() {
+        return true;
+    }
+
+    @Override
+    public boolean isActive() {
+        return true;
+    }
+
+    @Override
+    public void setResizable(boolean resizable) {}
+
+    @Override
+    public void setMinimumSize(int width, int height) {}
+
+    @Override
+    public Graphics transformGraphics(Graphics g) {
+        return g;
+    }
+
+    @Override
+    public void updateIconImages() {}
+
+    @Override
+    public void setOpacity(float opacity) {}
+
+    @Override
+    public void setOpaque(boolean isOpaque) {}
+
+    @Override
+    public void enterFullScreenMode() {}
+
+    @Override
+    public void exitFullScreenMode() {}
+
+    @Override
+    public void setWindowState(int windowState) {}
+}
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java
new file mode 100644
index 0000000..4a54c4b
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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.LWWindowPeer;
+import sun.lwawt.macosx.event.NSEvent;
+import java.awt.Toolkit;
+import java.awt.event.MouseEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.KeyEvent;
+
+/**
+ * Translates NSEvents/NPCocoaEvents into AWT events.
+ */
+final class CPlatformResponder {
+
+    private final LWWindowPeer peer;
+    private final boolean isNpapiCallback;
+
+    CPlatformResponder(final LWWindowPeer peer, final boolean isNpapiCallback) {
+        this.peer = peer;
+        this.isNpapiCallback = isNpapiCallback;
+    }
+
+    /**
+     * Handles mouse events.
+     */
+    void handleMouseEvent(int eventType, int modifierFlags, int buttonNumber,
+                          int clickCount, int x, int y, int absoluteX,
+                          int absoluteY) {
+        final SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit();
+        if ((buttonNumber > 2 && !tk.areExtraMouseButtonsEnabled())
+                || buttonNumber > tk.getNumberOfButtons() - 1) {
+            return;
+        }
+
+        int jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
+                                           NSEvent.nsToJavaEventType(eventType);
+
+        int jbuttonNumber = MouseEvent.NOBUTTON;
+        int jclickCount = 0;
+
+        if (jeventType != MouseEvent.MOUSE_MOVED &&
+            jeventType != MouseEvent.MOUSE_ENTERED &&
+            jeventType != MouseEvent.MOUSE_EXITED)
+        {
+            jbuttonNumber = NSEvent.nsToJavaButton(buttonNumber);
+            jclickCount = clickCount;
+        }
+
+        int jmodifiers = NSEvent.nsToJavaMouseModifiers(buttonNumber,
+                                                        modifierFlags);
+        boolean jpopupTrigger = NSEvent.isPopupTrigger(jmodifiers);
+
+        peer.dispatchMouseEvent(jeventType, System.currentTimeMillis(), jbuttonNumber,
+                                x, y, absoluteX, absoluteY, jmodifiers, jclickCount,
+                                jpopupTrigger, null);
+    }
+
+    /**
+     * Handles scroll events.
+     */
+    void handleScrollEvent(final int x, final int y, final int modifierFlags,
+                           final double deltaX, final double deltaY) {
+        final int buttonNumber = CocoaConstants.kCGMouseButtonCenter;
+        int jmodifiers = NSEvent.nsToJavaMouseModifiers(buttonNumber,
+                                                        modifierFlags);
+        final boolean isShift = (jmodifiers & InputEvent.SHIFT_DOWN_MASK) != 0;
+
+        // Vertical scroll.
+        if (!isShift && deltaY != 0.0) {
+            dispatchScrollEvent(x, y, jmodifiers, deltaY);
+        }
+        // Horizontal scroll or shirt+vertical scroll.
+        final double delta = isShift && deltaY != 0.0 ? deltaY : deltaX;
+        if (delta != 0.0) {
+            jmodifiers |= InputEvent.SHIFT_DOWN_MASK;
+            dispatchScrollEvent(x, y, jmodifiers, delta);
+        }
+    }
+
+    private void dispatchScrollEvent(final int x, final int y,
+                                     final int modifiers, final double delta) {
+        final long when = System.currentTimeMillis();
+        final int scrollType = MouseWheelEvent.WHEEL_UNIT_SCROLL;
+        final int scrollAmount = 1;
+        peer.dispatchMouseWheelEvent(when, x, y, modifiers, scrollType,
+                                     scrollAmount, (int) -delta, -delta, null);
+    }
+
+    /**
+     * Handles key events.
+     */
+    void handleKeyEvent(int eventType, int modifierFlags, String chars,
+                        short keyCode) {
+        boolean isFlagsChangedEvent =
+            isNpapiCallback ? (eventType == CocoaConstants.NPCocoaEventFlagsChanged) :
+                              (eventType == CocoaConstants.NSFlagsChanged);
+
+        int jeventType = KeyEvent.KEY_PRESSED;
+        int jkeyCode = KeyEvent.VK_UNDEFINED;
+        int jkeyLocation = KeyEvent.KEY_LOCATION_UNKNOWN;
+        boolean postsTyped = false;
+
+        char testChar = KeyEvent.CHAR_UNDEFINED;
+        char testDeadChar = 0;
+
+        if (isFlagsChangedEvent) {
+            int[] in = new int[] {modifierFlags, keyCode};
+            int[] out = new int[3]; // [jkeyCode, jkeyLocation, jkeyType]
+
+            NSEvent.nsKeyModifiersToJavaKeyInfo(in, out);
+
+            jkeyCode = out[0];
+            jkeyLocation = out[1];
+            jeventType = out[2];
+        } else {
+            if (chars != null && chars.length() > 0) {
+                testChar = chars.charAt(0);
+            }
+
+            int[] in = new int[] {testChar, testDeadChar, modifierFlags, keyCode};
+            int[] out = new int[2]; // [jkeyCode, jkeyLocation]
+
+            postsTyped = NSEvent.nsToJavaKeyInfo(in, out);
+            if (!postsTyped) {
+                testChar = KeyEvent.CHAR_UNDEFINED;
+            }
+
+            jkeyCode = out[0];
+            jkeyLocation = out[1];
+            jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
+                                           NSEvent.nsToJavaEventType(eventType);
+        }
+
+        int jmodifiers = NSEvent.nsToJavaKeyModifiers(modifierFlags);
+        long when = System.currentTimeMillis();
+
+        peer.dispatchKeyEvent(jeventType, when, jmodifiers,
+                              jkeyCode, testChar, jkeyLocation);
+
+        // 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 = (jmodifiers & KeyEvent.META_DOWN_MASK) != 0;
+        if (jeventType == KeyEvent.KEY_PRESSED && postsTyped && !isMetaDown) {
+            peer.dispatchKeyEvent(KeyEvent.KEY_TYPED, when, jmodifiers,
+                                  KeyEvent.VK_UNDEFINED, testChar,
+                                  KeyEvent.KEY_LOCATION_UNKNOWN);
+        }
+    }
+}
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..04bcb74
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformView.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.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;
+    private CPlatformResponder responder;
+
+    public CPlatformView() {
+        super(0, true);
+    }
+
+    public void initialize(LWWindowPeer peer) {
+        this.peer = peer;
+        this.responder = new CPlatformResponder(peer, false);
+
+        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
+    // ----------------------------------------------------------------------
+
+    private void deliverMouseEvent(NSEvent event) {
+        int x = event.getX();
+        int y = getBounds().height - event.getY();
+
+        if (event.getType() == CocoaConstants.NSScrollWheel) {
+            responder.handleScrollEvent(x, y, event.getModifierFlags(),
+                                        event.getScrollDeltaX(), event.getScrollDeltaY());
+        } else {
+            responder.handleMouseEvent(event.getType(), event.getModifierFlags(), event.getButtonNumber(),
+                                       event.getClickCount(), x, y, event.getAbsX(), event.getAbsY());
+        }
+    }
+
+    private void deliverKeyEvent(NSEvent event) {
+        responder.handleKeyEvent(event.getType(), event.getModifierFlags(),
+                                 event.getCharactersIgnoringModifiers(), event.getKeyCode());
+    }
+
+    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..ae3fbd5
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
@@ -0,0 +1,878 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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);
+
+    // Loger to report issues happened during execution but that do not affect functionality
+    private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.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();
+        }
+    };
+
+    // 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;
+        if (_owner instanceof CPlatformWindow) {
+            this.owner = (CPlatformWindow)_owner;
+        }
+
+        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) {
+        final long nsWindowPtr = getNSWindowPtr();
+
+        if (owner != null) {
+            if (!visible) {
+                CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), nsWindowPtr);
+            }
+        }
+
+        updateIconImages();
+        updateFocusabilityForAutoRequestFocus(false);
+
+        if (!visible) {
+            // Cancel out the current native state of the window
+            switch (peer.getState()) {
+                case Frame.ICONIFIED:
+                    CWrapper.NSWindow.deminiaturize(nsWindowPtr);
+                    break;
+                case Frame.MAXIMIZED_BOTH:
+                    CWrapper.NSWindow.zoom(nsWindowPtr);
+                    break;
+            }
+        }
+
+        LWWindowPeer blocker = peer.getBlocker();
+        if (blocker == null || !visible) {
+            // If it ain't blocked, or is being hidden, go regular way
+            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);
+                }
+            } else {
+                CWrapper.NSWindow.orderOut(nsWindowPtr);
+            }
+        } else {
+            // otherwise, put it in a proper z-order
+            CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowBelow,
+                    ((CPlatformWindow)blocker.getPlatformWindow()).getNSWindowPtr());
+        }
+
+        if (visible) {
+            // Re-apply the extended state as expected in shared code
+            if (target instanceof Frame) {
+                switch (((Frame)target).getExtendedState()) {
+                    case Frame.ICONIFIED:
+                        CWrapper.NSWindow.miniaturize(nsWindowPtr);
+                        break;
+                    case Frame.MAXIMIZED_BOTH:
+                        CWrapper.NSWindow.zoom(nsWindowPtr);
+                        break;
+                }
+            }
+        }
+
+        updateFocusabilityForAutoRequestFocus(true);
+
+        if (owner != null) {
+            if (visible) {
+                CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove);
+                if (target.isAlwaysOnTop()) {
+                    CWrapper.NSWindow.setLevel(nsWindowPtr, CWrapper.NSWindow.NSFloatingWindowLevel);
+                }
+            }
+        }
+
+        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() {
+        long ptr = getNSWindowPtr();
+        if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) {
+            CWrapper.NSWindow.makeMainWindow(ptr);
+        }
+        CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
+        return true;
+    }
+
+    @Override
+    public boolean isActive() {
+        long ptr = getNSWindowPtr();
+        return CWrapper.NSWindow.isKeyWindow(ptr);
+    }
+
+    @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) {
+        if (!peer.isVisible()) {
+            // setVisible() applies the state
+            return;
+        }
+
+        int prevWindowState = peer.getState();
+        if (prevWindowState == windowState) return;
+
+        final long nsWindowPtr = getNSWindowPtr();
+        switch (windowState) {
+            case Frame.ICONIFIED:
+                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
+    // ----------------------------------------------------------------------
+
+    /*
+     * 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.
+     */
+    @Override
+    public LWWindowPeer getPeer() {
+        return peer;
+    }
+
+    public CPlatformView getContentView() {
+        return contentView;
+    }
+
+    @Override
+    public long getLayerPtr() {
+        return contentView.getWindowLayerPtr();
+    }
+
+    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);
+    }
+
+    private void deliverNCMouseDown() {
+        peer.notifyNCMouseDown();
+    }
+
+    /*
+     * 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);
+        if (target.isAlwaysOnTop()) {
+            CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel);
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    //                          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..e04a45f
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CRobot.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 sun.lwawt.macosx;
+
+import java.awt.*;
+import java.awt.peer.*;
+
+import sun.awt.CGraphicsDevice;
+
+class CRobot implements RobotPeer {
+    private static final int MOUSE_LOCATION_UNKNOWN      = -1;
+
+    private final CGraphicsDevice fDevice;
+    private int mouseLastX = MOUSE_LOCATION_UNKNOWN;
+    private int mouseLastY = MOUSE_LOCATION_UNKNOWN;
+
+    // OS X doesn't generate dragged event as a result of button press and
+    // mouse move events. This means that we have to track buttons state
+    // in order to generate dragged events ourselves.
+    private int mouseButtonsState = 0;
+
+    /**
+     * 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) {
+        mouseLastX = x;
+        mouseLastY = y;
+
+        mouseEvent(fDevice.getCoreGraphicsScreen(), mouseLastX, mouseLastY,
+                   mouseButtonsState, true, true);
+    }
+
+    /**
+     * 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) {
+        mouseButtonsState |= buttons;
+
+        mouseEvent(fDevice.getCoreGraphicsScreen(), mouseLastX, mouseLastY,
+                   buttons, true, false);
+    }
+
+    /**
+     * 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) {
+        mouseButtonsState &= ~buttons;
+
+        mouseEvent(fDevice.getCoreGraphicsScreen(), mouseLastX, mouseLastY,
+                   buttons, false, false);
+    }
+
+    @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) {
+        int c[] = new int[bounds.width * bounds.height];
+        getScreenPixels(bounds, c);
+
+        return c;
+    }
+
+    private native void initRobot();
+    private native void mouseEvent(int screen, int lastX, int lastY,
+                                   int buttonsState,
+                                   boolean isButtonsDownState,
+                                   boolean isMouseMove);
+    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..bc25f18
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CWrapper.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 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;
+
+        // Window level constants
+        // The number of supported levels: (we'll use more in the future)
+        public static final int MAX_WINDOW_LEVELS = 2;
+        // The levels: (these are NOT real constants, these are keys. See native code.)
+        public static final int NSNormalWindowLevel = 0;
+        public static final int NSFloatingWindowLevel = 1;
+
+        // 'level' is one of the keys defined above
+        public static native void setLevel(long window, int level);
+
+        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..ca80d43
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CocoaConstants.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;
+
+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
+    */
+
+    // See http://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html
+
+    public final static int kCGMouseButtonLeft   = 0;
+    public final static int kCGMouseButtonRight  = 1;
+    public final static int kCGMouseButtonCenter = 2;
+
+    // See https://wiki.mozilla.org/NPAPI:CocoaEventModel
+
+    public final static int NPCocoaEventDrawRect           = 1;
+    public final static int NPCocoaEventMouseDown          = 2;
+    public final static int NPCocoaEventMouseUp            = 3;
+    public final static int NPCocoaEventMouseMoved         = 4;
+    public final static int NPCocoaEventMouseEntered       = 5;
+    public final static int NPCocoaEventMouseExited        = 6;
+    public final static int NPCocoaEventMouseDragged       = 7;
+    public final static int NPCocoaEventKeyDown            = 8;
+    public final static int NPCocoaEventKeyUp              = 9;
+    public final static int NPCocoaEventFlagsChanged       = 10;
+    public final static int NPCocoaEventFocusChanged       = 11;
+    public final static int NPCocoaEventWindowFocusChanged = 12;
+    public final static int NPCocoaEventScrollWheel        = 13;
+    public final static int NPCocoaEventTextInput          = 14;
+}
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..8365a50
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
@@ -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.
+ */
+
+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.event.KeyEvent;
+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 {
+    // While it is possible to enumerate all mouse devices
+    // and query them for the number of buttons, the code
+    // that does it is rather complex. Instead, we opt for
+    // the easy way and just support up to 5 mouse buttons,
+    // like Windows.
+    private static final int BUTTONS = 5;
+
+    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");
+
+        areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
+        //set system property if not yet assigned
+        System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
+    }
+
+    /*
+     * 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) {
+        if (peerType == PeerType.EMBEDDEDFRAME) {
+            return new CPlatformEmbeddedFrame();
+        } else {
+            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 RobotPeer createRobot(Robot target, GraphicsDevice screen) {
+        return new CRobot(target, (CGraphicsDevice)screen);
+    }
+
+    private native boolean isCapsLockOn();
+
+    /*
+     * NOTE: Among the keys this method is supposed to check,
+     * only Caps Lock works as a true locking key with OS X.
+     * There is no Scroll Lock key on modern Apple keyboards,
+     * and with a PC keyboard plugged in Scroll Lock is simply
+     * ignored: no LED lights up if you press it.
+     * The key located at the same position on Apple keyboards
+     * as Num Lock on PC keyboards is called Clear, doesn't lock
+     * anything and is used for entirely different purpose.
+     */
+    public boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException {
+        switch (keyCode) {
+            case KeyEvent.VK_NUM_LOCK:
+            case KeyEvent.VK_SCROLL_LOCK:
+            case KeyEvent.VK_KANA_LOCK:
+                throw new UnsupportedOperationException("Toolkit.getLockingKeyState");
+
+            case KeyEvent.VK_CAPS_LOCK:
+                return isCapsLockOn();
+
+            default:
+                throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
+        }
+    }
+
+    //Is it allowed to generate events assigned to extra mouse buttons.
+    //Set to true by default.
+    private static boolean areExtraMouseButtonsEnabled = true;
+
+    public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
+        return areExtraMouseButtonsEnabled;
+    }
+
+    public int getNumberOfButtons(){
+        return BUTTONS;
+    }
+
+
+    @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();
+    }
+
+    @Override
+    public native boolean isApplicationActive();
+
+    /************************
+     * 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..9648da30
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/event/NSEvent.java
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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;
+    private int modifierFlags;
+
+    // Mouse event information
+    private int clickCount;
+    private int buttonNumber;
+    private int x;
+    private int y;
+    private double scrollDeltaY;
+    private double scrollDeltaX;
+    private int absX;
+    private int absY;
+
+    // Key event information
+    private short keyCode;
+    private String charactersIgnoringModifiers;
+
+    public NSEvent(int type, int modifierFlags, short keyCode, String charactersIgnoringModifiers) {
+        this.type = type;
+        this.modifierFlags = modifierFlags;
+        this.keyCode = keyCode;
+        this.charactersIgnoringModifiers = charactersIgnoringModifiers;
+    }
+
+    public NSEvent(int type, int modifierFlags, int clickCount, int buttonNumber,
+                   int x, int y, int absX, int absY,
+                   double scrollDeltaY, double scrollDeltaX) {
+        this.type = type;
+        this.modifierFlags = modifierFlags;
+        this.clickCount = clickCount;
+        this.buttonNumber = buttonNumber;
+        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 getModifierFlags() {
+        return modifierFlags;
+    }
+
+    public int getClickCount() {
+        return clickCount;
+    }
+
+    public int getButtonNumber() {
+        return buttonNumber;
+    }
+
+    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;
+    }
+
+    public short getKeyCode() {
+        return keyCode;
+    }
+
+    public String getCharactersIgnoringModifiers() {
+        return charactersIgnoringModifiers;
+    }
+
+    @Override
+    public String toString() {
+        return "NSEvent[" + getType() + " ," + getModifierFlags() + " ,"
+                + getClickCount() + " ," + getButtonNumber() + " ," + getX() + " ,"
+                + getY() + " ," + getAbsX() + " ," + getAbsY()+ " ," + getKeyCode() + " ,"
+                + getCharactersIgnoringModifiers() + "]";
+    }
+
+    /*
+     * Converts an NSEvent button number to a MouseEvent constant.
+     */
+    public static int nsToJavaButton(int buttonNumber) {
+        int jbuttonNumber = buttonNumber + 1;
+        switch (buttonNumber) {
+            case CocoaConstants.kCGMouseButtonLeft:
+                jbuttonNumber = MouseEvent.BUTTON1;
+                break;
+            case CocoaConstants.kCGMouseButtonRight:
+                jbuttonNumber = MouseEvent.BUTTON3;
+                break;
+            case CocoaConstants.kCGMouseButtonCenter:
+                jbuttonNumber = MouseEvent.BUTTON2;
+                break;
+        }
+        return jbuttonNumber;
+    }
+
+    /*
+     * Converts NPCocoaEvent types to AWT event types.
+     */
+    public static int npToJavaEventType(int npEventType) {
+        int jeventType = 0;
+        switch (npEventType) {
+            case CocoaConstants.NPCocoaEventMouseDown:
+                jeventType = MouseEvent.MOUSE_PRESSED;
+                break;
+            case CocoaConstants.NPCocoaEventMouseUp:
+                jeventType = MouseEvent.MOUSE_RELEASED;
+                break;
+            case CocoaConstants.NPCocoaEventMouseMoved:
+                jeventType = MouseEvent.MOUSE_MOVED;
+                break;
+            case CocoaConstants.NPCocoaEventMouseEntered:
+                jeventType = MouseEvent.MOUSE_ENTERED;
+                break;
+            case CocoaConstants.NPCocoaEventMouseExited:
+                jeventType = MouseEvent.MOUSE_EXITED;
+                break;
+            case CocoaConstants.NPCocoaEventMouseDragged:
+                jeventType = MouseEvent.MOUSE_DRAGGED;
+                break;
+            case CocoaConstants.NPCocoaEventKeyDown:
+                jeventType = KeyEvent.KEY_PRESSED;
+                break;
+            case CocoaConstants.NPCocoaEventKeyUp:
+                jeventType = KeyEvent.KEY_RELEASED;
+                break;
+        }
+        return jeventType;
+    }
+
+    /*
+     * Converts NSEvent types to AWT event types.
+     */
+    public static int nsToJavaEventType(int nsEventType) {
+        int jeventType = 0;
+        switch (nsEventType) {
+            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;
+                break;
+            case CocoaConstants.NSKeyDown:
+                jeventType = KeyEvent.KEY_PRESSED;
+                break;
+            case CocoaConstants.NSKeyUp:
+                jeventType = KeyEvent.KEY_RELEASED;
+                break;
+        }
+        return jeventType;
+    }
+
+    /*
+     * Converts NSEvent mouse modifiers to AWT mouse modifiers.
+     */
+    public static native int nsToJavaMouseModifiers(int buttonNumber,
+                                                    int modifierFlags);
+
+    /*
+     * Converts NSEvent key modifiers to AWT key modifiers.
+     */
+    public static native int nsToJavaKeyModifiers(int modifierFlags);
+
+    /*
+     * Converts NSEvent key info to AWT key info.
+     */
+    public static native boolean nsToJavaKeyInfo(int[] in, int[] out);
+
+    /*
+     * Converts NSEvent key modifiers to AWT key info.
+     */
+    public static native void nsKeyModifiersToJavaKeyInfo(int[] in, int[] out);
+
+    public static boolean isPopupTrigger(int jmodifiers) {
+        final boolean isRightButtonDown = ((jmodifiers & InputEvent.BUTTON3_DOWN_MASK) != 0);
+        final boolean isLeftButtonDown = ((jmodifiers & InputEvent.BUTTON1_DOWN_MASK) != 0);
+        final boolean isControlDown = ((jmodifiers & 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..16af3aa
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/nio/ch/DefaultSelectorProvider.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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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;
+
+/**
+ * Creates this platform's default SelectorProvider
+ */
+
+public class DefaultSelectorProvider {
+
+    /**
+     * Prevent instantiation.
+     */
+    private DefaultSelectorProvider() { }
+
+    /**
+     * Returns the default SelectorProvider.
+     */
+    public static SelectorProvider create() {
+            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..71d098d
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/nio/ch/KQueueArrayWrapper.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 = 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..60d523b
--- /dev/null
+++ b/jdk/src/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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<Integer,SelectionKeyImpl> 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 = 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<SelectionKey> 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();
+    }
+
+
+    public 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/lib/Info-cmdline.plist b/jdk/src/macosx/lib/Info-cmdline.plist
new file mode 100644
index 0000000..48ff371
--- /dev/null
+++ b/jdk/src/macosx/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/macosx/lib/Info-privileged.plist b/jdk/src/macosx/lib/Info-privileged.plist
new file mode 100644
index 0000000..776967a
--- /dev/null
+++ b/jdk/src/macosx/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/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..7b95a70
--- /dev/null
+++ b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_PCM.cpp
@@ -0,0 +1,1042 @@
+/*
+ * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 <AudioToolbox/AudioConverter.h>
+#include <pthread.h>
+#include <math.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(const 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(const 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);
+
+    // any sample rates are supported
+    float sampleRate = -1;
+
+    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);
+        }
+    }
+};
+
+
+class Resampler {
+private:
+    enum {
+        kResamplerEndOfInputData = 1 // error to interrupt conversion (end of input data)
+    };
+public:
+    Resampler() : converter(NULL), outBuffer(NULL) { }
+    ~Resampler() {
+        if (converter != NULL) {
+            AudioConverterDispose(converter);
+        }
+        if (outBuffer != NULL) {
+            free(outBuffer);
+        }
+    }
+
+    // inFormat & outFormat must be interleaved!
+    bool Init(const AudioStreamBasicDescription *inFormat, const AudioStreamBasicDescription *outFormat,
+            int inputBufferSizeInBytes)
+    {
+        TRACE0(">>Resampler::Init\n");
+        TRACE0("  inFormat: ");
+        PrintStreamDesc(inFormat);
+        TRACE0("  outFormat: ");
+        PrintStreamDesc(outFormat);
+        TRACE1("  inputBufferSize: %d bytes\n", inputBufferSizeInBytes);
+        OSStatus err;
+
+        if ((outFormat->mFormatFlags & kAudioFormatFlagIsNonInterleaved) != 0 && outFormat->mChannelsPerFrame != 1) {
+            ERROR0("Resampler::Init ERROR: outFormat is non-interleaved\n");
+            return false;
+        }
+        if ((inFormat->mFormatFlags & kAudioFormatFlagIsNonInterleaved) != 0 && inFormat->mChannelsPerFrame != 1) {
+            ERROR0("Resampler::Init ERROR: inFormat is non-interleaved\n");
+            return false;
+        }
+
+        memcpy(&asbdIn, inFormat, sizeof(AudioStreamBasicDescription));
+        memcpy(&asbdOut, outFormat, sizeof(AudioStreamBasicDescription));
+
+        err = AudioConverterNew(inFormat, outFormat, &converter);
+
+        if (err || converter == NULL) {
+            OS_ERROR1(err, "Resampler::Init (AudioConverterNew), converter=%p", converter);
+            return false;
+        }
+
+        // allocate buffer for output data
+        int maximumInFrames = inputBufferSizeInBytes / inFormat->mBytesPerFrame;
+        // take into account trailingFrames
+        AudioConverterPrimeInfo primeInfo = {0, 0};
+        UInt32 sizePrime = sizeof(primeInfo);
+        err = AudioConverterGetProperty(converter, kAudioConverterPrimeInfo, &sizePrime, &primeInfo);
+        if (err) {
+            OS_ERROR0(err, "Resampler::Init (get kAudioConverterPrimeInfo)");
+            // ignore the error
+        } else {
+            // the default primeMethod is kConverterPrimeMethod_Normal, so we need only trailingFrames
+            maximumInFrames += primeInfo.trailingFrames;
+        }
+        float outBufferSizeInFrames = (outFormat->mSampleRate / inFormat->mSampleRate) * ((float)maximumInFrames);
+        // to avoid complex calculation just set outBufferSize as double of the calculated value
+        outBufferSize = (int)outBufferSizeInFrames * outFormat->mBytesPerFrame * 2;
+        // safety check - consider 256 frame as the minimum input buffer
+        int minOutSize = 256 * outFormat->mBytesPerFrame;
+        if (outBufferSize < minOutSize) {
+            outBufferSize = minOutSize;
+        }
+
+        outBuffer = malloc(outBufferSize);
+
+        if (outBuffer == NULL) {
+            ERROR1("Resampler::Init ERROR: malloc failed (%d bytes)\n", outBufferSize);
+            AudioConverterDispose(converter);
+            converter = NULL;
+            return false;
+        }
+
+        TRACE1("  allocated: %d bytes for output buffer\n", outBufferSize);
+
+        TRACE0("<<Resampler::Init: OK\n");
+        return true;
+    }
+
+    // returns size of the internal output buffer
+    int GetOutBufferSize() {
+        return outBufferSize;
+    }
+
+    // process next part of data (writes resampled data to the ringBuffer without overflow check)
+    int Process(void *srcBuffer, int len, RingBuffer *ringBuffer) {
+        int bytesWritten = 0;
+        TRACE2(">>Resampler::Process: %d bytes, converter = %p\n", len, converter);
+        if (converter == NULL) {    // sanity check
+            bytesWritten = ringBuffer->Write(srcBuffer, len, false);
+        } else {
+            InputProcData data;
+            data.pThis = this;
+            data.data = (Byte *)srcBuffer;
+            data.dataSize = len;
+
+            OSStatus err;
+            do {
+                AudioBufferList abl;    // by default it contains 1 AudioBuffer
+                abl.mNumberBuffers = 1;
+                abl.mBuffers[0].mNumberChannels = asbdOut.mChannelsPerFrame;
+                abl.mBuffers[0].mDataByteSize   = outBufferSize;
+                abl.mBuffers[0].mData           = outBuffer;
+
+                UInt32 packets = (UInt32)outBufferSize / asbdOut.mBytesPerPacket;
+
+                TRACE2(">>AudioConverterFillComplexBuffer: request %d packets, provide %d bytes buffer\n",
+                    (int)packets, (int)abl.mBuffers[0].mDataByteSize);
+
+                err = AudioConverterFillComplexBuffer(converter, ConverterInputProc, &data, &packets, &abl, NULL);
+
+                TRACE2("<<AudioConverterFillComplexBuffer: got %d packets (%d bytes)\n",
+                    (int)packets, (int)abl.mBuffers[0].mDataByteSize);
+                if (packets > 0) {
+                    int bytesToWrite = (int)(packets * asbdOut.mBytesPerPacket);
+                    bytesWritten += ringBuffer->Write(abl.mBuffers[0].mData, bytesToWrite, false);
+                }
+
+                // if outputBuffer is small to store all available frames,
+                // we get noErr here. In the case just continue the conversion
+            } while (err == noErr);
+
+            if (err != kResamplerEndOfInputData) {
+                // unexpected error
+                OS_ERROR0(err, "Resampler::Process (AudioConverterFillComplexBuffer)");
+            }
+        }
+        TRACE2("<<Resampler::Process: written %d bytes (converted from %d bytes)\n", bytesWritten, len);
+
+        return bytesWritten;
+    }
+
+    // resets internal bufferes
+    void Discontinue() {
+        TRACE0(">>Resampler::Discontinue\n");
+        if (converter != NULL) {
+            AudioConverterReset(converter);
+        }
+        TRACE0("<<Resampler::Discontinue\n");
+    }
+
+private:
+    AudioConverterRef converter;
+
+    // buffer for output data
+    // note that there is no problem if the buffer is not big enough to store
+    // all converted data - it's only performance issue
+    void *outBuffer;
+    int outBufferSize;
+
+    AudioStreamBasicDescription asbdIn;
+    AudioStreamBasicDescription asbdOut;
+
+    struct InputProcData {
+        Resampler *pThis;
+        Byte *data;     // data == NULL means we handle Discontinue(false)
+        int dataSize;   // == 0 if all data was already provided to the converted of we handle Discontinue(false)
+    };
+
+    static OSStatus ConverterInputProc(AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPackets,
+            AudioBufferList *ioData, AudioStreamPacketDescription **outDataPacketDescription, void *inUserData)
+    {
+        InputProcData *data = (InputProcData *)inUserData;
+
+        TRACE3("  >>ConverterInputProc: requested %d packets, data contains %d bytes (%d packets)\n",
+            (int)*ioNumberDataPackets, (int)data->dataSize, (int)(data->dataSize / data->pThis->asbdIn.mBytesPerPacket));
+        if (data->dataSize == 0) {
+            // already called & provided all input data
+            // interrupt conversion by returning error
+            *ioNumberDataPackets = 0;
+            TRACE0("  <<ConverterInputProc: returns kResamplerEndOfInputData\n");
+            return kResamplerEndOfInputData;
+        }
+
+        ioData->mNumberBuffers = 1;
+        ioData->mBuffers[0].mNumberChannels = data->pThis->asbdIn.mChannelsPerFrame;
+        ioData->mBuffers[0].mDataByteSize   = data->dataSize;
+        ioData->mBuffers[0].mData           = data->data;
+
+        *ioNumberDataPackets = data->dataSize / data->pThis->asbdIn.mBytesPerPacket;
+
+        // all data has been provided to the converter
+        data->dataSize = 0;
+
+        TRACE1("  <<ConverterInputProc: returns %d packets\n", (int)(*ioNumberDataPackets));
+        return noErr;
+    }
+
+};
+
+
+struct OSX_DirectAudioDevice {
+    AudioUnit   audioUnit;
+    RingBuffer  ringBuffer;
+    AudioStreamBasicDescription asbd;
+
+    // only for target lines
+    UInt32      inputBufferSizeInBytes;
+    Resampler   *resampler;
+    // to detect discontinuity (to reset resampler)
+    SInt64      lastWrittenSampleTime;
+
+
+    OSX_DirectAudioDevice() : audioUnit(NULL), asbd(), resampler(NULL), lastWrittenSampleTime(0) {
+    }
+
+    ~OSX_DirectAudioDevice() {
+        if (audioUnit) {
+            CloseComponent(audioUnit);
+        }
+        if (resampler) {
+            delete resampler;
+        }
+    }
+};
+
+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
+
+    OSStatus err = AudioUnitRender(device->audioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, &abl);
+    if (err) {
+        OS_ERROR0(err, "<<InputCallback: AudioUnitRender");
+    } else {
+        if (device->resampler != NULL) {
+            // test for discontinuity
+            // AUHAL starts timestamps at zero, so test if the current timestamp less then the last written
+            SInt64 sampleTime = inTimeStamp->mSampleTime;
+            if (sampleTime < device->lastWrittenSampleTime) {
+                // discontinuity, reset the resampler
+                TRACE2("  InputCallback (RESAMPLED), DISCONTINUITY (%f -> %f)\n",
+                    (float)device->lastWrittenSampleTime, (float)sampleTime);
+
+                device->resampler->Discontinue();
+            } else {
+                TRACE2("  InputCallback (RESAMPLED), continuous: lastWrittenSampleTime = %f, sampleTime=%f\n",
+                    (float)device->lastWrittenSampleTime, (float)sampleTime);
+            }
+            device->lastWrittenSampleTime = sampleTime + inNumberFrames;
+
+            int bytesWritten = device->resampler->Process(abl.mBuffers[0].mData, (int)abl.mBuffers[0].mDataByteSize, &device->ringBuffer);
+            TRACE2("<<InputCallback (RESAMPLED, saved %d bytes of %d)\n", bytesWritten, (int)abl.mBuffers[0].mDataByteSize);
+        } 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;
+}
+
+
+static void FillASBDForNonInterleavedPCM(AudioStreamBasicDescription& asbd,
+    float sampleRate, int channels, int sampleSizeInBits, bool isFloat, int isSigned, bool isBigEndian)
+{
+    // FillOutASBDForLPCM cannot produce unsigned integer format
+    asbd.mSampleRate = sampleRate;
+    asbd.mFormatID = kAudioFormatLinearPCM;
+    asbd.mFormatFlags = (isFloat ? kAudioFormatFlagIsFloat : (isSigned ? kAudioFormatFlagIsSignedInteger : 0))
+        | (isBigEndian ? (kAudioFormatFlagIsBigEndian) : 0)
+        | kAudioFormatFlagIsPacked;
+    asbd.mBytesPerPacket = channels * ((sampleSizeInBits + 7) / 8);
+    asbd.mFramesPerPacket = 1;
+    asbd.mBytesPerFrame = asbd.mBytesPerPacket;
+    asbd.mChannelsPerFrame = channels;
+    asbd.mBitsPerChannel = sampleSizeInBits;
+}
+
+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;
+    }
+
+    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;
+    }
+
+    if (!isSource) {
+        AudioDeviceID actualDeviceID = deviceID != 0 ? deviceID : GetDefaultDevice(isSource);
+        float hardwareSampleRate = GetSampleRate(actualDeviceID, isSource);
+        TRACE2("--DAUDIO_Open: sampleRate = %f, hardwareSampleRate=%f\n", sampleRate, hardwareSampleRate);
+
+        if (fabs(sampleRate - hardwareSampleRate) > 1) {
+            device->resampler = new Resampler();
+
+            // request HAL for Float32 with native endianess
+            FillASBDForNonInterleavedPCM(device->asbd, hardwareSampleRate, channels, 32, true, false, kAudioFormatFlagsNativeEndian != 0);
+        } else {
+            sampleRate = hardwareSampleRate;    // in case sample rates are not exactly equal
+        }
+    }
+
+    if (device->resampler == NULL) {
+        // no resampling, request HAL for the requested format
+        FillASBDForNonInterleavedPCM(device->asbd, sampleRate, channels, sampleSizeInBits, false, isSigned, isBigEndian);
+    }
+
+    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 ringBuffer
+        // 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 to bytes
+        extraBufferBytes = (int)device->inputBufferSizeInBytes;
+    }
+
+    if (device->resampler != NULL) {
+        // resampler output format is a user requested format (== ringBuffer format)
+        AudioStreamBasicDescription asbdOut; // ringBuffer format
+        FillASBDForNonInterleavedPCM(asbdOut, sampleRate, channels, sampleSizeInBits, false, isSigned, isBigEndian);
+
+        // set resampler input buffer size to the HAL buffer size
+        if (!device->resampler->Init(&device->asbd, &asbdOut, (int)device->inputBufferSizeInBytes)) {
+            ERROR0("<<DAUDIO_Open: resampler.Init() FAILED.\n");
+            delete device;
+            return NULL;
+        }
+        // extra bytes in the ringBuffer (extraBufferBytes) should be equal resampler output buffer size
+        extraBufferBytes = device->resampler->GetOutBufferSize();
+    }
+
+    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.cpp b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Ports.cpp
new file mode 100644
index 0000000..12ee4f2
--- /dev/null
+++ b/jdk/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_Ports.cpp
@@ -0,0 +1,852 @@
+/*
+ * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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
+
+/* If a device has the only AudioStream in the scope (input or output),
+ * PortMixer provides a single Port, using the stream kAudioStreamPropertyTerminalType
+ * property value to determine Port.Type (PORT_GetPortType function).
+ * If the device has several (more than 1) AudioStreams, there are 2 ways to represent Ports:
+ * 1. (HALLab-style) single Port which represents all device channels with
+ *    "master volume" and (if number of channel is 2) "master balance"; if AudioDevice
+ *    does not provide "master" controls, implement "virtual master" controls.
+ *    Port.Type is PORT_SRC_UNKNOWN or PORT_DST_UNKNOWN.
+ * 2. provide a separate Port for every AudioStream (with appropriate Port.Type);
+ *
+ * AudioHardware.h claims that AudioStream objects share AudioControl objects with their owning AudioDevice.
+ * In practice 10.7 OSX drivers (built-in devices, USB audio) implement AudioControl only for AudioDevice.
+ * For now 1st way is implemented (2nd way can be better if AudioStreams provide AudioControls).
+ */
+
+static DeviceList deviceCache;
+
+#define FourCC2Str(n) ((char[5]){(char)(n >> 24), (char)(n >> 16), (char)(n >> 8), (char)(n), 0})
+
+
+// CoreAudio's AudioControl
+struct AudioControl {
+    AudioObjectID controlID;
+    AudioClassID classID;               // kAudioVolumeControlClassID etc.
+    AudioObjectPropertyScope scope;     // input, output
+    AudioObjectPropertyElement channel; // master = 0, channels = 1 2 ...
+};
+
+// Controls for Java
+// PortMixer do all memory management (alloc/free audioControls)
+struct PortControl {
+    enum ControlType {
+        Volume,     // manages single or multiple volume AudioControl
+        Mute,       // manages single or multiple mute AudioControls
+        Balance     // "virtual" control, manages 2 volume AudioControls (only for stereo lines)
+    };
+    ControlType type;
+
+    int controlCount;
+    AudioControl **audioControls;
+
+    PortControl *next;  // to organize PortControl list
+};
+
+// represents line (port) for PortMixer
+// used for PORT_GetPortCount/PORT_GetPortType/PORT_GetPortName functions
+struct PortLine {
+    AudioObjectPropertyScope scope;
+    // if the device has several AudioStreams in the scope, streamID == 0
+    AudioStreamID streamID;
+};
+
+struct PortMixer {
+    AudioDeviceID deviceID;
+
+    int portCount;
+    PortLine ports[2]; // maximum 2 lines - 1 for input & 1 for output
+
+    int deviceControlCount; // -1 means "not initialized"
+    AudioControl *deviceControls;
+
+    PortControl *portControls;  // list of port controls
+
+    bool listenersInstalled;
+};
+
+
+void RemoveChangeListeners(PortMixer *mixer);   // forward declaration
+
+OSStatus ChangeListenerProc(AudioObjectID inObjectID, UInt32 inNumberAddresses,
+        const AudioObjectPropertyAddress inAddresses[], void *inClientData)
+{
+    PortMixer *mixer = (PortMixer *)inClientData;
+
+    OSStatus err = noErr;
+    UInt32 size;
+
+    bool invalid = false;
+
+    for (UInt32 i = 0; i < inNumberAddresses; i++) {
+        switch (inAddresses[i].mSelector) {
+        case kAudioHardwarePropertyDevices:
+            // check if the device has been removed
+            err = GetAudioObjectPropertySize(kAudioObjectSystemObject, kAudioObjectPropertyScopeGlobal,
+                kAudioHardwarePropertyDevices, &size);
+            if (err == noErr) {
+                int count = size/sizeof(AudioDeviceID);
+                AudioDeviceID devices[count];
+                err = GetAudioObjectProperty(kAudioObjectSystemObject, kAudioObjectPropertyScopeGlobal,
+                    kAudioHardwarePropertyDevices, count*sizeof(AudioDeviceID), devices, 1);
+                if (err == noErr) {
+                    bool found = false;
+                    for (int j = 0; j < count; j++) {
+                        if (devices[j] == mixer->deviceID) {
+                            found = true;
+                            break;
+                        }
+                    }
+                    if (!found) {
+                        invalid = true;
+                    }
+                }
+            }
+            break;
+        case kAudioObjectPropertyOwnedObjects:
+        case kAudioDevicePropertyDeviceHasChanged:
+            // ensure all _used_ AudioControl are valid
+            err = GetAudioObjectPropertySize(mixer->deviceID, kAudioObjectPropertyScopeGlobal,
+                kAudioObjectPropertyOwnedObjects, &size);
+            if (err == noErr) {
+                int count = size / sizeof(AudioObjectID);
+                AudioObjectID controlIDs[count];
+                err = GetAudioObjectProperty(mixer->deviceID, kAudioObjectPropertyScopeGlobal,
+                    kAudioObjectPropertyOwnedObjects, count * sizeof(AudioObjectID), &controlIDs, 1);
+                if (err == noErr) {
+                    for (PortControl *ctrl = mixer->portControls; ctrl != NULL; ctrl = ctrl->next) {
+                        for (int i = 0; i < ctrl->controlCount; i++) {
+                            bool found = false;
+                            for (int j = 0; j < count; j++) {
+                                if (ctrl->audioControls[i]->controlID == controlIDs[j]) {
+                                    found = true;
+                                    break;
+                                }
+                            }
+                            if (!found) {
+                                invalid = true;
+                                break;  // goto next control
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    if (invalid) {
+        TRACE1("PortMixer (deviceID=0x%x) becomes invalid", (int)mixer->deviceID);
+        // invalidate all controls
+        for (int i=0; i<mixer->deviceControlCount; i++) {
+            mixer->deviceControls[i].controlID = 0;
+        }
+        RemoveChangeListeners(mixer);
+    }
+
+
+    return noErr;
+}
+
+const AudioObjectPropertyAddress changeListenersAddresses[] = {
+    {kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster},
+    {kAudioObjectPropertyOwnedObjects, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster},
+    {kAudioDevicePropertyDeviceHasChanged, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster}
+};
+
+void AddChangeListeners(PortMixer *mixer) {
+    if (!mixer->listenersInstalled) {
+        for (size_t i=0; i<sizeof(changeListenersAddresses)/sizeof(changeListenersAddresses[0]); i++) {
+            AudioObjectAddPropertyListener(mixer->deviceID, &changeListenersAddresses[i], ChangeListenerProc, mixer);
+        }
+        mixer->listenersInstalled = true;
+    }
+}
+
+void RemoveChangeListeners(PortMixer *mixer) {
+    if (mixer->listenersInstalled) {
+        for (size_t i=0; i<sizeof(changeListenersAddresses)/sizeof(changeListenersAddresses[0]); i++) {
+            AudioObjectRemovePropertyListener(mixer->deviceID, &changeListenersAddresses[i], ChangeListenerProc, mixer);
+        }
+        mixer->listenersInstalled = false;
+    }
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// functions from Port.h
+
+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) {
+    TRACE1("\n>>PORT_Open (mixerIndex=%d)\n", (int)mixerIndex);
+    PortMixer *mixer = (PortMixer *)calloc(1, sizeof(PortMixer));
+
+    mixer->deviceID = deviceCache.GetDeviceID(mixerIndex);
+    if (mixer->deviceID != 0) {
+        mixer->deviceControlCount = -1; // not initialized
+        // fill mixer->ports (and mixer->portCount)
+        for (int i=0; i<2; i++) {
+            OSStatus err;
+            UInt32 size = 0;
+            AudioObjectPropertyScope scope =
+                (i == 0) ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
+
+            err = GetAudioObjectPropertySize(mixer->deviceID, scope, kAudioDevicePropertyStreams, &size);
+            if (err || size == 0) {
+                continue;
+            }
+            if (size / sizeof(AudioStreamID) == 1) {
+                // the device has the only AudioStream
+                AudioStreamID streamID;
+                err = GetAudioObjectProperty(mixer->deviceID, scope, kAudioDevicePropertyStreams,
+                    sizeof(streamID), &streamID, 1);
+                if (err) {
+                    continue;
+                }
+                mixer->ports[mixer->portCount].streamID = streamID;
+            } else {
+                // the device has several AudioStreams in the scope
+                mixer->ports[mixer->portCount].streamID = 0;
+            }
+            mixer->ports[mixer->portCount].scope = scope;
+            mixer->portCount++;
+        }
+    }
+
+    TRACE2("<<PORT_Open (mixerIndex=%d) %p\n", mixerIndex, mixer);
+    return mixer;
+}
+
+
+void PORT_Close(void* id) {
+    TRACE1(">>PORT_Close %p\n", id);
+    PortMixer *mixer = (PortMixer *)id;
+
+    if (mixer) {
+        RemoveChangeListeners(mixer);
+        while (mixer->portControls != NULL) {
+            PortControl *control2delete = mixer->portControls;
+            mixer->portControls = control2delete->next;
+
+            if (control2delete->audioControls != NULL) {
+                free(control2delete->audioControls);
+            }
+            free(control2delete);
+        }
+        if (mixer->deviceControls) {
+            free(mixer->deviceControls);
+        }
+        free(mixer);
+    }
+    TRACE1("<<PORT_Close %p\n", mixer);
+}
+
+INT32 PORT_GetPortCount(void* id) {
+    PortMixer *mixer = (PortMixer *)id;
+
+    int result = mixer->portCount;
+
+    TRACE1("<<PORT_GetPortCount = %d\n", result);
+    return result;
+}
+
+INT32 PORT_GetPortType(void* id, INT32 portIndex) {
+    PortMixer *mixer = (PortMixer *)id;
+    INT32 ret = 0;
+
+    if (portIndex < 0 || portIndex >= mixer->portCount) {
+        ERROR1("PORT_GetPortType: line (portIndex = %d) not found\n", portIndex);
+        return 0;
+    }
+
+    AudioObjectPropertyScope scope = mixer->ports[portIndex].scope;
+    AudioStreamID streamID = mixer->ports[portIndex].streamID;
+    if (streamID != 0) {
+        UInt32 terminalType;
+
+        OSStatus err = GetAudioObjectProperty(streamID, kAudioObjectPropertyScopeGlobal,
+            kAudioStreamPropertyTerminalType, sizeof(terminalType), &terminalType, 1);
+        if (err) {
+            OS_ERROR1(err, "PORT_GetPortType(kAudioStreamPropertyTerminalType), portIndex=%d", portIndex);
+            return 0;
+        }
+
+        // Note that kAudioStreamPropertyTerminalType actually returns values from
+        // IOAudioTypes.h, not the defined kAudioStreamTerminalType*.
+        TRACE4("PORT_GetPortType (portIndex=%d), scope=%s, termType=0x%04x (%s)\n",
+            (int)portIndex, FourCC2Str(scope), (int)terminalType, FourCC2Str(terminalType));
+        switch (terminalType) {
+        case INPUT_MICROPHONE:
+            ret = PORT_SRC_MICROPHONE;
+            break;
+
+        case OUTPUT_SPEAKER:
+            ret = PORT_DST_SPEAKER;
+            break;
+        case OUTPUT_HEADPHONES:
+            ret = PORT_DST_HEADPHONE;
+            break;
+
+        case EXTERNAL_LINE_CONNECTOR:
+            ret = scope == kAudioDevicePropertyScopeInput ? PORT_SRC_LINE_IN : PORT_DST_LINE_OUT;
+            break;
+
+        default:
+            TRACE1("  unknown output terminal type %#x\n", terminalType);
+        }
+    } else {
+        TRACE0("  PORT_GetPortType: multiple streams\n");
+    }
+
+    if (ret == 0) {
+        // if the type not detected, return "common type"
+        ret = scope == kAudioDevicePropertyScopeInput ? PORT_SRC_UNKNOWN : 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;
+
+    name[0] = 0;    // for safety
+
+    if (portIndex < 0 || portIndex >= mixer->portCount) {
+        ERROR1("PORT_GetPortName: line (portIndex = %d) not found\n", portIndex);
+        return FALSE;
+    }
+
+    AudioStreamID streamID = mixer->ports[portIndex].streamID;
+    CFStringRef cfname = NULL;
+    if (streamID != 0) {
+        OSStatus 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)
+        // or the device has several AudioStreams
+        OSStatus 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;
+}
+
+
+// counts number of valid (non-NULL) elements in the array of AudioControls
+static int ValidControlCount(AudioControl **arr, int offset, int len) {
+    int result = 0;
+    int end = offset + len;
+    for (int i=offset; i<end; i++) {
+        if (arr[i] != NULL)
+            result++;
+    }
+    return result;
+}
+
+// returns java control
+static void* CreatePortControl(PortMixer *mixer, PortControlCreator *creator, PortControl::ControlType type,
+                               AudioControl **audioControls, int offset, int len) {
+    void *jControl = NULL;
+    PortControl *control = (PortControl *)calloc(1, sizeof(PortControl));
+    float precision = 0.01;
+
+    control->type = type;
+    control->controlCount = len;
+    control->audioControls = (AudioControl **)malloc(len * sizeof(AudioControl *));
+    memcpy(control->audioControls, audioControls + offset, len * sizeof(AudioControl *));
+
+    switch (control->type) {
+    case PortControl::Volume:
+        jControl = creator->newFloatControl(creator, control, CONTROL_TYPE_VOLUME, 0, 1, precision, "");
+        break;
+    case PortControl::Mute:
+        jControl = creator->newBooleanControl(creator, control, CONTROL_TYPE_MUTE);
+        break;
+    case PortControl::Balance:
+        jControl = creator->newFloatControl(creator, control, CONTROL_TYPE_BALANCE, -1, 1, precision, "");
+        break;
+    };
+
+    if (jControl == NULL) {
+        ERROR0("CreatePortControl: javaControl was not created\n");
+        free(control->audioControls);
+        free(control);
+        return NULL;
+    }
+
+    // add the control to mixer control list;
+    control->next = mixer->portControls;
+    mixer->portControls = control;
+
+    return jControl;
+}
+
+void PORT_GetControls(void* id, INT32 portIndex, PortControlCreator* creator) {
+    PortMixer *mixer = (PortMixer *)id;
+
+    TRACE1(">>PORT_GetControls (portIndex = %d)\n", portIndex);
+
+    if (portIndex < 0 || portIndex >= mixer->portCount) {
+        ERROR1("<<PORT_GetControls: line (portIndex = %d) not found\n", portIndex);
+        return;
+    }
+
+    PortLine *port = &(mixer->ports[portIndex]);
+
+    if (mixer->deviceControlCount < 0) {    // not initialized
+        OSStatus err;
+        UInt32 size;
+        // deviceControlCount is overestimated
+        // because we don't actually filter by if the owned objects are controls
+        err = GetAudioObjectPropertySize(mixer->deviceID, kAudioObjectPropertyScopeGlobal,
+            kAudioObjectPropertyOwnedObjects, &size);
+
+        if (err) {
+            OS_ERROR1(err, "PORT_GetControls (portIndex = %d) get OwnedObject size", portIndex);
+        } else {
+            mixer->deviceControlCount = size / sizeof(AudioObjectID);
+            TRACE1("  PORT_GetControls: detected %d owned objects\n", mixer->deviceControlCount);
+
+            AudioObjectID controlIDs[mixer->deviceControlCount];
+
+            err = GetAudioObjectProperty(mixer->deviceID, kAudioObjectPropertyScopeGlobal,
+                kAudioObjectPropertyOwnedObjects, sizeof(controlIDs), controlIDs, 1);
+
+            if (err) {
+                OS_ERROR1(err, "PORT_GetControls (portIndex = %d) get OwnedObject values", portIndex);
+            } else {
+                mixer->deviceControls = (AudioControl *)calloc(mixer->deviceControlCount, sizeof(AudioControl));
+
+                for (int i = 0; i < mixer->deviceControlCount; i++) {
+                    AudioControl *control = &mixer->deviceControls[i];
+
+                    control->controlID = controlIDs[i];
+
+                    OSStatus err1 = GetAudioObjectProperty(control->controlID, kAudioObjectPropertyScopeGlobal,
+                        kAudioObjectPropertyClass, sizeof(control->classID), &control->classID, 1);
+                    OSStatus err2 = GetAudioObjectProperty(control->controlID, kAudioObjectPropertyScopeGlobal,
+                        kAudioControlPropertyScope, sizeof(control->scope), &control->scope, 1);
+                    OSStatus err3 = GetAudioObjectProperty(control->controlID, kAudioObjectPropertyScopeGlobal,
+                        kAudioControlPropertyElement, sizeof(control->channel), &control->channel, 1);
+                    if (err1 || err2 || err3) { // not a control or other error
+                        control->classID = 0;
+                        continue;
+                    }
+
+                    TRACE4("- control 0x%x, class='%s', scope='%s', channel=%d\n",
+                        control->controlID, FourCC2Str(control->classID), FourCC2Str(control->scope), control->channel);
+                }
+            }
+        }
+    }
+
+    if (mixer->deviceControlCount <= 0) {
+        TRACE1("<<PORT_GetControls (portIndex = %d): no owned AudioControls\n", portIndex);
+        return;
+    }
+
+    int totalChannels = GetChannelCount(mixer->deviceID, port->scope == kAudioDevicePropertyScopeOutput ? 1 : 0);
+
+    // collect volume and mute controls
+    AudioControl* volumeControls[totalChannels+1];  // 0 - for master channel
+    memset(&volumeControls, 0, sizeof(AudioControl *) * (totalChannels+1));
+    AudioControl* muteControls[totalChannels+1];  // 0 - for master channel
+    memset(&muteControls, 0, sizeof(AudioControl *) * (totalChannels+1));
+
+    for (int i=0; i<mixer->deviceControlCount; i++) {
+        AudioControl *control = &mixer->deviceControls[i];
+        if (control->classID == 0 || control->scope != port->scope || control->channel > (unsigned)totalChannels) {
+            continue;
+        }
+        if (control->classID == kAudioVolumeControlClassID) {
+            if (volumeControls[control->channel] == NULL) {
+                volumeControls[control->channel] = control;
+            } else {
+                ERROR4("WARNING: duplicate VOLUME control 0x%x, class='%s', scope='%s', channel=%d\n",
+                    control->controlID, FourCC2Str(control->classID), FourCC2Str(control->scope), control->channel);
+            }
+        } else if (control->classID == kAudioMuteControlClassID) {
+            if (muteControls[control->channel] == NULL) {
+                muteControls[control->channel] = control;
+            } else {
+                ERROR4("WARNING: duplicate MUTE control 0x%x, class='%s', scope='%s', channel=%d\n",
+                    control->controlID, FourCC2Str(control->classID), FourCC2Str(control->scope), control->channel);
+            }
+        } else {
+#ifdef USE_ERROR
+            if (control->classID != 0) {
+                ERROR4("WARNING: unhandled control 0x%x, class='%s', scope='%s', channel=%d\n",
+                    control->controlID, FourCC2Str(control->classID), FourCC2Str(control->scope), control->channel);
+            }
+#endif
+        }
+    }
+
+    ////////////////////////////////////////////////////////
+    // create java control hierarchy
+
+    void *masterVolume = NULL, *masterMute = NULL, *masterBalance = NULL;
+    // volumeControls[0] and muteControls[0] - master volume/mute
+    // volumeControls[n] and muteControls[n] (n=1..totalChannels) - corresponding channel controls
+    if (volumeControls[0] != NULL) {    // "master volume" AudioControl
+        masterVolume = CreatePortControl(mixer, creator, PortControl::Volume, volumeControls, 0, 1);
+    } else {
+        if (ValidControlCount(volumeControls, 1, totalChannels) == totalChannels) {
+            // every channel has volume control => create virtual master volume
+            masterVolume = CreatePortControl(mixer, creator, PortControl::Volume, volumeControls, 1, totalChannels);
+        } else {
+            TRACE2("  PORT_GetControls (master volume): totalChannels = %d, valid volume controls = %d\n",
+                totalChannels, ValidControlCount(volumeControls, 1, totalChannels));
+        }
+    }
+
+    if (muteControls[0] != NULL) {      // "master mute"
+        masterMute = CreatePortControl(mixer, creator, PortControl::Mute, muteControls, 0, 1);
+    } else {
+        if (ValidControlCount(muteControls, 1, totalChannels) == totalChannels) {
+            // every channel has mute control => create virtual master mute control
+            masterMute = CreatePortControl(mixer, creator, PortControl::Mute, muteControls, 1, totalChannels);
+        } else {
+            TRACE2("  PORT_GetControls (master mute): totalChannels = %d, valid volume controls = %d\n",
+                totalChannels, ValidControlCount(muteControls, 1, totalChannels));
+        }
+    }
+
+    // virtual balance
+    if (totalChannels == 2) {
+        if (ValidControlCount(volumeControls, 1, totalChannels) == totalChannels) {
+            masterBalance = CreatePortControl(mixer, creator, PortControl::Balance, volumeControls, 1, totalChannels);
+        } else {
+            TRACE2("  PORT_GetControls (naster balance): totalChannels = %d, valid volume controls = %d\n",
+                totalChannels, ValidControlCount(volumeControls, 1, totalChannels));
+        }
+    }
+
+    // add "master" controls
+    if (masterVolume != NULL) {
+        creator->addControl(creator, masterVolume);
+    }
+    if (masterBalance != NULL) {
+        creator->addControl(creator, masterBalance);
+    }
+    if (masterMute != NULL) {
+        creator->addControl(creator, masterMute);
+    }
+
+    // don't add per-channel controls for mono & stereo - they are handled by "master" controls
+    // TODO: this should be reviewed to handle controls other than mute & volume
+    if (totalChannels > 2) {
+        // add separate compound control for each channel (containing volume and mute)
+        // (ensure that we have controls)
+        if (ValidControlCount(volumeControls, 1, totalChannels) > 0 || ValidControlCount(muteControls, 1, totalChannels) > 0) {
+            for (int ch=1; ch<=totalChannels; ch++) {
+                // get the channel name
+                char *channelName;
+                CFStringRef cfname = NULL;
+                const AudioObjectPropertyAddress address = {kAudioObjectPropertyElementName, port->scope, ch};
+                UInt32 size = sizeof(cfname);
+                OSStatus err = AudioObjectGetPropertyData(mixer->deviceID, &address, 0, NULL, &size, &cfname);
+                if (err == noErr) {
+                    CFIndex length = CFStringGetLength(cfname) + 1;
+                    channelName = (char *)malloc(length);
+                    CFStringGetCString(cfname, channelName, length, kCFStringEncodingUTF8);
+                    CFRelease(cfname);
+                } else {
+                    channelName = (char *)malloc(16);
+                    sprintf(channelName, "Ch %d", ch);
+                }
+
+                void* jControls[2];
+                int controlCount = 0;
+                if (volumeControls[ch] != NULL) {
+                    jControls[controlCount++] = CreatePortControl(mixer, creator, PortControl::Volume, volumeControls, ch, 1);
+                }
+                if (muteControls[ch] != NULL) {
+                    jControls[controlCount++] = CreatePortControl(mixer, creator, PortControl::Mute, muteControls, ch, 1);
+                }
+                // TODO: add any extra controls for "other" controls for the channel
+
+                void *compoundControl = creator->newCompoundControl(creator, channelName, jControls, controlCount);
+                creator->addControl(creator, compoundControl);
+
+                free(channelName);
+            }
+        }
+    }
+
+    AddChangeListeners(mixer);
+
+    TRACE1("<<PORT_GetControls (portIndex = %d)\n", portIndex);
+}
+
+bool TestPortControlValidity(PortControl *control) {
+    for (int i=0; i<control->controlCount; i++) {
+        if (control->audioControls[i]->controlID == 0)
+            return false;
+    }
+    return true;
+}
+
+
+#define DEFAULT_MUTE_VALUE 0
+
+INT32 PORT_GetIntValue(void* controlIDV) {
+    PortControl *control = (PortControl *)controlIDV;
+    INT32 result = 0;
+
+    switch (control->type) {
+    case PortControl::Mute:
+        if (!TestPortControlValidity(control)) {
+            return DEFAULT_MUTE_VALUE;
+        }
+        result = 1; // default is "muted", if some channel in unmuted, then "virtual mute" is also unmuted
+        for (int i=0; i<control->controlCount; i++) {
+            UInt32 value;
+            OSStatus err = GetAudioObjectProperty(control->audioControls[i]->controlID,
+                kAudioObjectPropertyScopeGlobal, kAudioBooleanControlPropertyValue, sizeof(value), &value, 1);
+            if (err) {
+                OS_ERROR3(err, "PORT_GetIntValue, control %d of %d (coltrolID = 0x%x)",
+                    i, control->controlCount, control->audioControls[i]->controlID);
+                return DEFAULT_MUTE_VALUE;
+            }
+            if (value == 0) {
+                result = 0;
+            }
+        }
+        break;
+    default:
+        ERROR1("PORT_GetIntValue requested for non-Int control (control-type == %d)\n", control->type);
+        return 0;
+    }
+
+    //TRACE1("<<PORT_GetIntValue = %d\n", result);
+    return result;
+}
+
+void PORT_SetIntValue(void* controlIDV, INT32 value) {
+    //TRACE1("> PORT_SetIntValue = %d\n", value);
+    PortControl *control = (PortControl *)controlIDV;
+
+    if (!TestPortControlValidity(control)) {
+        return;
+    }
+
+    switch (control->type) {
+    case PortControl::Mute:
+        for (int i=0; i<control->controlCount; i++) {
+            OSStatus err = SetAudioObjectProperty(control->audioControls[i]->controlID,
+                kAudioObjectPropertyScopeGlobal, kAudioBooleanControlPropertyValue, sizeof(value), &value);
+            if (err) {
+                OS_ERROR3(err, "PORT_SetIntValue, control %d of %d (coltrolID = 0x%x)",
+                    i, control->controlCount, control->audioControls[i]->controlID);
+                // don't return - try to set the rest of AudioControls
+            }
+        }
+        break;
+    default:
+        ERROR1("PORT_SetIntValue requested for non-Int control (control-type == %d)\n", control->type);
+        return;
+    }
+}
+
+
+// gets volume value for all AudioControls of the PortControl
+static bool GetPortControlVolumes(PortControl *control, Float32 *volumes, Float32 *maxVolume) {
+    *maxVolume = 0.0f;
+    for (int i=0; i<control->controlCount; i++) {
+        OSStatus err = GetAudioObjectProperty(control->audioControls[i]->controlID,
+            kAudioObjectPropertyScopeGlobal, kAudioLevelControlPropertyScalarValue,
+            sizeof(volumes[i]), &volumes[i], 1);
+        if (err) {
+            OS_ERROR3(err, "GetPortControlVolumes, control %d of %d (controlID = 0x%x)",
+                i, control->controlCount, control->audioControls[i]->controlID);
+            return false;
+        }
+        if (volumes[i] > *maxVolume) {
+            *maxVolume = volumes[i];
+        }
+    }
+    return true;
+}
+
+// sets volume value for all AudioControls of the PortControl
+static void SetPortControlVolumes(PortControl *control, Float32 *volumes) {
+    for (int i=0; i<control->controlCount; i++) {
+        OSStatus err = SetAudioObjectProperty(control->audioControls[i]->controlID,
+            kAudioObjectPropertyScopeGlobal, kAudioLevelControlPropertyScalarValue,
+            sizeof(volumes[i]), &volumes[i]);
+        if (err) {
+            OS_ERROR3(err, "SetPortControlVolumes , control %d of %d (coltrolID = 0x%x)",
+                i, control->controlCount, control->audioControls[i]->controlID);
+            // don't return - try to set the rest of AudioControls
+        }
+    }
+}
+
+#define DEFAULT_VOLUME_VALUE    1.0f
+#define DEFAULT_BALANCE_VALUE   0.0f
+
+float PORT_GetFloatValue(void* controlIDV) {
+    PortControl *control = (PortControl *)controlIDV;
+    Float32 result = 0;
+
+    Float32 subVolumes[control->controlCount];
+    Float32 maxVolume;
+
+    switch (control->type) {
+    case PortControl::Volume:
+        if (!TestPortControlValidity(control)) {
+            return DEFAULT_VOLUME_VALUE;
+        }
+
+        if (!GetPortControlVolumes(control, subVolumes, &maxVolume)) {
+            return DEFAULT_VOLUME_VALUE;
+        }
+        result = maxVolume;
+        break;
+    case PortControl::Balance:
+        if (!TestPortControlValidity(control)) {
+            return DEFAULT_BALANCE_VALUE;
+        }
+
+        // balance control always has 2 volume controls
+        if (!GetPortControlVolumes(control, subVolumes, &maxVolume)) {
+            return DEFAULT_VOLUME_VALUE;
+        }
+        // calculate balance value
+        if (subVolumes[0] > subVolumes[1]) {
+            result = -1.0f + (subVolumes[1] / subVolumes[0]);
+        } else if (subVolumes[1] > subVolumes[0]) {
+            result = 1.0f - (subVolumes[0] / subVolumes[1]);
+        } else {
+            result = 0.0f;
+        }
+        break;
+    default:
+        ERROR1("GetFloatValue requested for non-Float control (control-type == %d)\n", control->type);
+        return 0;
+    }
+
+    TRACE1("<<PORT_GetFloatValue = %f\n", result);
+    return result;
+}
+
+void PORT_SetFloatValue(void* controlIDV, float value) {
+    TRACE1("> PORT_SetFloatValue = %f\n", value);
+    PortControl *control = (PortControl *)controlIDV;
+
+    if (!TestPortControlValidity(control)) {
+        return;
+    }
+
+    Float32 subVolumes[control->controlCount];
+    Float32 maxVolume;
+
+    switch (control->type) {
+    case PortControl::Volume:
+        if (!GetPortControlVolumes(control, subVolumes, &maxVolume)) {
+            return;
+        }
+        // update the values
+        if (maxVolume > 0.001) {
+            float multiplicator = value/maxVolume;
+            for (int i=0; i<control->controlCount; i++)
+                subVolumes[i] *= multiplicator;
+        } else {
+            // volume for all channels == 0, so set all channels to "value"
+            for (int i=0; i<control->controlCount; i++)
+                subVolumes[i] = value;
+        }
+        // set new values
+        SetPortControlVolumes(control, subVolumes);
+        break;
+    case PortControl::Balance:
+        // balance control always has 2 volume controls
+        if (!GetPortControlVolumes(control, subVolumes, &maxVolume)) {
+            return;
+        }
+        // calculate new values
+        if (value < 0.0f) {
+            subVolumes[0] = maxVolume;
+            subVolumes[1] = maxVolume * (value + 1.0f);
+        } else {
+            // this case also handles value == 0
+            subVolumes[0] = maxVolume * (1.0f - value);
+            subVolumes[1] = maxVolume;
+        }
+        // set new values
+        SetPortControlVolumes(control, subVolumes);
+        break;
+    default:
+        ERROR1("PORT_SetFloatValue requested for non-Float control (control-type == %d)\n", control->type);
+        return;
+    }
+}
+
+#endif // USE_PORTS
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..b5e0847
--- /dev/null
+++ b/jdk/src/macosx/native/jobjc/src/core/java/com/apple/jobjc/JObjCRuntime.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.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("amd64".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..f69a419
--- /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(NSInteger button, NSUInteger modifierFlags);
+
+#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..a215c10
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/AWTEvent.m
@@ -0,0 +1,1071 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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;
+}
+*/
+
+
+// REMIND: The fix for MACOSX_PORT-539 introduces Java-level implementation
+// of the function below (see CPlatformResponder). Consider removing this code.
+
+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);
+    }
+}
+
+jint GetJavaMouseModifiers(NSInteger button, NSUInteger modifierFlags)
+{
+    // Mousing needs the key modifiers
+    jint modifiers = NsKeyModifiersToJavaModifiers(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;
+    }
+
+    NSInteger extraButton = 3;
+    for (; extraButton < gNumberOfButtons; extraButton++) {
+        if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
+                                 extraButton)) {
+            modifiers |= gButtonDownMasks[extraButton];
+        }
+    }
+
+    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 buttonNumber], [event modifierFlags]);
+    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)
+{
+}
+
+/*
+ * Class:     sun_lwawt_macosx_event_NSEvent
+ * Method:    nsToJavaMouseModifiers
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL
+Java_sun_lwawt_macosx_event_NSEvent_nsToJavaMouseModifiers
+(JNIEnv *env, jclass cls, jint buttonNumber, jint modifierFlags)
+{
+    jint jmodifiers = 0;
+
+JNF_COCOA_ENTER(env);
+
+    jmodifiers = GetJavaMouseModifiers(buttonNumber, modifierFlags);
+
+JNF_COCOA_EXIT(env);
+
+    return jmodifiers;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_event_NSEvent
+ * Method:    nsToJavaKeyModifiers
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_sun_lwawt_macosx_event_NSEvent_nsToJavaKeyModifiers
+(JNIEnv *env, jclass cls, jint modifierFlags)
+{
+    jint jmodifiers = 0;
+
+JNF_COCOA_ENTER(env);
+
+    jmodifiers = NsKeyModifiersToJavaModifiers(modifierFlags);
+
+JNF_COCOA_EXIT(env);
+
+    return jmodifiers;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_event_NSEvent
+ * Method:    nsToJavaKeyInfo
+ * Signature: ([I[I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_sun_lwawt_macosx_event_NSEvent_nsToJavaKeyInfo
+(JNIEnv *env, jclass cls, jintArray inData, jintArray outData)
+{
+    BOOL postsTyped = NO;
+
+JNF_COCOA_ENTER(env);
+
+    jboolean copy = JNI_FALSE;
+    jint *data = (*env)->GetIntArrayElements(env, inData, &copy);
+
+    // in  = [testChar, testDeadChar, modifierFlags, keyCode]
+    jchar testChar = (jchar)data[0];
+    jchar testDeadChar = (jchar)data[1];
+    jint modifierFlags = data[2];
+    jshort keyCode = (jshort)data[3];
+
+    jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
+    jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
+
+    NsCharToJavaVirtualKeyCode((unichar)testChar, (unichar)testDeadChar,
+                               (NSUInteger)modifierFlags, (unsigned short)keyCode,
+                               &jkeyCode, &jkeyLocation, &postsTyped);
+
+    // out = [jkeyCode, jkeyLocation];
+    (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
+    (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
+
+    (*env)->ReleaseIntArrayElements(env, inData, data, 0);
+
+JNF_COCOA_EXIT(env);
+
+    return postsTyped;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_event_NSEvent
+ * Method:    nsKeyModifiersToJavaKeyInfo
+ * Signature: ([I[I)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_event_NSEvent_nsKeyModifiersToJavaKeyInfo
+(JNIEnv *env, jclass cls, jintArray inData, jintArray outData)
+{
+JNF_COCOA_ENTER(env);
+
+    jboolean copy = JNI_FALSE;
+    jint *data = (*env)->GetIntArrayElements(env, inData, &copy);
+
+    // in  = [modifierFlags, keyCode]
+    jint modifierFlags = data[0];
+    jshort keyCode = (jshort)data[1];
+
+    jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
+    jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
+    jint jkeyType = java_awt_event_KeyEvent_KEY_PRESSED;
+
+    NsKeyModifiersToJavaKeyInfo(modifierFlags,
+                                keyCode,
+                                &jkeyCode,
+                                &jkeyLocation,
+                                &jkeyType);
+
+    // out = [jkeyCode, jkeyLocation, jkeyType];
+    (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
+    (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
+    (*env)->SetIntArrayRegion(env, outData, 2, 1, &jkeyType);
+
+    (*env)->ReleaseIntArrayElements(env, inData, data, 0);
+
+JNF_COCOA_EXIT(env);
+}
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..5b61e27
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/AWTView.m
@@ -0,0 +1,1206 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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];
+
+#ifdef REMOTELAYER
+        CGLLayer *parentLayer = (CGLLayer*)self.cglLayer;
+        parentLayer.parentLayer = NULL;
+        parentLayer.remoteLayer = NULL;
+        if (JRSRemotePort != 0 && remoteSocketFD > 0) {
+            CGLLayer *remoteLayer = [[CGLLayer alloc] initWithJavaLayer: parentLayer.javaLayer];
+            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 */
+    }
+
+    return self;
+}
+
+- (void) dealloc {
+AWT_ASSERT_APPKIT_THREAD;
+
+    self.cglLayer = nil;
+
+    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];
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {
+        [[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];
+}
+
+- (BOOL) performKeyEquivalent: (NSEvent *) event {
+    [self deliverJavaKeyEventHelper: event];
+    return NO;
+}
+
+/**
+ * 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];
+    }
+
+    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,
+                                  [event type],
+                                  [event modifierFlags],
+                                  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)updateTrackingAreas {
+    [super updateTrackingAreas];
+    [self resetTrackingRect];
+}
+
+- (void) resetCursorRects {
+    [super resetCursorRects];
+    [self resetTrackingRect];
+}
+
+-(void) deliverJavaKeyEventHelper: (NSEvent *) event {
+    [AWTToolkit eventCountPlusPlus];
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+    jstring characters = NULL;
+    if ([event type] != NSFlagsChanged) {
+        characters = JNFNSToJavaString(env, [event characters]);
+    }
+
+    static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/event/NSEvent");
+    static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;)V");
+    jobject jevent = JNFNewObject(env, jctor_NSEvent,
+                                  [event type],
+                                  [event modifierFlags],
+                                  [event keyCode],
+                                  characters);
+
+    static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
+    static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView,
+                            "deliverKeyEvent", "(Lsun/lwawt/macosx/event/NSEvent;)V");
+    JNFCallVoidMethod(env, m_cPlatformView, jm_deliverKeyEvent, jevent);
+
+    if (characters != NULL) {
+        (*env)->DeleteLocalRef(env, characters);
+    }
+}
+
+- (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..5beb2eb
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/AWTWindow.m
@@ -0,0 +1,1016 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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) {
+        // 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) {
+            // 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);
+            (*env)->DeleteLocalRef(env, awtWindow);
+        }
+        (*env)->DeleteLocalRef(env, platformWindow);
+    }
+}
+
+- (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);
+    (*env)->DeleteLocalRef(env, platformWindow);
+}
+
+- (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];
+    if (platformWindow != NULL) {
+        static JNF_MEMBER_CACHE(jm_deliverZoom, jc_CPlatformWindow, "deliverZoom", "(Z)V");
+        JNFCallVoidMethod(env, platformWindow, jm_deliverZoom, ![window isZoomed]);
+        (*env)->DeleteLocalRef(env, platformWindow);
+    }
+    return YES;
+}
+
+- (void) _deliverIconify:(BOOL)iconify {
+AWT_ASSERT_APPKIT_THREAD;
+
+    [AWTToolkit eventCountPlusPlus];
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    if (platformWindow != NULL) {
+        static JNF_MEMBER_CACHE(jm_deliverIconify, jc_CPlatformWindow, "deliverIconify", "(Z)V");
+        JNFCallVoidMethod(env, platformWindow, jm_deliverIconify, iconify);
+        (*env)->DeleteLocalRef(env, platformWindow);
+    }
+}
+
+- (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];
+    if (platformWindow != NULL) {
+        static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(Z)V");
+        JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused);
+        (*env)->DeleteLocalRef(env, platformWindow);
+    }
+}
+
+
+- (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];
+    if (platformWindow != NULL) {
+        static JNF_MEMBER_CACHE(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V");
+        JNFCallVoidMethod(env, platformWindow, jm_windowDidBecomeMain);
+        (*env)->DeleteLocalRef(env, platformWindow);
+    }
+}
+
+- (BOOL)windowShouldClose:(id)sender {
+AWT_ASSERT_APPKIT_THREAD;
+    [AWTToolkit eventCountPlusPlus];
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    if (platformWindow != NULL) {
+        static JNF_MEMBER_CACHE(jm_deliverWindowClosingEvent, jc_CPlatformWindow, "deliverWindowClosingEvent", "()V");
+        JNFCallVoidMethod(env, platformWindow, jm_deliverWindowClosingEvent);
+        (*env)->DeleteLocalRef(env, platformWindow);
+    }
+    // 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 platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    if (platformWindow != NULL) {
+        jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target);
+        if (awtWindow != NULL) {
+            JNFCallStaticVoidMethod(env, jm_notifyFullScreenOperation, awtWindow, op);
+            (*env)->DeleteLocalRef(env, awtWindow);
+        }
+        (*env)->DeleteLocalRef(env, platformWindow);
+    }
+}
+
+
+- (void)windowWillEnterFullScreen:(NSNotification *)notification {
+    static JNF_MEMBER_CACHE(jm_windowWillEnterFullScreen, jc_CPlatformWindow, "windowWillEnterFullScreen", "()V");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    if (platformWindow != NULL) {
+        JNFCallVoidMethod(env, platformWindow, jm_windowWillEnterFullScreen);
+        [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_ENTER withEnv:env];
+        (*env)->DeleteLocalRef(env, platformWindow);
+    }
+}
+
+- (void)windowDidEnterFullScreen:(NSNotification *)notification {
+    static JNF_MEMBER_CACHE(jm_windowDidEnterFullScreen, jc_CPlatformWindow, "windowDidEnterFullScreen", "()V");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    if (platformWindow != NULL) {
+        JNFCallVoidMethod(env, platformWindow, jm_windowDidEnterFullScreen);
+        [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_ENTER withEnv:env];
+        (*env)->DeleteLocalRef(env, platformWindow);
+    }
+}
+
+- (void)windowWillExitFullScreen:(NSNotification *)notification {
+    static JNF_MEMBER_CACHE(jm_windowWillExitFullScreen, jc_CPlatformWindow, "windowWillExitFullScreen", "()V");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    if (platformWindow != NULL) {
+        JNFCallVoidMethod(env, platformWindow, jm_windowWillExitFullScreen);
+        [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_EXIT withEnv:env];
+        (*env)->DeleteLocalRef(env, platformWindow);
+    }
+}
+
+- (void)windowDidExitFullScreen:(NSNotification *)notification {
+    static JNF_MEMBER_CACHE(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V");
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+    if (platformWindow != NULL) {
+        JNFCallVoidMethod(env, platformWindow, jm_windowDidExitFullScreen);
+        [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_EXIT withEnv:env];
+        (*env)->DeleteLocalRef(env, platformWindow);
+    }
+}
+
+- (void)sendEvent:(NSEvent *)event {
+        if ([event type] == NSLeftMouseDown || [event type] == NSRightMouseDown || [event type] == NSOtherMouseDown) {
+
+            NSPoint p = [NSEvent mouseLocation];
+            NSRect frame = [self frame];
+            NSRect contentRect = [self contentRectForFrameRect:frame];
+
+            // Check if the click happened in the non-client area (title bar)
+            if (p.y >= (frame.origin.y + contentRect.size.height)) {
+                JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+                jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+                // Currently, no need to deliver the whole NSEvent.
+                static JNF_MEMBER_CACHE(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V");
+                JNFCallVoidMethod(env, platformWindow, jm_deliverNCMouseDown);
+            }
+        }
+        [super sendEvent:event];
+}
+@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);
+}
+
+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..27f505e
--- /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..4453d2f
--- /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.window.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..0d78469
--- /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:     sun_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..5fdf711
--- /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:     sun_lwawt_macosx_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..c04d568
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CRobot.m
@@ -0,0 +1,652 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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"
+#import "java_awt_event_InputEvent.h"
+
+
+// Starting number for event numbers generated by Robot.
+// Apple docs don't mention at all what are the requirements
+// for these numbers. It seems that they must be higher
+// than event numbers from real events, which start at some
+// value close to zero. There is no API for obtaining current
+// event number, so we have to start from some random number.
+// 32000 as starting value works for me, let's hope that it will
+// work for others as well.
+#define ROBOT_EVENT_NUMBER_START 32000
+
+#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;
+
+// Apparently, for mouse up/down events we have to set an event number
+// that is incremented on each button press. Otherwise, strange things
+// happen with z-order.
+static int gsEventNumber;
+static int* gsButtonEventNumber;
+
+static inline CGKeyCode GetCGKeyCode(jint javaKeyCode);
+
+static void PostMouseEvent(const CGPoint point, CGMouseButton button,
+                           CGEventType type, int clickCount, int eventNumber);
+
+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)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) {
+        int i;
+        jint* tmp;
+        jboolean copy = JNI_FALSE;
+
+        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;
+        gsEventNumber = ROBOT_EVENT_NUMBER_START;
+
+        gsButtonEventNumber = (int*)malloc(sizeof(int) * gNumberOfButtons);
+        if (gsButtonEventNumber == NULL) {
+            JNU_ThrowOutOfMemoryError(env, NULL);
+            return;
+        }
+
+        for (i = 0; i < gNumberOfButtons; ++i) {
+            gsButtonEventNumber[i] = ROBOT_EVENT_NUMBER_START;
+        }
+    }
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CRobot
+ * Method:    mouseEvent
+ * Signature: (IIIIZZ)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CRobot_mouseEvent
+(JNIEnv *env, jobject peer,
+ jint screenIndex, jint mouseLastX, jint mouseLastY, jint buttonsState,
+ jboolean isButtonsDownState, jboolean isMouseMove)
+{
+    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;
+
+    __block CGMouseButton button = kCGMouseButtonLeft;
+    __block CGEventType type = kCGEventMouseMoved;
+
+    void (^HandleRobotButton)(CGMouseButton, CGEventType, CGEventType, CGEventType) =
+        ^(CGMouseButton cgButton, CGEventType cgButtonUp, CGEventType cgButtonDown,
+          CGEventType cgButtonDragged) {
+
+            button = cgButton;
+            type = cgButtonUp;
+
+            if (isButtonsDownState) {
+                if (isMouseMove) {
+                    type = cgButtonDragged;
+                } else {
+                    type = cgButtonDown;
+                }
+            }
+        };
+
+    // Left
+    if (buttonsState & java_awt_event_InputEvent_BUTTON1_MASK ||
+        buttonsState & java_awt_event_InputEvent_BUTTON1_DOWN_MASK ) {
+
+        HandleRobotButton(kCGMouseButtonLeft, kCGEventLeftMouseUp,
+                          kCGEventLeftMouseDown, kCGEventLeftMouseDragged);
+    }
+
+    // Other
+    if (buttonsState & java_awt_event_InputEvent_BUTTON2_MASK ||
+        buttonsState & java_awt_event_InputEvent_BUTTON2_DOWN_MASK ) {
+
+        HandleRobotButton(kCGMouseButtonCenter, kCGEventOtherMouseUp,
+                          kCGEventOtherMouseDown, kCGEventOtherMouseDragged);
+    }
+
+    // Right
+    if (buttonsState & java_awt_event_InputEvent_BUTTON3_MASK ||
+        buttonsState & java_awt_event_InputEvent_BUTTON3_DOWN_MASK ) {
+
+        HandleRobotButton(kCGMouseButtonRight, kCGEventRightMouseUp,
+                          kCGEventRightMouseDown, kCGEventRightMouseDragged);
+    }
+
+    // Extra
+    if (gNumberOfButtons > 3) {
+        int extraButton;
+        for (extraButton = 3; extraButton < gNumberOfButtons; ++extraButton) {
+            if ((buttonsState & gButtonDownMasks[extraButton])) {
+                HandleRobotButton(extraButton, kCGEventOtherMouseUp,
+                            kCGEventOtherMouseDown, kCGEventOtherMouseDragged);
+            }
+        }
+    }
+
+    int clickCount = 0;
+    int eventNumber = gsEventNumber;
+
+    if (isMouseMove) {
+        // any mouse movement resets click count
+        gsLastClickTime = 0;
+    } else {
+        clickCount = GetClickCount(isButtonsDownState);
+
+        if (isButtonsDownState) {
+            gsButtonEventNumber[button] = gsEventNumber++;
+        }
+        eventNumber = gsButtonEventNumber[button];
+    }
+
+    PostMouseEvent(point, button, type, clickCount, eventNumber);
+
+    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, int eventNumber)
+{
+    CGEventRef mouseEvent = CGEventCreateMouseEvent(NULL, type, point, button);
+    if (mouseEvent != NULL) {
+        CGEventSetIntegerValueField(mouseEvent, kCGMouseEventClickState, clickCount);
+        CGEventSetIntegerValueField(mouseEvent, kCGMouseEventNumber, eventNumber);
+        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..01ab801
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CSystemColors.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.
+ */
+
+#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];
+    const CGFloat color = (CGFloat)0xEE/(CGFloat)0xFF;
+    sColors[java_awt_SystemColor_WINDOW] = [NSColor colorWithCalibratedRed:color green:color blue:color alpha:1.0f];
+    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..b9c2942
--- /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..dd3c75d
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/CWrapper.m
@@ -0,0 +1,739 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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"
+
+#import "sun_lwawt_macosx_CWrapper_NSWindow.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:YES 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:YES 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);
+}
+
+// Used for CWrapper.NSWindow.setLevel() (and level() which isn't implemented yet)
+static NSInteger LEVELS[sun_lwawt_macosx_CWrapper_NSWindow_MAX_WINDOW_LEVELS];
+static void initLevels()
+{
+    static dispatch_once_t pred;
+
+    dispatch_once(&pred, ^{
+        LEVELS[sun_lwawt_macosx_CWrapper_NSWindow_NSNormalWindowLevel] = NSNormalWindowLevel;
+        LEVELS[sun_lwawt_macosx_CWrapper_NSWindow_NSFloatingWindowLevel] = NSFloatingWindowLevel;
+    });
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    setLevel
+ * Signature: (JI)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setLevel
+(JNIEnv *env, jclass cls, jlong windowPtr, jint level)
+{
+JNF_COCOA_ENTER(env);
+
+    if (level >= 0 && level < sun_lwawt_macosx_CWrapper_NSWindow_MAX_WINDOW_LEVELS) {
+        initLevels();
+
+        NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+        [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+            [window setLevel: LEVELS[level]];
+        }];
+    } else {
+        [JNFException raise:env as:kIllegalArgumentException reason:"unknown level"];
+    }
+
+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..fe925d7
--- /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:     sun_lwawt_macosx_CAccessibility
+ * Method:    roleKey
+ * Signature: (Ljavax/accessibility/AccessibleRole;)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_sun_lwawt_macosx_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..61ba619
--- /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__, [self 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..c318421
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.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 <pthread.h>
+#import <assert.h>
+
+#import <Cocoa/Cocoa.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import <CoreServices/CoreServices.h>
+#import <AudioToolbox/AudioToolbox.h>
+
+#define DEBUG 1
+
+// number of mouse buttons supported
+extern int gNumberOfButtons;
+
+// InputEvent mask array
+extern jint* gButtonDownMasks;
+
+@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..96bea05
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.m
@@ -0,0 +1,455 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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>
+
+#include "jni_util.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"
+
+int gNumberOfButtons;
+jint* gButtonDownMasks;
+
+@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);
+    });
+
+    gNumberOfButtons = sun_lwawt_macosx_LWCToolkit_BUTTONS;
+
+    jclass inputEventClazz = (*env)->FindClass(env, "java/awt/event/InputEvent");
+    jmethodID getButtonDownMasksID = (*env)->GetStaticMethodID(env, inputEventClazz, "getButtonDownMasks", "()[I");
+    jintArray obj = (jintArray)(*env)->CallStaticObjectMethod(env, inputEventClazz, getButtonDownMasksID);
+    jint * tmp = (*env)->GetIntArrayElements(env, obj, JNI_FALSE);
+
+    gButtonDownMasks = (jint*)malloc(sizeof(jint) * gNumberOfButtons);
+    if (gButtonDownMasks == NULL) {
+        gNumberOfButtons = 0;
+        JNU_ThrowOutOfMemoryError(env, NULL);
+        return;
+    }
+
+    int i;
+    for (i = 0; i < gNumberOfButtons; i++) {
+        gButtonDownMasks[i] = tmp[i];
+    }
+
+    (*env)->ReleaseIntArrayElements(env, obj, tmp, 0);
+    (*env)->DeleteLocalRef(env, obj);
+}
+
+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_lwawt_macosx_LWCToolkit
+ * Method:    isCapsLockOn
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_isCapsLockOn
+(JNIEnv *env, jobject self)
+{
+    __block jboolean isOn = JNI_FALSE;
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+        NSUInteger modifiers = [NSEvent modifierFlags];
+        isOn = (modifiers & NSAlphaShiftKeyMask) != 0;
+    }];
+
+    return isOn;
+}
+
+/*
+ * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    isApplicationActive
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_isApplicationActive
+(JNIEnv *env, jclass clazz)
+{
+        __block jboolean active = JNI_FALSE;
+
+AWT_ASSERT_NOT_APPKIT_THREAD;
+JNF_COCOA_ENTER(env);
+
+        [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^() {
+                active = (jboolean)[NSRunningApplication currentApplication].active;
+        }];
+
+JNF_COCOA_EXIT(env);
+
+        return active;
+}
+
+
+/*
+ * 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..c519beb
--- /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..709fbe4
--- /dev/null
+++ b/jdk/src/macosx/native/sun/awt/splashscreen/splashscreen_sys.m
@@ -0,0 +1,389 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 NSScreen* SplashNSScreen()
+{
+    return [[NSScreen screens] objectAtIndex: 0];
+}
+
+static void SplashCenter(Splash * splash)
+{
+    NSRect screenFrame = [SplashNSScreen() frame];
+
+    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
+                         screen: SplashNSScreen()];
+
+        [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..ebceaa8
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.h
@@ -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.
+ */
+
+#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 {}
++ (void) _getCGLConfigInfo: (NSMutableArray *)argValue;
+@end
+
+// 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.
+
+/* Do 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.
+ */
+//#define REMOTELAYER 1
+
+#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 */
+
+
+/**
+ * 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..ba1f2bc
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m
@@ -0,0 +1,447 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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]];
+  if ([NSThread isMainThread]) {
+      [GraphicsConfigUtil _getCGLConfigInfo: retArray];
+  } else {
+      [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..4ace0e8
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLLayer.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.
+ */
+
+#ifndef CGLLayer_h_Included
+#define CGLLayer_h_Included
+
+#import "AWTView.h"
+
+@interface CGLLayer : CAOpenGLLayer
+{
+@private
+    JNFJObjectWrapper *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 (nonatomic, retain) JNFJObjectWrapper *javaLayer;
+@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:(JNFJObjectWrapper *)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..736a24b
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLLayer.m
@@ -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.
+ */
+
+#import "CGLGraphicsConfig.h"
+#import "CGLLayer.h"
+#import "ThreadUtilities.h"
+#import "LWCToolkit.h"
+#import "CGLSurfaceData.h"
+
+
+extern NSOpenGLPixelFormat *sharedPixelFormat;
+extern NSOpenGLContext *sharedContext;
+
+@implementation CGLLayer
+
+@synthesize javaLayer;
+@synthesize textureID;
+@synthesize target;
+@synthesize textureWidth;
+@synthesize textureHeight;
+#ifdef REMOTELAYER
+@synthesize parentLayer;
+@synthesize remoteLayer;
+@synthesize jrsRemoteLayer;
+#endif
+
+- (id) initWithJavaLayer:(JNFJObjectWrapper *)layer;
+{
+AWT_ASSERT_APPKIT_THREAD;
+    // Initialize ourselves
+    self = [super init];
+    if (self == nil) return self;
+
+    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 {
+    self.javaLayer = nil;
+    [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");
+
+    jobject javaLayerLocalRef = [self.javaLayer jObjectWithEnv:env];
+    JNFCallVoidMethod(env, javaLayerLocalRef, jm_drawInCGLContext);
+    (*env)->DeleteLocalRef(env, javaLayerLocalRef);
+
+    // 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;
+
+    JNFJObjectWrapper *javaLayer = [JNFJObjectWrapper wrapperWithJObject:obj withEnv:env];
+
+    [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..7623ab5
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLSurfaceData.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.
+ */
+
+#ifndef CGLSurfaceData_h_Included
+#define CGLSurfaceData_h_Included
+
+#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;
+} 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..34ba33c
--- /dev/null
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLSurfaceData.m
@@ -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.
+ */
+
+#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) {
+        // detach the NSView from the NSOpenGLContext
+        CGLGraphicsConfigInfo *cglInfo = cglsdo->configInfo;
+        OGLContext *oglc = cglInfo->context;
+        CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
+        [ctxinfo->context clearDrawable];
+    }
+
+    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)
+        j2d_glBindTexture(GL_TEXTURE_2D, 0);
+        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 {
+        CGLSDOps *cglsdo = (CGLSDOps *)dstOps->privOps;
+        NSView *nsView = (NSView *)cglsdo->peerData;
+
+        if ([ctxinfo->context view] != nsView) {
+            [ctxinfo->context makeCurrentContext];
+            [ctxinfo->context setView: nsView];
+        }
+    }
+
+    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);
+    }
+
+    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;
+}
+
+/**
+ * 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;
+    oglsdo->isOpaque = JNI_TRUE;
+    oglsdo->width = surfaceBounds.size.width;
+    oglsdo->height = surfaceBounds.size.height;
+JNF_COCOA_EXIT(env);
+
+    J2dTraceLn2(J2D_TRACE_VERBOSE, "  created window: w=%d h=%d", oglsdo->width, oglsdo->height);
+
+    return JNI_TRUE;
+}
+
+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];
+
+#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.
+                 */
+                if (layer.remoteLayer != nil) {
+                    CGLLayer* remoteLayer = layer.remoteLayer;
+                    remoteLayer.target = GL_TEXTURE_2D;
+                    remoteLayer.textureID = layer.textureID;
+                    remoteLayer.textureWidth = layer.textureWidth;
+                    remoteLayer.textureHeight = layer.textureHeight;
+                    [remoteLayer setNeedsDisplay];
+                }
+#endif /* REMOTELAYER */
+            }];
+        }
+    }
+}
+
+#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;
+
+    oglsdo->width = width;
+    oglsdo->height = height;
+    oglsdo->isOpaque = isOpaque;
+
+    if (oglsdo->drawableType == OGLSD_WINDOW) {
+        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);
+        [ctxinfo->context update];
+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..4128c87
--- /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..053837b
--- /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..26d9859
--- /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..6ff6b13
--- /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/emessages.h b/jdk/src/share/bin/emessages.h
index da79305..8538a8d 100644
--- a/jdk/src/share/bin/emessages.h
+++ b/jdk/src/share/bin/emessages.h
@@ -87,6 +87,7 @@
 #define JRE_ERROR10     "Error: Unable to resolve current executable"
 #define JRE_ERROR11     "Error: Path length exceeds maximum length (PATH_MAX)"
 #define JRE_ERROR12     "Error: Exec of %s failed"
+#define JRE_ERROR13     "Error: String processing operation failed"
 
 #define DLL_ERROR1      "Error: dl failure on line %d"
 #define DLL_ERROR2      "Error: failed %s, because %s"
diff --git a/jdk/src/share/bin/java.c b/jdk/src/share/bin/java.c
index 2d88dc9..3133258 100644
--- a/jdk/src/share/bin/java.c
+++ b/jdk/src/share/bin/java.c
@@ -147,7 +147,6 @@
 static void GrowKnownVMs();
 static int  KnownVMIndex(const char* name);
 static void FreeKnownVMs();
-static void ShowSplashScreen();
 static jboolean IsWildCardEnabled();
 
 #define ARG_CHECK(n, f, a) if (n < 1) { \
@@ -165,25 +164,6 @@
 static jlong maxHeapSize        = 0;  /* max heap size */
 static jlong initialHeapSize    = 0;  /* inital heap size */
 
-int JNICALL JavaMain(void * args); /* entry point                  */
-
-enum LaunchMode {               // cf. sun.launcher.LauncherHelper
-    LM_UNKNOWN = 0,
-    LM_CLASS,
-    LM_JAR
-};
-
-static const char *launchModeNames[]
-    = { "Unknown", "Main class", "JAR file" };
-
-typedef struct {
-    int    argc;
-    char **argv;
-    int    mode;
-    char  *what;
-    InvocationFunctions ifn;
-} JavaMainArgs;
-
 /*
  * Entry point.
  */
@@ -210,6 +190,7 @@
     jlong start, end;
     char jvmpath[MAXPATHLEN];
     char jrepath[MAXPATHLEN];
+    char jvmcfg[MAXPATHLEN];
 
     _fVersion = fullversion;
     _dVersion = dotversion;
@@ -252,7 +233,8 @@
 
     CreateExecutionEnvironment(&argc, &argv,
                                jrepath, sizeof(jrepath),
-                               jvmpath, sizeof(jvmpath));
+                               jvmpath, sizeof(jvmpath),
+                               jvmcfg,  sizeof(jvmcfg));
 
     ifn.CreateJavaVM = 0;
     ifn.GetDefaultJavaVMInitArgs = 0;
@@ -312,11 +294,7 @@
     /* set the -Dsun.java.launcher.* platform properties */
     SetJavaLauncherPlatformProps();
 
-    /* Show the splash screen if needed */
-    ShowSplashScreen();
-
-    return ContinueInNewThread(&ifn, argc, argv, mode, what, ret);
-
+    return JVMInit(&ifn, threadStackSize, argc, argv, mode, what, ret);
 }
 /*
  * Always detach the main thread so that it appears to have ended when
@@ -375,6 +353,8 @@
     int ret = 0;
     jlong start, end;
 
+    RegisterThread();
+
     /* Initialize the virtual machine */
     start = CounterGet();
     if (!InitializeJVM(&vm, &env, &ifn)) {
@@ -444,7 +424,7 @@
      */
     mainClass = LoadMainClass(env, mode, what);
     CHECK_EXCEPTION_NULL_LEAVE(mainClass);
-
+    PostJVMInit(env, mainClass, vm);
     /*
      * The LoadMainClass not only loads the main class, it will also ensure
      * that the main method's signature is correct, therefore further checking
@@ -1067,7 +1047,9 @@
                    JLI_StrCmp(arg, "-jre-restrict-search") == 0 ||
                    JLI_StrCCmp(arg, "-splash:") == 0) {
             ; /* Ignore machine independent options already handled */
-        } else if (RemovableOption(arg) ) {
+        } else if (ProcessPlatformOption(arg)) {
+            ; /* Processing of platform dependent options */
+        } else if (RemovableOption(arg)) {
             ; /* Do not pass option to vm. */
         } else {
             AddOption(arg, NULL);
@@ -1129,17 +1111,6 @@
     return r == JNI_OK;
 }
 
-
-#define NULL_CHECK0(e) if ((e) == 0) { \
-    JLI_ReportErrorMessage(JNI_ERROR); \
-    return 0; \
-  }
-
-#define NULL_CHECK(e) if ((e) == 0) { \
-    JLI_ReportErrorMessage(JNI_ERROR); \
-    return; \
-  }
-
 static jclass helperClass = NULL;
 
 static jclass
@@ -1598,10 +1569,9 @@
  * mechanism.
  */
 jint
-ReadKnownVMs(const char *jrepath, const char * arch, jboolean speculative)
+ReadKnownVMs(const char *jvmCfgName, jboolean speculative)
 {
     FILE *jvmCfg;
-    char jvmCfgName[MAXPATHLEN+20];
     char line[MAXPATHLEN+20];
     int cnt = 0;
     int lineno = 0;
@@ -1614,8 +1584,6 @@
     if (JLI_IsTraceLauncher()) {
         start = CounterGet();
     }
-    JLI_Snprintf(jvmCfgName, sizeof(jvmCfgName), "%s%slib%s%s%sjvm.cfg",
-        jrepath, FILESEP, FILESEP, arch, FILESEP);
 
     jvmCfg = fopen(jvmCfgName, "r");
     if (jvmCfg == NULL) {
@@ -1775,7 +1743,7 @@
  * Displays the splash screen according to the jar file name
  * and image file names stored in environment variables
  */
-static void
+void
 ShowSplashScreen()
 {
     const char *jar_name = getenv(SPLASH_JAR_ENV_ENTRY);
@@ -1852,8 +1820,9 @@
     return _wc_enabled;
 }
 
-static int
-ContinueInNewThread(InvocationFunctions* ifn, int argc, char **argv,
+int
+ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,
+                    int argc, char **argv,
                     int mode, char *what, int ret)
 {
 
diff --git a/jdk/src/share/bin/java.h b/jdk/src/share/bin/java.h
index 04c2091..5bf3db3 100644
--- a/jdk/src/share/bin/java.h
+++ b/jdk/src/share/bin/java.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -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
@@ -125,7 +127,8 @@
  */
 void CreateExecutionEnvironment(int *argc, char ***argv,
                                 char *jrepath, jint so_jrepath,
-                                char *jvmpath, jint so_jvmpath);
+                                char *jvmpath, jint so_jvmpath,
+                                char *jvmcfg,  jint so_jvmcfg);
 
 /* Reports an error message to stderr or a window as appropriate. */
 void JLI_ReportErrorMessage(const char * message, ...);
@@ -159,7 +162,7 @@
 /*
  * Functions defined in java.c and used in java_md.c.
  */
-jint ReadKnownVMs(const char *jrepath, const char * arch, jboolean speculative);
+jint ReadKnownVMs(const char *jvmcfg, jboolean speculative);
 char *CheckJvmType(int *argc, char ***argv, jboolean speculative);
 void AddOption(char *str, void *info);
 
@@ -178,9 +181,13 @@
 
 jboolean ServerClassMachine();
 
-static int ContinueInNewThread(InvocationFunctions* ifn,
-                               int argc, char** argv,
-                               int mode, char *what, int ret);
+int ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,
+                   int argc, char** argv,
+                   int mode, char *what, int ret);
+
+int JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
+                   int argc, char** argv,
+                   int mode, char *what, int ret);
 
 /*
  * Initialize platform specific settings
@@ -188,6 +195,21 @@
 void InitLauncher(jboolean javaw);
 
 /*
+ * For MacOSX and Windows/Unix compatibility we require these
+ * entry points, some of them may be stubbed out on Windows/Unixes.
+ */
+void     PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm);
+void     ShowSplashScreen();
+void     RegisterThread();
+/*
+ * this method performs additional platform specific processing and
+ * should return JNI_TRUE to indicate the argument has been consumed,
+ * otherwise returns JNI_FALSE to allow the calling logic to further
+ * process the option.
+ */
+jboolean ProcessPlatformOption(const char *arg);
+
+/*
  * This allows for finding classes from the VM's bootstrap class loader directly,
  * FindClass uses the application class loader internally, this will cause
  * unnecessary searching of the classpath for the required classes.
@@ -196,4 +218,34 @@
 typedef jclass (JNICALL FindClassFromBootLoader_t(JNIEnv *env,
                                                   const char *name));
 jclass FindBootStrapClass(JNIEnv *env, const char *classname);
+
+int JNICALL JavaMain(void * args); /* entry point                  */
+
+enum LaunchMode {               // cf. sun.launcher.LauncherHelper
+    LM_UNKNOWN = 0,
+    LM_CLASS,
+    LM_JAR
+};
+
+static const char *launchModeNames[]
+    = { "Unknown", "Main class", "JAR file" };
+
+typedef struct {
+    int    argc;
+    char **argv;
+    int    mode;
+    char  *what;
+    InvocationFunctions ifn;
+} JavaMainArgs;
+
+#define NULL_CHECK0(e) if ((e) == 0) { \
+    JLI_ReportErrorMessage(JNI_ERROR); \
+    return 0; \
+  }
+
+#define NULL_CHECK(e) if ((e) == 0) { \
+    JLI_ReportErrorMessage(JNI_ERROR); \
+    return; \
+  }
+
 #endif /* _JAVA_H_ */
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/toolkit/url/UrlUtil.java b/jdk/src/share/classes/com/sun/jndi/toolkit/url/UrlUtil.java
index 0f6c1d5..2e5858b 100644
--- a/jdk/src/share/classes/com/sun/jndi/toolkit/url/UrlUtil.java
+++ b/jdk/src/share/classes/com/sun/jndi/toolkit/url/UrlUtil.java
@@ -27,6 +27,7 @@
 
 import java.net.MalformedURLException;
 import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
 
 /**
  * Utilities for dealing with URLs.
@@ -61,29 +62,14 @@
      * The string is subsequently converted using the specified encoding
      */
     public static final String decode(String s, String enc)
-        throws MalformedURLException, UnsupportedEncodingException {
-
-        int length = s.length();
-        byte[] bytes = new byte[length];
-        int j = 0;
-
-        for (int i = 0; i < length; i++) {
-            if (s.charAt(i) == '%') {
-                i++;  // skip %
-                try {
-                    bytes[j++] = (byte)
-                        Integer.parseInt(s.substring(i, i + 2), 16);
-
-                } catch (Exception e) {
-                    throw new MalformedURLException("Invalid URI encoding: " + s);
-                }
-                i++;  // skip first hex char; for loop will skip second one
-            } else {
-                bytes[j++] = (byte) s.charAt(i);
-            }
+            throws MalformedURLException, UnsupportedEncodingException {
+        try {
+            return URLDecoder.decode(s, enc);
+        } catch (IllegalArgumentException iae) {
+            MalformedURLException mue = new MalformedURLException("Invalid URI encoding: " + s);
+            mue.initCause(iae);
+            throw mue;
         }
-
-        return new String(bytes, 0, j, enc);
     }
 
     /**
diff --git a/jdk/src/share/classes/com/sun/net/httpserver/spi/HttpServerProvider.java b/jdk/src/share/classes/com/sun/net/httpserver/spi/HttpServerProvider.java
index 7b5c053..02ede0b 100644
--- a/jdk/src/share/classes/com/sun/net/httpserver/spi/HttpServerProvider.java
+++ b/jdk/src/share/classes/com/sun/net/httpserver/spi/HttpServerProvider.java
@@ -76,7 +76,7 @@
      *
      * @throws  SecurityException
      *          If a security manager has been installed and it denies
-     *          {@link RuntimePermission}{@code("httpServerProvider")}
+     *          {@link RuntimePermission}{@code ("httpServerProvider")}
      */
     protected HttpServerProvider() {
         SecurityManager sm = System.getSecurityManager();
diff --git a/jdk/src/share/classes/com/sun/rmi/rmid/ExecOptionPermission.java b/jdk/src/share/classes/com/sun/rmi/rmid/ExecOptionPermission.java
index 75fe0a2..fd6f50c 100644
--- a/jdk/src/share/classes/com/sun/rmi/rmid/ExecOptionPermission.java
+++ b/jdk/src/share/classes/com/sun/rmi/rmid/ExecOptionPermission.java
@@ -223,7 +223,7 @@
         implements java.io.Serializable
     {
 
-        private Hashtable permissions;
+        private Hashtable<String, Permission> permissions;
         private boolean all_allowed; // true if "*" is in the collection
         private static final long serialVersionUID = -1242475729790124375L;
 
@@ -231,7 +231,7 @@
          * Create an empty ExecOptionPermissionCollection.
          */
         public ExecOptionPermissionCollection() {
-            permissions = new Hashtable(11);
+            permissions = new Hashtable<>(11);
             all_allowed = false;
         }
 
@@ -291,7 +291,7 @@
 
             String pname = p.getName();
 
-            Permission x = (Permission) permissions.get(pname);
+            Permission x = permissions.get(pname);
 
             if (x != null)
                 // we have a direct hit!
@@ -306,7 +306,7 @@
             while ((last = pname.lastIndexOf(".", offset)) != -1) {
 
                 pname = pname.substring(0, last+1) + "*";
-                x = (Permission) permissions.get(pname);
+                x = permissions.get(pname);
 
                 if (x != null) {
                     return x.implies(permission);
@@ -321,7 +321,7 @@
             while ((last = pname.lastIndexOf("=", offset)) != -1) {
 
                 pname = pname.substring(0, last+1) + "*";
-                x = (Permission) permissions.get(pname);
+                x = permissions.get(pname);
 
                 if (x != null) {
                     return x.implies(permission);
@@ -341,7 +341,7 @@
          * @return an enumeration of all the ExecOptionPermission objects.
          */
 
-        public Enumeration elements()
+        public Enumeration<Permission> elements()
         {
             return permissions.elements();
         }
diff --git a/jdk/src/share/classes/com/sun/rmi/rmid/ExecPermission.java b/jdk/src/share/classes/com/sun/rmi/rmid/ExecPermission.java
index 45674fe..067b9db 100644
--- a/jdk/src/share/classes/com/sun/rmi/rmid/ExecPermission.java
+++ b/jdk/src/share/classes/com/sun/rmi/rmid/ExecPermission.java
@@ -227,7 +227,7 @@
         extends PermissionCollection
         implements java.io.Serializable
     {
-        private Vector permissions;
+        private Vector<Permission> permissions;
 
         private static final long serialVersionUID = -3352558508888368273L;
 
@@ -235,7 +235,7 @@
          * Create an empty ExecPermissionCollection.
          */
         public ExecPermissionCollection() {
-            permissions = new Vector();
+            permissions = new Vector<>();
         }
 
         /**
@@ -274,10 +274,10 @@
             if (! (permission instanceof ExecPermission))
                 return false;
 
-            Enumeration e = permissions.elements();
+            Enumeration<Permission> e = permissions.elements();
 
             while (e.hasMoreElements()) {
-                ExecPermission x = (ExecPermission) e.nextElement();
+                ExecPermission x = (ExecPermission)e.nextElement();
                 if (x.implies(permission)) {
                     return true;
                 }
@@ -291,7 +291,7 @@
          *
          * @return an enumeration of all the ExecPermission objects.
          */
-        public Enumeration elements()
+        public Enumeration<Permission> elements()
         {
             return permissions.elements();
         }
diff --git a/jdk/src/share/classes/java/awt/EventDispatchThread.java b/jdk/src/share/classes/java/awt/EventDispatchThread.java
index c707f02..427ad7e 100644
--- a/jdk/src/share/classes/java/awt/EventDispatchThread.java
+++ b/jdk/src/share/classes/java/awt/EventDispatchThread.java
@@ -107,6 +107,34 @@
         }
     }
 
+    // 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);
     }
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/beans/ChangeListenerMap.java b/jdk/src/share/classes/java/beans/ChangeListenerMap.java
index e623d9b..fa8be47 100644
--- a/jdk/src/share/classes/java/beans/ChangeListenerMap.java
+++ b/jdk/src/share/classes/java/beans/ChangeListenerMap.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -237,12 +237,5 @@
      *
      * @return a real listener
      */
-    public final L extract(L listener) {
-        while (listener instanceof EventListenerProxy) {
-            @SuppressWarnings("unchecked")
-            EventListenerProxy<L> proxy = (EventListenerProxy<L>) listener;
-            listener = proxy.getListener();
-        }
-        return listener;
-    }
+    public abstract L extract(L listener);
 }
diff --git a/jdk/src/share/classes/java/beans/PropertyChangeSupport.java b/jdk/src/share/classes/java/beans/PropertyChangeSupport.java
index 1ea326e..c3c7317 100644
--- a/jdk/src/share/classes/java/beans/PropertyChangeSupport.java
+++ b/jdk/src/share/classes/java/beans/PropertyChangeSupport.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -533,5 +533,15 @@
         protected PropertyChangeListener newProxy(String name, PropertyChangeListener listener) {
             return new PropertyChangeListenerProxy(name, listener);
         }
+
+        /**
+         * {@inheritDoc}
+         */
+        public final PropertyChangeListener extract(PropertyChangeListener listener) {
+            while (listener instanceof PropertyChangeListenerProxy) {
+                listener = ((PropertyChangeListenerProxy) listener).getListener();
+            }
+            return listener;
+        }
     }
 }
diff --git a/jdk/src/share/classes/java/beans/VetoableChangeSupport.java b/jdk/src/share/classes/java/beans/VetoableChangeSupport.java
index 318abd2..6b7e268 100644
--- a/jdk/src/share/classes/java/beans/VetoableChangeSupport.java
+++ b/jdk/src/share/classes/java/beans/VetoableChangeSupport.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -522,5 +522,15 @@
         protected VetoableChangeListener newProxy(String name, VetoableChangeListener listener) {
             return new VetoableChangeListenerProxy(name, listener);
         }
+
+        /**
+         * {@inheritDoc}
+         */
+        public final VetoableChangeListener extract(VetoableChangeListener listener) {
+            while (listener instanceof VetoableChangeListenerProxy) {
+                listener = ((VetoableChangeListenerProxy) listener).getListener();
+            }
+            return listener;
+        }
     }
 }
diff --git a/jdk/src/share/classes/java/lang/System.java b/jdk/src/share/classes/java/lang/System.java
index 67ec909..9569376 100644
--- a/jdk/src/share/classes/java/lang/System.java
+++ b/jdk/src/share/classes/java/lang/System.java
@@ -1168,11 +1168,6 @@
         // classes are used.
         sun.misc.VM.initializeOSEnvironment();
 
-        // Subsystems that are invoked during initialization can invoke
-        // sun.misc.VM.isBooted() in order to avoid doing things that should
-        // wait until the application class loader has been set up.
-        sun.misc.VM.booted();
-
         // The main thread is not added to its thread group in the same
         // way as other threads; we must do it ourselves here.
         Thread current = Thread.currentThread();
@@ -1180,6 +1175,12 @@
 
         // register shared secrets
         setJavaLangAccess();
+
+        // Subsystems that are invoked during initialization can invoke
+        // sun.misc.VM.isBooted() in order to avoid doing things that should
+        // wait until the application class loader has been set up.
+        // IMPORTANT: Ensure that this remains the last initialization action!
+        sun.misc.VM.booted();
     }
 
     private static void setJavaLangAccess() {
diff --git a/jdk/src/share/classes/java/lang/Thread.java b/jdk/src/share/classes/java/lang/Thread.java
index b3d2e39..474dbfc 100644
--- a/jdk/src/share/classes/java/lang/Thread.java
+++ b/jdk/src/share/classes/java/lang/Thread.java
@@ -1136,6 +1136,9 @@
     public final void setName(String name) {
         checkAccess();
         this.name = name.toCharArray();
+        if (threadStatus != 0) {
+            setNativeName(name);
+        }
     }
 
     /**
@@ -2032,4 +2035,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/lang/annotation/ContainerAnnotation.java b/jdk/src/share/classes/java/lang/annotation/ContainerAnnotation.java
new file mode 100644
index 0000000..ee35e8b
--- /dev/null
+++ b/jdk/src/share/classes/java/lang/annotation/ContainerAnnotation.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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.annotation;
+
+/**
+ * A meta-annotation to indicate which annotation type should be used
+ * as a container for repeated values of the annotation type modified
+ * by the {@code ContainerAnnotation} annotation.
+ *
+ * @since 1.8
+ * @jls 9.6 Annotation Types
+ * @jls 9.7 Annotations
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.ANNOTATION_TYPE)
+public @interface ContainerAnnotation {
+    /**
+     * The annotation type to use to store repeated values of another
+     * annotation.
+     */
+    Class<? extends Annotation> value();
+}
diff --git a/jdk/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java b/jdk/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java
index f1a4995..71e329a 100644
--- a/jdk/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java
+++ b/jdk/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java
@@ -26,6 +26,7 @@
 
 import java.io.FileDescriptor;
 import java.io.IOException;
+import java.security.AccessController;
 import sun.net.ResourceManager;
 
 /**
@@ -52,6 +53,15 @@
     private boolean loopbackMode = true;
     private int ttl = -1;
 
+    private static final String os = AccessController.doPrivileged(
+        new sun.security.action.GetPropertyAction("os.name")
+    );
+
+    /**
+     * flag set if the native connect() call not to be used
+     */
+    private final static boolean connectDisabled = os.startsWith("Mac OS");
+
     /**
      * Load net library into runtime.
      */
@@ -349,4 +359,7 @@
     protected abstract void connect0(InetAddress address, int port) throws SocketException;
     protected abstract void disconnect0(int family);
 
+    protected boolean nativeConnectDisabled() {
+        return connectDisabled;
+    }
 }
diff --git a/jdk/src/share/classes/java/net/DatagramSocket.java b/jdk/src/share/classes/java/net/DatagramSocket.java
index 9c9dec1..9e3bec3 100644
--- a/jdk/src/share/classes/java/net/DatagramSocket.java
+++ b/jdk/src/share/classes/java/net/DatagramSocket.java
@@ -133,7 +133,8 @@
           bind(new InetSocketAddress(0));
 
         // old impls do not support connect/disconnect
-        if (oldImpl) {
+        if (oldImpl || (impl instanceof AbstractPlainDatagramSocketImpl &&
+             ((AbstractPlainDatagramSocketImpl)impl).nativeConnectDisabled())) {
             connectState = ST_CONNECTED_NO_IMPL;
         } else {
             try {
@@ -752,9 +753,19 @@
                 // via the impl failed.
                 boolean stop = false;
                 while (!stop) {
+                    InetAddress peekAddress = null;
+                    int peekPort = -1;
                     // peek at the packet to see who it is from.
-                    InetAddress peekAddress = new InetAddress();
-                    int peekPort = getImpl().peek(peekAddress);
+                    if (!oldImpl) {
+                        // We can use the new peekData() API
+                        DatagramPacket peekPacket = new DatagramPacket(new byte[1], 1);
+                        peekPort = getImpl().peekData(peekPacket);
+                        peekAddress = peekPacket.getAddress();
+                    } else {
+                        // this api only works for IPv4
+                        peekAddress = new InetAddress();
+                        peekPort = getImpl().peek(peekAddress);
+                    }
                     if ((!connectedAddress.equals(peekAddress)) ||
                         (connectedPort != peekPort)) {
                         // throw the packet away and silently continue
diff --git a/jdk/src/share/classes/java/net/MulticastSocket.java b/jdk/src/share/classes/java/net/MulticastSocket.java
index 017131553..0038829 100644
--- a/jdk/src/share/classes/java/net/MulticastSocket.java
+++ b/jdk/src/share/classes/java/net/MulticastSocket.java
@@ -81,6 +81,13 @@
  */
 public
 class MulticastSocket extends DatagramSocket {
+
+    /**
+     * Used on some platforms to record if an outgoing interface
+     * has been set for this socket.
+     */
+    private boolean interfaceSet;
+
     /**
      * Create a multicast socket.
      *
@@ -303,6 +310,16 @@
             throw new SocketException("Not a multicast address");
         }
 
+        /**
+         * required for some platforms where it's not possible to join
+         * a group without setting the interface first.
+         */
+        NetworkInterface defaultInterface = NetworkInterface.getDefault();
+
+        if (!interfaceSet && defaultInterface != null) {
+            setNetworkInterface(defaultInterface);
+        }
+
         getImpl().join(mcastaddr);
     }
 
@@ -453,6 +470,7 @@
         synchronized (infLock) {
             getImpl().setOption(SocketOptions.IP_MULTICAST_IF, inf);
             infAddress = inf;
+            interfaceSet = true;
         }
     }
 
@@ -535,6 +553,7 @@
         synchronized (infLock) {
             getImpl().setOption(SocketOptions.IP_MULTICAST_IF2, netIf);
             infAddress = null;
+            interfaceSet = true;
         }
     }
 
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/util/prefs/Preferences.java b/jdk/src/share/classes/java/util/prefs/Preferences.java
index de85e07..391439c 100644
--- a/jdk/src/share/classes/java/util/prefs/Preferences.java
+++ b/jdk/src/share/classes/java/util/prefs/Preferences.java
@@ -289,10 +289,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/script/ScriptEngineManager.java b/jdk/src/share/classes/javax/script/ScriptEngineManager.java
index bb43053..c7932a8 100644
--- a/jdk/src/share/classes/javax/script/ScriptEngineManager.java
+++ b/jdk/src/share/classes/javax/script/ScriptEngineManager.java
@@ -37,7 +37,7 @@
  * collection of key/value pairs storing state shared by all engines created
  * by the Manager. This class uses the <a href="../../../technotes/guides/jar/jar.html#Service%20Provider">service provider</a> mechanism to enumerate all the
  * implementations of <code>ScriptEngineFactory</code>. <br><br>
- * The <code>ScriptEngineManager</code> provides a method to return an array of all these factories
+ * The <code>ScriptEngineManager</code> provides a method to return a list of all these factories
  * as well as utility methods which look up factories on the basis of language name, file extension
  * and mime type.
  * <p>
@@ -202,7 +202,7 @@
      * The algorithm first searches for a <code>ScriptEngineFactory</code> that has been
      * registered as a handler for the specified name using the <code>registerEngineName</code>
      * method.
-     * <br><br> If one is not found, it searches the array of <code>ScriptEngineFactory</code> instances
+     * <br><br> If one is not found, it searches the set of <code>ScriptEngineFactory</code> instances
      * stored by the constructor for one with the specified name.  If a <code>ScriptEngineFactory</code>
      * is found by either method, it is used to create instance of <code>ScriptEngine</code>.
      * @param shortName The short name of the <code>ScriptEngine</code> implementation.
@@ -351,7 +351,7 @@
     }
 
     /**
-     * Returns an array whose elements are instances of all the <code>ScriptEngineFactory</code> classes
+     * Returns a list whose elements are instances of all the <code>ScriptEngineFactory</code> classes
      * found by the discovery mechanism.
      * @return List of all discovered <code>ScriptEngineFactory</code>s.
      */
diff --git a/jdk/src/share/classes/javax/swing/SwingUtilities.java b/jdk/src/share/classes/javax/swing/SwingUtilities.java
index 6566444..ecbe32e 100644
--- a/jdk/src/share/classes/javax/swing/SwingUtilities.java
+++ b/jdk/src/share/classes/javax/swing/SwingUtilities.java
@@ -792,7 +792,8 @@
      * @return true if the left mouse button was active
      */
     public static boolean isLeftMouseButton(MouseEvent anEvent) {
-         return (anEvent.getButton() == MouseEvent.BUTTON1);
+         return ((anEvent.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0 ||
+                 anEvent.getButton() == MouseEvent.BUTTON1);
     }
 
     /**
@@ -802,7 +803,8 @@
      * @return true if the middle mouse button was active
      */
     public static boolean isMiddleMouseButton(MouseEvent anEvent) {
-        return (anEvent.getButton() == MouseEvent.BUTTON2);
+        return ((anEvent.getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK) != 0 ||
+                anEvent.getButton() == MouseEvent.BUTTON2);
     }
 
     /**
@@ -812,7 +814,8 @@
      * @return true if the right mouse button was active
      */
     public static boolean isRightMouseButton(MouseEvent anEvent) {
-        return (anEvent.getButton() == MouseEvent.BUTTON3);
+        return ((anEvent.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0 ||
+                anEvent.getButton() == MouseEvent.BUTTON3);
     }
 
     /**
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 a47375f..3d80e12 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/javax/swing/plaf/synth/SynthComboBoxUI.java b/jdk/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java
index cfe0c4f..37f0c85 100644
--- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java
+++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
diff --git a/jdk/src/share/classes/sun/awt/AWTAccessor.java b/jdk/src/share/classes/sun/awt/AWTAccessor.java
index e8f5ca1..f804779 100644
--- a/jdk/src/share/classes/sun/awt/AWTAccessor.java
+++ b/jdk/src/share/classes/sun/awt/AWTAccessor.java
@@ -28,6 +28,7 @@
 import sun.misc.Unsafe;
 
 import java.awt.*;
+import java.awt.KeyboardFocusManager;
 import java.awt.event.InputEvent;
 import java.awt.geom.Point2D;
 import java.awt.peer.ComponentPeer;
@@ -396,6 +397,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/SunToolkit.java b/jdk/src/share/classes/sun/awt/SunToolkit.java
index 95ff33a..132c1d6 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;
@@ -578,7 +579,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;
 
     /*
@@ -1118,6 +1119,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 5910c4b..61be62f 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 9c72251..ae68003 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 20618e2..eef009a 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 aa3f556..0a822d7 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,
@@ -3349,7 +3357,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);
@@ -3769,6 +3779,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++) {
@@ -3782,6 +3795,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 4e7c87e..1a5ae17 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/OGLRenderQueue.java b/jdk/src/share/classes/sun/java2d/opengl/OGLRenderQueue.java
index e5e2f87..e30795b 100644
--- a/jdk/src/share/classes/sun/java2d/opengl/OGLRenderQueue.java
+++ b/jdk/src/share/classes/sun/java2d/opengl/OGLRenderQueue.java
@@ -28,6 +28,8 @@
 import sun.java2d.pipe.RenderBuffer;
 import sun.java2d.pipe.RenderQueue;
 import static sun.java2d.pipe.BufferedOpCodes.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 /**
  * OGL-specific implementation of RenderQueue.  This class provides a
@@ -41,7 +43,19 @@
     private final QueueFlusher flusher;
 
     private OGLRenderQueue() {
-        flusher = new QueueFlusher();
+        /*
+         * The thread must be a member of a thread group
+         * which will not get GCed before VM exit.
+         */
+        flusher = AccessController.doPrivileged(new PrivilegedAction<QueueFlusher>() {
+            public QueueFlusher run() {
+                ThreadGroup rootThreadGroup = Thread.currentThread().getThreadGroup();
+                while (rootThreadGroup.getParent() != null) {
+                    rootThreadGroup = rootThreadGroup.getParent();
+                }
+                return new QueueFlusher(rootThreadGroup);
+            }
+        });
     }
 
     /**
@@ -149,8 +163,8 @@
         private Runnable task;
         private Error error;
 
-        public QueueFlusher() {
-            super("Java2D Queue Flusher");
+        public QueueFlusher(ThreadGroup threadGroup) {
+            super(threadGroup, "Java2D Queue Flusher");
             setDaemon(true);
             setPriority(Thread.MAX_PRIORITY);
             start();
diff --git a/jdk/src/share/classes/sun/java2d/opengl/OGLSurfaceData.java b/jdk/src/share/classes/sun/java2d/opengl/OGLSurfaceData.java
index 3968f05..a495f92 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/launcher/LauncherHelper.java b/jdk/src/share/classes/sun/launcher/LauncherHelper.java
index 2f3710b..233704c 100644
--- a/jdk/src/share/classes/sun/launcher/LauncherHelper.java
+++ b/jdk/src/share/classes/sun/launcher/LauncherHelper.java
@@ -381,6 +381,10 @@
         PrintStream ostream =  (printToStderr) ? System.err : System.out;
         ostream.println(getLocalizedMessage("java.launcher.X.usage",
                 File.pathSeparator));
+        if (System.getProperty("os.name").startsWith("Mac OS")) {
+            ostream.println(getLocalizedMessage("java.launcher.X.macosx.usage",
+                        File.pathSeparator));
+        }
     }
 
     static String getMainClassFromJar(PrintStream ostream, String jarname) {
diff --git a/jdk/src/share/classes/sun/launcher/resources/launcher.properties b/jdk/src/share/classes/sun/launcher/resources/launcher.properties
index b1677c0..2475bd5 100644
--- a/jdk/src/share/classes/sun/launcher/resources/launcher.properties
+++ b/jdk/src/share/classes/sun/launcher/resources/launcher.properties
@@ -109,6 +109,17 @@
 \                      show all locale related settings and continue\n\n\
 The -X options are non-standard and subject to change without notice.\n
 
+# Translators please note do not translate the options themselves
+java.launcher.X.macosx.usage=\
+\n\
+The following options are Mac OS X specific:\n\
+\    -XstartOnFirstThread\n\
+\                      run the main() method on the first (AppKit) thread\n\
+\    -Xdock:name=<application name>"\n\
+\                      override default application name displayed in dock\n\
+\    -Xdock:icon=<path to icon file>\n\
+\                      override default icon displayed in dock\n\n
+
 java.launcher.cls.error1=\
     Error: Could not find or load main class {0}
 java.launcher.cls.error2=\
diff --git a/jdk/src/share/classes/sun/net/spi/DefaultProxySelector.java b/jdk/src/share/classes/sun/net/spi/DefaultProxySelector.java
index 39eadae..d7aa358 100644
--- a/jdk/src/share/classes/sun/net/spi/DefaultProxySelector.java
+++ b/jdk/src/share/classes/sun/net/spi/DefaultProxySelector.java
@@ -111,7 +111,7 @@
     static class NonProxyInfo {
         // Default value for nonProxyHosts, this provides backward compatibility
         // by excluding localhost and its litteral notations.
-        static final String defStringVal = "localhost|127.*|[::1]";
+        static final String defStringVal = "localhost|127.*|[::1]|0.0.0.0|[::0]";
 
         String hostsSource;
         RegexpPool hostsPool;
@@ -249,6 +249,12 @@
                                             nprop.hostsSource = null;
                                             nprop.hostsPool = null;
                                         }
+                                    } else if (nphosts.length() != 0) {
+                                        // add the required default patterns
+                                        // but only if property no set. If it
+                                        // is empty, leave empty.
+                                        nphosts += "|" + NonProxyInfo
+                                                         .defStringVal;
                                     }
                                     if (nphosts != null) {
                                         if (!nphosts.equals(nprop.hostsSource)) {
diff --git a/jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java b/jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java
index bdc5022..466a5db 100644
--- a/jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java
+++ b/jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java
@@ -509,8 +509,15 @@
         int rem = (pos <= lim ? lim - pos : 0);
 
         boolean preferIPv6 = (family != StandardProtocolFamily.INET);
-        int written = send0(preferIPv6, fd, ((DirectBuffer)bb).address() + pos,
+        int written;
+        try {
+            written = send0(preferIPv6, fd, ((DirectBuffer)bb).address() + pos,
                             rem, target);
+        } catch (PortUnreachableException pue) {
+            if (isConnected())
+                throw pue;
+            written = rem;
+        }
         if (written > 0)
             bb.position(pos + written);
         return written;
diff --git a/jdk/src/share/classes/sun/nio/cs/ext/ExtendedCharsets.java b/jdk/src/share/classes/sun/nio/cs/ext/ExtendedCharsets.java
index 5c71094..ebf55b2 100644
--- a/jdk/src/share/classes/sun/nio/cs/ext/ExtendedCharsets.java
+++ b/jdk/src/share/classes/sun/nio/cs/ext/ExtendedCharsets.java
@@ -1279,7 +1279,8 @@
         }
         String osName = AccessController.doPrivileged(
             new GetPropertyAction("os.name"));
-        if ("SunOS".equals(osName) || "Linux".equals(osName)) {
+        if ("SunOS".equals(osName) || "Linux".equals(osName)
+               || osName.startsWith("Mac OS")) {
             charset("x-COMPOUND_TEXT", "COMPOUND_TEXT",
                     new String[] {
                         "COMPOUND_TEXT",        // JDK historical
diff --git a/jdk/src/share/classes/sun/print/PSPrinterJob.java b/jdk/src/share/classes/sun/print/PSPrinterJob.java
index d4a0ffa..49584f2 100644
--- a/jdk/src/share/classes/sun/print/PSPrinterJob.java
+++ b/jdk/src/share/classes/sun/print/PSPrinterJob.java
@@ -1565,7 +1565,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/rmi/log/ReliableLog.java b/jdk/src/share/classes/sun/rmi/log/ReliableLog.java
index fe512c2..a247514 100644
--- a/jdk/src/share/classes/sun/rmi/log/ReliableLog.java
+++ b/jdk/src/share/classes/sun/rmi/log/ReliableLog.java
@@ -344,10 +344,9 @@
                                return ClassLoader.getSystemClassLoader();
                             }
                         });
-                Class cl = loader.loadClass(logClassName);
-                if (LogFile.class.isAssignableFrom(cl)) {
-                    return cl.getConstructor(String.class, String.class);
-                }
+                Class<? extends LogFile> cl =
+                    loader.loadClass(logClassName).asSubclass(LogFile.class);
+                return cl.getConstructor(String.class, String.class);
             } catch (Exception e) {
                 System.err.println("Exception occurred:");
                 e.printStackTrace();
@@ -595,10 +594,10 @@
         } else {
             name = versionFile;
         }
-        DataOutputStream out =
-            new DataOutputStream(new FileOutputStream(fName(name)));
-        writeInt(out, version);
-        out.close();
+        try (FileOutputStream fos = new FileOutputStream(fName(name));
+             DataOutputStream out = new DataOutputStream(fos)) {
+            writeInt(out, version);
+        }
     }
 
     /**
@@ -629,11 +628,9 @@
      * @exception IOException If an I/O error has occurred.
      */
     private int readVersion(String name) throws IOException {
-        DataInputStream in = new DataInputStream(new FileInputStream(name));
-        try {
+        try (DataInputStream in = new DataInputStream
+                (new FileInputStream(name))) {
             return in.readInt();
-        } finally {
-            in.close();
         }
     }
 
diff --git a/jdk/src/share/classes/sun/rmi/registry/RegistryImpl.java b/jdk/src/share/classes/sun/rmi/registry/RegistryImpl.java
index 1257132..34579c2 100644
--- a/jdk/src/share/classes/sun/rmi/registry/RegistryImpl.java
+++ b/jdk/src/share/classes/sun/rmi/registry/RegistryImpl.java
@@ -77,9 +77,9 @@
     /* indicate compatibility with JDK 1.1.x version of class */
     private static final long serialVersionUID = 4666870661827494597L;
     private Hashtable<String, Remote> bindings
-        = new Hashtable<String, Remote>(101);
+        = new Hashtable<>(101);
     private static Hashtable<InetAddress, InetAddress> allowedAccessCache
-        = new Hashtable<InetAddress, InetAddress>(3);
+        = new Hashtable<>(3);
     private static RegistryImpl registry;
     private static ObjID id = new ObjID(ObjID.REGISTRY_ID);
 
@@ -194,9 +194,9 @@
         synchronized (bindings) {
             int i = bindings.size();
             names = new String[i];
-            Enumeration enum_ = bindings.keys();
+            Enumeration<String> enum_ = bindings.keys();
             while ((--i) >= 0)
-                names[i] = (String)enum_.nextElement();
+                names[i] = enum_.nextElement();
         }
         return names;
     }
diff --git a/jdk/src/share/classes/sun/rmi/server/ActivatableRef.java b/jdk/src/share/classes/sun/rmi/server/ActivatableRef.java
index 9364e0d0..29a3529 100644
--- a/jdk/src/share/classes/sun/rmi/server/ActivatableRef.java
+++ b/jdk/src/share/classes/sun/rmi/server/ActivatableRef.java
@@ -80,7 +80,7 @@
         String className = desc.getClassName();
 
         try {
-            Class cl =
+            Class<?> cl =
                 RMIClassLoader.loadClass(desc.getLocation(), className);
             RemoteRef clientRef = new ActivatableRef(id, null);
             return Util.createProxy(cl, clientRef, false);
@@ -373,8 +373,8 @@
         if (className.equals("")) return;
 
         try {
-            Class refClass = Class.forName(RemoteRef.packagePrefix + "." +
-                                           className);
+            Class<?> refClass = Class.forName(RemoteRef.packagePrefix + "." +
+                                              className);
             ref = (RemoteRef)refClass.newInstance();
             ref.readExternal(in);
         } catch (InstantiationException e) {
diff --git a/jdk/src/share/classes/sun/rmi/server/Activation.java b/jdk/src/share/classes/sun/rmi/server/Activation.java
index 919edb7..c1ec95e 100644
--- a/jdk/src/share/classes/sun/rmi/server/Activation.java
+++ b/jdk/src/share/classes/sun/rmi/server/Activation.java
@@ -138,7 +138,6 @@
 
     /** indicate compatibility with JDK 1.2 version of class */
     private static final long serialVersionUID = 2921265612698155191L;
-
     private static final byte MAJOR_VERSION = 1;
     private static final byte MINOR_VERSION = 0;
 
@@ -298,6 +297,7 @@
     private static class SystemRegistryImpl extends RegistryImpl {
 
         private static final String NAME = ActivationSystem.class.getName();
+        private static final long serialVersionUID = 4877330021609408794L;
         private final ActivationSystem systemStub;
 
         SystemRegistryImpl(int port,
@@ -804,9 +804,8 @@
         ActivationGroupDesc desc = null;
         ActivationGroupID groupID = null;
         long incarnation = 0;
-        Map<ActivationID,ObjectEntry> objects =
-            new HashMap<ActivationID,ObjectEntry>();
-        Set<ActivationID> restartSet = new HashSet<ActivationID>();
+        Map<ActivationID,ObjectEntry> objects = new HashMap<>();
+        Set<ActivationID> restartSet = new HashSet<>();
 
         transient ActivationInstantiator group = null;
         transient int status = NORMAL;
@@ -1057,6 +1056,11 @@
             }
         }
 
+       /*
+        * Fallthrough from TERMINATE to TERMINATING
+        * is intentional
+        */
+        @SuppressWarnings("fallthrough")
         private void await() {
             while (true) {
                 switch (status) {
@@ -1228,14 +1232,13 @@
                     PipeWriter.plugTogetherPair
                         (child.getInputStream(), System.out,
                          child.getErrorStream(), System.err);
-
-                    MarshalOutputStream out =
-                        new MarshalOutputStream(child.getOutputStream());
-                    out.writeObject(id);
-                    out.writeObject(desc);
-                    out.writeLong(incarnation);
-                    out.flush();
-                    out.close();
+                    try (MarshalOutputStream out =
+                            new MarshalOutputStream(child.getOutputStream())) {
+                        out.writeObject(id);
+                        out.writeObject(desc);
+                        out.writeLong(incarnation);
+                        out.flush();
+                    }
 
 
                 } catch (IOException e) {
@@ -1352,7 +1355,7 @@
         cmdenv = desc.getCommandEnvironment();
 
         // argv is the literal command to exec
-        List<String> argv = new ArrayList<String>();
+        List<String> argv = new ArrayList<>();
 
         // Command name/path
         argv.add((cmdenv != null && cmdenv.getCommandPath() != null)
@@ -1957,7 +1960,7 @@
             }
 
             String log = null;
-            List<String> childArgs = new ArrayList<String>();
+            List<String> childArgs = new ArrayList<>();
 
             /*
              * Parse arguments
@@ -2031,8 +2034,7 @@
                 }
 
                 try {
-                    Class<?> execPolicyClass =
-                        RMIClassLoader.loadClass(execPolicyClassName);
+                    Class<?> execPolicyClass = getRMIClass(execPolicyClassName);
                     execPolicy = execPolicyClass.newInstance();
                     execPolicyMethod =
                         execPolicyClass.getMethod("checkExecCommand",
@@ -2123,6 +2125,10 @@
         }
     }
 
+    @SuppressWarnings("deprecation")
+    private static Class<?> getRMIClass(String execPolicyClassName) throws Exception  {
+        return RMIClassLoader.loadClass(execPolicyClassName);
+    }
     /*
      * Dijkstra semaphore operations to limit the number of subprocesses
      * rmid attempts to make at once.
diff --git a/jdk/src/share/classes/sun/rmi/server/ActivationGroupImpl.java b/jdk/src/share/classes/sun/rmi/server/ActivationGroupImpl.java
index 1ee26a5..dd89d51 100644
--- a/jdk/src/share/classes/sun/rmi/server/ActivationGroupImpl.java
+++ b/jdk/src/share/classes/sun/rmi/server/ActivationGroupImpl.java
@@ -66,10 +66,10 @@
 
     /** maps persistent IDs to activated remote objects */
     private final Hashtable<ActivationID,ActiveEntry> active =
-        new Hashtable<ActivationID,ActiveEntry>();
+        new Hashtable<>();
     private boolean groupInactive = false;
     private final ActivationGroupID groupID;
-    private final List<ActivationID> lockedIDs = new ArrayList<ActivationID>();
+    private final List<ActivationID> lockedIDs = new ArrayList<>();
 
     /**
      * Creates a default activation group implementation.
@@ -296,14 +296,9 @@
             active.put(id, entry);
             return entry.mobj;
 
-        } catch (NoSuchMethodException e) {
-            /* user forgot to provide activatable constructor? */
-            throw new ActivationException
-                ("Activatable object must provide an activation"+
-                 " constructor", e);
-
-        } catch (NoSuchMethodError e) {
-            /* code recompiled and user forgot to provide
+        } catch (NoSuchMethodException | NoSuchMethodError e) {
+            /* user forgot to provide activatable constructor?
+             * or code recompiled and user forgot to provide
              *  activatable constructor?
              */
             throw new ActivationException
diff --git a/jdk/src/share/classes/sun/rmi/server/LoaderHandler.java b/jdk/src/share/classes/sun/rmi/server/LoaderHandler.java
index e7db8c8..956e80b 100644
--- a/jdk/src/share/classes/sun/rmi/server/LoaderHandler.java
+++ b/jdk/src/share/classes/sun/rmi/server/LoaderHandler.java
@@ -112,11 +112,11 @@
      * garbage collected.
      */
     private static final HashMap<LoaderKey, LoaderEntry> loaderTable
-        = new HashMap<LoaderKey, LoaderEntry>(5);
+        = new HashMap<>(5);
 
     /** reference queue for cleared class loader entries */
     private static final ReferenceQueue<Loader> refQueue
-        = new ReferenceQueue<Loader>();
+        = new ReferenceQueue<>();
 
     /*
      * Disallow anyone from creating one of these.
@@ -149,8 +149,8 @@
      * but first try to resolve the named class through the given
      * "default loader".
      */
-    public static Class loadClass(String codebase, String name,
-                                  ClassLoader defaultLoader)
+    public static Class<?> loadClass(String codebase, String name,
+                                     ClassLoader defaultLoader)
         throws MalformedURLException, ClassNotFoundException
     {
         if (loaderLog.isLoggable(Log.BRIEF)) {
@@ -170,7 +170,7 @@
 
         if (defaultLoader != null) {
             try {
-                Class c = Class.forName(name, false, defaultLoader);
+                Class<?> c = Class.forName(name, false, defaultLoader);
                 if (loaderLog.isLoggable(Log.VERBOSE)) {
                     loaderLog.log(Log.VERBOSE,
                         "class \"" + name + "\" found via defaultLoader, " +
@@ -189,7 +189,7 @@
      * a class) that RMI will use to annotate the call stream when
      * marshalling objects of the given class.
      */
-    public static String getClassAnnotation(Class cl) {
+    public static String getClassAnnotation(Class<?> cl) {
         String name = cl.getName();
 
         /*
@@ -261,15 +261,13 @@
 
                     annotation = urlsToPath(urls);
                 }
-            } catch (SecurityException e) {
+            } catch (SecurityException | IOException e) {
                 /*
-                 * If access was denied to the knowledge of the class
-                 * loader's URLs, fall back to the default behavior.
-                 */
-            } catch (IOException e) {
-                /*
-                 * This shouldn't happen, although it is declared to be
-                 * thrown by openConnection() and getPermission().  If it
+                 * SecurityException: If access was denied to the knowledge of
+                 * the class loader's URLs, fall back to the default behavior.
+                 *
+                 * IOException: This shouldn't happen, although it is declared
+                 * to be thrown by openConnection() and getPermission().  If it
                  * does happen, forget about this class loader's URLs and
                  * fall back to the default behavior.
                  */
@@ -358,7 +356,7 @@
      * Load a class from the RMI class loader corresponding to the given
      * codebase URL path in the current execution context.
      */
-    private static Class loadClass(URL[] urls, String name)
+    private static Class<?> loadClass(URL[] urls, String name)
         throws ClassNotFoundException
     {
         ClassLoader parent = getRMIContextClassLoader();
@@ -375,7 +373,7 @@
         SecurityManager sm = System.getSecurityManager();
         if (sm == null) {
             try {
-                Class c = Class.forName(name, false, parent);
+                Class<?> c = Class.forName(name, false, parent);
                 if (loaderLog.isLoggable(Log.VERBOSE)) {
                     loaderLog.log(Log.VERBOSE,
                         "class \"" + name + "\" found via " +
@@ -424,7 +422,7 @@
                  * resolved without the security-offending codebase anyway;
                  * if so, return successfully (see bugids 4191926 & 4349670).
                  */
-                Class c = Class.forName(name, false, parent);
+                Class<?> c = Class.forName(name, false, parent);
                 if (loaderLog.isLoggable(Log.VERBOSE)) {
                     loaderLog.log(Log.VERBOSE,
                         "class \"" + name + "\" found via " +
@@ -450,7 +448,7 @@
         }
 
         try {
-            Class c = Class.forName(name, false, loader);
+            Class<?> c = Class.forName(name, false, loader);
             if (loaderLog.isLoggable(Log.VERBOSE)) {
                 loaderLog.log(Log.VERBOSE,
                     "class \"" + name + "\" " + "found via codebase, " +
@@ -472,8 +470,8 @@
      * implement interface classes named by the given array of
      * interface names.
      */
-    public static Class loadProxyClass(String codebase, String[] interfaces,
-                                       ClassLoader defaultLoader)
+    public static Class<?> loadProxyClass(String codebase, String[] interfaces,
+                                          ClassLoader defaultLoader)
         throws MalformedURLException, ClassNotFoundException
     {
         if (loaderLog.isLoggable(Log.BRIEF)) {
@@ -537,7 +535,7 @@
         SecurityManager sm = System.getSecurityManager();
         if (sm == null) {
             try {
-                Class c = loadProxyClass(interfaces, defaultLoader, parent,
+                Class<?> c = loadProxyClass(interfaces, defaultLoader, parent,
                                          false);
                 if (loaderLog.isLoggable(Log.VERBOSE)) {
                     loaderLog.log(Log.VERBOSE,
@@ -584,8 +582,8 @@
                  * resolved without the security-offending codebase anyway;
                  * if so, return successfully (see bugids 4191926 & 4349670).
                  */
-                Class c = loadProxyClass(interfaces, defaultLoader, parent,
-                                         false);
+                Class<?> c = loadProxyClass(interfaces, defaultLoader, parent,
+                                            false);
                 if (loaderLog.isLoggable(Log.VERBOSE)) {
                     loaderLog.log(Log.VERBOSE,
                         "(access to codebase denied) " +
@@ -608,7 +606,7 @@
         }
 
         try {
-            Class c = loadProxyClass(interfaces, defaultLoader, loader, true);
+            Class<?> c = loadProxyClass(interfaces, defaultLoader, loader, true);
             if (loaderLog.isLoggable(Log.VERBOSE)) {
                 loaderLog.log(Log.VERBOSE,
                               "proxy class defined by " + c.getClassLoader());
@@ -629,14 +627,14 @@
      * class will implement classes which are named in the supplied
      * interfaceNames.
      */
-    private static Class loadProxyClass(String[] interfaceNames,
-                                        ClassLoader defaultLoader,
-                                        ClassLoader codebaseLoader,
-                                        boolean preferCodebase)
+    private static Class<?> loadProxyClass(String[] interfaceNames,
+                                           ClassLoader defaultLoader,
+                                           ClassLoader codebaseLoader,
+                                           boolean preferCodebase)
         throws ClassNotFoundException
     {
         ClassLoader proxyLoader = null;
-        Class[] classObjs = new Class[interfaceNames.length];
+        Class<?>[] classObjs = new Class<?>[interfaceNames.length];
         boolean[] nonpublic = { false };
 
       defaultLoaderCase:
@@ -692,7 +690,7 @@
      * Define a proxy class in the given class loader.  The proxy
      * class will implement the given interfaces Classes.
      */
-    private static Class loadProxyClass(ClassLoader loader, Class[] interfaces)
+    private static Class<?> loadProxyClass(ClassLoader loader, Class[] interfaces)
         throws ClassNotFoundException
     {
         try {
@@ -727,7 +725,7 @@
         ClassLoader nonpublicLoader = null;
 
         for (int i = 0; i < interfaces.length; i++) {
-            Class cl =
+            Class<?> cl =
                 (classObjs[i] = Class.forName(interfaces[i], false, loader));
 
             if (!Modifier.isPublic(cl.getModifiers())) {
@@ -778,7 +776,7 @@
 
     /** map from weak(key=string) to [URL[], soft(key)] */
     private static final Map<String, Object[]> pathToURLsCache
-        = new WeakHashMap<String, Object[]>(5);
+        = new WeakHashMap<>(5);
 
     /**
      * Convert an array of URL objects into a corresponding string
@@ -1171,9 +1169,9 @@
         private void checkPermissions() {
             SecurityManager sm = System.getSecurityManager();
             if (sm != null) {           // should never be null?
-                Enumeration enum_ = permissions.elements();
+                Enumeration<Permission> enum_ = permissions.elements();
                 while (enum_.hasMoreElements()) {
-                    sm.checkPermission((Permission) enum_.nextElement());
+                    sm.checkPermission(enum_.nextElement());
                 }
             }
         }
diff --git a/jdk/src/share/classes/sun/rmi/server/MarshalInputStream.java b/jdk/src/share/classes/sun/rmi/server/MarshalInputStream.java
index cb32017..daa0f72 100644
--- a/jdk/src/share/classes/sun/rmi/server/MarshalInputStream.java
+++ b/jdk/src/share/classes/sun/rmi/server/MarshalInputStream.java
@@ -65,14 +65,14 @@
 
     /** table to hold sun classes to which access is explicitly permitted */
     protected static Map<String, Class<?>> permittedSunClasses
-        = new HashMap<String, Class<?>>(3);
+        = new HashMap<>(3);
 
     /** if true, don't try superclass first in resolveClass() */
     private boolean skipDefaultResolveClass = false;
 
     /** callbacks to make when done() called: maps Object to Runnable */
     private final Map<Object, Runnable> doneCallbacks
-        = new HashMap<Object, Runnable>(3);
+        = new HashMap<>(3);
 
     /**
      * if true, load classes (if not available locally) only from the
@@ -168,7 +168,7 @@
      * from which to load the specified class.
      * It will find, load, and return the class.
      */
-    protected Class resolveClass(ObjectStreamClass classDesc)
+    protected Class<?> resolveClass(ObjectStreamClass classDesc)
         throws IOException, ClassNotFoundException
     {
         /*
@@ -230,7 +230,7 @@
      * resolveProxyClass is extended to acquire (if present) the location
      * to determine the class loader to define the proxy class in.
      */
-    protected Class resolveProxyClass(String[] interfaces)
+    protected Class<?> resolveProxyClass(String[] interfaces)
         throws IOException, ClassNotFoundException
     {
         /*
@@ -262,7 +262,7 @@
      * Fix for 4179055: Need to assist resolving sun stubs; resolve
      * class locally if it is a "permitted" sun class
      */
-    private Class checkSunClass(String className, AccessControlException e)
+    private Class<?> checkSunClass(String className, AccessControlException e)
         throws AccessControlException
     {
         // ensure that we are giving out a stub for the correct reason
diff --git a/jdk/src/share/classes/sun/rmi/server/UnicastRef.java b/jdk/src/share/classes/sun/rmi/server/UnicastRef.java
index b928cfb..c2f1df1 100644
--- a/jdk/src/share/classes/sun/rmi/server/UnicastRef.java
+++ b/jdk/src/share/classes/sun/rmi/server/UnicastRef.java
@@ -65,6 +65,7 @@
         Log.getLog("sun.rmi.client.call", "RMI",
                    AccessController.doPrivileged(
                        new GetBooleanAction("sun.rmi.client.logCalls")));
+    private static final long serialVersionUID = 8258372400816541186L;
 
     protected LiveRef ref;
 
diff --git a/jdk/src/share/classes/sun/rmi/server/UnicastRef2.java b/jdk/src/share/classes/sun/rmi/server/UnicastRef2.java
index c2abc1f..2facc1e 100644
--- a/jdk/src/share/classes/sun/rmi/server/UnicastRef2.java
+++ b/jdk/src/share/classes/sun/rmi/server/UnicastRef2.java
@@ -36,6 +36,7 @@
  * implementation of javax.management.remote.rmi.RMIConnector.
  **/
 public class UnicastRef2 extends UnicastRef {
+    private static final long serialVersionUID = 1829537514995881838L;
 
     /**
      * Create a new (empty) Unicast remote reference.
diff --git a/jdk/src/share/classes/sun/rmi/server/UnicastServerRef.java b/jdk/src/share/classes/sun/rmi/server/UnicastServerRef.java
index fe199a2..5213742 100644
--- a/jdk/src/share/classes/sun/rmi/server/UnicastServerRef.java
+++ b/jdk/src/share/classes/sun/rmi/server/UnicastServerRef.java
@@ -189,7 +189,7 @@
                                boolean permanent)
         throws RemoteException
     {
-        Class implClass = impl.getClass();
+        Class<?> implClass = impl.getClass();
         Remote stub;
 
         try {
@@ -327,7 +327,7 @@
             // marshal return value
             try {
                 ObjectOutput out = call.getResultStream(true);
-                Class rtype = method.getReturnType();
+                Class<?> rtype = method.getReturnType();
                 if (rtype != void.class) {
                     marshalValue(rtype, result, out);
                 }
@@ -537,7 +537,7 @@
         HashToMethod_Maps() {}
 
         protected Map<Long,Method> computeValue(Class<?> remoteClass) {
-            Map<Long,Method> map = new HashMap<Long,Method>();
+            Map<Long,Method> map = new HashMap<>();
             for (Class<?> cl = remoteClass;
                  cl != null;
                  cl = cl.getSuperclass())
diff --git a/jdk/src/share/classes/sun/rmi/server/Util.java b/jdk/src/share/classes/sun/rmi/server/Util.java
index c3b6b4a..2cf01ff 100644
--- a/jdk/src/share/classes/sun/rmi/server/Util.java
+++ b/jdk/src/share/classes/sun/rmi/server/Util.java
@@ -119,12 +119,12 @@
      * @throws StubNotFoundException if problem locating/creating stub or
      * creating the dynamic proxy instance
      **/
-    public static Remote createProxy(Class implClass,
+    public static Remote createProxy(Class<?> implClass,
                                      RemoteRef clientRef,
                                      boolean forceStubUse)
         throws StubNotFoundException
     {
-        Class remoteClass;
+        Class<?> remoteClass;
 
         try {
             remoteClass = getRemoteClass(implClass);
@@ -162,7 +162,7 @@
      *
      * @param remoteClass the class to obtain remote interfaces from
      */
-    private static boolean stubClassExists(Class remoteClass) {
+    private static boolean stubClassExists(Class<?> remoteClass) {
         if (!withoutStubs.containsKey(remoteClass)) {
             try {
                 Class.forName(remoteClass.getName() + "_Stub",
@@ -182,11 +182,11 @@
      * @throws ClassNotFoundException if no class is found to have a
      * remote interface
      */
-    private static Class getRemoteClass(Class cl)
+    private static Class<?> getRemoteClass(Class<?> cl)
         throws ClassNotFoundException
     {
         while (cl != null) {
-            Class[] interfaces = cl.getInterfaces();
+            Class<?>[] interfaces = cl.getInterfaces();
             for (int i = interfaces.length -1; i >= 0; i--) {
                 if (Remote.class.isAssignableFrom(interfaces[i]))
                     return cl;          // this class implements remote object
@@ -206,8 +206,8 @@
      *          any illegal remote interfaces
      * @throws  NullPointerException if remoteClass is null
      */
-    private static Class[] getRemoteInterfaces(Class remoteClass) {
-        ArrayList<Class<?>> list = new ArrayList<Class<?>>();
+    private static Class<?>[] getRemoteInterfaces(Class<?> remoteClass) {
+        ArrayList<Class<?>> list = new ArrayList<>();
         getRemoteInterfaces(list, remoteClass);
         return list.toArray(new Class<?>[list.size()]);
     }
@@ -220,15 +220,15 @@
      *          any illegal remote interfaces
      * @throws  NullPointerException if the specified class or list is null
      */
-    private static void getRemoteInterfaces(ArrayList<Class<?>> list, Class cl) {
-        Class superclass = cl.getSuperclass();
+    private static void getRemoteInterfaces(ArrayList<Class<?>> list, Class<?> cl) {
+        Class<?> superclass = cl.getSuperclass();
         if (superclass != null) {
             getRemoteInterfaces(list, superclass);
         }
 
-        Class[] interfaces = cl.getInterfaces();
+        Class<?>[] interfaces = cl.getInterfaces();
         for (int i = 0; i < interfaces.length; i++) {
-            Class intf = interfaces[i];
+            Class<?> intf = interfaces[i];
             /*
              * If it is a remote interface (if it extends from
              * java.rmi.Remote) and is not already in the list,
@@ -272,7 +272,7 @@
      * the stub class is initiated from class loader of the specified class
      * (which may be the bootstrap class loader).
      **/
-    private static RemoteStub createStub(Class remoteClass, RemoteRef ref)
+    private static RemoteStub createStub(Class<?> remoteClass, RemoteRef ref)
         throws StubNotFoundException
     {
         String stubname = remoteClass.getName() + "_Stub";
@@ -285,7 +285,7 @@
         try {
             Class<?> stubcl =
                 Class.forName(stubname, false, remoteClass.getClassLoader());
-            Constructor cons = stubcl.getConstructor(stubConsParamTypes);
+            Constructor<?> cons = stubcl.getConstructor(stubConsParamTypes);
             return (RemoteStub) cons.newInstance(new Object[] { ref });
 
         } catch (ClassNotFoundException e) {
@@ -315,7 +315,7 @@
     static Skeleton createSkeleton(Remote object)
         throws SkeletonNotFoundException
     {
-        Class cl;
+        Class<?> cl;
         try {
             cl = getRemoteClass(object.getClass());
         } catch (ClassNotFoundException ex ) {
@@ -327,7 +327,7 @@
         // now try to load the skeleton based ont he name of the class
         String skelname = cl.getName() + "_Skel";
         try {
-            Class skelcl = Class.forName(skelname, false, cl.getClassLoader());
+            Class<?> skelcl = Class.forName(skelname, false, cl.getClassLoader());
 
             return (Skeleton)skelcl.newInstance();
         } catch (ClassNotFoundException ex) {
@@ -391,12 +391,12 @@
     private static String getMethodNameAndDescriptor(Method m) {
         StringBuffer desc = new StringBuffer(m.getName());
         desc.append('(');
-        Class[] paramTypes = m.getParameterTypes();
+        Class<?>[] paramTypes = m.getParameterTypes();
         for (int i = 0; i < paramTypes.length; i++) {
             desc.append(getTypeDescriptor(paramTypes[i]));
         }
         desc.append(')');
-        Class returnType = m.getReturnType();
+        Class<?> returnType = m.getReturnType();
         if (returnType == void.class) { // optimization: handle void here
             desc.append('V');
         } else {
@@ -409,7 +409,7 @@
      * Get the descriptor of a particular type, as appropriate for either
      * a parameter or return type in a method descriptor.
      */
-    private static String getTypeDescriptor(Class type) {
+    private static String getTypeDescriptor(Class<?> type) {
         if (type.isPrimitive()) {
             if (type == int.class) {
                 return "I";
@@ -454,7 +454,7 @@
      * top-level type (and perhaps other enclosing types), the
      * separator will be '$', etc.
      **/
-    public static String getUnqualifiedName(Class c) {
+    public static String getUnqualifiedName(Class<?> c) {
         String binaryName = c.getName();
         return binaryName.substring(binaryName.lastIndexOf('.') + 1);
     }
diff --git a/jdk/src/share/classes/sun/rmi/server/WeakClassHashMap.java b/jdk/src/share/classes/sun/rmi/server/WeakClassHashMap.java
index 1aff576..734e4ff 100644
--- a/jdk/src/share/classes/sun/rmi/server/WeakClassHashMap.java
+++ b/jdk/src/share/classes/sun/rmi/server/WeakClassHashMap.java
@@ -46,8 +46,7 @@
  **/
 public abstract class WeakClassHashMap<V> {
 
-    private Map<Class<?>,ValueCell<V>> internalMap =
-        new WeakHashMap<Class<?>,ValueCell<V>>();
+    private Map<Class<?>,ValueCell<V>> internalMap = new WeakHashMap<>();
 
     protected WeakClassHashMap() { }
 
diff --git a/jdk/src/share/classes/sun/rmi/transport/ConnectionInputStream.java b/jdk/src/share/classes/sun/rmi/transport/ConnectionInputStream.java
index f79482b..2c2a81f 100644
--- a/jdk/src/share/classes/sun/rmi/transport/ConnectionInputStream.java
+++ b/jdk/src/share/classes/sun/rmi/transport/ConnectionInputStream.java
@@ -43,7 +43,7 @@
     private boolean dgcAckNeeded = false;
 
     /** Hashtable mapping Endpoints to lists of LiveRefs to register */
-    private Map incomingRefTable = new HashMap(5);
+    private Map<Endpoint, List<LiveRef>> incomingRefTable = new HashMap<>(5);
 
     /** identifier for gc ack*/
     private UID ackID;
@@ -70,10 +70,10 @@
         Endpoint ep = ref.getEndpoint();
 
         // check whether endpoint is already in the hashtable
-        List refList = (List) incomingRefTable.get(ep);
+        List<LiveRef> refList = incomingRefTable.get(ep);
 
         if (refList == null) {
-            refList = new ArrayList();
+            refList = new ArrayList<LiveRef>();
             incomingRefTable.put(ep, refList);
         }
 
@@ -89,13 +89,9 @@
      */
     void registerRefs() throws IOException {
         if (!incomingRefTable.isEmpty()) {
-            Set entrySet = incomingRefTable.entrySet();
-            Iterator iter = entrySet.iterator();
-            while (iter.hasNext()) {
-                Map.Entry entry = (Map.Entry) iter.next();
-                Endpoint ep = (Endpoint) entry.getKey();
-                List refList = (List) entry.getValue();
-                DGCClient.registerRefs(ep, refList);
+            for (Map.Entry<Endpoint, List<LiveRef>> entry :
+                     incomingRefTable.entrySet()) {
+                DGCClient.registerRefs(entry.getKey(), entry.getValue());
             }
         }
     }
diff --git a/jdk/src/share/classes/sun/rmi/transport/DGCAckHandler.java b/jdk/src/share/classes/sun/rmi/transport/DGCAckHandler.java
index 2735457..7c757dd 100644
--- a/jdk/src/share/classes/sun/rmi/transport/DGCAckHandler.java
+++ b/jdk/src/share/classes/sun/rmi/transport/DGCAckHandler.java
@@ -78,7 +78,7 @@
         Collections.synchronizedMap(new HashMap<UID,DGCAckHandler>());
 
     private final UID id;
-    private List<Object> objList = new ArrayList<Object>(); // null if released
+    private List<Object> objList = new ArrayList<>(); // null if released
     private Future<?> task = null;
 
     /**
diff --git a/jdk/src/share/classes/sun/rmi/transport/DGCClient.java b/jdk/src/share/classes/sun/rmi/transport/DGCClient.java
index 039935c..c6e3266 100644
--- a/jdk/src/share/classes/sun/rmi/transport/DGCClient.java
+++ b/jdk/src/share/classes/sun/rmi/transport/DGCClient.java
@@ -125,7 +125,7 @@
      * All of the LiveRefs in the list must be for remote objects at the
      * given endpoint.
      */
-    static void registerRefs(Endpoint ep, List refs) {
+    static void registerRefs(Endpoint ep, List<LiveRef> refs) {
         /*
          * Look up the given endpoint and register the refs with it.
          * The retrieved entry may get removed from the global endpoint
@@ -176,9 +176,9 @@
         private DGC dgc;
 
         /** table of refs held for endpoint: maps LiveRef to RefEntry */
-        private Map refTable = new HashMap(5);
+        private Map<LiveRef, RefEntry> refTable = new HashMap<>(5);
         /** set of RefEntry instances from last (failed) dirty call */
-        private Set invalidRefs = new HashSet(5);
+        private Set<RefEntry> invalidRefs = new HashSet<>(5);
 
         /** true if this entry has been removed from the global table */
         private boolean removed = false;
@@ -200,12 +200,12 @@
         private boolean interruptible = false;
 
         /** reference queue for phantom references */
-        private ReferenceQueue refQueue = new ReferenceQueue();
+        private ReferenceQueue<LiveRef> refQueue = new ReferenceQueue<>();
         /** set of clean calls that need to be made */
-        private Set pendingCleans = new HashSet(5);
+        private Set<CleanRequest> pendingCleans = new HashSet<>(5);
 
         /** global endpoint table: maps Endpoint to EndpointEntry */
-        private static Map endpointTable = new HashMap(5);
+        private static Map<Endpoint,EndpointEntry> endpointTable = new HashMap<>(5);
         /** handle for GC latency request (for future cancellation) */
         private static GC.LatencyRequest gcLatencyRequest = null;
 
@@ -215,7 +215,7 @@
          */
         public static EndpointEntry lookup(Endpoint ep) {
             synchronized (endpointTable) {
-                EndpointEntry entry = (EndpointEntry) endpointTable.get(ep);
+                EndpointEntry entry = endpointTable.get(ep);
                 if (entry == null) {
                     entry = new EndpointEntry(ep);
                     endpointTable.put(ep, entry);
@@ -260,10 +260,10 @@
          *
          * This method must NOT be called while synchronized on this entry.
          */
-        public boolean registerRefs(List refs) {
+        public boolean registerRefs(List<LiveRef> refs) {
             assert !Thread.holdsLock(this);
 
-            Set refsToDirty = null;     // entries for refs needing dirty
+            Set<RefEntry> refsToDirty = null;     // entries for refs needing dirty
             long sequenceNum;           // sequence number for dirty call
 
             synchronized (this) {
@@ -271,18 +271,18 @@
                     return false;
                 }
 
-                Iterator iter = refs.iterator();
+                Iterator<LiveRef> iter = refs.iterator();
                 while (iter.hasNext()) {
-                    LiveRef ref = (LiveRef) iter.next();
+                    LiveRef ref = iter.next();
                     assert ref.getEndpoint().equals(endpoint);
 
-                    RefEntry refEntry = (RefEntry) refTable.get(ref);
+                    RefEntry refEntry = refTable.get(ref);
                     if (refEntry == null) {
                         LiveRef refClone = (LiveRef) ref.clone();
                         refEntry = new RefEntry(refClone);
                         refTable.put(refClone, refEntry);
                         if (refsToDirty == null) {
-                            refsToDirty = new HashSet(5);
+                            refsToDirty = new HashSet<>(5);
                         }
                         refsToDirty.add(refEntry);
                     }
@@ -345,7 +345,7 @@
          *
          * This method must NOT be called while synchronized on this entry.
          */
-        private void makeDirtyCall(Set refEntries, long sequenceNum) {
+        private void makeDirtyCall(Set<RefEntry> refEntries, long sequenceNum) {
             assert !Thread.holdsLock(this);
 
             ObjID[] ids;
@@ -443,9 +443,9 @@
                          * refs, so that clean calls for them in the future
                          * will be strong.
                          */
-                        Iterator iter = refEntries.iterator();
+                        Iterator<RefEntry> iter = refEntries.iterator();
                         while (iter.hasNext()) {
-                            RefEntry refEntry = (RefEntry) iter.next();
+                            RefEntry refEntry = iter.next();
                             refEntry.markDirtyFailed();
                         }
                     }
@@ -497,7 +497,7 @@
                     long timeToWait;
                     RefEntry.PhantomLiveRef phantom = null;
                     boolean needRenewal = false;
-                    Set refsToDirty = null;
+                    Set<RefEntry> refsToDirty = null;
                     long sequenceNum = Long.MIN_VALUE;
 
                     synchronized (EndpointEntry.this) {
@@ -564,7 +564,7 @@
                             needRenewal = true;
                             if (!invalidRefs.isEmpty()) {
                                 refsToDirty = invalidRefs;
-                                invalidRefs = new HashSet(5);
+                                invalidRefs = new HashSet<>(5);
                             }
                             sequenceNum = getNextSequenceNum();
                         }
@@ -594,8 +594,8 @@
         private void processPhantomRefs(RefEntry.PhantomLiveRef phantom) {
             assert Thread.holdsLock(this);
 
-            Set strongCleans = null;
-            Set normalCleans = null;
+            Set<RefEntry> strongCleans = null;
+            Set<RefEntry> normalCleans = null;
 
             do {
                 RefEntry refEntry = phantom.getRefEntry();
@@ -603,12 +603,12 @@
                 if (refEntry.isRefSetEmpty()) {
                     if (refEntry.hasDirtyFailed()) {
                         if (strongCleans == null) {
-                            strongCleans = new HashSet(5);
+                            strongCleans = new HashSet<>(5);
                         }
                         strongCleans.add(refEntry);
                     } else {
                         if (normalCleans == null) {
-                            normalCleans = new HashSet(5);
+                            normalCleans = new HashSet<>(5);
                         }
                         normalCleans.add(refEntry);
                     }
@@ -659,9 +659,9 @@
         private void makeCleanCalls() {
             assert !Thread.holdsLock(this);
 
-            Iterator iter = pendingCleans.iterator();
+            Iterator<CleanRequest> iter = pendingCleans.iterator();
             while (iter.hasNext()) {
-                CleanRequest request = (CleanRequest) iter.next();
+                CleanRequest request = iter.next();
                 try {
                     dgc.clean(request.objIDs, request.sequenceNum, vmid,
                               request.strong);
@@ -683,11 +683,11 @@
          * Create an array of ObjIDs (needed for the DGC remote calls)
          * from the ids in the given set of refs.
          */
-        private static ObjID[] createObjIDArray(Set refEntries) {
+        private static ObjID[] createObjIDArray(Set<RefEntry> refEntries) {
             ObjID[] ids = new ObjID[refEntries.size()];
-            Iterator iter = refEntries.iterator();
+            Iterator<RefEntry> iter = refEntries.iterator();
             for (int i = 0; i < ids.length; i++) {
-                ids[i] = ((RefEntry) iter.next()).getRef().getObjID();
+                ids[i] = iter.next().getRef().getObjID();
             }
             return ids;
         }
@@ -704,7 +704,7 @@
             /** LiveRef value for this entry (not a registered instance) */
             private LiveRef ref;
             /** set of phantom references to registered instances */
-            private Set refSet = new HashSet(5);
+            private Set<PhantomLiveRef> refSet = new HashSet<>(5);
             /** true if a dirty call containing this ref has failed */
             private boolean dirtyFailed = false;
 
@@ -792,7 +792,7 @@
              * used to detect when the LiveRef becomes permanently
              * unreachable in this VM.
              */
-            private class PhantomLiveRef extends PhantomReference {
+            private class PhantomLiveRef extends PhantomReference<LiveRef> {
 
                 public PhantomLiveRef(LiveRef ref) {
                     super(ref, EndpointEntry.this.refQueue);
diff --git a/jdk/src/share/classes/sun/rmi/transport/DGCImpl.java b/jdk/src/share/classes/sun/rmi/transport/DGCImpl.java
index caaa381..5e59cb1 100644
--- a/jdk/src/share/classes/sun/rmi/transport/DGCImpl.java
+++ b/jdk/src/share/classes/sun/rmi/transport/DGCImpl.java
@@ -84,7 +84,7 @@
     /** remote implementation of DGC interface for this VM */
     private static DGCImpl dgc;
     /** table that maps VMID to LeaseInfo */
-    private Map<VMID,LeaseInfo> leaseTable = new HashMap<VMID,LeaseInfo>();
+    private Map<VMID,LeaseInfo> leaseTable = new HashMap<>();
     /** checks for lease expiration */
     private Future<?> checker = null;
 
@@ -236,7 +236,7 @@
         long time = System.currentTimeMillis();
 
         /* List of vmids that need to be removed from the leaseTable */
-        List<LeaseInfo> toUnregister = new ArrayList<LeaseInfo>();
+        List<LeaseInfo> toUnregister = new ArrayList<>();
 
         /* Build a list of leaseInfo objects that need to have
          * targets removed from their notifySet.  Remove expired
@@ -313,7 +313,7 @@
     private static class LeaseInfo {
         VMID vmid;
         long expiration;
-        Set<Target> notifySet = new HashSet<Target>();
+        Set<Target> notifySet = new HashSet<>();
 
         LeaseInfo(VMID vmid, long lease) {
             this.vmid = vmid;
diff --git a/jdk/src/share/classes/sun/rmi/transport/ObjectTable.java b/jdk/src/share/classes/sun/rmi/transport/ObjectTable.java
index 8c3e5cf..97956cc 100644
--- a/jdk/src/share/classes/sun/rmi/transport/ObjectTable.java
+++ b/jdk/src/share/classes/sun/rmi/transport/ObjectTable.java
@@ -62,9 +62,9 @@
 
     /** tables mapping to Target, keyed from ObjectEndpoint and impl object */
     private static final Map<ObjectEndpoint,Target> objTable =
-        new HashMap<ObjectEndpoint,Target>();
+        new HashMap<>();
     private static final Map<WeakRef,Target> implTable =
-        new HashMap<WeakRef,Target>();
+        new HashMap<>();
 
     /**
      * lock guarding keepAliveCount, reaper, and gcLatencyRequest.
@@ -79,7 +79,7 @@
     private static Thread reaper = null;
 
     /** queue notified when weak refs in the table are cleared */
-    static final ReferenceQueue reapQueue = new ReferenceQueue();
+    static final ReferenceQueue<Object> reapQueue = new ReferenceQueue<>();
 
     /** handle for GC latency request (for future cancellation) */
     private static GC.LatencyRequest gcLatencyRequest = null;
diff --git a/jdk/src/share/classes/sun/rmi/transport/StreamRemoteCall.java b/jdk/src/share/classes/sun/rmi/transport/StreamRemoteCall.java
index f0c3c29..d6d6ee8 100644
--- a/jdk/src/share/classes/sun/rmi/transport/StreamRemoteCall.java
+++ b/jdk/src/share/classes/sun/rmi/transport/StreamRemoteCall.java
@@ -199,6 +199,7 @@
     /**
      * Do whatever it takes to execute the call.
      */
+    @SuppressWarnings("fallthrough")
     public void executeCall() throws Exception {
         byte returnType;
 
@@ -252,6 +253,7 @@
             } else {
                 throw new UnmarshalException("Return type not Exception");
             }
+            // Exception is thrown before fallthrough can occur
         default:
             if (Transport.transportLog.isLoggable(Log.BRIEF)) {
                 Transport.transportLog.log(Log.BRIEF,
diff --git a/jdk/src/share/classes/sun/rmi/transport/Target.java b/jdk/src/share/classes/sun/rmi/transport/Target.java
index f784064..bd1aded 100644
--- a/jdk/src/share/classes/sun/rmi/transport/Target.java
+++ b/jdk/src/share/classes/sun/rmi/transport/Target.java
@@ -53,9 +53,10 @@
     /** stub for remote object */
     private final Remote stub;
     /** set of clients that hold references to this target */
-    private final Vector refSet = new Vector();
+    private final Vector<VMID> refSet = new Vector<>();
     /** table that maps client endpoints to sequence numbers */
-    private final Hashtable sequenceTable = new Hashtable(5);
+    private final Hashtable<VMID, SequenceEntry> sequenceTable =
+        new Hashtable<>(5);
     /** access control context in which target was created */
     private final AccessControlContext acc;
     /** context class loader in which target was created */
@@ -241,7 +242,7 @@
      */
     synchronized void referenced(long sequenceNum, VMID vmid) {
         // check sequence number for vmid
-        SequenceEntry entry = (SequenceEntry) sequenceTable.get(vmid);
+        SequenceEntry entry = sequenceTable.get(vmid);
         if (entry == null) {
             sequenceTable.put(vmid, new SequenceEntry(sequenceNum));
         } else if (entry.sequenceNum < sequenceNum) {
@@ -280,7 +281,7 @@
     synchronized void unreferenced(long sequenceNum, VMID vmid, boolean strong)
     {
         // check sequence number for vmid
-        SequenceEntry entry = (SequenceEntry) sequenceTable.get(vmid);
+        SequenceEntry entry = sequenceTable.get(vmid);
         if (entry == null || entry.sequenceNum > sequenceNum) {
             // late clean call; ignore
             return;
@@ -366,9 +367,9 @@
              */
             unpinImpl();
             DGCImpl dgc = DGCImpl.getDGCImpl();
-            Enumeration enum_ = refSet.elements();
+            Enumeration<VMID> enum_ = refSet.elements();
             while (enum_.hasMoreElements()) {
-                VMID vmid = (VMID) enum_.nextElement();
+                VMID vmid = enum_.nextElement();
                 dgc.unregisterTarget(vmid, this);
             }
             return true;
diff --git a/jdk/src/share/classes/sun/rmi/transport/Transport.java b/jdk/src/share/classes/sun/rmi/transport/Transport.java
index 82a3fe7..bfafe98 100644
--- a/jdk/src/share/classes/sun/rmi/transport/Transport.java
+++ b/jdk/src/share/classes/sun/rmi/transport/Transport.java
@@ -62,7 +62,7 @@
         Log.getLog("sun.rmi.transport.misc", "transport", Transport.logLevel);
 
     /** References the current transport when a call is being serviced */
-    private static final ThreadLocal currentTransport = new ThreadLocal();
+    private static final ThreadLocal<Transport> currentTransport = new ThreadLocal<>();
 
     /** ObjID for DGCImpl */
     private static final ObjID dgcID = new ObjID(ObjID.DGC_ID);
@@ -104,7 +104,7 @@
      * returns null.
      **/
     static Transport currentTransport() {
-        return (Transport) currentTransport.get();
+        return currentTransport.get();
     }
 
     /**
diff --git a/jdk/src/share/classes/sun/rmi/transport/WeakRef.java b/jdk/src/share/classes/sun/rmi/transport/WeakRef.java
index 98bd0db..c20a8a1 100644
--- a/jdk/src/share/classes/sun/rmi/transport/WeakRef.java
+++ b/jdk/src/share/classes/sun/rmi/transport/WeakRef.java
@@ -41,7 +41,7 @@
  * @author  Ann Wollrath
  * @author  Peter Jones
  */
-class WeakRef extends WeakReference {
+class WeakRef extends WeakReference<Object> {
 
     /** value of the referent's "identity" hash code */
     private int hashValue;
@@ -60,7 +60,7 @@
     /**
      * Create a new WeakRef to the given object, registered with a queue.
      */
-    public WeakRef(Object obj, ReferenceQueue q) {
+    public WeakRef(Object obj, ReferenceQueue<Object> q) {
         super(obj, q);
         setHashValue(obj);      // cache object's "identity" hash code
     }
diff --git a/jdk/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java b/jdk/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java
index 25a84fa..918986d 100644
--- a/jdk/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java
+++ b/jdk/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java
@@ -33,6 +33,7 @@
  * in a client's request.
  */
 class CGIClientException extends Exception {
+    private static final long serialVersionUID = 8147981687059865216L;
 
     public CGIClientException(String s) {
         super(s);
@@ -44,6 +45,8 @@
  */
 class CGIServerException extends Exception {
 
+    private static final long serialVersionUID = 6928425456704527017L;
+
     public CGIServerException(String s) {
         super(s);
     }
@@ -111,9 +114,9 @@
     };
 
     /* construct table mapping command strings to handlers */
-    private static Hashtable commandLookup;
+    private static Hashtable<String, CGICommandHandler> commandLookup;
     static {
-        commandLookup = new Hashtable();
+        commandLookup = new Hashtable<>();
         for (int i = 0; i < commands.length; ++ i)
             commandLookup.put(commands[i].getName(), commands[i]);
     }
@@ -140,7 +143,7 @@
                 param = QueryString.substring(delim + 1);
             }
             CGICommandHandler handler =
-                (CGICommandHandler) commandLookup.get(command);
+                commandLookup.get(command);
             if (handler != null)
                 try {
                     handler.execute(param);
@@ -200,7 +203,7 @@
 
 /**
  * "forward" command: Forward request body to local port on the server,
- * and send reponse back to client.
+ * and send response back to client.
  */
 final class CGIForwardCommand implements CGICommandHandler {
 
@@ -208,6 +211,11 @@
         return "forward";
     }
 
+    @SuppressWarnings("deprecation")
+    private String getLine (DataInputStream socketIn) throws IOException {
+        return socketIn.readLine();
+    }
+
     public void execute(String param) throws CGIClientException, CGIServerException
     {
         if (!CGIHandler.RequestMethod.equals("POST"))
@@ -276,7 +284,7 @@
         int responseContentLength = -1;
         do {
             try {
-                line = socketIn.readLine();
+                line = getLine(socketIn);
             } catch (IOException e) {
                 throw new CGIServerException("error reading from server");
             }
@@ -285,8 +293,8 @@
                     "unexpected EOF reading server response");
 
             if (line.toLowerCase().startsWith(key)) {
-                if (contentLengthFound)
-                    ; // what would we want to do in this case??
+                // if contentLengthFound is true
+                // we should probably do something here
                 responseContentLength =
                     Integer.parseInt(line.substring(key.length()).trim());
                 contentLengthFound = true;
diff --git a/jdk/src/share/classes/sun/rmi/transport/proxy/HttpInputStream.java b/jdk/src/share/classes/sun/rmi/transport/proxy/HttpInputStream.java
index dc320c8..773493e 100644
--- a/jdk/src/share/classes/sun/rmi/transport/proxy/HttpInputStream.java
+++ b/jdk/src/share/classes/sun/rmi/transport/proxy/HttpInputStream.java
@@ -70,8 +70,8 @@
                 throw new EOFException();
 
             if (line.toLowerCase().startsWith(key)) {
-                if (contentLengthFound)
-                    ; // what would we want to do in this case??
+                // if contentLengthFound is true
+                // we should probably do something here
                 bytesLeft =
                     Integer.parseInt(line.substring(key.length()).trim());
                 contentLengthFound = true;
diff --git a/jdk/src/share/classes/sun/rmi/transport/proxy/HttpSendSocket.java b/jdk/src/share/classes/sun/rmi/transport/proxy/HttpSendSocket.java
index b599e1b..0d790d5 100644
--- a/jdk/src/share/classes/sun/rmi/transport/proxy/HttpSendSocket.java
+++ b/jdk/src/share/classes/sun/rmi/transport/proxy/HttpSendSocket.java
@@ -203,7 +203,7 @@
 
                 message += "HttpSendSocket.readNotify: response body: ";
                 try {
-                    DataInputStream din = new DataInputStream(in);
+                    BufferedReader din = new BufferedReader(new InputStreamReader(in));
                     String line;
                     while ((line = din.readLine()) != null)
                         message += line + lineSeparator;
diff --git a/jdk/src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java b/jdk/src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java
index 2a2bf2a..2caf6ac 100644
--- a/jdk/src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java
+++ b/jdk/src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java
@@ -74,20 +74,21 @@
             "sun.rmi.transport.proxy.eagerHttpFallback")).booleanValue();
 
     /** table of hosts successfully connected to and the factory used */
-    private Hashtable successTable = new Hashtable();
+    private Hashtable<String, RMISocketFactory> successTable =
+        new Hashtable<>();
 
     /** maximum number of hosts to remember successful connection to */
     private static final int MaxRememberedHosts = 64;
 
     /** list of the hosts in successTable in initial connection order */
-    private Vector hostList = new Vector(MaxRememberedHosts);
+    private Vector<String> hostList = new Vector<>(MaxRememberedHosts);
 
-    /** default factory to initally use for direct socket connection */
+    /** default factory for initial use for direct socket connection */
     protected RMISocketFactory initialFactory = new RMIDirectSocketFactory();
 
     /** ordered list of factories to try as alternate connection
       * mechanisms if a direct socket connections fails */
-    protected Vector altFactoryList;
+    protected Vector<RMISocketFactory> altFactoryList;
 
     /**
      * Create a RMIMasterSocketFactory object.  Establish order of
@@ -95,7 +96,7 @@
      * socket connection fails.
      */
     public RMIMasterSocketFactory() {
-        altFactoryList = new Vector(2);
+        altFactoryList = new Vector<>(2);
         boolean setFactories = false;
 
         try {
@@ -152,7 +153,7 @@
          * If we remember successfully connecting to this host before,
          * use the same factory.
          */
-        factory = (RMISocketFactory) successTable.get(host);
+        factory = successTable.get(host);
         if (factory != null) {
             if (proxyLog.isLoggable(Log.BRIEF)) {
                 proxyLog.log(Log.BRIEF,
@@ -207,9 +208,7 @@
 
             return initialSocket;
 
-        } catch (UnknownHostException e) {
-            initialFailure = e;
-        } catch (NoRouteToHostException e) {
+        } catch (UnknownHostException | NoRouteToHostException e) {
             initialFailure = e;
         } catch (SocketException e) {
             if (eagerHttpFallback) {
@@ -227,22 +226,20 @@
 
                 // Finally, try any alternate connection mechanisms.
                 for (int i = 0; i < altFactoryList.size(); ++ i) {
-                    factory = (RMISocketFactory) altFactoryList.elementAt(i);
-                    try {
-                        if (proxyLog.isLoggable(Log.BRIEF)) {
-                            proxyLog.log(Log.BRIEF,
-                                "trying with factory: " + factory);
-                        }
-
+                    factory = altFactoryList.elementAt(i);
+                    if (proxyLog.isLoggable(Log.BRIEF)) {
+                        proxyLog.log(Log.BRIEF,
+                            "trying with factory: " + factory);
+                    }
+                    try (Socket testSocket =
+                            factory.createSocket(host, port)) {
                         // For HTTP connections, the output (POST request) must
                         // be sent before we verify a successful connection.
                         // So, sacrifice a socket for the sake of testing...
                         // The following sequence should verify a successful
                         // HTTP connection if no IOException is thrown.
-                        Socket testSocket = factory.createSocket(host, port);
                         InputStream in = testSocket.getInputStream();
                         int b = in.read(); // probably -1 for EOF...
-                        testSocket.close();
                     } catch (IOException ex) {
                         if (proxyLog.isLoggable(Log.BRIEF)) {
                             proxyLog.log(Log.BRIEF, "factory failed: ", ex);
@@ -276,9 +273,7 @@
                 }
                 // if connector ever does get socket, it won't be used
                 connector.notUsed();
-            } catch (UnknownHostException e) {
-                initialFailure = e;
-            } catch (NoRouteToHostException e) {
+            } catch (UnknownHostException | NoRouteToHostException e) {
                 initialFailure = e;
             } catch (SocketException e) {
                 if (eagerHttpFallback) {
diff --git a/jdk/src/share/classes/sun/rmi/transport/tcp/ConnectionMultiplexer.java b/jdk/src/share/classes/sun/rmi/transport/tcp/ConnectionMultiplexer.java
index a3b6696..47b7143 100644
--- a/jdk/src/share/classes/sun/rmi/transport/tcp/ConnectionMultiplexer.java
+++ b/jdk/src/share/classes/sun/rmi/transport/tcp/ConnectionMultiplexer.java
@@ -85,7 +85,7 @@
     private DataOutputStream dataOut;
 
     /** table holding currently open connection IDs and related info */
-    private Hashtable connectionTable = new Hashtable(7);
+    private Hashtable<Integer, MultiplexConnectionInfo> connectionTable = new Hashtable<>(7);
 
     /** number of currently open connections */
     private int numConnections = 0;
@@ -131,7 +131,6 @@
     {
         try {
             int op, id, length;
-            Integer idObj;
             MultiplexConnectionInfo info;
 
             while (true) {
@@ -148,9 +147,7 @@
                         multiplexLog.log(Log.VERBOSE, "operation  OPEN " + id);
                     }
 
-                    idObj = new Integer(id);
-                    info =
-                        (MultiplexConnectionInfo) connectionTable.get(idObj);
+                    info = connectionTable.get(id);
                     if (info != null)
                         throw new IOException(
                             "OPEN: Connection ID already exists");
@@ -158,7 +155,7 @@
                     info.in = new MultiplexInputStream(this, info, 2048);
                     info.out = new MultiplexOutputStream(this, info, 2048);
                     synchronized (connectionTable) {
-                        connectionTable.put(idObj, info);
+                        connectionTable.put(id, info);
                         ++ numConnections;
                     }
                     sun.rmi.transport.Connection conn;
@@ -174,9 +171,7 @@
                         multiplexLog.log(Log.VERBOSE, "operation  CLOSE " + id);
                     }
 
-                    idObj = new Integer(id);
-                    info =
-                        (MultiplexConnectionInfo) connectionTable.get(idObj);
+                    info = connectionTable.get(id);
                     if (info == null)
                         throw new IOException(
                             "CLOSE: Invalid connection ID");
@@ -185,7 +180,7 @@
                     if (!info.closed)
                         sendCloseAck(info);
                     synchronized (connectionTable) {
-                        connectionTable.remove(idObj);
+                        connectionTable.remove(id);
                         -- numConnections;
                     }
                     break;
@@ -199,9 +194,7 @@
                             "operation  CLOSEACK " + id);
                     }
 
-                    idObj = new Integer(id);
-                    info =
-                        (MultiplexConnectionInfo) connectionTable.get(idObj);
+                    info = connectionTable.get(id);
                     if (info == null)
                         throw new IOException(
                             "CLOSEACK: Invalid connection ID");
@@ -211,7 +204,7 @@
                     info.in.disconnect();
                     info.out.disconnect();
                     synchronized (connectionTable) {
-                        connectionTable.remove(idObj);
+                        connectionTable.remove(id);
                         -- numConnections;
                     }
                     break;
@@ -219,9 +212,7 @@
                 // remote endpoint declaring additional bytes receivable
                 case REQUEST:
                     id = dataIn.readUnsignedShort();
-                    idObj = new Integer(id);
-                    info =
-                        (MultiplexConnectionInfo) connectionTable.get(idObj);
+                    info = connectionTable.get(id);
                     if (info == null)
                         throw new IOException(
                             "REQUEST: Invalid connection ID");
@@ -238,9 +229,7 @@
                 // remote endpoint transmitting data packet
                 case TRANSMIT:
                     id = dataIn.readUnsignedShort();
-                    idObj = new Integer(id);
-                    info =
-                        (MultiplexConnectionInfo) connectionTable.get(idObj);
+                    info = connectionTable.get(id);
                     if (info == null)
                         throw new IOException("SEND: Invalid connection ID");
                     length = dataIn.readInt();
@@ -273,7 +262,6 @@
         // If all possible 32768 IDs are used,
         // this method will block searching for a new ID forever.
         int id;
-        Integer idObj;
         do {
             lastID = (++ lastID) & 0x7FFF;
             id = lastID;
@@ -283,8 +271,7 @@
             // two endpoints.
             if (orig)
                 id |= 0x8000;
-            idObj = new Integer(id);
-        } while (connectionTable.get(idObj) != null);
+        } while (connectionTable.get(id) != null);
 
         // create multiplexing streams and bookkeeping information
         MultiplexConnectionInfo info = new MultiplexConnectionInfo(id);
@@ -298,7 +285,7 @@
             if (numConnections >= maxConnections)
                 throw new IOException("Cannot exceed " + maxConnections +
                     " simultaneous multiplexed connections");
-            connectionTable.put(idObj, info);
+            connectionTable.put(id, info);
             ++ numConnections;
         }
 
@@ -331,10 +318,10 @@
                 return;
             alive = false;
 
-            Enumeration enum_ = connectionTable.elements();
+            Enumeration<MultiplexConnectionInfo> enum_ =
+                    connectionTable.elements();
             while (enum_.hasMoreElements()) {
-                MultiplexConnectionInfo info =
-                    (MultiplexConnectionInfo) enum_.nextElement();
+                MultiplexConnectionInfo info = enum_.nextElement();
                 info.in.disconnect();
                 info.out.disconnect();
             }
diff --git a/jdk/src/share/classes/sun/rmi/transport/tcp/TCPChannel.java b/jdk/src/share/classes/sun/rmi/transport/tcp/TCPChannel.java
index e3aa730..7ab872c 100644
--- a/jdk/src/share/classes/sun/rmi/transport/tcp/TCPChannel.java
+++ b/jdk/src/share/classes/sun/rmi/transport/tcp/TCPChannel.java
@@ -64,7 +64,7 @@
     private final TCPTransport tr;
     /** list of cached connections */
     private final List<TCPConnection> freeList =
-        new ArrayList<TCPConnection>();
+        new ArrayList<>();
     /** frees cached connections that have expired (guarded by freeList) */
     private Future<?> reaper = null;
 
@@ -480,7 +480,7 @@
     private TCPTransport transport;
 
     /** queue of connections to be accepted */
-    private List<Connection> queue = new ArrayList<Connection>();
+    private List<Connection> queue = new ArrayList<>();
 
     /** thread ID counter */
     private static int threadNum = 0;
diff --git a/jdk/src/share/classes/sun/rmi/transport/tcp/TCPEndpoint.java b/jdk/src/share/classes/sun/rmi/transport/tcp/TCPEndpoint.java
index 5897877..4af3405 100644
--- a/jdk/src/share/classes/sun/rmi/transport/tcp/TCPEndpoint.java
+++ b/jdk/src/share/classes/sun/rmi/transport/tcp/TCPEndpoint.java
@@ -148,7 +148,7 @@
     // TBD: should this be a weak hash table?
     private static final
         Map<TCPEndpoint,LinkedList<TCPEndpoint>> localEndpoints =
-        new HashMap<TCPEndpoint,LinkedList<TCPEndpoint>>();
+        new HashMap<>();
 
     /**
      * Create an endpoint for a specified host and port.
@@ -623,10 +623,9 @@
             try {
                 TCPEndpoint.shedConnectionCaches();
                 // REMIND: should we retry createSocket?
-            } catch (OutOfMemoryError mem) {
+            } catch (OutOfMemoryError | Exception mem) {
                 // don't quit if out of memory
-            } catch (Exception ex) {
-                // don't quit if shed fails non-catastrophically
+                // or shed fails non-catastrophically
             }
 
             throw new ConnectIOException("Exception creating connection to: " +
diff --git a/jdk/src/share/classes/sun/rmi/transport/tcp/TCPTransport.java b/jdk/src/share/classes/sun/rmi/transport/tcp/TCPTransport.java
index a22c720..e2b9841 100644
--- a/jdk/src/share/classes/sun/rmi/transport/tcp/TCPTransport.java
+++ b/jdk/src/share/classes/sun/rmi/transport/tcp/TCPTransport.java
@@ -119,7 +119,7 @@
 
     /** client host for the current thread's connection */
     private static final ThreadLocal<ConnectionHandler>
-        threadConnectionHandler = new ThreadLocal<ConnectionHandler>();
+        threadConnectionHandler = new ThreadLocal<>();
 
     /** endpoints for this transport */
     private final LinkedList<TCPEndpoint> epList;
@@ -129,7 +129,7 @@
     private ServerSocket server = null;
     /** table mapping endpoints to channels */
     private final Map<TCPEndpoint,Reference<TCPChannel>> channelTable =
-        new WeakHashMap<TCPEndpoint,Reference<TCPChannel>>();
+        new WeakHashMap<>();
 
     static final RMISocketFactory defaultSocketFactory =
         RMISocketFactory.getDefaultSocketFactory();
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 94edd11..a628012 100644
--- a/jdk/src/share/classes/sun/security/jgss/wrapper/SunNativeProvider.java
+++ b/jdk/src/share/classes/sun/security/jgss/wrapper/SunNativeProvider.java
@@ -90,6 +90,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 ff4ae84..8c0cc62 100644
--- a/jdk/src/share/classes/sun/security/krb5/Config.java
+++ b/jdk/src/share/classes/sun/security/krb5/Config.java
@@ -113,6 +113,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.
      */
@@ -146,7 +166,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.
         }
@@ -713,6 +737,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";
                 }
@@ -724,6 +751,30 @@
         return name;
     }
 
+    private String getProperty(String property) {
+        return 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/Credentials.java b/jdk/src/share/classes/sun/security/krb5/Credentials.java
index 86dc3a0..15328cd 100644
--- a/jdk/src/share/classes/sun/security/krb5/Credentials.java
+++ b/jdk/src/share/classes/sun/security/krb5/Credentials.java
@@ -285,10 +285,11 @@
         throws KrbException, IOException {
 
         if (ticketCache == null) {
-            // The default ticket cache on Windows is not a file.
+            // The default ticket cache on Windows and Mac is not a file.
             String os = java.security.AccessController.doPrivileged(
                         new sun.security.action.GetPropertyAction("os.name"));
-            if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS")) {
+            if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") ||
+                    os.toUpperCase(Locale.ENGLISH).startsWith("MAC")) {
                 Credentials creds = acquireDefaultCreds();
                 if (creds == null) {
                     if (DEBUG) {
@@ -470,7 +471,11 @@
         java.security.AccessController.doPrivileged(
                 new java.security.PrivilegedAction<Void> () {
                         public Void run() {
-                                System.loadLibrary("w2k_lsa_auth");
+                                if (System.getProperty("os.name").startsWith("Mac")) {
+                                    System.loadLibrary("osxkrb5");
+                                } else {
+                                    System.loadLibrary("w2k_lsa_auth");
+                                }
                                 return null;
                         }
                 });
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..d4b51f8
--- /dev/null
+++ b/jdk/src/share/classes/sun/security/krb5/SCDynamicStoreConfig.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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.io.IOException;
+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 IOException
+     */
+    @SuppressWarnings("unchecked")
+    public static Hashtable<String, Object> getConfig() throws IOException {
+        Hashtable<String, Object> stanzaTable = getKerberosConfig();
+        if (stanzaTable == null) {
+            throw new IOException("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 stanzaTable;
+    }
+}
diff --git a/jdk/src/share/classes/sun/security/smartcardio/TerminalImpl.java b/jdk/src/share/classes/sun/security/smartcardio/TerminalImpl.java
index 9cef530..7461743 100644
--- a/jdk/src/share/classes/sun/security/smartcardio/TerminalImpl.java
+++ b/jdk/src/share/classes/sun/security/smartcardio/TerminalImpl.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -112,14 +112,17 @@
             if (wantPresent == present) {
                 return true;
             }
-            // no match, wait
-            status = SCardGetStatusChange(contextId, timeout, status, readers);
-            present = (status[0] & SCARD_STATE_PRESENT) != 0;
-            // should never happen
-            if (wantPresent != present) {
-                throw new CardException("wait mismatch");
+            // no match, wait (until timeout expires)
+            long end = System.currentTimeMillis() + timeout;
+            while (wantPresent != present && timeout != 0) {
+              // set remaining timeout
+              if (timeout != TIMEOUT_INFINITE) {
+                timeout = Math.max(end - System.currentTimeMillis(), 0l);
+              }
+              status = SCardGetStatusChange(contextId, timeout, status, readers);
+              present = (status[0] & SCARD_STATE_PRESENT) != 0;
             }
-            return true;
+            return wantPresent == present;
         } catch (PCSCException e) {
             if (e.code == SCARD_E_TIMEOUT) {
                 return false;
diff --git a/jdk/src/share/classes/sun/security/tools/JarSigner.java b/jdk/src/share/classes/sun/security/tools/JarSigner.java
index fe3944f..31dfbce 100644
--- a/jdk/src/share/classes/sun/security/tools/JarSigner.java
+++ b/jdk/src/share/classes/sun/security/tools/JarSigner.java
@@ -66,7 +66,7 @@
  * 0: success
  * 1: any error that the jar cannot be signed or verified, including:
  *      keystore loading error
- *      TSP communciation error
+ *      TSP communication error
  *      jarsigner command line error...
  * otherwise: error codes from -strict
  *
@@ -258,8 +258,7 @@
             if (hasExpiringCert) {
                 exitCode |= 2;
             }
-            if (chainNotValidated) {
-                // hasExpiredCert and notYetValidCert included in this case
+            if (chainNotValidated || hasExpiredCert || notYetValidCert) {
                 exitCode |= 4;
             }
             if (badKeyUsage || badExtendedKeyUsage || badNetscapeCertType) {
@@ -600,7 +599,6 @@
                 if (verbose != null) System.out.println();
                 Enumeration<JarEntry> e = entriesVec.elements();
 
-                long now = System.currentTimeMillis();
                 String tab = rb.getString("6SPACE");
 
                 while (e.hasMoreElements()) {
@@ -648,7 +646,7 @@
                             // signerInfo() must be called even if -verbose
                             // not provided. The method updates various
                             // warning flags.
-                            String si = signerInfo(signer, tab, now);
+                            String si = signerInfo(signer, tab);
                             if (showcerts) {
                                 sb.append(si);
                                 sb.append('\n');
@@ -837,7 +835,7 @@
      * Note: no newline character at the end
      */
     String printCert(String tab, Certificate c, boolean checkValidityPeriod,
-        long now, boolean checkUsage) {
+        Date timestamp, boolean checkUsage) {
 
         StringBuilder certStr = new StringBuilder();
         String space = rb.getString("SPACE");
@@ -862,22 +860,24 @@
             certStr.append("\n").append(tab).append("[");
             Date notAfter = x509Cert.getNotAfter();
             try {
-                x509Cert.checkValidity();
-                // test if cert will expire within six months
-                if (now == 0) {
-                    now = System.currentTimeMillis();
-                }
-                if (notAfter.getTime() < now + SIX_MONTHS) {
-                    hasExpiringCert = true;
-
-                    if (expiringTimeForm == null) {
-                        expiringTimeForm = new MessageFormat(
-                            rb.getString("certificate.will.expire.on"));
+                boolean printValidity = true;
+                if (timestamp == null) {
+                    x509Cert.checkValidity();
+                    // test if cert will expire within six months
+                    if (notAfter.getTime() < System.currentTimeMillis() + SIX_MONTHS) {
+                        hasExpiringCert = true;
+                        if (expiringTimeForm == null) {
+                            expiringTimeForm = new MessageFormat(
+                                rb.getString("certificate.will.expire.on"));
+                        }
+                        Object[] source = { notAfter };
+                        certStr.append(expiringTimeForm.format(source));
+                        printValidity = false;
                     }
-                    Object[] source = { notAfter };
-                    certStr.append(expiringTimeForm.format(source));
-
                 } else {
+                    x509Cert.checkValidity(timestamp);
+                }
+                if (printValidity) {
                     if (validityTimeForm == null) {
                         validityTimeForm = new MessageFormat(
                             rb.getString("certificate.is.valid.from"));
@@ -1283,7 +1283,7 @@
                             tsaURI);
                     }
                     System.out.println(rb.getString("TSA.certificate.") +
-                        printCert("", tsaCert, false, 0, false));
+                        printCert("", tsaCert, false, null, false));
                 }
                 if (signingMechanism != null) {
                     System.out.println(
@@ -1481,23 +1481,27 @@
     /**
      * Returns a string of singer info, with a newline at the end
      */
-    private String signerInfo(CodeSigner signer, String tab, long now) {
+    private String signerInfo(CodeSigner signer, String tab) {
         if (cacheForSignerInfo.containsKey(signer)) {
             return cacheForSignerInfo.get(signer);
         }
         StringBuffer s = new StringBuffer();
         List<? extends Certificate> certs = signer.getSignerCertPath().getCertificates();
         // display the signature timestamp, if present
-        Timestamp timestamp = signer.getTimestamp();
-        if (timestamp != null) {
-            s.append(printTimestamp(tab, timestamp));
+        Date timestamp;
+        Timestamp ts = signer.getTimestamp();
+        if (ts != null) {
+            s.append(printTimestamp(tab, ts));
             s.append('\n');
+            timestamp = ts.getTimestamp();
+        } else {
+            timestamp = null;
         }
-        // display the certificate(s). The first one is end-enity cert and
+        // display the certificate(s). The first one is end-entity cert and
         // its KeyUsage should be checked.
         boolean first = true;
         for (Certificate c : certs) {
-            s.append(printCert(tab, c, true, now, first));
+            s.append(printCert(tab, c, true, timestamp, first));
             s.append('\n');
             first = false;
         }
@@ -1508,9 +1512,15 @@
             if (debug) {
                 e.printStackTrace();
             }
-            chainNotValidated = true;
-            s.append(tab + rb.getString(".CertPath.not.validated.") +
-                    e.getLocalizedMessage() + "]\n");   // TODO
+            if (e.getCause() != null &&
+                    (e.getCause() instanceof CertificateExpiredException ||
+                     e.getCause() instanceof CertificateNotYetValidException)) {
+                // No more warning, we alreay have hasExpiredCert or notYetValidCert
+            } else {
+                chainNotValidated = true;
+                s.append(tab + rb.getString(".CertPath.not.validated.") +
+                        e.getLocalizedMessage() + "]\n");   // TODO
+            }
         }
         String result = s.toString();
         cacheForSignerInfo.put(signer, result);
@@ -1804,7 +1814,7 @@
 
             // We don't meant to print anything, the next call
             // checks validity and keyUsage etc
-            printCert("", certChain[0], true, 0, true);
+            printCert("", certChain[0], true, null, true);
 
             try {
                 CertPath cp = certificateFactory.generateCertPath(Arrays.asList(certChain));
@@ -1813,7 +1823,13 @@
                 if (debug) {
                     e.printStackTrace();
                 }
-                chainNotValidated = true;
+                if (e.getCause() != null &&
+                        (e.getCause() instanceof CertificateExpiredException ||
+                        e.getCause() instanceof CertificateNotYetValidException)) {
+                    // No more warning, we alreay have hasExpiredCert or notYetValidCert
+                } else {
+                    chainNotValidated = true;
+                }
             }
 
             try {
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/demo/jfc/TransparentRuler/transparentruler/Ruler.java b/jdk/src/share/demo/jfc/TransparentRuler/transparentruler/Ruler.java
index fcba7ac..9e93bd2 100644
--- a/jdk/src/share/demo/jfc/TransparentRuler/transparentruler/Ruler.java
+++ b/jdk/src/share/demo/jfc/TransparentRuler/transparentruler/Ruler.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2012, 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
@@ -40,12 +40,9 @@
 package transparentruler;
 
 
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GraphicsDevice;
+import java.awt.*;
 import java.awt.GraphicsDevice.WindowTranslucency;
-import java.awt.GraphicsEnvironment;
+import static java.awt.GraphicsDevice.WindowTranslucency.*;
 import java.awt.event.ActionEvent;
 import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentEvent;
@@ -79,16 +76,32 @@
     private static final int F_HEIGHT = 400;
     private static final int F_WIDTH = (int) (F_HEIGHT * 1.618 + 0.5);
 
-    private static void checkTranslucencyMode(WindowTranslucency arg) {
+    private static boolean translucencySupported;
+    private static boolean transparencySupported;
+
+    private static boolean checkTranslucencyMode(WindowTranslucency arg) {
         GraphicsEnvironment ge =
                 GraphicsEnvironment.getLocalGraphicsEnvironment();
         GraphicsDevice gd = ge.getDefaultScreenDevice();
-        if (!gd.isWindowTranslucencySupported(arg)) {
-            System.err.println("'" + arg
-                    + "' translucency mode isn't supported.");
-            System.exit(-1);
-        }
+        return gd.isWindowTranslucencySupported(arg);
     }
+
+    public Shape buildShape() {
+        int h = getHeight();
+        int w = getWidth();
+        float a = (float) Math.hypot(h, w);
+        Float path = new java.awt.geom.Path2D.Float();
+        path.moveTo(0, 0);
+        path.lineTo(w, 0);
+        path.lineTo(0, h);
+        path.closePath();
+        path.moveTo(W, W);
+        path.lineTo(W, h - W * (a + h) / w);
+        path.lineTo(w - W * (a + w) / h, W);
+        path.closePath();
+        return path;
+    }
+
     private final ComponentAdapter componentListener = new ComponentAdapter() {
 
         /**
@@ -97,36 +110,32 @@
          */
         @Override
         public void componentResized(ComponentEvent e) {
-            int h = getHeight();
-            int w = getWidth();
-            float a = (float) Math.hypot(h, w);
-            Float path = new java.awt.geom.Path2D.Float();
-            path.moveTo(0, 0);
-            path.lineTo(w, 0);
-            path.lineTo(0, h);
-            path.closePath();
-            path.moveTo(W, W);
-            path.lineTo(W, h - W * (a + h) / w);
-            path.lineTo(w - W * (a + w) / h, W);
-            path.closePath();
-            setShape(path);
+
+            // We do apply shape only if PERPIXEL_TRANSPARENT is supported
+            if (transparencySupported) {
+                setShape(buildShape());
+            }
         }
     };
+
     private final Action exitAction = new AbstractAction("Exit") {
 
         {
             putValue(Action.MNEMONIC_KEY, KeyEvent.VK_X);
         }
 
+        @Override
         public void actionPerformed(ActionEvent e) {
             System.exit(0);
         }
     };
+
     private final JPopupMenu jPopupMenu = new JPopupMenu();
 
     {
         jPopupMenu.add(new JMenuItem(exitAction));
     }
+
     /**
      * Implements mouse-related behavior: window dragging and popup menu
      * invocation
@@ -157,6 +166,7 @@
             }
         }
     };
+
     /**
      * Implements keyboard navigation. Arrows move by 5 pixels, Ctrl + arrows
      * move by 50 pixels, Alt + arrows move by 1 pixel.
@@ -201,10 +211,22 @@
 
             @Override
             protected void paintComponent(Graphics g) {
-                Graphics gg = g.create();
+                Graphics2D gg = (Graphics2D) g.create();
                 int w = getWidth();
                 int h = getHeight();
                 int hh = gg.getFontMetrics().getAscent();
+
+                // This is an approach to apply shape when PERPIXEL_TRANSPARENT
+                // isn't supported
+                if (!transparencySupported) {
+                    gg.setBackground(new Color(0, 0, 0, 0));
+                    gg.clearRect(0, 0, w, h);
+                    gg.clip(buildShape());
+
+                    gg.setBackground(Ruler.this.getBackground());
+                    gg.clearRect(0, 0, w, h);
+                }
+
                 gg.setColor(FOREGROUND);
                 for (int x = 0; x < w * (h - 8) / h - 5; x += 5) {
                     boolean hi = x % 50 == 0;
@@ -216,6 +238,7 @@
                         gg.drawString(number, x + 5 - ww / 2, 20 + hh);
                     }
                 }
+
                 gg.dispose();
             }
         });
@@ -231,9 +254,17 @@
 
         SwingUtilities.invokeAndWait(new Runnable() {
 
+            @Override
             public void run() {
-                checkTranslucencyMode(WindowTranslucency.PERPIXEL_TRANSLUCENT);
-                checkTranslucencyMode(WindowTranslucency.PERPIXEL_TRANSPARENT);
+                translucencySupported = checkTranslucencyMode(PERPIXEL_TRANSLUCENT);
+                transparencySupported = checkTranslucencyMode(PERPIXEL_TRANSPARENT);
+
+                if (!translucencySupported) {
+                    System.err.println("This application requires "
+                            + "'PERPIXEL_TRANSLUCENT' translucency mode to "
+                            + "be supported.");
+                    System.exit(-1);
+                }
 
                 Ruler ruler = new Ruler();
                 ruler.setVisible(true);
diff --git a/jdk/src/share/demo/jvmti/compiledMethodLoad/sample.makefile.txt b/jdk/src/share/demo/jvmti/compiledMethodLoad/sample.makefile.txt
index 22e2cec..e214792 100644
--- a/jdk/src/share/demo/jvmti/compiledMethodLoad/sample.makefile.txt
+++ b/jdk/src/share/demo/jvmti/compiledMethodLoad/sample.makefile.txt
@@ -90,7 +90,7 @@
     OBJECTS=$(SOURCES:%.c=%.o)
     # Library name and options needed to build it
     LIBRARY=lib$(LIBNAME).so
-    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
+    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc
     # Libraries we are dependent on
     LIBRARIES=-lc
     # Building a shared library
diff --git a/jdk/src/share/demo/jvmti/gctest/sample.makefile.txt b/jdk/src/share/demo/jvmti/gctest/sample.makefile.txt
index b14ea70..99fa399 100644
--- a/jdk/src/share/demo/jvmti/gctest/sample.makefile.txt
+++ b/jdk/src/share/demo/jvmti/gctest/sample.makefile.txt
@@ -90,7 +90,7 @@
     OBJECTS=$(SOURCES:%.c=%.o)
     # Library name and options needed to build it
     LIBRARY=lib$(LIBNAME).so
-    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
+    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc
     # Libraries we are dependent on
     LIBRARIES=-lc
     # Building a shared library
diff --git a/jdk/src/share/demo/jvmti/heapTracker/sample.makefile.txt b/jdk/src/share/demo/jvmti/heapTracker/sample.makefile.txt
index 83e7d79..a58f710 100644
--- a/jdk/src/share/demo/jvmti/heapTracker/sample.makefile.txt
+++ b/jdk/src/share/demo/jvmti/heapTracker/sample.makefile.txt
@@ -94,7 +94,7 @@
     OBJECTS=$(SOURCES:%.c=%.o)
     # Library name and options needed to build it
     LIBRARY=lib$(LIBNAME).so
-    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
+    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc
     # Libraries we are dependent on
     LIBRARIES=-L $(JDK)/jre/lib/$(LIBARCH) -ljava_crw_demo -lc
     # Building a shared library
diff --git a/jdk/src/share/demo/jvmti/heapViewer/sample.makefile.txt b/jdk/src/share/demo/jvmti/heapViewer/sample.makefile.txt
index a4e3d71..9f76046 100644
--- a/jdk/src/share/demo/jvmti/heapViewer/sample.makefile.txt
+++ b/jdk/src/share/demo/jvmti/heapViewer/sample.makefile.txt
@@ -90,7 +90,7 @@
     OBJECTS=$(SOURCES:%.c=%.o)
     # Library name and options needed to build it
     LIBRARY=lib$(LIBNAME).so
-    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
+    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc
     # Libraries we are dependent on
     LIBRARIES=-lc
     # Building a shared library
diff --git a/jdk/src/share/demo/jvmti/hprof/sample.makefile.txt b/jdk/src/share/demo/jvmti/hprof/sample.makefile.txt
index 8028cd8..8da8100 100644
--- a/jdk/src/share/demo/jvmti/hprof/sample.makefile.txt
+++ b/jdk/src/share/demo/jvmti/hprof/sample.makefile.txt
@@ -130,7 +130,7 @@
     OBJECTS=$(SOURCES:%.c=%.o)
     # Library name and options needed to build it
     LIBRARY=lib$(LIBNAME).so
-    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
+    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc
     # Libraries we are dependent on
     LIBRARIES= -ldl -lc
     # Building a shared library
diff --git a/jdk/src/share/demo/jvmti/index.html b/jdk/src/share/demo/jvmti/index.html
index 6ef96bb..b66ac8d 100644
--- a/jdk/src/share/demo/jvmti/index.html
+++ b/jdk/src/share/demo/jvmti/index.html
@@ -308,7 +308,7 @@
 <code><ul>
 gcc -O2 -fPIC -pthread -DLINUX -c <i>*.c</i>
 <br>
-gcc -z defs -static-libgcc -shared -mimpure-text -o <i>libXXX.so *.o</i> -lc
+gcc -z defs -static-libgcc -shared -o <i>libXXX.so *.o</i> -lc
 </code></ul>
 <br>
 For AMD64:
@@ -316,7 +316,7 @@
 <code><ul>
 gcc -O2 -fPIC -pthread -DLINUX -D_LP64=1 -c <i>*.c</i>
 <br>
-gcc -z defs -static-libgcc -shared -mimpure-text -o <i>libXXX.so *.o</i> -lc
+gcc -z defs -static-libgcc -shared -o <i>libXXX.so *.o</i> -lc
 </code></ul>
 <br>
 </li>
@@ -339,7 +339,7 @@
 </li>
 
 <li>
-Library: Use -static-libgcc -mimpure-text.
+Library: Use -static-libgcc.
 <br>
 When building the shared library (-shared option), this option
 allows for maximum portability of the library between different
diff --git a/jdk/src/share/demo/jvmti/java_crw_demo/sample.makefile.txt b/jdk/src/share/demo/jvmti/java_crw_demo/sample.makefile.txt
index 51f0796..a2ec685 100644
--- a/jdk/src/share/demo/jvmti/java_crw_demo/sample.makefile.txt
+++ b/jdk/src/share/demo/jvmti/java_crw_demo/sample.makefile.txt
@@ -90,7 +90,7 @@
     OBJECTS=$(SOURCES:%.c=%.o)
     # Library name and options needed to build it
     LIBRARY=lib$(LIBNAME).so
-    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
+    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc
     # Libraries we are dependent on
     LIBRARIES=-lc
     # Building a shared library
diff --git a/jdk/src/share/demo/jvmti/minst/sample.makefile.txt b/jdk/src/share/demo/jvmti/minst/sample.makefile.txt
index be8910b..42da35b 100644
--- a/jdk/src/share/demo/jvmti/minst/sample.makefile.txt
+++ b/jdk/src/share/demo/jvmti/minst/sample.makefile.txt
@@ -94,7 +94,7 @@
     OBJECTS=$(SOURCES:%.c=%.o)
     # Library name and options needed to build it
     LIBRARY=lib$(LIBNAME).so
-    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
+    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc
     # Libraries we are dependent on
     LIBRARIES=-L $(JDK)/jre/lib/$(LIBARCH) -ljava_crw_demo -lc
     # Building a shared library
diff --git a/jdk/src/share/demo/jvmti/mtrace/sample.makefile.txt b/jdk/src/share/demo/jvmti/mtrace/sample.makefile.txt
index c75a5e8..b103282 100644
--- a/jdk/src/share/demo/jvmti/mtrace/sample.makefile.txt
+++ b/jdk/src/share/demo/jvmti/mtrace/sample.makefile.txt
@@ -94,7 +94,7 @@
     OBJECTS=$(SOURCES:%.c=%.o)
     # Library name and options needed to build it
     LIBRARY=lib$(LIBNAME).so
-    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
+    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc
     # Libraries we are dependent on
     LIBRARIES=-L $(JDK)/jre/lib/$(LIBARCH) -ljava_crw_demo -lc
     # Building a shared library
diff --git a/jdk/src/share/demo/jvmti/versionCheck/sample.makefile.txt b/jdk/src/share/demo/jvmti/versionCheck/sample.makefile.txt
index 3028a85..9b7abd4 100644
--- a/jdk/src/share/demo/jvmti/versionCheck/sample.makefile.txt
+++ b/jdk/src/share/demo/jvmti/versionCheck/sample.makefile.txt
@@ -90,7 +90,7 @@
     OBJECTS=$(SOURCES:%.c=%.o)
     # Library name and options needed to build it
     LIBRARY=lib$(LIBNAME).so
-    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
+    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc
     # Libraries we are dependent on
     LIBRARIES=-lc
     # Building a shared library
diff --git a/jdk/src/share/demo/jvmti/waiters/sample.makefile.txt b/jdk/src/share/demo/jvmti/waiters/sample.makefile.txt
index 70d66bd..68ac497 100644
--- a/jdk/src/share/demo/jvmti/waiters/sample.makefile.txt
+++ b/jdk/src/share/demo/jvmti/waiters/sample.makefile.txt
@@ -91,7 +91,7 @@
     OBJECTS=$(SOURCES:%.cpp=%.o)
     # Library name and options needed to build it
     LIBRARY=lib$(LIBNAME).so
-    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
+    LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc
     # Libraries we are dependent on
     LIBRARIES=
     # Building a shared library
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 8d833eb..1e49717 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 6b06cbd..0c22353 100644
--- a/jdk/src/share/native/java/lang/System.c
+++ b/jdk/src/share/native/java/lang/System.c
@@ -249,6 +249,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 !!!
      */
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..ec943c1 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 */
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..3e738ab 100644
--- a/jdk/src/share/native/java/lang/fdlibm/include/jfdlibm.h
+++ b/jdk/src/share/native/java/lang/fdlibm/include/jfdlibm.h
@@ -61,7 +61,7 @@
 #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_log           __j__ieee754_log
diff --git a/jdk/src/share/native/java/lang/java_props.h b/jdk/src/share/native/java/lang/java_props.h
index 18a1b34..02cfe1e 100644
--- a/jdk/src/share/native/java/lang/java_props.h
+++ b/jdk/src/share/native/java/lang/java_props.h
@@ -87,6 +87,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 4328c4c..991ed5c 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 b35375b..10c3cd3 100644
--- a/jdk/src/share/native/sun/awt/medialib/mlib_types.h
+++ b/jdk/src/share/native/sun/awt/medialib/mlib_types.h
@@ -62,7 +62,7 @@
 #include <stdint.h>
 #include <stddef.h>
 
-#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..4b16bff 100644
--- a/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.c
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.c
@@ -137,7 +137,8 @@
                         jint width, jint height)
 {
     GLenum texTarget, texProxyTarget;
-    GLint format = isOpaque ? GL_RGB : GL_RGBA;
+    GLint format = GL_RGBA;
+    GLint size = GL_UNSIGNED_INT_8_8_8_8;
     GLuint texID;
     GLsizei texWidth, texHeight, realWidth, realHeight;
     GLint texMax;
@@ -191,7 +192,7 @@
     // the calculated power-of-two dimensions and the given internal format
     j2d_glTexImage2D(texProxyTarget, 0, format,
                      texWidth, texHeight, 0,
-                     format, GL_UNSIGNED_BYTE, NULL);
+                     format, size, NULL);
     j2d_glGetTexLevelParameteriv(texProxyTarget, 0,
                                  GL_TEXTURE_WIDTH, &realWidth);
     j2d_glGetTexLevelParameteriv(texProxyTarget, 0,
@@ -213,7 +214,7 @@
     j2d_glBindTexture(texTarget, texID);
     j2d_glTexImage2D(texTarget, 0, format,
                      texWidth, texHeight, 0,
-                     format, GL_UNSIGNED_BYTE, NULL);
+                     format, size, NULL);
 
     oglsdo->isOpaque = isOpaque;
     oglsdo->xOffset = 0;
@@ -548,12 +549,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..a859cf4 100644
--- a/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.h
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.h
@@ -286,7 +286,7 @@
 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,
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/native/sun/security/krb5/nativeccache.c b/jdk/src/share/native/sun/security/krb5/nativeccache.c
new file mode 100644
index 0000000..8b24033
--- /dev/null
+++ b/jdk/src/share/native/sun/security/krb5/nativeccache.c
@@ -0,0 +1,573 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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_security_krb5_Credentials.h"
+#import <Kerberos/Kerberos.h>
+
+/*
+ * Based largely on klist.c,
+ *
+ * Created by Scott Kovatch on 8/12/04.
+ *
+ * See http://www.opensource.apple.com/darwinsource/10.3.3/Kerberos-47/KerberosClients/klist/Sources/klist.c
+
+ */
+
+/*
+ * Statics for this module
+ */
+
+static jclass derValueClass = NULL;
+static jclass ticketClass = NULL;
+static jclass principalNameClass = NULL;
+static jclass encryptionKeyClass = NULL;
+static jclass ticketFlagsClass = NULL;
+static jclass kerberosTimeClass = NULL;
+static jclass javaLangStringClass = NULL;
+static jclass javaLangIntegerClass = NULL;
+static jclass hostAddressClass = NULL;
+static jclass hostAddressesClass = NULL;
+
+static jmethodID derValueConstructor = 0;
+static jmethodID ticketConstructor = 0;
+static jmethodID principalNameConstructor = 0;
+static jmethodID encryptionKeyConstructor = 0;
+static jmethodID ticketFlagsConstructor = 0;
+static jmethodID kerberosTimeConstructor = 0;
+static jmethodID krbcredsConstructor = 0;
+static jmethodID integerConstructor = 0;
+static jmethodID hostAddressConstructor = 0;
+static jmethodID hostAddressesConstructor = 0;
+
+/*
+ * Function prototypes for internal routines
+ */
+
+static jobject BuildTicket(JNIEnv *env, krb5_data *encodedTicket);
+static jobject BuildClientPrincipal(JNIEnv *env, krb5_context kcontext, krb5_principal principalName);
+static jobject BuildEncryptionKey(JNIEnv *env, krb5_keyblock *cryptoKey);
+static jobject BuildTicketFlags(JNIEnv *env, krb5_flags flags);
+static jobject BuildKerberosTime(JNIEnv *env, krb5_timestamp kerbtime);
+static jobject BuildAddressList(JNIEnv *env, krb5_address **kerbtime);
+
+static void printiferr (errcode_t err, const char *format, ...);
+
+static jclass FindClass(JNIEnv *env, char *className)
+{
+    jclass cls = (*env)->FindClass(env, className);
+
+    if (cls == NULL) {
+        printf("Couldn't find %s\n", className);
+        return NULL;
+    }
+#ifdef DEBUG
+    printf("Found %s\n", className);
+#endif /* DEBUG */
+
+    jobject returnValue = (*env)->NewWeakGlobalRef(env,cls);
+    return returnValue;
+}
+/*
+ * Class:     sun_security_krb5_KrbCreds
+ * Method:    JNI_OnLoad
+ */
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
+{
+    JNIEnv *env;
+
+    if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_4)) {
+        return JNI_EVERSION; /* JNI version not supported */
+    }
+
+    ticketClass = FindClass(env, "sun/security/krb5/internal/Ticket");
+    if (ticketClass == NULL) return JNI_ERR;
+
+    principalNameClass = FindClass(env, "sun/security/krb5/PrincipalName");
+    if (principalNameClass == NULL) return JNI_ERR;
+
+    derValueClass = FindClass(env, "sun/security/util/DerValue");
+    if (derValueClass == NULL) return JNI_ERR;
+
+    encryptionKeyClass = FindClass(env, "sun/security/krb5/EncryptionKey");
+    if (encryptionKeyClass == NULL) return JNI_ERR;
+
+    ticketFlagsClass = FindClass(env,"sun/security/krb5/internal/TicketFlags");
+    if (ticketFlagsClass == NULL) return JNI_ERR;
+
+    kerberosTimeClass = FindClass(env,"sun/security/krb5/internal/KerberosTime");
+    if (kerberosTimeClass == NULL) return JNI_ERR;
+
+    javaLangStringClass = FindClass(env,"java/lang/String");
+    if (javaLangStringClass == NULL) return JNI_ERR;
+
+    javaLangIntegerClass = FindClass(env,"java/lang/Integer");
+    if (javaLangIntegerClass == NULL) return JNI_ERR;
+
+    hostAddressClass = FindClass(env,"sun/security/krb5/internal/HostAddress");
+    if (hostAddressClass == NULL) return JNI_ERR;
+
+    hostAddressesClass = FindClass(env,"sun/security/krb5/internal/HostAddresses");
+    if (hostAddressesClass == NULL) return JNI_ERR;
+
+    derValueConstructor = (*env)->GetMethodID(env, derValueClass, "<init>", "([B)V");
+    if (derValueConstructor == 0) {
+        printf("Couldn't find DerValue constructor\n");
+        return JNI_ERR;
+    }
+#ifdef DEBUG
+    printf("Found DerValue constructor\n");
+#endif /* DEBUG */
+
+    ticketConstructor = (*env)->GetMethodID(env, ticketClass, "<init>", "(Lsun/security/util/DerValue;)V");
+    if (derValueConstructor == 0) {
+        printf("Couldn't find Ticket constructor\n");
+        return JNI_ERR;
+    }
+#ifdef DEBUG
+    printf("Found Ticket constructor\n");
+#endif /* DEBUG */
+
+    principalNameConstructor = (*env)->GetMethodID(env, principalNameClass, "<init>", "(Ljava/lang/String;I)V");
+    if (principalNameConstructor == 0) {
+        printf("Couldn't find PrincipalName constructor\n");
+        return JNI_ERR;
+    }
+#ifdef DEBUG
+    printf("Found PrincipalName constructor\n");
+#endif /* DEBUG */
+
+    encryptionKeyConstructor = (*env)->GetMethodID(env, encryptionKeyClass, "<init>", "(I[B)V");
+    if (encryptionKeyConstructor == 0) {
+        printf("Couldn't find EncryptionKey constructor\n");
+        return JNI_ERR;
+    }
+#ifdef DEBUG
+    printf("Found EncryptionKey constructor\n");
+#endif /* DEBUG */
+
+    ticketFlagsConstructor = (*env)->GetMethodID(env, ticketFlagsClass, "<init>", "(I[B)V");
+    if (ticketFlagsConstructor == 0) {
+        printf("Couldn't find TicketFlags constructor\n");
+        return JNI_ERR;
+    }
+#ifdef DEBUG
+    printf("Found TicketFlags constructor\n");
+#endif /* DEBUG */
+
+    kerberosTimeConstructor = (*env)->GetMethodID(env, kerberosTimeClass, "<init>", "(J)V");
+    if (kerberosTimeConstructor == 0) {
+        printf("Couldn't find KerberosTime constructor\n");
+        return JNI_ERR;
+    }
+#ifdef DEBUG
+    printf("Found KerberosTime constructor\n");
+#endif /* DEBUG */
+
+    integerConstructor = (*env)->GetMethodID(env, javaLangIntegerClass, "<init>", "(I)V");
+    if (integerConstructor == 0) {
+        printf("Couldn't find Integer constructor\n");
+        return JNI_ERR;
+    }
+#ifdef DEBUG
+    printf("Found Integer constructor\n");
+#endif /* DEBUG */
+
+    hostAddressConstructor = (*env)->GetMethodID(env, hostAddressClass, "<init>", "(I[B)V");
+    if (hostAddressConstructor == 0) {
+        printf("Couldn't find HostAddress constructor\n");
+        return JNI_ERR;
+    }
+#ifdef DEBUG
+    printf("Found HostAddress constructor\n");
+#endif /* DEBUG */
+
+    hostAddressesConstructor = (*env)->GetMethodID(env, hostAddressesClass, "<init>", "([Lsun/security/krb5/internal/HostAddress;)V");
+    if (hostAddressesConstructor == 0) {
+        printf("Couldn't find HostAddresses constructor\n");
+        return JNI_ERR;
+    }
+#ifdef DEBUG
+    printf("Found HostAddresses constructor\n");
+#endif /* DEBUG */
+
+#ifdef DEBUG
+    printf("Finished OnLoad processing\n");
+#endif /* DEBUG */
+
+    return JNI_VERSION_1_2;
+}
+
+/*
+ * Class:     sun_security_jgss_KrbCreds
+ * Method:    JNI_OnUnload
+ */
+JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved)
+{
+    JNIEnv *env;
+
+    if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
+        return; /* Nothing else we can do */
+    }
+
+    if (ticketClass != NULL) {
+        (*env)->DeleteWeakGlobalRef(env,ticketClass);
+    }
+    if (derValueClass != NULL) {
+        (*env)->DeleteWeakGlobalRef(env,derValueClass);
+    }
+    if (principalNameClass != NULL) {
+        (*env)->DeleteWeakGlobalRef(env,principalNameClass);
+    }
+    if (encryptionKeyClass != NULL) {
+        (*env)->DeleteWeakGlobalRef(env,encryptionKeyClass);
+    }
+    if (ticketFlagsClass != NULL) {
+        (*env)->DeleteWeakGlobalRef(env,ticketFlagsClass);
+    }
+    if (kerberosTimeClass != NULL) {
+        (*env)->DeleteWeakGlobalRef(env,kerberosTimeClass);
+    }
+    if (javaLangStringClass != NULL) {
+        (*env)->DeleteWeakGlobalRef(env,javaLangStringClass);
+    }
+    if (javaLangIntegerClass != NULL) {
+        (*env)->DeleteWeakGlobalRef(env,javaLangIntegerClass);
+    }
+    if (hostAddressClass != NULL) {
+        (*env)->DeleteWeakGlobalRef(env,hostAddressClass);
+    }
+    if (hostAddressesClass != NULL) {
+        (*env)->DeleteWeakGlobalRef(env,hostAddressesClass);
+    }
+
+}
+
+/*
+ * Class:     sun_security_krb5_Credentials
+ * Method:    acquireDefaultNativeCreds
+ * Signature: ()Lsun/security/krb5/Credentials;
+ */
+JNIEXPORT jobject JNICALL Java_sun_security_krb5_Credentials_acquireDefaultNativeCreds
+(JNIEnv *env, jclass krbcredsClass)
+{
+    jobject krbCreds = NULL;
+    krb5_error_code err = 0;
+    krb5_ccache ccache = NULL;
+    krb5_cc_cursor cursor = NULL;
+    krb5_creds creds;
+    krb5_flags flags = 0;
+    krb5_context kcontext = NULL;
+
+    /* Initialize the Kerberos 5 context */
+    err = krb5_init_context (&kcontext);
+
+    if (!err) {
+        err = krb5_cc_default (kcontext, &ccache);
+    }
+
+    if (!err) {
+        err = krb5_cc_set_flags (kcontext, ccache, flags); /* turn off OPENCLOSE */
+    }
+
+    if (!err) {
+        err = krb5_cc_start_seq_get (kcontext, ccache, &cursor);
+    }
+
+    if (!err) {
+        while ((err = krb5_cc_next_cred (kcontext, ccache, &cursor, &creds)) == 0) {
+            char *serverName = NULL;
+
+            if (!err) {
+                err = krb5_unparse_name (kcontext, creds.server, &serverName);
+                printiferr (err, "while unparsing server name");
+            }
+
+            if (!err) {
+                if (strncmp (serverName, "krbtgt", strlen("krbtgt")) == 0) {
+                    jobject ticket, clientPrincipal, targetPrincipal, encryptionKey;
+                    jobject ticketFlags, startTime, endTime;
+                    jobject authTime, renewTillTime, hostAddresses;
+
+                    ticket = clientPrincipal = targetPrincipal = encryptionKey = NULL;
+                    ticketFlags = startTime = endTime = NULL;
+                    authTime = renewTillTime = hostAddresses = NULL;
+
+                    // For the default credentials we're only interested in the krbtgt server.
+                    clientPrincipal = BuildClientPrincipal(env, kcontext, creds.client);
+                    if (clientPrincipal == NULL) goto cleanup;
+
+                    targetPrincipal = BuildClientPrincipal(env, kcontext, creds.server);
+                    if (targetPrincipal == NULL) goto cleanup;
+
+                    // Build a com.ibm.security.krb5.Ticket
+                    ticket = BuildTicket(env, &creds.ticket);
+                    if (ticket == NULL) goto cleanup;
+
+                    // Get the encryption key
+                    encryptionKey = BuildEncryptionKey(env, &creds.keyblock);
+                    if (encryptionKey == NULL) goto cleanup;
+
+                    // and the ticket flags
+                    ticketFlags = BuildTicketFlags(env, creds.ticket_flags);
+                    if (ticketFlags == NULL) goto cleanup;
+
+                    // Get the timestamps out.
+                    startTime = BuildKerberosTime(env, creds.times.starttime);
+                    if (startTime == NULL) goto cleanup;
+
+                    authTime = BuildKerberosTime(env, creds.times.authtime);
+                    if (authTime == NULL) goto cleanup;
+
+                    endTime = BuildKerberosTime(env, creds.times.endtime);
+                    if (endTime == NULL) goto cleanup;
+
+                    renewTillTime = BuildKerberosTime(env, creds.times.renew_till);
+                    if (renewTillTime == NULL) goto cleanup;
+
+                    // Create the addresses object.
+                    hostAddresses = BuildAddressList(env, creds.addresses);
+
+                    if (krbcredsConstructor == 0) {
+                        krbcredsConstructor = (*env)->GetMethodID(env, krbcredsClass, "<init>",
+                                                                  "(Lsun/security/krb5/internal/Ticket;Lsun/security/krb5/PrincipalName;Lsun/security/krb5/PrincipalName;Lsun/security/krb5/EncryptionKey;Lsun/security/krb5/internal/TicketFlags;Lsun/security/krb5/internal/KerberosTime;Lsun/security/krb5/internal/KerberosTime;Lsun/security/krb5/internal/KerberosTime;Lsun/security/krb5/internal/KerberosTime;Lsun/security/krb5/internal/HostAddresses;)V");
+                        if (krbcredsConstructor == 0) {
+                            printf("Couldn't find com.ibm.security.krb5.Credentials constructor\n");
+                            break;
+                        }
+                    }
+
+                    // and now go build a KrbCreds object
+                    krbCreds = (*env)->NewObject(
+                                                 env,
+                                                 krbcredsClass,
+                                                 krbcredsConstructor,
+                                                 ticket,
+                                                 clientPrincipal,
+                                                 targetPrincipal,
+                                                 encryptionKey,
+                                                 ticketFlags,
+                                                 authTime,
+                                                 startTime,
+                                                 endTime,
+                                                 renewTillTime,
+                                                 hostAddresses);
+cleanup:
+                    if (ticket) (*env)->DeleteLocalRef(env, ticket);
+                    if (clientPrincipal) (*env)->DeleteLocalRef(env, clientPrincipal);
+                    if (targetPrincipal) (*env)->DeleteLocalRef(env, targetPrincipal);
+                    if (encryptionKey) (*env)->DeleteLocalRef(env, encryptionKey);
+                    if (ticketFlags) (*env)->DeleteLocalRef(env, ticketFlags);
+                    if (authTime) (*env)->DeleteLocalRef(env, authTime);
+                    if (startTime) (*env)->DeleteLocalRef(env, startTime);
+                    if (endTime) (*env)->DeleteLocalRef(env, endTime);
+                    if (renewTillTime) (*env)->DeleteLocalRef(env, renewTillTime);
+                    if (hostAddresses) (*env)->DeleteLocalRef(env, hostAddresses);
+                }
+
+            }
+
+            if (serverName != NULL) { krb5_free_unparsed_name (kcontext, serverName); }
+
+            krb5_free_cred_contents (kcontext, &creds);
+        }
+
+        if (err == KRB5_CC_END) { err = 0; }
+        printiferr (err, "while retrieving a ticket");
+
+    }
+
+    if (!err) {
+        err = krb5_cc_end_seq_get (kcontext, ccache, &cursor);
+        printiferr (err, "while finishing ticket retrieval");
+    }
+
+    if (!err) {
+        flags = KRB5_TC_OPENCLOSE; /* restore OPENCLOSE mode */
+        err = krb5_cc_set_flags (kcontext, ccache, flags);
+        printiferr (err, "while finishing ticket retrieval");
+    }
+
+    krb5_free_context (kcontext);
+    return krbCreds;
+}
+
+
+#pragma mark -
+
+jobject BuildTicket(JNIEnv *env, krb5_data *encodedTicket)
+{
+    /* To build a Ticket, we first need to build a DerValue out of the EncodedTicket.
+    * But before we can do that, we need to make a byte array out of the ET.
+    */
+
+    jobject derValue, ticket;
+    jbyteArray ary;
+
+    ary = (*env)->NewByteArray(env, encodedTicket->length);
+    if ((*env)->ExceptionOccurred(env)) {
+        return (jobject) NULL;
+    }
+
+    (*env)->SetByteArrayRegion(env, ary, (jsize) 0, encodedTicket->length, (jbyte *)encodedTicket->data);
+    if ((*env)->ExceptionOccurred(env)) {
+        (*env)->DeleteLocalRef(env, ary);
+        return (jobject) NULL;
+    }
+
+    derValue = (*env)->NewObject(env, derValueClass, derValueConstructor, ary);
+    if ((*env)->ExceptionOccurred(env)) {
+        (*env)->DeleteLocalRef(env, ary);
+        return (jobject) NULL;
+    }
+
+    (*env)->DeleteLocalRef(env, ary);
+    ticket = (*env)->NewObject(env, ticketClass, ticketConstructor, derValue);
+    if ((*env)->ExceptionOccurred(env)) {
+        (*env)->DeleteLocalRef(env, derValue);
+        return (jobject) NULL;
+    }
+    (*env)->DeleteLocalRef(env, derValue);
+    return ticket;
+}
+
+jobject BuildClientPrincipal(JNIEnv *env, krb5_context kcontext, krb5_principal principalName) {
+    // Get the full principal string.
+    char *principalString = NULL;
+    jobject principal = NULL;
+    int err = krb5_unparse_name (kcontext, principalName, &principalString);
+
+    if (!err) {
+        // Make a PrincipalName from the full string and the type.  Let the PrincipalName class parse it out.
+        jstring principalStringObj = (*env)->NewStringUTF(env, principalString);
+        principal = (*env)->NewObject(env, principalNameClass, principalNameConstructor, principalStringObj, principalName->type);
+        if (principalString != NULL) { krb5_free_unparsed_name (kcontext, principalString); }
+        (*env)->DeleteLocalRef(env, principalStringObj);
+    }
+
+    return principal;
+}
+
+jobject BuildEncryptionKey(JNIEnv *env, krb5_keyblock *cryptoKey) {
+    // First, need to build a byte array
+    jbyteArray ary;
+    jobject encryptionKey = NULL;
+
+    ary = (*env)->NewByteArray(env,cryptoKey->length);
+    (*env)->SetByteArrayRegion(env, ary, (jsize) 0, cryptoKey->length, (jbyte *)cryptoKey->contents);
+    if (!(*env)->ExceptionOccurred(env)) {
+        encryptionKey = (*env)->NewObject(env, encryptionKeyClass, encryptionKeyConstructor, cryptoKey->enctype, ary);
+    }
+
+    (*env)->DeleteLocalRef(env, ary);
+    return encryptionKey;
+}
+
+jobject BuildTicketFlags(JNIEnv *env, krb5_flags flags) {
+    jobject ticketFlags = NULL;
+    jbyteArray ary;
+
+    /*
+     * Convert the bytes to network byte order before copying
+     * them to a Java byte array.
+     */
+    unsigned long nlflags = htonl(flags);
+
+    ary = (*env)->NewByteArray(env, sizeof(flags));
+    (*env)->SetByteArrayRegion(env, ary, (jsize) 0, sizeof(flags), (jbyte *)&nlflags);
+
+    if (!(*env)->ExceptionOccurred(env)) {
+        ticketFlags = (*env)->NewObject(env, ticketFlagsClass, ticketFlagsConstructor, sizeof(flags)*8, ary);
+    }
+
+    (*env)->DeleteLocalRef(env, ary);
+    return ticketFlags;
+}
+
+jobject BuildKerberosTime(JNIEnv *env, krb5_timestamp kerbtime) {
+    jlong time = kerbtime;
+
+    // Kerberos time is in seconds, but the KerberosTime class assumes milliseconds, so multiply by 1000.
+    time *= 1000;
+    return (*env)->NewObject(env, kerberosTimeClass, kerberosTimeConstructor, time);
+}
+
+jobject BuildAddressList(JNIEnv *env, krb5_address **addresses) {
+
+    if (addresses == NULL) {
+        return NULL;
+    }
+
+    int addressCount = 0;
+
+    // See how many we have.
+    krb5_address **p = addresses;
+
+    while (*p != 0) {
+        addressCount++;
+        p++;
+    }
+
+    jobject address_list = (*env)->NewObjectArray(env, addressCount, hostAddressClass, NULL);
+
+    // Create a new HostAddress object for each address block.
+    // First, reset the iterator.
+    p = addresses;
+    jsize index = 0;
+    while (*p != 0) {
+        krb5_address *currAddress = *p;
+
+        // HostAddres needs a byte array of the host data.
+        jbyteArray ary = (*env)->NewByteArray(env, currAddress->length);
+
+        if (ary == NULL) return NULL;
+
+        (*env)->SetByteArrayRegion(env, ary, (jsize) 0, currAddress->length, (jbyte *)currAddress->contents);
+        jobject address = (*env)->NewObject(env, hostAddressClass, hostAddressConstructor, currAddress->length, ary);
+
+        (*env)->DeleteLocalRef(env, ary);
+
+        // Add the HostAddress to the arrray.
+        (*env)->SetObjectArrayElement(env, address_list, index, address);
+
+        index++;
+        p++;
+    }
+
+    return address_list;
+}
+
+#pragma mark - Utility methods -
+
+static void printiferr (errcode_t err, const char *format, ...)
+{
+    if (err) {
+        va_list pvar;
+
+        va_start (pvar, format);
+        com_err_va ("ticketParser:", err, format, pvar);
+        va_end (pvar);
+    }
+}
+
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/java_md.h b/jdk/src/solaris/bin/java_md.h
index cc72740..ec0615c 100644
--- a/jdk/src/solaris/bin/java_md.h
+++ b/jdk/src/solaris/bin/java_md.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,9 @@
 #ifndef JAVA_MD_H
 #define JAVA_MD_H
 
+/*
+ * This file contains common defines and includes for Solaris, Linux and MacOSX.
+ */
 #include <limits.h>
 #include <unistd.h>
 #include <sys/param.h>
@@ -40,23 +43,25 @@
 #define MAXNAMELEN              PATH_MAX
 #endif
 
-#ifdef HAVE_GETHRTIME
 /*
- * Support for doing cheap, accurate interval timing.
- */
-#include <sys/time.h>
-#define CounterGet()              (gethrtime()/1000)
-#define Counter2Micros(counts)    (counts)
-#else
-#define CounterGet()              (0)
-#define Counter2Micros(counts)    (1)
-#endif /* HAVE_GETHRTIME */
-
-/*
- * Function prototypes.
+ * Common function prototypes and sundries.
  */
 char *LocateJRE(manifest_info *info);
 void ExecJRE(char *jre, char **argv);
 int UnsetEnv(char *name);
+char *FindExecName(char *program);
+const char *SetExecname(char **argv);
+const char *GetExecName();
+static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
+                           char *jvmpath, jint jvmpathsize, const char * arch,
+                           int bitsWanted);
+static jboolean GetJREPath(char *path, jint pathsize, const char * arch,
+                           jboolean speculative);
 
-#endif
+#ifdef MACOSX
+#include "java_md_macosx.h"
+#else  /* !MACOSX */
+#include "java_md_solinux.h"
+#endif /* MACOSX */
+
+#endif /* JAVA_MD_H */
diff --git a/jdk/src/solaris/bin/java_md_common.c b/jdk/src/solaris/bin/java_md_common.c
new file mode 100644
index 0000000..9ed63d1
--- /dev/null
+++ b/jdk/src/solaris/bin/java_md_common.c
@@ -0,0 +1,504 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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.h"
+
+/*
+ * If app is "/foo/bin/javac", or "/foo/bin/sparcv9/javac" then put
+ * "/foo" into buf.
+ */
+jboolean
+GetApplicationHome(char *buf, jint bufsize)
+{
+    const char *execname = GetExecName();
+    if (execname != NULL) {
+        JLI_Snprintf(buf, bufsize, "%s", execname);
+        buf[bufsize-1] = '\0';
+    } else {
+        return JNI_FALSE;
+    }
+
+    if (JLI_StrRChr(buf, '/') == 0) {
+        buf[0] = '\0';
+        return JNI_FALSE;
+    }
+    *(JLI_StrRChr(buf, '/')) = '\0';    /* executable file      */
+    if (JLI_StrLen(buf) < 4 || JLI_StrRChr(buf, '/') == 0) {
+        buf[0] = '\0';
+        return JNI_FALSE;
+    }
+    if (JLI_StrCmp("/bin", buf + JLI_StrLen(buf) - 4) != 0)
+        *(JLI_StrRChr(buf, '/')) = '\0';        /* sparcv9 or amd64     */
+    if (JLI_StrLen(buf) < 4 || JLI_StrCmp("/bin", buf + JLI_StrLen(buf) - 4) != 0) {
+        buf[0] = '\0';
+        return JNI_FALSE;
+    }
+    *(JLI_StrRChr(buf, '/')) = '\0';    /* bin                  */
+
+    return JNI_TRUE;
+}
+/*
+ * Return true if the named program exists
+ */
+static int
+ProgramExists(char *name)
+{
+    struct stat sb;
+    if (stat(name, &sb) != 0) return 0;
+    if (S_ISDIR(sb.st_mode)) return 0;
+    return (sb.st_mode & S_IEXEC) != 0;
+}
+
+/*
+ * Find a command in a directory, returning the path.
+ */
+static char *
+Resolve(char *indir, char *cmd)
+{
+    char name[PATH_MAX + 2], *real;
+
+    if ((JLI_StrLen(indir) + JLI_StrLen(cmd) + 1)  > PATH_MAX) return 0;
+    JLI_Snprintf(name, sizeof(name), "%s%c%s", indir, FILE_SEPARATOR, cmd);
+    if (!ProgramExists(name)) return 0;
+    real = JLI_MemAlloc(PATH_MAX + 2);
+    if (!realpath(name, real))
+        JLI_StrCpy(real, name);
+    return real;
+}
+
+/*
+ * Find a path for the executable
+ */
+char *
+FindExecName(char *program)
+{
+    char cwdbuf[PATH_MAX+2];
+    char *path;
+    char *tmp_path;
+    char *f;
+    char *result = NULL;
+
+    /* absolute path? */
+    if (*program == FILE_SEPARATOR ||
+        (FILE_SEPARATOR=='\\' && JLI_StrRChr(program, ':')))
+        return Resolve("", program+1);
+
+    /* relative path? */
+    if (JLI_StrRChr(program, FILE_SEPARATOR) != 0) {
+        char buf[PATH_MAX+2];
+        return Resolve(getcwd(cwdbuf, sizeof(cwdbuf)), program);
+    }
+
+    /* from search path? */
+    path = getenv("PATH");
+    if (!path || !*path) path = ".";
+    tmp_path = JLI_MemAlloc(JLI_StrLen(path) + 2);
+    JLI_StrCpy(tmp_path, path);
+
+    for (f=tmp_path; *f && result==0; ) {
+        char *s = f;
+        while (*f && (*f != PATH_SEPARATOR)) ++f;
+        if (*f) *f++ = 0;
+        if (*s == FILE_SEPARATOR)
+            result = Resolve(s, program);
+        else {
+            /* relative path element */
+            char dir[2*PATH_MAX];
+            JLI_Snprintf(dir, sizeof(dir), "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)),
+                    FILE_SEPARATOR, s);
+            result = Resolve(dir, program);
+        }
+        if (result != 0) break;
+    }
+
+    JLI_MemFree(tmp_path);
+    return result;
+}
+
+void JLI_ReportErrorMessage(const char* fmt, ...) {
+    va_list vl;
+    va_start(vl, fmt);
+    vfprintf(stderr, fmt, vl);
+    fprintf(stderr, "\n");
+    va_end(vl);
+}
+
+void JLI_ReportErrorMessageSys(const char* fmt, ...) {
+    va_list vl;
+    char *emsg;
+
+    /*
+     * TODO: its safer to use strerror_r but is not available on
+     * Solaris 8. Until then....
+     */
+    emsg = strerror(errno);
+    if (emsg != NULL) {
+        fprintf(stderr, "%s\n", emsg);
+    }
+
+    va_start(vl, fmt);
+    vfprintf(stderr, fmt, vl);
+    fprintf(stderr, "\n");
+    va_end(vl);
+}
+
+void  JLI_ReportExceptionDescription(JNIEnv * env) {
+  (*env)->ExceptionDescribe(env);
+}
+
+/*
+ *      Since using the file system as a registry is a bit risky, perform
+ *      additional sanity checks on the identified directory to validate
+ *      it as a valid jre/sdk.
+ *
+ *      Return 0 if the tests fail; otherwise return non-zero (true).
+ *
+ *      Note that checking for anything more than the existence of an
+ *      executable object at bin/java relative to the path being checked
+ *      will break the regression tests.
+ */
+static int
+CheckSanity(char *path, char *dir)
+{
+    char    buffer[PATH_MAX];
+
+    if (JLI_StrLen(path) + JLI_StrLen(dir) + 11 > PATH_MAX)
+        return (0);     /* Silently reject "impossibly" long paths */
+
+    JLI_Snprintf(buffer, sizeof(buffer), "%s/%s/bin/java", path, dir);
+    return ((access(buffer, X_OK) == 0) ? 1 : 0);
+}
+
+/*
+ *      Determine if there is an acceptable JRE in the directory dirname.
+ *      Upon locating the "best" one, return a fully qualified path to
+ *      it. "Best" is defined as the most advanced JRE meeting the
+ *      constraints contained in the manifest_info. If no JRE in this
+ *      directory meets the constraints, return NULL.
+ *
+ *      Note that we don't check for errors in reading the directory
+ *      (which would be done by checking errno).  This is because it
+ *      doesn't matter if we get an error reading the directory, or
+ *      we just don't find anything interesting in the directory.  We
+ *      just return NULL in either case.
+ *
+ *      The historical names of j2sdk and j2re were changed to jdk and
+ *      jre respecively as part of the 1.5 rebranding effort.  Since the
+ *      former names are legacy on Linux, they must be recognized for
+ *      all time.  Fortunately, this is a minor cost.
+ */
+static char
+*ProcessDir(manifest_info *info, char *dirname)
+{
+    DIR     *dirp;
+    struct dirent *dp;
+    char    *best = NULL;
+    int     offset;
+    int     best_offset = 0;
+    char    *ret_str = NULL;
+    char    buffer[PATH_MAX];
+
+    if ((dirp = opendir(dirname)) == NULL)
+        return (NULL);
+
+    do {
+        if ((dp = readdir(dirp)) != NULL) {
+            offset = 0;
+            if ((JLI_StrNCmp(dp->d_name, "jre", 3) == 0) ||
+                (JLI_StrNCmp(dp->d_name, "jdk", 3) == 0))
+                offset = 3;
+            else if (JLI_StrNCmp(dp->d_name, "j2re", 4) == 0)
+                offset = 4;
+            else if (JLI_StrNCmp(dp->d_name, "j2sdk", 5) == 0)
+                offset = 5;
+            if (offset > 0) {
+                if ((JLI_AcceptableRelease(dp->d_name + offset,
+                    info->jre_version)) && CheckSanity(dirname, dp->d_name))
+                    if ((best == NULL) || (JLI_ExactVersionId(
+                      dp->d_name + offset, best + best_offset) > 0)) {
+                        if (best != NULL)
+                            JLI_MemFree(best);
+                        best = JLI_StringDup(dp->d_name);
+                        best_offset = offset;
+                    }
+            }
+        }
+    } while (dp != NULL);
+    (void) closedir(dirp);
+    if (best == NULL)
+        return (NULL);
+    else {
+        ret_str = JLI_MemAlloc(JLI_StrLen(dirname) + JLI_StrLen(best) + 2);
+        sprintf(ret_str, "%s/%s", dirname, best);
+        JLI_MemFree(best);
+        return (ret_str);
+    }
+}
+
+/*
+ *      This is the global entry point. It examines the host for the optimal
+ *      JRE to be used by scanning a set of directories.  The set of directories
+ *      is platform dependent and can be overridden by the environment
+ *      variable JAVA_VERSION_PATH.
+ *
+ *      This routine itself simply determines the set of appropriate
+ *      directories before passing control onto ProcessDir().
+ */
+char*
+LocateJRE(manifest_info* info)
+{
+    char        *path;
+    char        *home;
+    char        *target = NULL;
+    char        *dp;
+    char        *cp;
+
+    /*
+     * Start by getting JAVA_VERSION_PATH
+     */
+    if (info->jre_restrict_search) {
+        path = JLI_StringDup(system_dir);
+    } else if ((path = getenv("JAVA_VERSION_PATH")) != NULL) {
+        path = JLI_StringDup(path);
+    } else {
+        if ((home = getenv("HOME")) != NULL) {
+            path = (char *)JLI_MemAlloc(JLI_StrLen(home) + \
+                        JLI_StrLen(system_dir) + JLI_StrLen(user_dir) + 2);
+            sprintf(path, "%s%s:%s", home, user_dir, system_dir);
+        } else {
+            path = JLI_StringDup(system_dir);
+        }
+    }
+
+    /*
+     * Step through each directory on the path. Terminate the scan with
+     * the first directory with an acceptable JRE.
+     */
+    cp = dp = path;
+    while (dp != NULL) {
+        cp = JLI_StrChr(dp, (int)':');
+        if (cp != NULL)
+            *cp = '\0';
+        if ((target = ProcessDir(info, dp)) != NULL)
+            break;
+        dp = cp;
+        if (dp != NULL)
+            dp++;
+    }
+    JLI_MemFree(path);
+    return (target);
+}
+
+/*
+ * Given a path to a jre to execute, this routine checks if this process
+ * is indeed that jre.  If not, it exec's that jre.
+ *
+ * We want to actually check the paths rather than just the version string
+ * built into the executable, so that given version specification (and
+ * JAVA_VERSION_PATH) will yield the exact same Java environment, regardless
+ * of the version of the arbitrary launcher we start with.
+ */
+void
+ExecJRE(char *jre, char **argv)
+{
+    char    wanted[PATH_MAX];
+    const char* progname = GetProgramName();
+    const char* execname = NULL;
+
+    /*
+     * Resolve the real path to the directory containing the selected JRE.
+     */
+    if (realpath(jre, wanted) == NULL) {
+        JLI_ReportErrorMessage(JRE_ERROR9, jre);
+        exit(1);
+    }
+
+    /*
+     * Resolve the real path to the currently running launcher.
+     */
+    SetExecname(argv);
+    execname = GetExecName();
+    if (execname == NULL) {
+        JLI_ReportErrorMessage(JRE_ERROR10);
+        exit(1);
+    }
+
+    /*
+     * If the path to the selected JRE directory is a match to the initial
+     * portion of the path to the currently executing JRE, we have a winner!
+     * If so, just return.
+     */
+    if (JLI_StrNCmp(wanted, execname, JLI_StrLen(wanted)) == 0)
+        return;                 /* I am the droid you were looking for */
+
+
+    /*
+     * This should never happen (because of the selection code in SelectJRE),
+     * but check for "impossibly" long path names just because buffer overruns
+     * can be so deadly.
+     */
+    if (JLI_StrLen(wanted) + JLI_StrLen(progname) + 6 > PATH_MAX) {
+        JLI_ReportErrorMessage(JRE_ERROR11);
+        exit(1);
+    }
+
+    /*
+     * Construct the path and exec it.
+     */
+    (void)JLI_StrCat(JLI_StrCat(wanted, "/bin/"), progname);
+    argv[0] = JLI_StringDup(progname);
+    if (JLI_IsTraceLauncher()) {
+        int i;
+        printf("ReExec Command: %s (%s)\n", wanted, argv[0]);
+        printf("ReExec Args:");
+        for (i = 1; argv[i] != NULL; i++)
+            printf(" %s", argv[i]);
+        printf("\n");
+    }
+    JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n");
+    (void)fflush(stdout);
+    (void)fflush(stderr);
+    execv(wanted, argv);
+    JLI_ReportErrorMessageSys(JRE_ERROR12, wanted);
+    exit(1);
+}
+
+/*
+ * "Borrowed" from Solaris 10 where the unsetenv() function is being added
+ * to libc thanks to SUSv3 (Standard Unix Specification, version 3). As
+ * such, in the fullness of time this will appear in libc on all relevant
+ * Solaris/Linux platforms and maybe even the Windows platform.  At that
+ * time, this stub can be removed.
+ *
+ * This implementation removes the environment locking for multithreaded
+ * applications.  (We don't have access to these mutexes within libc and
+ * the launcher isn't multithreaded.)  Note that what remains is platform
+ * independent, because it only relies on attributes that a POSIX environment
+ * defines.
+ *
+ * Returns 0 on success, -1 on failure.
+ *
+ * Also removed was the setting of errno.  The only value of errno set
+ * was EINVAL ("Invalid Argument").
+ */
+
+/*
+ * s1(environ) is name=value
+ * s2(name) is name(not the form of name=value).
+ * if names match, return value of 1, else return 0
+ */
+static int
+match_noeq(const char *s1, const char *s2)
+{
+        while (*s1 == *s2++) {
+                if (*s1++ == '=')
+                        return (1);
+        }
+        if (*s1 == '=' && s2[-1] == '\0')
+                return (1);
+        return (0);
+}
+
+/*
+ * added for SUSv3 standard
+ *
+ * Delete entry from environ.
+ * Do not free() memory!  Other threads may be using it.
+ * Keep it around forever.
+ */
+static int
+borrowed_unsetenv(const char *name)
+{
+        long    idx;            /* index into environ */
+
+        if (name == NULL || *name == '\0' ||
+            JLI_StrChr(name, '=') != NULL) {
+                return (-1);
+        }
+
+        for (idx = 0; environ[idx] != NULL; idx++) {
+                if (match_noeq(environ[idx], name))
+                        break;
+        }
+        if (environ[idx] == NULL) {
+                /* name not found but still a success */
+                return (0);
+        }
+        /* squeeze up one entry */
+        do {
+                environ[idx] = environ[idx+1];
+        } while (environ[++idx] != NULL);
+
+        return (0);
+}
+/* --- End of "borrowed" code --- */
+
+/*
+ * Wrapper for unsetenv() function.
+ */
+int
+UnsetEnv(char *name)
+{
+    return(borrowed_unsetenv(name));
+}
+
+const char *
+jlong_format_specifier() {
+    return "%lld";
+}
+
+jboolean
+IsJavaw()
+{
+    /* noop on UNIX */
+    return JNI_FALSE;
+}
+
+void
+InitLauncher(jboolean javaw)
+{
+    JLI_SetTraceLauncher();
+}
+
+/*
+ * The implementation for finding classes from the bootstrap
+ * class loader, refer to java.h
+ */
+static FindClassFromBootLoader_t *findBootClass = NULL;
+
+jclass
+FindBootStrapClass(JNIEnv *env, const char* classname)
+{
+   if (findBootClass == NULL) {
+       findBootClass = (FindClassFromBootLoader_t *)dlsym(RTLD_DEFAULT,
+          "JVM_FindClassFromBootLoader");
+       if (findBootClass == NULL) {
+           JLI_ReportErrorMessage(DLL_ERROR4,
+               "JVM_FindClassFromBootLoader");
+           return NULL;
+       }
+   }
+   return findBootClass(env, classname);
+}
+
diff --git a/jdk/src/solaris/bin/java_md_solinux.c b/jdk/src/solaris/bin/java_md_solinux.c
new file mode 100644
index 0000000..fc8bc99
--- /dev/null
+++ b/jdk/src/solaris/bin/java_md_solinux.c
@@ -0,0 +1,1066 @@
+/*
+ * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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.h"
+#include "jvm_md.h"
+#include <dirent.h>
+#include <dlfcn.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include "manifest_info.h"
+#include "version_comp.h"
+
+
+#define JVM_DLL "libjvm.so"
+#define JAVA_DLL "libjava.so"
+#define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
+
+/* help jettison the LD_LIBRARY_PATH settings in the future */
+#ifndef SETENV_REQUIRED
+#define SETENV_REQUIRED
+#endif
+/*
+ * If a processor / os combination has the ability to run binaries of
+ * two data models and cohabitation of jre/jdk bits with both data
+ * models is supported, then DUAL_MODE is defined.  When DUAL_MODE is
+ * defined, the architecture names for the narrow and wide version of
+ * the architecture are defined in LIBARCH64NAME and LIBARCH32NAME.
+ * Currently  only Solaris on sparc/sparcv9 and i586/amd64 is DUAL_MODE;
+ * linux i586/amd64 could be defined as DUAL_MODE but that is not the
+ * current policy.
+ */
+
+#ifdef __solaris__
+#  define DUAL_MODE
+#  ifndef LIBARCH32NAME
+#    error "The macro LIBARCH32NAME was not defined on the compile line"
+#  endif
+#  ifndef LIBARCH64NAME
+#    error "The macro LIBARCH64NAME was not defined on the compile line"
+#  endif
+#  include <sys/systeminfo.h>
+#  include <sys/elf.h>
+#  include <stdio.h>
+#endif
+
+/*
+ * Flowchart of launcher execs and options processing on unix
+ *
+ * The selection of the proper vm shared library to open depends on
+ * several classes of command line options, including vm "flavor"
+ * options (-client, -server) and the data model options, -d32  and
+ * -d64, as well as a version specification which may have come from
+ * the command line or from the manifest of an executable jar file.
+ * The vm selection options are not passed to the running
+ * virtual machine; they must be screened out by the launcher.
+ *
+ * The version specification (if any) is processed first by the
+ * platform independent routine SelectVersion.  This may result in
+ * the exec of the specified launcher version.
+ *
+ * Previously the launcher modified the LD_LIBRARY_PATH appropriately for the
+ * desired data model path, regardless if data models matched or not. The
+ * launcher subsequently exec'ed the desired executable, in order to make the
+ * LD_LIBRARY_PATH path available, for the runtime linker.
+ *
+ * Now, in most cases,the launcher will dlopen the target libjvm.so. All
+ * required libraries are loaded by the runtime linker, using the
+ * $RPATH/$ORIGIN baked into the shared libraries at compile time. Therefore,
+ * in most cases, the launcher will only exec, if the data models are
+ * mismatched, and will not set any environment variables, regardless of the
+ * data models.
+ *
+ * However, if the environment contains a LD_LIBRARY_PATH, this will cause the
+ * launcher to inspect the LD_LIBRARY_PATH. The launcher will check
+ *  a. if the LD_LIBRARY_PATH's first component is the the path to the desired
+ *     libjvm.so
+ *  b. if any other libjvm.so is found in any of the paths.
+ * If case b is true, then the launcher will set the LD_LIBRARY_PATH to the
+ * desired JRE and reexec, in order to propagate the environment.
+ *
+ *  Main
+ *  (incoming argv)
+ *  |
+ * \|/
+ * SelectVersion
+ * (selects the JRE version, note: not data model)
+ *  |
+ * \|/
+ * CreateExecutionEnvironment
+ * (determines desired data model)
+ *  |
+ *  |
+ * \|/
+ *  Have Desired Model ? --> NO --> Is Dual-Mode ? --> NO --> Exit(with error)
+ *  |                                          |
+ *  |                                          |
+ *  |                                         \|/
+ *  |                                         YES
+ *  |                                          |
+ *  |                                          |
+ *  |                                         \|/
+ *  |                                CheckJvmType
+ *  |                               (removes -client, -server etc.)
+ *  |                                          |
+ *  |                                          |
+ * \|/                                        \|/
+ * YES                             Find the desired executable/library
+ *  |                                          |
+ *  |                                          |
+ * \|/                                        \|/
+ * CheckJvmType                          RequiresSetenv
+ * (removes -client, -server, etc.)
+ *  |
+ *  |
+ * \|/
+ * TranslateDashJArgs...
+ * (Prepare to pass args to vm)
+ *  |
+ *  |
+ * \|/
+ * ParseArguments
+ * (removes -d32 and -d64 if any,
+ *  processes version options,
+ *  creates argument list for vm,
+ *  etc.)
+ *   |
+ *   |
+ *  \|/
+ * RequiresSetenv
+ * Is LD_LIBRARY_PATH
+ * and friends set ? --> NO --> Have Desired Model ? NO --> Re-exec --> Main
+ *  YES                              YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ * Path is desired JRE ? YES --> Have Desired Model ? NO --> Re-exec --> Main
+ *  NO                               YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ * Paths have well known
+ * jvm paths ?       --> NO --> Have Desired Model ? NO --> Re-exec --> Main
+ *  YES                              YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ *  Does libjvm.so exit
+ *  in any of them ? --> NO --> Have Desired Model ? NO --> Re-exec --> Main
+ *   YES                             YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ *  Set the LD_LIBRARY_PATH
+ *   |
+ *   |
+ *  \|/
+ * Re-exec
+ *   |
+ *   |
+ *  \|/
+ * Main
+ */
+
+#define GetArch() GetArchPath(CURRENT_DATA_MODEL)
+
+/* Store the name of the executable once computed */
+static char *execname = NULL;
+
+/*
+ * execname accessor from other parts of platform dependent logic
+ */
+const char *
+GetExecName() {
+    return execname;
+}
+
+const char *
+GetArchPath(int nbits)
+{
+    switch(nbits) {
+#ifdef DUAL_MODE
+        case 32:
+            return LIBARCH32NAME;
+        case 64:
+            return LIBARCH64NAME;
+#endif /* DUAL_MODE */
+        default:
+            return LIBARCHNAME;
+    }
+}
+
+#ifdef SETENV_REQUIRED
+static jboolean
+JvmExists(const char *path) {
+    char tmp[PATH_MAX + 1];
+    struct stat statbuf;
+    JLI_Snprintf(tmp, PATH_MAX, "%s/%s", path, JVM_DLL);
+    if (stat(tmp, &statbuf) == 0) {
+        return JNI_TRUE;
+    }
+    return JNI_FALSE;
+}
+/*
+ * contains a lib/$LIBARCH/{server,client}/libjvm.so ?
+ */
+static jboolean
+ContainsLibJVM(int wanted, const char *env) {
+    char clientPattern[PATH_MAX + 1];
+    char serverPattern[PATH_MAX + 1];
+    char *envpath;
+    char *path;
+    jboolean clientPatternFound;
+    jboolean serverPatternFound;
+
+    /* fastest path */
+    if (env == NULL) {
+        return JNI_FALSE;
+    }
+
+    /* the usual suspects */
+    JLI_Snprintf(clientPattern, PATH_MAX, "lib/%s/client", GetArchPath(wanted));
+    JLI_Snprintf(serverPattern, PATH_MAX, "lib/%s/server", GetArchPath(wanted));
+
+    /* to optimize for time, test if any of our usual suspects are present. */
+    clientPatternFound = JLI_StrStr(env, clientPattern) != NULL;
+    serverPatternFound = JLI_StrStr(env, serverPattern) != NULL;
+    if (clientPatternFound == JNI_FALSE && serverPatternFound == JNI_FALSE) {
+        return JNI_FALSE;
+    }
+
+    /*
+     * we have a suspicious path component, check if it contains a libjvm.so
+     */
+    envpath = JLI_StringDup(env);
+    for (path = JLI_StrTok(envpath, ":"); path != NULL; path = JLI_StrTok(NULL, ":")) {
+        if (clientPatternFound && JLI_StrStr(path, clientPattern) != NULL) {
+            if (JvmExists(path)) {
+                JLI_MemFree(envpath);
+                return JNI_TRUE;
+            }
+        }
+        if (serverPatternFound && JLI_StrStr(path, serverPattern)  != NULL) {
+            if (JvmExists(path)) {
+                JLI_MemFree(envpath);
+                return JNI_TRUE;
+            }
+        }
+    }
+    JLI_MemFree(envpath);
+    return JNI_FALSE;
+}
+
+/*
+ * Test whether the environment variable needs to be set, see flowchart.
+ */
+static jboolean
+RequiresSetenv(int wanted, const char *jvmpath) {
+    char jpath[PATH_MAX + 1];
+    char *llp;
+    char *dmllp = NULL;
+    char *p; /* a utility pointer */
+
+    llp = getenv("LD_LIBRARY_PATH");
+#ifdef __solaris__
+    dmllp = (CURRENT_DATA_MODEL == 32)
+            ? getenv("LD_LIBRARY_PATH_32")
+            : getenv("LD_LIBRARY_PATH_64");
+#endif /* __solaris__ */
+    /* no environment variable is a good environment variable */
+    if (llp == NULL && dmllp == NULL) {
+        return JNI_FALSE;
+    }
+#ifdef __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 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, here and further downstream. Therefore, if we are running sgid or
+     * suid, this function's setting of LD_LIBRARY_PATH will be ineffective and
+     * we should case a return from the calling function.  Getting the right
+     * libraries will be handled by the RPATH. In reality, this check is
+     * redundant, as the previous check for a non-null LD_LIBRARY_PATH will
+     * return back to the calling function forthwith, it is left here to safe
+     * guard against any changes, in the glibc's existing security policy.
+     */
+    if ((getgid() != getegid()) || (getuid() != geteuid())) {
+        return JNI_FALSE;
+    }
+#endif /* __linux */
+
+    /*
+     * Prevent recursions. Since LD_LIBRARY_PATH is the one which will be set by
+     * previous versions of the JRE, thus it is the only path that matters here.
+     * So we check to see if the desired JRE is set.
+     */
+    JLI_StrNCpy(jpath, jvmpath, PATH_MAX);
+    p = JLI_StrRChr(jpath, '/');
+    *p = '\0';
+    if (llp != NULL && JLI_StrNCmp(llp, jpath, JLI_StrLen(jpath)) == 0) {
+        return JNI_FALSE;
+    }
+
+    /* scrutinize all the paths further */
+    if (llp != NULL &&  ContainsLibJVM(wanted, llp)) {
+        return JNI_TRUE;
+    }
+    if (dmllp != NULL && ContainsLibJVM(wanted, dmllp)) {
+        return JNI_TRUE;
+    }
+    return JNI_FALSE;
+}
+#endif /* SETENV_REQUIRED */
+
+void
+CreateExecutionEnvironment(int *pargc, char ***pargv,
+                           char jrepath[], jint so_jrepath,
+                           char jvmpath[], jint so_jvmpath,
+                           char jvmcfg[],  jint so_jvmcfg) {
+  /*
+   * First, determine if we are running the desired data model.  If we
+   * are running the desired data model, all the error messages
+   * associated with calling GetJREPath, ReadKnownVMs, etc. should be
+   * output.  However, if we are not running the desired data model,
+   * some of the errors should be suppressed since it is more
+   * informative to issue an error message based on whether or not the
+   * os/processor combination has dual mode capabilities.
+   */
+    jboolean jvmpathExists;
+
+    /* Compute/set the name of the executable */
+    SetExecname(*pargv);
+
+    /* Check data model flags, and exec process, if needed */
+    {
+      char *arch        = (char *)GetArch(); /* like sparc or sparcv9 */
+      char * jvmtype    = NULL;
+      int  argc         = *pargc;
+      char **argv       = *pargv;
+      int running       = CURRENT_DATA_MODEL;
+
+      int wanted        = running;      /* What data mode is being
+                                           asked for? Current model is
+                                           fine unless another model
+                                           is asked for */
+#ifdef SETENV_REQUIRED
+      jboolean mustsetenv = JNI_FALSE;
+      char *runpath     = NULL; /* existing effective LD_LIBRARY_PATH setting */
+      char* new_runpath = NULL; /* desired new LD_LIBRARY_PATH string */
+      char* newpath     = NULL; /* path on new LD_LIBRARY_PATH */
+      char* lastslash   = NULL;
+      char** newenvp    = NULL; /* current environment */
+#ifdef __solaris__
+      char*  dmpath     = NULL;  /* data model specific LD_LIBRARY_PATH,
+                                    Solaris only */
+#endif /* __solaris__ */
+#endif  /* SETENV_REQUIRED */
+
+      char** newargv    = NULL;
+      int    newargc    = 0;
+
+      /*
+       * Starting in 1.5, all unix platforms accept the -d32 and -d64
+       * options.  On platforms where only one data-model is supported
+       * (e.g. ia-64 Linux), using the flag for the other data model is
+       * an error and will terminate the program.
+       */
+
+      { /* open new scope to declare local variables */
+        int i;
+
+        newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*));
+        newargv[newargc++] = argv[0];
+
+        /* scan for data model arguments and remove from argument list;
+           last occurrence determines desired data model */
+        for (i=1; i < argc; i++) {
+
+          if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) {
+            wanted = 64;
+            continue;
+          }
+          if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) {
+            wanted = 32;
+            continue;
+          }
+          newargv[newargc++] = argv[i];
+
+          if (IsJavaArgs()) {
+            if (argv[i][0] != '-') continue;
+          } else {
+            if (JLI_StrCmp(argv[i], "-classpath") == 0 || JLI_StrCmp(argv[i], "-cp") == 0) {
+              i++;
+              if (i >= argc) break;
+              newargv[newargc++] = argv[i];
+              continue;
+            }
+            if (argv[i][0] != '-') { i++; break; }
+          }
+        }
+
+        /* copy rest of args [i .. argc) */
+        while (i < argc) {
+          newargv[newargc++] = argv[i++];
+        }
+        newargv[newargc] = NULL;
+
+        /*
+         * newargv has all proper arguments here
+         */
+
+        argc = newargc;
+        argv = newargv;
+      }
+
+      /* If the data model is not changing, it is an error if the
+         jvmpath does not exist */
+      if (wanted == running) {
+        /* Find out where the JRE is that we will be using. */
+        if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) {
+          JLI_ReportErrorMessage(JRE_ERROR1);
+          exit(2);
+        }
+        JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg",
+                     jrepath, FILESEP, FILESEP,  arch, FILESEP);
+        /* Find the specified JVM type */
+        if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) {
+          JLI_ReportErrorMessage(CFG_ERROR7);
+          exit(1);
+        }
+
+        jvmpath[0] = '\0';
+        jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
+        if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
+            JLI_ReportErrorMessage(CFG_ERROR9);
+            exit(4);
+        }
+
+        if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch, 0 )) {
+          JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
+          exit(4);
+        }
+        /*
+         * we seem to have everything we need, so without further ado
+         * we return back, otherwise proceed to set the environment.
+         */
+#ifdef SETENV_REQUIRED
+        mustsetenv = RequiresSetenv(wanted, jvmpath);
+        JLI_TraceLauncher("mustsetenv: %s\n", mustsetenv ? "TRUE" : "FALSE");
+
+        if (mustsetenv == JNI_FALSE) {
+            return;
+        }
+#else
+        return;
+#endif /* SETENV_REQUIRED */
+      } else {  /* do the same speculatively or exit */
+#ifdef DUAL_MODE
+        if (running != wanted) {
+          /* Find out where the JRE is that we will be using. */
+          if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) {
+            /* give up and let other code report error message */
+            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
+            exit(1);
+          }
+          JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg",
+                       jrepath, FILESEP, FILESEP, GetArchPath(wanted), FILESEP);
+          /*
+           * Read in jvm.cfg for target data model and process vm
+           * selection options.
+           */
+          if (ReadKnownVMs(jvmcfg, JNI_TRUE) < 1) {
+            /* give up and let other code report error message */
+            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
+            exit(1);
+          }
+          jvmpath[0] = '\0';
+          jvmtype = CheckJvmType(pargc, pargv, JNI_TRUE);
+          if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
+            JLI_ReportErrorMessage(CFG_ERROR9);
+            exit(4);
+          }
+
+          /* exec child can do error checking on the existence of the path */
+          jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted), 0);
+#ifdef SETENV_REQUIRED
+          mustsetenv = RequiresSetenv(wanted, jvmpath);
+#endif /* SETENV_REQUIRED */
+        }
+#else /* ! DUALMODE */
+        JLI_ReportErrorMessage(JRE_ERROR2, wanted);
+        exit(1);
+#endif /* DUAL_MODE */
+        }
+#ifdef SETENV_REQUIRED
+        if (mustsetenv) {
+            /*
+             * We will set the LD_LIBRARY_PATH as follows:
+             *
+             *     o          $JVMPATH (directory portion only)
+             *     o          $JRE/lib/$LIBARCHNAME
+             *     o          $JRE/../lib/$LIBARCHNAME
+             *
+             * followed by the user's previous effective LD_LIBRARY_PATH, if
+             * any.
+             */
+
+#ifdef __solaris__
+            /*
+             * Starting in Solaris 7, ld.so.1 supports three LD_LIBRARY_PATH
+             * variables:
+             *
+             * 1. LD_LIBRARY_PATH -- used for 32 and 64 bit searches if
+             * data-model specific variables are not set.
+             *
+             * 2. LD_LIBRARY_PATH_64 -- overrides and replaces LD_LIBRARY_PATH
+             * for 64-bit binaries.
+             *
+             * 3. LD_LIBRARY_PATH_32 -- overrides and replaces LD_LIBRARY_PATH
+             * for 32-bit binaries.
+             *
+             * The vm uses LD_LIBRARY_PATH to set the java.library.path system
+             * property.  To shield the vm from the complication of multiple
+             * LD_LIBRARY_PATH variables, if the appropriate data model
+             * specific variable is set, we will act as if LD_LIBRARY_PATH had
+             * the value of the data model specific variant and the data model
+             * specific variant will be unset.  Note that the variable for the
+             * *wanted* data model must be used (if it is set), not simply the
+             * current running data model.
+             */
+
+            switch (wanted) {
+                case 0:
+                    if (running == 32) {
+                        dmpath = getenv("LD_LIBRARY_PATH_32");
+                        wanted = 32;
+                    } else {
+                        dmpath = getenv("LD_LIBRARY_PATH_64");
+                        wanted = 64;
+                    }
+                    break;
+
+                case 32:
+                    dmpath = getenv("LD_LIBRARY_PATH_32");
+                    break;
+
+                case 64:
+                    dmpath = getenv("LD_LIBRARY_PATH_64");
+                    break;
+
+                default:
+                    JLI_ReportErrorMessage(JRE_ERROR3, __LINE__);
+                    exit(1); /* unknown value in wanted */
+                    break;
+            }
+
+            /*
+             * If dmpath is NULL, the relevant data model specific variable is
+             * not set and normal LD_LIBRARY_PATH should be used.
+             */
+            if (dmpath == NULL) {
+                runpath = getenv("LD_LIBRARY_PATH");
+            } else {
+                runpath = dmpath;
+            }
+#else /* ! __solaris__ */
+            /*
+             * If not on Solaris, assume only a single LD_LIBRARY_PATH
+             * variable.
+             */
+            runpath = getenv("LD_LIBRARY_PATH");
+#endif /* __solaris__ */
+
+            /* runpath contains current effective LD_LIBRARY_PATH setting */
+
+            jvmpath = JLI_StringDup(jvmpath);
+            new_runpath = JLI_MemAlloc(((runpath != NULL) ? JLI_StrLen(runpath) : 0) +
+                    2 * JLI_StrLen(jrepath) + 2 * JLI_StrLen(arch) +
+                    JLI_StrLen(jvmpath) + 52);
+            newpath = new_runpath + JLI_StrLen("LD_LIBRARY_PATH=");
+
+
+            /*
+             * Create desired LD_LIBRARY_PATH value for target data model.
+             */
+            {
+                /* remove the name of the .so from the JVM path */
+                lastslash = JLI_StrRChr(jvmpath, '/');
+                if (lastslash)
+                    *lastslash = '\0';
+
+                sprintf(new_runpath, "LD_LIBRARY_PATH="
+                        "%s:"
+                        "%s/lib/%s:"
+                        "%s/../lib/%s",
+                        jvmpath,
+#ifdef DUAL_MODE
+                        jrepath, GetArchPath(wanted),
+                        jrepath, GetArchPath(wanted)
+#else /* !DUAL_MODE */
+                        jrepath, arch,
+                        jrepath, arch
+#endif /* DUAL_MODE */
+                        );
+
+
+                /*
+                 * Check to make sure that the prefix of the current path is the
+                 * desired environment variable setting, though the RequiresSetenv
+                 * checks if the desired runpath exists, this logic does a more
+                 * comprehensive check.
+                 */
+                if (runpath != NULL &&
+                        JLI_StrNCmp(newpath, runpath, JLI_StrLen(newpath)) == 0 &&
+                        (runpath[JLI_StrLen(newpath)] == 0 || runpath[JLI_StrLen(newpath)] == ':') &&
+                        (running == wanted) /* data model does not have to be changed */
+#ifdef __solaris__
+                        && (dmpath == NULL) /* data model specific variables not set  */
+#endif /* __solaris__ */
+                        ) {
+
+                    return;
+
+                }
+            }
+
+            /*
+             * Place the desired environment setting onto the prefix of
+             * LD_LIBRARY_PATH.  Note that this prevents any possible infinite
+             * loop of execv() because we test for the prefix, above.
+             */
+            if (runpath != 0) {
+                JLI_StrCat(new_runpath, ":");
+                JLI_StrCat(new_runpath, runpath);
+            }
+
+            if (putenv(new_runpath) != 0) {
+                exit(1); /* problem allocating memory; LD_LIBRARY_PATH not set
+                    properly */
+            }
+
+            /*
+             * Unix systems document that they look at LD_LIBRARY_PATH only
+             * once at startup, so we have to re-exec the current executable
+             * to get the changed environment variable to have an effect.
+             */
+
+#ifdef __solaris__
+            /*
+             * If dmpath is not NULL, remove the data model specific string
+             * in the environment for the exec'ed child.
+             */
+            if (dmpath != NULL)
+                (void)UnsetEnv((wanted == 32) ? "LD_LIBRARY_PATH_32" : "LD_LIBRARY_PATH_64");
+#endif /* __solaris */
+
+            newenvp = environ;
+        }
+#endif /* SETENV_REQUIRED */
+        {
+            char *newexec = execname;
+#ifdef DUAL_MODE
+            /*
+             * If the data model is being changed, the path to the
+             * executable must be updated accordingly; the executable name
+             * and directory the executable resides in are separate.  In the
+             * case of 32 => 64, the new bits are assumed to reside in, e.g.
+             * "olddir/LIBARCH64NAME/execname"; in the case of 64 => 32,
+             * the bits are assumed to be in "olddir/../execname".  For example,
+             *
+             * olddir/sparcv9/execname
+             * olddir/amd64/execname
+             *
+             * for Solaris SPARC and Linux amd64, respectively.
+             */
+
+            if (running != wanted) {
+                char *oldexec = JLI_StrCpy(JLI_MemAlloc(JLI_StrLen(execname) + 1), execname);
+                char *olddir = oldexec;
+                char *oldbase = JLI_StrRChr(oldexec, '/');
+
+
+                newexec = JLI_MemAlloc(JLI_StrLen(execname) + 20);
+                *oldbase++ = 0;
+                sprintf(newexec, "%s/%s/%s", olddir,
+                        ((wanted == 64) ? LIBARCH64NAME : ".."), oldbase);
+                argv[0] = newexec;
+            }
+#endif /* DUAL_MODE */
+            JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n");
+            (void) fflush(stdout);
+            (void) fflush(stderr);
+#ifdef SETENV_REQUIRED
+            if (mustsetenv) {
+                execve(newexec, argv, newenvp);
+            } else {
+                execv(newexec, argv);
+            }
+#else /* !SETENV_REQUIRED */
+            execv(newexec, argv);
+#endif /* SETENV_REQUIRED */
+            JLI_ReportErrorMessageSys(JRE_ERROR4, newexec);
+
+#ifdef DUAL_MODE
+            if (running != wanted) {
+                JLI_ReportErrorMessage(JRE_ERROR5, wanted, running);
+#ifdef __solaris__
+#ifdef __sparc
+                JLI_ReportErrorMessage(JRE_ERROR6);
+#else  /* ! __sparc__ */
+                JLI_ReportErrorMessage(JRE_ERROR7);
+#endif  /* __sparc */
+#endif /* __solaris__ */
+            }
+#endif /* DUAL_MODE */
+
+        }
+        exit(1);
+    }
+}
+
+/*
+ * On Solaris VM choosing is done by the launcher (java.c),
+ * bitsWanted is used by MacOSX,  on Solaris and Linux this.
+ * parameter is unused.
+ */
+static jboolean
+GetJVMPath(const char *jrepath, const char *jvmtype,
+           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 {
+        JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype);
+    }
+
+    JLI_TraceLauncher("Does `%s' exist ... ", jvmpath);
+
+    if (stat(jvmpath, &s) == 0) {
+        JLI_TraceLauncher("yes.\n");
+        return JNI_TRUE;
+    } else {
+        JLI_TraceLauncher("no.\n");
+        return JNI_FALSE;
+    }
+}
+
+/*
+ * Find path to JRE based on .exe's location or registry settings.
+ */
+static jboolean
+GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative)
+{
+    char libjava[MAXPATHLEN];
+
+    if (GetApplicationHome(path, pathsize)) {
+        /* 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) {
+            JLI_TraceLauncher("JRE path is %s\n", path);
+            return JNI_TRUE;
+        }
+
+        /* Does the app ship a private JRE in <apphome>/jre directory? */
+        JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/%s/" JAVA_DLL, path, arch);
+        if (access(libjava, F_OK) == 0) {
+            JLI_StrCat(path, "/jre");
+            JLI_TraceLauncher("JRE path is %s\n", path);
+            return JNI_TRUE;
+        }
+    }
+
+    if (!speculative)
+      JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
+    return JNI_FALSE;
+}
+
+jboolean
+LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
+{
+    Dl_info dlinfo;
+    void *libjvm;
+
+    JLI_TraceLauncher("JVM path is %s\n", jvmpath);
+
+    libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL);
+    if (libjvm == NULL) {
+#if defined(__solaris__) && defined(__sparc) && !defined(_LP64) /* i.e. 32-bit sparc */
+      FILE * fp;
+      Elf32_Ehdr elf_head;
+      int count;
+      int location;
+
+      fp = fopen(jvmpath, "r");
+      if (fp == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+      }
+
+      /* read in elf header */
+      count = fread((void*)(&elf_head), sizeof(Elf32_Ehdr), 1, fp);
+      fclose(fp);
+      if (count < 1) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+      }
+
+      /*
+       * Check for running a server vm (compiled with -xarch=v8plus)
+       * on a stock v8 processor.  In this case, the machine type in
+       * the elf header would not be included the architecture list
+       * provided by the isalist command, which is turn is gotten from
+       * sysinfo.  This case cannot occur on 64-bit hardware and thus
+       * does not have to be checked for in binaries with an LP64 data
+       * model.
+       */
+      if (elf_head.e_machine == EM_SPARC32PLUS) {
+        char buf[257];  /* recommended buffer size from sysinfo man
+                           page */
+        long length;
+        char* location;
+
+        length = sysinfo(SI_ISALIST, buf, 257);
+        if (length > 0) {
+            location = JLI_StrStr(buf, "sparcv8plus ");
+          if (location == NULL) {
+            JLI_ReportErrorMessage(JVM_ERROR3);
+            return JNI_FALSE;
+          }
+        }
+      }
+#endif
+        JLI_ReportErrorMessage(DLL_ERROR1, __LINE__);
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
+    ifn->CreateJavaVM = (CreateJavaVM_t)
+        dlsym(libjvm, "JNI_CreateJavaVM");
+    if (ifn->CreateJavaVM == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
+    ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t)
+        dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs");
+    if (ifn->GetDefaultJavaVMInitArgs == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        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;
+}
+
+/*
+ * Compute the name of the executable
+ *
+ * In order to re-exec securely we need the absolute path of the
+ * executable. On Solaris getexecname(3c) may not return an absolute
+ * path so we use dladdr to get the filename of the executable and
+ * then use realpath to derive an absolute path. From Solaris 9
+ * onwards the filename returned in DL_info structure from dladdr is
+ * an absolute pathname so technically realpath isn't required.
+ * On Linux we read the executable name from /proc/self/exe.
+ * As a fallback, and for platforms other than Solaris and Linux,
+ * we use FindExecName to compute the executable name.
+ */
+const char*
+SetExecname(char **argv)
+{
+    char* exec_path = NULL;
+#if defined(__solaris__)
+    {
+        Dl_info dlinfo;
+        int (*fptr)();
+
+        fptr = (int (*)())dlsym(RTLD_DEFAULT, "main");
+        if (fptr == NULL) {
+            JLI_ReportErrorMessage(DLL_ERROR3, dlerror());
+            return JNI_FALSE;
+        }
+
+        if (dladdr((void*)fptr, &dlinfo)) {
+            char *resolved = (char*)JLI_MemAlloc(PATH_MAX+1);
+            if (resolved != NULL) {
+                exec_path = realpath(dlinfo.dli_fname, resolved);
+                if (exec_path == NULL) {
+                    JLI_MemFree(resolved);
+                }
+            }
+        }
+    }
+#elif defined(__linux__)
+    {
+        const char* self = "/proc/self/exe";
+        char buf[PATH_MAX+1];
+        int len = readlink(self, buf, PATH_MAX);
+        if (len >= 0) {
+            buf[len] = '\0';            /* readlink doesn't nul terminate */
+            exec_path = JLI_StringDup(buf);
+        }
+    }
+#else /* !__solaris__ && !__linux__ */
+    {
+        /* Not implemented */
+    }
+#endif
+
+    if (exec_path == NULL) {
+        exec_path = FindExecName(argv[0]);
+    }
+    execname = exec_path;
+    return exec_path;
+}
+
+/* --- Splash Screen shared library support --- */
+static const char* SPLASHSCREEN_SO = JNI_LIB_NAME("splashscreen");
+static void* hSplashLib = NULL;
+
+void* SplashProcAddress(const char* name) {
+    if (!hSplashLib) {
+        const char * splashLibPath;
+        splashLibPath = SPLASHSCREEN_SO;
+        hSplashLib = dlopen(splashLibPath, RTLD_LAZY | RTLD_GLOBAL);
+    }
+    if (hSplashLib) {
+        void* sym = dlsym(hSplashLib, name);
+        return sym;
+    } else {
+        return NULL;
+    }
+}
+
+void SplashFreeLibrary() {
+    if (hSplashLib) {
+        dlclose(hSplashLib);
+        hSplashLib = NULL;
+    }
+}
+
+/*
+ * Block current thread and continue execution in a new thread
+ */
+int
+ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
+    int rslt;
+#ifdef __linux__
+    pthread_t tid;
+    pthread_attr_t attr;
+    pthread_attr_init(&attr);
+    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+
+    if (stack_size > 0) {
+      pthread_attr_setstacksize(&attr, stack_size);
+    }
+
+    if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) {
+      void * tmp;
+      pthread_join(tid, &tmp);
+      rslt = (int)tmp;
+    } else {
+     /*
+      * Continue execution in current thread if for some reason (e.g. out of
+      * memory/LWP)  a new thread can't be created. This will likely fail
+      * later in continuation as JNI_CreateJavaVM needs to create quite a
+      * few new threads, anyway, just give it a try..
+      */
+      rslt = continuation(args);
+    }
+
+    pthread_attr_destroy(&attr);
+#else /* ! __linux__ */
+    thread_t tid;
+    long flags = 0;
+    if (thr_create(NULL, stack_size, (void *(*)(void *))continuation, args, flags, &tid) == 0) {
+      void * tmp;
+      thr_join(tid, NULL, &tmp);
+      rslt = (int)tmp;
+    } else {
+      /* See above. Continue in current thread if thr_create() failed */
+      rslt = continuation(args);
+    }
+#endif /* __linux__ */
+    return rslt;
+}
+
+/* Coarse estimation of number of digits assuming the worst case is a 64-bit pid. */
+#define MAX_PID_STR_SZ   20
+
+void SetJavaLauncherPlatformProps() {
+   /* Linux only */
+#ifdef __linux__
+    const char *substr = "-Dsun.java.launcher.pid=";
+    char *pid_prop_str = (char *)JLI_MemAlloc(JLI_StrLen(substr) + MAX_PID_STR_SZ + 1);
+    sprintf(pid_prop_str, "%s%d", substr, getpid());
+    AddOption(pid_prop_str, NULL);
+#endif /* __linux__ */
+}
+
+int
+JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
+        int argc, char **argv,
+        int mode, char *what, int ret)
+{
+    ShowSplashScreen();
+    return ContinueInNewThread(ifn, threadStackSize, argc, argv, mode, what, ret);
+}
+
+void
+PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm)
+{
+    // stubbed out for windows and *nixes.
+}
+
+void
+RegisterThread()
+{
+    // stubbed out for windows and *nixes.
+}
+
+/*
+ * on unix, we return a false to indicate this option is not applicable
+ */
+jboolean
+ProcessPlatformOption(const char *arg)
+{
+    return JNI_FALSE;
+}
diff --git a/jdk/src/solaris/bin/java_md_solinux.h b/jdk/src/solaris/bin/java_md_solinux.h
new file mode 100644
index 0000000..a9e4438
--- /dev/null
+++ b/jdk/src/solaris/bin/java_md_solinux.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 JAVA_MD_SOLINUX_H
+#define JAVA_MD_SOLINUX_H
+
+#ifdef HAVE_GETHRTIME
+/*
+ * Support for doing cheap, accurate interval timing.
+ */
+#include <sys/time.h>
+#define CounterGet()              (gethrtime()/1000)
+#define Counter2Micros(counts)    (counts)
+#else  /* ! HAVE_GETHRTIME */
+#define CounterGet()              (0)
+#define Counter2Micros(counts)    (1)
+#endif /* HAVE_GETHRTIME */
+
+/* pointer to environment */
+extern char **environ;
+
+/*
+ *      A collection of useful strings. One should think of these as #define
+ *      entries, but actual strings can be more efficient (with many compilers).
+ */
+#ifdef __linux__
+static const char *system_dir   = "/usr/java";
+static const char *user_dir     = "/java";
+#else /* Solaris */
+static const char *system_dir   = "/usr/jdk";
+static const char *user_dir     = "/jdk";
+#endif
+
+#include <dlfcn.h>
+#ifdef __linux__
+#include <pthread.h>
+#else
+#include <thread.h>
+#endif
+
+#define JVM_DLL         "libjvm.so"
+#define JAVA_DLL        "libjava.so"
+#define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
+
+#endif /* JAVA_MD_SOLINUX_H */
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/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/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/ch/BsdAsynchronousChannelProvider.java b/jdk/src/solaris/classes/sun/nio/ch/BsdAsynchronousChannelProvider.java
new file mode 100644
index 0000000..a732c11
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/nio/ch/BsdAsynchronousChannelProvider.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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.*;
+import java.nio.channels.spi.AsynchronousChannelProvider;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadFactory;
+import java.io.IOException;
+
+public class BsdAsynchronousChannelProvider
+    extends AsynchronousChannelProvider
+{
+    private static volatile KQueuePort defaultPort;
+
+    private KQueuePort defaultEventPort() throws IOException {
+        if (defaultPort == null) {
+            synchronized (BsdAsynchronousChannelProvider.class) {
+                if (defaultPort == null) {
+                    defaultPort = new KQueuePort(this, ThreadPool.getDefault()).start();
+                }
+            }
+        }
+        return defaultPort;
+    }
+
+    public BsdAsynchronousChannelProvider() {
+    }
+
+    @Override
+    public AsynchronousChannelGroup openAsynchronousChannelGroup(int nThreads, ThreadFactory factory)
+        throws IOException
+    {
+        return new KQueuePort(this, ThreadPool.create(nThreads, factory)).start();
+    }
+
+    @Override
+    public AsynchronousChannelGroup openAsynchronousChannelGroup(ExecutorService executor, int initialSize)
+        throws IOException
+    {
+        return new KQueuePort(this, ThreadPool.wrap(executor, initialSize)).start();
+    }
+
+    private Port toPort(AsynchronousChannelGroup group) throws IOException {
+        if (group == null) {
+            return defaultEventPort();
+        } else {
+            if (!(group instanceof KQueuePort))
+                throw new IllegalChannelGroupException();
+            return (Port)group;
+        }
+    }
+
+    @Override
+    public AsynchronousServerSocketChannel openAsynchronousServerSocketChannel(AsynchronousChannelGroup group)
+        throws IOException
+    {
+        return new UnixAsynchronousServerSocketChannelImpl(toPort(group));
+    }
+
+    @Override
+    public AsynchronousSocketChannel openAsynchronousSocketChannel(AsynchronousChannelGroup group)
+        throws IOException
+    {
+        return new UnixAsynchronousSocketChannelImpl(toPort(group));
+    }
+}
diff --git a/jdk/src/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java b/jdk/src/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java
index 4d2e425..9767c7c 100644
--- a/jdk/src/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java
+++ b/jdk/src/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java
@@ -50,6 +50,8 @@
             return new SolarisAsynchronousChannelProvider();
         if (osname.equals("Linux"))
             return new LinuxAsynchronousChannelProvider();
+        if (osname.startsWith("Mac OS"))
+            return new BsdAsynchronousChannelProvider();
         throw new InternalError("platform not recognized");
     }
 
diff --git a/jdk/src/solaris/classes/sun/nio/ch/KQueue.java b/jdk/src/solaris/classes/sun/nio/ch/KQueue.java
new file mode 100644
index 0000000..e3466e3
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/nio/ch/KQueue.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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.io.IOException;
+import sun.misc.Unsafe;
+
+/**
+ * Provides access to the BSD kqueue facility.
+ */
+
+class KQueue {
+    private KQueue() { }
+
+    private static final Unsafe unsafe = Unsafe.getUnsafe();
+
+    /**
+     * struct kevent {
+     *        uintptr_t       ident;          // identifier for this event, usually the fd
+     *        int16_t         filter;         // filter for event
+     *        uint16_t        flags;          // general flags
+     *        uint32_t        fflags;         // filter-specific flags
+     *        intptr_t        data;           // filter-specific data
+     *        void            *udata;         // opaque user data identifier
+     * };
+     */
+    private static final int SIZEOF_KQUEUEEVENT    = keventSize();
+    private static final int OFFSET_IDENT          = identOffset();
+    private static final int OFFSET_FILTER         = filterOffset();
+    private static final int OFFSET_FLAGS          = flagsOffset();
+
+    // filters
+    static final int EVFILT_READ  = -1;
+    static final int EVFILT_WRITE = -2;
+
+    // flags
+    static final int EV_ADD     = 0x0001;
+    static final int EV_ONESHOT = 0x0010;
+    static final int EV_CLEAR   = 0x0020;
+
+    /**
+     * Allocates a poll array to handle up to {@code count} events.
+     */
+    static long allocatePollArray(int count) {
+        return unsafe.allocateMemory(count * SIZEOF_KQUEUEEVENT);
+    }
+
+    /**
+     * Free a poll array
+     */
+    static void freePollArray(long address) {
+        unsafe.freeMemory(address);
+    }
+
+    /**
+     * Returns kevent[i].
+     */
+    static long getEvent(long address, int i) {
+        return address + (SIZEOF_KQUEUEEVENT*i);
+    }
+
+    /**
+     * Returns the file descriptor from a kevent (assuming to be in ident field)
+     */
+    static int getDescriptor(long address) {
+        return unsafe.getInt(address + OFFSET_IDENT);
+    }
+
+    static int getFilter(long address) {
+        return unsafe.getShort(address + OFFSET_FILTER);
+    }
+
+    static int getFlags(long address) {
+        return unsafe.getShort(address + OFFSET_FLAGS);
+    }
+
+    // -- Native methods --
+
+    private static native int keventSize();
+
+    private static native int identOffset();
+
+    private static native int filterOffset();
+
+    private static native int flagsOffset();
+
+    static native int kqueue() throws IOException;
+
+    static native int keventRegister(int kqpfd, int fd, int filter, int flags);
+
+    static native int keventPoll(int kqpfd, long pollAddress, int nevents)
+        throws IOException;
+
+    static {
+        Util.load();
+    }
+}
diff --git a/jdk/src/solaris/classes/sun/nio/ch/KQueuePort.java b/jdk/src/solaris/classes/sun/nio/ch/KQueuePort.java
new file mode 100644
index 0000000..cd16e2e
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/nio/ch/KQueuePort.java
@@ -0,0 +1,331 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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.AsynchronousChannelProvider;
+import java.io.IOException;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.atomic.AtomicInteger;
+import static sun.nio.ch.KQueue.*;
+
+/**
+ * AsynchronousChannelGroup implementation based on the BSD kqueue facility.
+ */
+
+final class KQueuePort
+    extends Port
+{
+    // maximum number of events to poll at a time
+    private static final int MAX_KEVENTS_TO_POLL = 512;
+
+    // kqueue file descriptor
+    private final int kqfd;
+
+    // true if kqueue closed
+    private boolean closed;
+
+    // socket pair used for wakeup
+    private final int sp[];
+
+    // number of wakeups pending
+    private final AtomicInteger wakeupCount = new AtomicInteger();
+
+    // address of the poll array passed to kqueue_wait
+    private final long address;
+
+    // encapsulates an event for a channel
+    static class Event {
+        final PollableChannel channel;
+        final int events;
+
+        Event(PollableChannel channel, int events) {
+            this.channel = channel;
+            this.events = events;
+        }
+
+        PollableChannel channel()   { return channel; }
+        int events()                { return events; }
+    }
+
+    // queue of events for cases that a polling thread dequeues more than one
+    // event
+    private final ArrayBlockingQueue<Event> queue;
+    private final Event NEED_TO_POLL = new Event(null, 0);
+    private final Event EXECUTE_TASK_OR_SHUTDOWN = new Event(null, 0);
+
+    KQueuePort(AsynchronousChannelProvider provider, ThreadPool pool)
+        throws IOException
+    {
+        super(provider, pool);
+
+        // open kqueue
+        this.kqfd = kqueue();
+
+        // create socket pair for wakeup mechanism
+        int[] sv = new int[2];
+        try {
+            socketpair(sv);
+
+            // register one end with kqueue
+            keventRegister(kqfd, sv[0], EVFILT_READ, EV_ADD);
+        } catch (IOException x) {
+            close0(kqfd);
+            throw x;
+        }
+        this.sp = sv;
+
+        // allocate the poll array
+        this.address = allocatePollArray(MAX_KEVENTS_TO_POLL);
+
+        // create the queue and offer the special event to ensure that the first
+        // threads polls
+        this.queue = new ArrayBlockingQueue<Event>(MAX_KEVENTS_TO_POLL);
+        this.queue.offer(NEED_TO_POLL);
+    }
+
+    KQueuePort start() {
+        startThreads(new EventHandlerTask());
+        return this;
+    }
+
+    /**
+     * Release all resources
+     */
+    private void implClose() {
+        synchronized (this) {
+            if (closed)
+                return;
+            closed = true;
+        }
+        freePollArray(address);
+        close0(sp[0]);
+        close0(sp[1]);
+        close0(kqfd);
+    }
+
+    private void wakeup() {
+        if (wakeupCount.incrementAndGet() == 1) {
+            // write byte to socketpair to force wakeup
+            try {
+                interrupt(sp[1]);
+            } catch (IOException x) {
+                throw new AssertionError(x);
+            }
+        }
+    }
+
+    @Override
+    void executeOnHandlerTask(Runnable task) {
+        synchronized (this) {
+            if (closed)
+                throw new RejectedExecutionException();
+            offerTask(task);
+            wakeup();
+        }
+    }
+
+    @Override
+    void shutdownHandlerTasks() {
+        /*
+         * If no tasks are running then just release resources; otherwise
+         * write to the one end of the socketpair to wakeup any polling threads.
+         */
+        int nThreads = threadCount();
+        if (nThreads == 0) {
+            implClose();
+        } else {
+            // send interrupt to each thread
+            while (nThreads-- > 0) {
+                wakeup();
+            }
+        }
+    }
+
+    // invoked by clients to register a file descriptor
+    @Override
+    void startPoll(int fd, int events) {
+        // We use a separate filter for read and write events.
+        // TBD: Measure cost of EV_ONESHOT vs. EV_CLEAR, either will do here.
+        int err = 0;
+        int flags = (EV_ADD|EV_ONESHOT);
+        if ((events & Port.POLLIN) > 0)
+            err = keventRegister(kqfd, fd, EVFILT_READ, flags);
+        if (err == 0 && (events & Port.POLLOUT) > 0)
+            err = keventRegister(kqfd, fd, EVFILT_WRITE, flags);
+        if (err != 0)
+            throw new InternalError("kevent failed: " + err);  // should not happen
+    }
+
+    /*
+     * Task to process events from kqueue and dispatch to the channel's
+     * onEvent handler.
+     *
+     * Events are retreived from kqueue in batch and offered to a BlockingQueue
+     * where they are consumed by handler threads. A special "NEED_TO_POLL"
+     * event is used to signal one consumer to re-poll when all events have
+     * been consumed.
+     */
+    private class EventHandlerTask implements Runnable {
+        private Event poll() throws IOException {
+            try {
+                for (;;) {
+                    int n = keventPoll(kqfd, address, MAX_KEVENTS_TO_POLL);
+                    /*
+                     * 'n' events have been read. Here we map them to their
+                     * corresponding channel in batch and queue n-1 so that
+                     * they can be handled by other handler threads. The last
+                     * event is handled by this thread (and so is not queued).
+                     */
+                    fdToChannelLock.readLock().lock();
+                    try {
+                        while (n-- > 0) {
+                            long keventAddress = getEvent(address, n);
+                            int fd = getDescriptor(keventAddress);
+
+                            // wakeup
+                            if (fd == sp[0]) {
+                                if (wakeupCount.decrementAndGet() == 0) {
+                                    // no more wakeups so drain pipe
+                                    drain1(sp[0]);
+                                }
+
+                                // queue special event if there are more events
+                                // to handle.
+                                if (n > 0) {
+                                    queue.offer(EXECUTE_TASK_OR_SHUTDOWN);
+                                    continue;
+                                }
+                                return EXECUTE_TASK_OR_SHUTDOWN;
+                            }
+
+                            PollableChannel channel = fdToChannel.get(fd);
+                            if (channel != null) {
+                                int filter = getFilter(keventAddress);
+                                int events = 0;
+                                if (filter == EVFILT_READ)
+                                    events = Port.POLLIN;
+                                else if (filter == EVFILT_WRITE)
+                                    events = Port.POLLOUT;
+
+                                Event ev = new Event(channel, events);
+
+                                // n-1 events are queued; This thread handles
+                                // the last one except for the wakeup
+                                if (n > 0) {
+                                    queue.offer(ev);
+                                } else {
+                                    return ev;
+                                }
+                            }
+                        }
+                    } finally {
+                        fdToChannelLock.readLock().unlock();
+                    }
+                }
+            } finally {
+                // to ensure that some thread will poll when all events have
+                // been consumed
+                queue.offer(NEED_TO_POLL);
+            }
+        }
+
+        public void run() {
+            Invoker.GroupAndInvokeCount myGroupAndInvokeCount =
+                Invoker.getGroupAndInvokeCount();
+            final boolean isPooledThread = (myGroupAndInvokeCount != null);
+            boolean replaceMe = false;
+            Event ev;
+            try {
+                for (;;) {
+                    // reset invoke count
+                    if (isPooledThread)
+                        myGroupAndInvokeCount.resetInvokeCount();
+
+                    try {
+                        replaceMe = false;
+                        ev = queue.take();
+
+                        // no events and this thread has been "selected" to
+                        // poll for more.
+                        if (ev == NEED_TO_POLL) {
+                            try {
+                                ev = poll();
+                            } catch (IOException x) {
+                                x.printStackTrace();
+                                return;
+                            }
+                        }
+                    } catch (InterruptedException x) {
+                        continue;
+                    }
+
+                    // handle wakeup to execute task or shutdown
+                    if (ev == EXECUTE_TASK_OR_SHUTDOWN) {
+                        Runnable task = pollTask();
+                        if (task == null) {
+                            // shutdown request
+                            return;
+                        }
+                        // run task (may throw error/exception)
+                        replaceMe = true;
+                        task.run();
+                        continue;
+                    }
+
+                    // process event
+                    try {
+                        ev.channel().onEvent(ev.events(), isPooledThread);
+                    } catch (Error x) {
+                        replaceMe = true; throw x;
+                    } catch (RuntimeException x) {
+                        replaceMe = true; throw x;
+                    }
+                }
+            } finally {
+                // last handler to exit when shutdown releases resources
+                int remaining = threadExit(this, replaceMe);
+                if (remaining == 0 && isShutdown()) {
+                    implClose();
+                }
+            }
+        }
+    }
+
+    // -- Native methods --
+
+    private static native void socketpair(int[] sv) throws IOException;
+
+    private static native void interrupt(int fd) throws IOException;
+
+    private static native void drain1(int fd) throws IOException;
+
+    private static native void close0(int fd);
+
+    static {
+        Util.load();
+    }
+}
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..9dfc791
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/nio/fs/BsdFileStore.java
@@ -0,0 +1,88 @@
+/*
+ * 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");
+    }
+}
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..73c7e83
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/nio/fs/BsdFileSystemProvider.java
@@ -0,0 +1,50 @@
+/*
+ * 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);
+    }
+}
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 e607659..c1de9bc 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..d58a4c1
--- /dev/null
+++ b/jdk/src/solaris/classes/sun/tools/attach/BsdVirtualMachine.java
@@ -0,0 +1,303 @@
+/*
+ * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact 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 {
+    // "tmpdir" is used as a global well-known location for the files
+    // .java_pid<pid>. and .attach_pid<pid>. It is important that this
+    // location is the same for all processes, otherwise the tools
+    // will not be able to find all Hotspot processes.
+    // This is intentionally not the same as java.io.tmpdir, since
+    // the latter can be changed by the user.
+    // Any changes to this needs to be synchronized with HotSpot.
+    private static final String 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 temp directory for .java_pid<pid>.
+    private String findSocketFile(int pid) {
+        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 native String getTempDir();
+
+    static {
+        System.loadLibrary("attach");
+        tmpdir = getTempDir();
+    }
+}
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..390e89c 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
 
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..088b3cf 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
+    /*
+     * XXBSDL no way to do it in FreeBSD
+     */
+    // 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 aa8112d..43077ce 100644
--- a/jdk/src/solaris/native/java/lang/UNIXProcess_md.c
+++ b/jdk/src/solaris/native/java/lang/UNIXProcess_md.c
@@ -49,6 +49,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 +390,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 +415,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..13e4574
--- /dev/null
+++ b/jdk/src/solaris/native/java/lang/java_props_macosx.c
@@ -0,0 +1,350 @@
+/*
+ * 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);
+}
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 974e4db..8f931cc 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 e6bd2cc..28e8448 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 */
 #ifndef NI_MAXHOST
 #define NI_MAXHOST 1025
@@ -292,6 +568,8 @@
     return ret;
 }
 
+#endif /* _ALLBSD_SOURCE */
+
 #define SET_NONBLOCKING(fd) {           \
         int flags = fcntl(fd, F_GETFL); \
         flags |= O_NONBLOCK;            \
@@ -430,6 +708,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 051326b..e612131 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
@@ -107,7 +110,7 @@
             freeaddrinfo(res);
         }
 #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 049b2f8..b952626 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;
@@ -184,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");
 }
 
 
@@ -824,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;
@@ -1661,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/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..594d424
--- /dev/null
+++ b/jdk/src/solaris/native/java/net/bsd_close.c
@@ -0,0 +1,417 @@
+/*
+ * 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/select.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;
+    int i;
+
+    /*
+     * 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();
+    }
+    for (i=0; i<fdCount; i++) {
+        pthread_mutex_init(&fdTable[i].lock, NULL);
+    }
+
+    /*
+     * 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) {
+    /* casting int *fromlen -> socklen_t* Both are ints */
+    BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, (socklen_t *)fromlen) );
+}
+
+int NET_Send(int s, void *msg, int len, unsigned int flags) {
+    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 select(s, timeout). We are using select() on Mac OS due to Bug 7131399.
+ * 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, *tp = &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) {
+        /* Timed */
+        struct timeval now;
+        gettimeofday(&now, NULL);
+        prevtime = now.tv_sec * 1000  +  now.tv_usec / 1000;
+        t.tv_sec = timeout / 1000;
+        t.tv_usec = (timeout % 1000) * 1000;
+    } else if (timeout < 0) {
+        /* Blocking */
+        tp = 0;
+    } else {
+        /* Poll */
+        t.tv_sec = 0;
+        t.tv_usec = 0;
+    }
+
+    for(;;) {
+        fd_set rfds;
+        int rv;
+        threadEntry_t self;
+
+        /*
+         * call select on the fd. If interrupted by our wakeup signal
+         * errno will be set to EBADF.
+         */
+        FD_ZERO(&rfds);
+        FD_SET(s, &rfds);
+
+        startOp(fdEntry, &self);
+        rv = select(s+1, &rfds, 0, 0, tp);
+        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) {
+                struct timeval now;
+                gettimeofday(&now, NULL);
+                newtime = now.tv_sec * 1000  +  now.tv_usec / 1000;
+                timeout -= newtime - prevtime;
+                if (timeout <= 0) {
+                    return 0;
+                }
+                prevtime = newtime;
+                t.tv_sec = timeout / 1000;
+                t.tv_usec = (timeout % 1000) * 1000;
+            }
+        } 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 963ef2e..f7e6d6a 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,30 @@
 #define UDP_EXCLBIND            0x0101
 #endif
 
+void setDefaultScopeID(JNIEnv *env, struct sockaddr *him)
+{
+#ifdef MACOSX
+    static jclass ni_class = NULL;
+    static jfieldID ni_defaultIndexID;
+    if (ni_class == NULL) {
+        jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
+        CHECK_NULL(c);
+        c = (*env)->NewGlobalRef(env, c);
+        CHECK_NULL(c);
+        ni_defaultIndexID = (*env)->GetStaticFieldID(
+            env, c, "defaultIndex", "I");
+        ni_class = c;
+    }
+    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 +306,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
@@ -385,6 +427,7 @@
     }
 #endif /* AF_INET6 */
 }
+#endif /* DONT_ENABLE_IPV6 */
 
 void ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
                                            const char* hostname,
@@ -747,6 +790,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)
@@ -1168,6 +1216,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;
 }
 
@@ -1195,11 +1252,29 @@
 #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
-     *    field when connecting TCP socket, or sending
-     *    UDP packet.
+     * 1. IPv6 on Solaris/Mac OS: no-op and will be set
+     *    in flowinfo field when connecting TCP socket,
+     *    or sending UDP packet.
      * 2. IPv6 on Linux: By default Linux ignores flowinfo
      *    field so enable IPV6_FLOWINFO_SEND so that flowinfo
      *    will be examined.
@@ -1209,7 +1284,7 @@
     if (level == IPPROTO_IP && opt == IP_TOS) {
         int *iptos;
 
-#if defined(AF_INET6) && defined(__solaris__)
+#if defined(AF_INET6) && (defined(__solaris__) || defined(MACOSX))
         if (ipv6_available()) {
             return 0;
         }
@@ -1300,6 +1375,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 28664ab..8d835b2 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__) || defined(MACOSX)
 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 7e95d53..48b3c52 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) {
@@ -210,7 +211,7 @@
     return tz;
 }
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 
 /*
  * Performs Linux specific mapping and returns a zone ID
@@ -226,6 +227,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
@@ -249,6 +251,7 @@
             return tz;
         }
     }
+#endif /* __linux__ */
 
     /*
      * Next, try /etc/localtime to find the zone ID.
@@ -623,7 +626,7 @@
 
     tz = getenv("TZ");
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
     if (tz == NULL) {
 #else
 #ifdef __solaris__
@@ -664,10 +667,37 @@
     }
     return javatz;
 }
-
 /**
  * Returns a GMT-offset-based zone ID. (e.g., "GMT-08:00")
  */
+
+#ifdef MACOSX
+
+char *
+getGMTOffsetID()
+{
+    time_t offset;
+    char sign, buf[32];
+    struct tm *local_tm;
+    time_t clock;
+    time_t currenttime;
+
+    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()
 {
@@ -702,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/awt_Font.c b/jdk/src/solaris/native/sun/awt/awt_Font.c
index 239ea32..d8372fe 100644
--- a/jdk/src/solaris/native/sun/awt/awt_Font.c
+++ b/jdk/src/solaris/native/sun/awt/awt_Font.c
@@ -260,7 +260,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 f6e4b06..2cc122c 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>
@@ -119,7 +120,7 @@
  */
 
 #define MAXFRAMEBUFFERS 16
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 typedef struct {
    int   screen_number;
    short x_org;
@@ -424,6 +425,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",
@@ -568,19 +580,22 @@
 }
 
 #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);
 
@@ -616,11 +631,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 */
@@ -629,8 +643,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);
@@ -677,11 +691,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 */
 
@@ -1562,7 +1576,7 @@
 {
     jobject point = NULL;
 #ifndef HEADLESS    /* return NULL in HEADLESS, Linux */
-#ifndef __linux__
+#if !defined(__linux__) && !defined(MACOSX)
     int x,y;
 
     AWT_LOCK();
@@ -1575,7 +1589,7 @@
         DTRACE_PRINTLN("unable to call XineramaSolarisCenterFunc: symbol is null");
     }
     AWT_FLUSH_UNLOCK();
-#endif /* __linux __ */
+#endif /* __linux __ || MACOSX */
 #endif /* HEADLESS */
     return point;
 }
@@ -1645,7 +1659,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 af85e48..80da504 100644
--- a/jdk/src/solaris/native/sun/awt/awt_InputMethod.c
+++ b/jdk/src/solaris/native/sun/awt/awt_InputMethod.c
@@ -53,7 +53,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,
@@ -67,7 +67,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
@@ -85,14 +85,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        */
@@ -125,7 +125,7 @@
     XIMCallback *callbacks;     /* callback parameters */
     jobject     x11inputmethod; /* global ref to X11InputMethod instance */
                                 /* associated with the XIC */
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     StatusWindow *statusWindow; /* our own status window  */
 #endif
     char        *lookup_buf;    /* buffer used for XmbLookupString */
@@ -372,7 +372,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);
@@ -475,7 +475,7 @@
     pX11IMData = getX11InputMethodData(env, currentX11InputMethodInstance);
 
     if (pX11IMData == NULL) {
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
         return False;
 #else
         return result;
@@ -483,7 +483,7 @@
     }
 
     if ((ic = pX11IMData->current_ic) == (XIC)0){
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
         return False;
 #else
         return result;
@@ -579,7 +579,7 @@
     return result;
 }
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 static StatusWindow *createStatusWindow(
                                 Window parent) {
     StatusWindow *statusWindow;
@@ -892,7 +892,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
@@ -936,7 +936,7 @@
         return FALSE ;
     }
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     on_the_spot_styles |= XIMStatusNothing;
 
     /*kinput does not support XIMPreeditCallbacks and XIMStatusArea
@@ -949,9 +949,9 @@
             break;
         }
     }
-#else /*! __linux__ */
+#else /*! __linux__ && !MACOSX */
     on_the_spot_styles |= XIMStatusNothing;
-#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;
@@ -999,7 +999,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,
@@ -1021,7 +1021,7 @@
             XFree((void *)status);
             XFree((void *)preedit);
         }
-#else /* !__linux__ */
+#else /* !__linux__ && !MACOSX */
             pX11IMData->ic_active = XCreateIC(X11im,
                                               XNClientWindow, w,
                                               XNFocusWindow, w,
@@ -1029,7 +1029,7 @@
                                               XNPreeditAttributes, preedit,
                                               NULL);
         XFree((void *)preedit);
-#endif /* __linux__ */
+#endif /* __linux__ || MACOSX */
         pX11IMData->ic_passive = XCreateIC(X11im,
                                            XNClientWindow, w,
                                            XNFocusWindow, w,
@@ -1188,7 +1188,7 @@
 
 }
 
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
 static void
 StatusStartCallback(XIC ic, XPointer client_data, XPointer call_data)
 {
@@ -1256,7 +1256,7 @@
  finally:
     AWT_UNLOCK();
 }
-#endif /*__linux__*/
+#endif /* __linux__ || MACOSX */
 
 static void CommitStringCallback(XIC ic, XPointer client_data, XPointer call_data) {
     JNIEnv *env = GetJNIEnv();
@@ -1353,14 +1353,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
 
@@ -1395,9 +1395,9 @@
 
     globalRef = (*env)->NewGlobalRef(env, this);
     pX11IMData->x11inputmethod = globalRef;
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     pX11IMData->statusWindow = NULL;
-#endif /* __linux__ */
+#endif /* __linux__ || MACOSX */
 
     pX11IMData->lookup_buf = 0;
     pX11IMData->lookup_buf_len = 0;
@@ -1444,14 +1444,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
@@ -1468,7 +1468,7 @@
 Java_sun_awt_X11InputMethod_turnoffStatusWindow(JNIEnv *env,
                                                 jobject this)
 {
-#ifdef __linux__
+#if defined(__linux__) || defined(MACOSX)
     X11InputMethodData *pX11IMData;
     StatusWindow *statusWindow;
 
@@ -1636,7 +1636,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 5a070a6..cdb0e8f 100644
--- a/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c
+++ b/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c
@@ -73,13 +73,29 @@
     return isHeadless;
 }
 
+/*
+ * Pathnames to the various awt toolkits
+ */
+
+
+#ifdef MACOSX
+  #define XAWT_PATH "/libawt_xawt.dylib"
+  #define LWAWT_PATH "/libawt_lwawt.dylib"
+  #define DEFAULT_PATH LWAWT_PATH
+  #define HEADLESS_PATH "/libawt_headless.dylib"
+#else
+  #define XAWT_PATH "/libawt_xawt.so"
+  #define DEFAULT_PATH XAWT_PATH
+  #define HEADLESS_PATH "/libawt_headless.so"
+#endif
+
 jint
 AWT_OnLoad(JavaVM *vm, void *reserved)
 {
     Dl_info dlinfo;
     char buf[MAXPATHLEN];
     int32_t len;
-    char *p;
+    char *p, *tk;
     JNI_OnLoad_type *JNI_OnLoad_ptr;
     struct utsname name;
     JNIEnv *env = (JNIEnv *)JNU_GetEnv(vm, JNI_VERSION_1_2);
@@ -89,6 +105,8 @@
     int XAWT = 0;
     jstring toolkit = NULL;
     jstring propname = NULL;
+    jstring fmanager = NULL;
+    jstring fmProp = NULL;
 
     if (awtHandle != NULL) {
         /* Avoid several loading attempts */
@@ -111,30 +129,44 @@
      */
 
     propname = (*env)->NewStringUTF(env, "awt.toolkit");
+    fmProp = (*env)->NewStringUTF(env, "sun.font.fontmanager");
+    tk = DEFAULT_PATH; /* default value, may be changed below */
+
     /* Check if toolkit is specified in env variable */
     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"))) {
+        toolkit = (*env)->NewStringUTF(env, "sun.awt.X11.XToolkit");
+        tk = XAWT_PATH;
+        fmanager = (*env)->NewStringUTF(env, "sun.awt.X11FontManager");
+#ifdef MACOSX
+    } else {
+        fmanager = (*env)->NewStringUTF(env, "sun.font.CFontManager");
+        tk = LWAWT_PATH;
+#endif
+    }
+    /* 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 (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 */
     if (AWTIsHeadless()) {
-        strncpy(p, "/libawt_headless.so", MAXPATHLEN-len-1);
-    } else {
-        /* Default AWT Toolkit on Linux and Solaris is XAWT. */
-        strncpy(p, "/libawt_xawt.so", MAXPATHLEN-len-1);
+        tk = HEADLESS_PATH;
     }
+    strncpy(p, tk, MAXPATHLEN-len-1);
 
     if (toolkit) {
         (*env)->DeleteLocalRef(env, toolkit);
@@ -142,6 +174,12 @@
     if (propname) {
         (*env)->DeleteLocalRef(env, propname);
     }
+    if (fmProp) {
+        (*env)->DeleteLocalRef(env, fmProp);
+    }
+    if (fmanager) {
+        (*env)->DeleteLocalRef(env, fmanager);
+    }
 
     JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load",
                                "(Ljava/lang/String;)V",
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 a830756..6818b3b 100644
--- a/jdk/src/solaris/native/sun/awt/awt_Robot.c
+++ b/jdk/src/solaris/native/sun/awt/awt_Robot.c
@@ -44,7 +44,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/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 d389e16..16209e7 100644
--- a/jdk/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c
+++ b/jdk/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c
@@ -442,4 +442,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 a993217..330cf0d 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"
 
@@ -160,7 +161,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 f7310ba..6808dbe 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/KQueue.c b/jdk/src/solaris/native/sun/nio/ch/KQueue.c
new file mode 100644
index 0000000..3484cac
--- /dev/null
+++ b/jdk/src/solaris/native/sun/nio/ch/KQueue.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 "nio_util.h"
+
+#include "sun_nio_ch_KQueue.h"
+
+#include <strings.h>
+#include <sys/types.h>
+#include <sys/event.h>
+#include <sys/time.h>
+
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_KQueue_keventSize(JNIEnv* env, jclass this)
+{
+    return sizeof(struct kevent);
+}
+
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_KQueue_identOffset(JNIEnv* env, jclass this)
+{
+    return offsetof(struct kevent, ident);
+}
+
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_KQueue_filterOffset(JNIEnv* env, jclass this)
+{
+    return offsetof(struct kevent, filter);
+}
+
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_KQueue_flagsOffset(JNIEnv* env, jclass this)
+{
+    return offsetof(struct kevent, flags);
+}
+
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_KQueue_kqueue(JNIEnv *env, jclass c) {
+    int kqfd = kqueue();
+    if (kqfd < 0) {
+        JNU_ThrowIOExceptionWithLastError(env, "kqueue failed");
+    }
+    return kqfd;
+}
+
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_KQueue_keventRegister(JNIEnv *env, jclass c, jint kqfd,
+                                      jint fd, jint filter, jint flags)
+
+{
+    struct kevent changes[1];
+    struct timespec timeout = {0, 0};
+    int res;
+
+    EV_SET(&changes[0], fd, filter, flags, 0, 0, 0);
+    RESTARTABLE(kevent(kqfd, &changes[0], 1, NULL, 0, &timeout), res);
+    return (res == -1) ? errno : 0;
+}
+
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_KQueue_keventPoll(JNIEnv *env, jclass c,
+                                  jint kqfd, jlong address, jint nevents)
+{
+    struct kevent *events = jlong_to_ptr(address);
+    int res;
+
+    RESTARTABLE(kevent(kqfd, NULL, 0, events, nevents, NULL), res);
+    if (res < 0) {
+        JNU_ThrowIOExceptionWithLastError(env, "kqueue failed");
+    }
+    return res;
+}
diff --git a/jdk/src/solaris/native/sun/nio/ch/KQueuePort.c b/jdk/src/solaris/native/sun/nio/ch/KQueuePort.c
new file mode 100644
index 0000000..b0bc419
--- /dev/null
+++ b/jdk/src/solaris/native/sun/nio/ch/KQueuePort.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 "nio_util.h"
+
+#include "sun_nio_ch_KQueuePort.h"
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+JNIEXPORT void JNICALL
+Java_sun_nio_ch_KQueuePort_socketpair(JNIEnv* env, jclass clazz, jintArray sv) {
+    int sp[2];
+    if (socketpair(PF_UNIX, SOCK_STREAM, 0, sp) == -1) {
+        JNU_ThrowIOExceptionWithLastError(env, "socketpair failed");
+    } else {
+        jint res[2];
+        res[0] = (jint)sp[0];
+        res[1] = (jint)sp[1];
+        (*env)->SetIntArrayRegion(env, sv, 0, 2, &res[0]);
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_sun_nio_ch_KQueuePort_interrupt(JNIEnv *env, jclass c, jint fd) {
+    int res;
+    int buf[1];
+    buf[0] = 1;
+    RESTARTABLE(write(fd, buf, 1), res);
+    if (res < 0) {
+        JNU_ThrowIOExceptionWithLastError(env, "write failed");
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_sun_nio_ch_KQueuePort_drain1(JNIEnv *env, jclass cl, jint fd) {
+    int res;
+    char buf[1];
+    RESTARTABLE(read(fd, buf, 1), res);
+    if (res < 0) {
+        JNU_ThrowIOExceptionWithLastError(env, "drain1 failed");
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_sun_nio_ch_KQueuePort_close0(JNIEnv *env, jclass c, jint fd) {
+    int res;
+    RESTARTABLE(close(fd), res);
+}
diff --git a/jdk/src/solaris/native/sun/nio/ch/Net.c b/jdk/src/solaris/native/sun/nio/ch/Net.c
index def9859..45c09c3 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)
@@ -157,7 +198,12 @@
 JNIEXPORT jboolean JNICALL
 Java_sun_nio_ch_Net_canIPv6SocketJoinIPv4Group0(JNIEnv* env, jclass cl)
 {
+#ifdef MACOSX
+    /* for now IPv6 sockets cannot join IPv4 multicast groups */
+    return JNI_FALSE;
+#else
     return JNI_TRUE;
+#endif
 }
 
 JNIEXPORT jboolean JNICALL
@@ -287,8 +333,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 +368,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 +455,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 */
 
@@ -419,12 +510,17 @@
         optval = (void*)&mreq;
         optlen = sizeof(mreq);
     } else {
+#ifdef MACOSX
+        /* no IPv4 include-mode filtering for now */
+        return IOS_UNAVAILABLE;
+#else
         mreq_source.imr_multiaddr.s_addr = htonl(group);
         mreq_source.imr_sourceaddr.s_addr = htonl(source);
         mreq_source.imr_interface.s_addr = htonl(interf);
         opt = (join) ? IP_ADD_SOURCE_MEMBERSHIP : IP_DROP_SOURCE_MEMBERSHIP;
         optval = (void*)&mreq_source;
         optlen = sizeof(mreq_source);
+#endif
     }
 
     n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt, optval, optlen);
@@ -440,6 +536,10 @@
 Java_sun_nio_ch_Net_blockOrUnblock4(JNIEnv *env, jobject this, jboolean block, jobject fdo,
                                     jint group, jint interf, jint source)
 {
+#ifdef MACOSX
+    /* no IPv4 exclude-mode filtering for now */
+    return IOS_UNAVAILABLE;
+#else
     struct my_ip_mreq_source mreq_source;
     int n;
     int opt = (block) ? IP_BLOCK_SOURCE : IP_UNBLOCK_SOURCE;
@@ -456,6 +556,7 @@
         handleSocketError(env, errno);
     }
     return 0;
+#endif
 }
 
 JNIEXPORT jint JNICALL
@@ -475,8 +576,8 @@
         optval = (void*)&mreq6;
         optlen = sizeof(mreq6);
     } else {
-#ifdef __linux__
-        /* Include-mode filtering broken on Linux at least to 2.6.24 */
+#if defined (__linux__) || defined(MACOSX)
+        /* Include-mode filtering broken on Mac OS & Linux at least to 2.6.24 */
         return IOS_UNAVAILABLE;
 #else
         initGroupSourceReq(env, group, index, source, &req);
@@ -504,6 +605,10 @@
                                     jbyteArray group, jint index, jbyteArray source)
 {
 #ifdef AF_INET6
+  #ifdef MACOSX
+    /* no IPv6 exclude-mode filtering for now */
+    return IOS_UNAVAILABLE;
+  #else
     struct my_group_source_req req;
     int n;
     int opt = (block) ? MCAST_BLOCK_SOURCE : MCAST_UNBLOCK_SOURCE;
@@ -518,6 +623,7 @@
         handleSocketError(env, errno);
     }
     return 0;
+  #endif
 #else
     JNU_ThrowInternalError(env, "Should not get here");
     return IOS_THROWN;
@@ -528,7 +634,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 +665,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 +708,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/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 596dd99..f921574 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);
     }
 }
 
@@ -1071,6 +1090,10 @@
 {
 #ifdef __solaris__
     struct extmnttab ent;
+#elif defined(_ALLBSD_SOURCE)
+    char buf[1024];
+    char *str;
+    char *last;
 #else
     struct mntent ent;
     char buf[1024];
@@ -1099,6 +1122,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 7699828..ee46c73 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
 #ifdef O_NOFOLLOW
     DEFX(O_NOFOLLOW);
 #else
@@ -111,7 +116,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);
     DEF(EMFILE);
 
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 b763bc2..6cdeb62 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 c737981..c0fc2ab 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..9d46ad3
--- /dev/null
+++ b/jdk/src/solaris/native/sun/tools/attach/BsdVirtualMachine.c
@@ -0,0 +1,307 @@
+/*
+ * Copyright 2005, 2012, Oracle and/or its affiliates. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute 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/syslimits.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);
+    }
+}
+
+/*
+ * Class:     sun_tools_attach_BSDVirtualMachine
+ * Method:    getTempDir
+ * Signature: (V)Ljava.lang.String;
+ */
+JNIEXPORT jstring JNICALL Java_sun_tools_attach_BsdVirtualMachine_getTempDir(JNIEnv *env, jclass cls)
+{
+    // 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
+    static char *temp_path = NULL;
+    char temp_path_storage[PATH_MAX];
+    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 JNU_NewStringPlatform(env, temp_path);
+#else /* __APPLE__ */
+    return (*env)->NewStringUTF(env, "/tmp");
+#endif /* __APPLE__ */
+}
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/bin/java_md.c b/jdk/src/windows/bin/java_md.c
index b8665f3..a301ff7 100644
--- a/jdk/src/windows/bin/java_md.c
+++ b/jdk/src/windows/bin/java_md.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -171,7 +171,8 @@
 void
 CreateExecutionEnvironment(int *pargc, char ***pargv,
                            char *jrepath, jint so_jrepath,
-                           char *jvmpath, jint so_jvmpath) {
+                           char *jvmpath, jint so_jvmpath,
+                           char *jvmcfg,  jint so_jvmcfg) {
     char * jvmtype;
     int i = 0;
     int running = CURRENT_DATA_MODEL;
@@ -200,8 +201,11 @@
         exit(2);
     }
 
+    JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg",
+        jrepath, FILESEP, FILESEP, (char*)GetArch(), FILESEP);
+
     /* Find the specified JVM type */
-    if (ReadKnownVMs(jrepath, (char*)GetArch(), JNI_FALSE) < 1) {
+    if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) {
         JLI_ReportErrorMessage(CFG_ERROR7);
         exit(1);
     }
@@ -1323,3 +1327,33 @@
 }
 
 #endif /* ENABLE_AWT_PRELOAD */
+
+int
+JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
+        int argc, char **argv,
+        int mode, char *what, int ret)
+{
+    ShowSplashScreen();
+    return ContinueInNewThread(ifn, threadStackSize, argc, argv, mode, what, ret);
+}
+
+void
+PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm)
+{
+    // stubbed out for windows and *nixes.
+}
+
+void
+RegisterThread()
+{
+    // stubbed out for windows and *nixes.
+}
+
+/*
+ * on windows, we return a false to indicate this option is not applicable
+ */
+jboolean
+ProcessPlatformOption(const char *arg)
+{
+    return JNI_FALSE;
+}
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/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 268d6a5..0fd156b 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
diff --git a/jdk/test/ProblemList.txt b/jdk/test/ProblemList.txt
index 1a4d91e..8c48162 100644
--- a/jdk/test/ProblemList.txt
+++ b/jdk/test/ProblemList.txt
@@ -188,6 +188,20 @@
 sun/net/InetAddress/nameservice/simple/CacheTest.java		generic-all
 sun/net/InetAddress/nameservice/simple/DefaultCaching.java	generic-all
 
+# 7122846
+java/net/MulticastSocket/NoLoopbackPackets.java                  macosx-all
+java/net/MulticastSocket/SetLoopbackMode.java                    macosx-all
+
+# 7145658
+java/net/MulticastSocket/Test.java                               macosx-all
+
+#7143960
+java/net/DatagramSocket/SendDatagramToBadAddress.java            macosx-all
+
+# 7150552
+sun/net/www/protocol/http/B6299712.java                         macosx-all
+java/net/CookieHandler/CookieManagerTest.java                   macosx-all
+
 ############################################################################
 
 # jdk_io
@@ -198,6 +212,9 @@
 # 7076644
 java/io/File/Basic.java                                         windows-all
 
+# Test needs AWT window server, does not work headless
+java/io/Serializable/resolveClass/deserializeButton/run.sh      macosx-all
+
 ############################################################################
 
 # jdk_nio
@@ -208,6 +225,20 @@
 # 7052549
 java/nio/channels/FileChannel/ReleaseOnCloseDeadlock.java 	windows-all
 
+# 6963118
+java/nio/channels/Selector/Wakeup.java                          windows-all
+
+# 7133499, 7133497
+java/nio/channels/AsyncCloseAndInterrupt.java                   macosx-all
+java/nio/channels/AsynchronousFileChannel/Lock.java             macosx-all
+java/nio/channels/FileChannel/Transfer.java                     macosx-all
+
+# 7141822
+java/nio/channels/DatagramChannel/ChangingAddress.java          macosx-all
+
+# 7132677
+java/nio/channels/Selector/OutOfBand.java                       macosx-all
+
 ############################################################################
 
 # jdk_rmi
@@ -331,6 +362,9 @@
 tools/pack200/CommandLineTests.java                         	generic-all
 tools/pack200/Pack200Test.java                              	generic-all
 
+# 7150569
+tools/launcher/UnicodeTest.java                                 macosx-all
+
 ############################################################################
 
 # jdk_util
@@ -344,4 +378,8 @@
 # 7041639, Solaris DSA keypair generation bug
 java/util/TimeZone/TimeZoneDatePermissionCheck.sh               solaris-all
 
+# 7150557
+java/util/prefs/RemoveReadOnlyNode.java                         macosx-all
+java/util/prefs/RemoveUnregedListener.java                      macosx-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/PrivateTransportTest.sh b/jdk/test/com/sun/jdi/PrivateTransportTest.sh
index 89a306c..868d864 100644
--- a/jdk/test/com/sun/jdi/PrivateTransportTest.sh
+++ b/jdk/test/com/sun/jdi/PrivateTransportTest.sh
@@ -127,6 +127,9 @@
     xx=`find ${jreloc}/lib -name libdt_socket.so`
     libloc=`dirname ${xx}`
     ;;
+  Darwin)
+    libloc=${jreloc}/lib
+    ;;
   Windows*)
     is_windows=true
     libloc=${jreloc}/bin
@@ -160,6 +163,19 @@
     PATH="${PATH}${sep}${libdir}"
     export PATH
     echo PATH=${PATH}
+elif [ -f ${libloc}/libdt_socket.dylib ]; then
+    fullpath=${libdir}/lib${private_transport}.dylib
+    rm -f ${fullpath}
+    echo cp ${libloc}/libdt_socket.dylib ${fullpath}
+    cp ${libloc}/libdt_socket.dylib ${fullpath}
+    # make sure we can find libraries in current directory
+    if [ "${LD_LIBRARY_PATH}" = "" ] ; then
+        LD_LIBRARY_PATH=${libdir}
+    else
+        LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${libdir}
+    fi
+    export LD_LIBRARY_PATH
+    echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
 elif [ -f ${libloc}/libdt_socket.so ] ; then
     fullpath=${libdir}/lib${private_transport}.so
     rm -f ${fullpath}
diff --git a/jdk/test/com/sun/jdi/ShellScaffold.sh b/jdk/test/com/sun/jdi/ShellScaffold.sh
index 03c97bf..4e664c7 100644
--- a/jdk/test/com/sun/jdi/ShellScaffold.sh
+++ b/jdk/test/com/sun/jdi/ShellScaffold.sh
@@ -293,7 +293,7 @@
          psCmd=ps
          jstack=jstack.exe
          ;;
-       SunOS | Linux)
+       SunOS | Linux | Darwin)
          transport=dt_socket
          address=
          devnull=/dev/null
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/LdapUnicodeURL.java b/jdk/test/com/sun/jndi/ldap/LdapUnicodeURL.java
new file mode 100644
index 0000000..60f9759
--- /dev/null
+++ b/jdk/test/com/sun/jndi/ldap/LdapUnicodeURL.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 6961765
+ * @summary Double byte characters corrupted in DN for LDAP referrals
+ */
+
+import com.sun.jndi.ldap.LdapURL;
+
+public class LdapUnicodeURL {
+    public static void main(String[] args) throws Exception {
+        // First 3 characters of the CJK Unified Ideographs
+        String uid = "uid=\u4e00\u4e01\u4e02";
+        LdapURL ldURL = new LdapURL("ldap://www.example.com/" + uid);
+        if (!ldURL.getDN().equals(uid)) {
+            throw new Exception("uid changed to " + ldURL.getDN());
+        }
+    }
+}
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/demo/jvmti/DemoRun.java b/jdk/test/demo/jvmti/DemoRun.java
index b83b54d..9038507 100644
--- a/jdk/test/demo/jvmti/DemoRun.java
+++ b/jdk/test/demo/jvmti/DemoRun.java
@@ -123,7 +123,8 @@
         String os_arch   = System.getProperty("os.arch");
         String os_name   = System.getProperty("os.name");
         String libprefix = os_name.contains("Windows")?"":"lib";
-        String libsuffix = os_name.contains("Windows")?".dll":".so";
+        String libsuffix = os_name.contains("Windows")?".dll":
+                                os_name.startsWith("Mac OS")?".dylib":".so";
         boolean d64      =    ( os_name.contains("Solaris") ||
                                 os_name.contains("SunOS") )
                            && ( os_arch.equals("sparcv9") ||
diff --git a/jdk/test/java/beans/PropertyChangeSupport/Test7148143.java b/jdk/test/java/beans/PropertyChangeSupport/Test7148143.java
new file mode 100644
index 0000000..3ccf9a4
--- /dev/null
+++ b/jdk/test/java/beans/PropertyChangeSupport/Test7148143.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 7148143
+ * @summary Tests ClassCastException for the PropertyChangeSupport class
+ * @author Sergey Malenkov
+ */
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.EventListener;
+import java.util.EventListenerProxy;
+
+public class Test7148143 {
+
+    private static class CustomProxy
+            extends EventListenerProxy<EventListener>
+            implements PropertyChangeListener {
+
+        public CustomProxy() {
+            super(new EventListener() {
+            });
+        }
+
+        public void propertyChange(PropertyChangeEvent event) {
+        }
+    }
+
+    public static void main(String[] args) {
+        PropertyChangeListener listener = new CustomProxy();
+        PropertyChangeSupport support = new PropertyChangeSupport(listener);
+        support.addPropertyChangeListener(listener);
+        support.addPropertyChangeListener("foo", listener); // cast class exception
+    }
+}
diff --git a/jdk/test/java/beans/VetoableChangeSupport/Test7148143.java b/jdk/test/java/beans/VetoableChangeSupport/Test7148143.java
new file mode 100644
index 0000000..c44c321
--- /dev/null
+++ b/jdk/test/java/beans/VetoableChangeSupport/Test7148143.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 7148143
+ * @summary Tests ClassCastException for the VetoableChangeSupport class
+ * @author Sergey Malenkov
+ */
+
+import java.beans.PropertyChangeEvent;
+import java.beans.VetoableChangeListener;
+import java.beans.VetoableChangeSupport;
+import java.util.EventListener;
+import java.util.EventListenerProxy;
+
+public class Test7148143 {
+
+    private static class CustomProxy
+            extends EventListenerProxy<EventListener>
+            implements VetoableChangeListener {
+
+        public CustomProxy() {
+            super(new EventListener() {
+            });
+        }
+
+        public void vetoableChange(PropertyChangeEvent event) {
+        }
+    }
+
+    public static void main(String[] args) {
+        VetoableChangeListener listener = new CustomProxy();
+        VetoableChangeSupport support = new VetoableChangeSupport(listener);
+        support.addVetoableChangeListener(listener);
+        support.addVetoableChangeListener("foo", listener); // cast class exception
+    }
+}
diff --git a/jdk/test/java/io/File/GetXSpace.java b/jdk/test/java/io/File/GetXSpace.java
index 8868b54..9276ef5 100644
--- a/jdk/test/java/io/File/GetXSpace.java
+++ b/jdk/test/java/io/File/GetXSpace.java
@@ -50,7 +50,8 @@
     private static final String name = System.getProperty("os.name");
     private static final String dfFormat;
     static {
-        if (name.equals("SunOS") || name.equals("Linux")) {
+        if (name.equals("SunOS") || name.equals("Linux")
+                || name.startsWith("Mac OS")) {
             // FileSystem Total Used Available Use% MountedOn
             dfFormat = "([^\\s]+)\\s+(\\d+)\\s+\\d+\\s+(\\d+)\\s+\\d+%\\s+([^\\s]+)";
         } else if (name.startsWith("Windows")) {
diff --git a/jdk/test/java/io/File/isDirectory/Applet.java b/jdk/test/java/io/File/isDirectory/Applet.java
deleted file mode 100644
index 03f1d1c..0000000
--- a/jdk/test/java/io/File/isDirectory/Applet.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please 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 4054511
-   @summary Check that applets don't get a security exception when invoking
-            the File.isDirectory method on a non-existent directory
-   @author Mark Reinhold
-   @run applet Applet.html
- */
-
-import java.io.*;
-
-
-public class Applet extends java.applet.Applet {
-
-    void go(String fn) {
-        File f = new File(fn);
-        System.err.println(fn + ": " + f.isDirectory());
-    }
-
-    public void init() {
-        String nxdir = "non_EX_is_TENT_dir_EC_tory";
-        go(nxdir);
-        go(nxdir + File.separator + "bar" + File.separator + "baz");
-    }
-
-}
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 acdf9bb..06126d0 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 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 a9ba3b3..4397c2c 100644
--- a/jdk/test/java/lang/ProcessBuilder/Basic.java
+++ b/jdk/test/java/lang/ProcessBuilder/Basic.java
@@ -40,6 +40,7 @@
 import java.util.concurrent.CountDownLatch;
 import java.security.*;
 import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 import static java.lang.System.getenv;
 import static java.lang.System.out;
 import static java.lang.Boolean.TRUE;
@@ -50,6 +51,9 @@
     /* used for Windows only */
     static final String systemRoot = System.getenv("SystemRoot");
 
+    /* used for Mac OS X only */
+    static final String cfUserTextEncoding = System.getenv("__CF_USER_TEXT_ENCODING");
+
     private static String commandOutput(Reader r) throws Throwable {
         StringBuilder sb = new StringBuilder();
         int c;
@@ -590,6 +594,12 @@
             ! osName.equals("Windows Me");
     }
 
+    static class MacOSX {
+        public static boolean is() { return is; }
+        private static final String osName = System.getProperty("os.name");
+        private static final boolean is = osName.startsWith("Mac OS");
+    }
+
     static class True {
         public static int exitValue() { return 0; }
     }
@@ -629,6 +639,32 @@
         return Pattern.compile(regex).matcher(str).find();
     }
 
+    private static String matchAndExtract(String str, String regex) {
+        Matcher matcher = Pattern.compile(regex).matcher(str);
+        if (matcher.find()) {
+            return matcher.group();
+        } else {
+            return "";
+        }
+    }
+
+    /* Only used for Mac OS X --
+     * Mac OS X (may) add the variable __CF_USER_TEXT_ENCODING to an empty
+     * environment. The environment variable JAVA_MAIN_CLASS_<pid> may also
+     * be set in Mac OS X.
+     * Remove them both from the list of env variables
+     */
+    private static String removeMacExpectedVars(String vars) {
+        // Check for __CF_USER_TEXT_ENCODING
+        String cleanedVars = vars.replace("__CF_USER_TEXT_ENCODING="
+                                            +cfUserTextEncoding+",","");
+        // Check for JAVA_MAIN_CLASS_<pid>
+        String javaMainClassStr
+                = matchAndExtract(cleanedVars,
+                                    "JAVA_MAIN_CLASS_\\d+=Basic.JavaChild,");
+        return cleanedVars.replace(javaMainClassStr,"");
+    }
+
     private static String sortByLinesWindowsly(String text) {
         String[] lines = text.split("\n");
         Arrays.sort(lines, new WindowsComparator());
@@ -1080,7 +1116,11 @@
             if (Windows.is()) {
                 pb.environment().put("SystemRoot", systemRoot);
             }
-            equal(getenvInChild(pb), expected);
+            String result = getenvInChild(pb);
+            if (MacOSX.is()) {
+                result = removeMacExpectedVars(result);
+            }
+            equal(result, expected);
         } catch (Throwable t) { unexpected(t); }
 
         //----------------------------------------------------------------
@@ -1594,7 +1634,11 @@
             }
             Process p = Runtime.getRuntime().exec(cmdp, envp);
             String expected = Windows.is() ? "=C:=\\,SystemRoot="+systemRoot+",=ExitValue=3," : "=C:=\\,";
-            equal(commandOutput(p), expected);
+            String commandOutput = commandOutput(p);
+            if (MacOSX.is()) {
+                commandOutput = removeMacExpectedVars(commandOutput);
+            }
+            equal(commandOutput, expected);
             if (Windows.is()) {
                 ProcessBuilder pb = new ProcessBuilder(childArgs);
                 pb.environment().clear();
@@ -1632,8 +1676,22 @@
             } 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,"),
+            String commandOutput = commandOutput(p);
+            if (MacOSX.is()) {
+                commandOutput = removeMacExpectedVars(commandOutput);
+            }
+            check(commandOutput.equals(Windows.is()
+                    ? "SystemRoot="+systemRoot+",LC_ALL=C,"
+                    : "LC_ALL=C,"),
                   "Incorrect handling of envstrings containing NULs");
         } catch (Throwable t) { unexpected(t); }
 
diff --git a/jdk/test/java/lang/ProcessBuilder/Zombies.java b/jdk/test/java/lang/ProcessBuilder/Zombies.java
index 6e61ec3..210d831 100644
--- a/jdk/test/java/lang/ProcessBuilder/Zombies.java
+++ b/jdk/test/java/lang/ProcessBuilder/Zombies.java
@@ -31,6 +31,12 @@
 import java.io.*;
 
 public class Zombies {
+
+    static final String os = System.getProperty("os.name");
+
+    static final String TrueCommand = os.startsWith("Mac OS")?
+        "/usr/bin/true" : "/bin/true";
+
     public static void main(String[] args) throws Throwable {
         if (! new File("/usr/bin/perl").canExecute() ||
             ! new File("/bin/ps").canExecute())
@@ -49,11 +55,11 @@
         } catch (IOException _) {/* OK */}
 
         try {
-            rt.exec("/bin/true", null, new File("no-such-dir"));
+            rt.exec(TrueCommand, null, new File("no-such-dir"));
             throw new Error("expected IOException not thrown");
         } catch (IOException _) {/* OK */}
 
-        rt.exec("/bin/true").waitFor();
+        rt.exec(TrueCommand).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/GetSystemLoadAverage.java b/jdk/test/java/lang/management/OperatingSystemMXBean/GetSystemLoadAverage.java
index ce14c88..882c9b3 100644
--- a/jdk/test/java/lang/management/OperatingSystemMXBean/GetSystemLoadAverage.java
+++ b/jdk/test/java/lang/management/OperatingSystemMXBean/GetSystemLoadAverage.java
@@ -79,7 +79,11 @@
         System.out.println("Test passed.");
     }
 
-    private static String LOAD_AVERAGE_TEXT = "load average:";
+    private static String LOAD_AVERAGE_TEXT
+            = System.getProperty("os.name").startsWith("Mac OS")
+                ? "load averages:"
+                : "load average:";
+
     private static void checkLoadAvg() throws Exception {
         // Obtain load average from OS command
         ProcessBuilder pb = new ProcessBuilder("/usr/bin/uptime");
@@ -91,11 +95,13 @@
 
         // verify if two values are close
         output = output.substring(output.lastIndexOf(LOAD_AVERAGE_TEXT) +
-                                  LOAD_AVERAGE_TEXT.length());
+                                  LOAD_AVERAGE_TEXT.length() + 1);
         System.out.println("Load average returned from uptime = " + output);
         System.out.println("getSystemLoadAverage() returned " + loadavg);
 
-        String[] lavg = output.split(",");
+        String[] lavg = System.getProperty("os.name").startsWith("Mac OS")
+                ? output.split(" ")
+                : output.split(",");
         double expected = Double.parseDouble(lavg[0]);
         double lowRange = expected * (1 - DELTA);
         double highRange = expected * (1 + DELTA);
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/SendDatagramToBadAddress.java b/jdk/test/java/net/DatagramSocket/SendDatagramToBadAddress.java
index e69d790..cfe06b9 100644
--- a/jdk/test/java/net/DatagramSocket/SendDatagramToBadAddress.java
+++ b/jdk/test/java/net/DatagramSocket/SendDatagramToBadAddress.java
@@ -45,6 +45,8 @@
             return (true);
         if (p.getProperty ("os.name").equals ("Linux"))
             return (true);
+        if (p.getProperty ("os.name").startsWith ("Mac OS"))
+            return (true);
         // Check for specific Solaris version from here
         v = p.getProperty ("os.arch");
         if (!v.equalsIgnoreCase ("sparc"))
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/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/OpenStream.java b/jdk/test/java/net/URL/OpenStream.java
index 4f9ee306..2b5b450 100644
--- a/jdk/test/java/net/URL/OpenStream.java
+++ b/jdk/test/java/net/URL/OpenStream.java
@@ -39,7 +39,7 @@
         URL u = new URL(badHttp);
         try {
             InputStream in = u.openStream();
-        } catch (UnknownHostException x) {
+        } catch (IOException x) {
             return;
         }
         throw new RuntimeException("Expected UnknownHostException to be thrown");
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/nio/channels/DatagramChannel/Refused.java b/jdk/test/java/nio/channels/DatagramChannel/Refused.java
index c44dd37..6278804 100644
--- a/jdk/test/java/nio/channels/DatagramChannel/Refused.java
+++ b/jdk/test/java/nio/channels/DatagramChannel/Refused.java
@@ -104,16 +104,9 @@
             Thread.sleep(2000);
             inBuf.clear();
             server.read(inBuf);
-            if (onSolarisOrLinux())
-                throw new Exception("Expected PUE not thrown");
         } catch (PortUnreachableException pue) {
             System.err.println("received PUE");
         }
         server.close();
     }
-
-    static boolean onSolarisOrLinux() {
-        String osName = System.getProperty("os.name");
-        return osName.startsWith("SunOS") || osName.startsWith("Linux");
-    }
 }
diff --git a/jdk/test/java/nio/channels/FileChannel/Size.java b/jdk/test/java/nio/channels/FileChannel/Size.java
index 09f9eb1..ffa0720 100644
--- a/jdk/test/java/nio/channels/FileChannel/Size.java
+++ b/jdk/test/java/nio/channels/FileChannel/Size.java
@@ -69,7 +69,7 @@
         // Windows and Linux can't handle the really large file sizes for a truncate
         // or a positional write required by the test for 4563125
         String osName = System.getProperty("os.name");
-        if (osName.startsWith("SunOS")) {
+        if (osName.startsWith("SunOS") || osName.startsWith("Mac OS")) {
             blah = File.createTempFile("blah", null);
             long testSize = ((long)Integer.MAX_VALUE) * 2;
             initTestFile(blah, 10);
diff --git a/jdk/test/java/nio/channels/FileChannel/Transfer.java b/jdk/test/java/nio/channels/FileChannel/Transfer.java
index 0807ead..0e18f54 100644
--- a/jdk/test/java/nio/channels/FileChannel/Transfer.java
+++ b/jdk/test/java/nio/channels/FileChannel/Transfer.java
@@ -228,9 +228,8 @@
         // Windows and Linux can't handle the really large file sizes for a
         // truncate or a positional write required by the test for 4563125
         String osName = System.getProperty("os.name");
-        if (!osName.startsWith("SunOS"))
+        if (!(osName.startsWith("SunOS") || osName.startsWith("Mac OS")))
             return;
-
         File source = File.createTempFile("blah", null);
         source.deleteOnExit();
         long testSize = ((long)Integer.MAX_VALUE) * 2;
diff --git a/jdk/test/java/nio/charset/coders/CheckSJISMappingProp.sh b/jdk/test/java/nio/charset/coders/CheckSJISMappingProp.sh
index 3ff5841..8b39428 100644
--- a/jdk/test/java/nio/charset/coders/CheckSJISMappingProp.sh
+++ b/jdk/test/java/nio/charset/coders/CheckSJISMappingProp.sh
@@ -34,7 +34,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux ) ;;
+  SunOS | Linux | Darwin ) ;;
   # Skip locale test for Windows
   Windows* | CYGWIN* )
     echo "Passed"; exit 0 ;;
@@ -67,7 +67,7 @@
   expectPass $?
 }
 
-# Run the test in the common Solaris/Linux locales
+# Run the test in the common Solaris/Linux/Mac OS locales
 # Tests will simply run in current locale if locale isn't supported
 # on the test machine/platform
 
diff --git a/jdk/test/java/nio/charset/spi/basic.sh b/jdk/test/java/nio/charset/spi/basic.sh
index 2444581..330e4d0 100644
--- a/jdk/test/java/nio/charset/spi/basic.sh
+++ b/jdk/test/java/nio/charset/spi/basic.sh
@@ -47,7 +47,7 @@
 
 DIR=`pwd`
 case `uname` in
-  SunOS | Linux ) CPS=':' ;;
+  SunOS | Linux | Darwin ) CPS=':' ;;
   Windows* )      CPS=';' ;;
   CYGWIN*  )
     DIR=`/usr/bin/cygpath -a -s -m $DIR`
@@ -80,7 +80,7 @@
     L="$1"
     shift
     s=`uname -s`
-    if [ $s != Linux -a $s != SunOS ]; then
+    if [ $s != Linux -a $s != SunOS -a $s != Darwin ]; then
       echo "$L: Locales not supported on this system, skipping..."
       exit 0
     fi
diff --git a/jdk/test/java/nio/file/FileSystem/Basic.java b/jdk/test/java/nio/file/FileSystem/Basic.java
index 0717d07..a2ff3bf 100644
--- a/jdk/test/java/nio/file/FileSystem/Basic.java
+++ b/jdk/test/java/nio/file/FileSystem/Basic.java
@@ -76,6 +76,8 @@
             checkSupported(fs, "posix", "unix", "owner", "acl", "user");
         if (os.equals("Linux"))
             checkSupported(fs, "posix", "unix", "owner", "dos", "user");
+        if (os.startsWith("Mac OS"))
+            checkSupported(fs, "posix", "unix", "owner");
         if (os.equals("Windows"))
             checkSupported(fs, "owner", "dos", "acl", "user");
     }
diff --git a/jdk/test/java/nio/file/Files/CopyAndMove.java b/jdk/test/java/nio/file/Files/CopyAndMove.java
index a9cd87b..9ac27af 100644
--- a/jdk/test/java/nio/file/Files/CopyAndMove.java
+++ b/jdk/test/java/nio/file/Files/CopyAndMove.java
@@ -153,13 +153,12 @@
 
         // get file attributes of source file
         String os = System.getProperty("os.name");
-        if (os.equals("SunOS") || os.equals("Linux")) {
-            posixAttributes = readAttributes(source, PosixFileAttributes.class, NOFOLLOW_LINKS);
-            basicAttributes = posixAttributes;
-        }
         if (os.startsWith("Windows")) {
             dosAttributes = readAttributes(source, DosFileAttributes.class, NOFOLLOW_LINKS);
             basicAttributes = dosAttributes;
+        } else {
+            posixAttributes = readAttributes(source, PosixFileAttributes.class, NOFOLLOW_LINKS);
+            basicAttributes = posixAttributes;
         }
         if (basicAttributes == null)
             basicAttributes = readAttributes(source, BasicFileAttributes.class, NOFOLLOW_LINKS);
diff --git a/jdk/test/java/nio/file/Path/PathOps.java b/jdk/test/java/nio/file/Path/PathOps.java
index 03177f0..6c25213 100644
--- a/jdk/test/java/nio/file/Path/PathOps.java
+++ b/jdk/test/java/nio/file/Path/PathOps.java
@@ -991,8 +991,7 @@
         String osname = System.getProperty("os.name");
         if (osname.startsWith("Windows")) {
             doWindowsTests();
-        }
-        if (osname.equals("SunOS") || osname.equals("Linux")) {
+        } else {
             doUnixTests();
         }
 
diff --git a/jdk/test/java/rmi/registry/readTest/readTest.sh b/jdk/test/java/rmi/registry/readTest/readTest.sh
index 54be1d7..cb600d5 100644
--- a/jdk/test/java/rmi/registry/readTest/readTest.sh
+++ b/jdk/test/java/rmi/registry/readTest/readTest.sh
@@ -28,7 +28,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     FILEURL="file:"
diff --git a/jdk/test/java/security/Security/ClassLoaderDeadlock/ClassLoaderDeadlock.sh b/jdk/test/java/security/Security/ClassLoaderDeadlock/ClassLoaderDeadlock.sh
index ab6d609..57af501 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,18 @@
 
 # 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" \
+	-Djava.awt.headless=true \
+        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 bf25695..53803a6 100644
--- a/jdk/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.sh
+++ b/jdk/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.sh
@@ -62,6 +62,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/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/Bug6530694.java b/jdk/test/java/util/ResourceBundle/Control/Bug6530694.java
index 7f22cc9..7463681 100644
--- a/jdk/test/java/util/ResourceBundle/Control/Bug6530694.java
+++ b/jdk/test/java/util/ResourceBundle/Control/Bug6530694.java
@@ -24,7 +24,7 @@
  * @bug 6530694
  * @summary Checks that sun.util.CoreResourceBundleControl does not apply
  *     to the application provided Swing resources.
- * @run main/othervm Bug6530694
+ * @run main/othervm -Djava.awt.headless=true Bug6530694
  */
 
 import java.util.Locale;
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/java/util/concurrent/locks/Lock/TimedAcquireLeak.java b/jdk/test/java/util/concurrent/locks/Lock/TimedAcquireLeak.java
index ad0af9e..72b8f8a 100644
--- a/jdk/test/java/util/concurrent/locks/Lock/TimedAcquireLeak.java
+++ b/jdk/test/java/util/concurrent/locks/Lock/TimedAcquireLeak.java
@@ -28,6 +28,8 @@
  * @author Martin Buchholz
  */
 
+// Note: this file is now out of sync with the jsr166 CVS repository due to the fix for 7092140
+
 import java.util.*;
 import java.util.regex.*;
 import java.util.concurrent.*;
@@ -148,7 +150,7 @@
             String.valueOf(new Random().nextInt(Integer.MAX_VALUE));
 
         final String[] jobCmd = {
-            java, "-Xmx8m",
+            java, "-Xmx8m", "-XX:+UsePerfData",
             "-classpath", System.getProperty("test.classes", "."),
             childClassName, uniqueID
         };
diff --git a/jdk/test/java/util/logging/LoggingDeadlock4.java b/jdk/test/java/util/logging/LoggingDeadlock4.java
index 6dbc00f..3995625 100644
--- a/jdk/test/java/util/logging/LoggingDeadlock4.java
+++ b/jdk/test/java/util/logging/LoggingDeadlock4.java
@@ -27,7 +27,7 @@
  * @summary Deadlock between LogManager.<clinit> and Logger.getLogger()
  * @author  Daniel D. Daugherty
  * @build LoggingDeadlock4
- * @run main/timeout=15 LoggingDeadlock4
+ * @run main/othervm/timeout=15 -Djava.awt.headless=true LoggingDeadlock4
  */
 
 import java.awt.Container;
diff --git a/jdk/test/java/util/zip/ZipFile/ManyZipFiles.java b/jdk/test/java/util/zip/ZipFile/ManyZipFiles.java
index 7f64681..fe2da99 100644
--- a/jdk/test/java/util/zip/ZipFile/ManyZipFiles.java
+++ b/jdk/test/java/util/zip/ZipFile/ManyZipFiles.java
@@ -45,7 +45,7 @@
         // Windows capability it is much simpler to only run it
         // on that platform.
         String osName = System.getProperty("os.name");
-        if (osName.startsWith("Linux") || osName.startsWith("SunOS")) {
+        if (!(osName.startsWith("Windows"))) {
             return;
         }
 
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/JFileChooser/4524490/bug4524490.java b/jdk/test/javax/swing/JFileChooser/4524490/bug4524490.java
new file mode 100644
index 0000000..aedfdc1
--- /dev/null
+++ b/jdk/test/javax/swing/JFileChooser/4524490/bug4524490.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 4524490
+ * @summary Tests if in JFileChooser, ALT+L does not bring focus to 'Files' selection list in Motif LAF
+ * @library ../../regtesthelpers
+ * @build Util
+ * @author Konstantin Eremin
+ * @run main bug4524490
+ */
+import java.awt.Robot;
+import java.awt.Toolkit;
+import java.awt.event.KeyEvent;
+import javax.swing.*;
+import sun.awt.OSInfo;
+import sun.awt.SunToolkit;
+
+public class bug4524490 {
+
+    private static JFileChooser fileChooser;
+
+    public static void main(String[] args) throws Exception {
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+        Robot robot = new Robot();
+        robot.setAutoDelay(50);
+
+        UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
+
+        SwingUtilities.invokeLater(new Runnable() {
+
+            public void run() {
+                fileChooser = new JFileChooser();
+                fileChooser.showOpenDialog(null);
+            }
+        });
+
+        toolkit.realSync();
+
+        if (OSInfo.OSType.MACOSX.equals(OSInfo.getOSType())) {
+            Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_L);
+        } else {
+            Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_L);
+        }
+        checkFocus();
+    }
+
+    private static void checkFocus() throws Exception {
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                JList list = (JList) Util.findSubComponent(fileChooser, "javax.swing.JList");
+                System.out.println("list focus: " + list.isFocusOwner());
+                if (!list.isFocusOwner()) {
+                    throw new RuntimeException("Focus is not transfered to the Folders list.");
+                }
+            }
+        });
+    }
+}
diff --git a/jdk/test/javax/swing/JMenuItem/6209975/bug6209975.java b/jdk/test/javax/swing/JMenuItem/6209975/bug6209975.java
new file mode 100644
index 0000000..fc75658
--- /dev/null
+++ b/jdk/test/javax/swing/JMenuItem/6209975/bug6209975.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 6209975
+ * @summary regression: JMenuItem icons overimposed on JMenuItem labels under Metal LAF
+ * @library ../../regtesthelpers
+ * @build Util
+ * @author Alexander Zuev
+ * @run main bug6209975
+ */
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.InputEvent;
+import sun.awt.SunToolkit;
+
+public class bug6209975 {
+
+    private static final ReturnObject RO1 = new ReturnObject();
+    private static final ReturnObject RO2 = new ReturnObject();
+
+    private static JMenu menu;
+    private static JButton button;
+
+    public static void main(String[] args) throws Exception {
+
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+        Robot robot = new Robot();
+        robot.setAutoDelay(500);
+
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                createAndShowGUI();
+            }
+        });
+
+        toolkit.realSync();
+
+        Point clickPoint = getButtonClickPoint();
+        robot.mouseMove(clickPoint.x, clickPoint.y);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
+        toolkit.realSync();
+
+        clickPoint = getMenuClickPoint();
+        robot.mouseMove(clickPoint.x, clickPoint.y);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
+        toolkit.realSync();
+
+        if (RO1.itsValue <= RO2.itsValue) {
+            throw new RuntimeException("Offset if the second icon is invalid.");
+        }
+    }
+
+    private static Point getButtonClickPoint() throws Exception {
+        final Point[] result = new Point[1];
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                Point p = button.getLocationOnScreen();
+                Dimension size = button.getSize();
+                result[0] = new Point(p.x + size.width / 2, p.y + size.height / 2);
+            }
+        });
+        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 = menu.getLocationOnScreen();
+                Dimension size = menu.getSize();
+                result[0] = new Point(p.x + size.width / 2, p.y + size.height / 2);
+            }
+        });
+        return result[0];
+    }
+
+    private static void createAndShowGUI() {
+        JFrame frame = new JFrame("Test6209975");
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        frame.applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
+        frame.setLayout(new BorderLayout());
+        button = new JButton("Focus holder");
+        frame.add(button);
+
+        JMenuBar mb = new JMenuBar();
+        menu = new JMenu("File");
+
+        JMenuItem item;
+
+        item = new JMenuItem("Just a menu item");
+        item.setIcon(new MyIcon(RO1));
+        item.setHorizontalTextPosition(SwingConstants.LEADING);
+        menu.add(item);
+
+        item = new JMenuItem("Menu Item with another icon");
+        item.setIcon(new MyIcon(RO2));
+        item.setHorizontalTextPosition(SwingConstants.TRAILING);
+        menu.add(item);
+
+        mb.add(menu);
+
+        frame.setJMenuBar(mb);
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        frame.pack();
+        frame.setLocation(400, 300);
+        frame.setVisible(true);
+    }
+
+    public static class ReturnObject {
+
+        public volatile int itsValue;
+    }
+
+    public static class MyIcon implements Icon {
+
+        ReturnObject thisObject = null;
+
+        public MyIcon(ReturnObject ro) {
+            super();
+            thisObject = ro;
+        }
+
+        public void paintIcon(Component c, Graphics g, int x, int y) {
+            Color color = g.getColor();
+            g.setColor(Color.BLACK);
+            g.fillRect(x, y, 10, 10);
+            g.setColor(color);
+            thisObject.itsValue = x;
+        }
+
+        public int getIconWidth() {
+            return 10;
+        }
+
+        public int getIconHeight() {
+            return 10;
+        }
+    }
+}
diff --git a/jdk/test/javax/swing/SwingUtilities/7146377/bug7146377.java b/jdk/test/javax/swing/SwingUtilities/7146377/bug7146377.java
new file mode 100644
index 0000000..5b5c2b1
--- /dev/null
+++ b/jdk/test/javax/swing/SwingUtilities/7146377/bug7146377.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 7146377
+   @summary closed/javax/swing/DataTransfer/4876520/bug4876520.java failed since b08 in jdk 8
+   @author Pavel Porvatov
+*/
+
+import sun.awt.SunToolkit;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+
+public class bug7146377 {
+    private static JLabel label;
+    private static JFrame frame;
+
+    private static volatile Point point;
+
+    public static void main(String[] args) throws Exception {
+        SwingUtilities.invokeAndWait(new Runnable() {
+            public void run() {
+                frame = new JFrame();
+
+                label = new JLabel("A label");
+
+                label.addMouseListener(new MouseListener() {
+                    @Override
+                    public void mouseClicked(MouseEvent e) {
+                        checkEvent(e);
+                    }
+
+                    @Override
+                    public void mousePressed(MouseEvent e) {
+                        checkEvent(e);
+                    }
+
+                    @Override
+                    public void mouseReleased(MouseEvent e) {
+                        checkEvent(e);
+                    }
+
+                    @Override
+                    public void mouseEntered(MouseEvent e) {
+                        checkEvent(e);
+                    }
+
+                    @Override
+                    public void mouseExited(MouseEvent e) {
+                        checkEvent(e);
+                    }
+                });
+
+                frame.add(label);
+                frame.setSize(200, 100);
+                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+                frame.setVisible(true);
+            }
+        });
+
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+
+        toolkit.realSync();
+
+        // On Linux platforms realSync doesn't guaranties setSize completion
+        Thread.sleep(1000);
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            public void run() {
+                point = label.getLocationOnScreen();
+            }
+        });
+
+        Robot robot = new Robot();
+
+        robot.setAutoDelay(200);
+
+        // Move mouse
+        for (int i = 0; i < 20; i++) {
+            robot.mouseMove(point.x + i, point.y + i);
+        }
+
+        for (int button : new int[]{InputEvent.BUTTON1_MASK, InputEvent.BUTTON2_MASK, InputEvent.BUTTON3_MASK}) {
+            robot.mouseMove(point.x, point.y);
+
+            // Mouse Drag
+            robot.mousePress(button);
+
+            for (int i = 0; i < 20; i++) {
+                robot.mouseMove(point.x + i, point.y + i);
+            }
+
+            robot.mouseRelease(button);
+        }
+
+        toolkit.realSync();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            public void run() {
+                frame.dispose();
+            }
+        });
+
+        System.out.println("Test passed");
+    }
+
+    private static void checkEvent(MouseEvent e) {
+        String eventAsStr = eventToString(e);
+
+        System.out.println("Checking event " + eventAsStr);
+
+        check("isLeftMouseButton", SwingUtilities.isLeftMouseButton(e), oldIsLeftMouseButton(e), eventAsStr);
+        check("isRightMouseButton", SwingUtilities.isRightMouseButton(e), oldIsRightMouseButton(e), eventAsStr);
+        check("isMiddleMouseButton", SwingUtilities.isMiddleMouseButton(e), oldIsMiddleMouseButton(e), eventAsStr);
+    }
+
+    private static void check(String methodName, boolean newValue, boolean oldValue, String eventAsStr) {
+        if (newValue != oldValue) {
+            throw new RuntimeException("Regression on " + methodName + ", newValue = " + newValue +
+                    ", oldValue = " + oldValue + ", e = " + eventAsStr);
+        }
+    }
+
+    private static String eventToString(MouseEvent e) {
+        StringBuilder result = new StringBuilder();
+
+        switch (e.getID()) {
+            case MouseEvent.MOUSE_PRESSED:
+                result.append("MOUSE_PRESSED");
+                break;
+            case MouseEvent.MOUSE_RELEASED:
+                result.append("MOUSE_RELEASED");
+                break;
+            case MouseEvent.MOUSE_CLICKED:
+                result.append("MOUSE_CLICKED");
+                break;
+            case MouseEvent.MOUSE_ENTERED:
+                result.append("MOUSE_ENTERED");
+                break;
+            case MouseEvent.MOUSE_EXITED:
+                result.append("MOUSE_EXITED");
+                break;
+            case MouseEvent.MOUSE_MOVED:
+                result.append("MOUSE_MOVED");
+                break;
+            case MouseEvent.MOUSE_DRAGGED:
+                result.append("MOUSE_DRAGGED");
+                break;
+            case MouseEvent.MOUSE_WHEEL:
+                result.append("MOUSE_WHEEL");
+                break;
+            default:
+                result.append("unknown type");
+        }
+
+        result.append(", modifiers = " + MouseEvent.getMouseModifiersText(e.getModifiers()));
+        result.append(", modifiersEx = " + MouseEvent.getMouseModifiersText(e.getModifiersEx()));
+        result.append(", button = " + e.getButton());
+
+        return result.toString();
+    }
+
+    // Original implementation of SwingUtilities.isLeftMouseButton
+    private static boolean oldIsLeftMouseButton(MouseEvent e) {
+        return ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0);
+    }
+
+    // Original implementation of SwingUtilities.isMiddleMouseButton
+    private static boolean oldIsMiddleMouseButton(MouseEvent e) {
+        return ((e.getModifiers() & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK);
+    }
+
+    // Original implementation of SwingUtilities.isRightMouseButton
+    private static boolean oldIsRightMouseButton(MouseEvent e) {
+        return ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK);
+    }
+}
diff --git a/jdk/test/lib/security/java.policy/Ext_AllPolicy.sh b/jdk/test/lib/security/java.policy/Ext_AllPolicy.sh
index c10d383..63e60b5 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="/"
@@ -78,6 +78,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 bfb3b0d..570631d 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
 #
 
@@ -42,7 +42,7 @@
 fi
 
 case $OS in
-SunOS | Linux)
+SunOS | Linux | Darwin)
     PATHSEP=":"
     FILESEP="/"
     DFILESEP=$FILESEP
@@ -67,12 +67,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
 
@@ -84,47 +84,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/nio/ch/SelProvider.java b/jdk/test/sun/nio/ch/SelProvider.java
index 3eba361..53b18cb 100644
--- a/jdk/test/sun/nio/ch/SelProvider.java
+++ b/jdk/test/sun/nio/ch/SelProvider.java
@@ -50,6 +50,8 @@
             } else {
                 throw new RuntimeException("Test does not recognize this operating system");
             }
+        } else if (osname.startsWith("Mac OS")) {
+            expected = "sun.nio.ch.PollSelectorProvider";
         } else
             return;
         if (!spName.equals(expected))
diff --git a/jdk/test/sun/security/krb5/runNameEquals.sh b/jdk/test/sun/security/krb5/runNameEquals.sh
index dca2052..0f0ab17 100644
--- a/jdk/test/sun/security/krb5/runNameEquals.sh
+++ b/jdk/test/sun/security/krb5/runNameEquals.sh
@@ -48,15 +48,14 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS )
+  SunOS | Linux )
     PATHSEP=":"
     FILESEP="/"
     NATIVE=true
     ;;
-  Linux )
+  Darwin )
     PATHSEP=":"
     FILESEP="/"
-    NATIVE=true
     ;;
   CYGWIN* )
     PATHSEP=";"
diff --git a/jdk/test/sun/security/pkcs11/KeyStore/SecretKeysBasic.sh b/jdk/test/sun/security/pkcs11/KeyStore/SecretKeysBasic.sh
index 917e90e..bfa08c8 100644
--- a/jdk/test/sun/security/pkcs11/KeyStore/SecretKeysBasic.sh
+++ b/jdk/test/sun/security/pkcs11/KeyStore/SecretKeysBasic.sh
@@ -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
@@ -99,6 +99,7 @@
 MKDIR="mkdir -p"
 CHMOD="chmod"
 
+
 STATUS=0
 for token in ${TOKENS}
 do
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/EngineArgs/DebugReportsOneExtraByte.sh b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.sh
index cfc3026..c2d14c7 100644
--- a/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.sh
+++ b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.sh
@@ -33,11 +33,7 @@
 
 OS=`uname -s`
 case "$OS" in
-  SunOS )
-    PS=":"
-    FS="/"
-    ;;
-  Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
@@ -78,3 +74,7 @@
     echo "Received the expected debug output."
     exit 0
 fi
+else
+    echo "Received the expected debug output."
+    exit 0
+fi
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 ade1777..35bb1e7 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="/"
@@ -84,7 +84,7 @@
 if [ $RESULT -eq 0 ]; then
     echo "test 1 failed"
     failed=1
-else 
+else
     echo "test 1 passed"
 fi
 
@@ -98,11 +98,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 \
@@ -112,11 +112,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 \
@@ -126,11 +126,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 \
@@ -140,11 +140,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 \
@@ -153,22 +153,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 \
@@ -177,17 +177,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
@@ -202,17 +202,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 550801a..b299452 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 26a228e..0927b2d 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 6bab6c9..a6c7464 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="/"
@@ -70,7 +70,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 f18c3fa..05dc50c 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="/"
@@ -76,7 +76,7 @@
     -storetype "dks" -provider "org.test.dummy.DummyProvider" \
     -providerPath ${TESTCLASSES}
 
-if [ $? -ne 0 ]; then 
+if [ $? -ne 0 ]; then
     exit 1
 fi
 
@@ -85,7 +85,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
 
@@ -96,7 +96,7 @@
     -storetype "dks" -storepass storepass2 \
     -provider "org.test.dummy.DummyProvider" -providerPath ${TESTCLASSES}
 
-if [ $? -ne 0 ]; then 
+if [ $? -ne 0 ]; then
     exit 1
 fi
 
@@ -106,7 +106,7 @@
     -storepass storepass2 -provider "org.test.dummy.DummyProvider" \
     -providerPath ${TESTCLASSES}
 
-if [ $? -ne 0 ]; then 
+if [ $? -ne 0 ]; then
     exit 1
 fi
 
@@ -115,7 +115,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 fc752ba..98e3df4 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 bea5f9a..b3d1c51 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="/"
@@ -72,19 +72,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 55de062..b21cf83 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="/"
     ;;
@@ -65,7 +65,7 @@
 ${TESTJAVA}${FS}bin${FS}keytool > temp_file_40875602475 2> ${NULL}
 grep MissingResourceException temp_file_40875602475
 
-if [ $? -eq 0 ]; then 
+if [ $? -eq 0 ]; then
     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/security/tools/policytool/Alias.sh b/jdk/test/sun/security/tools/policytool/Alias.sh
index cbc0a68..ee00695 100644
--- a/jdk/test/sun/security/tools/policytool/Alias.sh
+++ b/jdk/test/sun/security/tools/policytool/Alias.sh
@@ -23,8 +23,8 @@
 
 # @test
 # @bug 4449491
-# @summary policytool should allow principal type to be empty 
-#		(keystore alias substitution)
+# @summary policytool should allow principal type to be empty
+#               (keystore alias substitution)
 #
 # @run applet/manual=done Alias.html
 # @run shell Alias.sh
@@ -47,7 +47,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/policytool/ChangeUI.sh b/jdk/test/sun/security/tools/policytool/ChangeUI.sh
index ce1eb0e..b423c23 100644
--- a/jdk/test/sun/security/tools/policytool/ChangeUI.sh
+++ b/jdk/test/sun/security/tools/policytool/ChangeUI.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/policytool/OpenPolicy.sh b/jdk/test/sun/security/tools/policytool/OpenPolicy.sh
index 7a3016d..34952e0 100644
--- a/jdk/test/sun/security/tools/policytool/OpenPolicy.sh
+++ b/jdk/test/sun/security/tools/policytool/OpenPolicy.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/policytool/SaveAs.sh b/jdk/test/sun/security/tools/policytool/SaveAs.sh
index 3271571..fed21e4 100644
--- a/jdk/test/sun/security/tools/policytool/SaveAs.sh
+++ b/jdk/test/sun/security/tools/policytool/SaveAs.sh
@@ -24,7 +24,7 @@
 # @test
 # @bug 4252583
 # @summary policytool throws FileNotFoundException when user tries to
-#		save new policy file
+#               save new policy file
 #
 # @run applet/manual=done SaveAs.html
 # @run shell SaveAs.sh
@@ -47,7 +47,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/policytool/UpdatePermissions.sh b/jdk/test/sun/security/tools/policytool/UpdatePermissions.sh
index 4e2f229..81cf1f2 100644
--- a/jdk/test/sun/security/tools/policytool/UpdatePermissions.sh
+++ b/jdk/test/sun/security/tools/policytool/UpdatePermissions.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/policytool/UsePolicy.sh b/jdk/test/sun/security/tools/policytool/UsePolicy.sh
index 4b94670..697f8c4 100644
--- a/jdk/test/sun/security/tools/policytool/UsePolicy.sh
+++ b/jdk/test/sun/security/tools/policytool/UsePolicy.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/policytool/i18n.sh b/jdk/test/sun/security/tools/policytool/i18n.sh
index 7b5570f..5a30c02 100644
--- a/jdk/test/sun/security/tools/policytool/i18n.sh
+++ b/jdk/test/sun/security/tools/policytool/i18n.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/tools/common/CommonSetup.sh b/jdk/test/sun/tools/common/CommonSetup.sh
index 7853663..7d37dbe 100644
--- a/jdk/test/sun/tools/common/CommonSetup.sh
+++ b/jdk/test/sun/tools/common/CommonSetup.sh
Binary files differ
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/jinfo/Basic.sh b/jdk/test/sun/tools/jinfo/Basic.sh
index 432dd62..02ef9be 100644
--- a/jdk/test/sun/tools/jinfo/Basic.sh
+++ b/jdk/test/sun/tools/jinfo/Basic.sh
@@ -1,5 +1,4 @@
 #!/bin/sh
-
 #
 # Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -46,6 +45,10 @@
 
 runSA=true
 
+if [ $isMacos = true ]; then
+    runSA=false
+fi
+
 if [ $isLinux = true ]; then
     # Some Linux systems disable non-child ptrace (see 7050524)
     ptrace_scope=`/sbin/sysctl -n kernel.yama.ptrace_scope`
diff --git a/jdk/test/sun/tools/jrunscript/common.sh b/jdk/test/sun/tools/jrunscript/common.sh
index 2b5bfd6..8fd6df5 100644
--- a/jdk/test/sun/tools/jrunscript/common.sh
+++ b/jdk/test/sun/tools/jrunscript/common.sh
@@ -63,4 +63,8 @@
     JRUNSCRIPT="${TESTJAVA}/bin/jrunscript"
     JAVAC="${TESTJAVA}/bin/javac"
     JAVA="${TESTJAVA}/bin/java"
+    # needed to get full headless behavior on Mac
+    if [ "$OS" = "Darwin" ]; then
+        export AWT_TOOLKIT=XToolkit
+    fi
 }
diff --git a/jdk/test/sun/tools/jrunscript/jrunscript-argsTest.sh b/jdk/test/sun/tools/jrunscript/jrunscript-argsTest.sh
index 96274e7..68928de 100644
--- a/jdk/test/sun/tools/jrunscript/jrunscript-argsTest.sh
+++ b/jdk/test/sun/tools/jrunscript/jrunscript-argsTest.sh
@@ -41,7 +41,7 @@
 
 # we check whether "excess" args are passed as script arguments
 
-${JRUNSCRIPT} -f - hello world <<EOF
+${JRUNSCRIPT} -J-Djava.awt.headless=true -f - hello world <<EOF
 
 if (typeof(arguments) == 'undefined') { println("arguments expected"); exit(1); }
 
diff --git a/jdk/test/sun/tools/jrunscript/jrunscript-eTest.sh b/jdk/test/sun/tools/jrunscript/jrunscript-eTest.sh
index 7291c87..625c6d4 100644
--- a/jdk/test/sun/tools/jrunscript/jrunscript-eTest.sh
+++ b/jdk/test/sun/tools/jrunscript/jrunscript-eTest.sh
@@ -40,7 +40,7 @@
 fi
 
 rm -f jrunscript-eTest.out 2>/dev/null
-${JRUNSCRIPT} -e "println('hello')" > jrunscript-eTest.out 2>&1
+${JRUNSCRIPT} -J-Djava.awt.headless=true -e "println('hello')" > jrunscript-eTest.out 2>&1
 
 $golden_diff jrunscript-eTest.out ${TESTSRC}/dash-e.out
 if [ $? != 0 ]
@@ -53,7 +53,7 @@
 # -e option with JavaScript explicitly choosen as language
 
 rm -f jrunscript-eTest.out 2>/dev/null
-${JRUNSCRIPT} -l js -e "println('hello')" > jrunscript-eTest.out 2>&1
+${JRUNSCRIPT} -J-Djava.awt.headless=true -l js -e "println('hello')" > jrunscript-eTest.out 2>&1
 
 $golden_diff jrunscript-eTest.out ${TESTSRC}/dash-e.out
 if [ $? != 0 ]
diff --git a/jdk/test/sun/tools/jrunscript/jrunscript-fTest.sh b/jdk/test/sun/tools/jrunscript/jrunscript-fTest.sh
index fd2feec..a50d983 100644
--- a/jdk/test/sun/tools/jrunscript/jrunscript-fTest.sh
+++ b/jdk/test/sun/tools/jrunscript/jrunscript-fTest.sh
@@ -40,7 +40,7 @@
 fi
 
 rm -f jrunscript-fTest.out 2>/dev/null
-${JRUNSCRIPT} -f ${TESTSRC}/hello.js > jrunscript-fTest.out 2>&1
+${JRUNSCRIPT} -J-Djava.awt.headless=true -f ${TESTSRC}/hello.js > jrunscript-fTest.out 2>&1
 
 $golden_diff jrunscript-fTest.out ${TESTSRC}/dash-f.out
 if [ $? != 0 ]
@@ -54,7 +54,7 @@
 # with -l option
 
 rm -f jrunscript-fTest.out 2>/dev/null
-${JRUNSCRIPT} -l js -f ${TESTSRC}/hello.js > jrunscript-fTest.out 2>&1
+${JRUNSCRIPT} -J-Djava.awt.headless=true -l js -f ${TESTSRC}/hello.js > jrunscript-fTest.out 2>&1
 
 $golden_diff jrunscript-fTest.out ${TESTSRC}/dash-f.out
 if [ $? != 0 ]
diff --git a/jdk/test/sun/tools/jrunscript/jrunscriptTest.sh b/jdk/test/sun/tools/jrunscript/jrunscriptTest.sh
index a07415b..2d1916a 100644
--- a/jdk/test/sun/tools/jrunscript/jrunscriptTest.sh
+++ b/jdk/test/sun/tools/jrunscript/jrunscriptTest.sh
@@ -40,7 +40,7 @@
 fi
 
 rm -f jrunscriptTest.out 2>/dev/null
-${JRUNSCRIPT} > jrunscriptTest.out 2>&1 <<EOF
+${JRUNSCRIPT} -J-Djava.awt.headless=true > jrunscriptTest.out 2>&1 <<EOF
 v = 2 + 5;
 v *= 5;
 v = v + " is the value";
@@ -58,7 +58,7 @@
 fi
 
 rm -f jrunscriptTest.out 2>/dev/null
-${JRUNSCRIPT} -l js > jrunscriptTest.out 2>&1 <<EOF
+${JRUNSCRIPT} -J-Djava.awt.headless=true -l js > jrunscriptTest.out 2>&1 <<EOF
 v = 2 + 5;
 v *= 5;
 v = v + " is the value";
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/jdk/test/tools/launcher/ExecutionEnvironment.java b/jdk/test/tools/launcher/ExecutionEnvironment.java
index 427c3fd..3b8b7eb 100644
--- a/jdk/test/tools/launcher/ExecutionEnvironment.java
+++ b/jdk/test/tools/launcher/ExecutionEnvironment.java
@@ -61,7 +61,9 @@
 
 
 public class ExecutionEnvironment extends TestHelper {
-    static final String LD_LIBRARY_PATH    = "LD_LIBRARY_PATH";
+    static final String LD_LIBRARY_PATH    = TestHelper.isMacOSX
+            ? "DYLD_LIBRARY_PATH"
+            : "LD_LIBRARY_PATH";
     static final String LD_LIBRARY_PATH_32 = LD_LIBRARY_PATH + "_32";
     static final String LD_LIBRARY_PATH_64 = LD_LIBRARY_PATH + "_64";
 
@@ -81,7 +83,9 @@
     static int errors = 0;
     static int passes = 0;
 
-    static final String LIBJVM = isWindows ? "jvm.dll" : "libjvm.so";
+    static final String LIBJVM = TestHelper.isWindows
+            ? "jvm.dll"
+            : "libjvm" + (TestHelper.isMacOSX ? ".dylib" : ".so");
 
     static void createTestJar() {
         try {
@@ -175,7 +179,7 @@
 
         Map<String, String> env = new HashMap<>();
 
-        if (isLinux) {
+        if (TestHelper.isLinux || TestHelper.isMacOSX) {
             for (String x : LD_PATH_STRINGS) {
                 String pairs[] = x.split("=");
                 env.put(pairs[0], pairs[1]);
diff --git a/jdk/test/tools/launcher/Test7029048.java b/jdk/test/tools/launcher/Test7029048.java
index 2f00b3a..aafee36 100644
--- a/jdk/test/tools/launcher/Test7029048.java
+++ b/jdk/test/tools/launcher/Test7029048.java
@@ -285,8 +285,8 @@
     }
 
     public static void main(String... args) throws Exception {
-        if (isWindows) {
-            System.out.println("Warning: noop on windows");
+        if (TestHelper.isWindows || TestHelper.isMacOSX) {
+            System.out.println("Note: applicable on neither Windows nor MacOSX");
             return;
         }
         // create our test jar first
diff --git a/jdk/test/tools/launcher/TestHelper.java b/jdk/test/tools/launcher/TestHelper.java
index a64d97d..2c4dedd 100644
--- a/jdk/test/tools/launcher/TestHelper.java
+++ b/jdk/test/tools/launcher/TestHelper.java
@@ -64,6 +64,8 @@
     static final boolean debug = Boolean.getBoolean("TestHelper.Debug");
     static final boolean isWindows =
             System.getProperty("os.name", "unknown").startsWith("Windows");
+    static final boolean isMacOSX =
+            System.getProperty("os.name", "unknown").startsWith("Mac");
     static final boolean is64Bit =
             System.getProperty("sun.arch.data.model").equals("64");
     static final boolean is32Bit =
diff --git a/jdk/test/tools/pack200/Pack200Test.java b/jdk/test/tools/pack200/Pack200Test.java
index 888beb8..476ece1 100644
--- a/jdk/test/tools/pack200/Pack200Test.java
+++ b/jdk/test/tools/pack200/Pack200Test.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -46,7 +46,7 @@
     private static ArrayList <File> jarList = new ArrayList<File>();
     static final MemoryMXBean mmxbean = ManagementFactory.getMemoryMXBean();
     static final long m0 = getUsedMemory();
-    static final int LEAK_TOLERANCE = 20000; // OS and GC related variations.
+    static final int LEAK_TOLERANCE = 21000; // OS and GC related variations.
 
     /** Creates a new instance of Pack200Test */
     private Pack200Test() {}
diff --git a/langtools/.hgignore b/langtools/.hgignore
index 83cef21..e05f093 100644
--- a/langtools/.hgignore
+++ b/langtools/.hgignore
@@ -2,3 +2,4 @@
 ^dist/
 /nbproject/private/
 ^.hgtip
+.DS_Store
diff --git a/langtools/.hgtags b/langtools/.hgtags
index 02391cf..d36d1d6 100644
--- a/langtools/.hgtags
+++ b/langtools/.hgtags
@@ -150,3 +150,4 @@
 b556aa8a99c358469861770aebdce884e06fa178 jdk8-b26
 be456f9c64e818161c789252145d4ddc292ae863 jdk8-b27
 5bed623b0c773aa8a8d5f8d4004ce9d3974143cc jdk8-b28
+e974e82abe51ef66dc32bb6ab5d0733753d3c7d7 jdk8-b29
diff --git a/langtools/make/build.xml b/langtools/make/build.xml
index 152be98..52b13b7 100644
--- a/langtools/make/build.xml
+++ b/langtools/make/build.xml
@@ -862,7 +862,8 @@
                source="${boot.javac.source}"
                target="${boot.javac.target}"
                executable="${boot.java.home}/bin/javac"
-               srcdir="${make.tools.dir}/CompileProperties"
+               srcdir="${make.tools.dir}"
+               includes="compileproperties/* anttasks/CompileProperties*"
                destdir="${build.toolclasses.dir}/"
                classpath="${ant.core.lib}"
                bootclasspath="${boot.java.home}/jre/lib/rt.jar"
@@ -870,7 +871,7 @@
             <compilerarg line="${javac.lint.opts}"/>
         </javac>
         <taskdef name="pcompile"
-                 classname="CompilePropertiesTask"
+                 classname="anttasks.CompilePropertiesTask"
                  classpath="${build.toolclasses.dir}/"/>
     </target>
 
@@ -880,7 +881,8 @@
                source="${boot.javac.source}"
                target="${boot.javac.target}"
                executable="${boot.java.home}/bin/javac"
-               srcdir="${make.tools.dir}/GenStubs"
+               srcdir="${make.tools.dir}"
+               includes="genstubs/* anttasks/GenStubs*"
                destdir="${build.toolclasses.dir}/"
                classpath="${ant.core.lib}"
                includeantruntime="false">
@@ -888,7 +890,7 @@
             <compilerarg line="${javac.lint.opts}"/>
         </javac>
         <taskdef name="genstubs"
-                 classname="GenStubs$$Ant"
+                 classname="anttasks.GenStubsTask"
                  classpath="${build.toolclasses.dir}/"/>
     </target>
 
diff --git a/langtools/make/jprt.properties b/langtools/make/jprt.properties
index a4ef7fd..a459321 100644
--- a/langtools/make/jprt.properties
+++ b/langtools/make/jprt.properties
@@ -39,6 +39,7 @@
     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}
 
@@ -50,6 +51,7 @@
     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
 
@@ -60,3 +62,18 @@
 # Directories to be excluded from the source bundles
 jprt.bundle.exclude.src.dirs=build dist webrev
 
+# 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 test targets
+jprt.make.rule.test.targets=					\
+    ${jprt.my.test.target.set:TESTNAME=jtreg}
diff --git a/langtools/make/netbeans/langtools/build.xml b/langtools/make/netbeans/langtools/build.xml
index d7e8f37..dd2caf9 100644
--- a/langtools/make/netbeans/langtools/build.xml
+++ b/langtools/make/netbeans/langtools/build.xml
@@ -261,7 +261,8 @@
 
     <target name="-def-select-tool">
         <mkdir dir="${build.toolclasses.dir}"/>
-        <javac srcdir="${make.tools.dir}/SelectTool"
+        <javac srcdir="${make.tools.dir}"
+               includes="anttasks/SelectTool*"
                destdir="${build.toolclasses.dir}/"
                classpath="${ant.core.lib}"
                includeantruntime="false"
@@ -270,7 +271,7 @@
                    <compilerarg line="-Xlint"/>
         </javac>
         <taskdef name="select-tool"
-                 classname="SelectToolTask"
+                 classname="anttasks.SelectToolTask"
                  classpath="${build.toolclasses.dir}/"/>
     </target>
 
diff --git a/langtools/make/tools/CompileProperties/CompileProperties.java b/langtools/make/tools/CompileProperties/CompileProperties.java
deleted file mode 100644
index c4654bf..0000000
--- a/langtools/make/tools/CompileProperties/CompileProperties.java
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- * 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.
- */
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
-/** Translates a .properties file into a .java file containing the
- *  definition of a java.util.Properties subclass which can then be
- *  compiled with javac. <P>
- *
- *  Usage: java CompileProperties [path to .properties file] [path to .java file to be output] [super class]
- *
- *  Infers the package by looking at the common suffix of the two
- *  inputs, eliminating "classes" from it.
- *
- * @author Scott Violet
- * @author Kenneth Russell
- */
-
-public class CompileProperties {
-
-    public static void main(String[] args) {
-        CompileProperties cp = new CompileProperties();
-        boolean ok = cp.run(args);
-        if ( !ok ) {
-            System.exit(1);
-        }
-    }
-
-    static interface Log {
-        void info(String msg);
-        void verbose(String msg);
-        void error(String msg, Exception e);
-    }
-
-    private String propfiles[];
-    private String outfiles[] ;
-    private String supers[]   ;
-    private int compileCount = 0;
-    private boolean quiet = false;
-    private Log log;
-
-    public void setLog(Log log) {
-        this.log = log;
-    }
-
-    public boolean run(String[] args) {
-        if (log == null) {
-            log = new Log() {
-                public void error(String msg, Exception e) {
-                    System.err.println("ERROR: CompileProperties: " + msg);
-                    if ( e != null ) {
-                        System.err.println("EXCEPTION: " + e.toString());
-                        e.printStackTrace();
-                    }
-                }
-                public void info(String msg) {
-                    System.out.println(msg);
-                }
-                public void verbose(String msg) {
-                    if (!quiet)
-                        System.out.println(msg);
-                }
-            };
-        }
-
-        boolean ok = true;
-        /* Original usage */
-        if (args.length == 2 && args[0].charAt(0) != '-' ) {
-            ok = createFile(args[0], args[1], "java.util.ListResourceBundle");
-        } else if (args.length == 3) {
-            ok = createFile(args[0], args[1], args[2]);
-        } else if (args.length == 0) {
-            usage(log);
-            ok = false;
-        } else {
-            /* New batch usage */
-            ok = parseOptions(args);
-            if ( ok && compileCount == 0 ) {
-                log.error("options parsed but no files to compile", null);
-                ok = false;
-            }
-            /* Need at least one file. */
-            if ( !ok ) {
-                usage(log);
-            } else {
-                /* Process files */
-                for ( int i = 0; i < compileCount && ok ; i++ ) {
-                    ok = createFile(propfiles[i], outfiles[i], supers[i]);
-                }
-            }
-        }
-        return ok;
-    }
-
-    private boolean parseOptions(String args[]) {
-        boolean ok = true;
-        if ( compileCount > 0 ) {
-            String new_propfiles[] = new String[compileCount + args.length];
-            String new_outfiles[]  = new String[compileCount + args.length];
-            String new_supers[]    = new String[compileCount + args.length];
-            System.arraycopy(propfiles, 0, new_propfiles, 0, compileCount);
-            System.arraycopy(outfiles, 0, new_outfiles, 0, compileCount);
-            System.arraycopy(supers, 0, new_supers, 0, compileCount);
-            propfiles = new_propfiles;
-            outfiles  = new_outfiles;
-            supers    = new_supers;
-        } else {
-            propfiles = new String[args.length];
-            outfiles  = new String[args.length];
-            supers    = new String[args.length];
-        }
-
-        for ( int i = 0; i < args.length ; i++ ) {
-            if ( "-compile".equals(args[i]) && i+3 < args.length ) {
-                propfiles[compileCount] = args[++i];
-                outfiles[compileCount]  = args[++i];
-                supers[compileCount]    = args[++i];
-                compileCount++;
-            } else if ( "-optionsfile".equals(args[i]) && i+1 < args.length ) {
-                String filename = args[++i];
-                FileInputStream finput = null;
-                byte contents[] = null;
-                try {
-                    finput = new FileInputStream(filename);
-                    int byteCount = finput.available();
-                    if ( byteCount <= 0 ) {
-                        log.error("The -optionsfile file is empty", null);
-                        ok = false;
-                    } else {
-                        contents = new byte[byteCount];
-                        int bytesRead = finput.read(contents);
-                        if ( byteCount != bytesRead ) {
-                            log.error("Cannot read all of -optionsfile file", null);
-                            ok = false;
-                        }
-                    }
-                } catch ( IOException e ) {
-                    log.error("cannot open " + filename, e);
-                    ok = false;
-                }
-                if ( finput != null ) {
-                    try {
-                        finput.close();
-                    } catch ( IOException e ) {
-                        ok = false;
-                        log.error("cannot close " + filename, e);
-                    }
-                }
-                if ( ok = true && contents != null ) {
-                    String tokens[] = (new String(contents)).split("\\s+");
-                    if ( tokens.length > 0 ) {
-                        ok = parseOptions(tokens);
-                    }
-                }
-                if ( !ok ) {
-                    break;
-                }
-            } else if ( "-quiet".equals(args[i]) ) {
-                quiet = true;
-            } else {
-                log.error("argument error", null);
-                ok = false;
-            }
-        }
-        return ok;
-    }
-
-    private boolean createFile(String propertiesPath, String outputPath,
-            String superClass) {
-        boolean ok = true;
-        log.verbose("parsing: " + propertiesPath);
-        Properties p = new Properties();
-        try {
-            p.load(new FileInputStream(propertiesPath));
-        } catch ( FileNotFoundException e ) {
-            ok = false;
-            log.error("Cannot find file " + propertiesPath, e);
-        } catch ( IOException e ) {
-            ok = false;
-            log.error("IO error on file " + propertiesPath, e);
-        }
-        if ( ok ) {
-            String packageName = inferPackageName(propertiesPath, outputPath);
-            log.verbose("inferred package name: " + packageName);
-            List<String> sortedKeys = new ArrayList<String>();
-            for ( Object key : p.keySet() ) {
-                sortedKeys.add((String)key);
-            }
-            Collections.sort(sortedKeys);
-            Iterator<String> keys = sortedKeys.iterator();
-
-            StringBuffer data = new StringBuffer();
-
-            while (keys.hasNext()) {
-                String key = keys.next();
-                data.append("            { \"" + escape(key) + "\", \"" +
-                        escape((String)p.get(key)) + "\" },\n");
-            }
-
-            // Get class name from java filename, not the properties filename.
-            //   (zh_TW properties might be used to create zh_HK files)
-            File file = new File(outputPath);
-            String name = file.getName();
-            int dotIndex = name.lastIndexOf('.');
-            String className;
-            if (dotIndex == -1) {
-                className = name;
-            } else {
-                className = name.substring(0, dotIndex);
-            }
-
-            String packageString = "";
-            if (packageName != null && !packageName.equals("")) {
-                packageString = "package " + packageName + ";\n\n";
-            }
-
-            Writer writer = null;
-            try {
-                writer = new BufferedWriter(
-                        new OutputStreamWriter(new FileOutputStream(outputPath), "8859_1"));
-                MessageFormat format = new MessageFormat(FORMAT);
-                writer.write(format.format(new Object[] { packageString, className, superClass, data }));
-            } catch ( IOException e ) {
-                ok = false;
-                log.error("IO error writing to file " + outputPath, e);
-            }
-            if ( writer != null ) {
-                try {
-                    writer.flush();
-                } catch ( IOException e ) {
-                    ok = false;
-                    log.error("IO error flush " + outputPath, e);
-                }
-                try {
-                    writer.close();
-                } catch ( IOException e ) {
-                    ok = false;
-                    log.error("IO error close " + outputPath, e);
-                }
-            }
-            log.verbose("wrote: " + outputPath);
-        }
-        return ok;
-    }
-
-    private static void usage(Log log) {
-        log.info("usage:");
-        log.info("    java CompileProperties path_to_properties_file path_to_java_output_file [super_class]");
-        log.info("      -OR-");
-        log.info("    java CompileProperties {-compile path_to_properties_file path_to_java_output_file super_class} -or- -optionsfile filename");
-        log.info("");
-        log.info("Example:");
-        log.info("    java CompileProperties -compile test.properties test.java java.util.ListResourceBundle");
-        log.info("    java CompileProperties -optionsfile option_file");
-        log.info("option_file contains: -compile test.properties test.java java.util.ListResourceBundle");
-    }
-
-    private static String escape(String theString) {
-        // This is taken from Properties.saveConvert with changes for Java strings
-        int len = theString.length();
-        StringBuffer outBuffer = new StringBuffer(len*2);
-
-        for(int x=0; x<len; x++) {
-            char aChar = theString.charAt(x);
-            switch(aChar) {
-                case '\\':outBuffer.append('\\'); outBuffer.append('\\');
-                break;
-                case '\t':outBuffer.append('\\'); outBuffer.append('t');
-                break;
-                case '\n':outBuffer.append('\\'); outBuffer.append('n');
-                break;
-                case '\r':outBuffer.append('\\'); outBuffer.append('r');
-                break;
-                case '\f':outBuffer.append('\\'); outBuffer.append('f');
-                break;
-                default:
-                    if ((aChar < 0x0020) || (aChar > 0x007e)) {
-                        outBuffer.append('\\');
-                        outBuffer.append('u');
-                        outBuffer.append(toHex((aChar >> 12) & 0xF));
-                        outBuffer.append(toHex((aChar >>  8) & 0xF));
-                        outBuffer.append(toHex((aChar >>  4) & 0xF));
-                        outBuffer.append(toHex( aChar        & 0xF));
-                    } else {
-                        if (specialSaveChars.indexOf(aChar) != -1) {
-                            outBuffer.append('\\');
-                        }
-                        outBuffer.append(aChar);
-                    }
-            }
-        }
-        return outBuffer.toString();
-    }
-
-    private static String inferPackageName(String inputPath, String outputPath) {
-        // Normalize file names
-        inputPath  = new File(inputPath).getPath();
-        outputPath = new File(outputPath).getPath();
-        // Split into components
-        String sep;
-        if (File.separatorChar == '\\') {
-            sep = "\\\\";
-        } else {
-            sep = File.separator;
-        }
-        String[] inputs  = inputPath.split(sep);
-        String[] outputs = outputPath.split(sep);
-        // Match common names, eliminating first "classes" entry from
-        // each if present
-        int inStart  = 0;
-        int inEnd    = inputs.length - 2;
-        int outEnd   = outputs.length - 2;
-        int i = inEnd;
-        int j = outEnd;
-        while (i >= 0 && j >= 0) {
-            if (!inputs[i].equals(outputs[j]) ||
-                    (inputs[i].equals("gensrc") && inputs[j].equals("gensrc"))) {
-                ++i;
-                ++j;
-                break;
-            }
-            --i;
-            --j;
-        }
-        String result;
-        if (i < 0 || j < 0 || i >= inEnd || j >= outEnd) {
-            result = "";
-        } else {
-            if (inputs[i].equals("classes") && outputs[j].equals("classes")) {
-                ++i;
-            }
-            inStart = i;
-            StringBuffer buf = new StringBuffer();
-            for (i = inStart; i <= inEnd; i++) {
-                buf.append(inputs[i]);
-                if (i < inEnd) {
-                    buf.append('.');
-                }
-            }
-            result = buf.toString();
-        }
-        return result;
-    }
-
-    private static final String FORMAT =
-            "{0}" +
-            "public final class {1} extends {2} '{'\n" +
-            "    protected final Object[][] getContents() '{'\n" +
-            "        return new Object[][] '{'\n" +
-            "{3}" +
-            "        };\n" +
-            "    }\n" +
-            "}\n";
-
-    // This comes from Properties
-    private static char toHex(int nibble) {
-        return hexDigit[(nibble & 0xF)];
-    }
-
-    // This comes from Properties
-    private static final char[] hexDigit = {
-        '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
-    };
-
-    // Note: different from that in Properties
-    private static final String specialSaveChars = "\"";
-}
diff --git a/langtools/make/tools/CompileProperties/CompilePropertiesTask.java b/langtools/make/tools/CompileProperties/CompilePropertiesTask.java
deleted file mode 100644
index 8bf3303..0000000
--- a/langtools/make/tools/CompileProperties/CompilePropertiesTask.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please 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.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.MatchingTask;
-
-public class CompilePropertiesTask extends MatchingTask {
-    public void setSrcDir(File srcDir) {
-        this.srcDir = srcDir;
-    }
-
-    public void setDestDir(File destDir) {
-        this.destDir = destDir;
-    }
-
-    public void setSuperclass(String superclass) {
-        this.superclass = superclass;
-    }
-
-    @Override
-    public void execute() {
-        CompileProperties.Log log = new CompileProperties.Log() {
-            public void error(String msg, Exception e) {
-                log(msg, Project.MSG_ERR);
-            }
-            public void info(String msg) {
-                log(msg, Project.MSG_INFO);
-            }
-            public void verbose(String msg) {
-                log(msg, Project.MSG_VERBOSE);
-            }
-        };
-        List<String> mainOpts = new ArrayList<String>();
-        int count = 0;
-        DirectoryScanner s = getDirectoryScanner(srcDir);
-        for (String path: s.getIncludedFiles()) {
-            if (path.endsWith(".properties")) {
-                String destPath =
-                        path.substring(0, path.length() - ".properties".length()) +
-                        ".java";
-                File srcFile = new File(srcDir, path);
-                File destFile = new File(destDir, destPath);
-                // Arguably, the comparison in the next line should be ">", not ">="
-                // but that assumes the resolution of the last modified time is fine
-                // grained enough; in practice, it is better to use ">=".
-                if (destFile.exists() && destFile.lastModified() >= srcFile.lastModified())
-                    continue;
-                destFile.getParentFile().mkdirs();
-                mainOpts.add("-compile");
-                mainOpts.add(srcFile.getPath());
-                mainOpts.add(destFile.getPath());
-                mainOpts.add(superclass);
-                count++;
-            }
-        }
-        if (mainOpts.size() > 0) {
-            log("Generating " + count + " resource files to " + destDir, Project.MSG_INFO);
-            CompileProperties cp = new CompileProperties();
-            cp.setLog(log);
-            boolean ok = cp.run(mainOpts.toArray(new String[mainOpts.size()]));
-            if (!ok)
-                throw new BuildException("CompileProperties failed.");
-        }
-    }
-
-    private File srcDir;
-    private File destDir;
-    private String superclass = "java.util.ListResourceBundle";
-}
diff --git a/langtools/make/tools/GenStubs/GenStubs.java b/langtools/make/tools/GenStubs/GenStubs.java
deleted file mode 100644
index b7caee2..0000000
--- a/langtools/make/tools/GenStubs/GenStubs.java
+++ /dev/null
@@ -1,448 +0,0 @@
-/*
- * Copyright (c) 2009, 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.
- */
-
-import java.io.*;
-import java.util.*;
-import javax.tools.JavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.StandardLocation;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.taskdefs.MatchingTask;
-import org.apache.tools.ant.types.Path;
-import org.apache.tools.ant.types.Reference;
-
-
-import com.sun.source.tree.CompilationUnitTree;
-import com.sun.source.util.JavacTask;
-import com.sun.tools.javac.api.JavacTool;
-import com.sun.tools.javac.code.Flags;
-import com.sun.tools.javac.code.TypeTags;
-import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
-import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
-import com.sun.tools.javac.tree.JCTree.JCIdent;
-import com.sun.tools.javac.tree.JCTree.JCImport;
-import com.sun.tools.javac.tree.JCTree.JCLiteral;
-import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
-import com.sun.tools.javac.tree.JCTree.JCModifiers;
-import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
-import com.sun.tools.javac.tree.Pretty;
-import com.sun.tools.javac.tree.TreeMaker;
-import com.sun.tools.javac.tree.TreeScanner;
-import com.sun.tools.javac.tree.TreeTranslator;
-import com.sun.tools.javac.util.Context;
-import com.sun.tools.javac.util.ListBuffer;
-import com.sun.tools.javac.util.Name;
-import javax.tools.JavaFileManager;
-
-/**
- * Generate stub source files by removing implementation details from input files.
- *
- * This is a special purpose stub generator, specific to the needs of generating
- * stub files for JDK 7 API that are needed to compile langtools files that depend
- * on that API. The stub generator works by removing as much of the API source code
- * as possible without affecting the public signature, in order to reduce the
- * transitive closure of the API being referenced. The resulting stubs can be
- * put on the langtools sourcepath with -implicit:none to compile the langtools
- * files that depend on the JDK 7 API.
- *
- * Usage:
- *  genstubs -s <outdir> -sourcepath <path> <classnames>
- *
- * The specified class names are looked up on the sourcepath, and corresponding
- * stubs are written to the source output directory.
- *
- * Classes are parsed into javac ASTs, then processed with a javac TreeTranslator
- * to remove implementation details, and written out in the source output directory.
- * Documentation comments and annotations are removed. Method bodies are removed
- * and methods are marked native. Private and package-private field definitions
- * have their initializers replace with 0, 0.0, false, null as appropriate.
- *
- * An Ant task, Main$Ant is also provided. Files are specified with an implicit
- * fileset, using srcdir as a base directory. The set of files to be included
- * is specified with an includes attribute or nested <includes> set. However,
- * unlike a normal fileset, an empty includes attribute means "no files" instead
- * of "all files".  The Ant task also accepts "fork=true" and classpath attribute
- * or nested <classpath> element to run GenStubs in a separate VM with the specified
- * path. This is likely necessary if a JDK 7 parser is required to read the
- * JDK 7 input files.
- */
-
-public class GenStubs {
-    static class Fault extends Exception {
-        private static final long serialVersionUID = 0;
-        Fault(String message) {
-            super(message);
-        }
-        Fault(String message, Throwable cause) {
-            super(message);
-            initCause(cause);
-        }
-    }
-
-    public static void main(String[] args) {
-        boolean ok = new GenStubs().run(args);
-        if (!ok)
-            System.exit(1);
-    }
-
-    boolean run(String... args) {
-        File outdir = null;
-        String sourcepath = null;
-        List<String> classes = new ArrayList<String>();
-        for (ListIterator<String> iter = Arrays.asList(args).listIterator(); iter.hasNext(); ) {
-            String arg = iter.next();
-            if (arg.equals("-s") && iter.hasNext())
-                outdir = new File(iter.next());
-            else if (arg.equals("-sourcepath") && iter.hasNext())
-                sourcepath = iter.next();
-            else if (arg.startsWith("-"))
-                throw new IllegalArgumentException(arg);
-            else {
-                classes.add(arg);
-                while (iter.hasNext())
-                    classes.add(iter.next());
-            }
-        }
-
-        return run(sourcepath, outdir, classes);
-    }
-
-    boolean run(String sourcepath, File outdir, List<String> classes) {
-        //System.err.println("run: sourcepath:" + sourcepath + " outdir:" + outdir + " classes:" + classes);
-        if (sourcepath == null)
-            throw new IllegalArgumentException("sourcepath not set");
-        if (outdir == null)
-            throw new IllegalArgumentException("source output dir not set");
-
-        JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-
-        try {
-            fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir));
-            fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath));
-            List<JavaFileObject> files = new ArrayList<JavaFileObject>();
-            for (String c: classes) {
-                JavaFileObject fo = fm.getJavaFileForInput(
-                        StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE);
-                if (fo == null)
-                    error("class not found: " + c);
-                else
-                    files.add(fo);
-            }
-
-            JavacTask t = tool.getTask(null, fm, null, null, null, files);
-            Iterable<? extends CompilationUnitTree> trees = t.parse();
-            for (CompilationUnitTree tree: trees) {
-                makeStub(fm, tree);
-            }
-        } catch (IOException e) {
-            error("IO error " + e, e);
-        }
-
-        return (errors == 0);
-    }
-
-    void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException {
-        CompilationUnitTree tree2 = new StubMaker().translate(tree);
-        CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2);
-
-        String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile());
-        JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT,
-                className, JavaFileObject.Kind.SOURCE, null);
-        // System.err.println("Writing " + className + " to " + fo.getName());
-        Writer out = fo.openWriter();
-        try {
-            new Pretty(out, true).printExpr((JCTree) tree3);
-        } finally {
-            out.close();
-        }
-    }
-
-    List<File> splitPath(String path) {
-        List<File> list = new ArrayList<File>();
-        for (String p: path.split(File.pathSeparator)) {
-            if (p.length() > 0)
-                list.add(new File(p));
-        }
-        return list;
-    }
-
-    void error(String message) {
-        System.err.println(message);
-        errors++;
-    }
-
-    void error(String message, Throwable cause) {
-        error(message);
-    }
-
-    int errors;
-
-    class StubMaker extends TreeTranslator {
-        CompilationUnitTree translate(CompilationUnitTree tree) {
-            return super.translate((JCCompilationUnit) tree);
-        }
-
-        /**
-         * compilation units: remove javadoc comments
-         * -- required, in order to remove @deprecated tags, since we
-         * (separately) remove all annotations, including @Deprecated
-         */
-        public void visitTopLevel(JCCompilationUnit tree) {
-            super.visitTopLevel(tree);
-            tree.docComments = Collections.emptyMap();
-        }
-
-        /**
-         * methods: remove method bodies, make methods native
-         */
-        @Override
-        public void visitMethodDef(JCMethodDecl tree) {
-            tree.mods = translate(tree.mods);
-            tree.restype = translate(tree.restype);
-            tree.typarams = translateTypeParams(tree.typarams);
-            tree.params = translateVarDefs(tree.params);
-            tree.thrown = translate(tree.thrown);
-            if (tree.restype != null && tree.body != null) {
-                tree.mods.flags |= Flags.NATIVE;
-                tree.body = null;
-            }
-            result = tree;
-        }
-
-        /**
-         * modifiers: remove annotations
-         */
-        @Override
-        public void visitModifiers(JCModifiers tree) {
-            tree.annotations = com.sun.tools.javac.util.List.nil();
-            result = tree;
-        }
-
-        /**
-         * field definitions: replace initializers with 0, 0.0, false etc
-         * when possible -- i.e. leave public, protected initializers alone
-         */
-        @Override
-        public void visitVarDef(JCVariableDecl tree) {
-            tree.mods = translate(tree.mods);
-            tree.vartype = translate(tree.vartype);
-            if (tree.init != null) {
-                if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
-                    tree.init = translate(tree.init);
-                else {
-                    String t = tree.vartype.toString();
-                    if (t.equals("boolean"))
-                        tree.init = new JCLiteral(TypeTags.BOOLEAN, 0) { };
-                    else if (t.equals("byte"))
-                        tree.init = new JCLiteral(TypeTags.BYTE, 0) { };
-                    else if (t.equals("char"))
-                        tree.init = new JCLiteral(TypeTags.CHAR, 0) { };
-                    else if (t.equals("double"))
-                        tree.init = new JCLiteral(TypeTags.DOUBLE, 0.d) { };
-                    else if (t.equals("float"))
-                        tree.init = new JCLiteral(TypeTags.FLOAT, 0.f) { };
-                    else if (t.equals("int"))
-                        tree.init = new JCLiteral(TypeTags.INT, 0) { };
-                    else if (t.equals("long"))
-                        tree.init = new JCLiteral(TypeTags.LONG, 0) { };
-                    else if (t.equals("short"))
-                        tree.init = new JCLiteral(TypeTags.SHORT, 0) { };
-                    else
-                        tree.init = new JCLiteral(TypeTags.BOT, null) { };
-                }
-            }
-            result = tree;
-        }
-    }
-
-    class ImportCleaner extends TreeScanner {
-        private Set<Name> names = new HashSet<Name>();
-        private TreeMaker m;
-
-        ImportCleaner(JavaFileManager fm) {
-            // ImportCleaner itself doesn't require a filemanager, but instantiating
-            // a TreeMaker does, indirectly (via ClassReader, sigh)
-            Context c = new Context();
-            c.put(JavaFileManager.class, fm);
-            m = TreeMaker.instance(c);
-        }
-
-        CompilationUnitTree removeRedundantImports(CompilationUnitTree t) {
-            JCCompilationUnit tree = (JCCompilationUnit) t;
-            tree.accept(this);
-            ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
-            for (JCTree def: tree.defs) {
-                if (def.getTag() == JCTree.IMPORT) {
-                    JCImport imp = (JCImport) def;
-                    if (imp.qualid.getTag() == JCTree.SELECT) {
-                        JCFieldAccess qualid = (JCFieldAccess) imp.qualid;
-                        if (!qualid.name.toString().equals("*")
-                                && !names.contains(qualid.name)) {
-                            continue;
-                        }
-                    }
-                }
-                defs.add(def);
-            }
-            return m.TopLevel(tree.packageAnnotations, tree.pid, defs.toList());
-        }
-
-        @Override
-        public void visitImport(JCImport tree) { } // ignore names found in imports
-
-        @Override
-        public void visitIdent(JCIdent tree) {
-            names.add(tree.name);
-        }
-
-        @Override
-        public void visitSelect(JCFieldAccess tree) {
-            super.visitSelect(tree);
-            names.add(tree.name);
-        }
-    }
-
-    //---------- Ant Invocation ------------------------------------------------
-
-    public static class Ant extends MatchingTask {
-        private File srcDir;
-        private File destDir;
-        private boolean fork;
-        private Path classpath;
-        private String includes;
-
-        public void setSrcDir(File dir) {
-            this.srcDir = dir;
-        }
-
-        public void setDestDir(File dir) {
-            this.destDir = dir;
-        }
-
-        public void setFork(boolean v) {
-            this.fork = v;
-        }
-
-        public void setClasspath(Path cp) {
-            if (classpath == null)
-                classpath = cp;
-            else
-                classpath.append(cp);
-        }
-
-        public Path createClasspath() {
-            if (classpath == null) {
-                classpath = new Path(getProject());
-            }
-            return classpath.createPath();
-        }
-
-        public void setClasspathRef(Reference r) {
-            createClasspath().setRefid(r);
-        }
-
-        public void setIncludes(String includes) {
-            super.setIncludes(includes);
-            this.includes = includes;
-        }
-
-        @Override
-        public void execute() {
-            if (includes != null && includes.trim().isEmpty())
-                return;
-
-            DirectoryScanner s = getDirectoryScanner(srcDir);
-            String[] files = s.getIncludedFiles();
-//            System.err.println("Ant.execute: srcDir " + srcDir);
-//            System.err.println("Ant.execute: destDir " + destDir);
-//            System.err.println("Ant.execute: files " + Arrays.asList(files));
-
-            files = filter(srcDir, destDir, files);
-            if (files.length == 0)
-                return;
-            System.out.println("Generating " + files.length + " stub files to " + destDir);
-
-            List<String> classNames = new ArrayList<String>();
-            for (String file: files) {
-                classNames.add(file.replaceAll(".java$", "").replace('/', '.'));
-            }
-
-            if (!fork) {
-                GenStubs m = new GenStubs();
-                boolean ok = m.run(srcDir.getPath(), destDir, classNames);
-                if (!ok)
-                    throw new BuildException("genstubs failed");
-            } else {
-                List<String> cmd = new ArrayList<String>();
-                String java_home = System.getProperty("java.home");
-                cmd.add(new File(new File(java_home, "bin"), "java").getPath());
-                if (classpath != null)
-                    cmd.add("-Xbootclasspath/p:" + classpath);
-                cmd.add(GenStubs.class.getName());
-                cmd.add("-sourcepath");
-                cmd.add(srcDir.getPath());
-                cmd.add("-s");
-                cmd.add(destDir.getPath());
-                cmd.addAll(classNames);
-                //System.err.println("GenStubs exec " + cmd);
-                ProcessBuilder pb = new ProcessBuilder(cmd);
-                pb.redirectErrorStream(true);
-                try {
-                    Process p = pb.start();
-                    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
-                    try {
-                        String line;
-                        while ((line = in.readLine()) != null)
-                            System.out.println(line);
-                    } finally {
-                        in.close();
-                    }
-                    int rc = p.waitFor();
-                    if (rc != 0)
-                        throw new BuildException("genstubs failed");
-                } catch (IOException e) {
-                    throw new BuildException("genstubs failed", e);
-                } catch (InterruptedException e) {
-                    throw new BuildException("genstubs failed", e);
-                }
-            }
-        }
-
-        String[] filter(File srcDir, File destDir, String[] files) {
-            List<String> results = new ArrayList<String>();
-            for (String f: files) {
-                long srcTime = new File(srcDir, f).lastModified();
-                long destTime = new File(destDir, f).lastModified();
-                if (srcTime > destTime)
-                    results.add(f);
-            }
-            return results.toArray(new String[results.size()]);
-        }
-    }
-}
diff --git a/langtools/make/tools/SelectTool/SelectToolTask.java b/langtools/make/tools/SelectTool/SelectToolTask.java
deleted file mode 100644
index b182b49..0000000
--- a/langtools/make/tools/SelectTool/SelectToolTask.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * 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.
- */
-
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.FocusEvent;
-import java.awt.event.FocusListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JComboBox;
-import javax.swing.JDialog;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JTextField;
-
-import javax.swing.SwingUtilities;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-
-/**
- * Task to allow the user to control langtools tools built when using NetBeans.
- *
- * There are two primary modes.
- * 1) Property mode. In this mode, property names are provided to get values
- * that may be specified by the user, either directly in a GUI dialog, or
- * read from a properties file. If the GUI dialog is invoked, values may
- * optionally be set for future use.
- * 2) Setup mode. In this mode, no property names are provided, and the GUI
- * is invoked to allow the user to set or reset values for use in property mode.
- */
-public class SelectToolTask extends Task {
-    /**
-     * Set the location of the private properties file used to keep the retain
-     * user preferences for this repository.
-     */
-    public void setPropertyFile(File propertyFile) {
-        this.propertyFile = propertyFile;
-    }
-
-    /**
-     * Set the name of the property which will be set to the name of the
-     * selected tool, if any. If no tool is selected, the property will
-     * remain unset.
-     */
-    public void setToolProperty(String toolProperty) {
-        this.toolProperty = toolProperty;
-    }
-
-    /**
-     * Set the name of the property which will be set to the execution args of the
-     * selected tool, if any. The args default to an empty string.
-     */
-    public void setArgsProperty(String argsProperty) {
-        this.argsProperty = argsProperty;
-    }
-
-    /**
-     * Specify whether or not to pop up a dialog if the user has not specified
-     * a default value for a property.
-     */
-    public void setAskIfUnset(boolean askIfUnset) {
-        this.askIfUnset = askIfUnset;
-    }
-
-    @Override
-    public void execute() {
-        Project p = getProject();
-
-        Properties props = readProperties(propertyFile);
-        toolName = props.getProperty("tool.name");
-        if (toolName != null) {
-            toolArgs = props.getProperty(toolName + ".args", "");
-        }
-
-        if (toolProperty == null ||
-            askIfUnset && (toolName == null
-                || (argsProperty != null && toolArgs == null))) {
-            showGUI(props);
-        }
-
-        // finally, return required values, if any
-        if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
-            p.setProperty(toolProperty, toolName);
-
-            if (argsProperty != null && toolArgs != null)
-                p.setProperty(argsProperty, toolArgs);
-        }
-    }
-
-    void showGUI(Properties fileProps) {
-        Properties guiProps = new Properties(fileProps);
-        JOptionPane p = createPane(guiProps);
-        p.createDialog("Select Tool").setVisible(true);
-
-        toolName = (String) toolChoice.getSelectedItem();
-        toolArgs = argsField.getText();
-
-        if (defaultCheck.isSelected()) {
-            if (toolName.equals("")) {
-                fileProps.remove("tool.name");
-            } else {
-                fileProps.put("tool.name", toolName);
-                fileProps.put(toolName + ".args", toolArgs);
-            }
-            writeProperties(propertyFile, fileProps);
-        }
-    }
-
-    JOptionPane createPane(final Properties props) {
-        JPanel body = new JPanel(new GridBagLayout());
-        GridBagConstraints lc = new GridBagConstraints();
-        lc.insets.right = 10;
-        lc.insets.bottom = 3;
-        GridBagConstraints fc = new GridBagConstraints();
-        fc.anchor = GridBagConstraints.WEST;
-        fc.gridx = 1;
-        fc.gridwidth = GridBagConstraints.REMAINDER;
-        fc.insets.bottom = 3;
-
-        JLabel toolLabel = new JLabel("Tool:");
-        body.add(toolLabel, lc);
-        String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" };
-        if (true || toolProperty == null) {
-            // include empty value in setup mode
-            List<String> l = new ArrayList<String>(Arrays.asList(toolChoices));
-            l.add(0, "");
-            toolChoices = l.toArray(new String[l.size()]);
-        }
-        toolChoice = new JComboBox(toolChoices);
-        if (toolName != null)
-            toolChoice.setSelectedItem(toolName);
-        toolChoice.addItemListener(new ItemListener() {
-            public void itemStateChanged(ItemEvent e) {
-                String tn = (String) e.getItem();
-                argsField.setText(getDefaultArgsForTool(props, tn));
-                if (toolProperty != null)
-                    okButton.setEnabled(!tn.equals(""));
-            }
-        });
-        body.add(toolChoice, fc);
-
-        argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40);
-        if (toolProperty == null || argsProperty != null) {
-            JLabel argsLabel = new JLabel("Args:");
-            body.add(argsLabel, lc);
-            body.add(argsField, fc);
-            argsField.addFocusListener(new FocusListener() {
-                public void focusGained(FocusEvent e) {
-                }
-                public void focusLost(FocusEvent e) {
-                    String toolName = (String) toolChoice.getSelectedItem();
-                    if (toolName.length() > 0)
-                        props.put(toolName + ".args", argsField.getText());
-                }
-            });
-        }
-
-        defaultCheck = new JCheckBox("Set as default");
-        if (toolProperty == null)
-            defaultCheck.setSelected(true);
-        else
-            body.add(defaultCheck, fc);
-
-        final JOptionPane p = new JOptionPane(body);
-        okButton = new JButton("OK");
-        okButton.setEnabled(toolProperty == null || (toolName != null && !toolName.equals("")));
-        okButton.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p);
-                d.setVisible(false);
-            }
-        });
-        p.setOptions(new Object[] { okButton });
-
-        return p;
-    }
-
-    Properties readProperties(File file) {
-        Properties p = new Properties();
-        if (file != null && file.exists()) {
-            Reader in = null;
-            try {
-                in = new BufferedReader(new FileReader(file));
-                p.load(in);
-                in.close();
-            } catch (IOException e) {
-                throw new BuildException("error reading property file", e);
-            } finally {
-                if (in != null) {
-                    try {
-                        in.close();
-                    } catch (IOException e) {
-                        throw new BuildException("cannot close property file", e);
-                    }
-                }
-            }
-        }
-        return p;
-    }
-
-    void writeProperties(File file, Properties p) {
-        if (file != null) {
-            Writer out = null;
-            try {
-                File dir = file.getParentFile();
-                if (dir != null && !dir.exists())
-                    dir.mkdirs();
-                out = new BufferedWriter(new FileWriter(file));
-                p.store(out, "langtools properties");
-                out.close();
-            } catch (IOException e) {
-                throw new BuildException("error writing property file", e);
-            } finally {
-                if (out != null) {
-                    try {
-                        out.close();
-                    } catch (IOException e) {
-                        throw new BuildException("cannot close property file", e);
-                    }
-                }
-            }
-        }
-    }
-
-    String getDefaultArgsForTool(Properties props, String tn) {
-        return (tn == null || tn.equals("")) ? "" : props.getProperty(tn + ".args", "");
-    }
-
-    // Ant task parameters
-    private boolean askIfUnset;
-    private String toolProperty;
-    private String argsProperty;
-    private File propertyFile;
-
-    // GUI components
-    private JComboBox toolChoice;
-    private JTextField argsField;
-    private JCheckBox defaultCheck;
-    private JButton okButton;
-
-    // Result values for the client
-    private String toolName;
-    private String toolArgs;
-}
diff --git a/langtools/make/tools/anttasks/CompilePropertiesTask.java b/langtools/make/tools/anttasks/CompilePropertiesTask.java
new file mode 100644
index 0000000..4615bd4
--- /dev/null
+++ b/langtools/make/tools/anttasks/CompilePropertiesTask.java
@@ -0,0 +1,101 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package anttasks;
+
+import compileproperties.CompileProperties;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.MatchingTask;
+
+public class CompilePropertiesTask extends MatchingTask {
+    public void setSrcDir(File srcDir) {
+        this.srcDir = srcDir;
+    }
+
+    public void setDestDir(File destDir) {
+        this.destDir = destDir;
+    }
+
+    public void setSuperclass(String superclass) {
+        this.superclass = superclass;
+    }
+
+    @Override
+    public void execute() {
+        CompileProperties.Log log = new CompileProperties.Log() {
+            public void error(String msg, Exception e) {
+                log(msg, Project.MSG_ERR);
+            }
+            public void info(String msg) {
+                log(msg, Project.MSG_INFO);
+            }
+            public void verbose(String msg) {
+                log(msg, Project.MSG_VERBOSE);
+            }
+        };
+        List<String> mainOpts = new ArrayList<String>();
+        int count = 0;
+        DirectoryScanner s = getDirectoryScanner(srcDir);
+        for (String path: s.getIncludedFiles()) {
+            if (path.endsWith(".properties")) {
+                String destPath =
+                        path.substring(0, path.length() - ".properties".length()) +
+                        ".java";
+                File srcFile = new File(srcDir, path);
+                File destFile = new File(destDir, destPath);
+                // Arguably, the comparison in the next line should be ">", not ">="
+                // but that assumes the resolution of the last modified time is fine
+                // grained enough; in practice, it is better to use ">=".
+                if (destFile.exists() && destFile.lastModified() >= srcFile.lastModified())
+                    continue;
+                destFile.getParentFile().mkdirs();
+                mainOpts.add("-compile");
+                mainOpts.add(srcFile.getPath());
+                mainOpts.add(destFile.getPath());
+                mainOpts.add(superclass);
+                count++;
+            }
+        }
+        if (mainOpts.size() > 0) {
+            log("Generating " + count + " resource files to " + destDir, Project.MSG_INFO);
+            CompileProperties cp = new CompileProperties();
+            cp.setLog(log);
+            boolean ok = cp.run(mainOpts.toArray(new String[mainOpts.size()]));
+            if (!ok)
+                throw new BuildException("CompileProperties failed.");
+        }
+    }
+
+    private File srcDir;
+    private File destDir;
+    private String superclass = "java.util.ListResourceBundle";
+}
diff --git a/langtools/make/tools/anttasks/GenStubsTask.java b/langtools/make/tools/anttasks/GenStubsTask.java
new file mode 100644
index 0000000..7212dc1
--- /dev/null
+++ b/langtools/make/tools/anttasks/GenStubsTask.java
@@ -0,0 +1,162 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package anttasks;
+
+import genstubs.GenStubs;
+
+import java.io.*;
+import java.util.*;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.taskdefs.MatchingTask;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+
+/**
+ * Files are specified with an implicit fileset, using srcdir as a base directory.
+ * The set of files to be included is specified with an includes attribute or
+ * nested <includes> set. However, unlike a normal fileset, an empty includes attribute
+ * means "no files" instead of "all files".  The Ant task also accepts "fork=true" and
+ * classpath attribute or nested <classpath> element to run GenStubs in a separate VM
+ * with the specified path. This is likely necessary if a JDK 7 parser is required to read the
+ * JDK 7 input files.
+ */
+public class GenStubsTask extends MatchingTask {
+    private File srcDir;
+    private File destDir;
+    private boolean fork;
+    private Path classpath;
+    private String includes;
+
+    public void setSrcDir(File dir) {
+        this.srcDir = dir;
+    }
+
+    public void setDestDir(File dir) {
+        this.destDir = dir;
+    }
+
+    public void setFork(boolean v) {
+        this.fork = v;
+    }
+
+    public void setClasspath(Path cp) {
+        if (classpath == null)
+            classpath = cp;
+        else
+            classpath.append(cp);
+    }
+
+    public Path createClasspath() {
+        if (classpath == null) {
+            classpath = new Path(getProject());
+        }
+        return classpath.createPath();
+    }
+
+    public void setClasspathRef(Reference r) {
+        createClasspath().setRefid(r);
+    }
+
+    public void setIncludes(String includes) {
+        super.setIncludes(includes);
+        this.includes = includes;
+    }
+
+    @Override
+    public void execute() {
+        if (includes != null && includes.trim().isEmpty())
+            return;
+
+        DirectoryScanner s = getDirectoryScanner(srcDir);
+        String[] files = s.getIncludedFiles();
+//            System.err.println("Ant.execute: srcDir " + srcDir);
+//            System.err.println("Ant.execute: destDir " + destDir);
+//            System.err.println("Ant.execute: files " + Arrays.asList(files));
+
+        files = filter(srcDir, destDir, files);
+        if (files.length == 0)
+            return;
+        System.out.println("Generating " + files.length + " stub files to " + destDir);
+
+        List<String> classNames = new ArrayList<String>();
+        for (String file: files) {
+            classNames.add(file.replaceAll(".java$", "").replace('/', '.'));
+        }
+
+        if (!fork) {
+            GenStubs m = new GenStubs();
+            boolean ok = m.run(srcDir.getPath(), destDir, classNames);
+            if (!ok)
+                throw new BuildException("genstubs failed");
+        } else {
+            List<String> cmd = new ArrayList<String>();
+            String java_home = System.getProperty("java.home");
+            cmd.add(new File(new File(java_home, "bin"), "java").getPath());
+            if (classpath != null)
+                cmd.add("-Xbootclasspath/p:" + classpath);
+            cmd.add(GenStubs.class.getName());
+            cmd.add("-sourcepath");
+            cmd.add(srcDir.getPath());
+            cmd.add("-s");
+            cmd.add(destDir.getPath());
+            cmd.addAll(classNames);
+            //System.err.println("GenStubs exec " + cmd);
+            ProcessBuilder pb = new ProcessBuilder(cmd);
+            pb.redirectErrorStream(true);
+            try {
+                Process p = pb.start();
+                BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+                try {
+                    String line;
+                    while ((line = in.readLine()) != null)
+                        System.out.println(line);
+                } finally {
+                    in.close();
+                }
+                int rc = p.waitFor();
+                if (rc != 0)
+                    throw new BuildException("genstubs failed");
+            } catch (IOException e) {
+                throw new BuildException("genstubs failed", e);
+            } catch (InterruptedException e) {
+                throw new BuildException("genstubs failed", e);
+            }
+        }
+    }
+
+    String[] filter(File srcDir, File destDir, String[] files) {
+        List<String> results = new ArrayList<String>();
+        for (String f: files) {
+            long srcTime = new File(srcDir, f).lastModified();
+            long destTime = new File(destDir, f).lastModified();
+            if (srcTime > destTime)
+                results.add(f);
+        }
+        return results.toArray(new String[results.size()]);
+    }
+}
diff --git a/langtools/make/tools/anttasks/SelectToolTask.java b/langtools/make/tools/anttasks/SelectToolTask.java
new file mode 100644
index 0000000..1fe21c4
--- /dev/null
+++ b/langtools/make/tools/anttasks/SelectToolTask.java
@@ -0,0 +1,286 @@
+/*
+ * 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 anttasks;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import javax.swing.SwingUtilities;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+
+/**
+ * Task to allow the user to control langtools tools built when using NetBeans.
+ *
+ * There are two primary modes.
+ * 1) Property mode. In this mode, property names are provided to get values
+ * that may be specified by the user, either directly in a GUI dialog, or
+ * read from a properties file. If the GUI dialog is invoked, values may
+ * optionally be set for future use.
+ * 2) Setup mode. In this mode, no property names are provided, and the GUI
+ * is invoked to allow the user to set or reset values for use in property mode.
+ */
+public class SelectToolTask extends Task {
+    /**
+     * Set the location of the private properties file used to keep the retain
+     * user preferences for this repository.
+     */
+    public void setPropertyFile(File propertyFile) {
+        this.propertyFile = propertyFile;
+    }
+
+    /**
+     * Set the name of the property which will be set to the name of the
+     * selected tool, if any. If no tool is selected, the property will
+     * remain unset.
+     */
+    public void setToolProperty(String toolProperty) {
+        this.toolProperty = toolProperty;
+    }
+
+    /**
+     * Set the name of the property which will be set to the execution args of the
+     * selected tool, if any. The args default to an empty string.
+     */
+    public void setArgsProperty(String argsProperty) {
+        this.argsProperty = argsProperty;
+    }
+
+    /**
+     * Specify whether or not to pop up a dialog if the user has not specified
+     * a default value for a property.
+     */
+    public void setAskIfUnset(boolean askIfUnset) {
+        this.askIfUnset = askIfUnset;
+    }
+
+    @Override
+    public void execute() {
+        Project p = getProject();
+
+        Properties props = readProperties(propertyFile);
+        toolName = props.getProperty("tool.name");
+        if (toolName != null) {
+            toolArgs = props.getProperty(toolName + ".args", "");
+        }
+
+        if (toolProperty == null ||
+            askIfUnset && (toolName == null
+                || (argsProperty != null && toolArgs == null))) {
+            showGUI(props);
+        }
+
+        // finally, return required values, if any
+        if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
+            p.setProperty(toolProperty, toolName);
+
+            if (argsProperty != null && toolArgs != null)
+                p.setProperty(argsProperty, toolArgs);
+        }
+    }
+
+    void showGUI(Properties fileProps) {
+        Properties guiProps = new Properties(fileProps);
+        JOptionPane p = createPane(guiProps);
+        p.createDialog("Select Tool").setVisible(true);
+
+        toolName = (String) toolChoice.getSelectedItem();
+        toolArgs = argsField.getText();
+
+        if (defaultCheck.isSelected()) {
+            if (toolName.equals("")) {
+                fileProps.remove("tool.name");
+            } else {
+                fileProps.put("tool.name", toolName);
+                fileProps.put(toolName + ".args", toolArgs);
+            }
+            writeProperties(propertyFile, fileProps);
+        }
+    }
+
+    JOptionPane createPane(final Properties props) {
+        JPanel body = new JPanel(new GridBagLayout());
+        GridBagConstraints lc = new GridBagConstraints();
+        lc.insets.right = 10;
+        lc.insets.bottom = 3;
+        GridBagConstraints fc = new GridBagConstraints();
+        fc.anchor = GridBagConstraints.WEST;
+        fc.gridx = 1;
+        fc.gridwidth = GridBagConstraints.REMAINDER;
+        fc.insets.bottom = 3;
+
+        JLabel toolLabel = new JLabel("Tool:");
+        body.add(toolLabel, lc);
+        String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" };
+        if (true || toolProperty == null) {
+            // include empty value in setup mode
+            List<String> l = new ArrayList<String>(Arrays.asList(toolChoices));
+            l.add(0, "");
+            toolChoices = l.toArray(new String[l.size()]);
+        }
+        toolChoice = new JComboBox(toolChoices);
+        if (toolName != null)
+            toolChoice.setSelectedItem(toolName);
+        toolChoice.addItemListener(new ItemListener() {
+            public void itemStateChanged(ItemEvent e) {
+                String tn = (String) e.getItem();
+                argsField.setText(getDefaultArgsForTool(props, tn));
+                if (toolProperty != null)
+                    okButton.setEnabled(!tn.equals(""));
+            }
+        });
+        body.add(toolChoice, fc);
+
+        argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40);
+        if (toolProperty == null || argsProperty != null) {
+            JLabel argsLabel = new JLabel("Args:");
+            body.add(argsLabel, lc);
+            body.add(argsField, fc);
+            argsField.addFocusListener(new FocusListener() {
+                public void focusGained(FocusEvent e) {
+                }
+                public void focusLost(FocusEvent e) {
+                    String toolName = (String) toolChoice.getSelectedItem();
+                    if (toolName.length() > 0)
+                        props.put(toolName + ".args", argsField.getText());
+                }
+            });
+        }
+
+        defaultCheck = new JCheckBox("Set as default");
+        if (toolProperty == null)
+            defaultCheck.setSelected(true);
+        else
+            body.add(defaultCheck, fc);
+
+        final JOptionPane p = new JOptionPane(body);
+        okButton = new JButton("OK");
+        okButton.setEnabled(toolProperty == null || (toolName != null && !toolName.equals("")));
+        okButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p);
+                d.setVisible(false);
+            }
+        });
+        p.setOptions(new Object[] { okButton });
+
+        return p;
+    }
+
+    Properties readProperties(File file) {
+        Properties p = new Properties();
+        if (file != null && file.exists()) {
+            Reader in = null;
+            try {
+                in = new BufferedReader(new FileReader(file));
+                p.load(in);
+                in.close();
+            } catch (IOException e) {
+                throw new BuildException("error reading property file", e);
+            } finally {
+                if (in != null) {
+                    try {
+                        in.close();
+                    } catch (IOException e) {
+                        throw new BuildException("cannot close property file", e);
+                    }
+                }
+            }
+        }
+        return p;
+    }
+
+    void writeProperties(File file, Properties p) {
+        if (file != null) {
+            Writer out = null;
+            try {
+                File dir = file.getParentFile();
+                if (dir != null && !dir.exists())
+                    dir.mkdirs();
+                out = new BufferedWriter(new FileWriter(file));
+                p.store(out, "langtools properties");
+                out.close();
+            } catch (IOException e) {
+                throw new BuildException("error writing property file", e);
+            } finally {
+                if (out != null) {
+                    try {
+                        out.close();
+                    } catch (IOException e) {
+                        throw new BuildException("cannot close property file", e);
+                    }
+                }
+            }
+        }
+    }
+
+    String getDefaultArgsForTool(Properties props, String tn) {
+        return (tn == null || tn.equals("")) ? "" : props.getProperty(tn + ".args", "");
+    }
+
+    // Ant task parameters
+    private boolean askIfUnset;
+    private String toolProperty;
+    private String argsProperty;
+    private File propertyFile;
+
+    // GUI components
+    private JComboBox toolChoice;
+    private JTextField argsField;
+    private JCheckBox defaultCheck;
+    private JButton okButton;
+
+    // Result values for the client
+    private String toolName;
+    private String toolArgs;
+}
diff --git a/langtools/make/tools/compileproperties/CompileProperties.java b/langtools/make/tools/compileproperties/CompileProperties.java
new file mode 100644
index 0000000..9a40592
--- /dev/null
+++ b/langtools/make/tools/compileproperties/CompileProperties.java
@@ -0,0 +1,404 @@
+/*
+ * 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.
+ */
+
+package compileproperties;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+/** Translates a .properties file into a .java file containing the
+ *  definition of a java.util.Properties subclass which can then be
+ *  compiled with javac. <P>
+ *
+ *  Usage: java CompileProperties [path to .properties file] [path to .java file to be output] [super class]
+ *
+ *  Infers the package by looking at the common suffix of the two
+ *  inputs, eliminating "classes" from it.
+ *
+ * @author Scott Violet
+ * @author Kenneth Russell
+ */
+
+public class CompileProperties {
+
+    public static void main(String[] args) {
+        CompileProperties cp = new CompileProperties();
+        boolean ok = cp.run(args);
+        if ( !ok ) {
+            System.exit(1);
+        }
+    }
+
+    public static interface Log {
+        void info(String msg);
+        void verbose(String msg);
+        void error(String msg, Exception e);
+    }
+
+    private String propfiles[];
+    private String outfiles[] ;
+    private String supers[]   ;
+    private int compileCount = 0;
+    private boolean quiet = false;
+    public Log log;
+
+    public void setLog(Log log) {
+        this.log = log;
+    }
+
+    public boolean run(String[] args) {
+        if (log == null) {
+            log = new Log() {
+                public void error(String msg, Exception e) {
+                    System.err.println("ERROR: CompileProperties: " + msg);
+                    if ( e != null ) {
+                        System.err.println("EXCEPTION: " + e.toString());
+                        e.printStackTrace();
+                    }
+                }
+                public void info(String msg) {
+                    System.out.println(msg);
+                }
+                public void verbose(String msg) {
+                    if (!quiet)
+                        System.out.println(msg);
+                }
+            };
+        }
+
+        boolean ok = true;
+        /* Original usage */
+        if (args.length == 2 && args[0].charAt(0) != '-' ) {
+            ok = createFile(args[0], args[1], "java.util.ListResourceBundle");
+        } else if (args.length == 3) {
+            ok = createFile(args[0], args[1], args[2]);
+        } else if (args.length == 0) {
+            usage(log);
+            ok = false;
+        } else {
+            /* New batch usage */
+            ok = parseOptions(args);
+            if ( ok && compileCount == 0 ) {
+                log.error("options parsed but no files to compile", null);
+                ok = false;
+            }
+            /* Need at least one file. */
+            if ( !ok ) {
+                usage(log);
+            } else {
+                /* Process files */
+                for ( int i = 0; i < compileCount && ok ; i++ ) {
+                    ok = createFile(propfiles[i], outfiles[i], supers[i]);
+                }
+            }
+        }
+        return ok;
+    }
+
+    private boolean parseOptions(String args[]) {
+        boolean ok = true;
+        if ( compileCount > 0 ) {
+            String new_propfiles[] = new String[compileCount + args.length];
+            String new_outfiles[]  = new String[compileCount + args.length];
+            String new_supers[]    = new String[compileCount + args.length];
+            System.arraycopy(propfiles, 0, new_propfiles, 0, compileCount);
+            System.arraycopy(outfiles, 0, new_outfiles, 0, compileCount);
+            System.arraycopy(supers, 0, new_supers, 0, compileCount);
+            propfiles = new_propfiles;
+            outfiles  = new_outfiles;
+            supers    = new_supers;
+        } else {
+            propfiles = new String[args.length];
+            outfiles  = new String[args.length];
+            supers    = new String[args.length];
+        }
+
+        for ( int i = 0; i < args.length ; i++ ) {
+            if ( "-compile".equals(args[i]) && i+3 < args.length ) {
+                propfiles[compileCount] = args[++i];
+                outfiles[compileCount]  = args[++i];
+                supers[compileCount]    = args[++i];
+                compileCount++;
+            } else if ( "-optionsfile".equals(args[i]) && i+1 < args.length ) {
+                String filename = args[++i];
+                FileInputStream finput = null;
+                byte contents[] = null;
+                try {
+                    finput = new FileInputStream(filename);
+                    int byteCount = finput.available();
+                    if ( byteCount <= 0 ) {
+                        log.error("The -optionsfile file is empty", null);
+                        ok = false;
+                    } else {
+                        contents = new byte[byteCount];
+                        int bytesRead = finput.read(contents);
+                        if ( byteCount != bytesRead ) {
+                            log.error("Cannot read all of -optionsfile file", null);
+                            ok = false;
+                        }
+                    }
+                } catch ( IOException e ) {
+                    log.error("cannot open " + filename, e);
+                    ok = false;
+                }
+                if ( finput != null ) {
+                    try {
+                        finput.close();
+                    } catch ( IOException e ) {
+                        ok = false;
+                        log.error("cannot close " + filename, e);
+                    }
+                }
+                if ( ok = true && contents != null ) {
+                    String tokens[] = (new String(contents)).split("\\s+");
+                    if ( tokens.length > 0 ) {
+                        ok = parseOptions(tokens);
+                    }
+                }
+                if ( !ok ) {
+                    break;
+                }
+            } else if ( "-quiet".equals(args[i]) ) {
+                quiet = true;
+            } else {
+                log.error("argument error", null);
+                ok = false;
+            }
+        }
+        return ok;
+    }
+
+    private boolean createFile(String propertiesPath, String outputPath,
+            String superClass) {
+        boolean ok = true;
+        log.verbose("parsing: " + propertiesPath);
+        Properties p = new Properties();
+        try {
+            p.load(new FileInputStream(propertiesPath));
+        } catch ( FileNotFoundException e ) {
+            ok = false;
+            log.error("Cannot find file " + propertiesPath, e);
+        } catch ( IOException e ) {
+            ok = false;
+            log.error("IO error on file " + propertiesPath, e);
+        }
+        if ( ok ) {
+            String packageName = inferPackageName(propertiesPath, outputPath);
+            log.verbose("inferred package name: " + packageName);
+            List<String> sortedKeys = new ArrayList<String>();
+            for ( Object key : p.keySet() ) {
+                sortedKeys.add((String)key);
+            }
+            Collections.sort(sortedKeys);
+            Iterator<String> keys = sortedKeys.iterator();
+
+            StringBuffer data = new StringBuffer();
+
+            while (keys.hasNext()) {
+                String key = keys.next();
+                data.append("            { \"" + escape(key) + "\", \"" +
+                        escape((String)p.get(key)) + "\" },\n");
+            }
+
+            // Get class name from java filename, not the properties filename.
+            //   (zh_TW properties might be used to create zh_HK files)
+            File file = new File(outputPath);
+            String name = file.getName();
+            int dotIndex = name.lastIndexOf('.');
+            String className;
+            if (dotIndex == -1) {
+                className = name;
+            } else {
+                className = name.substring(0, dotIndex);
+            }
+
+            String packageString = "";
+            if (packageName != null && !packageName.equals("")) {
+                packageString = "package " + packageName + ";\n\n";
+            }
+
+            Writer writer = null;
+            try {
+                writer = new BufferedWriter(
+                        new OutputStreamWriter(new FileOutputStream(outputPath), "8859_1"));
+                MessageFormat format = new MessageFormat(FORMAT);
+                writer.write(format.format(new Object[] { packageString, className, superClass, data }));
+            } catch ( IOException e ) {
+                ok = false;
+                log.error("IO error writing to file " + outputPath, e);
+            }
+            if ( writer != null ) {
+                try {
+                    writer.flush();
+                } catch ( IOException e ) {
+                    ok = false;
+                    log.error("IO error flush " + outputPath, e);
+                }
+                try {
+                    writer.close();
+                } catch ( IOException e ) {
+                    ok = false;
+                    log.error("IO error close " + outputPath, e);
+                }
+            }
+            log.verbose("wrote: " + outputPath);
+        }
+        return ok;
+    }
+
+    private static void usage(Log log) {
+        log.info("usage:");
+        log.info("    java CompileProperties path_to_properties_file path_to_java_output_file [super_class]");
+        log.info("      -OR-");
+        log.info("    java CompileProperties {-compile path_to_properties_file path_to_java_output_file super_class} -or- -optionsfile filename");
+        log.info("");
+        log.info("Example:");
+        log.info("    java CompileProperties -compile test.properties test.java java.util.ListResourceBundle");
+        log.info("    java CompileProperties -optionsfile option_file");
+        log.info("option_file contains: -compile test.properties test.java java.util.ListResourceBundle");
+    }
+
+    private static String escape(String theString) {
+        // This is taken from Properties.saveConvert with changes for Java strings
+        int len = theString.length();
+        StringBuffer outBuffer = new StringBuffer(len*2);
+
+        for(int x=0; x<len; x++) {
+            char aChar = theString.charAt(x);
+            switch(aChar) {
+                case '\\':outBuffer.append('\\'); outBuffer.append('\\');
+                break;
+                case '\t':outBuffer.append('\\'); outBuffer.append('t');
+                break;
+                case '\n':outBuffer.append('\\'); outBuffer.append('n');
+                break;
+                case '\r':outBuffer.append('\\'); outBuffer.append('r');
+                break;
+                case '\f':outBuffer.append('\\'); outBuffer.append('f');
+                break;
+                default:
+                    if ((aChar < 0x0020) || (aChar > 0x007e)) {
+                        outBuffer.append('\\');
+                        outBuffer.append('u');
+                        outBuffer.append(toHex((aChar >> 12) & 0xF));
+                        outBuffer.append(toHex((aChar >>  8) & 0xF));
+                        outBuffer.append(toHex((aChar >>  4) & 0xF));
+                        outBuffer.append(toHex( aChar        & 0xF));
+                    } else {
+                        if (specialSaveChars.indexOf(aChar) != -1) {
+                            outBuffer.append('\\');
+                        }
+                        outBuffer.append(aChar);
+                    }
+            }
+        }
+        return outBuffer.toString();
+    }
+
+    private static String inferPackageName(String inputPath, String outputPath) {
+        // Normalize file names
+        inputPath  = new File(inputPath).getPath();
+        outputPath = new File(outputPath).getPath();
+        // Split into components
+        String sep;
+        if (File.separatorChar == '\\') {
+            sep = "\\\\";
+        } else {
+            sep = File.separator;
+        }
+        String[] inputs  = inputPath.split(sep);
+        String[] outputs = outputPath.split(sep);
+        // Match common names, eliminating first "classes" entry from
+        // each if present
+        int inStart  = 0;
+        int inEnd    = inputs.length - 2;
+        int outEnd   = outputs.length - 2;
+        int i = inEnd;
+        int j = outEnd;
+        while (i >= 0 && j >= 0) {
+            if (!inputs[i].equals(outputs[j]) ||
+                    (inputs[i].equals("gensrc") && inputs[j].equals("gensrc"))) {
+                ++i;
+                ++j;
+                break;
+            }
+            --i;
+            --j;
+        }
+        String result;
+        if (i < 0 || j < 0 || i >= inEnd || j >= outEnd) {
+            result = "";
+        } else {
+            if (inputs[i].equals("classes") && outputs[j].equals("classes")) {
+                ++i;
+            }
+            inStart = i;
+            StringBuffer buf = new StringBuffer();
+            for (i = inStart; i <= inEnd; i++) {
+                buf.append(inputs[i]);
+                if (i < inEnd) {
+                    buf.append('.');
+                }
+            }
+            result = buf.toString();
+        }
+        return result;
+    }
+
+    private static final String FORMAT =
+            "{0}" +
+            "public final class {1} extends {2} '{'\n" +
+            "    protected final Object[][] getContents() '{'\n" +
+            "        return new Object[][] '{'\n" +
+            "{3}" +
+            "        };\n" +
+            "    }\n" +
+            "}\n";
+
+    // This comes from Properties
+    private static char toHex(int nibble) {
+        return hexDigit[(nibble & 0xF)];
+    }
+
+    // This comes from Properties
+    private static final char[] hexDigit = {
+        '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
+    };
+
+    // Note: different from that in Properties
+    private static final String specialSaveChars = "\"";
+}
diff --git a/langtools/make/tools/genstubs/GenStubs.java b/langtools/make/tools/genstubs/GenStubs.java
new file mode 100644
index 0000000..f43df55
--- /dev/null
+++ b/langtools/make/tools/genstubs/GenStubs.java
@@ -0,0 +1,316 @@
+/*
+ * Copyright (c) 2009, 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 genstubs;
+
+import java.io.*;
+import java.util.*;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.util.JavacTask;
+import com.sun.tools.javac.api.JavacTool;
+import com.sun.tools.javac.code.Flags;
+import com.sun.tools.javac.code.TypeTags;
+import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
+import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
+import com.sun.tools.javac.tree.JCTree.JCIdent;
+import com.sun.tools.javac.tree.JCTree.JCImport;
+import com.sun.tools.javac.tree.JCTree.JCLiteral;
+import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
+import com.sun.tools.javac.tree.JCTree.JCModifiers;
+import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
+import com.sun.tools.javac.tree.Pretty;
+import com.sun.tools.javac.tree.TreeMaker;
+import com.sun.tools.javac.tree.TreeScanner;
+import com.sun.tools.javac.tree.TreeTranslator;
+import com.sun.tools.javac.util.Context;
+import com.sun.tools.javac.util.ListBuffer;
+import com.sun.tools.javac.util.Name;
+import javax.tools.JavaFileManager;
+
+/**
+ * Generate stub source files by removing implementation details from input files.
+ *
+ * This is a special purpose stub generator, specific to the needs of generating
+ * stub files for JDK 7 API that are needed to compile langtools files that depend
+ * on that API. The stub generator works by removing as much of the API source code
+ * as possible without affecting the public signature, in order to reduce the
+ * transitive closure of the API being referenced. The resulting stubs can be
+ * put on the langtools sourcepath with -implicit:none to compile the langtools
+ * files that depend on the JDK 7 API.
+ *
+ * Usage:
+ *  genstubs -s <outdir> -sourcepath <path> <classnames>
+ *
+ * The specified class names are looked up on the sourcepath, and corresponding
+ * stubs are written to the source output directory.
+ *
+ * Classes are parsed into javac ASTs, then processed with a javac TreeTranslator
+ * to remove implementation details, and written out in the source output directory.
+ * Documentation comments and annotations are removed. Method bodies are removed
+ * and methods are marked native. Private and package-private field definitions
+ * have their initializers replace with 0, 0.0, false, null as appropriate.
+ */
+
+public class GenStubs {
+    static class Fault extends Exception {
+        private static final long serialVersionUID = 0;
+        Fault(String message) {
+            super(message);
+        }
+        Fault(String message, Throwable cause) {
+            super(message);
+            initCause(cause);
+        }
+    }
+
+    public static void main(String[] args) {
+        boolean ok = new GenStubs().run(args);
+        if (!ok)
+            System.exit(1);
+    }
+
+    public boolean run(String... args) {
+        File outdir = null;
+        String sourcepath = null;
+        List<String> classes = new ArrayList<String>();
+        for (ListIterator<String> iter = Arrays.asList(args).listIterator(); iter.hasNext(); ) {
+            String arg = iter.next();
+            if (arg.equals("-s") && iter.hasNext())
+                outdir = new File(iter.next());
+            else if (arg.equals("-sourcepath") && iter.hasNext())
+                sourcepath = iter.next();
+            else if (arg.startsWith("-"))
+                throw new IllegalArgumentException(arg);
+            else {
+                classes.add(arg);
+                while (iter.hasNext())
+                    classes.add(iter.next());
+            }
+        }
+
+        return run(sourcepath, outdir, classes);
+    }
+
+    public boolean run(String sourcepath, File outdir, List<String> classes) {
+        //System.err.println("run: sourcepath:" + sourcepath + " outdir:" + outdir + " classes:" + classes);
+        if (sourcepath == null)
+            throw new IllegalArgumentException("sourcepath not set");
+        if (outdir == null)
+            throw new IllegalArgumentException("source output dir not set");
+
+        JavacTool tool = JavacTool.create();
+        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
+
+        try {
+            fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir));
+            fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath));
+            List<JavaFileObject> files = new ArrayList<JavaFileObject>();
+            for (String c: classes) {
+                JavaFileObject fo = fm.getJavaFileForInput(
+                        StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE);
+                if (fo == null)
+                    error("class not found: " + c);
+                else
+                    files.add(fo);
+            }
+
+            JavacTask t = tool.getTask(null, fm, null, null, null, files);
+            Iterable<? extends CompilationUnitTree> trees = t.parse();
+            for (CompilationUnitTree tree: trees) {
+                makeStub(fm, tree);
+            }
+        } catch (IOException e) {
+            error("IO error " + e, e);
+        }
+
+        return (errors == 0);
+    }
+
+    void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException {
+        CompilationUnitTree tree2 = new StubMaker().translate(tree);
+        CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2);
+
+        String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile());
+        JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT,
+                className, JavaFileObject.Kind.SOURCE, null);
+        // System.err.println("Writing " + className + " to " + fo.getName());
+        Writer out = fo.openWriter();
+        try {
+            new Pretty(out, true).printExpr((JCTree) tree3);
+        } finally {
+            out.close();
+        }
+    }
+
+    List<File> splitPath(String path) {
+        List<File> list = new ArrayList<File>();
+        for (String p: path.split(File.pathSeparator)) {
+            if (p.length() > 0)
+                list.add(new File(p));
+        }
+        return list;
+    }
+
+    void error(String message) {
+        System.err.println(message);
+        errors++;
+    }
+
+    void error(String message, Throwable cause) {
+        error(message);
+    }
+
+    int errors;
+
+    class StubMaker extends TreeTranslator {
+        CompilationUnitTree translate(CompilationUnitTree tree) {
+            return super.translate((JCCompilationUnit) tree);
+        }
+
+        /**
+         * compilation units: remove javadoc comments
+         * -- required, in order to remove @deprecated tags, since we
+         * (separately) remove all annotations, including @Deprecated
+         */
+        public void visitTopLevel(JCCompilationUnit tree) {
+            super.visitTopLevel(tree);
+            tree.docComments = Collections.emptyMap();
+        }
+
+        /**
+         * methods: remove method bodies, make methods native
+         */
+        @Override
+        public void visitMethodDef(JCMethodDecl tree) {
+            tree.mods = translate(tree.mods);
+            tree.restype = translate(tree.restype);
+            tree.typarams = translateTypeParams(tree.typarams);
+            tree.params = translateVarDefs(tree.params);
+            tree.thrown = translate(tree.thrown);
+            if (tree.restype != null && tree.body != null) {
+                tree.mods.flags |= Flags.NATIVE;
+                tree.body = null;
+            }
+            result = tree;
+        }
+
+        /**
+         * modifiers: remove annotations
+         */
+        @Override
+        public void visitModifiers(JCModifiers tree) {
+            tree.annotations = com.sun.tools.javac.util.List.nil();
+            result = tree;
+        }
+
+        /**
+         * field definitions: replace initializers with 0, 0.0, false etc
+         * when possible -- i.e. leave public, protected initializers alone
+         */
+        @Override
+        public void visitVarDef(JCVariableDecl tree) {
+            tree.mods = translate(tree.mods);
+            tree.vartype = translate(tree.vartype);
+            if (tree.init != null) {
+                if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
+                    tree.init = translate(tree.init);
+                else {
+                    String t = tree.vartype.toString();
+                    if (t.equals("boolean"))
+                        tree.init = new JCLiteral(TypeTags.BOOLEAN, 0) { };
+                    else if (t.equals("byte"))
+                        tree.init = new JCLiteral(TypeTags.BYTE, 0) { };
+                    else if (t.equals("char"))
+                        tree.init = new JCLiteral(TypeTags.CHAR, 0) { };
+                    else if (t.equals("double"))
+                        tree.init = new JCLiteral(TypeTags.DOUBLE, 0.d) { };
+                    else if (t.equals("float"))
+                        tree.init = new JCLiteral(TypeTags.FLOAT, 0.f) { };
+                    else if (t.equals("int"))
+                        tree.init = new JCLiteral(TypeTags.INT, 0) { };
+                    else if (t.equals("long"))
+                        tree.init = new JCLiteral(TypeTags.LONG, 0) { };
+                    else if (t.equals("short"))
+                        tree.init = new JCLiteral(TypeTags.SHORT, 0) { };
+                    else
+                        tree.init = new JCLiteral(TypeTags.BOT, null) { };
+                }
+            }
+            result = tree;
+        }
+    }
+
+    class ImportCleaner extends TreeScanner {
+        private Set<Name> names = new HashSet<Name>();
+        private TreeMaker m;
+
+        ImportCleaner(JavaFileManager fm) {
+            // ImportCleaner itself doesn't require a filemanager, but instantiating
+            // a TreeMaker does, indirectly (via ClassReader, sigh)
+            Context c = new Context();
+            c.put(JavaFileManager.class, fm);
+            m = TreeMaker.instance(c);
+        }
+
+        CompilationUnitTree removeRedundantImports(CompilationUnitTree t) {
+            JCCompilationUnit tree = (JCCompilationUnit) t;
+            tree.accept(this);
+            ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
+            for (JCTree def: tree.defs) {
+                if (def.getTag() == JCTree.Tag.IMPORT) {
+                    JCImport imp = (JCImport) def;
+                    if (imp.qualid.getTag() == JCTree.Tag.SELECT) {
+                        JCFieldAccess qualid = (JCFieldAccess) imp.qualid;
+                        if (!qualid.name.toString().equals("*")
+                                && !names.contains(qualid.name)) {
+                            continue;
+                        }
+                    }
+                }
+                defs.add(def);
+            }
+            return m.TopLevel(tree.packageAnnotations, tree.pid, defs.toList());
+        }
+
+        @Override
+        public void visitImport(JCImport tree) { } // ignore names found in imports
+
+        @Override
+        public void visitIdent(JCIdent tree) {
+            names.add(tree.name);
+        }
+
+        @Override
+        public void visitSelect(JCFieldAccess tree) {
+            super.visitSelect(tree);
+            names.add(tree.name);
+        }
+    }
+}
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 4903886..7e2e20b 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
@@ -1235,7 +1235,7 @@
             // if origin is derived from a raw type, we might have missed
             // an implementation because we do not know enough about instantiations.
             // in this case continue with the supertype as origin.
-            if (types.isDerivedRaw(origin.type))
+            if (types.isDerivedRaw(origin.type) && !origin.isInterface())
                 return implementation(types.supertype(origin.type).tsym, types, checkResult);
             else
                 return null;
diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
index ec620d2..b50d1df 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -199,16 +199,15 @@
      *  @param tree     The tree whose kind and type is checked
      *  @param owntype  The computed type of the tree
      *  @param ownkind  The computed kind of the tree
-     *  @param pkind    The expected kind (or: protokind) of the tree
-     *  @param pt       The expected type (or: prototype) of the tree
+     *  @param resultInfo  The expected result of the tree
      */
-    Type check(JCTree tree, Type owntype, int ownkind, int pkind, Type pt) {
-        if (owntype.tag != ERROR && pt.tag != METHOD && pt.tag != FORALL) {
-            if ((ownkind & ~pkind) == 0) {
-                owntype = chk.checkType(tree.pos(), owntype, pt, errKey);
+    Type check(JCTree tree, Type owntype, int ownkind, ResultInfo resultInfo) {
+        if (owntype.tag != ERROR && resultInfo.pt.tag != METHOD && resultInfo.pt.tag != FORALL) {
+            if ((ownkind & ~resultInfo.pkind) == 0) {
+                owntype = chk.checkType(tree.pos(), owntype, resultInfo.pt, errKey);
             } else {
                 log.error(tree.pos(), "unexpected.type",
-                          kindNames(pkind),
+                          kindNames(resultInfo.pkind),
                           kindName(ownkind));
                 owntype = types.createErrorType(owntype);
             }
@@ -333,7 +332,16 @@
     public Type attribType(JCTree node, TypeSymbol sym) {
         Env<AttrContext> env = enter.typeEnvs.get(sym);
         Env<AttrContext> localEnv = env.dup(node, env.info.dup());
-        return attribTree(node, localEnv, Kinds.TYP, Type.noType);
+        return attribTree(node, localEnv, unknownTypeInfo);
+    }
+
+    public Type attribImportQualifier(JCImport tree, Env<AttrContext> env) {
+        // Attribute qualifying package or class.
+        JCFieldAccess s = (JCFieldAccess)tree.qualid;
+        return attribTree(s.selected,
+                       env,
+                       new ResultInfo(tree.staticImport ? TYP : (TYP | PCK),
+                       Type.noType));
     }
 
     public Env<AttrContext> attribExprToTree(JCTree expr, Env<AttrContext> env, JCTree tree) {
@@ -386,6 +394,28 @@
         }
     }
 
+    static class ResultInfo {
+        int pkind;
+        Type pt;
+
+        ResultInfo(int pkind, Type pt) {
+            this.pkind = pkind;
+            this.pt = pt;
+        }
+    }
+
+    private final ResultInfo statInfo = new ResultInfo(NIL, Type.noType);
+    private final ResultInfo varInfo = new ResultInfo(VAR, Type.noType);
+    private final ResultInfo unknownExprInfo = new ResultInfo(VAL, Type.noType);
+    private final ResultInfo unknownTypeInfo = new ResultInfo(TYP, Type.noType);
+
+    Type pt() {
+        return resultInfo.pt;
+    }
+
+    int pkind() {
+        return resultInfo.pkind;
+    }
 
 /* ************************************************************************
  * Visitor methods
@@ -395,13 +425,9 @@
      */
     Env<AttrContext> env;
 
-    /** Visitor argument: the currently expected proto-kind.
+    /** Visitor argument: the currently expected attribution result.
      */
-    int pkind;
-
-    /** Visitor argument: the currently expected proto-type.
-     */
-    Type pt;
+    ResultInfo resultInfo;
 
     /** Visitor argument: the error key to be generated when a type error occurs
      */
@@ -416,22 +442,19 @@
      *
      *  @param tree    The tree to be visited.
      *  @param env     The environment visitor argument.
-     *  @param pkind   The protokind visitor argument.
-     *  @param pt      The prototype visitor argument.
+     *  @param resultInfo   The result info visitor argument.
      */
-    Type attribTree(JCTree tree, Env<AttrContext> env, int pkind, Type pt) {
-        return attribTree(tree, env, pkind, pt, "incompatible.types");
+    private Type attribTree(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) {
+        return attribTree(tree, env, resultInfo, "incompatible.types");
     }
 
-    Type attribTree(JCTree tree, Env<AttrContext> env, int pkind, Type pt, String errKey) {
+    private Type attribTree(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo, String errKey) {
         Env<AttrContext> prevEnv = this.env;
-        int prevPkind = this.pkind;
-        Type prevPt = this.pt;
+        ResultInfo prevResult = this.resultInfo;
         String prevErrKey = this.errKey;
         try {
             this.env = env;
-            this.pkind = pkind;
-            this.pt = pt;
+            this.resultInfo = resultInfo;
             this.errKey = errKey;
             tree.accept(this);
             if (tree == breakTree)
@@ -442,8 +465,7 @@
             return chk.completionError(tree.pos(), ex);
         } finally {
             this.env = prevEnv;
-            this.pkind = prevPkind;
-            this.pt = prevPt;
+            this.resultInfo = prevResult;
             this.errKey = prevErrKey;
         }
     }
@@ -451,18 +473,18 @@
     /** Derived visitor method: attribute an expression tree.
      */
     public Type attribExpr(JCTree tree, Env<AttrContext> env, Type pt) {
-        return attribTree(tree, env, VAL, pt.tag != ERROR ? pt : Type.noType);
+        return attribExpr(tree, env, pt, "incompatible.types");
     }
 
     public Type attribExpr(JCTree tree, Env<AttrContext> env, Type pt, String key) {
-        return attribTree(tree, env, VAL, pt.tag != ERROR ? pt : Type.noType, key);
+        return attribTree(tree, env, new ResultInfo(VAL, pt.tag != ERROR ? pt : Type.noType), key);
     }
 
     /** Derived visitor method: attribute an expression tree with
      *  no constraints on the computed type.
      */
     Type attribExpr(JCTree tree, Env<AttrContext> env) {
-        return attribTree(tree, env, VAL, Type.noType);
+        return attribTree(tree, env, unknownExprInfo);
     }
 
     /** Derived visitor method: attribute a type tree.
@@ -475,14 +497,14 @@
     /** Derived visitor method: attribute a type tree.
      */
     Type attribType(JCTree tree, Env<AttrContext> env, Type pt) {
-        Type result = attribTree(tree, env, TYP, pt);
+        Type result = attribTree(tree, env, new ResultInfo(TYP, pt));
         return result;
     }
 
     /** Derived visitor method: attribute a statement or definition tree.
      */
     public Type attribStat(JCTree tree, Env<AttrContext> env) {
-        return attribTree(tree, env, NIL, Type.noType);
+        return attribTree(tree, env, statInfo);
     }
 
     /** Attribute a list of expressions, returning a list of types.
@@ -507,7 +529,7 @@
         ListBuffer<Type> argtypes = new ListBuffer<Type>();
         for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail)
             argtypes.append(chk.checkNonVoid(
-                l.head.pos(), types.upperBound(attribTree(l.head, env, VAL, Infer.anyPoly))));
+                l.head.pos(), types.upperBound(attribExpr(l.head, env, Infer.anyPoly))));
         return argtypes.toList();
     }
 
@@ -1181,7 +1203,7 @@
         result = check(tree,
                        capture(condType(tree.pos(), tree.cond.type,
                                         tree.truepart.type, tree.falsepart.type)),
-                       VAL, pkind, pt);
+                       VAL, resultInfo);
     }
     //where
         /** Compute the type of a conditional expression, after
@@ -1500,8 +1522,8 @@
                     // ...and check that it is legal in the current context.
                     // (this will also set the tree's type)
                     Type mpt = newMethTemplate(argtypes, typeargtypes);
-                    checkId(tree.meth, site, sym, localEnv, MTH,
-                            mpt, tree.varargsElement != null);
+                    checkId(tree.meth, site, sym, localEnv, new ResultInfo(MTH, mpt),
+                            tree.varargsElement != null);
                 }
                 // Otherwise, `site' is an error type and we do nothing
             }
@@ -1518,8 +1540,6 @@
             Type mpt = newMethTemplate(argtypes, typeargtypes);
             localEnv.info.varArgs = false;
             Type mtype = attribExpr(tree.meth, localEnv, mpt);
-            if (localEnv.info.varArgs)
-                Assert.check(mtype.isErroneous() || tree.varargsElement != null);
 
             // Compute the result type.
             Type restype = mtype.getReturnType();
@@ -1552,7 +1572,10 @@
 
             // Check that value of resulting type is admissible in the
             // current context.  Also, capture the return type
-            result = check(tree, capture(restype), VAL, pkind, pt);
+            result = check(tree, capture(restype), VAL, resultInfo);
+
+            if (localEnv.info.varArgs)
+                Assert.check(result.isErroneous() || tree.varargsElement != null);
         }
         chk.validate(tree.typeargs, localEnv);
     }
@@ -1627,7 +1650,6 @@
         // Attribute clazz expression and store
         // symbol + type back into the attributed tree.
         Type clazztype = attribType(clazz, env);
-        Pair<Scope,Scope> mapping = getSyntheticScopeMapping(clazztype);
         clazztype = chk.checkDiamond(tree, clazztype);
         chk.validate(clazz, localEnv);
         if (tree.encl != null) {
@@ -1654,7 +1676,7 @@
         List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv);
 
         if (TreeInfo.isDiamond(tree) && !clazztype.isErroneous()) {
-            clazztype = attribDiamond(localEnv, tree, clazztype, mapping, argtypes, typeargtypes);
+            clazztype = attribDiamond(localEnv, tree, clazztype, argtypes, typeargtypes);
             clazz.type = clazztype;
         } else if (allowDiamondFinder &&
                 tree.def == null &&
@@ -1671,7 +1693,6 @@
                 inferred = attribDiamond(localEnv,
                         tree,
                         clazztype,
-                        mapping,
                         argtypes,
                         typeargtypes);
             }
@@ -1682,7 +1703,7 @@
             if (inferred != null &&
                     !inferred.isErroneous() &&
                     inferred.tag == CLASS &&
-                    types.isAssignable(inferred, pt.tag == NONE ? clazztype : pt, Warner.noWarnings)) {
+                    types.isAssignable(inferred, pt().tag == NONE ? clazztype : pt(), Warner.noWarnings)) {
                 String key = types.isSameType(clazztype, inferred) ?
                     "diamond.redundant.args" :
                     "diamond.redundant.args.1";
@@ -1732,7 +1753,7 @@
                     tree.pos(), rsEnv, clazztype, argtypes, typeargtypes);
                 tree.constructorType = tree.constructor.type.isErroneous() ?
                     syms.errType :
-                    checkMethod(clazztype,
+                    checkConstructor(clazztype,
                         tree.constructor,
                         rsEnv,
                         tree.args,
@@ -1807,7 +1828,7 @@
                     tree.constructorType =  syms.errType;
                 }
                 else {
-                    tree.constructorType = checkMethod(clazztype,
+                    tree.constructorType = checkConstructor(clazztype,
                             tree.constructor,
                             localEnv,
                             tree.args,
@@ -1820,19 +1841,17 @@
             if (tree.constructor != null && tree.constructor.kind == MTH)
                 owntype = clazztype;
         }
-        result = check(tree, owntype, VAL, pkind, pt);
+        result = check(tree, owntype, VAL, resultInfo);
         chk.validate(tree.typeargs, localEnv);
     }
 
     Type attribDiamond(Env<AttrContext> env,
                         JCNewClass tree,
                         Type clazztype,
-                        Pair<Scope, Scope> mapping,
                         List<Type> argtypes,
                         List<Type> typeargtypes) {
         if (clazztype.isErroneous() ||
-                clazztype.isInterface() ||
-                mapping == erroneousMapping) {
+                clazztype.isInterface()) {
             //if the type of the instance creation expression is erroneous,
             //or if it's an interface, or if something prevented us to form a valid
             //mapping, return the (possibly erroneous) type unchanged
@@ -1841,27 +1860,22 @@
 
         //dup attribution environment and augment the set of inference variables
         Env<AttrContext> localEnv = env.dup(tree);
-        localEnv.info.tvars = clazztype.tsym.type.getTypeArguments();
+
+        ClassType site = new ClassType(clazztype.getEnclosingType(),
+                    clazztype.tsym.type.getTypeArguments(),
+                    clazztype.tsym);
 
         //if the type of the instance creation expression is a class type
         //apply method resolution inference (JLS 15.12.2.7). The return type
         //of the resolved constructor will be a partially instantiated type
-        ((ClassSymbol) clazztype.tsym).members_field = mapping.snd;
-        Symbol constructor;
-        try {
-            constructor = rs.resolveDiamond(tree.pos(),
+        Symbol constructor = rs.resolveDiamond(tree.pos(),
                     localEnv,
-                    clazztype,
+                    site,
                     argtypes,
                     typeargtypes);
-        } finally {
-            ((ClassSymbol) clazztype.tsym).members_field = mapping.fst;
-        }
+
         if (constructor.kind == MTH) {
-            ClassType ct = new ClassType(clazztype.getEnclosingType(),
-                    clazztype.tsym.type.getTypeArguments(),
-                    clazztype.tsym);
-            clazztype = checkMethod(ct,
+            clazztype = checkMethod(site,
                     constructor,
                     localEnv,
                     tree.args,
@@ -1872,13 +1886,13 @@
             clazztype = syms.errType;
         }
 
-        if (clazztype.tag == FORALL && !pt.isErroneous()) {
+        if (clazztype.tag == FORALL && !pt().isErroneous()) {
             //if the resolved constructor's return type has some uninferred
             //type-variables, infer them using the expected type and declared
             //bounds (JLS 15.12.2.8).
             try {
                 clazztype = infer.instantiateExpr((ForAll) clazztype,
-                        pt.tag == NONE ? syms.objectType : pt,
+                        pt().tag == NONE ? syms.objectType : pt(),
                         Warner.noWarnings);
             } catch (Infer.InferenceException ex) {
                 //an error occurred while inferring uninstantiated type-variables
@@ -1893,42 +1907,6 @@
                 true);
     }
 
-    /** Creates a synthetic scope containing fake generic constructors.
-     *  Assuming that the original scope contains a constructor of the kind:
-     *  Foo(X x, Y y), where X,Y are class type-variables declared in Foo,
-     *  the synthetic scope is added a generic constructor of the kind:
-     *  <X,Y>Foo<X,Y>(X x, Y y). This is crucial in order to enable diamond
-     *  inference. The inferred return type of the synthetic constructor IS
-     *  the inferred type for the diamond operator.
-     */
-    private Pair<Scope, Scope> getSyntheticScopeMapping(Type ctype) {
-        if (ctype.tag != CLASS) {
-            return erroneousMapping;
-        }
-
-        Pair<Scope, Scope> mapping =
-                new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym));
-
-        //for each constructor in the original scope, create a synthetic constructor
-        //whose return type is the type of the class in which the constructor is
-        //declared, and insert it into the new scope.
-        for (Scope.Entry e = mapping.fst.lookup(names.init);
-                e.scope != null;
-                e = e.next()) {
-            Type synthRestype = new ClassType(ctype.getEnclosingType(),
-                        ctype.tsym.type.getTypeArguments(),
-                        ctype.tsym);
-            MethodSymbol synhConstr = new MethodSymbol(e.sym.flags(),
-                    names.init,
-                    types.createMethodTypeWithReturn(e.sym.type, synthRestype),
-                    e.sym.owner);
-            mapping.snd.enter(synhConstr);
-        }
-        return mapping;
-    }
-
-    private final Pair<Scope,Scope> erroneousMapping = new Pair<Scope,Scope>(null, null);
-
     /** Make an attributed null check tree.
      */
     public JCExpression makeNullCheck(JCExpression arg) {
@@ -1957,14 +1935,14 @@
         } else {
             // we are seeing an untyped aggregate { ... }
             // this is allowed only if the prototype is an array
-            if (pt.tag == ARRAY) {
-                elemtype = types.elemtype(pt);
+            if (pt().tag == ARRAY) {
+                elemtype = types.elemtype(pt());
             } else {
-                if (pt.tag != ERROR) {
+                if (pt().tag != ERROR) {
                     log.error(tree.pos(), "illegal.initializer.for.type",
-                              pt);
+                              pt());
                 }
-                elemtype = types.createErrorType(pt);
+                elemtype = types.createErrorType(pt());
             }
         }
         if (tree.elems != null) {
@@ -1973,7 +1951,7 @@
         }
         if (!types.isReifiable(elemtype))
             log.error(tree.pos(), "generic.array.creation");
-        result = check(tree, owntype, VAL, pkind, pt);
+        result = check(tree, owntype, VAL, resultInfo);
     }
 
     @Override
@@ -1987,23 +1965,23 @@
     }
 
     public void visitParens(JCParens tree) {
-        Type owntype = attribTree(tree.expr, env, pkind, pt);
-        result = check(tree, owntype, pkind, pkind, pt);
+        Type owntype = attribTree(tree.expr, env, resultInfo);
+        result = check(tree, owntype, pkind(), resultInfo);
         Symbol sym = TreeInfo.symbol(tree);
         if (sym != null && (sym.kind&(TYP|PCK)) != 0)
             log.error(tree.pos(), "illegal.start.of.type");
     }
 
     public void visitAssign(JCAssign tree) {
-        Type owntype = attribTree(tree.lhs, env.dup(tree), VAR, Type.noType);
+        Type owntype = attribTree(tree.lhs, env.dup(tree), varInfo);
         Type capturedType = capture(owntype);
         attribExpr(tree.rhs, env, owntype);
-        result = check(tree, capturedType, VAL, pkind, pt);
+        result = check(tree, capturedType, VAL, resultInfo);
     }
 
     public void visitAssignop(JCAssignOp tree) {
         // Attribute arguments.
-        Type owntype = attribTree(tree.lhs, env, VAR, Type.noType);
+        Type owntype = attribTree(tree.lhs, env, varInfo);
         Type operand = attribExpr(tree.rhs, env);
         // Find operator.
         Symbol operator = tree.operator = rs.resolveBinaryOperator(
@@ -2023,13 +2001,13 @@
                               operator.type.getReturnType(),
                               owntype);
         }
-        result = check(tree, owntype, VAL, pkind, pt);
+        result = check(tree, owntype, VAL, resultInfo);
     }
 
     public void visitUnary(JCUnary tree) {
         // Attribute arguments.
         Type argtype = (tree.getTag().isIncOrDecUnaryOp())
-            ? attribTree(tree.arg, env, VAR, Type.noType)
+            ? attribTree(tree.arg, env, varInfo)
             : chk.checkNonVoid(tree.arg.pos(), attribExpr(tree.arg, env));
 
         // Find operator.
@@ -2061,7 +2039,7 @@
                 }
             }
         }
-        result = check(tree, owntype, VAL, pkind, pt);
+        result = check(tree, owntype, VAL, resultInfo);
     }
 
     public void visitBinary(JCBinary tree) {
@@ -2114,7 +2092,7 @@
 
             chk.checkDivZero(tree.rhs.pos(), operator, right);
         }
-        result = check(tree, owntype, VAL, pkind, pt);
+        result = check(tree, owntype, VAL, resultInfo);
     }
 
     public void visitTypeCast(JCTypeCast tree) {
@@ -2127,7 +2105,7 @@
         Type owntype = chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
         if (exprtype.constValue() != null)
             owntype = cfolder.coerce(exprtype, owntype);
-        result = check(tree, capture(owntype), VAL, pkind, pt);
+        result = check(tree, capture(owntype), VAL, resultInfo);
     }
 
     public void visitTypeTest(JCInstanceOf tree) {
@@ -2137,7 +2115,7 @@
             tree.clazz.pos(), attribType(tree.clazz, env));
         chk.validate(tree.clazz, env, false);
         chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
-        result = check(tree, syms.booleanType, VAL, pkind, pt);
+        result = check(tree, syms.booleanType, VAL, resultInfo);
     }
 
     public void visitIndexed(JCArrayAccess tree) {
@@ -2148,8 +2126,8 @@
             owntype = types.elemtype(atype);
         else if (atype.tag != ERROR)
             log.error(tree.pos(), "array.req.but.found", atype);
-        if ((pkind & VAR) == 0) owntype = capture(owntype);
-        result = check(tree, owntype, VAR, pkind, pt);
+        if ((pkind() & VAR) == 0) owntype = capture(owntype);
+        result = check(tree, owntype, VAR, resultInfo);
     }
 
     public void visitIdent(JCIdent tree) {
@@ -2157,16 +2135,16 @@
         boolean varArgs = false;
 
         // Find symbol
-        if (pt.tag == METHOD || pt.tag == FORALL) {
+        if (pt().tag == METHOD || pt().tag == FORALL) {
             // If we are looking for a method, the prototype `pt' will be a
             // method type with the type of the call's arguments as parameters.
             env.info.varArgs = false;
-            sym = rs.resolveMethod(tree.pos(), env, tree.name, pt.getParameterTypes(), pt.getTypeArguments());
+            sym = rs.resolveMethod(tree.pos(), env, tree.name, pt().getParameterTypes(), pt().getTypeArguments());
             varArgs = env.info.varArgs;
         } else if (tree.sym != null && tree.sym.kind != VAR) {
             sym = tree.sym;
         } else {
-            sym = rs.resolveIdent(tree.pos(), env, tree.name, pkind);
+            sym = rs.resolveIdent(tree.pos(), env, tree.name, pkind());
         }
         tree.sym = sym;
 
@@ -2213,7 +2191,7 @@
 
             // If we are expecting a variable (as opposed to a value), check
             // that the variable is assignable in the current environment.
-            if (pkind == VAR)
+            if (pkind() == VAR)
                 checkAssignable(tree.pos(), v, null, env);
         }
 
@@ -2234,7 +2212,7 @@
             while (env1.outer != null && !rs.isAccessible(env, env1.enclClass.sym.type, sym))
                 env1 = env1.outer;
         }
-        result = checkId(tree, env1.enclClass.sym.type, sym, env, pkind, pt, varArgs);
+        result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo, varArgs);
     }
 
     public void visitSelect(JCFieldAccess tree) {
@@ -2245,14 +2223,14 @@
         {
             skind = TYP;
         } else {
-            if ((pkind & PCK) != 0) skind = skind | PCK;
-            if ((pkind & TYP) != 0) skind = skind | TYP | PCK;
-            if ((pkind & (VAL | MTH)) != 0) skind = skind | VAL | TYP;
+            if ((pkind() & PCK) != 0) skind = skind | PCK;
+            if ((pkind() & TYP) != 0) skind = skind | TYP | PCK;
+            if ((pkind() & (VAL | MTH)) != 0) skind = skind | VAL | TYP;
         }
 
         // Attribute the qualifier expression, and determine its symbol (if any).
-        Type site = attribTree(tree.selected, env, skind, Infer.anyPoly);
-        if ((pkind & (PCK | TYP)) == 0)
+        Type site = attribTree(tree.selected, env, new ResultInfo(skind, Infer.anyPoly));
+        if ((pkind() & (PCK | TYP)) == 0)
             site = capture(site); // Capture field access
 
         // don't allow T.class T[].class, etc
@@ -2287,10 +2265,10 @@
 
         // Determine the symbol represented by the selection.
         env.info.varArgs = false;
-        Symbol sym = selectSym(tree, sitesym, site, env, pt, pkind);
-        if (sym.exists() && !isType(sym) && (pkind & (PCK | TYP)) != 0) {
+        Symbol sym = selectSym(tree, sitesym, site, env, resultInfo);
+        if (sym.exists() && !isType(sym) && (pkind() & (PCK | TYP)) != 0) {
             site = capture(site);
-            sym = selectSym(tree, sitesym, site, env, pt, pkind);
+            sym = selectSym(tree, sitesym, site, env, resultInfo);
         }
         boolean varArgs = env.info.varArgs;
         tree.sym = sym;
@@ -2310,7 +2288,7 @@
 
             // If we are expecting a variable (as opposed to a value), check
             // that the variable is assignable in the current environment.
-            if (pkind == VAR)
+            if (pkind() == VAR)
                 checkAssignable(tree.pos(), v, tree.selected, env);
         }
 
@@ -2326,8 +2304,8 @@
 
         // Disallow selecting a type from an expression
         if (isType(sym) && (sitesym==null || (sitesym.kind&(TYP|PCK)) == 0)) {
-            tree.type = check(tree.selected, pt,
-                              sitesym == null ? VAL : sitesym.kind, TYP|PCK, pt);
+            tree.type = check(tree.selected, pt(),
+                              sitesym == null ? VAL : sitesym.kind, new ResultInfo(TYP|PCK, pt()));
         }
 
         if (isType(sitesym)) {
@@ -2367,7 +2345,7 @@
         }
 
         env.info.selectSuper = selectSuperPrev;
-        result = checkId(tree, site, sym, env, pkind, pt, varArgs);
+        result = checkId(tree, site, sym, env, resultInfo, varArgs);
         env.info.tvars = List.nil();
     }
     //where
@@ -2376,34 +2354,25 @@
          *  @param tree   The select tree.
          *  @param site   The type of the selected expression,
          *  @param env    The current environment.
-         *  @param pt     The current prototype.
-         *  @param pkind  The expected kind(s) of the Select expression.
+         *  @param resultInfo The current result.
          */
         private Symbol selectSym(JCFieldAccess tree,
-                                     Type site,
-                                     Env<AttrContext> env,
-                                     Type pt,
-                                     int pkind) {
-            return selectSym(tree, site.tsym, site, env, pt, pkind);
-        }
-        private Symbol selectSym(JCFieldAccess tree,
                                  Symbol location,
                                  Type site,
                                  Env<AttrContext> env,
-                                 Type pt,
-                                 int pkind) {
+                                 ResultInfo resultInfo) {
             DiagnosticPosition pos = tree.pos();
             Name name = tree.name;
             switch (site.tag) {
             case PACKAGE:
                 return rs.access(
-                    rs.findIdentInPackage(env, site.tsym, name, pkind),
+                    rs.findIdentInPackage(env, site.tsym, name, resultInfo.pkind),
                     pos, location, site, name, true);
             case ARRAY:
             case CLASS:
-                if (pt.tag == METHOD || pt.tag == FORALL) {
+                if (resultInfo.pt.tag == METHOD || resultInfo.pt.tag == FORALL) {
                     return rs.resolveQualifiedMethod(
-                        pos, env, location, site, name, pt.getParameterTypes(), pt.getTypeArguments());
+                        pos, env, location, site, name, resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments());
                 } else if (name == names._this || name == names._super) {
                     return rs.resolveSelf(pos, env, site.tsym, name);
                 } else if (name == names._class) {
@@ -2418,8 +2387,8 @@
                         STATIC | PUBLIC | FINAL, names._class, t, site.tsym);
                 } else {
                     // We are seeing a plain identifier as selector.
-                    Symbol sym = rs.findIdentInType(env, site, name, pkind);
-                    if ((pkind & ERRONEOUS) == 0)
+                    Symbol sym = rs.findIdentInType(env, site, name, resultInfo.pkind);
+                    if ((resultInfo.pkind & ERRONEOUS) == 0)
                         sym = rs.access(sym, pos, location, site, name, true);
                     return sym;
                 }
@@ -2433,7 +2402,7 @@
                 // other words, we are seeing this illegal program:
                 // class B<T> extends A<T.foo> {}
                 Symbol sym = (site.getUpperBound() != null)
-                    ? selectSym(tree, location, capture(site.getUpperBound()), env, pt, pkind)
+                    ? selectSym(tree, location, capture(site.getUpperBound()), env, resultInfo)
                     : null;
                 if (sym == null) {
                     log.error(pos, "type.var.cant.be.deref");
@@ -2487,17 +2456,15 @@
          *                    expression, otherwise the type of the current class.
          *  @param sym        The symbol representing the identifier.
          *  @param env        The current environment.
-         *  @param pkind      The set of expected kinds.
-         *  @param pt         The expected type.
+         *  @param resultInfo    The expected result
          */
         Type checkId(JCTree tree,
                      Type site,
                      Symbol sym,
                      Env<AttrContext> env,
-                     int pkind,
-                     Type pt,
+                     ResultInfo resultInfo,
                      boolean useVarargs) {
-            if (pt.isErroneous()) return types.createErrorType(site);
+            if (resultInfo.pt.isErroneous()) return types.createErrorType(site);
             Type owntype; // The computed type of this identifier occurrence.
             switch (sym.kind) {
             case TYP:
@@ -2542,7 +2509,7 @@
                 // which is being assigned to, issue an unchecked warning if
                 // its type changes under erasure.
                 if (allowGenerics &&
-                    pkind == VAR &&
+                    resultInfo.pkind == VAR &&
                     v.owner.kind == TYP &&
                     (v.flags() & STATIC) == 0 &&
                     (site.tag == CLASS || site.tag == TYPEVAR)) {
@@ -2577,14 +2544,14 @@
                 if (v.getConstValue() != null && isStaticReference(tree))
                     owntype = owntype.constType(v.getConstValue());
 
-                if (pkind == VAL) {
+                if (resultInfo.pkind == VAL) {
                     owntype = capture(owntype); // capture "names as expressions"
                 }
                 break;
             case MTH: {
                 JCMethodInvocation app = (JCMethodInvocation)env.tree;
                 owntype = checkMethod(site, sym, env, app.args,
-                                      pt.getParameterTypes(), pt.getTypeArguments(),
+                                      resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments(),
                                       env.info.varArgs);
                 break;
             }
@@ -2607,7 +2574,7 @@
 
             // Test (3): if symbol is a variable, check that its type and
             // kind are compatible with the prototype and protokind.
-            return check(tree, owntype, sym.kind, pkind, pt);
+            return check(tree, owntype, sym.kind, resultInfo);
         }
 
         /** Check that variable is initialized and evaluate the variable's
@@ -2720,7 +2687,7 @@
     Warner noteWarner = new Warner();
 
     /**
-     * Check that method arguments conform to its instantation.
+     * Check that method arguments conform to its instantiation.
      **/
     public Type checkMethod(Type site,
                             Symbol sym,
@@ -2757,112 +2724,44 @@
                                       true,
                                       useVarargs,
                                       noteWarner);
-        boolean warned = noteWarner.hasNonSilentLint(LintCategory.UNCHECKED);
+
+        boolean unchecked = noteWarner.hasNonSilentLint(LintCategory.UNCHECKED);
 
         // If this fails, something went wrong; we should not have
         // found the identifier in the first place.
         if (owntype == null) {
-            if (!pt.isErroneous())
+            if (!pt().isErroneous())
                 log.error(env.tree.pos(),
-                          "internal.error.cant.instantiate",
-                          sym, site,
-                          Type.toString(pt.getParameterTypes()));
+                           "internal.error.cant.instantiate",
+                           sym, site,
+                          Type.toString(pt().getParameterTypes()));
             owntype = types.createErrorType(site);
+            return types.createErrorType(site);
+        } else if (owntype.getReturnType().tag == FORALL && !unchecked) {
+            return owntype;
         } else {
-            // System.out.println("call   : " + env.tree);
-            // System.out.println("method : " + owntype);
-            // System.out.println("actuals: " + argtypes);
-            List<Type> formals = owntype.getParameterTypes();
-            Type last = useVarargs ? formals.last() : null;
-            if (sym.name==names.init &&
-                sym.owner == syms.enumSym)
-                formals = formals.tail.tail;
-            List<JCExpression> args = argtrees;
-            while (formals.head != last) {
-                JCTree arg = args.head;
-                Warner warn = chk.convertWarner(arg.pos(), arg.type, formals.head);
-                assertConvertible(arg, arg.type, formals.head, warn);
-                warned |= warn.hasNonSilentLint(LintCategory.UNCHECKED);
-                args = args.tail;
-                formals = formals.tail;
-            }
-            if (useVarargs) {
-                Type varArg = types.elemtype(last);
-                while (args.tail != null) {
-                    JCTree arg = args.head;
-                    Warner warn = chk.convertWarner(arg.pos(), arg.type, varArg);
-                    assertConvertible(arg, arg.type, varArg, warn);
-                    warned |= warn.hasNonSilentLint(LintCategory.UNCHECKED);
-                    args = args.tail;
-                }
-            } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) {
-                // non-varargs call to varargs method
-                Type varParam = owntype.getParameterTypes().last();
-                Type lastArg = argtypes.last();
-                if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) &&
-                    !types.isSameType(types.erasure(varParam), types.erasure(lastArg)))
-                    log.warning(argtrees.last().pos(), "inexact.non-varargs.call",
-                                types.elemtype(varParam),
-                                varParam);
-            }
-
-            if (warned && sym.type.tag == FORALL) {
-                chk.warnUnchecked(env.tree.pos(),
-                                  "unchecked.meth.invocation.applied",
-                                  kindName(sym),
-                                  sym.name,
-                                  rs.methodArguments(sym.type.getParameterTypes()),
-                                  rs.methodArguments(argtypes),
-                                  kindName(sym.location()),
-                                  sym.location());
-                owntype = new MethodType(owntype.getParameterTypes(),
-                                         types.erasure(owntype.getReturnType()),
-                                         types.erasure(owntype.getThrownTypes()),
-                                         syms.methodClass);
-            }
-            if (useVarargs) {
-                JCTree tree = env.tree;
-                Type argtype = owntype.getParameterTypes().last();
-                if (owntype.getReturnType().tag != FORALL || warned) {
-                    chk.checkVararg(env.tree.pos(), owntype.getParameterTypes(), sym);
-                }
-                Type elemtype = types.elemtype(argtype);
-                switch (tree.getTag()) {
-                case APPLY:
-                    ((JCMethodInvocation) tree).varargsElement = elemtype;
-                    break;
-                case NEWCLASS:
-                    ((JCNewClass) tree).varargsElement = elemtype;
-                    break;
-                default:
-                    throw new AssertionError(""+tree);
-                }
-            }
+            return chk.checkMethod(owntype, sym, env, argtrees, argtypes, useVarargs, unchecked);
         }
-        return owntype;
     }
 
-    private void assertConvertible(JCTree tree, Type actual, Type formal, Warner warn) {
-        if (types.isConvertible(actual, formal, warn))
-            return;
-
-        if (formal.isCompound()
-            && types.isSubtype(actual, types.supertype(formal))
-            && types.isSubtypeUnchecked(actual, types.interfaces(formal), warn))
-            return;
-
-        if (false) {
-            // TODO: make assertConvertible work
-            chk.typeError(tree.pos(), diags.fragment("incompatible.types"), actual, formal);
-            throw new AssertionError("Tree: " + tree
-                                     + " actual:" + actual
-                                     + " formal: " + formal);
-        }
+    /**
+     * Check that constructor arguments conform to its instantiation.
+     **/
+    public Type checkConstructor(Type site,
+                            Symbol sym,
+                            Env<AttrContext> env,
+                            final List<JCExpression> argtrees,
+                            List<Type> argtypes,
+                            List<Type> typeargtypes,
+                            boolean useVarargs) {
+        Type owntype = checkMethod(site, sym, env, argtrees, argtypes, typeargtypes, useVarargs);
+        chk.checkType(env.tree.pos(), owntype.getReturnType(), syms.voidType);
+        return owntype;
     }
 
     public void visitLiteral(JCLiteral tree) {
         result = check(
-            tree, litType(tree.typetag).constType(tree.value), VAL, pkind, pt);
+            tree, litType(tree.typetag).constType(tree.value), VAL, resultInfo);
     }
     //where
     /** Return the type of a literal with given type tag.
@@ -2872,13 +2771,13 @@
     }
 
     public void visitTypeIdent(JCPrimitiveTypeTree tree) {
-        result = check(tree, syms.typeOfTag[tree.typetag], TYP, pkind, pt);
+        result = check(tree, syms.typeOfTag[tree.typetag], TYP, resultInfo);
     }
 
     public void visitTypeArray(JCArrayTypeTree tree) {
         Type etype = attribType(tree.elemtype, env);
         Type type = new ArrayType(etype, syms.arrayClass);
-        result = check(tree, type, TYP, pkind, pt);
+        result = check(tree, type, TYP, resultInfo);
     }
 
     /** Visitor method for parameterized types.
@@ -2936,7 +2835,7 @@
                 owntype = types.createErrorType(tree.type);
             }
         }
-        result = check(tree, owntype, TYP, pkind, pt);
+        result = check(tree, owntype, TYP, resultInfo);
     }
 
     public void visitTypeUnion(JCTypeUnion tree) {
@@ -2973,7 +2872,7 @@
                 all_multicatchTypes.append(ctype);
             }
         }
-        Type t = check(tree, types.lub(multicatchTypes.toList()), TYP, pkind, pt);
+        Type t = check(tree, types.lub(multicatchTypes.toList()), TYP, resultInfo);
         if (t.tag == CLASS) {
             List<Type> alternatives =
                 ((all_multicatchTypes == null) ? multicatchTypes : all_multicatchTypes).toList();
@@ -3059,18 +2958,18 @@
         result = check(tree, new WildcardType(chk.checkRefType(tree.pos(), type),
                                               tree.kind.kind,
                                               syms.boundClass),
-                       TYP, pkind, pt);
+                       TYP, resultInfo);
     }
 
     public void visitAnnotation(JCAnnotation tree) {
-        log.error(tree.pos(), "annotation.not.valid.for.type", pt);
+        log.error(tree.pos(), "annotation.not.valid.for.type", pt());
         result = tree.type = syms.errType;
     }
 
     public void visitErroneous(JCErroneous tree) {
         if (tree.errs != null)
             for (JCTree err : tree.errs)
-                attribTree(err, env, ERR, pt);
+                attribTree(err, env, new ResultInfo(ERR, pt()));
         result = tree.type = syms.errType;
     }
 
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 d7934f1..1753c19 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
@@ -63,6 +63,7 @@
 
     private final Names names;
     private final Log log;
+    private final Resolve rs;
     private final Symtab syms;
     private final Enter enter;
     private final Infer infer;
@@ -95,6 +96,7 @@
 
         names = Names.instance(context);
         log = Log.instance(context);
+        rs = Resolve.instance(context);
         syms = Symtab.instance(context);
         enter = Enter.instance(context);
         infer = Infer.instance(context);
@@ -106,6 +108,7 @@
 
         Source source = Source.instance(context);
         allowGenerics = source.allowGenerics();
+        allowVarargs = source.allowVarargs();
         allowAnnotations = source.allowAnnotations();
         allowCovariantReturns = source.allowCovariantReturns();
         allowSimplifiedVarargs = source.allowSimplifiedVarargs();
@@ -137,6 +140,10 @@
      */
     boolean allowGenerics;
 
+    /** Switch: varargs enabled?
+     */
+    boolean allowVarargs;
+
     /** Switch: annotations enabled?
      */
     boolean allowAnnotations;
@@ -525,16 +532,16 @@
      *  @param a             The type that should be bounded by bs.
      *  @param bs            The bound.
      */
-    private boolean checkExtends(Type a, TypeVar bs) {
+    private boolean checkExtends(Type a, Type bound) {
          if (a.isUnbound()) {
              return true;
          } else if (a.tag != WILDCARD) {
              a = types.upperBound(a);
-             return types.isSubtype(a, bs.bound);
+             return types.isSubtype(a, bound);
          } else if (a.isExtendsBound()) {
-             return types.isCastable(bs.getUpperBound(), types.upperBound(a), Warner.noWarnings);
+             return types.isCastable(bound, types.upperBound(a), Warner.noWarnings);
          } else if (a.isSuperBound()) {
-             return !types.notSoftSubtype(types.lowerBound(a), bs.getUpperBound());
+             return !types.notSoftSubtype(types.lowerBound(a), bound);
          }
          return true;
      }
@@ -743,22 +750,103 @@
                     (s.flags() & (STATIC | FINAL)) != 0);
         }
 
-    /**
-     * Check that vararg method call is sound
-     * @param pos Position to be used for error reporting.
-     * @param argtypes Actual arguments supplied to vararg method.
-     */
-    void checkVararg(DiagnosticPosition pos, List<Type> argtypes, Symbol msym) {
-        Type argtype = argtypes.last();
-        if (!types.isReifiable(argtype) &&
-                (!allowSimplifiedVarargs ||
-                msym.attribute(syms.trustMeType.tsym) == null ||
-                !isTrustMeAllowedOnMethod(msym))) {
-            warnUnchecked(pos,
-                              "unchecked.generic.array.creation",
-                              argtype);
+    Type checkMethod(Type owntype,
+                            Symbol sym,
+                            Env<AttrContext> env,
+                            final List<JCExpression> argtrees,
+                            List<Type> argtypes,
+                            boolean useVarargs,
+                            boolean unchecked) {
+        // System.out.println("call   : " + env.tree);
+        // System.out.println("method : " + owntype);
+        // System.out.println("actuals: " + argtypes);
+        List<Type> formals = owntype.getParameterTypes();
+        Type last = useVarargs ? formals.last() : null;
+        if (sym.name==names.init &&
+                sym.owner == syms.enumSym)
+                formals = formals.tail.tail;
+        List<JCExpression> args = argtrees;
+        while (formals.head != last) {
+            JCTree arg = args.head;
+            Warner warn = convertWarner(arg.pos(), arg.type, formals.head);
+            assertConvertible(arg, arg.type, formals.head, warn);
+            args = args.tail;
+            formals = formals.tail;
         }
+        if (useVarargs) {
+            Type varArg = types.elemtype(last);
+            while (args.tail != null) {
+                JCTree arg = args.head;
+                Warner warn = convertWarner(arg.pos(), arg.type, varArg);
+                assertConvertible(arg, arg.type, varArg, warn);
+                args = args.tail;
+            }
+        } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) {
+            // non-varargs call to varargs method
+            Type varParam = owntype.getParameterTypes().last();
+            Type lastArg = argtypes.last();
+            if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) &&
+                    !types.isSameType(types.erasure(varParam), types.erasure(lastArg)))
+                log.warning(argtrees.last().pos(), "inexact.non-varargs.call",
+                        types.elemtype(varParam), varParam);
+        }
+        if (unchecked) {
+            warnUnchecked(env.tree.pos(),
+                    "unchecked.meth.invocation.applied",
+                    kindName(sym),
+                    sym.name,
+                    rs.methodArguments(sym.type.getParameterTypes()),
+                    rs.methodArguments(argtypes),
+                    kindName(sym.location()),
+                    sym.location());
+           owntype = new MethodType(owntype.getParameterTypes(),
+                   types.erasure(owntype.getReturnType()),
+                   types.erasure(owntype.getThrownTypes()),
+                   syms.methodClass);
+        }
+        if (useVarargs) {
+            JCTree tree = env.tree;
+            Type argtype = owntype.getParameterTypes().last();
+            if (!types.isReifiable(argtype) &&
+                    (!allowSimplifiedVarargs ||
+                    sym.attribute(syms.trustMeType.tsym) == null ||
+                    !isTrustMeAllowedOnMethod(sym))) {
+                warnUnchecked(env.tree.pos(),
+                                  "unchecked.generic.array.creation",
+                                  argtype);
+            }
+            Type elemtype = types.elemtype(argtype);
+            switch (tree.getTag()) {
+                case APPLY:
+                    ((JCMethodInvocation) tree).varargsElement = elemtype;
+                    break;
+                case NEWCLASS:
+                    ((JCNewClass) tree).varargsElement = elemtype;
+                    break;
+                default:
+                    throw new AssertionError(""+tree);
+            }
+         }
+         return owntype;
     }
+    //where
+        private void assertConvertible(JCTree tree, Type actual, Type formal, Warner warn) {
+            if (types.isConvertible(actual, formal, warn))
+                return;
+
+            if (formal.isCompound()
+                && types.isSubtype(actual, types.supertype(formal))
+                && types.isSubtypeUnchecked(actual, types.interfaces(formal), warn))
+                return;
+
+            if (false) {
+                // TODO: make assertConvertible work
+                typeError(tree.pos(), diags.fragment("incompatible.types"), actual, formal);
+                throw new AssertionError("Tree: " + tree
+                                         + " actual:" + actual
+                                         + " formal: " + formal);
+            }
+        }
 
     /**
      * Check that type 't' is a valid instantiation of a generic class
@@ -776,18 +864,16 @@
             List<Type> actuals = type.allparams();
             List<Type> args = type.getTypeArguments();
             List<Type> forms = type.tsym.type.getTypeArguments();
-            ListBuffer<Type> tvars_buf = new ListBuffer<Type>();
+            ListBuffer<Type> bounds_buf = new ListBuffer<Type>();
 
             // For matching pairs of actual argument types `a' and
             // formal type parameters with declared bound `b' ...
             while (args.nonEmpty() && forms.nonEmpty()) {
                 // exact type arguments needs to know their
                 // bounds (for upper and lower bound
-                // calculations).  So we create new TypeVars with
-                // bounds substed with actuals.
-                tvars_buf.append(types.substBound(((TypeVar)forms.head),
-                                                  formals,
-                                                  actuals));
+                // calculations).  So we create new bounds where
+                // type-parameters are replaced with actuals argument types.
+                bounds_buf.append(types.subst(forms.head.getUpperBound(), formals, actuals));
                 args = args.tail;
                 forms = forms.tail;
             }
@@ -804,32 +890,30 @@
             }
 
             args = type.getTypeArguments();
-            List<Type> tvars = tvars_buf.toList();
+            List<Type> bounds = bounds_buf.toList();
 
-            while (args.nonEmpty() && tvars.nonEmpty()) {
-                Type actual = types.subst(args.head,
-                    type.tsym.type.getTypeArguments(),
-                    tvars_buf.toList());
+            while (args.nonEmpty() && bounds.nonEmpty()) {
+                Type actual = args.head;
                 if (!isTypeArgErroneous(actual) &&
-                        !tvars.head.getUpperBound().isErroneous() &&
-                        !checkExtends(actual, (TypeVar)tvars.head)) {
+                        !bounds.head.isErroneous() &&
+                        !checkExtends(actual, bounds.head)) {
                     return args.head;
                 }
                 args = args.tail;
-                tvars = tvars.tail;
+                bounds = bounds.tail;
             }
 
             args = type.getTypeArguments();
-            tvars = tvars_buf.toList();
+            bounds = bounds_buf.toList();
 
             for (Type arg : types.capture(type).getTypeArguments()) {
                 if (arg.tag == TYPEVAR &&
                         arg.getUpperBound().isErroneous() &&
-                        !tvars.head.getUpperBound().isErroneous() &&
+                        !bounds.head.isErroneous() &&
                         !isTypeArgErroneous(args.head)) {
                     return args.head;
                 }
-                tvars = tvars.tail;
+                bounds = bounds.tail;
                 args = args.tail;
             }
 
@@ -2492,7 +2576,7 @@
                     if (enableSunApiLintControl)
                       warnSunApi(pos, "sun.proprietary", s);
                     else
-                      log.strictWarning(pos, "sun.proprietary", s);
+                      log.mandatoryWarning(pos, "sun.proprietary", s);
                 }
             });
         }
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 23e8748..941d2dd 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
@@ -385,7 +385,6 @@
                                   final Warner warn) throws InferenceException {
         //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG
         List<Type> undetvars = Type.map(tvars, fromTypeVarFun);
-        //final List<Type> capturedArgs = types.capture(argtypes);
 
         final List<Type> capturedArgs =
                 rs.checkRawArgumentsAcceptable(env, undetvars, argtypes, mt.getParameterTypes(),
@@ -445,16 +444,20 @@
                     return List.nil();
                 }
                 @Override
-                void check(List<Type> inferred, Types types) throws NoInstanceException {
+                void instantiateReturnType(Type restype, List<Type> inferred, Types types) throws NoInstanceException {
+                    Type owntype = new MethodType(types.subst(getParameterTypes(), tvars, inferred),
+                                       restype,
+                                       types.subst(getThrownTypes(), tvars, inferred),
+                                       qtype.tsym);
                     // check that actuals conform to inferred formals
-                    checkArgumentsAcceptable(env, capturedArgs, getParameterTypes(), allowBoxing, useVarargs, warn);
+                    warn.clear();
+                    checkArgumentsAcceptable(env, capturedArgs, owntype.getParameterTypes(), allowBoxing, useVarargs, warn);
                     // check that inferred bounds conform to their bounds
                     checkWithinBounds(all_tvars,
                            types.subst(inferredTypes, tvars, inferred), warn);
-                    if (useVarargs) {
-                        chk.checkVararg(env.tree.pos(), getParameterTypes(), msym);
-                    }
-            }};
+                    qtype = chk.checkMethod(owntype, msym, env, TreeInfo.args(env.tree), capturedArgs, useVarargs, warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED));
+                }
+            };
         }
         else {
             // check that actuals conform to inferred formals
@@ -520,16 +523,7 @@
                 return qtype.map(f);
             }
 
-            void instantiateReturnType(Type restype, List<Type> inferred, Types types) throws NoInstanceException {
-                //update method type with newly inferred type-arguments
-                qtype = new MethodType(types.subst(getParameterTypes(), tvars, inferred),
-                                       restype,
-                                       types.subst(UninferredMethodType.this.getThrownTypes(), tvars, inferred),
-                                       UninferredMethodType.this.qtype.tsym);
-                check(inferred, types);
-            }
-
-            abstract void check(List<Type> inferred, Types types) throws NoInstanceException;
+            abstract void instantiateReturnType(Type restype, List<Type> inferred, Types types);
 
             abstract List<Type> getConstraints(TypeVar tv, ConstraintKind ck);
 
@@ -544,7 +538,7 @@
                     if (rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) {
                         log.note(pos, "deferred.method.inst", msym, UninferredMethodType.this.qtype, newRestype);
                     }
-                    return newRestype;
+                    return UninferredMethodType.this.qtype.getReturnType();
                 }
                 @Override
                 public List<Type> getConstraints(TypeVar tv, ConstraintKind ck) {
diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
index ad1c534..06eca2d 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
@@ -529,24 +529,17 @@
 
     // process the non-static imports and the static imports of types.
     public void visitImport(JCImport tree) {
-        JCTree imp = tree.qualid;
+        JCFieldAccess imp = (JCFieldAccess)tree.qualid;
         Name name = TreeInfo.name(imp);
-        TypeSymbol p;
 
         // Create a local environment pointing to this tree to disable
         // effects of other imports in Resolve.findGlobalType
         Env<AttrContext> localEnv = env.dup(tree);
 
-        // Attribute qualifying package or class.
-        JCFieldAccess s = (JCFieldAccess) imp;
-        p = attr.
-            attribTree(s.selected,
-                       localEnv,
-                       tree.staticImport ? TYP : (TYP | PCK),
-                       Type.noType).tsym;
+        TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym;
         if (name == names.asterisk) {
             // Import on demand.
-            chk.checkCanonical(s.selected);
+            chk.checkCanonical(imp.selected);
             if (tree.staticImport)
                 importStaticAll(tree.pos, p, env);
             else
@@ -555,7 +548,7 @@
             // Named type import.
             if (tree.staticImport) {
                 importNamedStatic(tree.pos(), p, name, localEnv);
-                chk.checkCanonical(s.selected);
+                chk.checkCanonical(imp.selected);
             } else {
                 TypeSymbol c = attribImportType(imp, localEnv).tsym;
                 chk.checkCanonical(imp);
diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
index 1a38317..be41f9e 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
@@ -29,6 +29,7 @@
 import com.sun.tools.javac.code.*;
 import com.sun.tools.javac.code.Type.*;
 import com.sun.tools.javac.code.Symbol.*;
+import com.sun.tools.javac.comp.Resolve.MethodResolutionContext.Candidate;
 import com.sun.tools.javac.jvm.*;
 import com.sun.tools.javac.tree.*;
 import com.sun.tools.javac.tree.JCTree.*;
@@ -39,10 +40,9 @@
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.EnumMap;
 import java.util.EnumSet;
-import java.util.HashMap;
 import java.util.HashSet;
-import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 
@@ -84,6 +84,58 @@
 
     Scope polymorphicSignatureScope;
 
+    protected Resolve(Context context) {
+        context.put(resolveKey, this);
+        syms = Symtab.instance(context);
+
+        varNotFound = new
+            SymbolNotFoundError(ABSENT_VAR);
+        wrongMethod = new
+            InapplicableSymbolError();
+        wrongMethods = new
+            InapplicableSymbolsError();
+        methodNotFound = new
+            SymbolNotFoundError(ABSENT_MTH);
+        typeNotFound = new
+            SymbolNotFoundError(ABSENT_TYP);
+
+        names = Names.instance(context);
+        log = Log.instance(context);
+        chk = Check.instance(context);
+        infer = Infer.instance(context);
+        reader = ClassReader.instance(context);
+        treeinfo = TreeInfo.instance(context);
+        types = Types.instance(context);
+        diags = JCDiagnostic.Factory.instance(context);
+        Source source = Source.instance(context);
+        boxingEnabled = source.allowBoxing();
+        varargsEnabled = source.allowVarargs();
+        Options options = Options.instance(context);
+        debugResolve = options.isSet("debugresolve");
+        verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
+        Target target = Target.instance(context);
+        allowMethodHandles = target.hasMethodHandles();
+        polymorphicSignatureScope = new Scope(syms.noSymbol);
+
+        inapplicableMethodException = new InapplicableMethodException(diags);
+    }
+
+    /** error symbols, which are returned when resolution fails
+     */
+    private final SymbolNotFoundError varNotFound;
+    private final InapplicableSymbolError wrongMethod;
+    private final InapplicableSymbolsError wrongMethods;
+    private final SymbolNotFoundError methodNotFound;
+    private final SymbolNotFoundError typeNotFound;
+
+    public static Resolve instance(Context context) {
+        Resolve instance = context.get(resolveKey);
+        if (instance == null)
+            instance = new Resolve(context);
+        return instance;
+    }
+
+    // <editor-fold defaultstate="collapsed" desc="Verbose resolution diagnostics support">
     enum VerboseResolutionMode {
         SUCCESS("success"),
         FAILURE("failure"),
@@ -119,56 +171,74 @@
         }
     }
 
-    public static Resolve instance(Context context) {
-        Resolve instance = context.get(resolveKey);
-        if (instance == null)
-            instance = new Resolve(context);
-        return instance;
+    void reportVerboseResolutionDiagnostic(DiagnosticPosition dpos, Name name, Type site,
+            List<Type> argtypes, List<Type> typeargtypes, Symbol bestSoFar) {
+        boolean success = bestSoFar.kind < ERRONEOUS;
+
+        if (success && !verboseResolutionMode.contains(VerboseResolutionMode.SUCCESS)) {
+            return;
+        } else if (!success && !verboseResolutionMode.contains(VerboseResolutionMode.FAILURE)) {
+            return;
+        }
+
+        if (bestSoFar.name == names.init &&
+                bestSoFar.owner == syms.objectType.tsym &&
+                !verboseResolutionMode.contains(VerboseResolutionMode.OBJECT_INIT)) {
+            return; //skip diags for Object constructor resolution
+        } else if (site == syms.predefClass.type &&
+                !verboseResolutionMode.contains(VerboseResolutionMode.PREDEF)) {
+            return; //skip spurious diags for predef symbols (i.e. operators)
+        } else if (currentResolutionContext.internalResolution &&
+                !verboseResolutionMode.contains(VerboseResolutionMode.INTERNAL)) {
+            return;
+        }
+
+        int pos = 0;
+        int mostSpecificPos = -1;
+        ListBuffer<JCDiagnostic> subDiags = ListBuffer.lb();
+        for (Candidate c : currentResolutionContext.candidates) {
+            if (currentResolutionContext.step != c.step ||
+                    (c.isApplicable() && !verboseResolutionMode.contains(VerboseResolutionMode.APPLICABLE)) ||
+                    (!c.isApplicable() && !verboseResolutionMode.contains(VerboseResolutionMode.INAPPLICABLE))) {
+                continue;
+            } else {
+                subDiags.append(c.isApplicable() ?
+                        getVerboseApplicableCandidateDiag(pos, c.sym, c.mtype) :
+                        getVerboseInapplicableCandidateDiag(pos, c.sym, c.details));
+                if (c.sym == bestSoFar)
+                    mostSpecificPos = pos;
+                pos++;
+            }
+        }
+        String key = success ? "verbose.resolve.multi" : "verbose.resolve.multi.1";
+        JCDiagnostic main = diags.note(log.currentSource(), dpos, key, name,
+                site.tsym, mostSpecificPos, currentResolutionContext.step,
+                methodArguments(argtypes), methodArguments(typeargtypes));
+        JCDiagnostic d = new JCDiagnostic.MultilineDiagnostic(main, subDiags.toList());
+        log.report(d);
     }
 
-    protected Resolve(Context context) {
-        context.put(resolveKey, this);
-        syms = Symtab.instance(context);
+    JCDiagnostic getVerboseApplicableCandidateDiag(int pos, Symbol sym, Type inst) {
+        JCDiagnostic subDiag = null;
+        if (inst.getReturnType().tag == FORALL) {
+            Type diagType = types.createMethodTypeWithReturn(inst.asMethodType(),
+                                                            ((ForAll)inst.getReturnType()).qtype);
+            subDiag = diags.fragment("partial.inst.sig", diagType);
+        } else if (sym.type.tag == FORALL) {
+            subDiag = diags.fragment("full.inst.sig", inst.asMethodType());
+        }
 
-        varNotFound = new
-            SymbolNotFoundError(ABSENT_VAR);
-        wrongMethod = new
-            InapplicableSymbolError(syms.errSymbol);
-        wrongMethods = new
-            InapplicableSymbolsError(syms.errSymbol);
-        methodNotFound = new
-            SymbolNotFoundError(ABSENT_MTH);
-        typeNotFound = new
-            SymbolNotFoundError(ABSENT_TYP);
+        String key = subDiag == null ?
+                "applicable.method.found" :
+                "applicable.method.found.1";
 
-        names = Names.instance(context);
-        log = Log.instance(context);
-        chk = Check.instance(context);
-        infer = Infer.instance(context);
-        reader = ClassReader.instance(context);
-        treeinfo = TreeInfo.instance(context);
-        types = Types.instance(context);
-        diags = JCDiagnostic.Factory.instance(context);
-        Source source = Source.instance(context);
-        boxingEnabled = source.allowBoxing();
-        varargsEnabled = source.allowVarargs();
-        Options options = Options.instance(context);
-        debugResolve = options.isSet("debugresolve");
-        verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
-        Target target = Target.instance(context);
-        allowMethodHandles = target.hasMethodHandles();
-        polymorphicSignatureScope = new Scope(syms.noSymbol);
-
-        inapplicableMethodException = new InapplicableMethodException(diags);
+        return diags.fragment(key, pos, sym, subDiag);
     }
 
-    /** error symbols, which are returned when resolution fails
-     */
-    final SymbolNotFoundError varNotFound;
-    final InapplicableSymbolError wrongMethod;
-    final InapplicableSymbolsError wrongMethods;
-    final SymbolNotFoundError methodNotFound;
-    final SymbolNotFoundError typeNotFound;
+    JCDiagnostic getVerboseInapplicableCandidateDiag(int pos, Symbol sym, JCDiagnostic subDiag) {
+        return diags.fragment("not.applicable.method.found", pos, sym, subDiag);
+    }
+    // </editor-fold>
 
 /* ************************************************************************
  * Identifier resolution
@@ -804,17 +874,18 @@
         try {
             Type mt = rawInstantiate(env, site, sym, argtypes, typeargtypes,
                                allowBoxing, useVarargs, Warner.noWarnings);
-            if (!operator) addVerboseApplicableCandidateDiag(sym ,mt);
+            if (!operator)
+                currentResolutionContext.addApplicableCandidate(sym, mt);
         } catch (InapplicableMethodException ex) {
-            if (!operator) addVerboseInapplicableCandidateDiag(sym, ex.getDiagnostic());
+            if (!operator)
+                currentResolutionContext.addInapplicableCandidate(sym, ex.getDiagnostic());
             switch (bestSoFar.kind) {
             case ABSENT_MTH:
-                return wrongMethod.setWrongSym(sym, ex.getDiagnostic());
+                return wrongMethod;
             case WRONG_MTH:
                 if (operator) return bestSoFar;
-                wrongMethods.addCandidate(currentStep, wrongMethod.sym, wrongMethod.explanation);
             case WRONG_MTHS:
-                return wrongMethods.addCandidate(currentStep, sym, ex.getDiagnostic());
+                return wrongMethods;
             default:
                 return bestSoFar;
             }
@@ -823,40 +894,12 @@
             return (bestSoFar.kind == ABSENT_MTH)
                 ? new AccessError(env, site, sym)
                 : bestSoFar;
-            }
+        }
         return (bestSoFar.kind > AMBIGUOUS)
             ? sym
             : mostSpecific(sym, bestSoFar, env, site,
                            allowBoxing && operator, useVarargs);
     }
-    //where
-        void addVerboseApplicableCandidateDiag(Symbol sym, Type inst) {
-            if (!verboseResolutionMode.contains(VerboseResolutionMode.APPLICABLE))
-                return;
-
-            JCDiagnostic subDiag = null;
-            if (inst.getReturnType().tag == FORALL) {
-                Type diagType = types.createMethodTypeWithReturn(inst.asMethodType(),
-                                                                ((ForAll)inst.getReturnType()).qtype);
-                subDiag = diags.fragment("partial.inst.sig", diagType);
-            } else if (sym.type.tag == FORALL) {
-                subDiag = diags.fragment("full.inst.sig", inst.asMethodType());
-            }
-
-            String key = subDiag == null ?
-                    "applicable.method.found" :
-                    "applicable.method.found.1";
-
-            verboseResolutionCandidateDiags.put(sym,
-                    diags.fragment(key, verboseResolutionCandidateDiags.size(), sym, subDiag));
-        }
-
-        void addVerboseInapplicableCandidateDiag(Symbol sym, JCDiagnostic subDiag) {
-            if (!verboseResolutionMode.contains(VerboseResolutionMode.INAPPLICABLE))
-                return;
-            verboseResolutionCandidateDiags.put(sym,
-                    diags.fragment("not.applicable.method.found", verboseResolutionCandidateDiags.size(), sym, subDiag));
-        }
 
     /* Return the most specific of the two methods for a call,
      *  given that both are accessible and applicable.
@@ -1054,7 +1097,6 @@
                       boolean allowBoxing,
                       boolean useVarargs,
                       boolean operator) {
-        verboseResolutionCandidateDiags.clear();
         Symbol bestSoFar = methodNotFound;
         bestSoFar = findMethod(env,
                           site,
@@ -1127,37 +1169,6 @@
         }
         return bestSoFar;
     }
-    //where
-        void reportVerboseResolutionDiagnostic(DiagnosticPosition dpos, Name name, Type site, List<Type> argtypes, List<Type> typeargtypes, Symbol bestSoFar) {
-            boolean success = bestSoFar.kind < ERRONEOUS;
-
-            if (success && !verboseResolutionMode.contains(VerboseResolutionMode.SUCCESS)) {
-                return;
-            } else if (!success && !verboseResolutionMode.contains(VerboseResolutionMode.FAILURE)) {
-                return;
-            }
-
-            if (bestSoFar.name == names.init &&
-                    bestSoFar.owner == syms.objectType.tsym &&
-                    !verboseResolutionMode.contains(VerboseResolutionMode.OBJECT_INIT)) {
-                return; //skip diags for Object constructor resolution
-            } else if (site == syms.predefClass.type && !verboseResolutionMode.contains(VerboseResolutionMode.PREDEF)) {
-                return; //skip spurious diags for predef symbols (i.e. operators)
-            } else if (internalResolution && !verboseResolutionMode.contains(VerboseResolutionMode.INTERNAL)) {
-                return;
-            }
-
-            int pos = 0;
-            for (Symbol s : verboseResolutionCandidateDiags.keySet()) {
-                if (s == bestSoFar) break;
-                pos++;
-            }
-            String key = success ? "verbose.resolve.multi" : "verbose.resolve.multi.1";
-            JCDiagnostic main = diags.note(log.currentSource(), dpos, key, name, site.tsym, pos, currentStep,
-                    methodArguments(argtypes), methodArguments(typeargtypes));
-            JCDiagnostic d = new JCDiagnostic.MultilineDiagnostic(main, List.from(verboseResolutionCandidateDiags.values().toArray(new JCDiagnostic[verboseResolutionCandidateDiags.size()])));
-            log.report(d);
-        }
 
     /** Find unqualified method matching given name, type and value arguments.
      *  @param env       The current environment.
@@ -1591,32 +1602,33 @@
                          Name name,
                          List<Type> argtypes,
                          List<Type> typeargtypes) {
-        Symbol sym = startResolution();
-        List<MethodResolutionPhase> steps = methodResolutionSteps;
-        while (steps.nonEmpty() &&
-               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
-               sym.kind >= ERRONEOUS) {
-            currentStep = steps.head;
-            sym = findFun(env, name, argtypes, typeargtypes,
-                    steps.head.isBoxingRequired,
-                    env.info.varArgs = steps.head.isVarargsRequired);
-            methodResolutionCache.put(steps.head, sym);
-            steps = steps.tail;
+        MethodResolutionContext prevResolutionContext = currentResolutionContext;
+        try {
+            currentResolutionContext = new MethodResolutionContext();
+            Symbol sym = methodNotFound;
+            List<MethodResolutionPhase> steps = methodResolutionSteps;
+            while (steps.nonEmpty() &&
+                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
+                   sym.kind >= ERRONEOUS) {
+                currentResolutionContext.step = steps.head;
+                sym = findFun(env, name, argtypes, typeargtypes,
+                        steps.head.isBoxingRequired,
+                        env.info.varArgs = steps.head.isVarargsRequired);
+                currentResolutionContext.resolutionCache.put(steps.head, sym);
+                steps = steps.tail;
+            }
+            if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
+                MethodResolutionPhase errPhase =
+                        currentResolutionContext.firstErroneousResolutionPhase();
+                sym = access(currentResolutionContext.resolutionCache.get(errPhase),
+                        pos, env.enclClass.sym.type, name, false, argtypes, typeargtypes);
+                env.info.varArgs = errPhase.isVarargsRequired;
+            }
+            return sym;
         }
-        if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
-            MethodResolutionPhase errPhase =
-                    firstErroneousResolutionPhase();
-            sym = access(methodResolutionCache.get(errPhase),
-                    pos, env.enclClass.sym.type, name, false, argtypes, typeargtypes);
-            env.info.varArgs = errPhase.isVarargsRequired;
+        finally {
+            currentResolutionContext = prevResolutionContext;
         }
-        return sym;
-    }
-
-    private Symbol startResolution() {
-        wrongMethod.clear();
-        wrongMethods.clear();
-        return methodNotFound;
     }
 
     /** Resolve a qualified method identifier
@@ -1636,40 +1648,53 @@
     Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
                                   Symbol location, Type site, Name name, List<Type> argtypes,
                                   List<Type> typeargtypes) {
-        Symbol sym = startResolution();
-        List<MethodResolutionPhase> steps = methodResolutionSteps;
-        while (steps.nonEmpty() &&
-               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
-               sym.kind >= ERRONEOUS) {
-            currentStep = steps.head;
-            sym = findMethod(env, site, name, argtypes, typeargtypes,
-                    steps.head.isBoxingRequired(),
-                    env.info.varArgs = steps.head.isVarargsRequired(), false);
-            methodResolutionCache.put(steps.head, sym);
-            steps = steps.tail;
-        }
-        if (sym.kind >= AMBIGUOUS) {
-            if (site.tsym.isPolymorphicSignatureGeneric()) {
-                //polymorphic receiver - synthesize new method symbol
+        return resolveQualifiedMethod(new MethodResolutionContext(), pos, env, location, site, name, argtypes, typeargtypes);
+    }
+    private Symbol resolveQualifiedMethod(MethodResolutionContext resolveContext,
+                                  DiagnosticPosition pos, Env<AttrContext> env,
+                                  Symbol location, Type site, Name name, List<Type> argtypes,
+                                  List<Type> typeargtypes) {
+        MethodResolutionContext prevResolutionContext = currentResolutionContext;
+        try {
+            currentResolutionContext = resolveContext;
+            Symbol sym = methodNotFound;
+            List<MethodResolutionPhase> steps = methodResolutionSteps;
+            while (steps.nonEmpty() &&
+                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
+                   sym.kind >= ERRONEOUS) {
+                currentResolutionContext.step = steps.head;
+                sym = findMethod(env, site, name, argtypes, typeargtypes,
+                        steps.head.isBoxingRequired(),
+                        env.info.varArgs = steps.head.isVarargsRequired(), false);
+                currentResolutionContext.resolutionCache.put(steps.head, sym);
+                steps = steps.tail;
+            }
+            if (sym.kind >= AMBIGUOUS) {
+                if (site.tsym.isPolymorphicSignatureGeneric()) {
+                    //polymorphic receiver - synthesize new method symbol
+                    env.info.varArgs = false;
+                    sym = findPolymorphicSignatureInstance(env,
+                            site, name, null, argtypes);
+                }
+                else {
+                    //if nothing is found return the 'first' error
+                    MethodResolutionPhase errPhase =
+                            currentResolutionContext.firstErroneousResolutionPhase();
+                    sym = access(currentResolutionContext.resolutionCache.get(errPhase),
+                            pos, location, site, name, true, argtypes, typeargtypes);
+                    env.info.varArgs = errPhase.isVarargsRequired;
+                }
+            } else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) {
+                //non-instantiated polymorphic signature - synthesize new method symbol
                 env.info.varArgs = false;
                 sym = findPolymorphicSignatureInstance(env,
-                        site, name, null, argtypes);
+                        site, name, (MethodSymbol)sym, argtypes);
             }
-            else {
-                //if nothing is found return the 'first' error
-                MethodResolutionPhase errPhase =
-                        firstErroneousResolutionPhase();
-                sym = access(methodResolutionCache.get(errPhase),
-                        pos, location, site, name, true, argtypes, typeargtypes);
-                env.info.varArgs = errPhase.isVarargsRequired;
-            }
-        } else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) {
-            //non-instantiated polymorphic signature - synthesize new method symbol
-            env.info.varArgs = false;
-            sym = findPolymorphicSignatureInstance(env,
-                    site, name, (MethodSymbol)sym, argtypes);
+            return sym;
         }
-        return sym;
+        finally {
+            currentResolutionContext = prevResolutionContext;
+        }
     }
 
     /** Find or create an implicit method of exactly the given type (after erasure).
@@ -1726,19 +1751,14 @@
                                         Type site, Name name,
                                         List<Type> argtypes,
                                         List<Type> typeargtypes) {
-        boolean prevInternal = internalResolution;
-        try {
-            internalResolution = true;
-            Symbol sym = resolveQualifiedMethod(
-                pos, env, site.tsym, site, name, argtypes, typeargtypes);
-            if (sym.kind == MTH) return (MethodSymbol)sym;
-            else throw new FatalError(
-                     diags.fragment("fatal.err.cant.locate.meth",
-                                    name));
-        }
-        finally {
-            internalResolution = prevInternal;
-        }
+        MethodResolutionContext resolveContext = new MethodResolutionContext();
+        resolveContext.internalResolution = true;
+        Symbol sym = resolveQualifiedMethod(resolveContext, pos, env, site.tsym,
+                site, name, argtypes, typeargtypes);
+        if (sym.kind == MTH) return (MethodSymbol)sym;
+        else throw new FatalError(
+                 diags.fragment("fatal.err.cant.locate.meth",
+                                name));
     }
 
     /** Resolve constructor.
@@ -1755,25 +1775,40 @@
                               Type site,
                               List<Type> argtypes,
                               List<Type> typeargtypes) {
-        Symbol sym = startResolution();
-        List<MethodResolutionPhase> steps = methodResolutionSteps;
-        while (steps.nonEmpty() &&
-               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
-               sym.kind >= ERRONEOUS) {
-            currentStep = steps.head;
-            sym = resolveConstructor(pos, env, site, argtypes, typeargtypes,
-                    steps.head.isBoxingRequired(),
-                    env.info.varArgs = steps.head.isVarargsRequired());
-            methodResolutionCache.put(steps.head, sym);
-            steps = steps.tail;
+        return resolveConstructor(new MethodResolutionContext(), pos, env, site, argtypes, typeargtypes);
+    }
+    private Symbol resolveConstructor(MethodResolutionContext resolveContext,
+                              DiagnosticPosition pos,
+                              Env<AttrContext> env,
+                              Type site,
+                              List<Type> argtypes,
+                              List<Type> typeargtypes) {
+        MethodResolutionContext prevResolutionContext = currentResolutionContext;
+        try {
+            currentResolutionContext = resolveContext;
+            Symbol sym = methodNotFound;
+            List<MethodResolutionPhase> steps = methodResolutionSteps;
+            while (steps.nonEmpty() &&
+                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
+                   sym.kind >= ERRONEOUS) {
+                currentResolutionContext.step = steps.head;
+                sym = findConstructor(pos, env, site, argtypes, typeargtypes,
+                        steps.head.isBoxingRequired(),
+                        env.info.varArgs = steps.head.isVarargsRequired());
+                currentResolutionContext.resolutionCache.put(steps.head, sym);
+                steps = steps.tail;
+            }
+            if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
+                MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase();
+                sym = access(currentResolutionContext.resolutionCache.get(errPhase),
+                        pos, site, names.init, true, argtypes, typeargtypes);
+                env.info.varArgs = errPhase.isVarargsRequired();
+            }
+            return sym;
         }
-        if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
-            MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
-            sym = access(methodResolutionCache.get(errPhase),
-                    pos, site, names.init, true, argtypes, typeargtypes);
-            env.info.varArgs = errPhase.isVarargsRequired();
+        finally {
+            currentResolutionContext = prevResolutionContext;
         }
-        return sym;
     }
 
     /** Resolve constructor using diamond inference.
@@ -1791,38 +1826,82 @@
                               Type site,
                               List<Type> argtypes,
                               List<Type> typeargtypes) {
-        Symbol sym = startResolution();
-        List<MethodResolutionPhase> steps = methodResolutionSteps;
-        while (steps.nonEmpty() &&
-               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
-               sym.kind >= ERRONEOUS) {
-            currentStep = steps.head;
-            sym = resolveConstructor(pos, env, site, argtypes, typeargtypes,
-                    steps.head.isBoxingRequired(),
-                    env.info.varArgs = steps.head.isVarargsRequired());
-            methodResolutionCache.put(steps.head, sym);
-            steps = steps.tail;
+        MethodResolutionContext prevResolutionContext = currentResolutionContext;
+        try {
+            currentResolutionContext = new MethodResolutionContext();
+            Symbol sym = methodNotFound;
+            List<MethodResolutionPhase> steps = methodResolutionSteps;
+            while (steps.nonEmpty() &&
+                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
+                   sym.kind >= ERRONEOUS) {
+                currentResolutionContext.step = steps.head;
+                sym = findDiamond(env, site, argtypes, typeargtypes,
+                        steps.head.isBoxingRequired(),
+                        env.info.varArgs = steps.head.isVarargsRequired());
+                currentResolutionContext.resolutionCache.put(steps.head, sym);
+                steps = steps.tail;
+            }
+            if (sym.kind >= AMBIGUOUS) {
+                final JCDiagnostic details = sym.kind == WRONG_MTH ?
+                                currentResolutionContext.candidates.head.details :
+                                null;
+                Symbol errSym = new ResolveError(WRONG_MTH, "diamond error") {
+                    @Override
+                    JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos,
+                            Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
+                        String key = details == null ?
+                            "cant.apply.diamond" :
+                            "cant.apply.diamond.1";
+                        return diags.create(dkind, log.currentSource(), pos, key,
+                                diags.fragment("diamond", site.tsym), details);
+                    }
+                };
+                MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase();
+                sym = access(errSym, pos, site, names.init, true, argtypes, typeargtypes);
+                env.info.varArgs = errPhase.isVarargsRequired();
+            }
+            return sym;
         }
-        if (sym.kind >= AMBIGUOUS) {
-            final JCDiagnostic details = sym.kind == WRONG_MTH ?
-                ((InapplicableSymbolError)sym).explanation :
-                null;
-            Symbol errSym = new ResolveError(WRONG_MTH, "diamond error") {
-                @Override
-                JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos,
-                        Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
-                    String key = details == null ?
-                        "cant.apply.diamond" :
-                        "cant.apply.diamond.1";
-                    return diags.create(dkind, log.currentSource(), pos, key,
-                            diags.fragment("diamond", site.tsym), details);
-                }
-            };
-            MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
-            sym = access(errSym, pos, site, names.init, true, argtypes, typeargtypes);
-            env.info.varArgs = errPhase.isVarargsRequired();
+        finally {
+            currentResolutionContext = prevResolutionContext;
         }
-        return sym;
+    }
+
+    /** This method scans all the constructor symbol in a given class scope -
+     *  assuming that the original scope contains a constructor of the kind:
+     *  Foo(X x, Y y), where X,Y are class type-variables declared in Foo,
+     *  a method check is executed against the modified constructor type:
+     *  <X,Y>Foo<X,Y>(X x, Y y). This is crucial in order to enable diamond
+     *  inference. The inferred return type of the synthetic constructor IS
+     *  the inferred type for the diamond operator.
+     */
+    private Symbol findDiamond(Env<AttrContext> env,
+                              Type site,
+                              List<Type> argtypes,
+                              List<Type> typeargtypes,
+                              boolean allowBoxing,
+                              boolean useVarargs) {
+        Symbol bestSoFar = methodNotFound;
+        for (Scope.Entry e = site.tsym.members().lookup(names.init);
+             e.scope != null;
+             e = e.next()) {
+            //- System.out.println(" e " + e.sym);
+            if (e.sym.kind == MTH &&
+                (e.sym.flags_field & SYNTHETIC) == 0) {
+                    List<Type> oldParams = e.sym.type.tag == FORALL ?
+                            ((ForAll)e.sym.type).tvars :
+                            List.<Type>nil();
+                    Type constrType = new ForAll(site.tsym.type.getTypeArguments().appendList(oldParams),
+                            types.createMethodTypeWithReturn(e.sym.type.asMethodType(), site));
+                    bestSoFar = selectBest(env, site, argtypes, typeargtypes,
+                            new MethodSymbol(e.sym.flags(), names.init, constrType, site.tsym),
+                            bestSoFar,
+                            allowBoxing,
+                            useVarargs,
+                            false);
+            }
+        }
+        return bestSoFar;
     }
 
     /** Resolve constructor.
@@ -1841,10 +1920,25 @@
                               List<Type> typeargtypes,
                               boolean allowBoxing,
                               boolean useVarargs) {
+        MethodResolutionContext prevResolutionContext = currentResolutionContext;
+        try {
+            currentResolutionContext = new MethodResolutionContext();
+            return findConstructor(pos, env, site, argtypes, typeargtypes, allowBoxing, useVarargs);
+        }
+        finally {
+            currentResolutionContext = prevResolutionContext;
+        }
+    }
+
+    Symbol findConstructor(DiagnosticPosition pos, Env<AttrContext> env,
+                              Type site, List<Type> argtypes,
+                              List<Type> typeargtypes,
+                              boolean allowBoxing,
+                              boolean useVarargs) {
         Symbol sym = findMethod(env, site,
-                                names.init, argtypes,
-                                typeargtypes, allowBoxing,
-                                useVarargs, false);
+                                    names.init, argtypes,
+                                    typeargtypes, allowBoxing,
+                                    useVarargs, false);
         chk.checkDeprecated(pos, env.info.scope.owner, sym);
         return sym;
     }
@@ -1860,8 +1954,9 @@
                                         Type site,
                                         List<Type> argtypes,
                                         List<Type> typeargtypes) {
-        Symbol sym = resolveConstructor(
-            pos, env, site, argtypes, typeargtypes);
+        MethodResolutionContext resolveContext = new MethodResolutionContext();
+        resolveContext.internalResolution = true;
+        Symbol sym = resolveConstructor(resolveContext, pos, env, site, argtypes, typeargtypes);
         if (sym.kind == MTH) return (MethodSymbol)sym;
         else throw new FatalError(
                  diags.fragment("fatal.err.cant.locate.ctor", site));
@@ -1875,15 +1970,21 @@
      */
     Symbol resolveOperator(DiagnosticPosition pos, JCTree.Tag optag,
                            Env<AttrContext> env, List<Type> argtypes) {
-        startResolution();
-        Name name = treeinfo.operatorName(optag);
-        Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes,
-                                null, false, false, true);
-        if (boxingEnabled && sym.kind >= WRONG_MTHS)
-            sym = findMethod(env, syms.predefClass.type, name, argtypes,
-                             null, true, false, true);
-        return access(sym, pos, env.enclClass.sym.type, name,
-                      false, argtypes, null);
+        MethodResolutionContext prevResolutionContext = currentResolutionContext;
+        try {
+            currentResolutionContext = new MethodResolutionContext();
+            Name name = treeinfo.operatorName(optag);
+            Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes,
+                                    null, false, false, true);
+            if (boxingEnabled && sym.kind >= WRONG_MTHS)
+                sym = findMethod(env, syms.predefClass.type, name, argtypes,
+                                 null, true, false, true);
+            return access(sym, pos, env.enclClass.sym.type, name,
+                          false, argtypes, null);
+        }
+        finally {
+            currentResolutionContext = prevResolutionContext;
+        }
     }
 
     /** Resolve operator.
@@ -1996,9 +2097,10 @@
  *  ResolveError classes, indicating error situations when accessing symbols
  ****************************************************************************/
 
-    public void logAccessError(Env<AttrContext> env, JCTree tree, Type type) {
-        AccessError error = new AccessError(env, type.getEnclosingType(), type.tsym);
-        logResolveError(error, tree.pos(), type.getEnclosingType().tsym, type.getEnclosingType(), null, null, null);
+    //used by TransTypes when checking target type of synthetic cast
+    public void logAccessErrorInternal(Env<AttrContext> env, JCTree tree, Type type) {
+        AccessError error = new AccessError(env, env.enclClass.type, type.tsym);
+        logResolveError(error, tree.pos(), env.enclClass.sym, env.enclClass.type, null, null, null);
     }
     //where
     private void logResolveError(ResolveError error,
@@ -2227,34 +2329,24 @@
      * (either a method, a constructor or an operand) is not applicable
      * given an actual arguments/type argument list.
      */
-    class InapplicableSymbolError extends InvalidSymbolError {
+    class InapplicableSymbolError extends ResolveError {
 
-        /** An auxiliary explanation set in case of instantiation errors. */
-        JCDiagnostic explanation;
-
-        InapplicableSymbolError(Symbol sym) {
-            super(WRONG_MTH, sym, "inapplicable symbol error");
+        InapplicableSymbolError() {
+            super(WRONG_MTH, "inapplicable symbol error");
         }
 
-        /** Update sym and explanation and return this.
-         */
-        InapplicableSymbolError setWrongSym(Symbol sym, JCDiagnostic explanation) {
-            this.sym = sym;
-            if (this.sym == sym && explanation != null)
-                this.explanation = explanation; //update the details
-            return this;
-        }
-
-        /** Update sym and return this.
-         */
-        InapplicableSymbolError setWrongSym(Symbol sym) {
-            this.sym = sym;
-            return this;
+        protected InapplicableSymbolError(int kind, String debugName) {
+            super(kind, debugName);
         }
 
         @Override
         public String toString() {
-            return super.toString() + " explanation=" + explanation;
+            return super.toString();
+        }
+
+        @Override
+        public boolean exists() {
+            return true;
         }
 
         @Override
@@ -2279,27 +2371,40 @@
                         key, name, first, second);
             }
             else {
-                Symbol ws = sym.asMemberOf(site, types);
+                Candidate c = errCandidate();
+                Symbol ws = c.sym.asMemberOf(site, types);
                 return diags.create(dkind, log.currentSource(), pos,
-                          "cant.apply.symbol" + (explanation != null ? ".1" : ""),
+                          "cant.apply.symbol" + (c.details != null ? ".1" : ""),
                           kindName(ws),
                           ws.name == names.init ? ws.owner.name : ws.name,
                           methodArguments(ws.type.getParameterTypes()),
                           methodArguments(argtypes),
                           kindName(ws.owner),
                           ws.owner.type,
-                          explanation);
+                          c.details);
             }
         }
 
-        void clear() {
-            explanation = null;
-        }
-
         @Override
         public Symbol access(Name name, TypeSymbol location) {
             return types.createErrorType(name, location, syms.errSymbol.type).tsym;
         }
+
+        protected boolean shouldReport(Candidate c) {
+            return !c.isApplicable() &&
+                    (((c.sym.flags() & VARARGS) != 0 && c.step == VARARITY) ||
+                      (c.sym.flags() & VARARGS) == 0 && c.step == (boxingEnabled ? BOX : BASIC));
+        }
+
+        private Candidate errCandidate() {
+            for (Candidate c : currentResolutionContext.candidates) {
+                if (shouldReport(c)) {
+                    return c;
+                }
+            }
+            Assert.error();
+            return null;
+        }
     }
 
     /**
@@ -2307,11 +2412,9 @@
      * (either methods, constructors or operands) is not applicable
      * given an actual arguments/type argument list.
      */
-    class InapplicableSymbolsError extends ResolveError {
+    class InapplicableSymbolsError extends InapplicableSymbolError {
 
-        private List<Candidate> candidates = List.nil();
-
-        InapplicableSymbolsError(Symbol sym) {
+        InapplicableSymbolsError() {
             super(WRONG_MTHS, "inapplicable symbols");
         }
 
@@ -2323,7 +2426,7 @@
                 Name name,
                 List<Type> argtypes,
                 List<Type> typeargtypes) {
-            if (candidates.nonEmpty()) {
+            if (currentResolutionContext.candidates.nonEmpty()) {
                 JCDiagnostic err = diags.create(dkind,
                         log.currentSource(),
                         pos,
@@ -2341,68 +2444,24 @@
         //where
         List<JCDiagnostic> candidateDetails(Type site) {
             List<JCDiagnostic> details = List.nil();
-            for (Candidate c : candidates)
-                details = details.prepend(c.getDiagnostic(site));
+            for (Candidate c : currentResolutionContext.candidates) {
+                if (!shouldReport(c)) continue;
+                JCDiagnostic detailDiag = diags.fragment("inapplicable.method",
+                        Kinds.kindName(c.sym),
+                        c.sym.location(site, types),
+                        c.sym.asMemberOf(site, types),
+                        c.details);
+                details = details.prepend(detailDiag);
+            }
             return details.reverse();
         }
 
-        Symbol addCandidate(MethodResolutionPhase currentStep, Symbol sym, JCDiagnostic details) {
-            Candidate c = new Candidate(currentStep, sym, details);
-            if (c.isValid() && !candidates.contains(c))
-                candidates = candidates.append(c);
-            return this;
-        }
-
-        void clear() {
-            candidates = List.nil();
-        }
-
         private Name getName() {
-            Symbol sym = candidates.head.sym;
+            Symbol sym = currentResolutionContext.candidates.head.sym;
             return sym.name == names.init ?
                 sym.owner.name :
                 sym.name;
         }
-
-        private class Candidate {
-
-            final MethodResolutionPhase step;
-            final Symbol sym;
-            final JCDiagnostic details;
-
-            private Candidate(MethodResolutionPhase step, Symbol sym, JCDiagnostic details) {
-                this.step = step;
-                this.sym = sym;
-                this.details = details;
-            }
-
-            JCDiagnostic getDiagnostic(Type site) {
-                return diags.fragment("inapplicable.method",
-                        Kinds.kindName(sym),
-                        sym.location(site, types),
-                        sym.asMemberOf(site, types),
-                        details);
-            }
-
-            @Override
-            public boolean equals(Object o) {
-                if (o instanceof Candidate) {
-                    Symbol s1 = this.sym;
-                    Symbol s2 = ((Candidate)o).sym;
-                    if  ((s1 != s2 &&
-                        (s1.overrides(s2, s1.owner.type.tsym, types, false) ||
-                        (s2.overrides(s1, s2.owner.type.tsym, types, false)))) ||
-                        ((s1.isConstructor() || s2.isConstructor()) && s1.owner != s2.owner))
-                        return true;
-                }
-                return false;
-            }
-
-            boolean isValid() {
-                return  (((sym.flags() & VARARGS) != 0 && step == VARARITY) ||
-                          (sym.flags() & VARARGS) == 0 && step == (boxingEnabled ? BOX : BASIC));
-            }
-        }
     }
 
     /**
@@ -2563,29 +2622,91 @@
         }
     }
 
-    private Map<MethodResolutionPhase, Symbol> methodResolutionCache =
-        new HashMap<MethodResolutionPhase, Symbol>(MethodResolutionPhase.values().length);
-
-    private Map<Symbol, JCDiagnostic> verboseResolutionCandidateDiags =
-        new LinkedHashMap<Symbol, JCDiagnostic>();
-
     final List<MethodResolutionPhase> methodResolutionSteps = List.of(BASIC, BOX, VARARITY);
 
-    private MethodResolutionPhase currentStep = null;
+    /**
+     * A resolution context is used to keep track of intermediate results of
+     * overload resolution, such as list of method that are not applicable
+     * (used to generate more precise diagnostics) and so on. Resolution contexts
+     * can be nested - this means that when each overload resolution routine should
+     * work within the resolution context it created.
+     */
+    class MethodResolutionContext {
 
-    private boolean internalResolution = false;
+        private List<Candidate> candidates = List.nil();
 
-    private MethodResolutionPhase firstErroneousResolutionPhase() {
-        MethodResolutionPhase bestSoFar = BASIC;
-        Symbol sym = methodNotFound;
-        List<MethodResolutionPhase> steps = methodResolutionSteps;
-        while (steps.nonEmpty() &&
-               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
-               sym.kind >= WRONG_MTHS) {
-            sym = methodResolutionCache.get(steps.head);
-            bestSoFar = steps.head;
-            steps = steps.tail;
+        private Map<MethodResolutionPhase, Symbol> resolutionCache =
+            new EnumMap<MethodResolutionPhase, Symbol>(MethodResolutionPhase.class);
+
+        private MethodResolutionPhase step = null;
+
+        private boolean internalResolution = false;
+
+        private MethodResolutionPhase firstErroneousResolutionPhase() {
+            MethodResolutionPhase bestSoFar = BASIC;
+            Symbol sym = methodNotFound;
+            List<MethodResolutionPhase> steps = methodResolutionSteps;
+            while (steps.nonEmpty() &&
+                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
+                   sym.kind >= WRONG_MTHS) {
+                sym = resolutionCache.get(steps.head);
+                bestSoFar = steps.head;
+                steps = steps.tail;
+            }
+            return bestSoFar;
         }
-        return bestSoFar;
+
+        void addInapplicableCandidate(Symbol sym, JCDiagnostic details) {
+            Candidate c = new Candidate(currentResolutionContext.step, sym, details, null);
+            if (!candidates.contains(c))
+                candidates = candidates.append(c);
+        }
+
+        void addApplicableCandidate(Symbol sym, Type mtype) {
+            Candidate c = new Candidate(currentResolutionContext.step, sym, null, mtype);
+            candidates = candidates.append(c);
+        }
+
+        /**
+         * This class represents an overload resolution candidate. There are two
+         * kinds of candidates: applicable methods and inapplicable methods;
+         * applicable methods have a pointer to the instantiated method type,
+         * while inapplicable candidates contain further details about the
+         * reason why the method has been considered inapplicable.
+         */
+        class Candidate {
+
+            final MethodResolutionPhase step;
+            final Symbol sym;
+            final JCDiagnostic details;
+            final Type mtype;
+
+            private Candidate(MethodResolutionPhase step, Symbol sym, JCDiagnostic details, Type mtype) {
+                this.step = step;
+                this.sym = sym;
+                this.details = details;
+                this.mtype = mtype;
+            }
+
+            @Override
+            public boolean equals(Object o) {
+                if (o instanceof Candidate) {
+                    Symbol s1 = this.sym;
+                    Symbol s2 = ((Candidate)o).sym;
+                    if  ((s1 != s2 &&
+                        (s1.overrides(s2, s1.owner.type.tsym, types, false) ||
+                        (s2.overrides(s1, s2.owner.type.tsym, types, false)))) ||
+                        ((s1.isConstructor() || s2.isConstructor()) && s1.owner != s2.owner))
+                        return true;
+                }
+                return false;
+            }
+
+            boolean isApplicable() {
+                return mtype != null;
+            }
+        }
     }
+
+    MethodResolutionContext currentResolutionContext = null;
 }
diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/TransTypes.java b/langtools/src/share/classes/com/sun/tools/javac/comp/TransTypes.java
index b69b498..ecd271b 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/TransTypes.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/TransTypes.java
@@ -107,7 +107,7 @@
         make.at(tree.pos);
         if (!types.isSameType(tree.type, target)) {
             if (!resolve.isAccessible(env, target.tsym))
-                resolve.logAccessError(env, tree, target);
+                resolve.logAccessErrorInternal(env, tree, target);
             tree = make.TypeCast(make.Type(target), tree).setType(target);
         }
         make.pos = oldpos;
diff --git a/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java b/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
index 00eef07..27703b7 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -102,6 +102,16 @@
         setOpname(MOD, "%", names);
     }
 
+    public static List<JCExpression> args(JCTree t) {
+        switch (t.getTag()) {
+            case APPLY:
+                return ((JCMethodInvocation)t).args;
+            case NEWCLASS:
+                return ((JCNewClass)t).args;
+            default:
+                return null;
+        }
+    }
 
     /** Return name of operator with given tree tag.
      */
diff --git a/langtools/test/Makefile b/langtools/test/Makefile
index 8964a00..c77f564 100644
--- a/langtools/test/Makefile
+++ b/langtools/test/Makefile
@@ -36,6 +36,14 @@
     ARCH=i586
   endif
 endif
+ifeq ($(OSNAME), Darwin)
+  PLATFORM = bsd
+  JT_PLATFORM = linux
+  ARCH = $(shell uname -m)
+  ifeq ($(ARCH), i386)
+    ARCH=i586
+  endif
+endif
 ifeq ($(OSNAME), Windows_NT)
   # MKS
   PLATFORM=windows
@@ -251,6 +259,7 @@
 # JTREG_REFERENCE
 #	(Optional) reference results (e.g. work, report or summary.txt)
 #
+jtreg_tests: jtreg-tests
 jtreg-tests: check-jtreg FRC
 	@rm -f -r $(JTREG_OUTPUT_DIR)/JTwork $(JTREG_OUTPUT_DIR)/JTreport \
 	    $(JTREG_OUTPUT_DIR)/diff.html $(JTREG_OUTPUT_DIR)/status.txt
diff --git a/langtools/test/jprt.config b/langtools/test/jprt.config
deleted file mode 100644
index 3d6c975..0000000
--- a/langtools/test/jprt.config
+++ /dev/null
@@ -1,159 +0,0 @@
-#!echo "This is not a shell script"
-#############################################################################
-# Copyright (c) 2006, 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.
-#############################################################################
-#
-# JPRT shell configuration for testing.
-#
-# Input environment variables:
-#    Windows Only:
-#      PATH
-#      ROOTDIR
-#
-# Output variable settings:
-#    make    Full path to GNU make
-#
-# Output environment variables:
-#    PATH
-#
-#############################################################################
-
-#############################################################################
-# Error
-error() # message
-{
-  echo "ERROR: $1"
-  exit 6
-}
-# Directory must exist
-dirMustExist() # dir name
-{
-  if [ ! -d "$1" ] ; then
-    error "Directory for $2 does not exist: $1"
-  fi
-}
-# File must exist
-fileMustExist() # dir name
-{
-  if [ ! -f "$1" ] ; then
-    error "File for $2 does not exist: $1"
-  fi
-}
-#############################################################################
-
-# Should be set by JPRT as the 3 basic inputs
-slashjava="${ALT_SLASH_JAVA}"
-if [ "${slashjava}" = "" ] ; then
-  slashjava=/java
-fi
-
-# Check input
-dirMustExist "${slashjava}"  ALT_SLASH_JAVA
-
-# Uses 'uname -s', but only expect SunOS or Linux, assume Windows otherwise.
-osname=`uname -s`
-if [ "${osname}" = SunOS ] ; then
-   
-    # SOLARIS: Sparc or X86
-    osarch=`uname -p`
-    if [ "${osarch}" = sparc ] ; then
-	solaris_arch=sparc
-    else
-	solaris_arch=i386
-    fi
-
-    # Add basic solaris system paths
-    path4sdk=/usr/ccs/bin:/usr/ccs/lib:/usr/bin:/bin:/usr/sfw/bin
-
-    # Find GNU make
-    make=/usr/sfw/bin/gmake
-    if [ ! -f ${make} ] ; then
-	make=/opt/sfw/bin/gmake
-	if [ ! -f ${make} ] ; then
-	    make=${slashjava}/devtools/${solaris_arch}/bin/gnumake
-        fi 
-    fi
-    fileMustExist "${make}" make
-
-    # File creation mask
-    umask 002
-
-elif [ "${osname}" = Linux ] ; then
-   
-    # Add basic paths
-    path4sdk=/usr/bin:/bin:/usr/sbin:/sbin
-
-    # Find GNU make
-    make=/usr/bin/make
-    fileMustExist "${make}" make
-
-    umask 002
-
-else
-
-    # Windows: Differs on CYGWIN vs. MKS.
-   
-    # We need to determine if we are running a CYGWIN shell or an MKS shell
-    #    (if uname isn't available, then it will be unix_toolset=unknown)
-    unix_toolset=unknown
-    if [ "`uname -a | fgrep Cygwin`" = "" -a -d "${ROOTDIR}" ] ; then
-        # We kind of assume ROOTDIR is where MKS is and it's ok
-        unix_toolset=MKS
-        mkshome=`dosname -s "${ROOTDIR}"`
-        # Most unix utilities are in the mksnt directory of ROOTDIR
-        unixcommand_path="${mkshome}/mksnt"
-        path4sdk="${unixcommand_path}"
-	devtools_path="${slashjava}/devtools/win32/bin"
-	path4sdk="${devtools_path};${path4sdk}"
-        # Find GNU make
-        make="${devtools_path}/gnumake.exe"
-        fileMustExist "${make}" make
-    elif [ "`uname -a | fgrep Cygwin`" != "" -a -f /bin/cygpath ] ; then
-        # For CYGWIN, uname will have "Cygwin" in it, and /bin/cygpath should exist
-        unix_toolset=CYGWIN
-        # Most unix utilities are in the /usr/bin
-        unixcommand_path="/usr/bin"
-        path4sdk="${unixcommand_path}"
-        # Find GNU make
-        make="${unixcommand_path}/make.exe"
-        fileMustExist "${make}" make
-    else
-      echo "WARNING: Cannot figure out if this is MKS or CYGWIN"
-    fi
-
-    
-    # For windows, it's hard to know where the system is, so we just add this
-    #    to PATH.
-    slash_path="`echo ${path4sdk} | sed -e 's@\\\\@/@g' -e 's@//@/@g' -e 's@/$@@' -e 's@/;@;@g'`"
-    path4sdk="${slash_path};${PATH}"
-    
-    # Convert path4sdk to cygwin style
-    if [ "${unix_toolset}" = CYGWIN ] ; then
-	path4sdk="`/usr/bin/cygpath -p ${path4sdk}`"
-    fi
-
-fi
-
-# Export PATH setting
-PATH="${path4sdk}"
-export PATH
-
diff --git a/langtools/test/tools/javac/4846262/Test.sh b/langtools/test/tools/javac/4846262/Test.sh
index 7bc9c65..543efb0 100644
--- a/langtools/test/tools/javac/4846262/Test.sh
+++ b/langtools/test/tools/javac/4846262/Test.sh
@@ -44,7 +44,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     FS="/"
     ;;
   CYGWIN* )
diff --git a/langtools/test/tools/javac/6302184/T6302184.sh b/langtools/test/tools/javac/6302184/T6302184.sh
index c95db5c..5a1c333 100644
--- a/langtools/test/tools/javac/6302184/T6302184.sh
+++ b/langtools/test/tools/javac/6302184/T6302184.sh
@@ -41,7 +41,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     FS="/"
     ;;
   CYGWIN* )
diff --git a/langtools/test/tools/javac/7132880/T7132880.java b/langtools/test/tools/javac/7132880/T7132880.java
new file mode 100644
index 0000000..b41f140
--- /dev/null
+++ b/langtools/test/tools/javac/7132880/T7132880.java
@@ -0,0 +1,60 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 7132880
+ * @summary Resolve should support nested resolution contexts
+ * @compile/fail/ref=T7132880.out -XDrawDiagnostics T7132880.java
+ */
+class Outer {
+    void m1(String s) { }
+    void m2(int i1, int i2) { }
+
+    class Inner {
+        void test() {
+           //ok - no method named 'm' in Inner - hence, class to search is Outer
+           m1("");
+        }
+    }
+
+    class Inner1 {
+        void m1(Integer i) { }
+
+        void test() {
+           //error - Inner1 defines an incompatible method - hence, class to search is Inner1
+           m1("");
+        }
+    }
+
+    class Inner2 {
+        private void m1(Integer i) { }
+        private void m1(Double d) { }
+
+        void test() {
+           //error - Inner2 defines multiple incompatible methods - hence, class to search is Inner2
+           m1("");
+        }
+    }
+
+    class Inner3 {
+        private void m2(Object o, int i) { }
+        private void m2(int i, Object o) { }
+
+        void test() {
+           //error - Inner3 defines multiple ambiguous methods - hence, class to search is Inner3
+           m2(1, 1);
+        }
+    }
+
+    class Inner4 extends Inner2 {
+        void test() {
+           //ok - Inner2 defines multiple incompatible inaccessible methods - hence, class to search is Outer
+           m1("");
+        }
+    }
+
+    class Inner5 extends Inner3 {
+        void test() {
+           //ok - Inner3 defines multiple inaccessible ambiguous methods - hence, class to search is Outer
+           m2(1, 1);
+        }
+    }
+}
diff --git a/langtools/test/tools/javac/7132880/T7132880.out b/langtools/test/tools/javac/7132880/T7132880.out
new file mode 100644
index 0000000..f977516
--- /dev/null
+++ b/langtools/test/tools/javac/7132880/T7132880.out
@@ -0,0 +1,4 @@
+T7132880.java:23:12: compiler.err.cant.apply.symbol.1: kindname.method, m1, java.lang.Integer, java.lang.String, kindname.class, Outer.Inner1, (compiler.misc.no.conforming.assignment.exists: java.lang.String, java.lang.Integer)
+T7132880.java:33:12: compiler.err.cant.apply.symbols: kindname.method, m1, java.lang.String,{(compiler.misc.inapplicable.method: kindname.method, Outer.Inner2, m1(java.lang.Double), (compiler.misc.no.conforming.assignment.exists: java.lang.String, java.lang.Double)),(compiler.misc.inapplicable.method: kindname.method, Outer.Inner2, m1(java.lang.Integer), (compiler.misc.no.conforming.assignment.exists: java.lang.String, java.lang.Integer))}
+T7132880.java:43:12: compiler.err.ref.ambiguous: m2, kindname.method, m2(java.lang.Object,int), Outer.Inner3, kindname.method, m2(int,java.lang.Object), Outer.Inner3
+3 errors
diff --git a/langtools/test/tools/javac/ClassPathTest/ClassPathTest.sh b/langtools/test/tools/javac/ClassPathTest/ClassPathTest.sh
index cbf7aa7..e46aef0 100644
--- a/langtools/test/tools/javac/ClassPathTest/ClassPathTest.sh
+++ b/langtools/test/tools/javac/ClassPathTest/ClassPathTest.sh
@@ -56,7 +56,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux | CYGWIN* )
+  SunOS | Linux | Darwin | CYGWIN* )
     FS="/"
     ;;
   Windows* )
diff --git a/langtools/test/tools/javac/ExtDirs/ExtDirs.sh b/langtools/test/tools/javac/ExtDirs/ExtDirs.sh
index 157a028..00da24e 100644
--- a/langtools/test/tools/javac/ExtDirs/ExtDirs.sh
+++ b/langtools/test/tools/javac/ExtDirs/ExtDirs.sh
@@ -54,7 +54,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/langtools/test/tools/javac/MissingInclude.sh b/langtools/test/tools/javac/MissingInclude.sh
index 3856ac8..f175a50 100644
--- a/langtools/test/tools/javac/MissingInclude.sh
+++ b/langtools/test/tools/javac/MissingInclude.sh
@@ -47,7 +47,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux | CYGWIN* )
+  SunOS | Linux | Darwin | CYGWIN* )
     FS="/"
     ;;
   Windows* )
diff --git a/langtools/test/tools/javac/ProtectedInnerClass/ProtectedInnerClass.sh b/langtools/test/tools/javac/ProtectedInnerClass/ProtectedInnerClass.sh
index 33f6922..d06b82a 100644
--- a/langtools/test/tools/javac/ProtectedInnerClass/ProtectedInnerClass.sh
+++ b/langtools/test/tools/javac/ProtectedInnerClass/ProtectedInnerClass.sh
@@ -52,7 +52,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/langtools/test/tools/javac/T5090006/compiler.sh b/langtools/test/tools/javac/T5090006/compiler.sh
index cb7c3c8..5c913b3 100644
--- a/langtools/test/tools/javac/T5090006/compiler.sh
+++ b/langtools/test/tools/javac/T5090006/compiler.sh
@@ -47,7 +47,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux | CYGWIN* )
+  SunOS | Linux | Darwin | CYGWIN* )
     FS="/"
     ;;
   Windows* )
diff --git a/langtools/test/tools/javac/constDebug/ConstDebug.sh b/langtools/test/tools/javac/constDebug/ConstDebug.sh
index a936a30..0a96a47 100644
--- a/langtools/test/tools/javac/constDebug/ConstDebug.sh
+++ b/langtools/test/tools/javac/constDebug/ConstDebug.sh
@@ -47,7 +47,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/langtools/test/tools/javac/fatalErrors/NoJavaLang.sh b/langtools/test/tools/javac/fatalErrors/NoJavaLang.sh
index 561bfa2..77cc37c 100644
--- a/langtools/test/tools/javac/fatalErrors/NoJavaLang.sh
+++ b/langtools/test/tools/javac/fatalErrors/NoJavaLang.sh
@@ -48,7 +48,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     FS="/"
     ;;
   CYGWIN* )
diff --git a/langtools/test/tools/javac/generics/6723444/T6723444.out b/langtools/test/tools/javac/generics/6723444/T6723444.out
index add9485..8fc9df4 100644
--- a/langtools/test/tools/javac/generics/6723444/T6723444.out
+++ b/langtools/test/tools/javac/generics/6723444/T6723444.out
@@ -1,5 +1,5 @@
-T6723444.java:42:9: compiler.err.unreported.exception.need.to.catch.or.throw: X2
-T6723444.java:43:9: compiler.err.unreported.exception.need.to.catch.or.throw: X2
+T6723444.java:42:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
+T6723444.java:43:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
 T6723444.java:45:32: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
 T6723444.java:46:17: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
 T6723444.java:48:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
diff --git a/langtools/test/tools/javac/generics/7151070/T7151070.java b/langtools/test/tools/javac/generics/7151070/T7151070.java
new file mode 100644
index 0000000..5dfbac5
--- /dev/null
+++ b/langtools/test/tools/javac/generics/7151070/T7151070.java
@@ -0,0 +1,25 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug     7151070
+ * @summary NullPointerException in Resolve.isAccessible
+ * @compile/fail/ref=T7151070.out -XDrawDiagnostics T7151070.java
+ */
+
+class T7151070a {
+    private static class PrivateCls { }
+    public static class PublicCls extends PrivateCls { }
+
+    public void m(PrivateCls p) { }
+}
+
+class T7151070b {
+    public void test(Test<T7151070a.PublicCls> obj, T7151070a outer) {
+        outer.m(obj.get());
+    }
+
+    public static class Test<T> {
+        public T get() {
+            return null;
+        }
+    }
+}
diff --git a/langtools/test/tools/javac/generics/7151070/T7151070.out b/langtools/test/tools/javac/generics/7151070/T7151070.out
new file mode 100644
index 0000000..8e9df56
--- /dev/null
+++ b/langtools/test/tools/javac/generics/7151070/T7151070.out
@@ -0,0 +1,2 @@
+T7151070.java:17:24: compiler.err.report.access: T7151070a.PrivateCls, private, T7151070a
+1 error
diff --git a/langtools/test/tools/javac/generics/7151802/T7151802.java b/langtools/test/tools/javac/generics/7151802/T7151802.java
new file mode 100644
index 0000000..efc1aec
--- /dev/null
+++ b/langtools/test/tools/javac/generics/7151802/T7151802.java
@@ -0,0 +1,43 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug     7151802
+ * @summary compiler update caused sqe test failed
+ * @compile/fail/ref=T7151802.out -Werror -Xlint:unchecked -XDrawDiagnostics T7151802.java
+ */
+class T7151802 {
+    static class Foo<X> { }
+
+    static class SubFoo<X> extends Foo<X> { }
+
+    //generic - bound - arg - non-slilent
+    <Z extends Foo<String>> void get1(Z fz) { }
+    void test1(Foo foo) { get1(foo); }
+
+    //generic - bound - arg - silent
+    <Z extends Foo<?>> void get2(Z fz) { }
+    void test2(Foo foo) { get2(foo); }
+
+    //generic - nobound - arg - non-slilent
+    <Z> void get3(Foo<Z> fz) { }
+    void test(Foo foo) { get3(foo); }
+
+    //generic - nobound - arg - slilent
+    <Z> void get4(Foo<?> fz) { }
+    void test4(Foo foo) { get4(foo); }
+
+    //generic - bound - ret - non-slilent
+    <Z extends Foo<String>> Z get5() { return null; }
+    void test5() { SubFoo sf = get5(); }
+
+    //generic - bound - ret - slilent
+    static <Z extends Foo<?>> Z get6() { return null; }
+    void test6() { SubFoo sf = get6(); }
+
+    //nogeneric - nobound - arg - non-slilent
+    void get7(Foo<String> fz) { }
+    void test7(Foo foo) { get7(foo); }
+
+    //nogeneric - nobound - arg - slilent
+    static void get8(Foo<?> fz) { }
+    void test8(Foo foo) { get8(foo); }
+}
diff --git a/langtools/test/tools/javac/generics/7151802/T7151802.out b/langtools/test/tools/javac/generics/7151802/T7151802.out
new file mode 100644
index 0000000..e2ff30b
--- /dev/null
+++ b/langtools/test/tools/javac/generics/7151802/T7151802.out
@@ -0,0 +1,9 @@
+T7151802.java:14:31: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get1, Z, T7151802.Foo, kindname.class, T7151802
+T7151802.java:22:31: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T7151802.Foo, T7151802.Foo<Z>
+T7151802.java:22:30: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get3, T7151802.Foo<Z>, T7151802.Foo, kindname.class, T7151802
+T7151802.java:30:36: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get5, compiler.misc.no.args, compiler.misc.no.args, kindname.class, T7151802
+T7151802.java:38:32: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T7151802.Foo, T7151802.Foo<java.lang.String>
+T7151802.java:38:31: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get7, T7151802.Foo<java.lang.String>, T7151802.Foo, kindname.class, T7151802
+- compiler.err.warnings.and.werror
+1 error
+6 warnings
diff --git a/langtools/test/tools/javac/generics/rawOverride/T7148556.java b/langtools/test/tools/javac/generics/rawOverride/T7148556.java
new file mode 100644
index 0000000..476d9ca
--- /dev/null
+++ b/langtools/test/tools/javac/generics/rawOverride/T7148556.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 7148556
+ * @summary Implementing a generic interface causes a public clone() to become inaccessible
+ * @compile T7148556.java
+ */
+
+class T7148556 {
+
+    interface A extends Cloneable {
+       public Object clone();
+    }
+
+    interface B extends A, java.util.List { }
+
+    void test(B b) {
+        b.clone();
+    }
+}
diff --git a/langtools/test/tools/javac/generics/typevars/T7148242.java b/langtools/test/tools/javac/generics/typevars/T7148242.java
new file mode 100644
index 0000000..1080c0d0
--- /dev/null
+++ b/langtools/test/tools/javac/generics/typevars/T7148242.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2009, 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.
+ */
+
+/*
+ * @test
+ * @bug     7148242
+ * @summary Regression: valid code rejected during generic type well-formedness check
+ * @compile T7148242.java
+ */
+class T7148242 {
+   static abstract class A<K, V, I extends Pair<K, V>, I2 extends Pair<V, K>> {
+      abstract A<V, K, I2, I> test();
+   }
+   static class Pair<K, V> { }
+}
diff --git a/langtools/test/tools/javac/innerClassFile/Driver.sh b/langtools/test/tools/javac/innerClassFile/Driver.sh
index f4d89d0..dbe7366 100644
--- a/langtools/test/tools/javac/innerClassFile/Driver.sh
+++ b/langtools/test/tools/javac/innerClassFile/Driver.sh
@@ -53,7 +53,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux | CYGWIN* )
+  SunOS | Linux | Darwin | CYGWIN* )
     FS="/"
     ;;
   Windows* )
diff --git a/langtools/test/tools/javac/javazip/Test.sh b/langtools/test/tools/javac/javazip/Test.sh
index c8a59a60..4fbf874 100644
--- a/langtools/test/tools/javac/javazip/Test.sh
+++ b/langtools/test/tools/javac/javazip/Test.sh
@@ -41,7 +41,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     FS="/"
     SCR=`pwd`
     ;;
diff --git a/langtools/test/tools/javac/links/links.sh b/langtools/test/tools/javac/links/links.sh
index 110497f..83d10c0 100644
--- a/langtools/test/tools/javac/links/links.sh
+++ b/langtools/test/tools/javac/links/links.sh
@@ -53,7 +53,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     NULL=/dev/null
     PS=":"
     FS="/"
diff --git a/langtools/test/tools/javac/newlines/Newlines.sh b/langtools/test/tools/javac/newlines/Newlines.sh
index 56f250e..ccb30c6 100644
--- a/langtools/test/tools/javac/newlines/Newlines.sh
+++ b/langtools/test/tools/javac/newlines/Newlines.sh
@@ -50,7 +50,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux | CYGWIN* )
+  SunOS | Linux | Darwin | CYGWIN* )
     FS="/"
     ;;
   Windows* )
diff --git a/langtools/test/tools/javac/stackmap/T4955930.sh b/langtools/test/tools/javac/stackmap/T4955930.sh
index e87300f..731ce80 100644
--- a/langtools/test/tools/javac/stackmap/T4955930.sh
+++ b/langtools/test/tools/javac/stackmap/T4955930.sh
@@ -41,7 +41,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux | CYGWIN* )
+  SunOS | Linux | Darwin | CYGWIN* )
     FS="/"
     ;;
   Windows_95 | Windows_98 | Windows_NT )
diff --git a/langtools/test/tools/javac/unicode/SupplementaryJavaID6.sh b/langtools/test/tools/javac/unicode/SupplementaryJavaID6.sh
index 6c2ac80..9f728bb 100644
--- a/langtools/test/tools/javac/unicode/SupplementaryJavaID6.sh
+++ b/langtools/test/tools/javac/unicode/SupplementaryJavaID6.sh
@@ -55,7 +55,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     if [ -d /usr/lib/locale/en_US.UTF-8 -o -d /usr/lib/locale/en_US.utf8 ]
     then
         ENV="env LANG=en_US.UTF-8"
diff --git a/langtools/test/tools/javah/6257087/foo.sh b/langtools/test/tools/javah/6257087/foo.sh
index 40b5458..e141e62 100644
--- a/langtools/test/tools/javah/6257087/foo.sh
+++ b/langtools/test/tools/javah/6257087/foo.sh
@@ -41,7 +41,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/langtools/test/tools/javah/ConstMacroTest.sh b/langtools/test/tools/javah/ConstMacroTest.sh
index 324decc..b8a7a3c 100644
--- a/langtools/test/tools/javah/ConstMacroTest.sh
+++ b/langtools/test/tools/javah/ConstMacroTest.sh
@@ -56,7 +56,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux )
+  SunOS | Linux | Darwin )
     PS=":"
     FS="/"
     ;;
diff --git a/langtools/test/tools/javah/MissingParamClassTest.sh b/langtools/test/tools/javah/MissingParamClassTest.sh
index 5b72a68..4796ac7 100644
--- a/langtools/test/tools/javah/MissingParamClassTest.sh
+++ b/langtools/test/tools/javah/MissingParamClassTest.sh
@@ -58,7 +58,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux | CYGWIN* )
+  SunOS | Linux | Darwin | CYGWIN* )
     PS=":"
     FS="/"
     ;;
diff --git a/langtools/test/tools/javah/ReadOldClass.sh b/langtools/test/tools/javah/ReadOldClass.sh
index 1ad4e55..516c188 100644
--- a/langtools/test/tools/javah/ReadOldClass.sh
+++ b/langtools/test/tools/javah/ReadOldClass.sh
@@ -43,7 +43,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux | CYGWIN* )
+  SunOS | Linux | Darwin | CYGWIN* )
     PS=":"
     FS="/"
     ;;
diff --git a/langtools/test/tools/javap/pathsep.sh b/langtools/test/tools/javap/pathsep.sh
index 90b5bdb..f34da2a 100644
--- a/langtools/test/tools/javap/pathsep.sh
+++ b/langtools/test/tools/javap/pathsep.sh
@@ -40,7 +40,7 @@
 # set platform-dependent variables
 OS=`uname -s`
 case "$OS" in
-  SunOS | Linux | CYGWIN* )
+  SunOS | Linux | Darwin | CYGWIN* )
     FS="/"
     ;;
   Windows* )
diff --git a/make/Defs-internal.gmk b/make/Defs-internal.gmk
index 89ca1c1..bc3f32b 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 b9c8d5b..abe0c1f 100644
--- a/make/jprt.properties
+++ b/make/jprt.properties
@@ -39,6 +39,7 @@
     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}
 
@@ -53,6 +54,7 @@
     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