changeset 47824:cf127be65014

Merge
author jwilhelm
date Sat, 11 Nov 2017 01:21:09 +0100
parents ce6ff74192fc 9c77ebad8c3a
children 13e39ca700d0 0ce0ac68ace7 352b17f62ff7
files make/autoconf/spec.gmk.in make/conf/jib-profiles.js src/hotspot/.mx.jvmci/.project src/hotspot/.mx.jvmci/.pydevproject src/hotspot/cpu/aarch64/jni_aarch64.h src/hotspot/cpu/arm/jni_arm.h src/hotspot/cpu/ppc/jni_ppc.h src/hotspot/cpu/s390/jni_s390.h src/hotspot/cpu/sparc/jni_sparc.h src/hotspot/cpu/x86/jni_x86.h src/hotspot/cpu/zero/jni_zero.h src/hotspot/os/aix/jvm_aix.h src/hotspot/os/bsd/jvm_bsd.h src/hotspot/os/linux/jvm_linux.h src/hotspot/os/solaris/jvm_solaris.h src/hotspot/os/windows/jvm_windows.h src/hotspot/share/gc/g1/concurrentG1Refine.cpp src/hotspot/share/gc/g1/concurrentG1Refine.hpp src/hotspot/share/gc/g1/concurrentG1RefineThread.cpp src/hotspot/share/gc/g1/concurrentG1RefineThread.hpp src/hotspot/share/interpreter/linkResolver.cpp src/hotspot/share/prims/jni_md.h src/hotspot/share/prims/jvm.h src/java.base/macosx/native/include/jni_md.h src/java.base/macosx/native/include/jvm_md.h src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/JNIid.java src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.code/overview.html src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.meta/overview.html src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/arraycopy/ArrayCopySlowPathNode.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/arraycopy/ArrayCopyUnrollNode.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/arraycopy/UnsafeArrayCopyNode.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/arraycopy/UnsafeArrayCopySnippets.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/DivNode.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/BasicIdealGraphPrinter.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/IdealGraphPrinter.java test/hotspot/jtreg/applications/ctw/Modules.java test/jdk/ProblemList.txt
diffstat 664 files changed, 13422 insertions(+), 8192 deletions(-) [+]
line wrap: on
line diff
--- a/make/CompileToolsHotspot.gmk	Wed Nov 08 13:38:00 2017 -0800
+++ b/make/CompileToolsHotspot.gmk	Sat Nov 11 01:21:09 2017 +0100
@@ -67,6 +67,7 @@
           $(SRC_DIR)/org.graalvm.compiler.phases.common/src \
           $(SRC_DIR)/org.graalvm.compiler.serviceprovider/src \
           $(SRC_DIR)/org.graalvm.compiler.virtual/src \
+          $(SRC_DIR)/org.graalvm.graphio/src \
           $(SRC_DIR)/org.graalvm.util/src \
           $(VM_CI_SRC_DIR)/jdk.vm.ci.code/src \
           $(VM_CI_SRC_DIR)/jdk.vm.ci.common/src \
@@ -125,6 +126,7 @@
           $(SRC_DIR)/org.graalvm.compiler.nodeinfo/src \
           $(SRC_DIR)/org.graalvm.compiler.options/src \
           $(SRC_DIR)/org.graalvm.compiler.serviceprovider/src \
+          $(SRC_DIR)/org.graalvm.graphio/src \
           $(SRC_DIR)/org.graalvm.util/src \
           $(VM_CI_SRC_DIR)/jdk.vm.ci.code/src \
           $(VM_CI_SRC_DIR)/jdk.vm.ci.common/src \
--- a/make/conf/jib-profiles.js	Wed Nov 08 13:38:00 2017 -0800
+++ b/make/conf/jib-profiles.js	Sat Nov 11 01:21:09 2017 +0100
@@ -824,7 +824,7 @@
         jtreg: {
             server: "javare",
             revision: "4.2",
-            build_number: "b09",
+            build_number: "b10",
             checksum_file: "MD5_VALUES",
             file: "jtreg_bin-4.2.zip",
             environment_name: "JT_HOME",
--- a/make/copy/Copy-java.base.gmk	Wed Nov 08 13:38:00 2017 -0800
+++ b/make/copy/Copy-java.base.gmk	Sat Nov 11 01:21:09 2017 +0100
@@ -42,7 +42,7 @@
 	$(call install-file)
 
 $(INCLUDE_DST_OS_DIR)/%.h: \
-    $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_EXPORT_DIR)/native/include/%.h
+    $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/include/%.h
 	$(call install-file)
 
 ################################################################################
--- a/make/hotspot/lib/CompileJvm.gmk	Wed Nov 08 13:38:00 2017 -0800
+++ b/make/hotspot/lib/CompileJvm.gmk	Sat Nov 11 01:21:09 2017 +0100
@@ -57,8 +57,8 @@
     $(patsubst %,-I%,$(filter-out $(JVM_VARIANT_OUTPUTDIR)/gensrc/%, $(JVM_SRC_DIRS))) \
     -I$(JVM_VARIANT_OUTPUTDIR)/gensrc \
     -I$(TOPDIR)/src/hotspot/share/precompiled \
-    -I$(TOPDIR)/src/hotspot/share/prims \
     -I$(TOPDIR)/src/java.base/share/native/include \
+    -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/include \
     #
 
 # INCLUDE_SUFFIX_* is only meant for including the proper
--- a/make/hotspot/lib/CompileLibjsig.gmk	Wed Nov 08 13:38:00 2017 -0800
+++ b/make/hotspot/lib/CompileLibjsig.gmk	Sat Nov 11 01:21:09 2017 +0100
@@ -57,7 +57,7 @@
       endif
 
     else ifeq ($(OPENJDK_TARGET_OS), solaris)
-      LIBJSIG_CFLAGS := -m64 -KPIC -mt -I $(TOPDIR)/src/hotspot/os/solaris
+      LIBJSIG_CFLAGS := -m64 -KPIC -mt -I $(TOPDIR)/src/java.base/unix/native/include
       LIBJSIG_LDFLAGS := -m64 -mt -xnolib
       LIBJSIG_LIBS := $(LIBDL)
 
--- a/make/mapfiles/libinstrument/mapfile-vers	Wed Nov 08 13:38:00 2017 -0800
+++ b/make/mapfiles/libinstrument/mapfile-vers	Sat Nov 11 01:21:09 2017 +0100
@@ -31,6 +31,7 @@
 	    Agent_OnAttach;
             Java_sun_instrument_InstrumentationImpl_isModifiableClass0;
             Java_sun_instrument_InstrumentationImpl_isRetransformClassesSupported0;
+            Java_sun_instrument_InstrumentationImpl_setHasTransformers;
             Java_sun_instrument_InstrumentationImpl_setHasRetransformableTransformers;
             Java_sun_instrument_InstrumentationImpl_retransformClasses0;
             Java_sun_instrument_InstrumentationImpl_getAllLoadedClasses0;
--- a/make/test/JtregNativeHotspot.gmk	Wed Nov 08 13:38:00 2017 -0800
+++ b/make/test/JtregNativeHotspot.gmk	Sat Nov 11 01:21:09 2017 +0100
@@ -63,6 +63,8 @@
     $(TOPDIR)/test/hotspot/jtreg/runtime/RedefineTests \
     $(TOPDIR)/test/hotspot/jtreg/compiler/floatingpoint/ \
     $(TOPDIR)/test/hotspot/jtreg/compiler/calls \
+    $(TOPDIR)/test/hotspot/jtreg/compiler/runtime/criticalnatives/lookup \
+    $(TOPDIR)/test/hotspot/jtreg/compiler/runtime/criticalnatives/argumentcorruption \
     $(TOPDIR)/test/hotspot/jtreg/serviceability/jvmti/GetOwnedMonitorInfo \
     $(TOPDIR)/test/hotspot/jtreg/serviceability/jvmti/GetNamedModule \
     $(TOPDIR)/test/hotspot/jtreg/serviceability/jvmti/IsModifiableModule \
--- a/src/hotspot/.mx.jvmci/.project	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>mx.jvmci</name>
-	<comment></comment>
-	<projects>
-		<project>mx</project>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.python.pydev.PyDevBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.python.pydev.pythonNature</nature>
-	</natures>
-</projectDescription>
--- a/src/hotspot/.mx.jvmci/.pydevproject	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<?eclipse-pydev version="1.0"?><pydev_project>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
-<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
-<path>/mx.jvmci</path>
-</pydev_pathproperty>
-<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
-<path>/mx</path>
-</pydev_pathproperty>
-
-</pydev_project>
--- a/src/hotspot/.mx.jvmci/mx_jvmci.py	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/.mx.jvmci/mx_jvmci.py	Sat Nov 11 01:21:09 2017 +0100
@@ -42,11 +42,6 @@
 
 JVMCI_VERSION = 9
 
-"""
-Top level directory of the JDK source workspace.
-"""
-_jdkSourceRoot = dirname(_suite.dir)
-
 _JVMCI_JDK_TAG = 'jvmci'
 
 _minVersion = mx.VersionSpec('1.9')
@@ -145,7 +140,7 @@
     return True
 
 def _makehelp():
