changeset 48173:7bcdb571ae31

Merge
author prr
date Mon, 27 Nov 2017 10:35:05 -0800
parents 5e86806f57f9 06652ffab955
children dcf5dacd0b2b
files src/hotspot/share/gc/g1/g1MarkSweep.cpp src/hotspot/share/gc/g1/g1MarkSweep.hpp src/hotspot/share/gc/g1/g1MarkSweep_ext.cpp src/hotspot/share/gc/g1/g1RemSet.inline.hpp src/hotspot/share/gc/g1/g1SerialFullCollector.cpp src/hotspot/share/gc/g1/g1SerialFullCollector.hpp src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TableHeader.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlDocWriter.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlWriter.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/GroupTypes.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/MethodTypes.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/ModulePackageTypes.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/TableTabTypes.java test/langtools/tools/javadoc/sourceOnly/p/NonSource.class
diffstat 485 files changed, 15821 insertions(+), 6232 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Fri Nov 24 16:55:18 2017 -0800
+++ b/.hgtags	Mon Nov 27 10:35:05 2017 -0800
@@ -456,3 +456,5 @@
 a6e591e12f122768f675428e1e5a838fd0e9c7ec jdk-10+29
 8fee80b92e65149f7414250fd5e34b6f35d417b4 jdk-10+30
 e6278add9ff28fab70fe1cc4c1d65f7363dc9445 jdk-10+31
+a2008587c13fa05fa2dbfcb09fe987576fbedfd1 jdk-10+32
+bbd692ad4fa300ecca7939ffbe3b1d5e52a28cc6 jdk-10+33
--- a/doc/building.html	Fri Nov 24 16:55:18 2017 -0800
+++ b/doc/building.html	Mon Nov 27 10:35:05 2017 -0800
@@ -871,9 +871,9 @@
 <p>When building for distribution, <code>zipped</code> is a good solution. Binaries built with <code>internal</code> is suitable for use by developers, since they facilitate debugging, but should be stripped before distributed to end users.</p>
 <h3 id="autoconf-details">Autoconf Details</h3>
 <p>The <code>configure</code> script is based on the autoconf framework, but in some details deviate from a normal autoconf <code>configure</code> script.</p>
-<p>The <code>configure</code> script in the top level directory of OpenJDK is just a thin wrapper that calls <code>common/autoconf/configure</code>. This in turn provides functionality that is not easily expressed in the normal Autoconf framework, and then calls into the core of the <code>configure</code> script, which is the <code>common/autoconf/generated-configure.sh</code> file.</p>
+<p>The <code>configure</code> script in the top level directory of OpenJDK is just a thin wrapper that calls <code>make/autoconf/configure</code>. This in turn provides functionality that is not easily expressed in the normal Autoconf framework, and then calls into the core of the <code>configure</code> script, which is the <code>make/autoconf/generated-configure.sh</code> file.</p>
 <p>As the name implies, this file is generated by Autoconf. It is checked in after regeneration, to alleviate the common user to have to install Autoconf.</p>
-<p>The build system will detect if the Autoconf source files have changed, and will trigger a regeneration of <code>common/autoconf/generated-configure.sh</code> if needed. You can also manually request such an update by <code>bash common/autoconf/autogen.sh</code>.</p>
+<p>The build system will detect if the Autoconf source files have changed, and will trigger a regeneration of <code>make/autoconf/generated-configure.sh</code> if needed. You can also manually request such an update by <code>bash make/autoconf/autogen.sh</code>.</p>
 <p>If you make changes to the build system that requires a re-generation, note the following:</p>
 <ul>
 <li><p>You must use <em>exactly</em> version 2.69 of autoconf for your patch to be accepted. This is to avoid spurious changes in the generated file. Note that Ubuntu 16.04 ships a patched version of autoconf which claims to be 2.69, but is not.</p></li>
--- a/doc/building.md	Fri Nov 24 16:55:18 2017 -0800
+++ b/doc/building.md	Mon Nov 27 10:35:05 2017 -0800
@@ -1660,18 +1660,18 @@
 deviate from a normal autoconf `configure` script.
 
 The `configure` script in the top level directory of OpenJDK is just a thin
-wrapper that calls `common/autoconf/configure`. This in turn provides
+wrapper that calls `make/autoconf/configure`. This in turn provides
 functionality that is not easily expressed in the normal Autoconf framework,
 and then calls into the core of the `configure` script, which is the
-`common/autoconf/generated-configure.sh` file.
+`make/autoconf/generated-configure.sh` file.
 
 As the name implies, this file is generated by Autoconf. It is checked in after
 regeneration, to alleviate the common user to have to install Autoconf.
 
 The build system will detect if the Autoconf source files have changed, and
