Merge
authorduke
Wed, 05 Jul 2017 23:08:24 +0200
changeset 44482 d045646dedfa
parent 44481 f2b3b6bb1f4a (current diff)
parent 44473 29c2d3d068ca (diff)
child 44487 4e9e078b4153
Merge
common/bin/shell-tracer.sh
--- a/.hgtags-top-repo	Sat Apr 08 03:25:31 2017 +0000
+++ b/.hgtags-top-repo	Wed Jul 05 23:08:24 2017 +0200
@@ -405,3 +405,6 @@
 fe8466adaef8178dba94be53c789a0aaa87d13bb jdk-9+159
 4d29ee32d926ebc960072d51a3bc558f95c1cbad jdk-9+160
 cda60babd152d889aba4d8f20a8f643ab151d3de jdk-9+161
+21b063d75b3edbffb9bebc8872d990920c4ae1e5 jdk-9+162
+c38c6b270ccc8e2b86d1631bcf42248241b54d2c jdk-9+163
+7810f75d016a52e32295c4233009de5ca90e31af jdk-9+164
--- a/common/autoconf/basics.m4	Sat Apr 08 03:25:31 2017 +0000
+++ b/common/autoconf/basics.m4	Wed Jul 05 23:08:24 2017 +0200
@@ -1098,6 +1098,7 @@
   BASIC_PATH_PROGS(HG, hg)
   BASIC_PATH_PROGS(STAT, stat)
   BASIC_PATH_PROGS(TIME, time)
+  BASIC_PATH_PROGS(FLOCK, flock)
   # Dtrace is usually found in /usr/sbin on Solaris, but that directory may not
   # be in the user path.
   BASIC_PATH_PROGS(DTRACE, dtrace, $PATH:/usr/sbin)
--- a/common/autoconf/flags.m4	Sat Apr 08 03:25:31 2017 +0000
+++ b/common/autoconf/flags.m4	Wed Jul 05 23:08:24 2017 +0200
@@ -355,7 +355,7 @@
         SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
         JVM_CFLAGS="$JVM_CFLAGS $PICFLAG"
       fi
-      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path[$]1'
+      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path$(or [$]1,/.)'
       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
       SET_SHARED_LIBRARY_NAME='-Wl,-install_name,@rpath/[$]1'
       SET_SHARED_LIBRARY_MAPFILE='-Wl,-exported_symbols_list,[$]1'
@@ -375,7 +375,7 @@
       # Linking is different on MacOSX
       PICFLAG=''
       SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
-      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path[$]1'
+      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path$(or [$]1,/.)'
       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
       SET_SHARED_LIBRARY_NAME='-Wl,-install_name,@rpath/[$]1'
       SET_SHARED_LIBRARY_MAPFILE='-Wl,-exported_symbols_list,[$]1'
--- a/common/autoconf/generated-configure.sh	Sat Apr 08 03:25:31 2017 +0000
+++ b/common/autoconf/generated-configure.sh	Wed Jul 05 23:08:24 2017 +0200
@@ -932,6 +932,7 @@
 IS_GNU_TIME
 PATCH
 DTRACE
+FLOCK
 TIME
 STAT
 HG
@@ -994,6 +995,7 @@
 OPENJDK_TARGET_CPU_LEGACY_LIB
 OPENJDK_TARGET_CPU_LEGACY
 REQUIRED_OS_VERSION
+REQUIRED_OS_ARCH
 REQUIRED_OS_NAME
 COMPILE_TYPE
 OPENJDK_TARGET_CPU_ENDIAN
@@ -1292,6 +1294,7 @@
 HG
 STAT
 TIME
+FLOCK
 DTRACE
 PATCH
 DSYMUTIL
@@ -2256,6 +2259,7 @@
   HG          Override default value for HG
   STAT        Override default value for STAT
   TIME        Override default value for TIME
+  FLOCK       Override default value for FLOCK
   DTRACE      Override default value for DTRACE
   PATCH       Override default value for PATCH
   DSYMUTIL    Override default value for DSYMUTIL
@@ -5173,7 +5177,7 @@
 #CUSTOM_AUTOCONF_INCLUDE
 
 # Do not change or remove the following line, it is needed for consistency checks:
-DATE_WHEN_GENERATED=1489410066
+DATE_WHEN_GENERATED=1490900744
 
 ###############################################################################
 #
@@ -16038,13 +16042,15 @@
     fi
   fi
   if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
-    REQUIRED_OS_NAME=Darwin
+    REQUIRED_OS_NAME="Mac OS X"
     REQUIRED_OS_VERSION=11.2
   fi
   if test "x$OPENJDK_TARGET_OS" = "xaix"; then
     REQUIRED_OS_NAME=AIX
     REQUIRED_OS_VERSION=7.1
   fi
+  REQUIRED_OS_ARCH=${OPENJDK_TARGET_CPU}
+
 
 
 
@@ -23056,6 +23062,203 @@
   fi
 
 
+
+
+  # Publish this variable in the help.
+
+
+  if [ -z "${FLOCK+x}" ]; then
+    # The variable is not set by user, try to locate tool using the code snippet
+    for ac_prog in flock
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_FLOCK+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $FLOCK in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_FLOCK="$FLOCK" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_FLOCK="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+FLOCK=$ac_cv_path_FLOCK
+if test -n "$FLOCK"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $FLOCK" >&5
+$as_echo "$FLOCK" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$FLOCK" && break
+done
+
+  else
+    # The variable is set, but is it from the command line or the environment?
+
+    # Try to remove the string !FLOCK! from our list.
+    try_remove_var=${CONFIGURE_OVERRIDDEN_VARIABLES//!FLOCK!/}
+    if test "x$try_remove_var" = "x$CONFIGURE_OVERRIDDEN_VARIABLES"; then
+      # If it failed, the variable was not from the command line. Ignore it,
+      # but warn the user (except for BASH, which is always set by the calling BASH).
+      if test "xFLOCK" != xBASH; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Ignoring value of FLOCK from the environment. Use command line variables instead." >&5
+$as_echo "$as_me: WARNING: Ignoring value of FLOCK from the environment. Use command line variables instead." >&2;}
+      fi
+      # Try to locate tool using the code snippet
+      for ac_prog in flock
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_FLOCK+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $FLOCK in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_FLOCK="$FLOCK" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_FLOCK="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+FLOCK=$ac_cv_path_FLOCK
+if test -n "$FLOCK"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $FLOCK" >&5
+$as_echo "$FLOCK" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$FLOCK" && break
+done
+
+    else
+      # If it succeeded, then it was overridden by the user. We will use it
+      # for the tool.
+
+      # First remove it from the list of overridden variables, so we can test
+      # for unknown variables in the end.
+      CONFIGURE_OVERRIDDEN_VARIABLES="$try_remove_var"
+
+      # Check if we try to supply an empty value
+      if test "x$FLOCK" = x; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: Setting user supplied tool FLOCK= (no value)" >&5
+$as_echo "$as_me: Setting user supplied tool FLOCK= (no value)" >&6;}
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for FLOCK" >&5
+$as_echo_n "checking for FLOCK... " >&6; }
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5
+$as_echo "disabled" >&6; }
+      else
+        # Check if the provided tool contains a complete path.
+        tool_specified="$FLOCK"
+        tool_basename="${tool_specified##*/}"
+        if test "x$tool_basename" = "x$tool_specified"; then
+          # A command without a complete path is provided, search $PATH.
+          { $as_echo "$as_me:${as_lineno-$LINENO}: Will search for user supplied tool FLOCK=$tool_basename" >&5
+$as_echo "$as_me: Will search for user supplied tool FLOCK=$tool_basename" >&6;}
+          # Extract the first word of "$tool_basename", so it can be a program name with args.
+set dummy $tool_basename; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_FLOCK+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $FLOCK in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_FLOCK="$FLOCK" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_FLOCK="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+FLOCK=$ac_cv_path_FLOCK
+if test -n "$FLOCK"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $FLOCK" >&5
+$as_echo "$FLOCK" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+          if test "x$FLOCK" = x; then
+            as_fn_error $? "User supplied tool $tool_basename could not be found" "$LINENO" 5
+          fi
+        else
+          # Otherwise we believe it is a complete path. Use it as it is.
+          { $as_echo "$as_me:${as_lineno-$LINENO}: Will use user supplied tool FLOCK=$tool_specified" >&5
+$as_echo "$as_me: Will use user supplied tool FLOCK=$tool_specified" >&6;}
+          { $as_echo "$as_me:${as_lineno-$LINENO}: checking for FLOCK" >&5
+$as_echo_n "checking for FLOCK... " >&6; }
+          if test ! -x "$tool_specified"; then
+            { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
+$as_echo "not found" >&6; }
+            as_fn_error $? "User supplied tool FLOCK=$tool_specified does not exist or is not executable" "$LINENO" 5
+          fi
+          { $as_echo "$as_me:${as_lineno-$LINENO}: result: $tool_specified" >&5
+$as_echo "$tool_specified" >&6; }
+        fi
+      fi
+    fi
+
+  fi
+
+
   # Dtrace is usually found in /usr/sbin on Solaris, but that directory may not
   # be in the user path.
 
@@ -49486,7 +49689,7 @@
         SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
         JVM_CFLAGS="$JVM_CFLAGS $PICFLAG"
       fi
-      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path$1'
+      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path$(or $1,/.)'
       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
       SET_SHARED_LIBRARY_NAME='-Wl,-install_name,@rpath/$1'
       SET_SHARED_LIBRARY_MAPFILE='-Wl,-exported_symbols_list,$1'
@@ -49506,7 +49709,7 @@
       # Linking is different on MacOSX
       PICFLAG=''
       SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
-      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path$1'
+      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path$(or $1,/.)'
       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
       SET_SHARED_LIBRARY_NAME='-Wl,-install_name,@rpath/$1'
       SET_SHARED_LIBRARY_MAPFILE='-Wl,-exported_symbols_list,$1'
--- a/common/autoconf/platform.m4	Sat Apr 08 03:25:31 2017 +0000
+++ b/common/autoconf/platform.m4	Wed Jul 05 23:08:24 2017 +0200
@@ -452,15 +452,17 @@
     fi
   fi
   if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
-    REQUIRED_OS_NAME=Darwin
+    REQUIRED_OS_NAME="Mac OS X"
     REQUIRED_OS_VERSION=11.2
   fi
   if test "x$OPENJDK_TARGET_OS" = "xaix"; then
     REQUIRED_OS_NAME=AIX
     REQUIRED_OS_VERSION=7.1
   fi
+  REQUIRED_OS_ARCH=${OPENJDK_TARGET_CPU}
 
   AC_SUBST(REQUIRED_OS_NAME)
+  AC_SUBST(REQUIRED_OS_ARCH)
   AC_SUBST(REQUIRED_OS_VERSION)
 ])
 
--- a/common/autoconf/spec.gmk.in	Sat Apr 08 03:25:31 2017 +0000
+++ b/common/autoconf/spec.gmk.in	Wed Jul 05 23:08:24 2017 +0200
@@ -48,7 +48,7 @@
 
 # The default make arguments
 MAKE_ARGS = $(MAKE_LOG_FLAGS) -r -R -I $(TOPDIR)/make/common SPEC=$(SPEC) \
-    MAKE_LOG_FLAGS="$(MAKE_LOG_FLAGS)" LOG_LEVEL=$(LOG_LEVEL)
+    MAKE_LOG_FLAGS="$(MAKE_LOG_FLAGS)" $(MAKE_LOG_VARS)
 
 OUTPUT_SYNC_SUPPORTED:=@OUTPUT_SYNC_SUPPORTED@
 OUTPUT_SYNC:=@OUTPUT_SYNC@
@@ -101,8 +101,9 @@
 OPENJDK_BUILD_CPU_BITS:=@OPENJDK_BUILD_CPU_BITS@
 OPENJDK_BUILD_CPU_ENDIAN:=@OPENJDK_BUILD_CPU_ENDIAN@
 
-# Legacy OS values for use in release file.
+# OS values for use in release file.
 REQUIRED_OS_NAME:=@REQUIRED_OS_NAME@
+REQUIRED_OS_ARCH:=@REQUIRED_OS_ARCH@
 REQUIRED_OS_VERSION:=@REQUIRED_OS_VERSION@
 
 LIBM:=@LIBM@
@@ -636,6 +637,7 @@
 DSYMUTIL:=@DSYMUTIL@
 FIND:=@FIND@
 FIND_DELETE:=@FIND_DELETE@
+FLOCK:=@FLOCK@
 ECHO:=@ECHO@
 EGREP:=@EGREP@
 FGREP:=@FGREP@
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/bin/shell-profiler.sh	Wed Jul 05 23:08:24 2017 +0200
@@ -0,0 +1,69 @@
+#!/bin/bash
+#
+# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# Usage: sh shell-tracer.sh <TIME_CMD_TYPE> <TIME_CMD> <OUTPUT_FILE> <shell command line>
+#
+# This shell script is supposed to be set as a replacement for SHELL in make,
+# causing it to be called whenever make wants to execute shell commands.
+# The <shell command line> is suitable for passing on to the old shell,
+# typically beginning with -c.
+#
+# This script will run the shell command line and it will also store a simple
+# log of the the time it takes to execute the command in the OUTPUT_FILE, using
+# utility for time measure specified with TIME_CMD option.
+#
+# Type of time measure utility is specified with TIME_CMD_TYPE option.
+# Recognized options values of TIME_CMD_TYPE option: "gnutime", "flock".
+
+TIME_CMD_TYPE="$1"
+TIME_CMD="$2"
+OUTPUT_FILE="$3"
+shift
+shift
+shift
+if [ "$TIME_CMD_TYPE" = "gnutime" ]; then
+  # Escape backslashes (\) and percent chars (%). See man for GNU 'time'.
+  msg=${@//\\/\\\\}
+  msg=${msg//%/%%}
+  "$TIME_CMD" -f "[TIME:%E] $msg" -a -o "$OUTPUT_FILE" "$@"
+elif [ "$TIME_CMD_TYPE" = "flock" ]; then
+  # Emulated GNU 'time' with 'flock' and 'date'.
+  ts=`date +%s%3N`
+  "$@"
+  status=$?
+  ts2=`date +%s%3N`
+  millis=$((ts2 - ts))
+  ms=$(($millis % 1000))
+  seconds=$((millis / 1000))
+  ss=$(($seconds % 60))
+  minutes=$(($seconds / 60))
+  mm=$(($minutes % 60))
+  hh=$(($minutes / 60)):
+  [ $hh != "0:" ] || hh=
+  # Synchronize on this script.
+  flock -w 10 "$0" printf "[TIME:${hh}${mm}:${ss}.%.2s] %s\n" $ms "$*" >> "$OUTPUT_FILE" || true
+  exit $status
+else
+  "$@"
+fi
--- a/common/bin/shell-tracer.sh	Sat Apr 08 03:25:31 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# Usage: sh shell-tracer.sh <TIME_CMD> <OUTPUT_FILE> <OLD_SHELL> <shell command line>
-#
-# This shell script is supposed to be set as a replacement for SHELL in make,
-# causing it to be called whenever make wants to execute shell commands.
-# The <shell command line> is suitable for passing on to the old shell,
-# typically beginning with -c.
-#
-# This script will make sure the shell command line is executed with
-# OLD_SHELL -x, and it will also store a simple log of the the time it takes to
-# execute the command in the OUTPUT_FILE, using the "time" utility as pointed
-# to by TIME_CMD. If TIME_CMD is "-", no timestamp will be stored.
-
-TIME_CMD="$1"
-OUTPUT_FILE="$2"
-OLD_SHELL="$3"
-shift
-shift
-shift
-if [ "$TIME_CMD" != "-" ]; then
-"$TIME_CMD" -f "[TIME:%E] $*" -a -o "$OUTPUT_FILE" "$OLD_SHELL" -x "$@"
-else
-"$OLD_SHELL" -x "$@"
-fi
--- a/common/conf/jib-profiles.js	Sat Apr 08 03:25:31 2017 +0000
+++ b/common/conf/jib-profiles.js	Wed Jul 05 23:08:24 2017 +0200
@@ -910,7 +910,7 @@
         freetype: {
             organization: common.organization,
             ext: "tar.gz",
-            revision: "2.3.4+1.0",
+            revision: "2.7.1-v120+1.0",
             module: "freetype-" + input.target_platform
         }
     };
--- a/hotspot/.hgtags	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/.hgtags	Wed Jul 05 23:08:24 2017 +0200
@@ -565,3 +565,6 @@
 9211c2e89c1cd11ec2d5752b0f97131a7d7525c7 jdk-9+159
 94b4e2e5331d38eab6a3639c3511b2e0715df0e9 jdk-9+160
 191ffbdb3d7b734288daa7fb76b37a0a85dfe7eb jdk-9+161
+b01c519b715ef6f785d0631adee0a6537cf6c12e jdk-9+162
+983fe207555724d98f4876991e1cbafbcf2733e8 jdk-9+163
+0af429be8bbaeaaf0cb838e9af28c953dda6a9c8 jdk-9+164
--- a/hotspot/make/gensrc/Gensrc-jdk.internal.vm.compiler.gmk	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/make/gensrc/Gensrc-jdk.internal.vm.compiler.gmk	Wed Jul 05 23:08:24 2017 +0200
@@ -81,6 +81,7 @@
 PROCESSOR_PATH := $(call PathList, $(PROCESSOR_JARS))
 
 ADD_EXPORTS := \
+    --add-modules jdk.internal.vm.ci \
     --add-exports jdk.internal.vm.ci/jdk.vm.ci.aarch64=ALL-UNNAMED \
     --add-exports jdk.internal.vm.ci/jdk.vm.ci.amd64=ALL-UNNAMED \
     --add-exports jdk.internal.vm.ci/jdk.vm.ci.code=ALL-UNNAMED \
--- a/hotspot/make/lib/CompileJvm.gmk	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/make/lib/CompileJvm.gmk	Wed Jul 05 23:08:24 2017 +0200
@@ -118,6 +118,12 @@
   OPENJDK_TARGET_CPU_VM_VERSION := amd64
 else ifeq ($(OPENJDK_TARGET_CPU), sparcv9)
   OPENJDK_TARGET_CPU_VM_VERSION := sparc
+else ifeq ($(HOTSPOT_TARGET_CPU_ARCH), arm)
+  ifeq ($(OPENJDK_TARGET_CPU), aarch64)
+    # This sets the Oracle Aarch64 port to use arm64
+    # while the original Aarch64 port uses aarch64
+    OPENJDK_TARGET_CPU_VM_VERSION := arm64
+  endif
 else
   OPENJDK_TARGET_CPU_VM_VERSION := $(OPENJDK_TARGET_CPU)
 endif
--- a/hotspot/make/test/JtregNative.gmk	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/make/test/JtregNative.gmk	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -48,6 +48,8 @@
     $(HOTSPOT_TOPDIR)/test/runtime/jni/PrivateInterfaceMethods \
     $(HOTSPOT_TOPDIR)/test/runtime/jni/ToStringInInterfaceTest \
     $(HOTSPOT_TOPDIR)/test/runtime/jni/CalleeSavedRegisters \
+    $(HOTSPOT_TOPDIR)/test/runtime/jni/CallWithJNIWeak \
+    $(HOTSPOT_TOPDIR)/test/runtime/jni/ReturnJNIWeak \
     $(HOTSPOT_TOPDIR)/test/runtime/modules/getModuleJNI \
     $(HOTSPOT_TOPDIR)/test/runtime/SameObject \
     $(HOTSPOT_TOPDIR)/test/runtime/BoolReturn \
--- a/hotspot/src/cpu/aarch64/vm/aarch64.ad	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/aarch64/vm/aarch64.ad	Wed Jul 05 23:08:24 2017 +0200
@@ -15501,7 +15501,7 @@
 %}
 
 instruct string_indexofUU(iRegP_R1 str1, iRegI_R4 cnt1, iRegP_R3 str2, iRegI_R2 cnt2,
-       iRegI_R0 result, iRegI tmp1, iRegI tmp2, iRegI tmp3, iRegI tmp4, rFlagsReg cr)
+       iRegI_R0 result, iRegINoSp tmp1, iRegINoSp tmp2, iRegINoSp tmp3, iRegINoSp tmp4, rFlagsReg cr)
 %{
   predicate(((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::UU);
   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
@@ -15520,7 +15520,7 @@
 %}
 
 instruct string_indexofLL(iRegP_R1 str1, iRegI_R4 cnt1, iRegP_R3 str2, iRegI_R2 cnt2,
-       iRegI_R0 result, iRegI tmp1, iRegI tmp2, iRegI tmp3, iRegI tmp4, rFlagsReg cr)
+       iRegI_R0 result, iRegINoSp tmp1, iRegINoSp tmp2, iRegINoSp tmp3, iRegINoSp tmp4, rFlagsReg cr)
 %{
   predicate(((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::LL);
   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
@@ -15539,7 +15539,7 @@
 %}
 
 instruct string_indexofUL(iRegP_R1 str1, iRegI_R4 cnt1, iRegP_R3 str2, iRegI_R2 cnt2,
-       iRegI_R0 result, iRegI tmp1, iRegI tmp2, iRegI tmp3, iRegI tmp4, rFlagsReg cr)
+       iRegI_R0 result, iRegINoSp tmp1, iRegINoSp tmp2, iRegINoSp tmp3, iRegINoSp tmp4, rFlagsReg cr)
 %{
   predicate(((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::UL);
   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
@@ -15558,7 +15558,7 @@
 %}
 
 instruct string_indexofLU(iRegP_R1 str1, iRegI_R4 cnt1, iRegP_R3 str2, iRegI_R2 cnt2,
-       iRegI_R0 result, iRegI tmp1, iRegI tmp2, iRegI tmp3, iRegI tmp4, rFlagsReg cr)
+       iRegI_R0 result, iRegINoSp tmp1, iRegINoSp tmp2, iRegINoSp tmp3, iRegINoSp tmp4, rFlagsReg cr)
 %{
   predicate(((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::LU);
   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
@@ -15577,8 +15577,8 @@
 %}
 
 instruct string_indexof_conUU(iRegP_R1 str1, iRegI_R4 cnt1, iRegP_R3 str2,
-                 immI_le_4 int_cnt2, iRegI_R0 result, iRegI tmp1, iRegI tmp2,
-                 iRegI tmp3, iRegI tmp4, rFlagsReg cr)
+                 immI_le_4 int_cnt2, iRegI_R0 result, iRegINoSp tmp1, iRegINoSp tmp2,
+                 iRegINoSp tmp3, iRegINoSp tmp4, rFlagsReg cr)
 %{
   predicate(((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::UU);
   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2)));
@@ -15598,8 +15598,8 @@
 %}
 
 instruct string_indexof_conLL(iRegP_R1 str1, iRegI_R4 cnt1, iRegP_R3 str2,
-                 immI_le_4 int_cnt2, iRegI_R0 result, iRegI tmp1, iRegI tmp2,
-                 iRegI tmp3, iRegI tmp4, rFlagsReg cr)
+                 immI_le_4 int_cnt2, iRegI_R0 result, iRegINoSp tmp1, iRegINoSp tmp2,
+                 iRegINoSp tmp3, iRegINoSp tmp4, rFlagsReg cr)
 %{
   predicate(((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::LL);
   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2)));
@@ -15619,8 +15619,8 @@
 %}
 
 instruct string_indexof_conUL(iRegP_R1 str1, iRegI_R4 cnt1, iRegP_R3 str2,
-                 immI_1 int_cnt2, iRegI_R0 result, iRegI tmp1, iRegI tmp2,
-                 iRegI tmp3, iRegI tmp4, rFlagsReg cr)
+                 immI_1 int_cnt2, iRegI_R0 result, iRegINoSp tmp1, iRegINoSp tmp2,
+                 iRegINoSp tmp3, iRegINoSp tmp4, rFlagsReg cr)
 %{
   predicate(((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::UL);
   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2)));
@@ -15640,8 +15640,8 @@
 %}
 
 instruct string_indexof_conLU(iRegP_R1 str1, iRegI_R4 cnt1, iRegP_R3 str2,
-                 immI_1 int_cnt2, iRegI_R0 result, iRegI tmp1, iRegI tmp2,
-                 iRegI tmp3, iRegI tmp4, rFlagsReg cr)
+                 immI_1 int_cnt2, iRegI_R0 result, iRegINoSp tmp1, iRegINoSp tmp2,
+                 iRegINoSp tmp3, iRegINoSp tmp4, rFlagsReg cr)
 %{
   predicate(((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::LU);
   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2)));
