Merge jdk7-b102
authorlana
Tue, 20 Jul 2010 22:21:31 -0700
changeset 261813029a61b16b
parent 2543 6c4450bbad6d
parent 2617 c5a436f053aa
child 2619 6488b70a23cc
Merge
test/java/nio/channels/ServerSocketChannel/AcceptAddress.java
test/java/nio/charset/coders/Surrogate.java
test/tools/launcher/Makefile.SolarisRunpath
test/tools/launcher/lib/i386/lib32/lib32/liblibrary.so
test/tools/launcher/lib/i386/lib32/liblibrary.so
test/tools/launcher/lib/sparc/lib32/lib32/liblibrary.so
test/tools/launcher/lib/sparc/lib32/liblibrary.so
test/tools/launcher/lib/sparc/lib64/lib64/liblibrary.so
test/tools/launcher/lib/sparc/lib64/liblibrary.so
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/make/common/shared/Defs-javadoc.gmk	Tue Jul 20 22:21:31 2010 -0700
     1.3 @@ -0,0 +1,93 @@
     1.4 +#
     1.5 +# Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 +#
     1.8 +# This code is free software; you can redistribute it and/or modify it
     1.9 +# under the terms of the GNU General Public License version 2 only, as
    1.10 +# published by the Free Software Foundation.  Oracle designates this
    1.11 +# particular file as subject to the "Classpath" exception as provided
    1.12 +# by Oracle in the LICENSE file that accompanied this code.
    1.13 +#
    1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 +# version 2 for more details (a copy is included in the LICENSE file that
    1.18 +# accompanied this code).
    1.19 +#
    1.20 +# You should have received a copy of the GNU General Public License version
    1.21 +# 2 along with this work; if not, write to the Free Software Foundation,
    1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 +#
    1.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 +# or visit www.oracle.com if you need additional information or have any
    1.26 +# questions.
    1.27 +#
    1.28 +
    1.29 +# Copyright year for beginning of Java and some of the apis
    1.30 +#   (Needed when creating the javadocs)
    1.31 +FIRST_COPYRIGHT_YEAR                = 1993
    1.32 +DOMAPI_FIRST_COPYRIGHT_YEAR         = 2005
    1.33 +MIRROR_FIRST_COPYRIGHT_YEAR         = 2004
    1.34 +DOCLETAPI_FIRST_COPYRIGHT_YEAR      = 1993
    1.35 +TAGLETAPI_FIRST_COPYRIGHT_YEAR      = 1993
    1.36 +JDI_FIRST_COPYRIGHT_YEAR            = 1999
    1.37 +JAAS_FIRST_COPYRIGHT_YEAR           = 1998
    1.38 +JGSS_FIRST_COPYRIGHT_YEAR           = 2000
    1.39 +SMARTCARDIO_FIRST_COPYRIGHT_YEAR    = 2005
    1.40 +HTTPSERVER_FIRST_COPYRIGHT_YEAR     = 2005
    1.41 +MGMT_FIRST_COPYRIGHT_YEAR           = 2003
    1.42 +ATTACH_FIRST_COPYRIGHT_YEAR         = 2005
    1.43 +JCONSOLE_FIRST_COPYRIGHT_YEAR       = 2006
    1.44 +SCTPAPI_FIRST_COPYRIGHT_YEAR        = 2009
    1.45 +TRACING_FIRST_COPYRIGHT_YEAR        = 2008
    1.46 +TREEAPI_FIRST_COPYRIGHT_YEAR        = 2005
    1.47 +JNLP_FIRST_COPYRIGHT_YEAR           = 1998
    1.48 +PLUGIN2_FIRST_COPYRIGHT_YEAR        = 2007
    1.49 +
    1.50 +# Oracle name
    1.51 +COMPANY_NAME = Oracle and/or its affiliates
    1.52 +
    1.53 +# Copyright address
    1.54 +COMPANY_ADDRESS = 500 Oracle Parkway<br>Redwood Shores, CA 94065 USA.
    1.55 +
    1.56 +# The trademark symbol
    1.57 +TRADEMARK = &trade;
    1.58 +
    1.59 +# Common copyright lines used
    1.60 +#   The word "Copyright" might optionally be a link to the file cpyr.html.
    1.61 +#   The first year of copyright may vary or not be available.
    1.62 +#   The address to the company might be optional.
    1.63 +COMMA:= ,
    1.64 +EMPTY:=
    1.65 +SPACE:=$(EMPTY) $(EMPTY)
    1.66 +COPYRIGHT_SYMBOL = &\#x00a9;
    1.67 +# Macros to handle the optional empty args.
    1.68 +#   (The GNU make 3.78.1 "if" conditional is broken, fixed in GNU make 3.81)
    1.69 +define OptionalCopyrightUrl # url
    1.70 +$(shell \
    1.71 +  if [ "$1" != "" ] ; then \
    1.72 +    printf "<a href=\"%s\">Copyright</a>" "$1"; \
    1.73 +  else \
    1.74 +    printf "Copyright"; \
    1.75 +  fi)
    1.76 +endef
    1.77 +define OptionalCopyrightFirstYear # year
    1.78 +$(shell \
    1.79 +  if [ "$1" != "" ] ; then \
    1.80 +    printf "%s," "$1";\
    1.81 +  fi)
    1.82 +endef
    1.83 +define OptionalCompanyAddress # address
    1.84 +$(shell \
    1.85 +  if [ "$1" != "" ] ; then \
    1.86 +    printf "%s" "$1";\
    1.87 +  fi)
    1.88 +endef
    1.89 +define CopyrightLine # optionalurl optionalfirstyear optionaladdress
    1.90 +$(call OptionalCopyrightUrl,$1) $(COPYRIGHT_SYMBOL)\
    1.91 +$(call OptionalCopyrightFirstYear,$2) $(COPYRIGHT_YEAR),\
    1.92 +$(COMPANY_NAME).\
    1.93 +$(call OptionalCompanyAddress,$3)\
    1.94 +All rights reserved.
    1.95 +endef
    1.96 +
     2.1 --- a/make/common/shared/Defs-windows.gmk	Thu Jul 15 20:11:45 2010 -0700
     2.2 +++ b/make/common/shared/Defs-windows.gmk	Tue Jul 20 22:21:31 2010 -0700
     2.3 @@ -230,7 +230,8 @@
     2.4  
     2.5  # Compilers, SDK, and Visual Studio (MSDEV) [32bit is different from 64bit]
     2.6  ifeq ($(ARCH_DATA_MODEL), 32)
     2.7 -  # Try looking in MSVCDIR or MSVCDir area first (set by vcvars32.bat)
     2.8 +  # Try looking in MSVCDIR or MSVCDir area first 
     2.9 +  # (set by vcvars32.bat for VC .NET, not defined in the VC 2008/2010)
    2.10    ifdef MSVCDIR
    2.11      xMSVCDIR  :="$(subst \,/,$(MSVCDIR))"
    2.12      _msvc_dir :=$(call FullPath,$(xMSVCDIR))
    2.13 @@ -238,11 +239,6 @@
    2.14      ifdef MSVCDir
    2.15        xMSVCDIR  :="$(subst \,/,$(MSVCDir))"
    2.16        _msvc_dir :=$(call FullPath,$(xMSVCDIR))
    2.17 -    else
    2.18 -      ifneq ($(_program_files),)
    2.19 -        xMSVCDIR  :="$(_program_files)/Microsoft Visual Studio .NET 2003/Vc7"
    2.20 -        _msvc_dir :=$(call FullPath,$(xMSVCDIR))
    2.21 -      endif
    2.22      endif
    2.23    endif
    2.24    # If we still don't have it, look for VSnnCOMNTOOLS (newest first),
     3.1 --- a/make/docs/Makefile	Thu Jul 15 20:11:45 2010 -0700
     3.2 +++ b/make/docs/Makefile	Tue Jul 20 22:21:31 2010 -0700
     3.3 @@ -1,5 +1,4 @@
     3.4 -#
     3.5 -# Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
     3.6 +# Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     3.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8  #
     3.9  # This code is free software; you can redistribute it and/or modify it
    3.10 @@ -30,6 +29,41 @@
    3.11  PRODUCT=docs
    3.12  include $(BUILDDIR)/common/Defs.gmk
    3.13  
    3.14 +# Get CopyrightLine macro and other shared variables
    3.15 +include $(BUILDDIR)/common/shared/Defs-javadoc.gmk
    3.16 +
    3.17 +# Url to root of documents
    3.18 +DOCSDIR_URL = {@docroot}/$(GET2DOCSDIR)
    3.19 +
    3.20 +# Url to copyright html file
    3.21 +COPYRIGHT_URL-7 = $(DOCSDIR_URL)/legal/cpyr.html
    3.22 +COPYRIGHT_URL = $(COPYRIGHT_URL-$(JDK_MINOR_VERSION))
    3.23 +
    3.24 +# Url to bug filing site
    3.25 +BUG_SUBMIT_URL = http://bugs.sun.com/services/bugreport/index.jsp
    3.26 +
    3.27 +# Common line for how to submit a bug or rfe
    3.28 +BUG_SUBMIT_LINE = <a href=\"$(BUG_SUBMIT_URL)\">Submit a bug or feature</a>
    3.29 +
    3.30 +# Url to devdocs page
    3.31 +#   Was: http://java.sun.com/javase/6/webnotes/devdocs-vs-specs.html
    3.32 +DEV_DOCS_URL-5 = http://java.sun.com/j2se/1.5.0/docs
    3.33 +DEV_DOCS_URL-6 = http://download.oracle.com/docs/cd/E17409_01/javase/6/docs
    3.34 +DEV_DOCS_URL-7 = http://download.oracle.com/docs/cd/E17409_01/javase/7/docs
    3.35 +DEV_DOCS_URL = $(DEV_DOCS_URL-$(JDK_MINOR_VERSION))
    3.36 +
    3.37 +# Url to Java Language Spec
    3.38 +JLS3_URL = http://java.sun.com/docs/books/jls/
    3.39 +
    3.40 +# Common Java trademark line
    3.41 +JAVA_TRADEMARK_LINE = Java is a trademark or registered trademark of \
    3.42 +$(COMPANY_NAME) in the US and other countries.
    3.43 +
    3.44 +#
    3.45 +# Definitions for imported components
    3.46 +#
    3.47 +include $(BUILDDIR)/common/internal/ImportComponents.gmk
    3.48 +
    3.49  # We override whatever the max VM memory setting is here.
    3.50  #    NOTE: javadoc will not complete without these larger settings.
    3.51  #    WARNING: This could cause thrashing on low memory machines.
    3.52 @@ -39,418 +73,155 @@
    3.53    MAX_VM_MEMORY = 512
    3.54  endif
    3.55  
    3.56 +# List of all possible directories for javadoc to look for sources
    3.57 +#    NOTE: Quotes are required around sourcepath argument only on Windows.
    3.58 +#          Otherwise, you get "No packages or classes specified." due 
    3.59 +#          to $(CLASSPATH_SEPARATOR) being interpreted as an end of 
    3.60 +#          command (newline or shell ; character)
    3.61 +ALL_SOURCE_DIRS = $(SHARE_SRC)/classes \
    3.62 +                  $(IMPORTSRCDIR) \
    3.63 +                  $(GENSRCDIR) \
    3.64 +                  $(SHARE_SRC)/../solaris/classes \
    3.65 +	          $(SHARE_SRC)/../windows/classes \
    3.66 +		  $(SHARE_SRC)/doc/stub
    3.67 +EMPTY:=
    3.68 +SPACE:= $(EMPTY) $(EMPTY)
    3.69 +RELEASEDOCS_SOURCEPATH = \
    3.70 +    $(subst $(SPACE),$(CLASSPATH_SEPARATOR),$(strip $(ALL_SOURCE_DIRS)))
    3.71 +
    3.72 +# Prep for javadoc creation, assumes $@ is an index.html file
    3.73 +define prep-javadoc
    3.74 +@if [ -f "$@" -a "$?" != "" ] ; then \
    3.75 +  $(ECHO) "# Dependencies have changed: $?"; \
    3.76 +fi
    3.77 +$(RM) -r $(@D)
    3.78 +$(MKDIR) -p $(@D)
    3.79 +endef
    3.80 +
    3.81 +# A cache of the directories in ALL_SOURCE_DIRS
    3.82 +DIRECTORY_CACHE = $(DOCSTMPDIR)/directory.cache
    3.83 +
    3.84 +# Given a list of packages, return a list of files or dirs to be dependent on
    3.85 +#   (Currently only returning a list of directories)
    3.86 +define PackageDependencies # packages
    3.87 +$(shell							\
    3.88 +  if [ "$1" != "" -a -f $(DIRECTORY_CACHE) ] ; then	\
    3.89 +    for p in $1 ; do 					\
    3.90 +      pd=`$(ECHO) $${p} | $(SED) -e 's@[.]@/@g'`;	\
    3.91 +      $(CAT) $(DIRECTORY_CACHE) | $(GREP) "/$${pd}/" ; 	\
    3.92 +    done; 						\
    3.93 +  fi							\
    3.94 +)
    3.95 +endef
    3.96 +
    3.97 +# Given a list of packages, add packages that exist to $@, print summary
    3.98 +define PackageFilter # packages
    3.99 +@if [ "$1" != "" ] ; then 				\
   3.100 +  for p in $1 ; do 					\
   3.101 +    pd=`$(ECHO) $${p} | $(SED) -e 's@[.]@/@g'`; 	\
   3.102 +    found="false"; 					\
   3.103 +    for cp in $(ALL_SOURCE_DIRS) ; do 			\
   3.104 +      if [ -d $${cp}/$${pd} ] ; then 			\
   3.105 +        $(ECHO) "$${p}" >> $@; 				\
   3.106 +	found="true";					\
   3.107 +	break; 						\
   3.108 +      fi; 						\
   3.109 +    done; 						\
   3.110 +    if [ "$${found}" = "false" ] ; then 		\
   3.111 +      $(ECHO) "WARNING: Package not found: $${p}"; 	\
   3.112 +    fi; 						\
   3.113 +  done; 						\
   3.114 +fi
   3.115 +endef
   3.116 +
   3.117 +# Print out a summary of the javadoc command about to be run
   3.118 +define JavadocSummary # optionsfile packagesfile
   3.119 +@$(ECHO) "# Summary for $@";\
   3.120 + $(ECHO) "# Options (`$(BASENAME) $1`):"; $(SED) -e 's@^@#   @' $1; \
   3.121 + $(ECHO) "# Packages (`$(BASENAME) $2`):";$(SED) -e 's@^@#   @' $2
   3.122 +endef
   3.123 +
   3.124  #
   3.125 -# Variables used by docs target
   3.126 +# Temporary directory for javadoc creation
   3.127  #
   3.128 -DOCSTMPDIR          = $(TEMPDIR)/doctmp
   3.129 +DOCSTMPDIR = $(TEMPDIR)/doctmp
   3.130  
   3.131 +#
   3.132 +# Different api directories created from root directory
   3.133 +#
   3.134 +COREAPI_DOCSDIR   = $(DOCSDIR)/api
   3.135 +JDK_API_DOCSDIR   = $(DOCSDIR)/jdk/api
   3.136 +JRE_API_DOCSDIR   = $(DOCSDIR)/jre/api
   3.137 +PLATFORM_DOCSDIR  = $(DOCSDIR)/platform
   3.138 +
   3.139 +# The non-core api javadocs need to be able to access the root of the core
   3.140 +#   api directory, so for jdk/api or jre/api to get to the core api/
   3.141 +#   directory we would use this:
   3.142 +JDKJRE2COREAPI    = ../../api
   3.143 +
   3.144 +# Common bottom argument
   3.145 +define CommonBottom # year
   3.146 +<font size=\"-1\"><p> $(call CopyrightLine,,$1,)</font>
   3.147 +endef
   3.148 +
   3.149 +# Common trademark bottom argument (Not sure why this is used sometimes)
   3.150 +define CommonTrademarkBottom # year
   3.151 +<font size=\"-1\">\
   3.152 +$(BUG_SUBMIT_LINE)<br>$(JAVA_TRADEMARK_LINE)<br>\
   3.153 +$(call CopyrightLine,,$1,$(COMPANY_ADDRESS))\
   3.154 +</font>
   3.155 +endef
   3.156 +
   3.157 +# Core api bottom argument (with special sauce)
   3.158 +COREAPI_BOTTOM = <font size=\"-1\"> $(BUG_SUBMIT_LINE)\
   3.159 +<br>For further API reference and developer documentation, \
   3.160 +see <a href=\"$(DEV_DOCS_URL)\" target=\"_blank\">Java SE Documentation</a>. \
   3.161 +That documentation contains more detailed, developer-targeted descriptions, \
   3.162 +with conceptual overviews, definitions of terms, workarounds, \
   3.163 +and working code examples.<p>\
   3.164 +$(call CopyrightLine,$(COPYRIGHT_URL),$(FIRST_COPYRIGHT_YEAR),)\
   3.165 +</font>
   3.166 +
   3.167 +# Common javadoc options used by all
   3.168  COMMON_JAVADOCFLAGS =					\
   3.169 -		$(NO_PROPRIETARY_API_WARNINGS)		\
   3.170 +                $(NO_PROPRIETARY_API_WARNINGS)          \
   3.171  		-source 1.5				\
   3.172  		-quiet					\
   3.173                  -use					\
   3.174                  -keywords				\
   3.175 -		$(JAVADOC_VM_MEMORY_FLAGS)		\
   3.176  		$(ADDITIONAL_JAVADOCFLAGS)
   3.177  ADDITIONAL_JAVADOCFLAGS =
   3.178  
   3.179 -CORE_JAVADOCFLAGS  = $(COMMON_JAVADOCFLAGS)		\
   3.180 -		$(TAGS)					\
   3.181 -		-encoding ISO-8859-1			\
   3.182 -		-splitIndex				\
   3.183 -		-doctitle $(DOCTITLE_SWITCH)		\
   3.184 -		-windowtitle $(WINDOWTITLE_SWITCH)	\
   3.185 -		-header $(HEADER_SWITCH)		\
   3.186 -		$(TOPOPTION) 				\
   3.187 -		-bottom $(JAVADOCBOTTOM_SWITCH)		\
   3.188 -		$(OVERVIEW_OPTION)
   3.189 -
   3.190 -DRAFT = '<br><strong>DRAFT&nbsp;'$(MILESTONE)-$(BUILD_NUMBER)'</strong>'
   3.191 -THIS_YEAR := $(shell $(DATE) | $(SED) -e 's/  / /g' | $(CUT) -d' ' -f6)
   3.192 -TRADEMARK = &\#x2122;
   3.193 -
   3.194 -IGNORED_TAGS =	beaninfo revised since.unbundled spec specdefault Note ToDo
   3.195 -
   3.196 -JLS3_URL = http://java.sun.com/docs/books/jls/
   3.197 -JLS3_CITE = <a href="$(JLS3_URL)"> \
   3.198 -		The Java Language Specification, Third Edition</a>
   3.199 -TAG_JLS3 = -tag 'jls3:a:See <cite>$(JLS3_CITE)</cite>:'
   3.200 -
   3.201 -TAGS = $(IGNORED_TAGS:%=-tag %:X) $(TAG_JLS3)
   3.202 -
   3.203 -ifeq ($(MILESTONE), fcs)
   3.204 -    DOCTITLE_SWITCH = $(JAVADOCTITLE)
   3.205 -    WINDOWTITLE_SWITCH = $(JAVADOCWINDOWTITLE)
   3.206 -    HEADER_SWITCH = $(JAVADOCHEADER)
   3.207 -    TOPOPTION=
   3.208 -    JAVADOCBOTTOM_SWITCH= $(JAVADOCBOTTOM)
   3.209 -    OVERVIEW_OPTION = -overview $(JAVADOCOVERVIEW)
   3.210 -else
   3.211 -    DOCTITLE_SWITCH = $(JAVADOCTITLE_EARLYACCESS)$(DRAFT)
   3.212 -    WINDOWTITLE_SWITCH = $(JAVADOCWINDOWTITLE)" $(BUILD_NUMBER)"
   3.213 -    HEADER_SWITCH = $(JAVADOCHEADER)$(DRAFT)
   3.214 -    JAVADOCBOTTOM_SWITCH= $(JAVADOCBOTTOM_EARLYACCESS)
   3.215 -    TOPOPTION= -top $(JAVADOCTOP_EARLYACCESS)
   3.216 -    OVERVIEW_OPTION =
   3.217 +# Draft used for non-fcs documents
   3.218 +JDK_IS_FCS = false
   3.219 +DRAFT_HEADER =
   3.220 +ifeq ($(JDK_MINOR_VERSION),5)
   3.221 +  JDK_IS_FCS = true
   3.222 +endif
   3.223 +ifeq ($(JDK_MINOR_VERSION),6)
   3.224 +  JDK_IS_FCS = true
   3.225 +endif
   3.226 +ifeq ($(JDK_IS_FCS),false)
   3.227 +  ifneq ($(MILESTONE), fcs)
   3.228 +    DRAFT_HEADER = <br><strong>DRAFT&nbsp;$(MILESTONE)-$(BUILD_NUMBER)</strong>
   3.229 +    DRAFT_BOTTOM = <br><strong>DRAFT&nbsp;$(MILESTONE)-$(BUILD_NUMBER)</strong>
   3.230 +    DRAFT_WINTITLE = $(BUILD_NUMBER)
   3.231 +    # Early access top text (not used in FCS releases)
   3.232 +    COREAPI_TOP_EARLYACCESS = \
   3.233 +<div style=\"background-color: \#EEEEEE\"> \
   3.234 +<div style=\"padding: 6px; margin-top: 2px; margin-bottom: 6px; \
   3.235 +margin-left: 6px; margin-right: 6px; text-align: justify; \
   3.236 +font-size: 80%; font-family: Helvetica, Arial, sans-serif; \
   3.237 +font-weight: normal;\"> \
   3.238 +Please note that the specifications and other information \
   3.239 +contained herein are not final and are subject to change. \
   3.240 +The information is being made available to you solely for purpose of \
   3.241 +evaluation. \
   3.242 +</div> </div>
   3.243 +  endif
   3.244  endif
   3.245  
   3.246 -JAVADOCTITLE  = 'Java$(TRADEMARK) Platform, Standard Edition $(JDK_MINOR_VERSION)<br>API Specification'
   3.247 -JAVADOCWINDOWTITLE  = 'Java Platform SE $(JDK_MINOR_VERSION)'
   3.248 -JAVADOCHEADER = '<strong>Java$(TRADEMARK)&nbsp;Platform<br>Standard&nbsp;Ed.&nbsp;$(JDK_MINOR_VERSION)</strong>'
   3.249 -JAVADOCBOTTOM = '<font size="-1"><a href="http://bugs.sun.com/services/bugreport/index.jsp">Submit a bug or feature</a><br>For further API reference and developer documentation, see <a href="{@docroot}/../../webnotes/devdocs-vs-specs.html">Java SE Developer Documentation</a>. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. <p>Copyright $(THIS_YEAR) Sun Microsystems, Inc. All Rights Reserved. Use is subject to <a href="{@docroot}/../legal/license.html">license terms</a>. Also see the <a href="http://java.sun.com/docs/redist.html">documentation redistribution policy</a>.</font>'
   3.250 -JAVADOCOVERVIEW = $(SHARE_SRC)/classes/overview-core.html
   3.251 -
   3.252 -#
   3.253 -# Early access top and bottom text (for snapshots, beta and rc)
   3.254 -#
   3.255 -JAVADOCTOP_EARLYACCESS = '<div style="background-color: \#EEEEEE"> <div style="padding: 6px; margin-top: 2px; margin-bottom: 6px; margin-left: 6px; margin-right: 6px; text-align: justify; font-size: 80%; font-family: Helvetica, Arial, sans-serif; font-weight: normal;"> Please note that this documentation is not final and is subject to change. </div> </div>'
   3.256 -JAVADOCBOTTOM_EARLYACCESS = '<font size="-1"><a href="http://bugs.sun.com/services/bugreport/index.jsp">Submit a bug or feature</a> <p>Copyright $(THIS_YEAR) Sun Microsystems, Inc. All Rights Reserved. Use is subject to <a href="{@docroot}/../legal/license.html">license terms</a>.</font>'
   3.257 -JAVADOCTITLE_EARLYACCESS = $(subst Specification,Documentation,$(JAVADOCTITLE))
   3.258 -
   3.259 -#
   3.260 -# Variables used by domapidocs target
   3.261 -#
   3.262 -
   3.263 -DOMAPI_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)		      \
   3.264 -		    -encoding ascii			      \
   3.265 -                    -splitIndex                               \
   3.266 -                    -doctitle $(DOMAPI_JAVADOCTITLE)          \
   3.267 -                    -windowtitle $(DOMAPI_JAVADOCWINDOWTITLE) \
   3.268 -                    -header $(DOMAPI_JAVADOCHEADER)           \
   3.269 -                    -bottom $(DOMAPI_JAVADOCBOTTOM)           \
   3.270 -                    -group $(DOMAPI_GROUPNAME) $(DOMAPI_REGEXP)
   3.271 -DOMAPI_JAVADOCTITLE  = 'Common DOM API'
   3.272 -DOMAPI_JAVADOCWINDOWTITLE  = 'Common DOM API'
   3.273 -DOMAPI_JAVADOCHEADER = '<strong>Common DOM API</strong>'
   3.274 -DOMAPI_JAVADOCBOTTOM = '<font size="-1"><a href="http://bugs.sun.com/services/bugreport/index.jsp">Submit a bug or feature</a><br>Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.<br>Copyright $(THIS_YEAR) Sun Microsystems, Inc. 4150 Network Circle<br>Santa Clara, California, 95054, U.S.A.  All Rights Reserved.</font>'
   3.275 -DOMAPI_GROUPNAME = "Packages"
   3.276 -DOMAPI_REGEXP = "com.sun.java.browser.dom:org.w3c.dom*"
   3.277 -# DOMAPI_PKGS is located in NON_CORE_PKGS.gmk
   3.278 -
   3.279 -#
   3.280 -# Variables used by mirrordocs target
   3.281 -#
   3.282 -
   3.283 -MIRROR_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)		        \
   3.284 -                    -encoding ascii			        \
   3.285 -                    -doctitle $(MIRROR_JAVADOCTITLE)            \
   3.286 -                    -windowtitle $(MIRROR_JAVADOCWINDOWTITLE)   \
   3.287 -                    -header $(MIRROR_JAVADOCHEADER)             \
   3.288 -                    -bottom $(MIRROR_JAVADOCBOTTOM)             \
   3.289 -                    -group $(MIRROR_GROUPNAME) $(MIRROR_REGEXP) \
   3.290 -                    -overview $(MIRROR_OVERVIEW)
   3.291 -MIRROR_JAVADOCTITLE = 'Mirror API'
   3.292 -MIRROR_JAVADOCWINDOWTITLE = 'Mirror API'
   3.293 -MIRROR_JAVADOCHEADER = '<strong>Mirror API</strong>'
   3.294 -MIRROR_JAVADOCBOTTOM = '<font size="-1"><a href="http://bugs.sun.com/services/bugreport/index.jsp">Report a bug or request a feature.</a><br>Copyright $(THIS_YEAR) Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.</font>'
   3.295 -MIRROR_GROUPNAME = "Packages"
   3.296 -MIRROR_OVERVIEW = $(IMPORTSRCDIR)/com/sun/mirror/overview.html
   3.297 -MIRROR_REGEXP = "com.sun.mirror.*"
   3.298 -MIRROR_DESTDIR = $(DOCSDIR)/jdk/api/apt/mirror
   3.299 -MIRROR_LINKOPT = -linkoffline ../../../../api $(DOCSDIR)/api/
   3.300 -# MIRROR_PKGS is located in NON_CORE_PKGS.gmk
   3.301 -
   3.302 -#
   3.303 -# Variables used by docletapidocs target
   3.304 -#
   3.305 -
   3.306 -DOCLETAPI_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)			 \
   3.307 -		    -breakiterator				 \
   3.308 -		    -encoding ascii			         \
   3.309 -                    -doctitle $(DOCLETAPI_JAVADOCTITLE)          \
   3.310 -                    -windowtitle $(DOCLETAPI_JAVADOCWINDOWTITLE) \
   3.311 -                    -header $(DOCLETAPI_JAVADOCHEADER)           \
   3.312 -                    -bottom $(DOCLETAPI_JAVADOCBOTTOM)           \
   3.313 -                    -group $(DOCLETAPI_GROUPNAME) $(DOCLETAPI_REGEXP)
   3.314 -DOCLETAPI_JAVADOCTITLE  = 'Doclet API'
   3.315 -DOCLETAPI_JAVADOCWINDOWTITLE  = 'Doclet API'
   3.316 -DOCLETAPI_JAVADOCHEADER = '<strong>Doclet API</strong>'
   3.317 -DOCLETAPI_JAVADOCBOTTOM = '<font size="-1"><a href="http://bugs.sun.com/services/bugreport/index.jsp">Submit a bug or feature</a><br>Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.<br>Copyright 1993-$(THIS_YEAR) Sun Microsystems, Inc. 4150 Network Circle<br>Santa Clara, California, 95054, U.S.A.  All Rights Reserved.</font>'
   3.318 -DOCLETAPI_GROUPNAME = "Packages"
   3.319 -DOCLETAPI_REGEXP = "com.sun.javadoc"
   3.320 -DOCLETAPI_LINKOPT = -linkoffline ../../../../api $(DOCSDIR)/api/
   3.321 -# DOCLETAPI_PKGS is located in NON_CORE_PKGS.gmk
   3.322 -
   3.323 -#
   3.324 -# Variables used by tagletapidocs target
   3.325 -#
   3.326 -
   3.327 -TAGLETAPI_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)			\
   3.328 -		    -encoding ascii			        \
   3.329 -                    -nonavbar                                   \
   3.330 -                    -noindex                                    \
   3.331 -                    -bottom $(TAGLETAPI_JAVADOCBOTTOM)
   3.332 -TAGLETAPI_JAVADOCBOTTOM = '<font size="-1"><a href="http://bugs.sun.com/services/bugreport/index.jsp">Submit a bug or feature</a><br>Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.<br>Copyright 1993-$(THIS_YEAR) Sun Microsystems, Inc. 4150 Network Circle<br>Santa Clara, California, 95054, U.S.A.  All Rights Reserved.</font>'
   3.333 -# TAGLETAPI_FILE is located in NON_CORE_PKGS.gmk
   3.334 -
   3.335 -#
   3.336 -# Variables used by jdi target
   3.337 -#
   3.338 -
   3.339 -JPDA_SOURCEPATH  = $(TOPDIR)/src/share/classes
   3.340 -
   3.341 -JDI_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)			 \
   3.342 -		   -encoding ascii			         \
   3.343 -                   -nodeprecatedlist                             \
   3.344 -                   -d $(DOCSDIR)/jdk/api/jpda/jdi                  \
   3.345 -                   -sourcepath $(JPDA_SOURCEPATH)                \
   3.346 -                   -windowtitle $(JDI_WINDOWTITLE)               \
   3.347 -                   -doctitle $(JDI_DOCTITLE)                     \
   3.348 -                   -header $(JDI_HEADER)                         \
   3.349 -                   -linkoffline ../../../../api $(DOCSDIR)/api/     \
   3.350 -                   -overview $(JPDA_SOURCEPATH)/jdi-overview.html
   3.351 -JDI_WINDOWTITLE = "Java Debug Interface"
   3.352 -JDI_DOCTITLE    = "Java$(TRADEMARK) Debug Interface"
   3.353 -JDI_HEADER      = "Java Debug Interface"
   3.354 -# JDI_PKGS is located in NON_CORE_PKGS.gmk
   3.355 -
   3.356 -# Variables used by security components
   3.357 -SECURITYAPI_JAVADOCBOTTOM = '<font size="-1"><a href="http://bugs.sun.com/services/bugreport/index.jsp">Report a bug or request a feature.</a><br>Copyright $(THIS_YEAR) Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.</font>'
   3.358 -
   3.359 -#
   3.360 -# Variables used by JAAS target
   3.361 -#
   3.362 -# NOTE: Quotes are required around sourcepath argument only on Windows.  Otherwise,
   3.363 -#       you get "No packages or classes specified." due to $(CLASSPATH_SEPARATOR)
   3.364 -#       being interpreted as an end of command (newline)
   3.365 -
   3.366 -JAAS_SOURCEPATH  = "$(TOPDIR)/src/share/classes$(CLASSPATH_SEPARATOR)$(TOPDIR)/src/solaris/classes$(CLASSPATH_SEPARATOR)$(TOPDIR)/src/windows/classes$(CLASSPATH_SEPARATOR)$(TOPDIR)/src/linux/classes"
   3.367 -JAAS_DOCDIR	 = $(DOCSDIR)/jre/api/security/jaas/spec
   3.368 -JAAS_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)			 \
   3.369 -		   -encoding ascii			         \
   3.370 -                   -nodeprecatedlist                             \
   3.371 -                   -d $(JAAS_DOCDIR)				 \
   3.372 -                   -sourcepath $(JAAS_SOURCEPATH)                \
   3.373 -                   -windowtitle $(JAAS_WINDOWTITLE)              \
   3.374 -                   -doctitle $(JAAS_DOCTITLE)                    \
   3.375 -                   -header $(JAAS_JAVADOCHEADER)                 \
   3.376 -                   -bottom $(SECURITYAPI_JAVADOCBOTTOM)                      \
   3.377 -                   -linkoffline ../../../../../api $(DOCSDIR)/api/	 \
   3.378 -                   -overview $(TOPDIR)/src/share/classes/com/sun/security/auth/jaas-overview.html
   3.379 -JAAS_WINDOWTITLE = "Java Authentication and Authorization Service "
   3.380 -JAAS_DOCTITLE    = "Java$(TRADEMARK) Authentication and Authorization Service"
   3.381 -JAAS_JAVADOCHEADER      = "JAAS"
   3.382 -# JAAS_PKGS is located in NON_CORE_PKGS.gmk
   3.383 -
   3.384 -#
   3.385 -# Variables used by JGSS target
   3.386 -#
   3.387 -
   3.388 -JGSS_SOURCEPATH  = $(TOPDIR)/src/share/classes
   3.389 -JGSS_DOCDIR	 = $(DOCSDIR)/jre/api/security/jgss/spec
   3.390 -
   3.391 -JGSS_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)			\
   3.392 -		   -encoding ascii			        \
   3.393 -                   -nodeprecatedlist                            \
   3.394 -                   -d $(JGSS_DOCDIR)				\
   3.395 -                   -sourcepath $(JGSS_SOURCEPATH)               \
   3.396 -                   -windowtitle $(JGSS_WINDOWTITLE)             \
   3.397 -                   -doctitle $(JGSS_DOCTITLE)                   \
   3.398 -                   -header $(JGSS_JAVADOCHEADER)                \
   3.399 -                   -bottom $(SECURITYAPI_JAVADOCBOTTOM)                      \
   3.400 -                   -linkoffline ../../../../../api $(DOCSDIR)/api/ \
   3.401 -                   -overview $(JGSS_SOURCEPATH)/com/sun/security/jgss/jgss-overview.html
   3.402 -
   3.403 -JGSS_WINDOWTITLE = "Java GSS-API Utilities "
   3.404 -JGSS_DOCTITLE    = "Java$(TRADEMARK) GSS-API Utilities"
   3.405 -JGSS_JAVADOCHEADER      = "Java GSS-API Utilities"
   3.406 -# JGSS_PKGS is located in NON_CORE_PKGS.gmk
   3.407 -
   3.408 -#
   3.409 -# Variables used by SMARTCARDIO target
   3.410 -#
   3.411 -
   3.412 -SMARTCARDIO_SOURCEPATH  = $(TOPDIR)/src/share/classes
   3.413 -SMARTCARDIO_DOCDIR	 = $(DOCSDIR)/jre/api/security/smartcardio/spec
   3.414 -
   3.415 -SMARTCARDIO_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)			\
   3.416 -		   -encoding ascii			        \
   3.417 -                   -nodeprecatedlist                            \
   3.418 -                   -d $(SMARTCARDIO_DOCDIR)				\
   3.419 -                   -sourcepath $(SMARTCARDIO_SOURCEPATH)               \
   3.420 -                   -windowtitle $(SMARTCARDIO_WINDOWTITLE)             \
   3.421 -                   -doctitle $(SMARTCARDIO_DOCTITLE)                   \
   3.422 -                   -header $(SMARTCARDIO_JAVADOCHEADER)                \
   3.423 -                   -bottom $(SECURITYAPI_JAVADOCBOTTOM)                      \
   3.424 -                   -linkoffline ../../../../../api $(DOCSDIR)/api/
   3.425 -
   3.426 -SMARTCARDIO_WINDOWTITLE = "Java Smart Card I/O"
   3.427 -SMARTCARDIO_DOCTITLE    = "Java$(TRADEMARK) Smart Card I/O"
   3.428 -SMARTCARDIO_JAVADOCHEADER      = "Java Smart Card I/O"
   3.429 -# SMARTCARDIO_PKGS is located in NON_CORE_PKGS.gmk
   3.430 -
   3.431 -#
   3.432 -# Variables used by TRACING target
   3.433 -#
   3.434 -
   3.435 -TRACING_SOURCEPATH  = $(TOPDIR)/src/share/classes
   3.436 -TRACING_DOCDIR	 = $(DOCSDIR)/jre/api/tracing
   3.437 -
   3.438 -TRACING_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)			    \
   3.439 -		   -encoding ascii			            \
   3.440 -                   -nodeprecatedlist                                \
   3.441 -                   -d $(TRACING_DOCDIR)				    \
   3.442 -                   -sourcepath $(TRACING_SOURCEPATH)                \
   3.443 -                   -windowtitle $(TRACING_WINDOWTITLE)              \
   3.444 -                   -doctitle $(TRACING_DOCTITLE)                    \
   3.445 -                   -header $(TRACING_JAVADOCHEADER)                 \
   3.446 -                   -linkoffline ../../../../../api $(DOCSDIR)/api/
   3.447 -
   3.448 -TRACING_WINDOWTITLE = "Tracing"
   3.449 -TRACING_DOCTITLE    = "Java$(TRADEMARK) Platform Tracing"
   3.450 -TRACING_JAVADOCHEADER      = "Platform Tracing"
   3.451 -# TRACING_PKGS is located in NON_CORE_PKGS.gmk
   3.452 -
   3.453 -#
   3.454 -# Variables used by HTTPSERVER target
   3.455 -#
   3.456 -
   3.457 -HTTPSERVER_SOURCEPATH  = $(TOPDIR)/src/share/classes
   3.458 -HTTPSERVER_DOCDIR	 = $(DOCSDIR)/jre/api/net/httpserver/spec
   3.459 -
   3.460 -HTTPSERVER_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)			\
   3.461 -		   -encoding ascii			        \
   3.462 -                   -nodeprecatedlist                            \
   3.463 -                   -d $(HTTPSERVER_DOCDIR)				\
   3.464 -                   -sourcepath $(HTTPSERVER_SOURCEPATH)               \
   3.465 -                   -windowtitle $(HTTPSERVER_WINDOWTITLE)             \
   3.466 -                   -doctitle $(HTTPSERVER_DOCTITLE)                   \
   3.467 -                   -header $(HTTPSERVER_JAVADOCHEADER)                \
   3.468 -                   -linkoffline ../../../../../api $(DOCSDIR)/api/
   3.469 -
   3.470 -HTTPSERVER_WINDOWTITLE = "Java HTTP Server"
   3.471 -HTTPSERVER_DOCTITLE    = "Java$(TRADEMARK) HTTP Server"
   3.472 -HTTPSERVER_JAVADOCHEADER      = "Java HTTP Server"
   3.473 -# HTTPSERVER_PKGS is located in NON_CORE_PKGS.gmk
   3.474 -
   3.475 -#
   3.476 -# Variables used by sctp target
   3.477 -#
   3.478 -
   3.479 -SCTPAPI_SOURCEPATH  = $(TOPDIR)/src/share/classes
   3.480 -SCTPAPI_DOCDIR   = $(DOCSDIR)/jre/api/nio/sctp/spec
   3.481 -
   3.482 -SCTPAPI_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)                           \
   3.483 -                   -encoding ascii                                      \
   3.484 -                   -nodeprecatedlist                                    \
   3.485 -                   -d $(SCTPAPI_DOCDIR)                                 \
   3.486 -                   -sourcepath $(SCTPAPI_SOURCEPATH)                    \
   3.487 -                   -windowtitle $(SCTPAPI_WINDOWTITLE)                  \
   3.488 -                   -doctitle $(SCTPAPI_DOCTITLE)                        \
   3.489 -                   -header $(SCTPAPI_JAVADOCHEADER)                     \
   3.490 -                   -bottom $(SCTPAPI_JAVADOCBOTTOM)			\
   3.491 -                   -linkoffline ../../../../../api $(DOCSDIR)/api/
   3.492 -
   3.493 -SCTPAPI_WINDOWTITLE = "SCTP API"
   3.494 -SCTPAPI_DOCTITLE    = "SCTP API"
   3.495 -SCTPAPI_JAVADOCHEADER      = "SCTP API"
   3.496 -SCTPAPI_JAVADOCBOTTOM = '<font size="-1"><a href="http://bugs.sun.com/services/bugreport/index.jsp">Report a bug or request a feature.</a><br>Copyright $(THIS_YEAR) Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.</font>'
   3.497 -# SCTPAPI_PKGS is located in NON_CORE_PKGS.gmk
   3.498 -
   3.499 -#
   3.500 -# Variables used by jvmti target
   3.501 -#
   3.502 -JVMTI_DOCS_SUBDIR = platform/jvmti
   3.503 -JVMTI_HTML        = $(HOTSPOT_DOCS_IMPORT_PATH)/$(JVMTI_DOCS_SUBDIR)/jvmti.html
   3.504 -
   3.505 -#
   3.506 -# Variables used by mgmt target
   3.507 -#
   3.508 -MGMT_DOCDIR	   = $(DOCSDIR)/jre/api/management/
   3.509 -MGMT_EXT_DIR	   = $(MGMT_DOCDIR)/extension
   3.510 -MGMT_SOURCEPATH    = $(TOPDIR)/src/share/classes
   3.511 -JVM_MIB_NAME       = JVM-MANAGEMENT-MIB.mib
   3.512 -JVM_MIB_SRC        = $(CLOSED_SRC)/share/classes/sun/management/snmp/$(JVM_MIB_NAME)
   3.513 -
   3.514 -ifdef OPENJDK
   3.515 -   COPY-MIB-TARGET =
   3.516 -else
   3.517 -   COPY-MIB-TARGET = copy-mib
   3.518 -endif
   3.519 -MGMT_JAVADOCFLAGS  = $(COMMON_JAVADOCFLAGS)			   \
   3.520 -		     -encoding ascii			           \
   3.521 -                     -nodeprecatedlist                             \
   3.522 -                     -d $(MGMT_EXT_DIR) 		  	   \
   3.523 -                     -sourcepath $(MGMT_SOURCEPATH)                \
   3.524 -                     -windowtitle $(MGMT_WINDOWTITLE)              \
   3.525 -                     -doctitle $(MGMT_DOCTITLE)                    \
   3.526 -                     -header $(MGMT_HEADER)                        \
   3.527 -		     -linkoffline ../../../../api $(DOCSDIR)/api/  \
   3.528 -                     -overview $(MGMT_SOURCEPATH)/com/sun/management/mgmt-overview.html
   3.529 -MGMT_WINDOWTITLE = "Monitoring and Management Interface for the Java Platform"
   3.530 -MGMT_DOCTITLE    = "Monitoring and Management Interface for the Java$(TRADEMARK) Platform"
   3.531 -MGMT_HEADER      = "Monitoring and Management Interface for the Java Platform"
   3.532 -# MGMT_PKGS is located in NON_CORE_PKGS.gmk
   3.533 -
   3.534 -#
   3.535 -# Variables used by attach target
   3.536 -#
   3.537 -
   3.538 -ATTACH_SOURCEPATH  = $(TOPDIR)/src/share/classes
   3.539 -ATTACH_DOCDIR      = $(DOCSDIR)/jdk/api/attach/spec
   3.540 -ATTACH_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)                        	\
   3.541 -		   -encoding ascii                               	\
   3.542 -                   -nodeprecatedlist                             	\
   3.543 -		   -d $(ATTACH_DOCDIR)					\
   3.544 -                   -sourcepath $(ATTACH_SOURCEPATH)                	\
   3.545 -                   -windowtitle $(ATTACH_WINDOWTITLE)               	\
   3.546 -                   -doctitle $(ATTACH_DOCTITLE)                     	\
   3.547 -                   -header $(ATTACH_HEADER)                         	\
   3.548 -		   -linkoffline ../../../../api $(DOCSDIR)/api/
   3.549 -ATTACH_WINDOWTITLE = "Attach API"
   3.550 -ATTACH_DOCTITLE    = "Attach API"
   3.551 -ATTACH_HEADER      = "Attach API"
   3.552 -# ATTACH_PKGS is located in NON_CORE_PKGS.gmk
   3.553 -
   3.554 -#
   3.555 -# Variables used by jconsole target
   3.556 -#
   3.557 -
   3.558 -JCONSOLE_SOURCEPATH  = $(TOPDIR)/src/share/classes
   3.559 -JCONSOLE_DOCDIR      = $(DOCSDIR)/jdk/api/jconsole/spec
   3.560 -JCONSOLE_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)                        	\
   3.561 -		   -encoding ascii                               	\
   3.562 -                   -nodeprecatedlist                             	\
   3.563 -		   -d $(JCONSOLE_DOCDIR)				\
   3.564 -                   -sourcepath $(JCONSOLE_SOURCEPATH)                	\
   3.565 -                   -windowtitle $(JCONSOLE_WINDOWTITLE)               	\
   3.566 -                   -doctitle $(JCONSOLE_DOCTITLE)                     	\
   3.567 -                   -header $(JCONSOLE_HEADER)                         	\
   3.568 -		   -linkoffline ../../../../api $(DOCSDIR)/api/
   3.569 -JCONSOLE_WINDOWTITLE = "JConsole API"
   3.570 -JCONSOLE_DOCTITLE    = "JConsole API"
   3.571 -JCONSOLE_HEADER      = "JConsole API"
   3.572 -# JCONSOLE_PKGS is located in NON_CORE_PKGS.gmk
   3.573 -
   3.574 -#
   3.575 -# Variables used by treeapidocs target
   3.576 -#
   3.577 -
   3.578 -TREEAPI_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)		        \
   3.579 -                    -encoding ascii			        \
   3.580 -                    -doctitle $(TREEAPI_JAVADOCTITLE)            \
   3.581 -                    -windowtitle $(TREEAPI_JAVADOCWINDOWTITLE)   \
   3.582 -                    -header $(TREEAPI_JAVADOCHEADER)             \
   3.583 -                    -bottom $(TREEAPI_JAVADOCBOTTOM)             \
   3.584 -                    -group $(TREEAPI_GROUPNAME) $(TREEAPI_REGEXP) 
   3.585 -#
   3.586 -#	            -overview $(TREEAPI_OVERVIEW)
   3.587 -#
   3.588 -TREEAPI_JAVADOCTITLE = 'Compiler Tree API'
   3.589 -TREEAPI_JAVADOCWINDOWTITLE = 'Compiler Tree API'
   3.590 -TREEAPI_JAVADOCHEADER = '<strong>Compiler Tree API</strong>'
   3.591 -TREEAPI_JAVADOCBOTTOM = '<font size="-1"><a href="http://bugs.sun.com/services/bugreport/index.jsp">Report a bug or request a feature.</a><br>Copyright $(THIS_YEAR) Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.</font>'
   3.592 -TREEAPI_GROUPNAME = "Packages"
   3.593 -TREEAPI_OVERVIEW = $(SHARE_SRC)/classes/com/sun/source/overview.html
   3.594 -TREEAPI_REGEXP = "com.sun.source.*"
   3.595 -TREEAPI_DESTDIR = $(DOCSDIR)/jdk/api/javac/tree
   3.596 -TREEAPI_LINKOPT = -linkoffline ../../../../api $(DOCSDIR)/api/
   3.597 -# TREEAPI_PKGS is located in NON_CORE_PKGS.gmk
   3.598 -
   3.599 -#
   3.600 -# Path where javadoc should find source files for release docs
   3.601 -#
   3.602 -RELEASEDOCS_SRCPATH = "$(SHARE_SRC)/classes$(CLASSPATH_SEPARATOR)$(PLATFORM_SRC)/classes$(CLASSPATH_SEPARATOR)$(GENSRCDIR)$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/doc/stub$(CLASSPATH_SEPARATOR)$(CLOSED_SRC)/share/classes$(CLASSPATH_SEPARATOR)$(IMPORTSRCDIR)"
   3.603 +#################################################################
   3.604  
   3.605  #
   3.606  # CORE_PKGS environment variable has been moved to the following file
   3.607 @@ -463,31 +234,14 @@
   3.608  #
   3.609  include NON_CORE_PKGS.gmk
   3.610  
   3.611 -# Targets for all APIs other than the core platform APIs
   3.612 -ALL_OTHER_TARGETS = \
   3.613 -    mirrordocs \
   3.614 -    docletapidocs \
   3.615 -    tagletapidocs \
   3.616 -    domapidocs \
   3.617 -    jpdadocs \
   3.618 -    jaasdocs \
   3.619 -    jgssdocs \
   3.620 -    smartcardiodocs \
   3.621 -    tracingdocs \
   3.622 -    httpserverdocs  \
   3.623 -    sctpdocs \
   3.624 -    mgmtdocs \
   3.625 -    attachdocs \
   3.626 -    jconsoledocs \
   3.627 -    treeapidocs
   3.628 +#################################################################
   3.629  
   3.630 -.PHONY: all docs
   3.631 +#
   3.632 +# Default target is same as docs target, create core api and all others it can
   3.633 +#
   3.634 +
   3.635  all docs: coredocs otherdocs
   3.636  
   3.637 -.PHONY: otherdocs
   3.638 -otherdocs: ${ALL_OTHER_TARGETS}
   3.639 -
   3.640 -
   3.641  #################################################################
   3.642  # Production Targets -- USE THESE TARGETS WHEN:
   3.643  #    a) You're generating docs outside of release engineering's
   3.644 @@ -496,9 +250,9 @@
   3.645  #       the downloaded doc bundle.
   3.646  #
   3.647  # See:  Notes.html#releaseTargets
   3.648 -# Note: Spaces preceed ifdef/ifndef indents. Tabs preceed target commands (!)
   3.649 +# Note: Spaces precede ifdef/ifndef indents. Tabs precede target commands (!)
   3.650  #
   3.651 -.PHONY: sanitycheckcoredocs
   3.652 +
   3.653  sanitycheckcoredocs:
   3.654  	@$(ECHO) ""
   3.655  	@$(ECHO) "Building core api docs with these values:"
   3.656 @@ -512,199 +266,942 @@
   3.657  	exit 1
   3.658    endif
   3.659  
   3.660 +#############################################################
   3.661 +#
   3.662 +# coredocs
   3.663 +#
   3.664 +COREAPI_DOCTITLE  = Java$(TRADEMARK) Platform, Standard Edition \
   3.665 +$(JDK_MINOR_VERSION)<br>API Specification
   3.666 +COREAPI_WINDOWTITLE  = Java Platform SE $(JDK_MINOR_VERSION)
   3.667 +COREAPI_HEADER = \
   3.668 +<strong>Java$(TRADEMARK)&nbsp;Platform<br>Standard&nbsp;Ed.&nbsp;$(JDK_MINOR_VERSION)</strong>
   3.669 +
   3.670 +# Ignored tags
   3.671 +IGNORED_TAGS =	beaninfo revised since.unbundled spec specdefault Note ToDo
   3.672 +
   3.673 +# Java language specification cite
   3.674 +JLS3_CITE = <a href=\"$(JLS3_URL)\"> \
   3.675 +		The Java Language Specification, Third Edition</a>
   3.676 +TAG_JLS3 = -tag 'jls3:a:See <cite>$(JLS3_CITE)</cite>:'
   3.677 +
   3.678 +TAGS = $(IGNORED_TAGS:%=-tag %:X) $(TAG_JLS3)
   3.679 +
   3.680 +# Overview file for core apis
   3.681 +COREAPI_OVERVIEW = $(SHARE_SRC)/classes/overview-core.html
   3.682 +
   3.683 +# The index.html, options, and packages files
   3.684 +COREAPI_INDEX_FILE    = $(COREAPI_DOCSDIR)/index.html
   3.685 +COREAPI_OPTIONS_FILE  = $(DOCSTMPDIR)/coredocs.options
   3.686 +COREAPI_PACKAGES_FILE = $(DOCSTMPDIR)/coredocs.packages
   3.687 +
   3.688 +coredocs: $(COREAPI_INDEX_FILE)
   3.689 +
   3.690 +# Set relative location to core api document root
   3.691 +$(COREAPI_INDEX_FILE): GET2DOCSDIR=..
   3.692 +
   3.693 +# Run javadoc if the index file is out of date or missing
   3.694 +$(COREAPI_INDEX_FILE): $(COREAPI_OPTIONS_FILE) $(COREAPI_PACKAGES_FILE)
   3.695 +	$(prep-javadoc)
   3.696 +	$(call JavadocSummary,$(COREAPI_OPTIONS_FILE),$(COREAPI_PACKAGES_FILE))
   3.697 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
   3.698 +	  @$(COREAPI_OPTIONS_FILE) @$(COREAPI_PACKAGES_FILE)
   3.699 +
   3.700 +# Create file with javadoc options in it
   3.701 +$(COREAPI_OPTIONS_FILE): $(COREAPI_OVERVIEW)
   3.702 +	$(prep-target)
   3.703 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
   3.704 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
   3.705 +	  $(ECHO) "$(TAGS)"						; \
   3.706 +	  $(ECHO) "-encoding ISO-8859-1"				; \
   3.707 +	  $(ECHO) "-splitIndex"						; \
   3.708 +	  $(ECHO) "-overview $(COREAPI_OVERVIEW)" 			; \
   3.709 +	  $(ECHO) "-doctitle '$(COREAPI_DOCTITLE)'"			; \
   3.710 +	  $(ECHO) "-windowtitle '$(COREAPI_WINDOWTITLE) $(DRAFT_WINTITLE)'";\
   3.711 +	  $(ECHO) "-header '$(COREAPI_HEADER)$(DRAFT_HEADER)'"		; \
   3.712 +	  $(ECHO) "-bottom '$(COREAPI_BOTTOM)$(DRAFT_BOTTOM)'"		; \
   3.713 +        ) >> $@
   3.714 +ifdef COREAPI_TOP_EARLYACCESS
   3.715 +	@$(ECHO) "-top '$(COREAPI_TOP_EARLYACCESS)'" >> $@
   3.716 +endif
   3.717 +
   3.718 +# Create a file with the package names in it
   3.719 +$(COREAPI_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(CORE_PKGS))
   3.720 +	$(prep-target)
   3.721 +	$(call PackageFilter,$(CORE_PKGS))
   3.722 +
   3.723 +#############################################################
   3.724 +#
   3.725 +# mirrordocs
   3.726 +#
   3.727 +
   3.728 +# Part of langtools
   3.729 +ifdef LANGTOOLS_DIST
   3.730 +  ALL_OTHER_TARGETS += mirrordocs
   3.731 +endif
   3.732 +
   3.733 +MIRROR_DOCDIR      := $(JDK_API_DOCSDIR)/apt/mirror
   3.734 +MIRROR2COREAPI     := ../../$(JDKJRE2COREAPI)
   3.735 +MIRROR_DOCTITLE    := Mirror API
   3.736 +MIRROR_WINDOWTITLE := Mirror API
   3.737 +MIRROR_HEADER      := <strong>Mirror API</strong>
   3.738 +MIRROR_BOTTOM      := $(call CommonBottom,$(MIRROR_FIRST_COPYRIGHT_YEAR))
   3.739 +MIRROR_GROUPNAME   := Packages
   3.740 +MIRROR_OVERVIEW    := $(IMPORTSRCDIR)/com/sun/mirror/overview.html
   3.741 +MIRROR_REGEXP      := com.sun.mirror.*
   3.742 +# MIRROR_PKGS is located in NON_CORE_PKGS.gmk
   3.743 +
   3.744 +# The index.html, options, and packages files
   3.745 +MIRROR_INDEX_FILE    = $(MIRROR_DOCDIR)/index.html
   3.746 +MIRROR_OPTIONS_FILE  = $(DOCSTMPDIR)/mirror.options
   3.747 +MIRROR_PACKAGES_FILE = $(DOCSTMPDIR)/mirror.packages
   3.748 +
   3.749 +mirrordocs: $(MIRROR_INDEX_FILE)
   3.750 +
   3.751 +# Set relative location to core api document root
   3.752 +$(MIRROR_INDEX_FILE): GET2DOCSDIR=$(MIRROR2COREAPI)/..
   3.753 +
   3.754 +# Run javadoc if the index file is out of date or missing
   3.755 +$(MIRROR_INDEX_FILE): $(MIRROR_OPTIONS_FILE) $(MIRROR_PACKAGES_FILE)
   3.756 +	$(prep-javadoc)
   3.757 +	$(call JavadocSummary,$(MIRROR_OPTIONS_FILE),$(MIRROR_PACKAGES_FILE))
   3.758 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
   3.759 +	  @$(MIRROR_OPTIONS_FILE) @$(MIRROR_PACKAGES_FILE)
   3.760 +
   3.761 +# Create file with javadoc options in it
   3.762 +$(MIRROR_OPTIONS_FILE): $(MIRROR_OVERVIEW)
   3.763 +	$(prep-target)
   3.764 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
   3.765 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
   3.766 +	  $(ECHO) "-encoding ascii"					; \
   3.767 +	  $(ECHO) "-overview $(MIRROR_OVERVIEW)" 			; \
   3.768 +	  $(ECHO) "-doctitle '$(MIRROR_DOCTITLE)'"			; \
   3.769 +	  $(ECHO) "-windowtitle '$(MIRROR_WINDOWTITLE) $(DRAFT_WINTITLE)'";\
   3.770 +	  $(ECHO) "-header '$(MIRROR_HEADER)$(DRAFT_HEADER)'"		; \
   3.771 +	  $(ECHO) "-bottom '$(MIRROR_BOTTOM)$(DRAFT_BOTTOM)'"		; \
   3.772 +	  $(ECHO) "-group $(MIRROR_GROUPNAME) $(MIRROR_REGEXP)"		; \
   3.773 +	  $(ECHO) "-linkoffline $(MIRROR2COREAPI) $(COREAPI_DOCSDIR)/"; \
   3.774 +        ) >> $@
   3.775 +
   3.776 +# Create a file with the package names in it
   3.777 +$(MIRROR_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(MIRROR_PKGS))
   3.778 +	$(prep-target)
   3.779 +	$(call PackageFilter,$(MIRROR_PKGS))
   3.780 +
   3.781 +#############################################################
   3.782 +#
   3.783 +# docletapidocs
   3.784 +#
   3.785 +
   3.786 +# Part of langtools
   3.787 +ifdef LANGTOOLS_DIST
   3.788 +  ALL_OTHER_TARGETS += docletapidocs
   3.789 +endif
   3.790 +
   3.791 +DOCLETAPI_DOCDIR       := $(JDK_API_DOCSDIR)/javadoc/doclet
   3.792 +DOCLETAPI2COREAPI      := ../../$(JDKJRE2COREAPI)
   3.793 +DOCLETAPI_DOCTITLE     := Doclet API
   3.794 +DOCLETAPI_WINDOWTITLE  := Doclet API
   3.795 +DOCLETAPI_HEADER       := <strong>Doclet API</strong>
   3.796 +DOCLETAPI_BOTTOM       := $(call CommonTrademarkBottom,$(DOCLETAPI_FIRST_COPYRIGHT_YEAR))
   3.797 +DOCLETAPI_GROUPNAME    := Packages
   3.798 +DOCLETAPI_REGEXP       := com.sun.javadoc
   3.799 +# DOCLETAPI_PKGS is located in NON_CORE_PKGS.gmk
   3.800 +
   3.801 +# The index.html, options, and packages files
   3.802 +DOCLETAPI_INDEX_FILE    = $(DOCLETAPI_DOCDIR)/index.html
   3.803 +DOCLETAPI_OPTIONS_FILE  = $(DOCSTMPDIR)/docletapi.options
   3.804 +DOCLETAPI_PACKAGES_FILE = $(DOCSTMPDIR)/docletapi.packages
   3.805 +
   3.806 +docletapidocs: $(DOCLETAPI_INDEX_FILE)
   3.807 +
   3.808 +# Set relative location to core api document root
   3.809 +$(DOCLETAPI_INDEX_FILE): GET2DOCSDIR=$(DOCLETAPI2COREAPI)/..
   3.810 +
   3.811 +# Run javadoc if the index file is out of date or missing
   3.812 +$(DOCLETAPI_INDEX_FILE): $(DOCLETAPI_OPTIONS_FILE) $(DOCLETAPI_PACKAGES_FILE)
   3.813 +	$(prep-javadoc)
   3.814 +	$(call JavadocSummary,$(DOCLETAPI_OPTIONS_FILE),$(DOCLETAPI_PACKAGES_FILE))
   3.815 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
   3.816 +	  @$(DOCLETAPI_OPTIONS_FILE) @$(DOCLETAPI_PACKAGES_FILE)
   3.817 +
   3.818 +# Create file with javadoc options in it
   3.819 +$(DOCLETAPI_OPTIONS_FILE):
   3.820 +	$(prep-target)
   3.821 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
   3.822 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
   3.823 +	  $(ECHO) "-breakiterator"					; \
   3.824 +	  $(ECHO) "-encoding ascii"					; \
   3.825 +	  $(ECHO) "-doctitle '$(DOCLETAPI_DOCTITLE)'"			; \
   3.826 +	  $(ECHO) "-windowtitle '$(DOCLETAPI_WINDOWTITLE) $(DRAFT_WINTITLE)'";\
   3.827 +	  $(ECHO) "-header '$(DOCLETAPI_HEADER)$(DRAFT_HEADER)'"	; \
   3.828 +	  $(ECHO) "-bottom '$(DOCLETAPI_BOTTOM)$(DRAFT_BOTTOM)'"	; \
   3.829 +	  $(ECHO) "-group $(DOCLETAPI_GROUPNAME) $(DOCLETAPI_REGEXP)"	; \
   3.830 +	  $(ECHO) "-linkoffline $(DOCLETAPI2COREAPI) $(COREAPI_DOCSDIR)/"; \
   3.831 +        ) >> $@
   3.832 +
   3.833 +# Create a file with the package names in it
   3.834 +$(DOCLETAPI_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(DOCLETAPI_PKGS))
   3.835 +	$(prep-target)
   3.836 +	$(call PackageFilter,$(DOCLETAPI_PKGS))
   3.837 +
   3.838 +#############################################################
   3.839 +#
   3.840 +# tagletapidocs
   3.841 +#
   3.842 +
   3.843 +# Part of langtools
   3.844 +ifdef LANGTOOLS_DIST
   3.845 +  ALL_OTHER_TARGETS += tagletapidocs
   3.846 +endif
   3.847 +
   3.848 +TAGLETAPI_DOCDIR   := $(JDK_API_DOCSDIR)/javadoc/taglet
   3.849 +TAGLETAPI2COREAPI  := ../../$(JDKJRE2COREAPI)
   3.850 +TAGLETAPI_BOTTOM   := $(call CommonTrademarkBottom,$(TAGLETAPI_FIRST_COPYRIGHT_YEAR))
   3.851 +# TAGLETAPI_FILE is located in NON_CORE_PKGS.gmk
   3.852 +
   3.853 +# Temporary directory (special generation rules)
   3.854 +TAGLETAPI_TEMPDIR       = $(DOCSTMPDIR)/taglets_temp
   3.855 +
   3.856 +# The index.html, options, and packages files
   3.857 +TAGLETAPI_INDEX_FILE    = $(TAGLETAPI_DOCDIR)/index.html
   3.858 +TAGLETAPI_OPTIONS_FILE  = $(DOCSTMPDIR)/tagletapi.options
   3.859 +TAGLETAPI_PACKAGES_FILE = $(DOCSTMPDIR)/tagletapi.packages
   3.860 +
   3.861 +tagletapidocs: $(TAGLETAPI_INDEX_FILE)
   3.862 +
   3.863 +# Set relative location to core api document root
   3.864 +$(TAGLETAPI_INDEX_FILE): GET2DOCSDIR=$(TAGLETAPI2COREAPI)/..
   3.865 +
   3.866 +# Run javadoc if the index file is out of date or missing
   3.867 +$(TAGLETAPI_INDEX_FILE): $(TAGLETAPI_OPTIONS_FILE) $(TAGLETAPI_PACKAGES_FILE)
   3.868 +	$(prep-javadoc)
   3.869 +	$(RM) -r $(TAGLETAPI_TEMPDIR)
   3.870 +	$(MKDIR) -p $(TAGLETAPI_TEMPDIR)
   3.871 +	$(call JavadocSummary,$(TAGLETAPI_OPTIONS_FILE),$(TAGLETAPI_PACKAGES_FILE))
   3.872 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(TAGLETAPI_TEMPDIR) \
   3.873 +	  @$(TAGLETAPI_OPTIONS_FILE) @$(TAGLETAPI_PACKAGES_FILE)
   3.874 +	cp -r $(TAGLETAPI_TEMPDIR)/com $(@D)
   3.875 +	cp $(TAGLETAPI_TEMPDIR)/stylesheet.css $(@D)
   3.876 +	$(RM) -r $(TAGLETAPI_TEMPDIR)
   3.877 +
   3.878 +# Create file with javadoc options in it
   3.879 +$(TAGLETAPI_OPTIONS_FILE):
   3.880 +	$(prep-target)
   3.881 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
   3.882 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
   3.883 +	  $(ECHO) "-encoding ascii"					; \
   3.884 +	  $(ECHO) "-nonavbar"						; \
   3.885 +	  $(ECHO) "-noindex"						; \
   3.886 +	  $(ECHO) "-bottom '$(TAGLETAPI_BOTTOM)$(DRAFT_BOTTOM)'"			; \
   3.887 +	  $(ECHO) "-linkoffline $(TAGLETAPI2COREAPI) $(COREAPI_DOCSDIR)/"; \
   3.888 +        ) >> $@
   3.889 +
   3.890 +# Create a file with the package names in it
   3.891 +$(TAGLETAPI_PACKAGES_FILE): $(IMPORTSRCDIR)/$(TAGLETAPI_FILE)
   3.892 +	$(prep-target)
   3.893 +	@($(ECHO) "$(IMPORTSRCDIR)/$(TAGLETAPI_FILE)" ) > $@
   3.894 +
   3.895 +#############################################################
   3.896 +#
   3.897 +# domapidocs
   3.898 +#
   3.899 +
   3.900 +ALL_OTHER_TARGETS += domapidocs
   3.901 +
   3.902 +DOMAPI_DOCDIR       := $(JRE_API_DOCSDIR)/plugin/dom
   3.903 +DOMAPI2COREAPI      := ../../$(JDKJRE2COREAPI)
   3.904 +DOMAPI_DOCTITLE     := Common DOM API
   3.905 +DOMAPI_WINDOWTITLE  := Common DOM API
   3.906 +DOMAPI_HEADER       := <strong>Common DOM API</strong>
   3.907 +DOMAPI_BOTTOM       := $(call CommonTrademarkBottom,$(DOMAPI_FIRST_COPYRIGHT_YEAR))
   3.908 +DOMAPI_GROUPNAME    := Packages
   3.909 +DOMAPI_REGEXP       := com.sun.java.browser.dom:org.w3c.dom*
   3.910 +# DOMAPI_PKGS is located in NON_CORE_PKGS.gmk
   3.911 +
   3.912 +# The index.html, options, and packages files
   3.913 +DOMAPI_INDEX_FILE    = $(DOMAPI_DOCDIR)/index.html
   3.914 +DOMAPI_OPTIONS_FILE  = $(DOCSTMPDIR)/domapi.options
   3.915 +DOMAPI_PACKAGES_FILE = $(DOCSTMPDIR)/domapi.packages
   3.916 +
   3.917 +domapidocs: $(DOMAPI_INDEX_FILE)
   3.918 +
   3.919 +# Set relative location to core api document root
   3.920 +$(DOMAPI_INDEX_FILE): GET2DOCSDIR=$(DOMAPI2COREAPI)/..
   3.921 +
   3.922 +# Run javadoc if the index file is out of date or missing
   3.923 +$(DOMAPI_INDEX_FILE): $(DOMAPI_OPTIONS_FILE) $(DOMAPI_PACKAGES_FILE)
   3.924 +	$(prep-javadoc)
   3.925 +	$(call JavadocSummary,$(DOMAPI_OPTIONS_FILE),$(DOMAPI_PACKAGES_FILE))
   3.926 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
   3.927 +	  @$(DOMAPI_OPTIONS_FILE) @$(DOMAPI_PACKAGES_FILE)
   3.928 +
   3.929 +# Create file with javadoc options in it
   3.930 +$(DOMAPI_OPTIONS_FILE):
   3.931 +	$(prep-target)
   3.932 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
   3.933 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
   3.934 +	  $(ECHO) "-encoding ascii"					; \
   3.935 +	  $(ECHO) "-splitIndex"						; \
   3.936 +	  $(ECHO) "-doctitle '$(DOMAPI_DOCTITLE)'"			; \
   3.937 +	  $(ECHO) "-windowtitle '$(DOMAPI_WINDOWTITLE) $(DRAFT_WINTITLE)'";\
   3.938 +	  $(ECHO) "-header '$(DOMAPI_HEADER)$(DRAFT_HEADER)'"		; \
   3.939 +	  $(ECHO) "-bottom '$(DOMAPI_BOTTOM)$(DRAFT_BOTTOM)'"		; \
   3.940 +	  $(ECHO) "-group $(DOMAPI_GROUPNAME) $(DOMAPI_REGEXP)"		; \
   3.941 +	  $(ECHO) "-linkoffline $(DOMAPI2COREAPI) $(COREAPI_DOCSDIR)/" 	; \
   3.942 +        ) >> $@
   3.943 +
   3.944 +# Create a file with the package names in it
   3.945 +$(DOMAPI_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(DOMAPI_PKGS))
   3.946 +	$(prep-target)
   3.947 +	$(call PackageFilter,$(DOMAPI_PKGS))
   3.948 +
   3.949 +#############################################################
   3.950 +#
   3.951 +# jpdadocs
   3.952 +#
   3.953 +
   3.954 +ALL_OTHER_TARGETS += jpdadocs
   3.955 +
   3.956 +jpdadocs: jdidocs jdwpdocs jvmtidocs
   3.957 +
   3.958 +#############################################################
   3.959 +#
   3.960 +# jdidocs
   3.961 +#
   3.962 +
   3.963 +ALL_OTHER_TARGETS += jdidocs
   3.964 +
   3.965 +JDI_DOCDIR      := $(JDK_API_DOCSDIR)/jpda/jdi
   3.966 +JDI2COREAPI     := ../../$(JDKJRE2COREAPI)
   3.967 +JDI_DOCTITLE    := Java$(TRADEMARK) Debug Interface
   3.968 +JDI_WINDOWTITLE := Java Debug Interface
   3.969 +JDI_HEADER      := <strong>Java Debug Interface</strong>
   3.970 +JDI_BOTTOM      := $(call CommonBottom,$(JDI_FIRST_COPYRIGHT_YEAR))
   3.971 +JDI_OVERVIEW    := $(SHARE_SRC)/classes/jdi-overview.html
   3.972 +# JDI_PKGS is located in NON_CORE_PKGS.gmk
   3.973 +
   3.974 +# The index.html, options, and packages files
   3.975 +JDI_INDEX_FILE    = $(JDI_DOCDIR)/index.html
   3.976 +JDI_OPTIONS_FILE  = $(DOCSTMPDIR)/jdi.options
   3.977 +JDI_PACKAGES_FILE = $(DOCSTMPDIR)/jdi.packages
   3.978 +
   3.979 +jdidocs: $(JDI_INDEX_FILE)
   3.980 +
   3.981 +# Set relative location to core api document root
   3.982 +$(JDI_INDEX_FILE): GET2DOCSDIR=$(JDI2COREAPI)/..
   3.983 +
   3.984 +# Run javadoc if the index file is out of date or missing
   3.985 +$(JDI_INDEX_FILE): $(JDI_OPTIONS_FILE) $(JDI_PACKAGES_FILE)
   3.986 +	$(prep-javadoc)
   3.987 +	$(call JavadocSummary,$(JDI_OPTIONS_FILE),$(JDI_PACKAGES_FILE))
   3.988 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
   3.989 +	  @$(JDI_OPTIONS_FILE) @$(JDI_PACKAGES_FILE)
   3.990 +
   3.991 +# Create file with javadoc options in it
   3.992 +$(JDI_OPTIONS_FILE): $(JDI_OVERVIEW)
   3.993 +	$(prep-target)
   3.994 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
   3.995 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
   3.996 +	  $(ECHO) "-encoding ascii"					; \
   3.997 +	  $(ECHO) "-overview $(JDI_OVERVIEW)" 				; \
   3.998 +	  $(ECHO) "-doctitle '$(JDI_DOCTITLE)'"				; \
   3.999 +	  $(ECHO) "-windowtitle '$(JDI_WINDOWTITLE) $(DRAFT_WINTITLE)'"	; \
  3.1000 +	  $(ECHO) "-header '$(JDI_HEADER)$(DRAFT_HEADER)'"		; \
  3.1001 +	  $(ECHO) "-bottom '$(JDI_BOTTOM)$(DRAFT_BOTTOM)'"		; \
  3.1002 +	  $(ECHO) "-linkoffline $(JDI2COREAPI) $(COREAPI_DOCSDIR)/" 	; \
  3.1003 +        ) >> $@
  3.1004 +
  3.1005 +# Create a file with the package names in it
  3.1006 +$(JDI_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(JDI_PKGS))
  3.1007 +	$(prep-target)
  3.1008 +	$(call PackageFilter,$(JDI_PKGS))
  3.1009 +
  3.1010 +#############################################################
  3.1011 +#
  3.1012 +# jdwpdocs
  3.1013 +#
  3.1014 +
  3.1015 +ALL_OTHER_TARGETS += jdwpdocs
  3.1016 +
  3.1017 +JDWP_DOCDIR     = $(PLATFORM_DOCSDIR)/jpda/jdwp
  3.1018 +JDWP_SPEC       = $(BUILDDIR)/jpda/jdwp/jdwp.spec
  3.1019 +JDWPGEN_JARFILE = $(BUILDTOOLJARDIR)/jdwpgen.jar
  3.1020 +
  3.1021 +jdwpdocs: $(JDWP_DOCDIR)/jdwp-protocol.html
  3.1022 +$(JDWP_DOCDIR)/jdwp-protocol.html: $(JDWPGEN_JARFILE) $(JDWP_SPEC)
  3.1023 +	$(prep-javadoc)
  3.1024 +	$(BOOT_JAVA_CMD) -jar $(JDWPGEN_JARFILE) $(JDWP_SPEC) -doc $@
  3.1025 +
  3.1026 +#############################################################
  3.1027 +#
  3.1028 +# jvmtidocs
  3.1029 +#
  3.1030 +
  3.1031 +ALL_OTHER_TARGETS += jvmtidocs
  3.1032 +
  3.1033 +JVMTI_DOCDIR      = $(PLATFORM_DOCSDIR)/jvmti
  3.1034 +JVMTI_HTML        = $(HOTSPOT_DOCS_IMPORT_PATH)/platform/jvmti/jvmti.html
  3.1035 +
  3.1036 +jvmtidocs:  $(JVMTI_DOCDIR)/jvmti.html
  3.1037 +$(JVMTI_DOCDIR)/jvmti.html:
  3.1038 +	@$(prep-javadoc)
  3.1039 +	@if [ -f $(JVMTI_HTML) ] ; then		                           \
  3.1040 +	  $(ECHO) "$(CP) $(JVMTI_HTML) $@";                 	           \
  3.1041 +	  $(CP) $(JVMTI_HTML) $@; 	                 	           \
  3.1042 +	else 						                   \
  3.1043 +	  $(ECHO) "WARNING: Generated file does not exist: $(JVMTI_HTML)"; \
  3.1044 +	fi
  3.1045 +
  3.1046 +#############################################################
  3.1047 +#
  3.1048 +# jaasdocs
  3.1049 +#
  3.1050 +
  3.1051 +ALL_OTHER_TARGETS += jaasdocs
  3.1052 +
  3.1053 +JAAS_DOCDIR	 := $(JRE_API_DOCSDIR)/security/jaas/spec
  3.1054 +JAAS2COREAPI     := ../../../$(JDKJRE2COREAPI)
  3.1055 +JAAS_DOCTITLE    := Java$(TRADEMARK) Authentication and Authorization Service
  3.1056 +JAAS_WINDOWTITLE := Java Authentication and Authorization Service
  3.1057 +JAAS_HEADER      := <strong>Java Authentication and Authorization Service</strong>
  3.1058 +JAAS_BOTTOM      := $(call CommonBottom,$(JAAS_FIRST_COPYRIGHT_YEAR))
  3.1059 +# JAAS_PKGS is located in NON_CORE_PKGS.gmk
  3.1060 +JAAS_OVERVIEW    := $(SHARE_SRC)/classes/com/sun/security/auth/jaas-overview.html
  3.1061 +
  3.1062 +# The index.html, options, and packages files
  3.1063 +JAAS_INDEX_FILE    = $(JAAS_DOCDIR)/index.html
  3.1064 +JAAS_OPTIONS_FILE  = $(DOCSTMPDIR)/jaas.options
  3.1065 +JAAS_PACKAGES_FILE = $(DOCSTMPDIR)/jaas.packages
  3.1066 +
  3.1067 +jaasdocs: $(JAAS_INDEX_FILE)
  3.1068 +
  3.1069 +# Set relative location to core api document root
  3.1070 +$(JAAS_INDEX_FILE): GET2DOCSDIR=$(JAAS2COREAPI)/..
  3.1071 +
  3.1072 +# Run javadoc if the index file is out of date or missing
  3.1073 +$(JAAS_INDEX_FILE): $(JAAS_OPTIONS_FILE) $(JAAS_PACKAGES_FILE)
  3.1074 +	$(prep-javadoc)
  3.1075 +	$(call JavadocSummary,$(JAAS_OPTIONS_FILE),$(JAAS_PACKAGES_FILE))
  3.1076 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
  3.1077 +	  @$(JAAS_OPTIONS_FILE) @$(JAAS_PACKAGES_FILE)
  3.1078 +
  3.1079 +# Create file with javadoc options in it
  3.1080 +$(JAAS_OPTIONS_FILE): $(JAAS_OVERVIEW)
  3.1081 +	$(prep-target)
  3.1082 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
  3.1083 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
  3.1084 +	  $(ECHO) "-encoding ascii"					; \
  3.1085 +	  $(ECHO) "-overview $(JAAS_OVERVIEW)" 				; \
  3.1086 +	  $(ECHO) "-doctitle '$(JAAS_DOCTITLE)'"			; \
  3.1087 +	  $(ECHO) "-windowtitle '$(JAAS_WINDOWTITLE) $(DRAFT_WINTITLE)'"; \
  3.1088 +	  $(ECHO) "-header '$(JAAS_HEADER)$(DRAFT_HEADER)'"		; \
  3.1089 +	  $(ECHO) "-bottom '$(JAAS_BOTTOM)$(DRAFT_BOTTOM)'"		; \
  3.1090 +	  $(ECHO) "-linkoffline $(JAAS2COREAPI) $(COREAPI_DOCSDIR)/" 	; \
  3.1091 +        ) >> $@
  3.1092 +
  3.1093 +# Create a file with the package names in it
  3.1094 +$(JAAS_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(JAAS_PKGS))
  3.1095 +	$(prep-target)
  3.1096 +	$(call PackageFilter,$(JAAS_PKGS))
  3.1097 +
  3.1098 +#############################################################
  3.1099 +#
  3.1100 +# jgssdocs
  3.1101 +#
  3.1102 +
  3.1103 +ALL_OTHER_TARGETS += jgssdocs
  3.1104 +
  3.1105 +JGSS_DOCDIR	 := $(JRE_API_DOCSDIR)/security/jgss/spec
  3.1106 +JGSS2COREAPI     := ../../../$(JDKJRE2COREAPI)
  3.1107 +JGSS_DOCTITLE    := Java$(TRADEMARK) GSS-API Utilities
  3.1108 +JGSS_WINDOWTITLE := Java GSS-API Utilities
  3.1109 +JGSS_HEADER      := <strong>Java GSS-API Utilities</strong>
  3.1110 +JGSS_BOTTOM      := $(call CommonBottom,$(JGSS_FIRST_COPYRIGHT_YEAR))
  3.1111 +JGSS_OVERVIEW    := $(SHARE_SRC)/classes/com/sun/security/jgss/jgss-overview.html
  3.1112 +# JGSS_PKGS is located in NON_CORE_PKGS.gmk
  3.1113 +
  3.1114 +# The index.html, options, and packages files
  3.1115 +JGSS_INDEX_FILE    = $(JGSS_DOCDIR)/index.html
  3.1116 +JGSS_OPTIONS_FILE  = $(DOCSTMPDIR)/jgss.options
  3.1117 +JGSS_PACKAGES_FILE = $(DOCSTMPDIR)/jgss.packages
  3.1118 +
  3.1119 +jgssdocs: $(JGSS_INDEX_FILE)
  3.1120 +
  3.1121 +# Set relative location to core api document root
  3.1122 +$(JGSS_INDEX_FILE): GET2DOCSDIR=$(JGSS2COREAPI)/..
  3.1123 +
  3.1124 +# Run javadoc if the index file is out of date or missing
  3.1125 +$(JGSS_INDEX_FILE): $(JGSS_OPTIONS_FILE) $(JGSS_PACKAGES_FILE)
  3.1126 +	$(prep-javadoc)
  3.1127 +	$(call JavadocSummary,$(JGSS_OPTIONS_FILE),$(JGSS_PACKAGES_FILE))
  3.1128 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
  3.1129 +	  @$(JGSS_OPTIONS_FILE) @$(JGSS_PACKAGES_FILE)
  3.1130 +
  3.1131 +# Create file with javadoc options in it
  3.1132 +$(JGSS_OPTIONS_FILE): $(JGSS_OVERVIEW)
  3.1133 +	$(prep-target)
  3.1134 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
  3.1135 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
  3.1136 +	  $(ECHO) "-encoding ascii"					; \
  3.1137 +	  $(ECHO) "-nodeprecatedlist"					; \
  3.1138 +	  $(ECHO) "-overview $(JGSS_OVERVIEW)" 				; \
  3.1139 +	  $(ECHO) "-doctitle '$(JGSS_DOCTITLE)'"			; \
  3.1140 +	  $(ECHO) "-windowtitle '$(JGSS_WINDOWTITLE) $(DRAFT_WINTITLE)'"; \
  3.1141 +	  $(ECHO) "-header '$(JGSS_HEADER)$(DRAFT_HEADER)'"		; \
  3.1142 +	  $(ECHO) "-bottom '$(JGSS_BOTTOM)$(DRAFT_BOTTOM)'"		; \
  3.1143 +	  $(ECHO) "-linkoffline $(JGSS2COREAPI) $(COREAPI_DOCSDIR)/" 	; \
  3.1144 +        ) >> $@
  3.1145 +
  3.1146 +# Create a file with the package names in it
  3.1147 +$(JGSS_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(JGSS_PKGS))
  3.1148 +	$(prep-target)
  3.1149 +	$(call PackageFilter,$(JGSS_PKGS))
  3.1150 +
  3.1151 +#############################################################
  3.1152 +#
  3.1153 +# smartcardiodocs
  3.1154 +#
  3.1155 +
  3.1156 +ALL_OTHER_TARGETS += smartcardiodocs
  3.1157 +
  3.1158 +SMARTCARDIO_DOCDIR	:= $(JRE_API_DOCSDIR)/security/smartcardio/spec
  3.1159 +SMARTCARDIO2COREAPI     := ../../../$(JDKJRE2COREAPI)
  3.1160 +SMARTCARDIO_DOCTITLE    := Java$(TRADEMARK) Smart Card I/O
  3.1161 +SMARTCARDIO_WINDOWTITLE := Java Smart Card I/O
  3.1162 +SMARTCARDIO_HEADER      := <strong>Java Smart Card I/O</strong>
  3.1163 +SMARTCARDIO_BOTTOM      := $(call CommonBottom,$(SMARTCARDIO_FIRST_COPYRIGHT_YEAR))
  3.1164 +# SMARTCARDIO_PKGS is located in NON_CORE_PKGS.gmk
  3.1165 +
  3.1166 +# The index.html, options, and packages files
  3.1167 +SMARTCARDIO_INDEX_FILE    = $(SMARTCARDIO_DOCDIR)/index.html
  3.1168 +SMARTCARDIO_OPTIONS_FILE  = $(DOCSTMPDIR)/smartcardio.options
  3.1169 +SMARTCARDIO_PACKAGES_FILE = $(DOCSTMPDIR)/smartcardio.packages
  3.1170 +
  3.1171 +smartcardiodocs: $(SMARTCARDIO_INDEX_FILE)
  3.1172 +
  3.1173 +# Set relative location to core api document root
  3.1174 +$(SMARTCARDIO_INDEX_FILE): GET2DOCSDIR=$(SMARTCARDIO2COREAPI)/..
  3.1175 +
  3.1176 +# Run javadoc if the index file is out of date or missing
  3.1177 +$(SMARTCARDIO_INDEX_FILE): $(SMARTCARDIO_OPTIONS_FILE) $(SMARTCARDIO_PACKAGES_FILE)
  3.1178 +	$(prep-javadoc)
  3.1179 +	$(call JavadocSummary,$(SMARTCARDIO_OPTIONS_FILE),$(SMARTCARDIO_PACKAGES_FILE))
  3.1180 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
  3.1181 +	  @$(SMARTCARDIO_OPTIONS_FILE) @$(SMARTCARDIO_PACKAGES_FILE)
  3.1182 +
  3.1183 +# Create file with javadoc options in it
  3.1184 +$(SMARTCARDIO_OPTIONS_FILE):
  3.1185 +	$(prep-target)
  3.1186 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
  3.1187 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
  3.1188 +	  $(ECHO) "-encoding ascii"					; \
  3.1189 +	  $(ECHO) "-nodeprecatedlist"					; \
  3.1190 +	  $(ECHO) "-doctitle '$(SMARTCARDIO_DOCTITLE)'"			; \
  3.1191 +	  $(ECHO) "-windowtitle '$(SMARTCARDIO_WINDOWTITLE) $(DRAFT_WINTITLE)'";\
  3.1192 +	  $(ECHO) "-header '$(SMARTCARDIO_HEADER)$(DRAFT_HEADER)'"	; \
  3.1193 +	  $(ECHO) "-bottom '$(SMARTCARDIO_BOTTOM)$(DRAFT_BOTTOM)'"	; \
  3.1194 +	  $(ECHO) "-linkoffline $(SMARTCARDIO2COREAPI) $(COREAPI_DOCSDIR)/"; \
  3.1195 +        ) >> $@
  3.1196 +
  3.1197 +# Create a file with the package names in it
  3.1198 +$(SMARTCARDIO_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(SMARTCARDIO_PKGS))
  3.1199 +	$(prep-target)
  3.1200 +	$(call PackageFilter,$(SMARTCARDIO_PKGS))
  3.1201 +
  3.1202 +#############################################################
  3.1203 +#
  3.1204 +# httpserverdocs
  3.1205 +#
  3.1206 +
  3.1207 +ALL_OTHER_TARGETS += httpserverdocs
  3.1208 +
  3.1209 +HTTPSERVER_DOCDIR      := $(JRE_API_DOCSDIR)/net/httpserver/spec
  3.1210 +HTTPSERVER2COREAPI     := ../../../$(JDKJRE2COREAPI)
  3.1211 +HTTPSERVER_DOCTITLE    := Java$(TRADEMARK) HTTP Server
  3.1212 +HTTPSERVER_WINDOWTITLE := Java HTTP Server
  3.1213 +HTTPSERVER_HEADER      := <strong>Java HTTP Server</strong>
  3.1214 +HTTPSERVER_BOTTOM      := $(call CommonBottom,$(HTTPSERVER_FIRST_COPYRIGHT_YEAR))
  3.1215 +# HTTPSERVER_PKGS is located in NON_CORE_PKGS.gmk
  3.1216 +
  3.1217 +HTTPSERVER_INDEX_HTML    = $(HTTPSERVER_DOCDIR)/index.html
  3.1218 +HTTPSERVER_OPTIONS_FILE  = $(DOCSTMPDIR)/httpserver.options
  3.1219 +HTTPSERVER_PACKAGES_FILE = $(DOCSTMPDIR)/httpserver.packages
  3.1220 +
  3.1221 +httpserverdocs: $(HTTPSERVER_INDEX_HTML)
  3.1222 +
  3.1223 +# Set relative location to core api document root
  3.1224 +$(HTTPSERVER_INDEX_HTML): GET2DOCSDIR=$(HTTPSERVER2COREAPI)/..
  3.1225 +
  3.1226 +# Run javadoc if the index file is out of date or missing
  3.1227 +$(HTTPSERVER_INDEX_HTML): $(HTTPSERVER_OPTIONS_FILE) $(HTTPSERVER_PACKAGES_FILE)
  3.1228 +	$(prep-javadoc)
  3.1229 +	$(call JavadocSummary,$(HTTPSERVER_OPTIONS_FILE),$(HTTPSERVER_PACKAGES_FILE))
  3.1230 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
  3.1231 +	  @$(HTTPSERVER_OPTIONS_FILE) @$(HTTPSERVER_PACKAGES_FILE)
  3.1232 +
  3.1233 +# Create file with javadoc options in it
  3.1234 +$(HTTPSERVER_OPTIONS_FILE):
  3.1235 +	$(prep-target)
  3.1236 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
  3.1237 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
  3.1238 +	  $(ECHO) "-encoding ascii"					; \
  3.1239 +	  $(ECHO) "-nodeprecatedlist"					; \
  3.1240 +	  $(ECHO) "-doctitle '$(HTTPSERVER_DOCTITLE)'"			; \
  3.1241 +	  $(ECHO) "-windowtitle '$(HTTPSERVER_WINDOWTITLE) $(DRAFT_WINTITLE)'";\
  3.1242 +	  $(ECHO) "-header '$(HTTPSERVER_HEADER)$(DRAFT_HEADER)'"	; \
  3.1243 +	  $(ECHO) "-bottom '$(HTTPSERVER_BOTTOM)$(DRAFT_BOTTOM)'"	; \
  3.1244 +	  $(ECHO) "-linkoffline $(HTTPSERVER2COREAPI) $(COREAPI_DOCSDIR)/"; \
  3.1245 +        ) >> $@
  3.1246 +
  3.1247 +# Create a file with the package names in it
  3.1248 +$(HTTPSERVER_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(HTTPSERVER_PKGS))
  3.1249 +	$(prep-target)
  3.1250 +	$(call PackageFilter,$(HTTPSERVER_PKGS))
  3.1251 +
  3.1252 +#############################################################
  3.1253 +#
  3.1254 +# mgmtdocs
  3.1255 +#
  3.1256 +
  3.1257 +ALL_OTHER_TARGETS += mgmtdocs
  3.1258 +
  3.1259 +MGMT_DOCDIR	 := $(JRE_API_DOCSDIR)/management/extension
  3.1260 +MGMT2COREAPI     := ../../$(JDKJRE2COREAPI)
  3.1261 +JVM_MIB_NAME     := JVM-MANAGEMENT-MIB.mib
  3.1262 +JVM_MIB_SRC      := $(CLOSED_SRC)/share/classes/sun/management/snmp/$(JVM_MIB_NAME)
  3.1263 +MGMT_DOCTITLE    := Monitoring and Management Interface for the Java$(TRADEMARK) Platform
  3.1264 +MGMT_WINDOWTITLE := Monitoring and Management Interface for the Java Platform
  3.1265 +MGMT_HEADER      := <strong>Monitoring and Management Interface for the Java Platform</strong>
  3.1266 +MGMT_BOTTOM      := $(call CommonBottom,$(MGMT_FIRST_COPYRIGHT_YEAR))
  3.1267 +MGMT_OVERVIEW    := $(SHARE_SRC)/classes/com/sun/management/mgmt-overview.html
  3.1268 +# MGMT_PKGS is located in NON_CORE_PKGS.gmk
  3.1269 +
  3.1270 +# The index.html, options, and packages files
  3.1271 +MGMT_INDEX_FILE    = $(MGMT_DOCDIR)/index.html
  3.1272 +MGMT_OPTIONS_FILE  = $(DOCSTMPDIR)/mgmt.options
  3.1273 +MGMT_PACKAGES_FILE = $(DOCSTMPDIR)/mgmt.packages
  3.1274 +
  3.1275 +mgmtdocs: $(MGMT_INDEX_FILE)
  3.1276 +
  3.1277 +# Set relative location to core api document root
  3.1278 +$(MGMT_INDEX_FILE): GET2DOCSDIR=$(MGMT2COREAPI)/..
  3.1279 +
  3.1280 +# Run javadoc if the index file is out of date or missing
  3.1281 +$(MGMT_INDEX_FILE): $(MGMT_OPTIONS_FILE) $(MGMT_PACKAGES_FILE)
  3.1282 +	$(prep-javadoc)
  3.1283 +	@if [ -f $(JVM_MIB_SRC) ] ; then 				\
  3.1284 +	  $(ECHO) "$(CP) $(JVM_MIB_SRC) $(@D)/.."; 			\
  3.1285 +	  $(CP) $(JVM_MIB_SRC) $(@D)/.. ; 				\
  3.1286 +	else 								\
  3.1287 +	  $(ECHO) "WARNING: File $(JVM_MIB_NAME) not available."; 	\
  3.1288 +	fi
  3.1289 +	$(call JavadocSummary,$(MGMT_OPTIONS_FILE),$(MGMT_PACKAGES_FILE))
  3.1290 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
  3.1291 +	  @$(MGMT_OPTIONS_FILE) @$(MGMT_PACKAGES_FILE)
  3.1292 +
  3.1293 +# Create file with javadoc options in it
  3.1294 +$(MGMT_OPTIONS_FILE): $(MGMT_OVERVIEW)
  3.1295 +	$(prep-target)
  3.1296 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
  3.1297 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
  3.1298 +	  $(ECHO) "-encoding ascii"					; \
  3.1299 +	  $(ECHO) "-nodeprecatedlist"					; \
  3.1300 +	  $(ECHO) "-overview $(MGMT_OVERVIEW)" 				; \
  3.1301 +	  $(ECHO) "-doctitle '$(MGMT_DOCTITLE)'"			; \
  3.1302 +	  $(ECHO) "-windowtitle '$(MGMT_WINDOWTITLE) $(DRAFT_WINTITLE)'"; \
  3.1303 +	  $(ECHO) "-header '$(MGMT_HEADER)$(DRAFT_HEADER)'"		; \
  3.1304 +	  $(ECHO) "-bottom '$(MGMT_BOTTOM)$(DRAFT_BOTTOM)'"		; \
  3.1305 +	  $(ECHO) "-linkoffline $(MGMT2COREAPI) $(COREAPI_DOCSDIR)/" 	; \
  3.1306 +        ) >> $@
  3.1307 +
  3.1308 +# Create a file with the package names in it
  3.1309 +$(MGMT_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(MGMT_PKGS))
  3.1310 +	$(prep-target)
  3.1311 +	$(call PackageFilter,$(MGMT_PKGS))
  3.1312 +
  3.1313 +#############################################################
  3.1314 +#
  3.1315 +# attachdocs
  3.1316 +#
  3.1317 +
  3.1318 +ALL_OTHER_TARGETS += attachdocs
  3.1319 +
  3.1320 +ATTACH_DOCDIR      := $(JDK_API_DOCSDIR)/attach/spec
  3.1321 +ATTACH2COREAPI     := ../../$(JDKJRE2COREAPI)
  3.1322 +ATTACH_DOCTITLE    := Attach API
  3.1323 +ATTACH_WINDOWTITLE := Attach API
  3.1324 +ATTACH_HEADER      := <strong>Attach API</strong>
  3.1325 +ATTACH_BOTTOM      := $(call CommonBottom,$(ATTACH_FIRST_COPYRIGHT_YEAR))
  3.1326 +# ATTACH_PKGS is located in NON_CORE_PKGS.gmk
  3.1327 +
  3.1328 +ATTACH_INDEX_HTML    = $(ATTACH_DOCDIR)/index.html
  3.1329 +ATTACH_OPTIONS_FILE  = $(DOCSTMPDIR)/attach.options
  3.1330 +ATTACH_PACKAGES_FILE = $(DOCSTMPDIR)/attach.packages
  3.1331 +
  3.1332 +attachdocs: $(ATTACH_INDEX_HTML)
  3.1333 +
  3.1334 +# Set relative location to core api document root
  3.1335 +$(ATTACH_INDEX_HTML): GET2DOCSDIR=$(ATTACH2COREAPI)/..
  3.1336 +
  3.1337 +# Run javadoc if the index file is out of date or missing
  3.1338 +$(ATTACH_INDEX_HTML): $(ATTACH_OPTIONS_FILE) $(ATTACH_PACKAGES_FILE)
  3.1339 +	$(prep-javadoc)
  3.1340 +	$(call JavadocSummary,$(ATTACH_OPTIONS_FILE),$(ATTACH_PACKAGES_FILE))
  3.1341 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
  3.1342 +	  @$(ATTACH_OPTIONS_FILE) @$(ATTACH_PACKAGES_FILE)
  3.1343 +
  3.1344 +# Create file with javadoc options in it
  3.1345 +$(ATTACH_OPTIONS_FILE):
  3.1346 +	$(prep-target)
  3.1347 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
  3.1348 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
  3.1349 +	  $(ECHO) "-encoding ascii"					; \
  3.1350 +	  $(ECHO) "-nodeprecatedlist"					; \
  3.1351 +	  $(ECHO) "-doctitle '$(ATTACH_DOCTITLE)'"			; \
  3.1352 +	  $(ECHO) "-windowtitle '$(ATTACH_WINDOWTITLE) $(DRAFT_WINTITLE)'";\
  3.1353 +	  $(ECHO) "-header '$(ATTACH_HEADER)$(DRAFT_HEADER)'"		; \
  3.1354 +	  $(ECHO) "-bottom '$(ATTACH_BOTTOM)$(DRAFT_BOTTOM)'"		; \
  3.1355 +	  $(ECHO) "-linkoffline $(ATTACH2COREAPI) $(COREAPI_DOCSDIR)/"	; \
  3.1356 +        ) >> $@
  3.1357 +
  3.1358 +# Create a file with the package names in it
  3.1359 +$(ATTACH_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(ATTACH_PKGS))
  3.1360 +	$(prep-target)
  3.1361 +	$(call PackageFilter,$(ATTACH_PKGS))
  3.1362 +
  3.1363 +#############################################################
  3.1364 +#
  3.1365 +# jconsoledocs
  3.1366 +#
  3.1367 +
  3.1368 +ALL_OTHER_TARGETS += jconsoledocs
  3.1369 +
  3.1370 +JCONSOLE_DOCDIR      := $(JDK_API_DOCSDIR)/jconsole/spec
  3.1371 +JCONSOLE2COREAPI     := ../../$(JDKJRE2COREAPI)
  3.1372 +JCONSOLE_DOCTITLE    := JConsole API
  3.1373 +JCONSOLE_WINDOWTITLE := JConsole API
  3.1374 +JCONSOLE_HEADER      := <strong>JConsole API</strong>
  3.1375 +JCONSOLE_BOTTOM      := $(call CommonBottom,$(JCONSOLE_FIRST_COPYRIGHT_YEAR))
  3.1376 +# JCONSOLE_PKGS is located in NON_CORE_PKGS.gmk
  3.1377 +
  3.1378 +JCONSOLE_INDEX_HTML    = $(JCONSOLE_DOCDIR)/index.html
  3.1379 +JCONSOLE_OPTIONS_FILE  = $(DOCSTMPDIR)/jconsole.options
  3.1380 +JCONSOLE_PACKAGES_FILE = $(DOCSTMPDIR)/jconsole.packages
  3.1381 +
  3.1382 +jconsoledocs: $(JCONSOLE_INDEX_HTML)
  3.1383 +
  3.1384 +# Set relative location to core api document root
  3.1385 +$(JCONSOLE_INDEX_HTML): GET2DOCSDIR=$(JCONSOLE2COREAPI)/..
  3.1386 +
  3.1387 +# Run javadoc if the index file is out of date or missing
  3.1388 +$(JCONSOLE_INDEX_HTML): $(JCONSOLE_OPTIONS_FILE) $(JCONSOLE_PACKAGES_FILE)
  3.1389 +	$(prep-javadoc)
  3.1390 +	$(call JavadocSummary,$(JCONSOLE_OPTIONS_FILE),$(JCONSOLE_PACKAGES_FILE))
  3.1391 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
  3.1392 +	  @$(JCONSOLE_OPTIONS_FILE) @$(JCONSOLE_PACKAGES_FILE)
  3.1393 +
  3.1394 +# Create file with javadoc options in it
  3.1395 +$(JCONSOLE_OPTIONS_FILE):
  3.1396 +	$(prep-target)
  3.1397 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
  3.1398 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
  3.1399 +	  $(ECHO) "-encoding ascii"					; \
  3.1400 +	  $(ECHO) "-nodeprecatedlist"					; \
  3.1401 +	  $(ECHO) "-doctitle '$(JCONSOLE_DOCTITLE)'"			; \
  3.1402 +	  $(ECHO) "-windowtitle '$(JCONSOLE_WINDOWTITLE) $(DRAFT_WINTITLE)'";\
  3.1403 +	  $(ECHO) "-header '$(JCONSOLE_HEADER)$(DRAFT_HEADER)'"		; \
  3.1404 +	  $(ECHO) "-bottom '$(JCONSOLE_BOTTOM)$(DRAFT_BOTTOM)'"		; \
  3.1405 +	  $(ECHO) "-linkoffline $(JCONSOLE2COREAPI) $(COREAPI_DOCSDIR)/"; \
  3.1406 +        ) >> $@
  3.1407 +
  3.1408 +# Create a file with the package names in it
  3.1409 +$(JCONSOLE_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(JCONSOLE_PKGS))
  3.1410 +	$(prep-target)
  3.1411 +	$(call PackageFilter,$(JCONSOLE_PKGS))
  3.1412 +
  3.1413 +#############################################################
  3.1414 +#
  3.1415 +# treeapidocs
  3.1416 +#
  3.1417 +
  3.1418 +# Part of langtools
  3.1419 +ifdef LANGTOOLS_DIST
  3.1420 +  ALL_OTHER_TARGETS += treeapidocs
  3.1421 +endif
  3.1422 +
  3.1423 +TREEAPI_DOCDIR       := $(JDK_API_DOCSDIR)/javac/tree
  3.1424 +TREEAPI2COREAPI      := ../../$(JDKJRE2COREAPI)
  3.1425 +TREEAPI_DOCTITLE     := Compiler Tree API
  3.1426 +TREEAPI_WINDOWTITLE  := Compiler Tree API
  3.1427 +TREEAPI_HEADER       := <strong>Compiler Tree API</strong>
  3.1428 +TREEAPI_BOTTOM       := $(call CommonBottom,$(TREEAPI_FIRST_COPYRIGHT_YEAR))
  3.1429 +TREEAPI_GROUPNAME    := Packages
  3.1430 +TREEAPI_REGEXP       := com.sun.source.*
  3.1431 +# TREEAPI_PKGS is located in NON_CORE_PKGS.gmk
  3.1432 +
  3.1433 +TREEAPI_INDEX_HTML    = $(TREEAPI_DOCDIR)/index.html
  3.1434 +TREEAPI_OPTIONS_FILE  = $(DOCSTMPDIR)/treeapi.options
  3.1435 +TREEAPI_PACKAGES_FILE = $(DOCSTMPDIR)/treeapi.packages
  3.1436 +
  3.1437 +treeapidocs: $(TREEAPI_INDEX_HTML)
  3.1438 +
  3.1439 +# Set relative location to core api document root
  3.1440 +$(TREEAPI_INDEX_HTML): GET2DOCSDIR=$(TREEAPI2COREAPI)/..
  3.1441 +
  3.1442 +# Run javadoc if the index file is out of date or missing
  3.1443 +$(TREEAPI_INDEX_HTML): $(TREEAPI_OPTIONS_FILE) $(TREEAPI_PACKAGES_FILE)
  3.1444 +	$(prep-javadoc)
  3.1445 +	$(call JavadocSummary,$(TREEAPI_OPTIONS_FILE),$(TREEAPI_PACKAGES_FILE))
  3.1446 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
  3.1447 +	  @$(TREEAPI_OPTIONS_FILE) @$(TREEAPI_PACKAGES_FILE)
  3.1448 +
  3.1449 +# Create file with javadoc options in it
  3.1450 +$(TREEAPI_OPTIONS_FILE):
  3.1451 +	$(prep-target)
  3.1452 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
  3.1453 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
  3.1454 +	  $(ECHO) "-encoding ascii"					; \
  3.1455 +	  $(ECHO) "-doctitle '$(TREEAPI_DOCTITLE)'"			; \
  3.1456 +	  $(ECHO) "-windowtitle '$(TREEAPI_WINDOWTITLE) $(DRAFT_WINTITLE)'";\
  3.1457 +	  $(ECHO) "-header '$(TREEAPI_HEADER)$(DRAFT_HEADER)'"		; \
  3.1458 +	  $(ECHO) "-bottom '$(TREEAPI_BOTTOM)$(DRAFT_BOTTOM)'"		; \
  3.1459 +	  $(ECHO) "-group $(TREEAPI_GROUPNAME) $(TREEAPI_REGEXP)"	; \
  3.1460 +	  $(ECHO) "-linkoffline $(TREEAPI2COREAPI) $(COREAPI_DOCSDIR)/"	; \
  3.1461 +        ) >> $@
  3.1462 +
  3.1463 +# Create a file with the package names in it
  3.1464 +$(TREEAPI_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(TREEAPI_PKGS))
  3.1465 +	$(prep-target)
  3.1466 +	$(call PackageFilter,$(TREEAPI_PKGS))
  3.1467 +
  3.1468 +#############################################################
  3.1469 +#
  3.1470 +# sctpdocs
  3.1471 +#
  3.1472 +
  3.1473 +ALL_OTHER_TARGETS += sctpdocs
  3.1474 +
  3.1475 +SCTPAPI_DOCDIR      := $(JRE_API_DOCSDIR)/nio/sctp/spec
  3.1476 +SCTPAPI2COREAPI     := ../../../$(JDKJRE2COREAPI)
  3.1477 +SCTPAPI_DOCTITLE    := SCTP API
  3.1478 +SCTPAPI_WINDOWTITLE := SCTP API
  3.1479 +SCTPAPI_HEADER      := <strong>SCTP API</strong>
  3.1480 +SCTPAPI_BOTTOM      := $(call CommonBottom,$(SCTPAPI_FIRST_COPYRIGHT_YEAR))
  3.1481 +# SCTPAPI_PKGS is located in NON_CORE_PKGS.gmk
  3.1482 +
  3.1483 +SCTPAPI_INDEX_HTML    = $(SCTPAPI_DOCDIR)/index.html
  3.1484 +SCTPAPI_OPTIONS_FILE  = $(DOCSTMPDIR)/sctp.options
  3.1485 +SCTPAPI_PACKAGES_FILE = $(DOCSTMPDIR)/sctp.packages
  3.1486 +
  3.1487 +sctpdocs: $(SCTPAPI_INDEX_HTML)
  3.1488 +
  3.1489 +# Set relative location to core api document root
  3.1490 +$(SCTSCTSCTP: GET2DOCSDIR=$(SCTPAPI2COREAPI)/..
  3.1491 +
  3.1492 +# Run javadoc if the index file is out of date or missing
  3.1493 +$(SCTPAPI_INDEX_HTML): $(SCTPAPI_OPTIONS_FILE) $(SCTPAPI_PACKAGES_FILE)
  3.1494 +	$(prep-javadoc)
  3.1495 +	$(call JavadocSummary,$(SCTPAPI_OPTIONS_FILE),$(SCTPAPI_PACKAGES_FILE))
  3.1496 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
  3.1497 +	  @$(SCTPAPI_OPTIONS_FILE) @$(SCTPAPI_PACKAGES_FILE)
  3.1498 +
  3.1499 +# Create file with javadoc options in it
  3.1500 +$(SCTPAPI_OPTIONS_FILE):
  3.1501 +	$(prep-target)
  3.1502 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
  3.1503 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
  3.1504 +	  $(ECHO) "-encoding ascii"					; \
  3.1505 +	  $(ECHO) "-nodeprecatedlist"					; \
  3.1506 +	  $(ECHO) "-doctitle '$(SCTPAPI_DOCTITLE)'"			; \
  3.1507 +	  $(ECHO) "-windowtitle '$(SCTPAPI_WINDOWTITLE) $(DRAFT_WINTITLE)'";\
  3.1508 +	  $(ECHO) "-header '$(SCTPAPI_HEADER)$(DRAFT_HEADER)'"		; \
  3.1509 +	  $(ECHO) "-bottom '$(SCTPAPI_BOTTOM)$(DRAFT_BOTTOM)'"		; \
  3.1510 +	  $(ECHO) "-linkoffline $(SCTPAPI2COREAPI) $(COREAPI_DOCSDIR)/"	; \
  3.1511 +        ) >> $@
  3.1512 +
  3.1513 +# Create a file with the package names in it
  3.1514 +$(SCTPAPI_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(SCTPAPI_PKGS))
  3.1515 +	$(prep-target)
  3.1516 +	$(call PackageFilter,$(SCTPAPI_PKGS))
  3.1517 +
  3.1518 +#############################################################
  3.1519 +#
  3.1520 +# tracingdocs
  3.1521 +#
  3.1522 +
  3.1523 +ALL_OTHER_TARGETS += tracingdocs
  3.1524 +
  3.1525 +TRACING_DOCDIR      := $(JRE_API_DOCSDIR)/tracing
  3.1526 +TRACING2COREAPI     := ../$(JDKJRE2COREAPI)
  3.1527 +TRACING_DOCTITLE    := Java$(TRADEMARK) Platform Tracing
  3.1528 +TRACING_WINDOWTITLE := Platform Tracing
  3.1529 +TRACING_HEADER      := <strong>Platform Tracing</strong>
  3.1530 +TRACING_BOTTOM      := $(call CommonBottom,$(TRACING_FIRST_COPYRIGHT_YEAR))
  3.1531 +# TRACING_PKGS is located in NON_CORE_PKGS.gmk
  3.1532 +
  3.1533 +TRACING_INDEX_HTML    = $(TRACING_DOCDIR)/index.html
  3.1534 +TRACING_OPTIONS_FILE  = $(DOCSTMPDIR)/tracing.options
  3.1535 +TRACING_PACKAGES_FILE = $(DOCSTMPDIR)/tracing.packages
  3.1536 +
  3.1537 +tracingdocs: $(TRACING_INDEX_HTML)
  3.1538 +
  3.1539 +# Set relative location to core api document root
  3.1540 +$(TRACING_INDEX_HTML): GET2DOCSDIR=$(TRACING2COREAPI)/..
  3.1541 +
  3.1542 +# Run javadoc if the index file is out of date or missing
  3.1543 +$(TRACING_INDEX_HTML): $(TRACING_OPTIONS_FILE) $(TRACING_PACKAGES_FILE)
  3.1544 +	$(prep-javadoc)
  3.1545 +	$(call JavadocSummary,$(TRACING_OPTIONS_FILE),$(TRACING_PACKAGES_FILE))
  3.1546 +	$(JAVADOC_CMD) $(JAVADOC_VM_MEMORY_FLAGS) -d $(@D) \
  3.1547 +	  @$(TRACING_OPTIONS_FILE) @$(TRACING_PACKAGES_FILE)
  3.1548 +
  3.1549 +# Create file with javadoc options in it
  3.1550 +$(TRACING_OPTIONS_FILE):
  3.1551 +	$(prep-target)
  3.1552 +	@($(ECHO) "$(COMMON_JAVADOCFLAGS)"				; \
  3.1553 +	  $(ECHO) "-sourcepath \"$(RELEASEDOCS_SOURCEPATH)\""		; \
  3.1554 +	  $(ECHO) "-encoding ascii"					; \
  3.1555 +	  $(ECHO) "-nodeprecatedlist"					; \
  3.1556 +	  $(ECHO) "-doctitle '$(TRACING_DOCTITLE)'"			; \
  3.1557 +	  $(ECHO) "-windowtitle '$(TRACING_WINDOWTITLE) $(DRAFT_WINTITLE)'";\
  3.1558 +	  $(ECHO) "-header '$(TRACING_HEADER)$(DRAFT_HEADER)'"		; \
  3.1559 +	  $(ECHO) "-bottom '$(TRACING_BOTTOM)$(DRAFT_BOTTOM)'"		; \
  3.1560 +	  $(ECHO) "-linkoffline $(TRACING2COREAPI) $(COREAPI_DOCSDIR)/"	; \
  3.1561 +        ) >> $@
  3.1562 +
  3.1563 +# Create a file with the package names in it
  3.1564 +$(TRACING_PACKAGES_FILE): $(DIRECTORY_CACHE) $(call PackageDependencies,$(TRACING_PKGS))
  3.1565 +	$(prep-target)
  3.1566 +	$(call PackageFilter,$(TRACING_PKGS))
  3.1567 +
  3.1568 +#############################################################
  3.1569 +#
  3.1570 +# Get a cache of all the directories
  3.1571 +
  3.1572 +$(DIRECTORY_CACHE): $(ALL_SOURCE_DIRS)
  3.1573 +	$(prep-target)
  3.1574 +	@for cp in $(ALL_SOURCE_DIRS) ; do 		\
  3.1575 +	  $(ECHO) "$(FIND) $${cp} -type f >> $@"; 	\
  3.1576 +	  $(FIND) $${cp} -type f >> $@; 		\
  3.1577 +	done
  3.1578 +
  3.1579 +#############################################################
  3.1580 +#release version of core packages ########
  3.1581  # Maximize performance and ensure that build number & milestone are set.
  3.1582 -.PHONY: rel-coredocs
  3.1583 +
  3.1584  rel-coredocs: sanitycheckcoredocs
  3.1585 -	@# ######## release version of core packages ########
  3.1586  	$(MAKE) coredocs
  3.1587  
  3.1588 -.PHONY: rel-docs
  3.1589 -rel-docs: rel-coredocs ${ALL_OTHER_TARGETS}
  3.1590 +rel-docs: rel-coredocs $(ALL_OTHER_TARGETS)
  3.1591  #
  3.1592  # end of production targets
  3.1593 +
  3.1594 +otherdocs: $(ALL_OTHER_TARGETS)
  3.1595 +
  3.1596 +clean:
  3.1597 +	$(RM) -r $(DOCSDIR) $(DOCSTMPDIR)
  3.1598 +
  3.1599  #############################################################
  3.1600 -
  3.1601 -.PHONY: coredocs
  3.1602 -coredocs:
  3.1603 -	@# ######## core packages #######################
  3.1604 -	$(RM) -r $(DOCSDIR)/api
  3.1605 -	$(MKDIR) -p $(DOCSDIR)/api
  3.1606 -	$(JAVADOC_CMD) $(CORE_JAVADOCFLAGS)            \
  3.1607 -                   -d $(DOCSDIR)/api                   \
  3.1608 -                   -sourcepath $(RELEASEDOCS_SRCPATH)  \
  3.1609 -                   $(CORE_PKGS)
  3.1610 -
  3.1611 -.PHONY: mirrordocs
  3.1612 -mirrordocs:
  3.1613 -	@# ######## mirror api for apt ##################
  3.1614 -	$(RM) -r $(MIRROR_DESTDIR)
  3.1615 -	$(MKDIR) -p $(MIRROR_DESTDIR)
  3.1616 -	$(JAVADOC_CMD) $(MIRROR_JAVADOCFLAGS)             \
  3.1617 -		   -d $(MIRROR_DESTDIR)               \
  3.1618 -		   -sourcepath $(RELEASEDOCS_SRCPATH) \
  3.1619 -		   $(MIRROR_LINKOPT)                  \
  3.1620 -		   $(MIRROR_PKGS)
  3.1621 -
  3.1622 -.PHONY: docletapidocs
  3.1623 -docletapidocs:
  3.1624 -	@# ######## doclet api ############################
  3.1625 -	$(RM) -r $(DOCSDIR)/jdk/api/javadoc/doclet
  3.1626 -	$(MKDIR) -p $(DOCSDIR)/jdk/api/javadoc/doclet
  3.1627 -	$(JAVADOC_CMD) $(DOCLETAPI_JAVADOCFLAGS)                 \
  3.1628 -                   -d $(DOCSDIR)/jdk/api/javadoc/doclet      \
  3.1629 -                   -sourcepath $(RELEASEDOCS_SRCPATH)        \
  3.1630 -                   $(DOCLETAPI_LINKOPT)                      \
  3.1631 -                   $(DOCLETAPI_PKGS)
  3.1632 -
  3.1633 -.PHONY: tagletapidocs
  3.1634 -tagletapidocs:
  3.1635 -	@# ######## taglet api ############################
  3.1636 -	$(RM) -r $(DOCSDIR)/jdk/api/javadoc/taglet
  3.1637 -	$(MKDIR) -p $(DOCSDIR)/jdk/api/javadoc/taglet
  3.1638 -	$(RM) -r $(DOCSTMPDIR)
  3.1639 -	$(MKDIR) -p $(DOCSTMPDIR)
  3.1640 -	$(JAVADOC_CMD) $(TAGLETAPI_JAVADOCFLAGS)                 \
  3.1641 -                   -d $(DOCSTMPDIR)                          \
  3.1642 -                   -linkoffline ../../../../api $(DOCSDIR)/api/ \
  3.1643 -                   $(IMPORTSRCDIR)/$(TAGLETAPI_FILE)
  3.1644 -	cp -r $(DOCSTMPDIR)/com $(DOCSDIR)/jdk/api/javadoc/taglet
  3.1645 -	cp $(DOCSTMPDIR)/stylesheet.css $(DOCSDIR)/jdk/api/javadoc/taglet
  3.1646 -	$(RM) -r $(DOCSTMPDIR)
  3.1647 -
  3.1648 -.PHONY: domapidocs
  3.1649 -domapidocs:
  3.1650 -	@# ######## dom api ############################
  3.1651 -	$(RM) -r $(DOCSDIR)/jre/api/plugin/dom
  3.1652 -	$(MKDIR) -p $(DOCSDIR)/jre/api/plugin/dom
  3.1653 -	$(JAVADOC_CMD) $(DOMAPI_JAVADOCFLAGS)		     \
  3.1654 -                   -d $(DOCSDIR)/jre/api/plugin/dom            \
  3.1655 -                   -sourcepath $(RELEASEDOCS_SRCPATH)        \
  3.1656 -                   -linkoffline ../../../../api $(DOCSDIR)/api/ \
  3.1657 -                   $(DOMAPI_PKGS)
  3.1658 -
  3.1659 -.PHONY: jpdadocs
  3.1660 -jpdadocs: jdidocs jdwpdocs jvmtidocs
  3.1661 -
  3.1662 -.PHONY: jdidocs
  3.1663 -jdidocs:
  3.1664 -	@# ######## jdi #################################
  3.1665 -	$(RM) -r $(DOCSDIR)/jdk/api/jpda/jdi
  3.1666 -	$(MKDIR) -p $(DOCSDIR)/jdk/api/jpda/jdi
  3.1667 -	$(JAVADOC_CMD) $(JDI_JAVADOCFLAGS)                       \
  3.1668 -                   $(JDI_PKGS)
  3.1669 -
  3.1670 -JDWP_SPEC       = $(BUILDDIR)/jpda/jdwp/jdwp.spec
  3.1671 -JDWP_DOC        = $(DOCSDIR)/platform/jpda/jdwp/jdwp-protocol.html
  3.1672 -JDWPGEN_JARFILE = $(BUILDTOOLJARDIR)/jdwpgen.jar
  3.1673 -
  3.1674 -.PHONY: jdwpdocs
  3.1675 -jdwpdocs: $(JDWP_DOC)
  3.1676 -
  3.1677 -$(JDWP_DOC): $(JDWPGEN_JARFILE) $(JDWP_SPEC)
  3.1678 -	$(prep-target)
  3.1679 -	$(BOOT_JAVA_CMD) -jar $(JDWPGEN_JARFILE) $(JDWP_SPEC) -doc $(JDWP_DOC)
  3.1680 -
  3.1681 -.PHONY: jvmtidocs
  3.1682 -jvmtidocs:
  3.1683 -	@# ######## jvmti #################################
  3.1684 -	@if [ -f $(JVMTI_HTML) ] ; then \
  3.1685 -	  $(RM) -r $(DOCSDIR)/$(JVMTI_DOCS_SUBDIR); \
  3.1686 -	  $(MKDIR) -p $(DOCSDIR)/$(JVMTI_DOCS_SUBDIR); \
  3.1687 -	  $(ECHO) $(CP) $(JVMTI_HTML) $(DOCSDIR)/$(JVMTI_DOCS_SUBDIR); \
  3.1688 -	  $(CP) $(JVMTI_HTML) $(DOCSDIR)/$(JVMTI_DOCS_SUBDIR); \
  3.1689 -	else \
  3.1690 -	  $(ECHO) "WARNING: Generated jvmti file does not exist: $(JVMTI_HTML)"; \
  3.1691 -	fi
  3.1692 -
  3.1693 -.PHONY: jaasdocs
  3.1694 -jaasdocs:
  3.1695 -	@# ######## api-jaas ############################
  3.1696 -	$(RM) -r $(JAAS_DOCDIR)
  3.1697 -	$(MKDIR) -p $(JAAS_DOCDIR)
  3.1698 -	$(JAVADOC_CMD) $(JAAS_JAVADOCFLAGS)                     \
  3.1699 -		   $(JAAS_PKGS)
  3.1700 -
  3.1701 -.PHONY: jgssdocs
  3.1702 -jgssdocs:
  3.1703 -	@# ######## api-jgss ############################
  3.1704 -	$(RM) -r $(JGSS_DOCDIR)
  3.1705 -	$(MKDIR) -p $(JGSS_DOCDIR)
  3.1706 -	$(JAVADOC_CMD) $(JGSS_JAVADOCFLAGS)                     \
  3.1707 -		   $(JGSS_PKGS)
  3.1708 -
  3.1709 -.PHONY: smartcardiodocs
  3.1710 -smartcardiodocs:
  3.1711 -	@# ######## api-smartcardio ############################
  3.1712 -	$(RM) -r $(SMARTCARDIO_DOCDIR)
  3.1713 -	$(MKDIR) -p $(SMARTCARDIO_DOCDIR)
  3.1714 -	$(JAVADOC_CMD) $(SMARTCARDIO_JAVADOCFLAGS)                     \
  3.1715 -		   $(SMARTCARDIO_PKGS)
  3.1716 -
  3.1717 -.PHONY: tracingdocs
  3.1718 -tracingdocs:
  3.1719 -	@# ######## api-tracing ############################
  3.1720 -	$(RM) -r $(TRACING_DOCDIR)
  3.1721 -	$(MKDIR) -p $(TRACING_DOCDIR)
  3.1722 -	$(JAVADOC_CMD) $(TRACING_JAVADOCFLAGS)                     \
  3.1723 -		   $(TRACING_PKGS)
  3.1724 -
  3.1725 -.PHONY: httpserverdocs
  3.1726 -httpserverdocs:
  3.1727 -	@# ######## api-httpserver #######################
  3.1728 -	$(RM) -r $(HTTPSERVER_DOCDIR)
  3.1729 -	$(MKDIR) -p $(HTTPSERVER_DOCDIR)
  3.1730 -	$(JAVADOC_CMD) $(HTTPSERVER_JAVADOCFLAGS)                     \
  3.1731 -		   $(HTTPSERVER_PKGS)
  3.1732 -
  3.1733 -.PHONY: sctpdocs
  3.1734 -sctpdocs:
  3.1735 -	@# ######## api-sctp #######################
  3.1736 -	$(RM) -r $(SCTPAPI_DOCDIR)
  3.1737 -	$(MKDIR) -p $(SCTPAPI_DOCDIR)
  3.1738 -	$(JAVADOC_CMD) $(SCTPAPI_JAVADOCFLAGS)                     \
  3.1739 -		$(SCTPAPI_PKGS)
  3.1740 -
  3.1741 -.PHONY: mgmtdocs
  3.1742 -mgmtdocs: $(COPY-MIB-TARGET)
  3.1743 -	@# ######## api-management ############################
  3.1744 -	$(RM) -r $(MGMT_EXT_DIR)
  3.1745 -	$(MKDIR) -p $(MGMT_EXT_DIR)
  3.1746 -	$(JAVADOC_CMD) $(MGMT_JAVADOCFLAGS)                     \
  3.1747 -		   $(MGMT_PKGS)
  3.1748 -
  3.1749 -copy-mib:
  3.1750 -	@# ######## copy-snmp-mib ############################
  3.1751 -	$(RM) $(MGMT_DOCDIR)/$(JVM_MIB_NAME)
  3.1752 -	$(MKDIR) -p $(MGMT_DOCDIR)
  3.1753 -	$(CP) $(JVM_MIB_SRC) $(MGMT_DOCDIR)
  3.1754 -
  3.1755 -.PHONY: attachdocs
  3.1756 -attachdocs:
  3.1757 -	@# ######## api-attach ############################
  3.1758 -	$(RM) -r $(ATTACH_DOCDIR)
  3.1759 -	$(MKDIR) -p $(ATTACH_DOCDIR)
  3.1760 -	$(JAVADOC_CMD) $(ATTACH_JAVADOCFLAGS)                     \
  3.1761 -		   $(ATTACH_PKGS)
  3.1762 -
  3.1763 -.PHONY: jconsoledocs
  3.1764 -jconsoledocs:
  3.1765 -	@# ######## api-jconsole ############################
  3.1766 -	$(RM) -r $(JCONSOLE_DOCDIR)
  3.1767 -	$(MKDIR) -p $(JCONSOLE_DOCDIR)
  3.1768 -	$(JAVADOC_CMD) $(JCONSOLE_JAVADOCFLAGS)                     \
  3.1769 -		   $(JCONSOLE_PKGS)
  3.1770 -
  3.1771 -.PHONY: treeapidocs
  3.1772 -treeapidocs:
  3.1773 -	@# ######## tree api for javac ##################
  3.1774 -	$(RM) -r $(TREEAPI_DESTDIR)
  3.1775 -	$(MKDIR) -p $(TREEAPI_DESTDIR)
  3.1776 -	$(JAVADOC_CMD) $(TREEAPI_JAVADOCFLAGS)             \
  3.1777 -		   -d $(TREEAPI_DESTDIR)               \
  3.1778 -		   -sourcepath $(RELEASEDOCS_SRCPATH) \
  3.1779 -		   $(TREEAPI_LINKOPT)                  \
  3.1780 -		   $(TREEAPI_PKGS)
  3.1781 -
  3.1782  # DEBUG TARGET
  3.1783  # List the values defined in the makefile hierarchy, to make sure everything
  3.1784  # is set properly, and to help identify values we can use instead of making new ones.
  3.1785 @@ -714,9 +1211,14 @@
  3.1786  #    * BUILD_NUMBER defaults to b00 if not set on command line with BUILD_NUMBER=<value>
  3.1787  #    * MILESTONE defaults to internal unless set to beta, rc, or fcs on command line
  3.1788  #
  3.1789 -.PHONY: echovalues
  3.1790 +
  3.1791  echovalues:
  3.1792  	@$(ECHO) ""
  3.1793 +	@$(ECHO) --------------Imports---------------------------
  3.1794 +	@$(ECHO) "IMPORT_PACKAGES = $(IMPORT_PACKAGES)"
  3.1795 +	@$(ECHO) "IMPORT_PACKAGE_FILTER = $(IMPORT_PACKAGE_FILTER)"
  3.1796 +	@$(ECHO) --------------Imports---------------------------
  3.1797 +	@$(ECHO) ""
  3.1798  	@$(ECHO) --------------Shared---------------------------
  3.1799  	@$(ECHO) BUILD_NUMBER = $(BUILD_NUMBER)
  3.1800  	@$(ECHO) FULL_VERSION = $(FULL_VERSION)
  3.1801 @@ -736,11 +1238,16 @@
  3.1802  	@$(ECHO) --------------Shared---------------------------
  3.1803  	@$(ECHO) ""
  3.1804  	@$(ECHO) --------------common/Defs---------------------------
  3.1805 -	@$(ECHO) "RELEASEDOCS_SRCPATH"
  3.1806 +	@$(ECHO) "RELEASEDOCS_SOURCEPATH"
  3.1807  	@$(ECHO) "   SHARE_SRC/classes: $(SHARE_SRC)/classes"
  3.1808  	@$(ECHO) "   PLATFORM_SRC/classes: $(PLATFORM_SRC)/classes"
  3.1809  	@$(ECHO) "   GENSRCDIR: $(GENSRCDIR)"
  3.1810 +	@$(ECHO) "   SHARE_SRC/doc/stub: $(SHARE_SRC)/doc/stub"
  3.1811  	@$(ECHO) "   IMPORTSRCDIR: $(IMPORTSRCDIR)"
  3.1812 -	@$(ECHO) "   SHARE_SRC/doc/stub: $(SHARE_SRC)/doc/stub"
  3.1813  	@$(ECHO) --------------common/Defs---------------------------
  3.1814  	@$(ECHO) ""
  3.1815 +
  3.1816 +#############################################################
  3.1817 +.PHONY: all docs coredocs rel-docs echovalues otherdocs rel-coredocs \
  3.1818 +        sanitycheckcoredocs $(ALL_OTHER_TARGETS)
  3.1819 +
     4.1 --- a/make/java/java/FILES_java.gmk	Thu Jul 15 20:11:45 2010 -0700
     4.2 +++ b/make/java/java/FILES_java.gmk	Tue Jul 20 22:21:31 2010 -0700
     4.3 @@ -30,6 +30,7 @@
     4.4  #
     4.5  JAVA_JAVA_java = \
     4.6      java/lang/Object.java \
     4.7 +    java/lang/AutoCloseable.java \
     4.8      java/lang/Class.java \
     4.9      java/lang/Thread.java \
    4.10      java/lang/Character.java \
     5.1 --- a/make/java/security/Makefile	Thu Jul 15 20:11:45 2010 -0700
     5.2 +++ b/make/java/security/Makefile	Tue Jul 20 22:21:31 2010 -0700
     5.3 @@ -1,5 +1,5 @@
     5.4  #
     5.5 -# Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
     5.6 +# Copyright (c) 1996, 2010 Oracle and/or its affiliates. All rights reserved.
     5.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.8  #
     5.9  # This code is free software; you can redistribute it and/or modify it
    5.10 @@ -62,6 +62,11 @@
    5.11  CACERTS_SRC =	$(CACERTS_FILE)
    5.12  CACERTS_BUILD = $(LIBDIR)/security/cacerts
    5.13  
    5.14 +ifndef OPENJDK
    5.15 +  BLACKLIST_SRC =	$(CLOSED_SHARE_SRC)/lib/security/blacklist
    5.16 +  BLACKLIST_BUILD = $(LIBDIR)/security/blacklist
    5.17 +endif
    5.18 +
    5.19  FILES_class = $(FILES_java:%.java=$(CLASSBINDIR)/%.class)
    5.20  
    5.21  #
    5.22 @@ -69,7 +74,11 @@
    5.23  #
    5.24  include $(BUILDDIR)/common/Rules.gmk
    5.25  
    5.26 +ifdef OPENJDK
    5.27  build: properties policy cacerts
    5.28 +else
    5.29 +build: properties policy cacerts blacklist
    5.30 +endif
    5.31  
    5.32  install: all
    5.33  
    5.34 @@ -79,6 +88,8 @@
    5.35  
    5.36  cacerts: classes $(CACERTS_BUILD)
    5.37  
    5.38 +blacklist: classes $(BLACKLIST_BUILD)
    5.39 +
    5.40  $(PROPS_BUILD): $(PROPS_SRC)
    5.41  	$(install-file)
    5.42  
    5.43 @@ -88,9 +99,12 @@
    5.44  $(CACERTS_BUILD): $(CACERTS_SRC)
    5.45  	$(install-file)
    5.46  
    5.47 +$(BLACKLIST_BUILD): $(BLACKLIST_SRC)
    5.48 +	$(install-file)
    5.49 +
    5.50  clean clobber:: .delete.classlist
    5.51  	$(RM) -r $(CLASSBINDIR)/java/security
    5.52 -	$(RM) $(PROPS_BUILD) $(POLICY_BUILD) $(CACERTS_BUILD)
    5.53 +	$(RM) $(PROPS_BUILD) $(POLICY_BUILD) $(CACERTS_BUILD) $(BLACKLIST_BUILD)
    5.54  
    5.55  # Additional Rule for building sun.security.util
    5.56  $(CLASSBINDIR)/%.class: $(SHARE_SRC)/sun/%.java
     6.1 --- a/make/mkdemo/Makefile	Thu Jul 15 20:11:45 2010 -0700
     6.2 +++ b/make/mkdemo/Makefile	Tue Jul 20 22:21:31 2010 -0700
     6.3 @@ -46,11 +46,11 @@
     6.4  	$(RM) -r $(DEMODIR)/nbproject
     6.5  	$(MKDIR) -p $(DEMODIR)
     6.6  	( $(CD) $(SHARE_SRC)/demo && $(TAR) -cf - \
     6.7 -	  `find nbproject $(SCM_DIRS_prune) -o -type f -print` ) | \
     6.8 +	  `$(FIND) nbproject $(SCM_DIRS_prune) -o -type f -print` ) | \
     6.9  	  ( $(CD) $(DEMODIR) && $(TAR) -xf - )
    6.10  ifndef OPENJDK
    6.11  	( $(CD) $(CLOSED_SHARE_SRC)/demo && $(TAR) -cf - \
    6.12 -	  `find nbproject $(SCM_DIRS_prune) -o -type f -print` ) | \
    6.13 +	  `$(FIND) nbproject $(SCM_DIRS_prune) -o -type f -print` ) | \
    6.14  	  ( $(CD) $(DEMODIR) && $(TAR) -xf - )
    6.15  endif
    6.16  
     7.1 --- a/make/tools/src/build/tools/jarreorder/JarReorder.java	Thu Jul 15 20:11:45 2010 -0700
     7.2 +++ b/make/tools/src/build/tools/jarreorder/JarReorder.java	Tue Jul 20 22:21:31 2010 -0700
     7.3 @@ -28,7 +28,6 @@
     7.4   * combine with an argument list of files and directories, and
     7.5   * write a list of items to be included in a jar file.
     7.6   */
     7.7 -
     7.8  package build.tools.jarreorder;
     7.9  
    7.10  import java.io.BufferedReader;
    7.11 @@ -36,74 +35,68 @@
    7.12  import java.io.FileNotFoundException;
    7.13  import java.io.FileReader;
    7.14  import java.io.IOException;
    7.15 -import java.util.Arrays;
    7.16 -import java.util.HashMap;
    7.17 +import java.util.Collections;
    7.18  import java.util.HashSet;
    7.19 -import java.util.Vector;
    7.20  import java.io.PrintStream;
    7.21  import java.io.FileOutputStream;
    7.22 +import java.util.ArrayList;
    7.23 +import java.util.List;
    7.24 +import java.util.Set;
    7.25  
    7.26  public class JarReorder {
    7.27  
    7.28      // To deal with output
    7.29 -    private static PrintStream out;
    7.30 +    private PrintStream out;
    7.31  
    7.32 -    private final static boolean useTopDir = false;
    7.33 -
    7.34 -    private static void usage() {
    7.35 +    private void usage() {
    7.36          String help;
    7.37          help =
    7.38 -            "Usage:  jar JarReorder [-o <outputfile>] <order_list> <exclude_list> <file> ...\n"
    7.39 -          + "   order_list    is a file containing names of files to load\n"
    7.40 -          + "                 in order at the end of a jar file.\n"
    7.41 -          + "   exclude_list  is a file containing names of files/directories\n"
    7.42 -          + "                 NOT to be included in a jar file.\n";
    7.43 -        if (useTopDir)
    7.44 -            help +=
    7.45 -                "   top_dir       is the top of the directory structure to be searched;\n"
    7.46 -              + "                 the contents of the lists and remaining arguments are\n"
    7.47 -              + "                 relative to this.\n";
    7.48 -        help +=
    7.49 -            "\n"
    7.50 -          + "The order_list or exclude_list may be replaced by a \"_\" if no\n"
    7.51 -          + "data is to be provided.\n"
    7.52 -          + "\n"
    7.53 -          + "   The remaining arguments are files or directories to be included\n"
    7.54 -          + "   in a jar file, from which will be excluded thse entries which\n"
    7.55 -          + "   appear in the exclude list.\n";
    7.56 +                "Usage:  jar JarReorder [-o <outputfile>] <order_list> <exclude_list> <file> ...\n"
    7.57 +                + "   order_list    is a file containing names of files to load\n"
    7.58 +                + "                 in order at the end of a jar file unless\n"
    7.59 +                + "                 excluded in the exclude list.\n"
    7.60 +                + "   exclude_list  is a file containing names of files/directories\n"
    7.61 +                + "                 NOT to be included in a jar file.\n"
    7.62 +                + "\n"
    7.63 +                + "The order_list or exclude_list may be replaced by a \"-\" if no\n"
    7.64 +                + "data is to be provided.\n"
    7.65 +                + "\n"
    7.66 +                + "   The remaining arguments are files or directories to be included\n"
    7.67 +                + "   in a jar file, from which will be excluded those entries which\n"
    7.68 +                + "   appear in the exclude list.\n";
    7.69          System.err.println(help);
    7.70 -        System.exit(1);
    7.71      }
    7.72  
    7.73  
    7.74      /*
    7.75 -     * Create a list of files to be included in a jar file, such that the
    7.76 -     * some the files will appear in a specific order, and allowing certain
    7.77 +     * Create the file list to be included in a jar file, such that the
    7.78 +     * list will appear in a specific order, and allowing certain
    7.79       * files and directories to be excluded.
    7.80       *
    7.81 -     * Command line arguments are
    7.82 +     * Command path arguments are
    7.83       *    - optional -o outputfile
    7.84 -     *    - name of a file containing a list of files to be included in a jar file.
    7.85 -     *    - name of a file containing a list of files (or directories) to be
    7.86 +     *    - name of a file containing a set of files to be included in a jar file.
    7.87 +     *    - name of a file containing a set of files (or directories) to be
    7.88       *      excluded from the jar file.
    7.89       *    - names of files or directories to be searched for files to include
    7.90       *      in the jar file.
    7.91       */
    7.92      public static void main(String[] args) {
    7.93 +        JarReorder jr = new JarReorder();
    7.94 +        jr.run(args);
    7.95 +    }
    7.96  
    7.97 -        HashMap filesExcluded = new HashMap();
    7.98 -        Vector filesIncluded = new Vector();
    7.99 -        int fileArgs;
   7.100 -        String topDirName = "";
   7.101 +    private void run(String args[]) {
   7.102 +
   7.103          int arglen = args.length;
   7.104          int argpos = 0;
   7.105  
   7.106          // Look for "-o outputfilename" option
   7.107 -        if ( arglen > 0 ) {
   7.108 -            if ( arglen >= 2 && args[0].equals("-o") ) {
   7.109 +        if (arglen > 0) {
   7.110 +            if (arglen >= 2 && args[0].equals("-o")) {
   7.111                  try {
   7.112                      out = new PrintStream(new FileOutputStream(args[1]));
   7.113 -                } catch ( FileNotFoundException e ) {
   7.114 +                } catch (FileNotFoundException e) {
   7.115                      System.err.println("Error: " + e.getMessage());
   7.116                      e.printStackTrace(System.err);
   7.117                      System.exit(1);
   7.118 @@ -118,128 +111,111 @@
   7.119              out = System.out;
   7.120          }
   7.121  
   7.122 -        fileArgs = useTopDir ? 3 : 2;
   7.123 -
   7.124 -        if (arglen <= fileArgs) {
   7.125 +        // Should be 2 or more args left
   7.126 +        if (arglen <= 2) {
   7.127              usage();
   7.128 +            System.exit(1);
   7.129          }
   7.130  
   7.131 -        // Read the ordered list of files to be included in rt.jar.
   7.132 -        // Read the list of files/directories to be excluded from rt.jar.
   7.133 +        // Read the ordered set of files to be included in rt.jar.
   7.134 +        // Read the set of files/directories to be excluded from rt.jar.
   7.135 +        String classListFile = args[argpos];
   7.136 +        String excludeListFile = args[argpos + 1];
   7.137 +        argpos += 2;
   7.138 +        arglen -= 2;
   7.139  
   7.140 -        Vector orderList = readListFromFile(args[argpos], true);
   7.141 -        Vector excludeList = readListFromFile(args[argpos+1], false);
   7.142 -        if (useTopDir) {
   7.143 -            topDirName = args[argpos+2];
   7.144 -            if (!topDirName.endsWith(File.separator))
   7.145 -                topDirName = topDirName + File.separator;
   7.146 -        }
   7.147 +        // Create 2 lists and a set of processed files
   7.148 +        List<String> orderList = readListFromFile(classListFile, true);
   7.149 +        List<String> excludeList = readListFromFile(excludeListFile, false);
   7.150 +        Set<String> processed = new HashSet<String>();
   7.151  
   7.152 -        // Copy these lists into filesExcluded so that these files will be excluded
   7.153 -        // from the file list. (The orderList files will be appended later.)
   7.154 +        // Create set of all files and directories excluded, then expand
   7.155 +        //   that list completely
   7.156 +        Set<String> excludeSet = new HashSet<String>(excludeList);
   7.157 +        Set<String> allFilesExcluded = expand(null, excludeSet, processed);
   7.158  
   7.159 -        for (int i = 0; i < orderList.size(); ++i) {
   7.160 -            String s = (String) orderList.elementAt(i);
   7.161 -            filesExcluded.put(s, s);
   7.162 -        }
   7.163 -        for (int i = 0; i < excludeList.size(); ++i) {
   7.164 -            String s = (String) excludeList.elementAt(i);
   7.165 -            filesExcluded.put(s, s);
   7.166 -        }
   7.167 +        // Indicate all these have been processed, orderList too, kept to end.
   7.168 +        processed.addAll(orderList);
   7.169  
   7.170          // The remaining arguments are names of files/directories to be included
   7.171          // in the jar file.
   7.172 -
   7.173 -        String[] files = new String[arglen - fileArgs];
   7.174 -        for (int i = fileArgs; i < arglen; ++i) {
   7.175 -            files[i-fileArgs] = args[argpos+i];
   7.176 -            filesExcluded.put(args[argpos+i], args[argpos+i]);
   7.177 +        Set<String> inputSet = new HashSet<String>();
   7.178 +        for (int i = 0; i < arglen; ++i) {
   7.179 +            String name = args[argpos + i];
   7.180 +            name = cleanPath(new File(name));
   7.181 +            if ( name != null && name.length() > 0 && !inputSet.contains(name) ) {
   7.182 +                inputSet.add(name);
   7.183 +            }
   7.184          }
   7.185  
   7.186 -        // Expand file/directory list to file list excluding those
   7.187 -        // read from the class list.
   7.188 +        // Expand file/directory input so we get a complete set (except ordered)
   7.189 +        //   Should be everything not excluded and not in order list.
   7.190 +        Set<String> allFilesIncluded = expand(null, inputSet, processed);
   7.191  
   7.192 -        if (useTopDir)
   7.193 -            expand(new File(topDirName), files, filesIncluded, filesExcluded, topDirName);
   7.194 -        else
   7.195 -            expand(null, files, filesIncluded, filesExcluded, null);
   7.196 +        // Create simple sorted list so we can add ordered items at end.
   7.197 +        List<String> allFiles = new ArrayList<String>(allFilesIncluded);
   7.198 +        Collections.sort(allFiles);
   7.199  
   7.200 -        // Now add the ordered list to the end of the expanded list.
   7.201 +        // Now add the ordered set to the end of the list.
   7.202          // Add in REVERSE ORDER, so that the first element is closest to
   7.203          // the end (and the index).
   7.204 -
   7.205 -        HashSet excludeSet = new HashSet(excludeList);
   7.206          for (int i = orderList.size() - 1; i >= 0; --i) {
   7.207 -            String s = (String) orderList.elementAt(i);
   7.208 -            if (excludeSet.contains(s)) {
   7.209 -                System.err.println("Included file " + s + " is also excluded, skipping.");
   7.210 -                continue;
   7.211 +            String s = orderList.get(i);
   7.212 +            if (allFilesExcluded.contains(s)) {
   7.213 +                System.err.println("Included order file " + s
   7.214 +                    + " is also excluded, skipping.");
   7.215 +            } else if (new File(s).exists()) {
   7.216 +                allFiles.add(s);
   7.217 +            } else {
   7.218 +                System.err.println("Included order file " + s
   7.219 +                    + " missing, skipping.");
   7.220              }
   7.221 -            if (new File(topDirName + s).exists())
   7.222 -                filesIncluded.addElement(s);
   7.223 -            else
   7.224 -                System.err.println("Included file "+s+" missing, skipping.");
   7.225          }
   7.226  
   7.227 -        // Print results.
   7.228 -
   7.229 -        for (int i = 0; i < filesIncluded.size(); ++i) {
   7.230 -            if (useTopDir) {
   7.231 -                out.print("-C ");
   7.232 -                out.print(topDirName);
   7.233 -                out.print(" ");
   7.234 -            }
   7.235 -            out.println((String)filesIncluded.elementAt(i));
   7.236 +        // Print final results.
   7.237 +        for (String str : allFiles) {
   7.238 +            out.println(str);
   7.239          }
   7.240 -
   7.241          out.flush();
   7.242          out.close();
   7.243      }
   7.244  
   7.245 -
   7.246      /*
   7.247 -     * Read a file containing a list of files into a Vector.
   7.248 +     * Read a file containing a list of files and directories into a List.
   7.249       */
   7.250 -    private static Vector readListFromFile(String fileName,
   7.251 -                                           boolean addClassSuffix) {
   7.252 +    private List<String> readListFromFile(String fileName,
   7.253 +            boolean addClassSuffix) {
   7.254  
   7.255          BufferedReader br = null;
   7.256 -        Vector v = new Vector(2000);
   7.257 -
   7.258 -        if ("-".equals(fileName))
   7.259 -            return v;
   7.260 -
   7.261 +        List<String> list = new ArrayList<String>();
   7.262 +        // If you see "-" for the name, just assume nothing was provided.
   7.263 +        if ("-".equals(fileName)) {
   7.264 +            return list;
   7.265 +        }
   7.266          try {
   7.267              br = new BufferedReader(new FileReader(fileName));
   7.268 -
   7.269 -        // Read the input file a line at a time. # in column 1 is a comment.
   7.270 -
   7.271 +            // Read the input file a path at a time. # in column 1 is a comment.
   7.272              while (true) {
   7.273 -                String line = null;
   7.274 -                line = br.readLine();
   7.275 -
   7.276 -                if (line == null)
   7.277 +                String path = br.readLine();
   7.278 +                if (path == null) {
   7.279                      break;
   7.280 -
   7.281 -                if (line.length() == 0    ||
   7.282 -                    line.charAt(0) == '#')
   7.283 +                }
   7.284 +                // Look for comments
   7.285 +                path = path.trim();
   7.286 +                if (path.length() == 0
   7.287 +                        || path.charAt(0) == '#') {
   7.288                      continue;
   7.289 -
   7.290 -                // Convert forward or back slashes to the type expected for
   7.291 -                // the current platform.
   7.292 -
   7.293 -                if (File.separatorChar == '/')
   7.294 -                    line = line.replace('\\', '/');
   7.295 -                else
   7.296 -                    line = line.replace('/', '\\');
   7.297 -
   7.298 -                line = line.trim();
   7.299 -                if (addClassSuffix) {
   7.300 -                    if (!line.endsWith(".class")) {
   7.301 -                        line = line + ".class";
   7.302 -                    }
   7.303                  }
   7.304 -                v.addElement(line);
   7.305 +                // Add trailing .class if necessary
   7.306 +                if (addClassSuffix && !path.endsWith(".class")) {
   7.307 +                    path = path + ".class";
   7.308 +                }
   7.309 +                // Normalize the path
   7.310 +                path = cleanPath(new File(path));
   7.311 +                // Add to list
   7.312 +                if (path != null && path.length() > 0 && !list.contains(path)) {
   7.313 +                    list.add(path);
   7.314 +                }
   7.315              }
   7.316              br.close();
   7.317          } catch (FileNotFoundException e) {
   7.318 @@ -249,68 +225,89 @@
   7.319              e.printStackTrace();
   7.320              System.exit(2);
   7.321          }
   7.322 -        return v;
   7.323 +        return list;
   7.324      }
   7.325  
   7.326 -
   7.327      /*
   7.328 -     * Expands list of files to process into full list of all files that
   7.329 +     * Expands inputSet (files or dirs) into full set of all files that
   7.330       * can be found by recursively descending directories.
   7.331 +     * @param dir root directory
   7.332 +     * @param inputSet set of files or dirs to look into
   7.333 +     * @param processed files or dirs already processed
   7.334 +     * @return set of files
   7.335       */
   7.336 -    private static void expand(File dir, String[] files,
   7.337 -                               Vector includedFiles, HashMap excludedFiles,
   7.338 -                               String topDirName) {
   7.339 -        if (files == null) {
   7.340 -            return;
   7.341 +    private Set<String> expand(File dir,
   7.342 +            Set<String> inputSet,
   7.343 +            Set<String> processed) {
   7.344 +        Set<String> includedFiles = new HashSet<String>();
   7.345 +        if (inputSet.isEmpty()) {
   7.346 +            return includedFiles;
   7.347          }
   7.348 -        for (int i = 0; i < files.length; i++) {
   7.349 -            File f = (dir == null) ? new File(files[i])
   7.350 -                                   : new File(dir, files[i]);
   7.351 -            if (f.isFile()) {
   7.352 -                String filePath = f.getPath();
   7.353 -
   7.354 -                if (useTopDir) {
   7.355 -                    if (filePath.startsWith(topDirName))
   7.356 -                        filePath = filePath.substring(topDirName.length());
   7.357 +        for (String name : inputSet) {
   7.358 +            // Depending on start location
   7.359 +            File f = (dir == null) ? new File(name)
   7.360 +                    : new File(dir, name);
   7.361 +            // Normalized path to use
   7.362 +            String path = cleanPath(f);
   7.363 +            if (path != null && path.length() > 0
   7.364 +                    && !processed.contains(path)) {
   7.365 +                if (f.isFile()) {
   7.366 +                    // Not in the excludeList, add it to both lists
   7.367 +                    includedFiles.add(path);
   7.368 +                    processed.add(path);
   7.369 +                } else if (f.isDirectory()) {
   7.370 +                    // Add the directory entries
   7.371 +                    String[] dirList = f.list();
   7.372 +                    Set<String> dirInputSet = new HashSet<String>();
   7.373 +                    for (String x : dirList) {
   7.374 +                        dirInputSet.add(x);
   7.375 +                    }
   7.376 +                    // Process all entries in this directory
   7.377 +                    Set<String> subList = expand(f, dirInputSet, processed);
   7.378 +                    includedFiles.addAll(subList);
   7.379 +                    processed.add(path);
   7.380                  }
   7.381 -
   7.382 -                if (filePath.length() >= 2 &&
   7.383 -                    filePath.charAt(0) == '.' &&
   7.384 -                    filePath.charAt(1) == File.separatorChar)
   7.385 -                    filePath = filePath.substring(2);
   7.386 -
   7.387 -                if (!excludedFiles.containsKey(filePath)) {
   7.388 -                    excludedFiles.put(filePath, filePath);
   7.389 -                    includedFiles.addElement(filePath);
   7.390 -                }
   7.391 -            } else if (f.isDirectory()) {
   7.392 -                String dirPath = f.getPath();
   7.393 -                dirPath = (dirPath.endsWith(File.separator)) ? dirPath :
   7.394 -                    (dirPath + File.separator);
   7.395 -
   7.396 -                if (useTopDir) {
   7.397 -                    if (dirPath.startsWith(topDirName))
   7.398 -                        dirPath = dirPath.substring(topDirName.length());
   7.399 -                }
   7.400 -
   7.401 -                if (dirPath.length() >= 2 &&
   7.402 -                    dirPath.charAt(0) == '.' &&
   7.403 -                    dirPath.charAt(1) == File.separatorChar)
   7.404 -                    dirPath = dirPath.substring(2);
   7.405 -
   7.406 -                if (!excludedFiles.containsKey(dirPath)) {
   7.407 -
   7.408 -                    // Sort the directory list so that entries in the jar file
   7.409 -                    // are in a repeatable order.  The order itself is not particularly
   7.410 -                    // important.  [File.list() is unpredictable.]
   7.411 -
   7.412 -                    String[] dirList = f.list();
   7.413 -                    Arrays.sort(dirList);
   7.414 -                    expand(f, dirList, includedFiles, excludedFiles, topDirName);
   7.415 -                }
   7.416 -            } else {
   7.417 -                System.err.println("Error accessing: " + f.getPath());
   7.418              }
   7.419          }
   7.420 +        return includedFiles;
   7.421      }
   7.422 +
   7.423 +    private String cleanPath(File f) {
   7.424 +        String path = f.getPath();
   7.425 +        if (f.isFile()) {
   7.426 +            path = cleanFilePath(path);
   7.427 +        } else if (f.isDirectory()) {
   7.428 +            path = cleanDirPath(path);
   7.429 +        } else {
   7.430 +            System.err.println("WARNING: Path does not exist as file or directory: " + path);
   7.431 +            path = null;
   7.432 +        }
   7.433 +        return path;
   7.434 +    }
   7.435 +
   7.436 +    private String cleanFilePath(String path) {
   7.437 +        // Remove leading and trailing whitespace
   7.438 +        path = path.trim();
   7.439 +        // Make all / and \ chars one
   7.440 +        if (File.separatorChar == '/') {
   7.441 +            path = path.replace('\\', '/');
   7.442 +        } else {
   7.443 +            path = path.replace('/', '\\');
   7.444 +        }
   7.445 +        // Remove leading ./
   7.446 +        if (path.startsWith("." + File.separator)) {
   7.447 +            path = path.substring(2);
   7.448 +        }
   7.449 +        return path;
   7.450 +    }
   7.451 +
   7.452 +    private String cleanDirPath(String path) {
   7.453 +        path = cleanFilePath(path);
   7.454 +        // Make sure it ends with a file separator
   7.455 +        if (!path.endsWith(File.separator)) {
   7.456 +            path = path + File.separator;
   7.457 +        }
   7.458 +        return path;
   7.459 +    }
   7.460 +
   7.461  }
     8.1 --- a/src/share/bin/emessages.h	Thu Jul 15 20:11:45 2010 -0700
     8.2 +++ b/src/share/bin/emessages.h	Tue Jul 20 22:21:31 2010 -0700
     8.3 @@ -1,5 +1,5 @@
     8.4  /*
     8.5 - * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
     8.6 + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
     8.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.8   *
     8.9   * This code is free software; you can redistribute it and/or modify it
    8.10 @@ -44,7 +44,7 @@
    8.11  
    8.12  #define JVM_ERROR1      "Error: Could not create the Java Virtual Machine.\n" GEN_ERROR
    8.13  #define JVM_ERROR2      "Error: Could not detach main thread.\n" JNI_ERROR
    8.14 -#define JVM_ERROR3      "Error: SPARC V8 processor detected; Server compiler requires V9 or better.\nUse Client compiler on V8 processors.\nCould not create the Java virtual machine."
    8.15 +#define JVM_ERROR3      "Error: SPARC V8 processor detected;  Required V9 processors or better.\nUse JDK5 client compiler for V8 processors.\n" JVM_ERROR1
    8.16  
    8.17  #define JAR_ERROR1      "Error: Failed to load Main-Class manifest attribute from\n%s\n%s"
    8.18  #define JAR_ERROR2      "Error: Unable to access jarfile %s"
    8.19 @@ -69,7 +69,8 @@
    8.20  #define CFG_ERROR5      "Error: Could not determine application home."
    8.21  #define CFG_ERROR6      "Error: could not open `%s'"
    8.22  #define CFG_ERROR7      "Error: no known VMs. (check for corrupt jvm.cfg file)"
    8.23 -#define CFG_ERROR8      "Error: no `%s' JVM at `%s'."
    8.24 +#define CFG_ERROR8      "Error: missing `%s' JVM at `%s'.\nPlease install or use the JRE or JDK that contains these missing components."
    8.25 +#define CFG_ERROR9      "Error: could not determine JVM type."
    8.26  
    8.27  
    8.28  #define SPC_ERROR1      "Error: Syntax error in version specification \"%s\""
     9.1 --- a/src/share/bin/java.c	Thu Jul 15 20:11:45 2010 -0700
     9.2 +++ b/src/share/bin/java.c	Tue Jul 20 22:21:31 2010 -0700
     9.3 @@ -1,5 +1,5 @@
     9.4  /*
     9.5 - * Copyright (c) 1995, 2009, Oracle and/or its affiliates. All rights reserved.
     9.6 + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
     9.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.8   *
     9.9   * This code is free software; you can redistribute it and/or modify it
    9.10 @@ -192,8 +192,8 @@
    9.11      int ret;
    9.12      InvocationFunctions ifn;
    9.13      jlong start, end;
    9.14 -    char jrepath[MAXPATHLEN], jvmpath[MAXPATHLEN];
    9.15 -    char ** original_argv = argv;
    9.16 +    char jvmpath[MAXPATHLEN];
    9.17 +    char jrepath[MAXPATHLEN];
    9.18  
    9.19      _fVersion = fullversion;
    9.20      _dVersion = dotversion;
    9.21 @@ -225,14 +225,17 @@
    9.22       */
    9.23      SelectVersion(argc, argv, &main_class);
    9.24  
    9.25 -    /* copy original argv */
    9.26 -    JLI_TraceLauncher("Command line Args:\n");
    9.27 -    original_argv = (JLI_CopyArgs(argc, (const char**)argv));
    9.28 +    if (JLI_IsTraceLauncher()) {
    9.29 +        int i;
    9.30 +        printf("Command line args:\n");
    9.31 +        for (i = 0; i < argc ; i++) {
    9.32 +            printf("argv[%d] = %s\n", i, argv[i]);
    9.33 +        }
    9.34 +    }
    9.35  
    9.36      CreateExecutionEnvironment(&argc, &argv,
    9.37                                 jrepath, sizeof(jrepath),
    9.38 -                               jvmpath, sizeof(jvmpath),
    9.39 -                               original_argv);
    9.40 +                               jvmpath, sizeof(jvmpath));
    9.41  
    9.42      ifn.CreateJavaVM = 0;
    9.43      ifn.GetDefaultJavaVMInitArgs = 0;
    9.44 @@ -301,22 +304,43 @@
    9.45      return ContinueInNewThread(&ifn, argc, argv, jarfile, classname, ret);
    9.46  
    9.47  }
    9.48 +/*
    9.49 + * Always detach the main thread so that it appears to have ended when
    9.50 + * the application's main method exits.  This will invoke the
    9.51 + * uncaught exception handler machinery if main threw an
    9.52 + * exception.  An uncaught exception handler cannot change the
    9.53 + * launcher's return code except by calling System.exit.
    9.54 + *
    9.55 + * Wait for all non-daemon threads to end, then destroy the VM.
    9.56 + * This will actually create a trivial new Java waiter thread
    9.57 + * named "DestroyJavaVM", but this will be seen as a different
    9.58 + * thread from the one that executed main, even though they are
    9.59 + * the same C thread.  This allows mainThread.join() and
    9.60 + * mainThread.isAlive() to work as expected.
    9.61 + */
    9.62 +#define LEAVE() \
    9.63 +    if ((*vm)->DetachCurrentThread(vm) != 0) { \
    9.64 +        JLI_ReportErrorMessage(JVM_ERROR2); \
    9.65 +        ret = 1; \
    9.66 +    } \
    9.67 +    (*vm)->DestroyJavaVM(vm); \
    9.68 +    return ret \
    9.69  
    9.70  #define CHECK_EXCEPTION_NULL_LEAVE(e) \
    9.71      if ((*env)->ExceptionOccurred(env)) { \
    9.72          JLI_ReportExceptionDescription(env); \
    9.73 -        goto leave; \
    9.74 +        LEAVE(); \
    9.75      } \
    9.76      if ((e) == NULL) { \
    9.77          JLI_ReportErrorMessage(JNI_ERROR); \
    9.78 -        goto leave; \
    9.79 +        LEAVE(); \
    9.80      }
    9.81  
    9.82  #define CHECK_EXCEPTION_LEAVE(rv) \
    9.83      if ((*env)->ExceptionOccurred(env)) { \
    9.84          JLI_ReportExceptionDescription(env); \
    9.85          ret = (rv); \
    9.86 -        goto leave; \
    9.87 +        LEAVE(); \
    9.88      }
    9.89  
    9.90  int JNICALL
    9.91 @@ -349,8 +373,7 @@
    9.92          PrintJavaVersion(env, showVersion);
    9.93          CHECK_EXCEPTION_LEAVE(0);
    9.94          if (printVersion) {
    9.95 -            ret = 0;
    9.96 -            goto leave;
    9.97 +            LEAVE();
    9.98          }
    9.99      }
   9.100  
   9.101 @@ -358,7 +381,7 @@
   9.102      if (printXUsage || printUsage || (jarfile == 0 && classname == 0)) {
   9.103          PrintUsage(env, printXUsage);
   9.104          CHECK_EXCEPTION_LEAVE(1);
   9.105 -        goto leave;
   9.106 +        LEAVE();
   9.107      }
   9.108  
   9.109      FreeKnownVMs();  /* after last possible PrintUsage() */
   9.110 @@ -430,30 +453,7 @@
   9.111       * System.exit) will be non-zero if main threw an exception.
   9.112       */
   9.113      ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1;
   9.114 -
   9.115 -leave:
   9.116 -    /*
   9.117 -     * Always detach the main thread so that it appears to have ended when
   9.118 -     * the application's main method exits.  This will invoke the
   9.119 -     * uncaught exception handler machinery if main threw an
   9.120 -     * exception.  An uncaught exception handler cannot change the
   9.121 -     * launcher's return code except by calling System.exit.
   9.122 -     */
   9.123 -    if ((*vm)->DetachCurrentThread(vm) != 0) {
   9.124 -        JLI_ReportErrorMessage(JVM_ERROR2);
   9.125 -        ret = 1;
   9.126 -    }
   9.127 -    /*
   9.128 -     * Wait for all non-daemon threads to end, then destroy the VM.
   9.129 -     * This will actually create a trivial new Java waiter thread
   9.130 -     * named "DestroyJavaVM", but this will be seen as a different
   9.131 -     * thread from the one that executed main, even though they are
   9.132 -     * the same C thread.  This allows mainThread.join() and
   9.133 -     * mainThread.isAlive() to work as expected.
   9.134 -     */
   9.135 -    (*vm)->DestroyJavaVM(vm);
   9.136 -
   9.137 -    return ret;
   9.138 +    LEAVE();
   9.139  }
   9.140  
   9.141  /*
   9.142 @@ -1076,15 +1076,17 @@
   9.143      if (--argc >= 0) {
   9.144          if (jarflag) {
   9.145              *pjarfile = *argv++;
   9.146 -            *pclassname = 0;
   9.147 +            *pclassname = NULL;
   9.148          } else {
   9.149 -            *pjarfile = 0;
   9.150 +            *pjarfile = NULL;
   9.151              *pclassname = *argv++;
   9.152          }
   9.153          *pargc = argc;
   9.154          *pargv = argv;
   9.155      }
   9.156 -
   9.157 +    if (*pjarfile == NULL && *pclassname == NULL) {
   9.158 +        *pret = 1;
   9.159 +    }
   9.160      return JNI_TRUE;
   9.161  }
   9.162  
    10.1 --- a/src/share/bin/java.h	Thu Jul 15 20:11:45 2010 -0700
    10.2 +++ b/src/share/bin/java.h	Tue Jul 20 22:21:31 2010 -0700
    10.3 @@ -1,5 +1,5 @@
    10.4  /*
    10.5 - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
    10.6 + * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
    10.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.8   *
    10.9   * This code is free software; you can redistribute it and/or modify it
   10.10 @@ -114,13 +114,19 @@
   10.11  
   10.12  #define GetArch() GetArchPath(CURRENT_DATA_MODEL)
   10.13  
   10.14 -void CreateExecutionEnvironment(int *_argc,
   10.15 -                                       char ***_argv,
   10.16 -                                       char jrepath[],
   10.17 -                                       jint so_jrepath,
   10.18 -                                       char jvmpath[],
   10.19 -                                       jint so_jvmpath,
   10.20 -                                       char **original_argv);
   10.21 +/*
   10.22 + * Different platforms will implement this, here
   10.23 + * pargc is a pointer to the original argc,
   10.24 + * pargv is a pointer to the original argv,
   10.25 + * jrepath is an accessible path to the jre as determined by the call
   10.26 + * so_jrepath is the length of the buffer jrepath
   10.27 + * jvmpath is an accessible path to the jvm as determined by the call
   10.28 + * so_jvmpath is the length of the buffer jvmpath
   10.29 + */
   10.30 +void CreateExecutionEnvironment(int *argc, char ***argv,
   10.31 +                                char *jrepath, jint so_jrepath,
   10.32 +                                char *jvmpath, jint so_jvmpath);
   10.33 +
   10.34  /* Reports an error message to stderr or a window as appropriate. */
   10.35  void JLI_ReportErrorMessage(const char * message, ...);
   10.36  
    11.1 --- a/src/share/bin/jli_util.c	Thu Jul 15 20:11:45 2010 -0700
    11.2 +++ b/src/share/bin/jli_util.c	Tue Jul 20 22:21:31 2010 -0700
    11.3 @@ -1,5 +1,5 @@
    11.4  /*
    11.5 - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
    11.6 + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
    11.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.8   *
    11.9   * This code is free software; you can redistribute it and/or modify it
   11.10 @@ -85,23 +85,6 @@
   11.11  }
   11.12  
   11.13  /*
   11.14 - * Makes a copy of arguments
   11.15 - */
   11.16 -char**
   11.17 -JLI_CopyArgs(int argc, const char **iargv)
   11.18 -{
   11.19 -    int i;
   11.20 -    char** oargv = (char**)JLI_MemAlloc(sizeof(char*)*(argc+1));
   11.21 -    for (i = 0 ; i < argc+1 ; i++) {
   11.22 -        oargv[i] = (iargv[i] == NULL) ? NULL : JLI_StringDup(iargv[i]);
   11.23 -        if (iargv[i] != NULL && JLI_IsTraceLauncher() == JNI_TRUE) {
   11.24 -            printf("\targv[%d] = '%s'\n",i,iargv[i]);
   11.25 -        }
   11.26 -    }
   11.27 -    return oargv;
   11.28 -}
   11.29 -
   11.30 -/*
   11.31   * debug helpers we use
   11.32   */
   11.33  static jboolean _launcher_debug = JNI_FALSE;
    12.1 --- a/src/share/bin/jli_util.h	Thu Jul 15 20:11:45 2010 -0700
    12.2 +++ b/src/share/bin/jli_util.h	Tue Jul 20 22:21:31 2010 -0700
    12.3 @@ -1,5 +1,5 @@
    12.4  /*
    12.5 - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
    12.6 + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
    12.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    12.8   *
    12.9   * This code is free software; you can redistribute it and/or modify it
   12.10 @@ -33,7 +33,6 @@
   12.11  void *JLI_MemRealloc(void *ptr, size_t size);
   12.12  char *JLI_StringDup(const char *s1);
   12.13  void  JLI_MemFree(void *ptr);
   12.14 -char **JLI_CopyArgs(int argc, const char **iargv);
   12.15  int   JLI_StrCCmp(const char *s1, const char* s2);
   12.16  
   12.17  
   12.18 @@ -56,10 +55,12 @@
   12.19  #include <io.h>
   12.20  #define JLI_StrCaseCmp(p1, p2)          stricmp((p1), (p2))
   12.21  #define JLI_StrNCaseCmp(p1, p2, p3)     strnicmp((p1), (p2), (p3))
   12.22 +#define JLI_Snprintf                    _snprintf
   12.23  #else
   12.24  #include <unistd.h>
   12.25  #define JLI_StrCaseCmp(p1, p2)          strcasecmp((p1), (p2))
   12.26  #define JLI_StrNCaseCmp(p1, p2, p3)     strncasecmp((p1), (p2), (p3))
   12.27 +#define JLI_Snprintf                    snprintf
   12.28  #endif /* _WIN32 */
   12.29  
   12.30  /*
    13.1 --- a/src/share/classes/com/sun/beans/finder/InstanceFinder.java	Thu Jul 15 20:11:45 2010 -0700
    13.2 +++ b/src/share/classes/com/sun/beans/finder/InstanceFinder.java	Tue Jul 20 22:21:31 2010 -0700
    13.3 @@ -1,5 +1,5 @@
    13.4  /*
    13.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
    13.6 + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
    13.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.8   *
    13.9   * This code is free software; you can redistribute it and/or modify it
   13.10 @@ -39,7 +39,7 @@
   13.11      private final Class<? extends T> type;
   13.12      private final boolean allow;
   13.13      private final String suffix;
   13.14 -    private String[] packages;
   13.15 +    private volatile String[] packages;
   13.16  
   13.17      InstanceFinder(Class<? extends T> type, boolean allow, String suffix, String... packages) {
   13.18          this.type = type;
   13.19 @@ -49,9 +49,7 @@
   13.20      }
   13.21  
   13.22      public String[] getPackages() {
   13.23 -        return (this.packages.length > 0)
   13.24 -                ? this.packages.clone()
   13.25 -                : this.packages;
   13.26 +        return this.packages.clone();
   13.27      }
   13.28  
   13.29      public void setPackages(String... packages) {
    14.1 --- a/src/share/classes/com/sun/beans/finder/MethodFinder.java	Thu Jul 15 20:11:45 2010 -0700
    14.2 +++ b/src/share/classes/com/sun/beans/finder/MethodFinder.java	Tue Jul 20 22:21:31 2010 -0700
    14.3 @@ -1,5 +1,5 @@
    14.4  /*
    14.5 - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
    14.6 + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
    14.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    14.8   *
    14.9   * This code is free software; you can redistribute it and/or modify it
   14.10 @@ -118,7 +118,7 @@
   14.11       * @throws NoSuchMethodException if method is not accessible or is not found
   14.12       *                               in specified superclass or interface
   14.13       */
   14.14 -    private static Method findAccessibleMethod(Method method) throws NoSuchMethodException {
   14.15 +    public static Method findAccessibleMethod(Method method) throws NoSuchMethodException {
   14.16          Class<?> type = method.getDeclaringClass();
   14.17          if (Modifier.isPublic(type.getModifiers())) {
   14.18              return method;
    15.1 --- a/src/share/classes/com/sun/beans/finder/PersistenceDelegateFinder.java	Thu Jul 15 20:11:45 2010 -0700
    15.2 +++ b/src/share/classes/com/sun/beans/finder/PersistenceDelegateFinder.java	Tue Jul 20 22:21:31 2010 -0700
    15.3 @@ -1,5 +1,5 @@
    15.4  /*
    15.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
    15.6 + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
    15.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    15.8   *
    15.9   * This code is free software; you can redistribute it and/or modify it
   15.10 @@ -47,17 +47,22 @@
   15.11      }
   15.12  
   15.13      public void register(Class<?> type, PersistenceDelegate delegate) {
   15.14 -        if (delegate != null) {
   15.15 -            this.registry.put(type, delegate);
   15.16 -        }
   15.17 -        else {
   15.18 -            this.registry.remove(type);
   15.19 +        synchronized (this.registry) {
   15.20 +            if (delegate != null) {
   15.21 +                this.registry.put(type, delegate);
   15.22 +            }
   15.23 +            else {
   15.24 +                this.registry.remove(type);
   15.25 +            }
   15.26          }
   15.27      }
   15.28  
   15.29      @Override
   15.30      public PersistenceDelegate find(Class<?> type) {
   15.31 -        PersistenceDelegate delegate = this.registry.get(type);
   15.32 +        PersistenceDelegate delegate;
   15.33 +        synchronized (this.registry) {
   15.34 +            delegate = this.registry.get(type);
   15.35 +        }
   15.36          return (delegate != null) ? delegate : super.find(type);
   15.37      }
   15.38  }
    16.1 --- a/src/share/classes/com/sun/beans/finder/PropertyEditorFinder.java	Thu Jul 15 20:11:45 2010 -0700
    16.2 +++ b/src/share/classes/com/sun/beans/finder/PropertyEditorFinder.java	Tue Jul 20 22:21:31 2010 -0700
    16.3 @@ -1,5 +1,5 @@
    16.4  /*
    16.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
    16.6 + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
    16.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    16.8   *
    16.9   * This code is free software; you can redistribute it and/or modify it
   16.10 @@ -64,12 +64,18 @@
   16.11      }
   16.12  
   16.13      public void register(Class<?> type, Class<?> editor) {
   16.14 -        this.registry.put(type, editor);
   16.15 +        synchronized (this.registry) {
   16.16 +            this.registry.put(type, editor);
   16.17 +        }
   16.18      }
   16.19  
   16.20      @Override
   16.21      public PropertyEditor find(Class<?> type) {
   16.22 -        PropertyEditor editor = instantiate(this.registry.get(type), null);
   16.23 +        Class<?> predefined;
   16.24 +        synchronized (this.registry) {
   16.25 +            predefined = this.registry.get(type);
   16.26 +        }
   16.27 +        PropertyEditor editor = instantiate(predefined, null);
   16.28          if (editor == null) {
   16.29              editor = super.find(type);
   16.30              if ((editor == null) && (null != type.getEnumConstants())) {
    17.1 --- a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java	Thu Jul 15 20:11:45 2010 -0700
    17.2 +++ b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java	Tue Jul 20 22:21:31 2010 -0700
    17.3 @@ -1440,10 +1440,6 @@
    17.4              }
    17.5          }
    17.6  
    17.7 -        public Insets getBorderInsets(Component c) {
    17.8 -            return getBorderInsets(c, null);
    17.9 -        }
   17.10 -
   17.11          public Insets getBorderInsets(Component c, Insets i) {
   17.12              SynthContext context = getContext(c);
   17.13  
    18.1 --- a/src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java	Thu Jul 15 20:11:45 2010 -0700
    18.2 +++ b/src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java	Tue Jul 20 22:21:31 2010 -0700
    18.3 @@ -1,5 +1,5 @@
    18.4  /*
    18.5 - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
    18.6 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
    18.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    18.8   *
    18.9   * This code is free software; you can redistribute it and/or modify it
   18.10 @@ -271,7 +271,9 @@
   18.11      }
   18.12  
   18.13      public void uninstallUI(JComponent c) {
   18.14 -        getFileChooser().removeAll();
   18.15 +        c.removePropertyChangeListener(filterComboBoxModel);
   18.16 +        approveButton.removeActionListener(getApproveSelectionAction());
   18.17 +        filenameTextField.removeActionListener(getApproveSelectionAction());
   18.18          super.uninstallUI(c);
   18.19      }
   18.20  
   18.21 @@ -515,6 +517,7 @@
   18.22  
   18.23      public void uninstallComponents(JFileChooser fc) {
   18.24          fc.removeAll();
   18.25 +        bottomPanel = null;
   18.26          if (filterComboBoxModel != null) {
   18.27              fc.removePropertyChangeListener(filterComboBoxModel);
   18.28          }
    19.1 --- a/src/share/classes/java/awt/EventDispatchThread.java	Thu Jul 15 20:11:45 2010 -0700
    19.2 +++ b/src/share/classes/java/awt/EventDispatchThread.java	Tue Jul 20 22:21:31 2010 -0700
    19.3 @@ -61,85 +61,43 @@
    19.4   * @since 1.1
    19.5   */
    19.6  class EventDispatchThread extends Thread {
    19.7 +
    19.8      private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventDispatchThread");
    19.9  
   19.10      private EventQueue theQueue;
   19.11      private boolean doDispatch = true;
   19.12 +    private boolean threadDeathCaught = false;
   19.13 +
   19.14      private static final int ANY_EVENT = -1;
   19.15  
   19.16      private Vector<EventFilter> eventFilters = new Vector<EventFilter>();
   19.17 -    // used in handleException
   19.18 -    private int modalFiltersCount = 0;
   19.19  
   19.20      EventDispatchThread(ThreadGroup group, String name, EventQueue queue) {
   19.21          super(group, name);
   19.22 -        theQueue = queue;
   19.23 +        setEventQueue(queue);
   19.24      }
   19.25  
   19.26 -    void stopDispatchingImpl(boolean wait) {
   19.27 -        // Note: We stop dispatching via a flag rather than using
   19.28 -        // Thread.interrupt() because we can't guarantee that the wait()
   19.29 -        // we interrupt will be EventQueue.getNextEvent()'s.  -fredx 8-11-98
   19.30 -
   19.31 -        StopDispatchEvent stopEvent = new StopDispatchEvent();
   19.32 -
   19.33 -        // wait for the dispatcher to complete
   19.34 -        if (Thread.currentThread() != this) {
   19.35 -
   19.36 -            // fix 4122683, 4128923
   19.37 -            // Post an empty event to ensure getNextEvent is unblocked
   19.38 -            //
   19.39 -            // We have to use postEventPrivate instead of postEvent because
   19.40 -            // EventQueue.pop calls EventDispatchThread.stopDispatching.
   19.41 -            // Calling SunToolkit.flushPendingEvents in this case could
   19.42 -            // lead to deadlock.
   19.43 -            theQueue.postEventPrivate(stopEvent);
   19.44 -
   19.45 -            if (wait) {
   19.46 -                try {
   19.47 -                    join();
   19.48 -                } catch(InterruptedException e) {
   19.49 -                }
   19.50 -            }
   19.51 -        } else {
   19.52 -            stopEvent.dispatch();
   19.53 -        }
   19.54 -
   19.55 -        theQueue.detachDispatchThread(this, false);
   19.56 -    }
   19.57 -
   19.58 +    /*
   19.59 +     * Must be called on EDT only, that's why no synchronization
   19.60 +     */
   19.61      public void stopDispatching() {
   19.62 -        stopDispatchingImpl(true);
   19.63 -    }
   19.64 -
   19.65 -    public void stopDispatchingLater() {
   19.66 -        stopDispatchingImpl(false);
   19.67 -    }
   19.68 -
   19.69 -    class StopDispatchEvent extends AWTEvent implements ActiveEvent {
   19.70 -        /*
   19.71 -         * serialVersionUID
   19.72 -         */
   19.73 -        static final long serialVersionUID = -3692158172100730735L;
   19.74 -
   19.75 -        public StopDispatchEvent() {
   19.76 -            super(EventDispatchThread.this,0);
   19.77 -        }
   19.78 -
   19.79 -        public void dispatch() {
   19.80 -            doDispatch = false;
   19.81 -        }
   19.82 +        doDispatch = false;
   19.83      }
   19.84  
   19.85      public void run() {
   19.86 -        try {
   19.87 -            pumpEvents(new Conditional() {
   19.88 -                public boolean evaluate() {
   19.89 -                    return true;
   19.90 +        while (true) {
   19.91 +            try {
   19.92 +                pumpEvents(new Conditional() {
   19.93 +                    public boolean evaluate() {
   19.94 +                        return true;
   19.95 +                    }
   19.96 +                });
   19.97 +            } finally {
   19.98 +                EventQueue eq = getEventQueue();
   19.99 +                if (eq.detachDispatchThread(this) || threadDeathCaught) {
  19.100 +                    break;
  19.101                  }
  19.102 -            });
  19.103 -        } finally {
  19.104 -            theQueue.detachDispatchThread(this, true);
  19.105 +            }
  19.106          }
  19.107      }
  19.108  
  19.109 @@ -190,7 +148,6 @@
  19.110                          }
  19.111                      }
  19.112                      eventFilters.add(k, filter);
  19.113 -                    modalFiltersCount++;
  19.114                  } else {
  19.115                      eventFilters.add(filter);
  19.116                  }
  19.117 @@ -200,28 +157,25 @@
  19.118  
  19.119      void removeEventFilter(EventFilter filter) {
  19.120          synchronized (eventFilters) {
  19.121 -            if (eventFilters.contains(filter)) {
  19.122 -                if (filter instanceof ModalEventFilter) {
  19.123 -                    modalFiltersCount--;
  19.124 -                }
  19.125 -                eventFilters.remove(filter);
  19.126 -            }
  19.127 +            eventFilters.remove(filter);
  19.128          }
  19.129      }
  19.130  
  19.131      boolean pumpOneEventForFilters(int id) {
  19.132 +        AWTEvent event = null;
  19.133 +        boolean eventOK = false;
  19.134          try {
  19.135 -            AWTEvent event;
  19.136 -            boolean eventOK;
  19.137 -            EventQueueDelegate.Delegate delegate =
  19.138 -                EventQueueDelegate.getDelegate();
  19.139 +            EventQueue eq = null;
  19.140 +            EventQueueDelegate.Delegate delegate = null;
  19.141              do {
  19.142 +                // EventQueue may change during the dispatching
  19.143 +                eq = getEventQueue();
  19.144 +                delegate = EventQueueDelegate.getDelegate();
  19.145 +
  19.146                  if (delegate != null && id == ANY_EVENT) {
  19.147 -                    event = delegate.getNextEvent(theQueue);
  19.148 +                    event = delegate.getNextEvent(eq);
  19.149                  } else {
  19.150 -                    event = (id == ANY_EVENT)
  19.151 -                        ? theQueue.getNextEvent()
  19.152 -                        : theQueue.getNextEvent(id);
  19.153 +                    event = (id == ANY_EVENT) ? eq.getNextEvent() : eq.getNextEvent(id);
  19.154                  }
  19.155  
  19.156                  eventOK = true;
  19.157 @@ -252,13 +206,15 @@
  19.158              if (delegate != null) {
  19.159                  handle = delegate.beforeDispatch(event);
  19.160              }
  19.161 -            theQueue.dispatchEvent(event);
  19.162 +            eq.dispatchEvent(event);
  19.163              if (delegate != null) {
  19.164                  delegate.afterDispatch(event, handle);
  19.165              }
  19.166 +
  19.167              return true;
  19.168          }
  19.169          catch (ThreadDeath death) {
  19.170 +            threadDeathCaught = true;
  19.171              return false;
  19.172  
  19.173          }
  19.174 @@ -267,12 +223,10 @@
  19.175                            // Threads in the AppContext
  19.176  
  19.177          }
  19.178 -        // Can get and throw only unchecked exceptions
  19.179 -        catch (RuntimeException e) {
  19.180 -            processException(e);
  19.181 -        } catch (Error e) {
  19.182 +        catch (Throwable e) {
  19.183              processException(e);
  19.184          }
  19.185 +
  19.186          return true;
  19.187      }
  19.188  
  19.189 @@ -281,14 +235,14 @@
  19.190              eventLog.fine("Processing exception: " + e);
  19.191          }
  19.192          getUncaughtExceptionHandler().uncaughtException(this, e);
  19.193 -        // don't rethrow the exception to avoid EDT recreation
  19.194      }
  19.195  
  19.196 -    boolean isDispatching(EventQueue eq) {
  19.197 -        return theQueue.equals(eq);
  19.198 +    public synchronized EventQueue getEventQueue() {
  19.199 +        return theQueue;
  19.200      }
  19.201 -
  19.202 -    EventQueue getEventQueue() { return theQueue; }
  19.203 +    public synchronized void setEventQueue(EventQueue eq) {
  19.204 +        theQueue = eq;
  19.205 +    }
  19.206  
  19.207      private static class HierarchyEventFilter implements EventFilter {
  19.208          private Component modalComponent;
    20.1 --- a/src/share/classes/java/awt/EventQueue.java	Thu Jul 15 20:11:45 2010 -0700
    20.2 +++ b/src/share/classes/java/awt/EventQueue.java	Tue Jul 20 22:21:31 2010 -0700
    20.3 @@ -138,6 +138,15 @@
    20.4      private final Lock pushPopLock;
    20.5      private final Condition pushPopCond;
    20.6  
    20.7 +    /*
    20.8 +     * Dummy runnable to wake up EDT from getNextEvent() after
    20.9 +     push/pop is performed
   20.10 +     */
   20.11 +    private final static Runnable dummyRunnable = new Runnable() {
   20.12 +        public void run() {
   20.13 +        }
   20.14 +    };
   20.15 +
   20.16      private EventDispatchThread dispatchThread;
   20.17  
   20.18      private final ThreadGroup threadGroup =
   20.19 @@ -219,22 +228,22 @@
   20.20       * @param theEvent an instance of <code>java.awt.AWTEvent</code>,
   20.21       *          or a subclass of it
   20.22       */
   20.23 -    final void postEventPrivate(AWTEvent theEvent) {
   20.24 +    private final void postEventPrivate(AWTEvent theEvent) {
   20.25          theEvent.isPosted = true;
   20.26          pushPopLock.lock();
   20.27          try {
   20.28 -            if (dispatchThread == null && nextQueue == null) {
   20.29 +            if (nextQueue != null) {
   20.30 +                // Forward the event to the top of EventQueue stack
   20.31 +                nextQueue.postEventPrivate(theEvent);
   20.32 +                return;
   20.33 +            }
   20.34 +            if (dispatchThread == null) {
   20.35                  if (theEvent.getSource() == AWTAutoShutdown.getInstance()) {
   20.36                      return;
   20.37                  } else {
   20.38                      initDispatchThread();
   20.39                  }
   20.40              }
   20.41 -            if (nextQueue != null) {
   20.42 -                // Forward event to top of EventQueue stack.
   20.43 -                nextQueue.postEventPrivate(theEvent);
   20.44 -                return;
   20.45 -            }
   20.46              postEvent(theEvent, getPriority(theEvent));
   20.47          } finally {
   20.48              pushPopLock.unlock();
   20.49 @@ -242,29 +251,20 @@
   20.50      }
   20.51  
   20.52      private static int getPriority(AWTEvent theEvent) {
   20.53 -        if (theEvent instanceof PeerEvent &&
   20.54 -            (((PeerEvent)theEvent).getFlags() &
   20.55 -                PeerEvent.ULTIMATE_PRIORITY_EVENT) != 0)
   20.56 -        {
   20.57 -            return ULTIMATE_PRIORITY;
   20.58 +        if (theEvent instanceof PeerEvent) {
   20.59 +            PeerEvent peerEvent = (PeerEvent)theEvent;
   20.60 +            if ((peerEvent.getFlags() & PeerEvent.ULTIMATE_PRIORITY_EVENT) != 0) {
   20.61 +                return ULTIMATE_PRIORITY;
   20.62 +            }
   20.63 +            if ((peerEvent.getFlags() & PeerEvent.PRIORITY_EVENT) != 0) {
   20.64 +                return HIGH_PRIORITY;
   20.65 +            }
   20.66 +            if ((peerEvent.getFlags() & PeerEvent.LOW_PRIORITY_EVENT) != 0) {
   20.67 +                return LOW_PRIORITY;
   20.68 +            }
   20.69          }
   20.70 -
   20.71 -        if (theEvent instanceof PeerEvent &&
   20.72 -            (((PeerEvent)theEvent).getFlags() &
   20.73 -                PeerEvent.PRIORITY_EVENT) != 0)
   20.74 -        {
   20.75 -            return HIGH_PRIORITY;
   20.76 -        }
   20.77 -
   20.78 -        if (theEvent instanceof PeerEvent &&
   20.79 -            (((PeerEvent)theEvent).getFlags() &
   20.80 -                PeerEvent.LOW_PRIORITY_EVENT) != 0)
   20.81 -        {
   20.82 -            return LOW_PRIORITY;
   20.83 -        }
   20.84 -
   20.85          int id = theEvent.getID();
   20.86 -        if (id == PaintEvent.PAINT || id == PaintEvent.UPDATE) {
   20.87 +        if ((id >= PaintEvent.PAINT_FIRST) && (id <= PaintEvent.PAINT_LAST)) {
   20.88              return LOW_PRIORITY;
   20.89          }
   20.90          return NORM_PRIORITY;
   20.91 @@ -501,16 +501,9 @@
   20.92              SunToolkit.flushPendingEvents();
   20.93              pushPopLock.lock();
   20.94              try {
   20.95 -                for (int i = NUM_PRIORITIES - 1; i >= 0; i--) {
   20.96 -                    if (queues[i].head != null) {
   20.97 -                        EventQueueItem entry = queues[i].head;
   20.98 -                        queues[i].head = entry.next;
   20.99 -                        if (entry.next == null) {
  20.100 -                            queues[i].tail = null;
  20.101 -                        }
  20.102 -                        uncacheEQItem(entry);
  20.103 -                        return entry.event;
  20.104 -                    }
  20.105 +                AWTEvent event = getNextEventPrivate();
  20.106 +                if (event != null) {
  20.107 +                    return event;
  20.108                  }
  20.109                  AWTAutoShutdown.getInstance().notifyThreadFree(dispatchThread);
  20.110                  pushPopCond.await();
  20.111 @@ -520,6 +513,24 @@
  20.112          } while(true);
  20.113      }
  20.114  
  20.115 +    /*
  20.116 +     * Must be called under the lock. Doesn't call flushPendingEvents()
  20.117 +     */
  20.118 +    AWTEvent getNextEventPrivate() throws InterruptedException {
  20.119 +        for (int i = NUM_PRIORITIES - 1; i >= 0; i--) {
  20.120 +            if (queues[i].head != null) {
  20.121 +                EventQueueItem entry = queues[i].head;
  20.122 +                queues[i].head = entry.next;
  20.123 +                if (entry.next == null) {
  20.124 +                    queues[i].tail = null;
  20.125 +                }
  20.126 +                uncacheEQItem(entry);
  20.127 +                return entry.event;
  20.128 +            }
  20.129 +        }
  20.130 +        return null;
  20.131 +    }
  20.132 +
  20.133      AWTEvent getNextEvent(int id) throws InterruptedException {
  20.134          do {
  20.135              /*
  20.136 @@ -659,7 +670,9 @@
  20.137                  dispatchThread.stopDispatching();
  20.138              }
  20.139          } else {
  20.140 -            System.err.println("unable to dispatch event: " + event);
  20.141 +            if (eventLog.isLoggable(PlatformLogger.FINE)) {
  20.142 +                eventLog.fine("Unable to dispatch event: " + event);
  20.143 +            }
  20.144          }
  20.145      }
  20.146  
  20.147 @@ -761,15 +774,23 @@
  20.148  
  20.149          pushPopLock.lock();
  20.150          try {
  20.151 -            EventQueue toPush = this;
  20.152 -            while (toPush.nextQueue != null) {
  20.153 -                toPush = toPush.nextQueue;
  20.154 +            EventQueue topQueue = this;
  20.155 +            while (topQueue.nextQueue != null) {
  20.156 +                topQueue = topQueue.nextQueue;
  20.157 +            }
  20.158 +
  20.159 +            if ((topQueue.dispatchThread != null) &&
  20.160 +                (topQueue.dispatchThread.getEventQueue() == this))
  20.161 +            {
  20.162 +                newEventQueue.dispatchThread = topQueue.dispatchThread;
  20.163 +                topQueue.dispatchThread.setEventQueue(newEventQueue);
  20.164              }
  20.165  
  20.166              // Transfer all events forward to new EventQueue.
  20.167 -            while (toPush.peekEvent() != null) {
  20.168 +            while (topQueue.peekEvent() != null) {
  20.169                  try {
  20.170 -                    newEventQueue.postEventPrivate(toPush.getNextEvent());
  20.171 +                    // Use getNextEventPrivate() as it doesn't call flushPendingEvents()
  20.172 +                    newEventQueue.postEventPrivate(topQueue.getNextEventPrivate());
  20.173                  } catch (InterruptedException ie) {
  20.174                      if (eventLog.isLoggable(PlatformLogger.FINE)) {
  20.175                          eventLog.fine("Interrupted push", ie);
  20.176 @@ -777,28 +798,21 @@
  20.177                  }
  20.178              }
  20.179  
  20.180 -            newEventQueue.previousQueue = toPush;
  20.181 +            // Wake up EDT waiting in getNextEvent(), so it can
  20.182 +            // pick up a new EventQueue. Post the waking event before
  20.183 +            // topQueue.nextQueue is assigned, otherwise the event would
  20.184 +            // go newEventQueue
  20.185 +            topQueue.postEventPrivate(new InvocationEvent(topQueue, dummyRunnable));
  20.186  
  20.187 -            /*
  20.188 -             * Stop the event dispatch thread associated with the currently
  20.189 -             * active event queue, so that after the new queue is pushed
  20.190 -             * on the top this event dispatch thread won't prevent AWT from
  20.191 -             * being automatically shut down.
  20.192 -             * Use stopDispatchingLater() to avoid deadlock: stopDispatching()
  20.193 -             * waits for the dispatch thread to exit, which in turn waits
  20.194 -             * for the lock in EQ.detachDispatchThread(), which is hold by
  20.195 -             * this method.
  20.196 -             */
  20.197 -            if (toPush.dispatchThread != null) {
  20.198 -                toPush.dispatchThread.stopDispatchingLater();
  20.199 +            newEventQueue.previousQueue = topQueue;
  20.200 +            topQueue.nextQueue = newEventQueue;
  20.201 +
  20.202 +            AppContext appContext = AppContext.getAppContext();
  20.203 +            if (appContext.get(AppContext.EVENT_QUEUE_KEY) == topQueue) {
  20.204 +                appContext.put(AppContext.EVENT_QUEUE_KEY, newEventQueue);
  20.205              }
  20.206  
  20.207 -            toPush.nextQueue = newEventQueue;
  20.208 -
  20.209 -            AppContext appContext = AppContext.getAppContext();
  20.210 -            if (appContext.get(AppContext.EVENT_QUEUE_KEY) == toPush) {
  20.211 -                appContext.put(AppContext.EVENT_QUEUE_KEY, newEventQueue);
  20.212 -            }
  20.213 +            pushPopCond.signalAll();
  20.214          } finally {
  20.215              pushPopLock.unlock();
  20.216          }
  20.217 @@ -822,44 +836,51 @@
  20.218              eventLog.fine("EventQueue.pop(" + this + ")");
  20.219          }
  20.220  
  20.221 -        EventDispatchThread dt = null;
  20.222          pushPopLock.lock();
  20.223          try {
  20.224 -            EventQueue toPop = this;
  20.225 -            while (toPop.nextQueue != null) {
  20.226 -                toPop = toPop.nextQueue;
  20.227 +            EventQueue topQueue = this;
  20.228 +            while (topQueue.nextQueue != null) {
  20.229 +                topQueue = topQueue.nextQueue;
  20.230              }
  20.231 -            EventQueue prev = toPop.previousQueue;
  20.232 -            if (prev == null) {
  20.233 +            EventQueue prevQueue = topQueue.previousQueue;
  20.234 +            if (prevQueue == null) {
  20.235                  throw new EmptyStackException();
  20.236              }
  20.237 -            toPop.previousQueue = null;
  20.238 +
  20.239 +            topQueue.previousQueue = null;
  20.240 +            prevQueue.nextQueue = null;
  20.241  
  20.242              // Transfer all events back to previous EventQueue.
  20.243 -            prev.nextQueue = null;
  20.244 -            while (toPop.peekEvent() != null) {
  20.245 +            while (topQueue.peekEvent() != null) {
  20.246                  try {
  20.247 -                    prev.postEventPrivate(toPop.getNextEvent());
  20.248 +                    prevQueue.postEventPrivate(topQueue.getNextEventPrivate());
  20.249                  } catch (InterruptedException ie) {
  20.250                      if (eventLog.isLoggable(PlatformLogger.FINE)) {
  20.251                          eventLog.fine("Interrupted pop", ie);
  20.252                      }
  20.253                  }
  20.254              }
  20.255 +
  20.256 +            if ((topQueue.dispatchThread != null) &&
  20.257 +                (topQueue.dispatchThread.getEventQueue() == this))
  20.258 +            {
  20.259 +                prevQueue.dispatchThread = topQueue.dispatchThread;
  20.260 +                topQueue.dispatchThread.setEventQueue(prevQueue);
  20.261 +            }
  20.262 +
  20.263              AppContext appContext = AppContext.getAppContext();
  20.264              if (appContext.get(AppContext.EVENT_QUEUE_KEY) == this) {
  20.265 -                appContext.put(AppContext.EVENT_QUEUE_KEY, prev);
  20.266 +                appContext.put(AppContext.EVENT_QUEUE_KEY, prevQueue);
  20.267              }
  20.268  
  20.269 -            dt = toPop.dispatchThread;
  20.270 +            // Wake up EDT waiting in getNextEvent(), so it can
  20.271 +            // pick up a new EventQueue
  20.272 +            topQueue.postEventPrivate(new InvocationEvent(topQueue, dummyRunnable));
  20.273 +
  20.274 +            pushPopCond.signalAll();
  20.275          } finally {
  20.276              pushPopLock.unlock();
  20.277          }
  20.278 -
  20.279 -        if (dt != null) {
  20.280 -            dt.stopDispatching(); // Must be done outside synchronized
  20.281 -                                  // block to avoid possible deadlock
  20.282 -        }
  20.283      }
  20.284  
  20.285      /**
  20.286 @@ -907,9 +928,9 @@
  20.287          try {
  20.288              AppContext appContext = AppContext.getAppContext();
  20.289              if (dispatchThread == null && !threadGroup.isDestroyed() && !appContext.isDisposed()) {
  20.290 -                dispatchThread = (EventDispatchThread)
  20.291 -                    AccessController.doPrivileged(new PrivilegedAction() {
  20.292 -                        public Object run() {
  20.293 +                dispatchThread = AccessController.doPrivileged(
  20.294 +                    new PrivilegedAction<EventDispatchThread>() {
  20.295 +                        public EventDispatchThread run() {
  20.296                              EventDispatchThread t =
  20.297                                  new EventDispatchThread(threadGroup,
  20.298                                                          name,
  20.299 @@ -919,7 +940,8 @@
  20.300                              t.setDaemon(false);
  20.301                              return t;
  20.302                          }
  20.303 -                    });
  20.304 +                    }
  20.305 +                );
  20.306                  AWTAutoShutdown.getInstance().notifyThreadBusy(dispatchThread);
  20.307                  dispatchThread.start();
  20.308              }
  20.309 @@ -928,7 +950,7 @@
  20.310          }
  20.311      }
  20.312  
  20.313 -    final void detachDispatchThread(EventDispatchThread edt, boolean restart) {
  20.314 +    final boolean detachDispatchThread(EventDispatchThread edt) {
  20.315          /*
  20.316           * This synchronized block is to secure that the event dispatch
  20.317           * thread won't die in the middle of posting a new event to the
  20.318 @@ -939,26 +961,21 @@
  20.319           */
  20.320          pushPopLock.lock();
  20.321          try {
  20.322 -            EventDispatchThread oldDispatchThread = dispatchThread;
  20.323 -            if (dispatchThread == edt) {
  20.324 -                dispatchThread = null;
  20.325 -            }
  20.326 -            if (restart) {
  20.327 +            if (edt == dispatchThread) {
  20.328                  /*
  20.329 -                 * Event dispatch thread dies in case of an uncaught exception.
  20.330 -                 * A new event dispatch thread for this queue will be started
  20.331 -                 * only if a new event is posted to it. In case if no more
  20.332 -                 * events are posted after this thread died all events that
  20.333 -                 * currently are in the queue will never be dispatched.
  20.334 +                 * Don't detach the thread if any events are pending. Not
  20.335 +                 * sure if it's a possible scenario, though.
  20.336                   *
  20.337                   * Fix for 4648733. Check both the associated java event
  20.338                   * queue and the PostEventQueue.
  20.339                   */
  20.340                  if ((peekEvent() != null) || !SunToolkit.isPostEventQueueEmpty()) {
  20.341 -                    initDispatchThread();
  20.342 +                    return false;
  20.343                  }
  20.344 -                AWTAutoShutdown.getInstance().notifyThreadFree(oldDispatchThread);
  20.345 +                dispatchThread = null;
  20.346              }
  20.347 +            AWTAutoShutdown.getInstance().notifyThreadFree(edt);
  20.348 +            return true;
  20.349          } finally {
  20.350              pushPopLock.unlock();
  20.351          }
    21.1 --- a/src/share/classes/java/beans/Encoder.java	Thu Jul 15 20:11:45 2010 -0700
    21.2 +++ b/src/share/classes/java/beans/Encoder.java	Tue Jul 20 22:21:31 2010 -0700
    21.3 @@ -194,13 +194,8 @@
    21.4       * @see java.beans.BeanInfo#getBeanDescriptor
    21.5       */
    21.6      public PersistenceDelegate getPersistenceDelegate(Class<?> type) {
    21.7 -        synchronized (this.finder) {
    21.8 -            PersistenceDelegate pd = this.finder.find(type);
    21.9 -            if (pd != null) {
   21.10 -                return pd;
   21.11 -            }
   21.12 -        }
   21.13 -        return MetaData.getPersistenceDelegate(type);
   21.14 +        PersistenceDelegate pd = this.finder.find(type);
   21.15 +        return (pd != null) ? pd : MetaData.getPersistenceDelegate(type);
   21.16      }
   21.17  
   21.18      /**
   21.19 @@ -214,9 +209,7 @@
   21.20       * @see java.beans.BeanInfo#getBeanDescriptor
   21.21       */
   21.22      public void setPersistenceDelegate(Class<?> type, PersistenceDelegate delegate) {
   21.23 -        synchronized (this.finder) {
   21.24 -            this.finder.register(type, delegate);
   21.25 -        }
   21.26 +        this.finder.register(type, delegate);
   21.27      }
   21.28  
   21.29      /**
    22.1 --- a/src/share/classes/java/beans/EventSetDescriptor.java	Thu Jul 15 20:11:45 2010 -0700
    22.2 +++ b/src/share/classes/java/beans/EventSetDescriptor.java	Tue Jul 20 22:21:31 2010 -0700
    22.3 @@ -27,6 +27,7 @@
    22.4  
    22.5  import java.lang.ref.Reference;
    22.6  import java.lang.reflect.Method;
    22.7 +import java.lang.reflect.Modifier;
    22.8  
    22.9  /**
   22.10   * An EventSetDescriptor describes a group of events that a given Java
   22.11 @@ -175,10 +176,8 @@
   22.12          setRemoveListenerMethod(getMethod(sourceClass, removeListenerMethodName, 1));
   22.13  
   22.14          // Be more forgiving of not finding the getListener method.
   22.15 -        Method method = Introspector.findMethod(sourceClass,
   22.16 -                                                getListenerMethodName, 0);
   22.17 -        if (method != null) {
   22.18 -            setGetListenerMethod(method);
   22.19 +        if (getListenerMethodName != null) {
   22.20 +            setGetListenerMethod(Introspector.findInstanceMethod(sourceClass, getListenerMethodName));
   22.21          }
   22.22      }
   22.23  
   22.24 @@ -188,7 +187,7 @@
   22.25              return null;
   22.26          }
   22.27          Method method = Introspector.findMethod(cls, name, args);
   22.28 -        if (method == null) {
   22.29 +        if ((method == null) || Modifier.isStatic(method.getModifiers())) {
   22.30              throw new IntrospectionException("Method not found: " + name +
   22.31                                               " on class " + cls.getName());
   22.32          }
    23.1 --- a/src/share/classes/java/beans/IndexedPropertyDescriptor.java	Thu Jul 15 20:11:45 2010 -0700
    23.2 +++ b/src/share/classes/java/beans/IndexedPropertyDescriptor.java	Tue Jul 20 22:21:31 2010 -0700
    23.3 @@ -189,16 +189,11 @@
    23.4                      indexedReadMethodName = Introspector.GET_PREFIX + getBaseName();
    23.5                  }
    23.6              }
    23.7 -
    23.8 -            Class[] args = { int.class };
    23.9 -
   23.10 -            indexedReadMethod = Introspector.findMethod(cls, indexedReadMethodName,
   23.11 -                                                        1, args);
   23.12 +            indexedReadMethod = Introspector.findInstanceMethod(cls, indexedReadMethodName, int.class);
   23.13              if (indexedReadMethod == null) {
   23.14                  // no "is" method, so look for a "get" method.
   23.15                  indexedReadMethodName = Introspector.GET_PREFIX + getBaseName();
   23.16 -                indexedReadMethod = Introspector.findMethod(cls, indexedReadMethodName,
   23.17 -                                                            1, args);
   23.18 +                indexedReadMethod = Introspector.findInstanceMethod(cls, indexedReadMethodName, int.class);
   23.19              }
   23.20              setIndexedReadMethod0(indexedReadMethod);
   23.21          }
   23.22 @@ -270,8 +265,7 @@
   23.23              if (indexedWriteMethodName == null) {
   23.24                  indexedWriteMethodName = Introspector.SET_PREFIX + getBaseName();
   23.25              }
   23.26 -            indexedWriteMethod = Introspector.findMethod(cls, indexedWriteMethodName,
   23.27 -                         2, (type == null) ? null : new Class[] { int.class, type });
   23.28 +            indexedWriteMethod = Introspector.findInstanceMethod(cls, indexedWriteMethodName, int.class, type);
   23.29              if (indexedWriteMethod != null) {
   23.30                  if (!indexedWriteMethod.getReturnType().equals(void.class)) {
   23.31                      indexedWriteMethod = null;
    24.1 --- a/src/share/classes/java/beans/Introspector.java	Thu Jul 15 20:11:45 2010 -0700
    24.2 +++ b/src/share/classes/java/beans/Introspector.java	Tue Jul 20 22:21:31 2010 -0700
    24.3 @@ -28,6 +28,7 @@
    24.4  import com.sun.beans.WeakCache;
    24.5  import com.sun.beans.finder.BeanInfoFinder;
    24.6  import com.sun.beans.finder.ClassFinder;
    24.7 +import com.sun.beans.finder.MethodFinder;
    24.8  
    24.9  import java.lang.ref.Reference;
   24.10  import java.lang.ref.SoftReference;
   24.11 @@ -157,21 +158,23 @@
   24.12          if (!ReflectUtil.isPackageAccessible(beanClass)) {
   24.13              return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
   24.14          }
   24.15 +        Map<Class<?>, BeanInfo> beanInfoCache;
   24.16 +        BeanInfo beanInfo;
   24.17          synchronized (BEANINFO_CACHE) {
   24.18 -            Map<Class<?>, BeanInfo> beanInfoCache =
   24.19 -                    (Map<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE);
   24.20 -
   24.21 +            beanInfoCache = (Map<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE);
   24.22              if (beanInfoCache == null) {
   24.23                  beanInfoCache = new WeakHashMap<Class<?>, BeanInfo>();
   24.24                  AppContext.getAppContext().put(BEANINFO_CACHE, beanInfoCache);
   24.25              }
   24.26 -            BeanInfo beanInfo = beanInfoCache.get(beanClass);
   24.27 -            if (beanInfo == null) {
   24.28 -                beanInfo = (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
   24.29 +            beanInfo = beanInfoCache.get(beanClass);
   24.30 +        }
   24.31 +        if (beanInfo == null) {
   24.32 +            beanInfo = new Introspector(beanClass, null, USE_ALL_BEANINFO).getBeanInfo();
   24.33 +            synchronized (BEANINFO_CACHE) {
   24.34                  beanInfoCache.put(beanClass, beanInfo);
   24.35              }
   24.36 -            return beanInfo;
   24.37          }
   24.38 +        return beanInfo;
   24.39      }
   24.40  
   24.41      /**
   24.42 @@ -301,10 +304,7 @@
   24.43       */
   24.44  
   24.45      public static String[] getBeanInfoSearchPath() {
   24.46 -        BeanInfoFinder finder = getFinder();
   24.47 -        synchronized (finder) {
   24.48 -            return finder.getPackages();
   24.49 -        }
   24.50 +        return getFinder().getPackages();
   24.51      }
   24.52  
   24.53      /**
   24.54 @@ -328,10 +328,7 @@
   24.55          if (sm != null) {
   24.56              sm.checkPropertiesAccess();
   24.57          }
   24.58 -        BeanInfoFinder finder = getFinder();
   24.59 -        synchronized (finder) {
   24.60 -            finder.setPackages(path);
   24.61 -        }
   24.62 +        getFinder().setPackages(path);
   24.63      }
   24.64  
   24.65  
   24.66 @@ -453,10 +450,7 @@
   24.67       * @return Instance of an explicit BeanInfo class or null if one isn't found.
   24.68       */
   24.69      private static BeanInfo findExplicitBeanInfo(Class beanClass) {
   24.70 -        BeanInfoFinder finder = getFinder();
   24.71 -        synchronized (finder) {
   24.72 -            return finder.find(beanClass);
   24.73 -        }
   24.74 +        return getFinder().find(beanClass);
   24.75      }
   24.76  
   24.77      /**
   24.78 @@ -849,8 +843,8 @@
   24.79                  Method read = result.getReadMethod();
   24.80  
   24.81                  if (read == null && write != null) {
   24.82 -                    read = findMethod(result.getClass0(),
   24.83 -                                      GET_PREFIX + NameGenerator.capitalize(result.getName()), 0);
   24.84 +                    read = findInstanceMethod(result.getClass0(),
   24.85 +                                              GET_PREFIX + NameGenerator.capitalize(result.getName()));
   24.86                      if (read != null) {
   24.87                          try {
   24.88                              result.setReadMethod(read);
   24.89 @@ -860,9 +854,9 @@
   24.90                      }
   24.91                  }
   24.92                  if (write == null && read != null) {
   24.93 -                    write = findMethod(result.getClass0(),
   24.94 -                                       SET_PREFIX + NameGenerator.capitalize(result.getName()), 1,
   24.95 -                                       new Class[] { FeatureDescriptor.getReturnType(result.getClass0(), read) });
   24.96 +                    write = findInstanceMethod(result.getClass0(),
   24.97 +                                               SET_PREFIX + NameGenerator.capitalize(result.getName()),
   24.98 +                                               FeatureDescriptor.getReturnType(result.getClass0(), read));
   24.99                      if (write != null) {
  24.100                          try {
  24.101                              result.setWriteMethod(write);
  24.102 @@ -1286,90 +1280,27 @@
  24.103      // Package private support methods.
  24.104      //======================================================================
  24.105  
  24.106 -    /**
  24.107 -     * Internal support for finding a target methodName with a given
  24.108 -     * parameter list on a given class.
  24.109 -     */
  24.110 -    private static Method internalFindMethod(Class start, String methodName,
  24.111 -                                                 int argCount, Class args[]) {
  24.112 -        // For overriden methods we need to find the most derived version.
  24.113 -        // So we start with the given class and walk up the superclass chain.
  24.114 -
  24.115 -        Method method = null;
  24.116 -
  24.117 -        for (Class cl = start; cl != null; cl = cl.getSuperclass()) {
  24.118 -            Method methods[] = getPublicDeclaredMethods(cl);
  24.119 -            for (int i = 0; i < methods.length; i++) {
  24.120 -                method = methods[i];
  24.121 -                if (method == null) {
  24.122 -                    continue;
  24.123 +    static Method findMethod(Class<?> type, String name, int args) {
  24.124 +        for (Method method : type.getMethods()) {
  24.125 +            if (method.getName().equals(name) && (args == method.getParameterTypes().length)) {
  24.126 +                try {
  24.127 +                    return MethodFinder.findAccessibleMethod(method);
  24.128                  }
  24.129 -
  24.130 -                // make sure method signature matches.
  24.131 -                Class params[] = FeatureDescriptor.getParameterTypes(start, method);
  24.132 -                if (method.getName().equals(methodName) &&
  24.133 -                    params.length == argCount) {
  24.134 -                    if (args != null) {
  24.135 -                        boolean different = false;
  24.136 -                        if (argCount > 0) {
  24.137 -                            for (int j = 0; j < argCount; j++) {
  24.138 -                                if (params[j] != args[j]) {
  24.139 -                                    different = true;
  24.140 -                                    continue;
  24.141 -                                }
  24.142 -                            }
  24.143 -                            if (different) {
  24.144 -                                continue;
  24.145 -                            }
  24.146 -                        }
  24.147 -                    }
  24.148 -                    return method;
  24.149 +                catch (NoSuchMethodException exception) {
  24.150 +                    // continue search for a method with the specified count of parameters
  24.151                  }
  24.152              }
  24.153          }
  24.154 -        method = null;
  24.155 -
  24.156 -        // Now check any inherited interfaces.  This is necessary both when
  24.157 -        // the argument class is itself an interface, and when the argument
  24.158 -        // class is an abstract class.
  24.159 -        Class ifcs[] = start.getInterfaces();
  24.160 -        for (int i = 0 ; i < ifcs.length; i++) {
  24.161 -            // Note: The original implementation had both methods calling
  24.162 -            // the 3 arg method. This is preserved but perhaps it should
  24.163 -            // pass the args array instead of null.
  24.164 -            method = internalFindMethod(ifcs[i], methodName, argCount, null);
  24.165 -            if (method != null) {
  24.166 -                break;
  24.167 -            }
  24.168 -        }
  24.169 -        return method;
  24.170 +        return null;
  24.171      }
  24.172  
  24.173 -    /**
  24.174 -     * Find a target methodName on a given class.
  24.175 -     */
  24.176 -    static Method findMethod(Class cls, String methodName, int argCount) {
  24.177 -        return findMethod(cls, methodName, argCount, null);
  24.178 -    }
  24.179 -
  24.180 -    /**
  24.181 -     * Find a target methodName with specific parameter list on a given class.
  24.182 -     * <p>
  24.183 -     * Used in the contructors of the EventSetDescriptor,
  24.184 -     * PropertyDescriptor and the IndexedPropertyDescriptor.
  24.185 -     * <p>
  24.186 -     * @param cls The Class object on which to retrieve the method.
  24.187 -     * @param methodName Name of the method.
  24.188 -     * @param argCount Number of arguments for the desired method.
  24.189 -     * @param args Array of argument types for the method.
  24.190 -     * @return the method or null if not found
  24.191 -     */
  24.192 -    static Method findMethod(Class cls, String methodName, int argCount,
  24.193 -                             Class args[]) {
  24.194 -        if (methodName == null) {
  24.195 +    static Method findInstanceMethod(Class<?> type, String name, Class<?>... args) {
  24.196 +        try {
  24.197 +            return MethodFinder.findInstanceMethod(type, name, args);
  24.198 +        }
  24.199 +        catch (NoSuchMethodException exception) {
  24.200              return null;
  24.201          }
  24.202 -        return internalFindMethod(cls, methodName, argCount, args);
  24.203      }
  24.204  
  24.205      /**
    25.1 --- a/src/share/classes/java/beans/MethodDescriptor.java	Thu Jul 15 20:11:45 2010 -0700
    25.2 +++ b/src/share/classes/java/beans/MethodDescriptor.java	Tue Jul 20 22:21:31 2010 -0700
    25.3 @@ -82,21 +82,21 @@
    25.4          Method method = getMethod0();
    25.5          if (method == null) {
    25.6              Class cls = getClass0();
    25.7 -            if (cls != null) {
    25.8 +            String name = getName();
    25.9 +            if ((cls != null) && (name != null)) {
   25.10                  Class[] params = getParams();
   25.11                  if (params == null) {
   25.12                      for (int i = 0; i < 3; i++) {
   25.13                          // Find methods for up to 2 params. We are guessing here.
   25.14                          // This block should never execute unless the classloader
   25.15                          // that loaded the argument classes disappears.
   25.16 -                        method = Introspector.findMethod(cls, getName(), i, null);
   25.17 +                        method = Introspector.findMethod(cls, name, i);
   25.18                          if (method != null) {
   25.19                              break;
   25.20                          }
   25.21                      }
   25.22                  } else {
   25.23 -                    method = Introspector.findMethod(cls, getName(),
   25.24 -                                                     params.length, params);
   25.25 +                    method = Statement.getMethod(cls, name, params);
   25.26                  }
   25.27                  setMethod(method);
   25.28              }
    26.1 --- a/src/share/classes/java/beans/PropertyDescriptor.java	Thu Jul 15 20:11:45 2010 -0700
    26.2 +++ b/src/share/classes/java/beans/PropertyDescriptor.java	Tue Jul 20 22:21:31 2010 -0700
    26.3 @@ -112,9 +112,7 @@
    26.4          // If this class or one of its base classes allow PropertyChangeListener,
    26.5          // then we assume that any properties we discover are "bound".
    26.6          // See Introspector.getTargetPropertyInfo() method.
    26.7 -        String name = "addPropertyChangeListener";
    26.8 -        Class[] args = {PropertyChangeListener.class};
    26.9 -        this.bound = (null != Introspector.findMethod(beanClass, name, args.length, args));
   26.10 +        this.bound = null != Introspector.findInstanceMethod(beanClass, "addPropertyChangeListener", PropertyChangeListener.class);
   26.11      }
   26.12  
   26.13      /**
   26.14 @@ -225,10 +223,10 @@
   26.15              // property type is.  For booleans, there can be "is" and "get"
   26.16              // methods.  If an "is" method exists, this is the official
   26.17              // reader method so look for this one first.
   26.18 -            readMethod = Introspector.findMethod(cls, readMethodName, 0);
   26.19 +            readMethod = Introspector.findInstanceMethod(cls, readMethodName);
   26.20              if (readMethod == null) {
   26.21                  readMethodName = Introspector.GET_PREFIX + getBaseName();
   26.22 -                readMethod = Introspector.findMethod(cls, readMethodName, 0);
   26.23 +                readMethod = Introspector.findInstanceMethod(cls, readMethodName);
   26.24              }
   26.25              try {
   26.26                  setReadMethod(readMethod);
   26.27 @@ -293,8 +291,7 @@
   26.28                  writeMethodName = Introspector.SET_PREFIX + getBaseName();
   26.29              }
   26.30  
   26.31 -            writeMethod = Introspector.findMethod(cls, writeMethodName, 1,
   26.32 -                          (type == null) ? null : new Class[] { type });
   26.33 +            writeMethod = Introspector.findInstanceMethod(cls, writeMethodName, type);
   26.34              if (writeMethod != null) {
   26.35                  if (!writeMethod.getReturnType().equals(void.class)) {
   26.36                      writeMethod = null;
    27.1 --- a/src/share/classes/java/beans/PropertyEditorManager.java	Thu Jul 15 20:11:45 2010 -0700
    27.2 +++ b/src/share/classes/java/beans/PropertyEditorManager.java	Tue Jul 20 22:21:31 2010 -0700
    27.3 @@ -1,5 +1,5 @@
    27.4  /*
    27.5 - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
    27.6 + * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
    27.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    27.8   *
    27.9   * This code is free software; you can redistribute it and/or modify it
   27.10 @@ -81,10 +81,7 @@
   27.11          if (sm != null) {
   27.12              sm.checkPropertiesAccess();
   27.13          }
   27.14 -        PropertyEditorFinder finder = getFinder();
   27.15 -        synchronized (finder) {
   27.16 -            finder.register(targetType, editorClass);
   27.17 -        }
   27.18 +        getFinder().register(targetType, editorClass);
   27.19      }
   27.20  
   27.21      /**
   27.22 @@ -95,10 +92,7 @@
   27.23       * The result is null if no suitable editor can be found.
   27.24       */
   27.25      public static PropertyEditor findEditor(Class<?> targetType) {
   27.26 -        PropertyEditorFinder finder = getFinder();
   27.27 -        synchronized (finder) {
   27.28 -            return finder.find(targetType);
   27.29 -        }
   27.30 +        return getFinder().find(targetType);
   27.31      }
   27.32  
   27.33      /**
   27.34 @@ -110,10 +104,7 @@
   27.35       *         e.g. Sun implementation initially sets to  {"sun.beans.editors"}.
   27.36       */
   27.37      public static String[] getEditorSearchPath() {
   27.38 -        PropertyEditorFinder finder = getFinder();
   27.39 -        synchronized (finder) {
   27.40 -            return finder.getPackages();
   27.41 -        }
   27.42 +        return getFinder().getPackages();
   27.43      }
   27.44  
   27.45      /**
   27.46 @@ -134,10 +125,7 @@
   27.47          if (sm != null) {
   27.48              sm.checkPropertiesAccess();
   27.49          }
   27.50 -        PropertyEditorFinder finder = getFinder();
   27.51 -        synchronized (finder) {
   27.52 -            finder.setPackages(path);
   27.53 -        }
   27.54 +        getFinder().setPackages(path);
   27.55      }
   27.56  
   27.57      private static PropertyEditorFinder getFinder() {
    28.1 --- a/src/share/classes/java/beans/XMLDecoder.java	Thu Jul 15 20:11:45 2010 -0700
    28.2 +++ b/src/share/classes/java/beans/XMLDecoder.java	Tue Jul 20 22:21:31 2010 -0700
    28.3 @@ -60,7 +60,7 @@
    28.4   *
    28.5   * @author Philip Milne
    28.6   */
    28.7 -public class XMLDecoder {
    28.8 +public class XMLDecoder implements AutoCloseable {
    28.9      private final DocumentHandler handler = new DocumentHandler();
   28.10      private final InputSource input;
   28.11      private Object owner;
    29.1 --- a/src/share/classes/java/beans/XMLEncoder.java	Thu Jul 15 20:11:45 2010 -0700
    29.2 +++ b/src/share/classes/java/beans/XMLEncoder.java	Tue Jul 20 22:21:31 2010 -0700
    29.3 @@ -204,7 +204,7 @@
    29.4   *
    29.5   * @author Philip Milne
    29.6   */
    29.7 -public class XMLEncoder extends Encoder {
    29.8 +public class XMLEncoder extends Encoder implements AutoCloseable {
    29.9  
   29.10      private final CharsetEncoder encoder;
   29.11      private final String charset;
    30.1 --- a/src/share/classes/java/io/Bits.java	Thu Jul 15 20:11:45 2010 -0700
    30.2 +++ b/src/share/classes/java/io/Bits.java	Tue Jul 20 22:21:31 2010 -0700
    30.3 @@ -41,51 +41,39 @@
    30.4      }
    30.5  
    30.6      static char getChar(byte[] b, int off) {
    30.7 -        return (char) (((b[off + 1] & 0xFF) << 0) +
    30.8 -                       ((b[off + 0]) << 8));
    30.9 +        return (char) ((b[off + 1] & 0xFF) +
   30.10 +                       (b[off] << 8));
   30.11      }
   30.12  
   30.13      static short getShort(byte[] b, int off) {
   30.14 -        return (short) (((b[off + 1] & 0xFF) << 0) +
   30.15 -                        ((b[off + 0]) << 8));
   30.16 +        return (short) ((b[off + 1] & 0xFF) +
   30.17 +                        (b[off] << 8));
   30.18      }
   30.19  
   30.20      static int getInt(byte[] b, int off) {
   30.21 -        return ((b[off + 3] & 0xFF) << 0) +
   30.22 -               ((b[off + 2] & 0xFF) << 8) +
   30.23 +        return ((b[off + 3] & 0xFF)      ) +
   30.24 +               ((b[off + 2] & 0xFF) <<  8) +
   30.25                 ((b[off + 1] & 0xFF) << 16) +
   30.26 -               ((b[off + 0]) << 24);
   30.27 +               ((b[off    ]       ) << 24);
   30.28      }
   30.29  
   30.30      static float getFloat(byte[] b, int off) {
   30.31 -        int i = ((b[off + 3] & 0xFF) << 0) +
   30.32 -                ((b[off + 2] & 0xFF) << 8) +
   30.33 -                ((b[off + 1] & 0xFF) << 16) +
   30.34 -                ((b[off + 0]) << 24);
   30.35 -        return Float.intBitsToFloat(i);
   30.36 +        return Float.intBitsToFloat(getInt(b, off));
   30.37      }
   30.38  
   30.39      static long getLong(byte[] b, int off) {
   30.40 -        return ((b[off + 7] & 0xFFL) << 0) +
   30.41 -               ((b[off + 6] & 0xFFL) << 8) +
   30.42 +        return ((b[off + 7] & 0xFFL)      ) +
   30.43 +               ((b[off + 6] & 0xFFL) <<  8) +
   30.44                 ((b[off + 5] & 0xFFL) << 16) +
   30.45                 ((b[off + 4] & 0xFFL) << 24) +
   30.46                 ((b[off + 3] & 0xFFL) << 32) +
   30.47                 ((b[off + 2] & 0xFFL) << 40) +
   30.48                 ((b[off + 1] & 0xFFL) << 48) +
   30.49 -               (((long) b[off + 0]) << 56);
   30.50 +               (((long) b[off])      << 56);
   30.51      }
   30.52  
   30.53      static double getDouble(byte[] b, int off) {
   30.54 -        long j = ((b[off + 7] & 0xFFL) << 0) +
   30.55 -                 ((b[off + 6] & 0xFFL) << 8) +
   30.56 -                 ((b[off + 5] & 0xFFL) << 16) +
   30.57 -                 ((b[off + 4] & 0xFFL) << 24) +
   30.58 -                 ((b[off + 3] & 0xFFL) << 32) +
   30.59 -                 ((b[off + 2] & 0xFFL) << 40) +
   30.60 -                 ((b[off + 1] & 0xFFL) << 48) +
   30.61 -                 (((long) b[off + 0]) << 56);
   30.62 -        return Double.longBitsToDouble(j);
   30.63 +        return Double.longBitsToDouble(getLong(b, off));
   30.64      }
   30.65  
   30.66      /*
   30.67 @@ -98,50 +86,38 @@
   30.68      }
   30.69  
   30.70      static void putChar(byte[] b, int off, char val) {
   30.71 -        b[off + 1] = (byte) (val >>> 0);
   30.72 -        b[off + 0] = (byte) (val >>> 8);
   30.73 +        b[off + 1] = (byte) (val      );
   30.74 +        b[off    ] = (byte) (val >>> 8);
   30.75      }
   30.76  
   30.77      static void putShort(byte[] b, int off, short val) {
   30.78 -        b[off + 1] = (byte) (val >>> 0);
   30.79 -        b[off + 0] = (byte) (val >>> 8);
   30.80 +        b[off + 1] = (byte) (val      );
   30.81 +        b[off    ] = (byte) (val >>> 8);
   30.82      }
   30.83  
   30.84      static void putInt(byte[] b, int off, int val) {
   30.85 -        b[off + 3] = (byte) (val >>> 0);
   30.86 -        b[off + 2] = (byte) (val >>> 8);
   30.87 +        b[off + 3] = (byte) (val       );
   30.88 +        b[off + 2] = (byte) (val >>>  8);
   30.89          b[off + 1] = (byte) (val >>> 16);
   30.90 -        b[off + 0] = (byte) (val >>> 24);
   30.91 +        b[off    ] = (byte) (val >>> 24);
   30.92      }
   30.93  
   30.94      static void putFloat(byte[] b, int off, float val) {
   30.95 -        int i = Float.floatToIntBits(val);
   30.96 -        b[off + 3] = (byte) (i >>> 0);
   30.97 -        b[off + 2] = (byte) (i >>> 8);
   30.98 -        b[off + 1] = (byte) (i >>> 16);
   30.99 -        b[off + 0] = (byte) (i >>> 24);
  30.100 +        putInt(b, off,  Float.floatToIntBits(val));
  30.101      }
  30.102  
  30.103      static void putLong(byte[] b, int off, long val) {
  30.104 -        b[off + 7] = (byte) (val >>> 0);
  30.105 -        b[off + 6] = (byte) (val >>> 8);
  30.106 +        b[off + 7] = (byte) (val       );
  30.107 +        b[off + 6] = (byte) (val >>>  8);
  30.108          b[off + 5] = (byte) (val >>> 16);
  30.109          b[off + 4] = (byte) (val >>> 24);
  30.110          b[off + 3] = (byte) (val >>> 32);
  30.111          b[off + 2] = (byte) (val >>> 40);
  30.112          b[off + 1] = (byte) (val >>> 48);
  30.113 -        b[off + 0] = (byte) (val >>> 56);
  30.114 +        b[off    ] = (byte) (val >>> 56);
  30.115      }
  30.116  
  30.117      static void putDouble(byte[] b, int off, double val) {
  30.118 -        long j = Double.doubleToLongBits(val);
  30.119 -        b[off + 7] = (byte) (j >>> 0);
  30.120 -        b[off + 6] = (byte) (j >>> 8);
  30.121 -        b[off + 5] = (byte) (j >>> 16);
  30.122 -        b[off + 4] = (byte) (j >>> 24);
  30.123 -        b[off + 3] = (byte) (j >>> 32);
  30.124 -        b[off + 2] = (byte) (j >>> 40);
  30.125 -        b[off + 1] = (byte) (j >>> 48);
  30.126 -        b[off + 0] = (byte) (j >>> 56);
  30.127 +        putLong(b, off, Double.doubleToLongBits(val));
  30.128      }
  30.129  }
    31.1 --- a/src/share/classes/java/io/Closeable.java	Thu Jul 15 20:11:45 2010 -0700
    31.2 +++ b/src/share/classes/java/io/Closeable.java	Tue Jul 20 22:21:31 2010 -0700
    31.3 @@ -28,14 +28,14 @@
    31.4  import java.io.IOException;
    31.5  
    31.6  /**
    31.7 - * A <tt>Closeable</tt> is a source or destination of data that can be closed.
    31.8 + * A {@code Closeable} is a source or destination of data that can be closed.
    31.9   * The close method is invoked to release resources that the object is
   31.10   * holding (such as open files).
   31.11   *
   31.12   * @since 1.5
   31.13   */
   31.14  
   31.15 -public interface Closeable {
   31.16 +public interface Closeable extends AutoCloseable {
   31.17  
   31.18      /**
   31.19       * Closes this stream and releases any system resources associated
   31.20 @@ -45,5 +45,4 @@
   31.21       * @throws IOException if an I/O error occurs
   31.22       */
   31.23      public void close() throws IOException;
   31.24 -
   31.25  }
    32.1 --- a/src/share/classes/java/io/ObjectInput.java	Thu Jul 15 20:11:45 2010 -0700
    32.2 +++ b/src/share/classes/java/io/ObjectInput.java	Tue Jul 20 22:21:31 2010 -0700
    32.3 @@ -36,7 +36,7 @@
    32.4   * @see java.io.ObjectInputStream
    32.5   * @since   JDK1.1
    32.6   */
    32.7 -public interface ObjectInput extends DataInput {
    32.8 +public interface ObjectInput extends DataInput, AutoCloseable {
    32.9      /**
   32.10       * Read and return an object. The class that implements this interface
   32.11       * defines where the object is "read" from.
    33.1 --- a/src/share/classes/java/io/ObjectOutput.java	Thu Jul 15 20:11:45 2010 -0700
    33.2 +++ b/src/share/classes/java/io/ObjectOutput.java	Tue Jul 20 22:21:31 2010 -0700
    33.3 @@ -36,7 +36,7 @@
    33.4   * @see java.io.ObjectInputStream
    33.5   * @since   JDK1.1
    33.6   */
    33.7 -public interface ObjectOutput extends DataOutput {
    33.8 +public interface ObjectOutput extends DataOutput, AutoCloseable {
    33.9      /**
   33.10       * Write an object to the underlying storage or stream.  The
   33.11       * class that implements this interface defines how the object is
    34.1 --- a/src/share/classes/java/lang/AbstractStringBuilder.java	Thu Jul 15 20:11:45 2010 -0700
    34.2 +++ b/src/share/classes/java/lang/AbstractStringBuilder.java	Tue Jul 20 22:21:31 2010 -0700
    34.3 @@ -721,20 +721,19 @@
    34.4       * {@code codePoint} isn't a valid Unicode code point
    34.5       */
    34.6      public AbstractStringBuilder appendCodePoint(int codePoint) {
    34.7 -        if (!Character.isValidCodePoint(codePoint)) {
    34.8 +        final int count = this.count;
    34.9 +
   34.10 +        if (Character.isBmpCodePoint(codePoint)) {
   34.11 +            ensureCapacityInternal(count + 1);
   34.12 +            value[count] = (char) codePoint;
   34.13 +            this.count = count + 1;
   34.14 +        } else if (Character.isValidCodePoint(codePoint)) {
   34.15 +            ensureCapacityInternal(count + 2);
   34.16 +            Character.toSurrogates(codePoint, value, count);
   34.17 +            this.count = count + 2;
   34.18 +        } else {
   34.19              throw new IllegalArgumentException();
   34.20          }
   34.21 -        int n = 1;
   34.22 -        if (codePoint >= Character.MIN_SUPPLEMENTARY_CODE_POINT) {
   34.23 -            n++;
   34.24 -        }
   34.25 -        ensureCapacityInternal(count + n);
   34.26 -        if (n == 1) {
   34.27 -            value[count++] = (char) codePoint;
   34.28 -        } else {
   34.29 -            Character.toSurrogates(codePoint, value, count);
   34.30 -            count += n;
   34.31 -        }
   34.32          return this;
   34.33      }
   34.34  
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/src/share/classes/java/lang/AutoCloseable.java	Tue Jul 20 22:21:31 2010 -0700
    35.3 @@ -0,0 +1,47 @@
    35.4 +/*
    35.5 + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
    35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    35.7 + *
    35.8 + * This code is free software; you can redistribute it and/or modify it
    35.9 + * under the terms of the GNU General Public License version 2 only, as
   35.10 + * published by the Free Software Foundation.  Oracle designates this
   35.11 + * particular file as subject to the "Classpath" exception as provided
   35.12 + * by Oracle in the LICENSE file that accompanied this code.
   35.13 + *
   35.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   35.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   35.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   35.17 + * version 2 for more details (a copy is included in the LICENSE file that
   35.18 + * accompanied this code).
   35.19 + *
   35.20 + * You should have received a copy of the GNU General Public License version
   35.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   35.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   35.23 + *
   35.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   35.25 + * or visit www.oracle.com if you need additional information or have any
   35.26 + * questions.
   35.27 + */
   35.28 +
   35.29 +package java.lang;
   35.30 +
   35.31 +/**
   35.32 + * A resource that must be closed when it is no longer needed.
   35.33 + *
   35.34 + * @author Josh Bloch
   35.35 + * @since 1.7
   35.36 + */
   35.37 +public interface AutoCloseable {
   35.38 +    /**
   35.39 +     * Close this resource, relinquishing any underlying resources.
   35.40 +     * This method is invoked automatically by the automatic resource
   35.41 +     * management block construct.
   35.42 +     *
   35.43 +     * <p>Classes implementing this method are strongly encouraged to
   35.44 +     * be declared to throw more specific exceptions (or no exception
   35.45 +     * at all, if the close cannot fail).
   35.46 +     *
   35.47 +     * @throws Exception if this resource cannot be closed
   35.48 +     */
   35.49 +    void close() throws Exception;
   35.50 +}
    36.1 --- a/src/share/classes/java/lang/Character.java	Thu Jul 15 20:11:45 2010 -0700
    36.2 +++ b/src/share/classes/java/lang/Character.java	Tue Jul 20 22:21:31 2010 -0700
    36.3 @@ -24,6 +24,7 @@
    36.4   */
    36.5  
    36.6  package java.lang;
    36.7 +
    36.8  import java.util.Arrays;
    36.9  import java.util.Map;
   36.10  import java.util.HashMap;
   36.11 @@ -67,17 +68,16 @@
   36.12   * definition</i></a> of the U+<i>n</i> notation in the Unicode
   36.13   * standard.)
   36.14   *
   36.15 - * <p>The set of characters from U+0000 to U+FFFF is sometimes
   36.16 - * referred to as the <em>Basic Multilingual Plane (BMP)</em>. <a
   36.17 - * name="supplementary">Characters</a> whose code points are greater
   36.18 + * <p><a name="BMP">The set of characters from U+0000 to U+FFFF is
   36.19 + * sometimes referred to as the <em>Basic Multilingual Plane (BMP)</em>.
   36.20 + * <a name="supplementary">Characters</a> whose code points are greater
   36.21   * than U+FFFF are called <em>supplementary character</em>s.  The Java
   36.22 - * 2 platform uses the UTF-16 representation in <code>char</code>
   36.23 - * arrays and in the <code>String</code> and <code>StringBuffer</code>
   36.24 - * classes. In this representation, supplementary characters are
   36.25 - * represented as a pair of <code>char</code> values, the first from
   36.26 - * the <em>high-surrogates</em> range, (&#92;uD800-&#92;uDBFF), the
   36.27 - * second from the <em>low-surrogates</em> range
   36.28 - * (&#92;uDC00-&#92;uDFFF).
   36.29 + * platform uses the UTF-16 representation in <code>char</code> arrays and
   36.30 + * in the <code>String</code> and <code>StringBuffer</code> classes. In
   36.31 + * this representation, supplementary characters are represented as a pair
   36.32 + * of <code>char</code> values, the first from the <em>high-surrogates</em>
   36.33 + * range, (&#92;uD800-&#92;uDBFF), the second from the
   36.34 + * <em>low-surrogates</em> range (&#92;uDC00-&#92;uDFFF).
   36.35   *
   36.36   * <p>A <code>char</code> value, therefore, represents Basic
   36.37   * Multilingual Plane (BMP) code points, including the surrogate
   36.38 @@ -115,10 +115,12 @@
   36.39   * @author  Lee Boynton
   36.40   * @author  Guy Steele
   36.41   * @author  Akira Tanaka
   36.42 + * @author  Martin Buchholz
   36.43 + * @author  Ulf Zibis
   36.44   * @since   1.0
   36.45   */
   36.46  public final
   36.47 -class Character extends Object implements java.io.Serializable, Comparable<Character> {
   36.48 +class Character implements java.io.Serializable, Comparable<Character> {
   36.49      /**
   36.50       * The minimum radix available for conversion to and from strings.
   36.51       * The constant value of this field is the smallest value permitted
   36.52 @@ -127,10 +129,10 @@
   36.53       * method, and the <code>toString</code> method of class
   36.54       * <code>Integer</code>.
   36.55       *
   36.56 -     * @see     java.lang.Character#digit(char, int)
   36.57 -     * @see     java.lang.Character#forDigit(int, int)
   36.58 -     * @see     java.lang.Integer#toString(int, int)
   36.59 -     * @see     java.lang.Integer#valueOf(java.lang.String)
   36.60 +     * @see     Character#digit(char, int)
   36.61 +     * @see     Character#forDigit(int, int)
   36.62 +     * @see     Integer#toString(int, int)
   36.63 +     * @see     Integer#valueOf(String)
   36.64       */
   36.65      public static final int MIN_RADIX = 2;
   36.66  
   36.67 @@ -142,10 +144,10 @@
   36.68       * method, and the <code>toString</code> method of class
   36.69       * <code>Integer</code>.
   36.70       *
   36.71 -     * @see     java.lang.Character#digit(char, int)
   36.72 -     * @see     java.lang.Character#forDigit(int, int)
   36.73 -     * @see     java.lang.Integer#toString(int, int)
   36.74 -     * @see     java.lang.Integer#valueOf(java.lang.String)
   36.75 +     * @see     Character#digit(char, int)
   36.76 +     * @see     Character#forDigit(int, int)
   36.77 +     * @see     Integer#toString(int, int)
   36.78 +     * @see     Integer#valueOf(String)
   36.79       */
   36.80      public static final int MAX_RADIX = 36;
   36.81  
   36.82 @@ -155,7 +157,7 @@
   36.83       *
   36.84       * @since   1.0.2
   36.85       */
   36.86 -    public static final char   MIN_VALUE = '\u0000';
   36.87 +    public static final char MIN_VALUE = '\u0000';
   36.88  
   36.89      /**
   36.90       * The constant value of this field is the largest value of type
   36.91 @@ -163,7 +165,7 @@
   36.92       *
   36.93       * @since   1.0.2
   36.94       */
   36.95 -    public static final char   MAX_VALUE = '\uFFFF';
   36.96 +    public static final char MAX_VALUE = '\uFFFF';
   36.97  
   36.98      /**
   36.99       * The <code>Class</code> instance representing the primitive type
  36.100 @@ -171,230 +173,201 @@
  36.101       *
  36.102       * @since   1.1
  36.103       */
  36.104 +    @SuppressWarnings("unchecked")
  36.105      public static final Class<Character> TYPE = Class.getPrimitiveClass("char");
  36.106  
  36.107 -   /*
  36.108 -    * Normative general types
  36.109 -    */
  36.110 -
  36.111 -   /*
  36.112 -    * General character types
  36.113 -    */
  36.114 -
  36.115 -   /**
  36.116 -    * General category "Cn" in the Unicode specification.
  36.117 -    * @since   1.1
  36.118 -    */
  36.119 -    public static final byte
  36.120 -        UNASSIGNED                  = 0;
  36.121 -
  36.122 -   /**
  36.123 -    * General category "Lu" in the Unicode specification.
  36.124 -    * @since   1.1
  36.125 -    */
  36.126 -    public static final byte
  36.127 -        UPPERCASE_LETTER            = 1;
  36.128 -
  36.129 -   /**
  36.130 -    * General category "Ll" in the Unicode specification.
  36.131 -    * @since   1.1
  36.132 -    */
  36.133 -    public static final byte
  36.134 -        LOWERCASE_LETTER            = 2;
  36.135 -
  36.136 -   /**
  36.137 -    * General category "Lt" in the Unicode specification.
  36.138 -    * @since   1.1
  36.139 -    */
  36.140 -    public static final byte
  36.141 -        TITLECASE_LETTER            = 3;
  36.142 -
  36.143 -   /**
  36.144 -    * General category "Lm" in the Unicode specification.
  36.145 -    * @since   1.1
  36.146 -    */
  36.147 -    public static final byte
  36.148 -        MODIFIER_LETTER             = 4;
  36.149 -
  36.150 -   /**
  36.151 -    * General category "Lo" in the Unicode specification.
  36.152 -    * @since   1.1
  36.153 -    */
  36.154 -    public static final byte
  36.155 -        OTHER_LETTER                = 5;
  36.156 -
  36.157 -   /**
  36.158 -    * General category "Mn" in the Unicode specification.
  36.159 -    * @since   1.1
  36.160 -    */
  36.161 -    public static final byte
  36.162 -        NON_SPACING_MARK            = 6;
  36.163 -
  36.164 -   /**
  36.165 -    * General category "Me" in the Unicode specification.
  36.166 -    * @since   1.1
  36.167 -    */
  36.168 -    public static final byte
  36.169 -        ENCLOSING_MARK              = 7;
  36.170 -
  36.171 -   /**
  36.172 -    * General category "Mc" in the Unicode specification.
  36.173 -    * @since   1.1
  36.174 -    */
  36.175 -    public static final byte
  36.176 -        COMBINING_SPACING_MARK      = 8;
  36.177 -
  36.178 -   /**
  36.179 -    * General category "Nd" in the Unicode specification.
  36.180 -    * @since   1.1
  36.181 -    */
  36.182 -    public static final byte
  36.183 -        DECIMAL_DIGIT_NUMBER        = 9;
  36.184 -
  36.185 -   /**
  36.186 -    * General category "Nl" in the Unicode specification.
  36.187 -    * @since   1.1
  36.188 -    */
  36.189 -    public static final byte
  36.190 -        LETTER_NUMBER               = 10;
  36.191 -
  36.192 -   /**
  36.193 -    * General category "No" in the Unicode specification.
  36.194 -    * @since   1.1
  36.195 -    */
  36.196 -    public static final byte
  36.197 -        OTHER_NUMBER                = 11;
  36.198 -
  36.199 -   /**
  36.200 -    * General category "Zs" in the Unicode specification.
  36.201 -    * @since   1.1
  36.202 -    */
  36.203 -    public static final byte
  36.204 -        SPACE_SEPARATOR             = 12;
  36.205 -
  36.206 -   /**
  36.207 -    * General category "Zl" in the Unicode specification.
  36.208 -    * @since   1.1
  36.209 -    */
  36.210 -    public static final byte
  36.211 -        LINE_SEPARATOR              = 13;
  36.212 -
  36.213 -   /**
  36.214 -    * General category "Zp" in the Unicode specification.
  36.215 -    * @since   1.1
  36.216 -    */
  36.217 -    public static final byte
  36.218 -        PARAGRAPH_SEPARATOR         = 14;
  36.219 -
  36.220 -   /**
  36.221 -    * General category "Cc" in the Unicode specification.
  36.222 -    * @since   1.1
  36.223 -    */
  36.224 -    public static final byte
  36.225 -        CONTROL                     = 15;
  36.226 -
  36.227 -   /**
  36.228 -    * General category "Cf" in the Unicode specification.
  36.229 -    * @since   1.1
  36.230 -    */
  36.231 -    public static final byte
  36.232 -        FORMAT                      = 16;
  36.233 -
  36.234 -   /**
  36.235 -    * General category "Co" in the Unicode specification.
  36.236 -    * @since   1.1
  36.237 -    */
  36.238 -    public static final byte
  36.239 -        PRIVATE_USE                 = 18;
  36.240 -
  36.241 -   /**
  36.242 -    * General category "Cs" in the Unicode specification.
  36.243 -    * @since   1.1
  36.244 -    */
  36.245 -    public static final byte
  36.246 -        SURROGATE                   = 19;
  36.247 -
  36.248 -   /**
  36.249 -    * General category "Pd" in the Unicode specification.
  36.250 -    * @since   1.1
  36.251 -    */
  36.252 -    public static final byte
  36.253 -        DASH_PUNCTUATION            = 20;
  36.254 -
  36.255 -   /**
  36.256 -    * General category "Ps" in the Unicode specification.
  36.257 -    * @since   1.1
  36.258 -    */
  36.259 -    public static final byte
  36.260 -        START_PUNCTUATION           = 21;
  36.261 -
  36.262 -   /**
  36.263 -    * General category "Pe" in the Unicode specification.
  36.264 -    * @since   1.1
  36.265 -    */
  36.266 -    public static final byte
  36.267 -        END_PUNCTUATION             = 22;
  36.268 -
  36.269 -   /**
  36.270 -    * General category "Pc" in the Unicode specification.
  36.271 -    * @since   1.1
  36.272 -    */
  36.273 -    public static final byte
  36.274 -        CONNECTOR_PUNCTUATION       = 23;
  36.275 -
  36.276 -   /**
  36.277 -    * General category "Po" in the Unicode specification.
  36.278 -    * @since   1.1
  36.279 -    */
  36.280 -    public static final byte
  36.281 -        OTHER_PUNCTUATION           = 24;
  36.282 -
  36.283 -   /**
  36.284 -    * General category "Sm" in the Unicode specification.
  36.285 -    * @since   1.1
  36.286 -    */
  36.287 -    public static final byte
  36.288 -        MATH_SYMBOL                 = 25;
  36.289 -
  36.290 -   /**
  36.291 -    * General category "Sc" in the Unicode specification.
  36.292 -    * @since   1.1
  36.293 -    */
  36.294 -    public static final byte
  36.295 -        CURRENCY_SYMBOL             = 26;
  36.296 -
  36.297 -   /**
  36.298 -    * General category "Sk" in the Unicode specification.
  36.299 -    * @since   1.1
  36.300 -    */
  36.301 -    public static final byte
  36.302 -        MODIFIER_SYMBOL             = 27;
  36.303 -
  36.304 -   /**
  36.305 -    * General category "So" in the Unicode specification.
  36.306 -    * @since   1.1
  36.307 -    */
  36.308 -    public static final byte
  36.309 -        OTHER_SYMBOL                = 28;
  36.310 -
  36.311 -   /**
  36.312 -    * General category "Pi" in the Unicode specification.
  36.313 -    * @since   1.4
  36.314 -    */
  36.315 -    public static final byte
  36.316 -        INITIAL_QUOTE_PUNCTUATION   = 29;
  36.317 -
  36.318 -   /**
  36.319 -    * General category "Pf" in the Unicode specification.
  36.320 -    * @since   1.4
  36.321 -    */
  36.322 -    public static final byte
  36.323 -        FINAL_QUOTE_PUNCTUATION     = 30;
  36.324 +    /*
  36.325 +     * Normative general types
  36.326 +     */
  36.327 +
  36.328 +    /*
  36.329 +     * General character types
  36.330 +     */
  36.331 +
  36.332 +    /**
  36.333 +     * General category "Cn" in the Unicode specification.
  36.334 +     * @since   1.1
  36.335 +     */
  36.336 +    public static final byte UNASSIGNED = 0;
  36.337 +
  36.338 +    /**
  36.339 +     * General category "Lu" in the Unicode specification.
  36.340 +     * @since   1.1
  36.341 +     */
  36.342 +    public static final byte UPPERCASE_LETTER = 1;
  36.343 +
  36.344 +    /**
  36.345 +     * General category "Ll" in the Unicode specification.
  36.346 +     * @since   1.1
  36.347 +     */
  36.348 +    public static final byte LOWERCASE_LETTER = 2;
  36.349 +
  36.350 +    /**
  36.351 +     * General category "Lt" in the Unicode specification.
  36.352 +     * @since   1.1
  36.353 +     */
  36.354 +    public static final byte TITLECASE_LETTER = 3;
  36.355 +
  36.356 +    /**
  36.357 +     * General category "Lm" in the Unicode specification.
  36.358 +     * @since   1.1
  36.359 +     */
  36.360 +    public static final byte MODIFIER_LETTER = 4;
  36.361 +
  36.362 +    /**
  36.363 +     * General category "Lo" in the Unicode specification.
  36.364 +     * @since   1.1
  36.365 +     */
  36.366 +    public static final byte OTHER_LETTER = 5;
  36.367 +
  36.368 +    /**
  36.369 +     * General category "Mn" in the Unicode specification.
  36.370 +     * @since   1.1
  36.371 +     */
  36.372 +    public static final byte NON_SPACING_MARK = 6;
  36.373 +
  36.374 +    /**
  36.375 +     * General category "Me" in the Unicode specification.
  36.376 +     * @since   1.1
  36.377 +     */
  36.378 +    public static final byte ENCLOSING_MARK = 7;
  36.379 +
  36.380 +    /**
  36.381 +     * General category "Mc" in the Unicode specification.
  36.382 +     * @since   1.1
  36.383 +     */
  36.384 +    public static final byte COMBINING_SPACING_MARK = 8;
  36.385 +
  36.386 +    /**
  36.387 +     * General category "Nd" in the Unicode specification.
  36.388 +     * @since   1.1
  36.389 +     */
  36.390 +    public static final byte DECIMAL_DIGIT_NUMBER        = 9;
  36.391 +
  36.392 +    /**
  36.393 +     * General category "Nl" in the Unicode specification.
  36.394 +     * @since   1.1
  36.395 +     */
  36.396 +    public static final byte LETTER_NUMBER = 10;
  36.397 +
  36.398 +    /**
  36.399 +     * General category "No" in the Unicode specification.
  36.400 +     * @since   1.1
  36.401 +     */
  36.402 +    public static final byte OTHER_NUMBER = 11;
  36.403 +
  36.404 +    /**
  36.405 +     * General category "Zs" in the Unicode specification.
  36.406 +     * @since   1.1
  36.407 +     */
  36.408 +    public static final byte SPACE_SEPARATOR = 12;
  36.409 +
  36.410 +    /**
  36.411 +     * General category "Zl" in the Unicode specification.
  36.412 +     * @since   1.1
  36.413 +     */
  36.414 +    public static final byte LINE_SEPARATOR = 13;
  36.415 +
  36.416 +    /**
  36.417 +     * General category "Zp" in the Unicode specification.
  36.418 +     * @since   1.1
  36.419 +     */
  36.420 +    public static final byte PARAGRAPH_SEPARATOR = 14;
  36.421 +
  36.422 +    /**
  36.423 +     * General category "Cc" in the Unicode specification.
  36.424 +     * @since   1.1
  36.425 +     */
  36.426 +    public static final byte CONTROL = 15;
  36.427 +
  36.428 +    /**
  36.429 +     * General category "Cf" in the Unicode specification.
  36.430 +     * @since   1.1
  36.431 +     */
  36.432 +    public static final byte FORMAT = 16;
  36.433 +
  36.434 +    /**
  36.435 +     * General category "Co" in the Unicode specification.
  36.436 +     * @since   1.1
  36.437 +     */
  36.438 +    public static final byte PRIVATE_USE = 18;
  36.439 +
  36.440 +    /**
  36.441 +     * General category "Cs" in the Unicode specification.
  36.442 +     * @since   1.1
  36.443 +     */
  36.444 +    public static final byte SURROGATE = 19;
  36.445 +
  36.446 +    /**
  36.447 +     * General category "Pd" in the Unicode specification.
  36.448 +     * @since   1.1
  36.449 +     */
  36.450 +    public static final byte DASH_PUNCTUATION = 20;
  36.451 +
  36.452 +    /**
  36.453 +     * General category "Ps" in the Unicode specification.
  36.454 +     * @since   1.1
  36.455 +     */
  36.456 +    public static final byte START_PUNCTUATION = 21;
  36.457 +
  36.458 +    /**
  36.459 +     * General category "Pe" in the Unicode specification.
  36.460 +     * @since   1.1
  36.461 +     */
  36.462 +    public static final byte END_PUNCTUATION = 22;
  36.463 +
  36.464 +    /**
  36.465 +     * General category "Pc" in the Unicode specification.
  36.466 +     * @since   1.1
  36.467 +     */
  36.468 +    public static final byte CONNECTOR_PUNCTUATION = 23;
  36.469 +
  36.470 +    /**
  36.471 +     * General category "Po" in the Unicode specification.
  36.472 +     * @since   1.1
  36.473 +     */
  36.474 +    public static final byte OTHER_PUNCTUATION = 24;
  36.475 +
  36.476 +    /**
  36.477 +     * General category "Sm" in the Unicode specification.
  36.478 +     * @since   1.1
  36.479 +     */
  36.480 +    public static final byte MATH_SYMBOL = 25;
  36.481 +
  36.482 +    /**
  36.483 +     * General category "Sc" in the Unicode specification.
  36.484 +     * @since   1.1
  36.485 +     */
  36.486 +    public static final byte CURRENCY_SYMBOL = 26;
  36.487 +
  36.488 +    /**
  36.489 +     * General category "Sk" in the Unicode specification.
  36.490 +     * @since   1.1
  36.491 +     */
  36.492 +    public static final byte MODIFIER_SYMBOL = 27;
  36.493 +
  36.494 +    /**
  36.495 +     * General category "So" in the Unicode specification.
  36.496 +     * @since   1.1
  36.497 +     */
  36.498 +    public static final byte OTHER_SYMBOL = 28;
  36.499 +
  36.500 +    /**
  36.501 +     * General category "Pi" in the Unicode specification.
  36.502 +     * @since   1.4
  36.503 +     */
  36.504 +    public static final byte INITIAL_QUOTE_PUNCTUATION = 29;
  36.505 +
  36.506 +    /**
  36.507 +     * General category "Pf" in the Unicode specification.
  36.508 +     * @since   1.4
  36.509 +     */
  36.510 +    public static final byte FINAL_QUOTE_PUNCTUATION = 30;
  36.511  
  36.512      /**
  36.513       * Error flag. Use int (code point) to avoid confusion with U+FFFF.
  36.514       */
  36.515 -     static final int ERROR = 0xFFFFFFFF;
  36.516 +    static final int ERROR = 0xFFFFFFFF;
  36.517  
  36.518  
  36.519      /**
  36.520 @@ -402,7 +375,7 @@
  36.521       * values have undefined directionality in the Unicode specification.
  36.522       * @since 1.4
  36.523       */
  36.524 -     public static final byte DIRECTIONALITY_UNDEFINED = -1;
  36.525 +    public static final byte DIRECTIONALITY_UNDEFINED = -1;
  36.526  
  36.527      /**
  36.528       * Strong bidirectional character type "L" in the Unicode specification.
  36.529 @@ -609,9 +582,9 @@
  36.530      /**
  36.531       * Instances of this class represent particular subsets of the Unicode
  36.532       * character set.  The only family of subsets defined in the
  36.533 -     * <code>Character</code> class is <code>{@link Character.UnicodeBlock
  36.534 -     * UnicodeBlock}</code>.  Other portions of the Java API may define other
  36.535 -     * subsets for their own purposes.
  36.536 +     * <code>Character</code> class is {@link Character.UnicodeBlock}.
  36.537 +     * Other portions of the Java API may define other subsets for their
  36.538 +     * own purposes.
  36.539       *
  36.540       * @since 1.2
  36.541       */
  36.542 @@ -624,6 +597,7 @@
  36.543           *
  36.544           * @exception NullPointerException if name is <code>null</code>
  36.545           * @param  name  The name of this subset
  36.546 +         * @exception NullPointerException if name is <code>null</code>
  36.547           */
  36.548          protected Subset(String name) {
  36.549              if (name == null) {
  36.550 @@ -662,6 +636,9 @@
  36.551          }
  36.552      }
  36.553  
  36.554 +    // See http://www.unicode.org/Public/UNIDATA/Blocks.txt
  36.555 +    // for the latest specification of Unicode Blocks.
  36.556 +
  36.557      /**
  36.558       * A family of character subsets representing the character blocks in the
  36.559       * Unicode specification. Character blocks generally define characters
  36.560 @@ -672,37 +649,35 @@
  36.561       */
  36.562      public static final class UnicodeBlock extends Subset {
  36.563  
  36.564 -        private static Map map = new HashMap();
  36.565 -
  36.566 -        /**
  36.567 -         * Create a UnicodeBlock with the given identifier name.
  36.568 +        private static Map<String, UnicodeBlock> map
  36.569 +            = new HashMap<String, UnicodeBlock>(256);
  36.570 +
  36.571 +        /**
  36.572 +         * Creates a UnicodeBlock with the given identifier name.
  36.573           * This name must be the same as the block identifier.
  36.574           */
  36.575          private UnicodeBlock(String idName) {
  36.576              super(idName);
  36.577 -            map.put(idName.toUpperCase(Locale.US), this);
  36.578 +            map.put(idName, this);
  36.579          }
  36.580  
  36.581          /**
  36.582 -         * Create a UnicodeBlock with the given identifier name and
  36.583 +         * Creates a UnicodeBlock with the given identifier name and
  36.584           * alias name.
  36.585           */
  36.586          private UnicodeBlock(String idName, String alias) {
  36.587              this(idName);
  36.588 -            map.put(alias.toUpperCase(Locale.US), this);
  36.589 +            map.put(alias, this);
  36.590          }
  36.591  
  36.592          /**
  36.593 -         * Create a UnicodeBlock with the given identifier name and
  36.594 +         * Creates a UnicodeBlock with the given identifier name and
  36.595           * alias names.
  36.596           */
  36.597 -        private UnicodeBlock(String idName, String[] aliasName) {
  36.598 +        private UnicodeBlock(String idName, String... aliases) {
  36.599              this(idName);
  36.600 -            if (aliasName != null) {
  36.601 -                for(int x=0; x<aliasName.length; ++x) {
  36.602 -                    map.put(aliasName[x].toUpperCase(Locale.US), this);
  36.603 -                }
  36.604 -            }
  36.605 +            for (String alias : aliases)
  36.606 +                map.put(alias, this);
  36.607          }
  36.608  
  36.609          /**
  36.610 @@ -710,51 +685,63 @@
  36.611           * @since 1.2
  36.612           */
  36.613          public static final UnicodeBlock  BASIC_LATIN =
  36.614 -            new UnicodeBlock("BASIC_LATIN", new String[] {"Basic Latin", "BasicLatin" });
  36.615 +            new UnicodeBlock("BASIC_LATIN",
  36.616 +                             "BASIC LATIN",
  36.617 +                             "BASICLATIN");
  36.618  
  36.619          /**
  36.620           * Constant for the "Latin-1 Supplement" Unicode character block.
  36.621           * @since 1.2
  36.622           */
  36.623          public static final UnicodeBlock LATIN_1_SUPPLEMENT =
  36.624 -            new UnicodeBlock("LATIN_1_SUPPLEMENT", new String[]{ "Latin-1 Supplement", "Latin-1Supplement"});
  36.625 +            new UnicodeBlock("LATIN_1_SUPPLEMENT",
  36.626 +                             "LATIN-1 SUPPLEMENT",
  36.627 +                             "LATIN-1SUPPLEMENT");
  36.628  
  36.629          /**
  36.630           * Constant for the "Latin Extended-A" Unicode character block.
  36.631           * @since 1.2
  36.632           */
  36.633          public static final UnicodeBlock LATIN_EXTENDED_A =
  36.634 -            new UnicodeBlock("LATIN_EXTENDED_A", new String[]{ "Latin Extended-A", "LatinExtended-A"});
  36.635 +            new UnicodeBlock("LATIN_EXTENDED_A",
  36.636 +                             "LATIN EXTENDED-A",
  36.637 +                             "LATINEXTENDED-A");
  36.638  
  36.639          /**
  36.640           * Constant for the "Latin Extended-B" Unicode character block.
  36.641           * @since 1.2
  36.642           */
  36.643          public static final UnicodeBlock LATIN_EXTENDED_B =
  36.644 -            new UnicodeBlock("LATIN_EXTENDED_B", new String[] {"Latin Extended-B", "LatinExtended-B"});
  36.645 +            new UnicodeBlock("LATIN_EXTENDED_B",
  36.646 +                             "LATIN EXTENDED-B",
  36.647 +                             "LATINEXTENDED-B");
  36.648  
  36.649          /**
  36.650           * Constant for the "IPA Extensions" Unicode character block.
  36.651           * @since 1.2
  36.652           */
  36.653          public static final UnicodeBlock IPA_EXTENSIONS =
  36.654 -            new UnicodeBlock("IPA_EXTENSIONS", new String[] {"IPA Extensions", "IPAExtensions"});
  36.655 +            new UnicodeBlock("IPA_EXTENSIONS",
  36.656 +                             "IPA EXTENSIONS",
  36.657 +                             "IPAEXTENSIONS");
  36.658  
  36.659          /**
  36.660           * Constant for the "Spacing Modifier Letters" Unicode character block.
  36.661           * @since 1.2
  36.662           */
  36.663          public static final UnicodeBlock SPACING_MODIFIER_LETTERS =
  36.664 -            new UnicodeBlock("SPACING_MODIFIER_LETTERS", new String[] { "Spacing Modifier Letters",
  36.665 -                                                                        "SpacingModifierLetters"});
  36.666 +            new UnicodeBlock("SPACING_MODIFIER_LETTERS",
  36.667 +                             "SPACING MODIFIER LETTERS",
  36.668 +                             "SPACINGMODIFIERLETTERS");
  36.669  
  36.670          /**
  36.671           * Constant for the "Combining Diacritical Marks" Unicode character block.
  36.672           * @since 1.2
  36.673           */
  36.674          public static final UnicodeBlock COMBINING_DIACRITICAL_MARKS =
  36.675 -            new UnicodeBlock("COMBINING_DIACRITICAL_MARKS", new String[] {"Combining Diacritical Marks",
  36.676 -                                                                          "CombiningDiacriticalMarks" });
  36.677 +            new UnicodeBlock("COMBINING_DIACRITICAL_MARKS",
  36.678 +                             "COMBINING DIACRITICAL MARKS",
  36.679 +                             "COMBININGDIACRITICALMARKS");
  36.680  
  36.681          /**
  36.682           * Constant for the "Greek and Coptic" Unicode character block.
  36.683 @@ -763,8 +750,10 @@
  36.684           *
  36.685           * @since 1.2
  36.686           */
  36.687 -        public static final UnicodeBlock GREEK
  36.688 -            = new UnicodeBlock("GREEK", new String[] {"Greek and Coptic", "GreekandCoptic"});
  36.689 +        public static final UnicodeBlock GREEK =
  36.690 +            new UnicodeBlock("GREEK",
  36.691 +                             "GREEK AND COPTIC",
  36.692 +                             "GREEKANDCOPTIC");
  36.693  
  36.694          /**
  36.695           * Constant for the "Cyrillic" Unicode character block.
  36.696 @@ -890,44 +879,54 @@
  36.697           * @since 1.2
  36.698           */
  36.699          public static final UnicodeBlock HANGUL_JAMO =
  36.700 -            new UnicodeBlock("HANGUL_JAMO", new String[] {"Hangul Jamo", "HangulJamo"});
  36.701 +            new UnicodeBlock("HANGUL_JAMO",
  36.702 +                             "HANGUL JAMO",
  36.703 +                             "HANGULJAMO");
  36.704  
  36.705          /**
  36.706           * Constant for the "Latin Extended Additional" Unicode character block.
  36.707           * @since 1.2
  36.708           */
  36.709          public static final UnicodeBlock LATIN_EXTENDED_ADDITIONAL =
  36.710 -            new UnicodeBlock("LATIN_EXTENDED_ADDITIONAL", new String[] {"Latin Extended Additional",
  36.711 -                                                                        "LatinExtendedAdditional"});
  36.712 +            new UnicodeBlock("LATIN_EXTENDED_ADDITIONAL",
  36.713 +                             "LATIN EXTENDED ADDITIONAL",
  36.714 +                             "LATINEXTENDEDADDITIONAL");
  36.715  
  36.716          /**
  36.717           * Constant for the "Greek Extended" Unicode character block.
  36.718           * @since 1.2
  36.719           */
  36.720          public static final UnicodeBlock GREEK_EXTENDED =
  36.721 -            new UnicodeBlock("GREEK_EXTENDED", new String[] {"Greek Extended", "GreekExtended"});
  36.722 +            new UnicodeBlock("GREEK_EXTENDED",
  36.723 +                             "GREEK EXTENDED",
  36.724 +                             "GREEKEXTENDED");
  36.725  
  36.726          /**
  36.727           * Constant for the "General Punctuation" Unicode character block.
  36.728           * @since 1.2
  36.729           */
  36.730          public static final UnicodeBlock GENERAL_PUNCTUATION =
  36.731 -            new UnicodeBlock("GENERAL_PUNCTUATION", new String[] {"General Punctuation", "GeneralPunctuation"});
  36.732 +            new UnicodeBlock("GENERAL_PUNCTUATION",
  36.733 +                             "GENERAL PUNCTUATION",
  36.734 +                             "GENERALPUNCTUATION");
  36.735  
  36.736          /**
  36.737           * Constant for the "Superscripts and Subscripts" Unicode character block.
  36.738           * @since 1.2
  36.739           */
  36.740          public static final UnicodeBlock SUPERSCRIPTS_AND_SUBSCRIPTS =
  36.741 -            new UnicodeBlock("SUPERSCRIPTS_AND_SUBSCRIPTS", new String[] {"Superscripts and Subscripts",
  36.742 -                                                                          "SuperscriptsandSubscripts" });
  36.743 +            new UnicodeBlock("SUPERSCRIPTS_AND_SUBSCRIPTS",
  36.744 +                             "SUPERSCRIPTS AND SUBSCRIPTS",
  36.745 +                             "SUPERSCRIPTSANDSUBSCRIPTS");
  36.746  
  36.747          /**
  36.748           * Constant for the "Currency Symbols" Unicode character block.
  36.749           * @since 1.2
  36.750           */
  36.751          public static final UnicodeBlock CURRENCY_SYMBOLS =
  36.752 -            new UnicodeBlock("CURRENCY_SYMBOLS", new String[] { "Currency Symbols", "CurrencySymbols"});
  36.753 +            new UnicodeBlock("CURRENCY_SYMBOLS",
  36.754 +                             "CURRENCY SYMBOLS",
  36.755 +                             "CURRENCYSYMBOLS");
  36.756  
  36.757          /**
  36.758           * Constant for the "Combining Diacritical Marks for Symbols" Unicode character block.
  36.759 @@ -936,24 +935,29 @@
  36.760           * @since 1.2
  36.761           */
  36.762          public static final UnicodeBlock COMBINING_MARKS_FOR_SYMBOLS =
  36.763 -            new UnicodeBlock("COMBINING_MARKS_FOR_SYMBOLS", new String[] {"Combining Diacritical Marks for Symbols",
  36.764 -                                                                                                                                                   "CombiningDiacriticalMarksforSymbols",
  36.765 -                                                                           "Combining Marks for Symbols",
  36.766 -                                                                           "CombiningMarksforSymbols" });
  36.767 +            new UnicodeBlock("COMBINING_MARKS_FOR_SYMBOLS",
  36.768 +                             "COMBINING DIACRITICAL MARKS FOR SYMBOLS",
  36.769 +                             "COMBININGDIACRITICALMARKSFORSYMBOLS",
  36.770 +                             "COMBINING MARKS FOR SYMBOLS",
  36.771 +                             "COMBININGMARKSFORSYMBOLS");
  36.772  
  36.773          /**
  36.774           * Constant for the "Letterlike Symbols" Unicode character block.
  36.775           * @since 1.2
  36.776           */
  36.777          public static final UnicodeBlock LETTERLIKE_SYMBOLS =
  36.778 -            new UnicodeBlock("LETTERLIKE_SYMBOLS", new String[] { "Letterlike Symbols", "LetterlikeSymbols"});
  36.779 +            new UnicodeBlock("LETTERLIKE_SYMBOLS",
  36.780 +                             "LETTERLIKE SYMBOLS",
  36.781 +                             "LETTERLIKESYMBOLS");
  36.782  
  36.783          /**
  36.784           * Constant for the "Number Forms" Unicode character block.
  36.785           * @since 1.2
  36.786           */
  36.787          public static final UnicodeBlock NUMBER_FORMS =
  36.788 -            new UnicodeBlock("NUMBER_FORMS", new String[] {"Number Forms", "NumberForms"});
  36.789 +            new UnicodeBlock("NUMBER_FORMS",
  36.790 +                             "NUMBER FORMS",
  36.791 +                             "NUMBERFORMS");
  36.792  
  36.793          /**
  36.794           * Constant for the "Arrows" Unicode character block.
  36.795 @@ -967,68 +971,81 @@
  36.796           * @since 1.2
  36.797           */
  36.798          public static final UnicodeBlock MATHEMATICAL_OPERATORS =
  36.799 -            new UnicodeBlock("MATHEMATICAL_OPERATORS", new String[] {"Mathematical Operators",
  36.800 -                                                                     "MathematicalOperators"});
  36.801 +            new UnicodeBlock("MATHEMATICAL_OPERATORS",
  36.802 +                             "MATHEMATICAL OPERATORS",
  36.803 +                             "MATHEMATICALOPERATORS");
  36.804  
  36.805          /**
  36.806           * Constant for the "Miscellaneous Technical" Unicode character block.
  36.807           * @since 1.2
  36.808           */
  36.809          public static final UnicodeBlock MISCELLANEOUS_TECHNICAL =
  36.810 -            new UnicodeBlock("MISCELLANEOUS_TECHNICAL", new String[] {"Miscellaneous Technical",
  36.811 -                                                                      "MiscellaneousTechnical"});
  36.812 +            new UnicodeBlock("MISCELLANEOUS_TECHNICAL",
  36.813 +                             "MISCELLANEOUS TECHNICAL",
  36.814 +                             "MISCELLANEOUSTECHNICAL");
  36.815  
  36.816          /**
  36.817           * Constant for the "Control Pictures" Unicode character block.
  36.818           * @since 1.2
  36.819           */
  36.820          public static final UnicodeBlock CONTROL_PICTURES =
  36.821 -            new UnicodeBlock("CONTROL_PICTURES", new String[] {"Control Pictures", "ControlPictures"});
  36.822 +            new UnicodeBlock("CONTROL_PICTURES",
  36.823 +                             "CONTROL PICTURES",
  36.824 +                             "CONTROLPICTURES");
  36.825  
  36.826          /**
  36.827           * Constant for the "Optical Character Recognition" Unicode character block.
  36.828           * @since 1.2
  36.829           */
  36.830          public static final UnicodeBlock OPTICAL_CHARACTER_RECOGNITION =
  36.831 -            new UnicodeBlock("OPTICAL_CHARACTER_RECOGNITION", new String[] {"Optical Character Recognition",
  36.832 -                                                                            "OpticalCharacterRecognition"});
  36.833 +            new UnicodeBlock("OPTICAL_CHARACTER_RECOGNITION",
  36.834 +                             "OPTICAL CHARACTER RECOGNITION",
  36.835 +                             "OPTICALCHARACTERRECOGNITION");
  36.836  
  36.837          /**
  36.838           * Constant for the "Enclosed Alphanumerics" Unicode character block.
  36.839           * @since 1.2
  36.840           */
  36.841          public static final UnicodeBlock ENCLOSED_ALPHANUMERICS =
  36.842 -            new UnicodeBlock("ENCLOSED_ALPHANUMERICS", new String[] {"Enclosed Alphanumerics",
  36.843 -                                                                     "EnclosedAlphanumerics"});
  36.844 +            new UnicodeBlock("ENCLOSED_ALPHANUMERICS",
  36.845 +                             "ENCLOSED ALPHANUMERICS",
  36.846 +                             "ENCLOSEDALPHANUMERICS");
  36.847  
  36.848          /**
  36.849           * Constant for the "Box Drawing" Unicode character block.
  36.850           * @since 1.2
  36.851           */
  36.852          public static final UnicodeBlock BOX_DRAWING =
  36.853 -            new UnicodeBlock("BOX_DRAWING", new String[] {"Box Drawing", "BoxDrawing"});
  36.854 +            new UnicodeBlock("BOX_DRAWING",
  36.855 +                             "BOX DRAWING",
  36.856 +                             "BOXDRAWING");
  36.857  
  36.858          /**
  36.859           * Constant for the "Block Elements" Unicode character block.
  36.860           * @since 1.2
  36.861           */
  36.862          public static final UnicodeBlock BLOCK_ELEMENTS =
  36.863 -            new UnicodeBlock("BLOCK_ELEMENTS", new String[] {"Block Elements", "BlockElements"});
  36.864 +            new UnicodeBlock("BLOCK_ELEMENTS",
  36.865 +                             "BLOCK ELEMENTS",
  36.866 +                             "BLOCKELEMENTS");
  36.867  
  36.868          /**
  36.869           * Constant for the "Geometric Shapes" Unicode character block.
  36.870           * @since 1.2
  36.871           */
  36.872          public static final UnicodeBlock GEOMETRIC_SHAPES =
  36.873 -            new UnicodeBlock("GEOMETRIC_SHAPES", new String[] {"Geometric Shapes", "GeometricShapes"});
  36.874 +            new UnicodeBlock("GEOMETRIC_SHAPES",
  36.875 +                             "GEOMETRIC SHAPES",
  36.876 +                             "GEOMETRICSHAPES");
  36.877  
  36.878          /**
  36.879           * Constant for the "Miscellaneous Symbols" Unicode character block.
  36.880           * @since 1.2
  36.881           */
  36.882          public static final UnicodeBlock MISCELLANEOUS_SYMBOLS =
  36.883 -            new UnicodeBlock("MISCELLANEOUS_SYMBOLS", new String[] {"Miscellaneous Symbols",
  36.884 -                                                                    "MiscellaneousSymbols"});
  36.885 +            new UnicodeBlock("MISCELLANEOUS_SYMBOLS",
  36.886 +                             "MISCELLANEOUS SYMBOLS",
  36.887 +                             "MISCELLANEOUSSYMBOLS");
  36.888  
  36.889          /**
  36.890           * Constant for the "Dingbats" Unicode character block.
  36.891 @@ -1042,8 +1059,9 @@
  36.892           * @since 1.2
  36.893           */
  36.894          public static final UnicodeBlock CJK_SYMBOLS_AND_PUNCTUATION =
  36.895 -            new UnicodeBlock("CJK_SYMBOLS_AND_PUNCTUATION", new String[] {"CJK Symbols and Punctuation",
  36.896 -                                                                          "CJKSymbolsandPunctuation"});
  36.897 +            new UnicodeBlock("CJK_SYMBOLS_AND_PUNCTUATION",
  36.898 +                             "CJK SYMBOLS AND PUNCTUATION",
  36.899 +                             "CJKSYMBOLSANDPUNCTUATION");
  36.900  
  36.901          /**
  36.902           * Constant for the "Hiragana" Unicode character block.
  36.903 @@ -1071,8 +1089,9 @@
  36.904           * @since 1.2
  36.905           */
  36.906          public static final UnicodeBlock HANGUL_COMPATIBILITY_JAMO =
  36.907 -            new UnicodeBlock("HANGUL_COMPATIBILITY_JAMO", new String[] {"Hangul Compatibility Jamo",
  36.908 -                                                                        "HangulCompatibilityJamo"});
  36.909 +            new UnicodeBlock("HANGUL_COMPATIBILITY_JAMO",
  36.910 +                             "HANGUL COMPATIBILITY JAMO",
  36.911 +                             "HANGULCOMPATIBILITYJAMO");
  36.912  
  36.913          /**
  36.914           * Constant for the "Kanbun" Unicode character block.
  36.915 @@ -1086,37 +1105,45 @@
  36.916           * @since 1.2
  36.917           */
  36.918          public static final UnicodeBlock ENCLOSED_CJK_LETTERS_AND_MONTHS =
  36.919 -            new UnicodeBlock("ENCLOSED_CJK_LETTERS_AND_MONTHS", new String[] {"Enclosed CJK Letters and Months",
  36.920 -                                                                              "EnclosedCJKLettersandMonths"});
  36.921 +            new UnicodeBlock("ENCLOSED_CJK_LETTERS_AND_MONTHS",
  36.922 +                             "ENCLOSED CJK LETTERS AND MONTHS",
  36.923 +                             "ENCLOSEDCJKLETTERSANDMONTHS");
  36.924  
  36.925          /**
  36.926           * Constant for the "CJK Compatibility" Unicode character block.
  36.927           * @since 1.2
  36.928           */
  36.929          public static final UnicodeBlock CJK_COMPATIBILITY =
  36.930 -            new UnicodeBlock("CJK_COMPATIBILITY", new String[] {"CJK Compatibility", "CJKCompatibility"});
  36.931 +            new UnicodeBlock("CJK_COMPATIBILITY",
  36.932 +                             "CJK COMPATIBILITY",
  36.933 +                             "CJKCOMPATIBILITY");
  36.934  
  36.935          /**
  36.936           * Constant for the "CJK Unified Ideographs" Unicode character block.
  36.937           * @since 1.2
  36.938           */
  36.939          public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS =
  36.940 -            new UnicodeBlock("CJK_UNIFIED_IDEOGRAPHS", new String[] {"CJK Unified Ideographs",
  36.941 -                                                                     "CJKUnifiedIdeographs"});
  36.942 +            new UnicodeBlock("CJK_UNIFIED_IDEOGRAPHS",
  36.943 +                             "CJK UNIFIED IDEOGRAPHS",
  36.944 +                             "CJKUNIFIEDIDEOGRAPHS");
  36.945  
  36.946          /**
  36.947           * Constant for the "Hangul Syllables" Unicode character block.
  36.948           * @since 1.2
  36.949           */
  36.950          public static final UnicodeBlock HANGUL_SYLLABLES =
  36.951 -            new UnicodeBlock("HANGUL_SYLLABLES", new String[] {"Hangul Syllables", "HangulSyllables"});
  36.952 +            new UnicodeBlock("HANGUL_SYLLABLES",
  36.953 +                             "HANGUL SYLLABLES",
  36.954 +                             "HANGULSYLLABLES");
  36.955  
  36.956          /**
  36.957           * Constant for the "Private Use Area" Unicode character block.
  36.958           * @since 1.2
  36.959           */
  36.960          public static final UnicodeBlock PRIVATE_USE_AREA =
  36.961 -            new UnicodeBlock("PRIVATE_USE_AREA", new String[] {"Private Use Area", "PrivateUseArea"});
  36.962 +            new UnicodeBlock("PRIVATE_USE_AREA",
  36.963 +                             "PRIVATE USE AREA",
  36.964 +                             "PRIVATEUSEAREA");
  36.965  
  36.966          /**
  36.967           * Constant for the "CJK Compatibility Ideographs" Unicode character block.
  36.968 @@ -1124,56 +1151,62 @@
  36.969           */
  36.970          public static final UnicodeBlock CJK_COMPATIBILITY_IDEOGRAPHS =
  36.971              new UnicodeBlock("CJK_COMPATIBILITY_IDEOGRAPHS",
  36.972 -                             new String[] {"CJK Compatibility Ideographs",
  36.973 -                                           "CJKCompatibilityIdeographs"});
  36.974 +                             "CJK COMPATIBILITY IDEOGRAPHS",
  36.975 +                             "CJKCOMPATIBILITYIDEOGRAPHS");
  36.976  
  36.977          /**
  36.978           * Constant for the "Alphabetic Presentation Forms" Unicode character block.
  36.979           * @since 1.2
  36.980           */
  36.981          public static final UnicodeBlock ALPHABETIC_PRESENTATION_FORMS =
  36.982 -            new UnicodeBlock("ALPHABETIC_PRESENTATION_FORMS", new String[] {"Alphabetic Presentation Forms",
  36.983 -                                                                            "AlphabeticPresentationForms"});
  36.984 +            new UnicodeBlock("ALPHABETIC_PRESENTATION_FORMS",
  36.985 +                             "ALPHABETIC PRESENTATION FORMS",
  36.986 +                             "ALPHABETICPRESENTATIONFORMS");
  36.987  
  36.988          /**
  36.989           * Constant for the "Arabic Presentation Forms-A" Unicode character block.
  36.990           * @since 1.2
  36.991           */
  36.992          public static final UnicodeBlock ARABIC_PRESENTATION_FORMS_A =
  36.993 -            new UnicodeBlock("ARABIC_PRESENTATION_FORMS_A", new String[] {"Arabic Presentation Forms-A",
  36.994 -                                                                          "ArabicPresentationForms-A"});
  36.995 +            new UnicodeBlock("ARABIC_PRESENTATION_FORMS_A",
  36.996 +                             "ARABIC PRESENTATION FORMS-A",
  36.997 +                             "ARABICPRESENTATIONFORMS-A");
  36.998  
  36.999          /**
 36.1000           * Constant for the "Combining Half Marks" Unicode character block.
 36.1001           * @since 1.2
 36.1002           */
 36.1003          public static final UnicodeBlock COMBINING_HALF_MARKS =
 36.1004 -            new UnicodeBlock("COMBINING_HALF_MARKS", new String[] {"Combining Half Marks",
 36.1005 -                                                                   "CombiningHalfMarks"});
 36.1006 +            new UnicodeBlock("COMBINING_HALF_MARKS",
 36.1007 +                             "COMBINING HALF MARKS",
 36.1008 +                             "COMBININGHALFMARKS");
 36.1009  
 36.1010          /**
 36.1011           * Constant for the "CJK Compatibility Forms" Unicode character block.
 36.1012           * @since 1.2
 36.1013           */
 36.1014          public static final UnicodeBlock CJK_COMPATIBILITY_FORMS =
 36.1015 -            new UnicodeBlock("CJK_COMPATIBILITY_FORMS", new String[] {"CJK Compatibility Forms",
 36.1016 -                                                                      "CJKCompatibilityForms"});
 36.1017 +            new UnicodeBlock("CJK_COMPATIBILITY_FORMS",
 36.1018 +                             "CJK COMPATIBILITY FORMS",
 36.1019 +                             "CJKCOMPATIBILITYFORMS");
 36.1020  
 36.1021          /**
 36.1022           * Constant for the "Small Form Variants" Unicode character block.
 36.1023           * @since 1.2
 36.1024           */
 36.1025          public static final UnicodeBlock SMALL_FORM_VARIANTS =
 36.1026 -            new UnicodeBlock("SMALL_FORM_VARIANTS", new String[] {"Small Form Variants",
 36.1027 -                                                                  "SmallFormVariants"});
 36.1028 +            new UnicodeBlock("SMALL_FORM_VARIANTS",
 36.1029 +                             "SMALL FORM VARIANTS",
 36.1030 +                             "SMALLFORMVARIANTS");
 36.1031  
 36.1032          /**
 36.1033           * Constant for the "Arabic Presentation Forms-B" Unicode character block.
 36.1034           * @since 1.2
 36.1035           */
 36.1036          public static final UnicodeBlock ARABIC_PRESENTATION_FORMS_B =
 36.1037 -            new UnicodeBlock("ARABIC_PRESENTATION_FORMS_B", new String[] {"Arabic Presentation Forms-B",
 36.1038 -                                                                          "ArabicPresentationForms-B"});
 36.1039 +            new UnicodeBlock("ARABIC_PRESENTATION_FORMS_B",
 36.1040 +                             "ARABIC PRESENTATION FORMS-B",
 36.1041 +                             "ARABICPRESENTATIONFORMS-B");
 36.1042  
 36.1043          /**
 36.1044           * Constant for the "Halfwidth and Fullwidth Forms" Unicode character block.
 36.1045 @@ -1181,8 +1214,8 @@
 36.1046           */
 36.1047          public static final UnicodeBlock HALFWIDTH_AND_FULLWIDTH_FORMS =
 36.1048              new UnicodeBlock("HALFWIDTH_AND_FULLWIDTH_FORMS",
 36.1049 -                             new String[] {"Halfwidth and Fullwidth Forms",
 36.1050 -                                           "HalfwidthandFullwidthForms"});
 36.1051 +                             "HALFWIDTH AND FULLWIDTH FORMS",
 36.1052 +                             "HALFWIDTHANDFULLWIDTHFORMS");
 36.1053  
 36.1054          /**
 36.1055           * Constant for the "Specials" Unicode character block.
 36.1056 @@ -1251,97 +1284,108 @@
 36.1057           */
 36.1058          public static final UnicodeBlock UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS =
 36.1059              new UnicodeBlock("UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS",
 36.1060 -                             new String[] {"Unified Canadian Aboriginal Syllabics",
 36.1061 -                                           "UnifiedCanadianAboriginalSyllabics"});
 36.1062 +                             "UNIFIED CANADIAN ABORIGINAL SYLLABICS",
 36.1063 +                             "UNIFIEDCANADIANABORIGINALSYLLABICS");
 36.1064  
 36.1065          /**
 36.1066           * Constant for the "Ogham" Unicode character block.
 36.1067           * @since 1.4
 36.1068           */
 36.1069          public static final UnicodeBlock OGHAM =
 36.1070 -                             new UnicodeBlock("OGHAM");
 36.1071 +            new UnicodeBlock("OGHAM");
 36.1072  
 36.1073          /**
 36.1074           * Constant for the "Runic" Unicode character block.
 36.1075           * @since 1.4
 36.1076           */
 36.1077          public static final UnicodeBlock RUNIC =
 36.1078 -                             new UnicodeBlock("RUNIC");
 36.1079 +            new UnicodeBlock("RUNIC");
 36.1080  
 36.1081          /**
 36.1082           * Constant for the "Khmer" Unicode character block.
 36.1083           * @since 1.4
 36.1084           */
 36.1085          public static final UnicodeBlock KHMER =
 36.1086 -                             new UnicodeBlock("KHMER");
 36.1087 +            new UnicodeBlock("KHMER");
 36.1088  
 36.1089          /**
 36.1090           * Constant for the "Mongolian" Unicode character block.
 36.1091           * @since 1.4
 36.1092           */
 36.1093          public static final UnicodeBlock MONGOLIAN =
 36.1094 -                             new UnicodeBlock("MONGOLIAN");
 36.1095 +            new UnicodeBlock("MONGOLIAN");
 36.1096  
 36.1097          /**
 36.1098           * Constant for the "Braille Patterns" Unicode character block.
 36.1099           * @since 1.4
 36.1100           */
 36.1101          public static final UnicodeBlock BRAILLE_PATTERNS =
 36.1102 -            new UnicodeBlock("BRAILLE_PATTERNS", new String[] {"Braille Patterns",
 36.1103 -                                                               "BraillePatterns"});
 36.1104 +            new UnicodeBlock("BRAILLE_PATTERNS",
 36.1105 +                             "BRAILLE PATTERNS",
 36.1106 +                             "BRAILLEPATTERNS");
 36.1107  
 36.1108          /**
 36.1109           * Constant for the "CJK Radicals Supplement" Unicode character block.
 36.1110           * @since 1.4
 36.1111           */
 36.1112          public static final UnicodeBlock CJK_RADICALS_SUPPLEMENT =
 36.1113 -             new UnicodeBlock("CJK_RADICALS_SUPPLEMENT", new String[] {"CJK Radicals Supplement",
 36.1114 -                                                                       "CJKRadicalsSupplement"});
 36.1115 +            new UnicodeBlock("CJK_RADICALS_SUPPLEMENT",
 36.1116 +                             "CJK RADICALS SUPPLEMENT",
 36.1117 +                             "CJKRADICALSSUPPLEMENT");
 36.1118  
 36.1119          /**
 36.1120           * Constant for the "Kangxi Radicals" Unicode character block.
 36.1121           * @since 1.4
 36.1122           */
 36.1123          public static final UnicodeBlock KANGXI_RADICALS =
 36.1124 -            new UnicodeBlock("KANGXI_RADICALS", new String[] {"Kangxi Radicals", "KangxiRadicals"});
 36.1125 +            new UnicodeBlock("KANGXI_RADICALS",
 36.1126 +                             "KANGXI RADICALS",
 36.1127 +                             "KANGXIRADICALS");
 36.1128  
 36.1129          /**
 36.1130           * Constant for the "Ideographic Description Characters" Unicode character block.
 36.1131           * @since 1.4
 36.1132           */
 36.1133          public static final UnicodeBlock IDEOGRAPHIC_DESCRIPTION_CHARACTERS =
 36.1134 -            new UnicodeBlock("IDEOGRAPHIC_DESCRIPTION_CHARACTERS", new String[] {"Ideographic Description Characters",
 36.1135 -                                                                                 "IdeographicDescriptionCharacters"});
 36.1136 +            new UnicodeBlock("IDEOGRAPHIC_DESCRIPTION_CHARACTERS",
 36.1137 +                             "IDEOGRAPHIC DESCRIPTION CHARACTERS",
 36.1138 +                             "IDEOGRAPHICDESCRIPTIONCHARACTERS");
 36.1139  
 36.1140          /**
 36.1141           * Constant for the "Bopomofo Extended" Unicode character block.
 36.1142           * @since 1.4
 36.1143           */
 36.1144          public static final UnicodeBlock BOPOMOFO_EXTENDED =
 36.1145 -            new UnicodeBlock("BOPOMOFO_EXTENDED", new String[] {"Bopomofo Extended",
 36.1146 -                                                                "BopomofoExtended"});
 36.1147 +            new UnicodeBlock("BOPOMOFO_EXTENDED",
 36.1148 +                             "BOPOMOFO EXTENDED",
 36.1149 +                             "BOPOMOFOEXTENDED");
 36.1150  
 36.1151          /**
 36.1152           * Constant for the "CJK Unified Ideographs Extension A" Unicode character block.
 36.1153           * @since 1.4
 36.1154           */
 36.1155          public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A =
 36.1156 -            new UnicodeBlock("CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A", new String[] {"CJK Unified Ideographs Extension A",
 36.1157 -                                                                                 "CJKUnifiedIdeographsExtensionA"});
 36.1158 +            new UnicodeBlock("CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A",
 36.1159 +                             "CJK UNIFIED IDEOGRAPHS EXTENSION A",
 36.1160 +                             "CJKUNIFIEDIDEOGRAPHSEXTENSIONA");
 36.1161  
 36.1162          /**
 36.1163           * Constant for the "Yi Syllables" Unicode character block.
 36.1164           * @since 1.4
 36.1165           */
 36.1166          public static final UnicodeBlock YI_SYLLABLES =
 36.1167 -            new UnicodeBlock("YI_SYLLABLES", new String[] {"Yi Syllables", "YiSyllables"});
 36.1168 +            new UnicodeBlock("YI_SYLLABLES",
 36.1169 +                             "YI SYLLABLES",
 36.1170 +                             "YISYLLABLES");
 36.1171  
 36.1172          /**
 36.1173           * Constant for the "Yi Radicals" Unicode character block.
 36.1174           * @since 1.4
 36.1175           */
 36.1176          public static final UnicodeBlock YI_RADICALS =
 36.1177 -            new UnicodeBlock("YI_RADICALS", new String[] {"Yi Radicals", "YiRadicals"});
 36.1178 +            new UnicodeBlock("YI_RADICALS",
 36.1179 +                             "YI RADICALS",
 36.1180 +                             "YIRADICALS");
 36.1181  
 36.1182  
 36.1183          /**
 36.1184 @@ -1350,10 +1394,10 @@
 36.1185           */
 36.1186          public static final UnicodeBlock CYRILLIC_SUPPLEMENTARY =
 36.1187              new UnicodeBlock("CYRILLIC_SUPPLEMENTARY",
 36.1188 -                             new String[] {"Cyrillic Supplementary",
 36.1189 -                                           "CyrillicSupplementary",
 36.1190 -                                           "Cyrillic Supplement",
 36.1191 -                                           "CyrillicSupplement"});
 36.1192 +                             "CYRILLIC SUPPLEMENTARY",
 36.1193 +                             "CYRILLICSUPPLEMENTARY",
 36.1194 +                             "CYRILLIC SUPPLEMENT",
 36.1195 +                             "CYRILLICSUPPLEMENT");
 36.1196  
 36.1197          /**
 36.1198           * Constant for the "Tagalog" Unicode character block.
 36.1199 @@ -1395,21 +1439,27 @@
 36.1200           * @since 1.5
 36.1201           */
 36.1202          public static final UnicodeBlock TAI_LE =
 36.1203 -            new UnicodeBlock("TAI_LE", new String[] {"Tai Le", "TaiLe"});
 36.1204 +            new UnicodeBlock("TAI_LE",
 36.1205 +                             "TAI LE",
 36.1206 +                             "TAILE");
 36.1207  
 36.1208          /**
 36.1209           * Constant for the "Khmer Symbols" Unicode character block.
 36.1210           * @since 1.5
 36.1211           */
 36.1212          public static final UnicodeBlock KHMER_SYMBOLS =
 36.1213 -            new UnicodeBlock("KHMER_SYMBOLS", new String[] {"Khmer Symbols", "KhmerSymbols"});
 36.1214 +            new UnicodeBlock("KHMER_SYMBOLS",
 36.1215 +                             "KHMER SYMBOLS",
 36.1216 +                             "KHMERSYMBOLS");
 36.1217  
 36.1218          /**
 36.1219           * Constant for the "Phonetic Extensions" Unicode character block.
 36.1220           * @since 1.5
 36.1221           */
 36.1222          public static final UnicodeBlock PHONETIC_EXTENSIONS =
 36.1223 -            new UnicodeBlock("PHONETIC_EXTENSIONS", new String[] {"Phonetic Extensions", "PhoneticExtensions"});
 36.1224 +            new UnicodeBlock("PHONETIC_EXTENSIONS",
 36.1225 +                             "PHONETIC EXTENSIONS",
 36.1226 +                             "PHONETICEXTENSIONS");
 36.1227  
 36.1228          /**
 36.1229           * Constant for the "Miscellaneous Mathematical Symbols-A" Unicode character block.
 36.1230 @@ -1417,33 +1467,35 @@
 36.1231           */
 36.1232          public static final UnicodeBlock MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A =
 36.1233              new UnicodeBlock("MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A",
 36.1234 -                             new String[]{"Miscellaneous Mathematical Symbols-A",
 36.1235 -                                          "MiscellaneousMathematicalSymbols-A"});
 36.1236 +                             "MISCELLANEOUS MATHEMATICAL SYMBOLS-A",
 36.1237 +                             "MISCELLANEOUSMATHEMATICALSYMBOLS-A");
 36.1238  
 36.1239          /**
 36.1240           * Constant for the "Supplemental Arrows-A" Unicode character block.
 36.1241           * @since 1.5
 36.1242           */
 36.1243          public static final UnicodeBlock SUPPLEMENTAL_ARROWS_A =
 36.1244 -            new UnicodeBlock("SUPPLEMENTAL_ARROWS_A", new String[] {"Supplemental Arrows-A",
 36.1245 -                                                                    "SupplementalArrows-A"});
 36.1246 +            new UnicodeBlock("SUPPLEMENTAL_ARROWS_A",
 36.1247 +                             "SUPPLEMENTAL ARROWS-A",
 36.1248 +                             "SUPPLEMENTALARROWS-A");
 36.1249  
 36.1250          /**
 36.1251           * Constant for the "Supplemental Arrows-B" Unicode character block.
 36.1252           * @since 1.5
 36.1253           */
 36.1254          public static final UnicodeBlock SUPPLEMENTAL_ARROWS_B =
 36.1255 -            new UnicodeBlock("SUPPLEMENTAL_ARROWS_B", new String[] {"Supplemental Arrows-B",
 36.1256 -                                                                    "SupplementalArrows-B"});
 36.1257 +            new UnicodeBlock("SUPPLEMENTAL_ARROWS_B",
 36.1258 +                             "SUPPLEMENTAL ARROWS-B",
 36.1259 +                             "SUPPLEMENTALARROWS-B");
 36.1260  
 36.1261          /**
 36.1262           * Constant for the "Miscellaneous Mathematical Symbols-B" Unicode character block.
 36.1263           * @since 1.5
 36.1264           */
 36.1265 -        public static final UnicodeBlock MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B
 36.1266 -                = new UnicodeBlock("MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B",
 36.1267 -                                   new String[] {"Miscellaneous Mathematical Symbols-B",
 36.1268 -                                                 "MiscellaneousMathematicalSymbols-B"});
 36.1269 +        public static final UnicodeBlock MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B =
 36.1270 +            new UnicodeBlock("MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B",
 36.1271 +                             "MISCELLANEOUS MATHEMATICAL SYMBOLS-B",
 36.1272 +                             "MISCELLANEOUSMATHEMATICALSYMBOLS-B");
 36.1273  
 36.1274          /**
 36.1275           * Constant for the "Supplemental Mathematical Operators" Unicode character block.
 36.1276 @@ -1451,127 +1503,151 @@
 36.1277           */
 36.1278          public static final UnicodeBlock SUPPLEMENTAL_MATHEMATICAL_OPERATORS =
 36.1279              new UnicodeBlock("SUPPLEMENTAL_MATHEMATICAL_OPERATORS",
 36.1280 -                             new String[]{"Supplemental Mathematical Operators",
 36.1281 -                                          "SupplementalMathematicalOperators"} );
 36.1282 +                             "SUPPLEMENTAL MATHEMATICAL OPERATORS",
 36.1283 +                             "SUPPLEMENTALMATHEMATICALOPERATORS");
 36.1284  
 36.1285          /**
 36.1286           * Constant for the "Miscellaneous Symbols and Arrows" Unicode character block.
 36.1287           * @since 1.5
 36.1288           */
 36.1289          public static final UnicodeBlock MISCELLANEOUS_SYMBOLS_AND_ARROWS =
 36.1290 -            new UnicodeBlock("MISCELLANEOUS_SYMBOLS_AND_ARROWS", new String[] {"Miscellaneous Symbols and Arrows",
 36.1291 -                                                                               "MiscellaneousSymbolsandArrows"});
 36.1292 +            new UnicodeBlock("MISCELLANEOUS_SYMBOLS_AND_ARROWS",
 36.1293 +                             "MISCELLANEOUS SYMBOLS AND ARROWS",
 36.1294 +                             "MISCELLANEOUSSYMBOLSANDARROWS");
 36.1295  
 36.1296          /**
 36.1297           * Constant for the "Katakana Phonetic Extensions" Unicode character block.
 36.1298           * @since 1.5
 36.1299           */
 36.1300          public static final UnicodeBlock KATAKANA_PHONETIC_EXTENSIONS =
 36.1301 -            new UnicodeBlock("KATAKANA_PHONETIC_EXTENSIONS", new String[] {"Katakana Phonetic Extensions",
 36.1302 -                                                                           "KatakanaPhoneticExtensions"});
 36.1303 +            new UnicodeBlock("KATAKANA_PHONETIC_EXTENSIONS",
 36.1304 +                             "KATAKANA PHONETIC EXTENSIONS",
 36.1305 +                             "KATAKANAPHONETICEXTENSIONS");
 36.1306  
 36.1307          /**
 36.1308           * Constant for the "Yijing Hexagram Symbols" Unicode character block.
 36.1309           * @since 1.5
 36.1310           */
 36.1311          public static final UnicodeBlock YIJING_HEXAGRAM_SYMBOLS =
 36.1312 -            new UnicodeBlock("YIJING_HEXAGRAM_SYMBOLS", new String[] {"Yijing Hexagram Symbols",
 36.1313 -                                                                      "YijingHexagramSymbols"});
 36.1314 +            new UnicodeBlock("YIJING_HEXAGRAM_SYMBOLS",
 36.1315 +                             "YIJING HEXAGRAM SYMBOLS",
 36.1316 +                             "YIJINGHEXAGRAMSYMBOLS");
 36.1317  
 36.1318          /**
 36.1319           * Constant for the "Variation Selectors" Unicode character block.
 36.1320           * @since 1.5
 36.1321           */
 36.1322          public static final UnicodeBlock VARIATION_SELECTORS =
 36.1323 -            new UnicodeBlock("VARIATION_SELECTORS", new String[] {"Variation Selectors", "VariationSelectors"});
 36.1324 +            new UnicodeBlock("VARIATION_SELECTORS",
 36.1325 +                             "VARIATION SELECTORS",
 36.1326 +                             "VARIATIONSELECTORS");
 36.1327  
 36.1328          /**
 36.1329           * Constant for the "Linear B Syllabary" Unicode character block.
 36.1330           * @since 1.5
 36.1331           */
 36.1332          public static final UnicodeBlock LINEAR_B_SYLLABARY =
 36.1333 -            new UnicodeBlock("LINEAR_B_SYLLABARY", new String[] {"Linear B Syllabary", "LinearBSyllabary"});
 36.1334 +            new UnicodeBlock("LINEAR_B_SYLLABARY",
 36.1335 +                             "LINEAR B SYLLABARY",
 36.1336 +                             "LINEARBSYLLABARY");
 36.1337  
 36.1338          /**
 36.1339           * Constant for the "Linear B Ideograms" Unicode character block.
 36.1340           * @since 1.5
 36.1341           */
 36.1342          public static final UnicodeBlock LINEAR_B_IDEOGRAMS =
 36.1343 -            new UnicodeBlock("LINEAR_B_IDEOGRAMS", new String[] {"Linear B Ideograms", "LinearBIdeograms"});
 36.1344 +            new UnicodeBlock("LINEAR_B_IDEOGRAMS",
 36.1345 +                             "LINEAR B IDEOGRAMS",
 36.1346 +                             "LINEARBIDEOGRAMS");
 36.1347  
 36.1348          /**
 36.1349           * Constant for the "Aegean Numbers" Unicode character block.
 36.1350           * @since 1.5
 36.1351           */
 36.1352          public static final UnicodeBlock AEGEAN_NUMBERS =
 36.1353 -            new UnicodeBlock("AEGEAN_NUMBERS", new String[] {"Aegean Numbers", "AegeanNumbers"});
 36.1354 +            new UnicodeBlock("AEGEAN_NUMBERS",
 36.1355 +                             "AEGEAN NUMBERS",
 36.1356 +                             "AEGEANNUMBERS");
 36.1357  
 36.1358          /**
 36.1359           * Constant for the "Old Italic" Unicode character block.
 36.1360           * @since 1.5
 36.1361           */
 36.1362          public static final UnicodeBlock OLD_ITALIC =
 36.1363 -            new UnicodeBlock("OLD_ITALIC", new String[] {"Old Italic", "OldItalic"});
 36.1364 +            new UnicodeBlock("OLD_ITALIC",
 36.1365 +                             "OLD ITALIC",
 36.1366 +                             "OLDITALIC");
 36.1367  
 36.1368          /**
 36.1369           * Constant for the "Gothic" Unicode character block.
 36.1370           * @since 1.5
 36.1371           */
 36.1372 -        public static final UnicodeBlock GOTHIC = new UnicodeBlock("GOTHIC");
 36.1373 +        public static final UnicodeBlock GOTHIC =
 36.1374 +            new UnicodeBlock("GOTHIC");
 36.1375  
 36.1376          /**
 36.1377           * Constant for the "Ugaritic" Unicode character block.
 36.1378           * @since 1.5
 36.1379           */
 36.1380 -        public static final UnicodeBlock UGARITIC = new UnicodeBlock("UGARITIC");
 36.1381 +        public static final UnicodeBlock UGARITIC =
 36.1382 +            new UnicodeBlock("UGARITIC");
 36.1383  
 36.1384          /**
 36.1385           * Constant for the "Deseret" Unicode character block.
 36.1386           * @since 1.5
 36.1387           */
 36.1388 -        public static final UnicodeBlock DESERET = new UnicodeBlock("DESERET");
 36.1389 +        public static final UnicodeBlock DESERET =
 36.1390 +            new UnicodeBlock("DESERET");
 36.1391  
 36.1392          /**
 36.1393           * Constant for the "Shavian" Unicode character block.
 36.1394           * @since 1.5
 36.1395           */
 36.1396 -        public static final UnicodeBlock SHAVIAN = new UnicodeBlock("SHAVIAN");
 36.1397 +        public static final UnicodeBlock SHAVIAN =
 36.1398 +            new UnicodeBlock("SHAVIAN");
 36.1399  
 36.1400          /**
 36.1401           * Constant for the "Osmanya" Unicode character block.
 36.1402           * @since 1.5
 36.1403           */
 36.1404 -        public static final UnicodeBlock OSMANYA = new UnicodeBlock("OSMANYA");
 36.1405 +        public static final UnicodeBlock OSMANYA =
 36.1406 +            new UnicodeBlock("OSMANYA");
 36.1407  
 36.1408          /**
 36.1409           * Constant for the "Cypriot Syllabary" Unicode character block.
 36.1410           * @since 1.5
 36.1411           */
 36.1412          public static final UnicodeBlock CYPRIOT_SYLLABARY =
 36.1413 -            new UnicodeBlock("CYPRIOT_SYLLABARY", new String[] {"Cypriot Syllabary", "CypriotSyllabary"});
 36.1414 +            new UnicodeBlock("CYPRIOT_SYLLABARY",
 36.1415 +                             "CYPRIOT SYLLABARY",
 36.1416 +                             "CYPRIOTSYLLABARY");
 36.1417  
 36.1418          /**
 36.1419           * Constant for the "Byzantine Musical Symbols" Unicode character block.
 36.1420           * @since 1.5
 36.1421           */
 36.1422          public static final UnicodeBlock BYZANTINE_MUSICAL_SYMBOLS =
 36.1423 -            new UnicodeBlock("BYZANTINE_MUSICAL_SYMBOLS", new String[] {"Byzantine Musical Symbols",
 36.1424 -                                                                        "ByzantineMusicalSymbols"});
 36.1425 +            new UnicodeBlock("BYZANTINE_MUSICAL_SYMBOLS",
 36.1426 +                             "BYZANTINE MUSICAL SYMBOLS",
 36.1427 +                             "BYZANTINEMUSICALSYMBOLS");
 36.1428  
 36.1429          /**
 36.1430           * Constant for the "Musical Symbols" Unicode character block.
 36.1431           * @since 1.5
 36.1432           */
 36.1433          public static final UnicodeBlock MUSICAL_SYMBOLS =
 36.1434 -            new UnicodeBlock("MUSICAL_SYMBOLS", new String[] {"Musical Symbols", "MusicalSymbols"});
 36.1435 +            new UnicodeBlock("MUSICAL_SYMBOLS",
 36.1436 +                             "MUSICAL SYMBOLS",
 36.1437 +                             "MUSICALSYMBOLS");
 36.1438  
 36.1439          /**
 36.1440           * Constant for the "Tai Xuan Jing Symbols" Unicode character block.
 36.1441           * @since 1.5
 36.1442           */
 36.1443          public static final UnicodeBlock TAI_XUAN_JING_SYMBOLS =
 36.1444 -            new UnicodeBlock("TAI_XUAN_JING_SYMBOLS", new String[] {"Tai Xuan Jing Symbols",
 36.1445 -                                                                     "TaiXuanJingSymbols"});
 36.1446 +            new UnicodeBlock("TAI_XUAN_JING_SYMBOLS",
 36.1447 +                             "TAI XUAN JING SYMBOLS",
 36.1448 +                             "TAIXUANJINGSYMBOLS");
 36.1449  
 36.1450          /**
 36.1451           * Constant for the "Mathematical Alphanumeric Symbols" Unicode character block.
 36.1452 @@ -1579,7 +1655,8 @@
 36.1453           */
 36.1454          public static final UnicodeBlock MATHEMATICAL_ALPHANUMERIC_SYMBOLS =
 36.1455              new UnicodeBlock("MATHEMATICAL_ALPHANUMERIC_SYMBOLS",
 36.1456 -                             new String[] {"Mathematical Alphanumeric Symbols", "MathematicalAlphanumericSymbols"});
 36.1457 +                             "MATHEMATICAL ALPHANUMERIC SYMBOLS",
 36.1458 +                             "MATHEMATICALALPHANUMERICSYMBOLS");
 36.1459  
 36.1460          /**
 36.1461           * Constant for the "CJK Unified Ideographs Extension B" Unicode character block.
 36.1462 @@ -1587,7 +1664,8 @@
 36.1463           */
 36.1464          public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B =
 36.1465              new UnicodeBlock("CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B",
 36.1466 -                             new String[] {"CJK Unified Ideographs Extension B", "CJKUnifiedIdeographsExtensionB"});
 36.1467 +                             "CJK UNIFIED IDEOGRAPHS EXTENSION B",
 36.1468 +                             "CJKUNIFIEDIDEOGRAPHSEXTENSIONB");
 36.1469  
 36.1470          /**
 36.1471           * Constant for the "CJK Compatibility Ideographs Supplement" Unicode character block.
 36.1472 @@ -1595,22 +1673,24 @@
 36.1473           */
 36.1474          public static final UnicodeBlock CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT =
 36.1475              new UnicodeBlock("CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT",
 36.1476 -                             new String[]{"CJK Compatibility Ideographs Supplement",
 36.1477 -                                          "CJKCompatibilityIdeographsSupplement"});
 36.1478 +                             "CJK COMPATIBILITY IDEOGRAPHS SUPPLEMENT",
 36.1479 +                             "CJKCOMPATIBILITYIDEOGRAPHSSUPPLEMENT");
 36.1480  
 36.1481          /**
 36.1482           * Constant for the "Tags" Unicode character block.
 36.1483           * @since 1.5
 36.1484           */
 36.1485 -        public static final UnicodeBlock TAGS = new UnicodeBlock("TAGS");
 36.1486 +        public static final UnicodeBlock TAGS =
 36.1487 +            new UnicodeBlock("TAGS");
 36.1488  
 36.1489          /**
 36.1490           * Constant for the "Variation Selectors Supplement" Unicode character block.
 36.1491           * @since 1.5
 36.1492           */
 36.1493          public static final UnicodeBlock VARIATION_SELECTORS_SUPPLEMENT =
 36.1494 -            new UnicodeBlock("VARIATION_SELECTORS_SUPPLEMENT", new String[] {"Variation Selectors Supplement",
 36.1495 -                                                                             "VariationSelectorsSupplement"});
 36.1496 +            new UnicodeBlock("VARIATION_SELECTORS_SUPPLEMENT",
 36.1497 +                             "VARIATION SELECTORS SUPPLEMENT",
 36.1498 +                             "VARIATIONSELECTORSSUPPLEMENT");
 36.1499  
 36.1500          /**
 36.1501           * Constant for the "Supplementary Private Use Area-A" Unicode character block.
 36.1502 @@ -1618,8 +1698,8 @@
 36.1503           */
 36.1504          public static final UnicodeBlock SUPPLEMENTARY_PRIVATE_USE_AREA_A =
 36.1505              new UnicodeBlock("SUPPLEMENTARY_PRIVATE_USE_AREA_A",
 36.1506 -                             new String[] {"Supplementary Private Use Area-A",
 36.1507 -                                           "SupplementaryPrivateUseArea-A"});
 36.1508 +                             "SUPPLEMENTARY PRIVATE USE AREA-A",
 36.1509 +                             "SUPPLEMENTARYPRIVATEUSEAREA-A");
 36.1510  
 36.1511          /**
 36.1512           * Constant for the "Supplementary Private Use Area-B" Unicode character block.
 36.1513 @@ -1627,39 +1707,44 @@
 36.1514           */
 36.1515          public static final UnicodeBlock SUPPLEMENTARY_PRIVATE_USE_AREA_B =
 36.1516              new UnicodeBlock("SUPPLEMENTARY_PRIVATE_USE_AREA_B",
 36.1517 -                             new String[] {"Supplementary Private Use Area-B",
 36.1518 -                                           "SupplementaryPrivateUseArea-B"});
 36.1519 +                             "SUPPLEMENTARY PRIVATE USE AREA-B",
 36.1520 +                             "SUPPLEMENTARYPRIVATEUSEAREA-B");
 36.1521  
 36.1522          /**
 36.1523           * Constant for the "High Surrogates" Unicode character block.
 36.1524           * This block represents codepoint values in the high surrogate
 36.1525 -         * range: 0xD800 through 0xDB7F
 36.1526 +         * range: U+D800 through U+DB7F
 36.1527           *
 36.1528           * @since 1.5
 36.1529           */
 36.1530          public static final UnicodeBlock HIGH_SURROGATES =
 36.1531 -            new UnicodeBlock("HIGH_SURROGATES", new String[] {"High Surrogates", "HighSurrogates"});
 36.1532 +            new UnicodeBlock("HIGH_SURROGATES",
 36.1533 +                             "HIGH SURROGATES",
 36.1534 +                             "HIGHSURROGATES");
 36.1535  
 36.1536          /**
 36.1537           * Constant for the "High Private Use Surrogates" Unicode character block.
 36.1538 -         * This block represents codepoint values in the high surrogate
 36.1539 -         * range: 0xDB80 through 0xDBFF
 36.1540 +         * This block represents codepoint values in the private use high surrogate
 36.1541 +         * range: U+DB80 through U+DBFF
 36.1542           *
 36.1543           * @since 1.5
 36.1544           */
 36.1545          public static final UnicodeBlock HIGH_PRIVATE_USE_SURROGATES =
 36.1546 -            new UnicodeBlock("HIGH_PRIVATE_USE_SURROGATES", new String[] { "High Private Use Surrogates",
 36.1547 -                                                                           "HighPrivateUseSurrogates"});
 36.1548 +            new UnicodeBlock("HIGH_PRIVATE_USE_SURROGATES",
 36.1549 +                             "HIGH PRIVATE USE SURROGATES",
 36.1550 +                             "HIGHPRIVATEUSESURROGATES");
 36.1551  
 36.1552          /**
 36.1553           * Constant for the "Low Surrogates" Unicode character block.
 36.1554 -         * This block represents codepoint values in the high surrogate
 36.1555 -         * range: 0xDC00 through 0xDFFF
 36.1556 +         * This block represents codepoint values in the low surrogate
 36.1557 +         * range: U+DC00 through U+DFFF
 36.1558           *
 36.1559           * @since 1.5
 36.1560           */
 36.1561          public static final UnicodeBlock LOW_SURROGATES =
 36.1562 -            new UnicodeBlock("LOW_SURROGATES", new String[] {"Low Surrogates", "LowSurrogates"});
 36.1563 +            new UnicodeBlock("LOW_SURROGATES",
 36.1564 +                             "LOW SURROGATES",
 36.1565 +                             "LOWSURROGATES");
 36.1566  
 36.1567          /**
 36.1568           * Constant for the "Arabic Supplement" Unicode character block.
 36.1569 @@ -1667,14 +1752,15 @@
 36.1570           */
 36.1571          public static final UnicodeBlock ARABIC_SUPPLEMENT =
 36.1572              new UnicodeBlock("ARABIC_SUPPLEMENT",
 36.1573 -                             new String[] { "Arabic Supplement",
 36.1574 -                                            "ArabicSupplement"});
 36.1575 +                             "ARABIC SUPPLEMENT",
 36.1576 +                             "ARABICSUPPLEMENT");
 36.1577  
 36.1578          /**
 36.1579           * Constant for the "NKo" Unicode character block.
 36.1580           * @since 1.7
 36.1581           */
 36.1582 -        public static final UnicodeBlock NKO = new UnicodeBlock("NKO");
 36.1583 +        public static final UnicodeBlock NKO =
 36.1584 +            new UnicodeBlock("NKO");
 36.1585  
 36.1586          /**
 36.1587           * Constant for the "Ethiopic Supplement" Unicode character block.
 36.1588 @@ -1682,8 +1768,8 @@
 36.1589           */
 36.1590          public static final UnicodeBlock ETHIOPIC_SUPPLEMENT =
 36.1591              new UnicodeBlock("ETHIOPIC_SUPPLEMENT",
 36.1592 -                             new String[] { "Ethiopic Supplement",
 36.1593 -                                            "EthiopicSupplement"});
 36.1594 +                             "ETHIOPIC SUPPLEMENT",
 36.1595 +                             "ETHIOPICSUPPLEMENT");
 36.1596  
 36.1597          /**
 36.1598           * Constant for the "New Tai Lue" Unicode character block.
 36.1599 @@ -1691,8 +1777,8 @@
 36.1600           */
 36.1601          public static final UnicodeBlock NEW_TAI_LUE =
 36.1602              new UnicodeBlock("NEW_TAI_LUE",
 36.1603 -                             new String[] { "New Tai Lue",
 36.1604 -                                            "NewTaiLue"});
 36.1605 +                             "NEW TAI LUE",
 36.1606 +                             "NEWTAILUE");
 36.1607  
 36.1608          /**
 36.1609           * Constant for the "Buginese" Unicode character block.
 36.1610 @@ -1719,7 +1805,8 @@
 36.1611           * Constant for the "Lepcha" Unicode character block.
 36.1612           * @since 1.7
 36.1613           */
 36.1614 -        public static final UnicodeBlock LEPCHA = new UnicodeBlock("LEPCHA");
 36.1615 +        public static final UnicodeBlock LEPCHA =
 36.1616 +            new UnicodeBlock("LEPCHA");
 36.1617  
 36.1618          /**
 36.1619           * Constant for the "Ol Chiki" Unicode character block.
 36.1620 @@ -1727,8 +1814,8 @@
 36.1621           */
 36.1622          public static final UnicodeBlock OL_CHIKI =
 36.1623              new UnicodeBlock("OL_CHIKI",
 36.1624 -                             new String[] { "Ol Chiki",
 36.1625 -                                            "OlChiki"});
 36.1626 +                             "OL CHIKI",
 36.1627 +                             "OLCHIKI");
 36.1628  
 36.1629          /**
 36.1630           * Constant for the "Phonetic Extensions Supplement" Unicode character
 36.1631 @@ -1737,8 +1824,8 @@
 36.1632           */
 36.1633          public static final UnicodeBlock PHONETIC_EXTENSIONS_SUPPLEMENT =
 36.1634              new UnicodeBlock("PHONETIC_EXTENSIONS_SUPPLEMENT",
 36.1635 -                             new String[] { "Phonetic Extensions Supplement",
 36.1636 -                                            "PhoneticExtensionsSupplement"});
 36.1637 +                             "PHONETIC EXTENSIONS SUPPLEMENT",
 36.1638 +                             "PHONETICEXTENSIONSSUPPLEMENT");
 36.1639  
 36.1640          /**
 36.1641           * Constant for the "Combining Diacritical Marks Supplement" Unicode
 36.1642 @@ -1747,8 +1834,8 @@
 36.1643           */
 36.1644          public static final UnicodeBlock COMBINING_DIACRITICAL_MARKS_SUPPLEMENT =
 36.1645              new UnicodeBlock("COMBINING_DIACRITICAL_MARKS_SUPPLEMENT",
 36.1646 -                             new String[] { "Combining Diacritical Marks Supplement",
 36.1647 -                                            "CombiningDiacriticalMarksSupplement"});
 36.1648 +                             "COMBINING DIACRITICAL MARKS SUPPLEMENT",
 36.1649 +                             "COMBININGDIACRITICALMARKSSUPPLEMENT");
 36.1650  
 36.1651          /**
 36.1652           * Constant for the "Glagolitic" Unicode character block.
 36.1653 @@ -1763,14 +1850,15 @@
 36.1654           */
 36.1655          public static final UnicodeBlock LATIN_EXTENDED_C =
 36.1656              new UnicodeBlock("LATIN_EXTENDED_C",
 36.1657 -                             new String[] { "Latin Extended-C",
 36.1658 -                                            "LatinExtended-C"});
 36.1659 +                             "LATIN EXTENDED-C",
 36.1660 +                             "LATINEXTENDED-C");
 36.1661  
 36.1662          /**
 36.1663           * Constant for the "Coptic" Unicode character block.
 36.1664           * @since 1.7
 36.1665           */
 36.1666 -        public static final UnicodeBlock COPTIC = new UnicodeBlock("COPTIC");
 36.1667 +        public static final UnicodeBlock COPTIC =
 36.1668 +            new UnicodeBlock("COPTIC");
 36.1669  
 36.1670          /**
 36.1671           * Constant for the "Georgian Supplement" Unicode character block.
 36.1672 @@ -1778,8 +1866,8 @@
 36.1673           */
 36.1674          public static final UnicodeBlock GEORGIAN_SUPPLEMENT =
 36.1675              new UnicodeBlock("GEORGIAN_SUPPLEMENT",
 36.1676 -                             new String[] { "Georgian Supplement",
 36.1677 -                                            "GeorgianSupplement"});
 36.1678 +                             "GEORGIAN SUPPLEMENT",
 36.1679 +                             "GEORGIANSUPPLEMENT");
 36.1680  
 36.1681          /**
 36.1682           * Constant for the "Tifinagh" Unicode character block.
 36.1683 @@ -1794,8 +1882,8 @@
 36.1684           */
 36.1685          public static final UnicodeBlock ETHIOPIC_EXTENDED =
 36.1686              new UnicodeBlock("ETHIOPIC_EXTENDED",
 36.1687 -                             new String[] { "Ethiopic Extended",
 36.1688 -                                            "EthiopicExtended"});
 36.1689 +                             "ETHIOPIC EXTENDED",
 36.1690 +                             "ETHIOPICEXTENDED");
 36.1691  
 36.1692          /**
 36.1693           * Constant for the "Cyrillic Extended-A" Unicode character block.
 36.1694 @@ -1803,8 +1891,8 @@
 36.1695           */
 36.1696          public static final UnicodeBlock CYRILLIC_EXTENDED_A =
 36.1697              new UnicodeBlock("CYRILLIC_EXTENDED_A",
 36.1698 -                             new String[] { "Cyrillic Extended-A",
 36.1699 -                                            "CyrillicExtended-A"});
 36.1700 +                             "CYRILLIC EXTENDED-A",
 36.1701 +                             "CYRILLICEXTENDED-A");
 36.1702  
 36.1703          /**
 36.1704           * Constant for the "Supplemental Punctuation" Unicode character block.
 36.1705 @@ -1812,8 +1900,8 @@
 36.1706           */
 36.1707          public static final UnicodeBlock SUPPLEMENTAL_PUNCTUATION =
 36.1708              new UnicodeBlock("SUPPLEMENTAL_PUNCTUATION",
 36.1709 -                             new String[] { "Supplemental Punctuation",
 36.1710 -                                            "SupplementalPunctuation"});
 36.1711 +                             "SUPPLEMENTAL PUNCTUATION",
 36.1712 +                             "SUPPLEMENTALPUNCTUATION");
 36.1713  
 36.1714          /**
 36.1715           * Constant for the "CJK Strokes" Unicode character block.
 36.1716 @@ -1821,14 +1909,15 @@
 36.1717           */
 36.1718          public static final UnicodeBlock CJK_STROKES =
 36.1719              new UnicodeBlock("CJK_STROKES",
 36.1720 -                             new String[] { "CJK Strokes",
 36.1721 -                                            "CJKStrokes"});
 36.1722 +                             "CJK STROKES",
 36.1723 +                             "CJKSTROKES");
 36.1724  
 36.1725          /**
 36.1726           * Constant for the "Vai" Unicode character block.
 36.1727           * @since 1.7
 36.1728           */
 36.1729 -        public static final UnicodeBlock VAI = new UnicodeBlock("VAI");
 36.1730 +        public static final UnicodeBlock VAI =
 36.1731 +            new UnicodeBlock("VAI");
 36.1732  
 36.1733          /**
 36.1734           * Constant for the "Cyrillic Extended-B" Unicode character block.
 36.1735 @@ -1836,8 +1925,8 @@
 36.1736           */
 36.1737          public static final UnicodeBlock CYRILLIC_EXTENDED_B =
 36.1738              new UnicodeBlock("CYRILLIC_EXTENDED_B",
 36.1739 -                             new String[] { "Cyrillic Extended-B",
 36.1740 -                                            "CyrillicExtended-B"});
 36.1741 +                             "CYRILLIC EXTENDED-B",
 36.1742 +                             "CYRILLICEXTENDED-B");
 36.1743  
 36.1744          /**
 36.1745           * Constant for the "Modifier Tone Letters" Unicode character block.
 36.1746 @@ -1845,8 +1934,8 @@
 36.1747           */
 36.1748          public static final UnicodeBlock MODIFIER_TONE_LETTERS =
 36.1749              new UnicodeBlock("MODIFIER_TONE_LETTERS",
 36.1750 -                             new String[] { "Modifier Tone Letters",
 36.1751 -                                            "ModifierToneLetters"});
 36.1752 +                             "MODIFIER TONE LETTERS",
 36.1753 +                             "MODIFIERTONELETTERS");
 36.1754  
 36.1755          /**
 36.1756           * Constant for the "Latin Extended-D" Unicode character block.
 36.1757 @@ -1854,8 +1943,8 @@
 36.1758           */
 36.1759          public static final UnicodeBlock LATIN_EXTENDED_D =
 36.1760              new UnicodeBlock("LATIN_EXTENDED_D",
 36.1761 -                             new String[] { "Latin Extended-D",
 36.1762 -                                            "LatinExtended-D"});
 36.1763 +                             "LATIN EXTENDED-D",
 36.1764 +                             "LATINEXTENDED-D");
 36.1765  
 36.1766          /**
 36.1767           * Constant for the "Syloti Nagri" Unicode character block.
 36.1768 @@ -1863,15 +1952,16 @@
 36.1769           */
 36.1770          public static final UnicodeBlock SYLOTI_NAGRI =
 36.1771              new UnicodeBlock("SYLOTI_NAGRI",
 36.1772 -                             new String[] { "Syloti Nagri",
 36.1773 -                                            "SylotiNagri"});
 36.1774 +                             "SYLOTI NAGRI",
 36.1775 +                             "SYLOTINAGRI");
 36.1776  
 36.1777          /**
 36.1778           * Constant for the "Phags-pa" Unicode character block.
 36.1779           * @since 1.7
 36.1780           */
 36.1781          public static final UnicodeBlock PHAGS_PA =
 36.1782 -            new UnicodeBlock("PHAGS_PA", new String[] { "Phags-pa"});
 36.1783 +            new UnicodeBlock("PHAGS_PA",
 36.1784 +                             "PHAGS-PA");
 36.1785  
 36.1786          /**
 36.1787           * Constant for the "Saurashtra" Unicode character block.
 36.1788 @@ -1886,20 +1976,22 @@
 36.1789           */
 36.1790          public static final UnicodeBlock KAYAH_LI =
 36.1791              new UnicodeBlock("KAYAH_LI",
 36.1792 -                             new String[] { "Kayah Li",
 36.1793 -                                            "KayahLi"});
 36.1794 +                             "KAYAH LI",
 36.1795 +                             "KAYAHLI");
 36.1796  
 36.1797          /**
 36.1798           * Constant for the "Rejang" Unicode character block.
 36.1799           * @since 1.7
 36.1800           */
 36.1801 -        public static final UnicodeBlock REJANG = new UnicodeBlock("REJANG");
 36.1802 +        public static final UnicodeBlock REJANG =
 36.1803 +            new UnicodeBlock("REJANG");
 36.1804  
 36.1805          /**
 36.1806           * Constant for the "Cham" Unicode character block.
 36.1807           * @since 1.7
 36.1808           */
 36.1809 -        public static final UnicodeBlock CHAM = new UnicodeBlock("CHAM");
 36.1810 +        public static final UnicodeBlock CHAM =
 36.1811 +            new UnicodeBlock("CHAM");
 36.1812  
 36.1813          /**
 36.1814           * Constant for the "Vertical Forms" Unicode character block.
 36.1815 @@ -1907,8 +1999,8 @@
 36.1816           */
 36.1817          public static final UnicodeBlock VERTICAL_FORMS =
 36.1818              new UnicodeBlock("VERTICAL_FORMS",
 36.1819 -                             new String[] { "Vertical Forms",
 36.1820 -                                            "VerticalForms"});
 36.1821 +                             "VERTICAL FORMS",
 36.1822 +                             "VERTICALFORMS");
 36.1823  
 36.1824          /**
 36.1825           * Constant for the "Ancient Greek Numbers" Unicode character block.
 36.1826 @@ -1916,8 +2008,8 @@
 36.1827           */
 36.1828          public static final UnicodeBlock ANCIENT_GREEK_NUMBERS =
 36.1829              new UnicodeBlock("ANCIENT_GREEK_NUMBERS",
 36.1830 -                             new String[] { "Ancient Greek Numbers",
 36.1831 -                                            "AncientGreekNumbers"});
 36.1832 +                             "ANCIENT GREEK NUMBERS",
 36.1833 +                             "ANCIENTGREEKNUMBERS");
 36.1834  
 36.1835          /**
 36.1836           * Constant for the "Ancient Symbols" Unicode character block.
 36.1837 @@ -1925,8 +2017,8 @@
 36.1838           */
 36.1839          public static final UnicodeBlock ANCIENT_SYMBOLS =
 36.1840              new UnicodeBlock("ANCIENT_SYMBOLS",
 36.1841 -                             new String[] { "Ancient Symbols",
 36.1842 -                                            "AncientSymbols"});
 36.1843 +                             "ANCIENT SYMBOLS",
 36.1844 +                             "ANCIENTSYMBOLS");
 36.1845  
 36.1846          /**
 36.1847           * Constant for the "Phaistos Disc" Unicode character block.
 36.1848 @@ -1934,20 +2026,22 @@
 36.1849           */
 36.1850          public static final UnicodeBlock PHAISTOS_DISC =
 36.1851              new UnicodeBlock("PHAISTOS_DISC",
 36.1852 -                             new String[] { "Phaistos Disc",
 36.1853 -                                            "PhaistosDisc"});
 36.1854 +                             "PHAISTOS DISC",
 36.1855 +                             "PHAISTOSDISC");
 36.1856  
 36.1857          /**
 36.1858           * Constant for the "Lycian" Unicode character block.
 36.1859           * @since 1.7
 36.1860           */
 36.1861 -        public static final UnicodeBlock LYCIAN = new UnicodeBlock("LYCIAN");
 36.1862 +        public static final UnicodeBlock LYCIAN =
 36.1863 +            new UnicodeBlock("LYCIAN");
 36.1864  
 36.1865          /**
 36.1866           * Constant for the "Carian" Unicode character block.
 36.1867           * @since 1.7
 36.1868           */
 36.1869 -        public static final UnicodeBlock CARIAN = new UnicodeBlock("CARIAN");
 36.1870 +        public static final UnicodeBlock CARIAN =
 36.1871 +            new UnicodeBlock("CARIAN");
 36.1872  
 36.1873          /**
 36.1874           * Constant for the "Old Persian" Unicode character block.
 36.1875 @@ -1955,8 +2049,8 @@
 36.1876           */
 36.1877          public static final UnicodeBlock OLD_PERSIAN =
 36.1878              new UnicodeBlock("OLD_PERSIAN",
 36.1879 -                             new String[] { "Old Persian",
 36.1880 -                                            "OldPersian"});
 36.1881 +                             "OLD PERSIAN",
 36.1882 +                             "OLDPERSIAN");
 36.1883  
 36.1884          /**
 36.1885           * Constant for the "Phoenician" Unicode character block.
 36.1886 @@ -1969,7 +2063,8 @@
 36.1887           * Constant for the "Lydian" Unicode character block.
 36.1888           * @since 1.7
 36.1889           */
 36.1890 -        public static final UnicodeBlock LYDIAN = new UnicodeBlock("LYDIAN");
 36.1891 +        public static final UnicodeBlock LYDIAN =
 36.1892 +            new UnicodeBlock("LYDIAN");
 36.1893  
 36.1894          /**
 36.1895           * Constant for the "Kharoshthi" Unicode character block.
 36.1896 @@ -1992,8 +2087,8 @@
 36.1897           */
 36.1898          public static final UnicodeBlock CUNEIFORM_NUMBERS_AND_PUNCTUATION =
 36.1899              new UnicodeBlock("CUNEIFORM_NUMBERS_AND_PUNCTUATION",
 36.1900 -                             new String[] { "Cuneiform Numbers and Punctuation",
 36.1901 -                                            "CuneiformNumbersandPunctuation"});
 36.1902 +                             "CUNEIFORM NUMBERS AND PUNCTUATION",
 36.1903 +                             "CUNEIFORMNUMBERSANDPUNCTUATION");
 36.1904  
 36.1905          /**
 36.1906           * Constant for the "Ancient Greek Musical Notation" Unicode character
 36.1907 @@ -2002,8 +2097,8 @@
 36.1908           */
 36.1909          public static final UnicodeBlock ANCIENT_GREEK_MUSICAL_NOTATION =
 36.1910              new UnicodeBlock("ANCIENT_GREEK_MUSICAL_NOTATION",
 36.1911 -                             new String[] { "Ancient Greek Musical Notation",
 36.1912 -                                            "AncientGreekMusicalNotation"});
 36.1913 +                             "ANCIENT GREEK MUSICAL NOTATION",
 36.1914 +                             "ANCIENTGREEKMUSICALNOTATION");
 36.1915  
 36.1916          /**
 36.1917           * Constant for the "Counting Rod Numerals" Unicode character block.
 36.1918 @@ -2011,8 +2106,8 @@
 36.1919           */
 36.1920          public static final UnicodeBlock COUNTING_ROD_NUMERALS =
 36.1921              new UnicodeBlock("COUNTING_ROD_NUMERALS",
 36.1922 -                             new String[] { "Counting Rod Numerals",
 36.1923 -                                            "CountingRodNumerals"});
 36.1924 +                             "COUNTING ROD NUMERALS",
 36.1925 +                             "COUNTINGRODNUMERALS");
 36.1926  
 36.1927          /**
 36.1928           * Constant for the "Mahjong Tiles" Unicode character block.
 36.1929 @@ -2020,8 +2115,8 @@
 36.1930           */
 36.1931          public static final UnicodeBlock MAHJONG_TILES =
 36.1932              new UnicodeBlock("MAHJONG_TILES",
 36.1933 -                             new String[] { "Mahjong Tiles",
 36.1934 -                                            "MahjongTiles"});
 36.1935 +                             "MAHJONG TILES",
 36.1936 +                             "MAHJONGTILES");
 36.1937  
 36.1938          /**
 36.1939           * Constant for the "Domino Tiles" Unicode character block.
 36.1940 @@ -2029,8 +2124,8 @@
 36.1941           */
 36.1942          public static final UnicodeBlock DOMINO_TILES =
 36.1943              new UnicodeBlock("DOMINO_TILES",
 36.1944 -                             new String[] { "Domino Tiles",
 36.1945 -                                            "DominoTiles"});
 36.1946 +                             "DOMINO TILES",
 36.1947 +                             "DOMINOTILES");
 36.1948  
 36.1949          private static final int blockStarts[] = {
 36.1950              0x0000,   // 0000..007F; Basic Latin
 36.1951 @@ -2046,7 +2141,7 @@
 36.1952              0x0530,   // 0530..058F; Armenian
 36.1953              0x0590,   // 0590..05FF; Hebrew
 36.1954              0x0600,   // 0600..06FF; Arabic
 36.1955 -            0x0700,   // 0700..074F; Syria
 36.1956 +            0x0700,   // 0700..074F; Syriac
 36.1957              0x0750,   // 0750..077F; Arabic Supplement
 36.1958              0x0780,   // 0780..07BF; Thaana
 36.1959              0x07C0,   // 07C0..07FF; NKo
 36.1960 @@ -2446,11 +2541,10 @@
 36.1961           * given character, or <code>null</code> if the character is not a
 36.1962           * member of a defined block.
 36.1963           *
 36.1964 -                 * <p><b>Note:</b> This method cannot handle <a
 36.1965 -                 * href="Character.html#supplementary"> supplementary
 36.1966 -                 * characters</a>. To support all Unicode characters,
 36.1967 -                 * including supplementary characters, use the {@link
 36.1968 -                 * #of(int)} method.
 36.1969 +         * <p><b>Note:</b> This method cannot handle
 36.1970 +         * <a href="Character.html#supplementary"> supplementary
 36.1971 +         * characters</a>.  To support all Unicode characters, including
 36.1972 +         * supplementary characters, use the {@link #of(int)} method.
 36.1973           *
 36.1974           * @param   c  The character in question
 36.1975           * @return  The <code>UnicodeBlock</code> instance representing the
 36.1976 @@ -2462,22 +2556,21 @@
 36.1977              return of((int)c);
 36.1978          }
 36.1979  
 36.1980 -
 36.1981          /**
 36.1982           * Returns the object representing the Unicode block
 36.1983           * containing the given character (Unicode code point), or
 36.1984           * <code>null</code> if the character is not a member of a
 36.1985           * defined block.
 36.1986           *
 36.1987 -                 * @param   codePoint the character (Unicode code point) in question.
 36.1988 +         * @param   codePoint the character (Unicode code point) in question.
 36.1989           * @return  The <code>UnicodeBlock</code> instance representing the
 36.1990           *          Unicode block of which this character is a member, or
 36.1991           *          <code>null</code> if the character is not a member of any
 36.1992           *          Unicode block
 36.1993 -                 * @exception IllegalArgumentException if the specified
 36.1994 -                 * <code>codePoint</code> is an invalid Unicode code point.
 36.1995 -                 * @see Character#isValidCodePoint(int)
 36.1996 -                 * @since   1.5
 36.1997 +         * @exception IllegalArgumentException if the specified
 36.1998 +         * <code>codePoint</code> is an invalid Unicode code point.
 36.1999 +         * @see Character#isValidCodePoint(int)
 36.2000 +         * @since   1.5
 36.2001           */
 36.2002          public static UnicodeBlock of(int codePoint) {
 36.2003              if (!isValidCodePoint(codePoint)) {
 36.2004 @@ -2519,7 +2612,7 @@
 36.2005           * <li>The text representation of each constant UnicodeBlock identifier.
 36.2006           * For example, this method will return the {@link #BASIC_LATIN} block if
 36.2007           * provided with the "BASIC_LATIN" name. This form replaces all spaces and
 36.2008 -         *  hyphens in the canonical name with underscores.
 36.2009 +         * hyphens in the canonical name with underscores.
 36.2010           * </ol>
 36.2011           * Finally, character case is ignored for all of the valid block name forms.
 36.2012           * For example, "BASIC_LATIN" and "basic_latin" are both valid block names.
 36.2013 @@ -2538,7 +2631,7 @@
 36.2014           * @since 1.5
 36.2015           */
 36.2016          public static final UnicodeBlock forName(String blockName) {
 36.2017 -            UnicodeBlock block = (UnicodeBlock)map.get(blockName.toUpperCase(Locale.US));
 36.2018 +            UnicodeBlock block = map.get(blockName.toUpperCase(Locale.US));
 36.2019              if (block == null) {
 36.2020                  throw new IllegalArgumentException();
 36.2021              }
 36.2022 @@ -3627,7 +3720,7 @@
 36.2023  
 36.2024          private static HashMap<String, Character.UnicodeScript> aliases;
 36.2025          static {
 36.2026 -            aliases = new HashMap<String, UnicodeScript>();
 36.2027 +            aliases = new HashMap<String, UnicodeScript>(128);
 36.2028              aliases.put("ARAB", ARABIC);
 36.2029              aliases.put("ARMI", IMPERIAL_ARAMAIC);
 36.2030              aliases.put("ARMN", ARMENIAN);
 36.2031 @@ -3809,7 +3902,7 @@
 36.2032          static final Character cache[] = new Character[127 + 1];
 36.2033  
 36.2034          static {
 36.2035 -            for(int i = 0; i < cache.length; i++)
 36.2036 +            for (int i = 0; i < cache.length; i++)
 36.2037                  cache[i] = new Character((char)i);
 36.2038          }
 36.2039      }
 36.2040 @@ -3832,7 +3925,7 @@
 36.2041       * @since  1.5
 36.2042       */
 36.2043      public static Character valueOf(char c) {
 36.2044 -        if(c <= 127) { // must cache
 36.2045 +        if (c <= 127) { // must cache
 36.2046              return CharacterCache.cache[(int)c];
 36.2047          }
 36.2048          return new Character(c);
 36.2049 @@ -3914,7 +4007,29 @@
 36.2050       * @since  1.5
 36.2051       */
 36.2052      public static boolean isValidCodePoint(int codePoint) {
 36.2053 -        return codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT;
 36.2054 +        // Optimized form of:
 36.2055 +        //     codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT
 36.2056 +        int plane = codePoint >>> 16;
 36.2057 +        return plane < ((MAX_CODE_POINT + 1) >>> 16);
 36.2058 +    }
 36.2059 +
 36.2060 +    /**
 36.2061 +     * Determines whether the specified character (Unicode code point)
 36.2062 +     * is in the <a href="#BMP">Basic Multilingual Plane (BMP)</a>.
 36.2063 +     * Such code points can be represented using a single {@code char}.
 36.2064 +     *
 36.2065 +     * @param  codePoint the character (Unicode code point) to be tested
 36.2066 +     * @return {@code true} if the specified code point is between
 36.2067 +     *         {@link #MIN_VALUE} and {@link #MAX_VALUE} inclusive;
 36.2068 +     *         {@code false} otherwise.
 36.2069 +     * @since  1.7
 36.2070 +     */
 36.2071 +    public static boolean isBmpCodePoint(int codePoint) {
 36.2072 +        return codePoint >>> 16 == 0;
 36.2073 +        // Optimized form of:
 36.2074 +        //     codePoint >= MIN_VALUE && codePoint <= MAX_VALUE
 36.2075 +        // We consistently use logical shift (>>>) to facilitate
 36.2076 +        // additional runtime optimizations.
 36.2077      }
 36.2078  
 36.2079      /**
 36.2080 @@ -3930,7 +4045,7 @@
 36.2081       */
 36.2082      public static boolean isSupplementaryCodePoint(int codePoint) {
 36.2083          return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT
 36.2084 -            && codePoint <= MAX_CODE_POINT;
 36.2085 +            && codePoint <  MAX_CODE_POINT + 1;
 36.2086      }
 36.2087  
 36.2088      /**
 36.2089 @@ -3949,12 +4064,13 @@
 36.2090       *         {@link #MIN_HIGH_SURROGATE} and
 36.2091       *         {@link #MAX_HIGH_SURROGATE} inclusive;
 36.2092       *         {@code false} otherwise.
 36.2093 -     * @see    #isLowSurrogate(char)
 36.2094 +     * @see    Character#isLowSurrogate(char)
 36.2095       * @see    Character.UnicodeBlock#of(int)
 36.2096       * @since  1.5
 36.2097       */
 36.2098      public static boolean isHighSurrogate(char ch) {
 36.2099 -        return ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE;
 36.2100 +        // Help VM constant-fold; MAX_HIGH_SURROGATE + 1 == MIN_LOW_SURROGATE
 36.2101 +        return ch >= MIN_HIGH_SURROGATE && ch < (MAX_HIGH_SURROGATE + 1);
 36.2102      }
 36.2103  
 36.2104      /**
 36.2105 @@ -3973,11 +4089,11 @@
 36.2106       *         {@link #MIN_LOW_SURROGATE} and
 36.2107       *         {@link #MAX_LOW_SURROGATE} inclusive;
 36.2108       *         {@code false} otherwise.
 36.2109 -     * @see    #isHighSurrogate(char)
 36.2110 +     * @see    Character#isHighSurrogate(char)
 36.2111       * @since  1.5
 36.2112       */
 36.2113      public static boolean isLowSurrogate(char ch) {
 36.2114 -        return ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE;
 36.2115 +        return ch >= MIN_LOW_SURROGATE && ch < (MAX_LOW_SURROGATE + 1);
 36.2116      }
 36.2117  
 36.2118      /**
 36.2119 @@ -4001,7 +4117,7 @@
 36.2120       * @since  1.7
 36.2121       */
 36.2122      public static boolean isSurrogate(char ch) {
 36.2123 -        return ch >= MIN_SURROGATE && ch <= MAX_SURROGATE;
 36.2124 +        return ch >= MIN_SURROGATE && ch < (MAX_SURROGATE + 1);
 36.2125      }
 36.2126  
 36.2127      /**
 36.2128 @@ -4039,11 +4155,11 @@
 36.2129       *
 36.2130       * @param   codePoint the character (Unicode code point) to be tested.
 36.2131       * @return  2 if the character is a valid supplementary character; 1 otherwise.
 36.2132 -     * @see     #isSupplementaryCodePoint(int)
 36.2133 +     * @see     Character#isSupplementaryCodePoint(int)
 36.2134       * @since   1.5
 36.2135       */
 36.2136      public static int charCount(int codePoint) {
 36.2137 -        return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT? 2 : 1;
 36.2138 +        return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT ? 2 : 1;
 36.2139      }
 36.2140  
 36.2141      /**
 36.2142 @@ -4160,6 +4276,7 @@
 36.2143          return codePointAtImpl(a, index, limit);
 36.2144      }
 36.2145  
 36.2146 +    // throws ArrayIndexOutofBoundsException if index out of bounds
 36.2147      static int codePointAtImpl(char[] a, int index, int limit) {
 36.2148          char c1 = a[index++];
 36.2149          if (isHighSurrogate(c1)) {
 36.2150 @@ -4266,6 +4383,7 @@
 36.2151          return codePointBeforeImpl(a, index, start);
 36.2152      }
 36.2153  
 36.2154 +    // throws ArrayIndexOutofBoundsException if index-1 out of bounds
 36.2155      static int codePointBeforeImpl(char[] a, int index, int start) {
 36.2156          char c2 = a[--index];
 36.2157          if (isLowSurrogate(c2)) {
 36.2158 @@ -4280,6 +4398,63 @@
 36.2159      }
 36.2160  
 36.2161      /**
 36.2162 +     * Returns the leading surrogate (a
 36.2163 +     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 36.2164 +     * high surrogate code unit</a>) of the
 36.2165 +     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
 36.2166 +     * surrogate pair</a>
 36.2167 +     * representing the specified supplementary character (Unicode
 36.2168 +     * code point) in the UTF-16 encoding.  If the specified character
 36.2169 +     * is not a
 36.2170 +     * <a href="Character.html#supplementary">supplementary character</a>,
 36.2171 +     * an unspecified {@code char} is returned.
 36.2172 +     *
 36.2173 +     * <p>If
 36.2174 +     * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
 36.2175 +     * is {@code true}, then
 36.2176 +     * {@link #isHighSurrogate isHighSurrogate}{@code (highSurrogate(x))} and
 36.2177 +     * {@link #toCodePoint toCodePoint}{@code (highSurrogate(x), }{@link #lowSurrogate lowSurrogate}{@code (x)) == x}
 36.2178 +     * are also always {@code true}.
 36.2179 +     *
 36.2180 +     * @param   codePoint a supplementary character (Unicode code point)
 36.2181 +     * @return  the leading surrogate code unit used to represent the
 36.2182 +     *          character in the UTF-16 encoding
 36.2183 +     * @since   1.7
 36.2184 +     */
 36.2185 +    public static char highSurrogate(int codePoint) {
 36.2186 +        return (char) ((codePoint >>> 10)
 36.2187 +            + (MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >>> 10)));
 36.2188 +    }
 36.2189 +
 36.2190 +    /**
 36.2191 +     * Returns the trailing surrogate (a
 36.2192 +     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 36.2193 +     * low surrogate code unit</a>) of the
 36.2194 +     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
 36.2195 +     * surrogate pair</a>
 36.2196 +     * representing the specified supplementary character (Unicode
 36.2197 +     * code point) in the UTF-16 encoding.  If the specified character
 36.2198 +     * is not a
 36.2199 +     * <a href="Character.html#supplementary">supplementary character</a>,
 36.2200 +     * an unspecified {@code char} is returned.
 36.2201 +     *
 36.2202 +     * <p>If
 36.2203 +     * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
 36.2204 +     * is {@code true}, then
 36.2205 +     * {@link #isLowSurrogate isLowSurrogate}{@code (lowSurrogate(x))} and
 36.2206 +     * {@link #toCodePoint toCodePoint}{@code (}{@link #highSurrogate highSurrogate}{@code (x), lowSurrogate(x)) == x}
 36.2207 +     * are also always {@code true}.
 36.2208 +     *
 36.2209 +     * @param   codePoint a supplementary character (Unicode code point)
 36.2210 +     * @return  the trailing surrogate code unit used to represent the
 36.2211 +     *          character in the UTF-16 encoding
 36.2212 +     * @since   1.7
 36.2213 +     */
 36.2214 +    public static char lowSurrogate(int codePoint) {
 36.2215 +        return (char) ((codePoint & 0x3ff) + MIN_LOW_SURROGATE);
 36.2216 +    }
 36.2217 +
 36.2218 +    /**
 36.2219       * Converts the specified character (Unicode code point) to its
 36.2220       * UTF-16 representation. If the specified code point is a BMP
 36.2221       * (Basic Multilingual Plane or Plane 0) value, the same value is
 36.2222 @@ -4311,15 +4486,15 @@
 36.2223       * @since  1.5
 36.2224       */
 36.2225      public static int toChars(int codePoint, char[] dst, int dstIndex) {
 36.2226 -        if (codePoint < 0 || codePoint > MAX_CODE_POINT) {
 36.2227 +        if (isBmpCodePoint(codePoint)) {
 36.2228 +            dst[dstIndex] = (char) codePoint;
 36.2229 +            return 1;
 36.2230 +        } else if (isValidCodePoint(codePoint)) {
 36.2231 +            toSurrogates(codePoint, dst, dstIndex);
 36.2232 +            return 2;
 36.2233 +        } else {
 36.2234              throw new IllegalArgumentException();
 36.2235          }
 36.2236 -        if (codePoint < MIN_SUPPLEMENTARY_CODE_POINT) {
 36.2237 -            dst[dstIndex] = (char) codePoint;
 36.2238 -            return 1;
 36.2239 -        }
 36.2240 -        toSurrogates(codePoint, dst, dstIndex);
 36.2241 -        return 2;
 36.2242      }
 36.2243  
 36.2244      /**
 36.2245 @@ -4339,22 +4514,21 @@
 36.2246       * @since  1.5
 36.2247       */
 36.2248      public static char[] toChars(int codePoint) {
 36.2249 -        if (codePoint < 0 || codePoint > MAX_CODE_POINT) {
 36.2250 +        if (isBmpCodePoint(codePoint)) {
 36.2251 +            return new char[] { (char) codePoint };
 36.2252 +        } else if (isValidCodePoint(codePoint)) {
 36.2253 +            char[] result = new char[2];
 36.2254 +            toSurrogates(codePoint, result, 0);
 36.2255 +            return result;
 36.2256 +        } else {
 36.2257              throw new IllegalArgumentException();
 36.2258          }
 36.2259 -        if (codePoint < MIN_SUPPLEMENTARY_CODE_POINT) {
 36.2260 -                return new char[] { (char) codePoint };
 36.2261 -        }
 36.2262 -        char[] result = new char[2];
 36.2263 -        toSurrogates(codePoint, result, 0);
 36.2264 -        return result;
 36.2265      }
 36.2266  
 36.2267      static void toSurrogates(int codePoint, char[] dst, int index) {
 36.2268          // We write elements "backwards" to guarantee all-or-nothing
 36.2269 -        dst[index+1] = (char)((codePoint & 0x3ff) + MIN_LOW_SURROGATE);
 36.2270 -        dst[index] = (char)((codePoint >>> 10)
 36.2271 -            + (MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >>> 10)));
 36.2272 +        dst[index+1] = lowSurrogate(codePoint);
 36.2273 +        dst[index] = highSurrogate(codePoint);
 36.2274      }
 36.2275  
 36.2276      /**
 36.2277 @@ -4385,13 +4559,12 @@
 36.2278          if (beginIndex < 0 || endIndex > length || beginIndex > endIndex) {
 36.2279              throw new IndexOutOfBoundsException();
 36.2280          }
 36.2281 -        int n = 0;
 36.2282 +        int n = endIndex - beginIndex;
 36.2283          for (int i = beginIndex; i < endIndex; ) {
 36.2284 -            n++;
 36.2285 -            if (isHighSurrogate(seq.charAt(i++))) {
 36.2286 -                if (i < endIndex && isLowSurrogate(seq.charAt(i))) {
 36.2287 -                    i++;
 36.2288 -                }
 36.2289 +            if (isHighSurrogate(seq.charAt(i++)) && i < endIndex &&
 36.2290 +                isLowSurrogate(seq.charAt(i))) {
 36.2291 +                n--;
 36.2292 +                i++;
 36.2293              }
 36.2294          }
 36.2295          return n;
 36.2296 @@ -4425,13 +4598,12 @@
 36.2297  
 36.2298      static int codePointCountImpl(char[] a, int offset, int count) {
 36.2299          int endIndex = offset + count;
 36.2300 -        int n = 0;
 36.2301 +        int n = count;
 36.2302          for (int i = offset; i < endIndex; ) {
 36.2303 -            n++;
 36.2304 -            if (isHighSurrogate(a[i++])) {
 36.2305 -                if (i < endIndex && isLowSurrogate(a[i])) {
 36.2306 -                    i++;
 36.2307 -                }
 36.2308 +            if (isHighSurrogate(a[i++]) && i < endIndex &&
 36.2309 +                isLowSurrogate(a[i])) {
 36.2310 +                n--;
 36.2311 +                i++;
 36.2312              }
 36.2313          }
 36.2314          return n;
 36.2315 @@ -4470,10 +4642,9 @@
 36.2316          if (codePointOffset >= 0) {
 36.2317              int i;
 36.2318              for (i = 0; x < length && i < codePointOffset; i++) {
 36.2319 -                if (isHighSurrogate(seq.charAt(x++))) {
 36.2320 -                    if (x < length && isLowSurrogate(seq.charAt(x))) {
 36.2321 -                        x++;
 36.2322 -                    }
 36.2323 +                if (isHighSurrogate(seq.charAt(x++)) && x < length &&
 36.2324 +                    isLowSurrogate(seq.charAt(x))) {
 36.2325 +                    x++;
 36.2326                  }
 36.2327              }
 36.2328              if (i < codePointOffset) {
 36.2329 @@ -4482,10 +4653,9 @@
 36.2330          } else {
 36.2331              int i;
 36.2332              for (i = codePointOffset; x > 0 && i < 0; i++) {
 36.2333 -                if (isLowSurrogate(seq.charAt(--x))) {
 36.2334 -                    if (x > 0 && isHighSurrogate(seq.charAt(x-1))) {
 36.2335 -                        x--;
 36.2336 -                    }
 36.2337 +                if (isLowSurrogate(seq.charAt(--x)) && x > 0 &&
 36.2338 +                    isHighSurrogate(seq.charAt(x-1))) {
 36.2339 +                    x--;
 36.2340                  }
 36.2341              }
 36.2342              if (i < 0) {
 36.2343 @@ -4544,10 +4714,9 @@
 36.2344              int limit = start + count;
 36.2345              int i;
 36.2346              for (i = 0; x < limit && i < codePointOffset; i++) {
 36.2347 -                if (isHighSurrogate(a[x++])) {
 36.2348 -                    if (x < limit && isLowSurrogate(a[x])) {
 36.2349 -                        x++;
 36.2350 -                    }
 36.2351 +                if (isHighSurrogate(a[x++]) && x < limit &&
 36.2352 +                    isLowSurrogate(a[x])) {
 36.2353 +                    x++;
 36.2354                  }
 36.2355              }
 36.2356              if (i < codePointOffset) {
 36.2357 @@ -4556,10 +4725,9 @@
 36.2358          } else {
 36.2359              int i;
 36.2360              for (i = codePointOffset; x > start && i < 0; i++) {
 36.2361 -                if (isLowSurrogate(a[--x])) {
 36.2362 -                    if (x > start && isHighSurrogate(a[x-1])) {
 36.2363 -                        x--;
 36.2364 -                    }
 36.2365 +                if (isLowSurrogate(a[--x]) && x > start &&
 36.2366 +                    isHighSurrogate(a[x-1])) {
 36.2367 +                    x--;
 36.2368                  }
 36.2369              }
 36.2370              if (i < 0) {
 36.2371 @@ -4569,7 +4737,7 @@
 36.2372          return x;
 36.2373      }
 36.2374  
 36.2375 -   /**
 36.2376 +    /**
 36.2377       * Determines if the specified character is a lowercase character.
 36.2378       * <p>
 36.2379       * A character is lowercase if its general category type, provided
 36.2380 @@ -4594,10 +4762,10 @@
 36.2381       * @param   ch   the character to be tested.
 36.2382       * @return  <code>true</code> if the character is lowercase;
 36.2383       *          <code>false</code> otherwise.
 36.2384 -     * @see     java.lang.Character#isLowerCase(char)
 36.2385 -     * @see     java.lang.Character#isTitleCase(char)
 36.2386 -     * @see     java.lang.Character#toLowerCase(char)
 36.2387 -     * @see     java.lang.Character#getType(char)
 36.2388 +     * @see     Character#isLowerCase(char)
 36.2389 +     * @see     Character#isTitleCase(char)
 36.2390 +     * @see     Character#toLowerCase(char)
 36.2391 +     * @see     Character#getType(char)
 36.2392       */
 36.2393      public static boolean isLowerCase(char ch) {
 36.2394          return isLowerCase((int)ch);
 36.2395 @@ -4624,17 +4792,17 @@
 36.2396       * @param   codePoint the character (Unicode code point) to be tested.
 36.2397       * @return  <code>true</code> if the character is lowercase;
 36.2398       *          <code>false</code> otherwise.
 36.2399 -     * @see     java.lang.Character#isLowerCase(int)
 36.2400 -     * @see     java.lang.Character#isTitleCase(int)
 36.2401 -     * @see     java.lang.Character#toLowerCase(int)
 36.2402 -     * @see     java.lang.Character#getType(int)
 36.2403 +     * @see     Character#isLowerCase(int)
 36.2404 +     * @see     Character#isTitleCase(int)
 36.2405 +     * @see     Character#toLowerCase(int)
 36.2406 +     * @see     Character#getType(int)
 36.2407       * @since   1.5
 36.2408       */
 36.2409      public static boolean isLowerCase(int codePoint) {
 36.2410          return getType(codePoint) == Character.LOWERCASE_LETTER;
 36.2411      }
 36.2412  
 36.2413 -   /**
 36.2414 +    /**
 36.2415       * Determines if the specified character is an uppercase character.
 36.2416       * <p>
 36.2417       * A character is uppercase if its general category type, provided by
 36.2418 @@ -4658,10 +4826,10 @@
 36.2419       * @param   ch   the character to be tested.
 36.2420       * @return  <code>true</code> if the character is uppercase;
 36.2421       *          <code>false</code> otherwise.
 36.2422 -     * @see     java.lang.Character#isLowerCase(char)
 36.2423 -     * @see     java.lang.Character#isTitleCase(char)
 36.2424 -     * @see     java.lang.Character#toUpperCase(char)
 36.2425 -     * @see     java.lang.Character#getType(char)
 36.2426 +     * @see     Character#isLowerCase(char)
 36.2427 +     * @see     Character#isTitleCase(char)
 36.2428 +     * @see     Character#toUpperCase(char)
 36.2429 +     * @see     Character#getType(char)
 36.2430       * @since   1.0
 36.2431       */
 36.2432      public static boolean isUpperCase(char ch) {
 36.2433 @@ -4687,10 +4855,10 @@
 36.2434       * @param   codePoint the character (Unicode code point) to be tested.
 36.2435       * @return  <code>true</code> if the character is uppercase;
 36.2436       *          <code>false</code> otherwise.
 36.2437 -     * @see     java.lang.Character#isLowerCase(int)
 36.2438 -     * @see     java.lang.Character#isTitleCase(int)
 36.2439 -     * @see     java.lang.Character#toUpperCase(int)
 36.2440 -     * @see     java.lang.Character#getType(int)
 36.2441 +     * @see     Character#isLowerCase(int)
 36.2442 +     * @see     Character#isTitleCase(int)
 36.2443 +     * @see     Character#toUpperCase(int)
 36.2444 +     * @see     Character#getType(int)
 36.2445       * @since   1.5
 36.2446       */
 36.2447      public static boolean isUpperCase(int codePoint) {
 36.2448 @@ -4728,10 +4896,10 @@
 36.2449       * @param   ch   the character to be tested.
 36.2450       * @return  <code>true</code> if the character is titlecase;
 36.2451       *          <code>false</code> otherwise.
 36.2452 -     * @see     java.lang.Character#isLowerCase(char)
 36.2453 -     * @see     java.lang.Character#isUpperCase(char)
 36.2454 -     * @see     java.lang.Character#toTitleCase(char)
 36.2455 -     * @see     java.lang.Character#getType(char)
 36.2456 +     * @see     Character#isLowerCase(char)
 36.2457 +     * @see     Character#isUpperCase(char)
 36.2458 +     * @see     Character#toTitleCase(char)
 36.2459 +     * @see     Character#getType(char)
 36.2460       * @since   1.0.2
 36.2461       */
 36.2462      public static boolean isTitleCase(char ch) {
 36.2463 @@ -4764,10 +4932,10 @@
 36.2464       * @param   codePoint the character (Unicode code point) to be tested.
 36.2465       * @return  <code>true</code> if the character is titlecase;
 36.2466       *          <code>false</code> otherwise.
 36.2467 -     * @see     java.lang.Character#isLowerCase(int)
 36.2468 -     * @see     java.lang.Character#isUpperCase(int)
 36.2469 -     * @see     java.lang.Character#toTitleCase(int)
 36.2470 -     * @see     java.lang.Character#getType(int)
 36.2471 +     * @see     Character#isLowerCase(int)
 36.2472 +     * @see     Character#isUpperCase(int)
 36.2473 +     * @see     Character#toTitleCase(int)
 36.2474 +     * @see     Character#getType(int)
 36.2475       * @since   1.5
 36.2476       */
 36.2477      public static boolean isTitleCase(int codePoint) {
 36.2478 @@ -4805,9 +4973,9 @@
 36.2479       * @param   ch   the character to be tested.
 36.2480       * @return  <code>true</code> if the character is a digit;
 36.2481       *          <code>false</code> otherwise.
 36.2482 -     * @see     java.lang.Character#digit(char, int)
 36.2483 -     * @see     java.lang.Character#forDigit(int, int)
 36.2484 -     * @see     java.lang.Character#getType(char)
 36.2485 +     * @see     Character#digit(char, int)
 36.2486 +     * @see     Character#forDigit(int, int)
 36.2487 +     * @see     Character#getType(char)
 36.2488       */
 36.2489      public static boolean isDigit(char ch) {
 36.2490          return isDigit((int)ch);
 36.2491 @@ -4839,8 +5007,8 @@
 36.2492       * @param   codePoint the character (Unicode code point) to be tested.
 36.2493       * @return  <code>true</code> if the character is a digit;
 36.2494       *          <code>false</code> otherwise.
 36.2495 -     * @see     java.lang.Character#forDigit(int, int)
 36.2496 -     * @see     java.lang.Character#getType(int)
 36.2497 +     * @see     Character#forDigit(int, int)
 36.2498 +     * @see     Character#getType(int)
 36.2499       * @since   1.5
 36.2500       */
 36.2501      public static boolean isDigit(int codePoint) {
 36.2502 @@ -4864,12 +5032,12 @@
 36.2503       * @param   ch   the character to be tested
 36.2504       * @return  <code>true</code> if the character has a defined meaning
 36.2505       *          in Unicode; <code>false</code> otherwise.
 36.2506 -     * @see     java.lang.Character#isDigit(char)
 36.2507 -     * @see     java.lang.Character#isLetter(char)
 36.2508 -     * @see     java.lang.Character#isLetterOrDigit(char)
 36.2509 -     * @see     java.lang.Character#isLowerCase(char)
 36.2510 -     * @see     java.lang.Character#isTitleCase(char)
 36.2511 -     * @see     java.lang.Character#isUpperCase(char)
 36.2512 +     * @see     Character#isDigit(char)
 36.2513 +     * @see     Character#isLetter(char)
 36.2514 +     * @see     Character#isLetterOrDigit(char)
 36.2515 +     * @see     Character#isLowerCase(char)
 36.2516 +     * @see     Character#isTitleCase(char)
 36.2517 +     * @see     Character#isUpperCase(char)
 36.2518       * @since   1.0.2
 36.2519       */
 36.2520      public static boolean isDefined(char ch) {
 36.2521 @@ -4888,12 +5056,12 @@
 36.2522       * @param   codePoint the character (Unicode code point) to be tested.
 36.2523       * @return  <code>true</code> if the character has a defined meaning
 36.2524       *          in Unicode; <code>false</code> otherwise.
 36.2525 -     * @see     java.lang.Character#isDigit(int)
 36.2526 -     * @see     java.lang.Character#isLetter(int)
 36.2527 -     * @see     java.lang.Character#isLetterOrDigit(int)
 36.2528 -     * @see     java.lang.Character#isLowerCase(int)
 36.2529 -     * @see     java.lang.Character#isTitleCase(int)
 36.2530 -     * @see     java.lang.Character#isUpperCase(int)
 36.2531 +     * @see     Character#isDigit(int)
 36.2532 +     * @see     Character#isLetter(int)
 36.2533 +     * @see     Character#isLetterOrDigit(int)
 36.2534 +     * @see     Character#isLowerCase(int)
 36.2535 +     * @see     Character#isTitleCase(int)
 36.2536 +     * @see     Character#isUpperCase(int)
 36.2537       * @since   1.5
 36.2538       */
 36.2539      public static boolean isDefined(int codePoint) {
 36.2540 @@ -4925,15 +5093,15 @@
 36.2541       * @param   ch   the character to be tested.
 36.2542       * @return  <code>true</code> if the character is a letter;
 36.2543       *          <code>false</code> otherwise.
 36.2544 -     * @see     java.lang.Character#isDigit(char)
 36.2545 -     * @see     java.lang.Character#isJavaIdentifierStart(char)
 36.2546 -     * @see     java.lang.Character#isJavaLetter(char)
 36.2547 -     * @see     java.lang.Character#isJavaLetterOrDigit(char)
 36.2548 -     * @see     java.lang.Character#isLetterOrDigit(char)
 36.2549 -     * @see     java.lang.Character#isLowerCase(char)
 36.2550 -     * @see     java.lang.Character#isTitleCase(char)
 36.2551 -     * @see     java.lang.Character#isUnicodeIdentifierStart(char)
 36.2552 -     * @see     java.lang.Character#isUpperCase(char)
 36.2553 +     * @see     Character#isDigit(char)
 36.2554 +     * @see     Character#isJavaIdentifierStart(char)
 36.2555 +     * @see     Character#isJavaLetter(char)
 36.2556 +     * @see     Character#isJavaLetterOrDigit(char)
 36.2557 +     * @see     Character#isLetterOrDigit(char)
 36.2558 +     * @see     Character#isLowerCase(char)
 36.2559 +     * @see     Character#isTitleCase(char)
 36.2560 +     * @see     Character#isUnicodeIdentifierStart(char)
 36.2561 +     * @see     Character#isUpperCase(char)
 36.2562       */
 36.2563      public static boolean isLetter(char ch) {
 36.2564          return isLetter((int)ch);
 36.2565 @@ -4959,13 +5127,13 @@
 36.2566       * @param   codePoint the character (Unicode code point) to be tested.
 36.2567       * @return  <code>true</code> if the character is a letter;
 36.2568       *          <code>false</code> otherwise.
 36.2569 -     * @see     java.lang.Character#isDigit(int)
 36.2570 -     * @see     java.lang.Character#isJavaIdentifierStart(int)
 36.2571 -     * @see     java.lang.Character#isLetterOrDigit(int)
 36.2572 -     * @see     java.lang.Character#isLowerCase(int)
 36.2573 -     * @see     java.lang.Character#isTitleCase(int)
 36.2574 -     * @see     java.lang.Character#isUnicodeIdentifierStart(int)
 36.2575 -     * @see     java.lang.Character#isUpperCase(int)
 36.2576 +     * @see     Character#isDigit(int)
 36.2577 +     * @see     Character#isJavaIdentifierStart(int)
 36.2578 +     * @see     Character#isLetterOrDigit(int)
 36.2579 +     * @see     Character#isLowerCase(int)
 36.2580 +     * @see     Character#isTitleCase(int)
 36.2581 +     * @see     Character#isUnicodeIdentifierStart(int)
 36.2582 +     * @see     Character#isUpperCase(int)
 36.2583       * @since   1.5
 36.2584       */
 36.2585      public static boolean isLetter(int codePoint) {
 36.2586 @@ -4993,12 +5161,12 @@
 36.2587       * @param   ch   the character to be tested.
 36.2588       * @return  <code>true</code> if the character is a letter or digit;
 36.2589       *          <code>false</code> otherwise.
 36.2590 -     * @see     java.lang.Character#isDigit(char)
 36.2591 -     * @see     java.lang.Character#isJavaIdentifierPart(char)
 36.2592 -     * @see     java.lang.Character#isJavaLetter(char)
 36.2593 -     * @see     java.lang.Character#isJavaLetterOrDigit(char)
 36.2594 -     * @see     java.lang.Character#isLetter(char)
 36.2595 -     * @see     java.lang.Character#isUnicodeIdentifierPart(char)
 36.2596 +     * @see     Character#isDigit(char)
 36.2597 +     * @see     Character#isJavaIdentifierPart(char)
 36.2598 +     * @see     Character#isJavaLetter(char)
 36.2599 +     * @see     Character#isJavaLetterOrDigit(char)
 36.2600 +     * @see     Character#isLetter(char)
 36.2601 +     * @see     Character#isUnicodeIdentifierPart(char)
 36.2602       * @since   1.0.2
 36.2603       */
 36.2604      public static boolean isLetterOrDigit(char ch) {
 36.2605 @@ -5016,10 +5184,10 @@
 36.2606       * @param   codePoint the character (Unicode code point) to be tested.
 36.2607       * @return  <code>true</code> if the character is a letter or digit;
 36.2608       *          <code>false</code> otherwise.
 36.2609 -     * @see     java.lang.Character#isDigit(int)
 36.2610 -     * @see     java.lang.Character#isJavaIdentifierPart(int)
 36.2611 -     * @see     java.lang.Character#isLetter(int)
 36.2612 -     * @see     java.lang.Character#isUnicodeIdentifierPart(int)
 36.2613 +     * @see     Character#isDigit(int)
 36.2614 +     * @see     Character#isJavaIdentifierPart(int)
 36.2615 +     * @see     Character#isLetter(int)
 36.2616 +     * @see     Character#isUnicodeIdentifierPart(int)
 36.2617       * @since   1.5
 36.2618       */
 36.2619      public static boolean isLetterOrDigit(int codePoint) {
 36.2620 @@ -5048,12 +5216,12 @@
 36.2621       * @param   ch the character to be tested.
 36.2622       * @return  <code>true</code> if the character may start a Java
 36.2623       *          identifier; <code>false</code> otherwise.
 36.2624 -     * @see     java.lang.Character#isJavaLetterOrDigit(char)
 36.2625 -     * @see     java.lang.Character#isJavaIdentifierStart(char)
 36.2626 -     * @see     java.lang.Character#isJavaIdentifierPart(char)
 36.2627 -     * @see     java.lang.Character#isLetter(char)
 36.2628 -     * @see     java.lang.Character#isLetterOrDigit(char)
 36.2629 -     * @see     java.lang.Character#isUnicodeIdentifierStart(char)
 36.2630 +     * @see     Character#isJavaLetterOrDigit(char)
 36.2631 +     * @see     Character#isJavaIdentifierStart(char)
 36.2632 +     * @see     Character#isJavaIdentifierPart(char)
 36.2633 +     * @see     Character#isLetter(char)
 36.2634 +     * @see     Character#isLetterOrDigit(char)
 36.2635 +     * @see     Character#isUnicodeIdentifierStart(char)
 36.2636       * @since   1.02
 36.2637       * @deprecated Replaced by isJavaIdentifierStart(char).
 36.2638       */
 36.2639 @@ -5083,13 +5251,13 @@
 36.2640       * @param   ch the character to be tested.
 36.2641       * @return  <code>true</code> if the character may be part of a
 36.2642       *          Java identifier; <code>false</code> otherwise.
 36.2643 -     * @see     java.lang.Character#isJavaLetter(char)
 36.2644 -     * @see     java.lang.Character#isJavaIdentifierStart(char)
 36.2645 -     * @see     java.lang.Character#isJavaIdentifierPart(char)
 36.2646 -     * @see     java.lang.Character#isLetter(char)
 36.2647 -     * @see     java.lang.Character#isLetterOrDigit(char)
 36.2648 -     * @see     java.lang.Character#isUnicodeIdentifierPart(char)
 36.2649 -     * @see     java.lang.Character#isIdentifierIgnorable(char)
 36.2650 +     * @see     Character#isJavaLetter(char)
 36.2651 +     * @see     Character#isJavaIdentifierStart(char)
 36.2652 +     * @see     Character#isJavaIdentifierPart(char)
 36.2653 +     * @see     Character#isLetter(char)
 36.2654 +     * @see     Character#isLetterOrDigit(char)
 36.2655 +     * @see     Character#isUnicodeIdentifierPart(char)
 36.2656 +     * @see     Character#isIdentifierIgnorable(char)
 36.2657       * @since   1.02
 36.2658       * @deprecated Replaced by isJavaIdentifierPart(char).
 36.2659       */
 36.2660 @@ -5119,9 +5287,9 @@
 36.2661       * @param   ch the character to be tested.
 36.2662       * @return  <code>true</code> if the character may start a Java identifier;
 36.2663       *          <code>false</code> otherwise.
 36.2664 -     * @see     java.lang.Character#isJavaIdentifierPart(char)
 36.2665 -     * @see     java.lang.Character#isLetter(char)
 36.2666 -     * @see     java.lang.Character#isUnicodeIdentifierStart(char)
 36.2667 +     * @see     Character#isJavaIdentifierPart(char)
 36.2668 +     * @see     Character#isLetter(char)
 36.2669 +     * @see     Character#isUnicodeIdentifierStart(char)
 36.2670       * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
 36.2671       * @since   1.1
 36.2672       */
 36.2673 @@ -5148,9 +5316,9 @@
 36.2674       * @param   codePoint the character (Unicode code point) to be tested.
 36.2675       * @return  <code>true</code> if the character may start a Java identifier;
 36.2676       *          <code>false</code> otherwise.
 36.2677 -     * @see     java.lang.Character#isJavaIdentifierPart(int)
 36.2678 -     * @see     java.lang.Character#isLetter(int)
 36.2679 -     * @see     java.lang.Character#isUnicodeIdentifierStart(int)
 36.2680 +     * @see     Character#isJavaIdentifierPart(int)
 36.2681 +     * @see     Character#isLetter(int)
 36.2682 +     * @see     Character#isUnicodeIdentifierStart(int)
 36.2683       * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
 36.2684       * @since   1.5
 36.2685       */
 36.2686 @@ -5184,10 +5352,10 @@
 36.2687       * @param   ch      the character to be tested.
 36.2688       * @return <code>true</code> if the character may be part of a
 36.2689       *          Java identifier; <code>false</code> otherwise.
 36.2690 -     * @see     java.lang.Character#isIdentifierIgnorable(char)
 36.2691 -     * @see     java.lang.Character#isJavaIdentifierStart(char)
 36.2692 -     * @see     java.lang.Character#isLetterOrDigit(char)
 36.2693 -     * @see     java.lang.Character#isUnicodeIdentifierPart(char)
 36.2694 +     * @see     Character#isIdentifierIgnorable(char)
 36.2695 +     * @see     Character#isJavaIdentifierStart(char)
 36.2696 +     * @see     Character#isLetterOrDigit(char)
 36.2697 +     * @see     Character#isUnicodeIdentifierPart(char)
 36.2698       * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
 36.2699       * @since   1.1
 36.2700       */
 36.2701 @@ -5217,10 +5385,10 @@
 36.2702       * @param   codePoint the character (Unicode code point) to be tested.
 36.2703       * @return <code>true</code> if the character may be part of a
 36.2704       *          Java identifier; <code>false</code> otherwise.
 36.2705 -     * @see     java.lang.Character#isIdentifierIgnorable(int)
 36.2706 -     * @see     java.lang.Character#isJavaIdentifierStart(int)
 36.2707 -     * @see     java.lang.Character#isLetterOrDigit(int)
 36.2708 -     * @see     java.lang.Character#isUnicodeIdentifierPart(int)
 36.2709 +     * @see     Character#isIdentifierIgnorable(int)
 36.2710 +     * @see     Character#isJavaIdentifierStart(int)
 36.2711 +     * @see     Character#isLetterOrDigit(int)
 36.2712 +     * @see     Character#isUnicodeIdentifierPart(int)
 36.2713       * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
 36.2714       * @since   1.5
 36.2715       */
 36.2716 @@ -5248,9 +5416,9 @@
 36.2717       * @param   ch      the character to be tested.
 36.2718       * @return  <code>true</code> if the character may start a Unicode
 36.2719       *          identifier; <code>false</code> otherwise.
 36.2720 -     * @see     java.lang.Character#isJavaIdentifierStart(char)
 36.2721 -     * @see     java.lang.Character#isLetter(char)
 36.2722 -     * @see     java.lang.Character#isUnicodeIdentifierPart(char)
 36.2723 +     * @see     Character#isJavaIdentifierStart(char)
 36.2724 +     * @see     Character#isLetter(char)
 36.2725 +     * @see     Character#isUnicodeIdentifierPart(char)
 36.2726       * @since   1.1
 36.2727       */
 36.2728      public static boolean isUnicodeIdentifierStart(char ch) {
 36.2729 @@ -5272,9 +5440,9 @@
 36.2730       * @param   codePoint the character (Unicode code point) to be tested.
 36.2731       * @return  <code>true</code> if the character may start a Unicode
 36.2732       *          identifier; <code>false</code> otherwise.
 36.2733 -     * @see     java.lang.Character#isJavaIdentifierStart(int)
 36.2734 -     * @see     java.lang.Character#isLetter(int)
 36.2735 -     * @see     java.lang.Character#isUnicodeIdentifierPart(int)
 36.2736 +     * @see     Character#isJavaIdentifierStart(int)
 36.2737 +     * @see     Character#isLetter(int)
 36.2738 +     * @see     Character#isUnicodeIdentifierPart(int)
 36.2739       * @since   1.5
 36.2740       */
 36.2741      public static boolean isUnicodeIdentifierStart(int codePoint) {
 36.2742 @@ -5306,10 +5474,10 @@
 36.2743       * @param   ch      the character to be tested.
 36.2744       * @return  <code>true</code> if the character may be part of a
 36.2745       *          Unicode identifier; <code>false</code> otherwise.
 36.2746 -     * @see     java.lang.Character#isIdentifierIgnorable(char)
 36.2747 -     * @see     java.lang.Character#isJavaIdentifierPart(char)
 36.2748 -     * @see     java.lang.Character#isLetterOrDigit(char)
 36.2749 -     * @see     java.lang.Character#isUnicodeIdentifierStart(char)
 36.2750 +     * @see     Character#isIdentifierIgnorable(char)
 36.2751 +     * @see     Character#isJavaIdentifierPart(char)
 36.2752 +     * @see     Character#isLetterOrDigit(char)
 36.2753 +     * @see     Character#isUnicodeIdentifierStart(char)
 36.2754       * @since   1.1
 36.2755       */
 36.2756      public static boolean isUnicodeIdentifierPart(char ch) {
 36.2757 @@ -5335,10 +5503,10 @@
 36.2758       * @param   codePoint the character (Unicode code point) to be tested.
 36.2759       * @return  <code>true</code> if the character may be part of a
 36.2760       *          Unicode identifier; <code>false</code> otherwise.
 36.2761 -     * @see     java.lang.Character#isIdentifierIgnorable(int)
 36.2762 -     * @see     java.lang.Character#isJavaIdentifierPart(int)
 36.2763 -     * @see     java.lang.Character#isLetterOrDigit(int)
 36.2764 -     * @see     java.lang.Character#isUnicodeIdentifierStart(int)
 36.2765 +     * @see     Character#isIdentifierIgnorable(int)
 36.2766 +     * @see     Character#isJavaIdentifierPart(int)
 36.2767 +     * @see     Character#isLetterOrDigit(int)
 36.2768 +     * @see     Character#isUnicodeIdentifierStart(int)
 36.2769       * @since   1.5
 36.2770       */
 36.2771      public static boolean isUnicodeIdentifierPart(int codePoint) {
 36.2772 @@ -5372,8 +5540,8 @@
 36.2773       * @return  <code>true</code> if the character is an ignorable control
 36.2774       *          character that may be part of a Java or Unicode identifier;
 36.2775       *           <code>false</code> otherwise.
 36.2776 -     * @see     java.lang.Character#isJavaIdentifierPart(char)
 36.2777 -     * @see     java.lang.Character#isUnicodeIdentifierPart(char)
 36.2778 +     * @see     Character#isJavaIdentifierPart(char)
 36.2779 +     * @see     Character#isUnicodeIdentifierPart(char)
 36.2780       * @since   1.1
 36.2781       */
 36.2782      public static boolean isIdentifierIgnorable(char ch) {
 36.2783 @@ -5402,8 +5570,8 @@
 36.2784       * @return  <code>true</code> if the character is an ignorable control
 36.2785       *          character that may be part of a Java or Unicode identifier;
 36.2786       *          <code>false</code> otherwise.
 36.2787 -     * @see     java.lang.Character#isJavaIdentifierPart(int)
 36.2788 -     * @see     java.lang.Character#isUnicodeIdentifierPart(int)
 36.2789 +     * @see     Character#isJavaIdentifierPart(int)
 36.2790 +     * @see     Character#isUnicodeIdentifierPart(int)
 36.2791       * @since   1.5
 36.2792       */
 36.2793      public static boolean isIdentifierIgnorable(int codePoint) {
 36.2794 @@ -5419,7 +5587,7 @@
 36.2795       * does not always return <code>true</code> for some ranges of
 36.2796       * characters, particularly those that are symbols or ideographs.
 36.2797       *
 36.2798 -     * <p>In general, {@link java.lang.String#toLowerCase()} should be used to map
 36.2799 +     * <p>In general, {@link String#toLowerCase()} should be used to map
 36.2800       * characters to lowercase. <code>String</code> case mapping methods
 36.2801       * have several benefits over <code>Character</code> case mapping methods.
 36.2802       * <code>String</code> case mapping methods can perform locale-sensitive
 36.2803 @@ -5434,8 +5602,8 @@
 36.2804       * @param   ch   the character to be converted.
 36.2805       * @return  the lowercase equivalent of the character, if any;
 36.2806       *          otherwise, the character itself.
 36.2807 -     * @see     java.lang.Character#isLowerCase(char)
 36.2808 -     * @see     java.lang.String#toLowerCase()
 36.2809 +     * @see     Character#isLowerCase(char)
 36.2810 +     * @see     String#toLowerCase()
 36.2811       */
 36.2812      public static char toLowerCase(char ch) {
 36.2813          return (char)toLowerCase((int)ch);
 36.2814 @@ -5451,7 +5619,7 @@
 36.2815       * does not always return <code>true</code> for some ranges of
 36.2816       * characters, particularly those that are symbols or ideographs.
 36.2817       *
 36.2818 -     * <p>In general, {@link java.lang.String#toLowerCase()} should be used to map
 36.2819 +     * <p>In general, {@link String#toLowerCase()} should be used to map
 36.2820       * characters to lowercase. <code>String</code> case mapping methods
 36.2821       * have several benefits over <code>Character</code> case mapping methods.
 36.2822       * <code>String</code> case mapping methods can perform locale-sensitive
 36.2823 @@ -5461,8 +5629,8 @@
 36.2824       * @param   codePoint   the character (Unicode code point) to be converted.
 36.2825       * @return  the lowercase equivalent of the character (Unicode code
 36.2826       *          point), if any; otherwise, the character itself.
 36.2827 -     * @see     java.lang.Character#isLowerCase(int)
 36.2828 -     * @see     java.lang.String#toLowerCase()
 36.2829 +     * @see     Character#isLowerCase(int)
 36.2830 +     * @see     String#toLowerCase()
 36.2831       *
 36.2832       * @since   1.5
 36.2833       */
 36.2834 @@ -5479,7 +5647,7 @@
 36.2835       * does not always return <code>true</code> for some ranges of
 36.2836       * characters, particularly those that are symbols or ideographs.
 36.2837       *
 36.2838 -     * <p>In general, {@link java.lang.String#toUpperCase()} should be used to map
 36.2839 +     * <p>In general, {@link String#toUpperCase()} should be used to map
 36.2840       * characters to uppercase. <code>String</code> case mapping methods
 36.2841       * have several benefits over <code>Character</code> case mapping methods.
 36.2842       * <code>String</code> case mapping methods can perform locale-sensitive
 36.2843 @@ -5494,8 +5662,8 @@
 36.2844       * @param   ch   the character to be converted.
 36.2845       * @return  the uppercase equivalent of the character, if any;
 36.2846       *          otherwise, the character itself.
 36.2847 -     * @see     java.lang.Character#isUpperCase(char)
 36.2848 -     * @see     java.lang.String#toUpperCase()
 36.2849 +     * @see     Character#isUpperCase(char)
 36.2850 +     * @see     String#toUpperCase()
 36.2851       */
 36.2852      public static char toUpperCase(char ch) {
 36.2853          return (char)toUpperCase((int)ch);
 36.2854 @@ -5511,7 +5679,7 @@
 36.2855       * does not always return <code>true</code> for some ranges of
 36.2856       * characters, particularly those that are symbols or ideographs.
 36.2857       *
 36.2858 -     * <p>In general, {@link java.lang.String#toUpperCase()} should be used to map
 36.2859 +     * <p>In general, {@link String#toUpperCase()} should be used to map
 36.2860       * characters to uppercase. <code>String</code> case mapping methods
 36.2861       * have several benefits over <code>Character</code> case mapping methods.
 36.2862       * <code>String</code> case mapping methods can perform locale-sensitive
 36.2863 @@ -5521,8 +5689,8 @@
 36.2864       * @param   codePoint   the character (Unicode code point) to be converted.
 36.2865       * @return  the uppercase equivalent of the character, if any;
 36.2866       *          otherwise, the character itself.
 36.2867 -     * @see     java.lang.Character#isUpperCase(int)
 36.2868 -     * @see     java.lang.String#toUpperCase()
 36.2869 +     * @see     Character#isUpperCase(int)
 36.2870 +     * @see     String#toUpperCase()
 36.2871       *
 36.2872       * @since   1.5
 36.2873       */
 36.2874 @@ -5553,9 +5721,9 @@
 36.2875       * @param   ch   the character to be converted.
 36.2876       * @return  the titlecase equivalent of the character, if any;
 36.2877       *          otherwise, the character itself.
 36.2878 -     * @see     java.lang.Character#isTitleCase(char)
 36.2879 -     * @see     java.lang.Character#toLowerCase(char)
 36.2880 -     * @see     java.lang.Character#toUpperCase(char)
 36.2881 +     * @see     Character#isTitleCase(char)
 36.2882 +     * @see     Character#toLowerCase(char)
 36.2883 +     * @see     Character#toUpperCase(char)
 36.2884       * @since   1.0.2
 36.2885       */
 36.2886      public static char toTitleCase(char ch) {
 36.2887 @@ -5580,9 +5748,9 @@
 36.2888       * @param   codePoint   the character (Unicode code point) to be converted.
 36.2889       * @return  the titlecase equivalent of the character, if any;
 36.2890       *          otherwise, the character itself.
 36.2891 -     * @see     java.lang.Character#isTitleCase(int)
 36.2892 -     * @see     java.lang.Character#toLowerCase(int)
 36.2893 -     * @see     java.lang.Character#toUpperCase(int)
 36.2894 +     * @see     Character#isTitleCase(int)
 36.2895 +     * @see     Character#toLowerCase(int)
 36.2896 +     * @see     Character#toUpperCase(int)
 36.2897       * @since   1.5
 36.2898       */
 36.2899      public static int toTitleCase(int codePoint) {
 36.2900 @@ -5624,8 +5792,8 @@
 36.2901       * @param   radix   the radix.
 36.2902       * @return  the numeric value represented by the character in the
 36.2903       *          specified radix.
 36.2904 -     * @see     java.lang.Character#forDigit(int, int)
 36.2905 -     * @see     java.lang.Character#isDigit(char)
 36.2906 +     * @see     Character#forDigit(int, int)
 36.2907 +     * @see     Character#isDigit(char)
 36.2908       */
 36.2909      public static int digit(char ch, int radix) {
 36.2910          return digit((int)ch, radix);
 36.2911 @@ -5661,8 +5829,8 @@
 36.2912       * @param   radix   the radix.
 36.2913       * @return  the numeric value represented by the character in the
 36.2914       *          specified radix.
 36.2915 -     * @see     java.lang.Character#forDigit(int, int)
 36.2916 -     * @see     java.lang.Character#isDigit(int)
 36.2917 +     * @see     Character#forDigit(int, int)
 36.2918 +     * @see     Character#isDigit(int)
 36.2919       * @since   1.5
 36.2920       */
 36.2921      public static int digit(int codePoint, int radix) {
 36.2922 @@ -5699,8 +5867,8 @@
 36.2923       * @return  the numeric value of the character, as a nonnegative <code>int</code>
 36.2924       *           value; -2 if the character has a numeric value that is not a
 36.2925       *          nonnegative integer; -1 if the character has no numeric value.
 36.2926 -     * @see     java.lang.Character#forDigit(int, int)
 36.2927 -     * @see     java.lang.Character#isDigit(char)
 36.2928 +     * @see     Character#forDigit(int, int)
 36.2929 +     * @see     Character#isDigit(char)
 36.2930       * @since   1.1
 36.2931       */
 36.2932      public static int getNumericValue(char ch) {
 36.2933 @@ -5732,8 +5900,8 @@
 36.2934       * @return  the numeric value of the character, as a nonnegative <code>int</code>
 36.2935       *          value; -2 if the character has a numeric value that is not a
 36.2936       *          nonnegative integer; -1 if the character has no numeric value.
 36.2937 -     * @see     java.lang.Character#forDigit(int, int)
 36.2938 -     * @see     java.lang.Character#isDigit(int)
 36.2939 +     * @see     Character#forDigit(int, int)
 36.2940 +     * @see     Character#isDigit(int)
 36.2941       * @since   1.5
 36.2942       */
 36.2943      public static int getNumericValue(int codePoint) {
 36.2944 @@ -5760,8 +5928,8 @@
 36.2945       * @param      ch   the character to be tested.
 36.2946       * @return     <code>true</code> if the character is ISO-LATIN-1 white
 36.2947       *             space; <code>false</code> otherwise.
 36.2948 -     * @see        java.lang.Character#isSpaceChar(char)
 36.2949 -     * @see        java.lang.Character#isWhitespace(char)
 36.2950 +     * @see        Character#isSpaceChar(char)
 36.2951 +     * @see        Character#isWhitespace(char)
 36.2952       * @deprecated Replaced by isWhitespace(char).
 36.2953       */
 36.2954      @Deprecated
 36.2955 @@ -5795,7 +5963,7 @@
 36.2956       * @param   ch      the character to be tested.
 36.2957       * @return  <code>true</code> if the character is a space character;
 36.2958       *          <code>false</code> otherwise.
 36.2959 -     * @see     java.lang.Character#isWhitespace(char)
 36.2960 +     * @see     Character#isWhitespace(char)
 36.2961       * @since   1.1
 36.2962       */
 36.2963      public static boolean isSpaceChar(char ch) {
 36.2964 @@ -5818,7 +5986,7 @@
 36.2965       * @param   codePoint the character (Unicode code point) to be tested.
 36.2966       * @return  <code>true</code> if the character is a space character;
 36.2967       *          <code>false</code> otherwise.
 36.2968 -     * @see     java.lang.Character#isWhitespace(int)
 36.2969 +     * @see     Character#isWhitespace(int)
 36.2970       * @since   1.5
 36.2971       */
 36.2972      public static boolean isSpaceChar(int codePoint) {
 36.2973 @@ -5856,7 +6024,7 @@
 36.2974       * @param   ch the character to be tested.
 36.2975       * @return  <code>true</code> if the character is a Java whitespace
 36.2976       *          character; <code>false</code> otherwise.
 36.2977 -     * @see     java.lang.Character#isSpaceChar(char)
 36.2978 +     * @see     Character#isSpaceChar(char)
 36.2979       * @since   1.1
 36.2980       */
 36.2981      public static boolean isWhitespace(char ch) {
 36.2982 @@ -5888,7 +6056,7 @@
 36.2983       * @param   codePoint the character (Unicode code point) to be tested.
 36.2984       * @return  <code>true</code> if the character is a Java whitespace
 36.2985       *          character; <code>false</code> otherwise.
 36.2986 -     * @see     java.lang.Character#isSpaceChar(int)
 36.2987 +     * @see     Character#isSpaceChar(int)
 36.2988       * @since   1.5
 36.2989       */
 36.2990      public static boolean isWhitespace(int codePoint) {
 36.2991 @@ -5911,8 +6079,8 @@
 36.2992       * @return  <code>true</code> if the character is an ISO control character;
 36.2993       *          <code>false</code> otherwise.
 36.2994       *
 36.2995 -     * @see     java.lang.Character#isSpaceChar(char)
 36.2996 -     * @see     java.lang.Character#isWhitespace(char)
 36.2997 +     * @see     Character#isSpaceChar(char)
 36.2998 +     * @see     Character#isWhitespace(char)
 36.2999       * @since   1.1
 36.3000       */
 36.3001      public static boolean isISOControl(char ch) {
 36.3002 @@ -5929,13 +6097,16 @@
 36.3003       * @param   codePoint the character (Unicode code point) to be tested.
 36.3004       * @return  <code>true</code> if the character is an ISO control character;
 36.3005       *          <code>false</code> otherwise.
 36.3006 -     * @see     java.lang.Character#isSpaceChar(int)
 36.3007 -     * @see     java.lang.Character#isWhitespace(int)
 36.3008 +     * @see     Character#isSpaceChar(int)
 36.3009 +     * @see     Character#isWhitespace(int)
 36.3010       * @since   1.5
 36.3011       */
 36.3012      public static boolean isISOControl(int codePoint) {
 36.3013 -        return (codePoint >= 0x0000 && codePoint <= 0x001F) ||
 36.3014 -            (codePoint >= 0x007F && codePoint <= 0x009F);
 36.3015 +        // Optimized form of:
 36.3016 +        //     (codePoint >= 0x00 && codePoint <= 0x1F) ||
 36.3017 +        //     (codePoint >= 0x7F && codePoint <= 0x9F);
 36.3018 +        return codePoint <= 0x9F &&
 36.3019 +            (codePoint >= 0x7F || (codePoint >>> 5 == 0));
 36.3020      }
 36.3021  
 36.3022      /**
 36.3023 @@ -5949,36 +6120,36 @@
 36.3024       * @param   ch      the character to be tested.
 36.3025       * @return  a value of type <code>int</code> representing the
 36.3026       *          character's general category.
 36.3027 -     * @see     java.lang.Character#COMBINING_SPACING_MARK
 36.3028 -     * @see     java.lang.Character#CONNECTOR_PUNCTUATION
 36.3029 -     * @see     java.lang.Character#CONTROL
 36.3030 -     * @see     java.lang.Character#CURRENCY_SYMBOL
 36.3031 -     * @see     java.lang.Character#DASH_PUNCTUATION
 36.3032 -     * @see     java.lang.Character#DECIMAL_DIGIT_NUMBER
 36.3033 -     * @see     java.lang.Character#ENCLOSING_MARK
 36.3034 -     * @see     java.lang.Character#END_PUNCTUATION
 36.3035 -     * @see     java.lang.Character#FINAL_QUOTE_PUNCTUATION
 36.3036 -     * @see     java.lang.Character#FORMAT
 36.3037 -     * @see     java.lang.Character#INITIAL_QUOTE_PUNCTUATION
 36.3038 -     * @see     java.lang.Character#LETTER_NUMBER
 36.3039 -     * @see     java.lang.Character#LINE_SEPARATOR
 36.3040 -     * @see     java.lang.Character#LOWERCASE_LETTER
 36.3041 -     * @see     java.lang.Character#MATH_SYMBOL
 36.3042 -     * @see     java.lang.Character#MODIFIER_LETTER
 36.3043 -     * @see     java.lang.Character#MODIFIER_SYMBOL
 36.3044 -     * @see     java.lang.Character#NON_SPACING_MARK
 36.3045 -     * @see     java.lang.Character#OTHER_LETTER
 36.3046 -     * @see     java.lang.Character#OTHER_NUMBER
 36.3047 -     * @see     java.lang.Character#OTHER_PUNCTUATION
 36.3048 -     * @see     java.lang.Character#OTHER_SYMBOL
 36.3049 -     * @see     java.lang.Character#PARAGRAPH_SEPARATOR
 36.3050 -     * @see     java.lang.Character#PRIVATE_USE
 36.3051 -     * @see     java.lang.Character#SPACE_SEPARATOR
 36.3052 -     * @see     java.lang.Character#START_PUNCTUATION
 36.3053 -     * @see     java.lang.Character#SURROGATE
 36.3054 -     * @see     java.lang.Character#TITLECASE_LETTER
 36.3055 -     * @see     java.lang.Character#UNASSIGNED
 36.3056 -     * @see     java.lang.Character#UPPERCASE_LETTER
 36.3057 +     * @see     Character#COMBINING_SPACING_MARK
 36.3058 +     * @see     Character#CONNECTOR_PUNCTUATION
 36.3059 +     * @see     Character#CONTROL
 36.3060 +     * @see     Character#CURRENCY_SYMBOL
 36.3061 +     * @see     Character#DASH_PUNCTUATION
 36.3062 +     * @see     Character#DECIMAL_DIGIT_NUMBER
 36.3063 +     * @see     Character#ENCLOSING_MARK
 36.3064 +     * @see     Character#END_PUNCTUATION
 36.3065 +     * @see     Character#FINAL_QUOTE_PUNCTUATION
 36.3066 +     * @see     Character#FORMAT
 36.3067 +     * @see     Character#INITIAL_QUOTE_PUNCTUATION
 36.3068 +     * @see     Character#LETTER_NUMBER
 36.3069 +     * @see     Character#LINE_SEPARATOR
 36.3070 +     * @see     Character#LOWERCASE_LETTER
 36.3071 +     * @see     Character#MATH_SYMBOL
 36.3072 +     * @see     Character#MODIFIER_LETTER
 36.3073 +     * @see     Character#MODIFIER_SYMBOL
 36.3074 +     * @see     Character#NON_SPACING_MARK
 36.3075 +     * @see     Character#OTHER_LETTER
 36.3076 +     * @see     Character#OTHER_NUMBER
 36.3077 +     * @see     Character#OTHER_PUNCTUATION
 36.3078 +     * @see     Character#OTHER_SYMBOL
 36.3079 +     * @see     Character#PARAGRAPH_SEPARATOR
 36.3080 +     * @see     Character#PRIVATE_USE
 36.3081 +     * @see     Character#SPACE_SEPARATOR
 36.3082 +     * @see     Character#START_PUNCTUATION
 36.3083 +     * @see     Character#SURROGATE
 36.3084 +     * @see     Character#TITLECASE_LETTER
 36.3085 +     * @see     Character#UNASSIGNED
 36.3086 +     * @see     Character#UPPERCASE_LETTER
 36.3087       * @since   1.1
 36.3088       */
 36.3089      public static int getType(char ch) {
 36.3090 @@ -6047,9 +6218,9 @@
 36.3091       * @param   radix   the radix.
 36.3092       * @return  the <code>char</code> representation of the specified digit
 36.3093       *          in the specified radix.
 36.3094 -     * @see     java.lang.Character#MIN_RADIX
 36.3095 -     * @see     java.lang.Character#MAX_RADIX
 36.3096 -     * @see     java.lang.Character#digit(char, int)
 36.3097 +     * @see     Character#MIN_RADIX
 36.3098 +     * @see     Character#MAX_RADIX
 36.3099 +     * @see     Character#digit(char, int)
 36.3100       */
 36.3101      public static char forDigit(int digit, int radix) {
 36.3102          if ((digit >= radix) || (digit < 0)) {
 36.3103 @@ -6230,10 +6401,10 @@
 36.3104       * @return  either the uppercase equivalent of the character, if
 36.3105       *          any, or an error flag (<code>Character.ERROR</code>)
 36.3106       *          that indicates that a 1:M <code>char</code> mapping exists.
 36.3107 -     * @see     java.lang.Character#isLowerCase(char)
 36.3108 -     * @see     java.lang.Character#isUpperCase(char)
 36.3109 -     * @see     java.lang.Character#toLowerCase(char)
 36.3110 -     * @see     java.lang.Character#toTitleCase(char)
 36.3111 +     * @see     Character#isLowerCase(char)
 36.3112 +     * @see     Character#isUpperCase(char)
 36.3113 +     * @see     Character#toLowerCase(char)
 36.3114 +     * @see     Character#toTitleCase(char)
 36.3115       * @since 1.4
 36.3116       */
 36.3117      static int toUpperCaseEx(int codePoint) {
 36.3118 @@ -6254,8 +6425,7 @@
 36.3119       */
 36.3120      static char[] toUpperCaseCharArray(int codePoint) {
 36.3121          // As of Unicode 4.0, 1:M uppercasings only happen in the BMP.
 36.3122 -        assert isValidCodePoint(codePoint) &&
 36.3123 -               !isSupplementaryCodePoint(codePoint);
 36.3124 +        assert isBmpCodePoint(codePoint);
 36.3125          return CharacterData.of(codePoint).toUpperCaseCharArray(codePoint);
 36.3126      }
 36.3127  
    37.1 --- a/src/share/classes/java/lang/String.java	Thu Jul 15 20:11:45 2010 -0700
    37.2 +++ b/src/share/classes/java/lang/String.java	Tue Jul 20 22:21:31 2010 -0700
    37.3 @@ -38,7 +38,6 @@
    37.4  import java.util.regex.Pattern;
    37.5  import java.util.regex.PatternSyntaxException;
    37.6  
    37.7 -
    37.8  /**
    37.9   * The <code>String</code> class represents character strings. All
   37.10   * string literals in Java programs, such as <code>"abc"</code>, are
   37.11 @@ -99,6 +98,8 @@
   37.12   *
   37.13   * @author  Lee Boynton
   37.14   * @author  Arthur van Hoff
   37.15 + * @author  Martin Buchholz
   37.16 + * @author  Ulf Zibis
   37.17   * @see     java.lang.Object#toString()
   37.18   * @see     java.lang.StringBuffer
   37.19   * @see     java.lang.StringBuilder
   37.20 @@ -273,32 +274,32 @@
   37.21              throw new StringIndexOutOfBoundsException(offset + count);
   37.22          }
   37.23  
   37.24 +        final int end = offset + count;
   37.25 +
   37.26          // Pass 1: Compute precise size of char[]
   37.27 -        int n = 0;
   37.28 -        for (int i = offset; i < offset + count; i++) {
   37.29 +        int n = count;
   37.30 +        for (int i = offset; i < end; i++) {
   37.31              int c = codePoints[i];
   37.32 -            if (c >= Character.MIN_CODE_POINT &&
   37.33 -                c <  Character.MIN_SUPPLEMENTARY_CODE_POINT)
   37.34 -                n += 1;
   37.35 -            else if (Character.isSupplementaryCodePoint(c))
   37.36 -                n += 2;
   37.37 +            if (Character.isBmpCodePoint(c))
   37.38 +                continue;
   37.39 +            else if (Character.isValidCodePoint(c))
   37.40 +                n++;
   37.41              else throw new IllegalArgumentException(Integer.toString(c));
   37.42          }
   37.43  
   37.44          // Pass 2: Allocate and fill in char[]
   37.45 -        char[] v = new char[n];
   37.46 -        for (int i = offset, j = 0; i < offset + count; i++) {
   37.47 +        final char[] v = new char[n];
   37.48 +
   37.49 +        for (int i = offset, j = 0; i < end; i++, j++) {
   37.50              int c = codePoints[i];
   37.51 -            if (c < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
   37.52 -                v[j++] = (char) c;
   37.53 -            } else {
   37.54 -                Character.toSurrogates(c, v, j);
   37.55 -                j += 2;
   37.56 -            }
   37.57 +            if (Character.isBmpCodePoint(c))
   37.58 +                v[j] = (char) c;
   37.59 +            else
   37.60 +                Character.toSurrogates(c, v, j++);
   37.61          }
   37.62  
   37.63          this.value  = v;
   37.64 -        this.count  = v.length;
   37.65 +        this.count  = n;
   37.66          this.offset = 0;
   37.67      }
   37.68  
   37.69 @@ -1573,9 +1574,6 @@
   37.70       *          if the character does not occur.
   37.71       */
   37.72      public int indexOf(int ch, int fromIndex) {
   37.73 -        int max = offset + count;
   37.74 -        char v[] = value;
   37.75 -
   37.76          if (fromIndex < 0) {
   37.77              fromIndex = 0;
   37.78          } else if (fromIndex >= count) {
   37.79 @@ -1583,29 +1581,36 @@
   37.80              return -1;
   37.81          }
   37.82  
   37.83 -        int i = offset + fromIndex;
   37.84          if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
   37.85              // handle most cases here (ch is a BMP code point or a
   37.86              // negative value (invalid code point))
   37.87 -            for (; i < max ; i++) {
   37.88 -                if (v[i] == ch) {
   37.89 +            final char[] value = this.value;
   37.90 +            final int offset = this.offset;
   37.91 +            final int max = offset + count;
   37.92 +            for (int i = offset + fromIndex; i < max ; i++) {
   37.93 +                if (value[i] == ch) {
   37.94                      return i - offset;
   37.95                  }
   37.96              }
   37.97              return -1;
   37.98 +        } else {
   37.99 +            return indexOfSupplementary(ch, fromIndex);
  37.100          }
  37.101 +    }
  37.102  
  37.103 -        if (ch <= Character.MAX_CODE_POINT) {
  37.104 -            // handle supplementary characters here
  37.105 -            char[] surrogates = Character.toChars(ch);
  37.106 -            for (; i < max; i++) {
  37.107 -                if (v[i] == surrogates[0]) {
  37.108 -                    if (i + 1 == max) {
  37.109 -                        break;
  37.110 -                    }
  37.111 -                    if (v[i+1] == surrogates[1]) {
  37.112 -                        return i - offset;
  37.113 -                    }
  37.114 +    /**
  37.115 +     * Handles (rare) calls of indexOf with a supplementary character.
  37.116 +     */
  37.117 +    private int indexOfSupplementary(int ch, int fromIndex) {
  37.118 +        if (Character.isValidCodePoint(ch)) {
  37.119 +            final char[] value = this.value;
  37.120 +            final int offset = this.offset;
  37.121 +            final char hi = Character.highSurrogate(ch);
  37.122 +            final char lo = Character.lowSurrogate(ch);
  37.123 +            final int max = offset + count - 1;
  37.124 +            for (int i = offset + fromIndex; i < max; i++) {
  37.125 +                if (value[i] == hi && value[i+1] == lo) {
  37.126 +                    return i - offset;
  37.127                  }
  37.128              }
  37.129          }
  37.130 @@ -1674,34 +1679,36 @@
  37.131       *          if the character does not occur before that point.
  37.132       */
  37.133      public int lastIndexOf(int ch, int fromIndex) {
  37.134 -        int min = offset;
  37.135 -        char v[] = value;
  37.136 -
  37.137 -        int i = offset + ((fromIndex >= count) ? count - 1 : fromIndex);
  37.138 -
  37.139          if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
  37.140              // handle most cases here (ch is a BMP code point or a
  37.141              // negative value (invalid code point))
  37.142 -            for (; i >= min ; i--) {
  37.143 -                if (v[i] == ch) {
  37.144 +            final char[] value = this.value;
  37.145 +            final int offset = this.offset;
  37.146 +            int i = offset + Math.min(fromIndex, count - 1);
  37.147 +            for (; i >= offset ; i--) {
  37.148 +                if (value[i] == ch) {
  37.149                      return i - offset;
  37.150                  }
  37.151              }
  37.152              return -1;
  37.153 +        } else {
  37.154 +            return lastIndexOfSupplementary(ch, fromIndex);
  37.155          }
  37.156 +    }
  37.157  
  37.158 -        int max = offset + count;
  37.159 -        if (ch <= Character.MAX_CODE_POINT) {
  37.160 -            // handle supplementary characters here
  37.161 -            char[] surrogates = Character.toChars(ch);
  37.162 -            for (; i >= min; i--) {
  37.163 -                if (v[i] == surrogates[0]) {
  37.164 -                    if (i + 1 == max) {
  37.165 -                        break;
  37.166 -                    }
  37.167 -                    if (v[i+1] == surrogates[1]) {
  37.168 -                        return i - offset;
  37.169 -                    }
  37.170 +    /**
  37.171 +     * Handles (rare) calls of lastIndexOf with a supplementary character.
  37.172 +     */
  37.173 +    private int lastIndexOfSupplementary(int ch, int fromIndex) {
  37.174 +        if (Character.isValidCodePoint(ch)) {
  37.175 +            final char[] value = this.value;
  37.176 +            final int offset = this.offset;
  37.177 +            char hi = Character.highSurrogate(ch);
  37.178 +            char lo = Character.lowSurrogate(ch);
  37.179 +            int i = offset + Math.min(fromIndex, count - 2);
  37.180 +            for (; i >= offset; i--) {
  37.181 +                if (value[i] == hi && value[i+1] == lo) {
  37.182 +                    return i - offset;
  37.183                  }
  37.184              }
  37.185          }
  37.186 @@ -1710,18 +1717,17 @@
  37.187  
  37.188      /**
  37.189       * Returns the index within this string of the first occurrence of the
  37.190 -     * specified substring. The integer returned is the smallest value
  37.191 -     * <i>k</i> such that:
  37.192 +     * specified substring.
  37.193 +     *
  37.194 +     * <p>The returned index is the smallest value <i>k</i> for which:
  37.195       * <blockquote><pre>
  37.196       * this.startsWith(str, <i>k</i>)
  37.197       * </pre></blockquote>
  37.198 -     * is <code>true</code>.
  37.199 +     * If no such value of <i>k</i> exists, then {@code -1} is returned.
  37.200       *
  37.201 -     * @param   str   any string.
  37.202 -     * @return  if the string argument occurs as a substring within this
  37.203 -     *          object, then the index of the first character of the first
  37.204 -     *          such substring is returned; if it does not occur as a
  37.205 -     *          substring, <code>-1</code> is returned.
  37.206 +     * @param   str   the substring to search for.
  37.207 +     * @return  the index of the first occurrence of the specified substring,
  37.208 +     *          or {@code -1} if there is no such occurrence.
  37.209       */
  37.210      public int indexOf(String str) {
  37.211          return indexOf(str, 0);
  37.212 @@ -1729,17 +1735,19 @@
  37.213  
  37.214      /**
  37.215       * Returns the index within this string of the first occurrence of the
  37.216 -     * specified substring, starting at the specified index.  The integer
  37.217 -     * returned is the smallest value <tt>k</tt> for which:
  37.218 +     * specified substring, starting at the specified index.
  37.219 +     *
  37.220 +     * <p>The returned index is the smallest value <i>k</i> for which:
  37.221       * <blockquote><pre>
  37.222 -     *     k &gt;= Math.min(fromIndex, this.length()) && this.startsWith(str, k)
  37.223 +     * <i>k</i> &gt;= fromIndex && this.startsWith(str, <i>k</i>)
  37.224       * </pre></blockquote>
  37.225 -     * If no such value of <i>k</i> exists, then -1 is returned.
  37.226 +     * If no such value of <i>k</i> exists, then {@code -1} is returned.
  37.227       *
  37.228 -     * @param   str         the substring for which to search.
  37.229 +     * @param   str         the substring to search for.
  37.230       * @param   fromIndex   the index from which to start the search.
  37.231 -     * @return  the index within this string of the first occurrence of the
  37.232 -     *          specified substring, starting at the specified index.
  37.233 +     * @return  the index of the first occurrence of the specified substring,
  37.234 +     *          starting at the specified index,
  37.235 +     *          or {@code -1} if there is no such occurrence.
  37.236       */
  37.237      public int indexOf(String str, int fromIndex) {
  37.238          return indexOf(value, offset, count,
  37.239 @@ -1798,20 +1806,19 @@
  37.240      }
  37.241  
  37.242      /**
  37.243 -     * Returns the index within this string of the rightmost occurrence
  37.244 -     * of the specified substring.  The rightmost empty string "" is
  37.245 -     * considered to occur at the index value <code>this.length()</code>.
  37.246 -     * The returned index is the largest value <i>k</i> such that
  37.247 +     * Returns the index within this string of the last occurrence of the
  37.248 +     * specified substring.  The last occurrence of the empty string ""
  37.249 +     * is considered to occur at the index value {@code this.length()}.
  37.250 +     *
  37.251 +     * <p>The returned index is the largest value <i>k</i> for which:
  37.252       * <blockquote><pre>
  37.253 -     * this.startsWith(str, k)
  37.254 +     * this.startsWith(str, <i>k</i>)
  37.255       * </pre></blockquote>
  37.256 -     * is true.
  37.257 +     * If no such value of <i>k</i> exists, then {@code -1} is returned.
  37.258       *
  37.259       * @param   str   the substring to search for.
  37.260 -     * @return  if the string argument occurs one or more times as a substring
  37.261 -     *          within this object, then the index of the first character of
  37.262 -     *          the last such substring is returned. If it does not occur as
  37.263 -     *          a substring, <code>-1</code> is returned.
  37.264 +     * @return  the index of the last occurrence of the specified substring,
  37.265 +     *          or {@code -1} if there is no such occurrence.
  37.266       */
  37.267      public int lastIndexOf(String str) {
  37.268          return lastIndexOf(str, count);
  37.269 @@ -1820,16 +1827,18 @@
  37.270      /**
  37.271       * Returns the index within this string of the last occurrence of the
  37.272       * specified substring, searching backward starting at the specified index.
  37.273 -     * The integer returned is the largest value <i>k</i> such that:
  37.274 +     *
  37.275 +     * <p>The returned index is the largest value <i>k</i> for which:
  37.276       * <blockquote><pre>
  37.277 -     *     k &lt;= Math.min(fromIndex, this.length()) && this.startsWith(str, k)
  37.278 +     * <i>k</i> &lt;= fromIndex && this.startsWith(str, <i>k</i>)
  37.279       * </pre></blockquote>
  37.280 -     * If no such value of <i>k</i> exists, then -1 is returned.
  37.281 +     * If no such value of <i>k</i> exists, then {@code -1} is returned.
  37.282       *
  37.283       * @param   str         the substring to search for.
  37.284       * @param   fromIndex   the index to start the search from.
  37.285 -     * @return  the index within this string of the last occurrence of the
  37.286 -     *          specified substring.
  37.287 +     * @return  the index of the last occurrence of the specified substring,
  37.288 +     *          searching backward from the specified index,
  37.289 +     *          or {@code -1} if there is no such occurrence.
  37.290       */
  37.291      public int lastIndexOf(String str, int fromIndex) {
  37.292          return lastIndexOf(value, offset, count,
    38.1 --- a/src/share/classes/java/lang/System.java	Thu Jul 15 20:11:45 2010 -0700
    38.2 +++ b/src/share/classes/java/lang/System.java	Tue Jul 20 22:21:31 2010 -0700
    38.3 @@ -69,7 +69,7 @@
    38.4       * corresponds to keyboard input or another input source specified by
    38.5       * the host environment or user.
    38.6       */
    38.7 -    public final static InputStream in = nullInputStream();
    38.8 +    public final static InputStream in = null;
    38.9  
   38.10      /**
   38.11       * The "standard" output stream. This stream is already
   38.12 @@ -96,7 +96,7 @@
   38.13       * @see     java.io.PrintStream#println(java.lang.Object)
   38.14       * @see     java.io.PrintStream#println(java.lang.String)
   38.15       */
   38.16 -    public final static PrintStream out = nullPrintStream();
   38.17 +    public final static PrintStream out = null;
   38.18  
   38.19      /**
   38.20       * The "standard" error output stream. This stream is already
   38.21 @@ -110,7 +110,7 @@
   38.22       * variable <code>out</code>, has been redirected to a file or other
   38.23       * destination that is typically not continuously monitored.
   38.24       */
   38.25 -    public final static PrintStream err = nullPrintStream();
   38.26 +    public final static PrintStream err = null;
   38.27  
   38.28      /* The security manager for the system.
   38.29       */
   38.30 @@ -1093,26 +1093,6 @@
   38.31      public static native String mapLibraryName(String libname);
   38.32  
   38.33      /**
   38.34 -     * The following two methods exist because in, out, and err must be
   38.35 -     * initialized to null.  The compiler, however, cannot be permitted to
   38.36 -     * inline access to them, since they are later set to more sensible values
   38.37 -     * by initializeSystemClass().
   38.38 -     */
   38.39 -    private static InputStream nullInputStream() throws NullPointerException {
   38.40 -        if (currentTimeMillis() > 0) {
   38.41 -            return null;
   38.42 -        }
   38.43 -        throw new NullPointerException();
   38.44 -    }
   38.45 -
   38.46 -    private static PrintStream nullPrintStream() throws NullPointerException {
   38.47 -        if (currentTimeMillis() > 0) {
   38.48 -            return null;
   38.49 -        }
   38.50 -        throw new NullPointerException();
   38.51 -    }
   38.52 -
   38.53 -    /**
   38.54       * Initialize the system class.  Called after thread initialization.
   38.55       */
   38.56      private static void initializeSystemClass() {
    39.1 --- a/src/share/classes/java/lang/Throwable.java	Thu Jul 15 20:11:45 2010 -0700
    39.2 +++ b/src/share/classes/java/lang/Throwable.java	Tue Jul 20 22:21:31 2010 -0700
    39.3 @@ -25,6 +25,7 @@
    39.4  
    39.5  package java.lang;
    39.6  import  java.io.*;
    39.7 +import  java.util.*;
    39.8  
    39.9  /**
   39.10   * The <code>Throwable</code> class is the superclass of all errors and
   39.11 @@ -102,7 +103,7 @@
   39.12   *         lowLevelOp();
   39.13   *     } catch (LowLevelException le) {
   39.14   *         throw (HighLevelException)
   39.15 -                 new HighLevelException().initCause(le);  // Legacy constructor
   39.16 + *               new HighLevelException().initCause(le);  // Legacy constructor
   39.17   *     }
   39.18   * </pre>
   39.19   *
   39.20 @@ -193,6 +194,24 @@
   39.21       */
   39.22  
   39.23      /**
   39.24 +     * The list of suppressed exceptions, as returned by
   39.25 +     * {@link #getSuppressedExceptions()}.
   39.26 +     *
   39.27 +     * @serial
   39.28 +     * @since 1.7
   39.29 +     */
   39.30 +    private List<Throwable> suppressedExceptions = Collections.emptyList();
   39.31 +
   39.32 +    /** Message for trying to suppress a null exception. */
   39.33 +    private static final String NULL_CAUSE_MESSAGE = "Cannot suppress a null exception.";
   39.34 +
   39.35 +    /** Caption  for labeling causative exception stack traces */
   39.36 +    private static final String CAUSE_CAPTION = "Caused by: ";
   39.37 +
   39.38 +    /** Caption for labeling suppressed exception stack traces */
   39.39 +    private static final String SUPPRESSED_CAPTION = "Suppressed: ";
   39.40 +
   39.41 +    /**
   39.42       * Constructs a new throwable with <code>null</code> as its detail message.
   39.43       * The cause is not initialized, and may subsequently be initialized by a
   39.44       * call to {@link #initCause}.
   39.45 @@ -469,6 +488,52 @@
   39.46       * class LowLevelException extends Exception {
   39.47       * }
   39.48       * </pre>
   39.49 +     * As of release 7, the platform supports the notion of
   39.50 +     * <i>suppressed exceptions</i> (in conjunction with automatic
   39.51 +     * resource management blocks). Any exceptions that were
   39.52 +     * suppressed in order to deliver an exception are printed out
   39.53 +     * beneath the stack trace.  The format of this information
   39.54 +     * depends on the implementation, but the following example may be
   39.55 +     * regarded as typical:
   39.56 +     *
   39.57 +     * <pre>
   39.58 +     * Exception in thread "main" java.lang.Exception: Something happened
   39.59 +     *  at Foo.bar(Foo.java:10)
   39.60 +     *  at Foo.main(Foo.java:5)
   39.61 +     *  Suppressed: Resource$CloseFailException: Resource ID = 0
   39.62 +     *          at Resource.close(Resource.java:26)
   39.63 +     *          at Foo.bar(Foo.java:9)
   39.64 +     *          ... 1 more
   39.65 +     * </pre>
   39.66 +     * Note that the "... n more" notation is used on suppressed exceptions
   39.67 +     * just at it is used on causes. Unlike causes, suppressed exceptions are
   39.68 +     * indented beyond their "containing exceptions."
   39.69 +     *
   39.70 +     * <p>An exception can have both a cause and one or more suppressed
   39.71 +     * exceptions:
   39.72 +     * <pre>
   39.73 +     * Exception in thread "main" java.lang.Exception: Main block
   39.74 +     *  at Foo3.main(Foo3.java:7)
   39.75 +     *  Suppressed: Resource$CloseFailException: Resource ID = 2
   39.76 +     *          at Resource.close(Resource.java:26)
   39.77 +     *          at Foo3.main(Foo3.java:5)
   39.78 +     *  Suppressed: Resource$CloseFailException: Resource ID = 1
   39.79 +     *          at Resource.close(Resource.java:26)
   39.80 +     *          at Foo3.main(Foo3.java:5)
   39.81 +     * Caused by: java.lang.Exception: I did it
   39.82 +     *  at Foo3.main(Foo3.java:8)
   39.83 +     * </pre>
   39.84 +     * Likewise, a suppressed exception can have a cause:
   39.85 +     * <pre>
   39.86 +     * Exception in thread "main" java.lang.Exception: Main block
   39.87 +     *  at Foo4.main(Foo4.java:6)
   39.88 +     *  Suppressed: Resource2$CloseFailException: Resource ID = 1
   39.89 +     *          at Resource2.close(Resource2.java:20)
   39.90 +     *          at Foo4.main(Foo4.java:5)
   39.91 +     *  Caused by: java.lang.Exception: Rats, you caught me
   39.92 +     *          at Resource2$CloseFailException.<init>(Resource2.java:45)
   39.93 +     *          ... 2 more
   39.94 +     * </pre>
   39.95       */
   39.96      public void printStackTrace() {
   39.97          printStackTrace(System.err);
   39.98 @@ -480,44 +545,71 @@
   39.99       * @param s <code>PrintStream</code> to use for output
  39.100       */
  39.101      public void printStackTrace(PrintStream s) {
  39.102 -        synchronized (s) {
  39.103 +        printStackTrace(new WrappedPrintStream(s));
  39.104 +    }
  39.105 +
  39.106 +    private void printStackTrace(PrintStreamOrWriter s) {
  39.107 +        Set<Throwable> dejaVu = new HashSet<Throwable>();
  39.108 +        dejaVu.add(this);
  39.109 +
  39.110 +        synchronized (s.lock()) {
  39.111 +            // Print our stack trace
  39.112              s.println(this);
  39.113              StackTraceElement[] trace = getOurStackTrace();
  39.114 -            for (int i=0; i < trace.length; i++)
  39.115 -                s.println("\tat " + trace[i]);
  39.116 +            for (StackTraceElement traceElement : trace)
  39.117 +                s.println("\tat " + traceElement);
  39.118  
  39.119 +            // Print suppressed exceptions, if any
  39.120 +            for (Throwable se : suppressedExceptions)
  39.121 +                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
  39.122 +
  39.123 +            // Print cause, if any
  39.124              Throwable ourCause = getCause();
  39.125              if (ourCause != null)
  39.126 -                ourCause.printStackTraceAsCause(s, trace);
  39.127 +                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
  39.128          }
  39.129      }
  39.130  
  39.131      /**
  39.132 -     * Print our stack trace as a cause for the specified stack trace.
  39.133 +     * Print our stack trace as an enclosed exception for the specified
  39.134 +     * stack trace.
  39.135       */
  39.136 -    private void printStackTraceAsCause(PrintStream s,
  39.137 -                                        StackTraceElement[] causedTrace)
  39.138 -    {
  39.139 -        // assert Thread.holdsLock(s);
  39.140 +    private void printEnclosedStackTrace(PrintStreamOrWriter s,
  39.141 +                                         StackTraceElement[] enclosingTrace,
  39.142 +                                         String caption,
  39.143 +                                         String prefix,
  39.144 +                                         Set<Throwable> dejaVu) {
  39.145 +        assert Thread.holdsLock(s.lock());
  39.146 +        if (dejaVu.contains(this)) {
  39.147 +            s.println("\t[CIRCULAR REFERENCE:" + this + "]");
  39.148 +        } else {
  39.149 +            dejaVu.add(this);
  39.150 +            // Compute number of frames in common between this and enclosing trace
  39.151 +            StackTraceElement[] trace = getOurStackTrace();
  39.152 +            int m = trace.length - 1;
  39.153 +            int n = enclosingTrace.length - 1;
  39.154 +            while (m >= 0 && n >=0 && trace[m].equals(enclosingTrace[n])) {
  39.155 +                m--; n--;
  39.156 +            }
  39.157 +            int framesInCommon = trace.length - 1 - m;
  39.158  
  39.159 -        // Compute number of frames in common between this and caused
  39.160 -        StackTraceElement[] trace = getOurStackTrace();
  39.161 -        int m = trace.length-1, n = causedTrace.length-1;
  39.162 -        while (m >= 0 && n >=0 && trace[m].equals(causedTrace[n])) {
  39.163 -            m--; n--;
  39.164 +            // Print our stack trace
  39.165 +            s.println(prefix + caption + this);
  39.166 +            for (int i = 0; i <= m; i++)
  39.167 +                s.println(prefix + "\tat " + trace[i]);
  39.168 +            if (framesInCommon != 0)
  39.169 +                s.println(prefix + "\t... " + framesInCommon + " more");
  39.170 +
  39.171 +            // Print suppressed exceptions, if any
  39.172 +            for (Throwable se : suppressedExceptions)
  39.173 +                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION,
  39.174 +                                           prefix +"\t", dejaVu);
  39.175 +
  39.176 +            // Print cause, if any
  39.177 +            Throwable ourCause = getCause();
  39.178 +            if (ourCause != null)
  39.179 +                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, prefix, dejaVu);
  39.180          }
  39.181 -        int framesInCommon = trace.length - 1 - m;
  39.182 -
  39.183 -        s.println("Caused by: " + this);
  39.184 -        for (int i=0; i <= m; i++)
  39.185 -            s.println("\tat " + trace[i]);
  39.186 -        if (framesInCommon != 0)
  39.187 -            s.println("\t... " + framesInCommon + " more");
  39.188 -
  39.189 -        // Recurse if we have a cause
  39.190 -        Throwable ourCause = getCause();
  39.191 -        if (ourCause != null)
  39.192 -            ourCause.printStackTraceAsCause(s, trace);
  39.193      }
  39.194  
  39.195      /**
  39.196 @@ -528,44 +620,51 @@
  39.197       * @since   JDK1.1
  39.198       */
  39.199      public void printStackTrace(PrintWriter s) {
  39.200 -        synchronized (s) {
  39.201 -            s.println(this);
  39.202 -            StackTraceElement[] trace = getOurStackTrace();
  39.203 -            for (int i=0; i < trace.length; i++)
  39.204 -                s.println("\tat " + trace[i]);
  39.205 +        printStackTrace(new WrappedPrintWriter(s));
  39.206 +    }
  39.207  
  39.208 -            Throwable ourCause = getCause();
  39.209 -            if (ourCause != null)
  39.210 -                ourCause.printStackTraceAsCause(s, trace);
  39.211 +    /**
  39.212 +     * Wrapper class for PrintStream and PrintWriter to enable a single
  39.213 +     * implementation of printStackTrace.
  39.214 +     */
  39.215 +    private abstract static class PrintStreamOrWriter {
  39.216 +        /** Returns the object to be locked when using this StreamOrWriter */
  39.217 +        abstract Object lock();
  39.218 +
  39.219 +        /** Prints the specified string as a line on this StreamOrWriter */
  39.220 +        abstract void println(Object o);
  39.221 +    }
  39.222 +
  39.223 +    private static class WrappedPrintStream extends PrintStreamOrWriter {
  39.224 +        private final PrintStream printStream;
  39.225 +
  39.226 +        WrappedPrintStream(PrintStream printStream) {
  39.227 +            this.printStream = printStream;
  39.228 +        }
  39.229 +
  39.230 +        Object lock() {
  39.231 +            return printStream;
  39.232 +        }
  39.233 +
  39.234 +        void println(Object o) {
  39.235 +            printStream.println(o);
  39.236          }
  39.237      }
  39.238  
  39.239 -    /**
  39.240 -     * Print our stack trace as a cause for the specified stack trace.
  39.241 -     */
  39.242 -    private void printStackTraceAsCause(PrintWriter s,
  39.243 -                                        StackTraceElement[] causedTrace)
  39.244 -    {
  39.245 -        // assert Thread.holdsLock(s);
  39.246 +    private static class WrappedPrintWriter extends PrintStreamOrWriter {
  39.247 +        private final PrintWriter printWriter;
  39.248  
  39.249 -        // Compute number of frames in common between this and caused
  39.250 -        StackTraceElement[] trace = getOurStackTrace();
  39.251 -        int m = trace.length-1, n = causedTrace.length-1;
  39.252 -        while (m >= 0 && n >=0 && trace[m].equals(causedTrace[n])) {
  39.253 -            m--; n--;
  39.254 +        WrappedPrintWriter(PrintWriter printWriter) {
  39.255 +            this.printWriter = printWriter;
  39.256          }
  39.257 -        int framesInCommon = trace.length - 1 - m;
  39.258  
  39.259 -        s.println("Caused by: " + this);
  39.260 -        for (int i=0; i <= m; i++)
  39.261 -            s.println("\tat " + trace[i]);
  39.262 -        if (framesInCommon != 0)
  39.263 -            s.println("\t... " + framesInCommon + " more");
  39.264 +        Object lock() {
  39.265 +            return printWriter;
  39.266 +        }
  39.267  
  39.268 -        // Recurse if we have a cause
  39.269 -        Throwable ourCause = getCause();
  39.270 -        if (ourCause != null)
  39.271 -            ourCause.printStackTraceAsCause(s, trace);
  39.272 +        void println(Object o) {
  39.273 +            printWriter.println(o);
  39.274 +        }
  39.275      }
  39.276  
  39.277      /**
  39.278 @@ -667,10 +766,60 @@
  39.279       */
  39.280      native StackTraceElement getStackTraceElement(int index);
  39.281  
  39.282 -    private synchronized void writeObject(java.io.ObjectOutputStream s)
  39.283 +    private void readObject(ObjectInputStream s)
  39.284 +        throws IOException, ClassNotFoundException {
  39.285 +        s.defaultReadObject();     // read in all fields
  39.286 +        List<Throwable> suppressed = Collections.emptyList();
  39.287 +        if (suppressedExceptions != null &&
  39.288 +            !suppressedExceptions.isEmpty()) { // Copy Throwables to new list
  39.289 +            suppressed = new ArrayList<Throwable>();
  39.290 +            for(Throwable t : suppressedExceptions) {
  39.291 +                if (t == null)
  39.292 +                    throw new NullPointerException(NULL_CAUSE_MESSAGE);
  39.293 +                suppressed.add(t);
  39.294 +            }
  39.295 +        }
  39.296 +        suppressedExceptions = suppressed;
  39.297 +    }
  39.298 +
  39.299 +    private synchronized void writeObject(ObjectOutputStream s)
  39.300          throws IOException
  39.301      {
  39.302          getOurStackTrace();  // Ensure that stackTrace field is initialized.
  39.303          s.defaultWriteObject();
  39.304      }
  39.305 +
  39.306 +    /**
  39.307 +     * Adds the specified exception to the list of exceptions that
  39.308 +     * were suppressed, typically by the automatic resource management
  39.309 +     * statement, in order to deliver this exception.
  39.310 +     *
  39.311 +     * @param exception the exception to be added to the list of
  39.312 +     *        suppressed exceptions
  39.313 +     * @throws NullPointerException if {@code exception} is null
  39.314 +     * @since 1.7
  39.315 +     */
  39.316 +    public synchronized void addSuppressedException(Throwable exception) {
  39.317 +        if (exception == null)
  39.318 +            throw new NullPointerException(NULL_CAUSE_MESSAGE);
  39.319 +
  39.320 +        if (suppressedExceptions.size() == 0)
  39.321 +            suppressedExceptions = new ArrayList<Throwable>();
  39.322 +        suppressedExceptions.add(exception);
  39.323 +    }
  39.324 +
  39.325 +    private static final Throwable[] EMPTY_THROWABLE_ARRAY = new Throwable[0];
  39.326 +
  39.327 +    /**
  39.328 +     * Returns an array containing all of the exceptions that were
  39.329 +     * suppressed, typically by the automatic resource management
  39.330 +     * statement, in order to deliver this exception.
  39.331 +     *
  39.332 +     * @return an array containing all of the exceptions that were
  39.333 +     *         suppressed to deliver this exception.
  39.334 +     * @since 1.7
  39.335 +     */
  39.336 +    public Throwable[] getSuppressedExceptions() {
  39.337 +        return suppressedExceptions.toArray(EMPTY_THROWABLE_ARRAY);
  39.338 +    }
  39.339  }
    40.1 --- a/src/share/classes/java/net/Inet6Address.java	Thu Jul 15 20:11:45 2010 -0700
    40.2 +++ b/src/share/classes/java/net/Inet6Address.java	Tue Jul 20 22:21:31 2010 -0700
    40.3 @@ -427,8 +427,9 @@
    40.4                      try {
    40.5                          scope_id = deriveNumericScope (scope_ifname);
    40.6                      } catch (UnknownHostException e) {
    40.7 -                        // should not happen
    40.8 -                        assert false;
    40.9 +                        // typically should not happen, but it may be that
   40.10 +                        // the machine being used for deserialization has
   40.11 +                        // the same interface name but without IPv6 configured.
   40.12                      }
   40.13                  }
   40.14              } catch (SocketException e) {}
    41.1 --- a/src/share/classes/java/nio/Bits.java	Thu Jul 15 20:11:45 2010 -0700
    41.2 +++ b/src/share/classes/java/nio/Bits.java	Tue Jul 20 22:21:31 2010 -0700
    41.3 @@ -41,25 +41,19 @@
    41.4      // -- Swapping --
    41.5  
    41.6      static short swap(short x) {
    41.7 -        return (short)((x << 8) |
    41.8 -                       ((char)x >>> 8));
    41.9 +        return Short.reverseBytes(x);
   41.10      }
   41.11  
   41.12      static char swap(char x) {
   41.13 -        return (char)((x << 8) |
   41.14 -                      (x >>> 8));
   41.15 +        return Character.reverseBytes(x);
   41.16      }
   41.17  
   41.18      static int swap(int x) {
   41.19 -        return ((x << 24) |
   41.20 -                ((x & 0x0000ff00) <<  8) |
   41.21 -                ((x & 0x00ff0000) >>> 8) |
   41.22 -                (x >>> 24));
   41.23 +        return Integer.reverseBytes(x);
   41.24      }
   41.25  
   41.26      static long swap(long x) {
   41.27 -        return (((long)swap((int)x) << 32) |
   41.28 -                ((long)swap((int)(x >>> 32)) & 0xffffffffL));
   41.29 +        return Long.reverseBytes(x);
   41.30      }
   41.31  
   41.32  
   41.33 @@ -71,52 +65,52 @@
   41.34  
   41.35      static char getCharL(ByteBuffer bb, int bi) {
   41.36          return makeChar(bb._get(bi + 1),
   41.37 -                        bb._get(bi + 0));
   41.38 +                        bb._get(bi    ));
   41.39      }
   41.40  
   41.41      static char getCharL(long a) {
   41.42          return makeChar(_get(a + 1),
   41.43 -                        _get(a + 0));
   41.44 +                        _get(a    ));
   41.45      }
   41.46  
   41.47      static char getCharB(ByteBuffer bb, int bi) {
   41.48 -        return makeChar(bb._get(bi + 0),
   41.49 +        return makeChar(bb._get(bi    ),
   41.50                          bb._get(bi + 1));
   41.51      }
   41.52  
   41.53      static char getCharB(long a) {
   41.54 -        return makeChar(_get(a + 0),
   41.55 +        return makeChar(_get(a    ),
   41.56                          _get(a + 1));
   41.57      }
   41.58  
   41.59      static char getChar(ByteBuffer bb, int bi, boolean bigEndian) {
   41.60 -        return (bigEndian ? getCharB(bb, bi) : getCharL(bb, bi));
   41.61 +        return bigEndian ? getCharB(bb, bi) : getCharL(bb, bi);
   41.62      }
   41.63  
   41.64      static char getChar(long a, boolean bigEndian) {
   41.65 -        return (bigEndian ? getCharB(a) : getCharL(a));
   41.66 +        return bigEndian ? getCharB(a) : getCharL(a);
   41.67      }
   41.68  
   41.69      private static byte char1(char x) { return (byte)(x >> 8); }
   41.70 -    private static byte char0(char x) { return (byte)(x >> 0); }
   41.71 +    private static byte char0(char x) { return (byte)(x     ); }
   41.72  
   41.73      static void putCharL(ByteBuffer bb, int bi, char x) {
   41.74 -        bb._put(bi + 0, char0(x));
   41.75 +        bb._put(bi    , char0(x));
   41.76          bb._put(bi + 1, char1(x));
   41.77      }
   41.78  
   41.79      static void putCharL(long a, char x) {
   41.80 -        _put(a + 0, char0(x));
   41.81 +        _put(a    , char0(x));
   41.82          _put(a + 1, char1(x));
   41.83      }
   41.84  
   41.85      static void putCharB(ByteBuffer bb, int bi, char x) {
   41.86 -        bb._put(bi + 0, char1(x));
   41.87 +        bb._put(bi    , char1(x));
   41.88          bb._put(bi + 1, char0(x));
   41.89      }
   41.90  
   41.91      static void putCharB(long a, char x) {
   41.92 -        _put(a + 0, char1(x));
   41.93 +        _put(a    , char1(x));
   41.94          _put(a + 1, char0(x));
   41.95      }
   41.96  
   41.97 @@ -143,52 +137,52 @@
   41.98  
   41.99      static short getShortL(ByteBuffer bb, int bi) {
  41.100          return makeShort(bb._get(bi + 1),
  41.101 -                         bb._get(bi + 0));
  41.102 +                         bb._get(bi    ));
  41.103      }
  41.104  
  41.105      static short getShortL(long a) {
  41.106          return makeShort(_get(a + 1),
  41.107 -                         _get(a));
  41.108 +                         _get(a    ));
  41.109      }
  41.110  
  41.111      static short getShortB(ByteBuffer bb, int bi) {
  41.112 -        return makeShort(bb._get(bi + 0),
  41.113 +        return makeShort(bb._get(bi    ),
  41.114                           bb._get(bi + 1));
  41.115      }
  41.116  
  41.117      static short getShortB(long a) {
  41.118 -        return makeShort(_get(a),
  41.119 +        return makeShort(_get(a    ),
  41.120                           _get(a + 1));
  41.121      }
  41.122  
  41.123      static short getShort(ByteBuffer bb, int bi, boolean bigEndian) {
  41.124 -        return (bigEndian ? getShortB(bb, bi) : getShortL(bb, bi));
  41.125 +        return bigEndian ? getShortB(bb, bi) : getShortL(bb, bi);
  41.126      }
  41.127  
  41.128      static short getShort(long a, boolean bigEndian) {
  41.129 -        return (bigEndian ? getShortB(a) : getShortL(a));
  41.130 +        return bigEndian ? getShortB(a) : getShortL(a);
  41.131      }
  41.132  
  41.133      private static byte short1(short x) { return (byte)(x >> 8); }
  41.134 -    private static byte short0(short x) { return (byte)(x >> 0); }
  41.135 +    private static byte short0(short x) { return (byte)(x     ); }
  41.136  
  41.137      static void putShortL(ByteBuffer bb, int bi, short x) {
  41.138 -        bb._put(bi + 0, short0(x));
  41.139 +        bb._put(bi    , short0(x));
  41.140          bb._put(bi + 1, short1(x));
  41.141      }
  41.142  
  41.143      static void putShortL(long a, short x) {
  41.144 -        _put(a, short0(x));
  41.145 +        _put(a    , short0(x));
  41.146          _put(a + 1, short1(x));
  41.147      }
  41.148  
  41.149      static void putShortB(ByteBuffer bb, int bi, short x) {
  41.150 -        bb._put(bi + 0, short1(x));
  41.151 +        bb._put(bi    , short1(x));
  41.152          bb._put(bi + 1, short0(x));
  41.153      }
  41.154  
  41.155      static void putShortB(long a, short x) {
  41.156 -        _put(a, short1(x));
  41.157 +        _put(a    , short1(x));
  41.158          _put(a + 1, short0(x));
  41.159      }
  41.160  
  41.161 @@ -210,76 +204,76 @@
  41.162      // -- get/put int --
  41.163  
  41.164      static private int makeInt(byte b3, byte b2, byte b1, byte b0) {
  41.165 -        return (((b3 & 0xff) << 24) |
  41.166 +        return (((b3       ) << 24) |
  41.167                  ((b2 & 0xff) << 16) |
  41.168                  ((b1 & 0xff) <<  8) |
  41.169 -                ((b0 & 0xff) <<  0));
  41.170 +                ((b0 & 0xff)      ));
  41.171      }
  41.172  
  41.173      static int getIntL(ByteBuffer bb, int bi) {
  41.174          return makeInt(bb._get(bi + 3),
  41.175                         bb._get(bi + 2),
  41.176                         bb._get(bi + 1),
  41.177 -                       bb._get(bi + 0));
  41.178 +                       bb._get(bi    ));
  41.179      }
  41.180  
  41.181      static int getIntL(long a) {
  41.182          return makeInt(_get(a + 3),
  41.183                         _get(a + 2),
  41.184                         _get(a + 1),
  41.185 -                       _get(a + 0));
  41.186 +                       _get(a    ));
  41.187      }
  41.188  
  41.189      static int getIntB(ByteBuffer bb, int bi) {
  41.190 -        return makeInt(bb._get(bi + 0),
  41.191 +        return makeInt(bb._get(bi    ),
  41.192                         bb._get(bi + 1),
  41.193                         bb._get(bi + 2),
  41.194                         bb._get(bi + 3));
  41.195      }
  41.196  
  41.197      static int getIntB(long a) {
  41.198 -        return makeInt(_get(a + 0),
  41.199 +        return makeInt(_get(a    ),
  41.200                         _get(a + 1),
  41.201                         _get(a + 2),
  41.202                         _get(a + 3));
  41.203      }
  41.204  
  41.205      static int getInt(ByteBuffer bb, int bi, boolean bigEndian) {
  41.206 -        return (bigEndian ? getIntB(bb, bi) : getIntL(bb, bi));
  41.207 +        return bigEndian ? getIntB(bb, bi) : getIntL(bb, bi) ;
  41.208      }
  41.209  
  41.210      static int getInt(long a, boolean bigEndian) {
  41.211 -        return (bigEndian ? getIntB(a) : getIntL(a));
  41.212 +        return bigEndian ? getIntB(a) : getIntL(a) ;
  41.213      }
  41.214  
  41.215      private static byte int3(int x) { return (byte)(x >> 24); }
  41.216      private static byte int2(int x) { return (byte)(x >> 16); }
  41.217      private static byte int1(int x) { return (byte)(x >>  8); }
  41.218 -    private static byte int0(int x) { return (byte)(x >>  0); }
  41.219 +    private static byte int0(int x) { return (byte)(x      ); }
  41.220  
  41.221      static void putIntL(ByteBuffer bb, int bi, int x) {
  41.222          bb._put(bi + 3, int3(x));
  41.223          bb._put(bi + 2, int2(x));
  41.224          bb._put(bi + 1, int1(x));
  41.225 -        bb._put(bi + 0, int0(x));
  41.226 +        bb._put(bi    , int0(x));
  41.227      }
  41.228  
  41.229      static void putIntL(long a, int x) {
  41.230          _put(a + 3, int3(x));
  41.231          _put(a + 2, int2(x));
  41.232          _put(a + 1, int1(x));
  41.233 -        _put(a + 0, int0(x));
  41.234 +        _put(a    , int0(x));
  41.235      }
  41.236  
  41.237      static void putIntB(ByteBuffer bb, int bi, int x) {
  41.238 -        bb._put(bi + 0, int3(x));
  41.239 +        bb._put(bi    , int3(x));
  41.240          bb._put(bi + 1, int2(x));
  41.241          bb._put(bi + 2, int1(x));
  41.242          bb._put(bi + 3, int0(x));
  41.243      }
  41.244  
  41.245      static void putIntB(long a, int x) {
  41.246 -        _put(a + 0, int3(x));
  41.247 +        _put(a    , int3(x));
  41.248          _put(a + 1, int2(x));
  41.249          _put(a + 2, int1(x));
  41.250          _put(a + 3, int0(x));
  41.251 @@ -305,14 +299,14 @@
  41.252      static private long makeLong(byte b7, byte b6, byte b5, byte b4,
  41.253                                   byte b3, byte b2, byte b1, byte b0)
  41.254      {
  41.255 -        return ((((long)b7 & 0xff) << 56) |
  41.256 +        return ((((long)b7       ) << 56) |
  41.257                  (((long)b6 & 0xff) << 48) |
  41.258                  (((long)b5 & 0xff) << 40) |
  41.259                  (((long)b4 & 0xff) << 32) |
  41.260                  (((long)b3 & 0xff) << 24) |
  41.261                  (((long)b2 & 0xff) << 16) |
  41.262                  (((long)b1 & 0xff) <<  8) |
  41.263 -                (((long)b0 & 0xff) <<  0));
  41.264 +                (((long)b0 & 0xff)      ));
  41.265      }
  41.266  
  41.267      static long getLongL(ByteBuffer bb, int bi) {
  41.268 @@ -323,7 +317,7 @@
  41.269                          bb._get(bi + 3),
  41.270                          bb._get(bi + 2),
  41.271                          bb._get(bi + 1),
  41.272 -                        bb._get(bi + 0));
  41.273 +                        bb._get(bi    ));
  41.274      }
  41.275  
  41.276      static long getLongL(long a) {
  41.277 @@ -334,11 +328,11 @@
  41.278                          _get(a + 3),
  41.279                          _get(a + 2),
  41.280                          _get(a + 1),
  41.281 -                        _get(a + 0));
  41.282 +                        _get(a    ));
  41.283      }
  41.284  
  41.285      static long getLongB(ByteBuffer bb, int bi) {
  41.286 -        return makeLong(bb._get(bi + 0),
  41.287 +        return makeLong(bb._get(bi    ),
  41.288                          bb._get(bi + 1),
  41.289                          bb._get(bi + 2),
  41.290                          bb._get(bi + 3),
  41.291 @@ -349,7 +343,7 @@
  41.292      }
  41.293  
  41.294      static long getLongB(long a) {
  41.295 -        return makeLong(_get(a + 0),
  41.296 +        return makeLong(_get(a    ),
  41.297                          _get(a + 1),
  41.298                          _get(a + 2),
  41.299                          _get(a + 3),
  41.300 @@ -360,11 +354,11 @@
  41.301      }
  41.302  
  41.303      static long getLong(ByteBuffer bb, int bi, boolean bigEndian) {
  41.304 -        return (bigEndian ? getLongB(bb, bi) : getLongL(bb, bi));
  41.305 +        return bigEndian ? getLongB(bb, bi) : getLongL(bb, bi);
  41.306      }
  41.307  
  41.308      static long getLong(long a, boolean bigEndian) {
  41.309 -        return (bigEndian ? getLongB(a) : getLongL(a));
  41.310 +        return bigEndian ? getLongB(a) : getLongL(a);
  41.311      }
  41.312  
  41.313      private static byte long7(long x) { return (byte)(x >> 56); }
  41.314 @@ -374,7 +368,7 @@
  41.315      private static byte long3(long x) { return (byte)(x >> 24); }
  41.316      private static byte long2(long x) { return (byte)(x >> 16); }
  41.317      private static byte long1(long x) { return (byte)(x >>  8); }
  41.318 -    private static byte long0(long x) { return (byte)(x >>  0); }
  41.319 +    private static byte long0(long x) { return (byte)(x      ); }
  41.320  
  41.321      static void putLongL(ByteBuffer bb, int bi, long x) {
  41.322          bb._put(bi + 7, long7(x));
  41.323 @@ -384,7 +378,7 @@
  41.324          bb._put(bi + 3, long3(x));
  41.325          bb._put(bi + 2, long2(x));
  41.326          bb._put(bi + 1, long1(x));
  41.327 -        bb._put(bi + 0, long0(x));
  41.328 +        bb._put(bi    , long0(x));
  41.329      }
  41.330  
  41.331      static void putLongL(long a, long x) {
  41.332 @@ -395,11 +389,11 @@
  41.333          _put(a + 3, long3(x));
  41.334          _put(a + 2, long2(x));
  41.335          _put(a + 1, long1(x));
  41.336 -        _put(a + 0, long0(x));
  41.337 +        _put(a    , long0(x));
  41.338      }
  41.339  
  41.340      static void putLongB(ByteBuffer bb, int bi, long x) {
  41.341 -        bb._put(bi + 0, long7(x));
  41.342 +        bb._put(bi    , long7(x));
  41.343          bb._put(bi + 1, long6(x));
  41.344          bb._put(bi + 2, long5(x));
  41.345          bb._put(bi + 3, long4(x));
  41.346 @@ -410,7 +404,7 @@
  41.347      }
  41.348  
  41.349      static void putLongB(long a, long x) {
  41.350 -        _put(a + 0, long7(x));
  41.351 +        _put(a    , long7(x));
  41.352          _put(a + 1, long6(x));
  41.353          _put(a + 2, long5(x));
  41.354          _put(a + 3, long4(x));
  41.355 @@ -454,11 +448,11 @@
  41.356      }
  41.357  
  41.358      static float getFloat(ByteBuffer bb, int bi, boolean bigEndian) {
  41.359 -        return (bigEndian ? getFloatB(bb, bi) : getFloatL(bb, bi));
  41.360 +        return bigEndian ? getFloatB(bb, bi) : getFloatL(bb, bi);
  41.361      }
  41.362  
  41.363      static float getFloat(long a, boolean bigEndian) {
  41.364 -        return (bigEndian ? getFloatB(a) : getFloatL(a));
  41.365 +        return bigEndian ? getFloatB(a) : getFloatL(a);
  41.366      }
  41.367  
  41.368      static void putFloatL(ByteBuffer bb, int bi, float x) {
  41.369 @@ -511,11 +505,11 @@
  41.370      }
  41.371  
  41.372      static double getDouble(ByteBuffer bb, int bi, boolean bigEndian) {
  41.373 -        return (bigEndian ? getDoubleB(bb, bi) : getDoubleL(bb, bi));
  41.374 +        return bigEndian ? getDoubleB(bb, bi) : getDoubleL(bb, bi);
  41.375      }
  41.376  
  41.377      static double getDouble(long a, boolean bigEndian) {
  41.378 -        return (bigEndian ? getDoubleB(a) : getDoubleL(a));
  41.379 +        return bigEndian ? getDoubleB(a) : getDoubleL(a);
  41.380      }
  41.381  
  41.382      static void putDoubleL(ByteBuffer bb, int bi, double x) {
  41.383 @@ -794,7 +788,7 @@
  41.384      static native void copyFromIntArray(Object src, long srcPos, long dstAddr,
  41.385                                          long length);
  41.386      static native void copyToIntArray(long srcAddr, Object dst, long dstPos,
  41.387 -                                        long length);
  41.388 +                                      long length);
  41.389  
  41.390      static native void copyFromLongArray(Object src, long srcPos, long dstAddr,
  41.391                                           long length);
    42.1 --- a/src/share/classes/java/nio/channels/FileLock.java	Thu Jul 15 20:11:45 2010 -0700
    42.2 +++ b/src/share/classes/java/nio/channels/FileLock.java	Tue Jul 20 22:21:31 2010 -0700
    42.3 @@ -116,7 +116,7 @@
    42.4   * @since 1.4
    42.5   */
    42.6  
    42.7 -public abstract class FileLock {
    42.8 +public abstract class FileLock implements AutoCloseable {
    42.9  
   42.10      private final Channel channel;
   42.11      private final long position;
   42.12 @@ -299,6 +299,17 @@
   42.13      public abstract void release() throws IOException;
   42.14  
   42.15      /**
   42.16 +     * This method invokes the {@link #release} method. It was added
   42.17 +     * to the class so that it could be used in conjunction with the
   42.18 +     * automatic resource management block construct.
   42.19 +     *
   42.20 +     * @since 1.7
   42.21 +     */
   42.22 +    public final void close() throws IOException {
   42.23 +        release();
   42.24 +    }
   42.25 +
   42.26 +    /**
   42.27       * Returns a string describing the range, type, and validity of this lock.
   42.28       *
   42.29       * @return  A descriptive string
    43.1 --- a/src/share/classes/java/util/DualPivotQuicksort.java	Thu Jul 15 20:11:45 2010 -0700
    43.2 +++ b/src/share/classes/java/util/DualPivotQuicksort.java	Tue Jul 20 22:21:31 2010 -0700
    43.3 @@ -1,5 +1,5 @@
    43.4  /*
    43.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
    43.6 + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
    43.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    43.8   *
    43.9   * This code is free software; you can redistribute it and/or modify it
   43.10 @@ -27,7 +27,7 @@
   43.11  
   43.12  /**
   43.13   * This class implements the Dual-Pivot Quicksort algorithm by
   43.14 - * Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. The algorithm
   43.15 + * Vladimir Yaroslavskiy, Jon Bentley, and Josh Bloch. The algorithm
   43.16   * offers O(n log(n)) performance on many data sets that cause other
   43.17   * quicksorts to degrade to quadratic performance, and is typically
   43.18   * faster than traditional (one-pivot) Quicksort implementations.
   43.19 @@ -36,7 +36,8 @@
   43.20   * @author Jon Bentley
   43.21   * @author Josh Bloch
   43.22   *
   43.23 - * @version 2009.11.29 m765.827.12i
   43.24 + * @version 2010.06.21 m765.827.12i:5\7
   43.25 + * @since 1.7
   43.26   */
   43.27  final class DualPivotQuicksort {
   43.28  
   43.29 @@ -68,7 +69,7 @@
   43.30      private static final int COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR = 32768;
   43.31  
   43.32      /*
   43.33 -     * Sorting methods for 7 primitive types.
   43.34 +     * Sorting methods for seven primitive types.
   43.35       */
   43.36  
   43.37      /**
   43.38 @@ -77,7 +78,7 @@
   43.39       * @param a the array to be sorted
   43.40       */
   43.41      public static void sort(int[] a) {
   43.42 -        doSort(a, 0, a.length - 1);
   43.43 +        sort(a, 0, a.length - 1, true);
   43.44      }
   43.45  
   43.46      /**
   43.47 @@ -95,98 +96,132 @@
   43.48       */
   43.49      public static void sort(int[] a, int fromIndex, int toIndex) {
   43.50          rangeCheck(a.length, fromIndex, toIndex);
   43.51 -        doSort(a, fromIndex, toIndex - 1);
   43.52 +        sort(a, fromIndex, toIndex - 1, true);
   43.53      }
   43.54  
   43.55      /**
   43.56 -     * Sorts the specified range of the array into ascending order. This
   43.57 -     * method differs from the public {@code sort} method in that the
   43.58 -     * {@code right} index is inclusive, and it does no range checking
   43.59 -     * on {@code left} or {@code right}.
   43.60 +     * Sorts the specified range of the array into ascending order by the
   43.61 +     * Dual-Pivot Quicksort algorithm. This method differs from the public
   43.62 +     * {@code sort} method in that the {@code right} index is inclusive,
   43.63 +     * it does no range checking on {@code left} or {@code right}, and has
   43.64 +     * boolean flag whether insertion sort with sentinel is used or not.
   43.65       *
   43.66       * @param a the array to be sorted
   43.67       * @param left the index of the first element, inclusive, to be sorted
   43.68       * @param right the index of the last element, inclusive, to be sorted
   43.69 +     * @param leftmost indicates if the part is the most left in the range
   43.70       */
   43.71 -    private static void doSort(int[] a, int left, int right) {
   43.72 +    private static void sort(int[] a, int left, int right, boolean leftmost) {
   43.73 +        int length = right - left + 1;
   43.74 +
   43.75          // Use insertion sort on tiny arrays
   43.76 -        if (right - left + 1 < INSERTION_SORT_THRESHOLD) {
   43.77 -            for (int i = left + 1; i <= right; i++) {
   43.78 -                int ai = a[i];
   43.79 -                int j;
   43.80 -                for (j = i - 1; j >= left && ai < a[j]; j--) {
   43.81 -                    a[j + 1] = a[j];
   43.82 +        if (length < INSERTION_SORT_THRESHOLD) {
   43.83 +            if (!leftmost) {
   43.84 +                /*
   43.85 +                 * Every element in adjoining part plays the role
   43.86 +                 * of sentinel, therefore this allows us to avoid
   43.87 +                 * the j >= left check on each iteration.
   43.88 +                 */
   43.89 +                for (int j, i = left + 1; i <= right; i++) {
   43.90 +                    int ai = a[i];
   43.91 +                    for (j = i - 1; ai < a[j]; j--) {
   43.92 +                        // assert j >= left;
   43.93 +                        a[j + 1] = a[j];
   43.94 +                    }
   43.95 +                    a[j + 1] = ai;
   43.96                  }
   43.97 -                a[j + 1] = ai;
   43.98 +            } else {
   43.99 +                /*
  43.100 +                 * For case of leftmost part traditional (without a sentinel)
  43.101 +                 * insertion sort, optimized for server JVM, is used.
  43.102 +                 */
  43.103 +                for (int i = left, j = i; i < right; j = ++i) {
  43.104 +                    int ai = a[i + 1];
  43.105 +                    while (ai < a[j]) {
  43.106 +                        a[j + 1] = a[j];
  43.107 +                        if (j-- == left) {
  43.108 +                            break;
  43.109 +                        }
  43.110 +                    }
  43.111 +                    a[j + 1] = ai;
  43.112 +                }
  43.113              }
  43.114 -        } else { // Use Dual-Pivot Quicksort on large arrays
  43.115 -            dualPivotQuicksort(a, left, right);
  43.116 +            return;
  43.117          }
  43.118 -    }
  43.119  
  43.120 -    /**
  43.121 -     * Sorts the specified range of the array into ascending order by the
  43.122 -     * Dual-Pivot Quicksort algorithm.
  43.123 -     *
  43.124 -     * @param a the array to be sorted
  43.125 -     * @param left the index of the first element, inclusive, to be sorted
  43.126 -     * @param right the index of the last element, inclusive, to be sorted
  43.127 -     */
  43.128 -    private static void dualPivotQuicksort(int[] a, int left, int right) {
  43.129 -        // Compute indices of five evenly spaced elements
  43.130 -        int sixth = (right - left + 1) / 6;
  43.131 -        int e1 = left  + sixth;
  43.132 -        int e5 = right - sixth;
  43.133 +        // Inexpensive approximation of length / 7
  43.134 +        int seventh = (length >>> 3) + (length >>> 6) + 1;
  43.135 +
  43.136 +        /*
  43.137 +         * Sort five evenly spaced elements around (and including) the
  43.138 +         * center element in the range. These elements will be used for
  43.139 +         * pivot selection as described below. The choice for spacing
  43.140 +         * these elements was empirically determined to work well on
  43.141 +         * a wide variety of inputs.
  43.142 +         */
  43.143          int e3 = (left + right) >>> 1; // The midpoint
  43.144 -        int e4 = e3 + sixth;
  43.145 -        int e2 = e3 - sixth;
  43.146 +        int e2 = e3 - seventh;
  43.147 +        int e1 = e2 - seventh;
  43.148 +        int e4 = e3 + seventh;
  43.149 +        int e5 = e4 + seventh;
  43.150  
  43.151 -        // Sort these elements using a 5-element sorting network
  43.152 -        int ae1 = a[e1], ae2 = a[e2], ae3 = a[e3], ae4 = a[e4], ae5 = a[e5];
  43.153 +        // Sort these elements using insertion sort
  43.154 +        if (a[e2] < a[e1]) { int t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
  43.155  
  43.156 -        if (ae1 > ae2) { int t = ae1; ae1 = ae2; ae2 = t; }
  43.157 -        if (ae4 > ae5) { int t = ae4; ae4 = ae5; ae5 = t; }
  43.158 -        if (ae1 > ae3) { int t = ae1; ae1 = ae3; ae3 = t; }
  43.159 -        if (ae2 > ae3) { int t = ae2; ae2 = ae3; ae3 = t; }
  43.160 -        if (ae1 > ae4) { int t = ae1; ae1 = ae4; ae4 = t; }
  43.161 -        if (ae3 > ae4) { int t = ae3; ae3 = ae4; ae4 = t; }
  43.162 -        if (ae2 > ae5) { int t = ae2; ae2 = ae5; ae5 = t; }
  43.163 -        if (ae2 > ae3) { int t = ae2; ae2 = ae3; ae3 = t; }
  43.164 -        if (ae4 > ae5) { int t = ae4; ae4 = ae5; ae5 = t; }
  43.165 -
  43.166 -        a[e1] = ae1; a[e3] = ae3; a[e5] = ae5;
  43.167 +        if (a[e3] < a[e2]) { int t = a[e3]; a[e3] = a[e2]; a[e2] = t;
  43.168 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  43.169 +        }
  43.170 +        if (a[e4] < a[e3]) { int t = a[e4]; a[e4] = a[e3]; a[e3] = t;
  43.171 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
  43.172 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  43.173 +            }
  43.174 +        }
  43.175 +        if (a[e5] < a[e4]) { int t = a[e5]; a[e5] = a[e4]; a[e4] = t;
  43.176 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
  43.177 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
  43.178 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  43.179 +                }
  43.180 +            }
  43.181 +        }
  43.182  
  43.183          /*
  43.184           * Use the second and fourth of the five sorted elements as pivots.
  43.185           * These values are inexpensive approximations of the first and
  43.186           * second terciles of the array. Note that pivot1 <= pivot2.
  43.187 -         *
  43.188 -         * The pivots are stored in local variables, and the first and
  43.189 -         * the last of the elements to be sorted are moved to the locations
  43.190 -         * formerly occupied by the pivots. When partitioning is complete,
  43.191 -         * the pivots are swapped back into their final positions, and
  43.192 -         * excluded from subsequent sorting.
  43.193           */
  43.194 -        int pivot1 = ae2; a[e2] = a[left];
  43.195 -        int pivot2 = ae4; a[e4] = a[right];
  43.196 +        int pivot1 = a[e2];
  43.197 +        int pivot2 = a[e4];
  43.198  
  43.199          // Pointers
  43.200 -        int less  = left  + 1; // The index of first element of center part
  43.201 -        int great = right - 1; // The index before first element of right part
  43.202 +        int less  = left;  // The index of the first element of center part
  43.203 +        int great = right; // The index before the first element of right part
  43.204  
  43.205 -        boolean pivotsDiffer = (pivot1 != pivot2);
  43.206 +        if (pivot1 != pivot2) {
  43.207 +            /*
  43.208 +             * The first and the last elements to be sorted are moved to the
  43.209 +             * locations formerly occupied by the pivots. When partitioning
  43.210 +             * is complete, the pivots are swapped back into their final
  43.211 +             * positions, and excluded from subsequent sorting.
  43.212 +             */
  43.213 +            a[e2] = a[left];
  43.214 +            a[e4] = a[right];
  43.215  
  43.216 -        if (pivotsDiffer) {
  43.217 +            /*
  43.218 +             * Skip elements, which are less or greater than pivot values.
  43.219 +             */
  43.220 +            while (a[++less] < pivot1);
  43.221 +            while (a[--great] > pivot2);
  43.222 +
  43.223              /*
  43.224               * Partitioning:
  43.225               *
  43.226 -             *   left part         center part                    right part
  43.227 -             * +------------------------------------------------------------+
  43.228 -             * | < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2 |
  43.229 -             * +------------------------------------------------------------+
  43.230 -             *              ^                          ^       ^
  43.231 -             *              |                          |       |
  43.232 -             *             less                        k     great
  43.233 +             *   left part           center part                   right part
  43.234 +             * +--------------------------------------------------------------+
  43.235 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
  43.236 +             * +--------------------------------------------------------------+
  43.237 +             *               ^                          ^       ^
  43.238 +             *               |                          |       |
  43.239 +             *              less                        k     great
  43.240               *
  43.241               * Invariants:
  43.242               *
  43.243 @@ -194,16 +229,14 @@
  43.244               *    pivot1 <= all in [less, k)     <= pivot2
  43.245               *              all in (great, right) > pivot2
  43.246               *
  43.247 -             * Pointer k is the first index of ?-part
  43.248 +             * Pointer k is the first index of ?-part.
  43.249               */
  43.250              outer:
  43.251              for (int k = less; k <= great; k++) {
  43.252                  int ak = a[k];
  43.253                  if (ak < pivot1) { // Move a[k] to left part
  43.254 -                    if (k != less) {
  43.255 -                        a[k] = a[less];
  43.256 -                        a[less] = ak;
  43.257 -                    }
  43.258 +                    a[k] = a[less];
  43.259 +                    a[less] = ak;
  43.260                      less++;
  43.261                  } else if (ak > pivot2) { // Move a[k] to right part
  43.262                      while (a[great] > pivot2) {
  43.263 @@ -213,26 +246,107 @@
  43.264                      }
  43.265                      if (a[great] < pivot1) {
  43.266                          a[k] = a[less];
  43.267 -                        a[less++] = a[great];
  43.268 -                        a[great--] = ak;
  43.269 +                        a[less] = a[great];
  43.270 +                        less++;
  43.271                      } else { // pivot1 <= a[great] <= pivot2
  43.272                          a[k] = a[great];
  43.273 -                        a[great--] = ak;
  43.274 +                    }
  43.275 +                    a[great] = ak;
  43.276 +                    great--;
  43.277 +                }
  43.278 +            }
  43.279 +
  43.280 +            // Swap pivots into their final positions
  43.281 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
  43.282 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
  43.283 +
  43.284 +            // Sort left and right parts recursively, excluding known pivots
  43.285 +            sort(a, left, less - 2, leftmost);
  43.286 +            sort(a, great + 2, right, false);
  43.287 +
  43.288 +            /*
  43.289 +             * If center part is too large (comprises > 5/7 of the array),
  43.290 +             * swap internal pivot values to ends.
  43.291 +             */
  43.292 +            if (less < e1 && e5 < great) {
  43.293 +                /*
  43.294 +                 * Skip elements, which are equal to pivot values.
  43.295 +                 */
  43.296 +                while (a[less] == pivot1) {
  43.297 +                    less++;
  43.298 +                }
  43.299 +                while (a[great] == pivot2) {
  43.300 +                    great--;
  43.301 +                }
  43.302 +
  43.303 +                /*
  43.304 +                 * Partitioning:
  43.305 +                 *
  43.306 +                 *   left part         center part                  right part
  43.307 +                 * +----------------------------------------------------------+
  43.308 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
  43.309 +                 * +----------------------------------------------------------+
  43.310 +                 *              ^                        ^       ^
  43.311 +                 *              |                        |       |
  43.312 +                 *             less                      k     great
  43.313 +                 *
  43.314 +                 * Invariants:
  43.315 +                 *
  43.316 +                 *              all in (*,  less) == pivot1
  43.317 +                 *     pivot1 < all in [less,  k)  < pivot2
  43.318 +                 *              all in (great, *) == pivot2
  43.319 +                 *
  43.320 +                 * Pointer k is the first index of ?-part.
  43.321 +                 */
  43.322 +                outer:
  43.323 +                for (int k = less; k <= great; k++) {
  43.324 +                    int ak = a[k];
  43.325 +                    if (ak == pivot1) { // Move a[k] to left part
  43.326 +                        a[k] = a[less];
  43.327 +                        a[less] = ak;
  43.328 +                        less++;
  43.329 +                    } else if (ak == pivot2) { // Move a[k] to right part
  43.330 +                        while (a[great] == pivot2) {
  43.331 +                            if (great-- == k) {
  43.332 +                                break outer;
  43.333 +                            }
  43.334 +                        }
  43.335 +                        if (a[great] == pivot1) {
  43.336 +                            a[k] = a[less];
  43.337 +                            /*
  43.338 +                             * Even though a[great] equals to pivot1, the
  43.339 +                             * assignment a[less] = pivot1 may be incorrect,
  43.340 +                             * if a[great] and pivot1 are floating-point zeros
  43.341 +                             * of different signs. Therefore in float and
  43.342 +                             * double sorting methods we have to use more
  43.343 +                             * accurate assignment a[less] = a[great].
  43.344 +                             */
  43.345 +                            a[less] = pivot1;
  43.346 +                            less++;
  43.347 +                        } else { // pivot1 < a[great] < pivot2
  43.348 +                            a[k] = a[great];
  43.349 +                        }
  43.350 +                        a[great] = ak;
  43.351 +                        great--;
  43.352                      }
  43.353                  }
  43.354              }
  43.355 +
  43.356 +            // Sort center part recursively
  43.357 +            sort(a, less, great, false);
  43.358 +
  43.359          } else { // Pivots are equal
  43.360              /*
  43.361 -             * Partition degenerates to the traditional 3-way,
  43.362 -             * or "Dutch National Flag", partition:
  43.363 +             * Partition degenerates to the traditional 3-way
  43.364 +             * (or "Dutch National Flag") schema:
  43.365               *
  43.366 -             *   left part   center part            right part
  43.367 -             * +----------------------------------------------+
  43.368 -             * |  < pivot  |  == pivot  |    ?    |  > pivot  |
  43.369 -             * +----------------------------------------------+
  43.370 -             *              ^            ^       ^
  43.371 -             *              |            |       |
  43.372 -             *             less          k     great
  43.373 +             *   left part    center part              right part
  43.374 +             * +-------------------------------------------------+
  43.375 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
  43.376 +             * +-------------------------------------------------+
  43.377 +             *              ^              ^        ^
  43.378 +             *              |              |        |
  43.379 +             *             less            k      great
  43.380               *
  43.381               * Invariants:
  43.382               *
  43.383 @@ -240,20 +354,19 @@
  43.384               *   all in [less, k)     == pivot
  43.385               *   all in (great, right) > pivot
  43.386               *
  43.387 -             * Pointer k is the first index of ?-part
  43.388 +             * Pointer k is the first index of ?-part.
  43.389               */
  43.390 -            for (int k = less; k <= great; k++) {
  43.391 -                int ak = a[k];
  43.392 -                if (ak == pivot1) {
  43.393 +            for (int k = left; k <= great; k++) {
  43.394 +                if (a[k] == pivot1) {
  43.395                      continue;
  43.396                  }
  43.397 +                int ak = a[k];
  43.398 +
  43.399                  if (ak < pivot1) { // Move a[k] to left part
  43.400 -                    if (k != less) {
  43.401 -                        a[k] = a[less];
  43.402 -                        a[less] = ak;
  43.403 -                    }
  43.404 +                    a[k] = a[less];
  43.405 +                    a[less] = ak;
  43.406                      less++;
  43.407 -                } else { // (a[k] > pivot1) - Move a[k] to right part
  43.408 +                } else { // a[k] > pivot1 - Move a[k] to right part
  43.409                      /*
  43.410                       * We know that pivot1 == a[e3] == pivot2. Thus, we know
  43.411                       * that great will still be >= k when the following loop
  43.412 @@ -261,92 +374,33 @@
  43.413                       * In other words, a[e3] acts as a sentinel for great.
  43.414                       */
  43.415                      while (a[great] > pivot1) {
  43.416 +                        // assert great > k;
  43.417                          great--;
  43.418                      }
  43.419                      if (a[great] < pivot1) {
  43.420                          a[k] = a[less];
  43.421 -                        a[less++] = a[great];
  43.422 -                        a[great--] = ak;
  43.423 +                        a[less] = a[great];
  43.424 +                        less++;
  43.425                      } else { // a[great] == pivot1
  43.426 +                        /*
  43.427 +                         * Even though a[great] equals to pivot1, the
  43.428 +                         * assignment a[k] = pivot1 may be incorrect,
  43.429 +                         * if a[great] and pivot1 are floating-point
  43.430 +                         * zeros of different signs. Therefore in float
  43.431 +                         * and double sorting methods we have to use
  43.432 +                         * more accurate assignment a[k] = a[great].
  43.433 +                         */
  43.434                          a[k] = pivot1;
  43.435 -                        a[great--] = ak;
  43.436                      }
  43.437 +                    a[great] = ak;
  43.438 +                    great--;
  43.439                  }
  43.440              }
  43.441 +
  43.442 +            // Sort left and right parts recursively
  43.443 +            sort(a, left, less - 1, leftmost);
  43.444 +            sort(a, great + 1, right, false);
  43.445          }
  43.446 -
  43.447 -        // Swap pivots into their final positions
  43.448 -        a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
  43.449 -        a[right] = a[great + 1]; a[great + 1] = pivot2;
  43.450 -
  43.451 -        // Sort left and right parts recursively, excluding known pivot values
  43.452 -        doSort(a, left,   less - 2);
  43.453 -        doSort(a, great + 2, right);
  43.454 -
  43.455 -        /*
  43.456 -         * If pivot1 == pivot2, all elements from center
  43.457 -         * part are equal and, therefore, already sorted
  43.458 -         */
  43.459 -        if (!pivotsDiffer) {
  43.460 -            return;
  43.461 -        }
  43.462 -
  43.463 -        /*
  43.464 -         * If center part is too large (comprises > 2/3 of the array),
  43.465 -         * swap internal pivot values to ends
  43.466 -         */
  43.467 -        if (less < e1 && great > e5) {
  43.468 -            while (a[less] == pivot1) {
  43.469 -                less++;
  43.470 -            }
  43.471 -            while (a[great] == pivot2) {
  43.472 -                great--;
  43.473 -            }
  43.474 -
  43.475 -            /*
  43.476 -             * Partitioning:
  43.477 -             *
  43.478 -             *   left part       center part                   right part
  43.479 -             * +----------------------------------------------------------+
  43.480 -             * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
  43.481 -             * +----------------------------------------------------------+
  43.482 -             *              ^                        ^       ^
  43.483 -             *              |                        |       |
  43.484 -             *             less                      k     great
  43.485 -             *
  43.486 -             * Invariants:
  43.487 -             *
  43.488 -             *              all in (*, less)  == pivot1
  43.489 -             *     pivot1 < all in [less, k)   < pivot2
  43.490 -             *              all in (great, *) == pivot2
  43.491 -             *
  43.492 -             * Pointer k is the first index of ?-part
  43.493 -             */
  43.494 -            outer:
  43.495 -            for (int k = less; k <= great; k++) {
  43.496 -                int ak = a[k];
  43.497 -                if (ak == pivot2) { // Move a[k] to right part
  43.498 -                    while (a[great] == pivot2) {
  43.499 -                        if (great-- == k) {
  43.500 -                            break outer;
  43.501 -                        }
  43.502 -                    }
  43.503 -                    if (a[great] == pivot1) {
  43.504 -                        a[k] = a[less];
  43.505 -                        a[less++] = pivot1;
  43.506 -                    } else { // pivot1 < a[great] < pivot2
  43.507 -                        a[k] = a[great];
  43.508 -                    }
  43.509 -                    a[great--] = pivot2;
  43.510 -                } else if (ak == pivot1) { // Move a[k] to left part
  43.511 -                    a[k] = a[less];
  43.512 -                    a[less++] = pivot1;
  43.513 -                }
  43.514 -            }
  43.515 -        }
  43.516 -
  43.517 -        // Sort center part recursively, excluding known pivot values
  43.518 -        doSort(a, less, great);
  43.519      }
  43.520  
  43.521      /**
  43.522 @@ -355,7 +409,7 @@
  43.523       * @param a the array to be sorted
  43.524       */
  43.525      public static void sort(long[] a) {
  43.526 -        doSort(a, 0, a.length - 1);
  43.527 +        sort(a, 0, a.length - 1, true);
  43.528      }
  43.529  
  43.530      /**
  43.531 @@ -373,98 +427,132 @@
  43.532       */
  43.533      public static void sort(long[] a, int fromIndex, int toIndex) {
  43.534          rangeCheck(a.length, fromIndex, toIndex);
  43.535 -        doSort(a, fromIndex, toIndex - 1);
  43.536 +        sort(a, fromIndex, toIndex - 1, true);
  43.537      }
  43.538  
  43.539      /**
  43.540 -     * Sorts the specified range of the array into ascending order. This
  43.541 -     * method differs from the public {@code sort} method in that the
  43.542 -     * {@code right} index is inclusive, and it does no range checking on
  43.543 -     * {@code left} or {@code right}.
  43.544 +     * Sorts the specified range of the array into ascending order by the
  43.545 +     * Dual-Pivot Quicksort algorithm. This method differs from the public
  43.546 +     * {@code sort} method in that the {@code right} index is inclusive,
  43.547 +     * it does no range checking on {@code left} or {@code right}, and has
  43.548 +     * boolean flag whether insertion sort with sentinel is used or not.
  43.549       *
  43.550       * @param a the array to be sorted
  43.551       * @param left the index of the first element, inclusive, to be sorted
  43.552       * @param right the index of the last element, inclusive, to be sorted
  43.553 +     * @param leftmost indicates if the part is the most left in the range
  43.554       */
  43.555 -    private static void doSort(long[] a, int left, int right) {
  43.556 +    private static void sort(long[] a, int left, int right, boolean leftmost) {
  43.557 +        int length = right - left + 1;
  43.558 +
  43.559          // Use insertion sort on tiny arrays
  43.560 -        if (right - left + 1 < INSERTION_SORT_THRESHOLD) {
  43.561 -            for (int i = left + 1; i <= right; i++) {
  43.562 -                long ai = a[i];
  43.563 -                int j;
  43.564 -                for (j = i - 1; j >= left && ai < a[j]; j--) {
  43.565 -                    a[j + 1] = a[j];
  43.566 +        if (length < INSERTION_SORT_THRESHOLD) {
  43.567 +            if (!leftmost) {
  43.568 +                /*
  43.569 +                 * Every element in adjoining part plays the role
  43.570 +                 * of sentinel, therefore this allows us to avoid
  43.571 +                 * the j >= left check on each iteration.
  43.572 +                 */
  43.573 +                for (int j, i = left + 1; i <= right; i++) {
  43.574 +                    long ai = a[i];
  43.575 +                    for (j = i - 1; ai < a[j]; j--) {
  43.576 +                        // assert j >= left;
  43.577 +                        a[j + 1] = a[j];
  43.578 +                    }
  43.579 +                    a[j + 1] = ai;
  43.580                  }
  43.581 -                a[j + 1] = ai;
  43.582 +            } else {
  43.583 +                /*
  43.584 +                 * For case of leftmost part traditional (without a sentinel)
  43.585 +                 * insertion sort, optimized for server JVM, is used.
  43.586 +                 */
  43.587 +                for (int i = left, j = i; i < right; j = ++i) {
  43.588 +                    long ai = a[i + 1];
  43.589 +                    while (ai < a[j]) {
  43.590 +                        a[j + 1] = a[j];
  43.591 +                        if (j-- == left) {
  43.592 +                            break;
  43.593 +                        }
  43.594 +                    }
  43.595 +                    a[j + 1] = ai;
  43.596 +                }
  43.597              }
  43.598 -        } else { // Use Dual-Pivot Quicksort on large arrays
  43.599 -            dualPivotQuicksort(a, left, right);
  43.600 +            return;
  43.601          }
  43.602 -    }
  43.603  
  43.604 -    /**
  43.605 -     * Sorts the specified range of the array into ascending order by the
  43.606 -     * Dual-Pivot Quicksort algorithm.
  43.607 -     *
  43.608 -     * @param a the array to be sorted
  43.609 -     * @param left the index of the first element, inclusive, to be sorted
  43.610 -     * @param right the index of the last element, inclusive, to be sorted
  43.611 -     */
  43.612 -    private static void dualPivotQuicksort(long[] a, int left, int right) {
  43.613 -        // Compute indices of five evenly spaced elements
  43.614 -        int sixth = (right - left + 1) / 6;
  43.615 -        int e1 = left  + sixth;
  43.616 -        int e5 = right - sixth;
  43.617 +        // Inexpensive approximation of length / 7
  43.618 +        int seventh = (length >>> 3) + (length >>> 6) + 1;
  43.619 +
  43.620 +        /*
  43.621 +         * Sort five evenly spaced elements around (and including) the
  43.622 +         * center element in the range. These elements will be used for
  43.623 +         * pivot selection as described below. The choice for spacing
  43.624 +         * these elements was empirically determined to work well on
  43.625 +         * a wide variety of inputs.
  43.626 +         */
  43.627          int e3 = (left + right) >>> 1; // The midpoint
  43.628 -        int e4 = e3 + sixth;
  43.629 -        int e2 = e3 - sixth;
  43.630 +        int e2 = e3 - seventh;
  43.631 +        int e1 = e2 - seventh;
  43.632 +        int e4 = e3 + seventh;
  43.633 +        int e5 = e4 + seventh;
  43.634  
  43.635 -        // Sort these elements using a 5-element sorting network
  43.636 -        long ae1 = a[e1], ae2 = a[e2], ae3 = a[e3], ae4 = a[e4], ae5 = a[e5];
  43.637 +        // Sort these elements using insertion sort
  43.638 +        if (a[e2] < a[e1]) { long t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
  43.639  
  43.640 -        if (ae1 > ae2) { long t = ae1; ae1 = ae2; ae2 = t; }
  43.641 -        if (ae4 > ae5) { long t = ae4; ae4 = ae5; ae5 = t; }
  43.642 -        if (ae1 > ae3) { long t = ae1; ae1 = ae3; ae3 = t; }
  43.643 -        if (ae2 > ae3) { long t = ae2; ae2 = ae3; ae3 = t; }
  43.644 -        if (ae1 > ae4) { long t = ae1; ae1 = ae4; ae4 = t; }
  43.645 -        if (ae3 > ae4) { long t = ae3; ae3 = ae4; ae4 = t; }
  43.646 -        if (ae2 > ae5) { long t = ae2; ae2 = ae5; ae5 = t; }
  43.647 -        if (ae2 > ae3) { long t = ae2; ae2 = ae3; ae3 = t; }
  43.648 -        if (ae4 > ae5) { long t = ae4; ae4 = ae5; ae5 = t; }
  43.649 -
  43.650 -        a[e1] = ae1; a[e3] = ae3; a[e5] = ae5;
  43.651 +        if (a[e3] < a[e2]) { long t = a[e3]; a[e3] = a[e2]; a[e2] = t;
  43.652 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  43.653 +        }
  43.654 +        if (a[e4] < a[e3]) { long t = a[e4]; a[e4] = a[e3]; a[e3] = t;
  43.655 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
  43.656 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  43.657 +            }
  43.658 +        }
  43.659 +        if (a[e5] < a[e4]) { long t = a[e5]; a[e5] = a[e4]; a[e4] = t;
  43.660 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
  43.661 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
  43.662 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  43.663 +                }
  43.664 +            }
  43.665 +        }
  43.666  
  43.667          /*
  43.668           * Use the second and fourth of the five sorted elements as pivots.
  43.669           * These values are inexpensive approximations of the first and
  43.670           * second terciles of the array. Note that pivot1 <= pivot2.
  43.671 -         *
  43.672 -         * The pivots are stored in local variables, and the first and
  43.673 -         * the last of the elements to be sorted are moved to the locations
  43.674 -         * formerly occupied by the pivots. When partitioning is complete,
  43.675 -         * the pivots are swapped back into their final positions, and
  43.676 -         * excluded from subsequent sorting.
  43.677           */
  43.678 -        long pivot1 = ae2; a[e2] = a[left];
  43.679 -        long pivot2 = ae4; a[e4] = a[right];
  43.680 +        long pivot1 = a[e2];
  43.681 +        long pivot2 = a[e4];
  43.682  
  43.683          // Pointers
  43.684 -        int less  = left  + 1; // The index of first element of center part
  43.685 -        int great = right - 1; // The index before first element of right part
  43.686 +        int less  = left;  // The index of the first element of center part
  43.687 +        int great = right; // The index before the first element of right part
  43.688  
  43.689 -        boolean pivotsDiffer = (pivot1 != pivot2);
  43.690 +        if (pivot1 != pivot2) {
  43.691 +            /*
  43.692 +             * The first and the last elements to be sorted are moved to the
  43.693 +             * locations formerly occupied by the pivots. When partitioning
  43.694 +             * is complete, the pivots are swapped back into their final
  43.695 +             * positions, and excluded from subsequent sorting.
  43.696 +             */
  43.697 +            a[e2] = a[left];
  43.698 +            a[e4] = a[right];
  43.699  
  43.700 -        if (pivotsDiffer) {
  43.701 +            /*
  43.702 +             * Skip elements, which are less or greater than pivot values.
  43.703 +             */
  43.704 +            while (a[++less] < pivot1);
  43.705 +            while (a[--great] > pivot2);
  43.706 +
  43.707              /*
  43.708               * Partitioning:
  43.709               *
  43.710 -             *   left part         center part                    right part
  43.711 -             * +------------------------------------------------------------+
  43.712 -             * | < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2 |
  43.713 -             * +------------------------------------------------------------+
  43.714 -             *              ^                          ^       ^
  43.715 -             *              |                          |       |
  43.716 -             *             less                        k     great
  43.717 +             *   left part           center part                   right part
  43.718 +             * +--------------------------------------------------------------+
  43.719 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
  43.720 +             * +--------------------------------------------------------------+
  43.721 +             *               ^                          ^       ^
  43.722 +             *               |                          |       |
  43.723 +             *              less                        k     great
  43.724               *
  43.725               * Invariants:
  43.726               *
  43.727 @@ -472,16 +560,14 @@
  43.728               *    pivot1 <= all in [less, k)     <= pivot2
  43.729               *              all in (great, right) > pivot2
  43.730               *
  43.731 -             * Pointer k is the first index of ?-part
  43.732 +             * Pointer k is the first index of ?-part.
  43.733               */
  43.734              outer:
  43.735              for (int k = less; k <= great; k++) {
  43.736                  long ak = a[k];
  43.737                  if (ak < pivot1) { // Move a[k] to left part
  43.738 -                    if (k != less) {
  43.739 -                        a[k] = a[less];
  43.740 -                        a[less] = ak;
  43.741 -                    }
  43.742 +                    a[k] = a[less];
  43.743 +                    a[less] = ak;
  43.744                      less++;
  43.745                  } else if (ak > pivot2) { // Move a[k] to right part
  43.746                      while (a[great] > pivot2) {
  43.747 @@ -491,26 +577,107 @@
  43.748                      }
  43.749                      if (a[great] < pivot1) {
  43.750                          a[k] = a[less];
  43.751 -                        a[less++] = a[great];
  43.752 -                        a[great--] = ak;
  43.753 +                        a[less] = a[great];
  43.754 +                        less++;
  43.755                      } else { // pivot1 <= a[great] <= pivot2
  43.756                          a[k] = a[great];
  43.757 -                        a[great--] = ak;
  43.758 +                    }
  43.759 +                    a[great] = ak;
  43.760 +                    great--;
  43.761 +                }
  43.762 +            }
  43.763 +
  43.764 +            // Swap pivots into their final positions
  43.765 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
  43.766 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
  43.767 +
  43.768 +            // Sort left and right parts recursively, excluding known pivots
  43.769 +            sort(a, left, less - 2, leftmost);
  43.770 +            sort(a, great + 2, right, false);
  43.771 +
  43.772 +            /*
  43.773 +             * If center part is too large (comprises > 5/7 of the array),
  43.774 +             * swap internal pivot values to ends.
  43.775 +             */
  43.776 +            if (less < e1 && e5 < great) {
  43.777 +                /*
  43.778 +                 * Skip elements, which are equal to pivot values.
  43.779 +                 */
  43.780 +                while (a[less] == pivot1) {
  43.781 +                    less++;
  43.782 +                }
  43.783 +                while (a[great] == pivot2) {
  43.784 +                    great--;
  43.785 +                }
  43.786 +
  43.787 +                /*
  43.788 +                 * Partitioning:
  43.789 +                 *
  43.790 +                 *   left part         center part                  right part
  43.791 +                 * +----------------------------------------------------------+
  43.792 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
  43.793 +                 * +----------------------------------------------------------+
  43.794 +                 *              ^                        ^       ^
  43.795 +                 *              |                        |       |
  43.796 +                 *             less                      k     great
  43.797 +                 *
  43.798 +                 * Invariants:
  43.799 +                 *
  43.800 +                 *              all in (*,  less) == pivot1
  43.801 +                 *     pivot1 < all in [less,  k)  < pivot2
  43.802 +                 *              all in (great, *) == pivot2
  43.803 +                 *
  43.804 +                 * Pointer k is the first index of ?-part.
  43.805 +                 */
  43.806 +                outer:
  43.807 +                for (int k = less; k <= great; k++) {
  43.808 +                    long ak = a[k];
  43.809 +                    if (ak == pivot1) { // Move a[k] to left part
  43.810 +                        a[k] = a[less];
  43.811 +                        a[less] = ak;
  43.812 +                        less++;
  43.813 +                    } else if (ak == pivot2) { // Move a[k] to right part
  43.814 +                        while (a[great] == pivot2) {
  43.815 +                            if (great-- == k) {
  43.816 +                                break outer;
  43.817 +                            }
  43.818 +                        }
  43.819 +                        if (a[great] == pivot1) {
  43.820 +                            a[k] = a[less];
  43.821 +                            /*
  43.822 +                             * Even though a[great] equals to pivot1, the
  43.823 +                             * assignment a[less] = pivot1 may be incorrect,
  43.824 +                             * if a[great] and pivot1 are floating-point zeros
  43.825 +                             * of different signs. Therefore in float and
  43.826 +                             * double sorting methods we have to use more
  43.827 +                             * accurate assignment a[less] = a[great].
  43.828 +                             */
  43.829 +                            a[less] = pivot1;
  43.830 +                            less++;
  43.831 +                        } else { // pivot1 < a[great] < pivot2
  43.832 +                            a[k] = a[great];
  43.833 +                        }
  43.834 +                        a[great] = ak;
  43.835 +                        great--;
  43.836                      }
  43.837                  }
  43.838              }
  43.839 +
  43.840 +            // Sort center part recursively
  43.841 +            sort(a, less, great, false);
  43.842 +
  43.843          } else { // Pivots are equal
  43.844              /*
  43.845 -             * Partition degenerates to the traditional 3-way,
  43.846 -             * or "Dutch National Flag", partition:
  43.847 +             * Partition degenerates to the traditional 3-way
  43.848 +             * (or "Dutch National Flag") schema:
  43.849               *
  43.850 -             *   left part   center part            right part
  43.851 -             * +----------------------------------------------+
  43.852 -             * |  < pivot  |  == pivot  |    ?    |  > pivot  |
  43.853 -             * +----------------------------------------------+
  43.854 -             *              ^            ^       ^
  43.855 -             *              |            |       |
  43.856 -             *             less          k     great
  43.857 +             *   left part    center part              right part
  43.858 +             * +-------------------------------------------------+
  43.859 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
  43.860 +             * +-------------------------------------------------+
  43.861 +             *              ^              ^        ^
  43.862 +             *              |              |        |
  43.863 +             *             less            k      great
  43.864               *
  43.865               * Invariants:
  43.866               *
  43.867 @@ -518,20 +685,19 @@
  43.868               *   all in [less, k)     == pivot
  43.869               *   all in (great, right) > pivot
  43.870               *
  43.871 -             * Pointer k is the first index of ?-part
  43.872 +             * Pointer k is the first index of ?-part.
  43.873               */
  43.874 -            for (int k = less; k <= great; k++) {
  43.875 -                long ak = a[k];
  43.876 -                if (ak == pivot1) {
  43.877 +            for (int k = left; k <= great; k++) {
  43.878 +                if (a[k] == pivot1) {
  43.879                      continue;
  43.880                  }
  43.881 +                long ak = a[k];
  43.882 +
  43.883                  if (ak < pivot1) { // Move a[k] to left part
  43.884 -                    if (k != less) {
  43.885 -                        a[k] = a[less];
  43.886 -                        a[less] = ak;
  43.887 -                    }
  43.888 +                    a[k] = a[less];
  43.889 +                    a[less] = ak;
  43.890                      less++;
  43.891 -                } else { // (a[k] > pivot1) - Move a[k] to right part
  43.892 +                } else { // a[k] > pivot1 - Move a[k] to right part
  43.893                      /*
  43.894                       * We know that pivot1 == a[e3] == pivot2. Thus, we know
  43.895                       * that great will still be >= k when the following loop
  43.896 @@ -539,92 +705,33 @@
  43.897                       * In other words, a[e3] acts as a sentinel for great.
  43.898                       */
  43.899                      while (a[great] > pivot1) {
  43.900 +                        // assert great > k;
  43.901                          great--;
  43.902                      }
  43.903                      if (a[great] < pivot1) {
  43.904                          a[k] = a[less];
  43.905 -                        a[less++] = a[great];
  43.906 -                        a[great--] = ak;
  43.907 +                        a[less] = a[great];
  43.908 +                        less++;
  43.909                      } else { // a[great] == pivot1
  43.910 +                        /*
  43.911 +                         * Even though a[great] equals to pivot1, the
  43.912 +                         * assignment a[k] = pivot1 may be incorrect,
  43.913 +                         * if a[great] and pivot1 are floating-point
  43.914 +                         * zeros of different signs. Therefore in float
  43.915 +                         * and double sorting methods we have to use
  43.916 +                         * more accurate assignment a[k] = a[great].
  43.917 +                         */
  43.918                          a[k] = pivot1;
  43.919 -                        a[great--] = ak;
  43.920                      }
  43.921 +                    a[great] = ak;
  43.922 +                    great--;
  43.923                  }
  43.924              }
  43.925 +
  43.926 +            // Sort left and right parts recursively
  43.927 +            sort(a, left, less - 1, leftmost);
  43.928 +            sort(a, great + 1, right, false);
  43.929          }
  43.930 -
  43.931 -        // Swap pivots into their final positions
  43.932 -        a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
  43.933 -        a[right] = a[great + 1]; a[great + 1] = pivot2;
  43.934 -
  43.935 -        // Sort left and right parts recursively, excluding known pivot values
  43.936 -        doSort(a, left,   less - 2);
  43.937 -        doSort(a, great + 2, right);
  43.938 -
  43.939 -        /*
  43.940 -         * If pivot1 == pivot2, all elements from center
  43.941 -         * part are equal and, therefore, already sorted
  43.942 -         */
  43.943 -        if (!pivotsDiffer) {
  43.944 -            return;
  43.945 -        }
  43.946 -
  43.947 -        /*
  43.948 -         * If center part is too large (comprises > 2/3 of the array),
  43.949 -         * swap internal pivot values to ends
  43.950 -         */
  43.951 -        if (less < e1 && great > e5) {
  43.952 -            while (a[less] == pivot1) {
  43.953 -                less++;
  43.954 -            }
  43.955 -            while (a[great] == pivot2) {
  43.956 -                great--;
  43.957 -            }
  43.958 -
  43.959 -            /*
  43.960 -             * Partitioning:
  43.961 -             *
  43.962 -             *   left part       center part                   right part
  43.963 -             * +----------------------------------------------------------+
  43.964 -             * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
  43.965 -             * +----------------------------------------------------------+
  43.966 -             *              ^                        ^       ^
  43.967 -             *              |                        |       |
  43.968 -             *             less                      k     great
  43.969 -             *
  43.970 -             * Invariants:
  43.971 -             *
  43.972 -             *              all in (*, less)  == pivot1
  43.973 -             *     pivot1 < all in [less, k)   < pivot2
  43.974 -             *              all in (great, *) == pivot2
  43.975 -             *
  43.976 -             * Pointer k is the first index of ?-part
  43.977 -             */
  43.978 -            outer:
  43.979 -            for (int k = less; k <= great; k++) {
  43.980 -                long ak = a[k];
  43.981 -                if (ak == pivot2) { // Move a[k] to right part
  43.982 -                    while (a[great] == pivot2) {
  43.983 -                        if (great-- == k) {
  43.984 -                            break outer;
  43.985 -                        }
  43.986 -                    }
  43.987 -                    if (a[great] == pivot1) {
  43.988 -                        a[k] = a[less];
  43.989 -                        a[less++] = pivot1;
  43.990 -                    } else { // pivot1 < a[great] < pivot2
  43.991 -                        a[k] = a[great];
  43.992 -                    }
  43.993 -                    a[great--] = pivot2;
  43.994 -                } else if (ak == pivot1) { // Move a[k] to left part
  43.995 -                    a[k] = a[less];
  43.996 -                    a[less++] = pivot1;
  43.997 -                }
  43.998 -            }
  43.999 -        }
 43.1000 -
 43.1001 -        // Sort center part recursively, excluding known pivot values
 43.1002 -        doSort(a, less, great);
 43.1003      }
 43.1004  
 43.1005      /**
 43.1006 @@ -633,7 +740,11 @@
 43.1007       * @param a the array to be sorted
 43.1008       */
 43.1009      public static void sort(short[] a) {
 43.1010 -        doSort(a, 0, a.length - 1);
 43.1011 +        if (a.length > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
 43.1012 +            countingSort(a, 0, a.length - 1);
 43.1013 +        } else {
 43.1014 +            sort(a, 0, a.length - 1, true);
 43.1015 +        }
 43.1016      }
 43.1017  
 43.1018      /**
 43.1019 @@ -651,115 +762,166 @@
 43.1020       */
 43.1021      public static void sort(short[] a, int fromIndex, int toIndex) {
 43.1022          rangeCheck(a.length, fromIndex, toIndex);
 43.1023 -        doSort(a, fromIndex, toIndex - 1);
 43.1024 +
 43.1025 +        if (toIndex - fromIndex > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
 43.1026 +            countingSort(a, fromIndex, toIndex - 1);
 43.1027 +        } else {
 43.1028 +            sort(a, fromIndex, toIndex - 1, true);
 43.1029 +        }
 43.1030      }
 43.1031  
 43.1032      /** The number of distinct short values. */
 43.1033      private static final int NUM_SHORT_VALUES = 1 << 16;
 43.1034  
 43.1035      /**
 43.1036 -     * Sorts the specified range of the array into ascending order. This
 43.1037 -     * method differs from the public {@code sort} method in that the
 43.1038 -     * {@code right} index is inclusive, and it does no range checking on
 43.1039 -     * {@code left} or {@code right}.
 43.1040 +     * Sorts the specified range of the array by counting sort.
 43.1041       *
 43.1042       * @param a the array to be sorted
 43.1043       * @param left the index of the first element, inclusive, to be sorted
 43.1044       * @param right the index of the last element, inclusive, to be sorted
 43.1045       */
 43.1046 -    private static void doSort(short[] a, int left, int right) {
 43.1047 -        // Use insertion sort on tiny arrays
 43.1048 -        if (right - left + 1 < INSERTION_SORT_THRESHOLD) {
 43.1049 -            for (int i = left + 1; i <= right; i++) {
 43.1050 -                short ai = a[i];
 43.1051 -                int j;
 43.1052 -                for (j = i - 1; j >= left && ai < a[j]; j--) {
 43.1053 -                    a[j + 1] = a[j];
 43.1054 -                }
 43.1055 -                a[j + 1] = ai;
 43.1056 +    private static void countingSort(short[] a, int left, int right) {
 43.1057 +        int[] count = new int[NUM_SHORT_VALUES];
 43.1058 +
 43.1059 +        for (int i = left; i <= right; i++) {
 43.1060 +            count[a[i] - Short.MIN_VALUE]++;
 43.1061 +        }
 43.1062 +        for (int i = NUM_SHORT_VALUES - 1, k = right; k >= left; i--) {
 43.1063 +            while (count[i] == 0) {
 43.1064 +                i--;
 43.1065              }
 43.1066 -        } else if (right-left+1 > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
 43.1067 -            // Use counting sort on huge arrays
 43.1068 -            int[] count = new int[NUM_SHORT_VALUES];
 43.1069 +            short value = (short) (i + Short.MIN_VALUE);
 43.1070 +            int s = count[i];
 43.1071  
 43.1072 -            for (int i = left; i <= right; i++) {
 43.1073 -                count[a[i] - Short.MIN_VALUE]++;
 43.1074 -            }
 43.1075 -            for (int i = 0, k = left; i < count.length && k <= right; i++) {
 43.1076 -                short value = (short) (i + Short.MIN_VALUE);
 43.1077 -
 43.1078 -                for (int s = count[i]; s > 0; s--) {
 43.1079 -                    a[k++] = value;
 43.1080 -               }
 43.1081 -            }
 43.1082 -        } else { // Use Dual-Pivot Quicksort on large arrays
 43.1083 -            dualPivotQuicksort(a, left, right);
 43.1084 +            do {
 43.1085 +                a[k--] = value;
 43.1086 +            } while (--s > 0);
 43.1087          }
 43.1088      }
 43.1089  
 43.1090      /**
 43.1091       * Sorts the specified range of the array into ascending order by the
 43.1092 -     * Dual-Pivot Quicksort algorithm.
 43.1093 +     * Dual-Pivot Quicksort algorithm. This method differs from the public
 43.1094 +     * {@code sort} method in that the {@code right} index is inclusive,
 43.1095 +     * it does no range checking on {@code left} or {@code right}, and has
 43.1096 +     * boolean flag whether insertion sort with sentinel is used or not.
 43.1097       *
 43.1098       * @param a the array to be sorted
 43.1099       * @param left the index of the first element, inclusive, to be sorted
 43.1100       * @param right the index of the last element, inclusive, to be sorted
 43.1101 +     * @param leftmost indicates if the part is the most left in the range
 43.1102       */
 43.1103 -    private static void dualPivotQuicksort(short[] a, int left, int right) {
 43.1104 -        // Compute indices of five evenly spaced elements
 43.1105 -        int sixth = (right - left + 1) / 6;
 43.1106 -        int e1 = left  + sixth;
 43.1107 -        int e5 = right - sixth;
 43.1108 +    private static void sort(short[] a, int left, int right,boolean leftmost) {
 43.1109 +        int length = right - left + 1;
 43.1110 +
 43.1111 +        // Use insertion sort on tiny arrays
 43.1112 +        if (length < INSERTION_SORT_THRESHOLD) {
 43.1113 +            if (!leftmost) {
 43.1114 +                /*
 43.1115 +                 * Every element in adjoining part plays the role
 43.1116 +                 * of sentinel, therefore this allows us to avoid
 43.1117 +                 * the j >= left check on each iteration.
 43.1118 +                 */
 43.1119 +                for (int j, i = left + 1; i <= right; i++) {
 43.1120 +                    short ai = a[i];
 43.1121 +                    for (j = i - 1; ai < a[j]; j--) {
 43.1122 +                        // assert j >= left;
 43.1123 +                        a[j + 1] = a[j];
 43.1124 +                    }
 43.1125 +                    a[j + 1] = ai;
 43.1126 +                }
 43.1127 +            } else {
 43.1128 +                /*
 43.1129 +                 * For case of leftmost part traditional (without a sentinel)
 43.1130 +                 * insertion sort, optimized for server JVM, is used.
 43.1131 +                 */
 43.1132 +                for (int i = left, j = i; i < right; j = ++i) {
 43.1133 +                    short ai = a[i + 1];
 43.1134 +                    while (ai < a[j]) {
 43.1135 +                        a[j + 1] = a[j];
 43.1136 +                        if (j-- == left) {
 43.1137 +                            break;
 43.1138 +                        }
 43.1139 +                    }
 43.1140 +                    a[j + 1] = ai;
 43.1141 +                }
 43.1142 +            }
 43.1143 +            return;
 43.1144 +        }
 43.1145 +
 43.1146 +        // Inexpensive approximation of length / 7
 43.1147 +        int seventh = (length >>> 3) + (length >>> 6) + 1;
 43.1148 +
 43.1149 +        /*
 43.1150 +         * Sort five evenly spaced elements around (and including) the
 43.1151 +         * center element in the range. These elements will be used for
 43.1152 +         * pivot selection as described below. The choice for spacing
 43.1153 +         * these elements was empirically determined to work well on
 43.1154 +         * a wide variety of inputs.
 43.1155 +         */
 43.1156          int e3 = (left + right) >>> 1; // The midpoint
 43.1157 -        int e4 = e3 + sixth;
 43.1158 -        int e2 = e3 - sixth;
 43.1159 +        int e2 = e3 - seventh;
 43.1160 +        int e1 = e2 - seventh;
 43.1161 +        int e4 = e3 + seventh;
 43.1162 +        int e5 = e4 + seventh;
 43.1163  
 43.1164 -        // Sort these elements using a 5-element sorting network
 43.1165 -        short ae1 = a[e1], ae2 = a[e2], ae3 = a[e3], ae4 = a[e4], ae5 = a[e5];
 43.1166 +        // Sort these elements using insertion sort
 43.1167 +        if (a[e2] < a[e1]) { short t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 43.1168  
 43.1169 -        if (ae1 > ae2) { short t = ae1; ae1 = ae2; ae2 = t; }
 43.1170 -        if (ae4 > ae5) { short t = ae4; ae4 = ae5; ae5 = t; }
 43.1171 -        if (ae1 > ae3) { short t = ae1; ae1 = ae3; ae3 = t; }
 43.1172 -        if (ae2 > ae3) { short t = ae2; ae2 = ae3; ae3 = t; }
 43.1173 -        if (ae1 > ae4) { short t = ae1; ae1 = ae4; ae4 = t; }
 43.1174 -        if (ae3 > ae4) { short t = ae3; ae3 = ae4; ae4 = t; }
 43.1175 -        if (ae2 > ae5) { short t = ae2; ae2 = ae5; ae5 = t; }
 43.1176 -        if (ae2 > ae3) { short t = ae2; ae2 = ae3; ae3 = t; }
 43.1177 -        if (ae4 > ae5) { short t = ae4; ae4 = ae5; ae5 = t; }
 43.1178 -
 43.1179 -        a[e1] = ae1; a[e3] = ae3; a[e5] = ae5;
 43.1180 +        if (a[e3] < a[e2]) { short t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 43.1181 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.1182 +        }
 43.1183 +        if (a[e4] < a[e3]) { short t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 43.1184 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 43.1185 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.1186 +            }
 43.1187 +        }
 43.1188 +        if (a[e5] < a[e4]) { short t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 43.1189 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 43.1190 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 43.1191 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.1192 +                }
 43.1193 +            }
 43.1194 +        }
 43.1195  
 43.1196          /*
 43.1197           * Use the second and fourth of the five sorted elements as pivots.
 43.1198           * These values are inexpensive approximations of the first and
 43.1199           * second terciles of the array. Note that pivot1 <= pivot2.
 43.1200 -         *
 43.1201 -         * The pivots are stored in local variables, and the first and
 43.1202 -         * the last of the elements to be sorted are moved to the locations
 43.1203 -         * formerly occupied by the pivots. When partitioning is complete,
 43.1204 -         * the pivots are swapped back into their final positions, and
 43.1205 -         * excluded from subsequent sorting.
 43.1206           */
 43.1207 -        short pivot1 = ae2; a[e2] = a[left];
 43.1208 -        short pivot2 = ae4; a[e4] = a[right];
 43.1209 +        short pivot1 = a[e2];
 43.1210 +        short pivot2 = a[e4];
 43.1211  
 43.1212          // Pointers
 43.1213 -        int less  = left  + 1; // The index of first element of center part
 43.1214 -        int great = right - 1; // The index before first element of right part
 43.1215 +        int less  = left;  // The index of the first element of center part
 43.1216 +        int great = right; // The index before the first element of right part
 43.1217  
 43.1218 -        boolean pivotsDiffer = (pivot1 != pivot2);
 43.1219 +        if (pivot1 != pivot2) {
 43.1220 +            /*
 43.1221 +             * The first and the last elements to be sorted are moved to the
 43.1222 +             * locations formerly occupied by the pivots. When partitioning
 43.1223 +             * is complete, the pivots are swapped back into their final
 43.1224 +             * positions, and excluded from subsequent sorting.
 43.1225 +             */
 43.1226 +            a[e2] = a[left];
 43.1227 +            a[e4] = a[right];
 43.1228  
 43.1229 -        if (pivotsDiffer) {
 43.1230 +            /*
 43.1231 +             * Skip elements, which are less or greater than pivot values.
 43.1232 +             */
 43.1233 +            while (a[++less] < pivot1);
 43.1234 +            while (a[--great] > pivot2);
 43.1235 +
 43.1236              /*
 43.1237               * Partitioning:
 43.1238               *
 43.1239 -             *   left part         center part                    right part
 43.1240 -             * +------------------------------------------------------------+
 43.1241 -             * | < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2 |
 43.1242 -             * +------------------------------------------------------------+
 43.1243 -             *              ^                          ^       ^
 43.1244 -             *              |                          |       |
 43.1245 -             *             less                        k     great
 43.1246 +             *   left part           center part                   right part
 43.1247 +             * +--------------------------------------------------------------+
 43.1248 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 43.1249 +             * +--------------------------------------------------------------+
 43.1250 +             *               ^                          ^       ^
 43.1251 +             *               |                          |       |
 43.1252 +             *              less                        k     great
 43.1253               *
 43.1254               * Invariants:
 43.1255               *
 43.1256 @@ -767,16 +929,14 @@
 43.1257               *    pivot1 <= all in [less, k)     <= pivot2
 43.1258               *              all in (great, right) > pivot2
 43.1259               *
 43.1260 -             * Pointer k is the first index of ?-part
 43.1261 +             * Pointer k is the first index of ?-part.
 43.1262               */
 43.1263              outer:
 43.1264              for (int k = less; k <= great; k++) {
 43.1265                  short ak = a[k];
 43.1266                  if (ak < pivot1) { // Move a[k] to left part
 43.1267 -                    if (k != less) {
 43.1268 -                        a[k] = a[less];
 43.1269 -                        a[less] = ak;
 43.1270 -                    }
 43.1271 +                    a[k] = a[less];
 43.1272 +                    a[less] = ak;
 43.1273                      less++;
 43.1274                  } else if (ak > pivot2) { // Move a[k] to right part
 43.1275                      while (a[great] > pivot2) {
 43.1276 @@ -786,26 +946,107 @@
 43.1277                      }
 43.1278                      if (a[great] < pivot1) {
 43.1279                          a[k] = a[less];
 43.1280 -                        a[less++] = a[great];
 43.1281 -                        a[great--] = ak;
 43.1282 +                        a[less] = a[great];
 43.1283 +                        less++;
 43.1284                      } else { // pivot1 <= a[great] <= pivot2
 43.1285                          a[k] = a[great];
 43.1286 -                        a[great--] = ak;
 43.1287 +                    }
 43.1288 +                    a[great] = ak;
 43.1289 +                    great--;
 43.1290 +                }
 43.1291 +            }
 43.1292 +
 43.1293 +            // Swap pivots into their final positions
 43.1294 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 43.1295 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
 43.1296 +
 43.1297 +            // Sort left and right parts recursively, excluding known pivots
 43.1298 +            sort(a, left, less - 2, leftmost);
 43.1299 +            sort(a, great + 2, right, false);
 43.1300 +
 43.1301 +            /*
 43.1302 +             * If center part is too large (comprises > 5/7 of the array),
 43.1303 +             * swap internal pivot values to ends.
 43.1304 +             */
 43.1305 +            if (less < e1 && e5 < great) {
 43.1306 +                /*
 43.1307 +                 * Skip elements, which are equal to pivot values.
 43.1308 +                 */
 43.1309 +                while (a[less] == pivot1) {
 43.1310 +                    less++;
 43.1311 +                }
 43.1312 +                while (a[great] == pivot2) {
 43.1313 +                    great--;
 43.1314 +                }
 43.1315 +
 43.1316 +                /*
 43.1317 +                 * Partitioning:
 43.1318 +                 *
 43.1319 +                 *   left part         center part                  right part
 43.1320 +                 * +----------------------------------------------------------+
 43.1321 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 43.1322 +                 * +----------------------------------------------------------+
 43.1323 +                 *              ^                        ^       ^
 43.1324 +                 *              |                        |       |
 43.1325 +                 *             less                      k     great
 43.1326 +                 *
 43.1327 +                 * Invariants:
 43.1328 +                 *
 43.1329 +                 *              all in (*,  less) == pivot1
 43.1330 +                 *     pivot1 < all in [less,  k)  < pivot2
 43.1331 +                 *              all in (great, *) == pivot2
 43.1332 +                 *
 43.1333 +                 * Pointer k is the first index of ?-part.
 43.1334 +                 */
 43.1335 +                outer:
 43.1336 +                for (int k = less; k <= great; k++) {
 43.1337 +                    short ak = a[k];
 43.1338 +                    if (ak == pivot1) { // Move a[k] to left part
 43.1339 +                        a[k] = a[less];
 43.1340 +                        a[less] = ak;
 43.1341 +                        less++;
 43.1342 +                    } else if (ak == pivot2) { // Move a[k] to right part
 43.1343 +                        while (a[great] == pivot2) {
 43.1344 +                            if (great-- == k) {
 43.1345 +                                break outer;
 43.1346 +                            }
 43.1347 +                        }
 43.1348 +                        if (a[great] == pivot1) {
 43.1349 +                            a[k] = a[less];
 43.1350 +                            /*
 43.1351 +                             * Even though a[great] equals to pivot1, the
 43.1352 +                             * assignment a[less] = pivot1 may be incorrect,
 43.1353 +                             * if a[great] and pivot1 are floating-point zeros
 43.1354 +                             * of different signs. Therefore in float and
 43.1355 +                             * double sorting methods we have to use more
 43.1356 +                             * accurate assignment a[less] = a[great].
 43.1357 +                             */
 43.1358 +                            a[less] = pivot1;
 43.1359 +                            less++;
 43.1360 +                        } else { // pivot1 < a[great] < pivot2
 43.1361 +                            a[k] = a[great];
 43.1362 +                        }
 43.1363 +                        a[great] = ak;
 43.1364 +                        great--;
 43.1365                      }
 43.1366                  }
 43.1367              }
 43.1368 +
 43.1369 +            // Sort center part recursively
 43.1370 +            sort(a, less, great, false);
 43.1371 +
 43.1372          } else { // Pivots are equal
 43.1373              /*
 43.1374 -             * Partition degenerates to the traditional 3-way,
 43.1375 -             * or "Dutch National Flag", partition:
 43.1376 +             * Partition degenerates to the traditional 3-way
 43.1377 +             * (or "Dutch National Flag") schema:
 43.1378               *
 43.1379 -             *   left part   center part            right part
 43.1380 -             * +----------------------------------------------+
 43.1381 -             * |  < pivot  |  == pivot  |    ?    |  > pivot  |
 43.1382 -             * +----------------------------------------------+
 43.1383 -             *              ^            ^       ^
 43.1384 -             *              |            |       |
 43.1385 -             *             less          k     great
 43.1386 +             *   left part    center part              right part
 43.1387 +             * +-------------------------------------------------+
 43.1388 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 43.1389 +             * +-------------------------------------------------+
 43.1390 +             *              ^              ^        ^
 43.1391 +             *              |              |        |
 43.1392 +             *             less            k      great
 43.1393               *
 43.1394               * Invariants:
 43.1395               *
 43.1396 @@ -813,20 +1054,19 @@
 43.1397               *   all in [less, k)     == pivot
 43.1398               *   all in (great, right) > pivot
 43.1399               *
 43.1400 -             * Pointer k is the first index of ?-part
 43.1401 +             * Pointer k is the first index of ?-part.
 43.1402               */
 43.1403 -            for (int k = less; k <= great; k++) {
 43.1404 -                short ak = a[k];
 43.1405 -                if (ak == pivot1) {
 43.1406 +            for (int k = left; k <= great; k++) {
 43.1407 +                if (a[k] == pivot1) {
 43.1408                      continue;
 43.1409                  }
 43.1410 +                short ak = a[k];
 43.1411 +
 43.1412                  if (ak < pivot1) { // Move a[k] to left part
 43.1413 -                    if (k != less) {
 43.1414 -                        a[k] = a[less];
 43.1415 -                        a[less] = ak;
 43.1416 -                    }
 43.1417 +                    a[k] = a[less];
 43.1418 +                    a[less] = ak;
 43.1419                      less++;
 43.1420 -                } else { // (a[k] > pivot1) - Move a[k] to right part
 43.1421 +                } else { // a[k] > pivot1 - Move a[k] to right part
 43.1422                      /*
 43.1423                       * We know that pivot1 == a[e3] == pivot2. Thus, we know
 43.1424                       * that great will still be >= k when the following loop
 43.1425 @@ -834,92 +1074,33 @@
 43.1426                       * In other words, a[e3] acts as a sentinel for great.
 43.1427                       */
 43.1428                      while (a[great] > pivot1) {
 43.1429 +                        // assert great > k;
 43.1430                          great--;
 43.1431                      }
 43.1432                      if (a[great] < pivot1) {
 43.1433                          a[k] = a[less];
 43.1434 -                        a[less++] = a[great];
 43.1435 -                        a[great--] = ak;
 43.1436 +                        a[less] = a[great];
 43.1437 +                        less++;
 43.1438                      } else { // a[great] == pivot1
 43.1439 +                        /*
 43.1440 +                         * Even though a[great] equals to pivot1, the
 43.1441 +                         * assignment a[k] = pivot1 may be incorrect,
 43.1442 +                         * if a[great] and pivot1 are floating-point
 43.1443 +                         * zeros of different signs. Therefore in float
 43.1444 +                         * and double sorting methods we have to use
 43.1445 +                         * more accurate assignment a[k] = a[great].
 43.1446 +                         */
 43.1447                          a[k] = pivot1;
 43.1448 -                        a[great--] = ak;
 43.1449                      }
 43.1450 +                    a[great] = ak;
 43.1451 +                    great--;
 43.1452                  }
 43.1453              }
 43.1454 +
 43.1455 +            // Sort left and right parts recursively
 43.1456 +            sort(a, left, less - 1, leftmost);
 43.1457 +            sort(a, great + 1, right, false);
 43.1458          }
 43.1459 -
 43.1460 -        // Swap pivots into their final positions
 43.1461 -        a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 43.1462 -        a[right] = a[great + 1]; a[great + 1] = pivot2;
 43.1463 -
 43.1464 -        // Sort left and right parts recursively, excluding known pivot values
 43.1465 -        doSort(a, left,   less - 2);
 43.1466 -        doSort(a, great + 2, right);
 43.1467 -
 43.1468 -        /*
 43.1469 -         * If pivot1 == pivot2, all elements from center
 43.1470 -         * part are equal and, therefore, already sorted
 43.1471 -         */
 43.1472 -        if (!pivotsDiffer) {
 43.1473 -            return;
 43.1474 -        }
 43.1475 -
 43.1476 -        /*
 43.1477 -         * If center part is too large (comprises > 2/3 of the array),
 43.1478 -         * swap internal pivot values to ends
 43.1479 -         */
 43.1480 -        if (less < e1 && great > e5) {
 43.1481 -            while (a[less] == pivot1) {
 43.1482 -                less++;
 43.1483 -            }
 43.1484 -            while (a[great] == pivot2) {
 43.1485 -                great--;
 43.1486 -            }
 43.1487 -
 43.1488 -            /*
 43.1489 -             * Partitioning:
 43.1490 -             *
 43.1491 -             *   left part       center part                   right part
 43.1492 -             * +----------------------------------------------------------+
 43.1493 -             * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 43.1494 -             * +----------------------------------------------------------+
 43.1495 -             *              ^                        ^       ^
 43.1496 -             *              |                        |       |
 43.1497 -             *             less                      k     great
 43.1498 -             *
 43.1499 -             * Invariants:
 43.1500 -             *
 43.1501 -             *              all in (*, less)  == pivot1
 43.1502 -             *     pivot1 < all in [less, k)   < pivot2
 43.1503 -             *              all in (great, *) == pivot2
 43.1504 -             *
 43.1505 -             * Pointer k is the first index of ?-part
 43.1506 -             */
 43.1507 -            outer:
 43.1508 -            for (int k = less; k <= great; k++) {
 43.1509 -                short ak = a[k];
 43.1510 -                if (ak == pivot2) { // Move a[k] to right part
 43.1511 -                    while (a[great] == pivot2) {
 43.1512 -                        if (great-- == k) {
 43.1513 -                            break outer;
 43.1514 -                        }
 43.1515 -                    }
 43.1516 -                    if (a[great] == pivot1) {
 43.1517 -                        a[k] = a[less];
 43.1518 -                        a[less++] = pivot1;
 43.1519 -                    } else { // pivot1 < a[great] < pivot2
 43.1520 -                        a[k] = a[great];
 43.1521 -                    }
 43.1522 -                    a[great--] = pivot2;
 43.1523 -                } else if (ak == pivot1) { // Move a[k] to left part
 43.1524 -                    a[k] = a[less];
 43.1525 -                    a[less++] = pivot1;
 43.1526 -                }
 43.1527 -            }
 43.1528 -        }
 43.1529 -
 43.1530 -        // Sort center part recursively, excluding known pivot values
 43.1531 -        doSort(a, less, great);
 43.1532      }
 43.1533  
 43.1534      /**
 43.1535 @@ -928,7 +1109,11 @@
 43.1536       * @param a the array to be sorted
 43.1537       */
 43.1538      public static void sort(char[] a) {
 43.1539 -        doSort(a, 0, a.length - 1);
 43.1540 +        if (a.length > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
 43.1541 +            countingSort(a, 0, a.length - 1);
 43.1542 +        } else {
 43.1543 +            sort(a, 0, a.length - 1, true);
 43.1544 +        }
 43.1545      }
 43.1546  
 43.1547      /**
 43.1548 @@ -946,113 +1131,166 @@
 43.1549       */
 43.1550      public static void sort(char[] a, int fromIndex, int toIndex) {
 43.1551          rangeCheck(a.length, fromIndex, toIndex);
 43.1552 -        doSort(a, fromIndex, toIndex - 1);
 43.1553 +
 43.1554 +        if (toIndex - fromIndex > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
 43.1555 +            countingSort(a, fromIndex, toIndex - 1);
 43.1556 +        } else {
 43.1557 +            sort(a, fromIndex, toIndex - 1, true);
 43.1558 +        }
 43.1559      }
 43.1560  
 43.1561      /** The number of distinct char values. */
 43.1562      private static final int NUM_CHAR_VALUES = 1 << 16;
 43.1563  
 43.1564      /**
 43.1565 -     * Sorts the specified range of the array into ascending order. This
 43.1566 -     * method differs from the public {@code sort} method in that the
 43.1567 -     * {@code right} index is inclusive, and it does no range checking on
 43.1568 -     * {@code left} or {@code right}.
 43.1569 +     * Sorts the specified range of the array by counting sort.
 43.1570       *
 43.1571       * @param a the array to be sorted
 43.1572       * @param left the index of the first element, inclusive, to be sorted
 43.1573       * @param right the index of the last element, inclusive, to be sorted
 43.1574       */
 43.1575 -    private static void doSort(char[] a, int left, int right) {
 43.1576 -        // Use insertion sort on tiny arrays
 43.1577 -        if (right - left + 1 < INSERTION_SORT_THRESHOLD) {
 43.1578 -            for (int i = left + 1; i <= right; i++) {
 43.1579 -                char ai = a[i];
 43.1580 -                int j;
 43.1581 -                for (j = i - 1; j >= left && ai < a[j]; j--) {
 43.1582 -                    a[j + 1] = a[j];
 43.1583 -                }
 43.1584 -                a[j + 1] = ai;
 43.1585 +    private static void countingSort(char[] a, int left, int right) {
 43.1586 +        int[] count = new int[NUM_CHAR_VALUES];
 43.1587 +
 43.1588 +        for (int i = left; i <= right; i++) {
 43.1589 +            count[a[i]]++;
 43.1590 +        }
 43.1591 +        for (int i = 0, k = left; k <= right; i++) {
 43.1592 +            while (count[i] == 0) {
 43.1593 +                i++;
 43.1594              }
 43.1595 -        } else if (right-left+1 > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
 43.1596 -            // Use counting sort on huge arrays
 43.1597 -            int[] count = new int[NUM_CHAR_VALUES];
 43.1598 +            char value = (char) i;
 43.1599 +            int s = count[i];
 43.1600  
 43.1601 -            for (int i = left; i <= right; i++) {
 43.1602 -                count[a[i]]++;
 43.1603 -            }
 43.1604 -            for (int i = 0, k = left; i < count.length && k <= right; i++) {
 43.1605 -                for (int s = count[i]; s > 0; s--) {
 43.1606 -                    a[k++] = (char) i;
 43.1607 -               }
 43.1608 -            }
 43.1609 -        } else { // Use Dual-Pivot Quicksort on large arrays
 43.1610 -            dualPivotQuicksort(a, left, right);
 43.1611 +            do {
 43.1612 +                a[k++] = value;
 43.1613 +            } while (--s > 0);
 43.1614          }
 43.1615      }
 43.1616  
 43.1617      /**
 43.1618       * Sorts the specified range of the array into ascending order by the
 43.1619 -     * Dual-Pivot Quicksort algorithm.
 43.1620 +     * Dual-Pivot Quicksort algorithm. This method differs from the public
 43.1621 +     * {@code sort} method in that the {@code right} index is inclusive,
 43.1622 +     * it does no range checking on {@code left} or {@code right}, and has
 43.1623 +     * boolean flag whether insertion sort with sentinel is used or not.
 43.1624       *
 43.1625       * @param a the array to be sorted
 43.1626       * @param left the index of the first element, inclusive, to be sorted
 43.1627       * @param right the index of the last element, inclusive, to be sorted
 43.1628 +     * @param leftmost indicates if the part is the most left in the range
 43.1629       */
 43.1630 -    private static void dualPivotQuicksort(char[] a, int left, int right) {
 43.1631 -        // Compute indices of five evenly spaced elements
 43.1632 -        int sixth = (right - left + 1) / 6;
 43.1633 -        int e1 = left  + sixth;
 43.1634 -        int e5 = right - sixth;
 43.1635 +    private static void sort(char[] a, int left, int right, boolean leftmost) {
 43.1636 +        int length = right - left + 1;
 43.1637 +
 43.1638 +        // Use insertion sort on tiny arrays
 43.1639 +        if (length < INSERTION_SORT_THRESHOLD) {
 43.1640 +            if (!leftmost) {
 43.1641 +                /*
 43.1642 +                 * Every element in adjoining part plays the role
 43.1643 +                 * of sentinel, therefore this allows us to avoid
 43.1644 +                 * the j >= left check on each iteration.
 43.1645 +                 */
 43.1646 +                for (int j, i = left + 1; i <= right; i++) {
 43.1647 +                    char ai = a[i];
 43.1648 +                    for (j = i - 1; ai < a[j]; j--) {
 43.1649 +                        // assert j >= left;
 43.1650 +                        a[j + 1] = a[j];
 43.1651 +                    }
 43.1652 +                    a[j + 1] = ai;
 43.1653 +                }
 43.1654 +            } else {
 43.1655 +                /*
 43.1656 +                 * For case of leftmost part traditional (without a sentinel)
 43.1657 +                 * insertion sort, optimized for server JVM, is used.
 43.1658 +                 */
 43.1659 +                for (int i = left, j = i; i < right; j = ++i) {
 43.1660 +                    char ai = a[i + 1];
 43.1661 +                    while (ai < a[j]) {
 43.1662 +                        a[j + 1] = a[j];
 43.1663 +                        if (j-- == left) {
 43.1664 +                            break;
 43.1665 +                        }
 43.1666 +                    }
 43.1667 +                    a[j + 1] = ai;
 43.1668 +                }
 43.1669 +            }
 43.1670 +            return;
 43.1671 +        }
 43.1672 +
 43.1673 +        // Inexpensive approximation of length / 7
 43.1674 +        int seventh = (length >>> 3) + (length >>> 6) + 1;
 43.1675 +
 43.1676 +        /*
 43.1677 +         * Sort five evenly spaced elements around (and including) the
 43.1678 +         * center element in the range. These elements will be used for
 43.1679 +         * pivot selection as described below. The choice for spacing
 43.1680 +         * these elements was empirically determined to work well on
 43.1681 +         * a wide variety of inputs.
 43.1682 +         */
 43.1683          int e3 = (left + right) >>> 1; // The midpoint
 43.1684 -        int e4 = e3 + sixth;
 43.1685 -        int e2 = e3 - sixth;
 43.1686 +        int e2 = e3 - seventh;
 43.1687 +        int e1 = e2 - seventh;
 43.1688 +        int e4 = e3 + seventh;
 43.1689 +        int e5 = e4 + seventh;
 43.1690  
 43.1691 -        // Sort these elements using a 5-element sorting network
 43.1692 -        char ae1 = a[e1], ae2 = a[e2], ae3 = a[e3], ae4 = a[e4], ae5 = a[e5];
 43.1693 +        // Sort these elements using insertion sort
 43.1694 +        if (a[e2] < a[e1]) { char t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 43.1695  
 43.1696 -        if (ae1 > ae2) { char t = ae1; ae1 = ae2; ae2 = t; }
 43.1697 -        if (ae4 > ae5) { char t = ae4; ae4 = ae5; ae5 = t; }
 43.1698 -        if (ae1 > ae3) { char t = ae1; ae1 = ae3; ae3 = t; }
 43.1699 -        if (ae2 > ae3) { char t = ae2; ae2 = ae3; ae3 = t; }
 43.1700 -        if (ae1 > ae4) { char t = ae1; ae1 = ae4; ae4 = t; }
 43.1701 -        if (ae3 > ae4) { char t = ae3; ae3 = ae4; ae4 = t; }
 43.1702 -        if (ae2 > ae5) { char t = ae2; ae2 = ae5; ae5 = t; }
 43.1703 -        if (ae2 > ae3) { char t = ae2; ae2 = ae3; ae3 = t; }
 43.1704 -        if (ae4 > ae5) { char t = ae4; ae4 = ae5; ae5 = t; }
 43.1705 -
 43.1706 -        a[e1] = ae1; a[e3] = ae3; a[e5] = ae5;
 43.1707 +        if (a[e3] < a[e2]) { char t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 43.1708 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.1709 +        }
 43.1710 +        if (a[e4] < a[e3]) { char t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 43.1711 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 43.1712 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.1713 +            }
 43.1714 +        }
 43.1715 +        if (a[e5] < a[e4]) { char t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 43.1716 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 43.1717 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 43.1718 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.1719 +                }
 43.1720 +            }
 43.1721 +        }
 43.1722  
 43.1723          /*
 43.1724           * Use the second and fourth of the five sorted elements as pivots.
 43.1725           * These values are inexpensive approximations of the first and
 43.1726           * second terciles of the array. Note that pivot1 <= pivot2.
 43.1727 -         *
 43.1728 -         * The pivots are stored in local variables, and the first and
 43.1729 -         * the last of the elements to be sorted are moved to the locations
 43.1730 -         * formerly occupied by the pivots. When partitioning is complete,
 43.1731 -         * the pivots are swapped back into their final positions, and
 43.1732 -         * excluded from subsequent sorting.
 43.1733           */
 43.1734 -        char pivot1 = ae2; a[e2] = a[left];
 43.1735 -        char pivot2 = ae4; a[e4] = a[right];
 43.1736 +        char pivot1 = a[e2];
 43.1737 +        char pivot2 = a[e4];
 43.1738  
 43.1739          // Pointers
 43.1740 -        int less  = left  + 1; // The index of first element of center part
 43.1741 -        int great = right - 1; // The index before first element of right part
 43.1742 +        int less  = left;  // The index of the first element of center part
 43.1743 +        int great = right; // The index before the first element of right part
 43.1744  
 43.1745 -        boolean pivotsDiffer = (pivot1 != pivot2);
 43.1746 +        if (pivot1 != pivot2) {
 43.1747 +            /*
 43.1748 +             * The first and the last elements to be sorted are moved to the
 43.1749 +             * locations formerly occupied by the pivots. When partitioning
 43.1750 +             * is complete, the pivots are swapped back into their final
 43.1751 +             * positions, and excluded from subsequent sorting.
 43.1752 +             */
 43.1753 +            a[e2] = a[left];
 43.1754 +            a[e4] = a[right];
 43.1755  
 43.1756 -        if (pivotsDiffer) {
 43.1757 +            /*
 43.1758 +             * Skip elements, which are less or greater than pivot values.
 43.1759 +             */
 43.1760 +            while (a[++less] < pivot1);
 43.1761 +            while (a[--great] > pivot2);
 43.1762 +
 43.1763              /*
 43.1764               * Partitioning:
 43.1765               *
 43.1766 -             *   left part         center part                    right part
 43.1767 -             * +------------------------------------------------------------+
 43.1768 -             * | < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2 |
 43.1769 -             * +------------------------------------------------------------+
 43.1770 -             *              ^                          ^       ^
 43.1771 -             *              |                          |       |
 43.1772 -             *             less                        k     great
 43.1773 +             *   left part           center part                   right part
 43.1774 +             * +--------------------------------------------------------------+
 43.1775 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 43.1776 +             * +--------------------------------------------------------------+
 43.1777 +             *               ^                          ^       ^
 43.1778 +             *               |                          |       |
 43.1779 +             *              less                        k     great
 43.1780               *
 43.1781               * Invariants:
 43.1782               *
 43.1783 @@ -1060,16 +1298,14 @@
 43.1784               *    pivot1 <= all in [less, k)     <= pivot2
 43.1785               *              all in (great, right) > pivot2
 43.1786               *
 43.1787 -             * Pointer k is the first index of ?-part
 43.1788 +             * Pointer k is the first index of ?-part.
 43.1789               */
 43.1790              outer:
 43.1791              for (int k = less; k <= great; k++) {
 43.1792                  char ak = a[k];
 43.1793                  if (ak < pivot1) { // Move a[k] to left part
 43.1794 -                    if (k != less) {
 43.1795 -                        a[k] = a[less];
 43.1796 -                        a[less] = ak;
 43.1797 -                    }
 43.1798 +                    a[k] = a[less];
 43.1799 +                    a[less] = ak;
 43.1800                      less++;
 43.1801                  } else if (ak > pivot2) { // Move a[k] to right part
 43.1802                      while (a[great] > pivot2) {
 43.1803 @@ -1079,26 +1315,107 @@
 43.1804                      }
 43.1805                      if (a[great] < pivot1) {
 43.1806                          a[k] = a[less];
 43.1807 -                        a[less++] = a[great];
 43.1808 -                        a[great--] = ak;
 43.1809 +                        a[less] = a[great];
 43.1810 +                        less++;
 43.1811                      } else { // pivot1 <= a[great] <= pivot2
 43.1812                          a[k] = a[great];
 43.1813 -                        a[great--] = ak;
 43.1814 +                    }
 43.1815 +                    a[great] = ak;
 43.1816 +                    great--;
 43.1817 +                }
 43.1818 +            }
 43.1819 +
 43.1820 +            // Swap pivots into their final positions
 43.1821 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 43.1822 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
 43.1823 +
 43.1824 +            // Sort left and right parts recursively, excluding known pivots
 43.1825 +            sort(a, left, less - 2, leftmost);
 43.1826 +            sort(a, great + 2, right, false);
 43.1827 +
 43.1828 +            /*
 43.1829 +             * If center part is too large (comprises > 5/7 of the array),
 43.1830 +             * swap internal pivot values to ends.
 43.1831 +             */
 43.1832 +            if (less < e1 && e5 < great) {
 43.1833 +                /*
 43.1834 +                 * Skip elements, which are equal to pivot values.
 43.1835 +                 */
 43.1836 +                while (a[less] == pivot1) {
 43.1837 +                    less++;
 43.1838 +                }
 43.1839 +                while (a[great] == pivot2) {
 43.1840 +                    great--;
 43.1841 +                }
 43.1842 +
 43.1843 +                /*
 43.1844 +                 * Partitioning:
 43.1845 +                 *
 43.1846 +                 *   left part         center part                  right part
 43.1847 +                 * +----------------------------------------------------------+
 43.1848 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 43.1849 +                 * +----------------------------------------------------------+
 43.1850 +                 *              ^                        ^       ^
 43.1851 +                 *              |                        |       |
 43.1852 +                 *             less                      k     great
 43.1853 +                 *
 43.1854 +                 * Invariants:
 43.1855 +                 *
 43.1856 +                 *              all in (*,  less) == pivot1
 43.1857 +                 *     pivot1 < all in [less,  k)  < pivot2
 43.1858 +                 *              all in (great, *) == pivot2
 43.1859 +                 *
 43.1860 +                 * Pointer k is the first index of ?-part.
 43.1861 +                 */
 43.1862 +                outer:
 43.1863 +                for (int k = less; k <= great; k++) {
 43.1864 +                    char ak = a[k];
 43.1865 +                    if (ak == pivot1) { // Move a[k] to left part
 43.1866 +                        a[k] = a[less];
 43.1867 +                        a[less] = ak;
 43.1868 +                        less++;
 43.1869 +                    } else if (ak == pivot2) { // Move a[k] to right part
 43.1870 +                        while (a[great] == pivot2) {
 43.1871 +                            if (great-- == k) {
 43.1872 +                                break outer;
 43.1873 +                            }
 43.1874 +                        }
 43.1875 +                        if (a[great] == pivot1) {
 43.1876 +                            a[k] = a[less];
 43.1877 +                            /*
 43.1878 +                             * Even though a[great] equals to pivot1, the
 43.1879 +                             * assignment a[less] = pivot1 may be incorrect,
 43.1880 +                             * if a[great] and pivot1 are floating-point zeros
 43.1881 +                             * of different signs. Therefore in float and
 43.1882 +                             * double sorting methods we have to use more
 43.1883 +                             * accurate assignment a[less] = a[great].
 43.1884 +                             */
 43.1885 +                            a[less] = pivot1;
 43.1886 +                            less++;
 43.1887 +                        } else { // pivot1 < a[great] < pivot2
 43.1888 +                            a[k] = a[great];
 43.1889 +                        }
 43.1890 +                        a[great] = ak;
 43.1891 +                        great--;
 43.1892                      }
 43.1893                  }
 43.1894              }
 43.1895 +
 43.1896 +            // Sort center part recursively
 43.1897 +            sort(a, less, great, false);
 43.1898 +
 43.1899          } else { // Pivots are equal
 43.1900              /*
 43.1901 -             * Partition degenerates to the traditional 3-way,
 43.1902 -             * or "Dutch National Flag", partition:
 43.1903 +             * Partition degenerates to the traditional 3-way
 43.1904 +             * (or "Dutch National Flag") schema:
 43.1905               *
 43.1906 -             *   left part   center part            right part
 43.1907 -             * +----------------------------------------------+
 43.1908 -             * |  < pivot  |  == pivot  |    ?    |  > pivot  |
 43.1909 -             * +----------------------------------------------+
 43.1910 -             *              ^            ^       ^
 43.1911 -             *              |            |       |
 43.1912 -             *             less          k     great
 43.1913 +             *   left part    center part              right part
 43.1914 +             * +-------------------------------------------------+
 43.1915 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 43.1916 +             * +-------------------------------------------------+
 43.1917 +             *              ^              ^        ^
 43.1918 +             *              |              |        |
 43.1919 +             *             less            k      great
 43.1920               *
 43.1921               * Invariants:
 43.1922               *
 43.1923 @@ -1106,20 +1423,19 @@
 43.1924               *   all in [less, k)     == pivot
 43.1925               *   all in (great, right) > pivot
 43.1926               *
 43.1927 -             * Pointer k is the first index of ?-part
 43.1928 +             * Pointer k is the first index of ?-part.
 43.1929               */
 43.1930 -            for (int k = less; k <= great; k++) {
 43.1931 -                char ak = a[k];
 43.1932 -                if (ak == pivot1) {
 43.1933 +            for (int k = left; k <= great; k++) {
 43.1934 +                if (a[k] == pivot1) {
 43.1935                      continue;
 43.1936                  }
 43.1937 +                char ak = a[k];
 43.1938 +
 43.1939                  if (ak < pivot1) { // Move a[k] to left part
 43.1940 -                    if (k != less) {
 43.1941 -                        a[k] = a[less];
 43.1942 -                        a[less] = ak;
 43.1943 -                    }
 43.1944 +                    a[k] = a[less];
 43.1945 +                    a[less] = ak;
 43.1946                      less++;
 43.1947 -                } else { // (a[k] > pivot1) - Move a[k] to right part
 43.1948 +                } else { // a[k] > pivot1 - Move a[k] to right part
 43.1949                      /*
 43.1950                       * We know that pivot1 == a[e3] == pivot2. Thus, we know
 43.1951                       * that great will still be >= k when the following loop
 43.1952 @@ -1127,92 +1443,33 @@
 43.1953                       * In other words, a[e3] acts as a sentinel for great.
 43.1954                       */
 43.1955                      while (a[great] > pivot1) {
 43.1956 +                        // assert great > k;
 43.1957                          great--;
 43.1958                      }
 43.1959                      if (a[great] < pivot1) {
 43.1960                          a[k] = a[less];
 43.1961 -                        a[less++] = a[great];
 43.1962 -                        a[great--] = ak;
 43.1963 +                        a[less] = a[great];
 43.1964 +                        less++;
 43.1965                      } else { // a[great] == pivot1
 43.1966 +                        /*
 43.1967 +                         * Even though a[great] equals to pivot1, the
 43.1968 +                         * assignment a[k] = pivot1 may be incorrect,
 43.1969 +                         * if a[great] and pivot1 are floating-point
 43.1970 +                         * zeros of different signs. Therefore in float
 43.1971 +                         * and double sorting methods we have to use
 43.1972 +                         * more accurate assignment a[k] = a[great].
 43.1973 +                         */
 43.1974                          a[k] = pivot1;
 43.1975 -                        a[great--] = ak;
 43.1976                      }
 43.1977 +                    a[great] = ak;
 43.1978 +                    great--;
 43.1979                  }
 43.1980              }
 43.1981 +
 43.1982 +            // Sort left and right parts recursively
 43.1983 +            sort(a, left, less - 1, leftmost);
 43.1984 +            sort(a, great + 1, right, false);
 43.1985          }
 43.1986 -
 43.1987 -        // Swap pivots into their final positions
 43.1988 -        a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 43.1989 -        a[right] = a[great + 1]; a[great + 1] = pivot2;
 43.1990 -
 43.1991 -        // Sort left and right parts recursively, excluding known pivot values
 43.1992 -        doSort(a, left,   less - 2);
 43.1993 -        doSort(a, great + 2, right);
 43.1994 -
 43.1995 -        /*
 43.1996 -         * If pivot1 == pivot2, all elements from center
 43.1997 -         * part are equal and, therefore, already sorted
 43.1998 -         */
 43.1999 -        if (!pivotsDiffer) {
 43.2000 -            return;
 43.2001 -        }
 43.2002 -
 43.2003 -        /*
 43.2004 -         * If center part is too large (comprises > 2/3 of the array),
 43.2005 -         * swap internal pivot values to ends
 43.2006 -         */
 43.2007 -        if (less < e1 && great > e5) {
 43.2008 -            while (a[less] == pivot1) {
 43.2009 -                less++;
 43.2010 -            }
 43.2011 -            while (a[great] == pivot2) {
 43.2012 -                great--;
 43.2013 -            }
 43.2014 -
 43.2015 -            /*
 43.2016 -             * Partitioning:
 43.2017 -             *
 43.2018 -             *   left part       center part                   right part
 43.2019 -             * +----------------------------------------------------------+
 43.2020 -             * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 43.2021 -             * +----------------------------------------------------------+
 43.2022 -             *              ^                        ^       ^
 43.2023 -             *              |                        |       |
 43.2024 -             *             less                      k     great
 43.2025 -             *
 43.2026 -             * Invariants:
 43.2027 -             *
 43.2028 -             *              all in (*, less)  == pivot1
 43.2029 -             *     pivot1 < all in [less, k)   < pivot2
 43.2030 -             *              all in (great, *) == pivot2
 43.2031 -             *
 43.2032 -             * Pointer k is the first index of ?-part
 43.2033 -             */
 43.2034 -            outer:
 43.2035 -            for (int k = less; k <= great; k++) {
 43.2036 -                char ak = a[k];
 43.2037 -                if (ak == pivot2) { // Move a[k] to right part
 43.2038 -                    while (a[great] == pivot2) {
 43.2039 -                        if (great-- == k) {
 43.2040 -                            break outer;
 43.2041 -                        }
 43.2042 -                    }
 43.2043 -                    if (a[great] == pivot1) {
 43.2044 -                        a[k] = a[less];
 43.2045 -                        a[less++] = pivot1;
 43.2046 -                    } else { // pivot1 < a[great] < pivot2
 43.2047 -                        a[k] = a[great];
 43.2048 -                    }
 43.2049 -                    a[great--] = pivot2;
 43.2050 -                } else if (ak == pivot1) { // Move a[k] to left part
 43.2051 -                    a[k] = a[less];
 43.2052 -                    a[less++] = pivot1;
 43.2053 -                }
 43.2054 -            }
 43.2055 -        }
 43.2056 -
 43.2057 -        // Sort center part recursively, excluding known pivot values
 43.2058 -        doSort(a, less, great);
 43.2059      }
 43.2060  
 43.2061      /**
 43.2062 @@ -1221,7 +1478,11 @@
 43.2063       * @param a the array to be sorted
 43.2064       */
 43.2065      public static void sort(byte[] a) {
 43.2066 -        doSort(a, 0, a.length - 1);
 43.2067 +        if (a.length > COUNTING_SORT_THRESHOLD_FOR_BYTE) {
 43.2068 +            countingSort(a, 0, a.length - 1);
 43.2069 +        } else {
 43.2070 +            sort(a, 0, a.length - 1, true);
 43.2071 +        }
 43.2072      }
 43.2073  
 43.2074      /**
 43.2075 @@ -1239,115 +1500,166 @@
 43.2076       */
 43.2077      public static void sort(byte[] a, int fromIndex, int toIndex) {
 43.2078          rangeCheck(a.length, fromIndex, toIndex);
 43.2079 -        doSort(a, fromIndex, toIndex - 1);
 43.2080 +
 43.2081 +        if (toIndex - fromIndex > COUNTING_SORT_THRESHOLD_FOR_BYTE) {
 43.2082 +            countingSort(a, fromIndex, toIndex - 1);
 43.2083 +        } else {
 43.2084 +            sort(a, fromIndex, toIndex - 1, true);
 43.2085 +        }
 43.2086      }
 43.2087  
 43.2088      /** The number of distinct byte values. */
 43.2089      private static final int NUM_BYTE_VALUES = 1 << 8;
 43.2090  
 43.2091      /**
 43.2092 -     * Sorts the specified range of the array into ascending order. This
 43.2093 -     * method differs from the public {@code sort} method in that the
 43.2094 -     * {@code right} index is inclusive, and it does no range checking on
 43.2095 -     * {@code left} or {@code right}.
 43.2096 +     * Sorts the specified range of the array by counting sort.
 43.2097       *
 43.2098       * @param a the array to be sorted
 43.2099       * @param left the index of the first element, inclusive, to be sorted
 43.2100       * @param right the index of the last element, inclusive, to be sorted
 43.2101       */
 43.2102 -    private static void doSort(byte[] a, int left, int right) {
 43.2103 -        // Use insertion sort on tiny arrays
 43.2104 -        if (right - left + 1 < INSERTION_SORT_THRESHOLD) {
 43.2105 -            for (int i = left + 1; i <= right; i++) {
 43.2106 -                byte ai = a[i];
 43.2107 -                int j;
 43.2108 -                for (j = i - 1; j >= left && ai < a[j]; j--) {
 43.2109 -                    a[j + 1] = a[j];
 43.2110 -                }
 43.2111 -                a[j + 1] = ai;
 43.2112 +    private static void countingSort(byte[] a, int left, int right) {
 43.2113 +        int[] count = new int[NUM_BYTE_VALUES];
 43.2114 +
 43.2115 +        for (int i = left; i <= right; i++) {
 43.2116 +            count[a[i] - Byte.MIN_VALUE]++;
 43.2117 +        }
 43.2118 +        for (int i = NUM_BYTE_VALUES - 1, k = right; k >= left; i--) {
 43.2119 +            while (count[i] == 0) {
 43.2120 +                i--;
 43.2121              }
 43.2122 -        } else if (right - left + 1 > COUNTING_SORT_THRESHOLD_FOR_BYTE) {
 43.2123 -            // Use counting sort on huge arrays
 43.2124 -            int[] count = new int[NUM_BYTE_VALUES];
 43.2125 +            byte value = (byte) (i + Byte.MIN_VALUE);
 43.2126 +            int s = count[i];
 43.2127  
 43.2128 -            for (int i = left; i <= right; i++) {
 43.2129 -                count[a[i] - Byte.MIN_VALUE]++;
 43.2130 -            }
 43.2131 -            for (int i = 0, k = left; i < count.length && k <= right; i++) {
 43.2132 -                byte value = (byte) (i + Byte.MIN_VALUE);
 43.2133 -
 43.2134 -                for (int s = count[i]; s > 0; s--) {
 43.2135 -                    a[k++] = value;
 43.2136 -               }
 43.2137 -            }
 43.2138 -        } else { // Use Dual-Pivot Quicksort on large arrays
 43.2139 -            dualPivotQuicksort(a, left, right);
 43.2140 +            do {
 43.2141 +                a[k--] = value;
 43.2142 +            } while (--s > 0);
 43.2143          }
 43.2144      }
 43.2145  
 43.2146      /**
 43.2147       * Sorts the specified range of the array into ascending order by the
 43.2148 -     * Dual-Pivot Quicksort algorithm.
 43.2149 +     * Dual-Pivot Quicksort algorithm. This method differs from the public
 43.2150 +     * {@code sort} method in that the {@code right} index is inclusive,
 43.2151 +     * it does no range checking on {@code left} or {@code right}, and has
 43.2152 +     * boolean flag whether insertion sort with sentinel is used or not.
 43.2153       *
 43.2154       * @param a the array to be sorted
 43.2155       * @param left the index of the first element, inclusive, to be sorted
 43.2156       * @param right the index of the last element, inclusive, to be sorted
 43.2157 +     * @param leftmost indicates if the part is the most left in the range
 43.2158       */
 43.2159 -    private static void dualPivotQuicksort(byte[] a, int left, int right) {
 43.2160 -        // Compute indices of five evenly spaced elements
 43.2161 -        int sixth = (right - left + 1) / 6;
 43.2162 -        int e1 = left  + sixth;
 43.2163 -        int e5 = right - sixth;
 43.2164 +    private static void sort(byte[] a, int left, int right, boolean leftmost) {
 43.2165 +        int length = right - left + 1;
 43.2166 +
 43.2167 +        // Use insertion sort on tiny arrays
 43.2168 +        if (length < INSERTION_SORT_THRESHOLD) {
 43.2169 +            if (!leftmost) {
 43.2170 +                /*
 43.2171 +                 * Every element in adjoining part plays the role
 43.2172 +                 * of sentinel, therefore this allows us to avoid
 43.2173 +                 * the j >= left check on each iteration.
 43.2174 +                 */
 43.2175 +                for (int j, i = left + 1; i <= right; i++) {
 43.2176 +                    byte ai = a[i];
 43.2177 +                    for (j = i - 1; ai < a[j]; j--) {
 43.2178 +                        // assert j >= left;
 43.2179 +                        a[j + 1] = a[j];
 43.2180 +                    }
 43.2181 +                    a[j + 1] = ai;
 43.2182 +                }
 43.2183 +            } else {
 43.2184 +                /*
 43.2185 +                 * For case of leftmost part traditional (without a sentinel)
 43.2186 +                 * insertion sort, optimized for server JVM, is used.
 43.2187 +                 */
 43.2188 +                for (int i = left, j = i; i < right; j = ++i) {
 43.2189 +                    byte ai = a[i + 1];
 43.2190 +                    while (ai < a[j]) {
 43.2191 +                        a[j + 1] = a[j];
 43.2192 +                        if (j-- == left) {
 43.2193 +                            break;
 43.2194 +                        }
 43.2195 +                    }
 43.2196 +                    a[j + 1] = ai;
 43.2197 +                }
 43.2198 +            }
 43.2199 +            return;
 43.2200 +        }
 43.2201 +
 43.2202 +        // Inexpensive approximation of length / 7
 43.2203 +        int seventh = (length >>> 3) + (length >>> 6) + 1;
 43.2204 +
 43.2205 +        /*
 43.2206 +         * Sort five evenly spaced elements around (and including) the
 43.2207 +         * center element in the range. These elements will be used for
 43.2208 +         * pivot selection as described below. The choice for spacing
 43.2209 +         * these elements was empirically determined to work well on
 43.2210 +         * a wide variety of inputs.
 43.2211 +         */
 43.2212          int e3 = (left + right) >>> 1; // The midpoint
 43.2213 -        int e4 = e3 + sixth;
 43.2214 -        int e2 = e3 - sixth;
 43.2215 +        int e2 = e3 - seventh;
 43.2216 +        int e1 = e2 - seventh;
 43.2217 +        int e4 = e3 + seventh;
 43.2218 +        int e5 = e4 + seventh;
 43.2219  
 43.2220 -        // Sort these elements using a 5-element sorting network
 43.2221 -        byte ae1 = a[e1], ae2 = a[e2], ae3 = a[e3], ae4 = a[e4], ae5 = a[e5];
 43.2222 +        // Sort these elements using insertion sort
 43.2223 +        if (a[e2] < a[e1]) { byte t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 43.2224  
 43.2225 -        if (ae1 > ae2) { byte t = ae1; ae1 = ae2; ae2 = t; }
 43.2226 -        if (ae4 > ae5) { byte t = ae4; ae4 = ae5; ae5 = t; }
 43.2227 -        if (ae1 > ae3) { byte t = ae1; ae1 = ae3; ae3 = t; }
 43.2228 -        if (ae2 > ae3) { byte t = ae2; ae2 = ae3; ae3 = t; }
 43.2229 -        if (ae1 > ae4) { byte t = ae1; ae1 = ae4; ae4 = t; }
 43.2230 -        if (ae3 > ae4) { byte t = ae3; ae3 = ae4; ae4 = t; }
 43.2231 -        if (ae2 > ae5) { byte t = ae2; ae2 = ae5; ae5 = t; }
 43.2232 -        if (ae2 > ae3) { byte t = ae2; ae2 = ae3; ae3 = t; }
 43.2233 -        if (ae4 > ae5) { byte t = ae4; ae4 = ae5; ae5 = t; }
 43.2234 -
 43.2235 -        a[e1] = ae1; a[e3] = ae3; a[e5] = ae5;
 43.2236 +        if (a[e3] < a[e2]) { byte t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 43.2237 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.2238 +        }
 43.2239 +        if (a[e4] < a[e3]) { byte t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 43.2240 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 43.2241 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.2242 +            }
 43.2243 +        }
 43.2244 +        if (a[e5] < a[e4]) { byte t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 43.2245 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 43.2246 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 43.2247 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.2248 +                }
 43.2249 +            }
 43.2250 +        }
 43.2251  
 43.2252          /*
 43.2253           * Use the second and fourth of the five sorted elements as pivots.
 43.2254           * These values are inexpensive approximations of the first and
 43.2255           * second terciles of the array. Note that pivot1 <= pivot2.
 43.2256 -         *
 43.2257 -         * The pivots are stored in local variables, and the first and
 43.2258 -         * the last of the elements to be sorted are moved to the locations
 43.2259 -         * formerly occupied by the pivots. When partitioning is complete,
 43.2260 -         * the pivots are swapped back into their final positions, and
 43.2261 -         * excluded from subsequent sorting.
 43.2262           */
 43.2263 -        byte pivot1 = ae2; a[e2] = a[left];
 43.2264 -        byte pivot2 = ae4; a[e4] = a[right];
 43.2265 +        byte pivot1 = a[e2];
 43.2266 +        byte pivot2 = a[e4];
 43.2267  
 43.2268          // Pointers
 43.2269 -        int less  = left  + 1; // The index of first element of center part
 43.2270 -        int great = right - 1; // The index before first element of right part
 43.2271 +        int less  = left;  // The index of the first element of center part
 43.2272 +        int great = right; // The index before the first element of right part
 43.2273  
 43.2274 -        boolean pivotsDiffer = (pivot1 != pivot2);
 43.2275 +        if (pivot1 != pivot2) {
 43.2276 +            /*
 43.2277 +             * The first and the last elements to be sorted are moved to the
 43.2278 +             * locations formerly occupied by the pivots. When partitioning
 43.2279 +             * is complete, the pivots are swapped back into their final
 43.2280 +             * positions, and excluded from subsequent sorting.
 43.2281 +             */
 43.2282 +            a[e2] = a[left];
 43.2283 +            a[e4] = a[right];
 43.2284  
 43.2285 -        if (pivotsDiffer) {
 43.2286 +            /*
 43.2287 +             * Skip elements, which are less or greater than pivot values.
 43.2288 +             */
 43.2289 +            while (a[++less] < pivot1);
 43.2290 +            while (a[--great] > pivot2);
 43.2291 +
 43.2292              /*
 43.2293               * Partitioning:
 43.2294               *
 43.2295 -             *   left part         center part                    right part
 43.2296 -             * +------------------------------------------------------------+
 43.2297 -             * | < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2 |
 43.2298 -             * +------------------------------------------------------------+
 43.2299 -             *              ^                          ^       ^
 43.2300 -             *              |                          |       |
 43.2301 -             *             less                        k     great
 43.2302 +             *   left part           center part                   right part
 43.2303 +             * +--------------------------------------------------------------+
 43.2304 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 43.2305 +             * +--------------------------------------------------------------+
 43.2306 +             *               ^                          ^       ^
 43.2307 +             *               |                          |       |
 43.2308 +             *              less                        k     great
 43.2309               *
 43.2310               * Invariants:
 43.2311               *
 43.2312 @@ -1355,16 +1667,14 @@
 43.2313               *    pivot1 <= all in [less, k)     <= pivot2
 43.2314               *              all in (great, right) > pivot2
 43.2315               *
 43.2316 -             * Pointer k is the first index of ?-part
 43.2317 +             * Pointer k is the first index of ?-part.
 43.2318               */
 43.2319              outer:
 43.2320              for (int k = less; k <= great; k++) {
 43.2321                  byte ak = a[k];
 43.2322                  if (ak < pivot1) { // Move a[k] to left part
 43.2323 -                    if (k != less) {
 43.2324 -                        a[k] = a[less];
 43.2325 -                        a[less] = ak;
 43.2326 -                    }
 43.2327 +                    a[k] = a[less];
 43.2328 +                    a[less] = ak;
 43.2329                      less++;
 43.2330                  } else if (ak > pivot2) { // Move a[k] to right part
 43.2331                      while (a[great] > pivot2) {
 43.2332 @@ -1374,26 +1684,107 @@
 43.2333                      }
 43.2334                      if (a[great] < pivot1) {
 43.2335                          a[k] = a[less];
 43.2336 -                        a[less++] = a[great];
 43.2337 -                        a[great--] = ak;
 43.2338 +                        a[less] = a[great];
 43.2339 +                        less++;
 43.2340                      } else { // pivot1 <= a[great] <= pivot2
 43.2341                          a[k] = a[great];
 43.2342 -                        a[great--] = ak;
 43.2343 +                    }
 43.2344 +                    a[great] = ak;
 43.2345 +                    great--;
 43.2346 +                }
 43.2347 +            }
 43.2348 +
 43.2349 +            // Swap pivots into their final positions
 43.2350 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 43.2351 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
 43.2352 +
 43.2353 +            // Sort left and right parts recursively, excluding known pivots
 43.2354 +            sort(a, left, less - 2, leftmost);
 43.2355 +            sort(a, great + 2, right, false);
 43.2356 +
 43.2357 +            /*
 43.2358 +             * If center part is too large (comprises > 5/7 of the array),
 43.2359 +             * swap internal pivot values to ends.
 43.2360 +             */
 43.2361 +            if (less < e1 && e5 < great) {
 43.2362 +                /*
 43.2363 +                 * Skip elements, which are equal to pivot values.
 43.2364 +                 */
 43.2365 +                while (a[less] == pivot1) {
 43.2366 +                    less++;
 43.2367 +                }
 43.2368 +                while (a[great] == pivot2) {
 43.2369 +                    great--;
 43.2370 +                }
 43.2371 +
 43.2372 +                /*
 43.2373 +                 * Partitioning:
 43.2374 +                 *
 43.2375 +                 *   left part         center part                  right part
 43.2376 +                 * +----------------------------------------------------------+
 43.2377 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 43.2378 +                 * +----------------------------------------------------------+
 43.2379 +                 *              ^                        ^       ^
 43.2380 +                 *              |                        |       |
 43.2381 +                 *             less                      k     great
 43.2382 +                 *
 43.2383 +                 * Invariants:
 43.2384 +                 *
 43.2385 +                 *              all in (*,  less) == pivot1
 43.2386 +                 *     pivot1 < all in [less,  k)  < pivot2
 43.2387 +                 *              all in (great, *) == pivot2
 43.2388 +                 *
 43.2389 +                 * Pointer k is the first index of ?-part.
 43.2390 +                 */
 43.2391 +                outer:
 43.2392 +                for (int k = less; k <= great; k++) {
 43.2393 +                    byte ak = a[k];
 43.2394 +                    if (ak == pivot1) { // Move a[k] to left part
 43.2395 +                        a[k] = a[less];
 43.2396 +                        a[less] = ak;
 43.2397 +                        less++;
 43.2398 +                    } else if (ak == pivot2) { // Move a[k] to right part
 43.2399 +                        while (a[great] == pivot2) {
 43.2400 +                            if (great-- == k) {
 43.2401 +                                break outer;
 43.2402 +                            }
 43.2403 +                        }
 43.2404 +                        if (a[great] == pivot1) {
 43.2405 +                            a[k] = a[less];
 43.2406 +                            /*
 43.2407 +                             * Even though a[great] equals to pivot1, the
 43.2408 +                             * assignment a[less] = pivot1 may be incorrect,
 43.2409 +                             * if a[great] and pivot1 are floating-point zeros
 43.2410 +                             * of different signs. Therefore in float and
 43.2411 +                             * double sorting methods we have to use more
 43.2412 +                             * accurate assignment a[less] = a[great].
 43.2413 +                             */
 43.2414 +                            a[less] = pivot1;
 43.2415 +                            less++;
 43.2416 +                        } else { // pivot1 < a[great] < pivot2
 43.2417 +                            a[k] = a[great];
 43.2418 +                        }
 43.2419 +                        a[great] = ak;
 43.2420 +                        great--;
 43.2421                      }
 43.2422                  }
 43.2423              }
 43.2424 +
 43.2425 +            // Sort center part recursively
 43.2426 +            sort(a, less, great, false);
 43.2427 +
 43.2428          } else { // Pivots are equal
 43.2429              /*
 43.2430 -             * Partition degenerates to the traditional 3-way,
 43.2431 -             * or "Dutch National Flag", partition:
 43.2432 +             * Partition degenerates to the traditional 3-way
 43.2433 +             * (or "Dutch National Flag") schema:
 43.2434               *
 43.2435 -             *   left part   center part            right part
 43.2436 -             * +----------------------------------------------+
 43.2437 -             * |  < pivot  |  == pivot  |    ?    |  > pivot  |
 43.2438 -             * +----------------------------------------------+
 43.2439 -             *              ^            ^       ^
 43.2440 -             *              |            |       |
 43.2441 -             *             less          k     great
 43.2442 +             *   left part    center part              right part
 43.2443 +             * +-------------------------------------------------+
 43.2444 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 43.2445 +             * +-------------------------------------------------+
 43.2446 +             *              ^              ^        ^
 43.2447 +             *              |              |        |
 43.2448 +             *             less            k      great
 43.2449               *
 43.2450               * Invariants:
 43.2451               *
 43.2452 @@ -1401,20 +1792,19 @@
 43.2453               *   all in [less, k)     == pivot
 43.2454               *   all in (great, right) > pivot
 43.2455               *
 43.2456 -             * Pointer k is the first index of ?-part
 43.2457 +             * Pointer k is the first index of ?-part.
 43.2458               */
 43.2459 -            for (int k = less; k <= great; k++) {
 43.2460 -                byte ak = a[k];
 43.2461 -                if (ak == pivot1) {
 43.2462 +            for (int k = left; k <= great; k++) {
 43.2463 +                if (a[k] == pivot1) {
 43.2464                      continue;
 43.2465                  }
 43.2466 +                byte ak = a[k];
 43.2467 +
 43.2468                  if (ak < pivot1) { // Move a[k] to left part
 43.2469 -                    if (k != less) {
 43.2470 -                        a[k] = a[less];
 43.2471 -                        a[less] = ak;
 43.2472 -                    }
 43.2473 +                    a[k] = a[less];
 43.2474 +                    a[less] = ak;
 43.2475                      less++;
 43.2476 -                } else { // (a[k] > pivot1) - Move a[k] to right part
 43.2477 +                } else { // a[k] > pivot1 - Move a[k] to right part
 43.2478                      /*
 43.2479                       * We know that pivot1 == a[e3] == pivot2. Thus, we know
 43.2480                       * that great will still be >= k when the following loop
 43.2481 @@ -1422,92 +1812,33 @@
 43.2482                       * In other words, a[e3] acts as a sentinel for great.
 43.2483                       */
 43.2484                      while (a[great] > pivot1) {
 43.2485 +                        // assert great > k;
 43.2486                          great--;
 43.2487                      }
 43.2488                      if (a[great] < pivot1) {
 43.2489                          a[k] = a[less];
 43.2490 -                        a[less++] = a[great];
 43.2491 -                        a[great--] = ak;
 43.2492 +                        a[less] = a[great];
 43.2493 +                        less++;
 43.2494                      } else { // a[great] == pivot1
 43.2495 +                        /*
 43.2496 +                         * Even though a[great] equals to pivot1, the
 43.2497 +                         * assignment a[k] = pivot1 may be incorrect,
 43.2498 +                         * if a[great] and pivot1 are floating-point
 43.2499 +                         * zeros of different signs. Therefore in float
 43.2500 +                         * and double sorting methods we have to use
 43.2501 +                         * more accurate assignment a[k] = a[great].
 43.2502 +                         */
 43.2503                          a[k] = pivot1;
 43.2504 -                        a[great--] = ak;
 43.2505                      }
 43.2506 +                    a[great] = ak;
 43.2507 +                    great--;
 43.2508                  }
 43.2509              }
 43.2510 +
 43.2511 +            // Sort left and right parts recursively
 43.2512 +            sort(a, left, less - 1, leftmost);
 43.2513 +            sort(a, great + 1, right, false);
 43.2514          }
 43.2515 -
 43.2516 -        // Swap pivots into their final positions
 43.2517 -        a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 43.2518 -        a[right] = a[great + 1]; a[great + 1] = pivot2;
 43.2519 -
 43.2520 -        // Sort left and right parts recursively, excluding known pivot values
 43.2521 -        doSort(a, left,   less - 2);
 43.2522 -        doSort(a, great + 2, right);
 43.2523 -
 43.2524 -        /*
 43.2525 -         * If pivot1 == pivot2, all elements from center
 43.2526 -         * part are equal and, therefore, already sorted
 43.2527 -         */
 43.2528 -        if (!pivotsDiffer) {
 43.2529 -            return;
 43.2530 -        }
 43.2531 -
 43.2532 -        /*
 43.2533 -         * If center part is too large (comprises > 2/3 of the array),
 43.2534 -         * swap internal pivot values to ends
 43.2535 -         */
 43.2536 -        if (less < e1 && great > e5) {
 43.2537 -            while (a[less] == pivot1) {
 43.2538 -                less++;
 43.2539 -            }
 43.2540 -            while (a[great] == pivot2) {
 43.2541 -                great--;
 43.2542 -            }
 43.2543 -
 43.2544 -            /*
 43.2545 -             * Partitioning:
 43.2546 -             *
 43.2547 -             *   left part       center part                   right part
 43.2548 -             * +----------------------------------------------------------+
 43.2549 -             * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 43.2550 -             * +----------------------------------------------------------+
 43.2551 -             *              ^                        ^       ^
 43.2552 -             *              |                        |       |
 43.2553 -             *             less                      k     great
 43.2554 -             *
 43.2555 -             * Invariants:
 43.2556 -             *
 43.2557 -             *              all in (*, less)  == pivot1
 43.2558 -             *     pivot1 < all in [less, k)   < pivot2
 43.2559 -             *              all in (great, *) == pivot2
 43.2560 -             *
 43.2561 -             * Pointer k is the first index of ?-part
 43.2562 -             */
 43.2563 -            outer:
 43.2564 -            for (int k = less; k <= great; k++) {
 43.2565 -                byte ak = a[k];
 43.2566 -                if (ak == pivot2) { // Move a[k] to right part
 43.2567 -                    while (a[great] == pivot2) {
 43.2568 -                        if (great-- == k) {
 43.2569 -                            break outer;
 43.2570 -                        }
 43.2571 -                    }
 43.2572 -                    if (a[great] == pivot1) {
 43.2573 -                        a[k] = a[less];
 43.2574 -                        a[less++] = pivot1;
 43.2575 -                    } else { // pivot1 < a[great] < pivot2
 43.2576 -                        a[k] = a[great];
 43.2577 -                    }
 43.2578 -                    a[great--] = pivot2;
 43.2579 -                } else if (ak == pivot1) { // Move a[k] to left part
 43.2580 -                    a[k] = a[less];
 43.2581 -                    a[less++] = pivot1;
 43.2582 -                }
 43.2583 -            }
 43.2584 -        }
 43.2585 -
 43.2586 -        // Sort center part recursively, excluding known pivot values
 43.2587 -        doSort(a, less, great);
 43.2588      }
 43.2589  
 43.2590      /**
 43.2591 @@ -1531,7 +1862,7 @@
 43.2592       * Sorts the specified range of the array into ascending order. The range
 43.2593       * to be sorted extends from the index {@code fromIndex}, inclusive, to
 43.2594       * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
 43.2595 -     * the range to be sorted is empty and the call is a no-op).
 43.2596 +     * the range to be sorted is empty (and the call is a no-op).
 43.2597       *
 43.2598       * <p>The {@code <} relation does not provide a total order on all float
 43.2599       * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
 43.2600 @@ -1565,162 +1896,207 @@
 43.2601       */
 43.2602      private static void sortNegZeroAndNaN(float[] a, int left, int right) {
 43.2603          /*
 43.2604 -         * Phase 1: Count negative zeros and move NaNs to end of array
 43.2605 +         * Phase 1: Move NaNs to the end of the array.
 43.2606           */
 43.2607 -        final int NEGATIVE_ZERO = Float.floatToIntBits(-0.0f);
 43.2608 -        int numNegativeZeros = 0;
 43.2609 -        int n = right;
 43.2610 -
 43.2611 -        for (int k = left; k <= n; k++) {
 43.2612 +        while (left <= right && Float.isNaN(a[right])) {
 43.2613 +            right--;
 43.2614 +        }
 43.2615 +        for (int k = right - 1; k >= left; k--) {
 43.2616              float ak = a[k];
 43.2617 -            if (ak == 0.0f && NEGATIVE_ZERO == Float.floatToIntBits(ak)) {
 43.2618 -                a[k] = 0.0f;
 43.2619 -                numNegativeZeros++;
 43.2620 -            } else if (ak != ak) { // i.e., ak is NaN
 43.2621 -                a[k--] = a[n];
 43.2622 -                a[n--] = Float.NaN;
 43.2623 +            if (ak != ak) { // a[k] is NaN
 43.2624 +                a[k] = a[right];
 43.2625 +                a[right] = ak;
 43.2626 +                right--;
 43.2627              }
 43.2628          }
 43.2629  
 43.2630          /*
 43.2631 -         * Phase 2: Sort everything except NaNs (which are already in place)
 43.2632 +         * Phase 2: Sort everything except NaNs (which are already in place).
 43.2633           */
 43.2634 -        doSort(a, left, n);
 43.2635 +        sort(a, left, right, true);
 43.2636  
 43.2637          /*
 43.2638 -         * Phase 3: Turn positive zeros back into negative zeros as appropriate
 43.2639 +         * Phase 3: Place negative zeros before positive zeros.
 43.2640           */
 43.2641 -        if (numNegativeZeros == 0) {
 43.2642 -            return;
 43.2643 -        }
 43.2644 +        int hi = right;
 43.2645  
 43.2646 -        // Find first zero element
 43.2647 -        int zeroIndex = findAnyZero(a, left, n);
 43.2648 -
 43.2649 -        for (int i = zeroIndex - 1; i >= left && a[i] == 0.0f; i--) {
 43.2650 -            zeroIndex = i;
 43.2651 -        }
 43.2652 -
 43.2653 -        // Turn the right number of positive zeros back into negative zeros
 43.2654 -        for (int i = zeroIndex, m = zeroIndex + numNegativeZeros; i < m; i++) {
 43.2655 -            a[i] = -0.0f;
 43.2656 -        }
 43.2657 -    }
 43.2658 -
 43.2659 -    /**
 43.2660 -     * Returns the index of some zero element in the specified range via
 43.2661 -     * binary search. The range is assumed to be sorted, and must contain
 43.2662 -     * at least one zero.
 43.2663 -     *
 43.2664 -     * @param a the array to be searched
 43.2665 -     * @param low the index of the first element, inclusive, to be searched
 43.2666 -     * @param high the index of the last element, inclusive, to be searched
 43.2667 -     */
 43.2668 -    private static int findAnyZero(float[] a, int low, int high) {
 43.2669 -        while (true) {
 43.2670 -            int middle = (low + high) >>> 1;
 43.2671 +        /*
 43.2672 +         * Search first zero, or first positive, or last negative element.
 43.2673 +         */
 43.2674 +        while (left < hi) {
 43.2675 +            int middle = (left + hi) >>> 1;
 43.2676              float middleValue = a[middle];
 43.2677  
 43.2678              if (middleValue < 0.0f) {
 43.2679 -                low = middle + 1;
 43.2680 -            } else if (middleValue > 0.0f) {
 43.2681 -                high = middle - 1;
 43.2682 -            } else { // middleValue == 0.0f
 43.2683 -                return middle;
 43.2684 +                left = middle + 1;
 43.2685 +            } else {
 43.2686 +                hi = middle;
 43.2687 +            }
 43.2688 +        }
 43.2689 +
 43.2690 +        /*
 43.2691 +         * Skip the last negative value (if any) or all leading negative zeros.
 43.2692 +         */
 43.2693 +        while (left <= right && Float.floatToRawIntBits(a[left]) < 0) {
 43.2694 +            left++;
 43.2695 +        }
 43.2696 +
 43.2697 +        /*
 43.2698 +         * Move negative zeros to the beginning of the sub-range.
 43.2699 +         *
 43.2700 +         * Partitioning:
 43.2701 +         *
 43.2702 +         * +---------------------------------------------------+
 43.2703 +         * |   < 0.0   |   -0.0   |    0.0    |  ?  ( >= 0.0 ) |
 43.2704 +         * +---------------------------------------------------+
 43.2705 +         *              ^          ^           ^
 43.2706 +         *              |          |           |
 43.2707 +         *             left        p           k
 43.2708 +         *
 43.2709 +         * Invariants:
 43.2710 +         *
 43.2711 +         *   all in (*,  left)  <  0.0
 43.2712 +         *   all in [left,  p) == -0.0
 43.2713 +         *   all in [p,     k) ==  0.0
 43.2714 +         *   all in [k, right] >=  0.0
 43.2715 +         *
 43.2716 +         * Pointer k is the first index of ?-part.
 43.2717 +         */
 43.2718 +        for (int k = left + 1, p = left; k <= right; k++) {
 43.2719 +            float ak = a[k];
 43.2720 +            if (ak != 0.0f) {
 43.2721 +                break;
 43.2722 +            }
 43.2723 +            if (Float.floatToRawIntBits(ak) < 0) { // ak is -0.0f
 43.2724 +                a[k] = 0.0f;
 43.2725 +                a[p++] = -0.0f;
 43.2726              }
 43.2727          }
 43.2728      }
 43.2729  
 43.2730      /**
 43.2731 -     * Sorts the specified range of the array into ascending order. This
 43.2732 -     * method differs from the public {@code sort} method in three ways:
 43.2733 -     * {@code right} index is inclusive, it does no range checking on
 43.2734 -     * {@code left} or {@code right}, and it does not handle negative
 43.2735 -     * zeros or NaNs in the array.
 43.2736 -     *
 43.2737 -     * @param a the array to be sorted, which must not contain -0.0f or NaN
 43.2738 -     * @param left the index of the first element, inclusive, to be sorted
 43.2739 -     * @param right the index of the last element, inclusive, to be sorted
 43.2740 -     */
 43.2741 -    private static void doSort(float[] a, int left, int right) {
 43.2742 -        // Use insertion sort on tiny arrays
 43.2743 -        if (right - left + 1 < INSERTION_SORT_THRESHOLD) {
 43.2744 -            for (int i = left + 1; i <= right; i++) {
 43.2745 -                float ai = a[i];
 43.2746 -                int j;
 43.2747 -                for (j = i - 1; j >= left && ai < a[j]; j--) {
 43.2748 -                    a[j + 1] = a[j];
 43.2749 -                }
 43.2750 -                a[j + 1] = ai;
 43.2751 -            }
 43.2752 -        } else { // Use Dual-Pivot Quicksort on large arrays
 43.2753 -            dualPivotQuicksort(a, left, right);
 43.2754 -        }
 43.2755 -    }
 43.2756 -
 43.2757 -    /**
 43.2758       * Sorts the specified range of the array into ascending order by the
 43.2759 -     * Dual-Pivot Quicksort algorithm.
 43.2760 +     * Dual-Pivot Quicksort algorithm. This method differs from the public
 43.2761 +     * {@code sort} method in that the {@code right} index is inclusive,
 43.2762 +     * it does no range checking on {@code left} or {@code right}, and has
 43.2763 +     * boolean flag whether insertion sort with sentinel is used or not.
 43.2764       *
 43.2765       * @param a the array to be sorted
 43.2766       * @param left the index of the first element, inclusive, to be sorted
 43.2767       * @param right the index of the last element, inclusive, to be sorted
 43.2768 +     * @param leftmost indicates if the part is the most left in the range
 43.2769       */
 43.2770 -    private static void dualPivotQuicksort(float[] a, int left, int right) {
 43.2771 -        // Compute indices of five evenly spaced elements
 43.2772 -        int sixth = (right - left + 1) / 6;
 43.2773 -        int e1 = left  + sixth;
 43.2774 -        int e5 = right - sixth;
 43.2775 +    private static void sort(float[] a, int left, int right,boolean leftmost) {
 43.2776 +        int length = right - left + 1;
 43.2777 +
 43.2778 +        // Use insertion sort on tiny arrays
 43.2779 +        if (length < INSERTION_SORT_THRESHOLD) {
 43.2780 +            if (!leftmost) {
 43.2781 +                /*
 43.2782 +                 * Every element in adjoining part plays the role
 43.2783 +                 * of sentinel, therefore this allows us to avoid
 43.2784 +                 * the j >= left check on each iteration.
 43.2785 +                 */
 43.2786 +                for (int j, i = left + 1; i <= right; i++) {
 43.2787 +                    float ai = a[i];
 43.2788 +                    for (j = i - 1; ai < a[j]; j--) {
 43.2789 +                        // assert j >= left;
 43.2790 +                        a[j + 1] = a[j];
 43.2791 +                    }
 43.2792 +                    a[j + 1] = ai;
 43.2793 +                }
 43.2794 +            } else {
 43.2795 +                /*
 43.2796 +                 * For case of leftmost part traditional (without a sentinel)
 43.2797 +                 * insertion sort, optimized for server JVM, is used.
 43.2798 +                 */
 43.2799 +                for (int i = left, j = i; i < right; j = ++i) {
 43.2800 +                    float ai = a[i + 1];
 43.2801 +                    while (ai < a[j]) {
 43.2802 +                        a[j + 1] = a[j];
 43.2803 +                        if (j-- == left) {
 43.2804 +                            break;
 43.2805 +                        }
 43.2806 +                    }
 43.2807 +                    a[j + 1] = ai;
 43.2808 +                }
 43.2809 +            }
 43.2810 +            return;
 43.2811 +        }
 43.2812 +
 43.2813 +        // Inexpensive approximation of length / 7
 43.2814 +        int seventh = (length >>> 3) + (length >>> 6) + 1;
 43.2815 +
 43.2816 +        /*
 43.2817 +         * Sort five evenly spaced elements around (and including) the
 43.2818 +         * center element in the range. These elements will be used for
 43.2819 +         * pivot selection as described below. The choice for spacing
 43.2820 +         * these elements was empirically determined to work well on
 43.2821 +         * a wide variety of inputs.
 43.2822 +         */
 43.2823          int e3 = (left + right) >>> 1; // The midpoint
 43.2824 -        int e4 = e3 + sixth;
 43.2825 -        int e2 = e3 - sixth;
 43.2826 +        int e2 = e3 - seventh;
 43.2827 +        int e1 = e2 - seventh;
 43.2828 +        int e4 = e3 + seventh;
 43.2829 +        int e5 = e4 + seventh;
 43.2830  
 43.2831 -        // Sort these elements using a 5-element sorting network
 43.2832 -        float ae1 = a[e1], ae2 = a[e2], ae3 = a[e3], ae4 = a[e4], ae5 = a[e5];
 43.2833 +        // Sort these elements using insertion sort
 43.2834 +        if (a[e2] < a[e1]) { float t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 43.2835  
 43.2836 -        if (ae1 > ae2) { float t = ae1; ae1 = ae2; ae2 = t; }
 43.2837 -        if (ae4 > ae5) { float t = ae4; ae4 = ae5; ae5 = t; }
 43.2838 -        if (ae1 > ae3) { float t = ae1; ae1 = ae3; ae3 = t; }
 43.2839 -        if (ae2 > ae3) { float t = ae2; ae2 = ae3; ae3 = t; }
 43.2840 -        if (ae1 > ae4) { float t = ae1; ae1 = ae4; ae4 = t; }
 43.2841 -        if (ae3 > ae4) { float t = ae3; ae3 = ae4; ae4 = t; }
 43.2842 -        if (ae2 > ae5) { float t = ae2; ae2 = ae5; ae5 = t; }
 43.2843 -        if (ae2 > ae3) { float t = ae2; ae2 = ae3; ae3 = t; }
 43.2844 -        if (ae4 > ae5) { float t = ae4; ae4 = ae5; ae5 = t; }
 43.2845 -
 43.2846 -        a[e1] = ae1; a[e3] = ae3; a[e5] = ae5;
 43.2847 +        if (a[e3] < a[e2]) { float t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 43.2848 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.2849 +        }
 43.2850 +        if (a[e4] < a[e3]) { float t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 43.2851 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 43.2852 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.2853 +            }
 43.2854 +        }
 43.2855 +        if (a[e5] < a[e4]) { float t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 43.2856 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 43.2857 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 43.2858 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.2859 +                }
 43.2860 +            }
 43.2861 +        }
 43.2862  
 43.2863          /*
 43.2864           * Use the second and fourth of the five sorted elements as pivots.
 43.2865           * These values are inexpensive approximations of the first and
 43.2866           * second terciles of the array. Note that pivot1 <= pivot2.
 43.2867 -         *
 43.2868 -         * The pivots are stored in local variables, and the first and
 43.2869 -         * the last of the elements to be sorted are moved to the locations
 43.2870 -         * formerly occupied by the pivots. When partitioning is complete,
 43.2871 -         * the pivots are swapped back into their final positions, and
 43.2872 -         * excluded from subsequent sorting.
 43.2873           */
 43.2874 -        float pivot1 = ae2; a[e2] = a[left];
 43.2875 -        float pivot2 = ae4; a[e4] = a[right];
 43.2876 +        float pivot1 = a[e2];
 43.2877 +        float pivot2 = a[e4];
 43.2878  
 43.2879          // Pointers
 43.2880 -        int less  = left  + 1; // The index of first element of center part
 43.2881 -        int great = right - 1; // The index before first element of right part
 43.2882 +        int less  = left;  // The index of the first element of center part
 43.2883 +        int great = right; // The index before the first element of right part
 43.2884  
 43.2885 -        boolean pivotsDiffer = (pivot1 != pivot2);
 43.2886 +        if (pivot1 != pivot2) {
 43.2887 +            /*
 43.2888 +             * The first and the last elements to be sorted are moved to the
 43.2889 +             * locations formerly occupied by the pivots. When partitioning
 43.2890 +             * is complete, the pivots are swapped back into their final
 43.2891 +             * positions, and excluded from subsequent sorting.
 43.2892 +             */
 43.2893 +            a[e2] = a[left];
 43.2894 +            a[e4] = a[right];
 43.2895  
 43.2896 -        if (pivotsDiffer) {
 43.2897 +            /*
 43.2898 +             * Skip elements, which are less or greater than pivot values.
 43.2899 +             */
 43.2900 +            while (a[++less] < pivot1);
 43.2901 +            while (a[--great] > pivot2);
 43.2902 +
 43.2903              /*
 43.2904               * Partitioning:
 43.2905               *
 43.2906 -             *   left part         center part                    right part
 43.2907 -             * +------------------------------------------------------------+
 43.2908 -             * | < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2 |
 43.2909 -             * +------------------------------------------------------------+
 43.2910 -             *              ^                          ^       ^
 43.2911 -             *              |                          |       |
 43.2912 -             *             less                        k     great
 43.2913 +             *   left part           center part                   right part
 43.2914 +             * +--------------------------------------------------------------+
 43.2915 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 43.2916 +             * +--------------------------------------------------------------+
 43.2917 +             *               ^                          ^       ^
 43.2918 +             *               |                          |       |
 43.2919 +             *              less                        k     great
 43.2920               *
 43.2921               * Invariants:
 43.2922               *
 43.2923 @@ -1728,16 +2104,14 @@
 43.2924               *    pivot1 <= all in [less, k)     <= pivot2
 43.2925               *              all in (great, right) > pivot2
 43.2926               *
 43.2927 -             * Pointer k is the first index of ?-part
 43.2928 +             * Pointer k is the first index of ?-part.
 43.2929               */
 43.2930              outer:
 43.2931              for (int k = less; k <= great; k++) {
 43.2932                  float ak = a[k];
 43.2933                  if (ak < pivot1) { // Move a[k] to left part
 43.2934 -                    if (k != less) {
 43.2935 -                        a[k] = a[less];
 43.2936 -                        a[less] = ak;
 43.2937 -                    }
 43.2938 +                    a[k] = a[less];
 43.2939 +                    a[less] = ak;
 43.2940                      less++;
 43.2941                  } else if (ak > pivot2) { // Move a[k] to right part
 43.2942                      while (a[great] > pivot2) {
 43.2943 @@ -1747,26 +2121,107 @@
 43.2944                      }
 43.2945                      if (a[great] < pivot1) {
 43.2946                          a[k] = a[less];
 43.2947 -                        a[less++] = a[great];
 43.2948 -                        a[great--] = ak;
 43.2949 +                        a[less] = a[great];
 43.2950 +                        less++;
 43.2951                      } else { // pivot1 <= a[great] <= pivot2
 43.2952                          a[k] = a[great];
 43.2953 -                        a[great--] = ak;
 43.2954 +                    }
 43.2955 +                    a[great] = ak;
 43.2956 +                    great--;
 43.2957 +                }
 43.2958 +            }
 43.2959 +
 43.2960 +            // Swap pivots into their final positions
 43.2961 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 43.2962 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
 43.2963 +
 43.2964 +            // Sort left and right parts recursively, excluding known pivots
 43.2965 +            sort(a, left, less - 2, leftmost);
 43.2966 +            sort(a, great + 2, right, false);
 43.2967 +
 43.2968 +            /*
 43.2969 +             * If center part is too large (comprises > 5/7 of the array),
 43.2970 +             * swap internal pivot values to ends.
 43.2971 +             */
 43.2972 +            if (less < e1 && e5 < great) {
 43.2973 +                /*
 43.2974 +                 * Skip elements, which are equal to pivot values.
 43.2975 +                 */
 43.2976 +                while (a[less] == pivot1) {
 43.2977 +                    less++;
 43.2978 +                }
 43.2979 +                while (a[great] == pivot2) {
 43.2980 +                    great--;
 43.2981 +                }
 43.2982 +
 43.2983 +                /*
 43.2984 +                 * Partitioning:
 43.2985 +                 *
 43.2986 +                 *   left part         center part                  right part
 43.2987 +                 * +----------------------------------------------------------+
 43.2988 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 43.2989 +                 * +----------------------------------------------------------+
 43.2990 +                 *              ^                        ^       ^
 43.2991 +                 *              |                        |       |
 43.2992 +                 *             less                      k     great
 43.2993 +                 *
 43.2994 +                 * Invariants:
 43.2995 +                 *
 43.2996 +                 *              all in (*,  less) == pivot1
 43.2997 +                 *     pivot1 < all in [less,  k)  < pivot2
 43.2998 +                 *              all in (great, *) == pivot2
 43.2999 +                 *
 43.3000 +                 * Pointer k is the first index of ?-part.
 43.3001 +                 */
 43.3002 +                outer:
 43.3003 +                for (int k = less; k <= great; k++) {
 43.3004 +                    float ak = a[k];
 43.3005 +                    if (ak == pivot1) { // Move a[k] to left part
 43.3006 +                        a[k] = a[less];
 43.3007 +                        a[less] = ak;
 43.3008 +                        less++;
 43.3009 +                    } else if (ak == pivot2) { // Move a[k] to right part
 43.3010 +                        while (a[great] == pivot2) {
 43.3011 +                            if (great-- == k) {
 43.3012 +                                break outer;
 43.3013 +                            }
 43.3014 +                        }
 43.3015 +                        if (a[great] == pivot1) {
 43.3016 +                            a[k] = a[less];
 43.3017 +                            /*
 43.3018 +                             * Even though a[great] equals to pivot1, the
 43.3019 +                             * assignment a[less] = pivot1 may be incorrect,
 43.3020 +                             * if a[great] and pivot1 are floating-point zeros
 43.3021 +                             * of different signs. Therefore in float and
 43.3022 +                             * double sorting methods we have to use more
 43.3023 +                             * accurate assignment a[less] = a[great].
 43.3024 +                             */
 43.3025 +                            a[less] = a[great];
 43.3026 +                            less++;
 43.3027 +                        } else { // pivot1 < a[great] < pivot2
 43.3028 +                            a[k] = a[great];
 43.3029 +                        }
 43.3030 +                        a[great] = ak;
 43.3031 +                        great--;
 43.3032                      }
 43.3033                  }
 43.3034              }
 43.3035 +
 43.3036 +            // Sort center part recursively
 43.3037 +            sort(a, less, great, false);
 43.3038 +
 43.3039          } else { // Pivots are equal
 43.3040              /*
 43.3041 -             * Partition degenerates to the traditional 3-way,
 43.3042 -             * or "Dutch National Flag", partition:
 43.3043 +             * Partition degenerates to the traditional 3-way
 43.3044 +             * (or "Dutch National Flag") schema:
 43.3045               *
 43.3046 -             *   left part   center part            right part
 43.3047 -             * +----------------------------------------------+
 43.3048 -             * |  < pivot  |  == pivot  |    ?    |  > pivot  |
 43.3049 -             * +----------------------------------------------+
 43.3050 -             *              ^            ^       ^
 43.3051 -             *              |            |       |
 43.3052 -             *             less          k     great
 43.3053 +             *   left part    center part              right part
 43.3054 +             * +-------------------------------------------------+
 43.3055 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 43.3056 +             * +-------------------------------------------------+
 43.3057 +             *              ^              ^        ^
 43.3058 +             *              |              |        |
 43.3059 +             *             less            k      great
 43.3060               *
 43.3061               * Invariants:
 43.3062               *
 43.3063 @@ -1774,20 +2229,19 @@
 43.3064               *   all in [less, k)     == pivot
 43.3065               *   all in (great, right) > pivot
 43.3066               *
 43.3067 -             * Pointer k is the first index of ?-part
 43.3068 +             * Pointer k is the first index of ?-part.
 43.3069               */
 43.3070 -            for (int k = less; k <= great; k++) {
 43.3071 -                float ak = a[k];
 43.3072 -                if (ak == pivot1) {
 43.3073 +            for (int k = left; k <= great; k++) {
 43.3074 +                if (a[k] == pivot1) {
 43.3075                      continue;
 43.3076                  }
 43.3077 +                float ak = a[k];
 43.3078 +
 43.3079                  if (ak < pivot1) { // Move a[k] to left part
 43.3080 -                    if (k != less) {
 43.3081 -                        a[k] = a[less];
 43.3082 -                        a[less] = ak;
 43.3083 -                    }
 43.3084 +                    a[k] = a[less];
 43.3085 +                    a[less] = ak;
 43.3086                      less++;
 43.3087 -                } else { // (a[k] > pivot1) - Move a[k] to right part
 43.3088 +                } else { // a[k] > pivot1 - Move a[k] to right part
 43.3089                      /*
 43.3090                       * We know that pivot1 == a[e3] == pivot2. Thus, we know
 43.3091                       * that great will still be >= k when the following loop
 43.3092 @@ -1795,92 +2249,33 @@
 43.3093                       * In other words, a[e3] acts as a sentinel for great.
 43.3094                       */
 43.3095                      while (a[great] > pivot1) {
 43.3096 +                        // assert great > k;
 43.3097                          great--;
 43.3098                      }
 43.3099                      if (a[great] < pivot1) {
 43.3100                          a[k] = a[less];
 43.3101 -                        a[less++] = a[great];
 43.3102 -                        a[great--] = ak;
 43.3103 +                        a[less] = a[great];
 43.3104 +                        less++;
 43.3105                      } else { // a[great] == pivot1
 43.3106 -                        a[k] = pivot1;
 43.3107 -                        a[great--] = ak;
 43.3108 +                        /*
 43.3109 +                         * Even though a[great] equals to pivot1, the
 43.3110 +                         * assignment a[k] = pivot1 may be incorrect,
 43.3111 +                         * if a[great] and pivot1 are floating-point
 43.3112 +                         * zeros of different signs. Therefore in float
 43.3113 +                         * and double sorting methods we have to use
 43.3114 +                         * more accurate assignment a[k] = a[great].
 43.3115 +                         */
 43.3116 +                        a[k] = a[great];
 43.3117                      }
 43.3118 +                    a[great] = ak;
 43.3119 +                    great--;
 43.3120                  }
 43.3121              }
 43.3122 +
 43.3123 +            // Sort left and right parts recursively
 43.3124 +            sort(a, left, less - 1, leftmost);
 43.3125 +            sort(a, great + 1, right, false);
 43.3126          }
 43.3127 -
 43.3128 -        // Swap pivots into their final positions
 43.3129 -        a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 43.3130 -        a[right] = a[great + 1]; a[great + 1] = pivot2;
 43.3131 -
 43.3132 -        // Sort left and right parts recursively, excluding known pivot values
 43.3133 -        doSort(a, left,   less - 2);
 43.3134 -        doSort(a, great + 2, right);
 43.3135 -
 43.3136 -        /*
 43.3137 -         * If pivot1 == pivot2, all elements from center
 43.3138 -         * part are equal and, therefore, already sorted
 43.3139 -         */
 43.3140 -        if (!pivotsDiffer) {
 43.3141 -            return;
 43.3142 -        }
 43.3143 -
 43.3144 -        /*
 43.3145 -         * If center part is too large (comprises > 2/3 of the array),
 43.3146 -         * swap internal pivot values to ends
 43.3147 -         */
 43.3148 -        if (less < e1 && great > e5) {
 43.3149 -            while (a[less] == pivot1) {
 43.3150 -                less++;
 43.3151 -            }
 43.3152 -            while (a[great] == pivot2) {
 43.3153 -                great--;
 43.3154 -            }
 43.3155 -
 43.3156 -            /*
 43.3157 -             * Partitioning:
 43.3158 -             *
 43.3159 -             *   left part       center part                   right part
 43.3160 -             * +----------------------------------------------------------+
 43.3161 -             * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 43.3162 -             * +----------------------------------------------------------+
 43.3163 -             *              ^                        ^       ^
 43.3164 -             *              |                        |       |
 43.3165 -             *             less                      k     great
 43.3166 -             *
 43.3167 -             * Invariants:
 43.3168 -             *
 43.3169 -             *              all in (*, less)  == pivot1
 43.3170 -             *     pivot1 < all in [less, k)   < pivot2
 43.3171 -             *              all in (great, *) == pivot2
 43.3172 -             *
 43.3173 -             * Pointer k is the first index of ?-part
 43.3174 -             */
 43.3175 -            outer:
 43.3176 -            for (int k = less; k <= great; k++) {
 43.3177 -                float ak = a[k];
 43.3178 -                if (ak == pivot2) { // Move a[k] to right part
 43.3179 -                    while (a[great] == pivot2) {
 43.3180 -                        if (great-- == k) {
 43.3181 -                            break outer;
 43.3182 -                        }
 43.3183 -                    }
 43.3184 -                    if (a[great] == pivot1) {
 43.3185 -                        a[k] = a[less];
 43.3186 -                        a[less++] = pivot1;
 43.3187 -                    } else { // pivot1 < a[great] < pivot2
 43.3188 -                        a[k] = a[great];
 43.3189 -                    }
 43.3190 -                    a[great--] = pivot2;
 43.3191 -                } else if (ak == pivot1) { // Move a[k] to left part
 43.3192 -                    a[k] = a[less];
 43.3193 -                    a[less++] = pivot1;
 43.3194 -                }
 43.3195 -            }
 43.3196 -        }
 43.3197 -
 43.3198 -        // Sort center part recursively, excluding known pivot values
 43.3199 -        doSort(a, less, great);
 43.3200      }
 43.3201  
 43.3202      /**
 43.3203 @@ -1938,162 +2333,207 @@
 43.3204       */
 43.3205      private static void sortNegZeroAndNaN(double[] a, int left, int right) {
 43.3206          /*
 43.3207 -         * Phase 1: Count negative zeros and move NaNs to end of array
 43.3208 +         * Phase 1: Move NaNs to the end of the array.
 43.3209           */
 43.3210 -        final long NEGATIVE_ZERO = Double.doubleToLongBits(-0.0d);
 43.3211 -        int numNegativeZeros = 0;
 43.3212 -        int n = right;
 43.3213 -
 43.3214 -        for (int k = left; k <= n; k++) {
 43.3215 +        while (left <= right && Double.isNaN(a[right])) {
 43.3216 +            right--;
 43.3217 +        }
 43.3218 +        for (int k = right - 1; k >= left; k--) {
 43.3219              double ak = a[k];
 43.3220 -            if (ak == 0.0d && NEGATIVE_ZERO == Double.doubleToLongBits(ak)) {
 43.3221 -                a[k] = 0.0d;
 43.3222 -                numNegativeZeros++;
 43.3223 -            } else if (ak != ak) { // i.e., ak is NaN
 43.3224 -                a[k--] = a[n];
 43.3225 -                a[n--] = Double.NaN;
 43.3226 +            if (ak != ak) { // a[k] is NaN
 43.3227 +                a[k] = a[right];
 43.3228 +                a[right] = ak;
 43.3229 +                right--;
 43.3230              }
 43.3231          }
 43.3232  
 43.3233          /*
 43.3234 -         * Phase 2: Sort everything except NaNs (which are already in place)
 43.3235 +         * Phase 2: Sort everything except NaNs (which are already in place).
 43.3236           */
 43.3237 -        doSort(a, left, n);
 43.3238 +        sort(a, left, right, true);
 43.3239  
 43.3240          /*
 43.3241 -         * Phase 3: Turn positive zeros back into negative zeros as appropriate
 43.3242 +         * Phase 3: Place negative zeros before positive zeros.
 43.3243           */
 43.3244 -        if (numNegativeZeros == 0) {
 43.3245 -            return;
 43.3246 -        }
 43.3247 +        int hi = right;
 43.3248  
 43.3249 -        // Find first zero element
 43.3250 -        int zeroIndex = findAnyZero(a, left, n);
 43.3251 -
 43.3252 -        for (int i = zeroIndex - 1; i >= left && a[i] == 0.0d; i--) {
 43.3253 -            zeroIndex = i;
 43.3254 -        }
 43.3255 -
 43.3256 -        // Turn the right number of positive zeros back into negative zeros
 43.3257 -        for (int i = zeroIndex, m = zeroIndex + numNegativeZeros; i < m; i++) {
 43.3258 -            a[i] = -0.0d;
 43.3259 -        }
 43.3260 -    }
 43.3261 -
 43.3262 -    /**
 43.3263 -     * Returns the index of some zero element in the specified range via
 43.3264 -     * binary search. The range is assumed to be sorted, and must contain
 43.3265 -     * at least one zero.
 43.3266 -     *
 43.3267 -     * @param a the array to be searched
 43.3268 -     * @param low the index of the first element, inclusive, to be searched
 43.3269 -     * @param high the index of the last element, inclusive, to be searched
 43.3270 -     */
 43.3271 -    private static int findAnyZero(double[] a, int low, int high) {
 43.3272 -        while (true) {
 43.3273 -            int middle = (low + high) >>> 1;
 43.3274 +        /*
 43.3275 +         * Search first zero, or first positive, or last negative element.
 43.3276 +         */
 43.3277 +        while (left < hi) {
 43.3278 +            int middle = (left + hi) >>> 1;
 43.3279              double middleValue = a[middle];
 43.3280  
 43.3281              if (middleValue < 0.0d) {
 43.3282 -                low = middle + 1;
 43.3283 -            } else if (middleValue > 0.0d) {
 43.3284 -                high = middle - 1;
 43.3285 -            } else { // middleValue == 0.0d
 43.3286 -                return middle;
 43.3287 +                left = middle + 1;
 43.3288 +            } else {
 43.3289 +                hi = middle;
 43.3290 +            }
 43.3291 +        }
 43.3292 +
 43.3293 +        /*
 43.3294 +         * Skip the last negative value (if any) or all leading negative zeros.
 43.3295 +         */
 43.3296 +        while (left <= right && Double.doubleToRawLongBits(a[left]) < 0) {
 43.3297 +            left++;
 43.3298 +        }
 43.3299 +
 43.3300 +        /*
 43.3301 +         * Move negative zeros to the beginning of the sub-range.
 43.3302 +         *
 43.3303 +         * Partitioning:
 43.3304 +         *
 43.3305 +         * +---------------------------------------------------+
 43.3306 +         * |   < 0.0   |   -0.0   |    0.0    |  ?  ( >= 0.0 ) |
 43.3307 +         * +---------------------------------------------------+
 43.3308 +         *              ^          ^           ^
 43.3309 +         *              |          |           |
 43.3310 +         *             left        p           k
 43.3311 +         *
 43.3312 +         * Invariants:
 43.3313 +         *
 43.3314 +         *   all in (*,  left)  <  0.0
 43.3315 +         *   all in [left,  p) == -0.0
 43.3316 +         *   all in [p,     k) ==  0.0
 43.3317 +         *   all in [k, right] >=  0.0
 43.3318 +         *
 43.3319 +         * Pointer k is the first index of ?-part.
 43.3320 +         */
 43.3321 +        for (int k = left + 1, p = left; k <= right; k++) {
 43.3322 +            double ak = a[k];
 43.3323 +            if (ak != 0.0d) {
 43.3324 +                break;
 43.3325 +            }
 43.3326 +            if (Double.doubleToRawLongBits(ak) < 0) { // ak is -0.0d
 43.3327 +                a[k] = 0.0d;
 43.3328 +                a[p++] = -0.0d;
 43.3329              }
 43.3330          }
 43.3331      }
 43.3332  
 43.3333      /**
 43.3334 -     * Sorts the specified range of the array into ascending order. This
 43.3335 -     * method differs from the public {@code sort} method in three ways:
 43.3336 -     * {@code right} index is inclusive, it does no range checking on
 43.3337 -     * {@code left} or {@code right}, and it does not handle negative
 43.3338 -     * zeros or NaNs in the array.
 43.3339 -     *
 43.3340 -     * @param a the array to be sorted, which must not contain -0.0d and NaN
 43.3341 -     * @param left the index of the first element, inclusive, to be sorted
 43.3342 -     * @param right the index of the last element, inclusive, to be sorted
 43.3343 -     */
 43.3344 -    private static void doSort(double[] a, int left, int right) {
 43.3345 -        // Use insertion sort on tiny arrays
 43.3346 -        if (right - left + 1 < INSERTION_SORT_THRESHOLD) {
 43.3347 -            for (int i = left + 1; i <= right; i++) {
 43.3348 -                double ai = a[i];
 43.3349 -                int j;
 43.3350 -                for (j = i - 1; j >= left && ai < a[j]; j--) {
 43.3351 -                    a[j + 1] = a[j];
 43.3352 -                }
 43.3353 -                a[j + 1] = ai;
 43.3354 -            }
 43.3355 -        } else { // Use Dual-Pivot Quicksort on large arrays
 43.3356 -            dualPivotQuicksort(a, left, right);
 43.3357 -        }
 43.3358 -    }
 43.3359 -
 43.3360 -    /**
 43.3361       * Sorts the specified range of the array into ascending order by the
 43.3362 -     * Dual-Pivot Quicksort algorithm.
 43.3363 +     * Dual-Pivot Quicksort algorithm. This method differs from the public
 43.3364 +     * {@code sort} method in that the {@code right} index is inclusive,
 43.3365 +     * it does no range checking on {@code left} or {@code right}, and has
 43.3366 +     * boolean flag whether insertion sort with sentinel is used or not.
 43.3367       *
 43.3368       * @param a the array to be sorted
 43.3369       * @param left the index of the first element, inclusive, to be sorted
 43.3370       * @param right the index of the last element, inclusive, to be sorted
 43.3371 +     * @param leftmost indicates if the part is the most left in the range
 43.3372       */
 43.3373 -    private static void dualPivotQuicksort(double[] a, int left, int right) {
 43.3374 -        // Compute indices of five evenly spaced elements
 43.3375 -        int sixth = (right - left + 1) / 6;
 43.3376 -        int e1 = left  + sixth;
 43.3377 -        int e5 = right - sixth;
 43.3378 +    private static void sort(double[] a, int left,int right,boolean leftmost) {
 43.3379 +        int length = right - left + 1;
 43.3380 +
 43.3381 +        // Use insertion sort on tiny arrays
 43.3382 +        if (length < INSERTION_SORT_THRESHOLD) {
 43.3383 +            if (!leftmost) {
 43.3384 +                /*
 43.3385 +                 * Every element in adjoining part plays the role
 43.3386 +                 * of sentinel, therefore this allows us to avoid
 43.3387 +                 * the j >= left check on each iteration.
 43.3388 +                 */
 43.3389 +                for (int j, i = left + 1; i <= right; i++) {
 43.3390 +                    double ai = a[i];
 43.3391 +                    for (j = i - 1; ai < a[j]; j--) {
 43.3392 +                        // assert j >= left;
 43.3393 +                        a[j + 1] = a[j];
 43.3394 +                    }
 43.3395 +                    a[j + 1] = ai;
 43.3396 +                }
 43.3397 +            } else {
 43.3398 +                /*
 43.3399 +                 * For case of leftmost part traditional (without a sentinel)
 43.3400 +                 * insertion sort, optimized for server JVM, is used.
 43.3401 +                 */
 43.3402 +                for (int i = left, j = i; i < right; j = ++i) {
 43.3403 +                    double ai = a[i + 1];
 43.3404 +                    while (ai < a[j]) {
 43.3405 +                        a[j + 1] = a[j];
 43.3406 +                        if (j-- == left) {
 43.3407 +                            break;
 43.3408 +                        }
 43.3409 +                    }
 43.3410 +                    a[j + 1] = ai;
 43.3411 +                }
 43.3412 +            }
 43.3413 +            return;
 43.3414 +        }
 43.3415 +
 43.3416 +        // Inexpensive approximation of length / 7
 43.3417 +        int seventh = (length >>> 3) + (length >>> 6) + 1;
 43.3418 +
 43.3419 +        /*
 43.3420 +         * Sort five evenly spaced elements around (and including) the
 43.3421 +         * center element in the range. These elements will be used for
 43.3422 +         * pivot selection as described below. The choice for spacing
 43.3423 +         * these elements was empirically determined to work well on
 43.3424 +         * a wide variety of inputs.
 43.3425 +         */
 43.3426          int e3 = (left + right) >>> 1; // The midpoint
 43.3427 -        int e4 = e3 + sixth;
 43.3428 -        int e2 = e3 - sixth;
 43.3429 +        int e2 = e3 - seventh;
 43.3430 +        int e1 = e2 - seventh;
 43.3431 +        int e4 = e3 + seventh;
 43.3432 +        int e5 = e4 + seventh;
 43.3433  
 43.3434 -        // Sort these elements using a 5-element sorting network
 43.3435 -        double ae1 = a[e1], ae2 = a[e2], ae3 = a[e3], ae4 = a[e4], ae5 = a[e5];
 43.3436 +        // Sort these elements using insertion sort
 43.3437 +        if (a[e2] < a[e1]) { double t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 43.3438  
 43.3439 -        if (ae1 > ae2) { double t = ae1; ae1 = ae2; ae2 = t; }
 43.3440 -        if (ae4 > ae5) { double t = ae4; ae4 = ae5; ae5 = t; }
 43.3441 -        if (ae1 > ae3) { double t = ae1; ae1 = ae3; ae3 = t; }
 43.3442 -        if (ae2 > ae3) { double t = ae2; ae2 = ae3; ae3 = t; }
 43.3443 -        if (ae1 > ae4) { double t = ae1; ae1 = ae4; ae4 = t; }
 43.3444 -        if (ae3 > ae4) { double t = ae3; ae3 = ae4; ae4 = t; }
 43.3445 -        if (ae2 > ae5) { double t = ae2; ae2 = ae5; ae5 = t; }
 43.3446 -        if (ae2 > ae3) { double t = ae2; ae2 = ae3; ae3 = t; }
 43.3447 -        if (ae4 > ae5) { double t = ae4; ae4 = ae5; ae5 = t; }
 43.3448 -
 43.3449 -        a[e1] = ae1; a[e3] = ae3; a[e5] = ae5;
 43.3450 +        if (a[e3] < a[e2]) { double t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 43.3451 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.3452 +        }
 43.3453 +        if (a[e4] < a[e3]) { double t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 43.3454 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 43.3455 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.3456 +            }
 43.3457 +        }
 43.3458 +        if (a[e5] < a[e4]) { double t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 43.3459 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 43.3460 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 43.3461 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 43.3462 +                }
 43.3463 +            }
 43.3464 +        }
 43.3465  
 43.3466          /*
 43.3467           * Use the second and fourth of the five sorted elements as pivots.
 43.3468           * These values are inexpensive approximations of the first and
 43.3469           * second terciles of the array. Note that pivot1 <= pivot2.
 43.3470 -         *
 43.3471 -         * The pivots are stored in local variables, and the first and
 43.3472 -         * the last of the elements to be sorted are moved to the locations
 43.3473 -         * formerly occupied by the pivots. When partitioning is complete,
 43.3474 -         * the pivots are swapped back into their final positions, and
 43.3475 -         * excluded from subsequent sorting.
 43.3476           */
 43.3477 -        double pivot1 = ae2; a[e2] = a[left];
 43.3478 -        double pivot2 = ae4; a[e4] = a[right];
 43.3479 +        double pivot1 = a[e2];
 43.3480 +        double pivot2 = a[e4];
 43.3481  
 43.3482          // Pointers
 43.3483 -        int less  = left  + 1; // The index of first element of center part
 43.3484 -        int great = right - 1; // The index before first element of right part
 43.3485 +        int less  = left;  // The index of the first element of center part
 43.3486 +        int great = right; // The index before the first element of right part
 43.3487  
 43.3488 -        boolean pivotsDiffer = (pivot1 != pivot2);
 43.3489 +        if (pivot1 != pivot2) {
 43.3490 +            /*
 43.3491 +             * The first and the last elements to be sorted are moved to the
 43.3492 +             * locations formerly occupied by the pivots. When partitioning
 43.3493 +             * is complete, the pivots are swapped back into their final
 43.3494 +             * positions, and excluded from subsequent sorting.
 43.3495 +             */
 43.3496 +            a[e2] = a[left];
 43.3497 +            a[e4] = a[right];
 43.3498  
 43.3499 -        if (pivotsDiffer) {
 43.3500 +            /*
 43.3501 +             * Skip elements, which are less or greater than pivot values.
 43.3502 +             */
 43.3503 +            while (a[++less] < pivot1);
 43.3504 +            while (a[--great] > pivot2);
 43.3505 +
 43.3506              /*
 43.3507               * Partitioning:
 43.3508               *
 43.3509 -             *   left part         center part                    right part
 43.3510 -             * +------------------------------------------------------------+
 43.3511 -             * | < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2 |
 43.3512 -             * +------------------------------------------------------------+
 43.3513 -             *              ^                          ^       ^
 43.3514 -             *              |                          |       |
 43.3515 -             *             less                        k     great
 43.3516 +             *   left part           center part                   right part
 43.3517 +             * +--------------------------------------------------------------+
 43.3518 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 43.3519 +             * +--------------------------------------------------------------+
 43.3520 +             *               ^                          ^       ^
 43.3521 +             *               |                          |       |
 43.3522 +             *              less                        k     great
 43.3523               *
 43.3524               * Invariants:
 43.3525               *
 43.3526 @@ -2101,16 +2541,14 @@
 43.3527               *    pivot1 <= all in [less, k)     <= pivot2
 43.3528               *              all in (great, right) > pivot2
 43.3529               *
 43.3530 -             * Pointer k is the first index of ?-part
 43.3531 +             * Pointer k is the first index of ?-part.
 43.3532               */
 43.3533              outer:
 43.3534              for (int k = less; k <= great; k++) {
 43.3535                  double ak = a[k];
 43.3536                  if (ak < pivot1) { // Move a[k] to left part
 43.3537 -                    if (k != less) {
 43.3538 -                        a[k] = a[less];
 43.3539 -                        a[less] = ak;
 43.3540 -                    }
 43.3541 +                    a[k] = a[less];
 43.3542 +                    a[less] = ak;
 43.3543                      less++;
 43.3544                  } else if (ak > pivot2) { // Move a[k] to right part
 43.3545                      while (a[great] > pivot2) {
 43.3546 @@ -2120,26 +2558,107 @@
 43.3547                      }
 43.3548                      if (a[great] < pivot1) {
 43.3549                          a[k] = a[less];
 43.3550 -                        a[less++] = a[great];
 43.3551 -                        a[great--] = ak;
 43.3552 +                        a[less] = a[great];
 43.3553 +                        less++;
 43.3554                      } else { // pivot1 <= a[great] <= pivot2
 43.3555                          a[k] = a[great];
 43.3556 -                        a[great--] = ak;
 43.3557 +                    }
 43.3558 +                    a[great] = ak;
 43.3559 +                    great--;
 43.3560 +                }
 43.3561 +            }
 43.3562 +
 43.3563 +            // Swap pivots into their final positions
 43.3564 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 43.3565 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
 43.3566 +
 43.3567 +            // Sort left and right parts recursively, excluding known pivots
 43.3568 +            sort(a, left, less - 2, leftmost);
 43.3569 +            sort(a, great + 2, right, false);
 43.3570 +
 43.3571 +            /*
 43.3572 +             * If center part is too large (comprises > 5/7 of the array),
 43.3573 +             * swap internal pivot values to ends.
 43.3574 +             */
 43.3575 +            if (less < e1 && e5 < great) {
 43.3576 +                /*
 43.3577 +                 * Skip elements, which are equal to pivot values.
 43.3578 +                 */
 43.3579 +                while (a[less] == pivot1) {
 43.3580 +                    less++;
 43.3581 +                }
 43.3582 +                while (a[great] == pivot2) {
 43.3583 +                    great--;
 43.3584 +                }
 43.3585 +
 43.3586 +                /*
 43.3587 +                 * Partitioning:
 43.3588 +                 *
 43.3589 +                 *   left part         center part                  right part
 43.3590 +                 * +----------------------------------------------------------+
 43.3591 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 43.3592 +                 * +----------------------------------------------------------+
 43.3593 +                 *              ^                        ^       ^
 43.3594 +                 *              |                        |       |
 43.3595 +                 *             less                      k     great
 43.3596 +                 *
 43.3597 +                 * Invariants:
 43.3598 +                 *
 43.3599 +                 *              all in (*,  less) == pivot1
 43.3600 +                 *     pivot1 < all in [less,  k)  < pivot2
 43.3601 +                 *              all in (great, *) == pivot2
 43.3602 +                 *
 43.3603 +                 * Pointer k is the first index of ?-part.
 43.3604 +                 */
 43.3605 +                outer:
 43.3606 +                for (int k = less; k <= great; k++) {
 43.3607 +                    double ak = a[k];
 43.3608 +                    if (ak == pivot1) { // Move a[k] to left part
 43.3609 +                        a[k] = a[less];
 43.3610 +                        a[less] = ak;
 43.3611 +                        less++;
 43.3612 +                    } else if (ak == pivot2) { // Move a[k] to right part
 43.3613 +                        while (a[great] == pivot2) {
 43.3614 +                            if (great-- == k) {
 43.3615 +                                break outer;
 43.3616 +                            }
 43.3617 +                        }
 43.3618 +                        if (a[great] == pivot1) {
 43.3619 +                            a[k] = a[less];
 43.3620 +                            /*
 43.3621 +                             * Even though a[great] equals to pivot1, the
 43.3622 +                             * assignment a[less] = pivot1 may be incorrect,
 43.3623 +                             * if a[great] and pivot1 are floating-point zeros
 43.3624 +                             * of different signs. Therefore in float and
 43.3625 +                             * double sorting methods we have to use more
 43.3626 +                             * accurate assignment a[less] = a[great].
 43.3627 +                             */
 43.3628 +                            a[less] = a[great];
 43.3629 +                            less++;
 43.3630 +                        } else { // pivot1 < a[great] < pivot2
 43.3631 +                            a[k] = a[great];
 43.3632 +                        }
 43.3633 +                        a[great] = ak;
 43.3634 +                        great--;
 43.3635                      }
 43.3636                  }
 43.3637              }
 43.3638 +
 43.3639 +            // Sort center part recursively
 43.3640 +            sort(a, less, great, false);
 43.3641 +
 43.3642          } else { // Pivots are equal
 43.3643              /*
 43.3644 -             * Partition degenerates to the traditional 3-way,
 43.3645 -             * or "Dutch National Flag", partition:
 43.3646 +             * Partition degenerates to the traditional 3-way
 43.3647 +             * (or "Dutch National Flag") schema:
 43.3648               *
 43.3649 -             *   left part   center part            right part
 43.3650 -             * +----------------------------------------------+
 43.3651 -             * |  < pivot  |  == pivot  |    ?    |  > pivot  |
 43.3652 -             * +----------------------------------------------+
 43.3653 -             *              ^            ^       ^
 43.3654 -             *              |            |       |
 43.3655 -             *             less          k     great
 43.3656 +             *   left part    center part              right part
 43.3657 +             * +-------------------------------------------------+
 43.3658 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 43.3659 +             * +-------------------------------------------------+
 43.3660 +             *              ^              ^        ^
 43.3661 +             *              |              |        |
 43.3662 +             *             less            k      great
 43.3663               *
 43.3664               * Invariants:
 43.3665               *
 43.3666 @@ -2147,20 +2666,19 @@
 43.3667               *   all in [less, k)     == pivot
 43.3668               *   all in (great, right) > pivot
 43.3669               *
 43.3670 -             * Pointer k is the first index of ?-part
 43.3671 +             * Pointer k is the first index of ?-part.
 43.3672               */
 43.3673 -            for (int k = less; k <= great; k++) {
 43.3674 -                double ak = a[k];
 43.3675 -                if (ak == pivot1) {
 43.3676 +            for (int k = left; k <= great; k++) {
 43.3677 +                if (a[k] == pivot1) {
 43.3678                      continue;
 43.3679                  }
 43.3680 +                double ak = a[k];
 43.3681 +
 43.3682                  if (ak < pivot1) { // Move a[k] to left part
 43.3683 -                    if (k != less) {
 43.3684 -                        a[k] = a[less];
 43.3685 -                        a[less] = ak;
 43.3686 -                    }
 43.3687 +                    a[k] = a[less];
 43.3688 +                    a[less] = ak;
 43.3689                      less++;
 43.3690 -                } else { // (a[k] > pivot1) - Move a[k] to right part
 43.3691 +                } else { // a[k] > pivot1 - Move a[k] to right part
 43.3692                      /*
 43.3693                       * We know that pivot1 == a[e3] == pivot2. Thus, we know
 43.3694                       * that great will still be >= k when the following loop
 43.3695 @@ -2168,102 +2686,43 @@
 43.3696                       * In other words, a[e3] acts as a sentinel for great.
 43.3697                       */
 43.3698                      while (a[great] > pivot1) {
 43.3699 +                        // assert great > k;
 43.3700                          great--;
 43.3701                      }
 43.3702                      if (a[great] < pivot1) {
 43.3703                          a[k] = a[less];
 43.3704 -                        a[less++] = a[great];
 43.3705 -                        a[great--] = ak;
 43.3706 +                        a[less] = a[great];
 43.3707 +                        less++;
 43.3708                      } else { // a[great] == pivot1
 43.3709 -                        a[k] = pivot1;
 43.3710 -                        a[great--] = ak;
 43.3711 +                        /*
 43.3712 +                         * Even though a[great] equals to pivot1, the
 43.3713 +                         * assignment a[k] = pivot1 may be incorrect,
 43.3714 +                         * if a[great] and pivot1 are floating-point
 43.3715 +                         * zeros of different signs. Therefore in float
 43.3716 +                         * and double sorting methods we have to use
 43.3717 +                         * more accurate assignment a[k] = a[great].
 43.3718 +                         */
 43.3719 +                        a[k] = a[great];
 43.3720                      }
 43.3721 +                    a[great] = ak;
 43.3722 +                    great--;
 43.3723                  }
 43.3724              }
 43.3725 +
 43.3726 +            // Sort left and right parts recursively
 43.3727 +            sort(a, left, less - 1, leftmost);
 43.3728 +            sort(a, great + 1, right, false);
 43.3729          }
 43.3730 -
 43.3731 -        // Swap pivots into their final positions
 43.3732 -        a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 43.3733 -        a[right] = a[great + 1]; a[great + 1] = pivot2;
 43.3734 -
 43.3735 -        // Sort left and right parts recursively, excluding known pivot values
 43.3736 -        doSort(a, left,   less - 2);
 43.3737 -        doSort(a, great + 2, right);
 43.3738 -
 43.3739 -        /*
 43.3740 -         * If pivot1 == pivot2, all elements from center
 43.3741 -         * part are equal and, therefore, already sorted
 43.3742 -         */
 43.3743 -        if (!pivotsDiffer) {
 43.3744 -            return;
 43.3745 -        }
 43.3746 -
 43.3747 -        /*
 43.3748 -         * If center part is too large (comprises > 2/3 of the array),
 43.3749 -         * swap internal pivot values to ends
 43.3750 -         */
 43.3751 -        if (less < e1 && great > e5) {
 43.3752 -            while (a[less] == pivot1) {
 43.3753 -                less++;
 43.3754 -            }
 43.3755 -            while (a[great] == pivot2) {
 43.3756 -                great--;
 43.3757 -            }
 43.3758 -
 43.3759 -            /*
 43.3760 -             * Partitioning:
 43.3761 -             *
 43.3762 -             *   left part       center part                   right part
 43.3763 -             * +----------------------------------------------------------+
 43.3764 -             * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 43.3765 -             * +----------------------------------------------------------+
 43.3766 -             *              ^                        ^       ^
 43.3767 -             *              |                        |       |
 43.3768 -             *             less                      k     great
 43.3769 -             *
 43.3770 -             * Invariants:
 43.3771 -             *
 43.3772 -             *              all in (*, less)  == pivot1
 43.3773 -             *     pivot1 < all in [less, k)   < pivot2
 43.3774 -             *              all in (great, *) == pivot2
 43.3775 -             *
 43.3776 -             * Pointer k is the first index of ?-part
 43.3777 -             */
 43.3778 -            outer:
 43.3779 -            for (int k = less; k <= great; k++) {
 43.3780 -                double ak = a[k];
 43.3781 -                if (ak == pivot2) { // Move a[k] to right part
 43.3782 -                    while (a[great] == pivot2) {
 43.3783 -                        if (great-- == k) {
 43.3784 -                            break outer;
 43.3785 -                        }
 43.3786 -                    }
 43.3787 -                    if (a[great] == pivot1) {
 43.3788 -                        a[k] = a[less];
 43.3789 -                        a[less++] = pivot1;
 43.3790 -                    } else { // pivot1 < a[great] < pivot2
 43.3791 -                        a[k] = a[great];
 43.3792 -                    }
 43.3793 -                    a[great--] = pivot2;
 43.3794 -                } else if (ak == pivot1) { // Move a[k] to left part
 43.3795 -                    a[k] = a[less];
 43.3796 -                    a[less++] = pivot1;
 43.3797 -                }
 43.3798 -            }
 43.3799 -        }
 43.3800 -
 43.3801 -        // Sort center part recursively, excluding known pivot values
 43.3802 -        doSort(a, less, great);
 43.3803      }
 43.3804  
 43.3805      /**
 43.3806 -     * Checks that {@code fromIndex} and {@code toIndex} are in
 43.3807 -     * the range and throws an appropriate exception, if they aren't.
 43.3808 +     * Checks that {@code fromIndex} and {@code toIndex} are in the range,
 43.3809 +     * otherwise throws an appropriate exception.
 43.3810       */
 43.3811      private static void rangeCheck(int length, int fromIndex, int toIndex) {
 43.3812          if (fromIndex > toIndex) {
 43.3813              throw new IllegalArgumentException(
 43.3814 -                "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
 43.3815 +                "fromIndex: " + fromIndex + " > toIndex: " + toIndex);
 43.3816          }
 43.3817          if (fromIndex < 0) {
 43.3818              throw new ArrayIndexOutOfBoundsException(fromIndex);
    44.1 --- a/src/share/classes/java/util/Scanner.java	Thu Jul 15 20:11:45 2010 -0700
    44.2 +++ b/src/share/classes/java/util/Scanner.java	Tue Jul 20 22:21:31 2010 -0700
    44.3 @@ -343,7 +343,7 @@
    44.4   *
    44.5   * @since   1.5
    44.6   */
    44.7 -public final class Scanner implements Iterator<String> {
    44.8 +public final class Scanner implements Iterator<String>, Closeable {
    44.9  
   44.10      // Internal buffer used to hold input
   44.11      private CharBuffer buf;
    45.1 --- a/src/share/classes/java/util/logging/LogManager.java	Thu Jul 15 20:11:45 2010 -0700
    45.2 +++ b/src/share/classes/java/util/logging/LogManager.java	Tue Jul 20 22:21:31 2010 -0700
    45.3 @@ -1,5 +1,5 @@
    45.4  /*
    45.5 - * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
    45.6 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    45.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    45.8   *
    45.9   * This code is free software; you can redistribute it and/or modify it
   45.10 @@ -29,6 +29,7 @@
   45.11  import java.io.*;
   45.12  import java.util.*;
   45.13  import java.security.*;
   45.14 +import java.lang.ref.ReferenceQueue;
   45.15  import java.lang.ref.WeakReference;
   45.16  import java.beans.PropertyChangeListener;
   45.17  import java.beans.PropertyChangeSupport;
   45.18 @@ -154,10 +155,10 @@
   45.19                           = new PropertyChangeSupport(LogManager.class);
   45.20      private final static Level defaultLevel = Level.INFO;
   45.21  
   45.22 -    // Table of known loggers.  Maps names to Loggers.
   45.23 -    private Hashtable<String,WeakReference<Logger>> loggers =
   45.24 -        new Hashtable<String,WeakReference<Logger>>();
   45.25 -    // Tree of known loggers
   45.26 +    // Table of named Loggers that maps names to Loggers.
   45.27 +    private Hashtable<String,LoggerWeakRef> namedLoggers =
   45.28 +        new Hashtable<String,LoggerWeakRef>();
   45.29 +    // Tree of named Loggers
   45.30      private LogNode root = new LogNode(null);
   45.31      private Logger rootLogger;
   45.32  
   45.33 @@ -417,6 +418,121 @@
   45.34              }});
   45.35      }
   45.36  
   45.37 +
   45.38 +    // loggerRefQueue holds LoggerWeakRef objects for Logger objects
   45.39 +    // that have been GC'ed.
   45.40 +    private final ReferenceQueue<Logger> loggerRefQueue
   45.41 +        = new ReferenceQueue<Logger>();
   45.42 +
   45.43 +    // Package-level inner class.
   45.44 +    // Helper class for managing WeakReferences to Logger objects.
   45.45 +    //
   45.46 +    // LogManager.namedLoggers
   45.47 +    //     - has weak references to all named Loggers
   45.48 +    //     - namedLoggers keeps the LoggerWeakRef objects for the named
   45.49 +    //       Loggers around until we can deal with the book keeping for
   45.50 +    //       the named Logger that is being GC'ed.
   45.51 +    // LogManager.LogNode.loggerRef
   45.52 +    //     - has a weak reference to a named Logger
   45.53 +    //     - the LogNode will also keep the LoggerWeakRef objects for
   45.54 +    //       the named Loggers around; currently LogNodes never go away.
   45.55 +    // Logger.kids
   45.56 +    //     - has a weak reference to each direct child Logger; this
   45.57 +    //       includes anonymous and named Loggers
   45.58 +    //     - anonymous Loggers are always children of the rootLogger
   45.59 +    //       which is a strong reference; rootLogger.kids keeps the
   45.60 +    //       LoggerWeakRef objects for the anonymous Loggers around
   45.61 +    //       until we can deal with the book keeping.
   45.62 +    //
   45.63 +    final class LoggerWeakRef extends WeakReference<Logger> {
   45.64 +        private String                name;       // for namedLoggers cleanup
   45.65 +        private LogNode               node;       // for loggerRef cleanup
   45.66 +        private WeakReference<Logger> parentRef;  // for kids cleanup
   45.67 +
   45.68 +        LoggerWeakRef(Logger logger) {
   45.69 +            super(logger, loggerRefQueue);
   45.70 +
   45.71 +            name = logger.getName();  // save for namedLoggers cleanup
   45.72 +        }
   45.73 +
   45.74 +        // dispose of this LoggerWeakRef object
   45.75 +        void dispose() {
   45.76 +            if (node != null) {
   45.77 +                // if we have a LogNode, then we were a named Logger
   45.78 +                // so clear namedLoggers weak ref to us
   45.79 +                manager.namedLoggers.remove(name);
   45.80 +                name = null;  // clear our ref to the Logger's name
   45.81 +
   45.82 +                node.loggerRef = null;  // clear LogNode's weak ref to us
   45.83 +                node = null;            // clear our ref to LogNode
   45.84 +            }
   45.85 +
   45.86 +            if (parentRef != null) {
   45.87 +                // this LoggerWeakRef has or had a parent Logger
   45.88 +                Logger parent = parentRef.get();
   45.89 +                if (parent != null) {
   45.90 +                    // the parent Logger is still there so clear the
   45.91 +                    // parent Logger's weak ref to us
   45.92 +                    parent.removeChildLogger(this);
   45.93 +                }
   45.94 +                parentRef = null;  // clear our weak ref to the parent Logger
   45.95 +            }
   45.96 +        }
   45.97 +
   45.98 +        // set the node field to the specified value
   45.99 +        void setNode(LogNode node) {
  45.100 +            this.node = node;
  45.101 +        }
  45.102 +
  45.103 +        // set the parentRef field to the specified value
  45.104 +        void setParentRef(WeakReference<Logger> parentRef) {
  45.105 +            this.parentRef = parentRef;
  45.106 +        }
  45.107 +    }
  45.108 +
  45.109 +    // Package-level method.
  45.110 +    // Drain some Logger objects that have been GC'ed.
  45.111 +    //
  45.112 +    // drainLoggerRefQueueBounded() is called by addLogger() below
  45.113 +    // and by Logger.getAnonymousLogger(String) so we'll drain up to
  45.114 +    // MAX_ITERATIONS GC'ed Loggers for every Logger we add.
  45.115 +    //
  45.116 +    // On a WinXP VMware client, a MAX_ITERATIONS value of 400 gives
  45.117 +    // us about a 50/50 mix in increased weak ref counts versus
  45.118 +    // decreased weak ref counts in the AnonLoggerWeakRefLeak test.
  45.119 +    // Here are stats for cleaning up sets of 400 anonymous Loggers:
  45.120 +    //   - test duration 1 minute
  45.121 +    //   - sample size of 125 sets of 400
  45.122 +    //   - average: 1.99 ms
  45.123 +    //   - minimum: 0.57 ms
  45.124 +    //   - maximum: 25.3 ms
  45.125 +    //
  45.126 +    // The same config gives us a better decreased weak ref count
  45.127 +    // than increased weak ref count in the LoggerWeakRefLeak test.
  45.128 +    // Here are stats for cleaning up sets of 400 named Loggers:
  45.129 +    //   - test duration 2 minutes
  45.130 +    //   - sample size of 506 sets of 400
  45.131 +    //   - average: 0.57 ms
  45.132 +    //   - minimum: 0.02 ms
  45.133 +    //   - maximum: 10.9 ms
  45.134 +    //
  45.135 +    private final static int MAX_ITERATIONS = 400;
  45.136 +    final synchronized void drainLoggerRefQueueBounded() {
  45.137 +        for (int i = 0; i < MAX_ITERATIONS; i++) {
  45.138 +            if (loggerRefQueue == null) {
  45.139 +                // haven't finished loading LogManager yet
  45.140 +                break;
  45.141 +            }
  45.142 +
  45.143 +            LoggerWeakRef ref = (LoggerWeakRef) loggerRefQueue.poll();
  45.144 +            if (ref == null) {
  45.145 +                break;
  45.146 +            }
  45.147 +            // a Logger object has been GC'ed so clean it up
  45.148 +            ref.dispose();
  45.149 +        }
  45.150 +    }
  45.151 +
  45.152      /**
  45.153       * Add a named logger.  This does nothing and returns false if a logger
  45.154       * with the same name is already registered.
  45.155 @@ -439,13 +555,16 @@
  45.156              throw new NullPointerException();
  45.157          }
  45.158  
  45.159 -        WeakReference<Logger> ref = loggers.get(name);
  45.160 +        // cleanup some Loggers that have been GC'ed
  45.161 +        drainLoggerRefQueueBounded();
  45.162 +
  45.163 +        LoggerWeakRef ref = namedLoggers.get(name);
  45.164          if (ref != null) {
  45.165              if (ref.get() == null) {
  45.166 -                // Hashtable holds stale weak reference
  45.167 -                // to a logger which has been GC-ed.
  45.168 -                // Allow to register new one.
  45.169 -                loggers.remove(name);
  45.170 +                // It's possible that the Logger was GC'ed after the
  45.171 +                // drainLoggerRefQueueBounded() call above so allow
  45.172 +                // a new one to be registered.
  45.173 +                namedLoggers.remove(name);
  45.174              } else {
  45.175                  // We already have a registered logger with the given name.
  45.176                  return false;
  45.177 @@ -454,7 +573,8 @@
  45.178  
  45.179          // We're adding a new logger.
  45.180          // Note that we are creating a weak reference here.
  45.181 -        loggers.put(name, new WeakReference<Logger>(logger));
  45.182 +        ref = new LoggerWeakRef(logger);
  45.183 +        namedLoggers.put(name, ref);
  45.184  
  45.185          // Apply any initial level defined for the new logger.
  45.186          Level level = getLevelProperty(name+".level", null);
  45.187 @@ -469,11 +589,11 @@
  45.188  
  45.189          // Find the new node and its parent.
  45.190          LogNode node = findNode(name);
  45.191 -        node.loggerRef = new WeakReference<Logger>(logger);
  45.192 +        node.loggerRef = ref;
  45.193          Logger parent = null;
  45.194          LogNode nodep = node.parent;
  45.195          while (nodep != null) {
  45.196 -            WeakReference<Logger> nodeRef = nodep.loggerRef;
  45.197 +            LoggerWeakRef nodeRef = nodep.loggerRef;
  45.198              if (nodeRef != null) {
  45.199                  parent = nodeRef.get();
  45.200                  if (parent != null) {
  45.201 @@ -489,6 +609,9 @@
  45.202          // Walk over the children and tell them we are their new parent.
  45.203          node.walkAndSetParent(logger);
  45.204  
  45.205 +        // new LogNode is ready so tell the LoggerWeakRef about it
  45.206 +        ref.setNode(node);
  45.207 +
  45.208          return true;
  45.209      }
  45.210  
  45.211 @@ -572,7 +695,7 @@
  45.212       * @return  matching logger or null if none is found
  45.213       */
  45.214      public synchronized Logger getLogger(String name) {
  45.215 -        WeakReference<Logger> ref = loggers.get(name);
  45.216 +        LoggerWeakRef ref = namedLoggers.get(name);
  45.217          if (ref == null) {
  45.218              return null;
  45.219          }
  45.220 @@ -580,7 +703,7 @@
  45.221          if (logger == null) {
  45.222              // Hashtable holds stale weak reference
  45.223              // to a logger which has been GC-ed.
  45.224 -            loggers.remove(name);
  45.225 +            namedLoggers.remove(name);
  45.226          }
  45.227          return logger;
  45.228      }
  45.229 @@ -594,7 +717,7 @@
  45.230       * @return  enumeration of logger name strings
  45.231       */
  45.232      public synchronized Enumeration<String> getLoggerNames() {
  45.233 -        return loggers.keys();
  45.234 +        return namedLoggers.keys();
  45.235      }
  45.236  
  45.237      /**
  45.238 @@ -942,7 +1065,7 @@
  45.239      // Nested class to represent a node in our tree of named loggers.
  45.240      private static class LogNode {
  45.241          HashMap<String,LogNode> children;
  45.242 -        WeakReference<Logger> loggerRef;
  45.243 +        LoggerWeakRef loggerRef;
  45.244          LogNode parent;
  45.245  
  45.246          LogNode(LogNode parent) {
  45.247 @@ -958,7 +1081,7 @@
  45.248              Iterator<LogNode> values = children.values().iterator();
  45.249              while (values.hasNext()) {
  45.250                  LogNode node = values.next();
  45.251 -                WeakReference<Logger> ref = node.loggerRef;
  45.252 +                LoggerWeakRef ref = node.loggerRef;
  45.253                  Logger logger = (ref == null) ? null : ref.get();
  45.254                  if (logger == null) {
  45.255                      node.walkAndSetParent(parent);
    46.1 --- a/src/share/classes/java/util/logging/Logger.java	Thu Jul 15 20:11:45 2010 -0700
    46.2 +++ b/src/share/classes/java/util/logging/Logger.java	Tue Jul 20 22:21:31 2010 -0700
    46.3 @@ -1,5 +1,5 @@
    46.4  /*
    46.5 - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
    46.6 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    46.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    46.8   *
    46.9   * This code is free software; you can redistribute it and/or modify it
   46.10 @@ -183,7 +183,7 @@
   46.11      // We keep weak references from parents to children, but strong
   46.12      // references from children to parents.
   46.13      private volatile Logger parent;    // our nearest parent.
   46.14 -    private ArrayList<WeakReference<Logger>> kids;   // WeakReferences to loggers that have us as parent
   46.15 +    private ArrayList<LogManager.LoggerWeakRef> kids;   // WeakReferences to loggers that have us as parent
   46.16      private volatile Level levelObject;
   46.17      private volatile int levelValue;  // current effective level value
   46.18  
   46.19 @@ -366,13 +366,8 @@
   46.20       *
   46.21       * @return a newly created private Logger
   46.22       */
   46.23 -    public static synchronized Logger getAnonymousLogger() {
   46.24 -        LogManager manager = LogManager.getLogManager();
   46.25 -        Logger result = new Logger(null, null);
   46.26 -        result.anonymous = true;
   46.27 -        Logger root = manager.getLogger("");
   46.28 -        result.doSetParent(root);
   46.29 -        return result;
   46.30 +    public static Logger getAnonymousLogger() {
   46.31 +        return getAnonymousLogger(null);
   46.32      }
   46.33  
   46.34      /**
   46.35 @@ -401,6 +396,8 @@
   46.36       */
   46.37      public static synchronized Logger getAnonymousLogger(String resourceBundleName) {
   46.38          LogManager manager = LogManager.getLogManager();
   46.39 +        // cleanup some Loggers that have been GC'ed
   46.40 +        manager.drainLoggerRefQueueBounded();
   46.41          Logger result = new Logger(null, resourceBundleName);
   46.42          result.anonymous = true;
   46.43          Logger root = manager.getLogger("");
   46.44 @@ -1380,14 +1377,18 @@
   46.45          synchronized (treeLock) {
   46.46  
   46.47              // Remove ourself from any previous parent.
   46.48 +            LogManager.LoggerWeakRef ref = null;
   46.49              if (parent != null) {
   46.50                  // assert parent.kids != null;
   46.51 -                for (Iterator<WeakReference<Logger>> iter = parent.kids.iterator(); iter.hasNext(); ) {
   46.52 -                    WeakReference<Logger> ref =  iter.next();
   46.53 +                for (Iterator<LogManager.LoggerWeakRef> iter = parent.kids.iterator(); iter.hasNext(); ) {
   46.54 +                    ref = iter.next();
   46.55                      Logger kid =  ref.get();
   46.56                      if (kid == this) {
   46.57 +                        // ref is used down below to complete the reparenting
   46.58                          iter.remove();
   46.59                          break;
   46.60 +                    } else {
   46.61 +                        ref = null;
   46.62                      }
   46.63                  }
   46.64                  // We have now removed ourself from our parents' kids.
   46.65 @@ -1396,9 +1397,14 @@
   46.66              // Set our new parent.
   46.67              parent = newParent;
   46.68              if (parent.kids == null) {
   46.69 -                parent.kids = new ArrayList<WeakReference<Logger>>(2);
   46.70 +                parent.kids = new ArrayList<LogManager.LoggerWeakRef>(2);
   46.71              }
   46.72 -            parent.kids.add(new WeakReference<Logger>(this));
   46.73 +            if (ref == null) {
   46.74 +                // we didn't have a previous parent
   46.75 +                ref = manager.new LoggerWeakRef(this);
   46.76 +            }
   46.77 +            ref.setParentRef(new WeakReference<Logger>(parent));
   46.78 +            parent.kids.add(ref);
   46.79  
   46.80              // As a result of the reparenting, the effective level
   46.81              // may have changed for us and our children.
   46.82 @@ -1407,6 +1413,21 @@
   46.83          }
   46.84      }
   46.85  
   46.86 +    // Package-level method.
   46.87 +    // Remove the weak reference for the specified child Logger from the
   46.88 +    // kid list. We should only be called from LoggerWeakRef.dispose().
   46.89 +    final void removeChildLogger(LogManager.LoggerWeakRef child) {
   46.90 +        synchronized (treeLock) {
   46.91 +            for (Iterator<LogManager.LoggerWeakRef> iter = kids.iterator(); iter.hasNext(); ) {
   46.92 +                LogManager.LoggerWeakRef ref = iter.next();
   46.93 +                if (ref == child) {
   46.94 +                    iter.remove();
   46.95 +                    return;
   46.96 +                }
   46.97 +            }
   46.98 +        }
   46.99 +    }
  46.100 +
  46.101      // Recalculate the effective level for this node and
  46.102      // recursively for our children.
  46.103  
  46.104 @@ -1438,7 +1459,7 @@
  46.105          // Recursively update the level on each of our kids.
  46.106          if (kids != null) {
  46.107              for (int i = 0; i < kids.size(); i++) {
  46.108 -                WeakReference<Logger> ref = kids.get(i);
  46.109 +                LogManager.LoggerWeakRef ref = kids.get(i);
  46.110                  Logger kid =  ref.get();
  46.111                  if (kid != null) {
  46.112                      kid.updateEffectiveLevel();
    47.1 --- a/src/share/classes/javax/imageio/stream/ImageInputStream.java	Thu Jul 15 20:11:45 2010 -0700
    47.2 +++ b/src/share/classes/javax/imageio/stream/ImageInputStream.java	Tue Jul 20 22:21:31 2010 -0700
    47.3 @@ -25,6 +25,7 @@
    47.4  
    47.5  package javax.imageio.stream;
    47.6  
    47.7 +import java.io.Closeable;
    47.8  import java.io.DataInput;
    47.9  import java.io.IOException;
   47.10  import java.nio.ByteOrder;
   47.11 @@ -42,7 +43,7 @@
   47.12   * @see MemoryCacheImageInputStream
   47.13   *
   47.14   */
   47.15 -public interface ImageInputStream extends DataInput {
   47.16 +public interface ImageInputStream extends DataInput, Closeable {
   47.17  
   47.18      /**
   47.19       * Sets the desired byte order for future reads of data values
    48.1 --- a/src/share/classes/javax/sound/midi/MidiDevice.java	Thu Jul 15 20:11:45 2010 -0700
    48.2 +++ b/src/share/classes/javax/sound/midi/MidiDevice.java	Tue Jul 20 22:21:31 2010 -0700
    48.3 @@ -107,7 +107,7 @@
    48.4   * @author Florian Bomers
    48.5   */
    48.6  
    48.7 -public interface MidiDevice {
    48.8 +public interface MidiDevice extends AutoCloseable {
    48.9  
   48.10  
   48.11      /**
    49.1 --- a/src/share/classes/javax/sound/midi/Receiver.java	Thu Jul 15 20:11:45 2010 -0700
    49.2 +++ b/src/share/classes/javax/sound/midi/Receiver.java	Tue Jul 20 22:21:31 2010 -0700
    49.3 @@ -38,7 +38,7 @@
    49.4   *
    49.5   * @author Kara Kytle
    49.6   */
    49.7 -public interface Receiver {
    49.8 +public interface Receiver extends AutoCloseable {
    49.9  
   49.10  
   49.11      //$$fb 2002-04-12: fix for 4662090: Contradiction in Receiver specification
    50.1 --- a/src/share/classes/javax/sound/midi/Transmitter.java	Thu Jul 15 20:11:45 2010 -0700
    50.2 +++ b/src/share/classes/javax/sound/midi/Transmitter.java	Tue Jul 20 22:21:31 2010 -0700
    50.3 @@ -35,7 +35,7 @@
    50.4   *
    50.5   * @author Kara Kytle
    50.6   */
    50.7 -public interface Transmitter {
    50.8 +public interface Transmitter extends AutoCloseable {
    50.9  
   50.10  
   50.11      /**
    51.1 --- a/src/share/classes/javax/sound/sampled/Line.java	Thu Jul 15 20:11:45 2010 -0700
    51.2 +++ b/src/share/classes/javax/sound/sampled/Line.java	Tue Jul 20 22:21:31 2010 -0700
    51.3 @@ -70,7 +70,7 @@
    51.4   * @see LineEvent
    51.5   * @since 1.3
    51.6   */
    51.7 -public interface Line {
    51.8 +public interface Line extends AutoCloseable {
    51.9  
   51.10      /**
   51.11       * Obtains the <code>Line.Info</code> object describing this
    52.1 --- a/src/share/classes/javax/swing/JSplitPane.java	Thu Jul 15 20:11:45 2010 -0700
    52.2 +++ b/src/share/classes/javax/swing/JSplitPane.java	Tue Jul 20 22:21:31 2010 -0700
    52.3 @@ -242,19 +242,19 @@
    52.4  
    52.5      /**
    52.6       * Creates a new <code>JSplitPane</code> configured to arrange the child
    52.7 -     * components side-by-side horizontally with no continuous
    52.8 -     * layout, using two buttons for the components.
    52.9 +     * components side-by-side horizontally, using two buttons for the components.
   52.10       */
   52.11      public JSplitPane() {
   52.12 -        this(JSplitPane.HORIZONTAL_SPLIT, false,
   52.13 -            new JButton(UIManager.getString("SplitPane.leftButtonText")),
   52.14 -            new JButton(UIManager.getString("SplitPane.rightButtonText")));
   52.15 +        this(JSplitPane.HORIZONTAL_SPLIT,
   52.16 +                UIManager.getBoolean("SplitPane.continuousLayout"),
   52.17 +                new JButton(UIManager.getString("SplitPane.leftButtonText")),
   52.18 +                new JButton(UIManager.getString("SplitPane.rightButtonText")));
   52.19      }
   52.20  
   52.21  
   52.22      /**
   52.23       * Creates a new <code>JSplitPane</code> configured with the
   52.24 -     * specified orientation and no continuous layout.
   52.25 +     * specified orientation.
   52.26       *
   52.27       * @param newOrientation  <code>JSplitPane.HORIZONTAL_SPLIT</code> or
   52.28       *                        <code>JSplitPane.VERTICAL_SPLIT</code>
   52.29 @@ -263,7 +263,8 @@
   52.30       */
   52.31      @ConstructorProperties({"orientation"})
   52.32      public JSplitPane(int newOrientation) {
   52.33 -        this(newOrientation, false);
   52.34 +        this(newOrientation,
   52.35 +                UIManager.getBoolean("SplitPane.continuousLayout"));
   52.36      }
   52.37  
   52.38  
   52.39 @@ -287,9 +288,7 @@
   52.40  
   52.41      /**
   52.42       * Creates a new <code>JSplitPane</code> with the specified
   52.43 -     * orientation and
   52.44 -     * with the specified components that do not do continuous
   52.45 -     * redrawing.
   52.46 +     * orientation and the specified components.
   52.47       *
   52.48       * @param newOrientation  <code>JSplitPane.HORIZONTAL_SPLIT</code> or
   52.49       *                        <code>JSplitPane.VERTICAL_SPLIT</code>
   52.50 @@ -307,7 +306,9 @@
   52.51      public JSplitPane(int newOrientation,
   52.52                        Component newLeftComponent,
   52.53                        Component newRightComponent){
   52.54 -        this(newOrientation, false, newLeftComponent, newRightComponent);
   52.55 +        this(newOrientation,
   52.56 +                UIManager.getBoolean("SplitPane.continuousLayout"),
   52.57 +                newLeftComponent, newRightComponent);
   52.58      }
   52.59  
   52.60  
    53.1 --- a/src/share/classes/javax/swing/JTable.java	Thu Jul 15 20:11:45 2010 -0700
    53.2 +++ b/src/share/classes/javax/swing/JTable.java	Tue Jul 20 22:21:31 2010 -0700
    53.3 @@ -1048,7 +1048,7 @@
    53.4  
    53.5      /**
    53.6       * Returns the horizontal and vertical space between cells.
    53.7 -     * The default spacing is (1, 1), which provides room to draw the grid.
    53.8 +     * The default spacing is look and feel dependent.
    53.9       *
   53.10       * @return  the horizontal and vertical spacing between cells
   53.11       * @see     #setIntercellSpacing
   53.12 @@ -1155,7 +1155,7 @@
   53.13  
   53.14      /**
   53.15       * Returns true if the table draws horizontal lines between cells, false if it
   53.16 -     * doesn't. The default is true.
   53.17 +     * doesn't. The default value is look and feel dependent.
   53.18       *
   53.19       * @return  true if the table draws horizontal lines between cells, false if it
   53.20       *          doesn't
   53.21 @@ -1167,7 +1167,7 @@
   53.22  
   53.23      /**
   53.24       * Returns true if the table draws vertical lines between cells, false if it
   53.25 -     * doesn't. The default is true.
   53.26 +     * doesn't. The default value is look and feel dependent.
   53.27       *
   53.28       * @return  true if the table draws vertical lines between cells, false if it
   53.29       *          doesn't
    54.1 --- a/src/share/classes/javax/swing/JTree.java	Thu Jul 15 20:11:45 2010 -0700
    54.2 +++ b/src/share/classes/javax/swing/JTree.java	Tue Jul 20 22:21:31 2010 -0700
    54.3 @@ -1986,20 +1986,17 @@
    54.4       *               true if all nodes in the path are expanded
    54.5       */
    54.6      public boolean isExpanded(TreePath path) {
    54.7 +
    54.8          if(path == null)
    54.9              return false;
   54.10 -
   54.11 -        // Is this node expanded?
   54.12 -        Boolean value = expandedState.get(path);
   54.13 -
   54.14 -        if(value == null || !value.booleanValue())
   54.15 -            return false;
   54.16 -
   54.17 -        // It is, make sure its parent is also expanded.
   54.18 -        TreePath        parentPath = path.getParentPath();
   54.19 -
   54.20 -        if(parentPath != null)
   54.21 -            return isExpanded(parentPath);
   54.22 +        Object  value;
   54.23 +
   54.24 +        do{
   54.25 +            value = expandedState.get(path);
   54.26 +            if(value == null || !((Boolean)value).booleanValue())
   54.27 +                return false;
   54.28 +        } while( (path=path.getParentPath())!=null );
   54.29 +
   54.30          return true;
   54.31      }
   54.32  
    55.1 --- a/src/share/classes/javax/swing/border/TitledBorder.java	Thu Jul 15 20:11:45 2010 -0700
    55.2 +++ b/src/share/classes/javax/swing/border/TitledBorder.java	Tue Jul 20 22:21:31 2010 -0700
    55.3 @@ -1,5 +1,5 @@
    55.4  /*
    55.5 - * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
    55.6 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
    55.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    55.8   *
    55.9   * This code is free software; you can redistribute it and/or modify it
   55.10 @@ -24,22 +24,20 @@
   55.11   */
   55.12  package javax.swing.border;
   55.13  
   55.14 -import sun.swing.SwingUtilities2;
   55.15 -
   55.16 +import java.awt.Color;
   55.17 +import java.awt.Component;
   55.18 +import java.awt.Dimension;
   55.19 +import java.awt.Font;
   55.20  import java.awt.Graphics;
   55.21 +import java.awt.Graphics2D;
   55.22  import java.awt.Insets;
   55.23  import java.awt.Rectangle;
   55.24 -import java.awt.Color;
   55.25 -import java.awt.Font;
   55.26 -import java.awt.FontMetrics;
   55.27 -import java.awt.Point;
   55.28 -import java.awt.Toolkit;
   55.29 -import java.awt.Component;
   55.30 -import java.awt.Dimension;
   55.31 +import java.awt.geom.Path2D;
   55.32  import java.beans.ConstructorProperties;
   55.33 -
   55.34  import javax.swing.JComponent;
   55.35 +import javax.swing.JLabel;
   55.36  import javax.swing.UIManager;
   55.37 +import javax.swing.plaf.basic.BasicHTML;
   55.38  
   55.39  /**
   55.40   * A class which implements an arbitrary border
   55.41 @@ -73,40 +71,40 @@
   55.42  {
   55.43      protected String title;
   55.44      protected Border border;
   55.45 -    protected int    titlePosition;
   55.46 -    protected int    titleJustification;
   55.47 -    protected Font   titleFont;
   55.48 -    protected Color  titleColor;
   55.49 +    protected int titlePosition;
   55.50 +    protected int titleJustification;
   55.51 +    protected Font titleFont;
   55.52 +    protected Color titleColor;
   55.53  
   55.54 -    private Point textLoc = new Point();
   55.55 +    private final JLabel label;
   55.56  
   55.57      /**
   55.58       * Use the default vertical orientation for the title text.
   55.59       */
   55.60      static public final int     DEFAULT_POSITION        = 0;
   55.61      /** Position the title above the border's top line. */
   55.62 -    static public final int     ABOVE_TOP       = 1;
   55.63 +    static public final int     ABOVE_TOP               = 1;
   55.64      /** Position the title in the middle of the border's top line. */
   55.65 -    static public final int     TOP             = 2;
   55.66 +    static public final int     TOP                     = 2;
   55.67      /** Position the title below the border's top line. */
   55.68 -    static public final int     BELOW_TOP       = 3;
   55.69 +    static public final int     BELOW_TOP               = 3;
   55.70      /** Position the title above the border's bottom line. */
   55.71 -    static public final int     ABOVE_BOTTOM    = 4;
   55.72 +    static public final int     ABOVE_BOTTOM            = 4;
   55.73      /** Position the title in the middle of the border's bottom line. */
   55.74 -    static public final int     BOTTOM          = 5;
   55.75 +    static public final int     BOTTOM                  = 5;
   55.76      /** Position the title below the border's bottom line. */
   55.77 -    static public final int     BELOW_BOTTOM    = 6;
   55.78 +    static public final int     BELOW_BOTTOM            = 6;
   55.79  
   55.80      /**
   55.81       * Use the default justification for the title text.
   55.82       */
   55.83      static public final int     DEFAULT_JUSTIFICATION   = 0;
   55.84      /** Position title text at the left side of the border line. */
   55.85 -    static public final int     LEFT    = 1;
   55.86 +    static public final int     LEFT                    = 1;
   55.87      /** Position title text in the center of the border line. */
   55.88 -    static public final int     CENTER  = 2;
   55.89 +    static public final int     CENTER                  = 2;
   55.90      /** Position title text at the right side of the border line. */
   55.91 -    static public final int     RIGHT   = 3;
   55.92 +    static public final int     RIGHT                   = 3;
   55.93      /** Position title text at the left side of the border line
   55.94       *  for left to right orientation, at the right side of the
   55.95       *  border line for right to left orientation.
   55.96 @@ -132,7 +130,7 @@
   55.97       *
   55.98       * @param title  the title the border should display
   55.99       */
  55.100 -    public TitledBorder(String title)     {
  55.101 +    public TitledBorder(String title) {
  55.102          this(null, title, LEADING, DEFAULT_POSITION, null, null);
  55.103      }
  55.104  
  55.105 @@ -142,7 +140,7 @@
  55.106       *
  55.107       * @param border  the border
  55.108       */
  55.109 -    public TitledBorder(Border border)       {
  55.110 +    public TitledBorder(Border border) {
  55.111          this(border, "", LEADING, DEFAULT_POSITION, null, null);
  55.112      }
  55.113  
  55.114 @@ -167,9 +165,9 @@
  55.115       * @param titlePosition the position for the title
  55.116       */
  55.117      public TitledBorder(Border border,
  55.118 -                        String title,
  55.119 -                        int titleJustification,
  55.120 -                        int titlePosition)      {
  55.121 +                         String title,
  55.122 +                         int titleJustification,
  55.123 +                         int titlePosition) {
  55.124          this(border, title, titleJustification,
  55.125                          titlePosition, null, null);
  55.126      }
  55.127 @@ -185,10 +183,10 @@
  55.128       * @param titleFont the font for rendering the title
  55.129       */
  55.130      public TitledBorder(Border border,
  55.131 -                        String title,
  55.132 -                        int titleJustification,
  55.133 -                        int titlePosition,
  55.134 -                        Font titleFont) {
  55.135 +                         String title,
  55.136 +                         int titleJustification,
  55.137 +                         int titlePosition,
  55.138 +                         Font titleFont) {
  55.139          this(border, title, titleJustification,
  55.140                          titlePosition, titleFont, null);
  55.141      }
  55.142 @@ -207,11 +205,11 @@
  55.143       */
  55.144      @ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"})
  55.145      public TitledBorder(Border border,
  55.146 -                        String title,
  55.147 -                        int titleJustification,
  55.148 -                        int titlePosition,
  55.149 -                        Font titleFont,
  55.150 -                        Color titleColor)       {
  55.151 +                         String title,
  55.152 +                         int titleJustification,
  55.153 +                         int titlePosition,
  55.154 +                         Font titleFont,
  55.155 +                         Color titleColor) {
  55.156          this.title = title;
  55.157          this.border = border;
  55.158          this.titleFont = titleFont;
  55.159 @@ -219,6 +217,10 @@
  55.160  
  55.161          setTitleJustification(titleJustification);
  55.162          setTitlePosition(titlePosition);
  55.163 +
  55.164 +        this.label = new JLabel();
  55.165 +        this.label.setOpaque(false);
  55.166 +        this.label.putClientProperty(BasicHTML.propertyKey, null);
  55.167      }
  55.168  
  55.169      /**
  55.170 @@ -232,178 +234,111 @@
  55.171       * @param height the height of the painted border
  55.172       */
  55.173      public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  55.174 +        Border border = getBorderUI();
  55.175 +        String title = getTitle();
  55.176 +        if ((title != null) && !title.isEmpty()) {
  55.177 +            int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING;
  55.178 +            JLabel label = getLabel(c);
  55.179 +            Dimension size = label.getPreferredSize();
  55.180 +            Insets insets = (border != null)
  55.181 +                    ? border.getBorderInsets(c)
  55.182 +                    : new Insets(0, 0, 0, 0);
  55.183  
  55.184 -        Border border = getBorder();
  55.185 +            int borderX = x + edge;
  55.186 +            int borderY = y + edge;
  55.187 +            int borderW = width - edge - edge;
  55.188 +            int borderH = height - edge - edge;
  55.189  
  55.190 -        if (getTitle() == null || getTitle().equals("")) {
  55.191 +            int labelY = y;
  55.192 +            int labelH = size.height;
  55.193 +            int position = getPosition();
  55.194 +            switch (position) {
  55.195 +                case ABOVE_TOP:
  55.196 +                    insets.left = 0;
  55.197 +                    insets.right = 0;
  55.198 +                    borderY += labelH - edge;
  55.199 +                    borderH -= labelH - edge;
  55.200 +                    break;
  55.201 +                case TOP:
  55.202 +                    insets.top = edge + insets.top/2 - labelH/2;
  55.203 +                    if (insets.top < edge) {
  55.204 +                        borderY -= insets.top;
  55.205 +                        borderH += insets.top;
  55.206 +                    }
  55.207 +                    else {
  55.208 +                        labelY += insets.top;
  55.209 +                    }
  55.210 +                    break;
  55.211 +                case BELOW_TOP:
  55.212 +                    labelY += insets.top + edge;
  55.213 +                    break;
  55.214 +                case ABOVE_BOTTOM:
  55.215 +                    labelY += height - labelH - insets.bottom - edge;
  55.216 +                    break;
  55.217 +                case BOTTOM:
  55.218 +                    labelY += height - labelH;
  55.219 +                    insets.bottom = edge + (insets.bottom - labelH) / 2;
  55.220 +                    if (insets.bottom < edge) {
  55.221 +                        borderH += insets.bottom;
  55.222 +                    }
  55.223 +                    else {
  55.224 +                        labelY -= insets.bottom;
  55.225 +                    }
  55.226 +                    break;
  55.227 +                case BELOW_BOTTOM:
  55.228 +                    insets.left = 0;
  55.229 +                    insets.right = 0;
  55.230 +                    labelY += height - labelH;
  55.231 +                    borderH -= labelH - edge;
  55.232 +                    break;
  55.233 +            }
  55.234 +            insets.left += edge + TEXT_INSET_H;
  55.235 +            insets.right += edge + TEXT_INSET_H;
  55.236 +
  55.237 +            int labelX = x;
  55.238 +            int labelW = width - insets.left - insets.right;
  55.239 +            if (labelW > size.width) {
  55.240 +                labelW = size.width;
  55.241 +            }
  55.242 +            switch (getJustification(c)) {
  55.243 +                case LEFT:
  55.244 +                    labelX += insets.left;
  55.245 +                    break;
  55.246 +                case RIGHT:
  55.247 +                    labelX += width - insets.right - labelW;
  55.248 +                    break;
  55.249 +                case CENTER:
  55.250 +                    labelX += (width - labelW) / 2;
  55.251 +                    break;
  55.252 +            }
  55.253 +
  55.254              if (border != null) {
  55.255 -                border.paintBorder(c, g, x, y, width, height);
  55.256 +                if ((position != TOP) && (position != BOTTOM)) {
  55.257 +                    border.paintBorder(c, g, borderX, borderY, borderW, borderH);
  55.258 +                }
  55.259 +                else {
  55.260 +                    Graphics g2 = g.create();
  55.261 +                    if (g2 instanceof Graphics2D) {
  55.262 +                        Graphics2D g2d = (Graphics2D) g2;
  55.263 +                        Path2D path = new Path2D.Float();
  55.264 +                        path.append(new Rectangle(borderX, borderY, borderW, labelY - borderY), false);
  55.265 +                        path.append(new Rectangle(borderX, labelY, labelX - borderX - TEXT_SPACING, labelH), false);
  55.266 +                        path.append(new Rectangle(labelX + labelW + TEXT_SPACING, labelY, borderX - labelX + borderW - labelW - TEXT_SPACING, labelH), false);
  55.267 +                        path.append(new Rectangle(borderX, labelY + labelH, borderW, borderY - labelY + borderH - labelH), false);
  55.268 +                        g2d.clip(path);
  55.269 +                    }
  55.270 +                    border.paintBorder(c, g2, borderX, borderY, borderW, borderH);
  55.271 +                    g2.dispose();
  55.272 +                }
  55.273              }
  55.274 -            return;
  55.275 +            g.translate(labelX, labelY);
  55.276 +            label.setSize(labelW, labelH);
  55.277 +            label.paint(g);
  55.278 +            g.translate(-labelX, -labelY);
  55.279          }
  55.280 -
  55.281 -        Rectangle grooveRect = new Rectangle(x + EDGE_SPACING, y + EDGE_SPACING,
  55.282 -                                             width - (EDGE_SPACING * 2),
  55.283 -                                             height - (EDGE_SPACING * 2));
  55.284 -        Font font = g.getFont();
  55.285 -        Color color = g.getColor();
  55.286 -
  55.287 -        g.setFont(getFont(c));
  55.288 -
  55.289 -        JComponent jc = (c instanceof JComponent) ? (JComponent)c : null;
  55.290 -        FontMetrics fm = SwingUtilities2.getFontMetrics(jc, g);
  55.291 -        int         fontHeight = fm.getHeight();
  55.292 -        int         descent = fm.getDescent();
  55.293 -        int         ascent = fm.getAscent();
  55.294 -        int         diff;
  55.295 -        int         stringWidth = SwingUtilities2.stringWidth(jc, fm,
  55.296 -                                                              getTitle());
  55.297 -        Insets      insets;
  55.298 -
  55.299 -        if (border != null) {
  55.300 -            insets = border.getBorderInsets(c);
  55.301 -        } else {
  55.302 -            insets = new Insets(0, 0, 0, 0);
  55.303 +        else if (border != null) {
  55.304 +            border.paintBorder(c, g, x, y, width, height);
  55.305          }
  55.306 -
  55.307 -        int titlePos = getTitlePosition();
  55.308 -        switch (titlePos) {
  55.309 -            case ABOVE_TOP:
  55.310 -                diff = ascent + descent + (Math.max(EDGE_SPACING,
  55.311 -                                 TEXT_SPACING*2) - EDGE_SPACING);
  55.312 -                grooveRect.y += diff;
  55.313 -                grooveRect.height -= diff;
  55.314 -                textLoc.y = grooveRect.y - (descent + TEXT_SPACING);
  55.315 -                break;
  55.316 -            case TOP:
  55.317 -            case DEFAULT_POSITION:
  55.318 -                diff = Math.max(0, ((ascent/2) + TEXT_SPACING) - EDGE_SPACING);
  55.319 -                grooveRect.y += diff;
  55.320 -                grooveRect.height -= diff;
  55.321 -                textLoc.y = (grooveRect.y - descent) +
  55.322 -                (insets.top + ascent + descent)/2;
  55.323 -                break;
  55.324 -            case BELOW_TOP:
  55.325 -                textLoc.y = grooveRect.y + insets.top + ascent + TEXT_SPACING;
  55.326 -                break;
  55.327 -            case ABOVE_BOTTOM:
  55.328 -                textLoc.y = (grooveRect.y + grooveRect.height) -
  55.329 -                (insets.bottom + descent + TEXT_SPACING);
  55.330 -                break;
  55.331 -            case BOTTOM:
  55.332 -                grooveRect.height -= fontHeight/2;
  55.333 -                textLoc.y = ((grooveRect.y + grooveRect.height) - descent) +
  55.334 -                        ((ascent + descent) - insets.bottom)/2;
  55.335 -                break;
  55.336 -            case BELOW_BOTTOM:
  55.337 -                grooveRect.height -= fontHeight;
  55.338 -                textLoc.y = grooveRect.y + grooveRect.height + ascent +
  55.339 -                        TEXT_SPACING;
  55.340 -                break;
  55.341 -        }
  55.342 -
  55.343 -        int justification = getTitleJustification();
  55.344 -        if(isLeftToRight(c)) {
  55.345 -            if(justification==LEADING ||
  55.346 -               justification==DEFAULT_JUSTIFICATION) {
  55.347 -                justification = LEFT;
  55.348 -            }
  55.349 -            else if(justification==TRAILING) {
  55.350 -                justification = RIGHT;
  55.351 -            }
  55.352 -        }
  55.353 -        else {
  55.354 -            if(justification==LEADING ||
  55.355 -               justification==DEFAULT_JUSTIFICATION) {
  55.356 -                justification = RIGHT;
  55.357 -            }
  55.358 -            else if(justification==TRAILING) {
  55.359 -                justification = LEFT;
  55.360 -            }
  55.361 -        }
  55.362 -
  55.363 -        switch (justification) {
  55.364 -            case LEFT:
  55.365 -                textLoc.x = grooveRect.x + TEXT_INSET_H + insets.left;
  55.366 -                break;
  55.367 -            case RIGHT:
  55.368 -                textLoc.x = (grooveRect.x + grooveRect.width) -
  55.369 -                        (stringWidth + TEXT_INSET_H + insets.right);
  55.370 -                break;
  55.371 -            case CENTER:
  55.372 -                textLoc.x = grooveRect.x +
  55.373 -                        ((grooveRect.width - stringWidth) / 2);
  55.374 -                break;
  55.375 -        }
  55.376 -
  55.377 -        // If title is positioned in middle of border AND its fontsize
  55.378 -        // is greater than the border's thickness, we'll need to paint
  55.379 -        // the border in sections to leave space for the component's background
  55.380 -        // to show through the title.
  55.381 -        //
  55.382 -        if (border != null) {
  55.383 -            if (((titlePos == TOP || titlePos == DEFAULT_POSITION) &&
  55.384 -                  (grooveRect.y > textLoc.y - ascent)) ||
  55.385 -                 (titlePos == BOTTOM &&
  55.386 -                  (grooveRect.y + grooveRect.height < textLoc.y + descent))) {
  55.387 -
  55.388 -                Rectangle clipRect = new Rectangle();
  55.389 -
  55.390 -                // save original clip
  55.391 -                Rectangle saveClip = g.getClipBounds();
  55.392 -
  55.393 -                // paint strip left of text
  55.394 -                clipRect.setBounds(saveClip);
  55.395 -                if (computeIntersection(clipRect, x, y, textLoc.x-1-x, height)) {
  55.396 -                    g.setClip(clipRect);
  55.397 -                    border.paintBorder(c, g, grooveRect.x, grooveRect.y,
  55.398 -                                  grooveRect.width, grooveRect.height);
  55.399 -                }
  55.400 -
  55.401 -                // paint strip right of text
  55.402 -                clipRect.setBounds(saveClip);
  55.403 -                if (computeIntersection(clipRect, textLoc.x+stringWidth+1, y,
  55.404 -                               x+width-(textLoc.x+stringWidth+1), height)) {
  55.405 -                    g.setClip(clipRect);
  55.406 -                    border.paintBorder(c, g, grooveRect.x, grooveRect.y,
  55.407 -                                  grooveRect.width, grooveRect.height);
  55.408 -                }
  55.409 -
  55.410 -                if (titlePos == TOP || titlePos == DEFAULT_POSITION) {
  55.411 -                    // paint strip below text
  55.412 -                    clipRect.setBounds(saveClip);
  55.413 -                    if (computeIntersection(clipRect, textLoc.x-1, textLoc.y+descent,
  55.414 -                                        stringWidth+2, y+height-textLoc.y-descent)) {
  55.415 -                        g.setClip(clipRect);
  55.416 -                        border.paintBorder(c, g, grooveRect.x, grooveRect.y,
  55.417 -                                  grooveRect.width, grooveRect.height);
  55.418 -                    }
  55.419 -
  55.420 -                } else { // titlePos == BOTTOM
  55.421 -                  // paint strip above text
  55.422 -                    clipRect.setBounds(saveClip);
  55.423 -                    if (computeIntersection(clipRect, textLoc.x-1, y,
  55.424 -                          stringWidth+2, textLoc.y - ascent - y)) {
  55.425 -                        g.setClip(clipRect);
  55.426 -                        border.paintBorder(c, g, grooveRect.x, grooveRect.y,
  55.427 -                                  grooveRect.width, grooveRect.height);
  55.428 -                    }
  55.429 -                }
  55.430 -
  55.431 -                // restore clip
  55.432 -                g.setClip(saveClip);
  55.433 -
  55.434 -            } else {
  55.435 -                border.paintBorder(c, g, grooveRect.x, grooveRect.y,
  55.436 -                                  grooveRect.width, grooveRect.height);
  55.437 -            }
  55.438 -        }
  55.439 -
  55.440 -        g.setColor(getTitleColor());
  55.441 -        SwingUtilities2.drawString(jc, g, getTitle(), textLoc.x, textLoc.y);
  55.442 -
  55.443 -        g.setFont(font);
  55.444 -        g.setColor(color);
  55.445      }
  55.446  
  55.447      /**
  55.448 @@ -412,69 +347,54 @@
  55.449       * @param insets the object to be reinitialized
  55.450       */
  55.451      public Insets getBorderInsets(Component c, Insets insets) {
  55.452 -        FontMetrics fm;
  55.453 -        int         descent = 0;
  55.454 -        int         ascent = 16;
  55.455 -        int         height = 16;
  55.456 +        Border border = getBorderUI();
  55.457 +        if (border == null) {
  55.458 +            insets.set(0, 0, 0, 0);
  55.459 +        }
  55.460 +        else if (border instanceof AbstractBorder) {
  55.461 +            AbstractBorder ab = (AbstractBorder) border;
  55.462 +            insets = ab.getBorderInsets(c, insets);
  55.463 +        }
  55.464 +        else {
  55.465 +            Insets i = border.getBorderInsets(c);
  55.466 +            insets.set(i.top, i.left, i.bottom, i.right);
  55.467 +        }
  55.468 +        String title = getTitle();
  55.469 +        if ((title != null) && !title.isEmpty()) {
  55.470 +            int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING;
  55.471 +            JLabel label = getLabel(c);
  55.472 +            Dimension size = label.getPreferredSize();
  55.473  
  55.474 -        Border border = getBorder();
  55.475 -        if (border != null) {
  55.476 -            if (border instanceof AbstractBorder) {
  55.477 -                ((AbstractBorder)border).getBorderInsets(c, insets);
  55.478 -            } else {
  55.479 -                // Can't reuse border insets because the Border interface
  55.480 -                // can't be enhanced.
  55.481 -                Insets i = border.getBorderInsets(c);
  55.482 -                insets.top = i.top;
  55.483 -                insets.right = i.right;
  55.484 -                insets.bottom = i.bottom;
  55.485 -                insets.left = i.left;
  55.486 +            switch (getPosition()) {
  55.487 +                case ABOVE_TOP:
  55.488 +                    insets.top += size.height - edge;
  55.489 +                    break;
  55.490 +                case TOP: {
  55.491 +                    if (insets.top < size.height) {
  55.492 +                        insets.top = size.height - edge;
  55.493 +                    }
  55.494 +                    break;
  55.495 +                }
  55.496 +                case BELOW_TOP:
  55.497 +                    insets.top += size.height;
  55.498 +                    break;
  55.499 +                case ABOVE_BOTTOM:
  55.500 +                    insets.bottom += size.height;
  55.501 +                    break;
  55.502 +                case BOTTOM: {
  55.503 +                    if (insets.bottom < size.height) {
  55.504 +                        insets.bottom = size.height - edge;
  55.505 +                    }
  55.506 +                    break;
  55.507 +                }
  55.508 +                case BELOW_BOTTOM:
  55.509 +                    insets.bottom += size.height - edge;
  55.510 +                    break;
  55.511              }
  55.512 -        } else {
  55.513 -            insets.left = insets.top = insets.right = insets.bottom = 0;
  55.514 -        }
  55.515 -
  55.516 -        insets.left += EDGE_SPACING + TEXT_SPACING;
  55.517 -        insets.right += EDGE_SPACING + TEXT_SPACING;
  55.518 -        insets.top += EDGE_SPACING + TEXT_SPACING;
  55.519 -        insets.bottom += EDGE_SPACING + TEXT_SPACING;
  55.520 -
  55.521 -        if(c == null || getTitle() == null || getTitle().equals(""))    {
  55.522 -            return insets;
  55.523 -        }
  55.524 -
  55.525 -        Font font = getFont(c);
  55.526 -
  55.527 -        fm = c.getFontMetrics(font);
  55.528 -
  55.529 -        if(fm != null) {
  55.530 -           descent = fm.getDescent();
  55.531 -           ascent = fm.getAscent();
  55.532 -           height = fm.getHeight();
  55.533 -        }
  55.534 -
  55.535 -        switch (getTitlePosition()) {
  55.536 -          case ABOVE_TOP:
  55.537 -              insets.top += ascent + descent
  55.538 -                            + (Math.max(EDGE_SPACING, TEXT_SPACING*2)
  55.539 -                            - EDGE_SPACING);
  55.540 -              break;
  55.541 -          case TOP:
  55.542 -          case DEFAULT_POSITION:
  55.543 -              insets.top += ascent + descent;
  55.544 -              break;
  55.545 -          case BELOW_TOP:
  55.546 -              insets.top += ascent + descent + TEXT_SPACING;
  55.547 -              break;
  55.548 -          case ABOVE_BOTTOM:
  55.549 -              insets.bottom += ascent + descent + TEXT_SPACING;
  55.550 -              break;
  55.551 -          case BOTTOM:
  55.552 -              insets.bottom += ascent + descent;
  55.553 -              break;
  55.554 -          case BELOW_BOTTOM:
  55.555 -              insets.bottom += height;
  55.556 -              break;
  55.557 +            insets.top += edge + TEXT_SPACING;
  55.558 +            insets.left += edge + TEXT_SPACING;
  55.559 +            insets.right += edge + TEXT_SPACING;
  55.560 +            insets.bottom += edge + TEXT_SPACING;
  55.561          }
  55.562          return insets;
  55.563      }
  55.564 @@ -492,41 +412,14 @@
  55.565      /**
  55.566       * Returns the border of the titled border.
  55.567       */
  55.568 -    public Border getBorder()       {
  55.569 -        Border b = border;
  55.570 -        if (b == null)
  55.571 -            b = UIManager.getBorder("TitledBorder.border");
  55.572 -        return b;
  55.573 +    public Border getBorder() {
  55.574 +        return border;
  55.575      }
  55.576  
  55.577      /**
  55.578       * Returns the title-position of the titled border.
  55.579       */
  55.580      public int getTitlePosition() {
  55.581 -        if (titlePosition == DEFAULT_POSITION) {
  55.582 -            Object value = UIManager.get("TitledBorder.position");
  55.583 -            if (value instanceof String) {
  55.584 -                String s = (String)value;
  55.585 -                if ("ABOVE_TOP".equalsIgnoreCase(s)) {
  55.586 -                    return ABOVE_TOP;
  55.587 -                } else if ("TOP".equalsIgnoreCase(s)) {
  55.588 -                    return TOP;
  55.589 -                } else if ("BELOW_TOP".equalsIgnoreCase(s)) {
  55.590 -                    return BELOW_TOP;
  55.591 -                } else if ("ABOVE_BOTTOM".equalsIgnoreCase(s)) {
  55.592 -                    return ABOVE_BOTTOM;
  55.593 -                } else if ("BOTTOM".equalsIgnoreCase(s)) {
  55.594 -                    return BOTTOM;
  55.595 -                } else if ("BELOW_BOTTOM".equalsIgnoreCase(s)) {
  55.596 -                    return BELOW_BOTTOM;
  55.597 -                }
  55.598 -            } else if (value instanceof Integer) {
  55.599 -                int i = (Integer)value;
  55.600 -                if (i >= 0 && i <= 6) {
  55.601 -                    return i;
  55.602 -                }
  55.603 -            }
  55.604 -        }
  55.605          return titlePosition;
  55.606      }
  55.607  
  55.608 @@ -539,20 +432,14 @@
  55.609       * Returns the title-font of the titled border.
  55.610       */
  55.611      public Font getTitleFont()      {
  55.612 -        Font f = titleFont;
  55.613 -        if (f == null)
  55.614 -            f = UIManager.getFont("TitledBorder.font");
  55.615 -        return f;
  55.616 +        return titleFont;
  55.617      }
  55.618  
  55.619      /**
  55.620       * Returns the title-color of the titled border.
  55.621       */
  55.622      public Color getTitleColor()    {
  55.623 -        Color c = titleColor;
  55.624 -        if (c == null)
  55.625 -            c = UIManager.getColor("TitledBorder.titleColor");
  55.626 -        return c;
  55.627 +        return titleColor;
  55.628      }
  55.629  
  55.630  
  55.631 @@ -576,18 +463,18 @@
  55.632       */
  55.633      public void setTitlePosition(int titlePosition) {
  55.634          switch (titlePosition) {
  55.635 -          case ABOVE_TOP:
  55.636 -          case TOP:
  55.637 -          case BELOW_TOP:
  55.638 -          case ABOVE_BOTTOM:
  55.639 -          case BOTTOM:
  55.640 -          case BELOW_BOTTOM:
  55.641 -          case DEFAULT_POSITION:
  55.642 +            case ABOVE_TOP:
  55.643 +            case TOP:
  55.644 +            case BELOW_TOP:
  55.645 +            case ABOVE_BOTTOM:
  55.646 +            case BOTTOM:
  55.647 +            case BELOW_BOTTOM:
  55.648 +            case DEFAULT_POSITION:
  55.649                  this.titlePosition = titlePosition;
  55.650                  break;
  55.651 -          default:
  55.652 -            throw new IllegalArgumentException(titlePosition +
  55.653 -                                        " is not a valid title position.");
  55.654 +            default:
  55.655 +                throw new IllegalArgumentException(titlePosition +
  55.656 +                        " is not a valid title position.");
  55.657          }
  55.658      }
  55.659  
  55.660 @@ -624,7 +511,7 @@
  55.661       * @param titleColor the color for the border title
  55.662       */
  55.663      public void setTitleColor(Color titleColor) {
  55.664 -      this.titleColor = titleColor;
  55.665 +        this.titleColor = titleColor;
  55.666      }
  55.667  
  55.668      /**
  55.669 @@ -636,22 +523,18 @@
  55.670          Insets insets = getBorderInsets(c);
  55.671          Dimension minSize = new Dimension(insets.right+insets.left,
  55.672                                            insets.top+insets.bottom);
  55.673 -        Font font = getFont(c);
  55.674 -        FontMetrics fm = c.getFontMetrics(font);
  55.675 -        JComponent jc = (c instanceof JComponent) ? (JComponent)c : null;
  55.676 -        switch (getTitlePosition()) {
  55.677 -          case ABOVE_TOP:
  55.678 -          case BELOW_BOTTOM:
  55.679 -              minSize.width = Math.max(SwingUtilities2.stringWidth(jc, fm,
  55.680 -                                       getTitle()), minSize.width);
  55.681 -              break;
  55.682 -          case BELOW_TOP:
  55.683 -          case ABOVE_BOTTOM:
  55.684 -          case TOP:
  55.685 -          case BOTTOM:
  55.686 -          case DEFAULT_POSITION:
  55.687 -          default:
  55.688 -              minSize.width += SwingUtilities2.stringWidth(jc, fm, getTitle());
  55.689 +        String title = getTitle();
  55.690 +        if ((title != null) && !title.isEmpty()) {
  55.691 +            JLabel label = getLabel(c);
  55.692 +            Dimension size = label.getPreferredSize();
  55.693 +
  55.694 +            int position = getPosition();
  55.695 +            if ((position != ABOVE_TOP) && (position != BELOW_BOTTOM)) {
  55.696 +                minSize.width += size.width;
  55.697 +            }
  55.698 +            else if (minSize.width < size.width) {
  55.699 +                minSize.width += size.width;
  55.700 +            }
  55.701          }
  55.702          return minSize;
  55.703      }
  55.704 @@ -674,48 +557,36 @@
  55.705          if (height < 0) {
  55.706              throw new IllegalArgumentException("Height must be >= 0");
  55.707          }
  55.708 +        Border border = getBorderUI();
  55.709          String title = getTitle();
  55.710 -        if (title != null && !"".equals(title)) {
  55.711 -            Font font = getFont(c);
  55.712 -            Border border2 = getBorder();
  55.713 -            Insets borderInsets;
  55.714 -            if (border2 != null) {
  55.715 -                borderInsets = border2.getBorderInsets(c);
  55.716 -            }
  55.717 -            else {
  55.718 -                borderInsets = new Insets(0, 0, 0, 0);
  55.719 -            }
  55.720 -            FontMetrics fm = c.getFontMetrics(font);
  55.721 -            int fontHeight = fm.getHeight();
  55.722 -            int descent = fm.getDescent();
  55.723 -            int ascent = fm.getAscent();
  55.724 -            int y = EDGE_SPACING;
  55.725 -            int h = height - EDGE_SPACING * 2;
  55.726 -            int diff;
  55.727 -            switch (getTitlePosition()) {
  55.728 -            case ABOVE_TOP:
  55.729 -                diff = ascent + descent + (Math.max(EDGE_SPACING,
  55.730 -                                                    TEXT_SPACING * 2) -
  55.731 -                                           EDGE_SPACING);
  55.732 -                return y + diff - (descent + TEXT_SPACING);
  55.733 -            case TOP:
  55.734 -            case DEFAULT_POSITION:
  55.735 -                diff = Math.max(0, ((ascent/2) + TEXT_SPACING) -
  55.736 -                                EDGE_SPACING);
  55.737 -                return (y + diff - descent) +
  55.738 -                    (borderInsets.top + ascent + descent)/2;
  55.739 -            case BELOW_TOP:
  55.740 -                return y + borderInsets.top + ascent + TEXT_SPACING;
  55.741 -            case ABOVE_BOTTOM:
  55.742 -                return (y + h) - (borderInsets.bottom + descent +
  55.743 -                                  TEXT_SPACING);
  55.744 -            case BOTTOM:
  55.745 -                h -= fontHeight / 2;
  55.746 -                return ((y + h) - descent) +
  55.747 -                        ((ascent + descent) - borderInsets.bottom)/2;
  55.748 -            case BELOW_BOTTOM:
  55.749 -                h -= fontHeight;
  55.750 -                return y + h + ascent + TEXT_SPACING;
  55.751 +        if ((title != null) && !title.isEmpty()) {
  55.752 +            int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING;
  55.753 +            JLabel label = getLabel(c);
  55.754 +            Dimension size = label.getPreferredSize();
  55.755 +            Insets insets = (border != null)
  55.756 +                    ? border.getBorderInsets(c)
  55.757 +                    : new Insets(0, 0, 0, 0);
  55.758 +
  55.759 +            int baseline = label.getBaseline(size.width, size.height);
  55.760 +            switch (getPosition()) {
  55.761 +                case ABOVE_TOP:
  55.762 +                    return baseline;
  55.763 +                case TOP:
  55.764 +                    insets.top = edge + (insets.top - size.height) / 2;
  55.765 +                    return (insets.top < edge)
  55.766 +                            ? baseline
  55.767 +                            : baseline + insets.top;
  55.768 +                case BELOW_TOP:
  55.769 +                    return baseline + insets.top + edge;
  55.770 +                case ABOVE_BOTTOM:
  55.771 +                    return baseline + height - size.height - insets.bottom - edge;
  55.772 +                case BOTTOM:
  55.773 +                    insets.bottom = edge + (insets.bottom - size.height) / 2;
  55.774 +                    return (insets.bottom < edge)
  55.775 +                            ? baseline + height - size.height
  55.776 +                            : baseline + height - size.height + insets.bottom;
  55.777 +                case BELOW_BOTTOM:
  55.778 +                    return baseline + height - size.height;
  55.779              }
  55.780          }
  55.781          return -1;
  55.782 @@ -732,44 +603,111 @@
  55.783      public Component.BaselineResizeBehavior getBaselineResizeBehavior(
  55.784              Component c) {
  55.785          super.getBaselineResizeBehavior(c);
  55.786 -        switch(getTitlePosition()) {
  55.787 -        case TitledBorder.ABOVE_TOP:
  55.788 -        case TitledBorder.TOP:
  55.789 -        case TitledBorder.DEFAULT_POSITION:
  55.790 -        case TitledBorder.BELOW_TOP:
  55.791 -            return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
  55.792 -        case TitledBorder.ABOVE_BOTTOM:
  55.793 -        case TitledBorder.BOTTOM:
  55.794 -        case TitledBorder.BELOW_BOTTOM:
  55.795 -            return JComponent.BaselineResizeBehavior.CONSTANT_DESCENT;
  55.796 +        switch (getPosition()) {
  55.797 +            case TitledBorder.ABOVE_TOP:
  55.798 +            case TitledBorder.TOP:
  55.799 +            case TitledBorder.BELOW_TOP:
  55.800 +                return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
  55.801 +            case TitledBorder.ABOVE_BOTTOM:
  55.802 +            case TitledBorder.BOTTOM:
  55.803 +            case TitledBorder.BELOW_BOTTOM:
  55.804 +                return JComponent.BaselineResizeBehavior.CONSTANT_DESCENT;
  55.805          }
  55.806          return Component.BaselineResizeBehavior.OTHER;
  55.807      }
  55.808  
  55.809 +    private Border getBorderUI() {
  55.810 +        Border border = getBorder();
  55.811 +        return border != null
  55.812 +                ? border
  55.813 +                : UIManager.getBorder("TitledBorder.border");
  55.814 +    }
  55.815 +
  55.816 +    private int getPosition() {
  55.817 +        int position = getTitlePosition();
  55.818 +        if (position != DEFAULT_POSITION) {
  55.819 +            return position;
  55.820 +        }
  55.821 +        Object value = UIManager.get("TitledBorder.position");
  55.822 +        if (value instanceof Integer) {
  55.823 +            int i = (Integer) value;
  55.824 +            if ((0 < i) && (i <= 6)) {
  55.825 +                return i;
  55.826 +            }
  55.827 +        }
  55.828 +        else if (value instanceof String) {
  55.829 +            String s = (String) value;
  55.830 +            if (s.equalsIgnoreCase("ABOVE_TOP")) {
  55.831 +                return ABOVE_TOP;
  55.832 +            }
  55.833 +            if (s.equalsIgnoreCase("TOP")) {
  55.834 +                return TOP;
  55.835 +            }
  55.836 +            if (s.equalsIgnoreCase("BELOW_TOP")) {
  55.837 +                return BELOW_TOP;
  55.838 +            }
  55.839 +            if (s.equalsIgnoreCase("ABOVE_BOTTOM")) {
  55.840 +                return ABOVE_BOTTOM;
  55.841 +            }
  55.842 +            if (s.equalsIgnoreCase("BOTTOM")) {
  55.843 +                return BOTTOM;
  55.844 +            }
  55.845 +            if (s.equalsIgnoreCase("BELOW_BOTTOM")) {
  55.846 +                return BELOW_BOTTOM;
  55.847 +            }
  55.848 +        }
  55.849 +        return TOP;
  55.850 +    }
  55.851 +
  55.852 +    private int getJustification(Component c) {
  55.853 +        int justification = getTitleJustification();
  55.854 +        if ((justification == LEADING) || (justification == DEFAULT_JUSTIFICATION)) {
  55.855 +            return c.getComponentOrientation().isLeftToRight() ? LEFT : RIGHT;
  55.856 +        }
  55.857 +        if (justification == TRAILING) {
  55.858 +            return c.getComponentOrientation().isLeftToRight() ? RIGHT : LEFT;
  55.859 +        }
  55.860 +        return justification;
  55.861 +    }
  55.862 +
  55.863      protected Font getFont(Component c) {
  55.864 -        Font font;
  55.865 -        if ((font = getTitleFont()) != null) {
  55.866 +        Font font = getTitleFont();
  55.867 +        if (font != null) {
  55.868              return font;
  55.869 -        } else if (c != null && (font = c.getFont()) != null) {
  55.870 +        }
  55.871 +        font = UIManager.getFont("TitledBorder.font");
  55.872 +        if (font != null) {
  55.873              return font;
  55.874          }
  55.875 +        if (c != null) {
  55.876 +            font = c.getFont();
  55.877 +            if (font != null) {
  55.878 +                return font;
  55.879 +            }
  55.880 +        }
  55.881          return new Font(Font.DIALOG, Font.PLAIN, 12);
  55.882      }
  55.883  
  55.884 -    private static boolean computeIntersection(Rectangle dest,
  55.885 -                                               int rx, int ry, int rw, int rh) {
  55.886 -        int x1 = Math.max(rx, dest.x);
  55.887 -        int x2 = Math.min(rx + rw, dest.x + dest.width);
  55.888 -        int y1 = Math.max(ry, dest.y);
  55.889 -        int y2 = Math.min(ry + rh, dest.y + dest.height);
  55.890 -        dest.x = x1;
  55.891 -        dest.y = y1;
  55.892 -        dest.width = x2 - x1;
  55.893 -        dest.height = y2 - y1;
  55.894 +    private Color getColor(Component c) {
  55.895 +        Color color = getTitleColor();
  55.896 +        if (color != null) {
  55.897 +            return color;
  55.898 +        }
  55.899 +        color = UIManager.getColor("TitledBorder.titleColor");
  55.900 +        if (color != null) {
  55.901 +            return color;
  55.902 +        }
  55.903 +        return (c != null)
  55.904 +                ? c.getForeground()
  55.905 +                : null;
  55.906 +    }
  55.907  
  55.908 -        if (dest.width <= 0 || dest.height <= 0) {
  55.909 -            return false;
  55.910 -        }
  55.911 -        return true;
  55.912 +    private JLabel getLabel(Component c) {
  55.913 +        this.label.setText(getTitle());
  55.914 +        this.label.setFont(getFont(c));
  55.915 +        this.label.setForeground(getColor(c));
  55.916 +        this.label.setComponentOrientation(c.getComponentOrientation());
  55.917 +        this.label.setEnabled(c.isEnabled());
  55.918 +        return this.label;
  55.919      }
  55.920  }
    56.1 --- a/src/share/classes/javax/swing/plaf/basic/BasicButtonListener.java	Thu Jul 15 20:11:45 2010 -0700
    56.2 +++ b/src/share/classes/javax/swing/plaf/basic/BasicButtonListener.java	Tue Jul 20 22:21:31 2010 -0700
    56.3 @@ -195,9 +195,8 @@
    56.4          }
    56.5  
    56.6          ButtonModel model = b.getModel();
    56.7 +        model.setPressed(false);
    56.8          model.setArmed(false);
    56.9 -        model.setPressed(false);
   56.10 -
   56.11          b.repaint();
   56.12      }
   56.13  
    57.1 --- a/src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java	Thu Jul 15 20:11:45 2010 -0700
    57.2 +++ b/src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java	Tue Jul 20 22:21:31 2010 -0700
    57.3 @@ -876,7 +876,7 @@
    57.4              String name = getName();
    57.5              if (TOGGLE_SORT_ORDER == name) {
    57.6                  JTable table = th.getTable();
    57.7 -                RowSorter sorter = table.getRowSorter();
    57.8 +                RowSorter sorter = table == null ? null : table.getRowSorter();
    57.9                  if (sorter != null) {
   57.10                      int columnIndex = ui.getSelectedColumnIndex();
   57.11                      columnIndex = table.convertColumnIndexToModel(
    58.1 --- a/src/share/classes/javax/swing/plaf/nimbus/skin.laf	Thu Jul 15 20:11:45 2010 -0700
    58.2 +++ b/src/share/classes/javax/swing/plaf/nimbus/skin.laf	Tue Jul 20 22:21:31 2010 -0700
    58.3 @@ -21276,6 +21276,7 @@
    58.4                 <uiProperty name="centerOneTouchButtons" type="BOOLEAN" value="true"/>
    58.5                 <uiProperty name="oneTouchButtonOffset" type="INT" value="30"/>
    58.6                 <uiProperty name="oneTouchExpandable" type="BOOLEAN" value="false"/>
    58.7 +               <uiProperty name="continuousLayout" type="BOOLEAN" value="true"/>
    58.8              </uiproperties>
    58.9           </style>
   58.10           <backgroundStates>
    59.1 --- a/src/share/classes/sun/awt/PlatformFont.java	Thu Jul 15 20:11:45 2010 -0700
    59.2 +++ b/src/share/classes/sun/awt/PlatformFont.java	Tue Jul 20 22:21:31 2010 -0700
    59.3 @@ -25,10 +25,10 @@
    59.4  
    59.5  package sun.awt;
    59.6  
    59.7 -import java.awt.GraphicsEnvironment;
    59.8  import java.awt.peer.FontPeer;
    59.9  import java.util.Locale;
   59.10  import java.util.Vector;
   59.11 +import sun.font.SunFontManager;
   59.12  import sun.java2d.FontSupport;
   59.13  import java.nio.CharBuffer;
   59.14  import java.nio.ByteBuffer;
   59.15 @@ -57,9 +57,9 @@
   59.16      protected static String osVersion;
   59.17  
   59.18      public PlatformFont(String name, int style){
   59.19 -        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
   59.20 -        if (ge instanceof FontSupport) {
   59.21 -            fontConfig = ((FontSupport)ge).getFontConfiguration();
   59.22 +        SunFontManager sfm = SunFontManager.getInstance();
   59.23 +        if (sfm instanceof FontSupport) {
   59.24 +            fontConfig = ((FontSupport)sfm).getFontConfiguration();
   59.25          }
   59.26          if (fontConfig == null) {
   59.27              return;
    60.1 --- a/src/share/classes/sun/awt/SunToolkit.java	Thu Jul 15 20:11:45 2010 -0700
    60.2 +++ b/src/share/classes/sun/awt/SunToolkit.java	Tue Jul 20 22:21:31 2010 -0700
    60.3 @@ -39,6 +39,7 @@
    60.4  import java.util.*;
    60.5  import java.util.concurrent.TimeUnit;
    60.6  import java.util.concurrent.locks.Condition;
    60.7 +import java.util.concurrent.locks.Lock;
    60.8  import java.util.concurrent.locks.ReentrantLock;
    60.9  import sun.util.logging.PlatformLogger;
   60.10  import sun.misc.SoftCache;
   60.11 @@ -592,7 +593,7 @@
   60.12          }
   60.13          PostEventQueue postEventQueue =
   60.14              (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
   60.15 -        if(postEventQueue != null) {
   60.16 +        if (postEventQueue != null) {
   60.17              postEventQueue.postEvent(event);
   60.18          }
   60.19      }
   60.20 @@ -610,16 +611,29 @@
   60.21          postEvent(targetToAppContext(e.getSource()), pe);
   60.22      }
   60.23  
   60.24 +    private static final Lock flushLock = new ReentrantLock();
   60.25 +    private static boolean isFlushingPendingEvents = false;
   60.26 +
   60.27      /*
   60.28       * Flush any pending events which haven't been posted to the AWT
   60.29       * EventQueue yet.
   60.30       */
   60.31      public static void flushPendingEvents()  {
   60.32 -        AppContext appContext = AppContext.getAppContext();
   60.33 -        PostEventQueue postEventQueue =
   60.34 -            (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
   60.35 -        if(postEventQueue != null) {
   60.36 -            postEventQueue.flush();
   60.37 +        flushLock.lock();
   60.38 +        try {
   60.39 +            // Don't call flushPendingEvents() recursively
   60.40 +            if (!isFlushingPendingEvents) {
   60.41 +                isFlushingPendingEvents = true;
   60.42 +                AppContext appContext = AppContext.getAppContext();
   60.43 +                PostEventQueue postEventQueue =
   60.44 +                    (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
   60.45 +                if (postEventQueue != null) {
   60.46 +                    postEventQueue.flush();
   60.47 +                }
   60.48 +            }
   60.49 +        } finally {
   60.50 +            isFlushingPendingEvents = false;
   60.51 +            flushLock.unlock();
   60.52          }
   60.53      }
   60.54  
   60.55 @@ -1930,6 +1944,25 @@
   60.56          return (Window)comp;
   60.57      }
   60.58  
   60.59 +    /**
   60.60 +     * Returns the value of the system property indicated by the specified key.
   60.61 +     */
   60.62 +    public static String getSystemProperty(final String key) {
   60.63 +        return (String)AccessController.doPrivileged(new PrivilegedAction() {
   60.64 +                public Object run() {
   60.65 +                    return System.getProperty(key);
   60.66 +                }
   60.67 +            });
   60.68 +    }
   60.69 +
   60.70 +    /**
   60.71 +     * Returns the boolean value of the system property indicated by the specified key.
   60.72 +     */
   60.73 +    protected static Boolean getBooleanSystemProperty(String key) {
   60.74 +        return Boolean.valueOf(AccessController.
   60.75 +                   doPrivileged(new GetBooleanAction(key)));
   60.76 +    }
   60.77 +
   60.78      private static Boolean sunAwtDisableMixing = null;
   60.79  
   60.80      /**
   60.81 @@ -1938,9 +1971,7 @@
   60.82       */
   60.83      public synchronized static boolean getSunAwtDisableMixing() {
   60.84          if (sunAwtDisableMixing == null) {
   60.85 -            sunAwtDisableMixing = Boolean.valueOf(
   60.86 -                    AccessController.doPrivileged(
   60.87 -                        new GetBooleanAction("sun.awt.disableMixing")));
   60.88 +            sunAwtDisableMixing = getBooleanSystemProperty("sun.awt.disableMixing");
   60.89          }
   60.90          return sunAwtDisableMixing.booleanValue();
   60.91      }
   60.92 @@ -2079,12 +2110,14 @@
   60.93          eventQueue = eq;
   60.94      }
   60.95  
   60.96 -    public boolean noEvents() {
   60.97 +    public synchronized boolean noEvents() {
   60.98          return queueHead == null;
   60.99      }
  60.100  
  60.101      /*
  60.102 -     * Continually post pending AWTEvents to the Java EventQueue.
  60.103 +     * Continually post pending AWTEvents to the Java EventQueue. The method
  60.104 +     * is synchronized to ensure the flush is completed before a new event
  60.105 +     * can be posted to this queue.
  60.106       */
  60.107      public synchronized void flush() {
  60.108          EventQueueItem tempQueue = queueHead;
    61.1 --- a/src/share/classes/sun/font/FontUtilities.java	Thu Jul 15 20:11:45 2010 -0700
    61.2 +++ b/src/share/classes/sun/font/FontUtilities.java	Tue Jul 20 22:21:31 2010 -0700
    61.3 @@ -60,6 +60,10 @@
    61.4  
    61.5      static final String LUCIDA_FILE_NAME = "LucidaSansRegular.ttf";
    61.6  
    61.7 +    private static boolean debugFonts = false;
    61.8 +    private static PlatformLogger logger = null;
    61.9 +    private static boolean logging;
   61.10 +
   61.11      // This static initializer block figures out the OS constants.
   61.12      static {
   61.13  
   61.14 @@ -115,6 +119,25 @@
   61.15                  File lucidaFile = new File(jreFontDirName + File.separator
   61.16                                             + LUCIDA_FILE_NAME);
   61.17                  isOpenJDK = !lucidaFile.exists();
   61.18 +
   61.19 +                String debugLevel =
   61.20 +                    System.getProperty("sun.java2d.debugfonts");
   61.21 +
   61.22 +                if (debugLevel != null && !debugLevel.equals("false")) {
   61.23 +                    debugFonts = true;
   61.24 +                    logger = PlatformLogger.getLogger("sun.java2d");
   61.25 +                    if (debugLevel.equals("warning")) {
   61.26 +                        logger.setLevel(PlatformLogger.WARNING);
   61.27 +                    } else if (debugLevel.equals("severe")) {
   61.28 +                        logger.setLevel(PlatformLogger.SEVERE);
   61.29 +                    }
   61.30 +                }
   61.31 +
   61.32 +                if (debugFonts) {
   61.33 +                    logger = PlatformLogger.getLogger("sun.java2d");
   61.34 +                    logging = logger.isEnabled();
   61.35 +                }
   61.36 +
   61.37                  return null;
   61.38              }
   61.39          });
   61.40 @@ -140,32 +163,6 @@
   61.41       */
   61.42      public static final int MAX_LAYOUT_CHARCODE = 0x206F;
   61.43  
   61.44 -    private static boolean debugFonts = false;
   61.45 -    private static PlatformLogger logger = null;
   61.46 -    private static boolean logging;
   61.47 -
   61.48 -    static {
   61.49 -
   61.50 -        String debugLevel =
   61.51 -            System.getProperty("sun.java2d.debugfonts");
   61.52 -
   61.53 -        if (debugLevel != null && !debugLevel.equals("false")) {
   61.54 -            debugFonts = true;
   61.55 -            logger = PlatformLogger.getLogger("sun.java2d");
   61.56 -            if (debugLevel.equals("warning")) {
   61.57 -                logger.setLevel(PlatformLogger.WARNING);
   61.58 -            } else if (debugLevel.equals("severe")) {
   61.59 -                logger.setLevel(PlatformLogger.SEVERE);
   61.60 -            }
   61.61 -        }
   61.62 -
   61.63 -        if (debugFonts) {
   61.64 -            logger = PlatformLogger.getLogger("sun.java2d");
   61.65 -            logging = logger.isEnabled();
   61.66 -        }
   61.67 -
   61.68 -    }
   61.69 -
   61.70      /**
   61.71       * Calls the private getFont2D() method in java.awt.Font objects.
   61.72       *
    62.1 --- a/src/share/classes/sun/io/CharToByteDBCS_ASCII.java	Thu Jul 15 20:11:45 2010 -0700
    62.2 +++ b/src/share/classes/sun/io/CharToByteDBCS_ASCII.java	Tue Jul 20 22:21:31 2010 -0700
    62.3 @@ -24,7 +24,6 @@
    62.4   */
    62.5  package sun.io;
    62.6  
    62.7 -import sun.nio.cs.Surrogate;
    62.8  import sun.nio.cs.ext.DoubleByte;
    62.9  import static sun.nio.cs.CharsetMapping.*;
   62.10  
    63.1 --- a/src/share/classes/sun/io/CharToByteDBCS_EBCDIC.java	Thu Jul 15 20:11:45 2010 -0700
    63.2 +++ b/src/share/classes/sun/io/CharToByteDBCS_EBCDIC.java	Tue Jul 20 22:21:31 2010 -0700
    63.3 @@ -24,7 +24,6 @@
    63.4   */
    63.5  package sun.io;
    63.6  
    63.7 -import sun.nio.cs.Surrogate;
    63.8  import sun.nio.cs.ext.DoubleByte;
    63.9  import static sun.nio.cs.CharsetMapping.*;
   63.10  
    64.1 --- a/src/share/classes/sun/java2d/HeadlessGraphicsEnvironment.java	Thu Jul 15 20:11:45 2010 -0700
    64.2 +++ b/src/share/classes/sun/java2d/HeadlessGraphicsEnvironment.java	Tue Jul 20 22:21:31 2010 -0700
    64.3 @@ -59,17 +59,12 @@
    64.4   * Headless decorator implementation of a SunGraphicsEnvironment
    64.5   */
    64.6  
    64.7 -public class HeadlessGraphicsEnvironment extends GraphicsEnvironment
    64.8 -    implements FontSupport {
    64.9 +public class HeadlessGraphicsEnvironment extends GraphicsEnvironment {
   64.10  
   64.11      private GraphicsEnvironment ge;
   64.12 -    private FontSupport fontSupport;
   64.13  
   64.14      public HeadlessGraphicsEnvironment(GraphicsEnvironment ge) {
   64.15          this.ge = ge;
   64.16 -        if (ge instanceof FontSupport) {
   64.17 -            fontSupport = (FontSupport)ge;
   64.18 -        }
   64.19      }
   64.20  
   64.21      public GraphicsDevice[] getScreenDevices()
   64.22 @@ -101,13 +96,6 @@
   64.23      public String[] getAvailableFontFamilyNames(Locale l) {
   64.24          return ge.getAvailableFontFamilyNames(l); }
   64.25  
   64.26 -    public FontConfiguration getFontConfiguration() {
   64.27 -        if (fontSupport != null) {
   64.28 -            return fontSupport.getFontConfiguration();
   64.29 -        }
   64.30 -        return null;
   64.31 -    }
   64.32 -
   64.33      /* Used by FontManager : internal API */
   64.34      public GraphicsEnvironment getSunGraphicsEnvironment() {
   64.35          return ge;
    65.1 --- a/src/share/classes/sun/launcher/LauncherHelper.java	Thu Jul 15 20:11:45 2010 -0700
    65.2 +++ b/src/share/classes/sun/launcher/LauncherHelper.java	Tue Jul 20 22:21:31 2010 -0700
    65.3 @@ -1,5 +1,5 @@
    65.4  /*
    65.5 - * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
    65.6 + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
    65.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    65.8   *
    65.9   * This code is free software; you can redistribute it and/or modify it
   65.10 @@ -208,7 +208,7 @@
   65.11          Method method = null;
   65.12          try {
   65.13              method = clazz.getMethod("main", String[].class);
   65.14 -        } catch (Exception e) {
   65.15 +        } catch (NoSuchMethodException nsme) {
   65.16              ostream.println(getLocalizedMessage("java.launcher.cls.error4",
   65.17                      classname));
   65.18              throw new RuntimeException("Main method not found in " + classname);
   65.19 @@ -225,8 +225,7 @@
   65.20              throw new RuntimeException("Main method is not static in class " +
   65.21                      classname);
   65.22          }
   65.23 -        Class<?> rType = method.getReturnType();
   65.24 -        if (!rType.isPrimitive() || !rType.getName().equals("void")) {
   65.25 +        if (method.getReturnType() != java.lang.Void.TYPE) {
   65.26              ostream.println(getLocalizedMessage("java.launcher.cls.error3",
   65.27                      classname));
   65.28              throw new RuntimeException("Main method must return a value" +
    66.1 --- a/src/share/classes/sun/net/httpserver/ExchangeImpl.java	Thu Jul 15 20:11:45 2010 -0700
    66.2 +++ b/src/share/classes/sun/net/httpserver/ExchangeImpl.java	Tue Jul 20 22:21:31 2010 -0700
    66.3 @@ -52,14 +52,16 @@
    66.4      boolean http10 = false;
    66.5  
    66.6      /* for formatting the Date: header */
    66.7 -    static TimeZone tz;
    66.8 -    static DateFormat df;
    66.9 -    static {
   66.10 -        String pattern = "EEE, dd MMM yyyy HH:mm:ss zzz";
   66.11 -        tz = TimeZone.getTimeZone ("GMT");
   66.12 -        df = new SimpleDateFormat (pattern, Locale.US);
   66.13 -        df.setTimeZone (tz);
   66.14 -    }
   66.15 +    private static final String pattern = "EEE, dd MMM yyyy HH:mm:ss zzz";
   66.16 +    private static final TimeZone gmtTZ = TimeZone.getTimeZone("GMT");
   66.17 +    private static final ThreadLocal<DateFormat> dateFormat =
   66.18 +         new ThreadLocal<DateFormat>() {
   66.19 +             @Override protected DateFormat initialValue() {
   66.20 +                 DateFormat df = new SimpleDateFormat(pattern, Locale.US);
   66.21 +                 df.setTimeZone(gmtTZ);
   66.22 +                 return df;
   66.23 +         }
   66.24 +     };
   66.25  
   66.26      private static final String HEAD = "HEAD";
   66.27  
   66.28 @@ -206,7 +208,7 @@
   66.29          PlaceholderOutputStream o = getPlaceholderResponseBody();
   66.30          tmpout.write (bytes(statusLine, 0), 0, statusLine.length());
   66.31          boolean noContentToSend = false; // assume there is content
   66.32 -        rspHdrs.set ("Date", df.format (new Date()));
   66.33 +        rspHdrs.set ("Date", dateFormat.get().format (new Date()));
   66.34  
   66.35          /* check for response type that is not allowed to send a body */
   66.36  
    67.1 --- a/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java	Thu Jul 15 20:11:45 2010 -0700
    67.2 +++ b/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java	Tue Jul 20 22:21:31 2010 -0700
    67.3 @@ -2331,7 +2331,7 @@
    67.4       * closed the connection to the web server.
    67.5       */
    67.6      private void disconnectWeb() throws IOException {
    67.7 -        if (usingProxy()) {
    67.8 +        if (usingProxy() && http.isKeepingAlive()) {
    67.9              responseCode = -1;
   67.10              // clean up, particularly, skip the content part
   67.11              // of a 401 error response
    68.1 --- a/src/share/classes/sun/nio/cs/Surrogate.java	Thu Jul 15 20:11:45 2010 -0700
    68.2 +++ b/src/share/classes/sun/nio/cs/Surrogate.java	Tue Jul 20 22:21:31 2010 -0700
    68.3 @@ -1,5 +1,5 @@
    68.4  /*
    68.5 - * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
    68.6 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    68.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    68.8   *
    68.9   * This code is free software; you can redistribute it and/or modify it
   68.10 @@ -34,8 +34,9 @@
   68.11   * Utility class for dealing with surrogates.
   68.12   *
   68.13   * @author Mark Reinhold
   68.14 + * @author Martin Buchholz
   68.15 + * @author Ulf Zibis
   68.16   */
   68.17 -
   68.18  public class Surrogate {
   68.19  
   68.20      private Surrogate() { }
   68.21 @@ -75,16 +76,9 @@
   68.22      }
   68.23  
   68.24      /**
   68.25 -     * Tells whether or not the given UCS-4 character is in the Basic
   68.26 -     * Multilingual Plane, and can be represented using a single char.
   68.27 -     */
   68.28 -    public static boolean isBMPCodePoint(int uc) {
   68.29 -        return uc >> 16 == 0;
   68.30 -    }
   68.31 -
   68.32 -    /**
   68.33       * Tells whether or not the given UCS-4 character must be represented as a
   68.34       * surrogate pair in UTF-16.
   68.35 +     * Use of {@link Character#isSupplementaryCodePoint} is generally preferred.
   68.36       */
   68.37      public static boolean neededFor(int uc) {
   68.38          return Character.isSupplementaryCodePoint(uc);
   68.39 @@ -92,24 +86,25 @@
   68.40  
   68.41      /**
   68.42       * Returns the high UTF-16 surrogate for the given supplementary UCS-4 character.
   68.43 +     * Use of {@link Character#highSurrogate} is generally preferred.
   68.44       */
   68.45      public static char high(int uc) {
   68.46          assert Character.isSupplementaryCodePoint(uc);
   68.47 -        return (char)((uc >> 10)
   68.48 -                      + (Character.MIN_HIGH_SURROGATE
   68.49 -                         - (Character.MIN_SUPPLEMENTARY_CODE_POINT >> 10)));
   68.50 +        return Character.highSurrogate(uc);
   68.51      }
   68.52  
   68.53      /**
   68.54       * Returns the low UTF-16 surrogate for the given supplementary UCS-4 character.
   68.55 +     * Use of {@link Character#lowSurrogate} is generally preferred.
   68.56       */
   68.57      public static char low(int uc) {
   68.58          assert Character.isSupplementaryCodePoint(uc);
   68.59 -        return (char)((uc & 0x3ff) + Character.MIN_LOW_SURROGATE);
   68.60 +        return Character.lowSurrogate(uc);
   68.61      }
   68.62  
   68.63      /**
   68.64       * Converts the given surrogate pair into a 32-bit UCS-4 character.
   68.65 +     * Use of {@link Character#toCodePoint} is generally preferred.
   68.66       */
   68.67      public static int toUCS4(char c, char d) {
   68.68          assert Character.isHighSurrogate(c) && Character.isLowSurrogate(d);
   68.69 @@ -290,8 +285,9 @@
   68.70           *           error() will return a descriptive result object
   68.71           */
   68.72          public int generate(int uc, int len, CharBuffer dst) {
   68.73 -            if (Surrogate.isBMPCodePoint(uc)) {
   68.74 -                if (Surrogate.is(uc)) {
   68.75 +            if (Character.isBmpCodePoint(uc)) {
   68.76 +                char c = (char) uc;
   68.77 +                if (Character.isSurrogate(c)) {
   68.78                      error = CoderResult.malformedForLength(len);
   68.79                      return -1;
   68.80                  }
   68.81 @@ -299,16 +295,16 @@
   68.82                      error = CoderResult.OVERFLOW;
   68.83                      return -1;
   68.84                  }
   68.85 -                dst.put((char)uc);
   68.86 +                dst.put(c);
   68.87                  error = null;
   68.88                  return 1;
   68.89 -            } else if (Character.isSupplementaryCodePoint(uc)) {
   68.90 +            } else if (Character.isValidCodePoint(uc)) {
   68.91                  if (dst.remaining() < 2) {
   68.92                      error = CoderResult.OVERFLOW;
   68.93                      return -1;
   68.94                  }
   68.95 -                dst.put(Surrogate.high(uc));
   68.96 -                dst.put(Surrogate.low(uc));
   68.97 +                dst.put(Character.highSurrogate(uc));
   68.98 +                dst.put(Character.lowSurrogate(uc));
   68.99                  error = null;
  68.100                  return 2;
  68.101              } else {
  68.102 @@ -334,8 +330,9 @@
  68.103           *           error() will return a descriptive result object
  68.104           */
  68.105          public int generate(int uc, int len, char[] da, int dp, int dl) {
  68.106 -            if (Surrogate.isBMPCodePoint(uc)) {
  68.107 -                if (Surrogate.is(uc)) {
  68.108 +            if (Character.isBmpCodePoint(uc)) {
  68.109 +                char c = (char) uc;
  68.110 +                if (Character.isSurrogate(c)) {
  68.111                      error = CoderResult.malformedForLength(len);
  68.112                      return -1;
  68.113                  }
  68.114 @@ -343,16 +340,16 @@
  68.115                      error = CoderResult.OVERFLOW;
  68.116                      return -1;
  68.117                  }
  68.118 -                da[dp] = (char)uc;
  68.119 +                da[dp] = c;
  68.120                  error = null;
  68.121                  return 1;
  68.122 -            } else if (Character.isSupplementaryCodePoint(uc)) {
  68.123 +            } else if (Character.isValidCodePoint(uc)) {
  68.124                  if (dl - dp < 2) {
  68.125                      error = CoderResult.OVERFLOW;
  68.126                      return -1;
  68.127                  }
  68.128 -                da[dp] = Surrogate.high(uc);
  68.129 -                da[dp + 1] = Surrogate.low(uc);
  68.130 +                da[dp] = Character.highSurrogate(uc);
  68.131 +                da[dp + 1] = Character.lowSurrogate(uc);
  68.132                  error = null;
  68.133                  return 2;
  68.134              } else {
    69.1 --- a/src/share/classes/sun/nio/cs/UTF_32Coder.java	Thu Jul 15 20:11:45 2010 -0700
    69.2 +++ b/src/share/classes/sun/nio/cs/UTF_32Coder.java	Tue Jul 20 22:21:31 2010 -0700
    69.3 @@ -86,22 +86,21 @@
    69.4                          src.position(mark);
    69.5                      }
    69.6                  }
    69.7 -                while (src.remaining() > 3) {
    69.8 +                while (src.remaining() >= 4) {
    69.9                      cp = getCP(src);
   69.10 -                    if (cp < 0 || cp > Surrogate.UCS4_MAX) {
   69.11 -                        return CoderResult.malformedForLength(4);
   69.12 -                    }
   69.13 -                    if (cp < Surrogate.UCS4_MIN) {
   69.14 +                    if (Character.isBmpCodePoint(cp)) {
   69.15                          if (!dst.hasRemaining())
   69.16                              return CoderResult.OVERFLOW;
   69.17                          mark += 4;
   69.18 -                        dst.put((char)cp);
   69.19 -                    } else {
   69.20 +                        dst.put((char) cp);
   69.21 +                    } else if (Character.isValidCodePoint(cp)) {
   69.22                          if (dst.remaining() < 2)
   69.23                              return CoderResult.OVERFLOW;
   69.24                          mark += 4;
   69.25 -                        dst.put(Surrogate.high(cp));
   69.26 -                        dst.put(Surrogate.low(cp));
   69.27 +                        dst.put(Character.highSurrogate(cp));
   69.28 +                        dst.put(Character.lowSurrogate(cp));
   69.29 +                    } else {
   69.30 +                        return CoderResult.malformedForLength(4);
   69.31                      }
   69.32                  }
   69.33                  return CoderResult.UNDERFLOW;
   69.34 @@ -154,7 +153,12 @@
   69.35              try {
   69.36                  while (src.hasRemaining()) {
   69.37                      char c = src.get();
   69.38 -                    if (Character.isHighSurrogate(c)) {
   69.39 +                    if (!Character.isSurrogate(c)) {
   69.40 +                        if (dst.remaining() < 4)
   69.41 +                            return CoderResult.OVERFLOW;
   69.42 +                        mark++;
   69.43 +                        put(c, dst);
   69.44 +                    } else if (Character.isHighSurrogate(c)) {
   69.45                          if (!src.hasRemaining())
   69.46                              return CoderResult.UNDERFLOW;
   69.47                          char low = src.get();
   69.48 @@ -162,17 +166,13 @@
   69.49                              if (dst.remaining() < 4)
   69.50                                  return CoderResult.OVERFLOW;
   69.51                              mark += 2;
   69.52 -                            put(Surrogate.toUCS4(c, low), dst);
   69.53 +                            put(Character.toCodePoint(c, low), dst);
   69.54                          } else {
   69.55                              return CoderResult.malformedForLength(1);
   69.56                          }
   69.57 -                    } else if (Character.isLowSurrogate(c)) {
   69.58 +                    } else {
   69.59 +                        // assert Character.isLowSurrogate(c);
   69.60                          return CoderResult.malformedForLength(1);
   69.61 -                    } else {
   69.62 -                        if (dst.remaining() < 4)
   69.63 -                            return CoderResult.OVERFLOW;
   69.64 -                        mark++;
   69.65 -                        put(c, dst);
   69.66                      }
   69.67                  }
   69.68                  return CoderResult.UNDERFLOW;
    70.1 --- a/src/share/classes/sun/nio/cs/UTF_8.java	Thu Jul 15 20:11:45 2010 -0700
    70.2 +++ b/src/share/classes/sun/nio/cs/UTF_8.java	Tue Jul 20 22:21:31 2010 -0700
    70.3 @@ -102,7 +102,7 @@
    70.4          //  [F1..F3] [80..BF] [80..BF] [80..BF]
    70.5          //  [F4]     [80..8F] [80..BF] [80..BF]
    70.6          //  only check 80-be range here, the [0xf0,0x80...] and [0xf4,0x90-...]
    70.7 -        //  will be checked by Surrogate.neededFor(uc)
    70.8 +        //  will be checked by Character.isSupplementaryCodePoint(uc)
    70.9          private static boolean isMalformed4(int b2, int b3, int b4) {
   70.10              return (b2 & 0xc0) != 0x80 || (b3 & 0xc0) != 0x80 ||
   70.11                     (b4 & 0xc0) != 0x80;
   70.12 @@ -207,15 +207,15 @@
   70.13  
   70.14              // ASCII only loop
   70.15              while (dp < dlASCII && sa[sp] >= 0)
   70.16 -                da[dp++] = (char)sa[sp++];
   70.17 +                da[dp++] = (char) sa[sp++];
   70.18  
   70.19              while (sp < sl) {
   70.20                  int b1 = sa[sp];
   70.21 -                if (b1  >= 0) {
   70.22 +                if (b1 >= 0) {
   70.23                      // 1 byte, 7 bits: 0xxxxxxx
   70.24                      if (dp >= dl)
   70.25                          return xflow(src, sp, sl, dst, dp, 1);
   70.26 -                    da[dp++] = (char)b1;
   70.27 +                    da[dp++] = (char) b1;
   70.28                      sp++;
   70.29                  } else if ((b1 >> 5) == -2) {
   70.30                      // 2 bytes, 11 bits: 110xxxxx 10xxxxxx
   70.31 @@ -224,7 +224,10 @@
   70.32                      int b2 = sa[sp + 1];
   70.33                      if (isMalformed2(b1, b2))
   70.34                          return malformed(src, sp, dst, dp, 2);
   70.35 -                    da[dp++] = (char) (((b1 << 6) ^ b2) ^ 0x0f80);
   70.36 +                    da[dp++] = (char) (((b1 << 6) ^ b2)
   70.37 +                                       ^
   70.38 +                                       (((byte) 0xC0 << 6) ^
   70.39 +                                        ((byte) 0x80 << 0)));
   70.40                      sp += 2;
   70.41                  } else if ((b1 >> 4) == -2) {
   70.42                      // 3 bytes, 16 bits: 1110xxxx 10xxxxxx 10xxxxxx
   70.43 @@ -234,7 +237,13 @@
   70.44                      int b3 = sa[sp + 2];
   70.45                      if (isMalformed3(b1, b2, b3))
   70.46                          return malformed(src, sp, dst, dp, 3);
   70.47 -                    da[dp++] = (char) (((b1 << 12) ^ (b2 << 6) ^ b3) ^ 0x1f80);
   70.48 +                    da[dp++] = (char)
   70.49 +                        ((b1 << 12) ^
   70.50 +                         (b2 <<  6) ^
   70.51 +                         (b3 ^
   70.52 +                          (((byte) 0xE0 << 12) ^
   70.53 +                           ((byte) 0x80 <<  6) ^
   70.54 +                           ((byte) 0x80 <<  0))));
   70.55                      sp += 3;
   70.56                  } else if ((b1 >> 3) == -2) {
   70.57                      // 4 bytes, 21 bits: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
   70.58 @@ -243,16 +252,21 @@
   70.59                      int b2 = sa[sp + 1];
   70.60                      int b3 = sa[sp + 2];
   70.61                      int b4 = sa[sp + 3];
   70.62 -                    int uc = ((b1 & 0x07) << 18) |
   70.63 -                             ((b2 & 0x3f) << 12) |
   70.64 -                             ((b3 & 0x3f) << 06) |
   70.65 -                             (b4 & 0x3f);
   70.66 +                    int uc = ((b1 << 18) ^
   70.67 +                              (b2 << 12) ^
   70.68 +                              (b3 <<  6) ^
   70.69 +                              (b4 ^
   70.70 +                               (((byte) 0xF0 << 18) ^
   70.71 +                                ((byte) 0x80 << 12) ^
   70.72 +                                ((byte) 0x80 <<  6) ^
   70.73 +                                ((byte) 0x80 <<  0))));
   70.74                      if (isMalformed4(b2, b3, b4) ||
   70.75 -                        !Surrogate.neededFor(uc)) {
   70.76 +                        // shortest form check
   70.77 +                        !Character.isSupplementaryCodePoint(uc)) {
   70.78                          return malformed(src, sp, dst, dp, 4);
   70.79                      }
   70.80 -                    da[dp++] = Surrogate.high(uc);
   70.81 -                    da[dp++] = Surrogate.low(uc);
   70.82 +                    da[dp++] = Character.highSurrogate(uc);
   70.83 +                    da[dp++] = Character.lowSurrogate(uc);
   70.84                      sp += 4;
   70.85                  } else
   70.86                      return malformed(src, sp, dst, dp, 1);
   70.87 @@ -270,8 +284,8 @@
   70.88                  if (b1 >= 0) {
   70.89                      // 1 byte, 7 bits: 0xxxxxxx
   70.90                      if (dst.remaining() < 1)
   70.91 -                        return xflow(src, mark, 1);  //overflow
   70.92 -                    dst.put((char)b1);
   70.93 +                        return xflow(src, mark, 1); // overflow
   70.94 +                    dst.put((char) b1);
   70.95                      mark++;
   70.96                  } else if ((b1 >> 5) == -2) {
   70.97                      // 2 bytes, 11 bits: 110xxxxx 10xxxxxx
   70.98 @@ -280,7 +294,10 @@
   70.99                      int b2 = src.get();
  70.100                      if (isMalformed2(b1, b2))
  70.101                          return malformed(src, mark, 2);
  70.102 -                    dst.put((char) (((b1 << 6) ^ b2) ^ 0x0f80));
  70.103 +                    dst.put((char) (((b1 << 6) ^ b2)
  70.104 +                                    ^
  70.105 +                                    (((byte) 0xC0 << 6) ^
  70.106 +                                     ((byte) 0x80 << 0))));
  70.107                      mark += 2;
  70.108                  } else if ((b1 >> 4) == -2) {
  70.109                      // 3 bytes, 16 bits: 1110xxxx 10xxxxxx 10xxxxxx
  70.110 @@ -290,7 +307,13 @@
  70.111                      int b3 = src.get();
  70.112                      if (isMalformed3(b1, b2, b3))
  70.113                          return malformed(src, mark, 3);
  70.114 -                    dst.put((char) (((b1 << 12) ^ (b2 << 6) ^ b3) ^ 0x1f80));
  70.115 +                    dst.put((char)
  70.116 +                            ((b1 << 12) ^
  70.117 +                             (b2 <<  6) ^
  70.118 +                             (b3 ^
  70.119 +                              (((byte) 0xE0 << 12) ^
  70.120 +                               ((byte) 0x80 <<  6) ^
  70.121 +                               ((byte) 0x80 <<  0)))));
  70.122                      mark += 3;
  70.123                  } else if ((b1 >> 3) == -2) {
  70.124                      // 4 bytes, 21 bits: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  70.125 @@ -299,16 +322,21 @@
  70.126                      int b2 = src.get();
  70.127                      int b3 = src.get();
  70.128                      int b4 = src.get();
  70.129 -                    int uc = ((b1 & 0x07) << 18) |
  70.130 -                             ((b2 & 0x3f) << 12) |
  70.131 -                             ((b3 & 0x3f) << 06) |
  70.132 -                             (b4 & 0x3f);
  70.133 +                    int uc = ((b1 << 18) ^
  70.134 +                              (b2 << 12) ^
  70.135 +                              (b3 <<  6) ^
  70.136 +                              (b4 ^
  70.137 +                               (((byte) 0xF0 << 18) ^
  70.138 +                                ((byte) 0x80 << 12) ^
  70.139 +                                ((byte) 0x80 <<  6) ^
  70.140 +                                ((byte) 0x80 <<  0))));
  70.141                      if (isMalformed4(b2, b3, b4) ||
  70.142 -                        !Surrogate.neededFor(uc)) { // shortest form check
  70.143 +                        // shortest form check
  70.144 +                        !Character.isSupplementaryCodePoint(uc)) {
  70.145                          return malformed(src, mark, 4);
  70.146                      }
  70.147 -                    dst.put(Surrogate.high(uc));
  70.148 -                    dst.put(Surrogate.low(uc));
  70.149 +                    dst.put(Character.highSurrogate(uc));
  70.150 +                    dst.put(Character.lowSurrogate(uc));
  70.151                      mark += 4;
  70.152                  } else {
  70.153                      return malformed(src, mark, 1);
  70.154 @@ -366,7 +394,7 @@
  70.155              int dl = dst.arrayOffset() + dst.limit();
  70.156              int dlASCII = dp + Math.min(sl - sp, dl - dp);
  70.157  
  70.158 -            //ASCII only loop
  70.159 +            // ASCII only loop
  70.160              while (dp < dlASCII && sa[sp] < '\u0080')
  70.161                  da[dp++] = (byte) sa[sp++];
  70.162              while (sp < sl) {
  70.163 @@ -380,7 +408,7 @@
  70.164                      // 2 bytes, 11 bits
  70.165                      if (dl - dp < 2)
  70.166                          return overflow(src, sp, dst, dp);
  70.167 -                    da[dp++] = (byte)(0xc0 | ((c >> 06)));
  70.168 +                    da[dp++] = (byte)(0xc0 | (c >> 6));
  70.169                      da[dp++] = (byte)(0x80 | (c & 0x3f));
  70.170                  } else if (Character.isSurrogate(c)) {
  70.171                      // Have a surrogate pair
  70.172 @@ -395,7 +423,7 @@
  70.173                          return overflow(src, sp, dst, dp);
  70.174                      da[dp++] = (byte)(0xf0 | ((uc >> 18)));
  70.175                      da[dp++] = (byte)(0x80 | ((uc >> 12) & 0x3f));
  70.176 -                    da[dp++] = (byte)(0x80 | ((uc >> 06) & 0x3f));
  70.177 +                    da[dp++] = (byte)(0x80 | ((uc >>  6) & 0x3f));
  70.178                      da[dp++] = (byte)(0x80 | (uc & 0x3f));
  70.179                      sp++;  // 2 chars
  70.180                  } else {
  70.181 @@ -403,7 +431,7 @@
  70.182                      if (dl - dp < 3)
  70.183                          return overflow(src, sp, dst, dp);
  70.184                      da[dp++] = (byte)(0xe0 | ((c >> 12)));
  70.185 -                    da[dp++] = (byte)(0x80 | ((c >> 06) & 0x3f));
  70.186 +                    da[dp++] = (byte)(0x80 | ((c >>  6) & 0x3f));
  70.187                      da[dp++] = (byte)(0x80 | (c & 0x3f));
  70.188                  }
  70.189                  sp++;
  70.190 @@ -427,7 +455,7 @@
  70.191                      // 2 bytes, 11 bits
  70.192                      if (dst.remaining() < 2)
  70.193                          return overflow(src, mark);
  70.194 -                    dst.put((byte)(0xc0 | ((c >> 06))));
  70.195 +                    dst.put((byte)(0xc0 | (c >> 6)));
  70.196                      dst.put((byte)(0x80 | (c & 0x3f)));
  70.197                  } else if (Character.isSurrogate(c)) {
  70.198                      // Have a surrogate pair
  70.199 @@ -442,15 +470,15 @@
  70.200                          return overflow(src, mark);
  70.201                      dst.put((byte)(0xf0 | ((uc >> 18))));
  70.202                      dst.put((byte)(0x80 | ((uc >> 12) & 0x3f)));
  70.203 -                    dst.put((byte)(0x80 | ((uc >> 06) & 0x3f)));
  70.204 +                    dst.put((byte)(0x80 | ((uc >>  6) & 0x3f)));
  70.205                      dst.put((byte)(0x80 | (uc & 0x3f)));
  70.206 -                    mark++;  //2 chars
  70.207 +                    mark++;  // 2 chars
  70.208                  } else {
  70.209                      // 3 bytes, 16 bits
  70.210                      if (dst.remaining() < 3)
  70.211                          return overflow(src, mark);
  70.212                      dst.put((byte)(0xe0 | ((c >> 12))));
  70.213 -                    dst.put((byte)(0x80 | ((c >> 06) & 0x3f)));
  70.214 +                    dst.put((byte)(0x80 | ((c >>  6) & 0x3f)));
  70.215                      dst.put((byte)(0x80 | (c & 0x3f)));
  70.216                  }
  70.217                  mark++;
    71.1 --- a/src/share/classes/sun/nio/cs/UnicodeEncoder.java	Thu Jul 15 20:11:45 2010 -0700
    71.2 +++ b/src/share/classes/sun/nio/cs/UnicodeEncoder.java	Tue Jul 20 22:21:31 2010 -0700
    71.3 @@ -93,8 +93,8 @@
    71.4                  if (dst.remaining() < 4)
    71.5                      return CoderResult.OVERFLOW;
    71.6                  mark += 2;
    71.7 -                put(Surrogate.high(d), dst);
    71.8 -                put(Surrogate.low(d), dst);
    71.9 +                put(Character.highSurrogate(d), dst);
   71.10 +                put(Character.lowSurrogate(d), dst);
   71.11              }
   71.12              return CoderResult.UNDERFLOW;
   71.13          } finally {
    72.1 --- a/src/share/classes/sun/nio/cs/ext/EUC_TW.java	Thu Jul 15 20:11:45 2010 -0700
    72.2 +++ b/src/share/classes/sun/nio/cs/ext/EUC_TW.java	Tue Jul 20 22:21:31 2010 -0700
    72.3 @@ -34,7 +34,6 @@
    72.4  import java.nio.charset.CoderResult;
    72.5  import java.util.Arrays;
    72.6  import sun.nio.cs.HistoricallyNamedCharset;
    72.7 -import sun.nio.cs.Surrogate;
    72.8  import static sun.nio.cs.CharsetMapping.*;
    72.9  
   72.10  public class EUC_TW extends Charset implements HistoricallyNamedCharset
   72.11 @@ -159,8 +158,8 @@
   72.12                  c1[0] = c;
   72.13                  return c1;
   72.14              } else {
   72.15 -                c2[0] = Surrogate.high(0x20000 + c);
   72.16 -                c2[1] = Surrogate.low(0x20000 + c);
   72.17 +                c2[0] = Character.highSurrogate(0x20000 + c);
   72.18 +                c2[1] = Character.lowSurrogate(0x20000 + c);
   72.19                  return c2;
   72.20              }
   72.21          }
   72.22 @@ -441,7 +440,7 @@
   72.23          }
   72.24  
   72.25          static int encode(char hi, char low, byte[] bb) {
   72.26 -            int c = Surrogate.toUCS4(hi, low);
   72.27 +            int c = Character.toCodePoint(hi, low);
   72.28              if ((c & 0xf0000) != 0x20000)
   72.29                  return -1;
   72.30              c -= 0x20000;
    73.1 --- a/src/share/classes/sun/nio/cs/ext/GB18030.java	Thu Jul 15 20:11:45 2010 -0700
    73.2 +++ b/src/share/classes/sun/nio/cs/ext/GB18030.java	Tue Jul 20 22:21:31 2010 -0700
    73.3 @@ -12628,7 +12628,7 @@
    73.4                      if (Character.isSurrogate(c)) {
    73.5                          if ((condensedKey=sgp.parse(c, sa, sp, sl)) < 0)
    73.6                              return sgp.error();
    73.7 -                        // Surogate.toUCS4 looks like
    73.8 +                        // Character.toCodePoint looks like
    73.9                          // (((high & 0x3ff) << 10) | (low & 0x3ff)) + 0x10000;
   73.10                          // so we add (0x2e248 - 0x10000) to get the "key".
   73.11                          condensedKey += 0x1E248;
    74.1 --- a/src/share/classes/sun/nio/cs/ext/IBM33722.java	Thu Jul 15 20:11:45 2010 -0700
    74.2 +++ b/src/share/classes/sun/nio/cs/ext/IBM33722.java	Tue Jul 20 22:21:31 2010 -0700
    74.3 @@ -36,7 +36,6 @@
    74.4  import java.nio.charset.CharsetEncoder;
    74.5  import java.nio.charset.CoderResult;
    74.6  import sun.nio.cs.HistoricallyNamedCharset;
    74.7 -import sun.nio.cs.Surrogate;
    74.8  
    74.9  public class IBM33722
   74.10      extends Charset
    75.1 --- a/src/share/classes/sun/nio/cs/ext/IBM964.java	Thu Jul 15 20:11:45 2010 -0700
    75.2 +++ b/src/share/classes/sun/nio/cs/ext/IBM964.java	Tue Jul 20 22:21:31 2010 -0700
    75.3 @@ -36,7 +36,6 @@
    75.4  import java.nio.charset.CharsetEncoder;
    75.5  import java.nio.charset.CoderResult;
    75.6  import sun.nio.cs.HistoricallyNamedCharset;
    75.7 -import sun.nio.cs.Surrogate;
    75.8  
    75.9  public class IBM964
   75.10      extends Charset
    76.1 --- a/src/share/classes/sun/security/krb5/Credentials.java	Thu Jul 15 20:11:45 2010 -0700
    76.2 +++ b/src/share/classes/sun/security/krb5/Credentials.java	Tue Jul 20 22:21:31 2010 -0700
    76.3 @@ -1,5 +1,5 @@
    76.4  /*
    76.5 - * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
    76.6 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    76.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    76.8   *
    76.9   * This code is free software; you can redistribute it and/or modify it
   76.10 @@ -33,9 +33,7 @@
   76.11  
   76.12  import sun.security.krb5.internal.*;
   76.13  import sun.security.krb5.internal.ccache.CredentialsCache;
   76.14 -import sun.security.krb5.internal.ktab.*;
   76.15  import sun.security.krb5.internal.crypto.EType;
   76.16 -import java.io.File;
   76.17  import java.io.IOException;
   76.18  import java.util.Date;
   76.19  import java.net.InetAddress;
   76.20 @@ -506,59 +504,6 @@
   76.21          return result;
   76.22      }
   76.23  
   76.24 -
   76.25 -    /**
   76.26 -     * Gets service credential from key table. The credential is used to
   76.27 -     * decrypt the received client message
   76.28 -     * and authenticate the client by verifying the client's credential.
   76.29 -     *
   76.30 -     * @param serviceName the name of service, using format component@realm
   76.31 -     * @param keyTabFile the file of key table.
   76.32 -     * @return a <code>KrbCreds</code> object.
   76.33 -     */
   76.34 -    public static Credentials getServiceCreds(String serviceName,
   76.35 -                                              File keyTabFile) {
   76.36 -        EncryptionKey k = null;
   76.37 -        PrincipalName service = null;
   76.38 -        Credentials result = null;
   76.39 -        try {
   76.40 -            service = new PrincipalName(serviceName);
   76.41 -            if (service.getRealm() == null) {
   76.42 -                String realm = Config.getInstance().getDefaultRealm();
   76.43 -                if (realm == null) {
   76.44 -                    return null;
   76.45 -                } else {
   76.46 -                    service.setRealm(realm);
   76.47 -                }
   76.48 -            }
   76.49 -        } catch (RealmException e) {
   76.50 -            if (DEBUG) {
   76.51 -                e.printStackTrace();
   76.52 -            }
   76.53 -            return null;
   76.54 -        } catch (KrbException e) {
   76.55 -            if (DEBUG) {
   76.56 -                e.printStackTrace();
   76.57 -            }
   76.58 -            return null;
   76.59 -        }
   76.60 -        KeyTab kt;
   76.61 -        if (keyTabFile == null) {
   76.62 -            kt = KeyTab.getInstance();
   76.63 -        } else {
   76.64 -            kt = KeyTab.getInstance(keyTabFile);
   76.65 -        }
   76.66 -        if ((kt != null) && (kt.findServiceEntry(service))) {
   76.67 -            k = kt.readServiceKey(service);
   76.68 -            result = new Credentials(null, service, null, null, null,
   76.69 -                                     null, null, null, null, null);
   76.70 -            result.serviceKey = k;
   76.71 -        }
   76.72 -        return result;
   76.73 -    }
   76.74 -
   76.75 -
   76.76 -
   76.77      /**
   76.78       * Acquires credentials for a specified service using initial credential.
   76.79       * When the service has a different realm
    77.1 --- a/src/share/classes/sun/security/krb5/EncryptedData.java	Thu Jul 15 20:11:45 2010 -0700
    77.2 +++ b/src/share/classes/sun/security/krb5/EncryptedData.java	Tue Jul 20 22:21:31 2010 -0700
    77.3 @@ -1,5 +1,5 @@
    77.4  /*
    77.5 - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
    77.6 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    77.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    77.8   *
    77.9   * This code is free software; you can redistribute it and/or modify it
   77.10 @@ -336,38 +336,29 @@
   77.11      }
   77.12  
   77.13      /**
   77.14 -     * Reset data stream after decryption, remove redundant bytes.
   77.15 +     * Reset asn.1 data stream after decryption, remove redundant bytes.
   77.16       * @param data the decrypted data from decrypt().
   77.17 -     * @param encoded true if the encrypted data is ASN1 encoded data,
   77.18 -     * false if the encrypted data is not ASN1 encoded data.
   77.19       * @return the reset byte array which holds exactly one asn1 datum
   77.20       * including its tag and length.
   77.21       *
   77.22       */
   77.23 -    public byte[] reset(byte[] data, boolean encoded) {
   77.24 +    public byte[] reset(byte[] data) {
   77.25          byte[]  bytes = null;
   77.26 -        // if it is encoded data, we use length field to
   77.27 +        // for asn.1 encoded data, we use length field to
   77.28          // determine the data length and remove redundant paddings.
   77.29 -        if (encoded) {
   77.30 -            if ((data[1] & 0xFF) < 128) {
   77.31 -                bytes = new byte[data[1] + 2];
   77.32 -                System.arraycopy(data, 0, bytes, 0, data[1] + 2);
   77.33 -            } else
   77.34 -                if ((data[1] & 0xFF) > 128) {
   77.35 -                    int len = data[1] & (byte)0x7F;
   77.36 -                    int result = 0;
   77.37 -                    for (int i = 0; i < len; i++) {
   77.38 -                        result |= (data[i + 2] & 0xFF) << (8 * (len - i - 1));
   77.39 -                    }
   77.40 -                    bytes = new byte[result + len + 2];
   77.41 -                    System.arraycopy(data, 0, bytes, 0, result + len + 2);
   77.42 +        if ((data[1] & 0xFF) < 128) {
   77.43 +            bytes = new byte[data[1] + 2];
   77.44 +            System.arraycopy(data, 0, bytes, 0, data[1] + 2);
   77.45 +        } else {
   77.46 +            if ((data[1] & 0xFF) > 128) {
   77.47 +                int len = data[1] & (byte)0x7F;
   77.48 +                int result = 0;
   77.49 +                for (int i = 0; i < len; i++) {
   77.50 +                    result |= (data[i + 2] & 0xFF) << (8 * (len - i - 1));
   77.51                  }
   77.52 -        } else {
   77.53 -            // if it is not encoded, which happens in GSS tokens,
   77.54 -            // we remove padding data according to padding pattern.
   77.55 -            bytes = new byte[data.length - data[data.length - 1]];
   77.56 -            System.arraycopy(data, 0, bytes, 0,
   77.57 -                             data.length - data[data.length - 1]);
   77.58 +                bytes = new byte[result + len + 2];
   77.59 +                System.arraycopy(data, 0, bytes, 0, result + len + 2);
   77.60 +            }
   77.61          }
   77.62          return bytes;
   77.63      }
    78.1 --- a/src/share/classes/sun/security/krb5/KrbApRep.java	Thu Jul 15 20:11:45 2010 -0700
    78.2 +++ b/src/share/classes/sun/security/krb5/KrbApRep.java	Tue Jul 20 22:21:31 2010 -0700
    78.3 @@ -1,5 +1,5 @@
    78.4  /*
    78.5 - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
    78.6 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    78.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    78.8   *
    78.9   * This code is free software; you can redistribute it and/or modify it
   78.10 @@ -130,7 +130,7 @@
   78.11  
   78.12          byte[] temp = rep.encPart.decrypt(tgs_creds.key,
   78.13              KeyUsage.KU_ENC_AP_REP_PART);
   78.14 -        byte[] enc_ap_rep_part = rep.encPart.reset(temp, true);
   78.15 +        byte[] enc_ap_rep_part = rep.encPart.reset(temp);
   78.16  
   78.17          encoding = new DerValue(enc_ap_rep_part);
   78.18          encPart = new EncAPRepPart(encoding);
    79.1 --- a/src/share/classes/sun/security/krb5/KrbApReq.java	Thu Jul 15 20:11:45 2010 -0700
    79.2 +++ b/src/share/classes/sun/security/krb5/KrbApReq.java	Tue Jul 20 22:21:31 2010 -0700
    79.3 @@ -1,5 +1,5 @@
    79.4  /*
    79.5 - * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
    79.6 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    79.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    79.8   *
    79.9   * This code is free software; you can redistribute it and/or modify it
   79.10 @@ -279,14 +279,14 @@
   79.11  
   79.12          byte[] bytes = apReqMessg.ticket.encPart.decrypt(dkey,
   79.13              KeyUsage.KU_TICKET);
   79.14 -        byte[] temp = apReqMessg.ticket.encPart.reset(bytes, true);
   79.15 +        byte[] temp = apReqMessg.ticket.encPart.reset(bytes);
   79.16          EncTicketPart enc_ticketPart = new EncTicketPart(temp);
   79.17  
   79.18          checkPermittedEType(enc_ticketPart.key.getEType());
   79.19  
   79.20          byte[] bytes2 = apReqMessg.authenticator.decrypt(enc_ticketPart.key,
   79.21              KeyUsage.KU_AP_REQ_AUTHENTICATOR);
   79.22 -        byte[] temp2 = apReqMessg.authenticator.reset(bytes2, true);
   79.23 +        byte[] temp2 = apReqMessg.authenticator.reset(bytes2);
   79.24          authenticator = new Authenticator(temp2);
   79.25          ctime = authenticator.ctime;
   79.26          cusec = authenticator.cusec;
    80.1 --- a/src/share/classes/sun/security/krb5/KrbAsRep.java	Thu Jul 15 20:11:45 2010 -0700
    80.2 +++ b/src/share/classes/sun/security/krb5/KrbAsRep.java	Tue Jul 20 22:21:31 2010 -0700
    80.3 @@ -1,5 +1,5 @@
    80.4  /*
    80.5 - * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
    80.6 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    80.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    80.8   *
    80.9   * This code is free software; you can redistribute it and/or modify it
   80.10 @@ -95,7 +95,7 @@
   80.11  
   80.12          byte[] enc_as_rep_bytes = rep.encPart.decrypt(dkey,
   80.13              KeyUsage.KU_ENC_AS_REP_PART);
   80.14 -        byte[] enc_as_rep_part = rep.encPart.reset(enc_as_rep_bytes, true);
   80.15 +        byte[] enc_as_rep_part = rep.encPart.reset(enc_as_rep_bytes);
   80.16  
   80.17          encoding = new DerValue(enc_as_rep_part);
   80.18          EncASRepPart enc_part = new EncASRepPart(encoding);
    81.1 --- a/src/share/classes/sun/security/krb5/KrbCred.java	Thu Jul 15 20:11:45 2010 -0700
    81.2 +++ b/src/share/classes/sun/security/krb5/KrbCred.java	Tue Jul 20 22:21:31 2010 -0700
    81.3 @@ -1,5 +1,5 @@
    81.4  /*
    81.5 - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
    81.6 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    81.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    81.8   *
    81.9   * This code is free software; you can redistribute it and/or modify it
   81.10 @@ -130,7 +130,7 @@
   81.11  
   81.12          byte[] temp = credMessg.encPart.decrypt(key,
   81.13              KeyUsage.KU_ENC_KRB_CRED_PART);
   81.14 -        byte[] plainText = credMessg.encPart.reset(temp, true);
   81.15 +        byte[] plainText = credMessg.encPart.reset(temp);
   81.16          DerValue encoding = new DerValue(plainText);
   81.17          EncKrbCredPart encPart = new EncKrbCredPart(encoding);
   81.18  
    82.1 --- a/src/share/classes/sun/security/krb5/KrbPriv.java	Thu Jul 15 20:11:45 2010 -0700
    82.2 +++ b/src/share/classes/sun/security/krb5/KrbPriv.java	Tue Jul 20 22:21:31 2010 -0700
    82.3 @@ -1,5 +1,5 @@
    82.4  /*
    82.5 - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
    82.6 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    82.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    82.8   *
    82.9   * This code is free software; you can redistribute it and/or modify it
   82.10 @@ -31,7 +31,6 @@
   82.11  
   82.12  package sun.security.krb5;
   82.13  
   82.14 -import sun.security.krb5.EncryptionKey;
   82.15  import sun.security.krb5.internal.*;
   82.16  import sun.security.krb5.internal.crypto.*;
   82.17  import sun.security.util.*;
   82.18 @@ -159,7 +158,7 @@
   82.19  
   82.20                                 byte[] bytes = krb_priv.encPart.decrypt(key,
   82.21                                     KeyUsage.KU_ENC_KRB_PRIV_PART);
   82.22 -                               byte[] temp = krb_priv.encPart.reset(bytes, true);
   82.23 +                               byte[] temp = krb_priv.encPart.reset(bytes);
   82.24                                 DerValue ref = new DerValue(temp);
   82.25                                 EncKrbPrivPart enc_part = new EncKrbPrivPart(ref);
   82.26  
    83.1 --- a/src/share/classes/sun/security/krb5/KrbTgsRep.java	Thu Jul 15 20:11:45 2010 -0700
    83.2 +++ b/src/share/classes/sun/security/krb5/KrbTgsRep.java	Tue Jul 20 22:21:31 2010 -0700
    83.3 @@ -1,5 +1,5 @@
    83.4  /*
    83.5 - * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
    83.6 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    83.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    83.8   *
    83.9   * This code is free software; you can redistribute it and/or modify it
   83.10 @@ -79,7 +79,7 @@
   83.11              tgsReq.usedSubkey() ? KeyUsage.KU_ENC_TGS_REP_PART_SUBKEY :
   83.12              KeyUsage.KU_ENC_TGS_REP_PART_SESSKEY);
   83.13  
   83.14 -        byte[] enc_tgs_rep_part = rep.encPart.reset(enc_tgs_rep_bytes, true);
   83.15 +        byte[] enc_tgs_rep_part = rep.encPart.reset(enc_tgs_rep_bytes);
   83.16          ref = new DerValue(enc_tgs_rep_part);
   83.17          EncTGSRepPart enc_part = new EncTGSRepPart(ref);
   83.18          rep.ticket.sname.setRealm(rep.ticket.realm);
    84.1 --- a/src/share/classes/sun/security/krb5/internal/crypto/EType.java	Thu Jul 15 20:11:45 2010 -0700
    84.2 +++ b/src/share/classes/sun/security/krb5/internal/crypto/EType.java	Tue Jul 20 22:21:31 2010 -0700
    84.3 @@ -185,20 +185,20 @@
    84.4      // is set to false.
    84.5  
    84.6      private static final int[] BUILTIN_ETYPES = new int[] {
    84.7 +        EncryptedData.ETYPE_AES256_CTS_HMAC_SHA1_96,
    84.8 +        EncryptedData.ETYPE_AES128_CTS_HMAC_SHA1_96,
    84.9 +        EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD,
   84.10 +        EncryptedData.ETYPE_ARCFOUR_HMAC,
   84.11 +        EncryptedData.ETYPE_DES_CBC_CRC,
   84.12          EncryptedData.ETYPE_DES_CBC_MD5,
   84.13 -        EncryptedData.ETYPE_DES_CBC_CRC,
   84.14 -        EncryptedData.ETYPE_ARCFOUR_HMAC,
   84.15 -        EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD,
   84.16 -        EncryptedData.ETYPE_AES128_CTS_HMAC_SHA1_96,
   84.17 -        EncryptedData.ETYPE_AES256_CTS_HMAC_SHA1_96,
   84.18      };
   84.19  
   84.20      private static final int[] BUILTIN_ETYPES_NOAES256 = new int[] {
   84.21 +        EncryptedData.ETYPE_AES128_CTS_HMAC_SHA1_96,
   84.22 +        EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD,
   84.23 +        EncryptedData.ETYPE_ARCFOUR_HMAC,
   84.24 +        EncryptedData.ETYPE_DES_CBC_CRC,
   84.25          EncryptedData.ETYPE_DES_CBC_MD5,
   84.26 -        EncryptedData.ETYPE_DES_CBC_CRC,
   84.27 -        EncryptedData.ETYPE_ARCFOUR_HMAC,
   84.28 -        EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD,
   84.29 -        EncryptedData.ETYPE_AES128_CTS_HMAC_SHA1_96,
   84.30      };
   84.31  
   84.32  
   84.33 @@ -217,8 +217,8 @@
   84.34              result = BUILTIN_ETYPES;
   84.35          }
   84.36          if (!ALLOW_WEAK_CRYPTO) {
   84.37 -            // The first 2 etypes are now weak ones
   84.38 -            return Arrays.copyOfRange(result, 2, result.length);
   84.39 +            // The last 2 etypes are now weak ones
   84.40 +            return Arrays.copyOfRange(result, 0, result.length - 2);
   84.41          }
   84.42          return result;
   84.43      }
    85.1 --- a/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java	Thu Jul 15 20:11:45 2010 -0700
    85.2 +++ b/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java	Tue Jul 20 22:21:31 2010 -0700
    85.3 @@ -1,5 +1,5 @@
    85.4  /*
    85.5 - * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
    85.6 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    85.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    85.8   *
    85.9   * This code is free software; you can redistribute it and/or modify it
   85.10 @@ -228,37 +228,6 @@
   85.11      }
   85.12  
   85.13      /**
   85.14 -     * Reads the service key from the keytab file.
   85.15 -     * @param service the PrincipalName of the requested service.
   85.16 -     * @return the last service key in the keytab with the highest kvno
   85.17 -     */
   85.18 -    public EncryptionKey readServiceKey(PrincipalName service) {
   85.19 -        KeyTabEntry entry = null;
   85.20 -        EncryptionKey key = null;
   85.21 -        if (entries != null) {
   85.22 -            // Find latest entry for this service that has an etype
   85.23 -            // that has been configured for use
   85.24 -            for (int i = entries.size()-1; i >= 0; i--) {
   85.25 -                entry = entries.elementAt(i);
   85.26 -                if (entry.service.match(service)) {
   85.27 -                    if (EType.isSupported(entry.keyType)) {
   85.28 -                        if (key == null ||
   85.29 -                                entry.keyVersion > key.getKeyVersionNumber()) {
   85.30 -                            key = new EncryptionKey(entry.keyblock,
   85.31 -                                             entry.keyType,
   85.32 -                                             new Integer(entry.keyVersion));
   85.33 -                        }
   85.34 -                    } else if (DEBUG) {
   85.35 -                        System.out.println("Found unsupported keytype (" +
   85.36 -                            entry.keyType + ") for " + service);
   85.37 -                    }
   85.38 -                }
   85.39 -            }
   85.40 -        }
   85.41 -        return key;
   85.42 -    }
   85.43 -
   85.44 -    /**
   85.45       * Reads all keys for a service from the keytab file that have
   85.46       * etypes that have been configured for use. If there are multiple
   85.47       * keys with same etype, the one with the highest kvno is returned.
   85.48 @@ -309,7 +278,7 @@
   85.49          Arrays.sort(retVal, new Comparator<EncryptionKey>() {
   85.50              @Override
   85.51              public int compare(EncryptionKey o1, EncryptionKey o2) {
   85.52 -                if (etypes != null && etypes != EType.getBuiltInDefaults()) {
   85.53 +                if (etypes != null) {
   85.54                      int o1EType = o1.getEType();
   85.55                      int o2EType = o2.getEType();
   85.56                      if (o1EType != o2EType) {
   85.57 @@ -320,6 +289,9 @@
   85.58                                  return 1;
   85.59                              }
   85.60                          }
   85.61 +                        // Neither o1EType nor o2EType in default_tkt_enctypes,
   85.62 +                        // therefore won't be used in AS-REQ. We do not care
   85.63 +                        // about their order, use kvno is OK.
   85.64                      }
   85.65                  }
   85.66                  return o2.getKeyVersionNumber().intValue()
    86.1 --- a/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java	Thu Jul 15 20:11:45 2010 -0700
    86.2 +++ b/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java	Tue Jul 20 22:21:31 2010 -0700
    86.3 @@ -1,5 +1,5 @@
    86.4  /*
    86.5 - * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
    86.6 + * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
    86.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    86.8   *
    86.9   * This code is free software; you can redistribute it and/or modify it
   86.10 @@ -180,24 +180,15 @@
   86.11          String alias;
   86.12      };
   86.13  
   86.14 -    private static class KeyId {
   86.15 -        byte[] keyId;
   86.16 -
   86.17 -        KeyId(byte[] keyId) {
   86.18 +    // A certificate with its PKCS #9 attributes
   86.19 +    private static class CertEntry {
   86.20 +        final X509Certificate cert;
   86.21 +        final byte[] keyId;
   86.22 +        final String alias;
   86.23 +        CertEntry(X509Certificate cert, byte[] keyId, String alias) {
   86.24 +            this.cert = cert;
   86.25              this.keyId = keyId;
   86.26 -        }
   86.27 -        public int hashCode() {
   86.28 -            int hash = 0;
   86.29 -
   86.30 -            for (int i = 0; i < keyId.length; i++)
   86.31 -                hash += keyId[i];
   86.32 -            return hash;
   86.33 -        }
   86.34 -        public boolean equals(Object obj) {
   86.35 -            if (!(obj instanceof KeyId))
   86.36 -                return false;
   86.37 -            KeyId that = (KeyId)obj;
   86.38 -            return (Arrays.equals(this.keyId, that.keyId));
   86.39 +            this.alias = alias;
   86.40          }
   86.41      }
   86.42  
   86.43 @@ -209,7 +200,9 @@
   86.44                                  new Hashtable<String, KeyEntry>();
   86.45  
   86.46      private ArrayList<KeyEntry> keyList = new ArrayList<KeyEntry>();
   86.47 -    private LinkedHashMap<Object, X509Certificate> certs = new LinkedHashMap<Object, X509Certificate>();
   86.48 +    private LinkedHashMap<X500Principal, X509Certificate> certsMap =
   86.49 +            new LinkedHashMap<X500Principal, X509Certificate>();
   86.50 +    private ArrayList<CertEntry> certEntries = new ArrayList<CertEntry>();
   86.51  
   86.52      /**
   86.53       * Returns the key associated with the given alias, using the given
   86.54 @@ -472,6 +465,15 @@
   86.55          KeyEntry entry = new KeyEntry();
   86.56          entry.date = new Date();
   86.57  
   86.58 +        try {
   86.59 +            // set the keyId to current date
   86.60 +            entry.keyId = ("Time " + (entry.date).getTime()).getBytes("UTF8");
   86.61 +        } catch (UnsupportedEncodingException ex) {
   86.62 +            // Won't happen
   86.63 +        }
   86.64 +        // set the alias
   86.65 +        entry.alias = alias.toLowerCase();
   86.66 +
   86.67          entry.protectedPrivKey = key.clone();
   86.68          if (chain != null) {
   86.69             entry.chain = chain.clone();
   86.70 @@ -1027,10 +1029,9 @@
   86.71                  // All Certs should have a unique friendlyName.
   86.72                  // This change is made to meet NSS requirements.
   86.73                  byte[] bagAttrs = null;
   86.74 -                String friendlyName = cert.getSubjectX500Principal().getName();
   86.75                  if (i == 0) {
   86.76                      // Only End-Entity Cert should have a localKeyId.
   86.77 -                    bagAttrs = getBagAttributes(friendlyName, entry.keyId);
   86.78 +                    bagAttrs = getBagAttributes(entry.alias, entry.keyId);
   86.79                  } else {
   86.80                      // Trusted root CA certs and Intermediate CA certs do not
   86.81                      // need to have a localKeyId, and hence localKeyId is null
   86.82 @@ -1038,7 +1039,8 @@
   86.83                      // NSS pkcs12 library requires trusted CA certs in the
   86.84                      // certificate chain to have unique or null localKeyID.
   86.85                      // However, IE/OpenSSL do not impose this restriction.
   86.86 -                    bagAttrs = getBagAttributes(friendlyName, null);
   86.87 +                    bagAttrs = getBagAttributes(
   86.88 +                            cert.getSubjectX500Principal().getName(), null);
   86.89                  }
   86.90                  if (bagAttrs != null) {
   86.91                      safeBag.write(bagAttrs);
   86.92 @@ -1333,24 +1335,49 @@
   86.93              if (entry.keyId != null) {
   86.94                  ArrayList<X509Certificate> chain =
   86.95                                  new ArrayList<X509Certificate>();
   86.96 -                X509Certificate cert = certs.get(new KeyId(entry.keyId));
   86.97 +                X509Certificate cert = findMatchedCertificate(entry);
   86.98                  while (cert != null) {
   86.99                      chain.add(cert);
  86.100                      X500Principal issuerDN = cert.getIssuerX500Principal();
  86.101                      if (issuerDN.equals(cert.getSubjectX500Principal())) {
  86.102                          break;
  86.103                      }
  86.104 -                    cert = certs.get(issuerDN);
  86.105 +                    cert = certsMap.get(issuerDN);
  86.106                  }
  86.107                  /* Update existing KeyEntry in entries table */
  86.108                  if (chain.size() > 0)
  86.109                      entry.chain = chain.toArray(new Certificate[chain.size()]);
  86.110              }
  86.111          }
  86.112 -        certs.clear();
  86.113 +        certEntries.clear();
  86.114 +        certsMap.clear();
  86.115          keyList.clear();
  86.116      }
  86.117  
  86.118 +    /**
  86.119 +     * Locates a matched CertEntry from certEntries, and returns its cert.
  86.120 +     * @param entry the KeyEntry to match
  86.121 +     * @return a certificate, null if not found
  86.122 +     */
  86.123 +    private X509Certificate findMatchedCertificate(KeyEntry entry) {
  86.124 +        CertEntry keyIdMatch = null;
  86.125 +        CertEntry aliasMatch = null;
  86.126 +        for (CertEntry ce: certEntries) {
  86.127 +            if (Arrays.equals(entry.keyId, ce.keyId)) {
  86.128 +                keyIdMatch = ce;
  86.129 +                if (entry.alias.equalsIgnoreCase(ce.alias)) {
  86.130 +                    // Full match!
  86.131 +                    return ce.cert;
  86.132 +                }
  86.133 +            } else if (entry.alias.equalsIgnoreCase(ce.alias)) {
  86.134 +                aliasMatch = ce;
  86.135 +            }
  86.136 +        }
  86.137 +        // keyId match first, for compatibility
  86.138 +        if (keyIdMatch != null) return keyIdMatch.cert;
  86.139 +        else if (aliasMatch != null) return aliasMatch.cert;
  86.140 +        else return null;
  86.141 +    }
  86.142  
  86.143      private void loadSafeContents(DerInputStream stream, char[] password)
  86.144          throws IOException, NoSuchAlgorithmException, CertificateException
  86.145 @@ -1491,19 +1518,12 @@
  86.146                          keyId = "01".getBytes("UTF8");
  86.147                      }
  86.148                  }
  86.149 -                if (keyId != null) {
  86.150 -                    KeyId keyid = new KeyId(keyId);
  86.151 -                    if (!certs.containsKey(keyid))
  86.152 -                        certs.put(keyid, cert);
  86.153 -                }
  86.154 -                if (alias != null) {
  86.155 -                    if (!certs.containsKey(alias))
  86.156 -                        certs.put(alias, cert);
  86.157 -                }
  86.158 +                certEntries.add(new CertEntry(cert, keyId, alias));
  86.159                  X500Principal subjectDN = cert.getSubjectX500Principal();
  86.160                  if (subjectDN != null) {
  86.161 -                    if (!certs.containsKey(subjectDN))
  86.162 -                        certs.put(subjectDN, cert);
  86.163 +                    if (!certsMap.containsKey(subjectDN)) {
  86.164 +                        certsMap.put(subjectDN, cert);
  86.165 +                    }
  86.166                  }
  86.167              }
  86.168          }
    87.1 --- a/src/share/classes/sun/security/ssl/krb5/KerberosClientKeyExchangeImpl.java	Thu Jul 15 20:11:45 2010 -0700
    87.2 +++ b/src/share/classes/sun/security/ssl/krb5/KerberosClientKeyExchangeImpl.java	Tue Jul 20 22:21:31 2010 -0700
    87.3 @@ -212,7 +212,7 @@
    87.4              byte[] bytes = encPart.decrypt(secretKey, KeyUsage.KU_TICKET);
    87.5  
    87.6              // Reset data stream after decryption, remove redundant bytes
    87.7 -            byte[] temp = encPart.reset(bytes, true);
    87.8 +            byte[] temp = encPart.reset(bytes);
    87.9              EncTicketPart encTicketPart = new EncTicketPart(temp);
   87.10  
   87.11              // Record the Kerberos Principals
    88.1 --- a/src/share/classes/sun/security/ssl/krb5/KerberosPreMasterSecret.java	Thu Jul 15 20:11:45 2010 -0700
    88.2 +++ b/src/share/classes/sun/security/ssl/krb5/KerberosPreMasterSecret.java	Tue Jul 20 22:21:31 2010 -0700
    88.3 @@ -1,5 +1,5 @@
    88.4  /*
    88.5 - * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
    88.6 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
    88.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    88.8   *
    88.9   * This code is free software; you can redistribute it and/or modify it
   88.10 @@ -27,7 +27,7 @@
   88.11  
   88.12  import java.io.*;
   88.13  import java.security.*;
   88.14 -import java.security.interfaces.*;
   88.15 +import java.util.Arrays;
   88.16  
   88.17  import javax.net.ssl.*;
   88.18  
   88.19 @@ -128,8 +128,8 @@
   88.20                 "are not supported for TLS Kerberos cipher suites");
   88.21          }
   88.22  
   88.23 -         // Decrypt premaster secret
   88.24 -         try {
   88.25 +        // Decrypt premaster secret
   88.26 +        try {
   88.27              EncryptedData data = new EncryptedData(sessionKey.getEType(),
   88.28                          null /* optional kvno */, encrypted);
   88.29  
   88.30 @@ -141,8 +141,25 @@
   88.31                   }
   88.32              }
   88.33  
   88.34 -            // Reset data stream after decryption, remove redundant bytes
   88.35 -            preMaster =  data.reset(temp, false);
   88.36 +            // Remove padding bytes after decryption. Only DES and DES3 have
   88.37 +            // paddings and we don't support DES3 in TLS (see above)
   88.38 +
   88.39 +            if (temp.length == 52 &&
   88.40 +                    data.getEType() == EncryptedData.ETYPE_DES_CBC_CRC) {
   88.41 +                // For des-cbc-crc, 4 paddings. Value can be 0x04 or 0x00.
   88.42 +                if (paddingByteIs(temp, 52, (byte)4) ||
   88.43 +                        paddingByteIs(temp, 52, (byte)0)) {
   88.44 +                    temp = Arrays.copyOf(temp, 48);
   88.45 +                }
   88.46 +            } else if (temp.length == 56 &&
   88.47 +                    data.getEType() == EncryptedData.ETYPE_DES_CBC_MD5) {
   88.48 +                // For des-cbc-md5, 8 paddings with 0x08, or no padding
   88.49 +                if (paddingByteIs(temp, 56, (byte)8)) {
   88.50 +                    temp = Arrays.copyOf(temp, 48);
   88.51 +                }
   88.52 +            }
   88.53 +
   88.54 +            preMaster = temp;
   88.55  
   88.56              protocolVersion = ProtocolVersion.valueOf(preMaster[0],
   88.57                   preMaster[1]);
   88.58 @@ -191,6 +208,19 @@
   88.59          }
   88.60      }
   88.61  
   88.62 +    /**
   88.63 +     * Checks if all paddings of data are b
   88.64 +     * @param data the block with padding
   88.65 +     * @param len length of data, >= 48
   88.66 +     * @param b expected padding byte
   88.67 +     */
   88.68 +    private static boolean paddingByteIs(byte[] data, int len, byte b) {
   88.69 +        for (int i=48; i<len; i++) {
   88.70 +            if (data[i] != b) return false;
   88.71 +        }
   88.72 +        return true;
   88.73 +    }
   88.74 +
   88.75      /*
   88.76       * Used by server to generate premaster secret in case of
   88.77       * problem decoding ticket.
    89.1 --- a/src/share/classes/sun/swing/SwingUtilities2.java	Thu Jul 15 20:11:45 2010 -0700
    89.2 +++ b/src/share/classes/sun/swing/SwingUtilities2.java	Tue Jul 20 22:21:31 2010 -0700
    89.3 @@ -438,8 +438,12 @@
    89.4          // c may be null here.
    89.5          String clipString = "...";
    89.6          availTextWidth -= SwingUtilities2.stringWidth(c, fm, clipString);
    89.7 +        if (availTextWidth <= 0) {
    89.8 +            //can not fit any characters
    89.9 +            return clipString;
   89.10 +        }
   89.11 +
   89.12          boolean needsTextLayout;
   89.13 -
   89.14          synchronized (charsBufferLock) {
   89.15              int stringLength = syncCharsBuffer(string);
   89.16              needsTextLayout =
    90.1 --- a/src/share/native/sun/awt/image/BufImgSurfaceData.c	Thu Jul 15 20:11:45 2010 -0700
    90.2 +++ b/src/share/native/sun/awt/image/BufImgSurfaceData.c	Tue Jul 20 22:21:31 2010 -0700
    90.3 @@ -111,6 +111,10 @@
    90.4  {
    90.5      BufImgSDOps *bisdo =
    90.6          (BufImgSDOps*)SurfaceData_InitOps(env, bisd, sizeof(BufImgSDOps));
    90.7 +    if (bisdo == NULL) {
    90.8 +        JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
    90.9 +        return;
   90.10 +    }
   90.11      bisdo->sdOps.Lock = BufImg_Lock;
   90.12      bisdo->sdOps.GetRasInfo = BufImg_GetRasInfo;
   90.13      bisdo->sdOps.Release = BufImg_Release;
    91.1 --- a/src/solaris/bin/java_md.c	Thu Jul 15 20:11:45 2010 -0700
    91.2 +++ b/src/solaris/bin/java_md.c	Tue Jul 20 22:21:31 2010 -0700
    91.3 @@ -1,5 +1,5 @@
    91.4  /*
    91.5 - * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved.
    91.6 + * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
    91.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    91.8   *
    91.9   * This code is free software; you can redistribute it and/or modify it
   91.10 @@ -183,13 +183,9 @@
   91.11  }
   91.12  
   91.13  void
   91.14 -CreateExecutionEnvironment(int *_argcp,
   91.15 -                           char ***_argvp,
   91.16 -                           char jrepath[],
   91.17 -                           jint so_jrepath,
   91.18 -                           char jvmpath[],
   91.19 -                           jint so_jvmpath,
   91.20 -                           char **original_argv) {
   91.21 +CreateExecutionEnvironment(int *pargc, char ***pargv,
   91.22 +                           char jrepath[], jint so_jrepath,
   91.23 +                           char jvmpath[], jint so_jvmpath) {
   91.24    /*
   91.25     * First, determine if we are running the desired data model.  If we
   91.26     * are running the desired data model, all the error messages
   91.27 @@ -200,18 +196,17 @@
   91.28     * os/processor combination has dual mode capabilities.
   91.29     */
   91.30  
   91.31 -    int original_argc = *_argcp;
   91.32      jboolean jvmpathExists;
   91.33  
   91.34      /* Compute/set the name of the executable */
   91.35 -    SetExecname(*_argvp);
   91.36 +    SetExecname(*pargv);
   91.37  
   91.38      /* Check data model flags, and exec process, if needed */
   91.39      {
   91.40        char *arch        = (char *)GetArch(); /* like sparc or sparcv9 */
   91.41        char * jvmtype    = NULL;
   91.42 -      int argc          = *_argcp;
   91.43 -      char **argv       = original_argv;
   91.44 +      int  argc         = *pargc;
   91.45 +      char **argv       = *pargv;
   91.46  
   91.47        int running       = CURRENT_DATA_MODEL;
   91.48  
   91.49 @@ -233,7 +228,7 @@
   91.50        { /* open new scope to declare local variables */
   91.51          int i;
   91.52  
   91.53 -        newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(*newargv));
   91.54 +        newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*));
   91.55          newargv[newargc++] = argv[0];
   91.56  
   91.57          /* scan for data model arguments and remove from argument list;
   91.58 @@ -293,7 +288,11 @@
   91.59          }
   91.60  
   91.61          jvmpath[0] = '\0';
   91.62 -        jvmtype = CheckJvmType(_argcp, _argvp, JNI_FALSE);
   91.63 +        jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
   91.64 +        if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
   91.65 +            JLI_ReportErrorMessage(CFG_ERROR9);
   91.66 +            exit(4);
   91.67 +        }
   91.68  
   91.69          if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch )) {
   91.70            JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
   91.71 @@ -309,7 +308,9 @@
   91.72          if (running != wanted) {
   91.73            /* Find out where the JRE is that we will be using. */
   91.74            if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) {
   91.75 -            goto EndDataModelSpeculate;
   91.76 +            /* give up and let other code report error message */
   91.77 +            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
   91.78 +            exit(1);
   91.79            }
   91.80  
   91.81            /*
   91.82 @@ -317,16 +318,21 @@
   91.83             * selection options.
   91.84             */
   91.85            if (ReadKnownVMs(jrepath, GetArchPath(wanted), JNI_TRUE) < 1) {
   91.86 -            goto EndDataModelSpeculate;
   91.87 +            /* give up and let other code report error message */
   91.88 +            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
   91.89 +            exit(1);
   91.90            }
   91.91            jvmpath[0] = '\0';
   91.92 -          jvmtype = CheckJvmType(_argcp, _argvp, JNI_TRUE);
   91.93 +          jvmtype = CheckJvmType(pargc, pargv, JNI_TRUE);
   91.94 +          if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
   91.95 +            JLI_ReportErrorMessage(CFG_ERROR9);
   91.96 +            exit(4);
   91.97 +          }
   91.98 +
   91.99            /* exec child can do error checking on the existence of the path */
  91.100            jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted));
  91.101  
  91.102          }
  91.103 -      EndDataModelSpeculate: /* give up and let other code report error message */
  91.104 -        ;
  91.105  #else
  91.106          JLI_ReportErrorMessage(JRE_ERROR2, wanted);
  91.107          exit(1);
  91.108 @@ -398,9 +404,9 @@
  91.109      struct stat s;
  91.110  
  91.111      if (JLI_StrChr(jvmtype, '/')) {
  91.112 -        sprintf(jvmpath, "%s/" JVM_DLL, jvmtype);
  91.113 +        JLI_Snprintf(jvmpath, jvmpathsize, "%s/" JVM_DLL, jvmtype);
  91.114      } else {
  91.115 -        sprintf(jvmpath, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype);
  91.116 +        JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype);
  91.117      }
  91.118  
  91.119      JLI_TraceLauncher("Does `%s' exist ... ", jvmpath);
  91.120 @@ -424,26 +430,24 @@
  91.121  
  91.122      if (GetApplicationHome(path, pathsize)) {
  91.123          /* Is JRE co-located with the application? */
  91.124 -        sprintf(libjava, "%s/lib/%s/" JAVA_DLL, path, arch);
  91.125 +        JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/%s/" JAVA_DLL, path, arch);
  91.126          if (access(libjava, F_OK) == 0) {
  91.127 -            goto found;
  91.128 +            JLI_TraceLauncher("JRE path is %s\n", path);
  91.129 +            return JNI_TRUE;
  91.130          }
  91.131  
  91.132          /* Does the app ship a private JRE in <apphome>/jre directory? */
  91.133 -        sprintf(libjava, "%s/jre/lib/%s/" JAVA_DLL, path, arch);
  91.134 +        JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/%s/" JAVA_DLL, path, arch);
  91.135          if (access(libjava, F_OK) == 0) {
  91.136              JLI_StrCat(path, "/jre");
  91.137 -            goto found;
  91.138 +            JLI_TraceLauncher("JRE path is %s\n", path);
  91.139 +            return JNI_TRUE;
  91.140          }
  91.141      }
  91.142  
  91.143      if (!speculative)
  91.144        JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
  91.145      return JNI_FALSE;
  91.146 -
  91.147 - found:
  91.148 -    JLI_TraceLauncher("JRE path is %s\n", path);
  91.149 -    return JNI_TRUE;
  91.150  }
  91.151  
  91.152  jboolean
  91.153 @@ -463,14 +467,18 @@
  91.154        int location;
  91.155  
  91.156        fp = fopen(jvmpath, "r");
  91.157 -      if(fp == NULL)
  91.158 -        goto error;
  91.159 +      if (fp == NULL) {
  91.160 +        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
  91.161 +        return JNI_FALSE;
  91.162 +      }
  91.163  
  91.164        /* read in elf header */
  91.165        count = fread((void*)(&elf_head), sizeof(Elf32_Ehdr), 1, fp);
  91.166        fclose(fp);
  91.167 -      if(count < 1)
  91.168 -        goto error;
  91.169 +      if (count < 1) {
  91.170 +        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
  91.171 +        return JNI_FALSE;
  91.172 +      }
  91.173  
  91.174        /*
  91.175         * Check for running a server vm (compiled with -xarch=v8plus)
  91.176 @@ -481,41 +489,42 @@
  91.177         * does not have to be checked for in binaries with an LP64 data
  91.178         * model.
  91.179         */
  91.180 -      if(elf_head.e_machine == EM_SPARC32PLUS) {
  91.181 +      if (elf_head.e_machine == EM_SPARC32PLUS) {
  91.182          char buf[257];  /* recommended buffer size from sysinfo man
  91.183                             page */
  91.184          long length;
  91.185          char* location;
  91.186  
  91.187          length = sysinfo(SI_ISALIST, buf, 257);
  91.188 -        if(length > 0) {
  91.189 -          location = JLI_StrStr(buf, "sparcv8plus ");
  91.190 -          if(location == NULL) {
  91.191 +        if (length > 0) {
  91.192 +            location = JLI_StrStr(buf, "sparcv8plus ");
  91.193 +          if (location == NULL) {
  91.194              JLI_ReportErrorMessage(JVM_ERROR3);
  91.195              return JNI_FALSE;
  91.196            }
  91.197          }
  91.198        }
  91.199  #endif
  91.200 -      JLI_ReportErrorMessage(DLL_ERROR1, __LINE__);
  91.201 -      goto error;
  91.202 +        JLI_ReportErrorMessage(DLL_ERROR1, __LINE__);
  91.203 +        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
  91.204 +        return JNI_FALSE;
  91.205      }
  91.206  
  91.207      ifn->CreateJavaVM = (CreateJavaVM_t)
  91.208 -      dlsym(libjvm, "JNI_CreateJavaVM");
  91.209 -    if (ifn->CreateJavaVM == NULL)
  91.210 -        goto error;
  91.211 +        dlsym(libjvm, "JNI_CreateJavaVM");
  91.212 +    if (ifn->CreateJavaVM == NULL) {
  91.213 +        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
  91.214 +        return JNI_FALSE;
  91.215 +    }
  91.216  
  91.217      ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t)
  91.218          dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs");
  91.219 -    if (ifn->GetDefaultJavaVMInitArgs == NULL)
  91.220 -      goto error;
  91.221 +    if (ifn->GetDefaultJavaVMInitArgs == NULL) {
  91.222 +        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
  91.223 +        return JNI_FALSE;
  91.224 +    }
  91.225  
  91.226      return JNI_TRUE;
  91.227 -
  91.228 -error:
  91.229 -    JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
  91.230 -    return JNI_FALSE;
  91.231  }
  91.232  
  91.233  /*
  91.234 @@ -575,7 +584,7 @@
  91.235      char name[PATH_MAX + 2], *real;
  91.236  
  91.237      if ((JLI_StrLen(indir) + JLI_StrLen(cmd) + 1)  > PATH_MAX) return 0;
  91.238 -    sprintf(name, "%s%c%s", indir, FILE_SEPARATOR, cmd);
  91.239 +    JLI_Snprintf(name, sizeof(name), "%s%c%s", indir, FILE_SEPARATOR, cmd);
  91.240      if (!ProgramExists(name)) return 0;
  91.241      real = JLI_MemAlloc(PATH_MAX + 2);
  91.242      if (!realpath(name, real))
  91.243 @@ -622,7 +631,7 @@
  91.244          else {
  91.245              /* relative path element */
  91.246              char dir[2*PATH_MAX];
  91.247 -            sprintf(dir, "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)),
  91.248 +            JLI_Snprintf(dir, sizeof(dir), "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)),
  91.249                      FILE_SEPARATOR, s);
  91.250              result = Resolve(dir, program);
  91.251          }
  91.252 @@ -746,7 +755,7 @@
  91.253      if (JLI_StrLen(path) + JLI_StrLen(dir) + 11 > PATH_MAX)
  91.254          return (0);     /* Silently reject "impossibly" long paths */
  91.255  
  91.256 -    sprintf(buffer, "%s/%s/bin/java", path, dir);
  91.257 +    JLI_Snprintf(buffer, sizeof(buffer), "%s/%s/bin/java", path, dir);
  91.258      return ((access(buffer, X_OK) == 0) ? 1 : 0);
  91.259  }
  91.260  
    92.1 --- a/src/solaris/classes/sun/awt/X11/XToolkit.java	Thu Jul 15 20:11:45 2010 -0700
    92.2 +++ b/src/solaris/classes/sun/awt/X11/XToolkit.java	Tue Jul 20 22:21:31 2010 -0700
    92.3 @@ -1053,10 +1053,28 @@
    92.4          return peer;
    92.5      }
    92.6  
    92.7 +    private static Boolean sunAwtDisableGtkFileDialogs = null;
    92.8 +
    92.9 +    /**
   92.10 +     * Returns the value of "sun.awt.disableGtkFileDialogs" property. Default
   92.11 +     * value is {@code false}.
   92.12 +     */
   92.13 +    public synchronized static boolean getSunAwtDisableGtkFileDialogs() {
   92.14 +        if (sunAwtDisableGtkFileDialogs == null) {
   92.15 +            sunAwtDisableGtkFileDialogs =
   92.16 +                getBooleanSystemProperty("sun.awt.disableGtkFileDialogs");
   92.17 +        }
   92.18 +        return sunAwtDisableGtkFileDialogs.booleanValue();
   92.19 +    }
   92.20 +
   92.21      public FileDialogPeer createFileDialog(FileDialog target) {
   92.22 +        FileDialogPeer peer = null;
   92.23          // The current GtkFileChooser is available from GTK+ 2.4
   92.24 -        FileDialogPeer peer = checkGtkVersion(2, 4, 0) ? new GtkFileDialogPeer(
   92.25 -                target) : new XFileDialogPeer(target);
   92.26 +        if (!getSunAwtDisableGtkFileDialogs() && checkGtkVersion(2, 4, 0)) {
   92.27 +            peer = new GtkFileDialogPeer(target);
   92.28 +        } else {
   92.29 +            peer = new XFileDialogPeer(target);
   92.30 +        }
   92.31          targetCreatedPeer(target, peer);
   92.32          return peer;
   92.33      }
   92.34 @@ -1201,14 +1219,6 @@
   92.35          }
   92.36      }
   92.37  
   92.38 -    static String getSystemProperty(final String name) {
   92.39 -        return (String)AccessController.doPrivileged(new PrivilegedAction() {
   92.40 -                public Object run() {
   92.41 -                    return System.getProperty(name);
   92.42 -                }
   92.43 -            });
   92.44 -    }
   92.45 -
   92.46      public PrintJob getPrintJob(final Frame frame, final String doctitle,
   92.47                                  final Properties props) {
   92.48  
    93.1 --- a/src/solaris/classes/sun/awt/X11/XWindow.java	Thu Jul 15 20:11:45 2010 -0700
    93.2 +++ b/src/solaris/classes/sun/awt/X11/XWindow.java	Tue Jul 20 22:21:31 2010 -0700
    93.3 @@ -778,8 +778,8 @@
    93.4                                                            x, y,
    93.5                                                            xbe.get_x_root(),
    93.6                                                            xbe.get_y_root(),
    93.7 -                                                          clickCount,false,MouseWheelEvent.WHEEL_UNIT_SCROLL,
    93.8 -                                                          3,button==4 ?  -1 : 1);
    93.9 +                                                          1,false,MouseWheelEvent.WHEEL_UNIT_SCROLL,
   93.10 +                                                          3,button==4 ?  -1*clickCount : 1*clickCount);
   93.11                  postEventToEventQueue(mwe);
   93.12              }
   93.13          }
    94.1 --- a/src/solaris/demo/jni/Poller/Poller.c	Thu Jul 15 20:11:45 2010 -0700
    94.2 +++ b/src/solaris/demo/jni/Poller/Poller.c	Tue Jul 20 22:21:31 2010 -0700
    94.3 @@ -160,10 +160,10 @@
    94.4    return -1;
    94.5  }
    94.6  
    94.7 -#define MEMORY_EXCEPTION(str) throwOutOfMemoryError(env, "Poller:" ## str)
    94.8 -#define STATE_EXCEPTION(str)  throwIllegalStateException(env, "Poller:" ## str)
    94.9 +#define MEMORY_EXCEPTION(str) throwOutOfMemoryError(env, "Poller:" str)
   94.10 +#define STATE_EXCEPTION(str)  throwIllegalStateException(env, "Poller:" str)
   94.11  #define INTERRUPT_EXCEPTION(str) throwInterruptedIOException(env, \
   94.12 -                                                             "Poller:" ## str)
   94.13 +                                                             "Poller:" str)
   94.14  jint addfd(JNIEnv *, ioevent_t *, jint, jshort);
   94.15  jint removefd(JNIEnv *, ioevent_t *, jint);
   94.16  
    95.1 --- a/src/solaris/native/java/net/NetworkInterface.c	Thu Jul 15 20:11:45 2010 -0700
    95.2 +++ b/src/solaris/native/java/net/NetworkInterface.c	Tue Jul 20 22:21:31 2010 -0700
    95.3 @@ -23,6 +23,7 @@
    95.4   * questions.
    95.5   */
    95.6  
    95.7 +
    95.8  #include <errno.h>
    95.9  #include <strings.h>
   95.10  #include <netinet/in.h>
   95.11 @@ -33,23 +34,23 @@
   95.12  #include <arpa/inet.h>
   95.13  #include <net/if.h>
   95.14  #include <net/if_arp.h>
   95.15 +
   95.16  #ifdef __solaris__
   95.17  #include <sys/dlpi.h>
   95.18  #include <fcntl.h>
   95.19  #include <stropts.h>
   95.20 +#include <sys/sockio.h>
   95.21  #endif
   95.22 +
   95.23  #ifdef __linux__
   95.24  #include <sys/ioctl.h>
   95.25  #include <bits/ioctls.h>
   95.26  #include <linux/sockios.h>
   95.27  #include <sys/utsname.h>
   95.28  #include <stdio.h>
   95.29 -#else
   95.30 -#include <sys/sockio.h>
   95.31  #endif
   95.32  
   95.33  #ifdef __linux__
   95.34 -#define ifr_index ifr_ifindex
   95.35  #define _PATH_PROCNET_IFINET6           "/proc/net/if_inet6"
   95.36  #endif
   95.37  
   95.38 @@ -108,20 +109,41 @@
   95.39  static jfieldID ni_ib4broadcastID;
   95.40  static jfieldID ni_ib4maskID;
   95.41  
   95.42 +/** Private methods declarations **/
   95.43  static jobject createNetworkInterface(JNIEnv *env, netif *ifs);
   95.44 +static int     getFlags0(JNIEnv *env, jstring  ifname);
   95.45  
   95.46 -static netif *enumInterfaces(JNIEnv *env);
   95.47 -static netif *enumIPv4Interfaces(JNIEnv *env, netif *ifs);
   95.48 +static netif  *enumInterfaces(JNIEnv *env);
   95.49 +static netif  *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs);
   95.50 +
   95.51  #ifdef AF_INET6
   95.52 -static netif *enumIPv6Interfaces(JNIEnv *env, netif *ifs);
   95.53 +static netif  *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs);
   95.54  #endif
   95.55  
   95.56 -static netif *addif(JNIEnv *env, netif *ifs, char *if_name, int index,
   95.57 -                    int family, struct sockaddr *new_addrP, int new_addrlen,
   95.58 -                    short prefix);
   95.59 -static void freeif(netif *ifs);
   95.60 -static struct sockaddr *getBroadcast(JNIEnv *env, const char *ifname);
   95.61 -static short getSubnet(JNIEnv *env, const char *ifname);
   95.62 +static netif  *addif(JNIEnv *env, int sock, const char * if_name, netif *ifs, struct sockaddr* ifr_addrP, int family, short prefix);
   95.63 +static void    freeif(netif *ifs);
   95.64 +
   95.65 +static int     openSocket(JNIEnv *env, int proto);
   95.66 +static int     openSocketWithFallback(JNIEnv *env, const char *ifname);
   95.67 +
   95.68 +
   95.69 +static struct  sockaddr *getBroadcast(JNIEnv *env, int sock, const char *name, struct sockaddr *brdcast_store);
   95.70 +static short   getSubnet(JNIEnv *env, int sock, const char *ifname);
   95.71 +static int     getIndex(int sock, const char *ifname);
   95.72 +
   95.73 +static int     getFlags(JNIEnv *env, int sock, const char *ifname);
   95.74 +static int     getMacAddress(JNIEnv *env, int sock,  const char* ifname, const struct in_addr* addr, unsigned char *buf);
   95.75 +static int     getMTU(JNIEnv *env, int sock, const char *ifname);
   95.76 +
   95.77 +
   95.78 +
   95.79 +#ifdef __solaris__
   95.80 +static netif *enumIPvXInterfaces(JNIEnv *env, int sock, netif *ifs, int family);
   95.81 +static int    getMacFromDevice(JNIEnv *env, const char* ifname, unsigned char* retbuf);
   95.82 +#endif
   95.83 +
   95.84 +
   95.85 +/******************* Java entry points *****************************/
   95.86  
   95.87  /*
   95.88   * Class:     java_net_NetworkInterface
   95.89 @@ -172,7 +194,7 @@
   95.90  
   95.91      netif *ifs, *curr;
   95.92      jboolean isCopy;
   95.93 -    const char* name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
   95.94 +    const char* name_utf;
   95.95      jobject obj = NULL;
   95.96  
   95.97      ifs = enumInterfaces(env);
   95.98 @@ -180,6 +202,8 @@
   95.99          return NULL;
  95.100      }
  95.101  
  95.102 +    name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
  95.103 +
  95.104      /*
  95.105       * Search the list of interface based on name
  95.106       */
  95.107 @@ -253,12 +277,13 @@
  95.108      (JNIEnv *env, jclass cls, jobject iaObj) {
  95.109  
  95.110      netif *ifs, *curr;
  95.111 +
  95.112  #ifdef AF_INET6
  95.113 -    int family = (*env)->GetIntField(env, iaObj, ni_iafamilyID) == IPv4?
  95.114 -        AF_INET : AF_INET6;
  95.115 +    int family = (  (*env)->GetIntField(env, iaObj, ni_iafamilyID) == IPv4 ) ? AF_INET : AF_INET6;
  95.116  #else
  95.117 -    int family = AF_INET;
  95.118 +    int family =  AF_INET;
  95.119  #endif
  95.120 +
  95.121      jobject obj = NULL;
  95.122      jboolean match = JNI_FALSE;
  95.123  
  95.124 @@ -390,18 +415,169 @@
  95.125      return netIFArr;
  95.126  }
  95.127  
  95.128 +
  95.129 +/*
  95.130 + * Class:     java_net_NetworkInterface
  95.131 + * Method:    isUp0
  95.132 + * Signature: (Ljava/lang/String;I)Z
  95.133 + */
  95.134 +JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0(JNIEnv *env, jclass cls, jstring name, jint index) {
  95.135 +    int ret = getFlags0(env, name);
  95.136 +    return ((ret & IFF_UP) && (ret & IFF_RUNNING)) ? JNI_TRUE :  JNI_FALSE;
  95.137 +}
  95.138 +
  95.139 +/*
  95.140 + * Class:     java_net_NetworkInterface
  95.141 + * Method:    isP2P0
  95.142 + * Signature: (Ljava/lang/String;I)Z
  95.143 + */
  95.144 +JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0(JNIEnv *env, jclass cls, jstring name, jint index) {
  95.145 +    int ret = getFlags0(env, name);
  95.146 +    return (ret & IFF_POINTOPOINT) ? JNI_TRUE :  JNI_FALSE;
  95.147 +}
  95.148 +
  95.149 +/*
  95.150 + * Class:     java_net_NetworkInterface
  95.151 + * Method:    isLoopback0
  95.152 + * Signature: (Ljava/lang/String;I)Z
  95.153 + */
  95.154 +JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0(JNIEnv *env, jclass cls, jstring name, jint index) {
  95.155 +    int ret = getFlags0(env, name);
  95.156 +    return (ret & IFF_LOOPBACK) ? JNI_TRUE :  JNI_FALSE;
  95.157 +}
  95.158 +
  95.159 +/*
  95.160 + * Class:     java_net_NetworkInterface
  95.161 + * Method:    supportsMulticast0
  95.162 + * Signature: (Ljava/lang/String;I)Z
  95.163 + */
  95.164 +JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0(JNIEnv *env, jclass cls, jstring name, jint index) {
  95.165 +    int ret = getFlags0(env, name);
  95.166 +    return (ret & IFF_MULTICAST) ? JNI_TRUE :  JNI_FALSE;
  95.167 +}
  95.168 +
  95.169 +/*
  95.170 + * Class:     java_net_NetworkInterface
  95.171 + * Method:    getMacAddr0
  95.172 + * Signature: ([bLjava/lang/String;I)[b
  95.173 + */
  95.174 +JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0(JNIEnv *env, jclass class, jbyteArray addrArray, jstring name, jint index) {
  95.175 +    jint addr;
  95.176 +    jbyte caddr[4];
  95.177 +    struct in_addr iaddr;
  95.178 +    jbyteArray ret = NULL;
  95.179 +    unsigned char mac[16];
  95.180 +    int len;
  95.181 +    int sock;
  95.182 +    jboolean isCopy;
  95.183 +    const char* name_utf;
  95.184 +
  95.185 +    name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
  95.186 +
  95.187 +    if ((sock =openSocketWithFallback(env, name_utf)) < 0) {
  95.188 +       (*env)->ReleaseStringUTFChars(env, name, name_utf);
  95.189 +       return JNI_FALSE;
  95.190 +    }
  95.191 +
  95.192 +
  95.193 +    if (!IS_NULL(addrArray)) {
  95.194 +       (*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
  95.195 +       addr = ((caddr[0]<<24) & 0xff000000);
  95.196 +       addr |= ((caddr[1] <<16) & 0xff0000);
  95.197 +       addr |= ((caddr[2] <<8) & 0xff00);
  95.198 +       addr |= (caddr[3] & 0xff);
  95.199 +       iaddr.s_addr = htonl(addr);
  95.200 +       len = getMacAddress(env, sock, name_utf, &iaddr, mac);
  95.201 +    } else {
  95.202 +       len = getMacAddress(env, sock, name_utf,NULL, mac);
  95.203 +    }
  95.204 +    if (len > 0) {
  95.205 +       ret = (*env)->NewByteArray(env, len);
  95.206 +       if (IS_NULL(ret)) {
  95.207 +          /* we may have memory to free at the end of this */
  95.208 +          goto fexit;
  95.209 +       }
  95.210 +       (*env)->SetByteArrayRegion(env, ret, 0, len, (jbyte *) (mac));
  95.211 +    }
  95.212 + fexit:
  95.213 +   /* release the UTF string and interface list */
  95.214 +   (*env)->ReleaseStringUTFChars(env, name, name_utf);
  95.215 +
  95.216 +   close(sock);
  95.217 +   return ret;
  95.218 +}
  95.219 +
  95.220 +/*
  95.221 + * Class:       java_net_NetworkInterface
  95.222 + * Method:      getMTU0
  95.223 + * Signature:   ([bLjava/lang/String;I)I
  95.224 + */
  95.225 +
  95.226 +JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0(JNIEnv *env, jclass class, jstring name, jint index) {
  95.227 +    jboolean isCopy;
  95.228 +    int ret = -1;
  95.229 +    int sock;
  95.230 +    const char* name_utf;
  95.231 +
  95.232 +    name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
  95.233 +
  95.234 +    if ((sock =openSocketWithFallback(env, name_utf)) < 0) {
  95.235 +       (*env)->ReleaseStringUTFChars(env, name, name_utf);
  95.236 +       return JNI_FALSE;
  95.237 +    }
  95.238 +
  95.239 +    ret = getMTU(env, sock, name_utf);
  95.240 +
  95.241 +    (*env)->ReleaseStringUTFChars(env, name, name_utf);
  95.242 +
  95.243 +    close(sock);
  95.244 +    return ret;
  95.245 +}
  95.246 +
  95.247 +/*** Private methods definitions ****/
  95.248 +
  95.249 +static int getFlags0(JNIEnv *env, jstring name) {
  95.250 +    jboolean isCopy;
  95.251 +    int ret, sock;
  95.252 +    const char* name_utf;
  95.253 +
  95.254 +    name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
  95.255 +
  95.256 +    if ((sock = openSocketWithFallback(env, name_utf)) < 0) {
  95.257 +        (*env)->ReleaseStringUTFChars(env, name, name_utf);
  95.258 +         return -1;
  95.259 +    }
  95.260 +
  95.261 +    name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
  95.262 +
  95.263 +    ret = getFlags(env, sock, name_utf);
  95.264 +
  95.265 +    close(sock);
  95.266 +    (*env)->ReleaseStringUTFChars(env, name, name_utf);
  95.267 +
  95.268 +    if (ret < 0) {
  95.269 +        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL  SIOCGLIFFLAGS failed");
  95.270 +        return -1;
  95.271 +    }
  95.272 +
  95.273 +    return ret;
  95.274 +}
  95.275 +
  95.276 +
  95.277 +
  95.278 +
  95.279  /*
  95.280   * Create a NetworkInterface object, populate the name and index, and
  95.281   * populate the InetAddress array based on the IP addresses for this
  95.282   * interface.
  95.283   */
  95.284 -jobject createNetworkInterface(JNIEnv *env, netif *ifs)
  95.285 -{
  95.286 +jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
  95.287      jobject netifObj;
  95.288      jobject name;
  95.289      jobjectArray addrArr;
  95.290      jobjectArray bindArr;
  95.291      jobjectArray childArr;
  95.292 +    netaddr *addrs;
  95.293      jint addr_index, addr_count, bind_index;
  95.294      jint child_count, child_index;
  95.295      netaddr *addrP;
  95.296 @@ -441,7 +617,7 @@
  95.297  
  95.298      bindArr = (*env)->NewObjectArray(env, addr_count, ni_ibcls, NULL);
  95.299      if (bindArr == NULL) {
  95.300 -      return NULL;
  95.301 +       return NULL;
  95.302      }
  95.303      addrP = ifs->addr;
  95.304      addr_index = 0;
  95.305 @@ -453,23 +629,22 @@
  95.306          if (addrP->family == AF_INET) {
  95.307              iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
  95.308              if (iaObj) {
  95.309 -                 (*env)->SetIntField(env, iaObj, ni_iaaddressID,
  95.310 -                     htonl(((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr));
  95.311 +                 (*env)->SetIntField(env, iaObj, ni_iaaddressID, htonl(((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr));
  95.312              }
  95.313              ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
  95.314              if (ibObj) {
  95.315 -              (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
  95.316 -              if (addrP->brdcast) {
  95.317 -                jobject ia2Obj = NULL;
  95.318 -                ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
  95.319 -                if (ia2Obj) {
  95.320 -                  (*env)->SetIntField(env, ia2Obj, ni_iaaddressID,
  95.321 -                                      htonl(((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr));
  95.322 -                  (*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj);
  95.323 -                  (*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask);
  95.324 -                }
  95.325 -              }
  95.326 -              (*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj);
  95.327 +                 (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
  95.328 +                 if (addrP->brdcast) {
  95.329 +                    jobject ia2Obj = NULL;
  95.330 +                    ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
  95.331 +                    if (ia2Obj) {
  95.332 +                       (*env)->SetIntField(env, ia2Obj, ni_iaaddressID,
  95.333 +                                                               htonl(((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr));
  95.334 +                       (*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj);
  95.335 +                       (*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask);
  95.336 +                    }
  95.337 +                 }
  95.338 +                 (*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj);
  95.339              }
  95.340          }
  95.341  
  95.342 @@ -483,14 +658,10 @@
  95.343                      return NULL;
  95.344                  }
  95.345                  (*env)->SetByteArrayRegion(env, ipaddress, 0, 16,
  95.346 -                    (jbyte *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr));
  95.347 -#ifdef __linux__
  95.348 -                if (!kernelIsV22()) {
  95.349 -                    scope = ((struct sockaddr_in6*)addrP->addr)->sin6_scope_id;
  95.350 -                }
  95.351 -#else
  95.352 +                                                                        (jbyte *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr));
  95.353 +
  95.354                  scope = ((struct sockaddr_in6*)addrP->addr)->sin6_scope_id;
  95.355 -#endif
  95.356 +
  95.357                  if (scope != 0) { /* zero is default value, no need to set */
  95.358                      (*env)->SetIntField(env, iaObj, ia6_scopeidID, scope);
  95.359                      (*env)->SetBooleanField(env, iaObj, ia6_scopeidsetID, JNI_TRUE);
  95.360 @@ -500,9 +671,9 @@
  95.361              }
  95.362              ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
  95.363              if (ibObj) {
  95.364 -              (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
  95.365 -              (*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask);
  95.366 -              (*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj);
  95.367 +                (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
  95.368 +                (*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask);
  95.369 +                (*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj);
  95.370              }
  95.371          }
  95.372  #endif
  95.373 @@ -521,13 +692,13 @@
  95.374      child_count = 0;
  95.375      childP = ifs->childs;
  95.376      while (childP) {
  95.377 -      child_count++;
  95.378 -      childP = childP->next;
  95.379 +        child_count++;
  95.380 +        childP = childP->next;
  95.381      }
  95.382  
  95.383      childArr = (*env)->NewObjectArray(env, child_count, ni_class, NULL);
  95.384      if (childArr == NULL) {
  95.385 -      return NULL;
  95.386 +        return NULL;
  95.387      }
  95.388  
  95.389      /*
  95.390 @@ -539,7 +710,7 @@
  95.391      while(childP) {
  95.392        tmp = createNetworkInterface(env, childP);
  95.393        if (tmp == NULL) {
  95.394 -        return NULL;
  95.395 +         return NULL;
  95.396        }
  95.397        (*env)->SetObjectField(env, tmp, ni_parentID, netifObj);
  95.398        (*env)->SetObjectArrayElement(env, childArr, child_index++, tmp);
  95.399 @@ -558,294 +729,56 @@
  95.400   */
  95.401  static netif *enumInterfaces(JNIEnv *env) {
  95.402      netif *ifs;
  95.403 +    int sock;
  95.404  
  95.405      /*
  95.406       * Enumerate IPv4 addresses
  95.407       */
  95.408 -    ifs = enumIPv4Interfaces(env, NULL);
  95.409 -    if (ifs == NULL) {
  95.410 -        if ((*env)->ExceptionOccurred(env)) {
  95.411 -            return NULL;
  95.412 -        }
  95.413 +
  95.414 +    sock = openSocket(env, AF_INET);
  95.415 +    if (sock < 0 && (*env)->ExceptionOccurred(env)) {
  95.416 +        return NULL;
  95.417      }
  95.418  
  95.419 +    ifs = enumIPv4Interfaces(env, sock, NULL);
  95.420 +    close(sock);
  95.421 +
  95.422 +    if (ifs == NULL && (*env)->ExceptionOccurred(env)) {
  95.423 +        return NULL;
  95.424 +    }
  95.425 +
  95.426 +    /* return partial list if exception occure in the middle of process ???*/
  95.427 +
  95.428      /*
  95.429       * If IPv6 is available then enumerate IPv6 addresses.
  95.430       */
  95.431  #ifdef AF_INET6
  95.432 -    if (ipv6_available()) {
  95.433 -        ifs = enumIPv6Interfaces(env, ifs);
  95.434 +        sock =  openSocket(env, AF_INET6);
  95.435 +        if (sock < 0 && (*env)->ExceptionOccurred(env)) {
  95.436 +            freeif(ifs);
  95.437 +            return NULL;
  95.438 +        }
  95.439 +
  95.440 +        ifs = enumIPv6Interfaces(env, sock, ifs);
  95.441 +        close(sock);
  95.442  
  95.443          if ((*env)->ExceptionOccurred(env)) {
  95.444              freeif(ifs);
  95.445              return NULL;
  95.446          }
  95.447 -    }
  95.448  #endif
  95.449  
  95.450      return ifs;
  95.451  }
  95.452  
  95.453 -
  95.454 -/*
  95.455 - * Enumerates and returns all IPv4 interfaces
  95.456 - */
  95.457 -static netif *enumIPv4Interfaces(JNIEnv *env, netif *ifs) {
  95.458 -    int sock;
  95.459 -    struct ifconf ifc;
  95.460 -    struct ifreq *ifreqP;
  95.461 -    char *buf;
  95.462 -    int numifs;
  95.463 -    unsigned i;
  95.464 -    unsigned bufsize;
  95.465 -
  95.466 -    sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0);
  95.467 -    if (sock < 0) {
  95.468 -        /*
  95.469 -         * If EPROTONOSUPPORT is returned it means we don't have
  95.470 -         * IPv4 support so don't throw an exception.
  95.471 -         */
  95.472 -        if (errno != EPROTONOSUPPORT) {
  95.473 -            NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
  95.474 -                             "Socket creation failed");
  95.475 -        }
  95.476 -        return ifs;
  95.477 -    }
  95.478 -
  95.479 -#ifdef __linux__
  95.480 -    /* need to do a dummy SIOCGIFCONF to determine the buffer size.
  95.481 -     * SIOCGIFCOUNT doesn't work
  95.482 -     */
  95.483 -    ifc.ifc_buf = NULL;
  95.484 -    if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
  95.485 -        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
  95.486 -                         "ioctl SIOCGIFCONF failed");
  95.487 -        close(sock);
  95.488 -        return ifs;
  95.489 -    }
  95.490 -    bufsize = ifc.ifc_len;
  95.491 -#else
  95.492 -    if (ioctl(sock, SIOCGIFNUM, (char *)&numifs) < 0) {
  95.493 -        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
  95.494 -                         "ioctl SIOCGIFNUM failed");
  95.495 -        close(sock);
  95.496 -        return ifs;
  95.497 -    }
  95.498 -    bufsize = numifs * sizeof (struct ifreq);
  95.499 -#endif /* __linux__ */
  95.500 -
  95.501 -    buf = (char *)malloc(bufsize);
  95.502 -    if (!buf) {
  95.503 -        JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
  95.504 -        (void) close(sock);
  95.505 -        return ifs;
  95.506 -    }
  95.507 -    ifc.ifc_len = bufsize;
  95.508 -    ifc.ifc_buf = buf;
  95.509 -    if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
  95.510 -        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
  95.511 -                         "ioctl SIOCGIFCONF failed");
  95.512 -        (void) close(sock);
  95.513 -        (void) free(buf);
  95.514 -        return ifs;
  95.515 -    }
  95.516 -
  95.517 -    /*
  95.518 -     * Iterate through each interface
  95.519 -     */
  95.520 -    ifreqP = ifc.ifc_req;
  95.521 -    for (i=0; i<ifc.ifc_len/sizeof (struct ifreq); i++, ifreqP++) {
  95.522 -        int index;
  95.523 -        struct ifreq if2;
  95.524 -
  95.525 -        memset((char *)&if2, 0, sizeof(if2));
  95.526 -        strcpy(if2.ifr_name, ifreqP->ifr_name);
  95.527 -
  95.528 -        /*
  95.529 -         * Try to get the interface index
  95.530 -         * (Not supported on Solaris 2.6 or 7)
  95.531 -         */
  95.532 -        if (ioctl(sock, SIOCGIFINDEX, (char *)&if2) >= 0) {
  95.533 -            index = if2.ifr_index;
  95.534 -        } else {
  95.535 -            index = -1;
  95.536 -        }
  95.537 -
  95.538 -        /*
  95.539 -         * Add to the list
  95.540 -         */
  95.541 -        ifs = addif(env, ifs, ifreqP->ifr_name, index, AF_INET,
  95.542 -                    (struct sockaddr *)&(ifreqP->ifr_addr),
  95.543 -                    sizeof(struct sockaddr_in), 0);
  95.544 -
  95.545 -        /*
  95.546 -         * If an exception occurred then free the list
  95.547 -         */
  95.548 -        if ((*env)->ExceptionOccurred(env)) {
  95.549 -            close(sock);
  95.550 -            free(buf);
  95.551 -            freeif(ifs);
  95.552 -            return NULL;
  95.553 -        }
  95.554 -    }
  95.555 -
  95.556 -    /*
  95.557 -     * Free socket and buffer
  95.558 -     */
  95.559 -    close(sock);
  95.560 -    free(buf);
  95.561 -    return ifs;
  95.562 -}
  95.563 -
  95.564 -
  95.565 -#if defined(__solaris__) && defined(AF_INET6)
  95.566 -/*
  95.567 - * Enumerates and returns all IPv6 interfaces on Solaris
  95.568 - */
  95.569 -static netif *enumIPv6Interfaces(JNIEnv *env, netif *ifs) {
  95.570 -    int sock;
  95.571 -    struct lifconf ifc;
  95.572 -    struct lifreq *ifr;
  95.573 -    int n;
  95.574 -    char *buf;
  95.575 -    struct lifnum numifs;
  95.576 -    unsigned bufsize;
  95.577 -
  95.578 -    sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0);
  95.579 -    if (sock < 0) {
  95.580 -        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
  95.581 -                         "Failed to create IPv6 socket");
  95.582 -        return ifs;
  95.583 -    }
  95.584 -
  95.585 -    /*
  95.586 -     * Get the interface count
  95.587 -     */
  95.588 -    numifs.lifn_family = AF_UNSPEC;
  95.589 -    numifs.lifn_flags = 0;
  95.590 -    if (ioctl(sock, SIOCGLIFNUM, (char *)&numifs) < 0) {
  95.591 -        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
  95.592 -                         "ioctl SIOCGLIFNUM failed");
  95.593 -        close(sock);
  95.594 -        return ifs;
  95.595 -    }
  95.596 -
  95.597 -    /*
  95.598 -     *  Enumerate the interface configurations
  95.599 -     */
  95.600 -    bufsize = numifs.lifn_count * sizeof (struct lifreq);
  95.601 -    buf = (char *)malloc(bufsize);
  95.602 -    if (!buf) {
  95.603 -        JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
  95.604 -        (void) close(sock);
  95.605 -        return ifs;
  95.606 -    }
  95.607 -    ifc.lifc_family = AF_UNSPEC;
  95.608 -    ifc.lifc_flags = 0;
  95.609 -    ifc.lifc_len = bufsize;
  95.610 -    ifc.lifc_buf = buf;
  95.611 -    if (ioctl(sock, SIOCGLIFCONF, (char *)&ifc) < 0) {
  95.612 -        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
  95.613 -                         "ioctl SIOCGLIFCONF failed");
  95.614 -        close(sock);
  95.615 -        free(buf);
  95.616 -        return ifs;
  95.617 -    }
  95.618 -
  95.619 -    /*
  95.620 -     * Iterate through each interface
  95.621 -     */
  95.622 -    ifr = ifc.lifc_req;
  95.623 -    for (n=0; n<numifs.lifn_count; n++, ifr++) {
  95.624 -        int index = -1;
  95.625 -        struct lifreq if2;
  95.626 -
  95.627 -        /*
  95.628 -         * Ignore non-IPv6 addresses
  95.629 -         */
  95.630 -        if (ifr->lifr_addr.ss_family != AF_INET6) {
  95.631 -            continue;
  95.632 -        }
  95.633 -
  95.634 -        /*
  95.635 -         * Get the index
  95.636 -         */
  95.637 -        memset((char *)&if2, 0, sizeof(if2));
  95.638 -        strcpy(if2.lifr_name, ifr->lifr_name);
  95.639 -        if (ioctl(sock, SIOCGLIFINDEX, (char *)&if2) >= 0) {
  95.640 -            struct sockaddr_in6 *s6= (struct sockaddr_in6 *)&(ifr->lifr_addr);
  95.641 -            index = if2.lifr_index;
  95.642 -            s6->sin6_scope_id = index;
  95.643 -        }
  95.644 -
  95.645 -        /* add to the list */
  95.646 -        ifs = addif(env, ifs, ifr->lifr_name, index, AF_INET6,
  95.647 -                    (struct sockaddr *)&(ifr->lifr_addr),
  95.648 -                    sizeof(struct sockaddr_in6), (short) ifr->lifr_addrlen);
  95.649 -
  95.650 -        /*
  95.651 -         * If an exception occurred we return
  95.652 -         */
  95.653 -        if ((*env)->ExceptionOccurred(env)) {
  95.654 -            close(sock);
  95.655 -            free(buf);
  95.656 -            return ifs;
  95.657 -        }
  95.658 -
  95.659 -    }
  95.660 -
  95.661 -    close(sock);
  95.662 -    free(buf);
  95.663 -    return ifs;
  95.664 -
  95.665 -}
  95.666 -#endif
  95.667 -
  95.668 -
  95.669 -#if defined(__linux__) && defined(AF_INET6)
  95.670 -/*
  95.671 - * Enumerates and returns all IPv6 interfaces on Linux
  95.672 - */
  95.673 -static netif *enumIPv6Interfaces(JNIEnv *env, netif *ifs) {
  95.674 -    FILE *f;
  95.675 -    char addr6[40], devname[20];
  95.676 -    char addr6p[8][5];
  95.677 -    int plen, scope, dad_status, if_idx;
  95.678 -    uint8_t ipv6addr[16];
  95.679 -
  95.680 -    if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) {
  95.681 -        while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
  95.682 -                      addr6p[0], addr6p[1], addr6p[2], addr6p[3],
  95.683 -                      addr6p[4], addr6p[5], addr6p[6], addr6p[7],
  95.684 -                  &if_idx, &plen, &scope, &dad_status, devname) != EOF) {
  95.685 -            struct sockaddr_in6 addr;
  95.686 -
  95.687 -            sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s",
  95.688 -                    addr6p[0], addr6p[1], addr6p[2], addr6p[3],
  95.689 -                    addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
  95.690 -            inet_pton(AF_INET6, addr6, ipv6addr);
  95.691 -
  95.692 -            memset(&addr, 0, sizeof(struct sockaddr_in6));
  95.693 -            memcpy((void*)addr.sin6_addr.s6_addr, (const void*)ipv6addr, 16);
  95.694 -            addr.sin6_scope_id = if_idx;
  95.695 -
  95.696 -            ifs = addif(env, ifs, devname, if_idx, AF_INET6,
  95.697 -                        (struct sockaddr *)&addr,
  95.698 -                        sizeof(struct sockaddr_in6), plen);
  95.699 -
  95.700 -            /*
  95.701 -             * If an exception occurred then return the list as is.
  95.702 -             */
  95.703 -            if ((*env)->ExceptionOccurred(env)) {
  95.704 -                fclose(f);
  95.705 -                return ifs;
  95.706 -            }
  95.707 -        }
  95.708 -        fclose(f);
  95.709 -    }
  95.710 -    return ifs;
  95.711 -}
  95.712 -#endif
  95.713 +#define CHECKED_MALLOC3(_pointer,_type,_size) \
  95.714 +       do{ \
  95.715 +        _pointer = (_type)malloc( _size ); \
  95.716 +        if (_pointer == NULL) { \
  95.717 +            JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); \
  95.718 +            return ifs; /* return untouched list */ \
  95.719 +        } \
  95.720 +       } while(0)
  95.721  
  95.722  
  95.723  /*
  95.724 @@ -853,52 +786,43 @@
  95.725   */
  95.726  void freeif(netif *ifs) {
  95.727      netif *currif = ifs;
  95.728 +    netif *child = NULL;
  95.729  
  95.730      while (currif != NULL) {
  95.731          netaddr *addrP = currif->addr;
  95.732          while (addrP != NULL) {
  95.733              netaddr *next = addrP->next;
  95.734 -            if (addrP->addr != NULL)
  95.735 -                free(addrP->addr);
  95.736 -            if (addrP->brdcast != NULL)
  95.737 -                free(addrP->brdcast);
  95.738              free(addrP);
  95.739              addrP = next;
  95.740 -        }
  95.741 +         }
  95.742  
  95.743 -        free(currif->name);
  95.744 +            /*
  95.745 +            * Don't forget to free the sub-interfaces.
  95.746 +            */
  95.747 +          if (currif->childs != NULL) {
  95.748 +                freeif(currif->childs);
  95.749 +          }
  95.750  
  95.751 -        /*
  95.752 -         * Don't forget to free the sub-interfaces.
  95.753 -         */
  95.754 -        if (currif->childs != NULL) {
  95.755 -          freeif(currif->childs);
  95.756 -        }
  95.757 -
  95.758 -        ifs = currif->next;
  95.759 -        free(currif);
  95.760 -        currif = ifs;
  95.761 +          ifs = currif->next;
  95.762 +          free(currif);
  95.763 +          currif = ifs;
  95.764      }
  95.765  }
  95.766  
  95.767 -/*
  95.768 - * Add an interface to the list. If known interface just link
  95.769 - * a new netaddr onto the list. If new interface create new
  95.770 - * netif structure.
  95.771 - */
  95.772 -netif *addif(JNIEnv *env, netif *ifs, char *if_name, int index, int family,
  95.773 -             struct sockaddr *new_addrP, int new_addrlen, short prefix) {
  95.774 -  netif *currif = ifs, *parent;
  95.775 +netif *addif(JNIEnv *env, int sock, const char * if_name, netif *ifs, struct sockaddr* ifr_addrP, int family, short prefix) {
  95.776 +    netif *currif = ifs, *parent;
  95.777      netaddr *addrP;
  95.778 -#ifdef LIFNAMSIZ
  95.779 -    char name[LIFNAMSIZ];
  95.780 -    char vname[LIFNAMSIZ];
  95.781 -#else
  95.782 -    char name[IFNAMSIZ];
  95.783 -    char vname[IFNAMSIZ];
  95.784 -#endif
  95.785 -    char *unit;
  95.786 +
  95.787 +    #ifdef __solaris__
  95.788 +    char name[LIFNAMSIZ],  vname[LIFNAMSIZ];
  95.789 +    #else
  95.790 +    char name[IFNAMSIZ],  vname[IFNAMSIZ];
  95.791 +    #endif
  95.792 +
  95.793 +    char  *name_colonP;
  95.794 +    int mask;
  95.795      int isVirtual = 0;
  95.796 +    int addr_size;
  95.797  
  95.798      /*
  95.799       * If the interface name is a logical interface then we
  95.800 @@ -908,107 +832,63 @@
  95.801       * logical interfaces.
  95.802       */
  95.803      strcpy(name, if_name);
  95.804 +    *vname = 0;
  95.805  
  95.806      /*
  95.807       * Create and populate the netaddr node. If allocation fails
  95.808       * return an un-updated list.
  95.809       */
  95.810 -    addrP = (netaddr *)malloc(sizeof(netaddr));
  95.811 -    if (addrP) {
  95.812 -        addrP->addr = (struct sockaddr *)malloc(new_addrlen);
  95.813 -        if (addrP->addr == NULL) {
  95.814 -            free(addrP);
  95.815 -            addrP = NULL;
  95.816 -        }
  95.817 -    }
  95.818 -    if (addrP == NULL) {
  95.819 -        JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
  95.820 -        return ifs; /* return untouched list */
  95.821 -    }
  95.822 -    memcpy(addrP->addr, new_addrP, new_addrlen);
  95.823 +    /*Allocate for addr and brdcast at once*/
  95.824 +
  95.825 +#ifdef AF_INET6
  95.826 +    addr_size = (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);
  95.827 +#else
  95.828 +    addr_size = sizeof(struct sockaddr_in);
  95.829 +#endif
  95.830 +
  95.831 +    CHECKED_MALLOC3(addrP, netaddr *, sizeof(netaddr)+2*addr_size);
  95.832 +    addrP->addr = (struct sockaddr *)( (char *) addrP+sizeof(netaddr) );
  95.833 +    memcpy(addrP->addr, ifr_addrP, addr_size);
  95.834 +
  95.835      addrP->family = family;
  95.836 -
  95.837      addrP->brdcast = NULL;
  95.838      addrP->mask = prefix;
  95.839 +    addrP->next = 0;
  95.840      if (family == AF_INET) {
  95.841        /*
  95.842         * Deal with brodcast addr & subnet mask
  95.843         */
  95.844 -      addrP->brdcast = getBroadcast(env, name);
  95.845 -      if (addrP->brdcast) {
  95.846 -        addrP->mask = getSubnet(env, name);
  95.847 -      }
  95.848 -    }
  95.849 +       struct sockaddr * brdcast_to = (struct sockaddr *) ((char *) addrP + sizeof(netaddr) + addr_size);
  95.850 +       addrP->brdcast = getBroadcast(env, sock, name,  brdcast_to );
  95.851  
  95.852 -    vname[0] = 0;
  95.853 -    unit = strchr(name, ':');
  95.854 -    if (unit != NULL) {
  95.855 +       if (addrP->brdcast && (mask = getSubnet(env, sock, name)) != -1) {
  95.856 +           addrP->mask = mask;
  95.857 +       }
  95.858 +     }
  95.859 +
  95.860 +    /**
  95.861 +     * Deal with virtual interface with colon notaion e.g. eth0:1
  95.862 +     */
  95.863 +    name_colonP = strchr(name, ':');
  95.864 +    if (name_colonP != NULL) {
  95.865        /**
  95.866         * This is a virtual interface. If we are able to access the parent
  95.867         * we need to create a new entry if it doesn't exist yet *and* update
  95.868         * the 'parent' interface with the new records.
  95.869         */
  95.870 -      struct ifreq if2;
  95.871 -      int sock;
  95.872 -      int len;
  95.873 -
  95.874 -      sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0);
  95.875 -      if (sock < 0) {
  95.876 -        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
  95.877 -                                     "Socket creation failed");
  95.878 -        return ifs; /* return untouched list */
  95.879 -      }
  95.880 -
  95.881 -      len = unit - name;
  95.882 -      if (len > 0) {
  95.883 -        // temporarily use vname to hold the parent name of the interface
  95.884 -        // instead of creating another buffer.
  95.885 -        memcpy(&vname, name, len);
  95.886 -        vname[len] = '\0';
  95.887 -
  95.888 -        memset((char *) &if2, 0, sizeof(if2));
  95.889 -        strcpy(if2.ifr_name, vname);
  95.890 -
  95.891 -        if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) >= 0) {
  95.892 -           // Got access to parent, so create it if necessary.
  95.893 -           strcpy(vname, name);
  95.894 -           *unit = '\0';
  95.895 -        } else {
  95.896 -#if defined(__solaris__) && defined(AF_INET6)
  95.897 -          struct   lifreq lifr;
  95.898 -          memset((char *) &lifr, 0, sizeof(lifr));
  95.899 -          strcpy(lifr.lifr_name, vname);
  95.900 -
  95.901 -          /* Try with an IPv6 socket in case the interface has only IPv6
  95.902 -           * addresses assigned to it */
  95.903 -          close(sock);
  95.904 -          sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0);
  95.905 -
  95.906 -          if (sock < 0) {
  95.907 -            NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
  95.908 -                                         "Socket creation failed");
  95.909 -            return ifs; /* return untouched list */
  95.910 -          }
  95.911 -
  95.912 -          if (ioctl(sock, SIOCGLIFFLAGS, (char *)&lifr) >= 0) {
  95.913 -            // Got access to parent, so create it if necessary.
  95.914 -            strcpy(vname, name);
  95.915 -            *unit = '\0';
  95.916 -          } else {
  95.917 +        *name_colonP = 0;
  95.918 +        if (getFlags(env,sock,name) < 0) {
  95.919              // failed to access parent interface do not create parent.
  95.920              // We are a virtual interface with no parent.
  95.921              isVirtual = 1;
  95.922 -            vname[0] = 0;
  95.923 -          }
  95.924 -#else
  95.925 -          // failed to access parent interface do not create parent.
  95.926 -          // We are a virtual interface with no parent.
  95.927 -          isVirtual = 1;
  95.928 -          vname[0] = 0;
  95.929 -#endif
  95.930 +            *name_colonP = ':';
  95.931          }
  95.932 -      }
  95.933 -      close(sock);
  95.934 +        else{
  95.935 +           // Got access to parent, so create it if necessary.
  95.936 +           // Save original name to vname and truncate name by ':'
  95.937 +            memcpy(vname, name, sizeof(vname) );
  95.938 +            vname[name_colonP - name] = ':';
  95.939 +        }
  95.940      }
  95.941  
  95.942      /*
  95.943 @@ -1028,24 +908,15 @@
  95.944       * insert it onto the list.
  95.945       */
  95.946      if (currif == NULL) {
  95.947 -        currif = (netif *)malloc(sizeof(netif));
  95.948 -        if (currif) {
  95.949 -            currif->name = strdup(name);
  95.950 -            if (currif->name == NULL) {
  95.951 -                free(currif);
  95.952 -                currif = NULL;
  95.953 -            }
  95.954 -        }
  95.955 -        if (currif == NULL) {
  95.956 -            JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
  95.957 -            return ifs;
  95.958 -        }
  95.959 -        currif->index = index;
  95.960 -        currif->addr = NULL;
  95.961 -        currif->childs = NULL;
  95.962 -        currif->virtual = isVirtual;
  95.963 -        currif->next = ifs;
  95.964 -        ifs = currif;
  95.965 +         CHECKED_MALLOC3(currif, netif *, sizeof(netif)+IFNAMSIZ );
  95.966 +         currif->name = (char *) currif+sizeof(netif);
  95.967 +         strcpy(currif->name, name);
  95.968 +         currif->index = getIndex(sock, name);
  95.969 +         currif->addr = NULL;
  95.970 +         currif->childs = NULL;
  95.971 +         currif->virtual = isVirtual;
  95.972 +         currif->next = ifs;
  95.973 +         ifs = currif;
  95.974      }
  95.975  
  95.976      /*
  95.977 @@ -1060,161 +931,251 @@
  95.978       * Let's deal with the virtual interface now.
  95.979       */
  95.980      if (vname[0]) {
  95.981 -      netaddr *tmpaddr;
  95.982 +        netaddr *tmpaddr;
  95.983  
  95.984 -      currif = parent->childs;
  95.985 +        currif = parent->childs;
  95.986  
  95.987 -      while (currif != NULL) {
  95.988 -        if (strcmp(vname, currif->name) == 0) {
  95.989 -          break;
  95.990 +        while (currif != NULL) {
  95.991 +            if (strcmp(vname, currif->name) == 0) {
  95.992 +                break;
  95.993 +            }
  95.994 +            currif = currif->next;
  95.995          }
  95.996 -        currif = currif->next;
  95.997 -      }
  95.998 -      if (currif == NULL) {
  95.999 -        currif = (netif *)malloc(sizeof(netif));
 95.1000 -        if (currif) {
 95.1001 -          currif->name = strdup(vname);
 95.1002 -          if (currif->name == NULL) {
 95.1003 -            free(currif);
 95.1004 -            currif = NULL;
 95.1005 -          }
 95.1006 +
 95.1007 +        if (currif == NULL) {
 95.1008 +            CHECKED_MALLOC3(currif, netif *, sizeof(netif)+ IFNAMSIZ );
 95.1009 +            currif->name = (char *) currif + sizeof(netif);
 95.1010 +            strcpy(currif->name, vname);
 95.1011 +            currif->index = getIndex(sock, vname);
 95.1012 +            currif->addr = NULL;
 95.1013 +           /* Need to duplicate the addr entry? */
 95.1014 +            currif->virtual = 1;
 95.1015 +            currif->childs = NULL;
 95.1016 +            currif->next = parent->childs;
 95.1017 +            parent->childs = currif;
 95.1018          }
 95.1019 -        if (currif == NULL) {
 95.1020 -          JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
 95.1021 -          return ifs;
 95.1022 +
 95.1023 +        CHECKED_MALLOC3(tmpaddr, netaddr *, sizeof(netaddr)+2*addr_size);
 95.1024 +        memcpy(tmpaddr, addrP, sizeof(netaddr));
 95.1025 +        if (addrP->addr != NULL) {
 95.1026 +            tmpaddr->addr = (struct sockaddr *) ( (char*)tmpaddr + sizeof(netaddr) ) ;
 95.1027 +            memcpy(tmpaddr->addr, addrP->addr, addr_size);
 95.1028          }
 95.1029 -        currif->index = index;
 95.1030 -        currif->addr = NULL;
 95.1031 -        /* Need to duplicate the addr entry? */
 95.1032 -        currif->virtual = 1;
 95.1033 -        currif->childs = NULL;
 95.1034 -        currif->next = parent->childs;
 95.1035 -        parent->childs = currif;
 95.1036 -      }
 95.1037  
 95.1038 -      tmpaddr = (netaddr *) malloc(sizeof(netaddr));
 95.1039 -      if (tmpaddr == NULL) {
 95.1040 -        JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
 95.1041 -        return ifs;
 95.1042 -      }
 95.1043 -      memcpy(tmpaddr, addrP, sizeof(netaddr));
 95.1044 -      /**
 95.1045 -       * Let's duplicate the address and broadcast address structures
 95.1046 -       * if there are any.
 95.1047 -       */
 95.1048 -      if (addrP->addr != NULL) {
 95.1049 -        tmpaddr->addr = malloc(new_addrlen);
 95.1050 -        if (tmpaddr->addr != NULL)
 95.1051 -          memcpy(tmpaddr->addr, addrP->addr, new_addrlen);
 95.1052 -      }
 95.1053 -      if (addrP->brdcast != NULL) {
 95.1054 -        tmpaddr->brdcast = malloc(new_addrlen);
 95.1055 -        if (tmpaddr->brdcast != NULL)
 95.1056 -          memcpy(tmpaddr->brdcast, addrP->brdcast, new_addrlen);
 95.1057 -      }
 95.1058 -      tmpaddr->next = currif->addr;
 95.1059 -      currif->addr = tmpaddr;
 95.1060 +        if (addrP->brdcast != NULL) {
 95.1061 +            tmpaddr->brdcast = (struct sockaddr *) ((char *) tmpaddr + sizeof(netaddr)+addr_size);
 95.1062 +            memcpy(tmpaddr->brdcast, addrP->brdcast, addr_size);
 95.1063 +        }
 95.1064 +
 95.1065 +        tmpaddr->next = currif->addr;
 95.1066 +        currif->addr = tmpaddr;
 95.1067      }
 95.1068  
 95.1069      return ifs;
 95.1070  }
 95.1071  
 95.1072 -/**
 95.1073 - * Get flags from a NetworkInterface.
 95.1074 +/* Open socket for further ioct calls
 95.1075 + * proto is AF_INET/AF_INET6
 95.1076   */
 95.1077 -static short getFlags(JNIEnv *env, jstring name) {
 95.1078 -  int sock;
 95.1079 -  struct ifreq if2;
 95.1080 -  jboolean isCopy;
 95.1081 -  const char* name_utf;
 95.1082 -  short ret = -1;
 95.1083 +static int  openSocket(JNIEnv *env, int proto){
 95.1084 +    int sock;
 95.1085  
 95.1086 -  sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0);
 95.1087 -  if (sock < 0) {
 95.1088 -    NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1089 -                                 "Socket creation failed");
 95.1090 -    return -1;
 95.1091 -  }
 95.1092 -
 95.1093 -  name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
 95.1094 -  memset((char *) &if2, 0, sizeof(if2));
 95.1095 -  strcpy(if2.ifr_name, name_utf);
 95.1096 -
 95.1097 -  if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) >= 0) {
 95.1098 -    ret = if2.ifr_flags;
 95.1099 -  } else {
 95.1100 -#if defined(__solaris__) && defined(AF_INET6)
 95.1101 -    /* Try with an IPv6 socket in case the interface has only IPv6 addresses assigned to it */
 95.1102 -    struct lifreq lifr;
 95.1103 -
 95.1104 -    close(sock);
 95.1105 -    sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0);
 95.1106 -
 95.1107 -    if (sock < 0) {
 95.1108 -      (*env)->ReleaseStringUTFChars(env, name, name_utf);
 95.1109 -      NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1110 -                                  "Socket creation failed");
 95.1111 -      return -1;
 95.1112 +    if ((sock = JVM_Socket(proto, SOCK_DGRAM, 0)) < 0) {
 95.1113 +        /*
 95.1114 +         * If EPROTONOSUPPORT is returned it means we don't have
 95.1115 +         * support  for this proto so don't throw an exception.
 95.1116 +         */
 95.1117 +        if (errno != EPROTONOSUPPORT) {
 95.1118 +            NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "Socket creation failed");
 95.1119 +        }
 95.1120 +        return -1;
 95.1121      }
 95.1122  
 95.1123 -    memset((caddr_t)&lifr, 0, sizeof(lifr));
 95.1124 -    strcpy((caddr_t)&(lifr.lifr_name), name_utf);
 95.1125 +    return sock;
 95.1126 +}
 95.1127  
 95.1128 -    if (ioctl(sock, SIOCGLIFFLAGS, (char *)&lifr) >= 0) {
 95.1129 -      ret = lifr.lifr_flags;
 95.1130 -    } else {
 95.1131 -      NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1132 -                               "IOCTL failed");
 95.1133 +
 95.1134 +/** Linux **/
 95.1135 +#ifdef __linux__
 95.1136 +/* Open socket for further ioct calls, try v4 socket first and
 95.1137 + * if it falls return v6 socket
 95.1138 + */
 95.1139 +
 95.1140 +#ifdef AF_INET6
 95.1141 +static int openSocketWithFallback(JNIEnv *env, const char *ifname){
 95.1142 +    int sock;
 95.1143 +    struct ifreq if2;
 95.1144 +
 95.1145 +     if ((sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
 95.1146 +         if (errno == EPROTONOSUPPORT){
 95.1147 +              if ( (sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0)) < 0 ){
 95.1148 +                 NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed");
 95.1149 +                 return -1;
 95.1150 +              }
 95.1151 +         }
 95.1152 +         else{ // errno is not NOSUPPORT
 95.1153 +             NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV4 Socket creation failed");
 95.1154 +             return -1;
 95.1155 +         }
 95.1156 +   }
 95.1157 +
 95.1158 +     /* Linux starting from 2.6.? kernel allows ioctl call with either IPv4 or IPv6 socket regardless of type
 95.1159 +        of address of an interface */
 95.1160 +
 95.1161 +       return sock;
 95.1162 +}
 95.1163 +
 95.1164 +#else
 95.1165 +static int openSocketWithFallback(JNIEnv *env, const char *ifname){
 95.1166 +    return openSocket(env,AF_INET);
 95.1167 +}
 95.1168 +#endif
 95.1169 +
 95.1170 +static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
 95.1171 +    struct ifconf ifc;
 95.1172 +    struct ifreq *ifreqP;
 95.1173 +    char *buf;
 95.1174 +    int numifs;
 95.1175 +    unsigned i;
 95.1176 +
 95.1177 +
 95.1178 +    /* need to do a dummy SIOCGIFCONF to determine the buffer size.
 95.1179 +     * SIOCGIFCOUNT doesn't work
 95.1180 +     */
 95.1181 +    ifc.ifc_buf = NULL;
 95.1182 +    if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
 95.1183 +        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "ioctl SIOCGIFCONF failed");
 95.1184 +        return ifs;
 95.1185      }
 95.1186 -#else
 95.1187 -    NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1188 -                                 "IOCTL failed");
 95.1189 +
 95.1190 +    CHECKED_MALLOC3(buf,char *, ifc.ifc_len);
 95.1191 +
 95.1192 +    ifc.ifc_buf = buf;
 95.1193 +    if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
 95.1194 +        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "ioctl SIOCGIFCONF failed");
 95.1195 +        (void) free(buf);
 95.1196 +        return ifs;
 95.1197 +    }
 95.1198 +
 95.1199 +    /*
 95.1200 +     * Iterate through each interface
 95.1201 +     */
 95.1202 +    ifreqP = ifc.ifc_req;
 95.1203 +    for (i=0; i<ifc.ifc_len/sizeof (struct ifreq); i++, ifreqP++) {
 95.1204 +        /*
 95.1205 +         * Add to the list
 95.1206 +         */
 95.1207 +        ifs = addif(env, sock, ifreqP->ifr_name, ifs, (struct sockaddr *) & (ifreqP->ifr_addr), AF_INET, 0);
 95.1208 +
 95.1209 +        /*
 95.1210 +         * If an exception occurred then free the list
 95.1211 +         */
 95.1212 +        if ((*env)->ExceptionOccurred(env)) {
 95.1213 +            free(buf);
 95.1214 +            freeif(ifs);
 95.1215 +            return NULL;
 95.1216 +        }
 95.1217 +    }
 95.1218 +
 95.1219 +    /*
 95.1220 +     * Free socket and buffer
 95.1221 +     */
 95.1222 +    free(buf);
 95.1223 +    return ifs;
 95.1224 +}
 95.1225 +
 95.1226 +
 95.1227 +/*
 95.1228 + * Enumerates and returns all IPv6 interfaces on Linux
 95.1229 + */
 95.1230 +
 95.1231 +#ifdef AF_INET6
 95.1232 +static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
 95.1233 +    FILE *f;
 95.1234 +    char addr6[40], devname[20];
 95.1235 +    char addr6p[8][5];
 95.1236 +    int plen, scope, dad_status, if_idx;
 95.1237 +    uint8_t ipv6addr[16];
 95.1238 +
 95.1239 +    if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) {
 95.1240 +        while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
 95.1241 +                         addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4], addr6p[5], addr6p[6], addr6p[7],
 95.1242 +                         &if_idx, &plen, &scope, &dad_status, devname) != EOF) {
 95.1243 +
 95.1244 +            struct netif *ifs_ptr = NULL;
 95.1245 +            struct netif *last_ptr = NULL;
 95.1246 +            struct sockaddr_in6 addr;
 95.1247 +
 95.1248 +            sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s",
 95.1249 +                           addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
 95.1250 +            inet_pton(AF_INET6, addr6, ipv6addr);
 95.1251 +
 95.1252 +            memset(&addr, 0, sizeof(struct sockaddr_in6));
 95.1253 +            memcpy((void*)addr.sin6_addr.s6_addr, (const void*)ipv6addr, 16);
 95.1254 +
 95.1255 +            addr.sin6_scope_id = if_idx;
 95.1256 +
 95.1257 +            ifs = addif(env, sock, devname, ifs, (struct sockaddr *)&addr, AF_INET6, plen);
 95.1258 +
 95.1259 +
 95.1260 +            /*
 95.1261 +             * If an exception occurred then return the list as is.
 95.1262 +             */
 95.1263 +            if ((*env)->ExceptionOccurred(env)) {
 95.1264 +                fclose(f);
 95.1265 +                return ifs;
 95.1266 +            }
 95.1267 +       }
 95.1268 +       fclose(f);
 95.1269 +    }
 95.1270 +    return ifs;
 95.1271 +}
 95.1272  #endif
 95.1273 -  }
 95.1274 -  close(sock);
 95.1275 -  /* release the UTF string and interface list */
 95.1276 -  (*env)->ReleaseStringUTFChars(env, name, name_utf);
 95.1277  
 95.1278 -  return ret;
 95.1279 +
 95.1280 +static int getIndex(int sock, const char *name){
 95.1281 +     /*
 95.1282 +      * Try to get the interface index
 95.1283 +      * (Not supported on Solaris 2.6 or 7)
 95.1284 +      */
 95.1285 +    struct ifreq if2;
 95.1286 +    strcpy(if2.ifr_name, name);
 95.1287 +
 95.1288 +    if (ioctl(sock, SIOCGIFINDEX, (char *)&if2) < 0) {
 95.1289 +        return -1;
 95.1290 +    }
 95.1291 +
 95.1292 +    return if2.ifr_ifindex;
 95.1293  }
 95.1294  
 95.1295  /**
 95.1296   * Returns the IPv4 broadcast address of a named interface, if it exists.
 95.1297   * Returns 0 if it doesn't have one.
 95.1298   */
 95.1299 -static struct sockaddr *getBroadcast(JNIEnv *env, const char *ifname) {
 95.1300 -  int sock;
 95.1301 +static struct sockaddr *getBroadcast(JNIEnv *env, int sock, const char *ifname, struct sockaddr *brdcast_store) {
 95.1302    struct sockaddr *ret = NULL;
 95.1303    struct ifreq if2;
 95.1304 -  short flag = 0;
 95.1305 -
 95.1306 -  sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0);
 95.1307 -  if (sock < 0) {
 95.1308 -    NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1309 -                                 "Socket creation failed");
 95.1310 -    return ret;
 95.1311 -  }
 95.1312  
 95.1313    memset((char *) &if2, 0, sizeof(if2));
 95.1314    strcpy(if2.ifr_name, ifname);
 95.1315 +
 95.1316    /* Let's make sure the interface does have a broadcast address */
 95.1317 -  if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) >= 0) {
 95.1318 -    flag = if2.ifr_flags;
 95.1319 -  } else {
 95.1320 -    NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1321 -                                 "IOCTL failed");
 95.1322 +  if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2)  < 0) {
 95.1323 +      NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL  SIOCGIFFLAGS failed");
 95.1324 +      return ret;
 95.1325    }
 95.1326 -  if (flag & IFF_BROADCAST) {
 95.1327 -    /* It does, let's retrieve it*/
 95.1328 -    if (ioctl(sock, SIOCGIFBRDADDR, (char *)&if2) >= 0) {
 95.1329 -      ret = (struct sockaddr*) malloc(sizeof(struct sockaddr));
 95.1330 +
 95.1331 +  if (if2.ifr_flags & IFF_BROADCAST) {
 95.1332 +      /* It does, let's retrieve it*/
 95.1333 +      if (ioctl(sock, SIOCGIFBRDADDR, (char *)&if2) < 0) {
 95.1334 +          NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFBRDADDR failed");
 95.1335 +          return ret;
 95.1336 +      }
 95.1337 +
 95.1338 +      ret = brdcast_store;
 95.1339        memcpy(ret, &if2.ifr_broadaddr, sizeof(struct sockaddr));
 95.1340 -    } else {
 95.1341 -      NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1342 -                                   "IOCTL failed");
 95.1343 -    }
 95.1344    }
 95.1345 -  close(sock);
 95.1346 +
 95.1347    return ret;
 95.1348  }
 95.1349  
 95.1350 @@ -1222,39 +1183,314 @@
 95.1351   * Returns the IPv4 subnet prefix length (aka subnet mask) for the named
 95.1352   * interface, if it has one, otherwise return -1.
 95.1353   */
 95.1354 -static short getSubnet(JNIEnv *env, const char *ifname) {
 95.1355 -  int sock;
 95.1356 -  unsigned int mask;
 95.1357 -  short ret;
 95.1358 +static short getSubnet(JNIEnv *env, int sock, const char *ifname) {
 95.1359 +    unsigned int mask;
 95.1360 +    short ret;
 95.1361 +    struct ifreq if2;
 95.1362 +
 95.1363 +    memset((char *) &if2, 0, sizeof(if2));
 95.1364 +    strcpy(if2.ifr_name, ifname);
 95.1365 +
 95.1366 +    if (ioctl(sock, SIOCGIFNETMASK, (char *)&if2) < 0) {
 95.1367 +        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFNETMASK failed");
 95.1368 +        return -1;
 95.1369 +    }
 95.1370 +
 95.1371 +    mask = ntohl(((struct sockaddr_in*)&(if2.ifr_addr))->sin_addr.s_addr);
 95.1372 +    ret = 0;
 95.1373 +    while (mask) {
 95.1374 +       mask <<= 1;
 95.1375 +       ret++;
 95.1376 +    }
 95.1377 +
 95.1378 +    return ret;
 95.1379 +}
 95.1380 +
 95.1381 +/**
 95.1382 + * Get the Hardware address (usually MAC address) for the named interface.
 95.1383 + * return puts the data in buf, and returns the length, in byte, of the
 95.1384 + * MAC address. Returns -1 if there is no hardware address on that interface.
 95.1385 + */
 95.1386 +static int getMacAddress(JNIEnv *env, int sock, const char* ifname, const struct in_addr* addr, unsigned char *buf) {
 95.1387 +    static struct ifreq ifr;
 95.1388 +    int i;
 95.1389 +
 95.1390 +    strcpy(ifr.ifr_name, ifname);
 95.1391 +    if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) {
 95.1392 +        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFHWADDR failed");
 95.1393 +        return -1;
 95.1394 +    }
 95.1395 +
 95.1396 +    memcpy(buf, &ifr.ifr_hwaddr.sa_data, IFHWADDRLEN);
 95.1397 +
 95.1398 +   /*
 95.1399 +    * All bytes to 0 means no hardware address.
 95.1400 +    */
 95.1401 +
 95.1402 +    for (i = 0; i < IFHWADDRLEN; i++) {
 95.1403 +        if (buf[i] != 0)
 95.1404 +            return IFHWADDRLEN;
 95.1405 +    }
 95.1406 +
 95.1407 +    return -1;
 95.1408 +}
 95.1409 +
 95.1410 +static int getMTU(JNIEnv *env, int sock,  const char *ifname) {
 95.1411 +    struct ifreq if2;
 95.1412 +
 95.1413 +    memset((char *) &if2, 0, sizeof(if2));
 95.1414 +    strcpy(if2.ifr_name, ifname);
 95.1415 +
 95.1416 +    if (ioctl(sock, SIOCGIFMTU, (char *)&if2) < 0) {
 95.1417 +        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFMTU failed");
 95.1418 +        return -1;
 95.1419 +    }
 95.1420 +
 95.1421 +    return  if2.ifr_mtu;
 95.1422 +}
 95.1423 +
 95.1424 +static int getFlags(JNIEnv *env, int sock, const char *ifname) {
 95.1425    struct ifreq if2;
 95.1426 -
 95.1427 -  sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0);
 95.1428 -  if (sock < 0) {
 95.1429 -    NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1430 -                                 "Socket creation failed");
 95.1431 -    return -1;
 95.1432 -  }
 95.1433 +  int ret = -1;
 95.1434  
 95.1435    memset((char *) &if2, 0, sizeof(if2));
 95.1436    strcpy(if2.ifr_name, ifname);
 95.1437 -  if (ioctl(sock, SIOCGIFNETMASK, (char *)&if2) >= 0) {
 95.1438 -    mask = ntohl(((struct sockaddr_in*)&(if2.ifr_addr))->sin_addr.s_addr);
 95.1439 -    ret = 0;
 95.1440 -    while (mask) {
 95.1441 -      mask <<= 1;
 95.1442 -      ret++;
 95.1443 -    }
 95.1444 -    close(sock);
 95.1445 -    return ret;
 95.1446 +
 95.1447 +  if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) < 0){
 95.1448 +      return -1;
 95.1449    }
 95.1450 -  NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1451 -                               "IOCTL failed");
 95.1452 -  close(sock);
 95.1453 -  return -1;
 95.1454 +
 95.1455 +  return if2.ifr_flags;
 95.1456  }
 95.1457  
 95.1458 +#endif
 95.1459 +
 95.1460 +/** Solaris **/
 95.1461  #ifdef __solaris__
 95.1462 -#define DEV_PREFIX      "/dev/"
 95.1463 +/* Open socket for further ioct calls, try v4 socket first and
 95.1464 + * if it falls return v6 socket
 95.1465 + */
 95.1466 +
 95.1467 +#ifdef AF_INET6
 95.1468 +static int openSocketWithFallback(JNIEnv *env, const char *ifname){
 95.1469 +    int sock, alreadyV6 = 0;
 95.1470 +    struct lifreq if2;
 95.1471 +
 95.1472 +     if ((sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
 95.1473 +         if (errno == EPROTONOSUPPORT){
 95.1474 +              if ( (sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0)) < 0 ){
 95.1475 +                 NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed");
 95.1476 +                 return -1;
 95.1477 +              }
 95.1478 +
 95.1479 +              alreadyV6=1;
 95.1480 +         }
 95.1481 +         else{ // errno is not NOSUPPORT
 95.1482 +             NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV4 Socket creation failed");
 95.1483 +             return -1;
 95.1484 +         }
 95.1485 +   }
 95.1486 +
 95.1487 +     /**
 95.1488 +      * Solaris requires that we have IPv6 socket to query an
 95.1489 +      * interface without IPv4 address - check it here
 95.1490 +      * POSIX 1 require the kernell to return ENOTTY if the call is
 95.1491 +      * unappropriate for device e.g. NETMASK for device having IPv6
 95.1492 +      * only address but not all devices follows the standart so
 95.1493 +      * fallback on any error.  It's not an ecology friendly but more
 95.1494 +      * reliable.
 95.1495 +      */
 95.1496 +
 95.1497 +    if (! alreadyV6 ){
 95.1498 +        memset((char *) &if2, 0, sizeof(if2));
 95.1499 +        strcpy(if2.lifr_name, ifname);
 95.1500 +        if (ioctl(sock, SIOCGLIFNETMASK, (char *)&if2) < 0) {
 95.1501 +                close(sock);
 95.1502 +                if ( (sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0)) < 0 ){
 95.1503 +                      NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed");
 95.1504 +                      return -1;
 95.1505 +                }
 95.1506 +        }
 95.1507 +    }
 95.1508 +
 95.1509 +    return sock;
 95.1510 +}
 95.1511 +
 95.1512 +#else
 95.1513 +static int openSocketWithFallback(JNIEnv *env, const char *ifname){
 95.1514 +    return openSocket(env,AF_INET);
 95.1515 +}
 95.1516 +#endif
 95.1517 +
 95.1518 +/*
 95.1519 + * Enumerates and returns all IPv4 interfaces
 95.1520 + * (linux verison)
 95.1521 + */
 95.1522 +
 95.1523 +static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
 95.1524 +     return enumIPvXInterfaces(env,sock, ifs, AF_INET);
 95.1525 +}
 95.1526 +
 95.1527 +#ifdef AF_INET6
 95.1528 +static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
 95.1529 +    return enumIPvXInterfaces(env,sock, ifs, AF_INET6);
 95.1530 +}
 95.1531 +#endif
 95.1532 +
 95.1533 +/*
 95.1534 +   Enumerates and returns all interfaces on Solaris
 95.1535 +   use the same code for IPv4 and IPv6
 95.1536 + */
 95.1537 +static netif *enumIPvXInterfaces(JNIEnv *env, int sock, netif *ifs, int family) {
 95.1538 +    struct lifconf ifc;
 95.1539 +    struct lifreq *ifr;
 95.1540 +    int n;
 95.1541 +    char *buf;
 95.1542 +    struct lifnum numifs;
 95.1543 +    unsigned bufsize;
 95.1544 +
 95.1545 +    /*
 95.1546 +     * Get the interface count
 95.1547 +     */
 95.1548 +    numifs.lifn_family = family;
 95.1549 +    numifs.lifn_flags = 0;
 95.1550 +    if (ioctl(sock, SIOCGLIFNUM, (char *)&numifs) < 0) {
 95.1551 +        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "ioctl SIOCGLIFNUM failed");
 95.1552 +        return ifs;
 95.1553 +    }
 95.1554 +
 95.1555 +    /*
 95.1556 +     *  Enumerate the interface configurations
 95.1557 +     */
 95.1558 +    bufsize = numifs.lifn_count * sizeof (struct lifreq);
 95.1559 +    CHECKED_MALLOC3(buf, char *, bufsize);
 95.1560 +
 95.1561 +    ifc.lifc_family = family;
 95.1562 +    ifc.lifc_flags = 0;
 95.1563 +    ifc.lifc_len = bufsize;
 95.1564 +    ifc.lifc_buf = buf;
 95.1565 +    if (ioctl(sock, SIOCGLIFCONF, (char *)&ifc) < 0) {
 95.1566 +        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "ioctl SIOCGLIFCONF failed");
 95.1567 +        free(buf);
 95.1568 +        return ifs;
 95.1569 +    }
 95.1570 +
 95.1571 +    /*
 95.1572 +     * Iterate through each interface
 95.1573 +     */
 95.1574 +    ifr = ifc.lifc_req;
 95.1575 +    for (n=0; n<numifs.lifn_count; n++, ifr++) {
 95.1576 +        int index = -1;
 95.1577 +        struct lifreq if2;
 95.1578 +
 95.1579 +        /*
 95.1580 +        * Ignore either IPv4 or IPv6 addresses
 95.1581 +        */
 95.1582 +        if (ifr->lifr_addr.ss_family != family) {
 95.1583 +            continue;
 95.1584 +        }
 95.1585 +
 95.1586 +#ifdef AF_INET6
 95.1587 +        if (ifr->lifr_addr.ss_family == AF_INET6) {
 95.1588 +            struct sockaddr_in6 *s6= (struct sockaddr_in6 *)&(ifr->lifr_addr);
 95.1589 +            s6->sin6_scope_id = getIndex(sock, ifr->lifr_name);
 95.1590 +        }
 95.1591 +#endif
 95.1592 +
 95.1593 +        /* add to the list */
 95.1594 +        ifs = addif(env, sock,ifr->lifr_name, ifs, (struct sockaddr *)&(ifr->lifr_addr),family, (short) ifr->lifr_addrlen);
 95.1595 +
 95.1596 +        /*
 95.1597 +        * If an exception occurred we return immediately
 95.1598 +        */
 95.1599 +        if ((*env)->ExceptionOccurred(env)) {
 95.1600 +            free(buf);
 95.1601 +            return ifs;
 95.1602 +        }
 95.1603 +
 95.1604 +   }
 95.1605 +
 95.1606 +    free(buf);
 95.1607 +    return ifs;
 95.1608 +}
 95.1609 +
 95.1610 +static int getIndex(int sock, const char *name){
 95.1611 +   /*
 95.1612 +    * Try to get the interface index
 95.1613 +    * (Not supported on Solaris 2.6 or 7)
 95.1614 +    */
 95.1615 +    struct lifreq if2;
 95.1616 +    strcpy(if2.lifr_name, name);
 95.1617 +
 95.1618 +    if (ioctl(sock, SIOCGLIFINDEX, (char *)&if2) < 0) {
 95.1619 +        return -1;
 95.1620 +    }
 95.1621 +
 95.1622 +    return if2.lifr_index;
 95.1623 +}
 95.1624 +
 95.1625 +/**
 95.1626 + * Returns the IPv4 broadcast address of a named interface, if it exists.
 95.1627 + * Returns 0 if it doesn't have one.
 95.1628 + */
 95.1629 +static struct sockaddr *getBroadcast(JNIEnv *env, int sock, const char *ifname, struct sockaddr *brdcast_store) {
 95.1630 +    struct sockaddr *ret = NULL;
 95.1631 +    struct lifreq if2;
 95.1632 +
 95.1633 +    memset((char *) &if2, 0, sizeof(if2));
 95.1634 +    strcpy(if2.lifr_name, ifname);
 95.1635 +
 95.1636 +    /* Let's make sure the interface does have a broadcast address */
 95.1637 +    if (ioctl(sock, SIOCGLIFFLAGS, (char *)&if2)  < 0) {
 95.1638 +        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL  SIOCGLIFFLAGS failed");
 95.1639 +        return ret;
 95.1640 +    }
 95.1641 +
 95.1642 +    if (if2.lifr_flags & IFF_BROADCAST) {
 95.1643 +        /* It does, let's retrieve it*/
 95.1644 +        if (ioctl(sock, SIOCGLIFBRDADDR, (char *)&if2) < 0) {
 95.1645 +            NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGLIFBRDADDR failed");
 95.1646 +            return ret;
 95.1647 +        }
 95.1648 +
 95.1649 +        ret = brdcast_store;
 95.1650 +        memcpy(ret, &if2.lifr_broadaddr, sizeof(struct sockaddr));
 95.1651 +    }
 95.1652 +
 95.1653 +    return ret;
 95.1654 +}
 95.1655 +
 95.1656 +/**
 95.1657 + * Returns the IPv4 subnet prefix length (aka subnet mask) for the named
 95.1658 + * interface, if it has one, otherwise return -1.
 95.1659 + */
 95.1660 +static short getSubnet(JNIEnv *env, int sock, const char *ifname) {
 95.1661 +    unsigned int mask;
 95.1662 +    short ret;
 95.1663 +    struct lifreq if2;
 95.1664 +
 95.1665 +    memset((char *) &if2, 0, sizeof(if2));
 95.1666 +    strcpy(if2.lifr_name, ifname);
 95.1667 +
 95.1668 +    if (ioctl(sock, SIOCGLIFNETMASK, (char *)&if2) < 0) {
 95.1669 +        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGLIFNETMASK failed");
 95.1670 +        return -1;
 95.1671 +    }
 95.1672 +
 95.1673 +    mask = ntohl(((struct sockaddr_in*)&(if2.lifr_addr))->sin_addr.s_addr);
 95.1674 +    ret = 0;
 95.1675 +
 95.1676 +    while (mask) {
 95.1677 +       mask <<= 1;
 95.1678 +       ret++;
 95.1679 +    }
 95.1680 +
 95.1681 +    return ret;
 95.1682 +}
 95.1683 +
 95.1684 +
 95.1685 +
 95.1686 +#define DEV_PREFIX  "/dev/"
 95.1687  
 95.1688  /**
 95.1689   * Solaris specific DLPI code to get hardware address from a device.
 95.1690 @@ -1262,306 +1498,147 @@
 95.1691   * privileges (i.e. be root).
 95.1692   */
 95.1693  static int getMacFromDevice(JNIEnv *env, const char* ifname, unsigned char* retbuf) {
 95.1694 -  char style1dev[MAXPATHLEN];
 95.1695 -  int fd;
 95.1696 -  dl_phys_addr_req_t dlpareq;
 95.1697 -  dl_phys_addr_ack_t *dlpaack;
 95.1698 -  struct strbuf msg;
 95.1699 -  char buf[128];
 95.1700 -  int flags = 0;
 95.1701 +    char style1dev[MAXPATHLEN];
 95.1702 +    int fd;
 95.1703 +    dl_phys_addr_req_t dlpareq;
 95.1704 +    dl_phys_addr_ack_t *dlpaack;
 95.1705 +    struct strbuf msg;
 95.1706 +    char buf[128];
 95.1707 +    int flags = 0;
 95.1708  
 95.1709 -  /**
 95.1710 -   * Device is in /dev
 95.1711 -   * e.g.: /dev/bge0
 95.1712 -   */
 95.1713 -  strcpy(style1dev, DEV_PREFIX);
 95.1714 -  strcat(style1dev, ifname);
 95.1715 -  if ((fd = open(style1dev, O_RDWR)) == -1) {
 95.1716 -    /*
 95.1717 -     * Can't open it. We probably are missing the privilege.
 95.1718 -     * We'll have to try something else
 95.1719 -     */
 95.1720 -    return 0;
 95.1721 -  }
 95.1722 -  dlpareq.dl_primitive = DL_PHYS_ADDR_REQ;
 95.1723 -  dlpareq.dl_addr_type = DL_CURR_PHYS_ADDR;
 95.1724 -  msg.buf = (char *)&dlpareq;
 95.1725 -  msg.len = DL_PHYS_ADDR_REQ_SIZE;
 95.1726 -  if (putmsg(fd, &msg, NULL, 0) < 0) {
 95.1727 -    NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1728 -                                 "putmsg failed");
 95.1729 -    return -1;
 95.1730 -  }
 95.1731 -  dlpaack = (dl_phys_addr_ack_t *)buf;
 95.1732 -  msg.buf = (char *)buf;
 95.1733 -  msg.len = 0;
 95.1734 -  msg.maxlen = sizeof (buf);
 95.1735 -  if (getmsg(fd, &msg, NULL, &flags) < 0) {
 95.1736 -    NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1737 -                                 "getmsg failed");
 95.1738 -    return -1;
 95.1739 -  }
 95.1740 -  if (msg.len < DL_PHYS_ADDR_ACK_SIZE ||
 95.1741 -      dlpaack->dl_primitive != DL_PHYS_ADDR_ACK) {
 95.1742 -    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
 95.1743 -                    "Couldn't obtain phys addr\n");
 95.1744 -    return -1;
 95.1745 -  }
 95.1746 +   /**
 95.1747 +    * Device is in /dev
 95.1748 +    * e.g.: /dev/bge0
 95.1749 +    */
 95.1750 +    strcpy(style1dev, DEV_PREFIX);
 95.1751 +    strcat(style1dev, ifname);
 95.1752 +    if ((fd = open(style1dev, O_RDWR)) < 0) {
 95.1753 +        /*
 95.1754 +         * Can't open it. We probably are missing the privilege.
 95.1755 +         * We'll have to try something else
 95.1756 +         */
 95.1757 +         return 0;
 95.1758 +    }
 95.1759  
 95.1760 -  memcpy(retbuf, &buf[dlpaack->dl_addr_offset], dlpaack->dl_addr_length);
 95.1761 -  return dlpaack->dl_addr_length;
 95.1762 +    dlpareq.dl_primitive = DL_PHYS_ADDR_REQ;
 95.1763 +    dlpareq.dl_addr_type = DL_CURR_PHYS_ADDR;
 95.1764 +
 95.1765 +    msg.buf = (char *)&dlpareq;
 95.1766 +    msg.len = DL_PHYS_ADDR_REQ_SIZE;
 95.1767 +
 95.1768 +    if (putmsg(fd, &msg, NULL, 0) < 0) {
 95.1769 +        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "putmsg failed");
 95.1770 +        return -1;
 95.1771 +    }
 95.1772 +
 95.1773 +    dlpaack = (dl_phys_addr_ack_t *)buf;
 95.1774 +
 95.1775 +    msg.buf = (char *)buf;
 95.1776 +    msg.len = 0;
 95.1777 +    msg.maxlen = sizeof (buf);
 95.1778 +    if (getmsg(fd, &msg, NULL, &flags) < 0) {
 95.1779 +        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "getmsg failed");
 95.1780 +        return -1;
 95.1781 +    }
 95.1782 +
 95.1783 +    if (msg.len < DL_PHYS_ADDR_ACK_SIZE || dlpaack->dl_primitive != DL_PHYS_ADDR_ACK) {
 95.1784 +        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Couldn't obtain phys addr\n");
 95.1785 +        return -1;
 95.1786 +    }
 95.1787 +
 95.1788 +    memcpy(retbuf, &buf[dlpaack->dl_addr_offset], dlpaack->dl_addr_length);
 95.1789 +    return dlpaack->dl_addr_length;
 95.1790  }
 95.1791 -#endif
 95.1792  
 95.1793  /**
 95.1794   * Get the Hardware address (usually MAC address) for the named interface.
 95.1795   * return puts the data in buf, and returns the length, in byte, of the
 95.1796   * MAC address. Returns -1 if there is no hardware address on that interface.
 95.1797   */
 95.1798 -int getMacAddress(JNIEnv *env, const struct in_addr* addr, const char* ifname,
 95.1799 -                  unsigned char *buf) {
 95.1800 -  int sock;
 95.1801 -#ifdef __linux__
 95.1802 -  static struct ifreq ifr;
 95.1803 -  int i;
 95.1804 +static int getMacAddress(JNIEnv *env, int sock, const char *ifname,  const struct in_addr* addr, unsigned char *buf) {
 95.1805 +    struct arpreq arpreq;
 95.1806 +    struct sockaddr_in* sin;
 95.1807 +    struct sockaddr_in ipAddr;
 95.1808 +    int len, i;
 95.1809  
 95.1810 -  sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0);
 95.1811 +   /**
 95.1812 +    * On Solaris we have to use DLPI, but it will only work if we have
 95.1813 +    * privileged access (i.e. root). If that fails, we try a lookup
 95.1814 +    * in the ARP table, which requires an IPv4 address.
 95.1815 +    */
 95.1816 +    if ((len = getMacFromDevice(env, ifname, buf))  == 0) {
 95.1817 +        /*DLPI failed - trying to do arp lookup*/
 95.1818  
 95.1819 -  if (sock < 0) {
 95.1820 -    NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1821 -                                 "Socket creation failed");
 95.1822 -    return -1;
 95.1823 +       if (addr == NULL) {
 95.1824 +          /**
 95.1825 +           * No IPv4 address for that interface, so can't do an ARP lookup.
 95.1826 +           */
 95.1827 +           return -1;
 95.1828 +      }
 95.1829 +
 95.1830 +      len = 6; //???
 95.1831 +
 95.1832 +      sin = (struct sockaddr_in *) &arpreq.arp_pa;
 95.1833 +      memset((char *) &arpreq, 0, sizeof(struct arpreq));
 95.1834 +      ipAddr.sin_port = 0;
 95.1835 +      ipAddr.sin_family = AF_INET;
 95.1836 +      memcpy(&ipAddr.sin_addr, addr, sizeof(struct in_addr));
 95.1837 +      memcpy(&arpreq.arp_pa, &ipAddr, sizeof(struct sockaddr_in));
 95.1838 +      arpreq.arp_flags= ATF_PUBL;
 95.1839 +
 95.1840 +      if (ioctl(sock, SIOCGARP, &arpreq) < 0) {
 95.1841 +          if (errno != ENXIO) {
 95.1842 +              // "No such device or address" means no hardware address, so it's
 95.1843 +              // normal don't throw an exception
 95.1844 +              NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL failed");
 95.1845 +              return -1;
 95.1846 +          }
 95.1847 +     }
 95.1848 +
 95.1849 +     memcpy(buf, &arpreq.arp_ha.sa_data[0], len );
 95.1850    }
 95.1851  
 95.1852 -  strcpy(ifr.ifr_name, ifname);
 95.1853 +    /*
 95.1854 +     * All bytes to 0 means no hardware address.
 95.1855 +     */
 95.1856  
 95.1857 -  if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) {
 95.1858 -    fprintf(stderr, "SIOCIFHWADDR: %s\n",
 95.1859 -            strerror(errno));
 95.1860 -    close(sock);
 95.1861 +    for (i = 0; i < len; i++) {
 95.1862 +      if (buf[i] != 0)
 95.1863 +         return len;
 95.1864 +    }
 95.1865 +
 95.1866      return -1;
 95.1867 -  }
 95.1868 -  memcpy(buf, &ifr.ifr_hwaddr.sa_data, IFHWADDRLEN);
 95.1869 -  close(sock);
 95.1870 -  for (i = 0; i < IFHWADDRLEN; i++) {
 95.1871 -    if (buf[i] != 0)
 95.1872 -      return IFHWADDRLEN;
 95.1873 -  }
 95.1874 -  /*
 95.1875 -   * All bytes to 0 means no hardware address.
 95.1876 -   */
 95.1877 -  return -1;
 95.1878 -#else
 95.1879 -  struct arpreq arpreq;
 95.1880 -  struct sockaddr_in* sin;
 95.1881 -  struct sockaddr_in ipAddr;
 95.1882 -  int len;
 95.1883 -
 95.1884 -  /**
 95.1885 -   * On Solaris we have to use DLPI, but it will only work if we have
 95.1886 -   * privileged access (i.e. root). If that fails, we try a lookup
 95.1887 -   * in the ARP table, which requires an IPv4 address.
 95.1888 -   */
 95.1889 -  if ((len = getMacFromDevice(env, ifname, buf)) > 0) {
 95.1890 -    return len;
 95.1891 -  }
 95.1892 -  if (addr == NULL) {
 95.1893 -    /**
 95.1894 -     * No IPv4 address for that interface, so can't do an ARP lookup.
 95.1895 -     */
 95.1896 -    return -1;
 95.1897 -  }
 95.1898 -  sin = (struct sockaddr_in *) &arpreq.arp_pa;
 95.1899 -  memset((char *) &arpreq, 0, sizeof(struct arpreq));
 95.1900 -  ipAddr.sin_port = 0;
 95.1901 -  ipAddr.sin_family = AF_INET;
 95.1902 -  memcpy(&ipAddr.sin_addr, addr, sizeof(struct in_addr));
 95.1903 -  memcpy(&arpreq.arp_pa, &ipAddr, sizeof(struct sockaddr_in));
 95.1904 -  arpreq.arp_flags= ATF_PUBL;
 95.1905 -  sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0);
 95.1906 -
 95.1907 -  if (sock < 0) {
 95.1908 -    NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1909 -                                 "Socket creation failed");
 95.1910 -    return -1;
 95.1911 -  }
 95.1912 -
 95.1913 -  if (ioctl(sock, SIOCGARP, &arpreq) >= 0) {
 95.1914 -    close(sock);
 95.1915 -    memcpy(buf, &arpreq.arp_ha.sa_data[0], 6);
 95.1916 -    return 6;
 95.1917 -  }
 95.1918 -
 95.1919 -  if (errno != ENXIO) {
 95.1920 -    // "No such device or address" means no hardware address, so it's
 95.1921 -    // normal don't throw an exception
 95.1922 -    NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.1923 -                                 "IOCTL failed");
 95.1924 -  }
 95.1925 -  close(sock);
 95.1926 -#endif
 95.1927 -  return -1;
 95.1928  }
 95.1929  
 95.1930 -/*
 95.1931 - * Class:     java_net_NetworkInterface
 95.1932 - * Method:    isUp0
 95.1933 - * Signature: (Ljava/lang/String;I)Z
 95.1934 - */
 95.1935 -JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0
 95.1936 -    (JNIEnv *env, jclass cls, jstring name, jint index) {
 95.1937 -    short val;
 95.1938 +static int getMTU(JNIEnv *env, int sock,  const char *ifname) {
 95.1939 +    struct lifreq if2;
 95.1940  
 95.1941 -    val = getFlags(env, name);
 95.1942 -    if ( (val & IFF_UP) && (val &  IFF_RUNNING))
 95.1943 -      return JNI_TRUE;
 95.1944 -    return JNI_FALSE;
 95.1945 +    memset((char *) &if2, 0, sizeof(if2));
 95.1946 +    strcpy(if2.lifr_name, ifname);
 95.1947 +
 95.1948 +    if (ioctl(sock, SIOCGLIFMTU, (char *)&if2) < 0) {
 95.1949 +        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGLIFMTU failed");
 95.1950 +        return -1;
 95.1951 +    }
 95.1952 +
 95.1953 +    return  if2.lifr_mtu;
 95.1954  }
 95.1955  
 95.1956 -/*
 95.1957 - * Class:     java_net_NetworkInterface
 95.1958 - * Method:    isP2P0
 95.1959 - * Signature: (Ljava/lang/String;I)Z
 95.1960 - */
 95.1961 -JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0
 95.1962 -    (JNIEnv *env, jclass cls, jstring name, jint index) {
 95.1963 -    if (getFlags(env, name) & IFF_POINTOPOINT)
 95.1964 -      return JNI_TRUE;
 95.1965 -    return JNI_FALSE;
 95.1966 +
 95.1967 +static int getFlags(JNIEnv *env, int sock, const char *ifname) {
 95.1968 +     struct   lifreq lifr;
 95.1969 +     memset((caddr_t)&lifr, 0, sizeof(lifr));
 95.1970 +     strcpy((caddr_t)&(lifr.lifr_name), ifname);
 95.1971 +
 95.1972 +     if (ioctl(sock, SIOCGLIFFLAGS, (char *)&lifr) < 0) {
 95.1973 +         NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGLIFFLAGS failed");
 95.1974 +         return -1;
 95.1975 +     }
 95.1976 +
 95.1977 +     return  lifr.lifr_flags;
 95.1978  }
 95.1979  
 95.1980 -/*
 95.1981 - * Class:     java_net_NetworkInterface
 95.1982 - * Method:    isLoopback0
 95.1983 - * Signature: (Ljava/lang/String;I)Z
 95.1984 - */
 95.1985 -JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0
 95.1986 -    (JNIEnv *env, jclass cls, jstring name, jint index) {
 95.1987 -    if (getFlags(env, name) & IFF_LOOPBACK)
 95.1988 -      return JNI_TRUE;
 95.1989 -    return JNI_FALSE;
 95.1990 -}
 95.1991  
 95.1992 -/*
 95.1993 - * Class:     java_net_NetworkInterface
 95.1994 - * Method:    supportsMulticast0
 95.1995 - * Signature: (Ljava/lang/String;I)Z
 95.1996 - */
 95.1997 -JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0
 95.1998 -(JNIEnv *env, jclass cls, jstring name, jint index) {
 95.1999 -  short val;
 95.2000 +#endif
 95.2001  
 95.2002 -  val = getFlags(env, name);
 95.2003 -  if (val & IFF_MULTICAST)
 95.2004 -    return JNI_TRUE;
 95.2005 -  return JNI_FALSE;
 95.2006 -}
 95.2007  
 95.2008 -/*
 95.2009 - * Class:     java_net_NetworkInterface
 95.2010 - * Method:    getMacAddr0
 95.2011 - * Signature: ([bLjava/lang/String;I)[b
 95.2012 - */
 95.2013 -JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0(JNIEnv *env, jclass class, jbyteArray addrArray, jstring name, jint index) {
 95.2014 -  jint addr;
 95.2015 -  jbyte caddr[4];
 95.2016 -  struct in_addr iaddr;
 95.2017 -  jbyteArray ret = NULL;
 95.2018 -  unsigned char mac[16];
 95.2019 -  int len;
 95.2020 -  jboolean isCopy;
 95.2021 -  const char* name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
 95.2022 -
 95.2023 -  if (!IS_NULL(addrArray)) {
 95.2024 -    (*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
 95.2025 -    addr = ((caddr[0]<<24) & 0xff000000);
 95.2026 -    addr |= ((caddr[1] <<16) & 0xff0000);
 95.2027 -    addr |= ((caddr[2] <<8) & 0xff00);
 95.2028 -    addr |= (caddr[3] & 0xff);
 95.2029 -    iaddr.s_addr = htonl(addr);
 95.2030 -    len = getMacAddress(env, &iaddr, name_utf, mac);
 95.2031 -  } else {
 95.2032 -    len = getMacAddress(env, NULL, name_utf, mac);
 95.2033 -  }
 95.2034 -  if (len > 0) {
 95.2035 -    ret = (*env)->NewByteArray(env, len);
 95.2036 -    if (IS_NULL(ret)) {
 95.2037 -      /* we may have memory to free at the end of this */
 95.2038 -      goto fexit;
 95.2039 -    }
 95.2040 -    (*env)->SetByteArrayRegion(env, ret, 0, len, (jbyte *) (mac));
 95.2041 -  }
 95.2042 - fexit:
 95.2043 -  /* release the UTF string and interface list */
 95.2044 -  (*env)->ReleaseStringUTFChars(env, name, name_utf);
 95.2045 -  return ret;
 95.2046 -}
 95.2047 -
 95.2048 -/*
 95.2049 - * Class:       java_net_NetworkInterface
 95.2050 - * Method:      getMTU0
 95.2051 - * Signature:   ([bLjava/lang/String;I)I
 95.2052 - */
 95.2053 -
 95.2054 -JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0(JNIEnv *env, jclass class, jstring name, jint index) {
 95.2055 -  jboolean isCopy;
 95.2056 -  int sock;
 95.2057 -  struct ifreq if2;
 95.2058 -  int ret = -1;
 95.2059 -  const char* name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
 95.2060 -
 95.2061 -  sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0);
 95.2062 -  if (sock < 0) {
 95.2063 -    NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.2064 -                                 "Socket creation failed");
 95.2065 -  } else {
 95.2066 -
 95.2067 -#ifdef __linux__
 95.2068 -    memset((char *) &if2, 0, sizeof(if2));
 95.2069 -    strcpy(if2.ifr_name, name_utf);
 95.2070 -
 95.2071 -    if (ioctl(sock, SIOCGIFMTU, (char *)&if2) >= 0) {
 95.2072 -      ret= if2.ifr_mtu;
 95.2073 -    } else {
 95.2074 -      NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.2075 -                                   "IOCTL failed");
 95.2076 -    }
 95.2077 -#else /* Solaris */
 95.2078 -    struct   lifreq lifr;
 95.2079 -    memset((caddr_t)&lifr, 0, sizeof(lifr));
 95.2080 -    strcpy((caddr_t)&(lifr.lifr_name), name_utf);
 95.2081 -    if (ioctl(sock, SIOCGLIFMTU, (caddr_t)&lifr) >= 0) {
 95.2082 -      ret = lifr.lifr_mtu;
 95.2083 -#ifdef AF_INET6
 95.2084 -    } else {
 95.2085 -      /* Try wIth an IPv6 socket in case the interface has only IPv6 addresses assigned to it */
 95.2086 -      close(sock);
 95.2087 -      sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0);
 95.2088 -
 95.2089 -      if (sock < 0) {
 95.2090 -        (*env)->ReleaseStringUTFChars(env, name, name_utf);
 95.2091 -        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.2092 -                                     "Socket creation failed");
 95.2093 -        return -1;
 95.2094 -      }
 95.2095 -
 95.2096 -      if (ioctl(sock, SIOCGLIFMTU, (caddr_t)&lifr) >= 0) {
 95.2097 -        ret = lifr.lifr_mtu;
 95.2098 -      } else {
 95.2099 -        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.2100 -                                     "IOCTL failed");
 95.2101 -      }
 95.2102 -    }
 95.2103 -#else
 95.2104 -    } else {
 95.2105 -        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 95.2106 -                                     "IOCTL failed");
 95.2107 -    }
 95.2108 -#endif
 95.2109 -#endif
 95.2110 -    close(sock);
 95.2111 -  }
 95.2112 -  /* release the UTF string and interface list */
 95.2113 -  (*env)->ReleaseStringUTFChars(env, name, name_utf);
 95.2114 -  return ret;
 95.2115 -}
    96.1 --- a/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c	Thu Jul 15 20:11:45 2010 -0700
    96.2 +++ b/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c	Tue Jul 20 22:21:31 2010 -0700
    96.3 @@ -42,6 +42,29 @@
    96.4              filename);
    96.5  }
    96.6  
    96.7 +static void quit(gboolean isSignalHandler)
    96.8 +{
    96.9 +    if (dialog != NULL)
   96.10 +    {
   96.11 +        // Callbacks from GTK signals are made within the GTK lock
   96.12 +        // So, within a signal handler there is no need to call
   96.13 +        // gdk_threads_enter() / fp_gdk_threads_leave()
   96.14 +        if (!isSignalHandler) {
   96.15 +            fp_gdk_threads_enter();
   96.16 +        }
   96.17 +
   96.18 +        fp_gtk_widget_hide (dialog);
   96.19 +        fp_gtk_widget_destroy (dialog);
   96.20 +
   96.21 +        fp_gtk_main_quit ();
   96.22 +        dialog = NULL;
   96.23 +
   96.24 +        if (!isSignalHandler) {
   96.25 +            fp_gdk_threads_leave();
   96.26 +        }
   96.27 +    }
   96.28 +}
   96.29 +
   96.30  /*
   96.31   * Class:     sun_awt_X11_GtkFileDialogPeer
   96.32   * Method:    quit
   96.33 @@ -50,18 +73,7 @@
   96.34  JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_quit
   96.35  (JNIEnv * env, jobject jpeer)
   96.36  {
   96.37 -    if (dialog != NULL)
   96.38 -    {
   96.39 -        fp_gdk_threads_enter();
   96.40 -
   96.41 -        fp_gtk_widget_hide (dialog);
   96.42 -        fp_gtk_widget_destroy (dialog);
   96.43 -
   96.44 -        fp_gtk_main_quit ();
   96.45 -        dialog = NULL;
   96.46 -
   96.47 -        fp_gdk_threads_leave();
   96.48 -    }
   96.49 +    quit(FALSE);
   96.50  }
   96.51  
   96.52  /**
   96.53 @@ -147,7 +159,7 @@
   96.54              jfilenames);
   96.55      fp_g_free(current_folder);
   96.56  
   96.57 -    Java_sun_awt_X11_GtkFileDialogPeer_quit(NULL, NULL);
   96.58 +    quit(TRUE);
   96.59  }
   96.60  
   96.61  /*
    97.1 --- a/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c	Thu Jul 15 20:11:45 2010 -0700
    97.2 +++ b/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c	Tue Jul 20 22:21:31 2010 -0700
    97.3 @@ -65,6 +65,11 @@
    97.4  
    97.5      J2dTraceLn(J2D_TRACE_INFO, "GLXSurfaceData_initOps");
    97.6  
    97.7 +    if (oglsdo == NULL) {
    97.8 +        JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
    97.9 +        return;
   97.10 +    }
   97.11 +
   97.12      if (glxsdo == NULL) {
   97.13          JNU_ThrowOutOfMemoryError(env, "creating native GLX ops");
   97.14          return;
    98.1 --- a/src/solaris/native/sun/java2d/x11/X11SurfaceData.c	Thu Jul 15 20:11:45 2010 -0700
    98.2 +++ b/src/solaris/native/sun/java2d/x11/X11SurfaceData.c	Tue Jul 20 22:21:31 2010 -0700
    98.3 @@ -253,6 +253,10 @@
    98.4  {
    98.5  #ifndef HEADLESS
    98.6      X11SDOps *xsdo = (X11SDOps*)SurfaceData_InitOps(env, xsd, sizeof(X11SDOps));
    98.7 +    if (xsdo == NULL) {
    98.8 +        JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
    98.9 +        return;
   98.10 +    }
   98.11      xsdo->sdOps.Lock = X11SD_Lock;
   98.12      xsdo->sdOps.GetRasInfo = X11SD_GetRasInfo;
   98.13      xsdo->sdOps.Unlock = X11SD_Unlock;
    99.1 --- a/src/windows/bin/java_md.c	Thu Jul 15 20:11:45 2010 -0700
    99.2 +++ b/src/windows/bin/java_md.c	Tue Jul 20 22:21:31 2010 -0700
    99.3 @@ -1,5 +1,5 @@
    99.4  /*
    99.5 - * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
    99.6 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
    99.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    99.8   *
    99.9   * This code is free software; you can redistribute it and/or modify it
   99.10 @@ -80,26 +80,22 @@
   99.11   *
   99.12   */
   99.13  void
   99.14 -CreateExecutionEnvironment(int *_argc,
   99.15 -                           char ***_argv,
   99.16 -                           char jrepath[],
   99.17 -                           jint so_jrepath,
   99.18 -                           char jvmpath[],
   99.19 -                           jint so_jvmpath,
   99.20 -                           char **original_argv) {
   99.21 +CreateExecutionEnvironment(int *pargc, char ***pargv,
   99.22 +                           char *jrepath, jint so_jrepath,
   99.23 +                           char *jvmpath, jint so_jvmpath) {
   99.24      char * jvmtype;
   99.25      int i = 0;
   99.26 -    char** pargv = *_argv;
   99.27      int running = CURRENT_DATA_MODEL;
   99.28  
   99.29      int wanted = running;
   99.30  
   99.31 -    for (i = 0; i < *_argc ; i++) {
   99.32 -        if (JLI_StrCmp(pargv[i], "-J-d64") == 0 || JLI_StrCmp(pargv[i], "-d64") == 0) {
   99.33 +    char** argv = *pargv;
   99.34 +    for (i = 0; i < *pargc ; i++) {
   99.35 +        if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) {
   99.36              wanted = 64;
   99.37              continue;
   99.38          }
   99.39 -        if (JLI_StrCmp(pargv[i], "-J-d32") == 0 || JLI_StrCmp(pargv[i], "-d32") == 0) {
   99.40 +        if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) {
   99.41              wanted = 32;
   99.42              continue;
   99.43          }
   99.44 @@ -123,7 +119,12 @@
   99.45          JLI_ReportErrorMessage(CFG_ERROR7);
   99.46          exit(1);
   99.47      }
   99.48 -    jvmtype = CheckJvmType(_argc, _argv, JNI_FALSE);
   99.49 +
   99.50 +    jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
   99.51 +    if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
   99.52 +        JLI_ReportErrorMessage(CFG_ERROR9);
   99.53 +        exit(4);
   99.54 +    }
   99.55  
   99.56      jvmpath[0] = '\0';
   99.57      if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) {
   99.58 @@ -131,7 +132,6 @@
   99.59          exit(4);
   99.60      }
   99.61      /* If we got here, jvmpath has been correctly initialized. */
   99.62 -
   99.63  }
   99.64  
   99.65  
   99.66 @@ -203,19 +203,21 @@
   99.67      PREJVMSTART PreJVMStart;
   99.68      struct stat s;
   99.69  
   99.70 +    /* Make sure the jrepath contains something */
   99.71 +    if (jrepath[0] == NULL) {
   99.72 +        return;
   99.73 +    }
   99.74      /* 32 bit windows only please */
   99.75 -    if (strcmp(GetArch(), "i386") != 0 ) {
   99.76 +    if (JLI_StrCmp(GetArch(), "i386") != 0 ) {
   99.77          return;
   99.78      }
   99.79      /* Does our bundle directory exist ? */
   99.80 -    strcpy(tmpbuf, jrepath);
   99.81 -    strcat(tmpbuf, "\\lib\\bundles");
   99.82 +    JLI_Snprintf(tmpbuf, sizeof(tmpbuf), "%s\\lib\\bundles", jrepath);
   99.83      if (stat(tmpbuf, &s) != 0) {
   99.84          return;
   99.85      }
   99.86      /* Does our jkernel dll exist ? */
   99.87 -    strcpy(tmpbuf, jrepath);
   99.88 -    strcat(tmpbuf, "\\bin\\jkernel.dll");
   99.89 +    JLI_Snprintf(tmpbuf, sizeof(tmpbuf), "%s\\bin\\jkernel.dll", jrepath);
   99.90      if (stat(tmpbuf, &s) != 0) {
   99.91          return;
   99.92      }
   99.93 @@ -249,30 +251,30 @@
   99.94  
   99.95      if (GetApplicationHome(path, pathsize)) {
   99.96          /* Is JRE co-located with the application? */
   99.97 -        sprintf(javadll, "%s\\bin\\" JAVA_DLL, path);
   99.98 +        JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path);
   99.99          if (stat(javadll, &s) == 0) {
  99.100 -            goto found;
  99.101 +            JLI_TraceLauncher("JRE path is %s\n", path);
  99.102 +            return JNI_TRUE;
  99.103          }
  99.104  
  99.105          /* Does this app ship a private JRE in <apphome>\jre directory? */
  99.106 -        sprintf(javadll, "%s\\jre\\bin\\" JAVA_DLL, path);
  99.107 +        JLI_Snprintf(javadll, sizeof (javadll), "%s\\jre\\bin\\" JAVA_DLL, path);
  99.108          if (stat(javadll, &s) == 0) {
  99.109              JLI_StrCat(path, "\\jre");
  99.110 -            goto found;
  99.111 +            JLI_TraceLauncher("JRE path is %s\n", path);
  99.112 +            return JNI_TRUE;
  99.113          }
  99.114      }
  99.115  
  99.116      /* Look for a public JRE on this machine. */
  99.117      if (GetPublicJREHome(path, pathsize)) {
  99.118 -        goto found;
  99.119 +        JLI_TraceLauncher("JRE path is %s\n", path);
  99.120 +        return JNI_TRUE;
  99.121      }
  99.122  
  99.123      JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
  99.124      return JNI_FALSE;
  99.125  
  99.126 - found:
  99.127 -    JLI_TraceLauncher("JRE path is %s\n", path);
  99.128 -    return JNI_TRUE;
  99.129  }
  99.130  
  99.131  /*
  99.132 @@ -286,9 +288,9 @@
  99.133  {
  99.134      struct stat s;
  99.135      if (JLI_StrChr(jvmtype, '/') || JLI_StrChr(jvmtype, '\\')) {
  99.136 -        sprintf(jvmpath, "%s\\" JVM_DLL, jvmtype);
  99.137 +        JLI_Snprintf(jvmpath, jvmpathsize, "%s\\" JVM_DLL, jvmtype);
  99.138      } else {
  99.139 -        sprintf(jvmpath, "%s\\bin\\%s\\" JVM_DLL, jrepath, jvmtype);
  99.140 +        JLI_Snprintf(jvmpath, jvmpathsize, "%s\\bin\\%s\\" JVM_DLL, jrepath, jvmtype);
  99.141      }
  99.142      if (stat(jvmpath, &s) == 0) {
  99.143          return JNI_TRUE;
   100.1 --- a/src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java	Thu Jul 15 20:11:45 2010 -0700
   100.2 +++ b/src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java	Tue Jul 20 22:21:31 2010 -0700
   100.3 @@ -312,14 +312,17 @@
   100.4          private int processSelectedKeys(long updateCount) {
   100.5              int numKeysUpdated = 0;
   100.6              numKeysUpdated += processFDSet(updateCount, readFds,
   100.7 -                                           PollArrayWrapper.POLLIN);
   100.8 +                                           PollArrayWrapper.POLLIN,
   100.9 +                                           false);
  100.10              numKeysUpdated += processFDSet(updateCount, writeFds,
  100.11                                             PollArrayWrapper.POLLCONN |
  100.12 -                                           PollArrayWrapper.POLLOUT);
  100.13 +                                           PollArrayWrapper.POLLOUT,
  100.14 +                                           false);
  100.15              numKeysUpdated += processFDSet(updateCount, exceptFds,
  100.16                                             PollArrayWrapper.POLLIN |
  100.17                                             PollArrayWrapper.POLLCONN |
  100.18 -                                           PollArrayWrapper.POLLOUT);
  100.19 +                                           PollArrayWrapper.POLLOUT,
  100.20 +                                           true);
  100.21              return numKeysUpdated;
  100.22          }
  100.23  
  100.24 @@ -331,7 +334,9 @@
  100.25           *
  100.26           * me.updateCount <= me.clearedCount <= updateCount
  100.27           */
  100.28 -        private int processFDSet(long updateCount, int[] fds, int rOps) {
  100.29 +        private int processFDSet(long updateCount, int[] fds, int rOps,
  100.30 +                                 boolean isExceptFds)
  100.31 +        {
  100.32              int numKeysUpdated = 0;
  100.33              for (int i = 1; i <= fds[0]; i++) {
  100.34                  int desc = fds[i];
  100.35 @@ -347,6 +352,17 @@
  100.36                  if (me == null)
  100.37                      continue;
  100.38                  SelectionKeyImpl sk = me.ski;
  100.39 +
  100.40 +                // The descriptor may be in the exceptfds set because there is
  100.41 +                // OOB data queued to the socket. If there is OOB data then it
  100.42 +                // is discarded and the key is not added to the selected set.
  100.43 +                if (isExceptFds &&
  100.44 +                    (sk.channel() instanceof SocketChannelImpl) &&
  100.45 +                    discardUrgentData(desc))
  100.46 +                {
  100.47 +                    continue;
  100.48 +                }
  100.49 +
  100.50                  if (selectedKeys.contains(sk)) { // Key in selected set
  100.51                      if (me.clearedCount != updateCount) {
  100.52                          if (sk.channel.translateAndSetReadyOps(rOps, sk) &&
  100.53 @@ -460,6 +476,8 @@
  100.54  
  100.55      private native void resetWakeupSocket0(int wakeupSourceFd);
  100.56  
  100.57 +    private native boolean discardUrgentData(int fd);
  100.58 +
  100.59      // We increment this counter on each call to updateSelectedKeys()
  100.60      // each entry in  SubSelector.fdsMap has a memorized value of
  100.61      // updateCount. When we increment numKeysUpdated we set updateCount
   101.1 --- a/src/windows/native/sun/java2d/opengl/WGLSurfaceData.c	Thu Jul 15 20:11:45 2010 -0700
   101.2 +++ b/src/windows/native/sun/java2d/opengl/WGLSurfaceData.c	Tue Jul 20 22:21:31 2010 -0700
   101.3 @@ -66,6 +66,10 @@
   101.4  
   101.5      J2dTraceLn(J2D_TRACE_INFO, "WGLSurfaceData_initOps");
   101.6  
   101.7 +    if (oglsdo == NULL) {
   101.8 +        JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
   101.9 +        return;
  101.10 +    }
  101.11      if (wglsdo == NULL) {
  101.12          JNU_ThrowOutOfMemoryError(env, "creating native wgl ops");
  101.13          return;
   102.1 --- a/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.cpp	Thu Jul 15 20:11:45 2010 -0700
   102.2 +++ b/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.cpp	Tue Jul 20 22:21:31 2010 -0700
   102.3 @@ -363,6 +363,10 @@
   102.4  {
   102.5      J2dTraceLn(J2D_TRACE_INFO, "GDIWindowSurfaceData_initOps");
   102.6      GDIWinSDOps *wsdo = (GDIWinSDOps *)SurfaceData_InitOps(env, wsd, sizeof(GDIWinSDOps));
   102.7 +    if (wsdo == NULL) {
   102.8 +        JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
   102.9 +        return;
  102.10 +    }
  102.11      wsdo->sdOps.Lock = GDIWinSD_Lock;
  102.12      wsdo->sdOps.GetRasInfo = GDIWinSD_GetRasInfo;
  102.13      wsdo->sdOps.Unlock = GDIWinSD_Unlock;
   103.1 --- a/src/windows/native/sun/nio/ch/WindowsSelectorImpl.c	Thu Jul 15 20:11:45 2010 -0700
   103.2 +++ b/src/windows/native/sun/nio/ch/WindowsSelectorImpl.c	Tue Jul 20 22:21:31 2010 -0700
   103.3 @@ -214,3 +214,19 @@
   103.4          recv(scinFd, bytes, WAKEUP_SOCKET_BUF_SIZE, 0);
   103.5      }
   103.6  }
   103.7 +
   103.8 +JNIEXPORT jboolean JNICALL
   103.9 +Java_sun_nio_ch_WindowsSelectorImpl_discardUrgentData(JNIEnv* env, jobject this,
  103.10 +                                                      jint s)
  103.11 +{
  103.12 +    char data[8];
  103.13 +    jboolean discarded = JNI_FALSE;
  103.14 +    int n;
  103.15 +    do {
  103.16 +        n = recv(s, &data, sizeof(data), MSG_OOB);
  103.17 +        if (n > 0) {
  103.18 +            discarded = JNI_TRUE;
  103.19 +        }
  103.20 +    } while (n > 0);
  103.21 +    return discarded;
  103.22 +}
   104.1 --- a/test/Makefile	Thu Jul 15 20:11:45 2010 -0700
   104.2 +++ b/test/Makefile	Tue Jul 20 22:21:31 2010 -0700
   104.3 @@ -495,19 +495,17 @@
   104.4  jdk_nio1: java/nio/file
   104.5  	$(call RunSamevmBatch)
   104.6  
   104.7 -# Stable othervm testruns (minus items from PROBLEM_LIST)
   104.8 -#   Using samevm has serious problems with these tests
   104.9 +# Stable samevm testruns (minus items from PROBLEM_LIST)
  104.10  JDK_ALL_TARGETS += jdk_nio2
  104.11  jdk_nio2: java/nio/Buffer java/nio/ByteOrder \
  104.12            java/nio/channels java/nio/BufferPoolMXBean java/nio/MappedByteBuffer
  104.13  	$(call SharedLibraryPermissions,java/nio/channels)
  104.14 -	$(call RunOthervmBatch)
  104.15 +	$(call RunSamevmBatch)
  104.16  
  104.17 -# Stable othervm testruns (minus items from PROBLEM_LIST)
  104.18 -#   Using samevm has serious problems with these tests
  104.19 +# Stable samevm testruns (minus items from PROBLEM_LIST)
  104.20  JDK_ALL_TARGETS += jdk_nio3
  104.21  jdk_nio3: com/sun/nio sun/nio
  104.22 -	$(call RunOthervmBatch)
  104.23 +	$(call RunSamevmBatch)
  104.24  
  104.25  # All nio tests
  104.26  jdk_nio: jdk_nio1 jdk_nio2 jdk_nio3
   105.1 --- a/test/ProblemList.txt	Thu Jul 15 20:11:45 2010 -0700
   105.2 +++ b/test/ProblemList.txt	Tue Jul 20 22:21:31 2010 -0700
   105.3 @@ -295,9 +295,6 @@
   105.4  
   105.5  # jdk_misc
   105.6  
   105.7 -# On Windows com.sun.java.swing.plaf.gtk does not exist, always fails there
   105.8 -com/sun/java/swing/plaf/gtk/Test6635110.java		 	windows-all
   105.9 -
  105.10  # Need to be marked othervm, or changed to be samevm safe
  105.11  com/sun/jndi/ldap/ReadTimeoutTest.java				generic-all
  105.12  com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java	generic-all
  105.13 @@ -379,9 +376,6 @@
  105.14  #   Interrupted or IO exception, maybe writing to non-unique named file?
  105.15  com/sun/net/httpserver/bugs/B6373555.java			generic-all
  105.16  
  105.17 -# Fails on OpenSolaris, BindException unexpected 
  105.18 -java/net/BindException/Test.java				generic-all
  105.19 -
  105.20  # Fails on OpenSolaris, times out
  105.21  java/net/MulticastSocket/SetOutgoingIf.java			generic-all
  105.22  
  105.23 @@ -507,25 +501,46 @@
  105.24  
  105.25  ############################################################################
  105.26  
  105.27 +# jdk_io
  105.28 +
  105.29 +# 6962637
  105.30 +java/io/File/MaxPathLength.java                                 windows-all
  105.31 +
  105.32 +############################################################################
  105.33 +
  105.34  # jdk_nio
  105.35  
  105.36 -# Suspect many of these tests auffer from using fixed ports, no concrete 
  105.37 -#   evidence.
  105.38 +# 6944810
  105.39 +java/nio/channels/FileChannel/ReleaseOnCloseDeadlock.java       windows-all
  105.40  
  105.41 -# Occasionally Failing with java.lang.AssertionError on Windows X64
  105.42 -#  at sun.nio.ch.PendingIoCache.clearPendingIoMap(PendingIoCache.java:144)
  105.43 -#java/nio/channels/FileChannel/ReleaseOnCloseDeadlock.java	windows-all
  105.44 +# 6963118
  105.45 +java/nio/channels/Selector/Wakeup.java                          windows-all
  105.46  
  105.47 -# Some kind of sleep/wake problem on Windows X64
  105.48 -java/nio/channels/Selector/Wakeup.java				windows-all
  105.49 +# The asynchronous I/O implementation on Windows requires Windows XP or newer.
  105.50 +# We can remove the following once all Windows 2000 machines have been
  105.51 +# decommissioned.
  105.52 +java/nio/channels/AsynchronousChannelGroup/Basic.java           windows-5.0
  105.53 +java/nio/channels/AsynchronousChannelGroup/GroupOfOne.java      windows-5.0
  105.54 +java/nio/channels/AsynchronousChannelGroup/Identity.java        windows-5.0
  105.55 +java/nio/channels/AsynchronousChannelGroup/Restart.java         windows-5.0
  105.56 +java/nio/channels/AsynchronousChannelGroup/Unbounded.java       windows-5.0
  105.57 +java/nio/channels/AsynchronousDatagramChannel/Basic.java        windows-5.0
  105.58 +java/nio/channels/AsynchronousFileChannel/Lock.java             windows-5.0
  105.59 +java/nio/channels/AsynchronousServerSocketChannel/Basic.java    windows-5.0
  105.60 +java/nio/channels/AsynchronousServerSocketChannel/WithSecurityManager.java windows-5.0
  105.61 +java/nio/channels/AsynchronousSocketChannel/Basic.java          windows-5.0
  105.62 +java/nio/channels/AsynchronousSocketChannel/DieBeforeComplete.java windows-5.0
  105.63 +java/nio/channels/AsynchronousSocketChannel/Leaky.java          windows-5.0
  105.64 +java/nio/channels/AsynchronousSocketChannel/StressLoopback.java windows-5.0
  105.65 +java/nio/channels/Channels/Basic2.java                          windows-5.0
  105.66 +
  105.67 +# 6959891
  105.68 +com/sun/nio/sctp/SctpChannel/SocketOptionTests.java
  105.69  
  105.70  # Fails with -ea -esa, Assertion error, but only on Solaris 10 machines?
  105.71  com/sun/nio/sctp/SctpChannel/Send.java				generic-all
  105.72  com/sun/nio/sctp/SctpChannel/Shutdown.java			generic-all
  105.73  
  105.74 -# Fails on Windows 2000,  times out
  105.75 -java/nio/channels/FileChannel/Transfer.java			generic-all
  105.76 -
  105.77  # Fails on OpenSolaris, IllegalStateException: Cannot add or remove addresses 
  105.78  #    from a channel that is bound to the wildcard address
  105.79  com/sun/nio/sctp/SctpChannel/Bind.java				generic-all
  105.80 @@ -533,18 +548,6 @@
  105.81  # Failed on OpenSolaris, java.lang.AssertionError: Unknown event type
  105.82  com/sun/nio/sctp/SctpChannel/Receive.java			generic-all
  105.83  
  105.84 -# Triggers a hotspot crash on Fedora 9 32bit -server and Windows X64  samevm
  105.85 -sun/nio/cs/TestUTF8.java					generic-all
  105.86 -
  105.87 -# Runtime exception on windows X64, samevm mode
  105.88 -java/nio/channels/Selector/WakeupNow.java			generic-all
  105.89 -
  105.90 -# Occasional errors, solarix x86, address already in use, othervm mode
  105.91 -java/nio/channels/Selector/SelectorTest.java			generic-all
  105.92 -
  105.93 -# Fails on Linux Fedora 9 X64
  105.94 -sun/nio/cs/FindDecoderBugs.java					generic-all
  105.95 -
  105.96  # Solaris 11 gave assert error and "connection refused", samevm issues?
  105.97  com/sun/nio/sctp/SctpServerChannel/NonBlockingAccept.java 	generic-all
  105.98  
  105.99 @@ -555,49 +558,6 @@
 105.100  com/sun/nio/sctp/SctpMultiChannel/Send.java			generic-all
 105.101  com/sun/nio/sctp/SctpMultiChannel/SocketOptionTests.java	generic-all
 105.102  
 105.103 -# Linux 64bit failures. too many files open
 105.104 -java/nio/channels/Selector/HelperSlowToDie.java			generic-all
 105.105 -
 105.106 -# Gets java.lang.ExceptionInInitializerError on Windows 2000 (need XP or newer)
 105.107 -java/nio/channels/AsynchronousChannelGroup/Basic.java	 	windows-5.0
 105.108 -java/nio/channels/AsynchronousChannelGroup/GroupOfOne.java 	windows-5.0
 105.109 -java/nio/channels/AsynchronousChannelGroup/Identity.java 	windows-5.0
 105.110 -java/nio/channels/AsynchronousChannelGroup/Restart.java 	windows-5.0
 105.111 -java/nio/channels/AsynchronousChannelGroup/Unbounded.java	windows-5.0
 105.112 -java/nio/channels/AsynchronousDatagramChannel/Basic.java 	windows-5.0
 105.113 -java/nio/channels/AsynchronousFileChannel/Lock.java	 	windows-5.0
 105.114 -java/nio/channels/AsynchronousServerSocketChannel/Basic.java 	windows-5.0
 105.115 -java/nio/channels/AsynchronousServerSocketChannel/WithSecurityManager.java windows-5.0
 105.116 -java/nio/channels/AsynchronousSocketChannel/Basic.java	 	windows-5.0
 105.117 -java/nio/channels/AsynchronousSocketChannel/DieBeforeComplete.java windows-5.0
 105.118 -java/nio/channels/AsynchronousSocketChannel/Leaky.java	 	windows-5.0
 105.119 -java/nio/channels/AsynchronousSocketChannel/StressLoopback.java windows-5.0
 105.120 -java/nio/channels/Channels/Basic2.java			 	windows-5.0
 105.121 -
 105.122 -# Failed loopback connection? On windows 32bit? 
 105.123 -#   Considered a stress test, can consume all resources.
 105.124 -java/nio/channels/Selector/LotsOfChannels.java		 	generic-all
 105.125 -
 105.126 -# Windows i586 client, crashed hotspot? Unpredictable
 105.127 -#   Considered a stress test, can consume all resources.
 105.128 -java/nio/channels/Selector/RegAfterPreClose.java	 	generic-all
 105.129 -
 105.130 -# Solaris i586, cannot assign address, samevm issues
 105.131 -java/nio/channels/Selector/SelectorLimit.java		 	generic-all
 105.132 -
 105.133 -# Socket timeout windows X64
 105.134 -java/nio/channels/ServerSocketChannel/AdaptServerSocket.java 	windows-all
 105.135 -
 105.136 -# Timeouts etc. on Window
 105.137 -java/nio/channels/SocketChannel/ConnectState.java	 	windows-all
 105.138 -java/nio/channels/SocketChannel/FinishConnect.java	 	windows-all
 105.139 -
 105.140 -# Fails on all platforms due to overlap of JDK jar file contents:
 105.141 -sun/nio/cs/Test4200310.sh				 	generic-all
 105.142 -
 105.143 -# Depends on motif packages that do not exist all the time:
 105.144 -sun/nio/cs/TestX11CNS.java				 	generic-all
 105.145 -
 105.146  ############################################################################
 105.147  
 105.148  # jdk_rmi
 105.149 @@ -848,9 +808,6 @@
 105.150  
 105.151  # jdk_swing (not using samevm)
 105.152  
 105.153 -# Fails on solaris 10 sparc, throws RuntimeException that just says "failed"
 105.154 -javax/swing/JLabel/6501991/bug6501991.java			generic-all
 105.155 -
 105.156  # Fails on solaris 11 i586, with othervm
 105.157  javax/swing/JFileChooser/6570445/bug6570445.java		generic-all
 105.158  javax/swing/JFileChooser/6738668/bug6738668.java		generic-all
   106.1 --- a/test/com/sun/java/swing/plaf/gtk/Test6635110.java	Thu Jul 15 20:11:45 2010 -0700
   106.2 +++ b/test/com/sun/java/swing/plaf/gtk/Test6635110.java	Tue Jul 20 22:21:31 2010 -0700
   106.3 @@ -28,7 +28,6 @@
   106.4     @run main Test6635110
   106.5  */
   106.6  
   106.7 -import com.sun.java.swing.plaf.gtk.GTKLookAndFeel;
   106.8  import javax.swing.*;
   106.9  import java.awt.*;
  106.10  import java.awt.image.BufferedImage;
  106.11 @@ -59,7 +58,12 @@
  106.12      }
  106.13  
  106.14      public static void main(String[] args) throws Exception {
  106.15 -        UIManager.setLookAndFeel(new GTKLookAndFeel());
  106.16 +        try {
  106.17 +            UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
  106.18 +        } catch (Exception e) {
  106.19 +            System.out.println("GTKLookAndFeel cannot be set, skipping this test");
  106.20 +            return;
  106.21 +        }
  106.22          SwingUtilities.invokeAndWait(new Test6635110());
  106.23      }
  106.24  }
   107.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   107.2 +++ b/test/com/sun/java/swing/plaf/gtk/Test6963870.java	Tue Jul 20 22:21:31 2010 -0700
   107.3 @@ -0,0 +1,72 @@
   107.4 +/*
   107.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   107.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   107.7 + *
   107.8 + * This code is free software; you can redistribute it and/or modify it
   107.9 + * under the terms of the GNU General Public License version 2 only, as
  107.10 + * published by the Free Software Foundation.
  107.11 + *
  107.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  107.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  107.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  107.15 + * version 2 for more details (a copy is included in the LICENSE file that
  107.16 + * accompanied this code).
  107.17 + *
  107.18 + * You should have received a copy of the GNU General Public License version
  107.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  107.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  107.21 + *
  107.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  107.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
  107.24 + * have any questions.
  107.25 + */
  107.26 +
  107.27 +/* @test
  107.28 +   @bug 6963870
  107.29 +   @summary Tests that GTKPainter.ListTableFocusBorder.getBorderInsets()
  107.30 +            doesn't return null
  107.31 +   @author Peter Zhelezniakov
  107.32 +   @run main Test6963870
  107.33 +*/
  107.34 +
  107.35 +import java.awt.Insets;
  107.36 +import javax.swing.SwingUtilities;
  107.37 +import javax.swing.UIManager;
  107.38 +import javax.swing.border.Border;
  107.39 +
  107.40 +public class Test6963870 implements Runnable {
  107.41 +
  107.42 +    final static String[] UI_NAMES = {
  107.43 +        "List.focusCellHighlightBorder",
  107.44 +        "List.focusSelectedCellHighlightBorder",
  107.45 +        "List.noFocusBorder",
  107.46 +        "Table.focusCellHighlightBorder",
  107.47 +        "Table.focusSelectedCellHighlightBorder",
  107.48 +    };
  107.49 +
  107.50 +    public void run() {
  107.51 +        for (String uiName: UI_NAMES) {
  107.52 +            test(uiName);
  107.53 +        }
  107.54 +    }
  107.55 +
  107.56 +    void test(String uiName) {
  107.57 +        Border b = UIManager.getBorder(uiName);
  107.58 +        Insets i = b.getBorderInsets(null);
  107.59 +        if (i == null) {
  107.60 +            throw new RuntimeException("getBorderInsets() returns null for " + uiName);
  107.61 +        }
  107.62 +    }
  107.63 +
  107.64 +    public static void main(String[] args) throws Exception {
  107.65 +        try {
  107.66 +            UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
  107.67 +        } catch (Exception e) {
  107.68 +            System.out.println("GTKLookAndFeel cannot be set, skipping this test");
  107.69 +            return;
  107.70 +        }
  107.71 +
  107.72 +        SwingUtilities.invokeAndWait(new Test6963870());
  107.73 +    }
  107.74 +}
  107.75 +
   108.1 --- a/test/java/awt/EventDispatchThread/HandleExceptionOnEDT/HandleExceptionOnEDT.java	Thu Jul 15 20:11:45 2010 -0700
   108.2 +++ b/test/java/awt/EventDispatchThread/HandleExceptionOnEDT/HandleExceptionOnEDT.java	Tue Jul 20 22:21:31 2010 -0700
   108.3 @@ -1,3 +1,26 @@
   108.4 +/*
   108.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   108.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   108.7 + *
   108.8 + * This code is free software; you can redistribute it and/or modify it
   108.9 + * under the terms of the GNU General Public License version 2 only, as
  108.10 + * published by the Free Software Foundation.
  108.11 + *
  108.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  108.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  108.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  108.15 + * version 2 for more details (a copy is included in the LICENSE file that
  108.16 + * accompanied this code).
  108.17 + *
  108.18 + * You should have received a copy of the GNU General Public License version
  108.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  108.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  108.21 + *
  108.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  108.23 + * or visit www.oracle.com if you need additional information or have any
  108.24 + * questions.
  108.25 + */
  108.26 +
  108.27  /*
  108.28    @test
  108.29    @bug 6304473 6727884
   109.1 --- a/test/java/awt/EventDispatchThread/LoopRobustness/LoopRobustness.java	Thu Jul 15 20:11:45 2010 -0700
   109.2 +++ b/test/java/awt/EventDispatchThread/LoopRobustness/LoopRobustness.java	Tue Jul 20 22:21:31 2010 -0700
   109.3 @@ -34,35 +34,40 @@
   109.4  
   109.5  import java.awt.*;
   109.6  import java.awt.event.*;
   109.7 -import java.lang.Math;
   109.8 +
   109.9 +import sun.awt.SunToolkit;
  109.10 +
  109.11  import test.java.awt.regtesthelpers.Util;
  109.12  
  109.13  public class LoopRobustness {
  109.14 -    static int clicks = 0;
  109.15 +
  109.16      final static long TIMEOUT = 5000;
  109.17      final static Object LOCK = new Object();
  109.18 -    static volatile boolean notifyOccur = false;
  109.19  
  109.20 -    public static void main(String [] args)  {
  109.21 +    public static int clicks = 0;
  109.22 +    public static volatile boolean notifyOccured = false;
  109.23 +    public static volatile boolean otherExceptionsCaught = false;
  109.24 +
  109.25 +    public static void main(String [] args) throws Exception {
  109.26          ThreadGroup mainThreadGroup = Thread.currentThread().getThreadGroup();
  109.27  
  109.28          long at;
  109.29          //wait for a TIMEOUT giving a chance to a new Thread above to accomplish its stuff.
  109.30 -        synchronized (LoopRobustness.LOCK){
  109.31 +        synchronized (LoopRobustness.LOCK) {
  109.32              new Thread(new TestThreadGroup(mainThreadGroup, "TestGroup"), new Impl()).start();
  109.33              at = System.currentTimeMillis();
  109.34              try {
  109.35 -                while(!notifyOccur && System.currentTimeMillis() - at < TIMEOUT) {
  109.36 +                while (!notifyOccured && (System.currentTimeMillis() - at < TIMEOUT)) {
  109.37                      LoopRobustness.LOCK.wait(1000);
  109.38                  }
  109.39 -            } catch(InterruptedException e){
  109.40 +            } catch (InterruptedException e) {
  109.41                  throw new RuntimeException("Test interrupted.", e);
  109.42              }
  109.43          }
  109.44  
  109.45 -        if( !notifyOccur){
  109.46 +        if (!notifyOccured) {
  109.47              //notify doesn't occur after a reasonable time.
  109.48 -            throw new RuntimeException("Test failed. Second Thread didn't notify MainThread.");
  109.49 +            throw new RuntimeException("Test FAILED: second thread hasn't notified MainThread");
  109.50          }
  109.51  
  109.52          //now wait for two clicks
  109.53 @@ -75,7 +80,10 @@
  109.54              }
  109.55          }
  109.56          if (clicks != 2) {
  109.57 -            throw new RuntimeException("robot should press button twice");
  109.58 +            throw new RuntimeException("Test FAILED: robot should press button twice");
  109.59 +        }
  109.60 +        if (otherExceptionsCaught) {
  109.61 +            throw new RuntimeException("Test FAILED: unexpected exceptions caught");
  109.62          }
  109.63      }
  109.64  }
  109.65 @@ -83,18 +91,11 @@
  109.66  class Impl implements Runnable{
  109.67      static Robot robot;
  109.68      public void run() {
  109.69 +        SunToolkit.createNewAppContext();
  109.70 +
  109.71          Button b = new Button("Press me to test the AWT-Event Queue thread");
  109.72          Frame lr = new Frame("ROBUST FRAME");
  109.73 -        /* Must load Toolkit on this thread only, rather then on Main.
  109.74 -           If load on Main (on the parent ThreadGroup of current ThreadGroup) then
  109.75 -           EDT will be created on Main thread and supplied with it's own exceptionHandler,
  109.76 -           which just throws an Exception and terminates current thread.
  109.77 -           The test implies that EDT is created on the child ThreadGroup (testThreadGroup)
  109.78 -           which is supplied with its own uncaughtException().
  109.79 -        */
  109.80 -        Toolkit.getDefaultToolkit();
  109.81          lr.setBounds(100, 100, 300, 100);
  109.82 -
  109.83          b.addActionListener(new ActionListener() {
  109.84                  public void actionPerformed(ActionEvent e) {
  109.85                      LoopRobustness.clicks++;
  109.86 @@ -107,40 +108,46 @@
  109.87  
  109.88          try {
  109.89              robot = new Robot();
  109.90 -        } catch(AWTException e){
  109.91 +        } catch (AWTException e) {
  109.92              throw new RuntimeException("Test interrupted.", e);
  109.93          }
  109.94          Util.waitForIdle(robot);
  109.95  
  109.96          synchronized (LoopRobustness.LOCK){
  109.97              LoopRobustness.LOCK.notify();
  109.98 -            LoopRobustness.notifyOccur = true;
  109.99 +            LoopRobustness.notifyOccured = true;
 109.100          }
 109.101  
 109.102          int i = 0;
 109.103 -        while(i < 2){
 109.104 +        while (i < 2) {
 109.105              robot.mouseMove(b.getLocationOnScreen().x + b.getWidth()/2,
 109.106 -                            b.getLocationOnScreen().y + b.getHeight()/2 );
 109.107 +                            b.getLocationOnScreen().y + b.getHeight()/2);
 109.108 +            Util.waitForIdle(robot);
 109.109              robot.mousePress(InputEvent.BUTTON1_MASK);
 109.110 -            //                robot.delay(10);
 109.111 +            Util.waitForIdle(robot);
 109.112              robot.mouseRelease(InputEvent.BUTTON1_MASK);
 109.113 +            Util.waitForIdle(robot);
 109.114              i++;
 109.115 -            robot.delay(1000);
 109.116          }
 109.117      }
 109.118  }
 109.119  
 109.120  class TestThreadGroup extends ThreadGroup {
 109.121 -    TestThreadGroup(ThreadGroup threadGroup, String name){
 109.122 +    TestThreadGroup(ThreadGroup threadGroup, String name) {
 109.123          super(threadGroup, name);
 109.124      }
 109.125  
 109.126 -    public void uncaughtException(Thread exitedThread, Throwable e) {
 109.127 -        e.printStackTrace();
 109.128 -        if ((e instanceof ExceptionInInitializerError) || (e instanceof
 109.129 -                NoClassDefFoundError)){
 109.130 -            throw new RuntimeException("Test failed: other Exceptions were thrown ", e);
 109.131 +    public void uncaughtException(Thread thread, Throwable e) {
 109.132 +        System.out.println("Exception caught: " + e);
 109.133 +        e.printStackTrace(System.out);
 109.134 +        System.out.flush();
 109.135 +        if ((e instanceof ExceptionInInitializerError) ||
 109.136 +            (e instanceof NoClassDefFoundError))
 109.137 +        {
 109.138 +            // These two are expected
 109.139 +            return;
 109.140          }
 109.141 +        LoopRobustness.otherExceptionsCaught = true;
 109.142      }
 109.143  }
 109.144  
   110.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   110.2 +++ b/test/java/awt/EventDispatchThread/PreserveDispathThread/PreserveDispatchThread.java	Tue Jul 20 22:21:31 2010 -0700
   110.3 @@ -0,0 +1,224 @@
   110.4 +/*
   110.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   110.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   110.7 + *
   110.8 + * This code is free software; you can redistribute it and/or modify it
   110.9 + * under the terms of the GNU General Public License version 2 only, as
  110.10 + * published by the Free Software Foundation.
  110.11 + *
  110.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  110.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  110.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  110.15 + * version 2 for more details (a copy is included in the LICENSE file that
  110.16 + * accompanied this code).
  110.17 + *
  110.18 + * You should have received a copy of the GNU General Public License version
  110.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  110.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  110.21 + *
  110.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  110.23 + * or visit www.oracle.com if you need additional information or have any
  110.24 + * questions.
  110.25 + */
  110.26 +
  110.27 +/*
  110.28 +  @test
  110.29 +  @bug 6424157
  110.30 +  @author Artem Ananiev: area=eventqueue
  110.31 +  @run main PreserveDispatchThread
  110.32 +*/
  110.33 +
  110.34 +import java.awt.*;
  110.35 +import java.awt.event.*;
  110.36 +
  110.37 +public class PreserveDispatchThread {
  110.38 +
  110.39 +    private static volatile Frame f;
  110.40 +    private static volatile Dialog d;
  110.41 +
  110.42 +    private static volatile boolean isEDT = true;
  110.43 +
  110.44 +    public static void main(String[] args) throws Exception {
  110.45 +        f = new Frame("F");
  110.46 +        f.setSize(320, 340);
  110.47 +        f.setLocationRelativeTo(null);
  110.48 +        f.setVisible(true);
  110.49 +
  110.50 +        try {
  110.51 +            test1();
  110.52 +            if (!isEDT) {
  110.53 +                throw new RuntimeException("Test FAILED (test1): event dispatch thread is changed");
  110.54 +            }
  110.55 +
  110.56 +            test2();
  110.57 +            if (!isEDT) {
  110.58 +                throw new RuntimeException("Test FAILED (test2): event dispatch thread is changed");
  110.59 +            }
  110.60 +
  110.61 +            test3();
  110.62 +            if (!isEDT) {
  110.63 +                throw new RuntimeException("Test FAILED (test3): event dispatch thread is changed");
  110.64 +            }
  110.65 +        } finally {
  110.66 +            if (d != null) {
  110.67 +                d.dispose();
  110.68 +            }
  110.69 +            f.dispose();
  110.70 +        }
  110.71 +    }
  110.72 +
  110.73 +    /*
  110.74 +     * Tests that push/pop doesn't change the dispatch thread if
  110.75 +     * called on EDT.
  110.76 +     */
  110.77 +    private static void test1() throws Exception {
  110.78 +        EventQueue.invokeAndWait(new Runnable() {
  110.79 +            @Override
  110.80 +            public void run() {
  110.81 +                TestEventQueue teq = new TestEventQueue();
  110.82 +                EventQueue seq = Toolkit.getDefaultToolkit().getSystemEventQueue();
  110.83 +                try {
  110.84 +                    seq.push(teq);
  110.85 +                    d = new TestDialog();
  110.86 +                    d.setVisible(true);
  110.87 +                    checkEDT();
  110.88 +                } finally {
  110.89 +                    teq.pop();
  110.90 +                }
  110.91 +                checkEDT();
  110.92 +            }
  110.93 +        });
  110.94 +    }
  110.95 +
  110.96 +    /*
  110.97 +     * Tests that push/pop doesn't change the dispatch thread if
  110.98 +     * called on the main thread.
  110.99 +     */
 110.100 +    private static void test2() throws Exception {
 110.101 +        TestEventQueue teq = new TestEventQueue();
 110.102 +        EventQueue seq = Toolkit.getDefaultToolkit().getSystemEventQueue();
 110.103 +        try {
 110.104 +            seq.push(teq);
 110.105 +            EventQueue.invokeAndWait(new Runnable() {
 110.106 +                @Override
 110.107 +                public void run() {
 110.108 +                    checkEDT();
 110.109 +                    d = new TestDialog();
 110.110 +                    d.setVisible(true);
 110.111 +                    checkEDT();
 110.112 +                }
 110.113 +            });
 110.114 +        } finally {
 110.115 +            teq.pop();
 110.116 +        }
 110.117 +    }
 110.118 +
 110.119 +    private static final Object test3Lock = new Object();
 110.120 +    private static boolean test3Sync = false;
 110.121 +
 110.122 +    /*
 110.123 +     * A complex test: several nested invokeLater() are called and
 110.124 +     * in every runnable a check for EDT is performed. At the ent
 110.125 +     * of the test we wait for all the runnables to be processed
 110.126 +     * and the dialog is disposed; otherwise the last EDT check can
 110.127 +     * be later than this method returns and the whole test is passed.
 110.128 +     */
 110.129 +    private static void test3() throws Exception {
 110.130 +        EventQueue.invokeLater(new Runnable() {
 110.131 +            @Override
 110.132 +            public void run() {
 110.133 +                d = new Dialog(f, true);
 110.134 +                d.setSize(240, 180);
 110.135 +                d.setLocationRelativeTo(f);
 110.136 +                EventQueue.invokeLater(new Runnable() {
 110.137 +                    @Override
 110.138 +                    public void run() {
 110.139 +                        d.setVisible(true);
 110.140 +                        checkEDT();
 110.141 +                    }
 110.142 +                });
 110.143 +                EventQueue.invokeLater(new Runnable() {
 110.144 +                    @Override
 110.145 +                    public void run() {
 110.146 +                        TestEventQueue teq = new TestEventQueue();
 110.147 +                        EventQueue seq = Toolkit.getDefaultToolkit().getSystemEventQueue();
 110.148 +                        try {
 110.149 +                            seq.push(teq);
 110.150 +                            checkEDT();
 110.151 +                            EventQueue.invokeLater(new Runnable() {
 110.152 +                                @Override
 110.153 +                                public void run() {
 110.154 +                                    d.dispose();
 110.155 +                                    checkEDT();
 110.156 +                                    synchronized (test3Lock) {
 110.157 +                                        test3Sync = true;
 110.158 +                                        test3Lock.notify();
 110.159 +                                    }
 110.160 +                                }
 110.161 +                            });
 110.162 +                        } finally {
 110.163 +                            teq.pop();
 110.164 +                        }
 110.165 +                        checkEDT();
 110.166 +                    }
 110.167 +                });
 110.168 +                checkEDT();
 110.169 +            }
 110.170 +        });
 110.171 +        synchronized (test3Lock) {
 110.172 +            while (!test3Sync) {
 110.173 +                try {
 110.174 +                    test3Lock.wait();
 110.175 +                } catch (InterruptedException ie) {
 110.176 +                    break;
 110.177 +                }
 110.178 +            }
 110.179 +        }
 110.180 +        // Make sure all the nested invokeLater/invokeAndWait are processed
 110.181 +        EventQueue.invokeAndWait(new Runnable() {
 110.182 +            @Override
 110.183 +            public void run() {
 110.184 +            }
 110.185 +        });
 110.186 +    }
 110.187 +
 110.188 +    private static void checkEDT() {
 110.189 +        isEDT = isEDT && EventQueue.isDispatchThread();
 110.190 +    }
 110.191 +
 110.192 +    private static class TestEventQueue extends EventQueue {
 110.193 +        public TestEventQueue() {
 110.194 +            super();
 110.195 +        }
 110.196 +        public void pop() {
 110.197 +            super.pop();
 110.198 +        }
 110.199 +    }
 110.200 +
 110.201 +    private static class TestDialog extends Dialog {
 110.202 +        private volatile boolean dialogShown = false;
 110.203 +        private volatile boolean paintCalled = false;
 110.204 +        public TestDialog() {
 110.205 +            super(f, true);
 110.206 +            setSize(240, 180);
 110.207 +            setLocationRelativeTo(f);
 110.208 +            addComponentListener(new ComponentAdapter() {
 110.209 +                @Override
 110.210 +                public void componentShown(ComponentEvent e) {
 110.211 +                    if (paintCalled) {
 110.212 +                        dispose();
 110.213 +                    }
 110.214 +                    dialogShown = true;
 110.215 +                }
 110.216 +            });
 110.217 +        }
 110.218 +        @Override
 110.219 +        public void paint(Graphics g) {
 110.220 +            if (dialogShown) {
 110.221 +                dispose();
 110.222 +            }
 110.223 +            paintCalled = true;
 110.224 +        }
 110.225 +    }
 110.226 +
 110.227 +}
   111.1 --- a/test/java/awt/EventQueue/PushPopDeadlock2/PushPopTest.java	Thu Jul 15 20:11:45 2010 -0700
   111.2 +++ b/test/java/awt/EventQueue/PushPopDeadlock2/PushPopTest.java	Tue Jul 20 22:21:31 2010 -0700
   111.3 @@ -43,6 +43,7 @@
   111.4          Runnable dummy = new Runnable() {
   111.5                  public void run() {
   111.6                      System.err.println("Dummy is here.");
   111.7 +                    System.err.flush();
   111.8                  }
   111.9              };
  111.10          EventQueue seq = Toolkit.getDefaultToolkit().getSystemEventQueue();
  111.11 @@ -58,10 +59,11 @@
  111.12          Runnable runnable = new Runnable() {
  111.13                  public void run() {
  111.14                      System.err.println("Dummy from SunToolkit");
  111.15 +                    System.err.flush();
  111.16                  }
  111.17              };
  111.18          InvocationEvent ie = new InvocationEvent(eq2, runnable, null, false);
  111.19 -        System.err.println(ie);
  111.20 +//        System.err.println(ie);
  111.21          SunToolkit.postEvent(SunToolkit.targetToAppContext(frame), ie);
  111.22          eq1.pop();
  111.23          frame.dispose();
  111.24 @@ -70,14 +72,14 @@
  111.25  
  111.26  class MyEventQueue1 extends EventQueue {
  111.27  
  111.28 -    public void pop() throws EmptyStackException {
  111.29 +    public void pop() {
  111.30          super.pop();
  111.31      }
  111.32  }
  111.33  
  111.34  class MyEventQueue2 extends EventQueue {
  111.35  
  111.36 -    protected void pop() throws EmptyStackException {
  111.37 +    protected void pop() {
  111.38          System.err.println("pop2()");
  111.39          Thread.dumpStack();
  111.40          try {
  111.41 @@ -85,7 +87,8 @@
  111.42                      public void run() {
  111.43                          Runnable runnable = new Runnable() {
  111.44                                  public void run() {
  111.45 -                                    System.err.println("Dummy from here");
  111.46 +                                    System.err.println("Dummy from pop");
  111.47 +                                    System.err.flush();
  111.48                                  }
  111.49                               };
  111.50                          InvocationEvent ie = new InvocationEvent(MyEventQueue2.this, runnable, null, false);
   112.1 --- a/test/java/awt/FontClass/FontPrivilege.java	Thu Jul 15 20:11:45 2010 -0700
   112.2 +++ b/test/java/awt/FontClass/FontPrivilege.java	Tue Jul 20 22:21:31 2010 -0700
   112.3 @@ -23,7 +23,7 @@
   112.4  
   112.5  /*
   112.6   * @test
   112.7 - * @bug 5010310 6319835 6904882
   112.8 + * @bug 5010310 6319835 6904882 6968373
   112.9   * @summary test fonts can be created in the presence of a security manager
  112.10   * @run main/othervm/secure=java.lang.SecurityManager FontPrivilege
  112.11   */
   113.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   113.2 +++ b/test/java/beans/Introspector/Test6707234.java	Tue Jul 20 22:21:31 2010 -0700
   113.3 @@ -0,0 +1,52 @@
   113.4 +/*
   113.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   113.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   113.7 + *
   113.8 + * This code is free software; you can redistribute it and/or modify it
   113.9 + * under the terms of the GNU General Public License version 2 only, as
  113.10 + * published by the Free Software Foundation.
  113.11 + *
  113.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  113.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  113.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  113.15 + * version 2 for more details (a copy is included in the LICENSE file that
  113.16 + * accompanied this code).
  113.17 + *
  113.18 + * You should have received a copy of the GNU General Public License version
  113.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  113.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  113.21 + *
  113.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  113.23 + * or visit www.oracle.com if you need additional information or have any
  113.24 + * questions.
  113.25 + */
  113.26 +
  113.27 +/*
  113.28 + * @test
  113.29 + * @bug 6707234
  113.30 + * @summary Tests setter in a complex bean
  113.31 + * @author Sergey Malenkov
  113.32 + */
  113.33 +
  113.34 +public class Test6707234 {
  113.35 +    public static void main(String[] args) {
  113.36 +        if (null == BeanUtils.getPropertyDescriptor(C.class, "number").getWriteMethod()) {
  113.37 +            throw new Error("no write method");
  113.38 +        }
  113.39 +    }
  113.40 +
  113.41 +    public interface I {
  113.42 +        void setNumber(Object number);
  113.43 +        Number getNumber();
  113.44 +    }
  113.45 +
  113.46 +    public class C implements I {
  113.47 +        public void setNumber(Object value) {
  113.48 +        }
  113.49 +        public void setNumber(Long value) {
  113.50 +        }
  113.51 +        public Long getNumber() {
  113.52 +            return null;
  113.53 +        }
  113.54 +    }
  113.55 +}
   114.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   114.2 +++ b/test/java/beans/Introspector/Test6963811.java	Tue Jul 20 22:21:31 2010 -0700
   114.3 @@ -0,0 +1,78 @@
   114.4 +/*
   114.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   114.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   114.7 + *
   114.8 + * This code is free software; you can redistribute it and/or modify it
   114.9 + * under the terms of the GNU General Public License version 2 only, as
  114.10 + * published by the Free Software Foundation.
  114.11 + *
  114.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  114.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  114.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  114.15 + * version 2 for more details (a copy is included in the LICENSE file that
  114.16 + * accompanied this code).
  114.17 + *
  114.18 + * You should have received a copy of the GNU General Public License version
  114.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  114.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  114.21 + *
  114.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  114.23 + * or visit www.oracle.com if you need additional information or have any
  114.24 + * questions.
  114.25 + */
  114.26 +
  114.27 +/*
  114.28 + * @test
  114.29 + * @bug 6963811
  114.30 + * @summary Tests deadlock in Introspector
  114.31 + * @author Sergey Malenkov
  114.32 + */
  114.33 +
  114.34 +import java.beans.Introspector;
  114.35 +import java.beans.SimpleBeanInfo;
  114.36 +
  114.37 +public class Test6963811 implements Runnable {
  114.38 +    private final long time;
  114.39 +    private final boolean sync;
  114.40 +
  114.41 +    public Test6963811(long time, boolean sync) {
  114.42 +        this.time = time;
  114.43 +        this.sync = sync;
  114.44 +    }
  114.45 +
  114.46 +    public void run() {
  114.47 +        try {
  114.48 +            Thread.sleep(this.time); // increase the chance of the deadlock
  114.49 +            Introspector.getBeanInfo(
  114.50 +                    this.sync ? Super.class : Sub.class,
  114.51 +                    this.sync ? null : Object.class);
  114.52 +        }
  114.53 +        catch (Exception exception) {
  114.54 +            exception.printStackTrace();
  114.55 +        }
  114.56 +    }
  114.57 +
  114.58 +    public static void main(String[] args) throws Exception {
  114.59 +        Thread[] threads = new Thread[2];
  114.60 +        for (int i = 0; i < threads.length; i++) {
  114.61 +            threads[i] = new Thread(new Test6963811(0L, i > 0));
  114.62 +            threads[i].start();
  114.63 +            Thread.sleep(500L); // increase the chance of the deadlock
  114.64 +        }
  114.65 +        for (Thread thread : threads) {
  114.66 +            thread.join();
  114.67 +        }
  114.68 +    }
  114.69 +
  114.70 +    public static class Super {
  114.71 +    }
  114.72 +
  114.73 +    public static class Sub extends Super {
  114.74 +    }
  114.75 +
  114.76 +    public static class SubBeanInfo extends SimpleBeanInfo {
  114.77 +        public SubBeanInfo() {
  114.78 +            new Test6963811(1000L, true).run();
  114.79 +        }
  114.80 +    }
  114.81 +}
   115.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   115.2 +++ b/test/java/beans/PropertyEditor/Test6963811.java	Tue Jul 20 22:21:31 2010 -0700
   115.3 @@ -0,0 +1,83 @@
   115.4 +/*
   115.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   115.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   115.7 + *
   115.8 + * This code is free software; you can redistribute it and/or modify it
   115.9 + * under the terms of the GNU General Public License version 2 only, as
  115.10 + * published by the Free Software Foundation.
  115.11 + *
  115.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  115.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  115.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  115.15 + * version 2 for more details (a copy is included in the LICENSE file that
  115.16 + * accompanied this code).
  115.17 + *
  115.18 + * You should have received a copy of the GNU General Public License version
  115.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  115.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  115.21 + *
  115.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  115.23 + * or visit www.oracle.com if you need additional information or have any
  115.24 + * questions.
  115.25 + */
  115.26 +
  115.27 +/*
  115.28 + * @test
  115.29 + * @bug 6963811
  115.30 + * @summary Tests deadlock in PropertyEditorManager
  115.31 + * @author Sergey Malenkov
  115.32 + */
  115.33 +
  115.34 +import java.beans.PropertyEditorManager;
  115.35 +import sun.beans.editors.StringEditor;
  115.36 +
  115.37 +public class Test6963811 implements Runnable {
  115.38 +    private final long time;
  115.39 +    private final boolean sync;
  115.40 +
  115.41 +    public Test6963811(long time, boolean sync) {
  115.42 +        this.time = time;
  115.43 +        this.sync = sync;
  115.44 +    }
  115.45 +
  115.46 +    public void run() {
  115.47 +        try {
  115.48 +            Thread.sleep(this.time); // increase the chance of the deadlock
  115.49 +            if (this.sync) {
  115.50 +                synchronized (Test6963811.class) {
  115.51 +                    PropertyEditorManager.findEditor(Super.class);
  115.52 +                }
  115.53 +            }
  115.54 +            else {
  115.55 +                PropertyEditorManager.findEditor(Sub.class);
  115.56 +            }
  115.57 +        }
  115.58 +        catch (Exception exception) {
  115.59 +            exception.printStackTrace();
  115.60 +        }
  115.61 +    }
  115.62 +
  115.63 +    public static void main(String[] args) throws Exception {
  115.64 +        Thread[] threads = new Thread[2];
  115.65 +        for (int i = 0; i < threads.length; i++) {
  115.66 +            threads[i] = new Thread(new Test6963811(0L, i > 0));
  115.67 +            threads[i].start();
  115.68 +            Thread.sleep(500L); // increase the chance of the deadlock
  115.69 +        }
  115.70 +        for (Thread thread : threads) {
  115.71 +            thread.join();
  115.72 +        }
  115.73 +    }
  115.74 +
  115.75 +    public static class Super {
  115.76 +    }
  115.77 +
  115.78 +    public static class Sub extends Super {
  115.79 +    }
  115.80 +
  115.81 +    public static class SubEditor extends StringEditor {
  115.82 +        public SubEditor() {
  115.83 +            new Test6963811(1000L, true).run();
  115.84 +        }
  115.85 +    }
  115.86 +}
   116.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   116.2 +++ b/test/java/beans/XMLEncoder/Test6963811.java	Tue Jul 20 22:21:31 2010 -0700
   116.3 @@ -0,0 +1,84 @@
   116.4 +/*
   116.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   116.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   116.7 + *
   116.8 + * This code is free software; you can redistribute it and/or modify it
   116.9 + * under the terms of the GNU General Public License version 2 only, as
  116.10 + * published by the Free Software Foundation.
  116.11 + *
  116.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  116.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  116.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  116.15 + * version 2 for more details (a copy is included in the LICENSE file that
  116.16 + * accompanied this code).
  116.17 + *
  116.18 + * You should have received a copy of the GNU General Public License version
  116.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  116.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  116.21 + *
  116.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  116.23 + * or visit www.oracle.com if you need additional information or have any
  116.24 + * questions.
  116.25 + */
  116.26 +
  116.27 +/*
  116.28 + * @test
  116.29 + * @bug 6963811
  116.30 + * @summary Tests deadlock in Encoder
  116.31 + * @author Sergey Malenkov
  116.32 + */
  116.33 +
  116.34 +import java.beans.Encoder;
  116.35 +import java.beans.DefaultPersistenceDelegate;
  116.36 +
  116.37 +public class Test6963811 implements Runnable {
  116.38 +    private static final Encoder ENCODER = new Encoder();
  116.39 +    private final long time;
  116.40 +    private final boolean sync;
  116.41 +
  116.42 +    public Test6963811(long time, boolean sync) {
  116.43 +        this.time = time;
  116.44 +        this.sync = sync;
  116.45 +    }
  116.46 +
  116.47 +    public void run() {
  116.48 +        try {
  116.49 +            Thread.sleep(this.time); // increase the chance of the deadlock
  116.50 +            if (this.sync) {
  116.51 +                synchronized (Test6963811.class) {
  116.52 +                    ENCODER.getPersistenceDelegate(Super.class);
  116.53 +                }
  116.54 +            }
  116.55 +            else {
  116.56 +                ENCODER.getPersistenceDelegate(Sub.class);
  116.57 +            }
  116.58 +        }
  116.59 +        catch (Exception exception) {
  116.60 +            exception.printStackTrace();
  116.61 +        }
  116.62 +    }
  116.63 +
  116.64 +    public static void main(String[] args) throws Exception {
  116.65 +        Thread[] threads = new Thread[2];
  116.66 +        for (int i = 0; i < threads.length; i++) {
  116.67 +            threads[i] = new Thread(new Test6963811(0L, i > 0));
  116.68 +            threads[i].start();
  116.69 +            Thread.sleep(500L); // increase the chance of the deadlock
  116.70 +        }
  116.71 +        for (Thread thread : threads) {
  116.72 +            thread.join();
  116.73 +        }
  116.74 +    }
  116.75 +
  116.76 +    public static class Super {
  116.77 +    }
  116.78 +
  116.79 +    public static class Sub extends Super {
  116.80 +    }
  116.81 +
  116.82 +    public static class SubPersistenceDelegate extends DefaultPersistenceDelegate {
  116.83 +        public SubPersistenceDelegate() {
  116.84 +            new Test6963811(1000L, true).run();
  116.85 +        }
  116.86 +    }
  116.87 +}
   117.1 --- a/test/java/lang/String/Supplementary.java	Thu Jul 15 20:11:45 2010 -0700
   117.2 +++ b/test/java/lang/String/Supplementary.java	Tue Jul 20 22:21:31 2010 -0700
   117.3 @@ -62,7 +62,7 @@
   117.4           0     1     2345     678     9     012     345678     9 01     2     */
   117.5          "\uD800\uDC00!#$\uD800%&\uD800\uDC00;+\uDC00<>;=^\uDC00\\@\uD800\uDC00",
   117.6  
   117.7 -        // includes an undefined supprementary characters in Unicode 4.0.0
   117.8 +        // includes an undefined supplementary character in Unicode 4.0.0
   117.9        /*                                    1     11     1     1111     1
  117.10           0     1     2345     6     789     0     12     3     4567     8     */
  117.11          "\uDB40\uDE00abc\uDE01\uDB40de\uDB40\uDE02f\uDB40\uDE03ghi\uDB40\uDE02",
  117.12 @@ -168,7 +168,7 @@
  117.13       * string in input[m].
  117.14       *
  117.15       * The meaning of each element in golden3[][n]
  117.16 -     *   golden3[][0]: characater which is searched.
  117.17 +     *   golden3[][0]: character which is searched.
  117.18       *   golden3[][2]: the golden data for indexOf(int ch)
  117.19       *   From golden3[][2] to golden3[][n-1]:
  117.20       *       the golden data for indexOf(int ch, int fromIndex)
  117.21 @@ -201,17 +201,17 @@
  117.22              /*
  117.23               * Normal case
  117.24               */
  117.25 -            testIndexOf(First, s, golden3[i][0], golden3[i][2]);
  117.26 +            testIndexOf(s, golden3[i][0], golden3[i][2]);
  117.27  
  117.28              /*
  117.29               * Abnormal case - char which isn't included in the string.
  117.30               */
  117.31 -            testIndexOf(First, s, 'Z', -1);
  117.32 -            testIndexOf(First, s, 0xDB98, -1);
  117.33 -            testIndexOf(First, s, 0xDE76, -1);
  117.34 -            testIndexOf(First, s, 0x12345, -1);
  117.35 -            testIndexOf(First, s, -1, -1);
  117.36 -            testIndexOf(First, s, 0x110000, -1);
  117.37 +            testIndexOf(s, 'Z', -1);
  117.38 +            testIndexOf(s, 0xDB98, -1);
  117.39 +            testIndexOf(s, 0xDE76, -1);
  117.40 +            testIndexOf(s, 0x12345, -1);
  117.41 +            testIndexOf(s, -1, -1);
  117.42 +            testIndexOf(s, 0x110000, -1);
  117.43          }
  117.44      }
  117.45  
  117.46 @@ -229,7 +229,7 @@
  117.47               */
  117.48              int fromIndex = 0;
  117.49              for (int j = 2; j < golden3[i].length; j++) {
  117.50 -                fromIndex = testIndexOf(First, s, fromIndex, ch,
  117.51 +                fromIndex = testIndexOf(s, fromIndex, ch,
  117.52                                          golden3[i][j]) + 1;
  117.53              }
  117.54  
  117.55 @@ -237,19 +237,19 @@
  117.56               * Abnormal case1 - char is included in the string but fromIndex
  117.57               *                  is incorrect.
  117.58               */
  117.59 -            testIndexOf(First, s, -1, ch, golden3[i][2]);
  117.60 -            testIndexOf(First, s, s.length(), ch,
  117.61 +            testIndexOf(s, -1, ch, golden3[i][2]);
  117.62 +            testIndexOf(s, s.length(), ch,
  117.63                          golden3[i][golden3[i].length-1]);
  117.64  
  117.65              /*
  117.66               * Abnormal case2 - char which isn't included in the string.
  117.67               */
  117.68 -            testIndexOf(First, s, 0, 'Z', -1);
  117.69 -            testIndexOf(First, s, 0, 0xDB98, -1);
  117.70 -            testIndexOf(First, s, 0, 0xDE76, -1);
  117.71 -            testIndexOf(First, s, 0, 0x12345, -1);
  117.72 -            testIndexOf(First, s, 0, -1, -1);
  117.73 -            testIndexOf(First, s, 0, 0x110000, -1);
  117.74 +            testIndexOf(s, 0, 'Z', -1);
  117.75 +            testIndexOf(s, 0, 0xDB98, -1);
  117.76 +            testIndexOf(s, 0, 0xDE76, -1);
  117.77 +            testIndexOf(s, 0, 0x12345, -1);
  117.78 +            testIndexOf(s, 0, -1, -1);
  117.79 +            testIndexOf(s, 0, 0x110000, -1);
  117.80          }
  117.81      }
  117.82  
  117.83 @@ -264,18 +264,18 @@
  117.84              /*
  117.85               * Normal case
  117.86               */
  117.87 -            testIndexOf(Last, s, golden3[i][0],
  117.88 +            testLastIndexOf(s, golden3[i][0],
  117.89                          golden3[i][golden3[i].length-2]);
  117.90  
  117.91              /*
  117.92               * Abnormal case - char which isn't included in the string.
  117.93               */
  117.94 -            testIndexOf(Last, s, 'Z', -1);
  117.95 -            testIndexOf(Last, s, 0xDB98, -1);
  117.96 -            testIndexOf(Last, s, 0xDE76, -1);
  117.97 -            testIndexOf(Last, s, 0x12345, -1);
  117.98 -            testIndexOf(Last, s, -1, -1);
  117.99 -            testIndexOf(Last, s, 0x110000, -1);
 117.100 +            testLastIndexOf(s, 'Z', -1);
 117.101 +            testLastIndexOf(s, 0xDB98, -1);
 117.102 +            testLastIndexOf(s, 0xDE76, -1);
 117.103 +            testLastIndexOf(s, 0x12345, -1);
 117.104 +            testLastIndexOf(s, -1, -1);
 117.105 +            testLastIndexOf(s, 0x110000, -1);
 117.106          }
 117.107      }
 117.108  
 117.109 @@ -294,7 +294,7 @@
 117.110               */
 117.111              int fromIndex = len - 1;
 117.112              for (int j = golden3[i].length - 2; j > 0; j--) {
 117.113 -                fromIndex = testIndexOf(Last, s, fromIndex, ch,
 117.114 +                fromIndex = testLastIndexOf(s, fromIndex, ch,
 117.115                                          golden3[i][j]) - 1;
 117.116              }
 117.117  
 117.118 @@ -302,18 +302,18 @@
 117.119               * Abnormal case1 - char is included in the string but fromIndex
 117.120               *                  is incorrect.
 117.121               */
 117.122 -            testIndexOf(Last, s, -1, ch, golden3[i][1]);
 117.123 -            testIndexOf(Last, s, len, ch, golden3[i][golden3[i].length-2]);
 117.124 +            testLastIndexOf(s, -1, ch, golden3[i][1]);
 117.125 +            testLastIndexOf(s, len, ch, golden3[i][golden3[i].length-2]);
 117.126  
 117.127              /*
 117.128               * Abnormal case2 - char which isn't included in the string.
 117.129               */
 117.130 -            testIndexOf(Last, s, len, 'Z', -1);
 117.131 -            testIndexOf(Last, s, len, 0xDB98, -1);
 117.132 -            testIndexOf(Last, s, len, 0xDE76, -1);
 117.133 -            testIndexOf(Last, s, len, 0x12345, -1);
 117.134 -            testIndexOf(Last, s, len, -1, -1);
 117.135 -            testIndexOf(Last, s, len, 0x110000, -1);
 117.136 +            testLastIndexOf(s, len, 'Z', -1);
 117.137 +            testLastIndexOf(s, len, 0xDB98, -1);
 117.138 +            testLastIndexOf(s, len, 0xDE76, -1);
 117.139 +            testLastIndexOf(s, len, 0x12345, -1);
 117.140 +            testLastIndexOf(s, len, -1, -1);
 117.141 +            testLastIndexOf(s, len, 0x110000, -1);
 117.142          }
 117.143      }
 117.144  
 117.145 @@ -471,7 +471,7 @@
 117.146                        result, expected);
 117.147                  result = str.offsetByCodePoints(j, -nCodePoints);
 117.148                  check(result != 0,
 117.149 -                      "offsetBycodePoints(input["+i+"], "+j+", "+(-nCodePoints)+")",
 117.150 +                      "offsetByCodePoints(input["+i+"], "+j+", "+(-nCodePoints)+")",
 117.151                        result, 0);
 117.152              }
 117.153  
 117.154 @@ -531,7 +531,7 @@
 117.155                        result, expected);
 117.156                  result = str.offsetByCodePoints(j, -nCodePoints);
 117.157                  check(result != 0,
 117.158 -                      "offsetBycodePoints(input["+i+"], "+j+", "+(-nCodePoints)+")",
 117.159 +                      "offsetByCodePoints(input["+i+"], "+j+", "+(-nCodePoints)+")",
 117.160                        result, 0);
 117.161              }
 117.162          }
 117.163 @@ -539,7 +539,7 @@
 117.164  
 117.165  
 117.166      static final boolean At = true, Before = false;
 117.167 -    static final boolean First = true, Last = false;
 117.168 +    static final boolean FIRST = true, LAST = false;
 117.169  
 117.170      static void testCodePoint(boolean isAt, String s, int index, int expected) {
 117.171          int c = isAt ? s.codePointAt(index) : s.codePointBefore(index);
 117.172 @@ -563,22 +563,72 @@
 117.173                + s + "> should throw StringIndexOutOfBoundsPointerException.");
 117.174      }
 117.175  
 117.176 -    static void testIndexOf(boolean isFirst, String s, int c, int expected) {
 117.177 -        int index = isFirst ? s.indexOf(c) : s.lastIndexOf(c);
 117.178 +    static void testIndexOf(String s, int c, int expected) {
 117.179 +        testIndexOf2(s, c, expected);
 117.180 +        if (s.indexOf(c) != -1) {
 117.181 +            testIndexOf2(s + (char) c, c, expected);
 117.182 +            if (Character.isSupplementaryCodePoint(c)) {
 117.183 +                char[] surrogates = Character.toChars(c);
 117.184 +                testIndexOf2(s + new String(surrogates), c, expected);
 117.185 +                testIndexOf2(s + surrogates[0], c, expected);
 117.186 +                testIndexOf2(s + surrogates[1], c, expected);
 117.187 +                testIndexOf2(new String(surrogates) + s, c, 0);
 117.188 +                testIndexOf2(surrogates[0] + s, c, expected + 1);
 117.189 +                testIndexOf2(surrogates[1] + s, c, expected + 1);
 117.190 +            }
 117.191 +        }
 117.192 +    }
 117.193 +
 117.194 +    static void testIndexOf2(String s, int c, int expected) {
 117.195 +        int index = s.indexOf(c);
 117.196  
 117.197          check(index != expected,
 117.198 -              (isFirst ? "i" : "lastI") + "ndexOf(" + toHexString(c)
 117.199 -              + ") for <" + s + ">", index, expected);
 117.200 +              "indexOf(" + toHexString(c) + ") for <" + s + ">",
 117.201 +              index, expected);
 117.202      }
 117.203  
 117.204 -    static int testIndexOf(boolean isFirst, String s, int fromIndex, int c,
 117.205 -                           int expected) {
 117.206 -        int index = isFirst ? s.indexOf(c, fromIndex) :
 117.207 -                              s.lastIndexOf(c, fromIndex);
 117.208 +    static void testLastIndexOf(String s, int c, int expected) {
 117.209 +        testLastIndexOf2(s, c, expected);
 117.210 +        if (s.lastIndexOf(c) != -1) {
 117.211 +            testLastIndexOf2((char) c + s, c, expected + 1);
 117.212 +            if (Character.isSupplementaryCodePoint(c)) {
 117.213 +                char[] surrogates = Character.toChars(c);
 117.214 +                testLastIndexOf2(s + new String(surrogates), c, s.length());
 117.215 +                testLastIndexOf2(s + surrogates[0], c, expected);
 117.216 +                testLastIndexOf2(s + surrogates[1], c, expected);
 117.217 +                testLastIndexOf2(new String(surrogates) + s, c, expected + 2);
 117.218 +                testLastIndexOf2(surrogates[0] + s, c, expected + 1);
 117.219 +                testLastIndexOf2(surrogates[1] + s, c, expected + 1);
 117.220 +            }
 117.221 +        }
 117.222 +    }
 117.223 +
 117.224 +    static void testLastIndexOf2(String s, int c, int expected) {
 117.225 +        int index = s.lastIndexOf(c);
 117.226  
 117.227          check(index != expected,
 117.228 -              (isFirst ? "i" : "lastI") + "ndexOf(" + toHexString(c) + ", "
 117.229 -              + fromIndex + ") for <" + s + ">", index, expected);
 117.230 +              "lastIndexOf(" + toHexString(c) + ") for <" + s + ">",
 117.231 +              index, expected);
 117.232 +    }
 117.233 +
 117.234 +    static int testIndexOf(String s, int fromIndex, int c, int expected) {
 117.235 +        int index = s.indexOf(c, fromIndex);
 117.236 +
 117.237 +        check(index != expected,
 117.238 +              "indexOf(" + toHexString(c) + ", "
 117.239 +              + fromIndex + ") for <" + s + ">",
 117.240 +              index, expected);
 117.241 +
 117.242 +        return index;
 117.243 +    }
 117.244 +
 117.245 +    static int testLastIndexOf(String s, int fromIndex, int c, int expected) {
 117.246 +        int index = s.lastIndexOf(c, fromIndex);
 117.247 +
 117.248 +        check(index != expected,
 117.249 +              "lastIndexOf(" + toHexString(c) + ", "
 117.250 +              + fromIndex + ") for <" + s + ">",
 117.251 +              index, expected);
 117.252  
 117.253          return index;
 117.254      }
   118.1 --- a/test/java/lang/StringBuffer/Supplementary.java	Thu Jul 15 20:11:45 2010 -0700
   118.2 +++ b/test/java/lang/StringBuffer/Supplementary.java	Tue Jul 20 22:21:31 2010 -0700
   118.3 @@ -24,7 +24,7 @@
   118.4  /*
   118.5   *
   118.6   * @test
   118.7 - * @bug 4533872 4915683 4985217 5017280
   118.8 + * @bug 4533872 4915683 4985217 5017280 6937112
   118.9   * @summary Unit tests for supplementary character support (JSR-204)
  118.10   */
  118.11  
  118.12 @@ -57,7 +57,7 @@
  118.13           0     1     2345     678     9     012     345678     9 01     2     */
  118.14          "\uD800\uDC00!#$\uD800%&\uD800\uDC00;+\uDC00<>;=^\uDC00\\@\uD800\uDC00",
  118.15  
  118.16 -        // includes an undefined supprementary characters in Unicode 4.0.0
  118.17 +        // includes an undefined supplementary character in Unicode 4.0.0
  118.18        /*                                    1     11     1     1111     1
  118.19           0     1     2345     6     789     0     12     3     4567     8     */
  118.20          "\uDB40\uDE00abc\uDE01\uDB40de\uDB40\uDE02f\uDB40\uDE03ghi\uDB40\uDE02",
  118.21 @@ -151,7 +151,7 @@
  118.22          "\uD800on\uDC00ml\uDC00\uDC00ki9\uD800\uDC00hgfe\uDBFF\uDFFFdcba\uDC00",
  118.23          "\uD800\uDC00@\\\uDC00^=;><\uDC00+;\uD800\uDC00&%\uD800$#!\uD800\uDC00",
  118.24  
  118.25 -        // includes an undefined supprementary characters in Unicode 4.0.0
  118.26 +        // includes an undefined supplementary character in Unicode 4.0.0
  118.27          "\uDB40\uDE02ihg\uDB40\uDE03f\uDB40\uDE02ed\uDB40\uDE01cba\uDB40\uDE00",
  118.28      };
  118.29  
   119.1 --- a/test/java/lang/StringBuilder/Supplementary.java	Thu Jul 15 20:11:45 2010 -0700
   119.2 +++ b/test/java/lang/StringBuilder/Supplementary.java	Tue Jul 20 22:21:31 2010 -0700
   119.3 @@ -57,7 +57,7 @@
   119.4           0     1     2345     678     9     012     345678     9 01     2     */
   119.5          "\uD800\uDC00!#$\uD800%&\uD800\uDC00;+\uDC00<>;=^\uDC00\\@\uD800\uDC00",
   119.6  
   119.7 -        // includes an undefined supprementary characters in Unicode 4.0.0
   119.8 +        // includes an undefined supplementary character in Unicode 4.0.0
   119.9        /*                                    1     11     1     1111     1
  119.10           0     1     2345     6     789     0     12     3     4567     8     */
  119.11          "\uDB40\uDE00abc\uDE01\uDB40de\uDB40\uDE02f\uDB40\uDE03ghi\uDB40\uDE02",
  119.12 @@ -151,7 +151,7 @@
  119.13          "\uD800on\uDC00ml\uDC00\uDC00ki9\uD800\uDC00hgfe\uDBFF\uDFFFdcba\uDC00",
  119.14          "\uD800\uDC00@\\\uDC00^=;><\uDC00+;\uD800\uDC00&%\uD800$#!\uD800\uDC00",
  119.15  
  119.16 -        // includes an undefined supprementary characters in Unicode 4.0.0
  119.17 +        // includes an undefined supplementary character in Unicode 4.0.0
  119.18          "\uDB40\uDE02ihg\uDB40\uDE03f\uDB40\uDE02ed\uDB40\uDE01cba\uDB40\uDE00",
  119.19      };
  119.20  
   120.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   120.2 +++ b/test/java/lang/Throwable/SuppressedExceptions.java	Tue Jul 20 22:21:31 2010 -0700
   120.3 @@ -0,0 +1,165 @@
   120.4 +/*
   120.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   120.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   120.7 + *
   120.8 + * This code is free software; you can redistribute it and/or modify it
   120.9 + * under the terms of the GNU General Public License version 2 only, as
  120.10 + * published by the Free Software Foundation.
  120.11 + *
  120.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  120.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  120.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  120.15 + * version 2 for more details (a copy is included in the LICENSE file that
  120.16 + * accompanied this code).
  120.17 + *
  120.18 + * You should have received a copy of the GNU General Public License version
  120.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  120.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  120.21 + *
  120.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  120.23 + * or visit www.oracle.com if you need additional information or have any
  120.24 + * questions.
  120.25 + */
  120.26 +
  120.27 +import java.io.*;
  120.28 +import java.util.*;
  120.29 +
  120.30 +/*
  120.31 + * @test
  120.32 + * @bug     6911258 6962571
  120.33 + * @summary Basic tests of suppressed exceptions
  120.34 + * @author  Joseph D. Darcy
  120.35 + */
  120.36 +
  120.37 +public class SuppressedExceptions {
  120.38 +    private static String message = "Bad suppressed exception information";
  120.39 +
  120.40 +    public static void main(String... args) throws Exception {
  120.41 +        basicSupressionTest();
  120.42 +        serializationTest();
  120.43 +        selfReference();
  120.44 +    }
  120.45 +
  120.46 +    private static void basicSupressionTest() {
  120.47 +        Throwable throwable = new Throwable();
  120.48 +        RuntimeException suppressed = new RuntimeException("A suppressed exception.");
  120.49 +        AssertionError repressed  = new AssertionError("A repressed error.");
  120.50 +
  120.51 +        Throwable[] t0 = throwable.getSuppressedExceptions();
  120.52 +        if (t0.length != 0) {
  120.53 +            throw new RuntimeException(message);
  120.54 +        }
  120.55 +        throwable.printStackTrace();
  120.56 +
  120.57 +        throwable.addSuppressedException(suppressed);
  120.58 +        Throwable[] t1 = throwable.getSuppressedExceptions();
  120.59 +        if (t1.length != 1 ||
  120.60 +            t1[0] != suppressed) {throw new RuntimeException(message);
  120.61 +        }
  120.62 +        throwable.printStackTrace();
  120.63 +
  120.64 +        throwable.addSuppressedException(repressed);
  120.65 +        Throwable[] t2 = throwable.getSuppressedExceptions();
  120.66 +        if (t2.length != 2 ||
  120.67 +            t2[0] != suppressed ||
  120.68 +            t2[1] != repressed) {
  120.69 +            throw new RuntimeException(message);
  120.70 +        }
  120.71 +        throwable.printStackTrace();
  120.72 +    }
  120.73 +
  120.74 +    private static void serializationTest() throws Exception {
  120.75 +        /*
  120.76 +         * Bytes of the serial form of
  120.77 +         *
  120.78 +         * (new Throwable())setStackTrace(new StackTraceElement[0])
  120.79 +         *
  120.80 +         * from JDK 6; suppressedException field will be missing and
  120.81 +         * thus default to null upon deserialization.
  120.82 +         */
  120.83 +        byte[] bytes = {
  120.84 +            (byte)0xac, (byte)0xed, (byte)0x00, (byte)0x05, (byte)0x73, (byte)0x72, (byte)0x00, (byte)0x13,
  120.85 +            (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e,
  120.86 +            (byte)0x67, (byte)0x2e, (byte)0x54, (byte)0x68, (byte)0x72, (byte)0x6f, (byte)0x77, (byte)0x61,
  120.87 +            (byte)0x62, (byte)0x6c, (byte)0x65, (byte)0xd5, (byte)0xc6, (byte)0x35, (byte)0x27, (byte)0x39,
  120.88 +            (byte)0x77, (byte)0xb8, (byte)0xcb, (byte)0x03, (byte)0x00, (byte)0x03, (byte)0x4c, (byte)0x00,
  120.89 +            (byte)0x05, (byte)0x63, (byte)0x61, (byte)0x75, (byte)0x73, (byte)0x65, (byte)0x74, (byte)0x00,
  120.90 +            (byte)0x15, (byte)0x4c, (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2f, (byte)0x6c,
  120.91 +            (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2f, (byte)0x54, (byte)0x68, (byte)0x72, (byte)0x6f,
  120.92 +            (byte)0x77, (byte)0x61, (byte)0x62, (byte)0x6c, (byte)0x65, (byte)0x3b, (byte)0x4c, (byte)0x00,
  120.93 +            (byte)0x0d, (byte)0x64, (byte)0x65, (byte)0x74, (byte)0x61, (byte)0x69, (byte)0x6c, (byte)0x4d,
  120.94 +            (byte)0x65, (byte)0x73, (byte)0x73, (byte)0x61, (byte)0x67, (byte)0x65, (byte)0x74, (byte)0x00,
  120.95 +            (byte)0x12, (byte)0x4c, (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2f, (byte)0x6c,
  120.96 +            (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2f, (byte)0x53, (byte)0x74, (byte)0x72, (byte)0x69,
  120.97 +            (byte)0x6e, (byte)0x67, (byte)0x3b, (byte)0x5b, (byte)0x00, (byte)0x0a, (byte)0x73, (byte)0x74,
  120.98 +            (byte)0x61, (byte)0x63, (byte)0x6b, (byte)0x54, (byte)0x72, (byte)0x61, (byte)0x63, (byte)0x65,
  120.99 +            (byte)0x74, (byte)0x00, (byte)0x1e, (byte)0x5b, (byte)0x4c, (byte)0x6a, (byte)0x61, (byte)0x76,
 120.100 +            (byte)0x61, (byte)0x2f, (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2f, (byte)0x53,
 120.101 +            (byte)0x74, (byte)0x61, (byte)0x63, (byte)0x6b, (byte)0x54, (byte)0x72, (byte)0x61, (byte)0x63,
 120.102 +            (byte)0x65, (byte)0x45, (byte)0x6c, (byte)0x65, (byte)0x6d, (byte)0x65, (byte)0x6e, (byte)0x74,
 120.103 +            (byte)0x3b, (byte)0x78, (byte)0x70, (byte)0x71, (byte)0x00, (byte)0x7e, (byte)0x00, (byte)0x04,
 120.104 +            (byte)0x70, (byte)0x75, (byte)0x72, (byte)0x00, (byte)0x1e, (byte)0x5b, (byte)0x4c, (byte)0x6a,
 120.105 +            (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67,
 120.106 +            (byte)0x2e, (byte)0x53, (byte)0x74, (byte)0x61, (byte)0x63, (byte)0x6b, (byte)0x54, (byte)0x72,
 120.107 +            (byte)0x61, (byte)0x63, (byte)0x65, (byte)0x45, (byte)0x6c, (byte)0x65, (byte)0x6d, (byte)0x65,
 120.108 +            (byte)0x6e, (byte)0x74, (byte)0x3b, (byte)0x02, (byte)0x46, (byte)0x2a, (byte)0x3c, (byte)0x3c,
 120.109 +            (byte)0xfd, (byte)0x22, (byte)0x39, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70,
 120.110 +            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0xac, (byte)0xed, (byte)0x00,
 120.111 +            (byte)0x05, (byte)0x73, (byte)0x72, (byte)0x00, (byte)0x13, (byte)0x6a, (byte)0x61, (byte)0x76,
 120.112 +            (byte)0x61, (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2e, (byte)0x54,
 120.113 +            (byte)0x68, (byte)0x72, (byte)0x6f, (byte)0x77, (byte)0x61, (byte)0x62, (byte)0x6c, (byte)0x65,
 120.114 +            (byte)0xd5, (byte)0xc6, (byte)0x35, (byte)0x27, (byte)0x39, (byte)0x77, (byte)0xb8, (byte)0xcb,
 120.115 +            (byte)0x03, (byte)0x00, (byte)0x03, (byte)0x4c, (byte)0x00, (byte)0x05, (byte)0x63, (byte)0x61,
 120.116 +            (byte)0x75, (byte)0x73, (byte)0x65, (byte)0x74, (byte)0x00, (byte)0x15, (byte)0x4c, (byte)0x6a,
 120.117 +            (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2f, (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67,
 120.118 +            (byte)0x2f, (byte)0x54, (byte)0x68, (byte)0x72, (byte)0x6f, (byte)0x77, (byte)0x61, (byte)0x62,
 120.119 +            (byte)0x6c, (byte)0x65, (byte)0x3b, (byte)0x4c, (byte)0x00, (byte)0x0d, (byte)0x64, (byte)0x65,
 120.120 +            (byte)0x74, (byte)0x61, (byte)0x69, (byte)0x6c, (byte)0x4d, (byte)0x65, (byte)0x73, (byte)0x73,
 120.121 +            (byte)0x61, (byte)0x67, (byte)0x65, (byte)0x74, (byte)0x00, (byte)0x12, (byte)0x4c, (byte)0x6a,
 120.122 +            (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2f, (byte)0x6c, (byte)0x6e, (byte)0x67, (byte)0x3b,
 120.123 +            (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2f, (byte)0x53, (byte)0x74, (byte)0x72, (byte)0x69,
 120.124 +            (byte)0x5b, (byte)0x00, (byte)0x0a, (byte)0x73, (byte)0x74, (byte)0x61, (byte)0x63, (byte)0x6b,
 120.125 +            (byte)0x54, (byte)0x72, (byte)0x61, (byte)0x63, (byte)0x65, (byte)0x74, (byte)0x00, (byte)0x1e,
 120.126 +            (byte)0x5b, (byte)0x4c, (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2f, (byte)0x6c,
 120.127 +            (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2f, (byte)0x53, (byte)0x74, (byte)0x61, (byte)0x63,
 120.128 +            (byte)0x6b, (byte)0x54, (byte)0x72, (byte)0x61, (byte)0x63, (byte)0x65, (byte)0x45, (byte)0x6c,
 120.129 +            (byte)0x65, (byte)0x6d, (byte)0x65, (byte)0x6e, (byte)0x74, (byte)0x3b, (byte)0x78, (byte)0x70,
 120.130 +            (byte)0x71, (byte)0x00, (byte)0x7e, (byte)0x00, (byte)0x04, (byte)0x70, (byte)0x75, (byte)0x72,
 120.131 +            (byte)0x00, (byte)0x1e, (byte)0x5b, (byte)0x4c, (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61,
 120.132 +            (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2e, (byte)0x53, (byte)0x74,
 120.133 +            (byte)0x61, (byte)0x63, (byte)0x6b, (byte)0x54, (byte)0x72, (byte)0x61, (byte)0x63, (byte)0x65,
 120.134 +            (byte)0x45, (byte)0x6c, (byte)0x65, (byte)0x6d, (byte)0x65, (byte)0x6e, (byte)0x74, (byte)0x3b,
 120.135 +            (byte)0x02, (byte)0x46, (byte)0x2a, (byte)0x3c, (byte)0x3c, (byte)0xfd, (byte)0x22, (byte)0x39,
 120.136 +            (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70,
 120.137 +        };
 120.138 +
 120.139 +        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
 120.140 +        ObjectInputStream ois = new ObjectInputStream(bais);
 120.141 +
 120.142 +        Object o = ois.readObject();
 120.143 +        Throwable throwable = (Throwable) o;
 120.144 +
 120.145 +        System.err.println("TESTING SERIALIZED EXCEPTION");
 120.146 +
 120.147 +        Throwable[] t0 = throwable.getSuppressedExceptions();
 120.148 +        if (t0.length != 0) { // Will fail if t0 is null.
 120.149 +            throw new RuntimeException(message);
 120.150 +        }
 120.151 +        throwable.printStackTrace();
 120.152 +    }
 120.153 +
 120.154 +    private static void selfReference() {
 120.155 +        Throwable throwable1 = new RuntimeException();
 120.156 +        Throwable throwable2 = new AssertionError();
 120.157 +        throwable1.initCause(throwable2);
 120.158 +        throwable2.initCause(throwable1);
 120.159 +
 120.160 +        throwable1.printStackTrace();
 120.161 +
 120.162 +
 120.163 +        throwable1.addSuppressedException(throwable1);
 120.164 +        throwable1.addSuppressedException(throwable2);
 120.165 +
 120.166 +        throwable1.printStackTrace();
 120.167 +    }
 120.168 +}
   121.1 --- a/test/java/net/Authenticator/B4769350.java	Thu Jul 15 20:11:45 2010 -0700
   121.2 +++ b/test/java/net/Authenticator/B4769350.java	Tue Jul 20 22:21:31 2010 -0700
   121.3 @@ -54,6 +54,7 @@
   121.4          boolean allowerror;
   121.5  
   121.6          Client (String authority, String path, boolean allowerror) {
   121.7 +            super("Thread-" + path);
   121.8              this.authority = authority;
   121.9              this.path = path;
  121.10              this.allowerror = allowerror;
  121.11 @@ -72,7 +73,8 @@
  121.12                  error = true;
  121.13              } catch (IOException e) {
  121.14                  if (!allowerror) {
  121.15 -                    System.out.println (e);
  121.16 +                    System.out.println (Thread.currentThread().getName() + " " + e);
  121.17 +                    e.printStackTrace();
  121.18                      error = true;
  121.19                  }
  121.20              }
  121.21 @@ -94,6 +96,7 @@
  121.22          }
  121.23  
  121.24          void okReply (HttpTransaction req) throws IOException {
  121.25 +            req.addResponseHeader ("Connection", "close");
  121.26              req.setResponseEntityBody ("Hello .");
  121.27              req.sendResponse (200, "Ok");
  121.28              req.orderlyClose();
   122.1 --- a/test/java/net/BindException/Test.java	Thu Jul 15 20:11:45 2010 -0700
   122.2 +++ b/test/java/net/BindException/Test.java	Tue Jul 20 22:21:31 2010 -0700
   122.3 @@ -180,7 +180,7 @@
   122.4              while (addrs.hasMoreElements()) {
   122.5                  InetAddress ia = (InetAddress)addrs.nextElement();
   122.6  
   122.7 -                if (ia.isLoopbackAddress()) {
   122.8 +                if (ia.isLoopbackAddress() || ia.isAnyLocalAddress()) {
   122.9                      continue;
  122.10                  }
  122.11  
   123.1 --- a/test/java/net/Inet6Address/B6214234.java	Thu Jul 15 20:11:45 2010 -0700
   123.2 +++ b/test/java/net/Inet6Address/B6214234.java	Tue Jul 20 22:21:31 2010 -0700
   123.3 @@ -23,7 +23,7 @@
   123.4  
   123.5  /**
   123.6   * @test
   123.7 - * @bug 6214234
   123.8 + * @bug 6214234 6967937
   123.9   * @summary IPv6 scope_id for local addresses not set in Solaris 10
  123.10   */
  123.11  
  123.12 @@ -51,6 +51,7 @@
  123.13              return;
  123.14          }
  123.15          if (addr.getScopeId() == 0) {
  123.16 +            System.out.println("addr: "+ addr);
  123.17              throw new RuntimeException ("Non zero scope_id expected");
  123.18          }
  123.19      }
   124.1 --- a/test/java/net/ipv6tests/Tests.java	Thu Jul 15 20:11:45 2010 -0700
   124.2 +++ b/test/java/net/ipv6tests/Tests.java	Tue Jul 20 22:21:31 2010 -0700
   124.3 @@ -248,7 +248,8 @@
   124.4                  }
   124.5                  while (addrs.hasMoreElements()) {
   124.6                      InetAddress addr = (InetAddress) addrs.nextElement();
   124.7 -                    if (filter.isInstance (addr) && !addr.isLoopbackAddress()) {
   124.8 +                    if (filter.isInstance (addr) && !addr.isLoopbackAddress()
   124.9 +                            && !addr.isAnyLocalAddress()) {
  124.10                          if (Arrays.equals (addr.getAddress(), fe80_loopback)) {
  124.11                              continue;
  124.12                          }
   125.1 --- a/test/java/nio/BufferPoolMXBean/Basic.java	Thu Jul 15 20:11:45 2010 -0700
   125.2 +++ b/test/java/nio/BufferPoolMXBean/Basic.java	Tue Jul 20 22:21:31 2010 -0700
   125.3 @@ -24,6 +24,7 @@
   125.4  /* @test
   125.5   * @bug 6606598
   125.6   * @summary Unit test for java.nio.BufferPoolMXBean
   125.7 + * @run main/othervm Basic
   125.8   */
   125.9  
  125.10  import java.nio.ByteBuffer;
   126.1 --- a/test/java/nio/MappedByteBuffer/Basic.java	Thu Jul 15 20:11:45 2010 -0700
   126.2 +++ b/test/java/nio/MappedByteBuffer/Basic.java	Tue Jul 20 22:21:31 2010 -0700
   126.3 @@ -24,6 +24,7 @@
   126.4  /* @test
   126.5   * @bug 4462336
   126.6   * @summary Simple MappedByteBuffer tests
   126.7 + * @run main/othervm Basic
   126.8   */
   126.9  
  126.10  import java.io.*;
   127.1 --- a/test/java/nio/MappedByteBuffer/Force.java	Thu Jul 15 20:11:45 2010 -0700
   127.2 +++ b/test/java/nio/MappedByteBuffer/Force.java	Tue Jul 20 22:21:31 2010 -0700
   127.3 @@ -24,6 +24,7 @@
   127.4  /* @test
   127.5   * @bug 4625907
   127.6   * @summary Testing force()
   127.7 + * @run main/othervm Force
   127.8   */
   127.9  
  127.10  import java.io.*;
   128.1 --- a/test/java/nio/MappedByteBuffer/ZeroMap.java	Thu Jul 15 20:11:45 2010 -0700
   128.2 +++ b/test/java/nio/MappedByteBuffer/ZeroMap.java	Tue Jul 20 22:21:31 2010 -0700
   128.3 @@ -24,6 +24,7 @@
   128.4  /* @test
   128.5   * @bug 4802340
   128.6   * @summary Testing force(), load() isLoaded() of zero len MBB
   128.7 + * @run main/othervm ZeroMap
   128.8   */
   128.9  
  128.10  import java.io.*;
   129.1 --- a/test/java/nio/channels/AsynchronousChannelGroup/GroupOfOne.java	Thu Jul 15 20:11:45 2010 -0700
   129.2 +++ b/test/java/nio/channels/AsynchronousChannelGroup/GroupOfOne.java	Tue Jul 20 22:21:31 2010 -0700
   129.3 @@ -29,6 +29,7 @@
   129.4  import java.nio.ByteBuffer;
   129.5  import java.nio.channels.*;
   129.6  import java.net.*;
   129.7 +import java.util.*;
   129.8  import java.util.concurrent.*;
   129.9  import java.io.IOException;
  129.10  
  129.11 @@ -44,8 +45,12 @@
  129.12          final AsynchronousServerSocketChannel listener =
  129.13              AsynchronousServerSocketChannel.open()
  129.14                  .bind(new InetSocketAddress(0));
  129.15 +        final List<AsynchronousSocketChannel> accepted = new ArrayList<AsynchronousSocketChannel>();
  129.16          listener.accept((Void)null, new CompletionHandler<AsynchronousSocketChannel,Void>() {
  129.17              public void completed(AsynchronousSocketChannel ch, Void att) {
  129.18 +                synchronized (accepted) {
  129.19 +                    accepted.add(ch);
  129.20 +                }
  129.21                  listener.accept((Void)null, this);
  129.22              }
  129.23              public void failed(Throwable exc, Void att) {
  129.24 @@ -58,6 +63,14 @@
  129.25          test(sa, true, false);
  129.26          test(sa, false, true);
  129.27          test(sa, true, true);
  129.28 +
  129.29 +        // clean-up
  129.30 +        listener.close();
  129.31 +        synchronized (accepted) {
  129.32 +            for (AsynchronousSocketChannel ch: accepted) {
  129.33 +                ch.close();
  129.34 +            }
  129.35 +        }
  129.36      }
  129.37  
  129.38      static void test(SocketAddress sa,
   130.1 --- a/test/java/nio/channels/AsynchronousChannelGroup/Identity.java	Thu Jul 15 20:11:45 2010 -0700
   130.2 +++ b/test/java/nio/channels/AsynchronousChannelGroup/Identity.java	Tue Jul 20 22:21:31 2010 -0700
   130.3 @@ -32,6 +32,7 @@
   130.4  import java.util.*;
   130.5  import java.util.concurrent.*;
   130.6  import java.util.concurrent.atomic.*;
   130.7 +import java.io.IOException;
   130.8  
   130.9  /**
  130.10   * Tests that the completion handler is invoked by a thread with
  130.11 @@ -81,14 +82,18 @@
  130.12          listener.accept((Void)null, new CompletionHandler<AsynchronousSocketChannel,Void>() {
  130.13              public void completed(final AsynchronousSocketChannel ch, Void att) {
  130.14                  listener.accept((Void)null, this);
  130.15 -
  130.16                  final ByteBuffer buf = ByteBuffer.allocate(100);
  130.17 -                ch.read(buf, (Void)null, new CompletionHandler<Integer,Void>() {
  130.18 -                    public void completed(Integer bytesRead, Void att) {
  130.19 -                        buf.clear();
  130.20 -                        ch.read(buf, (Void)null, this);
  130.21 +                ch.read(buf, ch, new CompletionHandler<Integer,AsynchronousSocketChannel>() {
  130.22 +                    public void completed(Integer bytesRead, AsynchronousSocketChannel ch) {
  130.23 +                        if (bytesRead < 0) {
  130.24 +                            try { ch.close(); } catch (IOException ignore) { }
  130.25 +                        } else {
  130.26 +                            buf.clear();
  130.27 +                            ch.read(buf, ch, this);
  130.28 +                        }
  130.29                      }
  130.30 -                    public void failed(Throwable exc, Void att) {
  130.31 +                    public void failed(Throwable exc, AsynchronousSocketChannel ch) {
  130.32 +                        try { ch.close(); } catch (IOException ignore) { }
  130.33                      }
  130.34                  });
  130.35              }
  130.36 @@ -100,7 +105,8 @@
  130.37  
  130.38          // create 3-10 channels, each in its own group
  130.39          final int groupCount = 3 + rand.nextInt(8);
  130.40 -        final AsynchronousSocketChannel[] channel = new AsynchronousSocketChannel[groupCount];
  130.41 +        AsynchronousChannelGroup[] groups = new AsynchronousChannelGroup[groupCount];
  130.42 +        final AsynchronousSocketChannel[] channels = new AsynchronousSocketChannel[groupCount];
  130.43          for (int i=0; i<groupCount; i++) {
  130.44              ThreadFactory factory = createThreadFactory(i);
  130.45              AsynchronousChannelGroup group;
  130.46 @@ -111,17 +117,18 @@
  130.47                  ExecutorService pool = Executors.newCachedThreadPool(factory);
  130.48                  group = AsynchronousChannelGroup.withCachedThreadPool(pool, rand.nextInt(5));
  130.49              }
  130.50 +            groups[i] = group;
  130.51  
  130.52              // create channel in group and connect it to the server
  130.53              AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(group);
  130.54              ch.connect(sa).get();
  130.55 -            channel[i] = ch;
  130.56 +            channels[i] = ch;
  130.57          }
  130.58  
  130.59          // randomly write to each channel, ensuring that the completion handler
  130.60          // is always invoked by a thread with the right identity.
  130.61          final AtomicInteger writeCount = new AtomicInteger(100);
  130.62 -        channel[0].write(getBuffer(), 0, new CompletionHandler<Integer,Integer>() {
  130.63 +        channels[0].write(getBuffer(), 0, new CompletionHandler<Integer,Integer>() {
  130.64              public void completed(Integer bytesWritten, Integer groupId) {
  130.65                  if (bytesWritten != 1)
  130.66                      fail("Expected 1 byte to be written");
  130.67 @@ -129,7 +136,7 @@
  130.68                      fail("Handler invoked by thread with the wrong identity");
  130.69                  if (writeCount.decrementAndGet() > 0) {
  130.70                      int id = rand.nextInt(groupCount);
  130.71 -                    channel[id].write(getBuffer(), id, this);
  130.72 +                    channels[id].write(getBuffer(), id, this);
  130.73                  } else {
  130.74                      done.countDown();
  130.75                  }
  130.76 @@ -139,8 +146,16 @@
  130.77              }
  130.78          });
  130.79  
  130.80 -        // wait until
  130.81 +        // wait until done
  130.82          done.await();
  130.83 +
  130.84 +        // clean-up
  130.85 +        for (AsynchronousSocketChannel ch: channels)
  130.86 +            ch.close();
  130.87 +        for (AsynchronousChannelGroup group: groups)
  130.88 +            group.shutdownNow();
  130.89 +        listener.close();
  130.90 +
  130.91          if (failed.get())
  130.92              throw new RuntimeException("Test failed - see log for details");
  130.93      }
   131.1 --- a/test/java/nio/channels/AsynchronousDatagramChannel/Basic.java	Thu Jul 15 20:11:45 2010 -0700
   131.2 +++ b/test/java/nio/channels/AsynchronousDatagramChannel/Basic.java	Tue Jul 20 22:21:31 2010 -0700
   131.3 @@ -371,17 +371,22 @@
   131.4      static void doMulticastTests() throws Exception {
   131.5          final byte[] msg = "hello".getBytes();
   131.6  
   131.7 +        InetAddress lh = InetAddress.getLocalHost();
   131.8 +        NetworkInterface interf = NetworkInterface.getByInetAddress(lh);
   131.9 +        if (interf.isLoopback() || !interf.supportsMulticast()) {
  131.10 +            System.out.println("Multicasting not tested");
  131.11 +            return;
  131.12 +        }
  131.13 +
  131.14          AsynchronousDatagramChannel ch = AsynchronousDatagramChannel
  131.15              .open(StandardProtocolFamily.INET, null)
  131.16              .setOption(StandardSocketOption.SO_REUSEADDR, true)
  131.17              .bind(new InetSocketAddress(0));
  131.18  
  131.19 -        InetAddress lh = InetAddress.getLocalHost();
  131.20          int port = ((InetSocketAddress)(ch.getLocalAddress())).getPort();
  131.21  
  131.22          // join group
  131.23          InetAddress group = InetAddress.getByName("225.4.5.6");
  131.24 -        NetworkInterface interf = NetworkInterface.getByInetAddress(lh);
  131.25          MembershipKey key = ch.join(group, interf);
  131.26  
  131.27          // check key
   132.1 --- a/test/java/nio/channels/AsynchronousFileChannel/Basic.java	Thu Jul 15 20:11:45 2010 -0700
   132.2 +++ b/test/java/nio/channels/AsynchronousFileChannel/Basic.java	Tue Jul 20 22:21:31 2010 -0700
   132.3 @@ -45,16 +45,18 @@
   132.4          File blah = File.createTempFile("blah", null);
   132.5          blah.deleteOnExit();
   132.6  
   132.7 -        final AsynchronousFileChannel ch = AsynchronousFileChannel
   132.8 +        AsynchronousFileChannel ch = AsynchronousFileChannel
   132.9              .open(blah.toPath(), READ, WRITE);
  132.10 +        try {
  132.11 +            // run tests
  132.12 +            testUsingCompletionHandlers(ch);
  132.13 +            testUsingWaitOnResult(ch);
  132.14 +            testInterruptHandlerThread(ch);
  132.15 +        } finally {
  132.16 +            ch.close();
  132.17 +        }
  132.18  
  132.19 -        // run tests
  132.20 -        testUsingCompletionHandlers(ch);
  132.21 -        testUsingWaitOnResult(ch);
  132.22 -        testInterruptHandlerThread(ch);
  132.23 -
  132.24 -        // close channel and invoke test that expects channel to be closed
  132.25 -        ch.close();
  132.26 +        // run test that expects channel to be closed
  132.27          testClosedChannel(ch);
  132.28  
  132.29          // these tests open the file themselves
  132.30 @@ -63,6 +65,9 @@
  132.31          testAsynchronousClose(blah.toPath());
  132.32          testCancel(blah.toPath());
  132.33          testTruncate(blah.toPath());
  132.34 +
  132.35 +        // eagerly clean-up
  132.36 +        blah.delete();
  132.37      }
  132.38  
  132.39      /*
   133.1 --- a/test/java/nio/channels/AsynchronousFileChannel/Lock.java	Thu Jul 15 20:11:45 2010 -0700
   133.2 +++ b/test/java/nio/channels/AsynchronousFileChannel/Lock.java	Tue Jul 20 22:21:31 2010 -0700
   133.3 @@ -53,13 +53,17 @@
   133.4          LockSlaveMirror slave = startLockSlave();
   133.5          try {
   133.6  
   133.7 -             // create temporary file
   133.8 +            // create temporary file
   133.9              File blah = File.createTempFile("blah", null);
  133.10              blah.deleteOnExit();
  133.11  
  133.12 +            // run tests
  133.13              testLockProtocol(blah, slave);
  133.14              testAsyncClose(blah, slave);
  133.15  
  133.16 +            // eagerly clean-up
  133.17 +            blah.delete();
  133.18 +
  133.19          } finally {
  133.20              slave.shutdown();
  133.21          }
  133.22 @@ -150,7 +154,12 @@
  133.23          String sep = FileSystems.getDefault().getSeparator();
  133.24  
  133.25          String command = System.getProperty("java.home") +
  133.26 -            sep + "bin" + sep + "java Lock -lockslave " + port;
  133.27 +            sep + "bin" + sep + "java";
  133.28 +        String testClasses = System.getProperty("test.classes");
  133.29 +        if (testClasses != null)
  133.30 +            command += " -cp " + testClasses;
  133.31 +        command += " Lock -lockslave " + port;
  133.32 +
  133.33          Process p = Runtime.getRuntime().exec(command);
  133.34          IOHandler.handle(p.getInputStream());
  133.35          IOHandler.handle(p.getErrorStream());
   134.1 --- a/test/java/nio/channels/AsynchronousFileChannel/LotsOfWrites.java	Thu Jul 15 20:11:45 2010 -0700
   134.2 +++ b/test/java/nio/channels/AsynchronousFileChannel/LotsOfWrites.java	Tue Jul 20 22:21:31 2010 -0700
   134.3 @@ -135,6 +135,7 @@
   134.4          latch.await();
   134.5  
   134.6          // verify content of each file
   134.7 +        boolean failed = false;
   134.8          byte[] buf = new byte[8192];
   134.9          for (int i=0; i<count ;i++) {
  134.10              Writer writer = writers[i];
  134.11 @@ -145,18 +146,35 @@
  134.12                  int nread = in.read(buf);
  134.13                  while (nread > 0) {
  134.14                      for (int j=0; j<nread; j++) {
  134.15 -                        if (buf[j] != expected)
  134.16 -                            throw new RuntimeException("Unexpected byte");
  134.17 +                        if (buf[j] != expected) {
  134.18 +                            System.err.println("Unexpected contents");
  134.19 +                            failed = true;
  134.20 +                            break;
  134.21 +                        }
  134.22                          expected++;
  134.23                      }
  134.24 +                    if (failed)
  134.25 +                        break;
  134.26                      size += nread;
  134.27                      nread = in.read(buf);
  134.28                  }
  134.29 -                if (size != writer.size())
  134.30 -                    throw new RuntimeException("Unexpected size");
  134.31 +                if (!failed && size != writer.size()) {
  134.32 +                    System.err.println("Unexpected size");
  134.33 +                    failed = true;
  134.34 +                }
  134.35 +                if (failed)
  134.36 +                    break;
  134.37              } finally {
  134.38                  in.close();
  134.39              }
  134.40          }
  134.41 +
  134.42 +        // clean-up
  134.43 +        for (int i=0; i<count; i++) {
  134.44 +            writers[i].file().delete();
  134.45 +        }
  134.46 +
  134.47 +        if (failed)
  134.48 +            throw new RuntimeException("Test failed");
  134.49      }
  134.50  }
   135.1 --- a/test/java/nio/channels/AsynchronousSocketChannel/Basic.java	Thu Jul 15 20:11:45 2010 -0700
   135.2 +++ b/test/java/nio/channels/AsynchronousSocketChannel/Basic.java	Tue Jul 20 22:21:31 2010 -0700
   135.3 @@ -776,6 +776,7 @@
   135.4              throw new RuntimeException("RuntimeException expected after timeout.");
   135.5  
   135.6          ch.close();
   135.7 +        server.close();
   135.8      }
   135.9  
  135.10      // returns ByteBuffer with random bytes
   136.1 --- a/test/java/nio/channels/Channels/Basic2.java	Thu Jul 15 20:11:45 2010 -0700
   136.2 +++ b/test/java/nio/channels/Channels/Basic2.java	Tue Jul 20 22:21:31 2010 -0700
   136.3 @@ -61,6 +61,9 @@
   136.4          writerThread.join();
   136.5          readerThread.join();
   136.6  
   136.7 +        // shutdown listener
   136.8 +        listener.close();
   136.9 +
  136.10          // check that reader received what we expected
  136.11          if (reader.total() != writer.total())
  136.12              throw new RuntimeException("Unexpected number of bytes read");
   137.1 --- a/test/java/nio/channels/Channels/Write.java	Thu Jul 15 20:11:45 2010 -0700
   137.2 +++ b/test/java/nio/channels/Channels/Write.java	Tue Jul 20 22:21:31 2010 -0700
   137.3 @@ -47,5 +47,6 @@
   137.4          out.close();
   137.5          fc.close();
   137.6          fos.close();
   137.7 +        testFile.delete();
   137.8      }
   137.9  }
   138.1 --- a/test/java/nio/channels/DatagramChannel/AdaptDatagramSocket.java	Thu Jul 15 20:11:45 2010 -0700
   138.2 +++ b/test/java/nio/channels/DatagramChannel/AdaptDatagramSocket.java	Tue Jul 20 22:21:31 2010 -0700
   138.3 @@ -82,8 +82,6 @@
   138.4                  }
   138.5                  throw x;
   138.6              }
   138.7 -            if (shouldTimeout)
   138.8 -                throw new Exception("Receive did not time out");
   138.9              break;
  138.10          }
  138.11  
   139.1 --- a/test/java/nio/channels/DatagramChannel/EmptyBuffer.java	Thu Jul 15 20:11:45 2010 -0700
   139.2 +++ b/test/java/nio/channels/DatagramChannel/EmptyBuffer.java	Tue Jul 20 22:21:31 2010 -0700
   139.3 @@ -46,21 +46,25 @@
   139.4          Thread serverThread = new Thread(server);
   139.5          serverThread.start();
   139.6          DatagramChannel dc = DatagramChannel.open();
   139.7 -        ByteBuffer bb = ByteBuffer.allocateDirect(12);
   139.8 -        bb.order(ByteOrder.BIG_ENDIAN);
   139.9 -        bb.putInt(1).putLong(1);
  139.10 -        bb.flip();
  139.11 -        InetAddress address = InetAddress.getLocalHost();
  139.12 -        InetSocketAddress isa = new InetSocketAddress(address, server.port());
  139.13 -        dc.connect(isa);
  139.14 -        dc.write(bb);
  139.15 -        bb.rewind();
  139.16 -        dc.write(bb);
  139.17 -        bb.rewind();
  139.18 -        dc.write(bb);
  139.19 -        Thread.sleep(2000);
  139.20 -        serverThread.interrupt();
  139.21 -        server.throwException();
  139.22 +        try {
  139.23 +            ByteBuffer bb = ByteBuffer.allocateDirect(12);
  139.24 +            bb.order(ByteOrder.BIG_ENDIAN);
  139.25 +            bb.putInt(1).putLong(1);
  139.26 +            bb.flip();
  139.27 +            InetAddress address = InetAddress.getLocalHost();
  139.28 +            InetSocketAddress isa = new InetSocketAddress(address, server.port());
  139.29 +            dc.connect(isa);
  139.30 +            dc.write(bb);
  139.31 +            bb.rewind();
  139.32 +            dc.write(bb);
  139.33 +            bb.rewind();
  139.34 +            dc.write(bb);
  139.35 +            Thread.sleep(2000);
  139.36 +            serverThread.interrupt();
  139.37 +            server.throwException();
  139.38 +        } finally {
  139.39 +            dc.close();
  139.40 +        }
  139.41      }
  139.42  
  139.43      public static class Server implements Runnable {
  139.44 @@ -118,6 +122,8 @@
  139.45                  }
  139.46              } catch (Exception ex) {
  139.47                  e = ex;
  139.48 +            } finally {
  139.49 +                try { dc.close(); } catch (IOException ignore) { }
  139.50              }
  139.51          }
  139.52      }
   140.1 --- a/test/java/nio/channels/DatagramChannel/ReceiveISA.java	Thu Jul 15 20:11:45 2010 -0700
   140.2 +++ b/test/java/nio/channels/DatagramChannel/ReceiveISA.java	Tue Jul 20 22:21:31 2010 -0700
   140.3 @@ -66,6 +66,10 @@
   140.4              rb.clear();
   140.5          }
   140.6  
   140.7 +        dc1.close();
   140.8 +        dc2.close();
   140.9 +        dc3.close();
  140.10 +
  140.11          /*
  140.12           * Check that sa[0] equals sa[1] (both from dc1)
  140.13           * Check that sa[1] not equal to sa[2] (one from dc1, one from dc2)
   141.1 --- a/test/java/nio/channels/DatagramChannel/SelectWhenRefused.java	Thu Jul 15 20:11:45 2010 -0700
   141.2 +++ b/test/java/nio/channels/DatagramChannel/SelectWhenRefused.java	Tue Jul 20 22:21:31 2010 -0700
   141.3 @@ -43,9 +43,9 @@
   141.4          SocketAddress refuser = new InetSocketAddress(InetAddress.getLocalHost(), port);
   141.5  
   141.6          dc = DatagramChannel.open().bind(new InetSocketAddress(0));
   141.7 +        Selector sel = Selector.open();
   141.8          try {
   141.9              dc.configureBlocking(false);
  141.10 -            Selector sel = Selector.open();
  141.11              dc.register(sel, SelectionKey.OP_READ);
  141.12  
  141.13              /* Test 1: not connected so ICMP port unreachable should not be received */
  141.14 @@ -81,6 +81,7 @@
  141.15              }
  141.16  
  141.17          } finally {
  141.18 +            sel.close();
  141.19              dc.close();
  141.20          }
  141.21      }
   142.1 --- a/test/java/nio/channels/FileChannel/Args.java	Thu Jul 15 20:11:45 2010 -0700
   142.2 +++ b/test/java/nio/channels/FileChannel/Args.java	Tue Jul 20 22:21:31 2010 -0700
   142.3 @@ -97,6 +97,8 @@
   142.4                             (long)Integer.MAX_VALUE << 3);
   142.5                  }});
   142.6  
   142.7 +        fc.close();
   142.8 +        f.delete();
   142.9      }
  142.10  
  142.11  }
   143.1 --- a/test/java/nio/channels/FileChannel/ClosedChannelTransfer.java	Thu Jul 15 20:11:45 2010 -0700
   143.2 +++ b/test/java/nio/channels/FileChannel/ClosedChannelTransfer.java	Tue Jul 20 22:21:31 2010 -0700
   143.3 @@ -38,6 +38,7 @@
   143.4          test1(channel);
   143.5          test2(channel);
   143.6          channel.close();
   143.7 +        file.delete();
   143.8      }
   143.9  
  143.10      static void test1(FileChannel channel) throws Exception {
   144.1 --- a/test/java/nio/channels/FileChannel/ExpandingMap.java	Thu Jul 15 20:11:45 2010 -0700
   144.2 +++ b/test/java/nio/channels/FileChannel/ExpandingMap.java	Tue Jul 20 22:21:31 2010 -0700
   144.3 @@ -25,6 +25,7 @@
   144.4   * @bug 4938372 6541641
   144.5   * @summary Flushing dirty pages prior to unmap can cause Cleaner thread to
   144.6   *          abort VM if memory system has pages locked
   144.7 + * @run main/othervm ExpandingMap
   144.8   */
   144.9  import java.io.File;
  144.10  import java.io.RandomAccessFile;
   145.1 --- a/test/java/nio/channels/FileChannel/Lock.java	Thu Jul 15 20:11:45 2010 -0700
   145.2 +++ b/test/java/nio/channels/FileChannel/Lock.java	Tue Jul 20 22:21:31 2010 -0700
   145.3 @@ -55,6 +55,7 @@
   145.4          test2(blah, true);
   145.5          test2(blah, false);
   145.6          test3(blah);
   145.7 +        blah.delete();
   145.8      }
   145.9  
  145.10      private static void test2(File blah, boolean b) throws Exception {
  145.11 @@ -90,7 +91,11 @@
  145.12  
  145.13          // Exec the tamperer
  145.14          String command = System.getProperty("java.home") +
  145.15 -            File.separator + "bin" + File.separator + "java Lock " + str + " " + blah;
  145.16 +            File.separator + "bin" + File.separator + "java";
  145.17 +        String testClasses = System.getProperty("test.classes");
  145.18 +        if (testClasses != null)
  145.19 +            command += " -cp " + testClasses;
  145.20 +        command += " Lock " + str + " " + blah;
  145.21          Process p = Runtime.getRuntime().exec(command);
  145.22  
  145.23          BufferedReader in = new BufferedReader
   146.1 --- a/test/java/nio/channels/FileChannel/MapOverEnd.java	Thu Jul 15 20:11:45 2010 -0700
   146.2 +++ b/test/java/nio/channels/FileChannel/MapOverEnd.java	Tue Jul 20 22:21:31 2010 -0700
   146.3 @@ -24,6 +24,7 @@
   146.4  /* @test
   146.5   * @bug 4463036
   146.6   * @summary Check if file mapping extends beyond end of file
   146.7 + * @run main/othervm MapOverEnd
   146.8   */
   146.9  
  146.10  import java.nio.*;
   147.1 --- a/test/java/nio/channels/FileChannel/MapReadOnly.java	Thu Jul 15 20:11:45 2010 -0700
   147.2 +++ b/test/java/nio/channels/FileChannel/MapReadOnly.java	Tue Jul 20 22:21:31 2010 -0700
   147.3 @@ -24,6 +24,7 @@
   147.4  /* @test
   147.5   * @bug 4510489
   147.6   * @summary Verify IOUtil.java reads to buffer limits
   147.7 + * @run main/othervm MapReadOnly
   147.8   */
   147.9  import java.io.*;
  147.10  import java.nio.*;
   148.1 --- a/test/java/nio/channels/FileChannel/MapTest.java	Thu Jul 15 20:11:45 2010 -0700
   148.2 +++ b/test/java/nio/channels/FileChannel/MapTest.java	Tue Jul 20 22:21:31 2010 -0700
   148.3 @@ -23,6 +23,7 @@
   148.4  
   148.5  /* @test
   148.6   * @summary Test file mapping with FileChannel
   148.7 + * @run main/othervm MapTest
   148.8   */
   148.9  
  148.10  import java.io.*;
   149.1 --- a/test/java/nio/channels/FileChannel/Mode.java	Thu Jul 15 20:11:45 2010 -0700
   149.2 +++ b/test/java/nio/channels/FileChannel/Mode.java	Tue Jul 20 22:21:31 2010 -0700
   149.3 @@ -24,6 +24,7 @@
   149.4  /* @test
   149.5     @bug 4462298
   149.6   * @summary Test FileChannel maps with different accesses
   149.7 + * @run main/othervm Mode
   149.8   */
   149.9  
  149.10  import java.nio.channels.*;
   150.1 --- a/test/java/nio/channels/FileChannel/Position.java	Thu Jul 15 20:11:45 2010 -0700
   150.2 +++ b/test/java/nio/channels/FileChannel/Position.java	Tue Jul 20 22:21:31 2010 -0700
   150.3 @@ -63,6 +63,7 @@
   150.4  
   150.5          c.close();
   150.6          fis.close();
   150.7 +        blah.delete();
   150.8      }
   150.9  
  150.10      /**
   151.1 --- a/test/java/nio/channels/FileChannel/Pread.java	Thu Jul 15 20:11:45 2010 -0700
   151.2 +++ b/test/java/nio/channels/FileChannel/Pread.java	Tue Jul 20 22:21:31 2010 -0700
   151.3 @@ -65,6 +65,9 @@
   151.4              throw new RuntimeException("Expected exception not thrown");
   151.5          } catch(IllegalArgumentException e) {
   151.6              // Correct result
   151.7 +        } finally {
   151.8 +            fc.close();
   151.9 +            blah.delete();
  151.10          }
  151.11      }
  151.12  
  151.13 @@ -73,13 +76,18 @@
  151.14          File blah = File.createTempFile("blah2", null);
  151.15          blah.deleteOnExit();
  151.16          FileOutputStream fos = new FileOutputStream(blah);
  151.17 -        fos.write(new byte[128]);
  151.18 -        FileChannel fc = fos.getChannel();
  151.19          try {
  151.20 -            fc.read(ByteBuffer.allocate(256),1);
  151.21 -            throw new RuntimeException("Expected exception not thrown");
  151.22 -        } catch(NonReadableChannelException e) {
  151.23 -            // Correct result
  151.24 +            fos.write(new byte[128]);
  151.25 +            FileChannel fc = fos.getChannel();
  151.26 +            try {
  151.27 +                fc.read(ByteBuffer.allocate(256),1);
  151.28 +                throw new RuntimeException("Expected exception not thrown");
  151.29 +            } catch(NonReadableChannelException e) {
  151.30 +                // Correct result
  151.31 +            }
  151.32 +        } finally {
  151.33 +            fos.close();
  151.34 +            blah.delete();
  151.35          }
  151.36      }
  151.37  
  151.38 @@ -130,6 +138,7 @@
  151.39  
  151.40          c.close();
  151.41          fis.close();
  151.42 +        blah.delete();
  151.43      }
  151.44  
  151.45      /**
   152.1 --- a/test/java/nio/channels/FileChannel/Pwrite.java	Thu Jul 15 20:11:45 2010 -0700
   152.2 +++ b/test/java/nio/channels/FileChannel/Pwrite.java	Tue Jul 20 22:21:31 2010 -0700
   152.3 @@ -62,6 +62,9 @@
   152.4              throw new RuntimeException("Expected exception not thrown");
   152.5          } catch(NonWritableChannelException e) {
   152.6              // Correct result
   152.7 +        } finally {
   152.8 +            fc.close();
   152.9 +            blah.delete();
  152.10          }
  152.11      }
  152.12  
  152.13 @@ -123,6 +126,7 @@
  152.14          }
  152.15          c.close();
  152.16          raf.close();
  152.17 +        blah.delete();
  152.18      }
  152.19  
  152.20      /**
   153.1 --- a/test/java/nio/channels/FileChannel/Read.java	Thu Jul 15 20:11:45 2010 -0700
   153.2 +++ b/test/java/nio/channels/FileChannel/Read.java	Tue Jul 20 22:21:31 2010 -0700
   153.3 @@ -80,6 +80,7 @@
   153.4  
   153.5          c.close();
   153.6          fis.close();
   153.7 +        blah.delete();
   153.8      }
   153.9  
  153.10      /**
   154.1 --- a/test/java/nio/channels/FileChannel/ReadFull.java	Thu Jul 15 20:11:45 2010 -0700
   154.2 +++ b/test/java/nio/channels/FileChannel/ReadFull.java	Tue Jul 20 22:21:31 2010 -0700
   154.3 @@ -54,5 +54,6 @@
   154.4  
   154.5          fc.close();
   154.6          fis.close();
   154.7 +        blah.delete();
   154.8      }
   154.9  }
   155.1 --- a/test/java/nio/channels/FileChannel/ReadToLimit.java	Thu Jul 15 20:11:45 2010 -0700
   155.2 +++ b/test/java/nio/channels/FileChannel/ReadToLimit.java	Tue Jul 20 22:21:31 2010 -0700
   155.3 @@ -48,6 +48,7 @@
   155.4                  throw new Exception("Test failed");
   155.5          fc.close();
   155.6          fis.close();
   155.7 +        blah.delete();
   155.8      }
   155.9  
  155.10      /**
   156.1 --- a/test/java/nio/channels/FileChannel/ReleaseOnCloseDeadlock.java	Thu Jul 15 20:11:45 2010 -0700
   156.2 +++ b/test/java/nio/channels/FileChannel/ReleaseOnCloseDeadlock.java	Tue Jul 20 22:21:31 2010 -0700
   156.3 @@ -39,8 +39,12 @@
   156.4      public static void main(String[] args) throws IOException {
   156.5          File blah = File.createTempFile("blah", null);
   156.6          blah.deleteOnExit();
   156.7 -        for (int i=0; i<100; i++) {
   156.8 -            test(blah.toPath());
   156.9 +        try {
  156.10 +            for (int i=0; i<100; i++) {
  156.11 +                test(blah.toPath());
  156.12 +            }
  156.13 +        } finally {
  156.14 +            blah.delete();
  156.15          }
  156.16      }
  156.17  
   157.1 --- a/test/java/nio/channels/FileChannel/ScatteringRead.java	Thu Jul 15 20:11:45 2010 -0700
   157.2 +++ b/test/java/nio/channels/FileChannel/ScatteringRead.java	Tue Jul 20 22:21:31 2010 -0700
   157.3 @@ -24,6 +24,7 @@
   157.4  /* @test
   157.5     @bug 4452020 4629048 4638365 4869859
   157.6   * @summary Test FileChannel scattering reads
   157.7 + * @run main/othervm ScatteringRead
   157.8   */
   157.9  
  157.10  import java.nio.channels.*;
   158.1 --- a/test/java/nio/channels/FileChannel/Size.java	Thu Jul 15 20:11:45 2010 -0700
   158.2 +++ b/test/java/nio/channels/FileChannel/Size.java	Tue Jul 20 22:21:31 2010 -0700
   158.3 @@ -24,6 +24,7 @@
   158.4  /* @test
   158.5   * @bug 4563125
   158.6   * @summary Test size method of FileChannel
   158.7 + * @run main/othervm Size
   158.8   */
   158.9  
  158.10  import java.io.*;
   159.1 --- a/test/java/nio/channels/FileChannel/Transfer.java	Thu Jul 15 20:11:45 2010 -0700
   159.2 +++ b/test/java/nio/channels/FileChannel/Transfer.java	Tue Jul 20 22:21:31 2010 -0700
   159.3 @@ -25,7 +25,6 @@
   159.4   * @bug 4434723 4482726 4559072 4638365 4795550 5081340 5103988 6253145
   159.5   * @summary Test FileChannel.transferFrom and transferTo
   159.6   * @library ..
   159.7 - * @run main/timeout=180 Transfer
   159.8   */
   159.9  
  159.10  import java.io.*;
  159.11 @@ -33,6 +32,8 @@
  159.12  import java.nio.*;
  159.13  import java.nio.channels.*;
  159.14  import java.nio.channels.spi.SelectorProvider;
  159.15 +import java.nio.file.StandardOpenOption;
  159.16 +import java.nio.file.FileAlreadyExistsException;
  159.17  import java.util.Random;
  159.18  
  159.19  
  159.20 @@ -96,6 +97,9 @@
  159.21  
  159.22          sourceChannel.close();
  159.23          sinkChannel.close();
  159.24 +
  159.25 +        source.delete();
  159.26 +        sink.delete();
  159.27      }
  159.28  
  159.29      private static void testReadableByteChannel(int size) throws Exception {
  159.30 @@ -139,6 +143,8 @@
  159.31          fc.close();
  159.32          sink.close();
  159.33          source.close();
  159.34 +
  159.35 +        f.delete();
  159.36      }
  159.37  
  159.38      public static void xferTest02() throws Exception {
  159.39 @@ -173,6 +179,9 @@
  159.40          fc2.close();
  159.41          raf1.close();
  159.42          raf2.close();
  159.43 +
  159.44 +        source.delete();
  159.45 +        dest.delete();
  159.46      }
  159.47  
  159.48      public static void xferTest03() throws Exception {
  159.49 @@ -207,6 +216,9 @@
  159.50          fc2.close();
  159.51          raf1.close();
  159.52          raf2.close();
  159.53 +
  159.54 +        source.delete();
  159.55 +        dest.delete();
  159.56      }
  159.57  
  159.58      // Test transferTo with large file
  159.59 @@ -245,27 +257,36 @@
  159.60          sourceChannel.close();
  159.61          sinkChannel.close();
  159.62  
  159.63 +        source.delete();
  159.64 +        sink.delete();
  159.65      }
  159.66  
  159.67      // Test transferFrom with large file
  159.68      public static void xferTest05() throws Exception {
  159.69 -        // Linux can't handle the really large file sizes for a
  159.70 -        // truncate or a positional write
  159.71 -        String osName = System.getProperty("os.name");
  159.72 -        if (osName.startsWith("Linux"))
  159.73 -            return;
  159.74 -
  159.75          // Create a source file & large sink file for the test
  159.76          File source = File.createTempFile("blech", null);
  159.77          source.deleteOnExit();
  159.78          initTestFile(source, 100);
  159.79  
  159.80 -        File sink = File.createTempFile("sink", null);
  159.81 +        // Create the sink file as a sparse file if possible
  159.82 +        File sink = null;
  159.83 +        FileChannel fc = null;
  159.84 +        while (fc == null) {
  159.85 +            sink = File.createTempFile("sink", null);
  159.86 +            // re-create as a sparse file
  159.87 +            sink.toPath().delete();
  159.88 +            try {
  159.89 +                fc = FileChannel.open(sink.toPath(),
  159.90 +                                      StandardOpenOption.CREATE_NEW,
  159.91 +                                      StandardOpenOption.WRITE,
  159.92 +                                      StandardOpenOption.SPARSE);
  159.93 +            } catch (FileAlreadyExistsException ignore) {
  159.94 +                // someone else got it
  159.95 +            }
  159.96 +        }
  159.97          sink.deleteOnExit();
  159.98  
  159.99          long testSize = ((long)Integer.MAX_VALUE) * 2;
 159.100 -        RandomAccessFile raf = new RandomAccessFile(sink, "rw");
 159.101 -        FileChannel fc = raf.getChannel();
 159.102          try {
 159.103              fc.write(ByteBuffer.wrap("Use the source!".getBytes()),
 159.104                       testSize - 40);
 159.105 @@ -275,24 +296,28 @@
 159.106              return;
 159.107          } finally {
 159.108              fc.close();
 159.109 -            raf.close();
 159.110          }
 159.111  
 159.112          // Get new channels for the source and sink and attempt transfer
 159.113 -        FileInputStream fis = new FileInputStream(source);
 159.114 -        FileChannel sourceChannel = fis.getChannel();
 159.115 +        FileChannel sourceChannel = new FileInputStream(source).getChannel();
 159.116 +        try {
 159.117 +            FileChannel sinkChannel = new RandomAccessFile(sink, "rw").getChannel();
 159.118 +            try {
 159.119 +                long bytesWritten = sinkChannel.transferFrom(sourceChannel,
 159.120 +                                                             testSize - 40, 10);
 159.121 +                if (bytesWritten != 10) {
 159.122 +                    throw new RuntimeException("Transfer test 5 failed " +
 159.123 +                                               bytesWritten);
 159.124 +                }
 159.125 +            } finally {
 159.126 +                sinkChannel.close();
 159.127 +            }
 159.128 +        } finally {
 159.129 +            sourceChannel.close();
 159.130 +        }
 159.131  
 159.132 -        raf = new RandomAccessFile(sink, "rw");
 159.133 -        FileChannel sinkChannel = raf.getChannel();
 159.134 -
 159.135 -        long bytesWritten = sinkChannel.transferFrom(sourceChannel,
 159.136 -                                                     testSize - 40, 10);
 159.137 -        if (bytesWritten != 10) {
 159.138 -            throw new RuntimeException("Transfer test 5 failed " +
 159.139 -                                       bytesWritten);
 159.140 -        }
 159.141 -        sourceChannel.close();
 159.142 -        sinkChannel.close();
 159.143 +        source.delete();
 159.144 +        sink.delete();
 159.145      }
 159.146  
 159.147      static void checkFileData(File file, String expected) throws Exception {
 159.148 @@ -338,6 +363,8 @@
 159.149  
 159.150          checkFileData(source, data);
 159.151          checkFileData(sink, data.substring(7,data.length()));
 159.152 +
 159.153 +        source.delete();
 159.154      }
 159.155  
 159.156      // Test transferTo to non-blocking socket channel
 159.157 @@ -371,6 +398,7 @@
 159.158          sink.close();
 159.159          other.close();
 159.160          ssc.close();
 159.161 +        source.delete();
 159.162      }
 159.163  
 159.164  
 159.165 @@ -473,6 +501,7 @@
 159.166              source.close();
 159.167              ssc.close();
 159.168              fc.close();
 159.169 +            file.delete();
 159.170          }
 159.171      }
 159.172  
   160.1 --- a/test/java/nio/channels/FileChannel/TransferToChannel.java	Thu Jul 15 20:11:45 2010 -0700
   160.2 +++ b/test/java/nio/channels/FileChannel/TransferToChannel.java	Tue Jul 20 22:21:31 2010 -0700
   160.3 @@ -51,6 +51,8 @@
   160.4          test1();
   160.5          test2();
   160.6          in.close();
   160.7 +        file.delete();
   160.8 +        outFile.delete();
   160.9      }
  160.10  
  160.11      static void test1() throws Exception {
   161.1 --- a/test/java/nio/channels/FileChannel/TransferToNonWritable.java	Thu Jul 15 20:11:45 2010 -0700
   161.2 +++ b/test/java/nio/channels/FileChannel/TransferToNonWritable.java	Tue Jul 20 22:21:31 2010 -0700
   161.3 @@ -43,6 +43,9 @@
   161.4              throw new RuntimeException("Test failed");
   161.5          } catch (NonWritableChannelException nwce) {
   161.6              // Correct result
   161.7 +        } finally {
   161.8 +            channel.close();
   161.9 +            blah.delete();
  161.10          }
  161.11      }
  161.12  }
   162.1 --- a/test/java/nio/channels/FileChannel/Transfers.java	Thu Jul 15 20:11:45 2010 -0700
   162.2 +++ b/test/java/nio/channels/FileChannel/Transfers.java	Tue Jul 20 22:21:31 2010 -0700
   162.3 @@ -554,6 +554,10 @@
   162.4                  break;
   162.5          }
   162.6  
   162.7 +        sourceFile.delete();
   162.8 +        targetFile.delete();
   162.9 +        fn.delete();
  162.10 +
  162.11          if (failures > 0) {
  162.12              out.println();
  162.13              throw new RuntimeException("Some tests failed");
   163.1 --- a/test/java/nio/channels/FileChannel/TryLock.java	Thu Jul 15 20:11:45 2010 -0700
   163.2 +++ b/test/java/nio/channels/FileChannel/TryLock.java	Tue Jul 20 22:21:31 2010 -0700
   163.3 @@ -56,7 +56,6 @@
   163.4  
   163.5      public static void test1(boolean shared, boolean trylock) throws Exception {
   163.6          File testFile = File.createTempFile("test1", null);
   163.7 -        testFile.deleteOnExit();
   163.8          FileInputStream fis = new FileInputStream(testFile);
   163.9          FileChannel fc = fis.getChannel();
  163.10          FileLock fl = null;
  163.11 @@ -73,12 +72,13 @@
  163.12          } finally {
  163.13              if (fl != null)
  163.14                  fl.release();
  163.15 +            fc.close();
  163.16 +            testFile.delete();
  163.17          }
  163.18      }
  163.19  
  163.20      public static void test2(boolean shared, boolean trylock) throws Exception {
  163.21          File testFile = File.createTempFile("test2", null);
  163.22 -        testFile.deleteOnExit();
  163.23          FileOutputStream fis = new FileOutputStream(testFile);
  163.24          FileChannel fc = fis.getChannel();
  163.25          FileLock fl = null;
  163.26 @@ -95,19 +95,25 @@
  163.27          } finally {
  163.28              if (fl != null)
  163.29                  fl.release();
  163.30 +            fc.close();
  163.31 +            testFile.delete();
  163.32          }
  163.33      }
  163.34  
  163.35      public static void test3(boolean shared, boolean trylock) throws Exception {
  163.36          File testFile = File.createTempFile("test3", null);
  163.37 -        testFile.deleteOnExit();
  163.38          RandomAccessFile fis = new RandomAccessFile(testFile, "rw");
  163.39          FileChannel fc = fis.getChannel();
  163.40 -        FileLock fl = null;
  163.41 -        if (trylock)
  163.42 -            fl = fc.tryLock(0, fc.size(), shared);
  163.43 -        else
  163.44 -            fl = fc.lock(0, fc.size(), shared);
  163.45 -        fl.release();
  163.46 +        try {
  163.47 +            FileLock fl = null;
  163.48 +            if (trylock)
  163.49 +                fl = fc.tryLock(0, fc.size(), shared);
  163.50 +            else
  163.51 +                fl = fc.lock(0, fc.size(), shared);
  163.52 +            fl.release();
  163.53 +        } finally {
  163.54 +            fc.close();
  163.55 +            testFile.delete();
  163.56 +        }
  163.57      }
  163.58  }
   164.1 --- a/test/java/nio/channels/FileChannel/Write.java	Thu Jul 15 20:11:45 2010 -0700
   164.2 +++ b/test/java/nio/channels/FileChannel/Write.java	Tue Jul 20 22:21:31 2010 -0700
   164.3 @@ -25,6 +25,7 @@
   164.4   * @test
   164.5   * @bug 4475533 4698138 4638365 4796221
   164.6   * @summary Test FileChannel write
   164.7 + * @run main/othervm Write
   164.8   */
   164.9  
  164.10  import java.nio.channels.*;
  164.11 @@ -46,23 +47,25 @@
  164.12  
  164.13      // Test to see that offset > length does not throw exception
  164.14      static void test1() throws Exception {
  164.15 -        File testFile = File.createTempFile("test1", null);
  164.16 -        testFile.deleteOnExit();
  164.17 -
  164.18          ByteBuffer[] dsts = new ByteBuffer[4];
  164.19          for (int i=0; i<4; i++)
  164.20              dsts[i] = ByteBuffer.allocateDirect(10);
  164.21  
  164.22 -        FileOutputStream fos = new FileOutputStream(testFile);
  164.23 -        FileChannel fc = fos.getChannel();
  164.24 -        fc.write(dsts, 2, 1);
  164.25 -        fos.close();
  164.26 +        File testFile = File.createTempFile("test1", null);
  164.27 +        try {
  164.28 +            FileOutputStream fos = new FileOutputStream(testFile);
  164.29 +            FileChannel fc = fos.getChannel();
  164.30 +            fc.write(dsts, 2, 1);
  164.31 +            fos.close();
  164.32 +        } finally {
  164.33 +            testFile.delete();
  164.34 +        }
  164.35      }
  164.36  
  164.37      // Test to see that the appropriate buffers are updated
  164.38      static void test2() throws Exception {
  164.39          File testFile = File.createTempFile("test2", null);
  164.40 -        testFile.deleteOnExit();
  164.41 +        testFile.delete();
  164.42          ByteBuffer[] srcs = new ByteBuffer[4];
  164.43          for (int i=0; i<4; i++)
  164.44              srcs[i] = ByteBuffer.allocateDirect(10);
  164.45 @@ -74,25 +77,34 @@
  164.46  
  164.47          FileOutputStream fos = new FileOutputStream(testFile);
  164.48          FileChannel fc = fos.getChannel();
  164.49 -        fc.write(srcs, 1, 2);
  164.50 -        fos.close();
  164.51 +        try {
  164.52 +            fc.write(srcs, 1, 2);
  164.53 +        } finally {
  164.54 +            fc.close();
  164.55 +        }
  164.56  
  164.57          FileInputStream fis = new FileInputStream(testFile);
  164.58          fc = fis.getChannel();
  164.59 -        ByteBuffer bb = ByteBuffer.allocateDirect(10);
  164.60 -        fc.read(bb);
  164.61 -        bb.flip();
  164.62 -        if (bb.get() != 2)
  164.63 -            throw new RuntimeException("Write failure");
  164.64 -        if (bb.get() != 3)
  164.65 -            throw new RuntimeException("Write failure");
  164.66          try {
  164.67 -            bb.get();
  164.68 -            throw new RuntimeException("Write failure");
  164.69 -        } catch (BufferUnderflowException bufe) {
  164.70 -            // correct result
  164.71 +            ByteBuffer bb = ByteBuffer.allocateDirect(10);
  164.72 +            fc.read(bb);
  164.73 +            bb.flip();
  164.74 +            if (bb.get() != 2)
  164.75 +                throw new RuntimeException("Write failure");
  164.76 +            if (bb.get() != 3)
  164.77 +                throw new RuntimeException("Write failure");
  164.78 +            try {
  164.79 +                bb.get();
  164.80 +                throw new RuntimeException("Write failure");
  164.81 +            } catch (BufferUnderflowException bufe) {
  164.82 +                // correct result
  164.83 +            }
  164.84 +        } finally {
  164.85 +            fc.close();
  164.86          }
  164.87 -        fis.close();
  164.88 +
  164.89 +        // eagerly clean-up
  164.90 +        testFile.delete();
  164.91      }
  164.92  
  164.93      // Test write to a negative position (bug 4698138).
   165.1 --- a/test/java/nio/channels/Pipe/NonBlocking.java	Thu Jul 15 20:11:45 2010 -0700
   165.2 +++ b/test/java/nio/channels/Pipe/NonBlocking.java	Tue Jul 20 22:21:31 2010 -0700
   165.3 @@ -41,12 +41,17 @@
   165.4  
   165.5      static void test1() throws Exception {
   165.6          Pipe p = Pipe.open();
   165.7 -        p.sink().configureBlocking(false);
   165.8 -        if (p.sink().isBlocking())
   165.9 -            throw new Exception("Sink still blocking");
  165.10 -        p.source().configureBlocking(false);
  165.11 -        if (p.source().isBlocking())
  165.12 -            throw new Exception("Source still blocking");
  165.13 +        try {
  165.14 +            p.sink().configureBlocking(false);
  165.15 +            if (p.sink().isBlocking())
  165.16 +                throw new Exception("Sink still blocking");
  165.17 +            p.source().configureBlocking(false);
  165.18 +            if (p.source().isBlocking())
  165.19 +                throw new Exception("Source still blocking");
  165.20 +        } finally {
  165.21 +            p.sink().close();
  165.22 +            p.source().close();
  165.23 +        }
  165.24      }
  165.25  
  165.26  }
   166.1 --- a/test/java/nio/channels/Pipe/SelectPipe.java	Thu Jul 15 20:11:45 2010 -0700
   166.2 +++ b/test/java/nio/channels/Pipe/SelectPipe.java	Tue Jul 20 22:21:31 2010 -0700
   166.3 @@ -78,10 +78,12 @@
   166.4                  totalRead += bytesRead;
   166.5          } while(totalRead < 10);
   166.6  
   166.7 +        sink.close();
   166.8 +        source.close();
   166.9 +        selector.close();
  166.10 +
  166.11          for(int i=0; i<10; i++)
  166.12              if (outgoingdata.get(i) != incomingdata.get(i))
  166.13                  throw new Exception("Pipe failed");
  166.14 -        sink.close();
  166.15 -        source.close();
  166.16      }
  166.17  }
   167.1 --- a/test/java/nio/channels/SelectionKey/AtomicAttachTest.java	Thu Jul 15 20:11:45 2010 -0700
   167.2 +++ b/test/java/nio/channels/SelectionKey/AtomicAttachTest.java	Tue Jul 20 22:21:31 2010 -0700
   167.3 @@ -58,6 +58,11 @@
   167.4          };
   167.5  
   167.6          t.join();
   167.7 +
   167.8 +        pipe.sink().close();
   167.9 +        pipe.source().close();
  167.10 +        selector.close();
  167.11 +
  167.12          int count = errorCount.get();
  167.13          if (count > 0) {
  167.14              throw new RuntimeException("Error count:" + count);
   168.1 --- a/test/java/nio/channels/Selector/BasicAccept.java	Thu Jul 15 20:11:45 2010 -0700
   168.2 +++ b/test/java/nio/channels/Selector/BasicAccept.java	Tue Jul 20 22:21:31 2010 -0700
   168.3 @@ -36,49 +36,60 @@
   168.4  
   168.5  public class BasicAccept {
   168.6  
   168.7 -    public static int TEST_PORT = 40170;
   168.8 +    static void server(ServerSocketChannel ssc) throws Exception {
   168.9 +        Selector acceptSelector = Selector.open();
  168.10 +        try {
  168.11 +            ssc.configureBlocking(false);
  168.12 +            SelectionKey acceptKey
  168.13 +                = ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
  168.14 +            for (;;) {
  168.15 +                int n = acceptSelector.select();
  168.16 +                if (Thread.interrupted())
  168.17 +                    break;
  168.18 +                if (n == 0)
  168.19 +                    continue;
  168.20 +                Set<SelectionKey> readyKeys = acceptSelector.selectedKeys();
  168.21 +                Iterator<SelectionKey> i = readyKeys.iterator();
  168.22 +                while (i.hasNext()) {
  168.23 +                    SelectionKey sk = i.next();
  168.24 +                    i.remove();
  168.25 +                    ServerSocketChannel nextReady
  168.26 +                        = (ServerSocketChannel)sk.channel();
  168.27 +                    SocketChannel sc = nextReady.accept();
  168.28 +                    ByteBuffer bb = ByteBuffer.wrap(new byte[] { 42 });
  168.29 +                    sc.write(bb);
  168.30 +                    sc.close();
  168.31 +                }
  168.32 +            }
  168.33 +        } finally {
  168.34 +            acceptSelector.close();
  168.35 +        }
  168.36 +    }
  168.37  
  168.38 -    static void server() throws Exception {
  168.39 -        Selector acceptSelector = Selector.open();
  168.40 -        ServerSocketChannel ssc = ServerSocketChannel.open();
  168.41 -        ssc.configureBlocking(false);
  168.42 -        InetAddress lh = InetAddress.getLocalHost();
  168.43 -        InetSocketAddress isa
  168.44 -            = new InetSocketAddress(lh, SelectorTest.TEST_PORT);
  168.45 -        ssc.socket().bind(isa);
  168.46 -        SelectionKey acceptKey
  168.47 -            = ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
  168.48 -        for (;;) {
  168.49 -            if (acceptSelector.select() == 0)
  168.50 -                continue;
  168.51 -            Set readyKeys = acceptSelector.selectedKeys();
  168.52 -            Iterator i = readyKeys.iterator();
  168.53 -            while (i.hasNext()) {
  168.54 -                SelectionKey sk = (SelectionKey)i.next();
  168.55 -                i.remove();
  168.56 -                ServerSocketChannel nextReady
  168.57 -                    = (ServerSocketChannel)sk.channel();
  168.58 -                SocketChannel sc = nextReady.accept();
  168.59 -                ByteBuffer bb = ByteBuffer.wrap(new byte[] { 42 });
  168.60 -                sc.write(bb);
  168.61 +    private static class Server extends TestThread {
  168.62 +        final ServerSocketChannel ssc;
  168.63 +        Server() throws IOException {
  168.64 +            super("Server", System.err);
  168.65 +            this.ssc = ServerSocketChannel.open()
  168.66 +                .bind(new InetSocketAddress(0));
  168.67 +        }
  168.68 +        int port() {
  168.69 +            return ssc.socket().getLocalPort();
  168.70 +        }
  168.71 +        void go() throws Exception {
  168.72 +            try {
  168.73 +                server(ssc);
  168.74 +            } finally {
  168.75 +                ssc.close();
  168.76              }
  168.77          }
  168.78      }
  168.79  
  168.80 -    private static class Server extends TestThread {
  168.81 -        Server() {
  168.82 -            super("Server", System.err);
  168.83 -        }
  168.84 -        void go() throws Exception {
  168.85 -            server();
  168.86 -        }
  168.87 -    }
  168.88 -
  168.89 -    static void client() throws Exception {
  168.90 +    static void client(int port) throws Exception {
  168.91          // Get a connection from the server
  168.92          InetAddress lh = InetAddress.getLocalHost();
  168.93          InetSocketAddress isa
  168.94 -            = new InetSocketAddress(lh, SelectorTest.TEST_PORT);
  168.95 +            = new InetSocketAddress(lh, port);
  168.96          int connectFailures = 0;
  168.97          boolean result = false;
  168.98          SocketChannel sc = SocketChannel.open();
  168.99 @@ -122,17 +133,17 @@
 168.100          if (bb.get(0) != 42)
 168.101              throw new RuntimeException("Read wrong byte from server");
 168.102          System.err.println("Read from server");
 168.103 +        sc.close();
 168.104      }
 168.105  
 168.106      public static void main(String[] args) throws Exception {
 168.107 -        if (args.length == 0) {
 168.108 -            Server server = new Server();
 168.109 -            server.start();
 168.110 -            client();
 168.111 -        } else if (args[0].equals("client")) {
 168.112 -            client();
 168.113 -        } else if (args[0].equals("server")) {
 168.114 -            server();
 168.115 +        Server server = new Server();
 168.116 +        server.start();
 168.117 +        try {
 168.118 +            client(server.port());
 168.119 +        } finally {
 168.120 +            server.interrupt();
 168.121 +            server.finish(2000);
 168.122          }
 168.123      }
 168.124  
   169.1 --- a/test/java/nio/channels/Selector/BasicConnect.java	Thu Jul 15 20:11:45 2010 -0700
   169.2 +++ b/test/java/nio/channels/Selector/BasicConnect.java	Tue Jul 20 22:21:31 2010 -0700
   169.3 @@ -83,10 +83,13 @@
   169.4          ByteBuffer bb2 = ByteBuffer.allocateDirect(100);
   169.5          int n = sc.read(bb2);
   169.6          bb2.flip();
   169.7 +
   169.8 +        sc.close();
   169.9 +        connectSelector.close();
  169.10 +
  169.11          if (!bb.equals(bb2))
  169.12              throw new Exception("Echoed bytes incorrect: Sent "
  169.13                                  + bb + ", got " + bb2);
  169.14 -        sc.close();
  169.15      }
  169.16  
  169.17  }
   170.1 --- a/test/java/nio/channels/Selector/CheckLocking.java	Thu Jul 15 20:11:45 2010 -0700
   170.2 +++ b/test/java/nio/channels/Selector/CheckLocking.java	Tue Jul 20 22:21:31 2010 -0700
   170.3 @@ -61,5 +61,7 @@
   170.4          doSelect();
   170.5          sk.interestOps(SelectionKey.OP_READ);
   170.6          selector.wakeup();
   170.7 +        sc.close();
   170.8 +        selector.close();
   170.9      }
  170.10  }
   171.1 --- a/test/java/nio/channels/Selector/CloseInvalidatesKeys.java	Thu Jul 15 20:11:45 2010 -0700
   171.2 +++ b/test/java/nio/channels/Selector/CloseInvalidatesKeys.java	Tue Jul 20 22:21:31 2010 -0700
   171.3 @@ -33,12 +33,16 @@
   171.4  
   171.5      public static void main (String [] args) throws Exception {
   171.6          DatagramChannel ch = DatagramChannel.open();
   171.7 -        ch.configureBlocking(false);
   171.8 -        Selector sel = Selector.open();
   171.9 -        SelectionKey key = ch.register(sel, SelectionKey.OP_WRITE);
  171.10 -        sel.close();
  171.11 -        if (key.isValid())
  171.12 -            throw new Exception("Key valid after selector closed");
  171.13 +        try {
  171.14 +            ch.configureBlocking(false);
  171.15 +            Selector sel = Selector.open();
  171.16 +            SelectionKey key = ch.register(sel, SelectionKey.OP_WRITE);
  171.17 +            sel.close();
  171.18 +            if (key.isValid())
  171.19 +                throw new Exception("Key valid after selector closed");
  171.20 +        } finally {
  171.21 +            ch.close();
  171.22 +        }
  171.23      }
  171.24  
  171.25  }
   172.1 --- a/test/java/nio/channels/Selector/CloseWhenKeyIdle.java	Thu Jul 15 20:11:45 2010 -0700
   172.2 +++ b/test/java/nio/channels/Selector/CloseWhenKeyIdle.java	Tue Jul 20 22:21:31 2010 -0700
   172.3 @@ -111,10 +111,14 @@
   172.4          // select should block
   172.5  
   172.6          int spinCount = 0;
   172.7 +        boolean failed = false;
   172.8          for (;;) {
   172.9              int n = sel.select();
  172.10 -            if (n > 0)
  172.11 -                throw new RuntimeException("channel should not be selected");
  172.12 +            if (n > 0) {
  172.13 +                System.err.println("Channel should not be selected!!!");
  172.14 +                failed = true;
  172.15 +                break;
  172.16 +            }
  172.17  
  172.18              // wakeup
  172.19              if (wakeupDone)
  172.20 @@ -123,10 +127,19 @@
  172.21              // wakeup for no reason - if it happens a few times then we have a
  172.22              // problem
  172.23              spinCount++;
  172.24 -            if (spinCount >= 3)
  172.25 -                throw new RuntimeException("Selector appears to be spinning");
  172.26 +            if (spinCount >= 3) {
  172.27 +                System.err.println("Selector appears to be spinning");
  172.28 +                failed = true;
  172.29 +                break;
  172.30 +            }
  172.31          }
  172.32  
  172.33 +        sc1.close();
  172.34 +        sel.close();
  172.35 +
  172.36 +        if (failed)
  172.37 +            throw new RuntimeException("Test failed");
  172.38 +
  172.39          System.out.println("PASS");
  172.40      }
  172.41  
   173.1 --- a/test/java/nio/channels/Selector/Connect.java	Thu Jul 15 20:11:45 2010 -0700
   173.2 +++ b/test/java/nio/channels/Selector/Connect.java	Tue Jul 20 22:21:31 2010 -0700
   173.3 @@ -25,7 +25,6 @@
   173.4   * @bug 4511624
   173.5   * @summary Test Making lots of Selectors
   173.6   * @library ..
   173.7 - * @run main/timeout=240 Connect
   173.8   */
   173.9  
  173.10  import java.io.*;
  173.11 @@ -38,7 +37,7 @@
  173.12  public class Connect {
  173.13  
  173.14      static int success = 0;
  173.15 -    static int LIMIT = 500;
  173.16 +    static int LIMIT = 100;
  173.17  
  173.18      public static void main(String[] args) throws Exception {
  173.19          scaleTest();
  173.20 @@ -51,29 +50,30 @@
  173.21          for (int j=0; j<LIMIT; j++) {
  173.22              SocketChannel sc = SocketChannel.open();
  173.23              sc.configureBlocking(false);
  173.24 -            boolean result = sc.connect(isa);
  173.25 -            if (!result) {
  173.26 +            boolean connected = sc.connect(isa);
  173.27 +            if (!connected) {
  173.28                  Selector RSelector = SelectorProvider.provider().openSelector();
  173.29                  SelectionKey RKey = sc.register (RSelector, SelectionKey.OP_CONNECT);
  173.30 -                while (!result) {
  173.31 +                while (!connected) {
  173.32                      int keysAdded = RSelector.select(100);
  173.33                      if (keysAdded > 0) {
  173.34 -                        Set readyKeys = RSelector.selectedKeys();
  173.35 -                        Iterator i = readyKeys.iterator();
  173.36 +                        Set<SelectionKey> readyKeys = RSelector.selectedKeys();
  173.37 +                        Iterator<SelectionKey> i = readyKeys.iterator();
  173.38                          while (i.hasNext()) {
  173.39 -                            SelectionKey sk = (SelectionKey)i.next();
  173.40 +                            SelectionKey sk = i.next();
  173.41                              SocketChannel nextReady = (SocketChannel)sk.channel();
  173.42 -                            result = nextReady.finishConnect();
  173.43 +                            connected = nextReady.finishConnect();
  173.44                          }
  173.45 +                        readyKeys.clear();
  173.46                      }
  173.47                  }
  173.48                  RSelector.close();
  173.49              }
  173.50 -            read(sc);
  173.51 +            readAndClose(sc);
  173.52          }
  173.53      }
  173.54  
  173.55 -    static void read(SocketChannel sc) throws Exception {
  173.56 +    static void readAndClose(SocketChannel sc) throws Exception {
  173.57          ByteBuffer bb = ByteBuffer.allocateDirect(100);
  173.58          int n = 0;
  173.59          while (n == 0) // Note this is not a rigorous check for done reading
   174.1 --- a/test/java/nio/channels/Selector/ConnectWrite.java	Thu Jul 15 20:11:45 2010 -0700
   174.2 +++ b/test/java/nio/channels/Selector/ConnectWrite.java	Tue Jul 20 22:21:31 2010 -0700
   174.3 @@ -45,8 +45,8 @@
   174.4          Selector selector = SelectorProvider.provider().openSelector();
   174.5          InetAddress myAddress=InetAddress.getByName(TestUtil.HOST);
   174.6          InetSocketAddress isa = new InetSocketAddress(myAddress, port);
   174.7 +        SocketChannel sc = SocketChannel.open();
   174.8          try {
   174.9 -            SocketChannel sc = SocketChannel.open();
  174.10              sc.configureBlocking(false);
  174.11              SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
  174.12              boolean result = sc.connect(isa);
  174.13 @@ -80,6 +80,7 @@
  174.14                  }
  174.15              }
  174.16          } finally {
  174.17 +            sc.close();
  174.18              selector.close();
  174.19          }
  174.20      }
   175.1 --- a/test/java/nio/channels/Selector/HelperSlowToDie.java	Thu Jul 15 20:11:45 2010 -0700
   175.2 +++ b/test/java/nio/channels/Selector/HelperSlowToDie.java	Tue Jul 20 22:21:31 2010 -0700
   175.3 @@ -33,9 +33,15 @@
   175.4  
   175.5  public class HelperSlowToDie {
   175.6      private static final int CHANNELS_PER_THREAD = 1023;
   175.7 +    private static final int TEST_ITERATIONS = 200;
   175.8      private static volatile boolean done;
   175.9  
  175.10      public static void main(String[] args) throws IOException {
  175.11 +        if (!System.getProperty("os.name").startsWith("Windows")) {
  175.12 +            System.out.println("Test skipped as it verifies a Windows specific bug");
  175.13 +            return;
  175.14 +        }
  175.15 +
  175.16          Selector sel = Selector.open();
  175.17  
  175.18          // register channels
  175.19 @@ -60,7 +66,7 @@
  175.20              new Thread(busy).start();
  175.21  
  175.22          // Loop changing the number of channels from 1023 to 1024 and back.
  175.23 -        for (int i=0; i<1000; i++) {
  175.24 +        for (int i=0; i<TEST_ITERATIONS; i++) {
  175.25              SocketChannel sc = SocketChannel.open();
  175.26              sc.configureBlocking(false);
  175.27              sc.register(sel, SelectionKey.OP_CONNECT);
  175.28 @@ -71,5 +77,11 @@
  175.29  
  175.30          // terminate busy threads
  175.31          done = true;
  175.32 +
  175.33 +        // clean-up
  175.34 +        for (int i=0; i<CHANNELS_PER_THREAD; i++) {
  175.35 +            channels[i].close();
  175.36 +        }
  175.37 +        sel.close();
  175.38      }
  175.39  }
   176.1 --- a/test/java/nio/channels/Selector/KeysReady.java	Thu Jul 15 20:11:45 2010 -0700
   176.2 +++ b/test/java/nio/channels/Selector/KeysReady.java	Tue Jul 20 22:21:31 2010 -0700
   176.3 @@ -49,14 +49,18 @@
   176.4  
   176.5          // Prepare a selector
   176.6          Selector selector = SelectorProvider.provider().openSelector();
   176.7 -        SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
   176.8 -        int keysAdded = selector.select();
   176.9 -        if (keysAdded > 0) {
  176.10 -            keysAdded = selector.select(1000);
  176.11 -            if (keysAdded > 0)
  176.12 -                throw new Exception("Same key reported added twice");
  176.13 +        try {
  176.14 +            SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
  176.15 +            int keysAdded = selector.select();
  176.16 +            if (keysAdded > 0) {
  176.17 +                keysAdded = selector.select(1000);
  176.18 +                if (keysAdded > 0)
  176.19 +                    throw new Exception("Same key reported added twice");
  176.20 +            }
  176.21 +        } finally {
  176.22 +            selector.close();
  176.23 +            sc.close();
  176.24          }
  176.25 -        sc.close();
  176.26      }
  176.27  
  176.28      public static void main(String[] args) throws Exception {
   177.1 --- a/test/java/nio/channels/Selector/LotsOfChannels.java	Thu Jul 15 20:11:45 2010 -0700
   177.2 +++ b/test/java/nio/channels/Selector/LotsOfChannels.java	Tue Jul 20 22:21:31 2010 -0700
   177.3 @@ -35,19 +35,11 @@
   177.4  
   177.5  public class LotsOfChannels {
   177.6  
   177.7 -    private final static int PIPES_COUNT = 1900;
   177.8 +    private final static int PIPES_COUNT = 256;
   177.9      private final static int BUF_SIZE = 8192;
  177.10      private final static int LOOPS = 10;
  177.11  
  177.12      public static void main(String[] argv) throws Exception {
  177.13 -
  177.14 -
  177.15 -        String os = System.getProperty("os.name");
  177.16 -        if (!(os.equals("Windows NT")
  177.17 -           || os.equals("Windows 2000")
  177.18 -           || os.equals("Windows XP")))
  177.19 -            return;
  177.20 -
  177.21          Pipe[] pipes = new Pipe[PIPES_COUNT];
  177.22          Pipe pipe = Pipe.open();
  177.23          Pipe.SinkChannel sink = pipe.sink();
  177.24 @@ -72,6 +64,13 @@
  177.25              sel.selectedKeys().clear();
  177.26              source.read(ByteBuffer.allocate(BUF_SIZE));
  177.27          }
  177.28 +
  177.29 +        for (int i = 0; i < PIPES_COUNT; i++ ) {
  177.30 +            pipes[i].sink().close();
  177.31 +            pipes[i].source().close();
  177.32 +        }
  177.33 +        pipe.sink().close();
  177.34 +        pipe.source().close();
  177.35          sel.close();
  177.36      }
  177.37  }
   178.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   178.2 +++ b/test/java/nio/channels/Selector/OutOfBand.java	Tue Jul 20 22:21:31 2010 -0700
   178.3 @@ -0,0 +1,132 @@
   178.4 +/*
   178.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   178.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   178.7 + *
   178.8 + * This code is free software; you can redistribute it and/or modify it
   178.9 + * under the terms of the GNU General Public License version 2 only, as
  178.10 + * published by the Free Software Foundation.
  178.11 + *
  178.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  178.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  178.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  178.15 + * version 2 for more details (a copy is included in the LICENSE file that
  178.16 + * accompanied this code).
  178.17 + *
  178.18 + * You should have received a copy of the GNU General Public License version
  178.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  178.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  178.21 + *
  178.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  178.23 + * or visit www.oracle.com if you need additional information or have any
  178.24 + * questions.
  178.25 + */
  178.26 +
  178.27 +/* @test
  178.28 + * @bug 6213702
  178.29 + * @summary OOB data causes a SocketChannel, with OOBINLINE disabled, to be
  178.30 + *    selected
  178.31 + */
  178.32 +
  178.33 +import java.net.*;
  178.34 +import java.nio.ByteBuffer;
  178.35 +import java.nio.channels.*;
  178.36 +import java.io.IOException;
  178.37 +
  178.38 +public class OutOfBand {
  178.39 +
  178.40 +    public static void main(String[] args) throws Exception {
  178.41 +        ServerSocketChannel ssc = null;
  178.42 +        SocketChannel sc = null;
  178.43 +        Selector sel = null;
  178.44 +        Socket s = null;
  178.45 +
  178.46 +        try {
  178.47 +            // establish loopback connection.
  178.48 +            ssc = ServerSocketChannel.open().bind(new InetSocketAddress(0));
  178.49 +            s = new Socket(InetAddress.getLocalHost(),
  178.50 +                           ssc.socket().getLocalPort());
  178.51 +            sc = ssc.accept();
  178.52 +
  178.53 +            sel = Selector.open();
  178.54 +            sc.configureBlocking(false);
  178.55 +            sc.register(sel, SelectionKey.OP_READ);
  178.56 +
  178.57 +            // OOB data should be disabled by default
  178.58 +            if (sc.socket().getOOBInline())
  178.59 +                throw new RuntimeException("SO_OOBINLINE enabled");
  178.60 +            test(s, false, 0,   0,   sel);
  178.61 +            test(s, false, 512, 0,   sel);
  178.62 +            test(s, false, 0,   512, sel);
  178.63 +            test(s, false, 512, 512, sel);
  178.64 +
  178.65 +            // enable SO_OOBINLINE
  178.66 +            sc.socket().setOOBInline(true);
  178.67 +
  178.68 +            // OOB data should be received
  178.69 +            test(s, true, 0,   0,   sel);
  178.70 +            test(s, true, 512, 0,   sel);
  178.71 +            test(s, true, 0,   512, sel);
  178.72 +            test(s, true, 512, 512, sel);
  178.73 +
  178.74 +        } finally {
  178.75 +            if (sel != null) sel.close();
  178.76 +            if (sc != null) sc.close();
  178.77 +            if (ssc != null) ssc.close();
  178.78 +            if (s != null) sc.close();
  178.79 +        }
  178.80 +    }
  178.81 +
  178.82 +    static void test(Socket s, boolean urgentExpected,
  178.83 +                     int bytesBefore, int bytesAfter,
  178.84 +                     Selector sel)
  178.85 +        throws IOException
  178.86 +    {
  178.87 +        // send data
  178.88 +        int bytesExpected = 0;
  178.89 +        if (bytesBefore > 0) {
  178.90 +            s.getOutputStream().write(new byte[bytesBefore]);
  178.91 +            bytesExpected += bytesBefore;
  178.92 +        }
  178.93 +        s.sendUrgentData(0xff);
  178.94 +        if (urgentExpected)
  178.95 +            bytesExpected++;
  178.96 +        if (bytesAfter > 0) {
  178.97 +            s.getOutputStream().write(new byte[bytesAfter]);
  178.98 +            bytesExpected += bytesAfter;
  178.99 +        }
 178.100 +
 178.101 +        // receive data, checking for spurious wakeups and reads
 178.102 +        int spuriousWakeups = 0;
 178.103 +        int spuriousReads = 0;
 178.104 +        int bytesRead = 0;
 178.105 +        ByteBuffer bb = ByteBuffer.allocate(100);
 178.106 +        for (;;) {
 178.107 +            int n = sel.select(2000);
 178.108 +            if (n == 0) {
 178.109 +                if (bytesRead == bytesExpected) {
 178.110 +                    System.out.format("Selector wakeups %d\tSpurious reads %d%n",
 178.111 +                            spuriousWakeups, spuriousReads);
 178.112 +                    return;
 178.113 +                }
 178.114 +                if (++spuriousWakeups >= 3)
 178.115 +                    throw new RuntimeException("Selector appears to be spinning" +
 178.116 +                        " or data not received");
 178.117 +                continue;
 178.118 +            }
 178.119 +            if (n > 1)
 178.120 +                throw new RuntimeException("More than one key selected????");
 178.121 +            SelectionKey key = sel.selectedKeys().iterator().next();
 178.122 +            bb.clear();
 178.123 +            n = ((SocketChannel)key.channel()).read(bb);
 178.124 +            if (n == 0) {
 178.125 +                if (++spuriousReads >=3)
 178.126 +                    throw new RuntimeException("Too many spurious reads");
 178.127 +            } else {
 178.128 +                bytesRead += n;
 178.129 +                if (bytesRead > bytesExpected)
 178.130 +                    throw new RuntimeException("Received more than expected");
 178.131 +            }
 178.132 +            sel.selectedKeys().clear();
 178.133 +        }
 178.134 +    }
 178.135 +}
   179.1 --- a/test/java/nio/channels/Selector/RegAfterPreClose.java	Thu Jul 15 20:11:45 2010 -0700
   179.2 +++ b/test/java/nio/channels/Selector/RegAfterPreClose.java	Tue Jul 20 22:21:31 2010 -0700
   179.3 @@ -35,6 +35,7 @@
   179.4  
   179.5  public class RegAfterPreClose {
   179.6  
   179.7 +    static final int TEST_ITERATIONS = 300;
   179.8      static volatile boolean done;
   179.9  
  179.10      /**
  179.11 @@ -96,26 +97,21 @@
  179.12              }
  179.13          };
  179.14  
  179.15 -        // schedule test to run for 1 minute
  179.16 -        Executors.newScheduledThreadPool(1, factory).schedule(new Runnable() {
  179.17 -            public void run() {
  179.18 -                done = true;
  179.19 -                sel.wakeup();
  179.20 -            }}, 1, TimeUnit.MINUTES);
  179.21 -
  179.22          // create Executor that handles tasks that closes channels
  179.23          // "asynchronously" - this creates the conditions to provoke the bug.
  179.24 -        Executor executor = Executors.newFixedThreadPool(2, factory);
  179.25 +        ExecutorService executor = Executors.newFixedThreadPool(2, factory);
  179.26  
  179.27          // submit task that connects to listener
  179.28          executor.execute(new Connector(ssc.socket().getLocalPort()));
  179.29  
  179.30          // loop accepting connections until done (or an IOException is thrown)
  179.31 -        while (!done) {
  179.32 +        int remaining = TEST_ITERATIONS;
  179.33 +        while (remaining > 0) {
  179.34              sel.select();
  179.35              if (key.isAcceptable()) {
  179.36                  SocketChannel sc = ssc.accept();
  179.37                  if (sc != null) {
  179.38 +                    remaining--;
  179.39                      sc.configureBlocking(false);
  179.40                      sc.register(sel, SelectionKey.OP_READ);
  179.41                      executor.execute(new Closer(sc));
  179.42 @@ -123,5 +119,8 @@
  179.43              }
  179.44              sel.selectedKeys().clear();
  179.45          }
  179.46 +        done = true;
  179.47 +        sel.close();
  179.48 +        executor.shutdown();
  179.49      }
  179.50  }
   180.1 --- a/test/java/nio/channels/Selector/SelectAndCancel.java	Thu Jul 15 20:11:45 2010 -0700
   180.2 +++ b/test/java/nio/channels/Selector/SelectAndCancel.java	Tue Jul 20 22:21:31 2010 -0700
   180.3 @@ -31,11 +31,7 @@
   180.4  import java.net.*;
   180.5  
   180.6  public class SelectAndCancel {
   180.7 -    static ServerSocketChannel ssc;
   180.8 -    static Selector selector;
   180.9      static SelectionKey sk;
  180.10 -    static InetSocketAddress isa;
  180.11 -    public static int TEST_PORT = 40170;
  180.12  
  180.13      /*
  180.14       * CancelledKeyException is the failure symptom of 4729342
  180.15 @@ -43,17 +39,17 @@
  180.16       * seen immediately when the bug is present.
  180.17       */
  180.18      public static void main(String[] args) throws Exception {
  180.19 -        InetAddress lh = InetAddress.getLocalHost();
  180.20 -        isa = new InetSocketAddress(lh, TEST_PORT);
  180.21 -        selector = Selector.open();
  180.22 -        ssc = ServerSocketChannel.open();
  180.23 +        final Selector selector = Selector.open();
  180.24 +        final ServerSocketChannel ssc =
  180.25 +            ServerSocketChannel.open().bind(new InetSocketAddress(0));
  180.26 +        final InetSocketAddress isa =
  180.27 +            new InetSocketAddress(InetAddress.getLocalHost(), ssc.socket().getLocalPort());
  180.28  
  180.29          // Create and start a selector in a separate thread.
  180.30          new Thread(new Runnable() {
  180.31                  public void run() {
  180.32                      try {
  180.33                          ssc.configureBlocking(false);
  180.34 -                        ssc.socket().bind(isa);
  180.35                          sk = ssc.register(selector, SelectionKey.OP_ACCEPT);
  180.36                          selector.select();
  180.37                      } catch (IOException e) {
   181.1 --- a/test/java/nio/channels/Selector/SelectorLimit.java	Thu Jul 15 20:11:45 2010 -0700
   181.2 +++ b/test/java/nio/channels/Selector/SelectorLimit.java	Tue Jul 20 22:21:31 2010 -0700
   181.3 @@ -26,6 +26,8 @@
   181.4   * @summary Ensure that a Selector can return at least 100 selected keys
   181.5   * @author Mark Reinhold
   181.6   * @library ..
   181.7 + * @build SelectorLimit
   181.8 + * @run main/othervm SelectorLimit
   181.9   */
  181.10  
  181.11  import java.io.*;
   182.1 --- a/test/java/nio/channels/Selector/SelectorTest.java	Thu Jul 15 20:11:45 2010 -0700
   182.2 +++ b/test/java/nio/channels/Selector/SelectorTest.java	Tue Jul 20 22:21:31 2010 -0700
   182.3 @@ -57,13 +57,13 @@
   182.4       */
   182.5      public static void main(String[] args) throws Exception {
   182.6          if (args.length == 0) {
   182.7 -            InetSocketAddress isa
   182.8 -                = new InetSocketAddress(InetAddress.getLocalHost(), TEST_PORT);
   182.9 -            Server server = new Server(isa);
  182.10 +            Server server = new Server(0);
  182.11              server.start();
  182.12              try {
  182.13                  Thread.sleep(1000);
  182.14              } catch (InterruptedException e) { }
  182.15 +            InetSocketAddress isa
  182.16 +                = new InetSocketAddress(InetAddress.getLocalHost(), server.port());
  182.17              Client client = new Client(isa);
  182.18              client.start();
  182.19              if ((server.finish(FINISH_TIME) & client.finish(FINISH_TIME)) == 0)
  182.20 @@ -74,9 +74,7 @@
  182.21  
  182.22              if (args.length > 1)
  182.23                  TEST_PORT = Integer.parseInt(args[1]);
  182.24 -            InetSocketAddress isa
  182.25 -                = new InetSocketAddress(InetAddress.getLocalHost(), TEST_PORT);
  182.26 -            Server server = new Server(isa);
  182.27 +            Server server = new Server(TEST_PORT);
  182.28              server.start();
  182.29              if (server.finish(FINISH_TIME) == 0)
  182.30                  throw new Exception("Failure");
  182.31 @@ -136,18 +134,22 @@
  182.32      }
  182.33  
  182.34      static class Server extends TestThread {
  182.35 +        private final ServerSocketChannel ssc;
  182.36          private List socketList = new ArrayList();
  182.37          private ServerSocket ss;
  182.38          private int connectionsAccepted = 0;
  182.39          private Selector pollSelector;
  182.40          private Selector acceptSelector;
  182.41 -        private InetSocketAddress isa;
  182.42          private Set pkeys;
  182.43          private Set pskeys;
  182.44  
  182.45 -        Server(InetSocketAddress isa) {
  182.46 +        Server(int port) throws IOException {
  182.47              super("Server", SelectorTest.log);
  182.48 -            this.isa = isa;
  182.49 +            this.ssc = ServerSocketChannel.open().bind(new InetSocketAddress(port));
  182.50 +        }
  182.51 +
  182.52 +        int port() {
  182.53 +            return ssc.socket().getLocalPort();
  182.54          }
  182.55  
  182.56          public void go() throws Exception {
  182.57 @@ -162,11 +164,7 @@
  182.58  
  182.59              requestThread.start();
  182.60  
  182.61 -            ServerSocketChannel ssc = ServerSocketChannel.open();
  182.62              ssc.configureBlocking(false);
  182.63 -            ssc.socket().setReuseAddress(true);
  182.64 -            ssc.socket().bind(isa);
  182.65 -
  182.66              SelectionKey acceptKey = ssc.register(acceptSelector,
  182.67                                                    SelectionKey.OP_ACCEPT);
  182.68              while(connectionsAccepted < SelectorTest.NUM_CLIENTS) {
   183.1 --- a/test/java/nio/channels/Selector/WakeupNow.java	Thu Jul 15 20:11:45 2010 -0700
   183.2 +++ b/test/java/nio/channels/Selector/WakeupNow.java	Tue Jul 20 22:21:31 2010 -0700
   183.3 @@ -44,10 +44,15 @@
   183.4          p.source().configureBlocking(false);
   183.5          p.source().register(sel, SelectionKey.OP_READ);
   183.6          sel.wakeup();
   183.7 +        // ensure wakeup is consumed by selectNow
   183.8 +        Thread.sleep(2000);
   183.9          sel.selectNow();
  183.10          long startTime = System.currentTimeMillis();
  183.11          int n = sel.select(2000);
  183.12          long endTime = System.currentTimeMillis();
  183.13 +        p.source().close();
  183.14 +        p.sink().close();
  183.15 +        sel.close();
  183.16          if (endTime - startTime < 1000)
  183.17              throw new RuntimeException("test failed");
  183.18      }
  183.19 @@ -60,10 +65,13 @@
  183.20          Pipe p = Pipe.open();
  183.21          p.source().configureBlocking(false);
  183.22          sel.wakeup();
  183.23 +        // ensure wakeup is consumed by selectNow
  183.24 +        Thread.sleep(2000);
  183.25          sel.selectNow();
  183.26          long startTime = System.currentTimeMillis();
  183.27          int n = sel.select(2000);
  183.28          long endTime = System.currentTimeMillis();
  183.29 +        sel.close();
  183.30          if (endTime - startTime < 1000)
  183.31              throw new RuntimeException("test failed");
  183.32      }
   184.1 --- a/test/java/nio/channels/Selector/WakeupOverflow.java	Thu Jul 15 20:11:45 2010 -0700
   184.2 +++ b/test/java/nio/channels/Selector/WakeupOverflow.java	Tue Jul 20 22:21:31 2010 -0700
   184.3 @@ -31,8 +31,12 @@
   184.4  public class WakeupOverflow {
   184.5      public static void main( String[] args ) throws Exception {
   184.6          Selector selector = Selector.open();
   184.7 -        for(int i=0; i<10000; i++) {
   184.8 -            selector.wakeup();
   184.9 +        try {
  184.10 +            for(int i=0; i<10000; i++) {
  184.11 +                selector.wakeup();
  184.12 +            }
  184.13 +        } finally {
  184.14 +            selector.close();
  184.15          }
  184.16      }
  184.17  }
   185.1 --- a/test/java/nio/channels/Selector/WakeupSpeed.java	Thu Jul 15 20:11:45 2010 -0700
   185.2 +++ b/test/java/nio/channels/Selector/WakeupSpeed.java	Tue Jul 20 22:21:31 2010 -0700
   185.3 @@ -35,16 +35,19 @@
   185.4      public static void main(String argv[]) throws Exception {
   185.5          int waitTime = 4000;
   185.6          Selector selector = Selector.open();
   185.7 +        try {
   185.8 +            selector.wakeup();
   185.9  
  185.10 -        selector.wakeup();
  185.11 +            long t1 = System.currentTimeMillis();
  185.12 +            selector.select(waitTime);
  185.13 +            long t2 = System.currentTimeMillis();
  185.14 +            long totalTime = t2 - t1;
  185.15  
  185.16 -        long t1 = System.currentTimeMillis();
  185.17 -        selector.select(waitTime);
  185.18 -        long t2 = System.currentTimeMillis();
  185.19 -        long totalTime = t2 - t1;
  185.20 -
  185.21 -        if (totalTime > waitTime)
  185.22 -            throw new RuntimeException("Test failed");
  185.23 +            if (totalTime > waitTime)
  185.24 +                throw new RuntimeException("Test failed");
  185.25 +        } finally {
  185.26 +            selector.close();
  185.27 +        }
  185.28      }
  185.29  
  185.30  }
   186.1 --- a/test/java/nio/channels/ServerSocketChannel/AcceptAddress.java	Thu Jul 15 20:11:45 2010 -0700
   186.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   186.3 @@ -1,51 +0,0 @@
   186.4 -/*
   186.5 - * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
   186.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   186.7 - *
   186.8 - * This code is free software; you can redistribute it and/or modify it
   186.9 - * under the terms of the GNU General Public License version 2 only, as
  186.10 - * published by the Free Software Foundation.
  186.11 - *
  186.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
  186.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  186.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  186.15 - * version 2 for more details (a copy is included in the LICENSE file that
  186.16 - * accompanied this code).
  186.17 - *
  186.18 - * You should have received a copy of the GNU General Public License version
  186.19 - * 2 along with this work; if not, write to the Free Software Foundation,
  186.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  186.21 - *
  186.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  186.23 - * or visit www.oracle.com if you need additional information or have any
  186.24 - * questions.
  186.25 - */
  186.26 -
  186.27 -/* @test
  186.28 - * @summary test the address returned in socket from accept
  186.29 - */
  186.30 -
  186.31 -import java.io.*;
  186.32 -import java.net.*;
  186.33 -import java.nio.*;
  186.34 -import java.nio.channels.*;
  186.35 -
  186.36 -
  186.37 -public class AcceptAddress {
  186.38 -
  186.39 -    public static void main(String[] args) throws Exception {
  186.40 -        InetAddress local = InetAddress.getLocalHost();
  186.41 -        InetSocketAddress isa = new InetSocketAddress(local, 5555);
  186.42 -
  186.43 -        ServerSocketChannel ssc;
  186.44 -        ssc = ServerSocketChannel.open();
  186.45 -        ssc.socket().bind(isa);
  186.46 -
  186.47 -        SocketChannel sc;
  186.48 -        sc = SocketChannel.open();
  186.49 -        sc.connect(isa);
  186.50 -
  186.51 -        SocketChannel sc2 = ssc.accept();
  186.52 -        System.err.println("Socket connected to " + sc2);
  186.53 -    }
  186.54 -}
   187.1 --- a/test/java/nio/channels/SocketChannel/AdaptSocket.java	Thu Jul 15 20:11:45 2010 -0700
   187.2 +++ b/test/java/nio/channels/SocketChannel/AdaptSocket.java	Tue Jul 20 22:21:31 2010 -0700
   187.3 @@ -78,8 +78,6 @@
   187.4                      throw x;
   187.5                  }
   187.6              }
   187.7 -            if (shouldTimeout)
   187.8 -                throw new Exception("Connection did not time out");
   187.9          }
  187.10          out.println("connected: " + so);
  187.11          out.println("           " + sc);
  187.12 @@ -118,8 +116,6 @@
  187.13              }
  187.14              throw x;
  187.15          }
  187.16 -        if (shouldTimeout)
  187.17 -            throw new Exception("Read did not time out");
  187.18      }
  187.19  
  187.20      static void testRead(String hn, int timeout, boolean shouldTimeout)
   188.1 --- a/test/java/nio/channels/SocketChannel/Bind.java	Thu Jul 15 20:11:45 2010 -0700
   188.2 +++ b/test/java/nio/channels/SocketChannel/Bind.java	Tue Jul 20 22:21:31 2010 -0700
   188.3 @@ -31,13 +31,20 @@
   188.4  
   188.5  public class Bind {
   188.6      public static void main(String[] args) throws Exception {
   188.7 +        SocketChannel sc1 = SocketChannel.open();
   188.8          try {
   188.9 -            SocketChannel channel1 = SocketChannel.open();
  188.10 -            channel1.socket().bind(new InetSocketAddress(5555));
  188.11 -            SocketChannel channel2 = SocketChannel.open();
  188.12 -            channel2.socket().bind(new InetSocketAddress(5555));
  188.13 +            sc1.bind(new InetSocketAddress(0));
  188.14 +            int port = sc1.socket().getLocalPort();
  188.15 +            SocketChannel sc2 = SocketChannel.open();
  188.16 +            try {
  188.17 +                sc2.bind(new InetSocketAddress(port));
  188.18 +            } finally {
  188.19 +               sc2.close();
  188.20 +            }
  188.21          } catch (BindException be) {
  188.22              // Correct result
  188.23 +        } finally {
  188.24 +            sc1.close();
  188.25          }
  188.26      }
  188.27  }
   189.1 --- a/test/java/nio/channels/SocketChannel/Close.java	Thu Jul 15 20:11:45 2010 -0700
   189.2 +++ b/test/java/nio/channels/SocketChannel/Close.java	Tue Jul 20 22:21:31 2010 -0700
   189.3 @@ -56,8 +56,12 @@
   189.4  
   189.5      static void testChannelClose() throws IOException {
   189.6          SelectionKey sk = open();
   189.7 -        sk.channel().close();
   189.8 -        check(sk);
   189.9 +        try {
  189.10 +            sk.channel().close();
  189.11 +            check(sk);
  189.12 +        } finally {
  189.13 +            sk.selector().close();
  189.14 +        }
  189.15      }
  189.16  
  189.17      public static void main(String[] args) throws Exception {
   190.1 --- a/test/java/nio/channels/SocketChannel/CloseRegisteredChannel.java	Thu Jul 15 20:11:45 2010 -0700
   190.2 +++ b/test/java/nio/channels/SocketChannel/CloseRegisteredChannel.java	Tue Jul 20 22:21:31 2010 -0700
   190.3 @@ -55,5 +55,8 @@
   190.4          System.out.println ("Will hang here...");
   190.5          int nb = slave.read (ByteBuffer.allocate (1024));
   190.6          //System.out.println("read nb=" + nb);
   190.7 +
   190.8 +        selector.close();
   190.9 +        server.close();
  190.10      }
  190.11  }
   191.1 --- a/test/java/nio/channels/SocketChannel/CloseTimeoutChannel.java	Thu Jul 15 20:11:45 2010 -0700
   191.2 +++ b/test/java/nio/channels/SocketChannel/CloseTimeoutChannel.java	Tue Jul 20 22:21:31 2010 -0700
   191.3 @@ -33,11 +33,12 @@
   191.4  import java.net.*;
   191.5  
   191.6  public class CloseTimeoutChannel {
   191.7 -    final static int PORT=6347;
   191.8      public static void main(String args[]) throws Exception {
   191.9 +        int port = -1;
  191.10          try {
  191.11              ServerSocketChannel listener=ServerSocketChannel.open();
  191.12 -            listener.socket().bind(new InetSocketAddress(PORT));
  191.13 +            listener.socket().bind(new InetSocketAddress(0));
  191.14 +            port = listener.socket().getLocalPort();
  191.15              AcceptorThread thread=new AcceptorThread(listener);
  191.16              thread.start();
  191.17          } catch (IOException e) {
  191.18 @@ -50,7 +51,7 @@
  191.19          try {
  191.20              System.out.println("Establishing connection");
  191.21              Socket socket=SocketChannel.open(
  191.22 -                new InetSocketAddress("127.0.0.1", PORT)).socket();
  191.23 +                new InetSocketAddress("127.0.0.1", port)).socket();
  191.24              OutputStream out=socket.getOutputStream();
  191.25              InputStream in=socket.getInputStream();
  191.26  
  191.27 @@ -98,7 +99,8 @@
  191.28                      Thread.sleep(100);
  191.29                  } catch (InterruptedException e) { }
  191.30  
  191.31 -                System.out.println(INDENT+"Listening on port "+ PORT);
  191.32 +                System.out.println(INDENT+"Listening on port "+
  191.33 +                    _listener.socket().getLocalPort());
  191.34                  ByteBuffer buf=ByteBuffer.allocate(5);
  191.35                  Socket client=_listener.accept().socket();;
  191.36                  System.out.println(INDENT+"Accepted client");
  191.37 @@ -123,6 +125,8 @@
  191.38                  client.close();
  191.39              } catch (IOException e) {
  191.40                  System.out.println(INDENT+"Error accepting!");
  191.41 +            } finally {
  191.42 +                try { _listener.close(); } catch (IOException ignore) { }
  191.43              }
  191.44          }
  191.45      }
   192.1 --- a/test/java/nio/channels/SocketChannel/IsConnectable.java	Thu Jul 15 20:11:45 2010 -0700
   192.2 +++ b/test/java/nio/channels/SocketChannel/IsConnectable.java	Tue Jul 20 22:21:31 2010 -0700
   192.3 @@ -48,27 +48,31 @@
   192.4          sc.connect(isa);
   192.5  
   192.6          Selector selector = SelectorProvider.provider().openSelector();
   192.7 -        SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
   192.8 -        int keysAdded = selector.select();
   192.9 -        if (keysAdded > 0) {
  192.10 -            boolean result = sc.finishConnect();
  192.11 -            if (result) {
  192.12 -                keysAdded = selector.select(5000);
  192.13 -                // 4750573: keysAdded should not be incremented when op is dropped
  192.14 -                // from a key already in the selected key set
  192.15 -                if (keysAdded > 0)
  192.16 -                    throw new Exception("Test failed: 4750573 detected");
  192.17 -                Set sel = selector.selectedKeys();
  192.18 -                Iterator i = sel.iterator();
  192.19 -                SelectionKey sk = (SelectionKey)i.next();
  192.20 -                // 4737146: isConnectable should be false while connected
  192.21 -                if (sk.isConnectable())
  192.22 -                    throw new Exception("Test failed: 4737146 detected");
  192.23 +        try {
  192.24 +            SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
  192.25 +            int keysAdded = selector.select();
  192.26 +            if (keysAdded > 0) {
  192.27 +                boolean result = sc.finishConnect();
  192.28 +                if (result) {
  192.29 +                    keysAdded = selector.select(5000);
  192.30 +                    // 4750573: keysAdded should not be incremented when op is dropped
  192.31 +                    // from a key already in the selected key set
  192.32 +                    if (keysAdded > 0)
  192.33 +                        throw new Exception("Test failed: 4750573 detected");
  192.34 +                    Set<SelectionKey> sel = selector.selectedKeys();
  192.35 +                    Iterator<SelectionKey> i = sel.iterator();
  192.36 +                    SelectionKey sk = i.next();
  192.37 +                    // 4737146: isConnectable should be false while connected
  192.38 +                    if (sk.isConnectable())
  192.39 +                        throw new Exception("Test failed: 4737146 detected");
  192.40 +                }
  192.41 +            } else {
  192.42 +                throw new Exception("Select failed");
  192.43              }
  192.44 -        } else {
  192.45 -            throw new Exception("Select failed");
  192.46 +        } finally {
  192.47 +            sc.close();
  192.48 +            selector.close();
  192.49          }
  192.50 -        sc.close();
  192.51      }
  192.52  
  192.53      public static void main(String[] args) throws Exception {
   193.1 --- a/test/java/nio/channels/SocketChannel/LocalAddress.java	Thu Jul 15 20:11:45 2010 -0700
   193.2 +++ b/test/java/nio/channels/SocketChannel/LocalAddress.java	Tue Jul 20 22:21:31 2010 -0700
   193.3 @@ -38,25 +38,33 @@
   193.4  
   193.5      static void test1() throws Exception {
   193.6          InetAddress bogus = InetAddress.getByName("0.0.0.0");
   193.7 -        SocketChannel sc = SocketChannel.open();
   193.8          InetSocketAddress saddr = new InetSocketAddress(
   193.9              InetAddress.getByName(TestUtil.HOST), 23);
  193.10  
  193.11          //Test1: connect only
  193.12 -        sc.connect(saddr);
  193.13 -        InetAddress isa = sc.socket().getLocalAddress();
  193.14 -        if (isa == null || isa.equals(bogus))
  193.15 -            throw new RuntimeException("test failed");
  193.16 +        SocketChannel sc = SocketChannel.open();
  193.17 +        try {
  193.18 +            sc.connect(saddr);
  193.19 +            InetAddress ia = sc.socket().getLocalAddress();
  193.20 +            if (ia == null || ia.equals(bogus))
  193.21 +                throw new RuntimeException("test failed");
  193.22 +        } finally {
  193.23 +            sc.close();
  193.24 +        }
  193.25  
  193.26          //Test2: bind and connect
  193.27          sc = SocketChannel.open();
  193.28 -        sc.socket().bind(new InetSocketAddress(0));
  193.29 -        if (sc.socket().getLocalPort() == 0)
  193.30 -            throw new RuntimeException("test failed");
  193.31 -        sc.socket().connect(saddr);
  193.32 -        isa = sc.socket().getLocalAddress();
  193.33 -        if (isa == null || isa.isAnyLocalAddress())
  193.34 -            throw new RuntimeException("test failed");
  193.35 +        try {
  193.36 +            sc.socket().bind(new InetSocketAddress(0));
  193.37 +            if (sc.socket().getLocalPort() == 0)
  193.38 +                throw new RuntimeException("test failed");
  193.39 +            sc.socket().connect(saddr);
  193.40 +            InetAddress ia = sc.socket().getLocalAddress();
  193.41 +            if (ia == null || ia.isAnyLocalAddress())
  193.42 +                throw new RuntimeException("test failed");
  193.43 +        } finally {
  193.44 +            sc.close();
  193.45 +        }
  193.46  
  193.47      }
  193.48  }
   194.1 --- a/test/java/nio/channels/SocketChannel/SocketInheritance.java	Thu Jul 15 20:11:45 2010 -0700
   194.2 +++ b/test/java/nio/channels/SocketChannel/SocketInheritance.java	Tue Jul 20 22:21:31 2010 -0700
   194.3 @@ -105,7 +105,11 @@
   194.4  
   194.5          // launch the child
   194.6          String cmd = System.getProperty("java.home") + File.separator + "bin" +
   194.7 -            File.separator + "java SocketInheritance -child " + port;
   194.8 +            File.separator + "java";
   194.9 +        String testClasses = System.getProperty("test.classes");
  194.10 +        if (testClasses != null)
  194.11 +            cmd += " -cp " + testClasses;
  194.12 +        cmd += " SocketInheritance -child " + port;
  194.13  
  194.14          Process p = Runtime.getRuntime().exec(cmd);
  194.15  
   195.1 --- a/test/java/nio/channels/SocketChannel/Trivial.java	Thu Jul 15 20:11:45 2010 -0700
   195.2 +++ b/test/java/nio/channels/SocketChannel/Trivial.java	Tue Jul 20 22:21:31 2010 -0700
   195.3 @@ -33,22 +33,27 @@
   195.4      public static void main(String[] args) throws Exception {
   195.5          SocketChannel sc = SocketChannel.open();
   195.6          Selector sel = Selector.open();
   195.7 -        if (sc.keyFor(sel) != null)
   195.8 -            throw new Exception("keyFor != null");
   195.9 -        sc.configureBlocking(false);
  195.10 -        SelectionKey sk = sc.register(sel, SelectionKey.OP_READ, args);
  195.11 -        if (sc.keyFor(sel) != sk)
  195.12 -            throw new Exception("keyFor returned " + sc.keyFor(sel));
  195.13 -        if (sk.attachment() != args)
  195.14 -            throw new Exception("attachment() returned " + sk.attachment());
  195.15 -        Trivial t = new Trivial();
  195.16 -        sk.attach(t);
  195.17 -        if (sk.attachment() != t)
  195.18 -            throw new Exception("Wrong attachment");
  195.19 -        sk.isReadable();
  195.20 -        sk.isWritable();
  195.21 -        sk.isConnectable();
  195.22 -        sk.isAcceptable();
  195.23 +        try {
  195.24 +            if (sc.keyFor(sel) != null)
  195.25 +                throw new Exception("keyFor != null");
  195.26 +            sc.configureBlocking(false);
  195.27 +            SelectionKey sk = sc.register(sel, SelectionKey.OP_READ, args);
  195.28 +            if (sc.keyFor(sel) != sk)
  195.29 +                throw new Exception("keyFor returned " + sc.keyFor(sel));
  195.30 +            if (sk.attachment() != args)
  195.31 +                throw new Exception("attachment() returned " + sk.attachment());
  195.32 +            Trivial t = new Trivial();
  195.33 +            sk.attach(t);
  195.34 +            if (sk.attachment() != t)
  195.35 +                throw new Exception("Wrong attachment");
  195.36 +            sk.isReadable();
  195.37 +            sk.isWritable();
  195.38 +            sk.isConnectable();
  195.39 +            sk.isAcceptable();
  195.40 +        } finally {
  195.41 +            sel.close();
  195.42 +            sc.close();
  195.43 +        }
  195.44      }
  195.45  
  195.46  }
   196.1 --- a/test/java/nio/channels/SocketChannel/UnboundSocketTests.java	Thu Jul 15 20:11:45 2010 -0700
   196.2 +++ b/test/java/nio/channels/SocketChannel/UnboundSocketTests.java	Tue Jul 20 22:21:31 2010 -0700
   196.3 @@ -57,39 +57,47 @@
   196.4          System.out.println("\n-- SocketChannel --");
   196.5  
   196.6          SocketChannel sc = SocketChannel.open();
   196.7 +        try {
   196.8 +            check("getLocalPort()", sc.socket().getLocalPort(), -1);
   196.9 +            checkIsAnyLocalAddress("getLocalAddress()",
  196.10 +                sc.socket().getLocalAddress());
  196.11 +            check("getLocalSocketAddress()", sc.socket().getLocalSocketAddress(), null);
  196.12  
  196.13 -        check("getLocalPort()", sc.socket().getLocalPort(), -1);
  196.14 -        checkIsAnyLocalAddress("getLocalAddress()",
  196.15 -            sc.socket().getLocalAddress());
  196.16 -        check("getLocalSocketAddress()", sc.socket().getLocalSocketAddress(), null);
  196.17 -
  196.18 -        check("getPort()", sc.socket().getPort(), 0);
  196.19 -        check("getInetAddress()", sc.socket().getInetAddress(), null);
  196.20 -        check("getRemoteSocketAddress()", sc.socket().getRemoteSocketAddress(), null);
  196.21 -
  196.22 +            check("getPort()", sc.socket().getPort(), 0);
  196.23 +            check("getInetAddress()", sc.socket().getInetAddress(), null);
  196.24 +            check("getRemoteSocketAddress()", sc.socket().getRemoteSocketAddress(), null);
  196.25 +        } finally {
  196.26 +            sc.close();
  196.27 +        }
  196.28  
  196.29          System.out.println("\n-- ServerSocketChannel --");
  196.30  
  196.31          ServerSocketChannel ssc = ServerSocketChannel.open();
  196.32 -
  196.33 -        check("getLocalPort()", ssc.socket().getLocalPort(), -1);
  196.34 -        check("getInetAddress()", ssc.socket().getInetAddress(), null);
  196.35 -        check("getLocalSocketAddress()", ssc.socket().getLocalSocketAddress(), null);
  196.36 +        try {
  196.37 +            check("getLocalPort()", ssc.socket().getLocalPort(), -1);
  196.38 +            check("getInetAddress()", ssc.socket().getInetAddress(), null);
  196.39 +            check("getLocalSocketAddress()", ssc.socket().getLocalSocketAddress(), null);
  196.40 +        } finally {
  196.41 +            ssc.close();
  196.42 +        }
  196.43  
  196.44          System.out.println("\n-- DatagramChannel --");
  196.45  
  196.46          DatagramChannel dc = DatagramChannel.open();
  196.47 +        try {
  196.48 +            // not specified
  196.49 +            check("getLocalPort()", dc.socket().getLocalPort(), 0);
  196.50  
  196.51 -        // not specified
  196.52 -        check("getLocalPort()", dc.socket().getLocalPort(), 0);
  196.53 +            checkIsAnyLocalAddress("getLocalAddress()",
  196.54 +                dc.socket().getLocalAddress());
  196.55 +            check("getLocalSocketAddress()", dc.socket().getLocalSocketAddress(), null);
  196.56  
  196.57 -        checkIsAnyLocalAddress("getLocalAddress()",
  196.58 -            dc.socket().getLocalAddress());
  196.59 -        check("getLocalSocketAddress()", dc.socket().getLocalSocketAddress(), null);
  196.60 -
  196.61 -        check("getPort()", dc.socket().getPort(), -1);
  196.62 -        check("getInetAddress()", dc.socket().getInetAddress(), null);
  196.63 -        check("getRemoteSocketAddress()", dc.socket().getRemoteSocketAddress(), null);
  196.64 +            check("getPort()", dc.socket().getPort(), -1);
  196.65 +            check("getInetAddress()", dc.socket().getInetAddress(), null);
  196.66 +            check("getRemoteSocketAddress()", dc.socket().getRemoteSocketAddress(), null);
  196.67 +        } finally {
  196.68 +            dc.close();
  196.69 +        }
  196.70  
  196.71          if (failures > 0) {
  196.72              throw new RuntimeException(failures + " sub-tests(s) failed.");
   197.1 --- a/test/java/nio/channels/etc/Shadow.java	Thu Jul 15 20:11:45 2010 -0700
   197.2 +++ b/test/java/nio/channels/etc/Shadow.java	Tue Jul 20 22:21:31 2010 -0700
   197.3 @@ -35,7 +35,6 @@
   197.4  
   197.5  public class Shadow {
   197.6  
   197.7 -    private static final int PORT = 2019;
   197.8      static PrintStream log = System.err;
   197.9  
  197.10      private static void dump(ServerSocket s) {
  197.11 @@ -69,7 +68,7 @@
  197.12      public static void main(String[] args) throws Exception {
  197.13          boolean useChannels
  197.14              = ((args.length == 0) || Boolean.valueOf(args[0]).booleanValue());
  197.15 -        int port = (args.length > 1 ? Integer.parseInt(args[1]) : PORT);
  197.16 +        int port = (args.length > 1 ? Integer.parseInt(args[1]) : -1);
  197.17  
  197.18          // open server socket
  197.19          ServerSocket serverSocket;
  197.20 @@ -86,7 +85,8 @@
  197.21          }
  197.22  
  197.23          // bind server socket to port
  197.24 -        SocketAddress bindAddr = new InetSocketAddress(port);
  197.25 +        SocketAddress bindAddr =
  197.26 +            new InetSocketAddress((port == -1) ? 0 : port);
  197.27          serverSocket.bind(bindAddr);
  197.28          log.println("bound ServerSocket: " + serverSocket);
  197.29  
   198.1 --- a/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/ClosedStreams.java	Thu Jul 15 20:11:45 2010 -0700
   198.2 +++ b/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/ClosedStreams.java	Tue Jul 20 22:21:31 2010 -0700
   198.3 @@ -26,6 +26,8 @@
   198.4   * @bug 4997227
   198.5   * @summary Calling inheritedChannel() after FileDescriptor.in was closed
   198.6   *          caused an InternalError to be thrown.
   198.7 + * @build ClosedStreams
   198.8 + * @run main/othervm ClosedStreams
   198.9   */
  198.10  
  198.11  import java.io.FileDescriptor;
   199.1 --- a/test/java/nio/charset/coders/BashStreams.java	Thu Jul 15 20:11:45 2010 -0700
   199.2 +++ b/test/java/nio/charset/coders/BashStreams.java	Tue Jul 20 22:21:31 2010 -0700
   199.3 @@ -46,7 +46,7 @@
   199.4  
   199.5          CharacterGenerator(long seed, String csn, int limit) {
   199.6              rand = new Random(seed);
   199.7 -            this.max = Surrogate.UCS4_MAX + 1;
   199.8 +            this.max = Character.MAX_CODE_POINT + 1;
   199.9              this.limit = limit;
  199.10          }
  199.11  
  199.12 @@ -77,17 +77,20 @@
  199.13              int c;
  199.14              for (;;) {
  199.15                  c = rand.nextInt(max);
  199.16 -                if (Surrogate.is(c) || (c == 0xfffe) || (c == 0xffff))
  199.17 +                if ((Character.isBmpCodePoint(c)
  199.18 +                     && (Character.isSurrogate((char) c)
  199.19 +                         || (c == 0xfffe) || (c == 0xffff))))
  199.20                      continue;
  199.21 -                if (Surrogate.neededFor(c) && (count == limit - 1))
  199.22 +                if (Character.isSupplementaryCodePoint(c)
  199.23 +                        && (count == limit - 1))
  199.24                      continue;
  199.25                  break;
  199.26              }
  199.27              count++;
  199.28 -            if (Surrogate.neededFor(c)) {
  199.29 +            if (Character.isSupplementaryCodePoint(c)) {
  199.30                  count++;
  199.31 -                push(Surrogate.low(c));
  199.32 -                return Surrogate.high(c);
  199.33 +                push(Character.lowSurrogate(c));
  199.34 +                return Character.highSurrogate(c);
  199.35              }
  199.36              return (char)c;
  199.37          }
  199.38 @@ -137,7 +140,7 @@
  199.39                  char d = cg.next();
  199.40                  if (c != d) {
  199.41                      if (c == '?') {
  199.42 -                        if (Surrogate.isHigh(d))
  199.43 +                        if (Character.isHighSurrogate(d))
  199.44                              cg.next();
  199.45                          continue;
  199.46                      }
  199.47 @@ -187,7 +190,7 @@
  199.48              w.write(ca, 0, n);
  199.49              count += n;
  199.50          }
  199.51 -        if (Surrogate.isHigh(ca[n - 1]))
  199.52 +        if (Character.isHighSurrogate(ca[n - 1]))
  199.53              w.write(cg.next());
  199.54          w.close();
  199.55      }
  199.56 @@ -253,7 +256,8 @@
  199.57                          if (!cg.hasNext())
  199.58                              break;
  199.59                          char c = cg.next();
  199.60 -                        if (Surrogate.isHigh(c) && (cb.remaining() == 1)) {
  199.61 +                        if (Character.isHighSurrogate(c)
  199.62 +                                && cb.remaining() == 1) {
  199.63                              cg.push(c);
  199.64                              break;
  199.65                          }
  199.66 @@ -311,7 +315,7 @@
  199.67                      mismatchedEOF(csn, count + i, cg.count());
  199.68                  char d = cg.next();
  199.69                  if (c == '?') {
  199.70 -                    if (Surrogate.isHigh(d)) {
  199.71 +                    if (Character.isHighSurrogate(d)) {
  199.72                          cg.next();
  199.73                          continue;
  199.74                      }
   200.1 --- a/test/java/nio/charset/coders/Surrogate.java	Thu Jul 15 20:11:45 2010 -0700
   200.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   200.3 @@ -1,66 +0,0 @@
   200.4 -/*
   200.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   200.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   200.7 - *
   200.8 - * This code is free software; you can redistribute it and/or modify it
   200.9 - * under the terms of the GNU General Public License version 2 only, as
  200.10 - * published by the Free Software Foundation.
  200.11 - *
  200.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
  200.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  200.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  200.15 - * version 2 for more details (a copy is included in the LICENSE file that
  200.16 - * accompanied this code).
  200.17 - *
  200.18 - * You should have received a copy of the GNU General Public License version
  200.19 - * 2 along with this work; if not, write to the Free Software Foundation,
  200.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  200.21 - *
  200.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  200.23 - * or visit www.oracle.com if you need additional information or have any
  200.24 - * questions.
  200.25 - */
  200.26 -
  200.27 -public class Surrogate {
  200.28 -
  200.29 -    public static final int UCS4_SURROGATE_MIN = 0x10000;
  200.30 -    public static final int UCS4_MAX = (1 << 20) + UCS4_SURROGATE_MIN - 1;
  200.31 -
  200.32 -    // UTF-16 surrogate-character ranges
  200.33 -    //
  200.34 -    public static final char MIN_HIGH = '\uD800';
  200.35 -    public static final char MAX_HIGH = '\uDBFF';
  200.36 -    public static final char MIN_LOW  = '\uDC00';
  200.37 -    public static final char MAX_LOW  = '\uDFFF';
  200.38 -    public static final char MIN = MIN_HIGH;
  200.39 -    public static final char MAX = MAX_LOW;
  200.40 -
  200.41 -    public static boolean neededFor(int uc) {
  200.42 -        return (uc >= UCS4_SURROGATE_MIN) && (uc <= UCS4_MAX);
  200.43 -    }
  200.44 -
  200.45 -    public static boolean isHigh(int c) {
  200.46 -        return (MIN_HIGH <= c) && (c <= MAX_HIGH);
  200.47 -    }
  200.48 -
  200.49 -    static char high(int uc) {
  200.50 -        return (char)(0xd800 | (((uc - UCS4_SURROGATE_MIN) >> 10) & 0x3ff));
  200.51 -    }
  200.52 -
  200.53 -    public static boolean isLow(int c) {
  200.54 -        return (MIN_LOW <= c) && (c <= MAX_LOW);
  200.55 -    }
  200.56 -
  200.57 -    static char low(int uc) {
  200.58 -        return (char)(0xdc00 | ((uc - UCS4_SURROGATE_MIN) & 0x3ff));
  200.59 -    }
  200.60 -
  200.61 -    public static boolean is(int c) {
  200.62 -        return (MIN <= c) && (c <= MAX);
  200.63 -    }
  200.64 -
  200.65 -    static int toUCS4(char c, char d) {
  200.66 -        return (((c & 0x3ff) << 10) | (d & 0x3ff)) + 0x10000;
  200.67 -    }
  200.68 -
  200.69 -}
   201.1 --- a/test/java/nio/charset/coders/Surrogates.java	Thu Jul 15 20:11:45 2010 -0700
   201.2 +++ b/test/java/nio/charset/coders/Surrogates.java	Tue Jul 20 22:21:31 2010 -0700
   201.3 @@ -42,9 +42,8 @@
   201.4      static void initData() throws IOException {
   201.5          StringBuffer sb = new StringBuffer();
   201.6          for (int i = 0; i < LEN; i++) {
   201.7 -            int c = Surrogate.UCS4_SURROGATE_MIN + 1;
   201.8 -            sb.append(Surrogate.high(c));
   201.9 -            sb.append(Surrogate.low(c));
  201.10 +            int c = Character.MIN_SUPPLEMENTARY_CODE_POINT + 1;
  201.11 +            sb.append(Character.toChars(c));
  201.12          }
  201.13          input = sb.toString().toCharArray();
  201.14          ByteArrayOutputStream bos = new ByteArrayOutputStream();
   202.1 --- a/test/java/util/Arrays/Sorting.java	Thu Jul 15 20:11:45 2010 -0700
   202.2 +++ b/test/java/util/Arrays/Sorting.java	Tue Jul 20 22:21:31 2010 -0700
   202.3 @@ -1,5 +1,5 @@
   202.4  /*
   202.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   202.6 + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
   202.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   202.8   *
   202.9   * This code is free software; you can redistribute it and/or modify it
  202.10 @@ -43,10 +43,11 @@
  202.11  
  202.12      // Array lengths used in a long run (default)
  202.13      private static final int[] LONG_RUN_LENGTHS = {
  202.14 -        1, 2, 3, 5, 8, 13, 21, 34, 55, 100, 1000, 10000, 100000, 1000000};
  202.15 +        1, 2, 3, 5, 8, 13, 21, 34, 55, 100, 1000, 10000, 100000, 1000000 };
  202.16  
  202.17      // Array lengths used in a short run
  202.18 -    private static final int[] SHORT_RUN_LENGTHS = { 1, 2, 3, 21, 55, 1000, 10000 };
  202.19 +    private static final int[] SHORT_RUN_LENGTHS = {
  202.20 +        1, 2, 3, 21, 55, 1000, 10000 };
  202.21  
  202.22      // Random initial values used in a long run (default)
  202.23      private static final long[] LONG_RUN_RANDOMS = {666, 0xC0FFEE, 999};
  202.24 @@ -65,99 +66,338 @@
  202.25          }
  202.26          long end = System.currentTimeMillis();
  202.27  
  202.28 -        out.format("PASS in %d sec.\n", Math.round((end - start) / 1E3));
  202.29 +        out.format("\nPASSED in %d sec.\n", Math.round((end - start) / 1E3));
  202.30      }
  202.31  
  202.32      private static void testAndCheck(int[] lengths, long[] randoms) {
  202.33 +        testEmptyAndNullIntArray();
  202.34 +        testEmptyAndNullLongArray();
  202.35 +        testEmptyAndNullShortArray();
  202.36 +        testEmptyAndNullCharArray();
  202.37 +        testEmptyAndNullByteArray();
  202.38 +        testEmptyAndNullFloatArray();
  202.39 +        testEmptyAndNullDoubleArray();
  202.40 +
  202.41          for (long random : randoms) {
  202.42              reset(random);
  202.43  
  202.44 -            for (int len : lengths) {
  202.45 -                testAndCheckWithCheckSum(len, random);
  202.46 +            for (int length : lengths) {
  202.47 +                testAndCheckWithCheckSum(length, random);
  202.48              }
  202.49              reset(random);
  202.50  
  202.51 -            for (int len : lengths) {
  202.52 -                testAndCheckWithScrambling(len, random);
  202.53 +            for (int length : lengths) {
  202.54 +                testAndCheckWithScrambling(length, random);
  202.55              }
  202.56              reset(random);
  202.57  
  202.58 -            for (int len : lengths) {
  202.59 -                testAndCheckFloat(len, random);
  202.60 +            for (int length : lengths) {
  202.61 +                testAndCheckFloat(length, random);
  202.62              }
  202.63              reset(random);
  202.64  
  202.65 -            for (int len : lengths) {
  202.66 -                testAndCheckDouble(len, random);
  202.67 +            for (int length : lengths) {
  202.68 +                testAndCheckDouble(length, random);
  202.69              }
  202.70              reset(random);
  202.71  
  202.72 -            for (int len : lengths) {
  202.73 -                testAndCheckRange(len, random);
  202.74 +            for (int length : lengths) {
  202.75 +                testAndCheckRange(length, random);
  202.76              }
  202.77              reset(random);
  202.78  
  202.79 -            for (int len : lengths) {
  202.80 -                testAndCheckSubArray(len, random);
  202.81 +            for (int length : lengths) {
  202.82 +                testAndCheckSubArray(length, random);
  202.83 +            }
  202.84 +            reset(random);
  202.85 +
  202.86 +            for (int length : lengths) {
  202.87 +                testStable(length, random);
  202.88              }
  202.89          }
  202.90      }
  202.91  
  202.92 -    private static void testAndCheckSubArray(int len, long random) {
  202.93 -        int[] golden = new int[len];
  202.94 +    private static void testEmptyAndNullIntArray() {
  202.95 +        ourDescription = "Check empty and null array";
  202.96 +        Arrays.sort(new int[] {});
  202.97 +        Arrays.sort(new int[] {}, 0, 0);
  202.98  
  202.99 -        for (int m = 1; m < len / 2; m *= 2) {
 202.100 +        try {
 202.101 +            Arrays.sort((int[]) null);
 202.102 +        } catch (NullPointerException expected) {
 202.103 +            try {
 202.104 +                Arrays.sort((int[]) null, 0, 0);
 202.105 +            } catch (NullPointerException expected2) {
 202.106 +                return;
 202.107 +            }
 202.108 +            failed("Arrays.sort(int[],fromIndex,toIndex) shouldn't " +
 202.109 +                "catch null array");
 202.110 +        }
 202.111 +        failed("Arrays.sort(int[]) shouldn't catch null array");
 202.112 +    }
 202.113 +
 202.114 +    private static void testEmptyAndNullLongArray() {
 202.115 +        ourDescription = "Check empty and null array";
 202.116 +        Arrays.sort(new long[] {});
 202.117 +        Arrays.sort(new long[] {}, 0, 0);
 202.118 +
 202.119 +        try {
 202.120 +            Arrays.sort((long[]) null);
 202.121 +        } catch (NullPointerException expected) {
 202.122 +            try {
 202.123 +                Arrays.sort((long[]) null, 0, 0);
 202.124 +            } catch (NullPointerException expected2) {
 202.125 +                return;
 202.126 +            }
 202.127 +            failed("Arrays.sort(long[],fromIndex,toIndex) shouldn't " +
 202.128 +                "catch null array");
 202.129 +        }
 202.130 +        failed("Arrays.sort(long[]) shouldn't catch null array");
 202.131 +    }
 202.132 +
 202.133 +    private static void testEmptyAndNullShortArray() {
 202.134 +        ourDescription = "Check empty and null array";
 202.135 +        Arrays.sort(new short[] {});
 202.136 +        Arrays.sort(new short[] {}, 0, 0);
 202.137 +
 202.138 +        try {
 202.139 +            Arrays.sort((short[]) null);
 202.140 +        } catch (NullPointerException expected) {
 202.141 +            try {
 202.142 +                Arrays.sort((short[]) null, 0, 0);
 202.143 +            } catch (NullPointerException expected2) {
 202.144 +                return;
 202.145 +            }
 202.146 +            failed("Arrays.sort(short[],fromIndex,toIndex) shouldn't " +
 202.147 +                "catch null array");
 202.148 +        }
 202.149 +        failed("Arrays.sort(short[]) shouldn't catch null array");
 202.150 +    }
 202.151 +
 202.152 +    private static void testEmptyAndNullCharArray() {
 202.153 +        ourDescription = "Check empty and null array";
 202.154 +        Arrays.sort(new char[] {});
 202.155 +        Arrays.sort(new char[] {}, 0, 0);
 202.156 +
 202.157 +        try {
 202.158 +            Arrays.sort((char[]) null);
 202.159 +        } catch (NullPointerException expected) {
 202.160 +            try {
 202.161 +                Arrays.sort((char[]) null, 0, 0);
 202.162 +            } catch (NullPointerException expected2) {
 202.163 +                return;
 202.164 +            }
 202.165 +            failed("Arrays.sort(char[],fromIndex,toIndex) shouldn't " +
 202.166 +                "catch null array");
 202.167 +        }
 202.168 +        failed("Arrays.sort(char[]) shouldn't catch null array");
 202.169 +    }
 202.170 +
 202.171 +    private static void testEmptyAndNullByteArray() {
 202.172 +        ourDescription = "Check empty and null array";
 202.173 +        Arrays.sort(new byte[] {});
 202.174 +        Arrays.sort(new byte[] {}, 0, 0);
 202.175 +
 202.176 +        try {
 202.177 +            Arrays.sort((byte[]) null);
 202.178 +        } catch (NullPointerException expected) {
 202.179 +            try {
 202.180 +                Arrays.sort((byte[]) null, 0, 0);
 202.181 +            } catch (NullPointerException expected2) {
 202.182 +                return;
 202.183 +            }
 202.184 +            failed("Arrays.sort(byte[],fromIndex,toIndex) shouldn't " +
 202.185 +                "catch null array");
 202.186 +        }
 202.187 +        failed("Arrays.sort(byte[]) shouldn't catch null array");
 202.188 +    }
 202.189 +
 202.190 +    private static void testEmptyAndNullFloatArray() {
 202.191 +        ourDescription = "Check empty and null array";
 202.192 +        Arrays.sort(new float[] {});
 202.193 +        Arrays.sort(new float[] {}, 0, 0);
 202.194 +
 202.195 +        try {
 202.196 +            Arrays.sort((float[]) null);
 202.197 +        } catch (NullPointerException expected) {
 202.198 +            try {
 202.199 +                Arrays.sort((float[]) null, 0, 0);
 202.200 +            } catch (NullPointerException expected2) {
 202.201 +                return;
 202.202 +            }
 202.203 +            failed("Arrays.sort(float[],fromIndex,toIndex) shouldn't " +
 202.204 +                "catch null array");
 202.205 +        }
 202.206 +        failed("Arrays.sort(float[]) shouldn't catch null array");
 202.207 +    }
 202.208 +
 202.209 +    private static void testEmptyAndNullDoubleArray() {
 202.210 +        ourDescription = "Check empty and null array";
 202.211 +        Arrays.sort(new double[] {});
 202.212 +        Arrays.sort(new double[] {}, 0, 0);
 202.213 +
 202.214 +        try {
 202.215 +            Arrays.sort((double[]) null);
 202.216 +        } catch (NullPointerException expected) {
 202.217 +            try {
 202.218 +                Arrays.sort((double[]) null, 0, 0);
 202.219 +            } catch (NullPointerException expected2) {
 202.220 +                return;
 202.221 +            }
 202.222 +            failed("Arrays.sort(double[],fromIndex,toIndex) shouldn't " +
 202.223 +                "catch null array");
 202.224 +        }
 202.225 +        failed("Arrays.sort(double[]) shouldn't catch null array");
 202.226 +    }
 202.227 +
 202.228 +    private static void testAndCheckSubArray(int length, long random) {
 202.229 +        ourDescription = "Check sorting of subarray";
 202.230 +        int[] golden = new int[length];
 202.231 +        boolean newLine = false;
 202.232 +
 202.233 +        for (int m = 1; m < length / 2; m *= 2) {
 202.234 +            newLine = true;
 202.235              int fromIndex = m;
 202.236 -            int toIndex = len - m;
 202.237 +            int toIndex = length - m;
 202.238  
 202.239              prepareSubArray(golden, fromIndex, toIndex, m);
 202.240              int[] test = golden.clone();
 202.241  
 202.242              for (TypeConverter converter : TypeConverter.values()) {
 202.243 -                out.println("Test #6: " + converter +
 202.244 -                   " len = " + len + ", m = " + m);
 202.245 +                out.println("Test 'subarray': " + converter +
 202.246 +                   " length = " + length + ", m = " + m);
 202.247                  Object convertedGolden = converter.convert(golden);
 202.248                  Object convertedTest = converter.convert(test);
 202.249 +                // outArray(test);
 202.250 +                sortSubArray(convertedTest, fromIndex, toIndex);
 202.251 +                // outArray(test);
 202.252 +                checkSubArray(convertedTest, fromIndex, toIndex, m);
 202.253 +            }
 202.254 +        }
 202.255 +        if (newLine) {
 202.256 +            out.println();
 202.257 +        }
 202.258 +    }
 202.259  
 202.260 -                // outArr(test);
 202.261 -                sortSubArray(convertedTest, fromIndex, toIndex);
 202.262 -                // outArr(test);
 202.263 -                checkSubArray(convertedTest, fromIndex, toIndex, m);
 202.264 +    private static void testAndCheckRange(int length, long random) {
 202.265 +        ourDescription = "Check range check";
 202.266 +        int[] golden = new int[length];
 202.267 +
 202.268 +        for (int m = 1; m < 2 * length; m *= 2) {
 202.269 +            for (int i = 1; i <= length; i++) {
 202.270 +                golden[i - 1] = i % m + m % i;
 202.271 +            }
 202.272 +            for (TypeConverter converter : TypeConverter.values()) {
 202.273 +                out.println("Test 'range': " + converter +
 202.274 +                   ", length = " + length + ", m = " + m);
 202.275 +                Object convertedGolden = converter.convert(golden);
 202.276 +                checkRange(convertedGolden, m);
 202.277              }
 202.278          }
 202.279          out.println();
 202.280      }
 202.281  
 202.282 -    private static void testAndCheckRange(int len, long random) {
 202.283 -        int[] golden = new int[len];
 202.284 +    private static void testStable(int length, long random) {
 202.285 +        ourDescription = "Check if sorting is stable";
 202.286 +        Pair[] a = build(length);
 202.287  
 202.288 -        for (int m = 1; m < 2 * len; m *= 2) {
 202.289 -            for (int i = 1; i <= len; i++) {
 202.290 -                golden[i - 1] = i % m + m % i;
 202.291 -            }
 202.292 -            for (TypeConverter converter : TypeConverter.values()) {
 202.293 -                out.println("Test #5: " + converter +
 202.294 -                   ", len = " + len + ", m = " + m);
 202.295 -                Object convertedGolden = converter.convert(golden);
 202.296 -                sortRange(convertedGolden, m);
 202.297 -                sortEmpty(convertedGolden);
 202.298 +        out.println("Test 'stable': " + "random = " +  random +
 202.299 +            ", length = " + length);
 202.300 +        Arrays.sort(a);
 202.301 +        checkSorted(a);
 202.302 +        checkStable(a);
 202.303 +    }
 202.304 +
 202.305 +    private static void checkSorted(Pair[] a) {
 202.306 +        for (int i = 0; i < a.length - 1; i++) {
 202.307 +            if (a[i].getKey() > a[i + 1].getKey()) {
 202.308 +                failed(i, "" + a[i].getKey(), "" + a[i + 1].getKey());
 202.309              }
 202.310          }
 202.311 -        out.println();
 202.312      }
 202.313  
 202.314 -    private static void testAndCheckWithCheckSum(int len, long random) {
 202.315 -        int[] golden = new int[len];
 202.316 +    private static void checkStable(Pair[] a) {
 202.317 +        for (int i = 0; i < a.length / 4; ) {
 202.318 +            int key1 = a[i].getKey();
 202.319 +            int value1 = a[i++].getValue();
 202.320 +            int key2 = a[i].getKey();
 202.321 +            int value2 = a[i++].getValue();
 202.322 +            int key3 = a[i].getKey();
 202.323 +            int value3 = a[i++].getValue();
 202.324 +            int key4 = a[i].getKey();
 202.325 +            int value4 = a[i++].getValue();
 202.326  
 202.327 -        for (int m = 1; m < 2 * len; m *= 2) {
 202.328 +            if (!(key1 == key2 && key2 == key3 && key3 == key4)) {
 202.329 +                failed("On position " + i + " must keys are different " +
 202.330 +                    key1 + ", " + key2 + ", " + key3 + ", " + key4);
 202.331 +            }
 202.332 +            if (!(value1 < value2 && value2 < value3 && value3 < value4)) {
 202.333 +                failed("Sorting is not stable at position " + i +
 202.334 +                    ". Second values have been changed: " +  value1 + ", " +
 202.335 +                    value2 + ", " + value3 + ", " + value4);
 202.336 +            }
 202.337 +        }
 202.338 +    }
 202.339 +
 202.340 +    private static Pair[] build(int length) {
 202.341 +        Pair[] a = new Pair[length * 4];
 202.342 +
 202.343 +        for (int i = 0; i < a.length; ) {
 202.344 +            int key = ourRandom.nextInt();
 202.345 +            a[i++] = new Pair(key, 1);
 202.346 +            a[i++] = new Pair(key, 2);
 202.347 +            a[i++] = new Pair(key, 3);
 202.348 +            a[i++] = new Pair(key, 4);
 202.349 +        }
 202.350 +        return a;
 202.351 +    }
 202.352 +
 202.353 +    private static final class Pair implements Comparable<Pair> {
 202.354 +        Pair(int key, int value) {
 202.355 +            myKey = key;
 202.356 +            myValue = value;
 202.357 +        }
 202.358 +
 202.359 +        int getKey() {
 202.360 +            return myKey;
 202.361 +        }
 202.362 +
 202.363 +        int getValue() {
 202.364 +            return myValue;
 202.365 +        }
 202.366 +
 202.367 +        public int compareTo(Pair pair) {
 202.368 +            if (myKey < pair.myKey) {
 202.369 +                return -1;
 202.370 +            }
 202.371 +            if (myKey > pair.myKey) {
 202.372 +                return 1;
 202.373 +            }
 202.374 +            return 0;
 202.375 +        }
 202.376 +
 202.377 +        @Override
 202.378 +        public String toString() {
 202.379 +            return "(" + myKey + ", " + myValue + ")";
 202.380 +        }
 202.381 +
 202.382 +        private int myKey;
 202.383 +        private int myValue;
 202.384 +    }
 202.385 +
 202.386 +    private static void testAndCheckWithCheckSum(int length, long random) {
 202.387 +        ourDescription = "Check sorting with check sum";
 202.388 +        int[] golden = new int[length];
 202.389 +
 202.390 +        for (int m = 1; m < 2 * length; m *= 2) {
 202.391              for (UnsortedBuilder builder : UnsortedBuilder.values()) {
 202.392                  builder.build(golden, m);
 202.393                  int[] test = golden.clone();
 202.394  
 202.395                  for (TypeConverter converter : TypeConverter.values()) {
 202.396 -                    out.println("Test #1: " + converter + " " + builder +
 202.397 -                       "random = " +  random + ", len = " + len +
 202.398 -                       ", m = " + m);
 202.399 +                    out.println("Test 'check sum': " + converter + " " +
 202.400 +                        builder + "random = " +  random + ", length = " +
 202.401 +                        length + ", m = " + m);
 202.402                      Object convertedGolden = converter.convert(golden);
 202.403                      Object convertedTest = converter.convert(test);
 202.404                      sort(convertedTest);
 202.405 @@ -168,11 +408,12 @@
 202.406          out.println();
 202.407      }
 202.408  
 202.409 -    private static void testAndCheckWithScrambling(int len, long random) {
 202.410 -        int[] golden = new int[len];
 202.411 +    private static void testAndCheckWithScrambling(int length, long random) {
 202.412 +        ourDescription = "Check sorting with scrambling";
 202.413 +        int[] golden = new int[length];
 202.414  
 202.415          for (int m = 1; m <= 7; m++) {
 202.416 -            if (m > len) {
 202.417 +            if (m > length) {
 202.418                  break;
 202.419              }
 202.420              for (SortedBuilder builder : SortedBuilder.values()) {
 202.421 @@ -181,9 +422,9 @@
 202.422                  scramble(test);
 202.423  
 202.424                  for (TypeConverter converter : TypeConverter.values()) {
 202.425 -                    out.println("Test #2: " + converter + " " + builder +
 202.426 -                       "random = " +  random + ", len = " + len +
 202.427 -                       ", m = " + m);
 202.428 +                    out.println("Test 'scrambling': " + converter + " " +
 202.429 +                       builder + "random = " +  random + ", length = " +
 202.430 +                       length + ", m = " + m);
 202.431                      Object convertedGolden = converter.convert(golden);
 202.432                      Object convertedTest = converter.convert(test);
 202.433                      sort(convertedTest);
 202.434 @@ -194,8 +435,9 @@
 202.435          out.println();
 202.436      }
 202.437  
 202.438 -    private static void testAndCheckFloat(int len, long random) {
 202.439 -        float[] golden = new float[len];
 202.440 +    private static void testAndCheckFloat(int length, long random) {
 202.441 +        ourDescription = "Check float sorting";
 202.442 +        float[] golden = new float[length];
 202.443          final int MAX = 10;
 202.444          boolean newLine = false;
 202.445  
 202.446 @@ -204,22 +446,23 @@
 202.447                  for (int z = 0; z <= MAX; z++) {
 202.448                      for (int n = 0; n <= MAX; n++) {
 202.449                          for (int p = 0; p <= MAX; p++) {
 202.450 -                            if (a + g + z + n + p > len) {
 202.451 +                            if (a + g + z + n + p > length) {
 202.452                                  continue;
 202.453                              }
 202.454 -                            if (a + g + z + n + p < len) {
 202.455 +                            if (a + g + z + n + p < length) {
 202.456                                  continue;
 202.457                              }
 202.458                              for (FloatBuilder builder : FloatBuilder.values()) {
 202.459 -                                out.println("Test #3: random = " + random +
 202.460 -                                   ", len = " + len + ", a = " + a + ", g = " + g +
 202.461 -                                   ", z = " + z + ", n = " + n + ", p = " + p);
 202.462 +                                out.println("Test 'float': random = " + random +
 202.463 +                                   ", length = " + length + ", a = " + a +
 202.464 +                                   ", g = " + g + ", z = " + z + ", n = " + n +
 202.465 +                                   ", p = " + p);
 202.466                                  builder.build(golden, a, g, z, n, p);
 202.467                                  float[] test = golden.clone();
 202.468                                  scramble(test);
 202.469 -                                // outArr(test);
 202.470 +                                // outArray(test);
 202.471                                  sort(test);
 202.472 -                                // outArr(test);
 202.473 +                                // outArray(test);
 202.474                                  compare(test, golden, a, n, g);
 202.475                              }
 202.476                              newLine = true;
 202.477 @@ -233,8 +476,9 @@
 202.478          }
 202.479      }
 202.480  
 202.481 -    private static void testAndCheckDouble(int len, long random) {
 202.482 -        double[] golden = new double[len];
 202.483 +    private static void testAndCheckDouble(int length, long random) {
 202.484 +        ourDescription = "Check double sorting";
 202.485 +        double[] golden = new double[length];
 202.486          final int MAX = 10;
 202.487          boolean newLine = false;
 202.488  
 202.489 @@ -243,22 +487,22 @@
 202.490                  for (int z = 0; z <= MAX; z++) {
 202.491                      for (int n = 0; n <= MAX; n++) {
 202.492                          for (int p = 0; p <= MAX; p++) {
 202.493 -                            if (a + g + z + n + p > len) {
 202.494 +                            if (a + g + z + n + p > length) {
 202.495                                  continue;
 202.496                              }
 202.497 -                            if (a + g + z + n + p < len) {
 202.498 +                            if (a + g + z + n + p < length) {
 202.499                                  continue;
 202.500                              }
 202.501                              for (DoubleBuilder builder : DoubleBuilder.values()) {
 202.502 -                                out.println("Test #4: random = " + random +
 202.503 -                                   ", len = " + len + ", a = " + a + ", g = " + g +
 202.504 -                                   ", z = " + z + ", n = " + n + ", p = " + p);
 202.505 +                                out.println("Test 'double': random = " + random +
 202.506 +                                   ", length = " + length + ", a = " + a + ", g = " +
 202.507 +                                   g + ", z = " + z + ", n = " + n + ", p = " + p);
 202.508                                  builder.build(golden, a, g, z, n, p);
 202.509                                  double[] test = golden.clone();
 202.510                                  scramble(test);
 202.511 -                                // outArr(test);
 202.512 +                                // outArray(test);
 202.513                                  sort(test);
 202.514 -                                // outArr(test);
 202.515 +                                // outArray(test);
 202.516                                  compare(test, golden, a, n, g);
 202.517                              }
 202.518                              newLine = true;
 202.519 @@ -276,37 +520,29 @@
 202.520          for (int i = 0; i < fromIndex; i++) {
 202.521              a[i] = 0xBABA;
 202.522          }
 202.523 -
 202.524          for (int i = fromIndex; i < toIndex; i++) {
 202.525              a[i] = -i + m;
 202.526          }
 202.527 -
 202.528          for (int i = toIndex; i < a.length; i++) {
 202.529              a[i] = 0xDEDA;
 202.530          }
 202.531      }
 202.532  
 202.533      private static void scramble(int[] a) {
 202.534 -        int length = a.length;
 202.535 -
 202.536 -        for (int i = 0; i < length * 7; i++) {
 202.537 -            swap(a, ourRandom.nextInt(length), ourRandom.nextInt(length));
 202.538 +        for (int i = 0; i < a.length * 7; i++) {
 202.539 +            swap(a, ourRandom.nextInt(a.length), ourRandom.nextInt(a.length));
 202.540          }
 202.541      }
 202.542  
 202.543      private static void scramble(float[] a) {
 202.544 -        int length = a.length;
 202.545 -
 202.546 -        for (int i = 0; i < length * 7; i++) {
 202.547 -            swap(a, ourRandom.nextInt(length), ourRandom.nextInt(length));
 202.548 +        for (int i = 0; i < a.length * 7; i++) {
 202.549 +            swap(a, ourRandom.nextInt(a.length), ourRandom.nextInt(a.length));
 202.550          }
 202.551      }
 202.552  
 202.553      private static void scramble(double[] a) {
 202.554 -        int length = a.length;
 202.555 -
 202.556 -        for (int i = 0; i < length * 7; i++) {
 202.557 -            swap(a, ourRandom.nextInt(length), ourRandom.nextInt(length));
 202.558 +        for (int i = 0; i < a.length * 7; i++) {
 202.559 +            swap(a, ourRandom.nextInt(a.length), ourRandom.nextInt(a.length));
 202.560          }
 202.561      }
 202.562  
 202.563 @@ -393,6 +629,16 @@
 202.564                  }
 202.565                  return b;
 202.566              }
 202.567 +        },
 202.568 +        INTEGER {
 202.569 +            Object convert(int[] a) {
 202.570 +                Integer[] b = new Integer[a.length];
 202.571 +
 202.572 +                for (int i = 0; i < a.length; i++) {
 202.573 +                    b[i] = new Integer(a[i]);
 202.574 +                }
 202.575 +                return b;
 202.576 +            }
 202.577          };
 202.578  
 202.579          abstract Object convert(int[] a);
 202.580 @@ -691,6 +937,8 @@
 202.581              compare((float[]) test, (float[]) golden);
 202.582          } else if (test instanceof double[]) {
 202.583              compare((double[]) test, (double[]) golden);
 202.584 +        } else if (test instanceof Integer[]) {
 202.585 +            compare((Integer[]) test, (Integer[]) golden);
 202.586          } else {
 202.587              failed("Unknow type of array: " + test + " of class " +
 202.588                  test.getClass().getName());
 202.589 @@ -703,13 +951,13 @@
 202.590      }
 202.591  
 202.592      private static void failed(String message) {
 202.593 -        err.format("\n*** FAILED: %s\n\n", message);
 202.594 +        err.format("\n*** TEST FAILED - %s\n\n%s\n\n", ourDescription, message);
 202.595          throw new RuntimeException("Test failed - see log file for details");
 202.596      }
 202.597  
 202.598      private static void failed(int index, String value1, String value2) {
 202.599 -        failed("Array is not sorted at " + index + "-th position: " + value1 +
 202.600 -               " and " + value2);
 202.601 +        failed("Array is not sorted at " + index + "-th position: " +
 202.602 +            value1 + " and " + value2);
 202.603      }
 202.604  
 202.605      private static void checkSorted(Object object) {
 202.606 @@ -727,12 +975,22 @@
 202.607              checkSorted((float[]) object);
 202.608          } else if (object instanceof double[]) {
 202.609              checkSorted((double[]) object);
 202.610 +        } else if (object instanceof Integer[]) {
 202.611 +            checkSorted((Integer[]) object);
 202.612          } else {
 202.613              failed("Unknow type of array: " + object + " of class " +
 202.614                  object.getClass().getName());
 202.615          }
 202.616      }
 202.617  
 202.618 +    private static void compare(Integer[] a, Integer[] b) {
 202.619 +        for (int i = 0; i < a.length; i++) {
 202.620 +            if (a[i].intValue() != b[i].intValue()) {
 202.621 +                failed(i, "" + a[i], "" + b[i]);
 202.622 +            }
 202.623 +        }
 202.624 +    }
 202.625 +
 202.626      private static void compare(int[] a, int[] b) {
 202.627          for (int i = 0; i < a.length; i++) {
 202.628              if (a[i] != b[i]) {
 202.629 @@ -789,6 +1047,14 @@
 202.630          }
 202.631      }
 202.632  
 202.633 +    private static void checkSorted(Integer[] a) {
 202.634 +        for (int i = 0; i < a.length - 1; i++) {
 202.635 +            if (a[i].intValue() > a[i + 1].intValue()) {
 202.636 +                failed(i, "" + a[i], "" + a[i + 1]);
 202.637 +            }
 202.638 +        }
 202.639 +    }
 202.640 +
 202.641      private static void checkSorted(int[] a) {
 202.642          for (int i = 0; i < a.length - 1; i++) {
 202.643              if (a[i] > a[i + 1]) {
 202.644 @@ -847,7 +1113,7 @@
 202.645  
 202.646      private static void checkCheckSum(Object test, Object golden) {
 202.647          if (checkSum(test) != checkSum(golden)) {
 202.648 -            failed("Original and sorted arrays seems not identical");
 202.649 +            failed("It seems that original and sorted arrays are not identical");
 202.650          }
 202.651      }
 202.652  
 202.653 @@ -866,6 +1132,8 @@
 202.654              return checkSum((float[]) object);
 202.655          } else if (object instanceof double[]) {
 202.656              return checkSum((double[]) object);
 202.657 +        } else if (object instanceof Integer[]) {
 202.658 +            return checkSum((Integer[]) object);
 202.659          } else {
 202.660              failed("Unknow type of array: " + object + " of class " +
 202.661                  object.getClass().getName());
 202.662 @@ -873,6 +1141,15 @@
 202.663          }
 202.664      }
 202.665  
 202.666 +    private static int checkSum(Integer[] a) {
 202.667 +        int checkXorSum = 0;
 202.668 +
 202.669 +        for (Integer e : a) {
 202.670 +            checkXorSum ^= e.intValue();
 202.671 +        }
 202.672 +        return checkXorSum;
 202.673 +    }
 202.674 +
 202.675      private static int checkSum(int[] a) {
 202.676          int checkXorSum = 0;
 202.677  
 202.678 @@ -951,6 +1228,8 @@
 202.679              Arrays.sort((float[]) object);
 202.680          } else if (object instanceof double[]) {
 202.681              Arrays.sort((double[]) object);
 202.682 +        } else if (object instanceof Integer[]) {
 202.683 +            Arrays.sort((Integer[]) object);
 202.684          } else {
 202.685              failed("Unknow type of array: " + object + " of class " +
 202.686                  object.getClass().getName());
 202.687 @@ -972,6 +1251,8 @@
 202.688              Arrays.sort((float[]) object, fromIndex, toIndex);
 202.689          } else if (object instanceof double[]) {
 202.690              Arrays.sort((double[]) object, fromIndex, toIndex);
 202.691 +        } else if (object instanceof Integer[]) {
 202.692 +            Arrays.sort((Integer[]) object, fromIndex, toIndex);
 202.693          } else {
 202.694              failed("Unknow type of array: " + object + " of class " +
 202.695                  object.getClass().getName());
 202.696 @@ -993,12 +1274,36 @@
 202.697              checkSubArray((float[]) object, fromIndex, toIndex, m);
 202.698          } else if (object instanceof double[]) {
 202.699              checkSubArray((double[]) object, fromIndex, toIndex, m);
 202.700 +        } else if (object instanceof Integer[]) {
 202.701 +            checkSubArray((Integer[]) object, fromIndex, toIndex, m);
 202.702          } else {
 202.703              failed("Unknow type of array: " + object + " of class " +
 202.704                  object.getClass().getName());
 202.705          }
 202.706      }
 202.707  
 202.708 +    private static void checkSubArray(Integer[] a, int fromIndex, int toIndex, int m) {
 202.709 +        for (int i = 0; i < fromIndex; i++) {
 202.710 +            if (a[i].intValue() != 0xBABA) {
 202.711 +                failed("Range sort changes left element on position " + i +
 202.712 +                    ": " + a[i] + ", must be " + 0xBABA);
 202.713 +            }
 202.714 +        }
 202.715 +
 202.716 +        for (int i = fromIndex; i < toIndex - 1; i++) {
 202.717 +            if (a[i].intValue() > a[i + 1].intValue()) {
 202.718 +                failed(i, "" + a[i], "" + a[i + 1]);
 202.719 +            }
 202.720 +        }
 202.721 +
 202.722 +        for (int i = toIndex; i < a.length; i++) {
 202.723 +            if (a[i].intValue() != 0xDEDA) {
 202.724 +                failed("Range sort changes right element on position " + i +
 202.725 +                    ": " + a[i] + ", must be " + 0xDEDA);
 202.726 +            }
 202.727 +        }
 202.728 +    }
 202.729 +
 202.730      private static void checkSubArray(int[] a, int fromIndex, int toIndex, int m) {
 202.731          for (int i = 0; i < fromIndex; i++) {
 202.732              if (a[i] != 0xBABA) {
 202.733 @@ -1153,49 +1458,30 @@
 202.734          }
 202.735      }
 202.736  
 202.737 -    private static void sortRange(Object object, int m) {
 202.738 +    private static void checkRange(Object object, int m) {
 202.739          if (object instanceof int[]) {
 202.740 -            sortRange((int[]) object, m);
 202.741 +            checkRange((int[]) object, m);
 202.742          } else if (object instanceof long[]) {
 202.743 -            sortRange((long[]) object, m);
 202.744 +            checkRange((long[]) object, m);
 202.745          } else if (object instanceof short[]) {
 202.746 -            sortRange((short[]) object, m);
 202.747 +            checkRange((short[]) object, m);
 202.748          } else if (object instanceof byte[]) {
 202.749 -            sortRange((byte[]) object, m);
 202.750 +            checkRange((byte[]) object, m);
 202.751          } else if (object instanceof char[]) {
 202.752 -            sortRange((char[]) object, m);
 202.753 +            checkRange((char[]) object, m);
 202.754          } else if (object instanceof float[]) {
 202.755 -            sortRange((float[]) object, m);
 202.756 +            checkRange((float[]) object, m);
 202.757          } else if (object instanceof double[]) {
 202.758 -            sortRange((double[]) object, m);
 202.759 +            checkRange((double[]) object, m);
 202.760 +        } else if (object instanceof Integer[]) {
 202.761 +            checkRange((Integer[]) object, m);
 202.762          } else {
 202.763              failed("Unknow type of array: " + object + " of class " +
 202.764                  object.getClass().getName());
 202.765          }
 202.766      }
 202.767  
 202.768 -    private static void sortEmpty(Object object) {
 202.769 -        if (object instanceof int[]) {
 202.770 -            Arrays.sort(new int [] {});
 202.771 -        } else if (object instanceof long[]) {
 202.772 -            Arrays.sort(new long [] {});
 202.773 -        } else if (object instanceof short[]) {
 202.774 -            Arrays.sort(new short [] {});
 202.775 -        } else if (object instanceof byte[]) {
 202.776 -            Arrays.sort(new byte [] {});
 202.777 -        } else if (object instanceof char[]) {
 202.778 -            Arrays.sort(new char [] {});
 202.779 -        } else if (object instanceof float[]) {
 202.780 -            Arrays.sort(new float [] {});
 202.781 -        } else if (object instanceof double[]) {
 202.782 -            Arrays.sort(new double [] {});
 202.783 -        } else {
 202.784 -            failed("Unknow type of array: " + object + " of class " +
 202.785 -                object.getClass().getName());
 202.786 -        }
 202.787 -    }
 202.788 -
 202.789 -    private static void sortRange(int[] a, int m) {
 202.790 +    private static void checkRange(Integer[] a, int m) {
 202.791          try {
 202.792              Arrays.sort(a, m + 1, m);
 202.793  
 202.794 @@ -1224,7 +1510,7 @@
 202.795          }
 202.796      }
 202.797  
 202.798 -    private static void sortRange(long[] a, int m) {
 202.799 +    private static void checkRange(int[] a, int m) {
 202.800          try {
 202.801              Arrays.sort(a, m + 1, m);
 202.802  
 202.803 @@ -1253,7 +1539,7 @@
 202.804          }
 202.805      }
 202.806  
 202.807 -    private static void sortRange(byte[] a, int m) {
 202.808 +    private static void checkRange(long[] a, int m) {
 202.809          try {
 202.810              Arrays.sort(a, m + 1, m);
 202.811  
 202.812 @@ -1282,7 +1568,7 @@
 202.813          }
 202.814      }
 202.815  
 202.816 -    private static void sortRange(short[] a, int m) {
 202.817 +    private static void checkRange(byte[] a, int m) {
 202.818          try {
 202.819              Arrays.sort(a, m + 1, m);
 202.820  
 202.821 @@ -1311,7 +1597,7 @@
 202.822          }
 202.823      }
 202.824  
 202.825 -    private static void sortRange(char[] a, int m) {
 202.826 +    private static void checkRange(short[] a, int m) {
 202.827          try {
 202.828              Arrays.sort(a, m + 1, m);
 202.829  
 202.830 @@ -1340,7 +1626,7 @@
 202.831          }
 202.832      }
 202.833  
 202.834 -    private static void sortRange(float[] a, int m) {
 202.835 +    private static void checkRange(char[] a, int m) {
 202.836          try {
 202.837              Arrays.sort(a, m + 1, m);
 202.838  
 202.839 @@ -1369,7 +1655,36 @@
 202.840          }
 202.841      }
 202.842  
 202.843 -    private static void sortRange(double[] a, int m) {
 202.844 +    private static void checkRange(float[] a, int m) {
 202.845 +        try {
 202.846 +            Arrays.sort(a, m + 1, m);
 202.847 +
 202.848 +            failed("Sort does not throw IllegalArgumentException " +
 202.849 +                " as expected: fromIndex = " + (m + 1) +
 202.850 +                " toIndex = " + m);
 202.851 +        }
 202.852 +        catch (IllegalArgumentException iae) {
 202.853 +            try {
 202.854 +                Arrays.sort(a, -m, a.length);
 202.855 +
 202.856 +                failed("Sort does not throw ArrayIndexOutOfBoundsException " +
 202.857 +                    " as expected: fromIndex = " + (-m));
 202.858 +            }
 202.859 +            catch (ArrayIndexOutOfBoundsException aoe) {
 202.860 +                try {
 202.861 +                    Arrays.sort(a, 0, a.length + m);
 202.862 +
 202.863 +                    failed("Sort does not throw ArrayIndexOutOfBoundsException " +
 202.864 +                        " as expected: toIndex = " + (a.length + m));
 202.865 +                }
 202.866 +                catch (ArrayIndexOutOfBoundsException aie) {
 202.867 +                    return;
 202.868 +                }
 202.869 +            }
 202.870 +        }
 202.871 +    }
 202.872 +
 202.873 +    private static void checkRange(double[] a, int m) {
 202.874          try {
 202.875              Arrays.sort(a, m + 1, m);
 202.876  
 202.877 @@ -1410,31 +1725,36 @@
 202.878          ourSecond = 0;
 202.879      }
 202.880  
 202.881 -    private static void outArr(int[] a) {
 202.882 +    private static void outArray(Object[] a) {
 202.883          for (int i = 0; i < a.length; i++) {
 202.884              out.print(a[i] + " ");
 202.885          }
 202.886          out.println();
 202.887 -        out.println();
 202.888      }
 202.889  
 202.890 -    private static void outArr(float[] a) {
 202.891 +    private static void outArray(int[] a) {
 202.892          for (int i = 0; i < a.length; i++) {
 202.893              out.print(a[i] + " ");
 202.894          }
 202.895          out.println();
 202.896 -        out.println();
 202.897      }
 202.898  
 202.899 -    private static void outArr(double[] a) {
 202.900 +    private static void outArray(float[] a) {
 202.901          for (int i = 0; i < a.length; i++) {
 202.902              out.print(a[i] + " ");
 202.903          }
 202.904          out.println();
 202.905 +    }
 202.906 +
 202.907 +    private static void outArray(double[] a) {
 202.908 +        for (int i = 0; i < a.length; i++) {
 202.909 +            out.print(a[i] + " ");
 202.910 +        }
 202.911          out.println();
 202.912      }
 202.913  
 202.914      private static int ourFirst;
 202.915      private static int ourSecond;
 202.916      private static Random ourRandom;
 202.917 +    private static String ourDescription;
 202.918  }
   203.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   203.2 +++ b/test/java/util/logging/AnonLoggerWeakRefLeak.java	Tue Jul 20 22:21:31 2010 -0700
   203.3 @@ -0,0 +1,76 @@
   203.4 +/*
   203.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   203.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   203.7 + *
   203.8 + * This code is free software; you can redistribute it and/or modify it
   203.9 + * under the terms of the GNU General Public License version 2 only, as
  203.10 + * published by the Free Software Foundation.
  203.11 + *
  203.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  203.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  203.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  203.15 + * version 2 for more details (a copy is included in the LICENSE file that
  203.16 + * accompanied this code).
  203.17 + *
  203.18 + * You should have received a copy of the GNU General Public License version
  203.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  203.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  203.21 + *
  203.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  203.23 + * or visit www.oracle.com if you need additional information or have any
  203.24 + * questions.
  203.25 + */
  203.26 +
  203.27 +import java.util.logging.*;
  203.28 +
  203.29 +public class AnonLoggerWeakRefLeak {
  203.30 +    public static int DEFAULT_LOOP_TIME = 60;  // time is in seconds
  203.31 +
  203.32 +    public static void main(String[] args) {
  203.33 +        int loop_time = 0;
  203.34 +        int max_loop_time = DEFAULT_LOOP_TIME;
  203.35 +
  203.36 +        if (args.length == 0) {
  203.37 +            System.out.println("INFO: using default time of "
  203.38 +                + max_loop_time + " seconds.");
  203.39 +        } else {
  203.40 +            try {
  203.41 +                max_loop_time = Integer.parseInt(args[0]);
  203.42 +            } catch (NumberFormatException nfe) {
  203.43 +                System.err.println("Error: '" + args[0]
  203.44 +                    + "': is not a valid seconds value.");
  203.45 +                System.err.println("Usage: AnonLoggerWeakRefLeak [seconds]");
  203.46 +                System.exit(1);
  203.47 +            }
  203.48 +        }
  203.49 +
  203.50 +        long count = 0;
  203.51 +        long now = 0;
  203.52 +        long startTime = System.currentTimeMillis();
  203.53 +
  203.54 +        while (now < (startTime + (max_loop_time * 1000))) {
  203.55 +            if ((count % 1000) == 0) {
  203.56 +                // Print initial call count to let caller know that
  203.57 +                // we're up and running and then periodically
  203.58 +                System.out.println("INFO: call count = " + count);
  203.59 +            }
  203.60 +
  203.61 +            for (int i = 0; i < 100; i++) {
  203.62 +                // this Logger call is leaking a WeakReference in Logger.kids
  203.63 +                java.util.logging.Logger.getAnonymousLogger();
  203.64 +                count++;
  203.65 +            }
  203.66 +
  203.67 +            try {
  203.68 +                // delay for 1/10 of a second to avoid CPU saturation
  203.69 +                Thread.sleep(100);
  203.70 +            } catch (InterruptedException ie) {
  203.71 +                // ignore any exceptions
  203.72 +            }
  203.73 +
  203.74 +            now = System.currentTimeMillis();
  203.75 +        }
  203.76 +
  203.77 +        System.out.println("INFO: final loop count = " + count);
  203.78 +    }
  203.79 +}
   204.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   204.2 +++ b/test/java/util/logging/AnonLoggerWeakRefLeak.sh	Tue Jul 20 22:21:31 2010 -0700
   204.3 @@ -0,0 +1,247 @@
   204.4 +#
   204.5 +# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   204.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   204.7 +#
   204.8 +# This code is free software; you can redistribute it and/or modify it
   204.9 +# under the terms of the GNU General Public License version 2 only, as
  204.10 +# published by the Free Software Foundation.
  204.11 +#
  204.12 +# This code is distributed in the hope that it will be useful, but WITHOUT
  204.13 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  204.14 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  204.15 +# version 2 for more details (a copy is included in the LICENSE file that
  204.16 +# accompanied this code).
  204.17 +#
  204.18 +# You should have received a copy of the GNU General Public License version
  204.19 +# 2 along with this work; if not, write to the Free Software Foundation,
  204.20 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  204.21 +#
  204.22 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  204.23 +# or visit www.oracle.com if you need additional information or have any
  204.24 +# questions.
  204.25 +#
  204.26 +
  204.27 +# @test
  204.28 +# @bug 6942989
  204.29 +# @ignore until 6964018 is fixed
  204.30 +# @summary Check for WeakReference leak in anonymous Logger objects
  204.31 +# @author Daniel D. Daugherty
  204.32 +#
  204.33 +# @run build AnonLoggerWeakRefLeak
  204.34 +# @run shell/timeout=180 AnonLoggerWeakRefLeak.sh
  204.35 +
  204.36 +# The timeout is: 2 minutes for infrastructure and 1 minute for the test
  204.37 +#
  204.38 +
  204.39 +if [ "${TESTJAVA}" = "" ]
  204.40 +then
  204.41 +  echo "TESTJAVA not set.  Test cannot execute.  Failed."
  204.42 +  exit 1
  204.43 +fi
  204.44 +
  204.45 +if [ "${TESTSRC}" = "" ]
  204.46 +then
  204.47 +  echo "TESTSRC not set.  Test cannot execute.  Failed."
  204.48 +  exit 1
  204.49 +fi
  204.50 +
  204.51 +if [ "${TESTCLASSES}" = "" ]
  204.52 +then
  204.53 +  echo "TESTCLASSES not set.  Test cannot execute.  Failed."
  204.54 +  exit 1
  204.55 +fi
  204.56 +
  204.57 +JAVA="${TESTJAVA}"/bin/java
  204.58 +JMAP="${TESTJAVA}"/bin/jmap
  204.59 +JPS="${TESTJAVA}"/bin/jps
  204.60 +
  204.61 +set -eu
  204.62 +
  204.63 +TEST_NAME="AnonLoggerWeakRefLeak"
  204.64 +TARGET_CLASS="java\.lang\.ref\.WeakReference"
  204.65 +
  204.66 +is_cygwin=false
  204.67 +is_mks=false
  204.68 +is_windows=false
  204.69 +
  204.70 +case `uname -s` in
  204.71 +CYGWIN*)
  204.72 +    is_cygwin=true
  204.73 +    is_windows=true
  204.74 +    ;;
  204.75 +Windows_*)
  204.76 +    is_mks=true
  204.77 +    is_windows=true
  204.78 +    ;;
  204.79 +*)
  204.80 +    ;;
  204.81 +esac
  204.82 +
  204.83 +
  204.84 +# wrapper for grep
  204.85 +#
  204.86 +grep_cmd() {
  204.87 +    set +e
  204.88 +    if $is_windows; then
  204.89 +        # need dos2unix to get rid of CTRL-M chars from java output
  204.90 +        dos2unix | grep "$@"
  204.91 +        status="$?"
  204.92 +    else
  204.93 +        grep "$@"
  204.94 +        status="$?"
  204.95 +    fi
  204.96 +    set -e
  204.97 +}
  204.98 +
  204.99 +
 204.100 +# MAIN begins here
 204.101 +#
 204.102 +
 204.103 +seconds=
 204.104 +if [ "$#" -gt 0 ]; then
 204.105 +    seconds="$1"
 204.106 +fi
 204.107 +
 204.108 +# see if this version of jmap supports the '-histo:live' option
 204.109 +jmap_option="-histo:live"
 204.110 +set +e
 204.111 +"${JMAP}" "$jmap_option" 0 > "$TEST_NAME.jmap" 2>&1
 204.112 +grep '^Usage: ' "$TEST_NAME.jmap" > /dev/null 2>&1
 204.113 +status="$?"
 204.114 +set -e
 204.115 +if [ "$status" = 0 ]; then
 204.116 +    echo "INFO: switching jmap option from '$jmap_option'\c"
 204.117 +    jmap_option="-histo"
 204.118 +    echo " to '$jmap_option'."
 204.119 +fi
 204.120 +
 204.121 +"${JAVA}" ${TESTVMOPTS} -classpath "${TESTCLASSES}" \
 204.122 +    "$TEST_NAME" $seconds > "$TEST_NAME.log" 2>&1 &
 204.123 +test_pid="$!"
 204.124 +echo "INFO: starting $TEST_NAME as pid = $test_pid"
 204.125 +
 204.126 +# wait for test program to get going
 204.127 +count=0
 204.128 +while [ "$count" -lt 30 ]; do
 204.129 +    sleep 2
 204.130 +    grep_cmd '^INFO: call count = 0$' < "$TEST_NAME.log" > /dev/null 2>&1
 204.131 +    if [ "$status" = 0 ]; then
 204.132 +        break
 204.133 +    fi
 204.134 +    count=`expr $count + 1`
 204.135 +done
 204.136 +
 204.137 +if [ "$count" -ge 30 ]; then
 204.138 +    echo "ERROR: $TEST_NAME failed to get going." >&2
 204.139 +    echo "INFO: killing $test_pid"
 204.140 +    kill "$test_pid"
 204.141 +    exit 1
 204.142 +elif [ "$count" -gt 1 ]; then
 204.143 +    echo "INFO: $TEST_NAME took $count loops to start."
 204.144 +fi
 204.145 +
 204.146 +if $is_cygwin; then
 204.147 +    # We need the Windows pid for jmap and not the Cygwin pid.
 204.148 +    # Note: '\t' works on Cygwin, but doesn't seem to work on Solaris.
 204.149 +    jmap_pid=`"${JPS}"| grep_cmd "[ \t]$TEST_NAME$" | sed 's/[ \t].*//'`
 204.150 +    if [ -z "$jmap_pid" ]; then
 204.151 +        echo "FAIL: jps could not map Cygwin pid to Windows pid." >&2
 204.152 +        echo "INFO: killing $test_pid"
 204.153 +        kill "$test_pid"
 204.154 +        exit 2
 204.155 +    fi
 204.156 +    echo "INFO: pid = $test_pid maps to Windows pid = $jmap_pid"
 204.157 +else
 204.158 +    jmap_pid="$test_pid"
 204.159 +fi
 204.160 +
 204.161 +decreasing_cnt=0
 204.162 +increasing_cnt=0
 204.163 +loop_cnt=0
 204.164 +prev_instance_cnt=0
 204.165 +
 204.166 +while true; do
 204.167 +    # Output format for 'jmap -histo' in JDK1.5.0:
 204.168 +    #
 204.169 +    #     <#bytes> <#instances> <class_name>
 204.170 +    #
 204.171 +    # Output format for 'jmap -histo:live':
 204.172 +    #
 204.173 +    #     <num>: <#instances> <#bytes> <class_name>
 204.174 +    #
 204.175 +    set +e
 204.176 +    "${JMAP}" "$jmap_option" "$jmap_pid" > "$TEST_NAME.jmap" 2>&1
 204.177 +    status="$?"
 204.178 +    set -e
 204.179 +
 204.180 +    if [ "$status" != 0 ]; then
 204.181 +        echo "INFO: jmap exited with exit code = $status"
 204.182 +        if [ "$loop_cnt" = 0 ]; then
 204.183 +            echo "INFO: on the first iteration so no samples were taken."
 204.184 +            echo "INFO: start of jmap output:"
 204.185 +            cat "$TEST_NAME.jmap"
 204.186 +            echo "INFO: end of jmap output."
 204.187 +            echo "FAIL: jmap is unable to take any samples." >&2
 204.188 +            echo "INFO: killing $test_pid"
 204.189 +            kill "$test_pid"
 204.190 +            exit 2
 204.191 +        fi
 204.192 +        echo "INFO: The likely reason is that $TEST_NAME has finished running."
 204.193 +        break
 204.194 +    fi
 204.195 +
 204.196 +    instance_cnt=`grep_cmd "[ 	]$TARGET_CLASS$" \
 204.197 +        < "$TEST_NAME.jmap" \
 204.198 +        | sed '
 204.199 +            # strip leading whitespace; does nothing in JDK1.5.0
 204.200 +            s/^[ 	][ 	]*//
 204.201 +            # strip <#bytes> in JDK1.5.0; does nothing otherwise
 204.202 +            s/^[1-9][0-9]*[ 	][ 	]*//
 204.203 +            # strip <num>: field; does nothing in JDK1.5.0
 204.204 +            s/^[1-9][0-9]*:[ 	][ 	]*//
 204.205 +            # strip <class_name> field
 204.206 +            s/[ 	].*//
 204.207 +            '`
 204.208 +    if [ -z "$instance_cnt" ]; then
 204.209 +        echo "INFO: instance count is unexpectedly empty"
 204.210 +        if [ "$loop_cnt" = 0 ]; then
 204.211 +            echo "INFO: on the first iteration so no sample was found."
 204.212 +            echo "INFO: There is likely a problem with the sed filter."
 204.213 +            echo "INFO: start of jmap output:"
 204.214 +            cat "$TEST_NAME.jmap"
 204.215 +            echo "INFO: end of jmap output."
 204.216 +            echo "FAIL: cannot find the instance count value." >&2
 204.217 +            echo "INFO: killing $test_pid"
 204.218 +            kill "$test_pid"
 204.219 +            exit 2
 204.220 +        fi
 204.221 +    else
 204.222 +        echo "INFO: instance_cnt = $instance_cnt"
 204.223 +
 204.224 +        if [ "$instance_cnt" -gt "$prev_instance_cnt" ]; then
 204.225 +            increasing_cnt=`expr $increasing_cnt + 1`
 204.226 +        else
 204.227 +            decreasing_cnt=`expr $decreasing_cnt + 1`
 204.228 +        fi
 204.229 +        prev_instance_cnt="$instance_cnt"
 204.230 +    fi
 204.231 +
 204.232 +    # delay between samples
 204.233 +    sleep 5
 204.234 +
 204.235 +    loop_cnt=`expr $loop_cnt + 1`
 204.236 +done
 204.237 +
 204.238 +echo "INFO: increasing_cnt = $increasing_cnt"
 204.239 +echo "INFO: decreasing_cnt = $decreasing_cnt"
 204.240 +
 204.241 +echo "INFO: The instance count of" `eval echo $TARGET_CLASS` "objects"
 204.242 +if [ "$decreasing_cnt" = 0 ]; then
 204.243 +    echo "INFO: is always increasing."
 204.244 +    echo "FAIL: This indicates that there is a memory leak." >&2
 204.245 +    exit 2
 204.246 +fi
 204.247 +
 204.248 +echo "INFO: is both increasing and decreasing."
 204.249 +echo "PASS: This indicates that there is not a memory leak."
 204.250 +exit 0
   205.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   205.2 +++ b/test/java/util/logging/LoggerWeakRefLeak.java	Tue Jul 20 22:21:31 2010 -0700
   205.3 @@ -0,0 +1,89 @@
   205.4 +/*
   205.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   205.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   205.7 + *
   205.8 + * This code is free software; you can redistribute it and/or modify it
   205.9 + * under the terms of the GNU General Public License version 2 only, as
  205.10 + * published by the Free Software Foundation.
  205.11 + *
  205.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  205.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  205.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  205.15 + * version 2 for more details (a copy is included in the LICENSE file that
  205.16 + * accompanied this code).
  205.17 + *
  205.18 + * You should have received a copy of the GNU General Public License version
  205.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  205.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  205.21 + *
  205.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  205.23 + * or visit www.oracle.com if you need additional information or have any
  205.24 + * questions.
  205.25 + */
  205.26 +
  205.27 +import java.util.logging.*;
  205.28 +
  205.29 +public class LoggerWeakRefLeak {
  205.30 +    // AnonLoggerWeakRefLeak checks for one weak reference leak.
  205.31 +    // LoggerWeakRefLeak checks for two weak reference leaks so
  205.32 +    // this test runs twice as long, by default.
  205.33 +    public static int DEFAULT_LOOP_TIME = 120;  // time is in seconds
  205.34 +
  205.35 +    public static void main(String[] args) {
  205.36 +        int loop_time = 0;
  205.37 +        int max_loop_time = DEFAULT_LOOP_TIME;
  205.38 +
  205.39 +        if (args.length == 0) {
  205.40 +            System.out.println("INFO: using default time of "
  205.41 +                + max_loop_time + " seconds.");
  205.42 +        } else {
  205.43 +            try {
  205.44 +                max_loop_time = Integer.parseInt(args[0]);
  205.45 +            } catch (NumberFormatException nfe) {
  205.46 +                System.err.println("Error: '" + args[0]
  205.47 +                    + "': is not a valid seconds value.");
  205.48 +                System.err.println("Usage: LoggerWeakRefLeak [seconds]");
  205.49 +                System.exit(1);
  205.50 +            }
  205.51 +        }
  205.52 +
  205.53 +        long count = 0;
  205.54 +        int  loggerCount = 0;
  205.55 +        long now = 0;
  205.56 +        long startTime = System.currentTimeMillis();
  205.57 +
  205.58 +        while (now < (startTime + (max_loop_time * 1000))) {
  205.59 +            if ((count % 1000) == 0) {
  205.60 +                // Print initial call count to let caller know that
  205.61 +                // we're up and running and then periodically
  205.62 +                System.out.println("INFO: call count = " + count);
  205.63 +            }
  205.64 +
  205.65 +            for (int i = 0; i < 100; i++) {
  205.66 +                // This Logger call is leaking two different WeakReferences:
  205.67 +                // - one in LogManager.LogNode
  205.68 +                // - one in Logger.kids
  205.69 +                java.util.logging.Logger.getLogger("logger-" + loggerCount);
  205.70 +                count++;
  205.71 +                if (++loggerCount >= 25000) {
  205.72 +                    // Limit the Logger namespace used by the test so
  205.73 +                    // the weak refs in LogManager.loggers that are
  205.74 +                    // being properly managed don't skew the counts
  205.75 +                    // by too much.
  205.76 +                    loggerCount = 0;
  205.77 +                }
  205.78 +            }
  205.79 +
  205.80 +            try {
  205.81 +                // delay for 1/10 of a second to avoid CPU saturation
  205.82 +                Thread.sleep(100);
  205.83 +            } catch (InterruptedException ie) {
  205.84 +                // ignore any exceptions
  205.85 +            }
  205.86 +
  205.87 +            now = System.currentTimeMillis();
  205.88 +        }
  205.89 +
  205.90 +        System.out.println("INFO: final loop count = " + count);
  205.91 +    }
  205.92 +}
   206.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   206.2 +++ b/test/java/util/logging/LoggerWeakRefLeak.sh	Tue Jul 20 22:21:31 2010 -0700
   206.3 @@ -0,0 +1,247 @@
   206.4 +#
   206.5 +# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   206.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   206.7 +#
   206.8 +# This code is free software; you can redistribute it and/or modify it
   206.9 +# under the terms of the GNU General Public License version 2 only, as
  206.10 +# published by the Free Software Foundation.
  206.11 +#
  206.12 +# This code is distributed in the hope that it will be useful, but WITHOUT
  206.13 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  206.14 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  206.15 +# version 2 for more details (a copy is included in the LICENSE file that
  206.16 +# accompanied this code).
  206.17 +#
  206.18 +# You should have received a copy of the GNU General Public License version
  206.19 +# 2 along with this work; if not, write to the Free Software Foundation,
  206.20 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  206.21 +#
  206.22 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  206.23 +# or visit www.oracle.com if you need additional information or have any
  206.24 +# questions.
  206.25 +#
  206.26 +
  206.27 +# @test
  206.28 +# @bug 6942989
  206.29 +# @ignore until 6964018 is fixed
  206.30 +# @summary Check for WeakReference leak in Logger objects
  206.31 +# @author Daniel D. Daugherty
  206.32 +#
  206.33 +# @run build LoggerWeakRefLeak
  206.34 +# @run shell/timeout=240 LoggerWeakRefLeak.sh
  206.35 +
  206.36 +# The timeout is: 2 minutes for infrastructure and 1 minute for the test
  206.37 +#
  206.38 +
  206.39 +if [ "${TESTJAVA}" = "" ]
  206.40 +then
  206.41 +  echo "TESTJAVA not set.  Test cannot execute.  Failed."
  206.42 +  exit 1
  206.43 +fi
  206.44 +
  206.45 +if [ "${TESTSRC}" = "" ]
  206.46 +then
  206.47 +  echo "TESTSRC not set.  Test cannot execute.  Failed."
  206.48 +  exit 1
  206.49 +fi
  206.50 +
  206.51 +if [ "${TESTCLASSES}" = "" ]
  206.52 +then
  206.53 +  echo "TESTCLASSES not set.  Test cannot execute.  Failed."
  206.54 +  exit 1
  206.55 +fi
  206.56 +
  206.57 +JAVA="${TESTJAVA}"/bin/java
  206.58 +JMAP="${TESTJAVA}"/bin/jmap
  206.59 +JPS="${TESTJAVA}"/bin/jps
  206.60 +
  206.61 +set -eu
  206.62 +
  206.63 +TEST_NAME="LoggerWeakRefLeak"
  206.64 +TARGET_CLASS="java\.lang\.ref\.WeakReference"
  206.65 +
  206.66 +is_cygwin=false
  206.67 +is_mks=false
  206.68 +is_windows=false
  206.69 +
  206.70 +case `uname -s` in
  206.71 +CYGWIN*)
  206.72 +    is_cygwin=true
  206.73 +    is_windows=true
  206.74 +    ;;
  206.75 +Windows_*)
  206.76 +    is_mks=true
  206.77 +    is_windows=true
  206.78 +    ;;
  206.79 +*)
  206.80 +    ;;
  206.81 +esac
  206.82 +
  206.83 +
  206.84 +# wrapper for grep
  206.85 +#
  206.86 +grep_cmd() {
  206.87 +    set +e
  206.88 +    if $is_windows; then
  206.89 +        # need dos2unix to get rid of CTRL-M chars from java output
  206.90 +        dos2unix | grep "$@"
  206.91 +        status="$?"
  206.92 +    else
  206.93 +        grep "$@"
  206.94 +        status="$?"
  206.95 +    fi
  206.96 +    set -e
  206.97 +}
  206.98 +
  206.99 +
 206.100 +# MAIN begins here
 206.101 +#
 206.102 +
 206.103 +seconds=
 206.104 +if [ "$#" -gt 0 ]; then
 206.105 +    seconds="$1"
 206.106 +fi
 206.107 +
 206.108 +# see if this version of jmap supports the '-histo:live' option
 206.109 +jmap_option="-histo:live"
 206.110 +set +e
 206.111 +"${JMAP}" "$jmap_option" 0 > "$TEST_NAME.jmap" 2>&1
 206.112 +grep '^Usage: ' "$TEST_NAME.jmap" > /dev/null 2>&1
 206.113 +status="$?"
 206.114 +set -e
 206.115 +if [ "$status" = 0 ]; then
 206.116 +    echo "INFO: switching jmap option from '$jmap_option'\c"
 206.117 +    jmap_option="-histo"
 206.118 +    echo " to '$jmap_option'."
 206.119 +fi
 206.120 +
 206.121 +"${JAVA}" ${TESTVMOPTS} -classpath "${TESTCLASSES}" \
 206.122 +    "$TEST_NAME" $seconds > "$TEST_NAME.log" 2>&1 &
 206.123 +test_pid="$!"
 206.124 +echo "INFO: starting $TEST_NAME as pid = $test_pid"
 206.125 +
 206.126 +# wait for test program to get going
 206.127 +count=0
 206.128 +while [ "$count" -lt 30 ]; do
 206.129 +    sleep 2
 206.130 +    grep_cmd '^INFO: call count = 0$' < "$TEST_NAME.log" > /dev/null 2>&1
 206.131 +    if [ "$status" = 0 ]; then
 206.132 +        break
 206.133 +    fi
 206.134 +    count=`expr $count + 1`
 206.135 +done
 206.136 +
 206.137 +if [ "$count" -ge 30 ]; then
 206.138 +    echo "ERROR: $TEST_NAME failed to get going." >&2
 206.139 +    echo "INFO: killing $test_pid"
 206.140 +    kill "$test_pid"
 206.141 +    exit 1
 206.142 +elif [ "$count" -gt 1 ]; then
 206.143 +    echo "INFO: $TEST_NAME took $count loops to start."
 206.144 +fi
 206.145 +
 206.146 +if $is_cygwin; then
 206.147 +    # We need the Windows pid for jmap and not the Cygwin pid.
 206.148 +    # Note: '\t' works on Cygwin, but doesn't seem to work on Solaris.
 206.149 +    jmap_pid=`"${JPS}"| grep_cmd "[ \t]$TEST_NAME$" | sed 's/[ \t].*//'`
 206.150 +    if [ -z "$jmap_pid" ]; then
 206.151 +        echo "FAIL: jps could not map Cygwin pid to Windows pid." >&2
 206.152 +        echo "INFO: killing $test_pid"
 206.153 +        kill "$test_pid"
 206.154 +        exit 2
 206.155 +    fi
 206.156 +    echo "INFO: pid = $test_pid maps to Windows pid = $jmap_pid"
 206.157 +else
 206.158 +    jmap_pid="$test_pid"
 206.159 +fi
 206.160 +
 206.161 +decreasing_cnt=0
 206.162 +increasing_cnt=0
 206.163 +loop_cnt=0
 206.164 +prev_instance_cnt=0
 206.165 +
 206.166 +while true; do
 206.167 +    # Output format for 'jmap -histo' in JDK1.5.0:
 206.168 +    #
 206.169 +    #     <#bytes> <#instances> <class_name>
 206.170 +    #
 206.171 +    # Output format for 'jmap -histo:live':
 206.172 +    #
 206.173 +    #     <num>: <#instances> <#bytes> <class_name>
 206.174 +    #
 206.175 +    set +e
 206.176 +    "${JMAP}" "$jmap_option" "$jmap_pid" > "$TEST_NAME.jmap" 2>&1
 206.177 +    status="$?"
 206.178 +    set -e
 206.179 +
 206.180 +    if [ "$status" != 0 ]; then
 206.181 +        echo "INFO: jmap exited with exit code = $status"
 206.182 +        if [ "$loop_cnt" = 0 ]; then
 206.183 +            echo "INFO: on the first iteration so no samples were taken."
 206.184 +            echo "INFO: start of jmap output:"
 206.185 +            cat "$TEST_NAME.jmap"
 206.186 +            echo "INFO: end of jmap output."
 206.187 +            echo "FAIL: jmap is unable to take any samples." >&2
 206.188 +            echo "INFO: killing $test_pid"
 206.189 +            kill "$test_pid"
 206.190 +            exit 2
 206.191 +        fi
 206.192 +        echo "INFO: The likely reason is that $TEST_NAME has finished running."
 206.193 +        break
 206.194 +    fi
 206.195 +
 206.196 +    instance_cnt=`grep_cmd "[ 	]$TARGET_CLASS$" \
 206.197 +        < "$TEST_NAME.jmap" \
 206.198 +        | sed '
 206.199 +            # strip leading whitespace; does nothing in JDK1.5.0
 206.200 +            s/^[ 	][ 	]*//
 206.201 +            # strip <#bytes> in JDK1.5.0; does nothing otherwise
 206.202 +            s/^[1-9][0-9]*[ 	][ 	]*//
 206.203 +            # strip <num>: field; does nothing in JDK1.5.0
 206.204 +            s/^[1-9][0-9]*:[ 	][ 	]*//
 206.205 +            # strip <class_name> field
 206.206 +            s/[ 	].*//
 206.207 +            '`
 206.208 +    if [ -z "$instance_cnt" ]; then
 206.209 +        echo "INFO: instance count is unexpectedly empty"
 206.210 +        if [ "$loop_cnt" = 0 ]; then
 206.211 +            echo "INFO: on the first iteration so no sample was found."
 206.212 +            echo "INFO: There is likely a problem with the sed filter."
 206.213 +            echo "INFO: start of jmap output:"
 206.214 +            cat "$TEST_NAME.jmap"
 206.215 +            echo "INFO: end of jmap output."
 206.216 +            echo "FAIL: cannot find the instance count value." >&2
 206.217 +            echo "INFO: killing $test_pid"
 206.218 +            kill "$test_pid"
 206.219 +            exit 2
 206.220 +        fi
 206.221 +    else
 206.222 +        echo "INFO: instance_cnt = $instance_cnt"
 206.223 +
 206.224 +        if [ "$instance_cnt" -gt "$prev_instance_cnt" ]; then
 206.225 +            increasing_cnt=`expr $increasing_cnt + 1`
 206.226 +        else
 206.227 +            decreasing_cnt=`expr $decreasing_cnt + 1`
 206.228 +        fi
 206.229 +        prev_instance_cnt="$instance_cnt"
 206.230 +    fi
 206.231 +
 206.232 +    # delay between samples
 206.233 +    sleep 5
 206.234 +
 206.235 +    loop_cnt=`expr $loop_cnt + 1`
 206.236 +done
 206.237 +
 206.238 +echo "INFO: increasing_cnt = $increasing_cnt"
 206.239 +echo "INFO: decreasing_cnt = $decreasing_cnt"
 206.240 +
 206.241 +echo "INFO: The instance count of" `eval echo $TARGET_CLASS` "objects"
 206.242 +if [ "$decreasing_cnt" = 0 ]; then
 206.243 +    echo "INFO: is always increasing."
 206.244 +    echo "FAIL: This indicates that there is a memory leak." >&2
 206.245 +    exit 2
 206.246 +fi
 206.247 +
 206.248 +echo "INFO: is both increasing and decreasing."
 206.249 +echo "PASS: This indicates that there is not a memory leak."
 206.250 +exit 0
   207.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   207.2 +++ b/test/javax/swing/AbstractButton/6711682/bug6711682.java	Tue Jul 20 22:21:31 2010 -0700
   207.3 @@ -0,0 +1,151 @@
   207.4 +/*
   207.5 + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   207.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   207.7 + *
   207.8 + * This code is free software; you can redistribute it and/or modify it
   207.9 + * under the terms of the GNU General Public License version 2 only, as
  207.10 + * published by the Free Software Foundation.
  207.11 + *
  207.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  207.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  207.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  207.15 + * version 2 for more details (a copy is included in the LICENSE file that
  207.16 + * accompanied this code).
  207.17 + *
  207.18 + * You should have received a copy of the GNU General Public License version
  207.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  207.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  207.21 + *
  207.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  207.23 + * or visit www.oracle.com if you need additional information or have any
  207.24 + * questions.
  207.25 + */
  207.26 +
  207.27 +/* @test
  207.28 +   @bug 6711682
  207.29 +   @summary  JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
  207.30 +   @author Alexander Potochkin
  207.31 +   @run main bug6711682
  207.32 +*/
  207.33 +
  207.34 +import sun.awt.SunToolkit;
  207.35 +
  207.36 +import javax.swing.*;
  207.37 +import javax.swing.event.CellEditorListener;
  207.38 +import javax.swing.table.TableCellEditor;
  207.39 +import javax.swing.table.TableCellRenderer;
  207.40 +import java.awt.*;
  207.41 +import java.awt.event.InputEvent;
  207.42 +import java.awt.event.KeyEvent;
  207.43 +import java.util.EventObject;
  207.44 +
  207.45 +public class bug6711682 {
  207.46 +    private static JCheckBox editorCb;
  207.47 +    private static JCheckBox rendererCb;
  207.48 +    private static JTable table;
  207.49 +
  207.50 +    public static void main(String[] args) throws Exception {
  207.51 +        Robot robot = new Robot();
  207.52 +        robot.setAutoDelay(50);
  207.53 +        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
  207.54 +        SwingUtilities.invokeAndWait(new Runnable() {
  207.55 +            public void run() {
  207.56 +                createAndShowGUI();
  207.57 +            }
  207.58 +        });
  207.59 +        toolkit.realSync();
  207.60 +        Point l = table.getLocationOnScreen();
  207.61 +        int h = table.getRowHeight();
  207.62 +        for (int i = 0; i < 3; i++) {
  207.63 +            robot.mouseMove(l.x + 5, l.y + 5 + i * h);
  207.64 +            robot.mousePress(InputEvent.BUTTON1_MASK);
  207.65 +            robot.mouseRelease(InputEvent.BUTTON1_MASK);
  207.66 +        }
  207.67 +        // Without pressing F2 the last table's cell
  207.68 +        // reported <code>false</code> value
  207.69 +        // note that I can't press it inside the for loop
  207.70 +        // because it doesn't reproduce the bug
  207.71 +        robot.keyPress(KeyEvent.VK_F2);
  207.72 +        robot.keyRelease(KeyEvent.VK_F2);
  207.73 +
  207.74 +        for (int i = 0; i < 3; i++) {
  207.75 +            if (!Boolean.TRUE.equals(table.getValueAt(i, 0))) {
  207.76 +                throw new RuntimeException("Row #" + i + " checkbox is not selected");
  207.77 +            }
  207.78 +        }
  207.79 +        for (int i = 2; i >= 0; i--) {
  207.80 +            robot.mouseMove(l.x + 5, l.y + 5 + i * h);
  207.81 +            robot.mousePress(InputEvent.BUTTON1_MASK);
  207.82 +            robot.mouseRelease(InputEvent.BUTTON1_MASK);
  207.83 +        }
  207.84 +        robot.keyPress(KeyEvent.VK_F2);
  207.85 +        robot.keyRelease(KeyEvent.VK_F2);
  207.86 +        for (int i = 0; i < 3; i++) {
  207.87 +            if (Boolean.TRUE.equals(table.getValueAt(i, 0))) {
  207.88 +                throw new RuntimeException("Row #" + i + " checkbox is selected");
  207.89 +            }
  207.90 +        }
  207.91 +    }
  207.92 +
  207.93 +    private static void createAndShowGUI() {
  207.94 +        editorCb = new JCheckBox();
  207.95 +        rendererCb = new JCheckBox();
  207.96 +        JFrame f = new JFrame("Table with CheckBox");
  207.97 +        Container p = f.getContentPane();
  207.98 +        p.setLayout(new BorderLayout());
  207.99 +        table = new JTable(new Object[][]{{false}, {false}, {false}}, new Object[]{"CheckBox"});
 207.100 +        TableCellEditor editor = new TableCellEditor() {
 207.101 +            int editedRow;
 207.102 +
 207.103 +            public Component getTableCellEditorComponent(JTable table,
 207.104 +                                                         Object value, boolean isSelected, int row, int column) {
 207.105 +                this.editedRow = row;
 207.106 +                editorCb.setSelected(Boolean.TRUE.equals(value));
 207.107 +                editorCb.setBackground(UIManager.getColor("Table.selectionBackground"));
 207.108 +                return editorCb;
 207.109 +            }
 207.110 +
 207.111 +            public void addCellEditorListener(CellEditorListener l) {
 207.112 +            }
 207.113 +
 207.114 +            public void cancelCellEditing() {
 207.115 +            }
 207.116 +
 207.117 +            public Object getCellEditorValue() {
 207.118 +                return editorCb.isSelected();
 207.119 +            }
 207.120 +
 207.121 +            public boolean isCellEditable(EventObject anEvent) {
 207.122 +                return true;
 207.123 +            }
 207.124 +
 207.125 +            public void removeCellEditorListener(CellEditorListener l) {
 207.126 +            }
 207.127 +
 207.128 +            public boolean shouldSelectCell(EventObject anEvent) {
 207.129 +                return true;
 207.130 +            }
 207.131 +
 207.132 +            public boolean stopCellEditing() {
 207.133 +                table.getModel().setValueAt(editorCb.isSelected(), editedRow, 0);
 207.134 +                return true;
 207.135 +            }
 207.136 +        };
 207.137 +        table.getColumnModel().getColumn(0).setCellEditor(editor);
 207.138 +
 207.139 +        TableCellRenderer renderer = new TableCellRenderer() {
 207.140 +            public Component getTableCellRendererComponent(JTable table,
 207.141 +                                                           Object value, boolean isSelected, boolean hasFocus,
 207.142 +                                                           int row, int column) {
 207.143 +                rendererCb.setSelected(Boolean.TRUE.equals(value));
 207.144 +                return rendererCb;
 207.145 +            }
 207.146 +        };
 207.147 +        table.getColumnModel().getColumn(0).setCellRenderer(renderer);
 207.148 +
 207.149 +        p.add(table, BorderLayout.CENTER);
 207.150 +
 207.151 +        f.pack();
 207.152 +        f.setVisible(true);
 207.153 +    }
 207.154 +}
   208.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   208.2 +++ b/test/javax/swing/JFileChooser/6520101/bug6520101.java	Tue Jul 20 22:21:31 2010 -0700
   208.3 @@ -0,0 +1,104 @@
   208.4 +/*
   208.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   208.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   208.7 + *
   208.8 + * This code is free software; you can redistribute it and/or modify it
   208.9 + * under the terms of the GNU General Public License version 2 only, as
  208.10 + * published by the Free Software Foundation.
  208.11 + *
  208.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  208.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  208.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  208.15 + * version 2 for more details (a copy is included in the LICENSE file that
  208.16 + * accompanied this code).
  208.17 + *
  208.18 + * You should have received a copy of the GNU General Public License version
  208.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  208.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  208.21 + *
  208.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  208.23 + * or visit www.oracle.com if you need additional information or have any
  208.24 + * questions.
  208.25 + */
  208.26 +
  208.27 +/*
  208.28 + * @test @(#)bug6520101
  208.29 + * @bug 6520101
  208.30 + * @summary JFileChooser throws OOM in 1.4.2, 5.0u4 and 1.6.0
  208.31 + * @author Praveen Gupta
  208.32 + * @run main/othervm/timeout=600 -Xmx8m -verify bug6520101
  208.33 +*/
  208.34 +
  208.35 +import javax.swing.*;
  208.36 +import java.awt.event.ActionEvent;
  208.37 +import java.awt.event.ActionListener;
  208.38 +
  208.39 +public class bug6520101 implements Runnable {
  208.40 +
  208.41 +    private static final int ATTEMPTS = 500;
  208.42 +    private static final int INTERVAL = 100;
  208.43 +
  208.44 +    private static final boolean ALWAYS_NEW_INSTANCE = false;
  208.45 +    private static final boolean DO_GC_EACH_INTERVAL = false;
  208.46 +    private static final boolean UPDATE_UI_EACH_INTERVAL = true;
  208.47 +    private static final boolean AUTO_CLOSE_DIALOG = true;
  208.48 +
  208.49 +    private static JFileChooser CHOOSER;
  208.50 +
  208.51 +    public static void main(String[] args) throws Exception {
  208.52 +        UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
  208.53 +
  208.54 +        for (int i = 0; i < ATTEMPTS; i++) {
  208.55 +            doAttempt();
  208.56 +        }
  208.57 +
  208.58 +        System.out.println("Test passed successfully");
  208.59 +    }
  208.60 +
  208.61 +    private static void doAttempt() throws InterruptedException {
  208.62 +        if (ALWAYS_NEW_INSTANCE || (CHOOSER == null))
  208.63 +            CHOOSER = new JFileChooser(".");
  208.64 +
  208.65 +        if (UPDATE_UI_EACH_INTERVAL) {
  208.66 +            CHOOSER.updateUI();
  208.67 +        }
  208.68 +
  208.69 +        if (AUTO_CLOSE_DIALOG) {
  208.70 +            Thread t = new Thread(new bug6520101(CHOOSER));
  208.71 +            t.start();
  208.72 +            CHOOSER.showOpenDialog(null);
  208.73 +            t.join();
  208.74 +        } else {
  208.75 +            CHOOSER.showOpenDialog(null);
  208.76 +        }
  208.77 +
  208.78 +        if (DO_GC_EACH_INTERVAL) {
  208.79 +            System.gc();
  208.80 +        }
  208.81 +    }
  208.82 +
  208.83 +    private final JFileChooser chooser;
  208.84 +
  208.85 +    bug6520101(JFileChooser chooser) {
  208.86 +        this.chooser = chooser;
  208.87 +    }
  208.88 +
  208.89 +    public void run() {
  208.90 +        while (!this.chooser.isShowing()) {
  208.91 +            try {
  208.92 +                Thread.sleep(30);
  208.93 +            } catch (InterruptedException exception) {
  208.94 +                exception.printStackTrace();
  208.95 +            }
  208.96 +        }
  208.97 +
  208.98 +        Timer timer = new Timer(INTERVAL, new ActionListener() {
  208.99 +            public void actionPerformed(ActionEvent e) {
 208.100 +                chooser.cancelSelection();
 208.101 +            }
 208.102 +        });
 208.103 +
 208.104 +        timer.setRepeats(false);
 208.105 +        timer.start();
 208.106 +    }
 208.107 +}
   209.1 --- a/test/javax/swing/JInternalFrame/6725409/bug6725409.java	Thu Jul 15 20:11:45 2010 -0700
   209.2 +++ b/test/javax/swing/JInternalFrame/6725409/bug6725409.java	Tue Jul 20 22:21:31 2010 -0700
   209.3 @@ -1,5 +1,5 @@
   209.4  /*
   209.5 - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
   209.6 + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
   209.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   209.8   *
   209.9   * This code is free software; you can redistribute it and/or modify it
  209.10 @@ -43,7 +43,7 @@
  209.11                      new com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel());
  209.12          } catch(UnsupportedLookAndFeelException e) {
  209.13              System.out.println("The test is for Windows LaF only");
  209.14 -            System.exit(0);
  209.15 +            return;
  209.16          }
  209.17  
  209.18          final bug6725409 bug6725409 = new bug6725409();
   210.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   210.2 +++ b/test/javax/swing/JPopupMenu/6495920/bug6495920.java	Tue Jul 20 22:21:31 2010 -0700
   210.3 @@ -0,0 +1,112 @@
   210.4 +/*
   210.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   210.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   210.7 + *
   210.8 + * This code is free software; you can redistribute it and/or modify it
   210.9 + * under the terms of the GNU General Public License version 2 only, as
  210.10 + * published by the Free Software Foundation.
  210.11 + *
  210.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  210.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  210.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  210.15 + * version 2 for more details (a copy is included in the LICENSE file that
  210.16 + * accompanied this code).
  210.17 + *
  210.18 + * You should have received a copy of the GNU General Public License version
  210.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  210.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  210.21 + *
  210.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  210.23 + * or visit www.oracle.com if you need additional information or have any
  210.24 + * questions.
  210.25 + */
  210.26 +
  210.27 +/*
  210.28 + * @test
  210.29 + * @bug 6495920
  210.30 + * @summary Tests that if the JPopupMenu.setVisible method throws an exception,
  210.31 +            interaction with GNOME is not crippled
  210.32 + * @author Sergey Malenkov
  210.33 + * @library ../..
  210.34 + */
  210.35 +
  210.36 +import sun.awt.AppContext;
  210.37 +
  210.38 +import java.awt.Point;
  210.39 +import java.awt.Robot;
  210.40 +import java.awt.event.InputEvent;
  210.41 +import java.lang.reflect.Field;
  210.42 +import javax.swing.JFrame;
  210.43 +import javax.swing.JMenuItem;
  210.44 +import javax.swing.JPanel;
  210.45 +import javax.swing.JPopupMenu;
  210.46 +import javax.swing.SwingUtilities;
  210.47 +import javax.swing.plaf.basic.BasicPopupMenuUI;
  210.48 +
  210.49 +public class bug6495920 implements Thread.UncaughtExceptionHandler {
  210.50 +
  210.51 +    public static void main(String[] args) throws Throwable {
  210.52 +        SwingTest.start(bug6495920.class);
  210.53 +    }
  210.54 +
  210.55 +    private static Robot robot;
  210.56 +    private final JPanel panel;
  210.57 +
  210.58 +    public bug6495920(JFrame frame) {
  210.59 +        JPopupMenu menu = new JPopupMenu() {
  210.60 +            public void setVisible(boolean visible) {
  210.61 +                super.setVisible(visible);
  210.62 +                throw new AssertionError(visible ? "show popup" : "hide popup");
  210.63 +            }
  210.64 +        };
  210.65 +        for (int i = 0; i < 10; i++) {
  210.66 +            menu.add(new JMenuItem(String.valueOf(i)));
  210.67 +        }
  210.68 +        this.panel = new JPanel();
  210.69 +        this.panel.setComponentPopupMenu(menu);
  210.70 +        frame.add(this.panel);
  210.71 +    }
  210.72 +
  210.73 +    public void firstShowPopup() throws Exception {
  210.74 +        Point point = this.panel.getLocation();
  210.75 +        SwingUtilities.convertPointToScreen(point, this.panel);
  210.76 +
  210.77 +        robot = new Robot(); // initialize shared static field first time
  210.78 +        robot.mouseMove(point.x + 1, point.y + 1);
  210.79 +        robot.mousePress(InputEvent.BUTTON3_MASK);
  210.80 +        Thread.currentThread().setUncaughtExceptionHandler(this);
  210.81 +        robot.mouseRelease(InputEvent.BUTTON3_MASK); // causes first AssertionError on EDT
  210.82 +    }
  210.83 +
  210.84 +    public void secondHidePopup() {
  210.85 +        Point point = this.panel.getLocation();
  210.86 +        SwingUtilities.convertPointToScreen(point, this.panel);
  210.87 +
  210.88 +        robot.mouseMove(point.x - 1, point.y - 1);
  210.89 +        Thread.currentThread().setUncaughtExceptionHandler(this);
  210.90 +        robot.mousePress(InputEvent.BUTTON1_MASK); // causes second AssertionError on EDT
  210.91 +        robot.mouseRelease(InputEvent.BUTTON1_MASK);
  210.92 +    }
  210.93 +
  210.94 +    public void thirdValidate() throws Exception {
  210.95 +        Field key = BasicPopupMenuUI.class.getDeclaredField("MOUSE_GRABBER_KEY");
  210.96 +        key.setAccessible(true);
  210.97 +
  210.98 +        Object grabber = AppContext.getAppContext().get(key.get(null));
  210.99 +        if (grabber == null) {
 210.100 +            throw new Exception("cannot find a mouse grabber in app's context");
 210.101 +        }
 210.102 +
 210.103 +        Field field = grabber.getClass().getDeclaredField("grabbedWindow");
 210.104 +        field.setAccessible(true);
 210.105 +
 210.106 +        Object window = field.get(grabber);
 210.107 +        if (window != null) {
 210.108 +            throw new Exception("interaction with GNOME is crippled");
 210.109 +        }
 210.110 +    }
 210.111 +
 210.112 +    public void uncaughtException(Thread thread, Throwable throwable) {
 210.113 +        System.out.println(throwable);
 210.114 +    }
 210.115 +}
   211.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   211.2 +++ b/test/javax/swing/JTable/6777378/bug6777378.java	Tue Jul 20 22:21:31 2010 -0700
   211.3 @@ -0,0 +1,88 @@
   211.4 +/*
   211.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   211.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   211.7 + *
   211.8 + * This code is free software; you can redistribute it and/or modify it
   211.9 + * under the terms of the GNU General Public License version 2 only, as
  211.10 + * published by the Free Software Foundation.
  211.11 + *
  211.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  211.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  211.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  211.15 + * version 2 for more details (a copy is included in the LICENSE file that
  211.16 + * accompanied this code).
  211.17 + *
  211.18 + * You should have received a copy of the GNU General Public License version
  211.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  211.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  211.21 + *
  211.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  211.23 + * or visit www.oracle.com if you need additional information or have any
  211.24 + * questions.
  211.25 + */
  211.26 +
  211.27 +/* @test
  211.28 +   @bug 6777378
  211.29 +   @summary NullPointerException in XPDefaultRenderer.paint()
  211.30 +   @author Alexander Potochkin
  211.31 +   @run main bug6777378
  211.32 +*/
  211.33 +
  211.34 +import sun.awt.SunToolkit;
  211.35 +
  211.36 +import javax.swing.*;
  211.37 +import javax.swing.table.AbstractTableModel;
  211.38 +import javax.swing.table.JTableHeader;
  211.39 +import javax.swing.plaf.metal.MetalLookAndFeel;
  211.40 +import java.awt.event.MouseEvent;
  211.41 +import java.awt.event.InputEvent;
  211.42 +import java.awt.*;
  211.43 +
  211.44 +public class bug6777378 {
  211.45 +    private static JFrame frame;
  211.46 +    private static JTableHeader header;
  211.47 +
  211.48 +    public static void main(String[] args) throws Exception {
  211.49 +        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
  211.50 +        Robot robot = new Robot();
  211.51 +        robot.setAutoDelay(20);
  211.52 +        SwingUtilities.invokeAndWait(new Runnable() {
  211.53 +            public void run() {
  211.54 +                try {
  211.55 +                    UIManager.setLookAndFeel(new MetalLookAndFeel());
  211.56 +                } catch (Exception e) {
  211.57 +                    e.printStackTrace();
  211.58 +                }
  211.59 +                JTable table = new JTable(new AbstractTableModel() {
  211.60 +                    public int getRowCount() {
  211.61 +                        return 10;
  211.62 +                    }
  211.63 +
  211.64 +                    public int getColumnCount() {
  211.65 +                        return 10;
  211.66 +                    }
  211.67 +
  211.68 +                    public Object getValueAt(int rowIndex, int columnIndex) {
  211.69 +                        return "" + rowIndex + " " + columnIndex;
  211.70 +                    }
  211.71 +                });
  211.72 +
  211.73 +                header = new JTableHeader(table.getColumnModel());
  211.74 +                header.setToolTipText("hello");
  211.75 +
  211.76 +                frame = new JFrame();
  211.77 +                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  211.78 +                frame.add(header);
  211.79 +
  211.80 +                frame.setSize(300, 300);
  211.81 +                frame.setVisible(true);
  211.82 +            }
  211.83 +        });
  211.84 +        toolkit.realSync();
  211.85 +        Point point = header.getLocationOnScreen();
  211.86 +        robot.mouseMove(point.x + 20, point.y + 50);
  211.87 +        robot.mouseMove(point.x + 30, point.y + 50);
  211.88 +        robot.mousePress(InputEvent.BUTTON1_MASK);
  211.89 +        robot.mouseRelease(InputEvent.BUTTON1_MASK);
  211.90 +    }
  211.91 +}
   212.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   212.2 +++ b/test/javax/swing/border/Test4129681.html	Tue Jul 20 22:21:31 2010 -0700
   212.3 @@ -0,0 +1,10 @@
   212.4 +<html>
   212.5 +<body>
   212.6 +When applet starts, you'll see a checkbox and a label with a titled border.
   212.7 +Turn on the checkbox to disable the label.
   212.8 +The test passes if the title of the border is disabled as well as the label.
   212.9 +
  212.10 +<applet width="300" height="200" code="Test4129681.class">
  212.11 +</applet>
  212.12 +</body>
  212.13 +</html>
   213.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   213.2 +++ b/test/javax/swing/border/Test4129681.java	Tue Jul 20 22:21:31 2010 -0700
   213.3 @@ -0,0 +1,59 @@
   213.4 +/*
   213.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   213.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   213.7 + *
   213.8 + * This code is free software; you can redistribute it and/or modify it
   213.9 + * under the terms of the GNU General Public License version 2 only, as
  213.10 + * published by the Free Software Foundation.
  213.11 + *
  213.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  213.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  213.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  213.15 + * version 2 for more details (a copy is included in the LICENSE file that
  213.16 + * accompanied this code).
  213.17 + *
  213.18 + * You should have received a copy of the GNU General Public License version
  213.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  213.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  213.21 + *
  213.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  213.23 + * or visit www.oracle.com if you need additional information or have any
  213.24 + * questions.
  213.25 + */
  213.26 +
  213.27 +/*
  213.28 + * @test
  213.29 + * @bug 4129681
  213.30 + * @summary Tests enabling/disabling of titled border's caption
  213.31 + * @author Sergey Malenkov
  213.32 + * @run applet/manual=yesno Test4129681.html
  213.33 + */
  213.34 +
  213.35 +import java.awt.BorderLayout;
  213.36 +import java.awt.event.ItemEvent;
  213.37 +import java.awt.event.ItemListener;
  213.38 +import javax.swing.BorderFactory;
  213.39 +import javax.swing.JApplet;
  213.40 +import javax.swing.JCheckBox;
  213.41 +import javax.swing.JLabel;
  213.42 +
  213.43 +public class Test4129681 extends JApplet implements ItemListener {
  213.44 +    private JLabel label;
  213.45 +
  213.46 +    @Override
  213.47 +    public void init() {
  213.48 +        JCheckBox check = new JCheckBox("disable");
  213.49 +        check.addItemListener(this);
  213.50 +
  213.51 +        this.label = new JLabel("message");
  213.52 +        this.label.setBorder(BorderFactory.createTitledBorder("label"));
  213.53 +        this.label.setEnabled(!check.isSelected());
  213.54 +
  213.55 +        add(BorderLayout.NORTH, check);
  213.56 +        add(BorderLayout.CENTER, this.label);
  213.57 +    }
  213.58 +
  213.59 +    public void itemStateChanged(ItemEvent event) {
  213.60 +        this.label.setEnabled(ItemEvent.DESELECTED == event.getStateChange());
  213.61 +    }
  213.62 +}
   214.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   214.2 +++ b/test/javax/swing/border/Test4760089.html	Tue Jul 20 22:21:31 2010 -0700
   214.3 @@ -0,0 +1,10 @@
   214.4 +<html>
   214.5 +<body>
   214.6 +When applet starts, you'll see a panel with a compound titled border.
   214.7 +If one of its titles is overstriken with the border's line then test fails.
   214.8 +Otherwise test passes.
   214.9 +
  214.10 +<applet width="600" height="300" code="Test4760089.class">
  214.11 +</applet>
  214.12 +</body>
  214.13 +</html>
   215.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   215.2 +++ b/test/javax/swing/border/Test4760089.java	Tue Jul 20 22:21:31 2010 -0700
   215.3 @@ -0,0 +1,49 @@
   215.4 +/*
   215.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   215.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   215.7 + *
   215.8 + * This code is free software; you can redistribute it and/or modify it
   215.9 + * under the terms of the GNU General Public License version 2 only, as
  215.10 + * published by the Free Software Foundation.
  215.11 + *
  215.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  215.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  215.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  215.15 + * version 2 for more details (a copy is included in the LICENSE file that
  215.16 + * accompanied this code).
  215.17 + *
  215.18 + * You should have received a copy of the GNU General Public License version
  215.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  215.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  215.21 + *
  215.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  215.23 + * or visit www.oracle.com if you need additional information or have any
  215.24 + * questions.
  215.25 + */
  215.26 +
  215.27 +/*
  215.28 + * @test
  215.29 + * @bug 4760089
  215.30 + * @summary Tests that titled border do not paint inner titled border over its caption
  215.31 + * @author Sergey Malenkov
  215.32 + * @run applet/manual=yesno Test4760089.html
  215.33 + */
  215.34 +
  215.35 +import javax.swing.JApplet;
  215.36 +import javax.swing.JPanel;
  215.37 +import javax.swing.border.Border;
  215.38 +import javax.swing.border.EtchedBorder;
  215.39 +import javax.swing.border.TitledBorder;
  215.40 +
  215.41 +public class Test4760089 extends JApplet {
  215.42 +    @Override
  215.43 +    public void init() {
  215.44 +        Border border = new EtchedBorder();
  215.45 +        border = new TitledBorder(border, "LEFT",  TitledBorder.LEFT,  TitledBorder.TOP);
  215.46 +        border = new TitledBorder(border, "RIGHT", TitledBorder.RIGHT, TitledBorder.TOP);
  215.47 +
  215.48 +        JPanel panel = new JPanel();
  215.49 +        panel.setBorder(border);
  215.50 +        getContentPane().add(panel);
  215.51 +    }
  215.52 +}
   216.1 --- a/test/sun/nio/ch/Basic.java	Thu Jul 15 20:11:45 2010 -0700
   216.2 +++ b/test/sun/nio/ch/Basic.java	Tue Jul 20 22:21:31 2010 -0700
   216.3 @@ -32,5 +32,7 @@
   216.4  public class Basic {
   216.5      public static void main(String[] args) throws Exception {
   216.6          Pipe p = Pipe.open();
   216.7 +        p.source().close();
   216.8 +        p.sink().close();
   216.9      }
  216.10  }
   217.1 --- a/test/sun/nio/ch/TempBuffer.java	Thu Jul 15 20:11:45 2010 -0700
   217.2 +++ b/test/sun/nio/ch/TempBuffer.java	Tue Jul 20 22:21:31 2010 -0700
   217.3 @@ -54,8 +54,12 @@
   217.4                      blah.deleteOnExit();
   217.5                      TempBuffer.initTestFile(blah);
   217.6                      RandomAccessFile raf = new RandomAccessFile(blah, "rw");
   217.7 -                    FileChannel fs = raf.getChannel();
   217.8 -                    fs.transferTo(0, SIZE, Channels.newChannel(out));
   217.9 +                    FileChannel fc = raf.getChannel();
  217.10 +                    try {
  217.11 +                        fc.transferTo(0, SIZE, Channels.newChannel(out));
  217.12 +                    } finally {
  217.13 +                        fc.close();
  217.14 +                    }
  217.15                      out.flush();
  217.16                  } catch (IOException ioe) {
  217.17                      throw new RuntimeException(ioe);
  217.18 @@ -69,10 +73,17 @@
  217.19          File blah = File.createTempFile("blah2", null);
  217.20          blah.deleteOnExit();
  217.21          RandomAccessFile raf = new RandomAccessFile(blah, "rw");
  217.22 -        FileChannel fs = raf.getChannel();
  217.23 -        raf.setLength(SIZE);
  217.24 -        fs.transferFrom(Channels.newChannel(in), 0, SIZE);
  217.25 -        fs.close();
  217.26 +        FileChannel fc = raf.getChannel();
  217.27 +        try {
  217.28 +            raf.setLength(SIZE);
  217.29 +            fc.transferFrom(Channels.newChannel(in), 0, SIZE);
  217.30 +        } finally {
  217.31 +            fc.close();
  217.32 +        }
  217.33 +
  217.34 +        sourceChannel.close();
  217.35 +        sinkChannel.close();
  217.36 +        blah.delete();
  217.37      }
  217.38  
  217.39      private static void initTestFile(File blah) throws IOException {
   218.1 --- a/test/sun/nio/cs/FindDecoderBugs.java	Thu Jul 15 20:11:45 2010 -0700
   218.2 +++ b/test/sun/nio/cs/FindDecoderBugs.java	Tue Jul 20 22:21:31 2010 -0700
   218.3 @@ -298,7 +298,7 @@
   218.4          void testRandomly(byte[] prefix, int n) {
   218.5              int len = prefix.length;
   218.6              byte[] ia = Arrays.copyOf(prefix, len + n);
   218.7 -            for (int i = 0; i < 10000; i++) {
   218.8 +            for (int i = 0; i < 5000; i++) {
   218.9                  for (int j = 0; j < n; j++)
  218.10                      ia[len + j] = randomByte();
  218.11                  test(ia);
  218.12 @@ -435,6 +435,9 @@
  218.13      static void equal(Object x, Object y) {
  218.14          if (x == null ? y == null : x.equals(y)) pass();
  218.15          else fail(x + " not equal to " + y);}
  218.16 +    static void equal(int x, int y) {
  218.17 +        if (x == y) pass();
  218.18 +        else fail(x + " not equal to " + y);}
  218.19      public static void main(String[] args) throws Throwable {
  218.20          try {realMain(args);} catch (Throwable t) {unexpected(t);}
  218.21          System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
   219.1 --- a/test/sun/nio/cs/ReadZero.java	Thu Jul 15 20:11:45 2010 -0700
   219.2 +++ b/test/sun/nio/cs/ReadZero.java	Tue Jul 20 22:21:31 2010 -0700
   219.3 @@ -43,15 +43,18 @@
   219.4                  return 0;
   219.5              }
   219.6          };
   219.7 +        try {
   219.8 +            is.read(new byte[1], 0, 1); // ok
   219.9 +            InputStreamReader isr = new InputStreamReader(is);
  219.10  
  219.11 -        is.read(new byte[1], 0, 1); // ok
  219.12 -        InputStreamReader isr = new InputStreamReader(is);
  219.13 -
  219.14 -        try {
  219.15 -            int res = isr.read(new char[1], 0, 1);
  219.16 -        } catch (IOException x) {
  219.17 -            System.out.println("IOException caught");
  219.18 -            return;
  219.19 +            try {
  219.20 +                int res = isr.read(new char[1], 0, 1);
  219.21 +            } catch (IOException x) {
  219.22 +                System.out.println("IOException caught");
  219.23 +                return;
  219.24 +            }
  219.25 +        } finally {
  219.26 +            is.close();
  219.27          }
  219.28          throw new RuntimeException("IOException not thrown");
  219.29      }
   220.1 --- a/test/sun/nio/cs/Test4206507.java	Thu Jul 15 20:11:45 2010 -0700
   220.2 +++ b/test/sun/nio/cs/Test4206507.java	Tue Jul 20 22:21:31 2010 -0700
   220.3 @@ -32,7 +32,12 @@
   220.4  
   220.5  public class Test4206507 {
   220.6      public static void main(String[] args) throws UnsupportedEncodingException {
   220.7 -        Locale.setDefault(new Locale("tr", "TR"));
   220.8 -        byte[] b = "".getBytes("ISO8859-9");
   220.9 +        Locale l = Locale.getDefault();
  220.10 +        try {
  220.11 +            Locale.setDefault(new Locale("tr", "TR"));
  220.12 +            byte[] b = "".getBytes("ISO8859-9");
  220.13 +        } finally {
  220.14 +            Locale.setDefault(l);
  220.15 +        }
  220.16      }
  220.17  }
   221.1 --- a/test/sun/nio/cs/TestStringCoding.java	Thu Jul 15 20:11:45 2010 -0700
   221.2 +++ b/test/sun/nio/cs/TestStringCoding.java	Tue Jul 20 22:21:31 2010 -0700
   221.3 @@ -26,7 +26,7 @@
   221.4  /* @test
   221.5     @bug 6636323 6636319
   221.6     @summary Test if StringCoding and NIO result have the same de/encoding result
   221.7 - * @run main/timeout=2000 TestStringCoding
   221.8 + * @run main/othervm/timeout=2000 TestStringCoding
   221.9   */
  221.10  
  221.11  import java.util.*;
   222.1 --- a/test/sun/nio/cs/TestX11CNS.java	Thu Jul 15 20:11:45 2010 -0700
   222.2 +++ b/test/sun/nio/cs/TestX11CNS.java	Tue Jul 20 22:21:31 2010 -0700
   222.3 @@ -94,6 +94,8 @@
   222.4      }
   222.5  
   222.6      static void compare(Charset newCS, Charset oldCS) throws Exception {
   222.7 +        if (newCS == null)
   222.8 +            return;  // does not exist on this platform
   222.9          char[] cc = getChars(newCS, oldCS);
  222.10          System.out.printf("    Diff <%s> <%s>...%n", newCS.name(), oldCS.name());
  222.11  
  222.12 @@ -120,14 +122,22 @@
  222.13          }
  222.14      }
  222.15  
  222.16 +    private static Charset getCharset(String czName)
  222.17 +        throws Exception {
  222.18 +        try {
  222.19 +            return (Charset)Class.forName(czName).newInstance();
  222.20 +        } catch (ClassNotFoundException e){}
  222.21 +        return null;  // does not exist
  222.22 +    }
  222.23 +
  222.24      public static void main(String[] args) throws Exception {
  222.25 -        compare(new sun.awt.motif.X11CNS11643P1(),
  222.26 +        compare(getCharset("sun.awt.motif.X11CNS11643P1"),
  222.27                  new X11CNS11643P1());
  222.28  
  222.29 -        compare(new sun.awt.motif.X11CNS11643P2(),
  222.30 +        compare(getCharset("sun.awt.motif.X11CNS11643P2"),
  222.31                  new X11CNS11643P2());
  222.32  
  222.33 -        compare(new sun.awt.motif.X11CNS11643P3(),
  222.34 +        compare(getCharset("sun.awt.motif.X11CNS11643P3"),
  222.35                  new X11CNS11643P3());
  222.36  
  222.37      }
   223.1 --- a/test/sun/security/krb5/auto/SSL.java	Thu Jul 15 20:11:45 2010 -0700
   223.2 +++ b/test/sun/security/krb5/auto/SSL.java	Tue Jul 20 22:21:31 2010 -0700
   223.3 @@ -25,6 +25,16 @@
   223.4   * @test
   223.5   * @bug 6894643 6913636
   223.6   * @summary Test JSSE Kerberos ciphersuite
   223.7 + * @run main SSL TLS_KRB5_WITH_RC4_128_SHA
   223.8 + * @run main SSL TLS_KRB5_WITH_RC4_128_MD5
   223.9 + * @run main SSL TLS_KRB5_WITH_3DES_EDE_CBC_SHA
  223.10 + * @run main SSL TLS_KRB5_WITH_3DES_EDE_CBC_MD5
  223.11 + * @run main SSL TLS_KRB5_WITH_DES_CBC_SHA
  223.12 + * @run main SSL TLS_KRB5_WITH_DES_CBC_MD5
  223.13 + * @run main SSL TLS_KRB5_EXPORT_WITH_RC4_40_SHA
  223.14 + * @run main SSL TLS_KRB5_EXPORT_WITH_RC4_40_MD5
  223.15 + * @run main SSL TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA
  223.16 + * @run main SSL TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5
  223.17   */
  223.18  import java.io.*;
  223.19  import java.net.InetAddress;
  223.20 @@ -37,7 +47,7 @@
  223.21  
  223.22  public class SSL {
  223.23  
  223.24 -    private static final String KRB5_CIPHER = "TLS_KRB5_WITH_3DES_EDE_CBC_SHA";
  223.25 +    private static String krb5Cipher;
  223.26      private static final int LOOP_LIMIT = 1;
  223.27      private static int loopCount = 0;
  223.28      private static volatile String server;
  223.29 @@ -45,6 +55,8 @@
  223.30  
  223.31      public static void main(String[] args) throws Exception {
  223.32  
  223.33 +        krb5Cipher = args[0];
  223.34 +
  223.35          KDC kdc = KDC.create(OneKDC.REALM);
  223.36          // Run this after KDC, so our own DNS service can be started
  223.37          try {
  223.38 @@ -117,7 +129,7 @@
  223.39              SSLSocket sslSocket = (SSLSocket) sslsf.createSocket(server, port);
  223.40  
  223.41              // Enable only a KRB5 cipher suite.
  223.42 -            String enabledSuites[] = {KRB5_CIPHER};
  223.43 +            String enabledSuites[] = {krb5Cipher};
  223.44              sslSocket.setEnabledCipherSuites(enabledSuites);
  223.45              // Should check for exception if enabledSuites is not supported
  223.46  
  223.47 @@ -155,7 +167,7 @@
  223.48              port = sslServerSocket.getLocalPort();
  223.49  
  223.50              // Enable only a KRB5 cipher suite.
  223.51 -            String enabledSuites[] = {KRB5_CIPHER};
  223.52 +            String enabledSuites[] = {krb5Cipher};
  223.53              sslServerSocket.setEnabledCipherSuites(enabledSuites);
  223.54              // Should check for exception if enabledSuites is not supported
  223.55  
   224.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   224.2 +++ b/test/sun/security/krb5/etype/ETypeOrder.java	Tue Jul 20 22:21:31 2010 -0700
   224.3 @@ -0,0 +1,52 @@
   224.4 +/*
   224.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   224.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   224.7 + *
   224.8 + * This code is free software; you can redistribute it and/or modify it
   224.9 + * under the terms of the GNU General Public License version 2 only, as
  224.10 + * published by the Free Software Foundation.
  224.11 + *
  224.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  224.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  224.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  224.15 + * version 2 for more details (a copy is included in the LICENSE file that
  224.16 + * accompanied this code).
  224.17 + *
  224.18 + * You should have received a copy of the GNU General Public License version
  224.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  224.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  224.21 + *
  224.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  224.23 + * or visit www.oracle.com if you need additional information or have any
  224.24 + * questions.
  224.25 + */
  224.26 +/*
  224.27 + * @test
  224.28 + * @bug 6844907
  224.29 + * @summary krb5 etype order should be from strong to weak
  224.30 + */
  224.31 +
  224.32 +import sun.security.krb5.internal.crypto.EType;
  224.33 +
  224.34 +public class ETypeOrder {
  224.35 +    public static void main(String[] args) throws Exception {
  224.36 +
  224.37 +        // File does not exist, so that the system-default one won't be used
  224.38 +        System.setProperty("java.security.krb5.conf", "no_such_file");
  224.39 +        int[] etypes = EType.getBuiltInDefaults();
  224.40 +
  224.41 +        // Reference order, note that 2 is not implemented in Java
  224.42 +        int correct[] = { 18, 17, 16, 23, 1, 3, 2 };
  224.43 +
  224.44 +        int match = 0;
  224.45 +        loopi: for (int i=0; i<etypes.length; i++) {
  224.46 +            for (; match < correct.length; match++) {
  224.47 +                if (etypes[i] == correct[match]) {
  224.48 +                    System.out.println("Find " + etypes[i] + " at #" + match);
  224.49 +                    continue loopi;
  224.50 +                }
  224.51 +            }
  224.52 +            throw new Exception("No match or bad order for " + etypes[i]);
  224.53 +        }
  224.54 +    }
  224.55 +}
   225.1 --- a/test/sun/security/krb5/ktab/HighestKvno.java	Thu Jul 15 20:11:45 2010 -0700
   225.2 +++ b/test/sun/security/krb5/ktab/HighestKvno.java	Tue Jul 20 22:21:31 2010 -0700
   225.3 @@ -1,5 +1,5 @@
   225.4  /*
   225.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   225.6 + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
   225.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   225.8   *
   225.9   * This code is free software; you can redistribute it and/or modify it
  225.10 @@ -227,9 +227,6 @@
  225.11          if (keys[0].getKeyVersionNumber() != 5) {
  225.12              throw new Exception("Highest not first");
  225.13          }
  225.14 -        if (ktab.readServiceKey(pn).getKeyVersionNumber() != 5) {
  225.15 -            throw new Exception("Highest not chosen");
  225.16 -        }
  225.17          new File("kt").delete();
  225.18      }
  225.19  }
   226.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   226.2 +++ b/test/sun/security/pkcs12/PKCS12SameKeyId.java	Tue Jul 20 22:21:31 2010 -0700
   226.3 @@ -0,0 +1,120 @@
   226.4 +/*
   226.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   226.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   226.7 + *
   226.8 + * This code is free software; you can redistribute it and/or modify it
   226.9 + * under the terms of the GNU General Public License version 2 only, as
  226.10 + * published by the Free Software Foundation.
  226.11 + *
  226.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  226.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  226.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  226.15 + * version 2 for more details (a copy is included in the LICENSE file that
  226.16 + * accompanied this code).
  226.17 + *
  226.18 + * You should have received a copy of the GNU General Public License version
  226.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  226.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  226.21 + *
  226.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  226.23 + * or visit www.oracle.com if you need additional information or have any
  226.24 + * questions.
  226.25 + */
  226.26 +
  226.27 +/*
  226.28 + * @test
  226.29 + * @bug 6958026
  226.30 + * @summary Problem with PKCS12 keystore
  226.31 + */
  226.32 +
  226.33 +import java.io.File;
  226.34 +import java.io.FileInputStream;
  226.35 +import java.io.FileOutputStream;
  226.36 +import java.security.AlgorithmParameters;
  226.37 +import java.security.KeyStore;
  226.38 +import java.security.cert.Certificate;
  226.39 +import java.security.cert.X509Certificate;
  226.40 +import javax.crypto.Cipher;
  226.41 +import javax.crypto.SecretKey;
  226.42 +import javax.crypto.SecretKeyFactory;
  226.43 +import javax.crypto.spec.PBEKeySpec;
  226.44 +import javax.crypto.spec.PBEParameterSpec;
  226.45 +import sun.security.pkcs.EncryptedPrivateKeyInfo;
  226.46 +import sun.security.tools.KeyTool;
  226.47 +import sun.security.util.ObjectIdentifier;
  226.48 +import sun.security.x509.AlgorithmId;
  226.49 +import sun.security.x509.X500Name;
  226.50 +
  226.51 +public class PKCS12SameKeyId {
  226.52 +
  226.53 +    private static final String JKSFILE = "PKCS12SameKeyId.jks";
  226.54 +    private static final String P12FILE = "PKCS12SameKeyId.p12";
  226.55 +    private static final char[] PASSWORD = "changeit".toCharArray();
  226.56 +    private static final int SIZE = 10;
  226.57 +
  226.58 +    public static void main(String[] args) throws Exception {
  226.59 +
  226.60 +        // Prepare a JKS keystore with many entries
  226.61 +        new File(JKSFILE).delete();
  226.62 +        for (int i=0; i<SIZE; i++) {
  226.63 +            System.err.print(".");
  226.64 +            String cmd = "-keystore " + JKSFILE
  226.65 +                    + " -storepass changeit -keypass changeit "
  226.66 +                    + "-genkeypair -alias p" + i + " -dname CN=" + i;
  226.67 +            KeyTool.main(cmd.split(" "));
  226.68 +        }
  226.69 +
  226.70 +        // Prepare EncryptedPrivateKeyInfo parameters, copied from various
  226.71 +        // places in PKCS12KeyStore.java
  226.72 +        AlgorithmParameters algParams =
  226.73 +                AlgorithmParameters.getInstance("PBEWithSHA1AndDESede");
  226.74 +        algParams.init(new PBEParameterSpec("12345678".getBytes(), 1024));
  226.75 +        AlgorithmId algid = new AlgorithmId(
  226.76 +                new ObjectIdentifier("1.2.840.113549.1.12.1.3"), algParams);
  226.77 +
  226.78 +        PBEKeySpec keySpec = new PBEKeySpec(PASSWORD);
  226.79 +        SecretKeyFactory skFac = SecretKeyFactory.getInstance("PBE");
  226.80 +        SecretKey skey = skFac.generateSecret(keySpec);
  226.81 +
  226.82 +        Cipher cipher = Cipher.getInstance("PBEWithSHA1AndDESede");
  226.83 +        cipher.init(Cipher.ENCRYPT_MODE, skey, algParams);
  226.84 +
  226.85 +        // Pre-calculated keys and certs and aliases
  226.86 +        byte[][] keys = new byte[SIZE][];
  226.87 +        Certificate[][] certChains = new Certificate[SIZE][];
  226.88 +        String[] aliases = new String[SIZE];
  226.89 +
  226.90 +        // Reads from JKS keystore and pre-calculate
  226.91 +        KeyStore ks = KeyStore.getInstance("jks");
  226.92 +        ks.load(new FileInputStream(JKSFILE), PASSWORD);
  226.93 +        for (int i=0; i<SIZE; i++) {
  226.94 +            aliases[i] = "p" + i;
  226.95 +            byte[] enckey = cipher.doFinal(
  226.96 +                    ks.getKey(aliases[i], PASSWORD).getEncoded());
  226.97 +            keys[i] = new EncryptedPrivateKeyInfo(algid, enckey).getEncoded();
  226.98 +            certChains[i] = ks.getCertificateChain(aliases[i]);
  226.99 +        }
 226.100 +
 226.101 +        // Write into PKCS12 keystore. Use this overloaded version of
 226.102 +        // setKeyEntry() to be as fast as possible, so that they would
 226.103 +        // have same localKeyId.
 226.104 +        KeyStore p12 = KeyStore.getInstance("pkcs12");
 226.105 +        p12.load(null, PASSWORD);
 226.106 +        for (int i=0; i<SIZE; i++) {
 226.107 +            p12.setKeyEntry(aliases[i], keys[i], certChains[i]);
 226.108 +        }
 226.109 +        p12.store(new FileOutputStream(P12FILE), PASSWORD);
 226.110 +
 226.111 +        // Check private keys still match certs
 226.112 +        p12 = KeyStore.getInstance("pkcs12");
 226.113 +        p12.load(new FileInputStream(P12FILE), PASSWORD);
 226.114 +        for (int i=0; i<SIZE; i++) {
 226.115 +            String a = "p" + i;
 226.116 +            X509Certificate x = (X509Certificate)p12.getCertificate(a);
 226.117 +            X500Name name = (X500Name)x.getSubjectDN();
 226.118 +            if (!name.getCommonName().equals(""+i)) {
 226.119 +                throw new Exception(a + "'s cert is " + name);
 226.120 +            }
 226.121 +        }
 226.122 +    }
 226.123 +}
   227.1 --- a/test/tools/launcher/Arrrghs.java	Thu Jul 15 20:11:45 2010 -0700
   227.2 +++ b/test/tools/launcher/Arrrghs.java	Tue Jul 20 22:21:31 2010 -0700
   227.3 @@ -1,5 +1,5 @@
   227.4  /*
   227.5 - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
   227.6 + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
   227.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   227.8   *
   227.9   * This code is free software; you can redistribute it and/or modify it
  227.10 @@ -23,7 +23,7 @@
  227.11  
  227.12  /**
  227.13   * @test
  227.14 - * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881
  227.15 + * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 6753938
  227.16   * @summary Argument parsing validation.
  227.17   * @compile -XDignore.symbol.file Arrrghs.java TestHelper.java
  227.18   * @run main Arrrghs
  227.19 @@ -223,6 +223,20 @@
  227.20          tr.checkPositive();
  227.21          tr.isNotZeroOutput();
  227.22          System.out.println(tr);
  227.23 +
  227.24 +        // 6753938, test for non-negative exit value for an incorrectly formed
  227.25 +        // command line,  '% java'
  227.26 +        tr = TestHelper.doExec(TestHelper.javaCmd);
  227.27 +        tr.checkNegative();
  227.28 +        tr.isNotZeroOutput();
  227.29 +        System.out.println(tr);
  227.30 +
  227.31 +        // 6753938, test for non-negative exit value for an incorrectly formed
  227.32 +        // command line,  '% java -Xcomp'
  227.33 +        tr = TestHelper.doExec(TestHelper.javaCmd, "-Xcomp");
  227.34 +        tr.checkNegative();
  227.35 +        tr.isNotZeroOutput();
  227.36 +        System.out.println(tr);
  227.37      }
  227.38  
  227.39      /*
   228.1 --- a/test/tools/launcher/Makefile.SolarisRunpath	Thu Jul 15 20:11:45 2010 -0700
   228.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   228.3 @@ -1,75 +0,0 @@
   228.4 -# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
   228.5 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   228.6 -#
   228.7 -# This code is free software; you can redistribute it and/or modify it
   228.8 -# under the terms of the GNU General Public License version 2 only, as
   228.9 -# published by the Free Software Foundation.
  228.10 -#
  228.11 -# This code is distributed in the hope that it will be useful, but WITHOUT
  228.12 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  228.13 -# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  228.14 -# version 2 for more details (a copy is included in the LICENSE file that
  228.15 -# accompanied this code).
  228.16 -#
  228.17 -# You should have received a copy of the GNU General Public License version
  228.18 -# 2 along with this work; if not, write to the Free Software Foundation,
  228.19 -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  228.20 -#
  228.21 -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  228.22 -# or visit www.oracle.com if you need additional information or have any
  228.23 -# questions.
  228.24 -
  228.25 -#
  228.26 -
  228.27 -# This is a not quite automated Makefile to generate the Solaris
  228.28 -# binaries used for the SolarisRunpath.sh test.  First,
  228.29 -# libraryCaller.java program must be compiled.  Next, javah is called
  228.30 -# on the class file to generate the needed header file for the jni
  228.31 -# code.  Then, 2 Solaris executables are generated in separate
  228.32 -# directories, a default one meant to be pointed to by LD_LIBRARY_PATH
  228.33 -# (this function returns 0) and another one for the data model
  228.34 -# specific LD_LIBRARY_PATH (this function returns the size of integers
  228.35 -# in the data model, 32 or 64).  A better makefile would run, say
  228.36 -# isainfo -v, and generated binaries for all supported data models.
  228.37 -# To do this a mapping would be needed from data models to
  228.38 -# architecture dependent compiler options; e.g. 64 bit on sparc =>
  228.39 -# -xarch=v9.  Also, the settings for JINCLUDE, JAVAC, and JAVAH should
  228.40 -# come from the current build.  The C compiler should be the one
  228.41 -# approved for the build.  To be extra safe, the binaries should be
  228.42 -# generated on the oldest Solaris release supported by the current
  228.43 -# Java build.
  228.44 -
  228.45 -# Include directory in JRE or JDK install; e.g.
  228.46 -JINCLUDE=/java/re/jdk/1.4.1/latest/binaries/solaris-sparc/include
  228.47 -
  228.48 -# Path to javac executable; e.g.
  228.49 -JAVAC=/java/re/jdk/1.4.1/promoted/fcs/b21/binaries/solaris-sparc/bin/javac
  228.50 -
  228.51 -# Path to javah executable; e.g.
  228.52 -JAVAH=/java/re/jdk/1.4.1/promoted/fcs/b21/binaries/solaris-sparc/bin/javah
  228.53 -
  228.54 -# Path to C compiler; e.g.
  228.55 -CC=/java/devtools/sparc/SUNWspro/SC6.1/bin/cc
  228.56 -
  228.57 -
  228.58 -ARCH=`uname -p`
  228.59 -
  228.60 -# 32-bit Solaris Options
  228.61 -DM=32
  228.62 -# Default architecture is fine for both sparc and x86 32-bit builds
  228.63 -OPTIONS=
  228.64 -
  228.65 -# 64-bit Solaris Options
  228.66 -#DM=64
  228.67 -#OPTIONS=-xarch=v9
  228.68 -
  228.69 -
  228.70 -all: libraryCaller.java libraryCaller.c
  228.71 -	$(JAVAC) libraryCaller.java;					\
  228.72 -	$(JAVAH) libraryCaller;						\
  228.73 -	$(CC) -G -I$(JINCLUDE) -I$(JINCLUDE)/solaris -DRETURN_VALUE=0 	\
  228.74 -		$(OPTIONS) libraryCaller.c 				\
  228.75 -		-o lib/$(ARCH)/lib$(DM)/liblibrary.so;			\
  228.76 -	$(CC) -G -I$(JINCLUDE) -I$(JINCLUDE)/solaris -DRETURN_VALUE=$(DM)\
  228.77 -		$(OPTIONS) libraryCaller.c 				\
  228.78 -		-o lib/$(ARCH)/lib$(DM)/lib$(DM)/liblibrary.so;
   229.1 --- a/test/tools/launcher/UnicodeTest.sh	Thu Jul 15 20:11:45 2010 -0700
   229.2 +++ b/test/tools/launcher/UnicodeTest.sh	Tue Jul 20 22:21:31 2010 -0700
   229.3 @@ -54,7 +54,11 @@
   229.4  
   229.5  echo "creating test source files"
   229.6  "$JAVAC" -d . "${TESTSRC}"/UnicodeTest.java
   229.7 -CLASS_NAME=`"$JAVA" UnicodeTest | sed -e 's@\\r@@g' `
   229.8 +if [ "`uname -s | grep CYGWIN`" != "" ] ; then
   229.9 +  CLASS_NAME=`"$JAVA" UnicodeTest | sed -e 's@\\r@@g' `
  229.10 +else
  229.11 +  CLASS_NAME=`"$JAVA" UnicodeTest`
  229.12 +fi
  229.13  
  229.14  if [ "$CLASS_NAME" = "" ]
  229.15  then
   230.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   230.2 +++ b/test/tools/launcher/VerifyExceptions.java	Tue Jul 20 22:21:31 2010 -0700
   230.3 @@ -0,0 +1,65 @@
   230.4 +/*
   230.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   230.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   230.7 + *
   230.8 + * This code is free software; you can redistribute it and/or modify it
   230.9 + * under the terms of the GNU General Public License version 2 only, as
  230.10 + * published by the Free Software Foundation.
  230.11 + *
  230.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  230.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  230.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  230.15 + * version 2 for more details (a copy is included in the LICENSE file that
  230.16 + * accompanied this code).
  230.17 + *
  230.18 + * You should have received a copy of the GNU General Public License version
  230.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  230.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  230.21 + *
  230.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  230.23 + * or visit www.oracle.com if you need additional information or have any
  230.24 + * questions.
  230.25 + */
  230.26 +
  230.27 +/*
  230.28 + * @test
  230.29 + * @bug 6856415
  230.30 + * @summary Checks to ensure that proper exceptions are thrown by java
  230.31 + * @compile -XDignore.symbol.file VerifyExceptions.java TestHelper.java
  230.32 + * @run main VerifyExceptions
  230.33 + */
  230.34 +
  230.35 +
  230.36 +import java.io.File;
  230.37 +import java.io.FileNotFoundException;
  230.38 +
  230.39 +
  230.40 +public class VerifyExceptions {
  230.41 +
  230.42 +    static void test6856415() {
  230.43 +        // No pkcs library on win-x64, so we bail out.
  230.44 +        if (TestHelper.is64Bit && TestHelper.isWindows) {
  230.45 +            return;
  230.46 +        }
  230.47 +        StringBuilder sb = new StringBuilder();
  230.48 +        sb.append("public static void main(String... args) {\n");
  230.49 +        sb.append("java.security.Provider p = new sun.security.pkcs11.SunPKCS11(args[0]);\n");
  230.50 +        sb.append("java.security.Security.insertProviderAt(p, 1);\n");
  230.51 +        sb.append("}");
  230.52 +        File testJar = new File("Foo.jar");
  230.53 +        testJar.delete();
  230.54 +        try {
  230.55 +            TestHelper.createJar(testJar, sb.toString());
  230.56 +        } catch (FileNotFoundException fnfe) {
  230.57 +            throw new RuntimeException(fnfe);
  230.58 +        }
  230.59 +        TestHelper.TestResult tr = TestHelper.doExec(TestHelper.javacCmd,
  230.60 +                "-Djava.security.manager", "-jar", testJar.getName(), "foo.bak");
  230.61 +        tr.checkNegative();
  230.62 +        tr.contains("Exception in thread \"main\" java.security.AccessControlException: access denied (\"java.lang.RuntimePermission\" \"accessClassInPackage.sun.security.pkcs11\")\")");
  230.63 +    }
  230.64 +
  230.65 +    public static void main(String... args) {
  230.66 +        test6856415();
  230.67 +    }
  230.68 +}
   231.1 Binary file test/tools/launcher/lib/i386/lib32/lib32/liblibrary.so has changed
   232.1 Binary file test/tools/launcher/lib/i386/lib32/liblibrary.so has changed
   233.1 Binary file test/tools/launcher/lib/sparc/lib32/lib32/liblibrary.so has changed
   234.1 Binary file test/tools/launcher/lib/sparc/lib32/liblibrary.so has changed
   235.1 Binary file test/tools/launcher/lib/sparc/lib64/lib64/liblibrary.so has changed
   236.1 Binary file test/tools/launcher/lib/sparc/lib64/liblibrary.so has changed