-will trigger a regeneration of `common/autoconf/generated-configure.sh` if
+will trigger a regeneration of `make/autoconf/generated-configure.sh` if
 needed. You can also manually request such an update by `bash
-common/autoconf/autogen.sh`.
+make/autoconf/autogen.sh`.
 
 If you make changes to the build system that requires a re-generation, note the
 following:
--- a/make/Bundles.gmk	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/Bundles.gmk	Mon Nov 27 10:35:05 2017 -0800
@@ -177,7 +177,7 @@
   # Create special filter rules when dealing with unzipped .dSYM directories on
   # macosx
   ifeq ($(OPENJDK_TARGET_OS), macosx)
-    ifeq ($(ZIP_DEBUGINFO_FILES), false)
+    ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
       JDK_SYMBOLS_EXCLUDE_PATTERN := $(addprefix %, \
           $(call containing, .dSYM/, $(patsubst $(JDK_IMAGE_DIR)/%, %, $(ALL_JDK_FILES))))
     endif
@@ -212,7 +212,7 @@
   # Create special filter rules when dealing with unzipped .dSYM directories on
   # macosx
   ifeq ($(OPENJDK_TARGET_OS), macosx)
-    ifeq ($(ZIP_DEBUGINFO_FILES), false)
+    ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
       JRE_SYMBOLS_EXCLUDE_PATTERN := $(addprefix %, \
           $(call containing, .dSYM/, $(patsubst $(JRE_IMAGE_DIR)/%, %, $(ALL_JRE_FILES))))
     endif
--- a/make/Init.gmk	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/Init.gmk	Mon Nov 27 10:35:05 2017 -0800
@@ -329,7 +329,7 @@
 	$(call PrintFailureReports)
 	$(call PrintBuildLogFailures)
 	$(call ReportProfileTimes)
-	$(PRINTF) "Hint: See common/doc/building.html#troubleshooting for assistance.\n\n"
+	$(PRINTF) "Hint: See doc/building.html#troubleshooting for assistance.\n\n"
         ifneq ($(COMPARE_BUILD), )
 	  $(call CleanupCompareBuild)
         endif
--- a/make/Main.gmk	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/Main.gmk	Mon Nov 27 10:35:05 2017 -0800
@@ -1049,7 +1049,7 @@
 # file.
 
 CLEAN_DIRS += hotspot jdk bootcycle-build test buildtools support \
-    images make-support test-make bundles buildjdk
+    images make-support test-make bundles buildjdk test-results test-support
 CLEAN_DIR_TARGETS := $(addprefix clean-, $(CLEAN_DIRS))
 CLEAN_SUPPORT_DIRS += demos
 CLEAN_SUPPORT_DIR_TARGETS := $(addprefix clean-, $(CLEAN_SUPPORT_DIRS))
@@ -1094,6 +1094,8 @@
 # while classes and touch files end up in jdk.
 clean-support: clean-jdk
 
+clean-test: clean-test-results clean-test-support
+
 # Remove everything, including configure configuration. If the output
 # directory was created by configure and now becomes empty, remove it as well.
 dist-clean: clean
--- a/make/RunTests.gmk	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/RunTests.gmk	Mon Nov 27 10:35:05 2017 -0800
@@ -32,15 +32,17 @@
 # We will always run multiple tests serially
 .NOTPARALLEL:
 
-# Directories to find jtreg tests relative to
-JTREG_TEST_TOPDIRS := $(TOPDIR) $(JTREG_TESTROOTS)
-
 # Hook to include the corresponding custom file, if present.
 $(eval $(call IncludeCustomExtension, RunTests.gmk))
 
 TEST_RESULTS_DIR := $(OUTPUTDIR)/test-results
 TEST_SUPPORT_DIR := $(OUTPUTDIR)/test-support
 
+ifeq ($(CUSTOM_ROOT), )
+  JTREG_TOPDIR := $(TOPDIR)
+else
+  JTREG_TOPDIR := $(CUSTOM_ROOT)
+endif
 
 ################################################################################
 # Parse control variables
@@ -87,6 +89,11 @@
 hotspot_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/hotspot/jtreg/native
 jdk_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/jdk/jtreg/native
 
+jdk_JTREG_PROBLEM_LIST += $(TOPDIR)/test/jdk/ProblemList.txt
+jaxp_JTREG_PROBLEM_LIST += $(TOPDIR)/test/jaxp/ProblemList.txt
+langtools_JTREG_PROBLEM_LIST += $(TOPDIR)/test/langtools/ProblemList.txt
+nashorn_JTREG_PROBLEM_LIST += $(TOPDIR)/test/nashorn/ProblemList.txt
+hotspot_JTREG_PROBLEM_LIST += $(TOPDIR)/test/hotspot/jtreg/ProblemList.txt
 
 ################################################################################
 # Parse test selection
@@ -119,12 +126,46 @@
   )
 endef
 
+# Helper function that removes the TOPDIR part
+CleanupJtregPath = \
+  $(strip $(patsubst %/, %, $(subst $(JTREG_TOPDIR)/,, $1)))
+
+# Take a partial Jtreg root path and return a full, absolute path to that Jtreg
+# root. Also support having "hotspot" as an alias for "hotspot/jtreg".
+ExpandJtregRoot = \
+  $(call CleanupJtregPath, $(wildcard \
+    $(if $(filter /%, $1), \
+      $(if $(wildcard $(strip $1)/TEST.ROOT), \
+        $1 \
+      ) \
+    , \
+      $(filter $(addprefix %, $1), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
+      $(filter $(addprefix %, $(strip $1)/jtreg), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
+    ) \
+  ))
+
+# Take a partial Jtreg test path and return a full, absolute path to that Jtreg
+# test. Also support having "hotspot" as an alias for "hotspot/jtreg".
+ExpandJtregPath = \
+  $(if $(call ExpandJtregRoot, $1), \
+    $(call ExpandJtregRoot, $1) \
+  , \
+    $(call CleanupJtregPath, $(wildcard \
+      $(if $(filter /%, $1), \
+        $1 \
+      , \
+        $(addsuffix /$(strip $1), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
+        $(addsuffix $(strip $(patsubst hotspot/%, /hotspot/jtreg/%, $1)), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
+      ) \
+    )) \
+  )
+
 # Helper function to determine if a test specification is a Jtreg test
 #
 # It is a Jtreg test if it optionally begins with jtreg:, and then is either
 # an unspecified group name (possibly prefixed by :), or a group in a
-# specified test/<component> directory, or a path to a test or test directory,
-# either absolute or relative to any of the JTREG_TEST_TOPDIRS.
+# specified test root, or a path to a test or test directory,
+# either absolute or relative to any of the TEST_BASEDIRS or test roots.
 define ParseJtregTestSelection
   $(eval TEST_NAME := $(strip $(patsubst jtreg:%, %, $1))) \
   $(if $(or $(findstring :, $(TEST_NAME)), $(findstring /, $(TEST_NAME))), , \
@@ -132,29 +173,26 @@
   ) \
   $(if $(findstring :, $(TEST_NAME)), \
     $(if $(filter :%, $(TEST_NAME)), \
-      $(foreach root, $(JTREG_TESTROOTS), \
-        $(if $(filter $(patsubst :%, %, $(TEST_NAME)), \
-            $($(root)_JTREG_TEST_GROUPS)), \
-          jtreg:$(root):$(patsubst :%,%,$(TEST_NAME)) \
-        ) \
-      ) \
+      $(eval TEST_GROUP := $(patsubst :%, %, $(TEST_NAME))) \
+      $(eval TEST_ROOTS := $(JTREG_TESTROOTS)) \
     , \
-      $(eval ROOT_PART := $(word 1, $(subst :, $(SPACE), $(TEST_NAME)))) \
-      $(eval ROOT := $(filter $(addprefix %, $(ROOT_PART)), $(JTREG_TESTROOTS))) \
-      $(eval GROUP := $(word 2, $(subst :, $(SPACE), $(TEST_NAME)))) \
-      $(foreach root, $(ROOT), \
-        $(if $(filter $(GROUP), $($(root)_JTREG_TEST_GROUPS)), \
-          jtreg:$(root):$(GROUP) \
+      $(eval TEST_PATH := $(word 1, $(subst :, $(SPACE), $(TEST_NAME)))) \
+      $(eval TEST_GROUP := $(word 2, $(subst :, $(SPACE), $(TEST_NAME)))) \
+      $(eval TEST_ROOTS := $(call ExpandJtregRoot, $(TEST_PATH))) \
+    ) \
+    $(foreach test_root, $(TEST_ROOTS), \
+      $(if $(filter /%, $(test_root)), \
+        jtreg:$(test_root):$(TEST_GROUP) \
+      , \
+        $(if $(filter $(TEST_GROUP), $($(JTREG_TOPDIR)/$(test_root)_JTREG_TEST_GROUPS)), \
+          jtreg:$(test_root):$(TEST_GROUP) \
         ) \
       ) \
     ) \
   , \
-    $(if $(filter /%, $(TEST_NAME)), \
-      $(if $(wildcard $(TEST_NAME)), \
-        jtreg:$(TEST_NAME) \
-      ) \
-    , \
-      $(addprefix jtreg:, $(wildcard $(addsuffix /$(TEST_NAME), $(JTREG_TEST_TOPDIRS)))) \
+    $(eval TEST_PATHS := $(call ExpandJtregPath, $(TEST_NAME))) \
+    $(foreach test_path, $(TEST_PATHS), \
+      jtreg:$(test_path) \
     ) \
   )
 endef
@@ -162,7 +200,7 @@
 ifeq ($(TEST), )
   $(info No test selection given in TEST!)
   $(info Please use e.g. 'run-test TEST=tier1' or 'run-test-tier1')
-  $(info See common/doc/testing.[md|html] for help)
+  $(info See doc/testing.[md|html] for help)
   $(error Cannot continue)
 endif
 
@@ -185,7 +223,7 @@
 
 ifneq ($(UNKNOWN_TEST), )
   $(info Unknown test selection: '$(UNKNOWN_TEST)')
-  $(info See common/doc/testing.[md|html] for help)
+  $(info See doc/testing.[md|html] for help)
   $(error Cannot continue)
 endif
 
@@ -299,8 +337,17 @@
   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 
   $1_TEST_NAME := $$(strip $$(patsubst jtreg:%, %, $$($1_TEST)))
-  $1_COMPONENT := $$(firstword $$(subst /, $$(SPACE), \
-      $$(patsubst test/%, %, $$($1_TEST_NAME))))
+
+  $1_COMPONENT := \
+      $$(strip $$(foreach root, $$(JTREG_TESTROOTS), \
+        $$(if $$(filter $$(root)%, $$(JTREG_TOPDIR)/$$($1_TEST_NAME)), \
+          $$(lastword $$(subst /, $$(SPACE), $$(root))) \
+        ) \
+      ))
+  # This will work only as long as just hotspot has the additional "jtreg" directory
+  ifeq ($$($1_COMPONENT), jtreg)
+    $1_COMPONENT := hotspot
+  endif
 
   ifeq ($$(JT_HOME), )
     $$(info Error: jtreg framework is not found.)
@@ -317,6 +364,7 @@
   $$(eval $$(call SetJtregValue,$1,JTREG_MAX_MEM,512m))
   $$(eval $$(call SetJtregValue,$1,JTREG_NATIVEPATH))
   $$(eval $$(call SetJtregValue,$1,JTREG_BASIC_OPTIONS))
+  $$(eval $$(call SetJtregValue,$1,JTREG_PROBLEM_LIST))
 
   ifneq ($(TEST_JOBS), 0)
     # User has specified TEST_JOBS, use that as fallback default
@@ -326,11 +374,6 @@
     $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(JOBS)))
   endif
 
-  ifeq ($$(shell $$(EXPR) $$($1_JTREG_JOBS) \> 50), 1)
-    # Until CODETOOLS-7901892 is fixed, JTreg cannot handle more than 50 jobs
-    $1_JTREG_JOBS := 50
-  endif
-
   # Make sure MaxRAMPercentage is high enough to not cause OOM or swapping since
   # we may end up with a lot of JVM's
   $1_JTREG_MAX_RAM_PERCENTAGE := $$(shell $$(EXPR) 25 / $$($1_JTREG_JOBS))
@@ -370,11 +413,18 @@
     $1_JTREG_BASIC_OPTIONS += -nativepath:$$($1_JTREG_NATIVEPATH)
   endif
 
+  ifneq ($$($1_JTREG_PROBLEM_LIST), )
+    $1_JTREG_BASIC_OPTIONS += $$(addprefix -exclude:, $$($1_JTREG_PROBLEM_LIST))
+  endif
+
   ifneq ($$(JIB_JAR), )
     $1_JTREG_BASIC_OPTIONS += -cpa:$$(JIB_JAR)
   endif
 
-  run-test-$1:
+  clean-workdir-$1:
+	$$(RM) -r $$($1_TEST_SUPPORT_DIR)
+
+  run-test-$1: clean-workdir-$1
 	$$(call LogWarn)
 	$$(call LogWarn, Running test '$$($1_TEST)')
 	$$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
@@ -383,7 +433,7 @@
 	        -Dprogram=jtreg -jar $$(JT_HOME)/lib/jtreg.jar \
 	        $$($1_JTREG_BASIC_OPTIONS) \
 	        -testjdk:$$(JDK_IMAGE_DIR) \
-	        -dir:$$(TOPDIR) \
+	        -dir:$$(JTREG_TOPDIR) \
 	        -reportDir:$$($1_TEST_RESULTS_DIR) \
 	        -workDir:$$($1_TEST_SUPPORT_DIR) \
 	        $$(JTREG_OPTIONS) \
@@ -481,12 +531,19 @@
 	$(foreach test, $(TESTS_TO_RUN), \
 	  $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
 	      $(TR) -cs '[a-z][A-Z][0-9]\n' '_')) \
+	  $(eval NAME_PATTERN := $(shell $(ECHO) $(test) | $(TR) -c \\n _)) \
+	  $(if $(filter __________________________________________________%, $(NAME_PATTERN)), \
+	    $(eval TEST_NAME := ) \
+	    $(PRINTF) "%2s %-49s\n" "  " "$(test)"  $(NEWLINE) \
+	  , \
+	    $(eval TEST_NAME := $(test)) \
+	  ) \
 	  $(if $(filter $($(TEST_ID)_PASSED), $($(TEST_ID)_TOTAL)), \
-	    $(PRINTF) "%2s %-49s %5d %5d %5d %5d %2s\n" "  " "$(test)" \
+	    $(PRINTF) "%2s %-49s %5d %5d %5d %5d %2s\n" "  " "$(TEST_NAME)" \
 	        $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) $($(TEST_ID)_FAILED) \
 	        $($(TEST_ID)_ERROR) "  " $(NEWLINE) \
 	  , \
-	    $(PRINTF) "%2s %-49s %5d %5d %5d %5d %2s\n" ">>" "$(test)" \
+	    $(PRINTF) "%2s %-49s %5d %5d %5d %5d %2s\n" ">>" "$(TEST_NAME)" \
 	        $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) $($(TEST_ID)_FAILED) \
 	        $($(TEST_ID)_ERROR) "<<" $(NEWLINE) \
 	    $(eval TEST_FAILURE := true) \
--- a/make/autoconf/configure	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/autoconf/configure	Mon Nov 27 10:35:05 2017 -0800
@@ -90,13 +90,13 @@
 
 check_hg_updates() {
   if test "x`which hg 2> /dev/null | grep -v '^no hg in'`" != x; then
-    conf_updated_autoconf_files=`cd $conf_script_dir && hg status -mard 2> /dev/null | grep autoconf`
+    conf_updated_autoconf_files=`cd $conf_script_dir && hg status -mard . 2> /dev/null`
     if test "x$conf_updated_autoconf_files" != x; then
       echo "Configure source code has been updated, checking time stamps"
       check_autoconf_timestamps
     elif test "x$CUSTOM_CONFIG_DIR" != x; then
       # If custom source configure is available, make sure it is up-to-date as well.
-      conf_custom_updated_autoconf_files=`cd $CUSTOM_CONFIG_DIR && hg status -mard 2> /dev/null | grep autoconf`
+      conf_custom_updated_autoconf_files=`cd $CUSTOM_CONFIG_DIR && hg status -mard . 2> /dev/null`
       if test "x$conf_custom_updated_autoconf_files" != x; then
         echo "Configure custom source code has been updated, checking time stamps"
         check_autoconf_timestamps
--- a/make/autoconf/generated-configure.sh	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/autoconf/generated-configure.sh	Mon Nov 27 10:35:05 2017 -0800
@@ -656,7 +656,6 @@
 ENABLE_INTREE_EC
 VALID_JVM_FEATURES
 JVM_FEATURES_custom
-JVM_FEATURES_zeroshark
 JVM_FEATURES_zero
 JVM_FEATURES_minimal
 JVM_FEATURES_core
@@ -676,10 +675,6 @@
 PNG_CFLAGS
 USE_EXTERNAL_LIBGIF
 USE_EXTERNAL_LIBJPEG
-LLVM_LIBS
-LLVM_LDFLAGS
-LLVM_CFLAGS
-LLVM_CONFIG
 LIBFFI_LIB_FILE
 ENABLE_LIBFFI_BUNDLING
 LIBFFI_LIBS
@@ -1993,6 +1988,7 @@
   --enable-cds[=yes/no]   enable class data sharing feature in non-minimal VM.
                           Default is yes.
   --disable-hotspot-gtest Disables building of the Hotspot unit tests
+                          [enabled]
   --disable-freetype-bundling
                           disable bundling of the freetype library with the
                           build result [enabled on Windows or when using
@@ -2033,8 +2029,7 @@
   --with-debug-level      set the debug level (release, fastdebug, slowdebug,
                           optimized) [release]
   --with-jvm-variants     JVM variants (separated by commas) to build
-                          (server,client,minimal,core,zero,zeroshark,custom)
-                          [server]
+                          (server,client,minimal,core,zero,custom) [server]
   --with-cpu-port         specify sources to use for Hotspot 64-bit ARM port
                           (arm64,aarch64) [aarch64]
   --with-devkit           use this devkit for compilers, tools and resources
@@ -4272,12 +4267,12 @@
 #
 
 # All valid JVM features, regardless of platform
-VALID_JVM_FEATURES="compiler1 compiler2 zero shark minimal dtrace jvmti jvmci \
+VALID_JVM_FEATURES="compiler1 compiler2 zero minimal dtrace jvmti jvmci \
     graal vm-structs jni-check services management all-gcs nmt cds \
     static-build link-time-opt aot"
 
 # All valid JVM variants
-VALID_JVM_VARIANTS="server client minimal core zero zeroshark custom"
+VALID_JVM_VARIANTS="server client minimal core zero custom"
 
 ###############################################################################
 # Check if the specified JVM variant should be built. To be used in shell if
@@ -4308,7 +4303,6 @@
 #   minimal: reduced form of client with optional features stripped out
 #   core: normal interpreter only, no compiler
 #   zero: C++ based interpreter only, no compiler
-#   zeroshark: C++ based interpreter, and a llvm-based compiler
 #   custom: baseline JVM with no default features
 #
 
@@ -4809,11 +4803,6 @@
 
 
 ################################################################################
-# Setup llvm (Low-Level VM)
-################################################################################
-
-
-################################################################################
 # Setup various libraries, typically small system libraries
 ################################################################################
 
@@ -5166,7 +5155,7 @@
 #CUSTOM_AUTOCONF_INCLUDE
 
 # Do not change or remove the following line, it is needed for consistency checks:
-DATE_WHEN_GENERATED=1509128484
+DATE_WHEN_GENERATED=1511359342
 
 ###############################################################################
 #
@@ -17069,7 +17058,7 @@
 
 
 
-  if   [[ " $JVM_VARIANTS " =~ " zero " ]]   ||   [[ " $JVM_VARIANTS " =~ " zeroshark " ]]  ; then
+  if   [[ " $JVM_VARIANTS " =~ " zero " ]]  ; then
     # zero behaves as a platform and rewrites these values. This is really weird. :(
     # We are guaranteed that we do not build any other variants when building zero.
     HOTSPOT_TARGET_CPU=zero
@@ -25114,7 +25103,7 @@
 
   # Should we build the serviceability agent (SA)?
   INCLUDE_SA=true
-  if   [[ " $JVM_VARIANTS " =~ " zero " ]]   ||   [[ " $JVM_VARIANTS " =~ " zeroshark " ]]  ; then
+  if   [[ " $JVM_VARIANTS " =~ " zero " ]]  ; then
     INCLUDE_SA=false
   fi
   if test "x$OPENJDK_TARGET_OS" = xaix ; then
@@ -51971,7 +51960,7 @@
 
 
     fi
-    if !   [[ " $JVM_VARIANTS " =~ " zero " ]]   && !   [[ " $JVM_VARIANTS " =~ " zeroshark " ]]  ; then
+    if !   [[ " $JVM_VARIANTS " =~ " zero " ]]  ; then
       # Non-zero builds have stricter warnings
       JVM_CFLAGS="$JVM_CFLAGS -Wreturn-type -Wundef -Wformat=2"
     else
@@ -52852,7 +52841,7 @@
 
 
     fi
-    if !   [[ " $JVM_VARIANTS " =~ " zero " ]]   && !   [[ " $JVM_VARIANTS " =~ " zeroshark " ]]  ; then
+    if !   [[ " $JVM_VARIANTS " =~ " zero " ]]  ; then
       # Non-zero builds have stricter warnings
       OPENJDK_BUILD_JVM_CFLAGS="$OPENJDK_BUILD_JVM_CFLAGS -Wreturn-type -Wundef -Wformat=2"
     else
@@ -54091,13 +54080,13 @@
 else
 
         if test "x$OPENJDK_TARGET_OS" = xaix; then
-          # AIX doesn't support 'zipped' so use 'internal' as default
+          # AIX doesn't support 'external' so use 'internal' as default
           with_native_debug_symbols="internal"
         else
           if test "x$STATIC_BUILD" = xtrue; then
             with_native_debug_symbols="none"
           else
-            with_native_debug_symbols="zipped"
+            with_native_debug_symbols="external"
           fi
         fi
 
@@ -54613,7 +54602,7 @@
   fi
 
   # Check if ffi is needed
-  if   [[ " $JVM_VARIANTS " =~ " zero " ]]   ||   [[ " $JVM_VARIANTS " =~ " zeroshark " ]]  ; then
+  if   [[ " $JVM_VARIANTS " =~ " zero " ]]  ; then
     NEEDS_LIB_FFI=true
   else
     NEEDS_LIB_FFI=false
@@ -54686,8 +54675,7 @@
     # If dynamic wasn't requested, go with static unless it isn't available.
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libstdc++" >&5
 $as_echo_n "checking how to link with libstdc++... " >&6; }
-    if test "x$with_stdc__lib" = xdynamic || test "x$has_static_libstdcxx" = xno \
-        ||   [[ " $JVM_VARIANTS " =~ " zeroshark " ]]  ; then
+    if test "x$with_stdc__lib" = xdynamic || test "x$has_static_libstdcxx" = xno ; then
       { $as_echo "$as_me:${as_lineno-$LINENO}: result: dynamic" >&5
 $as_echo "dynamic" >&6; }
     else
@@ -65169,94 +65157,6 @@
 
 
 
-  if   [[ " $JVM_VARIANTS " =~ " zeroshark " ]]  ; then
-    # Extract the first word of "llvm-config", so it can be a program name with args.
-set dummy llvm-config; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_LLVM_CONFIG+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$LLVM_CONFIG"; then
-  ac_cv_prog_LLVM_CONFIG="$LLVM_CONFIG" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_LLVM_CONFIG="llvm-config"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-LLVM_CONFIG=$ac_cv_prog_LLVM_CONFIG
-if test -n "$LLVM_CONFIG"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LLVM_CONFIG" >&5
-$as_echo "$LLVM_CONFIG" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-
-    if test "x$LLVM_CONFIG" != xllvm-config; then
-      as_fn_error $? "llvm-config not found in $PATH." "$LINENO" 5
-    fi
-
-    llvm_components="jit mcjit engine nativecodegen native"
-    unset LLVM_CFLAGS
-    for flag in $("$LLVM_CONFIG" --cxxflags); do
-      if echo "${flag}" | grep -q '^-[ID]'; then
-        if test "${flag}" != "-D_DEBUG" ; then
-          if test "${LLVM_CFLAGS}" != "" ; then
-            LLVM_CFLAGS="${LLVM_CFLAGS} "
-          fi
-          LLVM_CFLAGS="${LLVM_CFLAGS}${flag}"
-        fi
-      fi
-    done
-    llvm_version=$("${LLVM_CONFIG}" --version | $SED 's/\.//; s/svn.*//')
-    LLVM_CFLAGS="${LLVM_CFLAGS} -DSHARK_LLVM_VERSION=${llvm_version}"
-
-    unset LLVM_LDFLAGS
-    for flag in $("${LLVM_CONFIG}" --ldflags); do
-      if echo "${flag}" | grep -q '^-L'; then
-        if test "${LLVM_LDFLAGS}" != ""; then
-          LLVM_LDFLAGS="${LLVM_LDFLAGS} "
-        fi
-        LLVM_LDFLAGS="${LLVM_LDFLAGS}${flag}"
-      fi
-    done
-
-    unset LLVM_LIBS
-    for flag in $("${LLVM_CONFIG}" --libs ${llvm_components}); do
-      if echo "${flag}" | grep -q '^-l'; then
-        if test "${LLVM_LIBS}" != ""; then
-          LLVM_LIBS="${LLVM_LIBS} "
-        fi
-        LLVM_LIBS="${LLVM_LIBS}${flag}"
-      fi
-    done
-
-    # Due to https://llvm.org/bugs/show_bug.cgi?id=16902, llvm does not
-    # always properly detect -ltinfo
-    LLVM_LIBS="${LLVM_LIBS} -ltinfo"
-
-
-
-
-  fi
-
-
 
 # Check whether --with-libjpeg was given.
 if test "${with_libjpeg+set}" = set; then :
@@ -66053,7 +65953,6 @@
 
 
 
-
 # Hotspot setup depends on lib checks.
 
 
@@ -66124,15 +66023,9 @@
     fi
   fi
 
-  if !   [[ " $JVM_VARIANTS " =~ " zero " ]]   && !   [[ " $JVM_VARIANTS " =~ " zeroshark " ]]  ; then
+  if !   [[ " $JVM_VARIANTS " =~ " zero " ]]  ; then
     if   [[ " $JVM_FEATURES " =~ " zero " ]]  ; then
-      as_fn_error $? "To enable zero/zeroshark, you must use --with-jvm-variants=zero/zeroshark" "$LINENO" 5
-    fi
-  fi
-
-  if !   [[ " $JVM_VARIANTS " =~ " zeroshark " ]]  ; then
-    if   [[ " $JVM_FEATURES " =~ " shark " ]]  ; then
-      as_fn_error $? "To enable shark, you must use --with-jvm-variants=zeroshark" "$LINENO" 5
+      as_fn_error $? "To enable zero, you must use --with-jvm-variants=zero" "$LINENO" 5
     fi
   fi
 
@@ -66216,7 +66109,6 @@
   JVM_FEATURES_core="$NON_MINIMAL_FEATURES $JVM_FEATURES"
   JVM_FEATURES_minimal="compiler1 minimal $JVM_FEATURES $JVM_FEATURES_link_time_opt"
   JVM_FEATURES_zero="zero $NON_MINIMAL_FEATURES $JVM_FEATURES"
-  JVM_FEATURES_zeroshark="zero shark $NON_MINIMAL_FEATURES $JVM_FEATURES"
   JVM_FEATURES_custom="$JVM_FEATURES"
 
 
@@ -66226,7 +66118,6 @@
 
 
 
-
   # Used for verification of Makefiles by check-jvm-feature
 
 
@@ -68104,7 +67995,6 @@
   JVM_FEATURES_core="$($ECHO $($PRINTF '%s\n' $JVM_FEATURES_core | $SORT -u))"
   JVM_FEATURES_minimal="$($ECHO $($PRINTF '%s\n' $JVM_FEATURES_minimal | $SORT -u))"
   JVM_FEATURES_zero="$($ECHO $($PRINTF '%s\n' $JVM_FEATURES_zero | $SORT -u))"
-  JVM_FEATURES_zeroshark="$($ECHO $($PRINTF '%s\n' $JVM_FEATURES_zeroshark | $SORT -u))"
   JVM_FEATURES_custom="$($ECHO $($PRINTF '%s\n' $JVM_FEATURES_custom | $SORT -u))"
 
   # Validate features
--- a/make/autoconf/hotspot.m4	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/autoconf/hotspot.m4	Mon Nov 27 10:35:05 2017 -0800
@@ -393,7 +393,7 @@
   NON_MINIMAL_FEATURES="$NON_MINIMAL_FEATURES jvmti vm-structs jni-check services management all-gcs nmt"
   if test "x$ENABLE_CDS" = "xtrue"; then
     NON_MINIMAL_FEATURES="$NON_MINIMAL_FEATURES cds"
-  fi                                            
+  fi
 
   # Enable features depending on variant.
   JVM_FEATURES_server="compiler1 compiler2 $NON_MINIMAL_FEATURES $JVM_FEATURES $JVM_FEATURES_jvmci $JVM_FEATURES_aot $JVM_FEATURES_graal"
@@ -476,7 +476,7 @@
 AC_DEFUN_ONCE([HOTSPOT_ENABLE_DISABLE_GTEST],
 [
   AC_ARG_ENABLE([hotspot-gtest], [AS_HELP_STRING([--disable-hotspot-gtest],
-      [Disables building of the Hotspot unit tests])])
+      [Disables building of the Hotspot unit tests @<:@enabled@:>@])])
 
   if test -e "${TOPDIR}/test/hotspot/gtest"; then
     GTEST_DIR_EXISTS="true"
--- a/make/autoconf/jdk-options.m4	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/autoconf/jdk-options.m4	Mon Nov 27 10:35:05 2017 -0800
@@ -296,13 +296,13 @@
       ],
       [
         if test "x$OPENJDK_TARGET_OS" = xaix; then
-          # AIX doesn't support 'zipped' so use 'internal' as default
+          # AIX doesn't support 'external' so use 'internal' as default
           with_native_debug_symbols="internal"
         else
           if test "x$STATIC_BUILD" = xtrue; then
             with_native_debug_symbols="none"
           else
-            with_native_debug_symbols="zipped"
+            with_native_debug_symbols="external"
           fi
         fi
       ])
--- a/make/common/FindTests.gmk	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/common/FindTests.gmk	Mon Nov 27 10:35:05 2017 -0800
@@ -29,6 +29,9 @@
 # Hook to include the corresponding custom file, if present.
 $(eval $(call IncludeCustomExtension, common/FindTests.gmk))
 
+# TEST_BASEDIRS might have been set by a custom extension
+TEST_BASEDIRS += $(TOPDIR)/test $(TOPDIR)
+
 # JTREG_TESTROOTS might have been set by a custom extension
 JTREG_TESTROOTS += $(addprefix $(TOPDIR)/test/, hotspot/jtreg jdk langtools nashorn jaxp)
 
--- a/make/common/Modules.gmk	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/common/Modules.gmk	Mon Nov 27 10:35:05 2017 -0800
@@ -328,8 +328,9 @@
 	      $(NAWK) -v MODULE=$(call GetModuleNameFromModuleInfo, $m) '\
 	          BEGIN      { if (MODULE != "java.base") printf(" java.base"); } \
 	          /^ *requires/ { sub(/;/, ""); \
-	                          sub(/requires/, ""); \
-	                          sub(/transitive/, ""); \
+	                          sub(/requires /, " "); \
+	                          sub(/ static /, " "); \
+	                          sub(/ transitive /, " "); \
 	                          sub(/\/\/.*/, ""); \
 	                          sub(/\/\*.*\*\//, ""); \
 	                          gsub(/^ +\*.*/, ""); \
--- a/make/conf/jib-profiles.js	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/conf/jib-profiles.js	Mon Nov 27 10:35:05 2017 -0800
@@ -203,7 +203,7 @@
     data.src_bundle_excludes = "./build webrev* */webrev* */*/webrev* */*/*/webrev* .hg */.hg */*/.hg */*/*/.hg";
     // Include list to use when creating a minimal jib source bundle which
     // contains just the jib configuration files.
-    data.conf_bundle_includes = "*/conf/jib-profiles.* common/autoconf/version-numbers"
+    data.conf_bundle_includes = "*/conf/jib-profiles.* make/autoconf/version-numbers"
 
     // Define some common values
     var common = getJibProfilesCommon(input, data);
@@ -1043,7 +1043,7 @@
 
 /**
  * Constructs the numeric version string from reading the
- * common/autoconf/version-numbers file and removing all trailing ".0".
+ * make/autoconf/version-numbers file and removing all trailing ".0".
  *
  * @param major Override major version
  * @param minor Override minor version
@@ -1080,17 +1080,17 @@
     return args;
 }
 
-// Properties representation of the common/autoconf/version-numbers file. Lazily
+// Properties representation of the make/autoconf/version-numbers file. Lazily
 // initiated by the function below.
 var version_numbers;
 
 /**
- * Read the common/autoconf/version-numbers file into a Properties object.
+ * Read the make/autoconf/version-numbers file into a Properties object.
  *
  * @returns {java.utilProperties}
  */
 var getVersionNumbers = function () {
-    // Read version information from common/autoconf/version-numbers
+    // Read version information from make/autoconf/version-numbers
     if (version_numbers == null) {
         version_numbers = new java.util.Properties();
         var stream = new java.io.FileInputStream(__DIR__ + "/../autoconf/version-numbers");
--- a/make/data/lsrdata/language-subtag-registry.txt	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/data/lsrdata/language-subtag-registry.txt	Mon Nov 27 10:35:05 2017 -0800
@@ -1,4 +1,4 @@
-File-Date: 2016-02-10
+File-Date: 2017-08-15
 %%
 Type: language
 Subtag: aa
@@ -106,6 +106,7 @@
 Type: language
 Subtag: bn
 Description: Bengali
+Description: Bangla
 Added: 2005-10-16
 Suppress-Script: Beng
 %%
@@ -792,6 +793,7 @@
 Type: language
 Subtag: or
 Description: Oriya (macrolanguage)
+Description: Odia (macrolanguage)
 Added: 2005-10-16
 Suppress-Script: Orya
 Scope: macrolanguage
@@ -4107,7 +4109,7 @@
 %%
 Type: language
 Subtag: bcg
-Description: Baga Binari
+Description: Baga Pokur
 Added: 2009-07-29
 %%
 Type: language
@@ -4641,6 +4643,8 @@
 Subtag: bgm
 Description: Baga Mboteni
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: bcg
 %%
 Type: language
 Subtag: bgn
@@ -5330,6 +5334,7 @@
 %%
 Type: language
 Subtag: blv
+Description: Kibala
 Description: Bolo
 Added: 2009-07-29
 %%
@@ -5380,7 +5385,7 @@
 %%
 Type: language
 Subtag: bmf
-Description: Bom
+Description: Bom-Kim
 Added: 2009-07-29
 %%
 Type: language
@@ -6281,6 +6286,7 @@
 Subtag: btl
 Description: Bhatola
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: btm
@@ -7268,6 +7274,7 @@
 Subtag: cbe
 Description: Chipiajes
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: cbg
@@ -7278,6 +7285,7 @@
 Subtag: cbh
 Description: Cagua
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: cbi
@@ -8071,6 +8079,7 @@
 %%
 Type: language
 Subtag: cnh
+Description: Hakha Chin
 Description: Haka Chin
 Added: 2009-07-29
 %%
@@ -8230,6 +8239,8 @@
 Subtag: coy
 Description: Coyaima
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: pij
 %%
 Type: language
 Subtag: coz
@@ -8320,6 +8331,8 @@
 Subtag: cqu
 Description: Chilean Quechua
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: quh
 Macrolanguage: qu
 %%
 Type: language
@@ -8666,6 +8679,7 @@
 %%
 Type: language
 Subtag: cug
+Description: Chungmboko
 Description: Cung
 Added: 2009-07-29
 %%
@@ -8700,6 +8714,7 @@
 Subtag: cum
 Description: Cumeral
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: cuo
@@ -9320,6 +9335,7 @@
 %%
 Type: language
 Subtag: dhg
+Description: Dhangu-Djangu
 Description: Dhangu
 Description: Djangu
 Added: 2009-07-29
@@ -9958,7 +9974,7 @@
 %%
 Type: language
 Subtag: dri
-Description: C'lela
+Description: C'Lela
 Added: 2009-07-29
 %%
 Type: language
@@ -10090,12 +10106,18 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: dtn
+Description: Daatsʼíin
+Added: 2016-05-30
+%%
+Type: language
 Subtag: dto
 Description: Tommo So Dogon
 Added: 2012-08-12
 %%
 Type: language
 Subtag: dtp
+Description: Kadazan Dusun
 Description: Central Dusun
 Added: 2009-07-29
 %%
@@ -10176,6 +10198,8 @@
 Subtag: duj
 Description: Dhuwal
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Comments: see dwu, dwy
 %%
 Type: language
 Subtag: duk
@@ -10250,7 +10274,7 @@
 %%
 Type: language
 Subtag: duz
-Description: Duli
+Description: Duli-Gey
 Added: 2009-07-29
 %%
 Type: language
@@ -10281,11 +10305,21 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: dwu
+Description: Dhuwal
+Added: 2016-05-30
+%%
+Type: language
 Subtag: dww
 Description: Dawawa
 Added: 2009-07-29
 %%
 Type: language
+Subtag: dwy
+Description: Dhuwaya
+Added: 2016-05-30
+%%
+Type: language
 Subtag: dya
 Description: Dyan
 Added: 2009-07-29
@@ -10818,6 +10852,12 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: esg
+Description: Aheri Gondi
+Added: 2016-05-30
+Macrolanguage: gon
+%%
+Type: language
 Subtag: esh
 Description: Eshtehardi
 Added: 2009-07-29
@@ -11214,6 +11254,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: fnb
+Description: Fanbak
+Added: 2016-05-30
+%%
+Type: language
 Subtag: fng
 Description: Fanagalo
 Added: 2009-07-29
@@ -11898,7 +11943,7 @@
 %%
 Type: language
 Subtag: gek
-Description: Yiwom
+Description: Ywom
 Added: 2009-07-29
 %%
 Type: language
@@ -12003,12 +12048,15 @@
 Subtag: ggn
 Description: Eastern Gurung
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: gvr
 %%
 Type: language
 Subtag: ggo
 Description: Southern Gondi
 Added: 2009-07-29
-Macrolanguage: gon
+Deprecated: 2016-05-30
+Comments: see esg, wsg
 %%
 Type: language
 Subtag: ggr
@@ -12110,6 +12158,12 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: gie
+Description: Gaɓogbo
+Description: Guébie
+Added: 2017-02-23
+%%
+Type: language
 Subtag: gig
 Description: Goaria
 Added: 2009-07-29
@@ -12212,6 +12266,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: gjr
+Description: Gurindji Kriol
+Added: 2016-05-30
+%%
+Type: language
 Subtag: gju
 Description: Gujari
 Added: 2009-07-29
@@ -12791,6 +12850,7 @@
 %%
 Type: language
 Subtag: gsn
+Description: Nema
 Description: Gusan
 Added: 2009-07-29
 %%
@@ -12942,6 +13002,8 @@
 Subtag: guv
 Description: Gey
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: duz
 %%
 Type: language
 Subtag: guw
@@ -13011,7 +13073,7 @@
 %%
 Type: language
 Subtag: gvr
-Description: Western Gurung
+Description: Gurung
 Added: 2009-07-29
 %%
 Type: language
@@ -14195,6 +14257,7 @@
 Subtag: iap
 Description: Iapama
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: iar
@@ -14227,6 +14290,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: ibh
+Description: Bih
+Added: 2017-02-23
+%%
+Type: language
 Subtag: ibi
 Description: Ibilo
 Added: 2009-07-29
@@ -14581,6 +14649,13 @@
 Subtag: ill
 Description: Iranun
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Comments: see ilm, ilp
+%%
+Type: language
+Subtag: ilm
+Description: Iranun (Malaysia)
+Added: 2016-05-30
 %%
 Type: language
 Subtag: ilo
@@ -14588,6 +14663,11 @@
 Added: 2005-10-16
 %%
 Type: language
+Subtag: ilp
+Description: Iranun (Philippines)
+Added: 2016-05-30
+%%
+Type: language
 Subtag: ils
 Description: International Sign
 Added: 2009-07-29
@@ -14901,6 +14981,11 @@
 Scope: collection
 %%
 Type: language
+Subtag: itd
+Description: Southern Tidung
+Added: 2016-05-30
+%%
+Type: language
 Subtag: ite
 Description: Itene
 Added: 2009-07-29
@@ -15252,6 +15337,8 @@
 Subtag: jeg
 Description: Jeng
 Added: 2009-07-29
+Deprecated: 2017-02-23
+Preferred-Value: oyb
 %%
 Type: language
 Subtag: jeh
@@ -15416,6 +15503,11 @@
 Added: 2012-08-12
 %%
 Type: language
+Subtag: jka
+Description: Kaera
+Added: 2016-05-30
+%%
+Type: language
 Subtag: jkm
 Description: Mobwa Karen
 Added: 2012-08-12
@@ -15796,6 +15888,7 @@
 %%
 Type: language
 Subtag: kak
+Description: Kalanguya
 Description: Kayapa Kallahan
 Added: 2009-07-29
 %%
@@ -16450,7 +16543,8 @@
 %%
 Type: language
 Subtag: kfr
-Description: Kachchi
+Description: Kachhi
+Description: Kutchi
 Added: 2009-07-29
 %%
 Type: language
@@ -16507,11 +16601,15 @@
 Subtag: kgc
 Description: Kasseng
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: tdf
 %%
 Type: language
 Subtag: kgd
 Description: Kataang
 Added: 2009-07-29
+Deprecated: 2017-02-23
+Comments: see ncq, sct
 %%
 Type: language
 Subtag: kge
@@ -17238,6 +17336,7 @@
 %%
 Type: language
 Subtag: klw
+Description: Tado
 Description: Lindu
 Added: 2009-07-29
 %%
@@ -17621,6 +17720,7 @@
 Subtag: kox
 Description: Coxima
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: koy
@@ -17955,6 +18055,8 @@
 Subtag: krm
 Description: Krim
 Added: 2009-07-29
+Deprecated: 2017-02-23
+Preferred-Value: bmf
 %%
 Type: language
 Subtag: krn
@@ -17974,7 +18076,7 @@
 %%
 Type: language
 Subtag: krr
-Description: Kru'ng 2
+Description: Krung
 Added: 2009-07-29
 %%
 Type: language
@@ -18238,6 +18340,8 @@
 Subtag: ktr
 Description: Kota Marudu Tinagas
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: dtp
 %%
 Type: language
 Subtag: kts
@@ -18278,6 +18382,7 @@
 Subtag: ktz
 Description: Ju/'hoan
 Description: Juǀʼhoan
+Description: Juǀʼhoansi
 Added: 2009-07-29
 %%
 Type: language
@@ -18496,6 +18601,8 @@
 Subtag: kvs
 Description: Kunggara
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: gdj
 %%
 Type: language
 Subtag: kvt
@@ -18979,6 +19086,8 @@
 Subtag: kzj
 Description: Coastal Kadazan
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: dtp
 %%
 Type: language
 Subtag: kzk
@@ -19029,6 +19138,8 @@
 Subtag: kzt
 Description: Tambunan Dusun
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: dtp
 %%
 Type: language
 Subtag: kzu
@@ -19306,6 +19417,7 @@
 Type: language
 Subtag: lce
 Description: Loncong
+Description: Sekak
 Added: 2009-07-29
 Macrolanguage: ms
 %%
@@ -19602,6 +19714,7 @@
 %%
 Type: language
 Subtag: lgn
+Description: T'apo
 Description: Opuuo
 Added: 2009-07-29
 %%
@@ -20320,7 +20433,7 @@
 %%
 Type: language
 Subtag: lou
-Description: Louisiana Creole French
+Description: Louisiana Creole
 Added: 2009-07-29
 %%
 Type: language
@@ -20532,6 +20645,11 @@
 Macrolanguage: lv
 %%
 Type: language
+Subtag: lth
+Description: Thur
+Added: 2017-02-23
+%%
+Type: language
 Subtag: lti
 Description: Leti (Indonesia)
 Added: 2009-07-29
@@ -21926,6 +22044,11 @@
 Deprecated: 2011-08-16
 %%
 Type: language
+Subtag: mjb
+Description: Makalero
+Added: 2016-05-30
+%%
+Type: language
 Subtag: mjc
 Description: San Juan Colorado Mixtec
 Added: 2009-07-29
@@ -24093,6 +24216,8 @@
 Subtag: nad
 Description: Nijadali
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: xny
 %%
 Type: language
 Subtag: nae
@@ -24404,6 +24529,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: ncq
+Description: Northern Katang
+Added: 2017-02-23
+%%
+Type: language
 Subtag: ncr
 Description: Ncane
 Added: 2009-07-29
@@ -24802,6 +24932,7 @@
 %%
 Type: language
 Subtag: ngt
+Description: Kriang
 Description: Ngeq
 Added: 2009-07-29
 %%
@@ -25810,6 +25941,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: npx
+Description: Noipx
+Added: 2017-02-23
+%%
+Type: language
 Subtag: npy
 Description: Napu
 Added: 2009-07-29
@@ -25825,6 +25961,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: nql
+Description: Ngendelengo
+Added: 2017-02-23
+%%
+Type: language
 Subtag: nqm
 Description: Ndom
 Added: 2009-07-29
@@ -26062,6 +26203,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: ntd
+Description: Northern Tidung
+Added: 2016-05-30
+%%
+Type: language
 Subtag: nte
 Description: Nathembo
 Added: 2009-07-29
@@ -26110,6 +26256,8 @@
 Subtag: nts
 Description: Natagaimas
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: pij
 %%
 Type: language
 Subtag: ntu
@@ -26918,6 +27066,11 @@
 Added: 2014-02-28
 %%
 Type: language
+Subtag: olu
+Description: Kuvale
+Added: 2016-05-30
+%%
+Type: language
 Subtag: oma
 Description: Omaha-Ponca
 Added: 2009-07-29
@@ -26936,6 +27089,7 @@
 Subtag: ome
 Description: Omejes
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: omg
@@ -27219,6 +27373,7 @@
 %%
 Type: language
 Subtag: ory
+Description: Odia (individual language)
 Description: Oriya (individual language)
 Added: 2012-08-12
 Macrolanguage: or
@@ -27398,6 +27553,12 @@
 Preferred-Value: vaj
 %%
 Type: language
+Subtag: ovd
+Description: Elfdalian
+Description: Övdalian
+Added: 2016-06-16
+%%
+Type: language
 Subtag: owi
 Description: Owiniga
 Added: 2009-07-29
@@ -27941,6 +28102,11 @@
 Deprecated: 2012-08-12
 %%
 Type: language
+Subtag: pgz
+Description: Papua New Guinean Sign Language
+Added: 2016-05-30
+%%
+Type: language
 Subtag: pha
 Description: Pa-Hng
 Added: 2009-07-29
@@ -28343,6 +28509,8 @@
 Subtag: pmc
 Description: Palumata
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: huw
 %%
 Type: language
 Subtag: pmd
@@ -28580,6 +28748,7 @@
 Subtag: pod
 Description: Ponares
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: poe
@@ -28676,6 +28845,8 @@
 Subtag: ppa
 Description: Pao
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: bfy
 %%
 Type: language
 Subtag: ppe
@@ -28777,6 +28948,7 @@
 Subtag: prb
 Description: Lua'
 Added: 2009-07-29
+Deprecated: 2017-02-23
 %%
 Type: language
 Subtag: prc
@@ -28885,6 +29057,8 @@
 Subtag: pry
 Description: Pray 3
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: prt
 %%
 Type: language
 Subtag: prz
@@ -29104,6 +29278,7 @@
 Subtag: puk
 Description: Pu Ko
 Added: 2009-07-29
+Deprecated: 2017-02-23
 %%
 Type: language
 Subtag: pum
@@ -29874,6 +30049,7 @@
 Subtag: rie
 Description: Rien
 Added: 2009-07-29
+Deprecated: 2017-02-23
 %%
 Type: language
 Subtag: rif
@@ -30099,6 +30275,7 @@
 Subtag: rna
 Description: Runa
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: rnd
@@ -30241,6 +30418,7 @@
 Subtag: rsi
 Description: Rennellese Sign Language
 Added: 2009-07-29
+Deprecated: 2017-02-23
 %%
 Type: language
 Subtag: rsl
@@ -30248,6 +30426,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: rsm
+Description: Miriwoong Sign Language
+Added: 2016-05-30
+%%
+Type: language
 Subtag: rtc
 Description: Rungtu Chin
 Added: 2012-08-12
@@ -30401,6 +30584,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: rzh
+Description: Rāziḥī
+Added: 2016-05-30
+%%
+Type: language
 Subtag: saa
 Description: Saba
 Added: 2009-07-29
@@ -30729,6 +30917,11 @@
 Macrolanguage: den
 %%
 Type: language
+Subtag: sct
+Description: Southern Katang
+Added: 2017-02-23
+%%
+Type: language
 Subtag: scu
 Description: Shumcho
 Added: 2009-07-29
@@ -31515,6 +31708,8 @@
 Subtag: skk
 Description: Sok
 Added: 2009-07-29
+Deprecated: 2017-02-23
+Preferred-Value: oyb
 %%
 Type: language
 Subtag: skm
@@ -31849,6 +32044,7 @@
 Subtag: snh
 Description: Shinabo
 Added: 2009-07-29
+Deprecated: 2017-02-23
 %%
 Type: language
 Subtag: sni
@@ -32710,6 +32906,7 @@
 Subtag: svr
 Description: Savara
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: svs
@@ -33023,6 +33220,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: szs
+Description: Solomon Islands Sign Language
+Added: 2017-02-23
+%%
+Type: language
 Subtag: szv
 Description: Isu (Fako Division)
 Added: 2009-07-29
@@ -33458,6 +33660,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: tdm
+Description: Taruma
+Added: 2016-05-30
+%%
+Type: language
 Subtag: tdn
 Description: Tondano
 Added: 2009-07-29
@@ -33491,6 +33698,8 @@
 Subtag: tdu
 Description: Tempasuk Dusun
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: dtp
 %%
 Type: language
 Subtag: tdv
@@ -33771,6 +33980,8 @@
 Subtag: thc
 Description: Tai Hang Tong
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: tpo
 %%
 Type: language
 Subtag: thd
@@ -33891,6 +34102,8 @@
 Subtag: tid
 Description: Tidong
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Comments: see itd, ntd
 %%
 Type: language
 Subtag: tie
@@ -34246,6 +34459,7 @@
 %%
 Type: language
 Subtag: tlt
+Description: Sou Nama
 Description: Teluti
 Added: 2009-07-29
 %%
@@ -34358,6 +34572,8 @@
 Subtag: tmp
 Description: Tai Mène
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: tyj
 %%
 Type: language
 Subtag: tmq
@@ -34429,6 +34645,8 @@
 Subtag: tne
 Description: Tinoc Kallahan
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: kak
 %%
 Type: language
 Subtag: tnf
@@ -34529,7 +34747,7 @@
 %%
 Type: language
 Subtag: tnz
-Description: Tonga (Thailand)
+Description: Ten'edn
 Added: 2009-07-29
 %%
 Type: language
@@ -34551,6 +34769,7 @@
 Subtag: toe
 Description: Tomedes
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: tof
@@ -35596,6 +35815,7 @@
 Type: language
 Subtag: tyj
 Description: Tai Do
+Description: Tai Yo
 Added: 2009-07-29
 %%
 Type: language
@@ -35855,6 +36075,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: ukk
+Description: Muak Sa-aak
+Added: 2017-02-23
+%%
+Type: language
 Subtag: ukl
 Description: Ukrainian Sign Language
 Added: 2009-07-29
@@ -36989,6 +37214,11 @@
 Macrolanguage: raj
 %%
 Type: language
+Subtag: wbs
+Description: West Bengal Sign Language
+Added: 2017-02-23
+%%
+Type: language
 Subtag: wbt
 Description: Wanman
 Added: 2009-07-29
@@ -37169,6 +37399,7 @@
 %%
 Type: language
 Subtag: wha
+Description: Sou Upaa
 Description: Manusela
 Added: 2009-07-29
 %%
@@ -37739,6 +37970,12 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: wsg
+Description: Adilabad Gondi
+Added: 2016-05-30
+Macrolanguage: gon
+%%
+Type: language
 Subtag: wsi
 Description: Wusi
 Added: 2009-07-29
@@ -37971,6 +38208,11 @@
 Added: 2014-02-28
 %%
 Type: language
+Subtag: xak
+Description: Máku
+Added: 2016-05-30
+%%
+Type: language
 Subtag: xal
 Description: Kalmyk
 Description: Oirat
@@ -38041,6 +38283,8 @@
 Subtag: xba
 Description: Kamba (Brazil)
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: cax
 %%
 Type: language
 Subtag: xbb
@@ -38111,6 +38355,7 @@
 Subtag: xbx
 Description: Kabixí
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: xby
@@ -38214,6 +38459,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: xdo
+Description: Kwandu
+Added: 2017-02-23
+%%
+Type: language
 Subtag: xdy
 Description: Malayic Dayak
 Added: 2009-07-29
@@ -38408,6 +38658,7 @@
 Subtag: xip
 Description: Xipináwa
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: xir
@@ -38478,6 +38729,8 @@
 Subtag: xkh
 Description: Karahawyana
 Added: 2009-07-29
+Deprecated: 2016-05-30
+Preferred-Value: waw
 %%
 Type: language
 Subtag: xki
@@ -39328,6 +39581,7 @@
 Type: language
 Subtag: xuu
 Description: Kxoe
+Description: Khwedam
 Added: 2009-07-29
 %%
 Type: language
@@ -40394,6 +40648,7 @@
 Subtag: yri
 Description: Yarí
 Added: 2009-07-29
+Deprecated: 2016-05-30
 %%
 Type: language
 Subtag: yrk
@@ -40416,6 +40671,11 @@
 Added: 2009-07-29
 %%
 Type: language
+Subtag: yro
+Description: Yaroamë
+Added: 2016-05-30
+%%
+Type: language
 Subtag: yrs
 Description: Yarsun
 Added: 2009-07-29
@@ -40740,6 +41000,7 @@
 %%
 Type: language
 Subtag: zab
+Description: Western Tlacolula Valley Zapotec
 Description: San Juan Guelavía Zapotec
 Added: 2009-07-29
 Macrolanguage: zap
@@ -42633,6 +42894,7 @@
 Type: extlang
 Subtag: lce
 Description: Loncong
+Description: Sekak
 Added: 2009-07-29
 Preferred-Value: lce
 Prefix: ms
@@ -42953,6 +43215,13 @@
 Macrolanguage: ar
 %%
 Type: extlang
+Subtag: pgz
+Description: Papua New Guinean Sign Language
+Added: 2016-05-30
+Preferred-Value: pgz
+Prefix: sgn
+%%
+Type: extlang
 Subtag: pks
 Description: Pakistan Sign Language
 Added: 2009-07-29
@@ -43049,7 +43318,7 @@
 Subtag: rsi
 Description: Rennellese Sign Language
 Added: 2009-07-29
-Preferred-Value: rsi
+Deprecated: 2017-02-23
 Prefix: sgn
 %%
 Type: extlang
@@ -43060,6 +43329,13 @@
 Prefix: sgn
 %%
 Type: extlang
+Subtag: rsm
+Description: Miriwoong Sign Language
+Added: 2016-05-30
+Preferred-Value: rsm
+Prefix: sgn
+%%
+Type: extlang
 Subtag: sdl
 Description: Saudi Arabian Sign Language
 Added: 2009-07-29
@@ -43192,6 +43468,13 @@
 Prefix: sgn
 %%
 Type: extlang
+Subtag: szs
+Description: Solomon Islands Sign Language
+Added: 2017-02-23
+Preferred-Value: szs
+Prefix: sgn
+%%
+Type: extlang
 Subtag: tmw
 Description: Temuan
 Added: 2009-07-29
@@ -43342,6 +43625,13 @@
 Prefix: sgn
 %%
 Type: extlang
+Subtag: wbs
+Description: West Bengal Sign Language
+Added: 2017-02-23
+Preferred-Value: wbs
+Prefix: sgn
+%%
+Type: extlang
 Subtag: wuu
 Description: Wu Chinese
 Added: 2009-07-29
@@ -43522,6 +43812,7 @@
 Type: script
 Subtag: Beng
 Description: Bengali
+Description: Bangla
 Added: 2005-10-16
 %%
 Type: script
@@ -43595,8 +43886,13 @@
 Added: 2005-10-16
 %%
 Type: script
+Subtag: Cpmn
+Description: Cypro-Minoan
+Added: 2017-08-13
+%%
+Type: script
 Subtag: Cprt
-Description: Cypriot
+Description: Cypriot syllabary
 Added: 2005-10-16
 %%
 Type: script
@@ -43616,6 +43912,11 @@
 Added: 2005-10-16
 %%
 Type: script
+Subtag: Dogr
+Description: Dogra
+Added: 2017-01-13
+%%
+Type: script
 Subtag: Dsrt
 Description: Deseret
 Description: Mormon
@@ -43661,7 +43962,7 @@
 %%
 Type: script
 Subtag: Geor
-Description: Georgian (Mkhedruli)
+Description: Georgian (Mkhedruli and Mtavruli)
 Added: 2005-10-16
 %%
 Type: script
@@ -43670,6 +43971,16 @@
 Added: 2005-10-16
 %%
 Type: script
+Subtag: Gong
+Description: Gunjala Gondi
+Added: 2017-01-13
+%%
+Type: script
+Subtag: Gonm
+Description: Masaram Gondi
+Added: 2017-01-13
+%%
+Type: script
 Subtag: Goth
 Description: Gothic
 Added: 2005-10-16
@@ -43758,6 +44069,11 @@
 Added: 2005-10-16
 %%
 Type: script
+Subtag: Hmnp
+Description: Nyiakeng Puachue Hmong
+Added: 2017-08-13
+%%
+Type: script
 Subtag: Hrkt
 Description: Japanese syllabaries (alias for Hiragana + Katakana)
 Added: 2005-10-16
@@ -43933,6 +44249,11 @@
 Added: 2012-11-01
 %%
 Type: script
+Subtag: Maka
+Description: Makasar
+Added: 2017-01-13
+%%
+Type: script
 Subtag: Mand
 Description: Mandaic
 Description: Mandaean
@@ -43954,6 +44275,13 @@
 Added: 2005-10-16
 %%
 Type: script
+Subtag: Medf
+Description: Medefaidrin
+Description: Oberi Okaime
+Description: Oberi Ɔkaimɛ
+Added: 2017-01-13
+%%
+Type: script
 Subtag: Mend
 Description: Mende Kikakui
 Added: 2010-04-10
@@ -44036,10 +44364,18 @@
 Added: 2016-01-04
 %%
 Type: script
+Subtag: Nkdb
+Description: Naxi Dongba
+Description: na²¹ɕi³³ to³³ba²¹
+Description: Nakhi Tomba
+Added: 2017-08-13
+%%
+Type: script
 Subtag: Nkgb
+Description: Naxi Geba
+Description: na²¹ɕi³³ gʌ²¹ba²¹
+Description: 'Na-'Khi ²Ggŏ-¹baw
 Description: Nakhi Geba
-Description: 'Na-'Khi ²Ggŏ-¹baw
-Description: Naxi Geba
 Added: 2009-03-13
 %%
 Type: script
@@ -44075,6 +44411,7 @@
 Type: script
 Subtag: Orya
 Description: Oriya
+Description: Odia
 Added: 2005-10-16
 %%
 Type: script
@@ -44203,6 +44540,11 @@
 Added: 2011-01-07
 %%
 Type: script
+Subtag: Shui
+Description: Shuishu
+Added: 2017-08-13
+%%
+Type: script
 Subtag: Sidd
 Description: Siddham
 Description: Siddhaṃ
@@ -44226,6 +44568,11 @@
 Added: 2011-01-07
 %%
 Type: script
+Subtag: Soyo
+Description: Soyombo
+Added: 2017-01-13
+%%
+Type: script
 Subtag: Sund
 Description: Sundanese
 Added: 2006-07-21
@@ -44357,6 +44704,11 @@
 Added: 2009-12-09
 %%
 Type: script
+Subtag: Wcho
+Description: Wancho
+Added: 2017-08-13
+%%
+Type: script
 Subtag: Wole
 Description: Woleai
 Added: 2011-01-07
@@ -44377,6 +44729,14 @@
 Added: 2005-10-16
 %%
 Type: script
+Subtag: Zanb
+Description: Zanabazar Square
+Description: Zanabazarin Dörböljin Useg
+Description: Xewtee Dörböljin Bicig
+Description: Horizontal Square Script
+Added: 2017-01-13
+%%
+Type: script
 Subtag: Zinh
 Description: Code for inherited script
 Added: 2009-04-03
@@ -44726,6 +45086,7 @@
 %%
 Type: region
 Subtag: CZ
+Description: Czechia
 Description: Czech Republic
 Added: 2005-10-16
 %%
@@ -44817,6 +45178,11 @@
 Added: 2009-07-29
 %%
 Type: region
+Subtag: EZ
+Description: Eurozone
+Added: 2016-07-14
+%%
+Type: region
 Subtag: FI
 Description: Finland
 Added: 2005-10-16
@@ -45675,6 +46041,11 @@
 Added: 2005-10-16
 %%
 Type: region
+Subtag: UN
+Description: United Nations
+Added: 2016-07-14
+%%
+Type: region
 Subtag: US
 Description: United States
 Added: 2005-10-16
@@ -45940,6 +46311,11 @@
 Added: 2005-10-16
 %%
 Type: region
+Subtag: 202
+Description: Sub-Saharan Africa
+Added: 2017-04-18
+%%
+Type: region
 Subtag: 419
 Description: Latin America and the Caribbean
 Added: 2005-10-16
@@ -46020,6 +46396,12 @@
   continuum in Eastern Suriname and Western French Guiana
 %%
 Type: variant
+Subtag: akuapem
+Description: Akuapem Twi
+Added: 2017-06-05
+Prefix: tw
+%%
+Type: variant
 Subtag: ao1990
 Description: Portuguese Language Orthographic Agreement of 1990 (Acordo
   Ortográfico da Língua Portuguesa de 1990)
@@ -46042,6 +46424,13 @@
 Prefix: hy
 %%
 Type: variant
+Subtag: asante
+Description: Asante Twi
+Description: Ashanti Twi
+Added: 2017-06-05
+Prefix: tw
+%%
+Type: variant
 Subtag: baku1926
 Description: Unified Turkic Latin Alphabet (Historical)
 Added: 2007-04-18
@@ -46167,6 +46556,12 @@
 Added: 2006-12-11
 %%
 Type: variant
+Subtag: fonnapa
+Description: North American Phonetic Alphabet
+Description: Americanist Phonetic Notation
+Added: 2016-06-24
+%%
+Type: variant
 Subtag: fonupa
 Description: Uralic Phonetic Alphabet
 Added: 2006-12-11
@@ -46201,6 +46596,13 @@
   including modern usage.
 %%
 Type: variant
+Subtag: hsistemo
+Description: Standard H-system orthographic fallback for spelling
+  Esperanto
+Added: 2017-03-14
+Prefix: eo
+%%
+Type: variant
 Subtag: ijekavsk
 Description: Serbian with Ijekavian pronunciation
 Prefix: sr
@@ -46346,6 +46748,27 @@
 Prefix: en
 %%
 Type: variant
+Subtag: pahawh2
+Description: Pahawh Hmong Second Stage Reduced orthography
+Added: 2017-01-13
+Prefix: mww
+Prefix: hnj
+%%
+Type: variant
+Subtag: pahawh3
+Description: Pahawh Hmong Third Stage Reduced orthography
+Added: 2017-01-13
+Prefix: mww
+Prefix: hnj
+%%
+Type: variant
+Subtag: pahawh4
+Description: Pahawh Hmong Final Version orthography
+Added: 2017-01-13
+Prefix: mww
+Prefix: hnj
+%%
+Type: variant
 Subtag: pamaka
 Description: Pamaka dialect
 Added: 2009-09-05
@@ -46442,6 +46865,14 @@
 Added: 2013-12-10
 %%
 Type: variant
+Subtag: spanglis
+Description: Spanglish
+Added: 2017-02-23
+Prefix: en
+Prefix: es
+Comments: A variety of contact dialects of English and Spanish
+%%
+Type: variant
 Subtag: surmiran
 Description: Surmiran idiom of Romansh
 Added: 2010-06-29
@@ -46533,6 +46964,13 @@
 Added: 2008-10-03
 Prefix: zh-Latn
 %%
+Type: variant
+Subtag: xsistemo
+Description: Standard X-system orthographic fallback for spelling
+  Esperanto
+Added: 2017-03-14
+Prefix: eo
+%%
 Type: grandfathered
 Tag: art-lojban
 Description: Lojban
--- a/make/hotspot/lib/CompileJvm.gmk	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/hotspot/lib/CompileJvm.gmk	Mon Nov 27 10:35:05 2017 -0800
@@ -112,7 +112,7 @@
     #
 
 # These files and directories are always excluded
-JVM_EXCLUDE_FILES += jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp args.cc
+JVM_EXCLUDE_FILES += jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp args.cc
 JVM_EXCLUDES += adlc
 
 # Needed by vm_version.cpp
--- a/make/hotspot/lib/CompileLibjsig.gmk	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/hotspot/lib/CompileLibjsig.gmk	Mon Nov 27 10:35:05 2017 -0800
@@ -81,7 +81,7 @@
       $(error Unknown target OS $(OPENJDK_TARGET_OS) in CompileLibjsig.gmk)
     endif
 
-    LIBJSIG_SRC_FILE := $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libjsig/jsig.c
+    LIBJSIG_SRC_DIR := $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libjsig
     LIBJSIG_MAPFILE := $(wildcard $(TOPDIR)/make/mapfiles/libjsig/mapfile-vers-$(OPENJDK_TARGET_OS))
     LIBJSIG_OUTPUTDIR := $(HOTSPOT_OUTPUTDIR)/libjsig
 
@@ -91,7 +91,7 @@
 
     $(eval $(call SetupNativeCompilation, BUILD_LIBJSIG, \
         LIBRARY := jsig, \
-        EXTRA_FILES := $(LIBJSIG_SRC_FILE), \
+        SRC := $(LIBJSIG_SRC_DIR), \
         OUTPUT_DIR := $(LIB_OUTPUTDIR), \
         LANG := C, \
         CFLAGS := $(LIBJSIG_CFLAGS) $(LIBJSIG_CPU_FLAGS), \
--- a/make/hotspot/lib/JvmFeatures.gmk	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/hotspot/lib/JvmFeatures.gmk	Mon Nov 27 10:35:05 2017 -0800
@@ -153,7 +153,7 @@
   # like the old build, but it's probably not right.
   JVM_OPTIMIZATION :=
   JVM_CFLAGS_FEATURES += -O3 -flto
-  JVM_LDFLAGS_FEATURES += -O3 -flto -fwhole-program -fno-strict-aliasing
+  JVM_LDFLAGS_FEATURES += -O3 -flto -fuse-linker-plugin -fno-strict-aliasing
 endif
 
 ifeq ($(call check-jvm-feature, minimal), true)
--- a/make/nashorn/build.xml	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/nashorn/build.xml	Mon Nov 27 10:35:05 2017 -0800
@@ -278,7 +278,7 @@
       <arg value="${javadoc.option}"/>
       <fileset dir="${nashorn.module.src.dir}" includes="**/*.java"/>
       <fileset dir="${dynalink.module.src.dir}" includes="**/*.java"/>
-      <link href="http://docs.oracle.com/javase/8/docs/api/"/>
+      <link offline="true" href="${javadoc.base.url}" packagelistLoc="${javadoc.pkg.list}"/>
     </javadoc>
   </target>
 
@@ -296,7 +296,7 @@
       <arg value="."/>
       <arg value="${javadoc.option}"/>
       <fileset dir="${nashorn.module.src.dir}" includes="jdk/nashorn/api/**/*.java"/>
-      <link href="http://docs.oracle.com/javase/8/docs/api/"/>
+      <link offline="true" href="${javadoc.base.url}" packagelistLoc="${javadoc.pkg.list}"/>
     </javadoc>
   </target>
 
@@ -314,7 +314,7 @@
       <arg value="."/>
       <arg value="${javadoc.option}"/>
       <fileset dir="${dynalink.module.src.dir}" includes="**/*.java"/>
-      <link href="http://docs.oracle.com/javase/8/docs/api/"/>
+      <link offline="true" href="${javadoc.base.url}" packagelistLoc="${javadoc.pkg.list}"/>
     </javadoc>
   </target>
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/nashorn/package-list	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,315 @@
+com.sun.jarsigner
+com.sun.java.accessibility.util
+com.sun.javadoc
+com.sun.jdi
+com.sun.jdi.connect
+com.sun.jdi.connect.spi
+com.sun.jdi.event
+com.sun.jdi.request
+com.sun.management
+com.sun.net.httpserver
+com.sun.net.httpserver.spi
+com.sun.nio.sctp
+com.sun.security.auth
+com.sun.security.auth.callback
+com.sun.security.auth.login
+com.sun.security.auth.module
+com.sun.security.jgss
+com.sun.source.doctree
+com.sun.source.tree
+com.sun.source.util
+com.sun.tools.attach
+com.sun.tools.attach.spi
+com.sun.tools.doclets
+com.sun.tools.doclets.standard
+com.sun.tools.javac
+com.sun.tools.javadoc
+com.sun.tools.jconsole
+java.applet
+java.awt
+java.awt.color
+java.awt.datatransfer
+java.awt.desktop
+java.awt.dnd
+java.awt.event
+java.awt.font
+java.awt.geom
+java.awt.im
+java.awt.im.spi
+java.awt.image
+java.awt.image.renderable
+java.awt.print
+java.beans
+java.beans.beancontext
+java.io
+java.lang
+java.lang.annotation
+java.lang.instrument
+java.lang.invoke
+java.lang.management
+java.lang.module
+java.lang.ref
+java.lang.reflect
+java.math
+java.net
+java.net.spi
+java.nio
+java.nio.channels
+java.nio.channels.spi
+java.nio.charset
+java.nio.charset.spi
+java.nio.file
+java.nio.file.attribute
+java.nio.file.spi
+java.rmi
+java.rmi.activation
+java.rmi.dgc
+java.rmi.registry
+java.rmi.server
+java.security
+java.security.acl
+java.security.cert
+java.security.interfaces
+java.security.spec
+java.sql
+java.text
+java.text.spi
+java.time
+java.time.chrono
+java.time.format
+java.time.temporal
+java.time.zone
+java.util
+java.util.concurrent
+java.util.concurrent.atomic
+java.util.concurrent.locks
+java.util.function
+java.util.jar
+java.util.logging
+java.util.prefs
+java.util.regex
+java.util.spi
+java.util.stream
+java.util.zip
+javafx.animation
+javafx.application
+javafx.beans
+javafx.beans.binding
+javafx.beans.property
+javafx.beans.property.adapter
+javafx.beans.value
+javafx.collections
+javafx.collections.transformation
+javafx.concurrent
+javafx.css
+javafx.css.converter
+javafx.embed.swing
+javafx.event
+javafx.fxml
+javafx.geometry
+javafx.print
+javafx.scene
+javafx.scene.canvas
+javafx.scene.chart
+javafx.scene.control
+javafx.scene.control.cell
+javafx.scene.control.skin
+javafx.scene.effect
+javafx.scene.image
+javafx.scene.input
+javafx.scene.layout
+javafx.scene.media
+javafx.scene.paint
+javafx.scene.shape
+javafx.scene.text
+javafx.scene.transform
+javafx.scene.web
+javafx.stage
+javafx.util
+javafx.util.converter
+javax.accessibility
+javax.activation
+javax.activity
+javax.annotation
+javax.annotation.processing
+javax.crypto
+javax.crypto.interfaces
+javax.crypto.spec
+javax.imageio
+javax.imageio.event
+javax.imageio.metadata
+javax.imageio.plugins.bmp
+javax.imageio.plugins.jpeg
+javax.imageio.plugins.tiff
+javax.imageio.spi
+javax.imageio.stream
+javax.jnlp
+javax.jws
+javax.jws.soap
+javax.lang.model
+javax.lang.model.element
+javax.lang.model.type
+javax.lang.model.util
+javax.management
+javax.management.loading
+javax.management.modelmbean
+javax.management.monitor
+javax.management.openmbean
+javax.management.relation
+javax.management.remote
+javax.management.remote.rmi
+javax.management.timer
+javax.naming
+javax.naming.directory
+javax.naming.event
+javax.naming.ldap
+javax.naming.spi
+javax.net
+javax.net.ssl
+javax.print
+javax.print.attribute
+javax.print.attribute.standard
+javax.print.event
+javax.rmi
+javax.rmi.CORBA
+javax.rmi.ssl
+javax.script
+javax.security.auth
+javax.security.auth.callback
+javax.security.auth.kerberos
+javax.security.auth.login
+javax.security.auth.spi
+javax.security.auth.x500
+javax.security.cert
+javax.security.sasl
+javax.smartcardio
+javax.sound.midi
+javax.sound.midi.spi
+javax.sound.sampled
+javax.sound.sampled.spi
+javax.sql
+javax.sql.rowset
+javax.sql.rowset.serial
+javax.sql.rowset.spi
+javax.swing
+javax.swing.border
+javax.swing.colorchooser
+javax.swing.event
+javax.swing.filechooser
+javax.swing.plaf
+javax.swing.plaf.basic
+javax.swing.plaf.metal
+javax.swing.plaf.multi
+javax.swing.plaf.nimbus
+javax.swing.plaf.synth
+javax.swing.table
+javax.swing.text
+javax.swing.text.html
+javax.swing.text.html.parser
+javax.swing.text.rtf
+javax.swing.tree
+javax.swing.undo
+javax.tools
+javax.transaction
+javax.transaction.xa
+javax.xml
+javax.xml.bind
+javax.xml.bind.annotation
+javax.xml.bind.annotation.adapters
+javax.xml.bind.attachment
+javax.xml.bind.helpers
+javax.xml.bind.util
+javax.xml.catalog
+javax.xml.crypto
+javax.xml.crypto.dom
+javax.xml.crypto.dsig
+javax.xml.crypto.dsig.dom
+javax.xml.crypto.dsig.keyinfo
+javax.xml.crypto.dsig.spec
+javax.xml.datatype
+javax.xml.namespace
+javax.xml.parsers
+javax.xml.soap
+javax.xml.stream
+javax.xml.stream.events
+javax.xml.stream.util
+javax.xml.transform
+javax.xml.transform.dom
+javax.xml.transform.sax
+javax.xml.transform.stax
+javax.xml.transform.stream
+javax.xml.validation
+javax.xml.ws
+javax.xml.ws.handler
+javax.xml.ws.handler.soap
+javax.xml.ws.http
+javax.xml.ws.soap
+javax.xml.ws.spi
+javax.xml.ws.spi.http
+javax.xml.ws.wsaddressing
+javax.xml.xpath
+jdk.dynalink
+jdk.dynalink.beans
+jdk.dynalink.linker
+jdk.dynalink.linker.support
+jdk.dynalink.support
+jdk.incubator.http
+jdk.javadoc.doclet
+jdk.jfr
+jdk.jfr.consumer
+jdk.jshell
+jdk.jshell.execution
+jdk.jshell.spi
+jdk.jshell.tool
+jdk.management.cmm
+jdk.management.jfr
+jdk.management.resource
+jdk.nashorn.api.scripting
+jdk.nashorn.api.tree
+jdk.net
+jdk.packager.services
+jdk.security.jarsigner
+netscape.javascript
+org.ietf.jgss
+org.omg.CORBA
+org.omg.CORBA_2_3
+org.omg.CORBA_2_3.portable
+org.omg.CORBA.DynAnyPackage
+org.omg.CORBA.ORBPackage
+org.omg.CORBA.portable
+org.omg.CORBA.TypeCodePackage
+org.omg.CosNaming
+org.omg.CosNaming.NamingContextExtPackage
+org.omg.CosNaming.NamingContextPackage
+org.omg.Dynamic
+org.omg.DynamicAny
+org.omg.DynamicAny.DynAnyFactoryPackage
+org.omg.DynamicAny.DynAnyPackage
+org.omg.IOP
+org.omg.IOP.CodecFactoryPackage
+org.omg.IOP.CodecPackage
+org.omg.Messaging
+org.omg.PortableInterceptor
+org.omg.PortableInterceptor.ORBInitInfoPackage
+org.omg.PortableServer
+org.omg.PortableServer.CurrentPackage
+org.omg.PortableServer.POAManagerPackage
+org.omg.PortableServer.POAPackage
+org.omg.PortableServer.portable
+org.omg.PortableServer.ServantLocatorPackage
+org.omg.SendingContext
+org.omg.stub.java.rmi
+org.w3c.dom
+org.w3c.dom.bootstrap
+org.w3c.dom.css
+org.w3c.dom.events
+org.w3c.dom.html
+org.w3c.dom.ls
+org.w3c.dom.ranges
+org.w3c.dom.stylesheets
+org.w3c.dom.traversal
+org.w3c.dom.views
+org.w3c.dom.xpath
+org.xml.sax
+org.xml.sax.ext
+org.xml.sax.helpers
--- a/make/nashorn/project.properties	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/nashorn/project.properties	Mon Nov 27 10:35:05 2017 -0800
@@ -33,6 +33,12 @@
 # source and target levels
 build.compiler=modern
 
+jdk.build.dir=build
+nashorn.make.dir=make/nashorn
+
+javadoc.base.url=https://docs.oracle.com/javase/9/docs/api/
+javadoc.pkg.list=make/nashorn
+
 javadoc.option=\
     -tag "implSpec:a:Implementation Requirements:" \
     -tag "implNote:a:Implementation Note:" \
@@ -43,9 +49,6 @@
 nashorn.fullversion=0.1
 nashorn.product.name=Oracle Nashorn
 
-jdk.build.dir=build
-nashorn.make.dir=make/nashorn
-
 # This directory is removed when the project is cleaned:
 build.dir=${jdk.build.dir}/nashorn
 build.classes.dir=${build.dir}/classes
--- a/make/test/JtregNativeHotspot.gmk	Fri Nov 24 16:55:18 2017 -0800
+++ b/make/test/JtregNativeHotspot.gmk	Mon Nov 27 10:35:05 2017 -0800
@@ -60,6 +60,7 @@
     $(TOPDIR)/test/hotspot/jtreg/runtime/SameObject \
     $(TOPDIR)/test/hotspot/jtreg/runtime/BoolReturn \
     $(TOPDIR)/test/hotspot/jtreg/runtime/noClassDefFoundMsg \
+    $(TOPDIR)/test/hotspot/jtreg/runtime/handshake \
     $(TOPDIR)/test/hotspot/jtreg/runtime/RedefineTests \
     $(TOPDIR)/test/hotspot/jtreg/compiler/floatingpoint/ \
     $(TOPDIR)/test/hotspot/jtreg/compiler/calls \
@@ -108,6 +109,7 @@
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libMAAThreadStart := -lc
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libAllowedFunctions := -lc
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libRedefineDoubleDelete := -lc
+    BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libHandshakeTransitionTest := -lc
 endif
 
 ifeq ($(OPENJDK_TARGET_OS), linux)
--- a/src/hotspot/cpu/aarch64/globals_aarch64.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/aarch64/globals_aarch64.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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.
  * Copyright (c) 2015, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -79,6 +79,8 @@
 // Clear short arrays bigger than one word in an arch-specific way
 define_pd_global(intx, InitArrayShortSize, BytesPerLong);
 
+define_pd_global(bool, ThreadLocalHandshakes, false);
+
 #if defined(COMPILER1) || defined(COMPILER2)
 define_pd_global(intx, InlineSmallCode,          1000);
 #endif
--- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -3228,6 +3228,102 @@
     mvnw(crc, crc);
 }
 
+void MacroAssembler::kernel_crc32c_using_crc32c(Register crc, Register buf,
+        Register len, Register tmp0, Register tmp1, Register tmp2,
+        Register tmp3) {
+    Label CRC_by64_loop, CRC_by4_loop, CRC_by1_loop, CRC_less64, CRC_by64_pre, CRC_by32_loop, CRC_less32, L_exit;
+    assert_different_registers(crc, buf, len, tmp0, tmp1, tmp2, tmp3);
+
+    subs(len, len, 128);
+    br(Assembler::GE, CRC_by64_pre);
+  BIND(CRC_less64);
+    adds(len, len, 128-32);
+    br(Assembler::GE, CRC_by32_loop);
+  BIND(CRC_less32);
+    adds(len, len, 32-4);
+    br(Assembler::GE, CRC_by4_loop);
+    adds(len, len, 4);
+    br(Assembler::GT, CRC_by1_loop);
+    b(L_exit);
+
+  BIND(CRC_by32_loop);
+    ldp(tmp0, tmp1, Address(post(buf, 16)));
+    subs(len, len, 32);
+    crc32cx(crc, crc, tmp0);
+    ldr(tmp2, Address(post(buf, 8)));
+    crc32cx(crc, crc, tmp1);
+    ldr(tmp3, Address(post(buf, 8)));
+    crc32cx(crc, crc, tmp2);
+    crc32cx(crc, crc, tmp3);
+    br(Assembler::GE, CRC_by32_loop);
+    cmn(len, 32);
+    br(Assembler::NE, CRC_less32);
+    b(L_exit);
+
+  BIND(CRC_by4_loop);
+    ldrw(tmp0, Address(post(buf, 4)));
+    subs(len, len, 4);
+    crc32cw(crc, crc, tmp0);
+    br(Assembler::GE, CRC_by4_loop);
+    adds(len, len, 4);
+    br(Assembler::LE, L_exit);
+  BIND(CRC_by1_loop);
+    ldrb(tmp0, Address(post(buf, 1)));
+    subs(len, len, 1);
+    crc32cb(crc, crc, tmp0);
+    br(Assembler::GT, CRC_by1_loop);
+    b(L_exit);
+
+  BIND(CRC_by64_pre);
+    sub(buf, buf, 8);
+    ldp(tmp0, tmp1, Address(buf, 8));
+    crc32cx(crc, crc, tmp0);
+    ldr(tmp2, Address(buf, 24));
+    crc32cx(crc, crc, tmp1);
+    ldr(tmp3, Address(buf, 32));
+    crc32cx(crc, crc, tmp2);
+    ldr(tmp0, Address(buf, 40));
+    crc32cx(crc, crc, tmp3);
+    ldr(tmp1, Address(buf, 48));
+    crc32cx(crc, crc, tmp0);
+    ldr(tmp2, Address(buf, 56));
+    crc32cx(crc, crc, tmp1);
+    ldr(tmp3, Address(pre(buf, 64)));
+
+    b(CRC_by64_loop);
+
+    align(CodeEntryAlignment);
+  BIND(CRC_by64_loop);
+    subs(len, len, 64);
+    crc32cx(crc, crc, tmp2);
+    ldr(tmp0, Address(buf, 8));
+    crc32cx(crc, crc, tmp3);
+    ldr(tmp1, Address(buf, 16));
+    crc32cx(crc, crc, tmp0);
+    ldr(tmp2, Address(buf, 24));
+    crc32cx(crc, crc, tmp1);
+    ldr(tmp3, Address(buf, 32));
+    crc32cx(crc, crc, tmp2);
+    ldr(tmp0, Address(buf, 40));
+    crc32cx(crc, crc, tmp3);
+    ldr(tmp1, Address(buf, 48));
+    crc32cx(crc, crc, tmp0);
+    ldr(tmp2, Address(buf, 56));
+    crc32cx(crc, crc, tmp1);
+    ldr(tmp3, Address(pre(buf, 64)));
+    br(Assembler::GE, CRC_by64_loop);
+
+    // post-loop
+    crc32cx(crc, crc, tmp2);
+    crc32cx(crc, crc, tmp3);
+
+    sub(len, len, 64);
+    add(buf, buf, 8);
+    cmn(len, 128);
+    br(Assembler::NE, CRC_less64);
+  BIND(L_exit);
+}
+
 /**
  * @param crc   register containing existing CRC (32-bit)
  * @param buf   register pointing to input byte buffer (byte*)
@@ -3238,54 +3334,9 @@
 void MacroAssembler::kernel_crc32c(Register crc, Register buf, Register len,
         Register table0, Register table1, Register table2, Register table3,
         Register tmp, Register tmp2, Register tmp3) {
-  Label L_exit;
-  Label CRC_by64_loop, CRC_by4_loop, CRC_by1_loop;
-
-    subs(len, len, 64);
-    br(Assembler::GE, CRC_by64_loop);
-    adds(len, len, 64-4);
-    br(Assembler::GE, CRC_by4_loop);
-    adds(len, len, 4);
-    br(Assembler::GT, CRC_by1_loop);
-    b(L_exit);
-
-  BIND(CRC_by4_loop);
-    ldrw(tmp, Address(post(buf, 4)));
-    subs(len, len, 4);
-    crc32cw(crc, crc, tmp);
-    br(Assembler::GE, CRC_by4_loop);
-    adds(len, len, 4);
-    br(Assembler::LE, L_exit);
-  BIND(CRC_by1_loop);
-    ldrb(tmp, Address(post(buf, 1)));
-    subs(len, len, 1);
-    crc32cb(crc, crc, tmp);
-    br(Assembler::GT, CRC_by1_loop);
-    b(L_exit);
-
-    align(CodeEntryAlignment);
-  BIND(CRC_by64_loop);
-    subs(len, len, 64);
-    ldp(tmp, tmp3, Address(post(buf, 16)));
-    crc32cx(crc, crc, tmp);
-    crc32cx(crc, crc, tmp3);
-    ldp(tmp, tmp3, Address(post(buf, 16)));
-    crc32cx(crc, crc, tmp);
-    crc32cx(crc, crc, tmp3);
-    ldp(tmp, tmp3, Address(post(buf, 16)));
-    crc32cx(crc, crc, tmp);
-    crc32cx(crc, crc, tmp3);
-    ldp(tmp, tmp3, Address(post(buf, 16)));
-    crc32cx(crc, crc, tmp);
-    crc32cx(crc, crc, tmp3);
-    br(Assembler::GE, CRC_by64_loop);
-    adds(len, len, 64-4);
-    br(Assembler::GE, CRC_by4_loop);
-    adds(len, len, 4);
-    br(Assembler::GT, CRC_by1_loop);
-  BIND(L_exit);
-    return;
-}
+  kernel_crc32c_using_crc32c(crc, buf, len, table0, table1, table2, table3);
+}
+
 
 SkipIfEqual::SkipIfEqual(
     MacroAssembler* masm, const bool* flag_addr, bool value) {
--- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -1264,6 +1264,9 @@
   void kernel_crc32_using_crc32(Register crc, Register buf,
         Register len, Register tmp0, Register tmp1, Register tmp2,
         Register tmp3);
+  void kernel_crc32c_using_crc32c(Register crc, Register buf,
+        Register len, Register tmp0, Register tmp1, Register tmp2,
+        Register tmp3);
 public:
   void multiply_to_len(Register x, Register xlen, Register y, Register ylen, Register z,
                        Register zlen, Register tmp1, Register tmp2, Register tmp3,
--- a/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -447,7 +447,8 @@
 }
 
 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state,
-                                                               int step) {
+                                                               int step,
+                                                               address continuation) {
   address entry = __ pc();
   __ restore_bcp();
   __ restore_locals();
@@ -505,7 +506,11 @@
     __ bind(L);
   }
 
-  __ dispatch_next(state, step);
+  if (continuation == NULL) {
+    __ dispatch_next(state, step);
+  } else {
+    __ jump_to_entry(continuation);
+  }
   return entry;
 }
 
--- a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -2195,13 +2195,6 @@
     __ bind(skip_register_finalizer);
   }
 
-  // Explicitly reset last_sp, for handling special case in TemplateInterpreter::deopt_reexecute_entry
-#ifdef ASSERT
-  if (state == vtos) {
-    __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
-  }
-#endif
-
   // Issue a StoreStore barrier after all stores but before return
   // from any constructor for any class with a final field.  We don't
   // know if this is a finalizer, so we always do so.
--- a/src/hotspot/cpu/arm/globals_arm.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/arm/globals_arm.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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
@@ -79,6 +79,8 @@
 
 define_pd_global(intx, InitArrayShortSize, 8*BytesPerLong);
 
+define_pd_global(bool, ThreadLocalHandshakes, false);
+
 #define ARCH_FLAGS(develop, \
                    product, \
                    diagnostic, \
--- a/src/hotspot/cpu/arm/templateInterpreterGenerator_arm.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/arm/templateInterpreterGenerator_arm.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -314,7 +314,7 @@
 }
 
 
-address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) {
+address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step, address continuation) {
   address entry = __ pc();
 
   __ interp_verify_oop(R0_tos, state, __FILE__, __LINE__);
@@ -343,7 +343,11 @@
     __ bind(L);
   }
 
-  __ dispatch_next(state, step);
+  if (continuation == NULL) {
+    __ dispatch_next(state, step);
+  } else {
+    __ jump_to_entry(continuation);
+  }
 
   return entry;
 }
--- a/src/hotspot/cpu/arm/templateTable_arm.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/arm/templateTable_arm.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -2844,19 +2844,6 @@
     __ bind(skip_register_finalizer);
   }
 
-  // Explicitly reset last_sp, for handling special case in TemplateInterpreter::deopt_reexecute_entry
-#ifdef ASSERT
-  if (state == vtos) {
-#ifndef AARCH64
-    __ mov(Rtemp, 0);
-    __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
-#else
-    __ restore_sp_after_call(Rtemp);
-    __ restore_stack_top();
-#endif
-  }
-#endif
-
   // Narrow result if state is itos but result type is smaller.
   // Need to narrow in the return bytecode rather than in generate_return_entry
   // since compiled code callers expect the result to already be narrowed.
--- a/src/hotspot/cpu/ppc/globals_ppc.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/ppc/globals_ppc.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -83,6 +83,8 @@
 // 2x unrolled loop is shorter with more than 9 HeapWords.
 define_pd_global(intx, InitArrayShortSize, 9*BytesPerLong);
 
+define_pd_global(bool, ThreadLocalHandshakes, false);
+
 // Platform dependent flag handling: flags only defined on this platform.
 #define ARCH_FLAGS(develop, \
                    product, \
--- a/src/hotspot/cpu/ppc/templateInterpreterGenerator_ppc.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/ppc/templateInterpreterGenerator_ppc.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -694,7 +694,7 @@
   return entry;
 }
 
-address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) {
+address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step, address continuation) {
   address entry = __ pc();
   // If state != vtos, we're returning from a native method, which put it's result
   // into the result register. So move the value out of the return register back
@@ -721,7 +721,11 @@
   __ check_and_forward_exception(R11_scratch1, R12_scratch2);
 
   // Start executing bytecodes.
-  __ dispatch_next(state, step);
+  if (continuation == NULL) {
+    __ dispatch_next(state, step);
+  } else {
+    __ jump_to_entry(continuation, R11_scratch1);
+  }
 
   return entry;
 }
--- a/src/hotspot/cpu/s390/globals_s390.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/s390/globals_s390.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -85,6 +85,8 @@
 // 8146801 (Short Array Allocation): No performance work done here yet.
 define_pd_global(intx, InitArrayShortSize, 1*BytesPerLong);
 
+define_pd_global(bool, ThreadLocalHandshakes, false);
+
 #define ARCH_FLAGS(develop, product, diagnostic, experimental, notproduct, range, constraint, writeable) \
                                                                               \
   /* Reoptimize code-sequences of calls at runtime, e.g. replace an */        \
--- a/src/hotspot/cpu/s390/templateInterpreterGenerator_s390.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/s390/templateInterpreterGenerator_s390.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -687,7 +687,8 @@
 }
 
 address TemplateInterpreterGenerator::generate_deopt_entry_for (TosState state,
-                                                               int step) {
+                                                               int step,
+                                                               address continuation) {
   address entry = __ pc();
 
   BLOCK_COMMENT("deopt_entry {");
@@ -710,7 +711,11 @@
     __ should_not_reach_here();
     __ bind(L);
   }
-  __ dispatch_next(state, step);
+  if (continuation == NULL) {
+    __ dispatch_next(state, step);
+  } else {
+    __ jump_to_entry(continuation, Z_R1_scratch);
+  }
 
   BLOCK_COMMENT("} deopt_entry");
 
--- a/src/hotspot/cpu/sparc/c1_LIRAssembler_sparc.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/sparc/c1_LIRAssembler_sparc.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -35,6 +35,7 @@
 #include "gc/shared/collectedHeap.hpp"
 #include "nativeInst_sparc.hpp"
 #include "oops/objArrayKlass.hpp"
+#include "runtime/safepointMechanism.inline.hpp"
 #include "runtime/sharedRuntime.hpp"
 
 #define __ _masm->
@@ -1415,7 +1416,11 @@
   if (StackReservedPages > 0 && compilation()->has_reserved_stack_access()) {
     __ reserved_stack_check();
   }
-  __ set((intptr_t)os::get_polling_page(), L0);
+  if (SafepointMechanism::uses_thread_local_poll()) {
+    __ ld_ptr(Address(G2_thread, Thread::polling_page_offset()), L0);
+  } else {
+    __ set((intptr_t)os::get_polling_page(), L0);
+  }
   __ relocate(relocInfo::poll_return_type);
   __ ld_ptr(L0, 0, G0);
   __ ret();
@@ -1424,11 +1429,16 @@
 
 
 int LIR_Assembler::safepoint_poll(LIR_Opr tmp, CodeEmitInfo* info) {
-  __ set((intptr_t)os::get_polling_page(), tmp->as_register());
+  if (SafepointMechanism::uses_thread_local_poll()) {
+    __ ld_ptr(Address(G2_thread, Thread::polling_page_offset()), tmp->as_register());
+  } else {
+    __ set((intptr_t)os::get_polling_page(), tmp->as_register());
+  }
   if (info != NULL) {
     add_debug_info_for_branch(info);
   }
   int offset = __ offset();
+
   __ relocate(relocInfo::poll_type);
   __ ld_ptr(tmp->as_register(), 0, G0);
   return offset;
--- a/src/hotspot/cpu/sparc/c1_LIRGenerator_sparc.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/sparc/c1_LIRGenerator_sparc.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -33,6 +33,7 @@
 #include "ci/ciArray.hpp"
 #include "ci/ciObjArrayKlass.hpp"
 #include "ci/ciTypeArrayKlass.hpp"
+#include "runtime/safepointMechanism.hpp"
 #include "runtime/sharedRuntime.hpp"
 #include "runtime/stubRoutines.hpp"
 #include "vmreg_sparc.inline.hpp"
@@ -1304,7 +1305,7 @@
   if (x->is_safepoint()) {
     // increment backedge counter if needed
     increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci());
-    __ safepoint(new_register(T_INT), state_for(x, x->state_before()));
+    __ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));
   }
 
   __ cmp(lir_cond(cond), left, right);
--- a/src/hotspot/cpu/sparc/globalDefinitions_sparc.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/sparc/globalDefinitions_sparc.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -52,4 +52,7 @@
 #define SUPPORT_RESERVED_STACK_AREA
 #endif
 
+// SPARC have implemented the local polling
+#define THREAD_LOCAL_POLL
+
 #endif // CPU_SPARC_VM_GLOBALDEFINITIONS_SPARC_HPP
--- a/src/hotspot/cpu/sparc/globals_sparc.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/sparc/globals_sparc.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -87,6 +87,8 @@
 
 define_pd_global(intx, InitArrayShortSize, 8*BytesPerLong);
 
+define_pd_global(bool, ThreadLocalHandshakes, true);
+
 #define ARCH_FLAGS(develop, \
                    product, \
                    diagnostic, \
--- a/src/hotspot/cpu/sparc/interp_masm_sparc.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/sparc/interp_masm_sparc.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -36,6 +36,7 @@
 #include "prims/jvmtiThreadState.hpp"
 #include "runtime/basicLock.hpp"
 #include "runtime/biasedLocking.hpp"
+#include "runtime/safepointMechanism.hpp"
 #include "runtime/sharedRuntime.hpp"
 #include "runtime/thread.inline.hpp"
 #include "utilities/align.hpp"
@@ -95,12 +96,11 @@
   else                delayed()->nop();
 }
 
-
-void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr) {
+void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr, bool generate_poll) {
   // %%%% consider branching to a single shared dispatch stub (for each bcp_incr)
   assert_not_delayed();
   ldub( Lbcp, bcp_incr, Lbyte_code);               // load next bytecode
-  dispatch_Lbyte_code(state, Interpreter::dispatch_table(state), bcp_incr);
+  dispatch_Lbyte_code(state, Interpreter::dispatch_table(state), bcp_incr, true, generate_poll);
 }
 
 
@@ -261,15 +261,34 @@
 // common code to dispatch and dispatch_only
 // dispatch value in Lbyte_code and increment Lbcp
 
-void InterpreterMacroAssembler::dispatch_Lbyte_code(TosState state, address* table, int bcp_incr, bool verify) {
+void InterpreterMacroAssembler::dispatch_Lbyte_code(TosState state, address* table, int bcp_incr, bool verify, bool generate_poll) {
   verify_FPU(1, state);
   // %%%%% maybe implement +VerifyActivationFrameSize here
   //verify_thread(); //too slow; we will just verify on method entry & exit
   if (verify) interp_verify_oop(Otos_i, state, __FILE__, __LINE__);
   // dispatch table to use
   AddressLiteral tbl(table);
+  Label dispatch;
+
+  if (SafepointMechanism::uses_thread_local_poll() && generate_poll) {
+    AddressLiteral sfpt_tbl(Interpreter::safept_table(state));
+    Label no_safepoint;
+
+    if (tbl.value() != sfpt_tbl.value()) {
+      ldx(Address(G2_thread, Thread::polling_page_offset()), G3_scratch, 0);
+      // Armed page has poll_bit set, if poll bit is cleared just continue.
+      and3(G3_scratch, SafepointMechanism::poll_bit(), G3_scratch);
+
+      br_null_short(G3_scratch, Assembler::pt, no_safepoint);
+      set(sfpt_tbl, G3_scratch);
+      ba_short(dispatch);
+    }
+    bind(no_safepoint);
+  }
+
+  set(tbl, G3_scratch);                               // compute addr of table
+  bind(dispatch);
   sll(Lbyte_code, LogBytesPerWord, Lbyte_code);       // multiply by wordSize
-  set(tbl, G3_scratch);                               // compute addr of table
   ld_ptr(G3_scratch, Lbyte_code, G3_scratch);         // get entry addr
   jmp( G3_scratch, 0 );
   if (bcp_incr != 0)  delayed()->inc(Lbcp, bcp_incr);
--- a/src/hotspot/cpu/sparc/interp_masm_sparc.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/sparc/interp_masm_sparc.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -98,7 +98,7 @@
   void dispatch_epilog(TosState state, int step = 0);
   void dispatch_only(TosState state);
   void dispatch_normal(TosState state);
-  void dispatch_next(TosState state, int step = 0);
+  void dispatch_next(TosState state, int step = 0, bool generate_poll = false);
   void dispatch_next_noverify_oop(TosState state, int step = 0);
   void dispatch_via (TosState state, address* table);
 
@@ -113,7 +113,7 @@
                          bool install_monitor_exception = true);
 
  protected:
-  void dispatch_Lbyte_code(TosState state, address* table, int bcp_incr = 0, bool verify = true);
+  void dispatch_Lbyte_code(TosState state, address* table, int bcp_incr = 0, bool verify = true, bool generate_poll = false);
 
  public:
   // Super call_VM calls - correspond to MacroAssembler::call_VM(_leaf) calls
--- a/src/hotspot/cpu/sparc/macroAssembler_sparc.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/sparc/macroAssembler_sparc.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -37,6 +37,8 @@
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/objectMonitor.hpp"
 #include "runtime/os.inline.hpp"
+#include "runtime/safepoint.hpp"
+#include "runtime/safepointMechanism.hpp"
 #include "runtime/sharedRuntime.hpp"
 #include "runtime/stubRoutines.hpp"
 #include "utilities/align.hpp"
@@ -236,6 +238,20 @@
 }
 
 
+void MacroAssembler::safepoint_poll(Label& slow_path, bool a, Register thread_reg, Register temp_reg) {
+  if (SafepointMechanism::uses_thread_local_poll()) {
+    ldx(Address(thread_reg, Thread::polling_page_offset()), temp_reg, 0);
+    // Armed page has poll bit set.
+    and3(temp_reg, SafepointMechanism::poll_bit(), temp_reg);
+    br_notnull(temp_reg, a, Assembler::pn, slow_path);
+  } else {
+    AddressLiteral sync_state(SafepointSynchronize::address_of_state());
+
+    load_contents(sync_state, temp_reg);
+    cmp(temp_reg, SafepointSynchronize::_not_synchronized);
+    br(Assembler::notEqual, a, Assembler::pn, slow_path);
+  }
+}
 
 void MacroAssembler::enter() {
   Unimplemented();
--- a/src/hotspot/cpu/sparc/macroAssembler_sparc.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/sparc/macroAssembler_sparc.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -986,6 +986,8 @@
   // Support for serializing memory accesses between threads
   void serialize_memory(Register thread, Register tmp1, Register tmp2);
 
+  void safepoint_poll(Label& slow_path, bool a, Register thread_reg, Register temp_reg);
+
   // Stack frame creation/removal
   void enter();
   void leave();
--- a/src/hotspot/cpu/sparc/sharedRuntime_sparc.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/sparc/sharedRuntime_sparc.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -2359,7 +2359,6 @@
   // Block, if necessary, before resuming in _thread_in_Java state.
   // In order for GC to work, don't clear the last_Java_sp until after blocking.
   { Label no_block;
-    AddressLiteral sync_state(SafepointSynchronize::address_of_state());
 
     // Switch thread to "native transition" state before reading the synchronization state.
     // This additional state is necessary because reading and testing the synchronization
@@ -2382,12 +2381,10 @@
         __ serialize_memory(G2_thread, G1_scratch, G3_scratch);
       }
     }
-    __ load_contents(sync_state, G3_scratch);
-    __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
 
     Label L;
     Address suspend_state(G2_thread, JavaThread::suspend_flags_offset());
-    __ br(Assembler::notEqual, false, Assembler::pn, L);
+    __ safepoint_poll(L, false, G2_thread, G3_scratch);
     __ delayed()->ld(suspend_state, G3_scratch);
     __ cmp_and_br_short(G3_scratch, 0, Assembler::equal, Assembler::pt, no_block);
     __ bind(L);
@@ -3118,7 +3115,7 @@
   } else {
     // Make it look like we were called via the poll
     // so that frame constructor always sees a valid return address
-    __ ld_ptr(G2_thread, in_bytes(JavaThread::saved_exception_pc_offset()), O7);
+    __ ld_ptr(Address(G2_thread, JavaThread::saved_exception_pc_offset()), O7);
     __ sub(O7, frame::pc_return_offset, O7);
   }
 
@@ -3127,6 +3124,15 @@
   // setup last_Java_sp (blows G4)
   __ set_last_Java_frame(SP, noreg);
 
+  Register saved_O7 = O7->after_save();
+  if (!cause_return && SafepointMechanism::uses_thread_local_poll()) {
+    // Keep a copy of the return pc in L0 to detect if it gets modified
+    __ mov(saved_O7, L0);
+    // Adjust and keep a copy of our npc saved by the signal handler
+    __ ld_ptr(Address(G2_thread, JavaThread::saved_exception_npc_offset()), L1);
+    __ sub(L1, frame::pc_return_offset, L1);
+  }
+
   // call into the runtime to handle illegal instructions exception
   // Do not use call_VM_leaf, because we need to make a GC map at this call site.
   __ mov(G2_thread, O0);
@@ -3150,6 +3156,12 @@
   __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), O1);
   __ br_notnull_short(O1, Assembler::pn, pending);
 
+  if (!cause_return && SafepointMechanism::uses_thread_local_poll()) {
+    // If nobody modified our return pc then we must return to the npc which he saved in L1
+    __ cmp(saved_O7, L0);
+    __ movcc(Assembler::equal, false, Assembler::ptr_cc, L1, saved_O7);
+  }
+
   RegisterSaver::restore_live_registers(masm);
 
   // We are back the the original state on entry and ready to go.
--- a/src/hotspot/cpu/sparc/sparc.ad	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/sparc/sparc.ad	Mon Nov 27 10:35:05 2017 -0800
@@ -1206,7 +1206,11 @@
   Compile* C = ra_->C;
 
   if(do_polling() && ra_->C->is_method_compilation()) {
-    st->print("SETHI  #PollAddr,L0\t! Load Polling address\n\t");
+    if (SafepointMechanism::uses_global_page_poll()) {
+      st->print("SETHI  #PollAddr,L0\t! Load Polling address\n\t");
+    } else {
+      st->print("LDX    [R_G2 + #poll_offset],L0\t! Load local polling address\n\t");
+    }
     st->print("LDX    [L0],G0\t!Poll for Safepointing\n\t");
   }
 
@@ -1233,8 +1237,12 @@
 
   // If this does safepoint polling, then do it here
   if(do_polling() && ra_->C->is_method_compilation()) {
-    AddressLiteral polling_page(os::get_polling_page());
-    __ sethi(polling_page, L0);
+    if (SafepointMechanism::uses_thread_local_poll()) {
+      __ ld_ptr(Address(G2_thread, Thread::polling_page_offset()), L0);
+    } else {
+      AddressLiteral polling_page(os::get_polling_page());
+      __ sethi(polling_page, L0);
+    }
     __ relocate(relocInfo::poll_return_type);
     __ ld_ptr(L0, 0, G0);
   }
@@ -1266,6 +1274,7 @@
 }
 
 int MachEpilogNode::safepoint_offset() const {
+  assert(SafepointMechanism::uses_global_page_poll(), "sanity");
   assert( do_polling(), "no return for this epilog node");
   return MacroAssembler::insts_for_sethi(os::get_polling_page()) * BytesPerInstWord;
 }
--- a/src/hotspot/cpu/sparc/templateInterpreterGenerator_sparc.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/sparc/templateInterpreterGenerator_sparc.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -313,7 +313,7 @@
 }
 
 
-address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) {
+address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step, address continuation) {
   address entry = __ pc();
   __ get_constant_pool_cache(LcpoolCache); // load LcpoolCache
 #if INCLUDE_JVMCI
@@ -350,7 +350,11 @@
     __ should_not_reach_here();
     __ bind(L);
   }
-  __ dispatch_next(state, step);
+  if (continuation == NULL) {
+    __ dispatch_next(state, step);
+  } else {
+    __ jump_to_entry(continuation);
+  }
   return entry;
 }
 
@@ -912,10 +916,8 @@
 
     Label L_slow_path;
     // If we need a safepoint check, generate full interpreter entry.
-    ExternalAddress state(SafepointSynchronize::address_of_state());
-    __ set(ExternalAddress(SafepointSynchronize::address_of_state()), O2);
-    __ set(SafepointSynchronize::_not_synchronized, O3);
-    __ cmp_and_br_short(O2, O3, Assembler::notEqual, Assembler::pt, L_slow_path);
+    __ safepoint_poll(L_slow_path, false, G2_thread, O2);
+    __ delayed()->nop();
 
     // Load parameters
     const Register crc   = O0; // initial crc
@@ -956,10 +958,9 @@
 
     Label L_slow_path;
     // If we need a safepoint check, generate full interpreter entry.
-    ExternalAddress state(SafepointSynchronize::address_of_state());
-    __ set(ExternalAddress(SafepointSynchronize::address_of_state()), O2);
-    __ set(SafepointSynchronize::_not_synchronized, O3);
-    __ cmp_and_br_short(O2, O3, Assembler::notEqual, Assembler::pt, L_slow_path);
+
+    __ safepoint_poll(L_slow_path, false, G2_thread, O2);
+    __ delayed()->nop();
 
     // Load parameters from the stack
     const Register crc    = O0; // initial crc
@@ -1397,7 +1398,6 @@
   // Block, if necessary, before resuming in _thread_in_Java state.
   // In order for GC to work, don't clear the last_Java_sp until after blocking.
   { Label no_block;
-    AddressLiteral sync_state(SafepointSynchronize::address_of_state());
 
     // Switch thread to "native transition" state before reading the synchronization state.
     // This additional state is necessary because reading and testing the synchronization
@@ -1420,11 +1420,9 @@
         __ serialize_memory(G2_thread, G1_scratch, G3_scratch);
       }
     }
-    __ load_contents(sync_state, G3_scratch);
-    __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
 
     Label L;
-    __ br(Assembler::notEqual, false, Assembler::pn, L);
+    __ safepoint_poll(L, false, G2_thread, G3_scratch);
     __ delayed()->ld(G2_thread, JavaThread::suspend_flags_offset(), G3_scratch);
     __ cmp_and_br_short(G3_scratch, 0, Assembler::equal, Assembler::pt, no_block);
     __ bind(L);
--- a/src/hotspot/cpu/sparc/templateTable_sparc.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/sparc/templateTable_sparc.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -1499,7 +1499,7 @@
     // Push returnAddress for "ret" on stack
     __ push_ptr(Otos_i);
     // And away we go!
-    __ dispatch_next(vtos);
+    __ dispatch_next(vtos, 0, true);
     return;
   }
 
@@ -1607,7 +1607,7 @@
   // continue with bytecode @ target
   // %%%%% Like Intel, could speed things up by moving bytecode fetch to code above,
   // %%%%% and changing dispatch_next to dispatch_only
-  __ dispatch_next(vtos);
+  __ dispatch_next(vtos, 0, true);
 }
 
 
@@ -1676,7 +1676,7 @@
   __ ld_ptr(Lmethod, Method::const_offset(), G3_scratch);
   __ add(G3_scratch, Otos_i, G3_scratch);
   __ add(G3_scratch, in_bytes(ConstMethod::codes_offset()), Lbcp);
-  __ dispatch_next(vtos);
+  __ dispatch_next(vtos, 0, true);
 }
 
 
@@ -1691,7 +1691,7 @@
   __ ld_ptr(Lmethod, Method::const_offset(), G3_scratch);
   __ add(G3_scratch, Otos_i, G3_scratch);
   __ add(G3_scratch, in_bytes(ConstMethod::codes_offset()), Lbcp);
-  __ dispatch_next(vtos);
+  __ dispatch_next(vtos, 0, true);
 }
 
 
@@ -1727,7 +1727,7 @@
   // continue execution
   __ bind(continue_execution);
   __ add(Lbcp, O2, Lbcp);
-  __ dispatch_next(vtos);
+  __ dispatch_next(vtos, 0, true);
 }
 
 
@@ -1779,7 +1779,7 @@
     __ bind(continue_execution);
   }
   __ add(Lbcp, O4, Lbcp);
-  __ dispatch_next(vtos);
+  __ dispatch_next(vtos, 0, true);
 }
 
 
@@ -1888,7 +1888,7 @@
 
   __ bind(continue_execution);
   __ add( Lbcp, Rj, Lbcp );
-  __ dispatch_next( vtos );
+  __ dispatch_next(vtos, 0, true);
 }
 
 
@@ -1914,6 +1914,18 @@
     __ bind(skip_register_finalizer);
   }
 
+  if (SafepointMechanism::uses_thread_local_poll() && _desc->bytecode() != Bytecodes::_return_register_finalizer) {
+    Label no_safepoint;
+    __ ldx(Address(G2_thread, Thread::polling_page_offset()), G3_scratch, 0);
+    __ btst(SafepointMechanism::poll_bit(), G3_scratch);
+    __ br(Assembler::zero, false, Assembler::pt, no_safepoint);
+    __ delayed()->nop();
+    __ push(state);
+    __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint));
+    __ pop(state);
+    __ bind(no_safepoint);
+  }
+
   // Narrow result if state is itos but result type is smaller.
   // Need to narrow in the return bytecode rather than in generate_return_entry
   // since compiled code callers expect the result to already be narrowed.
--- a/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -526,32 +526,57 @@
 
   // Note: we do not need to round double result; float result has the right precision
   // the poll sets the condition code, but no data registers
-  AddressLiteral polling_page(os::get_polling_page(), relocInfo::poll_return_type);
-
-  if (Assembler::is_polling_page_far()) {
-    __ lea(rscratch1, polling_page);
+
+  if (SafepointMechanism::uses_thread_local_poll()) {
+#ifdef _LP64
+    __ movptr(rscratch1, Address(r15_thread, Thread::polling_page_offset()));
     __ relocate(relocInfo::poll_return_type);
     __ testl(rax, Address(rscratch1, 0));
+#else
+    ShouldNotReachHere();
+#endif
   } else {
-    __ testl(rax, polling_page);
+    AddressLiteral polling_page(os::get_polling_page(), relocInfo::poll_return_type);
+
+    if (Assembler::is_polling_page_far()) {
+      __ lea(rscratch1, polling_page);
+      __ relocate(relocInfo::poll_return_type);
+      __ testl(rax, Address(rscratch1, 0));
+    } else {
+      __ testl(rax, polling_page);
+    }
   }
   __ ret(0);
 }
 
 
 int LIR_Assembler::safepoint_poll(LIR_Opr tmp, CodeEmitInfo* info) {
-  AddressLiteral polling_page(os::get_polling_page(), relocInfo::poll_type);
   guarantee(info != NULL, "Shouldn't be NULL");
   int offset = __ offset();
-  if (Assembler::is_polling_page_far()) {
-    __ lea(rscratch1, polling_page);
-    offset = __ offset();
+  if (SafepointMechanism::uses_thread_local_poll()) {
+#ifdef _LP64
+    __ movptr(rscratch1, Address(r15_thread, Thread::polling_page_offset()));
     add_debug_info_for_branch(info);
     __ relocate(relocInfo::poll_type);
+    address pre_pc = __ pc();
     __ testl(rax, Address(rscratch1, 0));
+    address post_pc = __ pc();
+    guarantee(pointer_delta(post_pc, pre_pc, 1) == 3, "must be exact length");
+#else
+    ShouldNotReachHere();
+#endif
   } else {
-    add_debug_info_for_branch(info);
-    __ testl(rax, polling_page);
+    AddressLiteral polling_page(os::get_polling_page(), relocInfo::poll_type);
+    if (Assembler::is_polling_page_far()) {
+      __ lea(rscratch1, polling_page);
+      offset = __ offset();
+      add_debug_info_for_branch(info);
+      __ relocate(relocInfo::poll_type);
+      __ testl(rax, Address(rscratch1, 0));
+    } else {
+      add_debug_info_for_branch(info);
+      __ testl(rax, polling_page);
+    }
   }
   return offset;
 }
--- a/src/hotspot/cpu/x86/globalDefinitions_x86.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/globalDefinitions_x86.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, 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
@@ -65,4 +65,9 @@
 #define SUPPORT_RESERVED_STACK_AREA
 #endif
 
+#ifdef _LP64
+// X64 have implemented the local polling
+#define THREAD_LOCAL_POLL
+#endif
+
 #endif // CPU_X86_VM_GLOBALDEFINITIONS_X86_HPP
--- a/src/hotspot/cpu/x86/globals_x86.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/globals_x86.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -97,6 +97,12 @@
 
 define_pd_global(intx, InitArrayShortSize, 8*BytesPerLong);
 
+#ifdef _LP64
+define_pd_global(bool, ThreadLocalHandshakes, true);
+#else
+define_pd_global(bool, ThreadLocalHandshakes, false);
+#endif
+
 #define ARCH_FLAGS(develop, \
                    product, \
                    diagnostic, \
--- a/src/hotspot/cpu/x86/interp_masm_x86.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/interp_masm_x86.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -35,6 +35,7 @@
 #include "prims/jvmtiThreadState.hpp"
 #include "runtime/basicLock.hpp"
 #include "runtime/biasedLocking.hpp"
+#include "runtime/safepointMechanism.hpp"
 #include "runtime/sharedRuntime.hpp"
 #include "runtime/thread.inline.hpp"
 
@@ -809,7 +810,8 @@
 
 void InterpreterMacroAssembler::dispatch_base(TosState state,
                                               address* table,
-                                              bool verifyoop) {
+                                              bool verifyoop,
+                                              bool generate_poll) {
   verify_FPU(1, state);
   if (VerifyActivationFrameSize) {
     Label L;
@@ -827,8 +829,24 @@
     verify_oop(rax, state);
   }
 #ifdef _LP64
+
+  Label no_safepoint, dispatch;
+  address* const safepoint_table = Interpreter::safept_table(state);
+  if (SafepointMechanism::uses_thread_local_poll() && table != safepoint_table && generate_poll) {
+    NOT_PRODUCT(block_comment("Thread-local Safepoint poll"));
+
+    testb(Address(r15_thread, Thread::polling_page_offset()), SafepointMechanism::poll_bit());
+
+    jccb(Assembler::zero, no_safepoint);
+    lea(rscratch1, ExternalAddress((address)safepoint_table));
+    jmpb(dispatch);
+  }
+
+  bind(no_safepoint);
   lea(rscratch1, ExternalAddress((address)table));
+  bind(dispatch);
   jmp(Address(rscratch1, rbx, Address::times_8));
+
 #else
   Address index(noreg, rbx, Address::times_ptr);
   ExternalAddress tbl((address)table);
@@ -837,8 +855,8 @@
 #endif // _LP64
 }
 
-void InterpreterMacroAssembler::dispatch_only(TosState state) {
-  dispatch_base(state, Interpreter::dispatch_table(state));
+void InterpreterMacroAssembler::dispatch_only(TosState state, bool generate_poll) {
+  dispatch_base(state, Interpreter::dispatch_table(state), true, generate_poll);
 }
 
 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
@@ -850,12 +868,12 @@
 }
 
 
-void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
+void InterpreterMacroAssembler::dispatch_next(TosState state, int step, bool generate_poll) {
   // load next bytecode (load before advancing _bcp_register to prevent AGI)
   load_unsigned_byte(rbx, Address(_bcp_register, step));
   // advance _bcp_register
   increment(_bcp_register, step);
-  dispatch_base(state, Interpreter::dispatch_table(state));
+  dispatch_base(state, Interpreter::dispatch_table(state), true, generate_poll);
 }
 
 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
--- a/src/hotspot/cpu/x86/interp_masm_x86.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/interp_masm_x86.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -49,7 +49,7 @@
                             bool check_exceptions);
 
   // base routine for all dispatches
-  void dispatch_base(TosState state, address* table, bool verifyoop = true);
+  void dispatch_base(TosState state, address* table, bool verifyoop = true, bool generate_poll = false);
 
  public:
   InterpreterMacroAssembler(CodeBuffer* code) : MacroAssembler(code),
@@ -184,12 +184,12 @@
   void dispatch_prolog(TosState state, int step = 0);
   void dispatch_epilog(TosState state, int step = 0);
   // dispatch via rbx (assume rbx is loaded already)
-  void dispatch_only(TosState state);
+  void dispatch_only(TosState state, bool generate_poll = false);
   // dispatch normal table via rbx (assume rbx is loaded already)
   void dispatch_only_normal(TosState state);
   void dispatch_only_noverify(TosState state);
   // load rbx from [_bcp_register + step] and dispatch via rbx
-  void dispatch_next(TosState state, int step = 0);
+  void dispatch_next(TosState state, int step = 0, bool generate_poll = false);
   // load rbx from [_bcp_register] and dispatch via rbx and table
   void dispatch_via (TosState state, address* table);
 
--- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -38,6 +38,8 @@
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/objectMonitor.hpp"
 #include "runtime/os.hpp"
+#include "runtime/safepoint.hpp"
+#include "runtime/safepointMechanism.hpp"
 #include "runtime/sharedRuntime.hpp"
 #include "runtime/stubRoutines.hpp"
 #include "runtime/thread.hpp"
@@ -3759,6 +3761,25 @@
   movl(as_Address(ArrayAddress(page, index)), tmp);
 }
 
+#ifdef _LP64
+void MacroAssembler::safepoint_poll(Label& slow_path, Register thread_reg, Register temp_reg) {
+  if (SafepointMechanism::uses_thread_local_poll()) {
+    testb(Address(r15_thread, Thread::polling_page_offset()), SafepointMechanism::poll_bit());
+    jcc(Assembler::notZero, slow_path); // handshake bit set implies poll
+  } else {
+    cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
+        SafepointSynchronize::_not_synchronized);
+    jcc(Assembler::notEqual, slow_path);
+  }
+}
+#else
+void MacroAssembler::safepoint_poll(Label& slow_path) {
+  cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
+      SafepointSynchronize::_not_synchronized);
+  jcc(Assembler::notEqual, slow_path);
+}
+#endif
+
 // Calls to C land
 //
 // When entering C land, the rbp, & rsp of the last Java frame have to be recorded
--- a/src/hotspot/cpu/x86/macroAssembler_x86.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/macroAssembler_x86.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -656,6 +656,12 @@
   // Support for serializing memory accesses between threads
   void serialize_memory(Register thread, Register tmp);
 
+#ifdef _LP64
+  void safepoint_poll(Label& slow_path, Register thread_reg, Register temp_reg);
+#else
+  void safepoint_poll(Label& slow_path);
+#endif
+
   void verify_tlab();
 
   // Biased locking support
--- a/src/hotspot/cpu/x86/nativeInst_x86.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/nativeInst_x86.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -29,6 +29,7 @@
 #include "memory/allocation.hpp"
 #include "runtime/icache.hpp"
 #include "runtime/os.hpp"
+#include "runtime/safepointMechanism.hpp"
 
 // We have interfaces for the following instructions:
 // - NativeInstruction
@@ -678,6 +679,7 @@
   enum Intel_specific_constants {
     instruction_rex_prefix_mask = 0xF0,
     instruction_rex_prefix      = Assembler::REX,
+    instruction_rex_b_prefix    = Assembler::REX_B,
     instruction_code_memXregl   = 0x85,
     modrm_mask                  = 0x38, // select reg from the ModRM byte
     modrm_reg                   = 0x00  // rax
@@ -703,6 +705,16 @@
                                                           (ubyte_at(0) & 0xF0) == 0x70;  /* short jump */ }
 inline bool NativeInstruction::is_safepoint_poll() {
 #ifdef AMD64
+  if (SafepointMechanism::uses_thread_local_poll()) {
+    // We know that the poll must have a REX_B prefix since we enforce its source to be
+    // a rex-register and the destination to be rax.
+    const bool has_rex_prefix = ubyte_at(0) == NativeTstRegMem::instruction_rex_b_prefix;
+    const bool is_test_opcode = ubyte_at(1) == NativeTstRegMem::instruction_code_memXregl;
+    const bool is_rax_target = (ubyte_at(2) & NativeTstRegMem::modrm_mask) == NativeTstRegMem::modrm_reg;
+    if (has_rex_prefix && is_test_opcode && is_rax_target) {
+      return true;
+    }
+  }
   // Try decoding a near safepoint first:
   if (ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl &&
       ubyte_at(1) == 0x05) { // 00 rax 101
--- a/src/hotspot/cpu/x86/relocInfo_x86.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/relocInfo_x86.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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
@@ -29,6 +29,7 @@
 #include "oops/klass.inline.hpp"
 #include "oops/oop.inline.hpp"
 #include "runtime/safepoint.hpp"
+#include "runtime/safepointMechanism.hpp"
 
 
 void Relocation::pd_set_data_value(address x, intptr_t o, bool verify_only) {
@@ -183,9 +184,12 @@
   typedef Assembler::WhichOperand WhichOperand;
   WhichOperand which = (WhichOperand) format();
 #if !INCLUDE_JVMCI
-  assert((which == Assembler::disp32_operand) == !Assembler::is_polling_page_far(), "format not set correctly");
+  if (SafepointMechanism::uses_global_page_poll()) {
+    assert((which == Assembler::disp32_operand) == !Assembler::is_polling_page_far(), "format not set correctly");
+  }
 #endif
   if (which == Assembler::disp32_operand) {
+    assert(SafepointMechanism::uses_global_page_poll(), "should only have generated such a poll if global polling enabled");
     address orig_addr = old_addr_for(addr(), src, dest);
     NativeInstruction* oni = nativeInstruction_at(orig_addr);
     int32_t* orig_disp = (int32_t*) Assembler::locate_operand(orig_addr, which);
--- a/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -30,6 +30,7 @@
 #include "asm/macroAssembler.inline.hpp"
 #include "code/debugInfoRec.hpp"
 #include "code/icBuffer.hpp"
+#include "code/nativeInst.hpp"
 #include "code/vtableStubs.hpp"
 #include "interpreter/interpreter.hpp"
 #include "logging/log.hpp"
@@ -2474,15 +2475,13 @@
   // check for safepoint operation in progress and/or pending suspend requests
   {
     Label Continue;
-
-    __ cmp32(ExternalAddress((address)SafepointSynchronize::address_of_state()),
-             SafepointSynchronize::_not_synchronized);
-
-    Label L;
-    __ jcc(Assembler::notEqual, L);
+    Label slow_path;
+
+    __ safepoint_poll(slow_path, r15_thread, rscratch1);
+
     __ cmpl(Address(r15_thread, JavaThread::suspend_flags_offset()), 0);
     __ jcc(Assembler::equal, Continue);
-    __ bind(L);
+    __ bind(slow_path);
 
     // Don't use call_VM as it will see a possible pending exception and forward it
     // and never return here preventing us from clearing _last_native_pc down below.
@@ -3355,9 +3354,11 @@
   // sees an invalid pc.
 
   if (!cause_return) {
-    // overwrite the dummy value we pushed on entry
-    __ movptr(c_rarg0, Address(r15_thread, JavaThread::saved_exception_pc_offset()));
-    __ movptr(Address(rbp, wordSize), c_rarg0);
+    // Get the return pc saved by the signal handler and stash it in its appropriate place on the stack.
+    // Additionally, rbx is a callee saved register and we can look at it later to determine
+    // if someone changed the return address for us!
+    __ movptr(rbx, Address(r15_thread, JavaThread::saved_exception_pc_offset()));
+    __ movptr(Address(rbp, wordSize), rbx);
   }
 
   // Do the call
@@ -3387,11 +3388,38 @@
   // No exception case
   __ bind(noException);
 
+  Label no_adjust, bail;
+  if (SafepointMechanism::uses_thread_local_poll() && !cause_return) {
+    // If our stashed return pc was modified by the runtime we avoid touching it
+    __ cmpptr(rbx, Address(rbp, wordSize));
+    __ jccb(Assembler::notEqual, no_adjust);
+
+#ifdef ASSERT
+    // Verify the correct encoding of the poll we're about to skip.
+    // See NativeInstruction::is_safepoint_poll()
+    __ cmpb(Address(rbx, 0), NativeTstRegMem::instruction_rex_b_prefix);
+    __ jcc(Assembler::notEqual, bail);
+    __ cmpb(Address(rbx, 1), NativeTstRegMem::instruction_code_memXregl);
+    __ jcc(Assembler::notEqual, bail);
+    // Mask out the modrm bits
+    __ testb(Address(rbx, 2), NativeTstRegMem::modrm_mask);
+    // rax encodes to 0, so if the bits are nonzero it's incorrect
+    __ jcc(Assembler::notZero, bail);
+#endif
+    // Adjust return pc forward to step over the safepoint poll instruction
+    __ addptr(Address(rbp, wordSize), 3);
+  }
+
+  __ bind(no_adjust);
   // Normal exit, restore registers and exit.
   RegisterSaver::restore_live_registers(masm, save_vectors);
-
   __ ret(0);
 
+#ifdef ASSERT
+  __ bind(bail);
+  __ stop("Attempting to adjust pc to skip safepoint poll but the return point is not what we expected");
+#endif
+
   // Make sure all code is generated
   masm->flush();
 
--- a/src/hotspot/cpu/x86/templateInterpreterGenerator_x86.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/templateInterpreterGenerator_x86.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -237,7 +237,7 @@
 }
 
 
-address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) {
+address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step, address continuation) {
   address entry = __ pc();
 
 #ifndef _LP64
@@ -291,7 +291,11 @@
     __ should_not_reach_here();
     __ bind(L);
   }
-  __ dispatch_next(state, step);
+  if (continuation == NULL) {
+    __ dispatch_next(state, step);
+  } else {
+    __ jump_to_entry(continuation);
+  }
   return entry;
 }
 
@@ -1141,14 +1145,17 @@
   // check for safepoint operation in progress and/or pending suspend requests
   {
     Label Continue;
-    __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
-             SafepointSynchronize::_not_synchronized);
+    Label slow_path;
 
-    Label L;
-    __ jcc(Assembler::notEqual, L);
+#ifndef _LP64
+    __ safepoint_poll(slow_path);
+#else
+    __ safepoint_poll(slow_path, r15_thread, rscratch1);
+#endif
+
     __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0);
     __ jcc(Assembler::equal, Continue);
-    __ bind(L);
+    __ bind(slow_path);
 
     // Don't use call_VM as it will see a possible pending exception
     // and forward it and never return here preventing us from
--- a/src/hotspot/cpu/x86/templateInterpreterGenerator_x86_64.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/templateInterpreterGenerator_x86_64.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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
@@ -190,11 +190,7 @@
     // c_rarg1: scratch (rsi on non-Win64, rdx on Win64)
 
     Label slow_path;
-    // If we need a safepoint check, generate full interpreter entry.
-    ExternalAddress state(SafepointSynchronize::address_of_state());
-    __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
-             SafepointSynchronize::_not_synchronized);
-    __ jcc(Assembler::notEqual, slow_path);
+    __ safepoint_poll(slow_path, r15_thread, rscratch1);
 
     // We don't generate local frame and don't align stack because
     // we call stub code and there is no safepoint on this path.
@@ -240,11 +236,7 @@
     // r13: senderSP must preserved for slow path, set SP to it on fast path
 
     Label slow_path;
-    // If we need a safepoint check, generate full interpreter entry.
-    ExternalAddress state(SafepointSynchronize::address_of_state());
-    __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
-             SafepointSynchronize::_not_synchronized);
-    __ jcc(Assembler::notEqual, slow_path);
+    __ safepoint_poll(slow_path, r15_thread, rscratch1);
 
     // We don't generate local frame and don't align stack because
     // we call stub code and there is no safepoint on this path.
--- a/src/hotspot/cpu/x86/templateTable_x86.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/templateTable_x86.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -2084,7 +2084,7 @@
     __ addptr(rbcp, rdx);
     // jsr returns atos that is not an oop
     __ push_i(rax);
-    __ dispatch_only(vtos);
+    __ dispatch_only(vtos, true);
     return;
   }
 
@@ -2203,7 +2203,7 @@
   // rax: return bci for jsr's, unused otherwise
   // rbx: target bytecode
   // r13: target bcp
-  __ dispatch_only(vtos);
+  __ dispatch_only(vtos, true);
 
   if (UseLoopCounter) {
     if (ProfileInterpreter) {
@@ -2332,7 +2332,7 @@
   __ movptr(rbcp, Address(rax, Method::const_offset()));
   __ lea(rbcp, Address(rbcp, rbx, Address::times_1,
                       ConstMethod::codes_offset()));
-  __ dispatch_next(vtos);
+  __ dispatch_next(vtos, 0, true);
 }
 
 void TemplateTable::wide_ret() {
@@ -2343,7 +2343,7 @@
   __ get_method(rax);
   __ movptr(rbcp, Address(rax, Method::const_offset()));
   __ lea(rbcp, Address(rbcp, rbx, Address::times_1, ConstMethod::codes_offset()));
-  __ dispatch_next(vtos);
+  __ dispatch_next(vtos, 0, true);
 }
 
 void TemplateTable::tableswitch() {
@@ -2373,7 +2373,7 @@
   LP64_ONLY(__ movl2ptr(rdx, rdx));
   __ load_unsigned_byte(rbx, Address(rbcp, rdx, Address::times_1));
   __ addptr(rbcp, rdx);
-  __ dispatch_only(vtos);
+  __ dispatch_only(vtos, true);
   // handle default
   __ bind(default_case);
   __ profile_switch_default(rax);
@@ -2421,7 +2421,7 @@
   __ movl2ptr(rdx, rdx);
   __ load_unsigned_byte(rbx, Address(rbcp, rdx, Address::times_1));
   __ addptr(rbcp, rdx);
-  __ dispatch_only(vtos);
+  __ dispatch_only(vtos, true);
 }
 
 void TemplateTable::fast_binaryswitch() {
@@ -2525,7 +2525,7 @@
 
   __ load_unsigned_byte(rbx, Address(rbcp, j, Address::times_1));
   __ addptr(rbcp, j);
-  __ dispatch_only(vtos);
+  __ dispatch_only(vtos, true);
 
   // default case -> j = default offset
   __ bind(default_case);
@@ -2539,7 +2539,7 @@
 
   __ load_unsigned_byte(rbx, Address(rbcp, j, Address::times_1));
   __ addptr(rbcp, j);
-  __ dispatch_only(vtos);
+  __ dispatch_only(vtos, true);
 }
 
 void TemplateTable::_return(TosState state) {
@@ -2563,10 +2563,17 @@
     __ bind(skip_register_finalizer);
   }
 
-  // Explicitly reset last_sp, for handling special case in TemplateInterpreter::deopt_reexecute_entry
-#ifdef ASSERT
-  if (state == vtos) {
-    __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
+#ifdef _LP64
+  if (SafepointMechanism::uses_thread_local_poll() && _desc->bytecode() != Bytecodes::_return_register_finalizer) {
+    Label no_safepoint;
+    NOT_PRODUCT(__ block_comment("Thread-local Safepoint poll"));
+    __ testb(Address(r15_thread, Thread::polling_page_offset()), SafepointMechanism::poll_bit());
+    __ jcc(Assembler::zero, no_safepoint);
+    __ push(state);
+    __ call_VM(noreg, CAST_FROM_FN_PTR(address,
+                                    InterpreterRuntime::at_safepoint));
+    __ pop(state);
+    __ bind(no_safepoint);
   }
 #endif
 
--- a/src/hotspot/cpu/x86/x86_64.ad	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/x86/x86_64.ad	Mon Nov 27 10:35:05 2017 -0800
@@ -317,6 +317,18 @@
 // Singleton class for TLS pointer
 reg_class ptr_r15_reg(R15, R15_H);
 
+// The registers which can be used for
+// a thread local safepoint poll
+// * R12 is reserved for heap base
+// * R13 cannot be encoded for addressing without an offset byte
+// * R15 is reserved for the JavaThread
+reg_class ptr_rex_reg(R8,  R8_H,
+                      R9,  R9_H,
+                      R10, R10_H,
+                      R11, R11_H,
+                      R14, R14_H);
+
+
 // Class for all long registers (excluding RSP)
 reg_class long_reg_with_rbp(RAX, RAX_H,
                             RDX, RDX_H,
@@ -566,7 +578,7 @@
 // it does if the polling page is more than disp32 away.
 bool SafePointNode::needs_polling_address_input()
 {
-  return Assembler::is_polling_page_far();
+  return SafepointMechanism::uses_thread_local_poll() || Assembler::is_polling_page_far();
 }
 
 //
@@ -938,7 +950,11 @@
   st->print_cr("popq   rbp");
   if (do_polling() && C->is_method_compilation()) {
     st->print("\t");
-    if (Assembler::is_polling_page_far()) {
+    if (SafepointMechanism::uses_thread_local_poll()) {
+      st->print_cr("movq   rscratch1, poll_offset[r15_thread] #polling_page_address\n\t"
+                   "testl  rax, [rscratch1]\t"
+                   "# Safepoint: poll for GC");
+    } else if (Assembler::is_polling_page_far()) {
       st->print_cr("movq   rscratch1, #polling_page_address\n\t"
                    "testl  rax, [rscratch1]\t"
                    "# Safepoint: poll for GC");
@@ -989,13 +1005,19 @@
 
   if (do_polling() && C->is_method_compilation()) {
     MacroAssembler _masm(&cbuf);
-    AddressLiteral polling_page(os::get_polling_page(), relocInfo::poll_return_type);
-    if (Assembler::is_polling_page_far()) {
-      __ lea(rscratch1, polling_page);
+    if (SafepointMechanism::uses_thread_local_poll()) {
+      __ movq(rscratch1, Address(r15_thread, Thread::polling_page_offset()));
       __ relocate(relocInfo::poll_return_type);
       __ testl(rax, Address(rscratch1, 0));
     } else {
-      __ testl(rax, polling_page);
+      AddressLiteral polling_page(os::get_polling_page(), relocInfo::poll_return_type);
+      if (Assembler::is_polling_page_far()) {
+        __ lea(rscratch1, polling_page);
+        __ relocate(relocInfo::poll_return_type);
+        __ testl(rax, Address(rscratch1, 0));
+      } else {
+        __ testl(rax, polling_page);
+      }
     }
   }
 }
@@ -3511,6 +3533,16 @@
   interface(REG_INTER);
 %}
 
+operand rex_RegP()
+%{
+  constraint(ALLOC_IN_RC(ptr_rex_reg));
+  match(RegP);
+  match(rRegP);
+
+  format %{ %}
+  interface(REG_INTER);
+%}
+
 operand rRegL()
 %{
   constraint(ALLOC_IN_RC(long_reg));
@@ -12060,7 +12092,7 @@
 // Safepoint Instructions
 instruct safePoint_poll(rFlagsReg cr)
 %{
-  predicate(!Assembler::is_polling_page_far());
+  predicate(!Assembler::is_polling_page_far() && SafepointMechanism::uses_global_page_poll());
   match(SafePoint);
   effect(KILL cr);
 
@@ -12076,7 +12108,7 @@
 
 instruct safePoint_poll_far(rFlagsReg cr, rRegP poll)
 %{
-  predicate(Assembler::is_polling_page_far());
+  predicate(Assembler::is_polling_page_far() && SafepointMechanism::uses_global_page_poll());
   match(SafePoint poll);
   effect(KILL cr, USE poll);
 
@@ -12090,6 +12122,26 @@
   ins_pipe(ialu_reg_mem);
 %}
 
+instruct safePoint_poll_tls(rFlagsReg cr, rex_RegP poll)
+%{
+  predicate(SafepointMechanism::uses_thread_local_poll());
+  match(SafePoint poll);
+  effect(KILL cr, USE poll);
+
+  format %{ "testl  rax, [$poll]\t"
+            "# Safepoint: poll for GC" %}
+  ins_cost(125);
+  size(3); /* setting an explicit size will cause debug builds to assert if size is incorrect */
+  ins_encode %{
+    __ relocate(relocInfo::poll_type);
+    address pre_pc = __ pc();
+    __ testl(rax, Address($poll$$Register, 0));
+    address post_pc = __ pc();
+    guarantee(pre_pc[0] == 0x41 && pre_pc[1] == 0x85, "must emit #rex test-ax [reg]");
+  %}
+  ins_pipe(ialu_reg_mem);
+%}
+
 // ============================================================================
 // Procedure Call/Return Instructions
 // Call Java Static Instruction
--- a/src/hotspot/cpu/zero/cppInterpreter_zero.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/zero/cppInterpreter_zero.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -379,7 +379,7 @@
 
   // Handle safepoint operations, pending suspend requests,
   // and pending asynchronous exceptions.
-  if (SafepointSynchronize::do_call_back() ||
+  if (SafepointMechanism::poll(thread) ||
       thread->has_special_condition_for_native_trans()) {
     JavaThread::check_special_condition_for_native_trans(thread);
     CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops());
@@ -511,7 +511,7 @@
   intptr_t *locals = stack->sp();
 
   // Drop into the slow path if we need a safepoint check
-  if (SafepointSynchronize::do_call_back()) {
+  if (SafepointMechanism::poll(THREAD)) {
     return normal_entry(method, 0, THREAD);
   }
 
@@ -643,7 +643,7 @@
   ZeroStack *stack = thread->zero_stack();
 
   // Drop into the slow path if we need a safepoint check
-  if (SafepointSynchronize::do_call_back()) {
+  if (SafepointMechanism::poll(THREAD)) {
     return normal_entry(method, 0, THREAD);
   }
 
--- a/src/hotspot/cpu/zero/globals_zero.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/cpu/zero/globals_zero.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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.
  * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -81,6 +81,8 @@
 // No performance work done here yet.
 define_pd_global(bool, CompactStrings, false);
 
+define_pd_global(bool, ThreadLocalHandshakes, false);
+
 #define ARCH_FLAGS(develop, \
                    product, \
                    diagnostic, \
--- a/src/hotspot/os/aix/os_aix.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/os/aix/os_aix.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -3477,75 +3477,6 @@
     LoadedLibraries::print(tty);
   }
 
-  const int page_size = Aix::page_size();
-  const int map_size = page_size;
-
-  address map_address = (address) MAP_FAILED;
-  const int prot  = PROT_READ;
-  const int flags = MAP_PRIVATE|MAP_ANONYMOUS;
-
-  // Use optimized addresses for the polling page,
-  // e.g. map it to a special 32-bit address.
-  if (OptimizePollingPageLocation) {
-    // architecture-specific list of address wishes:
-    address address_wishes[] = {
-      // AIX: addresses lower than 0x30000000 don't seem to work on AIX.
-      // PPC64: all address wishes are non-negative 32 bit values where
-      // the lower 16 bits are all zero. we can load these addresses
-      // with a single ppc_lis instruction.
-      (address) 0x30000000, (address) 0x31000000,
-      (address) 0x32000000, (address) 0x33000000,
-      (address) 0x40000000, (address) 0x41000000,
-      (address) 0x42000000, (address) 0x43000000,
-      (address) 0x50000000, (address) 0x51000000,
-      (address) 0x52000000, (address) 0x53000000,
-      (address) 0x60000000, (address) 0x61000000,
-      (address) 0x62000000, (address) 0x63000000
-    };
-    int address_wishes_length = sizeof(address_wishes)/sizeof(address);
-
-    // iterate over the list of address wishes:
-    for (int i=0; i<address_wishes_length; i++) {
-      // Try to map with current address wish.
-      // AIX: AIX needs MAP_FIXED if we provide an address and mmap will
-      // fail if the address is already mapped.
-      map_address = (address) ::mmap(address_wishes[i] - (ssize_t)page_size,
-                                     map_size, prot,
-                                     flags | MAP_FIXED,
-                                     -1, 0);
-      trcVerbose("SafePoint Polling  Page address: %p (wish) => %p",
-                   address_wishes[i], map_address + (ssize_t)page_size);
-
-      if (map_address + (ssize_t)page_size == address_wishes[i]) {
-        // Map succeeded and map_address is at wished address, exit loop.
-        break;
-      }
-
-      if (map_address != (address) MAP_FAILED) {
-        // Map succeeded, but polling_page is not at wished address, unmap and continue.
-        ::munmap(map_address, map_size);
-        map_address = (address) MAP_FAILED;
-      }
-      // Map failed, continue loop.
-    }
-  } // end OptimizePollingPageLocation
-
-  if (map_address == (address) MAP_FAILED) {
-    map_address = (address) ::mmap(NULL, map_size, prot, flags, -1, 0);
-  }
-  guarantee(map_address != MAP_FAILED, "os::init_2: failed to allocate polling page");
-  os::set_polling_page(map_address);
-
-  if (!UseMembar) {
-    address mem_serialize_page = (address) ::mmap(NULL, Aix::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
-    guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page");
-    os::set_memory_serialize_page(mem_serialize_page);
-
-    trcVerbose("Memory Serialize  Page address: %p - %p, size %IX (%IB)",
-        mem_serialize_page, mem_serialize_page + Aix::page_size(),
-        Aix::page_size(), Aix::page_size());
-  }
-
   // initialize suspend/resume support - must do this before signal_sets_init()
   if (SR_initialize() != 0) {
     perror("SR_initialize failed");
@@ -3614,6 +3545,14 @@
 };
 
 int os::active_processor_count() {
+  // User has overridden the number of active processors
+  if (ActiveProcessorCount > 0) {
+    log_trace(os)("active_processor_count: "
+                  "active processor count set by user : %d",
+                  ActiveProcessorCount);
+    return ActiveProcessorCount;
+  }
+
   int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
   assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
   return online_cpus;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/aix/safepointMechanism_aix.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,85 @@
+/*
+ * 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 "logging/log.hpp"
+#include "runtime/globals.hpp"
+#include "runtime/os.hpp"
+#include "runtime/safepointMechanism.hpp"
+#include <sys/mman.h>
+
+void SafepointMechanism::pd_initialize() {
+  char* map_address = (char*)MAP_FAILED;
+  const size_t page_size = os::vm_page_size();
+  // Use optimized addresses for the polling page,
+  // e.g. map it to a special 32-bit address.
+  if (OptimizePollingPageLocation) {
+    // architecture-specific list of address wishes:
+    char* address_wishes[] = {
+        // AIX: addresses lower than 0x30000000 don't seem to work on AIX.
+        // PPC64: all address wishes are non-negative 32 bit values where
+        // the lower 16 bits are all zero. we can load these addresses
+        // with a single ppc_lis instruction.
+        (char*) 0x30000000, (char*) 0x31000000,
+        (char*) 0x32000000, (char*) 0x33000000,
+        (char*) 0x40000000, (char*) 0x41000000,
+        (char*) 0x42000000, (char*) 0x43000000,
+        (char*) 0x50000000, (char*) 0x51000000,
+        (char*) 0x52000000, (char*) 0x53000000,
+        (char*) 0x60000000, (char*) 0x61000000,
+        (char*) 0x62000000, (char*) 0x63000000
+    };
+    int address_wishes_length = sizeof(address_wishes)/sizeof(char*);
+
+    // iterate over the list of address wishes:
+    for (int i = 0; i < address_wishes_length; i++) {
+      // Try to map with current address wish.
+      // AIX: AIX needs MAP_FIXED if we provide an address and mmap will
+      // fail if the address is already mapped.
+      map_address = (char*) ::mmap(address_wishes[i] - (ssize_t)page_size,
+                                   page_size, PROT_READ,
+                                   MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
+                                   -1, 0);
+      log_debug(os)("SafePoint Polling  Page address: %p (wish) => %p",
+                    address_wishes[i], map_address + (ssize_t)page_size);
+
+      if (map_address + (ssize_t)page_size == address_wishes[i]) {
+        // Map succeeded and map_address is at wished address, exit loop.
+        break;
+      }
+
+      if (map_address != (char*)MAP_FAILED) {
+        // Map succeeded, but polling_page is not at wished address, unmap and continue.
+        ::munmap(map_address, page_size);
+        map_address = (char*)MAP_FAILED;
+      }
+      // Map failed, continue loop.
+    }
+  }
+  if (map_address == (char*)MAP_FAILED) {
+    map_address = os::reserve_memory(page_size, NULL, page_size);
+  }
+  guarantee(map_address != (char*)MAP_FAILED, "SafepointMechanism::pd_initialize: failed to allocate polling page");
+  os::set_polling_page((address)(map_address));
+}
--- a/src/hotspot/os/bsd/os_bsd.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/os/bsd/os_bsd.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -3391,20 +3391,6 @@
 
   os::Posix::init_2();
 
-  // Allocate a single page and mark it as readable for safepoint polling
-  address polling_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
-  guarantee(polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page");
-
-  os::set_polling_page(polling_page);
-  log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
-
-  if (!UseMembar) {
-    address mem_serialize_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
-    guarantee(mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
-    os::set_memory_serialize_page(mem_serialize_page);
-    log_info(os)("Memory Serialize Page address: " INTPTR_FORMAT, p2i(mem_serialize_page));
-  }
-
   // initialize suspend/resume support - must do this before signal_sets_init()
   if (SR_initialize() != 0) {
     perror("SR_initialize failed");
@@ -3491,6 +3477,14 @@
 }
 
 int os::active_processor_count() {
+  // User has overridden the number of active processors
+  if (ActiveProcessorCount > 0) {
+    log_trace(os)("active_processor_count: "
+                  "active processor count set by user : %d",
+                  ActiveProcessorCount);
+    return ActiveProcessorCount;
+  }
+
   return _processor_count;
 }
 
--- a/src/hotspot/os/linux/globals_linux.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/os/linux/globals_linux.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -59,6 +59,9 @@
   product(bool, UseSHM, false,                                          \
           "Use SYSV shared memory for large pages")                     \
                                                                         \
+  product(bool, UseContainerSupport, true,                              \
+          "Enable detection and runtime container configuration support") \
+                                                                        \
   diagnostic(bool, UseCpuAllocPath, false,                              \
              "Use CPU_ALLOC code path in os::active_processor_count ")
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/linux/osContainer_linux.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,594 @@
+/*
+ * 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 <string.h>
+#include <math.h>
+#include <errno.h>
+#include "utilities/globalDefinitions.hpp"
+#include "memory/allocation.hpp"
+#include "runtime/os.hpp"
+#include "logging/log.hpp"
+#include "osContainer_linux.hpp"
+
+/*
+ * Warning: Some linux distros use 0x7FFFFFFFFFFFF000
+ * and others use 0x7FFFFFFFFFFFFFFF for unlimited.
+ */
+#define UNLIMITED_MEM CONST64(0x7FFFFFFFFFFFF000)
+
+#define PER_CPU_SHARES 1024
+
+bool  OSContainer::_is_initialized   = false;
+bool  OSContainer::_is_containerized = false;
+
+class CgroupSubsystem: CHeapObj<mtInternal> {
+ friend class OSContainer;
+
+ private:
+    /* mountinfo contents */
+    char *_root;
+    char *_mount_point;
+
+    /* Constructed subsystem directory */
+    char *_path;
+
+ public:
+    CgroupSubsystem(char *root, char *mountpoint) {
+      _root = os::strdup(root);
+      _mount_point = os::strdup(mountpoint);
+      _path = NULL;
+    }
+
+    /*
+     * Set directory to subsystem specific files based
+     * on the contents of the mountinfo and cgroup files.
+     */
+    void set_subsystem_path(char *cgroup_path) {
+      char buf[MAXPATHLEN+1];
+      if (_root != NULL && cgroup_path != NULL) {
+        if (strcmp(_root, "/") == 0) {
+          int buflen;
+          strncpy(buf, _mount_point, MAXPATHLEN);
+          buf[MAXPATHLEN-1] = '\0';
+          if (strcmp(cgroup_path,"/") != 0) {
+            buflen = strlen(buf);
+            if ((buflen + strlen(cgroup_path)) > (MAXPATHLEN-1)) {
+              return;
+            }
+            strncat(buf, cgroup_path, MAXPATHLEN-buflen);
+            buf[MAXPATHLEN-1] = '\0';
+          }
+          _path = os::strdup(buf);
+        } else {
+          if (strcmp(_root, cgroup_path) == 0) {
+            strncpy(buf, _mount_point, MAXPATHLEN);
+            buf[MAXPATHLEN-1] = '\0';
+            _path = os::strdup(buf);
+          } else {
+            char *p = strstr(_root, cgroup_path);
+            if (p != NULL && p == _root) {
+              if (strlen(cgroup_path) > strlen(_root)) {
+                int buflen;
+                strncpy(buf, _mount_point, MAXPATHLEN);
+                buf[MAXPATHLEN-1] = '\0';
+                buflen = strlen(buf);
+                if ((buflen + strlen(cgroup_path)) > (MAXPATHLEN-1)) {
+                  return;
+                }
+                strncat(buf, cgroup_path + strlen(_root), MAXPATHLEN-buflen);
+                buf[MAXPATHLEN-1] = '\0';
+                _path = os::strdup(buf);
+              }
+            }
+          }
+        }
+      }
+    }
+
+    char *subsystem_path() { return _path; }
+};
+
+CgroupSubsystem* memory = NULL;
+CgroupSubsystem* cpuset = NULL;
+CgroupSubsystem* cpu = NULL;
+CgroupSubsystem* cpuacct = NULL;
+
+typedef char * cptr;
+
+PRAGMA_DIAG_PUSH
+PRAGMA_FORMAT_NONLITERAL_IGNORED
+template <typename T> int subsystem_file_contents(CgroupSubsystem* c,
+                                              const char *filename,
+                                              const char *scan_fmt,
+                                              T returnval) {
+  FILE *fp = NULL;
+  char *p;
+  char file[MAXPATHLEN+1];
+  char buf[MAXPATHLEN+1];
+
+  if (c != NULL && c->subsystem_path() != NULL) {
+    strncpy(file, c->subsystem_path(), MAXPATHLEN);
+    file[MAXPATHLEN-1] = '\0';
+    int filelen = strlen(file);
+    if ((filelen + strlen(filename)) > (MAXPATHLEN-1)) {
+       log_debug(os, container)("File path too long %s, %s", file, filename);
+       return OSCONTAINER_ERROR;
+    }
+    strncat(file, filename, MAXPATHLEN-filelen);
+    log_trace(os, container)("Path to %s is %s", filename, file);
+    fp = fopen(file, "r");
+    if (fp != NULL) {
+      p = fgets(buf, MAXPATHLEN, fp);
+      if (p != NULL) {
+        int matched = sscanf(p, scan_fmt, returnval);
+        if (matched == 1) {
+          fclose(fp);
+          return 0;
+        } else {
+          log_debug(os, container)("Type %s not found in file %s",
+                                     scan_fmt , file);
+        }
+      } else {
+        log_debug(os, container)("Empty file %s", file);
+      }
+    } else {
+      log_debug(os, container)("Open of file %s failed, %s", file,
+                               os::strerror(errno));
+    }
+  }
+  if (fp != NULL)
+    fclose(fp);
+  return OSCONTAINER_ERROR;
+}
+PRAGMA_DIAG_POP
+
+#define GET_CONTAINER_INFO(return_type, subsystem, filename,              \
+                           logstring, scan_fmt, variable)                 \
+  return_type variable;                                                   \
+{                                                                         \
+  int err;                                                                \
+  err = subsystem_file_contents(subsystem,                                \
+                                filename,                                 \
+                                scan_fmt,                                 \
+                                &variable);                               \
+  if (err != 0)                                                           \
+    return (return_type) OSCONTAINER_ERROR;                               \
+                                                                          \
+  log_trace(os, container)(logstring, variable);                          \
+}
+
+#define GET_CONTAINER_INFO_CPTR(return_type, subsystem, filename,         \
+                               logstring, scan_fmt, variable, bufsize)    \
+  char variable[bufsize];                                                 \
+{                                                                         \
+  int err;                                                                \
+  err = subsystem_file_contents(subsystem,                                \
+                                filename,                                 \
+                                scan_fmt,                                 \
+                                variable);                                \
+  if (err != 0)                                                           \
+    return (return_type) NULL;                                            \
+                                                                          \
+  log_trace(os, container)(logstring, variable);                          \
+}
+
+/* init
+ *
+ * Initialize the container support and determine if
+ * we are running under cgroup control.
+ */
+void OSContainer::init() {
+  int mountid;
+  int parentid;
+  int major;
+  int minor;
+  FILE *mntinfo = NULL;
+  FILE *cgroup = NULL;
+  char buf[MAXPATHLEN+1];
+  char tmproot[MAXPATHLEN+1];
+  char tmpmount[MAXPATHLEN+1];
+  char tmpbase[MAXPATHLEN+1];
+  char *p;
+  jlong mem_limit;
+
+  assert(!_is_initialized, "Initializing OSContainer more than once");
+
+  _is_initialized = true;
+  _is_containerized = false;
+
+  log_trace(os, container)("OSContainer::init: Initializing Container Support");
+  if (!UseContainerSupport) {
+    log_trace(os, container)("Container Support not enabled");
+    return;
+  }
+
+  /*
+   * Find the cgroup mount point for memory and cpuset
+   * by reading /proc/self/mountinfo
+   *
+   * Example for docker:
+   * 219 214 0:29 /docker/7208cebd00fa5f2e342b1094f7bed87fa25661471a4637118e65f1c995be8a34 /sys/fs/cgroup/memory ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,memory
+   *
+   * Example for host:
+   * 34 28 0:29 / /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime shared:16 - cgroup cgroup rw,memory
+   */
+  mntinfo = fopen("/proc/self/mountinfo", "r");
+  if (mntinfo == NULL) {
+      log_debug(os, container)("Can't open /proc/self/mountinfo, %s",
+                               os::strerror(errno));
+      return;
+  }
+
+  while ( (p = fgets(buf, MAXPATHLEN, mntinfo)) != NULL) {
+    // Look for the filesystem type and see if it's cgroup
+    char fstype[MAXPATHLEN+1];
+    fstype[0] = '\0';
+    char *s =  strstr(p, " - ");
+    if (s != NULL &&
+        sscanf(s, " - %s", fstype) == 1 &&
+        strcmp(fstype, "cgroup") == 0) {
+
+      if (strstr(p, "memory") != NULL) {
+        int matched = sscanf(p, "%d %d %d:%d %s %s",
+                             &mountid,
+                             &parentid,
+                             &major,
+                             &minor,
+                             tmproot,
+                             tmpmount);
+        if (matched == 6) {
+          memory = new CgroupSubsystem(tmproot, tmpmount);
+        }
+        else
+          log_debug(os, container)("Incompatible str containing cgroup and memory: %s", p);
+      } else if (strstr(p, "cpuset") != NULL) {
+        int matched = sscanf(p, "%d %d %d:%d %s %s",
+                             &mountid,
+                             &parentid,
+                             &major,
+                             &minor,
+                             tmproot,
+                             tmpmount);
+        if (matched == 6) {
+          cpuset = new CgroupSubsystem(tmproot, tmpmount);
+        }
+        else {
+          log_debug(os, container)("Incompatible str containing cgroup and cpuset: %s", p);
+        }
+      } else if (strstr(p, "cpu,cpuacct") != NULL) {
+        int matched = sscanf(p, "%d %d %d:%d %s %s",
+                             &mountid,
+                             &parentid,
+                             &major,
+                             &minor,
+                             tmproot,
+                             tmpmount);
+        if (matched == 6) {
+          cpu = new CgroupSubsystem(tmproot, tmpmount);
+          cpuacct = new CgroupSubsystem(tmproot, tmpmount);
+        }
+        else {
+          log_debug(os, container)("Incompatible str containing cgroup and cpu,cpuacct: %s", p);
+        }
+      } else if (strstr(p, "cpuacct") != NULL) {
+        int matched = sscanf(p, "%d %d %d:%d %s %s",
+                             &mountid,
+                             &parentid,
+                             &major,
+                             &minor,
+                             tmproot,
+                             tmpmount);
+        if (matched == 6) {
+          cpuacct = new CgroupSubsystem(tmproot, tmpmount);
+        }
+        else {
+          log_debug(os, container)("Incompatible str containing cgroup and cpuacct: %s", p);
+        }
+      } else if (strstr(p, "cpu") != NULL) {
+        int matched = sscanf(p, "%d %d %d:%d %s %s",
+                             &mountid,
+                             &parentid,
+                             &major,
+                             &minor,
+                             tmproot,
+                             tmpmount);
+        if (matched == 6) {
+          cpu = new CgroupSubsystem(tmproot, tmpmount);
+        }
+        else {
+          log_debug(os, container)("Incompatible str containing cgroup and cpu: %s", p);
+        }
+      }
+    }
+  }
+
+  if (mntinfo != NULL) fclose(mntinfo);
+
+  /*
+   * Read /proc/self/cgroup and map host mount point to
+   * local one via /proc/self/mountinfo content above
+   *
+   * Docker example:
+   * 5:memory:/docker/6558aed8fc662b194323ceab5b964f69cf36b3e8af877a14b80256e93aecb044
+   *
+   * Host example:
+   * 5:memory:/user.slice
+   *
+   * Construct a path to the process specific memory and cpuset
+   * cgroup directory.
+   *
+   * For a container running under Docker from memory example above
+   * the paths would be:
+   *
+   * /sys/fs/cgroup/memory
+   *
+   * For a Host from memory example above the path would be:
+   *
+   * /sys/fs/cgroup/memory/user.slice
+   *
+   */
+  cgroup = fopen("/proc/self/cgroup", "r");
+  if (cgroup == NULL) {
+    log_debug(os, container)("Can't open /proc/self/cgroup, %s",
+                             os::strerror(errno));
+    return;
+  }
+
+  while ( (p = fgets(buf, MAXPATHLEN, cgroup)) != NULL) {
+    int cgno;
+    int matched;
+    char *controller;
+    char *base;
+
+    /* Skip cgroup number */
+    strsep(&p, ":");
+    /* Get controller and base */
+    controller = strsep(&p, ":");
+    base = strsep(&p, "\n");
+
+    if (controller != NULL) {
+      if (strstr(controller, "memory") != NULL) {
+        memory->set_subsystem_path(base);
+      } else if (strstr(controller, "cpuset") != NULL) {
+        cpuset->set_subsystem_path(base);
+      } else if (strstr(controller, "cpu,cpuacct") != NULL) {
+        cpu->set_subsystem_path(base);
+        cpuacct->set_subsystem_path(base);
+      } else if (strstr(controller, "cpuacct") != NULL) {
+        cpuacct->set_subsystem_path(base);
+      } else if (strstr(controller, "cpu") != NULL) {
+        cpu->set_subsystem_path(base);
+      }
+    }
+  }
+
+  if (cgroup != NULL) fclose(cgroup);
+
+  if (memory == NULL || cpuset == NULL || cpu == NULL) {
+    log_debug(os, container)("Required cgroup subsystems not found");
+    return;
+  }
+
+  // We need to update the amount of physical memory now that
+  // command line arguments have been processed.
+  if ((mem_limit = memory_limit_in_bytes()) > 0) {
+    os::Linux::set_physical_memory(mem_limit);
+  }
+
+  _is_containerized = true;
+
+}
+
+char * OSContainer::container_type() {
+  if (is_containerized()) {
+    return (char *)"cgroupv1";
+  } else {
+    return NULL;
+  }
+}
+
+
+/* memory_limit_in_bytes
+ *
+ * Return the limit of available memory for this process.
+ *
+ * return:
+ *    memory limit in bytes or
+ *    -1 for unlimited
+ *    OSCONTAINER_ERROR for not supported
+ */
+jlong OSContainer::memory_limit_in_bytes() {
+  GET_CONTAINER_INFO(jlong, memory, "/memory.limit_in_bytes",
+                     "Memory Limit is: " JLONG_FORMAT, JLONG_FORMAT, memlimit);
+
+  if (memlimit >= UNLIMITED_MEM) {
+    log_trace(os, container)("Memory Limit is: Unlimited");
+    return (jlong)-1;
+  }
+  else {
+    return memlimit;
+  }
+}
+
+jlong OSContainer::memory_and_swap_limit_in_bytes() {
+  GET_CONTAINER_INFO(jlong, memory, "/memory.memsw.limit_in_bytes",
+                     "Memory and Swap Limit is: " JLONG_FORMAT, JLONG_FORMAT, memswlimit);
+  if (memswlimit >= UNLIMITED_MEM) {
+    log_trace(os, container)("Memory and Swap Limit is: Unlimited");
+    return (jlong)-1;
+  } else {
+    return memswlimit;
+  }
+}
+
+jlong OSContainer::memory_soft_limit_in_bytes() {
+  GET_CONTAINER_INFO(jlong, memory, "/memory.soft_limit_in_bytes",
+                     "Memory Soft Limit is: " JLONG_FORMAT, JLONG_FORMAT, memsoftlimit);
+  if (memsoftlimit >= UNLIMITED_MEM) {
+    log_trace(os, container)("Memory Soft Limit is: Unlimited");
+    return (jlong)-1;
+  } else {
+    return memsoftlimit;
+  }
+}
+
+/* memory_usage_in_bytes
+ *
+ * Return the amount of used memory for this process.
+ *
+ * return:
+ *    memory usage in bytes or
+ *    -1 for unlimited
+ *    OSCONTAINER_ERROR for not supported
+ */
+jlong OSContainer::memory_usage_in_bytes() {
+  GET_CONTAINER_INFO(jlong, memory, "/memory.usage_in_bytes",
+                     "Memory Usage is: " JLONG_FORMAT, JLONG_FORMAT, memusage);
+  return memusage;
+}
+
+/* memory_max_usage_in_bytes
+ *
+ * Return the maximum amount of used memory for this process.
+ *
+ * return:
+ *    max memory usage in bytes or
+ *    OSCONTAINER_ERROR for not supported
+ */
+jlong OSContainer::memory_max_usage_in_bytes() {
+  GET_CONTAINER_INFO(jlong, memory, "/memory.max_usage_in_bytes",
+                     "Maximum Memory Usage is: " JLONG_FORMAT, JLONG_FORMAT, memmaxusage);
+  return memmaxusage;
+}
+
+/* active_processor_count
+ *
+ * Calculate an appropriate number of active processors for the
+ * VM to use based on these three cgroup options.
+ *
+ * cpu affinity
+ * cpu quota & cpu period
+ * cpu shares
+ *
+ * Algorithm:
+ *
+ * Determine the number of available CPUs from sched_getaffinity
+ *
+ * If user specified a quota (quota != -1), calculate the number of
+ * required CPUs by dividing quota by period.
+ *
+ * If shares are in effect (shares != -1), calculate the number
+ * of cpus required for the shares by dividing the share value
+ * by PER_CPU_SHARES.
+ *
+ * All results of division are rounded up to the next whole number.
+ *
+ * Return the smaller number from the three different settings.
+ *
+ * return:
+ *    number of cpus
+ *    OSCONTAINER_ERROR if failure occured during extract of cpuset info
+ */
+int OSContainer::active_processor_count() {
+  int cpu_count, share_count, quota_count;
+  int share, quota, period;
+  int result;
+
+  cpu_count = os::Linux::active_processor_count();
+
+  share = cpu_shares();
+  if (share > -1) {
+    share_count = ceilf((float)share / (float)PER_CPU_SHARES);
+    log_trace(os, container)("cpu_share count: %d", share_count);
+  } else {
+    share_count = cpu_count;
+  }
+
+  quota = cpu_quota();
+  period = cpu_period();
+  if (quota > -1 && period > 0) {
+    quota_count = ceilf((float)quota / (float)period);
+    log_trace(os, container)("quota_count: %d", quota_count);
+  } else {
+    quota_count = cpu_count;
+  }
+
+  result = MIN2(cpu_count, MIN2(share_count, quota_count));
+  log_trace(os, container)("OSContainer::active_processor_count: %d", result);
+  return result;
+}
+
+char * OSContainer::cpu_cpuset_cpus() {
+  GET_CONTAINER_INFO_CPTR(cptr, cpuset, "/cpuset.cpus",
+                     "cpuset.cpus is: %s", "%1023s", cpus, 1024);
+  return os::strdup(cpus);
+}
+
+char * OSContainer::cpu_cpuset_memory_nodes() {
+  GET_CONTAINER_INFO_CPTR(cptr, cpuset, "/cpuset.mems",
+                     "cpuset.mems is: %s", "%1023s", mems, 1024);
+  return os::strdup(mems);
+}
+
+/* cpu_quota
+ *
+ * Return the number of milliseconds per period
+ * process is guaranteed to run.
+ *
+ * return:
+ *    quota time in milliseconds
+ *    -1 for no quota
+ *    OSCONTAINER_ERROR for not supported
+ */
+int OSContainer::cpu_quota() {
+  GET_CONTAINER_INFO(int, cpu, "/cpu.cfs_quota_us",
+                     "CPU Quota is: %d", "%d", quota);
+  return quota;
+}
+
+int OSContainer::cpu_period() {
+  GET_CONTAINER_INFO(int, cpu, "/cpu.cfs_period_us",
+                     "CPU Period is: %d", "%d", period);
+  return period;
+}
+
+/* cpu_shares
+ *
+ * Return the amount of cpu shares available to the process
+ *
+ * return:
+ *    Share number (typically a number relative to 1024)
+ *                 (2048 typically expresses 2 CPUs worth of processing)
+ *    -1 for no share setup
+ *    OSCONTAINER_ERROR for not supported
+ */
+int OSContainer::cpu_shares() {
+  GET_CONTAINER_INFO(int, cpu, "/cpu.shares",
+                     "CPU Shares is: %d", "%d", shares);
+  // Convert 1024 to no shares setup
+  if (shares == 1024) return -1;
+
+  return shares;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/linux/osContainer_linux.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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.
+ *
+ */
+
+#ifndef OS_LINUX_VM_OSCONTAINER_LINUX_HPP
+#define OS_LINUX_VM_OSCONTAINER_LINUX_HPP
+
+#include "utilities/globalDefinitions.hpp"
+#include "utilities/macros.hpp"
+#include "memory/allocation.hpp"
+
+#define OSCONTAINER_ERROR (-2)
+
+class OSContainer: AllStatic {
+
+ private:
+  static bool   _is_initialized;
+  static bool   _is_containerized;
+
+ public:
+  static void init();
+  static inline bool is_containerized();
+  static char * container_type();
+
+  static jlong memory_limit_in_bytes();
+  static jlong memory_and_swap_limit_in_bytes();
+  static jlong memory_soft_limit_in_bytes();
+  static jlong memory_usage_in_bytes();
+  static jlong memory_max_usage_in_bytes();
+
+  static int active_processor_count();
+
+  static char * cpu_cpuset_cpus();
+  static char * cpu_cpuset_memory_nodes();
+
+  static int cpu_quota();
+  static int cpu_period();
+
+  static int cpu_shares();
+
+};
+
+inline bool OSContainer::is_containerized() {
+  assert(_is_initialized, "OSContainer not initialized");
+  return _is_containerized;
+}
+
+#endif // OS_LINUX_VM_OSCONTAINER_LINUX_HPP
--- a/src/hotspot/os/linux/os_linux.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/os/linux/os_linux.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -38,6 +38,7 @@
 #include "oops/oop.inline.hpp"
 #include "os_linux.inline.hpp"
 #include "os_share_linux.hpp"
+#include "osContainer_linux.hpp"
 #include "prims/jniFastGetField.hpp"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
@@ -171,13 +172,52 @@
 julong os::Linux::available_memory() {
   // values in struct sysinfo are "unsigned long"
   struct sysinfo si;
+  julong avail_mem;
+
+  if (OSContainer::is_containerized()) {
+    jlong mem_limit, mem_usage;
+    if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) {
+      if ((mem_usage = OSContainer::memory_usage_in_bytes()) > 0) {
+        if (mem_limit > mem_usage) {
+          avail_mem = (julong)mem_limit - (julong)mem_usage;
+        } else {
+          avail_mem = 0;
+        }
+        log_trace(os)("available container memory: " JULONG_FORMAT, avail_mem);
+        return avail_mem;
+      } else {
+        log_debug(os,container)("container memory usage call failed: " JLONG_FORMAT, mem_usage);
+      }
+    } else {
+      log_debug(os,container)("container memory unlimited or failed: " JLONG_FORMAT, mem_limit);
+    }
+  }
+
   sysinfo(&si);
-
-  return (julong)si.freeram * si.mem_unit;
+  avail_mem = (julong)si.freeram * si.mem_unit;
+  log_trace(os)("available memory: " JULONG_FORMAT, avail_mem);
+  return avail_mem;
 }
 
 julong os::physical_memory() {
-  return Linux::physical_memory();
+  if (OSContainer::is_containerized()) {
+    jlong mem_limit;
+    if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) {
+      log_trace(os)("total container memory: " JLONG_FORMAT, mem_limit);
+      return (julong)mem_limit;
+    } else {
+      if (mem_limit == OSCONTAINER_ERROR) {
+        log_debug(os,container)("container memory limit call failed");
+      }
+      if (mem_limit == -1) {
+        log_debug(os,container)("container memory unlimited, using host value");
+      }
+    }
+  }
+
+  jlong phys_mem = Linux::physical_memory();
+  log_trace(os)("total system memory: " JLONG_FORMAT, phys_mem);
+  return phys_mem;
 }
 
 // Return true if user is running as root.
@@ -1950,6 +1990,8 @@
   os::Posix::print_load_average(st);
 
   os::Linux::print_full_memory_info(st);
+
+  os::Linux::print_container_info(st);
 }
 
 // Try to identify popular distros.
@@ -2087,6 +2129,66 @@
   st->cr();
 }
 
+void os::Linux::print_container_info(outputStream* st) {
+  if (OSContainer::is_containerized()) {
+    st->print("container (cgroup) information:\n");
+
+    char *p = OSContainer::container_type();
+    if (p == NULL)
+      st->print("container_type() failed\n");
+    else {
+      st->print("container_type: %s\n", p);
+    }
+
+    p = OSContainer::cpu_cpuset_cpus();
+    if (p == NULL)
+      st->print("cpu_cpuset_cpus() failed\n");
+    else {
+      st->print("cpu_cpuset_cpus: %s\n", p);
+      free(p);
+    }
+
+    p = OSContainer::cpu_cpuset_memory_nodes();
+    if (p < 0)
+      st->print("cpu_memory_nodes() failed\n");
+    else {
+      st->print("cpu_memory_nodes: %s\n", p);
+      free(p);
+    }
+
+    int i = OSContainer::active_processor_count();
+    if (i < 0)
+      st->print("active_processor_count() failed\n");
+    else
+      st->print("active_processor_count: %d\n", i);
+
+    i = OSContainer::cpu_quota();
+    st->print("cpu_quota: %d\n", i);
+
+    i = OSContainer::cpu_period();
+    st->print("cpu_period: %d\n", i);
+
+    i = OSContainer::cpu_shares();
+    st->print("cpu_shares: %d\n", i);
+
+    jlong j = OSContainer::memory_limit_in_bytes();
+    st->print("memory_limit_in_bytes: " JLONG_FORMAT "\n", j);
+
+    j = OSContainer::memory_and_swap_limit_in_bytes();
+    st->print("memory_and_swap_limit_in_bytes: " JLONG_FORMAT "\n", j);
+
+    j = OSContainer::memory_soft_limit_in_bytes();
+    st->print("memory_soft_limit_in_bytes: " JLONG_FORMAT "\n", j);
+
+    j = OSContainer::OSContainer::memory_usage_in_bytes();
+    st->print("memory_usage_in_bytes: " JLONG_FORMAT "\n", j);
+
+    j = OSContainer::OSContainer::memory_max_usage_in_bytes();
+    st->print("memory_max_usage_in_bytes: " JLONG_FORMAT "\n", j);
+    st->cr();
+  }
+}
+
 void os::print_memory_info(outputStream* st) {
 
   st->print("Memory:");
@@ -4798,6 +4900,10 @@
   }
 }
 
+void os::pd_init_container_support() {
+  OSContainer::init();
+}
+
 // this is called _after_ the global arguments have been parsed
 jint os::init_2(void) {
 
@@ -4805,20 +4911,6 @@
 
   Linux::fast_thread_clock_init();
 
-  // Allocate a single page and mark it as readable for safepoint polling
-  address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
-  guarantee(polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page");
-
-  os::set_polling_page(polling_page);
-  log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
-
-  if (!UseMembar) {
-    address mem_serialize_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
-    guarantee(mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
-    os::set_memory_serialize_page(mem_serialize_page);
-    log_info(os)("Memory Serialize Page address: " INTPTR_FORMAT, p2i(mem_serialize_page));
-  }
-
   // initialize suspend/resume support - must do this before signal_sets_init()
   if (SR_initialize() != 0) {
     perror("SR_initialize failed");
@@ -4960,12 +5052,12 @@
 // dynamic check - see 6515172 for details.
 // If anything goes wrong we fallback to returning the number of online
 // processors - which can be greater than the number available to the process.
-int os::active_processor_count() {
+int os::Linux::active_processor_count() {
   cpu_set_t cpus;  // can represent at most 1024 (CPU_SETSIZE) processors
   cpu_set_t* cpus_p = &cpus;
   int cpus_size = sizeof(cpu_set_t);
 
-  int configured_cpus = processor_count();  // upper bound on available cpus
+  int configured_cpus = os::processor_count();  // upper bound on available cpus
   int cpu_count = 0;
 
 // old build platforms may not support dynamic cpu sets
@@ -5028,10 +5120,44 @@
     CPU_FREE(cpus_p);
   }
 
-  assert(cpu_count > 0 && cpu_count <= processor_count(), "sanity check");
+  assert(cpu_count > 0 && cpu_count <= os::processor_count(), "sanity check");
   return cpu_count;
 }
 
+// Determine the active processor count from one of
+// three different sources:
+//
+// 1. User option -XX:ActiveProcessorCount
+// 2. kernel os calls (sched_getaffinity or sysconf(_SC_NPROCESSORS_ONLN)
+// 3. extracted from cgroup cpu subsystem (shares and quotas)
+//
+// Option 1, if specified, will always override.
+// If the cgroup subsystem is active and configured, we
+// will return the min of the cgroup and option 2 results.
+// This is required since tools, such as numactl, that
+// alter cpu affinity do not update cgroup subsystem
+// cpuset configuration files.
+int os::active_processor_count() {
+  // User has overridden the number of active processors
+  if (ActiveProcessorCount > 0) {
+    log_trace(os)("active_processor_count: "
+                  "active processor count set by user : %d",
+                  ActiveProcessorCount);
+    return ActiveProcessorCount;
+  }
+
+  int active_cpus;
+  if (OSContainer::is_containerized()) {
+    active_cpus = OSContainer::active_processor_count();
+    log_trace(os)("active_processor_count: determined by OSContainer: %d",
+                   active_cpus);
+  } else {
+    active_cpus = os::Linux::active_processor_count();
+  }
+
+  return active_cpus;
+}
+
 void os::set_native_thread_name(const char *name) {
   if (Linux::_pthread_setname_np) {
     char buf [16]; // according to glibc manpage, 16 chars incl. '/0'
--- a/src/hotspot/os/linux/os_linux.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/os/linux/os_linux.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -32,6 +32,7 @@
 
 class Linux {
   friend class os;
+  friend class OSContainer;
   friend class TestReserveMemorySpecial;
 
   static bool libjsig_is_loaded;        // libjsig that interposes sigaction(),
@@ -75,6 +76,9 @@
 
   static julong available_memory();
   static julong physical_memory() { return _physical_memory; }
+  static void set_physical_memory(julong phys_mem) { _physical_memory = phys_mem; }
+  static int active_processor_count();
+
   static void initialize_system_info();
 
   static int commit_memory_impl(char* addr, size_t bytes, bool exec);
@@ -106,6 +110,7 @@
   static bool release_memory_special_huge_tlbfs(char* base, size_t bytes);
 
   static void print_full_memory_info(outputStream* st);
+  static void print_container_info(outputStream* st);
   static void print_distro_info(outputStream* st);
   static void print_libversion_info(outputStream* st);
 
--- a/src/hotspot/os/solaris/os_solaris.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/os/solaris/os_solaris.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -290,6 +290,14 @@
 }
 
 int os::active_processor_count() {
+  // User has overridden the number of active processors
+  if (ActiveProcessorCount > 0) {
+    log_trace(os)("active_processor_count: "
+                  "active processor count set by user : %d",
+                  ActiveProcessorCount);
+    return ActiveProcessorCount;
+  }
+
   int online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
   pid_t pid = getpid();
   psetid_t pset = PS_NONE;
@@ -2190,10 +2198,6 @@
 
 static int page_size = -1;
 
-// The mmap MAP_ALIGN flag is supported on Solaris 9 and later.  init_2() will
-// clear this var if support is not available.
-static bool has_map_align = true;
-
 int os::vm_page_size() {
   assert(page_size != -1, "must call os::init");
   return page_size;
@@ -2560,7 +2564,7 @@
 
   if (fixed) {
     flags |= MAP_FIXED;
-  } else if (has_map_align && (alignment_hint > (size_t) vm_page_size())) {
+  } else if (alignment_hint > (size_t) vm_page_size()) {
     flags |= MAP_ALIGN;
     addr = (char*) alignment_hint;
   }
@@ -4222,28 +4226,6 @@
   // try to enable extended file IO ASAP, see 6431278
   os::Solaris::try_enable_extended_io();
 
-  // Allocate a single page and mark it as readable for safepoint polling.  Also
-  // use this first mmap call to check support for MAP_ALIGN.
-  address polling_page = (address)Solaris::mmap_chunk((char*)page_size,
-                                                      page_size,
-                                                      MAP_PRIVATE | MAP_ALIGN,
-                                                      PROT_READ);
-  if (polling_page == NULL) {
-    has_map_align = false;
-    polling_page = (address)Solaris::mmap_chunk(NULL, page_size, MAP_PRIVATE,
-                                                PROT_READ);
-  }
-
-  os::set_polling_page(polling_page);
-  log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
-
-  if (!UseMembar) {
-    address mem_serialize_page = (address)Solaris::mmap_chunk(NULL, page_size, MAP_PRIVATE, PROT_READ | PROT_WRITE);
-    guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page");
-    os::set_memory_serialize_page(mem_serialize_page);
-    log_info(os)("Memory Serialize Page address: " INTPTR_FORMAT, p2i(mem_serialize_page));
-  }
-
   // Check and sets minimum stack sizes against command line options
   if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
     return JNI_ERR;
--- a/src/hotspot/os/windows/os_windows.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/os/windows/os_windows.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -723,6 +723,14 @@
 }
 
 int os::active_processor_count() {
+  // User has overridden the number of active processors
+  if (ActiveProcessorCount > 0) {
+    log_trace(os)("active_processor_count: "
+                  "active processor count set by user : %d",
+                  ActiveProcessorCount);
+    return ActiveProcessorCount;
+  }
+
   DWORD_PTR lpProcessAffinityMask = 0;
   DWORD_PTR lpSystemAffinityMask = 0;
   int proc_count = processor_count();
@@ -2487,6 +2495,20 @@
     } // /EXCEPTION_ACCESS_VIOLATION
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
+    if (exception_code == EXCEPTION_IN_PAGE_ERROR) {
+      CompiledMethod* nm = NULL;
+      JavaThread* thread = (JavaThread*)t;
+      if (in_java) {
+        CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
+        nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;
+      }
+      if ((thread->thread_state() == _thread_in_vm &&
+          thread->doing_unsafe_access()) ||
+          (nm != NULL && nm->has_unsafe_access())) {
+        return Handle_Exception(exceptionInfo, SharedRuntime::handle_unsafe_access(thread, (address)Assembler::locate_next_instruction(pc)));
+      }
+    }
+
     if (in_java) {
       switch (exception_code) {
       case EXCEPTION_INT_DIVIDE_BY_ZERO:
@@ -3911,27 +3933,6 @@
 
 // this is called _after_ the global arguments have been parsed
 jint os::init_2(void) {
-  // Allocate a single page and mark it as readable for safepoint polling
-  address polling_page = (address)VirtualAlloc(NULL, os::vm_page_size(), MEM_RESERVE, PAGE_READONLY);
-  guarantee(polling_page != NULL, "Reserve Failed for polling page");
-
-  address return_page  = (address)VirtualAlloc(polling_page, os::vm_page_size(), MEM_COMMIT, PAGE_READONLY);
-  guarantee(return_page != NULL, "Commit Failed for polling page");
-
-  os::set_polling_page(polling_page);
-  log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
-
-  if (!UseMembar) {
-    address mem_serialize_page = (address)VirtualAlloc(NULL, os::vm_page_size(), MEM_RESERVE, PAGE_READWRITE);
-    guarantee(mem_serialize_page != NULL, "Reserve Failed for memory serialize page");
-
-    return_page  = (address)VirtualAlloc(mem_serialize_page, os::vm_page_size(), MEM_COMMIT, PAGE_READWRITE);
-    guarantee(return_page != NULL, "Commit Failed for memory serialize page");
-
-    os::set_memory_serialize_page(mem_serialize_page);
-    log_info(os)("Memory Serialize Page address: " INTPTR_FORMAT, p2i(mem_serialize_page));
-  }
-
   // Setup Windows Exceptions
 
   // for debugging float code generation bugs
--- a/src/hotspot/os_cpu/linux_sparc/thread_linux_sparc.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/os_cpu/linux_sparc/thread_linux_sparc.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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
@@ -68,7 +68,7 @@
   address o_reg_temps(int i) { return (address)&_o_reg_temps[i]; }
 #endif
 
-  static int saved_exception_npc_offset_in_bytes() { return offset_of(JavaThread,_saved_exception_npc); }
+  static ByteSize saved_exception_npc_offset() { return byte_offset_of(JavaThread,_saved_exception_npc); }
 
   address  saved_exception_npc()             { return _saved_exception_npc; }
   void set_saved_exception_npc(address a)    { _saved_exception_npc = a; }
--- a/src/hotspot/os_cpu/solaris_sparc/os_solaris_sparc.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/os_cpu/solaris_sparc/os_solaris_sparc.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -447,7 +447,7 @@
       // a fault inside compiled code, the interpreter, or a stub
 
       // Support Safepoint Polling
-      if ( sig == SIGSEGV && (address)info->si_addr == os::get_polling_page() ) {
+      if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) {
         stub = SharedRuntime::get_poll_stub(pc);
       }
 
--- a/src/hotspot/os_cpu/solaris_sparc/thread_solaris_sparc.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/os_cpu/solaris_sparc/thread_solaris_sparc.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -63,7 +63,7 @@
 
   static int o_reg_temps_offset_in_bytes() { return offset_of(JavaThread, _o_reg_temps); }
 
-  static int saved_exception_npc_offset_in_bytes() { return offset_of(JavaThread,_saved_exception_npc); }
+  static ByteSize saved_exception_npc_offset() { return byte_offset_of(JavaThread,_saved_exception_npc); }
 
   address  saved_exception_npc()             { return _saved_exception_npc; }
   void set_saved_exception_npc(address a)    { _saved_exception_npc = a; }
--- a/src/hotspot/share/ci/ciEnv.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/ci/ciEnv.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, 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
@@ -187,10 +187,6 @@
     }
   }
 
-  void ensure_metadata_alive(ciMetadata* m) {
-    _factory->ensure_metadata_alive(m);
-  }
-
   ciInstance* get_instance(oop o) {
     if (o == NULL) return NULL;
     return get_object(o)->as_instance();
--- a/src/hotspot/share/ci/ciInstanceKlass.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/ci/ciInstanceKlass.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -34,6 +34,9 @@
 #include "oops/oop.inline.hpp"
 #include "oops/fieldStreams.hpp"
 #include "runtime/fieldDescriptor.hpp"
+#if INCLUDE_ALL_GCS
+# include "gc/g1/g1SATBCardTableModRefBS.hpp"
+#endif
 
 // ciInstanceKlass
 //
@@ -41,6 +44,27 @@
 // whose Klass part in an InstanceKlass.
 
 // ------------------------------------------------------------------
+// ensure_metadata_alive
+//
+// Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
+// This is primarily useful for metadata which is considered as weak roots
+// by the GC but need to be strong roots if reachable from a current compilation.
+// InstanceKlass are created for both weak and strong metadata.  Ensuring this metadata
+// alive covers the cases where there are weak roots without performance cost.
+//
+static void ensure_metadata_alive(oop metadata_holder) {
+#if INCLUDE_ALL_GCS
+  if (!UseG1GC) {
+    return;
+  }
+  if (metadata_holder != NULL) {
+    G1SATBCardTableModRefBS::enqueue(metadata_holder);
+  }
+#endif
+}
+
+
+// ------------------------------------------------------------------
 // ciInstanceKlass::ciInstanceKlass
 //
 // Loaded instance klass.
@@ -64,6 +88,18 @@
   _has_injected_fields = -1;
   _implementor = NULL; // we will fill these lazily
 
+  oop holder = ik->klass_holder();
+  ensure_metadata_alive(holder);
+  if (ik->is_anonymous()) {
+    // Though ciInstanceKlass records class loader oop, it's not enough to keep
+    // VM anonymous classes alive (loader == NULL). Klass holder should be used instead.
+    // It is enough to record a ciObject, since cached elements are never removed
+    // during ciObjectFactory lifetime. ciObjectFactory itself is created for
+    // every compilation and lives for the whole duration of the compilation.
+    assert(holder != NULL, "holder of anonymous class is the mirror which is never null");
+    (void)CURRENT_ENV->get_object(holder);
+  }
+
   Thread *thread = Thread::current();
   if (ciObjectFactory::is_initialized()) {
     _loader = JNIHandles::make_local(thread, ik->class_loader());
--- a/src/hotspot/share/ci/ciMethodData.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/ci/ciMethodData.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -188,7 +188,6 @@
     Klass* k = data->as_ReceiverTypeData()->receiver(row);
     if (k != NULL) {
       ciKlass* klass = CURRENT_ENV->get_klass(k);
-      CURRENT_ENV->ensure_metadata_alive(klass);
       set_receiver(row, klass);
     }
   }
@@ -210,7 +209,6 @@
 void ciSpeculativeTrapData::translate_from(const ProfileData* data) {
   Method* m = data->as_SpeculativeTrapData()->method();
   ciMethod* ci_m = CURRENT_ENV->get_method(m);
-  CURRENT_ENV->ensure_metadata_alive(ci_m);
   set_method(ci_m);
 }
 
--- a/src/hotspot/share/ci/ciMethodData.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/ci/ciMethodData.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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
@@ -70,7 +70,6 @@
     Klass* v = TypeEntries::valid_klass(k);
     if (v != NULL) {
       ciKlass* klass = CURRENT_ENV->get_klass(v);
-      CURRENT_ENV->ensure_metadata_alive(klass);
       return with_status(klass, k);
     }
     return with_status(NULL, k);
--- a/src/hotspot/share/ci/ciObjectFactory.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/ci/ciObjectFactory.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -47,9 +47,6 @@
 #include "oops/oop.inline.hpp"
 #include "runtime/fieldType.hpp"
 #include "utilities/macros.hpp"
-#if INCLUDE_ALL_GCS
-# include "gc/g1/g1SATBCardTableModRefBS.hpp"
-#endif
 
 // ciObjectFactory
 //
@@ -363,19 +360,6 @@
 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
   EXCEPTION_CONTEXT;
 
-  // Hold metadata from unloading by keeping it's holder alive.
-  if (_initialized && o->is_klass()) {
-    Klass* holder = ((Klass*)o);
-    if (holder->is_instance_klass() && InstanceKlass::cast(holder)->is_anonymous()) {
-      // Though ciInstanceKlass records class loader oop, it's not enough to keep
-      // VM anonymous classes alive (loader == NULL). Klass holder should be used instead.
-      // It is enough to record a ciObject, since cached elements are never removed
-      // during ciObjectFactory lifetime. ciObjectFactory itself is created for
-      // every compilation and lives for the whole duration of the compilation.
-      ciObject* h = get(holder->klass_holder());
-    }
-  }
-
   if (o->is_klass()) {
     Klass* k = (Klass*)o;
     if (k->is_instance_klass()) {
@@ -401,38 +385,6 @@
   return NULL;
 }
 
-// ------------------------------------------------------------------
-// ciObjectFactory::ensure_metadata_alive
-//
-// Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
-// This is primarily useful for metadata which is considered as weak roots
-// by the GC but need to be strong roots if reachable from a current compilation.
-//
-void ciObjectFactory::ensure_metadata_alive(ciMetadata* m) {
-  ASSERT_IN_VM; // We're handling raw oops here.
-
-#if INCLUDE_ALL_GCS
-  if (!UseG1GC) {
-    return;
-  }
-  Klass* metadata_owner_klass;
-  if (m->is_klass()) {
-    metadata_owner_klass = m->as_klass()->get_Klass();
-  } else if (m->is_method()) {
-    metadata_owner_klass = m->as_method()->get_Method()->constants()->pool_holder();
-  } else {
-    fatal("Not implemented for other types of metadata");
-    return;
-  }
-
-  oop metadata_holder = metadata_owner_klass->klass_holder();
-  if (metadata_holder != NULL) {
-    G1SATBCardTableModRefBS::enqueue(metadata_holder);
-  }
-
-#endif
-}
-
 //------------------------------------------------------------------
 // ciObjectFactory::get_unloaded_method
 //
--- a/src/hotspot/share/ci/ciObjectFactory.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/ci/ciObjectFactory.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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
@@ -73,8 +73,6 @@
   ciObject* create_new_object(oop o);
   ciMetadata* create_new_metadata(Metadata* o);
 
-  void ensure_metadata_alive(ciMetadata* m);
-
   static bool is_equal(NonPermObject* p, oop key) {
     return p->object()->get_oop() == key;
   }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/cms/cmsArguments.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,201 @@
+/*
+ * 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.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "gc/cms/cmsArguments.hpp"
+#include "gc/cms/cmsCollectorPolicy.hpp"
+#include "gc/cms/cmsHeap.hpp"
+#include "gc/cms/compactibleFreeListSpace.hpp"
+#include "gc/shared/gcArguments.inline.hpp"
+#include "gc/shared/genCollectedHeap.hpp"
+#include "runtime/arguments.hpp"
+#include "runtime/globals.hpp"
+#include "runtime/globals_extension.hpp"
+#include "runtime/vm_version.hpp"
+#include "utilities/defaultStream.hpp"
+
+size_t CMSArguments::conservative_max_heap_alignment() {
+  return GenCollectedHeap::conservative_max_heap_alignment();
+}
+
+void CMSArguments::set_parnew_gc_flags() {
+  assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC,
+         "control point invariant");
+  assert(UseConcMarkSweepGC, "CMS is expected to be on here");
+
+  if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
+    FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads());
+    assert(ParallelGCThreads > 0, "We should always have at least one thread by default");
+  } else if (ParallelGCThreads == 0) {
+    jio_fprintf(defaultStream::error_stream(),
+        "The ParNew GC can not be combined with -XX:ParallelGCThreads=0\n");
+    vm_exit(1);
+  }
+
+  // By default YoungPLABSize and OldPLABSize are set to 4096 and 1024 respectively,
+  // these settings are default for Parallel Scavenger. For ParNew+Tenured configuration
+  // we set them to 1024 and 1024.
+  // See CR 6362902.
+  if (FLAG_IS_DEFAULT(YoungPLABSize)) {
+    FLAG_SET_DEFAULT(YoungPLABSize, (intx)1024);
+  }
+  if (FLAG_IS_DEFAULT(OldPLABSize)) {
+    FLAG_SET_DEFAULT(OldPLABSize, (intx)1024);
+  }
+
+  // When using compressed oops, we use local overflow stacks,
+  // rather than using a global overflow list chained through
+  // the klass word of the object's pre-image.
+  if (UseCompressedOops && !ParGCUseLocalOverflow) {
+    if (!FLAG_IS_DEFAULT(ParGCUseLocalOverflow)) {
+      warning("Forcing +ParGCUseLocalOverflow: needed if using compressed references");
+    }
+    FLAG_SET_DEFAULT(ParGCUseLocalOverflow, true);
+  }
+  assert(ParGCUseLocalOverflow || !UseCompressedOops, "Error");
+}
+
+// Adjust some sizes to suit CMS and/or ParNew needs; these work well on
+// sparc/solaris for certain applications, but would gain from
+// further optimization and tuning efforts, and would almost
+// certainly gain from analysis of platform and environment.
+void CMSArguments::initialize_flags() {
+  GCArguments::initialize_flags();
+  assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC, "Error");
+  assert(UseConcMarkSweepGC, "CMS is expected to be on here");
+
+  // Set CMS global values
+  CompactibleFreeListSpace::set_cms_values();
+
+  // Turn off AdaptiveSizePolicy by default for cms until it is complete.
+  disable_adaptive_size_policy("UseConcMarkSweepGC");
+
+  set_parnew_gc_flags();
+
+  size_t max_heap = align_down(MaxHeapSize,
+                               CardTableRS::ct_max_alignment_constraint());
+
+  // Now make adjustments for CMS
+  intx   tenuring_default = (intx)6;
+  size_t young_gen_per_worker = CMSYoungGenPerWorker;
+
+  // Preferred young gen size for "short" pauses:
+  // upper bound depends on # of threads and NewRatio.
+  const size_t preferred_max_new_size_unaligned =
+    MIN2(max_heap/(NewRatio+1), ScaleForWordSize(young_gen_per_worker * ParallelGCThreads));
+  size_t preferred_max_new_size =
+    align_up(preferred_max_new_size_unaligned, os::vm_page_size());
+
+  // Unless explicitly requested otherwise, size young gen
+  // for "short" pauses ~ CMSYoungGenPerWorker*ParallelGCThreads
+
+  // If either MaxNewSize or NewRatio is set on the command line,
+  // assume the user is trying to set the size of the young gen.
+  if (FLAG_IS_DEFAULT(MaxNewSize) && FLAG_IS_DEFAULT(NewRatio)) {
+
+    // Set MaxNewSize to our calculated preferred_max_new_size unless
+    // NewSize was set on the command line and it is larger than
+    // preferred_max_new_size.
+    if (!FLAG_IS_DEFAULT(NewSize)) {   // NewSize explicitly set at command-line
+      FLAG_SET_ERGO(size_t, MaxNewSize, MAX2(NewSize, preferred_max_new_size));
+    } else {
+      FLAG_SET_ERGO(size_t, MaxNewSize, preferred_max_new_size);
+    }
+    log_trace(gc, heap)("CMS ergo set MaxNewSize: " SIZE_FORMAT, MaxNewSize);
+
+    // Code along this path potentially sets NewSize and OldSize
+    log_trace(gc, heap)("CMS set min_heap_size: " SIZE_FORMAT " initial_heap_size:  " SIZE_FORMAT " max_heap: " SIZE_FORMAT,
+                        Arguments::min_heap_size(), InitialHeapSize, max_heap);
+    size_t min_new = preferred_max_new_size;
+    if (FLAG_IS_CMDLINE(NewSize)) {
+      min_new = NewSize;
+    }
+    if (max_heap > min_new && Arguments::min_heap_size() > min_new) {
+      // Unless explicitly requested otherwise, make young gen
+      // at least min_new, and at most preferred_max_new_size.
+      if (FLAG_IS_DEFAULT(NewSize)) {
+        FLAG_SET_ERGO(size_t, NewSize, MAX2(NewSize, min_new));
+        FLAG_SET_ERGO(size_t, NewSize, MIN2(preferred_max_new_size, NewSize));
+        log_trace(gc, heap)("CMS ergo set NewSize: " SIZE_FORMAT, NewSize);
+      }
+      // Unless explicitly requested otherwise, size old gen
+      // so it's NewRatio x of NewSize.
+      if (FLAG_IS_DEFAULT(OldSize)) {
+        if (max_heap > NewSize) {
+          FLAG_SET_ERGO(size_t, OldSize, MIN2(NewRatio*NewSize, max_heap - NewSize));
+          log_trace(gc, heap)("CMS ergo set OldSize: " SIZE_FORMAT, OldSize);
+        }
+      }
+    }
+  }
+  // Unless explicitly requested otherwise, definitely
+  // promote all objects surviving "tenuring_default" scavenges.
+  if (FLAG_IS_DEFAULT(MaxTenuringThreshold) &&
+      FLAG_IS_DEFAULT(SurvivorRatio)) {
+    FLAG_SET_ERGO(uintx, MaxTenuringThreshold, tenuring_default);
+  }
+  // If we decided above (or user explicitly requested)
+  // `promote all' (via MaxTenuringThreshold := 0),
+  // prefer minuscule survivor spaces so as not to waste
+  // space for (non-existent) survivors
+  if (FLAG_IS_DEFAULT(SurvivorRatio) && MaxTenuringThreshold == 0) {
+    FLAG_SET_ERGO(uintx, SurvivorRatio, MAX2((uintx)1024, SurvivorRatio));
+  }
+
+  // OldPLABSize is interpreted in CMS as not the size of the PLAB in words,
+  // but rather the number of free blocks of a given size that are used when
+  // replenishing the local per-worker free list caches.
+  if (FLAG_IS_DEFAULT(OldPLABSize)) {
+    if (!FLAG_IS_DEFAULT(ResizeOldPLAB) && !ResizeOldPLAB) {
+      // OldPLAB sizing manually turned off: Use a larger default setting,
+      // unless it was manually specified. This is because a too-low value
+      // will slow down scavenges.
+      FLAG_SET_ERGO(size_t, OldPLABSize, CompactibleFreeListSpaceLAB::_default_static_old_plab_size); // default value before 6631166
+    } else {
+      FLAG_SET_DEFAULT(OldPLABSize, CompactibleFreeListSpaceLAB::_default_dynamic_old_plab_size); // old CMSParPromoteBlocksToClaim default
+    }
+  }
+
+  // If either of the static initialization defaults have changed, note this
+  // modification.
+  if (!FLAG_IS_DEFAULT(OldPLABSize) || !FLAG_IS_DEFAULT(OldPLABWeight)) {
+    CompactibleFreeListSpaceLAB::modify_initialization(OldPLABSize, OldPLABWeight);
+  }
+
+  log_trace(gc)("MarkStackSize: %uk  MarkStackSizeMax: %uk", (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K));
+}
+
+void CMSArguments::disable_adaptive_size_policy(const char* collector_name) {
+  if (UseAdaptiveSizePolicy) {
+    if (FLAG_IS_CMDLINE(UseAdaptiveSizePolicy)) {
+      warning("Disabling UseAdaptiveSizePolicy; it is incompatible with %s.",
+              collector_name);
+    }
+    FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
+  }
+}
+
+CollectedHeap* CMSArguments::create_heap() {
+  return create_heap_with_policy<CMSHeap, ConcurrentMarkSweepPolicy>();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/cms/cmsArguments.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef SHARE_GC_CMS_CMSARGUMENTS_HPP
+#define SHARE_GC_CMS_CMSARGUMENTS_HPP
+
+#include "gc/shared/gcArguments.hpp"
+
+class CollectedHeap;
+
+class CMSArguments : public GCArguments {
+private:
+  void disable_adaptive_size_policy(const char* collector_name);
+  void set_parnew_gc_flags();
+public:
+  virtual void initialize_flags();
+  virtual size_t conservative_max_heap_alignment();
+  virtual CollectedHeap* create_heap();
+};
+
+#endif // SHARE_GC_CMS_CMSARGUMENTS_HPP
--- a/src/hotspot/share/gc/g1/collectionSetChooser.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/gc/g1/collectionSetChooser.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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
@@ -247,8 +247,8 @@
       _g1(G1CollectedHeap::heap()), _hrclaimer(n_workers) {}
 
   void work(uint worker_id) {
-    ParKnownGarbageHRClosure parKnownGarbageCl(_hrSorted, _chunk_size);
-    _g1->heap_region_par_iterate(&parKnownGarbageCl, worker_id, &_hrclaimer);
+    ParKnownGarbageHRClosure par_known_garbage_cl(_hrSorted, _chunk_size);
+    _g1->heap_region_par_iterate_from_worker_offset(&par_known_garbage_cl, &_hrclaimer, worker_id);
   }
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1Arguments.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "gc/g1/g1Arguments.hpp"
+#include "gc/g1/g1CollectedHeap.inline.hpp"
+#include "gc/g1/g1CollectorPolicy.hpp"
+#include "gc/g1/heapRegion.hpp"
+#include "gc/shared/gcArguments.inline.hpp"
+#include "runtime/globals.hpp"
+#include "runtime/globals_extension.hpp"
+#include "runtime/vm_version.hpp"
+
+size_t G1Arguments::conservative_max_heap_alignment() {
+  return HeapRegion::max_region_size();
+}
+
+void G1Arguments::initialize_flags() {
+  GCArguments::initialize_flags();
+  assert(UseG1GC, "Error");
+#if defined(COMPILER1) || INCLUDE_JVMCI
+  FastTLABRefill = false;
+#endif
+  FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads());
+  if (ParallelGCThreads == 0) {
+    assert(!FLAG_IS_DEFAULT(ParallelGCThreads), "The default value for ParallelGCThreads should not be 0.");
+    vm_exit_during_initialization("The flag -XX:+UseG1GC can not be combined with -XX:ParallelGCThreads=0", NULL);
+  }
+
+#if INCLUDE_ALL_GCS
+  if (FLAG_IS_DEFAULT(G1ConcRefinementThreads)) {
+    FLAG_SET_ERGO(uint, G1ConcRefinementThreads, ParallelGCThreads);
+  }
+#endif
+
+  // MarkStackSize will be set (if it hasn't been set by the user)
+  // when concurrent marking is initialized.
+  // Its value will be based upon the number of parallel marking threads.
+  // But we do set the maximum mark stack size here.
+  if (FLAG_IS_DEFAULT(MarkStackSizeMax)) {
+    FLAG_SET_DEFAULT(MarkStackSizeMax, 128 * TASKQUEUE_SIZE);
+  }
+
+  if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) {
+    // In G1, we want the default GC overhead goal to be higher than
+    // it is for PS, or the heap might be expanded too aggressively.
+    // We set it here to ~8%.
+    FLAG_SET_DEFAULT(GCTimeRatio, 12);
+  }
+
+  // Below, we might need to calculate the pause time interval based on
+  // the pause target. When we do so we are going to give G1 maximum
+  // flexibility and allow it to do pauses when it needs to. So, we'll
+  // arrange that the pause interval to be pause time target + 1 to
+  // ensure that a) the pause time target is maximized with respect to
+  // the pause interval and b) we maintain the invariant that pause
+  // time target < pause interval. If the user does not want this
+  // maximum flexibility, they will have to set the pause interval
+  // explicitly.
+
+  if (FLAG_IS_DEFAULT(MaxGCPauseMillis)) {
+    // The default pause time target in G1 is 200ms
+    FLAG_SET_DEFAULT(MaxGCPauseMillis, 200);
+  }
+
+  // Then, if the interval parameter was not set, set it according to
+  // the pause time target (this will also deal with the case when the
+  // pause time target is the default value).
+  if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
+    FLAG_SET_DEFAULT(GCPauseIntervalMillis, MaxGCPauseMillis + 1);
+  }
+
+  log_trace(gc)("MarkStackSize: %uk  MarkStackSizeMax: %uk", (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K));
+}
+
+CollectedHeap* G1Arguments::create_heap() {
+  return create_heap_with_policy<G1CollectedHeap, G1CollectorPolicy>();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1Arguments.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef SHARE_GC_G1_G1ARGUMENTS_HPP
+#define SHARE_GC_G1_G1ARGUMENTS_HPP
+
+#include "gc/shared/gcArguments.hpp"
+
+class CollectedHeap;
+
+class G1Arguments : public GCArguments {
+public:
+  virtual void initialize_flags();
+  virtual size_t conservative_max_heap_alignment();
+  virtual CollectedHeap* create_heap();
+};
+
+#endif // SHARE_GC_G1_G1ARGUMENTS_HPP
--- a/src/hotspot/share/gc/g1/g1CardLiveData.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1CardLiveData.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -314,7 +314,7 @@
     G1CollectedHeap* g1h = G1CollectedHeap::heap();
     G1ConcurrentMark* cm = g1h->concurrent_mark();
     G1CreateLiveDataClosure cl(g1h, cm, cm->next_mark_bitmap(), _live_data);
-    g1h->heap_region_par_iterate(&cl, worker_id, &_hr_claimer);
+    g1h->heap_region_par_iterate_from_worker_offset(&cl, &_hr_claimer, worker_id);
   }
 };
 