@@ -15661,8 +15661,8 @@
 %}
 
 instruct string_indexofU_char(iRegP_R1 str1, iRegI_R2 cnt1, iRegI_R3 ch,
-                              iRegI_R0 result, iRegI tmp1, iRegI tmp2,
-                              iRegI tmp3, rFlagsReg cr)
+                              iRegI_R0 result, iRegINoSp tmp1, iRegINoSp tmp2,
+                              iRegINoSp tmp3, rFlagsReg cr)
 %{
   match(Set result (StrIndexOfChar (Binary str1 cnt1) ch));
   effect(USE_KILL str1, USE_KILL cnt1, USE_KILL ch,
@@ -16101,7 +16101,7 @@
 
 // ====================REDUCTION ARITHMETIC====================================
 
-instruct reduce_add2I(iRegINoSp dst, iRegIorL2I src1, vecD src2, iRegI tmp, iRegI tmp2)
+instruct reduce_add2I(iRegINoSp dst, iRegIorL2I src1, vecD src2, iRegINoSp tmp, iRegINoSp tmp2)
 %{
   match(Set dst (AddReductionVI src1 src2));
   ins_cost(INSN_COST);
@@ -16120,7 +16120,7 @@
   ins_pipe(pipe_class_default);
 %}
 
-instruct reduce_add4I(iRegINoSp dst, iRegIorL2I src1, vecX src2, vecX tmp, iRegI tmp2)
+instruct reduce_add4I(iRegINoSp dst, iRegIorL2I src1, vecX src2, vecX tmp, iRegINoSp tmp2)
 %{
   match(Set dst (AddReductionVI src1 src2));
   ins_cost(INSN_COST);
@@ -16138,7 +16138,7 @@
   ins_pipe(pipe_class_default);
 %}
 
-instruct reduce_mul2I(iRegINoSp dst, iRegIorL2I src1, vecD src2, iRegI tmp)
+instruct reduce_mul2I(iRegINoSp dst, iRegIorL2I src1, vecD src2, iRegINoSp tmp)
 %{
   match(Set dst (MulReductionVI src1 src2));
   ins_cost(INSN_COST);
@@ -16157,7 +16157,7 @@
   ins_pipe(pipe_class_default);
 %}
 
-instruct reduce_mul4I(iRegINoSp dst, iRegIorL2I src1, vecX src2, vecX tmp, iRegI tmp2)
+instruct reduce_mul4I(iRegINoSp dst, iRegIorL2I src1, vecX src2, vecX tmp, iRegINoSp tmp2)
 %{
   match(Set dst (MulReductionVI src1 src2));
   ins_cost(INSN_COST);
--- a/hotspot/src/cpu/aarch64/vm/jniFastGetField_aarch64.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/aarch64/vm/jniFastGetField_aarch64.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2017, 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.
  *
@@ -82,6 +82,11 @@
   __ eor(robj, robj, rcounter);               // obj, since
                                               // robj ^ rcounter ^ rcounter == robj
                                               // robj is address dependent on rcounter.
+
+  // If mask changes we need to ensure that the inverse is still encodable as an immediate
+  STATIC_ASSERT(JNIHandles::weak_tag_mask == 1);
+  __ andr(robj, robj, ~JNIHandles::weak_tag_mask);
+
   __ ldr(robj, Address(robj, 0));             // *obj
   __ lsr(roffset, c_rarg2, 2);                // offset
 
--- a/hotspot/src/cpu/aarch64/vm/sharedRuntime_aarch64.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/aarch64/vm/sharedRuntime_aarch64.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, 2015, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -2052,13 +2052,31 @@
 
   __ reset_last_Java_frame(false);
 
-  // Unpack oop result
+  // Unbox oop result, e.g. JNIHandles::resolve result.
   if (ret_type == T_OBJECT || ret_type == T_ARRAY) {
-      Label L;
-      __ cbz(r0, L);
-      __ ldr(r0, Address(r0, 0));
-      __ bind(L);
-      __ verify_oop(r0);
+    Label done, not_weak;
+    __ cbz(r0, done);           // Use NULL as-is.
+    STATIC_ASSERT(JNIHandles::weak_tag_mask == 1u);
+    __ tbz(r0, 0, not_weak);    // Test for jweak tag.
+    // Resolve jweak.
+    __ ldr(r0, Address(r0, -JNIHandles::weak_tag_value));
+    __ verify_oop(r0);
+#if INCLUDE_ALL_GCS
+    if (UseG1GC) {
+      __ g1_write_barrier_pre(noreg /* obj */,
+                              r0 /* pre_val */,
+                              rthread /* thread */,
+                              rscratch1 /* tmp */,
+                              true /* tosca_live */,
+                              true /* expand_call */);
+    }
+#endif // INCLUDE_ALL_GCS
+    __ b(done);
+    __ bind(not_weak);
+    // Resolve (untagged) jobject.
+    __ ldr(r0, Address(r0, 0));
+    __ verify_oop(r0);
+    __ bind(done);
   }
 
   if (CheckJNICalls) {
--- a/hotspot/src/cpu/aarch64/vm/templateInterpreterGenerator_aarch64.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/aarch64/vm/templateInterpreterGenerator_aarch64.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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.
  *
@@ -1399,13 +1399,32 @@
   // and result handler will pick it up
 
   {
-    Label no_oop, store_result;
+    Label no_oop, not_weak, store_result;
     __ adr(t, ExternalAddress(AbstractInterpreter::result_handler(T_OBJECT)));
     __ cmp(t, result_handler);
     __ br(Assembler::NE, no_oop);
-    // retrieve result
+    // Unbox oop result, e.g. JNIHandles::resolve result.
     __ pop(ltos);
-    __ cbz(r0, store_result);
+    __ cbz(r0, store_result);   // Use NULL as-is.
+    STATIC_ASSERT(JNIHandles::weak_tag_mask == 1u);
+    __ tbz(r0, 0, not_weak);    // Test for jweak tag.
+    // Resolve jweak.
+    __ ldr(r0, Address(r0, -JNIHandles::weak_tag_value));
+#if INCLUDE_ALL_GCS
+    if (UseG1GC) {
+      __ enter();                   // Barrier may call runtime.
+      __ g1_write_barrier_pre(noreg /* obj */,
+                              r0 /* pre_val */,
+                              rthread /* thread */,
+                              t /* tmp */,
+                              true /* tosca_live */,
+                              true /* expand_call */);
+      __ leave();
+    }
+#endif // INCLUDE_ALL_GCS
+    __ b(store_result);
+    __ bind(not_weak);
+    // Resolve (untagged) jobject.
     __ ldr(r0, Address(r0, 0));
     __ bind(store_result);
     __ str(r0, Address(rfp, frame::interpreter_frame_oop_temp_offset*wordSize));
--- a/hotspot/src/cpu/arm/vm/interp_masm_arm.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/arm/vm/interp_masm_arm.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -476,185 +476,6 @@
 }
 
 //////////////////////////////////////////////////////////////////////////////////
-#if INCLUDE_ALL_GCS
-
-// G1 pre-barrier.
-// Blows all volatile registers (R0-R3 on 32-bit ARM, R0-R18 on AArch64, Rtemp, LR).
-// If store_addr != noreg, then previous value is loaded from [store_addr];
-// in such case store_addr and new_val registers are preserved;
-// otherwise pre_val register is preserved.
-void InterpreterMacroAssembler::g1_write_barrier_pre(Register store_addr,
-                                                     Register new_val,
-                                                     Register pre_val,
-                                                     Register tmp1,
-                                                     Register tmp2) {
-  Label done;
-  Label runtime;
-
-  if (store_addr != noreg) {
-    assert_different_registers(store_addr, new_val, pre_val, tmp1, tmp2, noreg);
-  } else {
-    assert (new_val == noreg, "should be");
-    assert_different_registers(pre_val, tmp1, tmp2, noreg);
-  }
-
-  Address in_progress(Rthread, in_bytes(JavaThread::satb_mark_queue_offset() +
-                                        SATBMarkQueue::byte_offset_of_active()));
-  Address index(Rthread, in_bytes(JavaThread::satb_mark_queue_offset() +
-                                  SATBMarkQueue::byte_offset_of_index()));
-  Address buffer(Rthread, in_bytes(JavaThread::satb_mark_queue_offset() +
-                                   SATBMarkQueue::byte_offset_of_buf()));
-
-  // Is marking active?
-  assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "adjust this code");
-  ldrb(tmp1, in_progress);
-  cbz(tmp1, done);
-
-  // Do we need to load the previous value?
-  if (store_addr != noreg) {
-    load_heap_oop(pre_val, Address(store_addr, 0));
-  }
-
-  // Is the previous value null?
-  cbz(pre_val, done);
-
-  // Can we store original value in the thread's buffer?
-  // Is index == 0?
-  // (The index field is typed as size_t.)
-
-  ldr(tmp1, index);           // tmp1 := *index_adr
-  ldr(tmp2, buffer);
-
-  subs(tmp1, tmp1, wordSize); // tmp1 := tmp1 - wordSize
-  b(runtime, lt);             // If negative, goto runtime
-
-  str(tmp1, index);           // *index_adr := tmp1
-
-  // Record the previous value
-  str(pre_val, Address(tmp2, tmp1));
-  b(done);
-
-  bind(runtime);
-
-  // save the live input values
-#ifdef AARCH64
-  if (store_addr != noreg) {
-    raw_push(store_addr, new_val);
-  } else {
-    raw_push(pre_val, ZR);
-  }
-#else
-  if (store_addr != noreg) {
-    // avoid raw_push to support any ordering of store_addr and new_val
-    push(RegisterSet(store_addr) | RegisterSet(new_val));
-  } else {
-    push(pre_val);
-  }
-#endif // AARCH64
-
-  if (pre_val != R0) {
-    mov(R0, pre_val);
-  }
-  mov(R1, Rthread);
-
-  call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_pre), R0, R1);
-
-#ifdef AARCH64
-  if (store_addr != noreg) {
-    raw_pop(store_addr, new_val);
-  } else {
-    raw_pop(pre_val, ZR);
-  }
-#else
-  if (store_addr != noreg) {
-    pop(RegisterSet(store_addr) | RegisterSet(new_val));
-  } else {
-    pop(pre_val);
-  }
-#endif // AARCH64
-
-  bind(done);
-}
-
-// G1 post-barrier.
-// Blows all volatile registers (R0-R3 on 32-bit ARM, R0-R18 on AArch64, Rtemp, LR).
-void InterpreterMacroAssembler::g1_write_barrier_post(Register store_addr,
-                                                      Register new_val,
-                                                      Register tmp1,
-                                                      Register tmp2,
-                                                      Register tmp3) {
-
-  Address queue_index(Rthread, in_bytes(JavaThread::dirty_card_queue_offset() +
-                                        DirtyCardQueue::byte_offset_of_index()));
-  Address buffer(Rthread, in_bytes(JavaThread::dirty_card_queue_offset() +
-                                   DirtyCardQueue::byte_offset_of_buf()));
-
-  BarrierSet* bs = Universe::heap()->barrier_set();
-  CardTableModRefBS* ct = (CardTableModRefBS*)bs;
-  Label done;
-  Label runtime;
-
-  // Does store cross heap regions?
-
-  eor(tmp1, store_addr, new_val);
-#ifdef AARCH64
-  logical_shift_right(tmp1, tmp1, HeapRegion::LogOfHRGrainBytes);
-  cbz(tmp1, done);
-#else
-  movs(tmp1, AsmOperand(tmp1, lsr, HeapRegion::LogOfHRGrainBytes));
-  b(done, eq);
-#endif
-
-  // crosses regions, storing NULL?
-
-  cbz(new_val, done);
-
-  // storing region crossing non-NULL, is card already dirty?
-  const Register card_addr = tmp1;
-  assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
-
-  mov_address(tmp2, (address)ct->byte_map_base, symbolic_Relocation::card_table_reference);
-  add(card_addr, tmp2, AsmOperand(store_addr, lsr, CardTableModRefBS::card_shift));
-
-  ldrb(tmp2, Address(card_addr));
-  cmp(tmp2, (int)G1SATBCardTableModRefBS::g1_young_card_val());
-  b(done, eq);
-
-  membar(MacroAssembler::Membar_mask_bits(MacroAssembler::StoreLoad), tmp2);
-
-  assert(CardTableModRefBS::dirty_card_val() == 0, "adjust this code");
-  ldrb(tmp2, Address(card_addr));
-  cbz(tmp2, done);
-
-  // storing a region crossing, non-NULL oop, card is clean.
-  // dirty card and log.
-
-  strb(zero_register(tmp2), Address(card_addr));
-
-  ldr(tmp2, queue_index);
-  ldr(tmp3, buffer);
-
-  subs(tmp2, tmp2, wordSize);
-  b(runtime, lt); // go to runtime if now negative
-
-  str(tmp2, queue_index);
-
-  str(card_addr, Address(tmp3, tmp2));
-  b(done);
-
-  bind(runtime);
-
-  if (card_addr != R0) {
-    mov(R0, card_addr);
-  }
-  mov(R1, Rthread);
-  call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_post), R0, R1);
-
-  bind(done);
-}
-
-#endif // INCLUDE_ALL_GCS
-//////////////////////////////////////////////////////////////////////////////////
 
 
 // Java Expression Stack
--- a/hotspot/src/cpu/arm/vm/interp_masm_arm.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/arm/vm/interp_masm_arm.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -146,27 +146,6 @@
 
   void set_card(Register card_table_base, Address card_table_addr, Register tmp);
 
-#if INCLUDE_ALL_GCS
-  // G1 pre-barrier.
-  // Blows all volatile registers (R0-R3 on 32-bit ARM, R0-R18 on AArch64, Rtemp, LR).
-  // If store_addr != noreg, then previous value is loaded from [store_addr];
-  // in such case store_addr and new_val registers are preserved;
-  // otherwise pre_val register is preserved.
-  void g1_write_barrier_pre(Register store_addr,
-                            Register new_val,
-                            Register pre_val,
-                            Register tmp1,
-                            Register tmp2);
-
-  // G1 post-barrier.
-  // Blows all volatile registers (R0-R3 on 32-bit ARM, R0-R18 on AArch64, Rtemp, LR).
-  void g1_write_barrier_post(Register store_addr,
-                             Register new_val,
-                             Register tmp1,
-                             Register tmp2,
-                             Register tmp3);
-#endif // INCLUDE_ALL_GCS
-
   void pop_ptr(Register r);
   void pop_i(Register r = R0_tos);
 #ifdef AARCH64
--- a/hotspot/src/cpu/arm/vm/jniFastGetField_arm.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/arm/vm/jniFastGetField_arm.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -119,6 +119,14 @@
   __ ldr_s32(Rsafept_cnt, Address(Rsafepoint_counter_addr));
   __ tbnz(Rsafept_cnt, 0, slow_case);
 
+#ifdef AARCH64
+  // If mask changes we need to ensure that the inverse is still encodable as an immediate
+  STATIC_ASSERT(JNIHandles::weak_tag_mask == 1);
+  __ andr(R1, R1, ~JNIHandles::weak_tag_mask);
+#else
+  __ bic(R1, R1, JNIHandles::weak_tag_mask);
+#endif
+
   if (os::is_MP()) {
     // Address dependency restricts memory access ordering. It's cheaper than explicit LoadLoad barrier
     __ andr(Rtmp1, Rsafept_cnt, (unsigned)1);
--- a/hotspot/src/cpu/arm/vm/macroAssembler_arm.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/arm/vm/macroAssembler_arm.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -2211,6 +2211,219 @@
   b(done, eq);
 }
 
+
+void MacroAssembler::resolve_jobject(Register value,
+                                     Register tmp1,
+                                     Register tmp2) {
+  assert_different_registers(value, tmp1, tmp2);
+  Label done, not_weak;
+  cbz(value, done);             // Use NULL as-is.
+  STATIC_ASSERT(JNIHandles::weak_tag_mask == 1u);
+  tbz(value, 0, not_weak);      // Test for jweak tag.
+  // Resolve jweak.
+  ldr(value, Address(value, -JNIHandles::weak_tag_value));
+  verify_oop(value);
+#if INCLUDE_ALL_GCS
+  if (UseG1GC) {
+    g1_write_barrier_pre(noreg, // store_addr
+                         noreg, // new_val
+                         value, // pre_val
+                         tmp1,  // tmp1
+                         tmp2); // tmp2
+    }
+#endif // INCLUDE_ALL_GCS
+  b(done);
+  bind(not_weak);
+  // Resolve (untagged) jobject.
+  ldr(value, Address(value));
+  verify_oop(value);
+  bind(done);
+}
+
+
+//////////////////////////////////////////////////////////////////////////////////
+
+#if INCLUDE_ALL_GCS
+
+// G1 pre-barrier.
+// Blows all volatile registers (R0-R3 on 32-bit ARM, R0-R18 on AArch64, Rtemp, LR).
+// If store_addr != noreg, then previous value is loaded from [store_addr];
+// in such case store_addr and new_val registers are preserved;
+// otherwise pre_val register is preserved.
+void MacroAssembler::g1_write_barrier_pre(Register store_addr,
+                                          Register new_val,
+                                          Register pre_val,
+                                          Register tmp1,
+                                          Register tmp2) {
+  Label done;
+  Label runtime;
+
+  if (store_addr != noreg) {
+    assert_different_registers(store_addr, new_val, pre_val, tmp1, tmp2, noreg);
+  } else {
+    assert (new_val == noreg, "should be");
+    assert_different_registers(pre_val, tmp1, tmp2, noreg);
+  }
+
+  Address in_progress(Rthread, in_bytes(JavaThread::satb_mark_queue_offset() +
+                                        SATBMarkQueue::byte_offset_of_active()));
+  Address index(Rthread, in_bytes(JavaThread::satb_mark_queue_offset() +
+                                  SATBMarkQueue::byte_offset_of_index()));
+  Address buffer(Rthread, in_bytes(JavaThread::satb_mark_queue_offset() +
+                                   SATBMarkQueue::byte_offset_of_buf()));
+
+  // Is marking active?
+  assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "adjust this code");
+  ldrb(tmp1, in_progress);
+  cbz(tmp1, done);
+
+  // Do we need to load the previous value?
+  if (store_addr != noreg) {
+    load_heap_oop(pre_val, Address(store_addr, 0));
+  }
+
+  // Is the previous value null?
+  cbz(pre_val, done);
+
+  // Can we store original value in the thread's buffer?
+  // Is index == 0?
+  // (The index field is typed as size_t.)
+
+  ldr(tmp1, index);           // tmp1 := *index_adr
+  ldr(tmp2, buffer);
+
+  subs(tmp1, tmp1, wordSize); // tmp1 := tmp1 - wordSize
+  b(runtime, lt);             // If negative, goto runtime
+
+  str(tmp1, index);           // *index_adr := tmp1
+
+  // Record the previous value
+  str(pre_val, Address(tmp2, tmp1));
+  b(done);
+
+  bind(runtime);
+
+  // save the live input values
+#ifdef AARCH64
+  if (store_addr != noreg) {
+    raw_push(store_addr, new_val);
+  } else {
+    raw_push(pre_val, ZR);
+  }
+#else
+  if (store_addr != noreg) {
+    // avoid raw_push to support any ordering of store_addr and new_val
+    push(RegisterSet(store_addr) | RegisterSet(new_val));
+  } else {
+    push(pre_val);
+  }
+#endif // AARCH64
+
+  if (pre_val != R0) {
+    mov(R0, pre_val);
+  }
+  mov(R1, Rthread);
+
+  call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_pre), R0, R1);
+
+#ifdef AARCH64
+  if (store_addr != noreg) {
+    raw_pop(store_addr, new_val);
+  } else {
+    raw_pop(pre_val, ZR);
+  }
+#else
+  if (store_addr != noreg) {
+    pop(RegisterSet(store_addr) | RegisterSet(new_val));
+  } else {
+    pop(pre_val);
+  }
+#endif // AARCH64
+
+  bind(done);
+}
+
+// G1 post-barrier.
+// Blows all volatile registers (R0-R3 on 32-bit ARM, R0-R18 on AArch64, Rtemp, LR).
+void MacroAssembler::g1_write_barrier_post(Register store_addr,
+                                           Register new_val,
+                                           Register tmp1,
+                                           Register tmp2,
+                                           Register tmp3) {
+
+  Address queue_index(Rthread, in_bytes(JavaThread::dirty_card_queue_offset() +
+                                        DirtyCardQueue::byte_offset_of_index()));
+  Address buffer(Rthread, in_bytes(JavaThread::dirty_card_queue_offset() +
+                                   DirtyCardQueue::byte_offset_of_buf()));
+
+  BarrierSet* bs = Universe::heap()->barrier_set();
+  CardTableModRefBS* ct = (CardTableModRefBS*)bs;
+  Label done;
+  Label runtime;
+
+  // Does store cross heap regions?
+
+  eor(tmp1, store_addr, new_val);
+#ifdef AARCH64
+  logical_shift_right(tmp1, tmp1, HeapRegion::LogOfHRGrainBytes);
+  cbz(tmp1, done);
+#else
+  movs(tmp1, AsmOperand(tmp1, lsr, HeapRegion::LogOfHRGrainBytes));
+  b(done, eq);
+#endif
+
+  // crosses regions, storing NULL?
+
+  cbz(new_val, done);
+
+  // storing region crossing non-NULL, is card already dirty?
+  const Register card_addr = tmp1;
+  assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
+
+  mov_address(tmp2, (address)ct->byte_map_base, symbolic_Relocation::card_table_reference);
+  add(card_addr, tmp2, AsmOperand(store_addr, lsr, CardTableModRefBS::card_shift));
+
+  ldrb(tmp2, Address(card_addr));
+  cmp(tmp2, (int)G1SATBCardTableModRefBS::g1_young_card_val());
+  b(done, eq);
+
+  membar(MacroAssembler::Membar_mask_bits(MacroAssembler::StoreLoad), tmp2);
+
+  assert(CardTableModRefBS::dirty_card_val() == 0, "adjust this code");
+  ldrb(tmp2, Address(card_addr));
+  cbz(tmp2, done);
+
+  // storing a region crossing, non-NULL oop, card is clean.
+  // dirty card and log.
+
+  strb(zero_register(tmp2), Address(card_addr));
+
+  ldr(tmp2, queue_index);
+  ldr(tmp3, buffer);
+
+  subs(tmp2, tmp2, wordSize);
+  b(runtime, lt); // go to runtime if now negative
+
+  str(tmp2, queue_index);
+
+  str(card_addr, Address(tmp3, tmp2));
+  b(done);
+
+  bind(runtime);
+
+  if (card_addr != R0) {
+    mov(R0, card_addr);
+  }
+  mov(R1, Rthread);
+  call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_post), R0, R1);
+
+  bind(done);
+}
+
+#endif // INCLUDE_ALL_GCS
+
+//////////////////////////////////////////////////////////////////////////////////
+
 #ifdef AARCH64
 
 void MacroAssembler::load_sized_value(Register dst, Address src, size_t size_in_bytes, bool is_signed) {
--- a/hotspot/src/cpu/arm/vm/macroAssembler_arm.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/arm/vm/macroAssembler_arm.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -402,6 +402,29 @@
   void biased_locking_enter_with_cas(Register obj_reg, Register old_mark_reg, Register new_mark_reg,
                                      Register tmp, Label& slow_case, int* counter_addr);
 
+  void resolve_jobject(Register value, Register tmp1, Register tmp2);
+
+#if INCLUDE_ALL_GCS
+  // G1 pre-barrier.
+  // Blows all volatile registers (R0-R3 on 32-bit ARM, R0-R18 on AArch64, Rtemp, LR).
+  // If store_addr != noreg, then previous value is loaded from [store_addr];
+  // in such case store_addr and new_val registers are preserved;
+  // otherwise pre_val register is preserved.
+  void g1_write_barrier_pre(Register store_addr,
+                            Register new_val,
+                            Register pre_val,
+                            Register tmp1,
+                            Register tmp2);
+
+  // G1 post-barrier.
+  // Blows all volatile registers (R0-R3 on 32-bit ARM, R0-R18 on AArch64, Rtemp, LR).
+  void g1_write_barrier_post(Register store_addr,
+                             Register new_val,
+                             Register tmp1,
+                             Register tmp2,
+                             Register tmp3);
+#endif // INCLUDE_ALL_GCS
+
 #ifndef AARCH64
   void nop() {
     mov(R0, R0);
--- a/hotspot/src/cpu/arm/vm/sharedRuntime_arm.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/arm/vm/sharedRuntime_arm.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1732,14 +1732,7 @@
   case T_FLOAT  : // fall through
   case T_DOUBLE : /* nothing to do */          break;
   case T_OBJECT : // fall through
-  case T_ARRAY  : {
-    Label L;
-    __ cbz(R0, L);
-    __ ldr(R0, Address(R0));
-    __ verify_oop(R0);
-    __ bind(L);
-    break;
-  }
+  case T_ARRAY  : break; // See JNIHandles::resolve below
   default:
     ShouldNotReachHere();
   }
@@ -1748,13 +1741,14 @@
   if (CheckJNICalls) {
     __ str(__ zero_register(Rtemp), Address(Rthread, JavaThread::pending_jni_exception_check_fn_offset()));
   }
+#endif // AARCH64
 
-  // Unhandle the result
+  // Unbox oop result, e.g. JNIHandles::resolve value in R0.
   if (ret_type == T_OBJECT || ret_type == T_ARRAY) {
-    __ cmp(R0, 0);
-    __ ldr(R0, Address(R0), ne);
+    __ resolve_jobject(R0,      // value
+                       Rtemp,   // tmp1
+                       R1_tmp); // tmp2
   }
-#endif // AARCH64
 
   // Any exception pending?
   __ ldr(Rtemp, Address(Rthread, Thread::pending_exception_offset()));
--- a/hotspot/src/cpu/arm/vm/templateInterpreterGenerator_arm.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/arm/vm/templateInterpreterGenerator_arm.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1240,28 +1240,25 @@
     __ str(__ zero_register(Rtemp), Address(Rthread, JavaThread::pending_jni_exception_check_fn_offset()));
   }
 