-    return subprocess.check_output([mx.gmake_cmd(), 'help'], cwd=_jdkSourceRoot)
+    return subprocess.check_output([mx.gmake_cmd(), 'help'], cwd=_get_jdk_dir())
 
 def _runmake(args):
     """run the JDK make process
@@ -155,12 +150,12 @@
 
     jdkBuildDir = _get_jdk_build_dir()
     if not exists(jdkBuildDir):
-        # JDK9 must be bootstrapped with a JDK8
-        compliance = mx.JavaCompliance('8')
-        jdk8 = mx.get_jdk(compliance.exactMatch, versionDescription=compliance.value)
+        # JDK10 must be bootstrapped with a JDK9
+        compliance = mx.JavaCompliance('9')
+        jdk9 = mx.get_jdk(compliance.exactMatch, versionDescription=compliance.value)
         cmd = ['sh', 'configure', '--with-debug-level=' + _vm.debugLevel, '--with-native-debug-symbols=external', '--disable-precompiled-headers', '--with-jvm-features=graal',
-               '--with-jvm-variants=' + _vm.jvmVariant, '--disable-warnings-as-errors', '--with-boot-jdk=' + jdk8.home, '--with-jvm-features=graal']
-        mx.run(cmd, cwd=_jdkSourceRoot)
+               '--with-jvm-variants=' + _vm.jvmVariant, '--disable-warnings-as-errors', '--with-boot-jdk=' + jdk9.home, '--with-jvm-features=graal']
+        mx.run(cmd, cwd=_get_jdk_dir())
     cmd = [mx.gmake_cmd(), 'CONF=' + _vm.debugLevel]
     if mx.get_opts().verbose:
         cmd.append('LOG=debug')
@@ -170,11 +165,11 @@
 
     if not mx.get_opts().verbose:
         mx.log('--------------- make execution ----------------------')
-        mx.log('Working directory: ' + _jdkSourceRoot)
+        mx.log('Working directory: ' + _get_jdk_dir())
         mx.log('Command line: ' + ' '.join(cmd))
         mx.log('-----------------------------------------------------')
 
-    mx.run(cmd, cwd=_jdkSourceRoot)
+    mx.run(cmd, cwd=_get_jdk_dir())
 
 def _runmultimake(args):
     """run the JDK make process for one or more configurations"""
--- a/src/hotspot/cpu/aarch64/assembler_aarch64.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/aarch64/assembler_aarch64.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -1489,6 +1489,17 @@
 
 #undef INSN
 
+  // Aliases for short forms of orn
+void mvn(Register Rd, Register Rm,
+            enum shift_kind kind = LSL, unsigned shift = 0) {
+  orn(Rd, zr, Rm, kind, shift);
+}
+
+void mvnw(Register Rd, Register Rm,
+            enum shift_kind kind = LSL, unsigned shift = 0) {
+  ornw(Rd, zr, Rm, kind, shift);
+}
+
   // Add/subtract (shifted register)
 #define INSN(NAME, size, op)                            \
   void NAME(Register Rd, Register Rn, Register Rm,      \
--- a/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -2657,9 +2657,9 @@
   __ adrp(res, ExternalAddress(StubRoutines::crc_table_addr()), offset);
   if (offset) __ add(res, res, offset);
 
-  __ ornw(crc, zr, crc); // ~crc
+  __ mvnw(crc, crc); // ~crc
   __ update_byte_crc32(crc, val, res);
-  __ ornw(res, zr, crc); // ~crc
+  __ mvnw(res, crc); // ~crc
 }
 
 void LIR_Assembler::emit_profile_type(LIR_OpProfileType* op) {
--- a/src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -1030,7 +1030,81 @@
 }
 
 void LIRGenerator::do_update_CRC32C(Intrinsic* x) {
-  Unimplemented();
+  assert(UseCRC32CIntrinsics, "why are we here?");
+  // Make all state_for calls early since they can emit code
+  LIR_Opr result = rlock_result(x);
+  int flags = 0;
+  switch (x->id()) {
+    case vmIntrinsics::_updateBytesCRC32C:
+    case vmIntrinsics::_updateDirectByteBufferCRC32C: {
+      bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32C);
+      int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
+
+      LIRItem crc(x->argument_at(0), this);
+      LIRItem buf(x->argument_at(1), this);
+      LIRItem off(x->argument_at(2), this);
+      LIRItem end(x->argument_at(3), this);
+
+      buf.load_item();
+      off.load_nonconstant();
+      end.load_nonconstant();
+
+      // len = end - off
+      LIR_Opr len  = end.result();
+      LIR_Opr tmpA = new_register(T_INT);
+      LIR_Opr tmpB = new_register(T_INT);
+      __ move(end.result(), tmpA);
+      __ move(off.result(), tmpB);
+      __ sub(tmpA, tmpB, tmpA);
+      len = tmpA;
+
+      LIR_Opr index = off.result();
+      if(off.result()->is_constant()) {
+        index = LIR_OprFact::illegalOpr;
+        offset += off.result()->as_jint();
+      }
+      LIR_Opr base_op = buf.result();
+
+      if (index->is_valid()) {
+        LIR_Opr tmp = new_register(T_LONG);
+        __ convert(Bytecodes::_i2l, index, tmp);
+        index = tmp;
+      }
+
+      if (offset) {
+        LIR_Opr tmp = new_pointer_register();
+        __ add(base_op, LIR_OprFact::intConst(offset), tmp);
+        base_op = tmp;
+        offset = 0;
+      }
+
+      LIR_Address* a = new LIR_Address(base_op,
+                                       index,
+                                       offset,
+                                       T_BYTE);
+      BasicTypeList signature(3);
+      signature.append(T_INT);
+      signature.append(T_ADDRESS);
+      signature.append(T_INT);
+      CallingConvention* cc = frame_map()->c_calling_convention(&signature);
+      const LIR_Opr result_reg = result_register_for(x->type());
+
+      LIR_Opr addr = new_pointer_register();
+      __ leal(LIR_OprFact::address(a), addr);
+
+      crc.load_item_force(cc->at(0));
+      __ move(addr, cc->at(1));
+      __ move(len, cc->at(2));
+
+      __ call_runtime_leaf(StubRoutines::updateBytesCRC32C(), getThreadTemp(), result_reg, cc->args());
+      __ move(result_reg, result);
+
+      break;
+    }
+    default: {
+      ShouldNotReachHere();
+    }
+  }
 }
 
 void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) {
--- a/src/hotspot/cpu/aarch64/frame_aarch64.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/aarch64/frame_aarch64.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -431,11 +431,11 @@
   // This is the sp before any possible extension (adapter/locals).
   intptr_t* unextended_sp = interpreter_frame_sender_sp();
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   if (map->update_map()) {
     update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
   }
-#endif // COMPILER2 || INCLUDE_JVMCI
+#endif // COMPILER2_OR_JVMCI
 
   return frame(sender_sp, unextended_sp, link(), sender_pc());
 }
--- a/src/hotspot/cpu/aarch64/jni_aarch64.h	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#ifndef _JAVASOFT_JNI_MD_H_
-#define _JAVASOFT_JNI_MD_H_
-
-#if defined(SOLARIS) || defined(LINUX) || defined(_ALLBSD_SOURCE)
-
-
-// Note: please do not change these without also changing jni_md.h in the JDK
-// repository
-#ifndef __has_attribute
-  #define __has_attribute(x) 0
-#endif
-#if (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))) || __has_attribute(visibility)
-  #define JNIEXPORT     __attribute__((visibility("default")))
-  #define JNIIMPORT     __attribute__((visibility("default")))
-#else
-  #define JNIEXPORT
-  #define JNIIMPORT
-#endif
-
-  #define JNICALL
-  typedef int jint;
-  typedef long jlong;
-
-#else
-  #define JNIEXPORT __declspec(dllexport)
-  #define JNIIMPORT __declspec(dllimport)
-  #define JNICALL __stdcall
-
-  typedef int jint;
-  typedef __int64 jlong;
-#endif
-
-typedef signed char jbyte;
-
-#endif /* !_JAVASOFT_JNI_MD_H_ */
--- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/assembler.hpp"
 #include "asm/assembler.inline.hpp"
 #include "interpreter/interpreter.hpp"
@@ -38,7 +39,6 @@
 #include "opto/compile.hpp"
 #include "opto/intrinsicnode.hpp"
 #include "opto/node.hpp"
-#include "prims/jvm.h"
 #include "runtime/biasedLocking.hpp"
 #include "runtime/icache.hpp"
 #include "runtime/interfaceSupport.hpp"
@@ -2929,6 +2929,105 @@
   eor(crc, crc, tmp);
 }
 
+void MacroAssembler::kernel_crc32_using_crc32(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);
+
+    mvnw(crc, crc);
+
+    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);
+    crc32x(crc, crc, tmp0);
+    ldr(tmp2, Address(post(buf, 8)));
+    crc32x(crc, crc, tmp1);
+    ldr(tmp3, Address(post(buf, 8)));
+    crc32x(crc, crc, tmp2);
+    crc32x(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);
+    crc32w(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);
+    crc32b(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));
+    crc32x(crc, crc, tmp0);
+    ldr(tmp2, Address(buf, 24));
+    crc32x(crc, crc, tmp1);
+    ldr(tmp3, Address(buf, 32));
+    crc32x(crc, crc, tmp2);
+    ldr(tmp0, Address(buf, 40));
+    crc32x(crc, crc, tmp3);
+    ldr(tmp1, Address(buf, 48));
+    crc32x(crc, crc, tmp0);
+    ldr(tmp2, Address(buf, 56));
+    crc32x(crc, crc, tmp1);
+    ldr(tmp3, Address(pre(buf, 64)));
+
+    b(CRC_by64_loop);
+
+    align(CodeEntryAlignment);
+  BIND(CRC_by64_loop);
+    subs(len, len, 64);
+    crc32x(crc, crc, tmp2);
+    ldr(tmp0, Address(buf, 8));
+    crc32x(crc, crc, tmp3);
+    ldr(tmp1, Address(buf, 16));
+    crc32x(crc, crc, tmp0);
+    ldr(tmp2, Address(buf, 24));
+    crc32x(crc, crc, tmp1);
+    ldr(tmp3, Address(buf, 32));
+    crc32x(crc, crc, tmp2);
+    ldr(tmp0, Address(buf, 40));
+    crc32x(crc, crc, tmp3);
+    ldr(tmp1, Address(buf, 48));
+    crc32x(crc, crc, tmp0);
+    ldr(tmp2, Address(buf, 56));
+    crc32x(crc, crc, tmp1);
+    ldr(tmp3, Address(pre(buf, 64)));
+    br(Assembler::GE, CRC_by64_loop);
+
+    // post-loop
+    crc32x(crc, crc, tmp2);
+    crc32x(crc, crc, tmp3);
+
+    sub(len, len, 64);
+    add(buf, buf, 8);
+    cmn(len, 128);
+    br(Assembler::NE, CRC_less64);
+  BIND(L_exit);
+    mvnw(crc, crc);
+}
+
 /**
  * @param crc   register containing existing CRC (32-bit)
  * @param buf   register pointing to input byte buffer (byte*)
@@ -2942,58 +3041,13 @@
   Label L_by16, L_by16_loop, L_by4, L_by4_loop, L_by1, L_by1_loop, L_exit;
   unsigned long offset;
 
-    ornw(crc, zr, crc);
-
   if (UseCRC32) {
-    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);
-      crc32w(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);
-      crc32b(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)));
-      crc32x(crc, crc, tmp);
-      crc32x(crc, crc, tmp3);
-      ldp(tmp, tmp3, Address(post(buf, 16)));
-      crc32x(crc, crc, tmp);
-      crc32x(crc, crc, tmp3);
-      ldp(tmp, tmp3, Address(post(buf, 16)));
-      crc32x(crc, crc, tmp);
-      crc32x(crc, crc, tmp3);
-      ldp(tmp, tmp3, Address(post(buf, 16)));
-      crc32x(crc, crc, tmp);
-      crc32x(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);
-      ornw(crc, zr, crc);
+      kernel_crc32_using_crc32(crc, buf, len, table0, table1, table2, table3);
       return;
   }
 
+    mvnw(crc, crc);
+
     adrp(table0, ExternalAddress(StubRoutines::crc_table_addr()), offset);
     if (offset) add(table0, table0, offset);
     add(table1, table0, 1*256*sizeof(juint));
@@ -3171,7 +3225,7 @@
     adds(len, len, 4);
     br(Assembler::GT, L_by1_loop);
   BIND(L_exit);
-    ornw(crc, zr, crc);
+    mvnw(crc, crc);
 }
 
 /**
--- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -1261,6 +1261,9 @@
                                Register yz_idx1, Register yz_idx2,
                                Register tmp, Register tmp3, Register tmp4,
                                Register tmp7, Register product_hi);
+  void kernel_crc32_using_crc32(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/sharedRuntime_aarch64.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -41,7 +41,7 @@
 #ifdef COMPILER1
 #include "c1/c1_Runtime1.hpp"
 #endif
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
 #include "adfiles/ad_aarch64.hpp"
 #include "opto/runtime.hpp"
 #endif
@@ -114,7 +114,7 @@
 };
 
 OopMap* RegisterSaver::save_live_registers(MacroAssembler* masm, int additional_frame_words, int* total_frame_words, bool save_vectors) {
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   if (save_vectors) {
     // Save upper half of vector registers
     int vect_words = 32 * 8 / wordSize;
@@ -2688,7 +2688,7 @@
   return 0;
 }
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
 //------------------------------generate_uncommon_trap_blob--------------------
 void SharedRuntime::generate_uncommon_trap_blob() {
   // Allocate space for the code
@@ -2894,7 +2894,7 @@
   }
 #endif
 }
-#endif // COMPILER2
+#endif // COMPILER2_OR_JVMCI
 
 
 //------------------------------generate_handler_blob------
@@ -3070,8 +3070,7 @@
   return RuntimeStub::new_runtime_stub(name, &buffer, frame_complete, frame_size_in_words, oop_maps, true);
 }
 
-
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
 // This is here instead of runtime_x86_64.cpp because it uses SimpleRuntimeFrame
 //
 //------------------------------generate_exception_blob---------------------------
@@ -3200,4 +3199,4 @@
   // Set exception blob
   _exception_blob =  ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
 }
-#endif // COMPILER2
+#endif // COMPILER2_OR_JVMCI
--- a/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -4937,6 +4937,10 @@
       StubRoutines::_crc_table_adr = (address)StubRoutines::aarch64::_crc_table;
       StubRoutines::_updateBytesCRC32 = generate_updateBytesCRC32();
     }
+
+    if (UseCRC32CIntrinsics) {
+      StubRoutines::_updateBytesCRC32C = generate_updateBytesCRC32C();
+    }
   }
 
   void generate_all() {
@@ -5014,10 +5018,6 @@
       StubRoutines::_sha256_implCompressMB = generate_sha256_implCompress(true,  "sha256_implCompressMB");
     }
 
-    if (UseCRC32CIntrinsics) {
-      StubRoutines::_updateBytesCRC32C = generate_updateBytesCRC32C();
-    }
-
     // generate Adler32 intrinsics code
     if (UseAdler32Intrinsics) {
       StubRoutines::_updateBytesAdler32 = generate_updateBytesAdler32();
--- a/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -472,7 +472,7 @@
 #if INCLUDE_JVMCI
   // Check if we need to take lock at entry of synchronized method.  This can
   // only occur on method entry so emit it only for vtos with step 0.
-  if (UseJVMCICompiler && state == vtos && step == 0) {
+  if (EnableJVMCI && state == vtos && step == 0) {
     Label L;
     __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset()));
     __ cbz(rscratch1, L);
@@ -483,7 +483,7 @@
     __ bind(L);
   } else {
 #ifdef ASSERT
-    if (UseJVMCICompiler) {
+    if (EnableJVMCI) {
       Label L;
       __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset()));
       __ cbz(rscratch1, L);
@@ -984,9 +984,9 @@
     __ adrp(tbl, ExternalAddress(StubRoutines::crc_table_addr()), offset);
     __ add(tbl, tbl, offset);
 
-    __ ornw(crc, zr, crc); // ~crc
+    __ mvnw(crc, crc); // ~crc
     __ update_byte_crc32(crc, val, tbl);
-    __ ornw(crc, zr, crc); // ~crc
+    __ mvnw(crc, crc); // ~crc
 
     // result in c_rarg0
 
@@ -1061,8 +1061,44 @@
   return NULL;
 }
 
-// Not supported
+/**
+ * Method entry for intrinsic-candidate (non-native) methods:
+ *   int java.util.zip.CRC32C.updateBytes(int crc, byte[] b, int off, int end)
+ *   int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long buf, int off, int end)
+ * Unlike CRC32, CRC32C does not have any methods marked as native
+ * CRC32C also uses an "end" variable instead of the length variable CRC32 uses
+ */
 address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
+  if (UseCRC32Intrinsics) {
+    address entry = __ pc();
+
+    // Prepare jump to stub using parameters from the stack
+    const Register crc = c_rarg0; // initial crc
+    const Register buf = c_rarg1; // source java byte array address
+    const Register len = c_rarg2; // len argument to the kernel
+
+    const Register end = len; // index of last element to process
+    const Register off = crc; // offset
+
+    __ ldrw(end, Address(esp)); // int end
+    __ ldrw(off, Address(esp, wordSize)); // int offset
+    __ sub(len, end, off);
+    __ ldr(buf, Address(esp, 2*wordSize)); // byte[] buf | long buf
+    __ add(buf, buf, off); // + offset
+    if (kind == Interpreter::java_util_zip_CRC32C_updateDirectByteBuffer) {
+      __ ldrw(crc, Address(esp, 4*wordSize)); // long crc
+    } else {
+      __ add(buf, buf, arrayOopDesc::base_offset_in_bytes(T_BYTE)); // + header size
+      __ ldrw(crc, Address(esp, 3*wordSize)); // long crc
+    }
+
+    __ andr(sp, r13, -16); // Restore the caller's SP
+
+    // Jump to the stub.
+    __ b(CAST_FROM_FN_PTR(address, StubRoutines::updateBytesCRC32C()));
+
+    return entry;
+  }
   return NULL;
 }
 
--- a/src/hotspot/cpu/arm/compiledIC_arm.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/arm/compiledIC_arm.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -33,7 +33,7 @@
 #include "runtime/safepoint.hpp"
 
 // ----------------------------------------------------------------------------
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
 #define __ _masm.
 // emit call stub, compiled java to interpreter
 address CompiledStaticCall::emit_to_interp_stub(CodeBuffer &cbuf, address mark) {
@@ -89,7 +89,7 @@
 int CompiledStaticCall::reloc_to_interp_stub() {
   return 10;  // 4 in emit_to_interp_stub + 1 in Java_Static_Call
 }
-#endif // COMPILER2 || JVMCI
+#endif // COMPILER2_OR_JVMCI
 
 // size of C2 call stub, compiled java to interpretor
 int CompiledStaticCall::to_interp_stub_size() {
--- a/src/hotspot/cpu/arm/interp_masm_arm.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/arm/interp_masm_arm.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "gc/shared/barrierSet.inline.hpp"
 #include "gc/shared/cardTableModRefBS.inline.hpp"
 #include "gc/shared/collectedHeap.hpp"
--- a/src/hotspot/cpu/arm/jni_arm.h	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#ifndef _JAVASOFT_JNI_MD_H_
-#define _JAVASOFT_JNI_MD_H_
-
-// Note: please do not change these without also changing jni_md.h in the JDK
-// repository
-#ifndef __has_attribute
-  #define __has_attribute(x) 0
-#endif
-#if (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))) || __has_attribute(visibility)
-  #define JNIEXPORT     __attribute__((externally_visible,visibility("default")))
-  #define JNIIMPORT     __attribute__((externally_visible,visibility("default")))
-#else
-  #define JNIEXPORT
-  #define JNIIMPORT
-#endif
-
-#define JNICALL
-
-typedef int jint;
-#if defined(_LP64)
-  typedef long jlong;
-#else
-  typedef long long jlong;
-#endif
-typedef signed char jbyte;
-
-#endif /* !_JAVASOFT_JNI_MD_H_ */
--- a/src/hotspot/cpu/arm/methodHandles_arm.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/arm/methodHandles_arm.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -27,12 +27,12 @@
 // Last synchronization: changeset f8c9417e3571
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "classfile/javaClasses.inline.hpp"
 #include "interpreter/interpreter.hpp"
 #include "interpreter/interpreterRuntime.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/resourceArea.hpp"
-#include "prims/jvm.h"
 #include "prims/methodHandles.hpp"
 
 #define __ _masm->
--- a/src/hotspot/cpu/arm/vm_version_arm_32.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/arm/vm_version_arm_32.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,9 +23,9 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/macroAssembler.inline.hpp"
 #include "memory/resourceArea.hpp"
-#include "prims/jvm.h"
 #include "runtime/java.hpp"
 #include "runtime/os.inline.hpp"
 #include "runtime/stubCodeGenerator.hpp"
--- a/src/hotspot/cpu/arm/vm_version_arm_64.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/arm/vm_version_arm_64.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,9 +23,9 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/macroAssembler.inline.hpp"
 #include "memory/resourceArea.hpp"
-#include "prims/jvm.h"
 #include "runtime/java.hpp"
 #include "runtime/os.inline.hpp"
 #include "runtime/stubCodeGenerator.hpp"
--- a/src/hotspot/cpu/ppc/assembler_ppc.inline.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/ppc/assembler_ppc.inline.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -941,7 +941,7 @@
 inline void Assembler::vpmsumw(  VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VPMSUMW_OPCODE | vrt(d) | vra(a) | vrb(b)); }
 
 // Vector Permute and Xor (introduced with Power 8)
-inline void Assembler::vpermxor( VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c) { emit_int32( VPMSUMW_OPCODE | vrt(d) | vra(a) | vrb(b) | vrc(c)); }
+inline void Assembler::vpermxor( VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c) { emit_int32( VPERMXOR_OPCODE | vrt(d) | vra(a) | vrb(b) | vrc(c)); }
 
 // Transactional Memory instructions (introduced with Power 8)
 inline void Assembler::tbegin_()                                { emit_int32( TBEGIN_OPCODE | rc(1)); }
--- a/src/hotspot/cpu/ppc/globals_ppc.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/ppc/globals_ppc.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -69,7 +69,7 @@
 define_pd_global(bool, RewriteBytecodes,      true);
 define_pd_global(bool, RewriteFrequentPairs,  true);
 
-define_pd_global(bool, UseMembar,             false);
+define_pd_global(bool, UseMembar,             true);
 
 define_pd_global(bool, PreserveFramePointer,  false);
 
--- a/src/hotspot/cpu/ppc/jni_ppc.h	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2013 SAP SE. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#ifndef CPU_PPC_VM_JNI_PPC_H
-#define CPU_PPC_VM_JNI_PPC_H
-
-// Note: please do not change these without also changing jni_md.h in the JDK
-// repository
-#ifndef __has_attribute
-  #define __has_attribute(x) 0
-#endif
-#if (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))) || __has_attribute(visibility)
-  #define JNIEXPORT     __attribute__((visibility("default")))
-  #define JNIIMPORT     __attribute__((visibility("default")))
-#else
-  #define JNIEXPORT
-  #define JNIIMPORT
-#endif
-
-#define JNICALL
-
-typedef int jint;
-
-#if defined(_LP64)
-  typedef long jlong;
-#else
-  typedef long long jlong;
-#endif
-
-typedef signed char jbyte;
-
-#endif // CPU_PPC_VM_JNI_PPC_H
--- a/src/hotspot/cpu/ppc/methodHandles_ppc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/ppc/methodHandles_ppc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -24,12 +24,12 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/macroAssembler.inline.hpp"
 #include "classfile/javaClasses.inline.hpp"
 #include "interpreter/interpreter.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/resourceArea.hpp"
-#include "prims/jvm.h"
 #include "prims/methodHandles.hpp"
 
 #define __ _masm->
--- a/src/hotspot/cpu/ppc/sharedRuntime_ppc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/ppc/sharedRuntime_ppc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -1469,8 +1469,31 @@
   }
   // Save or restore single word registers.
   for (int i = 0; i < total_in_args; i++) {
-    // PPC64: pass ints as longs: must only deal with floats here.
-    if (in_regs[i].first()->is_FloatRegister()) {
+    if (in_regs[i].first()->is_Register()) {
+      int offset = slot * VMRegImpl::stack_slot_size;
+      // Value lives in an input register. Save it on stack.
+      switch (in_sig_bt[i]) {
+        case T_BOOLEAN:
+        case T_CHAR:
+        case T_BYTE:
+        case T_SHORT:
+        case T_INT:
+          if (map != NULL) {
+            __ stw(in_regs[i].first()->as_Register(), offset, R1_SP);
+          } else {
+            __ lwa(in_regs[i].first()->as_Register(), offset, R1_SP);
+          }
+          slot++;
+          assert(slot <= stack_slots, "overflow (after INT or smaller stack slot)");
+          break;
+        case T_ARRAY:
+        case T_LONG:
+          // handled above
+          break;
+        case T_OBJECT:
+        default: ShouldNotReachHere();
+      }
+    } else if (in_regs[i].first()->is_FloatRegister()) {
       if (in_sig_bt[i] == T_FLOAT) {
         int offset = slot * VMRegImpl::stack_slot_size;
         slot++;
--- a/src/hotspot/cpu/ppc/vm_version_ppc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/ppc/vm_version_ppc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -24,11 +24,11 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/assembler.inline.hpp"
 #include "asm/macroAssembler.inline.hpp"
 #include "compiler/disassembler.hpp"
 #include "memory/resourceArea.hpp"
-#include "prims/jvm.h"
 #include "runtime/java.hpp"
 #include "runtime/os.hpp"
 #include "runtime/stubCodeGenerator.hpp"
@@ -109,7 +109,8 @@
 
   if (PowerArchitecturePPC64 >= 8) {
     if (FLAG_IS_DEFAULT(SuperwordUseVSX)) {
-      FLAG_SET_ERGO(bool, SuperwordUseVSX, true);
+      // TODO: Switch on when it works stable. Currently, MachSpillCopyNode::implementation code is missing.
+      //FLAG_SET_ERGO(bool, SuperwordUseVSX, true);
     }
   } else {
     if (SuperwordUseVSX) {
--- a/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -277,7 +277,7 @@
     length.set_instruction(x->length());
     length.load_item();
   }
-  if (needs_store_check) {
+  if (needs_store_check || x->check_boolean()) {
     value.load_item();
   } else {
     value.load_for_store(x->elt_type());
@@ -327,11 +327,14 @@
     // Needs GC write barriers.
     pre_barrier(LIR_OprFact::address(array_addr), LIR_OprFact::illegalOpr /* pre_val */,
                 true /* do_load */, false /* patch */, NULL);
-    __ move(value.result(), array_addr, null_check_info);
-    // Seems to be a precise.
+  }
+
+  LIR_Opr result = maybe_mask_boolean(x, array.result(), value.result(), null_check_info);
+  __ move(result, array_addr, null_check_info);
+
+  if (obj_store) {
+    // Precise card mark
     post_barrier(LIR_OprFact::address(array_addr), value.result());
-  } else {
-    __ move(value.result(), array_addr, null_check_info);
   }
 }
 
--- a/src/hotspot/cpu/s390/globals_s390.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/s390/globals_s390.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -71,7 +71,7 @@
 define_pd_global(bool, RewriteBytecodes,     true);
 define_pd_global(bool, RewriteFrequentPairs, true);
 
-define_pd_global(bool, UseMembar,            false);
+define_pd_global(bool, UseMembar,            true);
 
 define_pd_global(bool, PreserveFramePointer, false);
 
--- a/src/hotspot/cpu/s390/interp_masm_s390.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/s390/interp_masm_s390.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -843,6 +843,38 @@
   verify_oop(Z_tos, state);
 }
 
+void InterpreterMacroAssembler::narrow(Register result, Register ret_type) {
+  get_method(ret_type);
+  z_lg(ret_type, Address(ret_type, in_bytes(Method::const_offset())));
+  z_lb(ret_type, Address(ret_type, in_bytes(ConstMethod::result_type_offset())));
+
+  Label notBool, notByte, notChar, done;
+
+  // common case first
+  compareU32_and_branch(ret_type, T_INT, bcondEqual, done);
+
+  compareU32_and_branch(ret_type, T_BOOLEAN, bcondNotEqual, notBool);
+  z_nilf(result, 0x1);
+  z_bru(done);
+
+  bind(notBool);
+  compareU32_and_branch(ret_type, T_BYTE, bcondNotEqual, notByte);
+  z_lbr(result, result);
+  z_bru(done);
+
+  bind(notByte);
+  compareU32_and_branch(ret_type, T_CHAR, bcondNotEqual, notChar);
+  z_nilf(result, 0xffff);
+  z_bru(done);
+
+  bind(notChar);
+  // compareU32_and_branch(ret_type, T_SHORT, bcondNotEqual, notShort);
+  z_lhr(result, result);
+
+  // Nothing to do for T_INT
+  bind(done);
+}
+
 // remove activation
 //
 // Unlock the receiver if this is a synchronized method.
--- a/src/hotspot/cpu/s390/interp_masm_s390.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/s390/interp_masm_s390.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -86,6 +86,8 @@
   void dispatch_next_noverify_oop(TosState state, int step = 0);
   void dispatch_via(TosState state, address* table);
 
+  void narrow(Register result, Register ret_type);
+
   // Jump to an invoked target.
   void prepare_to_jump_from_interpreted(Register method);
   void jump_from_interpreted(Register method, Register temp);
--- a/src/hotspot/cpu/s390/jni_s390.h	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * 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 _JAVASOFT_JNI_MD_H_
-#define _JAVASOFT_JNI_MD_H_
-
-#if defined(__GNUC__) && (__GNUC__ >= 4)
-  #define JNIEXPORT     __attribute__((visibility("default")))
-  #define JNIIMPORT     __attribute__((visibility("default")))
-#else
-  #define JNIEXPORT
-  #define JNIIMPORT
-#endif
-
-#define JNICALL
-
-typedef int jint;
-
-typedef long int jlong;
-
-typedef signed char jbyte;
-
-#endif // _JAVASOFT_JNI_MD_H_
--- a/src/hotspot/cpu/s390/methodHandles_s390.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/s390/methodHandles_s390.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -24,12 +24,12 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/macroAssembler.inline.hpp"
 #include "classfile/javaClasses.inline.hpp"
 #include "interpreter/interpreter.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/resourceArea.hpp"
-#include "prims/jvm.h"
 #include "prims/methodHandles.hpp"
 
 #ifdef PRODUCT
--- a/src/hotspot/cpu/s390/sharedRuntime_s390.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/s390/sharedRuntime_s390.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -1309,15 +1309,42 @@
         }
       } else {
         __ z_lg(reg, offset, Z_SP);
-        slot += VMRegImpl::slots_per_word;
-        assert(slot <= stack_slots, "overflow (after LONG/ARRAY stack slot)");
       }
+      slot += VMRegImpl::slots_per_word;
+      assert(slot <= stack_slots, "overflow (after LONG/ARRAY stack slot)");
     }
   }
 
   // Save or restore single word registers.
   for (int i = 0; i < total_in_args; i++) {
-    if (in_regs[i].first()->is_FloatRegister()) {
+    if (in_regs[i].first()->is_Register()) {
+      int offset = slot * VMRegImpl::stack_slot_size;
+      // Value lives in an input register. Save it on stack.
+      switch (in_sig_bt[i]) {
+        case T_BOOLEAN:
+        case T_CHAR:
+        case T_BYTE:
+        case T_SHORT:
+        case T_INT: {
+          const Register   reg = in_regs[i].first()->as_Register();
+          Address   stackaddr(Z_SP, offset);
+          if (map != NULL) {
+            __ z_st(reg, stackaddr);
+          } else {
+            __ z_lgf(reg, stackaddr);
+          }
+          slot++;
+          assert(slot <= stack_slots, "overflow (after INT or smaller stack slot)");
+          break;
+        }
+        case T_ARRAY:
+        case T_LONG:
+          // handled above
+          break;
+        case T_OBJECT:
+        default: ShouldNotReachHere();
+      }
+    } else if (in_regs[i].first()->is_FloatRegister()) {
       if (in_sig_bt[i] == T_FLOAT) {
         int offset = slot * VMRegImpl::stack_slot_size;
         slot++;
@@ -1908,7 +1935,7 @@
       case T_ARRAY:
         if (is_critical_native) {
           int body_arg = cix;
-          cix -= 2; // Point to length arg.
+          cix -= 1; // Point to length arg.
           unpack_array_argument(masm, in_regs[jix], in_elem_bt[jix], out_regs[body_arg], out_regs[cix], stack_slots);
           break;
         }
--- a/src/hotspot/cpu/s390/templateInterpreterGenerator_s390.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/s390/templateInterpreterGenerator_s390.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -2377,6 +2377,12 @@
   __ store_const(Address(RjvmtiState, JvmtiThreadState::earlyret_state_offset()),
                  JvmtiThreadState::earlyret_inactive, 4, 4, Z_R0_scratch);
 
+  if (state == itos) {
+    // 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.
+    __ narrow(Z_tos, Z_tmp_1); /* fall through */
+  }
   __ remove_activation(state,
                        Z_tmp_1, // retaddr
                        false,   // throw_monitor_exception
--- a/src/hotspot/cpu/s390/templateTable_s390.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/s390/templateTable_s390.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -1174,8 +1174,20 @@
   __ pop_i(Z_ARG3);
   __ pop_ptr(Z_tmp_2);
   // Z_tos   : value
-  // Z_ARG3 : index
+  // Z_ARG3  : index
   // Z_tmp_2 : array
+
+  // Need to check whether array is boolean or byte
+  // since both types share the bastore bytecode.
+  __ load_klass(Z_tmp_1, Z_tmp_2);
+  __ z_llgf(Z_tmp_1, Address(Z_tmp_1, Klass::layout_helper_offset()));
+  __ z_tmll(Z_tmp_1, Klass::layout_helper_boolean_diffbit());
+  Label L_skip;
+  __ z_bfalse(L_skip);
+  // if it is a T_BOOLEAN array, mask the stored value to 0/1
+  __ z_nilf(Z_tos, 0x1);
+  __ bind(L_skip);
+
   // No index shift necessary - pass 0.
   index_check(Z_tmp_2, Z_ARG3, 0); // Prefer index in Z_ARG3.
   __ z_stc(Z_tos,
@@ -2321,6 +2333,13 @@
     __ bind(skip_register_finalizer);
   }
 
+  if (state == itos) {
+    // 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.
+    __ narrow(Z_tos, Z_tmp_1); /* fall through */
+  }
+
   __ remove_activation(state, Z_R14);
   __ z_br(Z_R14);
 }
--- a/src/hotspot/cpu/s390/vm_version_s390.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/s390/vm_version_s390.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -24,11 +24,11 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/assembler.inline.hpp"
 #include "compiler/disassembler.hpp"
 #include "code/compiledIC.hpp"
 #include "memory/resourceArea.hpp"
-#include "prims/jvm.h"
 #include "runtime/java.hpp"
 #include "runtime/stubCodeGenerator.hpp"
 #include "vm_version_s390.hpp"
--- a/src/hotspot/cpu/sparc/globals_sparc.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/sparc/globals_sparc.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -74,7 +74,7 @@
 define_pd_global(bool, RewriteBytecodes,     true);
 define_pd_global(bool, RewriteFrequentPairs, true);
 
-define_pd_global(bool, UseMembar,            false);
+define_pd_global(bool, UseMembar,            true);
 
 define_pd_global(bool, PreserveFramePointer, false);
 
--- a/src/hotspot/cpu/sparc/jni_sparc.h	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-// Note: please do not change these without also changing jni_md.h in the JDK
-// repository
-#ifndef __has_attribute
-  #define __has_attribute(x) 0
-#endif
-#if (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))) || __has_attribute(visibility)
-  #define JNIEXPORT     __attribute__((visibility("default")))
-  #define JNIIMPORT     __attribute__((visibility("default")))
-#else
-  #define JNIEXPORT
-  #define JNIIMPORT
-#endif
-#define JNICALL
-
-typedef int jint;
-
-typedef long jlong;
-
-typedef signed char jbyte;
--- a/src/hotspot/cpu/sparc/macroAssembler_sparc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/sparc/macroAssembler_sparc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/macroAssembler.inline.hpp"
 #include "compiler/disassembler.hpp"
 #include "gc/shared/cardTableModRefBS.hpp"
@@ -31,7 +32,6 @@
 #include "memory/resourceArea.hpp"
 #include "memory/universe.hpp"
 #include "oops/klass.inline.hpp"
-#include "prims/jvm.h"
 #include "prims/methodHandles.hpp"
 #include "runtime/biasedLocking.hpp"
 #include "runtime/interfaceSupport.hpp"
--- a/src/hotspot/cpu/sparc/methodHandles_sparc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/sparc/methodHandles_sparc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,13 +23,13 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/macroAssembler.hpp"
 #include "classfile/javaClasses.inline.hpp"
 #include "interpreter/interpreter.hpp"
 #include "interpreter/interp_masm.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/resourceArea.hpp"
-#include "prims/jvm.h"
 #include "prims/methodHandles.hpp"
 
 #define __ _masm->
--- a/src/hotspot/cpu/sparc/templateInterpreterGenerator_sparc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/sparc/templateInterpreterGenerator_sparc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -319,7 +319,7 @@
 #if INCLUDE_JVMCI
   // Check if we need to take lock at entry of synchronized method.  This can
   // only occur on method entry so emit it only for vtos with step 0.
-  if (UseJVMCICompiler && state == vtos && step == 0) {
+  if (EnableJVMCI && state == vtos && step == 0) {
     Label L;
     Address pending_monitor_enter_addr(G2_thread, JavaThread::pending_monitorenter_offset());
     __ ldbool(pending_monitor_enter_addr, Gtemp);  // Load if pending monitor enter
@@ -331,7 +331,7 @@
     __ bind(L);
   } else {
 #ifdef ASSERT
-    if (UseJVMCICompiler) {
+    if (EnableJVMCI) {
       Label L;
       Address pending_monitor_enter_addr(G2_thread, JavaThread::pending_monitorenter_offset());
       __ ldbool(pending_monitor_enter_addr, Gtemp);  // Load if pending monitor enter
--- a/src/hotspot/cpu/sparc/vm_version_sparc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/sparc/vm_version_sparc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,11 +23,11 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/macroAssembler.inline.hpp"
 #include "logging/log.hpp"
 #include "logging/logStream.hpp"
 #include "memory/resourceArea.hpp"
-#include "prims/jvm.h"
 #include "runtime/java.hpp"
 #include "runtime/os.hpp"
 #include "runtime/stubCodeGenerator.hpp"
--- a/src/hotspot/cpu/x86/frame_x86.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/x86/frame_x86.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -436,11 +436,11 @@
   // This is the sp before any possible extension (adapter/locals).
   intptr_t* unextended_sp = interpreter_frame_sender_sp();
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   if (map->update_map()) {
     update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
   }
-#endif // COMPILER2 || INCLUDE_JVMCI
+#endif // COMPILER2_OR_JVMCI
 
   return frame(sender_sp, unextended_sp, link(), sender_pc());
 }
--- a/src/hotspot/cpu/x86/globals_x86.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/x86/globals_x86.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -46,11 +46,11 @@
 // the the vep is aligned at CodeEntryAlignment whereas c2 only aligns
 // the uep and the vep doesn't get real alignment but just slops on by
 // only assured that the entry instruction meets the 5 byte size requirement.
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
 define_pd_global(intx, CodeEntryAlignment,       32);
 #else
 define_pd_global(intx, CodeEntryAlignment,       16);
-#endif // COMPILER2
+#endif // COMPILER2_OR_JVMCI
 define_pd_global(intx, OptoLoopAlignment,        16);
 define_pd_global(intx, InlineFrequencyCount,     100);
 define_pd_global(intx, InlineSmallCode,          1000);
@@ -84,11 +84,7 @@
 define_pd_global(bool, RewriteBytecodes,     true);
 define_pd_global(bool, RewriteFrequentPairs, true);
 
-#ifdef _ALLBSD_SOURCE
 define_pd_global(bool, UseMembar,            true);
-#else
-define_pd_global(bool, UseMembar,            false);
-#endif
 
 // GC Ergo Flags
 define_pd_global(size_t, CMSYoungGenPerWorker, 64*M);  // default max size of CMS young gen, per GC worker thread
--- a/src/hotspot/cpu/x86/jni_x86.h	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#ifndef _JAVASOFT_JNI_MD_H_
-#define _JAVASOFT_JNI_MD_H_
-
-#if defined(_WIN32)
-  #define JNIEXPORT __declspec(dllexport)
-  #define JNIIMPORT __declspec(dllimport)
-  #define JNICALL __stdcall
-
-  typedef int jint;
-  typedef __int64 jlong;
-#else
-
-// Note: please do not change these without also changing jni_md.h in the JDK
-// repository
-#ifndef __has_attribute
-  #define __has_attribute(x) 0
-#endif
-#if (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))) || __has_attribute(visibility)
-  #define JNIEXPORT     __attribute__((visibility("default")))
-  #define JNIIMPORT     __attribute__((visibility("default")))
-#else
-  #define JNIEXPORT
-  #define JNIIMPORT
-#endif
-
-  #define JNICALL
-  typedef int jint;
-#if defined(_LP64)
-  typedef long jlong;
-#else
-  typedef long long jlong;
-#endif
-
-#endif
-
-typedef signed char jbyte;
-
-#endif /* !_JAVASOFT_JNI_MD_H_ */
--- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/assembler.hpp"
 #include "asm/assembler.inline.hpp"
 #include "compiler/disassembler.hpp"
@@ -32,7 +33,6 @@
 #include "memory/resourceArea.hpp"
 #include "memory/universe.hpp"
 #include "oops/klass.inline.hpp"
-#include "prims/jvm.h"
 #include "prims/methodHandles.hpp"
 #include "runtime/biasedLocking.hpp"
 #include "runtime/interfaceSupport.hpp"
--- a/src/hotspot/cpu/x86/methodHandles_x86.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/x86/methodHandles_x86.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,13 +23,13 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/macroAssembler.hpp"
 #include "classfile/javaClasses.inline.hpp"
 #include "interpreter/interpreter.hpp"
 #include "interpreter/interpreterRuntime.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/resourceArea.hpp"
-#include "prims/jvm.h"
 #include "prims/methodHandles.hpp"
 
 #define __ _masm->
--- a/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -151,7 +151,7 @@
   if (UseAVX < 3) {
     num_xmm_regs = num_xmm_regs/2;
   }
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   if (save_vectors) {
     assert(UseAVX > 0, "Vectors larger than 16 byte long are supported only with AVX");
     assert(MaxVectorSize <= 64, "Only up to 64 byte long vectors are supported");
@@ -260,7 +260,7 @@
     }
   }
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   if (save_vectors) {
     off = ymm0_off;
     int delta = ymm1_off - off;
@@ -270,7 +270,7 @@
       off += delta;
     }
   }
-#endif // COMPILER2 || INCLUDE_JVMCI
+#endif // COMPILER2_OR_JVMCI
 
   // %%% These should all be a waste but we'll keep things as they were for now
   if (true) {
@@ -323,7 +323,7 @@
     __ addptr(rsp, frame::arg_reg_save_area_bytes);
   }
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   if (restore_vectors) {
     assert(UseAVX > 0, "Vectors larger than 16 byte long are supported only with AVX");
     assert(MaxVectorSize <= 64, "Only up to 64 byte long vectors are supported");
@@ -2183,7 +2183,7 @@
   // critical natives they are offset down.
   GrowableArray<int> arg_order(2 * total_in_args);
   VMRegPair tmp_vmreg;
-  tmp_vmreg.set1(rbx->as_VMReg());
+  tmp_vmreg.set2(rbx->as_VMReg());
 
   if (!is_critical_native) {
     for (int i = total_in_args - 1, c_arg = total_c_args - 1; i >= 0; i--, c_arg--) {
--- a/src/hotspot/cpu/x86/stubGenerator_x86_32.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/x86/stubGenerator_x86_32.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -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
@@ -3433,6 +3433,8 @@
   }
 
  address generate_libmExp() {
+    StubCodeMark mark(this, "StubRoutines", "libmExp");
+
     address start = __ pc();
 
     const XMMRegister x0  = xmm0;
@@ -3458,6 +3460,8 @@
   }
 
  address generate_libmLog() {
+   StubCodeMark mark(this, "StubRoutines", "libmLog");
+
    address start = __ pc();
 
    const XMMRegister x0 = xmm0;
@@ -3483,6 +3487,8 @@
  }
 
  address generate_libmLog10() {
+   StubCodeMark mark(this, "StubRoutines", "libmLog10");
+
    address start = __ pc();
 
    const XMMRegister x0 = xmm0;
@@ -3508,6 +3514,8 @@
  }
 
  address generate_libmPow() {
+   StubCodeMark mark(this, "StubRoutines", "libmPow");
+
    address start = __ pc();
 
    const XMMRegister x0 = xmm0;
@@ -3533,6 +3541,8 @@
  }
 
  address generate_libm_reduce_pi04l() {
+   StubCodeMark mark(this, "StubRoutines", "libm_reduce_pi04l");
+
    address start = __ pc();
 
    BLOCK_COMMENT("Entry:");
@@ -3543,6 +3553,8 @@
  }
 
  address generate_libm_sin_cos_huge() {
+   StubCodeMark mark(this, "StubRoutines", "libm_sin_cos_huge");
+
    address start = __ pc();
 
    const XMMRegister x0 = xmm0;
@@ -3556,6 +3568,8 @@
  }
 
  address generate_libmSin() {
+   StubCodeMark mark(this, "StubRoutines", "libmSin");
+
    address start = __ pc();
 
    const XMMRegister x0 = xmm0;
@@ -3579,6 +3593,8 @@
  }
 
  address generate_libmCos() {
+   StubCodeMark mark(this, "StubRoutines", "libmCos");
+
    address start = __ pc();
 
    const XMMRegister x0 = xmm0;
@@ -3604,6 +3620,8 @@
  }
 
  address generate_libm_tan_cot_huge() {
+   StubCodeMark mark(this, "StubRoutines", "libm_tan_cot_huge");
+
    address start = __ pc();
 
    const XMMRegister x0 = xmm0;
@@ -3617,6 +3635,8 @@
  }
 
  address generate_libmTan() {
+   StubCodeMark mark(this, "StubRoutines", "libmTan");
+
    address start = __ pc();
 
    const XMMRegister x0 = xmm0;
--- a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -4619,6 +4619,8 @@
   }
 
   address generate_libmExp() {
+    StubCodeMark mark(this, "StubRoutines", "libmExp");
+
     address start = __ pc();
 
     const XMMRegister x0  = xmm0;
@@ -4646,6 +4648,8 @@
   }
 
   address generate_libmLog() {
+    StubCodeMark mark(this, "StubRoutines", "libmLog");
+
     address start = __ pc();
 
     const XMMRegister x0 = xmm0;
@@ -4674,6 +4678,8 @@
   }
 
   address generate_libmLog10() {
+    StubCodeMark mark(this, "StubRoutines", "libmLog10");
+
     address start = __ pc();
 
     const XMMRegister x0 = xmm0;
@@ -4701,6 +4707,8 @@
   }
 
   address generate_libmPow() {
+    StubCodeMark mark(this, "StubRoutines", "libmPow");
+
     address start = __ pc();
 
     const XMMRegister x0 = xmm0;
@@ -4731,6 +4739,8 @@
   }
 
   address generate_libmSin() {
+    StubCodeMark mark(this, "StubRoutines", "libmSin");
+
     address start = __ pc();
 
     const XMMRegister x0 = xmm0;
@@ -4770,6 +4780,8 @@
   }
 
   address generate_libmCos() {
+    StubCodeMark mark(this, "StubRoutines", "libmCos");
+
     address start = __ pc();
 
     const XMMRegister x0 = xmm0;
@@ -4809,6 +4821,8 @@
   }
 
   address generate_libmTan() {
+    StubCodeMark mark(this, "StubRoutines", "libmTan");
+
     address start = __ pc();
 
     const XMMRegister x0 = xmm0;
--- a/src/hotspot/cpu/x86/templateInterpreterGenerator_x86.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/x86/templateInterpreterGenerator_x86.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -257,7 +257,7 @@
 #if INCLUDE_JVMCI
   // Check if we need to take lock at entry of synchronized method.  This can
   // only occur on method entry so emit it only for vtos with step 0.
-  if ((UseJVMCICompiler || UseAOT) && state == vtos && step == 0) {
+  if ((EnableJVMCI || UseAOT) && state == vtos && step == 0) {
     Label L;
     __ cmpb(Address(thread, JavaThread::pending_monitorenter_offset()), 0);
     __ jcc(Assembler::zero, L);
@@ -270,7 +270,7 @@
     __ bind(L);
   } else {
 #ifdef ASSERT
-    if (UseJVMCICompiler) {
+    if (EnableJVMCI) {
       Label L;
       __ cmpb(Address(r15_thread, JavaThread::pending_monitorenter_offset()), 0);
       __ jccb(Assembler::zero, L);
--- a/src/hotspot/cpu/x86/vm_version_x86.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/cpu/x86/vm_version_x86.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,12 +23,12 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "asm/macroAssembler.hpp"
 #include "asm/macroAssembler.inline.hpp"
 #include "logging/log.hpp"
 #include "logging/logStream.hpp"
 #include "memory/resourceArea.hpp"
-#include "prims/jvm.h"
 #include "runtime/java.hpp"
 #include "runtime/os.hpp"
 #include "runtime/stubCodeGenerator.hpp"
@@ -944,7 +944,7 @@
     }
   }
 #endif
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   if (MaxVectorSize > 0) {
     if (!is_power_of_2(MaxVectorSize)) {
       warning("MaxVectorSize must be a power of 2");
@@ -996,7 +996,7 @@
     }
 #endif // COMPILER2 && ASSERT
   }
-#endif // COMPILER2 || INCLUDE_JVMCI
+#endif // COMPILER2_OR_JVMCI
 
 #ifdef COMPILER2
 #ifdef _LP64
--- a/src/hotspot/cpu/zero/jni_zero.h	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2009 Red Hat, Inc.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-
-
-// Note: please do not change these without also changing jni_md.h in the JDK
-// repository
-#ifndef __has_attribute
-  #define __has_attribute(x) 0
-#endif
-#if (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))) || __has_attribute(visibility)
-  #define JNIEXPORT     __attribute__((visibility("default")))
-  #define JNIIMPORT     __attribute__((visibility("default")))
-#else
-  #define JNIEXPORT
-  #define JNIIMPORT
-#endif
-#define JNICALL
-
-typedef int jint;
-typedef signed char jbyte;
-
-#ifdef _LP64
-typedef long jlong;
-#else
-typedef long long jlong;
-#endif
--- a/src/hotspot/os/aix/jvm_aix.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/aix/jvm_aix.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -24,7 +24,7 @@
  */
 
 #include "precompiled.hpp"
-#include "prims/jvm.h"
+#include "jvm.h"
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/osThread.hpp"
 
--- a/src/hotspot/os/aix/jvm_aix.h	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2013 SAP SE. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * 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_AIX_VM_JVM_AIX_H
-#define OS_AIX_VM_JVM_AIX_H
-
-// HotSpot integration note:
-//
-// This is derived from the JDK classic file:
-// "$JDK/src/solaris/javavm/export/jvm_md.h":15 (ver. 1.10 98/04/22)
-// All local includes have been commented out.
-
-#ifndef JVM_MD_H
-#define JVM_MD_H
-
-/*
- * This file is currently collecting system-specific dregs for the
- * JNI conversion, which should be sorted out later.
- */
-
-#include <dirent.h>             /* For DIR */
-
-// Must redefine NULL because the macro gets redefined to int 0
-// by dirent.h. This redefinition is included later then the standard definition in
-// globalDefinitions_<compiler>.hpp and leads to assertions in the VM initialization.
-// We definitely need NULL to have the same lengh as an address pointer.
-#ifdef _LP64
-#undef NULL
-#define NULL 0L
-#else
-#ifndef NULL
-#define NULL 0
-#endif
-#endif
-
-#include <sys/param.h>          /* For MAXPATHLEN */
-#include <sys/socket.h>         /* For socklen_t */
-#include <unistd.h>             /* For F_OK, R_OK, W_OK */
-
-#define JNI_ONLOAD_SYMBOLS      {"JNI_OnLoad"}
-#define JNI_ONUNLOAD_SYMBOLS    {"JNI_OnUnload"}
-#define JVM_ONLOAD_SYMBOLS      {"JVM_OnLoad"}
-#define AGENT_ONLOAD_SYMBOLS    {"Agent_OnLoad"}
-#define AGENT_ONUNLOAD_SYMBOLS  {"Agent_OnUnload"}
-#define AGENT_ONATTACH_SYMBOLS  {"Agent_OnAttach"}
-
-#define JNI_LIB_PREFIX "lib"
-#define JNI_LIB_SUFFIX ".so"
-
-#define JVM_MAXPATHLEN MAXPATHLEN
-
-#define JVM_R_OK    R_OK
-#define JVM_W_OK    W_OK
-#define JVM_X_OK    X_OK
-#define JVM_F_OK    F_OK
-
-/*
- * File I/O
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-/* O Flags */
-
-#define JVM_O_RDONLY     O_RDONLY
-#define JVM_O_WRONLY     O_WRONLY
-#define JVM_O_RDWR       O_RDWR
-#define JVM_O_O_APPEND   O_APPEND
-#define JVM_O_EXCL       O_EXCL
-#define JVM_O_CREAT      O_CREAT
-
-/* Signal definitions */
-
-#define BREAK_SIGNAL     SIGQUIT           /* Thread dumping support.    */
-#define SHUTDOWN1_SIGNAL SIGHUP            /* Shutdown Hooks support.    */
-#define SHUTDOWN2_SIGNAL SIGINT
-#define SHUTDOWN3_SIGNAL SIGTERM
-
-#endif /* JVM_MD_H */
-
-#endif // OS_AIX_VM_JVM_AIX_H
--- a/src/hotspot/os/aix/os_aix.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/aix/os_aix.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -28,6 +28,7 @@
 #pragma alloca
 
 // no precompiled headers
+#include "jvm.h"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
@@ -35,7 +36,6 @@
 #include "code/vtableStubs.hpp"
 #include "compiler/compileBroker.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_aix.h"
 #include "logging/log.hpp"
 #include "libo4.hpp"
 #include "libperfstat_aix.hpp"
@@ -49,7 +49,6 @@
 #include "os_share_aix.hpp"
 #include "porting_aix.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/atomic.hpp"
@@ -3249,7 +3248,7 @@
   }
 
   // ReduceSignalUsage allows the user to override these handlers
-  // see comments at the very top and jvm_solaris.h
+  // see comments at the very top and jvm_md.h
   if (!ReduceSignalUsage) {
     DO_SIGNAL_CHECK(SHUTDOWN1_SIGNAL);
     DO_SIGNAL_CHECK(SHUTDOWN2_SIGNAL);
--- a/src/hotspot/os/bsd/decoder_machO.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/bsd/decoder_machO.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -25,7 +25,7 @@
 #include "precompiled.hpp"
 
 #ifdef __APPLE__
-#include "prims/jvm.h"
+#include "jvm.h"
 #include "decoder_machO.hpp"
 
 #include <cxxabi.h>
--- a/src/hotspot/os/bsd/jvm_bsd.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/bsd/jvm_bsd.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,7 +23,7 @@
  */
 
 #include "precompiled.hpp"
-#include "prims/jvm.h"
+#include "jvm.h"
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/osThread.hpp"
 
--- a/src/hotspot/os/bsd/jvm_bsd.h	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,115 +0,0 @@
-/*
- * 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
- * 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_BSD_VM_JVM_BSD_H
-#define OS_BSD_VM_JVM_BSD_H
-
-/*
-// HotSpot integration note:
-//
-// This is derived from the JDK classic file:
-// "$JDK/src/solaris/javavm/export/jvm_md.h":15 (ver. 1.10 98/04/22)
-// All local includes have been commented out.
-*/
-
-#ifndef JVM_MD_H
-#define JVM_MD_H
-
-/*
- * This file is currently collecting system-specific dregs for the
- * JNI conversion, which should be sorted out later.
- */
-
-#include <dirent.h>             /* For DIR */
-#include <sys/param.h>          /* For MAXPATHLEN */
-#include <sys/socket.h>         /* For socklen_t */
-#include <unistd.h>             /* For F_OK, R_OK, W_OK */
-
-#define JNI_ONLOAD_SYMBOLS      {"JNI_OnLoad"}
-#define JNI_ONUNLOAD_SYMBOLS    {"JNI_OnUnload"}
-#define JVM_ONLOAD_SYMBOLS      {"JVM_OnLoad"}
-#define AGENT_ONLOAD_SYMBOLS    {"Agent_OnLoad"}
-#define AGENT_ONUNLOAD_SYMBOLS  {"Agent_OnUnload"}
-#define AGENT_ONATTACH_SYMBOLS  {"Agent_OnAttach"}
-
-#define JNI_LIB_PREFIX "lib"
-#ifdef __APPLE__
-#define JNI_LIB_SUFFIX ".dylib"
-#else
-#define JNI_LIB_SUFFIX ".so"
-#endif
-
-// Hack: MAXPATHLEN is 4095 on some Bsd and 4096 on others. This may
-//       cause problems if JVM and the rest of JDK are built on different
-//       Bsd releases. Here we define JVM_MAXPATHLEN to be MAXPATHLEN + 1,
-//       so buffers declared in VM are always >= 4096.
-#define JVM_MAXPATHLEN MAXPATHLEN + 1
-
-#define JVM_R_OK    R_OK
-#define JVM_W_OK    W_OK
-#define JVM_X_OK    X_OK
-#define JVM_F_OK    F_OK
-
-/*
- * File I/O
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-/* O Flags */
-
-#define JVM_O_RDONLY     O_RDONLY
-#define JVM_O_WRONLY     O_WRONLY
-#define JVM_O_RDWR       O_RDWR
-#define JVM_O_O_APPEND   O_APPEND
-#define JVM_O_EXCL       O_EXCL
-#define JVM_O_CREAT      O_CREAT
-
-/* Signal definitions */
-
-#define BREAK_SIGNAL     SIGQUIT           /* Thread dumping support.    */
-#define SHUTDOWN1_SIGNAL SIGHUP            /* Shutdown Hooks support.    */
-#define SHUTDOWN2_SIGNAL SIGINT
-#define SHUTDOWN3_SIGNAL SIGTERM
-
-#ifndef SIGRTMIN
-#ifdef __OpenBSD__
-#define SIGRTMIN        1
-#else
-#define SIGRTMIN        33
-#endif
-#endif
-#ifndef SIGRTMAX
-#ifdef __OpenBSD__
-#define SIGRTMAX        31
-#else
-#define SIGRTMAX        63
-#endif
-#endif
-#endif /* JVM_MD_H */
-
-#endif // OS_BSD_VM_JVM_BSD_H
--- a/src/hotspot/os/bsd/os_bsd.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/bsd/os_bsd.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
@@ -31,7 +32,6 @@
 #include "compiler/compileBroker.hpp"
 #include "compiler/disassembler.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_bsd.h"
 #include "logging/log.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
@@ -39,7 +39,6 @@
 #include "os_bsd.inline.hpp"
 #include "os_share_bsd.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/atomic.hpp"
@@ -3240,7 +3239,7 @@
 
 
   // ReduceSignalUsage allows the user to override these handlers
-  // see comments at the very top and jvm_solaris.h
+  // see comments at the very top and jvm_md.h
   if (!ReduceSignalUsage) {
     DO_SIGNAL_CHECK(SHUTDOWN1_SIGNAL);
     DO_SIGNAL_CHECK(SHUTDOWN2_SIGNAL);
--- a/src/hotspot/os/linux/decoder_linux.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/linux/decoder_linux.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -22,7 +22,7 @@
  *
  */
 
-#include "prims/jvm.h"
+#include "jvm.h"
 #include "utilities/decoder_elf.hpp"
 
 #include <cxxabi.h>
--- a/src/hotspot/os/linux/jvm_linux.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/linux/jvm_linux.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,7 +23,7 @@
  */
 
 #include "precompiled.hpp"
-#include "prims/jvm.h"
+#include "jvm.h"
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/osThread.hpp"
 
--- a/src/hotspot/os/linux/jvm_linux.h	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-/*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
- * 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_JVM_LINUX_H
-#define OS_LINUX_VM_JVM_LINUX_H
-
-/*
-// HotSpot integration note:
-//
-// This is derived from the JDK classic file:
-// "$JDK/src/solaris/javavm/export/jvm_md.h":15 (ver. 1.10 98/04/22)
-// All local includes have been commented out.
-*/
-
-#ifndef JVM_MD_H
-#define JVM_MD_H
-
-/*
- * This file is currently collecting system-specific dregs for the
- * JNI conversion, which should be sorted out later.
- */
-
-#include <dirent.h>             /* For DIR */
-#include <sys/param.h>          /* For MAXPATHLEN */
-#include <sys/socket.h>         /* For socklen_t */
-#include <unistd.h>             /* For F_OK, R_OK, W_OK */
-
-#define JNI_ONLOAD_SYMBOLS      {"JNI_OnLoad"}
-#define JNI_ONUNLOAD_SYMBOLS    {"JNI_OnUnload"}
-#define JVM_ONLOAD_SYMBOLS      {"JVM_OnLoad"}
-#define AGENT_ONLOAD_SYMBOLS    {"Agent_OnLoad"}
-#define AGENT_ONUNLOAD_SYMBOLS  {"Agent_OnUnload"}
-#define AGENT_ONATTACH_SYMBOLS  {"Agent_OnAttach"}
-
-#define JNI_LIB_PREFIX "lib"
-#define JNI_LIB_SUFFIX ".so"
-
-// Hack: MAXPATHLEN is 4095 on some Linux and 4096 on others. This may
-//       cause problems if JVM and the rest of JDK are built on different
-//       Linux releases. Here we define JVM_MAXPATHLEN to be MAXPATHLEN + 1,
-//       so buffers declared in VM are always >= 4096.
-#define JVM_MAXPATHLEN MAXPATHLEN + 1
-
-#define JVM_R_OK    R_OK
-#define JVM_W_OK    W_OK
-#define JVM_X_OK    X_OK
-#define JVM_F_OK    F_OK
-
-/*
- * File I/O
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-/* O Flags */
-
-#define JVM_O_RDONLY     O_RDONLY
-#define JVM_O_WRONLY     O_WRONLY
-#define JVM_O_RDWR       O_RDWR
-#define JVM_O_O_APPEND   O_APPEND
-#define JVM_O_EXCL       O_EXCL
-#define JVM_O_CREAT      O_CREAT
-
-/* Signal definitions */
-
-#define BREAK_SIGNAL     SIGQUIT           /* Thread dumping support.    */
-#define SHUTDOWN1_SIGNAL SIGHUP            /* Shutdown Hooks support.    */
-#define SHUTDOWN2_SIGNAL SIGINT
-#define SHUTDOWN3_SIGNAL SIGTERM
-
-#endif /* JVM_MD_H */
-
-#endif // OS_LINUX_VM_JVM_LINUX_H
--- a/src/hotspot/os/linux/os_linux.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/linux/os_linux.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
@@ -31,7 +32,6 @@
 #include "compiler/compileBroker.hpp"
 #include "compiler/disassembler.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_linux.h"
 #include "logging/log.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
@@ -39,7 +39,6 @@
 #include "os_linux.inline.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/atomic.hpp"
@@ -4664,7 +4663,7 @@
 #endif
 
   // ReduceSignalUsage allows the user to override these handlers
-  // see comments at the very top and jvm_solaris.h
+  // see comments at the very top and jvm_md.h
   if (!ReduceSignalUsage) {
     DO_SIGNAL_CHECK(SHUTDOWN1_SIGNAL);
     DO_SIGNAL_CHECK(SHUTDOWN2_SIGNAL);
--- a/src/hotspot/os/posix/os_posix.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/posix/os_posix.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -22,8 +22,8 @@
  *
  */
 
+#include "jvm.h"
 #include "utilities/globalDefinitions.hpp"
-#include "prims/jvm.h"
 #include "runtime/frame.inline.hpp"
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/os.hpp"
--- a/src/hotspot/os/solaris/jvm_solaris.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/solaris/jvm_solaris.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,7 +23,7 @@
  */
 
 #include "precompiled.hpp"
-#include "prims/jvm.h"
+#include "jvm.h"
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/osThread.hpp"
 
--- a/src/hotspot/os/solaris/jvm_solaris.h	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-/*
- * 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
- * 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_SOLARIS_VM_JVM_SOLARIS_H
-#define OS_SOLARIS_VM_JVM_SOLARIS_H
-
-/*
-// HotSpot integration note:
-//
-// This is derived from the JDK classic file:
-// "$JDK/src/solaris/javavm/export/jvm_md.h":15 (ver. 1.10 98/04/22)
-// All local includes have been commented out.
-*/
-
-#ifndef JVM_MD_H
-#define JVM_MD_H
-
-/*
- * This file is currently collecting system-specific dregs for the
- * JNI conversion, which should be sorted out later.
- */
-
-#include <dirent.h>             /* For DIR */
-#include <sys/param.h>          /* For MAXPATHLEN */
-#include <sys/socket.h>         /* For socklen_t */
-#include <unistd.h>             /* For F_OK, R_OK, W_OK */
-#include <sys/int_types.h>      /* for intptr_t types (64 Bit cleanliness) */
-
-#define JNI_ONLOAD_SYMBOLS      {"JNI_OnLoad"}
-#define JNI_ONUNLOAD_SYMBOLS    {"JNI_OnUnload"}
-#define JVM_ONLOAD_SYMBOLS      {"JVM_OnLoad"}
-#define AGENT_ONLOAD_SYMBOLS    {"Agent_OnLoad"}
-#define AGENT_ONUNLOAD_SYMBOLS  {"Agent_OnUnload"}
-#define AGENT_ONATTACH_SYMBOLS  {"Agent_OnAttach"}
-
-#define JNI_LIB_PREFIX "lib"
-#define JNI_LIB_SUFFIX ".so"
-
-#define JVM_MAXPATHLEN MAXPATHLEN
-
-#define JVM_R_OK    R_OK
-#define JVM_W_OK    W_OK
-#define JVM_X_OK    X_OK
-#define JVM_F_OK    F_OK
-
-/*
- * File I/O
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-/* O Flags */
-
-#define JVM_O_RDONLY     O_RDONLY
-#define JVM_O_WRONLY     O_WRONLY
-#define JVM_O_RDWR       O_RDWR
-#define JVM_O_O_APPEND   O_APPEND
-#define JVM_O_EXCL       O_EXCL
-#define JVM_O_CREAT      O_CREAT
-
-/* Signal definitions */
-
-#define BREAK_SIGNAL     SIGQUIT           /* Thread dumping support.    */
-#define ASYNC_SIGNAL     SIGJVM2           /* Event-based suspend/resume support */
-#define SHUTDOWN1_SIGNAL SIGHUP            /* Shutdown Hooks support.    */
-#define SHUTDOWN2_SIGNAL SIGINT
-#define SHUTDOWN3_SIGNAL SIGTERM
-
-/* With 1.4.1 libjsig added versioning: used in os_solaris.cpp and jsig.c */
-#define JSIG_VERSION_1_4_1   0x30140100
-
-#endif /* JVM_MD_H */
-
-#endif // OS_SOLARIS_VM_JVM_SOLARIS_H
--- a/src/hotspot/os/solaris/os_solaris.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/solaris/os_solaris.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
@@ -31,7 +32,6 @@
 #include "compiler/compileBroker.hpp"
 #include "compiler/disassembler.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_solaris.h"
 #include "logging/log.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
@@ -39,7 +39,6 @@
 #include "os_share_solaris.hpp"
 #include "os_solaris.inline.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/atomic.hpp"
--- a/src/hotspot/os/windows/jvm_windows.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/windows/jvm_windows.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,7 +23,7 @@
  */
 
 #include "precompiled.hpp"
-#include "prims/jvm.h"
+#include "jvm.h"
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/osThread.hpp"
 
--- a/src/hotspot/os/windows/jvm_windows.h	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,118 +0,0 @@
-/*
- * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-#ifndef OS_WINDOWS_VM_JVM_WINDOWS_H
-#define OS_WINDOWS_VM_JVM_WINDOWS_H
-
-#ifndef _JAVASOFT_JVM_MD_H_
-#define _JAVASOFT_JVM_MD_H_
-
-/*
- * This file is currently collecting system-specific dregs for the
- * JNI conversion, which should be sorted out later.
- */
-
-// JDK7 requires VS2010
-#if _MSC_VER >= 1600
-// JDK7 minimum platform requirement: Windows XP
-#if _WIN32_WINNT < 0x0501
-#undef _WIN32_WINNT
-#define _WIN32_WINNT  0x0501
-#endif
-#endif
-
-#include <windows.h>
-
-#include <Psapi.h>
-#include <Tlhelp32.h>
-
-typedef int socklen_t;
-
-#define JNI_ONLOAD_SYMBOLS      {"_JNI_OnLoad@8", "JNI_OnLoad"}
-#define JNI_ONUNLOAD_SYMBOLS    {"_JNI_OnUnload@8", "JNI_OnUnload"}
-#define JVM_ONLOAD_SYMBOLS      {"_JVM_OnLoad@12", "JVM_OnLoad"}
-#define AGENT_ONLOAD_SYMBOLS    {"_Agent_OnLoad@12", "Agent_OnLoad"}
-#define AGENT_ONUNLOAD_SYMBOLS  {"_Agent_OnUnload@4", "Agent_OnUnload"}
-#define AGENT_ONATTACH_SYMBOLS  {"_Agent_OnAttach@12", "Agent_OnAttach"}
-
-#define JNI_LIB_PREFIX ""
-#define JNI_LIB_SUFFIX ".dll"
-
-struct dirent {
-    char d_name[MAX_PATH];
-};
-
-typedef struct {
-    struct dirent dirent;
-    char *path;
-    HANDLE handle;
-    WIN32_FIND_DATA find_data;
-} DIR;
-
-#include <stdlib.h>
-
-#define JVM_MAXPATHLEN _MAX_PATH
-
-#define JVM_R_OK    4
-#define JVM_W_OK    2
-#define JVM_X_OK    1
-#define JVM_F_OK    0
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-JNIEXPORT void * JNICALL
-JVM_GetThreadInterruptEvent();
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif /* __cplusplus */
-
-/*
- * File I/O
- */
-
-#include <sys/stat.h>
-
-/* O Flags */
-
-#define JVM_O_RDONLY     O_RDONLY
-#define JVM_O_WRONLY     O_WRONLY
-#define JVM_O_RDWR       O_RDWR
-#define JVM_O_O_APPEND   O_APPEND
-#define JVM_O_EXCL       O_EXCL
-#define JVM_O_CREAT      O_CREAT
-
-/* Signals */
-
-#define JVM_SIGINT     SIGINT
-#define JVM_SIGTERM    SIGTERM
-
-#define SHUTDOWN1_SIGNAL SIGINT            /* Shutdown Hooks support.    */
-#define SHUTDOWN2_SIGNAL SIGTERM
-
-#endif /* !_JAVASOFT_JVM_MD_H_ */
-
-#endif // OS_WINDOWS_VM_JVM_WINDOWS_H
--- a/src/hotspot/os/windows/os_windows.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/windows/os_windows.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -26,6 +26,7 @@
 #define _WIN32_WINNT 0x0600
 
 // no precompiled headers
+#include "jvm.h"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
@@ -34,7 +35,6 @@
 #include "compiler/compileBroker.hpp"
 #include "compiler/disassembler.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_windows.h"
 #include "logging/log.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
@@ -42,7 +42,6 @@
 #include "os_share_windows.hpp"
 #include "os_windows.inline.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/atomic.hpp"
@@ -100,6 +99,7 @@
 #include <imagehlp.h>             // For os::dll_address_to_function_name
 // for enumerating dll libraries
 #include <vdmdbg.h>
+#include <psapi.h>
 
 // for timer info max values which include all bits
 #define ALL_64_BITS CONST64(-1)
@@ -3656,7 +3656,7 @@
 
     static INIT_ONCE init_once_crit_sect = INIT_ONCE_STATIC_INIT;
     static CRITICAL_SECTION crit_sect;
-    static volatile jint process_exiting = 0;
+    static volatile DWORD process_exiting = 0;
     int i, j;
     DWORD res;
     HANDLE hproc, hthr;
@@ -3675,7 +3675,7 @@
       if (what != EPT_THREAD) {
         // Atomically set process_exiting before the critical section
         // to increase the visibility between racing threads.
-        Atomic::cmpxchg((jint)GetCurrentThreadId(), &process_exiting, 0);
+        Atomic::cmpxchg(GetCurrentThreadId(), &process_exiting, (DWORD)0);
       }
       EnterCriticalSection(&crit_sect);
 
@@ -3793,7 +3793,7 @@
 
     if (!registered &&
         OrderAccess::load_acquire(&process_exiting) != 0 &&
-        process_exiting != (jint)GetCurrentThreadId()) {
+        process_exiting != GetCurrentThreadId()) {
       // Some other thread is about to call exit(), so we don't let
       // the current unregistered thread proceed to exit() or _endthreadex()
       while (true) {
--- a/src/hotspot/os/windows/threadCritical_windows.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os/windows/threadCritical_windows.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -36,7 +36,7 @@
 //
 
 static bool initialized = false;
-static volatile jint lock_count = -1;
+static volatile int lock_count = -1;
 static HANDLE lock_event;
 static DWORD lock_owner = -1;
 
--- a/src/hotspot/os_cpu/aix_ppc/os_aix_ppc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/aix_ppc/os_aix_ppc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -24,6 +24,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "asm/assembler.inline.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -32,12 +33,10 @@
 #include "code/icBuffer.hpp"
 #include "code/vtableStubs.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_aix.h"
 #include "memory/allocation.inline.hpp"
 #include "nativeInst_ppc.hpp"
 #include "os_share_aix.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "porting_aix.hpp"
 #include "runtime/arguments.hpp"
--- a/src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "asm/macroAssembler.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -31,11 +32,9 @@
 #include "code/icBuffer.hpp"
 #include "code/vtableStubs.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_bsd.h"
 #include "memory/allocation.inline.hpp"
 #include "os_share_bsd.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/extendedPC.hpp"
--- a/src/hotspot/os_cpu/bsd_x86/thread_bsd_x86.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/bsd_x86/thread_bsd_x86.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -73,7 +73,7 @@
 
     frame ret_frame(ret_sp, ret_fp, addr.pc());
     if (!ret_frame.safe_for_sender(jt)) {
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
       // C2 and JVMCI use ebp as a general register see if NULL fp helps
       frame ret_frame2(ret_sp, NULL, addr.pc());
       if (!ret_frame2.safe_for_sender(jt)) {
@@ -84,7 +84,7 @@
 #else
       // nothing else to try if the frame isn't good
       return false;
-#endif /* COMPILER2 || INCLUDE_JVMCI */
+#endif // COMPILER2_OR_JVMCI
     }
     *fr_addr = ret_frame;
     return true;
--- a/src/hotspot/os_cpu/bsd_zero/os_bsd_zero.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/bsd_zero/os_bsd_zero.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -29,6 +29,7 @@
 #endif
 
 // no precompiled headers
+#include "jvm.h"
 #include "assembler_zero.inline.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -36,12 +37,10 @@
 #include "code/icBuffer.hpp"
 #include "code/vtableStubs.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_bsd.h"
 #include "memory/allocation.inline.hpp"
 #include "nativeInst_zero.hpp"
 #include "os_share_bsd.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/extendedPC.hpp"
--- a/src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -24,6 +24,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "asm/macroAssembler.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -33,11 +34,9 @@
 #include "code/vtableStubs.hpp"
 #include "code/nativeInst.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_linux.h"
 #include "memory/allocation.inline.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/extendedPC.hpp"
@@ -234,8 +233,17 @@
 }
 
 intptr_t* _get_previous_fp() {
-  register intptr_t **ebp __asm__ (SPELL_REG_FP);
-  return (intptr_t*) *ebp;   // we want what it points to.
+  register intptr_t **fp __asm__ (SPELL_REG_FP);
+
+  // fp is for this frame (_get_previous_fp). We want the fp for the
+  // caller of os::current_frame*(), so go up two frames. However, for
+  // optimized builds, _get_previous_fp() will be inlined, so only go
+  // up 1 frame in that case.
+  #ifdef _NMT_NOINLINE_
+    return **(intptr_t***)fp;
+  #else
+    return *fp;
+  #endif
 }
 
 
--- a/src/hotspot/os_cpu/linux_arm/os_linux_arm.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/linux_arm/os_linux_arm.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "assembler_arm.inline.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -30,12 +31,10 @@
 #include "code/icBuffer.hpp"
 #include "code/vtableStubs.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_linux.h"
 #include "memory/allocation.inline.hpp"
 #include "nativeInst_arm.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/extendedPC.hpp"
--- a/src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -24,6 +24,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "asm/assembler.inline.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -32,12 +33,10 @@
 #include "code/icBuffer.hpp"
 #include "code/vtableStubs.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_linux.h"
 #include "memory/allocation.inline.hpp"
 #include "nativeInst_ppc.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/extendedPC.hpp"
--- a/src/hotspot/os_cpu/linux_s390/os_linux_s390.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/linux_s390/os_linux_s390.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -26,6 +26,7 @@
 // This file is organized as os_linux_x86.cpp.
 
 // no precompiled headers
+#include "jvm.h"
 #include "asm/assembler.inline.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -35,12 +36,10 @@
 #include "code/vtableStubs.hpp"
 #include "compiler/disassembler.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_linux.h"
 #include "memory/allocation.inline.hpp"
 #include "nativeInst_s390.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/extendedPC.hpp"
--- a/src/hotspot/os_cpu/linux_sparc/os_linux_sparc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/linux_sparc/os_linux_sparc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "asm/macroAssembler.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -31,12 +32,10 @@
 #include "code/icBuffer.hpp"
 #include "code/vtableStubs.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_linux.h"
 #include "memory/allocation.inline.hpp"
 #include "nativeInst_sparc.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/extendedPC.hpp"
--- a/src/hotspot/os_cpu/linux_sparc/vm_version_linux_sparc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/linux_sparc/vm_version_linux_sparc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,58 +27,326 @@
 #include "runtime/os.hpp"
 #include "vm_version_sparc.hpp"
 
-static bool cpuinfo_field_contains(const char* field, const char* value) {
-  char line[1024];
-  bool rv = false;
+
+#define CPUINFO_LINE_SIZE 1024
+
+
+class CPUinfo {
+public:
+  CPUinfo(const char* field) : _string(NULL) {
+
+    char line[CPUINFO_LINE_SIZE];
+    FILE* fp = fopen("/proc/cpuinfo", "r");
 
-  FILE* fp = fopen("/proc/cpuinfo", "r");
-  if (fp == NULL) {
-    return rv;
-  }
+    if (fp != NULL) {
+      while (fgets(line, sizeof(line), fp) != NULL) {
+        assert(strlen(line) < sizeof(line) - 1,
+               "buffer too small (%d)", CPUINFO_LINE_SIZE);
+
+        const char* vstr = match_field(line, field);
 
-  while (fgets(line, sizeof(line), fp) != NULL) {
-    assert(strlen(line) < sizeof(line) - 1, "buffer line[1024] is too small.");
-    if (strncmp(line, field, strlen(field)) == 0) {
-      if (strstr(line, value) != NULL) {
-        rv = true;
+        if (vstr != NULL) {
+          // We have a matching line and a valid starting point to the value of
+          // the field, copy the string for keeps.
+          _string = strdup(vstr);
+          break;
+        }
       }
-      break;
+      fclose(fp);
     }
   }
 
-  fclose(fp);
-  return rv;
+  ~CPUinfo() { os::free((void*)_string); }
+
+  const char* value() const { return _string; }
+
+  bool valid() const { return _string != NULL; }
+
+  bool match(const char* s) const {
+    return valid() ? strcmp(_string, s) == 0 : false;
+  }
+
+private:
+  const char* _string;
+
+  const char* match_field(char line[CPUINFO_LINE_SIZE], const char* field);
+  const char* match_alo(const char* text, const char* exp);
+  const char* match_seq(const char* text, const char* seq);
+};
+
+/* Given a line of text read from /proc/cpuinfo, determine if the property header
+ * matches the field specified, according to the following regexp: "<field>"\W+:\W+
+ *
+ * If we have a matching expression, return a pointer to the first character after
+ * the matching pattern, i.e. the "value", otherwise return NULL.
+ */
+const char* CPUinfo::match_field(char line[CPUINFO_LINE_SIZE], const char* field) {
+  return match_alo(match_seq(match_alo(match_seq(line, field), "\t "), ":"), "\t ");
 }
 
-static bool detect_niagara() {
-  return cpuinfo_field_contains("cpu", "Niagara");
+/* Match a sequence of at-least-one character in the string expression (exp) to
+ * the text input.
+ */
+const char* CPUinfo::match_alo(const char* text, const char* exp) {
+  if (text == NULL) return NULL;
+
+  const char* chp;
+
+  for (chp = &text[0]; *chp != '\0'; chp++) {
+    if (strchr(exp, *chp) == NULL) break;
+  }
+
+  return text < chp ? chp : NULL;
 }
 
-static bool detect_M_family() {
-  return cpuinfo_field_contains("cpu", "SPARC-M");
-}
+/* Match an exact sequence of characters as specified by the string expression
+ * (seq) to the text input.
+ */
+const char* CPUinfo::match_seq(const char* text, const char* seq) {
+  if (text == NULL) return NULL;
 
-static bool detect_blkinit() {
-  return cpuinfo_field_contains("cpucaps", "blkinit");
+  while (*seq != '\0') {
+    if (*seq != *text++) break; else seq++;
+  }
+
+  return *seq == '\0' ? text : NULL;
 }
 
-int VM_Version::platform_features(int features) {
-  // Default to generic v9
-  features = generic_v9_m;
+
+typedef struct {
+  const uint32_t    hash;
+  bool              seen;
+  const char* const name;
+  const uint64_t    mask;
+} FeatureEntry;
+
+
+static uint64_t parse_features(FeatureEntry feature_tbl[], const char input[]);
+
+
+void VM_Version::platform_features() {
+
+  // Some of the features reported via "cpucaps", such as; 'flush', 'stbar',
+  // 'swap', 'muldiv', 'ultra3', 'blkinit', 'n2', 'mul32', 'div32', 'fsmuld'
+  // and 'v8plus', are either SPARC V8, supported by all HW or simply nonsense
+  // (the 'ultra3' "property").
+  //
+  // Entries marked as 'NYI' are not yet supported via "cpucaps" but are
+  // expected to have the names used in the table below (these are SPARC M7
+  // features or more recent).
+  //
+  // NOTE: Table sorted on lookup/hash ID.
 
-  if (detect_niagara()) {
-    log_info(os, cpu)("Detected Linux on Niagara");
-    features = niagara1_m | T_family_m;
+  static FeatureEntry s_feature_tbl[] = {
+    { 0x006f, false, "v9",         ISA_v9_msk },            // Mandatory
+    { 0x00a6, false, "md5",        ISA_md5_msk },
+    { 0x00ce, false, "adi",        ISA_adi_msk },           // NYI
+    { 0x00d7, false, "ima",        ISA_ima_msk },
+    { 0x00d9, false, "aes",        ISA_aes_msk },
+    { 0x00db, false, "hpc",        ISA_hpc_msk },
+    { 0x00dc, false, "des",        ISA_des_msk },
+    { 0x00ed, false, "sha1",       ISA_sha1_msk },
+    { 0x00f2, false, "vis",        ISA_vis1_msk },
+    { 0x0104, false, "vis2",       ISA_vis2_msk },
+    { 0x0105, false, "vis3",       ISA_vis3_msk },
+    { 0x0114, false, "sha512",     ISA_sha512_msk },
+    { 0x0119, false, "sha256",     ISA_sha256_msk },
+    { 0x011a, false, "fmaf",       ISA_fmaf_msk },
+    { 0x0132, false, "popc",       ISA_popc_msk },
+    { 0x0140, false, "crc32c",     ISA_crc32c_msk },
+    { 0x0147, false, "vis3b",      ISA_vis3b_msk },         // NYI
+    { 0x017e, false, "pause",      ISA_pause_msk },
+    { 0x0182, false, "mwait",      ISA_mwait_msk },         // NYI
+    { 0x018b, false, "mpmul",      ISA_mpmul_msk },
+    { 0x018e, false, "sparc5",     ISA_sparc5_msk },        // NYI
+    { 0x01a9, false, "cbcond",     ISA_cbcond_msk },
+    { 0x01c3, false, "vamask",     ISA_vamask_msk },        // NYI
+    { 0x01ca, false, "kasumi",     ISA_kasumi_msk },
+    { 0x01e3, false, "xmpmul",     ISA_xmpmul_msk },        // NYI
+    { 0x022c, false, "montmul",    ISA_mont_msk },
+    { 0x0234, false, "montsqr",    ISA_mont_msk },
+    { 0x0238, false, "camellia",   ISA_camellia_msk },
+    { 0x024a, false, "ASIBlkInit", ISA_blk_init_msk },
+    { 0x0284, false, "xmontmul",   ISA_xmont_msk },         // NYI
+    { 0x02e6, false, "pause_nsec", ISA_pause_nsec_msk },    // NYI
+
+    { 0x0000, false, NULL, 0 }
+  };
+
+  CPUinfo caps("cpucaps");      // Read "cpucaps" from /proc/cpuinfo.
+
+  assert(caps.valid(), "must be");
+
+  _features = parse_features(s_feature_tbl, caps.value());
+
+  assert(has_v9(), "must be");  // Basic SPARC-V9 required (V8 not supported).
+
+  CPUinfo type("type");
+
+  bool is_sun4v = type.match("sun4v");   // All Oracle SPARC + Fujitsu Athena+
+  bool is_sun4u = type.match("sun4u");   // All other Fujitsu
+
+  uint64_t synthetic = 0;
+
+  if (is_sun4v) {
+    // Indirect and direct branches are equally fast.
+    synthetic = CPU_fast_ind_br_msk;
+    // Fast IDIV, BIS and LD available on Niagara Plus.
+    if (has_vis2()) {
+      synthetic |= (CPU_fast_idiv_msk | CPU_fast_ld_msk);
+      // ...on Core C4 however, we prefer not to use BIS.
+      if (!has_sparc5()) {
+        synthetic |= CPU_fast_bis_msk;
+      }
+    }
+    // Niagara Core C3 supports fast RDPC and block zeroing.
+    if (has_ima()) {
+      synthetic |= (CPU_fast_rdpc_msk | CPU_blk_zeroing_msk);
+    }
+    // Niagara Core C3 and C4 have slow CMOVE.
+    if (!has_ima()) {
+      synthetic |= CPU_fast_cmove_msk;
+    }
+  } else if (is_sun4u) {
+    // SPARC64 only have fast IDIV and RDPC.
+    synthetic |= (CPU_fast_idiv_msk | CPU_fast_rdpc_msk);
+  } else {
+    log_info(os, cpu)("Unable to derive CPU features: %s", type.value());
   }
 
-  if (detect_M_family()) {
-    log_info(os, cpu)("Detected Linux on M family");
-    features = sun4v_m | generic_v9_m | M_family_m | T_family_m;
+  _features += synthetic;   // Including CPU derived/synthetic features.
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+
+static uint32_t uhash32(const char name[]);
+
+static void update_table(FeatureEntry feature_tbl[], uint32_t hv,
+                         const char* ch1p,
+                         const char* endp);
+
+/* Given a feature table, parse the input text holding the string value of
+ * 'cpucaps' as reported by '/proc/cpuinfo', in order to complete the table
+ * with information on each admissible feature (whether present or not).
+ *
+ * Return the composite bit-mask representing the features found.
+ */
+static uint64_t parse_features(FeatureEntry feature_tbl[], const char input[]) {
+  log_info(os, cpu)("Parse CPU features: %s\n", input);
+
+#ifdef ASSERT
+  // Verify that hash value entries in the table are unique and ordered.
+
+  uint32_t prev = 0;
+
+  for (uint k = 0; feature_tbl[k].name != NULL; k++) {
+    feature_tbl[k].seen = false;
+
+    assert(feature_tbl[k].hash == uhash32(feature_tbl[k].name),
+           "feature '%s' has mismatching hash 0x%08x (expected 0x%08x).\n",
+           feature_tbl[k].name,
+           feature_tbl[k].hash,
+           uhash32(feature_tbl[k].name));
+
+    assert(prev < feature_tbl[k].hash,
+           "feature '%s' has invalid hash 0x%08x (previous is 0x%08x).\n",
+           feature_tbl[k].name,
+           feature_tbl[k].hash,
+           prev);
+
+    prev = feature_tbl[k].hash;
+  }
+#endif
+  // Identify features from the input, consisting of a string with features
+  // separated by commas (or whitespace), e.g. "flush,muldiv,v9,mul32,div32,
+  // v8plus,popc,vis".
+
+  uint32_t hv = 0;
+  const char* ch1p = &input[0];
+  uint i = 0;
+
+  do {
+    char ch = input[i];
+
+    if (isalnum(ch) || ch == '_') {
+      hv += (ch - 32u);
+    }
+    else if (isspace(ch) || ch == ',' || ch == '\0') { // end-of-token
+      if (ch1p < &input[i]) {
+        update_table(feature_tbl, hv, ch1p, &input[i]);
+      }
+      ch1p = &input[i + 1]; hv = 0;
+    } else {
+      // Handle non-accepted input robustly.
+      log_info(os, cpu)("Bad token in feature string: '%c' (0x%02x).\n", ch, ch);
+      ch1p = &input[i + 1]; hv = 0;
+    }
+  }
+  while (input[i++] != '\0');
+
+  // Compute actual bit-mask representation.
+
+  uint64_t mask = 0;
+
+  for (uint k = 0; feature_tbl[k].name != NULL; k++) {
+    mask |= feature_tbl[k].seen ? feature_tbl[k].mask : 0;
   }
 
-  if (detect_blkinit()) {
-    features |= blk_init_instructions_m;
+  return mask;
+}
+
+static uint32_t uhash32(const char name[]) {
+  uint32_t hv = 0;
+
+  for (uint i = 0; name[i] != '\0'; i++) {
+    hv += (name[i] - 32u);
   }
 
-  return features;
+  return hv;
 }
+
+static bool verify_match(const char name[], const char* ch1p, const char* endp);
+
+static void update_table(FeatureEntry feature_tbl[], uint32_t hv, const char* ch1p, const char* endp) {
+  assert(ch1p < endp, "at least one character");
+
+  // Look for a hash value in the table. Since this table is a small one (and
+  // is expected to stay small), we use a simple linear search (iff the table
+  // grows large, we may consider to adopt a binary ditto, or a perfect hash).
+
+  for (uint k = 0; feature_tbl[k].name != NULL; k++) {
+    uint32_t hash = feature_tbl[k].hash;
+
+    if (hash < hv) continue;
+
+    if (hash == hv) {
+      const char* name = feature_tbl[k].name;
+
+      if (verify_match(name, ch1p, endp)) {
+        feature_tbl[k].seen = true;
+        break;
+      }
+    }
+
+    // Either a non-matching feature (when hash == hv) or hash > hv. In either
+    // case we break out of the loop and terminate the search (note that the
+    // table is assumed to be uniquely sorted on the hash).
+
+    break;
+  }
+}
+
+static bool verify_match(const char name[], const char* ch1p, const char* endp) {
+  size_t len = strlen(name);
+
+  if (len != static_cast<size_t>(endp - ch1p)) {
+    return false;
+  }
+
+  for (uint i = 0; ch1p + i < endp; i++) {
+    if (name[i] != ch1p[i]) return false;
+  }
+
+  return true;
+}
--- a/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "asm/macroAssembler.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -31,11 +32,9 @@
 #include "code/icBuffer.hpp"
 #include "code/vtableStubs.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_linux.h"
 #include "memory/allocation.inline.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/extendedPC.hpp"
--- a/src/hotspot/os_cpu/linux_x86/thread_linux_x86.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/linux_x86/thread_linux_x86.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -74,7 +74,7 @@
 
     frame ret_frame(ret_sp, ret_fp, addr.pc());
     if (!ret_frame.safe_for_sender(jt)) {
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
       // C2 and JVMCI use ebp as a general register see if NULL fp helps
       frame ret_frame2(ret_sp, NULL, addr.pc());
       if (!ret_frame2.safe_for_sender(jt)) {
@@ -85,7 +85,7 @@
 #else
       // nothing else to try if the frame isn't good
       return false;
-#endif /* COMPILER2 || INCLUDE_JVMCI */
+#endif // COMPILER2_OR_JVMCI
     }
     *fr_addr = ret_frame;
     return true;
--- a/src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -24,6 +24,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "assembler_zero.inline.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -31,12 +32,10 @@
 #include "code/icBuffer.hpp"
 #include "code/vtableStubs.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_linux.h"
 #include "memory/allocation.inline.hpp"
 #include "nativeInst_zero.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/extendedPC.hpp"
--- a/src/hotspot/os_cpu/solaris_sparc/os_solaris_sparc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/solaris_sparc/os_solaris_sparc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "asm/macroAssembler.hpp"
 #include "macroAssembler_sparc.hpp"
 #include "classfile/classLoader.hpp"
@@ -32,12 +33,10 @@
 #include "code/icBuffer.hpp"
 #include "code/vtableStubs.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_solaris.h"
 #include "memory/allocation.inline.hpp"
 #include "nativeInst_sparc.hpp"
 #include "os_share_solaris.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/extendedPC.hpp"
--- a/src/hotspot/os_cpu/solaris_x86/os_solaris_x86.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/solaris_x86/os_solaris_x86.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "asm/macroAssembler.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -31,11 +32,9 @@
 #include "code/icBuffer.hpp"
 #include "code/vtableStubs.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_solaris.h"
 #include "memory/allocation.inline.hpp"
 #include "os_share_solaris.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/atomic.hpp"
--- a/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 // no precompiled headers
+#include "jvm.h"
 #include "asm/macroAssembler.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -30,13 +31,11 @@
 #include "code/icBuffer.hpp"
 #include "code/vtableStubs.hpp"
 #include "interpreter/interpreter.hpp"
-#include "jvm_windows.h"
 #include "memory/allocation.inline.hpp"
 #include "memory/resourceArea.hpp"
 #include "nativeInst_x86.hpp"
 #include "os_share_windows.hpp"
 #include "prims/jniFastGetField.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/extendedPC.hpp"
--- a/src/hotspot/os_cpu/windows_x86/thread_windows_x86.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/os_cpu/windows_x86/thread_windows_x86.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -81,7 +81,7 @@
 
     frame ret_frame(ret_sp, ret_fp, addr.pc());
     if (!ret_frame.safe_for_sender(jt)) {
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
       // C2 and JVMCI use ebp as a general register see if NULL fp helps
       frame ret_frame2(ret_sp, NULL, addr.pc());
       if (!ret_frame2.safe_for_sender(jt)) {
@@ -92,7 +92,7 @@
 #else
       // nothing else to try if the frame isn't good
       return false;
-#endif /* COMPILER2 || INCLUDE_JVMCI */
+#endif // COMPILER2_OR_JVMCI
     }
     *fr_addr = ret_frame;
     return true;
--- a/src/hotspot/share/aot/aotCodeHeap.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/aot/aotCodeHeap.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -490,6 +490,8 @@
 
     SET_AOT_GLOBAL_SYMBOL_VALUE("_aot_stub_routines_checkcast_arraycopy", address, StubRoutines::_checkcast_arraycopy);
 
+    SET_AOT_GLOBAL_SYMBOL_VALUE("_aot_stub_routines_generic_arraycopy", address, StubRoutines::_generic_arraycopy);
+
     SET_AOT_GLOBAL_SYMBOL_VALUE("_aot_stub_routines_aescrypt_encryptBlock", address, StubRoutines::_aescrypt_encryptBlock);
     SET_AOT_GLOBAL_SYMBOL_VALUE("_aot_stub_routines_aescrypt_decryptBlock", address, StubRoutines::_aescrypt_decryptBlock);
     SET_AOT_GLOBAL_SYMBOL_VALUE("_aot_stub_routines_cipherBlockChaining_encryptAESCrypt", address, StubRoutines::_cipherBlockChaining_encryptAESCrypt);
--- a/src/hotspot/share/aot/aotLoader.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/aot/aotLoader.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -22,12 +22,12 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 
 #include "aot/aotCodeHeap.hpp"
 #include "aot/aotLoader.inline.hpp"
 #include "jvmci/jvmciRuntime.hpp"
 #include "oops/method.hpp"
-#include "prims/jvm.h"
 #include "runtime/os.hpp"
 #include "runtime/timerTrace.hpp"
 
--- a/src/hotspot/share/c1/c1_CFGPrinter.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/c1/c1_CFGPrinter.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,13 +23,13 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "c1/c1_CFGPrinter.hpp"
 #include "c1/c1_IR.hpp"
 #include "c1/c1_InstructionPrinter.hpp"
 #include "c1/c1_LIR.hpp"
 #include "c1/c1_LinearScan.hpp"
 #include "c1/c1_ValueStack.hpp"
-#include "prims/jvm.h"
 
 #ifndef PRODUCT
 
--- a/src/hotspot/share/c1/c1_Canonicalizer.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/c1/c1_Canonicalizer.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -40,6 +40,10 @@
   void set_constant(jlong x)                     { set_canonical(new Constant(new LongConstant(x))); }
   void set_constant(jfloat x)                    { set_canonical(new Constant(new FloatConstant(x))); }
   void set_constant(jdouble x)                   { set_canonical(new Constant(new DoubleConstant(x))); }
+#ifdef _WINDOWS
+  // jint is defined as long in jni_md.h, so convert from int to jint
+  void set_constant(int x)                       { set_constant((jint)x); }
+#endif
   void move_const_to_right(Op2* x);
   void do_Op2(Op2* x);
   void do_UnsafeRawOp(UnsafeRawOp* x);
--- a/src/hotspot/share/c1/c1_Compiler.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/c1/c1_Compiler.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -213,7 +213,7 @@
   case vmIntrinsics::_updateCRC32:
   case vmIntrinsics::_updateBytesCRC32:
   case vmIntrinsics::_updateByteBufferCRC32:
-#if defined(SPARC) || defined(S390) || defined(PPC64)
+#if defined(SPARC) || defined(S390) || defined(PPC64) || defined(AARCH64)
   case vmIntrinsics::_updateBytesCRC32C:
   case vmIntrinsics::_updateDirectByteBufferCRC32C:
 #endif
--- a/src/hotspot/share/c1/c1_LinearScan.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/c1/c1_LinearScan.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -2507,7 +2507,7 @@
 // use).
 ConstantOopWriteValue* LinearScan::_oop_null_scope_value = new (ResourceObj::C_HEAP, mtCompiler) ConstantOopWriteValue(NULL);
 ConstantIntValue*      LinearScan::_int_m1_scope_value = new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue(-1);
-ConstantIntValue*      LinearScan::_int_0_scope_value =  new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue(0);
+ConstantIntValue*      LinearScan::_int_0_scope_value =  new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue((jint)0);
 ConstantIntValue*      LinearScan::_int_1_scope_value =  new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue(1);
 ConstantIntValue*      LinearScan::_int_2_scope_value =  new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue(2);
 LocationValue*         _illegal_value = new (ResourceObj::C_HEAP, mtCompiler) LocationValue(Location());
--- a/src/hotspot/share/ci/ciEnv.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/ci/ciEnv.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "ci/ciConstant.hpp"
 #include "ci/ciEnv.hpp"
 #include "ci/ciField.hpp"
@@ -49,7 +50,6 @@
 #include "oops/objArrayKlass.hpp"
 #include "oops/objArrayOop.inline.hpp"
 #include "oops/oop.inline.hpp"
-#include "prims/jvm.h"
 #include "prims/jvmtiExport.hpp"
 #include "runtime/init.hpp"
 #include "runtime/reflection.hpp"
--- a/src/hotspot/share/ci/ciFlags.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/ci/ciFlags.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -25,9 +25,9 @@
 #ifndef SHARE_VM_CI_CIFLAGS_HPP
 #define SHARE_VM_CI_CIFLAGS_HPP
 
+#include "jvm.h"
 #include "ci/ciClassList.hpp"
 #include "memory/allocation.hpp"
-#include "prims/jvm.h"
 #include "utilities/accessFlags.hpp"
 #include "utilities/ostream.hpp"
 
--- a/src/hotspot/share/ci/ciReplay.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/ci/ciReplay.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "ci/ciMethodData.hpp"
 #include "ci/ciReplay.hpp"
 #include "ci/ciSymbol.hpp"
@@ -33,7 +34,6 @@
 #include "memory/oopFactory.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/oop.inline.hpp"
-#include "prims/jvm.h"
 #include "utilities/copy.hpp"
 #include "utilities/macros.hpp"
 
@@ -790,7 +790,7 @@
         while (field_signature[rank] == '[') {
           rank++;
         }
-        int* dims = NEW_RESOURCE_ARRAY(int, rank);
+        jint* dims = NEW_RESOURCE_ARRAY(jint, rank);
         dims[0] = length;
         for (int i = 1; i < rank; i++) {
           dims[i] = 1; // These aren't relevant to the compiler
--- a/src/hotspot/share/classfile/altHashing.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/altHashing.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -42,15 +42,15 @@
 juint AltHashing::compute_seed() {
   jlong nanos = os::javaTimeNanos();
   jlong now = os::javaTimeMillis();
-  int SEED_MATERIAL[8] = {
-            (int) object_hash(SystemDictionary::String_klass()),
-            (int) object_hash(SystemDictionary::System_klass()),
-            os::random(),  // current thread isn't a java thread
-            (int) (((julong)nanos) >> 32),
-            (int) nanos,
-            (int) (((julong)now) >> 32),
-            (int) now,
-            (int) (os::javaTimeNanos() >> 2)
+  jint SEED_MATERIAL[8] = {
+            (jint) object_hash(SystemDictionary::String_klass()),
+            (jint) object_hash(SystemDictionary::System_klass()),
+            (jint) os::random(),  // current thread isn't a java thread
+            (jint) (((julong)nanos) >> 32),
+            (jint) nanos,
+            (jint) (((julong)now) >> 32),
+            (jint) now,
+            (jint) (os::javaTimeNanos() >> 2)
   };
 
   return murmur3_32(SEED_MATERIAL, 8);
@@ -167,7 +167,7 @@
 }
 
 // Hash used for the seed.
-juint AltHashing::murmur3_32(juint seed, const int* data, int len) {
+juint AltHashing::murmur3_32(juint seed, const jint* data, int len) {
   juint h1 = seed;
 
   int off = 0;
@@ -202,6 +202,6 @@
   return h1;
 }
 
-juint AltHashing::murmur3_32(const int* data, int len) {
+juint AltHashing::murmur3_32(const jint* data, int len) {
   return murmur3_32(0, data, len);
 }
--- a/src/hotspot/share/classfile/altHashing.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/altHashing.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -43,8 +43,8 @@
   static juint Integer_rotateLeft(juint i, int distance) {
     return (i << distance) | (i >> (32 - distance));
   }
-  static juint murmur3_32(const int* data, int len);
-  static juint murmur3_32(juint seed, const int* data, int len);
+  static juint murmur3_32(const jint* data, int len);
+  static juint murmur3_32(juint seed, const jint* data, int len);
 
  public:
   static juint compute_seed();
--- a/src/hotspot/share/classfile/classFileParser.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -22,6 +22,7 @@
  *
  */
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "aot/aotLoader.hpp"
 #include "classfile/classFileParser.hpp"
 #include "classfile/classFileStream.hpp"
@@ -54,7 +55,6 @@
 #include "oops/method.hpp"
 #include "oops/oop.inline.hpp"
 #include "oops/symbol.hpp"
-#include "prims/jvm.h"
 #include "prims/jvmtiExport.hpp"
 #include "prims/jvmtiThreadState.hpp"
 #include "runtime/javaCalls.hpp"
--- a/src/hotspot/share/classfile/classLoader.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/classLoader.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "classfile/classFileStream.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/classLoaderData.inline.hpp"
@@ -53,7 +54,6 @@
 #include "oops/objArrayOop.inline.hpp"
 #include "oops/oop.inline.hpp"
 #include "oops/symbol.hpp"
-#include "prims/jvm.h"
 #include "prims/jvm_misc.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/compilationPolicy.hpp"
--- a/src/hotspot/share/classfile/classLoaderData.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/classLoaderData.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -604,40 +604,27 @@
 
 const int _boot_loader_dictionary_size    = 1009;
 const int _default_loader_dictionary_size = 107;
-const int _prime_array_size         = 8;                       // array of primes for system dictionary size
-const int _average_depth_goal       = 3;                       // goal for lookup length
-const int _primelist[_prime_array_size] = {107, 1009, 2017, 4049, 5051, 10103, 20201, 40423};
-
-// Calculate a "good" dictionary size based
-// on predicted or current loaded classes count.
-static int calculate_dictionary_size(int classcount) {
-  int newsize = _primelist[0];
-  if (classcount > 0 && !DumpSharedSpaces) {
-    int index = 0;
-    int desiredsize = classcount/_average_depth_goal;
-    for (newsize = _primelist[index]; index < _prime_array_size -1;
-         newsize = _primelist[++index]) {
-      if (desiredsize <=  newsize) {
-        break;
-      }
-    }
-  }
-  return newsize;
-}
 
 Dictionary* ClassLoaderData::create_dictionary() {
   assert(!is_anonymous(), "anonymous class loader data do not have a dictionary");
   int size;
+  bool resizable = false;
   if (_the_null_class_loader_data == NULL) {
     size = _boot_loader_dictionary_size;
+    resizable = true;
   } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
     size = 1;  // there's only one class in relection class loader and no initiated classes
   } else if (is_system_class_loader_data()) {
-    size = calculate_dictionary_size(PredictedLoadedClassCount);
+    size = _boot_loader_dictionary_size;
+    resizable = true;
   } else {
     size = _default_loader_dictionary_size;
+    resizable = true;
   }
-  return new Dictionary(this, size);
+  if (!DynamicallyResizeSystemDictionaries || DumpSharedSpaces || UseSharedSpaces) {
+    resizable = false;
+  }
+  return new Dictionary(this, size, resizable);
 }
 
 // Unloading support
@@ -1325,6 +1312,19 @@
   }
 }
 
+int ClassLoaderDataGraph::resize_if_needed() {
+  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
+  int resized = 0;
+  if (Dictionary::does_any_dictionary_needs_resizing()) {
+    FOR_ALL_DICTIONARY(cld) {
+      if (cld->dictionary()->resize_if_needed()) {
+        resized++;
+      }
+    }
+  }
+  return resized;
+}
+
 void ClassLoaderDataGraph::post_class_unload_events() {
 #if INCLUDE_TRACE
   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
--- a/src/hotspot/share/classfile/classLoaderData.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/classLoaderData.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -143,6 +143,8 @@
     }
   }
 
+  static int resize_if_needed();
+
   static bool has_metaspace_oom()           { return _metaspace_oom; }
   static void set_metaspace_oom(bool value) { _metaspace_oom = value; }
 
--- a/src/hotspot/share/classfile/compactHashtable.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/compactHashtable.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,12 +23,12 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "classfile/compactHashtable.inline.hpp"
 #include "classfile/javaClasses.hpp"
 #include "logging/logMessage.hpp"
 #include "memory/metadataFactory.hpp"
 #include "memory/metaspaceShared.hpp"
-#include "prims/jvm.h"
 #include "runtime/vmThread.hpp"
 #include "utilities/numberSeq.hpp"
 #include <sys/stat.h>
--- a/src/hotspot/share/classfile/dictionary.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/dictionary.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -29,6 +29,7 @@
 #include "classfile/protectionDomainCache.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/systemDictionaryShared.hpp"
+#include "gc/shared/gcLocker.hpp"
 #include "logging/log.hpp"
 #include "logging/logStream.hpp"
 #include "memory/iterator.hpp"
@@ -39,6 +40,11 @@
 #include "runtime/orderAccess.inline.hpp"
 #include "utilities/hashtable.inline.hpp"
 
+// Optimization: if any dictionary needs resizing, we set this flag,
+// so that we dont't have to walk all dictionaries to check if any actually
+// needs resizing, which is costly to do at Safepoint.
+bool Dictionary::_some_dictionary_needs_resizing = false;
+
 size_t Dictionary::entry_size() {
   if (DumpSharedSpaces) {
     return SystemDictionaryShared::dictionary_entry_size();
@@ -47,15 +53,17 @@
   }
 }
 
-Dictionary::Dictionary(ClassLoaderData* loader_data, int table_size)
-  : _loader_data(loader_data), Hashtable<InstanceKlass*, mtClass>(table_size, (int)entry_size()) {
+Dictionary::Dictionary(ClassLoaderData* loader_data, int table_size, bool resizable)
+  : _loader_data(loader_data), _resizable(resizable), _needs_resizing(false),
+  Hashtable<InstanceKlass*, mtClass>(table_size, (int)entry_size()) {
 };
 
 
 Dictionary::Dictionary(ClassLoaderData* loader_data,
                        int table_size, HashtableBucket<mtClass>* t,
-                       int number_of_entries)
-  : _loader_data(loader_data), Hashtable<InstanceKlass*, mtClass>(table_size, (int)entry_size(), t, number_of_entries) {
+                       int number_of_entries, bool resizable)
+  : _loader_data(loader_data), _resizable(resizable), _needs_resizing(false),
+  Hashtable<InstanceKlass*, mtClass>(table_size, (int)entry_size(), t, number_of_entries) {
 };
 
 Dictionary::~Dictionary() {
@@ -96,6 +104,60 @@
   FREE_C_HEAP_ARRAY(char, entry);
 }
 
+const int _resize_load_trigger = 5;       // load factor that will trigger the resize
+const double _resize_factor    = 2.0;     // by how much we will resize using current number of entries
+const int _resize_max_size     = 40423;   // the max dictionary size allowed
+const int _primelist[] = {107, 1009, 2017, 4049, 5051, 10103, 20201, _resize_max_size};
+const int _prime_array_size = sizeof(_primelist)/sizeof(int);
+
+// Calculate next "good" dictionary size based on requested count
+static int calculate_dictionary_size(int requested) {
+  int newsize = _primelist[0];
+  int index = 0;
+  for (newsize = _primelist[index]; index < (_prime_array_size - 1);
+       newsize = _primelist[++index]) {
+    if (requested <= newsize) {
+      break;
+    }
+  }
+  return newsize;
+}
+
+bool Dictionary::does_any_dictionary_needs_resizing() {
+  return Dictionary::_some_dictionary_needs_resizing;
+}
+
+void Dictionary::check_if_needs_resize() {
+  if (_resizable == true) {
+    if (number_of_entries() > (_resize_load_trigger*table_size())) {
+      _needs_resizing = true;
+      Dictionary::_some_dictionary_needs_resizing = true;
+    }
+  }
+}
+
+bool Dictionary::resize_if_needed() {
+  int desired_size = 0;
+  if (_needs_resizing == true) {
+    desired_size = calculate_dictionary_size((int)(_resize_factor*number_of_entries()));
+    if (desired_size >= _resize_max_size) {
+      desired_size = _resize_max_size;
+      // We have reached the limit, turn resizing off
+      _resizable = false;
+    }
+    if ((desired_size != 0) && (desired_size != table_size())) {
+      if (!resize(desired_size)) {
+        // Something went wrong, turn resizing off
+        _resizable = false;
+      }
+    }
+  }
+
+  _needs_resizing = false;
+  Dictionary::_some_dictionary_needs_resizing = false;
+
+  return (desired_size != 0);
+}
 
 bool DictionaryEntry::contains_protection_domain(oop protection_domain) const {
 #ifdef ASSERT
@@ -264,14 +326,16 @@
 // also cast to volatile;  we do this to ensure store order is maintained
 // by the compilers.
 
-void Dictionary::add_klass(int index, unsigned int hash, Symbol* class_name,
+void Dictionary::add_klass(unsigned int hash, Symbol* class_name,
                            InstanceKlass* obj) {
   assert_locked_or_safepoint(SystemDictionary_lock);
   assert(obj != NULL, "adding NULL obj");
   assert(obj->name() == class_name, "sanity check on name");
 
   DictionaryEntry* entry = new_entry(hash, obj);
+  int index = hash_to_index(hash);
   add_entry(index, entry);
+  check_if_needs_resize();
 }
 
 
@@ -299,8 +363,11 @@
 }
 
 
-InstanceKlass* Dictionary::find(int index, unsigned int hash, Symbol* name,
+InstanceKlass* Dictionary::find(unsigned int hash, Symbol* name,
                                 Handle protection_domain) {
+  NoSafepointVerifier nsv;
+
+  int index = hash_to_index(hash);
   DictionaryEntry* entry = get_entry(index, hash, name);
   if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
     return entry->instance_klass();
@@ -350,13 +417,24 @@
 }
 
 
-bool Dictionary::is_valid_protection_domain(int index, unsigned int hash,
+bool Dictionary::is_valid_protection_domain(unsigned int hash,
                                             Symbol* name,
                                             Handle protection_domain) {
+  int index = hash_to_index(hash);
   DictionaryEntry* entry = get_entry(index, hash, name);
   return entry->is_valid_protection_domain(protection_domain);
 }
 
+#if INCLUDE_CDS
+static bool is_jfr_event_class(Klass *k) {
+  while (k) {
+    if (k->name()->equals("jdk/jfr/Event")) {
+      return true;
+    }
+    k = k->super();
+  }
+  return false;
+}
 
 void Dictionary::reorder_dictionary_for_sharing() {
 
@@ -368,14 +446,22 @@
     while (p != NULL) {
       DictionaryEntry* next = p->next();
       InstanceKlass*ik = p->instance_klass();
-      // we cannot include signed classes in the archive because the certificates
-      // used during dump time may be different than those used during
-      // runtime (due to expiration, etc).
       if (ik->signers() != NULL) {
+        // We cannot include signed classes in the archive because the certificates
+        // used during dump time may be different than those used during
+        // runtime (due to expiration, etc).
         ResourceMark rm;
         tty->print_cr("Preload Warning: Skipping %s from signed JAR",
                        ik->name()->as_C_string());
         free_entry(p);
+      } else if (is_jfr_event_class(ik)) {
+        // We cannot include JFR event classes because they need runtime-specific
+        // instrumentation in order to work with -XX:FlightRecorderOptions=retransform=false.
+        // There are only a small number of these classes, so it's not worthwhile to
+        // support them and make CDS more complicated.
+        ResourceMark rm;
+        tty->print_cr("Skipping JFR event class %s", ik->name()->as_C_string());
+        free_entry(p);
       } else {
         p->set_next(master_list);
         master_list = p;
@@ -400,7 +486,7 @@
     set_entry(index, p);
   }
 }
-
+#endif
 
 SymbolPropertyTable::SymbolPropertyTable(int table_size)
   : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry))
--- a/src/hotspot/share/classfile/dictionary.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/dictionary.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -43,6 +43,11 @@
 class Dictionary : public Hashtable<InstanceKlass*, mtClass> {
   friend class VMStructs;
 
+  static bool _some_dictionary_needs_resizing;
+  bool _resizable;
+  bool _needs_resizing;
+  void check_if_needs_resize();
+
   ClassLoaderData* _loader_data;  // backpointer to owning loader
   ClassLoaderData* loader_data() const { return _loader_data; }
 
@@ -51,13 +56,16 @@
 protected:
   static size_t entry_size();
 public:
-  Dictionary(ClassLoaderData* loader_data, int table_size);
-  Dictionary(ClassLoaderData* loader_data, int table_size, HashtableBucket<mtClass>* t, int number_of_entries);
+  Dictionary(ClassLoaderData* loader_data, int table_size, bool resizable = false);
+  Dictionary(ClassLoaderData* loader_data, int table_size, HashtableBucket<mtClass>* t, int number_of_entries, bool resizable = false);
   ~Dictionary();
 
+  static bool does_any_dictionary_needs_resizing();
+  bool resize_if_needed();
+
   DictionaryEntry* new_entry(unsigned int hash, InstanceKlass* klass);
 
-  void add_klass(int index, unsigned int hash, Symbol* class_name, InstanceKlass* obj);
+  void add_klass(unsigned int hash, Symbol* class_name, InstanceKlass* obj);
 
   InstanceKlass* find_class(int index, unsigned int hash, Symbol* name);
 
@@ -79,8 +87,8 @@
   void do_unloading();
 
   // Protection domains
-  InstanceKlass* find(int index, unsigned int hash, Symbol* name, Handle protection_domain);
-  bool is_valid_protection_domain(int index, unsigned int hash,
+  InstanceKlass* find(unsigned int hash, Symbol* name, Handle protection_domain);
+  bool is_valid_protection_domain(unsigned int hash,
                                   Symbol* name,
                                   Handle protection_domain);
   void add_protection_domain(int index, unsigned int hash,
@@ -88,7 +96,7 @@
                              Handle protection_domain, TRAPS);
 
   // Sharing support
-  void reorder_dictionary_for_sharing();
+  void reorder_dictionary_for_sharing() NOT_CDS_RETURN;
 
   void print_on(outputStream* st) const;
   void verify();
--- a/src/hotspot/share/classfile/javaClasses.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/javaClasses.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -2258,8 +2258,9 @@
 
 void java_lang_StackFrameInfo::to_stack_trace_element(Handle stackFrame, Handle stack_trace_element, TRAPS) {
   ResourceMark rm(THREAD);
-  Handle k (THREAD, stackFrame->obj_field(_declaringClass_offset));
-  InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(k()));
+  Handle mname(THREAD, stackFrame->obj_field(java_lang_StackFrameInfo::_memberName_offset));
+  Klass* clazz = java_lang_Class::as_Klass(java_lang_invoke_MemberName::clazz(mname()));
+  InstanceKlass* holder = InstanceKlass::cast(clazz);
   Method* method = java_lang_StackFrameInfo::get_method(stackFrame, holder, CHECK);
 
   short version = stackFrame->short_field(_version_offset);
@@ -2270,7 +2271,6 @@
 
 void java_lang_StackFrameInfo::compute_offsets() {
   Klass* k = SystemDictionary::StackFrameInfo_klass();
-  compute_offset(_declaringClass_offset, k, vmSymbols::declaringClass_name(),  vmSymbols::class_signature());
   compute_offset(_memberName_offset,     k, vmSymbols::memberName_name(),  vmSymbols::object_signature());
   compute_offset(_bci_offset,            k, vmSymbols::bci_name(),         vmSymbols::short_signature());
   STACKFRAMEINFO_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
@@ -3679,7 +3679,6 @@
 int java_lang_StackTraceElement::classLoaderName_offset;
 int java_lang_StackTraceElement::declaringClass_offset;
 int java_lang_StackTraceElement::declaringClassObject_offset;
-int java_lang_StackFrameInfo::_declaringClass_offset;
 int java_lang_StackFrameInfo::_memberName_offset;
 int java_lang_StackFrameInfo::_bci_offset;
 int java_lang_StackFrameInfo::_version_offset;
@@ -3732,11 +3731,6 @@
   element->obj_field_put(declaringClassObject_offset, value);
 }
 
-// Support for java_lang_StackFrameInfo
-void java_lang_StackFrameInfo::set_declaringClass(oop element, oop value) {
-  element->obj_field_put(_declaringClass_offset, value);
-}
-
 void java_lang_StackFrameInfo::set_version(oop element, short value) {
   element->short_field_put(_version_offset, value);
 }
--- a/src/hotspot/share/classfile/javaClasses.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/javaClasses.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -1370,7 +1370,6 @@
 
 class java_lang_StackFrameInfo: AllStatic {
 private:
-  static int _declaringClass_offset;
   static int _memberName_offset;
   static int _bci_offset;
   static int _version_offset;
@@ -1379,7 +1378,6 @@
 
 public:
   // Setters
-  static void set_declaringClass(oop info, oop value);
   static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci, TRAPS);
   static void set_bci(oop info, int value);
 
--- a/src/hotspot/share/classfile/modules.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/modules.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
 */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "classfile/classFileParser.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/classLoaderData.inline.hpp"
@@ -40,7 +41,6 @@
 #include "logging/logStream.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/instanceKlass.hpp"
-#include "prims/jvm.h"
 #include "runtime/arguments.hpp"
 #include "runtime/handles.inline.hpp"
 #include "runtime/javaCalls.hpp"
--- a/src/hotspot/share/classfile/systemDictionary.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/systemDictionary.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "aot/aotLoader.hpp"
 #include "classfile/classFileParser.hpp"
 #include "classfile/classFileStream.hpp"
@@ -61,7 +62,6 @@
 #include "oops/oop.inline.hpp"
 #include "oops/symbol.hpp"
 #include "oops/typeArrayKlass.hpp"
-#include "prims/jvm.h"
 #include "prims/jvmtiEnvBase.hpp"
 #include "prims/resolvedMethodTable.hpp"
 #include "prims/methodHandles.hpp"
@@ -371,7 +371,6 @@
   ClassLoaderData* loader_data = class_loader_data(class_loader);
   Dictionary* dictionary = loader_data->dictionary();
   unsigned int d_hash = dictionary->compute_hash(child_name);
-  int d_index = dictionary->hash_to_index(d_hash);
   unsigned int p_hash = placeholders()->compute_hash(child_name);
   int p_index = placeholders()->hash_to_index(p_hash);
   // can't throw error holding a lock
@@ -379,7 +378,7 @@
   bool throw_circularity_error = false;
   {
     MutexLocker mu(SystemDictionary_lock, THREAD);
-    Klass* childk = find_class(d_index, d_hash, child_name, dictionary);
+    Klass* childk = find_class(d_hash, child_name, dictionary);
     Klass* quicksuperk;
     // to support // loading: if child done loading, just return superclass
     // if class_name, & class_loader don't match:
@@ -487,9 +486,9 @@
 
     Symbol*  kn = klass->name();
     unsigned int d_hash = dictionary->compute_hash(kn);
-    int d_index = dictionary->hash_to_index(d_hash);
 
     MutexLocker mu(SystemDictionary_lock, THREAD);
+    int d_index = dictionary->hash_to_index(d_hash);
     dictionary->add_protection_domain(d_index, d_hash, klass,
                                       protection_domain, THREAD);
   }
@@ -555,7 +554,6 @@
   ClassLoaderData* loader_data = class_loader_data(class_loader);
   Dictionary* dictionary = loader_data->dictionary();
   unsigned int d_hash = dictionary->compute_hash(name);
-  int d_index = dictionary->hash_to_index(d_hash);
   unsigned int p_hash = placeholders()->compute_hash(name);
   int p_index = placeholders()->hash_to_index(p_hash);
 
@@ -579,7 +577,7 @@
  if (!class_loader.is_null() && is_parallelCapable(class_loader)) {
     MutexLocker mu(SystemDictionary_lock, THREAD);
     // Check if classloading completed while we were loading superclass or waiting
-    return find_class(d_index, d_hash, name, dictionary);
+    return find_class(d_hash, name, dictionary);
   }
 
   // must loop to both handle other placeholder updates
@@ -589,7 +587,7 @@
   while (super_load_in_progress) {
     MutexLocker mu(SystemDictionary_lock, THREAD);
     // Check if classloading completed while we were loading superclass or waiting
-    InstanceKlass* check = find_class(d_index, d_hash, name, dictionary);
+    InstanceKlass* check = find_class(d_hash, name, dictionary);
     if (check != NULL) {
       // Klass is already loaded, so just return it
       return check;
@@ -670,6 +668,7 @@
   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
   ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL);
   Dictionary* dictionary = loader_data->dictionary();
+  unsigned int d_hash = dictionary->compute_hash(name);
 
   // Do lookup to see if class already exist and the protection domain
   // has the right access
@@ -677,11 +676,10 @@
   // All subsequent calls use find_class, and set has_loaded_class so that
   // before we return a result we call out to java to check for valid protection domain
   // to allow returning the Klass* and add it to the pd_set if it is valid
-  unsigned int d_hash = dictionary->compute_hash(name);
-  int d_index = dictionary->hash_to_index(d_hash);
-  Klass* probe = dictionary->find(d_index, d_hash, name, protection_domain);
-  if (probe != NULL) return probe;
-
+  {
+    Klass* probe = dictionary->find(d_hash, name, protection_domain);
+    if (probe != NULL) return probe;
+  }
 
   // Non-bootstrap class loaders will call out to class loader and
   // define via jvm/jni_DefineClass which will acquire the
@@ -716,7 +714,7 @@
 
   {
     MutexLocker mu(SystemDictionary_lock, THREAD);
-    InstanceKlass* check = find_class(d_index, d_hash, name, dictionary);
+    InstanceKlass* check = find_class(d_hash, name, dictionary);
     if (check != NULL) {
       // Klass is already loaded, so just return it
       class_has_been_loaded = true;
@@ -800,7 +798,7 @@
                 double_lock_wait(lockObject, THREAD);
               }
               // Check if classloading completed while we were waiting
-              InstanceKlass* check = find_class(d_index, d_hash, name, dictionary);
+              InstanceKlass* check = find_class(d_hash, name, dictionary);
               if (check != NULL) {
                 // Klass is already loaded, so just return it
                 k = check;
@@ -825,7 +823,7 @@
         // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL
         // one final check if the load has already completed
         // class loaders holding the ObjectLock shouldn't find the class here
-        InstanceKlass* check = find_class(d_index, d_hash, name, dictionary);
+        InstanceKlass* check = find_class(d_hash, name, dictionary);
         if (check != NULL) {
         // Klass is already loaded, so return it after checking/adding protection domain
           k = check;
@@ -858,7 +856,7 @@
         if (k == NULL && HAS_PENDING_EXCEPTION
           && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
           MutexLocker mu(SystemDictionary_lock, THREAD);
-          InstanceKlass* check = find_class(d_index, d_hash, name, dictionary);
+          InstanceKlass* check = find_class(d_hash, name, dictionary);
           if (check != NULL) {
             // Klass is already loaded, so just use it
             k = check;
@@ -873,7 +871,7 @@
       if (!HAS_PENDING_EXCEPTION && k != NULL &&
         k->class_loader() != class_loader()) {
 
-        check_constraints(d_index, d_hash, k, class_loader, false, THREAD);
+        check_constraints(d_hash, k, class_loader, false, THREAD);
 
         // Need to check for a PENDING_EXCEPTION again; check_constraints
         // can throw and doesn't use the CHECK macro.
@@ -881,7 +879,7 @@
           { // Grabbing the Compile_lock prevents systemDictionary updates
             // during compilations.
             MutexLocker mu(Compile_lock, THREAD);
-            update_dictionary(d_index, d_hash, p_index, p_hash,
+            update_dictionary(d_hash, p_index, p_hash,
               k, class_loader, THREAD);
           }
 
@@ -923,7 +921,7 @@
   if (protection_domain() == NULL) return k;
 
   // Check the protection domain has the right access
-  if (dictionary->is_valid_protection_domain(d_index, d_hash, name,
+  if (dictionary->is_valid_protection_domain(d_hash, name,
                                              protection_domain)) {
     return k;
   }
@@ -965,8 +963,7 @@
 
   Dictionary* dictionary = loader_data->dictionary();
   unsigned int d_hash = dictionary->compute_hash(class_name);
-  int d_index = dictionary->hash_to_index(d_hash);
-  return dictionary->find(d_index, d_hash, class_name,
+  return dictionary->find(d_hash, class_name,
                           protection_domain);
 }
 
@@ -1644,8 +1641,7 @@
   Symbol*  name_h = k->name();
   Dictionary* dictionary = loader_data->dictionary();
   unsigned int d_hash = dictionary->compute_hash(name_h);
-  int d_index = dictionary->hash_to_index(d_hash);
-  check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
+  check_constraints(d_hash, k, class_loader_h, true, CHECK);
 
   // Register class just loaded with class loader (placed in Vector)
   // Note we do this before updating the dictionary, as this can
@@ -1673,7 +1669,7 @@
 
     // Add to systemDictionary - so other classes can see it.
     // Grabs and releases SystemDictionary_lock
-    update_dictionary(d_index, d_hash, p_index, p_hash,
+    update_dictionary(d_hash, p_index, p_hash,
                       k, class_loader_h, THREAD);
   }
   k->eager_initialize(THREAD);
@@ -1715,7 +1711,6 @@
   Dictionary* dictionary = loader_data->dictionary();
 
   unsigned int d_hash = dictionary->compute_hash(name_h);
-  int d_index = dictionary->hash_to_index(d_hash);
 
   // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS
   unsigned int p_hash = placeholders()->compute_hash(name_h);
@@ -1726,7 +1721,7 @@
     MutexLocker mu(SystemDictionary_lock, THREAD);
     // First check if class already defined
     if (UnsyncloadClass || (is_parallelDefine(class_loader))) {
-      InstanceKlass* check = find_class(d_index, d_hash, name_h, dictionary);
+      InstanceKlass* check = find_class(d_hash, name_h, dictionary);
       if (check != NULL) {
         return check;
       }
@@ -1748,7 +1743,7 @@
         placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD);
         SystemDictionary_lock->notify_all();
 #ifdef ASSERT
-        InstanceKlass* check = find_class(d_index, d_hash, name_h, dictionary);
+        InstanceKlass* check = find_class(d_hash, name_h, dictionary);
         assert(check != NULL, "definer missed recording success");
 #endif
         return probe->instance_klass();
@@ -1823,10 +1818,11 @@
 // ----------------------------------------------------------------------------
 // Lookup
 
-InstanceKlass* SystemDictionary::find_class(int index, unsigned int hash,
+InstanceKlass* SystemDictionary::find_class(unsigned int hash,
                                             Symbol* class_name,
                                             Dictionary* dictionary) {
   assert_locked_or_safepoint(SystemDictionary_lock);
+  int index = dictionary->hash_to_index(hash);
   return dictionary->find_class(index, hash, class_name);
 }
 
@@ -1856,8 +1852,7 @@
 
   Dictionary* dictionary = loader_data->dictionary();
   unsigned int d_hash = dictionary->compute_hash(class_name);
-  int d_index = dictionary->hash_to_index(d_hash);
-  return find_class(d_index, d_hash, class_name, dictionary);
+  return find_class(d_hash, class_name, dictionary);
 }
 
 
@@ -2210,7 +2205,7 @@
 // if defining is true, then LinkageError if already in dictionary
 // if initiating loader, then ok if InstanceKlass matches existing entry
 
-void SystemDictionary::check_constraints(int d_index, unsigned int d_hash,
+void SystemDictionary::check_constraints(unsigned int d_hash,
                                          InstanceKlass* k,
                                          Handle class_loader, bool defining,
                                          TRAPS) {
@@ -2222,7 +2217,7 @@
 
     MutexLocker mu(SystemDictionary_lock, THREAD);
 
-    InstanceKlass* check = find_class(d_index, d_hash, name, loader_data->dictionary());
+    InstanceKlass* check = find_class(d_hash, name, loader_data->dictionary());
     if (check != NULL) {
       // if different InstanceKlass - duplicate class definition,
       // else - ok, class loaded by a different thread in parallel,
@@ -2270,7 +2265,7 @@
 
 // Update class loader data dictionary - done after check_constraint and add_to_hierachy
 // have been called.
-void SystemDictionary::update_dictionary(int d_index, unsigned int d_hash,
+void SystemDictionary::update_dictionary(unsigned int d_hash,
                                          int p_index, unsigned int p_hash,
                                          InstanceKlass* k,
                                          Handle class_loader,
@@ -2305,13 +2300,13 @@
 
     // Make a new dictionary entry.
     Dictionary* dictionary = loader_data->dictionary();
-    InstanceKlass* sd_check = find_class(d_index, d_hash, name, dictionary);
+    InstanceKlass* sd_check = find_class(d_hash, name, dictionary);
     if (sd_check == NULL) {
-      dictionary->add_klass(d_index, d_hash, name, k);
+      dictionary->add_klass(d_hash, name, k);
       notice_modification();
     }
   #ifdef ASSERT
-    sd_check = find_class(d_index, d_hash, name, dictionary);
+    sd_check = find_class(d_hash, name, dictionary);
     assert (sd_check != NULL, "should have entry in dictionary");
     // Note: there may be a placeholder entry: for circularity testing
     // or for parallel defines
@@ -2388,16 +2383,14 @@
 
   Dictionary* dictionary1 = loader_data1->dictionary();
   unsigned int d_hash1 = dictionary1->compute_hash(constraint_name);
-  int d_index1 = dictionary1->hash_to_index(d_hash1);
 
   Dictionary* dictionary2 = loader_data2->dictionary();
   unsigned int d_hash2 = dictionary2->compute_hash(constraint_name);
-  int d_index2 = dictionary2->hash_to_index(d_hash2);
 
   {
     MutexLocker mu_s(SystemDictionary_lock, THREAD);
-    InstanceKlass* klass1 = find_class(d_index1, d_hash1, constraint_name, dictionary1);
-    InstanceKlass* klass2 = find_class(d_index2, d_hash2, constraint_name, dictionary2);
+    InstanceKlass* klass1 = find_class(d_hash1, constraint_name, dictionary1);
+    InstanceKlass* klass2 = find_class(d_hash2, constraint_name, dictionary2);
     return constraints()->add_entry(constraint_name, klass1, class_loader1,
                                     klass2, class_loader2);
   }
@@ -2855,9 +2848,11 @@
   return _pd_cache_table->get(protection_domain);
 }
 
+#if INCLUDE_CDS
 void SystemDictionary::reorder_dictionary_for_sharing() {
   ClassLoaderData::the_null_class_loader_data()->dictionary()->reorder_dictionary_for_sharing();
 }
+#endif
 
 size_t SystemDictionary::count_bytes_for_buckets() {
   return ClassLoaderData::the_null_class_loader_data()->dictionary()->count_bytes_for_buckets();
--- a/src/hotspot/share/classfile/systemDictionary.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/systemDictionary.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -384,7 +384,7 @@
 
 public:
   // Sharing support.
-  static void reorder_dictionary_for_sharing();
+  static void reorder_dictionary_for_sharing() NOT_CDS_RETURN;
   static void combine_shared_dictionaries();
   static size_t count_bytes_for_buckets();
   static size_t count_bytes_for_table();
@@ -655,11 +655,8 @@
   // Setup link to hierarchy
   static void add_to_hierarchy(InstanceKlass* k, TRAPS);
 
-  // We pass in the hashtable index so we can calculate it outside of
-  // the SystemDictionary_lock.
-
   // Basic find on loaded classes
-  static InstanceKlass* find_class(int index, unsigned int hash,
+  static InstanceKlass* find_class(unsigned int hash,
                                    Symbol* name, Dictionary* dictionary);
   static InstanceKlass* find_class(Symbol* class_name, ClassLoaderData* loader_data);
 
@@ -685,10 +682,10 @@
   static void initialize_preloaded_classes(TRAPS);
 
   // Class loader constraints
-  static void check_constraints(int index, unsigned int hash,
+  static void check_constraints(unsigned int hash,
                                 InstanceKlass* k, Handle loader,
                                 bool defining, TRAPS);
-  static void update_dictionary(int d_index, unsigned int d_hash,
+  static void update_dictionary(unsigned int d_hash,
                                 int p_index, unsigned int p_hash,
                                 InstanceKlass* k, Handle loader,
                                 TRAPS);
--- a/src/hotspot/share/classfile/verifier.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/verifier.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "classfile/classFileStream.hpp"
 #include "classfile/javaClasses.hpp"
 #include "classfile/stackMapTable.hpp"
@@ -40,7 +41,6 @@
 #include "oops/instanceKlass.hpp"
 #include "oops/oop.inline.hpp"
 #include "oops/typeArrayOop.hpp"
-#include "prims/jvm.h"
 #include "runtime/fieldDescriptor.hpp"
 #include "runtime/handles.inline.hpp"
 #include "runtime/interfaceSupport.hpp"
--- a/src/hotspot/share/classfile/vmSymbols.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/vmSymbols.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,12 +23,12 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "classfile/vmSymbols.hpp"
 #include "compiler/compilerDirectives.hpp"
 #include "memory/oopFactory.hpp"
 #include "memory/metaspaceClosure.hpp"
 #include "oops/oop.inline.hpp"
-#include "prims/jvm.h"
 #include "runtime/handles.inline.hpp"
 #include "utilities/xmlstream.hpp"
 
--- a/src/hotspot/share/classfile/vmSymbols.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/classfile/vmSymbols.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -429,7 +429,6 @@
   template(append_name,                               "append")                                   \
   template(klass_name,                                "klass")                                    \
   template(array_klass_name,                          "array_klass")                              \
-  template(declaringClass_name,                       "declaringClass")                           \
   template(memberName_name,                           "memberName")                               \
   template(mid_name,                                  "mid")                                      \
   template(cpref_name,                                "cpref")                                    \
--- a/src/hotspot/share/code/codeBlob.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/code/codeBlob.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "code/codeBlob.hpp"
 #include "code/codeCache.hpp"
 #include "code/relocInfo.hpp"
@@ -33,7 +34,6 @@
 #include "memory/resourceArea.hpp"
 #include "oops/oop.inline.hpp"
 #include "prims/forte.hpp"
-#include "prims/jvm.h"
 #include "runtime/handles.inline.hpp"
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/mutexLocker.hpp"
--- a/src/hotspot/share/code/codeBlob.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/code/codeBlob.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -49,21 +49,35 @@
 // CodeBlob - superclass for all entries in the CodeCache.
 //
 // Subtypes are:
-//   CompiledMethod       : Compiled Java methods (include method that calls to native code)
-//     nmethod            : JIT Compiled Java methods
-//   RuntimeBlob          : Non-compiled method code; generated glue code
-//     RuntimeStub        : Call to VM runtime methods
-//     DeoptimizationBlob : Used for deoptimization
-//     ExceptionBlob      : Used for stack unrolling
-//     SafepointBlob      : Used to handle illegal instruction exceptions
+//  CompiledMethod       : Compiled Java methods (include method that calls to native code)
+//   nmethod             : JIT Compiled Java methods
+//   AOTCompiledMethod   : AOT Compiled Java methods - Not in the CodeCache!
+//                         AOTCompiledMethod objects are allocated in the C-Heap, the code they
+//                         point to is allocated in the AOTCodeHeap which is in the C-Heap as
+//                         well (i.e. it's the memory where the shared library was loaded to)
+//  RuntimeBlob          : Non-compiled method code; generated glue code
+//   BufferBlob          : Used for non-relocatable code such as interpreter, stubroutines, etc.
+//    AdapterBlob        : Used to hold C2I/I2C adapters
+//    MethodHandlesAdapterBlob : Used to hold MethodHandles adapters
+//   RuntimeStub         : Call to VM runtime methods
+//   SingletonBlob       : Super-class for all blobs that exist in only one instance
+//    DeoptimizationBlob : Used for deoptimization
+//    ExceptionBlob      : Used for stack unrolling
+//    SafepointBlob      : Used to handle illegal instruction exceptions
+//    UncommonTrapBlob   : Used to handle uncommon traps
 //
 //
-// Layout:
+// Layout (all except AOTCompiledMethod) : continuous in the CodeCache
 //   - header
 //   - relocation
 //   - content space
 //     - instruction space
 //   - data space
+//
+// Layout (AOTCompiledMethod) : in the C-Heap
+//   - header -\
+//     ...     |
+//   - code  <-/
 
 
 class CodeBlobLayout;
--- a/src/hotspot/share/code/nmethod.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/code/nmethod.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "code/codeCache.hpp"
 #include "code/compiledIC.hpp"
 #include "code/dependencies.hpp"
@@ -41,7 +42,6 @@
 #include "memory/resourceArea.hpp"
 #include "oops/methodData.hpp"
 #include "oops/oop.inline.hpp"
-#include "prims/jvm.h"
 #include "prims/jvmtiImpl.hpp"
 #include "runtime/atomic.hpp"
 #include "runtime/orderAccess.inline.hpp"
@@ -409,6 +409,7 @@
 #if INCLUDE_JVMCI
   _jvmci_installed_code   = NULL;
   _speculation_log        = NULL;
+  _jvmci_installed_code_triggers_unloading = false;
 #endif
 }
 
@@ -461,8 +462,8 @@
   AbstractCompiler* compiler,
   int comp_level
 #if INCLUDE_JVMCI
-  , Handle installed_code,
-  Handle speculationLog
+  , jweak installed_code,
+  jweak speculationLog
 #endif
 )
 {
@@ -642,8 +643,8 @@
   AbstractCompiler* compiler,
   int comp_level
 #if INCLUDE_JVMCI
-  , Handle installed_code,
-  Handle speculation_log
+  , jweak installed_code,
+  jweak speculation_log
 #endif
   )
   : CompiledMethod(method, "nmethod", type, nmethod_size, sizeof(nmethod), code_buffer, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps, false),
@@ -671,8 +672,14 @@
     set_ctable_begin(header_begin() + _consts_offset);
 
 #if INCLUDE_JVMCI
-    _jvmci_installed_code = installed_code();
-    _speculation_log = (instanceOop)speculation_log();
+    _jvmci_installed_code = installed_code;
+    _speculation_log = speculation_log;
+    oop obj = JNIHandles::resolve(installed_code);
+    if (obj == NULL || (obj->is_a(HotSpotNmethod::klass()) && HotSpotNmethod::isDefault(obj))) {
+      _jvmci_installed_code_triggers_unloading = false;
+    } else {
+      _jvmci_installed_code_triggers_unloading = true;
+    }
 
     if (compiler->is_jvmci()) {
       // JVMCI might not produce any stub sections
@@ -1026,8 +1033,6 @@
                   " unloadable, Method*(" INTPTR_FORMAT
                   "), cause(" INTPTR_FORMAT ")",
                   p2i(this), p2i(_method), p2i(cause));
-    if (!Universe::heap()->is_gc_active())
-      cause->klass()->print_on(&ls);
   }
   // Unlink the osr method, so we do not look this up again
   if (is_osr_method()) {
@@ -1077,14 +1082,8 @@
 #if INCLUDE_JVMCI
   // The method can only be unloaded after the pointer to the installed code
   // Java wrapper is no longer alive. Here we need to clear out this weak
-  // reference to the dead object. Nulling out the reference has to happen
-  // after the method is unregistered since the original value may be still
-  // tracked by the rset.
+  // reference to the dead object.
   maybe_invalidate_installed_code();
-  // Clear these out after the nmethod has been unregistered and any
-  // updates to the InstalledCode instance have been performed.
-  _jvmci_installed_code = NULL;
-  _speculation_log = NULL;
 #endif
 
   // The Method* is gone at this point
@@ -1246,10 +1245,6 @@
       MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
       if (nmethod_needs_unregister) {
         Universe::heap()->unregister_nmethod(this);
-#ifdef JVMCI
-        _jvmci_installed_code = NULL;
-        _speculation_log = NULL;
-#endif
       }
       flush_dependencies(NULL);
     }
@@ -1314,6 +1309,11 @@
     CodeCache::drop_scavenge_root_nmethod(this);
   }
 
+#if INCLUDE_JVMCI
+  assert(_jvmci_installed_code == NULL, "should have been nulled out when transitioned to zombie");
+  assert(_speculation_log == NULL, "should have been nulled out when transitioned to zombie");
+#endif
+
   CodeBlob::flush();
   CodeCache::free(this);
 }
@@ -1500,29 +1500,18 @@
 
 #if INCLUDE_JVMCI
 bool nmethod::do_unloading_jvmci(BoolObjectClosure* is_alive, bool unloading_occurred) {
-  bool is_unloaded = false;
-  // Follow JVMCI method
-  BarrierSet* bs = Universe::heap()->barrier_set();
   if (_jvmci_installed_code != NULL) {
-    if (_jvmci_installed_code->is_a(HotSpotNmethod::klass()) && HotSpotNmethod::isDefault(_jvmci_installed_code)) {
-      if (!is_alive->do_object_b(_jvmci_installed_code)) {
+    if (JNIHandles::is_global_weak_cleared(_jvmci_installed_code)) {
+      if (_jvmci_installed_code_triggers_unloading) {
+        // jweak reference processing has already cleared the referent
+        make_unloaded(is_alive, NULL);
+        return true;
+      } else {
         clear_jvmci_installed_code();
       }
-    } else {
-      if (can_unload(is_alive, (oop*)&_jvmci_installed_code, unloading_occurred)) {
-        return true;
-      }
     }
   }
-
-  if (_speculation_log != NULL) {
-    if (!is_alive->do_object_b(_speculation_log)) {
-      bs->write_ref_nmethod_pre(&_speculation_log, this);
-      _speculation_log = NULL;
-      bs->write_ref_nmethod_post(&_speculation_log, this);
-    }
-  }
-  return is_unloaded;
+  return false;
 }
 #endif
 
@@ -1594,15 +1583,6 @@
     // (See comment above.)
   }
 
-#if INCLUDE_JVMCI
-  if (_jvmci_installed_code != NULL) {
-    f->do_oop((oop*) &_jvmci_installed_code);
-  }
-  if (_speculation_log != NULL) {
-    f->do_oop((oop*) &_speculation_log);
-  }
-#endif
-
   RelocIterator iter(this, low_boundary);
 
   while (iter.next()) {
@@ -2860,43 +2840,49 @@
 
 #if INCLUDE_JVMCI
 void nmethod::clear_jvmci_installed_code() {
-  // write_ref_method_pre/post can only be safely called at a
-  // safepoint or while holding the CodeCache_lock
-  assert(CodeCache_lock->is_locked() ||
-         SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
+  assert_locked_or_safepoint(Patching_lock);
   if (_jvmci_installed_code != NULL) {
-    // This must be done carefully to maintain nmethod remembered sets properly
-    BarrierSet* bs = Universe::heap()->barrier_set();
-    bs->write_ref_nmethod_pre(&_jvmci_installed_code, this);
+    JNIHandles::destroy_weak_global(_jvmci_installed_code);
     _jvmci_installed_code = NULL;
-    bs->write_ref_nmethod_post(&_jvmci_installed_code, this);
+  }
+}
+
+void nmethod::clear_speculation_log() {
+  assert_locked_or_safepoint(Patching_lock);
+  if (_speculation_log != NULL) {
+    JNIHandles::destroy_weak_global(_speculation_log);
+    _speculation_log = NULL;
   }
 }
 
 void nmethod::maybe_invalidate_installed_code() {
   assert(Patching_lock->is_locked() ||
          SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
-  oop installed_code = jvmci_installed_code();
+  oop installed_code = JNIHandles::resolve(_jvmci_installed_code);
   if (installed_code != NULL) {
+    // Update the values in the InstalledCode instance if it still refers to this nmethod
     nmethod* nm = (nmethod*)InstalledCode::address(installed_code);
-    if (nm == NULL || nm != this) {
-      // The link has been broken or the InstalledCode instance is
-      // associated with another nmethod so do nothing.
-      return;
+    if (nm == this) {
+      if (!is_alive()) {
+        // Break the link between nmethod and InstalledCode such that the nmethod
+        // can subsequently be flushed safely.  The link must be maintained while
+        // the method could have live activations since invalidateInstalledCode
+        // might want to invalidate all existing activations.
+        InstalledCode::set_address(installed_code, 0);
+        InstalledCode::set_entryPoint(installed_code, 0);
+      } else if (is_not_entrant()) {
+        // Remove the entry point so any invocation will fail but keep
+        // the address link around that so that existing activations can
+        // be invalidated.
+        InstalledCode::set_entryPoint(installed_code, 0);
+      }
     }
-    if (!is_alive()) {
-      // Break the link between nmethod and InstalledCode such that the nmethod
-      // can subsequently be flushed safely.  The link must be maintained while
-      // the method could have live activations since invalidateInstalledCode
-      // might want to invalidate all existing activations.
-      InstalledCode::set_address(installed_code, 0);
-      InstalledCode::set_entryPoint(installed_code, 0);
-    } else if (is_not_entrant()) {
-      // Remove the entry point so any invocation will fail but keep
-      // the address link around that so that existing activations can
-      // be invalidated.
-      InstalledCode::set_entryPoint(installed_code, 0);
-    }
+  }
+  if (!is_alive()) {
+    // Clear these out after the nmethod has been unregistered and any
+    // updates to the InstalledCode instance have been performed.
+    clear_jvmci_installed_code();
+    clear_speculation_log();
   }
 }
 
@@ -2916,45 +2902,49 @@
   {
     MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
     // This relationship can only be checked safely under a lock
-    assert(nm == NULL || !nm->is_alive() || nm->jvmci_installed_code() == installedCode(), "sanity check");
+    assert(!nm->is_alive() || nm->jvmci_installed_code() == installedCode(), "sanity check");
   }
 #endif
 
   if (nm->is_alive()) {
-    // The nmethod state machinery maintains the link between the
-    // HotSpotInstalledCode and nmethod* so as long as the nmethod appears to be
-    // alive assume there is work to do and deoptimize the nmethod.
+    // Invalidating the InstalledCode means we want the nmethod
+    // to be deoptimized.
     nm->mark_for_deoptimization();
     VM_Deoptimize op;
     VMThread::execute(&op);
   }
 
+  // Multiple threads could reach this point so we now need to
+  // lock and re-check the link to the nmethod so that only one
+  // thread clears it.
   MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
-  // Check that it's still associated with the same nmethod and break
-  // the link if it is.
   if (InstalledCode::address(installedCode) == nativeMethod) {
-    InstalledCode::set_address(installedCode, 0);
+      InstalledCode::set_address(installedCode, 0);
   }
 }
 
+oop nmethod::jvmci_installed_code() {
+  return JNIHandles::resolve(_jvmci_installed_code);
+}
+
+oop nmethod::speculation_log() {
+  return JNIHandles::resolve(_speculation_log);
+}
+
 char* nmethod::jvmci_installed_code_name(char* buf, size_t buflen) {
   if (!this->is_compiled_by_jvmci()) {
     return NULL;
   }
-  oop installedCode = this->jvmci_installed_code();
-  if (installedCode != NULL) {
-    oop installedCodeName = NULL;
-    if (installedCode->is_a(InstalledCode::klass())) {
-      installedCodeName = InstalledCode::name(installedCode);
+  oop installed_code = JNIHandles::resolve(_jvmci_installed_code);
+  if (installed_code != NULL) {
+    oop installed_code_name = NULL;
+    if (installed_code->is_a(InstalledCode::klass())) {
+      installed_code_name = InstalledCode::name(installed_code);
     }
-    if (installedCodeName != NULL) {
-      return java_lang_String::as_utf8_string(installedCodeName, buf, (int)buflen);
-    } else {
-      jio_snprintf(buf, buflen, "null");
-      return buf;
+    if (installed_code_name != NULL) {
+      return java_lang_String::as_utf8_string(installed_code_name, buf, (int)buflen);
     }
   }
-  jio_snprintf(buf, buflen, "noInstalledCode");
-  return buf;
+  return NULL;
 }
 #endif
--- a/src/hotspot/share/code/nmethod.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/code/nmethod.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -63,9 +63,22 @@
   jmethodID _jmethod_id;       // Cache of method()->jmethod_id()
 
 #if INCLUDE_JVMCI
-  // Needed to keep nmethods alive that are not the default nmethod for the associated Method.
-  oop       _jvmci_installed_code;
-  oop       _speculation_log;
+  // A weak reference to an InstalledCode object associated with
+  // this nmethod.
+  jweak     _jvmci_installed_code;
+
+  // A weak reference to a SpeculationLog object associated with
+  // this nmethod.
+  jweak     _speculation_log;
+
+  // Determines whether this nmethod is unloaded when the
+  // referent in _jvmci_installed_code is cleared. This
+  // will be false if the referent is initialized to a
+  // HotSpotNMethod object whose isDefault field is true.
+  // That is, installed code other than a "default"
+  // HotSpotNMethod causes nmethod unloading.
+  // This field is ignored once _jvmci_installed_code is NULL.
+  bool _jvmci_installed_code_triggers_unloading;
 #endif
 
   // To support simple linked-list chaining of nmethods:
@@ -192,8 +205,8 @@
           AbstractCompiler* compiler,
           int comp_level
 #if INCLUDE_JVMCI
-          , Handle installed_code,
-          Handle speculation_log
+          , jweak installed_code,
+          jweak speculation_log
 #endif
           );
 
@@ -236,8 +249,8 @@
                               AbstractCompiler* compiler,
                               int comp_level
 #if INCLUDE_JVMCI
-                              , Handle installed_code = Handle(),
-                              Handle speculation_log = Handle()
+                              , jweak installed_code = NULL,
+                              jweak speculation_log = NULL
 #endif
   );
 
@@ -433,27 +446,46 @@
   void set_method(Method* method) { _method = method; }
 
 #if INCLUDE_JVMCI
-  oop jvmci_installed_code() { return _jvmci_installed_code ; }
+  // Gets the InstalledCode object associated with this nmethod
+  // which may be NULL if this nmethod was not compiled by JVMCI
+  // or the weak reference has been cleared.
+  oop jvmci_installed_code();
+
+  // Copies the value of the name field in the InstalledCode
+  // object (if any) associated with this nmethod into buf.
+  // Returns the value of buf if it was updated otherwise NULL.
   char* jvmci_installed_code_name(char* buf, size_t buflen);
 
-  // Update the state of any InstalledCode instance associated with
+  // Updates the state of the InstalledCode (if any) associated with
   // this nmethod based on the current value of _state.
   void maybe_invalidate_installed_code();
 
-  // Helper function to invalidate InstalledCode instances
+  // Deoptimizes the nmethod (if any) in the address field of a given
+  // InstalledCode object. The address field is zeroed upon return.
   static void invalidate_installed_code(Handle installed_code, TRAPS);
 
-  oop speculation_log() { return _speculation_log ; }
+  // Gets the SpeculationLog object associated with this nmethod
+  // which may be NULL if this nmethod was not compiled by JVMCI
+  // or the weak reference has been cleared.
+  oop speculation_log();
 
  private:
+  // Deletes the weak reference (if any) to the InstalledCode object
+  // associated with this nmethod.
   void clear_jvmci_installed_code();
 
+  // Deletes the weak reference (if any) to the SpeculationLog object
+  // associated with this nmethod.
+  void clear_speculation_log();
+
  public:
 #endif
 
  protected:
   virtual bool do_unloading_oops(address low_boundary, BoolObjectClosure* is_alive, bool unloading_occurred);
 #if INCLUDE_JVMCI
+  // See comment for _jvmci_installed_code_triggers_unloading field.
+  // Returns whether this nmethod was unloaded.
   virtual bool do_unloading_jvmci(BoolObjectClosure* is_alive, bool unloading_occurred);
 #endif
 
--- a/src/hotspot/share/code/relocInfo.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/code/relocInfo.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -489,7 +489,7 @@
 #ifndef _LP64
   _target = (address) (intptr_t)unpack_1_int();
 #else
-  int32_t lo, hi;
+  jint lo, hi;
   unpack_2_ints(lo, hi);
   jlong t = jlong_from(hi, lo);;
   _target = (address) t;
--- a/src/hotspot/share/code/scopeDesc.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/code/scopeDesc.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -228,7 +228,7 @@
     }
   }
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   if (NOT_JVMCI(DoEscapeAnalysis &&) is_top() && _objects != NULL) {
     st->print_cr("   Objects");
     for (int i = 0; i < _objects->length(); i++) {
@@ -239,7 +239,7 @@
       st->cr();
     }
   }
-#endif // COMPILER2 || INCLUDE_JVMCI
+#endif // COMPILER2_OR_JVMCI
 }
 
 #endif
--- a/src/hotspot/share/compiler/compileBroker.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/compiler/compileBroker.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "classfile/symbolTable.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
@@ -40,7 +41,6 @@
 #include "oops/methodData.hpp"
 #include "oops/method.hpp"
 #include "oops/oop.inline.hpp"
-#include "prims/jvm.h"
 #include "prims/nativeLookup.hpp"
 #include "prims/whitebox.hpp"
 #include "runtime/arguments.hpp"
@@ -108,7 +108,7 @@
 
 bool CompileBroker::_initialized = false;
 volatile bool CompileBroker::_should_block = false;
-volatile jint CompileBroker::_print_compilation_warning = 0;
+volatile int  CompileBroker::_print_compilation_warning = 0;
 volatile jint CompileBroker::_should_compile_new_jobs = run_compilation;
 
 // The installed compiler(s)
--- a/src/hotspot/share/compiler/compileBroker.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/compiler/compileBroker.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -217,7 +217,7 @@
   static int _sum_nmethod_code_size;
   static long _peak_compilation_time;
 
-  static volatile jint _print_compilation_warning;
+  static volatile int _print_compilation_warning;
 
   static JavaThread* make_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, AbstractCompiler* comp, bool compiler_thread, TRAPS);
   static void init_compiler_sweeper_threads(int c1_compiler_count, int c2_compiler_count);
--- a/src/hotspot/share/compiler/compileLog.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/compiler/compileLog.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,12 +23,12 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "ci/ciMethod.hpp"
 #include "code/codeCache.hpp"
 #include "compiler/compileLog.hpp"
 #include "memory/allocation.inline.hpp"
 #include "oops/method.hpp"
-#include "prims/jvm.h"
 #include "runtime/mutexLocker.hpp"
 #include "runtime/os.hpp"
 
--- a/src/hotspot/share/compiler/compilerOracle.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/compiler/compilerOracle.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "compiler/compilerOracle.hpp"
 #include "compiler/methodMatcher.hpp"
 #include "memory/allocation.inline.hpp"
@@ -31,7 +32,6 @@
 #include "oops/klass.hpp"
 #include "oops/method.hpp"
 #include "oops/symbol.hpp"
-#include "prims/jvm.h"
 #include "runtime/handles.inline.hpp"
 #include "runtime/jniHandles.hpp"
 #include "runtime/os.hpp"
--- a/src/hotspot/share/compiler/oopMap.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/compiler/oopMap.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -268,9 +268,9 @@
 #if !defined(TIERED) && !defined(INCLUDE_JVMCI)
   COMPILER1_PRESENT(ShouldNotReachHere();)
 #endif // !defined(TIERED) && !defined(INCLUDE_JVMCI)
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   DerivedPointerTable::add(derived, base);
-#endif // COMPILER2 || INCLUDE_JVMCI
+#endif // COMPILER2_OR_JVMCI
 }
 
 
@@ -461,12 +461,12 @@
 #if !defined(TIERED) && !defined(INCLUDE_JVMCI)
   COMPILER1_PRESENT(return false);
 #endif // !TIERED
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   OopMapStream oms(this,OopMapValue::derived_oop_value);
   return oms.is_done();
 #else
   return false;
-#endif // COMPILER2 || INCLUDE_JVMCI
+#endif // COMPILER2_OR_JVMCI
 }
 
 #endif //PRODUCT
@@ -726,7 +726,7 @@
 
 //------------------------------DerivedPointerTable---------------------------
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
 
 class DerivedPointerEntry : public CHeapObj<mtCompiler> {
  private:
@@ -819,4 +819,4 @@
   _active = false;
 }
 
-#endif // COMPILER2 || INCLUDE_JVMCI
+#endif // COMPILER2_OR_JVMCI
--- a/src/hotspot/share/compiler/oopMap.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/compiler/oopMap.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -427,7 +427,7 @@
 // oops, it is filled in with references to all locations that contains a
 // derived oop (assumed to be very few).  When the GC is complete, the derived
 // pointers are updated based on their base pointers new value and an offset.
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
 class DerivedPointerTable : public AllStatic {
   friend class VMStructs;
  private:
@@ -463,6 +463,6 @@
     }
   }
 };
-#endif // COMPILER2 || INCLUDE_JVMCI
+#endif // COMPILER2_OR_JVMCI
 
 #endif // SHARE_VM_COMPILER_OOPMAP_HPP
--- a/src/hotspot/share/gc/cms/cmsHeap.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/cms/cmsHeap.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -39,14 +39,16 @@
 class WorkGang;
 
 class CMSHeap : public GenCollectedHeap {
+
+protected:
+  virtual void check_gen_kinds();
+
 public:
   CMSHeap(GenCollectorPolicy *policy);
 
   // Returns JNI_OK on success
   virtual jint initialize();
 
-  virtual void check_gen_kinds();
-
   // Convenience function to be used in situations where the heap type can be
   // asserted to be this type.
   static CMSHeap* heap();
@@ -70,10 +72,6 @@
   // supports. Caller does not hold the Heap_lock on entry.
   void collect(GCCause::Cause cause);
 
-  bool is_in_closed_subset(const void* p) const {
-    return is_in_reserved(p);
-  }
-
   bool card_mark_must_follow_store() const {
     return true;
   }
--- a/src/hotspot/share/gc/cms/compactibleFreeListSpace.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/cms/compactibleFreeListSpace.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -57,6 +57,7 @@
 // Defaults are 0 so things will break badly if incorrectly initialized.
 size_t CompactibleFreeListSpace::IndexSetStart  = 0;
 size_t CompactibleFreeListSpace::IndexSetStride = 0;
+size_t CompactibleFreeListSpace::_min_chunk_size_in_bytes = 0;
 
 size_t MinChunkSize = 0;
 
@@ -66,8 +67,8 @@
 
   // MinChunkSize should be a multiple of MinObjAlignment and be large enough
   // for chunks to contain a FreeChunk.
-  size_t min_chunk_size_in_bytes = align_up(sizeof(FreeChunk), MinObjAlignmentInBytes);
-  MinChunkSize = min_chunk_size_in_bytes / BytesPerWord;
+  _min_chunk_size_in_bytes = align_up(sizeof(FreeChunk), MinObjAlignmentInBytes);
+  MinChunkSize = _min_chunk_size_in_bytes / BytesPerWord;
 
   assert(IndexSetStart == 0 && IndexSetStride == 0, "already set");
   IndexSetStart  = MinChunkSize;
--- a/src/hotspot/share/gc/cms/compactibleFreeListSpace.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/cms/compactibleFreeListSpace.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -118,6 +118,7 @@
   };
   static size_t IndexSetStart;
   static size_t IndexSetStride;
+  static size_t _min_chunk_size_in_bytes;
 
  private:
   enum FitStrategyOptions {
@@ -134,6 +135,7 @@
   // A lock protecting the free lists and free blocks;
   // mutable because of ubiquity of locking even for otherwise const methods
   mutable Mutex _freelistLock;
+
   // Locking verifier convenience function
   void assert_locked() const PRODUCT_RETURN;
   void assert_locked(const Mutex* lock) const PRODUCT_RETURN;
--- a/src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -2296,7 +2296,7 @@
   // way with the marking information used by GC.
   NoRefDiscovery no_discovery(ref_processor());
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   DerivedPointerTableDeactivate dpt_deact;
 #endif
 
@@ -2869,7 +2869,7 @@
   print_eden_and_survivor_chunk_arrays();
 
   {
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
     DerivedPointerTableDeactivate dpt_deact;
 #endif
     if (CMSParallelInitialMarkEnabled) {
@@ -4171,7 +4171,7 @@
   print_eden_and_survivor_chunk_arrays();
 
   {
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
     DerivedPointerTableDeactivate dpt_deact;
 #endif
 
--- a/src/hotspot/share/gc/cms/vmStructs_cms.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/cms/vmStructs_cms.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -30,7 +30,8 @@
                    static_field) \
   nonstatic_field(CompactibleFreeListSpace,    _collector,                                    CMSCollector*)                         \
   nonstatic_field(CompactibleFreeListSpace,    _bt,                                           BlockOffsetArrayNonContigSpace)        \
-                                                                                                                                     \
+     static_field(CompactibleFreeListSpace,    _min_chunk_size_in_bytes,                      size_t)                                \
+  nonstatic_field(CMSBitMap,                   _bmStartWord,                                  HeapWord*)                             \
   nonstatic_field(CMSBitMap,                   _bmWordSize,                                   size_t)                                \
   nonstatic_field(CMSBitMap,                   _shifter,                                      const int)                             \
   nonstatic_field(CMSBitMap,                   _bm,                                           BitMapView)                            \
@@ -63,6 +64,7 @@
   declare_toplevel_type(LinearAllocBlock)
 
 #define VM_INT_CONSTANTS_CMS(declare_constant)                            \
+  declare_constant(CompactibleFreeListSpace::IndexSetSize)                \
   declare_constant(Generation::ConcurrentMarkSweep)                       \
 
 #endif // SHARE_VM_GC_CMS_VMSTRUCTS_CMS_HPP
--- a/src/hotspot/share/gc/g1/concurrentG1Refine.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,370 +0,0 @@
-/*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * 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/concurrentG1Refine.hpp"
-#include "gc/g1/concurrentG1RefineThread.hpp"
-#include "gc/g1/g1YoungRemSetSamplingThread.hpp"
-#include "logging/log.hpp"
-#include "runtime/java.hpp"
-#include "runtime/thread.hpp"
-#include "utilities/debug.hpp"
-#include "utilities/globalDefinitions.hpp"
-#include "utilities/pair.hpp"
-#include <math.h>
-
-// Arbitrary but large limits, to simplify some of the zone calculations.
-// The general idea is to allow expressions like
-//   MIN2(x OP y, max_XXX_zone)
-// without needing to check for overflow in "x OP y", because the
-// ranges for x and y have been restricted.
-STATIC_ASSERT(sizeof(LP64_ONLY(jint) NOT_LP64(jshort)) <= (sizeof(size_t)/2));
-const size_t max_yellow_zone = LP64_ONLY(max_jint) NOT_LP64(max_jshort);
-const size_t max_green_zone = max_yellow_zone / 2;
-const size_t max_red_zone = INT_MAX; // For dcqs.set_max_completed_queue.
-STATIC_ASSERT(max_yellow_zone <= max_red_zone);
-
-// Range check assertions for green zone values.
-#define assert_zone_constraints_g(green)                        \
-  do {                                                          \
-    size_t azc_g_green = (green);                               \
-    assert(azc_g_green <= max_green_zone,                       \
-           "green exceeds max: " SIZE_FORMAT, azc_g_green);     \
-  } while (0)
-
-// Range check assertions for green and yellow zone values.
-#define assert_zone_constraints_gy(green, yellow)                       \
-  do {                                                                  \
-    size_t azc_gy_green = (green);                                      \
-    size_t azc_gy_yellow = (yellow);                                    \
-    assert_zone_constraints_g(azc_gy_green);                            \
-    assert(azc_gy_yellow <= max_yellow_zone,                            \
-           "yellow exceeds max: " SIZE_FORMAT, azc_gy_yellow);          \
-    assert(azc_gy_green <= azc_gy_yellow,                               \
-           "green (" SIZE_FORMAT ") exceeds yellow (" SIZE_FORMAT ")",  \
-           azc_gy_green, azc_gy_yellow);                                \
-  } while (0)
-
-// Range check assertions for green, yellow, and red zone values.
-#define assert_zone_constraints_gyr(green, yellow, red)                 \
-  do {                                                                  \
-    size_t azc_gyr_green = (green);                                     \
-    size_t azc_gyr_yellow = (yellow);                                   \
-    size_t azc_gyr_red = (red);                                         \
-    assert_zone_constraints_gy(azc_gyr_green, azc_gyr_yellow);          \
-    assert(azc_gyr_red <= max_red_zone,                                 \
-           "red exceeds max: " SIZE_FORMAT, azc_gyr_red);               \
-    assert(azc_gyr_yellow <= azc_gyr_red,                               \
-           "yellow (" SIZE_FORMAT ") exceeds red (" SIZE_FORMAT ")",    \
-           azc_gyr_yellow, azc_gyr_red);                                \
-  } while (0)
-
-// Logging tag sequence for refinement control updates.
-#define CTRL_TAGS gc, ergo, refine
-
-// For logging zone values, ensuring consistency of level and tags.
-#define LOG_ZONES(...) log_debug( CTRL_TAGS )(__VA_ARGS__)
-
-// Package for pair of refinement thread activation and deactivation
-// thresholds.  The activation and deactivation levels are resp. the first
-// and second values of the pair.
-typedef Pair<size_t, size_t> Thresholds;
-inline size_t activation_level(const Thresholds& t) { return t.first; }
-inline size_t deactivation_level(const Thresholds& t) { return t.second; }
-
-static Thresholds calc_thresholds(size_t green_zone,
-                                  size_t yellow_zone,
-                                  uint worker_i) {
-  double yellow_size = yellow_zone - green_zone;
-  double step = yellow_size / ConcurrentG1Refine::thread_num();
-  if (worker_i == 0) {
-    // Potentially activate worker 0 more aggressively, to keep
-    // available buffers near green_zone value.  When yellow_size is
-    // large we don't want to allow a full step to accumulate before
-    // doing any processing, as that might lead to significantly more
-    // than green_zone buffers to be processed by update_rs.
-    step = MIN2(step, ParallelGCThreads / 2.0);
-  }
-  size_t activate_offset = static_cast<size_t>(ceil(step * (worker_i + 1)));
-  size_t deactivate_offset = static_cast<size_t>(floor(step * worker_i));
-  return Thresholds(green_zone + activate_offset,
-                    green_zone + deactivate_offset);
-}
-
-ConcurrentG1Refine::ConcurrentG1Refine(size_t green_zone,
-                                       size_t yellow_zone,
-                                       size_t red_zone,
-                                       size_t min_yellow_zone_size) :
-  _threads(NULL),
-  _sample_thread(NULL),
-  _n_worker_threads(thread_num()),
-  _green_zone(green_zone),
-  _yellow_zone(yellow_zone),
-  _red_zone(red_zone),
-  _min_yellow_zone_size(min_yellow_zone_size)
-{
-  assert_zone_constraints_gyr(green_zone, yellow_zone, red_zone);
-}
-
-static size_t calc_min_yellow_zone_size() {
-  size_t step = G1ConcRefinementThresholdStep;
-  uint n_workers = ConcurrentG1Refine::thread_num();
-  if ((max_yellow_zone / step) < n_workers) {
-    return max_yellow_zone;
-  } else {
-    return step * n_workers;
-  }
-}
-
-static size_t calc_init_green_zone() {
-  size_t green = G1ConcRefinementGreenZone;
-  if (FLAG_IS_DEFAULT(G1ConcRefinementGreenZone)) {
-    green = ParallelGCThreads;
-  }
-  return MIN2(green, max_green_zone);
-}
-
-static size_t calc_init_yellow_zone(size_t green, size_t min_size) {
-  size_t config = G1ConcRefinementYellowZone;
-  size_t size = 0;
-  if (FLAG_IS_DEFAULT(G1ConcRefinementYellowZone)) {
-    size = green * 2;
-  } else if (green < config) {
-    size = config - green;
-  }
-  size = MAX2(size, min_size);
-  size = MIN2(size, max_yellow_zone);
-  return MIN2(green + size, max_yellow_zone);
-}
-
-static size_t calc_init_red_zone(size_t green, size_t yellow) {
-  size_t size = yellow - green;
-  if (!FLAG_IS_DEFAULT(G1ConcRefinementRedZone)) {
-    size_t config = G1ConcRefinementRedZone;
-    if (yellow < config) {
-      size = MAX2(size, config - yellow);
-    }
-  }
-  return MIN2(yellow + size, max_red_zone);
-}
-
-ConcurrentG1Refine* ConcurrentG1Refine::create(jint* ecode) {
-  size_t min_yellow_zone_size = calc_min_yellow_zone_size();
-  size_t green_zone = calc_init_green_zone();
-  size_t yellow_zone = calc_init_yellow_zone(green_zone, min_yellow_zone_size);
-  size_t red_zone = calc_init_red_zone(green_zone, yellow_zone);
-
-  LOG_ZONES("Initial Refinement Zones: "
-            "green: " SIZE_FORMAT ", "
-            "yellow: " SIZE_FORMAT ", "
-            "red: " SIZE_FORMAT ", "
-            "min yellow size: " SIZE_FORMAT,
-            green_zone, yellow_zone, red_zone, min_yellow_zone_size);
-
-  ConcurrentG1Refine* cg1r = new ConcurrentG1Refine(green_zone,
-                                                    yellow_zone,
-                                                    red_zone,
-                                                    min_yellow_zone_size);
-
-  if (cg1r == NULL) {
-    *ecode = JNI_ENOMEM;
-    vm_shutdown_during_initialization("Could not create ConcurrentG1Refine");
-    return NULL;
-  }
-
-  cg1r->_threads = NEW_C_HEAP_ARRAY_RETURN_NULL(ConcurrentG1RefineThread*, cg1r->_n_worker_threads, mtGC);
-  if (cg1r->_threads == NULL) {
-    *ecode = JNI_ENOMEM;
-    vm_shutdown_during_initialization("Could not allocate an array for ConcurrentG1RefineThread");
-    return NULL;
-  }
-
-  uint worker_id_offset = DirtyCardQueueSet::num_par_ids();
-
-  ConcurrentG1RefineThread *next = NULL;
-  for (uint i = cg1r->_n_worker_threads - 1; i != UINT_MAX; i--) {
-    Thresholds thresholds = calc_thresholds(green_zone, yellow_zone, i);
-    ConcurrentG1RefineThread* t =
-      new ConcurrentG1RefineThread(cg1r,
-                                   next,
-                                   worker_id_offset,
-                                   i,
-                                   activation_level(thresholds),
-                                   deactivation_level(thresholds));
-    assert(t != NULL, "Conc refine should have been created");
-    if (t->osthread() == NULL) {
-      *ecode = JNI_ENOMEM;
-      vm_shutdown_during_initialization("Could not create ConcurrentG1RefineThread");
-      return NULL;
-    }
-
-    assert(t->cg1r() == cg1r, "Conc refine thread should refer to this");
-    cg1r->_threads[i] = t;
-    next = t;
-  }
-
-  cg1r->_sample_thread = new G1YoungRemSetSamplingThread();
-  if (cg1r->_sample_thread->osthread() == NULL) {
-    *ecode = JNI_ENOMEM;
-    vm_shutdown_during_initialization("Could not create G1YoungRemSetSamplingThread");
-    return NULL;
-  }
-
-  *ecode = JNI_OK;
-  return cg1r;
-}
-
-void ConcurrentG1Refine::stop() {
-  for (uint i = 0; i < _n_worker_threads; i++) {
-    _threads[i]->stop();
-  }
-  _sample_thread->stop();
-}
-
-void ConcurrentG1Refine::update_thread_thresholds() {
-  for (uint i = 0; i < _n_worker_threads; i++) {
-    Thresholds thresholds = calc_thresholds(_green_zone, _yellow_zone, i);
-    _threads[i]->update_thresholds(activation_level(thresholds),
-                                   deactivation_level(thresholds));
-  }
-}
-
-ConcurrentG1Refine::~ConcurrentG1Refine() {
-  for (uint i = 0; i < _n_worker_threads; i++) {
-    delete _threads[i];
-  }
-  FREE_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _threads);
-
-  delete _sample_thread;
-}
-
-void ConcurrentG1Refine::threads_do(ThreadClosure *tc) {
-  worker_threads_do(tc);
-  tc->do_thread(_sample_thread);
-}
-
-void ConcurrentG1Refine::worker_threads_do(ThreadClosure * tc) {
-  for (uint i = 0; i < _n_worker_threads; i++) {
-    tc->do_thread(_threads[i]);
-  }
-}
-
-uint ConcurrentG1Refine::thread_num() {
-  return G1ConcRefinementThreads;
-}
-
-void ConcurrentG1Refine::print_worker_threads_on(outputStream* st) const {
-  for (uint i = 0; i < _n_worker_threads; ++i) {
-    _threads[i]->print_on(st);
-    st->cr();
-  }
-  _sample_thread->print_on(st);
-  st->cr();
-}
-
-static size_t calc_new_green_zone(size_t green,
-                                  double update_rs_time,
-                                  size_t update_rs_processed_buffers,
-                                  double goal_ms) {
-  // Adjust green zone based on whether we're meeting the time goal.
-  // Limit to max_green_zone.
-  const double inc_k = 1.1, dec_k = 0.9;
-  if (update_rs_time > goal_ms) {
-    if (green > 0) {
-      green = static_cast<size_t>(green * dec_k);
-    }
-  } else if (update_rs_time < goal_ms &&
-             update_rs_processed_buffers > green) {
-    green = static_cast<size_t>(MAX2(green * inc_k, green + 1.0));
-    green = MIN2(green, max_green_zone);
-  }
-  return green;
-}
-
-static size_t calc_new_yellow_zone(size_t green, size_t min_yellow_size) {
-  size_t size = green * 2;
-  size = MAX2(size, min_yellow_size);
-  return MIN2(green + size, max_yellow_zone);
-}
-
-static size_t calc_new_red_zone(size_t green, size_t yellow) {
-  return MIN2(yellow + (yellow - green), max_red_zone);
-}
-
-void ConcurrentG1Refine::update_zones(double update_rs_time,
-                                      size_t update_rs_processed_buffers,
-                                      double goal_ms) {
-  log_trace( CTRL_TAGS )("Updating Refinement Zones: "
-                         "update_rs time: %.3fms, "
-                         "update_rs buffers: " SIZE_FORMAT ", "
-                         "update_rs goal time: %.3fms",
-                         update_rs_time,
-                         update_rs_processed_buffers,
-                         goal_ms);
-
-  _green_zone = calc_new_green_zone(_green_zone,
-                                    update_rs_time,
-                                    update_rs_processed_buffers,
-                                    goal_ms);
-  _yellow_zone = calc_new_yellow_zone(_green_zone, _min_yellow_zone_size);
-  _red_zone = calc_new_red_zone(_green_zone, _yellow_zone);
-
-  assert_zone_constraints_gyr(_green_zone, _yellow_zone, _red_zone);
-  LOG_ZONES("Updated Refinement Zones: "
-            "green: " SIZE_FORMAT ", "
-            "yellow: " SIZE_FORMAT ", "
-            "red: " SIZE_FORMAT,
-            _green_zone, _yellow_zone, _red_zone);
-}
-
-void ConcurrentG1Refine::adjust(double update_rs_time,
-                                size_t update_rs_processed_buffers,
-                                double goal_ms) {
-  DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
-
-  if (G1UseAdaptiveConcRefinement) {
-    update_zones(update_rs_time, update_rs_processed_buffers, goal_ms);
-    update_thread_thresholds();
-
-    // Change the barrier params
-    if (_n_worker_threads == 0) {
-      // Disable dcqs notification when there are no threads to notify.
-      dcqs.set_process_completed_threshold(INT_MAX);
-    } else {
-      // Worker 0 is the primary; wakeup is via dcqs notification.
-      STATIC_ASSERT(max_yellow_zone <= INT_MAX);
-      size_t activate = _threads[0]->activation_threshold();
-      dcqs.set_process_completed_threshold((int)activate);
-    }
-    dcqs.set_max_completed_queue((int)red_zone());
-  }
-
-  size_t curr_queue_size = dcqs.completed_buffers_num();
-  if (curr_queue_size >= yellow_zone()) {
-    dcqs.set_completed_queue_padding(curr_queue_size);
-  } else {
-    dcqs.set_completed_queue_padding(0);
-  }
-  dcqs.notify_if_necessary();
-}
--- a/src/hotspot/share/gc/g1/concurrentG1Refine.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * 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_CONCURRENTG1REFINE_HPP
-#define SHARE_VM_GC_G1_CONCURRENTG1REFINE_HPP
-
-#include "memory/allocation.hpp"
-#include "utilities/globalDefinitions.hpp"
-
-// Forward decl
-class CardTableEntryClosure;
-class ConcurrentG1RefineThread;
-class G1YoungRemSetSamplingThread;
-class outputStream;
-class ThreadClosure;
-
-class ConcurrentG1Refine: public CHeapObj<mtGC> {
-  G1YoungRemSetSamplingThread* _sample_thread;
-
-  ConcurrentG1RefineThread** _threads;
-  uint _n_worker_threads;
- /*
-  * The value of the update buffer queue length falls into one of 3 zones:
-  * green, yellow, red. If the value is in [0, green) nothing is
-  * done, the buffers are left unprocessed to enable the caching effect of the
-  * dirtied cards. In the yellow zone [green, yellow) the concurrent refinement
-  * threads are gradually activated. In [yellow, red) all threads are
-  * running. If the length becomes red (max queue length) the mutators start
-  * processing the buffers.
-  *
-  * There are some interesting cases (when G1UseAdaptiveConcRefinement
-  * is turned off):
-  * 1) green = yellow = red = 0. In this case the mutator will process all
-  *    buffers. Except for those that are created by the deferred updates
-  *    machinery during a collection.
-  * 2) green = 0. Means no caching. Can be a good way to minimize the
-  *    amount of time spent updating rsets during a collection.
-  */
-  size_t _green_zone;
-  size_t _yellow_zone;
-  size_t _red_zone;
-  size_t _min_yellow_zone_size;
-
-  ConcurrentG1Refine(size_t green_zone,
-                     size_t yellow_zone,
-                     size_t red_zone,
-                     size_t min_yellow_zone_size);
-
-  // Update green/yellow/red zone values based on how well goals are being met.
-  void update_zones(double update_rs_time,
-                    size_t update_rs_processed_buffers,
-                    double goal_ms);
-
-  // Update thread thresholds to account for updated zone values.
-  void update_thread_thresholds();
-
- public:
-  ~ConcurrentG1Refine();
-
-  // Returns ConcurrentG1Refine instance if succeeded to create/initialize ConcurrentG1Refine and ConcurrentG1RefineThread.
-  // Otherwise, returns NULL with error code.
-  static ConcurrentG1Refine* create(jint* ecode);
-
-  void stop();
-
-  void adjust(double update_rs_time, size_t update_rs_processed_buffers, double goal_ms);
-
-  // Iterate over all concurrent refinement threads
-  void threads_do(ThreadClosure *tc);
-
-  // Iterate over all worker refinement threads
-  void worker_threads_do(ThreadClosure * tc);
-
-  // The RS sampling thread has nothing to do with refinement, but is here for now.
-  G1YoungRemSetSamplingThread * sampling_thread() const { return _sample_thread; }
-
-  static uint thread_num();
-
-  void print_worker_threads_on(outputStream* st) const;
-
-  size_t green_zone() const      { return _green_zone;  }
-  size_t yellow_zone() const     { return _yellow_zone; }
-  size_t red_zone() const        { return _red_zone;    }
-};
-
-#endif // SHARE_VM_GC_G1_CONCURRENTG1REFINE_HPP
--- a/src/hotspot/share/gc/g1/concurrentG1RefineThread.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,174 +0,0 @@
-/*
- * 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
- * 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/concurrentG1Refine.hpp"
-#include "gc/g1/concurrentG1RefineThread.hpp"
-#include "gc/g1/g1CollectedHeap.inline.hpp"
-#include "gc/g1/g1RemSet.hpp"
-#include "gc/shared/suspendibleThreadSet.hpp"
-#include "logging/log.hpp"
-#include "memory/resourceArea.hpp"
-#include "runtime/handles.inline.hpp"
-#include "runtime/mutexLocker.hpp"
-
-ConcurrentG1RefineThread::
-ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next,
-                         uint worker_id_offset, uint worker_id,
-                         size_t activate, size_t deactivate) :
-  ConcurrentGCThread(),
-  _worker_id_offset(worker_id_offset),
-  _worker_id(worker_id),
-  _active(false),
-  _next(next),
-  _monitor(NULL),
-  _cg1r(cg1r),
-  _vtime_accum(0.0),
-  _activation_threshold(activate),
-  _deactivation_threshold(deactivate)
-{
-
-  // Each thread has its own monitor. The i-th thread is responsible for signaling
-  // to thread i+1 if the number of buffers in the queue exceeds a threshold for this
-  // thread. Monitors are also used to wake up the threads during termination.
-  // The 0th (primary) worker is notified by mutator threads and has a special monitor.
-  if (!is_primary()) {
-    _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true,
-                           Monitor::_safepoint_check_never);
-  } else {
-    _monitor = DirtyCardQ_CBL_mon;
-  }
-
-  // set name
-  set_name("G1 Refine#%d", worker_id);
-  create_and_start();
-}
-
-void ConcurrentG1RefineThread::update_thresholds(size_t activate,
-                                                 size_t deactivate) {
-  assert(deactivate < activate, "precondition");
-  _activation_threshold = activate;
-  _deactivation_threshold = deactivate;
-}
-
-void ConcurrentG1RefineThread::wait_for_completed_buffers() {
-  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
-  while (!should_terminate() && !is_active()) {
-    _monitor->wait(Mutex::_no_safepoint_check_flag);
-  }
-}
-
-bool ConcurrentG1RefineThread::is_active() {
-  DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
-  return is_primary() ? dcqs.process_completed_buffers() : _active;
-}
-
-void ConcurrentG1RefineThread::activate() {
-  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
-  if (!is_primary()) {
-    set_active(true);
-  } else {
-    DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
-    dcqs.set_process_completed(true);
-  }
-  _monitor->notify();
-}
-
-void ConcurrentG1RefineThread::deactivate() {
-  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
-  if (!is_primary()) {
-    set_active(false);
-  } else {
-    DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
-    dcqs.set_process_completed(false);
-  }
-}
-
-void ConcurrentG1RefineThread::run_service() {
-  _vtime_start = os::elapsedVTime();
-
-  while (!should_terminate()) {
-    // Wait for work
-    wait_for_completed_buffers();
-    if (should_terminate()) {
-      break;
-    }
-
-    size_t buffers_processed = 0;
-    DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
-    log_debug(gc, refine)("Activated %d, on threshold: " SIZE_FORMAT ", current: " SIZE_FORMAT,
-                          _worker_id, _activation_threshold, dcqs.completed_buffers_num());
-
-    {
-      SuspendibleThreadSetJoiner sts_join;
-
-      while (!should_terminate()) {
-        if (sts_join.should_yield()) {
-          sts_join.yield();
-          continue;             // Re-check for termination after yield delay.
-        }
-
-        size_t curr_buffer_num = dcqs.completed_buffers_num();
-        // If the number of the buffers falls down into the yellow zone,
-        // that means that the transition period after the evacuation pause has ended.
-        if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) {
-          dcqs.set_completed_queue_padding(0);
-        }
-
-        // Check if we need to activate the next thread.
-        if ((_next != NULL) &&
-            !_next->is_active() &&
-            (curr_buffer_num > _next->_activation_threshold)) {
-          _next->activate();
-        }
-
-        // Process the next buffer, if there are enough left.
-        if (!dcqs.refine_completed_buffer_concurrently(_worker_id + _worker_id_offset, _deactivation_threshold)) {
-          break; // Deactivate, number of buffers fell below threshold.
-        }
-        ++buffers_processed;
-      }
-    }
-
-    deactivate();
-    log_debug(gc, refine)("Deactivated %d, off threshold: " SIZE_FORMAT
-                          ", current: " SIZE_FORMAT ", processed: " SIZE_FORMAT,
-                          _worker_id, _deactivation_threshold,
-                          dcqs.completed_buffers_num(),
-                          buffers_processed);
-
-    if (os::supports_vtime()) {
-      _vtime_accum = (os::elapsedVTime() - _vtime_start);
-    } else {
-      _vtime_accum = 0.0;
-    }
-  }
-
-  log_debug(gc, refine)("Stopping %d", _worker_id);
-}
-
-void ConcurrentG1RefineThread::stop_service() {
-  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
-  _monitor->notify();
-}
--- a/src/hotspot/share/gc/g1/concurrentG1RefineThread.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * 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_CONCURRENTG1REFINETHREAD_HPP
-#define SHARE_VM_GC_G1_CONCURRENTG1REFINETHREAD_HPP
-
-#include "gc/g1/dirtyCardQueue.hpp"
-#include "gc/shared/concurrentGCThread.hpp"
-
-// Forward Decl.
-class CardTableEntryClosure;
-class ConcurrentG1Refine;
-
-// One or more G1 Concurrent Refinement Threads may be active if concurrent
-// refinement is in progress.
-class ConcurrentG1RefineThread: public ConcurrentGCThread {
-  friend class VMStructs;
-  friend class G1CollectedHeap;
-
-  double _vtime_start;  // Initial virtual time.
-  double _vtime_accum;  // Accumulated virtual time.
-  uint _worker_id;
-  uint _worker_id_offset;
-
-  // The refinement threads collection is linked list. A predecessor can activate a successor
-  // when the number of the rset update buffer crosses a certain threshold. A successor
-  // would self-deactivate when the number of the buffers falls below the threshold.
-  bool _active;
-  ConcurrentG1RefineThread* _next;
-  Monitor* _monitor;
-  ConcurrentG1Refine* _cg1r;
-
-  // This thread's activation/deactivation thresholds
-  size_t _activation_threshold;
-  size_t _deactivation_threshold;
-
-  void wait_for_completed_buffers();
-
-  void set_active(bool x) { _active = x; }
-  bool is_active();
-  void activate();
-  void deactivate();
-
-  bool is_primary() { return (_worker_id == 0); }
-
-  void run_service();
-  void stop_service();
-
-public:
-  // Constructor
-  ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread* next,
-                           uint worker_id_offset, uint worker_id,
-                           size_t activate, size_t deactivate);
-
-  void update_thresholds(size_t activate, size_t deactivate);
-  size_t activation_threshold() const { return _activation_threshold; }
-
-  // Total virtual time so far.
-  double vtime_accum() { return _vtime_accum; }
-
-  ConcurrentG1Refine* cg1r() { return _cg1r;     }
-};
-
-#endif // SHARE_VM_GC_G1_CONCURRENTG1REFINETHREAD_HPP
--- a/src/hotspot/share/gc/g1/concurrentMarkThread.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/concurrentMarkThread.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -111,16 +111,31 @@
   }
 };
 
-// Marking pauses can be scheduled flexibly, so we might delay marking to meet MMU.
+double ConcurrentMarkThread::mmu_sleep_time(G1Policy* g1_policy, bool remark) {
+  // There are 3 reasons to use SuspendibleThreadSetJoiner.
+  // 1. To avoid concurrency problem.
+  //    - G1MMUTracker::add_pause(), when_sec() and its variation(when_ms() etc..) can be called
+  //      concurrently from ConcurrentMarkThread and VMThread.
+  // 2. If currently a gc is running, but it has not yet updated the MMU,
+  //    we will not forget to consider that pause in the MMU calculation.
+  // 3. If currently a gc is running, ConcurrentMarkThread will wait it to be finished.
+  //    And then sleep for predicted amount of time by delay_to_keep_mmu().
+  SuspendibleThreadSetJoiner sts_join;
+
+  const G1Analytics* analytics = g1_policy->analytics();
+  double now = os::elapsedTime();
+  double prediction_ms = remark ? analytics->predict_remark_time_ms()
+                                : analytics->predict_cleanup_time_ms();
+  G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
+  return mmu_tracker->when_ms(now, prediction_ms);
+}
+
 void ConcurrentMarkThread::delay_to_keep_mmu(G1Policy* g1_policy, bool remark) {
-  const G1Analytics* analytics = g1_policy->analytics();
   if (g1_policy->adaptive_young_list_length()) {
-    double now = os::elapsedTime();
-    double prediction_ms = remark ? analytics->predict_remark_time_ms()
-                                  : analytics->predict_cleanup_time_ms();
-    G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
-    jlong sleep_time_ms = mmu_tracker->when_ms(now, prediction_ms);
-    os::sleep(this, sleep_time_ms, false);
+    jlong sleep_time_ms = mmu_sleep_time(g1_policy, remark);
+    if (!cm()->has_aborted() && sleep_time_ms > 0) {
+      os::sleep(this, sleep_time_ms, false);
+    }
   }
 }
 
@@ -349,9 +364,11 @@
       if (!cm()->has_aborted()) {
         delay_to_keep_mmu(g1_policy, false /* cleanup */);
 
-        CMCleanUp cl_cl(_cm);
-        VM_CGC_Operation op(&cl_cl, "Pause Cleanup");
-        VMThread::execute(&op);
+        if (!cm()->has_aborted()) {
+          CMCleanUp cl_cl(_cm);
+          VM_CGC_Operation op(&cl_cl, "Pause Cleanup");
+          VMThread::execute(&op);
+        }
       } else {
         // We don't want to update the marking status if a GC pause
         // is already underway.
--- a/src/hotspot/share/gc/g1/concurrentMarkThread.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/concurrentMarkThread.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -55,7 +55,9 @@
   ConcurrentGCPhaseManager::Stack _phase_manager_stack;
 
   void sleepBeforeNextCycle();
+  // Delay marking to meet MMU.
   void delay_to_keep_mmu(G1Policy* g1_policy, bool remark);
+  double mmu_sleep_time(G1Policy* g1_policy, bool remark);
 
   void run_service();
   void stop_service();
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -29,14 +29,14 @@
 #include "code/codeCache.hpp"
 #include "code/icBuffer.hpp"
 #include "gc/g1/bufferingOopClosure.hpp"
-#include "gc/g1/concurrentG1Refine.hpp"
-#include "gc/g1/concurrentG1RefineThread.hpp"
 #include "gc/g1/concurrentMarkThread.inline.hpp"
 #include "gc/g1/g1Allocator.inline.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
 #include "gc/g1/g1CollectionSet.hpp"
 #include "gc/g1/g1CollectorPolicy.hpp"
 #include "gc/g1/g1CollectorState.hpp"
+#include "gc/g1/g1ConcurrentRefine.hpp"
+#include "gc/g1/g1ConcurrentRefineThread.hpp"
 #include "gc/g1/g1EvacStats.inline.hpp"
 #include "gc/g1/g1FullGCScope.hpp"
 #include "gc/g1/g1GCPhaseTimes.hpp"
@@ -54,6 +54,7 @@
 #include "gc/g1/g1SerialFullCollector.hpp"
 #include "gc/g1/g1StringDedup.hpp"
 #include "gc/g1/g1YCTypes.hpp"
+#include "gc/g1/g1YoungRemSetSamplingThread.hpp"
 #include "gc/g1/heapRegion.inline.hpp"
 #include "gc/g1/heapRegionRemSet.hpp"
 #include "gc/g1/heapRegionSet.inline.hpp"
@@ -1541,6 +1542,7 @@
 
 G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* collector_policy) :
   CollectedHeap(),
+  _young_gen_sampling_thread(NULL),
   _collector_policy(collector_policy),
   _gc_timer_stw(new (ResourceObj::C_HEAP, mtGC) STWGCTimer()),
   _gc_tracer_stw(new (ResourceObj::C_HEAP, mtGC) G1NewTracer()),
@@ -1554,7 +1556,7 @@
   _bot(NULL),
   _hot_card_cache(NULL),
   _g1_rem_set(NULL),
-  _cg1r(NULL),
+  _cr(NULL),
   _g1mm(NULL),
   _preserved_marks_set(true /* in_c_heap */),
   _secondary_free_list("Secondary Free List", new SecondaryFreeRegionListMtSafeChecker()),
@@ -1633,10 +1635,19 @@
 
 jint G1CollectedHeap::initialize_concurrent_refinement() {
   jint ecode = JNI_OK;
-  _cg1r = ConcurrentG1Refine::create(&ecode);
+  _cr = G1ConcurrentRefine::create(&ecode);
   return ecode;
 }
 
+jint G1CollectedHeap::initialize_young_gen_sampling_thread() {
+  _young_gen_sampling_thread = new G1YoungRemSetSamplingThread();
+  if (_young_gen_sampling_thread->osthread() == NULL) {
+    vm_shutdown_during_initialization("Could not create G1YoungRemSetSamplingThread");
+    return JNI_ENOMEM;
+  }
+  return JNI_OK;
+}
+
 jint G1CollectedHeap::initialize() {
   CollectedHeap::pre_initialize();
   os::enable_vtime();
@@ -1789,10 +1800,15 @@
     return ecode;
   }
 
+  ecode = initialize_young_gen_sampling_thread();
+  if (ecode != JNI_OK) {
+    return ecode;
+  }
+
   JavaThread::dirty_card_queue_set().initialize(DirtyCardQ_CBL_mon,
                                                 DirtyCardQ_FL_lock,
-                                                (int)concurrent_g1_refine()->yellow_zone(),
-                                                (int)concurrent_g1_refine()->red_zone(),
+                                                (int)concurrent_refine()->yellow_zone(),
+                                                (int)concurrent_refine()->red_zone(),
                                                 Shared_DirtyCardQ_lock,
                                                 NULL,  // fl_owner
                                                 true); // init_free_ids
@@ -1836,7 +1852,8 @@
   // Stop all concurrent threads. We do this to make sure these threads
   // do not continue to execute and access resources (e.g. logging)
   // that are destroyed during shutdown.
-  _cg1r->stop();
+  _cr->stop();
+  _young_gen_sampling_thread->stop();
   _cmThread->stop();
   if (G1StringDedup::is_enabled()) {
     G1StringDedup::stop();
@@ -2390,9 +2407,8 @@
   st->print(" %-20s", "garbage-first heap");
   st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
             capacity()/K, used_unlocked()/K);
-  st->print(" [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ")",
+  st->print(" [" PTR_FORMAT ", " PTR_FORMAT ")",
             p2i(_hrm.reserved().start()),
-            p2i(_hrm.reserved().start() + _hrm.length() + HeapRegion::GrainWords),
             p2i(_hrm.reserved().end()));
   st->cr();
   st->print("  region size " SIZE_FORMAT "K, ", HeapRegion::GrainBytes / K);
@@ -2437,7 +2453,8 @@
   _cmThread->print_on(st);
   st->cr();
   _cm->print_worker_threads_on(st);
-  _cg1r->print_worker_threads_on(st); // also prints the sample thread
+  _cr->print_threads_on(st);
+  _young_gen_sampling_thread->print_on(st);
   if (G1StringDedup::is_enabled()) {
     G1StringDedup::print_worker_threads_on(st);
   }
@@ -2447,7 +2464,8 @@
   workers()->threads_do(tc);
   tc->do_thread(_cmThread);
   _cm->threads_do(tc);
-  _cg1r->threads_do(tc); // also iterates over the sample thread
+  _cr->threads_do(tc);
+  tc->do_thread(_young_gen_sampling_thread);
   if (G1StringDedup::is_enabled()) {
     G1StringDedup::threads_do(tc);
   }
@@ -2579,7 +2597,7 @@
   // FIXME: what is this about?
   // I'm ignoring the "fill_newgen()" call if "alloc_event_enabled"
   // is set.
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   assert(DerivedPointerTable::is_empty(), "derived pointer present");
 #endif
   // always_do_update_barrier = true;
@@ -2992,7 +3010,7 @@
 
       _verifier->check_bitmaps("GC Start");
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
       DerivedPointerTable::clear();
 #endif
 
@@ -3622,7 +3640,7 @@
 
 class G1KlassCleaningTask : public StackObj {
   BoolObjectClosure*                      _is_alive;
-  volatile jint                           _clean_klass_tree_claimed;
+  volatile int                            _clean_klass_tree_claimed;
   ClassLoaderDataGraphKlassIteratorAtomic _klass_iterator;
 
  public:
@@ -3638,7 +3656,7 @@
       return false;
     }
 
-    return Atomic::cmpxchg(1, (jint*)&_clean_klass_tree_claimed, 0) == 0;
+    return Atomic::cmpxchg(1, &_clean_klass_tree_claimed, 0) == 0;
   }
 
   InstanceKlass* claim_next_klass() {
@@ -3675,7 +3693,7 @@
 
 class G1ResolvedMethodCleaningTask : public StackObj {
   BoolObjectClosure* _is_alive;
-  volatile jint      _resolved_method_task_claimed;
+  volatile int       _resolved_method_task_claimed;
 public:
   G1ResolvedMethodCleaningTask(BoolObjectClosure* is_alive) :
       _is_alive(is_alive), _resolved_method_task_claimed(0) {}
@@ -3684,7 +3702,7 @@
     if (_resolved_method_task_claimed) {
       return false;
     }
-    return Atomic::cmpxchg(1, (jint*)&_resolved_method_task_claimed, 0) == 0;
+    return Atomic::cmpxchg(1, &_resolved_method_task_claimed, 0) == 0;
   }
 
   // These aren't big, one thread can do it all.
@@ -4421,7 +4439,7 @@
   purge_code_root_memory();
 
   redirty_logged_cards();
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   double start = os::elapsedTime();
   DerivedPointerTable::update_pointers();
   g1_policy()->phase_times()->record_derived_pointer_table_update_time((os::elapsedTime() - start) * 1000.0);
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -73,10 +73,11 @@
 class G1Policy;
 class G1HotCardCache;
 class G1RemSet;
+class G1YoungRemSetSamplingThread;
 class HeapRegionRemSetIterator;
 class G1ConcurrentMark;
 class ConcurrentMarkThread;
-class ConcurrentG1Refine;
+class G1ConcurrentRefine;
 class GenerationCounters;
 class STWGCTimer;
 class G1NewTracer;
@@ -142,6 +143,8 @@
   friend class G1CheckCSetFastTableClosure;
 
 private:
+  G1YoungRemSetSamplingThread* _young_gen_sampling_thread;
+
   WorkGang* _workers;
   G1CollectorPolicy* _collector_policy;
 
@@ -553,6 +556,8 @@
   // during GC into global variables.
   void merge_per_thread_state_info(G1ParScanThreadStateSet* per_thread_states);
 public:
+  G1YoungRemSetSamplingThread* sampling_thread() const { return _young_gen_sampling_thread; }
+
   WorkGang* workers() const { return _workers; }
 
   G1Allocator* allocator() {
@@ -806,7 +811,7 @@
   ConcurrentMarkThread* _cmThread;
 
   // The concurrent refiner.
-  ConcurrentG1Refine* _cg1r;
+  G1ConcurrentRefine* _cr;
 
   // The parallel task queues
   RefToScanQueueSet *_task_queues;
@@ -959,6 +964,7 @@
 
 private:
   jint initialize_concurrent_refinement();
+  jint initialize_young_gen_sampling_thread();
 public:
   // Initialize the G1CollectedHeap to have the initial and
   // maximum sizes and remembered and barrier sets
@@ -1389,7 +1395,7 @@
 
   // Refinement
 
-  ConcurrentG1Refine* concurrent_g1_refine() const { return _cg1r; }
+  G1ConcurrentRefine* concurrent_refine() const { return _cr; }
 
   // Optimized nmethod scanning support routines
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -0,0 +1,351 @@
+/*
+ * 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
+ * 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/g1ConcurrentRefine.hpp"
+#include "gc/g1/g1ConcurrentRefineThread.hpp"
+#include "logging/log.hpp"
+#include "runtime/java.hpp"
+#include "runtime/thread.hpp"
+#include "utilities/debug.hpp"
+#include "utilities/globalDefinitions.hpp"
+#include "utilities/pair.hpp"
+#include <math.h>
+
+// Arbitrary but large limits, to simplify some of the zone calculations.
+// The general idea is to allow expressions like
+//   MIN2(x OP y, max_XXX_zone)
+// without needing to check for overflow in "x OP y", because the
+// ranges for x and y have been restricted.
+STATIC_ASSERT(sizeof(LP64_ONLY(jint) NOT_LP64(jshort)) <= (sizeof(size_t)/2));
+const size_t max_yellow_zone = LP64_ONLY(max_jint) NOT_LP64(max_jshort);
+const size_t max_green_zone = max_yellow_zone / 2;
+const size_t max_red_zone = INT_MAX; // For dcqs.set_max_completed_queue.
+STATIC_ASSERT(max_yellow_zone <= max_red_zone);
+
+// Range check assertions for green zone values.
+#define assert_zone_constraints_g(green)                        \
+  do {                                                          \
+    size_t azc_g_green = (green);                               \
+    assert(azc_g_green <= max_green_zone,                       \
+           "green exceeds max: " SIZE_FORMAT, azc_g_green);     \
+  } while (0)
+
+// Range check assertions for green and yellow zone values.
+#define assert_zone_constraints_gy(green, yellow)                       \
+  do {                                                                  \
+    size_t azc_gy_green = (green);                                      \
+    size_t azc_gy_yellow = (yellow);                                    \
+    assert_zone_constraints_g(azc_gy_green);                            \
+    assert(azc_gy_yellow <= max_yellow_zone,                            \
+           "yellow exceeds max: " SIZE_FORMAT, azc_gy_yellow);          \
+    assert(azc_gy_green <= azc_gy_yellow,                               \
+           "green (" SIZE_FORMAT ") exceeds yellow (" SIZE_FORMAT ")",  \
+           azc_gy_green, azc_gy_yellow);                                \
+  } while (0)
+
+// Range check assertions for green, yellow, and red zone values.
+#define assert_zone_constraints_gyr(green, yellow, red)                 \
+  do {                                                                  \
+    size_t azc_gyr_green = (green);                                     \
+    size_t azc_gyr_yellow = (yellow);                                   \
+    size_t azc_gyr_red = (red);                                         \
+    assert_zone_constraints_gy(azc_gyr_green, azc_gyr_yellow);          \
+    assert(azc_gyr_red <= max_red_zone,                                 \
+           "red exceeds max: " SIZE_FORMAT, azc_gyr_red);               \
+    assert(azc_gyr_yellow <= azc_gyr_red,                               \
+           "yellow (" SIZE_FORMAT ") exceeds red (" SIZE_FORMAT ")",    \
+           azc_gyr_yellow, azc_gyr_red);                                \
+  } while (0)
+
+// Logging tag sequence for refinement control updates.
+#define CTRL_TAGS gc, ergo, refine
+
+// For logging zone values, ensuring consistency of level and tags.
+#define LOG_ZONES(...) log_debug( CTRL_TAGS )(__VA_ARGS__)
+
+// Package for pair of refinement thread activation and deactivation
+// thresholds.  The activation and deactivation levels are resp. the first
+// and second values of the pair.
+typedef Pair<size_t, size_t> Thresholds;
+inline size_t activation_level(const Thresholds& t) { return t.first; }
+inline size_t deactivation_level(const Thresholds& t) { return t.second; }
+
+static Thresholds calc_thresholds(size_t green_zone,
+                                  size_t yellow_zone,
+                                  uint worker_i) {
+  double yellow_size = yellow_zone - green_zone;
+  double step = yellow_size / G1ConcurrentRefine::thread_num();
+  if (worker_i == 0) {
+    // Potentially activate worker 0 more aggressively, to keep
+    // available buffers near green_zone value.  When yellow_size is
+    // large we don't want to allow a full step to accumulate before
+    // doing any processing, as that might lead to significantly more
+    // than green_zone buffers to be processed by update_rs.
+    step = MIN2(step, ParallelGCThreads / 2.0);
+  }
+  size_t activate_offset = static_cast<size_t>(ceil(step * (worker_i + 1)));
+  size_t deactivate_offset = static_cast<size_t>(floor(step * worker_i));
+  return Thresholds(green_zone + activate_offset,
+                    green_zone + deactivate_offset);
+}
+
+G1ConcurrentRefine::G1ConcurrentRefine(size_t green_zone,
+                                       size_t yellow_zone,
+                                       size_t red_zone,
+                                       size_t min_yellow_zone_size) :
+  _threads(NULL),
+  _n_worker_threads(thread_num()),
+  _green_zone(green_zone),
+  _yellow_zone(yellow_zone),
+  _red_zone(red_zone),
+  _min_yellow_zone_size(min_yellow_zone_size)
+{
+  assert_zone_constraints_gyr(green_zone, yellow_zone, red_zone);
+}
+
+static size_t calc_min_yellow_zone_size() {
+  size_t step = G1ConcRefinementThresholdStep;
+  uint n_workers = G1ConcurrentRefine::thread_num();
+  if ((max_yellow_zone / step) < n_workers) {
+    return max_yellow_zone;
+  } else {
+    return step * n_workers;
+  }
+}
+
+static size_t calc_init_green_zone() {
+  size_t green = G1ConcRefinementGreenZone;
+  if (FLAG_IS_DEFAULT(G1ConcRefinementGreenZone)) {
+    green = ParallelGCThreads;
+  }
+  return MIN2(green, max_green_zone);
+}
+
+static size_t calc_init_yellow_zone(size_t green, size_t min_size) {
+  size_t config = G1ConcRefinementYellowZone;
+  size_t size = 0;
+  if (FLAG_IS_DEFAULT(G1ConcRefinementYellowZone)) {
+    size = green * 2;
+  } else if (green < config) {
+    size = config - green;
+  }
+  size = MAX2(size, min_size);
+  size = MIN2(size, max_yellow_zone);
+  return MIN2(green + size, max_yellow_zone);
+}
+
+static size_t calc_init_red_zone(size_t green, size_t yellow) {
+  size_t size = yellow - green;
+  if (!FLAG_IS_DEFAULT(G1ConcRefinementRedZone)) {
+    size_t config = G1ConcRefinementRedZone;
+    if (yellow < config) {
+      size = MAX2(size, config - yellow);
+    }
+  }
+  return MIN2(yellow + size, max_red_zone);
+}
+
+G1ConcurrentRefine* G1ConcurrentRefine::create(jint* ecode) {
+  size_t min_yellow_zone_size = calc_min_yellow_zone_size();
+  size_t green_zone = calc_init_green_zone();
+  size_t yellow_zone = calc_init_yellow_zone(green_zone, min_yellow_zone_size);
+  size_t red_zone = calc_init_red_zone(green_zone, yellow_zone);
+
+  LOG_ZONES("Initial Refinement Zones: "
+            "green: " SIZE_FORMAT ", "
+            "yellow: " SIZE_FORMAT ", "
+            "red: " SIZE_FORMAT ", "
+            "min yellow size: " SIZE_FORMAT,
+            green_zone, yellow_zone, red_zone, min_yellow_zone_size);
+
+  G1ConcurrentRefine* cr = new G1ConcurrentRefine(green_zone,
+                                                  yellow_zone,
+                                                  red_zone,
+                                                  min_yellow_zone_size);
+
+  if (cr == NULL) {
+    *ecode = JNI_ENOMEM;
+    vm_shutdown_during_initialization("Could not create G1ConcurrentRefine");
+    return NULL;
+  }
+
+  cr->_threads = NEW_C_HEAP_ARRAY_RETURN_NULL(G1ConcurrentRefineThread*, cr->_n_worker_threads, mtGC);
+  if (cr->_threads == NULL) {
+    *ecode = JNI_ENOMEM;
+    vm_shutdown_during_initialization("Could not allocate an array for G1ConcurrentRefineThread");
+    return NULL;
+  }
+
+  uint worker_id_offset = DirtyCardQueueSet::num_par_ids();
+
+  G1ConcurrentRefineThread *next = NULL;
+  for (uint i = cr->_n_worker_threads - 1; i != UINT_MAX; i--) {
+    Thresholds thresholds = calc_thresholds(green_zone, yellow_zone, i);
+    G1ConcurrentRefineThread* t =
+      new G1ConcurrentRefineThread(cr,
+                                   next,
+                                   worker_id_offset,
+                                   i,
+                                   activation_level(thresholds),
+                                   deactivation_level(thresholds));
+    assert(t != NULL, "Conc refine should have been created");
+    if (t->osthread() == NULL) {
+      *ecode = JNI_ENOMEM;
+      vm_shutdown_during_initialization("Could not create G1ConcurrentRefineThread");
+      return NULL;
+    }
+
+    assert(t->cr() == cr, "Conc refine thread should refer to this");
+    cr->_threads[i] = t;
+    next = t;
+  }
+
+  *ecode = JNI_OK;
+  return cr;
+}
+
+void G1ConcurrentRefine::stop() {
+  for (uint i = 0; i < _n_worker_threads; i++) {
+    _threads[i]->stop();
+  }
+}
+
+void G1ConcurrentRefine::update_thread_thresholds() {
+  for (uint i = 0; i < _n_worker_threads; i++) {
+    Thresholds thresholds = calc_thresholds(_green_zone, _yellow_zone, i);
+    _threads[i]->update_thresholds(activation_level(thresholds),
+                                   deactivation_level(thresholds));
+  }
+}
+
+G1ConcurrentRefine::~G1ConcurrentRefine() {
+  for (uint i = 0; i < _n_worker_threads; i++) {
+    delete _threads[i];
+  }
+  FREE_C_HEAP_ARRAY(G1ConcurrentRefineThread*, _threads);
+}
+
+void G1ConcurrentRefine::threads_do(ThreadClosure *tc) {
+  for (uint i = 0; i < _n_worker_threads; i++) {
+    tc->do_thread(_threads[i]);
+  }
+}
+
+uint G1ConcurrentRefine::thread_num() {
+  return G1ConcRefinementThreads;
+}
+
+void G1ConcurrentRefine::print_threads_on(outputStream* st) const {
+  for (uint i = 0; i < _n_worker_threads; ++i) {
+    _threads[i]->print_on(st);
+    st->cr();
+  }
+}
+
+static size_t calc_new_green_zone(size_t green,
+                                  double update_rs_time,
+                                  size_t update_rs_processed_buffers,
+                                  double goal_ms) {
+  // Adjust green zone based on whether we're meeting the time goal.
+  // Limit to max_green_zone.
+  const double inc_k = 1.1, dec_k = 0.9;
+  if (update_rs_time > goal_ms) {
+    if (green > 0) {
+      green = static_cast<size_t>(green * dec_k);
+    }
+  } else if (update_rs_time < goal_ms &&
+             update_rs_processed_buffers > green) {
+    green = static_cast<size_t>(MAX2(green * inc_k, green + 1.0));
+    green = MIN2(green, max_green_zone);
+  }
+  return green;
+}
+
+static size_t calc_new_yellow_zone(size_t green, size_t min_yellow_size) {
+  size_t size = green * 2;
+  size = MAX2(size, min_yellow_size);
+  return MIN2(green + size, max_yellow_zone);
+}
+
+static size_t calc_new_red_zone(size_t green, size_t yellow) {
+  return MIN2(yellow + (yellow - green), max_red_zone);
+}
+
+void G1ConcurrentRefine::update_zones(double update_rs_time,
+                                      size_t update_rs_processed_buffers,
+                                      double goal_ms) {
+  log_trace( CTRL_TAGS )("Updating Refinement Zones: "
+                         "update_rs time: %.3fms, "
+                         "update_rs buffers: " SIZE_FORMAT ", "
+                         "update_rs goal time: %.3fms",
+                         update_rs_time,
+                         update_rs_processed_buffers,
+                         goal_ms);
+
+  _green_zone = calc_new_green_zone(_green_zone,
+                                    update_rs_time,
+                                    update_rs_processed_buffers,
+                                    goal_ms);
+  _yellow_zone = calc_new_yellow_zone(_green_zone, _min_yellow_zone_size);
+  _red_zone = calc_new_red_zone(_green_zone, _yellow_zone);
+
+  assert_zone_constraints_gyr(_green_zone, _yellow_zone, _red_zone);
+  LOG_ZONES("Updated Refinement Zones: "
+            "green: " SIZE_FORMAT ", "
+            "yellow: " SIZE_FORMAT ", "
+            "red: " SIZE_FORMAT,
+            _green_zone, _yellow_zone, _red_zone);
+}
+
+void G1ConcurrentRefine::adjust(double update_rs_time,
+                                size_t update_rs_processed_buffers,
+                                double goal_ms) {
+  DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
+
+  if (G1UseAdaptiveConcRefinement) {
+    update_zones(update_rs_time, update_rs_processed_buffers, goal_ms);
+    update_thread_thresholds();
+
+    // Change the barrier params
+    if (_n_worker_threads == 0) {
+      // Disable dcqs notification when there are no threads to notify.
+      dcqs.set_process_completed_threshold(INT_MAX);
+    } else {
+      // Worker 0 is the primary; wakeup is via dcqs notification.
+      STATIC_ASSERT(max_yellow_zone <= INT_MAX);
+      size_t activate = _threads[0]->activation_threshold();
+      dcqs.set_process_completed_threshold((int)activate);
+    }
+    dcqs.set_max_completed_queue((int)red_zone());
+  }
+
+  size_t curr_queue_size = dcqs.completed_buffers_num();
+  if (curr_queue_size >= yellow_zone()) {
+    dcqs.set_completed_queue_padding(curr_queue_size);
+  } else {
+    dcqs.set_completed_queue_padding(0);
+  }
+  dcqs.notify_if_necessary();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1ConcurrentRefine.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -0,0 +1,98 @@
+/*
+ * 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
+ * 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_G1CONCURRENTREFINE_HPP
+#define SHARE_VM_GC_G1_G1CONCURRENTREFINE_HPP
+
+#include "memory/allocation.hpp"
+#include "utilities/globalDefinitions.hpp"
+
+// Forward decl
+class CardTableEntryClosure;
+class G1ConcurrentRefineThread;
+class outputStream;
+class ThreadClosure;
+
+class G1ConcurrentRefine : public CHeapObj<mtGC> {
+  G1ConcurrentRefineThread** _threads;
+  uint _n_worker_threads;
+ /*
+  * The value of the update buffer queue length falls into one of 3 zones:
+  * green, yellow, red. If the value is in [0, green) nothing is
+  * done, the buffers are left unprocessed to enable the caching effect of the
+  * dirtied cards. In the yellow zone [green, yellow) the concurrent refinement
+  * threads are gradually activated. In [yellow, red) all threads are
+  * running. If the length becomes red (max queue length) the mutators start
+  * processing the buffers.
+  *
+  * There are some interesting cases (when G1UseAdaptiveConcRefinement
+  * is turned off):
+  * 1) green = yellow = red = 0. In this case the mutator will process all
+  *    buffers. Except for those that are created by the deferred updates
+  *    machinery during a collection.
+  * 2) green = 0. Means no caching. Can be a good way to minimize the
+  *    amount of time spent updating rsets during a collection.
+  */
+  size_t _green_zone;
+  size_t _yellow_zone;
+  size_t _red_zone;
+  size_t _min_yellow_zone_size;
+
+  G1ConcurrentRefine(size_t green_zone,
+                     size_t yellow_zone,
+                     size_t red_zone,
+                     size_t min_yellow_zone_size);
+
+  // Update green/yellow/red zone values based on how well goals are being met.
+  void update_zones(double update_rs_time,
+                    size_t update_rs_processed_buffers,
+                    double goal_ms);
+
+  // Update thread thresholds to account for updated zone values.
+  void update_thread_thresholds();
+
+ public:
+  ~G1ConcurrentRefine();
+
+  // Returns a G1ConcurrentRefine instance if succeeded to create/initialize G1ConcurrentRefine and G1ConcurrentRefineThreads.
+  // Otherwise, returns NULL with error code.
+  static G1ConcurrentRefine* create(jint* ecode);
+
+  void stop();
+
+  void adjust(double update_rs_time, size_t update_rs_processed_buffers, double goal_ms);
+
+  // Iterate over all concurrent refinement threads applying the given closure.
+  void threads_do(ThreadClosure *tc);
+
+  static uint thread_num();
+
+  void print_threads_on(outputStream* st) const;
+
+  size_t green_zone() const      { return _green_zone;  }
+  size_t yellow_zone() const     { return _yellow_zone; }
+  size_t red_zone() const        { return _red_zone;    }
+};
+
+#endif // SHARE_VM_GC_G1_G1CONCURRENTREFINE_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -0,0 +1,176 @@
+/*
+ * 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
+ * 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/g1ConcurrentRefine.hpp"
+#include "gc/g1/g1ConcurrentRefineThread.hpp"
+#include "gc/g1/g1CollectedHeap.inline.hpp"
+#include "gc/g1/g1RemSet.hpp"
+#include "gc/shared/suspendibleThreadSet.hpp"
+#include "logging/log.hpp"
+#include "memory/resourceArea.hpp"
+#include "runtime/handles.inline.hpp"
+#include "runtime/mutexLocker.hpp"
+
+G1ConcurrentRefineThread::G1ConcurrentRefineThread(G1ConcurrentRefine* cr,
+                                                   G1ConcurrentRefineThread *next,
+                                                   uint worker_id_offset,
+                                                   uint worker_id,
+                                                   size_t activate,
+                                                   size_t deactivate) :
+  ConcurrentGCThread(),
+  _worker_id_offset(worker_id_offset),
+  _worker_id(worker_id),
+  _active(false),
+  _next(next),
+  _monitor(NULL),
+  _cr(cr),
+  _vtime_accum(0.0),
+  _activation_threshold(activate),
+  _deactivation_threshold(deactivate)
+{
+
+  // Each thread has its own monitor. The i-th thread is responsible for signaling
+  // to thread i+1 if the number of buffers in the queue exceeds a threshold for this
+  // thread. Monitors are also used to wake up the threads during termination.
+  // The 0th (primary) worker is notified by mutator threads and has a special monitor.
+  if (!is_primary()) {
+    _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true,
+                           Monitor::_safepoint_check_never);
+  } else {
+    _monitor = DirtyCardQ_CBL_mon;
+  }
+
+  // set name
+  set_name("G1 Refine#%d", worker_id);
+  create_and_start();
+}
+
+void G1ConcurrentRefineThread::update_thresholds(size_t activate,
+                                                 size_t deactivate) {
+  assert(deactivate < activate, "precondition");
+  _activation_threshold = activate;
+  _deactivation_threshold = deactivate;
+}
+
+void G1ConcurrentRefineThread::wait_for_completed_buffers() {
+  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
+  while (!should_terminate() && !is_active()) {
+    _monitor->wait(Mutex::_no_safepoint_check_flag);
+  }
+}
+
+bool G1ConcurrentRefineThread::is_active() {
+  DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
+  return is_primary() ? dcqs.process_completed_buffers() : _active;
+}
+
+void G1ConcurrentRefineThread::activate() {
+  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
+  if (!is_primary()) {
+    set_active(true);
+  } else {
+    DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
+    dcqs.set_process_completed(true);
+  }
+  _monitor->notify();
+}
+
+void G1ConcurrentRefineThread::deactivate() {
+  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
+  if (!is_primary()) {
+    set_active(false);
+  } else {
+    DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
+    dcqs.set_process_completed(false);
+  }
+}
+
+void G1ConcurrentRefineThread::run_service() {
+  _vtime_start = os::elapsedVTime();
+
+  while (!should_terminate()) {
+    // Wait for work
+    wait_for_completed_buffers();
+    if (should_terminate()) {
+      break;
+    }
+
+    size_t buffers_processed = 0;
+    DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
+    log_debug(gc, refine)("Activated %d, on threshold: " SIZE_FORMAT ", current: " SIZE_FORMAT,
+                          _worker_id, _activation_threshold, dcqs.completed_buffers_num());
+
+    {
+      SuspendibleThreadSetJoiner sts_join;
+
+      while (!should_terminate()) {
+        if (sts_join.should_yield()) {
+          sts_join.yield();
+          continue;             // Re-check for termination after yield delay.
+        }
+
+        size_t curr_buffer_num = dcqs.completed_buffers_num();
+        // If the number of the buffers falls down into the yellow zone,
+        // that means that the transition period after the evacuation pause has ended.
+        if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cr()->yellow_zone()) {
+          dcqs.set_completed_queue_padding(0);
+        }
+
+        // Check if we need to activate the next thread.
+        if ((_next != NULL) &&
+            !_next->is_active() &&
+            (curr_buffer_num > _next->_activation_threshold)) {
+          _next->activate();
+        }
+
+        // Process the next buffer, if there are enough left.
+        if (!dcqs.refine_completed_buffer_concurrently(_worker_id + _worker_id_offset, _deactivation_threshold)) {
+          break; // Deactivate, number of buffers fell below threshold.
+        }
+        ++buffers_processed;
+      }
+    }
+
+    deactivate();
+    log_debug(gc, refine)("Deactivated %d, off threshold: " SIZE_FORMAT
+                          ", current: " SIZE_FORMAT ", processed: " SIZE_FORMAT,
+                          _worker_id, _deactivation_threshold,
+                          dcqs.completed_buffers_num(),
+                          buffers_processed);
+
+    if (os::supports_vtime()) {
+      _vtime_accum = (os::elapsedVTime() - _vtime_start);
+    } else {
+      _vtime_accum = 0.0;
+    }
+  }
+
+  log_debug(gc, refine)("Stopping %d", _worker_id);
+}
+
+void G1ConcurrentRefineThread::stop_service() {
+  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
+  _monitor->notify();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -0,0 +1,85 @@
+/*
+ * 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
+ * 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_G1CONCURRENTREFINETHREAD_HPP
+#define SHARE_VM_GC_G1_G1CONCURRENTREFINETHREAD_HPP
+
+#include "gc/g1/dirtyCardQueue.hpp"
+#include "gc/shared/concurrentGCThread.hpp"
+
+// Forward Decl.
+class CardTableEntryClosure;
+class G1ConcurrentRefine;
+
+// One or more G1 Concurrent Refinement Threads may be active if concurrent
+// refinement is in progress.
+class G1ConcurrentRefineThread: public ConcurrentGCThread {
+  friend class VMStructs;
+  friend class G1CollectedHeap;
+
+  double _vtime_start;  // Initial virtual time.
+  double _vtime_accum;  // Accumulated virtual time.
+  uint _worker_id;
+  uint _worker_id_offset;
+
+  // The refinement threads collection is linked list. A predecessor can activate a successor
+  // when the number of the rset update buffer crosses a certain threshold. A successor
+  // would self-deactivate when the number of the buffers falls below the threshold.
+  bool _active;
+  G1ConcurrentRefineThread* _next;
+  Monitor* _monitor;
+  G1ConcurrentRefine* _cr;
+
+  // This thread's activation/deactivation thresholds
+  size_t _activation_threshold;
+  size_t _deactivation_threshold;
+
+  void wait_for_completed_buffers();
+
+  void set_active(bool x) { _active = x; }
+  bool is_active();
+  void activate();
+  void deactivate();
+
+  bool is_primary() { return (_worker_id == 0); }
+
+  void run_service();
+  void stop_service();
+
+public:
+  // Constructor
+  G1ConcurrentRefineThread(G1ConcurrentRefine* cr, G1ConcurrentRefineThread* next,
+                           uint worker_id_offset, uint worker_id,
+                           size_t activate, size_t deactivate);
+
+  void update_thresholds(size_t activate, size_t deactivate);
+  size_t activation_threshold() const { return _activation_threshold; }
+
+  // Total virtual time so far.
+  double vtime_accum() { return _vtime_accum; }
+
+  G1ConcurrentRefine* cr() { return _cr;     }
+};
+
+#endif // SHARE_VM_GC_G1_G1CONCURRENTREFINETHREAD_HPP
--- a/src/hotspot/share/gc/g1/g1DefaultPolicy.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1DefaultPolicy.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,12 +23,12 @@
  */
 
 #include "precompiled.hpp"
-#include "gc/g1/concurrentG1Refine.hpp"
 #include "gc/g1/concurrentMarkThread.inline.hpp"
 #include "gc/g1/g1Analytics.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
 #include "gc/g1/g1CollectionSet.hpp"
 #include "gc/g1/g1ConcurrentMark.hpp"
+#include "gc/g1/g1ConcurrentRefine.hpp"
 #include "gc/g1/g1DefaultPolicy.hpp"
 #include "gc/g1/g1HotCardCache.hpp"
 #include "gc/g1/g1IHOPControl.hpp"
@@ -745,7 +745,7 @@
   } else {
     update_rs_time_goal_ms -= scan_hcc_time_ms;
   }
-  _g1->concurrent_g1_refine()->adjust(average_time_ms(G1GCPhaseTimes::UpdateRS) - scan_hcc_time_ms,
+  _g1->concurrent_refine()->adjust(average_time_ms(G1GCPhaseTimes::UpdateRS) - scan_hcc_time_ms,
                                       phase_times()->sum_thread_work_items(G1GCPhaseTimes::UpdateRS),
                                       update_rs_time_goal_ms);
 
--- a/src/hotspot/share/gc/g1/g1GCPhaseTimes.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1GCPhaseTimes.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -414,7 +414,7 @@
 
   debug_time("Redirty Cards", _recorded_redirty_logged_cards_time_ms);
   trace_phase(_gc_par_phases[RedirtyCards]);
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   debug_time("DerivedPointerTable Update", _cur_derived_pointer_table_update_time_ms);
 #endif
 
--- a/src/hotspot/share/gc/g1/g1MMUTracker.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1MMUTracker.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -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
@@ -112,19 +112,7 @@
   }
 }
 
-// basically the _internal call does not remove expired entries
-// this is for trying things out in the future and a couple
-// of other places (debugging)
-
 double G1MMUTrackerQueue::when_sec(double current_time, double pause_time) {
-  MutexLockerEx x(MMUTracker_lock, Mutex::_no_safepoint_check_flag);
-  remove_expired_entries(current_time);
-
-  return when_internal(current_time, pause_time);
-}
-
-double G1MMUTrackerQueue::when_internal(double current_time,
-                                        double pause_time) {
   // if the pause is over the maximum, just assume that it's the maximum
   double adjusted_pause_time =
     (pause_time > max_gc_time()) ? max_gc_time() : pause_time;
--- a/src/hotspot/share/gc/g1/g1MMUTracker.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1MMUTracker.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -134,8 +134,6 @@
   void remove_expired_entries(double current_time);
   double calculate_gc_time(double current_time);
 
-  double when_internal(double current_time, double pause_time);
-
 public:
   G1MMUTrackerQueue(double time_slice, double max_gc_time);
 
--- a/src/hotspot/share/gc/g1/g1MarkSweep.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1MarkSweep.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -62,7 +62,7 @@
   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
   HandleMark hm;  // Discard invalid handles created during gc
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   DerivedPointerTable::clear();
 #endif
 #ifdef ASSERT
@@ -96,7 +96,7 @@
   // Prepare compaction.
   mark_sweep_phase2();
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   // Don't add any more derived pointers during phase3
   DerivedPointerTable::set_active(false);
 #endif
@@ -111,7 +111,7 @@
   BiasedLocking::restore_marks();
   GenMarkSweep::deallocate_stacks();
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   // Now update the derived pointers.
   DerivedPointerTable::update_pointers();
 #endif
@@ -204,7 +204,7 @@
 
   if (VerifyDuringGC) {
     HandleMark hm;  // handle scope
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
     DerivedPointerTableDeactivate dpt_deact;
 #endif
     g1h->prepare_for_verify();
--- a/src/hotspot/share/gc/g1/g1RemSet.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1RemSet.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,10 +23,10 @@
  */
 
 #include "precompiled.hpp"
-#include "gc/g1/concurrentG1Refine.hpp"
 #include "gc/g1/dirtyCardQueue.hpp"
 #include "gc/g1/g1BlockOffsetTable.inline.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
+#include "gc/g1/g1ConcurrentRefine.hpp"
 #include "gc/g1/g1FromCardCache.hpp"
 #include "gc/g1/g1GCPhaseTimes.hpp"
 #include "gc/g1/g1HotCardCache.hpp"
@@ -298,7 +298,7 @@
 }
 
 uint G1RemSet::num_par_rem_sets() {
-  return MAX2(DirtyCardQueueSet::num_par_ids() + ConcurrentG1Refine::thread_num(), ParallelGCThreads);
+  return MAX2(DirtyCardQueueSet::num_par_ids() + G1ConcurrentRefine::thread_num(), ParallelGCThreads);
 }
 
 void G1RemSet::initialize(size_t capacity, uint max_regions) {
--- a/src/hotspot/share/gc/g1/g1RemSetSummary.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1RemSetSummary.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,9 +23,9 @@
  */
 
 #include "precompiled.hpp"
-#include "gc/g1/concurrentG1Refine.hpp"
-#include "gc/g1/concurrentG1RefineThread.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
+#include "gc/g1/g1ConcurrentRefine.hpp"
+#include "gc/g1/g1ConcurrentRefineThread.hpp"
 #include "gc/g1/g1RemSet.inline.hpp"
 #include "gc/g1/g1RemSetSummary.hpp"
 #include "gc/g1/g1YoungRemSetSamplingThread.hpp"
@@ -45,7 +45,7 @@
   }
 
   virtual void do_thread(Thread* t) {
-    ConcurrentG1RefineThread* crt = (ConcurrentG1RefineThread*) t;
+    G1ConcurrentRefineThread* crt = (G1ConcurrentRefineThread*) t;
     _summary->set_rs_thread_vtime(_counter, crt->vtime_accum());
     _counter++;
   }
@@ -59,12 +59,13 @@
 
   _num_coarsenings = HeapRegionRemSet::n_coarsenings();
 
-  ConcurrentG1Refine * cg1r = G1CollectedHeap::heap()->concurrent_g1_refine();
+  G1CollectedHeap* g1h = G1CollectedHeap::heap();
+  G1ConcurrentRefine* cg1r = g1h->concurrent_refine();
   if (_rs_threads_vtimes != NULL) {
     GetRSThreadVTimeClosure p(this);
-    cg1r->worker_threads_do(&p);
+    cg1r->threads_do(&p);
   }
-  set_sampling_thread_vtime(cg1r->sampling_thread()->vtime_accum());
+  set_sampling_thread_vtime(g1h->sampling_thread()->vtime_accum());
 }
 
 void G1RemSetSummary::set_rs_thread_vtime(uint thread, double value) {
@@ -85,7 +86,7 @@
   _num_processed_buf_mutator(0),
   _num_processed_buf_rs_threads(0),
   _num_coarsenings(0),
-  _num_vtimes(ConcurrentG1Refine::thread_num()),
+  _num_vtimes(G1ConcurrentRefine::thread_num()),
   _rs_threads_vtimes(NEW_C_HEAP_ARRAY(double, _num_vtimes, mtGC)),
   _sampling_thread_vtime(0.0f) {
 
@@ -98,7 +99,7 @@
   _num_processed_buf_mutator(0),
   _num_processed_buf_rs_threads(0),
   _num_coarsenings(0),
-  _num_vtimes(ConcurrentG1Refine::thread_num()),
+  _num_vtimes(G1ConcurrentRefine::thread_num()),
   _rs_threads_vtimes(NEW_C_HEAP_ARRAY(double, _num_vtimes, mtGC)),
   _sampling_thread_vtime(0.0f) {
   update();
--- a/src/hotspot/share/gc/g1/g1SATBCardTableModRefBS.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1SATBCardTableModRefBS.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -214,52 +214,3 @@
     }
   }
 }
-
-void G1SATBCardTableModRefBS::write_ref_nmethod_post(oop* dst, nmethod* nm) {
-  oop obj = oopDesc::load_heap_oop(dst);
-  if (obj != NULL) {
-    G1CollectedHeap* g1h = G1CollectedHeap::heap();
-    HeapRegion* hr = g1h->heap_region_containing(obj);
-    hr->add_strong_code_root(nm);
-  }
-}
-
-class G1EnsureLastRefToRegion : public OopClosure {
-  G1CollectedHeap* _g1h;
-  HeapRegion* _hr;
-  oop* _dst;
-
-  bool _value;
-public:
-  G1EnsureLastRefToRegion(G1CollectedHeap* g1h, HeapRegion* hr, oop* dst) :
-    _g1h(g1h), _hr(hr), _dst(dst), _value(true) {}
-
-  void do_oop(oop* p) {
-    if (_value && p != _dst) {
-      oop obj = oopDesc::load_heap_oop(p);
-      if (obj != NULL) {
-        HeapRegion* hr = _g1h->heap_region_containing(obj);
-        if (hr == _hr) {
-          // Another reference to the same region.
-          _value = false;
-        }
-      }
-    }
-  }
-  void do_oop(narrowOop* p) { ShouldNotReachHere(); }
-  bool value() const        { return _value;  }
-};
-
-void G1SATBCardTableModRefBS::write_ref_nmethod_pre(oop* dst, nmethod* nm) {
-  oop obj = oopDesc::load_heap_oop(dst);
-  if (obj != NULL) {
-    G1CollectedHeap* g1h = G1CollectedHeap::heap();
-    HeapRegion* hr = g1h->heap_region_containing(obj);
-    G1EnsureLastRefToRegion ensure_last_ref(g1h, hr, dst);
-    nm->oops_do(&ensure_last_ref);
-    if (ensure_last_ref.value()) {
-      // Last reference to this region, remove the nmethod from the rset.
-      hr->remove_strong_code_root(nm);
-    }
-  }
-}
--- a/src/hotspot/share/gc/g1/g1SATBCardTableModRefBS.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1SATBCardTableModRefBS.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -95,9 +95,6 @@
     jbyte val = _byte_map[card_index];
     return (val & (clean_card_mask_val() | deferred_card_val())) == deferred_card_val();
   }
-  virtual void write_ref_nmethod_pre(oop* dst, nmethod* nm);
-  virtual void write_ref_nmethod_post(oop* dst, nmethod* nm);
-
 };
 
 template<>
--- a/src/hotspot/share/gc/g1/g1_globals.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/g1_globals.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -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
@@ -74,10 +74,10 @@
           "in milliseconds.")                                               \
           range(1.0, DBL_MAX)                                               \
                                                                             \
-  product(intx, G1RefProcDrainInterval, 10,                                 \
+  product(int, G1RefProcDrainInterval, 10,                                  \
           "The number of discovered reference objects to process before "   \
           "draining concurrent marking work queues.")                       \
-          range(1, max_intx)                                                \
+          range(1, INT_MAX)                                                 \
                                                                             \
   experimental(double, G1LastPLABAverageOccupancy, 50.0,                    \
                "The expected average occupancy of the last PLAB in "        \
--- a/src/hotspot/share/gc/g1/heapRegionManager.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/heapRegionManager.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,8 +23,8 @@
  */
 
 #include "precompiled.hpp"
-#include "gc/g1/concurrentG1Refine.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
+#include "gc/g1/g1ConcurrentRefine.hpp"
 #include "gc/g1/heapRegion.hpp"
 #include "gc/g1/heapRegionManager.inline.hpp"
 #include "gc/g1/heapRegionSet.inline.hpp"
--- a/src/hotspot/share/gc/g1/heapRegionRemSet.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/heapRegionRemSet.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,9 +23,9 @@
  */
 
 #include "precompiled.hpp"
-#include "gc/g1/concurrentG1Refine.hpp"
 #include "gc/g1/g1BlockOffsetTable.inline.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
+#include "gc/g1/g1ConcurrentRefine.hpp"
 #include "gc/g1/g1CardLiveData.inline.hpp"
 #include "gc/g1/heapRegionManager.inline.hpp"
 #include "gc/g1/heapRegionRemSet.hpp"
--- a/src/hotspot/share/gc/g1/satbMarkQueue.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/g1/satbMarkQueue.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,12 +23,12 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
 #include "gc/g1/satbMarkQueue.hpp"
 #include "gc/shared/collectedHeap.hpp"
 #include "memory/allocation.inline.hpp"
 #include "oops/oop.inline.hpp"
-#include "prims/jvm.h"
 #include "runtime/mutexLocker.hpp"
 #include "runtime/safepoint.hpp"
 #include "runtime/thread.hpp"
--- a/src/hotspot/share/gc/parallel/psMarkSweep.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/parallel/psMarkSweep.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -192,7 +192,7 @@
 
     allocate_stacks();
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
     DerivedPointerTable::clear();
 #endif
 
@@ -203,7 +203,7 @@
 
     mark_sweep_phase2();
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
     // Don't add any more derived pointers during phase3
     assert(DerivedPointerTable::is_active(), "Sanity");
     DerivedPointerTable::set_active(false);
@@ -252,7 +252,7 @@
     CodeCache::gc_epilogue();
     JvmtiExport::gc_epilogue();
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
     DerivedPointerTable::update_pointers();
 #endif
 
--- a/src/hotspot/share/gc/parallel/psParallelCompact.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/parallel/psParallelCompact.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -1032,7 +1032,7 @@
   CodeCache::gc_epilogue();
   JvmtiExport::gc_epilogue();
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   DerivedPointerTable::update_pointers();
 #endif
 
@@ -1783,7 +1783,7 @@
 
     CodeCache::gc_prologue();
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
     DerivedPointerTable::clear();
 #endif
 
@@ -1799,7 +1799,7 @@
       && GCCause::is_user_requested_gc(gc_cause);
     summary_phase(vmthread_cm, maximum_heap_compaction || max_on_system_gc);
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
     assert(DerivedPointerTable::is_active(), "Sanity");
     DerivedPointerTable::set_active(false);
 #endif
--- a/src/hotspot/share/gc/parallel/psScavenge.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/parallel/psScavenge.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -331,7 +331,7 @@
 
     save_to_space_top_before_gc();
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
     DerivedPointerTable::clear();
 #endif
 
@@ -601,7 +601,7 @@
       assert(young_gen->to_space()->is_empty(), "to space should be empty now");
     }
 
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
     DerivedPointerTable::update_pointers();
 #endif
 
--- a/src/hotspot/share/gc/serial/genMarkSweep.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/serial/genMarkSweep.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -92,7 +92,7 @@
   mark_sweep_phase2();
 
   // Don't add any more derived pointers during phase3
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   assert(DerivedPointerTable::is_active(), "Sanity");
   DerivedPointerTable::set_active(false);
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/serial/serialHeap.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -0,0 +1,35 @@
+/*
+ * 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/serial/serialHeap.hpp"
+
+SerialHeap::SerialHeap(GenCollectorPolicy* policy) : GenCollectedHeap(policy) {}
+
+void SerialHeap::check_gen_kinds() {
+  assert(young_gen()->kind() == Generation::DefNew,
+         "Wrong youngest generation type");
+  assert(old_gen()->kind() == Generation::MarkSweepCompact,
+         "Wrong generation kind");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/serial/serialHeap.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -0,0 +1,58 @@
+/*
+ * 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_SERIAL_SERIALHEAP_HPP
+#define SHARE_VM_GC_SERIAL_SERIALHEAP_HPP
+
+#include "gc/shared/genCollectedHeap.hpp"
+
+class GenCollectorPolicy;
+
+class SerialHeap : public GenCollectedHeap {
+protected:
+  virtual void check_gen_kinds();
+
+public:
+  SerialHeap(GenCollectorPolicy* policy);
+
+  virtual Name kind() const {
+    return CollectedHeap::SerialHeap;
+  }
+
+  virtual const char* name() const {
+    return "Serial";
+  }
+
+  // override
+  virtual bool is_in_closed_subset(const void* p) const {
+    return is_in(p);
+  }
+
+  virtual bool card_mark_must_follow_store() const {
+    return false;
+  }
+
+};
+
+#endif // SHARE_VM_GC_CMS_CMSHEAP_HPP
--- a/src/hotspot/share/gc/shared/ageTable.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/shared/ageTable.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "gc/shared/ageTable.inline.hpp"
 #include "gc/shared/ageTableTracer.hpp"
 #include "gc/shared/collectedHeap.hpp"
@@ -30,7 +31,6 @@
 #include "memory/resourceArea.hpp"
 #include "logging/log.hpp"
 #include "oops/oop.inline.hpp"
-#include "prims/jvm.h"
 #include "utilities/copy.hpp"
 
 /* Copyright (c) 1992, 2016, Oracle and/or its affiliates, and Stanford University.
--- a/src/hotspot/share/gc/shared/allocTracer.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/shared/allocTracer.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -26,9 +26,11 @@
 #include "gc/shared/allocTracer.hpp"
 #include "runtime/handles.hpp"
 #include "trace/tracing.hpp"
+#include "trace/traceMacros.hpp"
 #include "utilities/globalDefinitions.hpp"
 
-void AllocTracer::send_allocation_outside_tlab_event(Klass* klass, size_t alloc_size) {
+void AllocTracer::send_allocation_outside_tlab(Klass* klass, HeapWord* obj, size_t alloc_size, Thread* thread) {
+  TRACE_ALLOCATION(obj, alloc_size, thread);
   EventObjectAllocationOutsideTLAB event;
   if (event.should_commit()) {
     event.set_objectClass(klass);
@@ -37,7 +39,8 @@
   }
 }
 
-void AllocTracer::send_allocation_in_new_tlab_event(Klass* klass, size_t tlab_size, size_t alloc_size) {
+void AllocTracer::send_allocation_in_new_tlab(Klass* klass, HeapWord* obj, size_t tlab_size, size_t alloc_size, Thread* thread) {
+  TRACE_ALLOCATION(obj, tlab_size, thread);
   EventObjectAllocationInNewTLAB event;
   if (event.should_commit()) {
     event.set_objectClass(klass);
--- a/src/hotspot/share/gc/shared/allocTracer.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/shared/allocTracer.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -30,8 +30,8 @@
 
 class AllocTracer : AllStatic {
   public:
-    static void send_allocation_outside_tlab_event(Klass* klass, size_t alloc_size);
-    static void send_allocation_in_new_tlab_event(Klass* klass, size_t tlab_size, size_t alloc_size);
+    static void send_allocation_outside_tlab(Klass* klass, HeapWord* obj, size_t alloc_size, Thread* thread);
+    static void send_allocation_in_new_tlab(Klass* klass, HeapWord* obj, size_t tlab_size, size_t alloc_size, Thread* thread);
     static void send_allocation_requiring_gc_event(size_t size, uint gcId);
 };
 
--- a/src/hotspot/share/gc/shared/barrierSet.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/shared/barrierSet.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -120,9 +120,6 @@
   static void static_write_ref_array_pre(HeapWord* start, size_t count);
   static void static_write_ref_array_post(HeapWord* start, size_t count);
 
-  virtual void write_ref_nmethod_pre(oop* dst, nmethod* nm) {}
-  virtual void write_ref_nmethod_post(oop* dst, nmethod* nm) {}
-
 protected:
   virtual void write_ref_array_work(MemRegion mr) = 0;
 
--- a/src/hotspot/share/gc/shared/collectedHeap.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/shared/collectedHeap.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -241,7 +241,7 @@
 void CollectedHeap::pre_initialize() {
   // Used for ReduceInitialCardMarks (when COMPILER2 is used);
   // otherwise remains unused.
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   _defer_initial_card_mark = is_server_compilation_mode_vm() &&  ReduceInitialCardMarks && can_elide_tlab_store_barriers()
                              && (DeferInitialCardMark || card_mark_must_follow_store());
 #else
@@ -313,7 +313,7 @@
     return NULL;
   }
 
-  AllocTracer::send_allocation_in_new_tlab_event(klass, new_tlab_size * HeapWordSize, size * HeapWordSize);
+  AllocTracer::send_allocation_in_new_tlab(klass, obj, new_tlab_size * HeapWordSize, size * HeapWordSize, thread);
 
   if (ZeroTLAB) {
     // ..and clear it.
@@ -545,7 +545,7 @@
          " to threads list is doomed to failure!");
   for (JavaThread *thread = Threads::first(); thread; thread = thread->next()) {
      if (use_tlab) thread->tlab().make_parsable(retire_tlabs);
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
      // The deferred store barriers must all have been flushed to the
      // card-table (or other remembered set structure) before GC starts
      // processing the card-table (or other remembered set).
--- a/src/hotspot/share/gc/shared/collectedHeap.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/shared/collectedHeap.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -81,9 +81,10 @@
 //
 // CollectedHeap
 //   GenCollectedHeap
+//     SerialHeap
+//     CMSHeap
 //   G1CollectedHeap
 //   ParallelScavengeHeap
-//   CMSHeap
 //
 class CollectedHeap : public CHeapObj<mtInternal> {
   friend class VMStructs;
@@ -193,7 +194,7 @@
 
  public:
   enum Name {
-    GenCollectedHeap,
+    SerialHeap,
     ParallelScavengeHeap,
     G1CollectedHeap,
     CMSHeap
--- a/src/hotspot/share/gc/shared/collectedHeap.inline.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/shared/collectedHeap.inline.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -156,7 +156,7 @@
            "Unexpected exception, will result in uninitialized storage");
     THREAD->incr_allocated_bytes(size * HeapWordSize);
 
-    AllocTracer::send_allocation_outside_tlab_event(klass, size * HeapWordSize);
+    AllocTracer::send_allocation_outside_tlab(klass, result, size * HeapWordSize, THREAD);
 
     return result;
   }
--- a/src/hotspot/share/gc/shared/gcId.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/shared/gcId.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -23,8 +23,8 @@
  */
 
 #include "precompiled.hpp"
+#include "jvm.h"
 #include "gc/shared/gcId.hpp"
-#include "prims/jvm.h"
 #include "runtime/safepoint.hpp"
 #include "runtime/thread.inline.hpp"
 
--- a/src/hotspot/share/gc/shared/gcTimer.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/shared/gcTimer.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -26,7 +26,6 @@
 #define SHARE_VM_GC_SHARED_GCTIMER_HPP
 
 #include "memory/allocation.hpp"
-#include "prims/jni_md.h"
 #include "utilities/macros.hpp"
 #include "utilities/ticks.hpp"
 
--- a/src/hotspot/share/gc/shared/gcTraceTime.inline.hpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/shared/gcTraceTime.inline.hpp	Sat Nov 11 01:21:09 2017 +0100
@@ -32,7 +32,6 @@
 #include "logging/log.hpp"
 #include "logging/logStream.hpp"
 #include "memory/universe.hpp"
-#include "prims/jni_md.h"
 #include "utilities/ticks.hpp"
 
 #define LOG_STOP_HEAP_FORMAT SIZE_FORMAT "M->" SIZE_FORMAT "M("  SIZE_FORMAT "M)"
--- a/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Wed Nov 08 13:38:00 2017 -0800
+++ b/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Sat Nov 11 01:21:09 2017 +0100
@@ -153,13 +153,6 @@
   _gen_policy->initialize_gc_policy_counters();
 }
 
-void GenCollectedHeap::check_gen_kinds() {
-  assert(young_gen()->kind() == Generation::DefNew,
-         "Wrong youngest generation type");
-  assert(old_gen()->kind() == Generation::MarkSweepCompact,
-         "Wrong generation kind");
-}
-
 void GenCollectedHeap::ref_processing_init() {
   _young_gen->ref_processor_init();
   _old_gen->ref_processor_init();
@@ -984,7 +977,7 @@
 GenCollectedHeap* GenCollectedHeap::heap() {
   CollectedHeap* heap = Universe::heap();
   assert(heap != NULL, "Uninitialized access to GenCollectedHeap::heap()");
-  assert(heap->kind() == CollectedHeap::GenCollectedHeap ||
+  assert(heap->kind() == CollectedHeap::SerialHeap ||
          heap->kind() == CollectedHeap::CMSHeap, "Not a GenCollectedHeap");
   return (GenCollectedHeap*) heap;
 }
@@ -1067,11 +1060,11 @@
 };
 
 void GenCollectedHeap::gc_epilogue(bool full) {
-#if defined(COMPILER2) || INCLUDE_JVMCI
+#if COMPILER2_OR_JVMCI
   assert(DerivedPointerTable::is_empty(), "derived pointer present");
   size_t actual_gap = pointer_delta((HeapWord*) (max_uintx-3), *(end_addr()));
   guarantee(is_client_compilation_mode_vm() || actual_gap > (size_t)FastAlloca