@@ -381,7 +381,7 @@
   void work(uint worker_id) {
     G1FinalizeCardLiveDataClosure cl(G1CollectedHeap::heap(), _bitmap, _live_data);
 
-    G1CollectedHeap::heap()->heap_region_par_iterate(&cl, worker_id, &_hr_claimer);
+    G1CollectedHeap::heap()->heap_region_par_iterate_from_worker_offset(&cl, &_hr_claimer, worker_id);
   }
 };
 
@@ -560,7 +560,7 @@
                                    _mark_bitmap,
                                    _act_live_data,
                                    &_exp_live_data);
-    _g1h->heap_region_par_iterate(&cl, worker_id, &_hr_claimer);
+    _g1h->heap_region_par_iterate_from_worker_offset(&cl, &_hr_claimer, worker_id);
 
     Atomic::add(cl.failures(), &_failures);
   }
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -38,6 +38,7 @@
 #include "gc/g1/g1ConcurrentRefine.hpp"
 #include "gc/g1/g1ConcurrentRefineThread.hpp"
 #include "gc/g1/g1EvacStats.inline.hpp"
+#include "gc/g1/g1FullCollector.hpp"
 #include "gc/g1/g1FullGCScope.hpp"
 #include "gc/g1/g1GCPhaseTimes.hpp"
 #include "gc/g1/g1HeapSizingPolicy.hpp"