-  // Unbox if the result is non-zero object
+  // Unbox oop result, e.g. JNIHandles::resolve result if it's an oop.
+  {
+    Label Lnot_oop;
 #ifdef AARCH64
-  {
-    Label L, Lnull;
     __ mov_slow(Rtemp, AbstractInterpreter::result_handler(T_OBJECT));
     __ cmp(Rresult_handler, Rtemp);
-    __ b(L, ne);
-    __ cbz(Rsaved_result, Lnull);
-    __ ldr(Rsaved_result, Address(Rsaved_result));
-    __ bind(Lnull);
-    // Store oop on the stack for GC
-    __ str(Rsaved_result, Address(FP, frame::interpreter_frame_oop_temp_offset * wordSize));
-    __ bind(L);
+    __ b(Lnot_oop, ne);
+#else // !AARCH64
+    // For ARM32, Rresult_handler is -1 for oop result, 0 otherwise.
+    __ cbz(Rresult_handler, Lnot_oop);
+#endif // !AARCH64
+    Register value = AARCH64_ONLY(Rsaved_result) NOT_AARCH64(Rsaved_result_lo);
+    __ resolve_jobject(value,   // value
+                       Rtemp,   // tmp1
+                       R1_tmp); // tmp2
+    // Store resolved result in frame for GC visibility.
+    __ str(value, Address(FP, frame::interpreter_frame_oop_temp_offset * wordSize));
+    __ bind(Lnot_oop);
   }
-#else
-  __ tst(Rsaved_result_lo, Rresult_handler);
-  __ ldr(Rsaved_result_lo, Address(Rsaved_result_lo), ne);
-
-  // Store oop on the stack for GC
-  __ cmp(Rresult_handler, 0);
-  __ str(Rsaved_result_lo, Address(FP, frame::interpreter_frame_oop_temp_offset * wordSize), ne);
-#endif // AARCH64
 
 #ifdef AARCH64
   // Restore SP (drop native parameters area), to keep SP in sync with extended_sp in frame
--- a/hotspot/src/cpu/ppc/vm/frame_ppc.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/ppc/vm/frame_ppc.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
+ * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017 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
@@ -171,10 +171,7 @@
     switch (method->result_type()) {
       case T_OBJECT:
       case T_ARRAY: {
-        oop* obj_p = *(oop**)lresult;
-        oop obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
-        assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
-        *oop_result = obj;
+        *oop_result = JNIHandles::resolve(*(jobject*)lresult);
         break;
       }
       // We use std/stfd to store the values.
--- a/hotspot/src/cpu/ppc/vm/macroAssembler_ppc.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/ppc/vm/macroAssembler_ppc.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017 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
@@ -3033,6 +3033,34 @@
   stbx(R0, Rtmp, Robj);
 }
 
+// Kills R31 if value is a volatile register.
+void MacroAssembler::resolve_jobject(Register value, Register tmp1, Register tmp2, bool needs_frame) {
+  Label done;
+  cmpdi(CCR0, value, 0);
+  beq(CCR0, done);         // Use NULL as-is.
+
+  clrrdi(tmp1, value, JNIHandles::weak_tag_size);
+#if INCLUDE_ALL_GCS
+  if (UseG1GC) { andi_(tmp2, value, JNIHandles::weak_tag_mask); }
+#endif
+  ld(value, 0, tmp1);      // Resolve (untagged) jobject.
+
+#if INCLUDE_ALL_GCS
+  if (UseG1GC) {
+    Label not_weak;
+    beq(CCR0, not_weak);   // Test for jweak tag.
+    verify_oop(value);
+    g1_write_barrier_pre(noreg, // obj
+                         noreg, // offset
+                         value, // pre_val
+                         tmp1, tmp2, needs_frame);
+    bind(not_weak);
+  }
+#endif // INCLUDE_ALL_GCS
+  verify_oop(value);
+  bind(done);
+}
+
 #if INCLUDE_ALL_GCS
 // General G1 pre-barrier generator.
 // Goal: record the previous value if it is not null.
@@ -3094,7 +3122,7 @@
 
   bind(runtime);
 
-  // VM call need frame to access(write) O register.
+  // May need to preserve LR. Also needed if current frame is not compatible with C calling convention.
   if (needs_frame) {
     save_LR_CR(Rtmp1);
     push_frame_reg_args(0, Rtmp2);
--- a/hotspot/src/cpu/ppc/vm/macroAssembler_ppc.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/ppc/vm/macroAssembler_ppc.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017 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
@@ -649,6 +649,8 @@
   void card_write_barrier_post(Register Rstore_addr, Register Rnew_val, Register Rtmp);
   void card_table_write(jbyte* byte_map_base, Register Rtmp, Register Robj);
 
+  void resolve_jobject(Register value, Register tmp1, Register tmp2, bool needs_frame);
+
 #if INCLUDE_ALL_GCS
   // General G1 pre-barrier generator.
   void g1_write_barrier_pre(Register Robj, RegisterOrConstant offset, Register Rpre_val,
--- a/hotspot/src/cpu/ppc/vm/sharedRuntime_ppc.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/ppc/vm/sharedRuntime_ppc.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017 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
@@ -2477,16 +2477,11 @@
 
   __ reset_last_Java_frame();
 
-  // Unpack oop result.
+  // Unbox oop result, e.g. JNIHandles::resolve value.
   // --------------------------------------------------------------------------
 
   if (ret_type == T_OBJECT || ret_type == T_ARRAY) {
-    Label skip_unboxing;
-    __ cmpdi(CCR0, R3_RET, 0);
-    __ beq(CCR0, skip_unboxing);
-    __ ld(R3_RET, 0, R3_RET);
-    __ bind(skip_unboxing);
-    __ verify_oop(R3_RET);
+    __ resolve_jobject(R3_RET, r_temp_1, r_temp_2, /* needs_frame */ false); // kills R31
   }
 
   if (CheckJNICalls) {
--- a/hotspot/src/cpu/ppc/vm/templateInterpreterGenerator_ppc.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/ppc/vm/templateInterpreterGenerator_ppc.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2015, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017 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
@@ -401,11 +401,8 @@
   case T_LONG:
      break;
   case T_OBJECT:
-    // unbox result if not null
-    __ cmpdi(CCR0, R3_RET, 0);
-    __ beq(CCR0, done);
-    __ ld(R3_RET, 0, R3_RET);
-    __ verify_oop(R3_RET);
+    // JNIHandles::resolve result.
+    __ resolve_jobject(R3_RET, R11_scratch1, R12_scratch2, /* needs_frame */ true); // kills R31
     break;
   case T_FLOAT:
      break;
--- a/hotspot/src/cpu/s390/vm/macroAssembler_s390.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/s390/vm/macroAssembler_s390.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -3439,6 +3439,34 @@
   z_mvi(0, store_addr, 0); // Store byte 0.
 }
 
+void MacroAssembler::resolve_jobject(Register value, Register tmp1, Register tmp2) {
+  NearLabel Ldone;
+  z_ltgr(tmp1, value);
+  z_bre(Ldone);          // Use NULL result as-is.
+
+  z_nill(value, ~JNIHandles::weak_tag_mask);
+  z_lg(value, 0, value); // Resolve (untagged) jobject.
+
+#if INCLUDE_ALL_GCS
+  if (UseG1GC) {
+    NearLabel Lnot_weak;
+    z_tmll(tmp1, JNIHandles::weak_tag_mask); // Test for jweak tag.
+    z_braz(Lnot_weak);
+    verify_oop(value);
+    g1_write_barrier_pre(noreg /* obj */,
+                         noreg /* offset */,
+                         value /* pre_val */,
+                         noreg /* val */,
+                         tmp1  /* tmp1 */,
+                         tmp2  /* tmp2 */,
+                         true  /* pre_val_needed */);
+    bind(Lnot_weak);
+  }
+#endif // INCLUDE_ALL_GCS
+  verify_oop(value);
+  bind(Ldone);
+}
+
 #if INCLUDE_ALL_GCS
 
 //------------------------------------------------------
--- a/hotspot/src/cpu/s390/vm/macroAssembler_s390.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/s390/vm/macroAssembler_s390.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -726,6 +726,8 @@
   // Write to card table for modification at store_addr - register is destroyed afterwards.
   void card_write_barrier_post(Register store_addr, Register tmp);
 
+  void resolve_jobject(Register value, Register tmp1, Register tmp2);
+
 #if INCLUDE_ALL_GCS
   // General G1 pre-barrier generator.
   // Purpose: record the previous value if it is not null.
--- a/hotspot/src/cpu/s390/vm/sharedRuntime_s390.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/s390/vm/sharedRuntime_s390.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017 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
@@ -2272,13 +2272,9 @@
 
   __ reset_last_Java_frame();
 
-  // Unpack oop result
+  // Unpack oop result, e.g. JNIHandles::resolve result.
   if (ret_type == T_OBJECT || ret_type == T_ARRAY) {
-    NearLabel L;
-    __ compare64_and_branch(Z_RET, (RegisterOrConstant)0L, Assembler::bcondEqual, L);
-    __ z_lg(Z_RET, 0, Z_RET);
-    __ bind(L);
-    __ verify_oop(Z_RET);
+    __ resolve_jobject(Z_RET, /* tmp1 */ Z_R13, /* tmp2 */ Z_R7);
   }
 
   if (CheckJNICalls) {
--- a/hotspot/src/cpu/s390/vm/templateInterpreterGenerator_s390.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/s390/vm/templateInterpreterGenerator_s390.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017 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
@@ -1695,14 +1695,11 @@
   // from the jni handle to z_ijava_state.oop_temp. This is
   // necessary, because we reset the jni handle block below.
   // NOTE: frame::interpreter_frame_result() depends on this, too.
-  { NearLabel no_oop_result, store_oop_result;
+  { NearLabel no_oop_result;
   __ load_absolute_address(Z_R1, AbstractInterpreter::result_handler(T_OBJECT));
   __ compareU64_and_branch(Z_R1, Rresult_handler, Assembler::bcondNotEqual, no_oop_result);
-  __ compareU64_and_branch(Rlresult, (intptr_t)0L, Assembler::bcondEqual, store_oop_result);
-  __ z_lg(Rlresult, 0, Rlresult);  // unbox
-  __ bind(store_oop_result);
+  __ resolve_jobject(Rlresult, /* tmp1 */ Rmethod, /* tmp2 */ Z_R1);
   __ z_stg(Rlresult, oop_tmp_offset, Z_fp);
-  __ verify_oop(Rlresult);
   __ bind(no_oop_result);
   }
 
--- a/hotspot/src/cpu/sparc/vm/jniFastGetField_sparc.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/sparc/vm/jniFastGetField_sparc.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
  * 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,6 +68,7 @@
   __ andcc (G4, 1, G0);
   __ br (Assembler::notZero, false, Assembler::pn, label1);
   __ delayed()->srl (O2, 2, O4);
+  __ andn (O1, JNIHandles::weak_tag_mask, O1);
   __ ld_ptr (O1, 0, O5);
 
   assert(count < LIST_CAPACITY, "LIST_CAPACITY too small");
@@ -147,6 +148,7 @@
   __ andcc (G4, 1, G0);
   __ br (Assembler::notZero, false, Assembler::pn, label1);
   __ delayed()->srl (O2, 2, O4);
+  __ andn (O1, JNIHandles::weak_tag_mask, O1);
   __ ld_ptr (O1, 0, O5);
   __ add (O5, O4, O5);
 
@@ -219,6 +221,7 @@
   __ andcc (G4, 1, G0);
   __ br (Assembler::notZero, false, Assembler::pn, label1);
   __ delayed()->srl (O2, 2, O4);
+  __ andn (O1, JNIHandles::weak_tag_mask, O1);
   __ ld_ptr (O1, 0, O5);
 
   assert(count < LIST_CAPACITY, "LIST_CAPACITY too small");
--- a/hotspot/src/cpu/sparc/vm/sharedRuntime_sparc.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/sparc/vm/sharedRuntime_sparc.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -2754,15 +2754,30 @@
   __ verify_thread(); // G2_thread must be correct
   __ reset_last_Java_frame();
 
-  // Unpack oop result
+  // Unbox oop result, e.g. JNIHandles::resolve value in I0.
   if (ret_type == T_OBJECT || ret_type == T_ARRAY) {
-      Label L;
-      __ addcc(G0, I0, G0);
-      __ brx(Assembler::notZero, true, Assembler::pt, L);
-      __ delayed()->ld_ptr(I0, 0, I0);
-      __ mov(G0, I0);
-      __ bind(L);
-      __ verify_oop(I0);
+    Label done, not_weak;
+    __ br_null(I0, false, Assembler::pn, done); // Use NULL as-is.
+    __ delayed()->andcc(I0, JNIHandles::weak_tag_mask, G0); // Test for jweak
+    __ brx(Assembler::zero, true, Assembler::pt, not_weak);
+    __ delayed()->ld_ptr(I0, 0, I0); // Maybe resolve (untagged) jobject.
+    // Resolve jweak.
+    __ ld_ptr(I0, -JNIHandles::weak_tag_value, I0);
+#if INCLUDE_ALL_GCS
+    if (UseG1GC) {
+      // Copy to O0 because macro doesn't allow pre_val in input reg.
+      __ mov(I0, O0);
+      __ g1_write_barrier_pre(noreg /* obj */,
+                              noreg /* index */,
+                              0 /* offset */,
+                              O0 /* pre_val */,
+                              G3_scratch /* tmp */,
+                              true /* preserve_o_regs */);
+    }
+#endif // INCLUDE_ALL_GCS
+    __ bind(not_weak);
+    __ verify_oop(I0);
+    __ bind(done);
   }
 
   if (CheckJNICalls) {
--- a/hotspot/src/cpu/sparc/vm/templateInterpreterGenerator_sparc.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/sparc/vm/templateInterpreterGenerator_sparc.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1516,11 +1516,23 @@
 
     __ set((intptr_t)AbstractInterpreter::result_handler(T_OBJECT), G3_scratch);
     __ cmp_and_brx_short(G3_scratch, Lscratch, Assembler::notEqual, Assembler::pt, no_oop);
-    __ addcc(G0, O0, O0);
-    __ brx(Assembler::notZero, true, Assembler::pt, store_result);     // if result is not NULL:
-    __ delayed()->ld_ptr(O0, 0, O0);                                   // unbox it
-    __ mov(G0, O0);
-
+    // Unbox oop result, e.g. JNIHandles::resolve value in O0.
+    __ br_null(O0, false, Assembler::pn, store_result); // Use NULL as-is.
+    __ delayed()->andcc(O0, JNIHandles::weak_tag_mask, G0); // Test for jweak
+    __ brx(Assembler::zero, true, Assembler::pt, store_result);
+    __ delayed()->ld_ptr(O0, 0, O0); // Maybe resolve (untagged) jobject.
+    // Resolve jweak.
+    __ ld_ptr(O0, -JNIHandles::weak_tag_value, O0);
+#if INCLUDE_ALL_GCS
+    if (UseG1GC) {
+      __ g1_write_barrier_pre(noreg /* obj */,
+                              noreg /* index */,
+                              0 /* offset */,
+                              O0 /* pre_val */,
+                              G3_scratch /* tmp */,
+                              true /* preserve_o_regs */);
+    }
+#endif // INCLUDE_ALL_GCS
     __ bind(store_result);
     // Store it where gc will look for it and result handler expects it.
     __ st_ptr(O0, FP, (frame::interpreter_frame_oop_temp_offset*wordSize) + STACK_BIAS);
--- a/hotspot/src/cpu/x86/vm/jniFastGetField_x86_32.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/x86/vm/jniFastGetField_x86_32.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -85,6 +85,9 @@
     __ movptr (rdx, Address(rsp, 2*wordSize));  // obj
   }
   __ movptr(rax, Address(rsp, 3*wordSize));  // jfieldID
+
+  __ clear_jweak_tag(rdx);
+
   __ movptr(rdx, Address(rdx, 0));           // *obj
   __ shrptr (rax, 2);                         // offset
 
@@ -202,6 +205,9 @@
     __ movptr(rdx, Address(rsp, 3*wordSize));  // obj
   }
   __ movptr(rsi, Address(rsp, 4*wordSize));  // jfieldID
+
+  __ clear_jweak_tag(rdx);
+
   __ movptr(rdx, Address(rdx, 0));           // *obj
   __ shrptr(rsi, 2);                         // offset
 
@@ -291,6 +297,9 @@
     __ movptr(rdx, Address(rsp, 2*wordSize)); // obj
   }
   __ movptr(rax, Address(rsp, 3*wordSize));  // jfieldID
+
+  __ clear_jweak_tag(rdx);
+
   __ movptr(rdx, Address(rdx, 0));           // *obj
   __ shrptr(rax, 2);                         // offset
 
--- a/hotspot/src/cpu/x86/vm/jniFastGetField_x86_64.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/x86/vm/jniFastGetField_x86_64.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -80,6 +80,9 @@
                                                 // robj ^ rcounter ^ rcounter == robj
                                                 // robj is data dependent on rcounter.
   }
+
+  __ clear_jweak_tag(robj);
+
   __ movptr(robj, Address(robj, 0));             // *obj
   __ mov   (roffset, c_rarg2);
   __ shrptr(roffset, 2);                         // offset
@@ -178,6 +181,9 @@
                                                 // robj ^ rcounter ^ rcounter == robj
                                                 // robj is data dependent on rcounter.
   }
+
+  __ clear_jweak_tag(robj);
+
   __ movptr(robj, Address(robj, 0));             // *obj
   __ mov   (roffset, c_rarg2);
   __ shrptr(roffset, 2);                         // offset
--- a/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -5129,6 +5129,43 @@
 }
 
 
+void MacroAssembler::resolve_jobject(Register value,
+                                     Register thread,
+                                     Register tmp) {
+  assert_different_registers(value, thread, tmp);
+  Label done, not_weak;
+  testptr(value, value);
+  jcc(Assembler::zero, done);                // Use NULL as-is.
+  testptr(value, JNIHandles::weak_tag_mask); // Test for jweak tag.
+  jcc(Assembler::zero, not_weak);
+  // Resolve jweak.
+  movptr(value, Address(value, -JNIHandles::weak_tag_value));
+  verify_oop(value);
+#if INCLUDE_ALL_GCS
+  if (UseG1GC) {
+    g1_write_barrier_pre(noreg /* obj */,
+                         value /* pre_val */,
+                         thread /* thread */,
+                         tmp /* tmp */,
+                         true /* tosca_live */,
+                         true /* expand_call */);
+  }
+#endif // INCLUDE_ALL_GCS
+  jmp(done);
+  bind(not_weak);
+  // Resolve (untagged) jobject.
+  movptr(value, Address(value, 0));
+  verify_oop(value);
+  bind(done);
+}
+
+void MacroAssembler::clear_jweak_tag(Register possibly_jweak) {
+  const int32_t inverted_jweak_mask = ~static_cast<int32_t>(JNIHandles::weak_tag_mask);
+  STATIC_ASSERT(inverted_jweak_mask == -2); // otherwise check this code
+  // The inverted mask is sign-extended
+  andptr(possibly_jweak, inverted_jweak_mask);
+}
+
 //////////////////////////////////////////////////////////////////////////////////
 #if INCLUDE_ALL_GCS
 
--- a/hotspot/src/cpu/x86/vm/macroAssembler_x86.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/x86/vm/macroAssembler_x86.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -297,6 +297,9 @@
   void store_check(Register obj);                // store check for obj - register is destroyed afterwards
   void store_check(Register obj, Address dst);   // same as above, dst is exact store location (reg. is destroyed)
 
+  void resolve_jobject(Register value, Register thread, Register tmp);
+  void clear_jweak_tag(Register possibly_jweak);
+
 #if INCLUDE_ALL_GCS
 
   void g1_write_barrier_pre(Register obj,
--- a/hotspot/src/cpu/x86/vm/sharedRuntime_x86_32.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/x86/vm/sharedRuntime_x86_32.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -2226,14 +2226,11 @@
 
   __ reset_last_Java_frame(thread, false);
 
-  // Unpack oop result
+  // Unbox oop result, e.g. JNIHandles::resolve value.
   if (ret_type == T_OBJECT || ret_type == T_ARRAY) {
-      Label L;
-      __ cmpptr(rax, (int32_t)NULL_WORD);
-      __ jcc(Assembler::equal, L);
-      __ movptr(rax, Address(rax, 0));
-      __ bind(L);
-      __ verify_oop(rax);
+    __ resolve_jobject(rax /* value */,
+                       thread /* thread */,
+                       rcx /* tmp */);
   }
 
   if (CheckJNICalls) {
--- a/hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -2579,14 +2579,11 @@
 
   __ reset_last_Java_frame(false);
 
-  // Unpack oop result
+  // Unbox oop result, e.g. JNIHandles::resolve value.
   if (ret_type == T_OBJECT || ret_type == T_ARRAY) {
-      Label L;
-      __ testptr(rax, rax);
-      __ jcc(Assembler::zero, L);
-      __ movptr(rax, Address(rax, 0));
-      __ bind(L);
-      __ verify_oop(rax);
+    __ resolve_jobject(rax /* value */,
+                       r15_thread /* thread */,
+                       rcx /* tmp */);
   }
 
   if (CheckJNICalls) {
--- a/hotspot/src/cpu/x86/vm/templateInterpreterGenerator_x86.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/x86/vm/templateInterpreterGenerator_x86.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1193,16 +1193,16 @@
   // and result handler will pick it up
 
   {
-    Label no_oop, store_result;
+    Label no_oop, not_weak, store_result;
     __ lea(t, ExternalAddress(AbstractInterpreter::result_handler(T_OBJECT)));
     __ cmpptr(t, Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize));
     __ jcc(Assembler::notEqual, no_oop);
     // retrieve result
     __ pop(ltos);
-    __ testptr(rax, rax);
-    __ jcc(Assembler::zero, store_result);
-    __ movptr(rax, Address(rax, 0));
-    __ bind(store_result);
+    // Unbox oop result, e.g. JNIHandles::resolve value.
+    __ resolve_jobject(rax /* value */,
+                       thread /* thread */,
+                       t /* tmp */);
     __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize), rax);
     // keep stack depth as expected by pushing oop which will eventually be discarded
     __ push(ltos);
--- a/hotspot/src/cpu/zero/vm/cppInterpreter_zero.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/cpu/zero/vm/cppInterpreter_zero.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -406,10 +406,12 @@
   // oop_temp where the garbage collector can see it before
   // we release the handle it might be protected by.
   if (handler->result_type() == &ffi_type_pointer) {
-    if (result[0])
-      istate->set_oop_temp(*(oop *) result[0]);
-    else
+    if (result[0] == 0) {
       istate->set_oop_temp(NULL);
+    } else {
+      jobject handle = reinterpret_cast<jobject>(result[0]);
+      istate->set_oop_temp(JNIHandles::resolve(handle));
+    }
   }
 
   // Reset handle block
--- a/hotspot/src/share/vm/Xusage.txt	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/Xusage.txt	Wed Jul 05 23:08:24 2017 +0200
@@ -12,7 +12,7 @@
     -Xms<size>        set initial Java heap size
     -Xmx<size>        set maximum Java heap size
     -Xss<size>        set java thread stack size
-    -Xprof            output cpu profiling data
+    -Xprof            output cpu profiling data (deprecated)
     -Xfuture          enable strictest checks, anticipating future default
     -Xrs              reduce use of OS signals by Java/VM (see documentation)
     -Xcheck:jni       perform additional checks for JNI functions
--- a/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1540,7 +1540,7 @@
         ciMethod* caller = state()->scope()->method();
         ciMethodData* md = caller->method_data_or_null();
         ciProfileData* data = md->bci_to_data(invoke_bci);
-        if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {
+        if (data != NULL && (data->is_CallTypeData() || data->is_VirtualCallTypeData())) {
           bool has_return = data->is_CallTypeData() ? ((ciCallTypeData*)data)->has_return() : ((ciVirtualCallTypeData*)data)->has_return();
           // May not be true in case of an inlined call through a method handle intrinsic.
           if (has_return) {
@@ -1758,7 +1758,7 @@
   start = has_receiver ? 1 : 0;
   if (profile_arguments()) {
     ciProfileData* data = method()->method_data()->bci_to_data(bci());
-    if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {
+    if (data != NULL && (data->is_CallTypeData() || data->is_VirtualCallTypeData())) {
       n = data->is_CallTypeData() ? data->as_CallTypeData()->number_of_arguments() : data->as_VirtualCallTypeData()->number_of_arguments();
     }
   }
@@ -4349,7 +4349,7 @@
   }
   ciMethodData* md = m->method_data_or_null();
   ciProfileData* data = md->bci_to_data(invoke_bci);
-  if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {
+  if (data != NULL && (data->is_CallTypeData() || data->is_VirtualCallTypeData())) {
     append(new ProfileReturnType(m , invoke_bci, callee, ret));
   }
 }
--- a/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -3262,50 +3262,52 @@
     int bci = x->bci_of_invoke();
     ciMethodData* md = x->method()->method_data_or_null();
     ciProfileData* data = md->bci_to_data(bci);
-    if ((data->is_CallTypeData() && data->as_CallTypeData()->has_arguments()) ||
-        (data->is_VirtualCallTypeData() && data->as_VirtualCallTypeData()->has_arguments())) {
-      ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();
-      int base_offset = md->byte_offset_of_slot(data, extra);
-      LIR_Opr mdp = LIR_OprFact::illegalOpr;
-      ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args();
-
-      Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
-      int start = 0;
-      int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments();
-      if (x->callee()->is_loaded() && x->callee()->is_static() && Bytecodes::has_receiver(bc)) {
-        // first argument is not profiled at call (method handle invoke)
-        assert(x->method()->raw_code_at_bci(bci) == Bytecodes::_invokehandle, "invokehandle expected");
-        start = 1;
+    if (data != NULL) {
+      if ((data->is_CallTypeData() && data->as_CallTypeData()->has_arguments()) ||
+          (data->is_VirtualCallTypeData() && data->as_VirtualCallTypeData()->has_arguments())) {
+        ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();
+        int base_offset = md->byte_offset_of_slot(data, extra);
+        LIR_Opr mdp = LIR_OprFact::illegalOpr;
+        ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args();
+
+        Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
+        int start = 0;
+        int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments();
+        if (x->callee()->is_loaded() && x->callee()->is_static() && Bytecodes::has_receiver(bc)) {
+          // first argument is not profiled at call (method handle invoke)
+          assert(x->method()->raw_code_at_bci(bci) == Bytecodes::_invokehandle, "invokehandle expected");
+          start = 1;
+        }
+        ciSignature* callee_signature = x->callee()->signature();
+        // method handle call to virtual method
+        bool has_receiver = x->callee()->is_loaded() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc);
+        ciSignatureStream callee_signature_stream(callee_signature, has_receiver ? x->callee()->holder() : NULL);
+
+        bool ignored_will_link;
+        ciSignature* signature_at_call = NULL;
+        x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call);
+        ciSignatureStream signature_at_call_stream(signature_at_call);
+
+        // if called through method handle invoke, some arguments may have been popped
+        for (int i = 0; i < stop && i+start < x->nb_profiled_args(); i++) {
+          int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset());
+          ciKlass* exact = profile_type(md, base_offset, off,
+              args->type(i), x->profiled_arg_at(i+start), mdp,
+              !x->arg_needs_null_check(i+start),
+              signature_at_call_stream.next_klass(), callee_signature_stream.next_klass());
+          if (exact != NULL) {
+            md->set_argument_type(bci, i, exact);
+          }
+        }
+      } else {
+#ifdef ASSERT
+        Bytecodes::Code code = x->method()->raw_code_at_bci(x->bci_of_invoke());
+        int n = x->nb_profiled_args();
+        assert(MethodData::profile_parameters() && (MethodData::profile_arguments_jsr292_only() ||
+            (x->inlined() && ((code == Bytecodes::_invokedynamic && n <= 1) || (code == Bytecodes::_invokehandle && n <= 2)))),
+            "only at JSR292 bytecodes");
+#endif
       }
-      ciSignature* callee_signature = x->callee()->signature();
-      // method handle call to virtual method
-      bool has_receiver = x->callee()->is_loaded() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc);
-      ciSignatureStream callee_signature_stream(callee_signature, has_receiver ? x->callee()->holder() : NULL);
-
-      bool ignored_will_link;
-      ciSignature* signature_at_call = NULL;
-      x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call);
-      ciSignatureStream signature_at_call_stream(signature_at_call);
-
-      // if called through method handle invoke, some arguments may have been popped
-      for (int i = 0; i < stop && i+start < x->nb_profiled_args(); i++) {
-        int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset());
-        ciKlass* exact = profile_type(md, base_offset, off,
-                                      args->type(i), x->profiled_arg_at(i+start), mdp,
-                                      !x->arg_needs_null_check(i+start),
-                                      signature_at_call_stream.next_klass(), callee_signature_stream.next_klass());
-        if (exact != NULL) {
-          md->set_argument_type(bci, i, exact);
-        }
-      }
-    } else {
-#ifdef ASSERT
-      Bytecodes::Code code = x->method()->raw_code_at_bci(x->bci_of_invoke());
-      int n = x->nb_profiled_args();
-      assert(MethodData::profile_parameters() && (MethodData::profile_arguments_jsr292_only() ||
-                                                  (x->inlined() && ((code == Bytecodes::_invokedynamic && n <= 1) || (code == Bytecodes::_invokehandle && n <= 2)))),
-             "only at JSR292 bytecodes");
-#endif
     }
   }
 }
