Merge
authorsspitsyn
Sat, 21 Oct 2017 00:06:50 +0000
changeset 47670 80267ddfdcfa
parent 47669 e362049c1cb8 (current diff)
parent 47668 fc4cfca10556 (diff)
child 47672 50aa24ce898c
Merge
make/corba/Makefile
src/hotspot/os/windows/decoder_windows.hpp
src/hotspot/share/code/jvmticmlr.h
src/hotspot/share/gc/g1/suspendibleThreadSet.cpp
src/hotspot/share/gc/g1/suspendibleThreadSet.hpp
src/hotspot/share/prims/jni.h
--- a/.hgtags	Sat Oct 21 07:00:23 2017 +0900
+++ b/.hgtags	Sat Oct 21 00:06:50 2017 +0000
@@ -450,3 +450,5 @@
 22850b3a55240253841b9a425ad60a7fcdb22d47 jdk-10+23
 3b201865d5c1f244f555cad58da599c9261286d8 jdk-10+24
 8eb5e3ccee560c28ac9b1df2670adac2b3d36fad jdk-10+25
+1129253d3bc728a2963ba411ab9dd1adf358fb6b jdk-10+26
+b87d7b5d5dedc1185e5929470f945b7378cdb3ad jdk-10+27
--- a/bin/jib.sh	Sat Oct 21 07:00:23 2017 +0900
+++ b/bin/jib.sh	Sat Oct 21 00:06:50 2017 +0000
@@ -39,7 +39,7 @@
     jib_repository="jdk-virtual"
     jib_organization="jpg/infra/builddeps"
     jib_module="jib"
-    jib_revision="2.0-SNAPSHOT"
+    jib_revision="3.0-SNAPSHOT"
     jib_ext="jib.sh.gz"
 
     closed_script="${mydir}/../../closed/make/conf/jib-install.conf"
@@ -146,4 +146,9 @@
     install_jib
 fi
 
+# Provide a reasonable default for the --src-dir parameter if run out of tree
+if [ -z "${JIB_SRC_DIR}" ]; then
+    export JIB_SRC_DIR="${mydir}/../"
+fi
+
 ${installed_jib_script} "$@"
--- a/make/Bundles.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/Bundles.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -70,9 +70,14 @@
   $$(call SetIfEmpty, $1_UNZIP_DEBUGINFO, false)
 
   $(BUNDLES_OUTPUTDIR)/$$($1_BUNDLE_NAME): $$($1_FILES)
+        # If any of the files contain a space in the file name, CacheFind
+        # will have replaced it with ?. Tar does not accept that so need to
+        # switch it back.
 	$$(foreach d, $$($1_BASE_DIRS), \
 	  $$(eval $$(call ListPathsSafely, \
 	      $1_$$d_RELATIVE_FILES, $$($1_$$d_LIST_FILE))) \
+	  $$(CAT) $$($1_$$d_LIST_FILE) | $$(TR) '?' ' ' > $$($1_$$d_LIST_FILE).tmp \
+	      && $(MV) $$($1_$$d_LIST_FILE).tmp $$($1_$$d_LIST_FILE) $$(NEWLINE) \
 	)
 	$$(call MakeDir, $$(@D))
         ifneq ($$($1_SPECIAL_INCLUDES), )
--- a/make/CompileDemos.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/CompileDemos.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -37,9 +37,13 @@
 include TextFileProcessing.gmk
 include ZipArchive.gmk
 
+# Hook to include the corresponding custom file, if present.
+$(eval $(call IncludeCustomExtension, CompileDemos-pre.gmk))
+
 # Prepare the find cache.
-$(eval $(call FillCacheFind, $(wildcard $(TOPDIR)/src/demo \
-    $(TOPDIR)/src/*/demo)))
+DEMO_SRC_DIRS += $(TOPDIR)/src/demo
+
+$(eval $(call FillCacheFind, $(wildcard $(DEMO_SRC_DIRS))))
 
 # Append demo goals to this variable.
 TARGETS =
@@ -303,7 +307,7 @@
 
 ################################################################################
 # Hook to include the corresponding custom file, if present.
-$(eval $(call IncludeCustomExtension, CompileDemos.gmk))
+$(eval $(call IncludeCustomExtension, CompileDemos-post.gmk))
 
 all: $(TARGETS)
 images: $(IMAGES_TARGETS)
--- a/make/Init.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/Init.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -267,8 +267,9 @@
 	  $(ECHO) "Re-running configure using default settings"
         endif
 	( cd $(OUTPUTDIR) && PATH="$(ORIGINAL_PATH)" \
+	    CUSTOM_ROOT="$(CUSTOM_ROOT)" \
 	    CUSTOM_CONFIG_DIR="$(CUSTOM_CONFIG_DIR)" \
-	    $(BASH) $(CONFIGURE_CMD) $(CONFIGURE_COMMAND_LINE) )
+	    $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE) )
 
   ##############################################################################
   # The main target, for delegating into Main.gmk
--- a/make/InitSupport.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/InitSupport.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -70,10 +70,10 @@
       $(subst \ ,\#,$(MAKEOVERRIDES))))
 
   # Setup information about available configurations, if any.
-  ifeq ($(CUSTOM_BUILD_DIR), )
+  ifneq ($(CUSTOM_ROOT), )
+    build_dir=$(CUSTOM_ROOT)/build
+  else
     build_dir=$(topdir)/build
-  else
-    build_dir=$(CUSTOM_BUILD_DIR)
   endif
   all_spec_files=$(wildcard $(build_dir)/*/spec.gmk)
   # Extract the configuration names from the path
@@ -227,7 +227,11 @@
     else
       # Use spec.gmk files in the build output directory
       ifeq ($$(all_spec_files),)
-        $$(info Error: No configurations found for $$(topdir).)
+        ifneq ($(CUSTOM_ROOT), )
+          $$(info Error: No configurations found for $$(CUSTOM_ROOT).)
+        else
+          $$(info Error: No configurations found for $$(topdir).)
+        endif
         $$(info Please run 'bash configure' to create a configuration.)
         $$(info )
         $$(error Cannot continue)
--- a/make/MacBundles.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/MacBundles.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -49,22 +49,17 @@
     BUNDLE_VENDOR := $(COMPANY_NAME)
   endif
 
-  JDK_FILE_LIST := $(shell $(FIND) $(JDK_IMAGE_DIR))
-  JRE_FILE_LIST := $(shell $(FIND) $(JRE_IMAGE_DIR))
-
-  JDK_TARGET_LIST := $(subst $(JDK_IMAGE_DIR)/,$(JDK_MACOSX_CONTENTS_DIR)/Home/,$(JDK_FILE_LIST))
-  JRE_TARGET_LIST := $(subst $(JRE_IMAGE_DIR)/,$(JRE_MACOSX_CONTENTS_DIR)/Home/,$(JRE_FILE_LIST))
+  $(eval $(call SetupCopyFiles, COPY_JDK_IMAGE, \
+      SRC := $(JDK_IMAGE_DIR), \
+      DEST := $(JDK_MACOSX_CONTENTS_DIR)/Home, \
+      FILES := $(call CacheFind, $(JDK_IMAGE_DIR)), \
+  ))
 
-  # Copy empty directories (jre/lib/applet).
-  $(JDK_MACOSX_CONTENTS_DIR)/Home/%: $(JDK_IMAGE_DIR)/%
-	$(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
-	$(MKDIR) -p $(@D)
-	if [ -d "$<" ]; then $(MKDIR) -p $@; else $(CP) -f -R -P '$<' '$@'; fi
-
-  $(JRE_MACOSX_CONTENTS_DIR)/Home/%: $(JRE_IMAGE_DIR)/%
-	$(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
-	$(MKDIR) -p $(@D)
-	if [ -d "$<" ]; then $(MKDIR) -p $@; else $(CP) -f -R -P '$<' '$@'; fi
+  $(eval $(call SetupCopyFiles, COPY_JRE_IMAGE, \
+      SRC := $(JRE_IMAGE_DIR), \
+      DEST := $(JRE_MACOSX_CONTENTS_DIR)/Home, \
+      FILES := $(call CacheFind, $(JRE_IMAGE_DIR)), \
+  ))
 
   $(JDK_MACOSX_CONTENTS_DIR)/MacOS/libjli.dylib:
 	$(call LogInfo, Creating link $(patsubst $(OUTPUTDIR)/%,%,$@))
@@ -102,11 +97,11 @@
           @@VENDOR@@ => $(BUNDLE_VENDOR) , \
   ))
 
-  jdk-bundle: $(JDK_TARGET_LIST) $(JDK_MACOSX_CONTENTS_DIR)/MacOS/libjli.dylib \
+  jdk-bundle: $(COPY_JDK_IMAGE) $(JDK_MACOSX_CONTENTS_DIR)/MacOS/libjli.dylib \
       $(BUILD_JDK_PLIST)
 	$(SETFILE) -a B $(dir $(JDK_MACOSX_CONTENTS_DIR))
 
-  jre-bundle: $(JRE_TARGET_LIST) $(JRE_MACOSX_CONTENTS_DIR)/MacOS/libjli.dylib \
+  jre-bundle: $(COPY_JRE_IMAGE) $(JRE_MACOSX_CONTENTS_DIR)/MacOS/libjli.dylib \
       $(BUILD_JRE_PLIST)
 	$(SETFILE) -a B $(dir $(JRE_MACOSX_CONTENTS_DIR))
 
--- a/make/RunTests.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/RunTests.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -351,6 +351,9 @@
 
   $1_JTREG_BASIC_OPTIONS += -automatic -keywords:\!ignore -ignore:quiet
 
+  # Make it possible to specify the JIB_DATA_DIR for tests using the
+  # JIB Artifact resolver
+  $1_JTREG_BASIC_OPTIONS += -e:JIB_DATA_DIR
   # Some tests needs to find a boot JDK using the JDK8_HOME variable.
   $1_JTREG_BASIC_OPTIONS += -e:JDK8_HOME=$$(BOOT_JDK)
 
--- a/make/autoconf/basics.m4	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/autoconf/basics.m4	Sat Oct 21 00:06:50 2017 +0000
@@ -766,13 +766,10 @@
   AC_ARG_WITH(conf-name, [AS_HELP_STRING([--with-conf-name],
       [use this as the name of the configuration @<:@generated from important configuration options@:>@])],
       [ CONF_NAME=${with_conf_name} ])
-  AC_ARG_WITH(output-base-dir, [AS_HELP_STRING([--with-output-base-dir],
-      [override the default output base directory @<:@./build@:>@])],
-      [ OUTPUT_BASE=${with_output_base_dir} ], [ OUTPUT_BASE="$TOPDIR/build" ] )
 
   # Test from where we are running configure, in or outside of src root.
   AC_MSG_CHECKING([where to store configuration])
-  if test "x$CURDIR" = "x$TOPDIR" || test "x$CURDIR" = "x$TOPDIR/common" \
+  if test "x$CURDIR" = "x$TOPDIR" || test "x$CURDIR" = "x$CUSTOM_ROOT" \
       || test "x$CURDIR" = "x$TOPDIR/make/autoconf" \
       || test "x$CURDIR" = "x$TOPDIR/make" ; then
     # We are running configure from the src root.
@@ -783,7 +780,12 @@
     else
       AC_MSG_RESULT([in build directory with custom name])
     fi
-    OUTPUTDIR="${OUTPUT_BASE}/${CONF_NAME}"
+
+    if test "x$CUSTOM_ROOT" != x; then
+      OUTPUTDIR="${CUSTOM_ROOT}/build/${CONF_NAME}"
+    else
+      OUTPUTDIR="${TOPDIR}/build/${CONF_NAME}"
+    fi
     $MKDIR -p "$OUTPUTDIR"
     if test ! -d "$OUTPUTDIR"; then
       AC_MSG_ERROR([Could not create build directory $OUTPUTDIR])
--- a/make/autoconf/boot-jdk.m4	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/autoconf/boot-jdk.m4	Sat Oct 21 00:06:50 2017 +0000
@@ -325,6 +325,27 @@
   fi
   AC_MSG_CHECKING([if Boot JDK is 32 or 64 bits])
   AC_MSG_RESULT([$BOOT_JDK_BITS])
+
+  # Try to enable CDS
+  AC_MSG_CHECKING([for local Boot JDK Class Data Sharing (CDS)])
+  BOOT_JDK_CDS_ARCHIVE=$CONFIGURESUPPORT_OUTPUTDIR/classes.jsa
+  ADD_JVM_ARG_IF_OK([-XX:+UnlockDiagnosticVMOptions -XX:-VerifySharedSpaces -XX:SharedArchiveFile=$BOOT_JDK_CDS_ARCHIVE],boot_jdk_cds_args,[$JAVA])
+
+  if test "x$boot_jdk_cds_args" != x; then
+    # Try creating a CDS archive
+    "$JAVA" $boot_jdk_cds_args -Xshare:dump > /dev/null 2>&1
+    if test $? -eq 0; then
+      BOOTJDK_USE_LOCAL_CDS=true
+      AC_MSG_RESULT([yes, created])
+    else
+      # Generation failed, don't use CDS.
+      BOOTJDK_USE_LOCAL_CDS=false
+      AC_MSG_RESULT([no, creation failed])
+    fi
+  else
+    BOOTJDK_USE_LOCAL_CDS=false
+    AC_MSG_RESULT([no, -XX:SharedArchiveFile not supported])
+  fi
 ])
 
 AC_DEFUN_ONCE([BOOTJDK_SETUP_BOOT_JDK_ARGUMENTS],
@@ -346,6 +367,14 @@
   # Force en-US environment
   ADD_JVM_ARG_IF_OK([-Duser.language=en -Duser.country=US],boot_jdk_jvmargs,[$JAVA])
 
+  if test "x$BOOTJDK_USE_LOCAL_CDS" = xtrue; then
+    # Use our own CDS archive
+    ADD_JVM_ARG_IF_OK([$boot_jdk_cds_args -Xshare:auto],boot_jdk_jvmargs,[$JAVA])
+  else
+    # Otherwise optimistically use the system-wide one, if one is present
+    ADD_JVM_ARG_IF_OK([-Xshare:auto],boot_jdk_jvmargs,[$JAVA])
+  fi
+
   # Apply user provided options.
   ADD_JVM_ARG_IF_OK([$with_boot_jdk_jvmargs],boot_jdk_jvmargs,[$JAVA])
 
@@ -355,7 +384,6 @@
   JAVA_FLAGS=$boot_jdk_jvmargs
   AC_SUBST(JAVA_FLAGS)
 
-
   AC_MSG_CHECKING([flags for boot jdk java command for big workloads])
 
   # Starting amount of heap memory.
--- a/make/autoconf/configure	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/autoconf/configure	Sat Oct 21 00:06:50 2017 +0000
@@ -23,19 +23,18 @@
 #
 
 if test "x$1" != xCHECKME; then
-  echo "WARNING: Calling the wrapper script directly is deprecated and unsupported."
-  echo "Not all features of configure will be available."
+  echo "ERROR: Calling this wrapper script directly is not supported."
   echo "Use the 'configure' script in the top-level directory instead."
-  TOPDIR=$(cd $(dirname $0)/../.. > /dev/null && pwd)
-else
-  # Now the next argument is the absolute top-level directory path.
-  # The TOPDIR variable is passed on to configure.ac.
-  TOPDIR="$2"
-  # Remove these two arguments to get to the user supplied arguments
-  shift
-  shift
+  exit 1
 fi
 
+# The next argument is the absolute top-level directory path.
+# The TOPDIR variable is passed on to configure.ac.
+TOPDIR="$2"
+# Remove these two arguments to get to the user supplied arguments
+shift
+shift
+
 if test "x$BASH" = x; then
   echo "Error: This script must be run using bash." 1>&2
   exit 1
--- a/make/autoconf/generated-configure.sh	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/autoconf/generated-configure.sh	Sat Oct 21 00:06:50 2017 +0000
@@ -1134,7 +1134,6 @@
 with_extra_path
 with_sdk_name
 with_conf_name
-with_output_base_dir
 with_output_sync
 with_default_make_target
 enable_headless_only
@@ -2043,7 +2042,6 @@
   --with-sdk-name         use the platform SDK of the given name. [macosx]
   --with-conf-name        use this as the name of the configuration [generated
                           from important configuration options]
-  --with-output-base-dir  override the default output base directory [./build]
   --with-output-sync      set make output sync type if supported by make.
                           [recurse]
   --with-default-make-target
@@ -5117,7 +5115,7 @@
 #CUSTOM_AUTOCONF_INCLUDE
 
 # Do not change or remove the following line, it is needed for consistency checks:
-DATE_WHEN_GENERATED=1506397140
+DATE_WHEN_GENERATED=1508136203
 
 ###############################################################################
 #
@@ -17554,18 +17552,10 @@
 fi
 
 
-# Check whether --with-output-base-dir was given.
-if test "${with_output_base_dir+set}" = set; then :
-  withval=$with_output_base_dir;  OUTPUT_BASE=${with_output_base_dir}
-else
-   OUTPUT_BASE="$TOPDIR/build"
-fi
-
-
   # Test from where we are running configure, in or outside of src root.
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking where to store configuration" >&5
 $as_echo_n "checking where to store configuration... " >&6; }
-  if test "x$CURDIR" = "x$TOPDIR" || test "x$CURDIR" = "x$TOPDIR/common" \
+  if test "x$CURDIR" = "x$TOPDIR" || test "x$CURDIR" = "x$CUSTOM_ROOT" \
       || test "x$CURDIR" = "x$TOPDIR/make/autoconf" \
       || test "x$CURDIR" = "x$TOPDIR/make" ; then
     # We are running configure from the src root.
@@ -17578,7 +17568,12 @@
       { $as_echo "$as_me:${as_lineno-$LINENO}: result: in build directory with custom name" >&5
 $as_echo "in build directory with custom name" >&6; }
     fi
-    OUTPUTDIR="${OUTPUT_BASE}/${CONF_NAME}"
+
+    if test "x$CUSTOM_ROOT" != x; then
+      OUTPUTDIR="${CUSTOM_ROOT}/build/${CONF_NAME}"
+    else
+      OUTPUTDIR="${TOPDIR}/build/${CONF_NAME}"
+    fi
     $MKDIR -p "$OUTPUTDIR"
     if test ! -d "$OUTPUTDIR"; then
       as_fn_error $? "Could not create build directory $OUTPUTDIR" "$LINENO" 5
@@ -31483,6 +31478,45 @@
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $BOOT_JDK_BITS" >&5
 $as_echo "$BOOT_JDK_BITS" >&6; }
 
+  # Try to enable CDS
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for local Boot JDK Class Data Sharing (CDS)" >&5
+$as_echo_n "checking for local Boot JDK Class Data Sharing (CDS)... " >&6; }
+  BOOT_JDK_CDS_ARCHIVE=$CONFIGURESUPPORT_OUTPUTDIR/classes.jsa
+
+  $ECHO "Check if jvm arg is ok: -XX:+UnlockDiagnosticVMOptions -XX:-VerifySharedSpaces -XX:SharedArchiveFile=$BOOT_JDK_CDS_ARCHIVE" >&5
+  $ECHO "Command: $JAVA -XX:+UnlockDiagnosticVMOptions -XX:-VerifySharedSpaces -XX:SharedArchiveFile=$BOOT_JDK_CDS_ARCHIVE -version" >&5
+  OUTPUT=`$JAVA -XX:+UnlockDiagnosticVMOptions -XX:-VerifySharedSpaces -XX:SharedArchiveFile=$BOOT_JDK_CDS_ARCHIVE -version 2>&1`
+  FOUND_WARN=`$ECHO "$OUTPUT" | $GREP -i warn`
+  FOUND_VERSION=`$ECHO $OUTPUT | $GREP " version \""`
+  if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then
+    boot_jdk_cds_args="$boot_jdk_cds_args -XX:+UnlockDiagnosticVMOptions -XX:-VerifySharedSpaces -XX:SharedArchiveFile=$BOOT_JDK_CDS_ARCHIVE"
+    JVM_ARG_OK=true
+  else
+    $ECHO "Arg failed:" >&5
+    $ECHO "$OUTPUT" >&5
+    JVM_ARG_OK=false
+  fi
+
+
+  if test "x$boot_jdk_cds_args" != x; then
+    # Try creating a CDS archive
+    "$JAVA" $boot_jdk_cds_args -Xshare:dump > /dev/null 2>&1
+    if test $? -eq 0; then
+      BOOTJDK_USE_LOCAL_CDS=true
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, created" >&5
+$as_echo "yes, created" >&6; }
+    else
+      # Generation failed, don't use CDS.
+      BOOTJDK_USE_LOCAL_CDS=false
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, creation failed" >&5
+$as_echo "no, creation failed" >&6; }
+    fi
+  else
+    BOOTJDK_USE_LOCAL_CDS=false
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, -XX:SharedArchiveFile not supported" >&5
+$as_echo "no, -XX:SharedArchiveFile not supported" >&6; }
+  fi
+
 
 
 # Check whether --with-build-jdk was given.
@@ -66232,6 +66266,42 @@
   fi
 
 
+  if test "x$BOOTJDK_USE_LOCAL_CDS" = xtrue; then
+    # Use our own CDS archive
+
+  $ECHO "Check if jvm arg is ok: $boot_jdk_cds_args -Xshare:auto" >&5
+  $ECHO "Command: $JAVA $boot_jdk_cds_args -Xshare:auto -version" >&5
+  OUTPUT=`$JAVA $boot_jdk_cds_args -Xshare:auto -version 2>&1`
+  FOUND_WARN=`$ECHO "$OUTPUT" | $GREP -i warn`
+  FOUND_VERSION=`$ECHO $OUTPUT | $GREP " version \""`
+  if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then
+    boot_jdk_jvmargs="$boot_jdk_jvmargs $boot_jdk_cds_args -Xshare:auto"
+    JVM_ARG_OK=true
+  else
+    $ECHO "Arg failed:" >&5
+    $ECHO "$OUTPUT" >&5
+    JVM_ARG_OK=false
+  fi
+
+  else
+    # Otherwise optimistically use the system-wide one, if one is present
+
+  $ECHO "Check if jvm arg is ok: -Xshare:auto" >&5
+  $ECHO "Command: $JAVA -Xshare:auto -version" >&5
+  OUTPUT=`$JAVA -Xshare:auto -version 2>&1`
+  FOUND_WARN=`$ECHO "$OUTPUT" | $GREP -i warn`
+  FOUND_VERSION=`$ECHO $OUTPUT | $GREP " version \""`
+  if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then
+    boot_jdk_jvmargs="$boot_jdk_jvmargs -Xshare:auto"
+    JVM_ARG_OK=true
+  else
+    $ECHO "Arg failed:" >&5
+    $ECHO "$OUTPUT" >&5
+    JVM_ARG_OK=false
+  fi
+
+  fi
+
   # Apply user provided options.
 
   $ECHO "Check if jvm arg is ok: $with_boot_jdk_jvmargs" >&5
@@ -66256,7 +66326,6 @@
   JAVA_FLAGS=$boot_jdk_jvmargs
 
 
-
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking flags for boot jdk java command for big workloads" >&5
 $as_echo_n "checking flags for boot jdk java command for big workloads... " >&6; }
 
--- a/make/autoconf/spec.gmk.in	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/autoconf/spec.gmk.in	Sat Oct 21 00:06:50 2017 +0000
@@ -842,8 +842,6 @@
 TEST_BUNDLE :=  $(BUNDLES_OUTPUTDIR)/$(TEST_BUNDLE_NAME)
 DOCS_BUNDLE :=  $(BUNDLES_OUTPUTDIR)/$(DOCS_BUNDLE_NAME)
 
-CONFIGURE_CMD := $(TOPDIR)/configure
-
 # This macro is called to allow inclusion of closed source counterparts.
 # Unless overridden in closed sources, it expands to nothing.
 # Usage: This function is called in an open makefile, with the following
--- a/make/common/MakeBase.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/common/MakeBase.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -463,11 +463,22 @@
 endef
 
 ################################################################################
+# Replace question marks with space in string. This macro needs to be called on
+# files from CacheFind in case any of them contains space in their file name,
+# since CacheFind replaces space with ?.
+# Param 1 - String to replace in
+DecodeSpace = \
+    $(subst ?,$(SPACE),$(strip $1))
+EncodeSpace = \
+    $(subst $(SPACE),?,$(strip $1))
+
+################################################################################
 # Make directory without forking mkdir if not needed
 # 1: List of directories to create
 MakeDir = \
     $(strip \
-        $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, $(if $(wildcard $d), , $d)))) \
+        $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, $(if $(wildcard $d), , \
+            "$(call DecodeSpace, $d)")))) \
         $(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \
     )
 
@@ -479,6 +490,7 @@
     $(if $($(strip $1)),,$(eval $(strip $1) := $2))
 
 ################################################################################
+# All install-file and related macros automatically call DecodeSpace when needed.
 
 ifeq ($(OPENJDK_TARGET_OS),solaris)
   # On Solaris, if the target is a symlink and exists, cp won't overwrite.
@@ -487,19 +499,21 @@
   # If the source and target parent directories are the same, recursive copy doesn't work
   # so we fall back on regular copy, which isn't preserving symlinks.
   define install-file
-	$(MKDIR) -p '$(@D)'
-	$(RM) '$@'
-	if [ "$(@D)" != "$(<D)" ]; then \
-	  $(CP) -f -r -P '$<' '$(@D)'; \
-	  if [ "$(@F)" != "$(<F)" ]; then \
-	    $(MV) '$(@D)/$(<F)' '$@'; \
+	$(call MakeDir, $(@D))
+	$(RM) '$(call DecodeSpace, $@)'
+	if [ '$(call DecodeSpace, $(dir $@))' != \
+	    '$(call DecodeSpace, $(dir $(call EncodeSpace, $<)))' ]; then \
+	  $(CP) -f -r -P '$(call DecodeSpace, $<)' '$(call DecodeSpace, $(@D))'; \
+	  if [ '$(call DecodeSpace, $(@F))' != \
+	      '$(call DecodeSpace, $(notdir $(call EncodeSpace, $(<))))' ]; then \
+	    $(MV) '$(call DecodeSpace, $(@D)/$(<F))' '$(call DecodeSpace, $@)'; \
 	  fi; \
 	else \
-	  if [ -L '$<' ]; then \
+	  if [ -L '$(call DecodeSpace, $<)' ]; then \
 	    $(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \
 	    exit 1; \
 	  fi; \
-	  $(CP) -f '$<' '$@'; \
+	  $(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \
 	fi
   endef
 else ifeq ($(OPENJDK_TARGET_OS),macosx)
@@ -512,22 +526,22 @@
   # If copying a soft link to a directory, need to delete the target first to avoid
   # weird errors.
   define install-file
-	$(MKDIR) -p '$(@D)'
-	$(RM) '$@'
-	$(CP) -fRP '$<' '$@'
-	if [ -n "`$(XATTR) -l '$@'`" ]; then $(XATTR) -c '$@'; fi
+	$(call MakeDir, $(@D))
+	$(RM) '$(call DecodeSpace, $@)'
+	$(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
+	if [ -n "`$(XATTR) -l '$(call DecodeSpace, $@)'`" ]; then $(XATTR) -c '$(call DecodeSpace, $@)'; fi
   endef
 else
   define install-file
 	$(call MakeDir, $(@D))
-	$(CP) -fP '$<' '$@'
+	$(CP) -fP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
   endef
 endif
 
 # Variant of install file that does not preserve symlinks
 define install-file-nolink
 	$(call MakeDir, $(@D))
-	$(CP) -f '$<' '$@'
+	$(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
 endef
 
 ################################################################################
@@ -577,14 +591,14 @@
 # the unix emulation environment.
 define link-file-relative
 	$(call MakeDir, $(@D))
-	$(RM) $@
-	$(LN) -s $(call RelativePath, $<, $(@D)) $@
+	$(RM) '$(call DecodeSpace, $@)'
+	$(LN) -s '$(call DecodeSpace, $(call RelativePath, $<, $(@D)))' '$(call DecodeSpace, $@)'
 endef
 
 define link-file-absolute
 	$(call MakeDir, $(@D))
-	$(RM) $@
-	$(LN) -s $< $@
+	$(RM) '$(call DecodeSpace, $@)'
+	$(LN) -s '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
 endef
 
 ################################################################################
@@ -651,6 +665,13 @@
   # This macro can be called multiple times to add to the cache. Only finds files
   # with no filters.
   #
+  # Files containing space will get spaces replaced with ? because GNU Make
+  # cannot handle lists of files with space in them. By using ?, make will match
+  # the wildcard to space in many situations so we don't need to replace back
+  # to space on every use. While not a complete solution it does allow some uses
+  # of CacheFind to function with spaces in file names, including for
+  # SetupCopyFiles.
+  #
   # Needs to be called with $(eval )
   #
   # Even if the performance benifit is negligible on other platforms, keep the
@@ -668,7 +689,8 @@
     ifneq ($$(FIND_CACHE_NEW_DIRS), )
       # Remove any trailing slash from dirs in the cache dir list
       FIND_CACHE_DIRS += $$(patsubst %/,%, $$(FIND_CACHE_NEW_DIRS))
-      FIND_CACHE := $$(sort $$(FIND_CACHE) $$(shell $(FIND) $$(FIND_CACHE_NEW_DIRS) \( -type f -o -type l \) $2))
+      FIND_CACHE := $$(sort $$(FIND_CACHE) $$(shell $(FIND) $$(FIND_CACHE_NEW_DIRS) \
+          \( -type f -o -type l \) $2 | $(TR) ' ' '?'))
     endif
   endef
 
@@ -684,7 +706,8 @@
   # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression.
   define CacheFind
     $(if $(filter-out $(addsuffix /%,- $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS),$1), \
-      $(if $(wildcard $1), $(shell $(FIND) $1 \( -type f -o -type l \) $2)), \
+      $(if $(wildcard $1), $(shell $(FIND) $1 \( -type f -o -type l \) $2 \
+          | $(TR) ' ' '?')), \
       $(filter $(addsuffix /%,$(patsubst %/,%,$1)) $1,$(FIND_CACHE)))
   endef
 
@@ -693,7 +716,7 @@
   # Param 1 - Dirs to find in
   # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression.
   define CacheFind
-    $(shell $(FIND) $1 \( -type f -o -type l \) $2)
+    $(shell $(FIND) $1 \( -type f -o -type l \) $2 | $(TR) ' ' '?')
   endef
 endif
 
@@ -707,7 +730,7 @@
   # 4 : Macro to call for copy operation
   # 5 : Action text to log
   $2: $1
-	$$(call LogInfo, $(strip $5) $$(patsubst $(OUTPUTDIR)/%,%,$$@))
+	$$(call LogInfo, $(strip $5) $$(patsubst $(OUTPUTDIR)/%,%,$$(call DecodeSpace, $$@)))
 	$$($$(strip $4))
 
   $3 += $2
--- a/make/corba/Makefile	Sat Oct 21 07:00:23 2017 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-#
-# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.  Oracle designates this
-# particular file as subject to the "Classpath" exception as provided
-# by Oracle in the LICENSE file that accompanied this code.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# Locate this Makefile
-ifeq ($(filter /%, $(lastword $(MAKEFILE_LIST))), )
-  makefile_path := $(CURDIR)/$(lastword $(MAKEFILE_LIST))
-else
-  makefile_path := $(lastword $(MAKEFILE_LIST))
-endif
-repo_dir := $(patsubst %/make/Makefile, %, $(makefile_path))
-
-# What is the name of this subsystem (langtools, corba, etc)?
-subsystem_name := $(notdir $(repo_dir))
-
-# Try to locate top-level makefile
-top_level_makefile := $(repo_dir)/../Makefile
-ifneq ($(wildcard $(top_level_makefile)), )
-  $(info Will run $(subsystem_name) target on top-level Makefile)
-  $(info WARNING: This is a non-recommended way of building!)
-  $(info ===================================================)
-else
-  $(info Cannot locate top-level Makefile. Is this repo not checked out as part of a complete forest?)
-  $(error Build from top-level Makefile instead)
-endif
-
-all:
-	@$(MAKE) -f $(top_level_makefile) $(subsystem_name)
--- a/make/hotspot/lib/CompileJvm.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/hotspot/lib/CompileJvm.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -58,6 +58,7 @@
     -I$(JVM_VARIANT_OUTPUTDIR)/gensrc \
     -I$(TOPDIR)/src/hotspot/share/precompiled \
     -I$(TOPDIR)/src/hotspot/share/prims \
+    -I$(TOPDIR)/src/java.base/share/native/include \
     #
 
 # INCLUDE_SUFFIX_* is only meant for including the proper
--- a/make/hotspot/lib/JvmFeatures.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/hotspot/lib/JvmFeatures.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -132,6 +132,7 @@
       cms/ g1/ parallel/
   JVM_EXCLUDE_FILES += \
       concurrentGCThread.cpp \
+      suspendibleThreadSet.cpp \
       plab.cpp
   JVM_EXCLUDE_FILES += \
       g1MemoryPool.cpp \
--- a/make/lib/Lib-java.base.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/lib/Lib-java.base.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -25,9 +25,13 @@
 
 include LibCommon.gmk
 
+# Hook to include the corresponding custom file, if present.
+$(eval $(call IncludeCustomExtension, lib/Lib-java.base.gmk))
+
 # Prepare the find cache.
-$(eval $(call FillCacheFind, $(wildcard $(TOPDIR)/src/java.base/*/native \
-    $(TOPDIR)/src/*/java.base/*/native)))
+LIB_java.base_SRC_DIRS += $(TOPDIR)/src/java.base/*/native
+
+$(eval $(call FillCacheFind, $(wildcard $(LIB_java.base_SRC_DIRS))))
 
 include CoreLibraries.gmk
 include NetworkingLibraries.gmk
--- a/make/lib/Lib-java.desktop.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/lib/Lib-java.desktop.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -25,9 +25,13 @@
 
 include LibCommon.gmk
 
+# Hook to include the corresponding custom file, if present.
+$(eval $(call IncludeCustomExtension, lib/Lib-java.desktop.gmk))
+
 # Prepare the find cache.
-$(eval $(call FillCacheFind, $(wildcard $(TOPDIR)/src/java.desktop/*/native \
-    $(TOPDIR)/src/*/java.desktop/*/native)))
+LIB_java.desktop_SRC_DIRS += $(TOPDIR)/src/java.desktop/*/native
+
+$(eval $(call FillCacheFind, $(wildcard $(LIB_java.desktop_SRC_DIRS))))
 
 include LibosxLibraries.gmk
 include PlatformLibraries.gmk
--- a/make/test/JtregNativeHotspot.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/test/JtregNativeHotspot.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -35,7 +35,7 @@
 include MakeBase.gmk
 include TestFilesCompilation.gmk
 
-$(eval $(call IncludeCustomExtension, hotspot/test/JtregNative.gmk))
+$(eval $(call IncludeCustomExtension, test/JtregNativeHotspot.gmk))
 
 ################################################################################
 # Targets for building the native tests themselves.
@@ -50,6 +50,7 @@
     $(TOPDIR)/test/hotspot/jtreg/runtime/jni/8025979 \
     $(TOPDIR)/test/hotspot/jtreg/runtime/jni/8033445 \
     $(TOPDIR)/test/hotspot/jtreg/runtime/jni/checked \
+    $(TOPDIR)/test/hotspot/jtreg/runtime/jni/FindClass \
     $(TOPDIR)/test/hotspot/jtreg/runtime/jni/PrivateInterfaceMethods \
     $(TOPDIR)/test/hotspot/jtreg/runtime/jni/ToStringInInterfaceTest \
     $(TOPDIR)/test/hotspot/jtreg/runtime/jni/CalleeSavedRegisters \
--- a/make/test/JtregNativeJdk.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/make/test/JtregNativeJdk.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -35,7 +35,7 @@
 include MakeBase.gmk
 include TestFilesCompilation.gmk
 
-$(eval $(call IncludeCustomExtension, test/JtregNative.gmk))
+$(eval $(call IncludeCustomExtension, test/JtregNativeJdk.gmk))
 
 ################################################################################
 # Targets for building the native tests themselves.
--- a/src/hotspot/.mx.jvmci/hotspot/templates/eclipse/cproject	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/.mx.jvmci/hotspot/templates/eclipse/cproject	Sat Oct 21 00:06:50 2017 +0000
@@ -70,7 +70,7 @@
 						</toolChain>
 					</folderInfo>
 					<sourceEntries>
-						<entry excluding="cpu/vm/templateTable_x86_32.cpp|cpu/vm/templateInterpreter_x86_32.cpp|cpu/vm/stubRoutines_x86_32.cpp|cpu/vm/stubGenerator_x86_32.cpp|cpu/vm/sharedRuntime_x86_32.cpp|cpu/vm/jniFastGetField_x86_32.cpp|cpu/vm/interpreterRT_x86_32.cpp|cpu/vm/interpreter_x86_32.cpp|cpu/vm/interp_masm_x86_32.cpp|cpu/vm/vtableStubs_x86_32.cpp" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
+            <entry excluding="cpu/x86/templateTable_x86_32.cpp|cpu/x86/templateInterpreter_x86_32.cpp|cpu/x86/stubRoutines_x86_32.cpp|cpu/x86/stubGenerator_x86_32.cpp|cpu/x86/sharedRuntime_x86_32.cpp|cpu/x86/jniFastGetField_x86_32.cpp|cpu/x86/interpreterRT_x86_32.cpp|cpu/x86/interpreter_x86_32.cpp|cpu/x86/interp_masm_x86_32.cpp|cpu/x86/vtableStubs_x86_32.cpp" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
 					</sourceEntries>
 				</configuration>
 			</storageModule>
--- a/src/hotspot/.mx.jvmci/mx_jvmci.py	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/.mx.jvmci/mx_jvmci.py	Sat Oct 21 00:06:50 2017 +0000
@@ -256,14 +256,10 @@
         """
 
         roots = [
-            'ASSEMBLY_EXCEPTION',
-            'LICENSE',
-            'README',
-            'THIRD_PARTY_README',
-            'agent',
-            'make',
-            'src',
-            'test'
+            'cpu',
+            'os',
+            'os_cpu',
+            'share'
         ]
 
         for jvmVariant in _jdkJvmVariants:
@@ -605,6 +601,16 @@
 def _get_openjdk_os_cpu():
     return _get_openjdk_os() + '-' + _get_openjdk_cpu()
 
+def _get_jdk_dir():
+    suiteParentDir = dirname(_suite.dir)
+    # suitParentDir is now something like: /some_prefix/jdk10-hs/open/src
+    pathComponents = suiteParentDir.split(os.sep)
+    for i in range(0, len(pathComponents)):
+        if pathComponents[i] in ["open", "src"]:
+            del pathComponents[i:]
+            break
+    return os.path.join(os.sep, *pathComponents)
+
 def _get_jdk_build_dir(debugLevel=None):
     """
     Gets the directory into which the JDK is built. This directory contains
@@ -613,7 +619,7 @@
     if debugLevel is None:
         debugLevel = _vm.debugLevel
     name = '{}-{}-{}-{}'.format(_get_openjdk_os_cpu(), 'normal', _vm.jvmVariant, debugLevel)
-    return join(dirname(_suite.dir), 'build', name)
+    return join(_get_jdk_dir(), 'build', name)
 
 _jvmci_bootclasspath_prepends = []
 
--- a/src/hotspot/.mx.jvmci/suite.py	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/.mx.jvmci/suite.py	Sat Oct 21 00:06:50 2017 +0000
@@ -24,9 +24,7 @@
 
   "defaultLicense" : "GPLv2-CPE",
 
-  # This puts mx/ as a sibling of the JDK build configuration directories
-  # (e.g., macosx-x86_64-normal-server-release).
-  "outputRoot" : "../build/mx/hotspot",
+  "outputRoot" : "../../build/mx/hotspot",
 
     # ------------- Libraries -------------
 
@@ -43,7 +41,7 @@
     # ------------- JVMCI:Service -------------
 
     "jdk.vm.ci.services" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "sourceDirs" : ["src"],
       "javaCompliance" : "9",
       "workingSets" : "API,JVMCI",
@@ -52,7 +50,7 @@
     # ------------- JVMCI:API -------------
 
     "jdk.vm.ci.common" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "sourceDirs" : ["src"],
       "checkstyle" : "jdk.vm.ci.services",
       "javaCompliance" : "9",
@@ -60,7 +58,7 @@
     },
 
     "jdk.vm.ci.meta" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "sourceDirs" : ["src"],
       "checkstyle" : "jdk.vm.ci.services",
       "javaCompliance" : "9",
@@ -68,7 +66,7 @@
     },
 
     "jdk.vm.ci.code" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "sourceDirs" : ["src"],
       "dependencies" : ["jdk.vm.ci.meta"],
       "checkstyle" : "jdk.vm.ci.services",
@@ -77,7 +75,7 @@
     },
 
     "jdk.vm.ci.code.test" : {
-      "subDir" : "test/compiler/jvmci",
+      "subDir" : "../../test/hotspot/jtreg/compiler/jvmci",
       "sourceDirs" : ["src"],
       "dependencies" : [
         "mx:JUNIT",
@@ -92,7 +90,7 @@
     },
 
     "jdk.vm.ci.runtime" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "sourceDirs" : ["src"],
       "dependencies" : [
         "jdk.vm.ci.code",
@@ -104,7 +102,7 @@
     },
 
     "jdk.vm.ci.runtime.test" : {
-      "subDir" : "test/compiler/jvmci",
+      "subDir" : "../../test/hotspot/jtreg/compiler/jvmci",
       "sourceDirs" : ["src"],
       "dependencies" : [
         "mx:JUNIT",
@@ -119,7 +117,7 @@
     # ------------- JVMCI:HotSpot -------------
 
     "jdk.vm.ci.aarch64" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "sourceDirs" : ["src"],
       "dependencies" : ["jdk.vm.ci.code"],
       "checkstyle" : "jdk.vm.ci.services",
@@ -128,7 +126,7 @@
     },
 
     "jdk.vm.ci.amd64" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "sourceDirs" : ["src"],
       "dependencies" : ["jdk.vm.ci.code"],
       "checkstyle" : "jdk.vm.ci.services",
@@ -137,7 +135,7 @@
     },
 
     "jdk.vm.ci.sparc" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "sourceDirs" : ["src"],
       "dependencies" : ["jdk.vm.ci.code"],
       "checkstyle" : "jdk.vm.ci.services",
@@ -146,7 +144,7 @@
     },
 
     "jdk.vm.ci.hotspot" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "sourceDirs" : ["src"],
       "dependencies" : [
         "jdk.vm.ci.common",
@@ -163,7 +161,7 @@
     },
 
     "jdk.vm.ci.hotspot.test" : {
-      "subDir" : "test/compiler/jvmci",
+      "subDir" : "../../test/hotspot/jtreg/compiler/jvmci",
       "sourceDirs" : ["src"],
       "dependencies" : [
         "TESTNG",
@@ -175,7 +173,7 @@
     },
 
     "jdk.vm.ci.hotspot.aarch64" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "sourceDirs" : ["src"],
       "dependencies" : [
         "jdk.vm.ci.aarch64",
@@ -187,7 +185,7 @@
     },
 
     "jdk.vm.ci.hotspot.amd64" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "sourceDirs" : ["src"],
       "dependencies" : [
         "jdk.vm.ci.amd64",
@@ -199,7 +197,7 @@
     },
 
     "jdk.vm.ci.hotspot.sparc" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "sourceDirs" : ["src"],
       "dependencies" : [
         "jdk.vm.ci.sparc",
@@ -221,12 +219,12 @@
     # ------------- Distributions -------------
 
     "JVMCI_SERVICES" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "dependencies" : ["jdk.vm.ci.services"],
     },
 
     "JVMCI_API" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "dependencies" : [
         "jdk.vm.ci.runtime",
         "jdk.vm.ci.common",
@@ -240,7 +238,7 @@
     },
 
     "JVMCI_HOTSPOT" : {
-      "subDir" : "src/jdk.internal.vm.ci/share/classes",
+      "subDir" : "../jdk.internal.vm.ci/share/classes",
       "dependencies" : [
         "jdk.vm.ci.hotspot.aarch64",
         "jdk.vm.ci.hotspot.amd64",
@@ -253,7 +251,7 @@
     },
 
     "JVMCI_TEST" : {
-      "subDir" : "test/compiler/jvmci",
+      "subDir" : "../../test/hotspot/jtreg/compiler/jvmci",
       "dependencies" : [
         "jdk.vm.ci.runtime.test",
       ],
--- a/src/hotspot/cpu/aarch64/jniTypes_aarch64.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/aarch64/jniTypes_aarch64.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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.
  *
@@ -26,9 +26,9 @@
 #ifndef CPU_AARCH64_VM_JNITYPES_AARCH64_HPP
 #define CPU_AARCH64_VM_JNITYPES_AARCH64_HPP
 
+#include "jni.h"
 #include "memory/allocation.hpp"
 #include "oops/oop.hpp"
-#include "prims/jni.h"
 
 // This file holds platform-dependent routines used to write primitive jni
 // types to the array of arguments passed into JavaCalls::call
--- a/src/hotspot/cpu/arm/jniTypes_arm.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/arm/jniTypes_arm.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2013, 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
@@ -25,9 +25,9 @@
 #ifndef CPU_ARM_VM_JNITYPES_ARM_HPP
 #define CPU_ARM_VM_JNITYPES_ARM_HPP
 
+#include "jni.h"
 #include "memory/allocation.hpp"
 #include "oops/oop.hpp"
-#include "prims/jni.h"
 
 // This file holds platform-dependent routines used to write primitive jni
 // types to the array of arguments passed into JavaCalls::call
--- a/src/hotspot/cpu/arm/stubGenerator_arm.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/arm/stubGenerator_arm.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -2867,46 +2867,51 @@
   //  Blows all volatile registers (R0-R3 on 32-bit ARM, R0-R18 on AArch64, Rtemp, LR) except for callee_saved_regs.
   void gen_write_ref_array_pre_barrier(Register addr, Register count, int callee_saved_regs) {
     BarrierSet* bs = Universe::heap()->barrier_set();
-    if (bs->has_write_ref_pre_barrier()) {
-      assert(bs->has_write_ref_array_pre_opt(),
-             "Else unsupported barrier set.");
-
-      assert( addr->encoding() < callee_saved_regs, "addr must be saved");
-      assert(count->encoding() < callee_saved_regs, "count must be saved");
-
-      BLOCK_COMMENT("PreBarrier");
+    switch (bs->kind()) {
+    case BarrierSet::G1SATBCTLogging:
+      {
+        assert( addr->encoding() < callee_saved_regs, "addr must be saved");
+        assert(count->encoding() < callee_saved_regs, "count must be saved");
+
+        BLOCK_COMMENT("PreBarrier");
 
 #ifdef AARCH64
-      callee_saved_regs = align_up(callee_saved_regs, 2);
-      for (int i = 0; i < callee_saved_regs; i += 2) {
-        __ raw_push(as_Register(i), as_Register(i+1));
-      }
+        callee_saved_regs = align_up(callee_saved_regs, 2);
+        for (int i = 0; i < callee_saved_regs; i += 2) {
+          __ raw_push(as_Register(i), as_Register(i+1));
+        }
 #else
-      RegisterSet saved_regs = RegisterSet(R0, as_Register(callee_saved_regs-1));
-      __ push(saved_regs | R9ifScratched);
+        RegisterSet saved_regs = RegisterSet(R0, as_Register(callee_saved_regs-1));
+        __ push(saved_regs | R9ifScratched);
 #endif // AARCH64
 
-      if (addr != R0) {
-        assert_different_registers(count, R0);
-        __ mov(R0, addr);
-      }
+        if (addr != R0) {
+          assert_different_registers(count, R0);
+          __ mov(R0, addr);
+        }
 #ifdef AARCH64
-      __ zero_extend(R1, count, 32); // BarrierSet::static_write_ref_array_pre takes size_t
+        __ zero_extend(R1, count, 32); // BarrierSet::static_write_ref_array_pre takes size_t
 #else
-      if (count != R1) {
-        __ mov(R1, count);
-      }
+        if (count != R1) {
+          __ mov(R1, count);
+        }
 #endif // AARCH64
 
-      __ call(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre));
+        __ call(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre));
 
 #ifdef AARCH64
-      for (int i = callee_saved_regs - 2; i >= 0; i -= 2) {
-        __ raw_pop(as_Register(i), as_Register(i+1));
+        for (int i = callee_saved_regs - 2; i >= 0; i -= 2) {
+          __ raw_pop(as_Register(i), as_Register(i+1));
+        }
+#else
+        __ pop(saved_regs | R9ifScratched);
+#endif // AARCH64
       }
-#else
-      __ pop(saved_regs | R9ifScratched);
-#endif // AARCH64
+    case BarrierSet::CardTableForRS:
+    case BarrierSet::CardTableExtension:
+      break;
+    default:
+      ShouldNotReachHere();
     }
   }
 #endif // INCLUDE_ALL_GCS
--- a/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -863,7 +863,7 @@
     //
     // markOop displaced_header = obj->mark().set_unlocked();
     // monitor->lock()->set_displaced_header(displaced_header);
-    // if (Atomic::cmpxchg_ptr(/*ex=*/monitor, /*addr*/obj->mark_addr(), /*cmp*/displaced_header) == displaced_header) {
+    // if (Atomic::cmpxchg(/*ex=*/monitor, /*addr*/obj->mark_addr(), /*cmp*/displaced_header) == displaced_header) {
     //   // We stored the monitor address into the object's mark word.
     // } else if (THREAD->is_lock_owned((address)displaced_header))
     //   // Simple recursive case.
@@ -901,7 +901,7 @@
     std(displaced_header, BasicObjectLock::lock_offset_in_bytes() +
         BasicLock::displaced_header_offset_in_bytes(), monitor);
 
-    // if (Atomic::cmpxchg_ptr(/*ex=*/monitor, /*addr*/obj->mark_addr(), /*cmp*/displaced_header) == displaced_header) {
+    // if (Atomic::cmpxchg(/*ex=*/monitor, /*addr*/obj->mark_addr(), /*cmp*/displaced_header) == displaced_header) {
 
     // Store stack address of the BasicObjectLock (this is monitor) into object.
     addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes());
@@ -977,7 +977,7 @@
     // if ((displaced_header = monitor->displaced_header()) == NULL) {
     //   // Recursive unlock. Mark the monitor unlocked by setting the object field to NULL.
     //   monitor->set_obj(NULL);
-    // } else if (Atomic::cmpxchg_ptr(displaced_header, obj->mark_addr(), monitor) == monitor) {
+    // } else if (Atomic::cmpxchg(displaced_header, obj->mark_addr(), monitor) == monitor) {
     //   // We swapped the unlocked mark in displaced_header into the object's mark word.
     //   monitor->set_obj(NULL);
     // } else {
@@ -1010,7 +1010,7 @@
     cmpdi(CCR0, displaced_header, 0);
     beq(CCR0, free_slot); // recursive unlock
 
-    // } else if (Atomic::cmpxchg_ptr(displaced_header, obj->mark_addr(), monitor) == monitor) {
+    // } else if (Atomic::cmpxchg(displaced_header, obj->mark_addr(), monitor) == monitor) {
     //   // We swapped the unlocked mark in displaced_header into the object's mark word.
     //   monitor->set_obj(NULL);
 
--- a/src/hotspot/cpu/ppc/jniTypes_ppc.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/ppc/jniTypes_ppc.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2012, 2013 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -26,9 +26,9 @@
 #ifndef CPU_PPC_VM_JNITYPES_PPC_HPP
 #define CPU_PPC_VM_JNITYPES_PPC_HPP
 
+#include "jni.h"
 #include "memory/allocation.hpp"
 #include "oops/oop.hpp"
-#include "prims/jni.h"
 
 // This file holds platform-dependent routines used to write primitive
 // jni types to the array of arguments passed into JavaCalls::call.
--- a/src/hotspot/cpu/ppc/vm_version_ppc.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/ppc/vm_version_ppc.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -149,8 +149,7 @@
     print_features();
   }
 
-  // PPC64 supports 8-byte compare-exchange operations (see
-  // Atomic::cmpxchg and StubGenerator::generate_atomic_cmpxchg_ptr)
+  // PPC64 supports 8-byte compare-exchange operations (see Atomic::cmpxchg)
   // and 'atomic long memory ops' (see Unsafe_GetLongVolatile).
   _supports_cx8 = true;
 
--- a/src/hotspot/cpu/s390/interp_masm_s390.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/s390/interp_masm_s390.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -914,7 +914,7 @@
   //
   // markOop displaced_header = obj->mark().set_unlocked();
   // monitor->lock()->set_displaced_header(displaced_header);
-  // if (Atomic::cmpxchg_ptr(/*ex=*/monitor, /*addr*/obj->mark_addr(), /*cmp*/displaced_header) == displaced_header) {
+  // if (Atomic::cmpxchg(/*ex=*/monitor, /*addr*/obj->mark_addr(), /*cmp*/displaced_header) == displaced_header) {
   //   // We stored the monitor address into the object's mark word.
   // } else if (THREAD->is_lock_owned((address)displaced_header))
   //   // Simple recursive case.
@@ -949,7 +949,7 @@
   z_stg(displaced_header, BasicObjectLock::lock_offset_in_bytes() +
                           BasicLock::displaced_header_offset_in_bytes(), monitor);
 
-  // if (Atomic::cmpxchg_ptr(/*ex=*/monitor, /*addr*/obj->mark_addr(), /*cmp*/displaced_header) == displaced_header) {
+  // if (Atomic::cmpxchg(/*ex=*/monitor, /*addr*/obj->mark_addr(), /*cmp*/displaced_header) == displaced_header) {
 
   // Store stack address of the BasicObjectLock (this is monitor) into object.
   add2reg(object_mark_addr, oopDesc::mark_offset_in_bytes(), object);
@@ -1021,7 +1021,7 @@
   // if ((displaced_header = monitor->displaced_header()) == NULL) {
   //   // Recursive unlock. Mark the monitor unlocked by setting the object field to NULL.
   //   monitor->set_obj(NULL);
-  // } else if (Atomic::cmpxchg_ptr(displaced_header, obj->mark_addr(), monitor) == monitor) {
+  // } else if (Atomic::cmpxchg(displaced_header, obj->mark_addr(), monitor) == monitor) {
   //   // We swapped the unlocked mark in displaced_header into the object's mark word.
   //   monitor->set_obj(NULL);
   // } else {
@@ -1062,7 +1062,7 @@
                                                       BasicLock::displaced_header_offset_in_bytes()));
   z_bre(done); // displaced_header == 0 -> goto done
 
-  // } else if (Atomic::cmpxchg_ptr(displaced_header, obj->mark_addr(), monitor) == monitor) {
+  // } else if (Atomic::cmpxchg(displaced_header, obj->mark_addr(), monitor) == monitor) {
   //   // We swapped the unlocked mark in displaced_header into the object's mark word.
   //   monitor->set_obj(NULL);
 
--- a/src/hotspot/cpu/s390/jniTypes_s390.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/s390/jniTypes_s390.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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.
  * Copyright (c) 2016 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -29,9 +29,9 @@
 // This file holds platform-dependent routines used to write primitive
 // jni types to the array of arguments passed into JavaCalls::call.
 
+#include "jni.h"
 #include "memory/allocation.hpp"
 #include "oops/oop.hpp"
-#include "prims/jni.h"
 
 class JNITypes : AllStatic {
   // These functions write a java primitive type (in native format) to
--- a/src/hotspot/cpu/s390/vm_version_s390.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/s390/vm_version_s390.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -224,7 +224,7 @@
   }
 
   // z/Architecture supports 8-byte compare-exchange operations
-  // (see Atomic::cmpxchg and StubGenerator::generate_atomic_cmpxchg_ptr)
+  // (see Atomic::cmpxchg)
   // and 'atomic long memory ops' (see Unsafe_GetLongVolatile).
   _supports_cx8 = true;
 
--- a/src/hotspot/cpu/sparc/jniTypes_sparc.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/sparc/jniTypes_sparc.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -25,9 +25,9 @@
 #ifndef CPU_SPARC_VM_JNITYPES_SPARC_HPP
 #define CPU_SPARC_VM_JNITYPES_SPARC_HPP
 
+#include "jni.h"
 #include "memory/allocation.hpp"
 #include "oops/oop.hpp"
-#include "prims/jni.h"
 
 // This file holds platform-dependent routines used to write primitive jni
 // types to the array of arguments passed into JavaCalls::call
--- a/src/hotspot/cpu/x86/frame_x86.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/x86/frame_x86.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -383,6 +383,7 @@
 
 //------------------------------------------------------------------------------
 // frame::adjust_unextended_sp
+#ifdef ASSERT
 void frame::adjust_unextended_sp() {
   // On x86, sites calling method handle intrinsics and lambda forms are treated
   // as any other call site. Therefore, no special action is needed when we are
@@ -394,11 +395,12 @@
       // If the sender PC is a deoptimization point, get the original PC.
       if (sender_cm->is_deopt_entry(_pc) ||
           sender_cm->is_deopt_mh_entry(_pc)) {
-        DEBUG_ONLY(verify_deopt_original_pc(sender_cm, _unextended_sp));
+        verify_deopt_original_pc(sender_cm, _unextended_sp);
       }
     }
   }
 }
+#endif
 
 //------------------------------------------------------------------------------
 // frame::update_map_with_saved_link
--- a/src/hotspot/cpu/x86/frame_x86.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/x86/frame_x86.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -117,7 +117,7 @@
   // original sp we use that convention.
 
   intptr_t*     _unextended_sp;
-  void adjust_unextended_sp();
+  void adjust_unextended_sp() NOT_DEBUG_RETURN;
 
   intptr_t* ptr_at_addr(int offset) const {
     return (intptr_t*) addr_at(offset);
--- a/src/hotspot/cpu/x86/jniTypes_x86.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/x86/jniTypes_x86.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2010, 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
@@ -25,9 +25,9 @@
 #ifndef CPU_X86_VM_JNITYPES_X86_HPP
 #define CPU_X86_VM_JNITYPES_X86_HPP
 
+#include "jni.h"
 #include "memory/allocation.hpp"
 #include "oops/oop.hpp"
-#include "prims/jni.h"
 
 // This file holds platform-dependent routines used to write primitive jni
 // types to the array of arguments passed into JavaCalls::call
--- a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -566,7 +566,7 @@
     return start;
   }
 
-  // Support for intptr_t atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest)
+  // Support for intptr_t atomic::xchg_long(jlong exchange_value, volatile jlong* dest)
   //
   // Arguments :
   //    c_rarg0: exchange_value
@@ -574,8 +574,8 @@
   //
   // Result:
   //    *dest <- ex, return (orig *dest)
-  address generate_atomic_xchg_ptr() {
-    StubCodeMark mark(this, "StubRoutines", "atomic_xchg_ptr");
+  address generate_atomic_xchg_long() {
+    StubCodeMark mark(this, "StubRoutines", "atomic_xchg_long");
     address start = __ pc();
 
     __ movptr(rax, c_rarg0); // Copy to eax we need a return value anyhow
@@ -4998,7 +4998,7 @@
 
     // atomic calls
     StubRoutines::_atomic_xchg_entry         = generate_atomic_xchg();
-    StubRoutines::_atomic_xchg_ptr_entry     = generate_atomic_xchg_ptr();
+    StubRoutines::_atomic_xchg_long_entry    = generate_atomic_xchg_long();
     StubRoutines::_atomic_cmpxchg_entry      = generate_atomic_cmpxchg();
     StubRoutines::_atomic_cmpxchg_byte_entry = generate_atomic_cmpxchg_byte();
     StubRoutines::_atomic_cmpxchg_long_entry = generate_atomic_cmpxchg_long();
--- a/src/hotspot/cpu/zero/cppInterpreter_zero.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/zero/cppInterpreter_zero.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -276,7 +276,7 @@
     markOop disp = lockee->mark()->set_unlocked();
 
     monitor->lock()->set_displaced_header(disp);
-    if (Atomic::cmpxchg_ptr(monitor, lockee->mark_addr(), disp) != disp) {
+    if (Atomic::cmpxchg((markOop)monitor, lockee->mark_addr(), disp) != disp) {
       if (thread->is_lock_owned((address) disp->clear_lock_bits())) {
         monitor->lock()->set_displaced_header(NULL);
       }
@@ -420,7 +420,8 @@
     monitor->set_obj(NULL);
 
     if (header != NULL) {
-      if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) {
+      markOop old_header = markOopDesc::encode(lock);
+      if (rcvr->cas_set_mark(header, old_header) != old_header) {
         monitor->set_obj(rcvr); {
           HandleMark hm(thread);
           CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor));
--- a/src/hotspot/cpu/zero/jniTypes_zero.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/zero/jniTypes_zero.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2010, 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
@@ -25,9 +25,9 @@
 #ifndef CPU_ZERO_VM_JNITYPES_ZERO_HPP
 #define CPU_ZERO_VM_JNITYPES_ZERO_HPP
 
+#include "jni.h"
 #include "memory/allocation.hpp"
 #include "oops/oop.hpp"
-#include "prims/jni.h"
 
 // This file holds platform-dependent routines used to write primitive jni
 // types to the array of arguments passed into JavaCalls::call
--- a/src/hotspot/cpu/zero/stubGenerator_zero.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/cpu/zero/stubGenerator_zero.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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, 2010, 2015 Red Hat, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -253,9 +253,8 @@
 
     // atomic calls
     StubRoutines::_atomic_xchg_entry         = ShouldNotCallThisStub();
-    StubRoutines::_atomic_xchg_ptr_entry     = ShouldNotCallThisStub();
+    StubRoutines::_atomic_xchg_long_entry    = ShouldNotCallThisStub();
     StubRoutines::_atomic_cmpxchg_entry      = ShouldNotCallThisStub();
-    StubRoutines::_atomic_cmpxchg_ptr_entry  = ShouldNotCallThisStub();
     StubRoutines::_atomic_cmpxchg_byte_entry = ShouldNotCallThisStub();
     StubRoutines::_atomic_cmpxchg_long_entry = ShouldNotCallThisStub();
     StubRoutines::_atomic_add_entry          = ShouldNotCallThisStub();
--- a/src/hotspot/os/aix/decoder_aix.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os/aix/decoder_aix.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -34,8 +34,6 @@
   }
   virtual ~AIXDecoder() {}
 
-  virtual bool can_decode_C_frame_in_vm() const { return true; }
-
   virtual bool demangle(const char* symbol, char* buf, int buflen) { return false; } // use AixSymbols::get_function_name to demangle
 
   virtual bool decode(address addr, char* buf, int buflen, int* offset, const char* modulepath, bool demangle) {
--- a/src/hotspot/os/aix/os_aix.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os/aix/os_aix.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -889,8 +889,12 @@
                             stack_size / K);
   }
 
-  // Configure libc guard page.
-  ret = pthread_attr_setguardsize(&attr, os::Aix::default_guard_size(thr_type));
+  // Save some cycles and a page by disabling OS guard pages where we have our own
+  // VM guard pages (in java threads). For other threads, keep system default guard
+  // pages in place.
+  if (thr_type == java_thread || thr_type == compiler_thread) {
+    ret = pthread_attr_setguardsize(&attr, 0);
+  }
 
   pthread_t tid = 0;
   if (ret == 0) {
@@ -3019,19 +3023,6 @@
   return chained;
 }
 
-size_t os::Aix::default_guard_size(os::ThreadType thr_type) {
-  // Creating guard page is very expensive. Java thread has HotSpot
-  // guard pages, only enable glibc guard page for non-Java threads.
-  // (Remember: compiler thread is a Java thread, too!)
-  //
-  // Aix can have different page sizes for stack (4K) and heap (64K).
-  // As Hotspot knows only one page size, we assume the stack has
-  // the same page size as the heap. Returning page_size() here can
-  // cause 16 guard pages which we want to avoid.  Thus we return 4K
-  // which will be rounded to the real page size by the OS.
-  return ((thr_type == java_thread || thr_type == compiler_thread) ? 0 : 4 * K);
-}
-
 struct sigaction* os::Aix::get_preinstalled_handler(int sig) {
   if (sigismember(&sigs, sig)) {
     return &sigact[sig];
--- a/src/hotspot/os/aix/os_aix.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os/aix/os_aix.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -139,9 +139,6 @@
   // libpthread version string
   static void libpthread_init();
 
-  // Return default libc guard size for the specified thread type.
-  static size_t default_guard_size(os::ThreadType thr_type);
-
   // Function returns true if we run on OS/400 (pase), false if we run
   // on AIX.
   static bool on_pase() {
--- a/src/hotspot/os/bsd/decoder_machO.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os/bsd/decoder_machO.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -35,9 +35,6 @@
  public:
   MachODecoder() { }
   virtual ~MachODecoder() { }
-  virtual bool can_decode_C_frame_in_vm() const {
-    return true;
-  }
   virtual bool demangle(const char* symbol, char* buf, int buflen);
   virtual bool decode(address pc, char* buf, int buflen, int* offset,
                       const void* base);
--- a/src/hotspot/os/linux/os_linux.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os/linux/os_linux.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -98,6 +98,11 @@
 
 inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
 {
+// readdir_r has been deprecated since glibc 2.24.
+// See https://sourceware.org/bugzilla/show_bug.cgi?id=19056 for more details.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
   dirent* p;
   int status;
   assert(dirp != NULL, "just checking");
@@ -111,6 +116,8 @@
     return NULL;
   } else
     return p;
+
+#pragma GCC diagnostic pop
 }
 
 inline int os::closedir(DIR *dirp) {
--- a/src/hotspot/os/windows/decoder_windows.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os/windows/decoder_windows.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -23,136 +23,28 @@
  */
 
 #include "precompiled.hpp"
-#include "prims/jvm.h"
-#include "runtime/arguments.hpp"
-#include "runtime/os.hpp"
-#include "decoder_windows.hpp"
+#include "utilities/decoder.hpp"
+#include "symbolengine.hpp"
 #include "windbghelp.hpp"
 
-WindowsDecoder::WindowsDecoder() {
-  _can_decode_in_vm = true;
-  _decoder_status = no_error;
-  initialize();
+bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath, bool demangle) {
+  return SymbolEngine::decode(addr, buf, buflen, offset, demangle);
+}
+
+bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {
+  return SymbolEngine::decode(addr, buf, buflen, offset, true);
 }
 
-void WindowsDecoder::initialize() {
-  if (!has_error()) {
-    HANDLE hProcess = ::GetCurrentProcess();
-    WindowsDbgHelp::symSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_EXACT_SYMBOLS);
-    if (!WindowsDbgHelp::symInitialize(hProcess, NULL, TRUE)) {
-      _decoder_status = helper_init_error;
-      return;
-    }
-
-    // set pdb search paths
-    char paths[MAX_PATH];
-    int  len = sizeof(paths);
-    if (!WindowsDbgHelp::symGetSearchPath(hProcess, paths, len)) {
-      paths[0] = '\0';
-    } else {
-      // available spaces in path buffer
-      len -= (int)strlen(paths);
-    }
-
-    char tmp_path[MAX_PATH];
-    DWORD dwSize;
-    HMODULE hJVM = ::GetModuleHandle("jvm.dll");
-    tmp_path[0] = '\0';
-    // append the path where jvm.dll is located
-    if (hJVM != NULL && (dwSize = ::GetModuleFileName(hJVM, tmp_path, sizeof(tmp_path))) > 0) {
-      while (dwSize > 0 && tmp_path[dwSize] != '\\') {
-        dwSize --;
-      }
-
-      tmp_path[dwSize] = '\0';
-
-      if (dwSize > 0 && len > (int)dwSize + 1) {
-        strncat(paths, os::path_separator(), 1);
-        strncat(paths, tmp_path, dwSize);
-        len -= dwSize + 1;
-      }
-    }
-
-    // append $JRE/bin. Arguments::get_java_home actually returns $JRE
-    // path
-    char *p = Arguments::get_java_home();
-    assert(p != NULL, "empty java home");
-    size_t java_home_len = strlen(p);
-    if (len > (int)java_home_len + 5) {
-      strncat(paths, os::path_separator(), 1);
-      strncat(paths, p, java_home_len);
-      strncat(paths, "\\bin", 4);
-      len -= (int)(java_home_len + 5);
-    }
-
-    // append $JDK/bin path if it exists
-    assert(java_home_len < MAX_PATH, "Invalid path length");
-    // assume $JRE is under $JDK, construct $JDK/bin path and
-    // see if it exists or not
-    if (strncmp(&p[java_home_len - 3], "jre", 3) == 0) {
-      strncpy(tmp_path, p, java_home_len - 3);
-      tmp_path[java_home_len - 3] = '\0';
-      strncat(tmp_path, "bin", 3);
-
-      // if the directory exists
-      DWORD dwAttrib = GetFileAttributes(tmp_path);
-      if (dwAttrib != INVALID_FILE_ATTRIBUTES &&
-          (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
-        // tmp_path should have the same length as java_home_len, since we only
-        // replaced 'jre' with 'bin'
-        if (len > (int)java_home_len + 1) {
-          strncat(paths, os::path_separator(), 1);
-          strncat(paths, tmp_path, java_home_len);
-        }
-      }
-    }
-
-    WindowsDbgHelp::symSetSearchPath(hProcess, paths);
-
-    // find out if jvm.dll contains private symbols, by decoding
-    // current function and comparing the result
-    address addr = (address)Decoder::demangle;
-    char buf[MAX_PATH];
-    if (decode(addr, buf, sizeof(buf), NULL, NULL, true /* demangle */)) {
-      _can_decode_in_vm = !strcmp(buf, "Decoder::demangle");
-    }
-  }
+bool Decoder::get_source_info(address pc, char* buf, size_t buflen, int* line) {
+  return SymbolEngine::get_source_info(pc, buf, buflen, line);
 }
 
-void WindowsDecoder::uninitialize() {}
-
-bool WindowsDecoder::can_decode_C_frame_in_vm() const {
-  return  (!has_error() && _can_decode_in_vm);
+bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
+  return SymbolEngine::demangle(symbol, buf, buflen);
 }
 
-
-bool WindowsDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* modulepath, bool demangle_name)  {
-  if (!has_error()) {
-    PIMAGEHLP_SYMBOL64 pSymbol;
-    char symbolInfo[MAX_PATH + sizeof(IMAGEHLP_SYMBOL64)];
-    pSymbol = (PIMAGEHLP_SYMBOL64)symbolInfo;
-    pSymbol->MaxNameLength = MAX_PATH;
-    pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
-    DWORD64 displacement;
-    if (WindowsDbgHelp::symGetSymFromAddr64(::GetCurrentProcess(), (DWORD64)addr, &displacement, pSymbol)) {
-      if (buf != NULL) {
-        if (!(demangle_name && demangle(pSymbol->Name, buf, buflen))) {
-          jio_snprintf(buf, buflen, "%s", pSymbol->Name);
-        }
-      }
-      if(offset != NULL) *offset = (int)displacement;
-      return true;
-    }
-  }
-  if (buf != NULL && buflen > 0) buf[0] = '\0';
-  if (offset != NULL) *offset = -1;
-  return false;
+void Decoder::print_state_on(outputStream* st) {
+  WindowsDbgHelp::print_state_on(st);
+  SymbolEngine::print_state_on(st);
 }
 
-bool WindowsDecoder::demangle(const char* symbol, char *buf, int buflen) {
-  if (!has_error()) {
-    return WindowsDbgHelp::unDecorateSymbolName(symbol, buf, buflen, UNDNAME_COMPLETE) > 0;
-  }
-  return false;
-}
-
--- a/src/hotspot/os/windows/decoder_windows.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2011, 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.
- *
- */
-
-#ifndef OS_WINDOWS_VM_DECODER_WINDOWS_HPP
-#define OS_WINDOWS_VM_DECIDER_WINDOWS_HPP
-
-#include "utilities/decoder.hpp"
-
-class WindowsDecoder : public AbstractDecoder {
-
-public:
-  WindowsDecoder();
-  virtual ~WindowsDecoder() { uninitialize(); };
-
-  bool can_decode_C_frame_in_vm() const;
-  bool demangle(const char* symbol, char *buf, int buflen);
-  bool decode(address addr, char *buf, int buflen, int* offset, const char* modulepath, bool demangle);
-  bool decode(address addr, char *buf, int buflen, int* offset, const void* base) {
-    ShouldNotReachHere();
-    return false;
-  }
-
-private:
-  void initialize();
-  void uninitialize();
-
-  bool                      _can_decode_in_vm;
-
-};
-
-#endif // OS_WINDOWS_VM_DECODER_WINDOWS_HPP
--- a/src/hotspot/os/windows/os_windows.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os/windows/os_windows.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -74,6 +74,7 @@
 #include "utilities/growableArray.hpp"
 #include "utilities/macros.hpp"
 #include "utilities/vmError.hpp"
+#include "symbolengine.hpp"
 #include "windbghelp.hpp"
 
 
@@ -134,6 +135,8 @@
     if (ForceTimeHighResolution) {
       timeBeginPeriod(1L);
     }
+    WindowsDbgHelp::pre_initialize();
+    SymbolEngine::pre_initialize();
     break;
   case DLL_PROCESS_DETACH:
     if (ForceTimeHighResolution) {
@@ -1319,6 +1322,8 @@
 void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
   void * result = LoadLibrary(name);
   if (result != NULL) {
+    // Recalculate pdb search path if a DLL was loaded successfully.
+    SymbolEngine::recalc_search_path();
     return result;
   }
 
@@ -4032,6 +4037,8 @@
     return JNI_ERR;
   }
 
+  SymbolEngine::recalc_search_path();
+
   return JNI_OK;
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/windows/symbolengine.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,641 @@
+/*
+ * 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 "precompiled.hpp"
+#include "utilities/globalDefinitions.hpp"
+#include "symbolengine.hpp"
+#include "utilities/debug.hpp"
+#include "windbghelp.hpp"
+
+#include <windows.h>
+
+#include <imagehlp.h>
+#include <psapi.h>
+
+
+
+// This code may be invoked normally but also as part of error reporting
+// In the latter case, we may run under tight memory constraints (native oom)
+// or in a stack overflow situation or the C heap may be corrupted. We may
+// run very early before VM initialization or very late when C exit handlers
+// run. In all these cases, callstacks would still be nice, so lets be robust.
+//
+// We need a number of buffers - for the pdb search path, module handle
+// lists, for demangled symbols, etc.
+//
+// These buffers, while typically small, may need to be large for corner
+// cases (e.g. templatized C++ symbols, or many DLLs loaded). Where do we
+// allocate them?
+//
+// We may be in error handling for a stack overflow, so lets not put them on
+// the stack.
+//
+// Dynamically allocating them may fail if we are handling a native OOM. It
+// is also a bit dangerous, as the C heap may be corrupted already.
+//
+// That leaves pre-allocating them globally, which is safe and should always
+// work (if we synchronize access) but incurs an undesirable footprint for
+// non-error cases.
+//
+// We follow a two-way strategy: Allocate the buffers on the C heap in a
+// reasonable large size. Failing that, fall back to static preallocated
+// buffers. The size of the latter is large enough to handle common scenarios
+// but small enough not to drive up the footprint too much (several kb).
+//
+// We keep these buffers around once allocated, for subsequent requests. This
+// means that by running the initialization early at a safe time - before
+// any error happens - buffers can be pre-allocated. This increases the chance
+// of useful callstacks in error scenarios in exchange for a some cycles spent
+// at startup. This behavior can be controlled with -XX:+InitializeDbgHelpEarly
+// and is off by default.
+
+///////
+
+// A simple buffer which attempts to allocate an optimal size but will
+// fall back to a static minimally sized array on allocation error.
+template <class T, int MINIMAL_CAPACITY, int OPTIMAL_CAPACITY>
+class SimpleBufferWithFallback {
+  T _fallback_buffer[MINIMAL_CAPACITY];
+  T* _p;
+  int _capacity;
+
+  // A sentinel at the end of the buffer to catch overflows.
+  void imprint_sentinel() {
+    assert(_p && _capacity > 0, "Buffer must be allocated");
+    _p[_capacity - 1] = (T)'X';
+    _capacity --;
+  }
+
+public:
+
+  SimpleBufferWithFallback<T, MINIMAL_CAPACITY, OPTIMAL_CAPACITY> ()
+    : _p(NULL), _capacity(0)
+  {}
+
+  // Note: no destructor because these buffers should, once
+  // allocated, live until process end.
+  // ~SimpleBufferWithFallback()
+
+  // Note: We use raw ::malloc/::free here instead of os::malloc()/os::free
+  // to prevent circularities or secondary crashes during error reporting.
+  virtual void initialize () {
+    assert(_p == NULL && _capacity == 0, "Only call once.");
+    const size_t bytes = OPTIMAL_CAPACITY * sizeof(T);
+    T* q = (T*) ::malloc(bytes);
+    if (q != NULL) {
+      _p = q;
+      _capacity = OPTIMAL_CAPACITY;
+    } else {
+      _p = _fallback_buffer;
+      _capacity = (int)(sizeof(_fallback_buffer) / sizeof(T));
+    }
+    _p[0] = '\0';
+    imprint_sentinel();
+  }
+
+  // We need a way to reset the buffer to fallback size for one special
+  // case, where two buffers need to be of identical capacity.
+  void reset_to_fallback_capacity() {
+    if (_p != _fallback_buffer) {
+      ::free(_p);
+    }
+    _p = _fallback_buffer;
+    _capacity = (int)(sizeof(_fallback_buffer) / sizeof(T));
+    _p[0] = '\0';
+    imprint_sentinel();
+  }
+
+  T* ptr()                { return _p; }
+  const T* ptr() const    { return _p; }
+  int capacity() const    { return _capacity; }
+
+#ifdef ASSERT
+  void check() const {
+    assert(_p[_capacity] == (T)'X', "sentinel lost");
+  }
+#else
+  void check() const {}
+#endif
+
+};
+
+////
+
+// ModuleHandleArray: a list holding module handles. Needs to be large enough
+// to hold one handle per loaded DLL.
+// Note: a standard OpenJDK loads normally ~30 libraries, including system
+// libraries, without third party libraries.
+
+typedef SimpleBufferWithFallback <HMODULE, 48, 512> ModuleHandleArrayBase;
+
+class ModuleHandleArray : public ModuleHandleArrayBase {
+
+  int _num; // Number of handles in this array (may be < capacity).
+
+public:
+
+  void initialize() {
+    ModuleHandleArrayBase::initialize();
+    _num = 0;
+  }
+
+  int num() const { return _num; }
+  void set_num(int n) {
+    assert(n <= capacity(), "Too large");
+    _num = n;
+  }
+
+  // Compare with another list; returns true if all handles are equal (incl.
+  // sort order)
+  bool equals(const ModuleHandleArray& other) const {
+    if (_num != other._num) {
+      return false;
+    }
+    if (::memcmp(ptr(), other.ptr(), _num * sizeof(HMODULE)) != 0) {
+      return false;
+    }
+    return true;
+  }
+
+  // Copy content from other list.
+  void copy_content_from(ModuleHandleArray& other) {
+    assert(capacity() == other.capacity(), "Different capacities.");
+    memcpy(ptr(), other.ptr(), other._num * sizeof(HMODULE));
+    _num = other._num;
+  }
+
+};
+
+////
+
+// PathBuffer: a buffer to hold and work with a pdb search PATH - a concatenation
+// of multiple directories separated by ';'.
+// A single directory name can be (NTFS) as long as 32K, but in reality is
+// seldom larger than the (historical) MAX_PATH of 260.
+
+#define MINIMUM_PDB_PATH_LENGTH  MAX_PATH * 4
+#define OPTIMAL_PDB_PATH_LENGTH  MAX_PATH * 64
+
+typedef SimpleBufferWithFallback<char, MINIMUM_PDB_PATH_LENGTH, OPTIMAL_PDB_PATH_LENGTH> PathBufferBase;
+
+class PathBuffer: public PathBufferBase {
+public:
+
+  // Search PDB path for a directory. Search is case insensitive. Returns
+  // true if directory was found in the path, false otherwise.
+  bool contains_directory(const char* directory) {
+    if (ptr() == NULL) {
+      return false;
+    }
+    const size_t len = strlen(directory);
+    if (len == 0) {
+      return false;
+    }
+    char* p = ptr();
+    for(;;) {
+      char* q = strchr(p, ';');
+      if (q != NULL) {
+        if (len == (q - p)) {
+          if (strnicmp(p, directory, len) == 0) {
+            return true;
+          }
+        }
+        p = q + 1;
+      } else {
+        // tail
+        return stricmp(p, directory) == 0 ? true : false;
+      }
+    }
+    return false;
+  }
+
+  // Appends the given directory to the path. Returns false if internal
+  // buffer size was not sufficient.
+  bool append_directory(const char* directory) {
+    const size_t len = strlen(directory);
+    if (len == 0) {
+      return false;
+    }
+    char* p = ptr();
+    const size_t len_now = strlen(p);
+    const size_t needs_capacity = len_now + 1 + len + 1; // xxx;yy\0
+    if (needs_capacity > (size_t)capacity()) {
+      return false; // OOM
+    }
+    if (len_now > 0) { // Not the first path element.
+      p += len_now;
+      *p = ';';
+      p ++;
+    }
+    strcpy(p, directory);
+    return true;
+  }
+
+};
+
+// A simple buffer to hold one single file name. A file name can be (NTFS) as
+// long as 32K, but in reality is seldom larger than MAX_PATH.
+typedef SimpleBufferWithFallback<char, MAX_PATH, 8 * K> FileNameBuffer;
+
+// A buffer to hold a C++ symbol. Usually small, but symbols may be larger for
+// templates.
+#define MINIMUM_SYMBOL_NAME_LEN 128
+#define OPTIMAL_SYMBOL_NAME_LEN 1024
+
+typedef SimpleBufferWithFallback<uint8_t,
+        sizeof(IMAGEHLP_SYMBOL64) + MINIMUM_SYMBOL_NAME_LEN,
+        sizeof(IMAGEHLP_SYMBOL64) + OPTIMAL_SYMBOL_NAME_LEN> SymbolBuffer;
+
+static struct {
+
+  // Two buffers to hold lists of loaded modules. handles across invocations of
+  // SymbolEngine::recalc_search_path().
+  ModuleHandleArray loaded_modules;
+  ModuleHandleArray last_loaded_modules;
+  // Buffer to retrieve and assemble the pdb search path.
+  PathBuffer search_path;
+  // Buffer to retrieve directory names for loaded modules.
+  FileNameBuffer dir_name;
+  // Buffer to retrieve decoded symbol information (in SymbolEngine::decode)
+  SymbolBuffer decode_buffer;
+
+  void initialize() {
+    search_path.initialize();
+    dir_name.initialize();
+    decode_buffer.initialize();
+
+    loaded_modules.initialize();
+    last_loaded_modules.initialize();
+
+    // Note: both module lists must have the same capacity. If one allocation
+    // did fail, let them both fall back to the fallback size.
+    if (loaded_modules.capacity() != last_loaded_modules.capacity()) {
+      loaded_modules.reset_to_fallback_capacity();
+      last_loaded_modules.reset_to_fallback_capacity();
+    }
+
+    assert(search_path.capacity() > 0 && dir_name.capacity() > 0 &&
+            decode_buffer.capacity() > 0 && loaded_modules.capacity() > 0 &&
+            last_loaded_modules.capacity() > 0, "Init error.");
+  }
+
+} g_buffers;
+
+
+// Scan the loaded modules.
+//
+// For each loaded module, add the directory it is located in to the pdb search
+// path, but avoid duplicates. Prior search path content is preserved.
+//
+// If p_search_path_was_updated is not NULL, points to a bool which, upon
+// successful return from the function, contains true if the search path
+// was updated, false if no update was needed because no new DLLs were
+// loaded or unloaded.
+//
+// Returns true for success, false for error.
+static bool recalc_search_path_locked(bool* p_search_path_was_updated) {
+
+  if (p_search_path_was_updated) {
+    *p_search_path_was_updated = false;
+  }
+
+  HANDLE hProcess = ::GetCurrentProcess();
+
+  BOOL success = false;
+
+  // 1) Retrieve current set search path.
+  //    (PDB search path is a global setting and someone might have modified
+  //     it, so take care not to remove directories, just to add our own).
+
+  if (!WindowsDbgHelp::symGetSearchPath(hProcess, g_buffers.search_path.ptr(),
+                                       (int)g_buffers.search_path.capacity())) {
+    return false;
+  }
+  DEBUG_ONLY(g_buffers.search_path.check();)
+
+  // 2) Retrieve list of modules handles of all currently loaded modules.
+  DWORD bytes_needed = 0;
+  const DWORD buffer_capacity_bytes = (DWORD)g_buffers.loaded_modules.capacity() * sizeof(HMODULE);
+  success = ::EnumProcessModules(hProcess, g_buffers.loaded_modules.ptr(),
+                                 buffer_capacity_bytes, &bytes_needed);
+  DEBUG_ONLY(g_buffers.loaded_modules.check();)
+
+  // Note: EnumProcessModules is sloppily defined in terms of whether a
+  // too-small output buffer counts as error. Will it truncate but still
+  // return TRUE? Nobody knows and the manpage is not telling. So we count
+  // truncation it as error, disregarding the return value.
+  if (!success || bytes_needed > buffer_capacity_bytes) {
+    return false;
+  } else {
+    const int num_modules = bytes_needed / sizeof(HMODULE);
+    g_buffers.loaded_modules.set_num(num_modules);
+  }
+
+  // Compare the list of module handles with the last list. If the lists are
+  // identical, no additional dlls were loaded and we can stop.
+  if (g_buffers.loaded_modules.equals(g_buffers.last_loaded_modules)) {
+    return true;
+  } else {
+    // Remember the new set of module handles and continue.
+    g_buffers.last_loaded_modules.copy_content_from(g_buffers.loaded_modules);
+  }
+
+  // 3) For each loaded module: retrieve directory from which it was loaded.
+  //    Add directory to search path (but avoid duplicates).
+
+  bool did_modify_searchpath = false;
+
+  for (int i = 0; i < (int)g_buffers.loaded_modules.num(); i ++) {
+
+    const HMODULE hMod = g_buffers.loaded_modules.ptr()[i];
+    char* const filebuffer = g_buffers.dir_name.ptr();
+    const int file_buffer_capacity = g_buffers.dir_name.capacity();
+    const int len_returned = (int)::GetModuleFileName(hMod, filebuffer, (DWORD)file_buffer_capacity);
+    DEBUG_ONLY(g_buffers.dir_name.check();)
+    if (len_returned == 0) {
+      // Error. This is suspicious - this may happen if a module has just been
+      // unloaded concurrently after our call to EnumProcessModules and
+      // GetModuleFileName, but probably just indicates a coding error.
+      assert(false, "GetModuleFileName failed (%u)", ::GetLastError());
+    } else if (len_returned == file_buffer_capacity) {
+      // Truncation. Just skip this module and continue with the next module.
+      continue;
+    }
+
+    // Cut file name part off.
+    char* last_slash = ::strrchr(filebuffer, '\\');
+    if (last_slash == NULL) {
+      last_slash = ::strrchr(filebuffer, '/');
+    }
+    if (last_slash) {
+      *last_slash = '\0';
+    }
+
+    // If this is already part of the search path, ignore it, otherwise
+    // append to search path.
+    if (!g_buffers.search_path.contains_directory(filebuffer)) {
+      if (!g_buffers.search_path.append_directory(filebuffer)) {
+        return false; // oom
+      }
+      DEBUG_ONLY(g_buffers.search_path.check();)
+      did_modify_searchpath = true;
+    }
+
+  } // for each loaded module.
+
+  // If we did not modify the search path, nothing further needs to be done.
+  if (!did_modify_searchpath) {
+    return true;
+  }
+
+  // Set the search path to its new value.
+  if (!WindowsDbgHelp::symSetSearchPath(hProcess, g_buffers.search_path.ptr())) {
+    return false;
+  }
+
+  if (p_search_path_was_updated) {
+    *p_search_path_was_updated = true;
+  }
+
+  return true;
+
+}
+
+static bool demangle_locked(const char* symbol, char *buf, int buflen) {
+
+  return WindowsDbgHelp::unDecorateSymbolName(symbol, buf, buflen, UNDNAME_COMPLETE) > 0;
+
+}
+
+static bool decode_locked(const void* addr, char* buf, int buflen, int* offset, bool do_demangle) {
+
+  assert(g_buffers.decode_buffer.capacity() >= (sizeof(IMAGEHLP_SYMBOL64) + MINIMUM_SYMBOL_NAME_LEN),
+         "Decode buffer too small.");
+  assert(buf != NULL && buflen > 0 && offset != NULL, "invalid output buffer.");
+
+  DWORD64 displacement;
+  PIMAGEHLP_SYMBOL64 pSymbol = NULL;
+  bool success = false;
+
+  pSymbol = (PIMAGEHLP_SYMBOL64) g_buffers.decode_buffer.ptr();
+  pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
+  pSymbol->MaxNameLength = (DWORD)(g_buffers.decode_buffer.capacity() - sizeof(IMAGEHLP_SYMBOL64) - 1);
+
+  // It is unclear how SymGetSymFromAddr64 handles truncation. Experiments
+  // show it will return TRUE but not zero terminate (which is a really bad
+  // combination). Lets be super careful.
+  ::memset(pSymbol->Name, 0, pSymbol->MaxNameLength); // To catch truncation.
+
+  if (WindowsDbgHelp::symGetSymFromAddr64(::GetCurrentProcess(), (DWORD64)addr, &displacement, pSymbol)) {
+    success = true;
+    if (pSymbol->Name[pSymbol->MaxNameLength - 1] != '\0') {
+      // Symbol was truncated. Do not attempt to demangle. Instead, zero terminate the
+      // truncated string. We still return success - the truncated string may still
+      // be usable for the caller.
+      pSymbol->Name[pSymbol->MaxNameLength - 1] = '\0';
+      do_demangle = false;
+    }
+
+    // Attempt to demangle.
+    if (do_demangle && demangle_locked(pSymbol->Name, buf, buflen)) {
+      // ok.
+    } else {
+      ::strncpy(buf, pSymbol->Name, buflen - 1);
+    }
+    buf[buflen - 1] = '\0';
+
+    *offset = (int)displacement;
+  }
+
+  DEBUG_ONLY(g_buffers.decode_buffer.check();)
+
+  return success;
+}
+
+static enum {
+  state_uninitialized = 0,
+  state_ready = 1,
+  state_error = 2
+} g_state = state_uninitialized;
+
+static void initialize() {
+
+  assert(g_state == state_uninitialized, "wrong sequence");
+  g_state = state_error;
+
+  // 1) Initialize buffers.
+  g_buffers.initialize();
+
+  // 1) Call SymInitialize
+  HANDLE hProcess = ::GetCurrentProcess();
+  WindowsDbgHelp::symSetOptions(SYMOPT_FAIL_CRITICAL_ERRORS | SYMOPT_DEFERRED_LOADS |
+                        SYMOPT_EXACT_SYMBOLS | SYMOPT_LOAD_LINES);
+  if (!WindowsDbgHelp::symInitialize(hProcess, NULL, TRUE)) {
+    return;
+  }
+
+  // Note: we ignore any errors from this point on. The symbol engine may be
+  // usable enough.
+  g_state = state_ready;
+
+  (void)recalc_search_path_locked(NULL);
+
+}
+
+///////////////////// External functions //////////////////////////
+
+// All outside facing functions are synchronized. Also, we run
+// initialization on first touch.
+
+static CRITICAL_SECTION g_cs;
+
+namespace { // Do not export.
+  class SymbolEngineEntry {
+   public:
+    SymbolEngineEntry() {
+      ::EnterCriticalSection(&g_cs);
+      if (g_state == state_uninitialized) {
+        initialize();
+      }
+    }
+    ~SymbolEngineEntry() {
+      ::LeaveCriticalSection(&g_cs);
+    }
+  };
+}
+
+// Called at DLL_PROCESS_ATTACH.
+void SymbolEngine::pre_initialize() {
+  ::InitializeCriticalSection(&g_cs);
+}
+
+bool SymbolEngine::decode(const void* addr, char* buf, int buflen, int* offset, bool do_demangle) {
+
+  assert(buf != NULL && buflen > 0 && offset != NULL, "Argument error");
+  buf[0] = '\0';
+  *offset = -1;
+
+  if (addr == NULL) {
+    return false;
+  }
+
+  SymbolEngineEntry entry_guard;
+
+  // Try decoding the symbol once. If we fail, attempt to rebuild the
+  // symbol search path - maybe the pc points to a dll whose pdb file is
+  // outside our search path. Then do attempt the decode again.
+  bool success = decode_locked(addr, buf, buflen, offset, do_demangle);
+  if (!success) {
+    bool did_update_search_path = false;
+    if (recalc_search_path_locked(&did_update_search_path)) {
+      if (did_update_search_path) {
+        success = decode_locked(addr, buf, buflen, offset, do_demangle);
+      }
+    }
+  }
+
+  return success;
+
+}
+
+bool SymbolEngine::demangle(const char* symbol, char *buf, int buflen) {
+
+  SymbolEngineEntry entry_guard;
+
+  return demangle_locked(symbol, buf, buflen);
+
+}
+
+bool SymbolEngine::recalc_search_path(bool* p_search_path_was_updated) {
+
+  SymbolEngineEntry entry_guard;
+
+  return recalc_search_path_locked(p_search_path_was_updated);
+
+}
+
+bool SymbolEngine::get_source_info(const void* addr, char* buf, size_t buflen,
+                                   int* line_no)
+{
+  assert(buf != NULL && buflen > 0 && line_no != NULL, "Argument error");
+  buf[0] = '\0';
+  *line_no = -1;
+
+  if (addr == NULL) {
+    return false;
+  }
+
+  SymbolEngineEntry entry_guard;
+
+  IMAGEHLP_LINE64 lineinfo;
+  memset(&lineinfo, 0, sizeof(lineinfo));
+  lineinfo.SizeOfStruct = sizeof(lineinfo);
+  DWORD displacement;
+  if (WindowsDbgHelp::symGetLineFromAddr64(::GetCurrentProcess(), (DWORD64)addr,
+                                           &displacement, &lineinfo)) {
+    if (buf != NULL && buflen > 0 && lineinfo.FileName != NULL) {
+      // We only return the file name, not the whole path.
+      char* p = lineinfo.FileName;
+      char* q = strrchr(lineinfo.FileName, '\\');
+      if (q) {
+        p = q + 1;
+      }
+      ::strncpy(buf, p, buflen - 1);
+      buf[buflen - 1] = '\0';
+    }
+    if (line_no != 0) {
+      *line_no = lineinfo.LineNumber;
+    }
+    return true;
+  }
+  return false;
+}
+
+// Print one liner describing state (if library loaded, which functions are
+// missing - if any, and the dbhelp API version)
+void SymbolEngine::print_state_on(outputStream* st) {
+
+  SymbolEngineEntry entry_guard;
+
+  st->print("symbol engine: ");
+
+  if (g_state == state_uninitialized) {
+    st->print("uninitialized.");
+  } else if (g_state == state_error) {
+    st->print("initialization error.");
+  } else {
+    st->print("initialized successfully");
+    st->print(" - sym options: 0x%X", WindowsDbgHelp::symGetOptions());
+    st->print(" - pdb path: ");
+    if (WindowsDbgHelp::symGetSearchPath(::GetCurrentProcess(),
+                                          g_buffers.search_path.ptr(),
+                                          (int)g_buffers.search_path.capacity())) {
+      st->print_raw(g_buffers.search_path.ptr());
+    } else {
+      st->print_raw("(cannot be retrieved)");
+    }
+  }
+  st->cr();
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/windows/symbolengine.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef OS_WINDOWS_VM_SYMBOLENGINE_HPP
+#define OS_WINDOWS_VM_SYMBOLENGINE_HPP
+
+class outputStream;
+
+namespace SymbolEngine {
+
+  bool decode(const void* addr, char* buf, int buflen, int* offset, bool do_demangle);
+
+  bool demangle(const char* symbol, char *buf, int buflen);
+
+  // given an address, attempts to retrieve the source file and line number.
+  bool get_source_info(const void* addr, char* filename, size_t filename_len,
+                       int* line_no);
+
+  // Scan the loaded modules. Add all directories for all loaded modules
+  //  to the current search path, unless they are already part of the search
+  //    path. Prior search path content is preserved, directories are only
+  //   added, never removed.
+  // If p_search_path_was_updated is not NULL, points to a bool which, upon
+  //   successful return from the function, contains true if the search path
+  //   was updated, false if no update was needed because no new DLLs were
+  //   loaded or unloaded.
+  // Returns true for success, false for error.
+  bool recalc_search_path(bool* p_search_path_was_updated = NULL);
+
+  // Print one liner describing state (if library loaded, which functions are
+  // missing - if any, and the dbhelp API version)
+  void print_state_on(outputStream* st);
+
+  // Call at DLL_PROCESS_ATTACH.
+  void pre_initialize();
+
+};
+
+#endif // #ifndef OS_WINDOWS_VM_SYMBOLENGINE_HPP
+
+
--- a/src/hotspot/os/windows/windbghelp.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os/windows/windbghelp.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -116,38 +116,36 @@
 
 }
 
+
 ///////////////////// External functions //////////////////////////
 
 // All outside facing functions are synchronized. Also, we run
 // initialization on first touch.
 
-
-// Call InitializeCriticalSection as early as possible.
-class CritSect {
-  CRITICAL_SECTION cs;
-public:
-  CritSect() { ::InitializeCriticalSection(&cs); }
-  void enter() { ::EnterCriticalSection(&cs); }
-  void leave() { ::LeaveCriticalSection(&cs); }
-};
-
-static CritSect g_cs;
+static CRITICAL_SECTION g_cs;
 
-class EntryGuard {
-public:
-  EntryGuard() {
-    g_cs.enter();
-    if (g_state == state_uninitialized) {
-      initialize();
+namespace { // Do not export.
+  class WindowsDbgHelpEntry {
+   public:
+    WindowsDbgHelpEntry() {
+      ::EnterCriticalSection(&g_cs);
+      if (g_state == state_uninitialized) {
+        initialize();
+      }
     }
-  }
-  ~EntryGuard() {
-    g_cs.leave();
-  }
-};
+    ~WindowsDbgHelpEntry() {
+      ::LeaveCriticalSection(&g_cs);
+    }
+  };
+}
+
+// Called at DLL_PROCESS_ATTACH.
+void WindowsDbgHelp::pre_initialize() {
+  ::InitializeCriticalSection(&g_cs);
+}
 
 DWORD WindowsDbgHelp::symSetOptions(DWORD arg) {
-  EntryGuard entry_guard;
+  WindowsDbgHelpEntry entry_guard;
   if (g_pfn_SymSetOptions != NULL) {
     return g_pfn_SymSetOptions(arg);
   }
@@ -155,7 +153,7 @@
 }
 
 DWORD WindowsDbgHelp::symGetOptions(void) {
-  EntryGuard entry_guard;
+  WindowsDbgHelpEntry entry_guard;
   if (g_pfn_SymGetOptions != NULL) {
     return g_pfn_SymGetOptions();
   }
@@ -163,7 +161,7 @@
 }
 
 BOOL WindowsDbgHelp::symInitialize(HANDLE hProcess, PCTSTR UserSearchPath, BOOL fInvadeProcess) {
-  EntryGuard entry_guard;
+  WindowsDbgHelpEntry entry_guard;
   if (g_pfn_SymInitialize != NULL) {
     return g_pfn_SymInitialize(hProcess, UserSearchPath, fInvadeProcess);
   }
@@ -172,7 +170,7 @@
 
 BOOL WindowsDbgHelp::symGetSymFromAddr64(HANDLE hProcess, DWORD64 the_address,
                                          PDWORD64 Displacement, PIMAGEHLP_SYMBOL64 Symbol) {
-  EntryGuard entry_guard;
+  WindowsDbgHelpEntry entry_guard;
   if (g_pfn_SymGetSymFromAddr64 != NULL) {
     return g_pfn_SymGetSymFromAddr64(hProcess, the_address, Displacement, Symbol);
   }
@@ -181,7 +179,7 @@
 
 DWORD WindowsDbgHelp::unDecorateSymbolName(const char* DecoratedName, char* UnDecoratedName,
                                            DWORD UndecoratedLength, DWORD Flags) {
-  EntryGuard entry_guard;
+  WindowsDbgHelpEntry entry_guard;
   if (g_pfn_UnDecorateSymbolName != NULL) {
     return g_pfn_UnDecorateSymbolName(DecoratedName, UnDecoratedName, UndecoratedLength, Flags);
   }
@@ -192,7 +190,7 @@
 }
 
 BOOL WindowsDbgHelp::symSetSearchPath(HANDLE hProcess, PCTSTR SearchPath) {
-  EntryGuard entry_guard;
+  WindowsDbgHelpEntry entry_guard;
   if (g_pfn_SymSetSearchPath != NULL) {
     return g_pfn_SymSetSearchPath(hProcess, SearchPath);
   }
@@ -200,7 +198,7 @@
 }
 
 BOOL WindowsDbgHelp::symGetSearchPath(HANDLE hProcess, PTSTR SearchPath, int SearchPathLength) {
-  EntryGuard entry_guard;
+  WindowsDbgHelpEntry entry_guard;
   if (g_pfn_SymGetSearchPath != NULL) {
     return g_pfn_SymGetSearchPath(hProcess, SearchPath, SearchPathLength);
   }
@@ -212,7 +210,7 @@
                                  HANDLE hThread,
                                  LPSTACKFRAME64 StackFrame,
                                  PVOID ContextRecord) {
-  EntryGuard entry_guard;
+  WindowsDbgHelpEntry entry_guard;
   if (g_pfn_StackWalk64 != NULL) {
     return g_pfn_StackWalk64(MachineType, hProcess, hThread, StackFrame,
                              ContextRecord,
@@ -226,7 +224,7 @@
 }
 
 PVOID WindowsDbgHelp::symFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase) {
-  EntryGuard entry_guard;
+  WindowsDbgHelpEntry entry_guard;
   if (g_pfn_SymFunctionTableAccess64 != NULL) {
     return g_pfn_SymFunctionTableAccess64(hProcess, AddrBase);
   }
@@ -234,7 +232,7 @@
 }
 
 DWORD64 WindowsDbgHelp::symGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr) {
-  EntryGuard entry_guard;
+  WindowsDbgHelpEntry entry_guard;
   if (g_pfn_SymGetModuleBase64 != NULL) {
     return g_pfn_SymGetModuleBase64(hProcess, dwAddr);
   }
@@ -245,7 +243,7 @@
                                        MINIDUMP_TYPE DumpType, PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
                                        PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
                                        PMINIDUMP_CALLBACK_INFORMATION CallbackParam) {
-  EntryGuard entry_guard;
+  WindowsDbgHelpEntry entry_guard;
   if (g_pfn_MiniDumpWriteDump != NULL) {
     return g_pfn_MiniDumpWriteDump(hProcess, ProcessId, hFile, DumpType,
                                    ExceptionParam, UserStreamParam, CallbackParam);
@@ -255,7 +253,7 @@
 
 BOOL WindowsDbgHelp::symGetLineFromAddr64(HANDLE hProcess, DWORD64 dwAddr,
                           PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line) {
-  EntryGuard entry_guard;
+  WindowsDbgHelpEntry entry_guard;
   if (g_pfn_SymGetLineFromAddr64 != NULL) {
     return g_pfn_SymGetLineFromAddr64(hProcess, dwAddr, pdwDisplacement, Line);
   }
--- a/src/hotspot/os/windows/windbghelp.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os/windows/windbghelp.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -66,6 +66,9 @@
   // missing - if any, and the dbhelp API version)
   void print_state_on(outputStream* st);
 
+  // Call at DLL_PROCESS_ATTACH.
+  void pre_initialize();
+
 };
 
 
--- a/src/hotspot/os_cpu/aix_ppc/atomic_aix_ppc.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os_cpu/aix_ppc/atomic_aix_ppc.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -137,7 +137,7 @@
 inline T Atomic::PlatformXchg<4>::operator()(T exchange_value,
                                              T volatile* dest) const {
   STATIC_ASSERT(4 == sizeof(T));
-  // Note that xchg_ptr doesn't necessarily do an acquire
+  // Note that xchg doesn't necessarily do an acquire
   // (see synchronizer.cpp).
 
   T old_value;
@@ -176,7 +176,7 @@
 inline T Atomic::PlatformXchg<8>::operator()(T exchange_value,
                                              T volatile* dest) const {
   STATIC_ASSERT(8 == sizeof(T));
-  // Note that xchg_ptr doesn't necessarily do an acquire
+  // Note that xchg doesn't necessarily do an acquire
   // (see synchronizer.cpp).
 
   T old_value;
--- a/src/hotspot/os_cpu/linux_ppc/atomic_linux_ppc.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os_cpu/linux_ppc/atomic_linux_ppc.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -134,7 +134,7 @@
 template<typename T>
 inline T Atomic::PlatformXchg<4>::operator()(T exchange_value,
                                              T volatile* dest) const {
-  // Note that xchg_ptr doesn't necessarily do an acquire
+  // Note that xchg doesn't necessarily do an acquire
   // (see synchronizer.cpp).
 
   T old_value;
@@ -173,7 +173,7 @@
 inline T Atomic::PlatformXchg<8>::operator()(T exchange_value,
                                              T volatile* dest) const {
   STATIC_ASSERT(8 == sizeof(T));
-  // Note that xchg_ptr doesn't necessarily do an acquire
+  // Note that xchg doesn't necessarily do an acquire
   // (see synchronizer.cpp).
 
   T old_value;
--- a/src/hotspot/os_cpu/windows_x86/atomic_windows_x86.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os_cpu/windows_x86/atomic_windows_x86.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -73,7 +73,7 @@
   }
 
 DEFINE_STUB_XCHG(4, jint, os::atomic_xchg_func)
-DEFINE_STUB_XCHG(8, jlong, os::atomic_xchg_ptr_func)
+DEFINE_STUB_XCHG(8, jlong, os::atomic_xchg_long_func)
 
 #undef DEFINE_STUB_XCHG
 
--- a/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -50,6 +50,7 @@
 #include "runtime/stubRoutines.hpp"
 #include "runtime/thread.inline.hpp"
 #include "runtime/timer.hpp"
+#include "symbolengine.hpp"
 #include "unwind_windows_x86.hpp"
 #include "utilities/events.hpp"
 #include "utilities/vmError.hpp"
@@ -219,7 +220,7 @@
 // Atomics and Stub Functions
 
 typedef jint      xchg_func_t            (jint,     volatile jint*);
-typedef intptr_t  xchg_ptr_func_t        (intptr_t, volatile intptr_t*);
+typedef intptr_t  xchg_long_func_t       (jlong,    volatile jlong*);
 typedef jint      cmpxchg_func_t         (jint,     volatile jint*,  jint);
 typedef jbyte     cmpxchg_byte_func_t    (jbyte,    volatile jbyte*, jbyte);
 typedef jlong     cmpxchg_long_func_t    (jlong,    volatile jlong*, jlong);
@@ -243,12 +244,12 @@
   return old_value;
 }
 
-intptr_t os::atomic_xchg_ptr_bootstrap(intptr_t exchange_value, volatile intptr_t* dest) {
+intptr_t os::atomic_xchg_long_bootstrap(jlong exchange_value, volatile jlong* dest) {
   // try to use the stub:
-  xchg_ptr_func_t* func = CAST_TO_FN_PTR(xchg_ptr_func_t*, StubRoutines::atomic_xchg_ptr_entry());
+  xchg_long_func_t* func = CAST_TO_FN_PTR(xchg_long_func_t*, StubRoutines::atomic_xchg_long_entry());
 
   if (func != NULL) {
-    os::atomic_xchg_ptr_func = func;
+    os::atomic_xchg_long_func = func;
     return (*func)(exchange_value, dest);
   }
   assert(Threads::number_of_threads() == 0, "for bootstrap only");
@@ -338,7 +339,7 @@
 }
 
 xchg_func_t*         os::atomic_xchg_func         = os::atomic_xchg_bootstrap;
-xchg_ptr_func_t*     os::atomic_xchg_ptr_func     = os::atomic_xchg_ptr_bootstrap;
+xchg_long_func_t*    os::atomic_xchg_long_func    = os::atomic_xchg_long_bootstrap;
 cmpxchg_func_t*      os::atomic_cmpxchg_func      = os::atomic_cmpxchg_bootstrap;
 cmpxchg_byte_func_t* os::atomic_cmpxchg_byte_func = os::atomic_cmpxchg_byte_bootstrap;
 add_func_t*          os::atomic_add_func          = os::atomic_add_bootstrap;
@@ -397,6 +398,12 @@
         // may not contain what Java expects, and may cause the frame() constructor
         // to crash. Let's just print out the symbolic address.
         frame::print_C_frame(st, buf, buf_size, pc);
+        // print source file and line, if available
+        char buf[128];
+        int line_no;
+        if (SymbolEngine::get_source_info(pc, buf, sizeof(buf), &line_no)) {
+          st->print("  (%s:%d)", buf, line_no);
+        }
         st->cr();
       }
       lastpc = pc;
--- a/src/hotspot/os_cpu/windows_x86/os_windows_x86.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/os_cpu/windows_x86/os_windows_x86.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -30,7 +30,7 @@
   //
 #ifdef AMD64
   static jint      (*atomic_xchg_func)          (jint,      volatile jint*);
-  static intptr_t  (*atomic_xchg_ptr_func)      (intptr_t,  volatile intptr_t*);
+  static intptr_t  (*atomic_xchg_long_func)     (jlong,     volatile jlong*);
 
   static jint      (*atomic_cmpxchg_func)       (jint,      volatile jint*,  jint);
   static jbyte     (*atomic_cmpxchg_byte_func)  (jbyte,     volatile jbyte*, jbyte);
@@ -40,7 +40,7 @@
   static intptr_t  (*atomic_add_ptr_func)       (intptr_t,  volatile intptr_t*);
 
   static jint      atomic_xchg_bootstrap        (jint,      volatile jint*);
-  static intptr_t  atomic_xchg_ptr_bootstrap    (intptr_t,  volatile intptr_t*);
+  static intptr_t  atomic_xchg_long_bootstrap   (jlong,     volatile jlong*);
 
   static jint      atomic_cmpxchg_bootstrap     (jint,      volatile jint*,  jint);
   static jbyte     atomic_cmpxchg_byte_bootstrap(jbyte,     volatile jbyte*, jbyte);
--- a/src/hotspot/share/aot/aotCodeHeap.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/aot/aotCodeHeap.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -60,7 +60,14 @@
       fatal("Shared file %s error: klass %s should be resolved already", _lib->name(), klass_name);
       vm_exit(1);
     }
+    // Patch now to avoid extra runtime lookup
     _klasses_got[klass_data->_got_index] = k;
+    if (k->is_instance_klass()) {
+      InstanceKlass* ik = InstanceKlass::cast(k);
+      if (ik->is_initialized()) {
+        _klasses_got[klass_data->_got_index - 1] = ik;
+      }
+    }
   }
   return k;
 }
@@ -433,6 +440,7 @@
     SET_AOT_GLOBAL_SYMBOL_VALUE("_aot_exception_handler_for_return_address", address, SharedRuntime::exception_handler_for_return_address);
     SET_AOT_GLOBAL_SYMBOL_VALUE("_aot_register_finalizer", address, SharedRuntime::register_finalizer);
     SET_AOT_GLOBAL_SYMBOL_VALUE("_aot_OSR_migration_end", address, SharedRuntime::OSR_migration_end);
+    SET_AOT_GLOBAL_SYMBOL_VALUE("_aot_resolve_dynamic_invoke", address, CompilerRuntime::resolve_dynamic_invoke);
     SET_AOT_GLOBAL_SYMBOL_VALUE("_aot_resolve_string_by_symbol", address, CompilerRuntime::resolve_string_by_symbol);
     SET_AOT_GLOBAL_SYMBOL_VALUE("_aot_resolve_klass_by_symbol", address, CompilerRuntime::resolve_klass_by_symbol);
     SET_AOT_GLOBAL_SYMBOL_VALUE("_aot_resolve_method_by_symbol_and_load_counters", address, CompilerRuntime::resolve_method_by_symbol_and_load_counters);
@@ -609,9 +617,13 @@
   return m;
 }
 
+AOTKlassData* AOTCodeHeap::find_klass(const char *name) {
+  return (AOTKlassData*) os::dll_lookup(_lib->dl_handle(), name);
+}
+
 AOTKlassData* AOTCodeHeap::find_klass(InstanceKlass* ik) {
   ResourceMark rm;
-  AOTKlassData* klass_data = (AOTKlassData*) os::dll_lookup(_lib->dl_handle(), ik->signature_name());
+  AOTKlassData* klass_data = find_klass(ik->signature_name());
   return klass_data;
 }
 
@@ -640,35 +652,52 @@
   return false;
 }
 
+void AOTCodeHeap::sweep_dependent_methods(int* indexes, int methods_cnt) {
+  int marked = 0;
+  for (int i = 0; i < methods_cnt; ++i) {
+    int code_id = indexes[i];
+    // Invalidate aot code.
+    if (Atomic::cmpxchg(invalid, &_code_to_aot[code_id]._state, not_set) != not_set) {
+      if (_code_to_aot[code_id]._state == in_use) {
+        AOTCompiledMethod* aot = _code_to_aot[code_id]._aot;
+        assert(aot != NULL, "aot should be set");
+        if (!aot->is_runtime_stub()) { // Something is wrong - should not invalidate stubs.
+          aot->mark_for_deoptimization(false);
+          marked++;
+        }
+      }
+    }
+  }
+  if (marked > 0) {
+    VM_Deoptimize op;
+    VMThread::execute(&op);
+  }
+}
+
 void AOTCodeHeap::sweep_dependent_methods(AOTKlassData* klass_data) {
   // Make dependent methods non_entrant forever.
   int methods_offset = klass_data->_dependent_methods_offset;
   if (methods_offset >= 0) {
-    int marked = 0;
     address methods_cnt_adr = _dependencies + methods_offset;
     int methods_cnt = *(int*)methods_cnt_adr;
     int* indexes = (int*)(methods_cnt_adr + 4);
-    for (int i = 0; i < methods_cnt; ++i) {
-      int code_id = indexes[i];
-      // Invalidate aot code.
-      if (Atomic::cmpxchg(invalid, &_code_to_aot[code_id]._state, not_set) != not_set) {
-        if (_code_to_aot[code_id]._state == in_use) {
-          AOTCompiledMethod* aot = _code_to_aot[code_id]._aot;
-          assert(aot != NULL, "aot should be set");
-          if (!aot->is_runtime_stub()) { // Something is wrong - should not invalidate stubs.
-            aot->mark_for_deoptimization(false);
-            marked++;
-          }
-        }
-      }
-    }
-    if (marked > 0) {
-      VM_Deoptimize op;
-      VMThread::execute(&op);
-    }
+    sweep_dependent_methods(indexes, methods_cnt);
   }
 }
 
+void AOTCodeHeap::sweep_dependent_methods(InstanceKlass* ik) {
+  AOTKlassData* klass_data = find_klass(ik);
+  vmassert(klass_data != NULL, "dependency data missing");
+  sweep_dependent_methods(klass_data);
+}
+
+void AOTCodeHeap::sweep_method(AOTCompiledMethod *aot) {
+  int indexes[] = {aot->method_index()};
+  sweep_dependent_methods(indexes, 1);
+  vmassert(aot->method()->code() != aot && aot->method()->aot_code() == NULL, "method still active");
+}
+
+
 bool AOTCodeHeap::load_klass_data(InstanceKlass* ik, Thread* thread) {
   ResourceMark rm;
 
@@ -718,6 +747,9 @@
   aot_class->_classloader = ik->class_loader_data();
   // Set klass's Resolve (second) got cell.
   _klasses_got[klass_data->_got_index] = ik;
+  if (ik->is_initialized()) {
+    _klasses_got[klass_data->_got_index - 1] = ik;
+  }
 
   // Initialize global symbols of the DSO to the corresponding VM symbol values.
   link_global_lib_symbols();
@@ -837,7 +869,7 @@
       f(md);
     } else {
       intptr_t meta = (intptr_t)md;
-      fatal("Invalid value in _metaspace_got[%d] = " INTPTR_FORMAT, i, meta);
+      fatal("Invalid value in _klasses_got[%d] = " INTPTR_FORMAT, i, meta);
     }
   }
 }
@@ -886,6 +918,127 @@
       aot->metadata_do(f);
     }
   }
-  // Scan metaspace_got cells.
+  // Scan klasses_got cells.
   got_metadata_do(f);
 }
+
+bool AOTCodeHeap::reconcile_dynamic_klass(AOTCompiledMethod *caller, InstanceKlass* holder, int index, Klass *dyno_klass, const char *descriptor1, const char *descriptor2) {
+  const char * const descriptors[2] = {descriptor1, descriptor2};
+  JavaThread *thread = JavaThread::current();
+  ResourceMark rm(thread);
+
+  AOTKlassData* holder_data = find_klass(holder);
+  vmassert(holder_data != NULL, "klass %s not found", holder->signature_name());
+  vmassert(is_dependent_method(holder, caller), "sanity");
+
+  AOTKlassData* dyno_data = NULL;
+  bool adapter_failed = false;
+  char buf[64];
+  int descriptor_index = 0;
+  // descriptors[0] specific name ("adapter:<method_id>") for matching
+  // descriptors[1] fall-back name ("adapter") for depdencies
+  while (descriptor_index < 2) {
+    const char *descriptor = descriptors[descriptor_index];
+    if (descriptor == NULL) {
+      break;
+    }
+    jio_snprintf(buf, sizeof buf, "%s<%d:%d>", descriptor, holder_data->_class_id, index);
+    dyno_data = find_klass(buf);
+    if (dyno_data != NULL) {
+      break;
+    }
+    // If match failed then try fall-back for dependencies
+    ++descriptor_index;
+    adapter_failed = true;
+  }
+
+  if (dyno_data == NULL && dyno_klass == NULL) {
+    // all is well, no (appendix) at compile-time, and still none
+    return true;
+  }
+
+  if (dyno_data == NULL) {
+    // no (appendix) at build-time, but now there is
+    sweep_dependent_methods(holder_data);
+    return false;
+  }
+
+  if (adapter_failed) {
+    // adapter method mismatch
+    sweep_dependent_methods(holder_data);
+    sweep_dependent_methods(dyno_data);
+    return false;
+  }
+
+  if (dyno_klass == NULL) {
+    // (appendix) at build-time, none now
+    sweep_dependent_methods(holder_data);
+    sweep_dependent_methods(dyno_data);
+    return false;
+  }
+
+  // TODO: support array appendix object
+  if (!dyno_klass->is_instance_klass()) {
+    sweep_dependent_methods(holder_data);
+    sweep_dependent_methods(dyno_data);
+    return false;
+  }
+
+  InstanceKlass* dyno = InstanceKlass::cast(dyno_klass);
+
+  if (!dyno->is_anonymous()) {
+    if (_klasses_got[dyno_data->_got_index] != dyno) {
+      // compile-time class different from runtime class, fail and deoptimize
+      sweep_dependent_methods(holder_data);
+      sweep_dependent_methods(dyno_data);
+      return false;
+    }
+
+    if (dyno->is_initialized()) {
+      _klasses_got[dyno_data->_got_index - 1] = dyno;
+    }
+    return true;
+  }
+
+  // TODO: support anonymous supers
+  if (!dyno->supers_have_passed_fingerprint_checks() || dyno->get_stored_fingerprint() != dyno_data->_fingerprint) {
+      NOT_PRODUCT( aot_klasses_fp_miss++; )
+      log_trace(aot, class, fingerprint)("class  %s%s  has bad fingerprint in  %s tid=" INTPTR_FORMAT,
+          dyno->internal_name(), dyno->is_shared() ? " (shared)" : "",
+          _lib->name(), p2i(thread));
+    sweep_dependent_methods(holder_data);
+    sweep_dependent_methods(dyno_data);
+    return false;
+  }
+
+  _klasses_got[dyno_data->_got_index] = dyno;
+  if (dyno->is_initialized()) {
+    _klasses_got[dyno_data->_got_index - 1] = dyno;
+  }
+
+  // TODO: hook up any AOT code
+  // load_klass_data(dyno_data, thread);
+  return true;
+}
+
+bool AOTCodeHeap::reconcile_dynamic_method(AOTCompiledMethod *caller, InstanceKlass* holder, int index, Method *adapter_method) {
+    InstanceKlass *adapter_klass = adapter_method->method_holder();
+    char buf[64];
+    jio_snprintf(buf, sizeof buf, "adapter:%d", adapter_method->method_idnum());
+    if (!reconcile_dynamic_klass(caller, holder, index, adapter_klass, buf, "adapter")) {
+      return false;
+    }
+    return true;
+}
+
+bool AOTCodeHeap::reconcile_dynamic_invoke(AOTCompiledMethod* caller, InstanceKlass* holder, int index, Method* adapter_method, Klass *appendix_klass) {
+    if (!reconcile_dynamic_klass(caller, holder, index, appendix_klass, "appendix")) {
+      return false;
+    }
+
+    if (!reconcile_dynamic_method(caller, holder, index, adapter_method)) {
+      return false;
+    }
+
+    return true;
+}
--- a/src/hotspot/share/aot/aotCodeHeap.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/aot/aotCodeHeap.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -241,13 +241,14 @@
   AOTKlassData* find_klass(InstanceKlass* ik);
   bool load_klass_data(InstanceKlass* ik, Thread* thread);
   Klass* get_klass_from_got(const char* klass_name, int klass_len, const Method* method);
-  void sweep_dependent_methods(AOTKlassData* klass_data);
+
   bool is_dependent_method(Klass* dependee, AOTCompiledMethod* aot);
 
   const char* get_name_at(int offset) {
     return _metaspace_names + offset;
   }
 
+
   void oops_do(OopClosure* f);
   void metadata_do(void f(Metadata*));
   void got_metadata_do(void f(Metadata*));
@@ -294,6 +295,21 @@
 
   static void print_statistics();
 #endif
+
+  bool reconcile_dynamic_invoke(AOTCompiledMethod* caller, InstanceKlass* holder, int index, Method* adapter_method, Klass *appendix_klass);
+
+private:
+  AOTKlassData* find_klass(const char* name);
+
+  void sweep_dependent_methods(int* indexes, int methods_cnt);
+  void sweep_dependent_methods(AOTKlassData* klass_data);
+  void sweep_dependent_methods(InstanceKlass* ik);
+  void sweep_method(AOTCompiledMethod* aot);
+
+  bool reconcile_dynamic_klass(AOTCompiledMethod *caller, InstanceKlass* holder, int index, Klass *dyno, const char *descriptor1, const char *descriptor2 = NULL);
+
+  bool reconcile_dynamic_method(AOTCompiledMethod *caller, InstanceKlass* holder, int index, Method *adapter_method);
+
 };
 
 #endif // SHARE_VM_AOT_AOTCODEHEAP_HPP
--- a/src/hotspot/share/aot/aotLoader.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/aot/aotLoader.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -40,6 +40,10 @@
 #define FOR_ALL_AOT_LIBRARIES(lib) for (GrowableArrayIterator<AOTLib*> lib = libraries()->begin(); lib != libraries()->end(); ++lib)
 
 void AOTLoader::load_for_klass(InstanceKlass* ik, Thread* thread) {
+  if (ik->is_anonymous()) {
+    // don't even bother
+    return;
+  }
   if (UseAOT) {
     FOR_ALL_AOT_HEAPS(heap) {
       (*heap)->load_klass_data(ik, thread);
@@ -48,6 +52,10 @@
 }
 
 uint64_t AOTLoader::get_saved_fingerprint(InstanceKlass* ik) {
+  if (ik->is_anonymous()) {
+    // don't even bother
+    return 0;
+  }
   FOR_ALL_AOT_HEAPS(heap) {
     AOTKlassData* klass_data = (*heap)->find_klass(ik);
     if (klass_data != NULL) {
@@ -259,3 +267,34 @@
   }
 }
 #endif
+
+
+bool AOTLoader::reconcile_dynamic_invoke(InstanceKlass* holder, int index, Method* adapter_method, Klass* appendix_klass) {
+  if (!UseAOT) {
+    return true;
+  }
+  JavaThread* thread = JavaThread::current();
+  ResourceMark rm(thread);
+  RegisterMap map(thread, false);
+  frame caller_frame = thread->last_frame().sender(&map); // Skip stub
+  CodeBlob* caller_cb = caller_frame.cb();
+  guarantee(caller_cb != NULL && caller_cb->is_compiled(), "must be called from compiled method");
+  CompiledMethod* cm = caller_cb->as_compiled_method();
+
+  if (!cm->is_aot()) {
+    return true;
+  }
+  AOTCompiledMethod* aot = (AOTCompiledMethod*)cm;
+
+  AOTCodeHeap* caller_heap = NULL;
+  FOR_ALL_AOT_HEAPS(heap) {
+    if ((*heap)->contains_blob(aot)) {
+      caller_heap = *heap;
+      break;
+    }
+  }
+  guarantee(caller_heap != NULL, "CodeHeap not found");
+  bool success = caller_heap->reconcile_dynamic_invoke(aot, holder, index, adapter_method, appendix_klass);
+  vmassert(success || thread->last_frame().sender(&map).is_deoptimized_frame(), "caller not deoptimized on failure");
+  return success;
+}
--- a/src/hotspot/share/aot/aotLoader.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/aot/aotLoader.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -28,6 +28,7 @@
 #include "runtime/handles.hpp"
 
 class AOTCodeHeap;
+class AOTCompiledMethod;
 class AOTLib;
 class CodeBlob;
 template <class T> class GrowableArray;
@@ -71,6 +72,7 @@
   static void flush_evol_dependents_on(InstanceKlass* dependee) NOT_AOT_RETURN;
 #endif // HOTSWAP
 
+  static bool reconcile_dynamic_invoke(InstanceKlass* holder, int index, Method* adapter_method, Klass *appendix_klass) NOT_AOT({ return true; });
 };
 
 #endif // SHARE_VM_AOT_AOTLOADER_HPP
--- a/src/hotspot/share/asm/assembler.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/asm/assembler.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -236,11 +236,9 @@
     if (dcon->match(type, cfn))
       return dcon;
     if (dcon->value_fn == NULL) {
-      // (cmpxchg not because this is multi-threaded but because I'm paranoid)
-      if (Atomic::cmpxchg_ptr(CAST_FROM_FN_PTR(void*, cfn), &dcon->value_fn, NULL) == NULL) {
+        dcon->value_fn = cfn;
         dcon->type = type;
         return dcon;
-      }
     }
   }
   // If this assert is hit (in pre-integration testing!) then re-evaluate
--- a/src/hotspot/share/c1/c1_Runtime1.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/c1/c1_Runtime1.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1221,11 +1221,6 @@
     MutexLockerEx ml_code (CodeCache_lock, Mutex::_no_safepoint_check_flag);
     nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
     guarantee(nm != NULL, "only nmethods can contain non-perm oops");
-    if (!nm->on_scavenge_root_list() &&
-        ((mirror.not_null() && mirror()->is_scavengable()) ||
-         (appendix.not_null() && appendix->is_scavengable()))) {
-      CodeCache::add_scavenge_root_nmethod(nm);
-    }
 
     // Since we've patched some oops in the nmethod,
     // (re)register it with the heap.
@@ -1377,8 +1372,6 @@
   // barrier. The assert will fail if this is not the case.
   // Note that we use the non-virtual inlineable variant of write_ref_array.
   BarrierSet* bs = Universe::heap()->barrier_set();
-  assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
-  assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");
   if (src == dst) {
     // same object, no check
     bs->write_ref_array_pre(dst_addr, length);
--- a/src/hotspot/share/classfile/altHashing.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/classfile/altHashing.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -25,7 +25,7 @@
 #ifndef SHARE_VM_CLASSFILE_ALTHASHING_HPP
 #define SHARE_VM_CLASSFILE_ALTHASHING_HPP
 
-#include "prims/jni.h"
+#include "jni.h"
 #include "classfile/symbolTable.hpp"
 
 /**
--- a/src/hotspot/share/classfile/classLoader.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/classfile/classLoader.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -48,13 +48,11 @@
   ClassPathEntry* volatile _next;
 public:
   // Next entry in class path
-  ClassPathEntry* next() const {
-    return (ClassPathEntry*) OrderAccess::load_ptr_acquire(&_next);
-  }
+  ClassPathEntry* next() const { return OrderAccess::load_acquire(&_next); }
   virtual ~ClassPathEntry() {}
   void set_next(ClassPathEntry* next) {
     // may have unlocked readers, so ensure visibility.
-    OrderAccess::release_store_ptr(&_next, next);
+    OrderAccess::release_store(&_next, next);
   }
   virtual bool is_jrt() = 0;
   virtual bool is_jar_file() const = 0;
--- a/src/hotspot/share/classfile/classLoaderData.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/classfile/classLoaderData.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -82,11 +82,6 @@
 #include "trace/tracing.hpp"
 #endif
 
-// helper function to avoid in-line casts
-template <typename T> static T* load_ptr_acquire(T* volatile *p) {
-  return static_cast<T*>(OrderAccess::load_ptr_acquire(p));
-}
-
 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
 
 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
@@ -152,7 +147,7 @@
 oop* ClassLoaderData::ChunkedHandleList::add(oop o) {
   if (_head == NULL || _head->_size == Chunk::CAPACITY) {
     Chunk* next = new Chunk(_head);
-    OrderAccess::release_store_ptr(&_head, next);
+    OrderAccess::release_store(&_head, next);
   }
   oop* handle = &_head->_data[_head->_size];
   *handle = o;
@@ -169,7 +164,7 @@
 }
 
 void ClassLoaderData::ChunkedHandleList::oops_do(OopClosure* f) {
-  Chunk* head = (Chunk*) OrderAccess::load_ptr_acquire(&_head);
+  Chunk* head = OrderAccess::load_acquire(&_head);
   if (head != NULL) {
     // Must be careful when reading size of head
     oops_do_chunk(f, head, OrderAccess::load_acquire(&head->_size));
@@ -257,24 +252,24 @@
 }
 
 void ClassLoaderData::classes_do(KlassClosure* klass_closure) {
-  // Lock-free access requires load_ptr_acquire
-  for (Klass* k = load_ptr_acquire(&_klasses); k != NULL; k = k->next_link()) {
+  // Lock-free access requires load_acquire
+  for (Klass* k = OrderAccess::load_acquire(&_klasses); k != NULL; k = k->next_link()) {
     klass_closure->do_klass(k);
     assert(k != k->next_link(), "no loops!");
   }
 }
 
 void ClassLoaderData::classes_do(void f(Klass * const)) {
-  // Lock-free access requires load_ptr_acquire
-  for (Klass* k = load_ptr_acquire(&_klasses); k != NULL; k = k->next_link()) {
+  // Lock-free access requires load_acquire
+  for (Klass* k = OrderAccess::load_acquire(&_klasses); k != NULL; k = k->next_link()) {
     f(k);
     assert(k != k->next_link(), "no loops!");
   }
 }
 
 void ClassLoaderData::methods_do(void f(Method*)) {
-  // Lock-free access requires load_ptr_acquire
-  for (Klass* k = load_ptr_acquire(&_klasses); k != NULL; k = k->next_link()) {
+  // Lock-free access requires load_acquire
+  for (Klass* k = OrderAccess::load_acquire(&_klasses); k != NULL; k = k->next_link()) {
     if (k->is_instance_klass() && InstanceKlass::cast(k)->is_loaded()) {
       InstanceKlass::cast(k)->methods_do(f);
     }
@@ -282,8 +277,8 @@
 }
 
 void ClassLoaderData::loaded_classes_do(KlassClosure* klass_closure) {
-  // Lock-free access requires load_ptr_acquire
-  for (Klass* k = load_ptr_acquire(&_klasses); k != NULL; k = k->next_link()) {
+  // Lock-free access requires load_acquire
+  for (Klass* k = OrderAccess::load_acquire(&_klasses); k != NULL; k = k->next_link()) {
     // Do not filter ArrayKlass oops here...
     if (k->is_array_klass() || (k->is_instance_klass() && InstanceKlass::cast(k)->is_loaded())) {
       klass_closure->do_klass(k);
@@ -292,8 +287,8 @@
 }
 
 void ClassLoaderData::classes_do(void f(InstanceKlass*)) {
-  // Lock-free access requires load_ptr_acquire
-  for (Klass* k = load_ptr_acquire(&_klasses); k != NULL; k = k->next_link()) {
+  // Lock-free access requires load_acquire
+  for (Klass* k = OrderAccess::load_acquire(&_klasses); k != NULL; k = k->next_link()) {
     if (k->is_instance_klass()) {
       f(InstanceKlass::cast(k));
     }
@@ -449,7 +444,7 @@
     k->set_next_link(old_value);
     // Link the new item into the list, making sure the linked class is stable
     // since the list can be walked without a lock
-    OrderAccess::release_store_ptr(&_klasses, k);
+    OrderAccess::release_store(&_klasses, k);
   }
 
   if (publicize && k->class_loader_data() != NULL) {
@@ -589,8 +584,8 @@
 
 ModuleEntryTable* ClassLoaderData::modules() {
   // Lazily create the module entry table at first request.
-  // Lock-free access requires load_ptr_acquire.
-  ModuleEntryTable* modules = load_ptr_acquire(&_modules);
+  // Lock-free access requires load_acquire.
+  ModuleEntryTable* modules = OrderAccess::load_acquire(&_modules);
   if (modules == NULL) {
     MutexLocker m1(Module_lock);
     // Check if _modules got allocated while we were waiting for this lock.
@@ -600,7 +595,7 @@
       {
         MutexLockerEx m1(metaspace_lock(), Mutex::_no_safepoint_check_flag);
         // Ensure _modules is stable, since it is examined without a lock
-        OrderAccess::release_store_ptr(&_modules, modules);
+        OrderAccess::release_store(&_modules, modules);
       }
     }
   }
@@ -737,8 +732,8 @@
   // to create smaller arena for Reflection class loaders also.
   // The reason for the delayed allocation is because some class loaders are
   // simply for delegating with no metadata of their own.
-  // Lock-free access requires load_ptr_acquire.
-  Metaspace* metaspace = load_ptr_acquire(&_metaspace);
+  // Lock-free access requires load_acquire.
+  Metaspace* metaspace = OrderAccess::load_acquire(&_metaspace);
   if (metaspace == NULL) {
     MutexLockerEx ml(_metaspace_lock,  Mutex::_no_safepoint_check_flag);
     // Check if _metaspace got allocated while we were waiting for this lock.
@@ -760,7 +755,7 @@
         metaspace = new Metaspace(_metaspace_lock, Metaspace::StandardMetaspaceType);
       }
       // Ensure _metaspace is stable, since it is examined without a lock
-      OrderAccess::release_store_ptr(&_metaspace, metaspace);
+      OrderAccess::release_store(&_metaspace, metaspace);
     }
   }
   return metaspace;
@@ -914,8 +909,8 @@
 }
 
 bool ClassLoaderData::contains_klass(Klass* klass) {
-  // Lock-free access requires load_ptr_acquire
-  for (Klass* k = load_ptr_acquire(&_klasses); k != NULL; k = k->next_link()) {
+  // Lock-free access requires load_acquire
+  for (Klass* k = OrderAccess::load_acquire(&_klasses); k != NULL; k = k->next_link()) {
     if (k == klass) return true;
   }
   return false;
@@ -948,7 +943,7 @@
   if (!is_anonymous) {
     ClassLoaderData** cld_addr = java_lang_ClassLoader::loader_data_addr(loader());
     // First, Atomically set it
-    ClassLoaderData* old = (ClassLoaderData*) Atomic::cmpxchg_ptr(cld, cld_addr, NULL);
+    ClassLoaderData* old = Atomic::cmpxchg(cld, cld_addr, (ClassLoaderData*)NULL);
     if (old != NULL) {
       delete cld;
       // Returns the data.
@@ -963,7 +958,7 @@
 
   do {
     cld->set_next(next);
-    ClassLoaderData* exchanged = (ClassLoaderData*)Atomic::cmpxchg_ptr(cld, list_head, next);
+    ClassLoaderData* exchanged = Atomic::cmpxchg(cld, list_head, next);
     if (exchanged == next) {
       LogTarget(Debug, class, loader, data) lt;
       if (lt.is_enabled()) {
@@ -1387,7 +1382,7 @@
   while (head != NULL) {
     Klass* next = next_klass_in_cldg(head);
 
-    Klass* old_head = (Klass*)Atomic::cmpxchg_ptr(next, &_next_klass, head);
+    Klass* old_head = Atomic::cmpxchg(next, &_next_klass, head);
 
     if (old_head == head) {
       return head; // Won the CAS.
--- a/src/hotspot/share/classfile/classLoaderData.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/classfile/classLoaderData.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -194,7 +194,7 @@
       Chunk(Chunk* c) : _next(c), _size(0) { }
     };
 
-    Chunk* _head;
+    Chunk* volatile _head;
 
     void oops_do_chunk(OopClosure* f, Chunk* c, const juint size);
 
--- a/src/hotspot/share/classfile/dictionary.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/classfile/dictionary.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -161,10 +161,10 @@
   void set_pd_set(ProtectionDomainEntry* new_head) {  _pd_set = new_head; }
 
   ProtectionDomainEntry* pd_set_acquire() const    {
-    return (ProtectionDomainEntry*)OrderAccess::load_ptr_acquire(&_pd_set);
+    return OrderAccess::load_acquire(&_pd_set);
   }
   void release_set_pd_set(ProtectionDomainEntry* new_head) {
-    OrderAccess::release_store_ptr(&_pd_set, new_head);
+    OrderAccess::release_store(&_pd_set, new_head);
   }
 
   // Tells whether the initiating class' protection domain can access the klass in this entry
--- a/src/hotspot/share/classfile/jimage.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/classfile/jimage.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -22,7 +22,7 @@
  *
  */
 
-#include "prims/jni.h"
+#include "jni.h"
 
 // Opaque reference to a JImage file.
 class JImageFile;
--- a/src/hotspot/share/classfile/klassFactory.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/classfile/klassFactory.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -223,8 +223,8 @@
     result->set_cached_class_file(cached_class_file);
   }
 
-  if (InstanceKlass::should_store_fingerprint()) {
-    result->store_fingerprint(!result->is_anonymous() ? stream->compute_fingerprint() : 0);
+  if (result->should_store_fingerprint()) {
+    result->store_fingerprint(stream->compute_fingerprint());
   }
 
   TRACE_KLASS_CREATION(result, parser, THREAD);
--- a/src/hotspot/share/classfile/moduleEntry.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/classfile/moduleEntry.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -23,13 +23,13 @@
  */
 
 #include "precompiled.hpp"
+#include "jni.h"
 #include "classfile/classLoaderData.hpp"
 #include "classfile/javaClasses.hpp"
 #include "classfile/moduleEntry.hpp"
 #include "logging/log.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/symbol.hpp"
-#include "prims/jni.h"
 #include "runtime/handles.inline.hpp"
 #include "runtime/safepoint.hpp"
 #include "trace/traceMacros.hpp"
--- a/src/hotspot/share/classfile/moduleEntry.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/classfile/moduleEntry.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -25,11 +25,11 @@
 #ifndef SHARE_VM_CLASSFILE_MODULEENTRY_HPP
 #define SHARE_VM_CLASSFILE_MODULEENTRY_HPP
 
+#include "jni.h"
 #include "classfile/classLoaderData.hpp"
 #include "classfile/vmSymbols.hpp"
 #include "oops/oopHandle.hpp"
 #include "oops/symbol.hpp"
-#include "prims/jni.h"
 #include "runtime/jniHandles.hpp"
 #include "runtime/mutexLocker.hpp"
 #include "trace/traceMacros.hpp"
--- a/src/hotspot/share/classfile/verifier.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/classfile/verifier.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -69,14 +69,14 @@
 static volatile jint _is_new_verify_byte_codes_fn = (jint) true;
 
 static void* verify_byte_codes_fn() {
-  if (OrderAccess::load_ptr_acquire(&_verify_byte_codes_fn) == NULL) {
+  if (OrderAccess::load_acquire(&_verify_byte_codes_fn) == NULL) {
     void *lib_handle = os::native_java_library();
     void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion");
-    OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func);
+    OrderAccess::release_store(&_verify_byte_codes_fn, func);
     if (func == NULL) {
       _is_new_verify_byte_codes_fn = false;
       func = os::dll_lookup(lib_handle, "VerifyClassCodes");
-      OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func);
+      OrderAccess::release_store(&_verify_byte_codes_fn, func);
     }
   }
   return (void*)_verify_byte_codes_fn;
--- a/src/hotspot/share/code/codeCache.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/code/codeCache.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -683,22 +683,19 @@
       if (cb->is_alive()) {
         f->do_code_blob(cb);
 #ifdef ASSERT
-        if (cb->is_nmethod())
-        ((nmethod*)cb)->verify_scavenge_root_oops();
+        if (cb->is_nmethod()) {
+          Universe::heap()->verify_nmethod((nmethod*)cb);
+        }
 #endif //ASSERT
       }
     }
   }
 }
 
-// Walk the list of methods which might contain non-perm oops.
+// Walk the list of methods which might contain oops to the java heap.
 void CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure* f) {
   assert_locked_or_safepoint(CodeCache_lock);
 
-  if (UseG1GC) {
-    return;
-  }
-
   const bool fix_relocations = f->fix_relocations();
   debug_only(mark_scavenge_root_nmethods());
 
@@ -735,13 +732,20 @@
   debug_only(verify_perm_nmethods(NULL));
 }
 
+void CodeCache::register_scavenge_root_nmethod(nmethod* nm) {
+  assert_locked_or_safepoint(CodeCache_lock);
+  if (!nm->on_scavenge_root_list() && nm->detect_scavenge_root_oops()) {
+    add_scavenge_root_nmethod(nm);
+  }
+}
+
+void CodeCache::verify_scavenge_root_nmethod(nmethod* nm) {
+  nm->verify_scavenge_root_oops();
+}
+
 void CodeCache::add_scavenge_root_nmethod(nmethod* nm) {
   assert_locked_or_safepoint(CodeCache_lock);
 
-  if (UseG1GC) {
-    return;
-  }
-
   nm->set_on_scavenge_root_list();
   nm->set_scavenge_root_link(_scavenge_root_nmethods);
   set_scavenge_root_nmethods(nm);
@@ -754,8 +758,6 @@
   assert((prev == NULL && scavenge_root_nmethods() == nm) ||
          (prev != NULL && prev->scavenge_root_link() == nm), "precondition");
 
-  assert(!UseG1GC, "G1 does not use the scavenge_root_nmethods list");
-
   print_trace("unlink_scavenge_root", nm);
   if (prev == NULL) {
     set_scavenge_root_nmethods(nm->scavenge_root_link());
@@ -769,10 +771,6 @@
 void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) {
   assert_locked_or_safepoint(CodeCache_lock);
 
-  if (UseG1GC) {
-    return;
-  }
-
   print_trace("drop_scavenge_root", nm);
   nmethod* prev = NULL;
   for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
@@ -788,10 +786,6 @@
 void CodeCache::prune_scavenge_root_nmethods() {
   assert_locked_or_safepoint(CodeCache_lock);
 
-  if (UseG1GC) {
-    return;
-  }
-
   debug_only(mark_scavenge_root_nmethods());
 
   nmethod* last = NULL;
@@ -820,10 +814,6 @@
 
 #ifndef PRODUCT
 void CodeCache::asserted_non_scavengable_nmethods_do(CodeBlobClosure* f) {
-  if (UseG1GC) {
-    return;
-  }
-
   // While we are here, verify the integrity of the list.
   mark_scavenge_root_nmethods();
   for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
@@ -833,7 +823,7 @@
   verify_perm_nmethods(f);
 }
 
-// Temporarily mark nmethods that are claimed to be on the non-perm list.
+// Temporarily mark nmethods that are claimed to be on the scavenge list.
 void CodeCache::mark_scavenge_root_nmethods() {
   NMethodIterator iter;
   while(iter.next_alive()) {
@@ -854,7 +844,7 @@
     assert(nm->scavenge_root_not_marked(), "must be already processed");
     if (nm->on_scavenge_root_list())
       call_f = false;  // don't show this one to the client
-    nm->verify_scavenge_root_oops();
+    Universe::heap()->verify_nmethod(nm);
     if (call_f)  f_or_null->do_code_blob(nm);
   }
 }
@@ -1640,4 +1630,3 @@
             blob_count(), nmethod_count(), adapter_count(),
             unallocated_capacity());
 }
-
--- a/src/hotspot/share/code/codeCache.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/code/codeCache.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -181,6 +181,10 @@
   static void scavenge_root_nmethods_do(CodeBlobToOopClosure* f);
 
   static nmethod* scavenge_root_nmethods()            { return _scavenge_root_nmethods; }
+  // register_scavenge_root_nmethod() conditionally adds the nmethod to the list
+  // if it is not already on the list and has a scavengeable root
+  static void register_scavenge_root_nmethod(nmethod* nm);
+  static void verify_scavenge_root_nmethod(nmethod* nm);
   static void add_scavenge_root_nmethod(nmethod* nm);
   static void drop_scavenge_root_nmethod(nmethod* nm);
 
--- a/src/hotspot/share/code/compiledMethod.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/code/compiledMethod.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -288,7 +288,7 @@
   // Note: _exception_cache may be read concurrently. We rely on memory_order_consume here.
   ExceptionCache* exception_cache() const         { return _exception_cache; }
   void set_exception_cache(ExceptionCache *ec)    { _exception_cache = ec; }
-  void release_set_exception_cache(ExceptionCache *ec) { OrderAccess::release_store_ptr(&_exception_cache, ec); }
+  void release_set_exception_cache(ExceptionCache *ec) { OrderAccess::release_store(&_exception_cache, ec); }
   address handler_for_exception_and_pc(Handle exception, address pc);
   void add_handler_for_exception_and_pc(Handle exception, address pc, address handler);
   void clean_exception_cache(BoolObjectClosure* is_alive);
--- a/src/hotspot/share/code/jvmticmlr.h	Sat Oct 21 07:00:23 2017 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,115 +0,0 @@
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * This header file defines the data structures sent by the VM
- * through the JVMTI CompiledMethodLoad callback function via the
- * "void * compile_info" parameter. The memory pointed to by the
- * compile_info parameter may not be referenced after returning from
- * the CompiledMethodLoad callback. These are VM implementation
- * specific data structures that may evolve in future releases. A
- * JVMTI agent should interpret a non-NULL compile_info as a pointer
- * to a region of memory containing a list of records. In a typical
- * usage scenario, a JVMTI agent would cast each record to a
- * jvmtiCompiledMethodLoadRecordHeader, a struct that represents
- * arbitrary information. This struct contains a kind field to indicate
- * the kind of information being passed, and a pointer to the next
- * record. If the kind field indicates inlining information, then the
- * agent would cast the record to a jvmtiCompiledMethodLoadInlineRecord.
- * This record contains an array of PCStackInfo structs, which indicate
- * for every pc address what are the methods on the invocation stack.
- * The "methods" and "bcis" fields in each PCStackInfo struct specify a
- * 1-1 mapping between these inlined methods and their bytecode indices.
- * This can be used to derive the proper source lines of the inlined
- * methods.
- */
-
-#ifndef _JVMTI_CMLR_H_
-#define _JVMTI_CMLR_H_
-
-enum {
-    JVMTI_CMLR_MAJOR_VERSION_1 = 0x00000001,
-    JVMTI_CMLR_MINOR_VERSION_0 = 0x00000000,
-
-    JVMTI_CMLR_MAJOR_VERSION   = 0x00000001,
-    JVMTI_CMLR_MINOR_VERSION   = 0x00000000
-
-    /*
-     * This comment is for the "JDK import from HotSpot" sanity check:
-     * version: 1.0.0
-     */
-};
-
-typedef enum {
-    JVMTI_CMLR_DUMMY       = 1,
-    JVMTI_CMLR_INLINE_INFO = 2
-} jvmtiCMLRKind;
-
-/*
- * Record that represents arbitrary information passed through JVMTI
- * CompiledMethodLoadEvent void pointer.
- */
-typedef struct _jvmtiCompiledMethodLoadRecordHeader {
-  jvmtiCMLRKind kind;     /* id for the kind of info passed in the record */
-  jint majorinfoversion;  /* major and minor info version values. Init'ed */
-  jint minorinfoversion;  /* to current version value in jvmtiExport.cpp. */
-
-  struct _jvmtiCompiledMethodLoadRecordHeader* next;
-} jvmtiCompiledMethodLoadRecordHeader;
-
-/*
- * Record that gives information about the methods on the compile-time
- * stack at a specific pc address of a compiled method. Each element in
- * the methods array maps to same element in the bcis array.
- */
-typedef struct _PCStackInfo {
-  void* pc;             /* the pc address for this compiled method */
-  jint numstackframes;  /* number of methods on the stack */
-  jmethodID* methods;   /* array of numstackframes method ids */
-  jint* bcis;           /* array of numstackframes bytecode indices */
-} PCStackInfo;
-
-/*
- * Record that contains inlining information for each pc address of
- * an nmethod.
- */
-typedef struct _jvmtiCompiledMethodLoadInlineRecord {
-  jvmtiCompiledMethodLoadRecordHeader header;  /* common header for casting */
-  jint numpcs;          /* number of pc descriptors in this nmethod */
-  PCStackInfo* pcinfo;  /* array of numpcs pc descriptors */
-} jvmtiCompiledMethodLoadInlineRecord;
-
-/*
- * Dummy record used to test that we can pass records with different
- * information through the void pointer provided that they can be cast
- * to a jvmtiCompiledMethodLoadRecordHeader.
- */
-
-typedef struct _jvmtiCompiledMethodLoadDummyRecord {
-  jvmtiCompiledMethodLoadRecordHeader header;  /* common header for casting */
-  char message[50];
-} jvmtiCompiledMethodLoadDummyRecord;
-
-#endif
--- a/src/hotspot/share/code/nmethod.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/code/nmethod.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -411,11 +411,8 @@
   _oops_do_mark_link       = NULL;
   _jmethod_id              = NULL;
   _osr_link                = NULL;
-  if (UseG1GC) {
-    _unloading_next        = NULL;
-  } else {
-    _scavenge_root_link    = NULL;
-  }
+  _unloading_next          = NULL;
+  _scavenge_root_link      = NULL;
   _scavenge_root_state     = 0;
 #if INCLUDE_RTM_OPT
   _rtm_state               = NoRTM;
@@ -599,12 +596,9 @@
     code_buffer->copy_code_and_locs_to(this);
     code_buffer->copy_values_to(this);
     if (ScavengeRootsInCode) {
-      if (detect_scavenge_root_oops()) {
-        CodeCache::add_scavenge_root_nmethod(this);
-      }
       Universe::heap()->register_nmethod(this);
     }
-    debug_only(verify_scavenge_root_oops());
+    debug_only(Universe::heap()->verify_nmethod(this));
     CodeCache::commit(this);
   }
 
@@ -754,12 +748,9 @@
     debug_info->copy_to(this);
     dependencies->copy_to(this);
     if (ScavengeRootsInCode) {
-      if (detect_scavenge_root_oops()) {
-        CodeCache::add_scavenge_root_nmethod(this);
-      }
       Universe::heap()->register_nmethod(this);
     }
-    debug_only(verify_scavenge_root_oops());
+    debug_only(Universe::heap()->verify_nmethod(this));
 
     CodeCache::commit(this);
 
@@ -1661,20 +1652,16 @@
 // This code must be MP safe, because it is used from parallel GC passes.
 bool nmethod::test_set_oops_do_mark() {
   assert(nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called");
-  nmethod* observed_mark_link = _oops_do_mark_link;
-  if (observed_mark_link == NULL) {
+  if (_oops_do_mark_link == NULL) {
     // Claim this nmethod for this thread to mark.
-    observed_mark_link = (nmethod*)
-      Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_link, NULL);
-    if (observed_mark_link == NULL) {
-
+    if (Atomic::cmpxchg(NMETHOD_SENTINEL, &_oops_do_mark_link, (nmethod*)NULL) == NULL) {
       // Atomically append this nmethod (now claimed) to the head of the list:
       nmethod* observed_mark_nmethods = _oops_do_mark_nmethods;
       for (;;) {
         nmethod* required_mark_nmethods = observed_mark_nmethods;
         _oops_do_mark_link = required_mark_nmethods;
-        observed_mark_nmethods = (nmethod*)
-          Atomic::cmpxchg_ptr(this, &_oops_do_mark_nmethods, required_mark_nmethods);
+        observed_mark_nmethods =
+          Atomic::cmpxchg(this, &_oops_do_mark_nmethods, required_mark_nmethods);
         if (observed_mark_nmethods == required_mark_nmethods)
           break;
       }
@@ -1690,9 +1677,9 @@
 void nmethod::oops_do_marking_prologue() {
   if (TraceScavenge) { tty->print_cr("[oops_do_marking_prologue"); }
   assert(_oops_do_mark_nmethods == NULL, "must not call oops_do_marking_prologue twice in a row");
-  // We use cmpxchg_ptr instead of regular assignment here because the user
+  // We use cmpxchg instead of regular assignment here because the user
   // may fork a bunch of threads, and we need them all to see the same state.
-  void* observed = Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_nmethods, NULL);
+  nmethod* observed = Atomic::cmpxchg(NMETHOD_SENTINEL, &_oops_do_mark_nmethods, (nmethod*)NULL);
   guarantee(observed == NULL, "no races in this sequential code");
 }
 
@@ -1707,8 +1694,8 @@
     NOT_PRODUCT(if (TraceScavenge)  cur->print_on(tty, "oops_do, unmark"));
     cur = next;
   }
-  void* required = _oops_do_mark_nmethods;
-  void* observed = Atomic::cmpxchg_ptr(NULL, &_oops_do_mark_nmethods, required);
+  nmethod* required = _oops_do_mark_nmethods;
+  nmethod* observed = Atomic::cmpxchg((nmethod*)NULL, &_oops_do_mark_nmethods, required);
   guarantee(observed == required, "no races in this sequential code");
   if (TraceScavenge) { tty->print_cr("oops_do_marking_epilogue]"); }
 }
@@ -2137,7 +2124,7 @@
   VerifyOopsClosure voc(this);
   oops_do(&voc);
   assert(voc.ok(), "embedded oops must be OK");
-  verify_scavenge_root_oops();
+  Universe::heap()->verify_nmethod(this);
 
   verify_scopes();
 }
@@ -2230,10 +2217,6 @@
 };
 
 void nmethod::verify_scavenge_root_oops() {
-  if (UseG1GC) {
-    return;
-  }
-
   if (!on_scavenge_root_list()) {
     // Actually look inside, to verify the claim that it's clean.
     DebugScavengeRoot debug_scavenge_root(this);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/cms/cmsHeap.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,185 @@
+/*
+ * 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 "precompiled.hpp"
+#include "gc/cms/concurrentMarkSweepThread.hpp"
+#include "gc/cms/cmsHeap.hpp"
+#include "gc/cms/vmCMSOperations.hpp"
+#include "gc/shared/genOopClosures.inline.hpp"
+#include "gc/shared/strongRootsScope.hpp"
+#include "gc/shared/workgroup.hpp"
+#include "oops/oop.inline.hpp"
+#include "runtime/vmThread.hpp"
+#include "utilities/stack.inline.hpp"
+
+CMSHeap::CMSHeap(GenCollectorPolicy *policy) : GenCollectedHeap(policy) {
+  _workers = new WorkGang("GC Thread", ParallelGCThreads,
+                          /* are_GC_task_threads */true,
+                          /* are_ConcurrentGC_threads */false);
+  _workers->initialize_workers();
+}
+
+jint CMSHeap::initialize() {
+  jint status = GenCollectedHeap::initialize();
+  if (status != JNI_OK) return status;
+
+  // If we are running CMS, create the collector responsible
+  // for collecting the CMS generations.
+  assert(collector_policy()->is_concurrent_mark_sweep_policy(), "must be CMS policy");
+  if (!create_cms_collector()) {
+    return JNI_ENOMEM;
+  }
+
+  return JNI_OK;
+}
+
+void CMSHeap::check_gen_kinds() {
+  assert(young_gen()->kind() == Generation::ParNew,
+         "Wrong youngest generation type");
+  assert(old_gen()->kind() == Generation::ConcurrentMarkSweep,
+         "Wrong generation kind");
+}
+
+CMSHeap* CMSHeap::heap() {
+  CollectedHeap* heap = Universe::heap();
+  assert(heap != NULL, "Uninitialized access to CMSHeap::heap()");
+  assert(heap->kind() == CollectedHeap::CMSHeap, "Not a CMSHeap");
+  return (CMSHeap*) heap;
+}
+
+void CMSHeap::gc_threads_do(ThreadClosure* tc) const {
+  assert(workers() != NULL, "should have workers here");
+  workers()->threads_do(tc);
+  ConcurrentMarkSweepThread::threads_do(tc);
+}
+
+void CMSHeap::print_gc_threads_on(outputStream* st) const {
+  assert(workers() != NULL, "should have workers here");
+  workers()->print_worker_threads_on(st);
+  ConcurrentMarkSweepThread::print_all_on(st);
+}
+
+void CMSHeap::print_on_error(outputStream* st) const {
+  GenCollectedHeap::print_on_error(st);
+  st->cr();
+  CMSCollector::print_on_error(st);
+}
+
+bool CMSHeap::create_cms_collector() {
+  assert(old_gen()->kind() == Generation::ConcurrentMarkSweep,
+         "Unexpected generation kinds");
+  assert(gen_policy()->is_concurrent_mark_sweep_policy(), "Unexpected policy type");
+  CMSCollector* collector =
+    new CMSCollector((ConcurrentMarkSweepGeneration*) old_gen(),
+                     rem_set(),
+                     gen_policy()->as_concurrent_mark_sweep_policy());
+
+  if (collector == NULL || !collector->completed_initialization()) {
+    if (collector) {
+      delete collector; // Be nice in embedded situation
+    }
+    vm_shutdown_during_initialization("Could not create CMS collector");
+    return false;
+  }
+  return true; // success
+}
+
+void CMSHeap::collect(GCCause::Cause cause) {
+  if (should_do_concurrent_full_gc(cause)) {
+    // Mostly concurrent full collection.
+    collect_mostly_concurrent(cause);
+  } else {
+    GenCollectedHeap::collect(cause);
+  }
+}
+
+bool CMSHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
+  switch (cause) {
+    case GCCause::_gc_locker:           return GCLockerInvokesConcurrent;
+    case GCCause::_java_lang_system_gc:
+    case GCCause::_dcmd_gc_run:         return ExplicitGCInvokesConcurrent;
+    default:                            return false;
+  }
+}
+
+void CMSHeap::collect_mostly_concurrent(GCCause::Cause cause) {
+  assert(!Heap_lock->owned_by_self(), "Should not own Heap_lock");
+
+  MutexLocker ml(Heap_lock);
+  // Read the GC counts while holding the Heap_lock
+  unsigned int full_gc_count_before = total_full_collections();
+  unsigned int gc_count_before      = total_collections();
+  {
+    MutexUnlocker mu(Heap_lock);
+    VM_GenCollectFullConcurrent op(gc_count_before, full_gc_count_before, cause);
+    VMThread::execute(&op);
+  }
+}
+
+void CMSHeap::stop() {
+  ConcurrentMarkSweepThread::cmst()->stop();
+}
+
+void CMSHeap::safepoint_synchronize_begin() {
+  ConcurrentMarkSweepThread::synchronize(false);
+}
+
+void CMSHeap::safepoint_synchronize_end() {
+  ConcurrentMarkSweepThread::desynchronize(false);
+}
+
+void CMSHeap::cms_process_roots(StrongRootsScope* scope,
+                                bool young_gen_as_roots,
+                                ScanningOption so,
+                                bool only_strong_roots,
+                                OopsInGenClosure* root_closure,
+                                CLDClosure* cld_closure) {
+  MarkingCodeBlobClosure mark_code_closure(root_closure, !CodeBlobToOopClosure::FixRelocations);
+  OopsInGenClosure* weak_roots = only_strong_roots ? NULL : root_closure;
+  CLDClosure* weak_cld_closure = only_strong_roots ? NULL : cld_closure;
+
+  process_roots(scope, so, root_closure, weak_roots, cld_closure, weak_cld_closure, &mark_code_closure);
+  if (!only_strong_roots) {
+    process_string_table_roots(scope, root_closure);
+  }
+
+  if (young_gen_as_roots &&
+      !_process_strong_tasks->is_task_claimed(GCH_PS_younger_gens)) {
+    root_closure->set_generation(young_gen());
+    young_gen()->oop_iterate(root_closure);
+    root_closure->reset_generation();
+  }
+
+  _process_strong_tasks->all_tasks_completed(scope->n_threads());
+}
+
+void CMSHeap::gc_prologue(bool full) {
+  always_do_update_barrier = false;
+  GenCollectedHeap::gc_prologue(full);
+};
+
+void CMSHeap::gc_epilogue(bool full) {
+  GenCollectedHeap::gc_epilogue(full);
+  always_do_update_barrier = true;
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/cms/cmsHeap.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,117 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef SHARE_VM_GC_CMS_CMSHEAP_HPP
+#define SHARE_VM_GC_CMS_CMSHEAP_HPP
+
+#include "gc/cms/concurrentMarkSweepGeneration.hpp"
+#include "gc/shared/collectedHeap.hpp"
+#include "gc/shared/gcCause.hpp"
+#include "gc/shared/genCollectedHeap.hpp"
+
+class CLDClosure;
+class GenCollectorPolicy;
+class OopsInGenClosure;
+class outputStream;
+class StrongRootsScope;
+class ThreadClosure;
+class WorkGang;
+
+class CMSHeap : public GenCollectedHeap {
+public:
+  CMSHeap(GenCollectorPolicy *policy);
+
+  // Returns JNI_OK on success
+  virtual jint initialize();
+
+  virtual void check_gen_kinds();
+
+  // Convenience function to be used in situations where the heap type can be
+  // asserted to be this type.
+  static CMSHeap* heap();
+
+  virtual Name kind() const {
+    return CollectedHeap::CMSHeap;
+  }
+
+  virtual const char* name() const {
+    return "Concurrent Mark Sweep";
+  }
+
+  WorkGang* workers() const { return _workers; }
+
+  virtual void print_gc_threads_on(outputStream* st) const;
+  virtual void gc_threads_do(ThreadClosure* tc) const;
+  virtual void print_on_error(outputStream* st) const;
+
+  // Perform a full collection of the heap; intended for use in implementing
+  // "System.gc". This implies as full a collection as the CollectedHeap
+  // supports. Caller does not hold the Heap_lock on entry.
+  void collect(GCCause::Cause cause);
+
+  bool is_in_closed_subset(const void* p) const {
+    return is_in_reserved(p);
+  }
+
+  bool card_mark_must_follow_store() const {
+    return true;
+  }
+
+  void stop();
+  void safepoint_synchronize_begin();
+  void safepoint_synchronize_end();
+
+  // If "young_gen_as_roots" is false, younger generations are
+  // not scanned as roots; in this case, the caller must be arranging to
+  // scan the younger generations itself.  (For example, a generation might
+  // explicitly mark reachable objects in younger generations, to avoid
+  // excess storage retention.)
+  void cms_process_roots(StrongRootsScope* scope,
+                         bool young_gen_as_roots,
+                         ScanningOption so,
+                         bool only_strong_roots,
+                         OopsInGenClosure* root_closure,
+                         CLDClosure* cld_closure);
+
+private:
+  WorkGang* _workers;
+
+  virtual void gc_prologue(bool full);
+  virtual void gc_epilogue(bool full);
+
+  // Accessor for memory state verification support
+  NOT_PRODUCT(
+    virtual size_t skip_header_HeapWords() { return CMSCollector::skip_header_HeapWords(); }
+  )
+
+  // Returns success or failure.
+  bool create_cms_collector();
+
+  // In support of ExplicitGCInvokesConcurrent functionality
+  bool should_do_concurrent_full_gc(GCCause::Cause cause);
+
+  void collect_mostly_concurrent(GCCause::Cause cause);
+};
+
+#endif // SHARE_VM_GC_CMS_CMSHEAP_HPP
--- a/src/hotspot/share/gc/cms/compactibleFreeListSpace.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/cms/compactibleFreeListSpace.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -23,13 +23,13 @@
  */
 
 #include "precompiled.hpp"
+#include "gc/cms/cmsHeap.hpp"
 #include "gc/cms/cmsLockVerifier.hpp"
 #include "gc/cms/compactibleFreeListSpace.hpp"
 #include "gc/cms/concurrentMarkSweepGeneration.inline.hpp"
 #include "gc/cms/concurrentMarkSweepThread.hpp"
 #include "gc/shared/blockOffsetTable.inline.hpp"
 #include "gc/shared/collectedHeap.inline.hpp"
-#include "gc/shared/genCollectedHeap.hpp"
 #include "gc/shared/space.inline.hpp"
 #include "gc/shared/spaceDecorator.hpp"
 #include "logging/log.hpp"
@@ -154,7 +154,7 @@
       cp->space->set_compaction_top(compact_top);
       cp->space = cp->space->next_compaction_space();
       if (cp->space == NULL) {
-        cp->gen = GenCollectedHeap::heap()->young_gen();
+        cp->gen = CMSHeap::heap()->young_gen();
         assert(cp->gen != NULL, "compaction must succeed");
         cp->space = cp->gen->first_compaction_space();
         assert(cp->space != NULL, "generation must have a first compaction space");
@@ -2298,7 +2298,7 @@
 
     // Iterate over all oops in the heap. Uses the _no_header version
     // since we are not interested in following the klass pointers.
-    GenCollectedHeap::heap()->oop_iterate_no_header(&cl);
+    CMSHeap::heap()->oop_iterate_no_header(&cl);
   }
 
   if (VerifyObjectStartArray) {
--- a/src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -29,6 +29,7 @@
 #include "classfile/systemDictionary.hpp"
 #include "code/codeCache.hpp"
 #include "gc/cms/cmsCollectorPolicy.hpp"
+#include "gc/cms/cmsHeap.hpp"
 #include "gc/cms/cmsOopClosures.inline.hpp"
 #include "gc/cms/compactibleFreeListSpace.hpp"
 #include "gc/cms/concurrentMarkSweepGeneration.inline.hpp"
@@ -54,6 +55,7 @@
 #include "gc/shared/referencePolicy.hpp"
 #include "gc/shared/strongRootsScope.hpp"
 #include "gc/shared/taskqueue.inline.hpp"
+#include "gc/shared/weakProcessor.hpp"
 #include "logging/log.hpp"
 #include "logging/logStream.hpp"
 #include "memory/allocation.hpp"
@@ -298,14 +300,14 @@
 }
 
 AdaptiveSizePolicy* CMSCollector::size_policy() {
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  return gch->gen_policy()->size_policy();
+  CMSHeap* heap = CMSHeap::heap();
+  return heap->gen_policy()->size_policy();
 }
 
 void ConcurrentMarkSweepGeneration::initialize_performance_counters() {
 
   const char* gen_name = "old";
-  GenCollectorPolicy* gcp = GenCollectedHeap::heap()->gen_policy();
+  GenCollectorPolicy* gcp = CMSHeap::heap()->gen_policy();
   // Generation Counters - generation 1, 1 subspace
   _gen_counters = new GenerationCounters(gen_name, 1, 1,
       gcp->min_old_size(), gcp->max_old_size(), &_virtual_space);
@@ -354,8 +356,8 @@
 // young generation collection.
 double CMSStats::time_until_cms_gen_full() const {
   size_t cms_free = _cms_gen->cmsSpace()->free();
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  size_t expected_promotion = MIN2(gch->young_gen()->capacity(),
+  CMSHeap* heap = CMSHeap::heap();
+  size_t expected_promotion = MIN2(heap->young_gen()->capacity(),
                                    (size_t) _cms_gen->gc_stats()->avg_promoted()->padded_average());
   if (cms_free > expected_promotion) {
     // Start a cms collection if there isn't enough space to promote
@@ -595,12 +597,12 @@
   assert(CGC_lock != NULL, "Where's the CGC_lock?");
 
   // Support for parallelizing young gen rescan
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  assert(gch->young_gen()->kind() == Generation::ParNew, "CMS can only be used with ParNew");
-  _young_gen = (ParNewGeneration*)gch->young_gen();
-  if (gch->supports_inline_contig_alloc()) {
-    _top_addr = gch->top_addr();
-    _end_addr = gch->end_addr();
+  CMSHeap* heap = CMSHeap::heap();
+  assert(heap->young_gen()->kind() == Generation::ParNew, "CMS can only be used with ParNew");
+  _young_gen = (ParNewGeneration*)heap->young_gen();
+  if (heap->supports_inline_contig_alloc()) {
+    _top_addr = heap->top_addr();
+    _end_addr = heap->end_addr();
     assert(_young_gen != NULL, "no _young_gen");
     _eden_chunk_index = 0;
     _eden_chunk_capacity = (_young_gen->max_capacity() + CMSSamplingGrain) / CMSSamplingGrain;
@@ -762,9 +764,9 @@
       log.trace("  Maximum free fraction %f", maximum_free_percentage);
       log.trace("  Capacity " SIZE_FORMAT, capacity() / 1000);
       log.trace("  Desired capacity " SIZE_FORMAT, desired_capacity / 1000);
-      GenCollectedHeap* gch = GenCollectedHeap::heap();
-      assert(gch->is_old_gen(this), "The CMS generation should always be the old generation");
-      size_t young_size = gch->young_gen()->capacity();
+      CMSHeap* heap = CMSHeap::heap();
+      assert(heap->is_old_gen(this), "The CMS generation should always be the old generation");
+      size_t young_size = heap->young_gen()->capacity();
       log.trace("  Young gen size " SIZE_FORMAT, young_size / 1000);
       log.trace("  unsafe_max_alloc_nogc " SIZE_FORMAT, unsafe_max_alloc_nogc() / 1000);
       log.trace("  contiguous available " SIZE_FORMAT, contiguous_available() / 1000);
@@ -923,7 +925,7 @@
   assert_lock_strong(freelistLock());
 
 #ifndef PRODUCT
-  if (GenCollectedHeap::heap()->promotion_should_fail()) {
+  if (CMSHeap::heap()->promotion_should_fail()) {
     return NULL;
   }
 #endif  // #ifndef PRODUCT
@@ -1000,7 +1002,7 @@
                                            oop old, markOop m,
                                            size_t word_sz) {
 #ifndef PRODUCT
-  if (GenCollectedHeap::heap()->promotion_should_fail()) {
+  if (CMSHeap::heap()->promotion_should_fail()) {
     return NULL;
   }
 #endif  // #ifndef PRODUCT
@@ -1076,7 +1078,7 @@
 
   NOT_PRODUCT(
     Atomic::inc(&_numObjectsPromoted);
-    Atomic::add_ptr(alloc_sz, &_numWordsPromoted);
+    Atomic::add(alloc_sz, &_numWordsPromoted);
   )
 
   return obj;
@@ -1179,10 +1181,10 @@
   // We start a collection if we believe an incremental collection may fail;
   // this is not likely to be productive in practice because it's probably too
   // late anyway.
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  assert(gch->collector_policy()->is_generation_policy(),
+  CMSHeap* heap = CMSHeap::heap();
+  assert(heap->collector_policy()->is_generation_policy(),
          "You may want to check the correctness of the following");
-  if (gch->incremental_collection_will_fail(true /* consult_young */)) {
+  if (heap->incremental_collection_will_fail(true /* consult_young */)) {
     log.print("CMSCollector: collect because incremental collection will fail ");
     return true;
   }
@@ -1294,8 +1296,8 @@
 }
 
 void CMSCollector::request_full_gc(unsigned int full_gc_count, GCCause::Cause cause) {
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  unsigned int gc_count = gch->total_full_collections();
+  CMSHeap* heap = CMSHeap::heap();
+  unsigned int gc_count = heap->total_full_collections();
   if (gc_count == full_gc_count) {
     MutexLockerEx y(CGC_lock, Mutex::_no_safepoint_check_flag);
     _full_gc_requested = true;
@@ -1307,7 +1309,7 @@
 }
 
 bool CMSCollector::is_external_interruption() {
-  GCCause::Cause cause = GenCollectedHeap::heap()->gc_cause();
+  GCCause::Cause cause = CMSHeap::heap()->gc_cause();
   return GCCause::is_user_requested_gc(cause) ||
          GCCause::is_serviceability_requested_gc(cause);
 }
@@ -1456,8 +1458,8 @@
 
   // Inform cms gen if this was due to partial collection failing.
   // The CMS gen may use this fact to determine its expansion policy.
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  if (gch->incremental_collection_will_fail(false /* don't consult_young */)) {
+  CMSHeap* heap = CMSHeap::heap();
+  if (heap->incremental_collection_will_fail(false /* don't consult_young */)) {
     assert(!_cmsGen->incremental_collection_failed(),
            "Should have been noticed, reacted to and cleared");
     _cmsGen->set_incremental_collection_failed();
@@ -1489,14 +1491,14 @@
 
   // Has the GC time limit been exceeded?
   size_t max_eden_size = _young_gen->max_eden_size();
-  GCCause::Cause gc_cause = gch->gc_cause();
+  GCCause::Cause gc_cause = heap->gc_cause();
   size_policy()->check_gc_overhead_limit(_young_gen->used(),
                                          _young_gen->eden()->used(),
                                          _cmsGen->max_capacity(),
                                          max_eden_size,
                                          full,
                                          gc_cause,
-                                         gch->collector_policy());
+                                         heap->collector_policy());
 
   // Reset the expansion cause, now that we just completed
   // a collection cycle.
@@ -1518,21 +1520,21 @@
 // A work method used by the foreground collector to do
 // a mark-sweep-compact.
 void CMSCollector::do_compaction_work(bool clear_all_soft_refs) {
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* heap = CMSHeap::heap();
 
   STWGCTimer* gc_timer = GenMarkSweep::gc_timer();
   gc_timer->register_gc_start();
 
   SerialOldTracer* gc_tracer = GenMarkSweep::gc_tracer();
-  gc_tracer->report_gc_start(gch->gc_cause(), gc_timer->gc_start());
-
-  gch->pre_full_gc_dump(gc_timer);
+  gc_tracer->report_gc_start(heap->gc_cause(), gc_timer->gc_start());
+
+  heap->pre_full_gc_dump(gc_timer);
 
   GCTraceTime(Trace, gc, phases) t("CMS:MSC");
 
   // Temporarily widen the span of the weak reference processing to
   // the entire heap.
-  MemRegion new_span(GenCollectedHeap::heap()->reserved_region());
+  MemRegion new_span(CMSHeap::heap()->reserved_region());
   ReferenceProcessorSpanMutator rp_mut_span(ref_processor(), new_span);
   // Temporarily, clear the "is_alive_non_header" field of the
   // reference processor.
@@ -1608,7 +1610,7 @@
   // No longer a need to do a concurrent collection for Metaspace.
   MetaspaceGC::set_should_concurrent_collect(false);
 
-  gch->post_full_gc_dump(gc_timer);
+  heap->post_full_gc_dump(gc_timer);
 
   gc_timer->register_gc_end();
 
@@ -1702,7 +1704,7 @@
   assert(Thread::current()->is_ConcurrentGC_thread(),
     "A CMS asynchronous collection is only allowed on a CMS thread.");
 
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* heap = CMSHeap::heap();
   {
     bool safepoint_check = Mutex::_no_safepoint_check_flag;
     MutexLockerEx hl(Heap_lock, safepoint_check);
@@ -1731,8 +1733,8 @@
     _full_gc_requested = false;           // acks all outstanding full gc requests
     _full_gc_cause = GCCause::_no_gc;
     // Signal that we are about to start a collection
-    gch->increment_total_full_collections();  // ... starting a collection cycle
-    _collection_count_start = gch->total_full_collections();
+    heap->increment_total_full_collections();  // ... starting a collection cycle
+    _collection_count_start = heap->total_full_collections();
   }
 
   size_t prev_used = _cmsGen->used();
@@ -1925,9 +1927,9 @@
 }
 
 void CMSCollector::save_heap_summary() {
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  _last_heap_summary = gch->create_heap_summary();
-  _last_metaspace_summary = gch->create_metaspace_summary();
+  CMSHeap* heap = CMSHeap::heap();
+  _last_heap_summary = heap->create_heap_summary();
+  _last_metaspace_summary = heap->create_metaspace_summary();
 }
 
 void CMSCollector::report_heap_summary(GCWhen::Type when) {
@@ -2303,10 +2305,10 @@
   assert(verification_mark_stack()->isEmpty(), "markStack should be empty");
   verify_work_stacks_empty();
 
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  gch->ensure_parsability(false);  // fill TLABs, but no need to retire them
+  CMSHeap* heap = CMSHeap::heap();
+  heap->ensure_parsability(false);  // fill TLABs, but no need to retire them
   // Update the saved marks which may affect the root scans.
-  gch->save_marks();
+  heap->save_marks();
 
   if (CMSRemarkVerifyVariant == 1) {
     // In this first variant of verification, we complete
@@ -2329,19 +2331,19 @@
 void CMSCollector::verify_after_remark_work_1() {
   ResourceMark rm;
   HandleMark  hm;
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* heap = CMSHeap::heap();
 
   // Get a clear set of claim bits for the roots processing to work with.
   ClassLoaderDataGraph::clear_claimed_marks();
 
   // Mark from roots one level into CMS
   MarkRefsIntoClosure notOlder(_span, verification_mark_bm());
-  gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
+  heap->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
 
   {
     StrongRootsScope srs(1);
 
-    gch->cms_process_roots(&srs,
+    heap->cms_process_roots(&srs,
                            true,   // young gen as roots
                            GenCollectedHeap::ScanningOption(roots_scanning_options()),
                            should_unload_classes(),
@@ -2376,7 +2378,7 @@
     log.error("Failed marking verification after remark");
     ResourceMark rm;
     LogStream ls(log.error());
-    gch->print_on(&ls);
+    heap->print_on(&ls);
     fatal("CMS: failed marking verification after remark");
   }
 }
@@ -2399,7 +2401,7 @@
 void CMSCollector::verify_after_remark_work_2() {
   ResourceMark rm;
   HandleMark  hm;
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* heap = CMSHeap::heap();
 
   // Get a clear set of claim bits for the roots processing to work with.
   ClassLoaderDataGraph::clear_claimed_marks();
@@ -2409,12 +2411,12 @@
                                      markBitMap());
   CLDToOopClosure cld_closure(&notOlder, true);
 
-  gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
+  heap->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
 
   {
     StrongRootsScope srs(1);
 
-    gch->cms_process_roots(&srs,
+    heap->cms_process_roots(&srs,
                            true,   // young gen as roots
                            GenCollectedHeap::ScanningOption(roots_scanning_options()),
                            should_unload_classes(),
@@ -2803,7 +2805,7 @@
 void CMSCollector::checkpointRootsInitial() {
   assert(_collectorState == InitialMarking, "Wrong collector state");
   check_correct_thread_executing();
-  TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause());
+  TraceCMSMemoryManagerStats tms(_collectorState, CMSHeap::heap()->gc_cause());
 
   save_heap_summary();
   report_heap_summary(GCWhen::BeforeGC);
@@ -2844,14 +2846,14 @@
   HandleMark  hm;
 
   MarkRefsIntoClosure notOlder(_span, &_markBitMap);
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* heap = CMSHeap::heap();
 
   verify_work_stacks_empty();
   verify_overflow_empty();
 
-  gch->ensure_parsability(false);  // fill TLABs, but no need to retire them
+  heap->ensure_parsability(false);  // fill TLABs, but no need to retire them
   // Update the saved marks which may affect the root scans.
-  gch->save_marks();
+  heap->save_marks();
 
   // weak reference processing has not started yet.
   ref_processor()->set_enqueuing_is_done(false);
@@ -2872,7 +2874,7 @@
 #endif
     if (CMSParallelInitialMarkEnabled) {
       // The parallel version.
-      WorkGang* workers = gch->workers();
+      WorkGang* workers = heap->workers();
       assert(workers != NULL, "Need parallel worker threads.");
       uint n_workers = workers->active_workers();
 
@@ -2891,11 +2893,11 @@
     } else {
       // The serial version.
       CLDToOopClosure cld_closure(&notOlder, true);
-      gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
+      heap->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
 
       StrongRootsScope srs(1);
 
-      gch->cms_process_roots(&srs,
+      heap->cms_process_roots(&srs,
                              true,   // young gen as roots
                              GenCollectedHeap::ScanningOption(roots_scanning_options()),
                              should_unload_classes(),
@@ -3179,7 +3181,7 @@
   HeapWord* cur  = read;
   while (f > read) {
     cur = read;
-    read = (HeapWord*) Atomic::cmpxchg_ptr(f, &_global_finger, cur);
+    read = Atomic::cmpxchg(f, &_global_finger, cur);
     if (cur == read) {
       // our cas succeeded
       assert(_global_finger >= f, "protocol consistency");
@@ -3800,7 +3802,7 @@
                              bitMapLock());
     startTimer();
     unsigned int before_count =
-      GenCollectedHeap::heap()->total_collections();
+      CMSHeap::heap()->total_collections();
     SurvivorSpacePrecleanClosure
       sss_cl(this, _span, &_markBitMap, &_markStack,
              &pam_cl, before_count, CMSYield);
@@ -4103,7 +4105,7 @@
   // world is stopped at this checkpoint
   assert(SafepointSynchronize::is_at_safepoint(),
          "world should be stopped");
-  TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause());
+  TraceCMSMemoryManagerStats tms(_collectorState, CMSHeap::heap()->gc_cause());
 
   verify_work_stacks_empty();
   verify_overflow_empty();
@@ -4112,16 +4114,16 @@
                 _young_gen->used() / K, _young_gen->capacity() / K);
   {
     if (CMSScavengeBeforeRemark) {
-      GenCollectedHeap* gch = GenCollectedHeap::heap();
+      CMSHeap* heap = CMSHeap::heap();
       // Temporarily set flag to false, GCH->do_collection will
       // expect it to be false and set to true
-      FlagSetting fl(gch->_is_gc_active, false);
-
-      gch->do_collection(true,                      // full (i.e. force, see below)
-                         false,                     // !clear_all_soft_refs
-                         0,                         // size
-                         false,                     // is_tlab
-                         GenCollectedHeap::YoungGen // type
+      FlagSetting fl(heap->_is_gc_active, false);
+
+      heap->do_collection(true,                      // full (i.e. force, see below)
+                          false,                     // !clear_all_soft_refs
+                          0,                         // size
+                          false,                     // is_tlab
+                          GenCollectedHeap::YoungGen // type
         );
     }
     FreelistLocker x(this);
@@ -4142,7 +4144,7 @@
   ResourceMark rm;
   HandleMark   hm;
 
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* heap = CMSHeap::heap();
 
   if (should_unload_classes()) {
     CodeCache::gc_prologue();
@@ -4162,9 +4164,9 @@
   // or of an indication of whether the scavenge did indeed occur,
   // we cannot rely on TLAB's having been filled and must do
   // so here just in case a scavenge did not happen.
-  gch->ensure_parsability(false);  // fill TLAB's, but no need to retire them
+  heap->ensure_parsability(false);  // fill TLAB's, but no need to retire them
   // Update the saved marks which may affect the root scans.
-  gch->save_marks();
+  heap->save_marks();
 
   print_eden_and_survivor_chunk_arrays();
 
@@ -4240,7 +4242,7 @@
   _markStack._failed_double = 0;
 
   if ((VerifyAfterGC || VerifyDuringGC) &&
-      GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) {
+      CMSHeap::heap()->total_collections() >= VerifyGCStartAt) {
     verify_after_remark();
   }
 
@@ -4262,7 +4264,7 @@
 
   // ---------- scan from roots --------------
   _timer.start();
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* heap = CMSHeap::heap();
   ParMarkRefsIntoClosure par_mri_cl(_collector->_span, &(_collector->_markBitMap));
 
   // ---------- young gen roots --------------
@@ -4278,12 +4280,12 @@
 
   CLDToOopClosure cld_closure(&par_mri_cl, true);
 
-  gch->cms_process_roots(_strong_roots_scope,
-                         false,     // yg was scanned above
-                         GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
-                         _collector->should_unload_classes(),
-                         &par_mri_cl,
-                         &cld_closure);
+  heap->cms_process_roots(_strong_roots_scope,
+                          false,     // yg was scanned above
+                          GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
+                          _collector->should_unload_classes(),
+                          &par_mri_cl,
+                          &cld_closure);
   assert(_collector->should_unload_classes()
          || (_collector->CMSCollector::roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache),
          "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops");
@@ -4387,7 +4389,7 @@
 
   // ---------- rescan from roots --------------
   _timer.start();
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* heap = CMSHeap::heap();
   ParMarkRefsIntoAndScanClosure par_mrias_cl(_collector,
     _collector->_span, _collector->ref_processor(),
     &(_collector->_markBitMap),
@@ -4407,12 +4409,12 @@
   // ---------- remaining roots --------------
   _timer.reset();
   _timer.start();
-  gch->cms_process_roots(_strong_roots_scope,
-                         false,     // yg was scanned above
-                         GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
-                         _collector->should_unload_classes(),
-                         &par_mrias_cl,
-                         NULL);     // The dirty klasses will be handled below
+  heap->cms_process_roots(_strong_roots_scope,
+                          false,     // yg was scanned above
+                          GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
+                          _collector->should_unload_classes(),
+                          &par_mrias_cl,
+                          NULL);     // The dirty klasses will be handled below
 
   assert(_collector->should_unload_classes()
          || (_collector->CMSCollector::roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache),
@@ -4839,8 +4841,8 @@
 
 // Parallel version of remark
 void CMSCollector::do_remark_parallel() {
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  WorkGang* workers = gch->workers();
+  CMSHeap* heap = CMSHeap::heap();
+  WorkGang* workers = heap->workers();
   assert(workers != NULL, "Need parallel worker threads.");
   // Choose to use the number of GC workers most recently set
   // into "active_workers".
@@ -4856,7 +4858,7 @@
   // the younger_gen cards, so we shouldn't call the following else
   // the verification code as well as subsequent younger_refs_iterate
   // code would get confused. XXX
-  // gch->rem_set()->prepare_for_younger_refs_iterate(true); // parallel
+  // heap->rem_set()->prepare_for_younger_refs_iterate(true); // parallel
 
   // The young gen rescan work will not be done as part of
   // process_roots (which currently doesn't know how to
@@ -4898,7 +4900,7 @@
 void CMSCollector::do_remark_non_parallel() {
   ResourceMark rm;
   HandleMark   hm;
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* heap = CMSHeap::heap();
   ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), false);
 
   MarkRefsIntoAndScanClosure
@@ -4939,7 +4941,7 @@
     }
   }
   if (VerifyDuringGC &&
-      GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) {
+      CMSHeap::heap()->total_collections() >= VerifyGCStartAt) {
     HandleMark hm;  // Discard invalid handles created during verification
     Universe::verify();
   }
@@ -4948,15 +4950,15 @@
 
     verify_work_stacks_empty();
 
-    gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
+    heap->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
     StrongRootsScope srs(1);
 
-    gch->cms_process_roots(&srs,
-                           true,  // young gen as roots
-                           GenCollectedHeap::ScanningOption(roots_scanning_options()),
-                           should_unload_classes(),
-                           &mrias_cl,
-                           NULL); // The dirty klasses will be handled below
+    heap->cms_process_roots(&srs,
+                            true,  // young gen as roots
+                            GenCollectedHeap::ScanningOption(roots_scanning_options()),
+                            should_unload_classes(),
+                            &mrias_cl,
+                            NULL); // The dirty klasses will be handled below
 
     assert(should_unload_classes()
            || (roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache),
@@ -5148,8 +5150,8 @@
 
 void CMSRefProcTaskExecutor::execute(ProcessTask& task)
 {
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  WorkGang* workers = gch->workers();
+  CMSHeap* heap = CMSHeap::heap();
+  WorkGang* workers = heap->workers();
   assert(workers != NULL, "Need parallel worker threads.");
   CMSRefProcTaskProxy rp_task(task, &_collector,
                               _collector.ref_processor()->span(),
@@ -5161,8 +5163,8 @@
 void CMSRefProcTaskExecutor::execute(EnqueueTask& task)
 {
 
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  WorkGang* workers = gch->workers();
+  CMSHeap* heap = CMSHeap::heap();
+  WorkGang* workers = heap->workers();
   assert(workers != NULL, "Need parallel worker threads.");
   CMSRefEnqueueTaskProxy enq_task(task);
   workers->run_task(&enq_task);
@@ -5195,9 +5197,9 @@
       // and a different number of discovered lists may have Ref objects.
       // That is OK as long as the Reference lists are balanced (see
       // balance_all_queues() and balance_queues()).
-      GenCollectedHeap* gch = GenCollectedHeap::heap();
+      CMSHeap* heap = CMSHeap::heap();
       uint active_workers = ParallelGCThreads;
-      WorkGang* workers = gch->workers();
+      WorkGang* workers = heap->workers();
       if (workers != NULL) {
         active_workers = workers->active_workers();
         // The expectation is that active_workers will have already
@@ -5223,6 +5225,11 @@
     pt.print_all_references();
   }
 
+  {
+    GCTraceTime(Debug, gc, phases) t("Weak Processing", _gc_timer_cm);
+    WeakProcessor::weak_oops_do(&_is_alive_closure, &cmsKeepAliveClosure, &cmsDrainMarkingStackClosure);
+  }
+
   // This is the point where the entire marking should have completed.
   verify_work_stacks_empty();
 
@@ -5305,7 +5312,7 @@
   verify_work_stacks_empty();
   verify_overflow_empty();
   increment_sweep_count();
-  TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause());
+  TraceCMSMemoryManagerStats tms(_collectorState, CMSHeap::heap()->gc_cause());
 
   _inter_sweep_timer.stop();
   _inter_sweep_estimate.sample(_inter_sweep_timer.seconds());
@@ -5378,9 +5385,9 @@
   // this generation. If such a promotion may still fail,
   // the flag will be set again when a young collection is
   // attempted.
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  gch->clear_incremental_collection_failed();  // Worth retrying as fresh space may have been freed up
-  gch->update_full_collections_completed(_collection_count_start);
+  CMSHeap* heap = CMSHeap::heap();
+  heap->clear_incremental_collection_failed();  // Worth retrying as fresh space may have been freed up
+  heap->update_full_collections_completed(_collection_count_start);
 }
 
 // FIX ME!!! Looks like this belongs in CFLSpace, with
@@ -5415,7 +5422,7 @@
                                                     bool full) {
   // If the young generation has been collected, gather any statistics
   // that are of interest at this point.
-  bool current_is_young = GenCollectedHeap::heap()->is_young_gen(current_generation);
+  bool current_is_young = CMSHeap::heap()->is_young_gen(current_generation);
   if (!full && current_is_young) {
     // Gather statistics on the young generation collection.
     collector()->stats().record_gc0_end(used());
@@ -6188,7 +6195,7 @@
     do_yield_check();
   }
   unsigned int after_count =
-    GenCollectedHeap::heap()->total_collections();
+    CMSHeap::heap()->total_collections();
   bool abort = (_before_count != after_count) ||
                _collector->should_abort_preclean();
   return abort ? 0 : size;
@@ -7852,7 +7859,7 @@
     return false;
   }
   // Grab the entire list; we'll put back a suffix
-  oop prefix = cast_to_oop(Atomic::xchg_ptr(BUSY, &_overflow_list));
+  oop prefix = cast_to_oop(Atomic::xchg((oopDesc*)BUSY, &_overflow_list));
   Thread* tid = Thread::current();
   // Before "no_of_gc_threads" was introduced CMSOverflowSpinCount was
   // set to ParallelGCThreads.
@@ -7867,7 +7874,7 @@
       return false;
     } else if (_overflow_list != BUSY) {
       // Try and grab the prefix
-      prefix = cast_to_oop(Atomic::xchg_ptr(BUSY, &_overflow_list));
+      prefix = cast_to_oop(Atomic::xchg((oopDesc*)BUSY, &_overflow_list));
     }
   }
   // If the list was found to be empty, or we spun long
@@ -7880,7 +7887,7 @@
      if (prefix == NULL) {
        // Write back the NULL in case we overwrote it with BUSY above
        // and it is still the same value.
-       (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY);
+       Atomic::cmpxchg((oopDesc*)NULL, &_overflow_list, (oopDesc*)BUSY);
      }
      return false;
   }
@@ -7895,7 +7902,7 @@
     // Write back the NULL in lieu of the BUSY we wrote
     // above, if it is still the same value.
     if (_overflow_list == BUSY) {
-      (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY);
+      Atomic::cmpxchg((oopDesc*)NULL, &_overflow_list, (oopDesc*)BUSY);
     }
   } else {
     // Chop off the suffix and return it to the global list.
@@ -7911,7 +7918,7 @@
     bool attached = false;
     while (observed_overflow_list == BUSY || observed_overflow_list == NULL) {
       observed_overflow_list =
-        (oop) Atomic::cmpxchg_ptr(suffix_head, &_overflow_list, cur_overflow_list);
+        Atomic::cmpxchg((oopDesc*)suffix_head, &_overflow_list, (oopDesc*)cur_overflow_list);
       if (cur_overflow_list == observed_overflow_list) {
         attached = true;
         break;
@@ -7936,7 +7943,7 @@
         }
         // ... and try to place spliced list back on overflow_list ...
         observed_overflow_list =
-          (oop) Atomic::cmpxchg_ptr(suffix_head, &_overflow_list, cur_overflow_list);
+          Atomic::cmpxchg((oopDesc*)suffix_head, &_overflow_list, (oopDesc*)cur_overflow_list);
       } while (cur_overflow_list != observed_overflow_list);
       // ... until we have succeeded in doing so.
     }
@@ -7957,7 +7964,7 @@
   }
 #ifndef PRODUCT
   assert(_num_par_pushes >= n, "Too many pops?");
-  Atomic::add_ptr(-(intptr_t)n, &_num_par_pushes);
+  Atomic::sub(n, &_num_par_pushes);
 #endif
   return true;
 }
@@ -7986,7 +7993,7 @@
       p->set_mark(NULL);
     }
     observed_overflow_list =
-      (oop) Atomic::cmpxchg_ptr(p, &_overflow_list, cur_overflow_list);
+      Atomic::cmpxchg((oopDesc*)p, &_overflow_list, (oopDesc*)cur_overflow_list);
   } while (cur_overflow_list != observed_overflow_list);
 }
 #undef BUSY
--- a/src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -25,13 +25,13 @@
 #ifndef SHARE_VM_GC_CMS_CONCURRENTMARKSWEEPGENERATION_INLINE_HPP
 #define SHARE_VM_GC_CMS_CONCURRENTMARKSWEEPGENERATION_INLINE_HPP
 
+#include "gc/cms/cmsHeap.hpp"
 #include "gc/cms/cmsLockVerifier.hpp"
 #include "gc/cms/compactibleFreeListSpace.hpp"
 #include "gc/cms/concurrentMarkSweepGeneration.hpp"
 #include "gc/cms/concurrentMarkSweepThread.hpp"
 #include "gc/cms/parNewGeneration.hpp"
 #include "gc/shared/gcUtil.hpp"
-#include "gc/shared/genCollectedHeap.hpp"
 #include "utilities/align.hpp"
 #include "utilities/bitMap.inline.hpp"
 
@@ -256,7 +256,7 @@
   // scavenge is done or foreground GC wants to take over collection
   return _collectorState == AbortablePreclean &&
          (_abort_preclean || _foregroundGCIsActive ||
-          GenCollectedHeap::heap()->incremental_collection_will_fail(true /* consult_young */));
+          CMSHeap::heap()->incremental_collection_will_fail(true /* consult_young */));
 }
 
 inline size_t CMSCollector::get_eden_used() const {
--- a/src/hotspot/share/gc/cms/concurrentMarkSweepThread.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/cms/concurrentMarkSweepThread.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -24,10 +24,10 @@
 
 #include "precompiled.hpp"
 #include "classfile/systemDictionary.hpp"
+#include "gc/cms/cmsHeap.hpp"
 #include "gc/cms/concurrentMarkSweepGeneration.inline.hpp"
 #include "gc/cms/concurrentMarkSweepThread.hpp"
 #include "gc/shared/gcId.hpp"
-#include "gc/shared/genCollectedHeap.hpp"
 #include "oops/oop.inline.hpp"
 #include "runtime/init.hpp"
 #include "runtime/interfaceSupport.hpp"
@@ -225,7 +225,7 @@
   // Wait time in millis or 0 value representing infinite wait for a scavenge
   assert(t_millis >= 0, "Wait time for scavenge should be 0 or positive");
 
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* heap = CMSHeap::heap();
   double start_time_secs = os::elapsedTime();
   double end_time_secs = start_time_secs + (t_millis / ((double) MILLIUNITS));
 
@@ -233,7 +233,7 @@
   unsigned int before_count;
   {
     MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag);
-    before_count = gch->total_collections();
+    before_count = heap->total_collections();
   }
 
   unsigned int loop_count = 0;
@@ -279,7 +279,7 @@
     unsigned int after_count;
     {
       MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag);
-      after_count = gch->total_collections();
+      after_count = heap->total_collections();
     }
 
     if(before_count != after_count) {
--- a/src/hotspot/share/gc/cms/parCardTableModRefBS.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/cms/parCardTableModRefBS.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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,10 +23,10 @@
  */
 
 #include "precompiled.hpp"
+#include "gc/cms/cmsHeap.hpp"
 #include "gc/shared/cardTableModRefBS.hpp"
 #include "gc/shared/cardTableRS.hpp"
 #include "gc/shared/collectedHeap.hpp"
-#include "gc/shared/genCollectedHeap.hpp"
 #include "gc/shared/space.inline.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/virtualspace.hpp"
@@ -394,7 +394,7 @@
   // Do a dirty read here. If we pass the conditional then take the rare
   // event lock and do the read again in case some other thread had already
   // succeeded and done the resize.
-  int cur_collection = GenCollectedHeap::heap()->total_collections();
+  int cur_collection = CMSHeap::heap()->total_collections();
   // Updated _last_LNC_resizing_collection[i] must not be visible before
   // _lowest_non_clean and friends are visible. Therefore use acquire/release
   // to guarantee this on non TSO architecures.
--- a/src/hotspot/share/gc/cms/parNewGeneration.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/cms/parNewGeneration.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "gc/cms/cmsHeap.hpp"
 #include "gc/cms/compactibleFreeListSpace.hpp"
 #include "gc/cms/concurrentMarkSweepGeneration.hpp"
 #include "gc/cms/parNewGeneration.inline.hpp"
@@ -45,6 +46,7 @@
 #include "gc/shared/spaceDecorator.hpp"
 #include "gc/shared/strongRootsScope.hpp"
 #include "gc/shared/taskqueue.inline.hpp"
+#include "gc/shared/weakProcessor.hpp"
 #include "gc/shared/workgroup.hpp"
 #include "logging/log.hpp"
 #include "logging/logStream.hpp"
@@ -124,7 +126,7 @@
 void ParScanThreadState::scan_partial_array_and_push_remainder(oop old) {
   assert(old->is_objArray(), "must be obj array");
   assert(old->is_forwarded(), "must be forwarded");
-  assert(GenCollectedHeap::heap()->is_in_reserved(old), "must be in heap.");
+  assert(CMSHeap::heap()->is_in_reserved(old), "must be in heap.");
   assert(!old_gen()->is_in(old), "must be in young generation.");
 
   objArrayOop obj = objArrayOop(old->forwardee());
@@ -205,9 +207,9 @@
   for (size_t i = 0; i != num_take_elems; i++) {
     oop cur = of_stack->pop();
     oop obj_to_push = cur->forwardee();
-    assert(GenCollectedHeap::heap()->is_in_reserved(cur), "Should be in heap");
+    assert(CMSHeap::heap()->is_in_reserved(cur), "Should be in heap");
     assert(!old_gen()->is_in_reserved(cur), "Should be in young gen");
-    assert(GenCollectedHeap::heap()->is_in_reserved(obj_to_push), "Should be in heap");
+    assert(CMSHeap::heap()->is_in_reserved(obj_to_push), "Should be in heap");
     if (should_be_partially_scanned(obj_to_push, cur)) {
       assert(arrayOop(cur)->length() == 0, "entire array remaining to be scanned");
       obj_to_push = cur;
@@ -590,7 +592,7 @@
 {}
 
 void ParNewGenTask::work(uint worker_id) {
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* heap = CMSHeap::heap();
   // Since this is being done in a separate thread, need new resource
   // and handle marks.
   ResourceMark rm;
@@ -602,10 +604,10 @@
   par_scan_state.set_young_old_boundary(_young_old_boundary);
 
   CLDScanClosure cld_scan_closure(&par_scan_state.to_space_root_closure(),
-                                  gch->rem_set()->cld_rem_set()->accumulate_modified_oops());
+                                  heap->rem_set()->cld_rem_set()->accumulate_modified_oops());
 
   par_scan_state.start_strong_roots();
-  gch->young_process_roots(_strong_roots_scope,
+  heap->young_process_roots(_strong_roots_scope,
                            &par_scan_state.to_space_root_closure(),
                            &par_scan_state.older_gen_closure(),
                            &cld_scan_closure);
@@ -687,7 +689,7 @@
 
   _par_cl->do_oop_nv(p);
 
-  if (GenCollectedHeap::heap()->is_in_reserved(p)) {
+  if (CMSHeap::heap()->is_in_reserved(p)) {
     oop obj = oopDesc::load_decode_heap_oop_not_null(p);
     _rs->write_ref_field_gc_par(p, obj);
   }
@@ -714,7 +716,7 @@
 
   _cl->do_oop_nv(p);
 
-  if (GenCollectedHeap::heap()->is_in_reserved(p)) {
+  if (CMSHeap::heap()->is_in_reserved(p)) {
     oop obj = oopDesc::load_decode_heap_oop_not_null(p);
     _rs->write_ref_field_gc_par(p, obj);
   }
@@ -804,7 +806,7 @@
 };
 
 void ParNewRefProcTaskExecutor::execute(ProcessTask& task) {
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* gch = CMSHeap::heap();
   WorkGang* workers = gch->workers();
   assert(workers != NULL, "Need parallel worker threads.");
   _state_set.reset(workers->active_workers(), _young_gen.promotion_failed());
@@ -816,7 +818,7 @@
 }
 
 void ParNewRefProcTaskExecutor::execute(EnqueueTask& task) {
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* gch = CMSHeap::heap();
   WorkGang* workers = gch->workers();
   assert(workers != NULL, "Need parallel worker threads.");
   ParNewRefEnqueueTaskProxy enq_task(task);
@@ -825,8 +827,8 @@
 
 void ParNewRefProcTaskExecutor::set_single_threaded_mode() {
   _state_set.flush();
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  gch->save_marks();
+  CMSHeap* heap = CMSHeap::heap();
+  heap->save_marks();
 }
 
 ScanClosureWithParBarrier::
@@ -835,10 +837,10 @@
 { }
 
 EvacuateFollowersClosureGeneral::
-EvacuateFollowersClosureGeneral(GenCollectedHeap* gch,
+EvacuateFollowersClosureGeneral(CMSHeap* heap,
                                 OopsInGenClosure* cur,
                                 OopsInGenClosure* older) :
-  _gch(gch),
+  _heap(heap),
   _scan_cur_or_nonheap(cur), _scan_older(older)
 { }
 
@@ -846,15 +848,15 @@
   do {
     // Beware: this call will lead to closure applications via virtual
     // calls.
-    _gch->oop_since_save_marks_iterate(GenCollectedHeap::YoungGen,
-                                       _scan_cur_or_nonheap,
-                                       _scan_older);
-  } while (!_gch->no_allocs_since_save_marks());
+    _heap->oop_since_save_marks_iterate(GenCollectedHeap::YoungGen,
+                                        _scan_cur_or_nonheap,
+                                        _scan_older);
+  } while (!_heap->no_allocs_since_save_marks());
 }
 
 // A Generation that does parallel young-gen collection.
 
-void ParNewGeneration::handle_promotion_failed(GenCollectedHeap* gch, ParScanThreadStateSet& thread_state_set) {
+void ParNewGeneration::handle_promotion_failed(CMSHeap* gch, ParScanThreadStateSet& thread_state_set) {
   assert(_promo_failure_scan_stack.is_empty(), "post condition");
   _promo_failure_scan_stack.clear(true); // Clear cached segments.
 
@@ -883,7 +885,7 @@
                                bool   is_tlab) {
   assert(full || size > 0, "otherwise we don't want to collect");
 
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* gch = CMSHeap::heap();
 
   _gc_timer->register_gc_start();
 
@@ -998,6 +1000,8 @@
   _gc_tracer.report_tenuring_threshold(tenuring_threshold());
   pt.print_all_references();
 
+  WeakProcessor::weak_oops_do(&is_alive, &keep_alive, &evacuate_followers);
+
   if (!promotion_failed()) {
     // Swap the survivor spaces.
     eden()->clear(SpaceDecorator::Mangle);
@@ -1064,7 +1068,7 @@
 }
 
 size_t ParNewGeneration::desired_plab_sz() {
-  return _plab_stats.desired_plab_sz(GenCollectedHeap::heap()->workers()->active_workers());
+  return _plab_stats.desired_plab_sz(CMSHeap::heap()->workers()->active_workers());
 }
 
 static int sum;
@@ -1168,7 +1172,7 @@
   } else {
     // Is in to-space; do copying ourselves.
     Copy::aligned_disjoint_words((HeapWord*)old, (HeapWord*)new_obj, sz);
-    assert(GenCollectedHeap::heap()->is_in_reserved(new_obj), "illegal forwarding pointer value.");
+    assert(CMSHeap::heap()->is_in_reserved(new_obj), "illegal forwarding pointer value.");
     forward_ptr = old->forward_to_atomic(new_obj);
     // Restore the mark word copied above.
     new_obj->set_mark(m);
@@ -1296,7 +1300,7 @@
         from_space_obj->set_klass_to_list_ptr(NULL);
       }
       observed_overflow_list =
-        (oop)Atomic::cmpxchg_ptr(from_space_obj, &_overflow_list, cur_overflow_list);
+        Atomic::cmpxchg((oopDesc*)from_space_obj, &_overflow_list, (oopDesc*)cur_overflow_list);
     } while (cur_overflow_list != observed_overflow_list);
   }
 }
@@ -1339,7 +1343,7 @@
   if (_overflow_list == NULL) return false;
 
   // Otherwise, there was something there; try claiming the list.
-  oop prefix = cast_to_oop(Atomic::xchg_ptr(BUSY, &_overflow_list));
+  oop prefix = cast_to_oop(Atomic::xchg((oopDesc*)BUSY, &_overflow_list));
   // Trim off a prefix of at most objsFromOverflow items
   Thread* tid = Thread::current();
   size_t spin_count = ParallelGCThreads;
@@ -1353,7 +1357,7 @@
       return false;
     } else if (_overflow_list != BUSY) {
      // try and grab the prefix
-     prefix = cast_to_oop(Atomic::xchg_ptr(BUSY, &_overflow_list));
+     prefix = cast_to_oop(Atomic::xchg((oopDesc*)BUSY, &_overflow_list));
     }
   }
   if (prefix == NULL || prefix == BUSY) {
@@ -1361,7 +1365,7 @@
      if (prefix == NULL) {
        // Write back the NULL in case we overwrote it with BUSY above
        // and it is still the same value.
-       (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY);
+       (void) Atomic::cmpxchg((oopDesc*)NULL, &_overflow_list, (oopDesc*)BUSY);
      }
      return false;
   }
@@ -1380,7 +1384,7 @@
     // Write back the NULL in lieu of the BUSY we wrote
     // above and it is still the same value.
     if (_overflow_list == BUSY) {
-      (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY);
+      (void) Atomic::cmpxchg((oopDesc*)NULL, &_overflow_list, (oopDesc*)BUSY);
     }
   } else {
     assert(suffix != BUSY, "Error");
@@ -1394,7 +1398,7 @@
     bool attached = false;
     while (observed_overflow_list == BUSY || observed_overflow_list == NULL) {
       observed_overflow_list =
-        (oop) Atomic::cmpxchg_ptr(suffix, &_overflow_list, cur_overflow_list);
+        Atomic::cmpxchg((oopDesc*)suffix, &_overflow_list, (oopDesc*)cur_overflow_list);
       if (cur_overflow_list == observed_overflow_list) {
         attached = true;
         break;
@@ -1420,7 +1424,7 @@
           last->set_klass_to_list_ptr(NULL);
         }
         observed_overflow_list =
-          (oop)Atomic::cmpxchg_ptr(suffix, &_overflow_list, cur_overflow_list);
+          Atomic::cmpxchg((oopDesc*)suffix, &_overflow_list, (oopDesc*)cur_overflow_list);
       } while (cur_overflow_list != observed_overflow_list);
     }
   }
@@ -1452,7 +1456,7 @@
   TASKQUEUE_STATS_ONLY(par_scan_state->note_overflow_refill(n));
 #ifndef PRODUCT
   assert(_num_par_pushes >= n, "Too many pops?");
-  Atomic::add_ptr(-(intptr_t)n, &_num_par_pushes);
+  Atomic::sub(n, &_num_par_pushes);
 #endif
   return true;
 }
@@ -1475,3 +1479,9 @@
 const char* ParNewGeneration::name() const {
   return "par new generation";
 }
+
+void ParNewGeneration::restore_preserved_marks() {
+  SharedRestorePreservedMarksTaskExecutor task_executor(CMSHeap::heap()->workers());
+  _preserved_marks_set.restore(&task_executor);
+}
+
--- a/src/hotspot/share/gc/cms/parNewGeneration.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/cms/parNewGeneration.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -35,6 +35,7 @@
 #include "memory/padded.hpp"
 
 class ChunkArray;
+class CMSHeap;
 class ParScanWithoutBarrierClosure;
 class ParScanWithBarrierClosure;
 class ParRootScanWithoutBarrierClosure;
@@ -259,11 +260,11 @@
 
 class EvacuateFollowersClosureGeneral: public VoidClosure {
  private:
-  GenCollectedHeap* _gch;
+  CMSHeap* _heap;
   OopsInGenClosure* _scan_cur_or_nonheap;
   OopsInGenClosure* _scan_older;
  public:
-  EvacuateFollowersClosureGeneral(GenCollectedHeap* gch,
+  EvacuateFollowersClosureGeneral(CMSHeap* heap,
                                   OopsInGenClosure* cur,
                                   OopsInGenClosure* older);
   virtual void do_void();
@@ -336,7 +337,7 @@
   static oop real_forwardee_slow(oop obj);
   static void waste_some_time();
 
-  void handle_promotion_failed(GenCollectedHeap* gch, ParScanThreadStateSet& thread_state_set);
+  void handle_promotion_failed(CMSHeap* gch, ParScanThreadStateSet& thread_state_set);
 
  protected:
 
@@ -345,6 +346,8 @@
   bool survivor_overflow() { return _survivor_overflow; }
   void set_survivor_overflow(bool v) { _survivor_overflow = v; }
 
+  void restore_preserved_marks();
+
  public:
   ParNewGeneration(ReservedSpace rs, size_t initial_byte_size);
 
--- a/src/hotspot/share/gc/cms/parOopClosures.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/cms/parOopClosures.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -25,10 +25,10 @@
 #ifndef SHARE_VM_GC_CMS_PAROOPCLOSURES_INLINE_HPP
 #define SHARE_VM_GC_CMS_PAROOPCLOSURES_INLINE_HPP
 
+#include "gc/cms/cmsHeap.hpp"
 #include "gc/cms/parNewGeneration.hpp"
 #include "gc/cms/parOopClosures.hpp"
 #include "gc/shared/cardTableRS.hpp"
-#include "gc/shared/genCollectedHeap.hpp"
 #include "gc/shared/genOopClosures.inline.hpp"
 #include "logging/log.hpp"
 #include "logging/logStream.hpp"
@@ -72,9 +72,9 @@
 inline void ParScanClosure::do_oop_work(T* p,
                                         bool gc_barrier,
                                         bool root_scan) {
-  assert((!GenCollectedHeap::heap()->is_in_reserved(p) ||
+  assert((!CMSHeap::heap()->is_in_reserved(p) ||
           generation()->is_in_reserved(p))
-         && (GenCollectedHeap::heap()->is_young_gen(generation()) || gc_barrier),
+         && (CMSHeap::heap()->is_young_gen(generation()) || gc_barrier),
          "The gen must be right, and we must be doing the barrier "
          "in older generations.");
   T heap_oop = oopDesc::load_heap_oop(p);
@@ -85,8 +85,8 @@
       if (_g->to()->is_in_reserved(obj)) {
         Log(gc) log;
         log.error("Scanning field (" PTR_FORMAT ") twice?", p2i(p));
-        GenCollectedHeap* gch = GenCollectedHeap::heap();
-        Space* sp = gch->space_containing(p);
+        CMSHeap* heap = CMSHeap::heap();
+        Space* sp = heap->space_containing(p);
         oop obj = oop(sp->block_start(p));
         assert((HeapWord*)obj < (HeapWord*)p, "Error");
         log.error("Object: " PTR_FORMAT, p2i((void *)obj));
@@ -96,7 +96,7 @@
         log.error("-----");
         log.error("Heap:");
         log.error("-----");
-        gch->print_on(&ls);
+        heap->print_on(&ls);
         ShouldNotReachHere();
       }
 #endif
--- a/src/hotspot/share/gc/cms/vmCMSOperations.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/cms/vmCMSOperations.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "gc/cms/cmsHeap.hpp"
 #include "gc/cms/concurrentMarkSweepGeneration.inline.hpp"
 #include "gc/cms/concurrentMarkSweepThread.hpp"
 #include "gc/cms/vmCMSOperations.hpp"
@@ -39,19 +40,19 @@
 //////////////////////////////////////////////////////////
 void VM_CMS_Operation::verify_before_gc() {
   if (VerifyBeforeGC &&
-      GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) {
+      CMSHeap::heap()->total_collections() >= VerifyGCStartAt) {
     GCTraceTime(Info, gc, phases, verify) tm("Verify Before", _collector->_gc_timer_cm);
     HandleMark hm;
     FreelistLocker x(_collector);
     MutexLockerEx  y(_collector->bitMapLock(), Mutex::_no_safepoint_check_flag);
-    GenCollectedHeap::heap()->prepare_for_verify();
+    CMSHeap::heap()->prepare_for_verify();
     Universe::verify();
   }
 }
 
 void VM_CMS_Operation::verify_after_gc() {
   if (VerifyAfterGC &&
-      GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) {
+      CMSHeap::heap()->total_collections() >= VerifyGCStartAt) {
     GCTraceTime(Info, gc, phases, verify) tm("Verify After", _collector->_gc_timer_cm);
     HandleMark hm;
     FreelistLocker x(_collector);
@@ -112,13 +113,13 @@
 
   _collector->_gc_timer_cm->register_gc_pause_start("Initial Mark");
 
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  GCCauseSetter gccs(gch, GCCause::_cms_initial_mark);
+  CMSHeap* heap = CMSHeap::heap();
+  GCCauseSetter gccs(heap, GCCause::_cms_initial_mark);
 
   VM_CMS_Operation::verify_before_gc();
 
   IsGCActiveMark x; // stop-world GC active
-  _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsInitial, gch->gc_cause());
+  _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsInitial, heap->gc_cause());
 
   VM_CMS_Operation::verify_after_gc();
 
@@ -140,13 +141,13 @@
 
   _collector->_gc_timer_cm->register_gc_pause_start("Final Mark");
 
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  GCCauseSetter gccs(gch, GCCause::_cms_final_remark);
+  CMSHeap* heap = CMSHeap::heap();
+  GCCauseSetter gccs(heap, GCCause::_cms_final_remark);
 
   VM_CMS_Operation::verify_before_gc();
 
   IsGCActiveMark x; // stop-world GC active
-  _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsFinal, gch->gc_cause());
+  _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsFinal, heap->gc_cause());
 
   VM_CMS_Operation::verify_after_gc();
 
@@ -162,8 +163,8 @@
   assert(Thread::current()->is_VM_thread(), "Should be VM thread");
   assert(GCLockerInvokesConcurrent || ExplicitGCInvokesConcurrent, "Unexpected");
 
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
-  if (_gc_count_before == gch->total_collections()) {
+  CMSHeap* heap = CMSHeap::heap();
+  if (_gc_count_before == heap->total_collections()) {
     // The "full" of do_full_collection call below "forces"
     // a collection; the second arg, 0, below ensures that
     // only the young gen is collected. XXX In the future,
@@ -173,21 +174,21 @@
     // for the future.
     assert(SafepointSynchronize::is_at_safepoint(),
       "We can only be executing this arm of if at a safepoint");
-    GCCauseSetter gccs(gch, _gc_cause);
-    gch->do_full_collection(gch->must_clear_all_soft_refs(), GenCollectedHeap::YoungGen);
+    GCCauseSetter gccs(heap, _gc_cause);
+    heap->do_full_collection(heap->must_clear_all_soft_refs(), GenCollectedHeap::YoungGen);
   } // Else no need for a foreground young gc
-  assert((_gc_count_before < gch->total_collections()) ||
+  assert((_gc_count_before < heap->total_collections()) ||
          (GCLocker::is_active() /* gc may have been skipped */
-          && (_gc_count_before == gch->total_collections())),
+          && (_gc_count_before == heap->total_collections())),
          "total_collections() should be monotonically increasing");
 
   MutexLockerEx x(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
-  assert(_full_gc_count_before <= gch->total_full_collections(), "Error");
-  if (gch->total_full_collections() == _full_gc_count_before) {
+  assert(_full_gc_count_before <= heap->total_full_collections(), "Error");
+  if (heap->total_full_collections() == _full_gc_count_before) {
     // Nudge the CMS thread to start a concurrent collection.
     CMSCollector::request_full_gc(_full_gc_count_before, _gc_cause);
   } else {
-    assert(_full_gc_count_before < gch->total_full_collections(), "Error");
+    assert(_full_gc_count_before < heap->total_full_collections(), "Error");
     FullGCCount_lock->notify_all();  // Inform the Java thread its work is done
   }
 }
@@ -197,11 +198,11 @@
   assert(thr != NULL, "Unexpected tid");
   if (!thr->is_Java_thread()) {
     assert(thr->is_VM_thread(), "Expected to be evaluated by VM thread");
-    GenCollectedHeap* gch = GenCollectedHeap::heap();
-    if (_gc_count_before != gch->total_collections()) {
+    CMSHeap* heap = CMSHeap::heap();
+    if (_gc_count_before != heap->total_collections()) {
       // No need to do a young gc, we'll just nudge the CMS thread
       // in the doit() method above, to be executed soon.
-      assert(_gc_count_before < gch->total_collections(),
+      assert(_gc_count_before < heap->total_collections(),
              "total_collections() should be monotonically increasing");
       return false;  // no need for foreground young gc
     }
@@ -227,9 +228,9 @@
   // count overflows and wraps around. XXX fix me !!!
   // e.g. at the rate of 1 full gc per ms, this could
   // overflow in about 1000 years.
-  GenCollectedHeap* gch = GenCollectedHeap::heap();
+  CMSHeap* heap = CMSHeap::heap();
   if (_gc_cause != GCCause::_gc_locker &&
-      gch->total_full_collections_completed() <= _full_gc_count_before) {
+      heap->total_full_collections_completed() <= _full_gc_count_before) {
     // maybe we should change the condition to test _gc_cause ==
     // GCCause::_java_lang_system_gc or GCCause::_dcmd_gc_run,
     // instead of _gc_cause != GCCause::_gc_locker
@@ -245,7 +246,7 @@
     MutexLockerEx ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
     // Either a concurrent or a stop-world full gc is sufficient
     // witness to our request.
-    while (gch->total_full_collections_completed() <= _full_gc_count_before) {
+    while (heap->total_full_collections_completed() <= _full_gc_count_before) {
       FullGCCount_lock->wait(Mutex::_no_safepoint_check_flag);
     }
   }
--- a/src/hotspot/share/gc/g1/concurrentG1RefineThread.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/concurrentG1RefineThread.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -27,7 +27,7 @@
 #include "gc/g1/concurrentG1RefineThread.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
 #include "gc/g1/g1RemSet.hpp"
-#include "gc/g1/suspendibleThreadSet.hpp"
+#include "gc/shared/suspendibleThreadSet.hpp"
 #include "logging/log.hpp"
 #include "memory/resourceArea.hpp"
 #include "runtime/handles.inline.hpp"
--- a/src/hotspot/share/gc/g1/concurrentMarkThread.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/concurrentMarkThread.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -30,12 +30,12 @@
 #include "gc/g1/g1ConcurrentMark.inline.hpp"
 #include "gc/g1/g1MMUTracker.hpp"
 #include "gc/g1/g1Policy.hpp"
-#include "gc/g1/suspendibleThreadSet.hpp"
 #include "gc/g1/vm_operations_g1.hpp"
 #include "gc/shared/concurrentGCPhaseManager.hpp"
 #include "gc/shared/gcId.hpp"
 #include "gc/shared/gcTrace.hpp"
 #include "gc/shared/gcTraceTime.inline.hpp"
+#include "gc/shared/suspendibleThreadSet.hpp"
 #include "logging/log.hpp"
 #include "memory/resourceArea.hpp"
 #include "runtime/vmThread.hpp"
--- a/src/hotspot/share/gc/g1/dirtyCardQueue.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/dirtyCardQueue.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -280,13 +280,13 @@
   BufferNode* nd = _cur_par_buffer_node;
   while (nd != NULL) {
     BufferNode* next = nd->next();
-    void* actual = Atomic::cmpxchg_ptr(next, &_cur_par_buffer_node, nd);
+    BufferNode* actual = Atomic::cmpxchg(next, &_cur_par_buffer_node, nd);
     if (actual == nd) {
       bool b = apply_closure_to_buffer(cl, nd, false);
       guarantee(b, "Should not stop early.");
       nd = next;
     } else {
-      nd = static_cast<BufferNode*>(actual);
+      nd = actual;
     }
   }
 }
--- a/src/hotspot/share/gc/g1/g1CardLiveData.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1CardLiveData.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -26,7 +26,7 @@
 #include "gc/g1/g1CollectedHeap.inline.hpp"
 #include "gc/g1/g1ConcurrentMark.inline.hpp"
 #include "gc/g1/g1CardLiveData.inline.hpp"
-#include "gc/g1/suspendibleThreadSet.hpp"
+#include "gc/shared/suspendibleThreadSet.hpp"
 #include "gc/shared/workgroup.hpp"
 #include "logging/log.hpp"
 #include "memory/universe.hpp"
--- a/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -155,19 +155,19 @@
 }
 
 G1CodeRootSetTable* G1CodeRootSet::load_acquire_table() {
-  return (G1CodeRootSetTable*) OrderAccess::load_ptr_acquire(&_table);
+  return OrderAccess::load_acquire(&_table);
 }
 
 void G1CodeRootSet::allocate_small_table() {
   G1CodeRootSetTable* temp = new G1CodeRootSetTable(SmallSize);
 
-  OrderAccess::release_store_ptr(&_table, temp);
+  OrderAccess::release_store(&_table, temp);
 }
 
 void G1CodeRootSetTable::purge_list_append(G1CodeRootSetTable* table) {
   for (;;) {
     table->_purge_next = _purge_list;
-    G1CodeRootSetTable* old = (G1CodeRootSetTable*) Atomic::cmpxchg_ptr(table, &_purge_list, table->_purge_next);
+    G1CodeRootSetTable* old = Atomic::cmpxchg(table, &_purge_list, table->_purge_next);
     if (old == table->_purge_next) {
       break;
     }
@@ -191,7 +191,7 @@
 
   G1CodeRootSetTable::purge_list_append(_table);
 
-  OrderAccess::release_store_ptr(&_table, temp);
+  OrderAccess::release_store(&_table, temp);
 }
 
 void G1CodeRootSet::purge() {
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -57,7 +57,6 @@
 #include "gc/g1/heapRegion.inline.hpp"
 #include "gc/g1/heapRegionRemSet.hpp"
 #include "gc/g1/heapRegionSet.inline.hpp"
-#include "gc/g1/suspendibleThreadSet.hpp"
 #include "gc/g1/vm_operations_g1.hpp"
 #include "gc/shared/gcHeapSummary.hpp"
 #include "gc/shared/gcId.hpp"
@@ -68,8 +67,10 @@
 #include "gc/shared/generationSpec.hpp"
 #include "gc/shared/isGCActiveMark.hpp"
 #include "gc/shared/preservedMarks.inline.hpp"
+#include "gc/shared/suspendibleThreadSet.hpp"
 #include "gc/shared/referenceProcessor.inline.hpp"
 #include "gc/shared/taskqueue.inline.hpp"
+#include "gc/shared/weakProcessor.hpp"
 #include "logging/log.hpp"
 #include "memory/allocation.hpp"
 #include "memory/iterator.hpp"
@@ -141,13 +142,6 @@
   reset_from_card_cache(start_idx, num_regions);
 }
 
-// Returns true if the reference points to an object that
-// can move in an incremental collection.
-bool G1CollectedHeap::is_scavengable(const void* p) {
-  HeapRegion* hr = heap_region_containing(p);
-  return !hr->is_pinned();
-}
-
 // Private methods.
 
 HeapRegion*
@@ -1849,6 +1843,14 @@
   }
 }
 
+void G1CollectedHeap::safepoint_synchronize_begin() {
+  SuspendibleThreadSet::synchronize();
+}
+
+void G1CollectedHeap::safepoint_synchronize_end() {
+  SuspendibleThreadSet::desynchronize();
+}
+
 size_t G1CollectedHeap::conservative_max_heap_alignment() {
   return HeapRegion::max_region_size();
 }
@@ -3458,10 +3460,10 @@
 
   // Variables used to claim nmethods.
   CompiledMethod* _first_nmethod;
-  volatile CompiledMethod* _claimed_nmethod;
+  CompiledMethod* volatile _claimed_nmethod;
 
   // The list of nmethods that need to be processed by the second pass.
-  volatile CompiledMethod* _postponed_list;
+  CompiledMethod* volatile _postponed_list;
   volatile uint            _num_entered_barrier;
 
  public:
@@ -3480,7 +3482,7 @@
     if(iter.next_alive()) {
       _first_nmethod = iter.method();
     }
-    _claimed_nmethod = (volatile CompiledMethod*)_first_nmethod;
+    _claimed_nmethod = _first_nmethod;
   }
 
   ~G1CodeCacheUnloadingTask() {
@@ -3496,9 +3498,9 @@
   void add_to_postponed_list(CompiledMethod* nm) {
       CompiledMethod* old;
       do {
-        old = (CompiledMethod*)_postponed_list;
+        old = _postponed_list;
         nm->set_unloading_next(old);
-      } while ((CompiledMethod*)Atomic::cmpxchg_ptr(nm, &_postponed_list, old) != old);
+      } while (Atomic::cmpxchg(nm, &_postponed_list, old) != old);
   }
 
   void clean_nmethod(CompiledMethod* nm) {
@@ -3527,7 +3529,7 @@
     do {
       *num_claimed_nmethods = 0;
 
-      first = (CompiledMethod*)_claimed_nmethod;
+      first = _claimed_nmethod;
       last = CompiledMethodIterator(first);
 
       if (first != NULL) {
@@ -3541,7 +3543,7 @@
         }
       }
 
-    } while ((CompiledMethod*)Atomic::cmpxchg_ptr(last.method(), &_claimed_nmethod, first) != first);
+    } while (Atomic::cmpxchg(last.method(), &_claimed_nmethod, first) != first);
   }
 
   CompiledMethod* claim_postponed_nmethod() {
@@ -3549,14 +3551,14 @@
     CompiledMethod* next;
 
     do {
-      claim = (CompiledMethod*)_postponed_list;
+      claim = _postponed_list;
       if (claim == NULL) {
         return NULL;
       }
 
       next = claim->unloading_next();
 
-    } while ((CompiledMethod*)Atomic::cmpxchg_ptr(next, &_postponed_list, claim) != claim);
+    } while (Atomic::cmpxchg(next, &_postponed_list, claim) != claim);
 
     return claim;
   }
@@ -4127,17 +4129,6 @@
   }
 };
 
-void G1CollectedHeap::process_weak_jni_handles() {
-  double ref_proc_start = os::elapsedTime();
-
-  G1STWIsAliveClosure is_alive(this);
-  G1KeepAliveClosure keep_alive(this);
-  JNIHandles::weak_oops_do(&is_alive, &keep_alive);
-
-  double ref_proc_time = os::elapsedTime() - ref_proc_start;
-  g1_policy()->phase_times()->record_ref_proc_time(ref_proc_time * 1000.0);
-}
-
 void G1CollectedHeap::preserve_cm_referents(G1ParScanThreadStateSet* per_thread_states) {
   // Any reference objects, in the collection set, that were 'discovered'
   // by the CM ref processor should have already been copied (either by
@@ -4368,14 +4359,23 @@
     process_discovered_references(per_thread_states);
   } else {
     ref_processor_stw()->verify_no_references_recorded();
-    process_weak_jni_handles();
+  }
+
+  G1STWIsAliveClosure is_alive(this);
+  G1KeepAliveClosure keep_alive(this);
+
+  {
+    double start = os::elapsedTime();
+
+    WeakProcessor::weak_oops_do(&is_alive, &keep_alive);
+
+    double time_ms = (os::elapsedTime() - start) * 1000.0;
+    g1_policy()->phase_times()->record_ref_proc_time(time_ms);
   }
 
   if (G1StringDedup::is_enabled()) {
     double fixup_start = os::elapsedTime();
 
-    G1STWIsAliveClosure is_alive(this);
-    G1KeepAliveClosure keep_alive(this);
     G1StringDedup::unlink_or_oops_do(&is_alive, &keep_alive, true, g1_policy()->phase_times());
 
     double fixup_time_ms = (os::elapsedTime() - fixup_start) * 1000.0;
@@ -5323,17 +5323,20 @@
   void do_oop(narrowOop* p) { do_oop_work(p); }
 };
 
+// Returns true if the reference points to an object that
+// can move in an incremental collection.
+bool G1CollectedHeap::is_scavengable(oop obj) {
+  HeapRegion* hr = heap_region_containing(obj);
+  return !hr->is_pinned();
+}
+
 void G1CollectedHeap::register_nmethod(nmethod* nm) {
-  CollectedHeap::register_nmethod(nm);
-
   guarantee(nm != NULL, "sanity");
   RegisterNMethodOopClosure reg_cl(this, nm);
   nm->oops_do(&reg_cl);
 }
 
 void G1CollectedHeap::unregister_nmethod(nmethod* nm) {
-  CollectedHeap::unregister_nmethod(nm);
-
   guarantee(nm != NULL, "sanity");
   UnregisterNMethodOopClosure reg_cl(this, nm);
   nm->oops_do(&reg_cl, true);
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -303,8 +303,6 @@
 
   void trace_heap(GCWhen::Type when, const GCTracer* tracer);
 
-  void process_weak_jni_handles();
-
   // These are macros so that, if the assert fires, we get the correct
   // line number, file, etc.
 
@@ -968,6 +966,8 @@
   jint initialize();
 
   virtual void stop();
+  virtual void safepoint_synchronize_begin();
+  virtual void safepoint_synchronize_end();
 
   // Return the (conservative) maximum heap alignment for any G1 heap
   static size_t conservative_max_heap_alignment();
@@ -1282,8 +1282,6 @@
 
   inline bool is_in_young(const oop obj);
 
-  virtual bool is_scavengable(const void* addr);
-
   // We don't need barriers for initializing stores to objects
   // in the young gen: for the SATB pre-barrier, there is no
   // pre-value that needs to be remembered; for the remembered-set
@@ -1395,6 +1393,9 @@
 
   // Optimized nmethod scanning support routines
 
+  // Is an oop scavengeable
+  virtual bool is_scavengable(oop obj);
+
   // Register the given nmethod with the G1 heap.
   virtual void register_nmethod(nmethod* nm);
 
--- a/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -38,7 +38,6 @@
 #include "gc/g1/heapRegion.inline.hpp"
 #include "gc/g1/heapRegionRemSet.hpp"
 #include "gc/g1/heapRegionSet.inline.hpp"
-#include "gc/g1/suspendibleThreadSet.hpp"
 #include "gc/shared/gcId.hpp"
 #include "gc/shared/gcTimer.hpp"
 #include "gc/shared/gcTrace.hpp"
@@ -46,8 +45,10 @@
 #include "gc/shared/genOopClosures.inline.hpp"
 #include "gc/shared/referencePolicy.hpp"
 #include "gc/shared/strongRootsScope.hpp"
+#include "gc/shared/suspendibleThreadSet.hpp"
 #include "gc/shared/taskqueue.inline.hpp"
 #include "gc/shared/vmGCOperations.hpp"
+#include "gc/shared/weakProcessor.hpp"
 #include "logging/log.hpp"
 #include "memory/allocation.hpp"
 #include "memory/resourceArea.hpp"
@@ -1603,6 +1604,23 @@
   // Is alive closure.
   G1CMIsAliveClosure g1_is_alive(g1h);
 
+  // Instances of the 'Keep Alive' and 'Complete GC' closures used
+  // in serial reference processing. Note these closures are also
+  // used for serially processing (by the the current thread) the
+  // JNI references during parallel reference processing.
+  //
+  // These closures do not need to synchronize with the worker
+  // threads involved in parallel reference processing as these
+  // instances are executed serially by the current thread (e.g.
+  // reference processing is not multi-threaded and is thus
+  // performed by the current thread instead of a gang worker).
+  //
+  // The gang tasks involved in parallel reference processing create
+  // their own instances of these closures, which do their own
+  // synchronization among themselves.
+  G1CMKeepAliveAndDrainClosure g1_keep_alive(this, task(0), true /* is_serial */);
+  G1CMDrainMarkingStackClosure g1_drain_mark_stack(this, task(0), true /* is_serial */);
+
   // Inner scope to exclude the cleaning of the string and symbol
   // tables from the displayed time.
   {
@@ -1617,23 +1635,6 @@
     rp->setup_policy(clear_all_soft_refs);
     assert(_global_mark_stack.is_empty(), "mark stack should be empty");
 
-    // Instances of the 'Keep Alive' and 'Complete GC' closures used
-    // in serial reference processing. Note these closures are also
-    // used for serially processing (by the the current thread) the
-    // JNI references during parallel reference processing.
-    //
-    // These closures do not need to synchronize with the worker
-    // threads involved in parallel reference processing as these
-    // instances are executed serially by the current thread (e.g.
-    // reference processing is not multi-threaded and is thus
-    // performed by the current thread instead of a gang worker).
-    //
-    // The gang tasks involved in parallel reference processing create
-    // their own instances of these closures, which do their own
-    // synchronization among themselves.
-    G1CMKeepAliveAndDrainClosure g1_keep_alive(this, task(0), true /* is_serial */);
-    G1CMDrainMarkingStackClosure g1_drain_mark_stack(this, task(0), true /* is_serial */);
-
     // We need at least one active thread. If reference processing
     // is not multi-threaded we use the current (VMThread) thread,
     // otherwise we use the work gang from the G1CollectedHeap and
@@ -1687,6 +1688,11 @@
     assert(!rp->discovery_enabled(), "Post condition");
   }
 
+  {
+    GCTraceTime(Debug, gc, phases) debug("Weak Processing", _gc_timer_cm);
+    WeakProcessor::weak_oops_do(&g1_is_alive, &g1_keep_alive, &g1_drain_mark_stack);
+  }
+
   if (has_overflown()) {
     // We can not trust g1_is_alive if the marking stack overflowed
     return;
@@ -1870,7 +1876,7 @@
     HeapWord* end = curr_region != NULL ? curr_region->end() : finger + HeapRegion::GrainWords;
 
     // Is the gap between reading the finger and doing the CAS too long?
-    HeapWord* res = (HeapWord*) Atomic::cmpxchg_ptr(end, &_finger, finger);
+    HeapWord* res = Atomic::cmpxchg(end, &_finger, finger);
     if (res == finger && curr_region != NULL) {
       // we succeeded
       HeapWord*   bottom        = curr_region->bottom();
--- a/src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -29,7 +29,7 @@
 #include "gc/g1/g1ConcurrentMark.hpp"
 #include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
 #include "gc/g1/g1ConcurrentMarkObjArrayProcessor.inline.hpp"
-#include "gc/g1/suspendibleThreadSet.hpp"
+#include "gc/shared/suspendibleThreadSet.hpp"
 #include "gc/shared/taskqueue.inline.hpp"
 #include "utilities/bitMap.inline.hpp"
 
--- a/src/hotspot/share/gc/g1/g1EvacStats.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1EvacStats.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -29,17 +29,17 @@
 #include "runtime/atomic.hpp"
 
 inline void G1EvacStats::add_direct_allocated(size_t value) {
-  Atomic::add_ptr(value, &_direct_allocated);
+  Atomic::add(value, &_direct_allocated);
 }
 
 inline void G1EvacStats::add_region_end_waste(size_t value) {
-  Atomic::add_ptr(value, &_region_end_waste);
-  Atomic::add_ptr(1, &_regions_filled);
+  Atomic::add(value, &_region_end_waste);
+  Atomic::inc(&_regions_filled);
 }
 
 inline void G1EvacStats::add_failure_used_and_waste(size_t used, size_t waste) {
-  Atomic::add_ptr(used, &_failure_used);
-  Atomic::add_ptr(waste, &_failure_waste);
+  Atomic::add(used, &_failure_used);
+  Atomic::add(waste, &_failure_waste);
 }
 
 #endif // SHARE_VM_GC_G1_G1EVACSTATS_INLINE_HPP
--- a/src/hotspot/share/gc/g1/g1HotCardCache.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1HotCardCache.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -74,9 +74,9 @@
   // card_ptr in favor of the other option, which would be starting over. This
   // should be OK since card_ptr will likely be the older card already when/if
   // this ever happens.
-  jbyte* previous_ptr = (jbyte*)Atomic::cmpxchg_ptr(card_ptr,
-                                                    &_hot_cache[masked_index],
-                                                    current_ptr);
+  jbyte* previous_ptr = Atomic::cmpxchg(card_ptr,
+                                        &_hot_cache[masked_index],
+                                        current_ptr);
   return (previous_ptr == current_ptr) ? previous_ptr : card_ptr;
 }
 
--- a/src/hotspot/share/gc/g1/g1MMUTracker.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1MMUTracker.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -29,8 +29,6 @@
 #include "runtime/mutexLocker.hpp"
 #include "utilities/ostream.hpp"
 
-#define _DISABLE_MMU                             0
-
 // can't rely on comparing doubles with tolerating a small margin for error
 #define SMALL_MARGIN 0.0000001
 #define is_double_leq_0(_value) ( (_value) < SMALL_MARGIN )
@@ -119,9 +117,6 @@
 // of other places (debugging)
 
 double G1MMUTrackerQueue::when_sec(double current_time, double pause_time) {
-  if (_DISABLE_MMU)
-    return 0.0;
-
   MutexLockerEx x(MMUTracker_lock, Mutex::_no_safepoint_check_flag);
   remove_expired_entries(current_time);
 
--- a/src/hotspot/share/gc/g1/g1MarkSweep.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1MarkSweep.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -43,6 +43,7 @@
 #include "gc/shared/modRefBarrierSet.hpp"
 #include "gc/shared/referencePolicy.hpp"
 #include "gc/shared/space.hpp"
+#include "gc/shared/weakProcessor.hpp"
 #include "oops/instanceRefKlass.hpp"
 #include "oops/oop.inline.hpp"
 #include "prims/jvmtiExport.hpp"
@@ -181,6 +182,13 @@
     pt.print_all_references();
   }
 
+  {
+    GCTraceTime(Debug, gc, phases) trace("Weak Processing", gc_timer());
+    WeakProcessor::weak_oops_do(&GenMarkSweep::is_alive,
+                                &GenMarkSweep::keep_alive,
+                                &GenMarkSweep::follow_stack_closure);
+  }
+
   // This is the point where the entire marking should have completed.
   assert(GenMarkSweep::_marking_stack.is_empty(), "Marking should have completed");
 
@@ -272,7 +280,7 @@
 
   // Now adjust pointers in remaining weak roots.  (All of which should
   // have been cleared if they pointed to non-surviving objects.)
-  JNIHandles::weak_oops_do(&GenMarkSweep::adjust_pointer_closure);
+  WeakProcessor::oops_do(&GenMarkSweep::adjust_pointer_closure);
 
   if (G1StringDedup::is_enabled()) {
     G1StringDedup::oops_do(&GenMarkSweep::adjust_pointer_closure);
--- a/src/hotspot/share/gc/g1/g1PageBasedVirtualSpace.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1PageBasedVirtualSpace.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -251,7 +251,7 @@
   virtual void work(uint worker_id) {
     size_t const actual_chunk_size = MAX2(chunk_size(), _page_size);
     while (true) {
-      char* touch_addr = (char*)Atomic::add_ptr((intptr_t)actual_chunk_size, (volatile void*) &_cur_addr) - actual_chunk_size;
+      char* touch_addr = Atomic::add(actual_chunk_size, &_cur_addr) - actual_chunk_size;
       if (touch_addr < _start_addr || touch_addr >= _end_addr) {
         break;
       }
--- a/src/hotspot/share/gc/g1/g1RemSet.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1RemSet.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -36,8 +36,8 @@
 #include "gc/g1/heapRegion.inline.hpp"
 #include "gc/g1/heapRegionManager.inline.hpp"
 #include "gc/g1/heapRegionRemSet.hpp"
-#include "gc/g1/suspendibleThreadSet.hpp"
 #include "gc/shared/gcTraceTime.inline.hpp"
+#include "gc/shared/suspendibleThreadSet.hpp"
 #include "memory/iterator.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/oop.inline.hpp"
--- a/src/hotspot/share/gc/g1/g1SATBCardTableModRefBS.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1SATBCardTableModRefBS.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -54,8 +54,6 @@
   // pre-marking object graph.
   static void enqueue(oop pre_val);
 
-  virtual bool has_write_ref_pre_barrier() { return true; }
-
   // We export this to make it available in cases where the static
   // type of the barrier set is known.  Note that it is non-virtual.
   template <class T> inline void inline_write_ref_field_pre(T* field, oop newVal);
@@ -63,9 +61,6 @@
   // These are the more general virtual versions.
   inline virtual void write_ref_field_pre_work(oop* field, oop new_val);
   inline virtual void write_ref_field_pre_work(narrowOop* field, oop new_val);
-  virtual void write_ref_field_pre_work(void* field, oop new_val) {
-    guarantee(false, "Not needed");
-  }
 
   template <class T> void write_ref_array_pre_work(T* dst, int count);
   virtual void write_ref_array_pre(oop* dst, int count, bool dest_uninitialized);
--- a/src/hotspot/share/gc/g1/g1StringDedup.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1StringDedup.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -203,12 +203,12 @@
 // Atomically claims the next available queue for exclusive access by
 // the current thread. Returns the queue number of the claimed queue.
 size_t G1StringDedupUnlinkOrOopsDoClosure::claim_queue() {
-  return (size_t)Atomic::add_ptr(1, &_next_queue) - 1;
+  return Atomic::add((size_t)1, &_next_queue) - 1;
 }
 
 // Atomically claims the next available table partition for exclusive
 // access by the current thread. Returns the table bucket number where
 // the claimed partition starts.
 size_t G1StringDedupUnlinkOrOopsDoClosure::claim_table_partition(size_t partition_size) {
-  return (size_t)Atomic::add_ptr(partition_size, &_next_bucket) - partition_size;
+  return Atomic::add(partition_size, &_next_bucket) - partition_size;
 }
--- a/src/hotspot/share/gc/g1/g1StringDedupThread.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1StringDedupThread.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -28,7 +28,7 @@
 #include "gc/g1/g1StringDedupQueue.hpp"
 #include "gc/g1/g1StringDedupTable.hpp"
 #include "gc/g1/g1StringDedupThread.hpp"
-#include "gc/g1/suspendibleThreadSet.hpp"
+#include "gc/shared/suspendibleThreadSet.hpp"
 #include "logging/log.hpp"
 #include "oops/oop.inline.hpp"
 #include "runtime/atomic.hpp"
--- a/src/hotspot/share/gc/g1/g1YoungRemSetSamplingThread.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/g1YoungRemSetSamplingThread.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -29,7 +29,7 @@
 #include "gc/g1/g1YoungRemSetSamplingThread.hpp"
 #include "gc/g1/heapRegion.inline.hpp"
 #include "gc/g1/heapRegionRemSet.hpp"
-#include "gc/g1/suspendibleThreadSet.hpp"
+#include "gc/shared/suspendibleThreadSet.hpp"
 #include "runtime/mutexLocker.hpp"
 
 G1YoungRemSetSamplingThread::G1YoungRemSetSamplingThread() :
--- a/src/hotspot/share/gc/g1/heapRegion.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/heapRegion.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -59,7 +59,7 @@
     size_t want_to_allocate = MIN2(available, desired_word_size);
     if (want_to_allocate >= min_word_size) {
       HeapWord* new_top = obj + want_to_allocate;
-      HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
+      HeapWord* result = Atomic::cmpxchg(new_top, top_addr(), obj);
       // result can be one of two:
       //  the old top value: the exchange succeeded
       //  otherwise: the new value of the top is returned.
--- a/src/hotspot/share/gc/g1/heapRegionRemSet.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/heapRegionRemSet.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -113,9 +113,7 @@
 
 public:
 
-  HeapRegion* hr() const {
-    return (HeapRegion*) OrderAccess::load_ptr_acquire(&_hr);
-  }
+  HeapRegion* hr() const { return OrderAccess::load_acquire(&_hr); }
 
   jint occupied() const {
     // Overkill, but if we ever need it...
@@ -133,7 +131,7 @@
     _bm.clear();
     // Make sure that the bitmap clearing above has been finished before publishing
     // this PRT to concurrent threads.
-    OrderAccess::release_store_ptr(&_hr, hr);
+    OrderAccess::release_store(&_hr, hr);
   }
 
   void add_reference(OopOrNarrowOopStar from) {
@@ -182,7 +180,7 @@
     while (true) {
       PerRegionTable* fl = _free_list;
       last->set_next(fl);
-      PerRegionTable* res = (PerRegionTable*) Atomic::cmpxchg_ptr(prt, &_free_list, fl);
+      PerRegionTable* res = Atomic::cmpxchg(prt, &_free_list, fl);
       if (res == fl) {
         return;
       }
@@ -199,9 +197,7 @@
     PerRegionTable* fl = _free_list;
     while (fl != NULL) {
       PerRegionTable* nxt = fl->next();
-      PerRegionTable* res =
-        (PerRegionTable*)
-        Atomic::cmpxchg_ptr(nxt, &_free_list, fl);
+      PerRegionTable* res = Atomic::cmpxchg(nxt, &_free_list, fl);
       if (res == fl) {
         fl->init(hr, true);
         return fl;
@@ -416,7 +412,7 @@
       // some mark bits may not yet seem cleared or a 'later' update
       // performed by a concurrent thread could be undone when the
       // zeroing becomes visible). This requires store ordering.
-      OrderAccess::release_store_ptr((volatile PerRegionTable*)&_fine_grain_regions[ind], prt);
+      OrderAccess::release_store(&_fine_grain_regions[ind], prt);
       _n_fine_entries++;
 
       if (G1HRRSUseSparseTable) {
--- a/src/hotspot/share/gc/g1/sparsePRT.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/g1/sparsePRT.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -292,9 +292,7 @@
   SparsePRT* hd = _head_expanded_list;
   while (true) {
     sprt->_next_expanded = hd;
-    SparsePRT* res =
-      (SparsePRT*)
-      Atomic::cmpxchg_ptr(sprt, &_head_expanded_list, hd);
+    SparsePRT* res = Atomic::cmpxchg(sprt, &_head_expanded_list, hd);
     if (res == hd) return;
     else hd = res;
   }
@@ -305,9 +303,7 @@
   SparsePRT* hd = _head_expanded_list;
   while (hd != NULL) {
     SparsePRT* next = hd->next_expanded();
-    SparsePRT* res =
-      (SparsePRT*)
-      Atomic::cmpxchg_ptr(next, &_head_expanded_list, hd);
+    SparsePRT* res = Atomic::cmpxchg(next, &_head_expanded_list, hd);
     if (res == hd) {
       hd->set_next_expanded(NULL);
       return hd;
--- a/src/hotspot/share/gc/g1/suspendibleThreadSet.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,134 +0,0 @@
-/*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-#include "precompiled.hpp"
-#include "gc/g1/suspendibleThreadSet.hpp"
-#include "runtime/mutexLocker.hpp"
-#include "runtime/semaphore.hpp"
-#include "runtime/thread.inline.hpp"
-
-uint   SuspendibleThreadSet::_nthreads          = 0;
-uint   SuspendibleThreadSet::_nthreads_stopped  = 0;
-bool   SuspendibleThreadSet::_suspend_all       = false;
-double SuspendibleThreadSet::_suspend_all_start = 0.0;
-
-static Semaphore* _synchronize_wakeup = NULL;
-
-void SuspendibleThreadSet_init() {
-  assert(_synchronize_wakeup == NULL, "STS already initialized");
-  _synchronize_wakeup = new Semaphore();
-}
-
-bool SuspendibleThreadSet::is_synchronized() {
-  assert_lock_strong(STS_lock);
-  assert(_nthreads_stopped <= _nthreads, "invariant");
-  return _nthreads_stopped == _nthreads;
-}
-
-void SuspendibleThreadSet::join() {
-  assert(!Thread::current()->is_suspendible_thread(), "Thread already joined");
-  MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
-  while (_suspend_all) {
-    ml.wait(Mutex::_no_safepoint_check_flag);
-  }
-  _nthreads++;
-  DEBUG_ONLY(Thread::current()->set_suspendible_thread();)
-}
-
-void SuspendibleThreadSet::leave() {
-  assert(Thread::current()->is_suspendible_thread(), "Thread not joined");
-  MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
-  assert(_nthreads > 0, "Invalid");
-  DEBUG_ONLY(Thread::current()->clear_suspendible_thread();)
-  _nthreads--;
-  if (_suspend_all && is_synchronized()) {
-    // This leave completes a request, so inform the requestor.
-    _synchronize_wakeup->signal();
-  }
-}
-
-void SuspendibleThreadSet::yield() {
-  assert(Thread::current()->is_suspendible_thread(), "Must have joined");
-  MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
-  if (_suspend_all) {
-    _nthreads_stopped++;
-    if (is_synchronized()) {
-      if (ConcGCYieldTimeout > 0) {
-        double now = os::elapsedTime();
-        guarantee((now - _suspend_all_start) * 1000.0 < (double)ConcGCYieldTimeout, "Long delay");
-      }
-      // This yield completes the request, so inform the requestor.
-      _synchronize_wakeup->signal();
-    }
-    while (_suspend_all) {
-      ml.wait(Mutex::_no_safepoint_check_flag);
-    }
-    assert(_nthreads_stopped > 0, "Invalid");
-    _nthreads_stopped--;
-  }
-}
-
-void SuspendibleThreadSet::synchronize() {
-  assert(Thread::current()->is_VM_thread(), "Must be the VM thread");
-  if (ConcGCYieldTimeout > 0) {
-    _suspend_all_start = os::elapsedTime();
-  }
-  {
-    MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
-    assert(!_suspend_all, "Only one at a time");
-    _suspend_all = true;
-    if (is_synchronized()) {
-      return;
-    }
-  } // Release lock before semaphore wait.
-
-  // Semaphore initial count is zero.  To reach here, there must be at
-  // least one not yielded thread in the set, e.g. is_synchronized()
-  // was false before the lock was released.  A thread in the set will
-  // signal the semaphore iff it is the last to yield or leave while
-  // there is an active suspend request.  So there will be exactly one
-  // signal, which will increment the semaphore count to one, which
-  // will then be consumed by this wait, returning it to zero.  No
-  // thread can exit yield or enter the set until desynchronize is
-  // called, so there are no further opportunities for the semaphore
-  // being signaled until we get back here again for some later
-  // synchronize call.  Hence, there is no need to re-check for
-  // is_synchronized after the wait; it will always be true there.
-  _synchronize_wakeup->wait();
-
-#ifdef ASSERT
-  MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
-  assert(_suspend_all, "STS not synchronizing");
-  assert(is_synchronized(), "STS not synchronized");
-#endif
-}
-
-void SuspendibleThreadSet::desynchronize() {
-  assert(Thread::current()->is_VM_thread(), "Must be the VM thread");
-  MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
-  assert(_suspend_all, "STS not synchronizing");
-  assert(is_synchronized(), "STS not synchronized");
-  _suspend_all = false;
-  ml.notify_all();
-}
--- a/src/hotspot/share/gc/g1/suspendibleThreadSet.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-#ifndef SHARE_VM_GC_G1_SUSPENDIBLETHREADSET_HPP
-#define SHARE_VM_GC_G1_SUSPENDIBLETHREADSET_HPP
-
-#include "memory/allocation.hpp"
-
-// A SuspendibleThreadSet is a set of threads that can be suspended.
-// A thread can join and later leave the set, and periodically yield.
-// If some thread (not in the set) requests, via synchronize(), that
-// the threads be suspended, then the requesting thread is blocked
-// until all the threads in the set have yielded or left the set. Threads
-// may not enter the set when an attempted suspension is in progress. The
-// suspending thread later calls desynchronize(), allowing the suspended
-// threads to continue.
-class SuspendibleThreadSet : public AllStatic {
-  friend class SuspendibleThreadSetJoiner;
-  friend class SuspendibleThreadSetLeaver;
-
-private:
-  static uint   _nthreads;
-  static uint   _nthreads_stopped;
-  static bool   _suspend_all;
-  static double _suspend_all_start;
-
-  static bool is_synchronized();
-
-  // Add the current thread to the set. May block if a suspension is in progress.
-  static void join();
-
-  // Removes the current thread from the set.
-  static void leave();
-
-public:
-  // Returns true if an suspension is in progress.
-  static bool should_yield() { return _suspend_all; }
-
-  // Suspends the current thread if a suspension is in progress.
-  static void yield();
-
-  // Returns when all threads in the set are suspended.
-  static void synchronize();
-
-  // Resumes all suspended threads in the set.
-  static void desynchronize();
-};
-
-class SuspendibleThreadSetJoiner : public StackObj {
-private:
-  bool _active;
-
-public:
-  SuspendibleThreadSetJoiner(bool active = true) : _active(active) {
-    if (_active) {
-      SuspendibleThreadSet::join();
-    }
-  }
-
-  ~SuspendibleThreadSetJoiner() {
-    if (_active) {
-      SuspendibleThreadSet::leave();
-    }
-  }
-
-  bool should_yield() {
-    if (_active) {
-      return SuspendibleThreadSet::should_yield();
-    } else {
-      return false;
-    }
-  }
-
-  void yield() {
-    assert(_active, "Thread has not joined the suspendible thread set");
-    SuspendibleThreadSet::yield();
-  }
-};
-
-class SuspendibleThreadSetLeaver : public StackObj {
-private:
-  bool _active;
-
-public:
-  SuspendibleThreadSetLeaver(bool active = true) : _active(active) {
-    if (_active) {
-      SuspendibleThreadSet::leave();
-    }
-  }
-
-  ~SuspendibleThreadSetLeaver() {
-    if (_active) {
-      SuspendibleThreadSet::join();
-    }
-  }
-};
-
-#endif // SHARE_VM_GC_G1_SUSPENDIBLETHREADSET_HPP
--- a/src/hotspot/share/gc/parallel/gcTaskThread.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/parallel/gcTaskThread.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -77,8 +77,7 @@
   if (_time_stamps == NULL) {
     // We allocate the _time_stamps array lazily since logging can be enabled dynamically
     GCTaskTimeStamp* time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC);
-    void* old = Atomic::cmpxchg_ptr(time_stamps, &_time_stamps, NULL);
-    if (old != NULL) {
+    if (Atomic::cmpxchg(time_stamps, &_time_stamps, (GCTaskTimeStamp*)NULL) != NULL) {
       // Someone already setup the time stamps
       FREE_C_HEAP_ARRAY(GCTaskTimeStamp, time_stamps);
     }
--- a/src/hotspot/share/gc/parallel/mutableNUMASpace.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/parallel/mutableNUMASpace.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 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
@@ -862,7 +862,7 @@
   if (p != NULL) {
     HeapWord* cur_top, *cur_chunk_top = p + size;
     while ((cur_top = top()) < cur_chunk_top) { // Keep _top updated.
-      if (Atomic::cmpxchg_ptr(cur_chunk_top, top_addr(), cur_top) == cur_top) {
+      if (Atomic::cmpxchg(cur_chunk_top, top_addr(), cur_top) == cur_top) {
         break;
       }
     }
--- a/src/hotspot/share/gc/parallel/mutableSpace.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/parallel/mutableSpace.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -192,7 +192,7 @@
     HeapWord* obj = top();
     if (pointer_delta(end(), obj) >= size) {
       HeapWord* new_top = obj + size;
-      HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
+      HeapWord* result = Atomic::cmpxchg(new_top, top_addr(), obj);
       // result can be one of two:
       //  the old top value: the exchange succeeded
       //  otherwise: the new value of the top is returned.
@@ -211,7 +211,7 @@
 // Try to deallocate previous allocation. Returns true upon success.
 bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
   HeapWord* expected_top = obj + size;
-  return (HeapWord*)Atomic::cmpxchg_ptr(obj, top_addr(), expected_top) == expected_top;
+  return Atomic::cmpxchg(obj, top_addr(), expected_top) == expected_top;
 }
 
 void MutableSpace::oop_iterate_no_header(OopClosure* cl) {
--- a/src/hotspot/share/gc/parallel/parMarkBitMap.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/parallel/parMarkBitMap.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -90,7 +90,7 @@
     bool end_bit_ok = _end_bits.par_set_bit(end_bit);
     assert(end_bit_ok, "concurrency problem");
     DEBUG_ONLY(Atomic::inc(&mark_bitmap_count));
-    DEBUG_ONLY(Atomic::add_ptr(size, &mark_bitmap_size));
+    DEBUG_ONLY(Atomic::add(size, &mark_bitmap_size));
     return true;
   }
   return false;
--- a/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "code/codeCache.hpp"
 #include "gc/parallel/adjoiningGenerations.hpp"
 #include "gc/parallel/adjoiningVirtualSpaces.hpp"
 #include "gc/parallel/cardTableExtension.hpp"
@@ -169,10 +170,6 @@
   return young_gen()->is_in_reserved(p) || old_gen()->is_in_reserved(p);
 }
 
-bool ParallelScavengeHeap::is_scavengable(const void* addr) {
-  return is_in_young((oop)addr);
-}
-
 // There are two levels of allocation policy here.
 //
 // When an allocation request fails, the requesting thread must invoke a VM
@@ -665,3 +662,15 @@
   }
 }
 #endif
+
+bool ParallelScavengeHeap::is_scavengable(oop obj) {
+  return is_in_young(obj);
+}
+
+void ParallelScavengeHeap::register_nmethod(nmethod* nm) {
+  CodeCache::register_scavenge_root_nmethod(nm);
+}
+
+void ParallelScavengeHeap::verify_nmethod(nmethod* nm) {
+  CodeCache::verify_scavenge_root_nmethod(nm);
+}
--- a/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -134,7 +134,9 @@
   // can be moved in a partial collection.  For currently implemented
   // generational collectors that means during a collection of
   // the young gen.
-  virtual bool is_scavengable(const void* addr);
+  virtual bool is_scavengable(oop obj);
+  virtual void register_nmethod(nmethod* nm);
+  virtual void verify_nmethod(nmethod* nmethod);
 
   size_t max_capacity() const;
 
--- a/src/hotspot/share/gc/parallel/psMarkSweep.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/parallel/psMarkSweep.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -47,6 +47,7 @@
 #include "gc/shared/referencePolicy.hpp"
 #include "gc/shared/referenceProcessor.hpp"
 #include "gc/shared/spaceDecorator.hpp"
+#include "gc/shared/weakProcessor.hpp"
 #include "logging/log.hpp"
 #include "oops/oop.inline.hpp"
 #include "runtime/biasedLocking.hpp"
@@ -542,6 +543,11 @@
     pt.print_all_references();
   }
 
+  {
+    GCTraceTime(Debug, gc, phases) t("Weak Processing", _gc_timer);
+    WeakProcessor::weak_oops_do(is_alive_closure(), mark_and_push_closure(), follow_stack_closure());
+  }
+
   // This is the point where the entire marking should have completed.
   assert(_marking_stack.is_empty(), "Marking should have completed");
 
@@ -617,7 +623,7 @@
   // Now adjust pointers in remaining weak roots.  (All of which should
   // have been cleared if they pointed to non-surviving objects.)
   // Global (weak) JNI handles
-  JNIHandles::weak_oops_do(adjust_pointer_closure());
+  WeakProcessor::oops_do(adjust_pointer_closure());
 
   CodeBlobToOopClosure adjust_from_blobs(adjust_pointer_closure(), CodeBlobToOopClosure::FixRelocations);
   CodeCache::blobs_do(&adjust_from_blobs);
--- a/src/hotspot/share/gc/parallel/psParallelCompact.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/parallel/psParallelCompact.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -52,6 +52,7 @@
 #include "gc/shared/referencePolicy.hpp"
 #include "gc/shared/referenceProcessor.hpp"
 #include "gc/shared/spaceDecorator.hpp"
+#include "gc/shared/weakProcessor.hpp"
 #include "logging/log.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/instanceKlass.inline.hpp"
@@ -521,7 +522,7 @@
   const size_t end_region = (obj_ofs + len - 1) >> Log2RegionSize;
 
   DEBUG_ONLY(Atomic::inc(&add_obj_count);)
-  DEBUG_ONLY(Atomic::add_ptr(len, &add_obj_size);)
+  DEBUG_ONLY(Atomic::add(len, &add_obj_size);)
 
   if (beg_region == end_region) {
     // All in one region.
@@ -2118,6 +2119,11 @@
     pt.print_all_references();
   }
 
+  {
+    GCTraceTime(Debug, gc, phases) tm("Weak Processing", &_gc_timer);
+    WeakProcessor::weak_oops_do(is_alive_closure(), &mark_and_push_closure, &follow_stack_closure);
+  }
+
   // This is the point where the entire marking should have completed.
   assert(cm->marking_stacks_empty(), "Marking should have completed");
 
@@ -2170,8 +2176,7 @@
 
   // Now adjust pointers in remaining weak roots.  (All of which should
   // have been cleared if they pointed to non-surviving objects.)
-  // Global (weak) JNI handles
-  JNIHandles::weak_oops_do(&oop_closure);
+  WeakProcessor::oops_do(&oop_closure);
 
   CodeBlobToOopClosure adjust_from_blobs(&oop_closure, CodeBlobToOopClosure::FixRelocations);
   CodeCache::blobs_do(&adjust_from_blobs);
--- a/src/hotspot/share/gc/parallel/psParallelCompact.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/parallel/psParallelCompact.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -586,7 +586,7 @@
 #ifdef ASSERT
   HeapWord* tmp = _highest_ref;
   while (addr > tmp) {
-    tmp = (HeapWord*)Atomic::cmpxchg_ptr(addr, &_highest_ref, tmp);
+    tmp = Atomic::cmpxchg(addr, &_highest_ref, tmp);
   }
 #endif  // #ifdef ASSERT
 }
--- a/src/hotspot/share/gc/parallel/psScavenge.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/parallel/psScavenge.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -45,6 +45,7 @@
 #include "gc/shared/referencePolicy.hpp"
 #include "gc/shared/referenceProcessor.hpp"
 #include "gc/shared/spaceDecorator.hpp"
+#include "gc/shared/weakProcessor.hpp"
 #include "memory/resourceArea.hpp"
 #include "logging/log.hpp"
 #include "oops/oop.inline.hpp"
@@ -406,14 +407,15 @@
 
     scavenge_midpoint.update();
 
+    PSKeepAliveClosure keep_alive(promotion_manager);
+    PSEvacuateFollowersClosure evac_followers(promotion_manager);
+
     // Process reference objects discovered during scavenge
     {
       GCTraceTime(Debug, gc, phases) tm("Reference Processing", &_gc_timer);
 
       reference_processor()->setup_policy(false); // not always_clear
       reference_processor()->set_active_mt_degree(active_workers);
-      PSKeepAliveClosure keep_alive(promotion_manager);
-      PSEvacuateFollowersClosure evac_followers(promotion_manager);
       ReferenceProcessorStats stats;
       ReferenceProcessorPhaseTimes pt(&_gc_timer, reference_processor()->num_q());
       if (reference_processor()->processing_is_mt()) {
@@ -441,6 +443,11 @@
     }
 
     {
+      GCTraceTime(Debug, gc, phases) tm("Weak Processing", &_gc_timer);
+      WeakProcessor::weak_oops_do(&_is_alive_closure, &keep_alive, &evac_followers);
+    }
+
+    {
       GCTraceTime(Debug, gc, phases) tm("Scrub String Table", &_gc_timer);
       // Unlink any dead interned Strings and process the remaining live ones.
       PSScavengeRootsClosure root_closure(promotion_manager);
--- a/src/hotspot/share/gc/serial/defNewGeneration.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/serial/defNewGeneration.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -41,6 +41,7 @@
 #include "gc/shared/space.inline.hpp"
 #include "gc/shared/spaceDecorator.hpp"
 #include "gc/shared/strongRootsScope.hpp"
+#include "gc/shared/weakProcessor.hpp"
 #include "logging/log.hpp"
 #include "memory/iterator.hpp"
 #include "memory/resourceArea.hpp"
@@ -658,6 +659,8 @@
   gc_tracer.report_tenuring_threshold(tenuring_threshold());
   pt.print_all_references();
 
+  WeakProcessor::weak_oops_do(&is_alive, &keep_alive, &evacuate_followers);
+
   if (!_promotion_failed) {
     // Swap the survivor spaces.
     eden()->clear(SpaceDecorator::Mangle);
@@ -734,8 +737,11 @@
   RemoveForwardedPointerClosure rspc;
   eden()->object_iterate(&rspc);
   from()->object_iterate(&rspc);
+  restore_preserved_marks();
+}
 
-  SharedRestorePreservedMarksTaskExecutor task_executor(GenCollectedHeap::heap()->workers());
+void DefNewGeneration::restore_preserved_marks() {
+  SharedRestorePreservedMarksTaskExecutor task_executor(NULL);
   _preserved_marks_set.restore(&task_executor);
 }
 
--- a/src/hotspot/share/gc/serial/defNewGeneration.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/serial/defNewGeneration.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -89,6 +89,8 @@
   // therefore we must remove their forwarding pointers.
   void remove_forwarding_pointers();
 
+  virtual void restore_preserved_marks();
+
   // Preserved marks
   PreservedMarksSet _preserved_marks_set;
 
--- a/src/hotspot/share/gc/serial/genMarkSweep.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/serial/genMarkSweep.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -43,6 +43,7 @@
 #include "gc/shared/referencePolicy.hpp"
 #include "gc/shared/space.hpp"
 #include "gc/shared/strongRootsScope.hpp"
+#include "gc/shared/weakProcessor.hpp"
 #include "oops/instanceRefKlass.hpp"
 #include "oops/oop.inline.hpp"
 #include "prims/jvmtiExport.hpp"
@@ -217,6 +218,11 @@
     gc_tracer()->report_gc_reference_stats(stats);
   }
 
+  {
+    GCTraceTime(Debug, gc, phases) tm_m("Weak Processing", gc_timer());
+    WeakProcessor::weak_oops_do(&is_alive, &keep_alive, &follow_stack_closure);
+  }
+
   // This is the point where the entire marking should have completed.
   assert(_marking_stack.is_empty(), "Marking should have completed");
 
--- a/src/hotspot/share/gc/shared/barrierSet.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/barrierSet.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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,50 +80,11 @@
 
   // End of fake RTTI support.
 
-public:
-  enum Flags {
-    None                = 0,
-    TargetUninitialized = 1
-  };
-
 protected:
-  // Some barrier sets create tables whose elements correspond to parts of
-  // the heap; the CardTableModRefBS is an example.  Such barrier sets will
-  // normally reserve space for such tables, and commit parts of the table
-  // "covering" parts of the heap that are committed. At most one covered
-  // region per generation is needed.
-  static const int _max_covered_regions = 2;
-
   BarrierSet(const FakeRtti& fake_rtti) : _fake_rtti(fake_rtti) { }
   ~BarrierSet() { }
 
 public:
-
-  // These operations indicate what kind of barriers the BarrierSet has.
-  virtual bool has_read_ref_barrier() = 0;
-  virtual bool has_read_prim_barrier() = 0;
-  virtual bool has_write_ref_barrier() = 0;
-  virtual bool has_write_ref_pre_barrier() = 0;
-  virtual bool has_write_prim_barrier() = 0;
-
-  // These functions indicate whether a particular access of the given
-  // kinds requires a barrier.
-  virtual bool read_ref_needs_barrier(void* field) = 0;
-  virtual bool read_prim_needs_barrier(HeapWord* field, size_t bytes) = 0;
-  virtual bool write_prim_needs_barrier(HeapWord* field, size_t bytes,
-                                        juint val1, juint val2) = 0;
-
-  // The first four operations provide a direct implementation of the
-  // barrier set.  An interpreter loop, for example, could call these
-  // directly, as appropriate.
-
-  // Invoke the barrier, if any, necessary when reading the given ref field.
-  virtual void read_ref_field(void* field) = 0;
-
-  // Invoke the barrier, if any, necessary when reading the given primitive
-  // "field" of "bytes" bytes in "obj".
-  virtual void read_prim_field(HeapWord* field, size_t bytes) = 0;
-
   // Invoke the barrier, if any, necessary when writing "new_val" into the
   // ref field at "offset" in "obj".
   // (For efficiency reasons, this operation is specialized for certain
@@ -131,48 +92,19 @@
   // virtual "_work" function below, which must implement the barrier.)
   // First the pre-write versions...
   template <class T> inline void write_ref_field_pre(T* field, oop new_val);
-private:
-  // Helper for write_ref_field_pre and friends, testing for specialized cases.
-  bool devirtualize_reference_writes() const;
-
-  // Keep this private so as to catch violations at build time.
-  virtual void write_ref_field_pre_work(     void* field, oop new_val) { guarantee(false, "Not needed"); };
-protected:
-  virtual void write_ref_field_pre_work(      oop* field, oop new_val) {};
-  virtual void write_ref_field_pre_work(narrowOop* field, oop new_val) {};
-public:
 
   // ...then the post-write version.
   inline void write_ref_field(void* field, oop new_val, bool release = false);
-protected:
-  virtual void write_ref_field_work(void* field, oop new_val, bool release) = 0;
-public:
 
-  // Invoke the barrier, if any, necessary when writing the "bytes"-byte
-  // value(s) "val1" (and "val2") into the primitive "field".
-  virtual void write_prim_field(HeapWord* field, size_t bytes,
-                                juint val1, juint val2) = 0;
+protected:
+  virtual void write_ref_field_pre_work(      oop* field, oop new_val) {};
+  virtual void write_ref_field_pre_work(narrowOop* field, oop new_val) {};
+  virtual void write_ref_field_work(void* field, oop new_val, bool release) = 0;
 
+public:
   // Operations on arrays, or general regions (e.g., for "clone") may be
   // optimized by some barriers.
 
-  // The first six operations tell whether such an optimization exists for
-  // the particular barrier.
-  virtual bool has_read_ref_array_opt() = 0;
-  virtual bool has_read_prim_array_opt() = 0;
-  virtual bool has_write_ref_array_pre_opt() { return true; }
-  virtual bool has_write_ref_array_opt() = 0;
-  virtual bool has_write_prim_array_opt() = 0;
-
-  virtual bool has_read_region_opt() = 0;
-  virtual bool has_write_region_opt() = 0;
-
-  // These operations should assert false unless the corresponding operation
-  // above returns true.  Otherwise, they should perform an appropriate
-  // barrier for an array whose elements are all in the given memory region.
-  virtual void read_ref_array(MemRegion mr) = 0;
-  virtual void read_prim_array(MemRegion mr) = 0;
-
   // Below length is the # array elements being written
   virtual void write_ref_array_pre(oop* dst, int length,
                                    bool dest_uninitialized = false) {}
@@ -193,17 +125,16 @@
 
 protected:
   virtual void write_ref_array_work(MemRegion mr) = 0;
+
 public:
-  virtual void write_prim_array(MemRegion mr) = 0;
-
-  virtual void read_region(MemRegion mr) = 0;
-
   // (For efficiency reasons, this operation is specialized for certain
   // barrier types.  Semantically, it should be thought of as a call to the
   // virtual "_work" function below, which must implement the barrier.)
   void write_region(MemRegion mr);
+
 protected:
   virtual void write_region_work(MemRegion mr) = 0;
+
 public:
   // Inform the BarrierSet that the the covered heap region that starts
   // with "base" has been changed to have the given size (possibly from 0,
--- a/src/hotspot/share/gc/shared/barrierSet.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/barrierSet.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -26,37 +26,15 @@
 #define SHARE_VM_GC_SHARED_BARRIERSET_INLINE_HPP
 
 #include "gc/shared/barrierSet.hpp"
-#include "gc/shared/cardTableModRefBS.inline.hpp"
 #include "utilities/align.hpp"
 
-// Inline functions of BarrierSet, which de-virtualize certain
-// performance-critical calls when the barrier is the most common
-// card-table kind.
-
-inline bool BarrierSet::devirtualize_reference_writes() const {
-  switch (kind()) {
-  case CardTableForRS:
-  case CardTableExtension:
-    return true;
-  default:
-    return false;
-  }
-}
 
 template <class T> void BarrierSet::write_ref_field_pre(T* field, oop new_val) {
-  if (devirtualize_reference_writes()) {
-    barrier_set_cast<CardTableModRefBS>(this)->inline_write_ref_field_pre(field, new_val);
-  } else {
-    write_ref_field_pre_work(field, new_val);
-  }
+  write_ref_field_pre_work(field, new_val);
 }
 
 void BarrierSet::write_ref_field(void* field, oop new_val, bool release) {
-  if (devirtualize_reference_writes()) {
-    barrier_set_cast<CardTableModRefBS>(this)->inline_write_ref_field(field, new_val, release);
-  } else {
-    write_ref_field_work(field, new_val, release);
-  }
+  write_ref_field_work(field, new_val, release);
 }
 
 // count is number of array elements being written
@@ -84,11 +62,7 @@
 
 
 inline void BarrierSet::write_region(MemRegion mr) {
-  if (devirtualize_reference_writes()) {
-    barrier_set_cast<CardTableModRefBS>(this)->inline_write_region(mr);
-  } else {
-    write_region_work(mr);
-  }
+  write_region_work(mr);
 }
 
 #endif // SHARE_VM_GC_SHARED_BARRIERSET_INLINE_HPP
--- a/src/hotspot/share/gc/shared/cardTableModRefBS.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/cardTableModRefBS.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -73,7 +73,15 @@
   size_t          _byte_map_size;    // in bytes
   jbyte*          _byte_map;         // the card marking array
 
+  // Some barrier sets create tables whose elements correspond to parts of
+  // the heap; the CardTableModRefBS is an example.  Such barrier sets will
+  // normally reserve space for such tables, and commit parts of the table
+  // "covering" parts of the heap that are committed. At most one covered
+  // region per generation is needed.
+  static const int _max_covered_regions = 2;
+
   int _cur_covered_regions;
+
   // The covered regions should be in address order.
   MemRegion* _covered;
   // The committed regions correspond one-to-one to the covered regions.
@@ -89,7 +97,6 @@
   // uncommit the MemRegion for that page.
   MemRegion _guard_region;
 
- protected:
   inline size_t compute_byte_map_size();
 
   // Finds and return the index of the region, if any, to which the given
@@ -135,7 +142,6 @@
     return byte_for(p) + 1;
   }
 
- protected:
   // Dirty the bytes corresponding to "mr" (not all of which must be
   // covered.)
   void dirty_MemRegion(MemRegion mr);
@@ -144,7 +150,7 @@
   // all of which must be covered.)
   void clear_MemRegion(MemRegion mr);
 
-public:
+ public:
   // Constants
   enum SomePublicConstants {
     card_shift                  = 9,
@@ -163,8 +169,6 @@
 
   // *** Barrier set functions.
 
-  bool has_write_ref_pre_barrier() { return false; }
-
   // Initialization utilities; covered_words is the size of the covered region
   // in, um, words.
   inline size_t cards_required(size_t covered_words) {
@@ -173,8 +177,7 @@
     return words / card_size_in_words + 1;
   }
 
-protected:
-
+ protected:
   CardTableModRefBS(MemRegion whole_heap, const BarrierSet::FakeRtti& fake_rtti);
   ~CardTableModRefBS();
 
@@ -185,29 +188,18 @@
 
   void write_ref_field_work(oop obj, size_t offset, oop newVal);
   virtual void write_ref_field_work(void* field, oop newVal, bool release);
-public:
 
-  bool has_write_ref_array_opt() { return true; }
-  bool has_write_region_opt() { return true; }
-
-  inline void inline_write_region(MemRegion mr) {
+ protected:
+  void write_region_work(MemRegion mr) {
     dirty_MemRegion(mr);
   }
-protected:
-  void write_region_work(MemRegion mr) {
-    inline_write_region(mr);
-  }
-public:
 
-  inline void inline_write_ref_array(MemRegion mr) {
+ protected:
+  void write_ref_array_work(MemRegion mr) {
     dirty_MemRegion(mr);
   }
-protected:
-  void write_ref_array_work(MemRegion mr) {
-    inline_write_ref_array(mr);
-  }
-public:
 
+ public:
   bool is_aligned(HeapWord* addr) {
     return is_card_aligned(addr);
   }
--- a/src/hotspot/share/gc/shared/collectedHeap.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/collectedHeap.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -135,14 +135,6 @@
   _barrier_set->print_on(st);
 }
 
-void CollectedHeap::register_nmethod(nmethod* nm) {
-  assert_locked_or_safepoint(CodeCache_lock);
-}
-
-void CollectedHeap::unregister_nmethod(nmethod* nm) {
-  assert_locked_or_safepoint(CodeCache_lock);
-}
-
 void CollectedHeap::trace_heap(GCWhen::Type when, const GCTracer* gc_tracer) {
   const GCHeapSummary& heap_summary = create_heap_summary();
   gc_tracer->report_gc_heap_summary(when, heap_summary);
@@ -355,7 +347,6 @@
              "Mismatch: multiple objects?");
     }
     BarrierSet* bs = barrier_set();
-    assert(bs->has_write_region_opt(), "No write_region() on BarrierSet");
     bs->write_region(deferred);
     // "Clear" the deferred_card_mark field
     thread->set_deferred_card_mark(MemRegion());
@@ -438,7 +429,6 @@
     } else {
       // Do the card mark
       BarrierSet* bs = barrier_set();
-      assert(bs->has_write_region_opt(), "No write_region() on BarrierSet");
       bs->write_region(mr);
     }
   }
--- a/src/hotspot/share/gc/shared/collectedHeap.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/collectedHeap.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -83,6 +83,7 @@
 //   GenCollectedHeap
 //   G1CollectedHeap
 //   ParallelScavengeHeap
+//   CMSHeap
 //
 class CollectedHeap : public CHeapObj<mtInternal> {
   friend class VMStructs;
@@ -194,7 +195,8 @@
   enum Name {
     GenCollectedHeap,
     ParallelScavengeHeap,
-    G1CollectedHeap
+    G1CollectedHeap,
+    CMSHeap
   };
 
   static inline size_t filler_array_max_size() {
@@ -219,6 +221,10 @@
   // Stop any onging concurrent work and prepare for exit.
   virtual void stop() {}
 
+  // Stop and resume concurrent GC threads interfering with safepoint operations
+  virtual void safepoint_synchronize_begin() {}
+  virtual void safepoint_synchronize_end() {}
+
   void initialize_reserved_region(HeapWord *start, HeapWord *end);
   MemRegion reserved_region() const { return _reserved; }
   address base() const { return (address)reserved_region().start(); }
@@ -287,10 +293,6 @@
     return p == NULL || is_in_closed_subset(p);
   }
 
-  // An object is scavengable if its location may move during a scavenge.
-  // (A scavenge is a GC which is not a full GC.)
-  virtual bool is_scavengable(const void *p) = 0;
-
   void set_gc_cause(GCCause::Cause v) {
      if (UsePerfData) {
        _gc_lastcause = _gc_cause;
@@ -568,10 +570,14 @@
   void print_heap_before_gc();
   void print_heap_after_gc();
 
+  // An object is scavengable if its location may move during a scavenge.
+  // (A scavenge is a GC which is not a full GC.)
+  virtual bool is_scavengable(oop obj) = 0;
   // Registering and unregistering an nmethod (compiled code) with the heap.
   // Override with specific mechanism for each specialized heap type.
-  virtual void register_nmethod(nmethod* nm);
-  virtual void unregister_nmethod(nmethod* nm);
+  virtual void register_nmethod(nmethod* nm) {}
+  virtual void unregister_nmethod(nmethod* nm) {}
+  virtual void verify_nmethod(nmethod* nmethod) {}
 
   void trace_heap_before_gc(const GCTracer* gc_tracer);
   void trace_heap_after_gc(const GCTracer* gc_tracer);
--- a/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -42,6 +42,7 @@
 #include "gc/shared/space.hpp"
 #include "gc/shared/strongRootsScope.hpp"
 #include "gc/shared/vmGCOperations.hpp"
+#include "gc/shared/weakProcessor.hpp"
 #include "gc/shared/workgroup.hpp"
 #include "memory/filemap.hpp"
 #include "memory/resourceArea.hpp"
@@ -58,28 +59,6 @@
 #include "utilities/macros.hpp"
 #include "utilities/stack.inline.hpp"
 #include "utilities/vmError.hpp"
-#if INCLUDE_ALL_GCS
-#include "gc/cms/concurrentMarkSweepThread.hpp"
-#include "gc/cms/vmCMSOperations.hpp"
-#endif // INCLUDE_ALL_GCS
-
-NOT_PRODUCT(size_t GenCollectedHeap::_skip_header_HeapWords = 0;)
-
-// The set of potentially parallel tasks in root scanning.
-enum GCH_strong_roots_tasks {
-  GCH_PS_Universe_oops_do,
-  GCH_PS_JNIHandles_oops_do,
-  GCH_PS_ObjectSynchronizer_oops_do,
-  GCH_PS_Management_oops_do,
-  GCH_PS_SystemDictionary_oops_do,
-  GCH_PS_ClassLoaderDataGraph_oops_do,
-  GCH_PS_jvmti_oops_do,
-  GCH_PS_CodeCache_oops_do,
-  GCH_PS_aot_oops_do,
-  GCH_PS_younger_gens,
-  // Leave this one last.
-  GCH_PS_NumElements
-};
 
 GenCollectedHeap::GenCollectedHeap(GenCollectorPolicy *policy) :
   CollectedHeap(),
@@ -89,15 +68,6 @@
   _full_collections_completed(0)
 {
   assert(policy != NULL, "Sanity check");
-  if (UseConcMarkSweepGC) {
-    _workers = new WorkGang("GC Thread", ParallelGCThreads,
-                            /* are_GC_task_threads */true,
-                            /* are_ConcurrentGC_threads */false);
-    _workers->initialize_workers();
-  } else {
-    // Serial GC does not use workers.
-    _workers = NULL;
-  }
 }
 
 jint GenCollectedHeap::initialize() {
@@ -138,15 +108,6 @@
   _old_gen = gen_policy()->old_gen_spec()->init(old_rs, rem_set());
   clear_incremental_collection_failed();
 
-#if INCLUDE_ALL_GCS
-  // If we are running CMS, create the collector responsible
-  // for collecting the CMS generations.
-  if (collector_policy()->is_concurrent_mark_sweep_policy()) {
-    bool success = create_cms_collector();
-    if (!success) return JNI_ENOMEM;
-  }
-#endif // INCLUDE_ALL_GCS
-
   return JNI_OK;
 }
 
@@ -183,21 +144,22 @@
 
 void GenCollectedHeap::post_initialize() {
   ref_processing_init();
-  assert((_young_gen->kind() == Generation::DefNew) ||
-         (_young_gen->kind() == Generation::ParNew),
-    "Wrong youngest generation type");
+  check_gen_kinds();
   DefNewGeneration* def_new_gen = (DefNewGeneration*)_young_gen;
 
-  assert(_old_gen->kind() == Generation::ConcurrentMarkSweep ||
-         _old_gen->kind() == Generation::MarkSweepCompact,
-    "Wrong generation kind");
-
   _gen_policy->initialize_size_policy(def_new_gen->eden()->capacity(),
                                       _old_gen->capacity(),
                                       def_new_gen->from()->capacity());
   _gen_policy->initialize_gc_policy_counters();
 }
 
+void GenCollectedHeap::check_gen_kinds() {
+  assert(young_gen()->kind() == Generation::DefNew,
+         "Wrong youngest generation type");
+  assert(old_gen()->kind() == Generation::MarkSweepCompact,
+         "Wrong generation kind");
+}
+
 void GenCollectedHeap::ref_processing_init() {
   _young_gen->ref_processor_init();
   _old_gen->ref_processor_init();
@@ -309,19 +271,6 @@
          _gc_cause == GCCause::_wb_full_gc;
 }
 
-bool GenCollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
-  if (!UseConcMarkSweepGC) {
-    return false;
-  }
-
-  switch (cause) {
-    case GCCause::_gc_locker:           return GCLockerInvokesConcurrent;
-    case GCCause::_java_lang_system_gc:
-    case GCCause::_dcmd_gc_run:         return ExplicitGCInvokesConcurrent;
-    default:                            return false;
-  }
-}
-
 void GenCollectedHeap::collect_generation(Generation* gen, bool full, size_t size,
                                           bool is_tlab, bool run_verification, bool clear_soft_refs,
                                           bool restore_marks_for_biased_locking) {
@@ -553,6 +502,14 @@
 #endif
 }
 
+void GenCollectedHeap::register_nmethod(nmethod* nm) {
+  CodeCache::register_scavenge_root_nmethod(nm);
+}
+
+void GenCollectedHeap::verify_nmethod(nmethod* nm) {
+  CodeCache::verify_scavenge_root_nmethod(nm);
+}
+
 HeapWord* GenCollectedHeap::satisfy_failed_allocation(size_t size, bool is_tlab) {
   return gen_policy()->satisfy_failed_allocation(size, is_tlab);
 }
@@ -674,31 +631,6 @@
   _process_strong_tasks->all_tasks_completed(scope->n_threads());
 }
 
-void GenCollectedHeap::cms_process_roots(StrongRootsScope* scope,
-                                         bool young_gen_as_roots,
-                                         ScanningOption so,
-                                         bool only_strong_roots,
-                                         OopsInGenClosure* root_closure,
-                                         CLDClosure* cld_closure) {
-  MarkingCodeBlobClosure mark_code_closure(root_closure, !CodeBlobToOopClosure::FixRelocations);
-  OopsInGenClosure* weak_roots = only_strong_roots ? NULL : root_closure;
-  CLDClosure* weak_cld_closure = only_strong_roots ? NULL : cld_closure;
-
-  process_roots(scope, so, root_closure, weak_roots, cld_closure, weak_cld_closure, &mark_code_closure);
-  if (!only_strong_roots) {
-    process_string_table_roots(scope, root_closure);
-  }
-
-  if (young_gen_as_roots &&
-      !_process_strong_tasks->is_task_claimed(GCH_PS_younger_gens)) {
-    root_closure->set_generation(_young_gen);
-    _young_gen->oop_iterate(root_closure);
-    root_closure->reset_generation();
-  }
-
-  _process_strong_tasks->all_tasks_completed(scope->n_threads());
-}
-
 void GenCollectedHeap::full_process_roots(StrongRootsScope* scope,
                                           bool is_adjust_phase,
                                           ScanningOption so,
@@ -721,7 +653,7 @@
 }
 
 void GenCollectedHeap::gen_process_weak_roots(OopClosure* root_closure) {
-  JNIHandles::weak_oops_do(root_closure);
+  WeakProcessor::oops_do(root_closure);
   _young_gen->ref_processor()->weak_oops_do(root_closure);
   _old_gen->ref_processor()->weak_oops_do(root_closure);
 }
@@ -763,14 +695,7 @@
 // public collection interfaces
 
 void GenCollectedHeap::collect(GCCause::Cause cause) {
-  if (should_do_concurrent_full_gc(cause)) {
-#if INCLUDE_ALL_GCS
-    // Mostly concurrent full collection.
-    collect_mostly_concurrent(cause);
-#else  // INCLUDE_ALL_GCS
-    ShouldNotReachHere();
-#endif // INCLUDE_ALL_GCS
-  } else if (cause == GCCause::_wb_young_gc) {
+  if (cause == GCCause::_wb_young_gc) {
     // Young collection for the WhiteBox API.
     collect(cause, YoungGen);
   } else {
@@ -817,44 +742,6 @@
   }
 }
 
-#if INCLUDE_ALL_GCS
-bool GenCollectedHeap::create_cms_collector() {
-
-  assert(_old_gen->kind() == Generation::ConcurrentMarkSweep,
-         "Unexpected generation kinds");
-  // Skip two header words in the block content verification
-  NOT_PRODUCT(_skip_header_HeapWords = CMSCollector::skip_header_HeapWords();)
-  assert(_gen_policy->is_concurrent_mark_sweep_policy(), "Unexpected policy type");
-  CMSCollector* collector =
-    new CMSCollector((ConcurrentMarkSweepGeneration*)_old_gen,
-                     _rem_set,
-                     _gen_policy->as_concurrent_mark_sweep_policy());
-
-  if (collector == NULL || !collector->completed_initialization()) {
-    if (collector) {
-      delete collector;  // Be nice in embedded situation
-    }
-    vm_shutdown_during_initialization("Could not create CMS collector");
-    return false;
-  }
-  return true;  // success
-}
-
-void GenCollectedHeap::collect_mostly_concurrent(GCCause::Cause cause) {
-  assert(!Heap_lock->owned_by_self(), "Should not own Heap_lock");
-
-  MutexLocker ml(Heap_lock);
-  // Read the GC counts while holding the Heap_lock
-  unsigned int full_gc_count_before = total_full_collections();
-  unsigned int gc_count_before      = total_collections();
-  {
-    MutexUnlocker mu(Heap_lock);
-    VM_GenCollectFullConcurrent op(gc_count_before, full_gc_count_before, cause);
-    VMThread::execute(&op);
-  }
-}
-#endif // INCLUDE_ALL_GCS
-
 void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs) {
    do_full_collection(clear_all_soft_refs, OldGen);
 }
@@ -1097,8 +984,9 @@
 GenCollectedHeap* GenCollectedHeap::heap() {
   CollectedHeap* heap = Universe::heap();
   assert(heap != NULL, "Uninitialized access to GenCollectedHeap::heap()");
-  assert(heap->kind() == CollectedHeap::GenCollectedHeap, "Not a GenCollectedHeap");
-  return (GenCollectedHeap*)heap;
+  assert(heap->kind() == CollectedHeap::GenCollectedHeap ||
+         heap->kind() == CollectedHeap::CMSHeap, "Not a GenCollectedHeap");
+  return (GenCollectedHeap*) heap;
 }
 
 void GenCollectedHeap::prepare_for_compaction() {
@@ -1126,34 +1014,9 @@
 }
 
 void GenCollectedHeap::gc_threads_do(ThreadClosure* tc) const {
-  if (workers() != NULL) {
-    workers()->threads_do(tc);
-  }
-#if INCLUDE_ALL_GCS
-  if (UseConcMarkSweepGC) {
-    ConcurrentMarkSweepThread::threads_do(tc);
-  }
-#endif // INCLUDE_ALL_GCS
 }
 
 void GenCollectedHeap::print_gc_threads_on(outputStream* st) const {
-#if INCLUDE_ALL_GCS
-  if (UseConcMarkSweepGC) {
-    workers()->print_worker_threads_on(st);
-    ConcurrentMarkSweepThread::print_all_on(st);
-  }
-#endif // INCLUDE_ALL_GCS
-}
-
-void GenCollectedHeap::print_on_error(outputStream* st) const {
-  this->CollectedHeap::print_on_error(st);
-
-#if INCLUDE_ALL_GCS
-  if (UseConcMarkSweepGC) {
-    st->cr();
-    CMSCollector::print_on_error(st);
-  }
-#endif // INCLUDE_ALL_GCS
 }
 
 void GenCollectedHeap::print_tracing_info() const {
@@ -1184,7 +1047,6 @@
 void GenCollectedHeap::gc_prologue(bool full) {
   assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer");
 
-  always_do_update_barrier = false;
   // Fill TLAB's and such
   CollectedHeap::accumulate_statistics_all_tlabs();
   ensure_parsability(true);   // retire TLABs
@@ -1222,8 +1084,6 @@
 
   MetaspaceCounters::update_performance_counters();
   CompressedClassSpaceCounters::update_performance_counters();
-
-  always_do_update_barrier = UseConcMarkSweepGC;
 };
 
 #ifndef PRODUCT
@@ -1304,11 +1164,3 @@
   }
   return retVal;
 }
-
-void GenCollectedHeap::stop() {
-#if INCLUDE_ALL_GCS
-  if (UseConcMarkSweepGC) {
-    ConcurrentMarkSweepThread::cmst()->stop();
-  }
-#endif
-}
--- a/src/hotspot/share/gc/shared/genCollectedHeap.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/genCollectedHeap.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -78,21 +78,34 @@
   // In support of ExplicitGCInvokesConcurrent functionality
   unsigned int _full_collections_completed;
 
-  // Data structure for claiming the (potentially) parallel tasks in
-  // (gen-specific) roots processing.
-  SubTasksDone* _process_strong_tasks;
-
   // Collects the given generation.
   void collect_generation(Generation* gen, bool full, size_t size, bool is_tlab,
                           bool run_verification, bool clear_soft_refs,
                           bool restore_marks_for_biased_locking);
 
-  // In block contents verification, the number of header words to skip
-  NOT_PRODUCT(static size_t _skip_header_HeapWords;)
+protected:
 
-  WorkGang* _workers;
+  // The set of potentially parallel tasks in root scanning.
+  enum GCH_strong_roots_tasks {
+    GCH_PS_Universe_oops_do,
+    GCH_PS_JNIHandles_oops_do,
+    GCH_PS_ObjectSynchronizer_oops_do,
+    GCH_PS_FlatProfiler_oops_do,
+    GCH_PS_Management_oops_do,
+    GCH_PS_SystemDictionary_oops_do,
+    GCH_PS_ClassLoaderDataGraph_oops_do,
+    GCH_PS_jvmti_oops_do,
+    GCH_PS_CodeCache_oops_do,
+    GCH_PS_aot_oops_do,
+    GCH_PS_younger_gens,
+    // Leave this one last.
+    GCH_PS_NumElements
+  };
 
-protected:
+  // Data structure for claiming the (potentially) parallel tasks in
+  // (gen-specific) roots processing.
+  SubTasksDone* _process_strong_tasks;
+
   // Helper functions for allocation
   HeapWord* attempt_allocation(size_t size,
                                bool   is_tlab,
@@ -124,8 +137,6 @@
 public:
   GenCollectedHeap(GenCollectorPolicy *policy);
 
-  WorkGang* workers() const { return _workers; }
-
   // Returns JNI_OK on success
   virtual jint initialize();
 
@@ -135,6 +146,8 @@
   // Does operations required after initialization has been done.
   void post_initialize();
 
+  virtual void check_gen_kinds();
+
   // Initialize ("weak") refs processing support
   virtual void ref_processing_init();
 
@@ -143,11 +156,7 @@
   }
 
   virtual const char* name() const {
-    if (UseConcMarkSweepGC) {
-      return "Concurrent Mark Sweep";
-    } else {
-      return "Serial";
-    }
+    return "Serial";
   }
 
   Generation* young_gen() const { return _young_gen; }
@@ -190,7 +199,7 @@
   // Perform a full collection of the heap; intended for use in implementing
   // "System.gc". This implies as full a collection as the CollectedHeap
   // supports. Caller does not hold the Heap_lock on entry.
-  void collect(GCCause::Cause cause);
+  virtual void collect(GCCause::Cause cause);
 
   // The same as above but assume that the caller holds the Heap_lock.
   void collect_locked(GCCause::Cause cause);
@@ -207,12 +216,8 @@
   bool is_in(const void* p) const;
 
   // override
-  bool is_in_closed_subset(const void* p) const {
-    if (UseConcMarkSweepGC) {
-      return is_in_reserved(p);
-    } else {
-      return is_in(p);
-    }
+  virtual bool is_in_closed_subset(const void* p) const {
+    return is_in(p);
   }
 
   // Returns true if the reference is to an object in the reserved space
@@ -224,10 +229,14 @@
   bool is_in_partial_collection(const void* p);
 #endif
 
-  virtual bool is_scavengable(const void* addr) {
-    return is_in_young((oop)addr);
+  virtual bool is_scavengable(oop obj) {
+    return is_in_young(obj);
   }
 
+  // Optimized nmethod scanning support routines
+  virtual void register_nmethod(nmethod* nm);
+  virtual void verify_nmethod(nmethod* nmethod);
+
   // Iteration functions.
   void oop_iterate_no_header(OopClosure* cl);
   void oop_iterate(ExtendedOopClosure* cl);
@@ -278,7 +287,7 @@
   }
 
   virtual bool card_mark_must_follow_store() const {
-    return UseConcMarkSweepGC;
+    return false;
   }
 
   // We don't need barriers for stores to objects in the
@@ -344,7 +353,6 @@
   virtual void print_gc_threads_on(outputStream* st) const;
   virtual void gc_threads_do(ThreadClosure* tc) const;
   virtual void print_tracing_info() const;
-  virtual void print_on_error(outputStream* st) const;
 
   void print_heap_change(size_t young_prev_used, size_t old_prev_used) const;
 
@@ -383,7 +391,7 @@
     SO_ScavengeCodeCache   = 0x10
   };
 
- private:
+ protected:
   void process_roots(StrongRootsScope* scope,
                      ScanningOption so,
                      OopClosure* strong_roots,
@@ -395,24 +403,20 @@
   void process_string_table_roots(StrongRootsScope* scope,
                                   OopClosure* root_closure);
 
+  // Accessor for memory state verification support
+  NOT_PRODUCT(
+    virtual size_t skip_header_HeapWords() { return 0; }
+  )
+
+  virtual void gc_prologue(bool full);
+  virtual void gc_epilogue(bool full);
+
  public:
   void young_process_roots(StrongRootsScope* scope,
                            OopsInGenClosure* root_closure,
                            OopsInGenClosure* old_gen_closure,
                            CLDClosure* cld_closure);
 
-  // If "young_gen_as_roots" is false, younger generations are
-  // not scanned as roots; in this case, the caller must be arranging to
-  // scan the younger generations itself.  (For example, a generation might
-  // explicitly mark reachable objects in younger generations, to avoid
-  // excess storage retention.)
-  void cms_process_roots(StrongRootsScope* scope,
-                         bool young_gen_as_roots,
-                         ScanningOption so,
-                         bool only_strong_roots,
-                         OopsInGenClosure* root_closure,
-                         CLDClosure* cld_closure);
-
   void full_process_roots(StrongRootsScope* scope,
                           bool is_adjust_phase,
                           ScanningOption so,
@@ -479,12 +483,8 @@
                               oop obj,
                               size_t obj_size);
 
+
 private:
-  // Accessor for memory state verification support
-  NOT_PRODUCT(
-    static size_t skip_header_HeapWords() { return _skip_header_HeapWords; }
-  )
-
   // Override
   void check_for_non_bad_heap_word_value(HeapWord* addr,
     size_t size) PRODUCT_RETURN;
@@ -499,22 +499,8 @@
   // collect() and collect_locked(). Caller holds the Heap_lock on entry.
   void collect_locked(GCCause::Cause cause, GenerationType max_generation);
 
-  // Returns success or failure.
-  bool create_cms_collector();
-
-  // In support of ExplicitGCInvokesConcurrent functionality
-  bool should_do_concurrent_full_gc(GCCause::Cause cause);
-  void collect_mostly_concurrent(GCCause::Cause cause);
-
   // Save the tops of the spaces in all generations
   void record_gen_tops_before_GC() PRODUCT_RETURN;
-
-protected:
-  void gc_prologue(bool full);
-  void gc_epilogue(bool full);
-
-public:
-  void stop();
 };
 
 #endif // SHARE_VM_GC_SHARED_GENCOLLECTEDHEAP_HPP
--- a/src/hotspot/share/gc/shared/modRefBarrierSet.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/modRefBarrierSet.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -35,57 +35,12 @@
 class Generation;
 
 class ModRefBarrierSet: public BarrierSet {
-public:
-
-  // Barriers only on ref writes.
-  bool has_read_ref_barrier() { return false; }
-  bool has_read_prim_barrier() { return false; }
-  bool has_write_ref_barrier() { return true; }
-  bool has_write_prim_barrier() { return false; }
-
-  bool read_ref_needs_barrier(void* field) { return false; }
-  bool read_prim_needs_barrier(HeapWord* field, size_t bytes) { return false; }
-  bool write_prim_needs_barrier(HeapWord* field, size_t bytes,
-                                juint val1, juint val2) { return false; }
-
-  void write_prim_field(oop obj, size_t offset, size_t bytes,
-                        juint val1, juint val2) {}
-
-  void read_ref_field(void* field) {}
-  void read_prim_field(HeapWord* field, size_t bytes) {}
-
 protected:
-
   ModRefBarrierSet(const BarrierSet::FakeRtti& fake_rtti)
     : BarrierSet(fake_rtti.add_tag(BarrierSet::ModRef)) { }
   ~ModRefBarrierSet() { }
 
 public:
-  void write_prim_field(HeapWord* field, size_t bytes,
-                        juint val1, juint val2) {}
-
-  bool has_read_ref_array_opt() { return false; }
-  bool has_read_prim_array_opt() { return false; }
-  bool has_write_prim_array_opt() { return false; }
-
-  bool has_read_region_opt() { return false; }
-
-
-  // These operations should assert false unless the corresponding operation
-  // above returns true.
-  void read_ref_array(MemRegion mr) {
-    assert(false, "can't call");
-  }
-  void read_prim_array(MemRegion mr) {
-    assert(false, "can't call");
-  }
-  void write_prim_array(MemRegion mr) {
-    assert(false, "can't call");
-  }
-  void read_region(MemRegion mr) {
-    assert(false, "can't call");
-  }
-
   // Causes all refs in "mr" to be assumed to be modified.
   virtual void invalidate(MemRegion mr) = 0;
 
--- a/src/hotspot/share/gc/shared/plab.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/plab.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -43,19 +43,19 @@
 }
 
 void PLABStats::add_allocated(size_t v) {
-  Atomic::add_ptr(v, &_allocated);
+  Atomic::add(v, &_allocated);
 }
 
 void PLABStats::add_unused(size_t v) {
-  Atomic::add_ptr(v, &_unused);
+  Atomic::add(v, &_unused);
 }
 
 void PLABStats::add_wasted(size_t v) {
-  Atomic::add_ptr(v, &_wasted);
+  Atomic::add(v, &_wasted);
 }
 
 void PLABStats::add_undo_wasted(size_t v) {
-  Atomic::add_ptr(v, &_undo_wasted);
+  Atomic::add(v, &_undo_wasted);
 }
 
 #endif // SHARE_VM_GC_SHARED_PLAB_INLINE_HPP
--- a/src/hotspot/share/gc/shared/referenceProcessor.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/referenceProcessor.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -36,7 +36,6 @@
 #include "memory/resourceArea.hpp"
 #include "oops/oop.inline.hpp"
 #include "runtime/java.hpp"
-#include "runtime/jniHandles.hpp"
 
 ReferencePolicy* ReferenceProcessor::_always_clear_soft_ref_policy = NULL;
 ReferencePolicy* ReferenceProcessor::_default_soft_ref_policy      = NULL;
@@ -245,51 +244,16 @@
                                is_alive, keep_alive, complete_gc, task_executor, phase_times);
   }
 
-  // Weak global JNI references. It would make more sense (semantically) to
-  // traverse these simultaneously with the regular weak references above, but
-  // that is not how the JDK1.2 specification is. See #4126360. Native code can
-  // thus use JNI weak references to circumvent the phantom references and
-  // resurrect a "post-mortem" object.
-  {
-    GCTraceTime(Debug, gc, ref) tt("JNI Weak Reference", phase_times->gc_timer());
-    if (task_executor != NULL) {
-      task_executor->set_single_threaded_mode();
-    }
-    process_phaseJNI(is_alive, keep_alive, complete_gc);
+  if (task_executor != NULL) {
+    // Record the work done by the parallel workers.
+    task_executor->set_single_threaded_mode();
   }
 
   phase_times->set_total_time_ms((os::elapsedTime() - start_time) * 1000);
 
-  log_develop_trace(gc, ref)("JNI Weak Reference count: " SIZE_FORMAT, count_jni_refs());
-
   return stats;
 }
 
-#ifndef PRODUCT
-// Calculate the number of jni handles.
-size_t ReferenceProcessor::count_jni_refs() {
-  class CountHandleClosure: public OopClosure {
-  private:
-    size_t _count;
-  public:
-    CountHandleClosure(): _count(0) {}
-    void do_oop(oop* unused)       { _count++; }
-    void do_oop(narrowOop* unused) { ShouldNotReachHere(); }
-    size_t count() { return _count; }
-  };
-  CountHandleClosure global_handle_count;
-  JNIHandles::weak_oops_do(&global_handle_count);
-  return global_handle_count.count();
-}
-#endif
-
-void ReferenceProcessor::process_phaseJNI(BoolObjectClosure* is_alive,
-                                          OopClosure*        keep_alive,
-                                          VoidClosure*       complete_gc) {
-  JNIHandles::weak_oops_do(is_alive, keep_alive);
-  complete_gc->do_void();
-}
-
 void ReferenceProcessor::enqueue_discovered_references(AbstractRefProcTaskExecutor*  task_executor,
                                                        ReferenceProcessorPhaseTimes* phase_times) {
   // Enqueue references that are not made active again, and
--- a/src/hotspot/share/gc/shared/referenceProcessor.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/referenceProcessor.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -246,10 +246,6 @@
                                   AbstractRefProcTaskExecutor*  task_executor,
                                   ReferenceProcessorPhaseTimes* phase_times);
 
-  void process_phaseJNI(BoolObjectClosure* is_alive,
-                        OopClosure*        keep_alive,
-                        VoidClosure*       complete_gc);
-
   // Work methods used by the method process_discovered_reflist
   // Phase1: keep alive all those referents that are otherwise
   // dead but which must be kept alive by policy (and their closure).
@@ -341,9 +337,6 @@
 
   void clear_discovered_references(DiscoveredList& refs_list);
 
-  // Calculate the number of jni handles.
-  size_t count_jni_refs();
-
   void log_reflist_counts(DiscoveredList ref_lists[], uint active_length, size_t total_count) PRODUCT_RETURN;
 
   // Balances reference queues.
--- a/src/hotspot/share/gc/shared/space.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/space.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -631,7 +631,7 @@
     HeapWord* obj = top();
     if (pointer_delta(end(), obj) >= size) {
       HeapWord* new_top = obj + size;
-      HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
+      HeapWord* result = Atomic::cmpxchg(new_top, top_addr(), obj);
       // result can be one of two:
       //  the old top value: the exchange succeeded
       //  otherwise: the new value of the top is returned.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/shared/suspendibleThreadSet.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2014, 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 "precompiled.hpp"
+#include "gc/shared/suspendibleThreadSet.hpp"
+#include "runtime/mutexLocker.hpp"
+#include "runtime/semaphore.hpp"
+#include "runtime/thread.inline.hpp"
+
+uint   SuspendibleThreadSet::_nthreads          = 0;
+uint   SuspendibleThreadSet::_nthreads_stopped  = 0;
+bool   SuspendibleThreadSet::_suspend_all       = false;
+double SuspendibleThreadSet::_suspend_all_start = 0.0;
+
+static Semaphore* _synchronize_wakeup = NULL;
+
+void SuspendibleThreadSet_init() {
+  assert(_synchronize_wakeup == NULL, "STS already initialized");
+  _synchronize_wakeup = new Semaphore();
+}
+
+bool SuspendibleThreadSet::is_synchronized() {
+  assert_lock_strong(STS_lock);
+  assert(_nthreads_stopped <= _nthreads, "invariant");
+  return _nthreads_stopped == _nthreads;
+}
+
+void SuspendibleThreadSet::join() {
+  assert(!Thread::current()->is_suspendible_thread(), "Thread already joined");
+  MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
+  while (_suspend_all) {
+    ml.wait(Mutex::_no_safepoint_check_flag);
+  }
+  _nthreads++;
+  DEBUG_ONLY(Thread::current()->set_suspendible_thread();)
+}
+
+void SuspendibleThreadSet::leave() {
+  assert(Thread::current()->is_suspendible_thread(), "Thread not joined");
+  MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
+  assert(_nthreads > 0, "Invalid");
+  DEBUG_ONLY(Thread::current()->clear_suspendible_thread();)
+  _nthreads--;
+  if (_suspend_all && is_synchronized()) {
+    // This leave completes a request, so inform the requestor.
+    _synchronize_wakeup->signal();
+  }
+}
+
+void SuspendibleThreadSet::yield() {
+  assert(Thread::current()->is_suspendible_thread(), "Must have joined");
+  MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
+  if (_suspend_all) {
+    _nthreads_stopped++;
+    if (is_synchronized()) {
+      if (ConcGCYieldTimeout > 0) {
+        double now = os::elapsedTime();
+        guarantee((now - _suspend_all_start) * 1000.0 < (double)ConcGCYieldTimeout, "Long delay");
+      }
+      // This yield completes the request, so inform the requestor.
+      _synchronize_wakeup->signal();
+    }
+    while (_suspend_all) {
+      ml.wait(Mutex::_no_safepoint_check_flag);
+    }
+    assert(_nthreads_stopped > 0, "Invalid");
+    _nthreads_stopped--;
+  }
+}
+
+void SuspendibleThreadSet::synchronize() {
+  assert(Thread::current()->is_VM_thread(), "Must be the VM thread");
+  if (ConcGCYieldTimeout > 0) {
+    _suspend_all_start = os::elapsedTime();
+  }
+  {
+    MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
+    assert(!_suspend_all, "Only one at a time");
+    _suspend_all = true;
+    if (is_synchronized()) {
+      return;
+    }
+  } // Release lock before semaphore wait.
+
+  // Semaphore initial count is zero.  To reach here, there must be at
+  // least one not yielded thread in the set, e.g. is_synchronized()
+  // was false before the lock was released.  A thread in the set will
+  // signal the semaphore iff it is the last to yield or leave while
+  // there is an active suspend request.  So there will be exactly one
+  // signal, which will increment the semaphore count to one, which
+  // will then be consumed by this wait, returning it to zero.  No
+  // thread can exit yield or enter the set until desynchronize is
+  // called, so there are no further opportunities for the semaphore
+  // being signaled until we get back here again for some later
+  // synchronize call.  Hence, there is no need to re-check for
+  // is_synchronized after the wait; it will always be true there.
+  _synchronize_wakeup->wait();
+
+#ifdef ASSERT
+  MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
+  assert(_suspend_all, "STS not synchronizing");
+  assert(is_synchronized(), "STS not synchronized");
+#endif
+}
+
+void SuspendibleThreadSet::desynchronize() {
+  assert(Thread::current()->is_VM_thread(), "Must be the VM thread");
+  MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
+  assert(_suspend_all, "STS not synchronizing");
+  assert(is_synchronized(), "STS not synchronized");
+  _suspend_all = false;
+  ml.notify_all();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/shared/suspendibleThreadSet.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2014, 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.
+ *
+ */
+
+#ifndef SHARE_GC_SHARED_SUSPENDIBLETHREADSET_HPP
+#define SHARE_GC_SHARED_SUSPENDIBLETHREADSET_HPP
+
+#include "memory/allocation.hpp"
+
+// A SuspendibleThreadSet is a set of threads that can be suspended.
+// A thread can join and later leave the set, and periodically yield.
+// If some thread (not in the set) requests, via synchronize(), that
+// the threads be suspended, then the requesting thread is blocked
+// until all the threads in the set have yielded or left the set. Threads
+// may not enter the set when an attempted suspension is in progress. The
+// suspending thread later calls desynchronize(), allowing the suspended
+// threads to continue.
+class SuspendibleThreadSet : public AllStatic {
+  friend class SuspendibleThreadSetJoiner;
+  friend class SuspendibleThreadSetLeaver;
+
+private:
+  static uint   _nthreads;
+  static uint   _nthreads_stopped;
+  static bool   _suspend_all;
+  static double _suspend_all_start;
+
+  static bool is_synchronized();
+
+  // Add the current thread to the set. May block if a suspension is in progress.
+  static void join();
+
+  // Removes the current thread from the set.
+  static void leave();
+
+public:
+  // Returns true if an suspension is in progress.
+  static bool should_yield() { return _suspend_all; }
+
+  // Suspends the current thread if a suspension is in progress.
+  static void yield();
+
+  // Returns when all threads in the set are suspended.
+  static void synchronize();
+
+  // Resumes all suspended threads in the set.
+  static void desynchronize();
+};
+
+class SuspendibleThreadSetJoiner : public StackObj {
+private:
+  bool _active;
+
+public:
+  SuspendibleThreadSetJoiner(bool active = true) : _active(active) {
+    if (_active) {
+      SuspendibleThreadSet::join();
+    }
+  }
+
+  ~SuspendibleThreadSetJoiner() {
+    if (_active) {
+      SuspendibleThreadSet::leave();
+    }
+  }
+
+  bool should_yield() {
+    if (_active) {
+      return SuspendibleThreadSet::should_yield();
+    } else {
+      return false;
+    }
+  }
+
+  void yield() {
+    assert(_active, "Thread has not joined the suspendible thread set");
+    SuspendibleThreadSet::yield();
+  }
+};
+
+class SuspendibleThreadSetLeaver : public StackObj {
+private:
+  bool _active;
+
+public:
+  SuspendibleThreadSetLeaver(bool active = true) : _active(active) {
+    if (_active) {
+      SuspendibleThreadSet::leave();
+    }
+  }
+
+  ~SuspendibleThreadSetLeaver() {
+    if (_active) {
+      SuspendibleThreadSet::join();
+    }
+  }
+};
+
+#endif // SHARE_GC_SHARED_SUSPENDIBLETHREADSET_HPP
--- a/src/hotspot/share/gc/shared/taskqueue.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/gc/shared/taskqueue.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -259,9 +259,7 @@
 
 template <unsigned int N, MEMFLAGS F>
 inline typename TaskQueueSuper<N, F>::Age TaskQueueSuper<N, F>::Age::cmpxchg(const Age new_age, const Age old_age) volatile {
-  return (size_t) Atomic::cmpxchg_ptr((intptr_t)new_age._data,
-                                      (volatile intptr_t *)&_data,
-                                      (intptr_t)old_age._data);
+  return Atomic::cmpxchg(new_age._data, &_data, old_age._data);
 }
 
 template<class E, MEMFLAGS F, unsigned int N>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/shared/weakProcessor.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,42 @@
+/*
+ * 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 "precompiled.hpp"
+#include "gc/shared/weakProcessor.hpp"
+#include "prims/jvmtiExport.hpp"
+#include "runtime/jniHandles.hpp"
+
+void WeakProcessor::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive, VoidClosure* complete) {
+  JNIHandles::weak_oops_do(is_alive, keep_alive);
+  JvmtiExport::weak_oops_do(is_alive, keep_alive);
+
+  if (complete != NULL) {
+    complete->do_void();
+  }
+}
+
+void WeakProcessor::oops_do(OopClosure* closure) {
+  AlwaysTrueClosure always_true;
+  weak_oops_do(&always_true, closure, NULL);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/shared/weakProcessor.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef SHARE_VM_GC_SHARED_WEAKPROCESSOR_HPP
+#define SHARE_VM_GC_SHARED_WEAKPROCESSOR_HPP
+
+#include "memory/allocation.hpp"
+#include "memory/iterator.hpp"
+
+// Helper class to aid in root scanning and cleaning of weak oops in the VM.
+//
+// New containers of weak oops added to this class will automatically
+// be cleaned by all GCs, including the young generation GCs.
+class WeakProcessor : AllStatic {
+public:
+  // Visit all oop*s and apply the keep_alive closure if the referenced
+  // object is considered alive by the is_alive closure, otherwise do some
+  // container specific cleanup of element holding the oop.
+  //
+  // The complete closure is used as a post-processing step,
+  // called after all container have been processed.
+  static void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive, VoidClosure* complete = NULL);
+
+  // Visit all oop*s and apply the given closure.
+  static void oops_do(OopClosure* closure);
+};
+
+#endif // SHARE_VM_GC_SHARED_WEAKPROCESSOR_HPP
--- a/src/hotspot/share/interpreter/bytecodeInterpreter.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/interpreter/bytecodeInterpreter.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -705,7 +705,7 @@
             if (hash != markOopDesc::no_hash) {
               header = header->copy_set_hash(hash);
             }
-            if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), mark) == mark) {
+            if (Atomic::cmpxchg(header, rcvr->mark_addr(), mark) == mark) {
               if (PrintBiasedLockingStatistics)
                 (*BiasedLocking::revoked_lock_entry_count_addr())++;
             }
@@ -715,7 +715,7 @@
             if (hash != markOopDesc::no_hash) {
               new_header = new_header->copy_set_hash(hash);
             }
-            if (Atomic::cmpxchg_ptr((void*)new_header, rcvr->mark_addr(), mark) == mark) {
+            if (Atomic::cmpxchg(new_header, rcvr->mark_addr(), mark) == mark) {
               if (PrintBiasedLockingStatistics) {
                 (* BiasedLocking::rebiased_lock_entry_count_addr())++;
               }
@@ -734,7 +734,7 @@
             markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
             // Debugging hint.
             DEBUG_ONLY(mon->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
-            if (Atomic::cmpxchg_ptr((void*)new_header, rcvr->mark_addr(), header) == header) {
+            if (Atomic::cmpxchg(new_header, rcvr->mark_addr(), header) == header) {
               if (PrintBiasedLockingStatistics) {
                 (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
               }
@@ -750,7 +750,7 @@
           markOop displaced = rcvr->mark()->set_unlocked();
           mon->lock()->set_displaced_header(displaced);
           bool call_vm = UseHeavyMonitors;
-          if (call_vm || Atomic::cmpxchg_ptr(mon, rcvr->mark_addr(), displaced) != displaced) {
+          if (call_vm || Atomic::cmpxchg((markOop)mon, rcvr->mark_addr(), displaced) != displaced) {
             // Is it simple recursive case?
             if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
               mon->lock()->set_displaced_header(NULL);
@@ -903,7 +903,7 @@
           if (hash != markOopDesc::no_hash) {
             header = header->copy_set_hash(hash);
           }
-          if (Atomic::cmpxchg_ptr(header, lockee->mark_addr(), mark) == mark) {
+          if (Atomic::cmpxchg(header, lockee->mark_addr(), mark) == mark) {
             if (PrintBiasedLockingStatistics) {
               (*BiasedLocking::revoked_lock_entry_count_addr())++;
             }
@@ -914,7 +914,7 @@
           if (hash != markOopDesc::no_hash) {
                 new_header = new_header->copy_set_hash(hash);
           }
-          if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), mark) == mark) {
+          if (Atomic::cmpxchg(new_header, lockee->mark_addr(), mark) == mark) {
             if (PrintBiasedLockingStatistics) {
               (* BiasedLocking::rebiased_lock_entry_count_addr())++;
             }
@@ -932,7 +932,7 @@
           markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
           // debugging hint
           DEBUG_ONLY(entry->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
-          if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), header) == header) {
+          if (Atomic::cmpxchg(new_header, lockee->mark_addr(), header) == header) {
             if (PrintBiasedLockingStatistics) {
               (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
             }
@@ -948,7 +948,7 @@
         markOop displaced = lockee->mark()->set_unlocked();
         entry->lock()->set_displaced_header(displaced);
         bool call_vm = UseHeavyMonitors;
-        if (call_vm || Atomic::cmpxchg_ptr(entry, lockee->mark_addr(), displaced) != displaced) {
+        if (call_vm || Atomic::cmpxchg((markOop)entry, lockee->mark_addr(), displaced) != displaced) {
           // Is it simple recursive case?
           if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
             entry->lock()->set_displaced_header(NULL);
@@ -1844,7 +1844,7 @@
               if (hash != markOopDesc::no_hash) {
                 header = header->copy_set_hash(hash);
               }
-              if (Atomic::cmpxchg_ptr(header, lockee->mark_addr(), mark) == mark) {
+              if (Atomic::cmpxchg(header, lockee->mark_addr(), mark) == mark) {
                 if (PrintBiasedLockingStatistics)
                   (*BiasedLocking::revoked_lock_entry_count_addr())++;
               }
@@ -1855,7 +1855,7 @@
               if (hash != markOopDesc::no_hash) {
                 new_header = new_header->copy_set_hash(hash);
               }
-              if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), mark) == mark) {
+              if (Atomic::cmpxchg(new_header, lockee->mark_addr(), mark) == mark) {
                 if (PrintBiasedLockingStatistics)
                   (* BiasedLocking::rebiased_lock_entry_count_addr())++;
               }
@@ -1875,7 +1875,7 @@
               markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
               // debugging hint
               DEBUG_ONLY(entry->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
-              if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), header) == header) {
+              if (Atomic::cmpxchg(new_header, lockee->mark_addr(), header) == header) {
                 if (PrintBiasedLockingStatistics)
                   (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
               }
@@ -1891,7 +1891,7 @@
             markOop displaced = lockee->mark()->set_unlocked();
             entry->lock()->set_displaced_header(displaced);
             bool call_vm = UseHeavyMonitors;
-            if (call_vm || Atomic::cmpxchg_ptr(entry, lockee->mark_addr(), displaced) != displaced) {
+            if (call_vm || Atomic::cmpxchg((markOop)entry, lockee->mark_addr(), displaced) != displaced) {
               // Is it simple recursive case?
               if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
                 entry->lock()->set_displaced_header(NULL);
@@ -1923,7 +1923,8 @@
               bool call_vm = UseHeavyMonitors;
               // If it isn't recursive we either must swap old header or call the runtime
               if (header != NULL || call_vm) {
-                if (call_vm || Atomic::cmpxchg_ptr(header, lockee->mark_addr(), lock) != lock) {
+                markOop old_header = markOopDesc::encode(lock);
+                if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) {
                   // restore object for the slow case
                   most_recent->set_obj(lockee);
                   CALL_VM(InterpreterRuntime::monitorexit(THREAD, most_recent), handle_exception);
@@ -2189,7 +2190,7 @@
               HeapWord* compare_to = *Universe::heap()->top_addr();
               HeapWord* new_top = compare_to + obj_size;
               if (new_top <= *Universe::heap()->end_addr()) {
-                if (Atomic::cmpxchg_ptr(new_top, Universe::heap()->top_addr(), compare_to) != compare_to) {
+                if (Atomic::cmpxchg(new_top, Universe::heap()->top_addr(), compare_to) != compare_to) {
                   goto retry;
                 }
                 result = (oop) compare_to;
@@ -2975,7 +2976,8 @@
           if (!lockee->mark()->has_bias_pattern()) {
             // If it isn't recursive we either must swap old header or call the runtime
             if (header != NULL) {
-              if (Atomic::cmpxchg_ptr(header, lockee->mark_addr(), lock) != lock) {
+              markOop old_header = markOopDesc::encode(lock);
+              if (lockee->cas_set_mark(header, old_header) != old_header) {
                 // restore object for the slow case
                 end->set_obj(lockee);
                 {
@@ -3050,7 +3052,8 @@
               base->set_obj(NULL);
               // If it isn't recursive we either must swap old header or call the runtime
               if (header != NULL) {
-                if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) {
+                markOop old_header = markOopDesc::encode(lock);
+                if (rcvr->cas_set_mark(header, old_header) != old_header) {
                   // restore object for the slow case
                   base->set_obj(rcvr);
                   {
--- a/src/hotspot/share/interpreter/oopMapCache.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/interpreter/oopMapCache.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -448,11 +448,11 @@
 }
 
 OopMapCacheEntry* OopMapCache::entry_at(int i) const {
-  return (OopMapCacheEntry*)OrderAccess::load_ptr_acquire(&(_array[i % _size]));
+  return OrderAccess::load_acquire(&(_array[i % _size]));
 }
 
 bool OopMapCache::put_at(int i, OopMapCacheEntry* entry, OopMapCacheEntry* old) {
-  return Atomic::cmpxchg_ptr (entry, &_array[i % _size], old) == old;
+  return Atomic::cmpxchg(entry, &_array[i % _size], old) == old;
 }
 
 void OopMapCache::flush() {
@@ -564,7 +564,7 @@
   do {
     head = _old_entries;
     entry->_next = head;
-    success = Atomic::cmpxchg_ptr (entry, &_old_entries, head) == head;
+    success = Atomic::cmpxchg(entry, &_old_entries, head) == head;
   } while (!success);
 
   if (log_is_enabled(Debug, interpreter, oopmap)) {
--- a/src/hotspot/share/jvmci/compilerRuntime.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/jvmci/compilerRuntime.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -24,10 +24,14 @@
 #include "precompiled.hpp"
 #include "classfile/stringTable.hpp"
 #include "classfile/symbolTable.hpp"
+#include "interpreter/linkResolver.hpp"
 #include "jvmci/compilerRuntime.hpp"
+#include "oops/oop.inline.hpp"
 #include "runtime/compilationPolicy.hpp"
 #include "runtime/deoptimization.hpp"
 #include "runtime/interfaceSupport.hpp"
+#include "runtime/vframe.hpp"
+#include "aot/aotLoader.hpp"
 
 // Resolve and allocate String
 JRT_BLOCK_ENTRY(void, CompilerRuntime::resolve_string_by_symbol(JavaThread *thread, void* string_result, const char* name))
@@ -119,6 +123,62 @@
   return m;
 }
 
+JRT_BLOCK_ENTRY(void, CompilerRuntime::resolve_dynamic_invoke(JavaThread *thread, oop* appendix_result))
+  JRT_BLOCK
+  {
+    ResourceMark rm(THREAD);
+    vframeStream vfst(thread, true);  // Do not skip and javaCalls
+    assert(!vfst.at_end(), "Java frame must exist");
+    methodHandle caller(THREAD, vfst.method());
+    InstanceKlass* holder = caller->method_holder();
+    int bci = vfst.bci();
+    Bytecode_invoke bytecode(caller, bci);
+    int index = bytecode.index();
+
+    // Make sure it's resolved first
+    CallInfo callInfo;
+    constantPoolHandle cp(holder->constants());
+    ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index, true));
+    Bytecodes::Code invoke_code = bytecode.invoke_code();
+    if (!cp_cache_entry->is_resolved(invoke_code)) {
+        LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, invoke_code, CHECK);
+        if (bytecode.is_invokedynamic()) {
+            cp_cache_entry->set_dynamic_call(cp, callInfo);
+        } else {
+            cp_cache_entry->set_method_handle(cp, callInfo);
+        }
+        vmassert(cp_cache_entry->is_resolved(invoke_code), "sanity");
+    }
+
+    Handle appendix(THREAD, cp_cache_entry->appendix_if_resolved(cp));
+    Klass *appendix_klass = appendix.is_null() ? NULL : appendix->klass();
+
+    methodHandle adapter_method(cp_cache_entry->f1_as_method());
+    InstanceKlass *adapter_klass = adapter_method->method_holder();
+
+    if (appendix_klass != NULL && appendix_klass->is_instance_klass()) {
+        vmassert(InstanceKlass::cast(appendix_klass)->is_initialized(), "sanity");
+    }
+    if (!adapter_klass->is_initialized()) {
+        // Force initialization of adapter class
+        adapter_klass->initialize(CHECK);
+        // Double-check that it was really initialized,
+        // because we could be doing a recursive call
+        // from inside <clinit>.
+    }
+
+    int cpi = cp_cache_entry->constant_pool_index();
+    if (!AOTLoader::reconcile_dynamic_invoke(holder, cpi, adapter_method(),
+      appendix_klass)) {
+      return;
+    }
+
+    *appendix_result = appendix();
+    thread->set_vm_result(appendix());
+  }
+  JRT_BLOCK_END
+JRT_END
+
 JRT_BLOCK_ENTRY(MethodCounters*, CompilerRuntime::resolve_method_by_symbol_and_load_counters(JavaThread *thread, MethodCounters** counters_result, Klass* klass, const char* data))
   MethodCounters* c = *counters_result; // Is it resolved already?
   JRT_BLOCK
--- a/src/hotspot/share/jvmci/compilerRuntime.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/jvmci/compilerRuntime.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -39,6 +39,8 @@
                                        const char* signature_name, int signature_name_len);
   // Resolution methods for aot compiled code.
   static void resolve_string_by_symbol(JavaThread *thread, void* string_result, const char* name);
+  static void resolve_dynamic_invoke(JavaThread *thread, oop* appendix_result);
+
   static Klass* resolve_klass_by_symbol(JavaThread *thread, Klass** klass_result, const char* name);
   static Klass* initialize_klass_by_symbol(JavaThread *thread, Klass** klass_result, const char* name);
   static MethodCounters* resolve_method_by_symbol_and_load_counters(JavaThread *thread, MethodCounters** counters_result, Klass* klass_hint, const char* data);
--- a/src/hotspot/share/jvmci/jvmciCodeInstaller.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/jvmci/jvmciCodeInstaller.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -174,43 +174,42 @@
 }
 
 AOTOopRecorder::AOTOopRecorder(Arena* arena, bool deduplicate) : OopRecorder(arena, deduplicate) {
-  _meta_strings = new GrowableArray<const char*>();
+  _meta_refs = new GrowableArray<jobject>();
 }
 
-int AOTOopRecorder::nr_meta_strings() const {
-  return _meta_strings->length();
+int AOTOopRecorder::nr_meta_refs() const {
+  return _meta_refs->length();
 }
 
-const char* AOTOopRecorder::meta_element(int pos) const {
-  return _meta_strings->at(pos);
+jobject AOTOopRecorder::meta_element(int pos) const {
+  return _meta_refs->at(pos);
 }
 
 int AOTOopRecorder::find_index(Metadata* h) {
+  JavaThread* THREAD = JavaThread::current();
+  int oldCount = metadata_count();
   int index =  this->OopRecorder::find_index(h);
+  int newCount = metadata_count();
+
+  if (oldCount == newCount) {
+    // found a match
+    return index;
+  }
+
+  vmassert(index + 1 == newCount, "must be last");
 
   Klass* klass = NULL;
+  oop result = NULL;
   if (h->is_klass()) {
     klass = (Klass*) h;
-    record_meta_string(klass->signature_name(), index);
+    result = CompilerToVM::get_jvmci_type(klass, CATCH);
   } else if (h->is_method()) {
     Method* method = (Method*) h;
-    // Need klass->signature_name() in method name
-    klass = method->method_holder();
-    const char* klass_name = klass->signature_name();
-    int klass_name_len  = (int)strlen(klass_name);
-    Symbol* method_name = method->name();
-    Symbol* signature   = method->signature();
-    int method_name_len = method_name->utf8_length();
-    int method_sign_len = signature->utf8_length();
-    int len             = klass_name_len + 1 + method_name_len + method_sign_len;
-    char* dest          = NEW_RESOURCE_ARRAY(char, len + 1);
-    strcpy(dest, klass_name);
-    dest[klass_name_len] = '.';
-    strcpy(&dest[klass_name_len + 1], method_name->as_C_string());
-    strcpy(&dest[klass_name_len + 1 + method_name_len], signature->as_C_string());
-    dest[len] = 0;
-    record_meta_string(dest, index);
+    methodHandle mh(method);
+    result = CompilerToVM::get_jvmci_method(method, CATCH);
   }
+  jobject ref = JNIHandles::make_local(THREAD, result);
+  record_meta_ref(ref, index);
 
   return index;
 }
@@ -224,16 +223,12 @@
   return find_index(klass);
 }
 
-void AOTOopRecorder::record_meta_string(const char* name, int index) {
+void AOTOopRecorder::record_meta_ref(jobject o, int index) {
   assert(index > 0, "must be 1..n");
   index -= 1; // reduce by one to convert to array index
 
-  if (index < _meta_strings->length()) {
-    assert(strcmp(name, _meta_strings->at(index)) == 0, "must match");
-  } else {
-    assert(index == _meta_strings->length(), "must be last");
-    _meta_strings->append(name);
-  }
+  assert(index == _meta_refs->length(), "must be last");
+  _meta_refs->append(o);
 }
 
 void* CodeInstaller::record_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS) {
--- a/src/hotspot/share/jvmci/jvmciCodeInstaller.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/jvmci/jvmciCodeInstaller.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -49,13 +49,13 @@
 
   virtual int find_index(Metadata* h);
   virtual int find_index(jobject h);
-  int nr_meta_strings() const;
-  const char* meta_element(int pos) const;
+  int nr_meta_refs() const;
+  jobject meta_element(int pos) const;
 
 private:
-  void record_meta_string(const char* name, int index);
+  void record_meta_ref(jobject ref, int index);
 
-  GrowableArray<const char*>* _meta_strings;
+  GrowableArray<jobject>* _meta_refs;
 };
 
 class CodeMetadata {
--- a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1118,13 +1118,15 @@
 
   AOTOopRecorder* recorder = code_metadata.get_oop_recorder();
 
-  int nr_meta_strings = recorder->nr_meta_strings();
-  objArrayOop metadataArray = oopFactory::new_objectArray(nr_meta_strings, CHECK_(JVMCIEnv::cache_full));
+  int nr_meta_refs = recorder->nr_meta_refs();
+  objArrayOop metadataArray = oopFactory::new_objectArray(nr_meta_refs, CHECK_(JVMCIEnv::cache_full));
   objArrayHandle metadataArrayHandle(THREAD, metadataArray);
-  for (int i = 0; i < nr_meta_strings; ++i) {
-    const char* element = recorder->meta_element(i);
-    Handle java_string = java_lang_String::create_from_str(element, CHECK_(JVMCIEnv::cache_full));
-    metadataArrayHandle->obj_at_put(i, java_string());
+  for (int i = 0; i < nr_meta_refs; ++i) {
+    jobject element = recorder->meta_element(i);
+    if (element == NULL) {
+      return JVMCIEnv::cache_full;
+    }
+    metadataArrayHandle->obj_at_put(i, JNIHandles::resolve(element));
   }
   HotSpotMetaData::set_metadata(metadata_handle, metadataArrayHandle());
 
@@ -1519,6 +1521,48 @@
   }
 C2V_END
 
+C2V_VMENTRY(jint, isResolvedInvokeHandleInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
+  constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
+  ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index));
+  if (cp_cache_entry->is_resolved(Bytecodes::_invokehandle)) {
+    // MethodHandle.invoke* --> LambdaForm?
+    ResourceMark rm;
+
+    LinkInfo link_info(cp, index, CATCH);
+
+    Klass* resolved_klass = link_info.resolved_klass();
+
+    Symbol* name_sym = cp->name_ref_at(index);
+
+    vmassert(MethodHandles::is_method_handle_invoke_name(resolved_klass, name_sym), "!");
+    vmassert(MethodHandles::is_signature_polymorphic_name(resolved_klass, name_sym), "!");
+
+    methodHandle adapter_method(cp_cache_entry->f1_as_method());
+
+    methodHandle resolved_method(adapter_method);
+
+    // Can we treat it as a regular invokevirtual?
+    if (resolved_method->method_holder() == resolved_klass && resolved_method->name() == name_sym) {
+      vmassert(!resolved_method->is_static(),"!");
+      vmassert(MethodHandles::is_signature_polymorphic_method(resolved_method()),"!");
+      vmassert(!MethodHandles::is_signature_polymorphic_static(resolved_method->intrinsic_id()), "!");
+      vmassert(cp_cache_entry->appendix_if_resolved(cp) == NULL, "!");
+      vmassert(cp_cache_entry->method_type_if_resolved(cp) == NULL, "!");
+
+      methodHandle m(LinkResolver::linktime_resolve_virtual_method_or_null(link_info));
+      vmassert(m == resolved_method, "!!");
+      return -1;
+    }
+
+    return Bytecodes::_invokevirtual;
+  }
+  if (cp_cache_entry->is_resolved(Bytecodes::_invokedynamic)) {
+    return Bytecodes::_invokedynamic;
+  }
+  return -1;
+C2V_END
+
+
 C2V_VMENTRY(jobject, getSignaturePolymorphicHolders, (JNIEnv*, jobject))
   objArrayHandle holders = oopFactory::new_objArray_handle(SystemDictionary::String_klass(), 2, CHECK_NULL);
   Handle mh = java_lang_String::create_from_str("Ljava/lang/invoke/MethodHandle;", CHECK_NULL);
@@ -1795,6 +1839,7 @@
   {CC "resolveFieldInPool",                           CC "(" HS_CONSTANT_POOL "I" HS_RESOLVED_METHOD "B[I)" HS_RESOLVED_KLASS,              FN_PTR(resolveFieldInPool)},
   {CC "resolveInvokeDynamicInPool",                   CC "(" HS_CONSTANT_POOL "I)V",                                                        FN_PTR(resolveInvokeDynamicInPool)},
   {CC "resolveInvokeHandleInPool",                    CC "(" HS_CONSTANT_POOL "I)V",                                                        FN_PTR(resolveInvokeHandleInPool)},
+  {CC "isResolvedInvokeHandleInPool",                 CC "(" HS_CONSTANT_POOL "I)I",                                                        FN_PTR(isResolvedInvokeHandleInPool)},
   {CC "resolveMethod",                                CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD HS_RESOLVED_KLASS ")" HS_RESOLVED_METHOD, FN_PTR(resolveMethod)},
   {CC "getSignaturePolymorphicHolders",               CC "()[" STRING,                                                                      FN_PTR(getSignaturePolymorphicHolders)},
   {CC "getVtableIndexForInterfaceMethod",             CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD ")I",                                     FN_PTR(getVtableIndexForInterfaceMethod)},
--- a/src/hotspot/share/jvmci/jvmciCompilerToVM.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -24,7 +24,7 @@
 #ifndef SHARE_VM_JVMCI_JVMCI_COMPILER_TO_VM_HPP
 #define SHARE_VM_JVMCI_JVMCI_COMPILER_TO_VM_HPP
 
-#include "prims/jni.h"
+#include "jni.h"
 #include "runtime/javaCalls.hpp"
 #include "jvmci/jvmciJavaClasses.hpp"
 
--- a/src/hotspot/share/jvmci/jvmciJavaClasses.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/jvmci/jvmciJavaClasses.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -299,7 +299,7 @@
     typeArrayOop_field(HotSpotMetaData, relocBytes, "[B")                                                                                                      \
     typeArrayOop_field(HotSpotMetaData, exceptionBytes, "[B")                                                                                                  \
     typeArrayOop_field(HotSpotMetaData, oopMaps, "[B")                                                                                                         \
-    objArrayOop_field(HotSpotMetaData, metadata, "[Ljava/lang/String;")                                                                                        \
+    objArrayOop_field(HotSpotMetaData, metadata, "[Ljava/lang/Object;")                                                                                        \
   end_class                                                                                                                                                    \
   start_class(HotSpotConstantPool)                                                                                                                             \
     long_field(HotSpotConstantPool, metaspaceConstantPool)                                                                                                     \
--- a/src/hotspot/share/jvmci/vmStructs_compiler_runtime.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/jvmci/vmStructs_compiler_runtime.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -28,6 +28,7 @@
 #include "jvmci/compilerRuntime.hpp"
 
 #define VM_ADDRESSES_COMPILER_RUNTIME(declare_address, declare_preprocessor_address, declare_function) \
+  declare_function(CompilerRuntime::resolve_dynamic_invoke)                       \
   declare_function(CompilerRuntime::resolve_string_by_symbol)                     \
   declare_function(CompilerRuntime::resolve_klass_by_symbol)                      \
   declare_function(CompilerRuntime::resolve_method_by_symbol_and_load_counters)   \
--- a/src/hotspot/share/jvmci/vmStructs_jvmci.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/jvmci/vmStructs_jvmci.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -125,6 +125,7 @@
   nonstatic_field(ConstMethod,                 _code_size,                             u2)                                           \
   nonstatic_field(ConstMethod,                 _name_index,                            u2)                                           \
   nonstatic_field(ConstMethod,                 _signature_index,                       u2)                                           \
+  nonstatic_field(ConstMethod,                 _method_idnum,                          u2)                                           \
   nonstatic_field(ConstMethod,                 _max_stack,                             u2)                                           \
   nonstatic_field(ConstMethod,                 _max_locals,                            u2)                                           \
                                                                                                                                      \
@@ -157,6 +158,7 @@
   nonstatic_field(InstanceKlass,               _constants,                                    ConstantPool*)                         \
   nonstatic_field(InstanceKlass,               _source_file_name_index,                       u2)                                    \
   nonstatic_field(InstanceKlass,               _init_state,                                   u1)                                    \
+  nonstatic_field(InstanceKlass,               _misc_flags,                                   u2)                                    \
                                                                                                                                      \
   volatile_nonstatic_field(JavaFrameAnchor,    _last_Java_sp,                                 intptr_t*)                             \
   volatile_nonstatic_field(JavaFrameAnchor,    _last_Java_pc,                                 address)                               \
@@ -521,6 +523,7 @@
                                                                           \
   declare_constant(InstanceKlass::linked)                                 \
   declare_constant(InstanceKlass::fully_initialized)                      \
+  declare_constant(InstanceKlass::_misc_is_anonymous)                     \
                                                                           \
   declare_constant(JumpData::taken_off_set)                               \
   declare_constant(JumpData::displacement_off_set)                        \
--- a/src/hotspot/share/memory/metaspace.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/memory/metaspace.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1499,7 +1499,7 @@
 }
 
 size_t MetaspaceGC::capacity_until_GC() {
-  size_t value = (size_t)OrderAccess::load_ptr_acquire(&_capacity_until_GC);
+  size_t value = OrderAccess::load_acquire(&_capacity_until_GC);
   assert(value >= MetaspaceSize, "Not initialized properly?");
   return value;
 }
@@ -1507,16 +1507,16 @@
 bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC) {
   assert_is_aligned(v, Metaspace::commit_alignment());
 
-  size_t capacity_until_GC = (size_t) _capacity_until_GC;
-  size_t new_value = capacity_until_GC + v;
+  intptr_t capacity_until_GC = _capacity_until_GC;
+  intptr_t new_value = capacity_until_GC + v;
 
   if (new_value < capacity_until_GC) {
     // The addition wrapped around, set new_value to aligned max value.
     new_value = align_down(max_uintx, Metaspace::commit_alignment());
   }
 
-  intptr_t expected = (intptr_t) capacity_until_GC;
-  intptr_t actual = Atomic::cmpxchg_ptr((intptr_t) new_value, &_capacity_until_GC, expected);
+  intptr_t expected = _capacity_until_GC;
+  intptr_t actual = Atomic::cmpxchg(new_value, &_capacity_until_GC, expected);
 
   if (expected != actual) {
     return false;
@@ -1534,7 +1534,7 @@
 size_t MetaspaceGC::dec_capacity_until_GC(size_t v) {
   assert_is_aligned(v, Metaspace::commit_alignment());
 
-  return (size_t)Atomic::add_ptr(-(intptr_t)v, &_capacity_until_GC);
+  return (size_t)Atomic::sub((intptr_t)v, &_capacity_until_GC);
 }
 
 void MetaspaceGC::initialize() {
@@ -2398,7 +2398,7 @@
 
 void SpaceManager::inc_used_metrics(size_t words) {
   // Add to the per SpaceManager total
-  Atomic::add_ptr(words, &_allocated_blocks_words);
+  Atomic::add(words, &_allocated_blocks_words);
   // Add to the global total
   MetaspaceAux::inc_used(mdtype(), words);
 }
@@ -2753,8 +2753,7 @@
   // sweep which is a concurrent phase.  Protection by the expand_lock()
   // is not enough since allocation is on a per Metaspace basis
   // and protected by the Metaspace lock.
-  jlong minus_words = (jlong) - (jlong) words;
-  Atomic::add_ptr(minus_words, &_used_words[mdtype]);
+  Atomic::sub(words, &_used_words[mdtype]);
 }
 
 void MetaspaceAux::inc_used(Metaspace::MetadataType mdtype, size_t words) {
@@ -2762,7 +2761,7 @@
   // each piece of metadata.  Those allocations are
   // generally done concurrently by different application
   // threads so must be done atomically.
-  Atomic::add_ptr(words, &_used_words[mdtype]);
+  Atomic::add(words, &_used_words[mdtype]);
 }
 
 size_t MetaspaceAux::used_bytes_slow(Metaspace::MetadataType mdtype) {
@@ -3324,6 +3323,24 @@
 
   CompressedClassSpaceSize = align_down_bounded(CompressedClassSpaceSize, _reserve_alignment);
   set_compressed_class_space_size(CompressedClassSpaceSize);
+
+  // Initial virtual space size will be calculated at global_initialize()
+  size_t min_metaspace_sz =
+      VIRTUALSPACEMULTIPLIER * InitialBootClassLoaderMetaspaceSize;
+  if (UseCompressedClassPointers) {
+    if ((min_metaspace_sz + CompressedClassSpaceSize) >  MaxMetaspaceSize) {
+      if (min_metaspace_sz >= MaxMetaspaceSize) {
+        vm_exit_during_initialization("MaxMetaspaceSize is too small.");
+      } else {
+        FLAG_SET_ERGO(size_t, CompressedClassSpaceSize,
+                      MaxMetaspaceSize - min_metaspace_sz);
+      }
+    }
+  } else if (min_metaspace_sz >= MaxMetaspaceSize) {
+    FLAG_SET_ERGO(size_t, InitialBootClassLoaderMetaspaceSize,
+                  min_metaspace_sz);
+  }
+
 }
 
 void Metaspace::global_initialize() {
--- a/src/hotspot/share/memory/universe.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/memory/universe.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -84,6 +84,7 @@
 #include "utilities/preserveException.hpp"
 #if INCLUDE_ALL_GCS
 #include "gc/cms/cmsCollectorPolicy.hpp"
+#include "gc/cms/cmsHeap.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
 #include "gc/g1/g1CollectorPolicy.hpp"
 #include "gc/parallel/parallelScavengeHeap.hpp"
@@ -536,7 +537,7 @@
 
 oop Universe::swap_reference_pending_list(oop list) {
   assert_pll_locked(is_locked);
-  return (oop)Atomic::xchg_ptr(list, &_reference_pending_list);
+  return Atomic::xchg(list, &_reference_pending_list);
 }
 
 #undef assert_pll_locked
@@ -758,7 +759,7 @@
   } else if (UseG1GC) {
     return Universe::create_heap_with_policy<G1CollectedHeap, G1CollectorPolicy>();
   } else if (UseConcMarkSweepGC) {
-    return Universe::create_heap_with_policy<GenCollectedHeap, ConcurrentMarkSweepPolicy>();
+    return Universe::create_heap_with_policy<CMSHeap, ConcurrentMarkSweepPolicy>();
 #endif
   } else if (UseSerialGC) {
     return Universe::create_heap_with_policy<GenCollectedHeap, MarkSweepPolicy>();
--- a/src/hotspot/share/metaprogramming/integralConstant.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/metaprogramming/integralConstant.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -44,7 +44,7 @@
 // T is an integral type, and is the value_type.
 // v is an integral constant, and is the value.
 template<typename T, T v>
-struct IntegralConstant : AllStatic {
+struct IntegralConstant VALUE_OBJ_CLASS_SPEC {
   typedef T value_type;
   static const value_type value = v;
   typedef IntegralConstant<T, v> type;
--- a/src/hotspot/share/oops/arrayKlass.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/arrayKlass.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -29,11 +29,11 @@
 #include "oops/arrayKlass.hpp"
 
 inline Klass* ArrayKlass::higher_dimension_acquire() const {
-  return (Klass*) OrderAccess::load_ptr_acquire(&_higher_dimension);
+  return OrderAccess::load_acquire(&_higher_dimension);
 }
 
 inline void ArrayKlass::release_set_higher_dimension(Klass* k) {
-  OrderAccess::release_store_ptr(&_higher_dimension, k);
+  OrderAccess::release_store(&_higher_dimension, k);
 }
 
 #endif // SHARE_VM_OOPS_ARRAYKLASS_INLINE_HPP
--- a/src/hotspot/share/oops/constantPool.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/constantPool.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -226,7 +226,7 @@
   symbol_at_put(name_index, name);
   name->increment_refcount();
   Klass** adr = resolved_klasses()->adr_at(resolved_klass_index);
-  OrderAccess::release_store_ptr((Klass* volatile *)adr, k);
+  OrderAccess::release_store(adr, k);
 
   // The interpreter assumes when the tag is stored, the klass is resolved
   // and the Klass* non-NULL, so we need hardware store ordering here.
@@ -243,7 +243,7 @@
   CPKlassSlot kslot = klass_slot_at(class_index);
   int resolved_klass_index = kslot.resolved_klass_index();
   Klass** adr = resolved_klasses()->adr_at(resolved_klass_index);
-  OrderAccess::release_store_ptr((Klass* volatile *)adr, k);
+  OrderAccess::release_store(adr, k);
 
   // The interpreter assumes when the tag is stored, the klass is resolved
   // and the Klass* non-NULL, so we need hardware store ordering here.
@@ -511,7 +511,7 @@
     trace_class_resolution(this_cp, k);
   }
   Klass** adr = this_cp->resolved_klasses()->adr_at(resolved_klass_index);
-  OrderAccess::release_store_ptr((Klass* volatile *)adr, k);
+  OrderAccess::release_store(adr, k);
   // The interpreter assumes when the tag is stored, the klass is resolved
   // and the Klass* stored in _resolved_klasses is non-NULL, so we need
   // hardware store ordering here.
--- a/src/hotspot/share/oops/constantPool.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/constantPool.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -145,7 +145,7 @@
     assert(is_within_bounds(which), "index out of bounds");
     assert(!tag_at(which).is_unresolved_klass() && !tag_at(which).is_unresolved_klass_in_error(), "Corrupted constant pool");
     // Uses volatile because the klass slot changes without a lock.
-    volatile intptr_t adr = (intptr_t)OrderAccess::load_ptr_acquire(obj_at_addr_raw(which));
+    intptr_t adr = OrderAccess::load_acquire(obj_at_addr_raw(which));
     assert(adr != 0 || which == 0, "cp entry for klass should not be zero");
     return CPSlot(adr);
   }
@@ -407,7 +407,7 @@
     assert(tag_at(kslot.name_index()).is_symbol(), "sanity");
 
     Klass** adr = resolved_klasses()->adr_at(kslot.resolved_klass_index());
-    return (Klass*)OrderAccess::load_ptr_acquire(adr);
+    return OrderAccess::load_acquire(adr);
   }
 
   // RedefineClasses() API support:
--- a/src/hotspot/share/oops/cpCache.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/cpCache.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -91,7 +91,7 @@
   assert(c == 0 || c == code || code == 0, "update must be consistent");
 #endif
   // Need to flush pending stores here before bytecode is written.
-  OrderAccess::release_store_ptr(&_indices, _indices | ((u_char)code << bytecode_1_shift));
+  OrderAccess::release_store(&_indices, _indices | ((u_char)code << bytecode_1_shift));
 }
 
 void ConstantPoolCacheEntry::set_bytecode_2(Bytecodes::Code code) {
@@ -101,19 +101,13 @@
   assert(c == 0 || c == code || code == 0, "update must be consistent");
 #endif
   // Need to flush pending stores here before bytecode is written.
-  OrderAccess::release_store_ptr(&_indices, _indices | ((u_char)code << bytecode_2_shift));
+  OrderAccess::release_store(&_indices, _indices | ((u_char)code << bytecode_2_shift));
 }
 
 // Sets f1, ordering with previous writes.
 void ConstantPoolCacheEntry::release_set_f1(Metadata* f1) {
   assert(f1 != NULL, "");
-  OrderAccess::release_store_ptr((HeapWord*) &_f1, f1);
-}
-
-// Sets flags, but only if the value was previously zero.
-bool ConstantPoolCacheEntry::init_flags_atomic(intptr_t flags) {
-  intptr_t result = Atomic::cmpxchg_ptr(flags, &_flags, 0);
-  return (result == 0);
+  OrderAccess::release_store(&_f1, f1);
 }
 
 // Note that concurrent update of both bytecodes can leave one of them
@@ -154,7 +148,8 @@
   // bother trying to update it once it's nonzero but always make
   // sure that the final parameter size agrees with what was passed.
   if (_flags == 0) {
-    Atomic::cmpxchg_ptr((value & parameter_size_mask), &_flags, 0);
+    intx newflags = (value & parameter_size_mask);
+    Atomic::cmpxchg(newflags, &_flags, (intx)0);
   }
   guarantee(parameter_size() == value,
             "size must not change: parameter_size=%d, value=%d", parameter_size(), value);
--- a/src/hotspot/share/oops/cpCache.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/cpCache.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -136,7 +136,7 @@
 
  private:
   volatile intx     _indices;  // constant pool index & rewrite bytecodes
-  volatile Metadata*   _f1;       // entry specific metadata field
+  Metadata* volatile   _f1;       // entry specific metadata field
   volatile intx        _f2;       // entry specific int/metadata field
   volatile intx     _flags;    // flags
 
@@ -144,7 +144,7 @@
   void set_bytecode_1(Bytecodes::Code code);
   void set_bytecode_2(Bytecodes::Code code);
   void set_f1(Metadata* f1) {
-    Metadata* existing_f1 = (Metadata*)_f1; // read once
+    Metadata* existing_f1 = _f1; // read once
     assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
     _f1 = f1;
   }
@@ -160,7 +160,6 @@
   }
   int make_flags(TosState state, int option_bits, int field_index_or_method_params);
   void set_flags(intx flags)                     { _flags = flags; }
-  bool init_flags_atomic(intx flags);
   void set_field_flags(TosState field_type, int option_bits, int field_index) {
     assert((field_index & field_index_mask) == field_index, "field_index in range");
     set_flags(make_flags(field_type, option_bits | (1 << is_field_entry_shift), field_index));
@@ -169,10 +168,6 @@
     assert((method_params & parameter_size_mask) == method_params, "method_params in range");
     set_flags(make_flags(return_type, option_bits, method_params));
   }
-  bool init_method_flags_atomic(TosState return_type, int option_bits, int method_params) {
-    assert((method_params & parameter_size_mask) == method_params, "method_params in range");
-    return init_flags_atomic(make_flags(return_type, option_bits, method_params));
-  }
 
  public:
   // specific bit definitions for the flags field:
@@ -332,11 +327,11 @@
 
   // Accessors
   int indices() const                            { return _indices; }
-  int indices_ord() const                        { return (intx)OrderAccess::load_ptr_acquire(&_indices); }
+  int indices_ord() const                        { return OrderAccess::load_acquire(&_indices); }
   int constant_pool_index() const                { return (indices() & cp_index_mask); }
   Bytecodes::Code bytecode_1() const             { return Bytecodes::cast((indices_ord() >> bytecode_1_shift) & bytecode_1_mask); }
   Bytecodes::Code bytecode_2() const             { return Bytecodes::cast((indices_ord() >> bytecode_2_shift) & bytecode_2_mask); }
-  Metadata* f1_ord() const                       { return (Metadata *)OrderAccess::load_ptr_acquire(&_f1); }
+  Metadata* f1_ord() const                       { return (Metadata *)OrderAccess::load_acquire(&_f1); }
   Method*   f1_as_method() const                 { Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_method(), ""); return (Method*)f1; }
   Klass*    f1_as_klass() const                  { Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_klass(), ""); return (Klass*)f1; }
   // Use the accessor f1() to acquire _f1's value. This is needed for
--- a/src/hotspot/share/oops/instanceKlass.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -151,7 +151,7 @@
                                        nonstatic_oop_map_size(parser.total_oop_map_count()),
                                        parser.is_interface(),
                                        parser.is_anonymous(),
-                                       should_store_fingerprint());
+                                       should_store_fingerprint(parser.is_anonymous()));
 
   const Symbol* const class_name = parser.class_name();
   assert(class_name != NULL, "invariant");
@@ -1109,16 +1109,15 @@
 void InstanceKlass::mask_for(const methodHandle& method, int bci,
   InterpreterOopMap* entry_for) {
   // Lazily create the _oop_map_cache at first request
-  // Lock-free access requires load_ptr_acquire.
-  OopMapCache* oop_map_cache =
-      static_cast<OopMapCache*>(OrderAccess::load_ptr_acquire(&_oop_map_cache));
+  // Lock-free access requires load_acquire.
+  OopMapCache* oop_map_cache = OrderAccess::load_acquire(&_oop_map_cache);
   if (oop_map_cache == NULL) {
     MutexLocker x(OopMapCacheAlloc_lock);
     // Check if _oop_map_cache was allocated while we were waiting for this lock
     if ((oop_map_cache = _oop_map_cache) == NULL) {
       oop_map_cache = new OopMapCache();
       // Ensure _oop_map_cache is stable, since it is examined without a lock
-      OrderAccess::release_store_ptr(&_oop_map_cache, oop_map_cache);
+      OrderAccess::release_store(&_oop_map_cache, oop_map_cache);
     }
   }
   // _oop_map_cache is constant after init; lookup below does its own locking.
@@ -1672,7 +1671,7 @@
   // transitions from NULL to non-NULL which is safe because we use
   // release_set_methods_jmethod_ids() to advertise the new cache.
   // A partially constructed cache should never be seen by a racing
-  // thread. We also use release_store_ptr() to save a new jmethodID
+  // thread. We also use release_store() to save a new jmethodID
   // in the cache so a partially constructed jmethodID should never be
   // seen either. Cache reads of existing jmethodIDs proceed without a
   // lock, but cache writes of a new jmethodID requires uniqueness and
@@ -1831,7 +1830,7 @@
     // The jmethodID cache can be read while unlocked so we have to
     // make sure the new jmethodID is complete before installing it
     // in the cache.
-    OrderAccess::release_store_ptr(&jmeths[idnum+1], id);
+    OrderAccess::release_store(&jmeths[idnum+1], id);
   } else {
     *to_dealloc_id_p = new_id; // save new id for later delete
   }
@@ -1958,7 +1957,7 @@
   return true;
 }
 
-bool InstanceKlass::should_store_fingerprint() {
+bool InstanceKlass::should_store_fingerprint(bool is_anonymous) {
 #if INCLUDE_AOT
   // We store the fingerprint into the InstanceKlass only in the following 2 cases:
   if (CalculateClassFingerprint) {
@@ -1969,6 +1968,10 @@
     // (2) We are running -Xshare:dump to create a shared archive
     return true;
   }
+  if (UseAOT && is_anonymous) {
+    // (3) We are using AOT code from a shared library and see an anonymous class
+    return true;
+  }
 #endif
 
   // In all other cases we might set the _misc_has_passed_fingerprint_check bit,
--- a/src/hotspot/share/oops/instanceKlass.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/instanceKlass.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -731,7 +731,8 @@
   }
   bool supers_have_passed_fingerprint_checks();
 
-  static bool should_store_fingerprint();
+  static bool should_store_fingerprint(bool is_anonymous);
+  bool should_store_fingerprint() const { return should_store_fingerprint(is_anonymous()); }
   bool has_stored_fingerprint() const;
   uint64_t get_stored_fingerprint() const;
   void store_fingerprint(uint64_t fingerprint);
--- a/src/hotspot/share/oops/instanceKlass.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/instanceKlass.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -35,19 +35,19 @@
 #include "utilities/macros.hpp"
 
 inline Klass* InstanceKlass::array_klasses_acquire() const {
-  return (Klass*) OrderAccess::load_ptr_acquire(&_array_klasses);
+  return OrderAccess::load_acquire(&_array_klasses);
 }
 
 inline void InstanceKlass::release_set_array_klasses(Klass* k) {
-  OrderAccess::release_store_ptr(&_array_klasses, k);
+  OrderAccess::release_store(&_array_klasses, k);
 }
 
 inline jmethodID* InstanceKlass::methods_jmethod_ids_acquire() const {
-  return (jmethodID*)OrderAccess::load_ptr_acquire(&_methods_jmethod_ids);
+  return OrderAccess::load_acquire(&_methods_jmethod_ids);
 }
 
 inline void InstanceKlass::release_set_methods_jmethod_ids(jmethodID* jmeths) {
-  OrderAccess::release_store_ptr(&_methods_jmethod_ids, jmeths);
+  OrderAccess::release_store(&_methods_jmethod_ids, jmeths);
 }
 
 // The iteration over the oops in objects is a hot path in the GC code.
--- a/src/hotspot/share/oops/method.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/method.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -444,6 +444,11 @@
   return mh->method_counters();
 }
 
+bool Method::init_method_counters(MethodCounters* counters) {
+  // Try to install a pointer to MethodCounters, return true on success.
+  return Atomic::cmpxchg(counters, &_method_counters, (MethodCounters*)NULL) == NULL;
+}
+
 void Method::cleanup_inline_caches() {
   // The current system doesn't use inline caches in the interpreter
   // => nothing to do (keep this method around for future use)
@@ -1108,8 +1113,8 @@
   }
 }
 
-volatile address Method::from_compiled_entry_no_trampoline() const {
-  nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code);
+address Method::from_compiled_entry_no_trampoline() const {
+  CompiledMethod *code = OrderAccess::load_acquire(&_code);
   if (code) {
     return code->verified_entry_point();
   } else {
@@ -1135,7 +1140,7 @@
 // Not inline to avoid circular ref.
 bool Method::check_code() const {
   // cached in a register or local.  There's a race on the value of the field.
-  CompiledMethod *code = (CompiledMethod *)OrderAccess::load_ptr_acquire(&_code);
+  CompiledMethod *code = OrderAccess::load_acquire(&_code);
   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
 }
 
--- a/src/hotspot/share/oops/method.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/method.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -136,9 +136,9 @@
 
 
   static address make_adapters(const methodHandle& mh, TRAPS);
-  volatile address from_compiled_entry() const   { return (address)OrderAccess::load_ptr_acquire(&_from_compiled_entry); }
-  volatile address from_compiled_entry_no_trampoline() const;
-  volatile address from_interpreted_entry() const{ return (address)OrderAccess::load_ptr_acquire(&_from_interpreted_entry); }
+  address from_compiled_entry() const   { return OrderAccess::load_acquire(&_from_compiled_entry); }
+  address from_compiled_entry_no_trampoline() const;
+  address from_interpreted_entry() const{ return OrderAccess::load_acquire(&_from_interpreted_entry); }
 
   // access flag
   AccessFlags access_flags() const               { return _access_flags;  }
@@ -337,7 +337,7 @@
     // The store into method must be released. On platforms without
     // total store order (TSO) the reference may become visible before
     // the initialization of data otherwise.
-    OrderAccess::release_store_ptr((volatile void *)&_method_data, data);
+    OrderAccess::release_store(&_method_data, data);
   }
 
   MethodCounters* method_counters() const {
@@ -348,10 +348,7 @@
     _method_counters = NULL;
   }
 
-  bool init_method_counters(MethodCounters* counters) {
-    // Try to install a pointer to MethodCounters, return true on success.
-    return Atomic::cmpxchg_ptr(counters, (volatile void*)&_method_counters, NULL) == NULL;
-  }
+  bool init_method_counters(MethodCounters* counters);
 
 #ifdef TIERED
   // We are reusing interpreter_invocation_count as a holder for the previous event count!
@@ -452,7 +449,7 @@
   // nmethod/verified compiler entry
   address verified_code_entry();
   bool check_code() const;      // Not inline to avoid circular ref
-  CompiledMethod* volatile code() const                 { assert( check_code(), "" ); return (CompiledMethod *)OrderAccess::load_ptr_acquire(&_code); }
+  CompiledMethod* volatile code() const                 { assert( check_code(), "" ); return OrderAccess::load_acquire(&_code); }
   void clear_code(bool acquire_lock = true);    // Clear out any compiled code
   static void set_code(const methodHandle& mh, CompiledMethod* code);
   void set_adapter_entry(AdapterHandlerEntry* adapter) {
--- a/src/hotspot/share/oops/methodData.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/methodData.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -202,7 +202,7 @@
     _cells[index] = value;
   }
   void release_set_cell_at(int index, intptr_t value) {
-    OrderAccess::release_store_ptr(&_cells[index], value);
+    OrderAccess::release_store(&_cells[index], value);
   }
   intptr_t cell_at(int index) const {
     return _cells[index];
--- a/src/hotspot/share/oops/objArrayKlass.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/objArrayKlass.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -226,8 +226,6 @@
   // For performance reasons, we assume we are that the write barrier we
   // are using has optimized modes for arrays of references.  At least one
   // of the asserts below will fail if this is not the case.
-  assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
-  assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");
 
   if (s == d) {
     // since source and destination are equal we do not need conversion checks.
--- a/src/hotspot/share/oops/oop.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/oops/oop.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -66,7 +66,7 @@
 
 template <class T> void oop_store(volatile T* p, oop v) {
   update_barrier_set_pre((T*)p, v);   // cast away volatile
-  // Used by release_obj_field_put, so use release_store_ptr.
+  // Used by release_obj_field_put, so use release_store.
   oopDesc::release_encode_store_heap_oop(p, v);
   // When using CMS we must mark the card corresponding to p as dirty
   // with release sematics to prevent that CMS sees the dirty card but
@@ -90,7 +90,7 @@
 // We need a separate file to avoid circular references
 
 void oopDesc::release_set_mark(markOop m) {
-  OrderAccess::release_store_ptr(&_mark, m);
+  OrderAccess::release_store(&_mark, m);
 }
 
 markOop oopDesc::cas_set_mark(markOop new_mark, markOop old_mark) {
@@ -124,7 +124,7 @@
     volatile narrowKlass* xaddr = const_cast<volatile narrowKlass*>(addr);
     return Klass::decode_klass(OrderAccess::load_acquire(xaddr));
   } else {
-    return (Klass*)OrderAccess::load_ptr_acquire(&_metadata._klass);
+    return OrderAccess::load_acquire(&_metadata._klass);
   }
 }
 
@@ -161,7 +161,7 @@
     OrderAccess::release_store(compressed_klass_addr(),
                                Klass::encode_klass_not_null(k));
   } else {
-    OrderAccess::release_store_ptr(klass_addr(), k);
+    OrderAccess::release_store(klass_addr(), k);
   }
 }
 
@@ -361,7 +361,7 @@
 
 // Store heap oop as is for volatile fields.
 void oopDesc::release_store_heap_oop(volatile oop* p, oop v) {
-  OrderAccess::release_store_ptr(p, v);
+  OrderAccess::release_store(p, v);
 }
 void oopDesc::release_store_heap_oop(volatile narrowOop* p, narrowOop v) {
   OrderAccess::release_store(p, v);
@@ -372,11 +372,11 @@
   OrderAccess::release_store(p, encode_heap_oop_not_null(v));
 }
 void oopDesc::release_encode_store_heap_oop_not_null(volatile oop* p, oop v) {
-  OrderAccess::release_store_ptr(p, v);
+  OrderAccess::release_store(p, v);
 }
 
 void oopDesc::release_encode_store_heap_oop(volatile oop* p, oop v) {
-  OrderAccess::release_store_ptr(p, v);
+  OrderAccess::release_store(p, v);
 }
 void oopDesc::release_encode_store_heap_oop(volatile narrowOop* p, oop v) {
   OrderAccess::release_store(p, encode_heap_oop(v));
@@ -388,11 +388,11 @@
   if (UseCompressedOops) {
     // encode exchange value from oop to T
     narrowOop val = encode_heap_oop(exchange_value);
-    narrowOop old = (narrowOop)Atomic::xchg(val, (narrowOop*)dest);
+    narrowOop old = Atomic::xchg(val, (narrowOop*)dest);
     // decode old from T to oop
     return decode_heap_oop(old);
   } else {
-    return (oop)Atomic::xchg_ptr(exchange_value, (oop*)dest);
+    return Atomic::xchg(exchange_value, (oop*)dest);
   }
 }
 
@@ -447,11 +447,11 @@
 void oopDesc::metadata_field_put(int offset, Metadata* value) { *metadata_field_addr(offset) = value;  }
 
 Metadata* oopDesc::metadata_field_acquire(int offset) const   {
-  return (Metadata*)OrderAccess::load_ptr_acquire(metadata_field_addr(offset));
+  return OrderAccess::load_acquire(metadata_field_addr(offset));
 }
 
 void oopDesc::release_metadata_field_put(int offset, Metadata* value) {
-  OrderAccess::release_store_ptr(metadata_field_addr(offset), value);
+  OrderAccess::release_store(metadata_field_addr(offset), value);
 }
 
 jbyte oopDesc::byte_field(int offset) const                   { return (jbyte) *byte_field_addr(offset);    }
@@ -485,8 +485,8 @@
   return UseCompressedOops ?
              decode_heap_oop((narrowOop)
                OrderAccess::load_acquire(obj_field_addr<narrowOop>(offset)))
-           : decode_heap_oop((oop)
-               OrderAccess::load_ptr_acquire(obj_field_addr<oop>(offset)));
+           : decode_heap_oop(
+                OrderAccess::load_acquire(obj_field_addr<oop>(offset)));
 }
 void oopDesc::release_obj_field_put(int offset, oop value) {
   UseCompressedOops ?
@@ -518,8 +518,8 @@
 jdouble oopDesc::double_field_acquire(int offset) const               { return OrderAccess::load_acquire(double_field_addr(offset));     }
 void oopDesc::release_double_field_put(int offset, jdouble contents)  { OrderAccess::release_store(double_field_addr(offset), contents); }
 
-address oopDesc::address_field_acquire(int offset) const              { return (address) OrderAccess::load_ptr_acquire(address_field_addr(offset)); }
-void oopDesc::release_address_field_put(int offset, address contents) { OrderAccess::release_store_ptr(address_field_addr(offset), contents); }
+address oopDesc::address_field_acquire(int offset) const              { return OrderAccess::load_acquire(address_field_addr(offset)); }
+void oopDesc::release_address_field_put(int offset, address contents) { OrderAccess::release_store(address_field_addr(offset), contents); }
 
 bool oopDesc::is_locked() const {
   return mark()->is_locked();
@@ -539,7 +539,7 @@
 }
 
 bool oopDesc::is_scavengable() const {
-  return Universe::heap()->is_scavengable(this);
+  return Universe::heap()->is_scavengable(oop(const_cast<oopDesc*>(this)));
 }
 
 // Used by scavengers
--- a/src/hotspot/share/opto/c2_globals.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/opto/c2_globals.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -192,7 +192,7 @@
           "of rounds of unroll,optimize,..")                                \
           range(0, max_jint)                                                \
                                                                             \
-  product(bool, UseSubwordForMaxVector, false,                              \
+  product(bool, UseSubwordForMaxVector, true,                               \
           "Use Subword Analysis to set maximum vector size")                \
                                                                             \
   develop(intx, UnrollLimitForProfileCheck, 1,                              \
--- a/src/hotspot/share/opto/loopopts.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/opto/loopopts.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -826,45 +826,26 @@
             }
           }
           if (mem_ok) {
-            // Move the Store out of the loop creating clones along
-            // all paths out of the loop that observe the stored value
+            // Move the store out of the loop if the LCA of all
+            // users (except for the phi) is outside the loop.
+            Node* hook = new Node(1);
             _igvn.rehash_node_delayed(phi);
-            int count = phi->replace_edge(n, n->in(MemNode::Memory));
+            int count = phi->replace_edge(n, hook);
             assert(count > 0, "inconsistent phi");
-            for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
-              Node* u = n->fast_out(i);
-              Node* c = get_ctrl(u);
 
-              if (u->is_Phi()) {
-                c = u->in(0)->in(u->find_edge(n));
-              }
-              IdealLoopTree *u_loop = get_loop(c);
-              assert (!n_loop->is_member(u_loop), "only the phi should have been a use in the loop");
-              while(true) {
-                Node* next_c = find_non_split_ctrl(idom(c));
-                if (n_loop->is_member(get_loop(next_c))) {
-                  break;
-                }
-                c = next_c;
-              }
-
-              Node* st = n->clone();
-              st->set_req(0, c);
-              _igvn.register_new_node_with_optimizer(st);
-
-              set_ctrl(st, c);
-              IdealLoopTree* new_loop = get_loop(c);
-              assert(new_loop != n_loop, "should be moved out of loop");
-              if (new_loop->_child == NULL) new_loop->_body.push(st);
-
-              _igvn.replace_input_of(u, u->find_edge(n), st);
-              --imax;
-              --i;
+            // Compute latest point this store can go
+            Node* lca = get_late_ctrl(n, get_ctrl(n));
+            if (n_loop->is_member(get_loop(lca))) {
+              // LCA is in the loop - bail out
+              _igvn.replace_node(hook, n);
+              return;
             }
 
+            // Move store out of the loop
+            _igvn.replace_node(hook, n->in(MemNode::Memory));
+            _igvn.replace_input_of(n, 0, lca);
+            set_ctrl_and_loop(n, lca);
 
-            assert(n->outcnt() == 0, "all uses should be gone");
-            _igvn.replace_input_of(n, MemNode::Memory, C->top());
             // Disconnect the phi now. An empty phi can confuse other
             // optimizations in this pass of loop opts..
             if (phi->in(LoopNode::LoopBackControl) == phi) {
--- a/src/hotspot/share/opto/runtime.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/opto/runtime.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1658,7 +1658,7 @@
     c->set_next(NULL);
     head = _named_counters;
     c->set_next(head);
-  } while (Atomic::cmpxchg_ptr(c, &_named_counters, head) != head);
+  } while (Atomic::cmpxchg(c, &_named_counters, head) != head);
   return c;
 }
 
--- a/src/hotspot/share/precompiled/precompiled.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/precompiled/precompiled.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -26,6 +26,7 @@
 // or if the user passes --disable-precompiled-headers to configure.
 
 #ifndef DONT_USE_PRECOMPILED_HEADER
+# include "jni.h"
 # include "asm/assembler.hpp"
 # include "asm/assembler.inline.hpp"
 # include "asm/codeBuffer.hpp"
@@ -71,7 +72,6 @@
 # include "code/debugInfoRec.hpp"
 # include "code/dependencies.hpp"
 # include "code/exceptionHandlerTable.hpp"
-# include "code/jvmticmlr.h"
 # include "code/location.hpp"
 # include "code/nativeInst.hpp"
 # include "code/nmethod.hpp"
@@ -160,7 +160,6 @@
 # include "oops/symbol.hpp"
 # include "oops/typeArrayKlass.hpp"
 # include "oops/typeArrayOop.hpp"
-# include "prims/jni.h"
 # include "prims/jvm.h"
 # include "prims/jvmtiExport.hpp"
 # include "prims/methodHandles.hpp"
--- a/src/hotspot/share/prims/jni.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/jni.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -24,6 +24,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jni.h"
 #include "ci/ciReplay.hpp"
 #include "classfile/altHashing.hpp"
 #include "classfile/classFileStream.hpp"
@@ -51,7 +52,6 @@
 #include "oops/symbol.hpp"
 #include "oops/typeArrayKlass.hpp"
 #include "oops/typeArrayOop.hpp"
-#include "prims/jni.h"
 #include "prims/jniCheck.hpp"
 #include "prims/jniExport.hpp"
 #include "prims/jniFastGetField.hpp"
@@ -396,10 +396,11 @@
   }
 
   //%note jni_3
-  Handle loader;
   Handle protection_domain;
   // Find calling class
   Klass* k = thread->security_get_caller_class(0);
+  // default to the system loader when no context
+  Handle loader(THREAD, SystemDictionary::java_system_loader());
   if (k != NULL) {
     // Special handling to make sure JNI_OnLoad and JNI_OnUnload are executed
     // in the correct class context.
@@ -424,11 +425,6 @@
     }
   }
 
-  if (loader.is_null()) {
-    // No context and use the system class loader
-    loader = Handle(THREAD, SystemDictionary::java_system_loader());
-  }
-
   TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL);
   result = find_class_from_class_loader(env, sym, true, loader,
                                         protection_domain, true, thread);
@@ -3777,7 +3773,7 @@
   intptr_t *a = (intptr_t *) jni_functions();
   intptr_t *b = (intptr_t *) new_jni_NativeInterface;
   for (uint i=0; i <  sizeof(struct JNINativeInterface_)/sizeof(void *); i++) {
-    Atomic::store_ptr(*b++, a++);
+    Atomic::store(*b++, a++);
   }
 }
 
@@ -3898,11 +3894,11 @@
 #if defined(ZERO) && defined(ASSERT)
   {
     jint a = 0xcafebabe;
-    jint b = Atomic::xchg(0xdeadbeef, &a);
+    jint b = Atomic::xchg((jint) 0xdeadbeef, &a);
     void *c = &a;
-    void *d = Atomic::xchg_ptr(&b, &c);
+    void *d = Atomic::xchg(&b, &c);
     assert(a == (jint) 0xdeadbeef && b == (jint) 0xcafebabe, "Atomic::xchg() works");
-    assert(c == &b && d == &a, "Atomic::xchg_ptr() works");
+    assert(c == &b && d == &a, "Atomic::xchg() works");
   }
 #endif // ZERO && ASSERT
 
--- a/src/hotspot/share/prims/jni.h	Sat Oct 21 07:00:23 2017 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1973 +0,0 @@
-/*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * We used part of Netscape's Java Runtime Interface (JRI) as the starting
- * point of our design and implementation.
- */
-
-/******************************************************************************
- * Java Runtime Interface
- * Copyright (c) 1996 Netscape Communications Corporation. All rights reserved.
- *****************************************************************************/
-
-#ifndef _JAVASOFT_JNI_H_
-#define _JAVASOFT_JNI_H_
-
-#include <stdio.h>
-#include <stdarg.h>
-
-/* jni_md.h contains the machine-dependent typedefs for jbyte, jint
-   and jlong */
-
-#include "jni_md.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * JNI Types
- */
-
-#ifndef JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H
-
-typedef unsigned char   jboolean;
-typedef unsigned short  jchar;
-typedef short           jshort;
-typedef float           jfloat;
-typedef double          jdouble;
-
-typedef jint            jsize;
-
-#ifdef __cplusplus
-
-class _jobject {};
-class _jclass : public _jobject {};
-class _jthrowable : public _jobject {};
-class _jstring : public _jobject {};
-class _jarray : public _jobject {};
-class _jbooleanArray : public _jarray {};
-class _jbyteArray : public _jarray {};
-class _jcharArray : public _jarray {};
-class _jshortArray : public _jarray {};
-class _jintArray : public _jarray {};
-class _jlongArray : public _jarray {};
-class _jfloatArray : public _jarray {};
-class _jdoubleArray : public _jarray {};
-class _jobjectArray : public _jarray {};
-
-typedef _jobject *jobject;
-typedef _jclass *jclass;
-typedef _jthrowable *jthrowable;
-typedef _jstring *jstring;
-typedef _jarray *jarray;
-typedef _jbooleanArray *jbooleanArray;
-typedef _jbyteArray *jbyteArray;
-typedef _jcharArray *jcharArray;
-typedef _jshortArray *jshortArray;
-typedef _jintArray *jintArray;
-typedef _jlongArray *jlongArray;
-typedef _jfloatArray *jfloatArray;
-typedef _jdoubleArray *jdoubleArray;
-typedef _jobjectArray *jobjectArray;
-
-#else
-
-struct _jobject;
-
-typedef struct _jobject *jobject;
-typedef jobject jclass;
-typedef jobject jthrowable;
-typedef jobject jstring;
-typedef jobject jarray;
-typedef jarray jbooleanArray;
-typedef jarray jbyteArray;
-typedef jarray jcharArray;
-typedef jarray jshortArray;
-typedef jarray jintArray;
-typedef jarray jlongArray;
-typedef jarray jfloatArray;
-typedef jarray jdoubleArray;
-typedef jarray jobjectArray;
-
-#endif
-
-typedef jobject jweak;
-
-typedef union jvalue {
-    jboolean z;
-    jbyte    b;
-    jchar    c;
-    jshort   s;
-    jint     i;
-    jlong    j;
-    jfloat   f;
-    jdouble  d;
-    jobject  l;
-} jvalue;
-
-struct _jfieldID;
-typedef struct _jfieldID *jfieldID;
-
-struct _jmethodID;
-typedef struct _jmethodID *jmethodID;
-
-/* Return values from jobjectRefType */
-typedef enum _jobjectType {
-     JNIInvalidRefType    = 0,
-     JNILocalRefType      = 1,
-     JNIGlobalRefType     = 2,
-     JNIWeakGlobalRefType = 3
-} jobjectRefType;
-
-
-#endif /* JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H */
-
-/*
- * jboolean constants
- */
-
-#define JNI_FALSE 0
-#define JNI_TRUE 1
-
-/*
- * possible return values for JNI functions.
- */
-
-#define JNI_OK           0                 /* success */
-#define JNI_ERR          (-1)              /* unknown error */
-#define JNI_EDETACHED    (-2)              /* thread detached from the VM */
-#define JNI_EVERSION     (-3)              /* JNI version error */
-#define JNI_ENOMEM       (-4)              /* not enough memory */
-#define JNI_EEXIST       (-5)              /* VM already created */
-#define JNI_EINVAL       (-6)              /* invalid arguments */
-
-/*
- * used in ReleaseScalarArrayElements
- */
-
-#define JNI_COMMIT 1
-#define JNI_ABORT 2
-
-/*
- * used in RegisterNatives to describe native method name, signature,
- * and function pointer.
- */
-
-typedef struct {
-    char *name;
-    char *signature;
-    void *fnPtr;
-} JNINativeMethod;
-
-/*
- * JNI Native Method Interface.
- */
-
-struct JNINativeInterface_;
-
-struct JNIEnv_;
-
-#ifdef __cplusplus
-typedef JNIEnv_ JNIEnv;
-#else
-typedef const struct JNINativeInterface_ *JNIEnv;
-#endif
-
-/*
- * JNI Invocation Interface.
- */
-
-struct JNIInvokeInterface_;
-
-struct JavaVM_;
-
-#ifdef __cplusplus
-typedef JavaVM_ JavaVM;
-#else
-typedef const struct JNIInvokeInterface_ *JavaVM;
-#endif
-
-struct JNINativeInterface_ {
-    void *reserved0;
-    void *reserved1;
-    void *reserved2;
-
-    void *reserved3;
-    jint (JNICALL *GetVersion)(JNIEnv *env);
-
-    jclass (JNICALL *DefineClass)
-      (JNIEnv *env, const char *name, jobject loader, const jbyte *buf,
-       jsize len);
-    jclass (JNICALL *FindClass)
-      (JNIEnv *env, const char *name);
-
-    jmethodID (JNICALL *FromReflectedMethod)
-      (JNIEnv *env, jobject method);
-    jfieldID (JNICALL *FromReflectedField)
-      (JNIEnv *env, jobject field);
-
-    jobject (JNICALL *ToReflectedMethod)
-      (JNIEnv *env, jclass cls, jmethodID methodID, jboolean isStatic);
-
-    jclass (JNICALL *GetSuperclass)
-      (JNIEnv *env, jclass sub);
-    jboolean (JNICALL *IsAssignableFrom)
-      (JNIEnv *env, jclass sub, jclass sup);
-
-    jobject (JNICALL *ToReflectedField)
-      (JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic);
-
-    jint (JNICALL *Throw)
-      (JNIEnv *env, jthrowable obj);
-    jint (JNICALL *ThrowNew)
-      (JNIEnv *env, jclass clazz, const char *msg);
-    jthrowable (JNICALL *ExceptionOccurred)
-      (JNIEnv *env);
-    void (JNICALL *ExceptionDescribe)
-      (JNIEnv *env);
-    void (JNICALL *ExceptionClear)
-      (JNIEnv *env);
-    void (JNICALL *FatalError)
-      (JNIEnv *env, const char *msg);
-
-    jint (JNICALL *PushLocalFrame)
-      (JNIEnv *env, jint capacity);
-    jobject (JNICALL *PopLocalFrame)
-      (JNIEnv *env, jobject result);
-
-    jobject (JNICALL *NewGlobalRef)
-      (JNIEnv *env, jobject lobj);
-    void (JNICALL *DeleteGlobalRef)
-      (JNIEnv *env, jobject gref);
-    void (JNICALL *DeleteLocalRef)
-      (JNIEnv *env, jobject obj);
-    jboolean (JNICALL *IsSameObject)
-      (JNIEnv *env, jobject obj1, jobject obj2);
-    jobject (JNICALL *NewLocalRef)
-      (JNIEnv *env, jobject ref);
-    jint (JNICALL *EnsureLocalCapacity)
-      (JNIEnv *env, jint capacity);
-
-    jobject (JNICALL *AllocObject)
-      (JNIEnv *env, jclass clazz);
-    jobject (JNICALL *NewObject)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
-    jobject (JNICALL *NewObjectV)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
-    jobject (JNICALL *NewObjectA)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
-    jclass (JNICALL *GetObjectClass)
-      (JNIEnv *env, jobject obj);
-    jboolean (JNICALL *IsInstanceOf)
-      (JNIEnv *env, jobject obj, jclass clazz);
-
-    jmethodID (JNICALL *GetMethodID)
-      (JNIEnv *env, jclass clazz, const char *name, const char *sig);
-
-    jobject (JNICALL *CallObjectMethod)
-      (JNIEnv *env, jobject obj, jmethodID methodID, ...);
-    jobject (JNICALL *CallObjectMethodV)
-      (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
-    jobject (JNICALL *CallObjectMethodA)
-      (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue * args);
-
-    jboolean (JNICALL *CallBooleanMethod)
-      (JNIEnv *env, jobject obj, jmethodID methodID, ...);
-    jboolean (JNICALL *CallBooleanMethodV)
-      (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
-    jboolean (JNICALL *CallBooleanMethodA)
-      (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue * args);
-
-    jbyte (JNICALL *CallByteMethod)
-      (JNIEnv *env, jobject obj, jmethodID methodID, ...);
-    jbyte (JNICALL *CallByteMethodV)
-      (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
-    jbyte (JNICALL *CallByteMethodA)
-      (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
-    jchar (JNICALL *CallCharMethod)
-      (JNIEnv *env, jobject obj, jmethodID methodID, ...);
-    jchar (JNICALL *CallCharMethodV)
-      (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
-    jchar (JNICALL *CallCharMethodA)
-      (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
-    jshort (JNICALL *CallShortMethod)
-      (JNIEnv *env, jobject obj, jmethodID methodID, ...);
-    jshort (JNICALL *CallShortMethodV)
-      (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
-    jshort (JNICALL *CallShortMethodA)
-      (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
-    jint (JNICALL *CallIntMethod)
-      (JNIEnv *env, jobject obj, jmethodID methodID, ...);
-    jint (JNICALL *CallIntMethodV)
-      (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
-    jint (JNICALL *CallIntMethodA)
-      (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
-    jlong (JNICALL *CallLongMethod)
-      (JNIEnv *env, jobject obj, jmethodID methodID, ...);
-    jlong (JNICALL *CallLongMethodV)
-      (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
-    jlong (JNICALL *CallLongMethodA)
-      (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
-    jfloat (JNICALL *CallFloatMethod)
-      (JNIEnv *env, jobject obj, jmethodID methodID, ...);
-    jfloat (JNICALL *CallFloatMethodV)
-      (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
-    jfloat (JNICALL *CallFloatMethodA)
-      (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
-    jdouble (JNICALL *CallDoubleMethod)
-      (JNIEnv *env, jobject obj, jmethodID methodID, ...);
-    jdouble (JNICALL *CallDoubleMethodV)
-      (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
-    jdouble (JNICALL *CallDoubleMethodA)
-      (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
-    void (JNICALL *CallVoidMethod)
-      (JNIEnv *env, jobject obj, jmethodID methodID, ...);
-    void (JNICALL *CallVoidMethodV)
-      (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
-    void (JNICALL *CallVoidMethodA)
-      (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue * args);
-
-    jobject (JNICALL *CallNonvirtualObjectMethod)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
-    jobject (JNICALL *CallNonvirtualObjectMethodV)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       va_list args);
-    jobject (JNICALL *CallNonvirtualObjectMethodA)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       const jvalue * args);
-
-    jboolean (JNICALL *CallNonvirtualBooleanMethod)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
-    jboolean (JNICALL *CallNonvirtualBooleanMethodV)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       va_list args);
-    jboolean (JNICALL *CallNonvirtualBooleanMethodA)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       const jvalue * args);
-
-    jbyte (JNICALL *CallNonvirtualByteMethod)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
-    jbyte (JNICALL *CallNonvirtualByteMethodV)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       va_list args);
-    jbyte (JNICALL *CallNonvirtualByteMethodA)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       const jvalue *args);
-
-    jchar (JNICALL *CallNonvirtualCharMethod)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
-    jchar (JNICALL *CallNonvirtualCharMethodV)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       va_list args);
-    jchar (JNICALL *CallNonvirtualCharMethodA)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       const jvalue *args);
-
-    jshort (JNICALL *CallNonvirtualShortMethod)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
-    jshort (JNICALL *CallNonvirtualShortMethodV)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       va_list args);
-    jshort (JNICALL *CallNonvirtualShortMethodA)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       const jvalue *args);
-
-    jint (JNICALL *CallNonvirtualIntMethod)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
-    jint (JNICALL *CallNonvirtualIntMethodV)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       va_list args);
-    jint (JNICALL *CallNonvirtualIntMethodA)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       const jvalue *args);
-
-    jlong (JNICALL *CallNonvirtualLongMethod)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
-    jlong (JNICALL *CallNonvirtualLongMethodV)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       va_list args);
-    jlong (JNICALL *CallNonvirtualLongMethodA)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       const jvalue *args);
-
-    jfloat (JNICALL *CallNonvirtualFloatMethod)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
-    jfloat (JNICALL *CallNonvirtualFloatMethodV)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       va_list args);
-    jfloat (JNICALL *CallNonvirtualFloatMethodA)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       const jvalue *args);
-
-    jdouble (JNICALL *CallNonvirtualDoubleMethod)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
-    jdouble (JNICALL *CallNonvirtualDoubleMethodV)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       va_list args);
-    jdouble (JNICALL *CallNonvirtualDoubleMethodA)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       const jvalue *args);
-
-    void (JNICALL *CallNonvirtualVoidMethod)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
-    void (JNICALL *CallNonvirtualVoidMethodV)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       va_list args);
-    void (JNICALL *CallNonvirtualVoidMethodA)
-      (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
-       const jvalue * args);
-
-    jfieldID (JNICALL *GetFieldID)
-      (JNIEnv *env, jclass clazz, const char *name, const char *sig);
-
-    jobject (JNICALL *GetObjectField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID);
-    jboolean (JNICALL *GetBooleanField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID);
-    jbyte (JNICALL *GetByteField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID);
-    jchar (JNICALL *GetCharField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID);
-    jshort (JNICALL *GetShortField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID);
-    jint (JNICALL *GetIntField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID);
-    jlong (JNICALL *GetLongField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID);
-    jfloat (JNICALL *GetFloatField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID);
-    jdouble (JNICALL *GetDoubleField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID);
-
-    void (JNICALL *SetObjectField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID, jobject val);
-    void (JNICALL *SetBooleanField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID, jboolean val);
-    void (JNICALL *SetByteField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID, jbyte val);
-    void (JNICALL *SetCharField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID, jchar val);
-    void (JNICALL *SetShortField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID, jshort val);
-    void (JNICALL *SetIntField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID, jint val);
-    void (JNICALL *SetLongField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val);
-    void (JNICALL *SetFloatField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID, jfloat val);
-    void (JNICALL *SetDoubleField)
-      (JNIEnv *env, jobject obj, jfieldID fieldID, jdouble val);
-
-    jmethodID (JNICALL *GetStaticMethodID)
-      (JNIEnv *env, jclass clazz, const char *name, const char *sig);
-
-    jobject (JNICALL *CallStaticObjectMethod)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
-    jobject (JNICALL *CallStaticObjectMethodV)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
-    jobject (JNICALL *CallStaticObjectMethodA)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
-    jboolean (JNICALL *CallStaticBooleanMethod)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
-    jboolean (JNICALL *CallStaticBooleanMethodV)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
-    jboolean (JNICALL *CallStaticBooleanMethodA)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
-    jbyte (JNICALL *CallStaticByteMethod)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
-    jbyte (JNICALL *CallStaticByteMethodV)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
-    jbyte (JNICALL *CallStaticByteMethodA)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
-    jchar (JNICALL *CallStaticCharMethod)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
-    jchar (JNICALL *CallStaticCharMethodV)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
-    jchar (JNICALL *CallStaticCharMethodA)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
-    jshort (JNICALL *CallStaticShortMethod)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
-    jshort (JNICALL *CallStaticShortMethodV)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
-    jshort (JNICALL *CallStaticShortMethodA)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
-    jint (JNICALL *CallStaticIntMethod)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
-    jint (JNICALL *CallStaticIntMethodV)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
-    jint (JNICALL *CallStaticIntMethodA)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
-    jlong (JNICALL *CallStaticLongMethod)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
-    jlong (JNICALL *CallStaticLongMethodV)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
-    jlong (JNICALL *CallStaticLongMethodA)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
-    jfloat (JNICALL *CallStaticFloatMethod)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
-    jfloat (JNICALL *CallStaticFloatMethodV)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
-    jfloat (JNICALL *CallStaticFloatMethodA)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
-    jdouble (JNICALL *CallStaticDoubleMethod)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
-    jdouble (JNICALL *CallStaticDoubleMethodV)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
-    jdouble (JNICALL *CallStaticDoubleMethodA)
-      (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
-    void (JNICALL *CallStaticVoidMethod)
-      (JNIEnv *env, jclass cls, jmethodID methodID, ...);
-    void (JNICALL *CallStaticVoidMethodV)
-      (JNIEnv *env, jclass cls, jmethodID methodID, va_list args);
-    void (JNICALL *CallStaticVoidMethodA)
-      (JNIEnv *env, jclass cls, jmethodID methodID, const jvalue * args);
-
-    jfieldID (JNICALL *GetStaticFieldID)
-      (JNIEnv *env, jclass clazz, const char *name, const char *sig);
-    jobject (JNICALL *GetStaticObjectField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID);
-    jboolean (JNICALL *GetStaticBooleanField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID);
-    jbyte (JNICALL *GetStaticByteField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID);
-    jchar (JNICALL *GetStaticCharField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID);
-    jshort (JNICALL *GetStaticShortField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID);
-    jint (JNICALL *GetStaticIntField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID);
-    jlong (JNICALL *GetStaticLongField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID);
-    jfloat (JNICALL *GetStaticFloatField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID);
-    jdouble (JNICALL *GetStaticDoubleField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID);
-
-    void (JNICALL *SetStaticObjectField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value);
-    void (JNICALL *SetStaticBooleanField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value);
-    void (JNICALL *SetStaticByteField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value);
-    void (JNICALL *SetStaticCharField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value);
-    void (JNICALL *SetStaticShortField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value);
-    void (JNICALL *SetStaticIntField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID, jint value);
-    void (JNICALL *SetStaticLongField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value);
-    void (JNICALL *SetStaticFloatField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value);
-    void (JNICALL *SetStaticDoubleField)
-      (JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value);
-
-    jstring (JNICALL *NewString)
-      (JNIEnv *env, const jchar *unicode, jsize len);
-    jsize (JNICALL *GetStringLength)
-      (JNIEnv *env, jstring str);
-    const jchar *(JNICALL *GetStringChars)
-      (JNIEnv *env, jstring str, jboolean *isCopy);
-    void (JNICALL *ReleaseStringChars)
-      (JNIEnv *env, jstring str, const jchar *chars);
-
-    jstring (JNICALL *NewStringUTF)
-      (JNIEnv *env, const char *utf);
-    jsize (JNICALL *GetStringUTFLength)
-      (JNIEnv *env, jstring str);
-    const char* (JNICALL *GetStringUTFChars)
-      (JNIEnv *env, jstring str, jboolean *isCopy);
-    void (JNICALL *ReleaseStringUTFChars)
-      (JNIEnv *env, jstring str, const char* chars);
-
-
-    jsize (JNICALL *GetArrayLength)
-      (JNIEnv *env, jarray array);
-
-    jobjectArray (JNICALL *NewObjectArray)
-      (JNIEnv *env, jsize len, jclass clazz, jobject init);
-    jobject (JNICALL *GetObjectArrayElement)
-      (JNIEnv *env, jobjectArray array, jsize index);
-    void (JNICALL *SetObjectArrayElement)
-      (JNIEnv *env, jobjectArray array, jsize index, jobject val);
-
-    jbooleanArray (JNICALL *NewBooleanArray)
-      (JNIEnv *env, jsize len);
-    jbyteArray (JNICALL *NewByteArray)
-      (JNIEnv *env, jsize len);
-    jcharArray (JNICALL *NewCharArray)
-      (JNIEnv *env, jsize len);
-    jshortArray (JNICALL *NewShortArray)
-      (JNIEnv *env, jsize len);
-    jintArray (JNICALL *NewIntArray)
-      (JNIEnv *env, jsize len);
-    jlongArray (JNICALL *NewLongArray)
-      (JNIEnv *env, jsize len);
-    jfloatArray (JNICALL *NewFloatArray)
-      (JNIEnv *env, jsize len);
-    jdoubleArray (JNICALL *NewDoubleArray)
-      (JNIEnv *env, jsize len);
-
-    jboolean * (JNICALL *GetBooleanArrayElements)
-      (JNIEnv *env, jbooleanArray array, jboolean *isCopy);
-    jbyte * (JNICALL *GetByteArrayElements)
-      (JNIEnv *env, jbyteArray array, jboolean *isCopy);
-    jchar * (JNICALL *GetCharArrayElements)
-      (JNIEnv *env, jcharArray array, jboolean *isCopy);
-    jshort * (JNICALL *GetShortArrayElements)
-      (JNIEnv *env, jshortArray array, jboolean *isCopy);
-    jint * (JNICALL *GetIntArrayElements)
-      (JNIEnv *env, jintArray array, jboolean *isCopy);
-    jlong * (JNICALL *GetLongArrayElements)
-      (JNIEnv *env, jlongArray array, jboolean *isCopy);
-    jfloat * (JNICALL *GetFloatArrayElements)
-      (JNIEnv *env, jfloatArray array, jboolean *isCopy);
-    jdouble * (JNICALL *GetDoubleArrayElements)
-      (JNIEnv *env, jdoubleArray array, jboolean *isCopy);
-
-    void (JNICALL *ReleaseBooleanArrayElements)
-      (JNIEnv *env, jbooleanArray array, jboolean *elems, jint mode);
-    void (JNICALL *ReleaseByteArrayElements)
-      (JNIEnv *env, jbyteArray array, jbyte *elems, jint mode);
-    void (JNICALL *ReleaseCharArrayElements)
-      (JNIEnv *env, jcharArray array, jchar *elems, jint mode);
-    void (JNICALL *ReleaseShortArrayElements)
-      (JNIEnv *env, jshortArray array, jshort *elems, jint mode);
-    void (JNICALL *ReleaseIntArrayElements)
-      (JNIEnv *env, jintArray array, jint *elems, jint mode);
-    void (JNICALL *ReleaseLongArrayElements)
-      (JNIEnv *env, jlongArray array, jlong *elems, jint mode);
-    void (JNICALL *ReleaseFloatArrayElements)
-      (JNIEnv *env, jfloatArray array, jfloat *elems, jint mode);
-    void (JNICALL *ReleaseDoubleArrayElements)
-      (JNIEnv *env, jdoubleArray array, jdouble *elems, jint mode);
-
-    void (JNICALL *GetBooleanArrayRegion)
-      (JNIEnv *env, jbooleanArray array, jsize start, jsize l, jboolean *buf);
-    void (JNICALL *GetByteArrayRegion)
-      (JNIEnv *env, jbyteArray array, jsize start, jsize len, jbyte *buf);
-    void (JNICALL *GetCharArrayRegion)
-      (JNIEnv *env, jcharArray array, jsize start, jsize len, jchar *buf);
-    void (JNICALL *GetShortArrayRegion)
-      (JNIEnv *env, jshortArray array, jsize start, jsize len, jshort *buf);
-    void (JNICALL *GetIntArrayRegion)
-      (JNIEnv *env, jintArray array, jsize start, jsize len, jint *buf);
-    void (JNICALL *GetLongArrayRegion)
-      (JNIEnv *env, jlongArray array, jsize start, jsize len, jlong *buf);
-    void (JNICALL *GetFloatArrayRegion)
-      (JNIEnv *env, jfloatArray array, jsize start, jsize len, jfloat *buf);
-    void (JNICALL *GetDoubleArrayRegion)
-      (JNIEnv *env, jdoubleArray array, jsize start, jsize len, jdouble *buf);
-
-    void (JNICALL *SetBooleanArrayRegion)
-      (JNIEnv *env, jbooleanArray array, jsize start, jsize l, const jboolean *buf);
-    void (JNICALL *SetByteArrayRegion)
-      (JNIEnv *env, jbyteArray array, jsize start, jsize len, const jbyte *buf);
-    void (JNICALL *SetCharArrayRegion)
-      (JNIEnv *env, jcharArray array, jsize start, jsize len, const jchar *buf);
-    void (JNICALL *SetShortArrayRegion)
-      (JNIEnv *env, jshortArray array, jsize start, jsize len, const jshort *buf);
-    void (JNICALL *SetIntArrayRegion)
-      (JNIEnv *env, jintArray array, jsize start, jsize len, const jint *buf);
-    void (JNICALL *SetLongArrayRegion)
-      (JNIEnv *env, jlongArray array, jsize start, jsize len, const jlong *buf);
-    void (JNICALL *SetFloatArrayRegion)
-      (JNIEnv *env, jfloatArray array, jsize start, jsize len, const jfloat *buf);
-    void (JNICALL *SetDoubleArrayRegion)
-      (JNIEnv *env, jdoubleArray array, jsize start, jsize len, const jdouble *buf);
-
-    jint (JNICALL *RegisterNatives)
-      (JNIEnv *env, jclass clazz, const JNINativeMethod *methods,
-       jint nMethods);
-    jint (JNICALL *UnregisterNatives)
-      (JNIEnv *env, jclass clazz);
-
-    jint (JNICALL *MonitorEnter)
-      (JNIEnv *env, jobject obj);
-    jint (JNICALL *MonitorExit)
-      (JNIEnv *env, jobject obj);
-
-    jint (JNICALL *GetJavaVM)
-      (JNIEnv *env, JavaVM **vm);
-
-    void (JNICALL *GetStringRegion)
-      (JNIEnv *env, jstring str, jsize start, jsize len, jchar *buf);
-    void (JNICALL *GetStringUTFRegion)
-      (JNIEnv *env, jstring str, jsize start, jsize len, char *buf);
-
-    void * (JNICALL *GetPrimitiveArrayCritical)
-      (JNIEnv *env, jarray array, jboolean *isCopy);
-    void (JNICALL *ReleasePrimitiveArrayCritical)
-      (JNIEnv *env, jarray array, void *carray, jint mode);
-
-    const jchar * (JNICALL *GetStringCritical)
-      (JNIEnv *env, jstring string, jboolean *isCopy);
-    void (JNICALL *ReleaseStringCritical)
-      (JNIEnv *env, jstring string, const jchar *cstring);
-
-    jweak (JNICALL *NewWeakGlobalRef)
-       (JNIEnv *env, jobject obj);
-    void (JNICALL *DeleteWeakGlobalRef)
-       (JNIEnv *env, jweak ref);
-
-    jboolean (JNICALL *ExceptionCheck)
-       (JNIEnv *env);
-
-    jobject (JNICALL *NewDirectByteBuffer)
-       (JNIEnv* env, void* address, jlong capacity);
-    void* (JNICALL *GetDirectBufferAddress)
-       (JNIEnv* env, jobject buf);
-    jlong (JNICALL *GetDirectBufferCapacity)
-       (JNIEnv* env, jobject buf);
-
-    /* New JNI 1.6 Features */
-
-    jobjectRefType (JNICALL *GetObjectRefType)
-        (JNIEnv* env, jobject obj);
-
-    /* Module Features */
-
-    jobject (JNICALL *GetModule)
-       (JNIEnv* env, jclass clazz);
-};
-
-/*
- * We use inlined functions for C++ so that programmers can write:
- *
- *    env->FindClass("java/lang/String")
- *
- * in C++ rather than:
- *
- *    (*env)->FindClass(env, "java/lang/String")
- *
- * in C.
- */
-
-struct JNIEnv_ {
-    const struct JNINativeInterface_ *functions;
-#ifdef __cplusplus
-
-    jint GetVersion() {
-        return functions->GetVersion(this);
-    }
-    jclass DefineClass(const char *name, jobject loader, const jbyte *buf,
-                       jsize len) {
-        return functions->DefineClass(this, name, loader, buf, len);
-    }
-    jclass FindClass(const char *name) {
-        return functions->FindClass(this, name);
-    }
-    jmethodID FromReflectedMethod(jobject method) {
-        return functions->FromReflectedMethod(this,method);
-    }
-    jfieldID FromReflectedField(jobject field) {
-        return functions->FromReflectedField(this,field);
-    }
-
-    jobject ToReflectedMethod(jclass cls, jmethodID methodID, jboolean isStatic) {
-        return functions->ToReflectedMethod(this, cls, methodID, isStatic);
-    }
-
-    jclass GetSuperclass(jclass sub) {
-        return functions->GetSuperclass(this, sub);
-    }
-    jboolean IsAssignableFrom(jclass sub, jclass sup) {
-        return functions->IsAssignableFrom(this, sub, sup);
-    }
-
-    jobject ToReflectedField(jclass cls, jfieldID fieldID, jboolean isStatic) {
-        return functions->ToReflectedField(this,cls,fieldID,isStatic);
-    }
-
-    jint Throw(jthrowable obj) {
-        return functions->Throw(this, obj);
-    }
-    jint ThrowNew(jclass clazz, const char *msg) {
-        return functions->ThrowNew(this, clazz, msg);
-    }
-    jthrowable ExceptionOccurred() {
-        return functions->ExceptionOccurred(this);
-    }
-    void ExceptionDescribe() {
-        functions->ExceptionDescribe(this);
-    }
-    void ExceptionClear() {
-        functions->ExceptionClear(this);
-    }
-    void FatalError(const char *msg) {
-        functions->FatalError(this, msg);
-    }
-
-    jint PushLocalFrame(jint capacity) {
-        return functions->PushLocalFrame(this,capacity);
-    }
-    jobject PopLocalFrame(jobject result) {
-        return functions->PopLocalFrame(this,result);
-    }
-
-    jobject NewGlobalRef(jobject lobj) {
-        return functions->NewGlobalRef(this,lobj);
-    }
-    void DeleteGlobalRef(jobject gref) {
-        functions->DeleteGlobalRef(this,gref);
-    }
-    void DeleteLocalRef(jobject obj) {
-        functions->DeleteLocalRef(this, obj);
-    }
-
-    jboolean IsSameObject(jobject obj1, jobject obj2) {
-        return functions->IsSameObject(this,obj1,obj2);
-    }
-
-    jobject NewLocalRef(jobject ref) {
-        return functions->NewLocalRef(this,ref);
-    }
-    jint EnsureLocalCapacity(jint capacity) {
-        return functions->EnsureLocalCapacity(this,capacity);
-    }
-
-    jobject AllocObject(jclass clazz) {
-        return functions->AllocObject(this,clazz);
-    }
-    jobject NewObject(jclass clazz, jmethodID methodID, ...) {
-        va_list args;
-        jobject result;
-        va_start(args, methodID);
-        result = functions->NewObjectV(this,clazz,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jobject NewObjectV(jclass clazz, jmethodID methodID,
-                       va_list args) {
-        return functions->NewObjectV(this,clazz,methodID,args);
-    }
-    jobject NewObjectA(jclass clazz, jmethodID methodID,
-                       const jvalue *args) {
-        return functions->NewObjectA(this,clazz,methodID,args);
-    }
-
-    jclass GetObjectClass(jobject obj) {
-        return functions->GetObjectClass(this,obj);
-    }
-    jboolean IsInstanceOf(jobject obj, jclass clazz) {
-        return functions->IsInstanceOf(this,obj,clazz);
-    }
-
-    jmethodID GetMethodID(jclass clazz, const char *name,
-                          const char *sig) {
-        return functions->GetMethodID(this,clazz,name,sig);
-    }
-
-    jobject CallObjectMethod(jobject obj, jmethodID methodID, ...) {
-        va_list args;
-        jobject result;
-        va_start(args,methodID);
-        result = functions->CallObjectMethodV(this,obj,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jobject CallObjectMethodV(jobject obj, jmethodID methodID,
-                        va_list args) {
-        return functions->CallObjectMethodV(this,obj,methodID,args);
-    }
-    jobject CallObjectMethodA(jobject obj, jmethodID methodID,
-                        const jvalue * args) {
-        return functions->CallObjectMethodA(this,obj,methodID,args);
-    }
-
-    jboolean CallBooleanMethod(jobject obj,
-                               jmethodID methodID, ...) {
-        va_list args;
-        jboolean result;
-        va_start(args,methodID);
-        result = functions->CallBooleanMethodV(this,obj,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jboolean CallBooleanMethodV(jobject obj, jmethodID methodID,
-                                va_list args) {
-        return functions->CallBooleanMethodV(this,obj,methodID,args);
-    }
-    jboolean CallBooleanMethodA(jobject obj, jmethodID methodID,
-                                const jvalue * args) {
-        return functions->CallBooleanMethodA(this,obj,methodID, args);
-    }
-
-    jbyte CallByteMethod(jobject obj, jmethodID methodID, ...) {
-        va_list args;
-        jbyte result;
-        va_start(args,methodID);
-        result = functions->CallByteMethodV(this,obj,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jbyte CallByteMethodV(jobject obj, jmethodID methodID,
-                          va_list args) {
-        return functions->CallByteMethodV(this,obj,methodID,args);
-    }
-    jbyte CallByteMethodA(jobject obj, jmethodID methodID,
-                          const jvalue * args) {
-        return functions->CallByteMethodA(this,obj,methodID,args);
-    }
-
-    jchar CallCharMethod(jobject obj, jmethodID methodID, ...) {
-        va_list args;
-        jchar result;
-        va_start(args,methodID);
-        result = functions->CallCharMethodV(this,obj,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jchar CallCharMethodV(jobject obj, jmethodID methodID,
-                          va_list args) {
-        return functions->CallCharMethodV(this,obj,methodID,args);
-    }
-    jchar CallCharMethodA(jobject obj, jmethodID methodID,
-                          const jvalue * args) {
-        return functions->CallCharMethodA(this,obj,methodID,args);
-    }
-
-    jshort CallShortMethod(jobject obj, jmethodID methodID, ...) {
-        va_list args;
-        jshort result;
-        va_start(args,methodID);
-        result = functions->CallShortMethodV(this,obj,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jshort CallShortMethodV(jobject obj, jmethodID methodID,
-                            va_list args) {
-        return functions->CallShortMethodV(this,obj,methodID,args);
-    }
-    jshort CallShortMethodA(jobject obj, jmethodID methodID,
-                            const jvalue * args) {
-        return functions->CallShortMethodA(this,obj,methodID,args);
-    }
-
-    jint CallIntMethod(jobject obj, jmethodID methodID, ...) {
-        va_list args;
-        jint result;
-        va_start(args,methodID);
-        result = functions->CallIntMethodV(this,obj,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jint CallIntMethodV(jobject obj, jmethodID methodID,
-                        va_list args) {
-        return functions->CallIntMethodV(this,obj,methodID,args);
-    }
-    jint CallIntMethodA(jobject obj, jmethodID methodID,
-                        const jvalue * args) {
-        return functions->CallIntMethodA(this,obj,methodID,args);
-    }
-
-    jlong CallLongMethod(jobject obj, jmethodID methodID, ...) {
-        va_list args;
-        jlong result;
-        va_start(args,methodID);
-        result = functions->CallLongMethodV(this,obj,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jlong CallLongMethodV(jobject obj, jmethodID methodID,
-                          va_list args) {
-        return functions->CallLongMethodV(this,obj,methodID,args);
-    }
-    jlong CallLongMethodA(jobject obj, jmethodID methodID,
-                          const jvalue * args) {
-        return functions->CallLongMethodA(this,obj,methodID,args);
-    }
-
-    jfloat CallFloatMethod(jobject obj, jmethodID methodID, ...) {
-        va_list args;
-        jfloat result;
-        va_start(args,methodID);
-        result = functions->CallFloatMethodV(this,obj,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jfloat CallFloatMethodV(jobject obj, jmethodID methodID,
-                            va_list args) {
-        return functions->CallFloatMethodV(this,obj,methodID,args);
-    }
-    jfloat CallFloatMethodA(jobject obj, jmethodID methodID,
-                            const jvalue * args) {
-        return functions->CallFloatMethodA(this,obj,methodID,args);
-    }
-
-    jdouble CallDoubleMethod(jobject obj, jmethodID methodID, ...) {
-        va_list args;
-        jdouble result;
-        va_start(args,methodID);
-        result = functions->CallDoubleMethodV(this,obj,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jdouble CallDoubleMethodV(jobject obj, jmethodID methodID,
-                        va_list args) {
-        return functions->CallDoubleMethodV(this,obj,methodID,args);
-    }
-    jdouble CallDoubleMethodA(jobject obj, jmethodID methodID,
-                        const jvalue * args) {
-        return functions->CallDoubleMethodA(this,obj,methodID,args);
-    }
-
-    void CallVoidMethod(jobject obj, jmethodID methodID, ...) {
-        va_list args;
-        va_start(args,methodID);
-        functions->CallVoidMethodV(this,obj,methodID,args);
-        va_end(args);
-    }
-    void CallVoidMethodV(jobject obj, jmethodID methodID,
-                         va_list args) {
-        functions->CallVoidMethodV(this,obj,methodID,args);
-    }
-    void CallVoidMethodA(jobject obj, jmethodID methodID,
-                         const jvalue * args) {
-        functions->CallVoidMethodA(this,obj,methodID,args);
-    }
-
-    jobject CallNonvirtualObjectMethod(jobject obj, jclass clazz,
-                                       jmethodID methodID, ...) {
-        va_list args;
-        jobject result;
-        va_start(args,methodID);
-        result = functions->CallNonvirtualObjectMethodV(this,obj,clazz,
-                                                        methodID,args);
-        va_end(args);
-        return result;
-    }
-    jobject CallNonvirtualObjectMethodV(jobject obj, jclass clazz,
-                                        jmethodID methodID, va_list args) {
-        return functions->CallNonvirtualObjectMethodV(this,obj,clazz,
-                                                      methodID,args);
-    }
-    jobject CallNonvirtualObjectMethodA(jobject obj, jclass clazz,
-                                        jmethodID methodID, const jvalue * args) {
-        return functions->CallNonvirtualObjectMethodA(this,obj,clazz,
-                                                      methodID,args);
-    }
-
-    jboolean CallNonvirtualBooleanMethod(jobject obj, jclass clazz,
-                                         jmethodID methodID, ...) {
-        va_list args;
-        jboolean result;
-        va_start(args,methodID);
-        result = functions->CallNonvirtualBooleanMethodV(this,obj,clazz,
-                                                         methodID,args);
-        va_end(args);
-        return result;
-    }
-    jboolean CallNonvirtualBooleanMethodV(jobject obj, jclass clazz,
-                                          jmethodID methodID, va_list args) {
-        return functions->CallNonvirtualBooleanMethodV(this,obj,clazz,
-                                                       methodID,args);
-    }
-    jboolean CallNonvirtualBooleanMethodA(jobject obj, jclass clazz,
-                                          jmethodID methodID, const jvalue * args) {
-        return functions->CallNonvirtualBooleanMethodA(this,obj,clazz,
-                                                       methodID, args);
-    }
-
-    jbyte CallNonvirtualByteMethod(jobject obj, jclass clazz,
-                                   jmethodID methodID, ...) {
-        va_list args;
-        jbyte result;
-        va_start(args,methodID);
-        result = functions->CallNonvirtualByteMethodV(this,obj,clazz,
-                                                      methodID,args);
-        va_end(args);
-        return result;
-    }
-    jbyte CallNonvirtualByteMethodV(jobject obj, jclass clazz,
-                                    jmethodID methodID, va_list args) {
-        return functions->CallNonvirtualByteMethodV(this,obj,clazz,
-                                                    methodID,args);
-    }
-    jbyte CallNonvirtualByteMethodA(jobject obj, jclass clazz,
-                                    jmethodID methodID, const jvalue * args) {
-        return functions->CallNonvirtualByteMethodA(this,obj,clazz,
-                                                    methodID,args);
-    }
-
-    jchar CallNonvirtualCharMethod(jobject obj, jclass clazz,
-                                   jmethodID methodID, ...) {
-        va_list args;
-        jchar result;
-        va_start(args,methodID);
-        result = functions->CallNonvirtualCharMethodV(this,obj,clazz,
-                                                      methodID,args);
-        va_end(args);
-        return result;
-    }
-    jchar CallNonvirtualCharMethodV(jobject obj, jclass clazz,
-                                    jmethodID methodID, va_list args) {
-        return functions->CallNonvirtualCharMethodV(this,obj,clazz,
-                                                    methodID,args);
-    }
-    jchar CallNonvirtualCharMethodA(jobject obj, jclass clazz,
-                                    jmethodID methodID, const jvalue * args) {
-        return functions->CallNonvirtualCharMethodA(this,obj,clazz,
-                                                    methodID,args);
-    }
-
-    jshort CallNonvirtualShortMethod(jobject obj, jclass clazz,
-                                     jmethodID methodID, ...) {
-        va_list args;
-        jshort result;
-        va_start(args,methodID);
-        result = functions->CallNonvirtualShortMethodV(this,obj,clazz,
-                                                       methodID,args);
-        va_end(args);
-        return result;
-    }
-    jshort CallNonvirtualShortMethodV(jobject obj, jclass clazz,
-                                      jmethodID methodID, va_list args) {
-        return functions->CallNonvirtualShortMethodV(this,obj,clazz,
-                                                     methodID,args);
-    }
-    jshort CallNonvirtualShortMethodA(jobject obj, jclass clazz,
-                                      jmethodID methodID, const jvalue * args) {
-        return functions->CallNonvirtualShortMethodA(this,obj,clazz,
-                                                     methodID,args);
-    }
-
-    jint CallNonvirtualIntMethod(jobject obj, jclass clazz,
-                                 jmethodID methodID, ...) {
-        va_list args;
-        jint result;
-        va_start(args,methodID);
-        result = functions->CallNonvirtualIntMethodV(this,obj,clazz,
-                                                     methodID,args);
-        va_end(args);
-        return result;
-    }
-    jint CallNonvirtualIntMethodV(jobject obj, jclass clazz,
-                                  jmethodID methodID, va_list args) {
-        return functions->CallNonvirtualIntMethodV(this,obj,clazz,
-                                                   methodID,args);
-    }
-    jint CallNonvirtualIntMethodA(jobject obj, jclass clazz,
-                                  jmethodID methodID, const jvalue * args) {
-        return functions->CallNonvirtualIntMethodA(this,obj,clazz,
-                                                   methodID,args);
-    }
-
-    jlong CallNonvirtualLongMethod(jobject obj, jclass clazz,
-                                   jmethodID methodID, ...) {
-        va_list args;
-        jlong result;
-        va_start(args,methodID);
-        result = functions->CallNonvirtualLongMethodV(this,obj,clazz,
-                                                      methodID,args);
-        va_end(args);
-        return result;
-    }
-    jlong CallNonvirtualLongMethodV(jobject obj, jclass clazz,
-                                    jmethodID methodID, va_list args) {
-        return functions->CallNonvirtualLongMethodV(this,obj,clazz,
-                                                    methodID,args);
-    }
-    jlong CallNonvirtualLongMethodA(jobject obj, jclass clazz,
-                                    jmethodID methodID, const jvalue * args) {
-        return functions->CallNonvirtualLongMethodA(this,obj,clazz,
-                                                    methodID,args);
-    }
-
-    jfloat CallNonvirtualFloatMethod(jobject obj, jclass clazz,
-                                     jmethodID methodID, ...) {
-        va_list args;
-        jfloat result;
-        va_start(args,methodID);
-        result = functions->CallNonvirtualFloatMethodV(this,obj,clazz,
-                                                       methodID,args);
-        va_end(args);
-        return result;
-    }
-    jfloat CallNonvirtualFloatMethodV(jobject obj, jclass clazz,
-                                      jmethodID methodID,
-                                      va_list args) {
-        return functions->CallNonvirtualFloatMethodV(this,obj,clazz,
-                                                     methodID,args);
-    }
-    jfloat CallNonvirtualFloatMethodA(jobject obj, jclass clazz,
-                                      jmethodID methodID,
-                                      const jvalue * args) {
-        return functions->CallNonvirtualFloatMethodA(this,obj,clazz,
-                                                     methodID,args);
-    }
-
-    jdouble CallNonvirtualDoubleMethod(jobject obj, jclass clazz,
-                                       jmethodID methodID, ...) {
-        va_list args;
-        jdouble result;
-        va_start(args,methodID);
-        result = functions->CallNonvirtualDoubleMethodV(this,obj,clazz,
-                                                        methodID,args);
-        va_end(args);
-        return result;
-    }
-    jdouble CallNonvirtualDoubleMethodV(jobject obj, jclass clazz,
-                                        jmethodID methodID,
-                                        va_list args) {
-        return functions->CallNonvirtualDoubleMethodV(this,obj,clazz,
-                                                      methodID,args);
-    }
-    jdouble CallNonvirtualDoubleMethodA(jobject obj, jclass clazz,
-                                        jmethodID methodID,
-                                        const jvalue * args) {
-        return functions->CallNonvirtualDoubleMethodA(this,obj,clazz,
-                                                      methodID,args);
-    }
-
-    void CallNonvirtualVoidMethod(jobject obj, jclass clazz,
-                                  jmethodID methodID, ...) {
-        va_list args;
-        va_start(args,methodID);
-        functions->CallNonvirtualVoidMethodV(this,obj,clazz,methodID,args);
-        va_end(args);
-    }
-    void CallNonvirtualVoidMethodV(jobject obj, jclass clazz,
-                                   jmethodID methodID,
-                                   va_list args) {
-        functions->CallNonvirtualVoidMethodV(this,obj,clazz,methodID,args);
-    }
-    void CallNonvirtualVoidMethodA(jobject obj, jclass clazz,
-                                   jmethodID methodID,
-                                   const jvalue * args) {
-        functions->CallNonvirtualVoidMethodA(this,obj,clazz,methodID,args);
-    }
-
-    jfieldID GetFieldID(jclass clazz, const char *name,
-                        const char *sig) {
-        return functions->GetFieldID(this,clazz,name,sig);
-    }
-
-    jobject GetObjectField(jobject obj, jfieldID fieldID) {
-        return functions->GetObjectField(this,obj,fieldID);
-    }
-    jboolean GetBooleanField(jobject obj, jfieldID fieldID) {
-        return functions->GetBooleanField(this,obj,fieldID);
-    }
-    jbyte GetByteField(jobject obj, jfieldID fieldID) {
-        return functions->GetByteField(this,obj,fieldID);
-    }
-    jchar GetCharField(jobject obj, jfieldID fieldID) {
-        return functions->GetCharField(this,obj,fieldID);
-    }
-    jshort GetShortField(jobject obj, jfieldID fieldID) {
-        return functions->GetShortField(this,obj,fieldID);
-    }
-    jint GetIntField(jobject obj, jfieldID fieldID) {
-        return functions->GetIntField(this,obj,fieldID);
-    }
-    jlong GetLongField(jobject obj, jfieldID fieldID) {
-        return functions->GetLongField(this,obj,fieldID);
-    }
-    jfloat GetFloatField(jobject obj, jfieldID fieldID) {
-        return functions->GetFloatField(this,obj,fieldID);
-    }
-    jdouble GetDoubleField(jobject obj, jfieldID fieldID) {
-        return functions->GetDoubleField(this,obj,fieldID);
-    }
-
-    void SetObjectField(jobject obj, jfieldID fieldID, jobject val) {
-        functions->SetObjectField(this,obj,fieldID,val);
-    }
-    void SetBooleanField(jobject obj, jfieldID fieldID,
-                         jboolean val) {
-        functions->SetBooleanField(this,obj,fieldID,val);
-    }
-    void SetByteField(jobject obj, jfieldID fieldID,
-                      jbyte val) {
-        functions->SetByteField(this,obj,fieldID,val);
-    }
-    void SetCharField(jobject obj, jfieldID fieldID,
-                      jchar val) {
-        functions->SetCharField(this,obj,fieldID,val);
-    }
-    void SetShortField(jobject obj, jfieldID fieldID,
-                       jshort val) {
-        functions->SetShortField(this,obj,fieldID,val);
-    }
-    void SetIntField(jobject obj, jfieldID fieldID,
-                     jint val) {
-        functions->SetIntField(this,obj,fieldID,val);
-    }
-    void SetLongField(jobject obj, jfieldID fieldID,
-                      jlong val) {
-        functions->SetLongField(this,obj,fieldID,val);
-    }
-    void SetFloatField(jobject obj, jfieldID fieldID,
-                       jfloat val) {
-        functions->SetFloatField(this,obj,fieldID,val);
-    }
-    void SetDoubleField(jobject obj, jfieldID fieldID,
-                        jdouble val) {
-        functions->SetDoubleField(this,obj,fieldID,val);
-    }
-
-    jmethodID GetStaticMethodID(jclass clazz, const char *name,
-                                const char *sig) {
-        return functions->GetStaticMethodID(this,clazz,name,sig);
-    }
-
-    jobject CallStaticObjectMethod(jclass clazz, jmethodID methodID,
-                             ...) {
-        va_list args;
-        jobject result;
-        va_start(args,methodID);
-        result = functions->CallStaticObjectMethodV(this,clazz,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jobject CallStaticObjectMethodV(jclass clazz, jmethodID methodID,
-                              va_list args) {
-        return functions->CallStaticObjectMethodV(this,clazz,methodID,args);
-    }
-    jobject CallStaticObjectMethodA(jclass clazz, jmethodID methodID,
-                              const jvalue *args) {
-        return functions->CallStaticObjectMethodA(this,clazz,methodID,args);
-    }
-
-    jboolean CallStaticBooleanMethod(jclass clazz,
-                                     jmethodID methodID, ...) {
-        va_list args;
-        jboolean result;
-        va_start(args,methodID);
-        result = functions->CallStaticBooleanMethodV(this,clazz,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jboolean CallStaticBooleanMethodV(jclass clazz,
-                                      jmethodID methodID, va_list args) {
-        return functions->CallStaticBooleanMethodV(this,clazz,methodID,args);
-    }
-    jboolean CallStaticBooleanMethodA(jclass clazz,
-                                      jmethodID methodID, const jvalue *args) {
-        return functions->CallStaticBooleanMethodA(this,clazz,methodID,args);
-    }
-
-    jbyte CallStaticByteMethod(jclass clazz,
-                               jmethodID methodID, ...) {
-        va_list args;
-        jbyte result;
-        va_start(args,methodID);
-        result = functions->CallStaticByteMethodV(this,clazz,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jbyte CallStaticByteMethodV(jclass clazz,
-                                jmethodID methodID, va_list args) {
-        return functions->CallStaticByteMethodV(this,clazz,methodID,args);
-    }
-    jbyte CallStaticByteMethodA(jclass clazz,
-                                jmethodID methodID, const jvalue *args) {
-        return functions->CallStaticByteMethodA(this,clazz,methodID,args);
-    }
-
-    jchar CallStaticCharMethod(jclass clazz,
-                               jmethodID methodID, ...) {
-        va_list args;
-        jchar result;
-        va_start(args,methodID);
-        result = functions->CallStaticCharMethodV(this,clazz,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jchar CallStaticCharMethodV(jclass clazz,
-                                jmethodID methodID, va_list args) {
-        return functions->CallStaticCharMethodV(this,clazz,methodID,args);
-    }
-    jchar CallStaticCharMethodA(jclass clazz,
-                                jmethodID methodID, const jvalue *args) {
-        return functions->CallStaticCharMethodA(this,clazz,methodID,args);
-    }
-
-    jshort CallStaticShortMethod(jclass clazz,
-                                 jmethodID methodID, ...) {
-        va_list args;
-        jshort result;
-        va_start(args,methodID);
-        result = functions->CallStaticShortMethodV(this,clazz,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jshort CallStaticShortMethodV(jclass clazz,
-                                  jmethodID methodID, va_list args) {
-        return functions->CallStaticShortMethodV(this,clazz,methodID,args);
-    }
-    jshort CallStaticShortMethodA(jclass clazz,
-                                  jmethodID methodID, const jvalue *args) {
-        return functions->CallStaticShortMethodA(this,clazz,methodID,args);
-    }
-
-    jint CallStaticIntMethod(jclass clazz,
-                             jmethodID methodID, ...) {
-        va_list args;
-        jint result;
-        va_start(args,methodID);
-        result = functions->CallStaticIntMethodV(this,clazz,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jint CallStaticIntMethodV(jclass clazz,
-                              jmethodID methodID, va_list args) {
-        return functions->CallStaticIntMethodV(this,clazz,methodID,args);
-    }
-    jint CallStaticIntMethodA(jclass clazz,
-                              jmethodID methodID, const jvalue *args) {
-        return functions->CallStaticIntMethodA(this,clazz,methodID,args);
-    }
-
-    jlong CallStaticLongMethod(jclass clazz,
-                               jmethodID methodID, ...) {
-        va_list args;
-        jlong result;
-        va_start(args,methodID);
-        result = functions->CallStaticLongMethodV(this,clazz,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jlong CallStaticLongMethodV(jclass clazz,
-                                jmethodID methodID, va_list args) {
-        return functions->CallStaticLongMethodV(this,clazz,methodID,args);
-    }
-    jlong CallStaticLongMethodA(jclass clazz,
-                                jmethodID methodID, const jvalue *args) {
-        return functions->CallStaticLongMethodA(this,clazz,methodID,args);
-    }
-
-    jfloat CallStaticFloatMethod(jclass clazz,
-                                 jmethodID methodID, ...) {
-        va_list args;
-        jfloat result;
-        va_start(args,methodID);
-        result = functions->CallStaticFloatMethodV(this,clazz,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jfloat CallStaticFloatMethodV(jclass clazz,
-                                  jmethodID methodID, va_list args) {
-        return functions->CallStaticFloatMethodV(this,clazz,methodID,args);
-    }
-    jfloat CallStaticFloatMethodA(jclass clazz,
-                                  jmethodID methodID, const jvalue *args) {
-        return functions->CallStaticFloatMethodA(this,clazz,methodID,args);
-    }
-
-    jdouble CallStaticDoubleMethod(jclass clazz,
-                                   jmethodID methodID, ...) {
-        va_list args;
-        jdouble result;
-        va_start(args,methodID);
-        result = functions->CallStaticDoubleMethodV(this,clazz,methodID,args);
-        va_end(args);
-        return result;
-    }
-    jdouble CallStaticDoubleMethodV(jclass clazz,
-                                    jmethodID methodID, va_list args) {
-        return functions->CallStaticDoubleMethodV(this,clazz,methodID,args);
-    }
-    jdouble CallStaticDoubleMethodA(jclass clazz,
-                                    jmethodID methodID, const jvalue *args) {
-        return functions->CallStaticDoubleMethodA(this,clazz,methodID,args);
-    }
-
-    void CallStaticVoidMethod(jclass cls, jmethodID methodID, ...) {
-        va_list args;
-        va_start(args,methodID);
-        functions->CallStaticVoidMethodV(this,cls,methodID,args);
-        va_end(args);
-    }
-    void CallStaticVoidMethodV(jclass cls, jmethodID methodID,
-                               va_list args) {
-        functions->CallStaticVoidMethodV(this,cls,methodID,args);
-    }
-    void CallStaticVoidMethodA(jclass cls, jmethodID methodID,
-                               const jvalue * args) {
-        functions->CallStaticVoidMethodA(this,cls,methodID,args);
-    }
-
-    jfieldID GetStaticFieldID(jclass clazz, const char *name,
-                              const char *sig) {
-        return functions->GetStaticFieldID(this,clazz,name,sig);
-    }
-    jobject GetStaticObjectField(jclass clazz, jfieldID fieldID) {
-        return functions->GetStaticObjectField(this,clazz,fieldID);
-    }
-    jboolean GetStaticBooleanField(jclass clazz, jfieldID fieldID) {
-        return functions->GetStaticBooleanField(this,clazz,fieldID);
-    }
-    jbyte GetStaticByteField(jclass clazz, jfieldID fieldID) {
-        return functions->GetStaticByteField(this,clazz,fieldID);
-    }
-    jchar GetStaticCharField(jclass clazz, jfieldID fieldID) {
-        return functions->GetStaticCharField(this,clazz,fieldID);
-    }
-    jshort GetStaticShortField(jclass clazz, jfieldID fieldID) {
-        return functions->GetStaticShortField(this,clazz,fieldID);
-    }
-    jint GetStaticIntField(jclass clazz, jfieldID fieldID) {
-        return functions->GetStaticIntField(this,clazz,fieldID);
-    }
-    jlong GetStaticLongField(jclass clazz, jfieldID fieldID) {
-        return functions->GetStaticLongField(this,clazz,fieldID);
-    }
-    jfloat GetStaticFloatField(jclass clazz, jfieldID fieldID) {
-        return functions->GetStaticFloatField(this,clazz,fieldID);
-    }
-    jdouble GetStaticDoubleField(jclass clazz, jfieldID fieldID) {
-        return functions->GetStaticDoubleField(this,clazz,fieldID);
-    }
-
-    void SetStaticObjectField(jclass clazz, jfieldID fieldID,
-                        jobject value) {
-      functions->SetStaticObjectField(this,clazz,fieldID,value);
-    }
-    void SetStaticBooleanField(jclass clazz, jfieldID fieldID,
-                        jboolean value) {
-      functions->SetStaticBooleanField(this,clazz,fieldID,value);
-    }
-    void SetStaticByteField(jclass clazz, jfieldID fieldID,
-                        jbyte value) {
-      functions->SetStaticByteField(this,clazz,fieldID,value);
-    }
-    void SetStaticCharField(jclass clazz, jfieldID fieldID,
-                        jchar value) {
-      functions->SetStaticCharField(this,clazz,fieldID,value);
-    }
-    void SetStaticShortField(jclass clazz, jfieldID fieldID,
-                        jshort value) {
-      functions->SetStaticShortField(this,clazz,fieldID,value);
-    }
-    void SetStaticIntField(jclass clazz, jfieldID fieldID,
-                        jint value) {
-      functions->SetStaticIntField(this,clazz,fieldID,value);
-    }
-    void SetStaticLongField(jclass clazz, jfieldID fieldID,
-                        jlong value) {
-      functions->SetStaticLongField(this,clazz,fieldID,value);
-    }
-    void SetStaticFloatField(jclass clazz, jfieldID fieldID,
-                        jfloat value) {
-      functions->SetStaticFloatField(this,clazz,fieldID,value);
-    }
-    void SetStaticDoubleField(jclass clazz, jfieldID fieldID,
-                        jdouble value) {
-      functions->SetStaticDoubleField(this,clazz,fieldID,value);
-    }
-
-    jstring NewString(const jchar *unicode, jsize len) {
-        return functions->NewString(this,unicode,len);
-    }
-    jsize GetStringLength(jstring str) {
-        return functions->GetStringLength(this,str);
-    }
-    const jchar *GetStringChars(jstring str, jboolean *isCopy) {
-        return functions->GetStringChars(this,str,isCopy);
-    }
-    void ReleaseStringChars(jstring str, const jchar *chars) {
-        functions->ReleaseStringChars(this,str,chars);
-    }
-
-    jstring NewStringUTF(const char *utf) {
-        return functions->NewStringUTF(this,utf);
-    }
-    jsize GetStringUTFLength(jstring str) {
-        return functions->GetStringUTFLength(this,str);
-    }
-    const char* GetStringUTFChars(jstring str, jboolean *isCopy) {
-        return functions->GetStringUTFChars(this,str,isCopy);
-    }
-    void ReleaseStringUTFChars(jstring str, const char* chars) {
-        functions->ReleaseStringUTFChars(this,str,chars);
-    }
-
-    jsize GetArrayLength(jarray array) {
-        return functions->GetArrayLength(this,array);
-    }
-
-    jobjectArray NewObjectArray(jsize len, jclass clazz,
-                                jobject init) {
-        return functions->NewObjectArray(this,len,clazz,init);
-    }
-    jobject GetObjectArrayElement(jobjectArray array, jsize index) {
-        return functions->GetObjectArrayElement(this,array,index);
-    }
-    void SetObjectArrayElement(jobjectArray array, jsize index,
-                               jobject val) {
-        functions->SetObjectArrayElement(this,array,index,val);
-    }
-
-    jbooleanArray NewBooleanArray(jsize len) {
-        return functions->NewBooleanArray(this,len);
-    }
-    jbyteArray NewByteArray(jsize len) {
-        return functions->NewByteArray(this,len);
-    }
-    jcharArray NewCharArray(jsize len) {
-        return functions->NewCharArray(this,len);
-    }
-    jshortArray NewShortArray(jsize len) {
-        return functions->NewShortArray(this,len);
-    }
-    jintArray NewIntArray(jsize len) {
-        return functions->NewIntArray(this,len);
-    }
-    jlongArray NewLongArray(jsize len) {
-        return functions->NewLongArray(this,len);
-    }
-    jfloatArray NewFloatArray(jsize len) {
-        return functions->NewFloatArray(this,len);
-    }
-    jdoubleArray NewDoubleArray(jsize len) {
-        return functions->NewDoubleArray(this,len);
-    }
-
-    jboolean * GetBooleanArrayElements(jbooleanArray array, jboolean *isCopy) {
-        return functions->GetBooleanArrayElements(this,array,isCopy);
-    }
-    jbyte * GetByteArrayElements(jbyteArray array, jboolean *isCopy) {
-        return functions->GetByteArrayElements(this,array,isCopy);
-    }
-    jchar * GetCharArrayElements(jcharArray array, jboolean *isCopy) {
-        return functions->GetCharArrayElements(this,array,isCopy);
-    }
-    jshort * GetShortArrayElements(jshortArray array, jboolean *isCopy) {
-        return functions->GetShortArrayElements(this,array,isCopy);
-    }
-    jint * GetIntArrayElements(jintArray array, jboolean *isCopy) {
-        return functions->GetIntArrayElements(this,array,isCopy);
-    }
-    jlong * GetLongArrayElements(jlongArray array, jboolean *isCopy) {
-        return functions->GetLongArrayElements(this,array,isCopy);
-    }
-    jfloat * GetFloatArrayElements(jfloatArray array, jboolean *isCopy) {
-        return functions->GetFloatArrayElements(this,array,isCopy);
-    }
-    jdouble * GetDoubleArrayElements(jdoubleArray array, jboolean *isCopy) {
-        return functions->GetDoubleArrayElements(this,array,isCopy);
-    }
-
-    void ReleaseBooleanArrayElements(jbooleanArray array,
-                                     jboolean *elems,
-                                     jint mode) {
-        functions->ReleaseBooleanArrayElements(this,array,elems,mode);
-    }
-    void ReleaseByteArrayElements(jbyteArray array,
-                                  jbyte *elems,
-                                  jint mode) {
-        functions->ReleaseByteArrayElements(this,array,elems,mode);
-    }
-    void ReleaseCharArrayElements(jcharArray array,
-                                  jchar *elems,
-                                  jint mode) {
-        functions->ReleaseCharArrayElements(this,array,elems,mode);
-    }
-    void ReleaseShortArrayElements(jshortArray array,
-                                   jshort *elems,
-                                   jint mode) {
-        functions->ReleaseShortArrayElements(this,array,elems,mode);
-    }
-    void ReleaseIntArrayElements(jintArray array,
-                                 jint *elems,
-                                 jint mode) {
-        functions->ReleaseIntArrayElements(this,array,elems,mode);
-    }
-    void ReleaseLongArrayElements(jlongArray array,
-                                  jlong *elems,
-                                  jint mode) {
-        functions->ReleaseLongArrayElements(this,array,elems,mode);
-    }
-    void ReleaseFloatArrayElements(jfloatArray array,
-                                   jfloat *elems,
-                                   jint mode) {
-        functions->ReleaseFloatArrayElements(this,array,elems,mode);
-    }
-    void ReleaseDoubleArrayElements(jdoubleArray array,
-                                    jdouble *elems,
-                                    jint mode) {
-        functions->ReleaseDoubleArrayElements(this,array,elems,mode);
-    }
-
-    void GetBooleanArrayRegion(jbooleanArray array,
-                               jsize start, jsize len, jboolean *buf) {
-        functions->GetBooleanArrayRegion(this,array,start,len,buf);
-    }
-    void GetByteArrayRegion(jbyteArray array,
-                            jsize start, jsize len, jbyte *buf) {
-        functions->GetByteArrayRegion(this,array,start,len,buf);
-    }
-    void GetCharArrayRegion(jcharArray array,
-                            jsize start, jsize len, jchar *buf) {
-        functions->GetCharArrayRegion(this,array,start,len,buf);
-    }
-    void GetShortArrayRegion(jshortArray array,
-                             jsize start, jsize len, jshort *buf) {
-        functions->GetShortArrayRegion(this,array,start,len,buf);
-    }
-    void GetIntArrayRegion(jintArray array,
-                           jsize start, jsize len, jint *buf) {
-        functions->GetIntArrayRegion(this,array,start,len,buf);
-    }
-    void GetLongArrayRegion(jlongArray array,
-                            jsize start, jsize len, jlong *buf) {
-        functions->GetLongArrayRegion(this,array,start,len,buf);
-    }
-    void GetFloatArrayRegion(jfloatArray array,
-                             jsize start, jsize len, jfloat *buf) {
-        functions->GetFloatArrayRegion(this,array,start,len,buf);
-    }
-    void GetDoubleArrayRegion(jdoubleArray array,
-                              jsize start, jsize len, jdouble *buf) {
-        functions->GetDoubleArrayRegion(this,array,start,len,buf);
-    }
-
-    void SetBooleanArrayRegion(jbooleanArray array, jsize start, jsize len,
-                               const jboolean *buf) {
-        functions->SetBooleanArrayRegion(this,array,start,len,buf);
-    }
-    void SetByteArrayRegion(jbyteArray array, jsize start, jsize len,
-                            const jbyte *buf) {
-        functions->SetByteArrayRegion(this,array,start,len,buf);
-    }
-    void SetCharArrayRegion(jcharArray array, jsize start, jsize len,
-                            const jchar *buf) {
-        functions->SetCharArrayRegion(this,array,start,len,buf);
-    }
-    void SetShortArrayRegion(jshortArray array, jsize start, jsize len,
-                             const jshort *buf) {
-        functions->SetShortArrayRegion(this,array,start,len,buf);
-    }
-    void SetIntArrayRegion(jintArray array, jsize start, jsize len,
-                           const jint *buf) {
-        functions->SetIntArrayRegion(this,array,start,len,buf);
-    }
-    void SetLongArrayRegion(jlongArray array, jsize start, jsize len,
-                            const jlong *buf) {
-        functions->SetLongArrayRegion(this,array,start,len,buf);
-    }
-    void SetFloatArrayRegion(jfloatArray array, jsize start, jsize len,
-                             const jfloat *buf) {
-        functions->SetFloatArrayRegion(this,array,start,len,buf);
-    }
-    void SetDoubleArrayRegion(jdoubleArray array, jsize start, jsize len,
-                              const jdouble *buf) {
-        functions->SetDoubleArrayRegion(this,array,start,len,buf);
-    }
-
-    jint RegisterNatives(jclass clazz, const JNINativeMethod *methods,
-                         jint nMethods) {
-        return functions->RegisterNatives(this,clazz,methods,nMethods);
-    }
-    jint UnregisterNatives(jclass clazz) {
-        return functions->UnregisterNatives(this,clazz);
-    }
-
-    jint MonitorEnter(jobject obj) {
-        return functions->MonitorEnter(this,obj);
-    }
-    jint MonitorExit(jobject obj) {
-        return functions->MonitorExit(this,obj);
-    }
-
-    jint GetJavaVM(JavaVM **vm) {
-        return functions->GetJavaVM(this,vm);
-    }
-
-    void GetStringRegion(jstring str, jsize start, jsize len, jchar *buf) {
-        functions->GetStringRegion(this,str,start,len,buf);
-    }
-    void GetStringUTFRegion(jstring str, jsize start, jsize len, char *buf) {
-        functions->GetStringUTFRegion(this,str,start,len,buf);
-    }
-
-    void * GetPrimitiveArrayCritical(jarray array, jboolean *isCopy) {
-        return functions->GetPrimitiveArrayCritical(this,array,isCopy);
-    }
-    void ReleasePrimitiveArrayCritical(jarray array, void *carray, jint mode) {
-        functions->ReleasePrimitiveArrayCritical(this,array,carray,mode);
-    }
-
-    const jchar * GetStringCritical(jstring string, jboolean *isCopy) {
-        return functions->GetStringCritical(this,string,isCopy);
-    }
-    void ReleaseStringCritical(jstring string, const jchar *cstring) {
-        functions->ReleaseStringCritical(this,string,cstring);
-    }
-
-    jweak NewWeakGlobalRef(jobject obj) {
-        return functions->NewWeakGlobalRef(this,obj);
-    }
-    void DeleteWeakGlobalRef(jweak ref) {
-        functions->DeleteWeakGlobalRef(this,ref);
-    }
-
-    jboolean ExceptionCheck() {
-        return functions->ExceptionCheck(this);
-    }
-
-    jobject NewDirectByteBuffer(void* address, jlong capacity) {
-        return functions->NewDirectByteBuffer(this, address, capacity);
-    }
-    void* GetDirectBufferAddress(jobject buf) {
-        return functions->GetDirectBufferAddress(this, buf);
-    }
-    jlong GetDirectBufferCapacity(jobject buf) {
-        return functions->GetDirectBufferCapacity(this, buf);
-    }
-    jobjectRefType GetObjectRefType(jobject obj) {
-        return functions->GetObjectRefType(this, obj);
-    }
-
-    /* Module Features */
-
-    jobject GetModule(jclass clazz) {
-        return functions->GetModule(this, clazz);
-    }
-
-#endif /* __cplusplus */
-};
-
-typedef struct JavaVMOption {
-    char *optionString;
-    void *extraInfo;
-} JavaVMOption;
-
-typedef struct JavaVMInitArgs {
-    jint version;
-
-    jint nOptions;
-    JavaVMOption *options;
-    jboolean ignoreUnrecognized;
-} JavaVMInitArgs;
-
-typedef struct JavaVMAttachArgs {
-    jint version;
-
-    char *name;
-    jobject group;
-} JavaVMAttachArgs;
-
-/* These will be VM-specific. */
-
-#define JDK1_2
-#define JDK1_4
-
-/* End VM-specific. */
-
-struct JNIInvokeInterface_ {
-    void *reserved0;
-    void *reserved1;
-    void *reserved2;
-
-    jint (JNICALL *DestroyJavaVM)(JavaVM *vm);
-
-    jint (JNICALL *AttachCurrentThread)(JavaVM *vm, void **penv, void *args);
-
-    jint (JNICALL *DetachCurrentThread)(JavaVM *vm);
-
-    jint (JNICALL *GetEnv)(JavaVM *vm, void **penv, jint version);
-
-    jint (JNICALL *AttachCurrentThreadAsDaemon)(JavaVM *vm, void **penv, void *args);
-};
-
-struct JavaVM_ {
-    const struct JNIInvokeInterface_ *functions;
-#ifdef __cplusplus
-
-    jint DestroyJavaVM() {
-        return functions->DestroyJavaVM(this);
-    }
-    jint AttachCurrentThread(void **penv, void *args) {
-        return functions->AttachCurrentThread(this, penv, args);
-    }
-    jint DetachCurrentThread() {
-        return functions->DetachCurrentThread(this);
-    }
-
-    jint GetEnv(void **penv, jint version) {
-        return functions->GetEnv(this, penv, version);
-    }
-    jint AttachCurrentThreadAsDaemon(void **penv, void *args) {
-        return functions->AttachCurrentThreadAsDaemon(this, penv, args);
-    }
-#endif
-};
-
-#ifdef _JNI_IMPLEMENTATION_
-#define _JNI_IMPORT_OR_EXPORT_ JNIEXPORT
-#else
-#define _JNI_IMPORT_OR_EXPORT_ JNIIMPORT
-#endif
-_JNI_IMPORT_OR_EXPORT_ jint JNICALL
-JNI_GetDefaultJavaVMInitArgs(void *args);
-
-_JNI_IMPORT_OR_EXPORT_ jint JNICALL
-JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args);
-
-_JNI_IMPORT_OR_EXPORT_ jint JNICALL
-JNI_GetCreatedJavaVMs(JavaVM **, jsize, jsize *);
-
-/* Defined by native libraries. */
-JNIEXPORT jint JNICALL
-JNI_OnLoad(JavaVM *vm, void *reserved);
-
-JNIEXPORT void JNICALL
-JNI_OnUnload(JavaVM *vm, void *reserved);
-
-#define JNI_VERSION_1_1 0x00010001
-#define JNI_VERSION_1_2 0x00010002
-#define JNI_VERSION_1_4 0x00010004
-#define JNI_VERSION_1_6 0x00010006
-#define JNI_VERSION_1_8 0x00010008
-#define JNI_VERSION_9   0x00090000
-#define JNI_VERSION_10  0x000a0000
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif /* __cplusplus */
-
-#endif /* !_JAVASOFT_JNI_H_ */
--- a/src/hotspot/share/prims/jniCheck.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/jniCheck.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jni.h"
 #include "classfile/javaClasses.inline.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
@@ -30,7 +31,6 @@
 #include "oops/instanceKlass.hpp"
 #include "oops/oop.inline.hpp"
 #include "oops/symbol.hpp"
-#include "prims/jni.h"
 #include "prims/jniCheck.hpp"
 #include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
--- a/src/hotspot/share/prims/jniExport.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/jniExport.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, 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
@@ -25,7 +25,7 @@
 #ifndef SHARE_VM_PRIMS_JNI_EXPORT_HPP
 #define SHARE_VM_PRIMS_JNI_EXPORT_HPP
 
-#include "prims/jni.h"
+#include "jni.h"
 #include "prims/jvmtiExport.hpp"
 
 class JniExportedInterface {
--- a/src/hotspot/share/prims/jvm.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/jvm.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -669,7 +669,6 @@
 
   // Store check (mark entire object and let gc sort it out)
   BarrierSet* bs = Universe::heap()->barrier_set();
-  assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
   bs->write_region(MemRegion((HeapWord*)new_obj_oop, size));
 
   Handle new_obj(THREAD, new_obj_oop);
--- a/src/hotspot/share/prims/jvm.h	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/jvm.h	Sat Oct 21 00:06:50 2017 +0000
@@ -25,7 +25,7 @@
 #ifndef SHARE_VM_PRIMS_JVM_H
 #define SHARE_VM_PRIMS_JVM_H
 
-#include "prims/jni.h"
+#include "jni.h"
 #include "utilities/macros.hpp"
 
 #include OS_HEADER_H(jvm)
--- a/src/hotspot/share/prims/jvm_misc.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/jvm_misc.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, 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
@@ -25,7 +25,7 @@
 #ifndef SHARE_VM_PRIMS_JVM_MISC_HPP
 #define SHARE_VM_PRIMS_JVM_MISC_HPP
 
-#include "prims/jni.h"
+#include "jni.h"
 #include "runtime/handles.hpp"
 
 // Useful entry points shared by JNI and JVM interface.
--- a/src/hotspot/share/prims/jvmtiExport.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/jvmtiExport.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -37,7 +37,7 @@
 #include "utilities/macros.hpp"
 
 // Must be included after jvmti.h.
-#include "code/jvmticmlr.h"
+#include "jvmticmlr.h"
 
 // Forward declarations
 
--- a/src/hotspot/share/prims/jvmtiRawMonitor.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/jvmtiRawMonitor.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -127,7 +127,7 @@
 
 int JvmtiRawMonitor::SimpleEnter (Thread * Self) {
   for (;;) {
-    if (Atomic::cmpxchg_ptr (Self, &_owner, NULL) == NULL) {
+    if (Atomic::cmpxchg(Self, &_owner, (void*)NULL) == NULL) {
        return OS_OK ;
     }
 
@@ -139,7 +139,7 @@
     Node._next  = _EntryList ;
     _EntryList  = &Node ;
     OrderAccess::fence() ;
-    if (_owner == NULL && Atomic::cmpxchg_ptr (Self, &_owner, NULL) == NULL) {
+    if (_owner == NULL && Atomic::cmpxchg(Self, &_owner, (void*)NULL) == NULL) {
         _EntryList = Node._next ;
         RawMonitor_lock->unlock() ;
         return OS_OK ;
@@ -153,7 +153,7 @@
 
 int JvmtiRawMonitor::SimpleExit (Thread * Self) {
   guarantee (_owner == Self, "invariant") ;
-  OrderAccess::release_store_ptr (&_owner, NULL) ;
+  OrderAccess::release_store(&_owner, (void*)NULL) ;
   OrderAccess::fence() ;
   if (_EntryList == NULL) return OS_OK ;
   ObjectWaiter * w ;
@@ -277,10 +277,10 @@
       jt->SR_lock()->lock_without_safepoint_check();
     }
     // guarded by SR_lock to avoid racing with new external suspend requests.
-    Contended = Atomic::cmpxchg_ptr (THREAD, &_owner, NULL) ;
+    Contended = Atomic::cmpxchg(THREAD, &_owner, (void*)NULL);
     jt->SR_lock()->unlock();
   } else {
-    Contended = Atomic::cmpxchg_ptr (THREAD, &_owner, NULL) ;
+    Contended = Atomic::cmpxchg(THREAD, &_owner, (void*)NULL);
   }
 
   if (Contended == THREAD) {
--- a/src/hotspot/share/prims/perf.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/perf.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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,11 +23,11 @@
  */
 
 #include "precompiled.hpp"
+#include "jni.h"
 #include "classfile/vmSymbols.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/oop.inline.hpp"
-#include "prims/jni.h"
 #include "prims/jvm.h"
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/perfData.hpp"
--- a/src/hotspot/share/prims/unsafe.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/unsafe.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jni.h"
 #include "classfile/classFileStream.hpp"
 #include "classfile/vmSymbols.hpp"
 #include "memory/allocation.inline.hpp"
@@ -30,7 +31,6 @@
 #include "oops/fieldStreams.hpp"
 #include "oops/objArrayOop.inline.hpp"
 #include "oops/oop.inline.hpp"
-#include "prims/jni.h"
 #include "prims/jvm.h"
 #include "prims/unsafe.hpp"
 #include "runtime/atomic.hpp"
--- a/src/hotspot/share/prims/wbtestmethods/parserTests.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/wbtestmethods/parserTests.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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,12 +23,12 @@
  */
 
 #include "precompiled.hpp"
+#include "jni.h"
 #include "classfile/javaClasses.inline.hpp"
 #include "classfile/symbolTable.hpp"
 #include "memory/oopFactory.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/objArrayOop.inline.hpp"
-#include "prims/jni.h"
 #include "prims/whitebox.hpp"
 #include "prims/wbtestmethods/parserTests.hpp"
 #include "runtime/interfaceSupport.hpp"
--- a/src/hotspot/share/prims/wbtestmethods/parserTests.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/wbtestmethods/parserTests.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -24,7 +24,7 @@
 #ifndef SHARE_VM_PRIMS_WBTESTMETHODS_PARSERTESTS_H
 #define SHARE_VM_PRIMS_WBTESTMETHODS_PARSERTESTS_H
 
-#include "prims/jni.h"
+#include "jni.h"
 #include "prims/whitebox.hpp"
 
 WB_METHOD_DECLARE(jobjectArray) WB_ParseCommandLine(JNIEnv* env, jobject o, jstring args, jchar delim, jobjectArray arguments);
--- a/src/hotspot/share/prims/whitebox.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/prims/whitebox.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -25,7 +25,7 @@
 #ifndef SHARE_VM_PRIMS_WHITEBOX_HPP
 #define SHARE_VM_PRIMS_WHITEBOX_HPP
 
-#include "prims/jni.h"
+#include "jni.h"
 
 #include "utilities/exceptions.hpp"
 #include "memory/allocation.hpp"
--- a/src/hotspot/share/runtime/atomic.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/atomic.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -70,14 +70,6 @@
   template<typename T, typename D>
   inline static void store(T store_value, volatile D* dest);
 
-  inline static void store_ptr(intptr_t store_value, volatile intptr_t* dest) {
-    Atomic::store(store_value, dest);
-  }
-
-  inline static void store_ptr(void*    store_value, volatile void*     dest) {
-    Atomic::store(store_value, reinterpret_cast<void* volatile*>(dest));
-  }
-
   // Atomically load from a location
   // The type T must be either a pointer type, an integral/enum type,
   // or a type that is primitive convertible using PrimitiveConversions.
@@ -90,13 +82,8 @@
   template<typename I, typename D>
   inline static D add(I add_value, D volatile* dest);
 
-  inline static intptr_t add_ptr(intptr_t add_value, volatile intptr_t* dest) {
-    return add(add_value, dest);
-  }
-
-  inline static void* add_ptr(intptr_t add_value, volatile void* dest) {
-    return add(add_value, reinterpret_cast<char* volatile*>(dest));
-  }
+  template<typename I, typename D>
+  inline static D sub(I sub_value, D volatile* dest);
 
   // Atomically increment location. inc() provide:
   // <fence> increment-dest <membar StoreLoad|StoreStore>
@@ -123,14 +110,6 @@
   template<typename T, typename D>
   inline static D xchg(T exchange_value, volatile D* dest);
 
-  inline static intptr_t xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
-    return xchg(exchange_value, dest);
-  }
-
-  inline static void*    xchg_ptr(void*    exchange_value, volatile void*     dest) {
-    return xchg(exchange_value, reinterpret_cast<void* volatile*>(dest));
-  }
-
   // Performs atomic compare of *dest and compare_value, and exchanges
   // *dest with exchange_value if the comparison succeeded. Returns prior
   // value of *dest. cmpxchg*() provide:
@@ -151,23 +130,6 @@
   inline static bool replace_if_null(T* value, D* volatile* dest,
                                      cmpxchg_memory_order order = memory_order_conservative);
 
-  inline static intptr_t cmpxchg_ptr(intptr_t exchange_value,
-                                     volatile intptr_t* dest,
-                                     intptr_t compare_value,
-                                     cmpxchg_memory_order order = memory_order_conservative) {
-    return cmpxchg(exchange_value, dest, compare_value, order);
-  }
-
-  inline static void* cmpxchg_ptr(void* exchange_value,
-                                  volatile void* dest,
-                                  void* compare_value,
-                                  cmpxchg_memory_order order = memory_order_conservative) {
-    return cmpxchg(exchange_value,
-                   reinterpret_cast<void* volatile*>(dest),
-                   compare_value,
-                   order);
-  }
-
 private:
   // Test whether From is implicitly convertible to To.
   // From and To must be pointer types.
@@ -555,6 +517,23 @@
   Atomic::add(I(-1), dest);
 }
 
+template<typename I, typename D>
+inline D Atomic::sub(I sub_value, D volatile* dest) {
+  STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value);
+  STATIC_ASSERT(IsIntegral<I>::value);
+  // If D is a pointer type, use [u]intptr_t as the addend type,
+  // matching signedness of I.  Otherwise, use D as the addend type.
+  typedef typename Conditional<IsSigned<I>::value, intptr_t, uintptr_t>::type PI;
+  typedef typename Conditional<IsPointer<D>::value, PI, D>::type AddendType;
+  // Only allow conversions that can't change the value.
+  STATIC_ASSERT(IsSigned<I>::value == IsSigned<AddendType>::value);
+  STATIC_ASSERT(sizeof(I) <= sizeof(AddendType));
+  AddendType addend = sub_value;
+  // Assumes two's complement integer representation.
+  #pragma warning(suppress: 4146) // In case AddendType is not signed.
+  return Atomic::add(-addend, dest);
+}
+
 // Define the class before including platform file, which may specialize
 // the operator definition.  No generic definition of specializations
 // of the operator template are provided, nor are there any generic
--- a/src/hotspot/share/runtime/biasedLocking.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/biasedLocking.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -35,6 +35,7 @@
 #include "runtime/vframe.hpp"
 #include "runtime/vmThread.hpp"
 #include "runtime/vm_operations.hpp"
+#include "trace/tracing.hpp"
 
 static bool _biased_locking_enabled = false;
 BiasedLockingCounters BiasedLocking::_counters;
@@ -643,23 +644,43 @@
       // stale epoch.
       ResourceMark rm;
       log_info(biasedlocking)("Revoking bias by walking my own stack:");
+      EventBiasedLockSelfRevocation event;
       BiasedLocking::Condition cond = revoke_bias(obj(), false, false, (JavaThread*) THREAD);
       ((JavaThread*) THREAD)->set_cached_monitor_info(NULL);
       assert(cond == BIAS_REVOKED, "why not?");
+      if (event.should_commit()) {
+        event.set_lockClass(k);
+        event.commit();
+      }
       return cond;
     } else {
+      EventBiasedLockRevocation event;
       VM_RevokeBias revoke(&obj, (JavaThread*) THREAD);
       VMThread::execute(&revoke);
+      if (event.should_commit() && (revoke.status_code() != NOT_BIASED)) {
+        event.set_lockClass(k);
+        // Subtract 1 to match the id of events committed inside the safepoint
+        event.set_safepointId(SafepointSynchronize::safepoint_counter() - 1);
+        event.commit();
+      }
       return revoke.status_code();
     }
   }
 
   assert((heuristics == HR_BULK_REVOKE) ||
          (heuristics == HR_BULK_REBIAS), "?");
+  EventBiasedLockClassRevocation event;
   VM_BulkRevokeBias bulk_revoke(&obj, (JavaThread*) THREAD,
                                 (heuristics == HR_BULK_REBIAS),
                                 attempt_rebias);
   VMThread::execute(&bulk_revoke);
+  if (event.should_commit()) {
+    event.set_revokedClass(obj->klass());
+    event.set_disableBiasing((heuristics != HR_BULK_REBIAS));
+    // Subtract 1 to match the id of events committed inside the safepoint
+    event.set_safepointId(SafepointSynchronize::safepoint_counter() - 1);
+    event.commit();
+  }
   return bulk_revoke.status_code();
 }
 
--- a/src/hotspot/share/runtime/frame.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/frame.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -627,16 +627,9 @@
     st->print("  " PTR_FORMAT, p2i(pc));
   }
 
-  // function name - os::dll_address_to_function_name() may return confusing
-  // names if pc is within jvm.dll or libjvm.so, because JVM only has
-  // JVM_xxxx and a few other symbols in the dynamic symbol table. Do this
-  // only for native libraries.
-  if (!in_vm || Decoder::can_decode_C_frame_in_vm()) {
-    found = os::dll_address_to_function_name(pc, buf, buflen, &offset);
-
-    if (found) {
-      st->print("  %s+0x%x", buf, offset);
-    }
+  found = os::dll_address_to_function_name(pc, buf, buflen, &offset);
+  if (found) {
+    st->print("  %s+0x%x", buf, offset);
   }
 }
 
--- a/src/hotspot/share/runtime/jniHandles.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/jniHandles.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -27,7 +27,6 @@
 #include "logging/log.hpp"
 #include "memory/iterator.hpp"
 #include "oops/oop.inline.hpp"
-#include "prims/jvmtiExport.hpp"
 #include "runtime/jniHandles.hpp"
 #include "runtime/mutexLocker.hpp"
 #include "runtime/thread.inline.hpp"
@@ -424,12 +423,6 @@
       break;
     }
   }
-
-  /*
-   * JVMTI data structures may also contain weak oops.  The iteration of them
-   * is placed here so that we don't need to add it to each of the collectors.
-   */
-  JvmtiExport::weak_oops_do(is_alive, f);
 }
 
 
--- a/src/hotspot/share/runtime/mutex.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/mutex.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -251,12 +251,6 @@
 //
 // o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
 
-
-// CASPTR() uses the canonical argument order that dominates in the literature.
-// Our internal cmpxchg_ptr() uses a bastardized ordering to accommodate Sun .il templates.
-
-#define CASPTR(a, c, s)  \
-  intptr_t(Atomic::cmpxchg_ptr((void *)(s), (void *)(a), (void *)(c)))
 #define UNS(x) (uintptr_t(x))
 #define TRACE(m)                   \
   {                                \
@@ -268,6 +262,15 @@
     }                              \
   }
 
+const intptr_t _LBIT = 1;
+
+// Endian-ness ... index of least-significant byte in SplitWord.Bytes[]
+#ifdef VM_LITTLE_ENDIAN
+ #define _LSBINDEX 0
+#else
+ #define _LSBINDEX (sizeof(intptr_t)-1)
+#endif
+
 // Simplistic low-quality Marsaglia SHIFT-XOR RNG.
 // Bijective except for the trailing mask operation.
 // Useful for spin loops as the compiler can't optimize it away.
@@ -297,7 +300,7 @@
   intptr_t v = _LockWord.FullWord;
   for (;;) {
     if ((v & _LBIT) != 0) return 0;
-    const intptr_t u = CASPTR(&_LockWord, v, v|_LBIT);
+    const intptr_t u = Atomic::cmpxchg(v|_LBIT, &_LockWord.FullWord, v);
     if (v == u) return 1;
     v = u;
   }
@@ -307,12 +310,12 @@
   // Optimistic fast-path form ...
   // Fast-path attempt for the common uncontended case.
   // Avoid RTS->RTO $ coherence upgrade on typical SMP systems.
-  intptr_t v = CASPTR(&_LockWord, 0, _LBIT);  // agro ...
+  intptr_t v = Atomic::cmpxchg(_LBIT, &_LockWord.FullWord, (intptr_t)0);  // agro ...
   if (v == 0) return 1;
 
   for (;;) {
     if ((v & _LBIT) != 0) return 0;
-    const intptr_t u = CASPTR(&_LockWord, v, v|_LBIT);
+    const intptr_t u = Atomic::cmpxchg(v|_LBIT, &_LockWord.FullWord, v);
     if (v == u) return 1;
     v = u;
   }
@@ -350,7 +353,7 @@
   for (;;) {
     intptr_t v = _LockWord.FullWord;
     if ((v & _LBIT) == 0) {
-      if (CASPTR (&_LockWord, v, v|_LBIT) == v) {
+      if (Atomic::cmpxchg (v|_LBIT, &_LockWord.FullWord, v) == v) {
         return 1;
       }
       continue;
@@ -419,13 +422,13 @@
   intptr_t v = _LockWord.FullWord;
   for (;;) {
     if ((v & _LBIT) == 0) {
-      const intptr_t u = CASPTR(&_LockWord, v, v|_LBIT);
+      const intptr_t u = Atomic::cmpxchg(v|_LBIT, &_LockWord.FullWord, v);
       if (u == v) return 1;        // indicate acquired
       v = u;
     } else {
       // Anticipate success ...
       ESelf->ListNext = (ParkEvent *)(v & ~_LBIT);
-      const intptr_t u = CASPTR(&_LockWord, v, intptr_t(ESelf)|_LBIT);
+      const intptr_t u = Atomic::cmpxchg(intptr_t(ESelf)|_LBIT, &_LockWord.FullWord, v);
       if (u == v) return 0;        // indicate pushed onto cxq
       v = u;
     }
@@ -463,7 +466,7 @@
   OrderAccess::fence();
 
   // Optional optimization ... try barging on the inner lock
-  if ((NativeMonitorFlags & 32) && CASPTR (&_OnDeck, NULL, UNS(ESelf)) == 0) {
+  if ((NativeMonitorFlags & 32) && Atomic::cmpxchg(ESelf, &_OnDeck, (ParkEvent*)NULL) == NULL) {
     goto OnDeck_LOOP;
   }
 
@@ -474,7 +477,7 @@
   // Only the OnDeck thread can try to acquire -- contend for -- the lock.
   // CONSIDER: use Self->OnDeck instead of m->OnDeck.
   // Deschedule Self so that others may run.
-  while (OrderAccess::load_ptr_acquire(&_OnDeck) != ESelf) {
+  while (OrderAccess::load_acquire(&_OnDeck) != ESelf) {
     ParkCommon(ESelf, 0);
   }
 
@@ -570,7 +573,7 @@
   // Unlike a normal lock, however, the exiting thread "locks" OnDeck,
   // picks a successor and marks that thread as OnDeck.  That successor
   // thread will then clear OnDeck once it eventually acquires the outer lock.
-  if (CASPTR (&_OnDeck, NULL, _LBIT) != UNS(NULL)) {
+  if (Atomic::cmpxchg((ParkEvent*)_LBIT, &_OnDeck, (ParkEvent*)NULL) != NULL) {
     return;
   }
 
@@ -585,14 +588,14 @@
     assert(RelaxAssert || w != Thread::current()->_MutexEvent, "invariant");
     _EntryList = w->ListNext;
     // as a diagnostic measure consider setting w->_ListNext = BAD
-    assert(UNS(_OnDeck) == _LBIT, "invariant");
+    assert(intptr_t(_OnDeck) == _LBIT, "invariant");
 
     // Pass OnDeck role to w, ensuring that _EntryList has been set first.
     // w will clear _OnDeck once it acquires the outer lock.
     // Note that once we set _OnDeck that thread can acquire the mutex, proceed
     // with its critical section and then enter this code to unlock the mutex. So
     // you can have multiple threads active in IUnlock at the same time.
-    OrderAccess::release_store_ptr(&_OnDeck, w);
+    OrderAccess::release_store(&_OnDeck, w);
 
     // Another optional optimization ...
     // For heavily contended locks it's not uncommon that some other
@@ -616,7 +619,7 @@
     for (;;) {
       // optional optimization - if locked, the owner is responsible for succession
       if (cxq & _LBIT) goto Punt;
-      const intptr_t vfy = CASPTR(&_LockWord, cxq, cxq & _LBIT);
+      const intptr_t vfy = Atomic::cmpxchg(cxq & _LBIT, &_LockWord.FullWord, cxq);
       if (vfy == cxq) break;
       cxq = vfy;
       // Interference - LockWord changed - Just retry
@@ -652,7 +655,7 @@
   // A thread could have added itself to cxq since this thread previously checked.
   // Detect and recover by refetching cxq.
  Punt:
-  assert(UNS(_OnDeck) == _LBIT, "invariant");
+  assert(intptr_t(_OnDeck) == _LBIT, "invariant");
   _OnDeck = NULL;            // Release inner lock.
   OrderAccess::storeload();   // Dekker duality - pivot point
 
@@ -693,7 +696,7 @@
       const intptr_t v = _LockWord.FullWord;
       assert((v & 0xFF) == _LBIT, "invariant");
       nfy->ListNext = (ParkEvent *)(v & ~_LBIT);
-      if (CASPTR (&_LockWord, v, UNS(nfy)|_LBIT) == v) break;
+      if (Atomic::cmpxchg(intptr_t(nfy)|_LBIT, &_LockWord.FullWord, v) == v) break;
       // interference - _LockWord changed -- just retry
     }
     // Note that setting Notified before pushing nfy onto the cxq is
@@ -840,7 +843,7 @@
     // ESelf is now on the cxq, EntryList or at the OnDeck position.
     // The following fragment is extracted from Monitor::ILock()
     for (;;) {
-      if (OrderAccess::load_ptr_acquire(&_OnDeck) == ESelf && TrySpin(Self)) break;
+      if (OrderAccess::load_acquire(&_OnDeck) == ESelf && TrySpin(Self)) break;
       ParkCommon(ESelf, 0);
     }
     assert(_OnDeck == ESelf, "invariant");
@@ -1058,7 +1061,7 @@
   // Only the OnDeck thread can try to acquire -- contend for -- the lock.
   // CONSIDER: use Self->OnDeck instead of m->OnDeck.
   for (;;) {
-    if (OrderAccess::load_ptr_acquire(&_OnDeck) == ESelf && TrySpin(NULL)) break;
+    if (OrderAccess::load_acquire(&_OnDeck) == ESelf && TrySpin(NULL)) break;
     ParkCommon(ESelf, 0);
   }
 
--- a/src/hotspot/share/runtime/mutex.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/mutex.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -67,13 +67,6 @@
   volatile jbyte Bytes [sizeof(intptr_t)] ;
 } ;
 
-// Endian-ness ... index of least-significant byte in SplitWord.Bytes[]
-#ifdef VM_LITTLE_ENDIAN
- #define _LSBINDEX 0
-#else
- #define _LSBINDEX (sizeof(intptr_t)-1)
-#endif
-
 class ParkEvent ;
 
 // See orderAccess.hpp.  We assume throughout the VM that mutex lock and
@@ -128,7 +121,6 @@
 
  protected:                              // Monitor-Mutex metadata
   SplitWord _LockWord ;                  // Contention queue (cxq) colocated with Lock-byte
-  enum LockWordBits { _LBIT=1 } ;
   Thread * volatile _owner;              // The owner of the lock
                                          // Consider sequestering _owner on its own $line
                                          // to aid future synchronization mechanisms.
--- a/src/hotspot/share/runtime/objectMonitor.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/objectMonitor.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -249,7 +249,7 @@
   // and to reduce RTS->RTO cache line upgrades on SPARC and IA32 processors.
   Thread * const Self = THREAD;
 
-  void * cur = Atomic::cmpxchg_ptr (Self, &_owner, NULL);
+  void * cur = Atomic::cmpxchg(Self, &_owner, (void*)NULL);
   if (cur == NULL) {
     // Either ASSERT _recursions == 0 or explicitly set _recursions = 0.
     assert(_recursions == 0, "invariant");
@@ -406,7 +406,7 @@
 int ObjectMonitor::TryLock(Thread * Self) {
   void * own = _owner;
   if (own != NULL) return 0;
-  if (Atomic::cmpxchg_ptr (Self, &_owner, NULL) == NULL) {
+  if (Atomic::cmpxchg(Self, &_owner, (void*)NULL) == NULL) {
     // Either guarantee _recursions == 0 or set _recursions = 0.
     assert(_recursions == 0, "invariant");
     assert(_owner == Self, "invariant");
@@ -476,7 +476,7 @@
   ObjectWaiter * nxt;
   for (;;) {
     node._next = nxt = _cxq;
-    if (Atomic::cmpxchg_ptr(&node, &_cxq, nxt) == nxt) break;
+    if (Atomic::cmpxchg(&node, &_cxq, nxt) == nxt) break;
 
     // Interference - the CAS failed because _cxq changed.  Just retry.
     // As an optional optimization we retry the lock.
@@ -514,7 +514,7 @@
   if ((SyncFlags & 16) == 0 && nxt == NULL && _EntryList == NULL) {
     // Try to assume the role of responsible thread for the monitor.
     // CONSIDER:  ST vs CAS vs { if (Responsible==null) Responsible=Self }
-    Atomic::cmpxchg_ptr(Self, &_Responsible, NULL);
+    Atomic::cmpxchg(Self, &_Responsible, (Thread*)NULL);
   }
 
   // The lock might have been released while this thread was occupied queueing
@@ -538,7 +538,7 @@
     assert(_owner != Self, "invariant");
 
     if ((SyncFlags & 2) && _Responsible == NULL) {
-      Atomic::cmpxchg_ptr(Self, &_Responsible, NULL);
+      Atomic::cmpxchg(Self, &_Responsible, (Thread*)NULL);
     }
 
     // park self
@@ -795,7 +795,7 @@
 
     ObjectWaiter * v = _cxq;
     assert(v != NULL, "invariant");
-    if (v != SelfNode || Atomic::cmpxchg_ptr (SelfNode->_next, &_cxq, v) != v) {
+    if (v != SelfNode || Atomic::cmpxchg(SelfNode->_next, &_cxq, v) != v) {
       // The CAS above can fail from interference IFF a "RAT" arrived.
       // In that case Self must be in the interior and can no longer be
       // at the head of cxq.
@@ -947,7 +947,7 @@
       // in massive wasteful coherency traffic on classic SMP systems.
       // Instead, I use release_store(), which is implemented as just a simple
       // ST on x64, x86 and SPARC.
-      OrderAccess::release_store_ptr(&_owner, NULL);   // drop the lock
+      OrderAccess::release_store(&_owner, (void*)NULL);   // drop the lock
       OrderAccess::storeload();                        // See if we need to wake a successor
       if ((intptr_t(_EntryList)|intptr_t(_cxq)) == 0 || _succ != NULL) {
         TEVENT(Inflated exit - simple egress);
@@ -992,13 +992,13 @@
       // to reacquire the lock the responsibility for ensuring succession
       // falls to the new owner.
       //
-      if (Atomic::cmpxchg_ptr (THREAD, &_owner, NULL) != NULL) {
+      if (Atomic::cmpxchg(THREAD, &_owner, (void*)NULL) != NULL) {
         return;
       }
       TEVENT(Exit - Reacquired);
     } else {
       if ((intptr_t(_EntryList)|intptr_t(_cxq)) == 0 || _succ != NULL) {
-        OrderAccess::release_store_ptr(&_owner, NULL);   // drop the lock
+        OrderAccess::release_store(&_owner, (void*)NULL);   // drop the lock
         OrderAccess::storeload();
         // Ratify the previously observed values.
         if (_cxq == NULL || _succ != NULL) {
@@ -1017,7 +1017,7 @@
         // B.  If the elements forming the EntryList|cxq are TSM
         //     we could simply unpark() the lead thread and return
         //     without having set _succ.
-        if (Atomic::cmpxchg_ptr (THREAD, &_owner, NULL) != NULL) {
+        if (Atomic::cmpxchg(THREAD, &_owner, (void*)NULL) != NULL) {
           TEVENT(Inflated exit - reacquired succeeded);
           return;
         }
@@ -1052,7 +1052,7 @@
       w = _cxq;
       for (;;) {
         assert(w != NULL, "Invariant");
-        ObjectWaiter * u = (ObjectWaiter *) Atomic::cmpxchg_ptr(NULL, &_cxq, w);
+        ObjectWaiter * u = Atomic::cmpxchg((ObjectWaiter*)NULL, &_cxq, w);
         if (u == w) break;
         w = u;
       }
@@ -1093,7 +1093,7 @@
       w = _cxq;
       for (;;) {
         assert(w != NULL, "Invariant");
-        ObjectWaiter * u = (ObjectWaiter *) Atomic::cmpxchg_ptr(NULL, &_cxq, w);
+        ObjectWaiter * u = Atomic::cmpxchg((ObjectWaiter*)NULL, &_cxq, w);
         if (u == w) break;
         w = u;
       }
@@ -1146,7 +1146,7 @@
     // The following loop is tantamount to: w = swap(&cxq, NULL)
     for (;;) {
       assert(w != NULL, "Invariant");
-      ObjectWaiter * u = (ObjectWaiter *) Atomic::cmpxchg_ptr(NULL, &_cxq, w);
+      ObjectWaiter * u = Atomic::cmpxchg((ObjectWaiter*)NULL, &_cxq, w);
       if (u == w) break;
       w = u;
     }
@@ -1279,7 +1279,7 @@
   Wakee  = NULL;
 
   // Drop the lock
-  OrderAccess::release_store_ptr(&_owner, NULL);
+  OrderAccess::release_store(&_owner, (void*)NULL);
   OrderAccess::fence();                               // ST _owner vs LD in unpark()
 
   if (SafepointSynchronize::do_call_back()) {
@@ -1688,7 +1688,7 @@
         for (;;) {
           ObjectWaiter * front = _cxq;
           iterator->_next = front;
-          if (Atomic::cmpxchg_ptr(iterator, &_cxq, front) == front) {
+          if (Atomic::cmpxchg(iterator, &_cxq, front) == front) {
             break;
           }
         }
@@ -1699,7 +1699,7 @@
         ObjectWaiter * tail = _cxq;
         if (tail == NULL) {
           iterator->_next = NULL;
-          if (Atomic::cmpxchg_ptr(iterator, &_cxq, NULL) == NULL) {
+          if (Atomic::cmpxchg(iterator, &_cxq, (ObjectWaiter*)NULL) == NULL) {
             break;
           }
         } else {
@@ -1980,7 +1980,7 @@
 
     Thread * ox = (Thread *) _owner;
     if (ox == NULL) {
-      ox = (Thread *) Atomic::cmpxchg_ptr(Self, &_owner, NULL);
+      ox = (Thread*)Atomic::cmpxchg(Self, &_owner, (void*)NULL);
       if (ox == NULL) {
         // The CAS succeeded -- this thread acquired ownership
         // Take care of some bookkeeping to exit spin state.
--- a/src/hotspot/share/runtime/objectMonitor.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/objectMonitor.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -143,7 +143,7 @@
   volatile markOop   _header;       // displaced object header word - mark
   void*     volatile _object;       // backward object pointer - strong root
  public:
-  ObjectMonitor *    FreeNext;      // Free list linkage
+  ObjectMonitor*     FreeNext;      // Free list linkage
  private:
   DEFINE_PAD_MINUS_SIZE(0, DEFAULT_CACHE_LINE_SIZE,
                         sizeof(volatile markOop) + sizeof(void * volatile) +
@@ -251,6 +251,7 @@
     ((ObjectMonitor::f ## _offset_in_bytes()) - markOopDesc::monitor_value)
 
   markOop   header() const;
+  volatile markOop* header_addr();
   void      set_header(markOop hdr);
 
   intptr_t is_busy() const {
--- a/src/hotspot/share/runtime/objectMonitor.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/objectMonitor.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -36,6 +36,11 @@
   return _header;
 }
 
+inline volatile markOop* ObjectMonitor::header_addr() {
+  assert((intptr_t)this == (intptr_t)&_header, "sync code expects this");
+  return &_header;
+}
+
 inline void ObjectMonitor::set_header(markOop hdr) {
   _header = hdr;
 }
--- a/src/hotspot/share/runtime/orderAccess.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/orderAccess.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -268,21 +268,12 @@
   template <typename T>
   static T        load_acquire(const volatile T* p);
 
-  static intptr_t load_ptr_acquire(const volatile intptr_t* p);
-  static void*    load_ptr_acquire(const volatile void*     p);
-
   template <typename T, typename D>
   static void     release_store(volatile D* p, T v);
 
-  static void     release_store_ptr(volatile intptr_t* p, intptr_t v);
-  static void     release_store_ptr(volatile void*     p, void*    v);
-
   template <typename T, typename D>
   static void     release_store_fence(volatile D* p, T v);
 
-  static void     release_store_ptr_fence(volatile intptr_t* p, intptr_t v);
-  static void     release_store_ptr_fence(volatile void*     p, void*    v);
-
  private:
   // This is a helper that invokes the StubRoutines::fence_entry()
   // routine if it exists, It should only be used by platforms that
--- a/src/hotspot/share/runtime/orderAccess.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/orderAccess.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -54,28 +54,13 @@
   return LoadImpl<T, PlatformOrderedLoad<sizeof(T), X_ACQUIRE> >()(p);
 }
 
-inline intptr_t OrderAccess::load_ptr_acquire(const volatile intptr_t*   p) {
-  return load_acquire(p);
-}
-
-inline void*    OrderAccess::load_ptr_acquire(const volatile void*       p) {
-  return load_acquire(static_cast<void* const volatile *>(p));
-}
-
 template <typename T, typename D>
 inline void OrderAccess::release_store(volatile D* p, T v) {
   StoreImpl<T, D, PlatformOrderedStore<sizeof(D), RELEASE_X> >()(v, p);
 }
 
-inline void     OrderAccess::release_store_ptr(volatile intptr_t* p, intptr_t v) { release_store(p, v); }
-inline void     OrderAccess::release_store_ptr(volatile void*     p, void*    v) { release_store(static_cast<void* volatile*>(p), v); }
-
 template <typename T, typename D>
 inline void OrderAccess::release_store_fence(volatile D* p, T v) {
   StoreImpl<T, D, PlatformOrderedStore<sizeof(D), RELEASE_X_FENCE> >()(v, p);
 }
-
-inline void     OrderAccess::release_store_ptr_fence(volatile intptr_t* p, intptr_t v) { release_store_fence(p, v); }
-inline void     OrderAccess::release_store_ptr_fence(volatile void*     p, void*    v) { release_store_fence(static_cast<void* volatile*>(p), v); }
-
 #endif // SHARE_VM_RUNTIME_ORDERACCESS_INLINE_HPP
--- a/src/hotspot/share/runtime/safepoint.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/safepoint.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -63,10 +63,6 @@
 #include "trace/traceMacros.hpp"
 #include "utilities/events.hpp"
 #include "utilities/macros.hpp"
-#if INCLUDE_ALL_GCS
-#include "gc/cms/concurrentMarkSweepThread.hpp"
-#include "gc/g1/suspendibleThreadSet.hpp"
-#endif // INCLUDE_ALL_GCS
 #ifdef COMPILER1
 #include "c1/c1_globals.hpp"
 #endif
@@ -94,15 +90,7 @@
     _ts_of_current_safepoint = tty->time_stamp().seconds();
   }
 
-#if INCLUDE_ALL_GCS
-  if (UseConcMarkSweepGC) {
-    // In the future we should investigate whether CMS can use the
-    // more-general mechanism below.  DLD (01/05).
-    ConcurrentMarkSweepThread::synchronize(false);
-  } else if (UseG1GC) {
-    SuspendibleThreadSet::synchronize();
-  }
-#endif // INCLUDE_ALL_GCS
+  Universe::heap()->safepoint_synchronize_begin();
 
   // By getting the Threads_lock, we assure that no threads are about to start or
   // exit. It is released again in SafepointSynchronize::end().
@@ -333,7 +321,8 @@
     }
 
     if (sync_event.should_commit()) {
-      sync_event.set_safepointId(safepoint_counter());
+      // Group this event together with the ones committed after the counter is increased
+      sync_event.set_safepointId(safepoint_counter() + 1);
       sync_event.set_initialThreadCount(initial_running);
       sync_event.set_runningThreadCount(_waiting_to_block);
       sync_event.set_iterations(iterations);
@@ -511,14 +500,7 @@
     Threads_lock->unlock();
 
   }
-#if INCLUDE_ALL_GCS
-  // If there are any concurrent GC threads resume them.
-  if (UseConcMarkSweepGC) {
-    ConcurrentMarkSweepThread::desynchronize(false);
-  } else if (UseG1GC) {
-    SuspendibleThreadSet::desynchronize();
-  }
-#endif // INCLUDE_ALL_GCS
+  Universe::heap()->safepoint_synchronize_end();
   // record this time so VMThread can keep track how much time has elapsed
   // since last safepoint.
   _end_of_last_safepoint = os::javaTimeMillis();
@@ -581,7 +563,7 @@
 
   void work(uint worker_id) {
     // All threads deflate monitors and mark nmethods (if necessary).
-    Threads::parallel_java_threads_do(&_cleanup_threads_cl);
+    Threads::possibly_parallel_threads_do(true, &_cleanup_threads_cl);
 
     if (!_subtasks.is_task_claimed(SafepointSynchronize::SAFEPOINT_CLEANUP_DEFLATE_MONITORS)) {
       const char* name = "deflating idle monitors";
--- a/src/hotspot/share/runtime/sharedRuntimeTrans.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/sharedRuntimeTrans.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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 @@
  */
 
 #include "precompiled.hpp"
-#include "prims/jni.h"
+#include "jni.h"
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/sharedRuntime.hpp"
 
--- a/src/hotspot/share/runtime/sharedRuntimeTrig.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/sharedRuntimeTrig.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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 @@
  */
 
 #include "precompiled.hpp"
-#include "prims/jni.h"
+#include "jni.h"
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/sharedRuntime.hpp"
 #include "runtime/sharedRuntimeMath.hpp"
--- a/src/hotspot/share/runtime/stubRoutines.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/stubRoutines.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -59,11 +59,10 @@
 jint    StubRoutines::_verify_oop_count                         = 0;
 address StubRoutines::_verify_oop_subroutine_entry              = NULL;
 address StubRoutines::_atomic_xchg_entry                        = NULL;
-address StubRoutines::_atomic_xchg_ptr_entry                    = NULL;
+address StubRoutines::_atomic_xchg_long_entry                   = NULL;
 address StubRoutines::_atomic_store_entry                       = NULL;
 address StubRoutines::_atomic_store_ptr_entry                   = NULL;
 address StubRoutines::_atomic_cmpxchg_entry                     = NULL;
-address StubRoutines::_atomic_cmpxchg_ptr_entry                 = NULL;
 address StubRoutines::_atomic_cmpxchg_byte_entry                = NULL;
 address StubRoutines::_atomic_cmpxchg_long_entry                = NULL;
 address StubRoutines::_atomic_add_entry                         = NULL;
@@ -382,14 +381,12 @@
     assert(count != 0, "count should be non-zero");
     assert(count <= (size_t)max_intx, "count too large");
     BarrierSet* bs = Universe::heap()->barrier_set();
-    assert(bs->has_write_ref_array_pre_opt(), "Must have pre-barrier opt");
     bs->write_ref_array_pre(dest, (int)count, dest_uninitialized);
 }
 
 static void gen_arraycopy_barrier(oop* dest, size_t count) {
     assert(count != 0, "count should be non-zero");
     BarrierSet* bs = Universe::heap()->barrier_set();
-    assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
     bs->write_ref_array((HeapWord*)dest, count);
 }
 
--- a/src/hotspot/share/runtime/stubRoutines.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/stubRoutines.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -101,11 +101,10 @@
   static address _throw_delayed_StackOverflowError_entry;
 
   static address _atomic_xchg_entry;
-  static address _atomic_xchg_ptr_entry;
+  static address _atomic_xchg_long_entry;
   static address _atomic_store_entry;
   static address _atomic_store_ptr_entry;
   static address _atomic_cmpxchg_entry;
-  static address _atomic_cmpxchg_ptr_entry;
   static address _atomic_cmpxchg_byte_entry;
   static address _atomic_cmpxchg_long_entry;
   static address _atomic_add_entry;
@@ -276,11 +275,10 @@
   static address throw_delayed_StackOverflowError_entry()  { return _throw_delayed_StackOverflowError_entry; }
 
   static address atomic_xchg_entry()                       { return _atomic_xchg_entry; }
-  static address atomic_xchg_ptr_entry()                   { return _atomic_xchg_ptr_entry; }
+  static address atomic_xchg_long_entry()                  { return _atomic_xchg_long_entry; }
   static address atomic_store_entry()                      { return _atomic_store_entry; }
   static address atomic_store_ptr_entry()                  { return _atomic_store_ptr_entry; }
   static address atomic_cmpxchg_entry()                    { return _atomic_cmpxchg_entry; }
-  static address atomic_cmpxchg_ptr_entry()                { return _atomic_cmpxchg_ptr_entry; }
   static address atomic_cmpxchg_byte_entry()               { return _atomic_cmpxchg_byte_entry; }
   static address atomic_cmpxchg_long_entry()               { return _atomic_cmpxchg_long_entry; }
   static address atomic_add_entry()                        { return _atomic_add_entry; }
--- a/src/hotspot/share/runtime/synchronizer.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/synchronizer.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -111,9 +111,7 @@
 static volatile intptr_t gInflationLocks[NINFLATIONLOCKS];
 
 // global list of blocks of monitors
-// gBlockList is really PaddedEnd<ObjectMonitor> *, but we don't
-// want to expose the PaddedEnd template more than necessary.
-ObjectMonitor * volatile ObjectSynchronizer::gBlockList = NULL;
+PaddedEnd<ObjectMonitor> * volatile ObjectSynchronizer::gBlockList = NULL;
 // global monitor free list
 ObjectMonitor * volatile ObjectSynchronizer::gFreeList  = NULL;
 // global monitor in-use list, for moribund threads,
@@ -241,7 +239,7 @@
     lock->set_displaced_header(markOopDesc::unused_mark());
 
     if (owner == NULL &&
-        Atomic::cmpxchg_ptr(Self, &(m->_owner), NULL) == NULL) {
+        Atomic::cmpxchg(Self, &(m->_owner), (void*)NULL) == NULL) {
       assert(m->_recursions == 0, "invariant");
       assert(m->_owner == Self, "invariant");
       return true;
@@ -802,7 +800,7 @@
     hash = get_next_hash(Self, obj);
     temp = mark->copy_set_hash(hash); // merge hash code into header
     assert(temp->is_neutral(), "invariant");
-    test = (markOop) Atomic::cmpxchg_ptr(temp, monitor, mark);
+    test = Atomic::cmpxchg(temp, monitor->header_addr(), mark);
     if (test != mark) {
       // The only update to the header in the monitor (outside GC)
       // is install the hash code. If someone add new usage of
@@ -939,8 +937,7 @@
 // Visitors ...
 
 void ObjectSynchronizer::monitors_iterate(MonitorClosure* closure) {
-  PaddedEnd<ObjectMonitor> * block =
-    (PaddedEnd<ObjectMonitor> *)OrderAccess::load_ptr_acquire(&gBlockList);
+  PaddedEnd<ObjectMonitor> * block = OrderAccess::load_acquire(&gBlockList);
   while (block != NULL) {
     assert(block->object() == CHAINMARKER, "must be a block header");
     for (int i = _BLOCKSIZE - 1; i > 0; i--) {
@@ -955,9 +952,9 @@
 }
 
 // Get the next block in the block list.
-static inline ObjectMonitor* next(ObjectMonitor* block) {
+static inline PaddedEnd<ObjectMonitor>* next(PaddedEnd<ObjectMonitor>* block) {
   assert(block->object() == CHAINMARKER, "must be a block header");
-  block = block->FreeNext;
+  block = (PaddedEnd<ObjectMonitor>*) block->FreeNext;
   assert(block == NULL || block->object() == CHAINMARKER, "must be a block header");
   return block;
 }
@@ -991,9 +988,8 @@
 
 void ObjectSynchronizer::global_oops_do(OopClosure* f) {
   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
-  PaddedEnd<ObjectMonitor> * block =
-    (PaddedEnd<ObjectMonitor> *)OrderAccess::load_ptr_acquire(&gBlockList);
-  for (; block != NULL; block = (PaddedEnd<ObjectMonitor> *)next(block)) {
+  PaddedEnd<ObjectMonitor> * block = OrderAccess::load_acquire(&gBlockList);
+  for (; block != NULL; block = next(block)) {
     assert(block->object() == CHAINMARKER, "must be a block header");
     for (int i = 1; i < _BLOCKSIZE; i++) {
       ObjectMonitor* mid = (ObjectMonitor *)&block[i];
@@ -1232,7 +1228,7 @@
     temp[0].FreeNext = gBlockList;
     // There are lock-free uses of gBlockList so make sure that
     // the previous stores happen before we update gBlockList.
-    OrderAccess::release_store_ptr(&gBlockList, temp);
+    OrderAccess::release_store(&gBlockList, temp);
 
     // Add the new string of objectMonitors to the global free list
     temp[_BLOCKSIZE - 1].FreeNext = gFreeList;
@@ -1734,9 +1730,8 @@
     }
 
   } else {
-    PaddedEnd<ObjectMonitor> * block =
-      (PaddedEnd<ObjectMonitor> *)OrderAccess::load_ptr_acquire(&gBlockList);
-    for (; block != NULL; block = (PaddedEnd<ObjectMonitor> *)next(block)) {
+    PaddedEnd<ObjectMonitor> * block = OrderAccess::load_acquire(&gBlockList);
+    for (; block != NULL; block = next(block)) {
       // Iterate over all extant monitors - Scavenge all idle monitors.
       assert(block->object() == CHAINMARKER, "must be a block header");
       counters->nInCirculation += _BLOCKSIZE;
@@ -1969,12 +1964,10 @@
 // the list of extant blocks without taking a lock.
 
 int ObjectSynchronizer::verify_objmon_isinpool(ObjectMonitor *monitor) {
-  PaddedEnd<ObjectMonitor> * block =
-    (PaddedEnd<ObjectMonitor> *)OrderAccess::load_ptr_acquire(&gBlockList);
+  PaddedEnd<ObjectMonitor> * block = OrderAccess::load_acquire(&gBlockList);
   while (block != NULL) {
     assert(block->object() == CHAINMARKER, "must be a block header");
-    if (monitor > (ObjectMonitor *)&block[0] &&
-        monitor < (ObjectMonitor *)&block[_BLOCKSIZE]) {
+    if (monitor > &block[0] && monitor < &block[_BLOCKSIZE]) {
       address mon = (address)monitor;
       address blk = (address)block;
       size_t diff = mon - blk;
--- a/src/hotspot/share/runtime/synchronizer.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/synchronizer.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -25,6 +25,7 @@
 #ifndef SHARE_VM_RUNTIME_SYNCHRONIZER_HPP
 #define SHARE_VM_RUNTIME_SYNCHRONIZER_HPP
 
+#include "memory/padded.hpp"
 #include "oops/markOop.hpp"
 #include "runtime/basicLock.hpp"
 #include "runtime/handles.hpp"
@@ -159,9 +160,7 @@
  private:
   enum { _BLOCKSIZE = 128 };
   // global list of blocks of monitors
-  // gBlockList is really PaddedEnd<ObjectMonitor> *, but we don't
-  // want to expose the PaddedEnd template more than necessary.
-  static ObjectMonitor * volatile gBlockList;
+  static PaddedEnd<ObjectMonitor> * volatile gBlockList;
   // global monitor free list
   static ObjectMonitor * volatile gFreeList;
   // global monitor in-use list, for moribund threads,
--- a/src/hotspot/share/runtime/thread.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/thread.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -3349,20 +3349,17 @@
   // If CompilerThreads ever become non-JavaThreads, add them here
 }
 
-void Threads::parallel_java_threads_do(ThreadClosure* tc) {
+void Threads::possibly_parallel_threads_do(bool is_par, ThreadClosure* tc) {
   int cp = Threads::thread_claim_parity();
   ALL_JAVA_THREADS(p) {
-    if (p->claim_oops_do(true, cp)) {
+    if (p->claim_oops_do(is_par, cp)) {
       tc->do_thread(p);
     }
   }
-  // Thread claiming protocol requires us to claim the same interesting
-  // threads on all paths. Notably, Threads::possibly_parallel_threads_do
-  // claims all Java threads *and* the VMThread. To avoid breaking the
-  // claiming protocol, we have to claim VMThread on this path too, even
-  // if we do not apply the closure to the VMThread.
   VMThread* vmt = VMThread::vm_thread();
-  (void)vmt->claim_oops_do(true, cp);
+  if (vmt->claim_oops_do(is_par, cp)) {
+    tc->do_thread(vmt);
+  }
 }
 
 // The system initialization in the library has three phases.
@@ -4324,17 +4321,20 @@
 }
 #endif // ASSERT
 
+class ParallelOopsDoThreadClosure : public ThreadClosure {
+private:
+  OopClosure* _f;
+  CodeBlobClosure* _cf;
+public:
+  ParallelOopsDoThreadClosure(OopClosure* f, CodeBlobClosure* cf) : _f(f), _cf(cf) {}
+  void do_thread(Thread* t) {
+    t->oops_do(_f, _cf);
+  }
+};
+
 void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClosure* cf) {
-  int cp = Threads::thread_claim_parity();
-  ALL_JAVA_THREADS(p) {
-    if (p->claim_oops_do(is_par, cp)) {
-      p->oops_do(f, cf);
-    }
-  }
-  VMThread* vmt = VMThread::vm_thread();
-  if (vmt->claim_oops_do(is_par, cp)) {
-    vmt->oops_do(f, cf);
-  }
+  ParallelOopsDoThreadClosure tc(f, cf);
+  possibly_parallel_threads_do(is_par, &tc);
 }
 
 #if INCLUDE_ALL_GCS
@@ -4701,13 +4701,12 @@
 //
 
 
-typedef volatile intptr_t MutexT;      // Mux Lock-word
-enum MuxBits { LOCKBIT = 1 };
+const intptr_t LOCKBIT = 1;
 
 void Thread::muxAcquire(volatile intptr_t * Lock, const char * LockName) {
-  intptr_t w = Atomic::cmpxchg_ptr(LOCKBIT, Lock, 0);
+  intptr_t w = Atomic::cmpxchg(LOCKBIT, Lock, (intptr_t)0);
   if (w == 0) return;
-  if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) {
+  if ((w & LOCKBIT) == 0 && Atomic::cmpxchg(w|LOCKBIT, Lock, w) == w) {
     return;
   }
 
@@ -4720,7 +4719,7 @@
     // Optional spin phase: spin-then-park strategy
     while (--its >= 0) {
       w = *Lock;
-      if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) {
+      if ((w & LOCKBIT) == 0 && Atomic::cmpxchg(w|LOCKBIT, Lock, w) == w) {
         return;
       }
     }
@@ -4733,7 +4732,7 @@
     for (;;) {
       w = *Lock;
       if ((w & LOCKBIT) == 0) {
-        if (Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) {
+        if (Atomic::cmpxchg(w|LOCKBIT, Lock, w) == w) {
           Self->OnList = 0;   // hygiene - allows stronger asserts
           return;
         }
@@ -4741,7 +4740,7 @@
       }
       assert(w & LOCKBIT, "invariant");
       Self->ListNext = (ParkEvent *) (w & ~LOCKBIT);
-      if (Atomic::cmpxchg_ptr(intptr_t(Self)|LOCKBIT, Lock, w) == w) break;
+      if (Atomic::cmpxchg(intptr_t(Self)|LOCKBIT, Lock, w) == w) break;
     }
 
     while (Self->OnList != 0) {
@@ -4751,9 +4750,9 @@
 }
 
 void Thread::muxAcquireW(volatile intptr_t * Lock, ParkEvent * ev) {
-  intptr_t w = Atomic::cmpxchg_ptr(LOCKBIT, Lock, 0);
+  intptr_t w = Atomic::cmpxchg(LOCKBIT, Lock, (intptr_t)0);
   if (w == 0) return;
-  if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) {
+  if ((w & LOCKBIT) == 0 && Atomic::cmpxchg(w|LOCKBIT, Lock, w) == w) {
     return;
   }
 
@@ -4770,7 +4769,7 @@
     // Optional spin phase: spin-then-park strategy
     while (--its >= 0) {
       w = *Lock;
-      if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) {
+      if ((w & LOCKBIT) == 0 && Atomic::cmpxchg(w|LOCKBIT, Lock, w) == w) {
         if (ReleaseAfter != NULL) {
           ParkEvent::Release(ReleaseAfter);
         }
@@ -4786,7 +4785,7 @@
     for (;;) {
       w = *Lock;
       if ((w & LOCKBIT) == 0) {
-        if (Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) {
+        if (Atomic::cmpxchg(w|LOCKBIT, Lock, w) == w) {
           ev->OnList = 0;
           // We call ::Release while holding the outer lock, thus
           // artificially lengthening the critical section.
@@ -4801,7 +4800,7 @@
       }
       assert(w & LOCKBIT, "invariant");
       ev->ListNext = (ParkEvent *) (w & ~LOCKBIT);
-      if (Atomic::cmpxchg_ptr(intptr_t(ev)|LOCKBIT, Lock, w) == w) break;
+      if (Atomic::cmpxchg(intptr_t(ev)|LOCKBIT, Lock, w) == w) break;
     }
 
     while (ev->OnList != 0) {
@@ -4837,7 +4836,7 @@
 // store (CAS) to the lock-word that releases the lock becomes globally visible.
 void Thread::muxRelease(volatile intptr_t * Lock)  {
   for (;;) {
-    const intptr_t w = Atomic::cmpxchg_ptr(0, Lock, LOCKBIT);
+    const intptr_t w = Atomic::cmpxchg((intptr_t)0, Lock, LOCKBIT);
     assert(w & LOCKBIT, "invariant");
     if (w == LOCKBIT) return;
     ParkEvent * const List = (ParkEvent *) (w & ~LOCKBIT);
@@ -4848,7 +4847,7 @@
 
     // The following CAS() releases the lock and pops the head element.
     // The CAS() also ratifies the previously fetched lock-word value.
-    if (Atomic::cmpxchg_ptr (intptr_t(nxt), Lock, w) != w) {
+    if (Atomic::cmpxchg(intptr_t(nxt), Lock, w) != w) {
       continue;
     }
     List->OnList = 0;
--- a/src/hotspot/share/runtime/thread.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/thread.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -25,10 +25,10 @@
 #ifndef SHARE_VM_RUNTIME_THREAD_HPP
 #define SHARE_VM_RUNTIME_THREAD_HPP
 
+#include "jni.h"
 #include "gc/shared/threadLocalAllocBuffer.hpp"
 #include "memory/allocation.hpp"
 #include "oops/oop.hpp"
-#include "prims/jni.h"
 #include "prims/jvmtiExport.hpp"
 #include "runtime/frame.hpp"
 #include "runtime/javaFrameAnchor.hpp"
@@ -2052,7 +2052,7 @@
   static bool includes(JavaThread* p);
   static JavaThread* first()                     { return _thread_list; }
   static void threads_do(ThreadClosure* tc);
-  static void parallel_java_threads_do(ThreadClosure* tc);
+  static void possibly_parallel_threads_do(bool is_par, ThreadClosure* tc);
 
   // Initializes the vm and creates the vm thread
   static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
--- a/src/hotspot/share/runtime/vmStructs.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/runtime/vmStructs.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -48,6 +48,7 @@
 #include "gc/parallel/mutableSpace.hpp"
 #include "gc/serial/defNewGeneration.hpp"
 #include "gc/serial/tenuredGeneration.hpp"
+#include "gc/cms/cmsHeap.hpp"
 #include "gc/shared/cardTableRS.hpp"
 #include "gc/shared/collectedHeap.hpp"
 #include "gc/shared/genCollectedHeap.hpp"
@@ -61,6 +62,7 @@
 #include "memory/allocation.inline.hpp"
 #include "memory/heap.hpp"
 #include "memory/metachunk.hpp"
+#include "memory/padded.hpp"
 #include "memory/referenceType.hpp"
 #include "memory/universe.hpp"
 #include "memory/virtualspace.hpp"
@@ -198,6 +200,8 @@
 typedef CompactHashtable<Symbol*, char>       SymbolCompactHashTable;
 typedef RehashableHashtable<Symbol*, mtSymbol>   RehashableSymbolHashtable;
 
+typedef PaddedEnd<ObjectMonitor>              PaddedObjectMonitor;
+
 //--------------------------------------------------------------------------------
 // VM_STRUCTS
 //
@@ -359,7 +363,7 @@
   /***********************/                                                                                                          \
                                                                                                                                      \
   volatile_nonstatic_field(ConstantPoolCacheEntry,      _indices,                             intx)                                  \
-  nonstatic_field(ConstantPoolCacheEntry,               _f1,                                  volatile Metadata*)                    \
+  volatile_nonstatic_field(ConstantPoolCacheEntry,      _f1,                                  Metadata*)                             \
   volatile_nonstatic_field(ConstantPoolCacheEntry,      _f2,                                  intx)                                  \
   volatile_nonstatic_field(ConstantPoolCacheEntry,      _flags,                               intx)                                  \
                                                                                                                                      \
@@ -1052,7 +1056,7 @@
   volatile_nonstatic_field(BasicLock,          _displaced_header,                             markOop)                               \
   nonstatic_field(BasicObjectLock,             _lock,                                         BasicLock)                             \
   nonstatic_field(BasicObjectLock,             _obj,                                          oop)                                   \
-  static_ptr_volatile_field(ObjectSynchronizer, gBlockList,                                   ObjectMonitor*)                        \
+  static_ptr_volatile_field(ObjectSynchronizer, gBlockList,                                   PaddedObjectMonitor*)                  \
                                                                                                                                      \
   /*********************/                                                                                                            \
   /* Matcher (C2 only) */                                                                                                            \
@@ -1460,6 +1464,7 @@
                                                                           \
   declare_toplevel_type(CollectedHeap)                                    \
            declare_type(GenCollectedHeap,             CollectedHeap)      \
+           declare_type(CMSHeap,                      GenCollectedHeap)   \
   declare_toplevel_type(Generation)                                       \
            declare_type(DefNewGeneration,             Generation)         \
            declare_type(CardGeneration,               Generation)         \
@@ -1680,6 +1685,7 @@
   /************/                                                          \
                                                                           \
   declare_toplevel_type(ObjectMonitor)                                    \
+  declare_toplevel_type(PaddedObjectMonitor)                              \
   declare_toplevel_type(ObjectSynchronizer)                               \
   declare_toplevel_type(BasicLock)                                        \
   declare_toplevel_type(BasicObjectLock)                                  \
@@ -2154,6 +2160,7 @@
   declare_toplevel_type(nmethod*)                                         \
   COMPILER2_PRESENT(declare_unsigned_integer_type(node_idx_t))            \
   declare_toplevel_type(ObjectMonitor*)                                   \
+  declare_toplevel_type(PaddedObjectMonitor*)                             \
   declare_toplevel_type(oop*)                                             \
   declare_toplevel_type(OopMap**)                                         \
   declare_toplevel_type(OopMapCache*)                                     \
--- a/src/hotspot/share/services/mallocSiteTable.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/services/mallocSiteTable.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -147,7 +147,7 @@
     if (entry == NULL) return NULL;
 
     // swap in the head
-    if (Atomic::cmpxchg_ptr((void*)entry, (volatile void *)&_table[index], NULL) == NULL) {
+    if (Atomic::cmpxchg(entry, &_table[index], (MallocSiteHashtableEntry*)NULL) == NULL) {
       return entry->data();
     }
 
@@ -257,3 +257,7 @@
   }
   _lock_state = ExclusiveLock;
 }
+
+bool MallocSiteHashtableEntry::atomic_insert(MallocSiteHashtableEntry* entry) {
+  return Atomic::cmpxchg(entry, &_next, (MallocSiteHashtableEntry*)NULL) == NULL;
+}
--- a/src/hotspot/share/services/mallocSiteTable.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/services/mallocSiteTable.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -61,8 +61,8 @@
 // Malloc site hashtable entry
 class MallocSiteHashtableEntry : public CHeapObj<mtNMT> {
  private:
-  MallocSite                _malloc_site;
-  MallocSiteHashtableEntry* _next;
+  MallocSite                         _malloc_site;
+  MallocSiteHashtableEntry* volatile _next;
 
  public:
   MallocSiteHashtableEntry() : _next(NULL) { }
@@ -79,10 +79,7 @@
   // Insert an entry atomically.
   // Return true if the entry is inserted successfully.
   // The operation can be failed due to contention from other thread.
-  bool atomic_insert(const MallocSiteHashtableEntry* entry) {
-    return (Atomic::cmpxchg_ptr((void*)entry, (volatile void*)&_next,
-      NULL) == NULL);
-  }
+  bool atomic_insert(MallocSiteHashtableEntry* entry);
 
   void set_callsite(const MallocSite& site) {
     _malloc_site = site;
--- a/src/hotspot/share/services/mallocTracker.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/services/mallocTracker.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -68,7 +68,7 @@
     if (sz > 0) {
       // unary minus operator applied to unsigned type, result still unsigned
       #pragma warning(suppress: 4146)
-      Atomic::add(-sz, &_size);
+      Atomic::sub(sz, &_size);
     }
   }
 
--- a/src/hotspot/share/services/memoryManager.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/services/memoryManager.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -94,7 +94,7 @@
 instanceOop MemoryManager::get_memory_manager_instance(TRAPS) {
   // Must do an acquire so as to force ordering of subsequent
   // loads from anything _memory_mgr_obj points to or implies.
-  instanceOop mgr_obj = (instanceOop)OrderAccess::load_ptr_acquire(&_memory_mgr_obj);
+  instanceOop mgr_obj = OrderAccess::load_acquire(&_memory_mgr_obj);
   if (mgr_obj == NULL) {
     // It's ok for more than one thread to execute the code up to the locked region.
     // Extra manager instances will just be gc'ed.
@@ -147,7 +147,7 @@
       //
       // The lock has done an acquire, so the load can't float above it, but
       // we need to do a load_acquire as above.
-      mgr_obj = (instanceOop)OrderAccess::load_ptr_acquire(&_memory_mgr_obj);
+      mgr_obj = OrderAccess::load_acquire(&_memory_mgr_obj);
       if (mgr_obj != NULL) {
          return mgr_obj;
       }
@@ -159,7 +159,7 @@
       // with creating the management object are visible before publishing
       // its address.  The unlock will publish the store to _memory_mgr_obj
       // because it does a release first.
-      OrderAccess::release_store_ptr(&_memory_mgr_obj, mgr_obj);
+      OrderAccess::release_store(&_memory_mgr_obj, mgr_obj);
     }
   }
 
--- a/src/hotspot/share/services/memoryPool.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/services/memoryPool.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -82,7 +82,7 @@
 instanceOop MemoryPool::get_memory_pool_instance(TRAPS) {
   // Must do an acquire so as to force ordering of subsequent
   // loads from anything _memory_pool_obj points to or implies.
-  instanceOop pool_obj = (instanceOop)OrderAccess::load_ptr_acquire(&_memory_pool_obj);
+  instanceOop pool_obj = OrderAccess::load_acquire(&_memory_pool_obj);
   if (pool_obj == NULL) {
     // It's ok for more than one thread to execute the code up to the locked region.
     // Extra pool instances will just be gc'ed.
@@ -123,7 +123,7 @@
       //
       // The lock has done an acquire, so the load can't float above it,
       // but we need to do a load_acquire as above.
-      pool_obj = (instanceOop)OrderAccess::load_ptr_acquire(&_memory_pool_obj);
+      pool_obj = OrderAccess::load_acquire(&_memory_pool_obj);
       if (pool_obj != NULL) {
          return pool_obj;
       }
@@ -135,7 +135,7 @@
       // with creating the pool are visible before publishing its address.
       // The unlock will publish the store to _memory_pool_obj because
       // it does a release first.
-      OrderAccess::release_store_ptr(&_memory_pool_obj, pool_obj);
+      OrderAccess::release_store(&_memory_pool_obj, pool_obj);
     }
   }
 
--- a/src/hotspot/share/services/memoryService.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/services/memoryService.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -86,7 +86,8 @@
 void MemoryService::set_universe_heap(CollectedHeap* heap) {
   CollectedHeap::Name kind = heap->kind();
   switch (kind) {
-    case CollectedHeap::GenCollectedHeap : {
+    case CollectedHeap::GenCollectedHeap :
+    case CollectedHeap::CMSHeap : {
       add_gen_collected_heap_info(GenCollectedHeap::heap());
       break;
     }
--- a/src/hotspot/share/trace/noTraceBackend.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/trace/noTraceBackend.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -24,7 +24,7 @@
 #ifndef SHARE_VM_TRACE_NOTRACEBACKEND_HPP
 #define SHARE_VM_TRACE_NOTRACEBACKEND_HPP
 
-#include "prims/jni.h"
+#include "jni.h"
 #include "trace/traceTime.hpp"
 
 class NoTraceBackend {
--- a/src/hotspot/share/trace/trace.dtd	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/trace/trace.dtd	Sat Oct 21 00:06:50 2017 +0000
@@ -65,7 +65,8 @@
                         is_instant     CDATA "false"
                         is_constant    CDATA "false"
                         is_requestable CDATA "false"
-                        experimental   CDATA "false">
+                        experimental   CDATA "false"
+                        cutoff         CDATA "false">
 <!ATTLIST struct        id             CDATA #REQUIRED>
 <!ATTLIST value         type           CDATA #REQUIRED
                         field          CDATA #REQUIRED
--- a/src/hotspot/share/trace/traceBackend.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/trace/traceBackend.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -23,6 +23,6 @@
 */
 
 #include "precompiled.hpp"
-#include "prims/jni.h"
+#include "jni.h"
 
 extern "C" void JNICALL trace_register_natives(JNIEnv*, jclass) {}
--- a/src/hotspot/share/trace/traceTime.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/trace/traceTime.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -25,7 +25,7 @@
 #ifndef SHARE_VM_TRACE_TRACETIME_HPP
 #define SHARE_VM_TRACE_TRACETIME_HPP
 
-#include "prims/jni.h"
+#include "jni.h"
 
 typedef jlong TracingTime;
 
--- a/src/hotspot/share/trace/traceevents.xml	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/trace/traceevents.xml	Sat Oct 21 00:06:50 2017 +0000
@@ -104,6 +104,24 @@
     <value type="INFLATECAUSE" field="cause" label="Monitor Inflation Cause" description="Cause of inflation"/>
   </event>
 
+  <event id="BiasedLockRevocation" path="java/biased_lock_revocation" label="Biased Lock Revocation"
+         description="Revoked bias of object" has_thread="true" has_stacktrace="true" is_instant="false">
+    <value type="CLASS" field="lockClass" label="Lock Class" description="Class of object whose biased lock was revoked"/>
+    <value type="INTEGER" field="safepointId" label="Safepoint Identifier" relation="SafepointId"/>
+  </event>
+
+  <event id="BiasedLockSelfRevocation" path="java/biased_lock_self_revocation" label="Biased Lock Self Revocation"
+         description="Revoked bias of object biased towards own thread" has_thread="true" has_stacktrace="true" is_instant="false">
+    <value type="CLASS" field="lockClass" label="Lock Class" description="Class of object whose biased lock was revoked"/>
+  </event>
+
+  <event id="BiasedLockClassRevocation" path="java/biased_lock_class_revocation" label="Biased Lock Class Revocation"
+         description="Revoked biases for all instances of a class" has_thread="true" has_stacktrace="true" is_instant="false">
+    <value type="CLASS" field="revokedClass" label="Revoked Class" description="Class whose biased locks were revoked"/>
+    <value type="BOOLEAN" field="disableBiasing" label="Disable Further Biasing" description="Whether further biasing for instances of this class will be allowed"/>
+    <value type="INTEGER" field="safepointId" label="Safepoint Identifier" relation="SafepointId"/>
+  </event>
+
   <event id="ReservedStackActivation" path="vm/runtime/reserved_stack_activation" label="Reserved Stack Activation"
          description="Activation of Reserved Stack Area caused by stack overflow with ReservedStackAccess annotated method in call stack"
          has_thread="true" has_stacktrace="true" is_instant="true">
--- a/src/hotspot/share/utilities/bitMap.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/utilities/bitMap.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -628,7 +628,7 @@
       table[i] = num_set_bits(i);
     }
 
-    if (!Atomic::replace_if_null(table, &_pop_count_table)) {
+    if (Atomic::cmpxchg(table, &_pop_count_table, (BitMap::idx_t*)NULL) != NULL) {
       guarantee(_pop_count_table != NULL, "invariant");
       FREE_C_HEAP_ARRAY(idx_t, table);
     }
--- a/src/hotspot/share/utilities/decoder.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/utilities/decoder.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -28,10 +28,8 @@
 #include "utilities/decoder.hpp"
 #include "utilities/vmError.hpp"
 
-#if defined(_WINDOWS)
-  #include "decoder_windows.hpp"
-  #include "windbghelp.hpp"
-#elif defined(__APPLE__)
+#ifndef _WINDOWS
+#if defined(__APPLE__)
   #include "decoder_machO.hpp"
 #elif defined(AIX)
   #include "decoder_aix.hpp"
@@ -67,9 +65,7 @@
 
 AbstractDecoder* Decoder::create_decoder() {
   AbstractDecoder* decoder;
-#if defined(_WINDOWS)
-  decoder = new (std::nothrow) WindowsDecoder();
-#elif defined (__APPLE__)
+#if defined (__APPLE__)
   decoder = new (std::nothrow)MachODecoder();
 #elif defined(AIX)
   decoder = new (std::nothrow)AIXDecoder();
@@ -136,36 +132,12 @@
   return decoder->demangle(symbol, buf, buflen);
 }
 
-bool Decoder::can_decode_C_frame_in_vm() {
-  assert(_shared_decoder_lock != NULL, "Just check");
-  bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
-  MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
-  AbstractDecoder* decoder = error_handling_thread ?
-    get_error_handler_instance(): get_shared_instance();
-  assert(decoder != NULL, "null decoder");
-  return decoder->can_decode_C_frame_in_vm();
+void Decoder::print_state_on(outputStream* st) {
 }
 
-/*
- * Shutdown shared decoder and replace it with
- * _do_nothing_decoder. Do nothing with error handler
- * instance, since the JVM is going down.
- */
-void Decoder::shutdown() {
-  assert(_shared_decoder_lock != NULL, "Just check");
-  MutexLockerEx locker(_shared_decoder_lock, true);
-
-  if (_shared_decoder != NULL &&
-    _shared_decoder != &_do_nothing_decoder) {
-    delete _shared_decoder;
-  }
-
-  _shared_decoder = &_do_nothing_decoder;
+bool Decoder::get_source_info(address pc, char* buf, size_t buflen, int* line) {
+  return false;
 }
 
-void Decoder::print_state_on(outputStream* st) {
-#ifdef _WINDOWS
-  WindowsDbgHelp::print_state_on(st);
-#endif
-}
+#endif // !_WINDOWS
 
--- a/src/hotspot/share/utilities/decoder.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/utilities/decoder.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, 2017, 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
@@ -58,8 +58,6 @@
 
   // demangle a C++ symbol
   virtual bool demangle(const char* symbol, char* buf, int buflen) = 0;
-  // if the decoder can decode symbols in vm
-  virtual bool can_decode_C_frame_in_vm() const = 0;
 
   virtual decoder_status status() const {
     return _decoder_status;
@@ -99,9 +97,6 @@
     return false;
   }
 
-  virtual bool can_decode_C_frame_in_vm() const {
-    return false;
-  }
 };
 
 
@@ -113,10 +108,11 @@
   }
   static bool decode(address pc, char* buf, int buflen, int* offset, const void* base);
   static bool demangle(const char* symbol, char* buf, int buflen);
-  static bool can_decode_C_frame_in_vm();
 
-  // shutdown shared instance
-  static void shutdown();
+  // Attempts to retrieve source file name and line number associated with a pc.
+  // If buf != NULL, points to a buffer of size buflen which will receive the
+  // file name. File name will be silently truncated if output buffer is too small.
+  static bool get_source_info(address pc, char* buf, size_t buflen, int* line);
 
   static void print_state_on(outputStream* st);
 
--- a/src/hotspot/share/utilities/decoder_elf.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/utilities/decoder_elf.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -39,8 +39,6 @@
   }
   virtual ~ElfDecoder();
 
-  bool can_decode_C_frame_in_vm() const { return true; }
-
   bool demangle(const char* symbol, char *buf, int buflen);
   bool decode(address addr, char *buf, int buflen, int* offset, const char* filepath, bool demangle);
   bool decode(address addr, char *buf, int buflen, int* offset, const void *base) {
--- a/src/hotspot/share/utilities/globalDefinitions_gcc.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/utilities/globalDefinitions_gcc.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -25,7 +25,7 @@
 #ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP
 #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP
 
-#include "prims/jni.h"
+#include "jni.h"
 
 // This file holds compiler-dependent includes,
 // globally used constants & types, class (forward)
--- a/src/hotspot/share/utilities/globalDefinitions_sparcWorks.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/utilities/globalDefinitions_sparcWorks.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -25,7 +25,7 @@
 #ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_SPARCWORKS_HPP
 #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_SPARCWORKS_HPP
 
-#include "prims/jni.h"
+#include "jni.h"
 
 // This file holds compiler-dependent includes,
 // globally used constants & types, class (forward)
--- a/src/hotspot/share/utilities/globalDefinitions_visCPP.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/utilities/globalDefinitions_visCPP.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -25,7 +25,7 @@
 #ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_VISCPP_HPP
 #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_VISCPP_HPP
 
-#include "prims/jni.h"
+#include "jni.h"
 
 // This file holds compiler-dependent includes,
 // globally used constants & types, class (forward)
--- a/src/hotspot/share/utilities/globalDefinitions_xlc.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/utilities/globalDefinitions_xlc.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -26,7 +26,7 @@
 #ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_XLC_HPP
 #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_XLC_HPP
 
-#include "prims/jni.h"
+#include "jni.h"
 
 // This file holds compiler-dependent includes,
 // globally used constants & types, class (forward)
--- a/src/hotspot/share/utilities/hashtable.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/utilities/hashtable.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -190,7 +190,7 @@
   BasicHashtableEntry<F>* current = _free_list;
   while (true) {
     context->_removed_tail->set_next(current);
-    BasicHashtableEntry<F>* old = (BasicHashtableEntry<F>*)Atomic::cmpxchg_ptr(context->_removed_head, &_free_list, current);
+    BasicHashtableEntry<F>* old = Atomic::cmpxchg(context->_removed_head, &_free_list, current);
     if (old == current) {
       break;
     }
--- a/src/hotspot/share/utilities/hashtable.inline.hpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/utilities/hashtable.inline.hpp	Sat Oct 21 00:06:50 2017 +0000
@@ -78,7 +78,7 @@
   //          SystemDictionary are read without locks.  The new entry must be
   //          complete before other threads can be allowed to see it
   //          via a store to _buckets[index].
-  OrderAccess::release_store_ptr(&_entry, l);
+  OrderAccess::release_store(&_entry, l);
 }
 
 
@@ -87,7 +87,7 @@
   //          SystemDictionary are read without locks.  The new entry must be
   //          complete before other threads can be allowed to see it
   //          via a store to _buckets[index].
-  return (BasicHashtableEntry<F>*) OrderAccess::load_ptr_acquire(&_entry);
+  return OrderAccess::load_acquire(&_entry);
 }
 
 
--- a/src/hotspot/share/utilities/vmError.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/hotspot/share/utilities/vmError.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -232,6 +232,13 @@
     int count = 0;
     while (count++ < StackPrintLimit) {
       fr.print_on_error(st, buf, buf_size);
+      if (fr.pc()) { // print source file and line, if available
+        char buf[128];
+        int line_no;
+        if (Decoder::get_source_info(fr.pc(), buf, sizeof(buf), &line_no)) {
+          st->print("  (%s:%d)", buf, line_no);
+        }
+      }
       st->cr();
       // Compiled code may use EBP register on x86 so it looks like
       // non-walkable C frame. Use frame.sender() for java frames.
@@ -1269,7 +1276,7 @@
   }
   intptr_t mytid = os::current_thread_id();
   if (first_error_tid == -1 &&
-      Atomic::cmpxchg_ptr(mytid, &first_error_tid, -1) == -1) {
+      Atomic::cmpxchg(mytid, &first_error_tid, (intptr_t)-1) == -1) {
 
     // Initialize time stamps to use the same base.
     out.time_stamp().update_to(1);
--- a/src/java.base/share/classes/java/lang/Object.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/java.base/share/classes/java/lang/Object.java	Sat Oct 21 00:06:50 2017 +0000
@@ -307,18 +307,67 @@
     public final native void notifyAll();
 
     /**
-     * Causes the current thread to wait until either another thread invokes the
-     * {@link java.lang.Object#notify()} method or the
-     * {@link java.lang.Object#notifyAll()} method for this object, or a
-     * specified amount of time has elapsed.
+     * Causes the current thread to wait until it is awakened, typically
+     * by being <em>notified</em> or <em>interrupted</em>.
+     * <p>
+     * In all respects, this method behaves as if {@code wait(0L, 0)}
+     * had been called. See the specification of the {@link #wait(long, int)} method
+     * for details.
+     *
+     * @throws IllegalMonitorStateException if the current thread is not
+     *         the owner of the object's monitor
+     * @throws InterruptedException if any thread interrupted the current thread before or
+     *         while the current thread was waiting. The <em>interrupted status</em> of the
+     *         current thread is cleared when this exception is thrown.
+     * @see    #notify()
+     * @see    #notifyAll()
+     * @see    #wait(long)
+     * @see    #wait(long, int)
+     */
+    public final void wait() throws InterruptedException {
+        wait(0L);
+    }
+
+    /**
+     * Causes the current thread to wait until it is awakened, typically
+     * by being <em>notified</em> or <em>interrupted</em>, or until a
+     * certain amount of real time has elapsed.
      * <p>
-     * The current thread must own this object's monitor.
+     * In all respects, this method behaves as if {@code wait(timeout, 0)}
+     * had been called. See the specification of the {@link #wait(long, int)} method
+     * for details.
+     *
+     * @param  timeout the maximum time to wait, in milliseconds
+     * @throws IllegalArgumentException if the value of {@code timeout} is negative
+     * @throws IllegalMonitorStateException if the current thread is not
+     *         the owner of the object's monitor
+     * @throws InterruptedException if any thread interrupted the current thread before or
+     *         while the current thread was waiting. The <em>interrupted status</em> of the
+     *         current thread is cleared when this exception is thrown.
+     * @see    #notify()
+     * @see    #notifyAll()
+     * @see    #wait()
+     * @see    #wait(long, int)
+     */
+    public final native void wait(long timeout) throws InterruptedException;
+
+    /**
+     * Causes the current thread to wait until it is awakened, typically
+     * by being <em>notified</em> or <em>interrupted</em>, or until a
+     * certain amount of real time has elapsed.
      * <p>
-     * This method causes the current thread (call it <var>T</var>) to
-     * place itself in the wait set for this object and then to relinquish
-     * any and all synchronization claims on this object. Thread <var>T</var>
-     * becomes disabled for thread scheduling purposes and lies dormant
-     * until one of four things happens:
+     * The current thread must own this object's monitor lock. See the
+     * {@link #notify notify} method for a description of the ways in which
+     * a thread can become the owner of a monitor lock.
+     * <p>
+     * This method causes the current thread (referred to here as <var>T</var>) to
+     * place itself in the wait set for this object and then to relinquish any
+     * and all synchronization claims on this object. Note that only the locks
+     * on this object are relinquished; any other objects on which the current
+     * thread may be synchronized remain locked while the thread waits.
+     * <p>
+     * Thread <var>T</var> then becomes disabled for thread scheduling purposes
+     * and lies dormant until one of the following occurs:
      * <ul>
      * <li>Some other thread invokes the {@code notify} method for this
      * object and thread <var>T</var> happens to be arbitrarily chosen as
@@ -327,14 +376,18 @@
      * object.
      * <li>Some other thread {@linkplain Thread#interrupt() interrupts}
      * thread <var>T</var>.
-     * <li>The specified amount of real time has elapsed, more or less.  If
-     * {@code timeout} is zero, however, then real time is not taken into
-     * consideration and the thread simply waits until notified.
+     * <li>The specified amount of real time has elapsed, more or less.
+     * The amount of real time, in nanoseconds, is given by the expression
+     * {@code 1000000 * timeout + nanos}. If {@code timeout} and {@code nanos}
+     * are both zero, then real time is not taken into consideration and the
+     * thread waits until awakened by one of the other causes.
+     * <li>Thread <var>T</var> is awakened spuriously. (See below.)
      * </ul>
+     * <p>
      * The thread <var>T</var> is then removed from the wait set for this
-     * object and re-enabled for thread scheduling. It then competes in the
+     * object and re-enabled for thread scheduling. It competes in the
      * usual manner with other threads for the right to synchronize on the
-     * object; once it has gained control of the object, all its
+     * object; once it has regained control of the object, all its
      * synchronization claims on the object are restored to the status quo
      * ante - that is, to the situation as of the time that the {@code wait}
      * method was invoked. Thread <var>T</var> then returns from the
@@ -343,119 +396,54 @@
      * thread {@code T} is exactly as it was when the {@code wait} method
      * was invoked.
      * <p>
-     * A thread can also wake up without being notified, interrupted, or
-     * timing out, a so-called <i>spurious wakeup</i>.  While this will rarely
-     * occur in practice, applications must guard against it by testing for
-     * the condition that should have caused the thread to be awakened, and
-     * continuing to wait if the condition is not satisfied.  In other words,
-     * waits should always occur in loops, like this one:
-     * <pre>
-     *     synchronized (obj) {
-     *         while (&lt;condition does not hold&gt;)
-     *             obj.wait(timeout);
-     *         ... // Perform action appropriate to condition
-     *     }
-     * </pre>
+     * A thread can wake up without being notified, interrupted, or timing out, a
+     * so-called <em>spurious wakeup</em>.  While this will rarely occur in practice,
+     * applications must guard against it by testing for the condition that should
+     * have caused the thread to be awakened, and continuing to wait if the condition
+     * is not satisfied. See the example below.
+     * <p>
+     * For more information on this topic, see section 14.2,
+     * "Condition Queues," in Brian Goetz and others' <em>Java Concurrency
+     * in Practice</em> (Addison-Wesley, 2006) or Item 69 in Joshua
+     * Bloch's <em>Effective Java, Second Edition</em> (Addison-Wesley,
+     * 2008).
+     * <p>
+     * If the current thread is {@linkplain java.lang.Thread#interrupt() interrupted}
+     * by any thread before or while it is waiting, then an {@code InterruptedException}
+     * is thrown.  The <em>interrupted status</em> of the current thread is cleared when
+     * this exception is thrown. This exception is not thrown until the lock status of
+     * this object has been restored as described above.
      *
-     * (For more information on this topic, see section 14.2,
-     * Condition Queues, in Brian Goetz and others' "Java Concurrency
-     * in Practice" (Addison-Wesley, 2006) or Item 69 in Joshua
-     * Bloch's "Effective Java (Second Edition)" (Addison-Wesley,
-     * 2008).
-     *
-     * <p>If the current thread is {@linkplain java.lang.Thread#interrupt()
-     * interrupted} by any thread before or while it is waiting, then an
-     * {@code InterruptedException} is thrown.  This exception is not
-     * thrown until the lock status of this object has been restored as
-     * described above.
-     *
-     * <p>
-     * Note that the {@code wait} method, as it places the current thread
-     * into the wait set for this object, unlocks only this object; any
-     * other objects on which the current thread may be synchronized remain
-     * locked while the thread waits.
-     * <p>
-     * This method should only be called by a thread that is the owner
-     * of this object's monitor. See the {@code notify} method for a
-     * description of the ways in which a thread can become the owner of
-     * a monitor.
+     * @apiNote
+     * The recommended approach to waiting is to check the condition being awaited in
+     * a {@code while} loop around the call to {@code wait}, as shown in the example
+     * below. Among other things, this approach avoids problems that can be caused
+     * by spurious wakeups.
      *
-     * @param      timeout   the maximum time to wait in milliseconds.
-     * @throws  IllegalArgumentException      if the value of timeout is
-     *               negative.
-     * @throws  IllegalMonitorStateException  if the current thread is not
-     *               the owner of the object's monitor.
-     * @throws  InterruptedException if any thread interrupted the
-     *             current thread before or while the current thread
-     *             was waiting for a notification.  The <i>interrupted
-     *             status</i> of the current thread is cleared when
-     *             this exception is thrown.
-     * @see        java.lang.Object#notify()
-     * @see        java.lang.Object#notifyAll()
-     */
-    public final native void wait(long timeout) throws InterruptedException;
-
-    /**
-     * Causes the current thread to wait until another thread invokes the
-     * {@link java.lang.Object#notify()} method or the
-     * {@link java.lang.Object#notifyAll()} method for this object, or
-     * some other thread interrupts the current thread, or a certain
-     * amount of real time has elapsed.
-     * <p>
-     * This method is similar to the {@code wait} method of one
-     * argument, but it allows finer control over the amount of time to
-     * wait for a notification before giving up. The amount of real time,
-     * measured in nanoseconds, is given by:
-     * <blockquote>
-     * <pre>
-     * 1000000*timeout+nanos</pre></blockquote>
-     * <p>
-     * In all other respects, this method does the same thing as the
-     * method {@link #wait(long)} of one argument. In particular,
-     * {@code wait(0, 0)} means the same thing as {@code wait(0)}.
-     * <p>
-     * The current thread must own this object's monitor. The thread
-     * releases ownership of this monitor and waits until either of the
-     * following two conditions has occurred:
-     * <ul>
-     * <li>Another thread notifies threads waiting on this object's monitor
-     *     to wake up either through a call to the {@code notify} method
-     *     or the {@code notifyAll} method.
-     * <li>The timeout period, specified by {@code timeout}
-     *     milliseconds plus {@code nanos} nanoseconds arguments, has
-     *     elapsed.
-     * </ul>
-     * <p>
-     * The thread then waits until it can re-obtain ownership of the
-     * monitor and resumes execution.
-     * <p>
-     * As in the one argument version, interrupts and spurious wakeups are
-     * possible, and this method should always be used in a loop:
-     * <pre>
+     * <pre>{@code
      *     synchronized (obj) {
-     *         while (&lt;condition does not hold&gt;)
+     *         while (<condition does not hold> and <timeout not exceeded>) {
+     *             long timeout = ... ; // recompute timeout values
+     *             int nanos = ... ;
      *             obj.wait(timeout, nanos);
-     *         ... // Perform action appropriate to condition
+     *         }
+     *         ... // Perform action appropriate to condition or timeout
      *     }
-     * </pre>
-     * This method should only be called by a thread that is the owner
-     * of this object's monitor. See the {@code notify} method for a
-     * description of the ways in which a thread can become the owner of
-     * a monitor.
+     * }</pre>
      *
-     * @param      timeout   the maximum time to wait in milliseconds.
-     * @param      nanos      additional time, in nanoseconds range
-     *                       0-999999.
-     * @throws  IllegalArgumentException      if the value of timeout is
-     *                      negative or the value of nanos is
-     *                      not in the range 0-999999.
-     * @throws  IllegalMonitorStateException  if the current thread is not
-     *               the owner of this object's monitor.
-     * @throws  InterruptedException if any thread interrupted the
-     *             current thread before or while the current thread
-     *             was waiting for a notification.  The <i>interrupted
-     *             status</i> of the current thread is cleared when
-     *             this exception is thrown.
+     * @param  timeout the maximum time to wait, in milliseconds
+     * @param  nanos   additional time, in nanoseconds, in the range range 0-999999 inclusive
+     * @throws IllegalArgumentException if the value of {@code timeout} is negative,
+     *         or if the value of {@code nanos} is out of range
+     * @throws IllegalMonitorStateException if the current thread is not
+     *         the owner of the object's monitor
+     * @throws InterruptedException if any thread interrupted the current thread before or
+     *         while the current thread was waiting. The <em>interrupted status</em> of the
+     *         current thread is cleared when this exception is thrown.
+     * @see    #notify()
+     * @see    #notifyAll()
+     * @see    #wait()
+     * @see    #wait(long)
      */
     public final void wait(long timeout, int nanos) throws InterruptedException {
         if (timeout < 0) {
@@ -475,48 +463,6 @@
     }
 
     /**
-     * Causes the current thread to wait until another thread invokes the
-     * {@link java.lang.Object#notify()} method or the
-     * {@link java.lang.Object#notifyAll()} method for this object.
-     * In other words, this method behaves exactly as if it simply
-     * performs the call {@code wait(0)}.
-     * <p>
-     * The current thread must own this object's monitor. The thread
-     * releases ownership of this monitor and waits until another thread
-     * notifies threads waiting on this object's monitor to wake up
-     * either through a call to the {@code notify} method or the
-     * {@code notifyAll} method. The thread then waits until it can
-     * re-obtain ownership of the monitor and resumes execution.
-     * <p>
-     * As in the one argument version, interrupts and spurious wakeups are
-     * possible, and this method should always be used in a loop:
-     * <pre>
-     *     synchronized (obj) {
-     *         while (&lt;condition does not hold&gt;)
-     *             obj.wait();
-     *         ... // Perform action appropriate to condition
-     *     }
-     * </pre>
-     * This method should only be called by a thread that is the owner
-     * of this object's monitor. See the {@code notify} method for a
-     * description of the ways in which a thread can become the owner of
-     * a monitor.
-     *
-     * @throws  IllegalMonitorStateException  if the current thread is not
-     *               the owner of the object's monitor.
-     * @throws  InterruptedException if any thread interrupted the
-     *             current thread before or while the current thread
-     *             was waiting for a notification.  The <i>interrupted
-     *             status</i> of the current thread is cleared when
-     *             this exception is thrown.
-     * @see        java.lang.Object#notify()
-     * @see        java.lang.Object#notifyAll()
-     */
-    public final void wait() throws InterruptedException {
-        wait(0);
-    }
-
-    /**
      * Called by the garbage collector on an object when garbage collection
      * determines that there are no more references to the object.
      * A subclass overrides the {@code finalize} method to dispose of
--- a/src/java.base/share/classes/java/util/ServiceLoader.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/java.base/share/classes/java/util/ServiceLoader.java	Sat Oct 21 00:06:50 2017 +0000
@@ -747,8 +747,10 @@
                 // invoke factory method with permissions restricted by acc
                 try {
                     result = AccessController.doPrivileged(pa, acc);
-                } catch (PrivilegedActionException pae) {
-                    exc = pae.getCause();
+                } catch (Throwable x) {
+                    if (x instanceof PrivilegedActionException)
+                        x = x.getCause();
+                    exc = x;
                 }
             }
             if (exc != null) {
@@ -788,8 +790,10 @@
                 // invoke constructor with permissions restricted by acc
                 try {
                     p = AccessController.doPrivileged(pa, acc);
-                } catch (PrivilegedActionException pae) {
-                    exc = pae.getCause();
+                } catch (Throwable x) {
+                    if (x instanceof PrivilegedActionException)
+                        x = x.getCause();
+                    exc = x;
                 }
             }
             if (exc != null) {
@@ -852,8 +856,9 @@
             PrivilegedExceptionAction<Class<?>> pa = () -> Class.forName(module, cn);
             try {
                 clazz = AccessController.doPrivileged(pa);
-            } catch (PrivilegedActionException pae) {
-                Throwable x = pae.getCause();
+            } catch (Throwable x) {
+                if (x instanceof PrivilegedActionException)
+                    x = x.getCause();
                 fail(service, "Unable to load " + cn, x);
                 return null;
             }
@@ -1477,6 +1482,8 @@
                 next = (Provider<T>) loadedProviders.get(index++);
             } else if (iterator.hasNext()) {
                 next = iterator.next();
+                loadedProviders.add((Provider<S>)next);
+                index++;
             } else {
                 loadedAllProviders = true;
             }
--- a/src/java.base/share/classes/java/util/SplittableRandom.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/java.base/share/classes/java/util/SplittableRandom.java	Sat Oct 21 00:06:50 2017 +0000
@@ -399,6 +399,26 @@
     }
 
     /**
+     * Fills a user-supplied byte array with generated pseudorandom bytes.
+     *
+     * @param  bytes the byte array to fill with pseudorandom bytes
+     * @throws NullPointerException if bytes is null
+     * @since  10
+     */
+    public void nextBytes(byte[] bytes) {
+        int i = 0;
+        int len = bytes.length;
+        for (int words = len >> 3; words--> 0; ) {
+            long rnd = nextLong();
+            for (int n = 8; n--> 0; rnd >>>= Byte.SIZE)
+                bytes[i++] = (byte)rnd;
+        }
+        if (i < len)
+            for (long rnd = nextLong(); i < len; rnd >>>= Byte.SIZE)
+                bytes[i++] = (byte)rnd;
+    }
+
+    /**
      * Returns a pseudorandom {@code int} value.
      *
      * @return a pseudorandom {@code int} value
--- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java	Sat Oct 21 00:06:50 2017 +0000
@@ -231,15 +231,16 @@
      *
      * The implementation is completely directionally symmetrical,
      * except that most public methods that iterate through the list
-     * follow next pointers ("forward" direction).
+     * follow next pointers, in the "forward" direction.
      *
-     * We believe (without full proof) that all single-element deque
-     * operations (e.g., addFirst, peekLast, pollLast) are linearizable
-     * (see Herlihy and Shavit's book).  However, some combinations of
+     * We believe (without full proof) that all single-element Deque
+     * operations that operate directly at the two ends of the Deque
+     * (e.g., addFirst, peekLast, pollLast) are linearizable (see
+     * Herlihy and Shavit's book).  However, some combinations of
      * operations are known not to be linearizable.  In particular,
-     * when an addFirst(A) is racing with pollFirst() removing B, it is
-     * possible for an observer iterating over the elements to observe
-     * A B C and subsequently observe A C, even though no interior
+     * when an addFirst(A) is racing with pollFirst() removing B, it
+     * is possible for an observer iterating over the elements to
+     * observe first [A B C] and then [A C], even though no interior
      * removes are ever performed.  Nevertheless, iterators behave
      * reasonably, providing the "weakly consistent" guarantees.
      *
@@ -865,21 +866,33 @@
     }
 
     public E peekFirst() {
-        for (Node<E> p = first(); p != null; p = succ(p)) {
-            final E item;
-            if ((item = p.item) != null)
-                return item;
+        restart: for (;;) {
+            for (Node<E> first = first(), p = first;;) {
+                final E item;
+                if ((item = p.item) != null) {
+                    // recheck for linearizability
+                    if (first.prev != null) continue restart;
+                    return item;
+                }
+                if ((p = succ(p)) == null)
+                    return null;
+            }
         }
-        return null;
     }
 
     public E peekLast() {
-        for (Node<E> p = last(); p != null; p = pred(p)) {
-            final E item;
-            if ((item = p.item) != null)
-                return item;
+        restart: for (;;) {
+            for (Node<E> last = last(), p = last;;) {
+                final E item;
+                if ((item = p.item) != null) {
+                    // recheck for linearizability
+                    if (last.next != null) continue restart;
+                    return item;
+                }
+                if ((p = pred(p)) == null)
+                    return null;
+            }
         }
-        return null;
     }
 
     /**
@@ -897,27 +910,39 @@
     }
 
     public E pollFirst() {
-        for (Node<E> p = first(); p != null; p = succ(p)) {
-            final E item;
-            if ((item = p.item) != null
-                && ITEM.compareAndSet(p, item, null)) {
-                unlink(p);
-                return item;
+        restart: for (;;) {
+            for (Node<E> first = first(), p = first;;) {
+                final E item;
+                if ((item = p.item) != null) {
+                    // recheck for linearizability
+                    if (first.prev != null) continue restart;
+                    if (ITEM.compareAndSet(p, item, null)) {
+                        unlink(p);
+                        return item;
+                    }
+                }
+                if ((p = succ(p)) == null)
+                    return null;
             }
         }
-        return null;
     }
 
     public E pollLast() {
-        for (Node<E> p = last(); p != null; p = pred(p)) {
-            final E item;
-            if ((item = p.item) != null
-                && ITEM.compareAndSet(p, item, null)) {
-                unlink(p);
-                return item;
+        restart: for (;;) {
+            for (Node<E> last = last(), p = last;;) {
+                final E item;
+                if ((item = p.item) != null) {
+                    // recheck for linearizability
+                    if (last.next != null) continue restart;
+                    if (ITEM.compareAndSet(p, item, null)) {
+                        unlink(p);
+                        return item;
+                    }
+                }
+                if ((p = pred(p)) == null)
+                    return null;
             }
         }
-        return null;
     }
 
     /**
@@ -1079,14 +1104,14 @@
      * @return the number of elements in this deque
      */
     public int size() {
-        restartFromHead: for (;;) {
+        restart: for (;;) {
             int count = 0;
             for (Node<E> p = first(); p != null;) {
                 if (p.item != null)
                     if (++count == Integer.MAX_VALUE)
                         break;  // @see Collection.size()
                 if (p == (p = p.next))
-                    continue restartFromHead;
+                    continue restart;
             }
             return count;
         }
@@ -1183,7 +1208,7 @@
 
     public String toString() {
         String[] a = null;
-        restartFromHead: for (;;) {
+        restart: for (;;) {
             int charLength = 0;
             int size = 0;
             for (Node<E> p = first(); p != null;) {
@@ -1198,7 +1223,7 @@
                     charLength += s.length();
                 }
                 if (p == (p = p.next))
-                    continue restartFromHead;
+                    continue restart;
             }
 
             if (size == 0)
@@ -1210,7 +1235,7 @@
 
     private Object[] toArrayInternal(Object[] a) {
         Object[] x = a;
-        restartFromHead: for (;;) {
+        restart: for (;;) {
             int size = 0;
             for (Node<E> p = first(); p != null;) {
                 final E item;
@@ -1222,7 +1247,7 @@
                     x[size++] = item;
                 }
                 if (p == (p = p.next))
-                    continue restartFromHead;
+                    continue restart;
             }
             if (x == null)
                 return new Object[0];
--- a/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1039,7 +1039,10 @@
      */
     private static final long SEEDER_INCREMENT = 0xbb67ae8584caa73bL;
 
-    // Constants from SplittableRandom
+    /**
+     * The least non-zero value returned by nextDouble(). This value
+     * is scaled by a random value of 53 bits to produce a result.
+     */
     private static final double DOUBLE_UNIT = 0x1.0p-53;  // 1.0  / (1L << 53)
     private static final float  FLOAT_UNIT  = 0x1.0p-24f; // 1.0f / (1 << 24)
 
--- a/src/java.base/share/classes/java/util/concurrent/locks/StampedLock.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/java.base/share/classes/java/util/concurrent/locks/StampedLock.java	Sat Oct 21 00:06:50 2017 +0000
@@ -140,7 +140,8 @@
  *   private double x, y;
  *   private final StampedLock sl = new StampedLock();
  *
- *   void move(double deltaX, double deltaY) { // an exclusively locked method
+ *   // an exclusively locked method
+ *   void move(double deltaX, double deltaY) {
  *     long stamp = sl.writeLock();
  *     try {
  *       x += deltaX;
@@ -150,25 +151,57 @@
  *     }
  *   }
  *
- *   double distanceFromOrigin() { // A read-only method
- *     double currentX, currentY;
+ *   // a read-only method
+ *   // upgrade from optimistic read to read lock
+ *   double distanceFromOrigin() {
  *     long stamp = sl.tryOptimisticRead();
- *     do {
- *       if (stamp == 0L)
- *         stamp = sl.readLock();
- *       try {
+ *     try {
+ *       retryHoldingLock: for (;; stamp = sl.readLock()) {
+ *         if (stamp == 0L)
+ *           continue retryHoldingLock;
  *         // possibly racy reads
- *         currentX = x;
- *         currentY = y;
- *       } finally {
- *         stamp = sl.tryConvertToOptimisticRead(stamp);
+ *         double currentX = x;
+ *         double currentY = y;
+ *         if (!sl.validate(stamp))
+ *           continue retryHoldingLock;
+ *         return Math.hypot(currentX, currentY);
  *       }
- *     } while (stamp == 0);
- *     return Math.hypot(currentX, currentY);
+ *     } finally {
+ *       if (StampedLock.isReadLockStamp(stamp))
+ *         sl.unlockRead(stamp);
+ *     }
  *   }
  *
- *   void moveIfAtOrigin(double newX, double newY) { // upgrade
- *     // Could instead start with optimistic, not read mode
+ *   // upgrade from optimistic read to write lock
+ *   void moveIfAtOrigin(double newX, double newY) {
+ *     long stamp = sl.tryOptimisticRead();
+ *     try {
+ *       retryHoldingLock: for (;; stamp = sl.writeLock()) {
+ *         if (stamp == 0L)
+ *           continue retryHoldingLock;
+ *         // possibly racy reads
+ *         double currentX = x;
+ *         double currentY = y;
+ *         if (!sl.validate(stamp))
+ *           continue retryHoldingLock;
+ *         if (currentX != 0.0 || currentY != 0.0)
+ *           break;
+ *         stamp = sl.tryConvertToWriteLock(stamp);
+ *         if (stamp == 0L)
+ *           continue retryHoldingLock;
+ *         // exclusive access
+ *         x = newX;
+ *         y = newY;
+ *         return;
+ *       }
+ *     } finally {
+ *       if (StampedLock.isWriteLockStamp(stamp))
+ *         sl.unlockWrite(stamp);
+ *     }
+ *   }
+ *
+ *   // Upgrade read lock to write lock
+ *   void moveIfAtOrigin(double newX, double newY) {
  *     long stamp = sl.readLock();
  *     try {
  *       while (x == 0.0 && y == 0.0) {
@@ -882,6 +915,92 @@
     }
 
     /**
+     * Tells whether a stamp represents holding a lock exclusively.
+     * This method may be useful in conjunction with
+     * {@link #tryConvertToWriteLock}, for example: <pre> {@code
+     * long stamp = sl.tryOptimisticRead();
+     * try {
+     *   ...
+     *   stamp = sl.tryConvertToWriteLock(stamp);
+     *   ...
+     * } finally {
+     *   if (StampedLock.isWriteLockStamp(stamp))
+     *     sl.unlockWrite(stamp);
+     * }}</pre>
+     *
+     * @param stamp a stamp returned by a previous StampedLock operation
+     * @return {@code true} if the stamp was returned by a successful
+     *   write-lock operation
+     * @since 10
+     */
+    public static boolean isWriteLockStamp(long stamp) {
+        return (stamp & ABITS) == WBIT;
+    }
+
+    /**
+     * Tells whether a stamp represents holding a lock non-exclusively.
+     * This method may be useful in conjunction with
+     * {@link #tryConvertToReadLock}, for example: <pre> {@code
+     * long stamp = sl.tryOptimisticRead();
+     * try {
+     *   ...
+     *   stamp = sl.tryConvertToReadLock(stamp);
+     *   ...
+     * } finally {
+     *   if (StampedLock.isReadLockStamp(stamp))
+     *     sl.unlockRead(stamp);
+     * }}</pre>
+     *
+     * @param stamp a stamp returned by a previous StampedLock operation
+     * @return {@code true} if the stamp was returned by a successful
+     *   read-lock operation
+     * @since 10
+     */
+    public static boolean isReadLockStamp(long stamp) {
+        return (stamp & RBITS) != 0L;
+    }
+
+    /**
+     * Tells whether a stamp represents holding a lock.
+     * This method may be useful in conjunction with
+     * {@link #tryConvertToReadLock} and {@link #tryConvertToWriteLock},
+     * for example: <pre> {@code
+     * long stamp = sl.tryOptimisticRead();
+     * try {
+     *   ...
+     *   stamp = sl.tryConvertToReadLock(stamp);
+     *   ...
+     *   stamp = sl.tryConvertToWriteLock(stamp);
+     *   ...
+     * } finally {
+     *   if (StampedLock.isLockStamp(stamp))
+     *     sl.unlock(stamp);
+     * }}</pre>
+     *
+     * @param stamp a stamp returned by a previous StampedLock operation
+     * @return {@code true} if the stamp was returned by a successful
+     *   read-lock or write-lock operation
+     * @since 10
+     */
+    public static boolean isLockStamp(long stamp) {
+        return (stamp & ABITS) != 0L;
+    }
+
+    /**
+     * Tells whether a stamp represents a successful optimistic read.
+     *
+     * @param stamp a stamp returned by a previous StampedLock operation
+     * @return {@code true} if the stamp was returned by a successful
+     *   optimistic read operation, that is, a non-zero return from
+     *   {@link #tryOptimisticRead()} or
+     *   {@link #tryConvertToOptimisticRead(long)}
+     * @since 10
+     */
+    public static boolean isOptimisticReadStamp(long stamp) {
+        return (stamp & ABITS) == 0L && stamp != 0L;
+    }
+
+    /**
      * Queries the number of read locks held for this lock. This
      * method is designed for use in monitoring system state, not for
      * synchronization control.
--- a/src/java.base/share/classes/java/util/zip/ZipUtils.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/java.base/share/classes/java/util/zip/ZipUtils.java	Sat Oct 21 00:06:50 2017 +0000
@@ -28,9 +28,11 @@
 import java.nio.file.attribute.FileTime;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.time.DateTimeException;
 import java.time.Instant;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
+import java.util.Date;
 import java.util.concurrent.TimeUnit;
 
 import static java.util.zip.ZipConstants.ENDHDR;
@@ -78,31 +80,39 @@
     }
 
     /**
+     /*
      * Converts DOS time to Java time (number of milliseconds since epoch).
      */
     public static long dosToJavaTime(long dtime) {
-        int year;
-        int month;
-        int day;
+        int year = (int) (((dtime >> 25) & 0x7f) + 1980);
+        int month = (int) ((dtime >> 21) & 0x0f);
+        int day = (int) ((dtime >> 16) & 0x1f);
         int hour = (int) ((dtime >> 11) & 0x1f);
         int minute = (int) ((dtime >> 5) & 0x3f);
         int second = (int) ((dtime << 1) & 0x3e);
-        if ((dtime >> 16) == 0) {
-            // Interpret the 0 DOS date as 1979-11-30 for compatibility with
-            // other implementations.
-            year = 1979;
-            month = 11;
-            day = 30;
-        } else {
-            year = (int) (((dtime >> 25) & 0x7f) + 1980);
-            month = (int) ((dtime >> 21) & 0x0f);
-            day = (int) ((dtime >> 16) & 0x1f);
+
+        if (month > 0 && month < 13 && day > 0 && hour < 24 && minute < 60 && second < 60) {
+            try {
+                LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, minute, second);
+                return TimeUnit.MILLISECONDS.convert(ldt.toEpochSecond(
+                        ZoneId.systemDefault().getRules().getOffset(ldt)), TimeUnit.SECONDS);
+            } catch (DateTimeException dte) {
+                // ignore
+            }
         }
-        LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, minute, second);
-        return TimeUnit.MILLISECONDS.convert(ldt.toEpochSecond(
-                ZoneId.systemDefault().getRules().getOffset(ldt)), TimeUnit.SECONDS);
+        return overflowDosToJavaTime(year, month, day, hour, minute, second);
     }
 
+    /*
+     * Deal with corner cases where an arguably mal-formed DOS time is used
+     */
+    @SuppressWarnings("deprecation") // Use of Date constructor
+    private static long overflowDosToJavaTime(int year, int month, int day,
+                                              int hour, int minute, int second) {
+        return new Date(year - 1900, month - 1, day, hour, minute, second).getTime();
+    }
+
+
     /**
      * Converts extended DOS time to Java time, where up to 1999 milliseconds
      * might be encoded into the upper half of the returned long.
--- a/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java	Sat Oct 21 00:06:50 2017 +0000
@@ -27,6 +27,7 @@
 
 import java.io.FileDescriptor;
 import java.io.IOException;
+import java.lang.ref.Cleaner.Cleanable;
 import java.nio.ByteBuffer;
 import java.nio.MappedByteBuffer;
 import java.nio.channels.ClosedByInterruptException;
@@ -47,6 +48,7 @@
 import jdk.internal.misc.JavaNioAccess;
 import jdk.internal.misc.SharedSecrets;
 import jdk.internal.ref.Cleaner;
+import jdk.internal.ref.CleanerFactory;
 import sun.security.action.GetPropertyAction;
 
 public class FileChannelImpl
@@ -55,7 +57,7 @@
     // Memory allocation size for mapping buffers
     private static final long allocationGranularity;
 
-    // Access to FileDispatcher internals
+    // Access to FileDescriptor internals
     private static final JavaIOFileDescriptorAccess fdAccess =
         SharedSecrets.getJavaIOFileDescriptorAccess();
 
@@ -85,6 +87,21 @@
     // Positional-read is not interruptible
     private volatile boolean uninterruptible;
 
+    // Cleanable with an action which closes this channel's file descriptor
+    private final Cleanable closer;
+
+    private static class Closer implements Runnable {
+        private final FileDescriptor fd;
+
+        Closer(FileDescriptor fd) {
+            this.fd = fd;
+        }
+
+        public void run() {
+            fdAccess.close(fd);
+        }
+    }
+
     private FileChannelImpl(FileDescriptor fd, String path, boolean readable,
                             boolean writable, Object parent)
     {
@@ -94,6 +111,12 @@
         this.parent = parent;
         this.path = path;
         this.nd = new FileDispatcherImpl();
+        // Register a cleaning action if and only if there is no parent
+        // as the parent will take care of closing the file descriptor.
+        // FileChannel is used by the LambdaMetaFactory so a lambda cannot
+        // be used here hence we use a nested class instead.
+        this.closer = parent != null ? null :
+            CleanerFactory.cleaner().register(this, new Closer(fd));
     }
 
     // Used by FileInputStream.getChannel(), FileOutputStream.getChannel
@@ -143,6 +166,10 @@
             // that method will prevent this method from being reinvoked.
             //
             ((java.io.Closeable)parent).close();
+        } else if (closer != null) {
+            // Perform the cleaning action so it is not redone when
+            // this channel becomes phantom reachable.
+            closer.clean();
         } else {
             fdAccess.close(fd);
         }
@@ -1237,5 +1264,4 @@
         IOUtil.load();
         allocationGranularity = initIDs();
     }
-
 }
--- a/src/java.base/share/classes/sun/util/cldr/CLDRLocaleProviderAdapter.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/java.base/share/classes/sun/util/cldr/CLDRLocaleProviderAdapter.java	Sat Oct 21 00:06:50 2017 +0000
@@ -26,6 +26,7 @@
 package sun.util.cldr;
 
 import java.security.AccessController;
+import java.security.AccessControlException;
 import java.security.PrivilegedExceptionAction;
 import java.text.spi.BreakIteratorProvider;
 import java.text.spi.CollatorProvider;
@@ -37,6 +38,7 @@
 import java.util.Map;
 import java.util.Objects;
 import java.util.ServiceLoader;
+import java.util.ServiceConfigurationError;
 import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.concurrent.ConcurrentHashMap;
@@ -81,8 +83,11 @@
                     return null;
                 }
             });
-        }  catch (Exception e) {
+        } catch (Exception e) {
             // Catch any exception, and continue as if only CLDR's base locales exist.
+        } catch (ServiceConfigurationError sce) {
+            Throwable cause = sce.getCause();
+            if (!(cause instanceof AccessControlException)) throw sce;
         }
 
         nonBaseMetaInfo = nbmi;
--- a/src/java.base/share/classes/sun/util/locale/provider/JRELocaleProviderAdapter.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/java.base/share/classes/sun/util/locale/provider/JRELocaleProviderAdapter.java	Sat Oct 21 00:06:50 2017 +0000
@@ -26,6 +26,7 @@
 package sun.util.locale.provider;
 
 import java.security.AccessController;
+import java.security.AccessControlException;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedExceptionAction;
 import java.text.spi.BreakIteratorProvider;
@@ -40,6 +41,7 @@
 import java.util.Locale;
 import java.util.ResourceBundle;
 import java.util.ServiceLoader;
+import java.util.ServiceConfigurationError;
 import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.concurrent.ConcurrentHashMap;
@@ -476,8 +478,11 @@
             if (nonBaseTags != null) {
                 supportedLocaleString += " " + nonBaseTags;
             }
-        }  catch (Exception e) {
+        } catch (Exception e) {
             // catch any exception, and ignore them as if non-EN locales do not exist.
+        } catch (ServiceConfigurationError sce) {
+            Throwable cause = sce.getCause();
+            if (!(cause instanceof AccessControlException)) throw sce;
         }
 
         return supportedLocaleString;
--- a/src/java.base/windows/native/libnet/NetworkInterface_winXP.c	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/java.base/windows/native/libnet/NetworkInterface_winXP.c	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -79,6 +79,7 @@
             strlen("IP Helper Library GetAdaptersAddresses function failed"
                    " with error == ") + 10;
     int _ret = 0;
+    int try;
 
 
     adapterInfo = (IP_ADAPTER_ADDRESSES *) malloc(BUFF_SIZE);
@@ -94,7 +95,7 @@
     flags |= GAA_FLAG_INCLUDE_PREFIX;
     ret = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len);
 
-    for (int try = 0; ret == ERROR_BUFFER_OVERFLOW && try < MAX_TRIES; ++try) {
+    for (try = 0; ret == ERROR_BUFFER_OVERFLOW && try < MAX_TRIES; ++try) {
         IP_ADAPTER_ADDRESSES * newAdapterInfo = NULL;
         if (len < (ULONG_MAX - BUFF_SIZE)) {
             len += BUFF_SIZE;
@@ -160,6 +161,7 @@
     size_t error_msg_buf_size =
         strlen("IP Helper Library GetAdaptersAddresses function failed with error == ") + 10;
     int _ret = 0;
+    int try;
     adapterInfo = (IP_ADAPTER_ADDRESSES *) malloc(BUFF_SIZE);
     if (adapterInfo == NULL) {
         JNU_ThrowByName(env, "java/lang/OutOfMemoryError",
@@ -171,7 +173,7 @@
     flags |= GAA_FLAG_SKIP_MULTICAST;
     flags |= GAA_FLAG_INCLUDE_PREFIX;
     val = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len);
-    for (int try = 0; val == ERROR_BUFFER_OVERFLOW && try < MAX_TRIES; ++try) {
+    for (try = 0; val == ERROR_BUFFER_OVERFLOW && try < MAX_TRIES; ++try) {
         IP_ADAPTER_ADDRESSES * newAdapterInfo = NULL;
         if (len < (ULONG_MAX - BUFF_SIZE)) {
             len += BUFF_SIZE;
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/BinaryContainer.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/BinaryContainer.java	Sat Oct 21 00:06:50 2017 +0000
@@ -144,6 +144,7 @@
         {"SharedRuntime::exception_handler_for_return_address",        "_aot_exception_handler_for_return_address"},
         {"SharedRuntime::register_finalizer",                          "_aot_register_finalizer"},
         {"SharedRuntime::OSR_migration_end",                           "_aot_OSR_migration_end"},
+        {"CompilerRuntime::resolve_dynamic_invoke",                    "_aot_resolve_dynamic_invoke"},
         {"CompilerRuntime::resolve_string_by_symbol",                  "_aot_resolve_string_by_symbol"},
         {"CompilerRuntime::resolve_klass_by_symbol",                   "_aot_resolve_klass_by_symbol"},
         {"CompilerRuntime::resolve_method_by_symbol_and_load_counters","_aot_resolve_method_by_symbol_and_load_counters"},
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTBackend.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTBackend.java	Sat Oct 21 00:06:50 2017 +0000
@@ -33,6 +33,7 @@
 import org.graalvm.compiler.hotspot.HotSpotBackend;
 import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder;
 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
+import org.graalvm.compiler.hotspot.meta.HotSpotInvokeDynamicPlugin;
 import org.graalvm.compiler.java.GraphBuilderPhase;
 import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
 import org.graalvm.compiler.lir.phases.LIRSuites;
@@ -63,13 +64,13 @@
     private final PhaseSuite<HighTierContext> graphBuilderSuite;
     private final HighTierContext highTierContext;
 
-    AOTBackend(Main main, OptionValues graalOptions, HotSpotBackend backend) {
+    AOTBackend(Main main, OptionValues graalOptions, HotSpotBackend backend, HotSpotInvokeDynamicPlugin inokeDynamicPlugin) {
         this.main = main;
         this.graalOptions = graalOptions;
         this.backend = backend;
         providers = backend.getProviders();
         codeCache = providers.getCodeCache();
-        graphBuilderSuite = initGraphBuilderSuite(backend, main.options.compileWithAssertions);
+        graphBuilderSuite = initGraphBuilderSuite(backend, main.options.compileWithAssertions, inokeDynamicPlugin);
         highTierContext = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.ALL);
     }
 
@@ -146,13 +147,14 @@
         return null;
     }
 
-    private static PhaseSuite<HighTierContext> initGraphBuilderSuite(HotSpotBackend backend, boolean compileWithAssertions) {
+    private static PhaseSuite<HighTierContext> initGraphBuilderSuite(HotSpotBackend backend, boolean compileWithAssertions, HotSpotInvokeDynamicPlugin inokeDynamicPlugin) {
         PhaseSuite<HighTierContext> graphBuilderSuite = backend.getSuites().getDefaultGraphBuilderSuite().copy();
         ListIterator<BasePhase<? super HighTierContext>> iterator = graphBuilderSuite.findPhase(GraphBuilderPhase.class);
         GraphBuilderConfiguration baseConfig = ((GraphBuilderPhase) iterator.previous()).getGraphBuilderConfig();
 
         // Use all default plugins.
         Plugins plugins = baseConfig.getPlugins();
+        plugins.setInvokeDynamicPlugin(inokeDynamicPlugin);
         GraphBuilderConfiguration aotConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withOmitAssertions(!compileWithAssertions);
 
         iterator.next();
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTCompiledClass.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTCompiledClass.java	Sat Oct 21 00:06:50 2017 +0000
@@ -25,24 +25,35 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Map;
+import java.util.Set;
 
 import jdk.tools.jaotc.binformat.BinaryContainer;
 import jdk.tools.jaotc.binformat.ReadOnlyDataContainer;
 import jdk.tools.jaotc.binformat.Symbol.Binding;
 import jdk.tools.jaotc.binformat.Symbol.Kind;
 
+import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
 import jdk.vm.ci.meta.ResolvedJavaField;
 import jdk.vm.ci.meta.ResolvedJavaMethod;
 import jdk.vm.ci.meta.ResolvedJavaType;
 
+import jdk.tools.jaotc.AOTDynamicTypeStore.AdapterLocation;
+import jdk.tools.jaotc.AOTDynamicTypeStore.AppendixLocation;
+import jdk.tools.jaotc.AOTDynamicTypeStore.Location;
+
 /**
  * Class encapsulating Graal-compiled output of a Java class. The compilation result of all methods
  * of a class {@code className} are maintained in an array list.
  */
 final class AOTCompiledClass {
 
+    private static AOTDynamicTypeStore dynoStore;
+
+    static void setDynamicTypeStore(AOTDynamicTypeStore s) {
+        dynoStore = s;
+    }
+
     static class AOTKlassData {
         private int gotIndex; // Index (offset/8) to the got in the .metaspace.got section
         private int classId;  // Unique ID
@@ -50,29 +61,64 @@
         private int compiledMethodsOffset;
         // Offset to dependent methods data.
         private int dependentMethodsOffset;
-        private long fingerprint;           // Class fingerprint
 
-        private final String name;
-        private boolean isArray;
+        private final String metadataName;
+        HotSpotResolvedObjectType type;
 
         /**
          * List of dependent compiled methods which have a reference to this class.
          */
         private ArrayList<CompiledMethodInfo> dependentMethods;
 
-        AOTKlassData(BinaryContainer binaryContainer, String name, long fingerprint, int classId) {
+        AOTKlassData(BinaryContainer binaryContainer, HotSpotResolvedObjectType type, int classId) {
             this.dependentMethods = new ArrayList<>();
             this.classId = classId;
-            this.fingerprint = fingerprint;
-            this.gotIndex = binaryContainer.addTwoSlotKlassSymbol(name);
+            this.type = type;
+            this.metadataName = type.isAnonymous() ? "anon<"+ classId + ">": type.getName();
+            this.gotIndex = binaryContainer.addTwoSlotKlassSymbol(metadataName);
             this.compiledMethodsOffset = -1; // Not compiled classes do not have compiled methods.
             this.dependentMethodsOffset = -1;
-            this.name = name;
-            this.isArray = name.length() > 0 && name.charAt(0) == '[';
         }
 
-        long getFingerprint() {
-            return fingerprint;
+        private String[] getMetaspaceNames() {
+            String name = metadataName;
+            Set<Location> locs = dynoStore.getDynamicClassLocationsForType(type);
+            if (locs == null) {
+                return new String[] {name};
+            } else {
+                ArrayList<String> names = new ArrayList<String>();
+                names.add(name);
+                for (Location l : locs) {
+                    HotSpotResolvedObjectType cpType = l.getHolder();
+                    AOTKlassData data = getAOTKlassData(cpType);
+                    // We collect dynamic types at parse time, but late inlining
+                    // may record types that don't make it into the final graph.
+                    // We can safely ignore those here.
+                    if (data == null) {
+                       // Not a compiled or inlined method
+                       continue;
+                    }
+                    int cpi = l.getCpi();
+                    String location = "<"+ data.classId + ":" + cpi + ">";
+                    if (l instanceof AdapterLocation) {
+                        names.add("adapter" + location);
+                        AdapterLocation a = (AdapterLocation)l;
+                        names.add("adapter:" + a.getMethodId() + location);
+                    } else {
+                        assert l instanceof AppendixLocation;
+                        names.add("appendix" + location);
+                    }
+                }
+                return names.toArray(new String[names.size()]);
+            }
+        }
+
+        HotSpotResolvedObjectType getType() {
+            return type;
+        }
+
+        String getMetadataName() {
+            return metadataName;
         }
 
         /**
@@ -112,6 +158,7 @@
             for (CompiledMethodInfo methodInfo : dependentMethods) {
                 dependenciesContainer.appendInt(methodInfo.getCodeId());
             }
+
             verify();
 
             // @formatter:off
@@ -119,7 +166,9 @@
              * The offsets layout should match AOTKlassData structure in AOT JVM runtime
              */
             int offset = container.getByteStreamSize();
-            container.createSymbol(offset, Kind.OBJECT, Binding.GLOBAL, 0, name);
+            for (String name : getMetaspaceNames()) {
+                container.createSymbol(offset, Kind.OBJECT, Binding.GLOBAL, 0, name);
+            }
                       // Add index (offset/8) to the got in the .metaspace.got section
             container.appendInt(gotIndex).
                       // Add unique ID
@@ -129,13 +178,16 @@
                       // Add the offset to dependent methods data in the .metaspace.offsets section.
                       appendInt(dependentMethodsOffset).
                       // Add fingerprint.
-                      appendLong(fingerprint);
+                      appendLong(type.getFingerprint());
+
             // @formatter:on
         }
 
         private void verify() {
+            String name = type.getName();
             assert gotIndex > 0 : "incorrect gotIndex: " + gotIndex + " for klass: " + name;
-            assert isArray || fingerprint != 0 : "incorrect fingerprint: " + fingerprint + " for klass: " + name;
+            long fingerprint = type.getFingerprint();
+            assert type.isArray() || fingerprint != 0 : "incorrect fingerprint: " + fingerprint + " for klass: " + name;
             assert compiledMethodsOffset >= -1 : "incorrect compiledMethodsOffset: " + compiledMethodsOffset + " for klass: " + name;
             assert dependentMethodsOffset >= -1 : "incorrect dependentMethodsOffset: " + dependentMethodsOffset + " for klass: " + name;
             assert classId >= 0 : "incorrect classId: " + classId + " for klass: " + name;
@@ -148,7 +200,7 @@
     /**
      * List of all collected class data.
      */
-    private static Map<String, AOTKlassData> klassData = new HashMap<>();
+    private static HashMap<String, AOTKlassData> klassData = new HashMap<>();
 
     /**
      * List of all methods to be compiled.
@@ -269,23 +321,25 @@
      */
     synchronized static AOTKlassData addAOTKlassData(BinaryContainer binaryContainer, HotSpotResolvedObjectType type) {
         String name = type.getName();
-        long fingerprint = type.getFingerprint();
         AOTKlassData data = klassData.get(name);
         if (data != null) {
-            assert data.getFingerprint() == fingerprint : "incorrect fingerprint data for klass: " + name;
+            assert data.getType() == type : "duplicate classes for name " + name;
         } else {
-            data = new AOTKlassData(binaryContainer, name, fingerprint, classesCount++);
+            data = new AOTKlassData(binaryContainer, type, classesCount++);
             klassData.put(name, data);
         }
         return data;
     }
 
-    synchronized static AOTKlassData getAOTKlassData(String name) {
+    private synchronized static AOTKlassData getAOTKlassData(String name) {
         return klassData.get(name);
     }
 
     synchronized static AOTKlassData getAOTKlassData(HotSpotResolvedObjectType type) {
-        return getAOTKlassData(type.getName());
+        String name = type.getName();
+        AOTKlassData data =  getAOTKlassData(name);
+        assert data == null || data.getType() == type : "duplicate classes for name " + name;
+        return data;
     }
 
     void addAOTKlassData(BinaryContainer binaryContainer) {
@@ -354,21 +408,55 @@
             methodInfo.addMethodOffsets(binaryContainer, container);
         }
         String name = resolvedJavaType.getName();
-        AOTKlassData data = klassData.get(name);
+        AOTKlassData data = getAOTKlassData(resolvedJavaType);
         assert data != null : "missing data for klass: " + name;
-        assert data.getFingerprint() == resolvedJavaType.getFingerprint() : "incorrect fingerprint for klass: " + name;
         int cntDepMethods = data.dependentMethods.size();
         assert cntDepMethods > 0 : "no dependent methods for compiled klass: " + name;
         data.setCompiledMethodsOffset(startMethods);
     }
 
     static void putAOTKlassData(BinaryContainer binaryContainer) {
+        // record dynamic types
+        Set<HotSpotResolvedObjectType> dynoTypes = dynoStore.getDynamicTypes();
+        if (dynoTypes != null) {
+            for (HotSpotResolvedObjectType dynoType : dynoTypes) {
+                addFingerprintKlassData(binaryContainer, dynoType);
+            }
+        }
+
         ReadOnlyDataContainer container = binaryContainer.getKlassesOffsetsContainer();
         for (AOTKlassData data : klassData.values()) {
             data.putAOTKlassData(binaryContainer, container);
         }
     }
 
+    static HotSpotResolvedObjectType getType(Object ref) {
+        return (ref instanceof HotSpotResolvedObjectType) ?
+            (HotSpotResolvedObjectType)ref :
+            ((HotSpotResolvedJavaMethod)ref).getDeclaringClass();
+    }
+
+    static String metadataName(HotSpotResolvedObjectType type) {
+        AOTKlassData data = getAOTKlassData(type);
+        assert data != null : "no data for " + type;
+        return getAOTKlassData(type).getMetadataName();
+    }
+
+    private static String metadataName(HotSpotResolvedJavaMethod m) {
+        return metadataName(m.getDeclaringClass()) + "." + m.getName() + m.getSignature().toMethodDescriptor();
+    }
+
+    static String metadataName(Object ref) {
+        if (ref instanceof HotSpotResolvedJavaMethod) {
+            HotSpotResolvedJavaMethod m = (HotSpotResolvedJavaMethod)ref;
+            return metadataName(m);
+        } else {
+            assert ref instanceof HotSpotResolvedObjectType : "unexpected object type " + ref.getClass().getName();
+            HotSpotResolvedObjectType type = (HotSpotResolvedObjectType)ref;
+            return metadataName(type);
+        }
+    }
+
     boolean representsStubs() {
         return representsStubs;
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTDynamicTypeStore.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,169 @@
+/*
+ * 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.
+ */
+package jdk.tools.jaotc;
+
+import org.graalvm.compiler.hotspot.meta.HotSpotInvokeDynamicPlugin.DynamicTypeStore;
+import org.graalvm.compiler.nodes.ConstantNode;
+import org.graalvm.compiler.nodes.StructuredGraph;
+import org.graalvm.compiler.nodes.ValueNode;
+import org.graalvm.compiler.nodes.graphbuilderconf.InvokeDynamicPlugin;
+import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
+
+import jdk.vm.ci.hotspot.HotSpotConstantPool;
+import jdk.vm.ci.hotspot.HotSpotConstantPoolObject;
+import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
+import jdk.vm.ci.hotspot.HotSpotObjectConstant;
+import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
+import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
+import jdk.vm.ci.meta.ConstantPool;
+import jdk.vm.ci.meta.ConstantReflectionProvider;
+import jdk.vm.ci.meta.JavaConstant;
+import jdk.vm.ci.meta.MetaAccessProvider;
+import jdk.vm.ci.meta.ResolvedJavaMethod;
+import jdk.vm.ci.meta.ResolvedJavaType;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+final class AOTDynamicTypeStore implements DynamicTypeStore {
+
+    public static class Location {
+        private HotSpotResolvedObjectType holder;
+        private int cpi;
+
+        Location(HotSpotResolvedObjectType holder, int cpi) {
+            this.holder = holder;
+            this.cpi = cpi;
+        }
+
+        public HotSpotResolvedObjectType getHolder() {
+            return holder;
+        }
+        public int getCpi() {
+            return cpi;
+        }
+        public String toString() {
+            return getHolder().getName() + "@" + cpi;
+        }
+        public int hashCode() {
+            return holder.hashCode() + getClass().hashCode() + cpi;
+        }
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (getClass() != o.getClass()) {
+                return false;
+            }
+            Location l = (Location)o;
+            return cpi == l.cpi && holder.equals(l.holder);
+        }
+    }
+
+    public static class AdapterLocation extends Location {
+        private int methodId;
+
+        AdapterLocation(HotSpotResolvedObjectType holder, int cpi, int methodId) {
+            super(holder, cpi);
+            this.methodId = methodId;
+        }
+        public int getMethodId() {
+            return methodId;
+        }
+        public String toString() {
+            return "adapter:" + methodId + "@" + super.toString();
+        }
+    }
+
+    public static class AppendixLocation extends Location {
+        AppendixLocation(HotSpotResolvedObjectType holder, int cpi) {
+            super(holder, cpi);
+        }
+        public String toString() {
+            return "appendix@" + super.toString();
+        }
+    }
+
+    private HashMap<HotSpotResolvedObjectType, HashSet<Location>> typeMap = new HashMap<>();
+    private HashMap<HotSpotResolvedObjectType, HashSet<HotSpotResolvedObjectType>> holderMap = new HashMap<>();
+
+    public Set<HotSpotResolvedObjectType> getDynamicTypes() {
+        synchronized (typeMap) {
+            return typeMap.keySet();
+        }
+    }
+
+    public Set<HotSpotResolvedObjectType> getDynamicHolders() {
+        synchronized (holderMap) {
+            return holderMap.keySet();
+        }
+    }
+
+    @Override
+    public void recordAdapter(int opcode, HotSpotResolvedObjectType holder, int index, HotSpotResolvedJavaMethod adapter) {
+        int cpi = ((HotSpotConstantPool)holder.getConstantPool()).rawIndexToConstantPoolIndex(index, opcode);
+        int methodId = adapter.methodIdnum();
+        HotSpotResolvedObjectType adapterType = adapter.getDeclaringClass();
+        recordDynamicTypeLocation(new AdapterLocation(holder, cpi, methodId), adapterType);
+    }
+
+    @Override
+    public JavaConstant recordAppendix(int opcode, HotSpotResolvedObjectType holder, int index, JavaConstant appendix) {
+        int cpi = ((HotSpotConstantPool)holder.getConstantPool()).rawIndexToConstantPoolIndex(index, opcode);
+        HotSpotResolvedObjectType appendixType = ((HotSpotObjectConstant)appendix).getType();
+        recordDynamicTypeLocation(new AppendixLocation(holder, cpi), appendixType);
+        // Make the constant locatable
+        return HotSpotConstantPoolObject.forObject(holder, cpi, appendix);
+    }
+
+    private static <T> void recordDynamicMapValue(HashMap<HotSpotResolvedObjectType, HashSet<T>> map, HotSpotResolvedObjectType type, T v) {
+        synchronized (map) {
+            HashSet<T> set = map.get(type);
+            if (set == null) {
+                set = new HashSet<>();
+                map.put(type, set);
+            }
+            set.add(v);
+        }
+    }
+
+    private void recordDynamicTypeLocation(Location l, HotSpotResolvedObjectType type) {
+        recordDynamicMapValue(typeMap, type, l);
+        HotSpotResolvedObjectType holder = l.getHolder();
+        recordDynamicMapValue(holderMap, holder, type);
+    }
+
+    public Set<Location> getDynamicClassLocationsForType(HotSpotResolvedObjectType type) {
+        synchronized (typeMap) {
+            return typeMap.get(type);
+        }
+    }
+
+    public Set<HotSpotResolvedObjectType> getDynamicTypesForHolder(HotSpotResolvedObjectType holder) {
+        synchronized (holderMap) {
+            return holderMap.get(holder);
+        }
+    }
+
+}
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/CallInfo.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/CallInfo.java	Sat Oct 21 00:06:50 2017 +0000
@@ -32,9 +32,19 @@
 
 final class CallInfo {
 
+    static boolean isStaticTarget(Call call) {
+        return !((HotSpotResolvedJavaMethod)call.target).hasReceiver();
+    }
+
+    private static boolean isStaticOpcode(Call call) {
+        int opcode = getByteCode(call) & 0xFF;
+        return opcode == Bytecodes.INVOKESTATIC || opcode == Bytecodes.INVOKEDYNAMIC || opcode == Bytecodes.INVOKEVIRTUAL /* invokehandle */;
+    }
+
     static boolean isStaticCall(Call call) {
-        if (isJavaCall(call)) {
-            return ((getByteCode(call) & 0xFF) == Bytecodes.INVOKESTATIC);
+        if (isJavaCall(call) && isStaticTarget(call)) {
+            assert isStaticOpcode(call);
+            return true;
         }
         return false;
     }
@@ -54,7 +64,7 @@
     }
 
     static boolean isVirtualCall(CompiledMethodInfo methodInfo, Call call) {
-        return isInvokeVirtual(call) && !methodInfo.hasMark(call, MarkId.INVOKESPECIAL);
+        return isInvokeVirtual(call) && !methodInfo.hasMark(call, MarkId.INVOKESPECIAL) && !isStaticTarget(call);
     }
 
     static boolean isOptVirtualCall(CompiledMethodInfo methodInfo, Call call) {
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/CompiledMethodInfo.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/CompiledMethodInfo.java	Sat Oct 21 00:06:50 2017 +0000
@@ -25,7 +25,7 @@
 
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.HashMap;
-import java.util.Map;
+import java.util.HashSet;
 
 import jdk.tools.jaotc.binformat.BinaryContainer;
 import jdk.tools.jaotc.binformat.ReadOnlyDataContainer;
@@ -182,12 +182,12 @@
     /**
      * List of stubs (PLT trampoline).
      */
-    private Map<String, StubInformation> stubs = new HashMap<>();
+    private HashMap<String, StubInformation> stubs = new HashMap<>();
 
     /**
      * List of referenced classes.
      */
-    private Map<String, AOTKlassData> dependentKlasses = new HashMap<>();
+    private HashSet<AOTKlassData> dependentKlasses = new HashSet<>();
 
     /**
      * Methods count used to generate unique global method id.
@@ -209,7 +209,7 @@
     void addMethodOffsets(BinaryContainer binaryContainer, ReadOnlyDataContainer container) {
         this.methodOffsets.setNameOffset(binaryContainer.addMetaspaceName(name));
         this.methodOffsets.addMethodOffsets(container, name);
-        for (AOTKlassData data : dependentKlasses.values()) {
+        for (AOTKlassData data : dependentKlasses) {
             data.addDependentMethod(this);
         }
     }
@@ -291,17 +291,15 @@
 
     void addDependentKlassData(BinaryContainer binaryContainer, HotSpotResolvedObjectType type) {
         AOTKlassData klassData = AOTCompiledClass.addFingerprintKlassData(binaryContainer, type);
-        String klassName = type.getName();
-
-        if (dependentKlasses.containsKey(klassName)) {
-            assert dependentKlasses.get(klassName) == klassData : "duplicated data for klass: " + klassName;
-        } else {
-            dependentKlasses.put(klassName, klassData);
-        }
+        dependentKlasses.add(klassData);
     }
 
-    AOTKlassData getDependentKlassData(String klassName) {
-        return dependentKlasses.get(klassName);
+    AOTKlassData getDependentKlassData(HotSpotResolvedObjectType type) {
+        AOTKlassData klassData = AOTCompiledClass.getAOTKlassData(type);
+        if (dependentKlasses.contains(klassData)) {
+            return klassData;
+        }
+        return null;
     }
 
     boolean hasMark(Site call, MarkId id) {
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/DataPatchProcessor.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/DataPatchProcessor.java	Sat Oct 21 00:06:50 2017 +0000
@@ -32,6 +32,7 @@
 import jdk.tools.jaotc.binformat.Symbol;
 import jdk.tools.jaotc.binformat.Symbol.Binding;
 import jdk.tools.jaotc.binformat.Symbol.Kind;
+import jdk.tools.jaotc.AOTCompiledClass;
 import org.graalvm.compiler.code.DataSection;
 import org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction;
 
@@ -40,6 +41,7 @@
 import jdk.vm.ci.code.site.DataPatch;
 import jdk.vm.ci.code.site.DataSectionReference;
 import jdk.vm.ci.code.site.Reference;
+import jdk.vm.ci.hotspot.HotSpotConstantPoolObject;
 import jdk.vm.ci.hotspot.HotSpotMetaspaceConstant;
 import jdk.vm.ci.hotspot.HotSpotObjectConstant;
 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
@@ -84,18 +86,24 @@
             HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) constant;
             if (metaspaceConstant.asResolvedJavaType() != null) {
                 HotSpotResolvedObjectType type = metaspaceConstant.asResolvedJavaType();
-                targetSymbol = type.getName();
+                methodInfo.addDependentKlassData(binaryContainer, type);
+                targetSymbol = AOTCompiledClass.metadataName(type);
                 gotName = ((action == HotSpotConstantLoadAction.INITIALIZE) ? "got.init." : "got.") + targetSymbol;
-                methodInfo.addDependentKlassData(binaryContainer, type);
             } else if (metaspaceConstant.asResolvedJavaMethod() != null && action == HotSpotConstantLoadAction.LOAD_COUNTERS) {
                 targetSymbol = "counters." + JavaMethodInfo.uniqueMethodName(metaspaceConstant.asResolvedJavaMethod());
                 gotName = "got." + targetSymbol;
                 binaryContainer.addCountersSymbol(targetSymbol);
             }
         } else if (constant instanceof HotSpotObjectConstant) {
-            // String constant.
             HotSpotObjectConstant oopConstant = (HotSpotObjectConstant) constant;
-            targetSymbol = "ldc." + oopConstant.toValueString();
+            if (oopConstant instanceof HotSpotConstantPoolObject) {
+                HotSpotConstantPoolObject cpo = (HotSpotConstantPoolObject)oopConstant;
+                // Even if two locations use the same object, resolve separately
+                targetSymbol = "ldc." + cpo.getCpType().getName() + cpo.getCpi();
+            } else {
+                // String constant.
+                targetSymbol = "ldc." + oopConstant.toValueString();
+            }
             Integer offset = binaryContainer.addOopSymbol(targetSymbol);
             gotName = "got.ldc." + offset;
         } else if (constant instanceof HotSpotSentinelConstant) {
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/JavaCallSiteRelocationSymbol.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/JavaCallSiteRelocationSymbol.java	Sat Oct 21 00:06:50 2017 +0000
@@ -124,6 +124,7 @@
     private static String getResolveSymbolName(CompiledMethodInfo mi, Call call) {
         String resolveSymbolName;
         if (CallInfo.isStaticCall(call)) {
+            assert mi.hasMark(call, MarkId.INVOKESTATIC);
             resolveSymbolName = BinaryContainer.getResolveStaticEntrySymbolName();
         } else if (CallInfo.isSpecialCall(call)) {
             resolveSymbolName = BinaryContainer.getResolveOptVirtualEntrySymbolName();
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java	Sat Oct 21 00:06:50 2017 +0000
@@ -46,6 +46,7 @@
 import org.graalvm.compiler.hotspot.HotSpotGraalOptionValues;
 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
 import org.graalvm.compiler.hotspot.HotSpotHostBackend;
+import org.graalvm.compiler.hotspot.meta.HotSpotInvokeDynamicPlugin;
 import org.graalvm.compiler.java.GraphBuilderPhase;
 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
 import org.graalvm.compiler.options.OptionValues;
@@ -159,7 +160,10 @@
                 System.gc();
             }
 
-            AOTBackend aotBackend = new AOTBackend(this, graalOptions, backend);
+            AOTDynamicTypeStore dynoStore = new AOTDynamicTypeStore();
+            AOTCompiledClass.setDynamicTypeStore(dynoStore);
+
+            AOTBackend aotBackend = new AOTBackend(this, graalOptions, backend, new HotSpotInvokeDynamicPlugin(dynoStore));
             SnippetReflectionProvider snippetReflection = aotBackend.getProviders().getSnippetReflection();
             AOTCompiler compiler = new AOTCompiler(this, graalOptions, aotBackend, options.threads);
             classes = compiler.compileClasses(classes);
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/MetadataBuilder.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/MetadataBuilder.java	Sat Oct 21 00:06:50 2017 +0000
@@ -33,6 +33,7 @@
 import org.graalvm.compiler.code.CompilationResult;
 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
 
+
 import jdk.vm.ci.code.StackSlot;
 import jdk.vm.ci.code.site.DataPatch;
 import jdk.vm.ci.code.site.Infopoint;
@@ -40,6 +41,9 @@
 import jdk.vm.ci.hotspot.HotSpotCompiledCode;
 import jdk.vm.ci.hotspot.HotSpotMetaData;
 
+import static jdk.tools.jaotc.AOTCompiledClass.getType;
+import static jdk.tools.jaotc.AOTCompiledClass.metadataName;
+
 final class MetadataBuilder {
 
     private final DataBuilder dataBuilder;
@@ -168,7 +172,7 @@
     }
 
     private static int addMetadataEntries(BinaryContainer binaryContainer, HotSpotMetaData metaData, CompiledMethodInfo methodInfo) {
-        String[] metaDataEntries = metaData.metadataEntries();
+        Object[] metaDataEntries = metaData.metadataEntries();
 
         if (metaDataEntries.length == 0) {
             return 0;
@@ -177,20 +181,13 @@
         int metadataGotSlotsStart = binaryContainer.getMetadataGotContainer().getByteStreamSize(); // binaryContainer.reserveMetadataGOTSlots(metaDataEntries.length);
 
         for (int index = 0; index < metaDataEntries.length; index++) {
-            String name = metaDataEntries[index];
-            addMetadataEntry(binaryContainer, name);
+            Object ref = metaDataEntries[index];
+            String name = metadataName(ref);
             // Create GOT cells for klasses referenced in metadata
-            String klassName = name;
-            int len = name.length();
-            int parenthesesIndex = name.lastIndexOf('(', len - 1);
-            if (parenthesesIndex > 0) {  // Method name
-                int dotIndex = name.lastIndexOf('.', parenthesesIndex - 1);
-                assert dotIndex > 0 : "method's full name should have '.' : " + name;
-                klassName = name.substring(0, dotIndex);
-            }
+            addMetadataEntry(binaryContainer, name);
             // We should already have added entries for this klass
-            assert AOTCompiledClass.getAOTKlassData(klassName) != null;
-            assert methodInfo.getDependentKlassData(klassName) != null;
+            assert AOTCompiledClass.getAOTKlassData(getType(ref)) != null;
+            assert methodInfo.getDependentKlassData(getType(ref)) != null;
         }
 
         return metadataGotSlotsStart;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1174,6 +1174,9 @@
                         v.type = chk.checkLocalVarType(tree, tree.init.type.baseType(), tree.name);
                     }
                 }
+                if (tree.isImplicitlyTyped()) {
+                    setSyntheticVariableType(tree, v.type);
+                }
             }
             result = tree.type = v.type;
         }
@@ -1348,11 +1351,7 @@
             }
             if (tree.var.isImplicitlyTyped()) {
                 Type inferredType = chk.checkLocalVarType(tree.var, elemtype, tree.var.name);
-                if (inferredType.isErroneous()) {
-                    tree.var.vartype = make.at(tree.var.vartype).Erroneous();
-                } else {
-                    tree.var.vartype = make.at(tree.var.vartype).Type(inferredType);
-                }
+                setSyntheticVariableType(tree.var, inferredType);
             }
             attribStat(tree.var, loopEnv);
             chk.checkType(tree.expr.pos(), elemtype, tree.var.sym.type);
@@ -2559,7 +2558,7 @@
                     Type argType = arityMismatch ?
                             syms.errType :
                             actuals.head;
-                    params.head.vartype = make.at(params.head).Type(argType);
+                    setSyntheticVariableType(params.head, argType);
                     params.head.sym = null;
                     actuals = actuals.isEmpty() ?
                             actuals :
@@ -4831,6 +4830,14 @@
         return types.capture(type);
     }
 
+    private void setSyntheticVariableType(JCVariableDecl tree, Type type) {
+        if (type.isErroneous()) {
+            tree.vartype = make.at(Position.NOPOS).Erroneous();
+        } else {
+            tree.vartype = make.at(Position.NOPOS).Type(type);
+        }
+    }
+
     public void validateTypeAnnotations(JCTree tree, boolean sigOnly) {
         tree.accept(new TypeAnnotationsValidator(sigOnly));
     }
@@ -5152,7 +5159,7 @@
                 that.sym.adr = 0;
             }
             if (that.vartype == null) {
-                that.vartype = make.Erroneous();
+                that.vartype = make.at(Position.NOPOS).Erroneous();
             }
             super.visitVarDef(that);
         }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Sat Oct 21 00:06:50 2017 +0000
@@ -56,6 +56,7 @@
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.function.Consumer;
 import java.util.function.Supplier;
@@ -2096,9 +2097,12 @@
                             }
                             break;
                         case CAPTURED_OUTER_THIS:
-                            if (lambdaIdent.sym.owner.kind == TYP && m.containsKey(lambdaIdent.sym.owner)) {
+                            Optional<Symbol> proxy = m.keySet().stream()
+                                    .filter(out -> lambdaIdent.sym.isMemberOf(out.type.tsym, types))
+                                    .reduce((a, b) -> a.isEnclosedBy((ClassSymbol)b) ? a : b);
+                            if (proxy.isPresent()) {
                                 // Transform outer instance variable references anchoring them to the captured synthetic.
-                                Symbol tSym = m.get(lambdaIdent.sym.owner);
+                                Symbol tSym = m.get(proxy.get());
                                 JCExpression t = make.Ident(tSym).setType(lambdaIdent.sym.owner.type);
                                 t = make.Select(t, lambdaIdent.name);
                                 t.setType(lambdaIdent.type);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Sat Oct 21 00:06:50 2017 +0000
@@ -308,8 +308,8 @@
         void visitSymbol(Symbol _sym) {
             Symbol sym = _sym;
             if (sym.kind == VAR || sym.kind == MTH) {
-                while (sym != null && sym.owner != owner)
-                    sym = proxies.findFirst(proxyName(sym.name));
+                if (sym != null && sym.owner != owner)
+                    sym = proxies.get(sym);
                 if (sym != null && sym.owner == owner) {
                     VarSymbol v = (VarSymbol)sym;
                     if (v.getConstValue() == null) {
@@ -1084,7 +1084,7 @@
                 return makeLit(sym.type, cv);
             }
             // Otherwise replace the variable by its proxy.
-            sym = proxies.findFirst(proxyName(sym.name));
+            sym = proxies.get(sym);
             Assert.check(sym != null && (sym.flags_field & FINAL) != 0);
             tree = make.at(tree.pos).Ident(sym);
         }
@@ -1359,14 +1359,12 @@
  * Free variables proxies and this$n
  *************************************************************************/
 
-    /** A scope containing all free variable proxies for currently translated
-     *  class, as well as its this$n symbol (if needed).
-     *  Proxy scopes are nested in the same way classes are.
-     *  Inside a constructor, proxies and any this$n symbol are duplicated
-     *  in an additional innermost scope, where they represent the constructor
-     *  parameters.
+    /** A map which allows to retrieve the translated proxy variable for any given symbol of an
+     *  enclosing scope that is accessed (the accessed symbol could be the synthetic 'this$n' symbol).
+     *  Inside a constructor, the map temporarily overrides entries corresponding to proxies and any
+     *  'this$n' symbols, where they represent the constructor parameters.
      */
-    WriteableScope proxies;
+    Map<Symbol, Symbol> proxies;
 
     /** A scope containing all unnamed resource variables/saved
      *  exception variables for translated TWR blocks
@@ -1383,8 +1381,12 @@
 
     /** The name of a free variable proxy.
      */
-    Name proxyName(Name name) {
-        return names.fromString("val" + target.syntheticNameChar() + name);
+    Name proxyName(Name name, int index) {
+        Name proxyName = names.fromString("val" + target.syntheticNameChar() + name);
+        if (index > 0) {
+            proxyName = proxyName.append(names.fromString("" + target.syntheticNameChar() + index));
+        }
+        return proxyName;
     }
 
     /** Proxy definitions for all free variables in given list, in reverse order.
@@ -1400,11 +1402,17 @@
             long additionalFlags) {
         long flags = FINAL | SYNTHETIC | additionalFlags;
         List<JCVariableDecl> defs = List.nil();
+        Set<Name> proxyNames = new HashSet<>();
         for (List<VarSymbol> l = freevars; l.nonEmpty(); l = l.tail) {
             VarSymbol v = l.head;
+            int index = 0;
+            Name proxyName;
+            do {
+                proxyName = proxyName(v.name, index++);
+            } while (!proxyNames.add(proxyName));
             VarSymbol proxy = new VarSymbol(
-                flags, proxyName(v.name), v.erasure(types), owner);
-            proxies.enter(proxy);
+                flags, proxyName, v.erasure(types), owner);
+            proxies.put(v, proxy);
             JCVariableDecl vd = make.at(pos).VarDef(proxy, null);
             vd.vartype = access(vd.vartype);
             defs = defs.prepend(vd);
@@ -1843,11 +1851,8 @@
     /** Return tree simulating the assignment {@code this.name = name}, where
      *  name is the name of a free variable.
      */
-    JCStatement initField(int pos, Name name) {
-        Iterator<Symbol> it = proxies.getSymbolsByName(name).iterator();
-        Symbol rhs = it.next();
+    JCStatement initField(int pos, Symbol rhs, Symbol lhs) {
         Assert.check(rhs.owner.kind == MTH);
-        Symbol lhs = it.next();
         Assert.check(rhs.owner.owner == lhs.owner);
         make.at(pos);
         return
@@ -2207,7 +2212,8 @@
 
         classdefs.put(currentClass, tree);
 
-        proxies = proxies.dup(currentClass);
+        Map<Symbol, Symbol> prevProxies = proxies;
+        proxies = new HashMap<>(proxies);
         List<VarSymbol> prevOuterThisStack = outerThisStack;
 
         // If this is an enum definition
@@ -2270,7 +2276,7 @@
             enterSynthetic(tree.pos(), otdef.sym, currentClass.members());
         }
 
-        proxies = proxies.leave();
+        proxies = prevProxies;
         outerThisStack = prevOuterThisStack;
 
         // Append translated tree to `translated' queue.
@@ -2488,7 +2494,8 @@
 
             // Push a new proxy scope for constructor parameters.
             // and create definitions for any this$n and proxy parameters.
-            proxies = proxies.dup(m);
+            Map<Symbol, Symbol> prevProxies = proxies;
+            proxies = new HashMap<>(proxies);
             List<VarSymbol> prevOuterThisStack = outerThisStack;
             List<VarSymbol> fvs = freevars(currentClass);
             JCVariableDecl otdef = null;
@@ -2523,13 +2530,12 @@
             if (fvs.nonEmpty()) {
                 List<Type> addedargtypes = List.nil();
                 for (List<VarSymbol> l = fvs; l.nonEmpty(); l = l.tail) {
-                    final Name pName = proxyName(l.head.name);
                     m.capturedLocals =
                         m.capturedLocals.prepend((VarSymbol)
-                                                (proxies.findFirst(pName)));
+                                                (proxies.get(l.head)));
                     if (TreeInfo.isInitialConstructor(tree)) {
                         added = added.prepend(
-                          initField(tree.body.pos, pName));
+                          initField(tree.body.pos, proxies.get(l.head), prevProxies.get(l.head)));
                     }
                     addedargtypes = addedargtypes.prepend(l.head.erasure(types));
                 }
@@ -2547,7 +2553,7 @@
             }
 
             // pop local variables from proxy stack
-            proxies = proxies.leave();
+            proxies = prevProxies;
 
             // recursively translate following local statements and
             // combine with this- or super-call
@@ -3714,7 +3720,7 @@
             classdefs = new HashMap<>();
             actualSymbols = new HashMap<>();
             freevarCache = new HashMap<>();
-            proxies = WriteableScope.create(syms.noSymbol);
+            proxies = new HashMap<>();
             twrVars = WriteableScope.create(syms.noSymbol);
             outerThisStack = List.nil();
             accessNums = new HashMap<>();
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Sat Oct 21 00:06:50 2017 +0000
@@ -3063,6 +3063,7 @@
         }
         else if (reqInit) syntaxError(token.pos, "expected", EQ);
         JCTree elemType = TreeInfo.innermostType(type, true);
+        int startPos = Position.NOPOS;
         if (allowLocalVariableTypeInference && elemType.hasTag(IDENT)) {
             Name typeName = ((JCIdent)elemType).name;
             if (isRestrictedLocalVarTypeName(typeName)) {
@@ -3070,6 +3071,9 @@
                     //error - 'var' and arrays
                     reportSyntaxError(pos, "var.not.allowed.array");
                 } else {
+                    startPos = TreeInfo.getStartPos(mods);
+                    if (startPos == Position.NOPOS)
+                        startPos = TreeInfo.getStartPos(type);
                     //implicit type
                     type = null;
                 }
@@ -3078,6 +3082,7 @@
         JCVariableDecl result =
             toP(F.at(pos).VarDef(mods, name, type, init));
         attach(result, dc);
+        result.startPos = startPos;
         return result;
     }
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Sat Oct 21 00:06:50 2017 +0000
@@ -920,6 +920,8 @@
         public JCExpression init;
         /** symbol */
         public VarSymbol sym;
+        /** explicit start pos */
+        public int startPos = Position.NOPOS;
 
         protected JCVariableDecl(JCModifiers mods,
                          Name name,
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Sat Oct 21 00:06:50 2017 +0000
@@ -457,9 +457,11 @@
             }
             case VARDEF: {
                 JCVariableDecl node = (JCVariableDecl)tree;
-                if (node.mods.pos != Position.NOPOS) {
+                if (node.startPos != Position.NOPOS) {
+                    return node.startPos;
+                } else if (node.mods.pos != Position.NOPOS) {
                     return node.mods.pos;
-                } else if (node.vartype == null) {
+                } else if (node.vartype == null || node.vartype.pos == Position.NOPOS) {
                     //if there's no type (partially typed lambda parameter)
                     //simply return node position
                     return node.pos;
--- a/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m	Sat Oct 21 00:06:50 2017 +0000
@@ -689,8 +689,15 @@
 // attach to a process/thread specified by "pid"
 static bool ptrace_attach(pid_t pid) {
   int res;
-  if ((res = ptrace(PT_ATTACHEXC, pid, 0, 0)) < 0) {
-    print_error("ptrace(PT_ATTACHEXC, %d) failed with %d\n", pid, res);
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+  if ((res = ptrace(PT_ATTACH, pid, 0, 0)) < 0) {
+    print_error("ptrace(PT_ATTACH, %d) failed with %d\n", pid, res);
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
     return false;
   } else {
     return ptrace_waitpid(pid);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/cms/CMSHeap.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.gc.cms;
+
+import sun.jvm.hotspot.debugger.Address;
+import sun.jvm.hotspot.gc.shared.GenCollectedHeap;
+import sun.jvm.hotspot.gc.shared.CollectedHeapName;
+
+public class CMSHeap extends GenCollectedHeap {
+
+  public CMSHeap(Address addr) {
+    super(addr);
+  }
+
+  public CollectedHeapName kind() {
+    return CollectedHeapName.CMS_HEAP;
+  }
+}
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeapName.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeapName.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -32,6 +32,7 @@
   private CollectedHeapName(String name) { this.name = name; }
 
   public static final CollectedHeapName GEN_COLLECTED_HEAP = new CollectedHeapName("GenCollectedHeap");
+  public static final CollectedHeapName CMS_HEAP = new CollectedHeapName("CMSHeap");
   public static final CollectedHeapName G1_COLLECTED_HEAP = new CollectedHeapName("G1CollectedHeap");
   public static final CollectedHeapName PARALLEL_SCAVENGE_HEAP = new CollectedHeapName("ParallelScavengeHeap");
 
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/Universe.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/Universe.java	Sat Oct 21 00:06:50 2017 +0000
@@ -27,6 +27,7 @@
 import java.io.*;
 import java.util.*;
 import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.gc.cms.CMSHeap;
 import sun.jvm.hotspot.gc.shared.*;
 import sun.jvm.hotspot.gc.g1.G1CollectedHeap;
 import sun.jvm.hotspot.gc.parallel.*;
@@ -77,6 +78,7 @@
 
     heapConstructor = new VirtualConstructor(db);
     heapConstructor.addMapping("GenCollectedHeap", GenCollectedHeap.class);
+    heapConstructor.addMapping("CMSHeap", CMSHeap.class);
     heapConstructor.addMapping("ParallelScavengeHeap", ParallelScavengeHeap.class);
     heapConstructor.addMapping("G1CollectedHeap", G1CollectedHeap.class);
 
--- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/CompilerToVM.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/CompilerToVM.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -256,6 +256,15 @@
     native void resolveInvokeHandleInPool(HotSpotConstantPool constantPool, int cpi);
 
     /**
+     * If {@code cpi} denotes an entry representing a resolved dynamic adapter
+     * (see {@code resolveInvokeDynamicInPool} and {@code resolveInvokeHandleInPool}),
+     * return the opcode of the instruction for which the resolution was performed
+     * ({@code invokedynamic} or {@code invokevirtual}}, or {@code -1} otherwise.
+     */
+    native int isResolvedInvokeHandleInPool(HotSpotConstantPool constantPool, int cpi);
+
+
+    /**
      * Gets the list of type names (in the format of {@link JavaType#getName()}) denoting the
      * classes that define signature polymorphic methods.
      */
--- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPool.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPool.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -42,7 +42,7 @@
 /**
  * Implementation of {@link ConstantPool} for HotSpot.
  */
-final class HotSpotConstantPool implements ConstantPool, MetaspaceWrapperObject {
+public final class HotSpotConstantPool implements ConstantPool, MetaspaceWrapperObject {
 
     /**
      * Subset of JVM bytecode opcodes used by {@link HotSpotConstantPool}.
@@ -215,14 +215,14 @@
     }
 
     /**
-     * Converts a raw index from the bytecodes to a constant pool index by adding a
+     * Converts a raw index from the bytecodes to a constant pool cache index by adding a
      * {@link HotSpotVMConfig#constantPoolCpCacheIndexTag constant}.
      *
      * @param rawIndex index from the bytecode
      * @param opcode bytecode to convert the index for
-     * @return constant pool index
+     * @return constant pool cache index
      */
-    private static int rawIndexToConstantPoolIndex(int rawIndex, int opcode) {
+    private static int rawIndexToConstantPoolCacheIndex(int rawIndex, int opcode) {
         int index;
         if (opcode == Bytecodes.INVOKEDYNAMIC) {
             index = rawIndex;
@@ -271,6 +271,7 @@
         return metaspaceConstantPool;
     }
 
+    @Override
     public long getMetaspacePointer() {
         return getMetaspaceConstantPool();
     }
@@ -541,7 +542,7 @@
     @Override
     public JavaConstant lookupAppendix(int cpi, int opcode) {
         assert Bytecodes.isInvoke(opcode);
-        final int index = rawIndexToConstantPoolIndex(cpi, opcode);
+        final int index = rawIndexToConstantPoolCacheIndex(cpi, opcode);
         Object appendix = compilerToVM().lookupAppendixInPool(this, index);
         if (appendix == null) {
             return null;
@@ -566,7 +567,7 @@
 
     @Override
     public JavaMethod lookupMethod(int cpi, int opcode) {
-        final int index = rawIndexToConstantPoolIndex(cpi, opcode);
+        final int index = rawIndexToConstantPoolCacheIndex(cpi, opcode);
         final HotSpotResolvedJavaMethod method = compilerToVM().lookupMethodInPool(this, index, (byte) opcode);
         if (method != null) {
             return method;
@@ -603,7 +604,7 @@
 
     @Override
     public JavaField lookupField(int cpi, ResolvedJavaMethod method, int opcode) {
-        final int index = rawIndexToConstantPoolIndex(cpi, opcode);
+        final int index = rawIndexToConstantPoolCacheIndex(cpi, opcode);
         final int nameAndTypeIndex = getNameAndTypeRefIndexAt(index);
         final int typeIndex = getSignatureRefIndexAt(nameAndTypeIndex);
         String typeName = lookupUtf8(typeIndex);
@@ -634,6 +635,25 @@
         }
     }
 
+    /*
+     * Converts a raw index from the bytecodes to a constant pool index
+     * (not a cache index).
+     *
+     * @param rawIndex index from the bytecode
+     * @param opcode bytecode to convert the index for
+     * @return constant pool index
+     */
+    public int rawIndexToConstantPoolIndex(int index, int opcode) {
+        if (isInvokedynamicIndex(index)) {
+            assert opcode == Bytecodes.INVOKEDYNAMIC;
+            index = decodeInvokedynamicIndex(index) + config().constantPoolCpCacheIndexTag;
+        } else {
+            assert opcode != Bytecodes.INVOKEDYNAMIC;
+            index = rawIndexToConstantPoolCacheIndex(index, opcode);
+        }
+        return compilerToVM().constantPoolRemapInstructionOperandFromCache(this, index);
+    }
+
     @Override
     @SuppressWarnings("fallthrough")
     public void loadReferencedType(int cpi, int opcode) {
@@ -664,7 +684,7 @@
             case Bytecodes.INVOKESTATIC:
             case Bytecodes.INVOKEINTERFACE: {
                 // invoke and field instructions point to a constant pool cache entry.
-                index = rawIndexToConstantPoolIndex(cpi, opcode);
+                index = rawIndexToConstantPoolCacheIndex(cpi, opcode);
                 index = compilerToVM().constantPoolRemapInstructionOperandFromCache(this, index);
                 break;
             }
@@ -696,7 +716,7 @@
                 }
                 if (tag == JVM_CONSTANT.MethodRef) {
                     if (Bytecodes.isInvokeHandleAlias(opcode) && isSignaturePolymorphicHolder(type)) {
-                        final int methodRefCacheIndex = rawIndexToConstantPoolIndex(cpi, opcode);
+                        final int methodRefCacheIndex = rawIndexToConstantPoolCacheIndex(cpi, opcode);
                         assert checkTag(compilerToVM().constantPoolRemapInstructionOperandFromCache(this, methodRefCacheIndex), JVM_CONSTANT.MethodRef);
                         compilerToVM().resolveInvokeHandleInPool(this, methodRefCacheIndex);
                     }
@@ -734,6 +754,25 @@
         return false;
     }
 
+    /**
+     * Check for a resolved dynamic adapter method at the specified index,
+     * resulting from either a resolved invokedynamic or invokevirtual on a signature polymorphic
+     * MethodHandle method (HotSpot invokehandle).
+     *
+     * @param cpi the constant pool index
+     * @param opcode the opcode of the instruction for which the lookup is being performed
+     * @return {@code true} if a signature polymorphic method reference was found, otherwise {@code false}
+     */
+    public boolean isResolvedDynamicInvoke(int cpi, int opcode) {
+        if (Bytecodes.isInvokeHandleAlias(opcode)) {
+            final int methodRefCacheIndex = rawIndexToConstantPoolCacheIndex(cpi, opcode);
+            assert checkTag(compilerToVM().constantPoolRemapInstructionOperandFromCache(this, methodRefCacheIndex), JVM_CONSTANT.MethodRef);
+            int op =  compilerToVM().isResolvedInvokeHandleInPool(this, methodRefCacheIndex);
+            return op == opcode;
+        }
+        return false;
+    }
+
     @Override
     public String toString() {
         HotSpotResolvedObjectType holder = getHolder();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPoolObject.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+package jdk.vm.ci.hotspot;
+
+import jdk.vm.ci.meta.JavaConstant;
+import jdk.vm.ci.meta.ResolvedJavaType;
+
+/**
+ * Represents a constant that was retrieved from a constant pool.
+ * Used to keep track of the constant pool slot for the constant.
+ */
+public final class HotSpotConstantPoolObject extends HotSpotObjectConstantImpl {
+
+    static JavaConstant forObject(HotSpotResolvedObjectType type, int cpi, Object object) {
+        return new HotSpotConstantPoolObject(type, cpi, object);
+    }
+
+    public static JavaConstant forObject(HotSpotResolvedObjectType type, int cpi, JavaConstant object) {
+        return forObject(type, cpi, ((HotSpotObjectConstantImpl)object).object());
+    }
+
+    private final HotSpotResolvedObjectType type;
+    private final int cpi;
+
+    public HotSpotResolvedObjectType getCpType() { return type; }
+    public int getCpi()  { return cpi; }
+
+    HotSpotConstantPoolObject(HotSpotResolvedObjectType type, int cpi, Object object) {
+        super(object, false);
+        this.type = type;
+        this.cpi = cpi;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o instanceof HotSpotConstantPoolObject) {
+            if (super.equals(o)) {
+                HotSpotConstantPoolObject other = (HotSpotConstantPoolObject) o;
+                return type == other.type && cpi == other.cpi;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String toValueString() {
+        return getCpType().getName() + getCpi();
+    }
+
+    @Override
+    public String toString() {
+        return super.toString() + "@" + toValueString();
+    }
+
+}
--- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotMetaData.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotMetaData.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -32,7 +32,7 @@
     private byte[] relocBytes;
     private byte[] exceptionBytes;
     private byte[] oopMaps;
-    private String[] metadata;
+    private Object[] metadata;
 
     public HotSpotMetaData(TargetDescription target, HotSpotCompiledCode compiledMethod) {
         // Assign the fields default values...
@@ -66,7 +66,7 @@
         return oopMaps;
     }
 
-    public String[] metadataEntries() {
+    public Object[] metadataEntries() {
         return metadata;
     }
 }
--- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotObjectConstantImpl.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotObjectConstantImpl.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -38,7 +38,7 @@
  * Represents a constant non-{@code null} object reference, within the compiler and across the
  * compiler/runtime interface.
  */
-final class HotSpotObjectConstantImpl implements HotSpotObjectConstant {
+class HotSpotObjectConstantImpl implements HotSpotObjectConstant {
 
     static JavaConstant forObject(Object object) {
         return forObject(object, false);
@@ -73,7 +73,7 @@
     private final Object object;
     private final boolean compressed;
 
-    private HotSpotObjectConstantImpl(Object object, boolean compressed) {
+    protected HotSpotObjectConstantImpl(Object object, boolean compressed) {
         this.object = object;
         this.compressed = compressed;
         assert object != null;
--- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethod.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethod.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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,4 +122,6 @@
     int allocateCompileId(int entryBCI);
 
     boolean hasCodeAtLevel(int entryBCI, int level);
+
+    int methodIdnum();
 }
--- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java	Sat Oct 21 00:06:50 2017 +0000
@@ -777,4 +777,8 @@
         }
         return compilerToVM().hasCompiledCodeForOSR(this, entryBCI, level);
     }
+
+    public int methodIdnum() {
+        return UNSAFE.getChar(getConstMethod() + config().constMethodMethodIdnumOffset);
+    }
 }
--- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectType.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectType.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -108,4 +108,7 @@
     HotSpotResolvedObjectType getEnclosingType();
 
     ResolvedJavaMethod getClassInitializer();
+
+    boolean isAnonymous();
+
 }
--- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java	Sat Oct 21 00:06:50 2017 +0000
@@ -934,4 +934,13 @@
     public boolean isCloneableWithAllocation() {
         return (getAccessFlags() & config().jvmAccIsCloneableFast) != 0;
     }
+
+    private int getMiscFlags() {
+        return UNSAFE.getInt(getMetaspaceKlass() + config().instanceKlassMiscFlagsOffset);
+    }
+
+    public boolean isAnonymous() {
+        return (getMiscFlags() & config().instanceKlassMiscIsAnonymous) != 0;
+    }
+
 }
--- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfig.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfig.java	Sat Oct 21 00:06:50 2017 +0000
@@ -92,11 +92,13 @@
     final int instanceKlassInitStateOffset = getFieldOffset("InstanceKlass::_init_state", Integer.class, "u1");
     final int instanceKlassConstantsOffset = getFieldOffset("InstanceKlass::_constants", Integer.class, "ConstantPool*");
     final int instanceKlassFieldsOffset = getFieldOffset("InstanceKlass::_fields", Integer.class, "Array<u2>*");
+    final int instanceKlassMiscFlagsOffset = getFieldOffset("InstanceKlass::_misc_flags", Integer.class, "u2");
     final int klassVtableStartOffset = getFieldValue("CompilerToVM::Data::Klass_vtable_start_offset", Integer.class, "int");
     final int klassVtableLengthOffset = getFieldValue("CompilerToVM::Data::Klass_vtable_length_offset", Integer.class, "int");
 
     final int instanceKlassStateLinked = getConstant("InstanceKlass::linked", Integer.class);
     final int instanceKlassStateFullyInitialized = getConstant("InstanceKlass::fully_initialized", Integer.class);
+    final int instanceKlassMiscIsAnonymous = getConstant("InstanceKlass::_misc_is_anonymous", Integer.class);
 
     final int arrayU1LengthOffset = getFieldOffset("Array<int>::_length", Integer.class, "int");
     final int arrayU1DataOffset = getFieldOffset("Array<u1>::_data", Integer.class);
@@ -185,6 +187,7 @@
     final int constMethodCodeSizeOffset = getFieldOffset("ConstMethod::_code_size", Integer.class, "u2");
     final int constMethodNameIndexOffset = getFieldOffset("ConstMethod::_name_index", Integer.class, "u2");
     final int constMethodSignatureIndexOffset = getFieldOffset("ConstMethod::_signature_index", Integer.class, "u2");
+    final int constMethodMethodIdnumOffset = getFieldOffset("ConstMethod::_method_idnum", Integer.class, "u2");
     final int constMethodMaxStackOffset = getFieldOffset("ConstMethod::_max_stack", Integer.class, "u2");
     final int methodMaxLocalsOffset = getFieldOffset("ConstMethod::_max_locals", Integer.class, "u2");
 
--- a/src/jdk.internal.vm.compiler/.mx.graal/suite.py	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/.mx.graal/suite.py	Sat Oct 21 00:06:50 2017 +0000
@@ -6,7 +6,7 @@
 
   # This puts mx/ as a sibling of the JDK build configuration directories
   # (e.g., macosx-x86_64-normal-server-release).
-  "outputRoot" : "../../../build/mx/hotspot",
+  "outputRoot" : "../../build/mx/hotspot",
 
   "jdklibraries" : {
     "JVMCI_SERVICES" : {
@@ -1093,7 +1093,7 @@
     },
 
     "jdk.tools.jaotc.test" : {
-      "subDir" : "../../test/compiler/aot",
+      "subDir" : "../../test/hotspot/jtreg/compiler/aot",
       "sourceDirs" : ["src"],
       "dependencies" : [
         "mx:JUNIT",
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/ComputeBlockOrder.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/ComputeBlockOrder.java	Sat Oct 21 00:06:50 2017 +0000
@@ -253,13 +253,17 @@
      * Comparator for sorting blocks based on loop depth and probability.
      */
     private static class BlockOrderComparator<T extends AbstractBlockBase<T>> implements Comparator<T> {
+        private static final double EPSILON = 1E-6;
 
         @Override
         public int compare(T a, T b) {
-            // Loop blocks before any loop exit block.
-            int diff = b.getLoopDepth() - a.getLoopDepth();
-            if (diff != 0) {
-                return diff;
+            // Loop blocks before any loop exit block. The only exception are blocks that are
+            // (almost) impossible to reach.
+            if (a.probability() > EPSILON && b.probability() > EPSILON) {
+                int diff = b.getLoopDepth() - a.getLoopDepth();
+                if (diff != 0) {
+                    return diff;
+                }
             }
 
             // Blocks with high probability before blocks with low probability.
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CheckGraalInvariants.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CheckGraalInvariants.java	Sat Oct 21 00:06:50 2017 +0000
@@ -172,7 +172,7 @@
 
         PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
         Plugins plugins = new Plugins(new InvocationPlugins());
-        GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
+        GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
         graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
         HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
 
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1249,7 +1249,7 @@
     }
 
     protected PhaseSuite<HighTierContext> getEagerGraphBuilderSuite() {
-        return getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true));
+        return getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true).withUnresolvedIsError(true));
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/HashMapGetTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2017, 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.
+ */
+package org.graalvm.compiler.core.test;
+
+import jdk.vm.ci.meta.ResolvedJavaMethod;
+import org.graalvm.compiler.nodes.IfNode;
+import org.graalvm.compiler.nodes.LogicNode;
+import org.graalvm.compiler.nodes.ReturnNode;
+import org.graalvm.compiler.nodes.calc.ObjectEqualsNode;
+import org.junit.Test;
+
+import java.util.HashMap;
+
+public class HashMapGetTest extends GraalCompilerTest {
+
+    public static void mapGet(HashMap<Integer, Integer> map, Integer key) {
+        map.get(key);
+    }
+
+    @Test
+    public void hashMapTest() {
+        HashMap<Integer, Integer> map = new HashMap<>();
+        ResolvedJavaMethod get = getResolvedJavaMethod(HashMapGetTest.class, "mapGet");
+        for (int i = 0; i < 5000; i++) {
+            mapGet(map, i);
+            map.put(i, i);
+            mapGet(map, i);
+        }
+        test(get, null, map, new Integer(0));
+        for (IfNode ifNode : lastCompiledGraph.getNodes(IfNode.TYPE)) {
+            LogicNode condition = ifNode.condition();
+            if (ifNode.getTrueSuccessorProbability() < 0.4 && condition instanceof ObjectEqualsNode) {
+                assertTrue(ifNode.trueSuccessor().next() instanceof ReturnNode, "Expected return.", ifNode.trueSuccessor(), ifNode.trueSuccessor().next());
+            }
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/OffHeapUnsafeAccessTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+package org.graalvm.compiler.core.test;
+
+import java.lang.reflect.Field;
+
+import org.graalvm.compiler.nodes.NamedLocationIdentity;
+import org.graalvm.compiler.nodes.memory.ReadNode;
+import org.junit.Assert;
+import org.junit.Test;
+
+import jdk.vm.ci.meta.JavaKind;
+import sun.misc.Unsafe;
+
+/**
+ * Tests that off-heap memory writes don't prevent optimization of on-heap accesses.
+ */
+public class OffHeapUnsafeAccessTest extends GraalCompilerTest {
+
+    static final Unsafe UNSAFE = initUnsafe();
+
+    private static Unsafe initUnsafe() {
+        try {
+            // Fast path when we are trusted.
+            return Unsafe.getUnsafe();
+        } catch (SecurityException se) {
+            // Slow path when we are not trusted.
+            try {
+                Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
+                theUnsafe.setAccessible(true);
+                return (Unsafe) theUnsafe.get(Unsafe.class);
+            } catch (Exception e) {
+                throw new RuntimeException("exception while trying to get Unsafe", e);
+            }
+        }
+    }
+
+    public byte unboxByteAndStore(long memory, byte[] box) {
+        byte val = box[0];
+        UNSAFE.putByte(memory, val);
+        UNSAFE.putByte(null, memory, val);
+        return box[0];
+    }
+
+    public char unboxCharAndStore(long memory, char[] box) {
+        char val = box[0];
+        UNSAFE.putChar(memory, val);
+        UNSAFE.putChar(null, memory, val);
+        return box[0];
+    }
+
+    public int unboxIntAndStore(long memory, int[] box) {
+        int val = box[0];
+        UNSAFE.putInt(memory, val);
+        UNSAFE.putInt(null, memory, val);
+        return box[0];
+    }
+
+    public long unboxLongAndStore(long memory, long[] box) {
+        long val = box[0];
+        UNSAFE.putLong(memory, val);
+        UNSAFE.putLong(null, memory, val);
+        UNSAFE.putAddress(memory, val);
+        return box[0];
+    }
+
+    public float unboxFloatAndStore(long memory, float[] box) {
+        float val = box[0];
+        UNSAFE.putFloat(memory, val);
+        UNSAFE.putFloat(null, memory, val);
+        return box[0];
+    }
+
+    public double unboxDoubleAndStore(long memory, double[] box) {
+        double val = box[0];
+        UNSAFE.putDouble(memory, val);
+        UNSAFE.putDouble(null, memory, val);
+        return box[0];
+    }
+
+    private void assertExactlyOneArrayLoad(JavaKind elementKind) {
+        int total = 0;
+        for (ReadNode read : lastCompiledGraph.getNodes().filter(ReadNode.class)) {
+            if (read.getLocationIdentity().equals(NamedLocationIdentity.getArrayLocation(elementKind))) {
+                total++;
+            }
+        }
+        Assert.assertEquals(1, total);
+    }
+
+    @Test
+    public void testGet() {
+        long buf = allocBuf();
+        if (buf != 0) {
+            try {
+                test("unboxByteAndStore", buf, new byte[]{40});
+                assertExactlyOneArrayLoad(JavaKind.Byte);
+
+                test("unboxCharAndStore", buf, new char[]{41});
+                assertExactlyOneArrayLoad(JavaKind.Char);
+
+                test("unboxIntAndStore", buf, new int[]{42});
+                assertExactlyOneArrayLoad(JavaKind.Int);
+
+                test("unboxLongAndStore", buf, new long[]{43});
+                assertExactlyOneArrayLoad(JavaKind.Long);
+
+                test("unboxFloatAndStore", buf, new float[]{44.0F});
+                assertExactlyOneArrayLoad(JavaKind.Float);
+
+                test("unboxDoubleAndStore", buf, new double[]{45.0D});
+                assertExactlyOneArrayLoad(JavaKind.Double);
+            } finally {
+                UNSAFE.freeMemory(buf);
+            }
+        }
+    }
+
+    protected long allocBuf() {
+        try {
+            return UNSAFE.allocateMemory(16);
+        } catch (OutOfMemoryError e) {
+            return 0L;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/StableArrayReadFoldingTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,122 @@
+/*
+ * 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.
+ */
+package org.graalvm.compiler.core.test;
+
+import jdk.vm.ci.amd64.AMD64;
+import jdk.vm.ci.meta.ResolvedJavaMethod;
+
+import org.graalvm.compiler.core.common.CompilationIdentifier;
+import org.graalvm.compiler.nodes.ConstantNode;
+import org.graalvm.compiler.nodes.StructuredGraph;
+import org.graalvm.compiler.options.OptionValues;
+import org.junit.Assume;
+import org.junit.Test;
+
+public class StableArrayReadFoldingTest extends GraalCompilerTest {
+
+    static final boolean[] STABLE_BOOLEAN_ARRAY = new boolean[16];
+    static final int[] STABLE_INT_ARRAY = new int[16];
+
+    static final long BOOLEAN_ARRAY_BASE_OFFSET;
+    static final long INT_ARRAY_BASE_OFFSET;
+
+    static {
+        BOOLEAN_ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset(boolean[].class);
+        INT_ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset(int[].class);
+    }
+
+    @Override
+    protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) {
+        StructuredGraph graph = super.parseForCompile(method, compilationId, options);
+        // Mimic @Stable array constants.
+        for (ConstantNode constantNode : graph.getNodes().filter(ConstantNode.class).snapshot()) {
+            if (getConstantReflection().readArrayLength(constantNode.asJavaConstant()) != null) {
+                ConstantNode newConstantNode = graph.unique(ConstantNode.forConstant(constantNode.asJavaConstant(), 1, true, getMetaAccess()));
+                constantNode.replaceAndDelete(newConstantNode);
+            }
+        }
+        return graph;
+    }
+
+    public static boolean killWithSameType() {
+        boolean beforeKill = UNSAFE.getBoolean(STABLE_BOOLEAN_ARRAY, BOOLEAN_ARRAY_BASE_OFFSET);
+        STABLE_BOOLEAN_ARRAY[0] = true;
+        boolean afterKill = UNSAFE.getBoolean(STABLE_BOOLEAN_ARRAY, BOOLEAN_ARRAY_BASE_OFFSET);
+
+        STABLE_BOOLEAN_ARRAY[0] = false;
+        return beforeKill == afterKill;
+    }
+
+    @Test
+    public void testKillWithSameType() {
+        ResolvedJavaMethod method = getResolvedJavaMethod("killWithSameType");
+        testAgainstExpected(method, new Result(true, null), null);
+    }
+
+    public static boolean killWithDifferentType() {
+        byte beforeKill = UNSAFE.getByte(STABLE_BOOLEAN_ARRAY, BOOLEAN_ARRAY_BASE_OFFSET);
+        STABLE_BOOLEAN_ARRAY[0] = true;
+        byte afterKill = UNSAFE.getByte(STABLE_BOOLEAN_ARRAY, BOOLEAN_ARRAY_BASE_OFFSET);
+
+        STABLE_BOOLEAN_ARRAY[0] = false;
+        return beforeKill == afterKill;
+    }
+
+    @Test
+    public void testKillWithDifferentType() {
+        ResolvedJavaMethod method = getResolvedJavaMethod("killWithDifferentType");
+        testAgainstExpected(method, new Result(true, null), null);
+    }
+
+    public static boolean killWithSameTypeUnaligned() {
+        int beforeKill = UNSAFE.getInt(STABLE_INT_ARRAY, INT_ARRAY_BASE_OFFSET + 1);
+        STABLE_INT_ARRAY[0] = 0x01020304;
+        int afterKill = UNSAFE.getInt(STABLE_INT_ARRAY, INT_ARRAY_BASE_OFFSET + 1);
+
+        STABLE_INT_ARRAY[0] = 0;
+        return beforeKill == afterKill;
+    }
+
+    @Test
+    public void testKillWithSameTypeUnaligned() {
+        Assume.assumeTrue("Only test unaligned access on AMD64", getTarget().arch instanceof AMD64);
+        ResolvedJavaMethod method = getResolvedJavaMethod("killWithSameTypeUnaligned");
+        testAgainstExpected(method, new Result(true, null), null);
+    }
+
+    public static boolean killWithDifferentTypeUnaligned() {
+        byte beforeKill = UNSAFE.getByte(STABLE_INT_ARRAY, INT_ARRAY_BASE_OFFSET + 1);
+        STABLE_INT_ARRAY[0] = 0x01020304;
+        byte afterKill = UNSAFE.getByte(STABLE_INT_ARRAY, INT_ARRAY_BASE_OFFSET + 1);
+
+        STABLE_INT_ARRAY[0] = 0;
+        return beforeKill == afterKill;
+    }
+
+    @Test
+    public void testKillWithDifferentTypeUnaligned() {
+        Assume.assumeTrue("Only test unaligned access on AMD64", getTarget().arch instanceof AMD64);
+        ResolvedJavaMethod method = getResolvedJavaMethod("killWithDifferentTypeUnaligned");
+        testAgainstExpected(method, new Result(true, null), null);
+    }
+}
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/StaticInterfaceFieldTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/StaticInterfaceFieldTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -82,7 +82,7 @@
 
         PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
         Plugins plugins = new Plugins(new InvocationPlugins());
-        GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
+        GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
         graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
         HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
 
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/UnbalancedMonitorsTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/UnbalancedMonitorsTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -89,7 +89,7 @@
             OptionValues options = getInitialOptions();
             StructuredGraph graph = new StructuredGraph.Builder(options, getDebugContext(options)).method(method).build();
             Plugins plugins = new Plugins(new InvocationPlugins());
-            GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
+            GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
             OptimisticOptimizations optimisticOpts = OptimisticOptimizations.NONE;
 
             GraphBuilderPhase.Instance graphBuilder = new GraphBuilderPhase.Instance(getMetaAccess(), getProviders().getStampProvider(), null, null, graphBuilderConfig, optimisticOpts, null);
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/UnsafeReadEliminationTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/UnsafeReadEliminationTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -46,11 +46,13 @@
     public static double SideEffectD;
     public static double SideEffectL;
 
+    private static final long booleanArrayBaseOffset;
     private static final long byteArrayBaseOffset;
     private static final long intArrayBaseOffset;
     private static final long longArrayBaseOffset;
 
     static {
+        booleanArrayBaseOffset = UNSAFE.arrayBaseOffset(boolean[].class);
         byteArrayBaseOffset = UNSAFE.arrayBaseOffset(byte[].class);
         intArrayBaseOffset = UNSAFE.arrayBaseOffset(int[].class);
         longArrayBaseOffset = UNSAFE.arrayBaseOffset(long[].class);
@@ -212,4 +214,77 @@
         test("testWriteFloatToIntArraySnippet");
     }
 
+    public static final byte[] FINAL_BYTE_ARRAY = new byte[16];
+
+    public static boolean alignedKill() {
+        int beforeKill = UNSAFE.getInt(FINAL_BYTE_ARRAY, byteArrayBaseOffset);
+        FINAL_BYTE_ARRAY[0] = 1;
+        int afterKill = UNSAFE.getInt(FINAL_BYTE_ARRAY, byteArrayBaseOffset);
+
+        FINAL_BYTE_ARRAY[0] = 0; // reset
+        return beforeKill == afterKill;
+    }
+
+    @Test
+    public void testAlignedKill() {
+        test("alignedKill");
+    }
+
+    public static boolean unalignedKill() {
+        int beforeKill = UNSAFE.getInt(FINAL_BYTE_ARRAY, byteArrayBaseOffset);
+        FINAL_BYTE_ARRAY[1] = 1;
+        int afterKill = UNSAFE.getInt(FINAL_BYTE_ARRAY, byteArrayBaseOffset);
+
+        FINAL_BYTE_ARRAY[1] = 0; // reset
+        return beforeKill == afterKill;
+    }
+
+    @Test
+    public void testUnalignedKill() {
+        test("unalignedKill");
+    }
+
+    public static final boolean[] FINAL_BOOLEAN_ARRAY = new boolean[16];
+
+    public static boolean killBooleanAccessToBooleanArrayViaBASTORE() {
+        boolean beforeKill = UNSAFE.getBoolean(FINAL_BOOLEAN_ARRAY, booleanArrayBaseOffset);
+        FINAL_BOOLEAN_ARRAY[0] = true;
+        boolean afterKill = UNSAFE.getBoolean(FINAL_BOOLEAN_ARRAY, booleanArrayBaseOffset);
+
+        FINAL_BOOLEAN_ARRAY[0] = false; // reset
+        return beforeKill == afterKill;
+    }
+
+    @Test
+    public void testKillBooleanAccessToBooleanArrayViaBASTORE() {
+        test("killBooleanAccessToBooleanArrayViaBASTORE");
+    }
+
+    public static boolean killByteAccessToBooleanArrayViaBASTORE() {
+        byte beforeKill = UNSAFE.getByte(FINAL_BOOLEAN_ARRAY, booleanArrayBaseOffset);
+        FINAL_BOOLEAN_ARRAY[0] = true;
+        byte afterKill = UNSAFE.getByte(FINAL_BOOLEAN_ARRAY, booleanArrayBaseOffset);
+
+        FINAL_BOOLEAN_ARRAY[0] = false; // reset
+        return beforeKill == afterKill;
+    }
+
+    @Test
+    public void testKillByteAccessToBooleanArrayViaBASTORE() {
+        test("killByteAccessToBooleanArrayViaBASTORE");
+    }
+
+    public static boolean unsafeWriteToBooleanArray() {
+        UNSAFE.putByte(FINAL_BOOLEAN_ARRAY, booleanArrayBaseOffset, (byte) 2);
+        boolean result = UNSAFE.getBoolean(FINAL_BOOLEAN_ARRAY, booleanArrayBaseOffset);
+
+        FINAL_BOOLEAN_ARRAY[0] = false; // reset
+        return result;
+    }
+
+    @Test
+    public void testUnsafeWriteToBooleanArray() {
+        test("unsafeWriteToBooleanArray");
+    }
+
 }
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyBailoutUsageTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyBailoutUsageTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -123,7 +123,7 @@
         MetaAccessProvider metaAccess = providers.getMetaAccess();
         PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
         Plugins plugins = new Plugins(new InvocationPlugins());
-        GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
+        GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
         graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
         HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
         OptionValues options = getInitialOptions();
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyDebugUsageTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyDebugUsageTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -344,7 +344,7 @@
         MetaAccessProvider metaAccess = providers.getMetaAccess();
         PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
         Plugins plugins = new Plugins(new InvocationPlugins());
-        GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
+        GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
         graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
         HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
         OptionValues options = getInitialOptions();
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyVirtualizableTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyVirtualizableTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -268,7 +268,7 @@
         MetaAccessProvider metaAccess = providers.getMetaAccess();
         PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
         Plugins plugins = new Plugins(new InvocationPlugins());
-        GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
+        GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
         graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
         HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
         OptionValues options = getInitialOptions();
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/PEAReadEliminationTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/PEAReadEliminationTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -22,6 +22,7 @@
  */
 package org.graalvm.compiler.core.test.ea;
 
+import org.graalvm.compiler.core.test.GraalCompilerTest;
 import org.junit.Test;
 
 import sun.misc.Unsafe;
@@ -36,7 +37,7 @@
 import org.graalvm.compiler.phases.tiers.HighTierContext;
 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
 
-public class PEAReadEliminationTest extends EarlyReadEliminationTest {
+public class PEAReadEliminationTest extends GraalCompilerTest {
 
     public static int testIndexed1Snippet(int[] array) {
         array[1] = 1;
@@ -50,7 +51,7 @@
 
     @Test
     public void testIndexed1() {
-        StructuredGraph graph = processMethod("testIndexed1Snippet", false);
+        StructuredGraph graph = processMethod("testIndexed1Snippet");
         assertDeepEquals(0, graph.getNodes().filter(LoadIndexedNode.class).count());
     }
 
@@ -70,7 +71,7 @@
 
     @Test
     public void testIndexed2() {
-        StructuredGraph graph = processMethod("testIndexed2Snippet", false);
+        StructuredGraph graph = processMethod("testIndexed2Snippet");
         assertDeepEquals(3, graph.getNodes().filter(LoadIndexedNode.class).count());
         assertDeepEquals(7, graph.getNodes().filter(StoreIndexedNode.class).count());
     }
@@ -94,7 +95,7 @@
 
     @Test
     public void testIndexed3() {
-        StructuredGraph graph = processMethod("testIndexed3Snippet", false);
+        StructuredGraph graph = processMethod("testIndexed3Snippet");
         assertDeepEquals(3, graph.getNodes().filter(LoadIndexedNode.class).count());
     }
 
@@ -113,7 +114,7 @@
 
     @Test
     public void testIndexed4() {
-        StructuredGraph graph = processMethod("testIndexed4Snippet", false);
+        StructuredGraph graph = processMethod("testIndexed4Snippet");
         assertDeepEquals(3, graph.getNodes().filter(LoadIndexedNode.class).count());
     }
 
@@ -129,7 +130,7 @@
 
     @Test
     public void testUnsafe1() {
-        StructuredGraph graph = processMethod("testUnsafe1Snippet", false);
+        StructuredGraph graph = processMethod("testUnsafe1Snippet");
         assertDeepEquals(1, graph.getNodes().filter(RawLoadNode.class).count());
     }
 
@@ -142,7 +143,7 @@
 
     @Test
     public void testUnsafe2() {
-        StructuredGraph graph = processMethod("testUnsafe2Snippet", false);
+        StructuredGraph graph = processMethod("testUnsafe2Snippet");
         assertDeepEquals(3, graph.getNodes().filter(RawLoadNode.class).count());
     }
 
@@ -158,7 +159,7 @@
 
     @Test
     public void testUnsafe3() {
-        StructuredGraph graph = processMethod("testUnsafe3Snippet", false);
+        StructuredGraph graph = processMethod("testUnsafe3Snippet");
         assertDeepEquals(1, graph.getNodes().filter(RawLoadNode.class).count());
     }
 
@@ -172,28 +173,11 @@
 
     @Test
     public void testUnsafe4() {
-        StructuredGraph graph = processMethod("testUnsafe4Snippet", false);
+        StructuredGraph graph = processMethod("testUnsafe4Snippet");
         assertDeepEquals(3, graph.getNodes().filter(RawLoadNode.class).count());
     }
 
-    private static final long offsetLong1 = Unsafe.ARRAY_LONG_BASE_OFFSET + Unsafe.ARRAY_LONG_INDEX_SCALE * 1;
-    private static final long offsetLong2 = Unsafe.ARRAY_LONG_BASE_OFFSET + Unsafe.ARRAY_LONG_INDEX_SCALE * 2;
-
-    public static int testUnsafe5Snippet(int v, long[] array) {
-        int s = UNSAFE.getInt(array, offsetLong1);
-        UNSAFE.putInt(array, offsetLong1, v);
-        UNSAFE.putInt(array, offsetLong2, v);
-        return s + UNSAFE.getInt(array, offsetLong1) + UNSAFE.getInt(array, offsetLong2);
-    }
-
-    @Test
-    public void testUnsafe5() {
-        StructuredGraph graph = processMethod("testUnsafe5Snippet", false);
-        assertDeepEquals(1, graph.getNodes().filter(RawLoadNode.class).count());
-    }
-
-    @Override
-    protected StructuredGraph processMethod(final String snippet, boolean doLowering) {
+    protected StructuredGraph processMethod(final String snippet) {
         StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
         HighTierContext context = getDefaultHighTierContext();
         new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/TrufflePEATest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2017, 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.
+ */
+package org.graalvm.compiler.core.test.ea;
+
+import org.graalvm.compiler.core.common.GraalOptions;
+import org.graalvm.compiler.core.test.GraalCompilerTest;
+import org.graalvm.compiler.nodes.StructuredGraph;
+import org.graalvm.compiler.nodes.extended.RawLoadNode;
+import org.graalvm.compiler.nodes.extended.RawStoreNode;
+import org.graalvm.compiler.nodes.virtual.CommitAllocationNode;
+import org.graalvm.compiler.phases.common.CanonicalizerPhase;
+import org.graalvm.compiler.phases.common.inlining.InliningPhase;
+import org.graalvm.compiler.phases.tiers.HighTierContext;
+import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
+import org.junit.Test;
+import sun.misc.Unsafe;
+
+import java.lang.reflect.Field;
+
+public class TrufflePEATest extends GraalCompilerTest {
+
+    /**
+     * This class mimics the behavior of {@code FrameWithoutBoxing}.
+     */
+    static class Frame {
+        long[] primitiveLocals;
+
+        Frame(int size) {
+            primitiveLocals = new long[size];
+        }
+    }
+
+    /**
+     * This class mimics the behavior of {@code DynamicObjectL6I6}.
+     */
+    static class DynamicObject {
+        int primitiveField0;
+        int primitiveField1;
+    }
+
+    private static final long offsetLong1 = Unsafe.ARRAY_LONG_BASE_OFFSET + Unsafe.ARRAY_LONG_INDEX_SCALE * 1;
+    private static final long offsetLong2 = Unsafe.ARRAY_LONG_BASE_OFFSET + Unsafe.ARRAY_LONG_INDEX_SCALE * 2;
+
+    private static final long primitiveField0Offset;
+
+    static {
+        try {
+            Field primitiveField0 = DynamicObject.class.getDeclaredField("primitiveField0");
+            primitiveField0Offset = UNSAFE.objectFieldOffset(primitiveField0);
+        } catch (NoSuchFieldException | SecurityException e) {
+            throw new AssertionError(e);
+        }
+    }
+
+    public static int unsafeAccessToLongArray(int v, Frame frame) {
+        long[] array = frame.primitiveLocals;
+        int s = UNSAFE.getInt(array, offsetLong1);
+        UNSAFE.putInt(array, offsetLong1, v);
+        UNSAFE.putInt(array, offsetLong2, v);
+        return s + UNSAFE.getInt(array, offsetLong1) + UNSAFE.getInt(array, offsetLong2);
+    }
+
+    @Test
+    public void testUnsafeAccessToLongArray() {
+        StructuredGraph graph = processMethod("unsafeAccessToLongArray");
+        assertDeepEquals(1, graph.getNodes().filter(RawLoadNode.class).count());
+    }
+
+    /**
+     * The following value should be less than the default value of
+     * {@link GraalOptions#MaximumEscapeAnalysisArrayLength}.
+     */
+    private static final int FRAME_SIZE = 16;
+
+    public static long newFrame(long v) {
+        Frame frame = new Frame(FRAME_SIZE);
+        // Testing unsafe accesses with other kinds requires special handling of the initialized
+        // entry kind.
+        UNSAFE.putLong(frame.primitiveLocals, offsetLong1, v);
+        return UNSAFE.getLong(frame.primitiveLocals, offsetLong1);
+    }
+
+    @Test
+    public void testNewFrame() {
+        StructuredGraph graph = processMethod("newFrame");
+        assertDeepEquals(0, graph.getNodes().filter(CommitAllocationNode.class).count());
+        assertDeepEquals(0, graph.getNodes().filter(RawLoadNode.class).count());
+        assertDeepEquals(0, graph.getNodes().filter(RawStoreNode.class).count());
+    }
+
+    protected StructuredGraph processMethod(final String snippet) {
+        StructuredGraph graph = parseEager(snippet, StructuredGraph.AllowAssumptions.NO);
+        HighTierContext context = getDefaultHighTierContext();
+        new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
+        new PartialEscapePhase(true, true, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
+        return graph;
+    }
+
+    public static double accessDynamicObject(double v) {
+        DynamicObject obj = new DynamicObject();
+        UNSAFE.putDouble(obj, primitiveField0Offset, v);
+        return UNSAFE.getDouble(obj, primitiveField0Offset);
+    }
+
+    @Test
+    public void testAccessDynamicObject() {
+        StructuredGraph graph = processMethod("accessDynamicObject");
+        assertDeepEquals(0, graph.getNodes().filter(CommitAllocationNode.class).count());
+        assertDeepEquals(0, graph.getNodes().filter(RawLoadNode.class).count());
+        assertDeepEquals(0, graph.getNodes().filter(RawStoreNode.class).count());
+    }
+
+}
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/tutorial/StaticAnalysis.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/tutorial/StaticAnalysis.java	Sat Oct 21 00:06:50 2017 +0000
@@ -256,7 +256,7 @@
                      * yet and the bytecode parser would only create a graph.
                      */
                     Plugins plugins = new Plugins(new InvocationPlugins());
-                    GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
+                    GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
                     /*
                      * For simplicity, we ignore all exception handling during the static analysis.
                      * This is a constraint of this example code, a real static analysis needs to
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/GraalError.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/GraalError.java	Sat Oct 21 00:06:50 2017 +0000
@@ -181,6 +181,12 @@
     public String toString() {
         StringBuilder str = new StringBuilder();
         str.append(super.toString());
+        str.append(context());
+        return str.toString();
+    }
+
+    public String context() {
+        StringBuilder str = new StringBuilder();
         for (String s : context) {
             str.append("\n\tat ").append(s);
         }
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/Node.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/Node.java	Sat Oct 21 00:06:50 2017 +0000
@@ -38,6 +38,7 @@
 import java.util.Map;
 import java.util.Objects;
 import java.util.function.Predicate;
+import java.util.function.Supplier;
 
 import org.graalvm.compiler.core.common.Fields;
 import org.graalvm.compiler.core.common.type.AbstractPointerStamp;
@@ -598,6 +599,15 @@
         }
     }
 
+    /**
+     * Update the source position only if it is null.
+     */
+    public void updateNodeSourcePosition(Supplier<NodeSourcePosition> sourcePositionSupp) {
+        if (this.sourcePosition == null) {
+            setNodeSourcePosition(sourcePositionSupp.get());
+        }
+    }
+
     public DebugCloseable withNodeSourcePosition() {
         return graph.withNodeSourcePosition(this);
     }
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/NodeBitMap.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/NodeBitMap.java	Sat Oct 21 00:06:50 2017 +0000
@@ -195,7 +195,7 @@
                     Node result = graph.getNode(nodeId);
                     if (result == null) {
                         // node was deleted -> clear the bit and continue searching
-                        bits[wordIndex] = bits[wordIndex] & ~(1 << bitIndex);
+                        bits[wordIndex] = bits[wordIndex] & ~(1L << bitIndex);
                         int nextNodeId = nodeId + 1;
                         if ((nextNodeId & (Long.SIZE - 1)) == 0) {
                             // we reached the end of this word
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotLIRGenerator.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotLIRGenerator.java	Sat Oct 21 00:06:50 2017 +0000
@@ -28,6 +28,10 @@
 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_KLASS_BY_SYMBOL;
 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS;
 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_STRING_BY_SYMBOL;
+import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_DYNAMIC_INVOKE;
+import static org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction.RESOLVE;
+import static org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction.INITIALIZE;
+import static org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction.LOAD_COUNTERS;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -39,6 +43,7 @@
 import org.graalvm.compiler.core.amd64.AMD64MoveFactoryBase.BackupSlotProvider;
 import org.graalvm.compiler.core.common.CompressEncoding;
 import org.graalvm.compiler.core.common.LIRKind;
+import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
 import org.graalvm.compiler.core.common.spi.ForeignCallLinkage;
 import org.graalvm.compiler.core.common.spi.LIRKindTool;
 import org.graalvm.compiler.debug.DebugContext;
@@ -415,49 +420,49 @@
         return result;
     }
 
-    @Override
-    public Value emitObjectConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) {
-        ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(RESOLVE_STRING_BY_SYMBOL);
-        Constant[] constants = new Constant[]{constant};
-        AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(constantDescription)};
-        Object[] notes = new Object[]{HotSpotConstantLoadAction.RESOLVE};
-        append(new AMD64HotSpotConstantRetrievalOp(constants, constantDescriptions, frameState, linkage, notes));
-        AllocatableValue result = linkage.getOutgoingCallingConvention().getReturn();
-        return emitMove(result);
-    }
-
-    @Override
-    public Value emitMetaspaceConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) {
-        ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(RESOLVE_KLASS_BY_SYMBOL);
-        Constant[] constants = new Constant[]{constant};
-        AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(constantDescription)};
-        Object[] notes = new Object[]{HotSpotConstantLoadAction.RESOLVE};
+    private Value emitConstantRetrieval(ForeignCallDescriptor foreignCall, Object[] notes, Constant[] constants, AllocatableValue[] constantDescriptions, LIRFrameState frameState) {
+        ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(foreignCall);
         append(new AMD64HotSpotConstantRetrievalOp(constants, constantDescriptions, frameState, linkage, notes));
         AllocatableValue result = linkage.getOutgoingCallingConvention().getReturn();
         return emitMove(result);
     }
 
+    private Value emitConstantRetrieval(ForeignCallDescriptor foreignCall, HotSpotConstantLoadAction action, Constant constant, AllocatableValue[] constantDescriptions, LIRFrameState frameState) {
+        Constant[] constants = new Constant[]{constant};
+        Object[] notes = new Object[]{action};
+        return emitConstantRetrieval(foreignCall, notes, constants, constantDescriptions, frameState);
+    }
+
+    private Value emitConstantRetrieval(ForeignCallDescriptor foreignCall, HotSpotConstantLoadAction action, Constant constant, Value constantDescription, LIRFrameState frameState) {
+        AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(constantDescription)};
+        return emitConstantRetrieval(foreignCall, action, constant, constantDescriptions, frameState);
+    }
+
     @Override
-    public Value emitResolveMethodAndLoadCounters(Constant method, Value klassHint, Value methodDescription, LIRFrameState frameState) {
-        ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS);
-        Constant[] constants = new Constant[]{method};
-        AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(klassHint), asAllocatable(methodDescription)};
-        Object[] notes = new Object[]{HotSpotConstantLoadAction.LOAD_COUNTERS};
-        append(new AMD64HotSpotConstantRetrievalOp(constants, constantDescriptions, frameState, linkage, notes));
-        AllocatableValue result = linkage.getOutgoingCallingConvention().getReturn();
-        return emitMove(result);
+    public Value emitObjectConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) {
+        return emitConstantRetrieval(RESOLVE_STRING_BY_SYMBOL, RESOLVE, constant, constantDescription, frameState);
+    }
 
+    @Override
+    public Value emitMetaspaceConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) {
+        return emitConstantRetrieval(RESOLVE_KLASS_BY_SYMBOL, RESOLVE, constant, constantDescription, frameState);
     }
 
     @Override
     public Value emitKlassInitializationAndRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) {
-        ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(INITIALIZE_KLASS_BY_SYMBOL);
-        Constant[] constants = new Constant[]{constant};
-        AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(constantDescription)};
-        Object[] notes = new Object[]{HotSpotConstantLoadAction.INITIALIZE};
-        append(new AMD64HotSpotConstantRetrievalOp(constants, constantDescriptions, frameState, linkage, notes));
-        AllocatableValue result = linkage.getOutgoingCallingConvention().getReturn();
-        return emitMove(result);
+        return emitConstantRetrieval(INITIALIZE_KLASS_BY_SYMBOL, INITIALIZE, constant, constantDescription, frameState);
+    }
+
+    @Override
+    public Value emitResolveMethodAndLoadCounters(Constant method, Value klassHint, Value methodDescription, LIRFrameState frameState) {
+        AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(klassHint), asAllocatable(methodDescription)};
+        return emitConstantRetrieval(RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS, LOAD_COUNTERS, method, constantDescriptions, frameState);
+    }
+
+    @Override
+    public Value emitResolveDynamicInvoke(Constant appendix, LIRFrameState frameState) {
+        AllocatableValue[] constantDescriptions = new AllocatableValue[0];
+        return emitConstantRetrieval(RESOLVE_DYNAMIC_INVOKE, INITIALIZE, appendix, constantDescriptions, frameState);
     }
 
     @Override
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.sparc/src/org/graalvm/compiler/hotspot/sparc/SPARCHotSpotLIRGenerator.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.sparc/src/org/graalvm/compiler/hotspot/sparc/SPARCHotSpotLIRGenerator.java	Sat Oct 21 00:06:50 2017 +0000
@@ -27,6 +27,7 @@
 import static org.graalvm.compiler.lir.LIRValueUtil.asConstant;
 import static org.graalvm.compiler.lir.LIRValueUtil.isConstantValue;
 
+import org.graalvm.compiler.asm.sparc.SPARCAssembler;
 import org.graalvm.compiler.core.common.CompressEncoding;
 import org.graalvm.compiler.core.common.LIRKind;
 import org.graalvm.compiler.core.common.calc.Condition;
@@ -255,7 +256,7 @@
     @Override
     public void emitPrefetchAllocate(Value address) {
         SPARCAddressValue addr = asAddressValue(address);
-        append(new SPARCPrefetchOp(addr, config.allocatePrefetchInstr));
+        append(new SPARCPrefetchOp(addr, SPARCAssembler.Fcn.SeveralWritesAndPossiblyReads));
     }
 
     public StackSlot getDeoptimizationRescueSlot() {
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/CompileTheWorld.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/CompileTheWorld.java	Sat Oct 21 00:06:50 2017 +0000
@@ -52,8 +52,10 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
@@ -475,6 +477,7 @@
     private void compile(String classPath) throws IOException {
         final String[] entries = classPath.split(File.pathSeparator);
         long start = System.currentTimeMillis();
+        Map<Thread, StackTraceElement[]> initialThreads = Thread.getAllStackTraces();
 
         try {
             // compile dummy method to get compiler initialized outside of the
@@ -549,7 +552,13 @@
 
                     classFileCounter++;
 
-                    if (className.startsWith("jdk.management.") || className.startsWith("jdk.internal.cmm.*")) {
+                    if (className.startsWith("jdk.management.") ||
+                                    className.startsWith("jdk.internal.cmm.*") ||
+                                    // GR-5881: The class initializer for
+                                    // sun.tools.jconsole.OutputViewer
+                                    // spawns non-daemon threads for redirecting sysout and syserr.
+                                    // These threads tend to cause deadlock at VM exit
+                                    className.startsWith("sun.tools.jconsole.")) {
                         continue;
                     }
 
@@ -643,6 +652,33 @@
         } else {
             TTY.println("CompileTheWorld : Done (%d classes, %d methods, %d ms, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), compileTime.get(), memoryUsed.get());
         }
+
+        // Apart from the main thread, there should be only be daemon threads
+        // alive now. If not, then a class initializer has probably started
+        // a thread that could cause a deadlock while trying to exit the VM.
+        // One known example of this is sun.tools.jconsole.OutputViewer which
+        // spawns threads to redirect sysout and syserr. To help debug such
+        // scenarios, the stacks of potentially problematic threads are dumped.
+        Map<Thread, StackTraceElement[]> suspiciousThreads = new HashMap<>();
+        for (Map.Entry<Thread, StackTraceElement[]> e : Thread.getAllStackTraces().entrySet()) {
+            Thread thread = e.getKey();
+            if (thread != Thread.currentThread() && !initialThreads.containsKey(thread) && !thread.isDaemon() && thread.isAlive()) {
+                suspiciousThreads.put(thread, e.getValue());
+            }
+        }
+        if (!suspiciousThreads.isEmpty()) {
+            TTY.println("--- Non-daemon threads started during CTW ---");
+            for (Map.Entry<Thread, StackTraceElement[]> e : suspiciousThreads.entrySet()) {
+                Thread thread = e.getKey();
+                if (thread.isAlive()) {
+                    TTY.println(thread.toString() + " " + thread.getState());
+                    for (StackTraceElement ste : e.getValue()) {
+                        TTY.println("\tat " + ste);
+                    }
+                }
+            }
+            TTY.println("---------------------------------------------");
+        }
     }
 
     private synchronized void startThreads() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/HotSpotInvokeDynamicPluginTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,145 @@
+/*
+ * 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.
+ */
+package org.graalvm.compiler.hotspot.test;
+
+import java.util.function.IntPredicate;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import jdk.vm.ci.meta.ResolvedJavaMethod;
+import java.security.PrivilegedAction;
+import org.graalvm.compiler.core.common.GraalOptions;
+import org.graalvm.compiler.hotspot.meta.HotSpotClassInitializationPlugin;
+import org.graalvm.compiler.hotspot.meta.HotSpotInvokeDynamicPlugin;
+import org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode;
+import org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicStubCall;
+import org.graalvm.compiler.nodes.StructuredGraph;
+import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
+import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
+import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
+import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo;
+import org.graalvm.compiler.nodes.ValueNode;
+import org.graalvm.compiler.nodes.spi.LoweringTool;
+import org.graalvm.compiler.options.OptionValues;
+import org.graalvm.compiler.phases.OptimisticOptimizations;
+import org.graalvm.compiler.phases.common.CanonicalizerPhase;
+import org.graalvm.compiler.phases.common.LoweringPhase;
+import org.graalvm.compiler.phases.common.FrameStateAssignmentPhase;
+import org.graalvm.compiler.phases.common.GuardLoweringPhase;
+import org.graalvm.compiler.phases.tiers.PhaseContext;
+import org.graalvm.compiler.phases.tiers.MidTierContext;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class HotSpotInvokeDynamicPluginTest extends HotSpotGraalCompilerTest {
+    @Override
+    protected Plugins getDefaultGraphBuilderPlugins() {
+        Plugins plugins = super.getDefaultGraphBuilderPlugins();
+        plugins.setClassInitializationPlugin(new HotSpotClassInitializationPlugin());
+        plugins.setInvokeDynamicPlugin(new HotSpotInvokeDynamicPlugin() {
+            @Override
+            public boolean isResolvedDynamicInvoke(GraphBuilderContext builder, int index, int opcode) {
+                // Allow invokedynamic testing with older JVMCI
+                ResolvedJavaMethod m = builder.getMethod();
+                if (m.getName().startsWith("invokeDynamic") && m.getDeclaringClass().getName().equals("Lorg/graalvm/compiler/hotspot/test/HotSpotInvokeDynamicPluginTest;")) {
+                    return false;
+                }
+                return super.isResolvedDynamicInvoke(builder, index, opcode);
+            }
+
+            @Override
+            public boolean supportsDynamicInvoke(GraphBuilderContext builder, int index, int opcode) {
+                // Allow invokehandle testing with older JVMCI
+                ResolvedJavaMethod m = builder.getMethod();
+                if (m.getName().startsWith("invokeHandle") && m.getDeclaringClass().getName().equals("Lorg/graalvm/compiler/hotspot/test/HotSpotInvokeDynamicPluginTest;")) {
+                    return true;
+                }
+                return super.supportsDynamicInvoke(builder, index, opcode);
+            }
+        });
+        return plugins;
+    }
+
+    @Override
+    protected InlineInfo bytecodeParserShouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
+        return InlineInfo.DO_NOT_INLINE_NO_EXCEPTION;
+    }
+
+    private void test(String name, int expectedResolves, int expectedStubCalls) {
+        StructuredGraph graph = parseEager(name, AllowAssumptions.NO, new OptionValues(getInitialOptions(), GraalOptions.GeneratePIC, true));
+        MidTierContext midTierContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
+
+        CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
+        Assert.assertEquals(expectedResolves, graph.getNodes().filter(ResolveDynamicConstantNode.class).count());
+        Assert.assertEquals(0, graph.getNodes().filter(ResolveDynamicStubCall.class).count());
+        PhaseContext context = new PhaseContext(getProviders());
+        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
+        new GuardLoweringPhase().apply(graph, midTierContext);
+        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
+        new FrameStateAssignmentPhase().apply(graph);
+        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.LOW_TIER).apply(graph, context);
+        Assert.assertEquals(0, graph.getNodes().filter(ResolveDynamicConstantNode.class).count());
+        Assert.assertEquals(expectedStubCalls, graph.getNodes().filter(ResolveDynamicStubCall.class).count());
+    }
+
+    public static IntPredicate invokeDynamic1() {
+        IntPredicate i = (v) -> v > 1;
+        return i;
+    }
+
+    public static PrivilegedAction<Integer> invokeDynamic2(String s) {
+        return s::length;
+    }
+
+    static final MethodHandle objToStringMH;
+
+    static {
+        MethodHandle mh = null;
+        try {
+            mh = MethodHandles.lookup().findVirtual(Object.class, "toString", MethodType.methodType(String.class));
+        } catch (Exception e) {
+        }
+        objToStringMH = mh;
+    }
+
+    // invokehandle
+    public static String invokeHandle1(Object o) throws Throwable {
+        return (String) objToStringMH.invokeExact(o);
+    }
+
+    @Test
+    public void test1() {
+        test("invokeDynamic1", 1, 1);
+    }
+
+    @Test
+    public void test2() {
+        test("invokeDynamic2", 1, 1);
+    }
+
+    @Test
+    public void test3() {
+        test("invokeHandle1", 1, 1);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/HsErrLogTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,153 @@
+/*
+ * 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.
+ */
+package org.graalvm.compiler.hotspot.test;
+
+import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine;
+import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.graalvm.compiler.api.directives.GraalDirectives;
+import org.graalvm.compiler.core.test.GraalCompilerTest;
+import org.graalvm.compiler.test.SubprocessUtil;
+import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
+import org.junit.Assert;
+import org.junit.Test;
+
+import sun.misc.Unsafe;
+
+/**
+ * Tests that a hs_err crash log contains expected content.
+ */
+public class HsErrLogTest extends GraalCompilerTest {
+
+    @Test
+    public void test1() throws IOException, InterruptedException {
+        List<String> args = new ArrayList<>();
+        if (Java8OrEarlier) {
+            args.add("-XX:-UseJVMCIClassLoader");
+        }
+        args.add("-XX:+UseJVMCICompiler");
+        args.add("-XX:CompileOnly=" + Crasher.class.getName() + "::tryCrash");
+        args.add(Crasher.class.getName());
+        testHelper(args);
+    }
+
+    private static final boolean VERBOSE = Boolean.getBoolean(HsErrLogTest.class.getSimpleName() + ".verbose");
+
+    private static void testHelper(List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException {
+        List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
+        vmArgs.removeIf(a -> a.startsWith("-Dgraal."));
+        vmArgs.remove("-esa");
+        vmArgs.remove("-ea");
+        vmArgs.addAll(extraVmArgs);
+
+        Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs);
+        if (VERBOSE) {
+            System.out.println(proc);
+        }
+
+        Pattern re = Pattern.compile("# +(.*hs_err_pid[\\d]+\\.log)");
+
+        for (String line : proc.output) {
+            Matcher m = re.matcher(line);
+            if (m.matches()) {
+                File path = new File(m.group(1));
+                Assert.assertTrue(path.toString(), path.exists());
+                checkHsErr(path);
+                return;
+            }
+        }
+
+        Assert.fail("Could not find " + re.pattern());
+    }
+
+    private static void checkHsErr(File hsErrPath) {
+        try (BufferedReader br = new BufferedReader(new FileReader(hsErrPath))) {
+            String line = br.readLine();
+            String sig = Crasher.class.getName() + ".tryCrash(JI)I";
+            List<String> lines = new ArrayList<>();
+            while (line != null) {
+                if (line.contains(sig)) {
+                    if (!VERBOSE) {
+                        hsErrPath.delete();
+                    }
+                    return;
+                }
+                lines.add(line);
+                line = br.readLine();
+            }
+            throw new AssertionError("Could not find line containing \"" + sig + "\" in " + hsErrPath +
+                            ":" + System.lineSeparator() + String.join(System.lineSeparator(), lines));
+        } catch (IOException e) {
+            throw new AssertionError(e);
+        }
+    }
+}
+
+class Crasher {
+    public static void main(String[] args) {
+        int iter = 0;
+        long mem = UNSAFE.allocateMemory(1000);
+        while (iter < Integer.MAX_VALUE) {
+            tryCrash(mem, iter);
+            iter++;
+        }
+    }
+
+    protected static int tryCrash(long mem, int iter) {
+        if (GraalDirectives.inCompiledCode()) {
+            UNSAFE.putInt(0, iter);
+            return 0;
+        } else {
+            UNSAFE.putInt(mem, iter);
+            return UNSAFE.getInt(mem);
+        }
+    }
+
+    static final Unsafe UNSAFE = initUnsafe();
+
+    private static Unsafe initUnsafe() {
+        try {
+            // Fast path when we are trusted.
+            return Unsafe.getUnsafe();
+        } catch (SecurityException se) {
+            // Slow path when we are not trusted.
+            try {
+                Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
+                theUnsafe.setAccessible(true);
+                return (Unsafe) theUnsafe.get(Unsafe.class);
+            } catch (Exception e) {
+                throw new RuntimeException("exception while trying to get Unsafe", e);
+            }
+        }
+    }
+}
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompilationTask.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompilationTask.java	Sat Oct 21 00:06:50 2017 +0000
@@ -240,7 +240,7 @@
     }
 
     /**
-     * @return the compilation id plus a trailing '%' is the compilation is an OSR to match
+     * @return the compilation id plus a trailing '%' if the compilation is an OSR to match
      *         PrintCompilation style output
      */
     public String getIdString() {
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompilerConfigurationFactory.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompilerConfigurationFactory.java	Sat Oct 21 00:06:50 2017 +0000
@@ -29,7 +29,6 @@
 import java.util.List;
 import java.util.stream.Collectors;
 
-import org.graalvm.compiler.debug.Assertions;
 import org.graalvm.compiler.debug.GraalError;
 import org.graalvm.compiler.options.Option;
 import org.graalvm.compiler.options.OptionKey;
@@ -73,7 +72,6 @@
     protected CompilerConfigurationFactory(String name, int autoSelectionPriority) {
         this.name = name;
         this.autoSelectionPriority = autoSelectionPriority;
-        assert checkAndAddNewFactory(this);
     }
 
     public abstract CompilerConfiguration createCompilerConfiguration();
@@ -127,18 +125,18 @@
     }
 
     /**
-     * List used to assert uniqueness of {@link #name} and {@link #autoSelectionPriority} across all
-     * {@link CompilerConfigurationFactory} instances.
+     * Asserts uniqueness of {@link #name} and {@link #autoSelectionPriority} for {@code factory} in
+     * {@code factories}.
      */
-    private static final List<CompilerConfigurationFactory> factories = Assertions.assertionsEnabled() ? new ArrayList<>() : null;
-
-    private static boolean checkAndAddNewFactory(CompilerConfigurationFactory factory) {
+    private static boolean checkUnique(CompilerConfigurationFactory factory, List<CompilerConfigurationFactory> factories) {
         for (CompilerConfigurationFactory other : factories) {
-            assert !other.name.equals(factory.name) : factory.getClass().getName() + " cannot have the same selector as " + other.getClass().getName() + ": " + factory.name;
-            assert other.autoSelectionPriority != factory.autoSelectionPriority : factory.getClass().getName() + " cannot have the same auto-selection priority as " + other.getClass().getName() +
-                            ": " + factory.autoSelectionPriority;
+            if (other != factory) {
+                assert !other.name.equals(factory.name) : factory.getClass().getName() + " cannot have the same selector as " + other.getClass().getName() + ": " + factory.name;
+                assert other.autoSelectionPriority != factory.autoSelectionPriority : factory.getClass().getName() + " cannot have the same auto-selection priority as " +
+                                other.getClass().getName() +
+                                ": " + factory.autoSelectionPriority;
+            }
         }
-        factories.add(factory);
         return true;
     }
 
@@ -148,6 +146,7 @@
     private static List<CompilerConfigurationFactory> getAllCandidates() {
         List<CompilerConfigurationFactory> candidates = new ArrayList<>();
         for (CompilerConfigurationFactory candidate : GraalServices.load(CompilerConfigurationFactory.class)) {
+            assert checkUnique(candidate, candidates);
             candidates.add(candidate);
         }
         Collections.sort(candidates);
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompilerRuntimeHotSpotVMConfig.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompilerRuntimeHotSpotVMConfig.java	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -35,6 +35,7 @@
     }
 
     public final long resolveStringBySymbol = getAddress("CompilerRuntime::resolve_string_by_symbol");
+    public final long resolveDynamicInvoke = getAddress("CompilerRuntime::resolve_dynamic_invoke");
     public final long resolveKlassBySymbol = getAddress("CompilerRuntime::resolve_klass_by_symbol");
     public final long resolveMethodBySymbolAndLoadCounters = getAddress("CompilerRuntime::resolve_method_by_symbol_and_load_counters");
     public final long initializeKlassBySymbol = getAddress("CompilerRuntime::initialize_klass_by_symbol");
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotBackend.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotBackend.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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,11 @@
     /**
      * @see ResolveConstantStubCall
      */
+    public static final ForeignCallDescriptor RESOLVE_DYNAMIC_INVOKE = new ForeignCallDescriptor("resolve_dynamic_invoke", Object.class, Word.class);
+
+    /**
+     * @see ResolveConstantStubCall
+     */
     public static final ForeignCallDescriptor RESOLVE_KLASS_BY_SYMBOL = new ForeignCallDescriptor("resolve_klass_by_symbol", Word.class, Word.class, Word.class);
 
     /**
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotLIRGenerator.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotLIRGenerator.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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,7 +68,7 @@
      * @return value of loaded address in register
      */
     default Value emitLoadObjectAddress(Constant constant) {
-        throw GraalError.unimplemented();
+        throw new GraalError("Emitting code to load an object address is not currently supported on %s", target().arch);
     }
 
     /**
@@ -79,7 +79,7 @@
      * @return Value of loaded address in register
      */
     default Value emitLoadMetaspaceAddress(Constant constant, HotSpotConstantLoadAction action) {
-        throw GraalError.unimplemented();
+        throw new GraalError("Emitting code to load a metaspace address is not currently supported on %s", target().arch);
     }
 
     /**
@@ -90,7 +90,7 @@
      * @return value of loaded global in register
      */
     default Value emitLoadConfigValue(int markId, LIRKind kind) {
-        throw GraalError.unimplemented();
+        throw new GraalError("Emitting code to load a config value is not currently supported on %s", target().arch);
     }
 
     /**
@@ -100,10 +100,21 @@
      * @param constantDescription a description of the string that need to be materialized (and
      *            interned) as java.lang.String, generated with {@link EncodedSymbolConstant}
      * @param frameState frame state for the runtime call
-     * @return Returns the address of the requested constant.
+     * @return the address of the requested constant.
      */
     default Value emitObjectConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) {
-        throw GraalError.unimplemented();
+        throw new GraalError("Emitting code to resolve an object constant is not currently supported on %s", target().arch);
+    }
+
+    /**
+     * Emits code to resolve a dynamic constant.
+     *
+     * @param constant original constant
+     * @param frameState frame state for the runtime call
+     * @return the address of the requested constant.
+     */
+    default Value emitResolveDynamicInvoke(Constant constant, LIRFrameState frameState) {
+        throw new GraalError("Emitting code to resolve a dynamic constant is not currently supported on %s", target().arch);
     }
 
     /**
@@ -113,10 +124,10 @@
      * @param constantDescription a symbolic description of the {@link HotSpotMetaspaceConstant}
      *            generated by {@link EncodedSymbolConstant}
      * @param frameState frame state for the runtime call
-     * @return Returns the address of the requested constant.
+     * @return the address of the requested constant.
      */
     default Value emitMetaspaceConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) {
-        throw GraalError.unimplemented();
+        throw new GraalError("Emitting code to resolve a metaspace constant is not currently supported on %s", target().arch);
     }
 
     /**
@@ -129,10 +140,10 @@
      * @param methodDescription is symbolic description of the constant generated by
      *            {@link EncodedSymbolConstant}
      * @param frameState frame state for the runtime call
-     * @return Returns the address of the requested constant.
+     * @return the address of the requested constant.
      */
     default Value emitResolveMethodAndLoadCounters(Constant method, Value klassHint, Value methodDescription, LIRFrameState frameState) {
-        throw GraalError.unimplemented();
+        throw new GraalError("Emitting code to resolve a method and load counters is not currently supported on %s", target().arch);
     }
 
     /**
@@ -144,10 +155,10 @@
      * @param constantDescription a symbolic description of the {@link HotSpotMetaspaceConstant}
      *            generated by {@link EncodedSymbolConstant}
      * @param frameState frame state for the runtime call
-     * @return Returns the address of the requested constant.
+     * @return the address of the requested constant.
      */
     default Value emitKlassInitializationAndRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) {
-        throw GraalError.unimplemented();
+        throw new GraalError("Emitting code to initialize a class is not currently supported on %s", target().arch);
     }
 
     /**
@@ -156,7 +167,7 @@
      * @return value of the counter
      */
     default Value emitRandomSeed() {
-        throw GraalError.unimplemented();
+        throw new GraalError("Emitting code to return a random seed is not currently supported on %s", target().arch);
     }
 
     /**
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/DefaultHotSpotLoweringProvider.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/DefaultHotSpotLoweringProvider.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -24,7 +24,6 @@
 
 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayBaseOffset;
 import static org.graalvm.compiler.core.common.GraalOptions.AlwaysInlineVTableStubs;
-import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
 import static org.graalvm.compiler.core.common.GraalOptions.InlineVTableStubs;
 import static org.graalvm.compiler.core.common.GraalOptions.OmitHotExceptionStacktrace;
 import static org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProviderImpl.OSR_MIGRATION_END;
@@ -70,6 +69,7 @@
 import org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier;
 import org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode;
 import org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode;
+import org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode;
 import org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode;
 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode;
 import org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp;
@@ -214,10 +214,8 @@
         arraycopySnippets = new ArrayCopySnippets.Templates(options, factories, runtime, providers, target);
         stringToBytesSnippets = new StringToBytesSnippets.Templates(options, factories, providers, target);
         hashCodeSnippets = new HashCodeSnippets.Templates(options, factories, providers, target);
-        if (GeneratePIC.getValue(options)) {
-            resolveConstantSnippets = new ResolveConstantSnippets.Templates(options, factories, providers, target);
-            profileSnippets = new ProfileSnippets.Templates(options, factories, providers, target);
-        }
+        resolveConstantSnippets = new ResolveConstantSnippets.Templates(options, factories, providers, target);
+        profileSnippets = new ProfileSnippets.Templates(options, factories, providers, target);
         providers.getReplacements().registerSnippetTemplateCache(new UnsafeArrayCopySnippets.Templates(options, factories, providers, target));
     }
 
@@ -364,6 +362,10 @@
             }
         } else if (n instanceof IdentityHashCodeNode) {
             hashCodeSnippets.lower((IdentityHashCodeNode) n, tool);
+        } else if (n instanceof ResolveDynamicConstantNode) {
+            if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
+                resolveConstantSnippets.lower((ResolveDynamicConstantNode) n, tool);
+            }
         } else if (n instanceof ResolveConstantNode) {
             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
                 resolveConstantSnippets.lower((ResolveConstantNode) n, tool);
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -22,8 +22,6 @@
  */
 package org.graalvm.compiler.hotspot.meta;
 
-import static jdk.vm.ci.meta.DeoptimizationAction.InvalidateRecompile;
-import static jdk.vm.ci.meta.DeoptimizationReason.Unresolved;
 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
 import static org.graalvm.compiler.hotspot.meta.HotSpotAOTProfilingPlugin.Options.TieredAOT;
 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.JAVA_THREAD_THREAD_OBJECT_LOCATION;
@@ -63,7 +61,6 @@
 import org.graalvm.compiler.hotspot.replacements.arraycopy.ArrayCopyNode;
 import org.graalvm.compiler.hotspot.word.HotSpotWordTypes;
 import org.graalvm.compiler.nodes.ConstantNode;
-import org.graalvm.compiler.nodes.DeoptimizeNode;
 import org.graalvm.compiler.nodes.DynamicPiNode;
 import org.graalvm.compiler.nodes.FixedGuardNode;
 import org.graalvm.compiler.nodes.LogicNode;
@@ -80,7 +77,6 @@
 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration;
 import org.graalvm.compiler.nodes.graphbuilderconf.NodeIntrinsicPluginFactory;
-import org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin;
 import org.graalvm.compiler.nodes.java.InstanceOfDynamicNode;
 import org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType;
 import org.graalvm.compiler.nodes.memory.address.AddressNode;
@@ -101,13 +97,9 @@
 import org.graalvm.word.LocationIdentity;
 
 import jdk.vm.ci.code.CodeUtil;
-import jdk.vm.ci.hotspot.HotSpotObjectConstant;
-import jdk.vm.ci.hotspot.HotSpotResolvedJavaType;
-import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
 import jdk.vm.ci.meta.ConstantReflectionProvider;
 import jdk.vm.ci.meta.DeoptimizationAction;
 import jdk.vm.ci.meta.DeoptimizationReason;
-import jdk.vm.ci.meta.JavaConstant;
 import jdk.vm.ci.meta.JavaKind;
 import jdk.vm.ci.meta.MetaAccessProvider;
 import jdk.vm.ci.meta.ResolvedJavaMethod;
@@ -139,42 +131,9 @@
         plugins.appendTypePlugin(nodePlugin);
         plugins.appendNodePlugin(nodePlugin);
         OptionValues options = replacements.getOptions();
-        if (GeneratePIC.getValue(options)) {
-            // AOT needs to filter out bad invokes
-            plugins.prependNodePlugin(new NodePlugin() {
-                @Override
-                public boolean handleInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
-                    if (b.parsingIntrinsic()) {
-                        return false;
-                    }
-                    // check if the holder has a valid fingerprint
-                    if (((HotSpotResolvedObjectType) method.getDeclaringClass()).getFingerprint() == 0) {
-                        // Deopt otherwise
-                        b.append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
-                        return true;
-                    }
-                    // the last argument that may come from appendix, check if it is a supported
-                    // constant type
-                    if (args.length > 0) {
-                        JavaConstant constant = args[args.length - 1].asJavaConstant();
-                        if (constant != null && constant instanceof HotSpotObjectConstant) {
-                            HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) ((HotSpotObjectConstant) constant).getType();
-                            Class<?> clazz = type.mirror();
-                            if (clazz.equals(String.class)) {
-                                return false;
-                            }
-                            if (Class.class.isAssignableFrom(clazz) && ((HotSpotResolvedObjectType) type).getFingerprint() != 0) {
-                                return false;
-                            }
-                            b.append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
-                            return true;
-                        }
-                    }
-                    return false;
-                }
-            });
+        if (!GeneratePIC.getValue(options)) {
+            plugins.appendNodePlugin(new MethodHandlePlugin(constantReflection.getMethodHandleAccess(), true));
         }
-        plugins.appendNodePlugin(new MethodHandlePlugin(constantReflection.getMethodHandleAccess(), true));
         plugins.appendInlineInvokePlugin(replacements);
         if (InlineDuringParsing.getValue(options)) {
             plugins.appendInlineInvokePlugin(new InlineDuringParsingPlugin());
@@ -196,7 +155,9 @@
                 registerClassPlugins(plugins, config, replacementBytecodeProvider);
                 registerSystemPlugins(invocationPlugins, foreignCalls);
                 registerThreadPlugins(invocationPlugins, metaAccess, wordTypes, config, replacementBytecodeProvider);
-                registerCallSitePlugins(invocationPlugins);
+                if (!GeneratePIC.getValue(options)) {
+                    registerCallSitePlugins(invocationPlugins);
+                }
                 registerReflectionPlugins(invocationPlugins, replacementBytecodeProvider);
                 registerConstantPoolPlugins(invocationPlugins, wordTypes, config, replacementBytecodeProvider);
                 registerAESPlugins(invocationPlugins, config, replacementBytecodeProvider);
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotHostForeignCallsProvider.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotHostForeignCallsProvider.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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,6 +44,7 @@
 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_ARRAY;
 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_INSTANCE;
 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_MULTI_ARRAY;
+import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_DYNAMIC_INVOKE;
 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_KLASS_BY_SYMBOL;
 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS;
 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_STRING_BY_SYMBOL;
@@ -305,6 +306,7 @@
             registerForeignCall(WRONG_METHOD_HANDLER, c.handleWrongMethodStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
             CompilerRuntimeHotSpotVMConfig cr = new CompilerRuntimeHotSpotVMConfig(HotSpotJVMCIRuntime.runtime().getConfigStore());
             linkForeignCall(options, providers, RESOLVE_STRING_BY_SYMBOL, cr.resolveStringBySymbol, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, TLAB_TOP_LOCATION, TLAB_END_LOCATION);
+            linkForeignCall(options, providers, RESOLVE_DYNAMIC_INVOKE, cr.resolveDynamicInvoke, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, any());
             linkForeignCall(options, providers, RESOLVE_KLASS_BY_SYMBOL, cr.resolveKlassBySymbol, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, any());
             linkForeignCall(options, providers, RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS, cr.resolveMethodBySymbolAndLoadCounters, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, NO_LOCATIONS);
             linkForeignCall(options, providers, INITIALIZE_KLASS_BY_SYMBOL, cr.initializeKlassBySymbol, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, any());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotInvokeDynamicPlugin.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,156 @@
+/*
+ * 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.
+ */
+package org.graalvm.compiler.hotspot.meta;
+
+import org.graalvm.compiler.bytecode.Bytecodes;
+import org.graalvm.compiler.core.common.type.Stamp;
+import org.graalvm.compiler.debug.GraalError;
+import org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode;
+import org.graalvm.compiler.nodes.ConstantNode;
+import org.graalvm.compiler.nodes.FrameState;
+import org.graalvm.compiler.nodes.ValueNode;
+import org.graalvm.compiler.nodes.graphbuilderconf.InvokeDynamicPlugin;
+import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
+
+import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
+import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
+import jdk.vm.ci.meta.ConstantPool;
+import jdk.vm.ci.meta.JavaConstant;
+import jdk.vm.ci.meta.ResolvedJavaMethod;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+public class HotSpotInvokeDynamicPlugin implements InvokeDynamicPlugin {
+
+    private static final Class<? extends ConstantPool> hscp;
+    private static final MethodHandle isResolvedDynamicInvokeMH;
+
+    static {
+        MethodHandle m = null;
+        Class<? extends ConstantPool> c = null;
+        try {
+            c = Class.forName("jdk.vm.ci.hotspot.HotSpotConstantPool").asSubclass(ConstantPool.class);
+            m = MethodHandles.lookup().findVirtual(c, "isResolvedDynamicInvoke", MethodType.methodType(boolean.class, int.class, int.class));
+        } catch (Exception e) {
+        }
+        isResolvedDynamicInvokeMH = m;
+        hscp = c;
+    }
+
+    private static boolean isResolvedDynamicInvoke(ConstantPool constantPool, int index, int opcode) {
+        if (isResolvedDynamicInvokeMH != null) {
+            if (!hscp.isInstance(constantPool)) {
+                return false;
+            }
+            try {
+                return (boolean) isResolvedDynamicInvokeMH.invoke(constantPool, index, opcode);
+            } catch (Throwable t) {
+                throw GraalError.shouldNotReachHere(t);
+            }
+        }
+        throw GraalError.shouldNotReachHere("isResolvedDynamicInvokeMH not set");
+    }
+
+    private final DynamicTypeStore dynoStore;
+    private final boolean treatAppendixAsConstant;
+
+    public HotSpotInvokeDynamicPlugin(DynamicTypeStore dynoStore, boolean treatAppendixAsConstant) {
+        this.dynoStore = dynoStore;
+        this.treatAppendixAsConstant = treatAppendixAsConstant;
+    }
+
+    public HotSpotInvokeDynamicPlugin(DynamicTypeStore dynoStore) {
+        this(dynoStore, true);
+    }
+
+    public HotSpotInvokeDynamicPlugin() {
+        this(null);
+    }
+
+    // invokehandle support
+    @Override
+    public boolean isResolvedDynamicInvoke(GraphBuilderContext builder, int index, int opcode) {
+        ConstantPool constantPool = builder.getCode().getConstantPool();
+        if (isResolvedDynamicInvokeMH == null) {
+            // If older JVMCI, but HotSpotInvokeDynamicPlugin is being
+            // used for testing, return true so that we continue along the
+            // plugin path.
+            return true;
+        }
+        return isResolvedDynamicInvoke(constantPool, index, opcode);
+    }
+
+    @Override
+    public boolean supportsDynamicInvoke(GraphBuilderContext builder, int index, int opcode) {
+        return opcode == Bytecodes.INVOKEDYNAMIC || isResolvedDynamicInvokeMH != null;
+    }
+
+    public DynamicTypeStore getDynamicTypeStore() {
+        return dynoStore;
+    }
+
+    @Override
+    public void recordDynamicMethod(GraphBuilderContext builder, int index, int opcode, ResolvedJavaMethod target) {
+        assert supportsDynamicInvoke(builder, index, opcode);
+        HotSpotResolvedJavaMethod method = (HotSpotResolvedJavaMethod) builder.getMethod();
+        HotSpotResolvedObjectType methodHolder = method.getDeclaringClass();
+
+        HotSpotResolvedJavaMethod adapter = (HotSpotResolvedJavaMethod) target;
+        if (dynoStore != null) {
+            dynoStore.recordAdapter(opcode, methodHolder, index, adapter);
+        }
+    }
+
+    @Override
+    public ValueNode genAppendixNode(GraphBuilderContext builder, int index, int opcode, JavaConstant appendixConstant, FrameState frameState) {
+        JavaConstant appendix = appendixConstant;
+        assert supportsDynamicInvoke(builder, index, opcode);
+        HotSpotResolvedJavaMethod method = (HotSpotResolvedJavaMethod) builder.getMethod();
+        HotSpotResolvedObjectType methodHolder = method.getDeclaringClass();
+
+        if (dynoStore != null) {
+            appendix = dynoStore.recordAppendix(opcode, methodHolder, index, appendix);
+        }
+
+        ConstantNode appendixNode = ConstantNode.forConstant(appendix, builder.getMetaAccess(), builder.getGraph());
+
+        Stamp appendixStamp = appendixNode.stamp();
+        Stamp resolveStamp = treatAppendixAsConstant ? appendixStamp : appendixStamp.unrestricted();
+        ResolveDynamicConstantNode resolveNode = new ResolveDynamicConstantNode(resolveStamp, appendixNode);
+        ResolveDynamicConstantNode added = builder.append(resolveNode);
+        assert added == resolveNode;
+        added.setStateBefore(frameState);
+        return resolveNode;
+    }
+
+    public interface DynamicTypeStore {
+
+        void recordAdapter(int opcode, HotSpotResolvedObjectType holder, int cpi, HotSpotResolvedJavaMethod adapter);
+
+        JavaConstant recordAppendix(int opcode, HotSpotResolvedObjectType holder, int cpi, JavaConstant appendix);
+
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/nodes/aot/ResolveDynamicConstantNode.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+package org.graalvm.compiler.hotspot.nodes.aot;
+
+import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_4;
+import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_16;
+
+import org.graalvm.word.LocationIdentity;
+import org.graalvm.compiler.core.common.type.Stamp;
+import org.graalvm.compiler.graph.NodeClass;
+import org.graalvm.compiler.nodeinfo.NodeInfo;
+import org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode;
+import org.graalvm.compiler.nodes.ValueNode;
+import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
+import org.graalvm.compiler.nodes.spi.Lowerable;
+import org.graalvm.compiler.nodes.spi.LoweringTool;
+
+@NodeInfo(cycles = CYCLES_4, size = SIZE_16)
+public class ResolveDynamicConstantNode extends DeoptimizingFixedWithNextNode implements Lowerable, MemoryCheckpoint.Single {
+    public static final NodeClass<ResolveDynamicConstantNode> TYPE = NodeClass.create(ResolveDynamicConstantNode.class);
+
+    @Input ValueNode value;
+
+    public ResolveDynamicConstantNode(Stamp valueStamp, ValueNode value) {
+        super(TYPE, valueStamp);
+        this.value = value;
+    }
+
+    public ValueNode value() {
+        return value;
+    }
+
+    @Override
+    public void lower(LoweringTool tool) {
+        tool.getLowerer().lower(this, tool);
+    }
+
+    @Override
+    public boolean canDeoptimize() {
+        return true;
+    }
+
+    @Override
+    public LocationIdentity getLocationIdentity() {
+        return LocationIdentity.any();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/nodes/aot/ResolveDynamicStubCall.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ */
+package org.graalvm.compiler.hotspot.nodes.aot;
+
+import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_UNKNOWN;
+import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_16;
+
+import org.graalvm.compiler.debug.GraalError;
+import org.graalvm.compiler.graph.Node;
+import org.graalvm.compiler.graph.NodeClass;
+import org.graalvm.compiler.graph.spi.Canonicalizable;
+import org.graalvm.compiler.graph.spi.CanonicalizerTool;
+import org.graalvm.compiler.hotspot.HotSpotLIRGenerator;
+import org.graalvm.compiler.lir.LIRFrameState;
+import org.graalvm.compiler.nodeinfo.InputType;
+import org.graalvm.compiler.nodeinfo.NodeInfo;
+import org.graalvm.compiler.nodes.DeoptimizingNode;
+import org.graalvm.compiler.nodes.FrameState;
+import org.graalvm.compiler.nodes.ValueNode;
+import org.graalvm.compiler.nodes.spi.LIRLowerable;
+import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
+import org.graalvm.compiler.nodes.util.GraphUtil;
+import org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint;
+import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
+import org.graalvm.word.LocationIdentity;
+
+import jdk.vm.ci.meta.Constant;
+import jdk.vm.ci.meta.Value;
+
+/**
+ * A call to the VM via a regular stub.
+ */
+@NodeInfo(allowedUsageTypes = {InputType.Memory}, cycles = CYCLES_UNKNOWN, size = SIZE_16)
+public class ResolveDynamicStubCall extends AbstractMemoryCheckpoint implements LIRLowerable, Canonicalizable, DeoptimizingNode.DeoptBefore, MemoryCheckpoint.Single {
+    public static final NodeClass<ResolveDynamicStubCall> TYPE = NodeClass.create(ResolveDynamicStubCall.class);
+
+    @OptionalInput protected ValueNode value;
+    @OptionalInput(InputType.State) protected FrameState stateBefore;
+    protected Constant constant;
+
+    public ResolveDynamicStubCall(ValueNode value) {
+        super(TYPE, value.stamp());
+        this.value = value;
+    }
+
+    @NodeIntrinsic
+    public static native Object resolveInvoke(Object value);
+
+    @Override
+    public Node canonical(CanonicalizerTool tool) {
+        if (value != null) {
+            constant = GraphUtil.foldIfConstantAndRemove(this, value);
+        }
+        return this;
+    }
+
+    @Override
+    public void generate(NodeLIRBuilderTool gen) {
+        assert constant != null : "Expected the value to fold: " + value;
+        Value result;
+        LIRFrameState fs = gen.state(this);
+        assert fs != null : "The stateAfter is null";
+        result = ((HotSpotLIRGenerator) gen.getLIRGeneratorTool()).emitResolveDynamicInvoke(constant, fs);
+        gen.setResult(this, result);
+    }
+
+    @Override
+    public boolean canDeoptimize() {
+        return true;
+    }
+
+    @Override
+    public LocationIdentity getLocationIdentity() {
+        return LocationIdentity.any();
+    }
+
+    @Override
+    public FrameState stateBefore() {
+        return stateBefore;
+    }
+
+    @Override
+    public void setStateBefore(FrameState f) {
+        updateUsages(stateBefore, f);
+        stateBefore = f;
+    }
+
+    @Override
+    public void markDeleted() {
+        throw GraalError.shouldNotReachHere("ResolveDynamicStubCall node deleted");
+    }
+
+}
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/phases/aot/ReplaceConstantNodesPhase.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/phases/aot/ReplaceConstantNodesPhase.java	Sat Oct 21 00:06:50 2017 +0000
@@ -42,6 +42,7 @@
 import org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode;
 import org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode;
 import org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode;
+import org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode;
 import org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode;
 import org.graalvm.compiler.nodes.AbstractBeginNode;
 import org.graalvm.compiler.nodes.AbstractMergeNode;
@@ -107,6 +108,7 @@
         // @formatter:off
         return n instanceof LoadConstantIndirectlyNode      ||
                n instanceof LoadConstantIndirectlyFixedNode ||
+               n instanceof ResolveDynamicConstantNode      ||
                n instanceof ResolveConstantNode             ||
                n instanceof InitializeKlassNode;
         // @formatter:on
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/aot/ResolveConstantSnippets.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/aot/ResolveConstantSnippets.java	Sat Oct 21 00:06:50 2017 +0000
@@ -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,7 +36,9 @@
 import org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassStubCall;
 import org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode;
 import org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersIndirectlyNode;
+import org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicStubCall;
 import org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode;
+import org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode;
 import org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantStubCall;
 import org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode;
 import org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersStubCall;
@@ -73,6 +75,15 @@
     }
 
     @Snippet
+    public static Object resolveDynamicConstant(Object constant) {
+        Object result = LoadConstantIndirectlyNode.loadObject(constant);
+        if (probability(VERY_SLOW_PATH_PROBABILITY, result == null)) {
+            result = ResolveDynamicStubCall.resolveInvoke(constant);
+        }
+        return result;
+    }
+
+    @Snippet
     public static KlassPointer resolveKlassConstant(KlassPointer constant) {
         KlassPointer result = LoadConstantIndirectlyNode.loadKlass(constant);
         if (probability(VERY_SLOW_PATH_PROBABILITY, result.isNull())) {
@@ -110,6 +121,7 @@
 
     public static class Templates extends AbstractTemplates {
         private final SnippetInfo resolveObjectConstant = snippet(ResolveConstantSnippets.class, "resolveObjectConstant");
+        private final SnippetInfo resolveDynamicConstant = snippet(ResolveConstantSnippets.class, "resolveDynamicConstant");
         private final SnippetInfo resolveKlassConstant = snippet(ResolveConstantSnippets.class, "resolveKlassConstant");
         private final SnippetInfo resolveMethodAndLoadCounters = snippet(ResolveConstantSnippets.class, "resolveMethodAndLoadCounters");
         private final SnippetInfo initializeKlass = snippet(ResolveConstantSnippets.class, "initializeKlass");
@@ -119,6 +131,25 @@
             super(options, factories, providers, providers.getSnippetReflection(), target);
         }
 
+        public void lower(ResolveDynamicConstantNode resolveConstantNode, LoweringTool tool) {
+            StructuredGraph graph = resolveConstantNode.graph();
+
+            ValueNode value = resolveConstantNode.value();
+            assert value.isConstant() : "Expected a constant: " + value;
+            SnippetInfo snippet = resolveDynamicConstant;
+
+            Arguments args = new Arguments(snippet, graph.getGuardsStage(), tool.getLoweringStage());
+            args.add("constant", value);
+
+            SnippetTemplate template = template(graph.getDebug(), args);
+            template.instantiate(providers.getMetaAccess(), resolveConstantNode, DEFAULT_REPLACER, args);
+
+            assert resolveConstantNode.hasNoUsages();
+            if (!resolveConstantNode.isDeleted()) {
+                GraphUtil.killWithUnusedFloatingInputs(resolveConstantNode);
+            }
+        }
+
         public void lower(ResolveConstantNode resolveConstantNode, LoweringTool tool) {
             StructuredGraph graph = resolveConstantNode.graph();
 
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.java/src/org/graalvm/compiler/java/BytecodeParser.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.java/src/org/graalvm/compiler/java/BytecodeParser.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -374,6 +374,7 @@
 import org.graalvm.compiler.nodes.extended.StateSplitProxyNode;
 import org.graalvm.compiler.nodes.extended.ValueAnchorNode;
 import org.graalvm.compiler.nodes.graphbuilderconf.ClassInitializationPlugin;
+import org.graalvm.compiler.nodes.graphbuilderconf.InvokeDynamicPlugin;
 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.BytecodeExceptionMode;
 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
@@ -933,8 +934,13 @@
      * @param type the unresolved type of the constant
      */
     protected void handleUnresolvedLoadConstant(JavaType type) {
-        assert !graphBuilderConfig.eagerResolving();
-        append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        assert !graphBuilderConfig.unresolvedIsError();
+        DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        /*
+         * Track source position for deopt nodes even if
+         * GraphBuilderConfiguration.trackNodeSourcePosition is not set.
+         */
+        deopt.updateNodeSourcePosition(() -> createBytecodePosition());
     }
 
     /**
@@ -942,7 +948,7 @@
      * @param object the object value whose type is being checked against {@code type}
      */
     protected void handleUnresolvedCheckCast(JavaType type, ValueNode object) {
-        assert !graphBuilderConfig.eagerResolving();
+        assert !graphBuilderConfig.unresolvedIsError();
         append(new FixedGuardNode(graph.addOrUniqueWithInputs(IsNullNode.create(object)), Unresolved, InvalidateRecompile));
         frameState.push(JavaKind.Object, appendConstant(JavaConstant.NULL_POINTER));
     }
@@ -952,9 +958,10 @@
      * @param object the object value whose type is being checked against {@code type}
      */
     protected void handleUnresolvedInstanceOf(JavaType type, ValueNode object) {
-        assert !graphBuilderConfig.eagerResolving();
+        assert !graphBuilderConfig.unresolvedIsError();
         AbstractBeginNode successor = graph.add(new BeginNode());
         DeoptimizeNode deopt = graph.add(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        deopt.updateNodeSourcePosition(() -> createBytecodePosition());
         append(new IfNode(graph.addOrUniqueWithInputs(IsNullNode.create(object)), successor, deopt, 1));
         lastInstr = successor;
         frameState.push(JavaKind.Int, appendConstant(JavaConstant.INT_0));
@@ -964,8 +971,9 @@
      * @param type the type being instantiated
      */
     protected void handleUnresolvedNewInstance(JavaType type) {
-        assert !graphBuilderConfig.eagerResolving();
-        append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        assert !graphBuilderConfig.unresolvedIsError();
+        DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        deopt.updateNodeSourcePosition(() -> createBytecodePosition());
     }
 
     /**
@@ -973,8 +981,9 @@
      * @param length the length of the array
      */
     protected void handleUnresolvedNewObjectArray(JavaType type, ValueNode length) {
-        assert !graphBuilderConfig.eagerResolving();
-        append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        assert !graphBuilderConfig.unresolvedIsError();
+        DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        deopt.updateNodeSourcePosition(() -> createBytecodePosition());
     }
 
     /**
@@ -982,8 +991,9 @@
      * @param dims the dimensions for the multi-array
      */
     protected void handleUnresolvedNewMultiArray(JavaType type, ValueNode[] dims) {
-        assert !graphBuilderConfig.eagerResolving();
-        append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        assert !graphBuilderConfig.unresolvedIsError();
+        DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        deopt.updateNodeSourcePosition(() -> createBytecodePosition());
     }
 
     /**
@@ -991,8 +1001,9 @@
      * @param receiver the object containing the field or {@code null} if {@code field} is static
      */
     protected void handleUnresolvedLoadField(JavaField field, ValueNode receiver) {
-        assert !graphBuilderConfig.eagerResolving();
-        append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        assert !graphBuilderConfig.unresolvedIsError();
+        DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        deopt.updateNodeSourcePosition(() -> createBytecodePosition());
     }
 
     /**
@@ -1001,16 +1012,18 @@
      * @param receiver the object containing the field or {@code null} if {@code field} is static
      */
     protected void handleUnresolvedStoreField(JavaField field, ValueNode value, ValueNode receiver) {
-        assert !graphBuilderConfig.eagerResolving();
-        append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        assert !graphBuilderConfig.unresolvedIsError();
+        DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        deopt.updateNodeSourcePosition(() -> createBytecodePosition());
     }
 
     /**
      * @param type
      */
     protected void handleUnresolvedExceptionType(JavaType type) {
-        assert !graphBuilderConfig.eagerResolving();
-        append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        assert !graphBuilderConfig.unresolvedIsError();
+        DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        deopt.updateNodeSourcePosition(() -> createBytecodePosition());
     }
 
     /**
@@ -1018,8 +1031,9 @@
      * @param invokeKind
      */
     protected void handleUnresolvedInvoke(JavaMethod javaMethod, InvokeKind invokeKind) {
-        assert !graphBuilderConfig.eagerResolving();
-        append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        assert !graphBuilderConfig.unresolvedIsError();
+        DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+        deopt.updateNodeSourcePosition(() -> createBytecodePosition());
     }
 
     private AbstractBeginNode handleException(ValueNode exceptionObject, int bci) {
@@ -1307,7 +1321,12 @@
         return false;
     }
 
-    protected void genInvokeStatic(JavaMethod target) {
+    protected void genInvokeStatic(int cpi, int opcode) {
+        JavaMethod target = lookupMethod(cpi, opcode);
+        genInvokeStatic(target);
+    }
+
+    void genInvokeStatic(JavaMethod target) {
         if (callTargetIsResolved(target)) {
             ResolvedJavaMethod resolvedTarget = (ResolvedJavaMethod) target;
             ResolvedJavaType holder = resolvedTarget.getDeclaringClass();
@@ -1332,6 +1351,11 @@
         }
     }
 
+    protected void genInvokeInterface(int cpi, int opcode) {
+        JavaMethod target = lookupMethod(cpi, opcode);
+        genInvokeInterface(target);
+    }
+
     protected void genInvokeInterface(JavaMethod target) {
         if (callTargetIsResolved(target)) {
             ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(true));
@@ -1341,44 +1365,108 @@
         }
     }
 
-    protected void genInvokeDynamic(JavaMethod target) {
-        if (target instanceof ResolvedJavaMethod) {
-            JavaConstant appendix = constantPool.lookupAppendix(stream.readCPI4(), Bytecodes.INVOKEDYNAMIC);
-            if (appendix != null) {
-                frameState.push(JavaKind.Object, ConstantNode.forConstant(appendix, metaAccess, graph));
-            }
-            ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(false));
-            appendInvoke(InvokeKind.Static, (ResolvedJavaMethod) target, args);
-        } else {
+    protected void genInvokeDynamic(int cpi, int opcode) {
+        JavaMethod target = lookupMethod(cpi, opcode);
+        genInvokeDynamic(target);
+    }
+
+    void genInvokeDynamic(JavaMethod target) {
+        if (!(target instanceof ResolvedJavaMethod) || !genDynamicInvokeHelper((ResolvedJavaMethod) target, stream.readCPI4(), INVOKEDYNAMIC)) {
             handleUnresolvedInvoke(target, InvokeKind.Static);
         }
     }
 
-    protected void genInvokeVirtual(JavaMethod target) {
-        if (callTargetIsResolved(target)) {
-            /*
-             * Special handling for runtimes that rewrite an invocation of MethodHandle.invoke(...)
-             * or MethodHandle.invokeExact(...) to a static adapter. HotSpot does this - see
-             * https://wikis.oracle.com/display/HotSpotInternals/Method+handles +and+invokedynamic
-             */
-            boolean hasReceiver = !((ResolvedJavaMethod) target).isStatic();
-            JavaConstant appendix = constantPool.lookupAppendix(stream.readCPI(), Bytecodes.INVOKEVIRTUAL);
-            if (appendix != null) {
-                frameState.push(JavaKind.Object, ConstantNode.forConstant(appendix, metaAccess, graph));
+    protected void genInvokeVirtual(int cpi, int opcode) {
+        JavaMethod target = lookupMethod(cpi, opcode);
+        genInvokeVirtual(target);
+    }
+
+    private boolean genDynamicInvokeHelper(ResolvedJavaMethod target, int cpi, int opcode) {
+        assert opcode == INVOKEDYNAMIC || opcode == INVOKEVIRTUAL;
+
+        InvokeDynamicPlugin invokeDynamicPlugin = graphBuilderConfig.getPlugins().getInvokeDynamicPlugin();
+
+        if (opcode == INVOKEVIRTUAL && invokeDynamicPlugin != null && !invokeDynamicPlugin.isResolvedDynamicInvoke(this, cpi, opcode)) {
+            // regular invokevirtual, let caller handle it
+            return false;
+        }
+
+        if (GeneratePIC.getValue(options) && (invokeDynamicPlugin == null || !invokeDynamicPlugin.supportsDynamicInvoke(this, cpi, opcode))) {
+            // bail out if static compiler and no dynamic type support
+            append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+            return true;
+        }
+
+        JavaConstant appendix = constantPool.lookupAppendix(cpi, opcode);
+        ValueNode appendixNode = null;
+
+        if (appendix != null) {
+            if (invokeDynamicPlugin != null) {
+                invokeDynamicPlugin.recordDynamicMethod(this, cpi, opcode, target);
+
+                // Will perform runtime type checks and static initialization
+                FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
+                appendixNode = invokeDynamicPlugin.genAppendixNode(this, cpi, opcode, appendix, stateBefore);
+            } else {
+                appendixNode = ConstantNode.forConstant(appendix, metaAccess, graph);
             }
-            ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(hasReceiver));
-            if (hasReceiver) {
-                appendInvoke(InvokeKind.Virtual, (ResolvedJavaMethod) target, args);
-            } else {
-                appendInvoke(InvokeKind.Static, (ResolvedJavaMethod) target, args);
-            }
+
+            frameState.push(JavaKind.Object, appendixNode);
+
+        } else if (GeneratePIC.getValue(options)) {
+            // Need to emit runtime guard and perform static initialization.
+            // Not implemented yet.
+            append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
+            return true;
+        }
+
+        boolean hasReceiver = (opcode == INVOKEDYNAMIC) ? false : !target.isStatic();
+        ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(hasReceiver));
+        if (hasReceiver) {
+            appendInvoke(InvokeKind.Virtual, target, args);
         } else {
+            appendInvoke(InvokeKind.Static, target, args);
+        }
+
+        return true;
+    }
+
+    void genInvokeVirtual(JavaMethod target) {
+        if (!genInvokeVirtualHelper(target)) {
             handleUnresolvedInvoke(target, InvokeKind.Virtual);
         }
-
-    }
-
-    protected void genInvokeSpecial(JavaMethod target) {
+    }
+
+    private boolean genInvokeVirtualHelper(JavaMethod target) {
+        if (!callTargetIsResolved(target)) {
+            return false;
+        }
+
+        ResolvedJavaMethod resolvedTarget = (ResolvedJavaMethod) target;
+        int cpi = stream.readCPI();
+
+        /*
+         * Special handling for runtimes that rewrite an invocation of MethodHandle.invoke(...) or
+         * MethodHandle.invokeExact(...) to a static adapter. HotSpot does this - see
+         * https://wiki.openjdk.java.net/display/HotSpot/Method+handles+and+invokedynamic
+         */
+
+        if (genDynamicInvokeHelper(resolvedTarget, cpi, INVOKEVIRTUAL)) {
+            return true;
+        }
+
+        ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(true));
+        appendInvoke(InvokeKind.Virtual, (ResolvedJavaMethod) target, args);
+
+        return true;
+    }
+
+    protected void genInvokeSpecial(int cpi, int opcode) {
+        JavaMethod target = lookupMethod(cpi, opcode);
+        genInvokeSpecial(target);
+    }
+
+    void genInvokeSpecial(JavaMethod target) {
         if (callTargetIsResolved(target)) {
             assert target != null;
             assert target.getSignature() != null;
@@ -2149,9 +2237,9 @@
         TTY.println(s);
     }
 
-    protected BytecodeParserError asParserError(Throwable e) {
+    protected RuntimeException throwParserError(Throwable e) {
         if (e instanceof BytecodeParserError) {
-            return (BytecodeParserError) e;
+            throw (BytecodeParserError) e;
         }
         BytecodeParser bp = this;
         BytecodeParserError res = new BytecodeParserError(e);
@@ -2159,7 +2247,7 @@
             res.addContext("parsing " + bp.code.asStackTraceElement(bp.bci()));
             bp = bp.parent;
         }
-        return res;
+        throw res;
     }
 
     protected void parseAndInlineCallee(ResolvedJavaMethod targetMethod, ValueNode[] args, IntrinsicContext calleeIntrinsicContext) {
@@ -2837,7 +2925,7 @@
                 // Don't wrap bailouts as parser errors
                 throw e;
             } catch (Throwable e) {
-                throw asParserError(e);
+                throw throwParserError(e);
             }
 
             if (lastInstr == null || lastInstr.next() != null) {
@@ -3257,7 +3345,7 @@
         int nextBC = stream.readUByte(nextBCI);
         if (nextBCI <= currentBlock.endBci && nextBC == Bytecodes.GETFIELD) {
             stream.next();
-            genGetField(lookupField(stream.readCPI(), Bytecodes.GETFIELD), value);
+            genGetField(stream.readCPI(), Bytecodes.GETFIELD, value);
         } else {
             frameState.push(JavaKind.Object, value);
         }
@@ -3506,15 +3594,18 @@
         return result;
     }
 
-    private JavaField lookupField(int cpi, int opcode) {
+    protected JavaField lookupField(int cpi, int opcode) {
         maybeEagerlyResolve(cpi, opcode);
         JavaField result = constantPool.lookupField(cpi, method, opcode);
+
         if (graphBuilderConfig.eagerResolving()) {
-            assert result instanceof ResolvedJavaField : "Not resolved: " + result;
-            ResolvedJavaType declaringClass = ((ResolvedJavaField) result).getDeclaringClass();
-            if (!declaringClass.isInitialized()) {
-                assert declaringClass.isInterface() : "Declaring class not initialized but not an interface? " + declaringClass;
-                declaringClass.initialize();
+            assert !graphBuilderConfig.unresolvedIsError() || result instanceof ResolvedJavaField : "Not resolved: " + result;
+            if (result instanceof ResolvedJavaField) {
+                ResolvedJavaType declaringClass = ((ResolvedJavaField) result).getDeclaringClass();
+                if (!declaringClass.isInitialized()) {
+                    assert declaringClass.isInterface() : "Declaring class not initialized but not an interface? " + declaringClass;
+                    declaringClass.initialize();
+                }
             }
         }
         assert !graphBuilderConfig.unresolvedIsError() || (result instanceof ResolvedJavaField && ((ResolvedJavaField) result).getDeclaringClass().isInitialized()) : result;
@@ -3524,11 +3615,11 @@
     private Object lookupConstant(int cpi, int opcode) {
         maybeEagerlyResolve(cpi, opcode);
         Object result = constantPool.lookupConstant(cpi);
-        assert !graphBuilderConfig.eagerResolving() || !(result instanceof JavaType) || (result instanceof ResolvedJavaType) : result;
+        assert !graphBuilderConfig.unresolvedIsError() || !(result instanceof JavaType) || (result instanceof ResolvedJavaType) : result;
         return result;
     }
 
-    private void maybeEagerlyResolve(int cpi, int bytecode) {
+    protected void maybeEagerlyResolve(int cpi, int bytecode) {
         if (intrinsicContext != null) {
             constantPool.loadReferencedType(cpi, bytecode);
         } else if (graphBuilderConfig.eagerResolving()) {
@@ -3653,9 +3744,12 @@
         }
     }
 
-    void genNewInstance(int cpi) {
+    protected void genNewInstance(int cpi) {
         JavaType type = lookupType(cpi, NEW);
-
+        genNewInstance(type);
+    }
+
+    void genNewInstance(JavaType type) {
         if (!(type instanceof ResolvedJavaType) || !((ResolvedJavaType) type).isInitialized()) {
             handleUnresolvedNewInstance(type);
             return;
@@ -3790,8 +3884,13 @@
         frameState.push(JavaKind.Object, append(createNewMultiArray(resolvedType, dims)));
     }
 
-    private void genGetField(JavaField field) {
-        genGetField(field, frameState.pop(JavaKind.Object));
+    protected void genGetField(int cpi, int opcode) {
+        genGetField(cpi, opcode, frameState.pop(JavaKind.Object));
+    }
+
+    protected void genGetField(int cpi, int opcode, ValueNode receiverInput) {
+        JavaField field = lookupField(cpi, opcode);
+        genGetField(field, receiverInput);
     }
 
     private void genGetField(JavaField field, ValueNode receiverInput) {
@@ -3867,7 +3966,12 @@
         return false;
     }
 
-    private void genPutField(JavaField field) {
+    protected void genPutField(int cpi, int opcode) {
+        JavaField field = lookupField(cpi, opcode);
+        genPutField(field);
+    }
+
+    protected void genPutField(JavaField field) {
         genPutField(field, frameState.pop(field.getJavaKind()));
     }
 
@@ -3895,6 +3999,11 @@
         }
     }
 
+    protected void genGetStatic(int cpi, int opcode) {
+        JavaField field = lookupField(cpi, opcode);
+        genGetStatic(field);
+    }
+
     private void genGetStatic(JavaField field) {
         ResolvedJavaField resolvedField = resolveStaticFieldAccess(field, null);
         if (resolvedField == null) {
@@ -3956,7 +4065,12 @@
         return null;
     }
 
-    private void genPutStatic(JavaField field) {
+    protected void genPutStatic(int cpi, int opcode) {
+        JavaField field = lookupField(cpi, opcode);
+        genPutStatic(field);
+    }
+
+    protected void genPutStatic(JavaField field) {
         ValueNode value = frameState.pop(field.getJavaKind());
         ResolvedJavaField resolvedField = resolveStaticFieldAccess(field, value);
         if (resolvedField == null) {
@@ -4320,15 +4434,15 @@
             case DRETURN        : genReturn(frameState.pop(JavaKind.Double), JavaKind.Double); break;
             case ARETURN        : genReturn(frameState.pop(JavaKind.Object), JavaKind.Object); break;
             case RETURN         : genReturn(null, JavaKind.Void); break;
-            case GETSTATIC      : cpi = stream.readCPI(); genGetStatic(lookupField(cpi, opcode)); break;
-            case PUTSTATIC      : cpi = stream.readCPI(); genPutStatic(lookupField(cpi, opcode)); break;
-            case GETFIELD       : cpi = stream.readCPI(); genGetField(lookupField(cpi, opcode)); break;
-            case PUTFIELD       : cpi = stream.readCPI(); genPutField(lookupField(cpi, opcode)); break;
-            case INVOKEVIRTUAL  : cpi = stream.readCPI(); genInvokeVirtual(lookupMethod(cpi, opcode)); break;
-            case INVOKESPECIAL  : cpi = stream.readCPI(); genInvokeSpecial(lookupMethod(cpi, opcode)); break;
-            case INVOKESTATIC   : cpi = stream.readCPI(); genInvokeStatic(lookupMethod(cpi, opcode)); break;
-            case INVOKEINTERFACE: cpi = stream.readCPI(); genInvokeInterface(lookupMethod(cpi, opcode)); break;
-            case INVOKEDYNAMIC  : cpi = stream.readCPI4(); genInvokeDynamic(lookupMethod(cpi, opcode)); break;
+            case GETSTATIC      : cpi = stream.readCPI(); genGetStatic(cpi, opcode); break;
+            case PUTSTATIC      : cpi = stream.readCPI(); genPutStatic(cpi, opcode); break;
+            case GETFIELD       : cpi = stream.readCPI(); genGetField(cpi, opcode); break;
+            case PUTFIELD       : cpi = stream.readCPI(); genPutField(cpi, opcode); break;
+            case INVOKEVIRTUAL  : cpi = stream.readCPI(); genInvokeVirtual(cpi, opcode); break;
+            case INVOKESPECIAL  : cpi = stream.readCPI(); genInvokeSpecial(cpi, opcode); break;
+            case INVOKESTATIC   : cpi = stream.readCPI(); genInvokeStatic(cpi, opcode); break;
+            case INVOKEINTERFACE: cpi = stream.readCPI(); genInvokeInterface(cpi, opcode); break;
+            case INVOKEDYNAMIC  : cpi = stream.readCPI4(); genInvokeDynamic(cpi, opcode); break;
             case NEW            : genNewInstance(stream.readCPI()); break;
             case NEWARRAY       : genNewPrimitiveArray(stream.readLocalIndex()); break;
             case ANEWARRAY      : genNewObjectArray(stream.readCPI()); break;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.jtt/src/org/graalvm/compiler/jtt/bytecode/BC_irem4.java	Sat Oct 21 00:06:50 2017 +0000
@@ -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.
+ */
+package org.graalvm.compiler.jtt.bytecode;
+
+import org.junit.Test;
+
+import org.graalvm.compiler.jtt.JTTTest;
+
+public class BC_irem4 extends JTTTest {
+
+    public static int test(int a) {
+        return a % 8;
+    }
+
+    @Test
+    public void run0() throws Throwable {
+        runTest("test", -1);
+    }
+
+    @Test
+    public void run1() throws Throwable {
+        runTest("test", -2);
+    }
+
+    @Test
+    public void run2() throws Throwable {
+        runTest("test", -8);
+    }
+
+    @Test
+    public void run3() throws Throwable {
+        runTest("test", 16);
+    }
+
+    @Test
+    public void run4() throws Throwable {
+        runTest("test", -16);
+    }
+
+    @Test
+    public void run5() throws Throwable {
+        runTest("test", -23);
+    }
+
+    @Test
+    public void run6() throws Throwable {
+        runTest("test", 23);
+    }
+}
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.sparc/src/org/graalvm/compiler/lir/sparc/SPARCPrefetchOp.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.sparc/src/org/graalvm/compiler/lir/sparc/SPARCPrefetchOp.java	Sat Oct 21 00:06:50 2017 +0000
@@ -34,18 +34,17 @@
     public static final LIRInstructionClass<SPARCPrefetchOp> TYPE = LIRInstructionClass.create(SPARCPrefetchOp.class);
     public static final SizeEstimate SIZE = SizeEstimate.create(1);
 
-    private final int instr;  // AllocatePrefetchInstr
+    private final SPARCAssembler.Fcn fcn;
     @Alive({COMPOSITE}) protected SPARCAddressValue address;
 
-    public SPARCPrefetchOp(SPARCAddressValue address, int instr) {
+    public SPARCPrefetchOp(SPARCAddressValue address, SPARCAssembler.Fcn fcn) {
         super(TYPE, SIZE);
         this.address = address;
-        this.instr = instr;
+        this.fcn = fcn;
     }
 
     @Override
     public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) {
-        assert instr >= 0 && instr < SPARCAssembler.Fcn.values().length : instr;
-        masm.prefetch(address.toAddress(), SPARCAssembler.Fcn.values()[instr]);
+        masm.prefetch(address.toAddress(), fcn);
     }
 }
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/GraphDecoder.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/GraphDecoder.java	Sat Oct 21 00:06:50 2017 +0000
@@ -466,28 +466,6 @@
             AbstractMergeNode merge = (AbstractMergeNode) node;
             EndNode singleEnd = merge.forwardEndAt(0);
 
-            /*
-             * In some corner cases, the MergeNode already has PhiNodes. Since there is a single
-             * EndNode, each PhiNode can only have one input, and we can replace the PhiNode with
-             * this single input.
-             */
-            for (PhiNode phi : merge.phis()) {
-                assert phi.inputs().count() == 1 : "input count must match end count";
-                Node singlePhiInput = phi.inputs().first();
-
-                /*
-                 * We do not have the orderID of the PhiNode anymore, so we need to search through
-                 * the complete list of nodes to find a match.
-                 */
-                for (int i = 0; i < loopScope.createdNodes.length; i++) {
-                    if (loopScope.createdNodes[i] == phi) {
-                        loopScope.createdNodes[i] = singlePhiInput;
-                    }
-                }
-
-                phi.replaceAndDelete(singlePhiInput);
-            }
-
             /* Nodes that would use this merge as the guard need to use the previous block. */
             registerNode(loopScope, nodeOrderId, AbstractBeginNode.prevBegin(singleEnd), true, false);
 
@@ -973,8 +951,22 @@
             int phiNodeOrderId = readOrderId(methodScope);
 
             ValueNode phiInput = (ValueNode) ensureNodeCreated(methodScope, phiInputScope, phiInputOrderId);
+            ValueNode existing = (ValueNode) lookupNode(phiNodeScope, phiNodeOrderId);
 
-            ValueNode existing = (ValueNode) lookupNode(phiNodeScope, phiNodeOrderId);
+            if (existing != null && merge.phiPredecessorCount() == 1) {
+                /*
+                 * When exploding loops and the code after the loop (FULL_EXPLODE_UNTIL_RETURN),
+                 * then an existing value can already be registered: Parsing of the code before the
+                 * loop registers it when preparing for the later merge. The code after the loop,
+                 * which starts with a clone of the values that were created before the loop, sees
+                 * the stale value when processing the merge the first time. We can safely ignore
+                 * the stale value because it will never be needed to be merged (we are exploding
+                 * until we hit a return).
+                 */
+                assert methodScope.loopExplosion == LoopExplosionKind.FULL_EXPLODE_UNTIL_RETURN && phiNodeScope.loopIteration > 0;
+                existing = null;
+            }
+
             if (lazyPhi && (existing == null || existing == phiInput)) {
                 /* Phi function not yet necessary. */
                 registerNode(phiNodeScope, phiNodeOrderId, phiInput, true, false);
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/IfNode.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/IfNode.java	Sat Oct 21 00:06:50 2017 +0000
@@ -30,6 +30,8 @@
 import java.util.Iterator;
 import java.util.List;
 
+import jdk.vm.ci.meta.MetaAccessProvider;
+import jdk.vm.ci.meta.ResolvedJavaType;
 import org.graalvm.compiler.core.common.calc.Condition;
 import org.graalvm.compiler.core.common.type.IntegerStamp;
 import org.graalvm.compiler.core.common.type.Stamp;
@@ -52,7 +54,10 @@
 import org.graalvm.compiler.nodes.calc.IntegerLessThanNode;
 import org.graalvm.compiler.nodes.calc.IsNullNode;
 import org.graalvm.compiler.nodes.calc.NormalizeCompareNode;
+import org.graalvm.compiler.nodes.calc.ObjectEqualsNode;
+import org.graalvm.compiler.nodes.extended.UnboxNode;
 import org.graalvm.compiler.nodes.java.InstanceOfNode;
+import org.graalvm.compiler.nodes.java.LoadFieldNode;
 import org.graalvm.compiler.nodes.spi.LIRLowerable;
 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
 import org.graalvm.compiler.nodes.util.GraphUtil;
@@ -256,6 +261,123 @@
                 }
             }
         }
+
+        if (tryEliminateBoxedReferenceEquals(tool)) {
+            return;
+        }
+    }
+
+    private boolean isUnboxedFrom(MetaAccessProvider meta, ValueNode x, ValueNode src) {
+        if (x == src) {
+            return true;
+        } else if (x instanceof UnboxNode) {
+            return isUnboxedFrom(meta, ((UnboxNode) x).getValue(), src);
+        } else if (x instanceof PiNode) {
+            PiNode pi = (PiNode) x;
+            return isUnboxedFrom(meta, pi.getOriginalNode(), src);
+        } else if (x instanceof LoadFieldNode) {
+            LoadFieldNode load = (LoadFieldNode) x;
+            ResolvedJavaType integerType = meta.lookupJavaType(Integer.class);
+            if (load.getValue().stamp().javaType(meta).equals(integerType)) {
+                return isUnboxedFrom(meta, load.getValue(), src);
+            } else {
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Attempts to replace the following pattern:
+     *
+     * <pre>
+     * Integer x = ...;
+     * Integer y = ...;
+     * if ((x == y) || x.equals(y)) { ... }
+     * </pre>
+     *
+     * with:
+     *
+     * <pre>
+     * Integer x = ...;
+     * Integer y = ...;
+     * if (x.equals(y)) { ... }
+     * </pre>
+     *
+     * whenever the probability that the reference check will pass is relatively small.
+     *
+     * See GR-1315 for more information.
+     */
+    private boolean tryEliminateBoxedReferenceEquals(SimplifierTool tool) {
+        if (!(condition instanceof ObjectEqualsNode)) {
+            return false;
+        }
+
+        MetaAccessProvider meta = tool.getMetaAccess();
+        ObjectEqualsNode equalsCondition = (ObjectEqualsNode) condition;
+        ValueNode x = equalsCondition.getX();
+        ValueNode y = equalsCondition.getY();
+        ResolvedJavaType integerType = meta.lookupJavaType(Integer.class);
+
+        // At least one argument for reference equal must be a boxed primitive.
+        if (!x.stamp().javaType(meta).equals(integerType) && !y.stamp().javaType(meta).equals(integerType)) {
+            return false;
+        }
+
+        // The reference equality check is usually more efficient compared to a boxing check.
+        // The success of the reference equals must therefore be relatively rare, otherwise it makes
+        // no sense to eliminate it.
+        if (getTrueSuccessorProbability() > 0.4) {
+            return false;
+        }
+
+        // True branch must be empty.
+        if (trueSuccessor instanceof BeginNode || trueSuccessor instanceof LoopExitNode) {
+            if (trueSuccessor.next() instanceof EndNode) {
+                // Empty true branch.
+            } else {
+                return false;
+            }
+        } else {
+            return false;
+        }
+
+        // False branch must only check the unboxed values.
+        UnboxNode unbox = null;
+        FixedGuardNode unboxCheck = null;
+        for (FixedNode node : falseSuccessor.getBlockNodes()) {
+            if (!(node instanceof BeginNode || node instanceof UnboxNode || node instanceof FixedGuardNode || node instanceof EndNode ||
+                            node instanceof LoadFieldNode || node instanceof LoopExitNode)) {
+                return false;
+            }
+            if (node instanceof UnboxNode) {
+                if (unbox == null) {
+                    unbox = (UnboxNode) node;
+                } else {
+                    return false;
+                }
+            }
+            if (!(node instanceof FixedGuardNode)) {
+                continue;
+            }
+            FixedGuardNode fixed = (FixedGuardNode) node;
+            if (!(fixed.condition() instanceof IntegerEqualsNode)) {
+                continue;
+            }
+            IntegerEqualsNode equals = (IntegerEqualsNode) fixed.condition();
+            if ((isUnboxedFrom(meta, equals.getX(), x) && isUnboxedFrom(meta, equals.getY(), y)) || (isUnboxedFrom(meta, equals.getX(), y) && isUnboxedFrom(meta, equals.getY(), x))) {
+                unboxCheck = fixed;
+            }
+        }
+        if (unbox == null || unboxCheck == null) {
+            return false;
+        }
+
+        // Falsify the reference check.
+        setCondition(graph().addOrUnique(LogicConstantNode.contradiction()));
+
+        return true;
     }
 
     /**
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/NamedLocationIdentity.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/NamedLocationIdentity.java	Sat Oct 21 00:06:50 2017 +0000
@@ -60,6 +60,11 @@
      */
     public static final LocationIdentity ARRAY_LENGTH_LOCATION = NamedLocationIdentity.immutable("[].length");
 
+    /**
+     * Denotes an off-heap address.
+     */
+    public static final LocationIdentity OFF_HEAP_LOCATION = NamedLocationIdentity.mutable("OFF_HEAP_LOCATION");
+
     private final String name;
     private final boolean immutable;
 
@@ -81,7 +86,7 @@
 
     /**
      * Creates a named unique location identity for read operations against immutable memory.
-     * Immutable memory will never have a visible write in the graph, which is more restictive than
+     * Immutable memory will never have a visible write in the graph, which is more restrictive than
      * Java final.
      *
      * @param name the name of the new location identity
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/SignedRemNode.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/SignedRemNode.java	Sat Oct 21 00:06:50 2017 +0000
@@ -60,12 +60,26 @@
                 return this; // this will trap, can not canonicalize
             }
             return ConstantNode.forIntegerStamp(stamp(), forX.asJavaConstant().asLong() % y);
-        } else if (forY.isConstant()) {
-            long c = forY.asJavaConstant().asLong();
-            if (c == 1 || c == -1) {
+        } else if (forY.isConstant() && forX.stamp() instanceof IntegerStamp && forY.stamp() instanceof IntegerStamp) {
+            long constY = forY.asJavaConstant().asLong();
+            IntegerStamp xStamp = (IntegerStamp) forX.stamp();
+            IntegerStamp yStamp = (IntegerStamp) forY.stamp();
+            if (constY < 0 && constY != CodeUtil.minValue(yStamp.getBits())) {
+                return new SignedRemNode(forX, ConstantNode.forIntegerStamp(yStamp, -constY)).canonical(tool);
+            }
+
+            if (constY == 1) {
                 return ConstantNode.forIntegerStamp(stamp(), 0);
-            } else if (c > 0 && CodeUtil.isPowerOf2(c) && forX.stamp() instanceof IntegerStamp && ((IntegerStamp) forX.stamp()).isPositive()) {
-                return new AndNode(forX, ConstantNode.forIntegerStamp(stamp(), c - 1));
+            } else if (CodeUtil.isPowerOf2(constY)) {
+                if (xStamp.isPositive()) {
+                    return new AndNode(forX, ConstantNode.forIntegerStamp(stamp(), constY - 1));
+                } else if (xStamp.isNegative()) {
+                    return new NegateNode(new AndNode(new NegateNode(forX), ConstantNode.forIntegerStamp(stamp(), constY - 1)));
+                } else {
+                    return new ConditionalNode(IntegerLessThanNode.create(forX, ConstantNode.forIntegerStamp(forX.stamp(), 0)),
+                                    new NegateNode(new AndNode(new NegateNode(forX), ConstantNode.forIntegerStamp(stamp(), constY - 1))),
+                                    new AndNode(forX, ConstantNode.forIntegerStamp(stamp(), constY - 1)));
+                }
             }
         }
         return this;
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/extended/RawLoadNode.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/extended/RawLoadNode.java	Sat Oct 21 00:06:50 2017 +0000
@@ -30,7 +30,10 @@
 import org.graalvm.compiler.core.common.type.StampFactory;
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.graph.NodeClass;
+import org.graalvm.compiler.graph.spi.Canonicalizable;
+import org.graalvm.compiler.graph.spi.CanonicalizerTool;
 import org.graalvm.compiler.nodeinfo.NodeInfo;
+import org.graalvm.compiler.nodes.ConstantNode;
 import org.graalvm.compiler.nodes.ValueNode;
 import org.graalvm.compiler.nodes.calc.ReinterpretNode;
 import org.graalvm.compiler.nodes.java.LoadFieldNode;
@@ -38,19 +41,23 @@
 import org.graalvm.compiler.nodes.spi.LoweringTool;
 import org.graalvm.compiler.nodes.spi.Virtualizable;
 import org.graalvm.compiler.nodes.spi.VirtualizerTool;
+import org.graalvm.compiler.nodes.type.StampTool;
 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
 import org.graalvm.word.LocationIdentity;
 
 import jdk.vm.ci.meta.Assumptions;
+import jdk.vm.ci.meta.Constant;
+import jdk.vm.ci.meta.JavaConstant;
 import jdk.vm.ci.meta.JavaKind;
 import jdk.vm.ci.meta.ResolvedJavaField;
+import jdk.vm.ci.meta.ResolvedJavaType;
 
 /**
  * Load of a value from a location specified as an offset relative to an object. No null check is
  * performed before the load.
  */
 @NodeInfo(cycles = CYCLES_2, size = SIZE_1)
-public class RawLoadNode extends UnsafeAccessNode implements Lowerable, Virtualizable {
+public class RawLoadNode extends UnsafeAccessNode implements Lowerable, Virtualizable, Canonicalizable {
     public static final NodeClass<RawLoadNode> TYPE = NodeClass.create(RawLoadNode.class);
 
     /**
@@ -123,6 +130,32 @@
     }
 
     @Override
+    public Node canonical(CanonicalizerTool tool) {
+        if (!isAnyLocationForced() && getLocationIdentity().isAny()) {
+            ValueNode targetObject = object();
+            if (offset().isConstant() && targetObject.isConstant() && !targetObject.isNullConstant()) {
+                ConstantNode objectConstant = (ConstantNode) targetObject;
+                ResolvedJavaType type = StampTool.typeOrNull(objectConstant);
+                if (type != null && type.isArray()) {
+                    JavaConstant arrayConstant = objectConstant.asJavaConstant();
+                    if (arrayConstant != null) {
+                        int stableDimension = objectConstant.getStableDimension();
+                        if (stableDimension > 0) {
+                            long constantOffset = offset().asJavaConstant().asLong();
+                            Constant constant = stamp().readConstant(tool.getConstantReflection().getMemoryAccessProvider(), arrayConstant, constantOffset);
+                            boolean isDefaultStable = objectConstant.isDefaultStable();
+                            if (constant != null && (isDefaultStable || !constant.isDefaultForKind())) {
+                                return ConstantNode.forConstant(stamp(), constant, stableDimension - 1, isDefaultStable, tool.getMetaAccess());
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return super.canonical(tool);
+    }
+
+    @Override
     protected ValueNode cloneAsFieldAccess(Assumptions assumptions, ResolvedJavaField field) {
         return LoadFieldNode.create(assumptions, object(), field);
     }
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/GraphBuilderConfiguration.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/GraphBuilderConfiguration.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -39,6 +39,7 @@
         private InlineInvokePlugin[] inlineInvokePlugins;
         private LoopExplosionPlugin loopExplosionPlugin;
         private ClassInitializationPlugin classInitializationPlugin;
+        private InvokeDynamicPlugin invokeDynamicPlugin;
         private ProfilingPlugin profilingPlugin;
 
         /**
@@ -54,6 +55,7 @@
             this.inlineInvokePlugins = copyFrom.inlineInvokePlugins;
             this.loopExplosionPlugin = copyFrom.loopExplosionPlugin;
             this.classInitializationPlugin = copyFrom.classInitializationPlugin;
+            this.invokeDynamicPlugin = copyFrom.invokeDynamicPlugin;
             this.profilingPlugin = copyFrom.profilingPlugin;
         }
 
@@ -167,6 +169,14 @@
             this.classInitializationPlugin = plugin;
         }
 
+        public InvokeDynamicPlugin getInvokeDynamicPlugin() {
+            return invokeDynamicPlugin;
+        }
+
+        public void setInvokeDynamicPlugin(InvokeDynamicPlugin plugin) {
+            this.invokeDynamicPlugin = plugin;
+        }
+
         public ProfilingPlugin getProfilingPlugin() {
             return profilingPlugin;
         }
@@ -189,6 +199,7 @@
     private static final ResolvedJavaType[] EMPTY = new ResolvedJavaType[]{};
 
     private final boolean eagerResolving;
+    private final boolean unresolvedIsError;
     private final BytecodeExceptionMode bytecodeExceptionMode;
     private final boolean omitAssertions;
     private final ResolvedJavaType[] skippedExceptionTypes;
@@ -216,10 +227,11 @@
         Profile
     }
 
-    protected GraphBuilderConfiguration(boolean eagerResolving, BytecodeExceptionMode bytecodeExceptionMode, boolean omitAssertions, boolean insertFullInfopoints,
+    protected GraphBuilderConfiguration(boolean eagerResolving, boolean unresolvedIsError, BytecodeExceptionMode bytecodeExceptionMode, boolean omitAssertions, boolean insertFullInfopoints,
                     boolean trackNodeSourcePosition, ResolvedJavaType[] skippedExceptionTypes,
                     Plugins plugins) {
         this.eagerResolving = eagerResolving;
+        this.unresolvedIsError = unresolvedIsError;
         this.bytecodeExceptionMode = bytecodeExceptionMode;
         this.omitAssertions = omitAssertions;
         this.insertFullInfopoints = insertFullInfopoints;
@@ -235,35 +247,52 @@
      */
     public GraphBuilderConfiguration copy() {
         Plugins newPlugins = new Plugins(plugins);
-        GraphBuilderConfiguration result = new GraphBuilderConfiguration(eagerResolving, bytecodeExceptionMode, omitAssertions, insertFullInfopoints, trackNodeSourcePosition, skippedExceptionTypes,
-                        newPlugins);
+        GraphBuilderConfiguration result = new GraphBuilderConfiguration(eagerResolving, unresolvedIsError, bytecodeExceptionMode, omitAssertions, insertFullInfopoints, trackNodeSourcePosition,
+                        skippedExceptionTypes, newPlugins);
         return result;
     }
 
+    /**
+     * Set the {@link #unresolvedIsError} flag. This flag can be set independently from
+     * {@link #eagerResolving}, i.e., even if eager resolving fails execution is assumed to be
+     * valid. This allows us for example to process unresolved types/methods/fields even when
+     * eagerly resolving elements.
+     */
+    public GraphBuilderConfiguration withUnresolvedIsError(boolean newUnresolvedIsError) {
+        return new GraphBuilderConfiguration(eagerResolving, newUnresolvedIsError, bytecodeExceptionMode, omitAssertions, insertFullInfopoints, trackNodeSourcePosition, skippedExceptionTypes,
+                        plugins);
+    }
+
     public GraphBuilderConfiguration withEagerResolving(boolean newEagerResolving) {
-        return new GraphBuilderConfiguration(newEagerResolving, bytecodeExceptionMode, omitAssertions, insertFullInfopoints, trackNodeSourcePosition, skippedExceptionTypes, plugins);
+        return new GraphBuilderConfiguration(newEagerResolving, unresolvedIsError, bytecodeExceptionMode, omitAssertions, insertFullInfopoints, trackNodeSourcePosition, skippedExceptionTypes,
+                        plugins);
     }
 
     public GraphBuilderConfiguration withSkippedExceptionTypes(ResolvedJavaType[] newSkippedExceptionTypes) {
-        return new GraphBuilderConfiguration(eagerResolving, bytecodeExceptionMode, omitAssertions, insertFullInfopoints, trackNodeSourcePosition, newSkippedExceptionTypes, plugins);
+        return new GraphBuilderConfiguration(eagerResolving, unresolvedIsError, bytecodeExceptionMode, omitAssertions, insertFullInfopoints, trackNodeSourcePosition, newSkippedExceptionTypes,
+                        plugins);
     }
 
     public GraphBuilderConfiguration withBytecodeExceptionMode(BytecodeExceptionMode newBytecodeExceptionMode) {
-        return new GraphBuilderConfiguration(eagerResolving, newBytecodeExceptionMode, omitAssertions, insertFullInfopoints, trackNodeSourcePosition, skippedExceptionTypes, plugins);
+        return new GraphBuilderConfiguration(eagerResolving, unresolvedIsError, newBytecodeExceptionMode, omitAssertions, insertFullInfopoints, trackNodeSourcePosition, skippedExceptionTypes,
+                        plugins);
     }
 
     public GraphBuilderConfiguration withOmitAssertions(boolean newOmitAssertions) {
-        return new GraphBuilderConfiguration(eagerResolving, bytecodeExceptionMode, newOmitAssertions, insertFullInfopoints, trackNodeSourcePosition, skippedExceptionTypes, plugins);
+        return new GraphBuilderConfiguration(eagerResolving, unresolvedIsError, bytecodeExceptionMode, newOmitAssertions, insertFullInfopoints, trackNodeSourcePosition, skippedExceptionTypes,
+                        plugins);
     }
 
     public GraphBuilderConfiguration withFullInfopoints(boolean newInsertFullInfopoints) {
         ResolvedJavaType[] newSkippedExceptionTypes = skippedExceptionTypes == EMPTY ? EMPTY : Arrays.copyOf(skippedExceptionTypes, skippedExceptionTypes.length);
-        return new GraphBuilderConfiguration(eagerResolving, bytecodeExceptionMode, omitAssertions, newInsertFullInfopoints, trackNodeSourcePosition, newSkippedExceptionTypes, plugins);
+        return new GraphBuilderConfiguration(eagerResolving, unresolvedIsError, bytecodeExceptionMode, omitAssertions, newInsertFullInfopoints, trackNodeSourcePosition, newSkippedExceptionTypes,
+                        plugins);
     }
 
     public GraphBuilderConfiguration withNodeSourcePosition(boolean newTrackNodeSourcePosition) {
         ResolvedJavaType[] newSkippedExceptionTypes = skippedExceptionTypes == EMPTY ? EMPTY : Arrays.copyOf(skippedExceptionTypes, skippedExceptionTypes.length);
-        return new GraphBuilderConfiguration(eagerResolving, bytecodeExceptionMode, omitAssertions, insertFullInfopoints, newTrackNodeSourcePosition, newSkippedExceptionTypes, plugins);
+        return new GraphBuilderConfiguration(eagerResolving, unresolvedIsError, bytecodeExceptionMode, omitAssertions, insertFullInfopoints, newTrackNodeSourcePosition, newSkippedExceptionTypes,
+                        plugins);
     }
 
     public ResolvedJavaType[] getSkippedExceptionTypes() {
@@ -291,20 +320,16 @@
     }
 
     public static GraphBuilderConfiguration getDefault(Plugins plugins) {
-        return new GraphBuilderConfiguration(false, BytecodeExceptionMode.Profile, false, false, false, EMPTY, plugins);
+        return new GraphBuilderConfiguration(false, false, BytecodeExceptionMode.Profile, false, false, false, EMPTY, plugins);
     }
 
     public static GraphBuilderConfiguration getSnippetDefault(Plugins plugins) {
-        return new GraphBuilderConfiguration(true, BytecodeExceptionMode.OmitAll, false, false, false, EMPTY, plugins);
+        return new GraphBuilderConfiguration(true, true, BytecodeExceptionMode.OmitAll, false, false, false, EMPTY, plugins);
     }
 
-    /**
-     * Returns {@code true} if it is an error for a class/field/method resolution to fail. The
-     * default is the same result as returned by {@link #eagerResolving()}. However, it may be
-     * overridden to allow failure even when {@link #eagerResolving} is {@code true}.
-     */
+    /** Returns {@code true} if it is an error for a class/field/method resolution to fail. */
     public boolean unresolvedIsError() {
-        return eagerResolving;
+        return unresolvedIsError;
     }
 
     public Plugins getPlugins() {
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/GraphBuilderContext.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/GraphBuilderContext.java	Sat Oct 21 00:06:50 2017 +0000
@@ -295,4 +295,20 @@
     default void notifyReplacedCall(ResolvedJavaMethod targetMethod, ConstantNode node) {
 
     }
+
+    /**
+     * Interface whose instances hold inlining information about the current context, in a wider
+     * sense. The wider sense in this case concerns graph building approaches that don't necessarily
+     * keep a chain of {@link GraphBuilderContext} instances normally available through
+     * {@linkplain #getParent()}. Examples of such approaches are partial evaluation and incremental
+     * inlining.
+     */
+    interface ExternalInliningContext {
+        int getInlinedDepth();
+    }
+
+    default ExternalInliningContext getExternalInliningContext() {
+        return null;
+    }
+
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/InvokeDynamicPlugin.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+package org.graalvm.compiler.nodes.graphbuilderconf;
+
+import org.graalvm.compiler.nodes.FrameState;
+import org.graalvm.compiler.nodes.ValueNode;
+
+import jdk.vm.ci.meta.ResolvedJavaMethod;
+import jdk.vm.ci.meta.JavaConstant;
+
+/**
+ * {@link GraphBuilderPlugin} interface for static compilation mode, allowing references to dynamic
+ * types.
+ */
+public interface InvokeDynamicPlugin extends GraphBuilderPlugin {
+
+    /**
+     * Checks for a resolved dynamic adapter method at the specified index, resulting from either a
+     * resolved invokedynamic or invokevirtual on a signature polymorphic MethodHandle method
+     * (HotSpot invokehandle).
+     *
+     * @param builder context for the invoke
+     * @param cpi the constant pool index
+     * @param opcode the opcode of the instruction for which the lookup is being performed
+     * @return {@code true} if a signature polymorphic method reference was found, otherwise
+     *         {@code false}
+     */
+    boolean isResolvedDynamicInvoke(GraphBuilderContext builder, int cpi, int opcode);
+
+    /**
+     * Checks if this plugin instance supports the specified dynamic invoke.
+     *
+     * @param builder context for the invoke
+     * @param cpi the constant pool index
+     * @param opcode the opcode of the invoke instruction
+     * @return {@code true} if this dynamic invoke is supported
+     */
+    boolean supportsDynamicInvoke(GraphBuilderContext builder, int cpi, int opcode);
+
+    /**
+     * Notifies this object of the value and context of the dynamic method target (e.g., A HotSpot
+     * adapter method) for a resolved dynamic invoke.
+     *
+     * @param builder context for the invoke
+     * @param cpi the constant pool index
+     * @param opcode the opcode of the instruction for which the lookup is being performed
+     * @param target dynamic target method to record
+     */
+    void recordDynamicMethod(GraphBuilderContext builder, int cpi, int opcode, ResolvedJavaMethod target);
+
+    /**
+     * Notifies this object of the value and context of the dynamic appendix object for a resolved
+     * dynamic invoke.
+     *
+     * @param builder context for the invoke
+     * @param cpi the constant pool index
+     * @param opcode the opcode of the instruction for which the lookup is being performed
+     * @return {@link ValueNode} for appendix constant
+     */
+    ValueNode genAppendixNode(GraphBuilderContext builder, int cpi, int opcode, JavaConstant appendix, FrameState frameState);
+
+}
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/virtual/VirtualArrayNode.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/virtual/VirtualArrayNode.java	Sat Oct 21 00:06:50 2017 +0000
@@ -137,8 +137,9 @@
         }
         long offset;
         if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN && componentType.isPrimitive()) {
-            // On big endian, we do just get expect the type be right aligned in this memory slot
-            offset = constantOffset - (componentType.getJavaKind().getByteCount() - Math.min(componentType.getJavaKind().getByteCount(), 4 + expectedEntryKind.getByteCount()));
+            // On big endian, we expect the value to be correctly aligned in memory
+            int componentByteCount = componentType.getJavaKind().getByteCount();
+            offset = constantOffset - (componentByteCount - Math.min(componentByteCount, 4 + expectedEntryKind.getByteCount()));
         } else {
             offset = constantOffset;
         }
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/PEGraphDecoderTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/PEGraphDecoderTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -132,11 +132,11 @@
         StructuredGraph targetGraph = null;
         DebugContext debug = getDebugContext();
         try (DebugContext.Scope scope = debug.scope("GraphPETest", testMethod)) {
-            GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true);
+            GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true).withUnresolvedIsError(true);
             registerPlugins(graphBuilderConfig.getPlugins().getInvocationPlugins());
             targetGraph = new StructuredGraph.Builder(getInitialOptions(), debug, AllowAssumptions.YES).method(testMethod).build();
             CachingPEGraphDecoder decoder = new CachingPEGraphDecoder(getTarget().arch, targetGraph, getProviders(), graphBuilderConfig, OptimisticOptimizations.NONE, AllowAssumptions.YES,
-                            null, null, new InlineInvokePlugin[]{new InlineAll()}, null, null);
+                            null, null, new InlineInvokePlugin[]{new InlineAll()}, null, null, null);
 
             decoder.decode(testMethod);
             debug.dump(DebugContext.BASIC_LEVEL, targetGraph, "Target Graph");
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/CachingPEGraphDecoder.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/CachingPEGraphDecoder.java	Sat Oct 21 00:06:50 2017 +0000
@@ -63,9 +63,9 @@
     public CachingPEGraphDecoder(Architecture architecture, StructuredGraph graph, Providers providers, GraphBuilderConfiguration graphBuilderConfig, OptimisticOptimizations optimisticOpts,
                     AllowAssumptions allowAssumptions, LoopExplosionPlugin loopExplosionPlugin, InvocationPlugins invocationPlugins, InlineInvokePlugin[] inlineInvokePlugins,
                     ParameterPlugin parameterPlugin,
-                    NodePlugin[] nodePlugins) {
+                    NodePlugin[] nodePlugins, ResolvedJavaMethod callInlinedMethod) {
         super(architecture, graph, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), loopExplosionPlugin,
-                        invocationPlugins, inlineInvokePlugins, parameterPlugin, nodePlugins);
+                        invocationPlugins, inlineInvokePlugins, parameterPlugin, nodePlugins, callInlinedMethod);
 
         this.providers = providers;
         this.graphBuilderConfig = graphBuilderConfig;
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/GraphKit.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/GraphKit.java	Sat Oct 21 00:06:50 2017 +0000
@@ -238,11 +238,11 @@
 
         if (frameStateBuilder != null) {
             if (invoke.getStackKind() != JavaKind.Void) {
-                frameStateBuilder.push(returnType.getJavaKind(), invoke);
+                frameStateBuilder.push(invoke.getStackKind(), invoke);
             }
             invoke.setStateAfter(frameStateBuilder.create(bci, invoke));
             if (invoke.getStackKind() != JavaKind.Void) {
-                frameStateBuilder.pop(returnType.getJavaKind());
+                frameStateBuilder.pop(invoke.getStackKind());
             }
         }
         return invoke;
@@ -475,11 +475,11 @@
         invoke.setNext(noExceptionEdge);
         if (frameStateBuilder != null) {
             if (invoke.getStackKind() != JavaKind.Void) {
-                frameStateBuilder.push(returnType.getJavaKind(), invoke);
+                frameStateBuilder.push(invoke.getStackKind(), invoke);
             }
             invoke.setStateAfter(frameStateBuilder.create(invokeBci, invoke));
             if (invoke.getStackKind() != JavaKind.Void) {
-                frameStateBuilder.pop(returnType.getJavaKind());
+                frameStateBuilder.pop(invoke.getStackKind());
             }
         }
         lastFixedNode = null;
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/PEGraphDecoder.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/PEGraphDecoder.java	Sat Oct 21 00:06:50 2017 +0000
@@ -193,6 +193,24 @@
         protected final PEMethodScope methodScope;
         protected final Invoke invoke;
 
+        @Override
+        public ExternalInliningContext getExternalInliningContext() {
+            return new ExternalInliningContext() {
+                @Override
+                public int getInlinedDepth() {
+                    int count = 0;
+                    PEGraphDecoder.PEMethodScope scope = methodScope;
+                    while (scope != null) {
+                        if (scope.method.equals(callInlinedMethod)) {
+                            count++;
+                        }
+                        scope = scope.caller;
+                    }
+                    return count;
+                }
+            };
+        }
+
         public PENonAppendGraphBuilderContext(PEMethodScope methodScope, Invoke invoke) {
             this.methodScope = methodScope;
             this.invoke = invoke;
@@ -420,11 +438,12 @@
     private final NodePlugin[] nodePlugins;
     private final EconomicMap<SpecialCallTargetCacheKey, Object> specialCallTargetCache;
     private final EconomicMap<ResolvedJavaMethod, Object> invocationPluginCache;
+    private final ResolvedJavaMethod callInlinedMethod;
 
     public PEGraphDecoder(Architecture architecture, StructuredGraph graph, MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection, ConstantFieldProvider constantFieldProvider,
                     StampProvider stampProvider, LoopExplosionPlugin loopExplosionPlugin, InvocationPlugins invocationPlugins, InlineInvokePlugin[] inlineInvokePlugins,
                     ParameterPlugin parameterPlugin,
-                    NodePlugin[] nodePlugins) {
+                    NodePlugin[] nodePlugins, ResolvedJavaMethod callInlinedMethod) {
         super(architecture, graph, metaAccess, constantReflection, constantFieldProvider, stampProvider, true);
         this.loopExplosionPlugin = loopExplosionPlugin;
         this.invocationPlugins = invocationPlugins;
@@ -433,6 +452,7 @@
         this.nodePlugins = nodePlugins;
         this.specialCallTargetCache = EconomicMap.create(Equivalence.DEFAULT);
         this.invocationPluginCache = EconomicMap.create(Equivalence.DEFAULT);
+        this.callInlinedMethod = callInlinedMethod;
     }
 
     protected static LoopExplosionKind loopExplosionKind(ResolvedJavaMethod method, LoopExplosionPlugin loopExplosionPlugin) {
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/SnippetTemplate.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/SnippetTemplate.java	Sat Oct 21 00:06:50 2017 +0000
@@ -224,16 +224,12 @@
         }
 
         /**
-         * Times instantiations of all templates derived form this snippet.
-         *
-         * @see SnippetTemplate#instantiationTimer
+         * Times instantiations of all templates derived from this snippet.
          */
         private final TimerKey instantiationTimer;
 
         /**
          * Counts instantiations of all templates derived from this snippet.
-         *
-         * @see SnippetTemplate#instantiationCounter
          */
         private final CounterKey instantiationCounter;
 
@@ -706,8 +702,6 @@
 
         Object[] constantArgs = getConstantArgs(args);
         StructuredGraph snippetGraph = providers.getReplacements().getSnippet(args.info.method, args.info.original, constantArgs);
-        instantiationTimer = DebugContext.timer("SnippetTemplateInstantiationTime[%#s]", args);
-        instantiationCounter = DebugContext.counter("SnippetTemplateInstantiationCount[%#s]", args);
 
         ResolvedJavaMethod method = snippetGraph.method();
         Signature signature = method.getSignature();
@@ -1078,20 +1072,6 @@
     private final ArrayList<Node> nodes;
 
     /**
-     * Times instantiations of this template.
-     *
-     * @see SnippetInfo#instantiationTimer
-     */
-    private final TimerKey instantiationTimer;
-
-    /**
-     * Counts instantiations of this template.
-     *
-     * @see SnippetInfo#instantiationCounter
-     */
-    private final CounterKey instantiationCounter;
-
-    /**
      * Gets the instantiation-time bindings to this template's parameters.
      *
      * @return the map that will be used to bind arguments to parameters when inlining this template
@@ -1406,9 +1386,8 @@
     public UnmodifiableEconomicMap<Node, Node> instantiate(MetaAccessProvider metaAccess, FixedNode replacee, UsageReplacer replacer, Arguments args, boolean killReplacee) {
         DebugContext debug = replacee.getDebug();
         assert assertSnippetKills(replacee);
-        try (DebugCloseable a = args.info.instantiationTimer.start(debug); DebugCloseable b = instantiationTimer.start(debug)) {
+        try (DebugCloseable a = args.info.instantiationTimer.start(debug)) {
             args.info.instantiationCounter.increment(debug);
-            instantiationCounter.increment(debug);
             // Inline the snippet nodes, replacing parameters with the given args in the process
             StartNode entryPointNode = snippet.start();
             FixedNode firstCFGNode = entryPointNode.next();
@@ -1561,7 +1540,6 @@
         assert assertSnippetKills(replacee);
         try (DebugCloseable a = args.info.instantiationTimer.start(debug)) {
             args.info.instantiationCounter.increment(debug);
-            instantiationCounter.increment(debug);
 
             // Inline the snippet nodes, replacing parameters with the given args in the process
             StartNode entryPointNode = snippet.start();
@@ -1614,7 +1592,6 @@
         assert assertSnippetKills(replacee);
         try (DebugCloseable a = args.info.instantiationTimer.start(debug)) {
             args.info.instantiationCounter.increment(debug);
-            instantiationCounter.increment(debug);
 
             // Inline the snippet nodes, replacing parameters with the given args in the process
             StartNode entryPointNode = snippet.start();
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/StandardGraphBuilderPlugins.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/StandardGraphBuilderPlugins.java	Sat Oct 21 00:06:50 2017 +0000
@@ -30,6 +30,7 @@
 import static jdk.vm.ci.code.MemoryBarriers.LOAD_STORE;
 import static jdk.vm.ci.code.MemoryBarriers.STORE_LOAD;
 import static jdk.vm.ci.code.MemoryBarriers.STORE_STORE;
+import static org.graalvm.compiler.nodes.NamedLocationIdentity.OFF_HEAP_LOCATION;
 import static org.graalvm.compiler.serviceprovider.JDK9Method.Java8OrEarlier;
 
 import java.lang.reflect.Array;
@@ -650,7 +651,7 @@
         public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode address) {
             // Emits a null-check for the otherwise unused receiver
             unsafe.get();
-            b.addPush(returnKind, new UnsafeMemoryLoadNode(address, returnKind, LocationIdentity.any()));
+            b.addPush(returnKind, new UnsafeMemoryLoadNode(address, returnKind, OFF_HEAP_LOCATION));
             b.getGraph().markUnsafeAccess();
             return true;
         }
@@ -662,7 +663,8 @@
             if (isVolatile) {
                 b.add(new MembarNode(JMM_PRE_VOLATILE_READ));
             }
-            b.addPush(returnKind, new RawLoadNode(object, offset, returnKind, LocationIdentity.any()));
+            LocationIdentity locationIdentity = object.isNullConstant() ? OFF_HEAP_LOCATION : LocationIdentity.any();
+            b.addPush(returnKind, new RawLoadNode(object, offset, returnKind, locationIdentity));
             if (isVolatile) {
                 b.add(new MembarNode(JMM_POST_VOLATILE_READ));
             }
@@ -685,7 +687,7 @@
         public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode address, ValueNode value) {
             // Emits a null-check for the otherwise unused receiver
             unsafe.get();
-            b.add(new UnsafeMemoryStoreNode(address, value, kind, LocationIdentity.any()));
+            b.add(new UnsafeMemoryStoreNode(address, value, kind, OFF_HEAP_LOCATION));
             b.getGraph().markUnsafeAccess();
             return true;
         }
@@ -697,7 +699,8 @@
             if (isVolatile) {
                 b.add(new MembarNode(JMM_PRE_VOLATILE_WRITE));
             }
-            b.add(new RawStoreNode(object, offset, value, kind, LocationIdentity.any()));
+            LocationIdentity locationIdentity = object.isNullConstant() ? OFF_HEAP_LOCATION : LocationIdentity.any();
+            b.add(new RawStoreNode(object, offset, value, kind, locationIdentity));
             if (isVolatile) {
                 b.add(new MembarNode(JMM_POST_VOLATILE_WRITE));
             }
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/PEReadEliminationBlockState.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/PEReadEliminationBlockState.java	Sat Oct 21 00:06:50 2017 +0000
@@ -25,6 +25,8 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.graalvm.compiler.core.common.type.IntegerStamp;
+import org.graalvm.compiler.core.common.type.Stamp;
 import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.nodes.FieldLocationIdentity;
 import org.graalvm.compiler.nodes.ValueNode;
@@ -49,11 +51,15 @@
         public final int index;
         public final JavaKind kind;
 
-        ReadCacheEntry(LocationIdentity identity, ValueNode object, int index, JavaKind kind) {
+        /* This flag does not affect hashCode or equals implementations. */
+        public final boolean overflowAccess;
+
+        ReadCacheEntry(LocationIdentity identity, ValueNode object, int index, JavaKind kind, boolean overflowAccess) {
             this.identity = identity;
             this.object = object;
             this.index = index;
             this.kind = kind;
+            this.overflowAccess = overflowAccess;
         }
 
         @Override
@@ -94,12 +100,38 @@
         return super.toString() + " " + readCache;
     }
 
+    private static JavaKind stampToJavaKind(Stamp stamp) {
+        if (stamp instanceof IntegerStamp) {
+            switch (((IntegerStamp) stamp).getBits()) {
+                case 1:
+                    return JavaKind.Boolean;
+                case 8:
+                    return JavaKind.Byte;
+                case 16:
+                    return ((IntegerStamp) stamp).isPositive() ? JavaKind.Char : JavaKind.Short;
+                case 32:
+                    return JavaKind.Int;
+                case 64:
+                    return JavaKind.Long;
+                default:
+                    throw new IllegalArgumentException("unexpected IntegerStamp " + stamp);
+            }
+        } else {
+            return stamp.getStackKind();
+        }
+    }
+
     @Override
     protected void objectMaterialized(VirtualObjectNode virtual, AllocatedObjectNode representation, List<ValueNode> values) {
         if (virtual instanceof VirtualInstanceNode) {
             VirtualInstanceNode instance = (VirtualInstanceNode) virtual;
             for (int i = 0; i < instance.entryCount(); i++) {
-                readCache.put(new ReadCacheEntry(new FieldLocationIdentity(instance.field(i)), representation, -1, instance.field(i).getJavaKind()), values.get(i));
+                JavaKind declaredKind = instance.field(i).getJavaKind();
+                if (declaredKind == stampToJavaKind(values.get(i).stamp())) {
+                    // We won't cache unaligned field writes upon instantiation unless we add
+                    // support for non-array objects in PEReadEliminationClosure.processUnsafeLoad.
+                    readCache.put(new ReadCacheEntry(new FieldLocationIdentity(instance.field(i)), representation, -1, declaredKind, false), values.get(i));
+                }
             }
         }
     }
@@ -112,7 +144,7 @@
         return super.equivalentTo(other);
     }
 
-    public void addReadCache(ValueNode object, LocationIdentity identity, int index, JavaKind kind, ValueNode value, PartialEscapeClosure<?> closure) {
+    public void addReadCache(ValueNode object, LocationIdentity identity, int index, JavaKind kind, boolean overflowAccess, ValueNode value, PartialEscapeClosure<?> closure) {
         ValueNode cacheObject;
         ObjectState obj = closure.getObjectState(this, object);
         if (obj != null) {
@@ -121,7 +153,7 @@
         } else {
             cacheObject = object;
         }
-        readCache.put(new ReadCacheEntry(identity, cacheObject, index, kind), value);
+        readCache.put(new ReadCacheEntry(identity, cacheObject, index, kind, overflowAccess), value);
     }
 
     public ValueNode getReadCache(ValueNode object, LocationIdentity identity, int index, JavaKind kind, PartialEscapeClosure<?> closure) {
@@ -133,7 +165,7 @@
         } else {
             cacheObject = object;
         }
-        ValueNode cacheValue = readCache.get(new ReadCacheEntry(identity, cacheObject, index, kind));
+        ValueNode cacheValue = readCache.get(new ReadCacheEntry(identity, cacheObject, index, kind, false));
         obj = closure.getObjectState(this, cacheValue);
         if (obj != null) {
             assert !obj.isVirtual();
@@ -153,7 +185,7 @@
         Iterator<ReadCacheEntry> iter = readCache.getKeys().iterator();
         while (iter.hasNext()) {
             ReadCacheEntry entry = iter.next();
-            if (entry.identity.equals(identity) && (index == -1 || entry.index == -1 || index == entry.index)) {
+            if (entry.identity.equals(identity) && (index == -1 || entry.index == -1 || index == entry.index || entry.overflowAccess)) {
                 iter.remove();
             }
         }
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/PEReadEliminationClosure.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/PEReadEliminationClosure.java	Sat Oct 21 00:06:50 2017 +0000
@@ -31,7 +31,6 @@
 
 import org.graalvm.compiler.core.common.cfg.Loop;
 import org.graalvm.compiler.core.common.spi.ConstantFieldProvider;
-import org.graalvm.compiler.core.common.type.Stamp;
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.nodes.AbstractBeginNode;
 import org.graalvm.compiler.nodes.FieldLocationIdentity;
@@ -131,9 +130,10 @@
         return false;
     }
 
-    private boolean processStore(FixedNode store, ValueNode object, LocationIdentity identity, int index, JavaKind kind, ValueNode value, PEReadEliminationBlockState state, GraphEffectList effects) {
+    private boolean processStore(FixedNode store, ValueNode object, LocationIdentity identity, int index, JavaKind accessKind, boolean overflowAccess, ValueNode value,
+                    PEReadEliminationBlockState state, GraphEffectList effects) {
         ValueNode unproxiedObject = GraphUtil.unproxify(object);
-        ValueNode cachedValue = state.getReadCache(object, identity, index, kind, this);
+        ValueNode cachedValue = state.getReadCache(object, identity, index, accessKind, this);
 
         ValueNode finalValue = getScalarAlias(value);
         boolean result = false;
@@ -142,7 +142,7 @@
             result = true;
         }
         state.killReadCache(identity, index);
-        state.addReadCache(unproxiedObject, identity, index, kind, finalValue, this);
+        state.addReadCache(unproxiedObject, identity, index, accessKind, overflowAccess, finalValue, this);
         return result;
     }
 
@@ -150,43 +150,52 @@
         ValueNode unproxiedObject = GraphUtil.unproxify(object);
         ValueNode cachedValue = state.getReadCache(unproxiedObject, identity, index, kind, this);
         if (cachedValue != null) {
-            Stamp loadStamp = load.stamp();
-            Stamp cachedValueStamp = cachedValue.stamp();
-            if (!loadStamp.isCompatible(cachedValueStamp)) {
-                /*
-                 * Can either be the first field of a two slot write to a one slot field which would
-                 * have a non compatible stamp or the second load which will see Illegal.
-                 */
-                assert load.stamp().getStackKind() == JavaKind.Int && (cachedValue.stamp().getStackKind() == JavaKind.Long || cachedValue.getStackKind() == JavaKind.Double ||
-                                cachedValue.getStackKind() == JavaKind.Illegal) : "Can only allow different stack kind two slot marker writes on one slot fields.";
-                return false;
-            } else {
-                // perform the read elimination
-                effects.replaceAtUsages(load, cachedValue, load);
-                addScalarAlias(load, cachedValue);
-                return true;
-            }
+            // perform the read elimination
+            effects.replaceAtUsages(load, cachedValue, load);
+            addScalarAlias(load, cachedValue);
+            return true;
         } else {
-            state.addReadCache(unproxiedObject, identity, index, kind, load, this);
+            state.addReadCache(unproxiedObject, identity, index, kind, false, load, this);
             return false;
         }
     }
 
+    private static boolean isOverflowAccess(JavaKind accessKind, JavaKind declaredKind) {
+        if (accessKind == declaredKind) {
+            return false;
+        }
+        if (accessKind == JavaKind.Object) {
+            switch (declaredKind) {
+                case Object:
+                case Double:
+                case Long:
+                    return false;
+                default:
+                    return true;
+            }
+        }
+        assert accessKind.isPrimitive() : "Illegal access kind";
+        return declaredKind.isPrimitive() ? accessKind.getBitCount() > declaredKind.getBitCount() : true;
+    }
+
     private boolean processUnsafeLoad(RawLoadNode load, PEReadEliminationBlockState state, GraphEffectList effects) {
         if (load.offset().isConstant()) {
             ResolvedJavaType type = StampTool.typeOrNull(load.object());
             if (type != null && type.isArray()) {
+                JavaKind accessKind = load.accessKind();
+                JavaKind componentKind = type.getComponentType().getJavaKind();
                 long offset = load.offset().asJavaConstant().asLong();
-                int index = VirtualArrayNode.entryIndexForOffset(offset, load.accessKind(), type.getComponentType(), Integer.MAX_VALUE);
+                int index = VirtualArrayNode.entryIndexForOffset(offset, accessKind, type.getComponentType(), Integer.MAX_VALUE);
                 ValueNode object = GraphUtil.unproxify(load.object());
-                LocationIdentity location = NamedLocationIdentity.getArrayLocation(type.getComponentType().getJavaKind());
-                ValueNode cachedValue = state.getReadCache(object, location, index, load.accessKind(), this);
-                if (cachedValue != null && load.stamp().isCompatible(cachedValue.stamp())) {
+                LocationIdentity location = NamedLocationIdentity.getArrayLocation(componentKind);
+                ValueNode cachedValue = state.getReadCache(object, location, index, accessKind, this);
+                assert cachedValue == null || load.stamp().isCompatible(cachedValue.stamp()) : "The RawLoadNode's stamp is not compatible with the cached value.";
+                if (cachedValue != null) {
                     effects.replaceAtUsages(load, cachedValue, load);
                     addScalarAlias(load, cachedValue);
                     return true;
                 } else {
-                    state.addReadCache(object, location, index, load.accessKind(), load, this);
+                    state.addReadCache(object, location, index, accessKind, isOverflowAccess(accessKind, componentKind), load, this);
                 }
             }
         }
@@ -196,11 +205,14 @@
     private boolean processUnsafeStore(RawStoreNode store, PEReadEliminationBlockState state, GraphEffectList effects) {
         ResolvedJavaType type = StampTool.typeOrNull(store.object());
         if (type != null && type.isArray()) {
-            LocationIdentity location = NamedLocationIdentity.getArrayLocation(type.getComponentType().getJavaKind());
+            JavaKind accessKind = store.accessKind();
+            JavaKind componentKind = type.getComponentType().getJavaKind();
+            LocationIdentity location = NamedLocationIdentity.getArrayLocation(componentKind);
             if (store.offset().isConstant()) {
                 long offset = store.offset().asJavaConstant().asLong();
-                int index = VirtualArrayNode.entryIndexForOffset(offset, store.accessKind(), type.getComponentType(), Integer.MAX_VALUE);
-                return processStore(store, store.object(), location, index, store.accessKind(), store.value(), state, effects);
+                boolean overflowAccess = isOverflowAccess(accessKind, componentKind);
+                int index = overflowAccess ? -1 : VirtualArrayNode.entryIndexForOffset(offset, accessKind, type.getComponentType(), Integer.MAX_VALUE);
+                return processStore(store, store.object(), location, index, accessKind, overflowAccess, store.value(), state, effects);
             } else {
                 processIdentity(state, location);
             }
@@ -219,7 +231,8 @@
             state.killReadCache();
             return false;
         }
-        return processStore(store, store.object(), new FieldLocationIdentity(store.field()), -1, store.field().getJavaKind(), store.value(), state, effects);
+        JavaKind kind = store.field().getJavaKind();
+        return processStore(store, store.object(), new FieldLocationIdentity(store.field()), -1, kind, false, store.value(), state, effects);
     }
 
     private boolean processLoadField(LoadFieldNode load, PEReadEliminationBlockState state, GraphEffectList effects) {
@@ -230,11 +243,32 @@
         return processLoad(load, load.object(), new FieldLocationIdentity(load.field()), -1, load.field().getJavaKind(), state, effects);
     }
 
+    private static JavaKind getElementKindFromStamp(ValueNode array) {
+        ResolvedJavaType type = StampTool.typeOrNull(array);
+        if (type != null && type.isArray()) {
+            return type.getComponentType().getJavaKind();
+        } else {
+            // It is likely an OSRLocal without valid stamp
+            return JavaKind.Illegal;
+        }
+    }
+
     private boolean processStoreIndexed(StoreIndexedNode store, PEReadEliminationBlockState state, GraphEffectList effects) {
-        LocationIdentity arrayLocation = NamedLocationIdentity.getArrayLocation(store.elementKind());
-        if (store.index().isConstant()) {
-            int index = ((JavaConstant) store.index().asConstant()).asInt();
-            return processStore(store, store.array(), arrayLocation, index, store.elementKind(), store.value(), state, effects);
+        int index = store.index().isConstant() ? ((JavaConstant) store.index().asConstant()).asInt() : -1;
+        // BASTORE (with elementKind being Byte) can be used to store values in boolean arrays.
+        JavaKind elementKind = store.elementKind();
+        if (elementKind == JavaKind.Byte) {
+            elementKind = getElementKindFromStamp(store.array());
+            if (elementKind == JavaKind.Illegal) {
+                // Could not determine the actual access kind from stamp. Hence kill both.
+                state.killReadCache(NamedLocationIdentity.getArrayLocation(JavaKind.Boolean), index);
+                state.killReadCache(NamedLocationIdentity.getArrayLocation(JavaKind.Byte), index);
+                return false;
+            }
+        }
+        LocationIdentity arrayLocation = NamedLocationIdentity.getArrayLocation(elementKind);
+        if (index != -1) {
+            return processStore(store, store.array(), arrayLocation, index, elementKind, false, store.value(), state, effects);
         } else {
             state.killReadCache(arrayLocation, -1);
         }
@@ -244,8 +278,17 @@
     private boolean processLoadIndexed(LoadIndexedNode load, PEReadEliminationBlockState state, GraphEffectList effects) {
         if (load.index().isConstant()) {
             int index = ((JavaConstant) load.index().asConstant()).asInt();
-            LocationIdentity arrayLocation = NamedLocationIdentity.getArrayLocation(load.elementKind());
-            return processLoad(load, load.array(), arrayLocation, index, load.elementKind(), state, effects);
+            // BALOAD (with elementKind being Byte) can be used to retrieve values from boolean
+            // arrays.
+            JavaKind elementKind = load.elementKind();
+            if (elementKind == JavaKind.Byte) {
+                elementKind = getElementKindFromStamp(load.array());
+                if (elementKind == JavaKind.Illegal) {
+                    return false;
+                }
+            }
+            LocationIdentity arrayLocation = NamedLocationIdentity.getArrayLocation(elementKind);
+            return processLoad(load, load.array(), arrayLocation, index, elementKind, state, effects);
         }
         return false;
     }
@@ -293,7 +336,7 @@
                     if (object != null) {
                         Pair<ValueNode, Object> pair = firstValueSet.get(object);
                         while (pair != null) {
-                            initialState.addReadCache(pair.getLeft(), entry.identity, entry.index, entry.kind, initialState.getReadCache().get(entry), this);
+                            initialState.addReadCache(pair.getLeft(), entry.identity, entry.index, entry.kind, entry.overflowAccess, initialState.getReadCache().get(entry), this);
                             pair = (Pair<ValueNode, Object>) pair.getRight();
                         }
                     }
@@ -386,14 +429,14 @@
                 if (phi.getStackKind() == JavaKind.Object) {
                     for (ReadCacheEntry entry : states.get(0).readCache.getKeys()) {
                         if (entry.object == getPhiValueAt(phi, 0)) {
-                            mergeReadCachePhi(phi, entry.identity, entry.index, entry.kind, states);
+                            mergeReadCachePhi(phi, entry.identity, entry.index, entry.kind, entry.overflowAccess, states);
                         }
                     }
                 }
             }
         }
 
-        private void mergeReadCachePhi(PhiNode phi, LocationIdentity identity, int index, JavaKind kind, List<PEReadEliminationBlockState> states) {
+        private void mergeReadCachePhi(PhiNode phi, LocationIdentity identity, int index, JavaKind kind, boolean overflowAccess, List<PEReadEliminationBlockState> states) {
             ValueNode[] values = new ValueNode[states.size()];
             values[0] = states.get(0).getReadCache(getPhiValueAt(phi, 0), identity, index, kind, PEReadEliminationClosure.this);
             if (values[0] != null) {
@@ -407,12 +450,12 @@
                     values[i] = value;
                 }
 
-                PhiNode phiNode = getPhi(new ReadCacheEntry(identity, phi, index, kind), values[0].stamp().unrestricted());
+                PhiNode phiNode = getPhi(new ReadCacheEntry(identity, phi, index, kind, overflowAccess), values[0].stamp().unrestricted());
                 mergeEffects.addFloatingNode(phiNode, "mergeReadCachePhi");
                 for (int i = 0; i < values.length; i++) {
                     setPhiInput(phiNode, i, values[i]);
                 }
-                newState.readCache.put(new ReadCacheEntry(identity, phi, index, kind), phiNode);
+                newState.readCache.put(new ReadCacheEntry(identity, phi, index, kind, overflowAccess), phiNode);
             }
         }
     }
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/ReadEliminationClosure.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/ReadEliminationClosure.java	Sat Oct 21 00:06:50 2017 +0000
@@ -28,6 +28,7 @@
 import java.util.Iterator;
 import java.util.List;
 
+import jdk.vm.ci.meta.ResolvedJavaType;
 import org.graalvm.compiler.core.common.cfg.Loop;
 import org.graalvm.compiler.core.common.type.Stamp;
 import org.graalvm.compiler.graph.Node;
@@ -52,6 +53,7 @@
 import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
 import org.graalvm.compiler.nodes.memory.ReadNode;
 import org.graalvm.compiler.nodes.memory.WriteNode;
+import org.graalvm.compiler.nodes.type.StampTool;
 import org.graalvm.compiler.nodes.util.GraphUtil;
 import org.graalvm.compiler.options.OptionValues;
 import org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.CacheEntry;
@@ -146,37 +148,40 @@
                 processIdentity(state, write.getLocationIdentity());
             }
         } else if (node instanceof UnsafeAccessNode) {
-            if (node instanceof RawLoadNode) {
-                RawLoadNode load = (RawLoadNode) node;
-                if (load.getLocationIdentity().isSingle()) {
-                    ValueNode object = GraphUtil.unproxify(load.object());
-                    UnsafeLoadCacheEntry identifier = new UnsafeLoadCacheEntry(object, load.offset(), load.getLocationIdentity());
-                    ValueNode cachedValue = state.getCacheEntry(identifier);
-                    if (cachedValue != null && areValuesReplaceable(load, cachedValue, considerGuards)) {
-                        effects.replaceAtUsages(load, cachedValue, load);
-                        addScalarAlias(load, cachedValue);
-                        deleted = true;
-                    } else {
-                        state.addCacheEntry(identifier, load);
+            ResolvedJavaType type = StampTool.typeOrNull(((UnsafeAccessNode) node).object());
+            if (type != null && !type.isArray()) {
+                if (node instanceof RawLoadNode) {
+                    RawLoadNode load = (RawLoadNode) node;
+                    if (load.getLocationIdentity().isSingle()) {
+                        ValueNode object = GraphUtil.unproxify(load.object());
+                        UnsafeLoadCacheEntry identifier = new UnsafeLoadCacheEntry(object, load.offset(), load.getLocationIdentity());
+                        ValueNode cachedValue = state.getCacheEntry(identifier);
+                        if (cachedValue != null && areValuesReplaceable(load, cachedValue, considerGuards)) {
+                            effects.replaceAtUsages(load, cachedValue, load);
+                            addScalarAlias(load, cachedValue);
+                            deleted = true;
+                        } else {
+                            state.addCacheEntry(identifier, load);
+                        }
                     }
-                }
-            } else {
-                assert node instanceof RawStoreNode;
-                RawStoreNode write = (RawStoreNode) node;
-                if (write.getLocationIdentity().isSingle()) {
-                    ValueNode object = GraphUtil.unproxify(write.object());
-                    UnsafeLoadCacheEntry identifier = new UnsafeLoadCacheEntry(object, write.offset(), write.getLocationIdentity());
-                    ValueNode cachedValue = state.getCacheEntry(identifier);
+                } else {
+                    assert node instanceof RawStoreNode;
+                    RawStoreNode write = (RawStoreNode) node;
+                    if (write.getLocationIdentity().isSingle()) {
+                        ValueNode object = GraphUtil.unproxify(write.object());
+                        UnsafeLoadCacheEntry identifier = new UnsafeLoadCacheEntry(object, write.offset(), write.getLocationIdentity());
+                        ValueNode cachedValue = state.getCacheEntry(identifier);
 
-                    ValueNode value = getScalarAlias(write.value());
-                    if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) {
-                        effects.deleteNode(write);
-                        deleted = true;
+                        ValueNode value = getScalarAlias(write.value());
+                        if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) {
+                            effects.deleteNode(write);
+                            deleted = true;
+                        }
+                        processIdentity(state, write.getLocationIdentity());
+                        state.addCacheEntry(identifier, value);
+                    } else {
+                        processIdentity(state, write.getLocationIdentity());
                     }
-                    processIdentity(state, write.getLocationIdentity());
-                    state.addCacheEntry(identifier, value);
-                } else {
-                    processIdentity(state, write.getLocationIdentity());
                 }
             }
         } else if (node instanceof MemoryCheckpoint.Single) {
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.word/src/org/graalvm/compiler/word/WordOperationPlugin.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.word/src/org/graalvm/compiler/word/WordOperationPlugin.java	Sat Oct 21 00:06:50 2017 +0000
@@ -268,6 +268,9 @@
         }
 
         Word.Operation operation = BridgeMethodUtils.getAnnotation(Word.Operation.class, wordMethod);
+        if (operation == null) {
+            throw bailout(b, "Cannot call method on a word value: " + wordMethod.format("%H.%n(%p)"));
+        }
         switch (operation.opcode()) {
             case NODE_CLASS:
                 assert args.length == 2;
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.graphio/src/org/graalvm/graphio/GraphProtocol.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.graphio/src/org/graalvm/graphio/GraphProtocol.java	Sat Oct 21 00:06:50 2017 +0000
@@ -527,7 +527,7 @@
             final int bci = findNodeSourcePositionBCI(pos);
             writeInt(bci);
             StackTraceElement ste = findMethodStackTraceElement(method, bci, pos);
-            if (ste != null) {
+            if (ste != null && ste.getFileName() != null) {
                 writePoolObject(ste.getFileName());
                 writeInt(ste.getLineNumber());
             } else {
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.options/src/org/graalvm/options/OptionKey.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.options/src/org/graalvm/options/OptionKey.java	Sat Oct 21 00:06:50 2017 +0000
@@ -53,13 +53,11 @@
     }
 
     /**
-     * Constructs a new option key given a default value and option key. The default value and the
-     * type must not be <code>null</code>.
+     * Constructs a new option key given a default value and option key.
      *
      * @since 1.0
      */
     public OptionKey(T defaultValue, OptionType<T> type) {
-        Objects.requireNonNull(defaultValue);
         Objects.requireNonNull(type);
         this.defaultValue = defaultValue;
         this.type = type;
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.options/src/org/graalvm/options/OptionType.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.options/src/org/graalvm/options/OptionType.java	Sat Oct 21 00:06:50 2017 +0000
@@ -57,7 +57,6 @@
      */
     public OptionType(String name, T defaultValue, Function<String, T> stringConverter, Consumer<T> validator) {
         Objects.requireNonNull(name);
-        Objects.requireNonNull(defaultValue);
         Objects.requireNonNull(stringConverter);
         Objects.requireNonNull(validator);
         this.name = name;
@@ -133,7 +132,7 @@
         return "OptionType[name=" + name + ", defaultValue=" + defaultValue + "]";
     }
 
-    private static Map<Class<?>, OptionType<?>> DEFAULTTYPES = new HashMap<>();
+    private static final Map<Class<?>, OptionType<?>> DEFAULTTYPES = new HashMap<>();
     static {
         DEFAULTTYPES.put(Boolean.class, new OptionType<>("Boolean", false, new Function<String, Boolean>() {
             public Boolean apply(String t) {
@@ -200,13 +199,24 @@
 
     /**
      * Returns the default option type for a given value. Returns <code>null</code> if no default
-     * option type is available for this Java type.
+     * option type is available for the Java type of this value.
      *
      * @since 1.0
      */
     @SuppressWarnings("unchecked")
-    public static <T> OptionType<T> defaultType(Object value) {
-        return (OptionType<T>) DEFAULTTYPES.get(value.getClass());
+    public static <T> OptionType<T> defaultType(T value) {
+        return defaultType((Class<T>) value.getClass());
+    }
+
+    /**
+     * Returns the default option type for a class. Returns <code>null</code> if no default option
+     * type is available for this Java type.
+     *
+     * @since 1.0
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> OptionType<T> defaultType(Class<T> clazz) {
+        return (OptionType<T>) DEFAULTTYPES.get(clazz);
     }
 
 }
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractExecutableMemberWriter.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractExecutableMemberWriter.java	Sat Oct 21 00:06:50 2017 +0000
@@ -313,7 +313,8 @@
      * @return the 1.4.x style anchor for the executable element.
      */
     protected String getErasureAnchor(ExecutableElement executableElement) {
-        final StringBuilder buf = new StringBuilder(name(executableElement) + "(");
+        final StringBuilder buf = new StringBuilder(writer.anchorName(executableElement));
+        buf.append("(");
         List<? extends VariableElement> parameters = executableElement.getParameters();
         boolean foundTypeVariable = false;
         for (int i = 0; i < parameters.size(); i++) {
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FrameOutputWriter.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FrameOutputWriter.java	Sat Oct 21 00:06:50 2017 +0000
@@ -25,11 +25,15 @@
 
 package jdk.javadoc.internal.doclets.formats.html;
 
+import jdk.javadoc.internal.doclets.formats.html.markup.Comment;
+import jdk.javadoc.internal.doclets.formats.html.markup.DocType;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr;
+import jdk.javadoc.internal.doclets.formats.html.markup.HtmlDocument;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
 import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
+import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
 import jdk.javadoc.internal.doclets.toolkit.Content;
 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
@@ -110,15 +114,41 @@
             body.addContent(frame);
         }
         if (configuration.windowtitle.length() > 0) {
-            printFramesDocument(configuration.windowtitle, configuration,
-                    body);
+            printFramesDocument(configuration.windowtitle, body);
         } else {
-            printFramesDocument(configuration.getText("doclet.Generated_Docs_Untitled"),
-                    configuration, body);
+            printFramesDocument(configuration.getText("doclet.Generated_Docs_Untitled"), body);
         }
     }
 
     /**
+     * Print the frames version of the Html file header.
+     * Called only when generating an HTML frames file.
+     *
+     * @param title Title of this HTML document
+     * @param body the body content tree to be added to the HTML document
+     * @throws DocFileIOException if there is an error writing the frames document
+     */
+    private void printFramesDocument(String title, HtmlTree body) throws DocFileIOException {
+        Content htmlDocType = configuration.isOutputHtml5()
+                ? DocType.HTML5
+                : DocType.TRANSITIONAL;
+        Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
+        Content head = new HtmlTree(HtmlTag.HEAD);
+        head.addContent(getGeneratedBy(!configuration.notimestamp));
+        Content windowTitle = HtmlTree.TITLE(new StringContent(title));
+        head.addContent(windowTitle);
+        Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE, configuration.charset);
+        head.addContent(meta);
+        head.addContent(getStyleSheetProperties(configuration));
+        head.addContent(getFramesJavaScript());
+        Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
+                head, body);
+        Content htmlDocument = new HtmlDocument(htmlDocType,
+                htmlComment, htmlTree);
+        write(htmlDocument);
+    }
+
+    /**
      * Get the frame sizes and their contents.
      *
      * @return a content tree for the frame details
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java	Sat Oct 21 00:06:50 2017 +0000
@@ -33,6 +33,7 @@
 import javax.lang.model.element.AnnotationMirror;
 import javax.lang.model.element.AnnotationValue;
 import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
 import javax.lang.model.element.ExecutableElement;
 import javax.lang.model.element.ModuleElement;
 import javax.lang.model.element.Name;
@@ -74,6 +75,7 @@
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
+import jdk.javadoc.internal.doclets.formats.html.markup.HtmlVersion;
 import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
@@ -1468,20 +1470,18 @@
         if (isProperty) {
             return executableElement.getSimpleName().toString();
         }
-        String signature = utils.signature(executableElement);
-        StringBuilder signatureParsed = new StringBuilder();
-        int counter = 0;
-        for (int i = 0; i < signature.length(); i++) {
-            char c = signature.charAt(i);
-            if (c == '<') {
-                counter++;
-            } else if (c == '>') {
-                counter--;
-            } else if (counter == 0) {
-                signatureParsed.append(c);
-            }
+        String member = anchorName(executableElement);
+        String erasedSignature = utils.makeSignature(executableElement, true, true);
+        return member + erasedSignature;
+    }
+
+    public String anchorName(Element member) {
+        if (member.getKind() == ElementKind.CONSTRUCTOR
+                && configuration.isOutputHtml5()) {
+            return "<init>";
+        } else {
+            return utils.getSimpleName(member);
         }
-        return utils.getSimpleName(executableElement) + signatureParsed.toString();
     }
 
     public Content seeTagToContent(Element element, DocTree see) {
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlDocWriter.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlDocWriter.java	Sat Oct 21 00:06:50 2017 +0000
@@ -37,7 +37,6 @@
 import jdk.javadoc.internal.doclets.toolkit.Content;
 import jdk.javadoc.internal.doclets.toolkit.Messages;
 import jdk.javadoc.internal.doclets.toolkit.util.DocFile;
-import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
 import jdk.javadoc.internal.doclets.toolkit.util.DocLink;
 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
@@ -60,7 +59,8 @@
 
     public static final String CONTENT_TYPE = "text/html";
 
-    DocPath pathToRoot;
+    private final HtmlConfiguration configuration;
+    private final DocPath pathToRoot;
 
     /**
      * Constructor. Initializes the destination file name through the super
@@ -69,8 +69,9 @@
      * @param configuration the configuration for this doclet
      * @param filename String file name.
      */
-    public HtmlDocWriter(BaseConfiguration configuration, DocPath filename) {
+    public HtmlDocWriter(HtmlConfiguration configuration, DocPath filename) {
         super(configuration, filename);
+        this.configuration = configuration;
         this.pathToRoot = filename.parent().invert();
         Messages messages = configuration.getMessages();
         messages.notice("doclet.Generating_0",
@@ -81,7 +82,9 @@
      * Accessor for configuration.
      * @return the configuration for this doclet
      */
-    public abstract BaseConfiguration configuration();
+    public BaseConfiguration configuration() {
+        return configuration;
+    }
 
     public Content getHyperLink(DocPath link, String label) {
         return getHyperLink(link, new StringContent(label), false, "", "", "");
@@ -167,8 +170,6 @@
      * @return a valid HTML name string.
      */
     public String getName(String name) {
-        StringBuilder sb = new StringBuilder();
-        char ch;
         /* The HTML 4 spec at http://www.w3.org/TR/html4/types.html#h-6.2 mentions
          * that the name/id should begin with a letter followed by other valid characters.
          * The HTML 5 spec (draft) is more permissive on names/ids where the only restriction
@@ -179,8 +180,14 @@
          * substitute it accordingly, "_" and "$" can appear at the beginning of a member name.
          * The method substitutes "$" with "Z:Z:D" and will prefix "_" with "Z:Z".
          */
+
+        if (configuration.isOutputHtml5()) {
+            return name.replaceAll(" +", "");
+        }
+
+        StringBuilder sb = new StringBuilder();
         for (int i = 0; i < name.length(); i++) {
-            ch = name.charAt(i);
+            char ch = name.charAt(i);
             switch (ch) {
                 case '(':
                 case ')':
@@ -310,36 +317,6 @@
     }
 
     /**
-     * Print the frames version of the Html file header.
-     * Called only when generating an HTML frames file.
-     *
-     * @param title Title of this HTML document
-     * @param configuration the configuration object
-     * @param body the body content tree to be added to the HTML document
-     * @throws DocFileIOException if there is an error writing the frames document
-     */
-    public void printFramesDocument(String title, HtmlConfiguration configuration,
-            HtmlTree body) throws DocFileIOException {
-        Content htmlDocType = configuration.isOutputHtml5()
-                ? DocType.HTML5
-                : DocType.TRANSITIONAL;
-        Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
-        Content head = new HtmlTree(HtmlTag.HEAD);
-        head.addContent(getGeneratedBy(!configuration.notimestamp));
-        Content windowTitle = HtmlTree.TITLE(new StringContent(title));
-        head.addContent(windowTitle);
-        Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE, configuration.charset);
-        head.addContent(meta);
-        head.addContent(getStyleSheetProperties(configuration));
-        head.addContent(getFramesJavaScript());
-        Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
-                head, body);
-        Content htmlDocument = new HtmlDocument(htmlDocType,
-                htmlComment, htmlTree);
-        write(htmlDocument);
-    }
-
-    /**
      * Returns a link to the stylesheet file.
      *
      * @param configuration the configuration for this doclet
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java	Sat Oct 21 00:06:50 2017 +0000
@@ -181,36 +181,63 @@
         return s;
     }
 
-    /**
-     * A set of ASCII URI characters to be left unencoded.
+    /*
+     * The sets of ASCII URI characters to be left unencoded.
+     * See "Uniform Resource Identifier (URI): Generic Syntax"
+     * IETF RFC 3986. https://tools.ietf.org/html/rfc3986
      */
-    public static final BitSet NONENCODING_CHARS = new BitSet(256);
+    public static final BitSet MAIN_CHARS;
+    public static final BitSet QUERY_FRAGMENT_CHARS;
 
     static {
-        // alphabetic characters
-        for (int i = 'a'; i <= 'z'; i++) {
-            NONENCODING_CHARS.set(i);
-        }
-        for (int i = 'A'; i <= 'Z'; i++) {
-            NONENCODING_CHARS.set(i);
+        BitSet alphaDigit = bitSet(bitSet('A', 'Z'), bitSet('a', 'z'), bitSet('0', '9'));
+        BitSet unreserved = bitSet(alphaDigit, bitSet("-._~"));
+        BitSet genDelims = bitSet(":/?#[]@");
+        BitSet subDelims = bitSet("!$&'()*+,;=");
+        MAIN_CHARS = bitSet(unreserved, genDelims, subDelims);
+        BitSet pchar = bitSet(unreserved, subDelims, bitSet(":@"));
+        QUERY_FRAGMENT_CHARS = bitSet(pchar, bitSet("/?"));
+    }
+
+    private static BitSet bitSet(String s) {
+        BitSet result = new BitSet();
+        for (int i = 0; i < s.length(); i++) {
+           result.set(s.charAt(i));
         }
-        // numeric characters
-        for (int i = '0'; i <= '9'; i++) {
-            NONENCODING_CHARS.set(i);
-        }
-        // Reserved characters as per RFC 3986. These are set of delimiting characters.
-        String noEnc = ":/?#[]@!$&'()*+,;=";
-        // Unreserved characters as per RFC 3986 which should not be percent encoded.
-        noEnc += "-._~";
-        for (int i = 0; i < noEnc.length(); i++) {
-            NONENCODING_CHARS.set(noEnc.charAt(i));
-        }
+        return result;
+    }
+
+    private static BitSet bitSet(char from, char to) {
+        BitSet result = new BitSet();
+        result.set(from, to + 1);
+        return result;
     }
 
+    private static BitSet bitSet(BitSet... sets) {
+        BitSet result = new BitSet();
+        for (BitSet set : sets) {
+            result.or(set);
+        }
+        return result;
+    }
+
+    /**
+     * Apply percent-encoding to a URL.
+     * This is similar to {@link java.net.URLEncoder} but
+     * is less aggressive about encoding some characters,
+     * like '(', ')', ',' which are used in the anchor
+     * names for Java methods in HTML5 mode.
+     */
     private static String encodeURL(String url) {
+        BitSet nonEncodingChars = MAIN_CHARS;
         StringBuilder sb = new StringBuilder();
         for (byte c : url.getBytes(Charset.forName("UTF-8"))) {
-            if (NONENCODING_CHARS.get(c & 0xFF)) {
+            if (c == '?' || c == '#') {
+                sb.append((char) c);
+                // switch to the more restrictive set inside
+                // the query and/or fragment
+                nonEncodingChars = QUERY_FRAGMENT_CHARS;
+            } else if (nonEncodingChars.get(c & 0xFF)) {
                 sb.append((char) c);
             } else {
                 sb.append(String.format("%%%02X", c & 0xFF));
--- a/src/jdk.jlink/share/classes/module-info.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.jlink/share/classes/module-info.java	Sat Oct 21 00:06:50 2017 +0000
@@ -38,14 +38,13 @@
  * or the {@link java.util.ServiceLoader service loader} with the name
  * {@code "jlink"} or {@code "jmod"} as appropriate.
  *
- * <p> <em>{@extLink jimage_tool_reference jimage}</em> only exists
+ * <p> <em>jimage</em> only exists
  * as a command-line tool, and does not provide any direct API.
  *
  * <dl style="font-family:'DejaVu Sans', Arial, Helvetica, sans serif">
  * <dt class="simpleTagLabel">Tool Guides:
  * <dd>{@extLink jlink_tool_reference jlink},
- *     {@extLink jmod_tool_reference jmod},
- *     {@extLink jimage_tool_reference jimage}
+ *     {@extLink jmod_tool_reference jmod}
  * </dl>
  *
  * @provides java.util.spi.ToolProvider
--- a/src/jdk.jshell/share/classes/jdk/jshell/Eval.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.jshell/share/classes/jdk/jshell/Eval.java	Sat Oct 21 00:06:50 2017 +0000
@@ -295,6 +295,10 @@
                 Range rtype = dis.treeToRange(baseType);
                 typeWrap = Wrap.rangeWrap(compileSource, rtype);
             } else {
+                AnalyzeTask at = trialCompile(Wrap.methodWrap(compileSource));
+                if (at.hasErrors()) {
+                    return compileFailResult(at, userSource, kindOfTree(unitTree));
+                }
                 Tree init = vt.getInitializer();
                 if (init != null) {
                     Range rinit = dis.treeToRange(init);
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/IdentNode.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/IdentNode.java	Sat Oct 21 00:06:50 2017 +0000
@@ -477,4 +477,14 @@
     public IdentNode setIsDestructuredParameter() {
         return new IdentNode(this, name, type, flags | DESTRUCTURED_PARAMETER, programPoint, conversion);
     }
+
+    /**
+     * Checks whether the source code for this ident contains a unicode escape sequence by comparing
+     * the length of its name with its length in source code.
+     *
+     * @return true if ident source contains a unicode escape sequence
+     */
+    public boolean containsEscapes() {
+        return Token.descLength(getToken()) != name.length();
+    }
 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Lexer.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Lexer.java	Sat Oct 21 00:06:50 2017 +0000
@@ -786,15 +786,9 @@
             if (ch0 == '\\' && ch1 == 'u') {
                 skip(2);
                 final int ch = hexSequence(4, TokenType.IDENT);
-                if (isWhitespace((char)ch)) {
-                    return null;
-                }
-                if (ch < 0) {
-                    sb.append('\\');
-                    sb.append('u');
-                } else {
-                    sb.append((char)ch);
-                }
+                assert ! isWhitespace((char)ch);
+                assert ch >= 0;
+                sb.append((char)ch);
             } else {
                 // Add regular character.
                 sb.append(ch0);
@@ -994,9 +988,6 @@
             if (ch0 == '\\') {
                 type = ESCSTRING;
                 skip(1);
-                if (! isEscapeCharacter(ch0)) {
-                    error(Lexer.message("invalid.escape.char"), STRING, position, limit);
-                }
                 if (isEOL(ch0)) {
                     // Multiline string literal
                     skipEOL(false);
@@ -1093,9 +1084,6 @@
             } else if (ch0 == '\\') {
                 skip(1);
                 // EscapeSequence
-                if (!isEscapeCharacter(ch0)) {
-                    error(Lexer.message("invalid.escape.char"), TEMPLATE, position, limit);
-                }
                 if (isEOL(ch0)) {
                     // LineContinuation
                     skipEOL(false);
@@ -1115,16 +1103,6 @@
     }
 
     /**
-     * Is the given character a valid escape char after "\" ?
-     *
-     * @param ch character to be checked
-     * @return if the given character is valid after "\"
-     */
-    protected boolean isEscapeCharacter(final char ch) {
-        return true;
-    }
-
-    /**
      * Convert string to number.
      *
      * @param valueString  String to convert.
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1472,12 +1472,7 @@
      */
     private void verifyIdent(final IdentNode ident, final String contextString) {
         verifyStrictIdent(ident, contextString);
-        if (isES6()) {
-            final TokenType tokenType = TokenLookup.lookupKeyword(ident.getName().toCharArray(), 0, ident.getName().length());
-            if (tokenType != IDENT && tokenType.getKind() != TokenKind.FUTURESTRICT) {
-                throw error(expectMessage(IDENT));
-            }
-        }
+        checkEscapedKeyword(ident);
     }
 
     /**
@@ -1502,6 +1497,18 @@
         }
     }
 
+    /**
+     * ES6 11.6.2: A code point in a ReservedWord cannot be expressed by a | UnicodeEscapeSequence.
+     */
+    private void checkEscapedKeyword(final IdentNode ident) {
+        if (isES6() && ident.containsEscapes()) {
+            final TokenType tokenType = TokenLookup.lookupKeyword(ident.getName().toCharArray(), 0, ident.getName().length());
+            if (tokenType != IDENT && !(tokenType.getKind() == TokenKind.FUTURESTRICT && !isStrictMode)) {
+                throw error(AbstractParser.message("keyword.escaped.character"), ident.getToken());
+            }
+        }
+    }
+
     /*
      * VariableStatement :
      *      var VariableDeclarationList ;
@@ -2646,7 +2653,7 @@
                     });
                 } else {
                     // ECMA 12.4.1 strict mode restrictions
-                    verifyStrictIdent((IdentNode) exception, "catch argument");
+                    verifyIdent((IdentNode) exception, "catch argument");
                 }
 
 
@@ -2761,6 +2768,7 @@
                 break;
             }
             detectSpecialProperty(ident);
+            checkEscapedKeyword(ident);
             return ident;
         case OCTAL_LEGACY:
             if (isStrictMode) {
@@ -3404,6 +3412,7 @@
             // Catch special functions.
             if (lhs instanceof IdentNode) {
                 detectSpecialFunction((IdentNode)lhs);
+                checkEscapedKeyword((IdentNode)lhs);
             }
 
             lhs = new CallNode(callLine, callToken, finish, lhs, arguments, false);
@@ -3779,7 +3788,7 @@
                 expect(IDENT);
             }
             name = getIdent();
-            verifyStrictIdent(name, "function name");
+            verifyIdent(name, "function name");
         } else if (isStatement) {
             // Nashorn extension: anonymous function statements.
             // Do not allow anonymous function statement if extensions
@@ -4871,7 +4880,7 @@
         final String contextString = "function parameter";
         if (param instanceof IdentNode) {
             final IdentNode ident = (IdentNode)param;
-            verifyStrictIdent(ident, contextString);
+            verifyIdent(ident, contextString);
             final ParserContextFunctionNode currentFunction = lc.getCurrentFunction();
             if (currentFunction != null) {
                 currentFunction.addParameterBinding(ident);
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Messages.properties	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Messages.properties	Sat Oct 21 00:06:50 2017 +0000
@@ -62,6 +62,7 @@
 parser.error.trailing.comma.in.json=Trailing comma is not allowed in JSON
 parser.error.missing.const.assignment=Missing assignment to constant "{0}"
 parser.error.unterminated.template.expression=Expected } after expression in template literal
+parser.error.keyword.escaped.character=Keyword must not contain escaped characters
 
 # ES6 mode error messages
 parser.error.multiple.constructors=Class contains more than one constructor
--- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java	Sat Oct 21 00:06:50 2017 +0000
@@ -27,10 +27,12 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.time.DateTimeException;
 import java.time.Instant;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.regex.PatternSyntaxException;
 import java.util.concurrent.TimeUnit;
 
@@ -106,26 +108,32 @@
      * Converts DOS time to Java time (number of milliseconds since epoch).
      */
     public static long dosToJavaTime(long dtime) {
-        int year;
-        int month;
-        int day;
+        int year = (int) (((dtime >> 25) & 0x7f) + 1980);
+        int month = (int) ((dtime >> 21) & 0x0f);
+        int day = (int) ((dtime >> 16) & 0x1f);
         int hour = (int) ((dtime >> 11) & 0x1f);
         int minute = (int) ((dtime >> 5) & 0x3f);
         int second = (int) ((dtime << 1) & 0x3e);
-        if ((dtime >> 16) == 0) {
-            // Interpret the 0 DOS date as 1979-11-30 for compatibility with
-            // other implementations.
-            year = 1979;
-            month = 11;
-            day = 30;
-        } else {
-            year = (int) (((dtime >> 25) & 0x7f) + 1980);
-            month = (int) ((dtime >> 21) & 0x0f);
-            day = (int) ((dtime >> 16) & 0x1f);
+
+        if (month > 0 && month < 13 && day > 0 && hour < 24 && minute < 60 && second < 60) {
+            try {
+                LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, minute, second);
+                return TimeUnit.MILLISECONDS.convert(ldt.toEpochSecond(
+                        ZoneId.systemDefault().getRules().getOffset(ldt)), TimeUnit.SECONDS);
+            } catch (DateTimeException dte) {
+                // ignore
+            }
         }
-        LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, minute, second);
-        return TimeUnit.MILLISECONDS.convert(ldt.toEpochSecond(
-                ZoneId.systemDefault().getRules().getOffset(ldt)), TimeUnit.SECONDS);
+        return overflowDosToJavaTime(year, month, day, hour, minute, second);
+    }
+
+    /*
+     * Deal with corner cases where an arguably mal-formed DOS time is used
+     */
+    @SuppressWarnings("deprecation") // Use of Date constructor
+    private static long overflowDosToJavaTime(int year, int month, int day,
+                                              int hour, int minute, int second) {
+        return new Date(year - 1900, month - 1, day, hour, minute, second).getTime();
     }
 
     /*
--- a/test/TestCommon.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/TestCommon.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -360,6 +360,9 @@
   JTREG_TESTVM_MEMORY_OPTION = -vmoption:-Xmx512m
   JTREG_TEST_OPTIONS += $(JTREG_TESTVM_MEMORY_OPTION)
 endif
+# Make it possible to specify the JIB_DATA_DIR for tests using the
+# JIB Artifact resolver
+JTREG_BASIC_OPTIONS += -e:JIB_DATA_DIR
 # Give tests access to JT_JAVA, see JDK-8141609
 JTREG_BASIC_OPTIONS += -e:JDK8_HOME=${JT_JAVA}
 # Give aot tests access to Visual Studio installation
--- a/test/hotspot/gtest/gtestLauncher.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/gtest/gtestLauncher.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -21,7 +21,7 @@
  * questions.
  */
 
-#include "prims/jni.h"
+#include "jni.h"
 
 extern "C" {
   JNIIMPORT void JNICALL runUnitTests(int argv, char** argc);
--- a/test/hotspot/gtest/gtestMain.cpp	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/gtest/gtestMain.cpp	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -35,7 +35,7 @@
 #include <pthread.h>
 #endif
 
-#include "prims/jni.h"
+#include "jni.h"
 #include "unittest.hpp"
 
 // Default value for -new-thread option: true on AIX because we run into
@@ -319,4 +319,3 @@
     runUnitTestsInner(argc, argv);
   }
 }
-
--- a/test/hotspot/jtreg/ProblemList.txt	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/jtreg/ProblemList.txt	Sat Oct 21 00:06:50 2017 +0000
@@ -64,7 +64,6 @@
 gc/g1/humongousObjects/TestHeapCounters.java 8178918 generic-all
 gc/stress/gclocker/TestGCLockerWithG1.java 8179226 generic-all
 gc/survivorAlignment/TestPromotionFromSurvivorToTenuredAfterMinorGC.java 8177765 generic-all
-gc/logging/TestPrintReferences.java 8188245 generic-all
 
 #############################################################################
 
--- a/test/hotspot/jtreg/compiler/aot/calls/fromAot/AotInvokeDynamic2AotTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/jtreg/compiler/aot/calls/fromAot/AotInvokeDynamic2AotTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -25,7 +25,6 @@
  * @test
  * @requires vm.aot
  * @library /test/lib /testlibrary /
- * @ignore 8132547
  * @modules java.base/jdk.internal.org.objectweb.asm
  *          java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeDynamic
--- a/test/hotspot/jtreg/compiler/aot/calls/fromAot/AotInvokeDynamic2CompiledTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/jtreg/compiler/aot/calls/fromAot/AotInvokeDynamic2CompiledTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -25,7 +25,6 @@
  * @test
  * @requires vm.aot
  * @library /test/lib /testlibrary /
- * @ignore 8132547
  * @modules java.base/jdk.internal.org.objectweb.asm
  *          java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeDynamic
--- a/test/hotspot/jtreg/compiler/aot/calls/fromAot/AotInvokeDynamic2InterpretedTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/jtreg/compiler/aot/calls/fromAot/AotInvokeDynamic2InterpretedTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -25,7 +25,6 @@
  * @test
  * @requires vm.aot
  * @library /test/lib /testlibrary /
- * @ignore 8132547
  * @modules java.base/jdk.internal.org.objectweb.asm
  *          java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeDynamic
--- a/test/hotspot/jtreg/compiler/aot/calls/fromAot/AotInvokeDynamic2NativeTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/jtreg/compiler/aot/calls/fromAot/AotInvokeDynamic2NativeTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -25,7 +25,6 @@
  * @test
  * @requires vm.aot
  * @library /test/lib /testlibrary /
- * @ignore 8132547
  * @modules java.base/jdk.internal.org.objectweb.asm
  *          java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeDynamic
--- a/test/hotspot/jtreg/compiler/aot/scripts/test-javac.sh	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/jtreg/compiler/aot/scripts/test-javac.sh	Sat Oct 21 00:06:50 2017 +0000
@@ -108,7 +108,7 @@
 done
 
 NAME="jvmci"
-DIR="$DIR/../../../../src/jdk.internal.vm.ci"
+DIR="$DIR/../../../../../../src/jdk.internal.vm.ci"
 FILES=`find $DIR -type f -name '*.java'`
 COUNT=`find $DIR -type f -name '*.java' | wc -l`
 
--- a/test/hotspot/jtreg/compiler/jvmci/common/patches/jdk.internal.vm.ci/jdk/vm/ci/hotspot/CompilerToVMHelper.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/jtreg/compiler/jvmci/common/patches/jdk.internal.vm.ci/jdk/vm/ci/hotspot/CompilerToVMHelper.java	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -308,10 +308,6 @@
         return CompilerToVM.class;
     }
 
-    public static Class<?> HotSpotConstantPoolClass() {
-        return HotSpotConstantPool.class;
-    }
-
     public static Class<?> getMirror(HotSpotResolvedObjectType type) {
         return ((HotSpotResolvedJavaType) type).mirror();
     }
--- a/test/hotspot/jtreg/compiler/loopopts/TestMoveStoresOutOfLoops.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/jtreg/compiler/loopopts/TestMoveStoresOutOfLoops.java	Sat Oct 21 00:06:50 2017 +0000
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 8080289
+ * @bug 8080289 8189067
  * @summary Move stores out of loops if possible
  *
  * @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation
@@ -43,6 +43,7 @@
     private static long[] array = new long[10];
     private static long[] array2 = new long[10];
     private static boolean[] array3 = new boolean[1000];
+    private static int[] array4 = new int[1000];
     private static byte[] byte_array = new byte[10];
 
     // Array store should be moved out of the loop, value stored
@@ -108,6 +109,15 @@
         }
     }
 
+    // Array store can be moved out of the inner loop
+    static void test_after_7(int idx) {
+        for (int i = 0; i < 1000; i++) {
+            for (int j = 0; j <= 42; j++) {
+                array4[i] = j;
+            }
+        }
+    }
+
     // Optimize out redundant stores
     static void test_stores_1(int ignored) {
         array[0] = 0;
@@ -285,6 +295,17 @@
         return success;
     }
 
+    static boolean array_check5(String name) {
+        boolean success = true;
+        for (int i = 0; i < 1000; i++) {
+            if (array4[i] != 42) {
+                success = false;
+                System.out.println(name + " failed: array[" + i + "] = " + array4[i]);
+            }
+        }
+        return success;
+    }
+
     static public void main(String[] args) throws Exception {
         TestMoveStoresOutOfLoops test = new TestMoveStoresOutOfLoops();
         test.doTest("test_after_1", TestMoveStoresOutOfLoops::array_init, TestMoveStoresOutOfLoops::array_check);
@@ -295,6 +316,7 @@
         test.doTest("test_after_6", TestMoveStoresOutOfLoops::array_init, TestMoveStoresOutOfLoops::array_check);
         array3[999] = true;
         test.doTest("test_after_6", TestMoveStoresOutOfLoops::array_init, TestMoveStoresOutOfLoops::array_check);
+        test.doTest("test_after_7", TestMoveStoresOutOfLoops::array_init, TestMoveStoresOutOfLoops::array_check5);
 
         test.doTest("test_stores_1", TestMoveStoresOutOfLoops::array_init3, TestMoveStoresOutOfLoops::array_check3);
         test.doTest("test_stores_2", TestMoveStoresOutOfLoops::array_init3, TestMoveStoresOutOfLoops::array_check3);
--- a/test/hotspot/jtreg/gc/logging/TestPrintReferences.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/jtreg/gc/logging/TestPrintReferences.java	Sat Oct 21 00:06:50 2017 +0000
@@ -23,7 +23,7 @@
 
 /*
  * @test TestPrintReferences
- * @bug 8136991 8186402 8186465
+ * @bug 8136991 8186402 8186465 8188245
  * @summary Validate the reference processing logging
  * @key gc
  * @library /test/lib
@@ -32,6 +32,7 @@
  */
 
 import java.lang.ref.SoftReference;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 
 import jdk.test.lib.process.OutputAnalyzer;
@@ -108,7 +109,7 @@
   }
 
   // After getting time value, update 'output' for next use.
-  public static double getTimeValue(String name, int indentCount) {
+  public static BigDecimal getTimeValue(String name, int indentCount) {
     // Pattern of 'name', 'value' and some extra strings.
     String patternString = gcLogTimeRegex + indent(indentCount) + name + ": " + "(" + doubleRegex + ")";
     Matcher m = Pattern.compile(patternString).matcher(output);
@@ -126,59 +127,63 @@
       output = output.substring(index, output.length());
     }
 
-    return result;
+    // Convert to BigDecimal to control the precision of floating point arithmetic.
+    return BigDecimal.valueOf(result);
   }
 
   // Reference log is printing 1 decimal place of elapsed time.
   // So sum of each sub-phases could be slightly larger than the enclosing phase in some cases.
-  // As the maximum of sub-phases is 3, allow 0.1 of TOLERANCE.
-  // e.g. Actual value:  SoftReference(5.55) = phase1(1.85) + phase2(1.85) + phase3(1.85)
+  // e.g. If there are 3 sub-phases:
+  //      Actual value:  SoftReference(5.55) = phase1(1.85) + phase2(1.85) + phase3(1.85)
   //      Log value:     SoftReference(5.6) = phase1(1.9) + phase2(1.9) + phase3(1.9)
   //      When checked:  5.6 < 5.7 (sum of phase1~3)
-  public static boolean approximatelyEqual(double a, double b) {
-    final double TOLERANCE = 0.1;
+  public static boolean approximatelyEqual(BigDecimal phaseTime, BigDecimal sumOfSubPhasesTime, BigDecimal tolerance) {
+    BigDecimal abs = phaseTime.subtract(sumOfSubPhasesTime).abs();
+
+    int result = abs.compareTo(tolerance);
 
-    return Math.abs(a - b) <= TOLERANCE;
-  }
-
-  // Return false, if 'total' is larger and not approximately equal to 'refTime'.
-  public static boolean compare(double refTime, double total) {
-    return (refTime < total) && (!approximatelyEqual(refTime, total));
+    // result == -1, abs is less than tolerance.
+    // result == 0,  abs is equal to tolerance.
+    // result == 1,  abs is greater than tolerance.
+    return (result != 1);
   }
 
-  public static double checkRefTime(String refType) {
-    double refTime = getTimeValue(refType, 2);
-    double total = 0.0;
+  public static BigDecimal checkPhaseTime(String refType) {
+    BigDecimal phaseTime = getTimeValue(refType, 2);
+    BigDecimal sumOfSubPhasesTime = BigDecimal.valueOf(0.0);
 
     if (softReference.equals(refType)) {
-      total += getTimeValue(phase1, 4);
+      sumOfSubPhasesTime = sumOfSubPhasesTime.add(getTimeValue(phase1, 4));
     }
-    total += getTimeValue(phase2, 4);
-    total += getTimeValue(phase3, 4);
+    sumOfSubPhasesTime = sumOfSubPhasesTime.add(getTimeValue(phase2, 4));
+    sumOfSubPhasesTime = sumOfSubPhasesTime.add(getTimeValue(phase3, 4));
 
-    if (compare(refTime, total)) {
-      throw new RuntimeException(refType +" time(" + refTime +
-                                 "ms) is less than the sum(" + total + "ms) of each phases");
+    // If there are 3 sub-phases, we should allow 0.1 tolerance.
+    final BigDecimal toleranceFor3SubPhases = BigDecimal.valueOf(0.1);
+    if (!approximatelyEqual(phaseTime, sumOfSubPhasesTime, toleranceFor3SubPhases)) {
+      throw new RuntimeException(refType +" time(" + phaseTime +
+                                 "ms) is less than the sum(" + sumOfSubPhasesTime + "ms) of each phases");
     }
 
-    return refTime;
+    return phaseTime;
   }
 
-  // Find the first concurrent Reference Processing log and compare sub-time vs. total.
+  // Find the first concurrent Reference Processing log and compare phase time vs. sum of sub-phases.
   public static void checkLogValue(OutputAnalyzer out) {
     output = out.getStdout();
 
-    double refProcTime = getTimeValue(referenceProcessing, 0);
+    BigDecimal refProcTime = getTimeValue(referenceProcessing, 0);
 
-    double total = 0.0;
-    total += checkRefTime(softReference);
-    total += checkRefTime(weakReference);
-    total += checkRefTime(finalReference);
-    total += checkRefTime(phantomReference);
+    BigDecimal sumOfSubPhasesTime = checkPhaseTime(softReference);
+    sumOfSubPhasesTime = sumOfSubPhasesTime.add(checkPhaseTime(weakReference));
+    sumOfSubPhasesTime = sumOfSubPhasesTime.add(checkPhaseTime(finalReference));
+    sumOfSubPhasesTime = sumOfSubPhasesTime.add(checkPhaseTime(phantomReference));
 
-    if (compare(refProcTime, total)) {
+    // If there are 4 sub-phases, we should allow 0.2 tolerance.
+    final BigDecimal toleranceFor4SubPhases = BigDecimal.valueOf(0.2);
+    if (!approximatelyEqual(refProcTime, sumOfSubPhasesTime, toleranceFor4SubPhases)) {
       throw new RuntimeException("Reference Processing time(" + refProcTime + "ms) is less than the sum("
-                                 + total + "ms) of each phases");
+                                 + sumOfSubPhasesTime + "ms) of each phases");
     }
   }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/Metaspace/MaxMetaspaceSizeTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,47 @@
+/*
+ * 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.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+
+/*
+ * @test MaxMetaspaceSizeTest
+ * @requires vm.bits == "64"
+ * @bug 8087291
+ * @library /test/lib
+ * @run main/othervm MaxMetaspaceSizeTest
+ */
+
+public class MaxMetaspaceSizeTest {
+    public static void main(String... args) throws Exception {
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+            "-Xmx1g",
+            "-XX:InitialBootClassLoaderMetaspaceSize=4195328",
+            "-XX:MaxMetaspaceSize=4195328",
+            "-XX:+UseCompressedClassPointers",
+            "-XX:CompressedClassSpaceSize=1g",
+            "--version");
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        output.shouldContain("MaxMetaspaceSize is too small.");
+    }
+}
--- a/test/hotspot/jtreg/runtime/SharedArchiveFile/MaxMetaspaceSize.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/jtreg/runtime/SharedArchiveFile/MaxMetaspaceSize.java	Sat Oct 21 00:06:50 2017 +0000
@@ -31,14 +31,27 @@
  *          java.management
  */
 
+import java.util.ArrayList;
+
 import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.Platform;
 
 public class MaxMetaspaceSize {
   public static void main(String[] args) throws Exception {
+    ArrayList<String> processArgs = new ArrayList<>();
+    processArgs.add("-Xshare:dump");
+
+    if (Platform.is64bit()) {
+      processArgs.add("-XX:MaxMetaspaceSize=3m");
+      processArgs.add("-XX:CompressedClassSpaceSize=1m");
+      processArgs.add("-XX:InitialBootClassLoaderMetaspaceSize=1m");
+    } else {
+      processArgs.add("-XX:MaxMetaspaceSize=1m");
+    }
+
     String msg = "OutOfMemoryError: Metaspace";
-    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-        "-XX:MaxMetaspaceSize=1m", "-Xshare:dump");
+    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(processArgs.toArray(new String[0]));
     CDSTestUtils.executeAndLog(pb, "dump").shouldContain(msg).shouldHaveExitValue(1);
   }
 }
--- a/test/hotspot/jtreg/runtime/getSysPackage/GetSysPkgTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/hotspot/jtreg/runtime/getSysPackage/GetSysPkgTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -25,7 +25,7 @@
  * @test
  * @modules java.base/jdk.internal.misc
  * @modules java.base/jdk.internal.loader
- *          java.desktop
+ *          java.logging
  * @library /test/lib
  * @run main/othervm GetSysPkgTest
  */
@@ -134,10 +134,11 @@
         getPkg("GetSysPkg_package", null);
 
         // Access a class with a package in a boot loader module other than java.base
-        clss = Class.forName("java.awt.Button");
+        clss = Class.forName("java.util.logging.Level");
+
         if (clss == null)
-            throw new RuntimeException("Could not find class java.awt.Button");
-        getPkg("java/awt", "jrt:/java.desktop");
+            throw new RuntimeException("Could not find class java.util.logging.Level");
+        getPkg("java/util/logging", "jrt:/java.logging");
 
         // Test getting the package location from a class found via -Xbootclasspath/a
         clss = Class.forName("BootLdr_package.BootLdrPkg");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/jni/FindClass/BootLoaderTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,46 @@
+/*
+ * 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 java.lang.BootNativeLibrary;
+
+/*
+ * This is called from FindClassFromBoot class.
+ */
+public class BootLoaderTest {
+    public static void main(String... args) throws Exception {
+        testJNIFindClass("java/lang/String", String.class);
+        testJNIFindClass("java/lang/BootNativeLibrary", BootNativeLibrary.class);
+        testJNIFindClass("BootLoaderTest", null);
+    }
+
+    /*
+     * Call JNI FindClass with null loader as the context
+     */
+    static void testJNIFindClass(String name, Class<?> expected) {
+        Class<?> c = BootNativeLibrary.findClass(name);
+        if (c != expected) {
+            throw new RuntimeException("FindClass " + c + " expected: " + expected);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/jni/FindClass/FindClassFromBoot.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,50 @@
+/*
+ * 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 8189193
+ * @library /test/lib
+ * @build jdk.test.lib.process.ProcessTools
+ * @build java.base/java.lang.BootNativeLibrary BootLoaderTest FindClassFromBoot
+ * @run main/othervm/native -Xcheck:jni FindClassFromBoot
+ * @summary verify if the native library loaded by the boot loader
+ *          can only find classes visible to the boot loader
+ */
+
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import jdk.test.lib.process.ProcessTools;
+
+public class FindClassFromBoot {
+    public static void main(String... args) throws Exception {
+        Path patches = Paths.get(System.getProperty("test.classes"), "patches", "java.base");
+        String syspaths = System.getProperty("sun.boot.library.path") +
+                              File.pathSeparator + System.getProperty("java.library.path");
+        ProcessTools.executeTestJvm("-Dsun.boot.library.path=" + syspaths,
+                                    "--patch-module", "java.base=" + patches.toString(),
+                                    "BootLoaderTest")
+                    .shouldHaveExitValue(0);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/jni/FindClass/java.base/java/lang/BootNativeLibrary.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+package java.lang;
+
+public class BootNativeLibrary {
+    static {
+        System.loadLibrary("bootLoaderTest");
+    }
+
+    public static native Class<?> findClass(String name);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/jni/FindClass/libbootLoaderTest.c	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,49 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+
+#include "jni.h"
+#include "jni_util.h"
+
+JNIEXPORT jclass JNICALL
+Java_java_lang_BootNativeLibrary_findClass
+(JNIEnv *env, jclass cls, jstring name) {
+    jclass ncdfe;
+    jthrowable t;
+
+    const char* classname = (*env)->GetStringUTFChars(env, name, JNI_FALSE);
+    jclass c = (*env)->FindClass(env, classname);
+    (*env)->ReleaseStringUTFChars(env, name, classname);
+
+    if (c == NULL) {
+        // clear NCDFE
+        t = (*env)->ExceptionOccurred(env);
+        ncdfe = (*env)->FindClass(env, "java/lang/NoClassDefFoundError");
+        if (t != NULL && (*env)->IsInstanceOf(env, t, ncdfe)) {
+            (*env)->ExceptionClear(env);
+        }
+    }
+    return c;
+}
--- a/test/jdk/ProblemList.txt	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/ProblemList.txt	Sat Oct 21 00:06:50 2017 +0000
@@ -301,14 +301,6 @@
 
 com/sun/tools/attach/StartManagementAgent.java                  8179700 generic-all
 
-sun/tools/jhsdb/AlternateHashingTest.java                       8184042 macosx-all
-
-sun/tools/jhsdb/BasicLauncherTest.java                          8184042 macosx-all
-
-sun/tools/jhsdb/HeapDumpTest.java                               8184042 macosx-all
-
-sun/tools/jhsdb/heapconfig/JMapHeapConfigTest.java              8184042 macosx-all
-
 ############################################################################
 
 # jdk_other
--- a/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPSetAuthenticatorTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPSetAuthenticatorTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -147,11 +147,6 @@
             throw new AssertionError("Authenticator #2 called " + count(count)
                 + " expected it to be called " + expected(expectedIncrement));
         }
-        count = authTwo.count.get();
-        if (count != expectedIncrement) {
-            throw new AssertionError("Authenticator #2 called " + count(count)
-                + " expected it to be called " + expected(expectedIncrement));
-        }
 
         // Connect to the server with a GET request, then with a
         // POST that contains "Hello World!"
--- a/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTestServer.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTestServer.java	Sat Oct 21 00:06:50 2017 +0000
@@ -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
@@ -46,6 +46,7 @@
 import java.net.MalformedURLException;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.net.SocketAddress;
 import java.net.URL;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -148,62 +149,139 @@
     }
 
     /**
-     * The HttpServerFactory ensures that the local port used by an HttpServer
-     * previously created by the current test/VM will not get reused by
-     * a subsequent test in the same VM. This is to avoid having the
-     * AuthCache reuse credentials from previous tests - which would
-     * invalidate the assumptions made by the current test on when
-     * the default authenticator should be called.
+     * The SocketBindableFactory ensures that the local port used by an HttpServer
+     * or a proxy ServerSocket previously created by the current test/VM will not
+     * get reused by a subsequent test in the same VM. This is to avoid having the
+     * AuthCache reuse credentials from previous tests - which would invalidate the
+     * assumptions made by the current test on when the default authenticator should
+     * be called.
      */
-    private static final class HttpServerFactory {
+    private static abstract class SocketBindableFactory<B> {
         private static final int MAX = 10;
         private static final CopyOnWriteArrayList<String> addresses =
             new CopyOnWriteArrayList<>();
-        private static HttpServer newHttpServer(HttpProtocolType protocol)
-                throws IOException {
-            switch (protocol) {
-               case HTTP:  return HttpServer.create();
-               case HTTPS: return HttpsServer.create();
-               default: throw new InternalError("Unsupported protocol " + protocol);
-            }
-        }
-        static <T extends HttpServer> T create(HttpProtocolType protocol)
-                throws IOException {
+        protected B createInternal() throws IOException {
             final int max = addresses.size() + MAX;
-            final List<HttpServer> toClose = new ArrayList<>();
+            final List<B> toClose = new ArrayList<>();
             try {
                 for (int i = 1; i <= max; i++) {
-                    HttpServer server = newHttpServer(protocol);
-                    server.bind(new InetSocketAddress("127.0.0.1", 0), 0);
-                    InetSocketAddress address = server.getAddress();
+                    B bindable = createBindable();
+                    SocketAddress address = getAddress(bindable);
                     String key = address.toString();
                     if (addresses.addIfAbsent(key)) {
-                       System.out.println("Server bound to: " + key
+                       System.out.println("Socket bound to: " + key
                                           + " after " + i + " attempt(s)");
-                       return (T) server;
+                       return bindable;
                     }
                     System.out.println("warning: address " + key
                                        + " already used. Retrying bind.");
                     // keep the port bound until we get a port that we haven't
                     // used already
-                    toClose.add(server);
+                    toClose.add(bindable);
                 }
             } finally {
-                // if we had to retry, then close the servers we're not
+                // if we had to retry, then close the socket we're not
                 // going to use.
-                for (HttpServer s : toClose) {
-                  try { s.stop(1); } catch (Exception x) { /* ignore */ }
+                for (B b : toClose) {
+                  try { close(b); } catch (Exception x) { /* ignore */ }
                 }
             }
-            throw new IOException("Couldn't bind servers after " + max + " attempts: "
+            throw new IOException("Couldn't bind socket after " + max + " attempts: "
                                   + "addresses used before: " + addresses);
         }
+
+        protected abstract B createBindable() throws IOException;
+
+        protected abstract SocketAddress getAddress(B bindable);
+
+        protected abstract void close(B bindable) throws IOException;
+    }
+
+    /*
+     * Used to create ServerSocket for a proxy.
+     */
+    private static final class ServerSocketFactory
+            extends SocketBindableFactory<ServerSocket> {
+        private static final ServerSocketFactory instance = new ServerSocketFactory();
+
+        static ServerSocket create() throws IOException {
+            return instance.createInternal();
+        }
+
+        @Override
+        protected ServerSocket createBindable() throws IOException {
+            return new ServerSocket(0, 0, InetAddress.getByName("127.0.0.1"));
+        }
+
+        @Override
+        protected SocketAddress getAddress(ServerSocket socket) {
+            return socket.getLocalSocketAddress();
+        }
+
+        @Override
+        protected void close(ServerSocket socket) throws IOException {
+            socket.close();
+        }
+    }
+
+    /*
+     * Used to create HttpServer for a NTLMTestServer.
+     */
+    private static abstract class WebServerFactory<S extends HttpServer>
+            extends SocketBindableFactory<S> {
+        @Override
+        protected S createBindable() throws IOException {
+            S server = newHttpServer();
+            server.bind(new InetSocketAddress("127.0.0.1", 0), 0);
+            return server;
+        }
+
+        @Override
+        protected SocketAddress getAddress(S server) {
+            return server.getAddress();
+        }
+
+        @Override
+        protected void close(S server) throws IOException {
+            server.stop(1);
+        }
+
+        /*
+         * Returns a HttpServer or a HttpsServer in different subclasses.
+         */
+        protected abstract S newHttpServer() throws IOException;
+    }
+
+    private static final class HttpServerFactory extends WebServerFactory<HttpServer> {
+        private static final HttpServerFactory instance = new HttpServerFactory();
+
+        static HttpServer create() throws IOException {
+            return instance.createInternal();
+        }
+
+        @Override
+        protected HttpServer newHttpServer() throws IOException {
+            return HttpServer.create();
+        }
+    }
+
+    private static final class HttpsServerFactory extends WebServerFactory<HttpsServer> {
+        private static final HttpsServerFactory instance = new HttpsServerFactory();
+
+        static HttpsServer create() throws IOException {
+            return instance.createInternal();
+        }
+
+        @Override
+        protected HttpsServer newHttpServer() throws IOException {
+            return HttpsServer.create();
+        }
     }
 
     static HttpServer createHttpServer(HttpProtocolType protocol) throws IOException {
         switch (protocol) {
-            case HTTP:  return HttpServerFactory.create(protocol);
-            case HTTPS: return configure(HttpServerFactory.create(protocol));
+            case HTTP:  return HttpServerFactory.create();
+            case HTTPS: return configure(HttpsServerFactory.create());
             default: throw new InternalError("Unsupported protocol " + protocol);
         }
     }
@@ -894,7 +972,7 @@
             super(server, target, delegate);
             System.out.flush();
             System.err.println("WARNING: HttpsProxyTunnel is an experimental test class");
-            ss = new ServerSocket(0, 0, InetAddress.getByName("127.0.0.1"));
+            ss = ServerSocketFactory.create();
             start();
         }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/nio/channels/FileChannel/CleanerTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,87 @@
+/*
+ * 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 8147615
+ * @summary Test whether an unreferenced FileChannel is actually cleaned
+ * @requires (os.family == "linux") | (os.family == "mac") | (os.family == "solaris") | (os.family == "aix")
+ * @modules java.management
+ * @run main/othervm CleanerTest
+ */
+
+import com.sun.management.UnixOperatingSystemMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
+import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.nio.channels.FileChannel;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+
+public class CleanerTest {
+    public static void main(String[] args) throws Throwable {
+        OperatingSystemMXBean mxBean =
+            ManagementFactory.getOperatingSystemMXBean();
+        UnixOperatingSystemMXBean unixMxBean = null;
+        if (mxBean instanceof UnixOperatingSystemMXBean) {
+            unixMxBean = (UnixOperatingSystemMXBean)mxBean;
+        } else {
+            System.out.println("Non-Unix system: skipping test.");
+            return;
+        }
+
+        Path path = Paths.get(System.getProperty("test.dir", "."), "junk");
+        try {
+            FileChannel fc = FileChannel.open(path, StandardOpenOption.CREATE,
+                StandardOpenOption.READ, StandardOpenOption.WRITE);
+
+            ReferenceQueue refQueue = new ReferenceQueue();
+            Reference fcRef = new PhantomReference(fc, refQueue);
+
+            long fdCount0 = unixMxBean.getOpenFileDescriptorCount();
+            fc = null;
+
+            // Perform repeated GCs until the reference has been enqueued.
+            do {
+                Thread.sleep(1);
+                System.gc();
+            } while (refQueue.poll() == null);
+
+            // Loop until the open file descriptor count has been decremented.
+            while (unixMxBean.getOpenFileDescriptorCount() > fdCount0 - 1) {
+                Thread.sleep(1);
+            }
+
+            long fdCount = unixMxBean.getOpenFileDescriptorCount();
+            if (fdCount != fdCount0 - 1) {
+                throw new RuntimeException("FD count expected " +
+                    (fdCount0 - 1) + "; actual " + fdCount);
+            }
+        } finally {
+            Files.delete(path);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/ServiceLoader/CachingTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,187 @@
+/*
+ * 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
+ * @summary Test ServiceLoader caches
+ * @run testng CachingTest
+ */
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ServiceLoader;
+import java.util.ServiceLoader.Provider;
+import java.util.Spliterator;
+import java.util.stream.Collectors;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+public class CachingTest {
+
+    // service type
+    public static interface S { }
+
+    // service provider implementations
+    public static class S1 implements S { }
+
+    public static class S2 implements S { }
+
+    private ClassLoader testClassLoader;
+
+    // creates the services configuration file and sets the ClassLoader
+    @BeforeClass
+    void setup() throws Exception {
+        String classes = System.getProperty("test.classes");
+        Path dir = Paths.get(classes, "META-INF", "services");
+        Files.createDirectories(dir);
+        Path config = dir.resolve(S.class.getName());
+        Files.write(config, List.of(S1.class.getName(), S2.class.getName()));
+        this.testClassLoader = CachingTest.class.getClassLoader();
+    }
+
+    private void checkLists(List<?> list1, List<?> list2) {
+        assertTrue(list1.size() == 2);
+        assertTrue(list2.size() == 2);
+        Iterator<?> iterator1 = list1.iterator();
+        Iterator<?> iterator2 = list2.iterator();
+        while (iterator1.hasNext()) {
+            assertTrue(iterator1.next() == iterator2.next());
+        }
+    }
+
+    @Test
+    public void testIterator1() {
+        ServiceLoader<S> sl = ServiceLoader.load(S.class, testClassLoader);
+
+        List<S> list1 = new ArrayList<>();
+        List<S> list2 = new ArrayList<>();
+
+        // 1-1-2-2
+        sl.forEach(list1::add);
+        sl.forEach(list2::add);
+
+        checkLists(list1, list2);
+    }
+
+    // interleaved
+    @Test
+    public void testIterator2() {
+        ServiceLoader<S> sl = ServiceLoader.load(S.class, testClassLoader);
+
+        List<S> list1 = new ArrayList<>();
+        List<S> list2 = new ArrayList<>();
+
+        Iterator<S> iterator1 = sl.iterator();
+        Iterator<S> iterator2 = sl.iterator();
+
+        // 1-2-1-2
+        list1.add(iterator1.next());
+        list2.add(iterator2.next());
+        list1.add(iterator1.next());
+        list2.add(iterator2.next());
+
+        checkLists(list1, list2);
+    }
+
+    // interleaved
+    @Test
+    public void testIterator3() {
+        ServiceLoader<S> sl = ServiceLoader.load(S.class, testClassLoader);
+
+        List<S> list1 = new ArrayList<>();
+        List<S> list2 = new ArrayList<>();
+
+        Iterator<S> iterator1 = sl.iterator();
+        Iterator<S> iterator2 = sl.iterator();
+
+        // 1-2-2-1
+        list1.add(iterator1.next());
+        list2.add(iterator2.next());
+        list2.add(iterator2.next());
+        list1.add(iterator1.next());
+
+        checkLists(list1, list2);
+    }
+
+    @Test
+    public void testStream1() {
+        ServiceLoader<S> sl = ServiceLoader.load(S.class, testClassLoader);
+
+        // 1-1-2-2
+        List<Provider<S>> list1 = sl.stream().collect(Collectors.toList());
+        List<Provider<S>> list2 = sl.stream().collect(Collectors.toList());
+        checkLists(list1, list2);
+    }
+
+    // interleaved
+    @Test
+    public void testStream2() {
+        ServiceLoader<S> sl = ServiceLoader.load(S.class, testClassLoader);
+
+        List<Provider<S>> list1 = new ArrayList<>();
+        List<Provider<S>> list2 = new ArrayList<>();
+
+        Spliterator<Provider<S>> spliterator1 = sl.stream().spliterator();
+        Spliterator<Provider<S>> spliterator2 = sl.stream().spliterator();
+
+        // 1-2-1-2
+        spliterator1.tryAdvance(list1::add);
+        spliterator2.tryAdvance(list2::add);
+        spliterator1.tryAdvance(list1::add);
+        spliterator2.tryAdvance(list2::add);
+
+        assertFalse(spliterator1.tryAdvance(e -> assertTrue(false)));
+        assertFalse(spliterator2.tryAdvance(e -> assertTrue(false)));
+
+        checkLists(list1, list2);
+    }
+
+    // interleaved
+    @Test
+    public void testStream3() {
+        ServiceLoader<S> sl = ServiceLoader.load(S.class, testClassLoader);
+
+        List<Provider<S>> list1 = new ArrayList<>();
+        List<Provider<S>> list2 = new ArrayList<>();
+
+        Spliterator<Provider<S>> spliterator1 = sl.stream().spliterator();
+        Spliterator<Provider<S>> spliterator2 = sl.stream().spliterator();
+
+        // 1-2-2-1
+        spliterator1.tryAdvance(list1::add);
+        spliterator2.tryAdvance(list2::add);
+        spliterator2.tryAdvance(list2::add);
+        spliterator1.tryAdvance(list1::add);
+
+        assertFalse(spliterator1.tryAdvance(e -> assertTrue(false)));
+        assertFalse(spliterator2.tryAdvance(e -> assertTrue(false)));
+
+        checkLists(list1, list2);
+    }
+}
--- a/test/jdk/java/util/ServiceLoader/security/test/module-info.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/java/util/ServiceLoader/security/test/module-info.java	Sat Oct 21 00:06:50 2017 +0000
@@ -26,8 +26,16 @@
 module test {
     uses S1;
     uses S2;
+    uses S3;
+    uses S4;
+    uses S5;
+    uses S6;
     provides S1 with P1;
     provides S2 with P2;
+    provides S3 with P3;
+    provides S4 with P4;
+    provides S5 with P5;
+    provides S6 with P6;
     requires testng;
     exports p to testng;
 }
--- a/test/jdk/java/util/ServiceLoader/security/test/p/Tests.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/java/util/ServiceLoader/security/test/p/Tests.java	Sat Oct 21 00:06:50 2017 +0000
@@ -38,14 +38,16 @@
 import java.util.ServiceLoader.Provider;
 import static java.security.AccessController.doPrivileged;
 
+import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 import org.testng.annotations.BeforeTest;
 import static org.testng.Assert.*;
 
 /**
- * Basic tests with a security manager to ensure that the provider code
- * is run with permissions restricted by whatever created the ServiceLoader
- * object.
+ * Tests ServiceLoader when running with a security manager, specifically
+ * tests to ensure that provider code is run with permissions restricted by
+ * the creater of ServiceLoader, and also testing of exceptions thrown
+ * when loading or initializing a provider.
  */
 
 public class Tests {
@@ -163,11 +165,35 @@
         }
     }
 
+    @DataProvider(name = "failingServices")
+    public Object[][] failingServices() {
+        return new Object[][] {
+            { S3.class,    P3.Error3.class },
+            { S4.class,    P4.Error4.class },
+            { S5.class,    P5.Error5.class },
+            { S6.class,    P6.Error6.class },
+        };
+    }
+
+    @Test(dataProvider = "failingServices")
+    public void testFailingService(Class<?> service, Class<? extends Error> errorClass) {
+        ServiceLoader<?> sl = ServiceLoader.load(service);
+        try {
+            sl.iterator().next();
+            assertTrue(false);
+        } catch (ServiceConfigurationError e) {
+            assertTrue(e.getCause().getClass() == errorClass);
+        }
+    }
 
     // service types and implementations
 
     public static interface S1 { }
     public static interface S2 { }
+    public static interface S3 { }
+    public static interface S4 { }
+    public static interface S5 { }
+    public static interface S6 { }
 
     public static class P1 implements S1 {
         public P1() {
@@ -182,4 +208,36 @@
             return new P2();
         }
     }
+
+    public static class P3 implements S3 {
+        static class Error3 extends Error { }
+        static {
+            if (1==1) throw new Error3();  // fail
+        }
+        public P3() { }
+    }
+
+    public static class P4 implements S4 {
+        static class Error4 extends Error { }
+        static {
+            if (1==1) throw new Error4();  // fail
+        }
+        public static S4 provider() {
+            return new P4();
+        }
+    }
+
+    public static class P5 implements S5 {
+        static class Error5 extends Error { }
+        public P5() {
+            throw new Error5();  // fail
+        }
+    }
+
+    public static class P6 implements S6 {
+        static class Error6 extends Error { }
+        public static S6 provider() {
+            throw new Error6();   // fail
+        }
+    }
 }
--- a/test/jdk/java/util/concurrent/ConcurrentQueues/GCRetention.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/java/util/concurrent/ConcurrentQueues/GCRetention.java	Sat Oct 21 00:06:50 2017 +0000
@@ -35,7 +35,7 @@
  * @bug 6785442
  * @summary Benchmark that tries to GC-tenure head, followed by
  * many add/remove operations.
- * @run main GCRetention 12345
+ * @run main GCRetention just-testing
  */
 
 import static java.util.concurrent.TimeUnit.SECONDS;
@@ -60,8 +60,8 @@
 import java.util.Map;
 
 public class GCRetention {
-    // Suitable for benchmarking.  Overridden by args[0] for testing.
-    int count = 1024 * 1024;
+    boolean benchmarkMode;
+    int count;
 
     /** No guarantees, but effective in practice. */
     static void forceFullGc() {
@@ -124,8 +124,9 @@
     }
 
     void test(String[] args) {
-        if (args.length > 0)
-            count = Integer.valueOf(args[0]);
+        benchmarkMode = ! (args.length > 0 && args[0].equals("just-testing"));
+        count = benchmarkMode ? 1024 * 1024 : 30;
+
         // Warmup
         for (Queue<Boolean> queue : queues())
             test(queue);
@@ -140,7 +141,7 @@
         long t0 = System.nanoTime();
         for (int i = 0; i < count; i++)
             check(q.add(Boolean.TRUE));
-        forceFullGc();
+        if (benchmarkMode) forceFullGc();
         // forceFullGc();
         Boolean x;
         while ((x = q.poll()) != null)
--- a/test/jdk/java/util/concurrent/ExecutorService/Invoke.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/java/util/concurrent/ExecutorService/Invoke.java	Sat Oct 21 00:06:50 2017 +0000
@@ -28,12 +28,18 @@
  * @author  Martin Buchholz
  */
 
-import java.util.Arrays;
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
 import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 import java.util.concurrent.Callable;
+import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
+import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.atomic.AtomicLong;
 
 public class Invoke {
@@ -61,36 +67,162 @@
         check(condition, "Assertion failure");
     }
 
+    static long secondsElapsedSince(long startTime) {
+        return NANOSECONDS.toSeconds(System.nanoTime() - startTime);
+    }
+
+    static void awaitInterrupt(long timeoutSeconds) {
+        long startTime = System.nanoTime();
+        try {
+            Thread.sleep(SECONDS.toMillis(timeoutSeconds));
+            fail("timed out waiting for interrupt");
+        } catch (InterruptedException expected) {
+            check(secondsElapsedSince(startTime) < timeoutSeconds);
+        }
+    }
+
     public static void main(String[] args) {
         try {
-            final AtomicLong count = new AtomicLong(0);
-            ExecutorService fixed = Executors.newFixedThreadPool(5);
-            class Inc implements Callable<Long> {
-                public Long call() throws Exception {
-                    Thread.sleep(200); // Catch IE from possible cancel
-                    return count.incrementAndGet();
-                }
+            testInvokeAll();
+            testInvokeAny();
+            testInvokeAny_cancellationInterrupt();
+        } catch (Throwable t) {  unexpected(t); }
+
+        if (failed > 0)
+            throw new Error(
+                    String.format("Passed = %d, failed = %d", passed, failed));
+    }
+
+    static final long timeoutSeconds = 10L;
+
+    static void testInvokeAll() throws Throwable {
+        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
+        final int nThreads = rnd.nextInt(2, 7);
+        final boolean timed = rnd.nextBoolean();
+        final ExecutorService pool = Executors.newFixedThreadPool(nThreads);
+        final AtomicLong count = new AtomicLong(0);
+        class Task implements Callable<Long> {
+            public Long call() throws Exception {
+                return count.incrementAndGet();
             }
-            List<Inc> tasks = Arrays.asList(new Inc(), new Inc(), new Inc());
-            List<Future<Long>> futures = fixed.invokeAll(tasks);
+        }
+
+        try {
+            final List<Task> tasks =
+                IntStream.range(0, nThreads)
+                .mapToObj(i -> new Task())
+                .collect(Collectors.toList());
+
+            List<Future<Long>> futures;
+            if (timed) {
+                long startTime = System.nanoTime();
+                futures = pool.invokeAll(tasks, timeoutSeconds, SECONDS);
+                check(secondsElapsedSince(startTime) < timeoutSeconds);
+            }
+            else
+                futures = pool.invokeAll(tasks);
             check(futures.size() == tasks.size());
             check(count.get() == tasks.size());
 
             long gauss = 0;
             for (Future<Long> future : futures) gauss += future.get();
-            check(gauss == ((tasks.size()+1)*tasks.size())/2);
+            check(gauss == (tasks.size()+1)*tasks.size()/2);
+
+            pool.shutdown();
+            check(pool.awaitTermination(10L, SECONDS));
+        } finally {
+            pool.shutdownNow();
+        }
+    }
 
-            ExecutorService single = Executors.newSingleThreadExecutor();
-            long save = count.get();
-            check(single.invokeAny(tasks) == save + 1);
-            check(count.get() == save + 1);
+    static void testInvokeAny() throws Throwable {
+        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
+        final boolean timed = rnd.nextBoolean();
+        final ExecutorService pool = Executors.newSingleThreadExecutor();
+        final AtomicLong count = new AtomicLong(0);
+        class Task implements Callable<Long> {
+            public Long call() throws Exception {
+                long x = count.incrementAndGet();
+                check(x <= 2);
+                if (x == 2)
+                    // wait for main thread to interrupt us
+                    awaitInterrupt(timeoutSeconds);
+                return x;
+            }
+        }
+
+        try {
+            final List<Task> tasks =
+                IntStream.range(0, rnd.nextInt(1, 7))
+                .mapToObj(i -> new Task())
+                .collect(Collectors.toList());
+
+            long val;
+            if (timed) {
+                long startTime = System.nanoTime();
+                val = pool.invokeAny(tasks, timeoutSeconds, SECONDS);
+                check(secondsElapsedSince(startTime) < timeoutSeconds);
+            }
+            else
+                val = pool.invokeAny(tasks);
+            check(val == 1);
+
+            // inherent race between main thread interrupt and
+            // start of second task
+            check(count.get() == 1 || count.get() == 2);
 
-            fixed.shutdown();
-            single.shutdown();
+            pool.shutdown();
+            check(pool.awaitTermination(timeoutSeconds, SECONDS));
+        } finally {
+            pool.shutdownNow();
+        }
+    }
 
-        } catch (Throwable t) { unexpected(t); }
+    /**
+     * Every remaining running task is sent an interrupt for cancellation.
+     */
+    static void testInvokeAny_cancellationInterrupt() throws Throwable {
+        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
+        final int nThreads = rnd.nextInt(2, 7);
+        final boolean timed = rnd.nextBoolean();
+        final ExecutorService pool = Executors.newFixedThreadPool(nThreads);
+        final AtomicLong count = new AtomicLong(0);
+        final AtomicLong interruptedCount = new AtomicLong(0);
+        final CyclicBarrier allStarted = new CyclicBarrier(nThreads);
+        class Task implements Callable<Long> {
+            public Long call() throws Exception {
+                allStarted.await();
+                long x = count.incrementAndGet();
+                if (x > 1)
+                    // main thread will interrupt us
+                    awaitInterrupt(timeoutSeconds);
+                return x;
+            }
+        }
 
-        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
-        if (failed > 0) throw new Error("Some tests failed");
+        try {
+            final List<Task> tasks =
+                IntStream.range(0, nThreads)
+                .mapToObj(i -> new Task())
+                .collect(Collectors.toList());
+
+            long val;
+            if (timed) {
+                long startTime = System.nanoTime();
+                val = pool.invokeAny(tasks, timeoutSeconds, SECONDS);
+                check(secondsElapsedSince(startTime) < timeoutSeconds);
+            }
+            else
+                val = pool.invokeAny(tasks);
+            check(val == 1);
+
+            pool.shutdown();
+            check(pool.awaitTermination(timeoutSeconds, SECONDS));
+
+            // Check after shutdown to avoid race
+            check(count.get() == nThreads);
+        } finally {
+            pool.shutdownNow();
+        }
     }
 }
--- a/test/jdk/java/util/concurrent/tck/ConcurrentLinkedDequeTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/java/util/concurrent/tck/ConcurrentLinkedDequeTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -40,7 +40,10 @@
 import java.util.NoSuchElementException;
 import java.util.Queue;
 import java.util.Random;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.LongAdder;
 
 import junit.framework.Test;
 
@@ -932,4 +935,78 @@
             } catch (NullPointerException success) {}
         }
     }
+
+    /**
+     * Non-traversing Deque operations are linearizable.
+     * https://bugs.openjdk.java.net/browse/JDK-8188900
+     * ant -Djsr166.expensiveTests=true -Djsr166.tckTestClass=ConcurrentLinkedDequeTest -Djsr166.methodFilter=testBug8188900 tck
+     */
+    public void testBug8188900() {
+        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
+        final LongAdder nulls = new LongAdder(), zeros = new LongAdder();
+        for (int n = expensiveTests ? 100_000 : 10; n--> 0; ) {
+            ConcurrentLinkedDeque<Integer> d = new ConcurrentLinkedDeque<>();
+
+            boolean peek = rnd.nextBoolean();
+            Runnable getter = () -> {
+                Integer x = peek ? d.peekFirst() : d.pollFirst();
+                if (x == null) nulls.increment();
+                else if (x == 0) zeros.increment();
+                else
+                    throw new AssertionError(
+                        String.format(
+                            "unexpected value %d after %d nulls and %d zeros",
+                            x, nulls.sum(), zeros.sum()));
+            };
+
+            Runnable adder = () -> {
+                d.addFirst(0);
+                d.addLast(42);
+            };
+
+            boolean b = rnd.nextBoolean();
+            Runnable r1 = b ? getter : adder;
+            Runnable r2 = b ? adder : getter;
+            CompletableFuture<Void> f1 = CompletableFuture.runAsync(r1);
+            CompletableFuture<Void> f2 = CompletableFuture.runAsync(r2);
+            f1.join();
+            f2.join();
+        }
+    }
+
+    /**
+     * Reverse direction variant of testBug8188900
+     */
+    public void testBug8188900_reverse() {
+        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
+        final LongAdder nulls = new LongAdder(), zeros = new LongAdder();
+        for (int n = expensiveTests ? 100_000 : 10; n--> 0; ) {
+            ConcurrentLinkedDeque<Integer> d = new ConcurrentLinkedDeque<>();
+
+            boolean peek = rnd.nextBoolean();
+            Runnable getter = () -> {
+                Integer x = peek ? d.peekLast() : d.pollLast();
+                if (x == null) nulls.increment();
+                else if (x == 0) zeros.increment();
+                else
+                    throw new AssertionError(
+                        String.format(
+                            "unexpected value %d after %d nulls and %d zeros",
+                            x, nulls.sum(), zeros.sum()));
+            };
+
+            Runnable adder = () -> {
+                d.addLast(0);
+                d.addFirst(42);
+            };
+
+            boolean b = rnd.nextBoolean();
+            Runnable r1 = b ? getter : adder;
+            Runnable r2 = b ? adder : getter;
+            CompletableFuture<Void> f1 = CompletableFuture.runAsync(r1);
+            CompletableFuture<Void> f2 = CompletableFuture.runAsync(r2);
+            f1.join();
+            f2.join();
+        }
+    }
 }
--- a/test/jdk/java/util/concurrent/tck/SplittableRandomTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/java/util/concurrent/tck/SplittableRandomTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -31,9 +31,14 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
+import java.util.Arrays;
+import java.util.List;
 import java.util.SplittableRandom;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.LongAdder;
+import java.lang.reflect.Method;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -552,4 +557,64 @@
         assertEquals(size, counter.sum());
     }
 
+    /**
+     * SplittableRandom should implement most of Random's public methods
+     */
+    public void testShouldImplementMostRandomMethods() throws Throwable {
+        Predicate<Method> wasForgotten = method -> {
+            String name = method.getName();
+            // some methods deliberately not implemented
+            if (name.equals("setSeed")) return false;
+            if (name.equals("nextFloat")) return false;
+            if (name.equals("nextGaussian")) return false;
+            try {
+                SplittableRandom.class.getMethod(
+                    method.getName(), method.getParameterTypes());
+            } catch (ReflectiveOperationException ex) {
+                return true;
+            }
+            return false;
+        };
+        List<Method> forgotten =
+            Arrays.stream(java.util.Random.class.getMethods())
+            .filter(wasForgotten)
+            .collect(Collectors.toList());
+        if (!forgotten.isEmpty())
+            throw new AssertionError("Please implement: " + forgotten);
+    }
+
+    /**
+     * Repeated calls to nextBytes produce at least values of different signs for every byte
+     */
+    public void testNextBytes() {
+        SplittableRandom sr = new SplittableRandom();
+        int n = sr.nextInt(1, 20);
+        byte[] bytes = new byte[n];
+        outer:
+        for (int i = 0; i < n; i++) {
+            for (int tries = NCALLS; tries-->0; ) {
+                byte before = bytes[i];
+                sr.nextBytes(bytes);
+                byte after = bytes[i];
+                if (after * before < 0)
+                    continue outer;
+            }
+            fail("not enough variation in random bytes");
+        }
+    }
+
+    /**
+     * Filling an empty array with random bytes succeeds without effect.
+     */
+    public void testNextBytes_emptyArray() {
+        new SplittableRandom().nextBytes(new byte[0]);
+    }
+
+    public void testNextBytes_nullArray() {
+        try {
+            new SplittableRandom().nextBytes(null);
+            shouldThrow();
+        } catch (NullPointerException success) {}
+    }
+
 }
--- a/test/jdk/java/util/concurrent/tck/StampedLockTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/java/util/concurrent/tck/StampedLockTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -35,6 +35,11 @@
 import static java.util.concurrent.TimeUnit.DAYS;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
+import static java.util.concurrent.locks.StampedLock.isLockStamp;
+import static java.util.concurrent.locks.StampedLock.isOptimisticReadStamp;
+import static java.util.concurrent.locks.StampedLock.isReadLockStamp;
+import static java.util.concurrent.locks.StampedLock.isWriteLockStamp;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
@@ -1286,11 +1291,115 @@
                 } while (stamp == 0);
                 return Math.hypot(currentX, currentY);
             }
+
+            double distanceFromOrigin2() {
+                long stamp = sl.tryOptimisticRead();
+                try {
+                    retryHoldingLock:
+                    for (;; stamp = sl.readLock()) {
+                        if (stamp == 0L)
+                            continue retryHoldingLock;
+                        // possibly racy reads
+                        double currentX = x;
+                        double currentY = y;
+                        if (!sl.validate(stamp))
+                            continue retryHoldingLock;
+                        return Math.hypot(currentX, currentY);
+                    }
+                } finally {
+                    if (StampedLock.isReadLockStamp(stamp))
+                        sl.unlockRead(stamp);
+                }
+            }
+
+            void moveIfAtOrigin(double newX, double newY) {
+                long stamp = sl.readLock();
+                try {
+                    while (x == 0.0 && y == 0.0) {
+                        long ws = sl.tryConvertToWriteLock(stamp);
+                        if (ws != 0L) {
+                            stamp = ws;
+                            x = newX;
+                            y = newY;
+                            return;
+                        }
+                        else {
+                            sl.unlockRead(stamp);
+                            stamp = sl.writeLock();
+                        }
+                    }
+                } finally {
+                    sl.unlock(stamp);
+                }
+            }
         }
 
         Point p = new Point();
         p.move(3.0, 4.0);
         assertEquals(5.0, p.distanceFromOrigin());
+        p.moveIfAtOrigin(5.0, 12.0);
+        assertEquals(5.0, p.distanceFromOrigin2());
+    }
+
+    /**
+     * Stamp inspection methods work as expected, and do not inspect
+     * the state of the lock itself.
+     */
+    public void testStampStateInspectionMethods() {
+        StampedLock lock = new StampedLock();
+
+        assertFalse(isWriteLockStamp(0L));
+        assertFalse(isReadLockStamp(0L));
+        assertFalse(isLockStamp(0L));
+        assertFalse(isOptimisticReadStamp(0L));
+
+        {
+            long stamp = lock.writeLock();
+            for (int i = 0; i < 2; i++) {
+                assertTrue(isWriteLockStamp(stamp));
+                assertFalse(isReadLockStamp(stamp));
+                assertTrue(isLockStamp(stamp));
+                assertFalse(isOptimisticReadStamp(stamp));
+                if (i == 0)
+                    lock.unlockWrite(stamp);
+            }
+        }
+
+        {
+            long stamp = lock.readLock();
+            for (int i = 0; i < 2; i++) {
+                assertFalse(isWriteLockStamp(stamp));
+                assertTrue(isReadLockStamp(stamp));
+                assertTrue(isLockStamp(stamp));
+                assertFalse(isOptimisticReadStamp(stamp));
+                if (i == 0)
+                    lock.unlockRead(stamp);
+            }
+        }
+
+        {
+            long optimisticStamp = lock.tryOptimisticRead();
+            long readStamp = lock.tryConvertToReadLock(optimisticStamp);
+            long writeStamp = lock.tryConvertToWriteLock(readStamp);
+            for (int i = 0; i < 2; i++) {
+                assertFalse(isWriteLockStamp(optimisticStamp));
+                assertFalse(isReadLockStamp(optimisticStamp));
+                assertFalse(isLockStamp(optimisticStamp));
+                assertTrue(isOptimisticReadStamp(optimisticStamp));
+
+                assertFalse(isWriteLockStamp(readStamp));
+                assertTrue(isReadLockStamp(readStamp));
+                assertTrue(isLockStamp(readStamp));
+                assertFalse(isOptimisticReadStamp(readStamp));
+
+                assertTrue(isWriteLockStamp(writeStamp));
+                assertFalse(isReadLockStamp(writeStamp));
+                assertTrue(isLockStamp(writeStamp));
+                assertFalse(isOptimisticReadStamp(writeStamp));
+                if (i == 0)
+                    lock.unlockWrite(writeStamp);
+            }
+        }
     }
 
 }
--- a/test/jdk/java/util/concurrent/tck/ThreadLocalRandomTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/java/util/concurrent/tck/ThreadLocalRandomTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -412,4 +412,38 @@
         fail("all threads generate the same pseudo-random sequence");
     }
 
+    /**
+     * Repeated calls to nextBytes produce at least values of different signs for every byte
+     */
+    public void testNextBytes() {
+        ThreadLocalRandom rnd = ThreadLocalRandom.current();
+        int n = rnd.nextInt(1, 20);
+        byte[] bytes = new byte[n];
+        outer:
+        for (int i = 0; i < n; i++) {
+            for (int tries = NCALLS; tries-->0; ) {
+                byte before = bytes[i];
+                rnd.nextBytes(bytes);
+                byte after = bytes[i];
+                if (after * before < 0)
+                    continue outer;
+            }
+            fail("not enough variation in random bytes");
+        }
+    }
+
+    /**
+     * Filling an empty array with random bytes succeeds without effect.
+     */
+    public void testNextBytes_emptyArray() {
+        ThreadLocalRandom.current().nextBytes(new byte[0]);
+    }
+
+    public void testNextBytes_nullArray() {
+        try {
+            ThreadLocalRandom.current().nextBytes(null);
+            shouldThrow();
+        } catch (NullPointerException success) {}
+    }
+
 }
--- a/test/jdk/java/util/zip/ZipFile/ZeroDate.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/java/util/zip/ZipFile/ZeroDate.java	Sat Oct 21 00:06:50 2017 +0000
@@ -34,14 +34,16 @@
 import java.nio.file.Path;
 import java.time.Instant;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 import java.util.zip.ZipOutputStream;
 
 /* @test
- * @bug 8184940
+ * @bug 8184940 8188869
  * @summary JDK 9 rejects zip files where the modified day or month is 0
+ *          or otherwise represent an invalid date, such as 1980-02-30 24:60:60
  * @author Liam Miller-Cushon
  */
 public class ZeroDate {
@@ -63,12 +65,19 @@
         Files.delete(path);
 
         // year, month, day are zero
-        testDate(data.clone(), 0, LocalDate.of(1979, 11, 30));
+        testDate(data.clone(), 0, LocalDate.of(1979, 11, 30).atStartOfDay());
         // only year is zero
-        testDate(data.clone(), 0 << 25 | 4 << 21 | 5 << 16, LocalDate.of(1980, 4, 5));
+        testDate(data.clone(), 0 << 25 | 4 << 21 | 5 << 16, LocalDate.of(1980, 4, 5).atStartOfDay());
+        // month is greater than 12
+        testDate(data.clone(), 0 << 25 | 13 << 21 | 1 << 16, LocalDate.of(1981, 1, 1).atStartOfDay());
+        // 30th of February
+        testDate(data.clone(), 0 << 25 | 2 << 21 | 30 << 16, LocalDate.of(1980, 3, 1).atStartOfDay());
+        // 30th of February, 24:60:60
+        testDate(data.clone(), 0 << 25 | 2 << 21 | 30 << 16 | 24 << 11 | 60 << 5 | 60 >> 1,
+                LocalDateTime.of(1980, 3, 2, 1, 1, 0));
     }
 
-    private static void testDate(byte[] data, int date, LocalDate expected) throws IOException {
+    private static void testDate(byte[] data, int date, LocalDateTime expected) throws IOException {
         // set the datetime
         int endpos = data.length - ENDHDR;
         int cenpos = u16(data, endpos + ENDOFF);
@@ -84,8 +93,7 @@
         try (ZipFile zf = new ZipFile(path.toFile())) {
             ZipEntry ze = zf.entries().nextElement();
             Instant actualInstant = ze.getLastModifiedTime().toInstant();
-            Instant expectedInstant =
-                    expected.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
+            Instant expectedInstant = expected.atZone(ZoneId.systemDefault()).toInstant();
             if (!actualInstant.equals(expectedInstant)) {
                 throw new AssertionError(
                         String.format("actual: %s, expected: %s", actualInstant, expectedInstant));
--- a/test/jdk/jdk/nio/zipfs/ZeroDate.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/jdk/jdk/nio/zipfs/ZeroDate.java	Sat Oct 21 00:06:50 2017 +0000
@@ -38,14 +38,16 @@
 import java.nio.file.attribute.BasicFileAttributes;
 import java.time.Instant;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.util.Collections;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
 /* @test
- * @bug 8184940 8186227
+ * @bug 8184940 8186227 8188869
  * @summary JDK 9 rejects zip files where the modified day or month is 0
+ *          or otherwise represent an invalid date, such as 1980-02-30 24:60:60
  * @author Liam Miller-Cushon
  */
 public class ZeroDate {
@@ -67,12 +69,19 @@
         Files.delete(path);
 
         // year, month, day are zero
-        testDate(data.clone(), 0, LocalDate.of(1979, 11, 30));
+        testDate(data.clone(), 0, LocalDate.of(1979, 11, 30).atStartOfDay());
         // only year is zero
-        testDate(data.clone(), 0 << 25 | 4 << 21 | 5 << 16, LocalDate.of(1980, 4, 5));
+        testDate(data.clone(), 0 << 25 | 4 << 21 | 5 << 16, LocalDate.of(1980, 4, 5).atStartOfDay());
+        // month is greater than 12
+        testDate(data.clone(), 0 << 25 | 13 << 21 | 1 << 16, LocalDate.of(1981, 1, 1).atStartOfDay());
+        // 30th of February
+        testDate(data.clone(), 0 << 25 | 2 << 21 | 30 << 16, LocalDate.of(1980, 3, 1).atStartOfDay());
+        // 30th of February, 24:60:60
+        testDate(data.clone(), 0 << 25 | 2 << 21 | 30 << 16 | 24 << 11 | 60 << 5 | 60 >> 1,
+                LocalDateTime.of(1980, 3, 2, 1, 1, 0));
     }
 
-    private static void testDate(byte[] data, int date, LocalDate expected) throws IOException {
+    private static void testDate(byte[] data, int date, LocalDateTime expected) throws IOException {
         // set the datetime
         int endpos = data.length - ENDHDR;
         int cenpos = u16(data, endpos + ENDOFF);
@@ -93,7 +102,7 @@
                             .lastModifiedTime()
                             .toInstant();
             Instant expectedInstant =
-                    expected.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
+                    expected.atZone(ZoneId.systemDefault()).toInstant();
             if (!actualInstant.equals(expectedInstant)) {
                 throw new AssertionError(
                         String.format("actual: %s, expected: %s", actualInstant, expectedInstant));
--- a/test/langtools/jdk/javadoc/doclet/lib/JavadocTester.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/langtools/jdk/javadoc/doclet/lib/JavadocTester.java	Sat Oct 21 00:06:50 2017 +0000
@@ -37,6 +37,8 @@
 import java.lang.ref.SoftReference;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.nio.charset.Charset;
+import java.nio.charset.UnsupportedCharsetException;
 import java.nio.file.Files;
 import java.util.Arrays;
 import java.util.ArrayList;
@@ -46,6 +48,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.function.Function;
 
 
@@ -150,6 +153,9 @@
     /** The output directory used in the most recent call of javadoc. */
     protected File outputDir;
 
+    /** The output charset used in the most recent call of javadoc. */
+    protected Charset charset = Charset.defaultCharset();
+
     /** The exit code of the most recent call of javadoc. */
     private int exitCode;
 
@@ -158,6 +164,8 @@
 
     /** A cache of file content, to avoid reading files unnecessarily. */
     private final Map<File,SoftReference<String>> fileContentCache = new HashMap<>();
+    /** The charset used for files in the fileContentCache. */
+    private Charset fileContentCacheCharset = null;
 
     /** Stream used for logging messages. */
     protected final PrintStream out = System.out;
@@ -293,13 +301,46 @@
             out.println("Running javadoc (run "
                                     + javadocRunNum + ")...");
         }
+
         outputDir = new File(".");
+        String charsetArg = null;
+        String docencodingArg = null;
+        String encodingArg = null;
         for (int i = 0; i < args.length - 2; i++) {
-            if (args[i].equals("-d")) {
-                outputDir = new File(args[++i]);
-                break;
+            switch (args[i]) {
+                case "-d":
+                    outputDir = new File(args[++i]);
+                    break;
+                case "-charset":
+                    charsetArg = args[++i];
+                    break;
+                case "-docencoding":
+                    docencodingArg = args[++i];
+                    break;
+                case "-encoding":
+                    encodingArg = args[++i];
+                    break;
             }
         }
+
+        // The following replicates HtmlConfiguration.finishOptionSettings0
+        // and sets up the charset used to read files.
+        String cs;
+        if (docencodingArg == null) {
+            if (charsetArg == null) {
+                cs = (encodingArg == null) ? "UTF-8" : encodingArg;
+            } else {
+                cs = charsetArg;
+            }
+        } else {
+           cs = docencodingArg;
+        }
+        try {
+            charset = Charset.forName(cs);
+        } catch (UnsupportedCharsetException e) {
+            charset = Charset.defaultCharset();
+        }
+
         out.println("args: " + Arrays.toString(args));
 //        log.setOutDir(outputDir);
 
@@ -637,6 +678,10 @@
      * @return          the file in string format
      */
     private String readFile(File baseDir, String fileName) throws Error {
+        if (!Objects.equals(fileContentCacheCharset, charset)) {
+            fileContentCache.clear();
+            fileContentCacheCharset = charset;
+        }
         try {
             File file = new File(baseDir, fileName);
             SoftReference<String> ref = fileContentCache.get(file);
@@ -644,7 +689,8 @@
             if (content != null)
                 return content;
 
-            content = new String(Files.readAllBytes(file.toPath()));
+            // charset defaults to a value inferred from latest javadoc run
+            content = new String(Files.readAllBytes(file.toPath()), charset);
             fileContentCache.put(file, new SoftReference<>(content));
             return content;
         } catch (FileNotFoundException e) {
--- a/test/langtools/jdk/javadoc/doclet/testAnchorNames/TestAnchorNames.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/langtools/jdk/javadoc/doclet/testAnchorNames/TestAnchorNames.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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,29 +23,37 @@
 
 /*
  * @test
- * @bug 8025633 8025524 8081854
+ * @bug 8025633 8025524 8081854 8187521
  * @summary Test for valid name attribute in HTML anchors.
  * @author Bhavesh Patel
- * @library ../lib
+ * @library /tools/lib ../lib
  * @modules jdk.javadoc/jdk.javadoc.internal.tool
- * @build JavadocTester
+ * @build toolbox.ToolBox JavadocTester
  * @run main TestAnchorNames
  */
 
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import toolbox.*;
+
 public class TestAnchorNames extends JavadocTester {
 
-    private static final String[] ARGS = new String[] {
-
-    };
+    public final ToolBox tb;
+    public static void main(String... args) throws Exception {
+        TestAnchorNames tester = new TestAnchorNames();
+        tester.runTests(m -> new Object[] { Paths.get(m.getName()) });
+    }
 
-    public static void main(String[] args) throws Exception {
-        TestAnchorNames tester = new TestAnchorNames();
-        tester.runTests();
+    public TestAnchorNames() {
+        tb = new ToolBox();
     }
 
     @Test
-    void test() {
-        javadoc("-d", "out",
+    void testHtml4(Path ignore) {
+        javadoc("-d", "out-html4",
                 "-sourcepath", testSrc,
                 "-source", "8", //so that '_' can be used as an identifier
                 "-use",
@@ -153,11 +161,169 @@
                 "<a href=\"#I:Z:Z_\">_");
 
         // The marker name conversion should only affect HTML anchors. It should not
-        // affect the lables.
+        // affect the labels.
         checkOutput("pkg1/RegClass.html", false,
                 " Z:Z_",
                 " Z:Z:Dfield",
                 " Z:Z_field_In_Class",
                 " S_:D:D:D:D:DINT");
     }
+
+    @Test
+    void testHtml5(Path ignore) {
+        javadoc("-d", "out-html5",
+                "-sourcepath", testSrc,
+                "-source", "8", //so that '_' can be used as an identifier
+                "-use",
+                "-html5",
+                "pkg1");
+        checkExit(Exit.OK);
+
+        // Test some section markers and links to these markers
+        checkOutput("pkg1/RegClass.html", true,
+                "<a id=\"skip.navbar.top\">",
+                "<a href=\"#skip.navbar.top\" title=\"Skip navigation links\">",
+                "<a id=\"nested.class.summary\">",
+                "<a href=\"#nested.class.summary\">",
+                "<a id=\"method.summary\">",
+                "<a href=\"#method.summary\">",
+                "<a id=\"field.detail\">",
+                "<a href=\"#field.detail\">",
+                "<a id=\"constructor.detail\">",
+                "<a href=\"#constructor.detail\">");
+
+        // Test some members and link to these members
+        checkOutput("pkg1/RegClass.html", true,
+                //The marker for this appears in the serialized-form.html which we will
+                //test below
+                "<a href=\"../serialized-form.html#pkg1.RegClass\">");
+
+        // Test some fields
+        checkOutput("pkg1/RegClass.html", true,
+                "<a id=\"_\">",
+                "<a href=\"../pkg1/RegClass.html#_\">",
+                "<a id=\"_$\">",
+                "<a href=\"../pkg1/RegClass.html#_$\">",
+                "<a id=\"$_\">",
+                "<a href=\"../pkg1/RegClass.html#$_\">",
+                "<a id=\"$field\">",
+                "<a href=\"../pkg1/RegClass.html#$field\">",
+                "<a id=\"fieldInCla$$\">",
+                "<a href=\"../pkg1/RegClass.html#fieldInCla$$\">",
+                "<a id=\"S_$$$$$INT\">",
+                "<a href=\"../pkg1/RegClass.html#S_$$$$$INT\">",
+                "<a id=\"method$$\">",
+                "<a href=\"../pkg1/RegClass.html#method$$\">");
+
+        checkOutput("pkg1/DeprMemClass.html", true,
+                "<a id=\"_field_In_Class\">",
+                "<a href=\"../pkg1/DeprMemClass.html#_field_In_Class\">");
+
+        // Test constructor
+        checkOutput("pkg1/RegClass.html", true,
+                "<a id=\"&lt;init&gt;(java.lang.String,int)\">",
+                "<a href=\"../pkg1/RegClass.html#%3Cinit%3E(java.lang.String,int)\">");
+
+        // Test some methods
+        checkOutput("pkg1/RegClass.html", true,
+                "<a id=\"_methodInClass(java.lang.String)\">",
+                "<a href=\"../pkg1/RegClass.html#_methodInClass(java.lang.String)\">",
+                "<a id=\"method()\">",
+                "<a href=\"../pkg1/RegClass.html#method()\">",
+                "<a id=\"foo(java.util.Map)\">",
+                "<a href=\"../pkg1/RegClass.html#foo(java.util.Map)\">",
+                "<a id=\"methodInCla$s(java.lang.String[])\">",
+                "<a href=\"../pkg1/RegClass.html#methodInCla$s(java.lang.String%5B%5D)\">",
+                "<a id=\"_methodInClas$(java.lang.String,int)\">",
+                "<a href=\"../pkg1/RegClass.html#_methodInClas$(java.lang.String,int)\">",
+                "<a id=\"methodD(pkg1.RegClass.$A)\">",
+                "<a href=\"../pkg1/RegClass.html#methodD(pkg1.RegClass.$A)\">",
+                "<a id=\"methodD(pkg1.RegClass.D[])\">",
+                "<a href=\"../pkg1/RegClass.html#methodD(pkg1.RegClass.D%5B%5D)\">");
+
+        checkOutput("pkg1/DeprMemClass.html", true,
+                "<a id=\"$method_In_Class()\">",
+                "<a href=\"../pkg1/DeprMemClass.html#$method_In_Class()\">");
+
+        // Test enum
+        checkOutput("pkg1/RegClass.Te$t_Enum.html", true,
+                "<a id=\"$FLD2\">",
+                "<a href=\"../pkg1/RegClass.Te$t_Enum.html#$FLD2\">");
+
+        // Test nested class
+        checkOutput("pkg1/RegClass._NestedClas$.html", true,
+                "<a id=\"&lt;init&gt;()\">",
+                "<a href=\"../pkg1/RegClass._NestedClas$.html#%3Cinit%3E()\">");
+
+        // Test class use page
+        checkOutput("pkg1/class-use/DeprMemClass.html", true,
+                "<a href=\"../../pkg1/RegClass.html#d____mc\">");
+
+        // Test deprecated list page
+        checkOutput("deprecated-list.html", true,
+                "<a href=\"pkg1/DeprMemClass.html#_field_In_Class\">",
+                "<a href=\"pkg1/DeprMemClass.html#$method_In_Class()\">");
+
+        // Test constant values page
+        checkOutput("constant-values.html", true,
+                "<a href=\"pkg1/RegClass.html#S_$$$$$INT\">");
+
+        // Test serialized form page
+        checkOutput("serialized-form.html", true,
+                //This is the marker for the link that appears in the pkg1.RegClass.html page
+                "<a id=\"pkg1.RegClass\">");
+
+        // Test member name index page
+        checkOutput("index-all.html", true,
+                "<a id=\"I:$\">",
+                "<a href=\"#I:$\">$",
+                "<a href=\"#I:_\">_");
+    }
+
+    /**
+     * The following test is somewhat simplistic, but it is useful
+     * in conjunction with the W3C Validation Service at https://validator.w3.org/nu/#file
+     * @param base A working directory for this method, in which some UTF-8 source files
+     *      will be generated
+     * @throws IOException if there is a problem generating the source files
+     */
+    @Test
+    void testNonAscii(Path base) throws IOException {
+        Path src = base.resolve("src");
+        tb.writeJavaFiles(src,
+                "package p; public class Def {\n"
+                + "    public int \u00e0\u00e9;\n"              // a`e'
+                + "    public void \u00c0\u00c9() { }\n"        // A`E'
+                + "    public int \u03b1\u03b2\u03b3;\n"        // alpha beta gamma
+                + "    public void \u0391\u0392\u0393() { }\n"  // ALPHA BETA GAMMA
+                + "}",
+                "package p; \n"
+                + "/**\n"
+                + " * {@link Def#\u00e0\u00e9 &agrave;&eacute;}<br>\n"
+                + " * {@link Def#\u00c0\u00c9() &Agrave;&Eacute;}<br>\n"
+                + " * {@link Def#\u03b1\u03b2\u03b3 &alpha;&beta;&gamma;}<br>\n"
+                + " * {@link Def#\u0391\u0392\u0393() &Alpha;&Beta;&Gamma;}<br>\n"
+                + " */\n"
+                + "public class Ref { }");
+
+        javadoc("-d", "out-nonAscii",
+                "-sourcepath", src.toString(),
+                "-html5",
+                "-encoding", "utf-8",
+                "p");
+        checkExit(Exit.OK);
+
+        checkOutput("p/Def.html", true,
+                "<a id=\"\u00e0\u00e9\">",
+                "<a id=\"\u00c0\u00c9()\">",
+                "<a id=\"\u03b1\u03b2\u03b3\">",
+                "<a id=\"\u0391\u0392\u0393()\">");
+
+        checkOutput("p/Ref.html", true,
+                "<a href=\"../p/Def.html#%C3%A0%C3%A9\"><code>&agrave;&eacute;</code></a>",
+                "<a href=\"../p/Def.html#%C3%80%C3%89()\"><code>&Agrave;&Eacute;</code></a>",
+                "<a href=\"../p/Def.html#%CE%B1%CE%B2%CE%B3\"><code>&alpha;&beta;&gamma;</code></a>",
+                "<a href=\"../p/Def.html#%CE%91%CE%92%CE%93()\"><code>&Alpha;&Beta;&Gamma;</code></a>");
+
+    }
 }
--- a/test/langtools/jdk/javadoc/doclet/testDocEncoding/TestDocEncoding.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/langtools/jdk/javadoc/doclet/testDocEncoding/TestDocEncoding.java	Sat Oct 21 00:06:50 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -37,6 +37,8 @@
  * @run main TestDocEncoding
  */
 
+import java.nio.charset.Charset;
+
 public class TestDocEncoding extends JavadocTester {
 
     public static void main(String... args) throws Exception {
@@ -53,6 +55,13 @@
                 "pkg");
         checkExit(Exit.OK);
 
+        checkOutput("stylesheet.css", true,
+                "body {\n"
+                + "    background-color:#ffffff;");
+
+        // reset the charset, for a negative test, that the -docencoding
+        // was effective and that the output is not in UTF-8.
+        charset = Charset.forName("UTF-8");
         checkOutput("stylesheet.css", false,
                 "body {\n"
                 + "    background-color:#ffffff;");
--- a/test/langtools/jdk/javadoc/doclet/testSearch/TestSearch.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/langtools/jdk/javadoc/doclet/testSearch/TestSearch.java	Sat Oct 21 00:06:50 2017 +0000
@@ -23,7 +23,8 @@
 
 /*
  * @test
- * @bug 8141492 8071982 8141636 8147890 8166175 8168965 8176794 8175218 8147881 8181622 8182263 8074407
+ * @bug 8141492 8071982 8141636 8147890 8166175 8168965 8176794 8175218 8147881
+ *      8181622 8182263 8074407 8187521
  * @summary Test the search feature of javadoc.
  * @author bpatel
  * @library ../lib
@@ -64,7 +65,7 @@
         checkExit(Exit.OK);
         checkInvalidUsageIndexTag();
         checkSearchOutput(true);
-        checkSingleIndex(true);
+        checkSingleIndex(true, false);
         checkSingleIndexSearchTagDuplication();
         checkJqueryAndImageFiles(true);
         checkSearchJS();
@@ -86,7 +87,7 @@
         checkExit(Exit.ERROR);
         checkDocLintErrors();
         checkSearchOutput(true);
-        checkSingleIndex(true);
+        checkSingleIndex(true, false);
         checkSingleIndexSearchTagDuplication();
         checkJqueryAndImageFiles(true);
         checkSearchJS();
@@ -128,7 +129,7 @@
                 "-use", "pkg", "pkg1", "pkg2", "pkg3");
         checkExit(Exit.OK);
         checkSearchOutput(true);
-        checkSingleIndex(true);
+        checkSingleIndex(true, true);
         checkSingleIndexSearchTagDuplication();
         checkJqueryAndImageFiles(true);
         checkSearchJS();
@@ -280,7 +281,9 @@
                 "<div class=\"fixedNav\">");
     }
 
-    void checkSingleIndex(boolean expectedOutput) {
+    void checkSingleIndex(boolean expectedOutput, boolean html5) {
+        String html_span_see_span = html5 ? "html%3Cspan%3Esee%3C/span%3E" : "html-span-see-/span-";
+
         // Test for search tags markup in index file.
         checkOutput("index-all.html", expectedOutput,
                 "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#phrasewithspaces\">"
@@ -313,7 +316,7 @@
                 + "#nested%7B@indexnested_tag_test%7D\">nested {@index nested_tag_test}</a></span> - "
                 + "Search tag in pkg.AnotherClass.ModalExclusionType.NO_EXCLUDE</dt>",
                 "<dt><span class=\"searchTagLink\"><a href=\"pkg/AnotherClass.ModalExclusionType.html"
-                + "#html-span-see-/span-\">html &lt;span&gt; see &lt;/span&gt;</a></span> - Search "
+                + "#" + html_span_see_span + "\">html &lt;span&gt; see &lt;/span&gt;</a></span> - Search "
                 + "tag in pkg.AnotherClass.ModalExclusionType.APPLICATION_EXCLUDE</dt>",
                 "<dt><span class=\"searchTagLink\"><a href=\"pkg/AnotherClass.html#quoted\">quoted</a>"
                 + "</span> - Search tag in pkg.AnotherClass.CONSTANT1</dt>",
--- a/test/langtools/jdk/jshell/ErrorTranslationTest.java	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/langtools/jdk/jshell/ErrorTranslationTest.java	Sat Oct 21 00:06:50 2017 +0000
@@ -23,6 +23,7 @@
 
 /*
  * @test
+ * @bug 8188225
  * @summary Tests for shell error translation
  * @modules jdk.compiler/com.sun.tools.javac.api
  *          jdk.compiler/com.sun.tools.javac.main
@@ -59,6 +60,13 @@
         );
     }
 
+    public void testlvtiErrors() {
+        test(
+                a -> assertDiagnostic(a, "var broken = () -> {};", newExpectedDiagnostic(0, 22, 0, -1, -1, Diagnostic.Kind.ERROR)),
+                a -> assertDiagnostic(a, "void t () { var broken = () -> {}; }", newExpectedDiagnostic(12, 34, 0, -1, -1, Diagnostic.Kind.ERROR))
+        );
+    }
+
     public void testWarnings() {
         List<ReplTest> list = new ArrayList<>();
         ExpectedDiagnostic[] diagnostics = new ExpectedDiagnostic[]{
@@ -117,19 +125,16 @@
             }
             String kind = getKind(expectedDiagnostic.getKind());
             assertEquals(lines[0], kind);
-            String source;
-            String markingLine;
-            switch (expectedDiagnostic.getKind()) {
-                case ERROR:
-                case WARNING:
-                    source = lines[2];
-                    markingLine = lines[3];
-                    break;
-                default:
-                    throw new AssertionError("Unsupported diagnostic kind: " + expectedDiagnostic.getKind());
+            boolean found = false;
+            for (int i = 0; i < lines.length; i++) {
+                if (lines[i].endsWith(expectedSource)) {
+                    assertEquals(lines[i + 1], expectedMarkingLine, "Input: " + expectedSource + ", marking line: ");
+                    found = true;
+                }
             }
-            assertTrue(source.endsWith(expectedSource), "Expected: " + expectedSource + ", found: " + source);
-            assertEquals(markingLine, expectedMarkingLine, "Input: " + expectedSource + ", marking line: ");
+            if (!found) {
+                throw new AssertionError("Did not find: " + expectedSource + " in: " + s);
+            }
         };
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/8169345/T8169345a.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,55 @@
+/*
+ * 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 8169345
+ * @summary javac crash when local from enclosing context is captured multiple times
+ */
+
+public class T8169345a {
+    void test() {
+        Object o = new Object();
+        class Local1 {
+            Object test1() {
+                return o;
+            }
+        }
+        class Local2 {
+            void test2() {
+                Object o = new Object();
+                class Local3 extends Local1 {
+                    Object test3() {
+                        return o;
+                    }
+                }
+            }
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        Class.forName("T8169345a$1Local1");
+        Class.forName("T8169345a$1Local2$1Local3");
+        Class.forName("T8169345a$1Local2");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/8169345/T8169345b.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,57 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 8169345
+ * @summary javac crash when local from enclosing context is captured multiple times
+ */
+
+public class T8169345b {
+    void test() {
+        Object o = new Object();
+        class Local1 {
+            Object test1() {
+                return o;
+            }
+        }
+        class Local2 {
+            void test2() {
+                Object o = new Object();
+                class Local3 {
+                    Object test3() {
+                        return o;
+                    }
+                }
+            }
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        Class.forName("T8169345b$1Local1");
+        Class.forName("T8169345b$1Local2$1Local3");
+        Class.forName("T8169345b$1Local2");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/8169345/T8169345c.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,54 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please 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 8169345
+ * @summary javac crash when local from enclosing context is captured multiple times
+ * @compile T8169345c.java
+ */
+
+class T8169345c {
+    void test() {
+        final int b;
+        b = 10;
+        class Local1 {
+            public String toString() {
+                return "" + b;
+            }
+        }
+        class Local2 {
+            void test() {
+                final int b;
+                b = 20;
+                class DeepLocal extends Local1 {
+                    public String toString() {
+                        return "" + b;
+                    }
+                }
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/lambda/LambdaInSuperCallCapturingOuterThis.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,59 @@
+/*
+ * 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 8184989
+ * @summary Incorrect class file created when passing lambda in inner class constructor and outer is subclass
+ * @run main LambdaInSuperCallCapturingOuterThis
+ */
+
+class A8184989 {
+    public boolean test() {
+        return true;
+    }
+
+    class AA {
+        public AA(Condition8184989<AA> condition) {
+        }
+    }
+}
+
+interface Condition8184989<T> {
+    boolean check(T t);
+}
+
+public class LambdaInSuperCallCapturingOuterThis extends A8184989 {
+
+    public LambdaInSuperCallCapturingOuterThis() {
+        new BA();
+    }
+    public class BA extends AA {
+        public BA() {
+            super(o -> test());
+        }
+    }
+    public static void main(String[] args) {
+        LambdaInSuperCallCapturingOuterThis b = new LambdaInSuperCallCapturingOuterThis();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/lambda/LambdaInSuperCallCapturingOuterThis2.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,62 @@
+/*
+ * 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 8184989
+ * @summary Incorrect class file created when passing lambda in inner class constructor and outer is subclass
+ * @run main LambdaInSuperCallCapturingOuterThis2
+ */
+
+class A8184989_2 {
+    public boolean test() {
+        return true;
+    }
+    class AA {
+        public AA(Condition8184989_2<AA> condition) {
+            if (condition.check(this) != true) {
+                throw new AssertionError("Incorrect output");
+            }
+        }
+    }
+}
+
+interface Condition8184989_2<T> {
+    boolean check(T t);
+}
+
+public class LambdaInSuperCallCapturingOuterThis2 extends A8184989_2 {
+    public boolean test() {return false;}
+    public void b() {}
+
+    class C extends A8184989_2 {
+        public class BA extends AA {
+            public BA() {
+                super(o -> {b(); return test();});
+            }
+        }
+    }
+    public static void main(String[] args) {
+        new LambdaInSuperCallCapturingOuterThis2().new C().new BA();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/lambda/LambdaInSuperCallCapturingOuterThis3.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,65 @@
+/*
+ * 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 8184989
+ * @summary Incorrect class file created when passing lambda in inner class constructor and outer is subclass
+ * @run main LambdaInSuperCallCapturingOuterThis3
+ */
+
+interface I8184989_3 {
+    public default boolean test(){
+        return true;
+    }
+}
+
+class A8184989_3 implements I8184989_3 {
+    class AA {
+        public AA(Condition8184989_3<AA> condition) {
+            if (condition.check(this) != true) {
+                throw new AssertionError("Incorrect output");
+            }
+        }
+    }
+}
+
+interface Condition8184989_3<T> {
+    boolean check(T t);
+}
+
+public class LambdaInSuperCallCapturingOuterThis3 extends A8184989_3 {
+    public boolean test() {return false;}
+    public void b() {}
+
+    class C extends A8184989_3 {
+        public class BA extends AA {
+            public BA() {
+                super(o -> {b(); return test();});
+            }
+        }
+    }
+    public static void main(String[] args) {
+        new LambdaInSuperCallCapturingOuterThis3().new C().new BA();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/tree/VarTree.java	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,133 @@
+/*
+ * 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 8188225
+ * @summary Check that variables of type var have a consistent model
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ */
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.tools.javac.api.JavacTaskImpl;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+
+import com.sun.source.tree.VariableTree;
+import com.sun.source.util.TreeScanner;
+import com.sun.source.util.Trees;
+
+public class VarTree {
+    private final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
+
+    public static void main(String... args) throws Exception {
+        VarTree test = new VarTree();
+        test.run("|var testVar = 0;| ",
+                 "int testVar = 0");
+        test.run("|var testVar = 0;| undef undef;",
+                 "int testVar = 0");
+        test.run("|final var testVar = 0;| ",
+                 "final int testVar = 0");
+        test.run("for (|var testVar| : java.util.Arrays.asList(0, 1)) {}",
+                 "java.lang.Integer testVar");
+        test.run("for (|final var testVar| : java.util.Arrays.asList(0, 1)) {}",
+                 "final java.lang.Integer testVar");
+        test.run("java.util.function.Consumer<String> c = |testVar| -> {};",
+                 "java.lang.String testVar");
+        test.run("java.util.function.Consumer<String> c = (|testVar|) -> {};",
+                 "java.lang.String testVar");
+    }
+
+    void run(String code, String expected) throws IOException {
+        String[] parts = code.split("\\|");
+
+        if (parts.length != 3) {
+            throw new IllegalStateException("Incorrect number of markers.");
+        }
+
+        String prefix = "public class Test { void test() { ";
+        String src = prefix + parts[0] + parts[1] + parts[2] + " } }";
+
+        JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, d -> {},
+                                                        List.of("--should-stop:at=FLOW"),
+                                                        null, Arrays.asList(new MyFileObject(src)));
+
+        Iterable<? extends CompilationUnitTree> units = ct.parse();
+        ct.analyze();
+
+        Trees trees = Trees.instance(ct);
+
+        for (CompilationUnitTree cut : units) {
+            new TreeScanner<Void, Void>() {
+                @Override
+                public Void visitVariable(VariableTree node, Void p) {
+                    if (node.getName().contentEquals("testVar")) {
+                        if (!expected.equals(node.toString())) {
+                            throw new AssertionError("Unexpected tree: " + node.toString());
+                        }
+
+                        int start = (int) trees.getSourcePositions().getStartPosition(cut, node);
+                        int end   = (int) trees.getSourcePositions().getEndPosition(cut, node);
+
+                        String snip = src.substring(start, end);
+
+                        if (start != prefix.length() + parts[0].length() || end != prefix.length() + parts[0].length() + parts[1].length()) {
+                            throw new AssertionError("Unexpected span: " + snip);
+                        }
+
+                        int typeStart = (int) trees.getSourcePositions().getStartPosition(cut, node.getType());
+                        int typeEnd   = (int) trees.getSourcePositions().getEndPosition(cut, node.getType());
+
+                        if (typeStart != (-1) && typeEnd != (-1)) {
+                            throw new AssertionError("Unexpected type position: " + typeStart + ", " + typeEnd);
+                        }
+                    }
+                    return super.visitVariable(node, p);
+                }
+
+            }.scan(cut, null);
+        }
+    }
+    class MyFileObject extends SimpleJavaFileObject {
+
+        private String text;
+
+        public MyFileObject(String text) {
+            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
+            this.text = text;
+        }
+
+        @Override
+        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
+            return text;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/make/TestCopyFiles.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,80 @@
+#
+# 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.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+default: all
+
+include $(SPEC)
+include MakeBase.gmk
+include UtilsForTests.gmk
+
+THIS_FILE := $(TOPDIR)/test/make/TestCopyFiles.gmk
+DEPS := $(THIS_FILE) \
+    $(TOPDIR)/make/common/MakeBase.gmk \
+    #
+
+OUTPUT_DIR := $(TESTMAKE_OUTPUTDIR)/copy-files
+$(call MakeDir, $(OUTPUT_DIR))
+
+################################################################################
+# Test SetupCopyFiles with CacheFind and files with spaces in their names.
+
+SRC_DIR := $(OUTPUT_DIR)/src
+DEST_DIR := $(OUTPUT_DIR)/dest
+
+$(OUTPUT_DIR)/_src_created: $(DEPS)
+	$(RM) -r $(SRC_DIR)
+	$(MKDIR) -p $(SRC_DIR)
+	$(MKDIR) -p $(SRC_DIR)/foo
+	$(TOUCH) $(SRC_DIR)/file
+	$(TOUCH) $(SRC_DIR)/foo/foofile
+	$(TOUCH) "$(SRC_DIR)/foo/foo file"
+        # Spaces in directories only works with gnu make 4.0 or later
+        ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION))))
+	  $(MKDIR) -p "$(SRC_DIR)/foo bar"
+	  $(TOUCH) "$(SRC_DIR)/foo bar/foobarfile"
+	  $(TOUCH) "$(SRC_DIR)/foo bar/foo bar file"
+        endif
+	$(LN) -s file "$(SRC_DIR)/link to file"
+	$(TOUCH) $@
+
+$(eval $(call SetupCopyFiles, COPY_1, \
+    SRC := $(SRC_DIR), \
+    DEST := $(DEST_DIR), \
+    FILES := $(call CacheFind, $(SRC_DIR)), \
+))
+
+do-copy1: $(COPY_1)
+
+run-test1: $(OUTPUT_DIR)/_src_created
+	+$(MAKE) -f $(THIS_FILE) do-copy1
+	$(DIFF) -r $(SRC_DIR) $(DEST_DIR)
+
+TEST_TARGETS += run-test1
+
+.PHONY: do-copy1 run-test1
+
+################################################################################
+
+all: $(TEST_TARGETS)
--- a/test/make/TestIdea.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/make/TestIdea.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -35,11 +35,11 @@
 
 verify-idea:
 	$(MKDIR) -p $(IDEA_OUTPUT_DIR)
-	$(BASH) $(TOPDIR)/common/bin/idea.sh -o $(IDEA_OUTPUT_DIR)/idea1
-	$(BASH) $(TOPDIR)/common/bin/idea.sh -o $(IDEA_OUTPUT_DIR)/idea2 java.base
-	$(BASH) $(TOPDIR)/common/bin/idea.sh -o $(IDEA_OUTPUT_DIR)/idea3 java.base jdk.compiler
+	MAKEFLAGS= MFLAGS= $(BASH) $(TOPDIR)/bin/idea.sh -o $(IDEA_OUTPUT_DIR)/idea1
+	MAKEFLAGS= MFLAGS= $(BASH) $(TOPDIR)/bin/idea.sh -o $(IDEA_OUTPUT_DIR)/idea2 java.base
+	MAKEFLAGS= MFLAGS= $(BASH) $(TOPDIR)/bin/idea.sh -o $(IDEA_OUTPUT_DIR)/idea3 java.base jdk.compiler
 
-TEST_TARGETS += verify-idea 
+TEST_TARGETS += verify-idea
 
 all: $(TEST_TARGETS)
 
--- a/test/make/TestJavaCompilation.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/make/TestJavaCompilation.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -29,6 +29,7 @@
 include MakeBase.gmk
 include JarArchive.gmk
 include JavaCompilation.gmk
+include UtilsForTests.gmk
 
 THIS_FILE := $(TOPDIR)/test/make/TestJavaCompilation.gmk
 DEPS := $(THIS_FILE) \
@@ -90,8 +91,8 @@
 create-jar2: $(OUTPUT_DIR)/_jar1_verified
 TEST_TARGETS += $(OUTPUT_DIR)/_jar1_verified
 
-# Change a source file and call this makefile again to force the jar to be 
-# updated. 
+# Change a source file and call this makefile again to force the jar to be
+# updated.
 $(OUTPUT_DIR)/_jar1_updated: $(OUTPUT_DIR)/_jar1_verified
 	$(ECHO) updated > $(JAR1_SRC_ROOT)/dir1/file1.class
 	$(ECHO) updated > $(JAR1_SRC_ROOT)/META-INF/metafile
@@ -104,6 +105,7 @@
 # Change the manifest file and call this makefile again to force the jar
 # to be updated
 $(OUTPUT_DIR)/_jar1_updated_manifest: $(OUTPUT_DIR)/_jar1_updated
+	$(SLEEP_ON_MAC)
 	$(ECHO) "Test-Attribute: foobar" > $(JAR1_MANIFEST)
 	+$(MAKE) -f $(THIS_FILE) $(BUILD_JAR1)
 	$(RM) -r $(JAR1_UNZIP)
--- a/test/make/TestMake.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/make/TestMake.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -33,10 +33,13 @@
 java-compilation:
 	+$(MAKE) -f TestJavaCompilation.gmk $(TEST_SUBTARGET)
 
+copy-files:
+	+$(MAKE) -f TestCopyFiles.gmk $(TEST_SUBTARGET)
+
 test-idea:
 	+$(MAKE) -f TestIdea.gmk $(TEST_SUBTARGET)
 
 
-all: make-base java-compilation test-idea
+all: make-base java-compilation copy-files test-idea
 
-.PHONY: default all make-base java-compilation test-idea
+.PHONY: default all make-base java-compilation copy-files test-idea
--- a/test/make/TestMakeBase.gmk	Sat Oct 21 07:00:23 2017 +0900
+++ b/test/make/TestMakeBase.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -27,28 +27,13 @@
 
 include $(SPEC)
 include MakeBase.gmk
+include UtilsForTests.gmk
 
 THIS_FILE := $(TOPDIR)/test/make/TestMakeBase.gmk
 DEPS := $(THIS_FILE) \
     $(TOPDIR)/make/common/MakeBase.gmk \
     #
 
-# Assert two strings are equal
-# 1 - Tested value
-# 2 - Exepected value
-# 3 - Error message
-define assert-equals
-  ifneq ($$(strip $1),$$(strip $2))
-    $$(error $3 - Expected >$$(strip $2)< - Got >$$(strip $1)<)
-  endif
-endef
-
-# On macosx, file system timestamps only have 1 second resultion so must add
-# sleeps to properly test dependencies.
-ifeq ($(OPENJDK_BUILD_OS), macosx)
-  SLEEP_ON_MAC := sleep 1
-endif
-
 OUTPUT_DIR := $(TESTMAKE_OUTPUTDIR)/make-base
 $(call MakeDir, $(OUTPUT_DIR))
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/make/UtilsForTests.gmk	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,42 @@
+#
+# 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.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# This file contains utilities common for multiple test makefiles.
+
+# Assert two strings are equal
+# 1 - Tested value
+# 2 - Exepected value
+# 3 - Error message
+define assert-equals
+  ifneq ($$(strip $1),$$(strip $2))
+    $$(error $3 - Expected >$$(strip $2)< - Got >$$(strip $1)<)
+  endif
+endef
+
+# On macosx, file system timestamps only have 1 second resultion so must add
+# sleeps to properly test dependencies.
+ifeq ($(OPENJDK_BUILD_OS), macosx)
+  SLEEP_ON_MAC := sleep 1
+endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/nashorn/script/basic/JDK-8027302.js	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,160 @@
+/*
+ * 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.
+ */
+
+/**
+ * JDK-8027302: Identifiers containing unicode escapes are not recognized as reserved words
+ *
+ * @test
+ * @run
+ */
+
+// keywords containing escapes
+
+try {
+    eval("v\\u0061r i;");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("\\u0069f (true) ;");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof ReferenceError); // no SyntaxError in ES5
+}
+
+try {
+    eval("if (true) ; \\u0065lse ;");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof ReferenceError); // no SyntaxError in ES5
+}
+
+try {
+    eval("f\\u0075nction x() {}");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("var f = f\\u0075nction() {}");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("var o = { f: f\\u0075nction() {}}");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("var a = [f\\u0075nction() {}]");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+// keywords as identifiers, with and without escapes
+
+try {
+    eval("function break() {}");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("function bre\\u0061k() {}");
+} catch (e) {
+    fail("Unexpected error");
+}
+
+try {
+    eval("function f(break) {}");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("function f(bre\\u0061k) {}");
+} catch (e) {
+    fail("Unexpected error");
+}
+
+try {
+    eval("var break = 3");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("'use strict'; var break = 3");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("var bre\\u0061k = 3");
+} catch (e) {
+    fail("Unexpected error");
+}
+
+try {
+    eval("'use strict'; var bre\\u0061k = 3");
+} catch (e) {
+    fail("Unexpected error");
+}
+
+try {
+    eval("var package = 3");
+} catch (e) {
+    fail("Unexpected error");
+}
+
+try {
+    eval("'use strict'; var package = 3");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("var p\\u0061ckage = 3");
+} catch (e) {
+    fail("Unexpected error");
+}
+
+try {
+    eval("'use strict'; var p\\u0061ckage = 3");
+} catch (e) {
+    fail("Unexpected error");
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/nashorn/script/basic/es6/JDK-8027302.js	Sat Oct 21 00:06:50 2017 +0000
@@ -0,0 +1,166 @@
+/*
+ * 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.
+ */
+
+/**
+ * JDK-8027302: Identifiers containing unicode escapes are not recognized as reserved words
+ *
+ * @test
+ * @run
+ * @option --language=es6
+ */
+
+// keywords containing escapes
+
+try {
+    eval("v\\u0061r i;");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("\\u0069f (true) ;");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("if (true) ; \\u0065lse ;");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("f\\u0075nction x() {}");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("var f = f\\u0075nction() {}");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("var o = { f: f\\u0075nction() {}}");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("var a = [f\\u0075nction() {}]");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+// keywords as identifiers, with and without escapes
+
+try {
+    eval("function break() {}");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("function bre\\u0061k() {}");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("function f(break) {}");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("function f(bre\\u0061k) {}");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("var break = 3");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("'use strict'; var break = 3");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("var bre\\u0061k = 3");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("'use strict'; var bre\\u0061k = 3");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("var package = 3");
+} catch (e) {
+    fail("Unexpected error");
+}
+
+try {
+    eval("'use strict'; var package = 3");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+
+try {
+    eval("var p\\u0061ckage = 3");
+} catch (e) {
+    fail("Unexpected error");
+}
+
+try {
+    eval("'use strict'; var p\\u0061ckage = 3");
+    fail("Expected error");
+} catch (e) {
+    Assert.assertTrue(e instanceof SyntaxError);
+}
+