@@ -48,10 +49,9 @@
 #include "gc/g1/g1ParScanThreadState.inline.hpp"
 #include "gc/g1/g1Policy.hpp"
 #include "gc/g1/g1RegionToSpaceMapper.hpp"
-#include "gc/g1/g1RemSet.inline.hpp"
+#include "gc/g1/g1RemSet.hpp"
 #include "gc/g1/g1RootClosures.hpp"
 #include "gc/g1/g1RootProcessor.hpp"
-#include "gc/g1/g1SerialFullCollector.hpp"
 #include "gc/g1/g1StringDedup.hpp"
 #include "gc/g1/g1YCTypes.hpp"
 #include "gc/g1/g1YoungRemSetSamplingThread.hpp"
@@ -143,6 +143,12 @@
   reset_from_card_cache(start_idx, num_regions);
 }
 
+
+HeapRegion* G1CollectedHeap::new_heap_region(uint hrs_index,
+                                             MemRegion mr) {
+  return new HeapRegion(hrs_index, bot(), mr);
+}
+
 // Private methods.
 
 HeapRegion*
@@ -1155,7 +1161,6 @@
 
 void G1CollectedHeap::abort_refinement() {
   if (_hot_card_cache->use_cache()) {
-    _hot_card_cache->reset_card_counts();
     _hot_card_cache->reset_hot_cache();
   }
 
@@ -1199,6 +1204,10 @@
 }
 
 void G1CollectedHeap::print_heap_after_full_collection(G1HeapTransition* heap_transition) {
+  // Post collection logging.
+  // We should do this after we potentially resize the heap so
+  // that all the COMMIT / UNCOMMIT events are generated before
+  // the compaction events.
   print_hrm_post_compaction();
   heap_transition->print();
   print_heap_after_gc();
@@ -1221,23 +1230,18 @@
   gc_prologue(true);
   prepare_heap_for_full_collection();
 
-  G1SerialFullCollector serial(scope, ref_processor_stw());
-  serial.prepare_collection();
-  serial.collect();
-  serial.complete_collection();
+  G1FullCollector collector(scope, ref_processor_stw(), concurrent_mark()->next_mark_bitmap(), workers()->active_workers());
+  collector.prepare_collection();
+  collector.collect();
+  collector.complete_collection();
 
   prepare_heap_for_mutators();
 
   g1_policy()->record_full_collection_end();
   gc_epilogue(true);
 
-  // Post collection verification.
   verify_after_full_collection();
 
-  // Post collection logging.
-  // We should do this after we potentially resize the heap so
-  // that all the COMMIT / UNCOMMIT events are generated before
-  // the compaction events.
   print_heap_after_full_collection(scope->heap_transition());
 }
 