@@ -3396,24 +3398,26 @@
   int bci = x->bci_of_invoke();
   ciMethodData* md = x->method()->method_data_or_null();
   ciProfileData* data = md->bci_to_data(bci);
-  assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type");
-  ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret();
-  LIR_Opr mdp = LIR_OprFact::illegalOpr;
-
-  bool ignored_will_link;
-  ciSignature* signature_at_call = NULL;
-  x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call);
-
-  // The offset within the MDO of the entry to update may be too large
-  // to be used in load/store instructions on some platforms. So have
-  // profile_type() compute the address of the profile in a register.
-  ciKlass* exact = profile_type(md, md->byte_offset_of_slot(data, ret->type_offset()), 0,
-                                ret->type(), x->ret(), mdp,
-                                !x->needs_null_check(),
-                                signature_at_call->return_type()->as_klass(),
-                                x->callee()->signature()->return_type()->as_klass());
-  if (exact != NULL) {
-    md->set_return_type(bci, exact);
+  if (data != NULL) {
+    assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type");
+    ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret();
+    LIR_Opr mdp = LIR_OprFact::illegalOpr;
+
+    bool ignored_will_link;
+    ciSignature* signature_at_call = NULL;
+    x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call);
+
+    // The offset within the MDO of the entry to update may be too large
+    // to be used in load/store instructions on some platforms. So have
+    // profile_type() compute the address of the profile in a register.
+    ciKlass* exact = profile_type(md, md->byte_offset_of_slot(data, ret->type_offset()), 0,
+        ret->type(), x->ret(), mdp,
+        !x->needs_null_check(),
+        signature_at_call->return_type()->as_klass(),
+        x->callee()->signature()->return_type()->as_klass());
+    if (exact != NULL) {
+      md->set_return_type(bci, exact);
+    }
   }
 }
 
--- a/hotspot/src/share/vm/ci/ciMethodData.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/ci/ciMethodData.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -408,11 +408,13 @@
   MethodData* mdo = get_MethodData();
   if (mdo != NULL) {
     ProfileData* data = mdo->bci_to_data(bci);
-    if (data->is_CallTypeData()) {
-      data->as_CallTypeData()->set_argument_type(i, k->get_Klass());
-    } else {
-      assert(data->is_VirtualCallTypeData(), "no arguments!");
-      data->as_VirtualCallTypeData()->set_argument_type(i, k->get_Klass());
+    if (data != NULL) {
+      if (data->is_CallTypeData()) {
+        data->as_CallTypeData()->set_argument_type(i, k->get_Klass());
+      } else {
+        assert(data->is_VirtualCallTypeData(), "no arguments!");
+        data->as_VirtualCallTypeData()->set_argument_type(i, k->get_Klass());
+      }
     }
   }
 }
@@ -430,11 +432,13 @@
   MethodData* mdo = get_MethodData();
   if (mdo != NULL) {
     ProfileData* data = mdo->bci_to_data(bci);
-    if (data->is_CallTypeData()) {
-      data->as_CallTypeData()->set_return_type(k->get_Klass());
-    } else {
-      assert(data->is_VirtualCallTypeData(), "no arguments!");
-      data->as_VirtualCallTypeData()->set_return_type(k->get_Klass());
+    if (data != NULL) {
+      if (data->is_CallTypeData()) {
+        data->as_CallTypeData()->set_return_type(k->get_Klass());
+      } else {
+        assert(data->is_VirtualCallTypeData(), "no arguments!");
+        data->as_VirtualCallTypeData()->set_return_type(k->get_Klass());
+      }
     }
   }
 }
--- a/hotspot/src/share/vm/classfile/classFileParser.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/classfile/classFileParser.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -105,6 +105,12 @@
 
 #define JAVA_9_VERSION                    53
 
+void ClassFileParser::set_class_bad_constant_seen(short bad_constant) {
+  assert((bad_constant == 19 || bad_constant == 20) && _major_version >= JAVA_9_VERSION,
+         "Unexpected bad constant pool entry");
+  if (_bad_constant_seen == 0) _bad_constant_seen = bad_constant;
+}
+
 void ClassFileParser::parse_constant_pool_entries(const ClassFileStream* const stream,
                                                   ConstantPool* cp,
                                                   const int length,
@@ -302,6 +308,18 @@
         }
         break;
       }
