Merge
authorprr
Fri, 30 Sep 2016 09:28:18 -0700
changeset 41405 0d3b7bc68b7d
parent 41404 584981a12276 (current diff)
parent 41219 eab7a5086e95 (diff)
child 41406 d9b9053b5c5d
Merge
jdk/src/java.base/aix/native/libnio/ch/AixNativeThread.c
jdk/test/java/beans/XMLEncoder/EnumPrivate.java
jdk/test/java/beans/XMLEncoder/EnumPublic.java
jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedCollection.java
jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedList.java
jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedMap.java
jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedRandomAccessList.java
jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedSet.java
jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedSortedMap.java
jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedSortedSet.java
jdk/test/java/beans/XMLEncoder/java_util_EnumMap.java
jdk/test/java/beans/XMLEncoder/java_util_JumboEnumSet.java
jdk/test/java/beans/XMLEncoder/java_util_RegularEnumSet.java
jdk/test/java/net/URLPermission/nstest/LookupTestHosts
test/lib/jdk/test/lib/unsafe/UnsafeHelper.java
--- a/.hgtags	Thu Sep 29 11:13:42 2016 +0530
+++ b/.hgtags	Fri Sep 30 09:28:18 2016 -0700
@@ -379,3 +379,4 @@
 a71210c0d9800eb6925b61ecd6198abd554f90ee jdk-9+134
 e384420383a5b79fa0012ebcb25d8f83cff7f777 jdk-9+135
 1b4b5d01aa11edf24b6fadbe3d2f3e411e3b02cd jdk-9+136
+9cb87c88ed851c0575b8ead753ea238ed5b544e9 jdk-9+137
--- a/.hgtags-top-repo	Thu Sep 29 11:13:42 2016 +0530
+++ b/.hgtags-top-repo	Fri Sep 30 09:28:18 2016 -0700
@@ -379,3 +379,4 @@
 065724348690eda41fc69112278d8da6dcde548c jdk-9+134
 82b94cb5f342319d2cda77f9fa59703ad7fde576 jdk-9+135
 3ec350f5f32af249b59620d7e37b54bdcd77b233 jdk-9+136
+d7f519b004254b19e384131d9f0d0e40e31a0fd3 jdk-9+137
--- a/Makefile	Thu Sep 29 11:13:42 2016 +0530
+++ b/Makefile	Fri Sep 30 09:28:18 2016 -0700
@@ -28,8 +28,8 @@
 ### It also performs some sanity checks on make.
 ###
 
-# The shell code below will be executed on /usr/ccs/bin/make on Solaris, but not in GNU Make.
-# /usr/ccs/bin/make lacks basically every other flow control mechanism.
+# The shell code below will be executed on /usr/bin/make on Solaris, but not in GNU Make.
+# /usr/bin/make lacks basically every other flow control mechanism.
 .TEST_FOR_NON_GNUMAKE:sh=echo You are not using GNU Make/gmake, this is a requirement. Check your path. 1>&2 && exit 1
 
 # The .FEATURES variable is likely to be unique for GNU Make.
--- a/README-builds.html	Thu Sep 29 11:13:42 2016 +0530
+++ b/README-builds.html	Fri Sep 30 09:28:18 2016 -0700
@@ -626,8 +626,7 @@
 
 <p>The Common UNIX Printing System (CUPS) Headers are required for building the
    OpenJDK on Solaris and Linux. The Solaris header files can be obtained by
-   installing the package <strong>SFWcups</strong> from the Solaris Software Companion
-   CD/DVD, these often will be installed into the directory <code>/opt/sfw/cups</code>.</p>
+   installing the package <strong>print/cups</strong>.</p>
 
 <p>The CUPS header files can always be downloaded from
    <a href="http://www.cups.org">www.cups.org</a>.</p>
@@ -1111,8 +1110,7 @@
 <li>Place the location of the GNU make binary in the <code>PATH</code>.</li>
 <li><strong>Solaris:</strong> Do NOT use <code>/usr/bin/make</code> on Solaris. If your Solaris system
 has the software from the Solaris Developer Companion CD installed, you
-should try and use <code>gmake</code> which will be located in either the <code>/usr/bin</code>,
-<code>/opt/sfw/bin</code> or <code>/usr/sfw/bin</code> directory.</li>
+should try and use <code>/usr/bin/gmake</code> or <code>/usr/gnu/bin/make</code>.</li>
 <li><strong>Windows:</strong> Make sure you start your build inside a bash shell.</li>
 <li><strong>Mac OS X:</strong> The XCode "command line tools" must be installed on your Mac.</li>
 </ul>
--- a/README-builds.md	Thu Sep 29 11:13:42 2016 +0530
+++ b/README-builds.md	Fri Sep 30 09:28:18 2016 -0700
@@ -560,8 +560,7 @@
 
 >  The Common UNIX Printing System (CUPS) Headers are required for building the
    OpenJDK on Solaris and Linux. The Solaris header files can be obtained by
-   installing the package **SFWcups** from the Solaris Software Companion
-   CD/DVD, these often will be installed into the directory `/opt/sfw/cups`.
+   installing the package **print/cups**.
 
 >  The CUPS header files can always be downloaded from
    [www.cups.org](http://www.cups.org).
@@ -1017,8 +1016,7 @@
  * Place the location of the GNU make binary in the `PATH`.
  * **Solaris:** Do NOT use `/usr/bin/make` on Solaris. If your Solaris system
    has the software from the Solaris Developer Companion CD installed, you
-   should try and use `gmake` which will be located in either the `/usr/bin`,
-   `/opt/sfw/bin` or `/usr/sfw/bin` directory.
+   should try and use `/usr/bin/gmake` or `/usr/gnu/bin/make`.
  * **Windows:** Make sure you start your build inside a bash shell.
  * **Mac OS X:** The XCode "command line tools" must be installed on your Mac.
 
--- a/common/autoconf/basics.m4	Thu Sep 29 11:13:42 2016 +0530
+++ b/common/autoconf/basics.m4	Fri Sep 30 09:28:18 2016 -0700
@@ -750,11 +750,6 @@
   # Prepend the extra path to the global path
   BASIC_PREPEND_TO_PATH([PATH],$EXTRA_PATH)
 
-  if test "x$OPENJDK_BUILD_OS" = "xsolaris"; then
-    # Add extra search paths on solaris for utilities like ar, as, dtrace etc...
-    PATH="$PATH:/usr/ccs/bin:/usr/sfw/bin:/opt/csw/bin:/usr/sbin"
-  fi
-
   AC_MSG_CHECKING([for sysroot])
   AC_MSG_RESULT([$SYSROOT])
   AC_MSG_CHECKING([for toolchain path])
--- a/common/autoconf/flags.m4	Thu Sep 29 11:13:42 2016 +0530
+++ b/common/autoconf/flags.m4	Fri Sep 30 09:28:18 2016 -0700
@@ -88,8 +88,7 @@
         # inlining of system functions and intrinsics.
         $1SYSROOT_CFLAGS="-I-xbuiltin -I[$]$1SYSROOT/usr/include"
         $1SYSROOT_LDFLAGS="-L[$]$1SYSROOT/usr/lib$OPENJDK_TARGET_CPU_ISADIR \
-            -L[$]$1SYSROOT/lib$OPENJDK_TARGET_CPU_ISADIR \
-            -L[$]$1SYSROOT/usr/ccs/lib$OPENJDK_TARGET_CPU_ISADIR"
+            -L[$]$1SYSROOT/lib$OPENJDK_TARGET_CPU_ISADIR"
       fi
     elif test "x$TOOLCHAIN_TYPE" = xgcc; then
       $1SYSROOT_CFLAGS="--sysroot=[$]$1SYSROOT"
--- a/common/autoconf/generated-configure.sh	Thu Sep 29 11:13:42 2016 +0530
+++ b/common/autoconf/generated-configure.sh	Fri Sep 30 09:28:18 2016 -0700
@@ -926,9 +926,7 @@
 INCLUDE_SA
 UNLIMITED_CRYPTO
 CACERTS_FILE
-BUILD_HEADLESS
-SUPPORT_HEADFUL
-SUPPORT_HEADLESS
+ENABLE_HEADLESS_ONLY
 DEFAULT_MAKE_TARGET
 OS_VERSION_MICRO
 OS_VERSION_MINOR
@@ -1153,7 +1151,7 @@
 with_conf_name
 with_output_sync
 with_default_make_target
-enable_headful
+enable_headless_only
 with_cacerts_file
 enable_unlimited_crypto
 with_copyright_year
@@ -1976,8 +1974,7 @@
                           [disabled]
   --enable-debug          set the debug level to fastdebug (shorthand for
                           --with-debug-level=fastdebug) [disabled]
-  --disable-headful       disable building headful support (graphical UI
-                          support) [enabled]
+  --enable-headless-only  only build headless (no GUI) support [disabled]
   --enable-unlimited-crypto
                           Enable unlimited crypto policy [disabled]
   --disable-keep-packaged-modules
@@ -5095,7 +5092,7 @@
 #CUSTOM_AUTOCONF_INCLUDE
 
 # Do not change or remove the following line, it is needed for consistency checks:
-DATE_WHEN_GENERATED=1472718471
+DATE_WHEN_GENERATED=1474894604
 
 ###############################################################################
 #
@@ -17213,11 +17210,6 @@
   fi
 
 
-  if test "x$OPENJDK_BUILD_OS" = "xsolaris"; then
-    # Add extra search paths on solaris for utilities like ar, as, dtrace etc...
-    PATH="$PATH:/usr/ccs/bin:/usr/sfw/bin:/opt/csw/bin:/usr/sbin"
-  fi
-
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5
 $as_echo_n "checking for sysroot... " >&6; }
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SYSROOT" >&5
@@ -24197,36 +24189,30 @@
 
 # We need build & target for this.
 
-  # Should we build a JDK/JVM with headful support (ie a graphical ui)?
-  # We always build headless support.
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking headful support" >&5
-$as_echo_n "checking headful support... " >&6; }
-  # Check whether --enable-headful was given.
-if test "${enable_headful+set}" = set; then :
-  enableval=$enable_headful; SUPPORT_HEADFUL=${enable_headful}
-else
-  SUPPORT_HEADFUL=yes
-fi
-
-
-  SUPPORT_HEADLESS=yes
-  BUILD_HEADLESS="BUILD_HEADLESS:=true"
-
-  if test "x$SUPPORT_HEADFUL" = xyes; then
-    # We are building both headful and headless.
-    headful_msg="include support for both headful and headless"
-  fi
-
-  if test "x$SUPPORT_HEADFUL" = xno; then
-    # Thus we are building headless only.
-    BUILD_HEADLESS="BUILD_HEADLESS:=true"
-    headful_msg="headless only"
-  fi
-
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $headful_msg" >&5
-$as_echo "$headful_msg" >&6; }
-
-
+  # Should we build a JDK without a graphical UI?
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking headless only" >&5
+$as_echo_n "checking headless only... " >&6; }
+  # Check whether --enable-headless-only was given.
+if test "${enable_headless_only+set}" = set; then :
+  enableval=$enable_headless_only;
+fi
+
+
+  if test "x$enable_headless_only" = "xyes"; then
+    ENABLE_HEADLESS_ONLY="true"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+  elif test "x$enable_headless_only" = "xno"; then
+    ENABLE_HEADLESS_ONLY="false"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  elif test "x$enable_headless_only" = "x"; then
+    ENABLE_HEADLESS_ONLY="false"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  else
+    as_fn_error $? "--enable-headless-only can only take yes or no" "$LINENO" 5
+  fi
 
 
 
@@ -31475,8 +31461,7 @@
         # inlining of system functions and intrinsics.
         SYSROOT_CFLAGS="-I-xbuiltin -I$SYSROOT/usr/include"
         SYSROOT_LDFLAGS="-L$SYSROOT/usr/lib$OPENJDK_TARGET_CPU_ISADIR \
-            -L$SYSROOT/lib$OPENJDK_TARGET_CPU_ISADIR \
-            -L$SYSROOT/usr/ccs/lib$OPENJDK_TARGET_CPU_ISADIR"
+            -L$SYSROOT/lib$OPENJDK_TARGET_CPU_ISADIR"
       fi
     elif test "x$TOOLCHAIN_TYPE" = xgcc; then
       SYSROOT_CFLAGS="--sysroot=$SYSROOT"
@@ -32992,14 +32977,6 @@
   fi
 
 
-  # For solaris we really need solaris tools, and not the GNU equivalent.
-  # The build tools on Solaris reside in /usr/ccs (C Compilation System),
-  # so add that to path before starting to probe.
-  # FIXME: This was originally only done for AS,NM,GNM,STRIP,OBJCOPY,OBJDUMP.
-  if test "x$OPENJDK_BUILD_OS" = xsolaris; then
-    PATH="/usr/ccs/bin:$PATH"
-  fi
-
   # Finally add TOOLCHAIN_PATH at the beginning, to allow --with-tools-dir to
   # override all other locations.
   if test "x$TOOLCHAIN_PATH" != x; then
@@ -44000,8 +43977,7 @@
         # inlining of system functions and intrinsics.
         BUILD_SYSROOT_CFLAGS="-I-xbuiltin -I$BUILD_SYSROOT/usr/include"
         BUILD_SYSROOT_LDFLAGS="-L$BUILD_SYSROOT/usr/lib$OPENJDK_TARGET_CPU_ISADIR \
-            -L$BUILD_SYSROOT/lib$OPENJDK_TARGET_CPU_ISADIR \
-            -L$BUILD_SYSROOT/usr/ccs/lib$OPENJDK_TARGET_CPU_ISADIR"
+            -L$BUILD_SYSROOT/lib$OPENJDK_TARGET_CPU_ISADIR"
       fi
     elif test "x$TOOLCHAIN_TYPE" = xgcc; then
       BUILD_SYSROOT_CFLAGS="--sysroot=$BUILD_SYSROOT"
@@ -53060,13 +53036,9 @@
     # No X11 support on windows or macosx
     NEEDS_LIB_X11=false
   else
-    if test "x$SUPPORT_HEADFUL" = xno; then
-      # No X11 support if building headless-only
-      NEEDS_LIB_X11=false
-    else
-      # All other instances need X11
-      NEEDS_LIB_X11=true
-    fi
+    # All other instances need X11, even if building headless only, libawt still
+    # needs X11 headers.
+    NEEDS_LIB_X11=true
   fi
 
   # Check if cups is needed
@@ -56730,9 +56702,7 @@
     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
       OPENWIN_HOME="/usr/openwin"
       X_CFLAGS="-I$SYSROOT$OPENWIN_HOME/include -I$SYSROOT$OPENWIN_HOME/include/X11/extensions"
-      X_LIBS="-L$SYSROOT$OPENWIN_HOME/sfw/lib$OPENJDK_TARGET_CPU_ISADIR \
-          -L$SYSROOT$OPENWIN_HOME/lib$OPENJDK_TARGET_CPU_ISADIR \
-          -R$OPENWIN_HOME/sfw/lib$OPENJDK_TARGET_CPU_ISADIR \
+      X_LIBS="-L$SYSROOT$OPENWIN_HOME/lib$OPENJDK_TARGET_CPU_ISADIR \
           -R$OPENWIN_HOME/lib$OPENJDK_TARGET_CPU_ISADIR"
     fi
 
@@ -56911,23 +56881,6 @@
 
     fi
     if test "x$CUPS_FOUND" = xno; then
-      # Getting nervous now? Lets poke around for standard Solaris third-party
-      # package installation locations.
-      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cups headers" >&5
-$as_echo_n "checking for cups headers... " >&6; }
-      if test -s $SYSROOT/opt/sfw/cups/include/cups/cups.h; then
-        # An SFW package seems to be installed!
-        CUPS_FOUND=yes
-        CUPS_CFLAGS="-I$SYSROOT/opt/sfw/cups/include"
-      elif test -s $SYSROOT/opt/csw/include/cups/cups.h; then
-        # A CSW package seems to be installed!
-        CUPS_FOUND=yes
-        CUPS_CFLAGS="-I$SYSROOT/opt/csw/include"
-      fi
-      { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CUPS_FOUND" >&5
-$as_echo "$CUPS_FOUND" >&6; }
-    fi
-    if test "x$CUPS_FOUND" = xno; then
 
   # Print a helpful message on how to acquire the necessary build dependency.
   # cups is the help tag: freetype, cups, alsa etc
@@ -61167,346 +61120,6 @@
           fi
 
           if test "x$FOUND_FREETYPE" != xyes; then
-            FREETYPE_BASE_DIR="$SYSROOT/usr/sfw"
-
-  POTENTIAL_FREETYPE_INCLUDE_PATH="$FREETYPE_BASE_DIR/include"
-  POTENTIAL_FREETYPE_LIB_PATH="$FREETYPE_BASE_DIR/lib"
-  METHOD="well-known location"
-
-  # Let's start with an optimistic view of the world :-)
-  FOUND_FREETYPE=yes
-
-  # First look for the canonical freetype main include file ft2build.h.
-  if ! test -s "$POTENTIAL_FREETYPE_INCLUDE_PATH/ft2build.h"; then
-    # Oh no! Let's try in the freetype2 directory. This is needed at least at Mac OS X Yosemite.
-    POTENTIAL_FREETYPE_INCLUDE_PATH="$POTENTIAL_FREETYPE_INCLUDE_PATH/freetype2"
-    if ! test -s "$POTENTIAL_FREETYPE_INCLUDE_PATH/ft2build.h"; then
-      # Fail.
-      FOUND_FREETYPE=no
-    fi
-  fi
-
-  if test "x$FOUND_FREETYPE" = xyes; then
-    # Include file found, let's continue the sanity check.
-    { $as_echo "$as_me:${as_lineno-$LINENO}: Found freetype include files at $POTENTIAL_FREETYPE_INCLUDE_PATH using $METHOD" >&5
-$as_echo "$as_me: Found freetype include files at $POTENTIAL_FREETYPE_INCLUDE_PATH using $METHOD" >&6;}
-
-    # Reset to default value
-    FREETYPE_BASE_NAME=freetype
-    FREETYPE_LIB_NAME="${LIBRARY_PREFIX}${FREETYPE_BASE_NAME}${SHARED_LIBRARY_SUFFIX}"
-    if ! test -s "$POTENTIAL_FREETYPE_LIB_PATH/$FREETYPE_LIB_NAME"; then
-      if test "x$OPENJDK_TARGET_OS" = xmacosx \
-          && test -s "$POTENTIAL_FREETYPE_LIB_PATH/${LIBRARY_PREFIX}freetype.6${SHARED_LIBRARY_SUFFIX}"; then
-        # On Mac OS X Yosemite, the symlink from libfreetype.dylib to libfreetype.6.dylib disappeared. Check
-        # for the .6 version explicitly.
-        FREETYPE_BASE_NAME=freetype.6
-        FREETYPE_LIB_NAME="${LIBRARY_PREFIX}${FREETYPE_BASE_NAME}${SHARED_LIBRARY_SUFFIX}"
-        { $as_echo "$as_me:${as_lineno-$LINENO}: Compensating for missing symlink by using version 6 explicitly" >&5
-$as_echo "$as_me: Compensating for missing symlink by using version 6 explicitly" >&6;}
-      else
-        { $as_echo "$as_me:${as_lineno-$LINENO}: Could not find $POTENTIAL_FREETYPE_LIB_PATH/$FREETYPE_LIB_NAME. Ignoring location." >&5
-$as_echo "$as_me: Could not find $POTENTIAL_FREETYPE_LIB_PATH/$FREETYPE_LIB_NAME. Ignoring location." >&6;}
-        FOUND_FREETYPE=no
-      fi
-    else
-      if test "x$OPENJDK_TARGET_OS" = xwindows; then
-        # On Windows, we will need both .lib and .dll file.
-        if ! test -s "$POTENTIAL_FREETYPE_LIB_PATH/${FREETYPE_BASE_NAME}.lib"; then
-          { $as_echo "$as_me:${as_lineno-$LINENO}: Could not find $POTENTIAL_FREETYPE_LIB_PATH/${FREETYPE_BASE_NAME}.lib. Ignoring location." >&5
-$as_echo "$as_me: Could not find $POTENTIAL_FREETYPE_LIB_PATH/${FREETYPE_BASE_NAME}.lib. Ignoring location." >&6;}
-          FOUND_FREETYPE=no
-        fi
-      elif test "x$OPENJDK_TARGET_OS" = xsolaris \
-          && test -s "$POTENTIAL_FREETYPE_LIB_PATH$OPENJDK_TARGET_CPU_ISADIR/$FREETYPE_LIB_NAME"; then
-        # Found lib in isa dir, use that instead.
-        POTENTIAL_FREETYPE_LIB_PATH="$POTENTIAL_FREETYPE_LIB_PATH$OPENJDK_TARGET_CPU_ISADIR"
-        { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting to use $POTENTIAL_FREETYPE_LIB_PATH instead" >&5
-$as_echo "$as_me: Rewriting to use $POTENTIAL_FREETYPE_LIB_PATH instead" >&6;}
-      fi
-    fi
-  fi
-
-  if test "x$FOUND_FREETYPE" = xyes; then
-
-  # Only process if variable expands to non-empty
-
-  if test "x$POTENTIAL_FREETYPE_INCLUDE_PATH" != x; then
-    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
-
-  # Input might be given as Windows format, start by converting to
-  # unix format.
-  path="$POTENTIAL_FREETYPE_INCLUDE_PATH"
-  new_path=`$CYGPATH -u "$path"`
-
-  # Cygwin tries to hide some aspects of the Windows file system, such that binaries are
-  # named .exe but called without that suffix. Therefore, "foo" and "foo.exe" are considered
-  # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then
-  # "foo.exe" is OK but "foo" is an error.
-  #
-  # This test is therefore slightly more accurate than "test -f" to check for file precense.
-  # It is also a way to make sure we got the proper file name for the real test later on.
-  test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null`
-  if test "x$test_shortpath" = x; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: The path of POTENTIAL_FREETYPE_INCLUDE_PATH, which resolves as \"$path\", is invalid." >&5
-$as_echo "$as_me: The path of POTENTIAL_FREETYPE_INCLUDE_PATH, which resolves as \"$path\", is invalid." >&6;}
-    as_fn_error $? "Cannot locate the the path of POTENTIAL_FREETYPE_INCLUDE_PATH" "$LINENO" 5
-  fi
-
-  # Call helper function which possibly converts this using DOS-style short mode.
-  # If so, the updated path is stored in $new_path.
-
-  input_path="$new_path"
-  # Check if we need to convert this using DOS-style short mode. If the path
-  # contains just simple characters, use it. Otherwise (spaces, weird characters),
-  # take no chances and rewrite it.
-  # Note: m4 eats our [], so we need to use [ and ] instead.
-  has_forbidden_chars=`$ECHO "$input_path" | $GREP [^-._/a-zA-Z0-9]`
-  if test "x$has_forbidden_chars" != x; then
-    # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \)
-    shortmode_path=`$CYGPATH -s -m -a "$input_path"`
-    path_after_shortmode=`$CYGPATH -u "$shortmode_path"`
-    if test "x$path_after_shortmode" != "x$input_to_shortpath"; then
-      # Going to short mode and back again did indeed matter. Since short mode is
-      # case insensitive, let's make it lowercase to improve readability.
-      shortmode_path=`$ECHO "$shortmode_path" | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-      # Now convert it back to Unix-style (cygpath)
-      input_path=`$CYGPATH -u "$shortmode_path"`
-      new_path="$input_path"
-    fi
-  fi
-
-  test_cygdrive_prefix=`$ECHO $input_path | $GREP ^/cygdrive/`
-  if test "x$test_cygdrive_prefix" = x; then
-    # As a simple fix, exclude /usr/bin since it's not a real path.
-    if test "x`$ECHO $new_path | $GREP ^/usr/bin/`" = x; then
-      # The path is in a Cygwin special directory (e.g. /home). We need this converted to
-      # a path prefixed by /cygdrive for fixpath to work.
-      new_path="$CYGWIN_ROOT_PATH$input_path"
-    fi
-  fi
-
-
-  if test "x$path" != "x$new_path"; then
-    POTENTIAL_FREETYPE_INCLUDE_PATH="$new_path"
-    { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting POTENTIAL_FREETYPE_INCLUDE_PATH to \"$new_path\"" >&5
-$as_echo "$as_me: Rewriting POTENTIAL_FREETYPE_INCLUDE_PATH to \"$new_path\"" >&6;}
-  fi
-
-    elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
-
-  path="$POTENTIAL_FREETYPE_INCLUDE_PATH"
-  has_colon=`$ECHO $path | $GREP ^.:`
-  new_path="$path"
-  if test "x$has_colon" = x; then
-    # Not in mixed or Windows style, start by that.
-    new_path=`cmd //c echo $path`
-  fi
-
-
-  input_path="$new_path"
-  # Check if we need to convert this using DOS-style short mode. If the path
-  # contains just simple characters, use it. Otherwise (spaces, weird characters),
-  # take no chances and rewrite it.
-  # Note: m4 eats our [], so we need to use [ and ] instead.
-  has_forbidden_chars=`$ECHO "$input_path" | $GREP [^-_/:a-zA-Z0-9]`
-  if test "x$has_forbidden_chars" != x; then
-    # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \)
-    new_path=`cmd /c "for %A in (\"$input_path\") do @echo %~sA"|$TR \\\\\\\\ / | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-  fi
-
-
-  windows_path="$new_path"
-  if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
-    unix_path=`$CYGPATH -u "$windows_path"`
-    new_path="$unix_path"
-  elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
-    unix_path=`$ECHO "$windows_path" | $SED -e 's,^\\(.\\):,/\\1,g' -e 's,\\\\,/,g'`
-    new_path="$unix_path"
-  fi
-
-  if test "x$path" != "x$new_path"; then
-    POTENTIAL_FREETYPE_INCLUDE_PATH="$new_path"
-    { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting POTENTIAL_FREETYPE_INCLUDE_PATH to \"$new_path\"" >&5
-$as_echo "$as_me: Rewriting POTENTIAL_FREETYPE_INCLUDE_PATH to \"$new_path\"" >&6;}
-  fi
-
-  # Save the first 10 bytes of this path to the storage, so fixpath can work.
-  all_fixpath_prefixes=("${all_fixpath_prefixes[@]}" "${new_path:0:10}")
-
-    else
-      # We're on a unix platform. Hooray! :)
-      path="$POTENTIAL_FREETYPE_INCLUDE_PATH"
-      has_space=`$ECHO "$path" | $GREP " "`
-      if test "x$has_space" != x; then
-        { $as_echo "$as_me:${as_lineno-$LINENO}: The path of POTENTIAL_FREETYPE_INCLUDE_PATH, which resolves as \"$path\", is invalid." >&5
-$as_echo "$as_me: The path of POTENTIAL_FREETYPE_INCLUDE_PATH, which resolves as \"$path\", is invalid." >&6;}
-        as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5
-      fi
-
-      # Use eval to expand a potential ~
-      eval path="$path"
-      if test ! -f "$path" && test ! -d "$path"; then
-        as_fn_error $? "The path of POTENTIAL_FREETYPE_INCLUDE_PATH, which resolves as \"$path\", is not found." "$LINENO" 5
-      fi
-
-      if test -d "$path"; then
-        POTENTIAL_FREETYPE_INCLUDE_PATH="`cd "$path"; $THEPWDCMD -L`"
-      else
-        dir="`$DIRNAME "$path"`"
-        base="`$BASENAME "$path"`"
-        POTENTIAL_FREETYPE_INCLUDE_PATH="`cd "$dir"; $THEPWDCMD -L`/$base"
-      fi
-    fi
-  fi
-
-
-  # Only process if variable expands to non-empty
-
-  if test "x$POTENTIAL_FREETYPE_LIB_PATH" != x; then
-    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
-
-  # Input might be given as Windows format, start by converting to
-  # unix format.
-  path="$POTENTIAL_FREETYPE_LIB_PATH"
-  new_path=`$CYGPATH -u "$path"`
-
-  # Cygwin tries to hide some aspects of the Windows file system, such that binaries are
-  # named .exe but called without that suffix. Therefore, "foo" and "foo.exe" are considered
-  # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then
-  # "foo.exe" is OK but "foo" is an error.
-  #
-  # This test is therefore slightly more accurate than "test -f" to check for file precense.
-  # It is also a way to make sure we got the proper file name for the real test later on.
-  test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null`
-  if test "x$test_shortpath" = x; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: The path of POTENTIAL_FREETYPE_LIB_PATH, which resolves as \"$path\", is invalid." >&5
-$as_echo "$as_me: The path of POTENTIAL_FREETYPE_LIB_PATH, which resolves as \"$path\", is invalid." >&6;}
-    as_fn_error $? "Cannot locate the the path of POTENTIAL_FREETYPE_LIB_PATH" "$LINENO" 5
-  fi
-
-  # Call helper function which possibly converts this using DOS-style short mode.
-  # If so, the updated path is stored in $new_path.
-
-  input_path="$new_path"
-  # Check if we need to convert this using DOS-style short mode. If the path
-  # contains just simple characters, use it. Otherwise (spaces, weird characters),
-  # take no chances and rewrite it.
-  # Note: m4 eats our [], so we need to use [ and ] instead.
-  has_forbidden_chars=`$ECHO "$input_path" | $GREP [^-._/a-zA-Z0-9]`
-  if test "x$has_forbidden_chars" != x; then
-    # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \)
-    shortmode_path=`$CYGPATH -s -m -a "$input_path"`
-    path_after_shortmode=`$CYGPATH -u "$shortmode_path"`
-    if test "x$path_after_shortmode" != "x$input_to_shortpath"; then
-      # Going to short mode and back again did indeed matter. Since short mode is
-      # case insensitive, let's make it lowercase to improve readability.
-      shortmode_path=`$ECHO "$shortmode_path" | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-      # Now convert it back to Unix-style (cygpath)
-      input_path=`$CYGPATH -u "$shortmode_path"`
-      new_path="$input_path"
-    fi
-  fi
-
-  test_cygdrive_prefix=`$ECHO $input_path | $GREP ^/cygdrive/`
-  if test "x$test_cygdrive_prefix" = x; then
-    # As a simple fix, exclude /usr/bin since it's not a real path.
-    if test "x`$ECHO $new_path | $GREP ^/usr/bin/`" = x; then
-      # The path is in a Cygwin special directory (e.g. /home). We need this converted to
-      # a path prefixed by /cygdrive for fixpath to work.
-      new_path="$CYGWIN_ROOT_PATH$input_path"
-    fi
-  fi
-
-
-  if test "x$path" != "x$new_path"; then
-    POTENTIAL_FREETYPE_LIB_PATH="$new_path"
-    { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting POTENTIAL_FREETYPE_LIB_PATH to \"$new_path\"" >&5
-$as_echo "$as_me: Rewriting POTENTIAL_FREETYPE_LIB_PATH to \"$new_path\"" >&6;}
-  fi
-
-    elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
-
-  path="$POTENTIAL_FREETYPE_LIB_PATH"
-  has_colon=`$ECHO $path | $GREP ^.:`
-  new_path="$path"
-  if test "x$has_colon" = x; then
-    # Not in mixed or Windows style, start by that.
-    new_path=`cmd //c echo $path`
-  fi
-
-
-  input_path="$new_path"
-  # Check if we need to convert this using DOS-style short mode. If the path
-  # contains just simple characters, use it. Otherwise (spaces, weird characters),
-  # take no chances and rewrite it.
-  # Note: m4 eats our [], so we need to use [ and ] instead.
-  has_forbidden_chars=`$ECHO "$input_path" | $GREP [^-_/:a-zA-Z0-9]`
-  if test "x$has_forbidden_chars" != x; then
-    # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \)
-    new_path=`cmd /c "for %A in (\"$input_path\") do @echo %~sA"|$TR \\\\\\\\ / | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-  fi
-
-
-  windows_path="$new_path"
-  if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
-    unix_path=`$CYGPATH -u "$windows_path"`
-    new_path="$unix_path"
-  elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
-    unix_path=`$ECHO "$windows_path" | $SED -e 's,^\\(.\\):,/\\1,g' -e 's,\\\\,/,g'`
-    new_path="$unix_path"
-  fi
-
-  if test "x$path" != "x$new_path"; then
-    POTENTIAL_FREETYPE_LIB_PATH="$new_path"
-    { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting POTENTIAL_FREETYPE_LIB_PATH to \"$new_path\"" >&5
-$as_echo "$as_me: Rewriting POTENTIAL_FREETYPE_LIB_PATH to \"$new_path\"" >&6;}
-  fi
-
-  # Save the first 10 bytes of this path to the storage, so fixpath can work.
-  all_fixpath_prefixes=("${all_fixpath_prefixes[@]}" "${new_path:0:10}")
-
-    else
-      # We're on a unix platform. Hooray! :)
-      path="$POTENTIAL_FREETYPE_LIB_PATH"
-      has_space=`$ECHO "$path" | $GREP " "`
-      if test "x$has_space" != x; then
-        { $as_echo "$as_me:${as_lineno-$LINENO}: The path of POTENTIAL_FREETYPE_LIB_PATH, which resolves as \"$path\", is invalid." >&5
-$as_echo "$as_me: The path of POTENTIAL_FREETYPE_LIB_PATH, which resolves as \"$path\", is invalid." >&6;}
-        as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5
-      fi
-
-      # Use eval to expand a potential ~
-      eval path="$path"
-      if test ! -f "$path" && test ! -d "$path"; then
-        as_fn_error $? "The path of POTENTIAL_FREETYPE_LIB_PATH, which resolves as \"$path\", is not found." "$LINENO" 5
-      fi
-
-      if test -d "$path"; then
-        POTENTIAL_FREETYPE_LIB_PATH="`cd "$path"; $THEPWDCMD -L`"
-      else
-        dir="`$DIRNAME "$path"`"
-        base="`$BASENAME "$path"`"
-        POTENTIAL_FREETYPE_LIB_PATH="`cd "$dir"; $THEPWDCMD -L`/$base"
-      fi
-    fi
-  fi
-
-
-    FREETYPE_INCLUDE_PATH="$POTENTIAL_FREETYPE_INCLUDE_PATH"
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for freetype includes" >&5
-$as_echo_n "checking for freetype includes... " >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $FREETYPE_INCLUDE_PATH" >&5
-$as_echo "$FREETYPE_INCLUDE_PATH" >&6; }
-    FREETYPE_LIB_PATH="$POTENTIAL_FREETYPE_LIB_PATH"
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for freetype libraries" >&5
-$as_echo_n "checking for freetype libraries... " >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $FREETYPE_LIB_PATH" >&5
-$as_echo "$FREETYPE_LIB_PATH" >&6; }
-  fi
-
-          fi
-
-          if test "x$FOUND_FREETYPE" != xyes; then
             FREETYPE_BASE_DIR="$SYSROOT/usr"
             if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 
--- a/common/autoconf/jdk-options.m4	Thu Sep 29 11:13:42 2016 +0530
+++ b/common/autoconf/jdk-options.m4	Fri Sep 30 09:28:18 2016 -0700
@@ -134,32 +134,25 @@
 
 AC_DEFUN_ONCE([JDKOPT_SETUP_JDK_OPTIONS],
 [
-  # Should we build a JDK/JVM with headful support (ie a graphical ui)?
-  # We always build headless support.
-  AC_MSG_CHECKING([headful support])
-  AC_ARG_ENABLE([headful], [AS_HELP_STRING([--disable-headful],
-      [disable building headful support (graphical UI support) @<:@enabled@:>@])],
-      [SUPPORT_HEADFUL=${enable_headful}], [SUPPORT_HEADFUL=yes])
+  # Should we build a JDK without a graphical UI?
+  AC_MSG_CHECKING([headless only])
+  AC_ARG_ENABLE([headless-only], [AS_HELP_STRING([--enable-headless-only],
+      [only build headless (no GUI) support @<:@disabled@:>@])])
 
-  SUPPORT_HEADLESS=yes
-  BUILD_HEADLESS="BUILD_HEADLESS:=true"
-
-  if test "x$SUPPORT_HEADFUL" = xyes; then
-    # We are building both headful and headless.
-    headful_msg="include support for both headful and headless"
+  if test "x$enable_headless_only" = "xyes"; then
+    ENABLE_HEADLESS_ONLY="true"
+    AC_MSG_RESULT([yes])
+  elif test "x$enable_headless_only" = "xno"; then
+    ENABLE_HEADLESS_ONLY="false"
+    AC_MSG_RESULT([no])
+  elif test "x$enable_headless_only" = "x"; then
+    ENABLE_HEADLESS_ONLY="false"
+    AC_MSG_RESULT([no])
+  else
+    AC_MSG_ERROR([--enable-headless-only can only take yes or no])
   fi
 
-  if test "x$SUPPORT_HEADFUL" = xno; then
-    # Thus we are building headless only.
-    BUILD_HEADLESS="BUILD_HEADLESS:=true"
-    headful_msg="headless only"
-  fi
-
-  AC_MSG_RESULT([$headful_msg])
-
-  AC_SUBST(SUPPORT_HEADLESS)
-  AC_SUBST(SUPPORT_HEADFUL)
-  AC_SUBST(BUILD_HEADLESS)
+  AC_SUBST(ENABLE_HEADLESS_ONLY)
 
   # Choose cacerts source file
   AC_ARG_WITH(cacerts-file, [AS_HELP_STRING([--with-cacerts-file],
--- a/common/autoconf/lib-cups.m4	Thu Sep 29 11:13:42 2016 +0530
+++ b/common/autoconf/lib-cups.m4	Fri Sep 30 09:28:18 2016 -0700
@@ -76,21 +76,6 @@
       ])
     fi
     if test "x$CUPS_FOUND" = xno; then
-      # Getting nervous now? Lets poke around for standard Solaris third-party
-      # package installation locations.
-      AC_MSG_CHECKING([for cups headers])
-      if test -s $SYSROOT/opt/sfw/cups/include/cups/cups.h; then
-        # An SFW package seems to be installed!
-        CUPS_FOUND=yes
-        CUPS_CFLAGS="-I$SYSROOT/opt/sfw/cups/include"
-      elif test -s $SYSROOT/opt/csw/include/cups/cups.h; then
-        # A CSW package seems to be installed!
-        CUPS_FOUND=yes
-        CUPS_CFLAGS="-I$SYSROOT/opt/csw/include"
-      fi
-      AC_MSG_RESULT([$CUPS_FOUND])
-    fi
-    if test "x$CUPS_FOUND" = xno; then
       HELP_MSG_MISSING_DEPENDENCY([cups])
       AC_MSG_ERROR([Could not find cups! $HELP_MSG ])
     fi
--- a/common/autoconf/lib-freetype.m4	Thu Sep 29 11:13:42 2016 +0530
+++ b/common/autoconf/lib-freetype.m4	Fri Sep 30 09:28:18 2016 -0700
@@ -358,11 +358,6 @@
           fi
 
           if test "x$FOUND_FREETYPE" != xyes; then
-            FREETYPE_BASE_DIR="$SYSROOT/usr/sfw"
-            LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
-          fi
-
-          if test "x$FOUND_FREETYPE" != xyes; then
             FREETYPE_BASE_DIR="$SYSROOT/usr"
             if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
               LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib/x86_64-linux-gnu], [well-known location])
--- a/common/autoconf/lib-x11.m4	Thu Sep 29 11:13:42 2016 +0530
+++ b/common/autoconf/lib-x11.m4	Fri Sep 30 09:28:18 2016 -0700
@@ -91,9 +91,7 @@
     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
       OPENWIN_HOME="/usr/openwin"
       X_CFLAGS="-I$SYSROOT$OPENWIN_HOME/include -I$SYSROOT$OPENWIN_HOME/include/X11/extensions"
-      X_LIBS="-L$SYSROOT$OPENWIN_HOME/sfw/lib$OPENJDK_TARGET_CPU_ISADIR \
-          -L$SYSROOT$OPENWIN_HOME/lib$OPENJDK_TARGET_CPU_ISADIR \
-          -R$OPENWIN_HOME/sfw/lib$OPENJDK_TARGET_CPU_ISADIR \
+      X_LIBS="-L$SYSROOT$OPENWIN_HOME/lib$OPENJDK_TARGET_CPU_ISADIR \
           -R$OPENWIN_HOME/lib$OPENJDK_TARGET_CPU_ISADIR"
     fi
 
--- a/common/autoconf/libraries.m4	Thu Sep 29 11:13:42 2016 +0530
+++ b/common/autoconf/libraries.m4	Fri Sep 30 09:28:18 2016 -0700
@@ -42,13 +42,9 @@
     # No X11 support on windows or macosx
     NEEDS_LIB_X11=false
   else
-    if test "x$SUPPORT_HEADFUL" = xno; then
-      # No X11 support if building headless-only
-      NEEDS_LIB_X11=false
-    else
-      # All other instances need X11
-      NEEDS_LIB_X11=true
-    fi
+    # All other instances need X11, even if building headless only, libawt still
+    # needs X11 headers.
+    NEEDS_LIB_X11=true
   fi
 
   # Check if cups is needed
--- a/common/autoconf/spec.gmk.in	Thu Sep 29 11:13:42 2016 +0530
+++ b/common/autoconf/spec.gmk.in	Fri Sep 30 09:28:18 2016 -0700
@@ -241,12 +241,8 @@
 # Control use of precompiled header in hotspot libjvm build
 USE_PRECOMPILED_HEADER := @USE_PRECOMPILED_HEADER@
 
-# Should we compile support for running with a graphical UI? (ie headful)
-# Should we compile support for running without? (ie headless)
-SUPPORT_HEADFUL:=@SUPPORT_HEADFUL@
-SUPPORT_HEADLESS:=@SUPPORT_HEADLESS@
-# Legacy defines controlled by the SUPPORT_HEADLESS and SUPPORT_HEADFUL options.
-@BUILD_HEADLESS@
+# Only build headless support or not
+ENABLE_HEADLESS_ONLY := @ENABLE_HEADLESS_ONLY@
 
 # Legacy support
 USE_NEW_HOTSPOT_BUILD:=@USE_NEW_HOTSPOT_BUILD@
--- a/common/autoconf/toolchain.m4	Thu Sep 29 11:13:42 2016 +0530
+++ b/common/autoconf/toolchain.m4	Fri Sep 30 09:28:18 2016 -0700
@@ -294,14 +294,6 @@
   fi
   AC_SUBST(TOOLCHAIN_VERSION)
 
-  # For solaris we really need solaris tools, and not the GNU equivalent.
-  # The build tools on Solaris reside in /usr/ccs (C Compilation System),
-  # so add that to path before starting to probe.
-  # FIXME: This was originally only done for AS,NM,GNM,STRIP,OBJCOPY,OBJDUMP.
-  if test "x$OPENJDK_BUILD_OS" = xsolaris; then
-    PATH="/usr/ccs/bin:$PATH"
-  fi
-
   # Finally add TOOLCHAIN_PATH at the beginning, to allow --with-tools-dir to
   # override all other locations.
   if test "x$TOOLCHAIN_PATH" != x; then
--- a/common/conf/jib-profiles.js	Thu Sep 29 11:13:42 2016 +0530
+++ b/common/conf/jib-profiles.js	Fri Sep 30 09:28:18 2016 -0700
@@ -224,6 +224,23 @@
     common.configure_args_slowdebug = ["--with-debug-level=slowdebug"],
     common.organization = "jpg.infra.builddeps"
 
+    var boot_jdk_revision = "8";
+    var boot_jdk_subdirpart = "1.8.0";
+    // JDK 8 does not work on sparc M7 cpus, need a newer update when building
+    // on such hardware.
+    if (input.build_cpu == "sparcv9") {
+       var cpu_brand = $EXEC("bash -c \"kstat -m cpu_info | grep brand | head -n1 | awk '{ print \$2 }'\"");
+       if (cpu_brand.trim() == 'SPARC-M7') {
+           boot_jdk_revision = "8u20";
+           boot_jdk_subdirpart = "1.8.0_20";
+       }
+    }
+    common.boot_jdk_revision = boot_jdk_revision;
+    common.boot_jdk_subdirpart = boot_jdk_subdirpart;
+    common.boot_jdk_home = input.get("boot_jdk", "home_path") + "/jdk"
+        + common.boot_jdk_subdirpart
+        + (input.build_os == "macosx" ? ".jdk/Contents/Home" : "");
+
     return common;
 };
 
@@ -333,8 +350,11 @@
         "run-test": {
             target_os: input.build_os,
             target_cpu: input.build_cpu,
-            dependencies: [ "jtreg", "gnumake" ],
-            labels: "test"
+            dependencies: [ "jtreg", "gnumake", "boot_jdk" ],
+            labels: "test",
+            environment: {
+                "JT_JAVA": common.boot_jdk_home
+            }
         }
     };
     profiles = concatObjects(profiles, testOnlyProfiles);
@@ -357,18 +377,6 @@
     var boot_jdk_platform = input.build_os + "-"
         + (input.build_cpu == "x86" ? "i586" : input.build_cpu);
 
-    var boot_jdk_revision = "8";
-    var boot_jdk_subdirpart = "1.8.0";
-    // JDK 8 does not work on sparc M7 cpus, need a newer update when building
-    // on such hardware.
-    if (input.build_cpu == "sparcv9") {
-       var cpu_brand = $EXEC("bash -c \"kstat -m cpu_info | grep brand | head -n1 | awk '{ print \$2 }'\"");
-       if (cpu_brand.trim() == 'SPARC-M7') {
-           boot_jdk_revision = "8u20";
-           boot_jdk_subdirpart = "1.8.0_20";
-       }
-    }
-
     var devkit_platform_revisions = {
         linux_x64: "gcc4.9.2-OEL6.4+1.0",
         macosx_x64: "Xcode6.3-MacOSX10.9+1.0",
@@ -386,12 +394,12 @@
         boot_jdk: {
             server: "javare",
             module: "jdk",
-            revision: boot_jdk_revision,
+            revision: common.boot_jdk_revision,
             checksum_file: boot_jdk_platform + "/MD5_VALUES",
-            file: boot_jdk_platform + "/jdk-" + boot_jdk_revision + "-" + boot_jdk_platform + ".tar.gz",
-            configure_args: (input.build_os == "macosx"
-                ? "--with-boot-jdk=" + input.get("boot_jdk", "install_path") + "/jdk" + boot_jdk_subdirpart + ".jdk/Contents/Home"
-                : "--with-boot-jdk=" + input.get("boot_jdk", "install_path") + "/jdk" + boot_jdk_subdirpart)
+            file: boot_jdk_platform + "/jdk-" + common.boot_jdk_revision
+                + "-" + boot_jdk_platform + ".tar.gz",
+            configure_args: "--with-boot-jdk=" + common.boot_jdk_home,
+            environment_path: common.boot_jdk_home
         },
 
         devkit: {
@@ -420,7 +428,8 @@
             build_number: "b03",
             checksum_file: "MD5_VALUES",
             file: "jtreg_bin-4.2.zip",
-            environment_name: "JT_HOME"
+            environment_name: "JT_HOME",
+            environment_path: input.get("jtreg", "install_path") + "/jtreg/bin"
         },
 
         gnumake: {
--- a/corba/.hgtags	Thu Sep 29 11:13:42 2016 +0530
+++ b/corba/.hgtags	Fri Sep 30 09:28:18 2016 -0700
@@ -379,3 +379,4 @@
 1a497f5ca0cfd88115cc7daa8af8a62b8741caf2 jdk-9+134
 094d0db606db976045f594dba47d4593b715cc81 jdk-9+135
 aa053a3faf266c12b4fd5272da431a3e08e4a3e3 jdk-9+136
+258cf18fa7fc59359b874f8743b7168dc48baf73 jdk-9+137
--- a/hotspot/.hgtags	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/.hgtags	Fri Sep 30 09:28:18 2016 -0700
@@ -539,3 +539,4 @@
 b8b694c6b4d2ab0939aed7adaf0eec1ac321a085 jdk-9+134
 3b1c4562953db47e36b237a500f368d5c9746d47 jdk-9+135
 a20da289f646ee44440695b81abc0548330e4ca7 jdk-9+136
+dfcbf839e299e7e2bba1da69bdb347617ea4c7e8 jdk-9+137
--- a/hotspot/make/test/JtregNative.gmk	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/make/test/JtregNative.gmk	Fri Sep 30 09:28:18 2016 -0700
@@ -44,6 +44,7 @@
     $(HOTSPOT_TOPDIR)/test/native_sanity \
     $(HOTSPOT_TOPDIR)/test/runtime/jni/8025979 \
     $(HOTSPOT_TOPDIR)/test/runtime/jni/8033445 \
+    $(HOTSPOT_TOPDIR)/test/runtime/jni/checked \
     $(HOTSPOT_TOPDIR)/test/runtime/jni/ToStringInInterfaceTest \
     $(HOTSPOT_TOPDIR)/test/runtime/modules/getModuleJNI \
     $(HOTSPOT_TOPDIR)/test/runtime/SameObject \
--- a/hotspot/src/cpu/aarch64/vm/interp_masm_aarch64.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/aarch64/vm/interp_masm_aarch64.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -326,7 +326,8 @@
 }
 
 void InterpreterMacroAssembler::push_l(Register r) {
-  str(r, pre(esp, 2 * -wordSize));
+  str(zr, pre(esp, -wordSize));
+  str(r, pre(esp, -wordsize));
 }
 
 void InterpreterMacroAssembler::pop_f(FloatRegister r) {
--- a/hotspot/src/cpu/aarch64/vm/sharedRuntime_aarch64.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/aarch64/vm/sharedRuntime_aarch64.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -2041,6 +2041,11 @@
       __ verify_oop(r0);
   }
 
+  if (CheckJNICalls) {
+    // clear_pending_jni_exception_check
+    __ str(zr, Address(rthread, JavaThread::pending_jni_exception_check_fn_offset()));
+  }
+
   if (!is_critical_native) {
     // reset handle block
     __ ldr(r2, Address(rthread, JavaThread::active_handles_offset()));
--- a/hotspot/src/cpu/aarch64/vm/templateInterpreterGenerator_aarch64.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/aarch64/vm/templateInterpreterGenerator_aarch64.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1355,6 +1355,11 @@
   // reset_last_Java_frame
   __ reset_last_Java_frame(true);
 
+  if (CheckJNICalls) {
+    // clear_pending_jni_exception_check
+    __ str(zr, Address(rthread, JavaThread::pending_jni_exception_check_fn_offset()));
+  }
+
   // reset handle block
   __ ldr(t, Address(rthread, JavaThread::active_handles_offset()));
   __ str(zr, Address(t, JNIHandleBlock::top_offset_in_bytes()));
--- a/hotspot/src/cpu/sparc/vm/globals_sparc.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/sparc/vm/globals_sparc.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -57,10 +57,12 @@
 
 #ifdef _LP64
 // Stack slots are 2X larger in LP64 than in the 32 bit VM.
+define_pd_global(intx, CompilerThreadStackSize, 1024);
 define_pd_global(intx, ThreadStackSize,       1024);
 define_pd_global(intx, VMThreadStackSize,     1024);
 #define DEFAULT_STACK_SHADOW_PAGES (20 DEBUG_ONLY(+2))
 #else
+define_pd_global(intx, CompilerThreadStackSize, 512);
 define_pd_global(intx, ThreadStackSize,       512);
 define_pd_global(intx, VMThreadStackSize,     512);
 #define DEFAULT_STACK_SHADOW_PAGES (6 DEBUG_ONLY(+2))
--- a/hotspot/src/cpu/sparc/vm/interp_masm_sparc.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/sparc/vm/interp_masm_sparc.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -359,7 +359,7 @@
 #ifdef _LP64
   stx(l, r1, offset);
   // store something more useful here
-  debug_only(stx(G0, r1, offset+Interpreter::stackElementSize);)
+  stx(G0, r1, offset+Interpreter::stackElementSize);
 #else
   st(l, r1, offset);
   st(l->successor(), r1, offset + Interpreter::stackElementSize);
--- a/hotspot/src/cpu/sparc/vm/sharedRuntime_sparc.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/sparc/vm/sharedRuntime_sparc.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -2765,6 +2765,11 @@
       __ verify_oop(I0);
   }
 
+  if (CheckJNICalls) {
+    // clear_pending_jni_exception_check
+    __ st_ptr(G0, G2_thread, JavaThread::pending_jni_exception_check_fn_offset());
+  }
+
   if (!is_critical_native) {
     // reset handle block
     __ ld_ptr(G2_thread, in_bytes(JavaThread::active_handles_offset()), L5);
--- a/hotspot/src/cpu/sparc/vm/sparc.ad	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/sparc/vm/sparc.ad	Fri Sep 30 09:28:18 2016 -0700
@@ -2921,6 +2921,26 @@
     __ cmp( Rold, O7 );
   %}
 
+  // raw int cas without using tmp register for compareAndExchange
+  enc_class enc_casi_exch( iRegP mem, iRegL old, iRegL new) %{
+    Register Rmem = reg_to_register_object($mem$$reg);
+    Register Rold = reg_to_register_object($old$$reg);
+    Register Rnew = reg_to_register_object($new$$reg);
+
+    MacroAssembler _masm(&cbuf);
+    __ cas(Rmem, Rold, Rnew);
+  %}
+
+  // 64-bit cas without using tmp register for compareAndExchange
+  enc_class enc_casx_exch( iRegP mem, iRegL old, iRegL new) %{
+    Register Rmem = reg_to_register_object($mem$$reg);
+    Register Rold = reg_to_register_object($old$$reg);
+    Register Rnew = reg_to_register_object($new$$reg);
+
+    MacroAssembler _masm(&cbuf);
+    __ casx(Rmem, Rold, Rnew);
+  %}
+
   enc_class enc_lflags_ne_to_boolean( iRegI res ) %{
     Register Rres = reg_to_register_object($res$$reg);
 
@@ -7105,6 +7125,7 @@
 instruct compareAndSwapL_bool(iRegP mem_ptr, iRegL oldval, iRegL newval, iRegI res, o7RegI tmp1, flagsReg ccr ) %{
   predicate(VM_Version::supports_cx8());
   match(Set res (CompareAndSwapL mem_ptr (Binary oldval newval)));
+  match(Set res (WeakCompareAndSwapL mem_ptr (Binary oldval newval)));
   effect( USE mem_ptr, KILL ccr, KILL tmp1);
   format %{
             "MOV    $newval,O7\n\t"
@@ -7121,6 +7142,7 @@
 
 instruct compareAndSwapI_bool(iRegP mem_ptr, iRegI oldval, iRegI newval, iRegI res, o7RegI tmp1, flagsReg ccr ) %{
   match(Set res (CompareAndSwapI mem_ptr (Binary oldval newval)));
+  match(Set res (WeakCompareAndSwapI mem_ptr (Binary oldval newval)));
   effect( USE mem_ptr, KILL ccr, KILL tmp1);
   format %{
             "MOV    $newval,O7\n\t"
@@ -7139,6 +7161,7 @@
   predicate(VM_Version::supports_cx8());
 #endif
   match(Set res (CompareAndSwapP mem_ptr (Binary oldval newval)));
+  match(Set res (WeakCompareAndSwapP mem_ptr (Binary oldval newval)));
   effect( USE mem_ptr, KILL ccr, KILL tmp1);
   format %{
             "MOV    $newval,O7\n\t"
@@ -7159,6 +7182,7 @@
 
 instruct compareAndSwapN_bool(iRegP mem_ptr, iRegN oldval, iRegN newval, iRegI res, o7RegI tmp1, flagsReg ccr ) %{
   match(Set res (CompareAndSwapN mem_ptr (Binary oldval newval)));
+  match(Set res (WeakCompareAndSwapN mem_ptr (Binary oldval newval)));
   effect( USE mem_ptr, KILL ccr, KILL tmp1);
   format %{
             "MOV    $newval,O7\n\t"
@@ -7172,6 +7196,54 @@
   ins_pipe( long_memory_op );
 %}
 
+instruct compareAndExchangeI(iRegP mem_ptr, iRegI oldval, iRegI newval)
+%{
+  match(Set newval (CompareAndExchangeI mem_ptr (Binary oldval newval)));
+  effect( USE mem_ptr );
+
+  format %{
+            "CASA   [$mem_ptr],$oldval,$newval\t! If $oldval==[$mem_ptr] Then store $newval into [$mem_ptr] and set $newval=[$mem_ptr]\n\t"
+  %}
+  ins_encode( enc_casi_exch(mem_ptr, oldval, newval) );
+  ins_pipe( long_memory_op );
+%}
+
+instruct compareAndExchangeL(iRegP mem_ptr, iRegL oldval, iRegL newval)
+%{
+  match(Set newval (CompareAndExchangeL mem_ptr (Binary oldval newval)));
+  effect( USE mem_ptr );
+
+  format %{
+            "CASXA  [$mem_ptr],$oldval,$newval\t! If $oldval==[$mem_ptr] Then store $newval into [$mem_ptr] and set $newval=[$mem_ptr]\n\t"
+  %}
+  ins_encode( enc_casx_exch(mem_ptr, oldval, newval) );
+  ins_pipe( long_memory_op );
+%}
+
+instruct compareAndExchangeP(iRegP mem_ptr, iRegP oldval, iRegP newval)
+%{
+  match(Set newval (CompareAndExchangeP mem_ptr (Binary oldval newval)));
+  effect( USE mem_ptr );
+
+  format %{
+            "CASXA  [$mem_ptr],$oldval,$newval\t! If $oldval==[$mem_ptr] Then store $newval into [$mem_ptr] and set $newval=[$mem_ptr]\n\t"
+  %}
+  ins_encode( enc_casx_exch(mem_ptr, oldval, newval) );
+  ins_pipe( long_memory_op );
+%}
+
+instruct compareAndExchangeN(iRegP mem_ptr, iRegN oldval, iRegN newval)
+%{
+  match(Set newval (CompareAndExchangeN mem_ptr (Binary oldval newval)));
+  effect( USE mem_ptr );
+
+  format %{
+            "CASA   [$mem_ptr],$oldval,$newval\t! If $oldval==[$mem_ptr] Then store $newval into [$mem_ptr] and set $newval=[$mem_ptr]\n\t"
+  %}
+  ins_encode( enc_casi_exch(mem_ptr, oldval, newval) );
+  ins_pipe( long_memory_op );
+%}
+
 instruct xchgI( memory mem, iRegI newval) %{
   match(Set newval (GetAndSetI mem newval));
   format %{ "SWAP  [$mem],$newval" %}
--- a/hotspot/src/cpu/sparc/vm/templateInterpreterGenerator_sparc.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/sparc/vm/templateInterpreterGenerator_sparc.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1487,6 +1487,11 @@
   __ set(_thread_in_Java, G3_scratch);
   __ st(G3_scratch, thread_state);
 
+  if (CheckJNICalls) {
+    // clear_pending_jni_exception_check
+    __ st_ptr(G0, G2_thread, JavaThread::pending_jni_exception_check_fn_offset());
+  }
+
   // reset handle block
   __ ld_ptr(G2_thread, JavaThread::active_handles_offset(), G3_scratch);
   __ st(G0, G3_scratch, JNIHandleBlock::top_offset_in_bytes());
--- a/hotspot/src/cpu/x86/vm/interp_masm_x86.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/x86/vm/interp_masm_x86.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -611,7 +611,8 @@
 
 void InterpreterMacroAssembler::push_l(Register r) {
   subptr(rsp, 2 * wordSize);
-  movq(Address(rsp, 0), r);
+  movptr(Address(rsp, Interpreter::expr_offset_in_bytes(0)), r         );
+  movptr(Address(rsp, Interpreter::expr_offset_in_bytes(1)), NULL_WORD );
 }
 
 void InterpreterMacroAssembler::pop(TosState state) {
--- a/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -8131,8 +8131,7 @@
     jmp(FALSE_LABEL);
 
     clear_vector_masking();   // closing of the stub context for programming mask registers
-  }
-  else {
+  } else {
     movl(result, len); // copy
 
     if (UseAVX == 2 && UseSSE >= 2) {
@@ -8169,8 +8168,7 @@
       bind(COMPARE_TAIL); // len is zero
       movl(len, result);
       // Fallthru to tail compare
-    }
-    else if (UseSSE42Intrinsics) {
+    } else if (UseSSE42Intrinsics) {
       // With SSE4.2, use double quad vector compare
       Label COMPARE_WIDE_VECTORS, COMPARE_TAIL;
 
@@ -10748,7 +10746,10 @@
   // save length for return
   push(len);
 
+  // 8165287: EVEX version disabled for now, needs to be refactored as
+  // it is returning incorrect results.
   if ((UseAVX > 2) && // AVX512
+    0 &&
     VM_Version::supports_avx512vlbw() &&
     VM_Version::supports_bmi2()) {
 
@@ -11067,10 +11068,11 @@
 
       bind(below_threshold);
       bind(copy_new_tail);
-      if (UseAVX > 2) {
+      if ((UseAVX > 2) &&
+        VM_Version::supports_avx512vlbw() &&
+        VM_Version::supports_bmi2()) {
         movl(tmp2, len);
-      }
-      else {
+      } else {
         movl(len, tmp2);
       }
       andl(tmp2, 0x00000007);
--- a/hotspot/src/cpu/x86/vm/sharedRuntime_x86_32.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/x86/vm/sharedRuntime_x86_32.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -2236,6 +2236,11 @@
       __ verify_oop(rax);
   }
 
+  if (CheckJNICalls) {
+    // clear_pending_jni_exception_check
+    __ movptr(Address(thread, JavaThread::pending_jni_exception_check_fn_offset()), NULL_WORD);
+  }
+
   if (!is_critical_native) {
     // reset handle block
     __ movptr(rcx, Address(thread, JavaThread::active_handles_offset()));
--- a/hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -2589,6 +2589,11 @@
       __ verify_oop(rax);
   }
 
+  if (CheckJNICalls) {
+    // clear_pending_jni_exception_check
+    __ movptr(Address(r15_thread, JavaThread::pending_jni_exception_check_fn_offset()), NULL_WORD);
+  }
+
   if (!is_critical_native) {
     // reset handle block
     __ movptr(rcx, Address(r15_thread, JavaThread::active_handles_offset()));
--- a/hotspot/src/cpu/x86/vm/templateInterpreterGenerator_x86.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/cpu/x86/vm/templateInterpreterGenerator_x86.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1169,6 +1169,11 @@
   // reset_last_Java_frame
   __ reset_last_Java_frame(thread, true);
 
+  if (CheckJNICalls) {
+    // clear_pending_jni_exception_check
+    __ movptr(Address(thread, JavaThread::pending_jni_exception_check_fn_offset()), NULL_WORD);
+  }
+
   // reset handle block
   __ movptr(t, Address(thread, JavaThread::active_handles_offset()));
   __ movl(Address(t, JNIHandleBlock::top_offset_in_bytes()), (int32_t)NULL_WORD);
--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/GrowableArray.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/GrowableArray.java	Fri Sep 30 09:28:18 2016 -0700
@@ -65,4 +65,7 @@
     super(addr);
     virtualConstructor = v;
   }
+  public Address getData() {
+    return dataField.getValue(getAddress());
+  }
 }
--- a/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/CompilerToVM.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/CompilerToVM.java	Fri Sep 30 09:28:18 2016 -0700
@@ -366,8 +366,8 @@
      * {@code exactReceiver}.
      *
      * @param caller the caller or context type used to perform access checks
-     * @return the link-time resolved method (might be abstract) or {@code 0} if it can not be
-     *         linked
+     * @return the link-time resolved method (might be abstract) or {@code null} if it is either a
+     *         signature polymorphic method or can not be linked.
      */
     native HotSpotResolvedJavaMethodImpl resolveMethod(HotSpotResolvedObjectTypeImpl exactReceiver, HotSpotResolvedJavaMethodImpl method, HotSpotResolvedObjectTypeImpl caller);
 
--- a/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPool.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPool.java	Fri Sep 30 09:28:18 2016 -0700
@@ -722,7 +722,7 @@
     /**
      * Determines if {@code type} contains signature polymorphic methods.
      */
-    private static boolean isSignaturePolymorphicHolder(final HotSpotResolvedObjectTypeImpl type) {
+    static boolean isSignaturePolymorphicHolder(final ResolvedJavaType type) {
         String name = type.getName();
         if (signaturePolymorphicHolders == null) {
             signaturePolymorphicHolders = compilerToVM().getSignaturePolymorphicHolders();
--- a/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -24,6 +24,7 @@
 
 import static java.util.Objects.requireNonNull;
 import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM;
+import static jdk.vm.ci.hotspot.HotSpotConstantPool.isSignaturePolymorphicHolder;
 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config;
 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE;
@@ -426,7 +427,7 @@
             // Methods can only be resolved against concrete types
             return null;
         }
-        if (method.isConcrete() && method.getDeclaringClass().equals(this) && method.isPublic()) {
+        if (method.isConcrete() && method.getDeclaringClass().equals(this) && method.isPublic() && !isSignaturePolymorphicHolder(method.getDeclaringClass())) {
             return method;
         }
         if (!method.getDeclaringClass().isAssignableFrom(this)) {
--- a/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaType.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaType.java	Fri Sep 30 09:28:18 2016 -0700
@@ -209,8 +209,8 @@
      *
      * @param method the method to select the implementation of
      * @param callerType the caller or context type used to perform access checks
-     * @return the method that would be selected at runtime (might be abstract) or {@code null} if
-     *         it can not be resolved
+     * @return the link-time resolved method (might be abstract) or {@code null} if it is either a
+     *         signature polymorphic method or can not be linked.
      */
     ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType);
 
--- a/hotspot/src/os/aix/vm/os_aix.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os/aix/vm/os_aix.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -847,7 +847,8 @@
   return 0;
 }
 
-bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
+bool os::create_thread(Thread* thread, ThreadType thr_type,
+                       size_t req_stack_size) {
 
   assert(thread->osthread() == NULL, "caller responsible");
 
@@ -880,37 +881,12 @@
   guarantee(pthread_attr_setsuspendstate_np(&attr, PTHREAD_CREATE_SUSPENDED_NP) == 0, "???");
 
   // calculate stack size if it's not specified by caller
-  if (stack_size == 0) {
-    stack_size = os::Aix::default_stack_size(thr_type);
-
-    switch (thr_type) {
-    case os::java_thread:
-      // Java threads use ThreadStackSize whose default value can be changed with the flag -Xss.
-      assert(JavaThread::stack_size_at_create() > 0, "this should be set");
-      stack_size = JavaThread::stack_size_at_create();
-      break;
-    case os::compiler_thread:
-      if (CompilerThreadStackSize > 0) {
-        stack_size = (size_t)(CompilerThreadStackSize * K);
-        break;
-      } // else fall through:
-        // use VMThreadStackSize if CompilerThreadStackSize is not defined
-    case os::vm_thread:
-    case os::pgc_thread:
-    case os::cgc_thread:
-    case os::watcher_thread:
-      if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
-      break;
-    }
-  }
-
-  stack_size = MAX2(stack_size, os::Aix::min_stack_allowed);
+  size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
   pthread_attr_setstacksize(&attr, stack_size);
 
   pthread_t tid;
   int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
 
-
   char buf[64];
   if (ret == 0) {
     log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
@@ -3593,32 +3569,11 @@
   Aix::signal_sets_init();
   Aix::install_signal_handlers();
 
-  // Check minimum allowable stack size for thread creation and to initialize
-  // the java system classes, including StackOverflowError - depends on page
-  // size. Add two 4K pages for compiler2 recursion in main thread.
-  // Add in 4*BytesPerWord 4K pages to account for VM stack during
-  // class initialization depending on 32 or 64 bit VM.
-  os::Aix::min_stack_allowed = MAX2(os::Aix::min_stack_allowed,
-                                    JavaThread::stack_guard_zone_size() +
-                                    JavaThread::stack_shadow_zone_size() +
-                                    (4*BytesPerWord COMPILER2_PRESENT(+2)) * 4 * K);
-
-  os::Aix::min_stack_allowed = align_size_up(os::Aix::min_stack_allowed, os::vm_page_size());
-
-  size_t threadStackSizeInBytes = ThreadStackSize * K;
-  if (threadStackSizeInBytes != 0 &&
-      threadStackSizeInBytes < os::Aix::min_stack_allowed) {
-    tty->print_cr("\nThe stack size specified is too small, "
-                  "Specify at least %dk",
-                  os::Aix::min_stack_allowed / K);
+  // Check and sets minimum stack sizes against command line options
+  if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
     return JNI_ERR;
   }
 
-  // Make the stack size a multiple of the page size so that
-  // the yellow/red zones can be guarded.
-  // Note that this can be 0, if no default stacksize was set.
-  JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes, vm_page_size()));
-
   if (UseNUMA) {
     UseNUMA = false;
     warning("NUMA optimizations are not available on this OS.");
--- a/hotspot/src/os/aix/vm/os_aix.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os/aix/vm/os_aix.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2013, 2016 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -140,14 +140,6 @@
   // libpthread version string
   static void libpthread_init();
 
-  // Minimum stack size a thread can be created with (allowing
-  // the VM to completely create the thread and enter user code)
-  static size_t min_stack_allowed;
-
-  // Return default stack size or guard size for the specified thread type
-  static size_t default_stack_size(os::ThreadType thr_type);
-  static size_t default_guard_size(os::ThreadType thr_type);
-
   // Function returns true if we run on OS/400 (pase), false if we run
   // on AIX.
   static bool on_pase() {
--- a/hotspot/src/os/bsd/vm/os_bsd.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os/bsd/vm/os_bsd.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -734,7 +734,8 @@
   return 0;
 }
 
-bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
+bool os::create_thread(Thread* thread, ThreadType thr_type,
+                       size_t req_stack_size) {
   assert(thread->osthread() == NULL, "caller responsible");
 
   // Allocate the OSThread object
@@ -757,32 +758,7 @@
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 
   // calculate stack size if it's not specified by caller
-  if (stack_size == 0) {
-    stack_size = os::Bsd::default_stack_size(thr_type);
-
-    switch (thr_type) {
-    case os::java_thread:
-      // Java threads use ThreadStackSize which default value can be
-      // changed with the flag -Xss
-      assert(JavaThread::stack_size_at_create() > 0, "this should be set");
-      stack_size = JavaThread::stack_size_at_create();
-      break;
-    case os::compiler_thread:
-      if (CompilerThreadStackSize > 0) {
-        stack_size = (size_t)(CompilerThreadStackSize * K);
-        break;
-      } // else fall through:
-        // use VMThreadStackSize if CompilerThreadStackSize is not defined
-    case os::vm_thread:
-    case os::pgc_thread:
-    case os::cgc_thread:
-    case os::watcher_thread:
-      if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
-      break;
-    }
-  }
-
-  stack_size = MAX2(stack_size, os::Bsd::min_stack_allowed);
+  size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
   pthread_attr_setstacksize(&attr, stack_size);
 
   ThreadState state;
@@ -3502,32 +3478,11 @@
   Bsd::signal_sets_init();
   Bsd::install_signal_handlers();
 
-  // Check minimum allowable stack size for thread creation and to initialize
-  // the java system classes, including StackOverflowError - depends on page
-  // size.  Add two 4K pages for compiler2 recursion in main thread.
-  // Add in 4*BytesPerWord 4K pages to account for VM stack during
-  // class initialization depending on 32 or 64 bit VM.
-  os::Bsd::min_stack_allowed = MAX2(os::Bsd::min_stack_allowed,
-                                    JavaThread::stack_guard_zone_size() +
-                                    JavaThread::stack_shadow_zone_size() +
-                                    (4*BytesPerWord COMPILER2_PRESENT(+2)) * 4 * K);
-
-  os::Bsd::min_stack_allowed = align_size_up(os::Bsd::min_stack_allowed, os::vm_page_size());
-
-  size_t threadStackSizeInBytes = ThreadStackSize * K;
-  if (threadStackSizeInBytes != 0 &&
-      threadStackSizeInBytes < os::Bsd::min_stack_allowed) {
-    tty->print_cr("\nThe stack size specified is too small, "
-                  "Specify at least %dk",
-                  os::Bsd::min_stack_allowed/ K);
+  // Check and sets minimum stack sizes against command line options
+  if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
     return JNI_ERR;
   }
 
-  // Make the stack size a multiple of the page size so that
-  // the yellow/red zones can be guarded.
-  JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
-                                                vm_page_size()));
-
   if (MaxFDLimit) {
     // set the number of file descriptors to max. print out error
     // if getrlimit/setrlimit fails but continue regardless.
--- a/hotspot/src/os/bsd/vm/os_bsd.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os/bsd/vm/os_bsd.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -120,14 +120,6 @@
   static struct sigaction *get_chained_signal_action(int sig);
   static bool chained_handler(int sig, siginfo_t* siginfo, void* context);
 
-  // Minimum stack size a thread can be created with (allowing
-  // the VM to completely create the thread and enter user code)
-  static size_t min_stack_allowed;
-
-  // Return default stack size or guard size for the specified thread type
-  static size_t default_stack_size(os::ThreadType thr_type);
-  static size_t default_guard_size(os::ThreadType thr_type);
-
   // Real-time clock functions
   static void clock_init(void);
 
--- a/hotspot/src/os/linux/vm/os_linux.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os/linux/vm/os_linux.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -701,7 +701,7 @@
 }
 
 bool os::create_thread(Thread* thread, ThreadType thr_type,
-                       size_t stack_size) {
+                       size_t req_stack_size) {
   assert(thread->osthread() == NULL, "caller responsible");
 
   // Allocate the OSThread object
@@ -723,34 +723,8 @@
   pthread_attr_init(&attr);
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 
-  // stack size
   // calculate stack size if it's not specified by caller
-  if (stack_size == 0) {
-    stack_size = os::Linux::default_stack_size(thr_type);
-
-    switch (thr_type) {
-    case os::java_thread:
-      // Java threads use ThreadStackSize which default value can be
-      // changed with the flag -Xss
-      assert(JavaThread::stack_size_at_create() > 0, "this should be set");
-      stack_size = JavaThread::stack_size_at_create();
-      break;
-    case os::compiler_thread:
-      if (CompilerThreadStackSize > 0) {
-        stack_size = (size_t)(CompilerThreadStackSize * K);
-        break;
-      } // else fall through:
-        // use VMThreadStackSize if CompilerThreadStackSize is not defined
-    case os::vm_thread:
-    case os::pgc_thread:
-    case os::cgc_thread:
-    case os::watcher_thread:
-      if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
-      break;
-    }
-  }
-
-  stack_size = MAX2(stack_size, os::Linux::min_stack_allowed);
+  size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
   pthread_attr_setstacksize(&attr, stack_size);
 
   // glibc guard page
@@ -956,10 +930,9 @@
 // bogus value for initial thread.
 void os::Linux::capture_initial_stack(size_t max_size) {
   // stack size is the easy part, get it from RLIMIT_STACK
-  size_t stack_size;
   struct rlimit rlim;
   getrlimit(RLIMIT_STACK, &rlim);
-  stack_size = rlim.rlim_cur;
+  size_t stack_size = rlim.rlim_cur;
 
   // 6308388: a bug in ld.so will relocate its own .data section to the
   //   lower end of primordial stack; reduce ulimit -s value a little bit
@@ -4793,32 +4766,10 @@
   Linux::signal_sets_init();
   Linux::install_signal_handlers();
 
-  // Check minimum allowable stack size for thread creation and to initialize
-  // the java system classes, including StackOverflowError - depends on page
-  // size.  Add two 4K pages for compiler2 recursion in main thread.
-  // Add in 4*BytesPerWord 4K pages to account for VM stack during
-  // class initialization depending on 32 or 64 bit VM.
-  os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
-                                      JavaThread::stack_guard_zone_size() +
-                                      JavaThread::stack_shadow_zone_size() +
-                                      (4*BytesPerWord COMPILER2_PRESENT(+2)) * 4 * K);
-
-  os::Linux::min_stack_allowed = align_size_up(os::Linux::min_stack_allowed, os::vm_page_size());
-
-  size_t threadStackSizeInBytes = ThreadStackSize * K;
-  if (threadStackSizeInBytes != 0 &&
-      threadStackSizeInBytes < os::Linux::min_stack_allowed) {
-    tty->print_cr("\nThe stack size specified is too small, "
-                  "Specify at least " SIZE_FORMAT "k",
-                  os::Linux::min_stack_allowed/ K);
+  // Check and sets minimum stack sizes against command line options
+  if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
     return JNI_ERR;
   }
-
-  // Make the stack size a multiple of the page size so that
-  // the yellow/red zones can be guarded.
-  JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
-                                                vm_page_size()));
-
   Linux::capture_initial_stack(JavaThread::stack_size_at_create());
 
 #if defined(IA32)
--- a/hotspot/src/os/linux/vm/os_linux.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os/linux/vm/os_linux.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -170,12 +170,8 @@
   static void libpthread_init();
   static bool libnuma_init();
   static void* libnuma_dlsym(void* handle, const char* name);
-  // Minimum stack size a thread can be created with (allowing
-  // the VM to completely create the thread and enter user code)
-  static size_t min_stack_allowed;
 
-  // Return default stack size or guard size for the specified thread type
-  static size_t default_stack_size(os::ThreadType thr_type);
+  // Return default guard size for the specified thread type
   static size_t default_guard_size(os::ThreadType thr_type);
 
   static void capture_initial_stack(size_t max_size);
--- a/hotspot/src/os/posix/vm/os_posix.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os/posix/vm/os_posix.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1099,6 +1099,123 @@
   return buf;
 }
 
+// Check minimum allowable stack sizes for thread creation and to initialize
+// the java system classes, including StackOverflowError - depends on page
+// size.  Add two 4K pages for compiler2 recursion in main thread.
+// Add in 4*BytesPerWord 4K pages to account for VM stack during
+// class initialization depending on 32 or 64 bit VM.
+jint os::Posix::set_minimum_stack_sizes() {
+  _java_thread_min_stack_allowed = MAX2(_java_thread_min_stack_allowed,
+                                        JavaThread::stack_guard_zone_size() +
+                                        JavaThread::stack_shadow_zone_size() +
+                                        (4 * BytesPerWord COMPILER2_PRESENT(+ 2)) * 4 * K);
+
+  _java_thread_min_stack_allowed = align_size_up(_java_thread_min_stack_allowed, vm_page_size());
+
+  size_t stack_size_in_bytes = ThreadStackSize * K;
+  if (stack_size_in_bytes != 0 &&
+      stack_size_in_bytes < _java_thread_min_stack_allowed) {
+    // The '-Xss' and '-XX:ThreadStackSize=N' options both set
+    // ThreadStackSize so we go with "Java thread stack size" instead
+    // of "ThreadStackSize" to be more friendly.
+    tty->print_cr("\nThe Java thread stack size specified is too small. "
+                  "Specify at least " SIZE_FORMAT "k",
+                  _java_thread_min_stack_allowed / K);
+    return JNI_ERR;
+  }
+
+#ifdef SOLARIS
+  // For 64kbps there will be a 64kb page size, which makes
+  // the usable default stack size quite a bit less.  Increase the
+  // stack for 64kb (or any > than 8kb) pages, this increases
+  // virtual memory fragmentation (since we're not creating the
+  // stack on a power of 2 boundary.  The real fix for this
+  // should be to fix the guard page mechanism.
+
+  if (vm_page_size() > 8*K) {
+    stack_size_in_bytes = (stack_size_in_bytes != 0)
+       ? stack_size_in_bytes +
+         JavaThread::stack_red_zone_size() +
+         JavaThread::stack_yellow_zone_size()
+       : 0;
+    ThreadStackSize = stack_size_in_bytes/K;
+  }
+#endif // SOLARIS
+
+  // Make the stack size a multiple of the page size so that
+  // the yellow/red zones can be guarded.
+  JavaThread::set_stack_size_at_create(round_to(stack_size_in_bytes,
+                                                vm_page_size()));
+
+  _compiler_thread_min_stack_allowed = align_size_up(_compiler_thread_min_stack_allowed, vm_page_size());
+
+  stack_size_in_bytes = CompilerThreadStackSize * K;
+  if (stack_size_in_bytes != 0 &&
+      stack_size_in_bytes < _compiler_thread_min_stack_allowed) {
+    tty->print_cr("\nThe CompilerThreadStackSize specified is too small. "
+                  "Specify at least " SIZE_FORMAT "k",
+                  _compiler_thread_min_stack_allowed / K);
+    return JNI_ERR;
+  }
+
+  _vm_internal_thread_min_stack_allowed = align_size_up(_vm_internal_thread_min_stack_allowed, vm_page_size());
+
+  stack_size_in_bytes = VMThreadStackSize * K;
+  if (stack_size_in_bytes != 0 &&
+      stack_size_in_bytes < _vm_internal_thread_min_stack_allowed) {
+    tty->print_cr("\nThe VMThreadStackSize specified is too small. "
+                  "Specify at least " SIZE_FORMAT "k",
+                  _vm_internal_thread_min_stack_allowed / K);
+    return JNI_ERR;
+  }
+  return JNI_OK;
+}
+
+// Called when creating the thread.  The minimum stack sizes have already been calculated
+size_t os::Posix::get_initial_stack_size(ThreadType thr_type, size_t req_stack_size) {
+  size_t stack_size;
+  if (req_stack_size == 0) {
+    stack_size = default_stack_size(thr_type);
+  } else {
+    stack_size = req_stack_size;
+  }
+
+  switch (thr_type) {
+  case os::java_thread:
+    // Java threads use ThreadStackSize which default value can be
+    // changed with the flag -Xss
+    if (req_stack_size == 0 && JavaThread::stack_size_at_create() > 0) {
+      // no requested size and we have a more specific default value
+      stack_size = JavaThread::stack_size_at_create();
+    }
+    stack_size = MAX2(stack_size,
+                      _java_thread_min_stack_allowed);
+    break;
+  case os::compiler_thread:
+    if (req_stack_size == 0 && CompilerThreadStackSize > 0) {
+      // no requested size and we have a more specific default value
+      stack_size = (size_t)(CompilerThreadStackSize * K);
+    }
+    stack_size = MAX2(stack_size,
+                      _compiler_thread_min_stack_allowed);
+    break;
+  case os::vm_thread:
+  case os::pgc_thread:
+  case os::cgc_thread:
+  case os::watcher_thread:
+  default:  // presume the unknown thr_type is a VM internal
+    if (req_stack_size == 0 && VMThreadStackSize > 0) {
+      // no requested size and we have a more specific default value
+      stack_size = (size_t)(VMThreadStackSize * K);
+    }
+
+    stack_size = MAX2(stack_size,
+                      _vm_internal_thread_min_stack_allowed);
+    break;
+  }
+
+  return stack_size;
+}
 
 os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() {
   assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread");
--- a/hotspot/src/os/posix/vm/os_posix.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os/posix/vm/os_posix.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,18 @@
   static void print_libversion_info(outputStream* st);
   static void print_load_average(outputStream* st);
 
+  // Minimum stack size a thread can be created with (allowing
+  // the VM to completely create the thread and enter user code)
+  static size_t _compiler_thread_min_stack_allowed;
+  static size_t _java_thread_min_stack_allowed;
+  static size_t _vm_internal_thread_min_stack_allowed;
+
 public:
+  // Return default stack size for the specified thread type
+  static size_t default_stack_size(os::ThreadType thr_type);
+  // Check and sets minimum stack sizes
+  static jint set_minimum_stack_sizes();
+  static size_t get_initial_stack_size(ThreadType thr_type, size_t req_stack_size);
 
   // Returns true if signal is valid.
   static bool is_valid_signal(int sig);
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -917,8 +917,15 @@
   return buf;
 }
 
+// return default stack size for thr_type
+size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
+  // default stack size when not specified by caller is 1M (2M for LP64)
+  size_t s = (BytesPerWord >> 2) * K * K;
+  return s;
+}
+
 bool os::create_thread(Thread* thread, ThreadType thr_type,
-                       size_t stack_size) {
+                       size_t req_stack_size) {
   // Allocate the OSThread object
   OSThread* osthread = new OSThread(NULL, NULL);
   if (osthread == NULL) {
@@ -953,31 +960,8 @@
     tty->print_cr("In create_thread, creating a %s thread\n", thrtyp);
   }
 
-  // Calculate stack size if it's not specified by caller.
-  if (stack_size == 0) {
-    // The default stack size 1M (2M for LP64).
-    stack_size = (BytesPerWord >> 2) * K * K;
-
-    switch (thr_type) {
-    case os::java_thread:
-      // Java threads use ThreadStackSize which default value can be changed with the flag -Xss
-      if (JavaThread::stack_size_at_create() > 0) stack_size = JavaThread::stack_size_at_create();
-      break;
-    case os::compiler_thread:
-      if (CompilerThreadStackSize > 0) {
-        stack_size = (size_t)(CompilerThreadStackSize * K);
-        break;
-      } // else fall through:
-        // use VMThreadStackSize if CompilerThreadStackSize is not defined
-    case os::vm_thread:
-    case os::pgc_thread:
-    case os::cgc_thread:
-    case os::watcher_thread:
-      if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
-      break;
-    }
-  }
-  stack_size = MAX2(stack_size, os::Solaris::min_stack_allowed);
+  // calculate stack size if it's not specified by caller
+  size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
 
   // Initial state is ALLOCATED but not INITIALIZED
   osthread->set_state(ALLOCATED);
@@ -4400,7 +4384,12 @@
   // Constant minimum stack size allowed. It must be at least
   // the minimum of what the OS supports (thr_min_stack()), and
   // enough to allow the thread to get to user bytecode execution.
-  Solaris::min_stack_allowed = MAX2(thr_min_stack(), Solaris::min_stack_allowed);
+  Posix::_compiler_thread_min_stack_allowed = MAX2(thr_min_stack(),
+                                                   Posix::_compiler_thread_min_stack_allowed);
+  Posix::_java_thread_min_stack_allowed = MAX2(thr_min_stack(),
+                                               Posix::_java_thread_min_stack_allowed);
+  Posix::_vm_internal_thread_min_stack_allowed = MAX2(thr_min_stack(),
+                                                      Posix::_vm_internal_thread_min_stack_allowed);
 
   // dynamic lookup of functions that may not be available in our lowest
   // supported Solaris release
@@ -4445,47 +4434,11 @@
     log_info(os)("Memory Serialize Page address: " INTPTR_FORMAT, p2i(mem_serialize_page));
   }
 
-  // Check minimum allowable stack size for thread creation and to initialize
-  // the java system classes, including StackOverflowError - depends on page
-  // size.  Add two 4K pages for compiler2 recursion in main thread.
-  // Add in 4*BytesPerWord 4K pages to account for VM stack during
-  // class initialization depending on 32 or 64 bit VM.
-  os::Solaris::min_stack_allowed = MAX2(os::Solaris::min_stack_allowed,
-                                        JavaThread::stack_guard_zone_size() +
-                                        JavaThread::stack_shadow_zone_size() +
-                                        (4*BytesPerWord COMPILER2_PRESENT(+2)) * 4 * K);
-
-  os::Solaris::min_stack_allowed = align_size_up(os::Solaris::min_stack_allowed, os::vm_page_size());
-
-  size_t threadStackSizeInBytes = ThreadStackSize * K;
-  if (threadStackSizeInBytes != 0 &&
-      threadStackSizeInBytes < os::Solaris::min_stack_allowed) {
-    tty->print_cr("\nThe stack size specified is too small, Specify at least %dk",
-                  os::Solaris::min_stack_allowed/K);
+  // Check and sets minimum stack sizes against command line options
+  if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
     return JNI_ERR;
   }
 
-  // For 64kbps there will be a 64kb page size, which makes
-  // the usable default stack size quite a bit less.  Increase the
-  // stack for 64kb (or any > than 8kb) pages, this increases
-  // virtual memory fragmentation (since we're not creating the
-  // stack on a power of 2 boundary.  The real fix for this
-  // should be to fix the guard page mechanism.
-
-  if (vm_page_size() > 8*K) {
-    threadStackSizeInBytes = (threadStackSizeInBytes != 0)
-       ? threadStackSizeInBytes +
-         JavaThread::stack_red_zone_size() +
-         JavaThread::stack_yellow_zone_size()
-       : 0;
-    ThreadStackSize = threadStackSizeInBytes/K;
-  }
-
-  // Make the stack size a multiple of the page size so that
-  // the yellow/red zones can be guarded.
-  JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
-                                                vm_page_size()));
-
   Solaris::libthread_init();
 
   if (UseNUMA) {
--- a/hotspot/src/os/solaris/vm/os_solaris.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os/solaris/vm/os_solaris.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -292,10 +292,6 @@
   static          jint  _os_thread_limit;
   static volatile jint  _os_thread_count;
 
-  // Minimum stack size a thread can be created with (allowing
-  // the VM to completely create the thread and enter user code)
-
-  static size_t min_stack_allowed;
 
   // Stack overflow handling
 
--- a/hotspot/src/os/windows/vm/os_windows.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os/windows/vm/os_windows.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -4215,7 +4215,7 @@
   min_stack_allowed = align_size_up(min_stack_allowed, os::vm_page_size());
 
   if (actual_reserve_size < min_stack_allowed) {
-    tty->print_cr("\nThe stack size specified is too small, "
+    tty->print_cr("\nThe Java thread stack size specified is too small. "
                   "Specify at least %dk",
                   min_stack_allowed / K);
     return JNI_ERR;
--- a/hotspot/src/os_cpu/aix_ppc/vm/globals_aix_ppc.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/aix_ppc/vm/globals_aix_ppc.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -33,10 +33,6 @@
 define_pd_global(intx, ThreadStackSize,          2048); // 0 => use system default
 define_pd_global(intx, VMThreadStackSize,        2048);
 
-// if we set CompilerThreadStackSize to a value different than 0, it will
-// be used in os::create_thread(). Otherwise, due the strange logic in os::create_thread(),
-// the stack size for compiler threads will default to VMThreadStackSize, although it
-// is defined to 4M in os::Aix::default_stack_size()!
 define_pd_global(intx, CompilerThreadStackSize,  4096);
 
 // Allow extra space in DEBUG builds for asserts.
--- a/hotspot/src/os_cpu/aix_ppc/vm/os_aix_ppc.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/aix_ppc/vm/os_aix_ppc.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -192,8 +192,10 @@
   intptr_t* csp = (intptr_t*) *((intptr_t*) os::current_stack_pointer());
   // hack.
   frame topframe(csp, (address)0x8);
-  // return sender of current topframe which hopefully has pc != NULL.
-  return os::get_sender_for_C_frame(&topframe);
+  // Return sender of sender of current topframe which hopefully
+  // both have pc != NULL.
+  frame tmp = os::get_sender_for_C_frame(&topframe);
+  return os::get_sender_for_C_frame(&tmp);
 }
 
 // Utility functions
@@ -533,23 +535,17 @@
 ////////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-size_t os::Aix::min_stack_allowed = 128*K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = 128 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 128 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K;
 
 // return default stack size for thr_type
-size_t os::Aix::default_stack_size(os::ThreadType thr_type) {
+size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
   // default stack size (compiler thread needs larger stack)
-  // Notice that the setting for compiler threads here have no impact
-  // because of the strange 'fallback logic' in os::create_thread().
-  // Better set CompilerThreadStackSize in globals_<os_cpu>.hpp if you want to
-  // specify a different stack size for compiler threads!
   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
   return s;
 }
 
-size_t os::Aix::default_guard_size(os::ThreadType thr_type) {
-  return 2 * page_size();
-}
-
 /////////////////////////////////////////////////////////////////////////////
 // helper functions for fatal error handler
 
--- a/hotspot/src/os_cpu/bsd_x86/vm/globals_bsd_x86.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/bsd_x86/vm/globals_bsd_x86.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,9 +31,11 @@
 //
 define_pd_global(bool, DontYieldALot,            false);
 #ifdef AMD64
+define_pd_global(intx, CompilerThreadStackSize,  1024);
 define_pd_global(intx, ThreadStackSize,          1024); // 0 => use system default
 define_pd_global(intx, VMThreadStackSize,        1024);
 #else
+define_pd_global(intx, CompilerThreadStackSize,  512);
 // ThreadStackSize 320 allows a couple of test cases to run while
 // keeping the number of threads that can be created high.  System
 // default ThreadStackSize appears to be 512 which is too big.
@@ -41,7 +43,6 @@
 define_pd_global(intx, VMThreadStackSize,        512);
 #endif // AMD64
 
-define_pd_global(intx, CompilerThreadStackSize,  0);
 
 define_pd_global(size_t, JVMInvokeMethodSlack,   8192);
 
--- a/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -838,9 +838,13 @@
 // thread stack
 
 #ifdef AMD64
-size_t os::Bsd::min_stack_allowed  = 64 * K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 #else
-size_t os::Bsd::min_stack_allowed  =  (48 DEBUG_ONLY(+4))*K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
+size_t os::Posix::_java_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
 
 #ifdef __GNUC__
 #define GET_GS() ({int gs; __asm__ volatile("movw %%gs, %w0":"=q"(gs)); gs&0xffff;})
@@ -849,7 +853,7 @@
 #endif // AMD64
 
 // return default stack size for thr_type
-size_t os::Bsd::default_stack_size(os::ThreadType thr_type) {
+size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
   // default stack size (compiler thread needs larger stack)
 #ifdef AMD64
   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
@@ -859,11 +863,6 @@
   return s;
 }
 
-size_t os::Bsd::default_guard_size(os::ThreadType thr_type) {
-  // Creating guard page is very expensive. Java thread has HotSpot
-  // guard page, only enable glibc guard page for non-Java threads.
-  return (thr_type == java_thread ? 0 : page_size());
-}
 
 // Java thread:
 //
--- a/hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -282,9 +282,11 @@
 ///////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-size_t os::Bsd::min_stack_allowed = 64 * K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 
-size_t os::Bsd::default_stack_size(os::ThreadType thr_type) {
+size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
 #ifdef _LP64
   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
 #else
@@ -293,12 +295,6 @@
   return s;
 }
 
-size_t os::Bsd::default_guard_size(os::ThreadType thr_type) {
-  // Only enable glibc guard pages for non-Java threads
-  // (Java threads have HotSpot guard pages)
-  return (thr_type == java_thread ? 0 : page_size());
-}
-
 static void current_stack_region(address *bottom, size_t *size) {
   address stack_bottom;
   address stack_top;
--- a/hotspot/src/os_cpu/linux_aarch64/vm/globals_linux_aarch64.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/linux_aarch64/vm/globals_linux_aarch64.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -33,7 +33,7 @@
 define_pd_global(intx, ThreadStackSize,          2048); // 0 => use system default
 define_pd_global(intx, VMThreadStackSize,        2048);
 
-define_pd_global(intx, CompilerThreadStackSize,  0);
+define_pd_global(intx, CompilerThreadStackSize,  2048);
 
 define_pd_global(uintx,JVMInvokeMethodSlack,     8192);
 
--- a/hotspot/src/os_cpu/linux_aarch64/vm/os_linux_aarch64.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/linux_aarch64/vm/os_linux_aarch64.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -473,10 +473,12 @@
 ////////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-size_t os::Linux::min_stack_allowed  = 64 * K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 
 // return default stack size for thr_type
-size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
+size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
   // default stack size (compiler thread needs larger stack)
   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
   return s;
--- a/hotspot/src/os_cpu/linux_ppc/vm/globals_linux_ppc.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/linux_ppc/vm/globals_linux_ppc.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -33,10 +33,6 @@
 define_pd_global(intx, ThreadStackSize,          2048); // 0 => use system default
 define_pd_global(intx, VMThreadStackSize,        2048);
 
-// if we set CompilerThreadStackSize to a value different than 0, it will
-// be used in os::create_thread(). Otherwise, due the strange logic in os::create_thread(),
-// the stack size for compiler threads will default to VMThreadStackSize, although it
-// is defined to 4M in os::Linux::default_stack_size()!
 define_pd_global(intx, CompilerThreadStackSize,  4096);
 
 // Allow extra space in DEBUG builds for asserts.
--- a/hotspot/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -205,8 +205,10 @@
   intptr_t* csp = (intptr_t*) *((intptr_t*) os::current_stack_pointer());
   // hack.
   frame topframe(csp, (address)0x8);
-  // return sender of current topframe which hopefully has pc != NULL.
-  return os::get_sender_for_C_frame(&topframe);
+  // Return sender of sender of current topframe which hopefully
+  // both have pc != NULL.
+  frame tmp = os::get_sender_for_C_frame(&topframe);
+  return os::get_sender_for_C_frame(&tmp);
 }
 
 // Utility functions
@@ -533,15 +535,13 @@
 ////////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-size_t os::Linux::min_stack_allowed = 128*K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = 128 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 128 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K;
 
 // return default stack size for thr_type
-size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
+size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
   // default stack size (compiler thread needs larger stack)
-  // Notice that the setting for compiler threads here have no impact
-  // because of the strange 'fallback logic' in os::create_thread().
-  // Better set CompilerThreadStackSize in globals_<os_cpu>.hpp if you want to
-  // specify a different stack size for compiler threads!
   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1024 * K);
   return s;
 }
--- a/hotspot/src/os_cpu/linux_sparc/vm/globals_linux_sparc.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/linux_sparc/vm/globals_linux_sparc.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,6 @@
 //
 
 define_pd_global(size_t, JVMInvokeMethodSlack,   12288);
-define_pd_global(intx, CompilerThreadStackSize,  0);
 
 // Used on 64 bit platforms for UseCompressedOops base address
 define_pd_global(size_t, HeapBaseMinAddress,     CONST64(4)*G);
--- a/hotspot/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -726,10 +726,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-size_t os::Linux::min_stack_allowed  = 128 * K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = 128 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 128 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K;
 
 // return default stack size for thr_type
-size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
+size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
   // default stack size (compiler thread needs larger stack)
   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
   return s;
--- a/hotspot/src/os_cpu/linux_x86/vm/globals_linux_x86.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/linux_x86/vm/globals_linux_x86.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,9 +30,11 @@
 
 define_pd_global(bool, DontYieldALot,            false);
 #ifdef AMD64
+define_pd_global(intx, CompilerThreadStackSize,  1024);
 define_pd_global(intx, ThreadStackSize,          1024); // 0 => use system default
 define_pd_global(intx, VMThreadStackSize,        1024);
 #else
+define_pd_global(intx, CompilerThreadStackSize,  512);
 // ThreadStackSize 320 allows a couple of test cases to run while
 // keeping the number of threads that can be created high.  System
 // default ThreadStackSize appears to be 512 which is too big.
@@ -40,8 +42,6 @@
 define_pd_global(intx, VMThreadStackSize,        512);
 #endif // AMD64
 
-define_pd_global(intx, CompilerThreadStackSize,  0);
-
 define_pd_global(size_t, JVMInvokeMethodSlack,   8192);
 
 // Used on 64 bit platforms for UseCompressedOops base address
--- a/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -676,13 +676,17 @@
 // thread stack
 
 #ifdef AMD64
-size_t os::Linux::min_stack_allowed  = 64 * K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 #else
-size_t os::Linux::min_stack_allowed  =  (48 DEBUG_ONLY(+4))*K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
+size_t os::Posix::_java_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
 #endif // AMD64
 
 // return default stack size for thr_type
-size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
+size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
   // default stack size (compiler thread needs larger stack)
 #ifdef AMD64
   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
--- a/hotspot/src/os_cpu/linux_zero/vm/os_linux_zero.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/linux_zero/vm/os_linux_zero.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -307,9 +307,11 @@
 ///////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-size_t os::Linux::min_stack_allowed = 64 * K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 
-size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
+size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
 #ifdef _LP64
   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
 #else
--- a/hotspot/src/os_cpu/solaris_sparc/vm/globals_solaris_sparc.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/solaris_sparc/vm/globals_solaris_sparc.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,6 @@
 //
 
 define_pd_global(size_t, JVMInvokeMethodSlack,   12288);
-define_pd_global(intx, CompilerThreadStackSize,  0);
 
 // Used on 64 bit platforms for UseCompressedOops base address
 #ifdef _LP64
--- a/hotspot/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -84,9 +84,13 @@
 // Minimum stack size for the VM.  It's easier to document a constant
 // but it's different for x86 and sparc because the page sizes are different.
 #ifdef _LP64
-size_t os::Solaris::min_stack_allowed = 128*K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = 128 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 128 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K;
 #else
-size_t os::Solaris::min_stack_allowed = 96*K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = 96 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 96 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 96 * K;
 #endif
 
 int os::Solaris::max_register_window_saves_before_flushing() {
--- a/hotspot/src/os_cpu/solaris_x86/vm/globals_solaris_x86.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/solaris_x86/vm/globals_solaris_x86.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,10 +30,12 @@
 
 define_pd_global(bool, DontYieldALot,            true); // Determined in the design center
 #ifdef AMD64
+define_pd_global(intx, CompilerThreadStackSize,  1024);
 define_pd_global(intx, ThreadStackSize,          1024); // 0 => use system default
 define_pd_global(intx, VMThreadStackSize,        1024);
 define_pd_global(size_t, JVMInvokeMethodSlack,   8*K);
 #else
+define_pd_global(intx, CompilerThreadStackSize,  512);
 // ThreadStackSize 320 allows a couple of test cases to run while
 // keeping the number of threads that can be created high.
 define_pd_global(intx, ThreadStackSize,          320);
@@ -41,7 +43,6 @@
 define_pd_global(size_t, JVMInvokeMethodSlack,   10*K);
 #endif // AMD64
 
-define_pd_global(intx, CompilerThreadStackSize,  0);
 
 // Used on 64 bit platforms for UseCompressedOops base address
 define_pd_global(size_t, HeapBaseMinAddress,     2*G);
--- a/hotspot/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -86,15 +86,19 @@
 
 #define MAX_PATH (2 * K)
 
-// Minimum stack size for the VM.  It's easier to document a constant value
+// Minimum stack sizes for the VM.  It's easier to document a constant value
 // but it's different for x86 and sparc because the page sizes are different.
 #ifdef AMD64
-size_t os::Solaris::min_stack_allowed = 224*K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = 394 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 224 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 224 * K;
 #define REG_SP REG_RSP
 #define REG_PC REG_RIP
 #define REG_FP REG_RBP
 #else
-size_t os::Solaris::min_stack_allowed = 64*K;
+size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 #define REG_SP UESP
 #define REG_PC EIP
 #define REG_FP EBP
--- a/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -2410,6 +2410,15 @@
 #endif // INCLUDE_ALL_GCS
 
   if (x->is_volatile() && os::is_MP()) __ membar_acquire();
+
+  /* Normalize boolean value returned by unsafe operation, i.e., value  != 0 ? value = true : value false. */
+  if (type == T_BOOLEAN) {
+    LabelObj* equalZeroLabel = new LabelObj();
+    __ cmp(lir_cond_equal, value, 0);
+    __ branch(lir_cond_equal, T_BOOLEAN, equalZeroLabel->label());
+    __ move(LIR_OprFact::intConst(1), value);
+    __ branch_destination(equalZeroLabel->label());
+  }
 }
 
 
--- a/hotspot/src/share/vm/c1/c1_Runtime1.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/c1/c1_Runtime1.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -576,9 +576,8 @@
     // normal bytecode execution.
     thread->clear_exception_oop_and_pc();
 
-    Handle original_exception(thread, exception());
-
-    continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false);
+    bool recursive_exception = false;
+    continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false, recursive_exception);
     // If an exception was thrown during exception dispatch, the exception oop may have changed
     thread->set_exception_oop(exception());
     thread->set_exception_pc(pc);
@@ -586,8 +585,9 @@
     // the exception cache is used only by non-implicit exceptions
     // Update the exception cache only when there didn't happen
     // another exception during the computation of the compiled
-    // exception handler.
-    if (continuation != NULL && original_exception() == exception()) {
+    // exception handler. Checking for exception oop equality is not
+    // sufficient because some exceptions are pre-allocated and reused.
+    if (continuation != NULL && !recursive_exception) {
       nm->add_handler_for_exception_and_pc(exception, pc, continuation);
     }
   }
--- a/hotspot/src/share/vm/classfile/verificationType.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/classfile/verificationType.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -95,7 +95,8 @@
       Category2_2nd      = (Category2_2ndFlag << 1 * BitsPerByte) | Primitive,
 
       // Primitive values (type descriminator stored in most-signifcant bytes)
-      Bogus              = (ITEM_Bogus      << 2 * BitsPerByte) | Category1,
+      // Bogus needs the " | Primitive".  Else, is_reference(Bogus) returns TRUE.
+      Bogus              = (ITEM_Bogus      << 2 * BitsPerByte) | Primitive,
       Boolean            = (ITEM_Boolean    << 2 * BitsPerByte) | Category1,
       Byte               = (ITEM_Byte       << 2 * BitsPerByte) | Category1,
       Short              = (ITEM_Short      << 2 * BitsPerByte) | Category1,
--- a/hotspot/src/share/vm/code/codeCache.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/code/codeCache.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1305,7 +1305,7 @@
     event.set_entryCount(heap->blob_count());
     event.set_methodCount(heap->nmethod_count());
     event.set_adaptorCount(heap->adapter_count());
-    event.set_unallocatedCapacity(heap->unallocated_capacity()/K);
+    event.set_unallocatedCapacity(heap->unallocated_capacity());
     event.set_fullCount(heap->full_count());
     event.commit();
   }
--- a/hotspot/src/share/vm/gc/g1/g1CollectionSet.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/gc/g1/g1CollectionSet.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -32,6 +32,7 @@
 #include "gc/g1/heapRegionSet.hpp"
 #include "logging/logStream.hpp"
 #include "utilities/debug.hpp"
+#include "utilities/quickSort.hpp"
 
 G1CollectorState* G1CollectionSet::collector_state() {
   return _g1->collector_state();
@@ -396,6 +397,16 @@
   return time_remaining_ms;
 }
 
+static int compare_region_idx(const uint a, const uint b) {
+  if (a > b) {
+    return 1;
+  } else if (a == b) {
+    return 0;
+  } else {
+    return -1;
+  }
+}
+
 void G1CollectionSet::finalize_old_part(double time_remaining_ms) {
   double non_young_start_time_sec = os::elapsedTime();
   double predicted_old_time_ms = 0.0;
@@ -493,6 +504,8 @@
 
   double non_young_end_time_sec = os::elapsedTime();
   phase_times()->record_non_young_cset_choice_time_ms((non_young_end_time_sec - non_young_start_time_sec) * 1000.0);
+
+  QuickSort::sort<uint>(_collection_set_regions, (int)_collection_set_cur_length, compare_region_idx, true);
 }
 
 #ifdef ASSERT
--- a/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1904,7 +1904,8 @@
     assert(_g1h->is_in_g1_reserved(finger), "invariant");
 
     HeapRegion* curr_region = _g1h->heap_region_containing(finger);
-
+    // Make sure that the reads below do not float before loading curr_region.
+    OrderAccess::loadload();
     // Above heap_region_containing may return NULL as we always scan claim
     // until the end of the heap. In this case, just jump to the next region.
     HeapWord* end = curr_region != NULL ? curr_region->end() : finger + HeapRegion::GrainWords;
--- a/hotspot/src/share/vm/gc/g1/g1MarkSweep.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/gc/g1/g1MarkSweep.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -132,9 +132,16 @@
   MarkingCodeBlobClosure follow_code_closure(&GenMarkSweep::follow_root_closure, !CodeBlobToOopClosure::FixRelocations);
   {
     G1RootProcessor root_processor(g1h, 1);
-    root_processor.process_strong_roots(&GenMarkSweep::follow_root_closure,
-                                        &GenMarkSweep::follow_cld_closure,
-                                        &follow_code_closure);
+    if (ClassUnloading) {
+      root_processor.process_strong_roots(&GenMarkSweep::follow_root_closure,
+                                          &GenMarkSweep::follow_cld_closure,
+                                          &follow_code_closure);
+    } else {
+      root_processor.process_all_roots_no_string_table(
+                                          &GenMarkSweep::follow_root_closure,
+                                          &GenMarkSweep::follow_cld_closure,
+                                          &follow_code_closure);
+    }
   }
 
   {
@@ -157,7 +164,7 @@
   // This is the point where the entire marking should have completed.
   assert(GenMarkSweep::_marking_stack.is_empty(), "Marking should have completed");
 
-  {
+  if (ClassUnloading) {
     GCTraceTime(Debug, gc, phases) trace("Class Unloading", gc_timer());
 
     // Unload classes and purge the SystemDictionary.
--- a/hotspot/src/share/vm/gc/g1/g1RootProcessor.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/gc/g1/g1RootProcessor.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -83,6 +83,7 @@
   }
 
   process_vm_roots(closures, phase_times, worker_i);
+  process_string_table_roots(closures, phase_times, worker_i);
 
   {
     // Now the CM ref_processor roots.
@@ -191,19 +192,34 @@
 
 void G1RootProcessor::process_all_roots(OopClosure* oops,
                                         CLDClosure* clds,
-                                        CodeBlobClosure* blobs) {
+                                        CodeBlobClosure* blobs,
+                                        bool process_string_table) {
   AllRootsClosures closures(oops, clds);
 
   process_java_roots(&closures, NULL, 0);
   process_vm_roots(&closures, NULL, 0);
 
-  if (!_process_strong_tasks.is_task_claimed(G1RP_PS_CodeCache_oops_do)) {
-    CodeCache::blobs_do(blobs);
+  if (process_string_table) {
+    process_string_table_roots(&closures, NULL, 0);
   }
+  process_code_cache_roots(blobs, NULL, 0);
 
   _process_strong_tasks.all_tasks_completed(n_workers());
 }
 
+void G1RootProcessor::process_all_roots(OopClosure* oops,
+                                        CLDClosure* clds,
+                                        CodeBlobClosure* blobs) {
+  process_all_roots(oops, clds, blobs, true);
+}
+
+void G1RootProcessor::process_all_roots_no_string_table(OopClosure* oops,
+                                                        CLDClosure* clds,
+                                                        CodeBlobClosure* blobs) {
+  assert(!ClassUnloading, "Should only be used when class unloading is disabled");
+  process_all_roots(oops, clds, blobs, false);
+}
+
 void G1RootProcessor::process_java_roots(G1RootClosures* closures,
                                          G1GCPhaseTimes* phase_times,
                                          uint worker_i) {
@@ -280,14 +296,23 @@
       SystemDictionary::roots_oops_do(strong_roots, weak_roots);
     }
   }
+}
 
-  {
-    G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::StringTableRoots, worker_i);
-    // All threads execute the following. A specific chunk of buckets
-    // from the StringTable are the individual tasks.
-    if (weak_roots != NULL) {
-      StringTable::possibly_parallel_oops_do(weak_roots);
-    }
+void G1RootProcessor::process_string_table_roots(G1RootClosures* closures,
+                                                 G1GCPhaseTimes* phase_times,
+                                                 uint worker_i) {
+  assert(closures->weak_oops() != NULL, "Should only be called when all roots are processed");
+  G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::StringTableRoots, worker_i);
+  // All threads execute the following. A specific chunk of buckets
+  // from the StringTable are the individual tasks.
+  StringTable::possibly_parallel_oops_do(closures->weak_oops());
+}
+
+void G1RootProcessor::process_code_cache_roots(CodeBlobClosure* code_closure,
+                                               G1GCPhaseTimes* phase_times,
+                                               uint worker_i) {
+  if (!_process_strong_tasks.is_task_claimed(G1RP_PS_CodeCache_oops_do)) {
+    CodeCache::blobs_do(code_closure);
   }
 }
 
--- a/hotspot/src/share/vm/gc/g1/g1RootProcessor.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/gc/g1/g1RootProcessor.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -73,6 +73,11 @@
   void worker_has_discovered_all_strong_classes();
   void wait_until_all_strong_classes_discovered();
 
+  void process_all_roots(OopClosure* oops,
+                         CLDClosure* clds,
+                         CodeBlobClosure* blobs,
+                         bool process_string_table);
+
   void process_java_roots(G1RootClosures* closures,
                           G1GCPhaseTimes* phase_times,
                           uint worker_i);
@@ -81,6 +86,14 @@
                         G1GCPhaseTimes* phase_times,
                         uint worker_i);
 
+  void process_string_table_roots(G1RootClosures* closures,
+                                  G1GCPhaseTimes* phase_times,
+                                  uint worker_i);
+
+  void process_code_cache_roots(CodeBlobClosure* code_closure,
+                                G1GCPhaseTimes* phase_times,
+                                uint worker_i);
+
 public:
   G1RootProcessor(G1CollectedHeap* g1h, uint n_workers);
 
@@ -99,6 +112,13 @@
                          CLDClosure* clds,
                          CodeBlobClosure* blobs);
 
+  // Apply oops, clds and blobs to strongly and weakly reachable roots in the system,
+  // the only thing different from process_all_roots is that we skip the string table
+  // to avoid keeping every string live when doing class unloading.
+  void process_all_roots_no_string_table(OopClosure* oops,
+                                         CLDClosure* clds,
+                                         CodeBlobClosure* blobs);
+
   // Number of worker threads used by the root processor.
   uint n_workers() const;
 };
--- a/hotspot/src/share/vm/gc/g1/heapRegionManager.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/gc/g1/heapRegionManager.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -123,6 +123,7 @@
   for (uint i = start; i < start + num_regions; i++) {
     if (_regions.get_by_index(i) == NULL) {
       HeapRegion* new_hr = new_heap_region(i);
+      OrderAccess::storestore();
       _regions.set_by_index(i, new_hr);
       _allocated_heapregions_length = MAX2(_allocated_heapregions_length, i + 1);
     }
--- a/hotspot/src/share/vm/gc/shared/gcTrace.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/gc/shared/gcTrace.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -185,8 +185,10 @@
 }
 
 #if INCLUDE_ALL_GCS
-void G1MMUTracer::report_mmu(double timeSlice, double gcTime, double maxTime) {
-  send_g1_mmu_event(timeSlice, gcTime, maxTime);
+void G1MMUTracer::report_mmu(double time_slice_sec, double gc_time_sec, double max_time_sec) {
+  send_g1_mmu_event(time_slice_sec * MILLIUNITS,
+                    gc_time_sec * MILLIUNITS,
+                    max_time_sec * MILLIUNITS);
 }
 
 void G1NewTracer::report_yc_type(G1YCType type) {
--- a/hotspot/src/share/vm/gc/shared/gcTrace.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/gc/shared/gcTrace.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -235,10 +235,10 @@
 
 #if INCLUDE_ALL_GCS
 class G1MMUTracer : public AllStatic {
-  static void send_g1_mmu_event(double timeSlice, double gcTime, double maxTime);
+  static void send_g1_mmu_event(double time_slice_ms, double gc_time_ms, double max_time_ms);
 
  public:
-  static void report_mmu(double timeSlice, double gcTime, double maxTime);
+  static void report_mmu(double time_slice_sec, double gc_time_sec, double max_time_sec);
 };
 
 class G1NewTracer : public YoungGCTracer {
--- a/hotspot/src/share/vm/gc/shared/gcTraceSend.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/gc/shared/gcTraceSend.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -200,13 +200,13 @@
   }
 }
 
-void G1MMUTracer::send_g1_mmu_event(double timeSlice, double gcTime, double maxTime) {
+void G1MMUTracer::send_g1_mmu_event(double time_slice_ms, double gc_time_ms, double max_time_ms) {
   EventG1MMU e;
   if (e.should_commit()) {
     e.set_gcId(GCId::current());
-    e.set_timeSlice(timeSlice);
-    e.set_gcTime(gcTime);
-    e.set_maxGcTime(maxTime);
+    e.set_timeSlice(time_slice_ms);
+    e.set_gcTime(gc_time_ms);
+    e.set_pauseTarget(max_time_ms);
     e.commit();
   }
 }
@@ -281,10 +281,10 @@
     evt.set_targetOccupancy(target_occupancy);
     evt.set_thresholdPercentage(target_occupancy > 0 ? ((double)threshold / target_occupancy) : 0.0);
     evt.set_currentOccupancy(current_occupancy);
-    evt.set_lastAllocationSize(last_allocation_size);
-    evt.set_lastAllocationDuration(last_allocation_duration);
-    evt.set_lastAllocationRate(last_allocation_duration != 0.0 ? last_allocation_size / last_allocation_duration : 0.0);
-    evt.set_lastMarkingLength(last_marking_length);
+    evt.set_recentMutatorAllocationSize(last_allocation_size);
+    evt.set_recentMutatorDuration(last_allocation_duration * MILLIUNITS);
+    evt.set_recentAllocationRate(last_allocation_duration != 0.0 ? last_allocation_size / last_allocation_duration : 0.0);
+    evt.set_lastMarkingDuration(last_marking_length * MILLIUNITS);
     evt.commit();
   }
 }
@@ -301,11 +301,11 @@
     evt.set_gcId(GCId::current());
     evt.set_threshold(threshold);
     evt.set_thresholdPercentage(internal_target_occupancy > 0 ? ((double)threshold / internal_target_occupancy) : 0.0);
-    evt.set_internalTargetOccupancy(internal_target_occupancy);
+    evt.set_ihopTargetOccupancy(internal_target_occupancy);
     evt.set_currentOccupancy(current_occupancy);
     evt.set_additionalBufferSize(additional_buffer_size);
     evt.set_predictedAllocationRate(predicted_allocation_rate);
-    evt.set_predictedMarkingLength(predicted_marking_length);
+    evt.set_predictedMarkingDuration(predicted_marking_length * MILLIUNITS);
     evt.set_predictionActive(prediction_active);
     evt.commit();
   }
--- a/hotspot/src/share/vm/gc/shared/workerManager.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/gc/shared/workerManager.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
--- a/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -576,27 +576,39 @@
   // compute auxiliary field attributes
   TosState state  = as_TosState(info.field_type());
 
-  // Put instructions on final fields are not resolved. This is required so we throw
-  // exceptions at the correct place (when the instruction is actually invoked).
+  // Resolution of put instructions on final fields is delayed. That is required so that
+  // exceptions are thrown at the correct place (when the instruction is actually invoked).
   // If we do not resolve an instruction in the current pass, leaving the put_code
   // set to zero will cause the next put instruction to the same field to reresolve.
+
+  // Resolution of put instructions to final instance fields with invalid updates (i.e.,
+  // to final instance fields with updates originating from a method different than <init>)
+  // is inhibited. A putfield instruction targeting an instance final field must throw
+  // an IllegalAccessError if the instruction is not in an instance
+  // initializer method <init>. If resolution were not inhibited, a putfield
+  // in an initializer method could be resolved in the initializer. Subsequent
+  // putfield instructions to the same field would then use cached information.
+  // As a result, those instructions would not pass through the VM. That is,
+  // checks in resolve_field_access() would not be executed for those instructions
+  // and the required IllegalAccessError would not be thrown.
   //
   // Also, we need to delay resolving getstatic and putstatic instructions until the
   // class is initialized.  This is required so that access to the static
   // field will call the initialization function every time until the class
   // is completely initialized ala. in 2.17.5 in JVM Specification.
   InstanceKlass* klass = InstanceKlass::cast(info.field_holder());
-  bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) &&
-                               !klass->is_initialized());
-
-  Bytecodes::Code put_code = (Bytecodes::Code)0;
-  if (is_put && !info.access_flags().is_final() && !uninitialized_static) {
-    put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
-  }
+  bool uninitialized_static = is_static && !klass->is_initialized();
+  bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&
+                                      info.has_initialized_final_update();
+  assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");
 
   Bytecodes::Code get_code = (Bytecodes::Code)0;
+  Bytecodes::Code put_code = (Bytecodes::Code)0;
   if (!uninitialized_static) {
     get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
+    if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {
+      put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
+    }
   }
 
   cp_cache_entry->set_field(
--- a/hotspot/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -768,6 +768,11 @@
   Symbol* h_name      = method->name();
   Symbol* h_signature = method->signature();
 
+  if (MethodHandles::is_signature_polymorphic_method(method())) {
+      // Signature polymorphic methods are already resolved, JVMCI just returns NULL in this case.
+      return NULL;
+  }
+
   LinkInfo link_info(h_resolved, h_name, h_signature, caller_klass);
   methodHandle m;
   // Only do exact lookup if receiver klass has been linked.  Otherwise,
@@ -782,7 +787,7 @@
   }
 
   if (m.is_null()) {
-    // Return NULL only if there was a problem with lookup (uninitialized class, etc.)
+    // Return NULL if there was a problem with lookup (uninitialized class, etc.)
     return NULL;
   }
 
--- a/hotspot/src/share/vm/jvmci/jvmciRuntime.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/jvmci/jvmciRuntime.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -313,13 +313,18 @@
     // normal bytecode execution.
     thread->clear_exception_oop_and_pc();
 
-    continuation = SharedRuntime::compute_compiled_exc_handler(cm, pc, exception, false, false);
+    bool recursive_exception = false;
+    continuation = SharedRuntime::compute_compiled_exc_handler(cm, pc, exception, false, false, recursive_exception);
     // If an exception was thrown during exception dispatch, the exception oop may have changed
     thread->set_exception_oop(exception());
     thread->set_exception_pc(pc);
 
     // the exception cache is used only by non-implicit exceptions
-    if (continuation != NULL && !SharedRuntime::deopt_blob()->contains(continuation)) {
+    // Update the exception cache only when there didn't happen
+    // another exception during the computation of the compiled
+    // exception handler. Checking for exception oop equality is not
+    // sufficient because some exceptions are pre-allocated and reused.
+    if (continuation != NULL && !recursive_exception && !SharedRuntime::deopt_blob()->contains(continuation)) {
       cm->add_handler_for_exception_and_pc(exception, pc, continuation);
     }
   }
--- a/hotspot/src/share/vm/oops/klass.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/oops/klass.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -431,6 +431,12 @@
     if (clean_alive_klasses && current->is_instance_klass()) {
       InstanceKlass* ik = InstanceKlass::cast(current);
       ik->clean_weak_instanceklass_links(is_alive);
+
+      // JVMTI RedefineClasses creates previous versions that are not in
+      // the class hierarchy, so process them here.
+      while ((ik = ik->previous_versions()) != NULL) {
+        ik->clean_weak_instanceklass_links(is_alive);
+      }
     }
   }
 }
--- a/hotspot/src/share/vm/opto/graphKit.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/opto/graphKit.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -2172,10 +2172,9 @@
       java_bc() == Bytecodes::_instanceof ||
       java_bc() == Bytecodes::_aastore) {
     ciProfileData* data = method()->method_data()->bci_to_data(bci());
-    bool maybe_null = data == NULL ? true : data->as_BitData()->null_seen();
+    maybe_null = data == NULL ? true : data->as_BitData()->null_seen();
   }
   return record_profile_for_speculation(n, exact_kls, maybe_null);
-  return n;
 }
 
 /**
--- a/hotspot/src/share/vm/opto/library_call.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/opto/library_call.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -2475,6 +2475,28 @@
       // load value
       switch (type) {
       case T_BOOLEAN:
+      {
+        // Normalize the value returned by getBoolean in the following cases
+        if (mismatched ||
+            heap_base_oop == top() ||                            // - heap_base_oop is NULL or
+            (can_access_non_heap && alias_type->field() == NULL) // - heap_base_oop is potentially NULL
+                                                                 //   and the unsafe access is made to large offset
+                                                                 //   (i.e., larger than the maximum offset necessary for any
+                                                                 //   field access)
+            ) {
+          IdealKit ideal = IdealKit(this);
+#define __ ideal.
+          IdealVariable normalized_result(ideal);
+          __ declarations_done();
+          __ set(normalized_result, p);
+          __ if_then(p, BoolTest::ne, ideal.ConI(0));
+          __ set(normalized_result, ideal.ConI(1));
+          ideal.end_if();
+          final_sync(ideal);
+          p = __ value(normalized_result);
+#undef __
+        }
+      }
       case T_CHAR:
       case T_BYTE:
       case T_SHORT:
--- a/hotspot/src/share/vm/opto/runtime.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/opto/runtime.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1349,17 +1349,23 @@
         force_unwind ? NULL : nm->handler_for_exception_and_pc(exception, pc);
 
       if (handler_address == NULL) {
-        Handle original_exception(thread, exception());
-        handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true);
+        bool recursive_exception = false;
+        handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception);
         assert (handler_address != NULL, "must have compiled handler");
         // Update the exception cache only when the unwind was not forced
         // and there didn't happen another exception during the computation of the
-        // compiled exception handler.
-        if (!force_unwind && original_exception() == exception()) {
+        // compiled exception handler. Checking for exception oop equality is not
+        // sufficient because some exceptions are pre-allocated and reused.
+        if (!force_unwind && !recursive_exception) {
           nm->add_handler_for_exception_and_pc(exception,pc,handler_address);
         }
       } else {
-        assert(handler_address == SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true), "Must be the same");
+#ifdef ASSERT
+        bool recursive_exception = false;
+        address computed_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception);
+        vmassert(recursive_exception || (handler_address == computed_address), "Handler address inconsistency: " PTR_FORMAT " != " PTR_FORMAT,
+                 p2i(handler_address), p2i(computed_address));
+#endif
       }
     }
 
--- a/hotspot/src/share/vm/prims/jvm.h	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/prims/jvm.h	Fri Sep 30 09:28:18 2016 -0700
@@ -196,7 +196,8 @@
  * java.lang.StackWalker
  */
 enum {
-  JVM_STACKWALK_FILL_CLASS_REFS_ONLY       = 0x2,
+  JVM_STACKWALK_FILL_CLASS_REFS_ONLY       = 0x02,
+  JVM_STACKWALK_GET_CALLER_CLASS           = 0x04,
   JVM_STACKWALK_SHOW_HIDDEN_FRAMES         = 0x20,
   JVM_STACKWALK_FILL_LIVE_STACK_FRAMES     = 0x100
 };
--- a/hotspot/src/share/vm/prims/jvmtiEventController.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/prims/jvmtiEventController.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -96,7 +96,7 @@
 static const jlong  THREAD_FILTERED_EVENT_BITS = INTERP_EVENT_BITS | EXCEPTION_BITS | MONITOR_BITS |
                                         BREAKPOINT_BIT | CLASS_LOAD_BIT | CLASS_PREPARE_BIT | THREAD_END_BIT;
 static const jlong  NEED_THREAD_LIFE_EVENTS = THREAD_FILTERED_EVENT_BITS | THREAD_START_BIT;
-static const jlong  EARLY_EVENT_BITS = CLASS_FILE_LOAD_HOOK_BIT |
+static const jlong  EARLY_EVENT_BITS = CLASS_FILE_LOAD_HOOK_BIT | CLASS_LOAD_BIT | CLASS_PREPARE_BIT |
                                VM_START_BIT | VM_INIT_BIT | VM_DEATH_BIT | NATIVE_METHOD_BIND_BIT |
                                THREAD_START_BIT | THREAD_END_BIT |
                                COMPILED_METHOD_LOAD_BIT | COMPILED_METHOD_UNLOAD_BIT |
--- a/hotspot/src/share/vm/prims/stackwalk.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/prims/stackwalk.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -113,7 +113,10 @@
     int bci = stream.bci();
 
     if (method == NULL) continue;
-    if (!ShowHiddenFrames && StackWalk::skip_hidden_frames(mode)) {
+
+    // skip hidden frames for default StackWalker option (i.e. SHOW_HIDDEN_FRAMES
+    // not set) and when StackWalker::getCallerClass is called
+    if (!ShowHiddenFrames && (skip_hidden_frames(mode) || get_caller_class(mode))) {
       if (method->is_hidden()) {
         if (TraceStackWalk) {
           tty->print("  hidden method: "); method->print_short_name();
@@ -139,7 +142,14 @@
       Handle stackFrame(frames_array->obj_at(index));
       fill_stackframe(stackFrame, method, bci);
     } else {
-      assert (use_frames_array(mode) == false, "Bad mode for get caller class");
+      assert (use_frames_array(mode) == false, "Bad mode for filling in Class object");
+      if (get_caller_class(mode) && index == start_index && method->caller_sensitive()) {
+        ResourceMark rm(THREAD);
+        THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(),
+          err_msg("StackWalker::getCallerClass called from @CallerSensitive %s method",
+                  method->name_and_sig_as_C_string()));
+      }
+
       frames_array->obj_at_put(index, method->method_holder()->java_mirror());
     }
     if (++frames_decoded >= max_nframes)  break;
--- a/hotspot/src/share/vm/prims/stackwalk.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/prims/stackwalk.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -82,6 +82,9 @@
   static void fill_live_stackframe(Handle stackFrame, const methodHandle& method, int bci,
                                    javaVFrame* jvf, TRAPS);
 
+  static inline bool get_caller_class(int mode) {
+    return (mode & JVM_STACKWALK_GET_CALLER_CLASS) != 0;
+  }
   static inline bool skip_hidden_frames(int mode) {
     return (mode & JVM_STACKWALK_SHOW_HIDDEN_FRAMES) == 0;
   }
--- a/hotspot/src/share/vm/prims/unsafe.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/prims/unsafe.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -150,14 +150,23 @@
   }
 
   template <typename T>
-  T normalize(T x) {
+  T normalize_for_write(T x) {
     return x;
   }
 
-  jboolean normalize(jboolean x) {
+  jboolean normalize_for_write(jboolean x) {
     return x & 1;
   }
 
+  template <typename T>
+  T normalize_for_read(T x) {
+    return x;
+  }
+
+  jboolean normalize_for_read(jboolean x) {
+    return x != 0;
+  }
+
   /**
    * Helper class to wrap memory accesses in JavaThread::doing_unsafe_access()
    */
@@ -196,7 +205,7 @@
 
     T* p = (T*)addr();
 
-    T x = *p;
+    T x = normalize_for_read(*p);
 
     return x;
   }
@@ -207,7 +216,7 @@
 
     T* p = (T*)addr();
 
-    *p = normalize(x);
+    *p = normalize_for_write(x);
   }
 
 
@@ -223,7 +232,7 @@
 
     T x = OrderAccess::load_acquire((volatile T*)p);
 
-    return x;
+    return normalize_for_read(x);
   }
 
   template <typename T>
@@ -232,7 +241,7 @@
 
     T* p = (T*)addr();
 
-    OrderAccess::release_store_fence((volatile T*)p, normalize(x));
+    OrderAccess::release_store_fence((volatile T*)p, normalize_for_write(x));
   }
 
 
@@ -256,7 +265,7 @@
 
     jlong* p = (jlong*)addr();
 
-    Atomic::store(normalize(x),  p);
+    Atomic::store(normalize_for_write(x),  p);
   }
 #endif
 };
--- a/hotspot/src/share/vm/prims/whitebox.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/prims/whitebox.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -894,6 +894,7 @@
   }
   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
   const char* flag_name = env->GetStringUTFChars(name, NULL);
+  CHECK_JNI_EXCEPTION_(env, false);
   Flag::Error result = (*TAt)(flag_name, value, true, true);
   env->ReleaseStringUTFChars(name, flag_name);
   return (result == Flag::SUCCESS);
@@ -906,6 +907,7 @@
   }
   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
   const char* flag_name = env->GetStringUTFChars(name, NULL);
+  CHECK_JNI_EXCEPTION_(env, false);
   Flag::Error result = (*TAtPut)(flag_name, value, Flag::INTERNAL);
   env->ReleaseStringUTFChars(name, flag_name);
   return (result == Flag::SUCCESS);
@@ -944,6 +946,7 @@
 static Flag* getVMFlag(JavaThread* thread, JNIEnv* env, jstring name) {
   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
   const char* flag_name = env->GetStringUTFChars(name, NULL);
+  CHECK_JNI_EXCEPTION_(env, NULL);
   Flag* result = Flag::find_flag(flag_name, strlen(flag_name), true, true);
   env->ReleaseStringUTFChars(name, flag_name);
   return result;
@@ -1084,7 +1087,14 @@
 
 WB_ENTRY(void, WB_SetStringVMFlag(JNIEnv* env, jobject o, jstring name, jstring value))
   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
-  const char* ccstrValue = (value == NULL) ? NULL : env->GetStringUTFChars(value, NULL);
+  const char* ccstrValue;
+  if (value == NULL) {
+    ccstrValue = NULL;
+  }
+  else {
+    ccstrValue = env->GetStringUTFChars(value, NULL);
+    CHECK_JNI_EXCEPTION(env);
+  }
   ccstr ccstrResult = ccstrValue;
   bool needFree;
   {
@@ -1308,6 +1318,7 @@
   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
   CHECK_JNI_EXCEPTION_(env, NULL);
   result = env->NewObjectArray(blobs.length(), clazz, NULL);
+  CHECK_JNI_EXCEPTION_(env, NULL);
   if (result == NULL) {
     return result;
   }
@@ -1317,6 +1328,7 @@
     jobjectArray obj = codeBlob2objectArray(thread, env, *it);
     CHECK_JNI_EXCEPTION_(env, NULL);
     env->SetObjectArrayElement(result, i, obj);
+    CHECK_JNI_EXCEPTION_(env, NULL);
     ++i;
   }
   return result;
@@ -1523,6 +1535,7 @@
   // can't be in VM when we call JNI
   ThreadToNativeFromVM ttnfv(thread);
   const char* flag_name = env->GetStringUTFChars(name, NULL);
+  CHECK_JNI_EXCEPTION_(env, false);
   bool result =  CompilerOracle::has_option_value(mh, flag_name, *value);
   env->ReleaseStringUTFChars(name, flag_name);
   return result;
@@ -1678,6 +1691,7 @@
   // can't be in VM when we call JNI
   ThreadToNativeFromVM ttnfv(thread);
   const char* dir = env->GetStringUTFChars(compDirect, NULL);
+  CHECK_JNI_EXCEPTION_(env, 0);
   int ret;
   {
     ThreadInVMfromNative ttvfn(thread); // back to VM
--- a/hotspot/src/share/vm/prims/whitebox.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/prims/whitebox.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -33,9 +33,22 @@
 #include "oops/symbol.hpp"
 #include "runtime/interfaceSupport.hpp"
 
+// Unconditionally clear pedantic pending JNI checks
+class ClearPendingJniExcCheck : public StackObj {
+private:
+  JavaThread* _thread;
+public:
+  ClearPendingJniExcCheck(JNIEnv* env) : _thread(JavaThread::thread_from_jni_environment(env)) {}
+  ~ClearPendingJniExcCheck() {
+    _thread->clear_pending_jni_exception_check();
+  }
+};
+
 // Entry macro to transition from JNI to VM state.
 
-#define WB_ENTRY(result_type, header) JNI_ENTRY(result_type, header)
+#define WB_ENTRY(result_type, header) JNI_ENTRY(result_type, header) \
+  ClearPendingJniExcCheck _clearCheck(env);
+
 #define WB_END JNI_END
 #define WB_METHOD_DECLARE(result_type) extern "C" result_type JNICALL
 
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1308,35 +1308,13 @@
   return true;
 }
 
-// sets or adds a module name to the jdk.module.addmods property
-bool Arguments::append_to_addmods_property(const char* module_name) {
-  const char* key = "jdk.module.addmods";
-  const char* old_value = Arguments::get_property(key);
-  size_t buf_len = strlen(key) + strlen(module_name) + 2;
-  if (old_value != NULL) {
-    buf_len += strlen(old_value) + 1;
-  }
-  char* new_value = AllocateHeap(buf_len, mtArguments);
-  if (new_value == NULL) {
-    return false;
-  }
-  if (old_value == NULL) {
-    jio_snprintf(new_value, buf_len, "%s=%s", key, module_name);
-  } else {
-    jio_snprintf(new_value, buf_len, "%s=%s,%s", key, old_value, module_name);
-  }
-  bool added = add_property(new_value, UnwriteableProperty, InternalProperty);
-  FreeHeap(new_value);
-  return added;
-}
-
 #if INCLUDE_CDS
 void Arguments::check_unsupported_dumping_properties() {
   assert(DumpSharedSpaces, "this function is only used with -Xshare:dump");
   const char* unsupported_properties[5] = { "jdk.module.main",
                                            "jdk.module.path",
                                            "jdk.module.upgrade.path",
-                                           "jdk.module.addmods",
+                                           "jdk.module.addmods.0",
                                            "jdk.module.limitmods" };
   const char* unsupported_options[5] = { "-m",
                                         "--module-path",
@@ -1687,11 +1665,6 @@
     CompactibleFreeListSpaceLAB::modify_initialization(OldPLABSize, OldPLABWeight);
   }
 
-  if (!ClassUnloading) {
-    FLAG_SET_CMDLINE(bool, CMSClassUnloadingEnabled, false);
-    FLAG_SET_CMDLINE(bool, ExplicitGCInvokesConcurrentAndUnloadsClasses, false);
-  }
-
   log_trace(gc)("MarkStackSize: %uk  MarkStackSizeMax: %uk", (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K));
 }
 #endif // INCLUDE_ALL_GCS
@@ -2019,6 +1992,13 @@
     // Keeping the heap 100% free is hard ;-) so limit it to 99%.
     FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99);
   }
+
+  // If class unloading is disabled, also disable concurrent class unloading.
+  if (!ClassUnloading) {
+    FLAG_SET_CMDLINE(bool, CMSClassUnloadingEnabled, false);
+    FLAG_SET_CMDLINE(bool, ClassUnloadingWithConcurrentMark, false);
+    FLAG_SET_CMDLINE(bool, ExplicitGCInvokesConcurrentAndUnloadsClasses, false);
+  }
 #endif // INCLUDE_ALL_GCS
 }
 
@@ -2566,8 +2546,8 @@
 
 unsigned int addreads_count = 0;
 unsigned int addexports_count = 0;
+unsigned int addmods_count = 0;
 unsigned int patch_mod_count = 0;
-const char* add_modules_value = NULL;
 
 bool Arguments::create_property(const char* prop_name, const char* prop_value, PropertyInternal internal) {
   size_t prop_len = strlen(prop_name) + strlen(prop_value) + 2;
@@ -2821,7 +2801,9 @@
         return JNI_ENOMEM;
       }
     } else if (match_option(option, "--add-modules=", &tail)) {
-      add_modules_value = tail;
+      if (!create_numbered_property("jdk.module.addmods", tail, addmods_count++)) {
+        return JNI_ENOMEM;
+      }
     } else if (match_option(option, "--limit-modules=", &tail)) {
       if (!create_property("jdk.module.limitmods", tail, InternalProperty)) {
         return JNI_ENOMEM;
@@ -2873,7 +2855,7 @@
         char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1, mtArguments), tail);
         add_init_agent("instrument", options, false);
         // java agents need module java.instrument
-        if (!Arguments::append_to_addmods_property("java.instrument")) {
+        if (!create_numbered_property("jdk.module.addmods", "java.instrument", addmods_count++)) {
           return JNI_ENOMEM;
         }
       }
@@ -3149,7 +3131,7 @@
           return JNI_EINVAL;
         }
         // management agent in module java.management
-        if (!Arguments::append_to_addmods_property("java.management")) {
+        if (!create_numbered_property("jdk.module.addmods", "java.management", addmods_count++)) {
           return JNI_ENOMEM;
         }
 #else
@@ -3560,15 +3542,6 @@
     return JNI_ERR;
   }
 
-  // Append the value of the last --add-modules option specified on the command line.
-  // This needs to be done here, to prevent overwriting possible values written
-  // to the jdk.module.addmods property by -javaagent and other options.
-  if (add_modules_value != NULL) {
-    if (!append_to_addmods_property(add_modules_value)) {
-      return JNI_ENOMEM;
-    }
-  }
-
   // This must be done after all arguments have been processed.
   // java_compiler() true means set to "NONE" or empty.
   if (java_compiler() && !xdebug_mode()) {
@@ -3617,7 +3590,8 @@
 #endif
 
 #if INCLUDE_JVMCI
-  if (EnableJVMCI && !append_to_addmods_property("jdk.vm.ci")) {
+  if (EnableJVMCI &&
+      !create_numbered_property("jdk.module.addmods", "jdk.vm.ci", addmods_count++)) {
     return JNI_ENOMEM;
   }
 #endif
--- a/hotspot/src/share/vm/runtime/arguments.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/runtime/arguments.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -489,9 +489,6 @@
 
   static int process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase);
 
-  // Miscellaneous system property setter
-  static bool append_to_addmods_property(const char* module_name);
-
   // Aggressive optimization flags.
   static jint set_aggressive_opts_flags();
 
--- a/hotspot/src/share/vm/runtime/interfaceSupport.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/runtime/interfaceSupport.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -280,6 +280,7 @@
 
   ~ThreadToNativeFromVM() {
     trans_from_native(_thread_in_vm);
+    assert(!_thread->is_pending_jni_exception_check(), "Pending JNI Exception Check");
     // We don't need to clear_walkable because it will happen automagically when we return to java
   }
 };
--- a/hotspot/src/share/vm/runtime/os.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/runtime/os.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -443,7 +443,7 @@
 
   static bool create_thread(Thread* thread,
                             ThreadType thr_type,
-                            size_t stack_size = 0);
+                            size_t req_stack_size = 0);
   static bool create_main_thread(JavaThread* thread);
   static bool create_attached_thread(JavaThread* thread);
   static void pd_start_thread(Thread* thread);
--- a/hotspot/src/share/vm/runtime/sharedRuntime.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/runtime/sharedRuntime.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -621,7 +621,7 @@
 // ret_pc points into caller; we are returning caller's exception handler
 // for given exception
 address SharedRuntime::compute_compiled_exc_handler(CompiledMethod* cm, address ret_pc, Handle& exception,
-                                                    bool force_unwind, bool top_frame_only) {
+                                                    bool force_unwind, bool top_frame_only, bool& recursive_exception_occurred) {
   assert(cm != NULL, "must exist");
   ResourceMark rm;
 
@@ -677,6 +677,7 @@
         // BCI of the exception handler which caused the exception to be
         // thrown (bugs 4307310 and 4546590). Set "exception" reference
         // argument to ensure that the correct exception is thrown (4870175).
+        recursive_exception_occurred = true;
         exception = Handle(THREAD, PENDING_EXCEPTION);
         CLEAR_PENDING_EXCEPTION;
         if (handler_bci >= 0) {
--- a/hotspot/src/share/vm/runtime/sharedRuntime.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/runtime/sharedRuntime.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -189,7 +189,7 @@
 
   // exception handling and implicit exceptions
   static address compute_compiled_exc_handler(CompiledMethod* nm, address ret_pc, Handle& exception,
-                                              bool force_unwind, bool top_frame_only);
+                                              bool force_unwind, bool top_frame_only, bool& recursive_exception_occurred);
   enum ImplicitExceptionKind {
     IMPLICIT_NULL,
     IMPLICIT_DIVIDE_BY_ZERO,
--- a/hotspot/src/share/vm/runtime/thread.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/runtime/thread.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -1542,6 +1542,9 @@
   static ByteSize jmp_ring_offset()              { return byte_offset_of(JavaThread, _jmp_ring); }
 #endif // PRODUCT
   static ByteSize jni_environment_offset()       { return byte_offset_of(JavaThread, _jni_environment); }
+  static ByteSize pending_jni_exception_check_fn_offset() {
+    return byte_offset_of(JavaThread, _pending_jni_exception_check_fn);
+  }
   static ByteSize last_Java_sp_offset() {
     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
   }
@@ -1615,7 +1618,11 @@
     assert(_jni_active_critical >= 0, "JNI critical nesting problem?");
   }
 
-  // Checked JNI, is the programmer required to check for exceptions, specify which function name
+  // Checked JNI: is the programmer required to check for exceptions, if so specify
+  // which function name. Returning to a Java frame should implicitly clear the
+  // pending check, this is done for Native->Java transitions (i.e. user JNI code).
+  // VM->Java transistions are not cleared, it is expected that JNI code enclosed
+  // within ThreadToNativeFromVM makes proper exception checks (i.e. VM internal).
   bool is_pending_jni_exception_check() const { return _pending_jni_exception_check_fn != NULL; }
   void clear_pending_jni_exception_check() { _pending_jni_exception_check_fn = NULL; }
   const char* get_pending_jni_exception_check() const { return _pending_jni_exception_check_fn; }
--- a/hotspot/src/share/vm/trace/traceevents.xml	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/trace/traceevents.xml	Fri Sep 30 09:28:18 2016 -0700
@@ -315,9 +315,9 @@
 
   <event id="G1MMU" path="vm/gc/detailed/g1_mmu_info" label="G1 MMU Information" is_instant="true">
     <value type="UINT" field="gcId" label="GC Identifier" relation="GcId"/>
-    <value type="DOUBLE" field="timeSlice" label="Time Slice" description="Time slice used to calculate MMU"/>
-    <value type="DOUBLE" field="gcTime" label="GC Time" description="Time spent on GC during last time slice"/>
-    <value type="DOUBLE" field="maxGcTime" label="Max GC Time" description="Max time allowed to be spent on GC during last time slice"/>
+    <value type="MILLIS" field="timeSlice" label="Time Slice" description="Time slice used to calculate MMU"/>
+    <value type="MILLIS" field="gcTime" label="GC Time" description="Time stopped because of GC during last time slice"/>
+    <value type="MILLIS" field="pauseTarget" label="Pause Target" description="Max time allowed to be spent on GC during last time slice"/>
   </event>
 
   <event id="EvacuationInformation" path="vm/gc/detailed/evacuation_info" label="Evacuation Information" is_instant="true">
@@ -377,29 +377,29 @@
     <structvalue type="G1EvacuationStatistics" field="statistics" label="Evacuation Statistics"/>
   </event>
 
-  <event id="G1BasicIHOP" path="vm/gc/detailed/g1_basic_ihop_status" label="G1 Basic IHOP statistics"
+  <event id="G1BasicIHOP" path="vm/gc/detailed/g1_basic_ihop_status" label="G1 Basic IHOP Statistics"
          is_instant="true" description="Basic statistics related to current IHOP calculation">
     <value type="UINT" field="gcId" label="GC Identifier" relation="GcId"/>
-    <value type="BYTES64" field="threshold" label="Current IHOP threshold" description="Current IHOP threshold in bytes"/>
-    <value type="PERCENTAGE" field="thresholdPercentage" label="Current IHOP threshold in percent" description="Current IHOP threshold in percent of old gen"/>
-    <value type="BYTES64" field="targetOccupancy" label="Target Occupancy" description="Target old gen occupancy to reach at the start of mixed GC in bytes"/>
-    <value type="BYTES64" field="currentOccupancy" label="Current Occupancy" description="Current old generation occupancy in bytes"/>
-    <value type="BYTES64" field="lastAllocationSize" label="Last Mutator Allocation" description="Mutator allocation during mutator operation since last GC in bytes"/>
-    <value type="DOUBLE" field="lastAllocationDuration" label="Last Mutator Operation" description="Time the mutator ran since last GC in seconds"/>
-    <value type="DOUBLE" field="lastAllocationRate" label="Last Mutator Allocation Rate" description="Allocation rate of the mutator since last GC in bytes/second"/>
-    <value type="DOUBLE" field="lastMarkingLength" label="Last Marking Length" description="Last time from the end of the last initial mark to the first mixed GC in seconds"/>
+    <value type="BYTES64" field="threshold" label="Current IHOP Threshold" description="Current IHOP threshold"/>
+    <value type="PERCENTAGE" field="thresholdPercentage" label="Current IHOP Threshold" description="Current IHOP threshold in percent of old generation"/>
+    <value type="BYTES64" field="targetOccupancy" label="Target Occupancy" description="Target old generation occupancy to reach at the start of mixed GC"/>
+    <value type="BYTES64" field="currentOccupancy" label="Current Occupancy" description="Current old generation occupancy"/>
+    <value type="BYTES64" field="recentMutatorAllocationSize" label="Recent Mutator Allocation Size" description="Mutator allocation during mutator operation in the most recent interval"/>
+    <value type="MILLIS" field="recentMutatorDuration" label="Recent Mutator Duration" description="Time the mutator ran in the most recent interval"/>
+    <value type="DOUBLE" field="recentAllocationRate" label="Recent Allocation Rate" description="Allocation rate of the mutator in the most recent interval in bytes/second"/>
+    <value type="MILLIS" field="lastMarkingDuration" label="Last Marking Duration" description="Last time from the end of the last initial mark to the first mixed GC"/>
   </event>
 
-  <event id="G1AdaptiveIHOP" path="vm/gc/detailed/g1_adaptive_ihop_status" label="G1 Adaptive IHOP statistics"
+  <event id="G1AdaptiveIHOP" path="vm/gc/detailed/g1_adaptive_ihop_status" label="G1 Adaptive IHOP Statistics"
          is_instant="true" description="Statistics related to current adaptive IHOP calculation">
     <value type="UINT" field="gcId" label="GC Identifier" relation="GcId"/>
-    <value type="BYTES64" field="threshold" label="Threshold" description="Current IHOP threshold in bytes"/>
-    <value type="PERCENTAGE" field="thresholdPercentage" label="Threshold Percentage" description="Current IHOP threshold in percent of the internal target occupancy"/>
-    <value type="BYTES64" field="internalTargetOccupancy" label="Target Occupancy" description="Internal target old generation occupancy to reach at the start of mixed GC in bytes"/>
-    <value type="BYTES64" field="currentOccupancy" label="Current Occupancy" description="Current old generation occupancy in bytes"/>
-    <value type="BYTES64" field="additionalBufferSize" label="Additional Buffer" description="Additional buffer size in bytes"/>
+    <value type="BYTES64" field="threshold" label="Threshold" description="Current IHOP Threshold"/>
+    <value type="PERCENTAGE" field="thresholdPercentage" label="Threshold" description="Current IHOP threshold in percent of the internal target occupancy"/>
+    <value type="BYTES64" field="ihopTargetOccupancy" label="IHOP Target Occupancy" description="Internal target old generation occupancy to reach at the start of mixed GC"/>
+    <value type="BYTES64" field="currentOccupancy" label="Current Occupancy" description="Current old generation occupancy"/>
+    <value type="BYTES64" field="additionalBufferSize" label="Additional Buffer" description="Additional buffer size" experimental="true"/>
     <value type="DOUBLE" field="predictedAllocationRate" label="Predicted Allocation Rate" description="Current predicted allocation rate for the mutator in bytes/second"/>
-    <value type="DOUBLE" field="predictedMarkingLength" label="Predicted Marking Length" description="Current predicted time from the end of the last initial mark to the first mixed GC in seconds"/>
+    <value type="MILLIS" field="predictedMarkingDuration" label="Predicted Marking Duration" description="Current predicted time from the end of the last initial mark to the first mixed GC"/>
     <value type="BOOLEAN" field="predictionActive" label="Prediction Active" description="Indicates whether the adaptive IHOP prediction is active"/>
   </event>
 
--- a/hotspot/src/share/vm/utilities/exceptions.cpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/utilities/exceptions.cpp	Fri Sep 30 09:28:18 2016 -0700
@@ -80,7 +80,7 @@
   if (h_exception()->klass() == SystemDictionary::StackOverflowError_klass()) {
     InstanceKlass* ik = InstanceKlass::cast(h_exception->klass());
     assert(ik->is_initialized(),
-           "need to increase min_stack_allowed calculation");
+           "need to increase java_thread_min_stack_allowed calculation");
   }
 #endif // ASSERT
 
@@ -227,7 +227,7 @@
     Klass* k = SystemDictionary::StackOverflowError_klass();
     oop e = InstanceKlass::cast(k)->allocate_instance(CHECK);
     exception = Handle(THREAD, e);  // fill_in_stack trace does gc
-    assert(InstanceKlass::cast(k)->is_initialized(), "need to increase min_stack_allowed calculation");
+    assert(InstanceKlass::cast(k)->is_initialized(), "need to increase java_thread_min_stack_allowed calculation");
     if (StackTraceInThrowable) {
       java_lang_Throwable::fill_in_stack_trace(exception, method());
     }
--- a/hotspot/src/share/vm/utilities/globalDefinitions_xlc.hpp	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/src/share/vm/utilities/globalDefinitions_xlc.hpp	Fri Sep 30 09:28:18 2016 -0700
@@ -186,6 +186,6 @@
 
 // Inlining support
 #define NOINLINE
-#define ALWAYSINLINE __attribute__((always_inline))
+#define ALWAYSINLINE inline __attribute__((always_inline))
 
 #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_XLC_HPP
--- a/hotspot/test/compiler/c2/Test6968348.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/c2/Test6968348.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -38,15 +38,11 @@
 import java.lang.reflect.Field;
 
 public class Test6968348 {
-    static Unsafe unsafe;
+    static Unsafe unsafe = Unsafe.getUnsafe();
     static final long[] buffer = new long[4096];
     static int array_long_base_offset;
 
     public static void main(String[] args) throws Exception {
-        Class c = Test6968348.class.getClassLoader().loadClass("jdk.internal.misc.Unsafe");
-        Field f = c.getDeclaredField("theUnsafe");
-        f.setAccessible(true);
-        unsafe = (Unsafe)f.get(c);
         array_long_base_offset = unsafe.arrayBaseOffset(long[].class);
 
         for (int n = 0; n < 100000; n++) {
--- a/hotspot/test/compiler/c2/cr8004867/TestIntUnsafeCAS.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/c2/cr8004867/TestIntUnsafeCAS.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -50,14 +50,10 @@
   private static final int ALIGN_OFF = 8;
   private static final int UNALIGN_OFF = 5;
 
-  private static final Unsafe unsafe;
+  private static final Unsafe unsafe = Unsafe.getUnsafe();
   private static final int BASE;
   static {
     try {
-      Class c = TestIntUnsafeCAS.class.getClassLoader().loadClass("jdk.internal.misc.Unsafe");
-      Field f = c.getDeclaredField("theUnsafe");
-      f.setAccessible(true);
-      unsafe = (Unsafe)f.get(c);
       BASE = unsafe.arrayBaseOffset(int[].class);
     } catch (Exception e) {
       InternalError err = new InternalError();
--- a/hotspot/test/compiler/c2/cr8004867/TestIntUnsafeOrdered.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/c2/cr8004867/TestIntUnsafeOrdered.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -50,14 +50,10 @@
   private static final int ALIGN_OFF = 8;
   private static final int UNALIGN_OFF = 5;
 
-  private static final Unsafe unsafe;
+  private static final Unsafe unsafe = Unsafe.getUnsafe();
   private static final int BASE;
   static {
     try {
-      Class<?> c = Unsafe.class;
-      Field f = c.getDeclaredField("theUnsafe");
-      f.setAccessible(true);
-      unsafe = (Unsafe) f.get(c);
       BASE = unsafe.arrayBaseOffset(int[].class);
     } catch (Exception e) {
       InternalError err = new InternalError();
--- a/hotspot/test/compiler/c2/cr8004867/TestIntUnsafeVolatile.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/c2/cr8004867/TestIntUnsafeVolatile.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -50,14 +50,10 @@
   private static final int ALIGN_OFF = 8;
   private static final int UNALIGN_OFF = 5;
 
-  private static final Unsafe unsafe;
+  private static final Unsafe unsafe = Unsafe.getUnsafe();
   private static final int BASE;
   static {
     try {
-      Class c = TestIntUnsafeVolatile.class.getClassLoader().loadClass("jdk.internal.misc.Unsafe");
-      Field f = c.getDeclaredField("theUnsafe");
-      f.setAccessible(true);
-      unsafe = (Unsafe)f.get(c);
       BASE = unsafe.arrayBaseOffset(int[].class);
     } catch (Exception e) {
       InternalError err = new InternalError();
--- a/hotspot/test/compiler/codecache/OverflowCodeCacheTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/codecache/OverflowCodeCacheTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -75,6 +75,7 @@
         System.out.printf("type %s%n", type);
         System.out.println("allocating till possible...");
         ArrayList<Long> blobs = new ArrayList<>();
+        int compilationActivityMode = -1;
         try {
             long addr;
             int size = (int) (getHeapSize() >> 7);
@@ -88,13 +89,16 @@
                             type + " doesn't allow using " + actualType + " when overflow");
                 }
             }
-            Asserts.assertNotEquals(WHITE_BOX.getCompilationActivityMode(), 1 /* run_compilation*/,
-                    "Compilation must be disabled when CodeCache(CodeHeap) overflows");
+            /* now, remember compilationActivityMode to check it later, after freeing, since we
+               possibly have no free cache for futher work */
+            compilationActivityMode = WHITE_BOX.getCompilationActivityMode();
         } finally {
             for (Long blob : blobs) {
                 WHITE_BOX.freeCodeBlob(blob);
             }
         }
+        Asserts.assertNotEquals(compilationActivityMode, 1 /* run_compilation*/,
+                "Compilation must be disabled when CodeCache(CodeHeap) overflows");
     }
 
     private long getHeapSize() {
--- a/hotspot/test/compiler/cpuflags/AESIntrinsicsBase.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/cpuflags/AESIntrinsicsBase.java	Fri Sep 30 09:28:18 2016 -0700
@@ -48,8 +48,8 @@
             = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintIntrinsics"};
     public static final String[] TEST_AES_CMD
             = {"-XX:+IgnoreUnrecognizedVMOptions", "-XX:+PrintFlagsFinal",
-            "-Xbatch", "-DcheckOutput=true", "-Dmode=CBC",
-            TestAESMain.class.getName()};
+            "-Xbatch", "-XX:CompileThresholdScaling=0.01", "-DcheckOutput=true", "-Dmode=CBC",
+            TestAESMain.class.getName(), "100", "1000"};
 
     protected AESIntrinsicsBase(BooleanSupplier predicate) {
         super(predicate);
--- a/hotspot/test/compiler/cpuflags/TestAESIntrinsicsOnSupportedConfig.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/cpuflags/TestAESIntrinsicsOnSupportedConfig.java	Fri Sep 30 09:28:18 2016 -0700
@@ -27,11 +27,11 @@
  * @library /test/lib /
  * @modules java.base/jdk.internal.misc
  *          java.management
- * @ignore 8146128
  * @build sun.hotspot.WhiteBox
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
+ * @run main/othervm/timeout=600 -Xbootclasspath/a:.
+ *                   -XX:+UnlockDiagnosticVMOptions
  *                   -XX:+WhiteBoxAPI -Xbatch
  *                   compiler.cpuflags.TestAESIntrinsicsOnSupportedConfig
  */
--- a/hotspot/test/compiler/intrinsics/unsafe/TestUnsafeMismatchedArrayFieldAccess.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/intrinsics/unsafe/TestUnsafeMismatchedArrayFieldAccess.java	Fri Sep 30 09:28:18 2016 -0700
@@ -27,7 +27,6 @@
  * @bug 8142386
  * @summary Unsafe access to an array is wrongly marked as mismatched
  * @modules java.base/jdk.internal.misc
- * @library /test/lib
  *
  * @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:-TieredCompilation
  *      compiler.intrinsics.unsafe.TestUnsafeMismatchedArrayFieldAccess
@@ -36,11 +35,10 @@
 package compiler.intrinsics.unsafe;
 
 import jdk.internal.misc.Unsafe;
-import jdk.test.lib.unsafe.UnsafeHelper;
 
 public class TestUnsafeMismatchedArrayFieldAccess {
 
-    private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
+    private static final Unsafe UNSAFE = Unsafe.getUnsafe();
 
     static {
         try {
--- a/hotspot/test/compiler/jvmci/compilerToVM/ExecuteInstalledCodeTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/jvmci/compilerToVM/ExecuteInstalledCodeTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -19,7 +19,6 @@
  * @requires (vm.simpleArch == "x64" | vm.simpleArch == "sparcv9" | vm.simpleArch == "aarch64")
  * @library /test/lib /
  * @library ../common/patches
- * @ignore 8139383
  * @modules java.base/jdk.internal.misc
  * @modules java.base/jdk.internal.org.objectweb.asm
  *          java.base/jdk.internal.org.objectweb.asm.tree
--- a/hotspot/test/compiler/jvmci/compilerToVM/GetResolvedJavaMethodTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/jvmci/compilerToVM/GetResolvedJavaMethodTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -45,7 +45,6 @@
 
 import jdk.internal.misc.Unsafe;
 import jdk.test.lib.Asserts;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.vm.ci.hotspot.CompilerToVMHelper;
 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
 import jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject;
@@ -114,7 +113,7 @@
         abstract HotSpotResolvedJavaMethod getResolvedJavaMethod();
     }
 
-    private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
+    private static final Unsafe UNSAFE = Unsafe.getUnsafe();
     private static final WhiteBox WB = WhiteBox.getWhiteBox();
     private static final Field METASPACE_METHOD_FIELD;
     private static final Class<?> TEST_CLASS = GetResolvedJavaMethodTest.class;
--- a/hotspot/test/compiler/jvmci/compilerToVM/GetResolvedJavaTypeTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/jvmci/compilerToVM/GetResolvedJavaTypeTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -53,7 +53,6 @@
 
 import jdk.internal.misc.Unsafe;
 import jdk.test.lib.Asserts;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.vm.ci.hotspot.CompilerToVMHelper;
 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
@@ -154,7 +153,7 @@
         abstract HotSpotResolvedObjectType getResolvedJavaType();
     }
 
-    private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
+    private static final Unsafe UNSAFE = Unsafe.getUnsafe();
     private static final WhiteBox WB = WhiteBox.getWhiteBox();
     private static final Class TEST_CLASS = GetResolvedJavaTypeTest.class;
     /* a compressed parameter for tested method is set to false because
--- a/hotspot/test/compiler/jvmci/compilerToVM/ResolveFieldInPoolTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/jvmci/compilerToVM/ResolveFieldInPoolTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -53,7 +53,6 @@
 import jdk.internal.misc.Unsafe;
 import jdk.internal.org.objectweb.asm.Opcodes;
 import jdk.test.lib.Asserts;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.vm.ci.hotspot.CompilerToVMHelper;
 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
 import jdk.vm.ci.meta.ConstantPool;
@@ -69,7 +68,7 @@
  */
 public class ResolveFieldInPoolTest {
 
-    private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
+    private static final Unsafe UNSAFE = Unsafe.getUnsafe();
 
     public static void main(String[] args) throws Exception {
         Map<ConstantTypes, Validator> typeTests = new HashMap<>();
--- a/hotspot/test/compiler/jvmci/compilerToVM/ResolveMethodTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/jvmci/compilerToVM/ResolveMethodTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -52,7 +52,6 @@
 import jdk.internal.misc.Unsafe;
 import jdk.test.lib.Asserts;
 import jdk.test.lib.Utils;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.vm.ci.hotspot.CompilerToVMHelper;
 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
@@ -61,7 +60,7 @@
 import java.util.Set;
 
 public class ResolveMethodTest {
-    private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
+    private static final Unsafe UNSAFE = Unsafe.getUnsafe();
 
     public static void main(String args[]) {
         ResolveMethodTest test = new ResolveMethodTest();
--- a/hotspot/test/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java	Fri Sep 30 09:28:18 2016 -0700
@@ -25,7 +25,6 @@
  * @test
  * @requires (vm.simpleArch == "x64" | vm.simpleArch == "sparcv9" | vm.simpleArch == "aarch64")
  * @library ../../../../../
- * @ignore 8161550
  * @modules java.base/jdk.internal.reflect
  *          jdk.vm.ci/jdk.vm.ci.meta
  *          jdk.vm.ci/jdk.vm.ci.runtime
@@ -74,11 +73,29 @@
 /**
  * Tests for {@link ResolvedJavaType}.
  */
+@SuppressWarnings("unchecked")
 public class TestResolvedJavaType extends TypeUniverse {
+    private static final Class<? extends Annotation> SIGNATURE_POLYMORPHIC_CLASS = findPolymorphicSignatureClass();
 
     public TestResolvedJavaType() {
     }
 
+    private static Class<? extends Annotation> findPolymorphicSignatureClass() {
+        Class<? extends Annotation> signaturePolyAnnotation = null;
+        try {
+            for (Class<?> clazz : TestResolvedJavaType.class.getClassLoader().loadClass("java.lang.invoke.MethodHandle").getDeclaredClasses()) {
+                if (clazz.getName().endsWith("PolymorphicSignature") && Annotation.class.isAssignableFrom(clazz)) {
+                    signaturePolyAnnotation = (Class<? extends Annotation>) clazz;
+                    break;
+                }
+            }
+        } catch (Throwable e) {
+            throw new AssertionError("Could not find annotation PolymorphicSignature in java.lang.invoke.MethodHandle", e);
+        }
+        assertNotNull(signaturePolyAnnotation);
+        return signaturePolyAnnotation;
+    }
+
     @Test
     public void findInstanceFieldWithOffsetTest() {
         for (Class<?> c : classes) {
@@ -577,8 +594,14 @@
                     for (Method decl : decls) {
                         ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl);
                         if (m.isPublic()) {
-                            ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl);
-                            assertEquals(m.toString(), i, type.resolveMethod(m, context));
+                            ResolvedJavaMethod resolvedmethod = type.resolveMethod(m, context);
+                            if (isSignaturePolymorphic(m)) {
+                                // Signature polymorphic methods must not be resolved
+                                assertNull(resolvedmethod);
+                            } else {
+                                ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl);
+                                assertEquals(m.toString(), i, resolvedmethod);
+                            }
                         }
                     }
                 }
@@ -606,8 +629,14 @@
                     for (Method decl : decls) {
                         ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl);
                         if (m.isPublic()) {
-                            ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl);
-                            assertEquals(i, type.resolveConcreteMethod(m, context));
+                            ResolvedJavaMethod resolvedMethod = type.resolveConcreteMethod(m, context);
+                            if (isSignaturePolymorphic(m)) {
+                                // Signature polymorphic methods must not be resolved
+                                assertNull(String.format("Got: %s", resolvedMethod), resolvedMethod);
+                            } else {
+                                ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl);
+                                assertEquals(i, resolvedMethod);
+                            }
                         }
                     }
                 }
@@ -929,4 +958,8 @@
             }
         }
     }
+
+    private static boolean isSignaturePolymorphic(ResolvedJavaMethod method) {
+        return method.getAnnotation(SIGNATURE_POLYMORPHIC_CLASS) != null;
+    }
 }
--- a/hotspot/test/compiler/loopopts/UseCountedLoopSafepoints.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/loopopts/UseCountedLoopSafepoints.java	Fri Sep 30 09:28:18 2016 -0700
@@ -22,51 +22,32 @@
  *
  */
 
-/**
- * @test
- * @bug 6869327
- * @summary Test that C2 flag UseCountedLoopSafepoints ensures a safepoint is kept in a CountedLoop
- * @library /test/lib
- * @modules java.base/jdk.internal.misc
- * @ignore 8146096
- * @run driver compiler.loopopts.UseCountedLoopSafepoints
- */
-
 package compiler.loopopts;
 
-import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
-
-import java.util.concurrent.atomic.AtomicLong;
+import java.lang.reflect.Method;
+import sun.hotspot.WhiteBox;
+import jdk.test.lib.Asserts;
+import compiler.whitebox.CompilerWhiteBoxTest;
 
 public class UseCountedLoopSafepoints {
-    private static final AtomicLong _num = new AtomicLong(0);
+    private static final WhiteBox WB = WhiteBox.getWhiteBox();
+    private static final String METHOD_NAME = "testMethod";
 
-    // Uses the fact that an EnableBiasedLocking vmop will be started
-    // after 500ms, while we are still in the loop. If there is a
-    // safepoint in the counted loop, then we will reach safepoint
-    // very quickly. Otherwise SafepointTimeout will be hit.
+    private long accum = 0;
+
     public static void main (String args[]) throws Exception {
-        if (args.length == 1) {
-            final int loops = Integer.parseInt(args[0]);
-            for (int i = 0; i < loops; i++) {
-                _num.addAndGet(1);
-            }
-        } else {
-            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-                    "-XX:+IgnoreUnrecognizedVMOptions",
-                    "-XX:-TieredCompilation",
-                    "-XX:+UseBiasedLocking",
-                    "-XX:BiasedLockingStartupDelay=500",
-                    "-XX:+SafepointTimeout",
-                    "-XX:SafepointTimeoutDelay=2000",
-                    "-XX:+UseCountedLoopSafepoints",
-                    UseCountedLoopSafepoints.class.getName(),
-                    "2000000000"
-                    );
-            OutputAnalyzer output = new OutputAnalyzer(pb.start());
-            output.shouldNotContain("Timeout detected");
-            output.shouldHaveExitValue(0);
+        new UseCountedLoopSafepoints().testMethod();
+        Method m = UseCountedLoopSafepoints.class.getDeclaredMethod(METHOD_NAME);
+        String directive = "[{ match: \"" + UseCountedLoopSafepoints.class.getName().replace('.', '/')
+                + "." + METHOD_NAME + "\", " + "BackgroundCompilation: false }]";
+        Asserts.assertTrue(WB.addCompilerDirective(directive) == 1, "Can't add compiler directive");
+        Asserts.assertTrue(WB.enqueueMethodForCompilation(m,
+                CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION), "Can't enqueue method");
+    }
+
+    private void testMethod() {
+        for (int i = 0; i < 100; i++) {
+            accum += accum << 5 + accum >> 4 - accum >>> 5;
         }
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/loopopts/UseCountedLoopSafepointsTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/**
+ * @test
+ * @bug 6869327
+ * @summary Test that C2 flag UseCountedLoopSafepoints ensures a safepoint is kept in a CountedLoop
+ * @library /test/lib /
+ * @requires vm.compMode != "Xint" & vm.flavor == "server" & (vm.opt.TieredStopAtLevel == null | vm.opt.TieredStopAtLevel == 4)
+ * @modules java.base/jdk.internal.misc
+ * @build sun.hotspot.WhiteBox
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox
+ *                                sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run driver compiler.loopopts.UseCountedLoopSafepointsTest
+ */
+
+package compiler.loopopts;
+
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import jdk.test.lib.Asserts;
+
+/* Idea of this test is to check if ideal graph has CountedLoopEnd->SafePoint edge in case
+   of UseCountedLoopSafepoint enabled and has no such edge in case it's disabled. Restricting
+   compilation to testMethod only will leave only one counted loop (the one in testedMethod) */
+public class UseCountedLoopSafepointsTest {
+
+    public static void main (String args[]) {
+        check(true); // check ideal graph with UseCountedLoopSafepoint enabled
+        check(false); // ... and disabled
+    }
+
+    private static void check(boolean enabled) {
+        OutputAnalyzer oa;
+        try {
+            oa = ProcessTools.executeTestJvm("-XX:+UnlockDiagnosticVMOptions", "-Xbootclasspath/a:.",
+                    "-XX:" + (enabled ? "+" : "-") + "UseCountedLoopSafepoints", "-XX:+WhiteBoxAPI",
+                    "-XX:-Inline", "-Xbatch", "-XX:+PrintIdeal", "-XX:LoopUnrollLimit=0",
+                    "-XX:CompileOnly=" + UseCountedLoopSafepoints.class.getName() + "::testMethod",
+                    UseCountedLoopSafepoints.class.getName());
+        } catch (Exception e) {
+            throw new Error("Exception launching child for case enabled=" + enabled + " : " + e, e);
+        }
+        oa.shouldHaveExitValue(0);
+        // parse output in seach of SafePoint and CountedLoopEnd nodes
+        List<Node> safePoints = new ArrayList<>();
+        List<Node> loopEnds = new ArrayList<>();
+        for (String line : oa.getOutput().split("\\n")) {
+            int separatorIndex = line.indexOf("\t===");
+            if (separatorIndex > -1) {
+                String header = line.substring(0, separatorIndex);
+                if (header.endsWith("\tSafePoint")) {
+                    safePoints.add(new Node("SafePoint", line));
+                } else if (header.endsWith("\tCountedLoopEnd")) {
+                    loopEnds.add(new Node("CountedLoopEnd", line));
+                }
+            }
+        }
+        // now, find CountedLoopEnd -> SafePoint edge
+        boolean found = false;
+        for (Node loopEnd : loopEnds) {
+            found |= loopEnd.to.stream()
+                                 .filter(id -> nodeListHasElementWithId(safePoints, id))
+                                 .findAny()
+                                 .isPresent();
+        }
+        Asserts.assertEQ(enabled, found, "Safepoint " + (found ? "" : "not ") + "found");
+    }
+
+    private static boolean nodeListHasElementWithId(List<Node> list, int id) {
+        return list.stream()
+                   .filter(node -> node.id == id)
+                   .findAny()
+                   .isPresent();
+    }
+
+    private static class Node {
+        public final int id;
+        public final List<Integer> from;
+        public final List<Integer> to;
+
+        public Node(String name, String str) {
+            List<Integer> tmpFrom = new ArrayList<>();
+            List<Integer> tmpTo = new ArrayList<>();
+            // parse string like: " $id    $name       ===  $to1 $to2 ...   [[ $from1 $from2 ... ]] $anything"
+            // example:  318    SafePoint       ===  317  1  304  1  1  10  308  [[ 97  74 ]]  ...
+            id = Integer.parseInt(str.substring(1, str.indexOf(name)).trim());
+            Arrays.stream(str.substring(str.indexOf("===") + 4, str.indexOf("[[")).trim().split("\\s+"))
+                  .map(Integer::parseInt)
+                  .forEach(tmpTo::add);
+            Arrays.stream(str.substring(str.indexOf("[[") + 3, str.indexOf("]]")).trim().split("\\s+"))
+                  .map(Integer::parseInt)
+                  .forEach(tmpFrom::add);
+            this.from = Collections.unmodifiableList(tmpFrom);
+            this.to = Collections.unmodifiableList(tmpTo);
+        }
+    }
+}
--- a/hotspot/test/compiler/loopopts/superword/TestVectorizationWithInvariant.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/loopopts/superword/TestVectorizationWithInvariant.java	Fri Sep 30 09:28:18 2016 -0700
@@ -34,7 +34,6 @@
 package compiler.loopopts.superword;
 
 import jdk.internal.misc.Unsafe;
-import jdk.test.lib.unsafe.UnsafeHelper;
 
 public class TestVectorizationWithInvariant {
 
@@ -43,7 +42,7 @@
     private static final long CHAR_ARRAY_OFFSET;
 
     static {
-        unsafe = UnsafeHelper.getUnsafe();
+        unsafe = Unsafe.getUnsafe();
         BYTE_ARRAY_OFFSET = unsafe.arrayBaseOffset(byte[].class);
         CHAR_ARRAY_OFFSET = unsafe.arrayBaseOffset(char[].class);
     }
--- a/hotspot/test/compiler/rtm/locking/TestRTMAbortRatio.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/rtm/locking/TestRTMAbortRatio.java	Fri Sep 30 09:28:18 2016 -0700
@@ -49,7 +49,6 @@
 import jdk.internal.misc.Unsafe;
 import jdk.test.lib.Asserts;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.test.lib.cli.CommandLineOptionTest;
 import jdk.test.lib.cli.predicate.AndPredicate;
 
@@ -125,7 +124,7 @@
     public static class Test implements CompilableTest {
         private static final int TOTAL_ITERATIONS = 10000;
         private static final int WARMUP_ITERATIONS = 1000;
-        private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
+        private static final Unsafe UNSAFE = Unsafe.getUnsafe();
         private final Object monitor = new Object();
         // Following field have to be static in order to avoid escape analysis.
         @SuppressWarnings("UnsuedDeclaration")
--- a/hotspot/test/compiler/rtm/locking/TestRTMAfterNonRTMDeopt.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/rtm/locking/TestRTMAfterNonRTMDeopt.java	Fri Sep 30 09:28:18 2016 -0700
@@ -51,7 +51,6 @@
 import jdk.internal.misc.Unsafe;
 import jdk.test.lib.Asserts;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.test.lib.cli.CommandLineOptionTest;
 import jdk.test.lib.cli.predicate.AndPredicate;
 
@@ -158,7 +157,7 @@
         private static int field = 0;
         private static final int ITERATIONS = 10000;
         private static final int RANGE_CHECK_AT = ITERATIONS / 2;
-        private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
+        private static final Unsafe UNSAFE = Unsafe.getUnsafe();
         private final Object monitor = new Object();
 
         @Override
--- a/hotspot/test/compiler/rtm/locking/TestRTMDeoptOnLowAbortRatio.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/rtm/locking/TestRTMDeoptOnLowAbortRatio.java	Fri Sep 30 09:28:18 2016 -0700
@@ -48,7 +48,6 @@
 import jdk.internal.misc.Unsafe;
 import jdk.test.lib.Asserts;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.test.lib.cli.CommandLineOptionTest;
 import jdk.test.lib.cli.predicate.AndPredicate;
 
@@ -133,7 +132,7 @@
     }
 
     public static class Test implements CompilableTest {
-        private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
+        private static final Unsafe UNSAFE = Unsafe.getUnsafe();
         private final Object monitor = new Object();
 
         @Override
--- a/hotspot/test/compiler/rtm/locking/TestRTMLockingThreshold.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/rtm/locking/TestRTMLockingThreshold.java	Fri Sep 30 09:28:18 2016 -0700
@@ -49,7 +49,6 @@
 import jdk.internal.misc.Unsafe;
 import jdk.test.lib.Asserts;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.test.lib.cli.CommandLineOptionTest;
 import jdk.test.lib.cli.predicate.AndPredicate;
 
@@ -142,7 +141,7 @@
         @SuppressWarnings("UnsuedDeclaration")
         private static int field = 0;
         private static final int TOTAL_ITERATIONS = 10000;
-        private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
+        private static final Unsafe UNSAFE = Unsafe.getUnsafe();
         private final Object monitor = new Object();
 
 
--- a/hotspot/test/compiler/rtm/locking/TestRTMTotalCountIncrRate.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/rtm/locking/TestRTMTotalCountIncrRate.java	Fri Sep 30 09:28:18 2016 -0700
@@ -49,7 +49,6 @@
 import jdk.internal.misc.Unsafe;
 import jdk.test.lib.Asserts;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.test.lib.cli.CommandLineOptionTest;
 import jdk.test.lib.cli.predicate.AndPredicate;
 
@@ -113,7 +112,7 @@
 
     public static class Test implements CompilableTest {
         private static final long TOTAL_ITERATIONS = 10000L;
-        private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
+        private static final Unsafe UNSAFE = Unsafe.getUnsafe();
         private final Object monitor = new Object();
         // Following field have to be static in order to avoid escape analysis.
         @SuppressWarnings("UnsuedDeclaration")
--- a/hotspot/test/compiler/testlibrary/rtm/XAbortProvoker.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/testlibrary/rtm/XAbortProvoker.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
 package compiler.testlibrary.rtm;
 
 import jdk.internal.misc.Unsafe;
-import jdk.test.lib.unsafe.UnsafeHelper;
 
 /**
  * Current RTM locking implementation force transaction abort
@@ -35,7 +34,7 @@
     // Following field have to be static in order to avoid escape analysis.
     @SuppressWarnings("UnsuedDeclaration")
     private static int field = 0;
-    private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
+    private static final Unsafe UNSAFE = Unsafe.getUnsafe();
 
     public XAbortProvoker() {
         this(new Object());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/unsafe/UnsafeOffHeapBooleanTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8161720
+ * @modules java.base/jdk.internal.misc
+ * @run main/othervm -Xint UnsafeOffHeapBooleanTest 1
+ * @run main/othervm -XX:+TieredCompilation -XX:TieredStopAtLevel=3 -Xbatch  UnsafeOffHeapBooleanTest 20000
+ * @run main/othervm -XX:-TieredCompilation -Xbatch UnsafeOffHeapBooleanTest 20000
+ */
+
+
+import java.lang.reflect.Field;
+import jdk.internal.misc.Unsafe;
+
+public class UnsafeOffHeapBooleanTest {
+    static boolean bool0 = false, bool1 = false, result = false;
+    static Unsafe UNSAFE = Unsafe.getUnsafe();
+    static long offHeapMemory;
+
+    public static void test() {
+        // Write two bytes to the off-heap memory location, both
+        // bytes correspond to the boolean value 'true'.
+        UNSAFE.putShort(null, offHeapMemory, (short)0x0204);
+
+        // Read two bytes from the storage allocated above (as booleans).
+        bool0 = UNSAFE.getBoolean(null, offHeapMemory + 0);
+        bool1 = UNSAFE.getBoolean(null, offHeapMemory + 1);
+        result = bool0 & bool1;
+    }
+
+    public static void main(String args[]) {
+        System.out.println("### Test started");
+
+        if (args.length != 1) {
+            throw new RuntimeException("### Test failure: test called with incorrect number of arguments");
+        }
+
+        // Allocate two bytes of storage.
+        offHeapMemory = UNSAFE.allocateMemory(2);
+
+        try {
+            for (int i = 0; i < Integer.parseInt(args[0]); i++) {
+                test();
+            }
+
+            // Check if the two 'true' boolean values were normalized
+            // (i.e., reduced from the range 1...255 to 1).
+            if (!bool0 || !bool1 || !result) {
+                System.out.println("Some of the results below are wrong");
+                System.out.println("bool0 is: " + bool0);
+                System.out.println("bool1 is: " + bool1);
+                System.out.println("bool0 & bool1 is: " + result);
+                System.out.println("===================================");
+                throw new RuntimeException("### Test failed");
+            } else {
+                System.out.println("Test generated correct results");
+                System.out.println("bool0 is: " + bool0);
+                System.out.println("bool1 is: " + bool1);
+                System.out.println("bool0 & bool1 is: " + result);
+                System.out.println("===================================");
+            }
+        } catch (NumberFormatException e) {
+            throw new RuntimeException("### Test failure: test called with incorrectly formatted parameter");
+        }
+
+        UNSAFE.freeMemory(offHeapMemory);
+
+        System.out.println("### Test passed");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/unsafe/UnsafeOnHeapBooleanTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8161720
+ * @modules java.base/jdk.internal.misc
+ * @run main/othervm -Xint UnsafeOnHeapBooleanTest 1
+ * @run main/othervm -XX:-UseOnStackReplacement -XX:+TieredCompilation -XX:TieredStopAtLevel=3 -Xbatch UnsafeOnHeapBooleanTest 20000
+ * @run main/othervm -XX:-UseOnStackReplacement -XX:-TieredCompilation -Xbatch UnsafeOnHeapBooleanTest 20000
+ */
+
+import java.lang.reflect.Field;
+import jdk.internal.misc.Unsafe;
+
+public class UnsafeOnHeapBooleanTest {
+    static short static_v;
+    static boolean bool0 = false, bool1 = false, result = false;
+    static Unsafe UNSAFE = Unsafe.getUnsafe();
+
+    public static void test() {
+        try {
+            // Write two bytes into the static field
+            // UnsafeOnHeapBooleanTest.static_v write two values. Both
+            // bytes correspond to the boolean value 'true'.
+            Field staticVField = UnsafeOnHeapBooleanTest.class.getDeclaredField("static_v");
+            Object base = UNSAFE.staticFieldBase(staticVField);
+            long offset = UNSAFE.staticFieldOffset(staticVField);
+            UNSAFE.putShort(base, offset, (short)0x0204);
+
+            // Read two bytes from the static field
+            // UnsafeOnHeapBooleanTest.static_v (as booleans).
+            bool0 = UNSAFE.getBoolean(base, offset + 0);
+            bool1 = UNSAFE.getBoolean(base, offset + 1);
+            result = bool0 & bool1;
+        } catch (NoSuchFieldException e) {
+            throw new RuntimeException("### Test failure: static field UnsafeOnHeapBooleanTest.static_v was not found");
+        }
+    }
+
+    public static void main(String args[]) {
+        System.out.println("### Test started");
+
+        if (args.length != 1) {
+            throw new RuntimeException("### Test failure: test called with incorrect number of arguments");
+        }
+
+        try {
+            for (int i = 0; i < Integer.parseInt(args[0]); i++) {
+                test();
+            }
+
+            // Check if the two 'true' boolean values were normalized
+            // (i.e., reduced from the range 1...255 to 1).
+            if (!bool0 || !bool1 || !result) {
+                System.out.println("Some of the results below are wrong");
+                System.out.println("bool0 is: " + bool0);
+                System.out.println("bool1 is: " + bool1);
+                System.out.println("bool0 & bool1 is: " + result);
+                System.out.println("===================================");
+                throw new RuntimeException("### Test failed");
+            } else {
+                System.out.println("Test generated correct results");
+                System.out.println("bool0 is: " + bool0);
+                System.out.println("bool1 is: " + bool1);
+                System.out.println("bool0 & bool1 is: " + result);
+                System.out.println("===================================");
+            }
+        } catch (NumberFormatException e) {
+            throw new RuntimeException("### Test failure: test called with incorrectly formatted parameter");
+        }
+
+        System.out.println("### Test passed");
+    }
+}
--- a/hotspot/test/compiler/unsafe/UnsafeRaw.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/compiler/unsafe/UnsafeRaw.java	Fri Sep 30 09:28:18 2016 -0700
@@ -35,7 +35,6 @@
 
 import jdk.internal.misc.Unsafe;
 import jdk.test.lib.Utils;
-import jdk.test.lib.unsafe.UnsafeHelper;
 
 import java.util.Random;
 
@@ -82,7 +81,7 @@
   }
 
   public static void main(String[] args) throws Exception {
-    Unsafe unsafe = UnsafeHelper.getUnsafe();
+    Unsafe unsafe = Unsafe.getUnsafe();
     final int array_size = 128;
     final int element_size = 4;
     final int magic = 0x12345678;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/unsafe/UnsafeSmallOffsetBooleanAccessTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8161720
+ * @modules java.base/jdk.internal.misc
+ * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -Xbatch -XX:-TieredCompilation UnsafeSmallOffsetBooleanAccessTest
+ * @run main/othervm -Xbatch UnsafeSmallOffsetBooleanAccessTest
+ */
+
+import java.util.Random;
+import jdk.internal.misc.Unsafe;
+
+public class UnsafeSmallOffsetBooleanAccessTest {
+    static final Unsafe UNSAFE = Unsafe.getUnsafe();
+    static final long F_OFFSET;
+    static final Random random = new Random();
+
+    static {
+        try {
+            F_OFFSET = UNSAFE.objectFieldOffset(T.class.getDeclaredField("f"));
+            System.out.println("The offset is: " + F_OFFSET);
+        } catch (Exception e) {
+            throw new Error(e);
+        }
+    }
+
+    static class T {
+        boolean f;
+    }
+
+    // Always return false in a way that is not obvious to the compiler.
+    public static boolean myRandom() {
+        if (random.nextInt(101) > 134) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public static boolean test(T t) {
+        boolean result = false;
+        for (int i = 0; i < 20000; i++) {
+            boolean random = myRandom();
+            // If myRandom() returns false, access t.f.
+            //
+            // If myRandom() returns true, access virtual address
+            // F_OFFSET. That address is most likely not mapped,
+            // therefore the access will most likely cause a
+            // crash. We're not concerned about that, though, because
+            // myRandom() always returns false. However, the C2
+            // compiler avoids normalization of the value returned by
+            // getBoolean in this case.
+            result = UNSAFE.getBoolean(myRandom() ? null : t, F_OFFSET);
+        }
+        return result;
+    }
+
+    public static void main(String[] args) {
+        T t = new T();
+        UNSAFE.putBoolean(t, F_OFFSET, true);
+        System.out.println("The result for t is: " + test(t));
+    }
+}
--- a/hotspot/test/gc/arguments/TestMaxMinHeapFreeRatioFlags.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/gc/arguments/TestMaxMinHeapFreeRatioFlags.java	Fri Sep 30 09:28:18 2016 -0700
@@ -37,7 +37,6 @@
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.Utils;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 
 public class TestMaxMinHeapFreeRatioFlags {
@@ -134,7 +133,7 @@
      */
     public static class RatioVerifier {
 
-        private static final Unsafe unsafe = UnsafeHelper.getUnsafe();
+        private static final Unsafe unsafe = Unsafe.getUnsafe();
 
         // Size of byte array that will be allocated
         public static final int CHUNK_SIZE = 1024;
--- a/hotspot/test/gc/arguments/TestTargetSurvivorRatioFlag.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/gc/arguments/TestTargetSurvivorRatioFlag.java	Fri Sep 30 09:28:18 2016 -0700
@@ -46,7 +46,6 @@
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.Utils;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import sun.hotspot.WhiteBox;
 
 /* In order to test that TargetSurvivorRatio affects survivor space occupancy
@@ -249,7 +248,7 @@
     public static class TargetSurvivorRatioVerifier {
 
         static final WhiteBox wb = WhiteBox.getWhiteBox();
-        static final Unsafe unsafe = UnsafeHelper.getUnsafe();
+        static final Unsafe unsafe = Unsafe.getUnsafe();
 
         // Desired size of memory allocated at once
         public static final int CHUNK_SIZE = 1024;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/class_unloading/TestClassUnloadingDisabled.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reqserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key gc
+ * @bug 8114823
+ * @requires vm.gc == null
+ * @requires vm.opt.ExplicitGCInvokesConcurrent != true
+ * @requires vm.opt.ClassUnloading != true
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ *          java.management
+ * @build sun.hotspot.WhiteBox
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ *
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
+ *                   -XX:-ClassUnloading -XX:+UseG1GC TestClassUnloadingDisabled
+ *
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
+ *                   -XX:-ClassUnloading -XX:+UseSerialGC TestClassUnloadingDisabled
+ *
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
+ *                   -XX:-ClassUnloading -XX:+UseParallelGC TestClassUnloadingDisabled
+ *
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
+ *                   -XX:-ClassUnloading -XX:+UseConcMarkSweepGC TestClassUnloadingDisabled
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import sun.hotspot.WhiteBox;
+
+import static jdk.test.lib.Asserts.*;
+
+public class TestClassUnloadingDisabled {
+    public static void main(String args[]) throws Exception {
+        final WhiteBox wb = WhiteBox.getWhiteBox();
+        // Fetch the dir where the test class and the class
+        // to be loaded resides.
+        String classDir = TestClassUnloadingDisabled.class.getProtectionDomain().getCodeSource().getLocation().getPath();
+        String className = "ClassToLoadUnload";
+
+        assertFalse(wb.isClassAlive(className), "Should not be loaded yet");
+
+        // The NoPDClassLoader handles loading classes in the test directory
+        // and loads them without a protection domain, which in some cases
+        // keeps the class live regardless of marking state.
+        NoPDClassLoader nopd = new NoPDClassLoader(classDir);
+        nopd.loadClass(className);
+
+        assertTrue(wb.isClassAlive(className), "Class should be loaded");
+
+        // Clear the class-loader, class and object references to make
+        // class unloading possible.
+        nopd = null;
+
+        System.gc();
+        assertTrue(wb.isClassAlive(className), "Class should not have ben unloaded");
+    }
+}
+
+class NoPDClassLoader extends ClassLoader {
+    String path;
+
+    NoPDClassLoader(String path) {
+        this.path = path;
+    }
+
+    public Class<?> loadClass(String name) throws ClassNotFoundException {
+        byte[] cls = null;
+        File f = new File(path,name + ".class");
+
+        // Delegate class loading if class not present in the given
+        // directory.
+        if (!f.exists()) {
+            return super.loadClass(name);
+        }
+
+        try {
+            Path path = Paths.get(f.getAbsolutePath());
+            cls = Files.readAllBytes(path);
+        } catch (IOException e) {
+            throw new ClassNotFoundException(name);
+        }
+
+        // Define class with no protection domain and resolve it.
+        return defineClass(name, cls, 0, cls.length, null);
+    }
+}
+
+class ClassToLoadUnload {
+}
--- a/hotspot/test/jprt.config	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/jprt.config	Fri Sep 30 09:28:18 2016 -0700
@@ -86,12 +86,12 @@
     fi
 
     # Add basic solaris system paths
-    path4sdk=/usr/ccs/bin:/usr/ccs/lib:/usr/bin:/bin:/usr/sfw/bin
+    path4sdk=/usr/bin
 
     # Find GNU make
-    make=/usr/sfw/bin/gmake
+    make=/usr/bin/gmake
     if [ ! -f ${make} ] ; then
-	make=/opt/sfw/bin/gmake
+	make=/usr/gnu/bin/make
 	if [ ! -f ${make} ] ; then
 	    make=${slashjava}/devtools/${solaris_arch}/bin/gnumake
         fi 
--- a/hotspot/test/runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java	Fri Sep 30 09:28:18 2016 -0700
@@ -89,20 +89,6 @@
         excludeTestMaxRange("CICompilerCount");
 
         /*
-         * JDK-8136766
-         * Temporarily remove ThreadStackSize from testing because Windows can set it to 0
-         * (for default OS size) but other platforms insist it must be greater than 0
-        */
-        excludeTestRange("ThreadStackSize");
-
-        /*
-         * Remove the flag controlling the size of the stack because the
-         * flag has direct influence on the physical memory usage of
-         * the VM.
-         */
-        allOptionsAsMap.remove("CompilerThreadStackSize");
-
-        /*
          * Exclude MallocMaxTestWords as it is expected to exit VM at small values (>=0)
          */
         excludeTestMinRange("MallocMaxTestWords");
@@ -124,6 +110,8 @@
         excludeTestMaxRange("OldSize");
         excludeTestMaxRange("ParallelGCThreads");
 
+        excludeTestMaxRange("CompilerThreadStackSize");
+        excludeTestMaxRange("ThreadStackSize");
         excludeTestMaxRange("VMThreadStackSize");
 
         /*
--- a/hotspot/test/runtime/ErrorHandling/CreateCoredumpOnCrash.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/ErrorHandling/CreateCoredumpOnCrash.java	Fri Sep 30 09:28:18 2016 -0700
@@ -34,13 +34,12 @@
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.Platform;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 
 public class CreateCoredumpOnCrash {
     private static class Crasher {
         public static void main(String[] args) {
-            UnsafeHelper.getUnsafe().putInt(0L, 0);
+            Unsafe.getUnsafe().putInt(0L, 0);
         }
     }
 
--- a/hotspot/test/runtime/ErrorHandling/ProblematicFrameTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/ErrorHandling/ProblematicFrameTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -35,14 +35,13 @@
 
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.unsafe.UnsafeHelper;
 
 import jdk.internal.misc.Unsafe;
 
 public class ProblematicFrameTest {
     private static class Crasher {
         public static void main(String[] args) {
-            UnsafeHelper.getUnsafe().getInt(0);
+            Unsafe.getUnsafe().getInt(0);
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/LocalLong/LocalLongHelper.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.lang.StackWalker.StackFrame;
+
+public class LocalLongHelper {
+    static StackWalker sw;
+    static Method intValue;
+    static Method getLocals;
+    static Class<?> primitiveValueClass;
+    static Method primitiveType;
+    static Method getMethodType;
+    static Field memberName;
+    static Field offset;
+
+    public static void main(String[] args) throws Throwable {
+        setupReflectionStatics();
+        new LocalLongHelper().longArg(0xC0FFEE, 0x1234567890ABCDEFL);
+    }
+
+    // locals[2] contains the high byte of the long argument.
+    public long longArg(int i, long l) throws Throwable {
+        List<StackFrame> frames = sw.walk(s -> s.collect(Collectors.toList()));
+        Object[] locals = (Object[]) getLocals.invoke(frames.get(0));
+
+        int locals_2 = (int) intValue.invoke(locals[2]);
+        if (locals_2 != 0){
+            throw new RuntimeException("Expected locals_2 == 0");
+        }
+        return l; // Don't want l to become a dead var
+    }
+
+    private static void setupReflectionStatics() throws Throwable {
+        Class<?> liveStackFrameClass = Class.forName("java.lang.LiveStackFrame");
+        primitiveValueClass = Class.forName("java.lang.LiveStackFrame$PrimitiveValue");
+
+        getLocals = liveStackFrameClass.getDeclaredMethod("getLocals");
+        getLocals.setAccessible(true);
+
+        intValue = primitiveValueClass.getDeclaredMethod("intValue");
+        intValue.setAccessible(true);
+
+        Class<?> stackFrameInfoClass = Class.forName("java.lang.StackFrameInfo");
+        memberName = stackFrameInfoClass.getDeclaredField("memberName");
+        memberName.setAccessible(true);
+        offset = stackFrameInfoClass.getDeclaredField("bci");
+        offset.setAccessible(true);
+        getMethodType = Class.forName("java.lang.invoke.MemberName").getDeclaredMethod("getMethodType");
+        getMethodType.setAccessible(true);
+
+        Class<?> extendedOptionClass = Class.forName("java.lang.StackWalker$ExtendedOption");
+        Method ewsNI = StackWalker.class.getDeclaredMethod("newInstance", Set.class, extendedOptionClass);
+        ewsNI.setAccessible(true);
+        Field f = extendedOptionClass.getDeclaredField("LOCALS_AND_OPERANDS");
+        f.setAccessible(true);
+        Object localsAndOperandsOption = f.get(null);
+
+        primitiveType = primitiveValueClass.getDeclaredMethod("type");
+        primitiveType.setAccessible(true);
+
+        sw = (StackWalker) ewsNI.invoke(null, java.util.Collections.emptySet(), localsAndOperandsOption);
+    }
+
+    private static String type(Object o) throws Throwable {
+        if (primitiveValueClass.isInstance(o)) {
+            final char c = (char) primitiveType.invoke(o);
+            return String.valueOf(c);
+        } else if (o != null) {
+            return o.getClass().getName();
+        } else {
+            return "null";
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/LocalLong/LocalLongTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test LocalLongTest
+ * @bug 8163014
+ * @modules java.base/jdk.internal.misc
+ * @library /test/lib
+ * @compile LocalLongHelper.java
+ * @run driver LocalLongTest
+ */
+
+import jdk.test.lib.Platform;
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+
+public class LocalLongTest {
+    public static void main(String... args) throws Exception {
+        if (Platform.is64bit()) {
+            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xint",
+                                                                      "LocalLongHelper");
+            OutputAnalyzer o = new OutputAnalyzer(pb.start());
+            o.shouldHaveExitValue(0);
+        }
+    };
+}
--- a/hotspot/test/runtime/NMT/CheckForProperDetailStackTrace.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/NMT/CheckForProperDetailStackTrace.java	Fri Sep 30 09:28:18 2016 -0700
@@ -57,11 +57,6 @@
     private static String expectedSymbol =
         "locked_create_entry_or_null";
 
-    private static final String jdkDebug = System.getProperty("jdk.debug");
-    private static boolean isSlowDebugBuild() {
-        return (jdkDebug.toLowerCase().equals("slowdebug"));
-    }
-
     public static void main(String args[]) throws Exception {
         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
             "-XX:+UnlockDiagnosticVMOptions",
@@ -76,11 +71,12 @@
         output.shouldNotContain("NativeCallStack::NativeCallStack");
         output.shouldNotContain("os::get_native_stack");
 
-        // AllocateHeap shouldn't be in the output because it is suppose to always be inlined.
-        // We check for that here, but allow it for Windows and Solaris slowdebug builds because
-        // the compiler ends up not inlining AllocateHeap.
+        // AllocateHeap shouldn't be in the output because it is supposed to always be inlined.
+        // We check for that here, but allow it for Aix, Solaris and Windows slowdebug builds
+        // because the compiler ends up not inlining AllocateHeap.
         Boolean okToHaveAllocateHeap =
-            isSlowDebugBuild() && (Platform.isSolaris() || Platform.isWindows());
+            Platform.isSlowDebugBuild() &&
+            (Platform.isAix() || Platform.isSolaris() || Platform.isWindows());
         if (!okToHaveAllocateHeap) {
             output.shouldNotContain("AllocateHeap");
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/Thread/TooSmallStackSize.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,198 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8140520
+ * @summary Setting small CompilerThreadStackSize, ThreadStackSize, and
+ * VMThreadStackSize values should result in an error message that shows
+ * the minimum stack size value for each thread type.
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ *          java.management
+ * @run main TooSmallStackSize
+ */
+
+/*
+ * The primary purpose of this test is to make sure we can run with a
+ * stack smaller than the minimum without crashing. Also this test will
+ * determine the minimum allowed stack size for the platform (as
+ * provided by the JVM error message when a very small stack is used),
+ * and then verify that the JVM can be launched with that stack size
+ * without a crash or any error messages.
+ *
+ * Note: The '-Xss<size>' and '-XX:ThreadStackSize=<k-bytes>' options
+ * both control Java thread stack size. This repo's version of the test
+ * exercises the '-XX:ThreadStackSize' VM option. The jdk repo's version
+ * of the test exercises the '-Xss' option.
+ */
+
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+
+public class TooSmallStackSize {
+    /* for debugging. Normally false. */
+    static final boolean verbose = false;
+    static final String CompilerThreadStackSizeString = "CompilerThreadStackSize";
+    static final String ThreadStackSizeString = "Java thread stack size";
+    static final String VMThreadStackSizeString = "VMThreadStackSize";
+
+    /*
+     * Returns the minimum stack size this platform will allowed based on the
+     * contents of the error message the JVM outputs when too small of a
+     * stack size was used.
+     *
+     * The testOutput argument must contain the result of having already run
+     * the JVM with too small of a stack size.
+     */
+    static String getMinStackAllowed(String testOutput) {
+        /*
+         * The JVM output will contain in one of the lines:
+         *   "The CompilerThreadStackSize specified is too small. Specify at least 100k"
+         *   "The Java thread stack size specified is too small. Specify at least 100k"
+         *   "The VMThreadStackSize specified is too small. Specify at least 100k"
+         * Although the actual size will vary. We need to extract this size
+         * string from the output and return it.
+         */
+        String matchStr = "Specify at least ";
+        int match_idx = testOutput.indexOf(matchStr);
+        if (match_idx >= 0) {
+            int size_start_idx = match_idx + matchStr.length();
+            int k_start_idx = testOutput.indexOf("k", size_start_idx);
+            // don't include the 'k'; the caller will have to
+            // add it back as needed.
+            return testOutput.substring(size_start_idx, k_start_idx);
+        }
+
+        System.out.println("Expect='" + matchStr + "'");
+        System.out.println("Actual: " + testOutput);
+        System.out.println("FAILED: Could not get the stack size from the output");
+        throw new RuntimeException("test fails");
+    }
+
+    /*
+     * Run the JVM with the specified stack size.
+     *
+     * Returns the minimum allowed stack size gleaned from the error message,
+     * if there is an error message. Otherwise returns the stack size passed in.
+     */
+    static String checkStack(String stackOption, String optionMesg, String stackSize) throws Exception {
+        String min_stack_allowed;
+
+        System.out.println("*** Testing " + stackOption + stackSize);
+
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+            stackOption + stackSize,
+            // Uncomment the following to get log output
+            // that shows actual thread creation sizes.
+            // "-Xlog:os+thread",
+            "-version");
+
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+
+        if (verbose) {
+            System.out.println("stdout: " + output.getStdout());
+        }
+
+        if (output.getExitValue() == 0) {
+            // checkMinStackAllowed() is called with stackSize values
+            // that should be the minimum that works. This method,
+            // checkStack(), is called with stackSize values that
+            // should be too small and result in error messages.
+            // However, some platforms fix up a stackSize value that is
+            // too small into something that works so we have to allow
+            // for checkStack() calls that work.
+            System.out.println("PASSED: got exit_code == 0 with " + stackOption + stackSize);
+            min_stack_allowed = stackSize;
+        } else {
+            String expect = "The " + optionMesg + " specified is too small";
+            if (verbose) {
+                System.out.println("Expect='" + expect + "'");
+            }
+            output.shouldContain(expect);
+            min_stack_allowed = getMinStackAllowed(output.getStdout());
+
+            System.out.println("PASSED: got expected error message with " + stackOption + stackSize);
+        }
+
+        return min_stack_allowed;
+    }
+
+    /*
+     * Run the JVM with the minimum allowed stack size. This should always succeed.
+     */
+    static void checkMinStackAllowed(String stackOption, String optionMesg, String stackSize) throws Exception {
+        System.out.println("*** Testing " + stackOption + stackSize);
+
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+            stackOption + stackSize,
+            // Uncomment the following to get log output
+            // that shows actual thread creation sizes.
+            // "-Xlog:os+thread",
+            "-version");
+
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        output.shouldHaveExitValue(0);
+
+        System.out.println("PASSED: VM launched with " + stackOption + stackSize);
+    }
+
+    public static void main(String... args) throws Exception {
+        /*
+         * The result of a 16k stack size should be a quick exit with a complaint
+         * that the stack size is too small. However, for some win32 builds, the
+         * stack is always at least 64k, and this also sometimes is the minimum
+         * allowed size, so we won't see an error in this case.
+         *
+         * This test case will also produce a crash on some platforms if the fix
+         * for 6762191 is not yet in place.
+         */
+        checkStack("-XX:ThreadStackSize=", ThreadStackSizeString, "16");
+
+        /*
+         * Try with a 32k stack size, which is the size that the launcher will
+         * set to if you try setting to anything smaller. This should produce the same
+         * result as setting to 16k if the fix for 6762191 is in place.
+         */
+        String min_stack_allowed = checkStack("-XX:ThreadStackSize=", ThreadStackSizeString, "32");
+
+        /*
+         * Try again with a the minimum stack size that was given in the error message
+         */
+        checkMinStackAllowed("-XX:ThreadStackSize=", ThreadStackSizeString, min_stack_allowed);
+
+        /*
+         * Now redo the same tests with the compiler thread stack size:
+         */
+        checkStack("-XX:CompilerThreadStackSize=", CompilerThreadStackSizeString, "16");
+        min_stack_allowed = checkStack("-XX:CompilerThreadStackSize=", CompilerThreadStackSizeString, "32");
+        checkMinStackAllowed("-XX:CompilerThreadStackSize=", CompilerThreadStackSizeString, min_stack_allowed);
+
+        /*
+         * Now redo the same tests with the VM thread stack size:
+         */
+        checkStack("-XX:VMThreadStackSize=", VMThreadStackSizeString, "16");
+        min_stack_allowed = checkStack("-XX:VMThreadStackSize=", VMThreadStackSizeString, "32");
+        checkMinStackAllowed("-XX:VMThreadStackSize=", VMThreadStackSizeString, min_stack_allowed);
+    }
+}
--- a/hotspot/test/runtime/Unsafe/AllocateInstance.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/AllocateInstance.java	Fri Sep 30 09:28:18 2016 -0700
@@ -30,12 +30,11 @@
  * @run main AllocateInstance
  */
 
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class AllocateInstance {
-    static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
+    static final Unsafe UNSAFE = Unsafe.getUnsafe();
 
     class TestClass {
         public boolean calledConstructor = false;
--- a/hotspot/test/runtime/Unsafe/AllocateMemory.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/AllocateMemory.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,13 +31,12 @@
  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:MallocMaxTestWords=100m AllocateMemory
  */
 
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class AllocateMemory {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
 
         // Allocate a byte, write to the location and read back the value
         long address = unsafe.allocateMemory(1);
--- a/hotspot/test/runtime/Unsafe/CopyMemory.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/CopyMemory.java	Fri Sep 30 09:28:18 2016 -0700
@@ -30,14 +30,13 @@
  * @run main CopyMemory
  */
 
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class CopyMemory {
     final static int LENGTH = 8;
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         long src = unsafe.allocateMemory(LENGTH);
         long dst = unsafe.allocateMemory(LENGTH);
         assertNotEquals(src, 0L);
--- a/hotspot/test/runtime/Unsafe/DefineClass.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/DefineClass.java	Fri Sep 30 09:28:18 2016 -0700
@@ -34,13 +34,12 @@
 import java.security.ProtectionDomain;
 import java.io.InputStream;
 import jdk.test.lib.InMemoryJavaCompiler;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class DefineClass {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         TestClassLoader classloader = new TestClassLoader();
         ProtectionDomain pd = new ProtectionDomain(null, null);
 
--- a/hotspot/test/runtime/Unsafe/FieldOffset.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/FieldOffset.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,14 +31,13 @@
  */
 
 import java.lang.reflect.Field;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import java.lang.reflect.*;
 import static jdk.test.lib.Asserts.*;
 
 public class FieldOffset {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         Field[] fields = Test.class.getDeclaredFields();
 
         for (int i = 0; i < fields.length; i++) {
--- a/hotspot/test/runtime/Unsafe/GetField.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/GetField.java	Fri Sep 30 09:28:18 2016 -0700
@@ -30,14 +30,13 @@
  * @run main GetField
  */
 
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import java.lang.reflect.*;
 import static jdk.test.lib.Asserts.*;
 
 public class GetField {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         // Unsafe.INVALID_FIELD_OFFSET is a static final int field,
         // make sure getField returns the correct field
         Field field = Unsafe.class.getField("INVALID_FIELD_OFFSET");
--- a/hotspot/test/runtime/Unsafe/GetPutAddress.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/GetPutAddress.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,13 +31,12 @@
  */
 
 import jdk.test.lib.Platform;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class GetPutAddress {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         int addressSize = unsafe.addressSize();
         // Ensure the size returned from Unsafe.addressSize is correct
         assertEquals(unsafe.addressSize(), Platform.is32bit() ? 4 : 8);
--- a/hotspot/test/runtime/Unsafe/GetPutBoolean.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/GetPutBoolean.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,13 +31,12 @@
  */
 
 import java.lang.reflect.Field;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class GetPutBoolean {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         Test t = new Test();
         Field field = Test.class.getField("b1");
 
--- a/hotspot/test/runtime/Unsafe/GetPutByte.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/GetPutByte.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,13 +31,12 @@
  */
 
 import java.lang.reflect.Field;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class GetPutByte {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         Test t = new Test();
         Field field = Test.class.getField("b");
 
--- a/hotspot/test/runtime/Unsafe/GetPutChar.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/GetPutChar.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,13 +31,12 @@
  */
 
 import java.lang.reflect.Field;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class GetPutChar {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         Test t = new Test();
         Field field = Test.class.getField("c");
 
--- a/hotspot/test/runtime/Unsafe/GetPutDouble.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/GetPutDouble.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,13 +31,12 @@
  */
 
 import java.lang.reflect.Field;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class GetPutDouble {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         Test t = new Test();
         Field field = Test.class.getField("d");
 
--- a/hotspot/test/runtime/Unsafe/GetPutFloat.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/GetPutFloat.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,13 +31,12 @@
  */
 
 import java.lang.reflect.Field;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class GetPutFloat {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         Test t = new Test();
         Field field = Test.class.getField("f");
 
--- a/hotspot/test/runtime/Unsafe/GetPutInt.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/GetPutInt.java	Fri Sep 30 09:28:18 2016 -0700
@@ -30,13 +30,12 @@
  */
 
 import java.lang.reflect.Field;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class GetPutInt {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         Test t = new Test();
         Field field = Test.class.getField("i");
 
--- a/hotspot/test/runtime/Unsafe/GetPutLong.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/GetPutLong.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,13 +31,12 @@
  */
 
 import java.lang.reflect.Field;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class GetPutLong {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         Test t = new Test();
         Field field = Test.class.getField("l");
 
--- a/hotspot/test/runtime/Unsafe/GetPutObject.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/GetPutObject.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,13 +31,12 @@
  */
 
 import java.lang.reflect.Field;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class GetPutObject {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         Test t = new Test();
         Object o = new Object();
         Field field = Test.class.getField("o");
--- a/hotspot/test/runtime/Unsafe/GetPutShort.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/GetPutShort.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,13 +31,12 @@
  */
 
 import java.lang.reflect.Field;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class GetPutShort {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         Test t = new Test();
         Field field = Test.class.getField("s");
 
--- a/hotspot/test/runtime/Unsafe/GetUncompressedObject.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/GetUncompressedObject.java	Fri Sep 30 09:28:18 2016 -0700
@@ -30,13 +30,12 @@
 
 import static jdk.test.lib.Asserts.*;
 
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 
 public class GetUncompressedObject {
 
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
 
         // Allocate some memory and fill it with non-zero values.
         final int size = 32;
--- a/hotspot/test/runtime/Unsafe/NestedUnsafe.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/NestedUnsafe.java	Fri Sep 30 09:28:18 2016 -0700
@@ -35,7 +35,6 @@
 import java.io.InputStream;
 import java.lang.*;
 import jdk.test.lib.InMemoryJavaCompiler;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
@@ -50,7 +49,7 @@
         " } } ");
 
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
 
         Class klass = unsafe.defineAnonymousClass(NestedUnsafe.class, klassbuf, new Object[0]);
         unsafe.ensureClassInitialized(klass);
--- a/hotspot/test/runtime/Unsafe/PageSize.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/PageSize.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,13 +31,12 @@
  */
 
 import java.lang.reflect.Field;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class PageSize {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         int pageSize = unsafe.pageSize();
 
         for (int n = 1; n != 0; n <<= 1) {
--- a/hotspot/test/runtime/Unsafe/PrimitiveHostClass.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/PrimitiveHostClass.java	Fri Sep 30 09:28:18 2016 -0700
@@ -39,16 +39,7 @@
 
 public class PrimitiveHostClass {
 
-    static final Unsafe U;
-    static {
-        try {
-            Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
-            theUnsafe.setAccessible(true);
-            U = (Unsafe) theUnsafe.get(null);
-        } catch (Exception e) {
-            throw new AssertionError(e);
-        }
-    }
+    static final Unsafe U = Unsafe.getUnsafe();
 
     public static void testVMAnonymousClass(Class<?> hostClass) {
 
--- a/hotspot/test/runtime/Unsafe/RangeCheck.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/RangeCheck.java	Fri Sep 30 09:28:18 2016 -0700
@@ -33,7 +33,6 @@
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.Platform;
-import jdk.test.lib.unsafe.UnsafeHelper;
 
 import jdk.internal.misc.Unsafe;
 
@@ -60,7 +59,7 @@
 
     public static class DummyClassWithMainRangeCheck {
         public static void main(String args[]) throws Exception {
-            Unsafe unsafe = UnsafeHelper.getUnsafe();
+            Unsafe unsafe = Unsafe.getUnsafe();
             unsafe.getObject(new DummyClassWithMainRangeCheck(), Short.MAX_VALUE);
         }
     }
--- a/hotspot/test/runtime/Unsafe/Reallocate.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/Reallocate.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,13 +31,12 @@
  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:MallocMaxTestWords=100m Reallocate
  */
 
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class Reallocate {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
 
         long address = unsafe.allocateMemory(1);
         assertNotEquals(address, 0L);
--- a/hotspot/test/runtime/Unsafe/SetMemory.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/SetMemory.java	Fri Sep 30 09:28:18 2016 -0700
@@ -30,13 +30,12 @@
  * @run main SetMemory
  */
 
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class SetMemory {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         long address = unsafe.allocateMemory(1);
         assertNotEquals(address, 0L);
         unsafe.setMemory(address, 1, (byte)17);
--- a/hotspot/test/runtime/Unsafe/ThrowException.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/Unsafe/ThrowException.java	Fri Sep 30 09:28:18 2016 -0700
@@ -30,13 +30,12 @@
  * @run main ThrowException
  */
 
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.misc.Unsafe;
 import static jdk.test.lib.Asserts.*;
 
 public class ThrowException {
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
         try {
             unsafe.throwException(new TestException());
         } catch (Throwable t) {
--- a/hotspot/test/runtime/contended/Basic.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/contended/Basic.java	Fri Sep 30 09:28:18 2016 -0700
@@ -48,20 +48,11 @@
  */
 public class Basic {
 
-    private static final Unsafe U;
+    private static final Unsafe U = Unsafe.getUnsafe();
     private static int ADDRESS_SIZE;
     private static int HEADER_SIZE;
 
     static {
-        // steal Unsafe
-        try {
-            Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
-            unsafe.setAccessible(true);
-            U = (Unsafe) unsafe.get(null);
-        } catch (NoSuchFieldException | IllegalAccessException e) {
-            throw new IllegalStateException(e);
-        }
-
         // When running with CompressedOops on 64-bit platform, the address size
         // reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
         // Try to guess the reference field size with this naive trick.
--- a/hotspot/test/runtime/contended/DefaultValue.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/contended/DefaultValue.java	Fri Sep 30 09:28:18 2016 -0700
@@ -49,20 +49,11 @@
  */
 public class DefaultValue {
 
-    private static final Unsafe U;
+    private static final Unsafe U = Unsafe.getUnsafe();
     private static int ADDRESS_SIZE;
     private static int HEADER_SIZE;
 
     static {
-        // steal Unsafe
-        try {
-            Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
-            unsafe.setAccessible(true);
-            U = (Unsafe) unsafe.get(null);
-        } catch (NoSuchFieldException | IllegalAccessException e) {
-            throw new IllegalStateException(e);
-        }
-
         // When running with CompressedOops on 64-bit platform, the address size
         // reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
         // Try to guess the reference field size with this naive trick.
--- a/hotspot/test/runtime/contended/Inheritance1.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/contended/Inheritance1.java	Fri Sep 30 09:28:18 2016 -0700
@@ -49,20 +49,11 @@
  */
 public class Inheritance1 {
 
-    private static final Unsafe U;
+    private static final Unsafe U = Unsafe.getUnsafe();
     private static int ADDRESS_SIZE;
     private static int HEADER_SIZE;
 
     static {
-        // steal Unsafe
-        try {
-            Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
-            unsafe.setAccessible(true);
-            U = (Unsafe) unsafe.get(null);
-        } catch (NoSuchFieldException | IllegalAccessException e) {
-            throw new IllegalStateException(e);
-        }
-
         // When running with CompressedOops on 64-bit platform, the address size
         // reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
         // Try to guess the reference field size with this naive trick.
--- a/hotspot/test/runtime/defineAnonClass/NestedUnsafe.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/defineAnonClass/NestedUnsafe.java	Fri Sep 30 09:28:18 2016 -0700
@@ -39,7 +39,6 @@
 import java.lang.*;
 import jdk.test.lib.*;
 import jdk.internal.misc.Unsafe;
-import jdk.test.lib.unsafe.UnsafeHelper;
 
 
 // Test that an anonymous class in package 'p' cannot define its own anonymous class
@@ -54,7 +53,7 @@
         " } } ");
 
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
 
         // The anonymous class calls defineAnonymousClass creating a nested anonymous class.
         byte klassbuf2[] = InMemoryJavaCompiler.compile("p.TestClass2",
--- a/hotspot/test/runtime/defineAnonClass/NestedUnsafe2.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/defineAnonClass/NestedUnsafe2.java	Fri Sep 30 09:28:18 2016 -0700
@@ -39,7 +39,6 @@
 import java.lang.*;
 import jdk.test.lib.*;
 import jdk.internal.misc.Unsafe;
-import jdk.test.lib.unsafe.UnsafeHelper;
 
 
 // Test that an anonymous class that gets put in its host's package cannot define
@@ -54,7 +53,7 @@
         " } } ");
 
     public static void main(String args[]) throws Exception {
-        Unsafe unsafe = UnsafeHelper.getUnsafe();
+        Unsafe unsafe = Unsafe.getUnsafe();
 
         // The anonymous class calls defineAnonymousClass creating a nested anonymous class.
         byte klassbuf2[] = InMemoryJavaCompiler.compile("TestClass2",
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/jni/checked/TestCheckedJniExceptionCheck.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 8164086
+ * @summary regression tests for 8164086, verify correct warning from checked JNI
+ * @library /test/lib
+ * @modules java.management
+ * @run main/native TestCheckedJniExceptionCheck launch
+ */
+
+import java.util.List;
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+
+public class TestCheckedJniExceptionCheck {
+
+    static {
+        System.loadLibrary("TestCheckedJniExceptionCheck");
+    }
+
+    int callableMethodInvokeCount = 0;
+
+    static final String TEST_START           = "TEST STARTED";
+    static final String EXPECT_WARNING_START = "EXPECT_WARNING_START";
+    static final String EXPECT_WARNING_END   = "EXPECT_WARNING_END";
+
+    static final String JNI_CHECK_EXCEPTION = "WARNING in native method: JNI call made without checking exceptions when required to from";
+
+    static void printExpectWarningStart(int count) {
+        System.out.println(EXPECT_WARNING_START + " " + count);
+    }
+
+    static void printExpectWarningEnd() {
+        System.out.println(EXPECT_WARNING_END);
+    }
+
+    public TestCheckedJniExceptionCheck() {
+        initMethodIds("callableMethod", "()V",
+                      "callableNestedMethod", "(IZ)V");
+        System.out.println(TEST_START);
+    }
+
+    public void test() {
+        testSingleCallNoCheck();
+        testSingleCallCheck();
+        testSingleCallNoCheckMultipleTimes();
+
+        testMultipleCallsNoCheck();
+        testMultipleCallsCheck();
+
+        testNestedSingleCallsNoCheck();
+        testNestedSingleCallsCheck();
+        testNestedMultipleCallsNoCheck();
+        testNestedMultipleCallsCheck();
+    }
+
+    public void testSingleCallNoCheck() {
+        System.out.println("testSingleCallNoCheck start");
+        callJavaFromNative(1, false);
+        System.out.println("testSingleCallNoCheck end");
+    }
+
+    public void testSingleCallCheck() {
+        System.out.println("testSingleCallCheck start");
+        callJavaFromNative(1, true);
+        System.out.println("testSingleCallCheck end");
+    }
+
+    public void testSingleCallNoCheckMultipleTimes() {
+        System.out.println("testSingleCallNoCheckMultipleTimes start");
+        callJavaFromNative(1, false);
+        callJavaFromNative(1, false);
+        System.out.println("testSingleCallNoCheckMultipleTimes end");
+    }
+
+    public void testMultipleCallsNoCheck() {
+        System.out.println("testMultipleCallsNoCheck start");
+        printExpectWarningStart(1);
+        callJavaFromNative(2, false);
+        printExpectWarningEnd();
+        System.out.println("testMultipleCallsNoCheck end");
+    }
+
+    public void testMultipleCallsCheck() {
+        System.out.println("testMultipleCallsCheck start");
+        callJavaFromNative(2, true);
+        System.out.println("testMultipleCallsCheck end");
+    }
+
+    public void testNestedSingleCallsNoCheck() {
+        System.out.println("testNestedSingleCallsNoCheck start");
+        callNestedJavaFromNative(1, false);
+        System.out.println("testNestedSingleCallsNoCheck end");
+    }
+
+    public void testNestedSingleCallsCheck() {
+        System.out.println("testNestedSingleCallsCheck start");
+        callNestedJavaFromNative(1, true);
+        System.out.println("testNestedSingleCallsCheck end");
+    }
+
+    public void testNestedMultipleCallsNoCheck() {
+        System.out.println("testNestedMultipleCallsNoCheck start");
+        printExpectWarningStart(3);
+        callNestedJavaFromNative(2, false);
+        printExpectWarningEnd();
+        System.out.println("testNestedMultipleCallsNoCheck end");
+    }
+
+    public void testNestedMultipleCallsCheck() {
+        System.out.println("testNestedMultipleCallsCheck start");
+        callNestedJavaFromNative(2, true);
+        System.out.println("testNestedMultipleCallsCheck end");
+    }
+
+    public void callableMethod() {
+        callableMethodInvokeCount++;
+    }
+
+    public void callableNestedMethod(int nofCalls, boolean withExceptionChecks) {
+        callJavaFromNative(nofCalls, withExceptionChecks);
+    }
+
+    public native void callJavaFromNative(int nofCalls, boolean withExceptionChecks);
+
+    public native void callNestedJavaFromNative(int nofCalls, boolean withExceptionChecks);
+
+    private native void initMethodIds(String callableMethodName,
+                                      String callableMethodSig,
+                                      String callableNestedMethodName,
+                                      String callableNestedMethodSig);
+
+
+    // Check warnings appear where they should, with start/end statements in output...
+    static void checkOuputForCorrectWarnings(OutputAnalyzer oa) throws RuntimeException {
+        List<String> lines = oa.asLines();
+        int expectedWarnings = 0;
+        int warningCount = 0;
+        int lineNo = 0;
+        boolean testStartLine = false;
+        for (String line : lines) {
+            lineNo++;
+            if (!testStartLine) { // Skip any warning before the actual test itself
+                testStartLine = line.startsWith(TEST_START);
+                continue;
+            }
+            if (line.startsWith(JNI_CHECK_EXCEPTION)) {
+                if (expectedWarnings == 0) {
+                    oa.reportDiagnosticSummary();
+                    throw new RuntimeException("Unexpected warning at line " + lineNo);
+                }
+                warningCount++;
+                if (warningCount > expectedWarnings) {
+                    oa.reportDiagnosticSummary();
+                    throw new RuntimeException("Unexpected warning at line " + lineNo);
+                }
+            }
+            else if (line.startsWith(EXPECT_WARNING_START)) {
+                String countStr = line.substring(EXPECT_WARNING_START.length() + 1);
+                expectedWarnings = Integer.parseInt(countStr);
+            }
+            else if (line.startsWith(EXPECT_WARNING_END)) {
+                if (warningCount != expectedWarnings) {
+                    oa.reportDiagnosticSummary();
+                    throw new RuntimeException("Missing warning at line " + lineNo);
+                }
+                warningCount = 0;
+                expectedWarnings = 0;
+            }
+        }
+        /*
+        System.out.println("Output looks good...");
+        oa.reportDiagnosticSummary();
+        */
+    }
+
+    public static void main(String[] args) throws Throwable {
+        if (args == null || args.length == 0) {
+            new TestCheckedJniExceptionCheck().test();
+            return;
+        }
+
+        // launch and check output
+        checkOuputForCorrectWarnings(ProcessTools.executeTestJvm("-Xcheck:jni",
+                                                                  "TestCheckedJniExceptionCheck"));
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/jni/checked/libTestCheckedJniExceptionCheck.c	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <jni.h>
+
+static jmethodID _callable_method_id;
+static jmethodID _callable_nested_method_id;
+
+static void check_exceptions(JNIEnv *env) {
+  if ((*env)->ExceptionCheck(env)) {
+    (*env)->ExceptionDescribe(env);
+    (*env)->FatalError(env, "Unexpected Exception");
+  }
+}
+
+static jmethodID get_method_id(JNIEnv *env, jclass clz, jstring jname, jstring jsig) {
+  jmethodID mid;
+  const char *name, *sig;
+
+  name = (*env)->GetStringUTFChars(env, jname, NULL);
+  check_exceptions(env);
+
+  sig  = (*env)->GetStringUTFChars(env, jsig, NULL);
+  check_exceptions(env);
+
+  mid  = (*env)->GetMethodID(env, clz, name, sig);
+  check_exceptions(env);
+
+  (*env)->ReleaseStringUTFChars(env, jname, name);
+  (*env)->ReleaseStringUTFChars(env, jsig, sig);
+  return mid;
+}
+
+JNIEXPORT void JNICALL
+Java_TestCheckedJniExceptionCheck_initMethodIds(JNIEnv *env,
+                                                jobject obj,
+                                                jstring callable_method_name,
+                                                jstring callable_method_sig,
+                                                jstring callable_nested_method_name,
+                                                jstring callable_nested_method_sig) {
+  jclass clz = (*env)->GetObjectClass(env, obj);
+
+  _callable_method_id = get_method_id(env, clz,
+                                      callable_method_name,
+                                      callable_method_sig);
+
+  _callable_nested_method_id = get_method_id(env, clz,
+                                             callable_nested_method_name,
+                                             callable_nested_method_sig);
+}
+
+JNIEXPORT void JNICALL
+Java_TestCheckedJniExceptionCheck_callJavaFromNative(JNIEnv *env,
+                                                     jobject obj,
+                                                     jint nofCalls,
+                                                     jboolean checkExceptions) {
+  int i;
+  for (i = 0; i < nofCalls; i++) {
+    (*env)->CallVoidMethod(env, obj, _callable_method_id);
+    if (checkExceptions == JNI_TRUE) {
+      check_exceptions(env);
+    }
+  }
+}
+
+JNIEXPORT void JNICALL
+Java_TestCheckedJniExceptionCheck_callNestedJavaFromNative(JNIEnv *env,
+                                                           jobject obj,
+                                                           jint nofCalls,
+                                                           jboolean checkExceptions) {
+  int i;
+  for (i = 0; i < nofCalls; i++) {
+    (*env)->CallVoidMethod(env, obj, _callable_nested_method_id, nofCalls, checkExceptions);
+    if (checkExceptions == JNI_TRUE) {
+      check_exceptions(env);
+    }
+  }
+}
--- a/hotspot/test/runtime/modules/ModuleOptionsTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/runtime/modules/ModuleOptionsTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -24,8 +24,8 @@
 /*
  * @test
  * @bug 8136930
- * @summary Test that the VM only recognizes the last specified --add-modules
- *          and --list-modules options
+ * @summary Test that the VM only recognizes the last specified --list-modules
+ *          options but accumulates --add-module values.
  * @modules java.base/jdk.internal.misc
  * @library /test/lib
  */
@@ -38,14 +38,16 @@
 
     public static void main(String[] args) throws Exception {
 
-        // Test that last --add-modules is the only one recognized.  No exception
-        // should be thrown.
+        // Test that multiple --add-modules options are cumulative, not last one wins.
+        // An exception should be thrown because module i_dont_exist doesn't exist.
         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
             "--add-modules=i_dont_exist", "--add-modules=java.base", "-version");
         OutputAnalyzer output = new OutputAnalyzer(pb.start());
-        output.shouldHaveExitValue(0);
+        output.shouldContain("ResolutionException");
+        output.shouldContain("i_dont_exist");
+        output.shouldHaveExitValue(1);
 
-        // Test that last --limit-modules is the only one recognized.  No exception
+        // Test that the last --limit-modules is the only one recognized.  No exception
         // should be thrown.
         pb = ProcessTools.createJavaProcessBuilder(
             "--limit-modules=i_dont_exist", "--limit-modules=java.base", "-version");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/verifier/popTopTests/PopDupTop.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @bug 8149607
+ * @summary Throw VerifyError when popping a stack element of TOP
+ * @compile popDupSwapTests.jasm
+ * @run main/othervm -Xverify:all PopDupTop
+ */
+
+public class PopDupTop {
+
+    public static void testClass(String class_name, String msg) throws Throwable {
+        try {
+            Class newClass = Class.forName(class_name);
+            throw new RuntimeException("Expected VerifyError exception not thrown for " + msg);
+        } catch (java.lang.VerifyError e) {
+            if (!e.getMessage().contains("Bad type on operand stack")) {
+               throw new RuntimeException(
+                   "Unexpected VerifyError message for " + msg + ": " + e.getMessage());
+            }
+        }
+    }
+
+    public static void main(String args[]) throws Throwable {
+        System.out.println("Regression test for bug 8149607");
+
+        testClass("dup_x1", "dup_x1 of long,ref");
+        testClass("dup2toptop", "dup2 of top,top");
+        testClass("dup2longtop", "dup2 of long,top");
+        testClass("dup2_x1", "dup2_x1 long,ref,ref");
+        testClass("dup2_x2", "dup2_x2 top");
+        testClass("dup2_x2_long_refs", "dup2_x2 long,ref,ref,ref");
+        testClass("poptop", "pop of top");
+        testClass("poptoptop", "pop of top,top");
+        testClass("pop2toptop", "pop2 of top,top");
+        testClass("pop2longtop", "pop2 of long,top");
+        testClass("swaptoptop", "swap of top,top");
+        testClass("swapinttop", "swap of int,top");
+        testClass("swaptopint", "swap of top,int");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/verifier/popTopTests/popDupSwapTests.jasm	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+// Test that VerifyError is thrown if dup2_x1 tries to replace the filler slot
+// of a category 2 value.
+// The stack map is long,top,null,null.  The verifier should reject dup2_x1's
+// (form1) attempt to turn the stack map into long,top,null,null,null,null
+public class dup2_x1 version 51:0 {
+    public static Method run:"()V" stack 6 locals 0 {
+        lconst_0;
+        aconst_null;
+        aconst_null;
+        dup2_x1;
+        return;
+    }
+}
+
+
+public class dup2_x2 version 51:0 {
+    public static Method run:"()V" stack 6 locals 0 {
+        iconst_0;
+        lconst_0;
+        aconst_null;
+
+        stack_frame_type full;
+        stack_map int, bogus, bogus, null;
+        locals_map;
+
+        dup2_x2;
+        return;
+    }
+}
+
+
+// Test that VerifyError is thrown if dup2_x2 tries to replace the filler slot
+// of a category 2 value.
+// The stack map is long,top,null,null,null.  The verifier should reject dup2_x2's
+// (form 1) attempt to turn the stack map into long,top,null,null,null,top,null.
+public class dup2_x2_long_refs version 51:0 {
+    public static Method run:"()V" stack 6 locals 0 {
+        lconst_0;
+        aconst_null;
+        aconst_null;
+        aconst_null;
+        dup2_x2;
+        return;
+    }
+}
+
+
+// Test that VerifyError is thrown when dup2 is used to remove the upper
+// half of a category 2 type.
+public class dup2longtop version 51:0 {
+    public static Method main:"([Ljava/lang/String;)V" stack 5 locals 1 {
+        lconst_0;
+        iconst_0;
+        dup2;
+        return;
+    }
+}
+
+
+// Test that VerifyError is thrown when dup2 is used to remove top
+// because top may be the upper half of a category 2 type.
+public class dup2toptop version 51:0 {
+    public static Method main:"([Ljava/lang/String;)V" stack 5 locals 1 {
+        // here we have {long, top, null}
+        // EXECUTION: we have {long, null}
+        lconst_0;
+        aconst_null;
+
+        stack_frame_type full;
+        stack_map bogus, bogus, null;
+        locals_map bogus;
+
+        // VERIFIER: use form1 of dup2 - {top, top, null} -> {top, top, null, top, null}
+        // EXECUTION: have {long, null} - no applicable form of dup2 for such type state by JVMS ch. 6
+        dup2;
+
+        return;
+    }
+}
+
+
+// Test that VerifyError is thrown if dup_x1 tries to replace the filler slot
+// of a category 2 value.
+public class dup_x1 version 51:0 {
+    public static Method run:"()V" stack 6 locals 0 {
+        lconst_0;
+        aconst_null;
+        dup_x1;
+        return;
+    }
+}
+
+
+// Test that VerifyError is thrown when pop2 is used to remove top
+// because top may be the upper half of a category 2 type.
+public class pop2longtop version 51:0
+{
+
+    public Method regular:"()V" stack 6 locals 6
+    {
+        lconst_0;
+        iconst_0;
+        stack_frame_type full;
+        stack_map long, bogus;
+        locals_map;
+        pop2;
+        return;
+    }
+} // end Class pop2longtop
+
+
+
+// Test that VerifyError is thrown when pop2 is used to remove top, top
+// because either top may be the upper half of a category 2 type.
+public class pop2toptop version 51:0
+{
+
+    public Method regular:"()V" stack 6 locals 6
+    {
+        iconst_0;
+        iconst_0;
+        stack_frame_type full;
+        stack_map bogus, bogus;
+        locals_map;
+        pop2;
+        return;
+    }
+} // end Class pop2toptop
+
+
+
+// Test that VerifyError is thrown when pop is used to remove top
+// because top may be the upper half of a category 2 type.
+public class poptop version 51:0
+{
+
+    public Method regular:"()V" stack 2 locals 1
+    {
+        iconst_0;
+        stack_frame_type full;
+        stack_map bogus;
+        pop;
+        return;
+    }
+} // end Class poptop
+
+
+
+// Test that VerifyError is thrown when pop is used to remove top, top
+// because either top may be the upper half of a category 2 type.
+public class poptoptop version 51:0
+{
+
+    public Method regular:"()V" stack 2 locals 1
+    {
+        iconst_0;
+        iconst_0;
+        stack_frame_type full;
+        stack_map bogus, bogus;
+        pop;
+        return;
+    }
+} // end Class poptoptop
+
+
+
+// Test that VerifyError is thrown when swap is used to swap int, top
+// because top may be the lower half of a category 2 type.
+public class swapinttop version 51:0
+{
+
+    public Method regular:"()V" stack 6 locals 6
+    {
+        iconst_0;
+        iconst_0;
+        stack_frame_type full;
+        stack_map int, bogus;
+        locals_map;
+        swap;
+        return;
+    }
+} // end Class swapinttop
+
+
+
+// Test that VerifyError is thrown when swap is used to swap top, int
+// because top may be the upper half of a category 2 type.
+public class swaptopint version 51:0
+{
+
+    public Method regular:"()V" stack 6 locals 6
+    {
+        iconst_0;
+        iconst_0;
+        stack_frame_type full;
+        stack_map bogus, int;
+        locals_map;
+        swap;
+        return;
+    }
+} // end Class swaptopint
+
+
+
+// Test that VerifyError is thrown when swap is used to swap top, top
+// because either top may be the upper half of a category 2 type.
+public class swaptoptop version 51:0
+{
+
+    public Method regular:"()V" stack 6 locals 6
+    {
+        iconst_0;
+        iconst_0;
+        stack_frame_type full;
+        stack_map bogus, bogus;
+        locals_map;
+        swap;
+        return;
+    }
+} // end Class swaptoptop
--- a/hotspot/test/testlibrary/ctw/Makefile	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/testlibrary/ctw/Makefile	Fri Sep 30 09:28:18 2016 -0700
@@ -40,7 +40,7 @@
 JAVAC = $(JDK_HOME)/bin/javac
 JAR = $(JDK_HOME)/bin/jar
 
-SRC_FILES = $(shell find $(SRC_DIR) $(TESTLIBRARY_DIR)/share/classes -name '*.java')
+SRC_FILES = $(shell find $(SRC_DIR) $(TESTLIBRARY_DIR)/jdk/test/lib -name '*.java')
 WB_SRC_FILES = $(shell find $(TESTLIBRARY_DIR)/sun/hotspot -name '*.java')
 
 MAIN_CLASS = sun.hotspot.tools.ctw.CompileTheWorld
--- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/PathHandler.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/PathHandler.java	Fri Sep 30 09:28:18 2016 -0700
@@ -39,7 +39,7 @@
  * Concrete subclasses should implement method {@link #process()}.
  */
 public abstract class PathHandler {
-    private static final Unsafe UNSAFE = jdk.test.lib.unsafe.UnsafeHelper.getUnsafe();
+    private static final Unsafe UNSAFE = Unsafe.getUnsafe();
     private static final AtomicLong CLASS_COUNT = new AtomicLong(0L);
     private static volatile boolean CLASSES_LIMIT_REACHED = false;
     private static final Pattern JAR_IN_DIR_PATTERN
--- a/hotspot/test/testlibrary/jittester/Makefile	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/testlibrary/jittester/Makefile	Fri Sep 30 09:28:18 2016 -0700
@@ -56,7 +56,6 @@
 CLASSES_DIR = $(BUILD_DIR)/classes
 SRC_DIR = src
 TEST_DIR = test
-DRIVER_DIR = $(TESTBASE_DIR)/jdk/test/lib/jittester/jtreg
 MANIFEST = manifest.mf
 APPLICATION_ARGS += \
     --property-file $(PROPERTY_FILE) \
@@ -118,19 +117,18 @@
 	@rm filelist
 	@rm -rf $(CLASSES_DIR)
 
-copytestlibrary: $(DRIVER_DIR)
-	@cp -r src/jdk/test/lib/jittester/jtreg/*.java $(DRIVER_DIR)
+copytestlibrary: $(TESTBASE_DIR)/jdk/test/lib/jittester/jtreg
+	@cp -r src/jdk/test/lib/jittester/jtreg/*.java $(TESTBASE_DIR)/jdk/test/lib/jittester/jtreg
+	@cp -r $(TESTLIBRARY_SRC_DIR) $(TESTBASE_DIR)/jdk/test/
 
 testgroup: $(TESTBASE_DIR)
 	@echo 'jittester_all = \\' > $(TESTGROUP_FILE)
 	@echo '	/' >> $(TESTGROUP_FILE)
 	@echo '' >> $(TESTGROUP_FILE)
-	@echo 'main = \\' >> $(TESTGROUP_FILE)
-	@echo '	Test_0.java' >> $(TESTGROUP_FILE)
 
 testroot: $(TESTBASE_DIR)
 	@echo 'groups=TEST.groups' > $(TESTROOT_FILE)
 
-$(TESTBASE_DIR) $(DIST_DIR) $(DRIVER_DIR):
+$(TESTBASE_DIR) $(DIST_DIR) $(TESTBASE_DIR)/jdk/test/lib/jittester/jtreg:
 	$(shell if [ ! -d $@ ]; then mkdir -p $@; fi)
 
--- a/hotspot/test/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/hotspot/test/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java	Fri Sep 30 09:28:18 2016 -0700
@@ -50,8 +50,9 @@
         OS("isAix", "isLinux", "isOSX", "isSolaris", "isWindows"),
         VM_TYPE("isClient", "isServer", "isGraal", "isMinimal", "isZero", "isEmbedded"),
         MODE("isInt", "isMixed", "isComp"),
-        IGNORED("isDebugBuild", "shouldSAAttach",
-                "canPtraceAttachLinux", "canAttachOSX", "isTieredSupported");
+        IGNORED("isDebugBuild", "isFastDebugBuild", "isSlowDebugBuild",
+                "shouldSAAttach", "canPtraceAttachLinux", "canAttachOSX",
+                "isTieredSupported");
 
         public final List<String> methodNames;
 
--- a/jaxp/.hgtags	Thu Sep 29 11:13:42 2016 +0530
+++ b/jaxp/.hgtags	Fri Sep 30 09:28:18 2016 -0700
@@ -379,3 +379,4 @@
 1c6c21d87aa459d82425e1fddc9ce8647aebde34 jdk-9+134
 f695240370c77a25fed88225a392e7d530cb4d78 jdk-9+135
 f1eafcb0eb7182b937bc93f214d8cabd01ec4d59 jdk-9+136
+a8d5fe567ae72b4931040e59dd4478363f9004f5 jdk-9+137
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1033,12 +1033,12 @@
             staxInputSource = new StaxXMLInputSource(xmlInputSource, fISCreatedByResolver);
         }
 
-        if (staxInputSource == null) {
+        if (staxInputSource == null && fUseCatalog) {
             if (fCatalogFeatures == null) {
                 fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
             }
             fCatalogFile = fCatalogFeatures.get(Feature.FILES);
-            if (fUseCatalog && fCatalogFile != null) {
+            if (fCatalogFile != null) {
                 try {
                     if (fCatalogResolver == null) {
                         fCatalogResolver = CatalogManager.catalogResolver(fCatalogFeatures);
@@ -1133,12 +1133,12 @@
             xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
         }
 
-        if (xmlInputSource == null) {
+        if (xmlInputSource == null && fUseCatalog) {
             if (fCatalogFeatures == null) {
                 fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
             }
             fCatalogFile = fCatalogFeatures.get(Feature.FILES);
-            if (fUseCatalog && fCatalogFile != null) {
+            if (fCatalogFile != null) {
                 /*
                  since the method can be called from various processors, both
                  EntityResolver and URIResolver are used to attempt to find
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xinclude/XIncludeHandler.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xinclude/XIncludeHandler.java	Fri Sep 30 09:28:18 2016 -0700
@@ -34,6 +34,8 @@
 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
 import com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException;
 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
+import com.sun.org.apache.xerces.internal.parsers.XIncludeParserConfiguration;
+import com.sun.org.apache.xerces.internal.parsers.XPointerParserConfiguration;
 import com.sun.org.apache.xerces.internal.util.AugmentationsImpl;
 import com.sun.org.apache.xerces.internal.util.HTTPInputSource;
 import com.sun.org.apache.xerces.internal.util.IntStack;
@@ -129,8 +131,6 @@
 public class XIncludeHandler
     implements XMLComponent, XMLDocumentFilter, XMLDTDFilter {
 
-    public final static String XINCLUDE_DEFAULT_CONFIGURATION =
-        "com.sun.org.apache.xerces.internal.parsers.XIncludeParserConfiguration";
     public final static String HTTP_ACCEPT = "Accept";
     public final static String HTTP_ACCEPT_LANGUAGE = "Accept-Language";
     public final static String XPOINTER = "xpointer";
@@ -1624,12 +1624,12 @@
                 includedSource =
                     fEntityResolver.resolveEntity(resourceIdentifier);
 
-                if (includedSource == null) {
+                if (includedSource == null && fUseCatalog) {
                     if (fCatalogFeatures == null) {
                         fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
                     }
                     fCatalogFile = fCatalogFeatures.get(CatalogFeatures.Feature.FILES);
-                    if (fUseCatalog && fCatalogFile != null) {
+                    if (fCatalogFile != null) {
                         /*
                            Although URI entry is preferred for resolving XInclude, system entry
                            is allowed as well.
@@ -1690,14 +1690,11 @@
             if ((xpointer != null && fXPointerChildConfig == null)
                         || (xpointer == null && fXIncludeChildConfig == null) ) {
 
-                String parserName = XINCLUDE_DEFAULT_CONFIGURATION;
-                if (xpointer != null)
-                        parserName = "com.sun.org.apache.xerces.internal.parsers.XPointerParserConfiguration";
-
-                fChildConfig =
-                    (XMLParserConfiguration)ObjectFactory.newInstance(
-                        parserName,
-                        true);
+                if (xpointer == null) {
+                    fChildConfig = new XIncludeParserConfiguration();
+                } else {
+                    fChildConfig = new XPointerParserConfiguration();
+                }
 
                 // use the same symbol table, error reporter, entity resolver, security manager and buffer size.
                 if (fSymbolTable != null) fChildConfig.setProperty(SYMBOL_TABLE, fSymbolTable);
--- a/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupport.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupport.java	Fri Sep 30 09:28:18 2016 -0700
@@ -32,7 +32,6 @@
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stax.StAXSource;
 import javax.xml.transform.stream.StreamSource;
-
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Listeners;
@@ -42,7 +41,7 @@
 
 /**
  * @test
- * @bug 8158084 8162438 8162442 8166220
+ * @bug 8158084 8162438 8162442 8166220 8166398
  * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
  * @run testng/othervm -DrunSecMngr=true catalog.CatalogSupport
  * @run testng/othervm catalog.CatalogSupport
@@ -51,7 +50,7 @@
  * A custom resolver is used whether or not there's a Catalog;
  * A Catalog is used when there's no custom resolver, and the USE_CATALOG
  * is true (which is the case by default).
- */
+*/
 
 /**
  * Support Catalog:
@@ -177,13 +176,13 @@
      */
     @DataProvider(name = "data_SAXA")
     public Object[][] getDataSAX() {
-        String[] systemIds = {"system.xsd"};
-        InputSource[] returnValues = {new InputSource(new StringReader(dtd_systemResolved))};
-        MyEntityHandler entityHandler = new MyEntityHandler(systemIds, returnValues, elementInSystem);
+        String[] systemIds = {"system.dtd"};
         return new Object[][]{
             {false, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog},
-            {false, true, xml_catalog, xml_system, entityHandler, expectedWResolver},
-            {true, true, xml_catalog, xml_system, entityHandler, expectedWResolver}
+            {false, true, xml_catalog, xml_system, getMyEntityHandler(elementInSystem, systemIds,
+                    new InputSource(new StringReader(dtd_systemResolved))), expectedWResolver},
+            {true, true, xml_catalog, xml_system, getMyEntityHandler(elementInSystem, systemIds,
+                    new InputSource(new StringReader(dtd_systemResolved))), expectedWResolver}
         };
     }
 
@@ -209,7 +208,7 @@
      */
     @DataProvider(name = "data_DOMA")
     public Object[][] getDataDOM() {
-        String[] systemIds = {"system.xsd"};
+        String[] systemIds = {"system.dtd"};
         InputSource[] returnValues = {new InputSource(new StringReader(dtd_systemResolved))};
         MyEntityHandler entityHandler = new MyEntityHandler(systemIds, returnValues, elementInSystem);
         return new Object[][]{
@@ -230,8 +229,8 @@
 
         return new Object[][]{
             {false, true, xml_catalog, xml_system, null, expectedWCatalog},
-            {false, true, xml_catalog, xml_system, null, expectedWResolver},
-            {true, true, xml_catalog, xml_system, null, expectedWResolver}
+            {false, true, xml_catalog, xml_system, new MyStaxEntityResolver(), expectedWResolver},
+            {true, true, xml_catalog, xml_system, new MyStaxEntityResolver(), expectedWResolver}
         };
     }
 
--- a/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupport.xml	Thu Sep 29 11:13:42 2016 +0530
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupport.xml	Fri Sep 30 09:28:18 2016 -0700
@@ -15,6 +15,7 @@
     <system systemId="XI_utf8.xml" uri="XI_utf8.xml"/>
     <system systemId="XI_utf8Catalog.xml" uri="XI_utf8Catalog.xml"/>
     <system systemId="XI_test2.xml" uri="XI_test2.xml"/>
+    <system systemId="XI_test2Catalog.xml" uri="XI_test2Catalog.xml"/>
     <system systemId="XI_red.dtd" uri="XI_red.dtd"/>
 
     <!-- xsd import can be mapped using the namespace or systemId -->
--- a/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupportBase.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupportBase.java	Fri Sep 30 09:28:18 2016 -0700
@@ -276,7 +276,7 @@
         SAXParser parser = getSAXParser(setUseCatalog, useCatalog, catalog);
 
         parser.parse(xml, handler);
-        assertEquals(expected, handler.getResult().trim(), "");
+        Assert.assertEquals(handler.getResult().trim(), expected);
     }
 
     /*
@@ -287,8 +287,9 @@
         XMLReader reader = getXMLReader(setUseCatalog, useCatalog, catalog);
 
         reader.setContentHandler(handler);
+        reader.setEntityResolver(handler);
         reader.parse(xml);
-        assertEquals(expected, handler.getResult().trim(), "");
+        Assert.assertEquals(handler.getResult().trim(), expected);
     }
 
     /*
@@ -300,7 +301,7 @@
 
         parser.parse(new InputSource(new StringReader(xml)), handler);
         debugPrint("handler.result:" + handler.getResult());
-        assertEquals(expected, handler.getResult(), "Catalog support for XInclude");
+        Assert.assertEquals(handler.getResult().trim(), expected);
     }
 
     /*
@@ -314,8 +315,7 @@
 
         Node node = doc.getElementsByTagName(elementInSystem).item(0);
         String result = node.getFirstChild().getTextContent();
-
-        assertEquals(expected, result.trim(), "Catalog support for DOM");
+        Assert.assertEquals(result.trim(), expected);
     }
 
     /*
@@ -327,7 +327,7 @@
             XMLStreamReader streamReader = getStreamReader(
                     setUseCatalog, useCatalog, catalog, xml, resolver);
             String text = getText(streamReader, XMLStreamConstants.CHARACTERS);
-            assertEquals(expected, text.trim(), "Catalog support for StAX");
+            Assert.assertEquals(text.trim(), expected);
     }
 
     /*
@@ -340,7 +340,7 @@
             XMLStreamReader streamReader = getStreamReader(
                     setUseCatalog, useCatalog, catalog, xml, resolver);
             String text = getText(streamReader, XMLStreamConstants.ENTITY_REFERENCE);
-            assertEquals(expected, text.trim(), "Catalog support for StAX");
+            Assert.assertEquals(text.trim(), expected);
     }
 
     /*
@@ -601,9 +601,11 @@
     }
 
     /**
-     * Returns the text of the first element found by the reader.
+     * Returns the accumulated text of an event type.
+     *
      * @param streamReader the XMLStreamReader
-     * @return the text of the first element
+     * @param type the type of event requested
+     * @return the text of the accumulated text for the request type
      * @throws XMLStreamException
      */
     String getText(XMLStreamReader streamReader, int type) throws XMLStreamException {
@@ -662,24 +664,6 @@
         return factory;
     }
 
-    void assertNotNull(Object obj, String msg) {
-        if (obj == null) {
-            debugPrint("Test failed: " + msg);
-        } else {
-            debugPrint("Test passed: " + obj + " is not null");
-        }
-    }
-
-    void assertEquals(String expected, String actual, String msg) {
-        if (!expected.equals(actual)) {
-            debugPrint("Test failed: " + msg);
-        } else {
-            debugPrint("Test passed: ");
-        }
-        debugPrint("Expected: " + expected);
-        debugPrint("Actual: " + actual);
-    }
-
     void fail(String msg) {
         System.out.println("Test failed:");
         System.out.println(msg);
--- a/jaxp/test/javax/xml/jaxp/unittest/catalog/XI_simple4Catalog.xml	Thu Sep 29 11:13:42 2016 +0530
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/XI_simple4Catalog.xml	Fri Sep 30 09:28:18 2016 -0700
@@ -9,7 +9,7 @@
     </another>
   </latin1>
   <test2>
-    <xinclude:include href="XI_test2.xml"/>
+    <xinclude:include href="XI_test2Catalog.xml"/>
   </test2>
   <test3>
    <!-- <xinclude:include href="XI_roottest.xml"/> -->
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/XI_test2Catalog.xml	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<!-- comment before root -->
+<!DOCTYPE red SYSTEM "XI_red.dtd">
+<red xmlns:xinclude="http://www.w3.org/2001/XInclude">
+  <blue>
+    <xinclude:include href="XI_utf8Catalog.xml" parse="text"/>
+  </blue>
+</red>
+<!-- comment after root -->
+
--- a/jaxws/.hgtags	Thu Sep 29 11:13:42 2016 +0530
+++ b/jaxws/.hgtags	Fri Sep 30 09:28:18 2016 -0700
@@ -382,3 +382,4 @@
 ab1d78d395d4cb8be426ff181211da1a4085cf01 jdk-9+134
 22631824f55128a7ab6605493b3001a37af6a168 jdk-9+135
 09ec13a99f50a4a346180d1e3b0fd8bc1ee399ce jdk-9+136
+297c16d401c534cb879809d2a746d21ca99d2954 jdk-9+137
--- a/jdk/.hgtags	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/.hgtags	Fri Sep 30 09:28:18 2016 -0700
@@ -379,3 +379,5 @@
 803adcd526d74ae0b64948d1f8260c2dbe514779 jdk-9+134
 021369229cfd0b5feb76834b2ea498f47f43c0f3 jdk-9+135
 54c5931849a33a363e03fdffa141503f5cc4779d jdk-9+136
+e72df94364e3686e7d62059ce0d6b187b82da713 jdk-9+137
+665096863382bf23ce891307cf2a7511e77c1c88 jdk-9+138
--- a/jdk/make/launcher/Launcher-java.desktop.gmk	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/make/launcher/Launcher-java.desktop.gmk	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -28,7 +28,7 @@
 # Hook to include the corresponding custom file, if present.
 $(eval $(call IncludeCustomExtension, jdk, launcher/Launcher-java.desktop.gmk))
 
-ifndef BUILD_HEADLESS_ONLY
+ifeq ($(ENABLE_HEADLESS_ONLY), false)
   $(eval $(call SetupBuildLauncher, appletviewer, \
       MAIN_CLASS := sun.applet.Main, \
       JAVA_ARGS := --add-modules ALL-DEFAULT, \
--- a/jdk/make/launcher/Launcher-jdk.policytool.gmk	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/make/launcher/Launcher-jdk.policytool.gmk	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
 
 include LauncherCommon.gmk
 
-ifndef BUILD_HEADLESS_ONLY
+ifeq ($(ENABLE_HEADLESS_ONLY), false)
   $(eval $(call SetupBuildLauncher, policytool, \
       MAIN_CLASS := sun.security.tools.policytool.PolicyTool, \
       LIBS_unix := $(X_LIBS), \
--- a/jdk/make/lib/Awt2dLibraries.gmk	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/make/lib/Awt2dLibraries.gmk	Fri Sep 30 09:28:18 2016 -0700
@@ -280,7 +280,7 @@
 ################################################################################
 
 ifeq ($(findstring $(OPENJDK_TARGET_OS),windows macosx),)
-  ifndef BUILD_HEADLESS_ONLY
+  ifeq ($(ENABLE_HEADLESS_ONLY), false)
 
     LIBAWT_XAWT_DIRS := \
         $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libawt_xawt \
@@ -511,77 +511,75 @@
 
 ################################################################################
 
-ifeq ($(BUILD_HEADLESS), true)
-  # Mac and Windows only use the native AWT lib, do not build libawt_headless
-  ifeq ($(findstring $(OPENJDK_TARGET_OS), windows macosx),)
+# Mac and Windows only use the native AWT lib, do not build libawt_headless
+ifeq ($(findstring $(OPENJDK_TARGET_OS), windows macosx),)
 
-    LIBAWT_HEADLESS_DIRS := $(JDK_TOPDIR)/src/java.desktop/unix/native/libawt_headless/awt \
-        $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt \
-        $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/java2d/opengl \
-        $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/java2d/x11 \
-        $(JDK_TOPDIR)/src/java.desktop/share/native/common/java2d/opengl \
-        $(JDK_TOPDIR)/src/java.desktop/share/native/common/font \
-        #
+  LIBAWT_HEADLESS_DIRS := $(JDK_TOPDIR)/src/java.desktop/unix/native/libawt_headless/awt \
+      $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt \
+      $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/java2d/opengl \
+      $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/java2d/x11 \
+      $(JDK_TOPDIR)/src/java.desktop/share/native/common/java2d/opengl \
+      $(JDK_TOPDIR)/src/java.desktop/share/native/common/font \
+      #
 
-    LIBAWT_HEADLESS_EXCLUDES := medialib
-    LIBAWT_HEADLESS_CFLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
-        $(addprefix -I, $(LIBAWT_HEADLESS_DIRS)) \
-        -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/java2d \
-        -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/java2d/loops \
-        -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/awt/image/cvutils \
-        -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/java2d/pipe \
-        -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/awt/image \
-        -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libawt/java2d \
-        -I$(JDK_TOPDIR)/src/java.desktop/share/native/common/font \
-        -I$(JDK_TOPDIR)/src/java.desktop/share/native/common/awt/debug \
-        -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/font \
-        -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libsunwjdga/ \
-        $(LIBJAVA_HEADER_FLAGS) \
-        #
+  LIBAWT_HEADLESS_EXCLUDES := medialib
+  LIBAWT_HEADLESS_CFLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
+      $(addprefix -I, $(LIBAWT_HEADLESS_DIRS)) \
+      -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/java2d \
+      -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/java2d/loops \
+      -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/awt/image/cvutils \
+      -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/java2d/pipe \
+      -I$(JDK_TOPDIR)/src/java.desktop/share/native/libawt/awt/image \
+      -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libawt/java2d \
+      -I$(JDK_TOPDIR)/src/java.desktop/share/native/common/font \
+      -I$(JDK_TOPDIR)/src/java.desktop/share/native/common/awt/debug \
+      -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/font \
+      -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libsunwjdga/ \
+      $(LIBJAVA_HEADER_FLAGS) \
+      #
 
-    LIBAWT_HEADLESS_REORDER :=
-    ifeq ($(OPENJDK_TARGET_OS), solaris)
-      ifneq ($(OPENJDK_TARGET_CPU), x86_64)
-        LIBAWT_HEADLESS_REORDER := $(JDK_TOPDIR)/make/mapfiles/libawt_headless/reorder-$(OPENJDK_TARGET_CPU)
-      endif
+  LIBAWT_HEADLESS_REORDER :=
+  ifeq ($(OPENJDK_TARGET_OS), solaris)
+    ifneq ($(OPENJDK_TARGET_CPU), x86_64)
+      LIBAWT_HEADLESS_REORDER := $(JDK_TOPDIR)/make/mapfiles/libawt_headless/reorder-$(OPENJDK_TARGET_CPU)
     endif
+  endif
 
-    $(eval $(call SetupNativeCompilation,BUILD_LIBAWT_HEADLESS, \
-        LIBRARY := awt_headless, \
-        OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
-        SRC := $(LIBAWT_HEADLESS_DIRS), \
-        EXCLUDES := $(LIBAWT_HEADLESS_EXCLUDES), \
-        OPTIMIZATION := LOW, \
-        CFLAGS := $(CFLAGS_JDKLIB) \
-            -DHEADLESS=true \
-            -DPACKAGE_PATH=\"$(PACKAGE_PATH)\" \
-            $(CUPS_CFLAGS) \
-            $(X_CFLAGS) \
-            $(LIBAWT_HEADLESS_CFLAGS), \
-        DISABLED_WARNINGS_xlc := 1506-356, \
-        DISABLED_WARNINGS_solstudio := E_EMPTY_TRANSLATION_UNIT, \
-        MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libawt_headless/mapfile-vers, \
-        LDFLAGS := $(LDFLAGS_JDKLIB) \
-            $(call SET_SHARED_LIBRARY_ORIGIN), \
-        LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \
-        LDFLAGS_linux := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \
-        LDFLAGS_solaris := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \
-        REORDER := $(LIBAWT_HEADLESS_REORDER), \
-        LIBS_unix := -lawt -ljvm -ljava, \
-        LIBS_linux := $(LIBM) $(LIBDL), \
-        LIBS_solaris := $(LIBM) $(LIBDL) $(LIBCXX) -lc, \
-        OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libawt_headless, \
-    ))
+  $(eval $(call SetupNativeCompilation,BUILD_LIBAWT_HEADLESS, \
+      LIBRARY := awt_headless, \
+      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
+      SRC := $(LIBAWT_HEADLESS_DIRS), \
+      EXCLUDES := $(LIBAWT_HEADLESS_EXCLUDES), \
+      OPTIMIZATION := LOW, \
+      CFLAGS := $(CFLAGS_JDKLIB) \
+          -DHEADLESS=true \
+          -DPACKAGE_PATH=\"$(PACKAGE_PATH)\" \
+          $(CUPS_CFLAGS) \
+          $(X_CFLAGS) \
+          $(LIBAWT_HEADLESS_CFLAGS), \
+      DISABLED_WARNINGS_xlc := 1506-356, \
+      DISABLED_WARNINGS_solstudio := E_EMPTY_TRANSLATION_UNIT, \
+      MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libawt_headless/mapfile-vers, \
+      LDFLAGS := $(LDFLAGS_JDKLIB) \
+          $(call SET_SHARED_LIBRARY_ORIGIN), \
+      LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \
+      LDFLAGS_linux := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \
+      LDFLAGS_solaris := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \
+      REORDER := $(LIBAWT_HEADLESS_REORDER), \
+      LIBS_unix := -lawt -ljvm -ljava, \
+      LIBS_linux := $(LIBM) $(LIBDL), \
+      LIBS_solaris := $(LIBM) $(LIBDL) $(LIBCXX) -lc, \
+      OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libawt_headless, \
+  ))
 
-    # AIX warning explanation:
-    # 1506-356 : (W) Compilation unit is empty.
-    #            This happens during the headless build
+  # AIX warning explanation:
+  # 1506-356 : (W) Compilation unit is empty.
+  #            This happens during the headless build
 
-    $(BUILD_LIBAWT_HEADLESS): $(BUILD_LIBAWT)
+  $(BUILD_LIBAWT_HEADLESS): $(BUILD_LIBAWT)
 
-    TARGETS += $(BUILD_LIBAWT_HEADLESS)
+  TARGETS += $(BUILD_LIBAWT_HEADLESS)
 
-  endif
 endif
 
 ################################################################################
@@ -780,7 +778,7 @@
     ifneq ($(OPENJDK_TARGET_OS), solaris)
       JAWT_LIBS += -lawt
     endif
-    ifndef BUILD_HEADLESS_ONLY
+    ifeq ($(ENABLE_HEADLESS_ONLY), false)
       JAWT_LIBS += -lawt_xawt
     else
       JAWT_LIBS += -lawt_headless
@@ -809,7 +807,7 @@
       OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjawt, \
   ))
 
-  ifndef BUILD_HEADLESS_ONLY
+  ifeq ($(ENABLE_HEADLESS_ONLY), false)
     $(BUILD_LIBJAWT): $(BUILD_LIBAWT_XAWT)
   else
     $(BUILD_LIBJAWT): $(INSTALL_LIBRARIES_HERE)/$(LIBRARY_PREFIX)awt_headless$(SHARED_LIBRARY_SUFFIX)
@@ -825,7 +823,7 @@
 
 ################################################################################
 
-ifndef BUILD_HEADLESS_ONLY
+ifeq ($(ENABLE_HEADLESS_ONLY), false)
 
   LIBSPLASHSCREEN_DIRS := \
       $(JDK_TOPDIR)/src/java.desktop/share/native/libjavajpeg \
--- a/jdk/make/lib/CoreLibraries.gmk	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/make/lib/CoreLibraries.gmk	Fri Sep 30 09:28:18 2016 -0700
@@ -236,10 +236,6 @@
 
 ##########################################################################################
 
-ifeq ($(OPENJDK_TARGET_OS), aix)
-  LIBJIMAGE_TOOLCHAIN := TOOLCHAIN_LINK_CXX
-endif # OPENJDK_TARGET_OS aix
-
 JIMAGELIB_CPPFLAGS := \
     -I$(JDK_TOPDIR)/src/java.base/share/native/libjava \
     -I$(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjava \
@@ -249,7 +245,7 @@
 
 $(eval $(call SetupNativeCompilation,BUILD_LIBJIMAGE, \
     LIBRARY := jimage, \
-    TOOLCHAIN := $(LIBJIMAGE_TOOLCHAIN), \
+    TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
     OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
     OPTIMIZATION := LOW, \
     SRC := $(JDK_TOPDIR)/src/java.base/share/native/libjimage \
--- a/jdk/make/lib/NioLibraries.gmk	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/make/lib/NioLibraries.gmk	Fri Sep 30 09:28:18 2016 -0700
@@ -53,12 +53,7 @@
 endif
 
 ifeq ($(OPENJDK_TARGET_OS), aix)
-  BUILD_LIBNIO_MAPFILE:=$(JDK_TOPDIR)/make/mapfiles/libnio/mapfile-$(OPENJDK_TARGET_OS)
-  BUILD_LIBNIO_EXFILES += \
-      /NativeThread.c
-  # Notice: we really need the leading slash here because otherwise every
-  # FILE_NAME in EXCLUDE_FILES will actually match any file ending in FILE_NAME
-  # (e.g. 'NativeThread.c' will also exclude 'AixNativeThread.c').
+  BUILD_LIBNIO_MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libnio/mapfile-$(OPENJDK_TARGET_OS)
 endif
 
 $(eval $(call SetupNativeCompilation,BUILD_LIBNIO, \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/aix/native/libjli/java_md_aix.c	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2016 SAP SE. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include <stdio.h>
+#include <sys/ldr.h>
+
+#include "java_md_aix.h"
+
+static unsigned char dladdr_buffer[0x4000];
+
+static int fill_dll_info(void) {
+    return loadquery(L_GETINFO, dladdr_buffer, sizeof(dladdr_buffer));
+}
+
+static int dladdr_dont_reload(void *addr, Dl_info *info) {
+    const struct ld_info *p = (struct ld_info *)dladdr_buffer;
+    memset((void *)info, 0, sizeof(Dl_info));
+    for (;;) {
+        if (addr >= p->ldinfo_textorg &&
+            addr < (((char*)p->ldinfo_textorg) + p->ldinfo_textsize))
+        {
+            info->dli_fname = p->ldinfo_filename;
+            return 1;
+        }
+        if (!p->ldinfo_next) {
+            break;
+        }
+        p = (struct ld_info *)(((char *)p) + p->ldinfo_next);
+    }
+    return 0;
+}
+
+int dladdr(void *addr, Dl_info *info) {
+    static int loaded = 0;
+    int rc = 0;
+    void *addr0;
+    if (!addr) {
+        return rc;
+    }
+    if (!loaded) {
+        if (fill_dll_info() == -1)
+            return rc;
+        loaded = 1;
+    }
+
+    // first try with addr on cached data
+    rc = dladdr_dont_reload(addr, info);
+
+    // addr could be an AIX function descriptor, so try dereferenced version
+    if (rc == 0) {
+        addr0 = *((void **)addr);
+        rc = dladdr_dont_reload(addr0, info);
+    }
+
+    // if we had no success until now, maybe loadquery info is outdated.
+    // refresh and retry
+    if (rc == 0) {
+        if (fill_dll_info() == -1)
+            return rc;
+        rc = dladdr_dont_reload(addr, info);
+        if (rc == 0) {
+            rc = dladdr_dont_reload(addr0, info);
+        }
+    }
+    return rc;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/aix/native/libjli/java_md_aix.h	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016 SAP SE. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef JAVA_MD_AIX_H
+#define JAVA_MD_AIX_H
+
+/*
+ * Very limited AIX port of dladdr() for libjli.so.
+ *
+ * We try to mimick dladdr(3) on Linux (see http://linux.die.net/man/3/dladdr)
+ * dladdr(3) is not POSIX but a GNU extension, and is not available on AIX.
+ *
+ * We only support Dl_info.dli_fname here as this is the only thing that is
+ * used of it by libjli.so. A more comprehensive port of dladdr can be found
+ * in the hotspot implementation which is not available at this place, though.
+ */
+
+typedef struct {
+  const char *dli_fname; /* file path of loaded library */
+  void *dli_fbase;       /* unsupported */
+  const char *dli_sname; /* unsupported */
+  void *dli_saddr;       /* unsupported */
+} Dl_info;
+
+int dladdr(void *addr, Dl_info *info);
+
+#endif /* JAVA_MD_AIX_H */
--- a/jdk/src/java.base/aix/native/libnio/ch/AixNativeThread.c	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#include <sys/types.h>
-#include <string.h>
-#include "jni.h"
-#include "jni_util.h"
-#include "jvm.h"
-#include "jlong.h"
-#include "sun_nio_ch_NativeThread.h"
-
-#include <pthread.h>
-#include <sys/signal.h>
-
-/* Also defined in src/aix/native/java/net/aix_close.c */
-#define INTERRUPT_SIGNAL (SIGRTMAX - 1)
-
-static void
-nullHandler(int sig)
-{
-}
-
-
-JNIEXPORT void JNICALL
-Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
-{
-    /* Install the null handler for INTERRUPT_SIGNAL. This might overwrite the
-     * handler previously installed by java/net/aix_close.c, but that's okay
-     * since neither handler actually does anything.  We install our own
-     * handler here simply out of paranoia; ultimately the two mechanisms
-     * should somehow be unified, perhaps within the VM.
-     */
-
-    sigset_t ss;
-    struct sigaction sa, osa;
-    sa.sa_handler = nullHandler;
-    sa.sa_flags = 0;
-    sigemptyset(&sa.sa_mask);
-    if (sigaction(INTERRUPT_SIGNAL, &sa, &osa) < 0)
-        JNU_ThrowIOExceptionWithLastError(env, "sigaction");
-}
-
-JNIEXPORT jlong JNICALL
-Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl)
-{
-    return (long)pthread_self();
-}
-
-JNIEXPORT void JNICALL
-Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread)
-{
-    if (pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL))
-        JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed");
-}
--- a/jdk/src/java.base/share/classes/java/lang/StackStreamFactory.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/lang/StackStreamFactory.java	Fri Sep 30 09:28:18 2016 -0700
@@ -71,6 +71,7 @@
     // These flags must match the values maintained in the VM
     @Native private static final int DEFAULT_MODE              = 0x0;
     @Native private static final int FILL_CLASS_REFS_ONLY      = 0x2;
+    @Native private static final int GET_CALLER_CLASS          = 0x4;
     @Native private static final int SHOW_HIDDEN_FRAMES        = 0x20;  // LambdaForms are hidden by the VM
     @Native private static final int FILL_LIVE_STACK_FRAMES    = 0x100;
     /*
@@ -614,9 +615,7 @@
         private Class<?> caller;
 
         CallerClassFinder(StackWalker walker) {
-            super(walker, FILL_CLASS_REFS_ONLY);
-            assert (mode & FILL_CLASS_REFS_ONLY) == FILL_CLASS_REFS_ONLY
-                   : "mode should contain FILL_CLASS_REFS_ONLY";
+            super(walker, FILL_CLASS_REFS_ONLY|GET_CALLER_CLASS);
         }
 
         final class ClassBuffer extends FrameBuffer<Class<?>> {
--- a/jdk/src/java.base/share/classes/java/lang/String.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/lang/String.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1516,11 +1516,12 @@
      * @return  a hash code value for this object.
      */
     public int hashCode() {
-        if (hash == 0 && value.length > 0) {
-            hash = isLatin1() ? StringLatin1.hashCode(value)
-                              : StringUTF16.hashCode(value);
+        int h = hash;
+        if (h == 0 && value.length > 0) {
+            hash = h = isLatin1() ? StringLatin1.hashCode(value)
+                                  : StringUTF16.hashCode(value);
         }
-        return hash;
+        return h;
     }
 
     /**
--- a/jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java	Fri Sep 30 09:28:18 2016 -0700
@@ -869,5 +869,4 @@
     static SpeciesData speciesData_LLL()    { return checkCache(3, "LLL"); }
     static SpeciesData speciesData_LLLL()   { return checkCache(4, "LLLL"); }
     static SpeciesData speciesData_LLLLL()  { return checkCache(5, "LLLLL"); }
-    static SpeciesData speciesData_LLLLLL() { return checkCache(6, "LLLLLL"); }
 }
--- a/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java	Fri Sep 30 09:28:18 2016 -0700
@@ -39,14 +39,14 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.lang.reflect.Modifier;
+import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.stream.Stream;
 
-import static java.lang.invoke.LambdaForm.*;
+import static java.lang.invoke.LambdaForm.BasicType;
 import static java.lang.invoke.LambdaForm.BasicType.*;
-import static java.lang.invoke.LambdaForm.Kind.*;
+import static java.lang.invoke.LambdaForm.*;
 import static java.lang.invoke.MethodHandleNatives.Constants.*;
 import static java.lang.invoke.MethodHandleStatics.*;
 
@@ -65,6 +65,9 @@
     private static final String OBJ     = "java/lang/Object";
     private static final String OBJARY  = "[Ljava/lang/Object;";
 
+    private static final String LOOP_CLAUSES = MHI + "$LoopClauses";
+    private static final String MHARY2       = "[[L" + MH + ";";
+
     private static final String LF_SIG  = "L" + LF + ";";
     private static final String LFN_SIG = "L" + LFN + ";";
     private static final String LL_SIG  = "(L" + OBJ + ";)L" + OBJ + ";";
@@ -1319,38 +1322,43 @@
      * The pattern looks like (Cf. MethodHandleImpl.loop):
      * <blockquote><pre>{@code
      * // a0: BMH
-     * // a1: inits, a2: steps, a3: preds, a4: finis
-     * // a5: box, a6: unbox
-     * // a7 (and following): arguments
-     * loop=Lambda(a0:L,a1:L,a2:L,a3:L,a4:L,a5:L,a6:L,a7:L)=>{
-     *   t8:L=MethodHandle.invokeBasic(a5:L,a7:L);                  // box the arguments into an Object[]
-     *   t9:L=MethodHandleImpl.loop(bt:L,a1:L,a2:L,a3:L,a4:L,t8:L); // call the loop executor (with supplied types in bt)
-     *   t10:L=MethodHandle.invokeBasic(a6:L,t9:L);t10:L}           // unbox the result; return the result
+     * // a1: LoopClauses (containing an array of arrays: inits, steps, preds, finis)
+     * // a2: box, a3: unbox
+     * // a4 (and following): arguments
+     * loop=Lambda(a0:L,a1:L,a2:L,a3:L,a4:L)=>{
+     *   t5:L=MethodHandle.invokeBasic(a2:L,a4:L);          // box the arguments into an Object[]
+     *   t6:L=MethodHandleImpl.loop(bt:L,a1:L,t5:L);        // call the loop executor (with supplied types in bt)
+     *   t7:L=MethodHandle.invokeBasic(a3:L,t6:L);t7:L}     // unbox the result; return the result
      * }</pre></blockquote>
      * <p>
      * It is compiled into bytecode equivalent to the code seen in {@link MethodHandleImpl#loop(BasicType[],
-     * MethodHandle[], MethodHandle[], MethodHandle[], MethodHandle[], Object...)}, with the difference that no arrays
+     * MethodHandleImpl.LoopClauses, Object...)}, with the difference that no arrays
      * will be used for local state storage. Instead, the local state will be mapped to actual stack slots.
      * <p>
      * Bytecode generation applies an unrolling scheme to enable better bytecode generation regarding local state type
      * handling. The generated bytecode will have the following form ({@code void} types are ignored for convenience).
      * Assume there are {@code C} clauses in the loop.
      * <blockquote><pre>{@code
-     * INIT: (INIT_SEQ for clause 1)
-     *       ...
-     *       (INIT_SEQ for clause C)
-     * LOOP: (LOOP_SEQ for clause 1)
-     *       ...
-     *       (LOOP_SEQ for clause C)
-     *       GOTO LOOP
-     * DONE: ...
+     * PREINIT: ALOAD_1
+     *          CHECKCAST LoopClauses
+     *          GETFIELD LoopClauses.clauses
+     *          ASTORE clauseDataIndex          // place the clauses 2-dimensional array on the stack
+     * INIT:    (INIT_SEQ for clause 1)
+     *          ...
+     *          (INIT_SEQ for clause C)
+     * LOOP:    (LOOP_SEQ for clause 1)
+     *          ...
+     *          (LOOP_SEQ for clause C)
+     *          GOTO LOOP
+     * DONE:    ...
      * }</pre></blockquote>
      * <p>
      * The {@code INIT_SEQ_x} sequence for clause {@code x} (with {@code x} ranging from {@code 0} to {@code C-1}) has
      * the following shape. Assume slot {@code vx} is used to hold the state for clause {@code x}.
      * <blockquote><pre>{@code
-     * INIT_SEQ_x:  ALOAD inits
-     *              CHECKCAST MethodHandle[]
+     * INIT_SEQ_x:  ALOAD clauseDataIndex
+     *              ICONST_0
+     *              AALOAD      // load the inits array
      *              ICONST x
      *              AALOAD      // load the init handle for clause x
      *              load args
@@ -1361,24 +1369,27 @@
      * The {@code LOOP_SEQ_x} sequence for clause {@code x} (with {@code x} ranging from {@code 0} to {@code C-1}) has
      * the following shape. Again, assume slot {@code vx} is used to hold the state for clause {@code x}.
      * <blockquote><pre>{@code
-     * LOOP_SEQ_x:  ALOAD steps
-     *              CHECKCAST MethodHandle[]
+     * LOOP_SEQ_x:  ALOAD clauseDataIndex
+     *              ICONST_1
+     *              AALOAD              // load the steps array
      *              ICONST x
      *              AALOAD              // load the step handle for clause x
      *              load locals
      *              load args
      *              INVOKEVIRTUAL MethodHandle.invokeBasic
      *              store vx
-     *              ALOAD preds
-     *              CHECKCAST MethodHandle[]
+     *              ALOAD clauseDataIndex
+     *              ICONST_2
+     *              AALOAD              // load the preds array
      *              ICONST x
      *              AALOAD              // load the pred handle for clause x
      *              load locals
      *              load args
      *              INVOKEVIRTUAL MethodHandle.invokeBasic
      *              IFNE LOOP_SEQ_x+1   // predicate returned false -> jump to next clause
-     *              ALOAD finis
-     *              CHECKCAST MethodHandle[]
+     *              ALOAD clauseDataIndex
+     *              ICONST_3
+     *              AALOAD              // load the finis array
      *              ICONST x
      *              AALOAD              // load the fini handle for clause x
      *              load locals
@@ -1397,8 +1408,12 @@
         BasicType[] loopClauseTypes = (BasicType[]) invoker.arguments[0];
         Class<?>[] loopLocalStateTypes = Stream.of(loopClauseTypes).
                 filter(bt -> bt != BasicType.V_TYPE).map(BasicType::basicTypeClass).toArray(Class<?>[]::new);
+        Class<?>[] localTypes = new Class<?>[loopLocalStateTypes.length + 1];
+        localTypes[0] = MethodHandleImpl.LoopClauses.class;
+        System.arraycopy(loopLocalStateTypes, 0, localTypes, 1, loopLocalStateTypes.length);
 
-        final int firstLoopStateIndex = extendLocalsMap(loopLocalStateTypes);
+        final int clauseDataIndex = extendLocalsMap(localTypes);
+        final int firstLoopStateIndex = clauseDataIndex + 1;
 
         Class<?> returnType = result.function.resolvedHandle().type().returnType();
         MethodType loopType = args.function.resolvedHandle().type()
@@ -1420,10 +1435,16 @@
         Label lDone = new Label();
         Label lNext;
 
+        // PREINIT:
+        emitPushArgument(MethodHandleImpl.LoopClauses.class, invoker.arguments[1]);
+        mv.visitFieldInsn(Opcodes.GETFIELD, LOOP_CLAUSES, "clauses", MHARY2);
+        emitAstoreInsn(clauseDataIndex);
+
         // INIT:
         for (int c = 0, state = 0; c < nClauses; ++c) {
             MethodType cInitType = loopType.changeReturnType(loopClauseTypes[c].basicTypeClass());
-            emitLoopHandleInvoke(invoker, inits, c, args, false, cInitType, loopLocalStateTypes, firstLoopStateIndex);
+            emitLoopHandleInvoke(invoker, inits, c, args, false, cInitType, loopLocalStateTypes, clauseDataIndex,
+                    firstLoopStateIndex);
             if (cInitType.returnType() != void.class) {
                 emitStoreInsn(BasicType.basicType(cInitType.returnType()), firstLoopStateIndex + state);
                 ++state;
@@ -1440,18 +1461,21 @@
             boolean isVoid = stepType.returnType() == void.class;
 
             // invoke loop step
-            emitLoopHandleInvoke(invoker, steps, c, args, true, stepType, loopLocalStateTypes, firstLoopStateIndex);
+            emitLoopHandleInvoke(invoker, steps, c, args, true, stepType, loopLocalStateTypes, clauseDataIndex,
+                    firstLoopStateIndex);
             if (!isVoid) {
                 emitStoreInsn(BasicType.basicType(stepType.returnType()), firstLoopStateIndex + state);
                 ++state;
             }
 
             // invoke loop predicate
-            emitLoopHandleInvoke(invoker, preds, c, args, true, predType, loopLocalStateTypes, firstLoopStateIndex);
+            emitLoopHandleInvoke(invoker, preds, c, args, true, predType, loopLocalStateTypes, clauseDataIndex,
+                    firstLoopStateIndex);
             mv.visitJumpInsn(Opcodes.IFNE, lNext);
 
             // invoke fini
-            emitLoopHandleInvoke(invoker, finis, c, args, true, finiType, loopLocalStateTypes, firstLoopStateIndex);
+            emitLoopHandleInvoke(invoker, finis, c, args, true, finiType, loopLocalStateTypes, clauseDataIndex,
+                    firstLoopStateIndex);
             mv.visitJumpInsn(Opcodes.GOTO, lDone);
 
             // this is the beginning of the next loop clause
@@ -1483,9 +1507,10 @@
     }
 
     private void emitLoopHandleInvoke(Name holder, int handles, int clause, Name args, boolean pushLocalState,
-                                      MethodType type, Class<?>[] loopLocalStateTypes, int firstLoopStateSlot) {
+                                      MethodType type, Class<?>[] loopLocalStateTypes, int clauseDataSlot,
+                                      int firstLoopStateSlot) {
         // load handle for clause
-        emitPushArgument(holder, handles);
+        emitPushClauseArray(clauseDataSlot, handles);
         emitIconstInsn(clause);
         mv.visitInsn(Opcodes.AALOAD);
         // load loop state (preceding the other arguments)
@@ -1499,6 +1524,12 @@
         mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, MH, "invokeBasic", type.toMethodDescriptorString(), false);
     }
 
+    private void emitPushClauseArray(int clauseDataSlot, int which) {
+        emitAloadInsn(clauseDataSlot);
+        emitIconstInsn(which - 1);
+        mv.visitInsn(Opcodes.AALOAD);
+    }
+
     private void emitZero(BasicType type) {
         switch (type) {
             case I_TYPE: mv.visitInsn(Opcodes.ICONST_0); break;
--- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java	Fri Sep 30 09:28:18 2016 -0700
@@ -41,7 +41,6 @@
 import static java.lang.invoke.LambdaForm.BasicType.*;
 import static java.lang.invoke.MethodHandleNatives.Constants.REF_invokeStatic;
 import static java.lang.invoke.MethodHandleStatics.*;
-import java.util.Objects;
 
 /**
  * The symbolic, non-executable form of a method handle's invocation semantics.
@@ -732,9 +731,9 @@
     boolean isLoop(int pos) {
         // loop idiom:
         //   t_{n}:L=MethodHandle.invokeBasic(...)
-        //   t_{n+1}:L=MethodHandleImpl.loop(types, *, *, *, *, t_{n})
+        //   t_{n+1}:L=MethodHandleImpl.loop(types, *, t_{n})
         //   t_{n+2}:?=MethodHandle.invokeBasic(*, t_{n+1})
-        return isMatchingIdiom(pos, "loop", 5);
+        return isMatchingIdiom(pos, "loop", 2);
     }
 
     /*
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1689,8 +1689,7 @@
             NF_tryFinally = new NamedFunction(MethodHandleImpl.class
                     .getDeclaredMethod("tryFinally", MethodHandle.class, MethodHandle.class, Object[].class));
             NF_loop = new NamedFunction(MethodHandleImpl.class
-                    .getDeclaredMethod("loop", BasicType[].class, MethodHandle[].class, MethodHandle[].class,
-                            MethodHandle[].class, MethodHandle[].class, Object[].class));
+                    .getDeclaredMethod("loop", BasicType[].class, LoopClauses.class, Object[].class));
             NF_throwException = new NamedFunction(MethodHandleImpl.class
                     .getDeclaredMethod("throwException", Throwable.class));
             NF_profileBoolean = new NamedFunction(MethodHandleImpl.class
@@ -1794,12 +1793,13 @@
         MethodHandle collectArgs = varargsArray(type.parameterCount()).asType(varargsType);
         MethodHandle unboxResult = unboxResultHandle(tloop);
 
-        BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLLLL();
+        LoopClauses clauseData =
+                new LoopClauses(new MethodHandle[][]{toArray(init), toArray(step), toArray(pred), toArray(fini)});
+        BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLL();
         BoundMethodHandle mh;
         try {
-            mh = (BoundMethodHandle) data.constructor().invokeBasic(type, form, (Object) toArray(init),
-                    (Object) toArray(step), (Object) toArray(pred), (Object) toArray(fini), (Object) collectArgs,
-                    (Object) unboxResult);
+            mh = (BoundMethodHandle) data.constructor().invokeBasic(type, form, (Object) clauseData,
+                    (Object) collectArgs, (Object) unboxResult);
         } catch (Throwable ex) {
             throw uncaughtException(ex);
         }
@@ -1818,23 +1818,20 @@
      * {@code t12}):
      * <blockquote><pre>{@code
      *  loop=Lambda(a0:L,a1:L)=>{
-     *    t2:L=BoundMethodHandle$Species_L6.argL0(a0:L);             // array of init method handles
-     *    t3:L=BoundMethodHandle$Species_L6.argL1(a0:L);             // array of step method handles
-     *    t4:L=BoundMethodHandle$Species_L6.argL2(a0:L);             // array of pred method handles
-     *    t5:L=BoundMethodHandle$Species_L6.argL3(a0:L);             // array of fini method handles
-     *    t6:L=BoundMethodHandle$Species_L6.argL4(a0:L);             // helper handle to box the arguments into an Object[]
-     *    t7:L=BoundMethodHandle$Species_L6.argL5(a0:L);             // helper handle to unbox the result
-     *    t8:L=MethodHandle.invokeBasic(t6:L,a1:L);                  // box the arguments into an Object[]
-     *    t9:L=MethodHandleImpl.loop(null,t2:L,t3:L,t4:L,t5:L,t6:L); // call the loop executor
-     *    t10:L=MethodHandle.invokeBasic(t7:L,t9:L);t10:L}           // unbox the result; return the result
+     *    t2:L=BoundMethodHandle$Species_L3.argL0(a0:L);    // LoopClauses holding init, step, pred, fini handles
+     *    t3:L=BoundMethodHandle$Species_L3.argL1(a0:L);    // helper handle to box the arguments into an Object[]
+     *    t4:L=BoundMethodHandle$Species_L3.argL2(a0:L);    // helper handle to unbox the result
+     *    t5:L=MethodHandle.invokeBasic(t3:L,a1:L);         // box the arguments into an Object[]
+     *    t6:L=MethodHandleImpl.loop(null,t2:L,t3:L);       // call the loop executor
+     *    t7:L=MethodHandle.invokeBasic(t4:L,t6:L);t7:L}    // unbox the result; return the result
      * }</pre></blockquote>
      * <p>
-     * {@code argL0} through {@code argL3} are the arrays of init, step, pred, and fini method handles.
-     * {@code argL4} and {@code argL5} are auxiliary method handles: {@code argL2} boxes arguments and wraps them into
-     * {@code Object[]} ({@code ValueConversions.array()}), and {@code argL3} unboxes the result if necessary
+     * {@code argL0} is a LoopClauses instance holding, in a 2-dimensional array, the init, step, pred, and fini method
+     * handles. {@code argL1} and {@code argL2} are auxiliary method handles: {@code argL1} boxes arguments and wraps
+     * them into {@code Object[]} ({@code ValueConversions.array()}), and {@code argL2} unboxes the result if necessary
      * ({@code ValueConversions.unbox()}).
      * <p>
-     * Having {@code t6} and {@code t7} passed in via a BMH and not hardcoded in the lambda form allows to share lambda
+     * Having {@code t3} and {@code t4} passed in via a BMH and not hardcoded in the lambda form allows to share lambda
      * forms among loop combinators with the same basic type.
      * <p>
      * The above template is instantiated by using the {@link LambdaFormEditor} to replace the {@code null} argument to
@@ -1845,15 +1842,12 @@
     private static LambdaForm makeLoopForm(MethodType basicType, BasicType[] localVarTypes) {
         MethodType lambdaType = basicType.invokerType();
 
-        final int THIS_MH = 0;  // the BMH_LLLLLL
+        final int THIS_MH = 0;  // the BMH_LLL
         final int ARG_BASE = 1; // start of incoming arguments
         final int ARG_LIMIT = ARG_BASE + basicType.parameterCount();
 
         int nameCursor = ARG_LIMIT;
-        final int GET_INITS = nameCursor++;
-        final int GET_STEPS = nameCursor++;
-        final int GET_PREDS = nameCursor++;
-        final int GET_FINIS = nameCursor++;
+        final int GET_CLAUSE_DATA = nameCursor++;
         final int GET_COLLECT_ARGS = nameCursor++;
         final int GET_UNBOX_RESULT = nameCursor++;
         final int BOXED_ARGS = nameCursor++;
@@ -1864,14 +1858,11 @@
         if (lform == null) {
             Name[] names = arguments(nameCursor - ARG_LIMIT, lambdaType);
 
-            BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLLLL();
+            BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLL();
             names[THIS_MH] = names[THIS_MH].withConstraint(data);
-            names[GET_INITS] = new Name(data.getterFunction(0), names[THIS_MH]);
-            names[GET_STEPS] = new Name(data.getterFunction(1), names[THIS_MH]);
-            names[GET_PREDS] = new Name(data.getterFunction(2), names[THIS_MH]);
-            names[GET_FINIS] = new Name(data.getterFunction(3), names[THIS_MH]);
-            names[GET_COLLECT_ARGS] = new Name(data.getterFunction(4), names[THIS_MH]);
-            names[GET_UNBOX_RESULT] = new Name(data.getterFunction(5), names[THIS_MH]);
+            names[GET_CLAUSE_DATA] = new Name(data.getterFunction(0), names[THIS_MH]);
+            names[GET_COLLECT_ARGS] = new Name(data.getterFunction(1), names[THIS_MH]);
+            names[GET_UNBOX_RESULT] = new Name(data.getterFunction(2), names[THIS_MH]);
 
             // t_{i}:L=MethodHandle.invokeBasic(collectArgs:L,a1:L,...);
             MethodType collectArgsType = basicType.changeReturnType(Object.class);
@@ -1881,10 +1872,10 @@
             System.arraycopy(names, ARG_BASE, args, 1, ARG_LIMIT - ARG_BASE);
             names[BOXED_ARGS] = new Name(makeIntrinsic(invokeBasic, Intrinsic.LOOP), args);
 
-            // t_{i+1}:L=MethodHandleImpl.loop(localTypes:L,inits:L,steps:L,preds:L,finis:L,t_{i}:L);
+            // t_{i+1}:L=MethodHandleImpl.loop(localTypes:L,clauses:L,t_{i}:L);
             Object[] lArgs =
                     new Object[]{null, // placeholder for BasicType[] localTypes - will be added by LambdaFormEditor
-                            names[GET_INITS], names[GET_STEPS], names[GET_PREDS], names[GET_FINIS], names[BOXED_ARGS]};
+                            names[GET_CLAUSE_DATA], names[BOXED_ARGS]};
             names[LOOP] = new Name(NF_loop, lArgs);
 
             // t_{i+2}:I=MethodHandle.invokeBasic(unbox:L,t_{i+1}:L);
@@ -1900,22 +1891,52 @@
         return lform.editor().noteLoopLocalTypesForm(BOXED_ARGS, localVarTypes);
     }
 
+    static class LoopClauses {
+        @Stable final MethodHandle[][] clauses;
+        LoopClauses(MethodHandle[][] clauses) {
+            assert clauses.length == 4;
+            this.clauses = clauses;
+        }
+        @Override
+        public String toString() {
+            StringBuffer sb = new StringBuffer("LoopClauses -- ");
+            for (int i = 0; i < 4; ++i) {
+                if (i > 0) {
+                    sb.append("       ");
+                }
+                sb.append('<').append(i).append(">: ");
+                MethodHandle[] hs = clauses[i];
+                for (int j = 0; j < hs.length; ++j) {
+                    if (j > 0) {
+                        sb.append("          ");
+                    }
+                    sb.append('*').append(j).append(": ").append(hs[j]).append('\n');
+                }
+            }
+            sb.append(" --\n");
+            return sb.toString();
+        }
+    }
 
     /**
      * Intrinsified during LambdaForm compilation
      * (see {@link InvokerBytecodeGenerator#emitLoop(int)}).
      */
     @LambdaForm.Hidden
-    static Object loop(BasicType[] localTypes, MethodHandle[] init, MethodHandle[] step, MethodHandle[] pred,
-                       MethodHandle[] fini, Object... av) throws Throwable {
+    static Object loop(BasicType[] localTypes, LoopClauses clauseData, Object... av) throws Throwable {
+        final MethodHandle[] init = clauseData.clauses[0];
+        final MethodHandle[] step = clauseData.clauses[1];
+        final MethodHandle[] pred = clauseData.clauses[2];
+        final MethodHandle[] fini = clauseData.clauses[3];
         int varSize = (int) Stream.of(init).filter(h -> h.type().returnType() != void.class).count();
         int nArgs = init[0].type().parameterCount();
         Object[] varsAndArgs = new Object[varSize + nArgs];
         for (int i = 0, v = 0; i < init.length; ++i) {
-            if (init[i].type().returnType() == void.class) {
-                init[i].asFixedArity().invokeWithArguments(av);
+            MethodHandle ih = init[i];
+            if (ih.type().returnType() == void.class) {
+                ih.invokeWithArguments(av);
             } else {
-                varsAndArgs[v++] = init[i].asFixedArity().invokeWithArguments(av);
+                varsAndArgs[v++] = ih.invokeWithArguments(av);
             }
         }
         System.arraycopy(av, 0, varsAndArgs, varSize, nArgs);
@@ -1926,12 +1947,12 @@
                 MethodHandle s = step[i];
                 MethodHandle f = fini[i];
                 if (s.type().returnType() == void.class) {
-                    s.asFixedArity().invokeWithArguments(varsAndArgs);
+                    s.invokeWithArguments(varsAndArgs);
                 } else {
-                    varsAndArgs[v++] = s.asFixedArity().invokeWithArguments(varsAndArgs);
+                    varsAndArgs[v++] = s.invokeWithArguments(varsAndArgs);
                 }
-                if (!(boolean) p.asFixedArity().invokeWithArguments(varsAndArgs)) {
-                    return f.asFixedArity().invokeWithArguments(varsAndArgs);
+                if (!(boolean) p.invokeWithArguments(varsAndArgs)) {
+                    return f.invokeWithArguments(varsAndArgs);
                 }
             }
         }
@@ -1941,12 +1962,12 @@
      * This method is bound as the predicate in {@linkplain MethodHandles#countedLoop(MethodHandle, MethodHandle,
      * MethodHandle) counting loops}.
      *
+     * @param limit the upper bound of the parameter, statically bound at loop creation time.
      * @param counter the counter parameter, passed in during loop execution.
-     * @param limit the upper bound of the parameter, statically bound at loop creation time.
      *
      * @return whether the counter has reached the limit.
      */
-    static boolean countedLoopPredicate(int counter, int limit) {
+    static boolean countedLoopPredicate(int limit, int counter) {
         return counter < limit;
     }
 
@@ -1954,27 +1975,16 @@
      * This method is bound as the step function in {@linkplain MethodHandles#countedLoop(MethodHandle, MethodHandle,
      * MethodHandle) counting loops} to increment the counter.
      *
+     * @param limit the upper bound of the loop counter (ignored).
      * @param counter the loop counter.
      *
      * @return the loop counter incremented by 1.
      */
-    static int countedLoopStep(int counter, int limit) {
+    static int countedLoopStep(int limit, int counter) {
         return counter + 1;
     }
 
     /**
-     * This method is bound as a filter in {@linkplain MethodHandles#countedLoop(MethodHandle, MethodHandle, MethodHandle,
-     * MethodHandle) counting loops} to pass the correct counter value to the body.
-     *
-     * @param counter the loop counter.
-     *
-     * @return the loop counter decremented by 1.
-     */
-    static int decrementCounter(int counter) {
-        return counter - 1;
-    }
-
-    /**
      * This is bound to initialize the loop-local iterator in {@linkplain MethodHandles#iteratedLoop iterating loops}.
      *
      * @param it the {@link Iterable} over which the loop iterates.
@@ -2122,14 +2132,13 @@
         Throwable t = null;
         Object r = null;
         try {
-            // Use asFixedArity() to avoid unnecessary boxing of last argument for VarargsCollector case.
-            r = target.asFixedArity().invokeWithArguments(av);
+            r = target.invokeWithArguments(av);
         } catch (Throwable thrown) {
             t = thrown;
             throw t;
         } finally {
             Object[] args = target.type().returnType() == void.class ? prepend(av, t) : prepend(av, t, r);
-            r = cleanup.asFixedArity().invokeWithArguments(args);
+            r = cleanup.invokeWithArguments(args);
         }
         return r;
     }
@@ -2144,12 +2153,11 @@
             MH_arrayIdentity         =  5,
             MH_countedLoopPred       =  6,
             MH_countedLoopStep       =  7,
-            MH_iteratePred           =  8,
-            MH_initIterator          =  9,
+            MH_initIterator          =  8,
+            MH_iteratePred           =  9,
             MH_iterateNext           = 10,
-            MH_decrementCounter      = 11,
-            MH_Array_newInstance     = 12,
-            MH_LIMIT                 = 13;
+            MH_Array_newInstance     = 11,
+            MH_LIMIT                 = 12;
 
     static MethodHandle getConstantHandle(int idx) {
         MethodHandle handle = HANDLES[idx];
@@ -2200,18 +2208,15 @@
                 case MH_countedLoopStep:
                     return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "countedLoopStep",
                             MethodType.methodType(int.class, int.class, int.class));
-                case MH_iteratePred:
-                    return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "iteratePredicate",
-                            MethodType.methodType(boolean.class, Iterator.class));
                 case MH_initIterator:
                     return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "initIterator",
                             MethodType.methodType(Iterator.class, Iterable.class));
+                case MH_iteratePred:
+                    return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "iteratePredicate",
+                            MethodType.methodType(boolean.class, Iterator.class));
                 case MH_iterateNext:
                     return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "iterateNext",
                             MethodType.methodType(Object.class, Iterator.class));
-                case MH_decrementCounter:
-                    return IMPL_LOOKUP.findStatic(MethodHandleImpl.class, "decrementCounter",
-                            MethodType.methodType(int.class, int.class));
                 case MH_Array_newInstance:
                     return IMPL_LOOKUP.findStatic(Array.class, "newInstance",
                             MethodType.methodType(Object.class, Class.class, int.class));
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Fri Sep 30 09:28:18 2016 -0700
@@ -44,8 +44,6 @@
 import java.lang.reflect.Modifier;
 import java.lang.reflect.ReflectPermission;
 import java.nio.ByteOrder;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.BitSet;
@@ -3114,7 +3112,7 @@
      * @see MethodHandles#explicitCastArguments
      * @since 9
      */
-    public static  MethodHandle zero(Class<?> type) {
+    public static MethodHandle zero(Class<?> type) {
         Objects.requireNonNull(type);
         return type.isPrimitive() ?  zero(Wrapper.forPrimitiveType(type), type) : zero(Wrapper.OBJECT, type);
     }
@@ -3403,7 +3401,8 @@
                 throw newIllegalArgumentException("illegal pos", pos, newTypes);
             }
             addTypes = addTypes.subList(pos, add);
-            add -= pos; assert(addTypes.size() == add);
+            add -= pos;
+            assert(addTypes.size() == add);
         }
         // Do not add types which already match the existing arguments.
         if (match > add || !oldTypes.equals(addTypes.subList(0, match))) {
@@ -3413,7 +3412,8 @@
             throw newIllegalArgumentException("argument lists do not match", oldTypes, newTypes);
         }
         addTypes = addTypes.subList(match, add);
-        add -= match; assert(addTypes.size() == add);
+        add -= match;
+        assert(addTypes.size() == add);
         // newTypes:     (   P*[pos], M*[match], A*[add] )
         // target: ( S*[skip],        M*[match]  )
         MethodHandle adapter = target;
@@ -3423,26 +3423,37 @@
         // adapter: (S*[skip],        M*[match], A*[add] )
         if (pos > 0) {
             adapter = dropArguments0(adapter, skip, newTypes.subList(0, pos));
-       }
+        }
         // adapter: (S*[skip], P*[pos], M*[match], A*[add] )
         return adapter;
     }
 
     /**
-     * Adapts a target method handle to match the given parameter type list, if necessary, by adding dummy arguments.
-     * Some leading parameters are first skipped; they will be left unchanged and are otherwise ignored.
-     * The remaining types in the target's parameter type list must be contained as a sub-list of the given type list,
-     * at the given position.
-     * Any non-matching parameter types (before or after the matching sub-list) are inserted in corresponding
-     * positions of the target method handle's parameters, as if by {@link #dropArguments}.
-     * (More precisely, elements in the new list before {@code pos} are inserted into the target list at {@code skip},
-     * while elements in the new list after the match beginning at {@code pos} are inserted at the end of the
-     * target list.)
-     * The target's return type will be unchanged.
+     * Adapts a target method handle to match the given parameter type list. If necessary, adds dummy arguments. Some
+     * leading parameters can be skipped before matching begins. The remaining types in the {@code target}'s parameter
+     * type list must be a sub-list of the {@code newTypes} type list at the starting position {@code pos}. The
+     * resulting handle will have the target handle's parameter type list, with any non-matching parameter types (before
+     * or after the matching sub-list) inserted in corresponding positions of the target's original parameters, as if by
+     * {@link #dropArguments(MethodHandle, int, Class[])}.
+     * <p>
+     * The resulting handle will have the same return type as the target handle.
+     * <p>
+     * In more formal terms, assume these two type lists:<ul>
+     * <li>The target handle has the parameter type list {@code S..., M...}, with as many types in {@code S} as
+     * indicated by {@code skip}. The {@code M} types are those that are supposed to match part of the given type list,
+     * {@code newTypes}.
+     * <li>The {@code newTypes} list contains types {@code P..., M..., A...}, with as many types in {@code P} as
+     * indicated by {@code pos}. The {@code M} types are precisely those that the {@code M} types in the target handle's
+     * parameter type list are supposed to match. The types in {@code A} are additional types found after the matching
+     * sub-list.
+     * </ul>
+     * Given these assumptions, the result of an invocation of {@code dropArgumentsToMatch} will have the parameter type
+     * list {@code S..., P..., M..., A...}, with the {@code P} and {@code A} types inserted as if by
+     * {@link #dropArguments(MethodHandle, int, Class[])}.
+     * <p>
      * @apiNote
-     * Two method handles whose argument lists are "effectively identical" (i.e., identical
-     * in a common prefix) may be mutually converted to a common type
-     * by two calls to {@code dropArgumentsToMatch}, as follows:
+     * Two method handles whose argument lists are "effectively identical" (i.e., identical in a common prefix) may be
+     * mutually converted to a common type by two calls to {@code dropArgumentsToMatch}, as follows:
      * <blockquote><pre>{@code
 import static java.lang.invoke.MethodHandles.*;
 import static java.lang.invoke.MethodType.*;
@@ -3461,14 +3472,15 @@
      * }</pre></blockquote>
      * @param target the method handle to adapt
      * @param skip number of targets parameters to disregard (they will be unchanged)
-     * @param newTypes the desired argument list of the method handle
+     * @param newTypes the list of types to match {@code target}'s parameter type list to
      * @param pos place in {@code newTypes} where the non-skipped target parameters must occur
      * @return a possibly adapted method handle
      * @throws NullPointerException if either argument is null
      * @throws IllegalArgumentException if any element of {@code newTypes} is {@code void.class},
      *         or if {@code skip} is negative or greater than the arity of the target,
      *         or if {@code pos} is negative or greater than the newTypes list size,
-     *         or if the non-skipped target parameter types match the new types at {@code pos}
+     *         or if {@code newTypes} does not contain the {@code target}'s non-skipped parameter types at position
+     *         {@code pos}.
      * @since 9
      */
     public static
@@ -3922,6 +3934,113 @@
         return foldArguments(target, 0, combiner);
     }
 
+    /**
+     * Adapts a target method handle by pre-processing some of its arguments, starting at a given position, and then
+     * calling the target with the result of the pre-processing, inserted into the original sequence of arguments just
+     * before the folded arguments.
+     * <p>
+     * This method is closely related to {@link #foldArguments(MethodHandle, MethodHandle)}, but allows to control the
+     * position in the parameter list at which folding takes place. The argument controlling this, {@code pos}, is a
+     * zero-based index. The aforementioned method {@link #foldArguments(MethodHandle, MethodHandle)} assumes position
+     * 0.
+     * <p>
+     * @apiNote Example:
+     * <blockquote><pre>{@code
+    import static java.lang.invoke.MethodHandles.*;
+    import static java.lang.invoke.MethodType.*;
+    ...
+    MethodHandle trace = publicLookup().findVirtual(java.io.PrintStream.class,
+    "println", methodType(void.class, String.class))
+    .bindTo(System.out);
+    MethodHandle cat = lookup().findVirtual(String.class,
+    "concat", methodType(String.class, String.class));
+    assertEquals("boojum", (String) cat.invokeExact("boo", "jum"));
+    MethodHandle catTrace = foldArguments(cat, 1, trace);
+    // also prints "jum":
+    assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum"));
+     * }</pre></blockquote>
+     * <p>Here is pseudocode for the resulting adapter. In the code, {@code T}
+     * represents the result type of the {@code target} and resulting adapter.
+     * {@code V}/{@code v} represent the type and value of the parameter and argument
+     * of {@code target} that precedes the folding position; {@code V} also is
+     * the result type of the {@code combiner}. {@code A}/{@code a} denote the
+     * types and values of the {@code N} parameters and arguments at the folding
+     * position. {@code Z}/{@code z} and {@code B}/{@code b} represent the types
+     * and values of the {@code target} parameters and arguments that precede and
+     * follow the folded parameters and arguments starting at {@code pos},
+     * respectively.
+     * <blockquote><pre>{@code
+     * // there are N arguments in A...
+     * T target(Z..., V, A[N]..., B...);
+     * V combiner(A...);
+     * T adapter(Z... z, A... a, B... b) {
+     *   V v = combiner(a...);
+     *   return target(z..., v, a..., b...);
+     * }
+     * // and if the combiner has a void return:
+     * T target2(Z..., A[N]..., B...);
+     * void combiner2(A...);
+     * T adapter2(Z... z, A... a, B... b) {
+     *   combiner2(a...);
+     *   return target2(z..., a..., b...);
+     * }
+     * }</pre></blockquote>
+     * <p>
+     * <em>Note:</em> The resulting adapter is never a {@linkplain MethodHandle#asVarargsCollector
+     * variable-arity method handle}, even if the original target method handle was.
+     *
+     * @param target the method handle to invoke after arguments are combined
+     * @param pos the position at which to start folding and at which to insert the folding result; if this is {@code
+     *            0}, the effect is the same as for {@link #foldArguments(MethodHandle, MethodHandle)}.
+     * @param combiner method handle to call initially on the incoming arguments
+     * @return method handle which incorporates the specified argument folding logic
+     * @throws NullPointerException if either argument is null
+     * @throws IllegalArgumentException if either of the following two conditions holds:
+     *          (1) {@code combiner}'s return type is non-{@code void} and not the same as the argument type at position
+     *              {@code pos} of the target signature;
+     *          (2) the {@code N} argument types at position {@code pos} of the target signature (skipping one matching
+     *              the {@code combiner}'s return type) are not identical with the argument types of {@code combiner}.
+     *
+     * @see #foldArguments(MethodHandle, MethodHandle)
+     * @since 9
+     */
+    public static MethodHandle foldArguments(MethodHandle target, int pos, MethodHandle combiner) {
+        MethodType targetType = target.type();
+        MethodType combinerType = combiner.type();
+        Class<?> rtype = foldArgumentChecks(pos, targetType, combinerType);
+        BoundMethodHandle result = target.rebind();
+        boolean dropResult = rtype == void.class;
+        LambdaForm lform = result.editor().foldArgumentsForm(1 + pos, dropResult, combinerType.basicType());
+        MethodType newType = targetType;
+        if (!dropResult) {
+            newType = newType.dropParameterTypes(pos, pos + 1);
+        }
+        result = result.copyWithExtendL(newType, lform, combiner);
+        return result;
+    }
+
+    /**
+     * As {@see foldArguments(MethodHandle, int, MethodHandle)}, but with the
+     * added capability of selecting the arguments from the targets parameters
+     * to call the combiner with. This allows us to avoid some simple cases of
+     * permutations and padding the combiner with dropArguments to select the
+     * right argument, which may ultimately produce fewer intermediaries.
+     */
+    static MethodHandle foldArguments(MethodHandle target, int pos, MethodHandle combiner, int ... argPositions) {
+        MethodType targetType = target.type();
+        MethodType combinerType = combiner.type();
+        Class<?> rtype = foldArgumentChecks(pos, targetType, combinerType, argPositions);
+        BoundMethodHandle result = target.rebind();
+        boolean dropResult = rtype == void.class;
+        LambdaForm lform = result.editor().foldArgumentsForm(1 + pos, dropResult, combinerType.basicType(), argPositions);
+        MethodType newType = targetType;
+        if (!dropResult) {
+            newType = newType.dropParameterTypes(pos, pos + 1);
+        }
+        result = result.copyWithExtendL(newType, lform, combiner);
+        return result;
+    }
+
     private static Class<?> foldArgumentChecks(int foldPos, MethodType targetType, MethodType combinerType) {
         int foldArgs   = combinerType.parameterCount();
         Class<?> rtype = combinerType.returnType();
@@ -4125,32 +4244,69 @@
      * iteration. Upon termination of the loop due to one of the predicates, a corresponding finalizer is run and
      * delivers the loop's result, which is the return value of the resulting handle.
      * <p>
-     * Intuitively, every loop is formed by one or more "clauses", each specifying a local iteration value and/or a loop
+     * Intuitively, every loop is formed by one or more "clauses", each specifying a local <em>iteration variable</em> and/or a loop
      * exit. Each iteration of the loop executes each clause in order. A clause can optionally update its iteration
      * variable; it can also optionally perform a test and conditional loop exit. In order to express this logic in
-     * terms of method handles, each clause will determine four actions:<ul>
-     * <li>Before the loop executes, the initialization of an iteration variable or loop invariant local.
-     * <li>When a clause executes, an update step for the iteration variable.
-     * <li>When a clause executes, a predicate execution to test for loop exit.
-     * <li>If a clause causes a loop exit, a finalizer execution to compute the loop's return value.
+     * terms of method handles, each clause will specify up to four independent actions:<ul>
+     * <li><em>init:</em> Before the loop executes, the initialization of an iteration variable {@code v} of type {@code V}.
+     * <li><em>step:</em> When a clause executes, an update step for the iteration variable {@code v}.
+     * <li><em>pred:</em> When a clause executes, a predicate execution to test for loop exit.
+     * <li><em>fini:</em> If a clause causes a loop exit, a finalizer execution to compute the loop's return value.
      * </ul>
+     * The full sequence of all iteration variable types, in clause order, will be notated as {@code (V...)}.
+     * The values themselves will be {@code (v...)}.  When we speak of "parameter lists", we will usually
+     * be referring to types, but in some contexts (describing execution) the lists will be of actual values.
      * <p>
      * Some of these clause parts may be omitted according to certain rules, and useful default behavior is provided in
      * this case. See below for a detailed description.
      * <p>
-     * Each clause function, with the exception of clause initializers, is able to observe the entire loop state,
-     * because it will be passed <em>all</em> current iteration variable values, as well as all incoming loop
-     * parameters. Most clause functions will not need all of this information, but they will be formally connected as
-     * if by {@link #dropArguments}.
+     * <em>Parameters optional everywhere:</em>
+     * Each clause function is allowed but not required to accept a parameter for each iteration variable {@code v}.
+     * As an exception, the init functions cannot take any {@code v} parameters,
+     * because those values are not yet computed when the init functions are executed.
+     * Any clause function may neglect to take any trailing subsequence of parameters it is entitled to take.
+     * In fact, any clause function may take no arguments at all.
      * <p>
+     * <em>Loop parameters:</em>
+     * A clause function may take all the iteration variable values it is entitled to, in which case
+     * it may also take more trailing parameters. Such extra values are called <em>loop parameters</em>,
+     * with their types and values notated as {@code (A...)} and {@code (a...)}.
+     * These become the parameters of the resulting loop handle, to be supplied whenever the loop is executed.
+     * (Since init functions do not accept iteration variables {@code v}, any parameter to an
+     * init function is automatically a loop parameter {@code a}.)
+     * As with iteration variables, clause functions are allowed but not required to accept loop parameters.
+     * These loop parameters act as loop-invariant values visible across the whole loop.
+     * <p>
+     * <em>Parameters visible everywhere:</em>
+     * Each non-init clause function is permitted to observe the entire loop state, because it can be passed the full
+     * list {@code (v... a...)} of current iteration variable values and incoming loop parameters.
+     * The init functions can observe initial pre-loop state, in the form {@code (a...)}.
+     * Most clause functions will not need all of this information, but they will be formally connected to it
+     * as if by {@link #dropArguments}.
+     * <a name="astar"></a>
+     * More specifically, we shall use the notation {@code (V*)} to express an arbitrary prefix of a full
+     * sequence {@code (V...)} (and likewise for {@code (v*)}, {@code (A*)}, {@code (a*)}).
+     * In that notation, the general form of an init function parameter list
+     * is {@code (A*)}, and the general form of a non-init function parameter list is {@code (V*)} or {@code (V... A*)}.
+     * <p>
+     * <em>Checking clause structure:</em>
      * Given a set of clauses, there is a number of checks and adjustments performed to connect all the parts of the
      * loop. They are spelled out in detail in the steps below. In these steps, every occurrence of the word "must"
-     * corresponds to a place where {@link IllegalArgumentException} may be thrown if the required constraint is not met
-     * by the inputs to the loop combinator. The term "effectively identical", applied to parameter type lists, means
-     * that they must be identical, or else one list must be a proper prefix of the other.
+     * corresponds to a place where {@link IllegalArgumentException} will be thrown if the required constraint is not
+     * met by the inputs to the loop combinator.
+     * <p>
+     * <em>Effectively identical sequences:</em>
+     * <a name="effid"></a>
+     * A parameter list {@code A} is defined to be <em>effectively identical</em> to another parameter list {@code B}
+     * if {@code A} and {@code B} are identical, or if {@code A} is shorter and is identical with a proper prefix of {@code B}.
+     * When speaking of an unordered set of parameter lists, we say they the set is "effectively identical"
+     * as a whole if the set contains a longest list, and all members of the set are effectively identical to
+     * that longest list.
+     * For example, any set of type sequences of the form {@code (V*)} is effectively identical,
+     * and the same is true if more sequences of the form {@code (V... A*)} are added.
      * <p>
      * <em>Step 0: Determine clause structure.</em><ol type="a">
-     * <li>The clause array (of type {@code MethodHandle[][]} must be non-{@code null} and contain at least one element.
+     * <li>The clause array (of type {@code MethodHandle[][]}) must be non-{@code null} and contain at least one element.
      * <li>The clause array may not contain {@code null}s or sub-arrays longer than four elements.
      * <li>Clauses shorter than four elements are treated as if they were padded by {@code null} elements to length
      * four. Padding takes place by appending elements to the array.
@@ -4158,30 +4314,35 @@
      * <li>Each clause is treated as a four-tuple of functions, called "init", "step", "pred", and "fini".
      * </ol>
      * <p>
-     * <em>Step 1A: Determine iteration variables.</em><ol type="a">
-     * <li>Examine init and step function return types, pairwise, to determine each clause's iteration variable type.
-     * <li>If both functions are omitted, use {@code void}; else if one is omitted, use the other's return type; else
-     * use the common return type (they must be identical).
+     * <em>Step 1A: Determine iteration variable types {@code (V...)}.</em><ol type="a">
+     * <li>The iteration variable type for each clause is determined using the clause's init and step return types.
+     * <li>If both functions are omitted, there is no iteration variable for the corresponding clause ({@code void} is
+     * used as the type to indicate that). If one of them is omitted, the other's return type defines the clause's
+     * iteration variable type. If both are given, the common return type (they must be identical) defines the clause's
+     * iteration variable type.
      * <li>Form the list of return types (in clause order), omitting all occurrences of {@code void}.
-     * <li>This list of types is called the "common prefix".
+     * <li>This list of types is called the "iteration variable types" ({@code (V...)}).
      * </ol>
      * <p>
-     * <em>Step 1B: Determine loop parameters.</em><ul>
-     * <li><b>If at least one init function is given,</b><ol type="a">
-     *   <li>Examine init function parameter lists.
-     *   <li>Omitted init functions are deemed to have {@code null} parameter lists.
-     *   <li>All init function parameter lists must be effectively identical.
-     *   <li>The longest parameter list (which is necessarily unique) is called the "common suffix".
-     * </ol>
-     * <li><b>If no init function is given,</b><ol type="a">
-     *   <li>Examine the suffixes of the step, pred, and fini parameter lists, after removing the "common prefix".
-     *   <li>The longest of these suffixes is taken as the "common suffix".
-     * </ol></ul>
+     * <em>Step 1B: Determine loop parameters {@code (A...)}.</em><ul>
+     * <li>Examine and collect init function parameter lists (which are of the form {@code (A*)}).
+     * <li>Examine and collect the suffixes of the step, pred, and fini parameter lists, after removing the iteration variable types.
+     * (They must have the form {@code (V... A*)}; collect the {@code (A*)} parts only.)
+     * <li>Do not collect suffixes from step, pred, and fini parameter lists that do not begin with all the iteration variable types.
+     * (These types will checked in step 2, along with all the clause function types.)
+     * <li>Omitted clause functions are ignored.  (Equivalently, they are deemed to have empty parameter lists.)
+     * <li>All of the collected parameter lists must be effectively identical.
+     * <li>The longest parameter list (which is necessarily unique) is called the "external parameter list" ({@code (A...)}).
+     * <li>If there is no such parameter list, the external parameter list is taken to be the empty sequence.
+     * <li>The combined list consisting of iteration variable types followed by the external parameter types is called
+     * the "internal parameter list".
+     * </ul>
      * <p>
      * <em>Step 1C: Determine loop return type.</em><ol type="a">
      * <li>Examine fini function return types, disregarding omitted fini functions.
-     * <li>If there are no fini functions, use {@code void} as the loop return type.
-     * <li>Otherwise, use the common return type of the fini functions; they must all be identical.
+     * <li>If there are no fini functions, the loop return type is {@code void}.
+     * <li>Otherwise, the common return type {@code R} of the fini functions (their return types must be identical) defines the loop return
+     * type.
      * </ol>
      * <p>
      * <em>Step 1D: Check other types.</em><ol type="a">
@@ -4190,69 +4351,107 @@
      * </ol>
      * <p>
      * <em>Step 2: Determine parameter lists.</em><ol type="a">
-     * <li>The parameter list for the resulting loop handle will be the "common suffix".
-     * <li>The parameter list for init functions will be adjusted to the "common suffix". (Note that their parameter
-     * lists are already effectively identical to the common suffix.)
-     * <li>The parameter list for non-init (step, pred, and fini) functions will be adjusted to the common prefix
-     * followed by the common suffix, called the "common parameter sequence".
-     * <li>Every non-init, non-omitted function parameter list must be effectively identical to the common parameter
-     * sequence.
+     * <li>The parameter list for the resulting loop handle will be the external parameter list {@code (A...)}.
+     * <li>The parameter list for init functions will be adjusted to the external parameter list.
+     * (Note that their parameter lists are already effectively identical to this list.)
+     * <li>The parameter list for every non-omitted, non-init (step, pred, and fini) function must be
+     * effectively identical to the internal parameter list {@code (V... A...)}.
      * </ol>
      * <p>
      * <em>Step 3: Fill in omitted functions.</em><ol type="a">
-     * <li>If an init function is omitted, use a {@linkplain #constant constant function} of the appropriate
-     * {@code null}/zero/{@code false}/{@code void} type. (For this purpose, a constant {@code void} is simply a
-     * function which does nothing and returns {@code void}; it can be obtained from another constant function by
-     * {@linkplain MethodHandle#asType type conversion}.)
+     * <li>If an init function is omitted, use a {@linkplain #empty default value} for the clause's iteration variable
+     * type.
      * <li>If a step function is omitted, use an {@linkplain #identity identity function} of the clause's iteration
      * variable type; insert dropped argument parameters before the identity function parameter for the non-{@code void}
      * iteration variables of preceding clauses. (This will turn the loop variable into a local loop invariant.)
-     * <li>If a pred function is omitted, the corresponding fini function must also be omitted.
      * <li>If a pred function is omitted, use a constant {@code true} function. (This will keep the loop going, as far
-     * as this clause is concerned.)
-     * <li>If a fini function is omitted, use a constant {@code null}/zero/{@code false}/{@code void} function of the
+     * as this clause is concerned.  Note that in such cases the corresponding fini function is unreachable.)
+     * <li>If a fini function is omitted, use a {@linkplain #empty default value} for the
      * loop return type.
      * </ol>
      * <p>
      * <em>Step 4: Fill in missing parameter types.</em><ol type="a">
-     * <li>At this point, every init function parameter list is effectively identical to the common suffix, but some
-     * lists may be shorter. For every init function with a short parameter list, pad out the end of the list by
-     * {@linkplain #dropArguments dropping arguments}.
-     * <li>At this point, every non-init function parameter list is effectively identical to the common parameter
-     * sequence, but some lists may be shorter. For every non-init function with a short parameter list, pad out the end
-     * of the list by {@linkplain #dropArguments dropping arguments}.
+     * <li>At this point, every init function parameter list is effectively identical to the external parameter list {@code (A...)},
+     * but some lists may be shorter. For every init function with a short parameter list, pad out the end of the list.
+     * <li>At this point, every non-init function parameter list is effectively identical to the internal parameter
+     * list {@code (V... A...)}, but some lists may be shorter. For every non-init function with a short parameter list,
+     * pad out the end of the list.
+     * <li>Argument lists are padded out by {@linkplain #dropArgumentsToMatch dropping unused trailing arguments}.
      * </ol>
      * <p>
      * <em>Final observations.</em><ol type="a">
      * <li>After these steps, all clauses have been adjusted by supplying omitted functions and arguments.
-     * <li>All init functions have a common parameter type list, which the final loop handle will also have.
-     * <li>All fini functions have a common return type, which the final loop handle will also have.
-     * <li>All non-init functions have a common parameter type list, which is the common parameter sequence, of
-     * (non-{@code void}) iteration variables followed by loop parameters.
-     * <li>Each pair of init and step functions agrees in their return types.
-     * <li>Each non-init function will be able to observe the current values of all iteration variables, by means of the
-     * common prefix.
+     * <li>All init functions have a common parameter type list {@code (A...)}, which the final loop handle will also have.
+     * <li>All fini functions have a common return type {@code R}, which the final loop handle will also have.
+     * <li>All non-init functions have a common parameter type list {@code (V... A...)}, of
+     * (non-{@code void}) iteration variables {@code V} followed by loop parameters.
+     * <li>Each pair of init and step functions agrees in their return type {@code V}.
+     * <li>Each non-init function will be able to observe the current values {@code (v...)} of all iteration variables.
+     * <li>Every function will be able to observe the incoming values {@code (a...)} of all loop parameters.
      * </ol>
      * <p>
+     * <em>Example.</em> As a consequence of step 1A above, the {@code loop} combinator has the following property:
+     * <ul>
+     * <li>Given {@code N} clauses {@code Cn = {null, Sn, Pn}} with {@code n = 1..N}.
+     * <li>Suppose predicate handles {@code Pn} are either {@code null} or have no parameters.
+     * (Only one {@code Pn} has to be non-{@code null}.)
+     * <li>Suppose step handles {@code Sn} have signatures {@code (B1..BX)Rn}, for some constant {@code X>=N}.
+     * <li>Suppose {@code Q} is the count of non-void types {@code Rn}, and {@code (V1...VQ)} is the sequence of those types.
+     * <li>It must be that {@code Vn == Bn} for {@code n = 1..min(X,Q)}.
+     * <li>The parameter types {@code Vn} will be interpreted as loop-local state elements {@code (V...)}.
+     * <li>Any remaining types {@code BQ+1..BX} (if {@code Q<X}) will determine
+     * the resulting loop handle's parameter types {@code (A...)}.
+     * </ul>
+     * In this example, the loop handle parameters {@code (A...)} were derived from the step functions,
+     * which is natural if most of the loop computation happens in the steps.  For some loops,
+     * the burden of computation might be heaviest in the pred functions, and so the pred functions
+     * might need to accept the loop parameter values.  For loops with complex exit logic, the fini
+     * functions might need to accept loop parameters, and likewise for loops with complex entry logic,
+     * where the init functions will need the extra parameters.  For such reasons, the rules for
+     * determining these parameters are as symmetric as possible, across all clause parts.
+     * In general, the loop parameters function as common invariant values across the whole
+     * loop, while the iteration variables function as common variant values, or (if there is
+     * no step function) as internal loop invariant temporaries.
+     * <p>
      * <em>Loop execution.</em><ol type="a">
-     * <li>When the loop is called, the loop input values are saved in locals, to be passed (as the common suffix) to
+     * <li>When the loop is called, the loop input values are saved in locals, to be passed to
      * every clause function. These locals are loop invariant.
-     * <li>Each init function is executed in clause order (passing the common suffix) and the non-{@code void} values
-     * are saved (as the common prefix) into locals. These locals are loop varying (unless their steps are identity
-     * functions, as noted above).
-     * <li>All function executions (except init functions) will be passed the common parameter sequence, consisting of
-     * the non-{@code void} iteration values (in clause order) and then the loop inputs (in argument order).
+     * <li>Each init function is executed in clause order (passing the external arguments {@code (a...)})
+     * and the non-{@code void} values are saved (as the iteration variables {@code (v...)}) into locals.
+     * These locals will be loop varying (unless their steps behave as identity functions, as noted above).
+     * <li>All function executions (except init functions) will be passed the internal parameter list, consisting of
+     * the non-{@code void} iteration values {@code (v...)} (in clause order) and then the loop inputs {@code (a...)}
+     * (in argument order).
      * <li>The step and pred functions are then executed, in clause order (step before pred), until a pred function
      * returns {@code false}.
-     * <li>The non-{@code void} result from a step function call is used to update the corresponding loop variable. The
-     * updated value is immediately visible to all subsequent function calls.
+     * <li>The non-{@code void} result from a step function call is used to update the corresponding value in the
+     * sequence {@code (v...)} of loop variables.
+     * The updated value is immediately visible to all subsequent function calls.
      * <li>If a pred function returns {@code false}, the corresponding fini function is called, and the resulting value
-     * is returned from the loop as a whole.
+     * (of type {@code R}) is returned from the loop as a whole.
+     * <li>If all the pred functions always return true, no fini function is ever invoked, and the loop cannot exit
+     * except by throwing an exception.
      * </ol>
      * <p>
-     * Here is pseudocode for the resulting loop handle. In the code, {@code V}/{@code v} represent the types / values
-     * of loop variables; {@code A}/{@code a}, those of arguments passed to the resulting loop; and {@code R}, the
-     * result types of finalizers as well as of the resulting loop.
+     * <em>Usage tips.</em>
+     * <ul>
+     * <li>Although each step function will receive the current values of <em>all</em> the loop variables,
+     * sometimes a step function only needs to observe the current value of its own variable.
+     * In that case, the step function may need to explicitly {@linkplain #dropArguments drop all preceding loop variables}.
+     * This will require mentioning their types, in an expression like {@code dropArguments(step, 0, V0.class, ...)}.
+     * <li>Loop variables are not required to vary; they can be loop invariant.  A clause can create
+     * a loop invariant by a suitable init function with no step, pred, or fini function.  This may be
+     * useful to "wire" an incoming loop argument into the step or pred function of an adjacent loop variable.
+     * <li>If some of the clause functions are virtual methods on an instance, the instance
+     * itself can be conveniently placed in an initial invariant loop "variable", using an initial clause
+     * like {@code new MethodHandle[]{identity(ObjType.class)}}.  In that case, the instance reference
+     * will be the first iteration variable value, and it will be easy to use virtual
+     * methods as clause parts, since all of them will take a leading instance reference matching that value.
+     * </ul>
+     * <p>
+     * Here is pseudocode for the resulting loop handle. As above, {@code V} and {@code v} represent the types
+     * and values of loop variables; {@code A} and {@code a} represent arguments passed to the whole loop;
+     * and {@code R} is the common result type of all finalizers as well as of the resulting loop.
      * <blockquote><pre>{@code
      * V... init...(A...);
      * boolean pred...(V..., A...);
@@ -4270,6 +4469,9 @@
      *   }
      * }
      * }</pre></blockquote>
+     * Note that the parameter type lists {@code (V...)} and {@code (A...)} have been expanded
+     * to their full length, even though individual clause functions may neglect to take them all.
+     * As noted above, missing parameters are filled in as if by {@link #dropArgumentsToMatch}.
      * <p>
      * @apiNote Example:
      * <blockquote><pre>{@code
@@ -4286,6 +4488,43 @@
      * MethodHandle loop = MethodHandles.loop(counterClause, accumulatorClause);
      * assertEquals(120, loop.invoke(5));
      * }</pre></blockquote>
+     * The same example, dropping arguments and using combinators:
+     * <blockquote><pre>{@code
+     * // simplified implementation of the factorial function as a loop handle
+     * static int inc(int i) { return i + 1; } // drop acc, k
+     * static int mult(int i, int acc) { return i * acc; } //drop k
+     * static boolean cmp(int i, int k) { return i < k; }
+     * // assume MH_inc, MH_mult, and MH_cmp are handles to the above methods
+     * // null initializer for counter, should initialize to 0
+     * MethodHandle MH_one = MethodHandles.constant(int.class, 1);
+     * MethodHandle MH_pred = MethodHandles.dropArguments(MH_cmp, 1, int.class); // drop acc
+     * MethodHandle MH_fin = MethodHandles.dropArguments(MethodHandles.identity(int.class), 0, int.class); // drop i
+     * MethodHandle[] counterClause = new MethodHandle[]{null, MH_inc};
+     * MethodHandle[] accumulatorClause = new MethodHandle[]{MH_one, MH_mult, MH_pred, MH_fin};
+     * MethodHandle loop = MethodHandles.loop(counterClause, accumulatorClause);
+     * assertEquals(720, loop.invoke(6));
+     * }</pre></blockquote>
+     * A similar example, using a helper object to hold a loop parameter:
+     * <blockquote><pre>{@code
+     * // instance-based implementation of the factorial function as a loop handle
+     * static class FacLoop {
+     *   final int k;
+     *   FacLoop(int k) { this.k = k; }
+     *   int inc(int i) { return i + 1; }
+     *   int mult(int i, int acc) { return i * acc; }
+     *   boolean pred(int i) { return i < k; }
+     *   int fin(int i, int acc) { return acc; }
+     * }
+     * // assume MH_FacLoop is a handle to the constructor
+     * // assume MH_inc, MH_mult, MH_pred, and MH_fin are handles to the above methods
+     * // null initializer for counter, should initialize to 0
+     * MethodHandle MH_one = MethodHandles.constant(int.class, 1);
+     * MethodHandle[] instanceClause = new MethodHandle[]{MH_FacLoop};
+     * MethodHandle[] counterClause = new MethodHandle[]{null, MH_inc};
+     * MethodHandle[] accumulatorClause = new MethodHandle[]{MH_one, MH_mult, MH_pred, MH_fin};
+     * MethodHandle loop = MethodHandles.loop(instanceClause, counterClause, accumulatorClause);
+     * assertEquals(5040, loop.invoke(7));
+     * }</pre></blockquote>
      *
      * @param clauses an array of arrays (4-tuples) of {@link MethodHandle}s adhering to the rules described above.
      *
@@ -4301,7 +4540,7 @@
      */
     public static MethodHandle loop(MethodHandle[]... clauses) {
         // Step 0: determine clause structure.
-        checkLoop0(clauses);
+        loopChecks0(clauses);
 
         List<MethodHandle> init = new ArrayList<>();
         List<MethodHandle> step = new ArrayList<>();
@@ -4318,7 +4557,7 @@
         assert Stream.of(init, step, pred, fini).map(List::size).distinct().count() == 1;
         final int nclauses = init.size();
 
-        // Step 1A: determine iteration variables.
+        // Step 1A: determine iteration variables (V...).
         final List<Class<?>> iterationVariableTypes = new ArrayList<>();
         for (int i = 0; i < nclauses; ++i) {
             MethodHandle in = init.get(i);
@@ -4326,7 +4565,7 @@
             if (in == null && st == null) {
                 iterationVariableTypes.add(void.class);
             } else if (in != null && st != null) {
-                checkLoop1a(i, in, st);
+                loopChecks1a(i, in, st);
                 iterationVariableTypes.add(in.type().returnType());
             } else {
                 iterationVariableTypes.add(in == null ? st.type().returnType() : in.type().returnType());
@@ -4335,20 +4574,20 @@
         final List<Class<?>> commonPrefix = iterationVariableTypes.stream().filter(t -> t != void.class).
                 collect(Collectors.toList());
 
-        // Step 1B: determine loop parameters.
+        // Step 1B: determine loop parameters (A...).
         final List<Class<?>> commonSuffix = buildCommonSuffix(init, step, pred, fini, commonPrefix.size());
-        checkLoop1b(init, commonSuffix);
+        loopChecks1b(init, commonSuffix);
 
         // Step 1C: determine loop return type.
         // Step 1D: check other types.
         final Class<?> loopReturnType = fini.stream().filter(Objects::nonNull).map(MethodHandle::type).
                 map(MethodType::returnType).findFirst().orElse(void.class);
-        checkLoop1cd(pred, fini, loopReturnType);
+        loopChecks1cd(pred, fini, loopReturnType);
 
         // Step 2: determine parameter lists.
         final List<Class<?>> commonParameterSequence = new ArrayList<>(commonPrefix);
         commonParameterSequence.addAll(commonSuffix);
-        checkLoop2(step, pred, fini, commonParameterSequence);
+        loopChecks2(step, pred, fini, commonParameterSequence);
 
         // Step 3: fill in omitted functions.
         for (int i = 0; i < nclauses; ++i) {
@@ -4368,10 +4607,11 @@
         }
 
         // Step 4: fill in missing parameter types.
-        List<MethodHandle> finit = fillParameterTypes(init, commonSuffix);
-        List<MethodHandle> fstep = fillParameterTypes(step, commonParameterSequence);
-        List<MethodHandle> fpred = fillParameterTypes(pred, commonParameterSequence);
-        List<MethodHandle> ffini = fillParameterTypes(fini, commonParameterSequence);
+        // Also convert all handles to fixed-arity handles.
+        List<MethodHandle> finit = fixArities(fillParameterTypes(init, commonSuffix));
+        List<MethodHandle> fstep = fixArities(fillParameterTypes(step, commonParameterSequence));
+        List<MethodHandle> fpred = fixArities(fillParameterTypes(pred, commonParameterSequence));
+        List<MethodHandle> ffini = fixArities(fillParameterTypes(fini, commonParameterSequence));
 
         assert finit.stream().map(MethodHandle::type).map(MethodType::parameterList).
                 allMatch(pl -> pl.equals(commonSuffix));
@@ -4381,6 +4621,79 @@
         return MethodHandleImpl.makeLoop(loopReturnType, commonSuffix, finit, fstep, fpred, ffini);
     }
 
+    private static void loopChecks0(MethodHandle[][] clauses) {
+        if (clauses == null || clauses.length == 0) {
+            throw newIllegalArgumentException("null or no clauses passed");
+        }
+        if (Stream.of(clauses).anyMatch(Objects::isNull)) {
+            throw newIllegalArgumentException("null clauses are not allowed");
+        }
+        if (Stream.of(clauses).anyMatch(c -> c.length > 4)) {
+            throw newIllegalArgumentException("All loop clauses must be represented as MethodHandle arrays with at most 4 elements.");
+        }
+    }
+
+    private static void loopChecks1a(int i, MethodHandle in, MethodHandle st) {
+        if (in.type().returnType() != st.type().returnType()) {
+            throw misMatchedTypes("clause " + i + ": init and step return types", in.type().returnType(),
+                    st.type().returnType());
+        }
+    }
+
+    private static List<Class<?>> longestParameterList(Stream<MethodHandle> mhs, int skipSize) {
+        final List<Class<?>> empty = List.of();
+        final List<Class<?>> longest = mhs.filter(Objects::nonNull).
+                // take only those that can contribute to a common suffix because they are longer than the prefix
+                        map(MethodHandle::type).
+                        filter(t -> t.parameterCount() > skipSize).
+                        map(MethodType::parameterList).
+                        reduce((p, q) -> p.size() >= q.size() ? p : q).orElse(empty);
+        return longest.size() == 0 ? empty : longest.subList(skipSize, longest.size());
+    }
+
+    private static List<Class<?>> longestParameterList(List<List<Class<?>>> lists) {
+        final List<Class<?>> empty = List.of();
+        return lists.stream().reduce((p, q) -> p.size() >= q.size() ? p : q).orElse(empty);
+    }
+
+    private static List<Class<?>> buildCommonSuffix(List<MethodHandle> init, List<MethodHandle> step, List<MethodHandle> pred, List<MethodHandle> fini, int cpSize) {
+        final List<Class<?>> longest1 = longestParameterList(Stream.of(step, pred, fini).flatMap(List::stream), cpSize);
+        final List<Class<?>> longest2 = longestParameterList(init.stream(), 0);
+        return longestParameterList(Arrays.asList(longest1, longest2));
+    }
+
+    private static void loopChecks1b(List<MethodHandle> init, List<Class<?>> commonSuffix) {
+        if (init.stream().filter(Objects::nonNull).map(MethodHandle::type).
+                anyMatch(t -> !t.effectivelyIdenticalParameters(0, commonSuffix))) {
+            throw newIllegalArgumentException("found non-effectively identical init parameter type lists: " + init +
+                    " (common suffix: " + commonSuffix + ")");
+        }
+    }
+
+    private static void loopChecks1cd(List<MethodHandle> pred, List<MethodHandle> fini, Class<?> loopReturnType) {
+        if (fini.stream().filter(Objects::nonNull).map(MethodHandle::type).map(MethodType::returnType).
+                anyMatch(t -> t != loopReturnType)) {
+            throw newIllegalArgumentException("found non-identical finalizer return types: " + fini + " (return type: " +
+                    loopReturnType + ")");
+        }
+
+        if (!pred.stream().filter(Objects::nonNull).findFirst().isPresent()) {
+            throw newIllegalArgumentException("no predicate found", pred);
+        }
+        if (pred.stream().filter(Objects::nonNull).map(MethodHandle::type).map(MethodType::returnType).
+                anyMatch(t -> t != boolean.class)) {
+            throw newIllegalArgumentException("predicates must have boolean return type", pred);
+        }
+    }
+
+    private static void loopChecks2(List<MethodHandle> step, List<MethodHandle> pred, List<MethodHandle> fini, List<Class<?>> commonParameterSequence) {
+        if (Stream.of(step, pred, fini).flatMap(List::stream).filter(Objects::nonNull).map(MethodHandle::type).
+                anyMatch(t -> !t.effectivelyIdenticalParameters(0, commonParameterSequence))) {
+            throw newIllegalArgumentException("found non-effectively identical parameter type lists:\nstep: " + step +
+                    "\npred: " + pred + "\nfini: " + fini + " (common parameter sequence: " + commonParameterSequence + ")");
+        }
+    }
+
     private static List<MethodHandle> fillParameterTypes(List<MethodHandle> hs, final List<Class<?>> targetParams) {
         return hs.stream().map(h -> {
             int pc = h.type().parameterCount();
@@ -4389,27 +4702,65 @@
         }).collect(Collectors.toList());
     }
 
+    private static List<MethodHandle> fixArities(List<MethodHandle> hs) {
+        return hs.stream().map(MethodHandle::asFixedArity).collect(Collectors.toList());
+    }
+
     /**
-     * Constructs a {@code while} loop from an initializer, a body, and a predicate. This is a convenience wrapper for
-     * the {@linkplain #loop(MethodHandle[][]) generic loop combinator}.
+     * Constructs a {@code while} loop from an initializer, a body, and a predicate.
+     * This is a convenience wrapper for the {@linkplain #loop(MethodHandle[][]) generic loop combinator}.
+     * <p>
+     * The {@code pred} handle describes the loop condition; and {@code body}, its body. The loop resulting from this
+     * method will, in each iteration, first evaluate the predicate and then execute its body (if the predicate
+     * evaluates to {@code true}).
+     * The loop will terminate once the predicate evaluates to {@code false} (the body will not be executed in this case).
+     * <p>
+     * The {@code init} handle describes the initial value of an additional optional loop-local variable.
+     * In each iteration, this loop-local variable, if present, will be passed to the {@code body}
+     * and updated with the value returned from its invocation. The result of loop execution will be
+     * the final value of the additional loop-local variable (if present).
      * <p>
-     * The loop handle's result type is the same as the sole loop variable's, i.e., the result type of {@code init}.
-     * The parameter type list of {@code init} also determines that of the resulting handle. The {@code pred} handle
-     * must have an additional leading parameter of the same type as {@code init}'s result, and so must the {@code
-     * body}. These constraints follow directly from those described for the {@linkplain MethodHandles#loop(MethodHandle[][])
-     * generic loop combinator}.
+     * The following rules hold for these argument handles:<ul>
+     * <li>The {@code body} handle must not be {@code null}; its type must be of the form
+     * {@code (V A...)V}, where {@code V} is non-{@code void}, or else {@code (A...)void}.
+     * (In the {@code void} case, we assign the type {@code void} to the name {@code V},
+     * and we will write {@code (V A...)V} with the understanding that a {@code void} type {@code V}
+     * is quietly dropped from the parameter list, leaving {@code (A...)V}.)
+     * <li>The parameter list {@code (V A...)} of the body is called the <em>internal parameter list</em>.
+     * It will constrain the parameter lists of the other loop parts.
+     * <li>If the iteration variable type {@code V} is dropped from the internal parameter list, the resulting shorter
+     * list {@code (A...)} is called the <em>external parameter list</em>.
+     * <li>The body return type {@code V}, if non-{@code void}, determines the type of an
+     * additional state variable of the loop.
+     * The body must both accept and return a value of this type {@code V}.
+     * <li>If {@code init} is non-{@code null}, it must have return type {@code V}.
+     * Its parameter list (of some <a href="MethodHandles.html#astar">form {@code (A*)}</a>) must be
+     * <a href="MethodHandles.html#effid">effectively identical</a>
+     * to the external parameter list {@code (A...)}.
+     * <li>If {@code init} is {@code null}, the loop variable will be initialized to its
+     * {@linkplain #empty default value}.
+     * <li>The {@code pred} handle must not be {@code null}.  It must have {@code boolean} as its return type.
+     * Its parameter list (either empty or of the form {@code (V A*)}) must be
+     * effectively identical to the internal parameter list.
+     * </ul>
+     * <p>
+     * The resulting loop handle's result type and parameter signature are determined as follows:<ul>
+     * <li>The loop handle's result type is the result type {@code V} of the body.
+     * <li>The loop handle's parameter types are the types {@code (A...)},
+     * from the external parameter list.
+     * </ul>
      * <p>
      * Here is pseudocode for the resulting loop handle. In the code, {@code V}/{@code v} represent the type / value of
      * the sole loop variable as well as the result type of the loop; and {@code A}/{@code a}, that of the argument
      * passed to the loop.
      * <blockquote><pre>{@code
-     * V init(A);
-     * boolean pred(V, A);
-     * V body(V, A);
-     * V whileLoop(A a) {
-     *   V v = init(a);
-     *   while (pred(v, a)) {
-     *     v = body(v, a);
+     * V init(A...);
+     * boolean pred(V, A...);
+     * V body(V, A...);
+     * V whileLoop(A... a...) {
+     *   V v = init(a...);
+     *   while (pred(v, a...)) {
+     *     v = body(v, a...);
      *   }
      *   return v;
      * }
@@ -4434,58 +4785,96 @@
      * }</pre></blockquote>
      *
      * <p>
-     * @implSpec The implementation of this method is equivalent to:
+     * @apiNote The implementation of this method can be expressed as follows:
      * <blockquote><pre>{@code
      * MethodHandle whileLoop(MethodHandle init, MethodHandle pred, MethodHandle body) {
+     *     MethodHandle fini = (body.type().returnType() == void.class
+     *                         ? null : identity(body.type().returnType()));
      *     MethodHandle[]
-     *         checkExit = {null, null, pred, identity(init.type().returnType())},
-     *         varBody = {init, body};
+     *         checkExit = { null, null, pred, fini },
+     *         varBody   = { init, body };
      *     return loop(checkExit, varBody);
      * }
      * }</pre></blockquote>
      *
-     * @param init initializer: it should provide the initial value of the loop variable. This controls the loop's
-     *             result type. Passing {@code null} or a {@code void} init function will make the loop's result type
-     *             {@code void}.
-     * @param pred condition for the loop, which may not be {@code null}.
-     * @param body body of the loop, which may not be {@code null}.
+     * @param init optional initializer, providing the initial value of the loop variable.
+     *             May be {@code null}, implying a default initial value.  See above for other constraints.
+     * @param pred condition for the loop, which may not be {@code null}. Its result type must be {@code boolean}. See
+     *             above for other constraints.
+     * @param body body of the loop, which may not be {@code null}. It controls the loop parameters and result type.
+     *             See above for other constraints.
      *
-     * @return the value of the loop variable as the loop terminates.
-     * @throws IllegalArgumentException if any argument has a type inconsistent with the loop structure
+     * @return a method handle implementing the {@code while} loop as described by the arguments.
+     * @throws IllegalArgumentException if the rules for the arguments are violated.
+     * @throws NullPointerException if {@code pred} or {@code body} are {@code null}.
      *
-     * @see MethodHandles#loop(MethodHandle[][])
+     * @see #loop(MethodHandle[][])
+     * @see #doWhileLoop(MethodHandle, MethodHandle, MethodHandle)
      * @since 9
      */
     public static MethodHandle whileLoop(MethodHandle init, MethodHandle pred, MethodHandle body) {
-        MethodHandle fin = init == null || init.type().returnType() == void.class ? zero(void.class) :
-                identity(init.type().returnType());
-        MethodHandle[] checkExit = {null, null, pred, fin};
-        MethodHandle[] varBody = {init, body};
+        whileLoopChecks(init, pred, body);
+        MethodHandle fini = identityOrVoid(body.type().returnType());
+        MethodHandle[] checkExit = { null, null, pred, fini };
+        MethodHandle[] varBody = { init, body };
         return loop(checkExit, varBody);
     }
 
     /**
-     * Constructs a {@code do-while} loop from an initializer, a body, and a predicate. This is a convenience wrapper
-     * for the {@linkplain MethodHandles#loop(MethodHandle[][]) generic loop combinator}.
+     * Constructs a {@code do-while} loop from an initializer, a body, and a predicate.
+     * This is a convenience wrapper for the {@linkplain #loop(MethodHandle[][]) generic loop combinator}.
+     * <p>
+     * The {@code pred} handle describes the loop condition; and {@code body}, its body. The loop resulting from this
+     * method will, in each iteration, first execute its body and then evaluate the predicate.
+     * The loop will terminate once the predicate evaluates to {@code false} after an execution of the body.
+     * <p>
+     * The {@code init} handle describes the initial value of an additional optional loop-local variable.
+     * In each iteration, this loop-local variable, if present, will be passed to the {@code body}
+     * and updated with the value returned from its invocation. The result of loop execution will be
+     * the final value of the additional loop-local variable (if present).
      * <p>
-     * The loop handle's result type is the same as the sole loop variable's, i.e., the result type of {@code init}.
-     * The parameter type list of {@code init} also determines that of the resulting handle. The {@code pred} handle
-     * must have an additional leading parameter of the same type as {@code init}'s result, and so must the {@code
-     * body}. These constraints follow directly from those described for the {@linkplain MethodHandles#loop(MethodHandle[][])
-     * generic loop combinator}.
+     * The following rules hold for these argument handles:<ul>
+     * <li>The {@code body} handle must not be {@code null}; its type must be of the form
+     * {@code (V A...)V}, where {@code V} is non-{@code void}, or else {@code (A...)void}.
+     * (In the {@code void} case, we assign the type {@code void} to the name {@code V},
+     * and we will write {@code (V A...)V} with the understanding that a {@code void} type {@code V}
+     * is quietly dropped from the parameter list, leaving {@code (A...)V}.)
+     * <li>The parameter list {@code (V A...)} of the body is called the <em>internal parameter list</em>.
+     * It will constrain the parameter lists of the other loop parts.
+     * <li>If the iteration variable type {@code V} is dropped from the internal parameter list, the resulting shorter
+     * list {@code (A...)} is called the <em>external parameter list</em>.
+     * <li>The body return type {@code V}, if non-{@code void}, determines the type of an
+     * additional state variable of the loop.
+     * The body must both accept and return a value of this type {@code V}.
+     * <li>If {@code init} is non-{@code null}, it must have return type {@code V}.
+     * Its parameter list (of some <a href="MethodHandles.html#astar">form {@code (A*)}</a>) must be
+     * <a href="MethodHandles.html#effid">effectively identical</a>
+     * to the external parameter list {@code (A...)}.
+     * <li>If {@code init} is {@code null}, the loop variable will be initialized to its
+     * {@linkplain #empty default value}.
+     * <li>The {@code pred} handle must not be {@code null}.  It must have {@code boolean} as its return type.
+     * Its parameter list (either empty or of the form {@code (V A*)}) must be
+     * effectively identical to the internal parameter list.
+     * </ul>
+     * <p>
+     * The resulting loop handle's result type and parameter signature are determined as follows:<ul>
+     * <li>The loop handle's result type is the result type {@code V} of the body.
+     * <li>The loop handle's parameter types are the types {@code (A...)},
+     * from the external parameter list.
+     * </ul>
      * <p>
      * Here is pseudocode for the resulting loop handle. In the code, {@code V}/{@code v} represent the type / value of
      * the sole loop variable as well as the result type of the loop; and {@code A}/{@code a}, that of the argument
      * passed to the loop.
      * <blockquote><pre>{@code
-     * V init(A);
-     * boolean pred(V, A);
-     * V body(V, A);
-     * V doWhileLoop(A a) {
-     *   V v = init(a);
+     * V init(A...);
+     * boolean pred(V, A...);
+     * V body(V, A...);
+     * V doWhileLoop(A... a...) {
+     *   V v = init(a...);
      *   do {
-     *     v = body(v, a);
-     *   } while (pred(v, a));
+     *     v = body(v, a...);
+     *   } while (pred(v, a...));
      *   return v;
      * }
      * }</pre></blockquote>
@@ -4502,59 +4891,491 @@
      * }</pre></blockquote>
      *
      * <p>
-     * @implSpec The implementation of this method is equivalent to:
+     * @apiNote The implementation of this method can be expressed as follows:
      * <blockquote><pre>{@code
      * MethodHandle doWhileLoop(MethodHandle init, MethodHandle body, MethodHandle pred) {
-     *     MethodHandle[] clause = { init, body, pred, identity(init.type().returnType()) };
+     *     MethodHandle fini = (body.type().returnType() == void.class
+     *                         ? null : identity(body.type().returnType()));
+     *     MethodHandle[] clause = { init, body, pred, fini };
      *     return loop(clause);
      * }
      * }</pre></blockquote>
      *
+     * @param init optional initializer, providing the initial value of the loop variable.
+     *             May be {@code null}, implying a default initial value.  See above for other constraints.
+     * @param body body of the loop, which may not be {@code null}. It controls the loop parameters and result type.
+     *             See above for other constraints.
+     * @param pred condition for the loop, which may not be {@code null}. Its result type must be {@code boolean}. See
+     *             above for other constraints.
      *
-     * @param init initializer: it should provide the initial value of the loop variable. This controls the loop's
-     *             result type. Passing {@code null} or a {@code void} init function will make the loop's result type
-     *             {@code void}.
-     * @param pred condition for the loop, which may not be {@code null}.
-     * @param body body of the loop, which may not be {@code null}.
+     * @return a method handle implementing the {@code while} loop as described by the arguments.
+     * @throws IllegalArgumentException if the rules for the arguments are violated.
+     * @throws NullPointerException if {@code pred} or {@code body} are {@code null}.
      *
-     * @return the value of the loop variable as the loop terminates.
-     * @throws IllegalArgumentException if any argument has a type inconsistent with the loop structure
-     *
-     * @see MethodHandles#loop(MethodHandle[][])
+     * @see #loop(MethodHandle[][])
+     * @see #whileLoop(MethodHandle, MethodHandle, MethodHandle)
      * @since 9
      */
     public static MethodHandle doWhileLoop(MethodHandle init, MethodHandle body, MethodHandle pred) {
-        MethodHandle fin = init == null || init.type().returnType() == void.class ? zero(void.class) :
-                identity(init.type().returnType());
-        MethodHandle[] clause = {init, body, pred, fin};
+        whileLoopChecks(init, pred, body);
+        MethodHandle fini = identityOrVoid(body.type().returnType());
+        MethodHandle[] clause = {init, body, pred, fini };
         return loop(clause);
     }
 
+    private static void whileLoopChecks(MethodHandle init, MethodHandle pred, MethodHandle body) {
+        Objects.requireNonNull(pred);
+        Objects.requireNonNull(body);
+        MethodType bodyType = body.type();
+        Class<?> returnType = bodyType.returnType();
+        List<Class<?>> innerList = bodyType.parameterList();
+        List<Class<?>> outerList = innerList;
+        if (returnType == void.class) {
+            // OK
+        } else if (innerList.size() == 0 || innerList.get(0) != returnType) {
+            // leading V argument missing => error
+            MethodType expected = bodyType.insertParameterTypes(0, returnType);
+            throw misMatchedTypes("body function", bodyType, expected);
+        } else {
+            outerList = innerList.subList(1, innerList.size());
+        }
+        MethodType predType = pred.type();
+        if (predType.returnType() != boolean.class ||
+                !predType.effectivelyIdenticalParameters(0, innerList)) {
+            throw misMatchedTypes("loop predicate", predType, methodType(boolean.class, innerList));
+        }
+        if (init != null) {
+            MethodType initType = init.type();
+            if (initType.returnType() != returnType ||
+                    !initType.effectivelyIdenticalParameters(0, outerList)) {
+                throw misMatchedTypes("loop initializer", initType, methodType(returnType, outerList));
+            }
+        }
+    }
+
+    /**
+     * Constructs a loop that runs a given number of iterations.
+     * This is a convenience wrapper for the {@linkplain #loop(MethodHandle[][]) generic loop combinator}.
+     * <p>
+     * The number of iterations is determined by the {@code iterations} handle evaluation result.
+     * The loop counter {@code i} is an extra loop iteration variable of type {@code int}.
+     * It will be initialized to 0 and incremented by 1 in each iteration.
+     * <p>
+     * If the {@code body} handle returns a non-{@code void} type {@code V}, a leading loop iteration variable
+     * of that type is also present.  This variable is initialized using the optional {@code init} handle,
+     * or to the {@linkplain #empty default value} of type {@code V} if that handle is {@code null}.
+     * <p>
+     * In each iteration, the iteration variables are passed to an invocation of the {@code body} handle.
+     * A non-{@code void} value returned from the body (of type {@code V}) updates the leading
+     * iteration variable.
+     * The result of the loop handle execution will be the final {@code V} value of that variable
+     * (or {@code void} if there is no {@code V} variable).
+     * <p>
+     * The following rules hold for the argument handles:<ul>
+     * <li>The {@code iterations} handle must not be {@code null}, and must return
+     * the type {@code int}, referred to here as {@code I} in parameter type lists.
+     * <li>The {@code body} handle must not be {@code null}; its type must be of the form
+     * {@code (V I A...)V}, where {@code V} is non-{@code void}, or else {@code (I A...)void}.
+     * (In the {@code void} case, we assign the type {@code void} to the name {@code V},
+     * and we will write {@code (V I A...)V} with the understanding that a {@code void} type {@code V}
+     * is quietly dropped from the parameter list, leaving {@code (I A...)V}.)
+     * <li>The parameter list {@code (V I A...)} of the body contributes to a list
+     * of types called the <em>internal parameter list</em>.
+     * It will constrain the parameter lists of the other loop parts.
+     * <li>As a special case, if the body contributes only {@code V} and {@code I} types,
+     * with no additional {@code A} types, then the internal parameter list is extended by
+     * the argument types {@code A...} of the {@code iterations} handle.
+     * <li>If the iteration variable types {@code (V I)} are dropped from the internal parameter list, the resulting shorter
+     * list {@code (A...)} is called the <em>external parameter list</em>.
+     * <li>The body return type {@code V}, if non-{@code void}, determines the type of an
+     * additional state variable of the loop.
+     * The body must both accept a leading parameter and return a value of this type {@code V}.
+     * <li>If {@code init} is non-{@code null}, it must have return type {@code V}.
+     * Its parameter list (of some <a href="MethodHandles.html#astar">form {@code (A*)}</a>) must be
+     * <a href="MethodHandles.html#effid">effectively identical</a>
+     * to the external parameter list {@code (A...)}.
+     * <li>If {@code init} is {@code null}, the loop variable will be initialized to its
+     * {@linkplain #empty default value}.
+     * <li>The parameter list of {@code iterations} (of some form {@code (A*)}) must be
+     * effectively identical to the external parameter list {@code (A...)}.
+     * </ul>
+     * <p>
+     * The resulting loop handle's result type and parameter signature are determined as follows:<ul>
+     * <li>The loop handle's result type is the result type {@code V} of the body.
+     * <li>The loop handle's parameter types are the types {@code (A...)},
+     * from the external parameter list.
+     * </ul>
+     * <p>
+     * Here is pseudocode for the resulting loop handle. In the code, {@code V}/{@code v} represent the type / value of
+     * the second loop variable as well as the result type of the loop; and {@code A...}/{@code a...} represent
+     * arguments passed to the loop.
+     * <blockquote><pre>{@code
+     * int iterations(A...);
+     * V init(A...);
+     * V body(V, int, A...);
+     * V countedLoop(A... a...) {
+     *   int end = iterations(a...);
+     *   V v = init(a...);
+     *   for (int i = 0; i < end; ++i) {
+     *     v = body(v, i, a...);
+     *   }
+     *   return v;
+     * }
+     * }</pre></blockquote>
+     * <p>
+     * @apiNote Example with a fully conformant body method:
+     * <blockquote><pre>{@code
+     * // String s = "Lambdaman!"; for (int i = 0; i < 13; ++i) { s = "na " + s; } return s;
+     * // => a variation on a well known theme
+     * static String step(String v, int counter, String init) { return "na " + v; }
+     * // assume MH_step is a handle to the method above
+     * MethodHandle fit13 = MethodHandles.constant(int.class, 13);
+     * MethodHandle start = MethodHandles.identity(String.class);
+     * MethodHandle loop = MethodHandles.countedLoop(fit13, start, MH_step);
+     * assertEquals("na na na na na na na na na na na na na Lambdaman!", loop.invoke("Lambdaman!"));
+     * }</pre></blockquote>
+     * <p>
+     * @apiNote Example with the simplest possible body method type,
+     * and passing the number of iterations to the loop invocation:
+     * <blockquote><pre>{@code
+     * // String s = "Lambdaman!"; for (int i = 0; i < 13; ++i) { s = "na " + s; } return s;
+     * // => a variation on a well known theme
+     * static String step(String v, int counter ) { return "na " + v; }
+     * // assume MH_step is a handle to the method above
+     * MethodHandle count = MethodHandles.dropArguments(MethodHandles.identity(int.class), 1, String.class);
+     * MethodHandle start = MethodHandles.dropArguments(MethodHandles.identity(String.class), 0, int.class);
+     * MethodHandle loop = MethodHandles.countedLoop(count, start, MH_step);  // (v, i) -> "na " + v
+     * assertEquals("na na na na na na na na na na na na na Lambdaman!", loop.invoke(13, "Lambdaman!"));
+     * }</pre></blockquote>
+     * <p>
+     * @apiNote Example that treats the number of iterations, string to append to, and string to append
+     * as loop parameters:
+     * <blockquote><pre>{@code
+     * // String s = "Lambdaman!", t = "na"; for (int i = 0; i < 13; ++i) { s = t + " " + s; } return s;
+     * // => a variation on a well known theme
+     * static String step(String v, int counter, int iterations_, String pre, String start_) { return pre + " " + v; }
+     * // assume MH_step is a handle to the method above
+     * MethodHandle count = MethodHandles.identity(int.class);
+     * MethodHandle start = MethodHandles.dropArguments(MethodHandles.identity(String.class), 0, int.class, String.class);
+     * MethodHandle loop = MethodHandles.countedLoop(count, start, MH_step);  // (v, i, _, pre, _) -> pre + " " + v
+     * assertEquals("na na na na na na na na na na na na na Lambdaman!", loop.invoke(13, "na", "Lambdaman!"));
+     * }</pre></blockquote>
+     * <p>
+     * @apiNote Example that illustrates the usage of {@link #dropArgumentsToMatch(MethodHandle, int, List, int)}
+     * to enforce a loop type:
+     * <blockquote><pre>{@code
+     * // String s = "Lambdaman!", t = "na"; for (int i = 0; i < 13; ++i) { s = t + " " + s; } return s;
+     * // => a variation on a well known theme
+     * static String step(String v, int counter, String pre) { return pre + " " + v; }
+     * // assume MH_step is a handle to the method above
+     * MethodType loopType = methodType(String.class, String.class, int.class, String.class);
+     * MethodHandle count = MethodHandles.dropArgumentsToMatch(MethodHandles.identity(int.class),    0, loopType.parameterList(), 1);
+     * MethodHandle start = MethodHandles.dropArgumentsToMatch(MethodHandles.identity(String.class), 0, loopType.parameterList(), 2);
+     * MethodHandle body  = MethodHandles.dropArgumentsToMatch(MH_step,                              2, loopType.parameterList(), 0);
+     * MethodHandle loop = MethodHandles.countedLoop(count, start, body);  // (v, i, pre, _, _) -> pre + " " + v
+     * assertEquals("na na na na na na na na na na na na na Lambdaman!", loop.invoke("na", 13, "Lambdaman!"));
+     * }</pre></blockquote>
+     * <p>
+     * @apiNote The implementation of this method can be expressed as follows:
+     * <blockquote><pre>{@code
+     * MethodHandle countedLoop(MethodHandle iterations, MethodHandle init, MethodHandle body) {
+     *     return countedLoop(empty(iterations.type()), iterations, init, body);
+     * }
+     * }</pre></blockquote>
+     *
+     * @param iterations a non-{@code null} handle to return the number of iterations this loop should run. The handle's
+     *                   result type must be {@code int}. See above for other constraints.
+     * @param init optional initializer, providing the initial value of the loop variable.
+     *             May be {@code null}, implying a default initial value.  See above for other constraints.
+     * @param body body of the loop, which may not be {@code null}.
+     *             It controls the loop parameters and result type in the standard case (see above for details).
+     *             It must accept its own return type (if non-void) plus an {@code int} parameter (for the counter),
+     *             and may accept any number of additional types.
+     *             See above for other constraints.
+     *
+     * @return a method handle representing the loop.
+     * @throws NullPointerException if either of the {@code iterations} or {@code body} handles is {@code null}.
+     * @throws IllegalArgumentException if any argument violates the rules formulated above.
+     *
+     * @see #countedLoop(MethodHandle, MethodHandle, MethodHandle, MethodHandle)
+     * @since 9
+     */
+    public static MethodHandle countedLoop(MethodHandle iterations, MethodHandle init, MethodHandle body) {
+        return countedLoop(empty(iterations.type()), iterations, init, body);
+    }
+
     /**
-     * Constructs a loop that runs a given number of iterations. The loop counter is an {@code int} initialized from the
-     * {@code iterations} handle evaluation result. The counter is passed to the {@code body} function, so that must
-     * accept an initial {@code int} argument. The result of the loop execution is the final value of the additional
-     * local state. This is a convenience wrapper for the {@linkplain MethodHandles#loop(MethodHandle[][]) generic loop
-     * combinator}.
+     * Constructs a loop that counts over a range of numbers.
+     * This is a convenience wrapper for the {@linkplain #loop(MethodHandle[][]) generic loop combinator}.
+     * <p>
+     * The loop counter {@code i} is a loop iteration variable of type {@code int}.
+     * The {@code start} and {@code end} handles determine the start (inclusive) and end (exclusive)
+     * values of the loop counter.
+     * The loop counter will be initialized to the {@code int} value returned from the evaluation of the
+     * {@code start} handle and run to the value returned from {@code end} (exclusively) with a step width of 1.
+     * <p>
+     * If the {@code body} handle returns a non-{@code void} type {@code V}, a leading loop iteration variable
+     * of that type is also present.  This variable is initialized using the optional {@code init} handle,
+     * or to the {@linkplain #empty default value} of type {@code V} if that handle is {@code null}.
+     * <p>
+     * In each iteration, the iteration variables are passed to an invocation of the {@code body} handle.
+     * A non-{@code void} value returned from the body (of type {@code V}) updates the leading
+     * iteration variable.
+     * The result of the loop handle execution will be the final {@code V} value of that variable
+     * (or {@code void} if there is no {@code V} variable).
      * <p>
-     * The result type and parameter type list of {@code init} determine those of the resulting handle. The {@code
-     * iterations} handle must accept the same parameter types as {@code init} but return an {@code int}. The {@code
-     * body} handle must accept the same parameter types as well, preceded by an {@code int} parameter for the counter,
-     * and a parameter of the same type as {@code init}'s result. These constraints follow directly from those described
-     * for the {@linkplain MethodHandles#loop(MethodHandle[][]) generic loop combinator}.
+     * The following rules hold for the argument handles:<ul>
+     * <li>The {@code start} and {@code end} handles must not be {@code null}, and must both return
+     * the common type {@code int}, referred to here as {@code I} in parameter type lists.
+     * <li>The {@code body} handle must not be {@code null}; its type must be of the form
+     * {@code (V I A...)V}, where {@code V} is non-{@code void}, or else {@code (I A...)void}.
+     * (In the {@code void} case, we assign the type {@code void} to the name {@code V},
+     * and we will write {@code (V I A...)V} with the understanding that a {@code void} type {@code V}
+     * is quietly dropped from the parameter list, leaving {@code (I A...)V}.)
+     * <li>The parameter list {@code (V I A...)} of the body contributes to a list
+     * of types called the <em>internal parameter list</em>.
+     * It will constrain the parameter lists of the other loop parts.
+     * <li>As a special case, if the body contributes only {@code V} and {@code I} types,
+     * with no additional {@code A} types, then the internal parameter list is extended by
+     * the argument types {@code A...} of the {@code end} handle.
+     * <li>If the iteration variable types {@code (V I)} are dropped from the internal parameter list, the resulting shorter
+     * list {@code (A...)} is called the <em>external parameter list</em>.
+     * <li>The body return type {@code V}, if non-{@code void}, determines the type of an
+     * additional state variable of the loop.
+     * The body must both accept a leading parameter and return a value of this type {@code V}.
+     * <li>If {@code init} is non-{@code null}, it must have return type {@code V}.
+     * Its parameter list (of some <a href="MethodHandles.html#astar">form {@code (A*)}</a>) must be
+     * <a href="MethodHandles.html#effid">effectively identical</a>
+     * to the external parameter list {@code (A...)}.
+     * <li>If {@code init} is {@code null}, the loop variable will be initialized to its
+     * {@linkplain #empty default value}.
+     * <li>The parameter list of {@code start} (of some form {@code (A*)}) must be
+     * effectively identical to the external parameter list {@code (A...)}.
+     * <li>Likewise, the parameter list of {@code end} must be effectively identical
+     * to the external parameter list.
+     * </ul>
+     * <p>
+     * The resulting loop handle's result type and parameter signature are determined as follows:<ul>
+     * <li>The loop handle's result type is the result type {@code V} of the body.
+     * <li>The loop handle's parameter types are the types {@code (A...)},
+     * from the external parameter list.
+     * </ul>
      * <p>
      * Here is pseudocode for the resulting loop handle. In the code, {@code V}/{@code v} represent the type / value of
-     * the sole loop variable as well as the result type of the loop; and {@code A}/{@code a}, that of the argument
-     * passed to the loop.
+     * the second loop variable as well as the result type of the loop; and {@code A...}/{@code a...} represent
+     * arguments passed to the loop.
+     * <blockquote><pre>{@code
+     * int start(A...);
+     * int end(A...);
+     * V init(A...);
+     * V body(V, int, A...);
+     * V countedLoop(A... a...) {
+     *   int e = end(a...);
+     *   int s = start(a...);
+     *   V v = init(a...);
+     *   for (int i = s; i < e; ++i) {
+     *     v = body(v, i, a...);
+     *   }
+     *   return v;
+     * }
+     * }</pre></blockquote>
+     *
+     * <p>
+     * @apiNote The implementation of this method can be expressed as follows:
      * <blockquote><pre>{@code
-     * int iterations(A);
-     * V init(A);
-     * V body(int, V, A);
-     * V countedLoop(A a) {
-     *   int end = iterations(a);
-     *   V v = init(a);
-     *   for (int i = 0; i < end; ++i) {
-     *     v = body(i, v, a);
+     * MethodHandle countedLoop(MethodHandle start, MethodHandle end, MethodHandle init, MethodHandle body) {
+     *     MethodHandle returnVar = dropArguments(identity(init.type().returnType()), 0, int.class, int.class);
+     *     // assume MH_increment and MH_predicate are handles to implementation-internal methods with
+     *     // the following semantics:
+     *     // MH_increment: (int limit, int counter) -> counter + 1
+     *     // MH_predicate: (int limit, int counter) -> counter < limit
+     *     Class<?> counterType = start.type().returnType();  // int
+     *     Class<?> returnType = body.type().returnType();
+     *     MethodHandle incr = MH_increment, pred = MH_predicate, retv = null;
+     *     if (returnType != void.class) {  // ignore the V variable
+     *         incr = dropArguments(incr, 1, returnType);  // (limit, v, i) => (limit, i)
+     *         pred = dropArguments(pred, 1, returnType);  // ditto
+     *         retv = dropArguments(identity(returnType), 0, counterType); // ignore limit
+     *     }
+     *     body = dropArguments(body, 0, counterType);  // ignore the limit variable
+     *     MethodHandle[]
+     *         loopLimit  = { end, null, pred, retv }, // limit = end(); i < limit || return v
+     *         bodyClause = { init, body },            // v = init(); v = body(v, i)
+     *         indexVar   = { start, incr };           // i = start(); i = i + 1
+     *     return loop(loopLimit, bodyClause, indexVar);
+     * }
+     * }</pre></blockquote>
+     *
+     * @param start a non-{@code null} handle to return the start value of the loop counter, which must be {@code int}.
+     *              See above for other constraints.
+     * @param end a non-{@code null} handle to return the end value of the loop counter (the loop will run to
+     *            {@code end-1}). The result type must be {@code int}. See above for other constraints.
+     * @param init optional initializer, providing the initial value of the loop variable.
+     *             May be {@code null}, implying a default initial value.  See above for other constraints.
+     * @param body body of the loop, which may not be {@code null}.
+     *             It controls the loop parameters and result type in the standard case (see above for details).
+     *             It must accept its own return type (if non-void) plus an {@code int} parameter (for the counter),
+     *             and may accept any number of additional types.
+     *             See above for other constraints.
+     *
+     * @return a method handle representing the loop.
+     * @throws NullPointerException if any of the {@code start}, {@code end}, or {@code body} handles is {@code null}.
+     * @throws IllegalArgumentException if any argument violates the rules formulated above.
+     *
+     * @see #countedLoop(MethodHandle, MethodHandle, MethodHandle)
+     * @since 9
+     */
+    public static MethodHandle countedLoop(MethodHandle start, MethodHandle end, MethodHandle init, MethodHandle body) {
+        countedLoopChecks(start, end, init, body);
+        Class<?> counterType = start.type().returnType();  // int, but who's counting?
+        Class<?> limitType   = end.type().returnType();    // yes, int again
+        Class<?> returnType  = body.type().returnType();
+        MethodHandle incr = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_countedLoopStep);
+        MethodHandle pred = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_countedLoopPred);
+        MethodHandle retv = null;
+        if (returnType != void.class) {
+            incr = dropArguments(incr, 1, returnType);  // (limit, v, i) => (limit, i)
+            pred = dropArguments(pred, 1, returnType);  // ditto
+            retv = dropArguments(identity(returnType), 0, counterType);
+        }
+        body = dropArguments(body, 0, counterType);  // ignore the limit variable
+        MethodHandle[]
+            loopLimit  = { end, null, pred, retv }, // limit = end(); i < limit || return v
+            bodyClause = { init, body },            // v = init(); v = body(v, i)
+            indexVar   = { start, incr };           // i = start(); i = i + 1
+        return loop(loopLimit, bodyClause, indexVar);
+    }
+
+    private static void countedLoopChecks(MethodHandle start, MethodHandle end, MethodHandle init, MethodHandle body) {
+        Objects.requireNonNull(start);
+        Objects.requireNonNull(end);
+        Objects.requireNonNull(body);
+        Class<?> counterType = start.type().returnType();
+        if (counterType != int.class) {
+            MethodType expected = start.type().changeReturnType(int.class);
+            throw misMatchedTypes("start function", start.type(), expected);
+        } else if (end.type().returnType() != counterType) {
+            MethodType expected = end.type().changeReturnType(counterType);
+            throw misMatchedTypes("end function", end.type(), expected);
+        }
+        MethodType bodyType = body.type();
+        Class<?> returnType = bodyType.returnType();
+        List<Class<?>> innerList = bodyType.parameterList();
+        // strip leading V value if present
+        int vsize = (returnType == void.class ? 0 : 1);
+        if (vsize != 0 && (innerList.size() == 0 || innerList.get(0) != returnType)) {
+            // argument list has no "V" => error
+            MethodType expected = bodyType.insertParameterTypes(0, returnType);
+            throw misMatchedTypes("body function", bodyType, expected);
+        } else if (innerList.size() <= vsize || innerList.get(vsize) != counterType) {
+            // missing I type => error
+            MethodType expected = bodyType.insertParameterTypes(vsize, counterType);
+            throw misMatchedTypes("body function", bodyType, expected);
+        }
+        List<Class<?>> outerList = innerList.subList(vsize + 1, innerList.size());
+        if (outerList.isEmpty()) {
+            // special case; take lists from end handle
+            outerList = end.type().parameterList();
+            innerList = bodyType.insertParameterTypes(vsize + 1, outerList).parameterList();
+        }
+        MethodType expected = methodType(counterType, outerList);
+        if (!start.type().effectivelyIdenticalParameters(0, outerList)) {
+            throw misMatchedTypes("start parameter types", start.type(), expected);
+        }
+        if (end.type() != start.type() &&
+            !end.type().effectivelyIdenticalParameters(0, outerList)) {
+            throw misMatchedTypes("end parameter types", end.type(), expected);
+        }
+        if (init != null) {
+            MethodType initType = init.type();
+            if (initType.returnType() != returnType ||
+                !initType.effectivelyIdenticalParameters(0, outerList)) {
+                throw misMatchedTypes("loop initializer", initType, methodType(returnType, outerList));
+            }
+        }
+    }
+
+    /**
+     * Constructs a loop that ranges over the values produced by an {@code Iterator<T>}.
+     * This is a convenience wrapper for the {@linkplain #loop(MethodHandle[][]) generic loop combinator}.
+     * <p>
+     * The iterator itself will be determined by the evaluation of the {@code iterator} handle.
+     * Each value it produces will be stored in a loop iteration variable of type {@code T}.
+     * <p>
+     * If the {@code body} handle returns a non-{@code void} type {@code V}, a leading loop iteration variable
+     * of that type is also present.  This variable is initialized using the optional {@code init} handle,
+     * or to the {@linkplain #empty default value} of type {@code V} if that handle is {@code null}.
+     * <p>
+     * In each iteration, the iteration variables are passed to an invocation of the {@code body} handle.
+     * A non-{@code void} value returned from the body (of type {@code V}) updates the leading
+     * iteration variable.
+     * The result of the loop handle execution will be the final {@code V} value of that variable
+     * (or {@code void} if there is no {@code V} variable).
+     * <p>
+     * The following rules hold for the argument handles:<ul>
+     * <li>The {@code body} handle must not be {@code null}; its type must be of the form
+     * {@code (V T A...)V}, where {@code V} is non-{@code void}, or else {@code (T A...)void}.
+     * (In the {@code void} case, we assign the type {@code void} to the name {@code V},
+     * and we will write {@code (V T A...)V} with the understanding that a {@code void} type {@code V}
+     * is quietly dropped from the parameter list, leaving {@code (T A...)V}.)
+     * <li>The parameter list {@code (V T A...)} of the body contributes to a list
+     * of types called the <em>internal parameter list</em>.
+     * It will constrain the parameter lists of the other loop parts.
+     * <li>As a special case, if the body contributes only {@code V} and {@code T} types,
+     * with no additional {@code A} types, then the internal parameter list is extended by
+     * the argument types {@code A...} of the {@code iterator} handle; if it is {@code null} the
+     * single type {@code Iterable} is added and constitutes the {@code A...} list.
+     * <li>If the iteration variable types {@code (V T)} are dropped from the internal parameter list, the resulting shorter
+     * list {@code (A...)} is called the <em>external parameter list</em>.
+     * <li>The body return type {@code V}, if non-{@code void}, determines the type of an
+     * additional state variable of the loop.
+     * The body must both accept a leading parameter and return a value of this type {@code V}.
+     * <li>If {@code init} is non-{@code null}, it must have return type {@code V}.
+     * Its parameter list (of some <a href="MethodHandles.html#astar">form {@code (A*)}</a>) must be
+     * <a href="MethodHandles.html#effid">effectively identical</a>
+     * to the external parameter list {@code (A...)}.
+     * <li>If {@code init} is {@code null}, the loop variable will be initialized to its
+     * {@linkplain #empty default value}.
+     * <li>If the {@code iterator} handle is non-{@code null}, it must have the return
+     * type {@code java.util.Iterator} or a subtype thereof.
+     * The iterator it produces when the loop is executed will be assumed
+     * to yield values which can be converted to type {@code T}.
+     * <li>The parameter list of an {@code iterator} that is non-{@code null} (of some form {@code (A*)}) must be
+     * effectively identical to the external parameter list {@code (A...)}.
+     * <li>If {@code iterator} is {@code null} it defaults to a method handle which behaves
+     * like {@link java.lang.Iterable#iterator()}.  In that case, the internal parameter list
+     * {@code (V T A...)} must have at least one {@code A} type, and the default iterator
+     * handle parameter is adjusted to accept the leading {@code A} type, as if by
+     * the {@link MethodHandle#asType asType} conversion method.
+     * The leading {@code A} type must be {@code Iterable} or a subtype thereof, or an array type.
+     * This conversion step, done at loop construction time, must not throw a {@code WrongMethodTypeException}.
+     * </ul>
+     * <p>
+     * The type {@code T} may be either a primitive or reference.
+     * Since type {@code Iterator<T>} is erased in the method handle representation to the raw type {@code Iterator},
+     * the {@code iteratedLoop} combinator adjusts the leading argument type for {@code body} to {@code Object}
+     * as if by the {@link MethodHandle#asType asType} conversion method.
+     * Therefore, if an iterator of the wrong type appears as the loop is executed, runtime exceptions may occur
+     * as the result of dynamic conversions performed by {@link MethodHandle#asType(MethodType)}.
+     * <p>
+     * The resulting loop handle's result type and parameter signature are determined as follows:<ul>
+     * <li>The loop handle's result type is the result type {@code V} of the body.
+     * <li>The loop handle's parameter types are the types {@code (A...)},
+     * from the external parameter list.
+     * </ul>
+     * <p>
+     * Here is pseudocode for the resulting loop handle. In the code, {@code V}/{@code v} represent the type / value of
+     * the loop variable as well as the result type of the loop; {@code T}/{@code t}, that of the elements of the
+     * structure the loop iterates over, and {@code A...}/{@code a...} represent arguments passed to the loop.
+     * <blockquote><pre>{@code
+     * Iterator<T> iterator(A...);  // defaults to Iterable::iterator
+     * V init(A...);
+     * V body(V,T,A...);
+     * V iteratedLoop(A... a...) {
+     *   Iterator<T> it = iterator(a...);
+     *   V v = init(a...);
+     *   for (T t : it) {
+     *     v = body(v, t, a...);
      *   }
      *   return v;
      * }
@@ -4562,243 +5383,164 @@
      * <p>
      * @apiNote Example:
      * <blockquote><pre>{@code
-     * // String s = "Lambdaman!"; for (int i = 0; i < 13; ++i) { s = "na " + s; } return s;
-     * // => a variation on a well known theme
-     * static String start(String arg) { return arg; }
-     * static String step(int counter, String v, String arg) { return "na " + v; }
-     * // assume MH_start and MH_step are handles to the two methods above
-     * MethodHandle fit13 = MethodHandles.constant(int.class, 13);
-     * MethodHandle loop = MethodHandles.countedLoop(fit13, MH_start, MH_step);
-     * assertEquals("na na na na na na na na na na na na na Lambdaman!", loop.invoke("Lambdaman!"));
-     * }</pre></blockquote>
-     *
-     * <p>
-     * @implSpec The implementation of this method is equivalent to:
-     * <blockquote><pre>{@code
-     * MethodHandle countedLoop(MethodHandle iterations, MethodHandle init, MethodHandle body) {
-     *     return countedLoop(null, iterations, init, body);  // null => constant zero
-     * }
-     * }</pre></blockquote>
-     *
-     * @param iterations a handle to return the number of iterations this loop should run.
-     * @param init initializer for additional loop state. This determines the loop's result type.
-     *             Passing {@code null} or a {@code void} init function will make the loop's result type
-     *             {@code void}.
-     * @param body the body of the loop, which must not be {@code null}.
-     *             It must accept an initial {@code int} parameter (for the counter), and then any
-     *             additional loop-local variable plus loop parameters.
-     *
-     * @return a method handle representing the loop.
-     * @throws IllegalArgumentException if any argument has a type inconsistent with the loop structure
-     *
-     * @since 9
-     */
-    public static MethodHandle countedLoop(MethodHandle iterations, MethodHandle init, MethodHandle body) {
-        return countedLoop(null, iterations, init, body);
-    }
-
-    /**
-     * Constructs a loop that counts over a range of numbers. The loop counter is an {@code int} that will be
-     * initialized to the {@code int} value returned from the evaluation of the {@code start} handle and run to the
-     * value returned from {@code end} (exclusively) with a step width of 1. The counter value is passed to the {@code
-     * body} function in each iteration; it has to accept an initial {@code int} parameter
-     * for that. The result of the loop execution is the final value of the additional local state
-     * obtained by running {@code init}.
-     * This is a
-     * convenience wrapper for the {@linkplain MethodHandles#loop(MethodHandle[][]) generic loop combinator}.
-     * <p>
-     * The constraints for the {@code init} and {@code body} handles are the same as for {@link
-     * #countedLoop(MethodHandle, MethodHandle, MethodHandle)}. Additionally, the {@code start} and {@code end} handles
-     * must return an {@code int} and accept the same parameters as {@code init}.
-     * <p>
-     * Here is pseudocode for the resulting loop handle. In the code, {@code V}/{@code v} represent the type / value of
-     * the sole loop variable as well as the result type of the loop; and {@code A}/{@code a}, that of the argument
-     * passed to the loop.
-     * <blockquote><pre>{@code
-     * int start(A);
-     * int end(A);
-     * V init(A);
-     * V body(int, V, A);
-     * V countedLoop(A a) {
-     *   int s = start(a);
-     *   int e = end(a);
-     *   V v = init(a);
-     *   for (int i = s; i < e; ++i) {
-     *     v = body(i, v, a);
-     *   }
-     *   return v;
-     * }
-     * }</pre></blockquote>
-     *
-     * <p>
-     * @implSpec The implementation of this method is equivalent to:
-     * <blockquote><pre>{@code
-     * MethodHandle countedLoop(MethodHandle start, MethodHandle end, MethodHandle init, MethodHandle body) {
-     *     MethodHandle returnVar = dropArguments(identity(init.type().returnType()), 0, int.class, int.class);
-     *     // assume MH_increment and MH_lessThan are handles to x+1 and x<y of type int,
-     *     // assume MH_decrement is a handle to x-1 of type int
-     *     MethodHandle[]
-     *         indexVar = {start, MH_increment}, // i = start; i = i+1
-     *         loopLimit = {end, null,
-     *                       filterArgument(MH_lessThan, 0, MH_decrement), returnVar}, // i-1<end
-     *         bodyClause = {init,
-     *                       filterArgument(dropArguments(body, 1, int.class), 0, MH_decrement}; // v = body(i-1, v)
-     *     return loop(indexVar, loopLimit, bodyClause);
-     * }
-     * }</pre></blockquote>
-     *
-     * @param start a handle to return the start value of the loop counter.
-     *              If it is {@code null}, a constant zero is assumed.
-     * @param end a non-{@code null} handle to return the end value of the loop counter (the loop will run to {@code end-1}).
-     * @param init initializer for additional loop state. This determines the loop's result type.
-     *             Passing {@code null} or a {@code void} init function will make the loop's result type
-     *             {@code void}.
-     * @param body the body of the loop, which must not be {@code null}.
-     *             It must accept an initial {@code int} parameter (for the counter), and then any
-     *             additional loop-local variable plus loop parameters.
-     *
-     * @return a method handle representing the loop.
-     * @throws IllegalArgumentException if any argument has a type inconsistent with the loop structure
-     *
-     * @since 9
-     */
-    public static MethodHandle countedLoop(MethodHandle start, MethodHandle end, MethodHandle init, MethodHandle body) {
-        Class<?> resultType;
-        MethodHandle actualInit;
-        if (init == null) {
-            resultType = body == null ? void.class : body.type().returnType();
-            actualInit = empty(methodType(resultType));
-        } else {
-            resultType = init.type().returnType();
-            actualInit = init;
-        }
-        MethodHandle defaultResultHandle = resultType == void.class ? zero(void.class) : identity(resultType);
-        MethodHandle actualBody = body == null ? dropArguments(defaultResultHandle, 0, int.class) : body;
-        MethodHandle returnVar = dropArguments(defaultResultHandle, 0, int.class, int.class);
-        MethodHandle actualEnd = end == null ? constant(int.class, 0) : end;
-        MethodHandle decr = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_decrementCounter);
-        MethodHandle[] indexVar = {start, MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_countedLoopStep)};
-        MethodHandle[] loopLimit = {actualEnd, null,
-                filterArgument(MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_countedLoopPred), 0, decr),
-                returnVar};
-        MethodHandle[] bodyClause = {actualInit, filterArgument(dropArguments(actualBody, 1, int.class), 0, decr)};
-        return loop(indexVar, loopLimit, bodyClause);
-    }
-
-    /**
-     * Constructs a loop that ranges over the elements produced by an {@code Iterator<T>}.
-     * The iterator will be produced by the evaluation of the {@code iterator} handle.
-     * This handle must have {@link java.util.Iterator} as its return type.
-     * If this handle is passed as {@code null} the method {@link Iterable#iterator} will be used instead,
-     * and will be applied to a leading argument of the loop handle.
-     * Each value produced by the iterator is passed to the {@code body}, which must accept an initial {@code T} parameter.
-     * The result of the loop execution is the final value of the additional local state
-     * obtained by running {@code init}.
-     * <p>
-     * This is a convenience wrapper for the
-     * {@linkplain MethodHandles#loop(MethodHandle[][]) generic loop combinator}, and the constraints imposed on the {@code body}
-     * handle follow directly from those described for the latter.
-     * <p>
-     * Here is pseudocode for the resulting loop handle. In the code, {@code V}/{@code v} represent the type / value of
-     * the loop variable as well as the result type of the loop; {@code T}/{@code t}, that of the elements of the
-     * structure the loop iterates over, and {@code A}/{@code a}, that of the argument passed to the loop.
-     * <blockquote><pre>{@code
-     * Iterator<T> iterator(A);  // defaults to Iterable::iterator
-     * V init(A);
-     * V body(T,V,A);
-     * V iteratedLoop(A a) {
-     *   Iterator<T> it = iterator(a);
-     *   V v = init(a);
-     *   for (T t : it) {
-     *     v = body(t, v, a);
-     *   }
-     *   return v;
-     * }
-     * }</pre></blockquote>
-     * <p>
-     * The type {@code T} may be either a primitive or reference.
-     * Since type {@code Iterator<T>} is erased in the method handle representation to the raw type
-     * {@code Iterator}, the {@code iteratedLoop} combinator adjusts the leading argument type for {@code body}
-     * to {@code Object} as if by the {@link MethodHandle#asType asType} conversion method.
-     * Therefore, if an iterator of the wrong type appears as the loop is executed,
-     * runtime exceptions may occur as the result of dynamic conversions performed by {@code asType}.
-     * <p>
-     * @apiNote Example:
-     * <blockquote><pre>{@code
-     * // reverse a list
-     * static List<String> reverseStep(String e, List<String> r, List<String> l) {
+     * // get an iterator from a list
+     * static List<String> reverseStep(List<String> r, String e) {
      *   r.add(0, e);
      *   return r;
      * }
-     * static List<String> newArrayList(List<String> l) { return new ArrayList<>(); }
-     * // assume MH_reverseStep, MH_newArrayList are handles to the above methods
+     * static List<String> newArrayList() { return new ArrayList<>(); }
+     * // assume MH_reverseStep and MH_newArrayList are handles to the above methods
      * MethodHandle loop = MethodHandles.iteratedLoop(null, MH_newArrayList, MH_reverseStep);
      * List<String> list = Arrays.asList("a", "b", "c", "d", "e");
      * List<String> reversedList = Arrays.asList("e", "d", "c", "b", "a");
      * assertEquals(reversedList, (List<String>) loop.invoke(list));
      * }</pre></blockquote>
      * <p>
-     * @implSpec The implementation of this method is equivalent to (excluding error handling):
+     * @apiNote The implementation of this method can be expressed approximately as follows:
      * <blockquote><pre>{@code
      * MethodHandle iteratedLoop(MethodHandle iterator, MethodHandle init, MethodHandle body) {
-     *     // assume MH_next and MH_hasNext are handles to methods of Iterator
-     *     Class<?> itype = iterator.type().returnType();
-     *     Class<?> ttype = body.type().parameterType(0);
-     *     MethodHandle returnVar = dropArguments(identity(init.type().returnType()), 0, itype);
+     *     // assume MH_next, MH_hasNext, MH_startIter are handles to methods of Iterator/Iterable
+     *     Class<?> returnType = body.type().returnType();
+     *     Class<?> ttype = body.type().parameterType(returnType == void.class ? 0 : 1);
      *     MethodHandle nextVal = MH_next.asType(MH_next.type().changeReturnType(ttype));
+     *     MethodHandle retv = null, step = body, startIter = iterator;
+     *     if (returnType != void.class) {
+     *         // the simple thing first:  in (I V A...), drop the I to get V
+     *         retv = dropArguments(identity(returnType), 0, Iterator.class);
+     *         // body type signature (V T A...), internal loop types (I V A...)
+     *         step = swapArguments(body, 0, 1);  // swap V <-> T
+     *     }
+     *     if (startIter == null)  startIter = MH_getIter;
      *     MethodHandle[]
-     *         iterVar = {iterator, null, MH_hasNext, returnVar}, // it = iterator(); while (it.hasNext)
-     *         bodyClause = {init, filterArgument(body, 0, nextVal)};  // v = body(t, v, a);
+     *         iterVar    = { startIter, null, MH_hasNext, retv }, // it = iterator; while (it.hasNext())
+     *         bodyClause = { init, filterArguments(step, 0, nextVal) };  // v = body(v, t, a)
      *     return loop(iterVar, bodyClause);
      * }
      * }</pre></blockquote>
      *
-     * @param iterator a handle to return the iterator to start the loop.
-     *             The handle must have {@link java.util.Iterator} as its return type.
-     *             Passing {@code null} will make the loop call {@link Iterable#iterator()} on the first
-     *             incoming value.
-     * @param init initializer for additional loop state. This determines the loop's result type.
-     *             Passing {@code null} or a {@code void} init function will make the loop's result type
-     *             {@code void}.
-     * @param body the body of the loop, which must not be {@code null}.
-     *             It must accept an initial {@code T} parameter (for the iterated values), and then any
-     *             additional loop-local variable plus loop parameters.
+     * @param iterator an optional handle to return the iterator to start the loop.
+     *                 If non-{@code null}, the handle must return {@link java.util.Iterator} or a subtype.
+     *                 See above for other constraints.
+     * @param init optional initializer, providing the initial value of the loop variable.
+     *             May be {@code null}, implying a default initial value.  See above for other constraints.
+     * @param body body of the loop, which may not be {@code null}.
+     *             It controls the loop parameters and result type in the standard case (see above for details).
+     *             It must accept its own return type (if non-void) plus a {@code T} parameter (for the iterated values),
+     *             and may accept any number of additional types.
+     *             See above for other constraints.
      *
      * @return a method handle embodying the iteration loop functionality.
-     * @throws IllegalArgumentException if any argument has a type inconsistent with the loop structure
+     * @throws NullPointerException if the {@code body} handle is {@code null}.
+     * @throws IllegalArgumentException if any argument violates the above requirements.
      *
      * @since 9
      */
     public static MethodHandle iteratedLoop(MethodHandle iterator, MethodHandle init, MethodHandle body) {
-        checkIteratedLoop(iterator, body);
-        Class<?> resultType = init == null ?
-                body == null ? void.class : body.type().returnType() :
-                init.type().returnType();
-        boolean voidResult = resultType == void.class;
-
-        MethodHandle initIterator;
-        if (iterator == null) {
-            MethodHandle initit = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_initIterator);
-            initIterator = initit.asType(initit.type().changeParameterType(0,
-                    body.type().parameterType(voidResult ? 1 : 2)));
-        } else {
-            initIterator = iterator.asType(iterator.type().changeReturnType(Iterator.class));
+        Class<?> iterableType = iteratedLoopChecks(iterator, init, body);
+        Class<?> returnType = body.type().returnType();
+        MethodHandle hasNext = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_iteratePred);
+        MethodHandle nextRaw = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_iterateNext);
+        MethodHandle startIter;
+        MethodHandle nextVal;
+        {
+            MethodType iteratorType;
+            if (iterator == null) {
+                // derive argument type from body, if available, else use Iterable
+                startIter = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_initIterator);
+                iteratorType = startIter.type().changeParameterType(0, iterableType);
+            } else {
+                // force return type to the internal iterator class
+                iteratorType = iterator.type().changeReturnType(Iterator.class);
+                startIter = iterator;
+            }
+            Class<?> ttype = body.type().parameterType(returnType == void.class ? 0 : 1);
+            MethodType nextValType = nextRaw.type().changeReturnType(ttype);
+
+            // perform the asType transforms under an exception transformer, as per spec.:
+            try {
+                startIter = startIter.asType(iteratorType);
+                nextVal = nextRaw.asType(nextValType);
+            } catch (WrongMethodTypeException ex) {
+                throw new IllegalArgumentException(ex);
+            }
+        }
+
+        MethodHandle retv = null, step = body;
+        if (returnType != void.class) {
+            // the simple thing first:  in (I V A...), drop the I to get V
+            retv = dropArguments(identity(returnType), 0, Iterator.class);
+            // body type signature (V T A...), internal loop types (I V A...)
+            step = swapArguments(body, 0, 1);  // swap V <-> T
         }
 
-        Class<?> ttype = body.type().parameterType(0);
-
-        MethodHandle returnVar =
-                dropArguments(voidResult ? zero(void.class) : identity(resultType), 0, Iterator.class);
-        MethodHandle initnx = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_iterateNext);
-        MethodHandle nextVal = initnx.asType(initnx.type().changeReturnType(ttype));
-
-        MethodHandle[] iterVar = {initIterator, null, MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_iteratePred),
-                returnVar};
-        MethodHandle[] bodyClause = {init, filterArgument(body, 0, nextVal)};
-
+        MethodHandle[]
+            iterVar    = { startIter, null, hasNext, retv },
+            bodyClause = { init, filterArgument(step, 0, nextVal) };
         return loop(iterVar, bodyClause);
     }
 
+    private static Class<?> iteratedLoopChecks(MethodHandle iterator, MethodHandle init, MethodHandle body) {
+        Objects.requireNonNull(body);
+        MethodType bodyType = body.type();
+        Class<?> returnType = bodyType.returnType();
+        List<Class<?>> innerList = bodyType.parameterList();
+        // strip leading V value if present
+        int vsize = (returnType == void.class ? 0 : 1);
+        if (vsize != 0 && (innerList.size() == 0 || innerList.get(0) != returnType)) {
+            // argument list has no "V" => error
+            MethodType expected = bodyType.insertParameterTypes(0, returnType);
+            throw misMatchedTypes("body function", bodyType, expected);
+        } else if (innerList.size() <= vsize) {
+            // missing T type => error
+            MethodType expected = bodyType.insertParameterTypes(vsize, Object.class);
+            throw misMatchedTypes("body function", bodyType, expected);
+        }
+        //Class<?> elementType = innerList.get(vsize);  // do not need this
+        List<Class<?>> outerList = innerList.subList(vsize + 1, innerList.size());
+        if (outerList.isEmpty()) {
+            // special case; take lists from iterator handle
+            outerList = ((iterator != null)
+                    ? iterator.type().parameterList()
+                    : Arrays.asList(Iterable.class));
+            innerList = bodyType.insertParameterTypes(vsize + 1, outerList).parameterList();
+        }
+        if (iterator != null) {
+            MethodType itype = iterator.type();
+            if (!Iterator.class.isAssignableFrom(itype.returnType())) {
+                throw newIllegalArgumentException("iteratedLoop first argument must have Iterator return type");
+            }
+            if (!itype.effectivelyIdenticalParameters(0, outerList)) {
+                MethodType expected = methodType(itype.returnType(), outerList);
+                throw misMatchedTypes("iterator parameters", itype, expected);
+            }
+        }
+        if (init != null) {
+            MethodType initType = init.type();
+            if (initType.returnType() != returnType ||
+                    !initType.effectivelyIdenticalParameters(0, outerList)) {
+                throw misMatchedTypes("loop initializer", initType, methodType(returnType, outerList));
+            }
+        }
+        Class<?> iterableType = outerList.isEmpty() ? null : outerList.get(0);
+        if (iterableType != null && !Iterable.class.isAssignableFrom(iterableType) && !iterableType.isArray()) {
+            throw newIllegalArgumentException(
+                    "inferred first loop argument must be an array or inherit from Iterable: " + iterableType);
+        }
+        return iterableType;  // help the caller a bit
+    }
+
+    /*non-public*/ static MethodHandle swapArguments(MethodHandle mh, int i, int j) {
+        // there should be a better way to uncross my wires
+        int arity = mh.type().parameterCount();
+        int[] order = new int[arity];
+        for (int k = 0; k < arity; k++)  order[k] = k;
+        order[i] = j; order[j] = i;
+        Class<?>[] types = mh.type().parameterArray();
+        Class<?> ti = types[i]; types[i] = types[j]; types[j] = ti;
+        MethodType swapType = methodType(mh.type().returnType(), types);
+        return permuteArguments(mh, swapType, order);
+    }
+
     /**
      * Makes a method handle that adapts a {@code target} method handle by wrapping it in a {@code try-finally} block.
      * Another method handle, {@code cleanup}, represents the functionality of the {@code finally} block. Any exception
@@ -4880,220 +5622,33 @@
         List<Class<?>> cleanupParamTypes = cleanup.type().parameterList();
         Class<?> rtype = target.type().returnType();
 
-        checkTryFinally(target, cleanup);
+        tryFinallyChecks(target, cleanup);
 
         // Match parameter lists: if the cleanup has a shorter parameter list than the target, add ignored arguments.
         // The cleanup parameter list (minus the leading Throwable and result parameters) must be a sublist of the
         // target parameter list.
         cleanup = dropArgumentsToMatch(cleanup, (rtype == void.class ? 1 : 2), targetParamTypes, 0);
 
-        return MethodHandleImpl.makeTryFinally(target, cleanup, rtype, targetParamTypes);
-    }
-
-    /**
-     * Adapts a target method handle by pre-processing some of its arguments, starting at a given position, and then
-     * calling the target with the result of the pre-processing, inserted into the original sequence of arguments just
-     * before the folded arguments.
-     * <p>
-     * This method is closely related to {@link #foldArguments(MethodHandle, MethodHandle)}, but allows to control the
-     * position in the parameter list at which folding takes place. The argument controlling this, {@code pos}, is a
-     * zero-based index. The aforementioned method {@link #foldArguments(MethodHandle, MethodHandle)} assumes position
-     * 0.
-     * <p>
-     * @apiNote Example:
-     * <blockquote><pre>{@code
-    import static java.lang.invoke.MethodHandles.*;
-    import static java.lang.invoke.MethodType.*;
-    ...
-    MethodHandle trace = publicLookup().findVirtual(java.io.PrintStream.class,
-    "println", methodType(void.class, String.class))
-    .bindTo(System.out);
-    MethodHandle cat = lookup().findVirtual(String.class,
-    "concat", methodType(String.class, String.class));
-    assertEquals("boojum", (String) cat.invokeExact("boo", "jum"));
-    MethodHandle catTrace = foldArguments(cat, 1, trace);
-    // also prints "jum":
-    assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum"));
-     * }</pre></blockquote>
-     * <p>Here is pseudocode for the resulting adapter. In the code, {@code T}
-     * represents the result type of the {@code target} and resulting adapter.
-     * {@code V}/{@code v} represent the type and value of the parameter and argument
-     * of {@code target} that precedes the folding position; {@code V} also is
-     * the result type of the {@code combiner}. {@code A}/{@code a} denote the
-     * types and values of the {@code N} parameters and arguments at the folding
-     * position. {@code Z}/{@code z} and {@code B}/{@code b} represent the types
-     * and values of the {@code target} parameters and arguments that precede and
-     * follow the folded parameters and arguments starting at {@code pos},
-     * respectively.
-     * <blockquote><pre>{@code
-     * // there are N arguments in A...
-     * T target(Z..., V, A[N]..., B...);
-     * V combiner(A...);
-     * T adapter(Z... z, A... a, B... b) {
-     *   V v = combiner(a...);
-     *   return target(z..., v, a..., b...);
-     * }
-     * // and if the combiner has a void return:
-     * T target2(Z..., A[N]..., B...);
-     * void combiner2(A...);
-     * T adapter2(Z... z, A... a, B... b) {
-     *   combiner2(a...);
-     *   return target2(z..., a..., b...);
-     * }
-     * }</pre></blockquote>
-     * <p>
-     * <em>Note:</em> The resulting adapter is never a {@linkplain MethodHandle#asVarargsCollector
-     * variable-arity method handle}, even if the original target method handle was.
-     *
-     * @param target the method handle to invoke after arguments are combined
-     * @param pos the position at which to start folding and at which to insert the folding result; if this is {@code
-     *            0}, the effect is the same as for {@link #foldArguments(MethodHandle, MethodHandle)}.
-     * @param combiner method handle to call initially on the incoming arguments
-     * @return method handle which incorporates the specified argument folding logic
-     * @throws NullPointerException if either argument is null
-     * @throws IllegalArgumentException if {@code combiner}'s return type
-     *          is non-void and not the same as the argument type at position {@code pos} of
-     *          the target signature, or if the {@code N} argument types at position {@code pos}
-     *          of the target signature
-     *          (skipping one matching the {@code combiner}'s return type)
-     *          are not identical with the argument types of {@code combiner}
-     *
-     * @see #foldArguments(MethodHandle, MethodHandle)
-     * @since 9
-     */
-    public static MethodHandle foldArguments(MethodHandle target, int pos, MethodHandle combiner) {
-        MethodType targetType = target.type();
-        MethodType combinerType = combiner.type();
-        Class<?> rtype = foldArgumentChecks(pos, targetType, combinerType);
-        BoundMethodHandle result = target.rebind();
-        boolean dropResult = rtype == void.class;
-        LambdaForm lform = result.editor().foldArgumentsForm(1 + pos, dropResult, combinerType.basicType());
-        MethodType newType = targetType;
-        if (!dropResult) {
-            newType = newType.dropParameterTypes(pos, pos + 1);
-        }
-        result = result.copyWithExtendL(newType, lform, combiner);
-        return result;
+        // Use asFixedArity() to avoid unnecessary boxing of last argument for VarargsCollector case.
+        return MethodHandleImpl.makeTryFinally(target.asFixedArity(), cleanup.asFixedArity(), rtype, targetParamTypes);
     }
 
-    /**
-     * As {@see foldArguments(MethodHandle, int, MethodHandle)}, but with the
-     * added capability of selecting the arguments from the targets parameters
-     * to call the combiner with. This allows us to avoid some simple cases of
-     * permutations and padding the combiner with dropArguments to select the
-     * right argument, which may ultimately produce fewer intermediaries.
-     */
-    static MethodHandle foldArguments(MethodHandle target, int pos, MethodHandle combiner, int ... argPositions) {
-        MethodType targetType = target.type();
-        MethodType combinerType = combiner.type();
-        Class<?> rtype = foldArgumentChecks(pos, targetType, combinerType, argPositions);
-        BoundMethodHandle result = target.rebind();
-        boolean dropResult = rtype == void.class;
-        LambdaForm lform = result.editor().foldArgumentsForm(1 + pos, dropResult, combinerType.basicType(), argPositions);
-        MethodType newType = targetType;
-        if (!dropResult) {
-            newType = newType.dropParameterTypes(pos, pos + 1);
-        }
-        result = result.copyWithExtendL(newType, lform, combiner);
-        return result;
-    }
-
-    private static void checkLoop0(MethodHandle[][] clauses) {
-        if (clauses == null || clauses.length == 0) {
-            throw newIllegalArgumentException("null or no clauses passed");
-        }
-        if (Stream.of(clauses).anyMatch(Objects::isNull)) {
-            throw newIllegalArgumentException("null clauses are not allowed");
-        }
-        if (Stream.of(clauses).anyMatch(c -> c.length > 4)) {
-            throw newIllegalArgumentException("All loop clauses must be represented as MethodHandle arrays with at most 4 elements.");
-        }
-    }
-
-    private static void checkLoop1a(int i, MethodHandle in, MethodHandle st) {
-        if (in.type().returnType() != st.type().returnType()) {
-            throw misMatchedTypes("clause " + i + ": init and step return types", in.type().returnType(),
-                    st.type().returnType());
-        }
-    }
-
-    private static List<Class<?>> buildCommonSuffix(List<MethodHandle> init, List<MethodHandle> step, List<MethodHandle> pred, List<MethodHandle> fini, int cpSize) {
-        final List<Class<?>> empty = List.of();
-        final List<MethodHandle> nonNullInits = init.stream().filter(Objects::nonNull).collect(Collectors.toList());
-        if (nonNullInits.isEmpty()) {
-            final List<Class<?>> longest = Stream.of(step, pred, fini).flatMap(List::stream).filter(Objects::nonNull).
-                    // take only those that can contribute to a common suffix because they are longer than the prefix
-                    map(MethodHandle::type).filter(t -> t.parameterCount() > cpSize).map(MethodType::parameterList).
-                    reduce((p, q) -> p.size() >= q.size() ? p : q).orElse(empty);
-            return longest.size() == 0 ? empty : longest.subList(cpSize, longest.size());
-        } else {
-            return nonNullInits.stream().map(MethodHandle::type).map(MethodType::parameterList).
-                    reduce((p, q) -> p.size() >= q.size() ? p : q).get();
-        }
-    }
-
-    private static void checkLoop1b(List<MethodHandle> init, List<Class<?>> commonSuffix) {
-        if (init.stream().filter(Objects::nonNull).map(MethodHandle::type).map(MethodType::parameterList).
-                anyMatch(pl -> !pl.equals(commonSuffix.subList(0, pl.size())))) {
-            throw newIllegalArgumentException("found non-effectively identical init parameter type lists: " + init +
-                    " (common suffix: " + commonSuffix + ")");
-        }
-    }
-
-    private static void checkLoop1cd(List<MethodHandle> pred, List<MethodHandle> fini, Class<?> loopReturnType) {
-        if (fini.stream().filter(Objects::nonNull).map(MethodHandle::type).map(MethodType::returnType).
-                anyMatch(t -> t != loopReturnType)) {
-            throw newIllegalArgumentException("found non-identical finalizer return types: " + fini + " (return type: " +
-                    loopReturnType + ")");
-        }
-
-        if (!pred.stream().filter(Objects::nonNull).findFirst().isPresent()) {
-            throw newIllegalArgumentException("no predicate found", pred);
-        }
-        if (pred.stream().filter(Objects::nonNull).map(MethodHandle::type).map(MethodType::returnType).
-                anyMatch(t -> t != boolean.class)) {
-            throw newIllegalArgumentException("predicates must have boolean return type", pred);
-        }
-    }
-
-    private static void checkLoop2(List<MethodHandle> step, List<MethodHandle> pred, List<MethodHandle> fini, List<Class<?>> commonParameterSequence) {
-        final int cpSize = commonParameterSequence.size();
-        if (Stream.of(step, pred, fini).flatMap(List::stream).filter(Objects::nonNull).map(MethodHandle::type).
-                map(MethodType::parameterList).
-                anyMatch(pl -> pl.size() > cpSize || !pl.equals(commonParameterSequence.subList(0, pl.size())))) {
-            throw newIllegalArgumentException("found non-effectively identical parameter type lists:\nstep: " + step +
-                    "\npred: " + pred + "\nfini: " + fini + " (common parameter sequence: " + commonParameterSequence + ")");
-        }
-    }
-
-    private static void checkIteratedLoop(MethodHandle iterator, MethodHandle body) {
-        if (null != iterator && !Iterator.class.isAssignableFrom(iterator.type().returnType())) {
-            throw newIllegalArgumentException("iteratedLoop first argument must have Iterator return type");
-        }
-        if (null == body) {
-            throw newIllegalArgumentException("iterated loop body must not be null");
-        }
-    }
-
-    private static void checkTryFinally(MethodHandle target, MethodHandle cleanup) {
+    private static void tryFinallyChecks(MethodHandle target, MethodHandle cleanup) {
         Class<?> rtype = target.type().returnType();
         if (rtype != cleanup.type().returnType()) {
             throw misMatchedTypes("target and return types", cleanup.type().returnType(), rtype);
         }
-        List<Class<?>> cleanupParamTypes = cleanup.type().parameterList();
-        if (!Throwable.class.isAssignableFrom(cleanupParamTypes.get(0))) {
+        MethodType cleanupType = cleanup.type();
+        if (!Throwable.class.isAssignableFrom(cleanupType.parameterType(0))) {
             throw misMatchedTypes("cleanup first argument and Throwable", cleanup.type(), Throwable.class);
         }
-        if (rtype != void.class && cleanupParamTypes.get(1) != rtype) {
+        if (rtype != void.class && cleanupType.parameterType(1) != rtype) {
             throw misMatchedTypes("cleanup second argument and target return type", cleanup.type(), rtype);
         }
         // The cleanup parameter list (minus the leading Throwable and result parameters) must be a sublist of the
         // target parameter list.
         int cleanupArgIndex = rtype == void.class ? 1 : 2;
-        List<Class<?>> cleanupArgSuffix = cleanupParamTypes.subList(cleanupArgIndex, cleanupParamTypes.size());
-        List<Class<?>> targetParamTypes = target.type().parameterList();
-        if (targetParamTypes.size() < cleanupArgSuffix.size() ||
-                !cleanupArgSuffix.equals(targetParamTypes.subList(0, cleanupParamTypes.size() - cleanupArgIndex))) {
+        if (!cleanupType.effectivelyIdenticalParameters(cleanupArgIndex, target.type().parameterList())) {
             throw misMatchedTypes("cleanup parameters after (Throwable,result) and target parameter list prefix",
                     cleanup.type(), target.type());
         }
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java	Fri Sep 30 09:28:18 2016 -0700
@@ -809,6 +809,28 @@
         return sj.toString();
     }
 
+    /** True if my parameter list is effectively identical to the given full list,
+     *  after skipping the given number of my own initial parameters.
+     *  In other words, after disregarding {@code skipPos} parameters,
+     *  my remaining parameter list is no longer than the {@code fullList}, and
+     *  is equal to the same-length initial sublist of {@code fullList}.
+     */
+    /*non-public*/
+    boolean effectivelyIdenticalParameters(int skipPos, List<Class<?>> fullList) {
+        int myLen = ptypes.length, fullLen = fullList.size();
+        if (skipPos > myLen || myLen - skipPos > fullLen)
+            return false;
+        List<Class<?>> myList = Arrays.asList(ptypes);
+        if (skipPos != 0) {
+            myList = myList.subList(skipPos, myLen);
+            myLen -= skipPos;
+        }
+        if (fullLen == myLen)
+            return myList.equals(fullList);
+        else
+            return myList.equals(fullList.subList(0, myLen));
+    }
+
     /** True if the old return type can always be viewed (w/o casting) under new return type,
      *  and the new parameters can be viewed (w/o casting) under the old parameter types.
      */
--- a/jdk/src/java.base/share/classes/java/lang/module/ModuleInfo.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/lang/module/ModuleInfo.java	Fri Sep 30 09:28:18 2016 -0700
@@ -664,7 +664,7 @@
             try {
                 bb.get(b, off, len);
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -681,7 +681,7 @@
                 int ch = bb.get();
                 return (ch != 0);
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -690,7 +690,7 @@
             try {
                 return bb.get();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -699,7 +699,7 @@
             try {
                 return ((int) bb.get()) & 0xff;
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -708,7 +708,7 @@
             try {
                 return bb.getShort();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -717,7 +717,7 @@
             try {
                 return ((int) bb.getShort()) & 0xffff;
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -726,7 +726,7 @@
             try {
                 return bb.getChar();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -735,7 +735,7 @@
             try {
                 return bb.getInt();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -744,7 +744,7 @@
             try {
                 return bb.getLong();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -753,7 +753,7 @@
             try {
                 return bb.getFloat();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -762,7 +762,7 @@
             try {
                 return bb.getDouble();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java	Fri Sep 30 09:28:18 2016 -0700
@@ -597,10 +597,10 @@
         private final Module module;
         ProxyBuilder(ClassLoader loader, List<Class<?>> interfaces) {
             if (!VM.isModuleSystemInited()) {
-                throw new InternalError("Proxy is not supported until module system is fully initialzed");
+                throw new InternalError("Proxy is not supported until module system is fully initialized");
             }
             if (interfaces.size() > 65535) {
-                throw new IllegalArgumentException("interface limit exceeded");
+                throw new IllegalArgumentException("interface limit exceeded: " + interfaces.size());
             }
 
             Set<Class<?>> refTypes = referencedTypes(loader, interfaces);
--- a/jdk/src/java.base/share/classes/java/util/ArrayList.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/util/ArrayList.java	Fri Sep 30 09:28:18 2016 -0700
@@ -876,6 +876,8 @@
         int lastRet = -1; // index of last element returned; -1 if no such
         int expectedModCount = modCount;
 
+        Itr() {}
+
         public boolean hasNext() {
             return cursor != size;
         }
--- a/jdk/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java	Fri Sep 30 09:28:18 2016 -0700
@@ -2559,6 +2559,13 @@
      * exceptionally with a CompletionException with this exception as
      * cause.
      *
+     * <p>Unless overridden by a subclass, a new non-minimal
+     * CompletableFuture with all methods available can be obtained from
+     * a minimal CompletionStage via {@link #toCompletableFuture()}.
+     * For example, completion of a minimal stage can be awaited by
+     *
+     * <pre> {@code minimalStage.toCompletableFuture().join(); }</pre>
+     *
      * @return the new CompletionStage
      * @since 9
      */
@@ -2853,6 +2860,16 @@
         @Override public CompletableFuture<T> completeOnTimeout
             (T value, long timeout, TimeUnit unit) {
             throw new UnsupportedOperationException(); }
+        @Override public CompletableFuture<T> toCompletableFuture() {
+            Object r;
+            if ((r = result) != null)
+                return new CompletableFuture<T>(encodeRelay(r));
+            else {
+                CompletableFuture<T> d = new CompletableFuture<>();
+                unipush(new UniRelay<T,T>(d, this));
+                return d;
+            }
+        }
     }
 
     // VarHandle mechanics
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1191,7 +1191,7 @@
      * Default idle timeout value (in milliseconds) for the thread
      * triggering quiescence to park waiting for new work
      */
-    private static final long DEFAULT_KEEPALIVE = 60000L;
+    private static final long DEFAULT_KEEPALIVE = 60_000L;
 
     /**
      * Undershoot tolerance for idle timeouts
@@ -2303,7 +2303,6 @@
             throw new NullPointerException();
         long ms = Math.max(unit.toMillis(keepAliveTime), TIMEOUT_SLOP);
 
-        String prefix = "ForkJoinPool-" + nextPoolId() + "-worker-";
         int corep = Math.min(Math.max(corePoolSize, parallelism), MAX_CAP);
         long c = ((((long)(-corep)       << TC_SHIFT) & TC_MASK) |
                   (((long)(-parallelism) << RC_SHIFT) & RC_MASK));
@@ -2315,8 +2314,8 @@
         n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16;
         n = (n + 1) << 1; // power of two, including space for submission queues
 
+        this.workerNamePrefix = "ForkJoinPool-" + nextPoolId() + "-worker-";
         this.workQueues = new WorkQueue[n];
-        this.workerNamePrefix = prefix;
         this.factory = factory;
         this.ueh = handler;
         this.saturate = saturate;
@@ -2327,11 +2326,19 @@
         checkPermission();
     }
 
+    private Object newInstanceFromSystemProperty(String property)
+        throws ReflectiveOperationException {
+        String className = System.getProperty(property);
+        return (className == null)
+            ? null
+            : ClassLoader.getSystemClassLoader().loadClass(className)
+            .getConstructor().newInstance();
+    }
+
     /**
      * Constructor for common pool using parameters possibly
      * overridden by system properties
      */
-    @SuppressWarnings("deprecation") // Class.newInstance
     private ForkJoinPool(byte forCommonPoolOnly) {
         int parallelism = -1;
         ForkJoinWorkerThreadFactory fac = null;
@@ -2339,18 +2346,12 @@
         try {  // ignore exceptions in accessing/parsing properties
             String pp = System.getProperty
                 ("java.util.concurrent.ForkJoinPool.common.parallelism");
-            String fp = System.getProperty
-                ("java.util.concurrent.ForkJoinPool.common.threadFactory");
-            String hp = System.getProperty
-                ("java.util.concurrent.ForkJoinPool.common.exceptionHandler");
             if (pp != null)
                 parallelism = Integer.parseInt(pp);
-            if (fp != null)
-                fac = ((ForkJoinWorkerThreadFactory)ClassLoader.
-                           getSystemClassLoader().loadClass(fp).newInstance());
-            if (hp != null)
-                handler = ((UncaughtExceptionHandler)ClassLoader.
-                           getSystemClassLoader().loadClass(hp).newInstance());
+            fac = (ForkJoinWorkerThreadFactory) newInstanceFromSystemProperty(
+                "java.util.concurrent.ForkJoinPool.common.threadFactory");
+            handler = (UncaughtExceptionHandler) newInstanceFromSystemProperty(
+                "java.util.concurrent.ForkJoinPool.common.exceptionHandler");
         } catch (Exception ignore) {
         }
 
@@ -2373,8 +2374,8 @@
         n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16;
         n = (n + 1) << 1;
 
+        this.workerNamePrefix = "ForkJoinPool.commonPool-worker-";
         this.workQueues = new WorkQueue[n];
-        this.workerNamePrefix = "ForkJoinPool.commonPool-worker-";
         this.factory = fac;
         this.ueh = handler;
         this.saturate = null;
--- a/jdk/src/java.base/share/classes/java/util/concurrent/atomic/DoubleAccumulator.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/atomic/DoubleAccumulator.java	Fri Sep 30 09:28:18 2016 -0700
@@ -35,6 +35,9 @@
 
 package java.util.concurrent.atomic;
 
+import static java.lang.Double.doubleToRawLongBits;
+import static java.lang.Double.longBitsToDouble;
+
 import java.io.Serializable;
 import java.util.function.DoubleBinaryOperator;
 
@@ -91,7 +94,7 @@
     public DoubleAccumulator(DoubleBinaryOperator accumulatorFunction,
                              double identity) {
         this.function = accumulatorFunction;
-        base = this.identity = Double.doubleToRawLongBits(identity);
+        base = this.identity = doubleToRawLongBits(identity);
     }
 
     /**
@@ -101,18 +104,19 @@
      */
     public void accumulate(double x) {
         Cell[] as; long b, v, r; int m; Cell a;
-        if ((as = cells) != null ||
-            (r = Double.doubleToRawLongBits
-             (function.applyAsDouble
-              (Double.longBitsToDouble(b = base), x))) != b  && !casBase(b, r)) {
+        if ((as = cells) != null
+            || ((r = doubleToRawLongBits
+                (function.applyAsDouble(longBitsToDouble(b = base), x))) != b
+                && !casBase(b, r))) {
             boolean uncontended = true;
-            if (as == null || (m = as.length - 1) < 0 ||
-                (a = as[getProbe() & m]) == null ||
-                !(uncontended =
-                  (r = Double.doubleToRawLongBits
-                   (function.applyAsDouble
-                    (Double.longBitsToDouble(v = a.value), x))) == v ||
-                  a.cas(v, r)))
+            if (as == null
+                || (m = as.length - 1) < 0
+                || (a = as[getProbe() & m]) == null
+                || !(uncontended =
+                     ((r = doubleToRawLongBits
+                       (function.applyAsDouble
+                        (longBitsToDouble(v = a.value), x))) == v)
+                     || a.cas(v, r)))
                 doubleAccumulate(x, function, uncontended);
         }
     }
@@ -128,12 +132,12 @@
      */
     public double get() {
         Cell[] as = cells;
-        double result = Double.longBitsToDouble(base);
+        double result = longBitsToDouble(base);
         if (as != null) {
             for (Cell a : as)
                 if (a != null)
                     result = function.applyAsDouble
-                        (result, Double.longBitsToDouble(a.value));
+                        (result, longBitsToDouble(a.value));
         }
         return result;
     }
@@ -168,12 +172,12 @@
      */
     public double getThenReset() {
         Cell[] as = cells;
-        double result = Double.longBitsToDouble(base);
+        double result = longBitsToDouble(base);
         base = identity;
         if (as != null) {
             for (Cell a : as) {
                 if (a != null) {
-                    double v = Double.longBitsToDouble(a.value);
+                    double v = longBitsToDouble(a.value);
                     a.reset(identity);
                     result = function.applyAsDouble(result, v);
                 }
@@ -267,9 +271,9 @@
          * held by this proxy
          */
         private Object readResolve() {
-            double d = Double.longBitsToDouble(identity);
+            double d = longBitsToDouble(identity);
             DoubleAccumulator a = new DoubleAccumulator(function, d);
-            a.base = Double.doubleToRawLongBits(value);
+            a.base = doubleToRawLongBits(value);
             return a;
         }
     }
--- a/jdk/src/java.base/share/classes/java/util/concurrent/atomic/LongAccumulator.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/atomic/LongAccumulator.java	Fri Sep 30 09:28:18 2016 -0700
@@ -103,14 +103,16 @@
      */
     public void accumulate(long x) {
         Cell[] as; long b, v, r; int m; Cell a;
-        if ((as = cells) != null ||
-            (r = function.applyAsLong(b = base, x)) != b && !casBase(b, r)) {
+        if ((as = cells) != null
+            || ((r = function.applyAsLong(b = base, x)) != b
+                && !casBase(b, r))) {
             boolean uncontended = true;
-            if (as == null || (m = as.length - 1) < 0 ||
-                (a = as[getProbe() & m]) == null ||
-                !(uncontended =
-                  (r = function.applyAsLong(v = a.value, x)) == v ||
-                  a.cas(v, r)))
+            if (as == null
+                || (m = as.length - 1) < 0
+                || (a = as[getProbe() & m]) == null
+                || !(uncontended =
+                     (r = function.applyAsLong(v = a.value, x)) == v
+                     || a.cas(v, r)))
                 longAccumulate(x, function, uncontended);
         }
     }
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java	Fri Sep 30 09:28:18 2016 -0700
@@ -186,7 +186,9 @@
 
         if (result.getMajorVersion() != ImageHeader.MAJOR_VERSION ||
             result.getMinorVersion() != ImageHeader.MINOR_VERSION) {
-            throw new IOException("The image file \"" + name + "\" is not the correct version");
+            throw new IOException("The image file \"" + name + "\" is not " +
+                "the correct version. Major: " + result.getMajorVersion() +
+                ". Minor: " + result.getMinorVersion());
         }
 
         return result;
@@ -318,11 +320,11 @@
 
     private ByteBuffer readBuffer(long offset, long size) {
         if (offset < 0 || Integer.MAX_VALUE <= offset) {
-            throw new IndexOutOfBoundsException("offset");
+            throw new IndexOutOfBoundsException("Bad offset: " + offset);
         }
 
         if (size < 0 || Integer.MAX_VALUE <= size) {
-            throw new IndexOutOfBoundsException("size");
+            throw new IndexOutOfBoundsException("Bad size: " + size);
         }
 
         if (MAP_ALL) {
@@ -382,11 +384,13 @@
         long uncompressedSize = loc.getUncompressedSize();
 
         if (compressedSize < 0 || Integer.MAX_VALUE < compressedSize) {
-            throw new IndexOutOfBoundsException("Compressed size");
+            throw new IndexOutOfBoundsException(
+                "Bad compressed size: " + compressedSize);
         }
 
         if (uncompressedSize < 0 || Integer.MAX_VALUE < uncompressedSize) {
-            throw new IndexOutOfBoundsException("Uncompressed size");
+            throw new IndexOutOfBoundsException(
+                "Bad uncompressed size: " + uncompressedSize);
         }
 
         if (compressedSize == 0) {
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageHeader.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageHeader.java	Fri Sep 30 09:28:18 2016 -0700
@@ -79,7 +79,8 @@
         Objects.requireNonNull(buffer);
 
         if (buffer.capacity() != HEADER_SLOTS) {
-            throw new InternalError("jimage header not the correct size");
+            throw new InternalError(
+                "jimage header not the correct size: " + buffer.capacity());
         }
 
         int magic = buffer.get(0);
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageLocation.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageLocation.java	Fri Sep 30 09:28:18 2016 -0700
@@ -81,7 +81,8 @@
                 }
 
                 if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) {
-                    throw new InternalError("Invalid jimage attribute kind");
+                    throw new InternalError(
+                        "Invalid jimage attribute kind: " + kind);
                 }
 
                 int length = attributeLength(data);
@@ -91,7 +92,7 @@
                     value <<= 8;
 
                     if (!bytes.hasRemaining()) {
-                        throw new InternalError("\"Missing jimage attribute datad");
+                        throw new InternalError("Missing jimage attribute data");
                     }
 
                     value |= bytes.get() & 0xFF;
@@ -134,7 +135,8 @@
 
     long getAttribute(int kind) {
         if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) {
-            throw new InternalError("Invalid jimage attribute kind");
+            throw new InternalError(
+                "Invalid jimage attribute kind: " + kind);
         }
 
         return attributes[kind];
@@ -142,7 +144,8 @@
 
     String getAttributeString(int kind) {
         if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) {
-            throw new InternalError("Invalid jimage attribute kind");
+            throw new InternalError(
+                "Invalid jimage attribute kind: " + kind);
         }
 
         return getStrings().get((int)attributes[kind]);
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStream.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStream.java	Fri Sep 30 09:28:18 2016 -0700
@@ -82,7 +82,7 @@
 
     public void ensure(int needs) {
         if (needs < 0) {
-            throw new IndexOutOfBoundsException("needs");
+            throw new IndexOutOfBoundsException("Bad value: " + needs);
         }
 
         if (needs > buffer.remaining()) {
@@ -106,7 +106,7 @@
 
     public void skip(int n) {
         if (n < 0) {
-            throw new IndexOutOfBoundsException("n");
+            throw new IndexOutOfBoundsException("skip value = " + n);
         }
 
         buffer.position(buffer.position() + n);
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStringsReader.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStringsReader.java	Fri Sep 30 09:28:18 2016 -0700
@@ -151,7 +151,7 @@
         try {
             charsFromMUTF8(chars, bytes, offset, count);
         } catch (UTFDataFormatException ex) {
-            throw new InternalError("Attempt to convert non modified UTF-8 byte sequence");
+            throw new InternalError("Attempt to convert non modified UTF-8 byte sequence", ex);
         }
 
         return new String(chars);
@@ -199,7 +199,8 @@
                     ch = buffer.get();
 
                     if ((ch & 0xC0) != 0x80) {
-                        throw new InternalError("Bad continuation in modified UTF-8 byte sequence");
+                        throw new InternalError("Bad continuation in " +
+                            "modified UTF-8 byte sequence: " + ch);
                     }
 
                     uch = ((uch & ~mask) << 6) | (ch & 0x3F);
@@ -208,7 +209,8 @@
             }
 
             if ((uch & 0xFFFF) != uch) {
-                throw new InternalError("UTF-32 char in modified UTF-8 byte sequence");
+                throw new InternalError("UTF-32 char in modified UTF-8 " +
+                    "byte sequence: " + uch);
             }
 
             chars[j++] = (char)uch;
--- a/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java	Fri Sep 30 09:28:18 2016 -0700
@@ -183,7 +183,7 @@
     public PathMatcher getPathMatcher(String syntaxAndInput) {
         int pos = syntaxAndInput.indexOf(':');
         if (pos <= 0 || pos == syntaxAndInput.length()) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException("pos is " + pos);
         }
         String syntax = syntaxAndInput.substring(0, pos);
         String input = syntaxAndInput.substring(pos + 1);
@@ -285,7 +285,8 @@
         for (OpenOption option : options) {
             Objects.requireNonNull(option);
             if (!(option instanceof StandardOpenOption)) {
-                throw new IllegalArgumentException();
+                throw new IllegalArgumentException(
+                    "option class: " + option.getClass());
             }
         }
         if (options.contains(StandardOpenOption.WRITE) ||
--- a/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java	Fri Sep 30 09:28:18 2016 -0700
@@ -122,7 +122,8 @@
     public final JrtPath getName(int index) {
         initOffsets();
         if (index < 0 || index >= offsets.length) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException("index: " +
+                index + ", offsets length: " + offsets.length);
         }
         int begin = offsets[index];
         int end;
@@ -139,7 +140,9 @@
         initOffsets();
         if (beginIndex < 0 || endIndex > offsets.length ||
             beginIndex >= endIndex) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException(
+                "beginIndex: " + beginIndex + ", endIndex: " + endIndex +
+                ", offsets length: " + offsets.length);
         }
         // starting/ending offsets
         int begin = offsets[beginIndex];
@@ -211,7 +214,8 @@
             return o;
         }
         if (jrtfs != o.jrtfs || isAbsolute() != o.isAbsolute()) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException(
+                "Incorrect filesystem or path: " + other);
         }
         final String tp = this.path;
         final String op = o.path;
@@ -366,7 +370,8 @@
     private JrtPath checkPath(Path path) {
         Objects.requireNonNull(path);
         if (!(path instanceof JrtPath))
-            throw new ProviderMismatchException();
+            throw new ProviderMismatchException("path class: " +
+                path.getClass());
         return (JrtPath) path;
     }
 
@@ -459,7 +464,7 @@
             }
             if (c == '\u0000') {
                 throw new InvalidPathException(path,
-                        "Path: nul character not allowed");
+                        "Path: NUL character not allowed");
             }
             to.append(c);
             prevC = c;
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1603,11 +1603,50 @@
         return weakCompareAndSwapShort(o, offset, c2s(expected), c2s(x));
     }
 
+    /**
+     * The JVM converts integral values to boolean values using two
+     * different conventions, byte testing against zero and truncation
+     * to least-significant bit.
+     *
+     * <p>The JNI documents specify that, at least for returning
+     * values from native methods, a Java boolean value is converted
+     * to the value-set 0..1 by first truncating to a byte (0..255 or
+     * maybe -128..127) and then testing against zero. Thus, Java
+     * booleans in non-Java data structures are by convention
+     * represented as 8-bit containers containing either zero (for
+     * false) or any non-zero value (for true).
+     *
+     * <p>Java booleans in the heap are also stored in bytes, but are
+     * strongly normalized to the value-set 0..1 (i.e., they are
+     * truncated to the least-significant bit).
+     *
+     * <p>The main reason for having different conventions for
+     * conversion is performance: Truncation to the least-significant
+     * bit can be usually implemented with fewer (machine)
+     * instructions than byte testing against zero.
+     *
+     * <p>A number of Unsafe methods load boolean values from the heap
+     * as bytes. Unsafe converts those values according to the JNI
+     * rules (i.e, using the "testing against zero" convention). The
+     * method {@code byte2bool} implements that conversion.
+     *
+     * @param b the byte to be converted to boolean
+     * @return the result of the conversion
+     */
     @ForceInline
     private boolean byte2bool(byte b) {
-        return b > 0;
-    }
-
+        return b != 0;
+    }
+
+    /**
+     * Convert a boolean value to a byte. The return value is strongly
+     * normalized to the value-set 0..1 (i.e., the value is truncated
+     * to the least-significant bit). See {@link #byte2bool(byte)} for
+     * more details on conversion conventions.
+     *
+     * @param b the boolean to be converted to byte (and then normalized)
+     * @return the result of the conversion
+     */
     @ForceInline
     private byte bool2byte(boolean b) {
         return b ? (byte)1 : (byte)0;
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/VM.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/VM.java	Fri Sep 30 09:28:18 2016 -0700
@@ -50,7 +50,7 @@
     public static void initLevel(int value) {
         synchronized (lock) {
             if (value <= initLevel || value > SYSTEM_BOOTED)
-                throw new InternalError();
+                throw new InternalError("Bad level: " + value);
             initLevel = value;
             lock.notifyAll();
         }
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java	Fri Sep 30 09:28:18 2016 -0700
@@ -153,27 +153,24 @@
         boolean addAllDefaultModules = false;
         boolean addAllSystemModules = false;
         boolean addAllApplicationModules = false;
-        String propValue = getAndRemoveProperty("jdk.module.addmods");
-        if (propValue != null) {
-            for (String mod: propValue.split(",")) {
-                switch (mod) {
-                    case ALL_DEFAULT:
-                        addAllDefaultModules = true;
-                        break;
-                    case ALL_SYSTEM:
-                        addAllSystemModules = true;
-                        break;
-                    case ALL_MODULE_PATH:
-                        addAllApplicationModules = true;
-                        break;
-                    default :
-                        roots.add(mod);
-                }
+        for (String mod: getExtraAddModules()) {
+            switch (mod) {
+                case ALL_DEFAULT:
+                    addAllDefaultModules = true;
+                    break;
+                case ALL_SYSTEM:
+                    addAllSystemModules = true;
+                    break;
+                case ALL_MODULE_PATH:
+                    addAllApplicationModules = true;
+                    break;
+                default :
+                    roots.add(mod);
             }
         }
 
         // --limit-modules
-        propValue = getAndRemoveProperty("jdk.module.limitmods");
+        String propValue = getAndRemoveProperty("jdk.module.limitmods");
         if (propValue != null) {
             Set<String> mods = new HashSet<>();
             for (String mod: propValue.split(",")) {
@@ -392,6 +389,32 @@
         }
     }
 
+    /**
+     * Returns the set of module names specified via --add-modules options
+     * on the command line
+     */
+    private static Set<String> getExtraAddModules() {
+        String prefix = "jdk.module.addmods.";
+        int index = 0;
+
+        // the system property is removed after decoding
+        String value = getAndRemoveProperty(prefix + index);
+        if (value == null) {
+            return Collections.emptySet();
+        }
+
+        Set<String> modules = new HashSet<>();
+        while (value != null) {
+            for (String s : value.split(",")) {
+                if (s.length() > 0) modules.add(s);
+            }
+
+            index++;
+            value = getAndRemoveProperty(prefix + index);
+        }
+
+        return modules;
+    }
 
     /**
      * Process the --add-reads options to add any additional read edges that
@@ -514,7 +537,7 @@
 
             // value is <module>(,<module>)*
             if (map.containsKey(key))
-                fail(key + " specified more than once");
+                 fail(key + " specified more than once");
 
             Set<String> values = new HashSet<>();
             map.put(key, values);
--- a/jdk/src/java.base/share/classes/module-info.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/module-info.java	Fri Sep 30 09:28:18 2016 -0700
@@ -166,6 +166,7 @@
         jdk.charsets,
         jdk.compiler,
         jdk.jartool,
+        jdk.jdeps,
         jdk.jlink,
         jdk.net,
         jdk.scripting.nashorn,
@@ -189,7 +190,8 @@
         jdk.unsupported,
         jdk.vm.ci;
     exports jdk.internal.util.jar to
-        jdk.jartool;
+        jdk.jartool,
+        jdk.jdeps;
     exports jdk.internal.vm to
         java.management,
         jdk.jvmstat;
--- a/jdk/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -328,8 +328,6 @@
     public SocketAddress receive(ByteBuffer dst) throws IOException {
         if (dst.isReadOnly())
             throw new IllegalArgumentException("Read-only buffer");
-        if (dst == null)
-            throw new NullPointerException();
         synchronized (readLock) {
             ensureOpen();
             // Socket was not bound before attempting receive
@@ -716,8 +714,6 @@
 
     @Override
     public DatagramChannel connect(SocketAddress sa) throws IOException {
-        int localPort = 0;
-
         synchronized(readLock) {
             synchronized(writeLock) {
                 synchronized (stateLock) {
--- a/jdk/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -616,8 +616,6 @@
     }
 
     public boolean connect(SocketAddress sa) throws IOException {
-        int localPort = 0;
-
         synchronized (readLock) {
             synchronized (writeLock) {
                 ensureOpenAndUnconnected();
--- a/jdk/src/java.base/share/classes/sun/security/provider/SeedGenerator.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/sun/security/provider/SeedGenerator.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -344,7 +344,8 @@
                         try {
                             BogusThread bt = new BogusThread();
                             Thread t = new Thread
-                                (seedGroup, bt, "SeedGenerator Thread", 0, false);
+                                (seedGroup, bt, "SeedGenerator Thread", 0,
+                                        false);
                             t.start();
                         } catch (Exception e) {
                             throw new InternalError("internal error: " +
@@ -357,7 +358,8 @@
                         long startTime = System.nanoTime();
                         while (System.nanoTime() - startTime < 250000000) {
                             synchronized(this){};
-                            latch++;
+                            // Mask the sign bit and keep latch non-negative
+                            latch = (latch + 1) & 0x1FFFFFFF;
                         }
 
                         // Translate the value using the permutation, and xor
@@ -431,7 +433,7 @@
         // data and using it to mix the trivial permutation.
         // It should be evenly distributed. The specific values
         // are not crucial to the security of this class.
-        private static byte[] rndTab = {
+        private static final byte[] rndTab = {
             56, 30, -107, -6, -86, 25, -83, 75, -12, -64,
             5, -128, 78, 21, 16, 32, 70, -81, 37, -51,
             -43, -46, -108, 87, 29, 17, -55, 22, -11, -111,
--- a/jdk/src/java.base/share/classes/sun/security/rsa/RSASignature.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/classes/sun/security/rsa/RSASignature.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -182,14 +182,15 @@
     }
 
     // verify the data and return the result. See JCA doc
+    // should be reset to the state after engineInitVerify call.
     protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
-        if (sigBytes.length != RSACore.getByteLength(publicKey)) {
-            throw new SignatureException("Signature length not correct: got " +
+        try {
+            if (sigBytes.length != RSACore.getByteLength(publicKey)) {
+                throw new SignatureException("Signature length not correct: got " +
                     sigBytes.length + " but was expecting " +
                     RSACore.getByteLength(publicKey));
-        }
-        byte[] digest = getDigestValue();
-        try {
+            }
+            byte[] digest = getDigestValue();
             byte[] decrypted = RSACore.rsa(sigBytes, publicKey);
             byte[] unpadded = padding.unpad(decrypted);
             byte[] decodedDigest = decodeSignature(digestOID, unpadded);
@@ -202,6 +203,8 @@
             return false;
         } catch (IOException e) {
             throw new SignatureException("Signature encoding error", e);
+        } finally {
+            resetDigest();
         }
     }
 
--- a/jdk/src/java.base/share/native/include/jvm.h	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/share/native/include/jvm.h	Fri Sep 30 09:28:18 2016 -0700
@@ -179,6 +179,7 @@
  */
 enum {
   JVM_STACKWALK_FILL_CLASS_REFS_ONLY       = 0x2,
+  JVM_STACKWALK_GET_CALLER_CLASS           = 0x04,
   JVM_STACKWALK_SHOW_HIDDEN_FRAMES         = 0x20,
   JVM_STACKWALK_FILL_LIVE_STACK_FRAMES     = 0x100
 };
--- a/jdk/src/java.base/unix/native/libjava/ProcessImpl_md.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/unix/native/libjava/ProcessImpl_md.c	Fri Sep 30 09:28:18 2016 -0700
@@ -152,8 +152,8 @@
 #ifdef __solaris__
     /* These really are the Solaris defaults! */
     return (geteuid() == 0 || getuid() == 0) ?
-        "/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin:/usr/sbin" :
-        "/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin:";
+        "/usr/xpg4/bin:/usr/bin:/opt/SUNWspro/bin:/usr/sbin" :
+        "/usr/xpg4/bin:/usr/bin:/opt/SUNWspro/bin:";
 #else
     return ":/bin:/usr/bin";    /* glibc */
 #endif
--- a/jdk/src/java.base/unix/native/libjli/java_md.h	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/unix/native/libjli/java_md.h	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,12 +35,12 @@
 #include "manifest_info.h"
 #include "jli_util.h"
 
-#define PATH_SEPARATOR          ':'
-#define FILESEP                 "/"
-#define FILE_SEPARATOR          '/'
+#define PATH_SEPARATOR       ':'
+#define FILESEP              "/"
+#define FILE_SEPARATOR       '/'
 #define IS_FILE_SEPARATOR(c) ((c) == '/')
 #ifndef MAXNAMELEN
-#define MAXNAMELEN              PATH_MAX
+#define MAXNAMELEN           PATH_MAX
 #endif
 
 #ifdef _LP64
@@ -59,10 +59,13 @@
 static jboolean GetJREPath(char *path, jint pathsize, const char * arch,
                            jboolean speculative);
 
+#if defined(_AIX)
+#include "java_md_aix.h"
+#endif
+
 #ifdef MACOSX
 #include "java_md_macosx.h"
 #else  /* !MACOSX */
 #include "java_md_solinux.h"
 #endif /* MACOSX */
-
 #endif /* JAVA_MD_H */
--- a/jdk/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c	Fri Sep 30 09:28:18 2016 -0700
@@ -1302,7 +1302,7 @@
  * Sets the multicast loopback mode.
  */
 static void setMulticastLoopbackMode(JNIEnv *env, jobject this, int fd,
-                                  jint opt, jobject value) {
+                                     jint opt, jobject value) {
 #ifdef AF_INET6
 #ifdef __linux__
     mcast_set_loop_v4(env, this, fd, value);
@@ -1330,10 +1330,9 @@
  * Signature: (ILjava/lang/Object;)V
  */
 JNIEXPORT void JNICALL
-Java_java_net_PlainDatagramSocketImpl_socketSetOption0(JNIEnv *env,
-                                                      jobject this,
-                                                      jint opt,
-                                                      jobject value) {
+Java_java_net_PlainDatagramSocketImpl_socketSetOption0
+  (JNIEnv *env, jobject this, jint opt, jobject value)
+{
     int fd;
     int level, optname, optlen;
     int optval;
@@ -1380,7 +1379,7 @@
      * level and option name.
      */
     if (NET_MapSocketOption(opt, &level, &optname)) {
-        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
+        JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
         return;
     }
 
@@ -1699,8 +1698,9 @@
  * Signature: (I)Ljava/lang/Object;
  */
 JNIEXPORT jobject JNICALL
-Java_java_net_PlainDatagramSocketImpl_socketGetOption(JNIEnv *env, jobject this,
-                                                      jint opt) {
+Java_java_net_PlainDatagramSocketImpl_socketGetOption
+  (JNIEnv *env, jobject this, jint opt)
+{
     int fd;
     int level, optname, optlen;
     union {
@@ -1751,7 +1751,7 @@
      * level and option name.
      */
     if (NET_MapSocketOption(opt, &level, &optname)) {
-        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
+        JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
         return NULL;
     }
 
--- a/jdk/src/java.base/unix/native/libnet/PlainSocketImpl.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/unix/native/libnet/PlainSocketImpl.c	Fri Sep 30 09:28:18 2016 -0700
@@ -855,9 +855,9 @@
  * Signature: (IZLjava/lang/Object;)V
  */
 JNIEXPORT void JNICALL
-Java_java_net_PlainSocketImpl_socketSetOption0(JNIEnv *env, jobject this,
-                                              jint cmd, jboolean on,
-                                              jobject value) {
+Java_java_net_PlainSocketImpl_socketSetOption0
+  (JNIEnv *env, jobject this, jint cmd, jboolean on, jobject value)
+{
     int fd;
     int level, optname, optlen;
     union {
@@ -887,7 +887,7 @@
      * level and option name.
      */
     if (NET_MapSocketOption(cmd, &level, &optname)) {
-        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
+        JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
         return;
     }
 
@@ -951,9 +951,9 @@
  * Signature: (I)I
  */
 JNIEXPORT jint JNICALL
-Java_java_net_PlainSocketImpl_socketGetOption(JNIEnv *env, jobject this,
-                                              jint cmd, jobject iaContainerObj) {
-
+Java_java_net_PlainSocketImpl_socketGetOption
+  (JNIEnv *env, jobject this, jint cmd, jobject iaContainerObj)
+{
     int fd;
     int level, optname, optlen;
     union {
@@ -1004,7 +1004,7 @@
      * level and option name.
      */
     if (NET_MapSocketOption(cmd, &level, &optname)) {
-        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
+        JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
         return -1;
     }
 
--- a/jdk/src/java.base/unix/native/libnet/SocketInputStream.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/unix/native/libnet/SocketInputStream.c	Fri Sep 30 09:28:18 2016 -0700
@@ -58,15 +58,15 @@
         result = NET_TimeoutWithCurrentTime(fd, timeout, prevtime);
         if (result <= 0) {
             if (result == 0) {
-                JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", "Read timed out");
+                JNU_ThrowByName(env, "java/net/SocketTimeoutException", "Read timed out");
             } else if (result == -1) {
                 if (errno == EBADF) {
-                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+                    JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
                 } else if (errno == ENOMEM) {
                     JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
                 } else {
                     JNU_ThrowByNameWithMessageAndLastError
-                            (env, JNU_JAVANETPKG "SocketException", "select/poll failed");
+                            (env, "java/net/SocketException", "select/poll failed");
                 }
             }
             return -1;
@@ -100,19 +100,14 @@
     jint fd, nread;
 
     if (IS_NULL(fdObj)) {
-        /* shouldn't this be a NullPointerException? -br */
-        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+        JNU_ThrowByName(env, "java/net/SocketException",
                         "Socket closed");
         return -1;
-    } else {
-        fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
-        /* Bug 4086704 - If the Socket associated with this file descriptor
-         * was closed (sysCloseFD), then the file descriptor is set to -1.
-         */
-        if (fd == -1) {
-            JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
-            return -1;
-        }
+    }
+    fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+    if (fd == -1) {
+        JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
+        return -1;
     }
 
     /*
@@ -154,17 +149,17 @@
                     break;
 
                 case EBADF:
-                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                    JNU_ThrowByName(env, "java/net/SocketException",
                         "Socket closed");
                     break;
 
                 case EINTR:
-                     JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
+                     JNU_ThrowByName(env, "java/io/InterruptedIOException",
                            "Operation interrupted");
                      break;
                 default:
                     JNU_ThrowByNameWithMessageAndLastError
-                        (env, JNU_JAVANETPKG "SocketException", "Read failed");
+                        (env, "java/net/SocketException", "Read failed");
             }
         }
     } else {
--- a/jdk/src/java.base/unix/native/libnio/ch/NativeThread.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/unix/native/libnio/ch/NativeThread.c	Fri Sep 30 09:28:18 2016 -0700
@@ -37,6 +37,11 @@
   #include <sys/signal.h>
   /* Also defined in net/linux_close.c */
   #define INTERRUPT_SIGNAL (__SIGRTMAX - 2)
+#elif _AIX
+  #include <pthread.h>
+  #include <sys/signal.h>
+  /* Also defined in net/aix_close.c */
+  #define INTERRUPT_SIGNAL (SIGRTMAX - 1)
 #elif __solaris__
   #include <thread.h>
   #include <signal.h>
@@ -59,7 +64,7 @@
 Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
 {
     /* Install the null handler for INTERRUPT_SIGNAL.  This might overwrite the
-     * handler previously installed by java/net/linux_close.c, but that's okay
+     * handler previously installed by <platform>_close.c, but that's okay
      * since neither handler actually does anything.  We install our own
      * handler here simply out of paranoia; ultimately the two mechanisms
      * should somehow be unified, perhaps within the VM.
--- a/jdk/src/java.base/windows/native/libnet/DualStackPlainDatagramSocketImpl.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/windows/native/libnet/DualStackPlainDatagramSocketImpl.c	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -475,13 +475,14 @@
  * Method:    socketSetIntOption
  * Signature: (III)V
  */
-JNIEXPORT void JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketSetIntOption
-  (JNIEnv *env, jclass clazz, jint fd , jint cmd, jint value) {
+JNIEXPORT void JNICALL
+Java_java_net_DualStackPlainDatagramSocketImpl_socketSetIntOption
+  (JNIEnv *env, jclass clazz, jint fd, jint cmd, jint value)
+{
     int level = 0, opt = 0;
 
     if (NET_MapSocketOption(cmd, &level, &opt) < 0) {
-        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
-                                     "Invalid option");
+        JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
         return;
     }
 
@@ -495,14 +496,15 @@
  * Method:    socketGetIntOption
  * Signature: (II)I
  */
-JNIEXPORT jint JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketGetIntOption
-  (JNIEnv *env, jclass clazz, jint fd, jint cmd) {
-    int level = 0, opt = 0, result=0;
+JNIEXPORT jint JNICALL
+Java_java_net_DualStackPlainDatagramSocketImpl_socketGetIntOption
+  (JNIEnv *env, jclass clazz, jint fd, jint cmd)
+{
+    int level = 0, opt = 0, result = 0;
     int result_len = sizeof(result);
 
     if (NET_MapSocketOption(cmd, &level, &opt) < 0) {
-        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
-                                     "Invalid option");
+        JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
         return -1;
     }
 
@@ -519,8 +521,10 @@
  * Method:    dataAvailable
  * Signature: ()I
  */
-JNIEXPORT jint JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_dataAvailable
-(JNIEnv *env, jobject this) {
+JNIEXPORT jint JNICALL
+Java_java_net_DualStackPlainDatagramSocketImpl_dataAvailable
+  (JNIEnv *env, jobject this)
+{
     SOCKET fd;
     int  rv = -1;
     jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
--- a/jdk/src/java.base/windows/native/libnet/DualStackPlainSocketImpl.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/windows/native/libnet/DualStackPlainSocketImpl.c	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -369,18 +369,17 @@
  * Method:    setIntOption
  * Signature: (III)V
  */
-JNIEXPORT void JNICALL Java_java_net_DualStackPlainSocketImpl_setIntOption
-  (JNIEnv *env, jclass clazz, jint fd, jint cmd, jint value) {
-
+JNIEXPORT void JNICALL
+Java_java_net_DualStackPlainSocketImpl_setIntOption
+  (JNIEnv *env, jclass clazz, jint fd, jint cmd, jint value)
+{
     int level = 0, opt = 0;
     struct linger linger = {0, 0};
     char *parg;
     int arglen;
 
     if (NET_MapSocketOption(cmd, &level, &opt) < 0) {
-        JNU_ThrowByNameWithLastError(env,
-                                     JNU_JAVANETPKG "SocketException",
-                                     "Invalid option");
+        JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
         return;
     }
 
@@ -410,8 +409,8 @@
  * Signature: (II)I
  */
 JNIEXPORT jint JNICALL Java_java_net_DualStackPlainSocketImpl_getIntOption
-  (JNIEnv *env, jclass clazz, jint fd, jint cmd) {
-
+  (JNIEnv *env, jclass clazz, jint fd, jint cmd)
+{
     int level = 0, opt = 0;
     int result=0;
     struct linger linger = {0, 0};
@@ -419,9 +418,7 @@
     int arglen;
 
     if (NET_MapSocketOption(cmd, &level, &opt) < 0) {
-        JNU_ThrowByNameWithLastError(env,
-                                     JNU_JAVANETPKG "SocketException",
-                                     "Unsupported socket option");
+        JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
         return -1;
     }
 
--- a/jdk/src/java.base/windows/native/libnet/Inet4AddressImpl.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/windows/native/libnet/Inet4AddressImpl.c	Fri Sep 30 09:28:18 2016 -0700
@@ -33,6 +33,7 @@
 #include <process.h>
 #include <iphlpapi.h>
 #include <icmpapi.h>
+#include <WinError.h>
 
 #include "java_net_InetAddress.h"
 #include "java_net_Inet4AddressImpl.h"
@@ -442,7 +443,15 @@
     DWORD ReplySize = 0;
     jboolean ret = JNI_FALSE;
 
-    ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData);
+    // https://msdn.microsoft.com/en-us/library/windows/desktop/aa366051%28v=vs.85%29.aspx
+    ReplySize = sizeof(ICMP_ECHO_REPLY)   // The buffer should be large enough
+                                          // to hold at least one ICMP_ECHO_REPLY
+                                          // structure
+                + sizeof(SendData)        // plus RequestSize bytes of data.
+                + 8;                      // This buffer should also be large enough
+                                          // to also hold 8 more bytes of data
+                                          // (the size of an ICMP error message)
+
     ReplyBuffer = (VOID*) malloc(ReplySize);
     if (ReplyBuffer == NULL) {
         IcmpCloseHandle(hIcmpFile);
@@ -478,10 +487,47 @@
                                    (timeout < 1000) ? 1000 : timeout);   // DWORD Timeout
     }
 
-    if (dwRetVal != 0) {
+    if (dwRetVal == 0) { // if the call failed
+        TCHAR *buf;
+        DWORD err = WSAGetLastError();
+        switch (err) {
+            case ERROR_NO_NETWORK:
+            case ERROR_NETWORK_UNREACHABLE:
+            case ERROR_HOST_UNREACHABLE:
+            case ERROR_PROTOCOL_UNREACHABLE:
+            case ERROR_PORT_UNREACHABLE:
+            case ERROR_REQUEST_ABORTED:
+            case ERROR_INCORRECT_ADDRESS:
+            case ERROR_HOST_DOWN:
+            case ERROR_INVALID_COMPUTERNAME:
+            case ERROR_INVALID_NETNAME:
+            case WSAEHOSTUNREACH:   /* Host Unreachable */
+            case WSAENETUNREACH:    /* Network Unreachable */
+            case WSAENETDOWN:       /* Network is down */
+            case WSAEPFNOSUPPORT:   /* Protocol Family unsupported */
+            case IP_REQ_TIMED_OUT:
+                break;
+            default:
+                FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+                        NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                        (LPTSTR)&buf, 0, NULL);
+                NET_ThrowNew(env, err, buf);
+                LocalFree(buf);
+                break;
+        }
+    } else {
         PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
-        if ((int)pEchoReply->RoundTripTime <= timeout)
+
+        // This is to take into account the undocumented minimum
+        // timeout mentioned in the IcmpSendEcho call above.
+        // We perform an extra check to make sure that our
+        // roundtrip time was less than our desired timeout
+        // for cases where that timeout is < 1000ms.
+        if (pEchoReply->Status == IP_SUCCESS
+                && (int)pEchoReply->RoundTripTime <= timeout)
+        {
             ret = JNI_TRUE;
+        }
     }
 
     free(ReplyBuffer);
--- a/jdk/src/java.base/windows/native/libnet/SocketInputStream.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/windows/native/libnet/SocketInputStream.c	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -62,18 +62,18 @@
                                             jobject fdObj, jbyteArray data,
                                             jint off, jint len, jint timeout)
 {
+    char BUF[MAX_BUFFER_LEN];
     char *bufP;
-    char BUF[MAX_BUFFER_LEN];
-    jint fd, newfd;
-    jint nread;
+    jint fd, newfd, nread;
 
     if (IS_NULL(fdObj)) {
-        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed");
+        JNU_ThrowByName(env, "java/net/SocketException",
+                        "Socket closed");
         return -1;
     }
     fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
     if (fd == -1) {
-        NET_ThrowSocketException(env, "Socket closed");
+        JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
         return -1;
     }
 
@@ -103,10 +103,10 @@
 
             if (ret <= 0) {
                 if (ret == 0) {
-                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
+                    JNU_ThrowByName(env, "java/net/SocketTimeoutException",
                                     "Read timed out");
                 } else if (ret == -1) {
-                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed");
+                    JNU_ThrowByName(env, "java/net/SocketException", "socket closed");
                 }
                 if (bufP != BUF) {
                     free(bufP);
@@ -117,7 +117,7 @@
             /*check if the socket has been closed while we were in timeout*/
             newfd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
             if (newfd == -1) {
-                NET_ThrowSocketException(env, "Socket Closed");
+                JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
                 if (bufP != BUF) {
                     free(bufP);
                 }
@@ -134,11 +134,11 @@
             // Check if the socket has been closed since we last checked.
             // This could be a reason for recv failing.
             if ((*env)->GetIntField(env, fdObj, IO_fd_fdID) == -1) {
-                NET_ThrowSocketException(env, "Socket closed");
+                JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
             } else {
                 switch (WSAGetLastError()) {
                     case WSAEINTR:
-                        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        JNU_ThrowByName(env, "java/net/SocketException",
                             "socket closed");
                         break;
 
@@ -153,7 +153,7 @@
                         break;
 
                     case WSAETIMEDOUT :
-                        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
+                        JNU_ThrowByName(env, "java/net/SocketTimeoutException",
                                        "Read timed out");
                         break;
 
--- a/jdk/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c	Fri Sep 30 09:28:18 2016 -0700
@@ -1795,9 +1795,9 @@
  * Signature: (ILjava/lang/Object;)V
  */
 JNIEXPORT void JNICALL
-Java_java_net_TwoStacksPlainDatagramSocketImpl_socketNativeSetOption(JNIEnv *env,jobject this,
-                                                      jint opt,jobject value) {
-
+Java_java_net_TwoStacksPlainDatagramSocketImpl_socketNativeSetOption
+  (JNIEnv *env,jobject this, jint opt,jobject value)
+{
     int fd=-1, fd1=-1;
     int levelv4 = 0, levelv6 = 0, optnamev4 = 0, optnamev6 = 0, optlen = 0;
     union {
@@ -1828,13 +1828,13 @@
      */
     if (fd1 != -1) {
         if (NET_MapSocketOptionV6(opt, &levelv6, &optnamev6)) {
-            JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
+            JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
             return;
         }
     }
     if (fd != -1) {
         if (NET_MapSocketOption(opt, &levelv4, &optnamev4)) {
-            JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
+            JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
             return;
         }
     }
@@ -2163,9 +2163,9 @@
  * Signature: (I)Ljava/lang/Object;
  */
 JNIEXPORT jobject JNICALL
-Java_java_net_TwoStacksPlainDatagramSocketImpl_socketGetOption(JNIEnv *env, jobject this,
-                                                      jint opt) {
-
+Java_java_net_TwoStacksPlainDatagramSocketImpl_socketGetOption
+  (JNIEnv *env, jobject this, jint opt)
+{
     int fd=-1, fd1=-1;
     int level, optname, optlen;
     union {
@@ -2197,13 +2197,13 @@
      * level and option name.
      */
     if (NET_MapSocketOption(opt, &level, &optname)) {
-        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
+        JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
         return NULL;
     }
 
     if (fd == -1) {
         if (NET_MapSocketOptionV6(opt, &level, &optname)) {
-            JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
+            JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
             return NULL;
         }
         fd = fd1; /* must be IPv6 only */
--- a/jdk/src/java.base/windows/native/libnet/TwoStacksPlainSocketImpl.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/windows/native/libnet/TwoStacksPlainSocketImpl.c	Fri Sep 30 09:28:18 2016 -0700
@@ -838,10 +838,9 @@
  * Signature: (IZLjava/lang/Object;)V
  */
 JNIEXPORT void JNICALL
-Java_java_net_TwoStacksPlainSocketImpl_socketNativeSetOption(JNIEnv *env,
-                                              jobject this,
-                                              jint cmd, jboolean on,
-                                              jobject value) {
+Java_java_net_TwoStacksPlainSocketImpl_socketNativeSetOption
+  (JNIEnv *env, jobject this, jint cmd, jboolean on, jobject value)
+{
     int fd, fd1;
     int level = 0, optname = 0, optlen = 0;
     union {
@@ -923,11 +922,10 @@
 
     /*
      * Map the Java level socket option to the platform specific
-     * level
+     * level and option name.
      */
     if (NET_MapSocketOption(cmd, &level, &optname)) {
-        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
-                        "Invalid option");
+        JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
         return;
     }
 
@@ -1006,15 +1004,16 @@
  * Signature: (I)I
  */
 JNIEXPORT jint JNICALL
-Java_java_net_TwoStacksPlainSocketImpl_socketGetOption(JNIEnv *env, jobject this,
-                                              jint opt, jobject iaContainerObj) {
-
+Java_java_net_TwoStacksPlainSocketImpl_socketGetOption
+  (JNIEnv *env, jobject this, jint opt, jobject iaContainerObj)
+{
     int fd, fd1;
     int level = 0, optname = 0, optlen = 0;
     union {
         int i;
         struct linger ling;
     } optval;
+
     /*
      * Get SOCKET and check it hasn't been closed
      */
@@ -1073,7 +1072,7 @@
      * level and option name.
      */
     if (NET_MapSocketOption(opt, &level, &optname)) {
-        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
+        JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");
         return -1;
     }
 
--- a/jdk/src/java.base/windows/native/libnet/net_util_md.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/windows/native/libnet/net_util_md.c	Fri Sep 30 09:28:18 2016 -0700
@@ -203,19 +203,6 @@
 }
 
 void
-NET_ThrowSocketException(JNIEnv *env, char* msg)
-{
-    static jclass cls = NULL;
-    if (cls == NULL) {
-        cls = (*env)->FindClass(env, "java/net/SocketException");
-        CHECK_NULL(cls);
-        cls = (*env)->NewGlobalRef(env, cls);
-        CHECK_NULL(cls);
-    }
-    (*env)->ThrowNew(env, cls, msg);
-}
-
-void
 NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
                    const char *defaultDetail) {
     char errmsg[255];
--- a/jdk/src/java.base/windows/native/libnet/net_util_md.h	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.base/windows/native/libnet/net_util_md.h	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -299,8 +299,6 @@
 void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
          const char *defaultDetail);
 
-void NET_ThrowSocketException(JNIEnv *env, char* msg);
-
 /*
  * differs from NET_Timeout() as follows:
  *
--- a/jdk/src/java.desktop/share/classes/com/sun/beans/finder/ConstructorFinder.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/com/sun/beans/finder/ConstructorFinder.java	Fri Sep 30 09:28:18 2016 -0700
@@ -67,19 +67,22 @@
      */
     public static Constructor<?> findConstructor(Class<?> type, Class<?>...args) throws NoSuchMethodException {
         if (type.isPrimitive()) {
-            throw new NoSuchMethodException("Primitive wrapper does not contain constructors");
+            throw new NoSuchMethodException("Primitive wrapper does not contain constructors: "
+                + type.getName());
         }
         if (type.isInterface()) {
-            throw new NoSuchMethodException("Interface does not contain constructors");
+            throw new NoSuchMethodException("Interface does not contain constructors: "
+                + type.getName());
         }
         if (!FinderUtils.isExported(type)) {
-            throw new NoSuchMethodException("Class is not accessible");
+            throw new NoSuchMethodException("Class is not accessible: " + type.getName());
         }
         if (Modifier.isAbstract(type.getModifiers())) {
-            throw new NoSuchMethodException("Abstract class cannot be instantiated");
+            throw new NoSuchMethodException("Abstract class cannot be instantiated: "
+                + type.getName());
         }
         if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) {
-            throw new NoSuchMethodException("Class is not accessible");
+            throw new NoSuchMethodException("Class is not accessible: " + type.getName());
         }
         PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
         Signature signature = new Signature(type, args);
--- a/jdk/src/java.desktop/share/classes/java/beans/MetaData.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/beans/MetaData.java	Fri Sep 30 09:28:18 2016 -0700
@@ -510,102 +510,6 @@
             return new Expression(oldInstance, Collections.class, "synchronizedSortedMap", new Object[]{map});
         }
     }
-
-    static final class CheckedCollection_PersistenceDelegate extends java_util_Collections {
-        protected Expression instantiate(Object oldInstance, Encoder out) {
-            Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
-            List<?> list = new ArrayList<>((Collection<?>) oldInstance);
-            return new Expression(oldInstance, Collections.class, "checkedCollection", new Object[]{list, type});
-        }
-    }
-
-    static final class CheckedList_PersistenceDelegate extends java_util_Collections {
-        protected Expression instantiate(Object oldInstance, Encoder out) {
-            Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
-            List<?> list = new LinkedList<>((Collection<?>) oldInstance);
-            return new Expression(oldInstance, Collections.class, "checkedList", new Object[]{list, type});
-        }
-    }
-
-    static final class CheckedRandomAccessList_PersistenceDelegate extends java_util_Collections {
-        protected Expression instantiate(Object oldInstance, Encoder out) {
-            Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
-            List<?> list = new ArrayList<>((Collection<?>) oldInstance);
-            return new Expression(oldInstance, Collections.class, "checkedList", new Object[]{list, type});
-        }
-    }
-
-    static final class CheckedSet_PersistenceDelegate extends java_util_Collections {
-        protected Expression instantiate(Object oldInstance, Encoder out) {
-            Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
-            Set<?> set = new HashSet<>((Set<?>) oldInstance);
-            return new Expression(oldInstance, Collections.class, "checkedSet", new Object[]{set, type});
-        }
-    }
-
-    static final class CheckedSortedSet_PersistenceDelegate extends java_util_Collections {
-        protected Expression instantiate(Object oldInstance, Encoder out) {
-            Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
-            SortedSet<?> set = new TreeSet<>((SortedSet<?>) oldInstance);
-            return new Expression(oldInstance, Collections.class, "checkedSortedSet", new Object[]{set, type});
-        }
-    }
-
-    static final class CheckedMap_PersistenceDelegate extends java_util_Collections {
-        protected Expression instantiate(Object oldInstance, Encoder out) {
-            Object keyType   = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.keyType");
-            Object valueType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.valueType");
-            Map<?,?> map = new HashMap<>((Map<?,?>) oldInstance);
-            return new Expression(oldInstance, Collections.class, "checkedMap", new Object[]{map, keyType, valueType});
-        }
-    }
-
-    static final class CheckedSortedMap_PersistenceDelegate extends java_util_Collections {
-        protected Expression instantiate(Object oldInstance, Encoder out) {
-            Object keyType   = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.keyType");
-            Object valueType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.valueType");
-            SortedMap<?,?> map = new TreeMap<>((SortedMap<?,?>) oldInstance);
-            return new Expression(oldInstance, Collections.class, "checkedSortedMap", new Object[]{map, keyType, valueType});
-        }
-    }
-}
-
-/**
- * The persistence delegate for {@code java.util.EnumMap} classes.
- *
- * @author Sergey A. Malenkov
- */
-static final class java_util_EnumMap_PersistenceDelegate extends PersistenceDelegate {
-    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
-        return super.mutatesTo(oldInstance, newInstance) && (getType(oldInstance) == getType(newInstance));
-    }
-
-    protected Expression instantiate(Object oldInstance, Encoder out) {
-        return new Expression(oldInstance, EnumMap.class, "new", new Object[] {getType(oldInstance)});
-    }
-
-    private static Object getType(Object instance) {
-        return MetaData.getPrivateFieldValue(instance, "java.util.EnumMap.keyType");
-    }
-}
-
-/**
- * The persistence delegate for {@code java.util.EnumSet} classes.
- *
- * @author Sergey A. Malenkov
- */
-static final class java_util_EnumSet_PersistenceDelegate extends PersistenceDelegate {
-    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
-        return super.mutatesTo(oldInstance, newInstance) && (getType(oldInstance) == getType(newInstance));
-    }
-
-    protected Expression instantiate(Object oldInstance, Encoder out) {
-        return new Expression(oldInstance, EnumSet.class, "noneOf", new Object[] {getType(oldInstance)});
-    }
-
-    private static Object getType(Object instance) {
-        return MetaData.getPrivateFieldValue(instance, "java.util.EnumSet.elementType");
-    }
 }
 
 // Collection
@@ -1313,9 +1217,6 @@
 
         internalPersistenceDelegates.put("java.sql.Date", new java_util_Date_PersistenceDelegate());
         internalPersistenceDelegates.put("java.sql.Time", new java_util_Date_PersistenceDelegate());
-
-        internalPersistenceDelegates.put("java.util.JumboEnumSet", new java_util_EnumSet_PersistenceDelegate());
-        internalPersistenceDelegates.put("java.util.RegularEnumSet", new java_util_EnumSet_PersistenceDelegate());
     }
 
     @SuppressWarnings("rawtypes")
--- a/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java	Fri Sep 30 09:28:18 2016 -0700
@@ -2461,16 +2461,16 @@
             try {
                 bundle = ResourceBundle.getBundle(baseName, locale, this.getClass().getModule());
             } catch (MissingResourceException mre) {
-                throw new IllegalArgumentException("Bundle not found!");
+                throw new IllegalArgumentException("Bundle not found!", mre);
             }
 
             String warning = null;
             try {
                 warning = bundle.getString(keyword);
             } catch (ClassCastException cce) {
-                throw new IllegalArgumentException("Resource is not a String!");
+                throw new IllegalArgumentException("Resource is not a String!", cce);
             } catch (MissingResourceException mre) {
-                throw new IllegalArgumentException("Resource is missing!");
+                throw new IllegalArgumentException("Resource is missing!", mre);
             }
 
             listener.warningOccurred(this, warning);
--- a/jdk/src/java.desktop/share/classes/javax/imageio/ImageWriter.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/ImageWriter.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1963,16 +1963,16 @@
             try {
                 bundle = ResourceBundle.getBundle(baseName, locale, this.getClass().getModule());
             } catch (MissingResourceException mre) {
-                throw new IllegalArgumentException("Bundle not found!");
+                throw new IllegalArgumentException("Bundle not found!", mre);
             }
 
             String warning = null;
             try {
                 warning = bundle.getString(keyword);
             } catch (ClassCastException cce) {
-                throw new IllegalArgumentException("Resource is not a String!");
+                throw new IllegalArgumentException("Resource is not a String!", cce);
             } catch (MissingResourceException mre) {
-                throw new IllegalArgumentException("Resource is missing!");
+                throw new IllegalArgumentException("Resource is missing!", mre);
             }
 
             listener.warningOccurred(this, imageIndex, warning);
--- a/jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c	Fri Sep 30 09:28:18 2016 -0700
@@ -442,7 +442,7 @@
 
 #ifndef __linux__ /* SOLARIS */
         if (xrenderLibHandle == NULL) {
-            xrenderLibHandle = dlopen("/usr/sfw/lib/libXrender.so.1",
+            xrenderLibHandle = dlopen("/usr/lib/libXrender.so.1",
                                       RTLD_LAZY | RTLD_GLOBAL);
         }
 #endif
--- a/jdk/src/java.desktop/unix/native/libjawt/jawt.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/java.desktop/unix/native/libjawt/jawt.c	Fri Sep 30 09:28:18 2016 -0700
@@ -39,6 +39,10 @@
  */
 JNIEXPORT jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt)
 {
+#if defined(HEADLESS)
+    /* there are no AWT libs available at all */
+    return JNI_FALSE;
+#else
     if (awt == NULL) {
         return JNI_FALSE;
     }
@@ -64,4 +68,5 @@
     }
 
     return JNI_TRUE;
+#endif
 }
--- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Cipher.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Cipher.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -344,7 +344,7 @@
     private void implInit(int opmode, Key key, byte[] iv,
             SecureRandom random)
             throws InvalidKeyException, InvalidAlgorithmParameterException {
-        cancelOperation();
+        reset(true);
         if (fixedKeySize != -1 && key.getEncoded().length != fixedKeySize) {
             throw new InvalidKeyException("Key size is invalid");
         }
@@ -404,23 +404,26 @@
         if (initialized == false) {
             return;
         }
-        initialized = false;
+
         if ((session == null) || (token.explicitCancel == false)) {
             return;
         }
-        // cancel operation by finishing it
-        int bufLen = doFinalLength(0);
-        byte[] buffer = new byte[bufLen];
         try {
-            if (encrypt) {
-                token.p11.C_EncryptFinal(session.id(), 0, buffer, 0, bufLen);
+            if (session.hasObjects() == false) {
+                session = token.killSession(session);
+                return;
             } else {
-                token.p11.C_DecryptFinal(session.id(), 0, buffer, 0, bufLen);
+                // cancel operation by finishing it
+                int bufLen = doFinalLength(0);
+                byte[] buffer = new byte[bufLen];
+                if (encrypt) {
+                    token.p11.C_EncryptFinal(session.id(), 0, buffer, 0, bufLen);
+                } else {
+                    token.p11.C_DecryptFinal(session.id(), 0, buffer, 0, bufLen);
+                }
             }
         } catch (PKCS11Exception e) {
             throw new ProviderException("Cancel failed", e);
-        } finally {
-            reset();
         }
     }
 
@@ -483,7 +486,9 @@
     }
 
     // reset the states to the pre-initialized values
-    private void reset() {
+    private void reset(boolean doCancel) {
+        if (doCancel) cancelOperation();
+
         initialized = false;
         bytesBuffered = 0;
         padBufferLen = 0;
@@ -610,7 +615,7 @@
                 throw (ShortBufferException)
                         (new ShortBufferException().initCause(e));
             }
-            reset();
+            reset(false);
             throw new ProviderException("update() failed", e);
         }
     }
@@ -728,7 +733,7 @@
                 throw (ShortBufferException)
                         (new ShortBufferException().initCause(e));
             }
-            reset();
+            reset(false);
             throw new ProviderException("update() failed", e);
         }
     }
@@ -740,6 +745,7 @@
         if (outLen < requiredOutLen) {
             throw new ShortBufferException();
         }
+        boolean doCancel = true;
         try {
             ensureInitialized();
             int k = 0;
@@ -753,7 +759,12 @@
                 }
                 k += token.p11.C_EncryptFinal(session.id(),
                         0, out, (outOfs + k), (outLen - k));
+                doCancel = false;
             } else {
+                // Special handling to match SunJCE provider behavior
+                if (bytesBuffered == 0 && padBufferLen == 0) {
+                    return 0;
+                }
                 if (paddingObj != null) {
                     if (padBufferLen != 0) {
                         k = token.p11.C_DecryptUpdate(session.id(), 0,
@@ -762,20 +773,24 @@
                     }
                     k += token.p11.C_DecryptFinal(session.id(), 0, padBuffer, k,
                             padBuffer.length - k);
+                    doCancel = false;
+
                     int actualPadLen = paddingObj.unpad(padBuffer, k);
                     k -= actualPadLen;
                     System.arraycopy(padBuffer, 0, out, outOfs, k);
                 } else {
                     k = token.p11.C_DecryptFinal(session.id(), 0, out, outOfs,
                             outLen);
+                    doCancel = false;
                 }
             }
             return k;
         } catch (PKCS11Exception e) {
+            doCancel = false;
             handleException(e);
             throw new ProviderException("doFinal() failed", e);
         } finally {
-            reset();
+            reset(doCancel);
         }
     }
 
@@ -788,6 +803,7 @@
             throw new ShortBufferException();
         }
 
+        boolean doCancel = true;
         try {
             ensureInitialized();
 
@@ -818,7 +834,13 @@
                 }
                 k += token.p11.C_EncryptFinal(session.id(),
                         outAddr, outArray, (outOfs + k), (outLen - k));
+                doCancel = false;
             } else {
+                // Special handling to match SunJCE provider behavior
+                if (bytesBuffered == 0 && padBufferLen == 0) {
+                    return 0;
+                }
+
                 if (paddingObj != null) {
                     if (padBufferLen != 0) {
                         k = token.p11.C_DecryptUpdate(session.id(),
@@ -828,6 +850,8 @@
                     }
                     k += token.p11.C_DecryptFinal(session.id(),
                             0, padBuffer, k, padBuffer.length - k);
+                    doCancel = false;
+
                     int actualPadLen = paddingObj.unpad(padBuffer, k);
                     k -= actualPadLen;
                     outArray = padBuffer;
@@ -835,6 +859,7 @@
                 } else {
                     k = token.p11.C_DecryptFinal(session.id(),
                             outAddr, outArray, outOfs, outLen);
+                    doCancel = false;
                 }
             }
             if ((!encrypt && paddingObj != null) ||
@@ -846,10 +871,11 @@
             }
             return k;
         } catch (PKCS11Exception e) {
+            doCancel = false;
             handleException(e);
             throw new ProviderException("doFinal() failed", e);
         } finally {
-            reset();
+            reset(doCancel);
         }
     }
 
--- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Signature.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Signature.java	Fri Sep 30 09:28:18 2016 -0700
@@ -616,8 +616,11 @@
                     return dsaToASN1(signature);
                 }
             }
-        } catch (PKCS11Exception e) {
-            throw new ProviderException(e);
+        } catch (PKCS11Exception pe) {
+            throw new ProviderException(pe);
+        } catch (SignatureException | ProviderException e) {
+            cancelOperation();
+            throw e;
         } finally {
             initialized = false;
             session = token.releaseSession(session);
@@ -669,8 +672,8 @@
                 }
             }
             return true;
-        } catch (PKCS11Exception e) {
-            long errorCode = e.getErrorCode();
+        } catch (PKCS11Exception pe) {
+            long errorCode = pe.getErrorCode();
             if (errorCode == CKR_SIGNATURE_INVALID) {
                 return false;
             }
@@ -682,10 +685,11 @@
             if (errorCode == CKR_DATA_LEN_RANGE) {
                 return false;
             }
-            throw new ProviderException(e);
+            throw new ProviderException(pe);
+        }  catch (SignatureException | ProviderException e) {
+            cancelOperation();
+            throw e;
         } finally {
-            // XXX we should not release the session if we abort above
-            // before calling C_Verify
             initialized = false;
             session = token.releaseSession(session);
         }
--- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -68,8 +68,8 @@
     // master secret as a P11Key
     private P11Key p11Key;
 
-    // version, e.g. 0x0301
-    private int version;
+    // whether SSLv3 is supported
+    private final boolean supportSSLv3;
 
     P11TlsKeyMaterialGenerator(Token token, String algorithm, long mechanism)
             throws PKCS11Exception {
@@ -77,6 +77,11 @@
         this.token = token;
         this.algorithm = algorithm;
         this.mechanism = mechanism;
+
+        // Given the current lookup order specified in SunPKCS11.java,
+        // if CKM_SSL3_KEY_AND_MAC_DERIVE is not used to construct this object,
+        // it means that this mech is disabled or unsupported.
+        this.supportSSLv3 = (mechanism == CKM_SSL3_KEY_AND_MAC_DERIVE);
     }
 
     protected void engineInit(SecureRandom random) {
@@ -89,20 +94,26 @@
         if (params instanceof TlsKeyMaterialParameterSpec == false) {
             throw new InvalidAlgorithmParameterException(MSG);
         }
-        this.spec = (TlsKeyMaterialParameterSpec)params;
+
+        TlsKeyMaterialParameterSpec spec = (TlsKeyMaterialParameterSpec)params;
+        int version = (spec.getMajorVersion() << 8) | spec.getMinorVersion();
+
+        if ((version == 0x0300 && !supportSSLv3) || (version < 0x0300) ||
+            (version > 0x0302)) {
+             throw new InvalidAlgorithmParameterException
+                    ("Only" + (supportSSLv3? " SSL 3.0,": "") +
+                     " TLS 1.0, and TLS 1.1 are supported (0x" +
+                     Integer.toHexString(version) + ")");
+        }
         try {
             p11Key = P11SecretKeyFactory.convertKey
                             (token, spec.getMasterSecret(), "TlsMasterSecret");
         } catch (InvalidKeyException e) {
             throw new InvalidAlgorithmParameterException("init() failed", e);
         }
-        version = (spec.getMajorVersion() << 8) | spec.getMinorVersion();
-        if ((version < 0x0300) && (version > 0x0302)) {
-            throw new InvalidAlgorithmParameterException
-                    ("Only SSL 3.0, TLS 1.0, and TLS 1.1 are supported");
-        }
-        // we assume the token supports both the CKM_SSL3_* and the CKM_TLS_*
-        // mechanisms
+        this.spec = spec;
+        this.mechanism = (version == 0x0300)?
+            CKM_SSL3_KEY_AND_MAC_DERIVE : CKM_TLS_KEY_AND_MAC_DERIVE;
     }
 
     protected void engineInit(int keysize, SecureRandom random) {
@@ -115,8 +126,6 @@
             throw new IllegalStateException
                 ("TlsKeyMaterialGenerator must be initialized");
         }
-        mechanism = (version == 0x0300) ? CKM_SSL3_KEY_AND_MAC_DERIVE
-                                         : CKM_TLS_KEY_AND_MAC_DERIVE;
         int macBits = spec.getMacKeyLength() << 3;
         int ivBits = spec.getIvLength() << 3;
 
--- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsMasterSecretGenerator.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsMasterSecretGenerator.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -61,7 +61,10 @@
     private TlsMasterSecretParameterSpec spec;
     private P11Key p11Key;
 
-    int version;
+    CK_VERSION ckVersion;
+
+    // whether SSLv3 is supported
+    private final boolean supportSSLv3;
 
     P11TlsMasterSecretGenerator(Token token, String algorithm, long mechanism)
             throws PKCS11Exception {
@@ -69,6 +72,11 @@
         this.token = token;
         this.algorithm = algorithm;
         this.mechanism = mechanism;
+
+        // Given the current lookup order specified in SunPKCS11.java, if
+        // CKM_SSL3_MASTER_KEY_DERIVE is not used to construct this object,
+        // it means that this mech is disabled or unsupported.
+        supportSSLv3 = (mechanism == CKM_SSL3_MASTER_KEY_DERIVE);
     }
 
     protected void engineInit(SecureRandom random) {
@@ -81,7 +89,17 @@
         if (params instanceof TlsMasterSecretParameterSpec == false) {
             throw new InvalidAlgorithmParameterException(MSG);
         }
-        this.spec = (TlsMasterSecretParameterSpec)params;
+
+        TlsMasterSecretParameterSpec spec = (TlsMasterSecretParameterSpec)params;
+        int version = (spec.getMajorVersion() << 8) | spec.getMinorVersion();
+        if ((version == 0x0300 && !supportSSLv3) || (version < 0x0300) ||
+            (version > 0x0302)) {
+             throw new InvalidAlgorithmParameterException
+                    ("Only" + (supportSSLv3? " SSL 3.0,": "") +
+                     " TLS 1.0, and TLS 1.1 are supported (0x" +
+                     Integer.toHexString(version) + ")");
+        }
+
         SecretKey key = spec.getPremasterSecret();
         // algorithm should be either TlsRsaPremasterSecret or TlsPremasterSecret,
         // but we omit the check
@@ -90,25 +108,7 @@
         } catch (InvalidKeyException e) {
             throw new InvalidAlgorithmParameterException("init() failed", e);
         }
-        version = (spec.getMajorVersion() << 8) | spec.getMinorVersion();
-        if ((version < 0x0300) || (version > 0x0302)) {
-            throw new InvalidAlgorithmParameterException
-                ("Only SSL 3.0, TLS 1.0, and TLS 1.1 supported");
-        }
-        // We assume the token supports the required mechanism. If it does not,
-        // generateKey() will fail and the failover should take care of us.
-    }
-
-    protected void engineInit(int keysize, SecureRandom random) {
-        throw new InvalidParameterException(MSG);
-    }
-
-    protected SecretKey engineGenerateKey() {
-        if (spec == null) {
-            throw new IllegalStateException
-                ("TlsMasterSecretGenerator must be initialized");
-        }
-        CK_VERSION ckVersion;
+        this.spec = spec;
         if (p11Key.getAlgorithm().equals("TlsRsaPremasterSecret")) {
             mechanism = (version == 0x0300) ? CKM_SSL3_MASTER_KEY_DERIVE
                                              : CKM_TLS_MASTER_KEY_DERIVE;
@@ -124,6 +124,17 @@
                                              : CKM_TLS_MASTER_KEY_DERIVE_DH;
             ckVersion = null;
         }
+    }
+
+    protected void engineInit(int keysize, SecureRandom random) {
+        throw new InvalidParameterException(MSG);
+    }
+
+    protected SecretKey engineGenerateKey() {
+        if (spec == null) {
+            throw new IllegalStateException
+                ("TlsMasterSecretGenerator must be initialized");
+        }
         byte[] clientRandom = spec.getClientRandom();
         byte[] serverRandom = spec.getServerRandom();
         CK_SSL3_RANDOM_DATA random =
@@ -139,13 +150,12 @@
             long keyID = token.p11.C_DeriveKey(session.id(),
                 new CK_MECHANISM(mechanism, params), p11Key.keyID, attributes);
             int major, minor;
-            ckVersion = params.pVersion;
-            if (ckVersion == null) {
+            if (params.pVersion == null) {
                 major = -1;
                 minor = -1;
             } else {
-                major = ckVersion.major;
-                minor = ckVersion.minor;
+                major = params.pVersion.major;
+                minor = params.pVersion.minor;
             }
             SecretKey key = P11Key.masterSecretKey(session, keyID,
                 "TlsMasterSecret", 48 << 3, attributes, major, minor);
@@ -156,5 +166,4 @@
             token.releaseSession(session);
         }
     }
-
 }
--- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -60,12 +60,20 @@
     @SuppressWarnings("deprecation")
     private TlsRsaPremasterSecretParameterSpec spec;
 
+    // whether SSLv3 is supported
+    private final boolean supportSSLv3;
+
     P11TlsRsaPremasterSecretGenerator(Token token, String algorithm, long mechanism)
             throws PKCS11Exception {
         super();
         this.token = token;
         this.algorithm = algorithm;
         this.mechanism = mechanism;
+
+        // Given the current lookup order specified in SunPKCS11.java,
+        // if CKM_SSL3_PRE_MASTER_KEY_GEN is not used to construct this object,
+        // it means that this mech is disabled or unsupported.
+        this.supportSSLv3 = (mechanism == CKM_SSL3_PRE_MASTER_KEY_GEN);
     }
 
     protected void engineInit(SecureRandom random) {
@@ -78,7 +86,20 @@
         if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
             throw new InvalidAlgorithmParameterException(MSG);
         }
-        this.spec = (TlsRsaPremasterSecretParameterSpec)params;
+
+        TlsRsaPremasterSecretParameterSpec spec =
+            (TlsRsaPremasterSecretParameterSpec) params;
+
+        int version = (spec.getMajorVersion() << 8) | spec.getMinorVersion();
+
+        if ((version == 0x0300 && !supportSSLv3) || (version < 0x0300) ||
+            (version > 0x0302)) {
+             throw new InvalidAlgorithmParameterException
+                    ("Only" + (supportSSLv3? " SSL 3.0,": "") +
+                     " TLS 1.0, and TLS 1.1 are supported (0x" +
+                     Integer.toHexString(version) + ")");
+        }
+        this.spec = spec;
     }
 
     protected void engineInit(int keysize, SecureRandom random) {
--- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/Secmod.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/Secmod.java	Fri Sep 30 09:28:18 2016 -0700
@@ -45,7 +45,7 @@
  * <pre>
  *   Secmod secmod = Secmod.getInstance();
  *   if (secmod.isInitialized() == false) {
- *       secmod.initialize("/home/myself/.mozilla", "/usr/sfw/lib/mozilla");
+ *       secmod.initialize("/home/myself/.mozilla");
  *   }
  *
  *   Provider p = secmod.getModule(ModuleType.KEYSTORE).getProvider();
@@ -743,6 +743,7 @@
         Map<Bytes,TrustAttributes> trustMap = new HashMap<Bytes,TrustAttributes>();
         Token token = provider.getToken();
         Session session = null;
+        boolean exceptionOccurred = true;
         try {
             session = token.getOpSession();
             int MAX_NUM = 8192;
@@ -762,8 +763,13 @@
                     // skip put on pkcs11 error
                 }
             }
+            exceptionOccurred = false;
         } finally {
-            token.releaseSession(session);
+            if (exceptionOccurred) {
+                token.killSession(session);
+            } else {
+                token.releaseSession(session);
+            }
         }
         return trustMap;
     }
--- a/jdk/src/jdk.crypto.ucrypto/solaris/classes/com/oracle/security/ucrypto/NativeCipherWithJavaPadding.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/jdk.crypto.ucrypto/solaris/classes/com/oracle/security/ucrypto/NativeCipherWithJavaPadding.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -160,8 +160,11 @@
                 ShortBufferException {
             int tbSize = (trailingBytes == null? 0:trailingBytes.position());
             int dataLen = tbSize + lastData.length;
-            // check total length
-            if ((dataLen < 1) || (dataLen % blockSize != 0)) {
+
+            // Special handling to match SunJCE provider behavior
+            if (dataLen <= 0) {
+                return 0;
+            } else if (dataLen % blockSize != 0) {
                 UcryptoProvider.debug("PKCS5Padding: unpad, buffered " + tbSize +
                                  " bytes, last block " + lastData.length + " bytes");
 
@@ -402,7 +405,6 @@
         throws ShortBufferException, IllegalBlockSizeException,
                BadPaddingException {
         int estimatedOutLen = engineGetOutputSize(inLen);
-
         if (out.length - outOfs < estimatedOutLen) {
             throw new ShortBufferException("Actual: " + (out.length - outOfs) +
                 ". Estimated Out Length: " + estimatedOutLen);
--- a/jdk/src/jdk.crypto.ucrypto/solaris/classes/com/oracle/security/ucrypto/NativeRSASignature.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/jdk.crypto.ucrypto/solaris/classes/com/oracle/security/ucrypto/NativeRSASignature.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -258,27 +258,38 @@
 
     @Override
     protected synchronized byte[] engineSign() throws SignatureException {
-        byte[] sig = new byte[sigLength];
-        int rv = doFinal(sig, 0, sigLength);
-        if (rv < 0) {
-            throw new SignatureException(new UcryptoException(-rv));
+        try {
+            byte[] sig = new byte[sigLength];
+            int rv = doFinal(sig, 0, sigLength);
+            if (rv < 0) {
+                throw new SignatureException(new UcryptoException(-rv));
+            }
+            return sig;
+        } finally {
+            // doFinal should already be called, no need to cancel
+            reset(false);
         }
-        return sig;
     }
 
     @Override
     protected synchronized int engineSign(byte[] outbuf, int offset, int len)
         throws SignatureException {
-        if (outbuf == null || (offset < 0) || (outbuf.length < (offset + sigLength))
-            || (len < sigLength)) {
-            throw new SignatureException("Invalid output buffer. offset: " +
-                offset + ". len: " + len + ". sigLength: " + sigLength);
+        boolean doCancel = true;
+        try {
+            if (outbuf == null || (offset < 0) || (outbuf.length < (offset + sigLength))
+                || (len < sigLength)) {
+                throw new SignatureException("Invalid output buffer. offset: " +
+                    offset + ". len: " + len + ". sigLength: " + sigLength);
+            }
+            int rv = doFinal(outbuf, offset, sigLength);
+            doCancel = false;
+            if (rv < 0) {
+                throw new SignatureException(new UcryptoException(-rv));
+            }
+            return sigLength;
+        } finally {
+            reset(doCancel);
         }
-        int rv = doFinal(outbuf, offset, sigLength);
-        if (rv < 0) {
-            throw new SignatureException(new UcryptoException(-rv));
-        }
-        return sigLength;
     }
 
     @Override
@@ -329,19 +340,25 @@
     @Override
     protected synchronized boolean engineVerify(byte[] sigBytes, int sigOfs, int sigLen)
         throws SignatureException {
-        if (sigBytes == null || (sigOfs < 0) || (sigBytes.length < (sigOfs + this.sigLength))
-            || (sigLen != this.sigLength)) {
-            throw new SignatureException("Invalid signature length: got " +
-                sigLen + " but was expecting " + this.sigLength);
-        }
+        boolean doCancel = true;
+        try {
+            if (sigBytes == null || (sigOfs < 0) || (sigBytes.length < (sigOfs + this.sigLength))
+                || (sigLen != this.sigLength)) {
+                throw new SignatureException("Invalid signature length: got " +
+                    sigLen + " but was expecting " + this.sigLength);
+            }
 
-        int rv = doFinal(sigBytes, sigOfs, sigLen);
-        if (rv == 0) {
-            return true;
-        } else {
-            UcryptoProvider.debug("Signature: " + mech + " verification error " +
+            int rv = doFinal(sigBytes, sigOfs, sigLen);
+            doCancel = false;
+            if (rv == 0) {
+                return true;
+            } else {
+                UcryptoProvider.debug("Signature: " + mech + " verification error " +
                              new UcryptoException(-rv).getMessage());
-            return false;
+                return false;
+            }
+        } finally {
+            reset(doCancel);
         }
     }
 
@@ -432,13 +449,9 @@
 
     // returns 0 (success) or negative (ucrypto error occurred)
     private int doFinal(byte[] sigBytes, int sigOfs, int sigLen) {
-        try {
-            ensureInitialized();
-            int k = nativeFinal(pCtxt.id, sign, sigBytes, sigOfs, sigLen);
-            return k;
-        } finally {
-            reset(false);
-        }
+        ensureInitialized();
+        int k = nativeFinal(pCtxt.id, sign, sigBytes, sigOfs, sigLen);
+        return k;
     }
 
     // check and return RSA key size in number of bytes
--- a/jdk/src/jdk.internal.le/share/classes/jdk/internal/jline/extra/EditingHistory.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/jdk.internal.le/share/classes/jdk/internal/jline/extra/EditingHistory.java	Fri Sep 30 09:28:18 2016 -0700
@@ -48,7 +48,9 @@
     private History currentDelegate;
 
     protected EditingHistory(ConsoleReader in, Iterable<? extends String> originalHistory) {
-        this.fullHistory = new MemoryHistory();
+        MemoryHistory fullHistory = new MemoryHistory();
+        fullHistory.setIgnoreDuplicates(false);
+        this.fullHistory = fullHistory;
         this.currentDelegate = fullHistory;
         bind(in, CTRL_UP,
              (Runnable) () -> moveHistoryToSnippet(in, ((EditingHistory) in.getHistory())::previousSnippet));
--- a/jdk/src/jdk.jdwp.agent/share/native/libjdwp/invoker.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/jdk.jdwp.agent/share/native/libjdwp/invoker.c	Fri Sep 30 09:28:18 2016 -0700
@@ -211,6 +211,62 @@
     return error;
 }
 
+/*
+ * Delete saved global references - if any - for:
+ * - a potentially thrown Exception
+ * - a returned refernce/array value
+ * See invoker_doInvoke() and invoke* methods where global references
+ * are being saved.
+ */
+static void
+deletePotentiallySavedGlobalRefs(JNIEnv *env, InvokeRequest *request)
+{
+    /* Delete potentially saved return value */
+    if ((request->invokeType == INVOKE_CONSTRUCTOR) ||
+        (returnTypeTag(request->methodSignature) == JDWP_TAG(OBJECT)) ||
+        (returnTypeTag(request->methodSignature) == JDWP_TAG(ARRAY))) {
+        if (request->returnValue.l != NULL) {
+            tossGlobalRef(env, &(request->returnValue.l));
+        }
+    }
+    /* Delete potentially saved exception */
+    if (request->exception != NULL) {
+        tossGlobalRef(env, &(request->exception));
+    }
+}
+
+/*
+ * Delete global argument references from the request which got put there before a
+ * invoke request was carried out. See fillInvokeRequest().
+ */
+static void
+deleteGlobalArgumentRefs(JNIEnv *env, InvokeRequest *request)
+{
+    void *cursor;
+    jint argIndex = 0;
+    jvalue *argument = request->arguments;
+    jbyte argumentTag = firstArgumentTypeTag(request->methodSignature, &cursor);
+
+    if (request->clazz != NULL) {
+        tossGlobalRef(env, &(request->clazz));
+    }
+    if (request->instance != NULL) {
+        tossGlobalRef(env, &(request->instance));
+    }
+    /* Delete global argument references */
+    while (argIndex < request->argumentCount) {
+        if ((argumentTag == JDWP_TAG(OBJECT)) ||
+            (argumentTag == JDWP_TAG(ARRAY))) {
+            if (argument->l != NULL) {
+                tossGlobalRef(env, &(argument->l));
+            }
+        }
+        argument++;
+        argIndex++;
+        argumentTag = nextArgumentTypeTag(&cursor);
+    }
+}
+
 static jvmtiError
 fillInvokeRequest(JNIEnv *env, InvokeRequest *request,
                   jbyte invokeType, jbyte options, jint id,
@@ -322,6 +378,8 @@
 invokeConstructor(JNIEnv *env, InvokeRequest *request)
 {
     jobject object;
+
+    JDI_ASSERT_MSG(request->clazz, "Request clazz null");
     object = JNI_FUNC_PTR(env,NewObjectA)(env, request->clazz,
                                      request->method,
                                      request->arguments);
@@ -338,6 +396,7 @@
         case JDWP_TAG(OBJECT):
         case JDWP_TAG(ARRAY): {
             jobject object;
+            JDI_ASSERT_MSG(request->clazz, "Request clazz null");
             object = JNI_FUNC_PTR(env,CallStaticObjectMethodA)(env,
                                        request->clazz,
                                        request->method,
@@ -426,6 +485,7 @@
         case JDWP_TAG(OBJECT):
         case JDWP_TAG(ARRAY): {
             jobject object;
+            JDI_ASSERT_MSG(request->instance, "Request instance null");
             object = JNI_FUNC_PTR(env,CallObjectMethodA)(env,
                                  request->instance,
                                  request->method,
@@ -513,6 +573,8 @@
         case JDWP_TAG(OBJECT):
         case JDWP_TAG(ARRAY): {
             jobject object;
+            JDI_ASSERT_MSG(request->clazz, "Request clazz null");
+            JDI_ASSERT_MSG(request->instance, "Request instance null");
             object = JNI_FUNC_PTR(env,CallNonvirtualObjectMethodA)(env,
                                            request->instance,
                                            request->clazz,
@@ -609,6 +671,8 @@
     JNIEnv *env;
     jboolean startNow;
     InvokeRequest *request;
+    jbyte options;
+    jbyte invokeType;
 
     JDI_ASSERT(thread);
 
@@ -625,6 +689,9 @@
     if (startNow) {
         request->started = JNI_TRUE;
     }
+    options = request->options;
+    invokeType = request->invokeType;
+
     debugMonitorExit(invokerLock);
 
     if (!startNow) {
@@ -639,7 +706,7 @@
 
         JNI_FUNC_PTR(env,ExceptionClear)(env);
 
-        switch (request->invokeType) {
+        switch (invokeType) {
             case INVOKE_CONSTRUCTOR:
                 invokeConstructor(env, request);
                 break;
@@ -647,7 +714,7 @@
                 invokeStatic(env, request);
                 break;
             case INVOKE_INSTANCE:
-                if (request->options & JDWP_INVOKE_OPTIONS(NONVIRTUAL) ) {
+                if (options & JDWP_INVOKE_OPTIONS(NONVIRTUAL) ) {
                     invokeNonvirtual(env, request);
                 } else {
                     invokeVirtual(env, request);
@@ -725,12 +792,23 @@
     }
 
     /*
+     * At this time, there's no need to retain global references on
+     * arguments since the reply is processed. No one will deal with
+     * this request ID anymore, so we must call deleteGlobalArgumentRefs().
+     *
+     * We cannot delete saved exception or return value references
+     * since otherwise a deleted handle would escape when writing
+     * the response to the stream. Instead, we clean those refs up
+     * after writing the respone.
+     */
+    deleteGlobalArgumentRefs(env, request);
+
+    /*
      * Give up the lock before I/O operation
      */
     debugMonitorExit(invokerLock);
     eventHandler_unlock();
 
-
     if (!detached) {
         outStream_initReply(&out, id);
         (void)outStream_writeValue(env, &out, tag, returnValue);
@@ -738,6 +816,16 @@
         (void)outStream_writeObjectRef(env, &out, exc);
         outStream_sendReply(&out);
     }
+
+    /*
+     * Delete potentially saved global references of return value
+     * and exception
+     */
+    eventHandler_lock(); // for proper lock order
+    debugMonitorEnter(invokerLock);
+    deletePotentiallySavedGlobalRefs(env, request);
+    debugMonitorExit(invokerLock);
+    eventHandler_unlock();
 }
 
 jboolean
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java	Fri Sep 30 09:28:18 2016 -0700
@@ -86,6 +86,9 @@
             task.options.help = true;
         }, "--help", "-h"),
         new Option<JlinkTask>(true, (task, opt, arg) -> {
+            // if used multiple times, the last one wins!
+            // So, clear previous values, if any.
+            task.options.modulePath.clear();
             String[] dirs = arg.split(File.pathSeparator);
             int i = 0;
             Arrays.stream(dirs)
@@ -93,6 +96,9 @@
                   .forEach(task.options.modulePath::add);
         }, "--module-path", "-p"),
         new Option<JlinkTask>(true, (task, opt, arg) -> {
+            // if used multiple times, the last one wins!
+            // So, clear previous values, if any.
+            task.options.limitMods.clear();
             for (String mn : arg.split(",")) {
                 if (mn.isEmpty()) {
                     throw taskHelper.newBadArgs("err.mods.must.be.specified",
--- a/jdk/src/jdk.management/share/native/libmanagement_ext/DiagnosticCommandImpl.c	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/src/jdk.management/share/native/libmanagement_ext/DiagnosticCommandImpl.c	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -45,6 +45,13 @@
   return jmm_interface->GetDiagnosticCommands(env);
 }
 
+#define EXCEPTION_CHECK_AND_FREE(x) do { \
+                                        if ((*env)->ExceptionCheck(env)) { \
+                                            free(x); \
+                                            return NULL; \
+                                        } \
+                                    } while(0)
+
 jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command,
                                               int num_arg) {
   int i;
@@ -59,6 +66,7 @@
   dcmd_arg_info_array = (dcmdArgInfo*) malloc(num_arg * sizeof(dcmdArgInfo));
   /* According to ISO C it is perfectly legal for malloc to return zero if called with a zero argument */
   if (dcmd_arg_info_array == NULL && num_arg != 0) {
+    JNU_ThrowOutOfMemoryError(env, 0);
     return NULL;
   }
   jmm_interface->GetDiagnosticCommandArgumentsInfo(env, command,
@@ -76,14 +84,24 @@
     return NULL;
   }
   for (i=0; i<num_arg; i++) {
+    jstring jname, jdesc,jtype,jdefStr;
+
+    jname = (*env)->NewStringUTF(env,dcmd_arg_info_array[i].name);
+    EXCEPTION_CHECK_AND_FREE(dcmd_arg_info_array);
+
+    jdesc = (*env)->NewStringUTF(env,dcmd_arg_info_array[i].description);
+    EXCEPTION_CHECK_AND_FREE(dcmd_arg_info_array);
+
+    jtype = (*env)->NewStringUTF(env,dcmd_arg_info_array[i].type);
+    EXCEPTION_CHECK_AND_FREE(dcmd_arg_info_array);
+
+    jdefStr = (*env)->NewStringUTF(env, dcmd_arg_info_array[i].default_string);
+    EXCEPTION_CHECK_AND_FREE(dcmd_arg_info_array);
     obj = JNU_NewObjectByName(env,
                               "com/sun/management/internal/DiagnosticCommandArgumentInfo",
                               "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZI)V",
-                              (*env)->NewStringUTF(env,dcmd_arg_info_array[i].name),
-                              (*env)->NewStringUTF(env,dcmd_arg_info_array[i].description),
-                              (*env)->NewStringUTF(env,dcmd_arg_info_array[i].type),
-                              dcmd_arg_info_array[i].default_string == NULL ? NULL:
-                              (*env)->NewStringUTF(env, dcmd_arg_info_array[i].default_string),
+                              jname, jdesc, jtype,
+                              dcmd_arg_info_array[i].default_string == NULL ? NULL: jdefStr,
                               dcmd_arg_info_array[i].mandatory,
                               dcmd_arg_info_array[i].option,
                               dcmd_arg_info_array[i].multiple,
@@ -93,6 +111,7 @@
       return NULL;
     }
     (*env)->SetObjectArrayElement(env, result, i, obj);
+    EXCEPTION_CHECK_AND_FREE(dcmd_arg_info_array);
   }
   free(dcmd_arg_info_array);
   arraysCls = (*env)->FindClass(env, "java/util/Arrays");
@@ -125,6 +144,7 @@
   jint ret = jmm_interface->GetOptionalSupport(env, &mos);
   jsize num_commands;
   dcmdInfo* dcmd_info_array;
+  jstring jname, jdesc, jimpact;
 
   if (commands == NULL) {
       JNU_ThrowNullPointerException(env, "Invalid String Array");
@@ -139,7 +159,6 @@
 
   result = (*env)->NewObjectArray(env, num_commands, dcmdInfoCls, NULL);
   if (result == NULL) {
-      JNU_ThrowOutOfMemoryError(env, 0);
       return NULL;
   }
   if (num_commands == 0) {
@@ -159,15 +178,22 @@
                                                    dcmd_info_array[i].num_arguments);
       if (args == NULL) {
           free(dcmd_info_array);
-          JNU_ThrowOutOfMemoryError(env, 0);
           return NULL;
       }
+
+      jname = (*env)->NewStringUTF(env,dcmd_info_array[i].name);
+      EXCEPTION_CHECK_AND_FREE(dcmd_info_array);
+
+      jdesc = (*env)->NewStringUTF(env,dcmd_info_array[i].description);
+      EXCEPTION_CHECK_AND_FREE(dcmd_info_array);
+
+      jimpact = (*env)->NewStringUTF(env,dcmd_info_array[i].impact);
+      EXCEPTION_CHECK_AND_FREE(dcmd_info_array);
+
       obj = JNU_NewObjectByName(env,
                                 "com/sun/management/internal/DiagnosticCommandInfo",
                                 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLjava/util/List;)V",
-                                (*env)->NewStringUTF(env,dcmd_info_array[i].name),
-                                (*env)->NewStringUTF(env,dcmd_info_array[i].description),
-                                (*env)->NewStringUTF(env,dcmd_info_array[i].impact),
+                                jname, jdesc, jimpact,
                                 dcmd_info_array[i].permission_class==NULL?NULL:(*env)->NewStringUTF(env,dcmd_info_array[i].permission_class),
                                 dcmd_info_array[i].permission_name==NULL?NULL:(*env)->NewStringUTF(env,dcmd_info_array[i].permission_name),
                                 dcmd_info_array[i].permission_action==NULL?NULL:(*env)->NewStringUTF(env,dcmd_info_array[i].permission_action),
@@ -175,10 +201,11 @@
                                 args);
       if (obj == NULL) {
           free(dcmd_info_array);
-          JNU_ThrowOutOfMemoryError(env, 0);
           return NULL;
       }
+
       (*env)->SetObjectArrayElement(env, result, i, obj);
+      EXCEPTION_CHECK_AND_FREE(dcmd_info_array);
   }
   free(dcmd_info_array);
   return result;
--- a/jdk/test/ProblemList.txt	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/ProblemList.txt	Fri Sep 30 09:28:18 2016 -0700
@@ -275,8 +275,6 @@
 
 java/util/spi/ResourceBundleControlProvider/UserDefaultControlTest.java 8062512 generic-all
 
-java/util/Arrays/ParallelPrefix.java                            8080165,8085982 generic-all
-
 java/util/BitSet/BitSetStreamTest.java                          8079538 generic-all
 
 ############################################################################
--- a/jdk/test/com/sun/jdi/InvokeHangTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/com/sun/jdi/InvokeHangTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
  *  @author jjh
  *
  *  @modules jdk.jdi
+ *  @library /test/lib
  *  @run build TestScaffold VMConnection TargetListener TargetAdapter
  *  @run compile -g InvokeHangTest.java
  *  @run driver InvokeHangTest
@@ -133,7 +134,7 @@
     BreakpointRequest request2;
     static volatile int bkpts = 0;
     Thread timerThread;
-    static int waitTime = 20000;
+    static long waitTime = jdk.test.lib.Utils.adjustTimeout(20000);
 
     InvokeHangTest (String args[]) {
         super(args);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/jdi/OomDebugTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,416 @@
+/*
+ * Copyright (c) 2016 Red Hat Inc.
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ *  @test
+ *  @bug 8153711
+ *  @summary JDWP: Memory Leak (global references not deleted after invokeMethod).
+ *
+ *  @author Severin Gehwolf <sgehwolf@redhat.com>
+ *
+ *  @library ..
+ *  @run build TestScaffold VMConnection TargetListener TargetAdapter
+ *  @run compile -g OomDebugTest.java
+ *  @run main OomDebugTest OomDebugTestTarget test1
+ *  @run main OomDebugTest OomDebugTestTarget test2
+ *  @run main OomDebugTest OomDebugTestTarget test3
+ *  @run main OomDebugTest OomDebugTestTarget test4
+ *  @run main OomDebugTest OomDebugTestTarget test5
+ */
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import com.sun.jdi.ArrayReference;
+import com.sun.jdi.ArrayType;
+import com.sun.jdi.ClassType;
+import com.sun.jdi.Field;
+import com.sun.jdi.InvocationException;
+import com.sun.jdi.Method;
+import com.sun.jdi.ObjectReference;
+import com.sun.jdi.ReferenceType;
+import com.sun.jdi.StackFrame;
+import com.sun.jdi.VMOutOfMemoryException;
+import com.sun.jdi.Value;
+import com.sun.jdi.event.BreakpointEvent;
+import com.sun.jdi.event.ExceptionEvent;
+
+/***************** Target program **********************/
+
+class OomDebugTestTarget {
+
+    OomDebugTestTarget() {
+        System.out.println("DEBUG: invoked constructor");
+    }
+    static class FooCls {
+        @SuppressWarnings("unused")
+        private byte[] bytes = new byte[3000000];
+    };
+
+    FooCls fooCls = new FooCls();
+    byte[] byteArray = new byte[0];
+
+    void testMethod(FooCls foo) {
+        System.out.println("DEBUG: invoked 'void testMethod(FooCls)', foo == " + foo);
+    }
+
+    void testPrimitive(byte[] foo) {
+        System.out.println("DEBUG: invoked 'void testPrimitive(byte[])', foo == " + foo);
+    }
+
+    byte[] testPrimitiveArrRetval() {
+        System.out.println("DEBUG: invoked 'byte[] testPrimitiveArrRetval()'");
+        return new byte[3000000];
+    }
+
+    FooCls testFooClsRetval() {
+        System.out.println("DEBUG: invoked 'FooCls testFooClsRetval()'");
+        return new FooCls();
+    }
+
+    public void entry() {}
+
+    public static void main(String[] args){
+        System.out.println("DEBUG: OomDebugTestTarget.main");
+        new OomDebugTestTarget().entry();
+    }
+}
+
+/***************** Test program ************************/
+
+public class OomDebugTest extends TestScaffold {
+
+    private static final String[] ALL_TESTS = new String[] {
+            "test1", "test2", "test3", "test4", "test5"
+    };
+    private static final Set<String> ALL_TESTS_SET = new HashSet<String>();
+    static {
+        ALL_TESTS_SET.addAll(Arrays.asList(ALL_TESTS));
+    }
+    private static final String TEST_CLASSES = System.getProperty("test.classes", ".");
+    private static final File RESULT_FILE = new File(TEST_CLASSES, "results.properties");
+    private static final String LAST_TEST = ALL_TESTS[ALL_TESTS.length - 1];
+    private ReferenceType targetClass;
+    private ObjectReference thisObject;
+    private int failedTests;
+    private final String testMethod;
+
+    public OomDebugTest(String[] args) {
+        super(args);
+        if (args.length != 2) {
+            throw new RuntimeException("Test failed unexpectedly.");
+        }
+        this.testMethod = args[1];
+    }
+
+    @Override
+    protected void runTests() throws Exception {
+        try {
+            addListener(new TargetAdapter() {
+
+                @Override
+                public void exceptionThrown(ExceptionEvent event) {
+                    String name = event.exception().referenceType().name();
+                    System.err.println("DEBUG: Exception thrown in debuggee was: " + name);
+                }
+            });
+            /*
+             * Get to the top of entry()
+             * to determine targetClass and mainThread
+             */
+            BreakpointEvent bpe = startTo("OomDebugTestTarget", "entry", "()V");
+            targetClass = bpe.location().declaringType();
+
+            mainThread = bpe.thread();
+
+            StackFrame frame = mainThread.frame(0);
+            thisObject = frame.thisObject();
+            java.lang.reflect.Method m = findTestMethod();
+            m.invoke(this);
+        } catch (NoSuchMethodException e) {
+            e.printStackTrace();
+            failure();
+        } catch (SecurityException e) {
+            e.printStackTrace();
+            failure();
+        }
+        /*
+         * resume the target, listening for events
+         */
+        listenUntilVMDisconnect();
+    }
+
+    private java.lang.reflect.Method findTestMethod()
+            throws NoSuchMethodException, SecurityException {
+        return OomDebugTest.class.getDeclaredMethod(testMethod);
+    }
+
+    private void failure() {
+        failedTests++;
+    }
+
+    /*
+     * Test case: Object reference as method parameter.
+     */
+    @SuppressWarnings("unused") // called via reflection
+    private void test1() throws Exception {
+        System.out.println("DEBUG: ------------> Running test1");
+        try {
+            Field field = targetClass.fieldByName("fooCls");
+            ClassType clsType = (ClassType)field.type();
+            Method constructor = getConstructorForClass(clsType);
+            for (int i = 0; i < 15; i++) {
+                @SuppressWarnings({ "rawtypes", "unchecked" })
+                ObjectReference objRef = clsType.newInstance(mainThread,
+                                                             constructor,
+                                                             new ArrayList(0),
+                                                             ObjectReference.INVOKE_NONVIRTUAL);
+                if (objRef.isCollected()) {
+                    System.out.println("DEBUG: Object got GC'ed before we can use it. NO-OP.");
+                    continue;
+                }
+                invoke("testMethod", "(LOomDebugTestTarget$FooCls;)V", objRef);
+            }
+        } catch (InvocationException e) {
+            handleFailure(e);
+        }
+    }
+
+    /*
+     * Test case: Array reference as method parameter.
+     */
+    @SuppressWarnings("unused") // called via reflection
+    private void test2() throws Exception {
+        System.out.println("DEBUG: ------------> Running test2");
+        try {
+            Field field = targetClass.fieldByName("byteArray");
+            ArrayType arrType = (ArrayType)field.type();
+
+            for (int i = 0; i < 15; i++) {
+                ArrayReference byteArrayVal = arrType.newInstance(3000000);
+                if (byteArrayVal.isCollected()) {
+                    System.out.println("DEBUG: Object got GC'ed before we can use it. NO-OP.");
+                    continue;
+                }
+                invoke("testPrimitive", "([B)V", byteArrayVal);
+            }
+        } catch (VMOutOfMemoryException e) {
+            defaultHandleOOMFailure(e);
+        }
+    }
+
+    /*
+     * Test case: Array reference as return value.
+     */
+    @SuppressWarnings("unused") // called via reflection
+    private void test3() throws Exception {
+        System.out.println("DEBUG: ------------> Running test3");
+        try {
+            for (int i = 0; i < 15; i++) {
+                invoke("testPrimitiveArrRetval",
+                       "()[B",
+                       Collections.EMPTY_LIST,
+                       vm().mirrorOfVoid());
+            }
+        } catch (InvocationException e) {
+            handleFailure(e);
+        }
+    }
+
+    /*
+     * Test case: Object reference as return value.
+     */
+    @SuppressWarnings("unused") // called via reflection
+    private void test4() throws Exception {
+        System.out.println("DEBUG: ------------> Running test4");
+        try {
+            for (int i = 0; i < 15; i++) {
+                invoke("testFooClsRetval",
+                       "()LOomDebugTestTarget$FooCls;",
+                       Collections.EMPTY_LIST,
+                       vm().mirrorOfVoid());
+            }
+        } catch (InvocationException e) {
+            handleFailure(e);
+        }
+    }
+
+    /*
+     * Test case: Constructor
+     */
+    @SuppressWarnings({ "unused", "unchecked", "rawtypes" }) // called via reflection
+    private void test5() throws Exception {
+        System.out.println("DEBUG: ------------> Running test5");
+        try {
+            ClassType type = (ClassType)thisObject.type();
+            for (int i = 0; i < 15; i++) {
+                type.newInstance(mainThread,
+                                 findMethod(targetClass, "<init>", "()V"),
+                                 new ArrayList(0),
+                                 ObjectReference.INVOKE_NONVIRTUAL);
+            }
+        } catch (InvocationException e) {
+            handleFailure(e);
+        }
+    }
+
+    private Method getConstructorForClass(ClassType clsType) {
+        List<Method> methods = clsType.methodsByName("<init>");
+        if (methods.size() != 1) {
+            throw new RuntimeException("FAIL. Expected only one, the default, constructor");
+        }
+        return methods.get(0);
+    }
+
+    private void handleFailure(InvocationException e) {
+        // There is no good way to see the OOME diagnostic message in the target since the
+        // TestScaffold might throw an exception while trying to print the stack trace. I.e
+        // it might get a a VMDisconnectedException before the stack trace printing finishes.
+        System.err.println("FAILURE: InvocationException thrown. Trying to determine cause...");
+        defaultHandleOOMFailure(e);
+    }
+
+    private void defaultHandleOOMFailure(Exception e) {
+        e.printStackTrace();
+        failure();
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    void invoke(String methodName, String methodSig, Value value)
+            throws Exception {
+        List args = new ArrayList(1);
+        args.add(value);
+        invoke(methodName, methodSig, args, value);
+    }
+
+    void invoke(String methodName,
+                String methodSig,
+                @SuppressWarnings("rawtypes") List args,
+                Value value) throws Exception {
+        Method method = findMethod(targetClass, methodName, methodSig);
+        if ( method == null) {
+            failure("FAILED: Can't find method: "
+                    + methodName  + " for class = " + targetClass);
+            return;
+        }
+        invoke(method, args, value);
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    void invoke(Method method, List args, Value value) throws Exception {
+        thisObject.invokeMethod(mainThread, method, args, 0);
+        System.out.println("DEBUG: Done invoking method via debugger.");
+    }
+
+    Value fieldValue(String fieldName) {
+        Field field = targetClass.fieldByName(fieldName);
+        return thisObject.getValue(field);
+    }
+
+    // Determine the pass/fail status on some heuristic and don't fail the
+    // test if < 3 of the total number of tests (currently 5) fail. This also
+    // has the nice side effect that all tests are first attempted and only
+    // all tests ran an overall pass/fail status is determined.
+    private static void determineOverallTestStatus(OomDebugTest oomTest)
+                                   throws IOException, FileNotFoundException {
+        Properties resultProps = new Properties();
+        if (!RESULT_FILE.exists()) {
+            RESULT_FILE.createNewFile();
+        }
+        FileInputStream fin = null;
+        try {
+            fin = new FileInputStream(RESULT_FILE);
+            resultProps.load(fin);
+            resultProps.put(oomTest.testMethod,
+                            Integer.toString(oomTest.failedTests));
+        } finally {
+            if (fin != null) {
+                fin.close();
+            }
+        }
+        System.out.println("DEBUG: Finished running test '"
+                           + oomTest.testMethod + "'.");
+        if (LAST_TEST.equals(oomTest.testMethod)) {
+            System.out.println("DEBUG: Determining overall test status.");
+            Set<String> actualTestsRun = new HashSet<String>();
+            int totalTests = ALL_TESTS.length;
+            int failedTests = 0;
+            for (Object key: resultProps.keySet()) {
+                actualTestsRun.add((String)key);
+                Object propVal = resultProps.get(key);
+                int value = Integer.parseInt((String)propVal);
+                failedTests += value;
+            }
+            if (!ALL_TESTS_SET.equals(actualTestsRun)) {
+                String errorMsg = "Test failed! Expected to run tests '"
+                        + ALL_TESTS_SET + "', but only these were run '"
+                        + actualTestsRun + "'";
+                throw new RuntimeException(errorMsg);
+            }
+            if (failedTests >= 3) {
+                String errorMsg = "Test failed. Expected < 3 sub-tests to fail "
+                                  + "for a pass. Got " + failedTests
+                                  + " failed tests out of " + totalTests + ".";
+                throw new RuntimeException(errorMsg);
+            }
+            RESULT_FILE.delete();
+            System.out.println("All " + totalTests + " tests passed.");
+        } else {
+            System.out.println("DEBUG: More tests to run. Coninuing.");
+            FileOutputStream fout = null;
+            try {
+                fout = new FileOutputStream(RESULT_FILE);
+                resultProps.store(fout, "Storing results after test "
+                                         + oomTest.testMethod);
+            } finally {
+                if (fout != null) {
+                    fout.close();
+                }
+            }
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        System.setProperty("test.vm.opts", "-Xmx40m"); // Set debuggee VM option
+        OomDebugTest oomTest = new OomDebugTest(args);
+        try {
+            oomTest.startTests();
+        } catch (Throwable e) {
+            System.out.println("DEBUG: Got exception for test run. " + e);
+            e.printStackTrace();
+            oomTest.failure();
+        }
+        determineOverallTestStatus(oomTest);
+    }
+
+}
--- a/jdk/test/com/sun/net/httpserver/Test5.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/com/sun/net/httpserver/Test5.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -145,6 +145,7 @@
         socket.close();
         s = new String (b,0,count, "ISO8859_1");
         if (!compare (s, result)) {
+            System.err.println(" Expected [" + result + "]\n actual [" + s + "]");
             throw new RuntimeException ("wrong string result");
         }
     }
--- a/jdk/test/java/beans/XMLEncoder/EnumPrivate.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-enum EnumPrivate {
-    A0,B0,C0,D0,E0,F0,G0,H0,I0,J0,K0,L0,M0,N0,O0,P0,Q0,R0,S0,T0,U0,V0,W0,X0,Y0,Z0,
-    A1,B1,C1,D1,E1,F1,G1,H1,I1,J1,K1,L1,M1,N1,O1,P1,Q1,R1,S1,T1,U1,V1,W1,X1,Y1,Z1,
-    A2,B2,C2,D2,E2,F2,G2,H2,I2,J2,K2,L2,M2,N2,O2,P2,Q2,R2,S2,T2,U2,V2,W2,X2,Y2,Z2,
-    A3,B3,C3,D3,E3,F3,G3,H3,I3,J3,K3,L3,M3,N3,O3,P3,Q3,R3,S3,T3,U3,V3,W3,X3,Y3,Z3,
-    A4,B4,C4,D4,E4,F4,G4,H4,I4,J4,K4,L4,M4,N4,O4,P4,Q4,R4,S4,T4,U4,V4,W4,X4,Y4,Z4,
-    A5,B5,C5,D5,E5,F5,G5,H5,I5,J5,K5,L5,M5,N5,O5,P5,Q5,R5,S5,T5,U5,V5,W5,X5,Y5,Z5,
-    A6,B6,C6,D6,E6,F6,G6,H6,I6,J6,K6,L6,M6,N6,O6,P6,Q6,R6,S6,T6,U6,V6,W6,X6,Y6,Z6,
-    A7,B7,C7,D7,E7,F7,G7,H7,I7,J7,K7,L7,M7,N7,O7,P7,Q7,R7,S7,T7,U7,V7,W7,X7,Y7,Z7,
-    A8,B8,C8,D8,E8,F8,G8,H8,I8,J8,K8,L8,M8,N8,O8,P8,Q8,R8,S8,T8,U8,V8,W8,X8,Y8,Z8,
-    A9,B9,C9,D9,E9,F9,G9,H9,I9,J9,K9,L9,M9,N9,O9,P9,Q9,R9,S9,T9,U9,V9,W9,X9,Y9,Z9,
-}
--- a/jdk/test/java/beans/XMLEncoder/EnumPublic.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-public enum EnumPublic {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}
--- a/jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedCollection.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6505888
- * @summary Tests CheckedCollection encoding
- * @author Sergey Malenkov
- */
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-public final class java_util_Collections_CheckedCollection extends AbstractTest<Collection<String>> {
-    public static void main(String[] args) {
-        new java_util_Collections_CheckedCollection().test(true);
-    }
-
-    protected Collection<String> getObject() {
-        List<String> list = Collections.singletonList("string");
-        return Collections.checkedCollection(list, String.class);
-    }
-
-    protected Collection<String> getAnotherObject() {
-        List<String> list = Collections.emptyList();
-        return Collections.checkedCollection(list, String.class);
-    }
-}
--- a/jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedList.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6505888
- * @summary Tests CheckedList encoding
- * @author Sergey Malenkov
- */
-
-import java.util.Collections;
-import java.util.List;
-
-public final class java_util_Collections_CheckedList extends AbstractTest<List<String>> {
-    public static void main(String[] args) {
-        new java_util_Collections_CheckedList().test(true);
-    }
-
-    protected List<String> getObject() {
-        List<String> list = Collections.singletonList("string");
-        return Collections.checkedList(list, String.class);
-    }
-
-    protected List<String> getAnotherObject() {
-        List<String> list = Collections.emptyList();
-        return Collections.checkedList(list, String.class);
-    }
-}
--- a/jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedMap.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6505888
- * @summary Tests CheckedMap encoding
- * @author Sergey Malenkov
- */
-
-import java.util.Collections;
-import java.util.Map;
-
-public final class java_util_Collections_CheckedMap extends AbstractTest<Map<String, String>> {
-    public static void main(String[] args) {
-        new java_util_Collections_CheckedMap().test(true);
-    }
-
-    protected Map<String, String> getObject() {
-        Map<String, String> map = Collections.singletonMap("key", "value");
-        return Collections.checkedMap(map, String.class, String.class);
-    }
-
-    protected Map<String, String> getAnotherObject() {
-        Map<String, String> map = Collections.emptyMap();
-        return Collections.checkedMap(map, String.class, String.class);
-    }
-}
--- a/jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedRandomAccessList.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6505888
- * @summary Tests CheckedRandomAccessList encoding
- * @author Sergey Malenkov
- */
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public final class java_util_Collections_CheckedRandomAccessList extends AbstractTest<List<String>> {
-    public static void main(String[] args) {
-        new java_util_Collections_CheckedRandomAccessList().test(true);
-    }
-
-    protected List<String> getObject() {
-        List<String> list = new ArrayList<String>();
-        list.add("string");
-        return Collections.checkedList(list, String.class);
-    }
-
-    protected List<String> getAnotherObject() {
-        List<String> list = new ArrayList<String>();
-        return Collections.checkedList(list, String.class);
-    }
-}
--- a/jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedSet.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6505888
- * @summary Tests CheckedSet encoding
- * @author Sergey Malenkov
- */
-
-import java.util.Collections;
-import java.util.Set;
-
-public final class java_util_Collections_CheckedSet extends AbstractTest<Set<String>> {
-    public static void main(String[] args) {
-        new java_util_Collections_CheckedSet().test(true);
-    }
-
-    protected Set<String> getObject() {
-        Set<String> set = Collections.singleton("string");
-        return Collections.checkedSet(set, String.class);
-    }
-
-    protected Set<String> getAnotherObject() {
-        Set<String> set = Collections.emptySet();
-        return Collections.checkedSet(set, String.class);
-    }
-}
--- a/jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedSortedMap.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6505888
- * @summary Tests CheckedSortedMap encoding
- * @author Sergey Malenkov
- */
-
-import java.util.Collections;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-public final class java_util_Collections_CheckedSortedMap extends AbstractTest<SortedMap<String, String>> {
-    public static void main(String[] args) {
-        new java_util_Collections_CheckedSortedMap().test(true);
-    }
-
-    protected SortedMap<String, String> getObject() {
-        SortedMap<String, String> map = new TreeMap<String, String>();
-        map.put("key", "value");
-        return Collections.checkedSortedMap(map, String.class, String.class);
-    }
-
-    protected SortedMap<String, String> getAnotherObject() {
-        SortedMap<String, String> map = new TreeMap<String, String>();
-        return Collections.checkedSortedMap(map, String.class, String.class);
-    }
-}
--- a/jdk/test/java/beans/XMLEncoder/java_util_Collections_CheckedSortedSet.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6505888
- * @summary Tests CheckedSortedSet encoding
- * @author Sergey Malenkov
- */
-
-import java.util.Collections;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-public final class java_util_Collections_CheckedSortedSet extends AbstractTest<SortedSet<String>> {
-    public static void main(String[] args) {
-        new java_util_Collections_CheckedSortedSet().test(true);
-    }
-
-    protected SortedSet<String> getObject() {
-        SortedSet<String> set = new TreeSet<String>();
-        set.add("string");
-        return Collections.checkedSortedSet(set, String.class);
-    }
-
-    protected SortedSet<String> getAnotherObject() {
-        SortedSet<String> set = new TreeSet<String>();
-        return Collections.checkedSortedSet(set, String.class);
-    }
-}
--- a/jdk/test/java/beans/XMLEncoder/java_util_EnumMap.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6536295
- * @summary Tests EnumMap encoding
- * @author Sergey Malenkov
- */
-
-import java.util.EnumMap;
-import java.util.Map;
-
-public final class java_util_EnumMap extends AbstractTest<Map<EnumPublic, String>> {
-    public static void main(String[] args) {
-        new java_util_EnumMap().test(true);
-    }
-
-    protected Map<EnumPublic, String> getObject() {
-        return new EnumMap<EnumPublic, String>(EnumPublic.class);
-    }
-
-    protected Map<EnumPublic, String> getAnotherObject() {
-        Map<EnumPublic, String> map = new EnumMap<EnumPublic, String>(EnumPublic.class);
-        map.put(EnumPublic.A, "value");
-        map.put(EnumPublic.Z, null);
-        return map;
-    }
-}
--- a/jdk/test/java/beans/XMLEncoder/java_util_JumboEnumSet.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6536295
- * @summary Tests JumboEnumSet encoding
- * @author Sergey Malenkov
- */
-
-import java.util.EnumSet;
-import java.util.Set;
-
-public final class java_util_JumboEnumSet extends AbstractTest<Set<EnumPrivate>> {
-    public static void main(String[] args) {
-        new java_util_JumboEnumSet().test(true);
-    }
-
-    protected Set<EnumPrivate> getObject() {
-        return EnumSet.noneOf(EnumPrivate.class);
-    }
-
-    protected Set<EnumPrivate> getAnotherObject() {
-        Set<EnumPrivate> set = EnumSet.noneOf(EnumPrivate.class);
-        set.add(EnumPrivate.A0);
-        set.add(EnumPrivate.Z9);
-        return set;
-    }
-}
--- a/jdk/test/java/beans/XMLEncoder/java_util_RegularEnumSet.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6536295
- * @summary Tests RegularEnumSet encoding
- * @author Sergey Malenkov
- */
-
-import java.util.EnumSet;
-import java.util.Set;
-
-public final class java_util_RegularEnumSet extends AbstractTest<Set<EnumPublic>> {
-    public static void main(String[] args) {
-        new java_util_RegularEnumSet().test(true);
-    }
-
-    protected Set<EnumPublic> getObject() {
-        return EnumSet.noneOf(EnumPublic.class);
-    }
-
-    protected Set<EnumPublic> getAnotherObject() {
-        Set<EnumPublic> set = EnumSet.noneOf(EnumPublic.class);
-        set.add(EnumPublic.A);
-        set.add(EnumPublic.Z);
-        return set;
-    }
-}
--- a/jdk/test/java/io/PrintStream/FormatLocale.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/io/PrintStream/FormatLocale.java	Fri Sep 30 09:28:18 2016 -0700
@@ -21,10 +21,11 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 8146156
  * @summary test whether conversion follows Locale.Category.FORMAT locale.
+ * @modules jdk.localedata
  * @run main/othervm FormatLocale
  */
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/Main.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8157464
+ * @summary Basic test for StackWalker.getCallerClass()
+ * @library src
+ * @build java.base/java.util.CSM csm/*
+ * @run main/othervm csm/jdk.test.CallerSensitiveTest
+ * @run main/othervm csm/jdk.test.CallerSensitiveTest sm
+ */
+public class Main {
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/csm/jdk/test/CallerSensitiveTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.test;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodHandles.Lookup;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Method;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.Permissions;
+import java.security.Policy;
+import java.security.ProtectionDomain;
+import java.util.CSM.Result;
+import java.util.function.Supplier;
+
+/**
+ * This test invokes StackWalker::getCallerClass via static reference,
+ * reflection, MethodHandle, lambda.  Also verify that
+ * StackWalker::getCallerClass can't be called from @CallerSensitive method.
+ */
+public class CallerSensitiveTest {
+    private static final String NON_CSM_CALLER_METHOD = "getCallerClass";
+    private static final String CSM_CALLER_METHOD = "caller";
+
+    public static void main(String... args) throws Throwable {
+        boolean sm = false;
+        if (args.length > 0 && args[0].equals("sm")) {
+            sm = true;
+            PermissionCollection perms = new Permissions();
+            perms.add(new StackFramePermission("retainClassReference"));
+            Policy.setPolicy(new Policy() {
+                @Override
+                public boolean implies(ProtectionDomain domain, Permission p) {
+                    return perms.implies(p);
+                }
+            });
+            System.setSecurityManager(new SecurityManager());
+        }
+
+        System.err.format("Test %s security manager.%n",
+                          sm ? "with" : "without");
+
+        CallerSensitiveTest cstest = new CallerSensitiveTest();
+        // test static call to java.util.CSM::caller and CSM::getCallerClass
+        cstest.staticMethodCall();
+        // test java.lang.reflect.Method call
+        cstest.reflectMethodCall();
+        // test java.lang.invoke.MethodHandle
+        cstest.invokeMethodHandle(Lookup1.lookup);
+        cstest.invokeMethodHandle(Lookup2.lookup);
+        // test method ref
+        cstest.lambda();
+
+        LambdaTest.lambda();
+
+        if (failed > 0) {
+            throw new RuntimeException(failed + " test cases failed.");
+        }
+    }
+
+    void staticMethodCall() {
+        java.util.CSM.caller();
+
+        Result result = java.util.CSM.getCallerClass();
+        checkNonCSMCaller(CallerSensitiveTest.class, result);
+    }
+
+    void reflectMethodCall() throws Throwable {
+        Method method1 = java.util.CSM.class.getMethod(CSM_CALLER_METHOD);
+        method1.invoke(null);
+
+        Method method2 = java.util.CSM.class.getMethod(NON_CSM_CALLER_METHOD);
+        Result result = (Result) method2.invoke(null);
+        checkNonCSMCaller(CallerSensitiveTest.class, result);
+    }
+
+    void invokeMethodHandle(Lookup lookup) throws Throwable {
+        MethodHandle mh1 = lookup.findStatic(java.util.CSM.class, CSM_CALLER_METHOD,
+            MethodType.methodType(Class.class));
+        Class<?> c = (Class<?>)mh1.invokeExact();
+
+        MethodHandle mh2 = lookup.findStatic(java.util.CSM.class, NON_CSM_CALLER_METHOD,
+            MethodType.methodType(Result.class));
+        Result result = (Result)mh2.invokeExact();
+        checkNonCSMCaller(CallerSensitiveTest.class, result);
+    }
+
+    void lambda() {
+        Result result = LambdaTest.getCallerClass.get();
+        checkNonCSMCaller(CallerSensitiveTest.class, result);
+
+        LambdaTest.caller.get();
+    }
+
+    static int failed = 0;
+
+    static void checkNonCSMCaller(Class<?> expected, Result result) {
+        if (result.callers.size() != 1) {
+            throw new RuntimeException("Expected result.callers contain one element");
+        }
+        if (expected != result.callers.get(0)) {
+            System.err.format("ERROR: Expected %s but got %s%n", expected,
+                result.callers);
+            result.frames.stream()
+                .forEach(f -> System.err.println("   " + f));
+            failed++;
+        }
+    }
+
+    static class Lookup1 {
+        static Lookup lookup = MethodHandles.lookup();
+    }
+
+    static class Lookup2 {
+        static Lookup lookup = MethodHandles.lookup();
+    }
+
+    static class LambdaTest {
+        static Supplier<Class<?>> caller = java.util.CSM::caller;
+        static Supplier<Result> getCallerClass = java.util.CSM::getCallerClass;
+
+        static void caller() {
+            caller.get();
+        }
+        static Result getCallerClass() {
+            return getCallerClass.get();
+        }
+
+        static void lambda() {
+            Result result = LambdaTest.getCallerClass();
+            checkNonCSMCaller(LambdaTest.class, result);
+
+            LambdaTest.caller();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/csm/module-info.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+module csm {
+    exports jdk.test;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/src/java.base/java/util/CSM.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util;
+
+import static java.lang.StackWalker.Option.*;
+import java.lang.StackWalker.StackFrame;
+import java.util.stream.Collectors;
+
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
+
+public class CSM {
+    private static StackWalker walker =
+        StackWalker.getInstance(EnumSet.of(RETAIN_CLASS_REFERENCE,
+                                           SHOW_HIDDEN_FRAMES,
+                                           SHOW_REFLECT_FRAMES));
+
+    public static class Result {
+        public final List<Class<?>> callers;
+        public final List<StackWalker.StackFrame> frames;
+        Result(List<Class<?>> callers,
+               List<StackFrame> frames) {
+            this.callers = callers;
+            this.frames = frames;
+        }
+    }
+
+    /**
+     * Returns the caller of this caller-sensitive method returned by
+     * by Reflection::getCallerClass.
+     *
+     * StackWalker::getCallerClass is expected to throw UOE
+     */
+    @CallerSensitive
+    public static Class<?> caller() {
+        Class<?> c1 = Reflection.getCallerClass();
+
+        try {
+            Class<?> c2 = walker.getCallerClass();
+            throw new RuntimeException("Exception not thrown by StackWalker::getCallerClass");
+        } catch (UnsupportedOperationException e) {}
+        return c1;
+    }
+
+    /**
+     * Returns the caller of this non-caller-sensitive method.
+     */
+    public static Result getCallerClass() {
+        Class<?> caller = walker.getCallerClass();
+        return new Result(List.of(caller), dump());
+    }
+
+    static List<StackFrame> dump() {
+        return walker.walk(s -> s.collect(Collectors.toList()));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/SimpleAgent.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.lang.instrument.Instrumentation;
+
+class SimpleAgent {
+
+    public static void premain(String args, Instrumentation inst) {
+        System.out.println("in premain");
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/TestAgentWithLimitMods.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ *
+ * @test
+ * @summary Tests that the -javaagent option adds the java.instrument into
+ * the module graph
+ * @modules java.instrument
+ * @run shell MakeJAR3.sh SimpleAgent
+ * @run main/othervm -javaagent:SimpleAgent.jar -limitmods java.base TestAgentWithLimitMods
+ *
+ */
+public class TestAgentWithLimitMods {
+
+    public static void main(String[] args) {
+        System.out.println("Test passed");
+    }
+
+}
--- a/jdk/test/java/lang/invoke/CountedLoopIterationCountsTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/lang/invoke/CountedLoopIterationCountsTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -71,7 +71,7 @@
         }
     }
 
-    static int step(int counter, int stepCount) {
+    static int step(int stepCount, int counter) {
         return stepCount + 1;
     }
 
--- a/jdk/test/java/lang/invoke/JavaDocExamplesTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/lang/invoke/JavaDocExamplesTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -703,6 +703,66 @@
         }}
     }
 
+    static int inc(int i) { return i + 1; } // drop acc, k
+    static int mult(int i, int acc) { return i * acc; } //drop k
+    static boolean cmp(int i, int k) { return i < k; }
+
+    @Test public void testSimplerLoop() throws Throwable {
+        MethodHandle MH_inc, MH_mult, MH_cmp;
+        Class<?> I = int.class;
+        MH_inc = LOOKUP.findStatic(THIS_CLASS, "inc", methodType(I, I));
+        MH_mult = LOOKUP.findStatic(THIS_CLASS, "mult", methodType(I, I, I));
+        MH_cmp = LOOKUP.findStatic(THIS_CLASS, "cmp", methodType(boolean.class, I, I));
+        {{
+{} /// JAVADOC
+// simplified implementation of the factorial function as a loop handle
+// null initializer for counter, should initialize to 0
+MethodHandle MH_one = MethodHandles.constant(int.class, 1);
+MethodHandle MH_pred = MethodHandles.dropArguments(MH_cmp, 1, int.class); // drop acc
+MethodHandle MH_fin = MethodHandles.dropArguments(MethodHandles.identity(int.class), 0, int.class); // drop i
+MethodHandle[] counterClause = new MethodHandle[]{null, MH_inc};
+MethodHandle[] accumulatorClause = new MethodHandle[]{MH_one, MH_mult, MH_pred, MH_fin};
+MethodHandle loop = MethodHandles.loop(counterClause, accumulatorClause);
+assertEquals(720, loop.invoke(6));
+{}
+        }}
+    }
+
+    // for testFacLoop
+{}
+static class FacLoop {
+  final int k;
+  FacLoop(int k) { this.k = k; }
+  int inc(int i) { return i + 1; }
+  int mult(int i, int acc) { return i * acc; }
+  boolean pred(int i) { return i < k; }
+  int fin(int i, int acc) { return acc; }
+}
+{}
+
+    // assume MH_inc, MH_mult, and MH_pred are handles to the above methods
+    @Test public void testFacLoop() throws Throwable {
+        MethodHandle MH_FacLoop, MH_inc, MH_mult, MH_pred, MH_fin;
+        Class<?> I = int.class;
+        MH_FacLoop = LOOKUP.findConstructor(FacLoop.class, methodType(void.class, I));
+        MH_inc = LOOKUP.findVirtual(FacLoop.class, "inc", methodType(I, I));
+        MH_mult = LOOKUP.findVirtual(FacLoop.class, "mult", methodType(I, I, I));
+        MH_pred = LOOKUP.findVirtual(FacLoop.class, "pred", methodType(boolean.class, I));
+        MH_fin = LOOKUP.findVirtual(FacLoop.class, "fin", methodType(I, I, I));
+        {{
+{} /// JAVADOC
+// instance-based implementation of the factorial function as a loop handle
+// null initializer for counter, should initialize to 0
+MethodHandle MH_one = MethodHandles.constant(int.class, 1);
+MethodHandle[] instanceClause = new MethodHandle[]{MH_FacLoop};
+MethodHandle[] counterClause = new MethodHandle[]{null, MH_inc};
+MethodHandle[] accumulatorClause = new MethodHandle[]{MH_one, MH_mult, MH_pred, MH_fin};
+MethodHandle loop = MethodHandles.loop(instanceClause, counterClause, accumulatorClause);
+assertEquals(5040, loop.invoke(7));
+{}
+        }}
+    }
+
     static List<String> initZip(Iterator<String> a, Iterator<String> b) { return new ArrayList<>(); }
     static boolean zipPred(List<String> zip, Iterator<String> a, Iterator<String> b) { return a.hasNext() && b.hasNext(); }
     static List<String> zipStep(List<String> zip, Iterator<String> a, Iterator<String> b) {
@@ -749,36 +809,81 @@
         }}
     }
 
-    static String start(String arg) { return arg; }
-    static String step(int counter, String v, String arg) { return "na " + v; }
+    static String step(String v, int counter, String start_) { return "na " + v; }  //#0
+    static String step(String v, int counter ) { return "na " + v; } //#1
+    static String step(String v, int counter, int iterations_, String pre, String start_) { return pre + " " + v; } //#2
+    static String step3(String v, int counter, String pre) { return pre + " " + v; } //#3
 
     @Test public void testCountedLoop() throws Throwable {
-        MethodHandle MH_start, MH_step;
-        Class<?> S = String.class;
-        MH_start = LOOKUP.findStatic(THIS_CLASS, "start", methodType(S, S));
-        MH_step = LOOKUP.findStatic(THIS_CLASS, "step", methodType(S, int.class, S, S));
+        MethodHandle MH_step;
+        Class<?> S = String.class, I = int.class;
+        // Theme:
+        MH_step = LOOKUP.findStatic(THIS_CLASS, "step", methodType(S, S, I, S));
         {{
 {} /// JAVADOC
 // String s = "Lambdaman!"; for (int i = 0; i < 13; ++i) { s = "na " + s; } return s;
 // => a variation on a well known theme
 MethodHandle fit13 = MethodHandles.constant(int.class, 13);
-MethodHandle loop = MethodHandles.countedLoop(fit13, MH_start, MH_step);
+MethodHandle start = MethodHandles.identity(String.class);
+MethodHandle loop = MethodHandles.countedLoop(fit13, start, MH_step);  // (v, i, _) -> "na " + v
 assertEquals("na na na na na na na na na na na na na Lambdaman!", loop.invoke("Lambdaman!"));
 {}
         }}
+        // Variation #1:
+        MH_step = LOOKUP.findStatic(THIS_CLASS, "step", methodType(S, S, I));
+        {{
+{} /// JAVADOC
+// String s = "Lambdaman!"; for (int i = 0; i < 13; ++i) { s = "na " + s; } return s;
+// => a variation on a well known theme
+MethodHandle count = MethodHandles.dropArguments(MethodHandles.identity(int.class), 1, String.class);
+MethodHandle start = MethodHandles.dropArguments(MethodHandles.identity(String.class), 0, int.class);
+MethodHandle loop = MethodHandles.countedLoop(count, start, MH_step);  // (v, i) -> "na " + v
+assertEquals("na na na na na na na na na na na na na Lambdaman!", loop.invoke(13, "Lambdaman!"));
+{}
+            assertEquals("na na Lambdaman!", loop.invoke(2, "Lambdaman!"));
+            assertEquals("Lambdaman!", loop.invoke(0, "Lambdaman!"));
+            assertEquals("Lambdaman!", loop.invoke(-1, "Lambdaman!"));
+            assertEquals("Lambdaman!", loop.invoke(Integer.MIN_VALUE, "Lambdaman!"));
+        }}
+        // Variation #2:
+        MH_step = LOOKUP.findStatic(THIS_CLASS, "step", methodType(S, S, I, I, S, S));
+        {{
+{} /// JAVADOC
+// String s = "Lambdaman!", t = "na"; for (int i = 0; i < 13; ++i) { s = t + " " + s; } return s;
+// => a variation on a well known theme
+MethodHandle count = MethodHandles.identity(int.class);
+MethodHandle start = MethodHandles.dropArguments(MethodHandles.identity(String.class), 0, int.class, String.class);
+MethodHandle loop = MethodHandles.countedLoop(count, start, MH_step);  // (v, i, _, pre, _) -> pre + " " + v
+assertEquals("na na na na na na na na na na na na na Lambdaman!", loop.invoke(13, "na", "Lambdaman!"));
+{}
+        }}
+        // Variation #3:
+        MH_step = LOOKUP.findStatic(THIS_CLASS, "step3", methodType(S, S, I, S));
+        {{
+{} /// JAVADOC
+// String s = "Lambdaman!", t = "na"; for (int i = 0; i < 13; ++i) { s = t + " " + s; } return s;
+// => a variation on a well known theme
+MethodType loopType = methodType(String.class, String.class, int.class, String.class);
+MethodHandle count = MethodHandles.dropArgumentsToMatch(MethodHandles.identity(int.class),    0, loopType.parameterList(), 1);
+MethodHandle start = MethodHandles.dropArgumentsToMatch(MethodHandles.identity(String.class), 0, loopType.parameterList(), 2);
+MethodHandle body  = MethodHandles.dropArgumentsToMatch(MH_step,                              2, loopType.parameterList(), 0);
+MethodHandle loop = MethodHandles.countedLoop(count, start, body);  // (v, i, pre, _, _) -> pre + " " + v
+assertEquals("na na na na na na na na na na na na na Lambdaman!", loop.invoke("na", 13, "Lambdaman!"));
+{}
+        }}
     }
 
-    static List<String> reverseStep(String e, List<String> r, List<String> l) {
+    static List<String> reverseStep(List<String> r, String e) {
         r.add(0, e);
         return r;
     }
-    static List<String> newArrayList(List<String> l) { return new ArrayList<>(); }
+    static List<String> newArrayList() { return new ArrayList<>(); }
 
     @Test public void testIteratedLoop() throws Throwable {
         MethodHandle MH_newArrayList, MH_reverseStep;
-        Class<?> L = List.class;
-        MH_newArrayList = LOOKUP.findStatic(THIS_CLASS, "newArrayList", methodType(L, L));
-        MH_reverseStep = LOOKUP.findStatic(THIS_CLASS, "reverseStep", methodType(L, String.class, L, L));
+        Class<?> L = List.class, S = String.class;
+        MH_newArrayList = LOOKUP.findStatic(THIS_CLASS, "newArrayList", methodType(L));
+        MH_reverseStep = LOOKUP.findStatic(THIS_CLASS, "reverseStep", methodType(L, L, S));
         {{
 {} /// JAVADOC
 // reverse a list
--- a/jdk/test/java/lang/invoke/LoopCombinatorTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/lang/invoke/LoopCombinatorTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -28,6 +28,7 @@
  * @bug 8150635
  * @bug 8150956
  * @bug 8150957
+ * @bug 8151179
  * @bug 8152667
  * @bug 8153637
  * @bug 8154751
@@ -146,6 +147,16 @@
         assertEquals(120, loop.invoke(new LoopWithVirtuals(), 5));
     }
 
+    @Test
+    public static void testLoopOmitPred() throws Throwable {
+        // construct a loop to calculate factorial that omits a predicate
+        MethodHandle[] counterClause = new MethodHandle[]{null, Fac.MH_inc, null, Fac.MH_fin};
+        MethodHandle[] accumulatorClause = new MethodHandle[]{Fac.MH_one, Fac.MH_mult, Fac.MH_pred, Fac.MH_fin};
+        MethodHandle loop = MethodHandles.loop(counterClause, accumulatorClause);
+        assertEquals(Fac.MT_fac, loop.type());
+        assertEquals(120, loop.invoke(5));
+    }
+
     @DataProvider
     static Object[][] negativeTestData() {
         MethodHandle i0 = MethodHandles.constant(int.class, 0);
@@ -153,7 +164,8 @@
         MethodHandle id = MethodHandles.dropArguments(i0, 0, int.class, double.class);
         MethodHandle i3 = MethodHandles.dropArguments(i0, 0, int.class, int.class, int.class);
         List<MethodHandle> inits = Arrays.asList(ii, id, i3);
-        List<Class<?>> ints = Arrays.asList(int.class, int.class, int.class);
+        List<Class<?>> ints3 = Arrays.asList(int.class, int.class, int.class);
+        List<Class<?>> ints4 = Arrays.asList(int.class, int.class, int.class, int.class);
         List<MethodHandle> finis = Arrays.asList(Fac.MH_fin, Fac.MH_inc, Counted.MH_step);
         List<MethodHandle> preds1 = Arrays.asList(null, null, null);
         List<MethodHandle> preds2 = Arrays.asList(null, Fac.MH_fin, null);
@@ -174,7 +186,7 @@
                         "clause 0: init and step return types must match: int != void"},
                 {new MethodHandle[][]{{ii}, {id}, {i3}},
                         "found non-effectively identical init parameter type lists: " + inits +
-                                " (common suffix: " + ints + ")"},
+                                " (common suffix: " + ints3 + ")"},
                 {new MethodHandle[][]{{null, Fac.MH_inc, null, Fac.MH_fin}, {null, Fac.MH_inc, null, Fac.MH_inc},
                         {null, Counted.MH_start, null, Counted.MH_step}},
                         "found non-identical finalizer return types: " + finis + " (return type: int)"},
@@ -185,11 +197,11 @@
                 {new MethodHandle[][]{{Fac.MH_zero, Fac.MH_inc}, {Fac.MH_one, eek, Fac.MH_pred, Fac.MH_fin},
                         {null, Fac.MH_dot}},
                         "found non-effectively identical parameter type lists:\nstep: " + nesteps +
-                                "\npred: " + nepreds + "\nfini: " + nefinis + " (common parameter sequence: " + ints + ")"},
+                                "\npred: " + nepreds + "\nfini: " + nefinis + " (common parameter sequence: " + ints3 + ")"},
                 {new MethodHandle[][]{{null, LoopWithVirtuals.MH_inc},
                         {LoopWithVirtuals.MH_one, LoopWithVirtuals.MH_mult, LoopWithVirtuals.MH_pred, LoopWithVirtuals.MH_fin}},
                         "found non-effectively identical parameter type lists:\nstep: " + lvsteps +
-                                "\npred: " + lvpreds + "\nfini: " + lvfinis + " (common parameter sequence: " + ints + ")"}
+                                "\npred: " + lvpreds + "\nfini: " + lvfinis + " (common parameter sequence: " + ints4 + ")"}
         };
     }
 
@@ -207,7 +219,7 @@
     public static void testLoopNegative(MethodHandle[][] clauses, String expectedMessage) throws Throwable {
         boolean caught = false;
         try {
-            MH_loop.invokeWithArguments(clauses);
+            MH_loop.invokeWithArguments((Object[]) clauses);
         } catch (IllegalArgumentException iae) {
             assertEquals(expectedMessage, iae.getMessage());
             caught = true;
@@ -215,12 +227,100 @@
         assertTrue(caught);
     }
 
-    @Test
-    public static void testWhileLoop() throws Throwable {
+    @Test(dataProvider = "whileLoopTestData")
+    public static void testWhileLoop(MethodHandle MH_zero,
+                                     MethodHandle MH_pred,
+                                     MethodHandle MH_step,
+                                     String messageOrNull) throws Throwable {
         // int i = 0; while (i < limit) { ++i; } return i; => limit
-        MethodHandle loop = MethodHandles.whileLoop(While.MH_zero, While.MH_pred, While.MH_step);
-        assertEquals(While.MT_while, loop.type());
-        assertEquals(23, loop.invoke(23));
+        try {
+            MethodHandle loop = MethodHandles.whileLoop(MH_zero, MH_pred, MH_step);
+            assert messageOrNull == null;
+            if (MH_step.type().equals(While.MH_step.type()))
+                assertEquals(While.MT_while, loop.type());
+            assertEquals(MH_step.type().dropParameterTypes(0, 1), loop.type());
+            while (loop.type().parameterCount() > 1)  loop = snip(loop);
+            assertEquals(23, loop.invoke(23));
+        } catch (IllegalArgumentException iae) {
+            assert messageOrNull != null;
+            assertEqualsFIXME(messageOrNull, iae.getMessage());
+        }
+    }
+
+    static void assertEqualsFIXME(String expect, String actual) {
+        if (!expect.equals(actual)) {
+            // just issue a warning
+            System.out.println("*** "+actual+"\n != "+expect);
+        }
+    }
+
+    @DataProvider
+    static Object[][] whileLoopTestData() {
+        MethodHandle
+            zeroI = While.MH_zero,
+            zeroX = snip(zeroI),
+            zeroIB = slap(zeroI, byte.class),
+            predII = While.MH_pred,
+            predIX = snip(predII),
+            predIIB = slap(predII, byte.class),
+            stepII = While.MH_step,
+            stepIX = snip(stepII),
+            stepIIB = slap(stepII, byte.class)
+            ;
+        return new Object[][] {
+            // normal while loop clauses, perhaps with effectively-identical reductions
+            {zeroI, predII, stepII, null},
+            {zeroX, predII, stepII, null},
+            {null, predII, stepII, null},
+            // expanded while loop clauses
+            {zeroIB, predIIB, stepIIB, null},
+            {zeroI, predIIB, stepIIB, null},
+            {null, predIIB, stepIIB, null},
+            {zeroIB, predII, stepIIB, null},
+            {zeroX, predII, stepIIB, null},
+            {null, predII, stepIIB, null},
+            // short step clauses cause errors
+            {zeroI, predII, stepIX, "loop predicate must match: (int,int)boolean != (int)boolean"},
+            {zeroIB, predIX, stepIX, "loop initializer must match: (int,byte)int != ()int"},
+            // bad body type
+            {zeroI, predII, tweak(stepII, -1, char.class), "body function must match: (int,int)char != (char,int,int)char"},
+            {zeroI, predII, tweak(stepII,  0, char.class), "body function must match: (char,int)int != (int,char,int)int"},
+            // bad pred type
+            {zeroI, tweak(predII, -1, char.class), stepII, "loop predicate must match: (int,int)char != (int,int)boolean"},
+            {zeroI, tweak(predII,  0, char.class), stepII, "loop predicate must match: (char,int)boolean != (int,int)boolean"},
+            // bad init type
+            {tweak(zeroI, -1, char.class), predII, stepII, "loop initializer must match: (int)char != (int)int"},
+            {tweak(zeroI,  0, char.class), predII, stepII, "loop initializer must match: (char)int != (int)int"},
+        };
+    }
+
+    // tweak the type of an MH
+    static MethodHandle tweak(MethodHandle mh, int argPos, Class<?> type) {
+        MethodType mt = mh.type();
+        if (argPos == -1)
+            mt = mt.changeReturnType(type);
+        else
+            mt = mt.changeParameterType(argPos, type);
+        return MethodHandles.explicitCastArguments(mh, mt);
+    }
+    // snip off an MH argument, hard-wiring to zero
+    static MethodHandle snip(MethodHandle mh, int argPos) {
+        if (argPos < 0)  return null;  // special case for optional args
+        Class<?> argType = mh.type().parameterType(argPos);
+        Object zero;
+        try {
+            zero = MethodHandles.zero(argType).invoke();
+        } catch (Throwable ex) {
+            throw new AssertionError(ex);
+        }
+        return MethodHandles.insertArguments(mh, argPos, zero);
+    }
+    static MethodHandle snip(MethodHandle mh) {
+        return snip(mh, mh.type().parameterCount()-1);
+    }
+    // slap on an extra type on the end of the MH
+    static MethodHandle slap(MethodHandle mh, Class<?> addType) {
+        return MethodHandles.dropArguments(mh, mh.type().parameterCount(), addType);
     }
 
     @Test
@@ -231,22 +331,42 @@
         assertEquals("a", loop.invoke());
     }
 
-    @Test
-    public static void testDoWhileLoop() throws Throwable {
+    @Test(dataProvider = "whileLoopTestData")
+    public static void testDoWhileLoop(MethodHandle MH_zero,
+                                       MethodHandle MH_pred,
+                                       MethodHandle MH_step,
+                                       String messageOrNull) throws Throwable {
         // int i = 0; do { ++i; } while (i < limit); return i; => limit
-        MethodHandle loop = MethodHandles.doWhileLoop(While.MH_zero, While.MH_step, While.MH_pred);
-        assertEquals(While.MT_while, loop.type());
-        assertEquals(23, loop.invoke(23));
+        try {
+            MethodHandle loop = MethodHandles.doWhileLoop(MH_zero, MH_step, MH_pred);
+            assert messageOrNull == null;
+            if (MH_step.type().equals(While.MH_step.type()))
+                assertEquals(While.MT_while, loop.type());
+            assertEquals(MH_step.type().dropParameterTypes(0, 1), loop.type());
+            while (loop.type().parameterCount() > 1)  loop = snip(loop);
+            assertEquals(23, loop.invoke(23));
+        } catch (IllegalArgumentException iae) {
+            assert messageOrNull != null;
+            if (!messageOrNull.equals(iae.getMessage())) {
+                // just issue a warning
+                System.out.println("*** "+messageOrNull+"\n != "+iae.getMessage());
+            }
+        }
     }
 
     @Test
-    public static void testDoWhileNullInit() throws Throwable {
-        While w = new While();
-        int v = 5;
-        MethodHandle loop = MethodHandles.doWhileLoop(null, While.MH_voidBody.bindTo(w), While.MH_voidPred.bindTo(w));
-        assertEquals(While.MT_void, loop.type());
-        loop.invoke(v);
-        assertEquals(v, w.i);
+    public static void testDoWhileBadInit() throws Throwable {
+        boolean caught = false;
+        try {
+            While w = new While();
+            MethodHandle loop = MethodHandles.doWhileLoop(MethodHandles.empty(methodType(char.class)),
+                                                          While.MH_voidBody.bindTo(w),
+                                                          While.MH_voidPred.bindTo(w));
+        } catch (IllegalArgumentException iae) {
+            assertEquals("loop initializer must match: ()char != (int)void", iae.getMessage());
+            caught = true;
+        }
+        assertTrue(caught);
     }
 
     @Test
@@ -260,13 +380,18 @@
     }
 
     @Test
-    public static void testWhileNullInit() throws Throwable {
-        While w = new While();
-        int v = 5;
-        MethodHandle loop = MethodHandles.whileLoop(null, While.MH_voidPred.bindTo(w), While.MH_voidBody.bindTo(w));
-        assertEquals(While.MT_void, loop.type());
-        loop.invoke(v);
-        assertEquals(v, w.i);
+    public static void testWhileBadInit() throws Throwable {
+        boolean caught = false;
+        try {
+            While w = new While();
+            MethodHandle loop = MethodHandles.whileLoop(MethodHandles.empty(methodType(void.class, char.class)),
+                                                        While.MH_voidPred.bindTo(w),
+                                                        While.MH_voidBody.bindTo(w));
+        } catch (IllegalArgumentException iae) {
+            assertEquals("loop initializer must match: (char)void != (int)void", iae.getMessage());
+            caught = true;
+        }
+        assertTrue(caught);
     }
 
     @Test
@@ -291,10 +416,26 @@
         assertEquals(v, w.i);
     }
 
+    @DataProvider
+    static Object[][] nullArgs() {
+        MethodHandle c = MethodHandles.constant(int.class, 1);
+        return new Object[][]{{null, c}, {c, null}};
+    }
+
+    @Test(dataProvider = "nullArgs", expectedExceptions = NullPointerException.class)
+    public static void testWhileNullArgs(MethodHandle pred, MethodHandle body) {
+        MethodHandles.whileLoop(null, pred, body);
+    }
+
+    @Test(dataProvider = "nullArgs", expectedExceptions = NullPointerException.class)
+    public static void testDoWhileNullArgs(MethodHandle body, MethodHandle pred) {
+        MethodHandles.whileLoop(null, body, pred);
+    }
+
     @Test
     public static void testCountedLoop() throws Throwable {
         // String s = "Lambdaman!"; for (int i = 0; i < 13; ++i) { s = "na " + s; } return s; => a variation on a well known theme
-        MethodHandle fit13 = MethodHandles.constant(int.class, 13);
+        MethodHandle fit13 = MethodHandles.dropArguments(MethodHandles.constant(int.class, 13), 0, String.class);
         MethodHandle loop = MethodHandles.countedLoop(fit13, Counted.MH_start, Counted.MH_step);
         assertEquals(Counted.MT_counted, loop.type());
         assertEquals("na na na na na na na na na na na na na Lambdaman!", loop.invoke("Lambdaman!"));
@@ -303,9 +444,25 @@
     @Test
     public static void testCountedLoopVoidInit() throws Throwable {
         MethodHandle fit5 = MethodHandles.constant(int.class, 5);
-        MethodHandle loop = MethodHandles.countedLoop(fit5, MethodHandles.zero(void.class), Counted.MH_printHello);
-        assertEquals(Counted.MT_countedPrinting, loop.type());
-        loop.invoke();
+        for (int i = 0; i < 8; i++) {
+            MethodHandle zero = MethodHandles.zero(void.class);
+            MethodHandle init = fit5;
+            MethodHandle body = Counted.MH_printHello;
+            boolean useNull = (i & 1) != 0, addInitArg = (i & 2) != 0, addBodyArg = (i & 4) != 0;
+            if (useNull)    zero = null;
+            if (addInitArg) init = MethodHandles.dropArguments(init, 0, int.class);
+            if (addBodyArg) body = MethodHandles.dropArguments(body, 1, int.class);
+            System.out.println("testCountedLoopVoidInit i="+i+" : "+Arrays.asList(init, zero, body));
+            MethodHandle loop = MethodHandles.countedLoop(init, zero, body);
+            MethodType expectedType = Counted.MT_countedPrinting;
+            if (addInitArg || addBodyArg)
+                expectedType = expectedType.insertParameterTypes(0, int.class);
+            assertEquals(expectedType, loop.type());
+            if (addInitArg || addBodyArg)
+                loop.invoke(99);
+            else
+                loop.invoke();
+        }
     }
 
     @Test
@@ -327,7 +484,7 @@
         loop.invoke();
     }
 
-    @Test
+    @Test(expectedExceptions = NullPointerException.class)
     public static void testCountedLoopNullBody() throws Throwable {
         MethodHandle h5 = MethodHandles.constant(int.class, 5);
         MethodHandle h13 = MethodHandles.constant(int.class, 13);
@@ -336,14 +493,14 @@
         assertEquals(13, loop.invoke());
     }
 
-    @Test
+    @Test(expectedExceptions = NullPointerException.class)
     public static void testCountedLoopNullIterations() throws Throwable {
         MethodHandle loop = MethodHandles.countedLoop(null, null, null);
         assertEquals(methodType(void.class), loop.type());
         loop.invoke();
     }
 
-    @Test
+    @Test(expectedExceptions = NullPointerException.class)
     public static void testCountedLoopNullInitAndBody() throws Throwable {
         MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5), null, null);
         assertEquals(methodType(void.class), loop.type());
@@ -352,45 +509,63 @@
 
     @DataProvider
     static Object[][] countedLoopBodyParameters() {
+        Class<?> V = String.class, I = int.class, A = List.class;
+        // return types are of these forms:
+        //    {count = int(A...), init = V(A...), body = V(V, I, A...)}
         return new Object[][] {
-                {methodType(String.class), methodType(String.class, int.class)},
-                {methodType(String.class, List.class), methodType(String.class, int.class)},
-                {methodType(String.class, List.class), methodType(String.class, int.class, String.class)}
+            // body leads determining A...
+            {methodType(I), methodType(V), methodType(V, V, I)},
+            {methodType(I), methodType(V), methodType(V, V, I, A)},
+            {methodType(I,A), methodType(V), methodType(V, V, I, A)},
+            {methodType(I), methodType(V,A), methodType(V, V, I, A)},
+            // body leads, with void V
+            {methodType(I), methodType(void.class), methodType(void.class, I)},
+            {methodType(I), methodType(void.class), methodType(void.class, I, A)},
+            {methodType(I,A), methodType(void.class), methodType(void.class, I, A)},
+            {methodType(I), methodType(void.class,A), methodType(void.class, I, A)},
+            // count leads determining A..., but only if body drops all A...
+            {methodType(I,A), methodType(V), methodType(V, V, I)},
+            {methodType(I,A), methodType(V,A), methodType(V, V, I)},
+            // count leads, with void V
+            {methodType(I,A), methodType(void.class), methodType(void.class, I)},
+            {methodType(I,A), methodType(void.class,A), methodType(void.class, I)},
         };
     }
 
     @Test(dataProvider = "countedLoopBodyParameters")
-    public static void testCountedLoopBodyParameters(MethodType initType, MethodType bodyType) throws Throwable {
-        MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5),
-                MethodHandles.empty(initType), MethodHandles.empty(bodyType));
-        assertEquals(initType, loop.type());
+    public static void testCountedLoopBodyParameters(MethodType countType, MethodType initType, MethodType bodyType) throws Throwable {
+        MethodHandle loop = MethodHandles.countedLoop(
+                MethodHandles.empty(countType),
+                initType == null ? null : MethodHandles.empty(initType),
+                MethodHandles.empty(bodyType));
+        // The rule:  If body takes the minimum number of parameters, then take what countType offers.
+        // The initType has to just roll with whatever the other two agree on.
+        int innerParams = (bodyType.returnType() == void.class ? 1 : 2);
+        MethodType expectType = bodyType.dropParameterTypes(0, innerParams);
+        if (expectType.parameterCount() == 0)
+            expectType = expectType.insertParameterTypes(0, countType.parameterList());
+        assertEquals(expectType, loop.type());
     }
 
-    @DataProvider
-    static Object[][] countedLoopTypes() {
-        return new Object[][]{{void.class}, {int.class}, {Object.class}, {String.class}, {List.class}};
-    }
-
-    @Test(dataProvider = "countedLoopTypes")
-    public static void testCountedLoopBodyParametersNullInit(Class<?> t) throws Throwable {
-        MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5), null,
-                MethodHandles.empty(methodType(t, int.class)));
-        assertEquals(methodType(t), loop.type());
-        loop.invoke();
+    @Test(dataProvider = "countedLoopBodyParameters")
+    public static void testCountedLoopBodyParametersNullInit(MethodType countType, MethodType initType, MethodType bodyType) throws Throwable {
+        testCountedLoopBodyParameters(countType, null, bodyType);
     }
 
     @Test
-    public static void testCountedLoopStateDefinedByBody() throws Throwable {
-        MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5), null, Counted.MH_stateBody);
+    public static void testCountedLoopStateInitializedToNull() throws Throwable {
+        MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5),
+                MethodHandles.empty(methodType(String.class)), Counted.MH_stateBody);
         assertEquals(Counted.MT_bodyDeterminesState, loop.type());
         assertEquals("sssssnull01234", loop.invoke());
     }
 
     @Test
     public static void testCountedLoopArgsDefinedByIterations() throws Throwable {
-        MethodHandle loop = MethodHandles.countedLoop(
-                MethodHandles.dropArguments(MethodHandles.constant(int.class, 3), 0, String.class),
-                null, Counted.MH_append);
+        MethodHandle iterations =
+                MethodHandles.dropArguments(MethodHandles.constant(int.class, 3), 0, String.class);
+        MethodHandle loop = MethodHandles.countedLoop(iterations,
+                MethodHandles.empty(iterations.type().changeReturnType(String.class)), Counted.MH_append);
         assertEquals(Counted.MT_iterationsDefineArgs, loop.type());
         assertEquals("hello012", loop.invoke("hello"));
     }
@@ -420,7 +595,8 @@
     @Test
     public static void testCountedLoopEmpty() throws Throwable {
         // for (int i = 0; i < 5; ++i) { /* empty */ }
-        MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5), null, null);
+        MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5), null,
+                MethodHandles.empty(methodType(void.class, int.class)));
         assertEquals(methodType(void.class), loop.type());
         loop.invoke();
     }
@@ -429,11 +605,45 @@
     public static void testCountedRangeLoopEmpty() throws Throwable {
         // for (int i = -5; i < 5; ++i) { /* empty */ }
         MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, -5),
-                MethodHandles.constant(int.class, 5), null, null);
+                MethodHandles.constant(int.class, 5), null, MethodHandles.empty(methodType(void.class, int.class)));
         assertEquals(methodType(void.class), loop.type());
         loop.invoke();
     }
 
+    @DataProvider
+    static Object[][] countedLoopNegativeData() {
+        MethodHandle dummy = MethodHandles.zero(void.class);
+        MethodHandle one = MethodHandles.constant(int.class, 1);
+        MethodHandle oneString = MethodHandles.dropArguments(one, 0, String.class);
+        MethodHandle oneDouble = MethodHandles.dropArguments(one, 0, double.class);
+        return new Object[][]{
+                {dummy, one, dummy, dummy, String.format("start/end must return int %s, %s", dummy, one)},
+                {one, dummy, dummy, dummy, String.format("start/end must return int %s, %s", one, dummy)},
+                {oneString, oneDouble, dummy, dummy,
+                        String.format("start and end parameter types must match: %s != %s", oneString.type(),
+                                oneDouble.type())},
+                {oneString, oneString, dummy, dummy,
+                        String.format("start/end and init parameter types must match: %s != %s", oneString.type(),
+                                dummy.type())},
+                {one, one, null, dummy, String.format("actual and expected body signatures must match: %s != %s",
+                        dummy.type(), dummy.type().appendParameterTypes(int.class))}
+        };
+    }
+
+    @Test(dataProvider = "countedLoopNegativeData")
+    public static void testCountedLoopNegative(MethodHandle start, MethodHandle end, MethodHandle init,
+                                               MethodHandle body, String msg) {
+        if (true)  return;  //%%%FIXME%%%%
+        boolean caught = false;
+        try {
+            MethodHandles.countedLoop(start, end, init, body);
+        } catch (IllegalArgumentException iae) {
+            assertEquals(msg, iae.getMessage());
+            caught = true;
+        }
+        assertTrue(caught);
+    }
+
     @Test
     public static void testIterateSum() throws Throwable {
         // Integer[] a = new Integer[]{1,2,3,4,5,6}; int sum = 0; for (int e : a) { sum += e; } return sum; => 21
@@ -442,50 +652,106 @@
         assertEquals(21, loop.invoke(new Integer[]{1, 2, 3, 4, 5, 6}));
     }
 
-    @Test
-    public static void testIterateReverse() throws Throwable {
-        MethodHandle loop = MethodHandles.iteratedLoop(null, Iterate.MH_reverseInit, Iterate.MH_reverseStep);
-        assertEquals(Iterate.MT_reverse, loop.type());
-        List<String> list = Arrays.asList("a", "b", "c", "d", "e");
-        List<String> reversedList = Arrays.asList("e", "d", "c", "b", "a");
-        assertEquals(reversedList, (List<String>) loop.invoke(list));
+    @DataProvider
+    static Object[][] iteratorInits() {
+        return new Object[][]{{Iterate.MH_iteratorFromList}, {Iterate.MH_iteratorFromIterable}, {null}};
+    }
+
+    @Test(dataProvider = "iteratorInits")
+    public static void testIterateReverse(MethodHandle iterator) throws Throwable {
+        // this test uses List as its loop state type; don't try to change that
+        if (iterator != null)
+            iterator = iterator.asType(iterator.type().changeParameterType(0, List.class));
+        for (int i = 0; i < 4; i++) {
+            MethodHandle init = Iterate.MH_reverseInit, body = Iterate.MH_reverseStep;
+            boolean snipInit = (i & 1) != 0, snipBody = (i & 2) != 0;
+            if (snipInit)  init = snip(init);
+            if (snipBody)  body = snip(body);
+            if (!snipInit && snipBody && iterator == null) {
+                // Body does not determine (A...), so the default guy just picks Iterable.
+                // If body insisted on (List), the default guy would adjust himself.
+                // Init has no authority to change the (A...), so must patch init.
+                // All according to plan!
+                init = slap(snip(init), Iterable.class);
+            }
+            System.out.println("testIterateReverse i="+i+" : "+Arrays.asList(iterator, init, body));
+            MethodHandle loop = MethodHandles.iteratedLoop(iterator, init, body);
+            MethodType expectedType = Iterate.MT_reverse;
+            if (iterator == null && i >= 2)
+                expectedType = expectedType.changeParameterType(0, Iterable.class);
+            assertEquals(expectedType, loop.type());
+            List<String> list = Arrays.asList("a", "b", "c", "d", "e");
+            List<String> reversedList = Arrays.asList("e", "d", "c", "b", "a");
+            assertEquals(reversedList, (List<String>) loop.invoke(list));
+        }
     }
 
-    @Test
-    public static void testIterateLength() throws Throwable {
-        MethodHandle loop = MethodHandles.iteratedLoop(null, Iterate.MH_lengthInit, Iterate.MH_lengthStep);
-        assertEquals(Iterate.MT_length, loop.type());
-        List<Double> list = Arrays.asList(23.0, 148.0, 42.0);
-        assertEquals(list.size(), (int) loop.invoke(list));
+    @Test(dataProvider = "iteratorInits")
+    public static void testIterateLength(MethodHandle iterator) throws Throwable {
+        MethodHandle body = Iterate.MH_lengthStep;
+        MethodHandle init = Iterate.MH_lengthInit;
+        MethodType expectedType = Iterate.MT_length;
+        int barity = body.type().parameterCount();
+        Class<?> iteratorSource = iterator == null ? null : iterator.type().parameterType(0);
+        if (iterator != null && iteratorSource != body.type().parameterType(barity-1)) {
+            // adjust body to accept the other type
+            body = body.asType(body.type().changeParameterType(barity-1, iteratorSource));
+            init = init.asType(init.type().changeParameterType(0, iteratorSource));
+            expectedType = expectedType.changeParameterType(0, iteratorSource);
+        }
+        for (;; init = snip(init)) {
+            System.out.println("testIterateLength.init = "+init);
+            MethodHandle loop = MethodHandles.iteratedLoop(iterator, init, body);
+            assertEquals(expectedType, loop.type());
+            List<Double> list = Arrays.asList(23.0, 148.0, 42.0);
+            assertEquals(list.size(), (int) loop.invoke(list));
+            if (init == null)  break;
+        }
     }
 
-    @Test
-    public static void testIterateMap() throws Throwable {
-        MethodHandle loop = MethodHandles.iteratedLoop(null, Iterate.MH_mapInit, Iterate.MH_mapStep);
-        assertEquals(Iterate.MT_map, loop.type());
-        List<String> list = Arrays.asList("Hello", "world", "!");
-        List<String> upList = Arrays.asList("HELLO", "WORLD", "!");
-        assertEquals(upList, (List<String>) loop.invoke(list));
+    @Test(dataProvider = "iteratorInits")
+    public static void testIterateMap(MethodHandle iterator) throws Throwable {
+        MethodHandle body = Iterate.MH_mapStep;
+        MethodHandle init = Iterate.MH_mapInit;
+        MethodType expectedType = Iterate.MT_map;
+        int barity = body.type().parameterCount();
+        Class<?> iteratorSource = iterator == null ? null : iterator.type().parameterType(0);
+        if (iterator != null && iteratorSource != body.type().parameterType(barity-1)) {
+            // adjust body to accept the other type
+            body = body.asType(body.type().changeParameterType(barity-1, iteratorSource));
+            init = init.asType(init.type().changeParameterType(0, iteratorSource));
+            expectedType = expectedType.changeParameterType(0, iteratorSource);
+        }
+        for (; init != null; init = snip(init)) {
+            System.out.println("testIterateMap.init = "+init);
+            MethodHandle loop = MethodHandles.iteratedLoop(iterator, init, body);
+            assertEquals(expectedType, loop.type());
+            List<String> list = Arrays.asList("Hello", "world", "!");
+            List<String> upList = Arrays.asList("HELLO", "WORLD", "!");
+            assertEquals(upList, (List<String>) loop.invoke(list));
+        }
     }
 
-    @Test
-    public static void testIteratePrint() throws Throwable {
-        MethodHandle loop = MethodHandles.iteratedLoop(null, null, Iterate.MH_printStep);
-        assertEquals(Iterate.MT_print, loop.type());
+    @Test(dataProvider = "iteratorInits")
+    public static void testIteratePrint(MethodHandle iterator) throws Throwable {
+        MethodHandle body = Iterate.MH_printStep;
+        MethodType expectedType = Iterate.MT_print;
+        int barity = body.type().parameterCount();
+        Class<?> iteratorSource = iterator == null ? null : iterator.type().parameterType(0);
+        if (iterator != null && iteratorSource != body.type().parameterType(barity-1)) {
+            // adjust body to accept the other type
+            body = body.asType(body.type().changeParameterType(barity-1, iteratorSource));
+            expectedType = expectedType.changeParameterType(0, iteratorSource);
+        }
+        MethodHandle loop = MethodHandles.iteratedLoop(iterator, null, body);
+        assertEquals(expectedType, loop.type());
         loop.invoke(Arrays.asList("hello", "world"));
     }
 
-    @Test
+    @Test(expectedExceptions = NullPointerException.class)
     public static void testIterateNullBody() {
-        boolean caught = false;
-        try {
-            MethodHandles.iteratedLoop(MethodHandles.empty(methodType(Iterator.class, int.class)),
-                    MethodHandles.identity(int.class), null);
-        } catch (IllegalArgumentException iae) {
-            assertEquals("iterated loop body must not be null", iae.getMessage());
-            caught = true;
-        }
-        assertTrue(caught);
+        MethodHandles.iteratedLoop(MethodHandles.empty(methodType(Iterator.class, int.class)),
+                MethodHandles.identity(int.class), null);
     }
 
     @DataProvider
@@ -500,15 +766,18 @@
         try {
             MethodHandles.iteratedLoop(MethodHandles.empty(v), null, MethodHandles.empty(v));
         } catch(IllegalArgumentException iae) {
-            assertEquals("iteratedLoop first argument must have Iterator return type", iae.getMessage());
+            assertEqualsFIXME("iteratedLoop first argument must have Iterator return type", iae.getMessage());
             caught = true;
         }
         assertTrue(caught);
     }
 
-    @Test
-    public static void testIterateVoidInit() throws Throwable {
-        MethodHandle loop = MethodHandles.iteratedLoop(null, Iterate.MH_voidInit, Iterate.MH_printStep);
+    @Test(dataProvider = "iteratorInits")
+    public static void testIterateVoidInit(MethodHandle iterator) throws Throwable {
+        // this test uses List as its loop state type; don't try to change that
+        if (iterator != null)
+            iterator = iterator.asType(iterator.type().changeParameterType(0, List.class));
+        MethodHandle loop = MethodHandles.iteratedLoop(iterator, Iterate.MH_voidInit, Iterate.MH_printStep);
         assertEquals(Iterate.MT_print, loop.type());
         loop.invoke(Arrays.asList("hello", "world"));
     }
@@ -516,60 +785,79 @@
     @DataProvider
     static Object[][] iterateParameters() {
         MethodType i = methodType(int.class);
-        MethodType sil_i = methodType(int.class, String.class, int.class, List.class);
+        MethodType sil_v = methodType(void.class, String.class, int.class, List.class);
+        MethodType isl_i = methodType(int.class, int.class, String.class, List.class);
+        MethodType isli_i = methodType(int.class, int.class, String.class, List.class, int.class);
         MethodType sl_v = methodType(void.class, String.class, List.class);
+        MethodType sli_v = methodType(void.class, String.class, List.class, int.class);
         MethodType l_it = methodType(Iterator.class, List.class);
+        MethodType li_i = methodType(int.class, List.class, int.class);
         MethodType li_it = methodType(Iterator.class, List.class, int.class);
+        MethodType il_it = methodType(Iterator.class, int.class, List.class);
         MethodType l_i = methodType(int.class, List.class);
-        MethodType _it = methodType(Iterator.class);
-        MethodType si_i = methodType(int.class, String.class, int.class);
-        MethodType s_i = methodType(int.class, String.class);
         return new Object[][]{
-                {null, null, sl_v},
-                {null, i, sil_i},
-                {null, l_i, sil_i},
-                {l_it, null, sl_v},
-                {l_it, i, sil_i},
-                {li_it, l_i, sil_i},
-                {l_it, null, sil_i},
-                {li_it, null, sl_v},
-                {_it, l_i, si_i},
-                {_it, l_i, s_i}
+                {l_it, null, sl_v, ""},
+                {l_it, l_i, isl_i, ""},
+                {l_it, null, sl_v, ""},
+                {li_it, li_i, isli_i, ""},
+                {il_it, null, sil_v, "inferred first loop argument must inherit from Iterable: int"},
+                {li_it, null, sli_v, ""},
+                {sl_v, null, sl_v, "iteratedLoop first argument must have Iterator return type"},
+                {li_it, l_it, sl_v,
+                        String.format("iterator and init parameter lists must match: %s != %s", li_it, l_it)},
+                {li_it, li_i, isl_i,
+                        String.format("body types (regard parameter types after index 0, and result type) must match: %s != %s",
+                                isl_i, isl_i.dropParameterTypes(0, 1).appendParameterTypes(int.class))}
         };
     }
 
     @Test(dataProvider = "iterateParameters")
-    public static void testIterateParameters(MethodType it, MethodType in, MethodType bo) throws Throwable {
+    public static void testIterateParameters(MethodType it, MethodType in, MethodType bo, String msg) {
+        boolean negative = !msg.isEmpty();
         MethodHandle iterator = it == null ? null : MethodHandles.empty(it);
         MethodHandle init = in == null ? null : MethodHandles.empty(in);
-        MethodHandle loop = MethodHandles.iteratedLoop(iterator, init, MethodHandles.empty(bo));
-        MethodType lt = loop.type();
-        if (it == null && in == null) {
-            assertEquals(bo.dropParameterTypes(0, 1), lt);
-        } else if (it == null) {
-            if (in.parameterCount() == 0) {
-                assertEquals(bo.dropParameterTypes(0, in.returnType() == void.class ? 1 : 2), lt);
-            } else {
-                assertEquals(methodType(bo.returnType(), in.parameterArray()), lt);
+        boolean caught = false;
+        MethodHandle loop = null;
+        try {
+            loop = MethodHandles.iteratedLoop(iterator, init, MethodHandles.empty(bo));
+        } catch (Throwable t) {
+            if (!negative) {
+                throw t;
             }
-        } else if (in == null) {
-            assertEquals(methodType(bo.returnType(), it.parameterArray()), lt);
-        } else if (it.parameterCount() > in.parameterCount()) {
-            assertEquals(methodType(bo.returnType(), it.parameterArray()), lt);
-        } else if (it.parameterCount() < in.parameterCount()) {
-            assertEquals(methodType(bo.returnType(), in.parameterArray()), lt);
+            assertEqualsFIXME(msg, t.getMessage());
+            caught = true;
+        }
+        if (negative) {
+            assertTrue(caught);
         } else {
-            // both it, in present; with equal parameter list lengths
-            assertEquals(it.parameterList(), lt.parameterList());
-            assertEquals(in.parameterList(), lt.parameterList());
-            assertEquals(bo.returnType(), lt.returnType());
+            MethodType lt = loop.type();
+            if (it == null && in == null) {
+                assertEquals(bo.dropParameterTypes(0, 1), lt);
+            } else if (it == null) {
+                if (in.parameterCount() == 0) {
+                    assertEquals(bo.dropParameterTypes(0, in.returnType() == void.class ? 1 : 2), lt);
+                } else {
+                    assertEquals(methodType(bo.returnType(), in.parameterArray()), lt);
+                }
+            } else if (in == null) {
+                assertEquals(methodType(bo.returnType(), it.parameterArray()), lt);
+            } else if (it.parameterCount() > in.parameterCount()) {
+                assertEquals(methodType(bo.returnType(), it.parameterArray()), lt);
+            } else if (it.parameterCount() < in.parameterCount()) {
+                assertEquals(methodType(bo.returnType(), in.parameterArray()), lt);
+            } else {
+                // both it, in present; with equal parameter list lengths
+                assertEquals(it.parameterList(), lt.parameterList());
+                assertEquals(in.parameterList(), lt.parameterList());
+                assertEquals(bo.returnType(), lt.returnType());
+            }
         }
     }
 
     @Test
     public static void testIteratorSubclass() throws Throwable {
         MethodHandle loop = MethodHandles.iteratedLoop(MethodHandles.empty(methodType(BogusIterator.class, List.class)),
-                null, MethodHandles.empty(methodType(void.class, String.class)));
+                null, MethodHandles.empty(methodType(void.class, String.class, List.class)));
         assertEquals(methodType(void.class, List.class), loop.type());
     }
 
@@ -892,7 +1180,7 @@
             return arg;
         }
 
-        static String step(int counter, String v, String arg) {
+        static String step(String v, int counter) {
             return "na " + v;
         }
 
@@ -904,15 +1192,15 @@
             System.out.print("hello");
         }
 
-        static int addCounter(int counter, int x) {
+        static int addCounter(int x, int counter) {
             return x + counter;
         }
 
-        static String stateBody(int counter, String s) {
+        static String stateBody(String s, int counter) {
             return "s" + s + counter;
         }
 
-        static String append(int counter, String localState, String loopArg) {
+        static String append(String localState, int counter, String loopArg) {
             if (null == localState) {
                 return loopArg + counter;
             }
@@ -922,12 +1210,12 @@
         static final Class<Counted> COUNTED = Counted.class;
 
         static final MethodType MT_start = methodType(String.class, String.class);
-        static final MethodType MT_step = methodType(String.class, int.class, String.class, String.class);
+        static final MethodType MT_step = methodType(String.class, String.class, int.class);
         static final MethodType MT_stepUpdateArray = methodType(void.class, int.class, int[].class);
         static final MethodType MT_printHello = methodType(void.class, int.class);
         static final MethodType MT_addCounter = methodType(int.class, int.class, int.class);
-        static final MethodType MT_stateBody = methodType(String.class, int.class, String.class);
-        static final MethodType MT_append = methodType(String.class, int.class, String.class, String.class);
+        static final MethodType MT_stateBody = methodType(String.class, String.class, int.class);
+        static final MethodType MT_append = methodType(String.class, String.class, int.class, String.class);
 
         static final MethodHandle MH_13;
         static final MethodHandle MH_m5;
@@ -984,7 +1272,7 @@
             return new ArrayList<>();
         }
 
-        static List<String> reverseStep(String e, List<String> r, List<String> l) {
+        static List<String> reverseStep(List<String> r, String e, List<String> l) {
             r.add(0, e);
             return r;
         }
@@ -993,7 +1281,7 @@
             return 0;
         }
 
-        static int lengthStep(Object o, int len, List<Double> l) {
+        static int lengthStep(int len, Object o, List<Double> l) {
             return len + 1;
         }
 
@@ -1001,7 +1289,7 @@
             return new ArrayList<>();
         }
 
-        static List<String> mapStep(String e, List<String> r, List<String> l) {
+        static List<String> mapStep(List<String> r, String e, List<String> l) {
             r.add(e.toUpperCase());
             return r;
         }
@@ -1010,10 +1298,18 @@
             System.out.print(s);
         }
 
-        static void voidInit() {
+        static void voidInit(List<String> l) {
             // empty
         }
 
+        static ListIterator<?> iteratorFromList(List<?> l) {
+            return l.listIterator();
+        }
+
+        static Iterator<?> iteratorFromIterable(Iterable<?> l) {
+            return l.iterator();
+        }
+
         static final Class<Iterate> ITERATE = Iterate.class;
 
         static final MethodType MT_sumIterator = methodType(Iterator.class, Integer[].class);
@@ -1024,12 +1320,15 @@
         static final MethodType MT_mapInit = methodType(List.class, List.class);
 
         static final MethodType MT_sumStep = methodType(int.class, int.class, int.class, Integer[].class);
-        static final MethodType MT_reverseStep = methodType(List.class, String.class, List.class, List.class);
-        static final MethodType MT_lengthStep = methodType(int.class, Object.class, int.class, List.class);
-        static final MethodType MT_mapStep = methodType(List.class, String.class, List.class, List.class);
+        static final MethodType MT_reverseStep = methodType(List.class, List.class, String.class, List.class);
+        static final MethodType MT_lengthStep = methodType(int.class, int.class, Object.class, List.class);
+        static final MethodType MT_mapStep = methodType(List.class, List.class, String.class, List.class);
         static final MethodType MT_printStep = methodType(void.class, String.class, List.class);
 
-        static final MethodType MT_voidInit = methodType(void.class);
+        static final MethodType MT_voidInit = methodType(void.class, List.class);
+
+        static final MethodType MT_iteratorFromList = methodType(ListIterator.class, List.class);
+        static final MethodType MT_iteratorFromIterable = methodType(Iterator.class, Iterable.class);
 
         static final MethodHandle MH_sumIterator;
         static final MethodHandle MH_sumInit;
@@ -1047,6 +1346,9 @@
 
         static final MethodHandle MH_voidInit;
 
+        static final MethodHandle MH_iteratorFromList;
+        static final MethodHandle MH_iteratorFromIterable;
+
         static final MethodType MT_sum = methodType(int.class, Integer[].class);
         static final MethodType MT_reverse = methodType(List.class, List.class);
         static final MethodType MT_length = methodType(int.class, List.class);
@@ -1066,6 +1368,8 @@
                 MH_mapStep = LOOKUP.findStatic(ITERATE, "mapStep", MT_mapStep);
                 MH_printStep = LOOKUP.findStatic(ITERATE, "printStep", MT_printStep);
                 MH_voidInit = LOOKUP.findStatic(ITERATE, "voidInit", MT_voidInit);
+                MH_iteratorFromList = LOOKUP.findStatic(ITERATE, "iteratorFromList", MT_iteratorFromList);
+                MH_iteratorFromIterable = LOOKUP.findStatic(ITERATE, "iteratorFromIterable", MT_iteratorFromIterable);
             } catch (Exception e) {
                 throw new ExceptionInInitializerError(e);
             }
--- a/jdk/test/java/lang/invoke/MethodHandlesTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/lang/invoke/MethodHandlesTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -632,6 +632,7 @@
     }
 
     public void testFindVirtualClone0() throws Throwable {
+        if (CAN_SKIP_WORKING)  return;
         // test some ad hoc system methods
         testFindVirtual(false, PUBLIC, Object.class, Object.class, "clone");
 
@@ -2798,11 +2799,17 @@
             toClauseMajor(postClauses, inits, steps, usePreds, finis);
             MethodHandle pre = MethodHandles.loop(preClauses);
             MethodHandle post = MethodHandles.loop(postClauses);
+            if (verbosity >= 6) {
+                System.out.println("pre-handle: " + pre);
+            }
             Object[] preResults = (Object[]) pre.invokeWithArguments(args);
             if (verbosity >= 4) {
                 System.out.println("pre-checked: expected " + Arrays.asList(preCheckedResults[i]) + ", actual " +
                         Arrays.asList(preResults));
             }
+            if (verbosity >= 6) {
+                System.out.println("post-handle: " + post);
+            }
             Object[] postResults = (Object[]) post.invokeWithArguments(args);
             if (verbosity >= 4) {
                 System.out.println("post-checked: expected " + Arrays.asList(postCheckedResults[i]) + ", actual " +
--- a/jdk/test/java/net/MulticastSocket/TimeToLive.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/net/MulticastSocket/TimeToLive.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,26 +37,27 @@
     static int[] bad_ttls = { -1, 256 };
 
     public static void main(String[] args) throws Exception {
-        MulticastSocket socket = new MulticastSocket(6789);
-        int ttl = socket.getTimeToLive();
-        System.out.println("default ttl: " + ttl);
-        for (int i = 0; i < new_ttls.length; i++) {
-            socket.setTimeToLive(new_ttls[i]);
-            if (!(new_ttls[i] == socket.getTimeToLive())) {
-                throw new RuntimeException("test failure, set/get differ: " +
-                                           new_ttls[i] + " /  " +
-                                           socket.getTimeToLive());
+        try (MulticastSocket socket = new MulticastSocket()) {
+            int ttl = socket.getTimeToLive();
+            System.out.println("default ttl: " + ttl);
+            for (int i = 0; i < new_ttls.length; i++) {
+                socket.setTimeToLive(new_ttls[i]);
+                if (!(new_ttls[i] == socket.getTimeToLive())) {
+                    throw new RuntimeException("test failure, set/get differ: " +
+                            new_ttls[i] + " /  " +
+                            socket.getTimeToLive());
+                }
             }
-        }
-        for (int j = 0; j < bad_ttls.length; j++) {
-            boolean exception = false;
-            try {
-                socket.setTimeToLive(bad_ttls[j]);
-            } catch (IllegalArgumentException e) {
-                exception = true;
-            }
-            if (!exception) {
-                throw new RuntimeException("bad argument accepted: " + bad_ttls[j]);
+            for (int j = 0; j < bad_ttls.length; j++) {
+                boolean exception = false;
+                try {
+                    socket.setTimeToLive(bad_ttls[j]);
+                } catch (IllegalArgumentException e) {
+                    exception = true;
+                }
+                if (!exception) {
+                    throw new RuntimeException("bad argument accepted: " + bad_ttls[j]);
+                }
             }
         }
     }
--- a/jdk/test/java/net/ServerSocket/ThreadStop.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/net/ServerSocket/ThreadStop.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -68,23 +68,23 @@
         thr.start();
 
         // give server time to block in ServerSocket.accept()
-        Thread.currentThread().sleep(2000);
+        Thread.sleep(2000);
 
         // "stop" the thread
         thr.stop();
 
         // give thread time to stop
-        Thread.currentThread().sleep(2000);
+        Thread.sleep(2000);
 
         // it's platform specific if Thread.stop interrupts the
         // thread - on Linux/Windows most likely that thread is
         // still in accept() so we connect to server which causes
         // it to unblock and do JNI-stuff with a pending exception
 
-        try {
-            Socket s = new Socket("localhost", svr.localPort());
-        } catch (IOException ioe) { }
-
+        try (Socket s = new Socket("localhost", svr.localPort())) {
+        } catch (IOException ioe) {
+        }
+        thr.join();
     }
 
 }
--- a/jdk/test/java/net/Socket/InheritHandle.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/net/Socket/InheritHandle.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
    @author Chris Hegarty
  */
 
+import java.net.BindException;
 import java.net.ServerSocket;
 import java.io.File;
 import java.io.IOException;
@@ -74,6 +75,11 @@
         } catch (IOException ioe) {
             System.out.println("Cannot create process");
             ioe.printStackTrace();
+            try {
+                ss.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
             return;
         }
 
@@ -85,9 +91,18 @@
             System.out.println("Now close the socket and try to create another" +
                                " one listening on the same port");
             ss.close();
-            ss = new ServerSocket(port);
-            System.out.println("Second ServerSocket created successfully");
-            ss.close();
+            int retries = 0;
+            while (retries < 5) {
+                try (ServerSocket s = new ServerSocket(port);) {
+                    System.out.println("Second ServerSocket created successfully");
+                    break;
+                } catch (BindException e) {
+                    System.out.println("BindException \"" + e.getMessage() + "\", retrying...");
+                    Thread.sleep(100L);
+                    retries ++;
+                    continue;
+                }
+            }
 
         } catch (InterruptedException ie) {
         } catch (IOException ioe) {
--- a/jdk/test/java/net/URLClassLoader/definePackage/SplitPackage.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/net/URLClassLoader/definePackage/SplitPackage.java	Fri Sep 30 09:28:18 2016 -0700
@@ -27,6 +27,7 @@
  * @summary Test two URLClassLoader define Package object of the same name
  * @library /lib/testlibrary
  * @build CompilerUtils
+ * @modules jdk.compiler
  * @run testng SplitPackage
  */
 
--- a/jdk/test/java/net/URLPermission/nstest/LookupTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/net/URLPermission/nstest/LookupTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -37,6 +37,7 @@
         String url, boolean throwsSecException, boolean throwsIOException)
     {
         try {
+            ProxySelector.setDefault(null);
             URL u = new URL(url);
             System.err.println ("Connecting to " + u);
             URLConnection urlc = u.openConnection();
@@ -71,7 +72,7 @@
             System.out.print(port);
         } else if (cmd.equals("-runtest")) {
             port = Integer.parseInt(args[1]);
-            String hostsFileName = System.getProperty("test.src", ".") + "/LookupTestHosts";
+            String hostsFileName = System.getProperty("user.dir", ".") + "/LookupTestHosts";
             System.setProperty("jdk.net.hosts.file", hostsFileName);
             addMappingToHostsFile("allowedAndFound.com", "127.0.0.1", hostsFileName, false);
             addMappingToHostsFile("notAllowedButFound.com", "99.99.99.99", hostsFileName, true);
--- a/jdk/test/java/net/URLPermission/nstest/LookupTestHosts	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-127.0.0.1 allowedAndFound.com
-99.99.99.99 notAllowedButFound.com
--- a/jdk/test/java/net/URLPermission/nstest/lookup.sh	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/net/URLPermission/nstest/lookup.sh	Fri Sep 30 09:28:18 2016 -0700
@@ -48,6 +48,7 @@
 grant {
     permission java.net.URLPermission "http://allowedAndFound.com:${port}/-", "*:*";
     permission java.net.URLPermission "http://allowedButNotfound.com:${port}/-", "*:*";
+    permission java.net.NetPermission "setProxySelector";
     permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete";
     permission java.util.PropertyPermission "java.io.tmpdir", "read";
 
--- a/jdk/test/java/net/httpclient/HeadersTest1.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/net/httpclient/HeadersTest1.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,9 +23,11 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 8153142
+ * @modules java.httpclient
+ *          jdk.httpserver
  * @run main/othervm HeadersTest1
  * @summary HeadersTest1
  */
@@ -39,9 +41,11 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.InetSocketAddress;
-import java.net.PasswordAuthentication;
 import java.net.URI;
-import java.net.http.*;
+import java.net.http.HttpClient;
+import java.net.http.HttpHeaders;
+import java.net.http.HttpResponse;
+import java.net.http.HttpRequest;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.List;
--- a/jdk/test/java/net/httpclient/ProxyAuthTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/net/httpclient/ProxyAuthTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -26,6 +26,7 @@
  * @test
  * @bug 8163561
  * @modules java.base/sun.net.www
+ *          java.httpclient
  * @summary Verify that Proxy-Authenticate header is correctly handled
  *
  * @run main/othervm ProxyAuthTest
--- a/jdk/test/java/net/httpclient/whitebox/Driver.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/net/httpclient/whitebox/Driver.java	Fri Sep 30 09:28:18 2016 -0700
@@ -24,5 +24,6 @@
 /*
  * @test
  * @bug 8151299
+ * @modules java.httpclient
  * @run testng java.httpclient/java.net.http.SelectorTest
  */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/security/Signature/ResetAfterException.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8149802
+ * @summary Ensure that Signature objects are reset after verification errored out.
+ */
+import java.util.Arrays;
+import java.security.*;
+
+public class ResetAfterException {
+
+    public static void main(String[] args) throws Exception {
+
+        byte[] data = "data to be signed".getBytes();
+        byte[] shortBuffer = new byte[2];
+
+        Provider[] provs = Security.getProviders();
+        boolean failed = false;
+
+        for (Provider p : provs) {
+            Signature sig;
+            try {
+                sig = Signature.getInstance("SHA256withRSA", p);
+            } catch (NoSuchAlgorithmException nsae) {
+                // no support, skip
+                continue;
+            }
+
+            boolean res = true;
+            System.out.println("Testing Provider: " + p.getName());
+            KeyPairGenerator keyGen = null;
+            try {
+                // It's possible that some provider, e.g. SunMSCAPI,
+                // doesn't work well with keys from other providers
+                // so we use the same provider to generate key first
+                keyGen = KeyPairGenerator.getInstance("RSA", p);
+            } catch (NoSuchAlgorithmException nsae) {
+                keyGen = KeyPairGenerator.getInstance("RSA");
+            }
+            if (keyGen == null) {
+                throw new RuntimeException("Error: No support for RSA KeyPairGenerator");
+            }
+            keyGen.initialize(1024);
+            KeyPair keyPair = keyGen.generateKeyPair();
+
+            sig.initSign(keyPair.getPrivate());
+            sig.update(data);
+            byte[] signature = sig.sign();
+            // First check signing
+            try {
+                sig.update(data);
+                // sign with short output buffer to cause exception
+                int len = sig.sign(shortBuffer, 0, shortBuffer.length);
+                System.out.println("FAIL: Should throw SE with short buffer");
+                res = false;
+            } catch (SignatureException e) {
+                // expected exception; ignore
+                System.out.println("Expected Ex for short output buffer: " + e);
+            }
+            // Signature object should reset after a failed generation
+            sig.update(data);
+            byte[] signature2 = sig.sign();
+            if (!Arrays.equals(signature, signature2)) {
+                System.out.println("FAIL: Generated different signature");
+                res = false;
+            } else {
+                System.out.println("Generated same signature");
+            }
+
+            // Now, check signature verification
+            sig.initVerify(keyPair.getPublic());
+            sig.update(data);
+            try {
+                // first verify with valid signature bytes
+                res = sig.verify(signature);
+            } catch (SignatureException e) {
+                System.out.println("FAIL: Valid signature rejected");
+                e.printStackTrace();
+                res = false;
+            }
+
+            try {
+                sig.update(data);
+                // verify with short signaure to cause exception
+                if (sig.verify(shortBuffer)) {
+                    System.out.println("FAIL: Invalid signature verified");
+                    res = false;
+                } else {
+                    System.out.println("Invalid signature rejected");
+                }
+            } catch (SignatureException e) {
+                // expected exception; ignore
+                System.out.println("Expected Ex for short output buffer: " + e);
+            }
+            // Signature object should reset after an a failed verification
+            sig.update(data);
+            try {
+                // verify with valid signature bytes again
+                res = sig.verify(signature);
+                if (!res) {
+                    System.out.println("FAIL: Valid signature is rejected");
+                } else {
+                    System.out.println("Valid signature is accepted");
+                }
+            } catch (GeneralSecurityException e) {
+                System.out.println("FAIL: Valid signature is rejected");
+                e.printStackTrace();
+                res = false;
+            }
+            failed |= !res;
+        }
+        if (failed) {
+            throw new RuntimeException("One or more test failed");
+        } else {
+            System.out.println("Test Passed");
+        }
+   }
+}
--- a/jdk/test/java/text/Format/NumberFormat/DFSSerialization.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/text/Format/NumberFormat/DFSSerialization.java	Fri Sep 30 09:28:18 2016 -0700
@@ -27,13 +27,21 @@
  * @library /java/text/testlib
  * @build DFSSerialization IntlTest HexDumpReader
  * @run main DFSSerialization
- * @summary Three different tests are done. 1.read from the object created using jdk1.4.2  2.create a valid DecimalFormatSymbols object with current JDK, then read the object 3.Try to create an valid DecimalFormatSymbols object by passing null to set null for the exponent separator symbol. Expect the NullPointerException.
+ * @summary Three different tests are done.
+ *    1. read from the object created using jdk1.4.2
+ *    2. create a valid DecimalFormatSymbols object with current JDK, then read the object
+ *    3. Try to create an valid DecimalFormatSymbols object by passing null to set null
+ *       for the exponent separator symbol. Expect the NullPointerException.
  */
 
-import java.awt.*;
-import java.text.*;
-import java.util.*;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.text.DecimalFormatSymbols;
+import java.util.Locale;
 
 public class DFSSerialization extends IntlTest{
     public static void main(String[] args) throws Exception {
--- a/jdk/test/java/text/Format/NumberFormat/SerializationLoadTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/text/Format/NumberFormat/SerializationLoadTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,10 +31,13 @@
  * @key randomness
  */
 
-import java.awt.*;
-import java.text.*;
-import java.util.*;
-import java.io.*;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.text.NumberFormat;
+import java.util.Random;
 
 public class SerializationLoadTest {
 
--- a/jdk/test/java/util/Collections/EmptyNavigableMap.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/Collections/EmptyNavigableMap.java	Fri Sep 30 09:28:18 2016 -0700
@@ -33,7 +33,6 @@
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
-import java.util.NoSuchElementException;
 import java.util.NavigableMap;
 import java.util.SortedMap;
 import java.util.TreeMap;
@@ -41,10 +40,8 @@
 import org.testng.annotations.DataProvider;
 
 import static org.testng.Assert.fail;
-import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertSame;
 
 public class EmptyNavigableMap {
 
--- a/jdk/test/java/util/Collections/EmptyNavigableSet.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/Collections/EmptyNavigableSet.java	Fri Sep 30 09:28:18 2016 -0700
@@ -41,10 +41,9 @@
 import org.testng.annotations.DataProvider;
 
 import static org.testng.Assert.fail;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
 
 public class EmptyNavigableSet {
 
--- a/jdk/test/java/util/Deque/ChorusLine.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/Deque/ChorusLine.java	Fri Sep 30 09:28:18 2016 -0700
@@ -28,8 +28,14 @@
  * @author Martin Buchholz
  */
 
-import java.util.*;
-import java.util.concurrent.*;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.NoSuchElementException;
+import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.concurrent.LinkedBlockingDeque;
 
 public class ChorusLine {
     private interface Tweaker {
--- a/jdk/test/java/util/PriorityQueue/ForgetMeNot.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/PriorityQueue/ForgetMeNot.java	Fri Sep 30 09:28:18 2016 -0700
@@ -28,7 +28,11 @@
  * @author Martin Buchholz
  */
 
-import java.util.*;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.Queue;
 
 public class ForgetMeNot {
     private static void checkQ(PriorityQueue<Integer> q, Integer...elts) {
--- a/jdk/test/java/util/PriorityQueue/PriorityQueueSort.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/PriorityQueue/PriorityQueueSort.java	Fri Sep 30 09:28:18 2016 -0700
@@ -37,7 +37,13 @@
  * @summary Checks that a priority queue returns elements in sorted order across various operations
  */
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Queue;
+import java.util.PriorityQueue;
 
 public class PriorityQueueSort {
 
--- a/jdk/test/java/util/PriorityQueue/RemoveContains.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/PriorityQueue/RemoveContains.java	Fri Sep 30 09:28:18 2016 -0700
@@ -28,8 +28,17 @@
  * @author  Martin Buchholz
  */
 
-import java.util.*;
-import java.util.concurrent.*;
+import java.util.ArrayDeque;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.PriorityBlockingQueue;
+import java.util.concurrent.LinkedTransferQueue;
 
 public class RemoveContains {
     static volatile int passed = 0, failed = 0;
--- a/jdk/test/java/util/concurrent/Executors/AutoShutdown.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/Executors/AutoShutdown.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,8 +31,6 @@
  */
 
 import static java.util.concurrent.Executors.defaultThreadFactory;
-import static java.util.concurrent.Executors.newFixedThreadPool;
-import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
 import static java.util.concurrent.Executors.newSingleThreadExecutor;
 
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
--- a/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java	Fri Sep 30 09:28:18 2016 -0700
@@ -83,15 +83,18 @@
         tpe.allowCoreThreadTimeOut(true);
         check(tpe.allowsCoreThreadTimeOut());
         equal(countExecutorThreads(), 0);
-        long t0 = System.nanoTime();
-        for (int i = 0; i < threadCount; i++)
-            tpe.submit(new Runnable() { public void run() {}});
-        int count = countExecutorThreads();
-        if (millisElapsedSince(t0) < timeoutMillis)
-            equal(count, threadCount);
+        long startTime = System.nanoTime();
+        for (int i = 0; i < threadCount; i++) {
+            tpe.submit(() -> {});
+            int count = countExecutorThreads();
+            if (millisElapsedSince(startTime) < timeoutMillis)
+                equal(count, i + 1);
+        }
         while (countExecutorThreads() > 0 &&
-               millisElapsedSince(t0) < 10 * 1000);
+               millisElapsedSince(startTime) < LONG_DELAY_MS)
+            Thread.yield();
         equal(countExecutorThreads(), 0);
+        check(millisElapsedSince(startTime) >= timeoutMillis);
         tpe.shutdown();
         check(tpe.allowsCoreThreadTimeOut());
         check(tpe.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
--- a/jdk/test/java/util/concurrent/tck/AtomicIntegerArrayTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/tck/AtomicIntegerArrayTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -303,7 +303,7 @@
 
     class Counter extends CheckedRunnable {
         final AtomicIntegerArray aa;
-        volatile int counts;
+        int decs;
         Counter(AtomicIntegerArray a) { aa = a; }
         public void realRun() {
             for (;;) {
@@ -314,7 +314,7 @@
                     if (v != 0) {
                         done = false;
                         if (aa.compareAndSet(i, v, v - 1))
-                            ++counts;
+                            decs++;
                     }
                 }
                 if (done)
@@ -334,13 +334,11 @@
             aa.set(i, countdown);
         Counter c1 = new Counter(aa);
         Counter c2 = new Counter(aa);
-        Thread t1 = new Thread(c1);
-        Thread t2 = new Thread(c2);
-        t1.start();
-        t2.start();
+        Thread t1 = newStartedThread(c1);
+        Thread t2 = newStartedThread(c2);
         t1.join();
         t2.join();
-        assertEquals(c1.counts+c2.counts, SIZE * countdown);
+        assertEquals(c1.decs + c2.decs, SIZE * countdown);
     }
 
     /**
--- a/jdk/test/java/util/concurrent/tck/AtomicLongArrayTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/tck/AtomicLongArrayTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -302,7 +302,7 @@
 
     class Counter extends CheckedRunnable {
         final AtomicLongArray aa;
-        volatile long counts;
+        int decs;
         Counter(AtomicLongArray a) { aa = a; }
         public void realRun() {
             for (;;) {
@@ -313,7 +313,7 @@
                     if (v != 0) {
                         done = false;
                         if (aa.compareAndSet(i, v, v - 1))
-                            ++counts;
+                            decs++;
                     }
                 }
                 if (done)
@@ -333,13 +333,11 @@
             aa.set(i, countdown);
         Counter c1 = new Counter(aa);
         Counter c2 = new Counter(aa);
-        Thread t1 = new Thread(c1);
-        Thread t2 = new Thread(c2);
-        t1.start();
-        t2.start();
+        Thread t1 = newStartedThread(c1);
+        Thread t2 = newStartedThread(c2);
         t1.join();
         t2.join();
-        assertEquals(c1.counts+c2.counts, SIZE * countdown);
+        assertEquals(c1.decs + c2.decs, SIZE * countdown);
     }
 
     /**
--- a/jdk/test/java/util/concurrent/tck/CompletableFutureTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/tck/CompletableFutureTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -388,7 +388,7 @@
         checkCompletedNormally(f, "test");
     }
 
-    abstract class CheckedAction {
+    abstract static class CheckedAction {
         int invocationCount = 0;
         final ExecutionMode m;
         CheckedAction(ExecutionMode m) { this.m = m; }
@@ -400,7 +400,7 @@
         void assertInvoked() { assertEquals(1, invocationCount); }
     }
 
-    abstract class CheckedIntegerAction extends CheckedAction {
+    abstract static class CheckedIntegerAction extends CheckedAction {
         Integer value;
         CheckedIntegerAction(ExecutionMode m) { super(m); }
         void assertValue(Integer expected) {
@@ -409,7 +409,7 @@
         }
     }
 
-    class IntegerSupplier extends CheckedAction
+    static class IntegerSupplier extends CheckedAction
         implements Supplier<Integer>
     {
         final Integer value;
@@ -428,7 +428,7 @@
         return (x == null) ? null : x + 1;
     }
 
-    class NoopConsumer extends CheckedIntegerAction
+    static class NoopConsumer extends CheckedIntegerAction
         implements Consumer<Integer>
     {
         NoopConsumer(ExecutionMode m) { super(m); }
@@ -438,7 +438,7 @@
         }
     }
 
-    class IncFunction extends CheckedIntegerAction
+    static class IncFunction extends CheckedIntegerAction
         implements Function<Integer,Integer>
     {
         IncFunction(ExecutionMode m) { super(m); }
@@ -456,7 +456,7 @@
             - ((y == null) ? 99 : y.intValue());
     }
 
-    class SubtractAction extends CheckedIntegerAction
+    static class SubtractAction extends CheckedIntegerAction
         implements BiConsumer<Integer, Integer>
     {
         SubtractAction(ExecutionMode m) { super(m); }
@@ -466,7 +466,7 @@
         }
     }
 
-    class SubtractFunction extends CheckedIntegerAction
+    static class SubtractFunction extends CheckedIntegerAction
         implements BiFunction<Integer, Integer, Integer>
     {
         SubtractFunction(ExecutionMode m) { super(m); }
@@ -476,14 +476,14 @@
         }
     }
 
-    class Noop extends CheckedAction implements Runnable {
+    static class Noop extends CheckedAction implements Runnable {
         Noop(ExecutionMode m) { super(m); }
         public void run() {
             invoked();
         }
     }
 
-    class FailingSupplier extends CheckedAction
+    static class FailingSupplier extends CheckedAction
         implements Supplier<Integer>
     {
         final CFException ex;
@@ -494,7 +494,7 @@
         }
     }
 
-    class FailingConsumer extends CheckedIntegerAction
+    static class FailingConsumer extends CheckedIntegerAction
         implements Consumer<Integer>
     {
         final CFException ex;
@@ -506,7 +506,7 @@
         }
     }
 
-    class FailingBiConsumer extends CheckedIntegerAction
+    static class FailingBiConsumer extends CheckedIntegerAction
         implements BiConsumer<Integer, Integer>
     {
         final CFException ex;
@@ -518,7 +518,7 @@
         }
     }
 
-    class FailingFunction extends CheckedIntegerAction
+    static class FailingFunction extends CheckedIntegerAction
         implements Function<Integer, Integer>
     {
         final CFException ex;
@@ -530,7 +530,7 @@
         }
     }
 
-    class FailingBiFunction extends CheckedIntegerAction
+    static class FailingBiFunction extends CheckedIntegerAction
         implements BiFunction<Integer, Integer, Integer>
     {
         final CFException ex;
@@ -542,7 +542,7 @@
         }
     }
 
-    class FailingRunnable extends CheckedAction implements Runnable {
+    static class FailingRunnable extends CheckedAction implements Runnable {
         final CFException ex;
         FailingRunnable(ExecutionMode m) { super(m); ex = new CFException(); }
         public void run() {
@@ -551,7 +551,7 @@
         }
     }
 
-    class CompletableFutureInc extends CheckedIntegerAction
+    static class CompletableFutureInc extends CheckedIntegerAction
         implements Function<Integer, CompletableFuture<Integer>>
     {
         CompletableFutureInc(ExecutionMode m) { super(m); }
@@ -564,7 +564,7 @@
         }
     }
 
-    class FailingCompletableFutureFunction extends CheckedIntegerAction
+    static class FailingCompletableFutureFunction extends CheckedIntegerAction
         implements Function<Integer, CompletableFuture<Integer>>
     {
         final CFException ex;
@@ -3604,29 +3604,53 @@
      * copy returns a CompletableFuture that is completed normally,
      * with the same value, when source is.
      */
-    public void testCopy() {
+    public void testCopy_normalCompletion() {
+        for (boolean createIncomplete : new boolean[] { true, false })
+        for (Integer v1 : new Integer[] { 1, null })
+    {
         CompletableFuture<Integer> f = new CompletableFuture<>();
+        if (!createIncomplete) assertTrue(f.complete(v1));
         CompletableFuture<Integer> g = f.copy();
-        checkIncomplete(f);
-        checkIncomplete(g);
-        f.complete(1);
-        checkCompletedNormally(f, 1);
-        checkCompletedNormally(g, 1);
-    }
+        if (createIncomplete) {
+            checkIncomplete(f);
+            checkIncomplete(g);
+            assertTrue(f.complete(v1));
+        }
+        checkCompletedNormally(f, v1);
+        checkCompletedNormally(g, v1);
+    }}
 
     /**
      * copy returns a CompletableFuture that is completed exceptionally
      * when source is.
      */
-    public void testCopy2() {
+    public void testCopy_exceptionalCompletion() {
+        for (boolean createIncomplete : new boolean[] { true, false })
+    {
+        CFException ex = new CFException();
         CompletableFuture<Integer> f = new CompletableFuture<>();
+        if (!createIncomplete) f.completeExceptionally(ex);
         CompletableFuture<Integer> g = f.copy();
-        checkIncomplete(f);
-        checkIncomplete(g);
-        CFException ex = new CFException();
-        f.completeExceptionally(ex);
+        if (createIncomplete) {
+            checkIncomplete(f);
+            checkIncomplete(g);
+            f.completeExceptionally(ex);
+        }
         checkCompletedExceptionally(f, ex);
         checkCompletedWithWrappedException(g, ex);
+    }}
+
+    /**
+     * Completion of a copy does not complete its source.
+     */
+    public void testCopy_oneWayPropagation() {
+        CompletableFuture<Integer> f = new CompletableFuture<>();
+        assertTrue(f.copy().complete(1));
+        assertTrue(f.copy().complete(null));
+        assertTrue(f.copy().cancel(true));
+        assertTrue(f.copy().cancel(false));
+        assertTrue(f.copy().completeExceptionally(new CFException()));
+        checkIncomplete(f);
     }
 
     /**
@@ -3991,7 +4015,10 @@
             .collect(Collectors.toList());
 
         List<CompletionStage<Integer>> stages = new ArrayList<>();
-        stages.add(new CompletableFuture<Integer>().minimalCompletionStage());
+        CompletionStage<Integer> min =
+            new CompletableFuture<Integer>().minimalCompletionStage();
+        stages.add(min);
+        stages.add(min.thenApply(x -> x));
         stages.add(CompletableFuture.completedStage(1));
         stages.add(CompletableFuture.failedStage(new CFException()));
 
@@ -4027,6 +4054,131 @@
             throw new Error("Methods did not throw UOE: " + bugs);
     }
 
+    /**
+     * minimalStage.toCompletableFuture() returns a CompletableFuture that
+     * is completed normally, with the same value, when source is.
+     */
+    public void testMinimalCompletionStage_toCompletableFuture_normalCompletion() {
+        for (boolean createIncomplete : new boolean[] { true, false })
+        for (Integer v1 : new Integer[] { 1, null })
+    {
+        CompletableFuture<Integer> f = new CompletableFuture<>();
+        CompletionStage<Integer> minimal = f.minimalCompletionStage();
+        if (!createIncomplete) assertTrue(f.complete(v1));
+        CompletableFuture<Integer> g = minimal.toCompletableFuture();
+        if (createIncomplete) {
+            checkIncomplete(f);
+            checkIncomplete(g);
+            assertTrue(f.complete(v1));
+        }
+        checkCompletedNormally(f, v1);
+        checkCompletedNormally(g, v1);
+    }}
+
+    /**
+     * minimalStage.toCompletableFuture() returns a CompletableFuture that
+     * is completed exceptionally when source is.
+     */
+    public void testMinimalCompletionStage_toCompletableFuture_exceptionalCompletion() {
+        for (boolean createIncomplete : new boolean[] { true, false })
+    {
+        CFException ex = new CFException();
+        CompletableFuture<Integer> f = new CompletableFuture<>();
+        CompletionStage<Integer> minimal = f.minimalCompletionStage();
+        if (!createIncomplete) f.completeExceptionally(ex);
+        CompletableFuture<Integer> g = minimal.toCompletableFuture();
+        if (createIncomplete) {
+            checkIncomplete(f);
+            checkIncomplete(g);
+            f.completeExceptionally(ex);
+        }
+        checkCompletedExceptionally(f, ex);
+        checkCompletedWithWrappedException(g, ex);
+    }}
+
+    /**
+     * minimalStage.toCompletableFuture() gives mutable CompletableFuture
+     */
+    public void testMinimalCompletionStage_toCompletableFuture_mutable() {
+        for (Integer v1 : new Integer[] { 1, null })
+    {
+        CompletableFuture<Integer> f = new CompletableFuture<>();
+        CompletionStage minimal = f.minimalCompletionStage();
+        CompletableFuture<Integer> g = minimal.toCompletableFuture();
+        assertTrue(g.complete(v1));
+        checkCompletedNormally(g, v1);
+        checkIncomplete(f);
+        checkIncomplete(minimal.toCompletableFuture());
+    }}
+
+    /**
+     * minimalStage.toCompletableFuture().join() awaits completion
+     */
+    public void testMinimalCompletionStage_toCompletableFuture_join() throws Exception {
+        for (boolean createIncomplete : new boolean[] { true, false })
+        for (Integer v1 : new Integer[] { 1, null })
+    {
+        CompletableFuture<Integer> f = new CompletableFuture<>();
+        if (!createIncomplete) assertTrue(f.complete(v1));
+        CompletionStage<Integer> minimal = f.minimalCompletionStage();
+        if (createIncomplete) assertTrue(f.complete(v1));
+        assertEquals(v1, minimal.toCompletableFuture().join());
+        assertEquals(v1, minimal.toCompletableFuture().get());
+        checkCompletedNormally(minimal.toCompletableFuture(), v1);
+    }}
+
+    /**
+     * Completion of a toCompletableFuture copy of a minimal stage
+     * does not complete its source.
+     */
+    public void testMinimalCompletionStage_toCompletableFuture_oneWayPropagation() {
+        CompletableFuture<Integer> f = new CompletableFuture<>();
+        CompletionStage<Integer> g = f.minimalCompletionStage();
+        assertTrue(g.toCompletableFuture().complete(1));
+        assertTrue(g.toCompletableFuture().complete(null));
+        assertTrue(g.toCompletableFuture().cancel(true));
+        assertTrue(g.toCompletableFuture().cancel(false));
+        assertTrue(g.toCompletableFuture().completeExceptionally(new CFException()));
+        checkIncomplete(g.toCompletableFuture());
+        f.complete(1);
+        checkCompletedNormally(g.toCompletableFuture(), 1);
+    }
+
+    /** Demo utility method for external reliable toCompletableFuture */
+    static <T> CompletableFuture<T> toCompletableFuture(CompletionStage<T> stage) {
+        CompletableFuture<T> f = new CompletableFuture<>();
+        stage.handle((T t, Throwable ex) -> {
+                         if (ex != null) f.completeExceptionally(ex);
+                         else f.complete(t);
+                         return null;
+                     });
+        return f;
+    }
+
+    /** Demo utility method to join a CompletionStage */
+    static <T> T join(CompletionStage<T> stage) {
+        return toCompletableFuture(stage).join();
+    }
+
+    /**
+     * Joining a minimal stage "by hand" works
+     */
+    public void testMinimalCompletionStage_join_by_hand() {
+        for (boolean createIncomplete : new boolean[] { true, false })
+        for (Integer v1 : new Integer[] { 1, null })
+    {
+        CompletableFuture<Integer> f = new CompletableFuture<>();
+        CompletionStage<Integer> minimal = f.minimalCompletionStage();
+        CompletableFuture<Integer> g = new CompletableFuture<>();
+        if (!createIncomplete) assertTrue(f.complete(v1));
+        minimal.thenAccept((x) -> g.complete(x));
+        if (createIncomplete) assertTrue(f.complete(v1));
+        g.join();
+        checkCompletedNormally(g, v1);
+        checkCompletedNormally(f, v1);
+        assertEquals(v1, join(minimal));
+    }}
+
     static class Monad {
         static class ZeroException extends RuntimeException {
             public ZeroException() { super("monadic zero"); }
@@ -4317,6 +4469,22 @@
             assertTrue(neverCompleted.thenRun(() -> {}).cancel(true));
     }
 
+    /**
+     * Checks for garbage retention when MinimalStage.toCompletableFuture()
+     * is invoked many times.
+     * 8161600: Garbage retention when source CompletableFutures are never completed
+     *
+     * As of 2016-07, fails with OOME:
+     * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testToCompletableFutureGarbageRetention tck
+     */
+    public void testToCompletableFutureGarbageRetention() throws Throwable {
+        final int n = expensiveTests ? 900_000 : 10;
+        CompletableFuture<Integer> neverCompleted = new CompletableFuture<>();
+        CompletionStage minimal = neverCompleted.minimalCompletionStage();
+        for (int i = 0; i < n; i++)
+            assertTrue(minimal.toCompletableFuture().cancel(true));
+    }
+
 //     static <U> U join(CompletionStage<U> stage) {
 //         CompletableFuture<U> f = new CompletableFuture<>();
 //         stage.whenComplete((v, ex) -> {
--- a/jdk/test/java/util/concurrent/tck/ConcurrentSkipListMapTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentSkipListMapTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1024,7 +1024,7 @@
 
     static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
         NavigableMap<Integer, Integer> result =
-            (NavigableMap<Integer, Integer>) cl.newInstance();
+            (NavigableMap<Integer, Integer>) cl.getConstructor().newInstance();
         assertEquals(0, result.size());
         assertFalse(result.keySet().iterator().hasNext());
         return result;
--- a/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSetTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSetTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -725,7 +725,8 @@
     }
 
     static NavigableSet<Integer> newSet(Class cl) throws Exception {
-        NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance();
+        NavigableSet<Integer> result =
+            (NavigableSet<Integer>) cl.getConstructor().newInstance();
         assertEquals(0, result.size());
         assertFalse(result.iterator().hasNext());
         return result;
--- a/jdk/test/java/util/concurrent/tck/CyclicBarrierTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/tck/CyclicBarrierTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -40,6 +40,7 @@
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -52,11 +53,6 @@
         return new TestSuite(CyclicBarrierTest.class);
     }
 
-    private volatile int countAction;
-    private class MyAction implements Runnable {
-        public void run() { ++countAction; }
-    }
-
     /**
      * Spin-waits till the number of waiters == numberOfWaiters.
      */
@@ -114,14 +110,16 @@
      * The supplied barrier action is run at barrier
      */
     public void testBarrierAction() throws Exception {
-        countAction = 0;
-        CyclicBarrier b = new CyclicBarrier(1, new MyAction());
+        final AtomicInteger count = new AtomicInteger(0);
+        final Runnable incCount = new Runnable() { public void run() {
+            count.getAndIncrement(); }};
+        CyclicBarrier b = new CyclicBarrier(1, incCount);
         assertEquals(1, b.getParties());
         assertEquals(0, b.getNumberWaiting());
         b.await();
         b.await();
         assertEquals(0, b.getNumberWaiting());
-        assertEquals(2, countAction);
+        assertEquals(2, count.get());
     }
 
     /**
--- a/jdk/test/java/util/concurrent/tck/DelayQueueTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/tck/DelayQueueTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -121,10 +121,8 @@
         }
 
         public boolean equals(Object other) {
-            return equals((NanoDelay)other);
-        }
-        public boolean equals(NanoDelay other) {
-            return other.trigger == trigger;
+            return (other instanceof NanoDelay) &&
+                this.trigger == ((NanoDelay)other).trigger;
         }
 
         // suppress [overrides] javac warning
--- a/jdk/test/java/util/concurrent/tck/ForkJoinPoolTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/tck/ForkJoinPoolTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -51,6 +51,7 @@
 import java.util.concurrent.RecursiveTask;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.ReentrantLock;
 
 import junit.framework.AssertionFailedError;
@@ -84,13 +85,6 @@
 
     // Some classes to test extension and factory methods
 
-    static class MyHandler implements Thread.UncaughtExceptionHandler {
-        volatile int catches = 0;
-        public void uncaughtException(Thread t, Throwable e) {
-            ++catches;
-        }
-    }
-
     static class MyError extends Error {}
 
     // to test handlers
@@ -101,9 +95,9 @@
 
     static class FailingThreadFactory
             implements ForkJoinPool.ForkJoinWorkerThreadFactory {
-        volatile int calls = 0;
+        final AtomicInteger calls = new AtomicInteger(0);
         public ForkJoinWorkerThread newThread(ForkJoinPool p) {
-            if (++calls > 1) return null;
+            if (calls.incrementAndGet() > 1) return null;
             return new FailingFJWSubclass(p);
         }
     }
--- a/jdk/test/java/util/concurrent/tck/JSR166TestCase.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/tck/JSR166TestCase.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1032,14 +1032,17 @@
         ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
         System.err.println("------ stacktrace dump start ------");
         for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
-            String name = info.getThreadName();
+            final String name = info.getThreadName();
+            String lockName;
             if ("Signal Dispatcher".equals(name))
                 continue;
             if ("Reference Handler".equals(name)
-                && info.getLockName().startsWith("java.lang.ref.Reference$Lock"))
+                && (lockName = info.getLockName()) != null
+                && lockName.startsWith("java.lang.ref.Reference$Lock"))
                 continue;
             if ("Finalizer".equals(name)
-                && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock"))
+                && (lockName = info.getLockName()) != null
+                && lockName.startsWith("java.lang.ref.ReferenceQueue$Lock"))
                 continue;
             if ("checkForWedgedTest".equals(name))
                 continue;
@@ -1783,7 +1786,7 @@
      * A CyclicBarrier that uses timed await and fails with
      * AssertionFailedErrors instead of throwing checked exceptions.
      */
-    public class CheckedBarrier extends CyclicBarrier {
+    public static class CheckedBarrier extends CyclicBarrier {
         public CheckedBarrier(int parties) { super(parties); }
 
         public int await() {
--- a/jdk/test/java/util/concurrent/tck/ScheduledExecutorTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/tck/ScheduledExecutorTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -537,15 +537,14 @@
      * isShutdown is false before shutdown, true after
      */
     public void testIsShutdown() {
-
         final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
-        try {
-            assertFalse(p.isShutdown());
+        assertFalse(p.isShutdown());
+        try (PoolCleaner cleaner = cleaner(p)) {
+            try {
+                p.shutdown();
+                assertTrue(p.isShutdown());
+            } catch (SecurityException ok) {}
         }
-        finally {
-            try { p.shutdown(); } catch (SecurityException ok) { return; }
-        }
-        assertTrue(p.isShutdown());
     }
 
     /**
--- a/jdk/test/java/util/concurrent/tck/TreeMapTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/tck/TreeMapTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -829,7 +829,7 @@
 
     static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
         NavigableMap<Integer, Integer> result
-            = (NavigableMap<Integer, Integer>) cl.newInstance();
+            = (NavigableMap<Integer, Integer>) cl.getConstructor().newInstance();
         assertEquals(0, result.size());
         assertFalse(result.keySet().iterator().hasNext());
         return result;
--- a/jdk/test/java/util/concurrent/tck/TreeSetTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/concurrent/tck/TreeSetTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -722,7 +722,8 @@
     }
 
     static NavigableSet<Integer> newSet(Class cl) throws Exception {
-        NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance();
+        NavigableSet<Integer> result =
+            (NavigableSet<Integer>) cl.getConstructor().newInstance();
         assertEquals(0, result.size());
         assertFalse(result.iterator().hasNext());
         return result;
--- a/jdk/test/java/util/jar/JarFile/mrjar/MultiReleaseJarAPI.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/java/util/jar/JarFile/mrjar/MultiReleaseJarAPI.java	Fri Sep 30 09:28:18 2016 -0700
@@ -40,6 +40,7 @@
 import java.util.Arrays;
 import java.util.Map;
 import java.util.Random;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.jar.JarFile;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
@@ -133,11 +134,14 @@
         testCustomMultiReleaseValue(value, Map.of(), expected);
     }
 
+    private static final AtomicInteger JAR_COUNT = new AtomicInteger(0);
+
     private void testCustomMultiReleaseValue(String value,
             Map<String, String> extraAttributes, boolean expected)
             throws Exception {
-        creator.buildCustomMultiReleaseJar("custom-mr.jar", value, extraAttributes);
-        File custom = new File(userdir, "custom-mr.jar");
+        String fileName = "custom-mr" + JAR_COUNT.incrementAndGet() + ".jar";
+        creator.buildCustomMultiReleaseJar(fileName, value, extraAttributes);
+        File custom = new File(userdir, fileName);
         try (JarFile jf = new JarFile(custom, true, ZipFile.OPEN_READ, Runtime.version())) {
             Assert.assertEquals(jf.isMultiRelease(), expected);
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/crypto/Cipher/EmptyFinalBuffer.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 6946830
+ * @summary Test the Cipher.doFinal() with 0-length buffer
+ * @key randomness
+ */
+
+import java.util.*;
+import java.nio.*;
+
+import java.security.*;
+
+import javax.crypto.*;
+import javax.crypto.spec.*;
+
+public class EmptyFinalBuffer {
+
+    private static final String[] ALGOS = {
+        "AES/ECB/PKCS5Padding", "AES/CBC/PKCS5Padding"
+    };
+
+    public static void main(String[] args) throws Exception {
+
+        Provider[] provs = Security.getProviders();
+
+        SecretKey key = new SecretKeySpec(new byte[16], "AES");
+
+        boolean testFailed = false;
+        for (Provider p : provs) {
+            System.out.println("Testing: " + p.getName());
+            for (String algo : ALGOS) {
+                System.out.print("Algo: " + algo);
+                Cipher c;
+                try {
+                    c = Cipher.getInstance(algo, p);
+                } catch (NoSuchAlgorithmException nsae) {
+                    // skip
+                    System.out.println("=> No Support");
+                    continue;
+                }
+                c.init(Cipher.ENCRYPT_MODE, key);
+                AlgorithmParameters params = c.getParameters();
+                c.init(Cipher.DECRYPT_MODE, key, params);
+                try {
+                    byte[] out = c.doFinal(new byte[0]);
+                    System.out.println("=> Accepted w/ " +
+                        (out == null? "null" : (out.length + "-byte")) +
+                        " output");
+                } catch (Exception e) {
+                    testFailed = true;
+                    System.out.println("=> Rejected w/ Exception");
+                    e.printStackTrace();
+                }
+            }
+        }
+        if (testFailed) {
+            throw new Exception("One or more tests failed");
+        } else {
+            System.out.println("All tests passed");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/net/ssl/templates/SSLTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,493 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.SocketTimeoutException;
+import java.security.KeyStore;
+import java.util.Arrays;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+
+/**
+ * Helper class for JSSE tests.
+ *
+ * Please run in othervm mode.  SunJSSE does not support dynamic system
+ * properties, no way to re-use system properties in samevm/agentvm mode.
+ */
+public class SSLTest {
+
+    public static final String TEST_SRC = System.getProperty("test.src", ".");
+
+    /*
+     * Where do we find the keystores?
+     */
+    public static final String PATH_TO_STORES = "../etc";
+    public static final String KEY_STORE_FILE = "keystore";
+    public static final String TRUST_STORE_FILE = "truststore";
+    public static final String PASSWORD = "passphrase";
+
+    public static final int FREE_PORT = 0;
+
+    // in seconds
+    public static final long CLIENT_SIGNAL_TIMEOUT = 30L;
+    public static final long SERVER_SIGNAL_TIMEOUT = 90L;
+
+    // in millis
+    public static final int CLIENT_TIMEOUT = 15000;
+    public static final int SERVER_TIMEOUT = 30000;
+
+    /*
+     * Should we run the client or server in a separate thread?
+     * Both sides can throw exceptions, but do you have a preference
+     * as to which side should be the main thread.
+     */
+    private boolean separateServerThread = false;
+
+    /*
+     * What's the server port?  Use any free port by default
+     */
+    private volatile int serverPort;
+
+    private volatile Exception serverException;
+    private volatile Exception clientException;
+
+    private Thread clientThread;
+    private Thread serverThread;
+
+    private Peer serverPeer;
+    private Peer clientPeer;
+
+    private Application serverApplication;
+    private Application clientApplication;
+
+    private SSLContext context;
+
+    /*
+     * Is the server ready to serve?
+     */
+    private final CountDownLatch serverCondition = new CountDownLatch(1);
+
+    /*
+     * Is the client ready to handshake?
+     */
+    private final CountDownLatch clientCondition = new CountDownLatch(1);
+
+    /*
+     * Public API.
+     */
+
+    public static interface Peer {
+        void run(SSLTest test) throws Exception;
+    }
+
+    public static interface Application {
+        void run(SSLSocket socket, SSLTest test) throws Exception;
+    }
+
+    public static void debug() {
+        debug("ssl");
+    }
+
+    public static void debug(String mode) {
+        System.setProperty("javax.net.debug", mode);
+    }
+
+    public static void setup(String keyFilename, String trustFilename,
+            String password) {
+
+        System.setProperty("javax.net.ssl.keyStore", keyFilename);
+        System.setProperty("javax.net.ssl.keyStorePassword", password);
+        System.setProperty("javax.net.ssl.trustStore", trustFilename);
+        System.setProperty("javax.net.ssl.trustStorePassword", password);
+    }
+
+    public static void setup() throws Exception {
+        String keyFilename = TEST_SRC + "/" + PATH_TO_STORES + "/"
+                + KEY_STORE_FILE;
+        String trustFilename = TEST_SRC + "/" + PATH_TO_STORES + "/"
+                + TRUST_STORE_FILE;
+
+        setup(keyFilename, trustFilename, PASSWORD);
+    }
+
+    public static void print(String message, Throwable... errors) {
+        synchronized (System.out) {
+            System.out.println(message);
+            Arrays.stream(errors).forEach(e -> e.printStackTrace(System.out));
+        }
+    }
+
+    public static KeyStore loadJksKeyStore(String filename, String password)
+            throws Exception {
+
+        return loadKeyStore(filename, password, "JKS");
+    }
+
+    public static KeyStore loadKeyStore(String filename, String password,
+            String type) throws Exception {
+
+        KeyStore keystore = KeyStore.getInstance(type);
+        try (FileInputStream fis = new FileInputStream(filename)) {
+            keystore.load(fis, password.toCharArray());
+        }
+        return keystore;
+    }
+
+    public SSLTest setSeparateServerThread(boolean separateServerThread) {
+        this.separateServerThread = separateServerThread;
+        return this;
+    }
+
+    public SSLTest setServerPort(int serverPort) {
+        this.serverPort = serverPort;
+        return this;
+    }
+
+    public int getServerPort() {
+        return serverPort;
+    }
+
+    public SSLTest setSSLContext(SSLContext context) {
+        this.context = context;
+        return this;
+    }
+
+    public SSLContext getSSLContext() {
+        return context;
+    }
+
+    public SSLServerSocketFactory getSSLServerSocketFactory() {
+        if (context != null) {
+            return context.getServerSocketFactory();
+        }
+
+        return (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
+    }
+
+    public SSLSocketFactory getSSLSocketFactory() {
+        if (context != null) {
+            return context.getSocketFactory();
+        }
+
+        return (SSLSocketFactory) SSLSocketFactory.getDefault();
+    }
+
+    public void signalServerReady() {
+        serverCondition.countDown();
+    }
+
+    public boolean waitForClientSignal(long timeout, TimeUnit unit)
+            throws InterruptedException {
+
+        return clientCondition.await(timeout, unit);
+    }
+
+    public boolean waitForClientSignal() throws InterruptedException {
+        return waitForClientSignal(CLIENT_SIGNAL_TIMEOUT, TimeUnit.SECONDS);
+    }
+
+    public void signalClientReady() {
+        clientCondition.countDown();
+    }
+
+    public boolean waitForServerSignal(long timeout, TimeUnit unit)
+            throws InterruptedException {
+
+        return serverCondition.await(timeout, unit);
+    }
+
+    public boolean waitForServerSignal() throws InterruptedException {
+        return waitForServerSignal(SERVER_SIGNAL_TIMEOUT, TimeUnit.SECONDS);
+    }
+
+    public SSLTest setServerPeer(Peer serverPeer) {
+        this.serverPeer = serverPeer;
+        return this;
+    }
+
+    public Peer getServerPeer() {
+        return serverPeer;
+    }
+
+    public SSLTest setServerApplication(Application serverApplication) {
+        this.serverApplication = serverApplication;
+        return this;
+    }
+
+    public Application getServerApplication() {
+        return serverApplication;
+    }
+
+    public SSLTest setClientPeer(Peer clientPeer) {
+        this.clientPeer = clientPeer;
+        return this;
+    }
+
+    public Peer getClientPeer() {
+        return clientPeer;
+    }
+
+    public SSLTest setClientApplication(Application clientApplication) {
+        this.clientApplication = clientApplication;
+        return this;
+    }
+
+    public Application getClientApplication() {
+        return clientApplication;
+    }
+
+    public void runTest() throws Exception {
+        if (separateServerThread) {
+            startServer(true, this);
+            startClient(false, this);
+            serverThread.join();
+        } else {
+            startClient(true, this);
+            startServer(false, this);
+            clientThread.join();
+        }
+
+        if (clientException != null || serverException != null) {
+            throw new RuntimeException("Test failed");
+        }
+    }
+
+    public SSLTest() {
+        serverPeer = (test) -> doServerSide(test);
+        clientPeer = (test) -> doClientSide(test);
+        serverApplication = (socket, test) -> runServerApplication(socket);
+        clientApplication = (socket, test) -> runClientApplication(socket);
+    }
+
+    /*
+     * Private part.
+     */
+
+
+    /*
+     * Define the server side of the test.
+     */
+    private static void doServerSide(SSLTest test) throws Exception {
+        SSLServerSocket sslServerSocket;
+
+        // kick start the server side service
+        SSLServerSocketFactory sslssf = test.getSSLServerSocketFactory();
+        sslServerSocket = (SSLServerSocket)sslssf.createServerSocket(FREE_PORT);
+
+        test.setServerPort(sslServerSocket.getLocalPort());
+        print("Server is listening on port " + test.getServerPort());
+
+        // Signal the client, the server is ready to accept connection.
+        test.signalServerReady();
+
+        // Try to accept a connection in 30 seconds.
+        SSLSocket sslSocket;
+        try {
+            sslServerSocket.setSoTimeout(SERVER_TIMEOUT);
+            sslSocket = (SSLSocket) sslServerSocket.accept();
+            print("Server accepted connection");
+        } catch (SocketTimeoutException ste) {
+            sslServerSocket.close();
+
+            // Ignore the test case if no connection within 30 seconds.
+            print("No incoming client connection in 30 seconds. "
+                    + "Ignore in server side.", ste);
+            return;
+        }
+
+        // handle the connection
+        try {
+            // Is it the expected client connection?
+            //
+            // Naughty test cases or third party routines may try to
+            // connection to this server port unintentionally.  In
+            // order to mitigate the impact of unexpected client
+            // connections and avoid intermittent failure, it should
+            // be checked that the accepted connection is really linked
+            // to the expected client.
+            boolean clientIsReady = test.waitForClientSignal();
+
+            if (clientIsReady) {
+                // Run the application in server side.
+                print("Run server application");
+                test.getServerApplication().run(sslSocket, test);
+            } else {    // Otherwise, ignore
+                // We don't actually care about plain socket connections
+                // for TLS communication testing generally.  Just ignore
+                // the test if the accepted connection is not linked to
+                // the expected client or the client connection timeout
+                // in 30 seconds.
+                print("The client is not the expected one or timeout. "
+                        + "Ignore in server side.");
+            }
+        } finally {
+            sslSocket.close();
+            sslServerSocket.close();
+        }
+    }
+
+    /*
+     * Define the server side application of the test for the specified socket.
+     */
+    private static void runServerApplication(SSLSocket socket)
+            throws Exception {
+
+        // here comes the test logic
+        InputStream sslIS = socket.getInputStream();
+        OutputStream sslOS = socket.getOutputStream();
+
+        sslIS.read();
+        sslOS.write(85);
+        sslOS.flush();
+    }
+
+    /*
+     * Define the client side of the test.
+     */
+    private static void doClientSide(SSLTest test) throws Exception {
+
+        // Wait for server to get started.
+        //
+        // The server side takes care of the issue if the server cannot
+        // get started in 90 seconds.  The client side would just ignore
+        // the test case if the serer is not ready.
+        boolean serverIsReady = test.waitForServerSignal();
+        if (!serverIsReady) {
+            print("The server is not ready yet in 90 seconds. "
+                    + "Ignore in client side.");
+            return;
+        }
+
+        SSLSocketFactory sslsf = test.getSSLSocketFactory();
+        try (SSLSocket sslSocket = (SSLSocket)sslsf.createSocket()) {
+            try {
+                sslSocket.connect(
+                        new InetSocketAddress("localhost",
+                                test.getServerPort()), CLIENT_TIMEOUT);
+                print("Client connected to server");
+            } catch (IOException ioe) {
+                // The server side may be impacted by naughty test cases or
+                // third party routines, and cannot accept connections.
+                //
+                // Just ignore the test if the connection cannot be
+                // established.
+                print("Cannot make a connection in 15 seconds. "
+                        + "Ignore in client side.", ioe);
+                return;
+            }
+
+            // OK, here the client and server get connected.
+
+            // Signal the server, the client is ready to communicate.
+            test.signalClientReady();
+
+            // There is still a chance in theory that the server thread may
+            // wait client-ready timeout and then quit.  The chance should
+            // be really rare so we don't consider it until it becomes a
+            // real problem.
+
+            // Run the application in client side.
+            print("Run client application");
+            test.getClientApplication().run(sslSocket, test);
+        }
+    }
+
+    /*
+     * Define the client side application of the test for the specified socket.
+     */
+    private static void runClientApplication(SSLSocket socket)
+            throws Exception {
+
+        InputStream sslIS = socket.getInputStream();
+        OutputStream sslOS = socket.getOutputStream();
+
+        sslOS.write(280);
+        sslOS.flush();
+        sslIS.read();
+    }
+
+    private void startServer(boolean newThread, SSLTest test) throws Exception {
+        if (newThread) {
+            serverThread = new Thread() {
+                @Override
+                public void run() {
+                    try {
+                        serverPeer.run(test);
+                    } catch (Exception e) {
+                        /*
+                         * Our server thread just died.
+                         *
+                         * Release the client, if not active already...
+                         */
+                        print("Server died ...", e);
+                        serverException = e;
+                    }
+                }
+            };
+            serverThread.start();
+        } else {
+            try {
+                serverPeer.run(test);
+            } catch (Exception e) {
+                print("Server failed ...", e);
+                serverException = e;
+            }
+        }
+    }
+
+    private void startClient(boolean newThread, SSLTest test) throws Exception {
+        if (newThread) {
+            clientThread = new Thread() {
+                @Override
+                public void run() {
+                    try {
+                        clientPeer.run(test);
+                    } catch (Exception e) {
+                        /*
+                         * Our client thread just died.
+                         */
+                        print("Client died ...", e);
+                        clientException = e;
+                    }
+                }
+            };
+            clientThread.start();
+        } else {
+            try {
+                clientPeer.run(test);
+            } catch (Exception e) {
+                print("Client failed ...", e);
+                clientException = e;
+            }
+        }
+    }
+}
--- a/jdk/test/jdk/internal/misc/Unsafe/TestBadHostClass.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/jdk/internal/misc/Unsafe/TestBadHostClass.java	Fri Sep 30 09:28:18 2016 -0700
@@ -25,7 +25,6 @@
  * @test
  * @bug 8058575
  * @summary Test that bad host classes cause exceptions to get thrown.
- * @library /test/lib
  * @modules java.base/jdk.internal.misc
  *          java.base/jdk.internal.org.objectweb.asm
  * @run main TestBadHostClass
@@ -35,7 +34,6 @@
 import java.lang.*;
 import java.lang.reflect.Field;
 import jdk.internal.misc.Unsafe;
-import jdk.test.lib.unsafe.UnsafeHelper;
 import jdk.internal.org.objectweb.asm.ClassWriter;
 import static jdk.internal.org.objectweb.asm.Opcodes.*;
 
--- a/jdk/test/jprt.config	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/jprt.config	Fri Sep 30 09:28:18 2016 -0700
@@ -82,15 +82,12 @@
     fi
 
     # Add basic solaris system paths
-    path4sdk=/usr/ccs/bin:/usr/ccs/lib:/usr/bin:/bin:/usr/sfw/bin
+    path4sdk=/usr/bin:/usr/gnu/bin
 
     # Find GNU make
-    make=/usr/sfw/bin/gmake
+    make=/usr/bin/gmake
     if [ ! -f ${make} ] ; then
-	make=/opt/sfw/bin/gmake
-	if [ ! -f ${make} ] ; then
-	    make=${slashjava}/devtools/${solaris_arch}/bin/gnumake
-        fi 
+	make=${slashjava}/devtools/${solaris_arch}/bin/gnumake
     fi
     fileMustExist "${make}" make
 
--- a/jdk/test/start-Xvfb.sh	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/start-Xvfb.sh	Fri Sep 30 09:28:18 2016 -0700
@@ -59,9 +59,6 @@
   /usr/bin/nohup /usr/bin/X11/Xvfb -fbdir ${currentDir} -pixdepths 8 16 24 32 ${DISPLAY} > ${currentDir}/nohup.$$ 2>&1 &
 fi
 WM="/usr/bin/X11/fvwm2"
-if [ ! -x ${WM} ] ; then
-  WM="/opt/sfw/bin/fvwm2"
-fi
 #
 # Wait for Xvfb to initialize:
 sleep 5
--- a/jdk/test/sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,9 @@
  * @bug 4328195
  * @summary Need to include the alternate subject DN for certs,
  *          https should check for this
- * @run main/othervm ServerIdentityTest
+ * @library /javax/net/ssl/templates
+ * @run main/othervm ServerIdentityTest dnsstore
+ * @run main/othervm ServerIdentityTest ipstore
  *
  *     SunJSSE does not support dynamic system properties, no way to re-use
  *     system properties in samevm/agentvm mode.
@@ -34,242 +36,71 @@
  * @author Yingxian Wang
  */
 
-import java.io.*;
-import java.net.*;
-import javax.net.ssl.*;
+import java.io.BufferedWriter;
+import java.io.OutputStreamWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
 import java.security.KeyStore;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContext;
 
 public class ServerIdentityTest {
 
-    /*
-     * =============================================================
-     * Set the various variables needed for the tests, then
-     * specify what tests to run on each side.
-     */
-
-    /*
-     * Should we run the client or server in a separate thread?
-     * Both sides can throw exceptions, but do you have a preference
-     * as to which side should be the main thread.
-     */
-    static boolean separateServerThread = true;
-
-    /*
-     * Where do we find the keystores?
-     */
-    static String pathToStores = "./";
-    static String[] keyStoreFiles = {"dnsstore", "ipstore"};
-    static String[] trustStoreFiles = {"dnsstore", "ipstore"};
-    static String passwd = "changeit";
-
-    /*
-     * Is the server ready to serve?
-     */
-    boolean serverReady = false;
-
-    /*
-     * Turn on SSL debugging?
-     */
-    static boolean debug = false;
-
-    /*
-     * If the client or server is doing some kind of object creation
-     * that the other side depends on, and that thread prematurely
-     * exits, you may experience a hang.  The test harness will
-     * terminate all hung threads after its timeout has expired,
-     * currently 3 minutes by default, but you might try to be
-     * smart about it....
-     */
-
-    /*
-     * Define the server side of the test.
-     *
-     * If the server prematurely exits, serverReady will be set to true
-     * to avoid infinite hangs.
-     */
-    void doServerSide() throws Exception {
-        SSLServerSocketFactory sslssf =
-            context.getServerSocketFactory();
-        SSLServerSocket sslServerSocket =
-            (SSLServerSocket) sslssf.createServerSocket(serverPort);
-        serverPort = sslServerSocket.getLocalPort();
-
-        /*
-         * Signal Client, we're ready for his connect.
-         */
-        serverReady = true;
-
-        SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
-        OutputStream sslOS = sslSocket.getOutputStream();
-        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(sslOS));
-        bw.write("HTTP/1.1 200 OK\r\n\r\n\r\n");
-        bw.flush();
-        Thread.sleep(2000);
-        sslSocket.getSession().invalidate();
-        sslSocket.close();
-    }
-
-    /*
-     * Define the client side of the test.
-     *
-     * If the server prematurely exits, serverReady will be set to true
-     * to avoid infinite hangs.
-     */
-    void doClientSide() throws Exception {
-        /*
-         * Wait for server to get started.
-         */
-        while (!serverReady) {
-            Thread.sleep(50);
-        }
-        String host = iphost? "127.0.0.1": "localhost";
-        URL url = new URL("https://"+host+":"+serverPort+"/index.html");
-
-        HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
-        InputStream is = urlc.getInputStream();
-        is.close();
-    }
-
-    /*
-     * =============================================================
-     * The remainder is just support stuff
-     */
-
-    volatile int serverPort = 0;
-
-    volatile Exception serverException = null;
-    volatile Exception clientException = null;
+    private static final String PASSWORD = "changeit";
 
     public static void main(String[] args) throws Exception {
-        SSLSocketFactory reservedSFactory =
-                HttpsURLConnection.getDefaultSSLSocketFactory();
-        try {
-            for (int i = 0; i < keyStoreFiles.length; i++) {
-                String keyFilename =
-                    System.getProperty("test.src", ".") + "/" + pathToStores +
-                    "/" + keyStoreFiles[i];
-                String trustFilename =
-                    System.getProperty("test.src", ".") + "/" + pathToStores +
-                    "/" + trustStoreFiles[i];
+        final String keystore = args[0];
+        String keystoreFilename = SSLTest.TEST_SRC + "/" + keystore;
 
-                System.setProperty("javax.net.ssl.keyStore", keyFilename);
-                System.setProperty("javax.net.ssl.keyStorePassword", passwd);
-                System.setProperty("javax.net.ssl.trustStore", trustFilename);
-                System.setProperty("javax.net.ssl.trustStorePassword", passwd);
-
-                if (debug)
-                    System.setProperty("javax.net.debug", "all");
-                SSLContext context = SSLContext.getInstance("SSL");
+        SSLTest.setup(keystoreFilename, keystoreFilename, PASSWORD);
 
-                KeyManager[] kms = new KeyManager[1];
-                KeyStore ks = KeyStore.getInstance("JKS");
-                FileInputStream fis = new FileInputStream(keyFilename);
-                ks.load(fis, passwd.toCharArray());
-                fis.close();
-                KeyManager km = new MyKeyManager(ks, passwd.toCharArray());
-                kms[0] = km;
-                context.init(kms, null, null);
-                HttpsURLConnection.setDefaultSSLSocketFactory(
-                     context.getSocketFactory());
+        SSLContext context = SSLContext.getInstance("SSL");
 
-                /*
-                 * Start the tests.
-                 */
-                System.out.println("Testing " + keyFilename);
-                new ServerIdentityTest(context, keyStoreFiles[i]);
-            }
-        } finally {
-            HttpsURLConnection.setDefaultSSLSocketFactory(reservedSFactory);
-        }
-    }
-
-    Thread clientThread = null;
-    Thread serverThread = null;
-
-    /*
-     * Primary constructor, used to drive remainder of the test.
-     *
-     * Fork off the other side, then do your work.
-     */
-    SSLContext context;
-    boolean iphost = false;
-    ServerIdentityTest(SSLContext context, String keystore)
-        throws Exception {
-        this.context = context;
-        iphost = keystore.equals("ipstore");
-        if (separateServerThread) {
-            startServer(true);
-            startClient(false);
-        } else {
-            startClient(true);
-            startServer(false);
-        }
+        KeyManager[] kms = new KeyManager[1];
+        KeyStore ks = SSLTest.loadJksKeyStore(keystoreFilename, PASSWORD);
+        KeyManager km = new MyKeyManager(ks, PASSWORD.toCharArray());
+        kms[0] = km;
+        context.init(kms, null, null);
+        HttpsURLConnection.setDefaultSSLSocketFactory(
+                context.getSocketFactory());
 
         /*
-         * Wait for other side to close down.
+         * Start the test.
          */
-        if (separateServerThread) {
-            serverThread.join();
-        } else {
-            clientThread.join();
-        }
-
-        /*
-         * When we get here, the test is pretty much over.
-         *
-         * If the main thread excepted, that propagates back
-         * immediately.  If the other thread threw an exception, we
-         * should report back.
-         */
-        if (serverException != null)
-            throw serverException;
-        if (clientException != null)
-            throw clientException;
-    }
+        System.out.println("Testing " + keystore);
 
-    void startServer(boolean newThread) throws Exception {
-        if (newThread) {
-            serverThread = new Thread() {
-                public void run() {
-                    try {
-                        doServerSide();
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                        /*
-                         * Our server thread just died.
-                         *
-                         * Release the client, if not active already...
-                         */
-                        System.err.println("Server died...");
-                        serverReady = true;
-                        serverException = e;
-                    }
+        new SSLTest()
+            .setSSLContext(context)
+            .setServerApplication((socket, test) -> {
+                BufferedWriter bw = new BufferedWriter(
+                        new OutputStreamWriter(socket.getOutputStream()));
+                bw.write("HTTP/1.1 200 OK\r\n\r\n\r\n");
+                bw.flush();
+                Thread.sleep(2000);
+                socket.getSession().invalidate();
+                SSLTest.print("Server application is done");
+            })
+            .setClientPeer((test) -> {
+                boolean serverIsReady = test.waitForServerSignal();
+                if (!serverIsReady) {
+                    SSLTest.print(
+                            "The server is not ready, ignore on client side.");
+                    return;
                 }
-            };
-            serverThread.start();
-        } else {
-            doServerSide();
-        }
-    }
+
+                // Signal the server, the client is ready to communicate.
+                test.signalClientReady();
 
-    void startClient(boolean newThread) throws Exception {
-        if (newThread) {
-            clientThread = new Thread() {
-                public void run() {
-                    try {
-                        doClientSide();
-                    } catch (Exception e) {
-                        /*
-                         * Our client thread just died.
-                         */
-                        System.err.println("Client died...");
-                        clientException = e;
-                    }
-                }
-            };
-            clientThread.start();
-        } else {
-            doClientSide();
-        }
+                String host = keystore.equals("ipstore")
+                        ? "127.0.0.1" : "localhost";
+                URL url = new URL("https://" + host + ":" + test.getServerPort()
+                        + "/index.html");
+
+                ((HttpURLConnection) url.openConnection())
+                        .getInputStream().close();
+
+                SSLTest.print("Client is done");
+            }).runTest();
     }
 }
--- a/jdk/test/sun/nio/cs/TestUnmappable.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/nio/cs/TestUnmappable.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,11 +28,11 @@
  * @bug 8008386
  * @summary (cs) Unmappable leading should be decoded to replacement.
  *          Tests for Shift_JIS and MS932 decoding
+ * @modules jdk.charsets
  * @run main TestUnmappable
  */
 
-import java.nio.*;
-import java.nio.charset.*;
+import java.nio.charset.Charset;
 
 public class TestUnmappable {
     public static void main(String args[]) throws Exception {
--- a/jdk/test/sun/security/pkcs11/tls/TestKeyMaterial.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/pkcs11/tls/TestKeyMaterial.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 6316539
+ * @bug 6316539 8136355
  * @summary Known-answer-test for TlsKeyMaterial generator
  * @author Andreas Sterbenz
  * @library ..
@@ -37,6 +37,7 @@
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.security.Provider;
+import java.security.InvalidAlgorithmParameterException;
 import java.util.Arrays;
 import javax.crypto.KeyGenerator;
 import javax.crypto.SecretKey;
@@ -139,21 +140,28 @@
                         keyLength, expandedKeyLength, ivLength, macLength,
                         null, -1, -1);
 
-                    kg.init(spec);
-                    TlsKeyMaterialSpec result =
-                        (TlsKeyMaterialSpec)kg.generateKey();
-                    match(lineNumber, clientCipherBytes,
-                        result.getClientCipherKey(), cipherAlgorithm);
-                    match(lineNumber, serverCipherBytes,
-                        result.getServerCipherKey(), cipherAlgorithm);
-                    match(lineNumber, clientIv, result.getClientIv(), "");
-                    match(lineNumber, serverIv, result.getServerIv(), "");
-                    match(lineNumber, clientMacBytes, result.getClientMacKey(), "");
-                    match(lineNumber, serverMacBytes, result.getServerMacKey(), "");
-
-                } else {
+                    try {
+                        kg.init(spec);
+                        TlsKeyMaterialSpec result =
+                            (TlsKeyMaterialSpec)kg.generateKey();
+                        match(lineNumber, clientCipherBytes,
+                            result.getClientCipherKey(), cipherAlgorithm);
+                        match(lineNumber, serverCipherBytes,
+                            result.getServerCipherKey(), cipherAlgorithm);
+                        match(lineNumber, clientIv, result.getClientIv(), "");
+                        match(lineNumber, serverIv, result.getServerIv(), "");
+                        match(lineNumber, clientMacBytes, result.getClientMacKey(), "");
+                        match(lineNumber, serverMacBytes, result.getServerMacKey(), "");
+                    } catch (InvalidAlgorithmParameterException iape) {
+                        // SSLv3 support is removed in S12
+                        if (major == 3 && minor == 0) {
+                            System.out.println("Skip testing SSLv3");
+                            continue;
+                        }
+                    }
+               } else {
                     throw new Exception("Unknown line: " + line);
-                }
+               }
             }
             if (n == 0) {
                 throw new Exception("no tests");
--- a/jdk/test/sun/security/pkcs11/tls/TestMasterSecret.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/pkcs11/tls/TestMasterSecret.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 6316539
+ * @bug 6316539 8136355
  * @summary Known-answer-test for TlsMasterSecret generator
  * @author Andreas Sterbenz
  * @library ..
@@ -38,6 +38,7 @@
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.security.Provider;
+import java.security.InvalidAlgorithmParameterException;
 import java.util.Arrays;
 import javax.crypto.KeyGenerator;
 import javax.crypto.SecretKey;
@@ -116,15 +117,24 @@
                         new TlsMasterSecretParameterSpec(premasterKey,
                             protoMajor, protoMinor, clientRandom, serverRandom,
                             null, -1, -1);
-                    kg.init(spec);
-                    TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
-                    byte[] enc = key.getEncoded();
-                    if (Arrays.equals(master, enc) == false) {
-                        throw new Exception("mismatch line: " + lineNumber);
-                    }
-                    if ((preMajor != key.getMajorVersion()) ||
-                            (preMinor != key.getMinorVersion())) {
-                        throw new Exception("version mismatch line: " + lineNumber);
+
+                    try {
+                        kg.init(spec);
+                        TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
+                        byte[] enc = key.getEncoded();
+                        if (Arrays.equals(master, enc) == false) {
+                            throw new Exception("mismatch line: " + lineNumber);
+                        }
+                        if ((preMajor != key.getMajorVersion()) ||
+                                (preMinor != key.getMinorVersion())) {
+                           throw new Exception("version mismatch line: " + lineNumber);
+                        }
+                    } catch (InvalidAlgorithmParameterException iape) {
+                        // SSLv3 support is removed in S12
+                        if (preMajor == 3 && preMinor == 0) {
+                            System.out.println("Skip testing SSLv3");
+                            continue;
+                        }
                     }
                 } else {
                     throw new Exception("Unknown line: " + line);
--- a/jdk/test/sun/security/pkcs11/tls/TestPremaster.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/pkcs11/tls/TestPremaster.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 6316539
+ * @bug 6316539 8136355
  * @summary Basic tests for TlsRsaPremasterSecret generator
  * @author Andreas Sterbenz
  * @library ..
@@ -34,6 +34,7 @@
  */
 
 import java.security.Provider;
+import java.security.InvalidAlgorithmParameterException;
 import javax.crypto.KeyGenerator;
 import javax.crypto.SecretKey;
 import sun.security.internal.spec.TlsRsaPremasterSecretParameterSpec;
@@ -61,7 +62,7 @@
             System.out.println("OK: " + e);
         }
 
-        int[] protocolVersions = {0x0300, 0x0301, 0x0302, 0x0400};
+        int[] protocolVersions = {0x0300, 0x0301, 0x0302};
         for (int clientVersion : protocolVersions) {
             for (int serverVersion : protocolVersions) {
                 test(kg, clientVersion, serverVersion);
@@ -81,8 +82,18 @@
                 "Testing RSA pre-master secret key generation between " +
                 "client (0x%04X) and server(0x%04X)%n",
                 clientVersion, serverVersion);
-        kg.init(new TlsRsaPremasterSecretParameterSpec(
+        try {
+            kg.init(new TlsRsaPremasterSecretParameterSpec(
                                     clientVersion, serverVersion));
+        } catch (InvalidAlgorithmParameterException iape) {
+            // S12 removed support for SSL v3.0
+            if (clientVersion == 0x300 || serverVersion == 0x300) {
+                System.out.println("Skip testing SSLv3 due to no support");
+                return;
+            }
+            // unexpected, pass it up
+            throw iape;
+        }
         SecretKey key = kg.generateKey();
         byte[] encoded = key.getEncoded();
         if (encoded != null) {  // raw key material may be not extractable
--- a/jdk/test/sun/security/smartcardio/README.txt	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/smartcardio/README.txt	Fri Sep 30 09:28:18 2016 -0700
@@ -1,17 +1,17 @@
 
 Rough hints for setting up MUSCLE on Solaris:
 
-Make sure you have libusb, usually in /usr/sfw:
+Make sure you have libusb, usually in /usr/lib:
 
-ls -l /usr/sfw/lib/libusb.so
-lrwxrwxrwx   1 root     other         11 Jan 12 16:02 /usr/sfw/lib/libusb.so -> libusb.so.1
+ls -l /usr/lib/libusb.so
+lrwxrwxrwx   1 root     other         11 Jan 12 16:02 /usr/lib/libusb.so -> libusb.so.1
 
 Get PCSC and CCID.
 -rwx------   1 user staff     529540 Jun 16 18:24 ccid-1.0.1.tar.gz
 -rwx------   1 user staff     842654 Jun 16 18:24 pcsc-lite-1.3.1.tar.gz
 
 Unpack pcsc
-Run ./configure --enable-libusb=/usr/sfw (??)
+Run ./configure --enable-libusb (??)
 gnumake
 Make /usr/local writeable for user
 gnumake install
--- a/jdk/test/sun/security/smartcardio/TestChannel.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/smartcardio/TestChannel.java	Fri Sep 30 09:28:18 2016 -0700
@@ -21,11 +21,12 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 6239117
  * @summary test logical channels work
  * @author Andreas Sterbenz
+ * @modules java.smartcardio/javax.smartcardio
  * @run main/manual TestChannel
  */
 
--- a/jdk/test/sun/security/smartcardio/TestConnect.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/smartcardio/TestConnect.java	Fri Sep 30 09:28:18 2016 -0700
@@ -21,11 +21,12 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 6293769 6294527 6309280
  * @summary test connect() works
  * @author Andreas Sterbenz
+ * @modules java.smartcardio/javax.smartcardio
  * @run main/manual TestConnect
  */
 
--- a/jdk/test/sun/security/smartcardio/TestConnectAgain.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/smartcardio/TestConnectAgain.java	Fri Sep 30 09:28:18 2016 -0700
@@ -21,11 +21,12 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 6239117
  * @summary test connect works correctly if called multiple times/card removed
  * @author Andreas Sterbenz
+ * @modules java.smartcardio/javax.smartcardio
  * @run main/manual TestConnectAgain
  */
 
--- a/jdk/test/sun/security/smartcardio/TestControl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/smartcardio/TestControl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -21,11 +21,12 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 6239117 6470320
  * @summary test if transmitControlCommand() works
  * @author Andreas Sterbenz
+ * @modules java.smartcardio/javax.smartcardio
  * @run main/manual TestControl
  */
 
--- a/jdk/test/sun/security/smartcardio/TestDefault.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/smartcardio/TestDefault.java	Fri Sep 30 09:28:18 2016 -0700
@@ -21,11 +21,12 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 6327047
  * @summary verify that TerminalFactory.getDefault() works
  * @author Andreas Sterbenz
+ * @modules java.smartcardio/javax.smartcardio
  * @run main/manual TestDefault
  */
 
--- a/jdk/test/sun/security/smartcardio/TestDirect.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/smartcardio/TestDirect.java	Fri Sep 30 09:28:18 2016 -0700
@@ -21,10 +21,11 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 8046343
  * @summary Make sure that direct protocol is available
+ * @modules java.smartcardio/javax.smartcardio
  * @run main/manual TestDirect
  */
 
--- a/jdk/test/sun/security/smartcardio/TestExclusive.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/smartcardio/TestExclusive.java	Fri Sep 30 09:28:18 2016 -0700
@@ -21,11 +21,12 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 6239117
  * @summary verify that beginExclusive()/endExclusive() works
  * @author Andreas Sterbenz
+ * @modules java.smartcardio/javax.smartcardio
  * @run main/manual TestExclusive
  */
 
--- a/jdk/test/sun/security/smartcardio/TestMultiplePresent.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/smartcardio/TestMultiplePresent.java	Fri Sep 30 09:28:18 2016 -0700
@@ -21,11 +21,12 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 6239117 6445367
  * @summary test that CardTerminals.waitForCard() works
  * @author Andreas Sterbenz
+ * @modules java.smartcardio/javax.smartcardio
  * @run main/manual TestMultiplePresent
  */
 
--- a/jdk/test/sun/security/smartcardio/TestPresent.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/smartcardio/TestPresent.java	Fri Sep 30 09:28:18 2016 -0700
@@ -21,11 +21,12 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 6293769 6294527
  * @summary test that the isCardPresent()/waitForX() APIs work correctly
  * @author Andreas Sterbenz
+ * @modules java.smartcardio/javax.smartcardio
  * @run main/manual TestPresent
  */
 
--- a/jdk/test/sun/security/smartcardio/TestTransmit.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/smartcardio/TestTransmit.java	Fri Sep 30 09:28:18 2016 -0700
@@ -21,11 +21,12 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 6293769 6294527
  * @summary test transmit() works
  * @author Andreas Sterbenz
+ * @modules java.smartcardio/javax.smartcardio
  * @run main/manual TestTransmit
  */
 
--- a/jdk/test/sun/security/ssl/SocketCreation/SocketCreation.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/ssl/SocketCreation/SocketCreation.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -139,7 +139,7 @@
             (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
 
         System.out.println("Server: Will call createServerSocket(int)");
-        ServerSocket sslServerSocket = sslssf.createServerSocket(serverPort);
+        ServerSocket sslServerSocket = sslssf.createServerSocket(0);
         serverPort = sslServerSocket.getLocalPort();
 
         System.out.println("Server: Will accept on SSL server socket...");
@@ -157,7 +157,7 @@
             (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
 
         System.out.println("Server: Will call createServerSocket(int, int)");
-        ServerSocket sslServerSocket = sslssf.createServerSocket(serverPort,
+        ServerSocket sslServerSocket = sslssf.createServerSocket(0,
                                                                  1);
         serverPort = sslServerSocket.getLocalPort();
 
@@ -177,7 +177,7 @@
 
         System.out.println("Server: Will call createServerSocket(int, " +
                            " int, InetAddress)");
-        ServerSocket sslServerSocket = sslssf.createServerSocket(serverPort,
+        ServerSocket sslServerSocket = sslssf.createServerSocket(0,
                                          1,
                                          InetAddress.getByName("localhost"));
         serverPort = sslServerSocket.getLocalPort();
@@ -203,14 +203,15 @@
         if (sslServerSocket.isBound())
             throw new Exception("Server socket is already bound!");
 
-        System.out.println("Server: Will bind SSL server socket to port " +
-                           serverPort + "...");
-
-        sslServerSocket.bind(new java.net.InetSocketAddress(serverPort));
+        sslServerSocket.bind(new java.net.InetSocketAddress(0));
 
         if (!sslServerSocket.isBound())
             throw new Exception("Server socket is not bound!");
 
+        serverPort = sslServerSocket.getLocalPort();
+        System.out.println("Server: Bound SSL server socket to port " +
+                serverPort + "...");
+
         serverReady = true;
 
         System.out.println("Server: Will accept on SSL server socket...");
@@ -224,11 +225,10 @@
         SSLSocketFactory sslsf =
             (SSLSocketFactory) SSLSocketFactory.getDefault();
 
-        System.out.println("Server: Will create normal server socket bound"
-                           + " to port " + serverPort + "...");
-
-        ServerSocket ss = new ServerSocket(serverPort);
+        ServerSocket ss = new ServerSocket(0);
         serverPort = ss.getLocalPort();
+        System.out.println("Server: Created normal server socket bound"
+                + " to port " + serverPort + "...");
         System.out.println("Server: Will accept on server socket...");
         serverReady = true;
         Socket s = ss.accept();
--- a/jdk/test/sun/security/tools/keytool/KeyToolTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/sun/security/tools/keytool/KeyToolTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1761,7 +1761,7 @@
         //PKCS#11 tests
 
         //   1. sccs edit cert8.db key3.db
-        //Runtime.getRuntime().exec("/usr/ccs/bin/sccs edit cert8.db key3.db");
+        //Runtime.getRuntime().exec("/usr/bin/sccs edit cert8.db key3.db");
         testOK("", p11Arg + ("-storepass test12 -genkey -alias genkey" +
                 " -dname cn=genkey -keysize 512 -keyalg rsa"));
         testOK("", p11Arg + "-storepass test12 -list");
@@ -1781,7 +1781,7 @@
         testOK("", p11Arg + "-storepass test12 -list");
         assertTrue(out.indexOf("Your keystore contains 0 entries") != -1);
         //(check for empty database listing)
-        //Runtime.getRuntime().exec("/usr/ccs/bin/sccs unedit cert8.db key3.db");
+        //Runtime.getRuntime().exec("/usr/bin/sccs unedit cert8.db key3.db");
         remove("genkey.cert");
         remove("genkey.certreq");
         //  12. sccs unedit cert8.db key3.db
--- a/jdk/test/tools/jlink/JLinkTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/tools/jlink/JLinkTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -150,6 +150,43 @@
         }
 
         {
+            String moduleName = "m_8165735"; // JDK-8165735
+            helper.generateDefaultJModule(moduleName+"dependency").assertSuccess();
+            Path jmod = helper.generateDefaultJModule(moduleName, moduleName+"dependency").assertSuccess();
+            JImageGenerator.getJLinkTask()
+                    .modulePath(helper.defaultModulePath())
+                    .repeatedModulePath(".") // second --module-path overrides the first one
+                    .output(helper.createNewImageDir(moduleName))
+                    .addMods(moduleName)
+                    // second --module-path does not have that module
+                    .call().assertFailure("Error: Module m_8165735 not found");
+
+            JImageGenerator.getJLinkTask()
+                    .modulePath(".") // first --module-path overridden later
+                    .repeatedModulePath(helper.defaultModulePath())
+                    .output(helper.createNewImageDir(moduleName))
+                    .addMods(moduleName)
+                    // second --module-path has that module
+                    .call().assertSuccess();
+
+            JImageGenerator.getJLinkTask()
+                    .modulePath(helper.defaultModulePath())
+                    .output(helper.createNewImageDir(moduleName))
+                    .limitMods(moduleName)
+                    .repeatedLimitMods("java.base") // second --limit-modules overrides first
+                    .addMods(moduleName)
+                    .call().assertFailure("Error: Module m_8165735dependency not found, required by m_8165735");
+
+            JImageGenerator.getJLinkTask()
+                    .modulePath(helper.defaultModulePath())
+                    .output(helper.createNewImageDir(moduleName))
+                    .limitMods("java.base")
+                    .repeatedLimitMods(moduleName) // second --limit-modules overrides first
+                    .addMods(moduleName)
+                    .call().assertSuccess();
+        }
+
+        {
             // Help
             StringWriter writer = new StringWriter();
             jdk.tools.jlink.internal.Main.run(new String[]{"--help"}, new PrintWriter(writer));
--- a/jdk/test/tools/launcher/RunpathTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/tools/launcher/RunpathTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -40,7 +40,7 @@
     }
 
     final String findElfReader() {
-        String[] paths = {"/bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/ccs/bin"};
+        String[] paths = {"/usr/sbin", "/usr/bin"};
         final String cmd = isSolaris ? "elfdump" : "readelf";
         for (String x : paths) {
             File p = new File(x);
--- a/jdk/test/tools/launcher/TooSmallStackSize.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/tools/launcher/TooSmallStackSize.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,6 +35,11 @@
  * stack size for the platform (as provided by the JVM error message when a very
  * small stack is used), and then verify that the JVM can be launched with that stack
  * size without a crash or any error messages.
+ *
+ * Note: The '-Xss<size>' and '-XX:ThreadStackSize=<k-bytes>' options
+ * both control Java thread stack size. This repo's version of the test
+ * exercises the '-Xss' option. The hotspot repo's version of the test
+ * exercises the '-XX:ThreadStackSize' VM option.
  */
 
 public class TooSmallStackSize extends TestHelper {
@@ -59,7 +64,7 @@
     static String getMinStackAllowed(TestResult tr) {
         /*
          * The JVM output will contain in one of the lines:
-         *   "The stack size specified is too small, Specify at least 100k"
+         *   "The Java thread stack size specified is too small. Specify at least 100k"
          * Although the actual size will vary. We need to extract this size
          * string from the output and return it.
          */
@@ -73,6 +78,9 @@
             }
         }
 
+        System.out.println("Expect='" + matchStr + "'");
+        System.out.println("Actual:");
+        printTestOutput(tr);
         System.out.println("FAILED: Could not get the stack size from the output");
         throw new RuntimeException("test fails");
     }
@@ -96,11 +104,15 @@
             System.out.println("PASSED: got no error message with stack size of " + stackSize);
             min_stack_allowed = stackSize;
         } else {
-            if (tr.contains("The stack size specified is too small")) {
+            String matchStr = "The Java thread stack size specified is too small";
+            if (tr.contains(matchStr)) {
                 System.out.println("PASSED: got expected error message with stack size of " + stackSize);
                 min_stack_allowed = getMinStackAllowed(tr);
             } else {
                 // Likely a crash
+                System.out.println("Expect='" + matchStr + "'");
+                System.out.println("Actual:");
+                printTestOutput(tr);
                 System.out.println("FAILED: Did not get expected error message with stack size of " + stackSize);
                 throw new RuntimeException("test fails");
             }
@@ -123,6 +135,8 @@
             System.out.println("PASSED: VM launched with minimum allowed stack size of " + stackSize);
         } else {
             // Likely a crash
+            System.out.println("Test output:");
+            printTestOutput(tr);
             System.out.println("FAILED: VM failed to launch with minimum allowed stack size of " + stackSize);
             throw new RuntimeException("test fails");
         }
--- a/jdk/test/tools/launcher/modules/addmods/AddModsTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/tools/launcher/modules/addmods/AddModsTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -31,6 +31,7 @@
  * @summary Basic test for java --add-modules
  */
 
+import java.io.File;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 
@@ -224,6 +225,27 @@
 
 
     /**
+     * Tests {@code --add-modules} be specified more than once.
+     */
+    public void testWithMultipleAddModules() throws Exception {
+
+        String modulepath = MODS1_DIR.toString() + File.pathSeparator +
+                                MODS2_DIR.toString();
+        int exitValue
+            = executeTestJava("--module-path", modulepath,
+            "--add-modules", LOGGER_MODULE,
+            "--add-modules", TEST_MODULE,
+            "-m", TEST_MID,
+            "logger.Logger")
+            .outputTo(System.out)
+            .errorTo(System.out)
+            .getExitValue();
+
+        assertTrue(exitValue == 0);
+    }
+
+
+    /**
      * Attempt to run with a bad module name specified to --add-modules
      */
     public void testRunWithBadAddMods() throws Exception {
--- a/jdk/test/tools/lib/tests/JImageGenerator.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/tools/lib/tests/JImageGenerator.java	Fri Sep 30 09:28:18 2016 -0700
@@ -564,6 +564,10 @@
         private final List<String> limitMods = new ArrayList<>();
         private final List<String> options = new ArrayList<>();
         private String modulePath;
+        // if you want to specifiy repeated --module-path option
+        private String repeatedModulePath;
+        // if you want to specifiy repeated --limit-modules option
+        private String repeatedLimitMods;
         private Path output;
         private Path existing;
 
@@ -572,6 +576,11 @@
             return this;
         }
 
+        public JLinkTask repeatedModulePath(String modulePath) {
+            this.repeatedModulePath = modulePath;
+            return this;
+        }
+
         public JLinkTask addJars(Path jars) {
             this.jars.add(jars);
             return this;
@@ -597,6 +606,11 @@
             return this;
         }
 
+        public JLinkTask repeatedLimitMods(String modules) {
+            this.repeatedLimitMods = modules;
+            return this;
+        }
+
         public JLinkTask output(Path output) {
             this.output = output;
             return this;
@@ -639,6 +653,10 @@
                 options.add(LIMIT_MODULES_OPTION);
                 options.add(limitMods.stream().collect(Collectors.joining(",")));
             }
+            if (repeatedLimitMods != null) {
+                options.add(LIMIT_MODULES_OPTION);
+                options.add(repeatedLimitMods);
+            }
             if (!jars.isEmpty() || !jmods.isEmpty()) {
                 options.add(MODULE_PATH_OPTION);
                 options.add(modulePath());
@@ -647,6 +665,10 @@
                 options.add(MODULE_PATH_OPTION);
                 options.add(modulePath);
             }
+            if (repeatedModulePath != null) {
+                options.add(MODULE_PATH_OPTION);
+                options.add(repeatedModulePath);
+            }
             if (!pluginModulePath.isEmpty()) {
                 options.add(PLUGIN_MODULE_PATH);
                 options.add(toPath(pluginModulePath));
--- a/jdk/test/tools/pack200/Pack200Test.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/jdk/test/tools/pack200/Pack200Test.java	Fri Sep 30 09:28:18 2016 -0700
@@ -24,6 +24,7 @@
  /*
   * @test
   * @bug 6521334 6712743 8007902 8151901
+  * @requires (sun.arch.data.model == "64" & os.maxMemory >= 4g)
   * @summary test general packer/unpacker functionality
   *          using native and java unpackers
   * @compile -XDignore.symbol.file Utils.java Pack200Test.java
--- a/langtools/.hgtags	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/.hgtags	Fri Sep 30 09:28:18 2016 -0700
@@ -379,3 +379,4 @@
 f08683786207a48b652266b3b7b908e6c863c3fc jdk-9+134
 af5eb8f3ffd21288305a54ea177ffad75021a741 jdk-9+135
 c8f02f0ecbd7cd6700f47416e4b7e9d5ec20ad77 jdk-9+136
+dd56c243c199a540c9f1fbff4855f0934b32a9d0 jdk-9+137
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java	Fri Sep 30 09:28:18 2016 -0700
@@ -383,18 +383,16 @@
         JCTree tree = (JCTree) path.getLeaf();
         Symbol sym = TreeInfo.symbolFor(tree);
         if (sym == null) {
-            if (TreeInfo.isDeclaration(tree)) {
-                for (TreePath p = path; p != null; p = p.getParentPath()) {
-                    JCTree t = (JCTree) p.getLeaf();
-                    if (t.hasTag(JCTree.Tag.CLASSDEF)) {
-                        JCClassDecl ct = (JCClassDecl) t;
-                        if (ct.sym != null) {
-                            if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
-                                attr.attribClass(ct.pos(), ct.sym);
-                                sym = TreeInfo.symbolFor(tree);
-                            }
-                            break;
+            for (TreePath p = path; p != null; p = p.getParentPath()) {
+                JCTree t = (JCTree) p.getLeaf();
+                if (t.hasTag(JCTree.Tag.CLASSDEF)) {
+                    JCClassDecl ct = (JCClassDecl) t;
+                    if (ct.sym != null) {
+                        if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
+                            attr.attribClass(ct.pos(), ct.sym);
+                            sym = TreeInfo.symbolFor(tree);
                         }
+                        break;
                     }
                 }
             }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java	Fri Sep 30 09:28:18 2016 -0700
@@ -134,7 +134,7 @@
     /** Flag is set for nested classes that do not access instance members
      *  or `this' of an outer class and therefore don't need to be passed
      *  a this$n reference.  This value is currently set only for anonymous
-     *  classes in superclass constructor calls and only for pre 1.4 targets.
+     *  classes in superclass constructor calls.
      *  todo: use this value for optimizing away this$n parameters in
      *  other cases.
      */
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Fri Sep 30 09:28:18 2016 -0700
@@ -789,7 +789,7 @@
         classExtends(final List<TypePathEntry> location,
                      final JCLambda onLambda,
                      final int pos) {
-        return classExtends(location, onLambda, -1, pos);
+        return classExtends(location, onLambda, 65535, pos);
     }
 
     /**
@@ -821,7 +821,7 @@
      * @param pos The position from the associated tree node.
      */
     public static TypeAnnotationPosition classExtends(final int pos) {
-        return classExtends(-1, pos);
+        return classExtends(65535, pos);
     }
 
     /**
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Sep 30 09:28:18 2016 -0700
@@ -921,13 +921,11 @@
                 c.complete();
 
                 // If this class appears as an anonymous class
-                // in a superclass constructor call where
-                // no explicit outer instance is given,
+                // in a superclass constructor call
                 // disable implicit outer instance from being passed.
                 // (This would be an illegal access to "this before super").
                 if (env.info.isSelfCall &&
-                        env.tree.hasTag(NEWCLASS) &&
-                        ((JCNewClass)env.tree).encl == null) {
+                        env.tree.hasTag(NEWCLASS)) {
                     c.flags_field |= NOOUTERTHIS;
                 }
                 attribClass(tree.pos(), c);
@@ -1453,7 +1451,7 @@
             try {
                 close = rs.resolveQualifiedMethod(pos,
                         env,
-                        resource,
+                        types.skipTypeVars(resource, false),
                         names.close,
                         List.<Type>nil(),
                         List.<Type>nil());
@@ -2329,6 +2327,9 @@
     /** Make an attributed null check tree.
      */
     public JCExpression makeNullCheck(JCExpression arg) {
+        // optimization: new Outer() can never be null; skip null check
+        if (arg.getTag() == NEWCLASS)
+            return arg;
         // optimization: X.this is never null; skip null check
         Name name = TreeInfo.name(arg);
         if (name == names._this || name == names._super) return arg;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1098,7 +1098,7 @@
                     if (types.asSuper(sup, syms.autoCloseableType.tsym) != null) {
                         Symbol closeMethod = rs.resolveQualifiedMethod(tree,
                                 attrEnv,
-                                sup,
+                                types.skipTypeVars(sup, false),
                                 names.close,
                                 List.<Type>nil(),
                                 List.<Type>nil());
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java	Fri Sep 30 09:28:18 2016 -0700
@@ -287,6 +287,7 @@
 
             case MULTIRELEASE:
                 multiReleaseValue = value;
+                locations.setMultiReleaseValue(value);
                 return true;
 
             default:
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Fri Sep 30 09:28:18 2016 -0700
@@ -130,6 +130,7 @@
 
     Map<Path, FileSystem> fileSystems = new LinkedHashMap<>();
     List<Closeable> closeables = new ArrayList<>();
+    private Map<String,String> fsEnv = Collections.emptyMap();
 
     Locations() {
         initHandlers();
@@ -207,6 +208,10 @@
         return entries;
     }
 
+    public void setMultiReleaseValue(String multiReleaseValue) {
+        fsEnv = Collections.singletonMap("multi-release", multiReleaseValue);
+    }
+
     /**
      * Utility class to help evaluate a path option. Duplicate entries are ignored, jar class paths
      * can be expanded.
@@ -1047,7 +1052,8 @@
                 }
 
                 if (p.getFileName().toString().endsWith(".jar") && fsInfo.exists(p)) {
-                    try (FileSystem fs = FileSystems.newFileSystem(p, null)) {
+                    URI uri = URI.create("jar:" + p.toUri());
+                    try (FileSystem fs = FileSystems.newFileSystem(uri, fsEnv, null)) {
                         Path moduleInfoClass = fs.getPath("module-info.class");
                         if (Files.exists(moduleInfoClass)) {
                             String moduleName = readModuleName(moduleInfoClass);
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1503,13 +1503,35 @@
                 }
             }
             public void visitClassDef(JCClassDecl node) {
+                super.visitClassDef(node);
+                // remove generated constructor that may have been added during attribution:
+                List<JCTree> beforeConstructor = List.nil();
+                List<JCTree> defs = node.defs;
+                while (defs.nonEmpty() && !defs.head.hasTag(Tag.METHODDEF)) {
+                    beforeConstructor = beforeConstructor.prepend(defs.head);
+                    defs = defs.tail;
+                }
+                if (defs.nonEmpty() &&
+                    (((JCMethodDecl) defs.head).mods.flags & Flags.GENERATEDCONSTR) != 0) {
+                    defs = defs.tail;
+                    while (beforeConstructor.nonEmpty()) {
+                        defs = defs.prepend(beforeConstructor.head);
+                        beforeConstructor = beforeConstructor.tail;
+                    }
+                    node.defs = defs;
+                }
                 if (node.sym != null) {
                     node.sym.completer = new ImplicitCompleter(topLevel);
                 }
                 node.sym = null;
-                super.visitClassDef(node);
             }
             public void visitMethodDef(JCMethodDecl node) {
+                // remove super constructor call that may have been added during attribution:
+                if (TreeInfo.isConstructor(node) && node.sym != null && node.sym.owner.isEnum() &&
+                    node.body.stats.nonEmpty() && TreeInfo.isSuperCall(node.body.stats.head) &&
+                    node.body.stats.head.pos == node.body.pos) {
+                    node.body.stats = node.body.stats.tail;
+                }
                 node.sym = null;
                 super.visitMethodDef(node);
             }
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractMemberWriter.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractMemberWriter.java	Fri Sep 30 09:28:18 2016 -0700
@@ -424,12 +424,15 @@
             Content tbody = new HtmlTree(HtmlTag.TBODY);
             boolean altColor = true;
             for (Element member : deprmembers) {
-                HtmlTree td = HtmlTree.TD(HtmlStyle.colOne, getDeprecatedLink(member));
+                HtmlTree thRow = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst, getDeprecatedLink(member));
+                HtmlTree tr = HtmlTree.TR(thRow);
+                HtmlTree td = new HtmlTree(HtmlTag.TD);
+                td.addStyle(HtmlStyle.colLast);
                 List<? extends DocTree> deprTrees = utils.getBlockTags(member, DocTree.Kind.DEPRECATED);
                 if (!deprTrees.isEmpty()) {
                     writer.addInlineDeprecatedComment(member, deprTrees.get(0), td);
                 }
-                HtmlTree tr = HtmlTree.TR(td);
+                tr.addContent(td);
                 tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
                 altColor = !altColor;
                 tbody.addContent(tr);
@@ -477,8 +480,9 @@
                 tdFirst.addStyle(HtmlStyle.colFirst);
                 writer.addSummaryType(this, element, tdFirst);
                 tr.addContent(tdFirst);
-                HtmlTree tdLast = new HtmlTree(HtmlTag.TD);
-                tdLast.addStyle(HtmlStyle.colLast);
+                HtmlTree thType = new HtmlTree(HtmlTag.TH);
+                thType.addStyle(HtmlStyle.colSecond);
+                thType.addAttr(HtmlAttr.SCOPE, "row");
                 if (te != null
                         && !utils.isConstructor(element)
                         && !utils.isClass(element)
@@ -487,14 +491,17 @@
                     HtmlTree name = new HtmlTree(HtmlTag.SPAN);
                     name.addStyle(HtmlStyle.typeNameLabel);
                     name.addContent(name(te) + ".");
-                    tdLast.addContent(name);
+                    thType.addContent(name);
                 }
                 addSummaryLink(utils.isClass(element) || utils.isInterface(element)
                         ? LinkInfoImpl.Kind.CLASS_USE
                         : LinkInfoImpl.Kind.MEMBER,
-                    te, element, tdLast);
-                writer.addSummaryLinkComment(this, element, tdLast);
-                tr.addContent(tdLast);
+                        te, element, thType);
+                tr.addContent(thType);
+                HtmlTree tdDesc = new HtmlTree(HtmlTag.TD);
+                tdDesc.addStyle(HtmlStyle.colLast);
+                writer.addSummaryLinkComment(this, element, tdDesc);
+                tr.addContent(tdDesc);
                 tbody.addContent(tr);
             }
             table.addContent(tbody);
@@ -557,12 +564,15 @@
         HtmlTree tdSummaryType = new HtmlTree(HtmlTag.TD);
         tdSummaryType.addStyle(HtmlStyle.colFirst);
         writer.addSummaryType(this, member, tdSummaryType);
-        HtmlTree tdSummary = new HtmlTree(HtmlTag.TD);
-        setSummaryColumnStyle(tdSummary);
-        addSummaryLink(tElement, member, tdSummary);
-        writer.addSummaryLinkComment(this, member, firstSentenceTags, tdSummary);
         HtmlTree tr = HtmlTree.TR(tdSummaryType);
-        tr.addContent(tdSummary);
+        HtmlTree thSummaryLink = new HtmlTree(HtmlTag.TH);
+        setSummaryColumnStyleAndScope(thSummaryLink);
+        addSummaryLink(tElement, member, thSummaryLink);
+        tr.addContent(thSummaryLink);
+        HtmlTree tdDesc = new HtmlTree(HtmlTag.TD);
+        tdDesc.addStyle(HtmlStyle.colLast);
+        writer.addSummaryLinkComment(this, member, firstSentenceTags, tdDesc);
+        tr.addContent(tdDesc);
         if (utils.isMethod(member) && !utils.isAnnotationType(member)) {
             int methodType = utils.isStatic(member) ? MethodTypes.STATIC.value() :
                     MethodTypes.INSTANCE.value();
@@ -612,12 +622,13 @@
     }
 
     /**
-     * Set the style for the summary column.
+     * Set the style and scope attribute for the summary column.
      *
-     * @param tdTree the column for which the style will be set
+     * @param thTree the column for which the style and scope attribute will be set
      */
-    public void setSummaryColumnStyle(HtmlTree tdTree) {
-        tdTree.addStyle(HtmlStyle.colLast);
+    public void setSummaryColumnStyleAndScope(HtmlTree thTree) {
+        thTree.addStyle(HtmlStyle.colSecond);
+        thTree.addAttr(HtmlAttr.SCOPE, "row");
     }
 
     /**
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeFieldWriterImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeFieldWriterImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -25,8 +25,6 @@
 
 package jdk.javadoc.internal.doclets.formats.html;
 
-import java.io.*;
-
 import java.util.Arrays;
 import java.util.List;
 
@@ -222,9 +220,7 @@
      */
     public List<String> getSummaryTableHeader(Element member) {
         List<String> header = Arrays.asList(writer.getModifierTypeHeader(),
-                configuration.getText("doclet.0_and_1",
-                        configuration.getText("doclet.Fields"),
-                        configuration.getText("doclet.Description")));
+                resources.getText("doclet.Fields"), resources.getText("doclet.Description"));
         return header;
     }
 
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeOptionalMemberWriterImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeOptionalMemberWriterImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -133,9 +133,8 @@
      */
     public List<String> getSummaryTableHeader(Element member) {
         List<String> header = Arrays.asList(writer.getModifierTypeHeader(),
-                configuration.getText("doclet.0_and_1",
-                        configuration.getText("doclet.Annotation_Type_Optional_Member"),
-                        configuration.getText("doclet.Description")));
+                resources.getText("doclet.Annotation_Type_Optional_Member"),
+                resources.getText("doclet.Description"));
         return header;
     }
 
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeRequiredMemberWriterImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeRequiredMemberWriterImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -25,7 +25,6 @@
 
 package jdk.javadoc.internal.doclets.formats.html;
 
-import java.io.*;
 import java.util.Arrays;
 import java.util.List;
 
@@ -223,9 +222,7 @@
      */
     public List<String> getSummaryTableHeader(Element member) {
         List<String> header = Arrays.asList(writer.getModifierTypeHeader(),
-                configuration.getText("doclet.0_and_1",
-                        configuration.getText("doclet.Annotation_Type_Required_Member"),
-                        configuration.getText("doclet.Description")));
+                resources.getText("doclet.Annotation_Type_Required_Member"), resources.getText("doclet.Description"));
         return header;
     }
 
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassUseWriter.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassUseWriter.java	Fri Sep 30 09:28:18 2016 -0700
@@ -330,8 +330,8 @@
             HtmlTree tr = new HtmlTree(HtmlTag.TR);
             tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
             altColor = !altColor;
-            Content tdFirst = HtmlTree.TD(HtmlStyle.colFirst, getPackageLink(pkg));
-            tr.addContent(tdFirst);
+            Content thFirst = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst, getPackageLink(pkg));
+            tr.addContent(thFirst);
             HtmlTree tdLast = new HtmlTree(HtmlTag.TD);
             tdLast.addStyle(HtmlStyle.colLast);
             addSummaryComment(pkg, tdLast);
@@ -380,9 +380,9 @@
      * @param contentTree the content tree to which the package use information will be added
      */
     protected void addPackageUse(PackageElement pkg, Content contentTree) {
-        Content tdFirst = HtmlTree.TD(HtmlStyle.colFirst,
+        Content thFirst = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst,
                 getHyperLink(getPackageAnchorName(pkg), new StringContent(utils.getPackageName(pkg))));
-        contentTree.addContent(tdFirst);
+        contentTree.addContent(thFirst);
         HtmlTree tdLast = new HtmlTree(HtmlTag.TD);
         tdLast.addStyle(HtmlStyle.colLast);
         addSummaryComment(pkg, tdLast);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstantsSummaryWriterImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstantsSummaryWriterImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -25,7 +25,6 @@
 
 package jdk.javadoc.internal.doclets.formats.html;
 
-import java.io.*;
 import java.util.*;
 
 import javax.lang.model.element.Modifier;
@@ -332,7 +331,7 @@
         Content nameContent = getDocLink(LinkInfoImpl.Kind.CONSTANT_SUMMARY,
                 member, member.getSimpleName(), false);
         Content code = HtmlTree.CODE(nameContent);
-        return HtmlTree.TD(code);
+        return HtmlTree.TH_ROW_SCOPE(HtmlStyle.colSecond, code);
     }
 
     /**
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstructorWriterImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstructorWriterImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -25,13 +25,13 @@
 
 package jdk.javadoc.internal.doclets.formats.html;
 
-import java.io.*;
 import java.util.*;
 
 import javax.lang.model.element.Element;
 import javax.lang.model.element.ExecutableElement;
 import javax.lang.model.element.TypeElement;
 
+import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
@@ -168,11 +168,13 @@
      * {@inheritDoc}
      */
     @Override
-    public void setSummaryColumnStyle(HtmlTree tdTree) {
-        if (foundNonPubConstructor)
-            tdTree.addStyle(HtmlStyle.colLast);
-        else
-            tdTree.addStyle(HtmlStyle.colOne);
+    public void setSummaryColumnStyleAndScope(HtmlTree thTree) {
+        if (foundNonPubConstructor) {
+            thTree.addStyle(HtmlStyle.colSecond);
+        } else {
+            thTree.addStyle(HtmlStyle.colFirst);
+        }
+        thTree.addAttr(HtmlAttr.SCOPE, "row");
     }
 
     /**
@@ -267,9 +269,8 @@
         if (foundNonPubConstructor) {
             header.add(resources.getText("doclet.Modifier"));
         }
-        header.add(resources.getText("doclet.0_and_1",
-                resources.getText("doclet.Constructor"),
-                resources.getText("doclet.Description")));
+        header.add(resources.getText("doclet.Constructor"));
+        header.add(resources.getText("doclet.Description"));
         return header;
     }
 
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DeprecatedListWriter.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DeprecatedListWriter.java	Fri Sep 30 09:28:18 2016 -0700
@@ -261,14 +261,13 @@
         for (DeprElementKind kind : DeprElementKind.values()) {
             if (deprapi.hasDocumentation(kind)) {
                 addAnchor(deprapi, kind, div);
-                memberTableSummary =
-                        configuration.getText("doclet.Member_Table_Summary",
-                        configuration.getText(getHeadingKey(kind)),
-                        configuration.getText(getSummaryKey(kind)));
+                memberTableSummary
+                        = resources.getText("doclet.Member_Table_Summary",
+                                resources.getText(getHeadingKey(kind)),
+                                resources.getText(getSummaryKey(kind)));
                 List<String> memberTableHeader = new ArrayList<>();
-                memberTableHeader.add(configuration.getText("doclet.0_and_1",
-                        configuration.getText(getHeaderKey(kind)),
-                        configuration.getText("doclet.Description")));
+                memberTableHeader.add(resources.getText(getHeaderKey(kind)));
+                memberTableHeader.add(resources.getText("doclet.Description"));
                 if (kind == DeprElementKind.PACKAGE)
                     addPackageDeprecatedAPI(deprapi.getSet(kind),
                             getHeadingKey(kind), memberTableSummary, memberTableHeader, div);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriterImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriterImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -25,8 +25,7 @@
 
 package jdk.javadoc.internal.doclets.formats.html;
 
-import java.io.*;
-
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -34,6 +33,7 @@
 import javax.lang.model.element.TypeElement;
 import javax.lang.model.element.VariableElement;
 
+import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
@@ -214,9 +214,8 @@
      */
     @Override
     public List<String> getSummaryTableHeader(Element member) {
-        List<String> header = Arrays.asList(configuration.getText("doclet.0_and_1",
-                configuration.getText("doclet.Enum_Constant"),
-                configuration.getText("doclet.Description")));
+        List<String> header = Arrays.asList(resources.getText("doclet.Enum_Constant"),
+                resources.getText("doclet.Description"));
         return header;
     }
 
@@ -259,8 +258,9 @@
      * {@inheritDoc}
      */
     @Override
-    public void setSummaryColumnStyle(HtmlTree tdTree) {
-        tdTree.addStyle(HtmlStyle.colOne);
+    public void setSummaryColumnStyleAndScope(HtmlTree thTree) {
+        thTree.addStyle(HtmlStyle.colFirst);
+        thTree.addAttr(HtmlAttr.SCOPE, "row");
     }
 
     /**
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FieldWriterImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FieldWriterImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -25,7 +25,6 @@
 
 package jdk.javadoc.internal.doclets.formats.html;
 
-import java.io.*;
 import java.util.Arrays;
 import java.util.List;
 
@@ -215,9 +214,7 @@
     @Override
     public List<String> getSummaryTableHeader(Element member) {
         List<String> header = Arrays.asList(writer.getModifierTypeHeader(),
-            resources.getText("doclet.0_and_1",
-                    resources.getText("doclet.Field"),
-                    resources.getText("doclet.Description")));
+                resources.getText("doclet.Field"), resources.getText("doclet.Description"));
         return header;
     }
 
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java	Fri Sep 30 09:28:18 2016 -0700
@@ -405,7 +405,7 @@
                 }
                 Content classContent = getLink(new LinkInfoImpl(
                         configuration, LinkInfoImpl.Kind.PACKAGE, te));
-                Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
+                Content tdClass = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst, classContent);
                 HtmlTree tr = HtmlTree.TR(tdClass);
                 tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
                 altColor = !altColor;
@@ -942,16 +942,20 @@
         Content tr = new HtmlTree(HtmlTag.TR);
         final int size = header.size();
         Content tableHeader;
-        if (size == 1) {
+        if (size == 2) {
             tableHeader = new StringContent(header.get(0));
-            tr.addContent(HtmlTree.TH(HtmlStyle.colOne, scope, tableHeader));
+            tr.addContent(HtmlTree.TH(HtmlStyle.colFirst, scope, tableHeader));
+            tableHeader = new StringContent(header.get(1));
+            tr.addContent(HtmlTree.TH(HtmlStyle.colLast, scope, tableHeader));
             return tr;
         }
         for (int i = 0; i < size; i++) {
             tableHeader = new StringContent(header.get(i));
-            if(i == 0)
+            if (i == 0)
                 tr.addContent(HtmlTree.TH(HtmlStyle.colFirst, scope, tableHeader));
-            else if(i == (size - 1))
+            else if (i == 1)
+                tr.addContent(HtmlTree.TH(HtmlStyle.colSecond, scope, tableHeader));
+            else if (i == (size - 1))
                 tr.addContent(HtmlTree.TH(HtmlStyle.colLast, scope, tableHeader));
             else
                 tr.addContent(HtmlTree.TH(scope, tableHeader));
@@ -1062,13 +1066,16 @@
             boolean altColor = true;
             for (Element e : deprPkgs) {
                 PackageElement pkg = (PackageElement) e;
-                HtmlTree td = HtmlTree.TD(HtmlStyle.colOne,
+                HtmlTree thRow = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst,
                         getPackageLink(pkg, getPackageName(pkg)));
+                HtmlTree tr = HtmlTree.TR(thRow);
+                HtmlTree tdDesc = new HtmlTree(HtmlTag.TD);
+                tdDesc.addStyle(HtmlStyle.colLast);
                 List<? extends DocTree> tags = utils.getDeprecatedTrees(pkg);
                 if (!tags.isEmpty()) {
-                    addInlineDeprecatedComment(pkg, tags.get(0), td);
+                    addInlineDeprecatedComment(pkg, tags.get(0), tdDesc);
                 }
-                HtmlTree tr = HtmlTree.TR(td);
+                tr.addContent(tdDesc);
                 tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
                 altColor = !altColor;
                 tbody.addContent(tr);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/MethodWriterImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/MethodWriterImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -261,9 +261,7 @@
     @Override
     public List<String> getSummaryTableHeader(Element member) {
         List<String> header = Arrays.asList(writer.getModifierTypeHeader(),
-                resources.getText("doclet.0_and_1",
-                        resources.getText("doclet.Method"),
-                        resources.getText("doclet.Description")));
+                resources.getText("doclet.Method"), resources.getText("doclet.Description"));
         return header;
     }
 
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexWriter.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexWriter.java	Fri Sep 30 09:28:18 2016 -0700
@@ -159,11 +159,11 @@
         for (ModuleElement mdle : modules) {
             if (!mdle.isUnnamed()) {
                 Content moduleLinkContent = getModuleLink(mdle, new StringContent(mdle.getQualifiedName().toString()));
-                Content tdModule = HtmlTree.TD(HtmlStyle.colFirst, moduleLinkContent);
+                Content thModule = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst, moduleLinkContent);
                 HtmlTree tdSummary = new HtmlTree(HtmlTag.TD);
                 tdSummary.addStyle(HtmlStyle.colLast);
                 addSummaryComment(mdle, tdSummary);
-                HtmlTree tr = HtmlTree.TR(tdModule);
+                HtmlTree tr = HtmlTree.TR(thModule);
                 tr.addContent(tdSummary);
                 tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
                 tbody.addContent(tr);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -294,11 +294,11 @@
     public void addRequiresList(ModuleElement.RequiresDirective direct, Content tbody, boolean altColor) {
         ModuleElement m = direct.getDependency();
         Content moduleLinkContent = getModuleLink(m, new StringContent(m.getQualifiedName().toString()));
-        Content tdPackage = HtmlTree.TD(HtmlStyle.colFirst, moduleLinkContent);
+        Content thPackage = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst, moduleLinkContent);
         HtmlTree tdSummary = new HtmlTree(HtmlTag.TD);
         tdSummary.addStyle(HtmlStyle.colLast);
         addSummaryComment(m, tdSummary);
-        HtmlTree tr = HtmlTree.TR(tdPackage);
+        HtmlTree tr = HtmlTree.TR(thPackage);
         tr.addContent(tdSummary);
         tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
         tbody.addContent(tr);
@@ -347,27 +347,27 @@
     public void addExportedPackagesList(ModuleElement.ExportsDirective direct, Content tbody, boolean altColor) {
         PackageElement pkg = direct.getPackage();
         Content pkgLinkContent = getPackageLink(pkg, new StringContent(utils.getPackageName(pkg)));
-        Content tdPackage = HtmlTree.TD(HtmlStyle.colFirst, pkgLinkContent);
-        HtmlTree tdModules = new HtmlTree(HtmlTag.TD);
-        tdModules.addStyle(HtmlStyle.colSecond);
+        Content tdPackage = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst, pkgLinkContent);
+        HtmlTree thModules = new HtmlTree(HtmlTag.TD);
+        thModules.addStyle(HtmlStyle.colSecond);
         List<? extends ModuleElement> targetModules = direct.getTargetModules();
         if (targetModules != null) {
             List<? extends ModuleElement> mElements = direct.getTargetModules();
             for (int i = 0; i < mElements.size(); i++) {
                 if (i > 0) {
-                    tdModules.addContent(new HtmlTree(HtmlTag.BR));
+                    thModules.addContent(new HtmlTree(HtmlTag.BR));
                 }
                 ModuleElement m = mElements.get(i);
-                tdModules.addContent(new StringContent(m.getQualifiedName().toString()));
+                thModules.addContent(new StringContent(m.getQualifiedName().toString()));
             }
         } else {
-            tdModules.addContent(configuration.getText("doclet.All_Modules"));
+            thModules.addContent(configuration.getText("doclet.All_Modules"));
         }
         HtmlTree tdSummary = new HtmlTree(HtmlTag.TD);
         tdSummary.addStyle(HtmlStyle.colLast);
         addSummaryComment(pkg, tdSummary);
         HtmlTree tr = HtmlTree.TR(tdPackage);
-        tr.addContent(tdModules);
+        tr.addContent(thModules);
         tr.addContent(tdSummary);
         tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
         tbody.addContent(tr);
@@ -428,11 +428,11 @@
     public void addUsesList(ModuleElement.UsesDirective direct, Content tbody, boolean altColor) {
         TypeElement type = direct.getService();
         Content typeLinkContent = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.PACKAGE, type));
-        Content tdPackage = HtmlTree.TD(HtmlStyle.colFirst, typeLinkContent);
+        Content thPackage = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst, typeLinkContent);
         HtmlTree tdSummary = new HtmlTree(HtmlTag.TD);
         tdSummary.addStyle(HtmlStyle.colLast);
         addSummaryComment(type, tdSummary);
-        HtmlTree tr = HtmlTree.TR(tdPackage);
+        HtmlTree tr = HtmlTree.TR(thPackage);
         tr.addContent(tdSummary);
         tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
         tbody.addContent(tr);
@@ -463,18 +463,18 @@
         TypeElement srv = direct.getService();
         Content implLinkContent = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.PACKAGE, impl));
         Content srvLinkContent = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.PACKAGE, srv));
-        HtmlTree tdType = HtmlTree.TD(HtmlStyle.colFirst, srvLinkContent);
-        tdType.addContent(new HtmlTree(HtmlTag.BR));
-        tdType.addContent("(");
+        HtmlTree thType = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst, srvLinkContent);
+        thType.addContent(new HtmlTree(HtmlTag.BR));
+        thType.addContent("(");
         HtmlTree implSpan = HtmlTree.SPAN(HtmlStyle.implementationLabel, contents.implementation);
-        tdType.addContent(implSpan);
-        tdType.addContent(Contents.SPACE);
-        tdType.addContent(implLinkContent);
-        tdType.addContent(")");
+        thType.addContent(implSpan);
+        thType.addContent(Contents.SPACE);
+        thType.addContent(implLinkContent);
+        thType.addContent(")");
         HtmlTree tdDesc = new HtmlTree(HtmlTag.TD);
         tdDesc.addStyle(HtmlStyle.colLast);
         addSummaryComment(srv, tdDesc);
-        HtmlTree tr = HtmlTree.TR(tdType);
+        HtmlTree tr = HtmlTree.TR(thType);
         tr.addContent(tdDesc);
         tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
         tbody.addContent(tr);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NestedClassWriterImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NestedClassWriterImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -25,8 +25,6 @@
 
 package jdk.javadoc.internal.doclets.formats.html;
 
-import java.io.*;
-
 import java.util.Arrays;
 import java.util.List;
 
@@ -118,15 +116,11 @@
     public List<String> getSummaryTableHeader(Element member) {
         if (utils.isInterface(member)) {
             return Arrays.asList(writer.getModifierTypeHeader(),
-                configuration.getText("doclet.0_and_1",
-                    configuration.getText("doclet.Interface"),
-                    configuration.getText("doclet.Description")));
+                    resources.getText("doclet.Interface"), resources.getText("doclet.Description"));
 
         } else {
             return Arrays.asList(writer.getModifierTypeHeader(),
-                configuration.getText("doclet.0_and_1",
-                    configuration.getText("doclet.Class"),
-                    configuration.getText("doclet.Description")));
+                    resources.getText("doclet.Class"), resources.getText("doclet.Description"));
         }
     }
 
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java	Fri Sep 30 09:28:18 2016 -0700
@@ -151,11 +151,11 @@
             if (!pkg.isUnnamed()) {
                 if (!(configuration.nodeprecated && utils.isDeprecated(pkg))) {
                     Content packageLinkContent = getPackageLink(pkg, getPackageName(pkg));
-                    Content tdPackage = HtmlTree.TD(HtmlStyle.colFirst, packageLinkContent);
+                    Content thPackage = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst, packageLinkContent);
                     HtmlTree tdSummary = new HtmlTree(HtmlTag.TD);
                     tdSummary.addStyle(HtmlStyle.colLast);
                     addSummaryComment(pkg, tdSummary);
-                    HtmlTree tr = HtmlTree.TR(tdPackage);
+                    HtmlTree tr = HtmlTree.TR(thPackage);
                     tr.addContent(tdSummary);
                     tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
                     tbody.addContent(tr);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageUseWriter.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageUseWriter.java	Fri Sep 30 09:28:18 2016 -0700
@@ -187,9 +187,7 @@
      */
     protected void addClassList(Content contentTree) {
         List<String> classTableHeader = Arrays.asList(
-            configuration.getText("doclet.0_and_1",
-                    configuration.getText("doclet.Class"),
-                    configuration.getText("doclet.Description")));
+                resources.getText("doclet.Class"), resources.getText("doclet.Description"));
         for (String packageName : usingPackageToUsedClasses.keySet()) {
             PackageElement usingPackage = utils.elementUtils.getPackageElement(packageName);
             HtmlTree li = new HtmlTree(HtmlTag.LI);
@@ -234,10 +232,13 @@
         DocPath dp = pathString(usedClass,
                 DocPaths.CLASS_USE.resolve(DocPath.forName(utils, usedClass)));
         StringContent stringContent = new StringContent(utils.getSimpleName(usedClass));
-        Content td = HtmlTree.TD(HtmlStyle.colOne,
+        Content thType = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst,
                 getHyperLink(dp.fragment(getPackageAnchorName(pkg)), stringContent));
-        addIndexComment(usedClass, td);
-        contentTree.addContent(td);
+        contentTree.addContent(thType);
+        HtmlTree tdDesc = new HtmlTree(HtmlTag.TD);
+        tdDesc.addStyle(HtmlStyle.colLast);
+        addIndexComment(usedClass, tdDesc);
+        contentTree.addContent(tdDesc);
     }
 
     /**
@@ -247,10 +248,10 @@
      * @param contentTree the content tree to which the information will be added
      */
     protected void addPackageUse(PackageElement pkg, Content contentTree) {
-        Content tdFirst = HtmlTree.TD(HtmlStyle.colFirst,
+        Content thFirst = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst,
                 getHyperLink(utils.getPackageName(pkg),
                 new StringContent(utils.getPackageName(pkg))));
-        contentTree.addContent(tdFirst);
+        contentTree.addContent(thFirst);
         HtmlTree tdLast = new HtmlTree(HtmlTag.TD);
         tdLast.addStyle(HtmlStyle.colLast);
         if (pkg != null && !pkg.isUnnamed()) {
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriterImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriterImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -229,8 +229,8 @@
                 }
                 Content classContent = getLink(new LinkInfoImpl(
                         configuration, LinkInfoImpl.Kind.PACKAGE, klass));
-                Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
-                HtmlTree tr = HtmlTree.TR(tdClass);
+                Content thClass = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst, classContent);
+                HtmlTree tr = HtmlTree.TR(thClass);
                 tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
 
                 HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PropertyWriterImpl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PropertyWriterImpl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -25,8 +25,6 @@
 
 package jdk.javadoc.internal.doclets.formats.html;
 
-import java.io.*;
-
 import java.util.Arrays;
 import java.util.List;
 
@@ -235,10 +233,8 @@
      */
     @Override
     public List<String> getSummaryTableHeader(Element member) {
-        List<String> header = Arrays.asList(configuration.getText("doclet.Type"),
-                configuration.getText("doclet.0_and_1",
-                        configuration.getText("doclet.Property"),
-                        configuration.getText("doclet.Description")));
+        List<String> header = Arrays.asList(resources.getText("doclet.Type"),
+                resources.getText("doclet.Property"), resources.getText("doclet.Description"));
         return header;
     }
 
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlStyle.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlStyle.java	Fri Sep 30 09:28:18 2016 -0700
@@ -48,7 +48,6 @@
     classUseContainer,
     colFirst,
     colLast,
-    colOne,
     colSecond,
     constantsSummary,
     constantValuesContainer,
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java	Fri Sep 30 09:28:18 2016 -0700
@@ -808,6 +808,17 @@
     }
 
     /**
+     * Generates a TH tag with style class, scope attribute and some content.
+     *
+     * @param styleClass style for the tag
+     * @param body content for the tag
+     * @return an HtmlTree object for the TH tag
+     */
+    public static HtmlTree TH_ROW_SCOPE(HtmlStyle styleClass, Content body) {
+        return TH(styleClass, "row", body);
+    }
+
+    /**
      * Generates a TITLE tag with some content.
      *
      * @param body content for the tag
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/stylesheet.css	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/stylesheet.css	Fri Sep 30 09:28:18 2016 -0700
@@ -528,20 +528,23 @@
     float:left;
 
 }
+.rowColor th, .altColor th {
+    font-weight:normal;
+}
 .overviewSummary td, .memberSummary td, .typeSummary td,
 .useSummary td, .constantsSummary td, .deprecatedSummary td,
 .requiresSummary td, .packagesSummary td, .providesSummary td, .usesSummary td {
     text-align:left;
     padding:0px 0px 12px 10px;
 }
-th.colOne, th.colFirst, th.colSecond, th.colLast, .useSummary th, .constantsSummary th, .packagesSummary th,
-td.colOne, td.colFirst, td.colSecond, td.colLast, .useSummary td, .constantsSummary td {
+th.colFirst, th.colSecond, th.colLast, .useSummary th, .constantsSummary th, .packagesSummary th,
+td.colFirst, td.colSecond, td.colLast, .useSummary td, .constantsSummary td {
     vertical-align:top;
     padding-right:0px;
     padding-top:8px;
     padding-bottom:3px;
 }
-th.colFirst, th.colSecond, th.colLast, th.colOne, .constantsSummary th, .packagesSummary th {
+th.colFirst, th.colSecond, th.colLast, .constantsSummary th, .packagesSummary th {
     background:#dee3e9;
     text-align:left;
     padding:8px 3px 3px 7px;
@@ -550,10 +553,10 @@
     white-space:nowrap;
     font-size:13px;
 }
-td.colLast, th.colLast {
+td.colSecond, th.colSecond, td.colLast, th.colLast {
     font-size:13px;
 }
-td.colOne, th.colOne, .constantsSummary th, .packagesSummary th {
+.constantsSummary th, .packagesSummary th {
     font-size:13px;
 }
 .providesSummary th.colFirst, .providesSummary th.colLast, .providesSummary td.colFirst,
@@ -567,23 +570,22 @@
 .packagesSummary td.colFirst, .packagesSummary td.colSecond, .packagesSummary th.colFirst, .packagesSummary th,
 .usesSummary td.colFirst, .usesSummary th.colFirst,
 .useSummary td.colFirst, .useSummary th.colFirst,
-.overviewSummary td.colOne, .overviewSummary th.colOne,
 .memberSummary td.colFirst, .memberSummary th.colFirst,
-.memberSummary td.colOne, .memberSummary th.colOne,
+.memberSummary td.colSecond, .memberSummary th.colSecond,
 .typeSummary td.colFirst{
     width:25%;
     vertical-align:top;
 }
-td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colSecond a:link, td.colSecond a:active, td.colSecond a:visited, td.colSecond a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover {
+td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colSecond a:link, td.colSecond a:active, td.colSecond a:visited, td.colSecond a:hover, th.colFirst a:link, th.colFirst a:active, th.colFirst a:visited, th.colFirst a:hover, th.colSecond a:link, th.colSecond a:active, th.colSecond a:visited, th.colSecond a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover {
     font-weight:bold;
 }
 .tableSubHeadingColor {
     background-color:#EEEEFF;
 }
-.altColor {
+.altColor, .altColor th {
     background-color:#FFFFFF;
 }
-.rowColor {
+.rowColor, .rowColor th {
     background-color:#EEEEEF;
 }
 /*
@@ -774,4 +776,4 @@
 .searchTagHolderResult {
     font-style:italic;
     font-size:12px;
-}
+}
\ No newline at end of file
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/classfile/TypeAnnotation.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/classfile/TypeAnnotation.java	Fri Sep 30 09:28:18 2016 -0700
@@ -130,10 +130,7 @@
             break;
         // class extends or implements clause
         case CLASS_EXTENDS:
-            int in = cr.readUnsignedShort();
-            if (in == 0xFFFF)
-                in = -1;
-            position.type_index = in;
+            position.type_index = cr.readUnsignedShort();;
             break;
         // throws
         case THROWS:
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Analyzer.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Analyzer.java	Fri Sep 30 09:28:18 2016 -0700
@@ -256,7 +256,7 @@
         // return classname or package name depending on the level
         private String getLocationName(Location o) {
             if (level == Type.CLASS || level == Type.VERBOSE) {
-                return o.getClassName();
+                return VersionHelper.get(o.getClassName());
             } else {
                 String pkg = o.getPackageName();
                 return pkg.isEmpty() ? "<unnamed>" : pkg;
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Archive.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Archive.java	Fri Sep 30 09:28:18 2016 -0700
@@ -45,9 +45,9 @@
  * Represents the source of the class files.
  */
 public class Archive implements Closeable {
-    public static Archive getInstance(Path p) {
+    public static Archive getInstance(Path p, Runtime.Version version) {
         try {
-            return new Archive(p, ClassFileReader.newInstance(p));
+            return new Archive(p, ClassFileReader.newInstance(p, version));
         } catch (IOException e) {
             throw new UncheckedIOException(e);
         }
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ClassFileReader.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ClassFileReader.java	Fri Sep 30 09:28:18 2016 -0700
@@ -29,6 +29,8 @@
 import com.sun.tools.classfile.ConstantPoolException;
 import com.sun.tools.classfile.Dependencies.ClassFileError;
 
+import jdk.internal.util.jar.VersionedStream;
+
 import java.io.Closeable;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -50,6 +52,7 @@
 import java.util.jar.JarFile;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
+import java.util.zip.ZipFile;
 
 /**
  * ClassFileReader reads ClassFile(s) of a given path that can be
@@ -60,6 +63,13 @@
      * Returns a ClassFileReader instance of a given path.
      */
     public static ClassFileReader newInstance(Path path) throws IOException {
+        return newInstance(path, JarFile.baseVersion());
+    }
+
+    /**
+     * Returns a ClassFileReader instance of a given path.
+     */
+    public static ClassFileReader newInstance(Path path, Runtime.Version version) throws IOException {
         if (Files.notExists(path)) {
             throw new FileNotFoundException(path.toString());
         }
@@ -67,20 +77,13 @@
         if (Files.isDirectory(path)) {
             return new DirectoryReader(path);
         } else if (path.getFileName().toString().endsWith(".jar")) {
-            return new JarFileReader(path);
+            return new JarFileReader(path, version);
         } else {
             return new ClassFileReader(path);
         }
     }
 
     /**
-     * Returns a ClassFileReader instance of a given JarFile.
-     */
-    public static ClassFileReader newInstance(Path path, JarFile jf) throws IOException {
-        return new JarFileReader(path, jf);
-    }
-
-    /**
      * Returns a ClassFileReader instance of a given FileSystem and path.
      *
      * This method is used for reading classes from jrtfs.
@@ -302,13 +305,16 @@
 
     static class JarFileReader extends ClassFileReader {
         private final JarFile jarfile;
-        JarFileReader(Path path) throws IOException {
-            this(path, new JarFile(path.toFile(), false));
+        private final Runtime.Version version;
+
+        JarFileReader(Path path, Runtime.Version version) throws IOException {
+            this(path, openJarFile(path.toFile(), version), version);
         }
 
-        JarFileReader(Path path, JarFile jf) throws IOException {
+        JarFileReader(Path path, JarFile jf, Runtime.Version version) throws IOException {
             super(path);
             this.jarfile = jf;
+            this.version = version;
         }
 
         @Override
@@ -316,9 +322,26 @@
             jarfile.close();
         }
 
+        private static JarFile openJarFile(File f, Runtime.Version version)
+                throws IOException {
+            JarFile jf;
+            if (version == null) {
+                jf = new JarFile(f, false);
+                if (jf.isMultiRelease()) {
+                    throw new MultiReleaseException("err.multirelease.option.notfound", f.getName());
+                }
+            } else {
+                jf = new JarFile(f, false, ZipFile.OPEN_READ, version);
+                if (!jf.isMultiRelease()) {
+                    throw new MultiReleaseException("err.multirelease.option.exists", f.getName());
+                }
+            }
+            return jf;
+        }
+
         protected Set<String> scan() {
-            try (JarFile jf = new JarFile(path.toFile())) {
-                return jf.stream().map(JarEntry::getName)
+            try (JarFile jf = openJarFile(path.toFile(), version)) {
+                return VersionedStream.stream(jf).map(JarEntry::getName)
                          .filter(n -> n.endsWith(".class"))
                          .collect(Collectors.toSet());
             } catch (IOException e) {
@@ -348,15 +371,14 @@
         }
 
         protected ClassFile readClassFile(JarFile jarfile, JarEntry e) throws IOException {
-            InputStream is = null;
-            try {
-                is = jarfile.getInputStream(e);
-                return ClassFile.read(is);
+            try (InputStream is = jarfile.getInputStream(e)) {
+                ClassFile cf = ClassFile.read(is);
+                if (jarfile.isMultiRelease()) {
+                    VersionHelper.add(jarfile, e, cf);
+                }
+                return cf;
             } catch (ConstantPoolException ex) {
                 throw new ClassFileError(ex);
-            } finally {
-                if (is != null)
-                    is.close();
             }
         }
 
@@ -370,6 +392,21 @@
         }
     }
 
+    Enumeration<JarEntry> versionedEntries(JarFile jf) {
+        Iterator<JarEntry> it = VersionedStream.stream(jf).iterator();
+        return new Enumeration<>() {
+            @Override
+            public boolean hasMoreElements() {
+                return it.hasNext();
+            }
+
+            @Override
+            public JarEntry nextElement() {
+                return it.next();
+            }
+        };
+    }
+
     class JarFileIterator implements Iterator<ClassFile> {
         protected final JarFileReader reader;
         protected Enumeration<JarEntry> entries;
@@ -388,7 +425,7 @@
             if (jarfile == null) return;
 
             this.jf = jarfile;
-            this.entries = jf.entries();
+            this.entries = versionedEntries(jf);
             this.nextEntry = nextEntry();
         }
 
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java	Fri Sep 30 09:28:18 2016 -0700
@@ -81,19 +81,22 @@
     private final List<Archive> initialArchives = new ArrayList<>();
     private final Set<Module> rootModules = new HashSet<>();
     private final Configuration configuration;
+    private final Runtime.Version version;
 
     private JdepsConfiguration(SystemModuleFinder systemModulePath,
                                ModuleFinder finder,
                                Set<String> roots,
                                List<Path> classpaths,
                                List<Archive> initialArchives,
-                               boolean allDefaultModules)
+                               boolean allDefaultModules,
+                               Runtime.Version version)
         throws IOException
     {
         trace("root: %s%n", roots);
 
         this.system = systemModulePath;
         this.finder = finder;
+        this.version = version;
 
         // build root set for resolution
         Set<String> mods = new HashSet<>(roots);
@@ -121,7 +124,7 @@
         // classpath archives
         for (Path p : classpaths) {
             if (Files.exists(p)) {
-                Archive archive = Archive.getInstance(p);
+                Archive archive = Archive.getInstance(p, version);
                 addPackagesInUnnamedModule(archive);
                 classpathArchives.add(archive);
             }
@@ -292,7 +295,7 @@
             if (location.getScheme().equals("jrt")) {
                 reader = system.getClassReader(mn);
             } else {
-                reader = ClassFileReader.newInstance(Paths.get(location));
+                reader = ClassFileReader.newInstance(Paths.get(location), version);
             }
 
             builder.classes(reader);
@@ -304,6 +307,10 @@
         }
     }
 
+    public Runtime.Version getVersion() {
+        return version;
+    }
+
     /*
      * Close all archives e.g. JarFile
      */
@@ -476,6 +483,7 @@
         ModuleFinder appModulePath;
         boolean addAllApplicationModules;
         boolean addAllDefaultModules;
+        Runtime.Version version;
 
         public Builder() {
             this.systemModulePath = new SystemModuleFinder();
@@ -526,8 +534,13 @@
             return this;
         }
 
+        public Builder multiRelease(Runtime.Version version) {
+            this.version = version;
+            return this;
+        }
+
         public Builder addRoot(Path path) {
-            Archive archive = Archive.getInstance(path);
+            Archive archive = Archive.getInstance(path, version);
             if (archive.contains(MODULE_INFO)) {
                 paths.add(path);
             } else {
@@ -569,7 +582,8 @@
                                           rootModules,
                                           classPaths,
                                           initialArchives,
-                                          addAllDefaultModules);
+                                          addAllDefaultModules,
+                                          version);
         }
 
         private static ModuleFinder createModulePathFinder(String mpaths) {
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java	Fri Sep 30 09:28:18 2016 -0700
@@ -36,6 +36,7 @@
 import java.nio.file.Paths;
 import java.text.MessageFormat;
 import java.util.*;
+import java.util.jar.JarFile;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -389,6 +390,23 @@
                 }
             }
         },
+        new Option(true, "--multi-release") {
+            void process(JdepsTask task, String opt, String arg) throws BadArgs {
+                if (arg.equalsIgnoreCase("base")) {
+                    task.options.multiRelease = JarFile.baseVersion();
+                } else {
+                    try {
+                        int v = Integer.parseInt(arg);
+                        if (v < 9) {
+                            throw new BadArgs("err.invalid.arg.for.option", arg);
+                        }
+                    } catch (NumberFormatException x) {
+                        throw new BadArgs("err.invalid.arg.for.option", arg);
+                    }
+                    task.options.multiRelease = Runtime.Version.parse(arg);
+                }
+            }
+        },
     };
 
     private static final String PROGNAME = "jdeps";
@@ -481,6 +499,9 @@
         } catch (IOException e) {
             e.printStackTrace();
             return EXIT_CMDERR;
+        } catch (MultiReleaseException e) {
+            reportError(e.getKey(), (Object)e.getMsg());
+            return EXIT_CMDERR;  // could be EXIT_ABNORMAL sometimes
         } finally {
             log.flush();
         }
@@ -541,11 +562,16 @@
         if (options.classpath != null)
             builder.addClassPath(options.classpath);
 
+        if (options.multiRelease != null)
+            builder.multiRelease(options.multiRelease);
+
         // build the root set of archives to be analyzed
         for (String s : inputArgs) {
             Path p = Paths.get(s);
             if (Files.exists(p)) {
                 builder.addRoot(p);
+            } else {
+                warning("warn.invalid.arg", s);
             }
         }
 
@@ -839,6 +865,7 @@
         String modulePath;
         String rootModule;
         Set<String> addmods = new HashSet<>();
+        Runtime.Version multiRelease;
 
         boolean hasFilter() {
             return numFilters() > 0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/MultiReleaseException.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.tools.jdeps;
+
+/**
+ * Signals that an exception of some sort has occurred while processing
+ * a multi-release jar file.
+ *
+ * @since   9
+ */
+class MultiReleaseException extends RuntimeException {
+    private static final long serialVersionUID = 4474870142461654108L;
+    private final String key;
+    private final String[] msg;
+
+    /**
+     * Constructs an {@code MultiReleaseException} with the specified detail
+     * error message array.
+     *
+     * @param key
+     *        The key that identifies the message in the jdeps.properties file
+     * @param msg
+     *        The detail message array
+     */
+    public MultiReleaseException(String key, String... msg) {
+        super();
+        this.key = key;
+        this.msg = msg;
+    }
+
+    /**
+     * Returns the resource message key
+     */
+    public String getKey() {
+        return key;
+    }
+
+    /**
+     * Returns the detailed error message array.
+     *
+     * @return the detailed error message array
+     */
+    public String[] getMsg() {
+        return msg;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/VersionHelper.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.tools.jdeps;
+
+import com.sun.tools.classfile.ClassFile;
+import com.sun.tools.classfile.ConstantPoolException;
+import jdk.internal.misc.SharedSecrets;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+public class VersionHelper {
+    private static final String META_INF_VERSIONS = "META-INF/versions/";
+    private static final Map<String,String> nameToVersion = new ConcurrentHashMap<>();
+
+    public static String get(String classname) {
+        if (nameToVersion.containsKey(classname)) {
+            return nameToVersion.get(classname) + "/" + classname;
+        }
+        return classname;
+    }
+
+    public static void add(JarFile jarfile, JarEntry e, ClassFile cf)
+            throws ConstantPoolException
+    {
+        String realName = SharedSecrets.javaUtilJarAccess().getRealName(jarfile, e);
+        if (realName.startsWith(META_INF_VERSIONS)) {
+            int len = META_INF_VERSIONS.length();
+            int n = realName.indexOf('/', len);
+            if (n > 0) {
+                String version = realName.substring(len, n);
+                assert (Integer.parseInt(version) > 8);
+                String name = cf.getName().replace('/', '.');
+                if (nameToVersion.containsKey(name)) {
+                    if (!version.equals(nameToVersion.get(name))) {
+                        throw new MultiReleaseException(
+                                "err.multirelease.version.associated",
+                                name, nameToVersion.get(name), version
+                        );
+                    }
+                } else {
+                    nameToVersion.put(name, version);
+                }
+            } else {
+                throw new MultiReleaseException("err.multirelease.jar.malformed",
+                        jarfile.getName(), realName);
+            }
+        }
+    }
+}
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/resources/jdeps.properties	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/resources/jdeps.properties	Fri Sep 30 09:28:18 2016 -0700
@@ -150,6 +150,11 @@
 \  -q           -quiet               Do not show missing dependencies from \n\
 \                                    -genmoduleinfo output.
 
+main.opt.multi-release=\
+\  --multi-release <version>         Specifies the version when processing\n\
+\                                    multi-release jar files.  <version> should\n\
+\                                    be integer >= 9 or base.
+
 err.unknown.option=unknown option: {0}
 err.missing.arg=no value given for {0}
 err.invalid.arg.for.option=invalid argument for option: {0}
@@ -164,7 +169,11 @@
 err.root.module.not.set=root module set empty
 err.invalid.inverse.option={0} cannot be used with -inverse option
 err.inverse.filter.not.set={0} cannot be used with -inverse option
-warn.invalid.arg=Path not exist: {0}
+err.multirelease.option.exists={0} is not a multi-release jar file, but the --multi-release option is set
+err.multirelease.option.notfound={0} is a multi-release jar file, but the --multi-release option is not set
+err.multirelease.version.associated=class {0} already associated with version {1}, trying to add version {2}
+err.multirelease.jar.malformed=malformed multi-release jar, {0}, bad entry: {1}
+warn.invalid.arg=Path does not exist: {0}
 warn.split.package=package {0} defined in {1} {2}
 warn.replace.useJDKInternals=\
 JDK internal APIs are unsupported and private to JDK implementation that are\n\
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties	Fri Sep 30 09:28:18 2016 -0700
@@ -543,7 +543,6 @@
 \n\
 Where <mode> is the name of a previously defined feedback mode -- see '/help /set mode'.\n\
 Where <length> is an unsigned integer representing a maximum length.\n\
-Where <format> is a quoted string which will be the value of the field if one of\n\
 Where <selector> is only needed if you wish to fine-tune value truncation length\n\
 by context, <selector> is the context in which the truncation is applied.\n\
 The structure of selector is a hyphen separated list of selector kind lists.\n\
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DemultiplexInput.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DemultiplexInput.java	Fri Sep 30 09:28:18 2016 -0700
@@ -45,6 +45,7 @@
 
     DemultiplexInput(InputStream input, Map<String, OutputStream> io, Iterable<OutputStream> closeList) {
         super("output reader");
+        setDaemon(true);
         this.delegate = new DataInputStream(input);
         this.io = io;
         this.closeList = closeList;
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DirectExecutionControl.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DirectExecutionControl.java	Fri Sep 30 09:28:18 2016 -0700
@@ -24,6 +24,7 @@
  */
 package jdk.jshell.execution;
 
+import java.lang.reflect.Array;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -200,6 +201,21 @@
             return "\"" + (String) value + "\"";
         } else if (value instanceof Character) {
             return "'" + value + "'";
+        } else if (value.getClass().isArray()) {
+            String tn = value.getClass().getTypeName();
+            int len = Array.getLength(value);
+            StringBuilder sb = new StringBuilder();
+            sb.append(tn.substring(tn.lastIndexOf('.') + 1, tn.length() - 1));
+            sb.append(len);
+            sb.append("] { ");
+            for (int i = 0; i < len; ++i) {
+                sb.append(valueString(Array.get(value, i)));
+                if (i < len - 1) {
+                    sb.append(", ");
+                }
+            }
+            sb.append(" }");
+            return sb.toString();
         } else {
             return value.toString();
         }
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/JDIEventHandler.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/JDIEventHandler.java	Fri Sep 30 09:28:18 2016 -0700
@@ -53,6 +53,7 @@
         this.vm = vm;
         this.reportVMExit = reportVMExit;
         this.thread = new Thread(this, "event-handler");
+        this.thread.setDaemon(true);
     }
 
     /**
--- a/langtools/test/jdk/javadoc/doclet/constantValues/TestConstantValuesDriver.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/constantValues/TestConstantValuesDriver.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4504730 4526070 5077317
+ * @bug 4504730 4526070 5077317 8162363
  * @summary Test the generation of constant-values.html.
  * @author jamieh
  * @library ../lib
@@ -53,29 +53,29 @@
                 "TEST4PASSES",
                 "<code>\"&lt;Hello World&gt;\"</code>",
                 "</a><code>public&nbsp;static&nbsp;final&nbsp;byte</code></td>\n" +
-                    "<td><code><a href=\"TestConstantValues.html#BYTE_MAX_VALUE\">" +
-                    "BYTE_MAX_VALUE</a></code></td>\n" +
+                    "<th class=\"colSecond\" scope=\"row\"><code><a href=\"TestConstantValues.html#BYTE_MAX_VALUE\">" +
+                    "BYTE_MAX_VALUE</a></code></th>\n" +
                     "<td class=\"colLast\"><code>127</code></td>",
                 "</a><code>public&nbsp;static&nbsp;final&nbsp;byte</code></td>\n" +
-                    "<td><code><a href=\"TestConstantValues.html#BYTE_MIN_VALUE\">" +
-                    "BYTE_MIN_VALUE</a></code></td>\n" +
+                    "<th class=\"colSecond\" scope=\"row\"><code><a href=\"TestConstantValues.html#BYTE_MIN_VALUE\">" +
+                    "BYTE_MIN_VALUE</a></code></th>\n" +
                     "<td class=\"colLast\"><code>-127</code></td>",
                 "</a><code>public&nbsp;static&nbsp;final&nbsp;char</code></td>\n" +
-                    "<td><code><a href=\"TestConstantValues.html#CHAR_MAX_VALUE\">" +
-                    "CHAR_MAX_VALUE</a></code></td>\n" +
+                    "<th class=\"colSecond\" scope=\"row\"><code><a href=\"TestConstantValues.html#CHAR_MAX_VALUE\">" +
+                    "CHAR_MAX_VALUE</a></code></th>\n" +
                     "<td class=\"colLast\"><code>65535</code></td>",
                 "</a><code>public&nbsp;static&nbsp;final&nbsp;double</code></td>",
-                    "<td><code><a href=\"TestConstantValues.html#DOUBLE_MAX_VALUE\">" +
-                    "DOUBLE_MAX_VALUE</a></code></td>\n" +
+                    "<th class=\"colSecond\" scope=\"row\"><code><a href=\"TestConstantValues.html#DOUBLE_MAX_VALUE\">" +
+                    "DOUBLE_MAX_VALUE</a></code></th>\n" +
                     "<td class=\"colLast\"><code>1.7976931348623157E308</code></td>",
                 "</a><code>public&nbsp;static&nbsp;final&nbsp;double</code></td>\n" +
-                    "<td><code><a href=\"TestConstantValues.html#DOUBLE_MIN_VALUE\">" +
-                    "DOUBLE_MIN_VALUE</a></code></td>",
+                    "<th class=\"colSecond\" scope=\"row\"><code><a href=\"TestConstantValues.html#DOUBLE_MIN_VALUE\">" +
+                    "DOUBLE_MIN_VALUE</a></code></th>",
                 "</a><code>public&nbsp;static&nbsp;final&nbsp;boolean</code></td>\n" +
-                    "<td><code><a href=\"TestConstantValues.html#GOODBYE\">" +
-                    "GOODBYE</a></code></td>",
+                    "<th class=\"colSecond\" scope=\"row\"><code><a href=\"TestConstantValues.html#GOODBYE\">" +
+                    "GOODBYE</a></code></th>",
                 "</a><code>public&nbsp;static&nbsp;final&nbsp;boolean</code></td>\n" +
-                    "<td><code><a href=\"TestConstantValues.html#HELLO\">HELLO</a></code></td>\n" +
+                    "<th class=\"colSecond\" scope=\"row\"><code><a href=\"TestConstantValues.html#HELLO\">HELLO</a></code></th>\n" +
                     "<td class=\"colLast\"><code>true</code></td>"
         );
     }
--- a/langtools/test/jdk/javadoc/doclet/testAnnotationTypes/TestAnnotationTypes.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/testAnnotationTypes/TestAnnotationTypes.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      4973609 8015249 8025633 8026567 6469561 8071982
+ * @bug      4973609 8015249 8025633 8026567 6469561 8071982 8162363
  * @summary  Make sure that annotation types with 0 members does not have
  *           extra HR tags.
  * @author   jamieh
@@ -56,9 +56,9 @@
                 + "field.detail\">Field</a>&nbsp;|&nbsp;</li>",
                 "<!-- =========== ANNOTATION TYPE FIELD SUMMARY =========== -->",
                 "<h3>Field Summary</h3>",
-                "<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href=\"../"
+                "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\"><a href=\"../"
                 + "pkg/AnnotationTypeField.html#DEFAULT_NAME\">DEFAULT_NAME</a></span>"
-                + "</code>&nbsp;</td>",
+                + "</code></th>",
                 "<!-- ============ ANNOTATION TYPE FIELD DETAIL =========== -->",
                 "<h4>DEFAULT_NAME</h4>\n"
                 + "<pre>static final&nbsp;java."
--- a/langtools/test/jdk/javadoc/doclet/testHeadings/TestHeadings.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/testHeadings/TestHeadings.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      4905786 6259611
+ * @bug      4905786 6259611 8162363
  * @summary  Make sure that headings use the TH tag instead of the TD tag.
  * @author   jamieh
  * @library ../lib
@@ -76,7 +76,8 @@
         // Class documentation
         checkOutput("pkg1/C1.html", true,
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Field and Description</th>",
+                + "<th class=\"colSecond\" scope=\"col\">Field</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>",
                 "<h3>Methods inherited from class&nbsp;java.lang.Object</h3>");
 
         // Class use documentation
@@ -84,17 +85,19 @@
                 "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
                 + "<th class=\"colLast\" scope=\"col\">Description</th>",
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Field and Description</th>");
+                + "<th class=\"colSecond\" scope=\"col\">Field</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         // Deprecated
         checkOutput("deprecated-list.html", true,
-                "<th class=\"colOne\" scope=\"col\">Method and Description</th>");
+                "<th class=\"colFirst\" scope=\"col\">Method</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         // Constant values
         checkOutput("constant-values.html", true,
                 "<th class=\"colFirst\" scope=\"col\">"
                 + "Modifier and Type</th>\n"
-                + "<th scope=\"col\">Constant Field</th>\n"
+                + "<th class=\"colSecond\" scope=\"col\">Constant Field</th>\n"
                 + "<th class=\"colLast\" scope=\"col\">Value</th>");
 
         // Serialized Form
--- a/langtools/test/jdk/javadoc/doclet/testHtmlTableTags/TestHtmlTableTags.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/testHtmlTableTags/TestHtmlTableTags.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      6786688 8008164
+ * @bug      6786688 8008164 8162363
  * @summary  HTML tables should have table summary, caption and table headers.
  * @author   Bhavesh Patel
  * @library  ../lib
@@ -282,25 +282,32 @@
         // Class documentation
         checkOutput("pkg1/C1.html", true,
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Field and Description</th>",
+                + "<th class=\"colSecond\" scope=\"col\">Field</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>",
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Method and Description</th>");
+                + "<th class=\"colSecond\" scope=\"col\">Method</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         checkOutput("pkg2/C2.html", true,
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Class and Description</th>",
-                "<th class=\"colOne\" scope=\"col\">Constructor and Description</th>");
+                + "<th class=\"colSecond\" scope=\"col\">Class</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>",
+                "<th class=\"colFirst\" scope=\"col\">Constructor</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         checkOutput("pkg2/C2.ModalExclusionType.html", true,
-                "<th class=\"colOne\" scope=\"col\">Enum Constant and Description</th>");
+                "<th class=\"colFirst\" scope=\"col\">Enum Constant</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         checkOutput("pkg2/C3.html", true,
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Required Element and Description</th>");
+                + "<th class=\"colSecond\" scope=\"col\">Required Element</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         checkOutput("pkg2/C4.html", true,
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Optional Element and Description</th>");
+                + "<th class=\"colSecond\" scope=\"col\">Optional Element</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         // Class use documentation
         checkOutput("pkg1/class-use/I1.html", true,
@@ -309,43 +316,52 @@
 
         checkOutput("pkg1/class-use/C1.html", true,
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Field and Description</th>",
+                + "<th class=\"colSecond\" scope=\"col\">Field</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>",
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Method and Description</th>");
+                + "<th class=\"colSecond\" scope=\"col\">Method</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         checkOutput("pkg2/class-use/C2.html", true,
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Field and Description</th>",
+                + "<th class=\"colSecond\" scope=\"col\">Field</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>",
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Method and Description</th>");
+                + "<th class=\"colSecond\" scope=\"col\">Method</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         checkOutput("pkg2/class-use/C2.ModalExclusionType.html", true,
                 "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
                 + "<th class=\"colLast\" scope=\"col\">Description</th>",
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Method and Description</th>");
+                + "<th class=\"colSecond\" scope=\"col\">Method</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         // Package use documentation
         checkOutput("pkg1/package-use.html", true,
                 "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
                 + "<th class=\"colLast\" scope=\"col\">Description</th>",
-                "<th class=\"colOne\" scope=\"col\">Class and Description</th>");
+                "<th class=\"colFirst\" scope=\"col\">Class</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         checkOutput("pkg2/package-use.html", true,
                 "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
                 + "<th class=\"colLast\" scope=\"col\">Description</th>",
-                "<th class=\"colOne\" scope=\"col\">Class and Description</th>");
+                "<th class=\"colFirst\" scope=\"col\">Class</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         // Deprecated
         checkOutput("deprecated-list.html", true,
-                "<th class=\"colOne\" scope=\"col\">Field and Description</th>",
-                "<th class=\"colOne\" scope=\"col\">Method and Description</th>");
+                "<th class=\"colFirst\" scope=\"col\">Field</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>",
+                "<th class=\"colFirst\" scope=\"col\">Method</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>");
 
         // Constant values
         checkOutput("constant-values.html", true,
                 "<th class=\"colFirst\" scope=\"col\">"
                 + "Modifier and Type</th>\n"
-                + "<th"
+                + "<th class=\"colSecond\""
                 + " scope=\"col\">Constant Field</th>\n"
                 + "<th class=\"colLast\" scope=\"col\">Value</th>");
 
--- a/langtools/test/jdk/javadoc/doclet/testJavaFX/TestJavaFX.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/testJavaFX/TestJavaFX.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 7112427 8012295 8025633 8026567 8061305 8081854 8150130
+ * @bug 7112427 8012295 8025633 8026567 8061305 8081854 8150130 8162363
  * @summary Test of the JavaFX doclet features.
  * @author jvalenta
  * @library ../lib
@@ -61,19 +61,17 @@
                     + "<div class=\"block\">Gets the value of the property rate.</div>\n"
                     + "<dl>\n"
                     + "<dt><span class=\"simpleTagLabel\">Property description:</span></dt>",
-                "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
-                    + "<a href=\"../pkg1/C.html#rateProperty\">rate</a></span></code>\n"
-                    + "<div class=\"block\">Defines the direction/speed at which the "
-                    + "<code>Timeline</code> is expected to",
+                "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
+                    + "<a href=\"../pkg1/C.html#rateProperty\">rate</a></span></code>",
                 "<span class=\"simpleTagLabel\">Default value:</span>",
                 "<span class=\"simpleTagLabel\">Since:</span></dt>\n"
                     + "<dd>JavaFX 8.0</dd>",
                 "<p>Sets the value of the property <code>Property</code>",
                 "<p>Gets the value of the property <code>Property</code>",
                 "<span class=\"simpleTagLabel\">Property description:</span>",
-                "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+                "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
                     + "<a href=\"../pkg1/C.html#setTestMethodProperty--\">"
-                    + "setTestMethodProperty</a></span>()</code>&nbsp;</td>",
+                    + "setTestMethodProperty</a></span>()</code></th>",
                 "<h4>isPaused</h4>\n"
                     + "<pre>public final&nbsp;double&nbsp;isPaused()</pre>\n"
                     + "<div class=\"block\">Gets the value of the property paused.</div>");
@@ -152,34 +150,34 @@
         checkOutput("pkg2/Test.html", false, "<h3>Property Summary</h3>");
         checkOutput("pkg2/Test.html", true,
                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Method and Description</th>\n"
+                + "<th class=\"colSecond\" scope=\"col\">Method</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
                 + "</tr>\n"
                 + "<tr id=\"i0\" class=\"altColor\">\n"
                 + "<td class=\"colFirst\"><code>&lt;T&gt;&nbsp;java.lang.Object</code></td>\n"
-                + "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
-                + "<a href=\"../pkg2/Test.html#alphaProperty-java.util.List-\">"
-                + "alphaProperty</a></span>(java.util.List&lt;T&gt;&nbsp;foo)</code>&nbsp;</td>\n"
+                + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
+                + "<a href=\"../pkg2/Test.html#alphaProperty-java.util.List-\">alphaProperty</a>"
+                + "</span>(java.util.List&lt;T&gt;&nbsp;foo)</code></th>\n"
+                + "<td class=\"colLast\">&nbsp;</td>\n"
                 + "</tr>\n"
                 + "<tr id=\"i1\" class=\"rowColor\">\n"
                 + "<td class=\"colFirst\"><code>java.lang.Object</code></td>\n"
-                + "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
-                + "<a href=\"../pkg2/Test.html#betaProperty--\">betaProperty</a></span>()</code>"
-                + "&nbsp;</td>\n"
+                + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
+                + "<a href=\"../pkg2/Test.html#betaProperty--\">betaProperty</a></span>()</code></th>\n"
+                + "<td class=\"colLast\">&nbsp;</td>\n"
                 + "</tr>\n"
                 + "<tr id=\"i2\" class=\"altColor\">\n"
-                + "<td class=\"colFirst\"><code>"
-                + "java.util.List&lt;java.util.Set&lt;? super java.lang.Object&gt;&gt;"
+                + "<td class=\"colFirst\"><code>java.util.List&lt;java.util.Set&lt;? super java.lang.Object&gt;&gt;"
                 + "</code></td>\n"
-                + "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
-                + "<a href=\"../pkg2/Test.html#deltaProperty--\">"
-                + "deltaProperty</a></span>()</code>&nbsp;</td>\n"
+                + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
+                + "<a href=\"../pkg2/Test.html#deltaProperty--\">deltaProperty</a></span>()</code></th>\n"
+                + "<td class=\"colLast\">&nbsp;</td>\n"
                 + "</tr>\n"
                 + "<tr id=\"i3\" class=\"rowColor\">\n"
-                + "<td class=\"colFirst\"><code>java.util.List&lt;java.lang.String&gt;"
-                + "</code></td>\n"
-                + "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
-                + "<a href=\"../pkg2/Test.html#gammaProperty--\">gammaProperty</a>"
-                + "</span>()</code>&nbsp;</td>"
+                + "<td class=\"colFirst\"><code>java.util.List&lt;java.lang.String&gt;</code></td>\n"
+                + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
+                + "<a href=\"../pkg2/Test.html#gammaProperty--\">gammaProperty</a></span>()</code></th>\n"
+                + "<td class=\"colLast\">&nbsp;</td>"
         );
     }
 
--- a/langtools/test/jdk/javadoc/doclet/testMemberInheritence/TestMemberInheritence.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/testMemberInheritence/TestMemberInheritence.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4638588 4635809 6256068 6270645 8025633 8026567
+ * @bug 4638588 4635809 6256068 6270645 8025633 8026567 8162363
  * @summary Test to make sure that members are inherited properly in the Javadoc.
  *          Verify that inheritence labels are correct.
  * @author jamieh
@@ -90,10 +90,10 @@
         checkOutput("pkg1/Implementer.html", true,
                 // ensure the method makes it
                 "<td class=\"colFirst\"><code>static java.time.Period</code></td>\n"
-                + "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+                + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
                 + "<a href=\"../pkg1/Implementer.html#between-java.time.LocalDate-java.time.LocalDate-\">"
                 + "between</a></span>(java.time.LocalDate&nbsp;startDateInclusive,\n"
-                + "       java.time.LocalDate&nbsp;endDateExclusive)</code>&nbsp;</td>",
+                + "       java.time.LocalDate&nbsp;endDateExclusive)</code></th>",
                 // check the inherited from interfaces
                 "<h3>Methods inherited from interface&nbsp;pkg1.<a href=\"../pkg1/Interface.html\""
                 + " title=\"interface in pkg1\">Interface</a></h3>\n"
--- a/langtools/test/jdk/javadoc/doclet/testMemberSummary/TestMemberSummary.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/testMemberSummary/TestMemberSummary.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      4951228 6290760 8025633 8026567 8081854
+ * @bug      4951228 6290760 8025633 8026567 8081854 8162363
  * @summary  Test the case where the overriden method returns a different
  *           type than the method in the child class.  Make sure the
  *           documentation is inherited but the return type isn't.
@@ -51,7 +51,7 @@
         checkOutput("pkg/PublicChild.html", true,
                 // Check return type in member summary.
                 "<code><a href=\"../pkg/PublicChild.html\" title=\"class in pkg\">PublicChild</a></code></td>\n"
-                + "<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href=\"../pkg/PublicChild.html#returnTypeTest--\">"
+                + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\"><a href=\"../pkg/PublicChild.html#returnTypeTest--\">"
                 + "returnTypeTest</a></span>()</code>",
                 // Check return type in member detail.
                 "<pre>public&nbsp;<a href=\"../pkg/PublicChild.html\" title=\"class in pkg\">"
--- a/langtools/test/jdk/javadoc/doclet/testModules/TestModules.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/testModules/TestModules.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8154119 8154262 8156077 8157987 8154261 8154817 8135291 8155995
+ * @bug 8154119 8154262 8156077 8157987 8154261 8154817 8135291 8155995 8162363
  * @summary Test modules support in javadoc.
  * @author bpatel
  * @library ../lib
@@ -397,7 +397,7 @@
                 + "</a>");
         checkOutput("module1-summary.html", true,
                 "<tr class=\"altColor\">\n"
-                + "<td class=\"colFirst\"><a href=\"testpkgmdl1/package-summary.html\">testpkgmdl1</a></td>\n"
+                + "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkgmdl1/package-summary.html\">testpkgmdl1</a></th>\n"
                 + "<td class=\"colSecond\">All Modules</td>\n"
                 + "<td class=\"colLast\">&nbsp;</td>\n"
                 + "</tr>");
@@ -408,7 +408,7 @@
                 + "</a>");
         checkOutput("module1-summary.html", true,
                 "<tr class=\"rowColor\">\n"
-                + "<td class=\"colFirst\"><a href=\"module2-summary.html\">module2</a></td>\n"
+                + "<th class=\"colFirst\" scope=\"row\"><a href=\"module2-summary.html\">module2</a></th>\n"
                 + "<td class=\"colLast\">\n"
                 + "<div class=\"block\">This is a test description for the module2 module.</div>\n"
                 + "</td>\n"
@@ -424,8 +424,8 @@
                 + "</a>");
         checkOutput("module2-summary.html", true,
                 "<tr class=\"rowColor\">\n"
-                + "<td class=\"colFirst\"><a href=\"testpkg2mdl2/package-summary.html\">"
-                + "testpkg2mdl2</a></td>\n"
+                + "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkg2mdl2/package-summary.html\">"
+                + "testpkg2mdl2</a></th>\n"
                 + "<td class=\"colSecond\">module1</td>\n"
                 + "<td class=\"colLast\">&nbsp;</td>\n"
                 + "</tr>");
@@ -436,7 +436,7 @@
                 + "</a>");
         checkOutput("module2-summary.html", true,
                 "<tr class=\"altColor\">\n"
-                + "<td class=\"colFirst\"><a href=\"java.base-summary.html\">java.base</a></td>\n"
+                + "<th class=\"colFirst\" scope=\"row\"><a href=\"java.base-summary.html\">java.base</a></th>\n"
                 + "<td class=\"colLast\">&nbsp;</td>\n"
                 + "</tr>");
         checkOutput("module2-summary.html", true,
@@ -446,24 +446,24 @@
                 + "</a>");
         checkOutput("module2-summary.html", true,
                 "<tr class=\"altColor\">\n"
-                + "<td class=\"colFirst\"><a href=\"testpkgmdl2/TestClassInModule2.html\" "
-                + "title=\"class in testpkgmdl2\">TestClassInModule2</a></td>\n"
+                + "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkgmdl2/TestClassInModule2.html\" "
+                + "title=\"class in testpkgmdl2\">TestClassInModule2</a></th>\n"
                 + "<td class=\"colLast\">&nbsp;</td>\n"
                 + "</tr>");
         checkOutput("module2-summary.html", true,
                 "<tr class=\"altColor\">\n"
-                + "<td class=\"colFirst\"><a href=\"testpkg2mdl2/TestInterfaceInModule2.html\" "
+                + "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkg2mdl2/TestInterfaceInModule2.html\" "
                 + "title=\"interface in testpkg2mdl2\">TestInterfaceInModule2</a><br>"
                 + "(<span class=\"implementationLabel\">Implementation:</span>&nbsp;"
                 + "<a href=\"testpkgmdl2/TestClassInModule2.html\" title=\"class in testpkgmdl2\">"
-                + "TestClassInModule2</a>)</td>\n"
+                + "TestClassInModule2</a>)</th>\n"
                 + "<td class=\"colLast\">&nbsp;</td>\n"
                 + "</tr");
         checkOutput("module2-summary.html", true,
                 "<caption><span>Exported Packages</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
                 + "<tr>\n"
                 + "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
-                + "<th scope=\"col\">Module</th>\n"
+                + "<th class=\"colSecond\" scope=\"col\">Module</th>\n"
                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
                 + "</tr>");
         checkOutput("module2-summary.html", true,
--- a/langtools/test/jdk/javadoc/doclet/testNewLanguageFeatures/TestNewLanguageFeatures.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/testNewLanguageFeatures/TestNewLanguageFeatures.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      4789689 4905985 4927164 4827184 4993906 5004549 7025314 7010344 8025633 8026567
+ * @bug      4789689 4905985 4927164 4827184 4993906 5004549 7025314 7010344 8025633 8026567 8162363
  * @summary  Run Javadoc on a set of source files that demonstrate new
  *           language features.  Check the output to ensure that the new
  *           language features are properly documented.
@@ -134,7 +134,7 @@
                 // Method that returns TypeParameters
                 "<td class=\"colFirst\"><code><a href=\"../pkg/TypeParameters.html\" "
                 + "title=\"type parameter in TypeParameters\">E</a>[]</code></td>\n"
-                + "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+                + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
                 + "<a href=\"../pkg/TypeParameters.html#methodThatReturnsTypeParameterA-E:A-\">"
                 + "methodThatReturnsTypeParameterA</a></span>(<a href=\"../pkg/TypeParameters.html\" "
                 + "title=\"type parameter in TypeParameters\">E</a>[]&nbsp;e)</code>",
@@ -144,15 +144,15 @@
                 + "title=\"type parameter in TypeParameters\">E</a>[]&nbsp;e)</pre>\n",
                 "<td class=\"colFirst\"><code>&lt;T extends java.lang.Object &amp; java.lang.Comparable&lt;? super T&gt;&gt;"
                 + "<br>T</code></td>\n"
-                + "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+                + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
                 + "<a href=\"../pkg/TypeParameters.html#methodtThatReturnsTypeParametersB-java.util.Collection-\">"
-                + "methodtThatReturnsTypeParametersB</a></span>(java.util.Collection&lt;? extends T&gt;&nbsp;coll)</code>\n"
-                + "<div class=\"block\">Returns TypeParameters</div>\n",
+                + "methodtThatReturnsTypeParametersB</a></span>(java.util.Collection&lt;? extends T&gt;&nbsp;coll)</code>",
+                "<div class=\"block\">Returns TypeParameters</div>\n",
                 // Method takes a TypeVariable
                 "<td class=\"colFirst\"><code>&lt;X extends java.lang.Throwable&gt;<br>"
                 + "<a href=\"../pkg/TypeParameters.html\" title=\"type parameter in TypeParameters\">E</a>"
                 + "</code></td>\n"
-                + "<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+                + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
                 + "<a href=\"../pkg/TypeParameters.html#orElseThrow-java.util.function.Supplier-\">"
                 + "orElseThrow</a></span>(java.util.function.Supplier&lt;? extends X&gt;&nbsp;exceptionSupplier)</code>"
                 );
@@ -219,19 +219,19 @@
                 + "package-summary.html\">pkg2</a> with type parameters of "
                 + "type <a href=\"../../pkg2/Foo.html\" title=\"class in pkg2\">"
                 + "Foo</a></span><span class=\"tabEnd\">&nbsp;</span></caption>",
-                "<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest1.html\" "
+                "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest1.html\" "
                 + "title=\"class in pkg2\">ClassUseTest1</a>&lt;T extends "
                 + "<a href=\"../../pkg2/Foo.html\" title=\"class in pkg2\">Foo"
                 + "</a> &amp; <a href=\"../../pkg2/Foo2.html\" title=\"interface in pkg2\">"
-                + "Foo2</a>&gt;</span></code>&nbsp;</td>",
+                + "Foo2</a>&gt;</span></code></th>",
                 "<caption><span>Methods in <a href=\"../../pkg2/"
                 + "package-summary.html\">pkg2</a> with type parameters of "
                 + "type <a href=\"../../pkg2/Foo.html\" title=\"class in "
                 + "pkg2\">Foo</a></span><span class=\"tabEnd\">&nbsp;</span></caption>",
-                "<td class=\"colLast\"><span class=\"typeNameLabel\">ClassUseTest1."
+                "<th class=\"colSecond\" scope=\"row\"><span class=\"typeNameLabel\">ClassUseTest1."
                 + "</span><code><span class=\"memberNameLink\"><a href=\"../../pkg2/"
                 + "ClassUseTest1.html#method-T-\">method</a></span>"
-                + "(T&nbsp;t)</code>&nbsp;</td>",
+                + "(T&nbsp;t)</code></th>",
                 "<caption><span>Fields in <a href=\"../../pkg2/"
                 + "package-summary.html\">pkg2</a> with type parameters of "
                 + "type <a href=\"../../pkg2/Foo.html\" title=\"class in pkg2\">"
@@ -259,20 +259,20 @@
                 + "type <a href=\"../../pkg2/Foo2.html\" title=\"interface "
                 + "in pkg2\">Foo2</a></span><span class=\"tabEnd\">&nbsp;"
                 + "</span></caption>",
-                "<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest1.html\" "
+                "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest1.html\" "
                 + "title=\"class in pkg2\">ClassUseTest1</a>&lt;T extends "
                 + "<a href=\"../../pkg2/Foo.html\" title=\"class in pkg2\">Foo"
                 + "</a> &amp; <a href=\"../../pkg2/Foo2.html\" title=\"interface in pkg2\">"
-                + "Foo2</a>&gt;</span></code>&nbsp;</td>",
+                + "Foo2</a>&gt;</span></code></th>",
                 "<caption><span>Methods in <a href=\"../../pkg2/"
                 + "package-summary.html\">pkg2</a> with type parameters of "
                 + "type <a href=\"../../pkg2/Foo2.html\" title=\"interface "
                 + "in pkg2\">Foo2</a></span><span class=\"tabEnd\">&nbsp;"
                 + "</span></caption>",
-                "<td class=\"colLast\"><span class=\"typeNameLabel\">"
+                "<th class=\"colSecond\" scope=\"row\"><span class=\"typeNameLabel\">"
                 + "ClassUseTest1.</span><code><span class=\"memberNameLink\"><a href=\"../../"
                 + "pkg2/ClassUseTest1.html#method-T-\">method</a></span>"
-                + "(T&nbsp;t)</code>&nbsp;</td>"
+                + "(T&nbsp;t)</code></th>"
         );
 
         // ClassUseTest2: <T extends ParamTest<Foo3>>
@@ -282,20 +282,20 @@
                 + "type <a href=\"../../pkg2/ParamTest.html\" title=\"class "
                 + "in pkg2\">ParamTest</a></span><span class=\"tabEnd\">"
                 + "&nbsp;</span></caption>",
-                "<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest2.html\" "
+                "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest2.html\" "
                 + "title=\"class in pkg2\">ClassUseTest2</a>&lt;T extends "
                 + "<a href=\"../../pkg2/ParamTest.html\" title=\"class in pkg2\">"
                 + "ParamTest</a>&lt;<a href=\"../../pkg2/Foo3.html\" title=\"class in pkg2\">"
-                + "Foo3</a>&gt;&gt;</span></code>&nbsp;</td>",
+                + "Foo3</a>&gt;&gt;</span></code></th>",
                 "<caption><span>Methods in <a href=\"../../pkg2/"
                 + "package-summary.html\">pkg2</a> with type parameters of "
                 + "type <a href=\"../../pkg2/ParamTest.html\" title=\"class "
                 + "in pkg2\">ParamTest</a></span><span class=\"tabEnd\">"
                 + "&nbsp;</span></caption>",
-                "<td class=\"colLast\"><span class=\"typeNameLabel\">ClassUseTest2."
+                "<th class=\"colSecond\" scope=\"row\"><span class=\"typeNameLabel\">ClassUseTest2."
                 + "</span><code><span class=\"memberNameLink\"><a href=\"../../pkg2/"
                 + "ClassUseTest2.html#method-T-\">method</a></span>"
-                + "(T&nbsp;t)</code>&nbsp;</td>",
+                + "(T&nbsp;t)</code></th>",
                 "<caption><span>Fields in <a href=\"../../pkg2/"
                 + "package-summary.html\">pkg2</a> declared as <a href=\"../"
                 + "../pkg2/ParamTest.html\" title=\"class in pkg2\">ParamTest"
@@ -323,20 +323,20 @@
                 + "package-summary.html\">pkg2</a> with type parameters of "
                 + "type <a href=\"../../pkg2/Foo3.html\" title=\"class in pkg2\">"
                 + "Foo3</a></span><span class=\"tabEnd\">&nbsp;</span></caption>",
-                "<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest2.html\" "
+                "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest2.html\" "
                 + "title=\"class in pkg2\">ClassUseTest2</a>&lt;T extends "
                 + "<a href=\"../../pkg2/ParamTest.html\" title=\"class in pkg2\">"
                 + "ParamTest</a>&lt;<a href=\"../../pkg2/Foo3.html\" title=\"class in pkg2\">"
-                + "Foo3</a>&gt;&gt;</span></code>&nbsp;</td>",
+                + "Foo3</a>&gt;&gt;</span></code></th>",
                 "<caption><span>Methods in <a href=\"../../pkg2/"
                 + "package-summary.html\">pkg2</a> with type parameters of "
                 + "type <a href=\"../../pkg2/Foo3.html\" title=\"class in "
                 + "pkg2\">Foo3</a></span><span class=\"tabEnd\">&nbsp;"
                 + "</span></caption>",
-                "<td class=\"colLast\"><span class=\"typeNameLabel\">ClassUseTest2."
+                "<th class=\"colSecond\" scope=\"row\"><span class=\"typeNameLabel\">ClassUseTest2."
                 + "</span><code><span class=\"memberNameLink\"><a href=\"../../pkg2/"
                 + "ClassUseTest2.html#method-T-\">method</a></span>"
-                + "(T&nbsp;t)</code>&nbsp;</td>",
+                + "(T&nbsp;t)</code></th>",
                 "<caption><span>Methods in <a href=\"../../pkg2/"
                 + "package-summary.html\">pkg2</a> that return types with "
                 + "arguments of type <a href=\"../../pkg2/Foo3.html\" title"
@@ -357,20 +357,20 @@
                 + "type <a href=\"../../pkg2/ParamTest2.html\" title=\"class "
                 + "in pkg2\">ParamTest2</a></span><span class=\"tabEnd\">"
                 + "&nbsp;</span></caption>",
-                "<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest3.html\" "
+                "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest3.html\" "
                 + "title=\"class in pkg2\">ClassUseTest3</a>&lt;T extends "
                 + "<a href=\"../../pkg2/ParamTest2.html\" title=\"class in pkg2\">"
                 + "ParamTest2</a>&lt;java.util.List&lt;? extends "
                 + "<a href=\"../../pkg2/Foo4.html\" title=\"class in pkg2\">"
-                + "Foo4</a>&gt;&gt;&gt;</span></code>&nbsp;</td>",
+                + "Foo4</a>&gt;&gt;&gt;</span></code></th>",
                 "<caption><span>Methods in <a href=\"../../pkg2/"
                 + "package-summary.html\">pkg2</a> with type parameters of "
                 + "type <a href=\"../../pkg2/ParamTest2.html\" title=\"class "
                 + "in pkg2\">ParamTest2</a></span><span class=\"tabEnd\">"
                 + "&nbsp;</span></caption>",
-                "<td class=\"colLast\"><span class=\"typeNameLabel\">ClassUseTest3"
+                "<th class=\"colSecond\" scope=\"row\"><span class=\"typeNameLabel\">ClassUseTest3"
                 + ".</span><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest3."
-                + "html#method-T-\">method</a></span>(T&nbsp;t)</code>&nbsp;</td>",
+                + "html#method-T-\">method</a></span>(T&nbsp;t)</code></th>",
                 "<td class=\"colFirst\"><code>&lt;T extends <a href=\"../"
                 + "../pkg2/ParamTest2.html\" title=\"class in pkg2\">"
                 + "ParamTest2</a>&lt;java.util.List&lt;? extends <a href=\".."
@@ -387,20 +387,20 @@
                 + "type <a href=\"../../pkg2/Foo4.html\" title=\"class in "
                 + "pkg2\">Foo4</a></span><span class=\"tabEnd\">&nbsp;"
                 + "</span></caption>",
-                "<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest3.html\" "
+                "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest3.html\" "
                 + "title=\"class in pkg2\">ClassUseTest3</a>&lt;T extends "
                 + "<a href=\"../../pkg2/ParamTest2.html\" title=\"class in pkg2\">"
                 + "ParamTest2</a>&lt;java.util.List&lt;? extends "
                 + "<a href=\"../../pkg2/Foo4.html\" title=\"class in pkg2\">"
-                + "Foo4</a>&gt;&gt;&gt;</span></code>&nbsp;</td>",
+                + "Foo4</a>&gt;&gt;&gt;</span></code></th>",
                 "<caption><span>Methods in <a href=\"../../pkg2/"
                 + "package-summary.html\">pkg2</a> with type parameters of "
                 + "type <a href=\"../../pkg2/Foo4.html\" title=\"class in "
                 + "pkg2\">Foo4</a></span><span class=\"tabEnd\">&nbsp;</span></caption>",
-                "<td class=\"colLast\"><span class=\"typeNameLabel\">ClassUseTest3."
+                "<th class=\"colSecond\" scope=\"row\"><span class=\"typeNameLabel\">ClassUseTest3."
                 + "</span><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest3."
                 + "html#method-T-\">method</a></span>(T&nbsp;t)</code>"
-                + "&nbsp;</td>",
+                + "</th>",
                 "<caption><span>Methods in <a href=\"../../pkg2/"
                 + "package-summary.html\">pkg2</a> that return types with "
                 + "arguments of type <a href=\"../../pkg2/Foo4.html\" "
@@ -425,18 +425,17 @@
                 + "</span></caption>\n"
                 + "<tr>\n"
                 + "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
-                + "<th class=\"colLast\" scope=\"col\">Method and Description</th>\n"
+                + "<th class=\"colSecond\" scope=\"col\">Method</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
                 + "</tr>\n"
                 + "<tbody>\n"
                 + "<tr class=\"altColor\">\n"
                 + "<td class=\"colFirst\"><code>void</code></td>\n"
-                + "<td class=\"colLast\"><span class=\"typeNameLabel\">ClassUseTest3."
+                + "<th class=\"colSecond\" scope=\"row\"><span class=\"typeNameLabel\">ClassUseTest3."
                 + "</span><code><span class=\"memberNameLink\"><a href=\"../../pkg2/ClassUseTest3."
                 + "html#method-java.util.Set-\">method</a></span>(java."
                 + "util.Set&lt;<a href=\"../../pkg2/Foo4.html\" title=\""
-                + "class in pkg2\">Foo4</a>&gt;&nbsp;p)</code>&nbsp;</td>\n"
-                + "</tr>\n"
-                + "</tbody>",
+                + "class in pkg2\">Foo4</a>&gt;&nbsp;p)</code></th>",
                 "<caption><span>Constructor parameters in <a href=\"../../"
                 + "pkg2/package-summary.html\">pkg2</a> with type arguments "
                 + "of type <a href=\"../../pkg2/Foo4.html\" title=\"class in "
--- a/langtools/test/jdk/javadoc/doclet/testPackageDeprecation/TestPackageDeprecation.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/testPackageDeprecation/TestPackageDeprecation.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      6492694 8026567 8048351
+ * @bug      6492694 8026567 8048351 8162363
  * @summary  Test package deprecation.
  * @author   bpatel
  * @library  ../lib/
@@ -72,7 +72,7 @@
         checkOutput("allclasses-frame.html", false,
                 "FooDepr");
         checkOutput("class-use/C2.ModalExclusionType.html", true,
-                "<td class=\"colFirst\"><a href=\"#unnamed.package\">&lt;Unnamed&gt;</a></td>");
+                "<th class=\"colFirst\" scope=\"row\"><a href=\"#unnamed.package\">&lt;Unnamed&gt;</a></th>");
 
         checkFiles(false,
                 "pkg1/package-summary.html",
--- a/langtools/test/jdk/javadoc/doclet/testStylesheet/TestStylesheet.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/testStylesheet/TestStylesheet.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      4494033 7028815 7052425 8007338 8023608 8008164 8016549 8072461 8154261
+ * @bug      4494033 7028815 7052425 8007338 8023608 8008164 8016549 8072461 8154261 8162363
  * @summary  Run tests on doclet stylesheet.
  * @author   jamieh
  * @library  ../lib
@@ -139,9 +139,8 @@
                 + ".packagesSummary td.colFirst, .packagesSummary td.colSecond, .packagesSummary th.colFirst, .packagesSummary th,\n"
                 + ".usesSummary td.colFirst, .usesSummary th.colFirst,\n"
                 + ".useSummary td.colFirst, .useSummary th.colFirst,\n"
-                + ".overviewSummary td.colOne, .overviewSummary th.colOne,\n"
                 + ".memberSummary td.colFirst, .memberSummary th.colFirst,\n"
-                + ".memberSummary td.colOne, .memberSummary th.colOne,\n"
+                + ".memberSummary td.colSecond, .memberSummary th.colSecond,\n"
                 + ".typeSummary td.colFirst{\n"
                 + "    width:25%;\n"
                 + "    vertical-align:top;\n"
--- a/langtools/test/jdk/javadoc/doclet/testTypeAnnotations/TestTypeAnnotations.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/testTypeAnnotations/TestTypeAnnotations.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      8005091 8009686 8025633 8026567 6469562 8071982 8071984
+ * @bug      8005091 8009686 8025633 8026567 6469562 8071982 8071984 8162363
  * @summary  Make sure that type annotations are displayed correctly
  * @author   Bhavesh Patel
  * @library  ../lib
@@ -473,7 +473,7 @@
                 + "\" title=\"annotation in typeannos\">@RepTypeUseB</a> ...&nbsp;vararg)");
 
         checkOutput("typeannos/RepeatingOnField.html", true,
-                "<code>(package private) java.lang.Integer</code></td>\n<td class=\"colLast\">"
+                "<code>(package private) java.lang.Integer</code></td>\n<th class=\"colSecond\" scope=\"row\">"
                 + "<code><span class=\"memberNameLink\"><a href=\"../typeannos/RepeatingOnField.html#i1"
                 + "\">i1</a></span></code>",
 
@@ -483,7 +483,7 @@
                 + "@RepTypeUseA</a> <a href=\"../typeannos/RepTypeUseB.html\" title="
                 + "\"annotation in typeannos\">@RepTypeUseB</a> <a href=\"../typeannos/RepTypeUseB.html"
                 + "\" title=\"annotation in typeannos\">@RepTypeUseB</a> java.lang.Integer</code></td>\n"
-                + "<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href="
+                + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\"><a href="
                 + "\"../typeannos/RepeatingOnField.html#i2\">i2</a></span></code>",
 
                 "<code>(package private) <a href=\"../typeannos/RepTypeUseA.html\" title="
@@ -492,7 +492,7 @@
                 + "\"../typeannos/RepTypeUseB.html\" title=\"annotation in typeannos\">"
                 + "@RepTypeUseB</a> <a href=\"../typeannos/RepTypeUseB.html\" title="
                 + "\"annotation in typeannos\">@RepTypeUseB</a> java.lang.Integer</code>"
-                + "</td>\n<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+                + "</td>\n<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
                 + "<a href=\"../typeannos/RepeatingOnField.html#i3\">i3</a></span></code>",
 
                 "<code>(package private) <a href=\"../typeannos/RepAllContextsA.html\" title=\""
@@ -501,7 +501,7 @@
                 + "\"../typeannos/RepAllContextsB.html\" title=\"annotation in typeannos\">"
                 + "@RepAllContextsB</a> <a href=\"../typeannos/RepAllContextsB.html\" title="
                 + "\"annotation in typeannos\">@RepAllContextsB</a> java.lang.Integer</code>"
-                + "</td>\n<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+                + "</td>\n<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
                 + "<a href=\"../typeannos/RepeatingOnField.html#i4\">i4</a></span></code>",
 
                 "<code>(package private) java.lang.String <a href=\"../typeannos/RepTypeUseA.html"
@@ -515,7 +515,7 @@
                 + "\"annotation in typeannos\">@RepTypeUseA</a> <a href=\"../typeannos/RepTypeUseB.html"
                 + "\" title=\"annotation in typeannos\">@RepTypeUseB</a> <a href="
                 + "\"../typeannos/RepTypeUseB.html\" title=\"annotation in typeannos\">"
-                + "@RepTypeUseB</a> []</code></td>\n<td class=\"colLast\"><code><span class="
+                + "@RepTypeUseB</a> []</code></td>\n<th class=\"colSecond\" scope=\"row\"><code><span class="
                 + "\"memberNameLink\"><a href=\"../typeannos/RepeatingOnField.html#sa"
                 + "\">sa</a></span></code>",
 
@@ -572,8 +572,8 @@
                 + "@RepTypeUseB</a> [] sa</pre>");
 
         checkOutput("typeannos/RepeatingOnMethod.html", true,
-                "<code>(package private) java.lang.String</code></td>\n<td class="
-                + "\"colLast\"><code><span class=\"memberNameLink\"><a href="
+                "<code>(package private) java.lang.String</code></td>\n<th class=\"colSecond\" scope=\"row\">"
+                + "<code><span class=\"memberNameLink\"><a href="
                 + "\"../typeannos/RepeatingOnMethod.html#test1--\">test1</a></span>()</code>",
 
                 "<code>(package private) <a href=\"../typeannos/RepTypeUseA.html\" "
@@ -582,7 +582,7 @@
                 + "@RepTypeUseA</a> <a href=\"../typeannos/RepTypeUseB.html\" title="
                 + "\"annotation in typeannos\">@RepTypeUseB</a> <a href=\"../typeannos/RepTypeUseB.html"
                 + "\" title=\"annotation in typeannos\">@RepTypeUseB</a> java.lang.String</code>"
-                + "</td>\n<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+                + "</td>\n<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
                 + "<a href=\"../typeannos/RepeatingOnMethod.html#test2--\">test2</a>"
                 + "</span>()</code>",
 
@@ -592,7 +592,7 @@
                 + "@RepTypeUseA</a> <a href=\"../typeannos/RepTypeUseB.html\" title="
                 + "\"annotation in typeannos\">@RepTypeUseB</a> <a href=\"../typeannos/RepTypeUseB.html\" "
                 + "title=\"annotation in typeannos\">@RepTypeUseB</a> java.lang.String</code>"
-                + "</td>\n<td class=\"colLast\"><code><span class=\"memberNameLink\">"
+                + "</td>\n<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
                 + "<a href=\"../typeannos/RepeatingOnMethod.html#test3--\">test3</a>"
                 + "</span>()</code>",
 
@@ -602,7 +602,7 @@
                 + "@RepAllContextsA</a> <a href=\"../typeannos/RepAllContextsB.html\" "
                 + "title=\"annotation in typeannos\">@RepAllContextsB</a> <a href="
                 + "\"../typeannos/RepAllContextsB.html\" title=\"annotation in typeannos\">"
-                + "@RepAllContextsB</a> java.lang.String</code></td>\n<td class=\"colLast\">"
+                + "@RepAllContextsB</a> java.lang.String</code></td>\n<th class=\"colSecond\" scope=\"row\">"
                 + "<code><span class=\"memberNameLink\"><a href=\"../typeannos/RepeatingOnMethod.html"
                 + "#test4--\">test4</a></span>()</code>",
 
@@ -682,12 +682,12 @@
 
         checkOutput("typeannos/RepeatingOnTypeParametersBoundsTypeArgumentsOnMethod.html", true,
                 "<code>(package private) &lt;T&gt;&nbsp;java.lang.String</code></td>\n"
-                + "<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href="
+                + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\"><a href="
                 + "\"../typeannos/RepeatingOnTypeParametersBoundsTypeArgumentsOnMethod.html#"
                 + "genericMethod-T-\">genericMethod</a></span>(T&nbsp;t)</code>",
 
                 "<code>(package private) &lt;T&gt;&nbsp;java.lang.String</code></td>\n"
-                + "<td class=\"colLast\"><code><span class=\"memberNameLink\"><a href="
+                + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\"><a href="
                 + "\"../typeannos/RepeatingOnTypeParametersBoundsTypeArgumentsOnMethod.html#"
                 + "genericMethod2-T-\">genericMethod2</a></span>(<a href=\"../typeannos/RepTypeUseA.html"
                 + "\" title=\"annotation in typeannos\">@RepTypeUseA</a> <a href=\"../typeannos/RepTypeUseA.html"
@@ -695,7 +695,7 @@
                 + "\" title=\"annotation in typeannos\">@RepTypeUseB</a> <a href=\"../typeannos/RepTypeUseB.html"
                 + "\" title=\"annotation in typeannos\">@RepTypeUseB</a> T&nbsp;t)</code>",
 
-                "<code>(package private) java.lang.String</code></td>\n<td class=\"colLast\"><code>"
+                "<code>(package private) java.lang.String</code></td>\n<th class=\"colSecond\" scope=\"row\"><code>"
                 + "<span class=\"memberNameLink\"><a href=\"../typeannos/RepeatingOnTypeParametersBoundsTypeArgumentsOnMethod.html#"
                 + "test--\">test</a></span>()</code>",
 
--- a/langtools/test/jdk/javadoc/doclet/testUseOption/TestUseOption.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/doclet/testUseOption/TestUseOption.java	Fri Sep 30 09:28:18 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4496290 4985072 7006178 7068595 8016328 8050031 8048351 8081854 8071982
+ * @bug 4496290 4985072 7006178 7068595 8016328 8050031 8048351 8081854 8071982 8162363
  * @summary A simple test to ensure class-use files are correct.
  * @author jamieh
  * @library ../lib
@@ -124,17 +124,17 @@
         checkOutput("pkg1/class-use/UsedInterface.html", true,
             "Subinterfaces of <a href=\"../../pkg1/UsedInterface.html\" title=\"interface in pkg1\">"
             + "UsedInterface</a> in <a href=\"../../pkg1/package-summary.html\">pkg1",
-            "<td class=\"colFirst\"><code>interface&nbsp;</code></td>\n<td class=\"colLast\">"
+            "<td class=\"colFirst\"><code>interface&nbsp;</code></td>\n<th class=\"colSecond\" scope=\"row\">"
             + "<code><span class=\"memberNameLink\"><a href=\"../../pkg1/SubInterface.html\" "
-            + "title=\"interface in pkg1\">SubInterface</a>&lt;T&gt;</span></code>&nbsp;</td>"
+            + "title=\"interface in pkg1\">SubInterface</a>&lt;T&gt;</span></code></th>"
         );
         checkOutput("pkg1/class-use/UsedThrowable.html", true,
             "Methods in <a href=\"../../pkg1/package-summary.html\">pkg1</a> that throw "
             + "<a href=\"../../pkg1/UsedThrowable.html\" title=\"class in pkg1\">UsedThrowable</a>",
-            "<td class=\"colFirst\"><code>void</code></td>\n<td class=\"colLast\"><span class="
+            "<td class=\"colFirst\"><code>void</code></td>\n<th class=\"colSecond\" scope=\"row\"><span class="
             + "\"typeNameLabel\">C1.</span><code><span class=\"memberNameLink\">"
             + "<a href=\"../../pkg1/C1.html#methodInC1ThrowsThrowable--\">methodInC1ThrowsThrowable"
-            + "</a></span>()</code>&nbsp;</td>"
+            + "</a></span>()</code></th>"
         );
     }
 
@@ -154,9 +154,9 @@
                 "<li class=\"blockList\"><a name=\"unnamed.package\">"
         );
         checkOutput("package-use.html", true,
-                "<td class=\"colOne\">"
-                + "<a href=\"class-use/UsedInC.html#unnamed.package\">UsedInC</a>&nbsp;</td>",
-                "<td class=\"colFirst\"><a href=\"#-Unnamed-\">&lt;Unnamed&gt;</a></td>\n"
+                "<th class=\"colFirst\" scope=\"row\">"
+                + "<a href=\"class-use/UsedInC.html#unnamed.package\">UsedInC</a></th>",
+                "<th class=\"colFirst\" scope=\"row\"><a href=\"#-Unnamed-\">&lt;Unnamed&gt;</a></th>\n"
                 + "<td class=\"colLast\">&nbsp;</td>"
         );
     }
--- a/langtools/test/jdk/javadoc/tool/modules/ModuleTestBase.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/tool/modules/ModuleTestBase.java	Fri Sep 30 09:28:18 2016 -0700
@@ -252,10 +252,14 @@
     }
 
     void assertAbsent(String regex) throws Exception {
-        List<String> foundList = tb.grep(regex, currentTask.getOutputLines(STDOUT));
+        assertAbsent(regex, STDOUT);
+    }
+
+    void assertAbsent(String regex, Task.OutputKind kind) throws Exception {
+        List<String> foundList = tb.grep(regex, currentTask.getOutputLines(kind));
         if (!foundList.isEmpty()) {
             dumpDocletDiagnostics();
-            throw new Exception(regex + " found in: " + STDOUT);
+            throw new Exception(regex + " found in: " + kind);
         }
     }
 
--- a/langtools/test/jdk/javadoc/tool/modules/Modules.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/javadoc/tool/modules/Modules.java	Fri Sep 30 09:28:18 2016 -0700
@@ -21,9 +21,9 @@
  * questions.
  */
 
-/**
+/*
  * @test
- * @bug 8159305
+ * @bug 8159305 8166127
  * @summary Tests primarily the module graph computations.
  * @modules
  *      jdk.javadoc/jdk.javadoc.internal.api
@@ -40,6 +40,8 @@
 import java.nio.file.Path;
 
 import toolbox.*;
+import toolbox.Task.Expect;
+import toolbox.Task.OutputKind;
 
 public class Modules extends ModuleTestBase {
 
@@ -54,8 +56,8 @@
         ModuleBuilder mb = new ModuleBuilder(tb, "m1");
         mb.comment("The first module.")
                 .exports("pub")
-                .classes("package pub; /** Klass A */ public class A {}")
-                .classes("package pro; /** Klass B */ public class B {}")
+                .classes("package pub; /** Class A */ public class A {}")
+                .classes("package pro; /** Class B */ public class B {}")
                 .write(src);
         execTask("--module-source-path", src.toString(),
                  "--module", "m1");
@@ -72,15 +74,15 @@
         mb1.comment("The first module.")
                 .exports("m1pub")
                 .requires("m2")
-                .classes("package m1pub; /** Klass A */ public class A {}")
-                .classes("package m1pro; /** Klass B */ public class B {}")
+                .classes("package m1pub; /** Class A */ public class A {}")
+                .classes("package m1pro; /** Class B */ public class B {}")
                 .write(src);
 
         ModuleBuilder mb2 = new ModuleBuilder(tb, "m2");
         mb2.comment("The second module.")
                 .exports("m2pub")
-                .classes("package m2pub; /** Klass A */ public class A {}")
-                .classes("package m2pro; /** Klass B */ public class B {}")
+                .classes("package m2pub; /** Class A */ public class A {}")
+                .classes("package m2pro; /** Class B */ public class B {}")
                 .write(src);
         execTask("--module-source-path", src.toString(),
             "--module", "m1,m2");
@@ -98,15 +100,15 @@
         mb1.comment("The first module.")
                 .exports("m1pub")
                 .requires("m2")
-                .classes("package m1pub; /** Klass A */ public class A {}")
-                .classes("package m1pro; /** Klass B */ public class B {}")
+                .classes("package m1pub; /** Class A */ public class A {}")
+                .classes("package m1pro; /** Class B */ public class B {}")
                 .write(src);
 
         ModuleBuilder mb2 = new ModuleBuilder(tb, "m2");
         mb2.comment("The second module.")
                 .exports("m2pub")
-                .classes("package m2pub; /** Klass A */ public class A {}")
-                .classes("package m2pro; /** Klass B */ public class B {}")
+                .classes("package m2pub; /** Class A */ public class A {}")
+                .classes("package m2pro; /** Class B */ public class B {}")
                 .write(src);
         execTask("--module-source-path", src.toString(),
             "--module", "m1",
@@ -117,7 +119,268 @@
 
     }
 
-   /**
+    @Test
+    public void testModulePathOption(Path base) throws Exception {
+        Path src = base.resolve("src");
+        Path modulePath = base.resolve("modules");
+
+        ModuleBuilder mb1 = new ModuleBuilder(tb, "m1");
+        mb1.comment("Module on module path.")
+                .exports("pkg1")
+                .classes("package pkg1; /** Class A */ public class A { }")
+                .build(modulePath);
+
+        ModuleBuilder mb2 = new ModuleBuilder(tb, "m2");
+        mb2.comment("The second module.")
+                .exports("pkg2")
+                .requires("m1")
+                .classes("package pkg2; /** Class B */ public class B { /** Field f */ public pkg1.A f; }")
+                .write(src);
+        execTask("--module-source-path", src.toString(),
+                "--module-path", modulePath.toString(),
+                "--module", "m2");
+        checkModulesSpecified("m2");
+        checkPackagesIncluded("pkg2");
+        checkMembersSelected("pkg2.B.f");
+
+        // module path option "-p"
+        execTask("--module-source-path", src.toString(),
+                "-p", modulePath.toString(),
+                "--module", "m2");
+        // no module path
+        execNegativeTask("--module-source-path", src.toString(),
+                "--module", "m2");
+        assertErrorPresent("error: module not found: m1");
+    }
+
+    @Test
+    public void testUpgradeModulePathOption(Path base) throws Exception {
+        Path src = base.resolve("src");
+        Path modulePath = base.resolve("modules");
+        Path upgradePath = base.resolve("upgrades");
+
+        ModuleBuilder mb1 = new ModuleBuilder(tb, "m1");
+        mb1.comment("Module on module path.")
+                .exports("pkg1")
+                .classes("package pkg1; /** Class A */ public class A { }")
+                .build(modulePath);
+
+        ModuleBuilder mbUpgrade = new ModuleBuilder(tb, "m1");
+        mbUpgrade.comment("Module on upgrade module path.")
+                .exports("pkg1")
+                .classes("package pkg1; /** Class C */ public class C { }")
+                .build(upgradePath);
+
+        ModuleBuilder mb2 = new ModuleBuilder(tb, "m2");
+        mb2.comment("The second module.")
+                .exports("pkg2")
+                .requires("m1")
+                .classes("package pkg2; /** Class B */ public class B { /** Field f */ public pkg1.C f; }")
+                .write(src);
+        execTask("--module-source-path", src.toString(),
+                "--module-path", modulePath.toString(),
+                "--upgrade-module-path", upgradePath.toString(),
+                "--module", "m2");
+        checkModulesSpecified("m2");
+        checkPackagesIncluded("pkg2");
+        checkMembersSelected("pkg2.B.f");
+
+        // no upgrade module path
+        execNegativeTask("--module-source-path", src.toString(),
+                "--module-path", modulePath.toString(),
+                "--module", "m2");
+        assertErrorPresent("error: cannot find symbol");
+
+        // dependency from module path
+        ModuleBuilder mb3 = new ModuleBuilder(tb, "m3");
+        mb3.comment("The third module.")
+                .exports("pkg3")
+                .requires("m1")
+                .classes("package pkg3; /** Class Z */ public class Z { /** Field f */ public pkg1.A f; }")
+                .write(src);
+        execNegativeTask("--module-source-path", src.toString(),
+                "--module-path", modulePath.toString(),
+                "--upgrade-module-path", upgradePath.toString(),
+                "--module", "m3");
+        assertErrorPresent("Z.java:1: error: cannot find symbol");
+    }
+
+    @Test
+    public void testAddModulesOption(Path base) throws Exception {
+        Path src = base.resolve("src");
+        Path modulePath = base.resolve("modules");
+
+        ModuleBuilder mb1 = new ModuleBuilder(tb, "m1");
+        mb1.comment("Module on module path.")
+                .exports("pkg1")
+                .classes("package pkg1; /** Class A */ public class A { }")
+                .build(modulePath);
+
+        ModuleBuilder mb2 = new ModuleBuilder(tb, "m2");
+        mb2.comment("The second module.")
+                .exports("pkg2")
+                .classes("package pkg2; /** @see pkg1.A */ public class B { }")
+                .write(src);
+
+        String log = new JavadocTask(tb)
+                .options("--module-source-path", src.toString(),
+                        "--module-path", modulePath.toString(),
+                        "--module", "m2")
+                .run(Expect.FAIL)
+                .writeAll()
+                .getOutput(OutputKind.DIRECT);
+        if (!log.contains("B.java:1: error: reference not found")) {
+            throw new Exception("Error not found");
+        }
+
+        new JavadocTask(tb)
+                .options("--module-source-path", src.toString(),
+                        "--module-path", modulePath.toString(),
+                        "--add-modules", "m1",
+                        "--module", "m2")
+                .run()
+                .writeAll();
+    }
+
+    @Test
+    public void testLimitModulesOption(Path base) throws Exception {
+        Path src = base.resolve("src");
+        Path modulePath = base.resolve("modules");
+
+        ModuleBuilder mb1 = new ModuleBuilder(tb, "m1");
+        mb1.comment("Module on module path.")
+                .build(modulePath);
+
+        ModuleBuilder mb2 = new ModuleBuilder(tb, "m2");
+        mb2.comment("The second module.")
+                .exports("pkg2")
+                .requires("m1")
+                .classes("package pkg2; /** Class B */ public class B { }")
+                .write(src);
+
+        execNegativeTask("--module-source-path", src.toString(),
+                "--module-path", modulePath.toString(),
+                "--limit-modules", "java.base",
+                "--module", "m2");
+        assertErrorPresent("error: module not found: m1");
+    }
+
+    @Test
+    public void testAddExportsOption(Path base) throws Exception {
+        Path src = base.resolve("src");
+        Path modulePath = base.resolve("modules");
+
+        ModuleBuilder mb1 = new ModuleBuilder(tb, "m1");
+        mb1.comment("Module on module path.")
+                .classes("package pkg1; /** Class A */ public class A { }")
+                .build(modulePath);
+
+        ModuleBuilder mb2 = new ModuleBuilder(tb, "m2");
+        mb2.comment("The second module.")
+                .exports("pkg2")
+                .requires("m1")
+                .classes("package pkg2; /** Class B */ public class B { /** Field f */ public pkg1.A f; }")
+                .write(src);
+        execTask("--module-source-path", src.toString(),
+                "--module-path", modulePath.toString(),
+                "--add-exports", "m1/pkg1=m2",
+                "--module", "m2");
+        checkModulesSpecified("m2");
+        checkPackagesIncluded("pkg2");
+        checkMembersSelected("pkg2.B.f");
+    }
+
+//    @Test @ignore JDK-8166379
+    public void testPatchModuleOption(Path base) throws Exception {
+        Path src = base.resolve("src");
+        Path modulePath = base.resolve("modules");
+        Path patchPath = base.resolve("patch");
+
+        ModuleBuilder mb1 = new ModuleBuilder(tb, "m1");
+        mb1.comment("Module on module path.")
+                .exports("pkg1")
+                .classes("package pkg1; /** Class A */ public class A { }")
+                .build(modulePath);
+
+        tb.writeJavaFiles(patchPath, "package pkg1; /** Class A */ public class A { public static int k; }");
+        new JavacTask(tb)
+                .files(patchPath.resolve("pkg1/A.java"))
+                .run();
+
+        ModuleBuilder mb2 = new ModuleBuilder(tb, "m2");
+        mb2.comment("The second module.")
+                .exports("pkg2")
+                .requires("m1")
+                .classes("package pkg2; /** Class B */ public class B { /** Field f */ public int f = pkg1.A.k; }")
+                .write(src);
+        execTask("--module-source-path", src.toString(),
+                "--patch-module", "m1=" + patchPath.toString(),
+                "--module-path", modulePath.toString(),
+                "--module", "m2");
+        checkModulesSpecified("m2");
+        checkPackagesIncluded("pkg2");
+        checkMembersSelected("pkg2.B.f");
+    }
+
+    @Test
+    public void testAddReadsOption(Path base) throws Exception {
+        Path src = base.resolve("src");
+        Path modulePath = base.resolve("modules");
+
+        ModuleBuilder mb1 = new ModuleBuilder(tb, "m1");
+        mb1.comment("Module on module path.")
+                .exports("pkg1")
+                .classes("package pkg1; /** Class A */ public class A {}")
+                .build(modulePath);
+
+        ModuleBuilder mb2 = new ModuleBuilder(tb, "m2");
+        mb2.comment("The second module.")
+                .exports("pkg2")
+                .classes("package pkg2; /** Class B */ public class B { /** Field f */ public pkg1.A f;}")
+                .write(src);
+        execTask("--module-source-path", src.toString(),
+                "--module-path", modulePath.toString(),
+                "--add-modules", "m1",
+                "--add-reads", "m2=m1",
+                "--module", "m2");
+        checkModulesSpecified("m2");
+        checkPackagesIncluded("pkg2");
+        checkMembersSelected("pkg2.B.f");
+    }
+
+    @Test
+    public void testModuleOptionsWithLegacy(Path base) throws Exception {
+        Files.createDirectory(base);
+        Path src = base.resolve("src");
+        Path classpath = base.resolve("classpath");
+        Path modulePath = base.resolve("modules");
+
+        tb.writeJavaFiles(classpath, "package pkg1; /** Class C */ public class C { }");
+        new JavacTask(tb)
+                .files(classpath.resolve("pkg1/C.java"))
+                .run();
+
+        ModuleBuilder mb = new ModuleBuilder(tb, "m1");
+        mb.comment("The first module.")
+                .exports("pub")
+                .classes("package pub; /** Class M */ public class M { }")
+                .build(modulePath);
+
+        tb.writeJavaFiles(src, "package pkg; /** Class L */ public class L { public pkg1.C f1; public pub.M f2; }");
+
+        execTask("--source-path", src.toString(),
+                "--class-path", classpath.toString(),
+                "--module-path", modulePath.toString(),
+                "--add-modules", "m1",
+                "pkg");
+        checkPackagesIncluded("pkg");
+        checkTypesIncluded("pkg.L");
+        checkMembersSelected("pkg.L.f1");
+        checkMembersSelected("pkg.L.f2");
+        assertAbsent("error", OutputKind.DIRECT);
+    }
+
+    /**
      * Tests diamond graph, inspired by javac diamond tests.
      *
      *
@@ -262,48 +525,48 @@
         new ModuleBuilder(tb, "J")
                 .comment("The J module.")
                 .exports("openJ")
-                .classes("package openJ;  /** Klass J open. */ public class J { }")
-                .classes("package closedJ; /** Klass J closed. */ public class J  { }")
+                .classes("package openJ;  /** Class J open. */ public class J { }")
+                .classes("package closedJ; /** Class J closed. */ public class J  { }")
                 .write(src);
 
         new ModuleBuilder(tb, "L")
                 .comment("The L module.")
                 .exports("openL")
                 .requiresPublic("P")
-                .classes("package openL; /** Klass L open */ public class L { }")
-                .classes("package closedL;  /** Klass L closed */ public class L { }")
+                .classes("package openL; /** Class L open */ public class L { }")
+                .classes("package closedL;  /** Class L closed */ public class L { }")
                 .write(src);
 
         new ModuleBuilder(tb, "N")
                 .comment("The N module.")
                 .exports("openN")
                 .requiresPublic("O")
-                .classes("package openN; /** Klass N open */ public class N  { }")
-                .classes("package closedN; /** Klass N closed */ public class N { }")
+                .classes("package openN; /** Class N open */ public class N  { }")
+                .classes("package closedN; /** Class N closed */ public class N { }")
                 .write(src);
 
         new ModuleBuilder(tb, "O")
                 .comment("The O module.")
                 .exports("openO")
                 .requires("J")
-                .classes("package openO; /** Klass O open. */ public class O { openJ.J j; }")
-                .classes("package closedO;  /** Klass O closed. */ public class O { }")
+                .classes("package openO; /** Class O open. */ public class O { openJ.J j; }")
+                .classes("package closedO;  /** Class O closed. */ public class O { }")
                 .write(src);
 
         new ModuleBuilder(tb, "P")
                 .comment("The O module.")
                 .exports("openP")
                 .requires("J")
-                .classes("package openP; /** Klass O open. */ public class O { openJ.J j; }")
-                .classes("package closedP;  /** Klass O closed. */ public class O { }")
+                .classes("package openP; /** Class O open. */ public class O { openJ.J j; }")
+                .classes("package closedP;  /** Class O closed. */ public class O { }")
                 .write(src);
 
         new ModuleBuilder(tb, "Q")
                 .comment("The Q module.")
                 .exports("openQ")
                 .requires("J")
-                .classes("package openQ; /** Klass Q open. */ public class Q { openJ.J j; }")
-                .classes("package closedQ;  /** Klass Q closed. */ public class Q { }")
+                .classes("package openQ; /** Class Q open. */ public class Q { openJ.J j; }")
+                .classes("package closedQ;  /** Class Q closed. */ public class Q { }")
                 .write(src);
 
     }
--- a/langtools/test/jdk/jshell/SimpleRegressionTest.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/jdk/jshell/SimpleRegressionTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
  */
 
 /*
- * @test 8130450 8158906 8154374
+ * @test 8130450 8158906 8154374 8166400
  * @summary simple regression test
  * @build KullaTesting TestingInputStream
  * @run testng SimpleRegressionTest
@@ -149,4 +149,21 @@
         assertEval("class C {}");
         assertEval("C.class.getClassLoader() == Thread.currentThread().getContextClassLoader()", "true");
     }
+
+    public void testArayRepresentation() {
+        assertEval("new int[4]", "int[4] { 0, 0, 0, 0 }");
+        assertEval("new int[0]", "int[0] {  }");
+        assertEval("new byte[2]", "byte[2] { 0, 0 }");
+        assertEval("new short[] { 1234, 4321 }", "short[2] { 1234, 4321 }");
+        assertEval("new long[] { 123456789 }", "long[1] { 123456789 }");
+        assertEval("new float[] { -23.5645f, 1.0101f }", "float[2] { -23.5645, 1.0101 }");
+        assertEval("new double[] { 1/8, Math.PI }", "double[2] { 0.0, 3.141592653589793 }");
+        assertEval("new String[] { \"hi\", \"low\", null }", "String[3] { \"hi\", \"low\", null }");
+        assertEval("new char[] { 'a', 34, 77 }", "char[3] { 'a', '\"', 'M' }");
+        assertEval("new boolean[] { false, true }", "boolean[2] { false, true }");
+        assertEval("new int[][] { new int[] {44, 55}, new int[] {88,99}}",
+                "int[][2] { int[2] { 44, 55 }, int[2] { 88, 99 } }");
+        assertEval("new Object[] { \"howdy\", new int[] { 33, 44, 55 }, new String[] { \"up\", \"down\" }}",
+                "Object[3] { \"howdy\", int[3] { 33, 44, 55 }, String[2] { \"up\", \"down\" } }");
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/AnonymousClass/AnonymousInSuperCallNegTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,31 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8166108
+ * @summary Verify that a program cannot access instance state before construction
+ * @compile/fail/ref=AnonymousInSuperCallNegTest.out -XDrawDiagnostics AnonymousInSuperCallNegTest.java
+ */
+
+public class AnonymousInSuperCallNegTest {
+
+    static class Base {
+        Base(Object o) {}
+    }
+
+    static class Outer {
+        class Inner {}
+    }
+
+    public static class JavacBug extends Base {
+        int x;
+        JavacBug() {
+            super(new Outer().new Inner() {
+                void foo() {
+                    System.out.println("x = " + x);
+                }
+            }); }
+    }
+
+    public static void main(String[] args) {
+        new JavacBug();
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/AnonymousClass/AnonymousInSuperCallNegTest.out	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,2 @@
+AnonymousInSuperCallNegTest.java:23:49: compiler.err.cant.ref.before.ctor.called: x
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/AnonymousClass/AnonymousInSuperCallTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8166108
+ * @summary Verify that javac skips outer this to anonymous inner classes in super type constructor calls
+ *
+ */
+
+public class AnonymousInSuperCallTest {
+
+    static class Base {
+        Base(Object o) {}
+    }
+
+    static class Outer {
+        class Inner {}
+    }
+
+    public static class JavacBug extends Base {
+        JavacBug() { super(new Outer().new Inner() {}); }
+    }
+
+    public static void main(String[] args) {
+        new JavacBug();
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/TryWithResources/TwrAndTypeVariables2Test.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8163027
+ * @summary AssertionError while compiling program that uses try with resources
+ * @compile TwrAndTypeVariables2Test.java
+ */
+
+abstract class TwrAndTypeVariables2Test_01 implements AutoCloseable {
+    @Override
+    public void close() {
+    }
+    public boolean close(long timeout) {
+        return true;
+    }
+}
+
+public abstract class TwrAndTypeVariables2Test<C extends TwrAndTypeVariables2Test_01> {
+    abstract C newCloseable();
+
+    void m() throws Exception{
+        try(C p= newCloseable()){
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/typeAnnotations/classfile/AnnotatedExtendsTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8164519
+ * @summary Verify that javac emits proper super type index (65535) for an annotated extends
+ * @library /tools/lib
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ *          jdk.compiler/com.sun.tools.javac.main
+ *          jdk.jdeps/com.sun.tools.javap
+ * @build toolbox.ToolBox toolbox.JavapTask
+ * @run compile -g AnnotatedExtendsTest.java
+ * @run main AnnotatedExtendsTest
+ */
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+import toolbox.JavapTask;
+import toolbox.Task;
+import toolbox.ToolBox;
+
+public class AnnotatedExtendsTest {
+
+    @Target(ElementType.TYPE_USE)
+    public @interface TA {
+    };
+
+    public class Inner extends @TA Object {}
+
+    public static strictfp void main(String args[]) throws Exception {
+        ToolBox tb = new ToolBox();
+        Path classPath = Paths.get(ToolBox.testClasses, "AnnotatedExtendsTest$Inner.class");
+        String javapOut = new JavapTask(tb)
+                .options("-v", "-p")
+                .classes(classPath.toString())
+                .run()
+                .getOutput(Task.OutputKind.DIRECT);
+        if (!javapOut.contains("0: #21(): CLASS_EXTENDS, type_index=65535"))
+            throw new AssertionError("Expected output missing: " + javapOut);
+    }
+}
\ No newline at end of file
--- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ClassExtends.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ClassExtends.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
 
 /*
  * @test
- * @bug 8042451
+ * @bug 8042451 8164519
  * @summary Test population of reference info for class extends clauses
  * @modules jdk.jdeps/com.sun.tools.classfile
  * @compile -g Driver.java ReferenceInfoUtil.java ClassExtends.java
@@ -33,21 +33,21 @@
  */
 public class ClassExtends {
 
-    @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1)
+    @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = 65535)
     @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1)
     public String regularClass() {
         return "class %TEST_CLASS_NAME% extends @TA Object implements Cloneable, @TB Runnable {"
                + "  public void run() { } }";
     }
 
-    @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = -1)
+    @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = 65535)
     @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1)
     public String regularClassRepeatableAnnotation() {
         return "class %TEST_CLASS_NAME% extends @RTA @RTA Object implements Cloneable, @RTB @RTB Runnable {"
                 + "  public void run() { } }";
     }
 
-    @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1,
+    @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = 65535,
             genericLocation = { 3, 0 })
     @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1,
             genericLocation  = { 3, 1 })
@@ -55,7 +55,7 @@
         return "class %TEST_CLASS_NAME% extends HashMap<@TA String, String> implements Cloneable, Map<String, @TB String>{ } ";
     }
 
-    @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = -1,
+    @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = 65535,
             genericLocation = { 3, 0 })
     @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1,
             genericLocation  = { 3, 1 })
@@ -63,21 +63,21 @@
         return "class %TEST_CLASS_NAME% extends HashMap<@RTA @RTA String, String> implements Cloneable, Map<String, @RTB @RTB String>{ } ";
     }
 
-    @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1)
+    @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = 65535)
     @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1)
     public String abstractClass() {
         return "abstract class %TEST_CLASS_NAME% extends @TA Date implements Cloneable, @TB Runnable {"
                + "  public void run() { } }";
     }
 
-    @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = -1)
+    @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = 65535)
     @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1)
     public String abstractClassRepeatableAnnotation() {
         return "abstract class %TEST_CLASS_NAME% extends @RTA @RTA Date implements Cloneable, @RTB @RTB Runnable {"
                 + "  public void run() { } }";
     }
 
-    @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = -1,
+    @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = 65535,
             genericLocation = { 3, 0 })
     @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1,
             genericLocation  = { 3, 1 })
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/file/MultiReleaseJar/MutliReleaseModuleInfoTest.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8156568
+ * @summary Update javac to support compiling against a modular multi-release JAR
+ * @library /tools/lib
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ *          jdk.compiler/com.sun.tools.javac.main
+ * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
+ * @run main MutliReleaseModuleInfoTest
+ */
+
+import java.nio.file.Paths;
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.ModuleElement;
+import javax.lang.model.element.ModuleElement.RequiresDirective;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.util.ElementFilter;
+
+import toolbox.JarTask;
+import toolbox.JavacTask;
+import toolbox.Task;
+import toolbox.ToolBox;
+
+
+public class MutliReleaseModuleInfoTest {
+
+    private final String service_mi =
+            "module service {\n" +
+            "}\n";
+
+    private final String service =
+            "package service;\n" +
+            "public class Service {\n" +
+            "}\n";
+
+    private final String service_mi9 =
+            "module service {\n" +
+            "    requires java.desktop;\n" +
+            "}\n";
+
+    private final String service9 =
+            "package service;\n" +
+            "public class Service {\n" +
+            "}\n";
+
+    private final String client_mi =
+            "module client {\n" +
+            "    requires service;\n" +
+            "}\n";
+
+    private final String manifest =
+        "Manifest-Version: 1.0\n" +
+        "Multi-Release: true\n";
+
+    private final ToolBox tb = new ToolBox();
+
+    public static void main(String [] args) throws Exception {
+        new MutliReleaseModuleInfoTest().runTest();
+    }
+
+    private void runTest() throws Exception {
+        tb.createDirectories("classes", "classes/META-INF/versions/9");
+        new JavacTask(tb)
+                .outdir("classes")
+                .sources(service_mi, service)
+                .run();
+        new JavacTask(tb)
+                .outdir("classes/META-INF/versions/9")
+                .sources(service_mi9, service9)
+                .run();
+        new JarTask(tb, "multi-release.jar")
+                .manifest(manifest)
+                .baseDir("classes")
+                .files("module-info.class", "service/Service.class",
+                       "META-INF/versions/9/module-info.class",
+                       "META-INF/versions/9/service/Service.class")
+                .run();
+        tb.cleanDirectory(Paths.get("classes"));
+
+        tb.writeFile("module-info.java", client_mi);
+        Task.Result result = new JavacTask(tb)
+                .outdir("classes")
+                .options("-processor", VerifyRequires.class.getName(),
+                               "--module-path", "multi-release.jar")
+                .files("module-info.java")
+                .run();
+        result.writeAll();
+        tb.deleteFiles("module-info.java");
+
+        tb.deleteFiles(
+                "multi-release.jar",
+                "classes/module-info.class",
+                "classes"
+        );
+    }
+
+    @SupportedAnnotationTypes("*")
+    public static final class VerifyRequires extends AbstractProcessor {
+
+        @Override
+        public boolean process(Set<? extends TypeElement> u, RoundEnvironment r) {
+            ModuleElement sm = processingEnv.getElementUtils().getModuleElement("service");
+            if (sm == null) {
+                throw new AssertionError("Cannot find the service module!");
+            }
+            boolean foundjd = false;
+            for (RequiresDirective rd : ElementFilter.requiresIn(sm.getDirectives())) {
+                foundjd |= rd.getDependency().getSimpleName().contentEquals("java.desktop");
+            }
+            if (!foundjd) {
+                throw new AssertionError("Missing dependency on java desktop module!");
+            }
+            return false;
+        }
+
+        @Override
+        public SourceVersion getSupportedSourceVersion() {
+            return SourceVersion.latest();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/processing/model/trees/BrokenEnumConstructor.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8047347
+ * @summary Verify that an explicit (incorrect) super constructor invocation in enums is not cleared
+ *          by JavacProcessingEnvironment
+ * @library /tools/javac/lib
+ * @modules jdk.compiler
+ * @build JavacTestingAbstractProcessor OnDemandAttribution
+ * @compile/process/fail/ref=BrokenEnumConstructor.out -XDrawDiagnostics -processor OnDemandAttribution BrokenEnumConstructor.java
+ */
+
+public enum BrokenEnumConstructor {
+
+    A;
+
+    BrokenEnumConstructor() {super(); /*illegal*/}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/processing/model/trees/BrokenEnumConstructor.out	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,2 @@
+BrokenEnumConstructor.java:39:30: compiler.err.call.to.super.not.allowed.in.enum.ctor: BrokenEnumConstructor
+1 error
--- a/langtools/test/tools/javac/processing/model/trees/OnDemandAttribution.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/langtools/test/tools/javac/processing/model/trees/OnDemandAttribution.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,56 +23,88 @@
 
 /*
  * @test
- * @bug 8038455
+ * @bug 8038455 8047347
  * @summary Verify that in-method ClassSymbols from one round do not affect ClassSymbols in
  *          following rounds.
  * @library /tools/javac/lib
  * @modules jdk.compiler
  * @build JavacTestingAbstractProcessor OnDemandAttribution
- * @compile/process -processor OnDemandAttribution OnDemandAttribution.java
+ * @clean Gen
+ * @compile/process -processor OnDemandAttribution OnDemandAttributionData.java
  */
 
+import java.io.IOException;
+import java.io.Writer;
 import java.util.*;
 import javax.annotation.processing.*;
 import javax.lang.model.element.*;
-import static javax.lang.model.util.ElementFilter.*;
+import static javax.lang.model.util.ElementFilter.constructorsIn;
 import com.sun.source.tree.*;
 import com.sun.source.util.*;
 
 public class OnDemandAttribution extends JavacTestingAbstractProcessor {
 
     public OnDemandAttribution() {
-        class Local { }
-        new Object() { };
     }
 
+    int round;
+    Set<String> roots = new HashSet<>();
+
     public boolean process(Set<? extends TypeElement> annos,RoundEnvironment rEnv) {
-        TypeElement currentClass = elements.getTypeElement("OnDemandAttribution");
-        ExecutableElement constr = constructorsIn(currentClass.getEnclosedElements()).get(0);
-        Trees trees = Trees.instance(processingEnv);
-        TreePath path = trees.getPath(constr);
+        for (Element root : rEnv.getRootElements()) {
+            while (root.getEnclosingElement().getKind() != ElementKind.PACKAGE) {
+                root = root.getEnclosingElement();
+            }
+            roots.add(((TypeElement) root).getQualifiedName().toString());
+        }
+        for (String root : roots) {
+            TypeElement currentClass = elements.getTypeElement(root);
+            ExecutableElement constr = constructorsIn(currentClass.getEnclosedElements()).get(0);
+            Trees trees = Trees.instance(processingEnv);
+            TreePath path = trees.getPath(constr);
 
-        new TreePathScanner<Void, Void>() {
-            @Override public Void visitClass(ClassTree node, Void p) {
-                if (node.getSimpleName().contentEquals("Local")) {
-                     //will also attribute the body on demand:
+            new TreePathScanner<Void, Void>() {
+                @Override public Void visitClass(ClassTree node, Void p) {
+                    if (node.getSimpleName().contentEquals("Local")) {
+                         //will also attribute the body on demand:
+                        Element el = trees.getElement(getCurrentPath());
+                        Name binaryName = elements.getBinaryName((TypeElement) el);
+                        if (!binaryName.contentEquals("OnDemandAttributionData$1Local")) {
+                            throw new IllegalStateException("Incorrect binary name=" + binaryName);
+                        }
+                    }
+                    return super.visitClass(node, p);
+                }
+                @Override public Void visitNewClass(NewClassTree node, Void p) {
                     Element el = trees.getElement(getCurrentPath());
-                    Name binaryName = elements.getBinaryName((TypeElement) el);
-                    if (!binaryName.contentEquals("OnDemandAttribution$1Local")) {
+                    Name binaryName = elements.getBinaryName((TypeElement) el.getEnclosingElement());
+                    if (!binaryName.contentEquals("OnDemandAttributionData$1")) {
                         throw new IllegalStateException("Incorrect binary name=" + binaryName);
                     }
+                    return super.visitNewClass(node, p);
                 }
-                return super.visitClass(node, p);
+                @Override
+                public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
+                    if (trees.getElement(getCurrentPath()) == null)
+                        throw new IllegalStateException("No element for: " + node);
+                    return super.visitMethodInvocation(node, p);
+                }
+                @Override
+                public Void visitIdentifier(IdentifierTree node, Void p) {
+                    if (trees.getElement(getCurrentPath()) == null)
+                        throw new IllegalStateException("No element for: " + node);
+                    return super.visitIdentifier(node, p);
+                }
+            }.scan(path, null);
+        }
+
+        if (round++ == 0) {
+            try (Writer out = filer.createSourceFile("Gen").openWriter()) {
+                out.write("class Gen { public static long C = 1; }");
+            } catch (IOException ex) {
+                throw new IllegalStateException(ex);
             }
-            @Override public Void visitNewClass(NewClassTree node, Void p) {
-                Element el = trees.getElement(getCurrentPath());
-                Name binaryName = elements.getBinaryName((TypeElement) el.getEnclosingElement());
-                if (!binaryName.contentEquals("OnDemandAttribution$1")) {
-                    throw new IllegalStateException("Incorrect binary name=" + binaryName);
-                }
-                return super.visitNewClass(node, p);
-            }
-        }.scan(path, null);
+        }
 
         return true;
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/processing/model/trees/OnDemandAttributionData.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+public class OnDemandAttributionData {
+
+    public OnDemandAttributionData(int i) {
+        class Local { }
+        new Aux(Gen.C) { };
+    }
+
+    class Aux {
+        Aux(String str) {}
+        Aux(int i) {}
+        Aux(long l) {}
+    }
+
+    private void methodAttributionTest() {
+        System.err.println("");
+    }
+
+    enum E {
+        A;
+
+        final int i;
+
+        E() {
+            i = Integer.parseInt("1");
+        }
+
+    }
+
+    enum E2 {
+        A;
+
+        {
+            int i = Integer.parseInt("1");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeps/MultiReleaseJar.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,274 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8153654
+ * @summary Tests for jdeps tool with multi-release jar files
+ * @modules jdk.jdeps/com.sun.tools.jdeps
+ * @library mrjar mrjar/base mrjar/9 mrjar/10 mrjar/v9 mrjar/v10
+ * @build test.* p.* q.*
+ * @run testng MultiReleaseJar
+ */
+
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.TimeUnit;
+
+public class MultiReleaseJar {
+    Path mrjar;
+    String testJdk;
+    String fileSep;
+    Path cmdPath;
+
+    @BeforeClass
+    public void initialize() throws Exception {
+        mrjar = Paths.get(System.getProperty("test.classes", "."), "mrjar");
+        testJdk = System.getProperty("test.jdk");
+        fileSep = System.getProperty("file.separator");
+        cmdPath = Paths.get(testJdk, "bin");
+    }
+
+    @Test
+    public void basic() throws Exception {
+        // build the jar file
+        Result r = run("jar -cf Version.jar -C base test --release 9 -C 9 test --release 10 -C 10 test");
+        checkResult(r);
+
+        // try out a bunch of things
+        r = run("jdeps --multi-release 9  -v missing.jar");
+        checkResult(r, false, "Warning: Path does not exist: missing.jar");
+
+        r = run("jdeps -v Version.jar");
+        checkResult(r, false, "the --multi-release option is not set");
+
+        r = run("jdeps --multi-release base  -v Version.jar");
+        checkResult(r, true,
+                "Version.jar ->",
+                "test.Version",
+                "test.Version"
+        );
+
+        r = run("jdeps --multi-release 9  -v Version.jar");
+        checkResult(r, true,
+                "Version.jar ->",
+                "9/test.NonPublic",
+                "9/test.NonPublic",
+                "9/test.Version",
+                "9/test.Version",
+                "9/test.Version",
+                "9/test.Version"
+        );
+
+        r = run("jdeps --multi-release 10  -v Version.jar");
+        checkResult(r, true,
+                "Version.jar ->",
+                "10/test.Version",
+                "10/test.Version",
+                "10/test.Version",
+                "10/test.Version",
+                "9/test.NonPublic",
+                "9/test.NonPublic"
+        );
+
+        r = run("jdeps --multi-release 8  -v Version.jar");
+        checkResult(r, false, "Error: invalid argument for option: 8");
+
+        r = run("jdeps --multi-release 9.1  -v Version.jar");
+        checkResult(r, false, "Error: invalid argument for option: 9.1");
+
+        r = run("jdeps -v -R -cp Version.jar test/Main.class");
+        checkResult(r, false, "the --multi-release option is not set");
+
+        r = run("jdeps -v -R -cp Version.jar -multi-release 9 test/Main.class");
+        checkResult(r, false,
+                "Error: unknown option: -multi-release",
+                "Usage: jdeps <options> <path",
+                "use -h, -?, -help, or --help"
+        );
+
+        r = run("jdeps -v -R -cp Version.jar --multi-release 9 test/Main.class");
+        checkResult(r, true,
+                "Main.class ->",
+                "Main.class ->",
+                "test.Main",
+                "test.Main",
+                "test.Main",
+                "Version.jar ->",
+                "9/test.NonPublic",
+                "9/test.NonPublic",
+                "9/test.Version",
+                "9/test.Version",
+                "9/test.Version",
+                "9/test.Version"
+        );
+
+        r = run("jdeps -v -R -cp Version.jar --multi-release 10 test/Main.class");
+        checkResult(r, true,
+                "Main.class ->",
+                "Main.class ->",
+                "test.Main",
+                "test.Main",
+                "test.Main",
+                "Version.jar ->",
+                "10/test.Version",
+                "10/test.Version",
+                "10/test.Version",
+                "10/test.Version",
+                "9/test.NonPublic",
+                "9/test.NonPublic"
+        );
+
+        r = run("jdeps -v -R -cp Version.jar --multi-release base test/Main.class");
+        checkResult(r, true,
+                "Main.class ->",
+                "Main.class ->",
+                "test.Main",
+                "test.Main",
+                "test.Main",
+                "Version.jar ->",
+                "test.Version",
+                "test.Version"
+        );
+
+        r = run("jdeps -v -R -cp Version.jar --multi-release 9.1 test/Main.class");
+        checkResult(r, false, "Error: invalid argument for option: 9.1");
+
+        // Rebuild jar without version 10
+        r = run("jar -cf Version.jar -C base test --release 9 -C 9 test");
+        checkResult(r);
+
+        // but ask for version 10
+        r = run("jdeps -v -R -cp Version.jar --multi-release 10 test/Main.class");
+        checkResult(r, true,
+                "Main.class ->",
+                "Main.class ->",
+                "test.Main",
+                "test.Main",
+                "test.Main",
+                "Version.jar ->",
+                "9/test.NonPublic",
+                "9/test.NonPublic",
+                "9/test.Version",
+                "9/test.Version",
+                "9/test.Version",
+                "9/test.Version"
+        );
+    }
+
+    @Test
+    public void ps_and_qs() throws Exception {
+        // build the jar file
+        Result r = run("jar -cf PQ.jar -C base p --release 9 -C v9 p -C v9 q --release 10 -C v10 q");
+        checkResult(r);
+
+        r = run("jdeps -v -R -cp PQ.jar --multi-release base PQ.jar");
+        checkResult(r, true,
+                "PQ.jar -> java.base",
+                "p.Foo"
+        );
+
+        r = run("jdeps -v -R -cp PQ.jar --multi-release 9 PQ.jar");
+        checkResult(r, true,
+                "PQ.jar -> java.base",
+                "9/p.Foo",
+                "9/p.Foo",
+                "9/q.Bar"
+        );
+
+
+        r = run("jdeps -v -R -cp PQ.jar --multi-release 10 PQ.jar");
+        checkResult(r, true,
+                "PQ.jar -> java.base",
+                "10/q.Bar",
+                "10/q.Bar",
+                "10/q.Gee",
+                "9/p.Foo",
+                "9/p.Foo"
+        );
+    }
+
+    static class Result {
+        final String cmd;
+        final int rc;
+        final String out;
+        final String err;
+        Result(String cmd, int rc, String out, String err) {
+            this.cmd = cmd;
+            this.rc = rc;
+            this.out = out;
+            this.err = err;
+        }
+    }
+
+    Result run(String cmd) throws Exception {
+        String[] cmds = cmd.split(" +");
+        cmds[0] = cmdPath.resolve(cmds[0]).toString();
+        ProcessBuilder pb = new ProcessBuilder(cmds);
+        pb.directory(mrjar.toFile());
+        Process p = pb.start();
+        p.waitFor(10, TimeUnit.SECONDS);
+        String out;
+        try (InputStream is = p.getInputStream()) {
+            out = new String(is.readAllBytes());
+        }
+        String err;
+        try (InputStream is = p.getErrorStream()) {
+            err = new String(is.readAllBytes());
+        }
+        return new Result(cmd, p.exitValue(), out, err);
+    }
+
+    void checkResult(Result r) throws Exception {
+        System.out.println(r.cmd);
+        System.out.println(r.out);
+        if (r.rc != 0) {
+            System.out.println(r.err);
+            throw new Exception("rc=" + r.rc);
+        }
+        System.out.println();
+    }
+
+    void checkResult(Result r, boolean checkrc, String... lines) throws Exception {
+        System.out.println(r.cmd);
+        System.out.println(r.out);
+        if (checkrc && r.rc != 0) {
+            System.out.println(r.err);
+            throw new Exception("rc=" + r.rc);
+        }
+        String[] out = r.out.split("\r?\n");
+        Assert.assertEquals(out.length, lines.length);
+        int n = 0;
+        for (String line : lines) {
+            Assert.assertTrue(out[n++].contains(line), "\"" + line + "\"");
+        }
+        System.out.println();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeps/mrjar/10/test/Version.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test;
+
+public class Version {
+    public int getVersion() {
+        NonPublic np = new NonPublic();
+        String ignore = np.toString();
+        return 10;
+    }
+
+    private String getStringVersion() {
+        return "10";
+    }
+
+    private void foo() {
+        if (getStringVersion() == null) throw new NullPointerException();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeps/mrjar/9/test/NonPublic.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test;
+
+class NonPublic {
+    public String toString() {
+        return "NonPublic";
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeps/mrjar/9/test/Version.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test;
+
+public class Version {
+    public int getVersion() {
+        NonPublic np = new NonPublic();
+        String ignore = np.toString();
+        return 9;
+    }
+
+    private void foo() {
+        if (getVersion() != 9) throw new RuntimeException();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeps/mrjar/base/p/Foo.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package p;
+
+// dependencies: Object
+public class Foo {
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeps/mrjar/base/test/Version.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test;
+
+public class Version {
+    public int getVersion() {
+        return 8;
+    }
+
+    private void foo() {
+        if (getVersion() != 8) throw new IllegalStateException();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeps/mrjar/test/Main.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test;
+
+public class Main {
+    public void run() {
+        Version v = new Version();
+        v.getVersion();
+    }
+
+    public static void main(String[] args) {
+        (new Main()).run();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeps/mrjar/v10/q/Bar.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package q;
+
+// dependencies: Object, q.Gee
+class Bar {
+    Gee gee = new Gee();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeps/mrjar/v10/q/Gee.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package q;
+
+// dependencies: Object
+class Gee {
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeps/mrjar/v9/p/Foo.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package p;
+
+// dependencies: Object, q.Bar
+public class Foo {
+    void crash() {
+        throw new RuntimeException();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeps/mrjar/v9/q/Bar.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package q;
+
+// dependecies: Object
+class Bar {
+}
--- a/make/MainSupport.gmk	Thu Sep 29 11:13:42 2016 +0530
+++ b/make/MainSupport.gmk	Fri Sep 30 09:28:18 2016 -0700
@@ -31,11 +31,13 @@
 _MAINSUPPORT_GMK := 1
 
 # Run the tests specified by $1, with PRODUCT_HOME specified by $2
+# JT_JAVA is picked up by the jtreg launcher and used to run Jtreg itself.
 define RunTests
 	($(CD) $(SRC_ROOT)/test && $(MAKE) $(MAKE_ARGS) -j1 -k MAKEFLAGS= \
 	    JT_HOME=$(JT_HOME) PRODUCT_HOME=$(strip $2) \
 	    TEST_IMAGE_DIR=$(TEST_IMAGE_DIR) \
 	    ALT_OUTPUTDIR=$(OUTPUT_ROOT) TEST_JOBS=$(TEST_JOBS) \
+	    JT_JAVA=$(BOOT_JDK) \
 	    JOBS=$(JOBS) $1) || true
 endef
 
--- a/nashorn/.hgtags	Thu Sep 29 11:13:42 2016 +0530
+++ b/nashorn/.hgtags	Fri Sep 30 09:28:18 2016 -0700
@@ -370,3 +370,4 @@
 e05400ba935753c77697af936db24657eb811022 jdk-9+134
 cb00d5ef023a18a66fcb4311ed4474d4145c66e9 jdk-9+135
 f11b8f5c4ccbf9c87d283815abac6c0117fba3c0 jdk-9+136
+17ed43add2f9e3528686cd786ae2ed49c8ed36e9 jdk-9+137
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java	Fri Sep 30 09:28:18 2016 -0700
@@ -2512,7 +2512,8 @@
         final List<PropertyNode> elements = objectNode.getElements();
 
         final List<MapTuple<Expression>> tuples = new ArrayList<>();
-        final List<PropertyNode> gettersSetters = new ArrayList<>();
+        // List below will contain getter/setter properties and properties with computed keys (ES6)
+        final List<PropertyNode> specialProperties = new ArrayList<>();
         final int ccp = getCurrentContinuationEntryPoint();
         final List<Splittable.SplitRange> ranges = objectNode.getSplitRanges();
 
@@ -2522,11 +2523,14 @@
         for (final PropertyNode propertyNode : elements) {
             final Expression value = propertyNode.getValue();
             final String key = propertyNode.getKeyName();
+            final boolean isComputedOrAccessor = propertyNode.isComputed() || value == null;
+
             // Just use a pseudo-symbol. We just need something non null; use the name and zero flags.
-            final Symbol symbol = value == null ? null : new Symbol(key, 0);
-
-            if (value == null) {
-                gettersSetters.add(propertyNode);
+            final Symbol symbol = isComputedOrAccessor ? null : new Symbol(key, 0);
+
+            if (isComputedOrAccessor) {
+                // Properties with computed names or getter/setters need special handling.
+                specialProperties.add(propertyNode);
             } else if (propertyNode.getKey() instanceof IdentNode &&
                        key.equals(ScriptObject.PROTO_PROPERTY_NAME)) {
                 // ES6 draft compliant __proto__ inside object literal
@@ -2542,7 +2546,7 @@
 
             //for literals, a value of null means object type, i.e. the value null or getter setter function
             //(I think)
-            final Class<?> valueType = (!useDualFields() || value == null || value.getType().isBoolean()) ? Object.class : value.getType().getTypeClass();
+            final Class<?> valueType = (!useDualFields() || isComputedOrAccessor || value.getType().isBoolean()) ? Object.class : value.getType().getTypeClass();
             tuples.add(new MapTuple<Expression>(key, symbol, Type.typeFor(valueType), value) {
                 @Override
                 public Class<?> getValueType() {
@@ -2590,26 +2594,41 @@
             method.invoke(ScriptObject.SET_GLOBAL_OBJECT_PROTO);
         }
 
-        for (final PropertyNode propertyNode : gettersSetters) {
-            final FunctionNode getter = propertyNode.getGetter();
-            final FunctionNode setter = propertyNode.getSetter();
-
-            assert getter != null || setter != null;
-
-            method.dup().loadKey(propertyNode.getKey());
-            if (getter == null) {
-                method.loadNull();
+        for (final PropertyNode propertyNode : specialProperties) {
+
+            method.dup();
+
+            if (propertyNode.isComputed()) {
+                assert propertyNode.getKeyName() == null;
+                loadExpressionAsObject(propertyNode.getKey());
+            } else {
+                method.loadKey(propertyNode.getKey());
+            }
+
+            if (propertyNode.getValue() != null) {
+                loadExpressionAsObject(propertyNode.getValue());
+                method.load(0);
+                method.invoke(ScriptObject.GENERIC_SET);
             } else {
-                getter.accept(this);
-            }
-
-            if (setter == null) {
-                method.loadNull();
-            } else {
-                setter.accept(this);
-            }
-
-            method.invoke(ScriptObject.SET_USER_ACCESSORS);
+                final FunctionNode getter = propertyNode.getGetter();
+                final FunctionNode setter = propertyNode.getSetter();
+
+                assert getter != null || setter != null;
+
+                if (getter == null) {
+                    method.loadNull();
+                } else {
+                    getter.accept(this);
+                }
+
+                if (setter == null) {
+                    method.loadNull();
+                } else {
+                    setter.accept(this);
+                }
+
+                method.invoke(ScriptObject.SET_USER_ACCESSORS);
+            }
         }
     }
 
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/PropertyNode.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/PropertyNode.java	Fri Sep 30 09:28:18 2016 -0700
@@ -86,11 +86,11 @@
     }
 
     /**
-     * Get the name of the property key
-     * @return key name
+     * Get the name of the property key, or {@code null} if key is a computed name.
+     * @return key name or null
      */
     public String getKeyName() {
-        return key instanceof PropertyKey ? ((PropertyKey) key).getPropertyName() : null;
+        return !computed && key instanceof PropertyKey ? ((PropertyKey) key).getPropertyName() : null;
     }
 
     @Override
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1176,10 +1176,9 @@
                     labelStatement();
                     return;
                 }
-                final boolean allowPropertyFunction = (reparseFlags & ScriptFunctionData.IS_PROPERTY_ACCESSOR) != 0;
-                final boolean isES6Method = (reparseFlags & ScriptFunctionData.IS_ES6_METHOD) != 0;
-                if(allowPropertyFunction) {
-                    final String ident = (String)getValue();
+
+                if ((reparseFlags & ScriptFunctionData.IS_PROPERTY_ACCESSOR) != 0) {
+                    final String ident = (String) getValue();
                     final long propertyToken = token;
                     final int propertyLine = line;
                     if (GET_NAME.equals(ident)) {
@@ -1191,19 +1190,22 @@
                         addPropertyFunctionStatement(propertySetterFunction(propertyToken, propertyLine));
                         return;
                     }
-                } else if (isES6Method) {
-                    final String ident = (String)getValue();
-                    IdentNode identNode = createIdentNode(token, finish, ident).setIsPropertyName();
-                    final long propertyToken = token;
-                    final int propertyLine = line;
-                    next();
-                    // Code below will need refinement once we fully support ES6 class syntax
-                    final int flags = CONSTRUCTOR_NAME.equals(ident) ? FunctionNode.ES6_IS_CLASS_CONSTRUCTOR : FunctionNode.ES6_IS_METHOD;
-                    addPropertyFunctionStatement(propertyMethodFunction(identNode, propertyToken, propertyLine, false, flags, false));
-                    return;
                 }
             }
 
+            if ((reparseFlags & ScriptFunctionData.IS_ES6_METHOD) != 0
+                    && (type == IDENT || type == LBRACKET || isNonStrictModeIdent())) {
+                final String ident = (String)getValue();
+                final long propertyToken = token;
+                final int propertyLine = line;
+                final Expression propertyKey = propertyName();
+
+                // Code below will need refinement once we fully support ES6 class syntax
+                final int flags = CONSTRUCTOR_NAME.equals(ident) ? FunctionNode.ES6_IS_CLASS_CONSTRUCTOR : FunctionNode.ES6_IS_METHOD;
+                addPropertyFunctionStatement(propertyMethodFunction(propertyKey, propertyToken, propertyLine, false, flags, false));
+                return;
+            }
+
             expressionStatement();
             break;
         }
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java	Fri Sep 30 09:28:18 2016 -0700
@@ -186,7 +186,10 @@
 
     /** Method handle for setting the user accessors of a ScriptObject */
     //TODO fastpath this
-    public static final Call SET_USER_ACCESSORS = virtualCall(MethodHandles.lookup(), ScriptObject.class, "setUserAccessors", void.class, String.class, ScriptFunction.class, ScriptFunction.class);
+    public static final Call SET_USER_ACCESSORS = virtualCallNoLookup(ScriptObject.class, "setUserAccessors", void.class, Object.class, ScriptFunction.class, ScriptFunction.class);
+
+    /** Method handle for generic property setter */
+    public static final Call GENERIC_SET = virtualCallNoLookup(ScriptObject.class, "set", void.class, Object.class, Object.class, int.class);
 
     static final MethodHandle[] SET_SLOW = new MethodHandle[] {
         findOwnMH_V("set", void.class, Object.class, int.class, int.class),
@@ -1063,12 +1066,13 @@
      * @param getter {@link UserAccessorProperty} defined getter, or null if none
      * @param setter {@link UserAccessorProperty} defined setter, or null if none
      */
-    public final void setUserAccessors(final String key, final ScriptFunction getter, final ScriptFunction setter) {
-        final Property oldProperty = getMap().findProperty(key);
+    public final void setUserAccessors(final Object key, final ScriptFunction getter, final ScriptFunction setter) {
+        final Object realKey = JSType.toPropertyKey(key);
+        final Property oldProperty = getMap().findProperty(realKey);
         if (oldProperty instanceof UserAccessorProperty) {
             modifyOwnProperty(oldProperty, oldProperty.getFlags(), getter, setter);
         } else {
-            addOwnProperty(newUserAccessors(key, oldProperty != null ? oldProperty.getFlags() : 0, getter, setter));
+            addOwnProperty(newUserAccessors(realKey, oldProperty != null ? oldProperty.getFlags() : 0, getter, setter));
         }
     }
 
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties	Thu Sep 29 11:13:42 2016 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties	Fri Sep 30 09:28:18 2016 -0700
@@ -190,3 +190,105 @@
 
 Number.prototype.toPrecision=returns a string representing the number to a specified precision in fixed-point or exponential notation
 
+Date.parse=returns a number, the UTC time value corresponding to the date and time interpreted from the given string argument, returns NAN if the argument is not recognized
+
+Date.UTC=returns the number of milliseconds in the given date object since January 1, 1970, 00:00:00 universal time
+
+Date.now=returns the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC
+
+Date.prototype.toString=returns the string value representing the given date object
+
+Date.prototype.toDateString=returns the string value representing the date portion of the given date object
+
+Date.prototype.toTimeString=returns the string value representing the time portion of the given date object
+
+Date.prototype.toLocaleString=returns the string value representing the date according to language specific conventions
+
+Date.prototype.toLocaleDateString=returns the string value representing the date portion of the given date object according to language specific conventions
+
+Date.prototype.toLocaleTimeString=returns the string value representing the time portion of the given date object according to language specific conventions
+
+Date.prototype.valueOf=returns the number of milliseconds between January 1, 1970, 00:00:00 UTC and the given date
+
+Date.prototype.getTime=returns the number representing milliseconds elapsed between January 1, 1970, 00:00:00 UTC and the given date
+
+Date.prototype.getFullYear=returns the year of the given date according to local time
+
+Date.prototype.getUTCFullYear=returns the year of the given date according to universal time
+
+Date.prototype.getMonth=returns the month between 0 to 11 of the given date according to local time
+
+Date.prototype.getUTCMonth=returns the month between 0 and 11 of the given date according to universal time
+
+Date.prototype.getDate=returns the day of the month for the given date according to local time
+
+Date.prototype.getUTCDate=returns the day of the month for the given date according to universal time
+
+Date.prototype.getDay=returns the day of the week for the given date according to local time, 0 represents Sunday
+
+Date.prototype.getUTCDay=returns the day of the week for the given date according to universal time, 0 represents Sunday
+
+Date.prototype.getHours=returns the hour in the given date, according to local time
+
+Date.prototype.getUTCHours=returns the hour in the given date, according to universal time
+
+Date.prototype.getMinutes=returns the minutes in the given date, according to local time
+
+Date.prototype.getUTCMinutes=returns the minutes in the given date, according to universal time
+
+Date.prototype.getSeconds=returns the seconds in the given date, according to local time
+
+Date.prototype.getUTCSeconds=returns the seconds in the given date, according to universal time
+
+Date.prototype.getMilliseconds=returns the milliseconds in the given date, according to local time
+
+Date.prototype.getUTCMilliseconds=returns the milliseconds in the given date, according to universal time
+
+Date.prototype.getTimezoneOffset=returns the difference between local time and UTC time in minutes
+
+Date.prototype.setTime=sets the date object to the time given, which is represented by the number of milliseconds since January 1, 1970, 00:00:00 UTC
+
+Date.prototype.setMilliseconds=sets the milliseconds for the given date according to local time
+
+Date.prototype.setUTCMilliseconds=sets the milliseconds for the given date according to universal time
+
+Date.prototype.setSeconds=sets the seconds for the given date according to local time
+
+Date.prototype.setUTCSeconds=sets the seconds for the given date according to universal time
+
+Date.prototype.setMinutes=sets the minutes for the given date according to local time
+
+Date.prototype.setUTCMinutes=sets the minutes for the given date according to universal time
+
+Date.prototype.setHours=sets the hours for the given date according to local time
+
+Date.prototype.setUTCHours=sets the hours for the given date according to universal time
+
+Date.prototype.setDate=sets the day of the month for the given date according to local time
+
+Date.prototype.setUTCDate=sets the day of the month for the given date according to universal time
+
+Date.prototype.setMonth=sets the month for the given date according to the currently set year
+
+Date.prototype.setUTCMonth=sets the month for the given date according to the universal time
+
+Date.prototype.setFullYear=sets the full year for the given date according to local time
+
+Date.prototype.toUTCString=converts the given date to a string using UTC time zone
+
+Date.prototype.toISOString=returns the string value in ISO 8601 format for the given date according to universal time
+
+Date.prototype.toJSON=returns the string representation of the given date
+
+RegExp.prototype.exec=returns an array object containing the results of match of given string against regular expression, null if no match found
+
+RegExp.prototype.test=returns true if match of given string against regular expression found, else returns false
+
+RegExp.prototype.toString=returns string representation of regular expression
+
+Error.prototype.toString=returns string representation of error object
+
+JSON.parse=returns an object by parsing given string as JSON
+
+JSON.stringify=returns a JSON string corresponding to the given ECMAScript value
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/es6/computed-property-duplicate.js	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8164467: ES6 computed properties are implemented wrongly
+ *
+ * @test
+ * @run
+ * @option --language=es6
+ */
+
+var obj = {
+    get ['a']() {
+        throw new Error('should not be called');
+    },
+    get ['a']() {
+        throw new Error('should not be called');
+    },
+    get ['a']() {
+        return 'a';
+    }
+};
+
+Assert.assertEquals(obj.a, 'a');
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/es6/computed-property-getter.js	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8164467: ES6 computed properties are implemented wrongly
+ *
+ * @test
+ * @run
+ * @option --language=es6
+ */
+
+function f(x) {
+    return x;
+}
+
+var d = 'd';
+var n = 3;
+var s1 = Symbol();
+var s2 = Symbol();
+
+var object = {
+    get a() {  return 'a' },
+    get ['b']() { return 'b' },
+    get [f('c')]() { return 'c' },
+    get [d]() { return d },
+    get [1]() { return 1 },
+    get [f(2)]() { return 2 },
+    get [n]() { return 3 },
+    get [s1]() { return s1 },
+    get [f(s2)]() { return s2 }
+};
+
+
+Assert.assertEquals(object.a, 'a');
+Assert.assertEquals(object.b, 'b');
+Assert.assertEquals(object.c, 'c');
+Assert.assertEquals(object.d, 'd');
+Assert.assertEquals(object[1], 1);
+Assert.assertEquals(object[2], 2);
+Assert.assertEquals(object[3], 3);
+Assert.assertEquals(object[s1], s1);
+Assert.assertEquals(object[s2], s2);
+
+for (var s of ['a', 'b', 'c', 'd', 1, 2, 3, s1, s2]) {
+    Assert.assertEquals(object[s], s);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/es6/computed-property-method.js	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8164467: ES6 computed properties are implemented wrongly
+ *
+ * @test
+ * @run
+ * @option --language=es6
+ */
+
+function f(x) {
+    return x;
+}
+
+var d = 'd';
+var n = 3;
+var s1 = Symbol();
+var s2 = Symbol();
+
+var object = {
+    a() {  return 'a' },
+    ['b']() { return 'b' },
+    [f('c')]() { return 'c' },
+    [d]() { return d },
+    [1]() { return 1 },
+    [f(2)]() { return 2 },
+    [n]() { return 3 },
+    [s1]() { return s1 },
+    [f(s2)]() { return s2 }
+};
+
+
+Assert.assertEquals(object.a(), 'a');
+Assert.assertEquals(object.b(), 'b');
+Assert.assertEquals(object.c(), 'c');
+Assert.assertEquals(object.d(), 'd');
+Assert.assertEquals(object[1](), 1);
+Assert.assertEquals(object[2](), 2);
+Assert.assertEquals(object[3](), 3);
+Assert.assertEquals(object[s1](), s1);
+Assert.assertEquals(object[s2](), s2);
+
+for (var s of ['a', 'b', 'c', 'd', 1, 2, 3, s1, s2]) {
+    Assert.assertEquals(object[s](), s);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/es6/computed-property-number.js	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8164467: ES6 computed properties are implemented wrongly
+ *
+ * @test
+ * @run
+ * @option --language=es6
+ */
+
+function f(x) {
+    return x;
+}
+
+var object = {
+    [1.5]: 'a',
+    get [f(1e+40)]() { return 'b' },
+    [0.0001]: 'c',
+    [-0]: 'd',
+    [Infinity]: 'e',
+    [-Infinity]: 'f',
+    [NaN]: 'g'
+
+};
+
+
+Assert.assertEquals(object['1.5'], 'a');
+Assert.assertEquals(object['1e+40'], 'b');
+Assert.assertEquals(object['0.0001'], 'c');
+Assert.assertEquals(object[0], 'd');
+Assert.assertEquals(object[Infinity], 'e');
+Assert.assertEquals(object[-Infinity], 'f');
+Assert.assertEquals(object[NaN], 'g');
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/es6/computed-property-setter.js	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8164467: ES6 computed properties are implemented wrongly
+ *
+ * @test
+ * @run
+ * @option --language=es6
+ */
+
+var counter = 0;
+
+var obj = {
+    set ['a'](x) {
+        counter++;
+    }
+};
+
+obj.a = 'a';
+Assert.assertTrue(counter === 1);
+obj.a = 'a';
+Assert.assertTrue(counter === 2);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/es6/computed-property.js	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8164467: ES6 computed properties are implemented wrongly
+ *
+ * @test
+ * @run
+ * @option --language=es6
+ */
+
+function f(x) {
+    return x;
+}
+
+var d = 'd';
+var n = 3;
+var s1 = Symbol();
+var s2 = Symbol();
+
+var object = {
+    a: 'a',
+    ['b']: 'b',
+    [f('c')]: 'c',
+    [d]: d,
+    [1]: 1,
+    [f(2)]: 2,
+    [n]: 3,
+    [s1]: s1,
+    [f(s2)]: s2
+};
+
+
+Assert.assertEquals(object.a, 'a');
+Assert.assertEquals(object.b, 'b');
+Assert.assertEquals(object.c, 'c');
+Assert.assertEquals(object.d, 'd');
+Assert.assertEquals(object[1], 1);
+Assert.assertEquals(object[2], 2);
+Assert.assertEquals(object[3], 3);
+Assert.assertEquals(object[s1], s1);
+Assert.assertEquals(object[s2], s2);
+
+for (var s of ['a', 'b', 'c', 'd', 1, 2, 3, s1, s2]) {
+    Assert.assertEquals(object[s], s);
+}
--- a/nashorn/test/script/trusted/JDK-8006529.js	Thu Sep 29 11:13:42 2016 +0530
+++ b/nashorn/test/script/trusted/JDK-8006529.js	Fri Sep 30 09:28:18 2016 -0700
@@ -38,7 +38,7 @@
  * We cannot use direct Java class (via dynalink bean linker) to Compiler
  * and FunctionNode because of package-access check and so reflective calls.
  */
-
+var Reflector           = Java.type("jdk.nashorn.test.models.Reflector");
 var forName             = java.lang.Class["forName(String)"];
 var Parser              = forName("jdk.nashorn.internal.parser.Parser").static
 var Compiler            = forName("jdk.nashorn.internal.codegen.Compiler").static
@@ -69,7 +69,11 @@
 var lhsMethod = BinaryNode.class.getMethod("lhs")
 var binaryRhsMethod = BinaryNode.class.getMethod("rhs")
 var debugIdMethod = Debug.class.getMethod("id", java.lang.Object.class)
-var compilePhases = CompilationPhases.class.getField("COMPILE_UPTO_BYTECODE").get(null);
+var compilePhases = Reflector.get(CompilationPhases.class.getField("COMPILE_UPTO_BYTECODE"), null);
+
+function invoke(m, obj) {
+    return Reflector.invoke(m, obj);
+}
 
 // These are method names of methods in FunctionNode class
 var allAssertionList = ['isVarArg', 'needsParentScope', 'needsCallee', 'hasScopeBlock', 'usesSelfSymbol', 'isSplit', 'hasEval', 'allVarsInScope', 'isStrict']
@@ -86,7 +90,7 @@
 
 // returns functionNode.getBody().getStatements().get(0)
 function getFirstFunction(functionNode) {
-    var f = findFunction(getBodyMethod.invoke(functionNode))
+    var f = findFunction(invoke(getBodyMethod, functionNode))
     if (f == null) {
         throw new Error();
     }
@@ -95,7 +99,7 @@
 
 function findFunction(node) {
     if(node instanceof Block) {
-        var stmts = getStatementsMethod.invoke(node)
+        var stmts = invoke(getStatementsMethod, node)
         for(var i = 0; i < stmts.size(); ++i) {
             var retval = findFunction(stmts.get(i))
             if(retval != null) {
@@ -103,13 +107,13 @@
             }
         }
     } else if(node instanceof VarNode) {
-        return findFunction(getInitMethod.invoke(node))
+        return findFunction(invoke(getInitMethod, node))
     } else if(node instanceof UnaryNode) {
-        return findFunction(rhsMethod.invoke(node))
+        return findFunction(invoke(rhsMethod, node))
     } else if(node instanceof BinaryNode) {
-        return findFunction(lhsMethod.invoke(node)) || findFunction(binaryRhsMethod.invoke(node))
+        return findFunction(invoke(lhsMethod, node)) || findFunction(invoke(binaryRhsMethod, node))
     } else if(node instanceof ExpressionStatement) {
-        return findFunction(getExpressionMethod.invoke(node))
+        return findFunction(invoke(getExpressionMethod, node))
     } else if(node instanceof FunctionNode) {
         return node
     }
@@ -131,12 +135,12 @@
     var ctxt = getContextMethod.invoke(null);
     var env = getEnvMethod.invoke(ctxt);
 
-    var parser   = ParserConstructor.newInstance(env, source, ThrowErrorManager.class.newInstance());
-    var func     = parseMethod.invoke(parser);
+    var parser   = Reflector.newInstance(ParserConstructor, env, source, ThrowErrorManager.class.newInstance());
+    var func     = invoke(parseMethod, parser);
 
-    var compiler = CompilerConstructor.invoke(null, ctxt, source, false);
+    var compiler = Reflector.invoke(CompilerConstructor, null, ctxt, source, false);
 
-    return compileMethod.invoke(compiler, func, phases);
+    return Reflector.invoke(compileMethod, compiler, func, phases);
 };
 
 var allAssertions = (function() {
@@ -161,9 +165,10 @@
     }
     for(var assertion in allAssertions) {
         var expectedValue = !!assertions[assertion]
-        var actualValue = functionNodeMethods[assertion].invoke(f)
+        var actualValue = invoke(functionNodeMethods[assertion], f)
         if(actualValue !== expectedValue) {
-            throw "Expected " + assertion + " === " + expectedValue + ", got " + actualValue + " for " + f + ":" + debugIdMethod.invoke(null, f);
+            throw "Expected " + assertion + " === " + expectedValue + ", got " + actualValue + " for " + f + ":" 
+                + invoke(debugIdMethod, null, f);
         }
     }
 }
--- a/nashorn/test/script/trusted/event_queue.js	Thu Sep 29 11:13:42 2016 +0530
+++ b/nashorn/test/script/trusted/event_queue.js	Fri Sep 30 09:28:18 2016 -0700
@@ -36,6 +36,7 @@
 print(Debug);
 print();
 
+var Reflector     = Java.type("jdk.nashorn.test.models.Reflector");
 var forName       = java.lang.Class["forName(String)"];
 var RuntimeEvent  = forName("jdk.nashorn.internal.runtime.events.RuntimeEvent").static;
 var getValue      = RuntimeEvent.class.getMethod("getValue");
@@ -84,19 +85,19 @@
     var e = events[i];
     print("event #" + i);
     print("\tevent class=" + e.getClass());
-    print("\tvalueClass in event=" + getValueClass.invoke(e));
-    var v = getValue.invoke(e);
+    print("\tvalueClass in event=" + Reflector.invoke(getValueClass, e));
+    var v = Reflector.invoke(getValue, e);
     print("\tclass of value=" + v.getClass());
-    print("\treturn type=" + getReturnType.invoke(v));
+    print("\treturn type=" + Reflector.invoke(getReturnType, v));
     lastInLoop = events[i];
 }
 
 print();
 print("in loop last class = " + lastInLoop.getClass());
-print("in loop last value class = " + getValueClass.invoke(lastInLoop));
-var rexInLoop = getValue.invoke(lastInLoop);
+print("in loop last value class = " + Reflector.invoke(getValueClass, lastInLoop));
+var rexInLoop = Reflector.invoke(getValue, lastInLoop);
 print("in loop rex class = " + rexInLoop.getClass());
-print("in loop rex return type = " + getReturnType.invoke(rexInLoop));
+print("in loop rex return type = " + Reflector.invoke(getReturnType, rexInLoop));
 
 //try last runtime events
 var last = Debug.getLastRuntimeEvent();
@@ -106,10 +107,10 @@
 print();
 
 print("last class = " + last.getClass());
-print("last value class = " + getValueClass.invoke(last));
-var rex = getValue.invoke(last);
+print("last value class = " + Reflector.invoke(getValueClass, last));
+var rex = Reflector.invoke(getValue, last);
 print("rex class = " + rex.getClass());
-print("rex return type = " + getReturnType.invoke(rex));
+print("rex return type = " + Reflector.invoke(getReturnType, rex));
 
 //try the capacity setter
 print();
--- a/nashorn/test/script/trusted/optimistic_recompilation.js	Thu Sep 29 11:13:42 2016 +0530
+++ b/nashorn/test/script/trusted/optimistic_recompilation.js	Fri Sep 30 09:28:18 2016 -0700
@@ -32,6 +32,7 @@
  * @run
  */
 
+var Reflector     = Java.type("jdk.nashorn.test.models.Reflector");
 var forName       = java.lang.Class["forName(String)"];
 var RuntimeEvent  = forName("jdk.nashorn.internal.runtime.events.RuntimeEvent").static;
 var getValue      = RuntimeEvent.class.getMethod("getValue");
@@ -42,6 +43,10 @@
 var setReturnTypeAndValue = [];
 var expectedValues = [];
 
+function invoke(m, obj) {
+    return Reflector.invoke(m, obj);
+}
+
 function checkExpectedRecompilation(f, expectedValues, testCase) {
     Debug.clearRuntimeEvents();
     print(f());
@@ -51,12 +56,12 @@
     if (events.length ==  expectedValues.length) {
         for (var i in events) {
             var e = events[i];
-            var returnValue = getReturnValue.invoke(e);
+            var returnValue = invoke(getReturnValue, e);
             if (typeof returnValue != 'undefined') {
-            setReturnTypeAndValue[i] = [getReturnType.invoke(getValue.invoke(e)), returnValue];
+                setReturnTypeAndValue[i] = [invoke(getReturnType, invoke(getValue, e)), returnValue];
             } else {
                 returnValue = "undefined";
-                setReturnTypeAndValue[i] = [getReturnType.invoke(getValue.invoke(e)), returnValue];
+                setReturnTypeAndValue[i] = [invoke(getReturnType, invoke(getValue, e)), returnValue];
             }
             if (!setReturnTypeAndValue[i].toString().equals(expectedValues[i].toString())) {
                 fail("The return values are not as expected. Expected value: " + expectedValues[i] + " and got: " + setReturnTypeAndValue[i] + " in test case: " + f);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/src/jdk/nashorn/test/models/Reflector.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.nashorn.test.models;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Module;
+import jdk.nashorn.internal.runtime.Context;
+
+/**
+ * Few tests reflectively invoke or read fields of Nashorn classes
+ * and objects - but of packages that are not exported to any module!
+ * But, those packages are qualified exported to test [java] code
+ * such as this class. So, test scripts can invoke the methods of this
+ * class instead.
+ */
+public final class Reflector {
+    private Reflector() {}
+    private static final Module NASHORN_MOD = Context.class.getModule();
+
+    public static Object invoke(Method m, Object self, Object...args) {
+        if (m.getDeclaringClass().getModule() != NASHORN_MOD) {
+            throw new RuntimeException(m + " is not from Nashorn module");
+        }
+
+        try {
+            return m.invoke(self, args);
+        } catch (final Exception e) {
+            if (e instanceof RuntimeException) {
+                throw (RuntimeException)e;
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    public static Object newInstance(Constructor c, Object...args) {
+        if (c.getDeclaringClass().getModule() != NASHORN_MOD) {
+            throw new RuntimeException(c + " is not from Nashorn module");
+        }
+
+        try {
+            return c.newInstance(args);
+        } catch (final Exception e) {
+            if (e instanceof RuntimeException) {
+                throw (RuntimeException)e;
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    public static Object get(Field f, Object self) {
+        if (f.getDeclaringClass().getModule() != NASHORN_MOD) {
+            throw new RuntimeException(f + " is not from Nashorn module");
+        }
+
+        try {
+            return f.get(self);
+        } catch (final Exception e) {
+            if (e instanceof RuntimeException) {
+                throw (RuntimeException)e;
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+}
--- a/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherDiagnosticInfoObserver.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherDiagnosticInfoObserver.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,8 +26,7 @@
 import com.sun.javatest.Harness;
 import com.sun.javatest.Parameters;
 import com.sun.javatest.TestResult;
-import com.sun.javatest.regtest.RegressionParameters;
-import com.sun.javatest.regtest.OS;
+import com.sun.javatest.InterviewParameters;
 import jdk.test.failurehandler.*;
 
 import java.io.File;
@@ -119,7 +118,7 @@
     @Override
     public void startingTestRun(Parameters params) {
         // TODO find a better way to get JDKs
-        RegressionParameters rp = (RegressionParameters) params;
+        InterviewParameters rp = (InterviewParameters) params;
         Map<?,?> map = new HashMap<>();
         rp.save(map);
         compileJdk = (String) map.get("regtest.compilejdk");
--- a/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherProcessInfoTimeoutHandler.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherProcessInfoTimeoutHandler.java	Fri Sep 30 09:28:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,6 @@
 
 package jdk.test.failurehandler.jtreg;
 
-import com.sun.javatest.regtest.OS;
 import com.sun.javatest.regtest.TimeoutHandler;
 import jdk.test.failurehandler.*;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/OS.java	Fri Sep 30 09:28:18 2016 -0700
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.test.failurehandler.jtreg;
+
+// Stripped down version of jtreg internal class com.sun.javatest.regtest.config.OS
+class OS {
+    public final String family;
+
+    private static OS current;
+
+    public static OS current() {
+        if (current == null) {
+            String name = System.getProperty("os.name");
+            current = new OS(name);
+        }
+        return current;
+    }
+
+    private OS(String name) {
+        if (name.startsWith("Linux")) {
+            family = "linux";
+        } else if (name.startsWith("Mac") || name.startsWith("Darwin")) {
+            family = "mac";
+        } else if (name.startsWith("SunOS") || name.startsWith("Solaris")) {
+            family = "solaris";
+        } else if (name.startsWith("Windows")) {
+            family = "windows";
+        } else {
+            // use first word of name
+            family = name.replaceFirst("^([^ ]+).*", "$1");
+        }
+    }
+}
+
+
--- a/test/lib/jdk/test/lib/Platform.java	Thu Sep 29 11:13:42 2016 +0530
+++ b/test/lib/jdk/test/lib/Platform.java	Fri Sep 30 09:28:18 2016 -0700
@@ -116,6 +116,14 @@
         return (jdkDebug.toLowerCase().contains("debug"));
     }
 
+    public static boolean isSlowDebugBuild() {
+        return (jdkDebug.toLowerCase().equals("slowdebug"));
+    }
+
+    public static boolean isFastDebugBuild() {
+        return (jdkDebug.toLowerCase().equals("fastdebug"));
+    }
+
     public static String getVMVersion() {
         return vmVersion;
     }
--- a/test/lib/jdk/test/lib/unsafe/UnsafeHelper.java	Thu Sep 29 11:13:42 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.test.lib.unsafe;
-
-import jdk.internal.misc.Unsafe;
-import java.lang.reflect.Field;
-
-
-/**
- * Helper class for accessing the jdk.internal.misc.Unsafe functionality
- */
-public final class UnsafeHelper {
-    private static Unsafe unsafe = null;
-
-    /**
-     * @return Unsafe instance.
-     */
-    public static synchronized Unsafe getUnsafe() {
-        if (unsafe == null) {
-            try {
-                Field f = Unsafe.class.getDeclaredField("theUnsafe");
-                f.setAccessible(true);
-                unsafe = (Unsafe) f.get(null);
-            } catch (NoSuchFieldException | IllegalAccessException e) {
-                throw new RuntimeException("Unable to get Unsafe instance.", e);
-            }
-        }
-        return unsafe;
-    }
-}
-