@@ -1269,10 +1273,10 @@
 }
 
 void G1CollectedHeap::resize_if_necessary_after_full_collection() {
-  // Include bytes that will be pre-allocated to support collections, as "used".
-  const size_t used_after_gc = used();
+  // Capacity, free and used after the GC counted as full regions to
+  // include the waste in the following calculations.
   const size_t capacity_after_gc = capacity();
-  const size_t free_after_gc = capacity_after_gc - used_after_gc;
+  const size_t used_after_gc = capacity_after_gc - unused_committed_regions_in_bytes();
 
   // This is enforced in arguments.cpp.
   assert(MinHeapFreeRatio <= MaxHeapFreeRatio,
@@ -1326,8 +1330,9 @@
     size_t expand_bytes = minimum_desired_capacity - capacity_after_gc;
 
     log_debug(gc, ergo, heap)("Attempt heap expansion (capacity lower than min desired capacity after Full GC). "
-                              "Capacity: " SIZE_FORMAT "B occupancy: " SIZE_FORMAT "B min_desired_capacity: " SIZE_FORMAT "B (" UINTX_FORMAT " %%)",
-                              capacity_after_gc, used_after_gc, minimum_desired_capacity, MinHeapFreeRatio);
+                              "Capacity: " SIZE_FORMAT "B occupancy: " SIZE_FORMAT "B live: " SIZE_FORMAT "B "
+                              "min_desired_capacity: " SIZE_FORMAT "B (" UINTX_FORMAT " %%)",
+                              capacity_after_gc, used_after_gc, used(), minimum_desired_capacity, MinHeapFreeRatio);
 
     expand(expand_bytes, _workers);
 
@@ -1337,8 +1342,9 @@
     size_t shrink_bytes = capacity_after_gc - maximum_desired_capacity;
 
     log_debug(gc, ergo, heap)("Attempt heap shrinking (capacity higher than max desired capacity after Full GC). "
-                              "Capacity: " SIZE_FORMAT "B occupancy: " SIZE_FORMAT "B min_desired_capacity: " SIZE_FORMAT "B (" UINTX_FORMAT " %%)",
-                              capacity_after_gc, used_after_gc, minimum_desired_capacity, MinHeapFreeRatio);
+                              "Capacity: " SIZE_FORMAT "B occupancy: " SIZE_FORMAT "B live: " SIZE_FORMAT "B "
+                              "maximum_desired_capacity: " SIZE_FORMAT "B (" UINTX_FORMAT " %%)",
+                              capacity_after_gc, used_after_gc, used(), maximum_desired_capacity, MaxHeapFreeRatio);
 
     shrink(shrink_bytes);
   }