+      case 19:
+      case 20: {
+        // Record that an error occurred in these two cases but keep parsing so
+        // that ACC_Module can be checked for in the access_flags.  Need to
+        // throw NoClassDefFoundError in that case.
+        if (_major_version >= JAVA_9_VERSION) {
+          cfs->guarantee_more(3, CHECK);
+          cfs->get_u2_fast();
+          set_class_bad_constant_seen(tag);
+          break;
+        }
+      }
       default: {
         classfile_parse_error("Unknown constant tag %u in class file %s",
                               tag,
@@ -359,14 +377,18 @@
 #endif
 
 void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
-                                          ConstantPool* const cp,
-                                          const int length,
-                                          TRAPS) {
+                                         ConstantPool* const cp,
+                                         const int length,
+                                         TRAPS) {
   assert(cp != NULL, "invariant");
   assert(stream != NULL, "invariant");
 
   // parsing constant pool entries
   parse_constant_pool_entries(stream, cp, length, CHECK);
+  if (class_bad_constant_seen() != 0) {
+    // a bad CP entry has been detected previously so stop parsing and just return.
+    return;
+  }
 
   int index = 1;  // declared outside of loops for portability
 
@@ -1244,6 +1266,10 @@
       }
     } else if (_major_version >= JAVA_1_5_VERSION) {
       if (attribute_name == vmSymbols::tag_signature()) {
+        if (generic_signature_index != 0) {
+          classfile_parse_error(
+            "Multiple Signature attributes for field in class file %s", CHECK);
+        }
         if (attribute_length != 2) {
           classfile_parse_error(
             "Wrong size %u for field's Signature attribute in class file %s",
@@ -2565,6 +2591,11 @@
       }
     } else if (_major_version >= JAVA_1_5_VERSION) {
       if (method_attribute_name == vmSymbols::tag_signature()) {
+        if (generic_signature_index != 0) {
+          classfile_parse_error(
+            "Multiple Signature attributes for method in class file %s",
+            CHECK_NULL);
+        }
         if (method_attribute_length != 2) {
           classfile_parse_error(
             "Invalid Signature attribute length %u in class file %s",
@@ -3284,6 +3315,10 @@
       }
     } else if (_major_version >= JAVA_1_5_VERSION) {
       if (tag == vmSymbols::tag_signature()) {
+        if (_generic_signature_index != 0) {
+          classfile_parse_error(
+            "Multiple Signature attributes in class file %s", CHECK);
+        }
         if (attribute_length != 2) {
           classfile_parse_error(
             "Wrong Signature attribute length %u in class file %s",
@@ -5558,6 +5593,7 @@
   _protection_domain(protection_domain),
   _access_flags(),
   _pub_level(pub_level),
+  _bad_constant_seen(0),
   _synthetic_flag(false),
   _sde_length(false),
   _sde_buffer(NULL),
@@ -5765,9 +5801,15 @@
 
   verify_legal_class_modifiers(flags, CHECK);
 
+  short bad_constant = class_bad_constant_seen();
+  if (bad_constant != 0) {
+    // Do not throw CFE until after the access_flags are checked because if
+    // ACC_MODULE is set in the access flags, then NCDFE must be thrown, not CFE.
+    classfile_parse_error("Unknown constant tag %u in class file %s", bad_constant, CHECK);
+  }
+
   _access_flags.set_flags(flags);
 
-
   // This class and superclass
   _this_class_index = stream->get_u2_fast();
   check_property(
--- a/hotspot/src/share/vm/classfile/classFileParser.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/classfile/classFileParser.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -122,6 +122,15 @@
   // for tracing and notifications
   Publicity _pub_level;
 
+  // Used to keep track of whether a constant pool item 19 or 20 is found.  These
+  // correspond to CONSTANT_Module and CONSTANT_Package tags and are not allowed
+  // in regular class files.  For class file version >= 53, a CFE cannot be thrown
+  // immediately when these are seen because a NCDFE must be thrown if the class's
+  // access_flags have ACC_MODULE set.  But, the access_flags haven't been looked
+  // at yet.  So, the bad constant pool item is cached here.  A value of zero
+  // means that no constant pool item 19 or 20 was found.
+  short _bad_constant_seen;
+
   // class attributes parsed before the instance klass is created:
   bool _synthetic_flag;
   int _sde_length;
@@ -161,6 +170,8 @@
   void fill_instance_klass(InstanceKlass* ik, bool cf_changed_in_CFLH, TRAPS);
   void set_klass(InstanceKlass* instance);
 
+  void set_class_bad_constant_seen(short bad_constant);
+  short class_bad_constant_seen() { return  _bad_constant_seen; }
   void set_class_synthetic_flag(bool x)        { _synthetic_flag = x; }
   void set_class_sourcefile_index(u2 x)        { _sourcefile_index = x; }
   void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; }
--- a/hotspot/src/share/vm/classfile/moduleEntry.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/classfile/moduleEntry.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,8 +36,8 @@
 #include "utilities/ostream.hpp"
 
 #define UNNAMED_MODULE "Unnamed Module"
-#define JAVAPKG "java/"
-#define JAVAPKG_LEN 5
+#define JAVAPKG "java"
+#define JAVAPKG_LEN 4
 #define JAVA_BASE_NAME "java.base"
 
 class ModuleClosure;
--- a/hotspot/src/share/vm/classfile/modules.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/classfile/modules.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -325,7 +325,8 @@
     // Only modules defined to either the boot or platform class loader, can define a "java/" package.
     if (!h_loader.is_null() &&
         !SystemDictionary::is_platform_class_loader(h_loader) &&
-        strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0) {
+        (strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0 &&
+          (package_name[JAVAPKG_LEN] == '/' || package_name[JAVAPKG_LEN] == '\0'))) {
       const char* class_loader_name = SystemDictionary::loader_name(h_loader());
       size_t pkg_len = strlen(package_name);
       char* pkg_name = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, pkg_len);
@@ -748,7 +749,8 @@
   // Only modules defined to either the boot or platform class loader, can define a "java/" package.
   if (!loader_data->is_the_null_class_loader_data() &&
       !loader_data->is_platform_class_loader_data() &&
-      strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0) {
+      (strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0 &&
+        (package_name[JAVAPKG_LEN] == '/' || package_name[JAVAPKG_LEN] == '\0'))) {
     const char* class_loader_name = SystemDictionary::loader_name(loader_data);
     size_t pkg_len = strlen(package_name);
     char* pkg_name = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, pkg_len);
--- a/hotspot/src/share/vm/classfile/stringTable.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/classfile/stringTable.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -96,10 +96,14 @@
 
 // Pick hashing algorithm
 unsigned int StringTable::hash_string(const jchar* s, int len) {
-  return use_alternate_hashcode() ? AltHashing::murmur3_32(seed(), s, len) :
+  return use_alternate_hashcode() ? alt_hash_string(s, len) :
                                     java_lang_String::hash_code(s, len);
 }
 
+unsigned int StringTable::alt_hash_string(const jchar* s, int len) {
+  return AltHashing::murmur3_32(seed(), s, len);
+}
+
 unsigned int StringTable::hash_string(oop string) {
   EXCEPTION_MARK;
   if (string == NULL) {
@@ -117,11 +121,10 @@
   }
 }
 
-oop StringTable::lookup_shared(jchar* name, int len) {
-  // java_lang_String::hash_code() was used to compute hash values in the shared table. Don't
-  // use the hash value from StringTable::hash_string() as it might use alternate hashcode.
-  return _shared_table.lookup((const char*)name,
-                              java_lang_String::hash_code(name, len), len);
+oop StringTable::lookup_shared(jchar* name, int len, unsigned int hash) {
+  assert(hash == java_lang_String::hash_code(name, len),
+         "hash must be computed using java_lang_String::hash_code");
+  return _shared_table.lookup((const char*)name, hash, len);
 }
 
 oop StringTable::lookup_in_main_table(int index, jchar* name,
@@ -156,7 +159,7 @@
   unsigned int hashValue;
   int index;
   if (use_alternate_hashcode()) {
-    hashValue = hash_string(name, len);
+    hashValue = alt_hash_string(name, len);
     index = hash_to_index(hashValue);
   } else {
     hashValue = hashValue_arg;
@@ -199,12 +202,15 @@
 }
 
 oop StringTable::lookup(jchar* name, int len) {
-  oop string = lookup_shared(name, len);
+  // shared table always uses java_lang_String::hash_code
+  unsigned int hash = java_lang_String::hash_code(name, len);
+  oop string = lookup_shared(name, len, hash);
   if (string != NULL) {
     return string;
   }
-
-  unsigned int hash = hash_string(name, len);
+  if (use_alternate_hashcode()) {
+    hash = alt_hash_string(name, len);
+  }
   int index = the_table()->hash_to_index(hash);
   string = the_table()->lookup_in_main_table(index, name, len, hash);
 
@@ -215,12 +221,15 @@
 
 oop StringTable::intern(Handle string_or_null, jchar* name,
                         int len, TRAPS) {
-  oop found_string = lookup_shared(name, len);
+  // shared table always uses java_lang_String::hash_code
+  unsigned int hashValue = java_lang_String::hash_code(name, len);
+  oop found_string = lookup_shared(name, len, hashValue);
   if (found_string != NULL) {
     return found_string;
   }
-
-  unsigned int hashValue = hash_string(name, len);
+  if (use_alternate_hashcode()) {
+    hashValue = alt_hash_string(name, len);
+  }
   int index = the_table()->hash_to_index(hashValue);
   found_string = the_table()->lookup_in_main_table(index, name, len, hashValue);
 
--- a/hotspot/src/share/vm/classfile/stringTable.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/classfile/stringTable.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -56,7 +56,7 @@
                 unsigned int hashValue, TRAPS);
 
   oop lookup_in_main_table(int index, jchar* chars, int length, unsigned int hashValue);
-  static oop lookup_shared(jchar* name, int len);
+  static oop lookup_shared(jchar* name, int len, unsigned int hash);
 
   // Apply the give oop closure to the entries to the buckets
   // in the range [start_idx, end_idx).
@@ -65,6 +65,13 @@
   // in the range [start_idx, end_idx).
   static void buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, int* processed, int* removed);
 
+  // Hashing algorithm, used as the hash value used by the
+  //     StringTable for bucket selection and comparison (stored in the
+  //     HashtableEntry structures).  This is used in the String.intern() method.
+  static unsigned int hash_string(const jchar* s, int len);
+  static unsigned int hash_string(oop string);
+  static unsigned int alt_hash_string(const jchar* s, int len);
+
   StringTable() : RehashableHashtable<oop, mtSymbol>((int)StringTableSize,
                               sizeof (HashtableEntry<oop, mtSymbol>)) {}
 
@@ -109,12 +116,6 @@
   }
   static void possibly_parallel_oops_do(OopClosure* f);
 
-  // Hashing algorithm, used as the hash value used by the
-  //     StringTable for bucket selection and comparison (stored in the
-  //     HashtableEntry structures).  This is used in the String.intern() method.
-  static unsigned int hash_string(const jchar* s, int len);
-  static unsigned int hash_string(oop string);
-
   // Internal test.
   static void test_alt_hash() PRODUCT_RETURN;
 
--- a/hotspot/src/share/vm/classfile/vmSymbols.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/classfile/vmSymbols.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -561,6 +561,7 @@
   template(int_StringBuffer_signature,                "(I)Ljava/lang/StringBuffer;")                              \
   template(char_StringBuffer_signature,               "(C)Ljava/lang/StringBuffer;")                              \
   template(int_String_signature,                      "(I)Ljava/lang/String;")                                    \
+  template(boolean_boolean_int_signature,             "(ZZ)I")                                                    \
   template(codesource_permissioncollection_signature, "(Ljava/security/CodeSource;Ljava/security/PermissionCollection;)V") \
   /* signature symbols needed by intrinsics */                                                                    \
   VM_INTRINSICS_DO(VM_INTRINSIC_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, template, VM_ALIAS_IGNORE)            \
--- a/hotspot/src/share/vm/compiler/compilerDefinitions.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/compiler/compilerDefinitions.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -100,7 +100,9 @@
     FLAG_SET_ERGO(size_t, MetaspaceSize, 12*M);
   }
   if (FLAG_IS_DEFAULT(MaxRAM)) {
-    FLAG_SET_ERGO(uint64_t, MaxRAM, 1ULL*G);
+    // Do not use FLAG_SET_ERGO to update MaxRAM, as this will impact
+    // heap setting done based on available phys_mem (see Arguments::set_heap_size).
+    FLAG_SET_DEFAULT(MaxRAM, 1ULL*G);
   }
   if (FLAG_IS_DEFAULT(CompileThreshold)) {
     FLAG_SET_ERGO(intx, CompileThreshold, 1500);
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -2456,22 +2456,24 @@
 void InstanceKlass::check_prohibited_package(Symbol* class_name,
                                              Handle class_loader,
                                              TRAPS) {
-  ResourceMark rm(THREAD);
   if (!class_loader.is_null() &&
       !SystemDictionary::is_platform_class_loader(class_loader) &&
-      class_name != NULL &&
-      strncmp(class_name->as_C_string(), JAVAPKG, JAVAPKG_LEN) == 0) {
-    TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK);
-    assert(pkg_name != NULL, "Error in parsing package name starting with 'java/'");
-    char* name = pkg_name->as_C_string();
-    const char* class_loader_name = SystemDictionary::loader_name(class_loader());
-    StringUtils::replace_no_expand(name, "/", ".");
-    const char* msg_text1 = "Class loader (instance of): ";
-    const char* msg_text2 = " tried to load prohibited package name: ";
-    size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + strlen(name) + 1;
-    char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len);
-    jio_snprintf(message, len, "%s%s%s%s", msg_text1, class_loader_name, msg_text2, name);
-    THROW_MSG(vmSymbols::java_lang_SecurityException(), message);
+      class_name != NULL) {
+    ResourceMark rm(THREAD);
+    char* name = class_name->as_C_string();
+    if (strncmp(name, JAVAPKG, JAVAPKG_LEN) == 0 && name[JAVAPKG_LEN] == '/') {
+      TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK);
+      assert(pkg_name != NULL, "Error in parsing package name starting with 'java/'");
+      name = pkg_name->as_C_string();
+      const char* class_loader_name = SystemDictionary::loader_name(class_loader());
+      StringUtils::replace_no_expand(name, "/", ".");
+      const char* msg_text1 = "Class loader (instance of): ";
+      const char* msg_text2 = " tried to load prohibited package name: ";
+      size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + strlen(name) + 1;
+      char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len);
+      jio_snprintf(message, len, "%s%s%s%s", msg_text1, class_loader_name, msg_text2, name);
+      THROW_MSG(vmSymbols::java_lang_SecurityException(), message);
+    }
   }
   return;
 }
--- a/hotspot/src/share/vm/opto/arraycopynode.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/opto/arraycopynode.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -225,7 +225,6 @@
   Node* dest = in(ArrayCopyNode::Dest);
   const Type* src_type = phase->type(src);
   const TypeAryPtr* ary_src = src_type->isa_aryptr();
-  assert(ary_src != NULL, "should be an array copy/clone");
 
   if (is_arraycopy() || is_copyofrange() || is_copyof()) {
     const Type* dest_type = phase->type(dest);
@@ -286,7 +285,8 @@
 
     copy_type = dest_elem;
   } else {
-    assert (is_clonebasic(), "should be");
+    assert(ary_src != NULL, "should be a clone");
+    assert(is_clonebasic(), "should be");
 
     disjoint_bases = true;
     assert(src->is_AddP(), "should be base + off");
--- a/hotspot/src/share/vm/opto/callnode.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/opto/callnode.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -784,8 +784,8 @@
       }
       // May modify (by reflection) if an boxing object is passed
       // as argument or returned.
-      if (returns_pointer() && (proj_out(TypeFunc::Parms) != NULL)) {
-        Node* proj = proj_out(TypeFunc::Parms);
+      Node* proj = returns_pointer() ? proj_out(TypeFunc::Parms) : NULL;
+      if (proj != NULL) {
         const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
         if ((inst_t != NULL) && (!inst_t->klass_is_exact() ||
                                  (inst_t->klass() == boxing_klass))) {
--- a/hotspot/src/share/vm/opto/castnode.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/opto/castnode.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -225,7 +225,10 @@
   }
 
   // Similar to ConvI2LNode::Ideal() for the same reasons
-  if (can_reshape && !phase->C->major_progress()) {
+  // Do not narrow the type of range check dependent CastIINodes to
+  // avoid corruption of the graph if a CastII is replaced by TOP but
+  // the corresponding range check is not removed.
+  if (can_reshape && !_range_check_dependency && !phase->C->major_progress()) {
     const TypeInt* this_type = this->type()->is_int();
     const TypeInt* in_type = phase->type(in(1))->isa_int();
     if (in_type != NULL && this_type != NULL &&
--- a/hotspot/src/share/vm/opto/convertnode.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/opto/convertnode.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -294,8 +294,7 @@
   }
 
 #ifdef _LP64
-  // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) or
-  // ConvI2L(CastII(AddI(x, y))) to AddL(ConvI2L(CastII(x)), ConvI2L(CastII(y))),
+  // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y))
   // but only if x and y have subranges that cannot cause 32-bit overflow,
   // under the assumption that x+y is in my own subrange this->type().
 
@@ -319,13 +318,6 @@
 
   Node* z = in(1);
   int op = z->Opcode();
-  Node* ctrl = NULL;
-  if (op == Op_CastII && z->as_CastII()->has_range_check()) {
-    // Skip CastII node but save control dependency
-    ctrl = z->in(0);
-    z = z->in(1);
-    op = z->Opcode();
-  }
   if (op == Op_AddI || op == Op_SubI) {
     Node* x = z->in(1);
     Node* y = z->in(2);
@@ -385,8 +377,8 @@
     }
     assert(rxlo == (int)rxlo && rxhi == (int)rxhi, "x should not overflow");
     assert(rylo == (int)rylo && ryhi == (int)ryhi, "y should not overflow");
-    Node* cx = phase->C->constrained_convI2L(phase, x, TypeInt::make(rxlo, rxhi, widen), ctrl);
-    Node* cy = phase->C->constrained_convI2L(phase, y, TypeInt::make(rylo, ryhi, widen), ctrl);
+    Node* cx = phase->C->constrained_convI2L(phase, x, TypeInt::make(rxlo, rxhi, widen), NULL);
+    Node* cy = phase->C->constrained_convI2L(phase, y, TypeInt::make(rylo, ryhi, widen), NULL);
     switch (op) {
       case Op_AddI:  return new AddLNode(cx, cy);
       case Op_SubI:  return new SubLNode(cx, cy);
--- a/hotspot/src/share/vm/opto/ifnode.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/opto/ifnode.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -249,6 +249,13 @@
       predicate_proj = proj;
     }
   }
+
+  // If all the defs of the phi are the same constant, we already have the desired end state.
+  // Skip the split that would create empty phi and region nodes.
+  if((r->req() - req_c) == 1) {
+    return NULL;
+  }
+
   if (nb_predicate_proj > 1) {
     // Can happen in case of loop unswitching and when the loop is
     // optimized out: it's not a loop anymore so we don't care about
@@ -1458,8 +1465,9 @@
   // be skipped. For example, range check predicate has two checks
   // for lower and upper bounds.
   ProjNode* unc_proj = proj_out(1 - prev_dom->as_Proj()->_con)->as_Proj();
-  if (unc_proj->is_uncommon_trap_proj(Deoptimization::Reason_predicate) != NULL)
-   prev_dom = idom;
+  if ((unc_proj != NULL) && (unc_proj->is_uncommon_trap_proj(Deoptimization::Reason_predicate) != NULL)) {
+    prev_dom = idom;
+  }
 
   // Now walk the current IfNode's projections.
   // Loop ends when 'this' has no more uses.
--- a/hotspot/src/share/vm/opto/lcm.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/opto/lcm.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -254,10 +254,12 @@
       const TypePtr *adr_type = NULL;  // Do not need this return value here
       const Node* base = mach->get_base_and_disp(offset, adr_type);
       if (base == NULL || base == NodeSentinel) {
-        // Narrow oop address doesn't have base, only index
-        if( val->bottom_type()->isa_narrowoop() &&
-            MacroAssembler::needs_explicit_null_check(offset) )
-          continue;             // Give up if offset is beyond page size
+        // Narrow oop address doesn't have base, only index.
+        // Give up if offset is beyond page size or if heap base is not protected.
+        if (val->bottom_type()->isa_narrowoop() &&
+            (MacroAssembler::needs_explicit_null_check(offset) ||
+             !Universe::narrow_oop_use_implicit_null_checks()))
+          continue;
         // cannot reason about it; is probably not implicit null exception
       } else {
         const TypePtr* tptr;
@@ -269,12 +271,17 @@
           // only regular oops are expected here
           tptr = base->bottom_type()->is_ptr();
         }
-        // Give up if offset is not a compile-time constant
-        if( offset == Type::OffsetBot || tptr->_offset == Type::OffsetBot )
+        // Give up if offset is not a compile-time constant.
+        if (offset == Type::OffsetBot || tptr->_offset == Type::OffsetBot)
           continue;
         offset += tptr->_offset; // correct if base is offseted
-        if( MacroAssembler::needs_explicit_null_check(offset) )
-          continue;             // Give up is reference is beyond 4K page size
+        // Give up if reference is beyond page size.
+        if (MacroAssembler::needs_explicit_null_check(offset))
+          continue;
+        // Give up if base is a decode node and the heap base is not protected.
+        if (base->is_Mach() && base->as_Mach()->ideal_Opcode() == Op_DecodeN &&
+            !Universe::narrow_oop_use_implicit_null_checks())
+          continue;
       }
     }
 
--- a/hotspot/src/share/vm/opto/library_call.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/opto/library_call.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -2372,10 +2372,10 @@
   // the barriers get omitted and the unsafe reference begins to "pollute"
   // the alias analysis of the rest of the graph, either Compile::can_alias
   // or Compile::must_alias will throw a diagnostic assert.)
-  bool need_mem_bar;
+  bool need_mem_bar = false;
   switch (kind) {
       case Relaxed:
-          need_mem_bar = mismatched || can_access_non_heap;
+          need_mem_bar = mismatched && !adr_type->isa_aryptr();
           break;
       case Opaque:
           // Opaque uses CPUOrder membars for protection against code movement.
--- a/hotspot/src/share/vm/opto/loopTransform.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/opto/loopTransform.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -3174,6 +3174,11 @@
     return false;
   }
 
+  Node* exit = head->loopexit()->proj_out(0);
+  if (exit == NULL) {
+    return false;
+  }
+
 #ifndef PRODUCT
   if (TraceLoopOpts) {
     tty->print("ArrayFill    ");
@@ -3281,7 +3286,6 @@
 */
 
   // Redirect the old control and memory edges that are outside the loop.
-  Node* exit = head->loopexit()->proj_out(0);
   // Sometimes the memory phi of the head is used as the outgoing
   // state of the loop.  It's safe in this case to replace it with the
   // result_mem.
--- a/hotspot/src/share/vm/opto/parse2.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/opto/parse2.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -826,6 +826,9 @@
     ciMethodData* methodData = method()->method_data();
     if (!methodData->is_mature())  return PROB_UNKNOWN;
     ciProfileData* data = methodData->bci_to_data(bci());
+    if (data == NULL) {
+      return PROB_UNKNOWN;
+    }
     if (!data->is_JumpData())  return PROB_UNKNOWN;
 
     // get taken and not taken values
@@ -917,8 +920,8 @@
         // of the OSR-ed method, and we want to deopt to gather more stats.
         // If you have ANY counts, then this loop is simply 'cold' relative
         // to the OSR loop.
-        if (data->as_BranchData()->taken() +
-            data->as_BranchData()->not_taken() == 0 ) {
+        if (data == NULL ||
+            (data->as_BranchData()->taken() +  data->as_BranchData()->not_taken() == 0)) {
           // This is the only way to return PROB_UNKNOWN:
           return PROB_UNKNOWN;
         }
--- a/hotspot/src/share/vm/opto/stringopts.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/opto/stringopts.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -891,8 +891,9 @@
       ctrl_path.push(cn);
       ctrl_path.push(cn->proj_out(0));
       ctrl_path.push(cn->proj_out(0)->unique_out());
-      if (cn->proj_out(0)->unique_out()->as_Catch()->proj_out(0) != NULL) {
-        ctrl_path.push(cn->proj_out(0)->unique_out()->as_Catch()->proj_out(0));
+      Node* catchproj = cn->proj_out(0)->unique_out()->as_Catch()->proj_out(0);
+      if (catchproj != NULL) {
+        ctrl_path.push(catchproj);
       }
     } else {
       ShouldNotReachHere();
--- a/hotspot/src/share/vm/prims/jni.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/prims/jni.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2012 Red Hat, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -935,8 +935,7 @@
   inline void get_long()   { _arguments->push_long(va_arg(_ap, jlong)); }
   inline void get_float()  { _arguments->push_float((jfloat)va_arg(_ap, jdouble)); } // float is coerced to double w/ va_arg
   inline void get_double() { _arguments->push_double(va_arg(_ap, jdouble)); }
-  inline void get_object() { jobject l = va_arg(_ap, jobject);
-                             _arguments->push_oop(Handle((oop *)l, false)); }
+  inline void get_object() { _arguments->push_jobject(va_arg(_ap, jobject)); }
 
   inline void set_ap(va_list rap) {
     va_copy(_ap, rap);
@@ -1025,7 +1024,7 @@
   inline void get_long()   { _arguments->push_long((_ap++)->j);  }
   inline void get_float()  { _arguments->push_float((_ap++)->f); }
   inline void get_double() { _arguments->push_double((_ap++)->d);}
-  inline void get_object() { _arguments->push_oop(Handle((oop *)(_ap++)->l, false)); }
+  inline void get_object() { _arguments->push_jobject((_ap++)->l); }
 
   inline void set_ap(const jvalue *rap) { _ap = rap; }
 
--- a/hotspot/src/share/vm/prims/jvmtiEnv.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/prims/jvmtiEnv.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1796,6 +1796,13 @@
     }
   }
 
+  if (initial_object != NULL) {
+    oop init_obj = JNIHandles::resolve_external_guard(initial_object);
+    if (init_obj == NULL) {
+      return JVMTI_ERROR_INVALID_OBJECT;
+    }
+  }
+
   Thread *thread = Thread::current();
   HandleMark hm(thread);
   KlassHandle kh (thread, k_oop);
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -2856,6 +2856,10 @@
       if (res != JNI_OK) {
         return res;
       }
+    } else if (match_option(option, "--permit-illegal-access")) {
+      if (!create_property("jdk.module.permitIllegalAccess", "true", ExternalProperty)) {
+        return JNI_ENOMEM;
+      }
     // -agentlib and -agentpath
     } else if (match_option(option, "-agentlib:", &tail) ||
           (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
@@ -3098,6 +3102,7 @@
     // -Xprof
     } else if (match_option(option, "-Xprof")) {
 #if INCLUDE_FPROF
+      log_warning(arguments)("Option -Xprof was deprecated in version 9 and will likely be removed in a future release.");
       _has_profile = true;
 #else // INCLUDE_FPROF
       jio_fprintf(defaultStream::error_stream(),
--- a/hotspot/src/share/vm/runtime/java.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/runtime/java.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -621,6 +621,13 @@
   }
 }
 
+void vm_exit_during_initialization() {
+  vm_notify_during_shutdown(NULL, NULL);
+
+  // Failure during initialization, we don't want to dump core
+  vm_abort(false);
+}
+
 void vm_exit_during_initialization(Handle exception) {
   tty->print_cr("Error occurred during initialization of VM");
   // If there are exceptions on this thread it must be cleared
--- a/hotspot/src/share/vm/runtime/java.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/runtime/java.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * 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,7 @@
 extern void notify_vm_shutdown();
 
 // VM exit if error occurs during initialization of VM
+extern void vm_exit_during_initialization();
 extern void vm_exit_during_initialization(Handle exception);
 extern void vm_exit_during_initialization(Symbol* exception_name, const char* message);
 extern void vm_exit_during_initialization(const char* error, const char* message = NULL);
--- a/hotspot/src/share/vm/runtime/javaCalls.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/runtime/javaCalls.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -328,9 +328,9 @@
 // Verify the arguments
 
   if (CheckJNICalls)  {
-    args->verify(method, result->get_type(), thread);
+    args->verify(method, result->get_type());
   }
-  else debug_only(args->verify(method, result->get_type(), thread));
+  else debug_only(args->verify(method, result->get_type()));
 #if INCLUDE_JVMCI
   }
 #else
@@ -442,12 +442,43 @@
 //--------------------------------------------------------------------------------------
 // Implementation of JavaCallArguments
 
+inline bool is_value_state_indirect_oop(uint state) {
+  assert(state != JavaCallArguments::value_state_oop,
+         "Checking for handles after removal");
+  assert(state < JavaCallArguments::value_state_limit,
+         "Invalid value state %u", state);
+  return state != JavaCallArguments::value_state_primitive;
+}
+
+inline oop resolve_indirect_oop(intptr_t value, uint state) {
+  switch (state) {
+  case JavaCallArguments::value_state_handle:
+  {
+    oop* ptr = reinterpret_cast<oop*>(value);
+    return Handle::raw_resolve(ptr);
+  }
+
+  case JavaCallArguments::value_state_jobject:
+  {
+    jobject obj = reinterpret_cast<jobject>(value);
+    return JNIHandles::resolve(obj);
+  }
+
+  default:
+    ShouldNotReachHere();
+    return NULL;
+  }
+}
+
 intptr_t* JavaCallArguments::parameters() {
   // First convert all handles to oops
   for(int i = 0; i < _size; i++) {
-    if (_is_oop[i]) {
-      // Handle conversion
-      _value[i] = cast_from_oop<intptr_t>(Handle::raw_resolve((oop *)_value[i]));
+    uint state = _value_state[i];
+    assert(state != value_state_oop, "Multiple handle conversions");
+    if (is_value_state_indirect_oop(state)) {
+      oop obj = resolve_indirect_oop(_value[i], state);
+      _value[i] = cast_from_oop<intptr_t>(obj);
+      _value_state[i] = value_state_oop;
     }
   }
   // Return argument vector
@@ -457,30 +488,42 @@
 
 class SignatureChekker : public SignatureIterator {
  private:
-   bool *_is_oop;
-   int   _pos;
+   int _pos;
    BasicType _return_type;
-   intptr_t*   _value;
-   Thread* _thread;
+   u_char* _value_state;
+   intptr_t* _value;
 
  public:
   bool _is_return;
 
-  SignatureChekker(Symbol* signature, BasicType return_type, bool is_static, bool* is_oop, intptr_t* value, Thread* thread) : SignatureIterator(signature) {
-    _is_oop = is_oop;
-    _is_return = false;
-    _return_type = return_type;
-    _pos = 0;
-    _value = value;
-    _thread = thread;
-
+  SignatureChekker(Symbol* signature,
+                   BasicType return_type,
+                   bool is_static,
+                   u_char* value_state,
+                   intptr_t* value) :
+    SignatureIterator(signature),
+    _pos(0),
+    _return_type(return_type),
+    _value_state(value_state),
+    _value(value),
+    _is_return(false)
+  {
     if (!is_static) {
       check_value(true); // Receiver must be an oop
     }
   }
 
   void check_value(bool type) {
-    guarantee(_is_oop[_pos++] == type, "signature does not match pushed arguments");
+    uint state = _value_state[_pos++];
+    if (type) {
+      guarantee(is_value_state_indirect_oop(state),
+                "signature does not match pushed arguments: %u at %d",
+                state, _pos - 1);
+    } else {
+      guarantee(state == JavaCallArguments::value_state_primitive,
+                "signature does not match pushed arguments: %u at %d",
+                state, _pos - 1);
+    }
   }
 
   void check_doing_return(bool state) { _is_return = state; }
@@ -515,24 +558,20 @@
       return;
     }
 
-    // verify handle and the oop pointed to by handle
-    int p = _pos;
-    bool bad = false;
-    // If argument is oop
-    if (_is_oop[p]) {
-      intptr_t v = _value[p];
-      if (v != 0 ) {
-        size_t t = (size_t)v;
-        bad = (t < (size_t)os::vm_page_size() ) || !Handle::raw_resolve((oop *)v)->is_oop_or_null(true);
-        if (CheckJNICalls && bad) {
-          ReportJNIFatalError((JavaThread*)_thread, "Bad JNI oop argument");
-        }
-      }
-      // for the regular debug case.
-      assert(!bad, "Bad JNI oop argument");
+    intptr_t v = _value[_pos];
+    if (v != 0) {
+      // v is a "handle" referring to an oop, cast to integral type.
+      // There shouldn't be any handles in very low memory.
+      guarantee((size_t)v >= (size_t)os::vm_page_size(),
+                "Bad JNI oop argument %d: " PTR_FORMAT, _pos, v);
+      // Verify the pointee.
+      oop vv = resolve_indirect_oop(v, _value_state[_pos]);
+      guarantee(vv->is_oop_or_null(true),
+                "Bad JNI oop argument %d: " PTR_FORMAT " -> " PTR_FORMAT,
+                _pos, v, p2i(vv));
     }
 
-    check_value(true);
+    check_value(true);          // Verify value state.
   }
 
   void do_bool()                       { check_int(T_BOOLEAN);       }
@@ -549,8 +588,7 @@
 };
 
 
-void JavaCallArguments::verify(const methodHandle& method, BasicType return_type,
-  Thread *thread) {
+void JavaCallArguments::verify(const methodHandle& method, BasicType return_type) {
   guarantee(method->size_of_parameters() == size_of_parameters(), "wrong no. of arguments pushed");
 
   // Treat T_OBJECT and T_ARRAY as the same
@@ -559,7 +597,11 @@
   // Check that oop information is correct
   Symbol* signature = method->signature();
 
-  SignatureChekker sc(signature, return_type, method->is_static(),_is_oop, _value, thread);
+  SignatureChekker sc(signature,
+                      return_type,
+                      method->is_static(),
+                      _value_state,
+                      _value);
   sc.iterate_parameters();
   sc.check_doing_return(true);
   sc.iterate_returntype();
--- a/hotspot/src/share/vm/runtime/javaCalls.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/runtime/javaCalls.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -80,11 +80,11 @@
    _default_size = 8    // Must be at least # of arguments in JavaCalls methods
   };
 
-  intptr_t    _value_buffer [_default_size + 1];
-  bool        _is_oop_buffer[_default_size + 1];
+  intptr_t    _value_buffer      [_default_size + 1];
+  u_char      _value_state_buffer[_default_size + 1];
 
   intptr_t*   _value;
-  bool*       _is_oop;
+  u_char*     _value_state;
   int         _size;
   int         _max_size;
   bool        _start_at_zero;      // Support late setting of receiver
@@ -92,8 +92,8 @@
 
   void initialize() {
     // Starts at first element to support set_receiver.
-    _value    = &_value_buffer[1];
-    _is_oop   = &_is_oop_buffer[1];
+    _value       = &_value_buffer[1];
+    _value_state = &_value_state_buffer[1];
 
     _max_size = _default_size;
     _size = 0;
@@ -101,6 +101,23 @@
     JVMCI_ONLY(_alternative_target = NULL;)
   }
 
+  // Helper for push_oop and the like.  The value argument is a
+  // "handle" that refers to an oop.  We record the address of the
+  // handle rather than the designated oop.  The handle is later
+  // resolved to the oop by parameters().  This delays the exposure of
+  // naked oops until it is GC-safe.
+  template<typename T>
+  inline int push_oop_impl(T handle, int size) {
+    // JNITypes::put_obj expects an oop value, so we play fast and
+    // loose with the type system.  The cast from handle type to oop
+    // *must* use a C-style cast.  In a product build it performs a
+    // reinterpret_cast. In a debug build (more accurately, in a
+    // CHECK_UNHANDLED_OOPS build) it performs a static_cast, invoking
+    // the debug-only oop class's conversion from void* constructor.
+    JNITypes::put_obj((oop)handle, _value, size); // Updates size.
+    return size;                // Return the updated size.
+  }
+
  public:
   JavaCallArguments() { initialize(); }
 
@@ -111,11 +128,12 @@
 
   JavaCallArguments(int max_size) {
     if (max_size > _default_size) {
-      _value  = NEW_RESOURCE_ARRAY(intptr_t, max_size + 1);
-      _is_oop = NEW_RESOURCE_ARRAY(bool, max_size + 1);
+      _value = NEW_RESOURCE_ARRAY(intptr_t, max_size + 1);
+      _value_state = NEW_RESOURCE_ARRAY(u_char, max_size + 1);
 
-      // Reserve room for potential receiver in value and is_oop
-      _value++; _is_oop++;
+      // Reserve room for potential receiver in value and state
+      _value++;
+      _value_state++;
 
       _max_size = max_size;
       _size = 0;
@@ -136,25 +154,52 @@
   }
 #endif
 
-  inline void push_oop(Handle h)    { _is_oop[_size] = true;
-                               JNITypes::put_obj((oop)h.raw_value(), _value, _size); }
+  // The possible values for _value_state elements.
+  enum {
+    value_state_primitive,
+    value_state_oop,
+    value_state_handle,
+    value_state_jobject,
+    value_state_limit
+  };
 
-  inline void push_int(int i)       { _is_oop[_size] = false;
-                               JNITypes::put_int(i, _value, _size); }
+  inline void push_oop(Handle h) {
+    _value_state[_size] = value_state_handle;
+    _size = push_oop_impl(h.raw_value(), _size);
+  }
+
+  inline void push_jobject(jobject h) {
+    _value_state[_size] = value_state_jobject;
+    _size = push_oop_impl(h, _size);
+  }
 
-  inline void push_double(double d) { _is_oop[_size] = false; _is_oop[_size + 1] = false;
-                               JNITypes::put_double(d, _value, _size); }
+  inline void push_int(int i) {
+    _value_state[_size] = value_state_primitive;
+    JNITypes::put_int(i, _value, _size);
+  }
+
+  inline void push_double(double d) {
+    _value_state[_size] = value_state_primitive;
+    _value_state[_size + 1] = value_state_primitive;
+    JNITypes::put_double(d, _value, _size);
+  }
 
-  inline void push_long(jlong l)    { _is_oop[_size] = false; _is_oop[_size + 1] = false;
-                               JNITypes::put_long(l, _value, _size); }
+  inline void push_long(jlong l) {
+    _value_state[_size] = value_state_primitive;
+    _value_state[_size + 1] = value_state_primitive;
+    JNITypes::put_long(l, _value, _size);
+  }
 
-  inline void push_float(float f)   { _is_oop[_size] = false;
-                               JNITypes::put_float(f, _value, _size); }
+  inline void push_float(float f) {
+    _value_state[_size] = value_state_primitive;
+    JNITypes::put_float(f, _value, _size);
+  }
 
   // receiver
   Handle receiver() {
     assert(_size > 0, "must at least be one argument");
-    assert(_is_oop[0], "first argument must be an oop");
+    assert(_value_state[0] == value_state_handle,
+           "first argument must be an oop");
     assert(_value[0] != 0, "receiver must be not-null");
     return Handle((oop*)_value[0], false);
   }
@@ -162,11 +207,11 @@
   void set_receiver(Handle h) {
     assert(_start_at_zero == false, "can only be called once");
     _start_at_zero = true;
-    _is_oop--;
+    _value_state--;
     _value--;
     _size++;
-    _is_oop[0] = true;
-    _value[0] = (intptr_t)h.raw_value();
+    _value_state[0] = value_state_handle;
+    push_oop_impl(h.raw_value(), 0);
   }
 
   // Converts all Handles to oops, and returns a reference to parameter vector
@@ -174,7 +219,7 @@
   int   size_of_parameters() const { return _size; }
 
   // Verify that pushed arguments fits a given method
-  void verify(const methodHandle& method, BasicType return_type, Thread *thread);
+  void verify(const methodHandle& method, BasicType return_type);
 };
 
 // All calls to Java have to go via JavaCalls. Sets up the stack frame
--- a/hotspot/src/share/vm/runtime/jniHandles.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/runtime/jniHandles.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * 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,6 +31,9 @@
 #include "runtime/jniHandles.hpp"
 #include "runtime/mutexLocker.hpp"
 #include "runtime/thread.inline.hpp"
+#if INCLUDE_ALL_GCS
+#include "gc/g1/g1SATBCardTableModRefBS.hpp"
+#endif
 
 JNIHandleBlock* JNIHandles::_global_handles       = NULL;
 JNIHandleBlock* JNIHandles::_weak_global_handles  = NULL;
@@ -92,28 +95,48 @@
   jobject res = NULL;
   if (!obj.is_null()) {
     // ignore null handles
-    MutexLocker ml(JNIGlobalHandle_lock);
-    assert(Universe::heap()->is_in_reserved(obj()), "sanity check");
-    res = _weak_global_handles->allocate_handle(obj());
+    {
+      MutexLocker ml(JNIGlobalHandle_lock);
+      assert(Universe::heap()->is_in_reserved(obj()), "sanity check");
+      res = _weak_global_handles->allocate_handle(obj());
+    }
+    // Add weak tag.
+    assert(is_ptr_aligned(res, weak_tag_alignment), "invariant");
+    char* tptr = reinterpret_cast<char*>(res) + weak_tag_value;
+    res = reinterpret_cast<jobject>(tptr);
   } else {
     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
   }
   return res;
 }
 
+template<bool external_guard>
+oop JNIHandles::resolve_jweak(jweak handle) {
+  assert(is_jweak(handle), "precondition");
+  oop result = jweak_ref(handle);
+  result = guard_value<external_guard>(result);
+#if INCLUDE_ALL_GCS
+  if (result != NULL && UseG1GC) {
+    G1SATBCardTableModRefBS::enqueue(result);
+  }
+#endif // INCLUDE_ALL_GCS
+  return result;
+}
+
+template oop JNIHandles::resolve_jweak<true>(jweak);
+template oop JNIHandles::resolve_jweak<false>(jweak);
 
 void JNIHandles::destroy_global(jobject handle) {
   if (handle != NULL) {
     assert(is_global_handle(handle), "Invalid delete of global JNI handle");
-    *((oop*)handle) = deleted_handle(); // Mark the handle as deleted, allocate will reuse it
+    jobject_ref(handle) = deleted_handle();
   }
 }
 
 
 void JNIHandles::destroy_weak_global(jobject handle) {
   if (handle != NULL) {
-    assert(!CheckJNICalls || is_weak_global_handle(handle), "Invalid delete of weak global JNI handle");
-    *((oop*)handle) = deleted_handle(); // Mark the handle as deleted, allocate will reuse it
+    jweak_ref(handle) = deleted_handle();
   }
 }
 
--- a/hotspot/src/share/vm/runtime/jniHandles.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/runtime/jniHandles.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,28 @@
   static JNIHandleBlock* _weak_global_handles;        // First weak global handle block
   static oop _deleted_handle;                         // Sentinel marking deleted handles
 
+  inline static bool is_jweak(jobject handle);
+  inline static oop& jobject_ref(jobject handle); // NOT jweak!
+  inline static oop& jweak_ref(jobject handle);
+
+  template<bool external_guard> inline static oop guard_value(oop value);
+  template<bool external_guard> inline static oop resolve_impl(jobject handle);
+  template<bool external_guard> static oop resolve_jweak(jweak handle);
+
  public:
+  // Low tag bit in jobject used to distinguish a jweak.  jweak is
+  // type equivalent to jobject, but there are places where we need to
+  // be able to distinguish jweak values from other jobjects, and
+  // is_weak_global_handle is unsuitable for performance reasons.  To
+  // provide such a test we add weak_tag_value to the (aligned) byte
+  // address designated by the jobject to produce the corresponding
+  // jweak.  Accessing the value of a jobject must account for it
+  // being a possibly offset jweak.
+  static const uintptr_t weak_tag_size = 1;
+  static const uintptr_t weak_tag_alignment = (1u << weak_tag_size);
+  static const uintptr_t weak_tag_mask = weak_tag_alignment - 1;
+  static const int weak_tag_value = 1;
+
   // Resolve handle into oop
   inline static oop resolve(jobject handle);
   // Resolve externally provided handle into oop with some guards
@@ -176,36 +197,85 @@
   #endif
 };
 
+inline bool JNIHandles::is_jweak(jobject handle) {
+  STATIC_ASSERT(weak_tag_size == 1);
+  STATIC_ASSERT(weak_tag_value == 1);
+  return (reinterpret_cast<uintptr_t>(handle) & weak_tag_mask) != 0;
+}
+
+inline oop& JNIHandles::jobject_ref(jobject handle) {
+  assert(!is_jweak(handle), "precondition");
+  return *reinterpret_cast<oop*>(handle);
+}
+
+inline oop& JNIHandles::jweak_ref(jobject handle) {
+  assert(is_jweak(handle), "precondition");
+  char* ptr = reinterpret_cast<char*>(handle) - weak_tag_value;
+  return *reinterpret_cast<oop*>(ptr);
+}
+
+// external_guard is true if called from resolve_external_guard.
+// Treat deleted (and possibly zapped) as NULL for external_guard,
+// else as (asserted) error.
+template<bool external_guard>
+inline oop JNIHandles::guard_value(oop value) {
+  if (!external_guard) {
+    assert(value != badJNIHandle, "Pointing to zapped jni handle area");
+    assert(value != deleted_handle(), "Used a deleted global handle");
+  } else if ((value == badJNIHandle) || (value == deleted_handle())) {
+    value = NULL;
+  }
+  return value;
+}
+
+// external_guard is true if called from resolve_external_guard.
+template<bool external_guard>
+inline oop JNIHandles::resolve_impl(jobject handle) {
+  assert(handle != NULL, "precondition");
+  oop result;
+  if (is_jweak(handle)) {       // Unlikely
+    result = resolve_jweak<external_guard>(handle);
+  } else {
+    result = jobject_ref(handle);
+    // Construction of jobjects canonicalize a null value into a null
+    // jobject, so for non-jweak the pointee should never be null.
+    assert(external_guard || result != NULL,
+           "Invalid value read from jni handle");
+    result = guard_value<external_guard>(result);
+  }
+  return result;
+}
 
 inline oop JNIHandles::resolve(jobject handle) {
-  oop result = (handle == NULL ? (oop)NULL : *(oop*)handle);
-  assert(result != NULL || (handle == NULL || !CheckJNICalls || is_weak_global_handle(handle)), "Invalid value read from jni handle");
-  assert(result != badJNIHandle, "Pointing to zapped jni handle area");
+  oop result = NULL;
+  if (handle != NULL) {
+    result = resolve_impl<false /* external_guard */ >(handle);
+  }
   return result;
-};
-
+}
 
+// Resolve some erroneous cases to NULL, rather than treating them as
+// possibly unchecked errors.  In particular, deleted handles are
+// treated as NULL (though a deleted and later reallocated handle
+// isn't detected).
 inline oop JNIHandles::resolve_external_guard(jobject handle) {
-  if (handle == NULL) return NULL;
-  oop result = *(oop*)handle;
-  if (result == NULL || result == badJNIHandle) return NULL;
+  oop result = NULL;
+  if (handle != NULL) {
+    result = resolve_impl<true /* external_guard */ >(handle);
+  }
   return result;
-};
-
+}
 
 inline oop JNIHandles::resolve_non_null(jobject handle) {
   assert(handle != NULL, "JNI handle should not be null");
-  oop result = *(oop*)handle;
-  assert(result != NULL, "Invalid value read from jni handle");
-  assert(result != badJNIHandle, "Pointing to zapped jni handle area");
-  // Don't let that private _deleted_handle object escape into the wild.
-  assert(result != deleted_handle(), "Used a deleted global handle.");
+  oop result = resolve_impl<false /* external_guard */ >(handle);
+  assert(result != NULL, "NULL read from jni handle");
   return result;
-};
+}
 
 inline void JNIHandles::destroy_local(jobject handle) {
   if (handle != NULL) {
-    *((oop*)handle) = deleted_handle(); // Mark the handle as deleted, allocate will reuse it
+    jobject_ref(handle) = deleted_handle();
   }
 }
 
--- a/hotspot/src/share/vm/runtime/mutexLocker.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/runtime/mutexLocker.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -181,13 +181,13 @@
   }
   if (UseG1GC) {
 
-    def(SATB_Q_FL_lock             , PaddedMutex  , special,     true,  Monitor::_safepoint_check_never);
-    def(SATB_Q_CBL_mon             , PaddedMonitor, nonleaf,     true,  Monitor::_safepoint_check_never);
-    def(Shared_SATB_Q_lock         , PaddedMutex  , nonleaf,     true,  Monitor::_safepoint_check_never);
+    def(SATB_Q_FL_lock             , PaddedMutex  , special  ,   true,  Monitor::_safepoint_check_never);
+    def(SATB_Q_CBL_mon             , PaddedMonitor, leaf - 1 ,   true,  Monitor::_safepoint_check_never);
+    def(Shared_SATB_Q_lock         , PaddedMutex  , leaf - 1 ,   true,  Monitor::_safepoint_check_never);
 
-    def(DirtyCardQ_FL_lock         , PaddedMutex  , special,     true,  Monitor::_safepoint_check_never);
-    def(DirtyCardQ_CBL_mon         , PaddedMonitor, nonleaf,     true,  Monitor::_safepoint_check_never);
-    def(Shared_DirtyCardQ_lock     , PaddedMutex  , nonleaf,     true,  Monitor::_safepoint_check_never);
+    def(DirtyCardQ_FL_lock         , PaddedMutex  , special  ,   true,  Monitor::_safepoint_check_never);
+    def(DirtyCardQ_CBL_mon         , PaddedMonitor, leaf - 1 ,   true,  Monitor::_safepoint_check_never);
+    def(Shared_DirtyCardQ_lock     , PaddedMutex  , leaf - 1 ,   true,  Monitor::_safepoint_check_never);
 
     def(FreeList_lock              , PaddedMutex  , leaf     ,   true,  Monitor::_safepoint_check_never);
     def(SecondaryFreeList_lock     , PaddedMonitor, leaf     ,   true,  Monitor::_safepoint_check_never);
--- a/hotspot/src/share/vm/runtime/thread.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/runtime/thread.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -3409,9 +3409,16 @@
   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
   instanceKlassHandle klass (THREAD, k);
 
-  JavaValue result(T_VOID);
+  JavaValue result(T_INT);
+  JavaCallArguments args;
+  args.push_int(DisplayVMOutputToStderr);
+  args.push_int(log_is_enabled(Debug, init)); // print stack trace if exception thrown
   JavaCalls::call_static(&result, klass, vmSymbols::initPhase2_name(),
-                                         vmSymbols::void_method_signature(), CHECK);
+                                         vmSymbols::boolean_boolean_int_signature(), &args, CHECK);
+  if (result.get_jint() != JNI_OK) {
+    vm_exit_during_initialization(); // no message or exception
+  }
+
   universe_post_module_init();
 }
 
--- a/hotspot/src/share/vm/shark/sharkNativeWrapper.cpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/shark/sharkNativeWrapper.cpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2009, 2010 Red Hat, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -300,6 +300,7 @@
       not_null, merge);
 
     builder()->SetInsertPoint(not_null);
+#error Needs to be updated for tagged jweak; see JNIHandles.
     Value *unboxed_result = builder()->CreateLoad(result);
     builder()->CreateBr(merge);
 
--- a/hotspot/src/share/vm/utilities/debug.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/utilities/debug.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -140,6 +140,9 @@
 // For backward compatibility.
 #define assert(p, ...) vmassert(p, __VA_ARGS__)
 
+#ifndef ASSERT
+#define vmassert_status(p, status, msg)
+#else
 // This version of vmassert is for use with checking return status from
 // library calls that return actual error values eg. EINVAL,
 // ENOMEM etc, rather than returning -1 and setting errno.
@@ -155,6 +158,7 @@
     BREAKPOINT;                                                                \
   }                                                                            \
 } while (0)
+#endif
 
 // For backward compatibility.
 #define assert_status(p, status, msg) vmassert_status(p, status, msg)
--- a/hotspot/src/share/vm/utilities/globalDefinitions_xlc.hpp	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/src/share/vm/utilities/globalDefinitions_xlc.hpp	Wed Jul 05 23:08:24 2017 +0200
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2012, 2017 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
@@ -153,6 +153,9 @@
 // offset_of as it is defined for gcc.
 #define offset_of(klass,field) (size_t)((intx)&(((klass*)16)->field) - 16)
 
+// AIX 5.3 has buggy __thread support. (see JDK-8176442).
+#define USE_LIBRARY_BASED_TLS_ONLY 1
+
 #ifndef USE_LIBRARY_BASED_TLS_ONLY
 #define THREAD_LOCAL_DECL __thread
 #endif
--- a/hotspot/test/ProblemList.txt	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/test/ProblemList.txt	Wed Jul 05 23:08:24 2017 +0200
@@ -79,7 +79,5 @@
 
 # :hotspot_misc
 
-testlibrary_tests/ctw/JarDirTest.java 8172457 windows-all
-
 #############################################################################
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/arraycopy/TestObjectArrayCopy.java	Wed Jul 05 23:08:24 2017 +0200
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2017, SAP SE and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 8176505
+ * @summary Wrong assertion 'should be an array copy/clone' in arraycopynode.cpp
+ *
+ * @run main/othervm -Xbatch -XX:-UseOnStackReplacement compiler.arraycopy.TestObjectArrayCopy
+ *
+ * @author Volker Simonis
+ */
+
+package compiler.arraycopy;
+
+public class TestObjectArrayCopy {
+
+    public static boolean crash(Object src) {
+        String[] dst = new String[1];
+        System.arraycopy(src, 0, dst, 0, 1);
+        return dst[0] == null;
+    }
+
+    public static void main(String[] args) {
+        String[] sa = new String[1];
+        for (int i = 0; i < 20_000; i++) {
+            crash(sa);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/c2/TestNPEHeapBased.java	Wed Jul 05 23:08:24 2017 +0200
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017 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.
+ */
+
+/**
+ * @test
+ * @bug 8176518
+ * @summary Invalid ImplicitNullChecks when heap base not protected
+ *
+ * @run main/othervm -XX:ObjectAlignmentInBytes=16 -XX:HeapBaseMinAddress=64g
+ *      -XX:-TieredCompilation -Xbatch
+ *      compiler.c2.TestNPEHeapBased
+ * @requires vm.bits == "64"
+ */
+
+package compiler.c2;
+public class TestNPEHeapBased {
+
+    TestNPEHeapBased instance = null;
+    int i = 0;
+
+    public void set_i(int value) {
+        instance.i = value;
+    }
+
+
+    static final int loop_cnt = 200000;
+
+    public static void main(String args[]){
+        TestNPEHeapBased xyz = new TestNPEHeapBased();
+        xyz.instance = xyz;
+        for (int x = 0; x < loop_cnt; x++) xyz.set_i(x);
+        xyz.instance = null;
+        try {
+            xyz.set_i(0);
+        } catch (NullPointerException npe) {
+            System.out.println("Got expected NullPointerException:");
+            npe.printStackTrace();
+            return;
+        }
+        throw new InternalError("NullPointerException is missing!");
+    }
+
+}
--- a/hotspot/test/compiler/loopopts/TestLoopPeeling.java	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/test/compiler/loopopts/TestLoopPeeling.java	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8078262
+ * @bug 8078262 8177095
  * @summary Tests correct dominator information after loop peeling.
  *
  * @run main/othervm -Xcomp
@@ -40,14 +40,16 @@
     public static void main(String args[]) {
         TestLoopPeeling test = new TestLoopPeeling();
         try {
-            test.testArrayAccess(0, 1);
+            test.testArrayAccess1(0, 1);
+            test.testArrayAccess2(0);
+            test.testArrayAccess3(0, false);
             test.testArrayAllocation(0, 1);
         } catch (Exception e) {
             // Ignore exceptions
         }
     }
 
-    public void testArrayAccess(int index, int inc) {
+    public void testArrayAccess1(int index, int inc) {
         int storeIndex = -1;
 
         for (; index < 10; index += inc) {
@@ -63,7 +65,7 @@
 
             if (index == 42) {
                 // This store and the corresponding range check are moved out of the
-                // loop and both used after old loop and the peeled iteration exit.
+                // loop and both used after main loop and the peeled iteration exit.
                 // For the peeled iteration, storeIndex is always -1 and the ConvI2L
                 // is replaced by TOP. However, the range check is not folded because
                 // we don't do the split if optimization in PhaseIdealLoop2.
@@ -77,6 +79,44 @@
         }
     }
 
+    public int testArrayAccess2(int index) {
+        // Load1 and the corresponding range check are moved out of the loop
+        // and both are used after the main loop and the peeled iteration exit.
+        // For the peeled iteration, storeIndex is always Integer.MIN_VALUE and
+        // for the main loop it is 0. Hence, the merging phi has type int:<=0.
+        // Load1 reads the array at index ConvI2L(CastII(AddI(storeIndex, -1)))
+        // where the CastII is range check dependent and has type int:>=0.
+        // The CastII gets pushed through the AddI and its type is changed to int:>=1
+        // which does not overlap with the input type of storeIndex (int:<=0).
+        // The CastII is replaced by TOP causing a cascade of other eliminations.
+        // Since the control path through the range check CmpU(AddI(storeIndex, -1))
+        // is not eliminated, the graph is in a corrupted state. We fail once we merge
+        // with the result of Load2 because we get data from a non-dominating region.
+        int storeIndex = Integer.MIN_VALUE;
+        for (; index < 10; ++index) {
+            if (index == 42) {
+                return array[storeIndex-1]; // Load1
+            }
+            storeIndex = 0;
+        }
+        return array[42]; // Load2
+    }
+
+    public int testArrayAccess3(int index, boolean b) {
+        // Same as testArrayAccess2 but manifests as crash in register allocator.
+        int storeIndex = Integer.MIN_VALUE;
+        for (; index < 10; ++index) {
+            if (b) {
+                return 0;
+            }
+            if (index == 42) {
+                return array[storeIndex-1]; // Load1
+            }
+            storeIndex = 0;
+        }
+        return array[42]; // Load2
+    }
+
     public byte[] testArrayAllocation(int index, int inc) {
         int allocationCount = -1;
         byte[] result;
@@ -88,7 +128,7 @@
 
             if (index == 42) {
                 // This allocation and the corresponding size check are moved out of the
-                // loop and both used after old loop and the peeled iteration exit.
+                // loop and both used after main loop and the peeled iteration exit.
                 // For the peeled iteration, allocationCount is always -1 and the ConvI2L
                 // is replaced by TOP. However, the size check is not folded because
                 // we don't do the split if optimization in PhaseIdealLoop2.
--- a/hotspot/test/runtime/MinimalVM/JMX.java	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/test/runtime/MinimalVM/JMX.java	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -47,9 +47,8 @@
                 .shouldContain("-Dcom.sun.management is not supported in this VM.")
                 .shouldHaveExitValue(1);
 
-        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), Long.toString(ProcessTools.getProcessId()), "VM.print_threads"});
+        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), "-l"});
         new OutputAnalyzer(pb.start())
-                .shouldContain("Could not find any processes matching ")
-                .shouldHaveExitValue(1);
+                .shouldNotMatch("^" + Long.toString(ProcessTools.getProcessId()) + "\\s+.*$");
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/constantPool/ACCModule52.java	Wed Jul 05 23:08:24 2017 +0200
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 jdk.internal.org.objectweb.asm.*;
+
+/*
+ * @test
+ * @summary Test that the JVM ignores ACC_MODULE if it is set for a version
+ *          52 class file.
+ * @bug 8175383
+ * @library /test/lib
+ * @modules java.base/jdk.internal.org.objectweb.asm
+ * @compile -XDignore.symbol.file ACCModule52.java
+ * @run main ACCModule52
+ */
+
+public class ACCModule52 {
+
+    static final String CLASS_NAME = "ACCModule52Pkg";
+
+    public static void main(String[] args) throws Exception {
+        int ACC_MODULE = 0x8000;
+        ClassWriter cw = new ClassWriter(0);
+        cw.visit(Opcodes.V1_8,
+                Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT + Opcodes.ACC_SYNTHETIC + ACC_MODULE,
+                CLASS_NAME,
+                null,
+                "java/lang/Object",
+                null);
+
+        cw.visitEnd();
+        byte[] bytes = cw.toByteArray();
+
+
+        ClassLoader loader = new ClassLoader(ACCModule52.class.getClassLoader()) {
+            @Override
+            protected Class<?> findClass(String cn)throws ClassNotFoundException {
+                if (cn.equals(CLASS_NAME)) {
+                    Class superClass = super.defineClass(cn, bytes, 0, bytes.length);
+                } else {
+                    throw new ClassNotFoundException(cn);
+                }
+                return null;
+            }
+        };
+
+        Class<?> clazz = loader.loadClass(CLASS_NAME);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/constantPool/ConstModule.java	Wed Jul 05 23:08:24 2017 +0200
@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 jdk.internal.org.objectweb.asm.*;
+
+/*
+ * @test
+ * @summary Test scenarios for constant pool CONSTANT_Module and CONSTANT_Package
+ *          types, for class file versions 53 and 52, when ACC_MODULE is set and
+ *          not set in the access_flags.
+ * @bug 8175383
+ * @library /test/lib
+ * @modules java.base/jdk.internal.org.objectweb.asm
+ * @compile -XDignore.symbol.file ConstModule.java
+ * @run main ConstModule
+ */
+
+public class ConstModule {
+
+    static final int ACC_MODULE = 0x8000;
+    static final boolean MODULE_TEST = true;
+    static final boolean PACKAGE_TEST = false;
+    static final boolean CFE_EXCEPTION = true;
+    static final boolean NCDFE_EXCEPTION = false;
+
+    public static void main(String[] args) throws Exception {
+
+        // Test that the JVM throws CFE for constant pool CONSTANT_Module type, for
+        // class file version 53, when ACC_MODULE is not set in the access_flags.
+        ConstModule.write_and_load(Opcodes.V1_9,
+            Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT + Opcodes.ACC_SYNTHETIC,
+            "jdk.fooMod", "FooMod", MODULE_TEST, CFE_EXCEPTION);
+
+        // Test that the JVM throws NCDFE for constant pool CONSTANT_Module type,
+        // for class file version 53, when ACC_MODULE is set in the access_flags.
+        ConstModule.write_and_load(Opcodes.V1_9,
+            Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT + Opcodes.ACC_SYNTHETIC + ACC_MODULE,
+            "jdk.fooModACC", "FooModACC", MODULE_TEST, NCDFE_EXCEPTION);
+
+        // Test that the JVM throws CFE for constant pool CONSTANT_Module type, for
+        // class file version 52, even when ACC_MODULE is set in the access_flags.
+        ConstModule.write_and_load(Opcodes.V1_8,
+            Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT + Opcodes.ACC_SYNTHETIC + ACC_MODULE,
+            "jdk.fooModACC52", "FooModACC52", MODULE_TEST, CFE_EXCEPTION);
+
+        // Test that the JVM throws CFE for constant pool CONSTANT_Package type, for
+        // class file version 53, when ACC_MODULE is not set in the access_flags.
+        ConstModule.write_and_load(Opcodes.V1_9,
+            Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT + Opcodes.ACC_SYNTHETIC,
+            "jdk.fooPkg", "FooPkg", PACKAGE_TEST, CFE_EXCEPTION);
+
+        // Test that the JVM throws NCDFE for constant pool CONSTANT_Package type,
+        // for class file version 53, when ACC_MODULE is set in the access_flags.
+        ConstModule.write_and_load(Opcodes.V1_9,
+            Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT + Opcodes.ACC_SYNTHETIC + ACC_MODULE,
+            "jdk.fooModACC", "FooModACC", PACKAGE_TEST, NCDFE_EXCEPTION);
+
+        // Test that the JVM throws CFE for constant pool CONSTANT_Package type, for
+        // class file version 52, even when ACC_MODULE is set in the access_flags.
+        ConstModule.write_and_load(Opcodes.V1_8,
+            Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT + Opcodes.ACC_SYNTHETIC + ACC_MODULE,
+            "jdk.fooModACC52", "FooModACC52", PACKAGE_TEST, CFE_EXCEPTION);
+
+    }
+
+    public static void write_and_load(int version,
+                                      int access_flags,
+                                      String attr,
+                                      String class_name,
+                                      boolean module_test,
+                                      boolean throwCFE) throws Exception {
+        ClassWriter cw = new ClassWriter(0);
+        cw.visit(version,
+                 access_flags,
+                 class_name,
+                 null,
+                 "java/lang/Object",
+                 null);
+
+        if (module_test)
+            cw.visitAttribute(new TestModuleAttribute(attr));
+        else
+            cw.visitAttribute(new TestPackageAttribute(attr));
+
+        cw.visitEnd();
+        byte[] bytes = cw.toByteArray();
+
+
+        ClassLoader loader = new ClassLoader(ConstModule.class.getClassLoader()) {
+            @Override
+            protected Class<?> findClass(String cn)throws ClassNotFoundException {
+                if (cn.equals(class_name)) {
+                    try {
+                        Class superClass = super.defineClass(cn, bytes, 0, bytes.length);
+                        throw new RuntimeException("Expected ClassFormatError not thrown");
+                    } catch (java.lang.ClassFormatError e) {
+                       if (!throwCFE) {
+                           throw new RuntimeException("Unexpected ClassFormatError exception: " + e.getMessage());
+                       }
+                       if (module_test && !e.getMessage().contains(
+                           "Unknown constant tag 19 in class file")) {
+                           throw new RuntimeException("Wrong ClassFormatError exception: " + e.getMessage());
+                       } else if (!module_test && !e.getMessage().contains(
+                           "Unknown constant tag 20 in class file")) {
+                           throw new RuntimeException("Wrong ClassFormatError exception: " + e.getMessage());
+                       }
+                    } catch (java.lang.NoClassDefFoundError f) {
+                       if (throwCFE) {
+                           throw new RuntimeException("Unexpected NoClassDefFoundError exception: " + f.getMessage());
+                       }
+                       if (!f.getMessage().contains(
+                           "is not a class because access_flag ACC_MODULE is set")) {
+                           throw new RuntimeException("Wrong NoClassDefFoundError exception: " + f.getMessage());
+                       }
+                    }
+                } else {
+                    throw new ClassNotFoundException(cn);
+                }
+                return null;
+            }
+        };
+
+        Class<?> clazz = loader.loadClass(class_name);
+    }
+
+    /**
+     * ConstModuleAttr attribute.
+     *
+     * <pre> {@code
+     *
+     * MainClass_attribute {
+     *   // index to CONSTANT_utf8_info structure in constant pool representing
+     *   // the string "ConstModuleAttr"
+     *   u2 attribute_name_index;
+     *   u4 attribute_length;
+     *
+     *   // index to CONSTANT_Module_info structure
+     *   u2 module_name_index
+     * }
+     *
+     * } </pre>
+     */
+    public static class TestModuleAttribute extends Attribute {
+        private final String moduleName;
+
+        public TestModuleAttribute(String moduleName) {
+            super("ConstModuleAttr");
+            this.moduleName = moduleName;
+        }
+
+        public TestModuleAttribute() {
+            this(null);
+        }
+
+        @Override
+        protected Attribute read(ClassReader cr,
+                                 int off,
+                                 int len,
+                                 char[] buf,
+                                 int codeOff,
+                                 Label[] labels)
+        {
+            String mn = cr.readModule(off, buf);
+            off += 2;
+            return new TestModuleAttribute(mn);
+        }
+
+        @Override
+        protected ByteVector write(ClassWriter cw,
+                                   byte[] code,
+                                   int len,
+                                   int maxStack,
+                                   int maxLocals)
+        {
+            ByteVector attr = new ByteVector();
+            attr.putShort(cw.newModule(moduleName));
+            return attr;
+        }
+    }
+
+    /**
+     * ConstPackageAttr attribute.
+     *
+     * <pre> {@code
+     *
+     * MainClass_attribute {
+     *   // index to CONSTANT_utf8_info structure in constant pool representing
+     *   // the string "ConstPackageAttr"
+     *   u2 attribute_name_index;
+     *   u4 attribute_length;
+     *
+     *   // index to CONSTANT_Package_info structure
+     *   u2 module_name_index
+     * }
+     *
+     * } </pre>
+     */
+    public static class TestPackageAttribute extends Attribute {
+        private final String packageName;
+
+        public TestPackageAttribute(String packageName) {
+            super("ConstPackageAttr");
+            this.packageName = packageName;
+        }
+
+        public TestPackageAttribute() {
+            this(null);
+        }
+
+        @Override
+        protected Attribute read(ClassReader cr,
+                                 int off,
+                                 int len,
+                                 char[] buf,
+                                 int codeOff,
+                                 Label[] labels)
+        {
+            String mn = cr.readPackage(off, buf);
+            off += 2;
+            return new TestPackageAttribute(mn);
+        }
+
+        @Override
+        protected ByteVector write(ClassWriter cw,
+                                   byte[] code,
+                                   int len,
+                                   int maxStack,
+                                   int maxLocals)
+        {
+            ByteVector attr = new ByteVector();
+            attr.putShort(cw.newPackage(packageName));
+            return attr;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/duplAttributes/DupSignatureAttrs.jcod	Wed Jul 05 23:08:24 2017 +0200
@@ -0,0 +1,615 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// Class containing duplicate Signature attributes.  Loading it should cause a
+// ClassFormatError exception.
+class DupClassSigAttrs {
+  0xCAFEBABE;
+  0; // minor version
+  53; // version
+  [33] { // Constant Pool
+    ; // first element is empty
+    Method #6 #17; // #1     at 0x0A
+    Field #18 #19; // #2     at 0x0F
+    String #20; // #3     at 0x14
+    Method #21 #22; // #4     at 0x17
+    class #23; // #5     at 0x1C
+    class #24; // #6     at 0x1F
+    Utf8 "<init>"; // #7     at 0x22
+    Utf8 "()V"; // #8     at 0x2B
+    Utf8 "Code"; // #9     at 0x31
+    Utf8 "LineNumberTable"; // #10     at 0x38
+    Utf8 "main"; // #11     at 0x4A
+    Utf8 "([Ljava/lang/String;)V"; // #12     at 0x51
+    Utf8 "Exceptions"; // #13     at 0x6A
+    class #25; // #14     at 0x77
+    Utf8 "SourceFile"; // #15     at 0x7A
+    Utf8 "DupClassSigAttrs.java"; // #16     at 0x87
+    NameAndType #7 #8; // #17     at 0x9F
+    class #26; // #18     at 0xA4
+    NameAndType #27 #28; // #19     at 0xA7
+    Utf8 "hi"; // #20     at 0xAC
+    class #29; // #21     at 0xB1
+    NameAndType #30 #31; // #22     at 0xB4
+    Utf8 "DupClassSigAttrs"; // #23     at 0xB9
+    Utf8 "java/lang/Object"; // #24     at 0xCC
+    Utf8 "java/lang/Throwable"; // #25     at 0xDF
+    Utf8 "java/lang/System"; // #26     at 0xF5
+    Utf8 "out"; // #27     at 0x0108
+    Utf8 "Ljava/io/PrintStream;"; // #28     at 0x010E
+    Utf8 "java/io/PrintStream"; // #29     at 0x0126
+    Utf8 "println"; // #30     at 0x013C
+    Utf8 "(Ljava/lang/String;)V"; // #31     at 0x0146
+    Utf8 "Signature"; // #32     at 0x015E
+  } // Constant Pool
+
+  0x0021; // access
+  #5;// this_cpx
+  #6;// super_cpx
+
+  [0] { // Interfaces
+  } // Interfaces
+
+  [0] { // fields
+  } // fields
+
+  [2] { // methods
+    { // Member at 0x0176
+      0x0001; // access
+      #7; // name_cpx
+      #8; // sig_cpx
+      [1] { // Attributes
+        Attr(#9, 29) { // Code at 0x017E
+          1; // max_stack
+          1; // max_locals
+          Bytes[5]{
+            0x2AB70001B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#10, 6) { // LineNumberTable at 0x0195
+              [1] { // LineNumberTable
+                0  1; //  at 0x01A1
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x01A1
+      0x0009; // access
+      #11; // name_cpx
+      #12; // sig_cpx
+      [2] { // Attributes
+        Attr(#9, 37) { // Code at 0x01A9
+          2; // max_stack
+          1; // max_locals
+          Bytes[9]{
+            0xB200021203B60004;
+            0xB1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#10, 10) { // LineNumberTable at 0x01C4
+              [2] { // LineNumberTable
+                0  4; //  at 0x01D0
+                8  5; //  at 0x01D4
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+        ;
+        Attr(#13, 4) { // Exceptions at 0x01D4
+          [1] { // Exceptions
+            #14; //  at 0x01DE
+          }
+        } // end Exceptions
+      } // Attributes
+    } // Member
+  } // methods
+
+  [3] { // Attributes
+    Attr(#15, 2) { // SourceFile at 0x01E0
+      #16;
+    } // end SourceFile
+    ;
+    Attr(#32, 2) { // Signature at 0x01E8
+      #16;
+    } // end Signature
+    ;
+    Attr(#32, 2) { // *** Duplicate *** Signature at 0x01F0
+      #16;
+    } // end Signature
+  } // Attributes
+} // end class DupClassSigAttrs
+
+
+// Class containing a method with duplicate Signature attributes.  Loading it
+// should cause a ClassFormatError exception.
+class DupMthSigAttrs {
+  0xCAFEBABE;
+  0; // minor version
+  53; // version
+  [33] { // Constant Pool
+    ; // first element is empty
+    Method #6 #17; // #1     at 0x0A
+    Field #18 #19; // #2     at 0x0F
+    String #20; // #3     at 0x14
+    Method #21 #22; // #4     at 0x17
+    class #23; // #5     at 0x1C
+    class #24; // #6     at 0x1F
+    Utf8 "<init>"; // #7     at 0x22
+    Utf8 "()V"; // #8     at 0x2B
+    Utf8 "Code"; // #9     at 0x31
+    Utf8 "LineNumberTable"; // #10     at 0x38
+    Utf8 "main"; // #11     at 0x4A
+    Utf8 "([Ljava/lang/String;)V"; // #12     at 0x51
+    Utf8 "Exceptions"; // #13     at 0x6A
+    class #25; // #14     at 0x77
+    Utf8 "SourceFile"; // #15     at 0x7A
+    Utf8 "DupMthSigAttrs.java"; // #16     at 0x87
+    NameAndType #7 #8; // #17     at 0x9D
+    class #26; // #18     at 0xA2
+    NameAndType #27 #28; // #19     at 0xA5
+    Utf8 "hi"; // #20     at 0xAA
+    class #29; // #21     at 0xAF
+    NameAndType #30 #31; // #22     at 0xB2
+    Utf8 "DupMthSigAttrs"; // #23     at 0xB7
+    Utf8 "java/lang/Object"; // #24     at 0xC8
+    Utf8 "java/lang/Throwable"; // #25     at 0xDB
+    Utf8 "java/lang/System"; // #26     at 0xF1
+    Utf8 "out"; // #27     at 0x0104
+    Utf8 "Ljava/io/PrintStream;"; // #28     at 0x010A
+    Utf8 "java/io/PrintStream"; // #29     at 0x0122
+    Utf8 "println"; // #30     at 0x0138
+    Utf8 "(Ljava/lang/String;)V"; // #31     at 0x0142
+    Utf8 "Signature"; // #32     at 0x015A
+  } // Constant Pool
+
+  0x0021; // access
+  #5;// this_cpx
+  #6;// super_cpx
+
+  [0] { // Interfaces
+  } // Interfaces
+
+  [0] { // fields
+  } // fields
+
+  [2] { // methods
+    { // Member at 0x0172
+      0x0001; // access
+      #7; // name_cpx
+      #8; // sig_cpx
+      [1] { // Attributes
+        Attr(#9, 29) { // Code at 0x017A
+          1; // max_stack
+          1; // max_locals
+          Bytes[5]{
+            0x2AB70001B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#10, 6) { // LineNumberTable at 0x0191
+              [1] { // LineNumberTable
+                0  1; //  at 0x019D
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x019D
+      0x0009; // access
+      #11; // name_cpx
+      #12; // sig_cpx
+      [4] { // Attributes
+        Attr(#9, 37) { // Code at 0x01A5
+          2; // max_stack
+          1; // max_locals
+          Bytes[9]{
+            0xB200021203B60004;
+            0xB1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#10, 10) { // LineNumberTable at 0x01C0
+              [2] { // LineNumberTable
+                0  4; //  at 0x01CC
+                8  5; //  at 0x01D0
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+        ;
+        Attr(#32, 2) { // Signature at 0x01D0
+          #16;
+        } // end Signature
+        ;
+        Attr(#13, 4) { // Exceptions at 0x01D8
+          [1] { // Exceptions
+            #14; //  at 0x01E2
+          }
+        } // end Exceptions
+        ;
+        Attr(#32, 2) { // *** Duplicate *** Signature at 0x01E2
+          #16;
+        } // end Signature
+      } // Attributes
+    } // Member
+  } // methods
+
+  [1] { // Attributes
+    Attr(#15, 2) { // SourceFile at 0x01EC
+      #16;
+    } // end SourceFile
+  } // Attributes
+} // end class DupMthSigAttrs
+
+
+// Class containing a field with duplicate Signature attributes.  Loading it
+// should cause a ClassFormatError exception.
+class DupFldSigAttrs {
+  0xCAFEBABE;
+  0; // minor version
+  53; // version
+  [42] { // Constant Pool
+    ; // first element is empty
+    Method #9 #23; // #1     at 0x0A
+    Field #24 #25; // #2     at 0x0F
+    Field #8 #26; // #3     at 0x14
+    Method #27 #28; // #4     at 0x19
+    class #29; // #5     at 0x1E
+    String #30; // #6     at 0x21
+    Method #5 #31; // #7     at 0x24
+    class #32; // #8     at 0x29
+    class #33; // #9     at 0x2C
+    Utf8 "str"; // #10     at 0x2F
+    Utf8 "Ljava/lang/String;"; // #11     at 0x35
+    Utf8 "<init>"; // #12     at 0x4A
+    Utf8 "()V"; // #13     at 0x53
+    Utf8 "Code"; // #14     at 0x59
+    Utf8 "LineNumberTable"; // #15     at 0x60
+    Utf8 "main"; // #16     at 0x72
+    Utf8 "([Ljava/lang/String;)V"; // #17     at 0x79
+    Utf8 "Exceptions"; // #18     at 0x92
+    class #34; // #19     at 0x9F
+    Utf8 "<clinit>"; // #20     at 0xA2
+    Utf8 "SourceFile"; // #21     at 0xAD
+    Utf8 "DupFldSigAttrs.java"; // #22     at 0xBA
+    NameAndType #12 #13; // #23     at 0xD0
+    class #35; // #24     at 0xD5
+    NameAndType #36 #37; // #25     at 0xD8
+    NameAndType #10 #11; // #26     at 0xDD
+    class #38; // #27     at 0xE2
+    NameAndType #39 #40; // #28     at 0xE5
+    Utf8 "java/lang/String"; // #29     at 0xEA
+    Utf8 "Hi"; // #30     at 0xFD
+    NameAndType #12 #40; // #31     at 0x0102
+    Utf8 "DupFldSigAttrs"; // #32     at 0x0107
+    Utf8 "java/lang/Object"; // #33     at 0x0118
+    Utf8 "java/lang/Throwable"; // #34     at 0x012B
+    Utf8 "java/lang/System"; // #35     at 0x0141
+    Utf8 "out"; // #36     at 0x0154
+    Utf8 "Ljava/io/PrintStream;"; // #37     at 0x015A
+    Utf8 "java/io/PrintStream"; // #38     at 0x0172
+    Utf8 "println"; // #39     at 0x0188
+    Utf8 "(Ljava/lang/String;)V"; // #40     at 0x0192
+    Utf8 "Signature"; // #41     at 0x01AA
+  } // Constant Pool
+
+  0x0021; // access
+  #8;// this_cpx
+  #9;// super_cpx
+
+  [0] { // Interfaces
+  } // Interfaces
+
+  [1] { // fields
+    { // Member at 0x01C0
+      0x0008; // access
+      #10; // name_cpx
+      #11; // sig_cpx
+      [2] { // Attributes
+        Attr(#41, 2) { // Signature at 0x01C8
+          #16;
+        } // end Signature
+        ;
+        Attr(#41, 2) { // *** Duplicate *** Signature at 0x01D0
+          #16;
+        } // end Signature
+      } // Attributes
+    } // Member
+  } // fields
+
+  [3] { // methods
+    { // Member at 0x01DA
+      0x0001; // access
+      #12; // name_cpx
+      #13; // sig_cpx
+      [1] { // Attributes
+        Attr(#14, 29) { // Code at 0x01E2
+          1; // max_stack
+          1; // max_locals
+          Bytes[5]{
+            0x2AB70001B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#15, 6) { // LineNumberTable at 0x01F9
+              [1] { // LineNumberTable
+                0  1; //  at 0x0205
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x0205
+      0x0009; // access
+      #16; // name_cpx
+      #17; // sig_cpx
+      [2] { // Attributes
+        Attr(#14, 38) { // Code at 0x020D
+          2; // max_stack
+          1; // max_locals
+          Bytes[10]{
+            0xB20002B20003B600;
+            0x04B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#15, 10) { // LineNumberTable at 0x0229
+              [2] { // LineNumberTable
+                0  6; //  at 0x0235
+                9  7; //  at 0x0239
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+        ;
+        Attr(#18, 4) { // Exceptions at 0x0239
+          [1] { // Exceptions
+            #19; //  at 0x0243
+          }
+        } // end Exceptions
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x0243
+      0x0008; // access
+      #20; // name_cpx
+      #13; // sig_cpx
+      [1] { // Attributes
+        Attr(#14, 37) { // Code at 0x024B
+          3; // max_stack
+          0; // max_locals
+          Bytes[13]{
+            0xBB0005591206B700;
+            0x07B30003B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#15, 6) { // LineNumberTable at 0x026A
+              [1] { // LineNumberTable
+                0  3; //  at 0x0276
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+  } // methods
+
+  [1] { // Attributes
+    Attr(#21, 2) { // SourceFile at 0x0278
+      #22;
+    } // end SourceFile
+  } // Attributes
+} // end class DupFldSigAttrs
+
+
+// Class containing a Signature attribute and a field and methods with Signature
+// attributes.  Since neither the class nor any of its fields or methods have
+// duplicate Signature attributes, loading this class should not cause a
+// ClassFormatError exception.
+class OkaySigAttrs {
+  0xCAFEBABE;
+  0; // minor version
+  53; // version
+  [42] { // Constant Pool
+    ; // first element is empty
+    Method #9 #23; // #1     at 0x0A
+    Field #24 #25; // #2     at 0x0F
+    Field #8 #26; // #3     at 0x14
+    Method #27 #28; // #4     at 0x19
+    class #29; // #5     at 0x1E
+    String #30; // #6     at 0x21
+    Method #5 #31; // #7     at 0x24
+    class #32; // #8     at 0x29
+    class #33; // #9     at 0x2C
+    Utf8 "str"; // #10     at 0x2F
+    Utf8 "Ljava/lang/String;"; // #11     at 0x35
+    Utf8 "<init>"; // #12     at 0x4A
+    Utf8 "()V"; // #13     at 0x53
+    Utf8 "Code"; // #14     at 0x59
+    Utf8 "LineNumberTable"; // #15     at 0x60
+    Utf8 "main"; // #16     at 0x72
+    Utf8 "([Ljava/lang/String;)V"; // #17     at 0x79
+    Utf8 "Exceptions"; // #18     at 0x92
+    class #34; // #19     at 0x9F
+    Utf8 "<clinit>"; // #20     at 0xA2
+    Utf8 "SourceFile"; // #21     at 0xAD
+    Utf8 "OkaySigAttrs.java"; // #22     at 0xBA
+    NameAndType #12 #13; // #23     at 0xCE
+    class #35; // #24     at 0xD3
+    NameAndType #36 #37; // #25     at 0xD6
+    NameAndType #10 #11; // #26     at 0xDB
+    class #38; // #27     at 0xE0
+    NameAndType #39 #40; // #28     at 0xE3
+    Utf8 "java/lang/String"; // #29     at 0xE8
+    Utf8 "Hi"; // #30     at 0xFB
+    NameAndType #12 #40; // #31     at 0x0100
+    Utf8 "OkaySigAttrs"; // #32     at 0x0105
+    Utf8 "java/lang/Object"; // #33     at 0x0114
+    Utf8 "java/lang/Throwable"; // #34     at 0x0127
+    Utf8 "java/lang/System"; // #35     at 0x013D
+    Utf8 "out"; // #36     at 0x0150
+    Utf8 "Ljava/io/PrintStream;"; // #37     at 0x0156
+    Utf8 "java/io/PrintStream"; // #38     at 0x016E
+    Utf8 "println"; // #39     at 0x0184
+    Utf8 "(Ljava/lang/String;)V"; // #40     at 0x018E
+    Utf8 "Signature"; // #41     at 0x01A6
+  } // Constant Pool
+
+  0x0021; // access
+  #8;// this_cpx
+  #9;// super_cpx
+
+  [0] { // Interfaces
+  } // Interfaces
+
+  [1] { // fields
+    { // Member at 0x01BC
+      0x0008; // access
+      #10; // name_cpx
+      #11; // sig_cpx
+      [1] { // Attributes
+        Attr(#41, 2) { // Signature at 0x01C4
+          #16;
+        } // end Signature
+      } // Attributes
+    } // Member
+  } // fields
+
+  [3] { // methods
+    { // Member at 0x01CE
+      0x0001; // access
+      #12; // name_cpx
+      #13; // sig_cpx
+      [2] { // Attributes
+        Attr(#14, 29) { // Code at 0x01D6
+          1; // max_stack
+          1; // max_locals
+          Bytes[5]{
+            0x2AB70001B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#15, 6) { // LineNumberTable at 0x01ED
+              [1] { // LineNumberTable
+                0  1; //  at 0x01F9
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+        ;
+        Attr(#41, 2) { // Signature at 0x01F9
+          #16;
+        } // end Signature
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x0201
+      0x0009; // access
+      #16; // name_cpx
+      #17; // sig_cpx
+      [3] { // Attributes
+        Attr(#14, 38) { // Code at 0x0209
+          2; // max_stack
+          1; // max_locals
+          Bytes[10]{
+            0xB20002B20003B600;
+            0x04B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#15, 10) { // LineNumberTable at 0x0225
+              [2] { // LineNumberTable
+                0  6; //  at 0x0231
+                9  7; //  at 0x0235
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+        ;
+        Attr(#41, 2) { // Signature at 0x0235
+          #16;
+        } // end Signature
+        ;
+        Attr(#18, 4) { // Exceptions at 0x023D
+          [1] { // Exceptions
+            #19; //  at 0x0247
+          }
+        } // end Exceptions
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x0247
+      0x0008; // access
+      #20; // name_cpx
+      #13; // sig_cpx
+      [1] { // Attributes
+        Attr(#14, 37) { // Code at 0x024F
+          3; // max_stack
+          0; // max_locals
+          Bytes[13]{
+            0xBB0005591206B700;
+            0x07B30003B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#15, 6) { // LineNumberTable at 0x026E
+              [1] { // LineNumberTable
+                0  3; //  at 0x027A
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+  } // methods
+
+  [2] { // Attributes
+    Attr(#21, 2) { // SourceFile at 0x027C
+      #22;
+    } // end SourceFile
+    ;
+    Attr(#41, 2) { // Signature at 0x0284
+      #16;
+    } // end Signature
+  } // Attributes
+} // end class OkaySigAttrs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/duplAttributes/TestDupSignatureAttr.java	Wed Jul 05 23:08:24 2017 +0200
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 8176147
+ * @summary Throw ClassFormatError exception for multiple Signature attributes
+ * @compile DupSignatureAttrs.jcod
+ * @run main TestDupSignatureAttr
+ */
+
+public class TestDupSignatureAttr {
+    public static void main(String args[]) throws Throwable {
+
+        System.out.println("Regression test for bug 8176147");
+
+        String[] badClasses = new String[] {
+            "DupClassSigAttrs",
+            "DupMthSigAttrs",
+            "DupFldSigAttrs",
+        };
+        String[] messages = new String[] {
+            "Multiple Signature attributes in class file",
+            "Multiple Signature attributes for method",
+            "Multiple Signature attributes for field",
+        };
+
+        for (int x = 0; x < badClasses.length; x++) {
+            try {
+                Class newClass = Class.forName(badClasses[x]);
+                throw new RuntimeException("Expected ClassFormatError exception not thrown");
+            } catch (java.lang.ClassFormatError e) {
+                if (!e.getMessage().contains(messages[x])) {
+                    throw new RuntimeException("Wrong ClassFormatError exception thrown: " +
+                                               e.getMessage());
+                }
+            }
+        }
+
+        // Multiple Signature attributes but no duplicates.
+        Class newClass = Class.forName("OkaySigAttrs");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/jni/CallWithJNIWeak/CallWithJNIWeak.java	Wed Jul 05 23:08:24 2017 +0200
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 8166188
+ * @summary Test call of native function with JNI weak global ref.
+ * @modules java.base
+ * @run main/othervm/native CallWithJNIWeak
+ */
+
+public class CallWithJNIWeak {
+    static {
+        System.loadLibrary("CallWithJNIWeak");
+    }
+
+    private static native void testJNIFieldAccessors(CallWithJNIWeak o);
+
+    // The field initializations must be kept in sync with the JNI code
+    // which reads verifies the values of these fields.
+    private int i = 1;
+    private long j = 2;
+    private boolean z = true;
+    private char c = 'a';
+    private short s = 3;
+    private float f = 1.0f;
+    private double d = 2.0;
+    private Object l;
+
+    private CallWithJNIWeak() {
+        this.l = this;
+    }
+
+    private native void weakReceiverTest0();
+    private void weakReceiverTest() {
+        weakReceiverTest0();
+    }
+
+    private synchronized void synchonizedWeakReceiverTest() {
+        this.notifyAll();
+    }
+
+
+    private static native void runTests(CallWithJNIWeak o);
+
+    public static void main(String[] args) {
+        CallWithJNIWeak w = new CallWithJNIWeak();
+        for (int i = 0; i < 20000; i++) {
+            runTests(w);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/jni/CallWithJNIWeak/libCallWithJNIWeak.c	Wed Jul 05 23:08:24 2017 +0200
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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>
+
+/*
+ * Class:     CallWithJNIWeak
+ * Method:    testJNIFieldAccessors
+ * Signature: (LCallWithJNIWeak;)V
+ */
+JNIEXPORT void JNICALL
+Java_CallWithJNIWeak_testJNIFieldAccessors(JNIEnv *env, jclass clazz, jobject this) {
+  // Make sure that we have a weak reference to the receiver
+
+  jweak self = (*env)->NewWeakGlobalRef(env, this);
+
+  jclass this_class = (*env)->GetObjectClass(env, self);
+
+  jclass exception = (*env)->FindClass(env, "java/lang/RuntimeException");
+
+  jfieldID id_i = (*env)->GetFieldID(env, this_class, "i", "I");
+  jfieldID id_j = (*env)->GetFieldID(env, this_class, "j", "J");
+  jfieldID id_z = (*env)->GetFieldID(env, this_class, "z", "Z");
+  jfieldID id_c = (*env)->GetFieldID(env, this_class, "c", "C");
+  jfieldID id_s = (*env)->GetFieldID(env, this_class, "s", "S");
+  jfieldID id_f = (*env)->GetFieldID(env, this_class, "f", "F");
+  jfieldID id_d = (*env)->GetFieldID(env, this_class, "d", "D");
+  jfieldID id_l = (*env)->GetFieldID(env, this_class, "l", "Ljava/lang/Object;");
+  jvalue v;
+
+#define CHECK(variable, expected)                                   \
+  do {                                                              \
+    if ((variable) != (expected)) {                                 \
+      (*env)->ThrowNew(env, exception,  #variable" != " #expected); \
+      return;                                                       \
+    }                                                               \
+  } while(0)
+
+  // The values checked below must be kept in sync with the Java source file.
+
+  v.i = (*env)->GetIntField(env, self, id_i);
+  CHECK(v.i, 1);
+
+  v.j = (*env)->GetLongField(env, self, id_j);
+  CHECK(v.j, 2);
+
+  v.z = (*env)->GetBooleanField(env, self, id_z);
+  CHECK(v.z, JNI_TRUE);
+
+  v.c = (*env)->GetCharField(env, self, id_c);
+  CHECK(v.c, 'a');
+
+  v.s = (*env)->GetShortField(env, self, id_s);
+  CHECK(v.s, 3);
+
+  v.f = (*env)->GetFloatField(env, self, id_f);
+  CHECK(v.f, 1.0f);
+
+  v.d = (*env)->GetDoubleField(env, self, id_d);
+  CHECK(v.d, 2.0);
+
+#undef CHECK
+
+  v.l = (*env)->GetObjectField(env, self, id_l);
+  if (v.l == NULL) {
+    (*env)->ThrowNew(env, exception, "Object field was null");
+    return;
+  }
+  {
+    jclass clz = (*env)->GetObjectClass(env, v.l);
+    if (!(*env)->IsSameObject(env, clazz, clz)) {
+      (*env)->ThrowNew(env, exception, "Bad object class");
+    }
+  }
+
+  (*env)->DeleteWeakGlobalRef(env, self);
+}
+
+/*
+ * Class:     CallWithJNIWeak
+ * Method:    runTests
+ * Signature: (LCallWithJNIWeak;)V
+ */
+JNIEXPORT void JNICALL
+Java_CallWithJNIWeak_runTests(JNIEnv *env, jclass clazz, jobject this) {
+  jweak that = (*env)->NewWeakGlobalRef(env, this);
+  {
+    jmethodID method = (*env)->GetStaticMethodID(env,
+        clazz, "testJNIFieldAccessors", "(LCallWithJNIWeak;)V");
+    (*env)->CallStaticVoidMethod(env, clazz, method, that);
+    if ((*env)->ExceptionCheck(env)) {
+      return;
+    }
+  }
+
+  {
+    jmethodID method = (*env)->GetMethodID(env, clazz, "weakReceiverTest", "()V");
+    (*env)->CallVoidMethod(env, that, method);
+    if ((*env)->ExceptionCheck(env)) {
+      return;
+    }
+  }
+
+  {
+    jmethodID method = (*env)->GetMethodID(env, clazz, "synchonizedWeakReceiverTest", "()V");
+    (*env)->CallVoidMethod(env, that, method);
+    if ((*env)->ExceptionCheck(env)) {
+      return;
+    }
+  }
+  (*env)->DeleteWeakGlobalRef(env, that);
+}
+
+/*
+ * Class:     CallWithJNIWeak
+ * Method:    weakReceiverTest0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_CallWithJNIWeak_weakReceiverTest0(JNIEnv *env, jobject obj) {
+  (*env)->GetObjectClass(env, obj);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/jni/ReturnJNIWeak/ReturnJNIWeak.java	Wed Jul 05 23:08:24 2017 +0200
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 8166188
+ * @requires vm.opt.ExplicitGCInvokesConcurrent != true
+ * @summary Test return of JNI weak global refs from native calls.
+ * @modules java.base
+ * @run main/othervm/native -Xint ReturnJNIWeak
+ * @run main/othervm/native -Xcomp ReturnJNIWeak
+ */
+
+public final class ReturnJNIWeak {
+
+    static {
+        System.loadLibrary("ReturnJNIWeak");
+    }
+
+    private static final class TestObject {
+        public final int value;
+
+        public TestObject(int value) {
+            this.value = value;
+        }
+    }
+
+    private static volatile TestObject testObject = null;
+
+    private static native void registerObject(Object o);
+    private static native void unregisterObject();
+    private static native Object getObject();
+
+    // Create the test object and record it both strongly and weakly.
+    private static void remember(int value) {
+        TestObject o = new TestObject(value);
+        registerObject(o);
+        testObject = o;
+    }
+
+    // Remove both strong and weak references to the current test object.
+    private static void forget() {
+        unregisterObject();
+        testObject = null;
+    }
+
+    // Verify the weakly recorded object
+    private static void checkValue(int value) throws Exception {
+        Object o = getObject();
+        if (o == null) {
+            throw new RuntimeException("Weak reference unexpectedly null");
+        }
+        TestObject t = (TestObject)o;
+        if (t.value != value) {
+            throw new RuntimeException("Incorrect value");
+        }
+    }
+
+    // Verify we can create a weak reference and get it back.
+    private static void testSanity() throws Exception {
+        System.out.println("running testSanity");
+        int value = 5;
+        try {
+            remember(value);
+            checkValue(value);
+        } finally {
+            forget();
+        }
+    }
+
+    // Verify weak ref value survives across collection if strong ref exists.
+    private static void testSurvival() throws Exception {
+        System.out.println("running testSurvival");
+        int value = 10;
+        try {
+            remember(value);
+            checkValue(value);
+            System.gc();
+            // Verify weak ref still has expected value.
+            checkValue(value);
+        } finally {
+            forget();
+        }
+    }
+
+    // Verify weak ref cleared if no strong ref exists.
+    private static void testClear() throws Exception {
+        System.out.println("running testClear");
+        int value = 15;
+        try {
+          remember(value);
+          checkValue(value);
+          // Verify still good.
+          checkValue(value);
+          // Drop reference.
+          testObject = null;
+          System.gc();
+          // Verify weak ref cleared as expected.
+          Object recorded = getObject();
+          if (recorded != null) {
+            throw new RuntimeException("expected clear");
+          }
+        } finally {
+          forget();
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        testSanity();
+        testSurvival();
+        testClear();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/jni/ReturnJNIWeak/libReturnJNIWeak.c	Wed Jul 05 23:08:24 2017 +0200
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * Native support for ReturnJNIWeak test.
+ */
+
+#include "jni.h"
+
+static jweak registered = NULL;
+
+JNIEXPORT void JNICALL
+Java_ReturnJNIWeak_registerObject(JNIEnv* env,
+                                  jclass jclazz,
+                                  jobject value) {
+  // assert registered == NULL
+  registered = (*env)->NewWeakGlobalRef(env, value);
+}
+
+JNIEXPORT void JNICALL
+Java_ReturnJNIWeak_unregisterObject(JNIEnv* env, jclass jclazz) {
+  if (registered != NULL) {
+    (*env)->DeleteWeakGlobalRef(env, registered);
+    registered = NULL;
+  }
+}
+
+JNIEXPORT jobject JNICALL
+Java_ReturnJNIWeak_getObject(JNIEnv* env, jclass jclazz) {
+  // assert registered != NULL
+  return registered;
+}
--- a/hotspot/test/runtime/modules/IgnoreModulePropertiesTest.java	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/test/runtime/modules/IgnoreModulePropertiesTest.java	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,7 @@
         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
             "-D" + prop + "=" + value, "-version");
         OutputAnalyzer output = new OutputAnalyzer(pb.start());
-        output.shouldContain("java version ");
+        output.shouldContain(" version ");
         output.shouldHaveExitValue(0);
 
         // Ensure that the property and its value aren't available.
--- a/hotspot/test/serviceability/jvmti/GetNamedModule/libGetNamedModuleTest.c	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/test/serviceability/jvmti/GetNamedModule/libGetNamedModuleTest.c	Wed Jul 05 23:08:24 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -183,7 +183,7 @@
     err = (*jvmti)->GetNamedModule(jvmti, loader, pkg_name, module_ptr);
     if (err != JVMTI_ERROR_NONE) {
         printf("    Error in GetNamedModule for package \"%s\": %s (%d)\n",
-               pkg_name, TranslateError(err), err);
+               name, TranslateError(err), err);
         return err;
     }
     printf("    returned module: %p\n", *module_ptr);
--- a/hotspot/test/test_env.sh	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/test/test_env.sh	Wed Jul 05 23:08:24 2017 +0200
@@ -214,6 +214,11 @@
 then
   VM_CPU="aarch64"
 fi
+grep "arm64" vm_version.out > ${NULL}
+if [ $? = 0 ]
+then
+  VM_CPU="aarch64"
+fi
 export VM_TYPE VM_BITS VM_OS VM_CPU
 echo "VM_TYPE=${VM_TYPE}"
 echo "VM_BITS=${VM_BITS}"
--- a/hotspot/test/testlibrary_tests/ctw/CtwTest.java	Sat Apr 08 03:25:31 2017 +0000
+++ b/hotspot/test/testlibrary_tests/ctw/CtwTest.java	Wed Jul 05 23:08:24 2017 +0200
@@ -37,6 +37,7 @@
 import java.nio.file.StandardCopyOption;
 import java.nio.charset.Charset;
 
+import jdk.test.lib.Platform;
 import jdk.test.lib.JDKToolFinder;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
@@ -93,7 +94,12 @@
         // concat CTW_COMMAND and args w/o 0th element
         String[] cmd = Arrays.copyOf(CTW_COMMAND, CTW_COMMAND.length + args.length - 1);
         System.arraycopy(args, 1, cmd, CTW_COMMAND.length, args.length - 1);
-
+        if (Platform.isWindows()) {
+            // '*' has to be escaped on windows
+            for (int i = 0; i < cmd.length; ++i) {
+                cmd[i] = cmd[i].replace("*", "\"*\"");
+            }
+        }
         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmd);
         OutputAnalyzer output = new OutputAnalyzer(pb.start());
         dump(output, "compile");
--- a/make/CreateJmods.gmk	Sat Apr 08 03:25:31 2017 +0000
+++ b/make/CreateJmods.gmk	Wed Jul 05 23:08:24 2017 +0200
@@ -135,9 +135,8 @@
 	$(RM) $@ $(JMODS_TEMPDIR)/$(notdir $@)
 	$(JMOD) create \
             --module-version $(VERSION_SHORT) \
-            --os-name $(REQUIRED_OS_NAME) \
-            --os-arch $(OPENJDK_TARGET_CPU_LEGACY) \
-            --os-version $(REQUIRED_OS_VERSION) \
+            --os-name '$(REQUIRED_OS_NAME)' \
+            --os-arch '$(REQUIRED_OS_ARCH)' \
             --module-path $(JMODS_DIR) \
 	    --exclude '**{_the.*,_*.marker,*.diz,*.debuginfo,*.dSYM/**,*.dSYM,*.pdb,*.map}' \
 	    $(JMOD_FLAGS) $(JMODS_TEMPDIR)/$(notdir $@)
--- a/make/Images.gmk	Sat Apr 08 03:25:31 2017 +0000
+++ b/make/Images.gmk	Wed Jul 05 23:08:24 2017 +0200
@@ -119,6 +119,7 @@
     --module-path $(IMAGES_OUTPUTDIR)/jmods \
     --endian $(OPENJDK_BUILD_CPU_ENDIAN) \
     --release-info $(BASE_RELEASE_FILE) \
+    --release-info add:OS_VERSION=\"$(REQUIRED_OS_VERSION)\" \
     --order-resources=$(call CommaList, $(JLINK_ORDER_RESOURCES)) \
     --dedup-legal-notices=error-if-not-same-content \
     $(JLINK_JLI_CLASSES) \
--- a/make/Init.gmk	Sat Apr 08 03:25:31 2017 +0000
+++ b/make/Init.gmk	Wed Jul 05 23:08:24 2017 +0200
@@ -117,7 +117,7 @@
     # Check that CONF_CHECK is valid.
     $(eval $(call ParseConfCheckOption))
 
-    # Check that the LOG given is valid, and set LOG_LEVEL, LOG_NOFILE and MAKE_LOG_FLAGS.
+    # Check that the LOG given is valid, and set LOG_LEVEL, LOG_NOFILE, MAKE_LOG_VARS and MAKE_LOG_FLAGS.
     $(eval $(call ParseLogLevel))
 
     # After this SPECS contain 1..N spec files (otherwise ParseConfAndSpec fails).
@@ -171,7 +171,7 @@
 
     MAKE_INIT_WITH_SPEC_ARGUMENTS := ACTUAL_TOPDIR=$(topdir) \
         USER_MAKE_VARS="$(USER_MAKE_VARS)" MAKE_LOG_FLAGS=$(MAKE_LOG_FLAGS) \
-        LOG_LEVEL=$(LOG_LEVEL) LOG_NOFILE=$(LOG_NOFILE) LOG_CMDLINES=$(LOG_CMDLINES) \
+        $(MAKE_LOG_VARS) \
         INIT_TARGETS="$(INIT_TARGETS)" \
         SEQUENTIAL_TARGETS="$(SEQUENTIAL_TARGETS)" \
         PARALLEL_TARGETS="$(PARALLEL_TARGETS)"
@@ -319,6 +319,7 @@
 	    exit 1 ; \
 	  fi
 	  $(PRINTF) "Finished building $(TARGET_DESCRIPTION)\n" $(BUILD_LOG_PIPE)
+	  $(call ReportProfileTimes)
         endif
 
     on-failure:
@@ -327,6 +328,7 @@
 	$(call ReportBuildTimes)
 	$(call PrintFailureReports)
 	$(call PrintBuildLogFailures)
+	$(call ReportProfileTimes)
 	$(PRINTF) "Hint: If caused by a warning, try configure --disable-warnings-as-errors.\n\n"
         ifneq ($(COMPARE_BUILD), )
 	  $(call CleanupCompareBuild)
--- a/make/InitSupport.gmk	Sat Apr 08 03:25:31 2017 +0000
+++ b/make/InitSupport.gmk	Wed Jul 05 23:08:24 2017 +0200
@@ -158,6 +158,18 @@
     # If the "cmdline" argument is given, act on it and strip it away
     $$(eval $$(call ParseLogOption, cmdlines, LOG_CMDLINES))
 
+    # If the "profile-to-log" argument is given, write shell times in build log
+    $$(eval $$(call ParseLogOption, profile-to-log, LOG_PROFILE_TIMES_LOG))
+
+    # If the "profile" argument is given, write shell times in separate log file
+    # IMPORTANT: $(ParseLogOption profile-to-log) should go first. Otherwise
+    # parsing of 'LOG=debug,profile-to-log,nofile' ends up in the following error:
+    # Error: LOG contains unknown option or log level: debug-to-log.
+    $$(eval $$(call ParseLogOption, profile, LOG_PROFILE_TIMES_FILE))
+
+    # Treat LOG=profile-to-log as if it were LOG=profile,profile-to-log
+    LOG_PROFILE_TIMES_FILE := $$(firstword $$(LOG_PROFILE_TIMES_FILE) $$(LOG_PROFILE_TIMES_LOG))
+
     LOG_LEVEL := $$(LOG)
 
     ifeq ($$(LOG_LEVEL),)
@@ -175,7 +187,7 @@
       MAKE_LOG_FLAGS :=
     else
       $$(info Error: LOG contains unknown option or log level: $$(LOG).)
-      $$(info LOG can be <level>[,<opt>[...]] where <opt> is nofile | cmdlines)
+      $$(info LOG can be <level>[,<opt>[...]] where <opt> is nofile | cmdlines | profile | profile-to-log)
       $$(info and <level> is warn | info | debug | trace)
       $$(error Cannot continue)
     endif
@@ -309,7 +321,7 @@
 	@( cd $$(topdir) && \
 	$$(MAKE) $$(MAKE_LOG_FLAGS) -r -R -f $$(topdir)/make/Main.gmk \
 	    -I $$(topdir)/make/common SPEC=$(strip $2) NO_RECIPES=true \
-	    LOG_LEVEL=$$(LOG_LEVEL) \
+	    $$(MAKE_LOG_VARS) \
 	    create-main-targets-include )
 
     # Now include main-targets.gmk. This will define ALL_MAIN_TARGETS.
@@ -334,7 +346,7 @@
 
   # Define basic logging setup
   BUILD_LOG := $(OUTPUT_ROOT)/build.log
-  BUILD_TRACE_LOG := $(OUTPUT_ROOT)/build-trace-time.log
+  BUILD_PROFILE_LOG := $(OUTPUT_ROOT)/build-profile.log
 
   BUILD_LOG_PIPE := > >($(TEE) -a $(BUILD_LOG)) 2> >($(TEE) -a $(BUILD_LOG) >&2) && wait
 
@@ -494,9 +506,9 @@
   define RotateLogFiles
 	$(RM) $(BUILD_LOG).old 2> /dev/null && \
 	$(MV) $(BUILD_LOG) $(BUILD_LOG).old 2> /dev/null || true
-	$(if $(findstring trace, $(LOG_LEVEL)), \
-	  $(RM) $(BUILD_TRACE_LOG).old 2> /dev/null && \
-	  $(MV) $(BUILD_TRACE_LOG) $(BUILD_TRACE_LOG).old 2> /dev/null || true \
+	$(if $(findstring true, $(LOG_PROFILE_TIMES_FILE)), \
+	  $(RM) $(BUILD_PROFILE_LOG).old 2> /dev/null && \
+	  $(MV) $(BUILD_PROFILE_LOG) $(BUILD_PROFILE_LOG).old 2> /dev/null || true \
 	)
   endef
 
@@ -558,6 +570,22 @@
 	    $(BUILD_LOG_PIPE)
   endef
 
+  define ReportProfileTimes
+    $(if $(findstring true, $(LOG_PROFILE_TIMES_LOG)), \
+      [ ! -f $(BUILD_PROFILE_LOG) ] || \
+      { $(ECHO) Begin $(notdir $(BUILD_PROFILE_LOG)) && \
+        $(CAT) $(BUILD_PROFILE_LOG) && \
+        $(ECHO) End $(notdir $(BUILD_PROFILE_LOG)); \
+      } \
+      $(BUILD_LOG_PIPE)
+    )
+  endef
+
 endif # HAS_SPEC
 
+MAKE_LOG_VARS = $(foreach v, \
+    LOG_LEVEL LOG_NOFILE LOG_CMDLINES LOG_PROFILE_TIMES_LOG LOG_PROFILE_TIMES_FILE, \
+    $v=$($v) \
+)
+
 endif # _INITSUPPORT_GMK
--- a/make/Javadoc.gmk	Sat Apr 08 03:25:31 2017 +0000
+++ b/make/Javadoc.gmk	Wed Jul 05 23:08:24 2017 +0200
@@ -27,6 +27,7 @@
 include $(SPEC)
 include MakeBase.gmk
 include $(JDK_TOPDIR)/make/Tools.gmk
+include $(JDK_TOPDIR)/make/ModuleTools.gmk
 
 ################################################################################
 
@@ -174,6 +175,7 @@
     -tag param \
     -tag return \
     -tag throws \
+    -taglet build.tools.taglet.ModuleGraph \
     -tag since \
     -tag version \
     -tag serialData \
@@ -188,6 +190,13 @@
 DEFAULT_JAVADOC_OPTIONS := -XDignore.symbol.file=true -use -keywords -notimestamp \
     -serialwarn -encoding ISO-8859-1 -breakiterator --system none
 
+#
+# TODO: this should be set by the configure option.
+#
+ifndef ENABLE_MODULE_GRAPH
+   ENABLE_MODULE_GRAPH=false
+endif
+
 ################################################################################
 # Setup make rules for running javadoc.
 #
@@ -321,7 +330,8 @@
 	  $$(eval $$(call ListPathsSafely, $1_PACKAGES, $$($1_PACKAGES_FILE)))
         endif
 	$$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/docs/$1.javadoc, \
-	    $$($1_JAVA) -Djava.awt.headless=true $(NEW_JAVADOC) -d $$(@D) \
+	    $$($1_JAVA) -Djava.awt.headless=true -DenableModuleGraph=$(ENABLE_MODULE_GRAPH) \
+		$(NEW_JAVADOC) -d $$(@D) \
 	        $$(DEFAULT_JAVADOC_TAGS) $$(DEFAULT_JAVADOC_OPTIONS) \
 	        --module-source-path $$(call PathList, $$(JAVADOC_SOURCE_DIRS)) \
 	        $$($1_OPTIONS) $$($1_PACKAGES_ARG))
@@ -735,18 +745,34 @@
 ZIP_TARGETS += $(JAVADOC_ARCHIVE)
 
 ################################################################################
+# generate .dot files for module graphs
+
+JAVADOC_MODULE_GRAPHS_DIR := $(SUPPORT_OUTPUTDIR)/docs/module-graphs
+JAVADOC_MODULE_GRAPHS := $(JAVADOC_MODULE_GRAPHS_DIR)/java.se.dot
+JAVADOC_MODULE_GRAPHS_PROPS := $(JDK_TOPDIR)/make/src/classes/build/tools/jigsaw/javadoc-graphs.properties
+
+$(JAVADOC_MODULE_GRAPHS): $(BUILD_JIGSAW_TOOLS) $(JAVADOC_MODULE_GRAPHS_PROPS)
+	$(MKDIR) -p $(@D)
+	$(TOOL_GENGRAPHS) --spec --output $(JAVADOC_MODULE_GRAPHS_DIR) \
+	    --dot-attributes $(JAVADOC_MODULE_GRAPHS_PROPS)
+
+MODULE_GRAPH_TARGETS += $(JAVADOC_MODULE_GRAPHS)
+
+################################################################################
 
 # Hook to include the corresponding custom file, if present.
 $(eval $(call IncludeCustomExtension, , Javadoc.gmk))
 
 ################################################################################
 
+docs-module-graphs: $(MODULE_GRAPH_TARGETS) 
+
 docs-javadoc: $(TARGETS)
 
 docs-copy: $(COPY_TARGETS)
 
 docs-zip: $(ZIP_TARGETS)
 
-all: docs-javadoc docs-copy docs-zip
+all: docs-module-graphs docs-javadoc docs-copy docs-zip
 
-.PHONY: default all docs-javadoc docs-copy docs-zip
+.PHONY: default all docs-module-graphs docs-javadoc docs-copy docs-zip
--- a/make/Main.gmk	Sat Apr 08 03:25:31 2017 +0000
+++ b/make/Main.gmk	Wed Jul 05 23:08:24 2017 +0200
@@ -363,6 +363,9 @@
 ################################################################################
 # Docs targets
 
+docs-module-graphs:
+	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f Javadoc.gmk docs-module-graphs)
+
 docs-javadoc:
 	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f Javadoc.gmk docs-javadoc)
 
@@ -375,7 +378,7 @@
 update-build-docs:
 	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f UpdateBuildDocs.gmk)
 
-ALL_TARGETS += docs-javadoc docs-copy docs-zip update-build-docs
+ALL_TARGETS += docs-module-graphs docs-javadoc docs-copy docs-zip update-build-docs
 
 ################################################################################
 # Cross compilation support
@@ -772,6 +775,8 @@
 
   bootcycle-images: jdk-image
 
+  docs-module-graphs: exploded-image buildtools-modules 
+
   docs-javadoc: $(GENSRC_TARGETS) rmic
 
   # The gensrc step for jdk.jdi creates an html file that is used by docs-copy.
@@ -929,7 +934,7 @@
 endif
 
 # This target builds the documentation image
-docs-image: docs-javadoc docs-copy
+docs-image: docs-module-graphs docs-javadoc docs-copy
 
 # This target builds the test image
 test-image: prepare-test-image test-image-hotspot-jtreg-native \
--- a/make/common/MakeBase.gmk	Sat Apr 08 03:25:31 2017 +0000
+++ b/make/common/MakeBase.gmk	Wed Jul 05 23:08:24 2017 +0200
@@ -355,17 +355,28 @@
 ################################################################################
 
 define SetupLogging
+  ifeq ($$(LOG_PROFILE_TIMES_FILE), true)
+    ifeq ($$(IS_GNU_TIME), yes)
+      SHELL :=  $$(BASH) $$(SRC_ROOT)/common/bin/shell-profiler.sh \
+                gnutime $$(TIME) \
+                $$(OUTPUT_ROOT)/build-profile.log $$(SHELL)
+    else ifneq ($$(FLOCK), )
+      SHELL :=  $$(BASH) $$(SRC_ROOT)/common/bin/shell-profiler.sh \
+                flock $$(FLOCK) \
+                $$(OUTPUT_ROOT)/build-profile.log $$(SHELL)
+    endif
+  endif
+
   ifeq ($$(LOG_LEVEL), trace)
+    SHELL_NO_RECURSE := $$(SHELL)
     # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
     # For each target executed, will print
     # Building <TARGET> (from <FIRST PREREQUISITE>) (<ALL NEWER PREREQUISITES> newer)
     # but with a limit of 20 on <ALL NEWER PREREQUISITES>, to avoid cluttering logs too much
     # (and causing a crash on Cygwin).
-    # Default shell seems to always be /bin/sh. Must override with bash to get this to work on Solaris.
-    # Only use time if it's GNU time which supports format and output file.
-    WRAPPER_SHELL := $$(BASH) $$(SRC_ROOT)/common/bin/shell-tracer.sh $$(if $$(findstring yes,$$(IS_GNU_TIME)),$$(TIME),-) $$(OUTPUT_ROOT)/build-trace-time.log $$(SHELL)
-    SHELL = $$(warning $$(if $$@,Building $$@,Running shell command) $$(if $$<, (from $$<))$$(if $$?, ($$(wordlist 1, 20, $$?) $$(if $$(wordlist 21, 22, $$?), ... [in total $$(words $$?) files]) newer)))$$(WRAPPER_SHELL)
+    SHELL = $$(warning $$(if $$@,Building $$@,Running shell command) $$(if $$<, (from $$<))$$(if $$?, ($$(wordlist 1, 20, $$?) $$(if $$(wordlist 21, 22, $$?), ... [in total $$(words $$?) files]) newer)))$$(SHELL_NO_RECURSE) -x
   endif
+
   # The warn level can never be turned off
   LogWarn = $$(info $$(strip $$1))
   LOG_WARN :=