@@ -1959,6 +1965,10 @@
   return _hrm.length() * HeapRegion::GrainBytes;
 }
 
+size_t G1CollectedHeap::unused_committed_regions_in_bytes() const {
+  return _hrm.total_free_bytes();
+}
+
 void G1CollectedHeap::reset_gc_time_stamps(HeapRegion* hr) {
   hr->reset_gc_time_stamp();
 }
@@ -2262,10 +2272,15 @@
   _hrm.iterate(cl);
 }
 
-void G1CollectedHeap::heap_region_par_iterate(HeapRegionClosure* cl,
-                                              uint worker_id,
-                                              HeapRegionClaimer *hrclaimer) const {
-  _hrm.par_iterate(cl, worker_id, hrclaimer);
+void G1CollectedHeap::heap_region_par_iterate_from_worker_offset(HeapRegionClosure* cl,
+                                                                 HeapRegionClaimer *hrclaimer,
+                                                                 uint worker_id) const {
+  _hrm.par_iterate(cl, hrclaimer, hrclaimer->offset_for_worker(worker_id));
+}
+
+void G1CollectedHeap::heap_region_par_iterate_from_start(HeapRegionClosure* cl,
+                                                         HeapRegionClaimer *hrclaimer) const {
+  _hrm.par_iterate(cl, hrclaimer, 0);
 }
 
 void G1CollectedHeap::collection_set_iterate(HeapRegionClosure* cl) {
@@ -2276,14 +2291,6 @@
   _collection_set.iterate_from(cl, worker_id, workers()->active_workers());
 }
 
-HeapRegion* G1CollectedHeap::next_compaction_region(const HeapRegion* from) const {
-  HeapRegion* result = _hrm.next_region_in_heap(from);
-  while (result != NULL && result->is_pinned()) {
-    result = _hrm.next_region_in_heap(result);
-  }
-  return result;
-}
-
 HeapWord* G1CollectedHeap::block_start(const void* addr) const {
   HeapRegion* hr = heap_region_containing(addr);
   return hr->block_start(addr);
@@ -2375,7 +2382,7 @@
   switch (vo) {
   case VerifyOption_G1UsePrevMarking: return is_obj_dead(obj, hr);
   case VerifyOption_G1UseNextMarking: return is_obj_ill(obj, hr);
-  case VerifyOption_G1UseMarkWord:    return !obj->is_gc_marked() && !hr->is_archive();
+  case VerifyOption_G1UseFullMarking: return is_obj_dead_full(obj, hr);
   default:                            ShouldNotReachHere();
   }
   return false; // keep some compilers happy
@@ -2386,10 +2393,7 @@
   switch (vo) {
   case VerifyOption_G1UsePrevMarking: return is_obj_dead(obj);
   case VerifyOption_G1UseNextMarking: return is_obj_ill(obj);
-  case VerifyOption_G1UseMarkWord: {
-    HeapRegion* hr = _hrm.addr_to_region((HeapWord*)obj);
-    return !obj->is_gc_marked() && !hr->is_archive();
-  }
+  case VerifyOption_G1UseFullMarking: return is_obj_dead_full(obj);
   default:                            ShouldNotReachHere();
   }
   return false; // keep some compilers happy
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -1046,6 +1046,7 @@
   // The Concurrent Marking reference processor...
   ReferenceProcessor* ref_processor_cm() const { return _ref_processor_cm; }
 
+  size_t unused_committed_regions_in_bytes() const;
   virtual size_t capacity() const;
   virtual size_t used() const;
   // This should be called when we're not holding the heap lock. The
@@ -1181,6 +1182,8 @@
     return barrier_set_cast<G1SATBCardTableLoggingModRefBS>(barrier_set());
   }
 
+  G1HotCardCache* g1_hot_card_cache() const { return _hot_card_cache; }
+
   // Iteration functions.
 
   // Iterate over all objects, calling "cl.do_object" on each.
@@ -1207,15 +1210,18 @@
 
   inline HeapWord* bottom_addr_for_region(uint index) const;
 
-  // Iterate over the heap regions in parallel. Assumes that this will be called
-  // in parallel by a number of worker threads with distinct worker ids
-  // in the range passed to the HeapRegionClaimer. Applies "blk->doHeapRegion"
-  // to each of the regions, by attempting to claim the region using the
-  // HeapRegionClaimer and, if successful, applying the closure to the claimed
-  // region.
-  void heap_region_par_iterate(HeapRegionClosure* cl,
-                               uint worker_id,
-                               HeapRegionClaimer* hrclaimer) const;
+  // Two functions to iterate over the heap regions in parallel. Threads
+  // compete using the HeapRegionClaimer to claim the regions before
+  // applying the closure on them.
+  // The _from_worker_offset version uses the HeapRegionClaimer and
+  // the worker id to calculate a start offset to prevent all workers to
+  // start from the point.
+  void heap_region_par_iterate_from_worker_offset(HeapRegionClosure* cl,
+                                                  HeapRegionClaimer* hrclaimer,
+                                                  uint worker_id) const;
+
+  void heap_region_par_iterate_from_start(HeapRegionClosure* cl,
+                                          HeapRegionClaimer* hrclaimer) const;
 
   // Iterate over the regions (if any) in the current collection set.
   void collection_set_iterate(HeapRegionClosure* blk);
@@ -1226,8 +1232,6 @@
   // collection set regions.
   void collection_set_iterate_from(HeapRegionClosure *blk, uint worker_id);
 
-  HeapRegion* next_compaction_region(const HeapRegion* from) const;
-
   // Returns the HeapRegion that contains addr. addr must not be NULL.
   template <class T>
   inline HeapRegion* heap_region_containing(const T addr) const;
@@ -1391,6 +1395,9 @@
 
   inline bool is_obj_ill(const oop obj) const;
 
+  inline bool is_obj_dead_full(const oop obj, const HeapRegion* hr) const;
+  inline bool is_obj_dead_full(const oop obj) const;
+
   G1ConcurrentMark* concurrent_mark() const { return _cm; }
 
   // Refinement
@@ -1435,9 +1442,9 @@
 
   // Perform verification.
 
-  // vo == UsePrevMarking  -> use "prev" marking information,
+  // vo == UsePrevMarking -> use "prev" marking information,
   // vo == UseNextMarking -> use "next" marking information
-  // vo == UseMarkWord    -> use the mark word in the object header
+  // vo == UseFullMarking -> use "next" marking bitmap but no TAMS
   //
   // NOTE: Only the "prev" marking information is guaranteed to be
   // consistent most of the time, so most calls to this should use
@@ -1446,7 +1453,7 @@
   // vo == UseNextMarking, which is to verify the "next" marking
   // information at the end of remark.
   // Currently there is only one place where this is called with
-  // vo == UseMarkWord, which is to verify the marking during a
+  // vo == UseFullMarking, which is to verify the marking during a
   // full GC.
   void verify(VerifyOption vo);
 
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.inline.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.inline.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -264,6 +264,14 @@
   return is_obj_ill(obj, heap_region_containing(obj));
 }
 
+inline bool G1CollectedHeap::is_obj_dead_full(const oop obj, const HeapRegion* hr) const {
+   return !isMarkedNext(obj) && !hr->is_archive();
+}
+
+inline bool G1CollectedHeap::is_obj_dead_full(const oop obj) const {
+    return is_obj_dead_full(obj, heap_region_containing(obj));
+}
+
 inline void G1CollectedHeap::set_humongous_reclaim_candidate(uint region, bool value) {
   assert(_hrm.at(region)->is_starts_humongous(), "Must start a humongous object");
   _humongous_reclaim_candidates.set_candidate(region, value);
--- a/src/hotspot/share/gc/g1/g1CollectedHeap_ext.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap_ext.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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
@@ -37,11 +37,6 @@
   return false;
 }
 
-HeapRegion* G1CollectedHeap::new_heap_region(uint hrs_index,
-                                             MemRegion mr) {
-  return new HeapRegion(hrs_index, bot(), mr);
-}
-
 G1Policy* G1CollectedHeap::create_g1_policy(STWGCTimer* gc_timer) {
   return new G1DefaultPolicy(gc_timer);
 }
--- a/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -634,7 +634,7 @@
 
   void work(uint worker_id) {
     SuspendibleThreadSetJoiner sts_join(_suspendible);
-    G1CollectedHeap::heap()->heap_region_par_iterate(&_cl, worker_id, &_hr_claimer);
+    G1CollectedHeap::heap()->heap_region_par_iterate_from_worker_offset(&_cl, &_hr_claimer, worker_id);
   }
 
   bool is_complete() {
@@ -1140,7 +1140,7 @@
     HRRSCleanupTask hrrs_cleanup_task;
     G1NoteEndOfConcMarkClosure g1_note_end(_g1h, &local_cleanup_list,
                                            &hrrs_cleanup_task);
-    _g1h->heap_region_par_iterate(&g1_note_end, worker_id, &_hrclaimer);
+    _g1h->heap_region_par_iterate_from_worker_offset(&g1_note_end, &_hrclaimer, worker_id);
     assert(g1_note_end.complete(), "Shouldn't have yielded!");
 
     // Now update the lists
--- a/src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.cpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -25,6 +25,7 @@
 #include "precompiled.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
 #include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
+#include "gc/g1/heapRegion.hpp"
 #include "memory/virtualspace.hpp"
 
 void G1CMBitMap::print_on_error(outputStream* st, const char* prefix) const {
@@ -65,3 +66,10 @@
   _bm.at_put_range(addr_to_offset(intersection.start()),
                    addr_to_offset(intersection.end()), false);
 }
+
+void G1CMBitMap::clear_region(HeapRegion* region) {
+ if (!region->is_empty()) {
+   MemRegion mr(region->bottom(), region->top());
+   clear_range(mr);
+ }
+}
--- a/src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -28,6 +28,7 @@
 #include "gc/g1/g1RegionToSpaceMapper.hpp"
 #include "memory/allocation.hpp"
 #include "memory/memRegion.hpp"
+#include "oops/oopsHierarchy.hpp"
 #include "utilities/bitMap.hpp"
 #include "utilities/globalDefinitions.hpp"
 #include "utilities/macros.hpp"
@@ -35,6 +36,7 @@
 class G1CMBitMap;
 class G1CMTask;
 class G1ConcurrentMark;
+class HeapRegion;
 
 // Closure for iteration over bitmaps
 class G1CMBitMapClosure VALUE_OBJ_CLASS_SPEC {
@@ -96,6 +98,7 @@
   void initialize(MemRegion heap, G1RegionToSpaceMapper* storage);
 
   // Read marks
+  bool is_marked(oop obj) const;
   bool is_marked(HeapWord* addr) const {
     assert(_covered.contains(addr),
            "Address " PTR_FORMAT " is outside underlying space from " PTR_FORMAT " to " PTR_FORMAT,
@@ -120,9 +123,12 @@
   // Write marks.
   inline void mark(HeapWord* addr);
   inline void clear(HeapWord* addr);
+  inline void clear(oop obj);
   inline bool par_mark(HeapWord* addr);
+  inline bool par_mark(oop obj);
 
   void clear_range(MemRegion mr);
+  void clear_region(HeapRegion* hr);
 };
 
 #endif // SHARE_VM_GC_G1_G1CONCURRENTMARKBITMAP_HPP
--- a/src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.inline.hpp	Fri Nov 24 16:55:18 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.inline.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -83,4 +83,16 @@
   return _bm.par_set_bit(addr_to_offset(addr));
 }
 
+inline bool G1CMBitMap::par_mark(oop obj) {
+  return par_mark((HeapWord*) obj);
+}
+
+inline bool G1CMBitMap::is_marked(oop obj) const{
+  return is_marked((HeapWord*) obj);
+}
+
+inline void G1CMBitMap::clear(oop obj) {
+  clear((HeapWord*) obj);
+}
+
 #endif // SHARE_VM_GC_G1_G1CONCURRENTMARKBITMAP_INLINE_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullCollector.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,245 @@
+/*
+ * 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 "code/codeCache.hpp"
+#include "gc/g1/g1CollectedHeap.hpp"
+#include "gc/g1/g1CollectorPolicy.hpp"
+#include "gc/g1/g1FullCollector.hpp"
+#include "gc/g1/g1FullGCAdjustTask.hpp"
+#include "gc/g1/g1FullGCCompactTask.hpp"
+#include "gc/g1/g1FullGCMarker.inline.hpp"
+#include "gc/g1/g1FullGCMarkTask.hpp"
+#include "gc/g1/g1FullGCPrepareTask.hpp"
+#include "gc/g1/g1FullGCReferenceProcessorExecutor.hpp"
+#include "gc/g1/g1FullGCScope.hpp"
+#include "gc/g1/g1OopClosures.hpp"
+#include "gc/g1/g1StringDedup.hpp"
+#include "gc/shared/gcTraceTime.inline.hpp"
+#include "gc/shared/preservedMarks.hpp"
+#include "gc/shared/referenceProcessor.hpp"
+#include "gc/shared/weakProcessor.hpp"
+#include "logging/log.hpp"
+#include "runtime/biasedLocking.hpp"
+#include "utilities/debug.hpp"
+
+static void clear_and_activate_derived_pointers() {
+#if COMPILER2_OR_JVMCI
+  DerivedPointerTable::clear();
+#endif
+}
+
+static void deactivate_derived_pointers() {
+#if COMPILER2_OR_JVMCI
+  DerivedPointerTable::set_active(false);
+#endif
+}
+
+static void update_derived_pointers() {
+#if COMPILER2_OR_JVMCI
+  DerivedPointerTable::update_pointers();
+#endif
+}
+
+G1FullCollector::G1FullCollector(G1FullGCScope* scope,
+                                 ReferenceProcessor* reference_processor,
+                                 G1CMBitMap* bitmap,
+                                 uint workers) :
+    _scope(scope),
+    _num_workers(workers),
+    _mark_bitmap(bitmap),
+    _oop_queue_set(_num_workers),
+    _array_queue_set(_num_workers),
+    _preserved_marks_set(true),
+    _reference_processor(reference_processor),
+    _serial_compaction_point(),
+    _is_alive(_mark_bitmap),
+    _is_alive_mutator(_reference_processor, &_is_alive) {
+  assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
+
+  _preserved_marks_set.init(_num_workers);
+  _markers = NEW_C_HEAP_ARRAY(G1FullGCMarker*, _num_workers, mtGC);
+  _compaction_points = NEW_C_HEAP_ARRAY(G1FullGCCompactionPoint*, _num_workers, mtGC);
+  for (uint i = 0; i < _num_workers; i++) {
+    _markers[i] = new G1FullGCMarker(i, _preserved_marks_set.get(i), mark_bitmap());
+    _compaction_points[i] = new G1FullGCCompactionPoint();
+    _oop_queue_set.register_queue(i, marker(i)->oop_stack());
+    _array_queue_set.register_queue(i, marker(i)->objarray_stack());
+  }
+}
+
+G1FullCollector::~G1FullCollector() {
+  for (uint i = 0; i < _num_workers; i++) {
+    delete _markers[i];
+    delete _compaction_points[i];
+  }
+  FREE_C_HEAP_ARRAY(G1FullGCMarker*, _markers);
+  FREE_C_HEAP_ARRAY(G1FullGCCompactionPoint*, _compaction_points);
+}
+
+void G1FullCollector::prepare_collection() {
+  _reference_processor->enable_discovery();
+  _reference_processor->setup_policy(scope()->should_clear_soft_refs());
+
+  // When collecting the permanent generation Method*s may be moving,
+  // so we either have to flush all bcp data or convert it into bci.
+  CodeCache::gc_prologue();
+
+  // We should save the marks of the currently locked biased monitors.
+  // The marking doesn't preserve the marks of biased objects.
+  BiasedLocking::preserve_marks();
+
+  // Clear and activate derived pointer collection.
+  clear_and_activate_derived_pointers();
+}
+
+void G1FullCollector::collect() {
+  phase1_mark_live_objects();
+  verify_after_marking();
+
+  // Don't add any more derived pointers during later phases
+  deactivate_derived_pointers();
+
+  phase2_prepare_compaction();
+
+  phase3_adjust_pointers();
+
+  phase4_do_compaction();
+}
+
+void G1FullCollector::complete_collection() {
+  // Restore all marks.
+  restore_marks();
+
+  // When the pointers have been adjusted and moved, we can
+  // update the derived pointer table.
+  update_derived_pointers();
+
+  BiasedLocking::restore_marks();
+  CodeCache::gc_epilogue();
+  JvmtiExport::gc_epilogue();
+}
+
+void G1FullCollector::phase1_mark_live_objects() {
+  // Recursively traverse all live objects and mark them.
+  GCTraceTime(Info, gc, phases) info("Phase 1: Mark live objects", scope()->timer());
+
+  // Do the actual marking.
+  G1FullGCMarkTask marking_task(this);
+  run_task(&marking_task);
+
+  // Process references discovered during marking.
+  G1FullGCReferenceProcessingExecutor reference_processing(this);
+  reference_processing.execute(scope()->timer(), scope()->tracer());
+
+  // Weak oops cleanup.
+  {
+    GCTraceTime(Debug, gc, phases) trace("Phase 1: Weak Processing", scope()->timer());
+    WeakProcessor::weak_oops_do(&_is_alive, &do_nothing_cl);
+  }
+
+  // Class unloading and cleanup.
+  if (ClassUnloading) {
+    GCTraceTime(Debug, gc, phases) debug("Phase 1: Class Unloading and Cleanup", scope()->timer());
+    // Unload classes and purge the SystemDictionary.
+    bool purged_class = SystemDictionary::do_unloading(&_is_alive, scope()->timer());
+    G1CollectedHeap::heap()->complete_cleaning(&_is_alive, purged_class);
+  } else {
+    GCTraceTime(Debug, gc, phases) debug("Phase 1: String and Symbol Tables Cleanup", scope()->timer());
+    // If no class unloading just clean out strings and symbols.
+    G1CollectedHeap::heap()->partial_cleaning(&_is_alive, true, true, G1StringDedup::is_enabled());
+  }
+
+  scope()->tracer()->report_object_count_after_gc(&_is_alive);
+}
+
+void G1FullCollector::prepare_compaction_common() {
+  G1FullGCPrepareTask task(this);
+  run_task(&task);
+
+  // To avoid OOM when there is memory left.
+  if (!task.has_freed_regions()) {
+    task.prepare_serial_compaction();
+  }
+}
+
+void G1FullCollector::phase2_prepare_compaction() {
+  GCTraceTime(Info, gc, phases) info("Phase 2: Prepare for compaction", scope()->timer());
+  prepare_compaction_ext(); // Will call prepare_compaction_common() above.
+}
+
+void G1FullCollector::phase3_adjust_pointers() {
+  // Adjust the pointers to reflect the new locations
+  GCTraceTime(Info, gc, phases) info("Phase 3: Adjust pointers and remembered sets", scope()->timer());
+
+  G1FullGCAdjustTask task(this);
+  run_task(&task);
+}
+
+void G1FullCollector::phase4_do_compaction() {
+  // Compact the heap using the compaction queues created in phase 2.
+  GCTraceTime(Info, gc, phases) info("Phase 4: Compact heap", scope()->timer());
+  G1FullGCCompactTask task(this);
+  run_task(&task);
+
+  // Serial compact to avoid OOM when very few free regions.
+  if (serial_compaction_point()->has_regions()) {
+    task.serial_compaction();
+  }
+}
+
+void G1FullCollector::restore_marks() {
+  SharedRestorePreservedMarksTaskExecutor task_executor(G1CollectedHeap::heap()->workers());
+  _preserved_marks_set.restore(&task_executor);
+  _preserved_marks_set.reclaim();
+}
+
+void G1FullCollector::run_task(AbstractGangTask* task) {
+  G1CollectedHeap::heap()->workers()->run_task(task, _num_workers);
+}
+
+void G1FullCollector::verify_after_marking() {
+  if (!VerifyDuringGC) {
+    //Only do verification if VerifyDuringGC is set.
+    return;
+  }
+
+  HandleMark hm;  // handle scope
+#if COMPILER2_OR_JVMCI
+  DerivedPointerTableDeactivate dpt_deact;
+#endif
+  G1CollectedHeap::heap()->prepare_for_verify();
+  // Note: we can verify only the heap here. When an object is
+  // marked, the previous value of the mark word (including
+  // identity hash values, ages, etc) is preserved, and the mark
+  // word is set to markOop::marked_value - effectively removing
+  // any hash values from the mark word. These hash values are
+  // used when verifying the dictionaries and so removing them
+  // from the mark word can make verification of the dictionaries
+  // fail. At the end of the GC, the original mark word values
+  // (including hash values) are restored to the appropriate
+  // objects.
+  GCTraceTime(Info, gc, verify)("During GC (full)");
+  G1CollectedHeap::heap()->verify(VerifyOption_G1UseFullMarking);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullCollector.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,98 @@
+/*
+ * 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_GC_G1_G1FULLCOLLECTOR_HPP
+#define SHARE_GC_G1_G1FULLCOLLECTOR_HPP
+
+#include "gc/g1/g1FullGCCompactionPoint.hpp"
+#include "gc/g1/g1FullGCMarker.hpp"
+#include "gc/g1/g1FullGCOopClosures.hpp"
+#include "gc/shared/preservedMarks.hpp"
+#include "gc/shared/referenceProcessor.hpp"
+#include "gc/shared/taskqueue.hpp"
+#include "memory/allocation.hpp"
+
+class AbstractGangTask;
+class G1CMBitMap;
+class G1FullGCMarker;
+class G1FullGCScope;
+class G1FullGCCompactionPoint;
+class ReferenceProcessor;
+
+// The G1FullCollector holds data associated with the current Full GC.
+class G1FullCollector : StackObj {
+  G1FullGCScope*            _scope;
+  uint                      _num_workers;
+  G1FullGCMarker**          _markers;
+  G1FullGCCompactionPoint** _compaction_points;
+  G1CMBitMap*               _mark_bitmap;
+  OopQueueSet               _oop_queue_set;
+  ObjArrayTaskQueueSet      _array_queue_set;
+  PreservedMarksSet         _preserved_marks_set;
+  ReferenceProcessor*       _reference_processor;
+  G1FullGCCompactionPoint   _serial_compaction_point;
+
+  G1IsAliveClosure          _is_alive;
+  ReferenceProcessorIsAliveMutator _is_alive_mutator;
+
+public:
+  G1FullCollector(G1FullGCScope* scope,
+                  ReferenceProcessor* reference_processor,
+                  G1CMBitMap* mark_bitmap,
+                  uint workers);
+  ~G1FullCollector();
+
+  void prepare_collection();
+  void collect();
+  void complete_collection();
+
+  G1FullGCScope*           scope() { return _scope; }
+  uint                     workers() { return _num_workers; }
+  G1FullGCMarker*          marker(uint id) { return _markers[id]; }
+  G1FullGCCompactionPoint* compaction_point(uint id) { return _compaction_points[id]; }
+  G1CMBitMap*              mark_bitmap() { return _mark_bitmap; }
+  OopQueueSet*             oop_queue_set() { return &_oop_queue_set; }
+  ObjArrayTaskQueueSet*    array_queue_set() { return &_array_queue_set; }
+  PreservedMarksSet*       preserved_mark_set() { return &_preserved_marks_set; }
+  ReferenceProcessor*      reference_processor() { return _reference_processor; }
+  G1FullGCCompactionPoint* serial_compaction_point() { return &_serial_compaction_point; }
+
+private:
+  void phase1_mark_live_objects();
+  void phase2_prepare_compaction();
+  void phase3_adjust_pointers();
+  void phase4_do_compaction();
+
+  void restore_marks();
+  void verify_after_marking();
+
+  void run_task(AbstractGangTask* task);
+
+  // Prepare compaction extension support.
+  void prepare_compaction_ext();
+  void prepare_compaction_common();
+};
+
+
+#endif // SHARE_GC_G1_G1FULLCOLLECTOR_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullCollector_ext.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,30 @@
+/*
+ * 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/g1/g1FullCollector.hpp"
+
+void G1FullCollector::prepare_compaction_ext() {
+  prepare_compaction_common();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCAdjustTask.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,119 @@
+/*
+ * 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/g1/g1CollectedHeap.hpp"
+#include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
+#include "gc/g1/g1FullCollector.hpp"
+#include "gc/g1/g1FullGCAdjustTask.hpp"
+#include "gc/g1/g1FullGCCompactionPoint.hpp"
+#include "gc/g1/g1FullGCMarker.hpp"
+#include "gc/g1/g1FullGCOopClosures.inline.hpp"
+#include "gc/g1/heapRegion.inline.hpp"
+#include "gc/shared/gcTraceTime.inline.hpp"
+#include "gc/shared/referenceProcessor.hpp"
+#include "logging/log.hpp"
+#include "utilities/ticks.inline.hpp"
+
+class G1AdjustLiveClosure : public StackObj {
+  G1AdjustAndRebuildClosure* _adjust_closure;
+public:
+  G1AdjustLiveClosure(G1AdjustAndRebuildClosure* cl) :
+    _adjust_closure(cl) { }
+
+  size_t apply(oop object) {
+    _adjust_closure->update_compaction_delta(object);
+    return object->oop_iterate_size(_adjust_closure);
+  }
+};
+
+class G1AdjustRegionClosure : public HeapRegionClosure {
+  G1CMBitMap* _bitmap;
+  uint _worker_id;
+ public:
+  G1AdjustRegionClosure(G1CMBitMap* bitmap, uint worker_id) :
+    _bitmap(bitmap),
+    _worker_id(worker_id) { }
+
+  bool doHeapRegion(HeapRegion* r) {
+    G1AdjustAndRebuildClosure cl(_worker_id);
+    if (r->is_humongous()) {
+      oop obj = oop(r->humongous_start_region()->bottom());
+      cl.update_compaction_delta(obj);
+      obj->oop_iterate(&cl, MemRegion(r->bottom(), r->top()));
+    } else if (r->is_open_archive()) {
+      // Only adjust the open archive regions, the closed ones
+      // never change.
+      G1AdjustLiveClosure adjust(&cl);
+      r->apply_to_marked_objects(_bitmap, &adjust);
+      // Open archive regions will not be compacted and the marking information is
+      // no longer needed. Clear it here to avoid having to do it later.
+      _bitmap->clear_region(r);
+    } else {
+      G1AdjustLiveClosure adjust(&cl);
+      r->apply_to_marked_objects(_bitmap, &adjust);
+    }
+    return false;
+  }
+};
+
+G1FullGCAdjustTask::G1FullGCAdjustTask(G1FullCollector* collector) :
+    G1FullGCTask("G1 Adjust and Rebuild", collector),
+    _root_processor(G1CollectedHeap::heap(), collector->workers()),
+    _hrclaimer(collector->workers()),
+    _adjust(),
+    _adjust_string_dedup(NULL, &_adjust, G1StringDedup::is_enabled()) {
+  // Need cleared claim bits for the roots processing
+  ClassLoaderDataGraph::clear_claimed_marks();
+}
+
+void G1FullGCAdjustTask::work(uint worker_id) {
+  Ticks start = Ticks::now();
+  ResourceMark rm;
+
+  // Adjust preserved marks first since they are not balanced.
+  G1FullGCMarker* marker = collector()->marker(worker_id);
+  marker->preserved_stack()->adjust_during_full_gc();
+
+  // Adjust the weak_roots.
+  CLDToOopClosure adjust_cld(&_adjust);
+  CodeBlobToOopClosure adjust_code(&_adjust, CodeBlobToOopClosure::FixRelocations);
+  _root_processor.process_full_gc_weak_roots(&_adjust);
+
+  // Needs to be last, process_all_roots calls all_tasks_completed(...).
+  _root_processor.process_all_roots(
+      &_adjust,
+      &adjust_cld,
+      &adjust_code);
+
+  // Adjust string dedup if enabled.
+  if (G1StringDedup::is_enabled()) {
+    G1StringDedup::parallel_unlink(&_adjust_string_dedup, worker_id);
+  }
+
+  // Now adjust pointers region by region
+  G1AdjustRegionClosure blk(collector()->mark_bitmap(), worker_id);
+  G1CollectedHeap::heap()->heap_region_par_iterate_from_worker_offset(&blk, &_hrclaimer, worker_id);
+  log_task("Adjust and Rebuild task", worker_id, start);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCAdjustTask.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,48 @@
+/*
+ * 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_GC_G1_G1FULLGCADJUSTTASK_HPP
+#define SHARE_GC_G1_G1FULLGCADJUSTTASK_HPP
+
+#include "gc/g1/g1FullGCOopClosures.hpp"
+#include "gc/g1/g1FullGCTask.hpp"
+#include "gc/g1/g1RootProcessor.hpp"
+#include "gc/g1/g1StringDedup.hpp"
+#include "gc/g1/heapRegionManager.hpp"
+#include "utilities/ticks.hpp"
+
+class G1CollectedHeap;
+
+class G1FullGCAdjustTask : public G1FullGCTask {
+  G1RootProcessor          _root_processor;
+  HeapRegionClaimer        _hrclaimer;
+  G1AdjustClosure          _adjust;
+  G1StringDedupUnlinkOrOopsDoClosure _adjust_string_dedup;
+
+public:
+  G1FullGCAdjustTask(G1FullCollector* collector);
+  void work(uint worker_id);
+};
+
+#endif // SHARE_GC_G1_G1FULLGCADJUSTTASK_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCCompactTask.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,111 @@
+/*
+ * 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/g1/g1CollectedHeap.hpp"
+#include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
+#include "gc/g1/g1FullCollector.hpp"
+#include "gc/g1/g1FullGCCompactionPoint.hpp"
+#include "gc/g1/g1FullGCCompactTask.hpp"
+#include "gc/g1/heapRegion.inline.hpp"
+#include "gc/shared/gcTraceTime.inline.hpp"
+#include "logging/log.hpp"
+#include "utilities/ticks.inline.hpp"
+
+class G1ResetHumongousClosure : public HeapRegionClosure {
+  G1CMBitMap* _bitmap;
+
+public:
+  G1ResetHumongousClosure(G1CMBitMap* bitmap) :
+      _bitmap(bitmap) { }
+
+  bool doHeapRegion(HeapRegion* current) {
+    if (current->is_humongous()) {
+      if (current->is_starts_humongous()) {
+        oop obj = oop(current->bottom());
+        if (_bitmap->is_marked(obj)) {
+          // Clear bitmap and fix mark word.
+          _bitmap->clear(obj);
+          obj->init_mark();
+        } else {
+          assert(current->is_empty(), "Should have been cleared in phase 2.");
+        }
+      }
+      current->reset_during_compaction();
+    }
+    return false;
+  }
+};
+
+size_t G1FullGCCompactTask::G1CompactRegionClosure::apply(oop obj) {
+  size_t size = obj->size();
+  HeapWord* destination = (HeapWord*)obj->forwardee();
+  if (destination == NULL) {
+    // Object not moving
+    return size;
+  }
+
+  // copy object and reinit its mark
+  HeapWord* obj_addr = (HeapWord*) obj;
+  assert(obj_addr != destination, "everything in this pass should be moving");
+  Copy::aligned_conjoint_words(obj_addr, destination, size);
+  oop(destination)->init_mark();
+  assert(oop(destination)->klass() != NULL, "should have a class");
+
+  return size;
+}
+
+void G1FullGCCompactTask::compact_region(HeapRegion* hr) {
+  assert(!hr->is_humongous(), "Should be no humongous regions in compaction queue");
+  G1CompactRegionClosure compact(collector()->mark_bitmap());
+  hr->apply_to_marked_objects(collector()->mark_bitmap(), &compact);
+  // Once all objects have been moved the liveness information
+  // needs be cleared.
+  collector()->mark_bitmap()->clear_region(hr);
+  hr->complete_compaction();
+}
+
+void G1FullGCCompactTask::work(uint worker_id) {
+  Ticks start = Ticks::now();
+  GrowableArray<HeapRegion*>* compaction_queue = collector()->compaction_point(worker_id)->regions();
+  for (GrowableArrayIterator<HeapRegion*> it = compaction_queue->begin();
+       it != compaction_queue->end();
+       ++it) {
+    compact_region(*it);
+  }
+
+  G1ResetHumongousClosure hc(collector()->mark_bitmap());
+  G1CollectedHeap::heap()->heap_region_par_iterate_from_worker_offset(&hc, &_claimer, worker_id);
+  log_task("Compaction task", worker_id, start);
+}
+
+void G1FullGCCompactTask::serial_compaction() {
+  GCTraceTime(Debug, gc, phases) tm("Phase 4: Serial Compaction", collector()->scope()->timer());
+  GrowableArray<HeapRegion*>* compaction_queue = collector()->serial_compaction_point()->regions();
+  for (GrowableArrayIterator<HeapRegion*> it = compaction_queue->begin();
+       it != compaction_queue->end();
+       ++it) {
+    compact_region(*it);
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCCompactTask.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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.
+ *
+ */
+
+#ifndef SHARE_GC_G1_G1FULLGCCOMPACTTASK_HPP
+#define SHARE_GC_G1_G1FULLGCCOMPACTTASK_HPP
+
+#include "gc/g1/g1FullGCCompactionPoint.hpp"
+#include "gc/g1/g1FullGCScope.hpp"
+#include "gc/g1/g1FullGCTask.hpp"
+#include "gc/g1/g1StringDedup.hpp"
+#include "gc/g1/heapRegionManager.hpp"
+#include "gc/shared/referenceProcessor.hpp"
+#include "utilities/ticks.hpp"
+
+class G1CollectedHeap;
+class G1CMBitMap;
+
+class G1FullGCCompactTask : public G1FullGCTask {
+protected:
+  HeapRegionClaimer _claimer;
+
+private:
+  void compact_region(HeapRegion* hr);
+
+public:
+  G1FullGCCompactTask(G1FullCollector* collector) :
+    G1FullGCTask("G1 Compact Task", collector),
+    _claimer(collector->workers()) { }
+  void work(uint worker_id);
+  void serial_compaction();
+
+  class G1CompactRegionClosure : public StackObj {
+    G1CMBitMap* _bitmap;
+
+  public:
+    G1CompactRegionClosure(G1CMBitMap* bitmap) : _bitmap(bitmap) { }
+    size_t apply(oop object);
+  };
+};
+
+#endif // SHARE_GC_G1_G1FULLGCCOMPACTTASK_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCCompactionPoint.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "gc/g1/g1FullGCCompactionPoint.hpp"
+#include "gc/g1/heapRegion.hpp"
+#include "oops/oop.inline.hpp"
+#include "utilities/debug.hpp"
+
+G1FullGCCompactionPoint::G1FullGCCompactionPoint() :
+    _current_region(NULL),
+    _threshold(NULL),
+    _compaction_top(NULL) {
+  _compaction_regions = new (ResourceObj::C_HEAP, mtGC) GrowableArray<HeapRegion*>(32, true, mtGC);
+  _compaction_region_iterator = _compaction_regions->begin();
+}
+
+G1FullGCCompactionPoint::~G1FullGCCompactionPoint() {
+  delete _compaction_regions;
+}
+
+void G1FullGCCompactionPoint::update() {
+  if (is_initialized()) {
+    _current_region->set_compaction_top(_compaction_top);
+  }
+}
+
+void G1FullGCCompactionPoint::initialize_values(bool init_threshold) {
+  _compaction_top = _current_region->compaction_top();
+  if (init_threshold) {
+    _threshold = _current_region->initialize_threshold();
+  }
+}
+
+bool G1FullGCCompactionPoint::has_regions() {
+  return !_compaction_regions->is_empty();
+}
+
+bool G1FullGCCompactionPoint::is_initialized() {
+  return _current_region != NULL;
+}
+
+void G1FullGCCompactionPoint::initialize(HeapRegion* hr, bool init_threshold) {
+  _current_region = hr;
+  initialize_values(init_threshold);
+}
+
+HeapRegion* G1FullGCCompactionPoint::current_region() {
+  return *_compaction_region_iterator;
+}
+
+HeapRegion* G1FullGCCompactionPoint::next_region() {
+  HeapRegion* next = *(++_compaction_region_iterator);
+  assert(next != NULL, "Must return valid region");
+  return next;
+}
+
+GrowableArray<HeapRegion*>* G1FullGCCompactionPoint::regions() {
+  return _compaction_regions;
+}
+
+bool G1FullGCCompactionPoint::object_will_fit(size_t size) {
+  size_t space_left = pointer_delta(_current_region->end(), _compaction_top);
+  return size <= space_left;
+}
+
+void G1FullGCCompactionPoint::switch_region() {
+  // Save compaction top in the region.
+  _current_region->set_compaction_top(_compaction_top);
+  // Get the next region and re-initialize the values.
+  _current_region = next_region();
+  initialize_values(true);
+}
+
+void G1FullGCCompactionPoint::forward(oop object, size_t size) {
+  assert(_current_region != NULL, "Must have been initialized");
+
+  // Ensure the object fit in the current region.
+  while (!object_will_fit(size)) {
+    switch_region();
+  }
+
+  // Store a forwarding pointer if the object should be moved.
+  if ((HeapWord*)object != _compaction_top) {
+    object->forward_to(oop(_compaction_top));
+  } else {
+    if (object->forwardee() != NULL) {
+      // Object should not move but mark-word is used so it looks like the
+      // object is forwarded. Need to clear the mark and it's no problem
+      // since it will be restored by preserved marks. There is an exception
+      // with BiasedLocking, in this case forwardee() will return NULL
+      // even if the mark-word is used. This is no problem since
+      // forwardee() will return NULL in the compaction phase as well.
+      object->init_mark();
+    } else {
+      // Make sure object has the correct mark-word set or that it will be
+      // fixed when restoring the preserved marks.
+      assert(object->mark() == markOopDesc::prototype_for_object(object) || // Correct mark
+             object->mark()->must_be_preserved(object) || // Will be restored by PreservedMarksSet
+             (UseBiasedLocking && object->has_bias_pattern()), // Will be restored by BiasedLocking
+             "should have correct prototype obj: " PTR_FORMAT " mark: " PTR_FORMAT " prototype: " PTR_FORMAT,
+             p2i(object), p2i(object->mark()), p2i(markOopDesc::prototype_for_object(object)));
+    }
+    assert(object->forwardee() == NULL, "should be forwarded to NULL");
+  }
+
+  // Update compaction values.
+  _compaction_top += size;
+  if (_compaction_top > _threshold) {
+    _threshold = _current_region->cross_threshold(_compaction_top - size, _compaction_top);
+  }
+}
+
+void G1FullGCCompactionPoint::add(HeapRegion* hr) {
+  _compaction_regions->append(hr);
+}
+
+void G1FullGCCompactionPoint::merge(G1FullGCCompactionPoint* other) {
+   _compaction_regions->appendAll(other->regions());
+}
+
+HeapRegion* G1FullGCCompactionPoint::remove_last() {
+  return _compaction_regions->pop();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCCompactionPoint.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_GC_G1_G1FULLGCCOMPACTIONPOINT_HPP
+#define SHARE_GC_G1_G1FULLGCCOMPACTIONPOINT_HPP
+
+#include "memory/allocation.hpp"
+#include "utilities/growableArray.hpp"
+
+class HeapRegion;
+
+class G1FullGCCompactionPoint : public CHeapObj<mtGC> {
+  HeapRegion* _current_region;
+  HeapWord*   _threshold;
+  HeapWord*   _compaction_top;
+  GrowableArray<HeapRegion*>* _compaction_regions;
+  GrowableArrayIterator<HeapRegion*> _compaction_region_iterator;
+
+  bool object_will_fit(size_t size);
+  void initialize_values(bool init_threshold);
+  void switch_region();
+  HeapRegion* next_region();
+
+public:
+  G1FullGCCompactionPoint();
+  ~G1FullGCCompactionPoint();
+
+  bool has_regions();
+  bool is_initialized();
+  void initialize(HeapRegion* hr, bool init_threshold);
+  void update();
+  void forward(oop object, size_t size);
+  void add(HeapRegion* hr);
+  void merge(G1FullGCCompactionPoint* other);
+
+  HeapRegion* remove_last();
+  HeapRegion* current_region();
+
+  GrowableArray<HeapRegion*>* regions();
+};
+
+#endif // SHARE_GC_G1_G1FULLGCCOMPACTIONPOINT_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCMarkTask.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "gc/g1/g1CollectedHeap.hpp"
+#include "gc/g1/g1FullCollector.hpp"
+#include "gc/g1/g1FullGCMarker.hpp"
+#include "gc/g1/g1FullGCMarkTask.hpp"
+#include "gc/g1/g1FullGCOopClosures.inline.hpp"
+#include "gc/g1/g1FullGCReferenceProcessorExecutor.hpp"
+#include "gc/shared/gcTraceTime.inline.hpp"
+#include "gc/shared/referenceProcessor.hpp"
+
+G1FullGCMarkTask::G1FullGCMarkTask(G1FullCollector* collector) :
+    G1FullGCTask("G1 Parallel Marking Task", collector),
+    _root_processor(G1CollectedHeap::heap(), collector->workers()),
+    _terminator(collector->workers(), collector->array_queue_set()) {
+  // Need cleared claim bits for the roots processing
+  ClassLoaderDataGraph::clear_claimed_marks();
+}
+
+void G1FullGCMarkTask::work(uint worker_id) {
+  Ticks start = Ticks::now();
+  ResourceMark rm;
+  G1FullGCMarker* marker = collector()->marker(worker_id);
+  MarkingCodeBlobClosure code_closure(marker->mark_closure(), !CodeBlobToOopClosure::FixRelocations);
+
+  if (ClassUnloading) {
+    _root_processor.process_strong_roots(
+        marker->mark_closure(),
+        marker->cld_closure(),
+        &code_closure);
+  } else {
+    _root_processor.process_all_roots_no_string_table(
+        marker->mark_closure(),
+        marker->cld_closure(),
+        &code_closure);
+  }
+
+  // Mark stack is populated, now process and drain it.
+  marker->complete_marking(collector()->oop_queue_set(), collector()->array_queue_set(), &_terminator);
+
+  // This is the point where the entire marking should have completed.
+  assert(marker->oop_stack()->is_empty(), "Marking should have completed");
+  assert(marker->objarray_stack()->is_empty(), "Array marking should have completed");
+  log_task("Marking task", worker_id, start);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCMarkTask.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -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.
+ *
+ */
+
+#ifndef SHARE_GC_G1_G1FULLGCMARKTASK_HPP
+#define SHARE_GC_G1_G1FULLGCMARKTASK_HPP
+
+#include "gc/g1/g1FullGCCompactionPoint.hpp"
+#include "gc/g1/g1FullGCScope.hpp"
+#include "gc/g1/g1FullGCTask.hpp"
+#include "gc/g1/g1RootProcessor.hpp"
+#include "gc/g1/g1StringDedup.hpp"
+#include "gc/g1/heapRegionManager.hpp"
+#include "gc/shared/referenceProcessor.hpp"
+#include "utilities/ticks.hpp"
+
+class G1FullGCMarkTask : public G1FullGCTask {
+  G1RootProcessor          _root_processor;
+  ParallelTaskTerminator   _terminator;
+
+public:
+  G1FullGCMarkTask(G1FullCollector* collector);
+  void work(uint worker_id);
+};
+
+#endif // SHARE_GC_G1_G1FULLGCMARKTASK_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCMarker.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,60 @@
+/*
+ * 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/g1/g1FullGCMarker.inline.hpp"
+
+G1FullGCMarker::G1FullGCMarker(uint worker_id, PreservedMarks* preserved_stack, G1CMBitMap* bitmap) :
+    _worker_id(worker_id),
+    _mark_closure(worker_id, this, G1CollectedHeap::heap()->ref_processor_stw()),
+    _verify_closure(VerifyOption_G1UseFullMarking),
+    _cld_closure(mark_closure()),
+    _stack_closure(this),
+    _preserved_stack(preserved_stack),
+    _bitmap(bitmap) {
+  _oop_stack.initialize();
+  _objarray_stack.initialize();
+}
+
+G1FullGCMarker::~G1FullGCMarker() {
+  assert(is_empty(), "Must be empty at this point");
+}
+
+void G1FullGCMarker::complete_marking(OopQueueSet* oop_stacks,
+                                      ObjArrayTaskQueueSet* array_stacks,
+                                      ParallelTaskTerminator* terminator) {
+  int hash_seed = 17;
+  do {
+    drain_stack();
+    ObjArrayTask steal_array;
+    if (array_stacks->steal(_worker_id, &hash_seed, steal_array)) {
+      follow_array_chunk(objArrayOop(steal_array.obj()), steal_array.index());
+    } else {
+      oop steal_oop;
+      if (oop_stacks->steal(_worker_id, &hash_seed, steal_oop)) {
+        follow_object(steal_oop);
+      }
+    }
+  } while (!is_empty() || !terminator->offer_termination());
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCMarker.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,99 @@
+/*
+ * 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_GC_G1_G1FULLGCMARKER_HPP
+#define SHARE_GC_G1_G1FULLGCMARKER_HPP
+
+#include "gc/g1/g1FullGCOopClosures.hpp"
+#include "gc/shared/preservedMarks.hpp"
+#include "gc/shared/taskqueue.hpp"
+#include "memory/iterator.hpp"
+#include "oops/markOop.hpp"
+#include "oops/oop.hpp"
+#include "runtime/timer.hpp"
+#include "utilities/chunkedList.hpp"
+#include "utilities/growableArray.hpp"
+#include "utilities/stack.hpp"
+
+typedef OverflowTaskQueue<oop, mtGC>                 OopQueue;
+typedef OverflowTaskQueue<ObjArrayTask, mtGC>        ObjArrayTaskQueue;
+
+typedef GenericTaskQueueSet<OopQueue, mtGC>          OopQueueSet;
+typedef GenericTaskQueueSet<ObjArrayTaskQueue, mtGC> ObjArrayTaskQueueSet;
+
+class G1CMBitMap;
+
+class G1FullGCMarker : public CHeapObj<mtGC> {
+private:
+  uint               _worker_id;
+  // Backing mark bitmap
+  G1CMBitMap*        _bitmap;
+
+  // Mark stack
+  OopQueue           _oop_stack;
+  ObjArrayTaskQueue  _objarray_stack;
+  PreservedMarks*    _preserved_stack;
+
+  // Marking closures
+  G1MarkAndPushClosure _mark_closure;
+  G1VerifyOopClosure   _verify_closure;
+  G1FollowStackClosure _stack_closure;
+  CLDToOopClosure      _cld_closure;
+
+  inline bool is_empty();
+  inline bool pop_object(oop& obj);
+  inline bool pop_objarray(ObjArrayTask& array);
+  inline void push_objarray(oop obj, size_t index);
+  inline bool mark_object(oop obj);
+
+  // Marking helpers
+  inline void follow_object(oop obj);
+  inline void follow_array(objArrayOop array);
+  inline void follow_array_chunk(objArrayOop array, int index);
+public:
+  G1FullGCMarker(uint worker_id, PreservedMarks* preserved_stack, G1CMBitMap* bitmap);
+  ~G1FullGCMarker();
+
+  // Stack getters
+  OopQueue*          oop_stack()       { return &_oop_stack; }
+  ObjArrayTaskQueue* objarray_stack()  { return &_objarray_stack; }
+  PreservedMarks*    preserved_stack() { return _preserved_stack; }
+
+  // Marking entry points
+  template <class T> inline void mark_and_push(T* p);
+  inline void follow_klass(Klass* k);
+  inline void follow_cld(ClassLoaderData* cld);
+
+  inline void drain_stack();
+  void complete_marking(OopQueueSet* oop_stacks,
+                        ObjArrayTaskQueueSet* array_stacks,
+                        ParallelTaskTerminator* terminator);
+
+  // Closure getters
+  CLDToOopClosure*      cld_closure()   { return &_cld_closure; }
+  G1MarkAndPushClosure* mark_closure()  { return &_mark_closure; }
+  G1FollowStackClosure* stack_closure() { return &_stack_closure; }
+};
+
+#endif // SHARE_GC_G1_G1FULLGCMARKER_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCMarker.inline.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,172 @@
+/*
+ * 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_G1_G1MARKSTACK_INLINE_HPP
+#define SHARE_VM_GC_G1_G1MARKSTACK_INLINE_HPP
+
+#include "gc/g1/g1Allocator.inline.hpp"
+#include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
+#include "gc/g1/g1FullGCMarker.hpp"
+#include "gc/g1/g1StringDedup.hpp"
+#include "gc/g1/g1StringDedupQueue.hpp"
+#include "gc/shared/preservedMarks.inline.hpp"
+#include "utilities/debug.hpp"
+
+inline bool G1FullGCMarker::mark_object(oop obj) {
+  // Not marking closed archive objects.
+  if (G1ArchiveAllocator::is_closed_archive_object(obj)) {
+    return false;
+  }
+
+  // Try to mark.
+  if (!_bitmap->par_mark(obj)) {
+    // Lost mark race.
+    return false;
+  }
+
+  // Marked by us, preserve if needed.
+  markOop mark = obj->mark();
+  if (mark->must_be_preserved(obj) &&
+      !G1ArchiveAllocator::is_open_archive_object(obj)) {
+    preserved_stack()->push(obj, mark);
+  }
+
+  // Check if deduplicatable string.
+  if (G1StringDedup::is_enabled()) {
+    G1StringDedup::enqueue_from_mark(obj, _worker_id);
+  }
+  return true;
+}
+
+template <class T> inline void G1FullGCMarker::mark_and_push(T* p) {
+  T heap_oop = oopDesc::load_heap_oop(p);
+  if (!oopDesc::is_null(heap_oop)) {
+    oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
+    if (mark_object(obj)) {
+      _oop_stack.push(obj);
+      assert(_bitmap->is_marked(obj), "Must be marked now - map self");
+    } else {
+      assert(_bitmap->is_marked(obj) || G1ArchiveAllocator::is_closed_archive_object(obj),
+             "Must be marked by other or closed archive object");
+    }
+  }
+}
+
+inline bool G1FullGCMarker::is_empty() {
+  return _oop_stack.is_empty() && _objarray_stack.is_empty();
+}
+
+inline bool G1FullGCMarker::pop_object(oop& oop) {
+  return _oop_stack.pop_overflow(oop) || _oop_stack.pop_local(oop);
+}
+
+inline void G1FullGCMarker::push_objarray(oop obj, size_t index) {
+  ObjArrayTask task(obj, index);
+  assert(task.is_valid(), "bad ObjArrayTask");
+  _objarray_stack.push(task);
+}
+
+inline bool G1FullGCMarker::pop_objarray(ObjArrayTask& arr) {
+  return _objarray_stack.pop_overflow(arr) || _objarray_stack.pop_local(arr);
+}
+
+inline void G1FullGCMarker::follow_array(objArrayOop array) {
+  follow_klass(array->klass());
+  // Don't push empty arrays to avoid unnecessary work.
+  if (array->length() > 0) {
+    push_objarray(array, 0);
+  }
+}
+
+void G1FullGCMarker::follow_array_chunk(objArrayOop array, int index) {
+  const int len = array->length();
+  const int beg_index = index;
+  assert(beg_index < len || len == 0, "index too large");
+
+  const int stride = MIN2(len - beg_index, (int) ObjArrayMarkingStride);
+  const int end_index = beg_index + stride;
+
+  array->oop_iterate_range(mark_closure(), beg_index, end_index);
+
+  if (VerifyDuringGC) {
+    _verify_closure.set_containing_obj(array);
+    NoHeaderExtendedOopClosure no(&_verify_closure);
+    array->oop_iterate_range(&no, beg_index, end_index);
+    if (_verify_closure.failures()) {
+      assert(false, "Failed");
+    }
+  }
+
+  if (end_index < len) {
+    push_objarray(array, end_index); // Push the continuation.
+  }
+}
+
+inline void G1FullGCMarker::follow_object(oop obj) {
+  assert(_bitmap->is_marked(obj), "should be marked");
+  if (obj->is_objArray()) {
+    // Handle object arrays explicitly to allow them to
+    // be split into chunks if needed.
+    follow_array((objArrayOop)obj);
+  } else {
+    obj->oop_iterate(mark_closure());
+    if (VerifyDuringGC) {
+      if (obj->is_instance() && InstanceKlass::cast(obj->klass())->is_reference_instance_klass()) {
+        return;
+      }
+      _verify_closure.set_containing_obj(obj);
+      obj->oop_iterate_no_header(&_verify_closure);
+      if (_verify_closure.failures()) {
+        log_warning(gc, verify)("Failed after %d", _verify_closure._cc);
+        assert(false, "Failed");
+      }
+    }
+  }
+}
+
+void G1FullGCMarker::drain_stack() {
+  do {
+    oop obj;
+    while (pop_object(obj)) {
+      assert(_bitmap->is_marked(obj), "must be marked");
+      follow_object(obj);
+    }
+    // Process ObjArrays one at a time to avoid marking stack bloat.
+    ObjArrayTask task;
+    if (pop_objarray(task)) {
+      follow_array_chunk(objArrayOop(task.obj()), task.index());
+    }
+  } while (!is_empty());
+}
+
+inline void G1FullGCMarker::follow_klass(Klass* k) {
+  oop op = k->klass_holder();
+  mark_and_push(&op);
+}
+
+inline void G1FullGCMarker::follow_cld(ClassLoaderData* cld) {
+  _cld_closure.do_cld(cld);
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCOopClosures.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,151 @@
+/*
+ * 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/g1/g1CollectedHeap.hpp"
+#include "gc/g1/g1FullGCMarker.inline.hpp"
+#include "gc/g1/g1FullGCOopClosures.inline.hpp"
+#include "gc/g1/g1_specialized_oop_closures.hpp"
+#include "logging/logStream.hpp"
+
+void G1MarkAndPushClosure::do_oop(oop* p) {
+  do_oop_nv(p);
+}
+
+void G1MarkAndPushClosure::do_oop(narrowOop* p) {
+  do_oop_nv(p);
+}
+
+bool G1MarkAndPushClosure::do_metadata() {
+  return do_metadata_nv();
+}
+
+void G1MarkAndPushClosure::do_klass(Klass* k) {
+  do_klass_nv(k);
+}
+
+void G1MarkAndPushClosure::do_cld(ClassLoaderData* cld) {
+  do_cld_nv(cld);
+}
+
+G1AdjustAndRebuildClosure::G1AdjustAndRebuildClosure(uint worker_id) :
+  _worker_id(worker_id),
+  _compaction_delta(0),
+  _g1h(G1CollectedHeap::heap()) { }
+
+void G1AdjustAndRebuildClosure::update_compaction_delta(oop obj) {
+  if (G1ArchiveAllocator::is_open_archive_object(obj)) {
+    _compaction_delta = 0;
+    return;
+  }
+  oop forwardee = obj->forwardee();
+  if (forwardee == NULL) {
+    // Object not moved.
+    _compaction_delta = 0;
+  } else {
+    // Object moved to forwardee, calculate delta.
+    _compaction_delta = calculate_compaction_delta(obj, forwardee);
+  }
+}
+
+void G1AdjustClosure::do_oop(oop* p)       { adjust_pointer(p); }
+void G1AdjustClosure::do_oop(narrowOop* p) { adjust_pointer(p); }
+
+void G1AdjustAndRebuildClosure::do_oop(oop* p)       { do_oop_nv(p); }
+void G1AdjustAndRebuildClosure::do_oop(narrowOop* p) { do_oop_nv(p); }
+
+void G1FollowStackClosure::do_void() { _marker->drain_stack(); }
+
+void G1FullKeepAliveClosure::do_oop(oop* p) { do_oop_work(p); }
+void G1FullKeepAliveClosure::do_oop(narrowOop* p) { do_oop_work(p); }
+
+G1VerifyOopClosure::G1VerifyOopClosure(VerifyOption option) :
+   _g1h(G1CollectedHeap::heap()),
+   _containing_obj(NULL),
+   _verify_option(option),
+   _cc(0),
+   _failures(false) {
+}
+
+void G1VerifyOopClosure::print_object(outputStream* out, oop obj) {
+#ifdef PRODUCT
+  Klass* k = obj->klass();
+  const char* class_name = InstanceKlass::cast(k)->external_name();
+  out->print_cr("class name %s", class_name);
+#else // PRODUCT
+  obj->print_on(out);
+#endif // PRODUCT
+}
+
+template <class T> void G1VerifyOopClosure::do_oop_nv(T* p) {
+  T heap_oop = oopDesc::load_heap_oop(p);
+  if (!oopDesc::is_null(heap_oop)) {
+    _cc++;
+    oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
+    bool failed = false;
+    if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _verify_option)) {
+      MutexLockerEx x(ParGCRareEvent_lock,
+          Mutex::_no_safepoint_check_flag);
+      LogStreamHandle(Error, gc, verify) yy;
+      if (!_failures) {
+        yy.cr();
+        yy.print_cr("----------");
+      }
+      if (!_g1h->is_in_closed_subset(obj)) {
+        HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
+        yy.print_cr("Field " PTR_FORMAT
+            " of live obj " PTR_FORMAT " in region "
+            "[" PTR_FORMAT ", " PTR_FORMAT ")",
+            p2i(p), p2i(_containing_obj),
+            p2i(from->bottom()), p2i(from->end()));
+        print_object(&yy, _containing_obj);
+        yy.print_cr("points to obj " PTR_FORMAT " not in the heap",
+            p2i(obj));
+      } else {
+        HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
+        HeapRegion* to   = _g1h->heap_region_containing((HeapWord*)obj);
+        yy.print_cr("Field " PTR_FORMAT
+            " of live obj " PTR_FORMAT " in region "
+            "[" PTR_FORMAT ", " PTR_FORMAT ")",
+            p2i(p), p2i(_containing_obj),
+            p2i(from->bottom()), p2i(from->end()));
+        print_object(&yy, _containing_obj);
+        yy.print_cr("points to dead obj " PTR_FORMAT " in region "
+            "[" PTR_FORMAT ", " PTR_FORMAT ")",
+            p2i(obj), p2i(to->bottom()), p2i(to->end()));
+        print_object(&yy, obj);
+      }
+      yy.print_cr("----------");
+      yy.flush();
+      _failures = true;
+      failed = true;
+    }
+  }
+}
+
+template void G1VerifyOopClosure::do_oop_nv(oop*);
+template void G1VerifyOopClosure::do_oop_nv(narrowOop*);
+
+// Generate G1 full GC specialized oop_oop_iterate functions.
+SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_G1FULL(ALL_KLASS_OOP_OOP_ITERATE_DEFN)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCOopClosures.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,151 @@
+/*
+ * 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_GC_G1_G1FULLGCOOPCLOSURES_HPP
+#define SHARE_GC_G1_G1FULLGCOOPCLOSURES_HPP
+
+#include "memory/iterator.hpp"
+#include "memory/universe.hpp"
+
+class G1CollectedHeap;
+class G1FullCollector;
+class G1CMBitMap;
+class G1FullGCMarker;
+
+// Below are closures used by the G1 Full GC.
+class G1IsAliveClosure : public BoolObjectClosure {
+  G1CMBitMap* _bitmap;
+
+public:
+  G1IsAliveClosure(G1CMBitMap* bitmap) : _bitmap(bitmap) { }
+
+  virtual bool do_object_b(oop p);
+};
+
+class G1FullKeepAliveClosure: public OopClosure {
+  G1FullGCMarker* _marker;
+  template <class T>
+  inline void do_oop_work(T* p);
+
+public:
+  G1FullKeepAliveClosure(G1FullGCMarker* pm) : _marker(pm) { }
+
+  virtual void do_oop(oop* p);
+  virtual void do_oop(narrowOop* p);
+};
+
+class G1MarkAndPushClosure : public ExtendedOopClosure {
+  G1FullGCMarker* _marker;
+  uint _worker_id;
+
+public:
+  G1MarkAndPushClosure(uint worker, G1FullGCMarker* marker, ReferenceProcessor* ref) :
+    _marker(marker),
+    _worker_id(worker),
+    ExtendedOopClosure(ref) { }
+
+  template <class T> inline void do_oop_nv(T* p);
+  virtual void do_oop(oop* p);
+  virtual void do_oop(narrowOop* p);
+
+  virtual bool do_metadata();
+  bool do_metadata_nv();
+
+  virtual void do_klass(Klass* k);
+  void do_klass_nv(Klass* k);
+
+  virtual void do_cld(ClassLoaderData* cld);
+  void do_cld_nv(ClassLoaderData* cld);
+};
+
+class G1AdjustClosure : public OopClosure {
+public:
+  template <class T> static inline oop adjust_pointer(T* p);
+  virtual void do_oop(oop* p);
+  virtual void do_oop(narrowOop* p);
+};
+
+class G1AdjustAndRebuildClosure : public ExtendedOopClosure {
+  uint _worker_id;
+  size_t _compaction_delta;
+  G1CollectedHeap* _g1h;
+
+  inline size_t calculate_compaction_delta(oop current, oop forwardee);
+  template <class T> inline T* add_compaction_delta(T* p);
+
+public:
+  G1AdjustAndRebuildClosure(uint worker_id);
+
+  void update_compaction_delta(oop obj);
+
+  template <class T> inline void add_reference(T* from_field, oop reference, uint worker_id);
+  template <class T> void do_oop_nv(T* p);
+  virtual void do_oop(oop* p);
+  virtual void do_oop(narrowOop* p);
+
+  virtual ReferenceIterationMode reference_iteration_mode() { return DO_FIELDS; }
+};
+
+class G1AdjustObjectClosure {
+  G1AdjustAndRebuildClosure* _closure;
+
+public:
+  G1AdjustObjectClosure(G1AdjustAndRebuildClosure* cl) : _closure(cl) { }
+
+  inline int adjust_object(oop obj);
+};
+
+class G1VerifyOopClosure: public OopClosure {
+private:
+  G1CollectedHeap* _g1h;
+  bool             _failures;
+  oop              _containing_obj;
+  VerifyOption     _verify_option;
+
+public:
+  int _cc;
+  G1VerifyOopClosure(VerifyOption option);
+
+  void set_containing_obj(oop obj) {
+    _containing_obj = obj;
+  }
+
+  bool failures() { return _failures; }
+  void print_object(outputStream* out, oop obj);
+
+  template <class T> void do_oop_nv(T* p);
+
+  void do_oop(oop* p)       { do_oop_nv(p); }
+  void do_oop(narrowOop* p) { do_oop_nv(p); }
+};
+
+class G1FollowStackClosure: public VoidClosure {
+  G1FullGCMarker* _marker;
+
+public:
+  G1FollowStackClosure(G1FullGCMarker* marker) : _marker(marker) {}
+  virtual void do_void();
+};
+
+#endif // SHARE_GC_G1_G1FULLGCOOPCLOSURES_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCOopClosures.inline.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,128 @@
+/*
+ * 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_G1_G1FULLGCOOPCLOSURES_INLINE_HPP
+#define SHARE_VM_GC_G1_G1FULLGCOOPCLOSURES_INLINE_HPP
+
+#include "gc/g1/g1Allocator.hpp"
+#include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
+#include "gc/g1/g1FullGCMarker.inline.hpp"
+#include "gc/g1/g1FullGCOopClosures.hpp"
+#include "gc/g1/heapRegionRemSet.hpp"
+#include "memory/iterator.inline.hpp"
+
+template <typename T>
+inline void G1MarkAndPushClosure::do_oop_nv(T* p) {
+  _marker->mark_and_push(p);
+}
+
+inline bool G1MarkAndPushClosure::do_metadata_nv() {
+  return true;
+}
+
+inline void G1MarkAndPushClosure::do_klass_nv(Klass* k) {
+  _marker->follow_klass(k);
+}
+
+inline void G1MarkAndPushClosure::do_cld_nv(ClassLoaderData* cld) {
+  _marker->follow_cld(cld);
+}
+
+template <class T> inline oop G1AdjustClosure::adjust_pointer(T* p) {
+  T heap_oop = oopDesc::load_heap_oop(p);
+  if (oopDesc::is_null(heap_oop)) {
+    // NULL reference, return NULL.
+    return NULL;
+  }
+
+  oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
+  assert(Universe::heap()->is_in(obj), "should be in heap");
+  if (G1ArchiveAllocator::is_archive_object(obj)) {
+    // Never forwarding archive objects, return current reference.
+    return obj;
+  }
+
+  oop forwardee = obj->forwardee();
+  if (forwardee == NULL) {
+    // Not forwarded, return current reference.
+    assert(obj->mark() == markOopDesc::prototype_for_object(obj) || // Correct mark
+           obj->mark()->must_be_preserved(obj) || // Will be restored by PreservedMarksSet
+           (UseBiasedLocking && obj->has_bias_pattern()), // Will be restored by BiasedLocking
+           "Must have correct prototype or be preserved, obj: " PTR_FORMAT ", mark: " PTR_FORMAT ", prototype: " PTR_FORMAT,
+           p2i(obj), p2i(obj->mark()), p2i(markOopDesc::prototype_for_object(obj)));
+    return obj;
+  }
+
+  // Forwarded, update and return new reference.
+  assert(Universe::heap()->is_in_reserved(forwardee), "should be in object space");
+  oopDesc::encode_store_heap_oop_not_null(p, forwardee);
+  return forwardee;
+}
+
+template <class T>
+inline void G1AdjustAndRebuildClosure::add_reference(T* from_field, oop reference, uint worker_id) {
+  if (HeapRegion::is_in_same_region(from_field, reference)) {
+    return;
+  }
+  _g1h->heap_region_containing(reference)->rem_set()->add_reference(from_field, worker_id);
+}
+
+inline size_t G1AdjustAndRebuildClosure::calculate_compaction_delta(oop current, oop forwardee) {
+  return pointer_delta((HeapWord*)forwardee, (HeapWord*)current);
+}
+
+template <class T>
+inline T* G1AdjustAndRebuildClosure::add_compaction_delta(T* p) {
+  return (T*)((HeapWord*)p + _compaction_delta);
+}
+
+template<typename T>
+void G1AdjustAndRebuildClosure::do_oop_nv(T* p) {
+  oop new_reference = G1AdjustClosure::adjust_pointer(p);
+  if (new_reference == NULL) {
+    return;
+  }
+
+  // Update p using the calculated compaction delta to
+  // get the new field address.
+  T* new_field = add_compaction_delta(p);
+  // Update the remembered set.
+  add_reference(new_field, new_reference, _worker_id);
+}
+
+inline int G1AdjustObjectClosure::adjust_object(oop obj) {
+  _closure->update_compaction_delta(obj);
+  return obj->oop_iterate_size(_closure);
+}
+
+inline bool G1IsAliveClosure::do_object_b(oop p) {
+  return _bitmap->is_marked(p) || G1ArchiveAllocator::is_closed_archive_object(p);
+}
+
+template<typename T>
+inline void G1FullKeepAliveClosure::do_oop_work(T* p) {
+  _marker->mark_and_push(p);
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCPrepareTask.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,220 @@
+/*
+ * 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/g1/g1CollectedHeap.hpp"
+#include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
+#include "gc/g1/g1FullCollector.hpp"
+#include "gc/g1/g1FullGCCompactionPoint.hpp"
+#include "gc/g1/g1FullGCMarker.hpp"
+#include "gc/g1/g1FullGCOopClosures.inline.hpp"
+#include "gc/g1/g1FullGCPrepareTask.hpp"
+#include "gc/g1/g1HotCardCache.hpp"
+#include "gc/g1/heapRegion.inline.hpp"
+#include "gc/shared/gcTraceTime.inline.hpp"
+#include "gc/shared/referenceProcessor.hpp"
+#include "logging/log.hpp"
+#include "utilities/ticks.inline.hpp"
+
+bool G1FullGCPrepareTask::G1CalculatePointersClosure::doHeapRegion(HeapRegion* hr) {
+  if (hr->is_humongous()) {
+    oop obj = oop(hr->humongous_start_region()->bottom());
+    if (_bitmap->is_marked(obj)) {
+      if (hr->is_starts_humongous()) {
+        obj->forward_to(obj);
+      }
+    } else {
+      free_humongous_region(hr);
+    }
+  } else if (!hr->is_pinned()) {
+    prepare_for_compaction(hr);
+  }
+
+  // Reset data structures not valid after Full GC.
+  reset_region_metadata(hr);
+
+  return false;
+}
+
+G1FullGCPrepareTask::G1FullGCPrepareTask(G1FullCollector* collector) :
+    G1FullGCTask("G1 Prepare Compact Task", collector),
+    _hrclaimer(collector->workers()),
+    _freed_regions(false) {
+}
+
+void G1FullGCPrepareTask::set_freed_regions() {
+  if (!_freed_regions) {
+    _freed_regions = true;
+  }
+}
+
+bool G1FullGCPrepareTask::has_freed_regions() {
+  return _freed_regions;
+}
+
+void G1FullGCPrepareTask::work(uint worker_id) {
+  Ticks start = Ticks::now();
+  G1FullGCCompactionPoint* compaction_point = collector()->compaction_point(worker_id);
+  G1CalculatePointersClosure closure(collector()->mark_bitmap(), compaction_point);
+  G1CollectedHeap::heap()->heap_region_par_iterate_from_start(&closure, &_hrclaimer);
+
+  // Update humongous region sets
+  closure.update_sets();
+  compaction_point->update();
+
+  // Check if any regions was freed by this worker and store in task.
+  if (closure.freed_regions()) {
+    set_freed_regions();
+  }
+  log_task("Prepare compaction task", worker_id, start);
+}
+
+G1FullGCPrepareTask::G1CalculatePointersClosure::G1CalculatePointersClosure(G1CMBitMap* bitmap,
+                                                                            G1FullGCCompactionPoint* cp) :
+    _g1h(G1CollectedHeap::heap()),
+    _bitmap(bitmap),
+    _cp(cp),
+    _humongous_regions_removed(0) { }
+
+void G1FullGCPrepareTask::G1CalculatePointersClosure::free_humongous_region(HeapRegion* hr) {
+  FreeRegionList dummy_free_list("Dummy Free List for G1MarkSweep");
+
+  hr->set_containing_set(NULL);
+  _humongous_regions_removed++;
+
+  _g1h->free_humongous_region(hr, &dummy_free_list, false /* skip_remset */);
+  prepare_for_compaction(hr);
+  dummy_free_list.remove_all();
+}
+
+void G1FullGCPrepareTask::G1CalculatePointersClosure::reset_region_metadata(HeapRegion* hr) {
+  hr->reset_gc_time_stamp();
+  hr->rem_set()->clear();
+
+  _g1h->g1_barrier_set()->clear(MemRegion(hr->bottom(), hr->end()));
+
+  if (_g1h->g1_hot_card_cache()->use_cache()) {
+    _g1h->g1_hot_card_cache()->reset_card_counts(hr);
+  }
+}
+
+G1FullGCPrepareTask::G1PrepareCompactLiveClosure::G1PrepareCompactLiveClosure(G1FullGCCompactionPoint* cp) :
+    _cp(cp) { }
+
+size_t G1FullGCPrepareTask::G1PrepareCompactLiveClosure::apply(oop object) {
+  size_t size = object->size();
+  _cp->forward(object, size);
+  return size;
+}
+
+size_t G1FullGCPrepareTask::G1RePrepareClosure::apply(oop obj) {
+  // We only re-prepare objects forwarded within the current region, so
+  // skip objects that are already forwarded to another region.
+  oop forwarded_to = obj->forwardee();
+  if (forwarded_to != NULL && !_current->is_in(forwarded_to)) {
+    return obj->size();
+  }
+
+  // Get size and forward.
+  size_t size = obj->size();
+  _cp->forward(obj, size);
+
+  return size;
+}
+
+void G1FullGCPrepareTask::G1CalculatePointersClosure::prepare_for_compaction_work(G1FullGCCompactionPoint* cp,
+                                                                                  HeapRegion* hr) {
+  G1PrepareCompactLiveClosure prepare_compact(cp);
+  hr->set_compaction_top(hr->bottom());
+  hr->apply_to_marked_objects(_bitmap, &prepare_compact);
+}
+
+void G1FullGCPrepareTask::G1CalculatePointersClosure::prepare_for_compaction(HeapRegion* hr) {
+  if (!_cp->is_initialized()) {
+    hr->set_compaction_top(hr->bottom());
+    _cp->initialize(hr, true);
+  }
+  // Add region to the compaction queue and prepare it.
+  _cp->add(hr);
+  prepare_for_compaction_work(_cp, hr);
+}
+
+void G1FullGCPrepareTask::prepare_serial_compaction() {
+  GCTraceTime(Debug, gc, phases) debug("Phase 2: Prepare Serial Compaction", collector()->scope()->timer());
+  // At this point we know that no regions were completely freed by
+  // the parallel compaction. That means that the last region of
+  // all compaction queues still have data in them. We try to compact
+  // these regions in serial to avoid a premature OOM.
+  for (uint i = 0; i < collector()->workers(); i++) {
+    G1FullGCCompactionPoint* cp = collector()->compaction_point(i);
+    if (cp->has_regions()) {
+      collector()->serial_compaction_point()->add(cp->remove_last());
+    }
+  }
+
+  // Update the forwarding information for the regions in the serial
+  // compaction point.
+  G1FullGCCompactionPoint* cp = collector()->serial_compaction_point();
+  for (GrowableArrayIterator<HeapRegion*> it = cp->regions()->begin(); it != cp->regions()->end(); ++it) {
+    HeapRegion* current = *it;
+    if (!cp->is_initialized()) {
+      // Initialize the compaction point. Nothing more is needed for the first heap region
+      // since it is already prepared for compaction.
+      cp->initialize(current, false);
+    } else {
+      assert(!current->is_humongous(), "Should be no humongous regions in compaction queue");
+      G1RePrepareClosure re_prepare(cp, current);
+      current->set_compaction_top(current->bottom());
+      current->apply_to_marked_objects(collector()->mark_bitmap(), &re_prepare);
+    }
+  }
+  cp->update();
+}
+
+void G1FullGCPrepareTask::G1CalculatePointersClosure::update_sets() {
+  // We'll recalculate total used bytes and recreate the free list
+  // at the end of the GC, so no point in updating those values here.
+  _g1h->remove_from_old_sets(0, _humongous_regions_removed);
+}
+
+bool G1FullGCPrepareTask::G1CalculatePointersClosure::freed_regions() {
+  if (_humongous_regions_removed > 0) {
+    // Free regions from dead humongous regions.
+    return true;
+  }
+
+  if (!_cp->has_regions()) {
+    // No regions in queue, so no free ones either.
+    return false;
+  }
+
+  if (_cp->current_region() != _cp->regions()->last()) {
+    // The current region used for compaction is not the last in the
+    // queue. That means there is at least one free region in the queue.
+    return true;
+  }
+
+  // No free regions in the queue.
+  return false;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCPrepareTask.hpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,96 @@
+/*
+ * 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_GC_G1_G1FULLGCPREPARETASK_HPP
+#define SHARE_GC_G1_G1FULLGCPREPARETASK_HPP
+
+#include "gc/g1/g1FullGCCompactionPoint.hpp"
+#include "gc/g1/g1FullGCScope.hpp"
+#include "gc/g1/g1FullGCTask.hpp"
+#include "gc/g1/g1RootProcessor.hpp"
+#include "gc/g1/g1StringDedup.hpp"
+#include "gc/g1/heapRegionManager.hpp"
+#include "gc/shared/referenceProcessor.hpp"
+#include "utilities/ticks.hpp"
+
+class G1CMBitMap;
+
+class G1FullGCPrepareTask : public G1FullGCTask {
+protected:
+  volatile bool     _freed_regions;
+  HeapRegionClaimer _hrclaimer;
+
+  void set_freed_regions();
+
+public:
+  G1FullGCPrepareTask(G1FullCollector* collector);
+  void work(uint worker_id);
+  void prepare_serial_compaction();
+  bool has_freed_regions();
+
+protected:
+  class G1CalculatePointersClosure : public HeapRegionClosure {
+  protected:
+    G1CollectedHeap* _g1h;
+    G1CMBitMap* _bitmap;
+    G1FullGCCompactionPoint* _cp;
+    uint _humongous_regions_removed;
+
+    virtual void prepare_for_compaction(HeapRegion* hr);
+    void prepare_for_compaction_work(G1FullGCCompactionPoint* cp, HeapRegion* hr);
+    void free_humongous_region(HeapRegion* hr);
+    void reset_region_metadata(HeapRegion* hr);
+
+  public:
+    G1CalculatePointersClosure(G1CMBitMap* bitmap,
+                               G1FullGCCompactionPoint* cp);
+
+    void update_sets();
+    bool doHeapRegion(HeapRegion* hr);
+    bool freed_regions();
+  };
+
+  class G1PrepareCompactLiveClosure : public StackObj {
+    G1FullGCCompactionPoint* _cp;
+
+  public:
+    G1PrepareCompactLiveClosure(G1FullGCCompactionPoint* cp);
+    size_t apply(oop object);
+  };
+
+  class G1RePrepareClosure : public StackObj {
+    G1FullGCCompactionPoint* _cp;
+    HeapRegion* _current;
+
+  public:
+    G1RePrepareClosure(G1FullGCCompactionPoint* hrcp,
+                       HeapRegion* hr) :
+        _cp(hrcp),
+        _current(hr) { }
+
+    size_t apply(oop object);
+  };
+};
+
+#endif // SHARE_GC_G1_G1FULLGCPREPARETASK_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1FullGCReferenceProcessorExecutor.cpp	Mon Nov 27 10:35:05 2017 -0800
@@ -0,0 +1,115 @@
+/*
+ * 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/g1/g1CollectedHeap.hpp"
+#include "gc/g1/g1FullCollector.hpp"
+#include "gc/g1/g1FullGCMarker.hpp"
+#include "gc/g1/g1FullGCOopClosures.inline.hpp"
+#include "gc/g1/g1FullGCReferenceProcessorExecutor.hpp"
+#include "gc/shared/gcTraceTime.inline.hpp"
+#include "gc/shared/referenceProcessor.hpp"
+
+G1FullGCReferenceProcessingExecutor::G1FullGCReferenceProcessingExecutor(G1FullCollector* collector) :
+    _collector(collector),
+    _reference_processor(collector->reference_processor()),
+    _old_mt_degree(_reference_processor->num_q()) {
+  if (_reference_processor->processing_is_mt()) {
+    _reference_processor->set_active_mt_degree(_collector->workers());
+  }
+}
+
+G1FullGCReferenceProcessingExecutor::~G1FullGCReferenceProcessingExecutor() {
+  if (_reference_processor->processing_is_mt()) {
+    _reference_processor->set_active_mt_degree(_old_mt_degree);
+  }
+}
+
+G1FullGCReferenceProcessingExecutor::G1RefProcTaskProxy::G1RefProcTaskProxy(ProcessTask& proc_task,
+                                                                      G1FullCollector* collector) :
+     AbstractGangTask("G1 reference processing task"),
+     _proc_task(proc_task),
+     _collector(collector),
+     _terminator(_collector->workers(), _collector->oop_queue_set()) { }
+
+void G1FullGCReferenceProcessingExecutor::G1RefProcTaskProxy::work(uint worker_id) {
+  G1FullGCMarker* marker = _collector->marker(worker_id);
+  G1IsAliveClosure is_alive(_collector->mark_bitmap());
+  G1FullKeepAliveClosure keep_alive(marker);
+  _proc_task.work(worker_id,
+                  is_alive,
+                  keep_alive,
+                  *marker->stack_closure());
+}
+
+G1FullGCReferenceProcessingExecutor::G1RefEnqueueTaskProxy::G1RefEnqueueTaskProxy(EnqueueTask& enq_task) :
+  AbstractGangTask("G1 reference enqueue task"),
+  _enq_task(enq_task) { }
+
+void G1FullGCReferenceProcessingExecutor::G1RefEnqueueTaskProxy::work(uint worker_id) {
+  _enq_task.work(worker_id);
+}
+
+void G1FullGCReferenceProcessingExecutor::run_task(AbstractGangTask* task) {
+  G1CollectedHeap::heap()->workers()->run_task(task, _collector->workers());
+}
+
+void G1FullGCReferenceProcessingExecutor::execute(ProcessTask& proc_task) {
+  G1RefProcTaskProxy proc_task_proxy(proc_task, _collector);
+  run_task(&proc_task_proxy);
+}
+
+// Driver routine for parallel reference processing.
+void G1FullGCReferenceProcessingExecutor::execute(EnqueueTask& enq_task) {
+  G1RefEnqueueTaskProxy enq_task_proxy(enq_task);
+  run_task(&enq_task_proxy);
+}
+
+void G1FullGCReferenceProcessingExecutor::execute(STWGCTimer* timer, G1FullGCTracer* tracer) {
+  GCTraceTime(Debug, gc, phases) debug("Phase 1: Reference Processing", timer);
+  // Process reference objects found during marking.
+  G1FullGCMarker* marker = _collector->marker(0);
+  G1IsAliveClosure is_alive(_collector->mark_bitmap());
+  G1FullKeepAliveClosure keep_alive(marker);
+  ReferenceProcessorPhaseTimes pt(timer, _reference_processor->num_q());
+  AbstractRefProcTaskExecutor* executor = _reference_processor->processing_is_mt() ? this : NULL;
+
+  // Process discovered references, use this executor if multi-threaded
+  // processing is enabled.
+  const ReferenceProcessorStats& stats =
+      _reference_processor->process_discovered_references(&is_alive,