Merge
authoramurillo
Fri, 29 Jul 2016 16:11:55 -0700
changeset 40098 8db886f4617c
parent 39922 e613affb88d1 (current diff)
parent 40020 20738e6bef83 (diff)
child 40099 24807846ffe1
Merge
hotspot/src/cpu/ppc/vm/interp_masm_ppc_64.hpp
hotspot/src/cpu/ppc/vm/ppc_64.ad
hotspot/src/cpu/ppc/vm/stubRoutines_ppc_64.hpp
hotspot/src/cpu/ppc/vm/templateTable_ppc_64.hpp
hotspot/src/cpu/x86/vm/stubRoutines_x86_32.hpp
hotspot/src/cpu/x86/vm/stubRoutines_x86_64.hpp
hotspot/src/os/aix/vm/mutex_aix.inline.hpp
hotspot/src/os/bsd/vm/mutex_bsd.cpp
hotspot/src/os/bsd/vm/mutex_bsd.inline.hpp
hotspot/src/os/linux/vm/mutex_linux.cpp
hotspot/src/os/linux/vm/mutex_linux.inline.hpp
hotspot/src/os/solaris/vm/mutex_solaris.cpp
hotspot/src/os/solaris/vm/mutex_solaris.inline.hpp
hotspot/src/os/windows/vm/mutex_windows.cpp
hotspot/src/os/windows/vm/mutex_windows.inline.hpp
hotspot/test/runtime/7107135/Test.java
hotspot/test/runtime/7107135/Test7107135.sh
hotspot/test/runtime/7107135/TestMT.java
hotspot/test/runtime/7107135/test.c
hotspot/test/runtime/StackGuardPages/invoke.c
hotspot/test/runtime/Unsafe/GetUnsafe.java
hotspot/test/runtime/jsig/Test8017498.sh
hotspot/test/runtime/jsig/TestJNI.c
--- a/hotspot/make/gensrc/GensrcAdlc.gmk	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/make/gensrc/GensrcAdlc.gmk	Fri Jul 29 16:11:55 2016 -0700
@@ -51,6 +51,9 @@
     ADLC_CFLAGS_WARNINGS := -W3 -D_CRT_SECURE_NO_WARNINGS
   endif
 
+  # Set the C++ standard if supported
+  ADLC_CFLAGS += $(CXXSTD_CXXFLAG)
+  
   # NOTE: The old build didn't set -DASSERT for windows but it doesn't seem to
   # hurt.
   ADLC_CFLAGS += -DASSERT
@@ -153,10 +156,10 @@
 	$(call MakeDir, $(@D))
 	$(call ExecuteWithLog, $(ADLC_SUPPORT_DIR)/adlc_run, \
 	    $(FIXPATH) $(ADLC_TOOL) $(ADLCFLAGS) $(SINGLE_AD_SRCFILE) \
-	        -c$(ADLC_SUPPORT_DIR)/ad_$(HOTSPOT_TARGET_CPU).cpp \
-	        -h$(ADLC_SUPPORT_DIR)/ad_$(HOTSPOT_TARGET_CPU).hpp \
-	        -a$(ADLC_SUPPORT_DIR)/dfa_$(HOTSPOT_TARGET_CPU).cpp \
-	        -v$(ADLC_SUPPORT_DIR)/adGlobals_$(HOTSPOT_TARGET_CPU).hpp)
+	        -c$(ADLC_SUPPORT_DIR)/ad_$(HOTSPOT_TARGET_CPU_ARCH).cpp \
+	        -h$(ADLC_SUPPORT_DIR)/ad_$(HOTSPOT_TARGET_CPU_ARCH).hpp \
+	        -a$(ADLC_SUPPORT_DIR)/dfa_$(HOTSPOT_TARGET_CPU_ARCH).cpp \
+	        -v$(ADLC_SUPPORT_DIR)/adGlobals_$(HOTSPOT_TARGET_CPU_ARCH).hpp)
 	$(TOUCH) $@
 
   ##############################################################################
@@ -164,17 +167,17 @@
   # and postprocess them by fixing dummy #line directives.
 
   ADLC_GENERATED_FILES := $(addprefix $(JVM_VARIANT_OUTPUTDIR)/gensrc/adfiles/, \
-      ad_$(HOTSPOT_TARGET_CPU).cpp \
-      ad_$(HOTSPOT_TARGET_CPU).hpp \
-      ad_$(HOTSPOT_TARGET_CPU)_clone.cpp \
-      ad_$(HOTSPOT_TARGET_CPU)_expand.cpp \
-      ad_$(HOTSPOT_TARGET_CPU)_format.cpp \
-      ad_$(HOTSPOT_TARGET_CPU)_gen.cpp \
-      ad_$(HOTSPOT_TARGET_CPU)_misc.cpp \
-      ad_$(HOTSPOT_TARGET_CPU)_peephole.cpp \
-      ad_$(HOTSPOT_TARGET_CPU)_pipeline.cpp \
-      adGlobals_$(HOTSPOT_TARGET_CPU).hpp \
-      dfa_$(HOTSPOT_TARGET_CPU).cpp \
+      ad_$(HOTSPOT_TARGET_CPU_ARCH).cpp \
+      ad_$(HOTSPOT_TARGET_CPU_ARCH).hpp \
+      ad_$(HOTSPOT_TARGET_CPU_ARCH)_clone.cpp \
+      ad_$(HOTSPOT_TARGET_CPU_ARCH)_expand.cpp \
+      ad_$(HOTSPOT_TARGET_CPU_ARCH)_format.cpp \
+      ad_$(HOTSPOT_TARGET_CPU_ARCH)_gen.cpp \
+      ad_$(HOTSPOT_TARGET_CPU_ARCH)_misc.cpp \
+      ad_$(HOTSPOT_TARGET_CPU_ARCH)_peephole.cpp \
+      ad_$(HOTSPOT_TARGET_CPU_ARCH)_pipeline.cpp \
+      adGlobals_$(HOTSPOT_TARGET_CPU_ARCH).hpp \
+      dfa_$(HOTSPOT_TARGET_CPU_ARCH).cpp \
   )
 
   $(JVM_VARIANT_OUTPUTDIR)/gensrc/adfiles/%: $(ADLC_RUN_MARKER)
--- a/hotspot/make/lib/CompileGtest.gmk	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/make/lib/CompileGtest.gmk	Fri Jul 29 16:11:55 2016 -0700
@@ -104,7 +104,7 @@
         -I$(GTEST_FRAMEWORK_SRC)/include, \
     CFLAGS_DEBUG_SYMBOLS := $(JVM_CFLAGS_SYMBOLS), \
     CXXFLAGS_DEBUG_SYMBOLS := $(JVM_CFLAGS_SYMBOLS), \
-    LDFLAGS := $(LDFLAGS_TESTEXE), \
+    LDFLAGS := $(LDFLAGS_JDKEXE), \
     LDFLAGS_unix := -L$(JVM_OUTPUTDIR)/gtest $(call SET_SHARED_LIBRARY_ORIGIN), \
     LDFLAGS_solaris := -library=stlport4, \
     LIBS_unix := -ljvm, \
--- a/hotspot/make/lib/CompileJvm.gmk	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/make/lib/CompileJvm.gmk	Fri Jul 29 16:11:55 2016 -0700
@@ -60,12 +60,15 @@
     -I$(HOTSPOT_TOPDIR)/src/share/vm/prims \
     #
 
+# INCLUDE_SUFFIX_* is only meant for including the proper
+# platform files. Don't use it to guard code. Use the value of
+# HOTSPOT_TARGET_CPU_DEFINE etc. instead.
+# Remaining TARGET_ARCH_* is needed to distinguish closed and open
+# 64-bit ARM ports (also called AARCH64).
 JVM_CFLAGS_TARGET_DEFINES += \
-    -DTARGET_OS_FAMILY_$(HOTSPOT_TARGET_OS) \
-    -DTARGET_ARCH_MODEL_$(HOTSPOT_TARGET_CPU) \
     -DTARGET_ARCH_$(HOTSPOT_TARGET_CPU_ARCH) \
-    -DTARGET_OS_ARCH_MODEL_$(HOTSPOT_TARGET_OS)_$(HOTSPOT_TARGET_CPU) \
-    -DTARGET_OS_ARCH_$(HOTSPOT_TARGET_OS)_$(HOTSPOT_TARGET_CPU_ARCH) \
+    -DINCLUDE_SUFFIX_OS=_$(HOTSPOT_TARGET_OS) \
+    -DINCLUDE_SUFFIX_CPU=_$(HOTSPOT_TARGET_CPU_ARCH) \
     -DTARGET_COMPILER_$(HOTSPOT_TOOLCHAIN_TYPE) \
     -D$(HOTSPOT_TARGET_CPU_DEFINE) \
     -DHOTSPOT_LIB_ARCH='"$(OPENJDK_TARGET_CPU_LEGACY_LIB)"' \
--- a/hotspot/make/test/JtregNative.gmk	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/make/test/JtregNative.gmk	Fri Jul 29 16:11:55 2016 -0700
@@ -53,6 +53,7 @@
     $(HOTSPOT_TOPDIR)/test/compiler/native \
     $(HOTSPOT_TOPDIR)/test/serviceability/jvmti/GetNamedModule \
     $(HOTSPOT_TOPDIR)/test/testlibrary/jvmti \
+    $(HOTSPOT_TOPDIR)/test/serviceability/jvmti/GetModulesInfo \
     #
 
 # Add conditional directories here when needed.
@@ -62,12 +63,26 @@
     $(HOTSPOT_TOPDIR)/test/runtime/ThreadSignalMask
 endif
 
+ifeq ($(OPENJDK_TARGET_OS), linux)
+BUILD_HOTSPOT_JTREG_NATIVE_SRC += \
+    $(HOTSPOT_TOPDIR)/test/runtime/execstack \
+    $(HOTSPOT_TOPDIR)/test/runtime/jsig \
+    $(HOTSPOT_TOPDIR)/test/runtime/StackGuardPages
+endif
+
 ifeq ($(TOOLCHAIN_TYPE), solstudio)
     BUILD_HOTSPOT_JTREG_LIBRARIES_LDFLAGS_liboverflow := -lc
     BUILD_HOTSPOT_JTREG_LIBRARIES_LDFLAGS_libSimpleClassFileLoadHook := -lc
     BUILD_HOTSPOT_JTREG_LIBRARIES_LDFLAGS_libGetNamedModuleTest := -lc
 endif
 
+ifeq ($(OPENJDK_TARGET_OS), linux)
+    BUILD_HOTSPOT_JTREG_LIBRARIES_LDFLAGS_libtest-rw := -z noexecstack
+    BUILD_HOTSPOT_JTREG_LIBRARIES_LDFLAGS_libtest-rwx := -z execstack
+    BUILD_HOTSPOT_JTREG_EXECUTABLES_LDFLAGS_exeinvoke := -ljvm -lpthread
+    BUILD_TEST_invoke_exeinvoke.c_OPTIMIZATION := NONE
+endif
+
 BUILD_HOTSPOT_JTREG_OUTPUT_DIR := $(BUILD_OUTPUT)/support/test/hotspot/jtreg/native
 
 BUILD_HOTSPOT_JTREG_IMAGE_DIR := $(TEST_IMAGE_DIR)/hotspot/jtreg
--- a/hotspot/src/cpu/aarch64/vm/bytes_aarch64.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/aarch64/vm/bytes_aarch64.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -67,9 +67,6 @@
 
 
 // The following header contains the implementations of swap_u2, swap_u4, and swap_u8[_base]
-
-#ifdef TARGET_OS_ARCH_linux_aarch64
-# include "bytes_linux_aarch64.inline.hpp"
-#endif
+#include OS_CPU_HEADER_INLINE(bytes)
 
 #endif // CPU_AARCH64_VM_BYTES_AARCH64_HPP
--- a/hotspot/src/cpu/aarch64/vm/copy_aarch64.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/aarch64/vm/copy_aarch64.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -29,9 +29,7 @@
 // Inline functions for memory copy and fill.
 
 // Contains inline asm implementations
-#ifdef TARGET_OS_ARCH_linux_aarch64
-# include "copy_linux_aarch64.inline.hpp"
-#endif
+#include OS_CPU_HEADER_INLINE(copy)
 
 
 static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) {
--- a/hotspot/src/cpu/aarch64/vm/vm_version_aarch64.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/aarch64/vm/vm_version_aarch64.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2015, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -29,10 +29,10 @@
 #include "memory/resourceArea.hpp"
 #include "runtime/java.hpp"
 #include "runtime/stubCodeGenerator.hpp"
+#include "utilities/macros.hpp"
 #include "vm_version_aarch64.hpp"
-#ifdef TARGET_OS_FAMILY_linux
-# include "os_linux.inline.hpp"
-#endif
+
+#include OS_HEADER_INLINE(os)
 
 #ifndef BUILTIN_SIM
 #include <sys/auxv.h>
--- a/hotspot/src/cpu/ppc/vm/bytes_ppc.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/bytes_ppc.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2013 SAP SE. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -274,8 +274,6 @@
 #endif // VM_LITTLE_ENDIAN
 };
 
-#if defined(TARGET_OS_ARCH_linux_ppc)
-#include "bytes_linux_ppc.inline.hpp"
-#endif
+#include OS_CPU_HEADER_INLINE(bytes)
 
 #endif // CPU_PPC_VM_BYTES_PPC_HPP
--- a/hotspot/src/cpu/ppc/vm/globalDefinitions_ppc.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/globalDefinitions_ppc.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -47,7 +47,7 @@
 // The expected size in bytes of a cache line, used to pad data structures.
 #define DEFAULT_CACHE_LINE_SIZE 128
 
-#if defined(COMPILER2) && (defined(AIX) || defined(linux))
+#if defined(COMPILER2) && (defined(AIX) || defined(LINUX))
 // Include Transactional Memory lock eliding optimization
 #define INCLUDE_RTM_OPT 1
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/cpu/ppc/vm/interp_masm_ppc.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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 CPU_PPC_VM_INTERP_MASM_PPC_HPP
+#define CPU_PPC_VM_INTERP_MASM_PPC_HPP
+
+#include "asm/macroAssembler.hpp"
+#include "interpreter/invocationCounter.hpp"
+
+// This file specializes the assembler with interpreter-specific macros.
+
+
+class InterpreterMacroAssembler: public MacroAssembler {
+
+ public:
+  InterpreterMacroAssembler(CodeBuffer* code) : MacroAssembler(code) {}
+
+  void null_check_throw(Register a, int offset, Register temp_reg);
+
+  void jump_to_entry(address entry, Register Rscratch);
+
+  // Handy address generation macros.
+#define thread_(field_name) in_bytes(JavaThread::field_name ## _offset()), R16_thread
+#define method_(field_name) in_bytes(Method::field_name ## _offset()), R19_method
+
+  virtual void check_and_handle_popframe(Register java_thread);
+  virtual void check_and_handle_earlyret(Register java_thread);
+
+  // Base routine for all dispatches.
+  void dispatch_base(TosState state, address* table);
+
+  void load_earlyret_value(TosState state, Register Rscratch1);
+
+  static const Address l_tmp;
+  static const Address d_tmp;
+
+  // dispatch routines
+  void dispatch_next(TosState state, int step = 0);
+  void dispatch_via (TosState state, address* table);
+  void load_dispatch_table(Register dst, address* table);
+  void dispatch_Lbyte_code(TosState state, Register bytecode, address* table, bool verify = false);
+
+  // Called by shared interpreter generator.
+  void dispatch_prolog(TosState state, int step = 0);
+  void dispatch_epilog(TosState state, int step = 0);
+
+  // Super call_VM calls - correspond to MacroAssembler::call_VM(_leaf) calls.
+  void super_call_VM_leaf(Register thread_cache, address entry_point, Register arg_1);
+  void super_call_VM(Register thread_cache, Register oop_result, Register last_java_sp,
+                     address entry_point, Register arg_1, Register arg_2, bool check_exception = true);
+
+  // Generate a subtype check: branch to ok_is_subtype if sub_klass is
+  // a subtype of super_klass.  Blows registers tmp1, tmp2 and tmp3.
+  void gen_subtype_check(Register sub_klass, Register super_klass,
+                         Register tmp1, Register tmp2, Register tmp3, Label &ok_is_subtype);
+
+  // Load object from cpool->resolved_references(index).
+  void load_resolved_reference_at_index(Register result, Register index, Label *is_null = NULL);
+
+  void load_receiver(Register Rparam_count, Register Rrecv_dst);
+
+  // helpers for expression stack
+  void pop_i(     Register r = R17_tos);
+  void pop_ptr(   Register r = R17_tos);
+  void pop_l(     Register r = R17_tos);
+  void pop_f(FloatRegister f = F15_ftos);
+  void pop_d(FloatRegister f = F15_ftos );
+
+  void push_i(     Register r = R17_tos);
+  void push_ptr(   Register r = R17_tos);
+  void push_l(     Register r = R17_tos);
+  void push_f(FloatRegister f = F15_ftos );
+  void push_d(FloatRegister f = F15_ftos);
+
+  void push_2ptrs(Register first, Register second);
+
+  void push_l_pop_d(Register l = R17_tos, FloatRegister d = F15_ftos);
+  void push_d_pop_l(FloatRegister d = F15_ftos, Register l = R17_tos);
+
+  void pop (TosState state);           // transition vtos -> state
+  void push(TosState state);           // transition state -> vtos
+  void empty_expression_stack();       // Resets both Lesp and SP.
+
+ public:
+  // Load values from bytecode stream:
+
+  enum signedOrNot { Signed, Unsigned };
+  enum setCCOrNot  { set_CC, dont_set_CC };
+
+  void get_2_byte_integer_at_bcp(int         bcp_offset,
+                                 Register    Rdst,
+                                 signedOrNot is_signed);
+
+  void get_4_byte_integer_at_bcp(int         bcp_offset,
+                                 Register    Rdst,
+                                 signedOrNot is_signed = Unsigned);
+
+  void get_cache_index_at_bcp(Register Rdst, int bcp_offset, size_t index_size);
+
+  void get_cache_and_index_at_bcp(Register cache, int bcp_offset, size_t index_size = sizeof(u2));
+
+  void get_u4(Register Rdst, Register Rsrc, int offset, signedOrNot is_signed);
+
+  // common code
+
+  void field_offset_at(int n, Register tmp, Register dest, Register base);
+  int  field_offset_at(Register object, address bcp, int offset);
+  void fast_iaaccess(int n, address bcp);
+  void fast_iaputfield(address bcp, bool do_store_check);
+
+  void index_check(Register array, Register index, int index_shift, Register tmp, Register res);
+  void index_check_without_pop(Register array, Register index, int index_shift, Register tmp, Register res);
+
+  void get_const(Register Rdst);
+  void get_constant_pool(Register Rdst);
+  void get_constant_pool_cache(Register Rdst);
+  void get_cpool_and_tags(Register Rcpool, Register Rtags);
+  void is_a(Label& L);
+
+  void narrow(Register result);
+
+  // Java Call Helpers
+  void call_from_interpreter(Register Rtarget_method, Register Rret_addr, Register Rscratch1, Register Rscratch2);
+
+  // --------------------------------------------------
+
+  void unlock_if_synchronized_method(TosState state, bool throw_monitor_exception = true,
+                                     bool install_monitor_exception = true);
+
+  // Removes the current activation (incl. unlocking of monitors).
+  // Additionally this code is used for earlyReturn in which case we
+  // want to skip throwing an exception and installing an exception.
+  void remove_activation(TosState state,
+                         bool throw_monitor_exception = true,
+                         bool install_monitor_exception = true);
+  void merge_frames(Register Rtop_frame_sp, Register return_pc, Register Rscratch1, Register Rscratch2); // merge top frames
+
+  void add_monitor_to_stack(bool stack_is_empty, Register Rtemp1, Register Rtemp2);
+
+  // Local variable access helpers
+  void load_local_int(Register Rdst_value, Register Rdst_address, Register Rindex);
+  void load_local_long(Register Rdst_value, Register Rdst_address, Register Rindex);
+  void load_local_ptr(Register Rdst_value, Register Rdst_address, Register Rindex);
+  void load_local_float(FloatRegister Rdst_value, Register Rdst_address, Register Rindex);
+  void load_local_double(FloatRegister Rdst_value, Register Rdst_address, Register Rindex);
+  void store_local_int(Register Rvalue, Register Rindex);
+  void store_local_long(Register Rvalue, Register Rindex);
+  void store_local_ptr(Register Rvalue, Register Rindex);
+  void store_local_float(FloatRegister Rvalue, Register Rindex);
+  void store_local_double(FloatRegister Rvalue, Register Rindex);
+
+  // Call VM for std frames
+  // Special call VM versions that check for exceptions and forward exception
+  // via short cut (not via expensive forward exception stub).
+  void check_and_forward_exception(Register Rscratch1, Register Rscratch2);
+  void call_VM(Register oop_result, address entry_point, bool check_exceptions = true);
+  void call_VM(Register oop_result, address entry_point, Register arg_1, bool check_exceptions = true);
+  void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, bool check_exceptions = true);
+  void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions = true);
+  // Should not be used:
+  void call_VM(Register oop_result, Register last_java_sp, address entry_point, bool check_exceptions = true) {ShouldNotReachHere();}
+  void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, bool check_exceptions = true) {ShouldNotReachHere();}
+  void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, bool check_exceptions = true) {ShouldNotReachHere();}
+  void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions = true) {ShouldNotReachHere();}
+
+  Address first_local_in_stack();
+
+  enum LoadOrStore { load, store };
+  void static_iload_or_store(int which_local, LoadOrStore direction, Register Rtmp);
+  void static_aload_or_store(int which_local, LoadOrStore direction, Register Rtmp);
+  void static_dload_or_store(int which_local, LoadOrStore direction);
+
+  void save_interpreter_state(Register scratch);
+  void restore_interpreter_state(Register scratch, bool bcp_and_mdx_only = false);
+
+  void increment_backedge_counter(const Register Rcounters, Register Rtmp, Register Rtmp2, Register Rscratch);
+  void test_backedge_count_for_osr(Register backedge_count, Register method_counters, Register target_bcp, Register disp, Register Rtmp);
+
+  void record_static_call_in_profile(Register Rentry, Register Rtmp);
+  void record_receiver_call_in_profile(Register Rklass, Register Rentry, Register Rtmp);
+
+  void get_method_counters(Register method, Register Rcounters, Label& skip);
+  void increment_invocation_counter(Register iv_be_count, Register Rtmp1, Register Rtmp2_r0);
+
+  // Object locking
+  void lock_object  (Register lock_reg, Register obj_reg);
+  void unlock_object(Register lock_reg, bool check_for_exceptions = true);
+
+  // Interpreter profiling operations
+  void set_method_data_pointer_for_bcp();
+  void test_method_data_pointer(Label& zero_continue);
+  void verify_method_data_pointer();
+  void test_invocation_counter_for_mdp(Register invocation_count, Register method_counters, Register Rscratch, Label &profile_continue);
+
+  void set_mdp_data_at(int constant, Register value);
+
+  void increment_mdp_data_at(int constant, Register counter_addr, Register Rbumped_count, bool decrement = false);
+
+  void increment_mdp_data_at(Register counter_addr, Register Rbumped_count, bool decrement = false);
+  void increment_mdp_data_at(Register reg, int constant, Register scratch, Register Rbumped_count, bool decrement = false);
+
+  void set_mdp_flag_at(int flag_constant, Register scratch);
+  void test_mdp_data_at(int offset, Register value, Label& not_equal_continue, Register test_out);
+
+  void update_mdp_by_offset(int offset_of_disp, Register scratch);
+  void update_mdp_by_offset(Register reg, int offset_of_disp,
+                            Register scratch);
+  void update_mdp_by_constant(int constant);
+  void update_mdp_for_ret(TosState state, Register return_bci);
+
+  void profile_taken_branch(Register scratch, Register bumped_count);
+  void profile_not_taken_branch(Register scratch1, Register scratch2);
+  void profile_call(Register scratch1, Register scratch2);
+  void profile_final_call(Register scratch1, Register scratch2);
+  void profile_virtual_call(Register Rreceiver, Register Rscratch1, Register Rscratch2,  bool receiver_can_be_null);
+  void profile_typecheck(Register Rklass, Register Rscratch1, Register Rscratch2);
+  void profile_typecheck_failed(Register Rscratch1, Register Rscratch2);
+  void profile_ret(TosState state, Register return_bci, Register scratch1, Register scratch2);
+  void profile_switch_default(Register scratch1, Register scratch2);
+  void profile_switch_case(Register index, Register scratch1,Register scratch2, Register scratch3);
+  void profile_null_seen(Register Rscratch1, Register Rscratch2);
+  void record_klass_in_profile(Register receiver, Register scratch1, Register scratch2, bool is_virtual_call);
+  void record_klass_in_profile_helper(Register receiver, Register scratch1, Register scratch2, int start_row, Label& done, bool is_virtual_call);
+
+  // Argument and return type profiling.
+  void profile_obj_type(Register obj, Register mdo_addr_base, RegisterOrConstant mdo_addr_offs, Register tmp, Register tmp2);
+  void profile_arguments_type(Register callee, Register tmp1, Register tmp2, bool is_virtual);
+  void profile_return_type(Register ret, Register tmp1, Register tmp2);
+  void profile_parameters_type(Register tmp1, Register tmp2, Register tmp3, Register tmp4);
+
+  // Debugging
+  void verify_oop(Register reg, TosState state = atos);    // only if +VerifyOops && state == atos
+  void verify_oop_or_return_address(Register reg, Register rtmp); // for astore
+  void verify_FPU(int stack_depth, TosState state = ftos);
+
+  typedef enum { NotifyJVMTI, SkipNotifyJVMTI } NotifyMethodExitMode;
+
+  // Support for jvmdi/jvmpi.
+  void notify_method_entry();
+  void notify_method_exit(bool is_native_method, TosState state,
+                          NotifyMethodExitMode mode, bool check_exceptions);
+};
+
+#endif // CPU_PPC_VM_INTERP_MASM_PPC_HPP
--- a/hotspot/src/cpu/ppc/vm/interp_masm_ppc_64.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/interp_masm_ppc_64.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -26,7 +26,7 @@
 
 #include "precompiled.hpp"
 #include "asm/macroAssembler.inline.hpp"
-#include "interp_masm_ppc_64.hpp"
+#include "interp_masm_ppc.hpp"
 #include "interpreter/interpreterRuntime.hpp"
 #include "prims/jvmtiThreadState.hpp"
 #include "runtime/sharedRuntime.hpp"
--- a/hotspot/src/cpu/ppc/vm/interp_masm_ppc_64.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,266 +0,0 @@
-/*
- * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 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 CPU_PPC_VM_INTERP_MASM_PPC_64_HPP
-#define CPU_PPC_VM_INTERP_MASM_PPC_64_HPP
-
-#include "asm/macroAssembler.hpp"
-#include "interpreter/invocationCounter.hpp"
-
-// This file specializes the assembler with interpreter-specific macros.
-
-
-class InterpreterMacroAssembler: public MacroAssembler {
-
- public:
-  InterpreterMacroAssembler(CodeBuffer* code) : MacroAssembler(code) {}
-
-  void null_check_throw(Register a, int offset, Register temp_reg);
-
-  void jump_to_entry(address entry, Register Rscratch);
-
-  // Handy address generation macros.
-#define thread_(field_name) in_bytes(JavaThread::field_name ## _offset()), R16_thread
-#define method_(field_name) in_bytes(Method::field_name ## _offset()), R19_method
-
-  virtual void check_and_handle_popframe(Register java_thread);
-  virtual void check_and_handle_earlyret(Register java_thread);
-
-  // Base routine for all dispatches.
-  void dispatch_base(TosState state, address* table);
-
-  void load_earlyret_value(TosState state, Register Rscratch1);
-
-  static const Address l_tmp;
-  static const Address d_tmp;
-
-  // dispatch routines
-  void dispatch_next(TosState state, int step = 0);
-  void dispatch_via (TosState state, address* table);
-  void load_dispatch_table(Register dst, address* table);
-  void dispatch_Lbyte_code(TosState state, Register bytecode, address* table, bool verify = false);
-
-  // Called by shared interpreter generator.
-  void dispatch_prolog(TosState state, int step = 0);
-  void dispatch_epilog(TosState state, int step = 0);
-
-  // Super call_VM calls - correspond to MacroAssembler::call_VM(_leaf) calls.
-  void super_call_VM_leaf(Register thread_cache, address entry_point, Register arg_1);
-  void super_call_VM(Register thread_cache, Register oop_result, Register last_java_sp,
-                     address entry_point, Register arg_1, Register arg_2, bool check_exception = true);
-
-  // Generate a subtype check: branch to ok_is_subtype if sub_klass is
-  // a subtype of super_klass.  Blows registers tmp1, tmp2 and tmp3.
-  void gen_subtype_check(Register sub_klass, Register super_klass,
-                         Register tmp1, Register tmp2, Register tmp3, Label &ok_is_subtype);
-
-  // Load object from cpool->resolved_references(index).
-  void load_resolved_reference_at_index(Register result, Register index, Label *is_null = NULL);
-
-  void load_receiver(Register Rparam_count, Register Rrecv_dst);
-
-  // helpers for expression stack
-  void pop_i(     Register r = R17_tos);
-  void pop_ptr(   Register r = R17_tos);
-  void pop_l(     Register r = R17_tos);
-  void pop_f(FloatRegister f = F15_ftos);
-  void pop_d(FloatRegister f = F15_ftos );
-
-  void push_i(     Register r = R17_tos);
-  void push_ptr(   Register r = R17_tos);
-  void push_l(     Register r = R17_tos);
-  void push_f(FloatRegister f = F15_ftos );
-  void push_d(FloatRegister f = F15_ftos);
-
-  void push_2ptrs(Register first, Register second);
-
-  void push_l_pop_d(Register l = R17_tos, FloatRegister d = F15_ftos);
-  void push_d_pop_l(FloatRegister d = F15_ftos, Register l = R17_tos);
-
-  void pop (TosState state);           // transition vtos -> state
-  void push(TosState state);           // transition state -> vtos
-  void empty_expression_stack();       // Resets both Lesp and SP.
-
- public:
-  // Load values from bytecode stream:
-
-  enum signedOrNot { Signed, Unsigned };
-  enum setCCOrNot  { set_CC, dont_set_CC };
-
-  void get_2_byte_integer_at_bcp(int         bcp_offset,
-                                 Register    Rdst,
-                                 signedOrNot is_signed);
-
-  void get_4_byte_integer_at_bcp(int         bcp_offset,
-                                 Register    Rdst,
-                                 signedOrNot is_signed = Unsigned);
-
-  void get_cache_index_at_bcp(Register Rdst, int bcp_offset, size_t index_size);
-
-  void get_cache_and_index_at_bcp(Register cache, int bcp_offset, size_t index_size = sizeof(u2));
-
-  void get_u4(Register Rdst, Register Rsrc, int offset, signedOrNot is_signed);
-
-  // common code
-
-  void field_offset_at(int n, Register tmp, Register dest, Register base);
-  int  field_offset_at(Register object, address bcp, int offset);
-  void fast_iaaccess(int n, address bcp);
-  void fast_iaputfield(address bcp, bool do_store_check);
-
-  void index_check(Register array, Register index, int index_shift, Register tmp, Register res);
-  void index_check_without_pop(Register array, Register index, int index_shift, Register tmp, Register res);
-
-  void get_const(Register Rdst);
-  void get_constant_pool(Register Rdst);
-  void get_constant_pool_cache(Register Rdst);
-  void get_cpool_and_tags(Register Rcpool, Register Rtags);
-  void is_a(Label& L);
-
-  void narrow(Register result);
-
-  // Java Call Helpers
-  void call_from_interpreter(Register Rtarget_method, Register Rret_addr, Register Rscratch1, Register Rscratch2);
-
-  // --------------------------------------------------
-
-  void unlock_if_synchronized_method(TosState state, bool throw_monitor_exception = true,
-                                     bool install_monitor_exception = true);
-
-  // Removes the current activation (incl. unlocking of monitors).
-  // Additionally this code is used for earlyReturn in which case we
-  // want to skip throwing an exception and installing an exception.
-  void remove_activation(TosState state,
-                         bool throw_monitor_exception = true,
-                         bool install_monitor_exception = true);
-  void merge_frames(Register Rtop_frame_sp, Register return_pc, Register Rscratch1, Register Rscratch2); // merge top frames
-
-  void add_monitor_to_stack(bool stack_is_empty, Register Rtemp1, Register Rtemp2);
-
-  // Local variable access helpers
-  void load_local_int(Register Rdst_value, Register Rdst_address, Register Rindex);
-  void load_local_long(Register Rdst_value, Register Rdst_address, Register Rindex);
-  void load_local_ptr(Register Rdst_value, Register Rdst_address, Register Rindex);
-  void load_local_float(FloatRegister Rdst_value, Register Rdst_address, Register Rindex);
-  void load_local_double(FloatRegister Rdst_value, Register Rdst_address, Register Rindex);
-  void store_local_int(Register Rvalue, Register Rindex);
-  void store_local_long(Register Rvalue, Register Rindex);
-  void store_local_ptr(Register Rvalue, Register Rindex);
-  void store_local_float(FloatRegister Rvalue, Register Rindex);
-  void store_local_double(FloatRegister Rvalue, Register Rindex);
-
-  // Call VM for std frames
-  // Special call VM versions that check for exceptions and forward exception
-  // via short cut (not via expensive forward exception stub).
-  void check_and_forward_exception(Register Rscratch1, Register Rscratch2);
-  void call_VM(Register oop_result, address entry_point, bool check_exceptions = true);
-  void call_VM(Register oop_result, address entry_point, Register arg_1, bool check_exceptions = true);
-  void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, bool check_exceptions = true);
-  void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions = true);
-  // Should not be used:
-  void call_VM(Register oop_result, Register last_java_sp, address entry_point, bool check_exceptions = true) {ShouldNotReachHere();}
-  void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, bool check_exceptions = true) {ShouldNotReachHere();}
-  void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, bool check_exceptions = true) {ShouldNotReachHere();}
-  void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions = true) {ShouldNotReachHere();}
-
-  Address first_local_in_stack();
-
-  enum LoadOrStore { load, store };
-  void static_iload_or_store(int which_local, LoadOrStore direction, Register Rtmp);
-  void static_aload_or_store(int which_local, LoadOrStore direction, Register Rtmp);
-  void static_dload_or_store(int which_local, LoadOrStore direction);
-
-  void save_interpreter_state(Register scratch);
-  void restore_interpreter_state(Register scratch, bool bcp_and_mdx_only = false);
-
-  void increment_backedge_counter(const Register Rcounters, Register Rtmp, Register Rtmp2, Register Rscratch);
-  void test_backedge_count_for_osr(Register backedge_count, Register method_counters, Register target_bcp, Register disp, Register Rtmp);
-
-  void record_static_call_in_profile(Register Rentry, Register Rtmp);
-  void record_receiver_call_in_profile(Register Rklass, Register Rentry, Register Rtmp);
-
-  void get_method_counters(Register method, Register Rcounters, Label& skip);
-  void increment_invocation_counter(Register iv_be_count, Register Rtmp1, Register Rtmp2_r0);
-
-  // Object locking
-  void lock_object  (Register lock_reg, Register obj_reg);
-  void unlock_object(Register lock_reg, bool check_for_exceptions = true);
-
-  // Interpreter profiling operations
-  void set_method_data_pointer_for_bcp();
-  void test_method_data_pointer(Label& zero_continue);
-  void verify_method_data_pointer();
-  void test_invocation_counter_for_mdp(Register invocation_count, Register method_counters, Register Rscratch, Label &profile_continue);
-
-  void set_mdp_data_at(int constant, Register value);
-
-  void increment_mdp_data_at(int constant, Register counter_addr, Register Rbumped_count, bool decrement = false);
-
-  void increment_mdp_data_at(Register counter_addr, Register Rbumped_count, bool decrement = false);
-  void increment_mdp_data_at(Register reg, int constant, Register scratch, Register Rbumped_count, bool decrement = false);
-
-  void set_mdp_flag_at(int flag_constant, Register scratch);
-  void test_mdp_data_at(int offset, Register value, Label& not_equal_continue, Register test_out);
-
-  void update_mdp_by_offset(int offset_of_disp, Register scratch);
-  void update_mdp_by_offset(Register reg, int offset_of_disp,
-                            Register scratch);
-  void update_mdp_by_constant(int constant);
-  void update_mdp_for_ret(TosState state, Register return_bci);
-
-  void profile_taken_branch(Register scratch, Register bumped_count);
-  void profile_not_taken_branch(Register scratch1, Register scratch2);
-  void profile_call(Register scratch1, Register scratch2);
-  void profile_final_call(Register scratch1, Register scratch2);
-  void profile_virtual_call(Register Rreceiver, Register Rscratch1, Register Rscratch2,  bool receiver_can_be_null);
-  void profile_typecheck(Register Rklass, Register Rscratch1, Register Rscratch2);
-  void profile_typecheck_failed(Register Rscratch1, Register Rscratch2);
-  void profile_ret(TosState state, Register return_bci, Register scratch1, Register scratch2);
-  void profile_switch_default(Register scratch1, Register scratch2);
-  void profile_switch_case(Register index, Register scratch1,Register scratch2, Register scratch3);
-  void profile_null_seen(Register Rscratch1, Register Rscratch2);
-  void record_klass_in_profile(Register receiver, Register scratch1, Register scratch2, bool is_virtual_call);
-  void record_klass_in_profile_helper(Register receiver, Register scratch1, Register scratch2, int start_row, Label& done, bool is_virtual_call);
-
-  // Argument and return type profiling.
-  void profile_obj_type(Register obj, Register mdo_addr_base, RegisterOrConstant mdo_addr_offs, Register tmp, Register tmp2);
-  void profile_arguments_type(Register callee, Register tmp1, Register tmp2, bool is_virtual);
-  void profile_return_type(Register ret, Register tmp1, Register tmp2);
-  void profile_parameters_type(Register tmp1, Register tmp2, Register tmp3, Register tmp4);
-
-  // Debugging
-  void verify_oop(Register reg, TosState state = atos);    // only if +VerifyOops && state == atos
-  void verify_oop_or_return_address(Register reg, Register rtmp); // for astore
-  void verify_FPU(int stack_depth, TosState state = ftos);
-
-  typedef enum { NotifyJVMTI, SkipNotifyJVMTI } NotifyMethodExitMode;
-
-  // Support for jvmdi/jvmpi.
-  void notify_method_entry();
-  void notify_method_exit(bool is_native_method, TosState state,
-                          NotifyMethodExitMode mode, bool check_exceptions);
-};
-
-#endif // CPU_PPC_VM_INTERP_MASM_PPC_64_HPP
--- a/hotspot/src/cpu/ppc/vm/ppc_64.ad	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-//
-// Copyright (c) 2011, 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.
-//
-// 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.
-//
-//
--- a/hotspot/src/cpu/ppc/vm/sharedRuntime_ppc.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/sharedRuntime_ppc.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -40,7 +40,7 @@
 #include "c1/c1_Runtime1.hpp"
 #endif
 #ifdef COMPILER2
-#include "adfiles/ad_ppc_64.hpp"
+#include "opto/ad.hpp"
 #include "opto/runtime.hpp"
 #endif
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/cpu/ppc/vm/stubRoutines_ppc.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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 CPU_PPC_VM_STUBROUTINES_PPC_HPP
+#define CPU_PPC_VM_STUBROUTINES_PPC_HPP
+
+// This file holds the platform specific parts of the StubRoutines
+// definition. See stubRoutines.hpp for a description on how to
+// extend it.
+
+static bool returns_to_call_stub(address return_pc) { return return_pc == _call_stub_return_address; }
+
+enum platform_dependent_constants {
+  code_size1 = 20000,          // simply increase if too small (assembler will crash if too small)
+  code_size2 = 20000           // simply increase if too small (assembler will crash if too small)
+};
+
+// CRC32 Intrinsics.
+#define CRC32_COLUMN_SIZE 256
+#define CRC32_BYFOUR
+#ifdef  CRC32_BYFOUR
+  #define CRC32_TABLES 8
+#else
+  #define CRC32_TABLES 1
+#endif
+
+class ppc64 {
+ friend class StubGenerator;
+
+ private:
+
+  // CRC32 Intrinsics.
+  static juint _crc_table[CRC32_TABLES][CRC32_COLUMN_SIZE];
+
+ public:
+
+  // CRC32 Intrinsics.
+  static void generate_load_crc_table_addr(MacroAssembler* masm, Register table);
+
+};
+
+#endif // CPU_PPC_VM_STUBROUTINES_PPC_HPP
--- a/hotspot/src/cpu/ppc/vm/stubRoutines_ppc_64.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * 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 CPU_PPC_VM_STUBROUTINES_PPC_64_HPP
-#define CPU_PPC_VM_STUBROUTINES_PPC_64_HPP
-
-// This file holds the platform specific parts of the StubRoutines
-// definition. See stubRoutines.hpp for a description on how to
-// extend it.
-
-static bool returns_to_call_stub(address return_pc) { return return_pc == _call_stub_return_address; }
-
-enum platform_dependent_constants {
-  code_size1 = 20000,          // simply increase if too small (assembler will crash if too small)
-  code_size2 = 20000           // simply increase if too small (assembler will crash if too small)
-};
-
-// CRC32 Intrinsics.
-#define CRC32_COLUMN_SIZE 256
-#define CRC32_BYFOUR
-#ifdef  CRC32_BYFOUR
-  #define CRC32_TABLES 8
-#else
-  #define CRC32_TABLES 1
-#endif
-
-class ppc64 {
- friend class StubGenerator;
-
- private:
-
-  // CRC32 Intrinsics.
-  static juint _crc_table[CRC32_TABLES][CRC32_COLUMN_SIZE];
-
- public:
-
-  // CRC32 Intrinsics.
-  static void generate_load_crc_table_addr(MacroAssembler* masm, Register table);
-
-};
-
-#endif // CPU_PPC_VM_STUBROUTINES_PPC_64_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/cpu/ppc/vm/templateTable_ppc.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016 SAP SE. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * 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 CPU_PPC_VM_TEMPLATETABLE_PPC_HPP
+#define CPU_PPC_VM_TEMPLATETABLE_PPC_HPP
+
+  static void prepare_invoke(int byte_no, Register Rmethod, Register Rret_addr, Register Rindex, Register Rrecv, Register Rflags, Register Rscratch);
+  static void invokevfinal_helper(Register Rmethod, Register Rflags, Register Rscratch1, Register Rscratch2);
+  static void generate_vtable_call(Register Rrecv_klass, Register Rindex, Register Rret, Register Rtemp);
+  static void invokeinterface_object_method(Register Rrecv_klass, Register Rret, Register Rflags, Register Rindex, Register Rtemp, Register Rtemp2);
+
+  // Branch_conditional which takes TemplateTable::Condition.
+  static void branch_conditional(ConditionRegister crx, TemplateTable::Condition cc, Label& L, bool invert = false);
+  static void if_cmp_common(Register Rfirst, Register Rsecond, Register Rscratch1, Register Rscratch2, Condition cc, bool is_jint, bool cmp0);
+
+#endif // CPU_PPC_VM_TEMPLATETABLE_PPC_HPP
--- a/hotspot/src/cpu/ppc/vm/templateTable_ppc_64.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2013, 2014 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 CPU_PPC_VM_TEMPLATETABLE_PPC_64_HPP
-#define CPU_PPC_VM_TEMPLATETABLE_PPC_64_HPP
-
-  static void prepare_invoke(int byte_no, Register Rmethod, Register Rret_addr, Register Rindex, Register Rrecv, Register Rflags, Register Rscratch);
-  static void invokevfinal_helper(Register Rmethod, Register Rflags, Register Rscratch1, Register Rscratch2);
-  static void generate_vtable_call(Register Rrecv_klass, Register Rindex, Register Rret, Register Rtemp);
-  static void invokeinterface_object_method(Register Rrecv_klass, Register Rret, Register Rflags, Register Rindex, Register Rtemp, Register Rtemp2);
-
-  // Branch_conditional which takes TemplateTable::Condition.
-  static void branch_conditional(ConditionRegister crx, TemplateTable::Condition cc, Label& L, bool invert = false);
-  static void if_cmp_common(Register Rfirst, Register Rsecond, Register Rscratch1, Register Rscratch2, Condition cc, bool is_jint, bool cmp0);
-
-#endif // CPU_PPC_VM_TEMPLATETABLE_PPC_64_HPP
--- a/hotspot/src/cpu/ppc/vm/vm_version_ppc.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/vm_version_ppc.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -278,7 +278,7 @@
       os_too_old = false;
     }
 #endif
-#ifdef linux
+#ifdef LINUX
     // At least Linux kernel 4.2, as the problematic behavior of syscalls
     // being called in the middle of a transaction has been addressed.
     // Please, refer to commit b4b56f9ecab40f3b4ef53e130c9f6663be491894
--- a/hotspot/src/cpu/ppc/vm/vtableStubs_ppc_64.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/vtableStubs_ppc_64.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -26,7 +26,7 @@
 #include "precompiled.hpp"
 #include "asm/macroAssembler.inline.hpp"
 #include "code/vtableStubs.hpp"
-#include "interp_masm_ppc_64.hpp"
+#include "interp_masm_ppc.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/instanceKlass.hpp"
 #include "oops/klassVtable.hpp"
--- a/hotspot/src/cpu/x86/vm/bytes_x86.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/x86/vm/bytes_x86.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
 #define CPU_X86_VM_BYTES_X86_HPP
 
 #include "memory/allocation.hpp"
+#include "utilities/macros.hpp"
 
 class Bytes: AllStatic {
  private:
@@ -70,20 +71,7 @@
   static inline u8   swap_u8(u8 x);
 };
 
-
 // The following header contains the implementations of swap_u2, swap_u4, and swap_u8[_base]
-#ifdef TARGET_OS_ARCH_linux_x86
-# include "bytes_linux_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_x86
-# include "bytes_solaris_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_windows_x86
-# include "bytes_windows_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_x86
-# include "bytes_bsd_x86.inline.hpp"
-#endif
-
+#include OS_CPU_HEADER_INLINE(bytes)
 
 #endif // CPU_X86_VM_BYTES_X86_HPP
--- a/hotspot/src/cpu/x86/vm/copy_x86.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/x86/vm/copy_x86.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,19 +28,7 @@
 // Inline functions for memory copy and fill.
 
 // Contains inline asm implementations
-#ifdef TARGET_OS_ARCH_linux_x86
-# include "copy_linux_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_x86
-# include "copy_solaris_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_windows_x86
-# include "copy_windows_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_x86
-# include "copy_bsd_x86.inline.hpp"
-#endif
-
+#include OS_CPU_HEADER_INLINE(copy)
 
 static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) {
 #ifdef AMD64
--- a/hotspot/src/cpu/x86/vm/globalDefinitions_x86.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/x86/vm/globalDefinitions_x86.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -56,7 +56,7 @@
   #endif
 #endif
 
-#if defined(COMPILER2) && !defined(JAVASE_EMBEDDED)
+#if defined(COMPILER2)
 // Include Restricted Transactional Memory lock eliding optimization
 #define INCLUDE_RTM_OPT 1
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/cpu/x86/vm/macroAssembler_x86.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef CPU_X86_VM_MACROASSEMBLER_X86_INLINE_HPP
+#define CPU_X86_VM_MACROASSEMBLER_X86_INLINE_HPP
+
+// Still empty.
+
+#endif // CPU_X86_VM_MACROASSEMBLER_X86_INLINE_HPP
--- a/hotspot/src/cpu/x86/vm/register_definitions_x86.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/x86/vm/register_definitions_x86.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -26,9 +26,7 @@
 #include "asm/assembler.hpp"
 #include "asm/register.hpp"
 #include "register_x86.hpp"
-#ifdef TARGET_ARCH_x86
-# include "interp_masm_x86.hpp"
-#endif
+#include "interp_masm_x86.hpp"
 
 REGISTER_DEFINITION(Register, noreg);
 REGISTER_DEFINITION(Register, rax);
--- a/hotspot/src/cpu/x86/vm/stubRoutines_x86.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/x86/vm/stubRoutines_x86.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,83 @@
 // definition. See stubRoutines.hpp for a description on how to
 // extend it.
 
+static bool returns_to_call_stub(address return_pc) { return return_pc == _call_stub_return_address; }
+
+enum platform_dependent_constants {
+  code_size1 = 20000 LP64_ONLY(+10000),         // simply increase if too small (assembler will crash if too small)
+  code_size2 = 33800 LP64_ONLY(+1200)           // simply increase if too small (assembler will crash if too small)
+};
+
+class x86 {
+ friend class StubGenerator;
+ friend class VMStructs;
+
+#ifdef _LP64
+ private:
+  static address _get_previous_fp_entry;
+  static address _get_previous_sp_entry;
+
+  static address _f2i_fixup;
+  static address _f2l_fixup;
+  static address _d2i_fixup;
+  static address _d2l_fixup;
+
+  static address _float_sign_mask;
+  static address _float_sign_flip;
+  static address _double_sign_mask;
+  static address _double_sign_flip;
+
+ public:
+
+  static address get_previous_fp_entry() {
+    return _get_previous_fp_entry;
+  }
+
+  static address get_previous_sp_entry() {
+    return _get_previous_sp_entry;
+  }
+
+  static address f2i_fixup() {
+    return _f2i_fixup;
+  }
+
+  static address f2l_fixup() {
+    return _f2l_fixup;
+  }
+
+  static address d2i_fixup() {
+    return _d2i_fixup;
+  }
+
+  static address d2l_fixup() {
+    return _d2l_fixup;
+  }
+
+  static address float_sign_mask() {
+    return _float_sign_mask;
+  }
+
+  static address float_sign_flip() {
+    return _float_sign_flip;
+  }
+
+  static address double_sign_mask() {
+    return _double_sign_mask;
+  }
+
+  static address double_sign_flip() {
+    return _double_sign_flip;
+  }
+#else // !LP64
+
+ private:
+  static address _verify_fpu_cntrl_wrd_entry;
+
+ public:
+  static address verify_fpu_cntrl_wrd_entry() { return _verify_fpu_cntrl_wrd_entry; }
+
+#endif // !LP64
+
  private:
   static address _verify_mxcsr_entry;
   // shuffle mask for fixing up 128-bit words consisting of big-endian 32-bit integers
@@ -138,4 +215,6 @@
   static address _Pi4x4_addr()      { return _Pi4x4_adr; }
   static address _ones_addr()      { return _ones_adr; }
 
-#endif // CPU_X86_VM_STUBROUTINES_X86_32_HPP
+};
+
+#endif // CPU_X86_VM_STUBROUTINES_X86_HPP
--- a/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +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.
- *
- * 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_X86_VM_STUBROUTINES_X86_32_HPP
-#define CPU_X86_VM_STUBROUTINES_X86_32_HPP
-
-// This file holds the platform specific parts of the StubRoutines
-// definition. See stubRoutines.hpp for a description on how to
-// extend it.
-
-enum platform_dependent_constants {
-  code_size1 =  20000,           // simply increase if too small (assembler will crash if too small)
-  code_size2 = 33800            // simply increase if too small (assembler will crash if too small)
-};
-
-class x86 {
- friend class StubGenerator;
- friend class VMStructs;
-
- private:
-  static address _verify_fpu_cntrl_wrd_entry;
-
- public:
-  static address verify_fpu_cntrl_wrd_entry()                { return _verify_fpu_cntrl_wrd_entry; }
-
-# include "stubRoutines_x86.hpp"
-
-};
-
-  static bool    returns_to_call_stub(address return_pc)     { return return_pc == _call_stub_return_address; }
-
-#endif // CPU_X86_VM_STUBROUTINES_X86_32_HPP
--- a/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-/*
- * Copyright (c) 2003, 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.
- *
- * 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_X86_VM_STUBROUTINES_X86_64_HPP
-#define CPU_X86_VM_STUBROUTINES_X86_64_HPP
-
-// This file holds the platform specific parts of the StubRoutines
-// definition. See stubRoutines.hpp for a description on how to
-// extend it.
-
-static bool    returns_to_call_stub(address return_pc)   { return return_pc == _call_stub_return_address; }
-
-enum platform_dependent_constants {
-  code_size1 = 30000,          // simply increase if too small (assembler will crash if too small)
-  code_size2 = 35000           // simply increase if too small (assembler will crash if too small)
-};
-
-class x86 {
- friend class StubGenerator;
-
- private:
-  static address _get_previous_fp_entry;
-  static address _get_previous_sp_entry;
-
-  static address _f2i_fixup;
-  static address _f2l_fixup;
-  static address _d2i_fixup;
-  static address _d2l_fixup;
-
-  static address _float_sign_mask;
-  static address _float_sign_flip;
-  static address _double_sign_mask;
-  static address _double_sign_flip;
-
- public:
-
-  static address get_previous_fp_entry()
-  {
-    return _get_previous_fp_entry;
-  }
-
-  static address get_previous_sp_entry()
-  {
-    return _get_previous_sp_entry;
-  }
-
-  static address f2i_fixup()
-  {
-    return _f2i_fixup;
-  }
-
-  static address f2l_fixup()
-  {
-    return _f2l_fixup;
-  }
-
-  static address d2i_fixup()
-  {
-    return _d2i_fixup;
-  }
-
-  static address d2l_fixup()
-  {
-    return _d2l_fixup;
-  }
-
-  static address float_sign_mask()
-  {
-    return _float_sign_mask;
-  }
-
-  static address float_sign_flip()
-  {
-    return _float_sign_flip;
-  }
-
-  static address double_sign_mask()
-  {
-    return _double_sign_mask;
-  }
-
-  static address double_sign_flip()
-  {
-    return _double_sign_flip;
-  }
-
-# include "stubRoutines_x86.hpp"
-
-};
-
-#endif // CPU_X86_VM_STUBROUTINES_X86_64_HPP
--- a/hotspot/src/cpu/zero/vm/bytes_zero.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/cpu/zero/vm/bytes_zero.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2007, 2008, 2009 Red Hat, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -165,12 +165,8 @@
 #ifdef VM_LITTLE_ENDIAN
 // The following header contains the implementations of swap_u2,
 // swap_u4, and swap_u8
-#ifdef TARGET_OS_ARCH_linux_zero
-# include "bytes_linux_zero.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_zero
-# include "bytes_bsd_zero.inline.hpp"
-#endif
+
+#include OS_CPU_HEADER_INLINE(bytes)
 
 #endif // VM_LITTLE_ENDIAN
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/cpu/zero/vm/macroAssembler_zero.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef CPU_ZERO_VM_MACROASSEMBLER_ZERO_HPP
+#define CPU_ZERO_VM_MACROASSEMBLER_ZERO_HPP
+
+// Needed for includes in shared files.
+
+#endif // CPU_ZERO_VM_MACROASSEMBLER_ZERO_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/cpu/zero/vm/macroAssembler_zero.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef CPU_ZERO_VM_MACROASSEMBLER_ZERO_INLINE_HPP
+#define CPU_ZERO_VM_MACROASSEMBLER_ZERO_INLINE_HPP
+
+// Needed for includes in shared files.
+
+#endif // CPU_ZERO_VM_MACROASSEMBLER_ZERO_INLINE_HPP
--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java	Fri Jul 29 16:11:55 2016 -0700
@@ -242,7 +242,15 @@
   }
 
   public long getSize() {
-    return alignSize(getHeaderSize() + getVtableLen() + getItableLen() + getNonstaticOopMapSize());
+    long wordLength = VM.getVM().getBytesPerWord();
+    long size = getHeaderSize() +
+                (getVtableLen() +
+                 getItableLen() +
+                 getNonstaticOopMapSize()) * wordLength;
+    if (isInterface()) {
+      size += wordLength;
+    }
+    return alignSize(size);
   }
 
   public static long getHeaderSize() { return headerSize; }
--- a/hotspot/src/os/aix/vm/mutex_aix.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2014 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_MUTEX_AIX_INLINE_HPP
-#define OS_AIX_VM_MUTEX_AIX_INLINE_HPP
-
-#include "os_aix.inline.hpp"
-#include "runtime/interfaceSupport.hpp"
-#include "runtime/thread.inline.hpp"
-
-#endif // OS_AIX_VM_MUTEX_AIX_INLINE_HPP
--- a/hotspot/src/os/aix/vm/os_aix.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os/aix/vm/os_aix.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -44,7 +44,6 @@
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
 #include "misc_aix.hpp"
-#include "mutex_aix.inline.hpp"
 #include "oops/oop.inline.hpp"
 #include "os_aix.inline.hpp"
 #include "os_share_aix.hpp"
--- a/hotspot/src/os/bsd/vm/mutex_bsd.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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 "mutex_bsd.inline.hpp"
-#include "runtime/interfaceSupport.hpp"
-#include "runtime/mutex.hpp"
-#include "runtime/thread.inline.hpp"
-#include "utilities/events.hpp"
-
-// put OS-includes here
-# include <signal.h>
--- a/hotspot/src/os/bsd/vm/mutex_bsd.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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_MUTEX_BSD_INLINE_HPP
-#define OS_BSD_VM_MUTEX_BSD_INLINE_HPP
-
-#include "os_bsd.inline.hpp"
-#include "runtime/interfaceSupport.hpp"
-#include "runtime/thread.inline.hpp"
-
-
-// Reconciliation History
-// mutex_solaris.inline.hpp     1.5 99/06/22 16:38:49
-// End
-
-#endif // OS_BSD_VM_MUTEX_BSD_INLINE_HPP
--- a/hotspot/src/os/bsd/vm/os_bsd.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os/bsd/vm/os_bsd.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -35,7 +35,6 @@
 #include "logging/log.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
-#include "mutex_bsd.inline.hpp"
 #include "oops/oop.inline.hpp"
 #include "os_bsd.inline.hpp"
 #include "os_share_bsd.hpp"
--- a/hotspot/src/os/linux/vm/mutex_linux.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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 "mutex_linux.inline.hpp"
-#include "runtime/interfaceSupport.hpp"
-#include "runtime/mutex.hpp"
-#include "runtime/thread.inline.hpp"
-#include "utilities/events.hpp"
-
-// put OS-includes here
-# include <signal.h>
--- a/hotspot/src/os/linux/vm/mutex_linux.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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_MUTEX_LINUX_INLINE_HPP
-#define OS_LINUX_VM_MUTEX_LINUX_INLINE_HPP
-
-#include "os_linux.inline.hpp"
-#include "runtime/interfaceSupport.hpp"
-#include "runtime/thread.inline.hpp"
-
-
-// Reconciliation History
-// mutex_solaris.inline.hpp     1.5 99/06/22 16:38:49
-// End
-
-#endif // OS_LINUX_VM_MUTEX_LINUX_INLINE_HPP
--- a/hotspot/src/os/linux/vm/os_linux.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os/linux/vm/os_linux.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -35,7 +35,6 @@
 #include "logging/log.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
-#include "mutex_linux.inline.hpp"
 #include "oops/oop.inline.hpp"
 #include "os_linux.inline.hpp"
 #include "os_share_linux.hpp"
--- a/hotspot/src/os/posix/vm/os_posix.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os/posix/vm/os_posix.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -28,6 +28,7 @@
 #include "runtime/frame.inline.hpp"
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/os.hpp"
+#include "utilities/macros.hpp"
 #include "utilities/vmError.hpp"
 
 #include <signal.h>
@@ -214,7 +215,7 @@
   else st->print("%luk", rlim.rlim_cur >> 10);
 
   // Isn't there on solaris
-#if !defined(TARGET_OS_FAMILY_solaris) && !defined(TARGET_OS_FAMILY_aix)
+#if !defined(SOLARIS) && !defined(AIX)
   st->print(", NPROC ");
   getrlimit(RLIMIT_NPROC, &rlim);
   if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
@@ -1062,28 +1063,28 @@
 }
 
 address os::Posix::ucontext_get_pc(const ucontext_t* ctx) {
-#ifdef TARGET_OS_FAMILY_linux
+#if defined(AIX)
+   return Aix::ucontext_get_pc(ctx);
+#elif defined(BSD)
+   return Bsd::ucontext_get_pc(ctx);
+#elif defined(LINUX)
    return Linux::ucontext_get_pc(ctx);
-#elif defined(TARGET_OS_FAMILY_solaris)
+#elif defined(SOLARIS)
    return Solaris::ucontext_get_pc(ctx);
-#elif defined(TARGET_OS_FAMILY_aix)
-   return Aix::ucontext_get_pc(ctx);
-#elif defined(TARGET_OS_FAMILY_bsd)
-   return Bsd::ucontext_get_pc(ctx);
 #else
    VMError::report_and_die("unimplemented ucontext_get_pc");
 #endif
 }
 
 void os::Posix::ucontext_set_pc(ucontext_t* ctx, address pc) {
-#ifdef TARGET_OS_FAMILY_linux
+#if defined(AIX)
+   Aix::ucontext_set_pc(ctx, pc);
+#elif defined(BSD)
+   Bsd::ucontext_set_pc(ctx, pc);
+#elif defined(LINUX)
    Linux::ucontext_set_pc(ctx, pc);
-#elif defined(TARGET_OS_FAMILY_solaris)
+#elif defined(SOLARIS)
    Solaris::ucontext_set_pc(ctx, pc);
-#elif defined(TARGET_OS_FAMILY_aix)
-   Aix::ucontext_set_pc(ctx, pc);
-#elif defined(TARGET_OS_FAMILY_bsd)
-   Bsd::ucontext_set_pc(ctx, pc);
 #else
    VMError::report_and_die("unimplemented ucontext_get_pc");
 #endif
--- a/hotspot/src/os/posix/vm/vmError_posix.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os/posix/vm/vmError_posix.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,17 +33,17 @@
 #include <sys/wait.h>
 #include <signal.h>
 
-#ifdef TARGET_OS_FAMILY_linux
+#ifdef LINUX
 #include <sys/syscall.h>
 #include <unistd.h>
 #endif
-#ifdef TARGET_OS_FAMILY_solaris
+#ifdef SOLARIS
 #include <thread.h>
 #endif
-#ifdef TARGET_OS_FAMILY_aix
+#ifdef AIX
 #include <unistd.h>
 #endif
-#ifdef TARGET_OS_FAMILY_bsd
+#ifdef BSD
 #include <sys/syscall.h>
 #include <unistd.h>
 #endif
--- a/hotspot/src/os/solaris/vm/mutex_solaris.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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 "mutex_solaris.inline.hpp"
-#include "runtime/interfaceSupport.hpp"
-#include "runtime/mutex.hpp"
-#include "runtime/thread.inline.hpp"
-#include "utilities/events.hpp"
-
-// Solaris-specific include, therefore not in includeDB_*
-# include "os_share_solaris.hpp"
-
-// put OS-includes here
-# include <signal.h>
--- a/hotspot/src/os/solaris/vm/mutex_solaris.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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_MUTEX_SOLARIS_INLINE_HPP
-#define OS_SOLARIS_VM_MUTEX_SOLARIS_INLINE_HPP
-
-#include "os_solaris.inline.hpp"
-#include "runtime/interfaceSupport.hpp"
-#include "runtime/thread.inline.hpp"
-
-#endif // OS_SOLARIS_VM_MUTEX_SOLARIS_INLINE_HPP
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -35,7 +35,6 @@
 #include "logging/log.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
-#include "mutex_solaris.inline.hpp"
 #include "oops/oop.inline.hpp"
 #include "os_share_solaris.hpp"
 #include "os_solaris.inline.hpp"
@@ -79,7 +78,6 @@
 # include <link.h>
 # include <poll.h>
 # include <pthread.h>
-# include <pwd.h>
 # include <schedctl.h>
 # include <setjmp.h>
 # include <signal.h>
--- a/hotspot/src/os/solaris/vm/perfMemory_solaris.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os/solaris/vm/perfMemory_solaris.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -34,16 +34,18 @@
 #include "utilities/exceptions.hpp"
 
 // put OS-includes here
-# include <sys/types.h>
-# include <sys/mman.h>
-# include <errno.h>
-# include <stdio.h>
-# include <unistd.h>
-# include <sys/stat.h>
-# include <signal.h>
-# include <pwd.h>
-# include <procfs.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <procfs.h>
 
+/* For POSIX-compliant getpwuid_r on Solaris */
+#define _POSIX_PTHREAD_SEMANTICS
+#include <pwd.h>
 
 static char* backing_store_file_name = NULL;  // name of the backing store
                                               // file, if successfully created.
@@ -453,12 +455,8 @@
 
   char* pwbuf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
 
-#ifdef _GNU_SOURCE
   struct passwd* p = NULL;
   int result = getpwuid_r(uid, &pwent, pwbuf, (size_t)bufsize, &p);
-#else  // _GNU_SOURCE
-  struct passwd* p = getpwuid_r(uid, &pwent, pwbuf, (int)bufsize);
-#endif // _GNU_SOURCE
 
   if (p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') {
     if (PrintMiscellaneous && Verbose) {
--- a/hotspot/src/os/windows/vm/mutex_windows.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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 "mutex_windows.inline.hpp"
-#include "runtime/interfaceSupport.hpp"
-#include "runtime/mutex.hpp"
-#include "runtime/thread.inline.hpp"
-#include "utilities/events.hpp"
-
-// put OS-includes here
-# include <windows.h>
--- a/hotspot/src/os/windows/vm/mutex_windows.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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_MUTEX_WINDOWS_INLINE_HPP
-#define OS_WINDOWS_VM_MUTEX_WINDOWS_INLINE_HPP
-
-#include "os_windows.inline.hpp"
-#include "runtime/interfaceSupport.hpp"
-#include "runtime/thread.inline.hpp"
-
-#endif // OS_WINDOWS_VM_MUTEX_WINDOWS_INLINE_HPP
--- a/hotspot/src/os/windows/vm/os_windows.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os/windows/vm/os_windows.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -38,7 +38,6 @@
 #include "logging/log.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
-#include "mutex_windows.inline.hpp"
 #include "oops/oop.inline.hpp"
 #include "os_share_windows.hpp"
 #include "os_windows.inline.hpp"
@@ -3898,6 +3897,13 @@
     DWORD res;
     HANDLE hproc, hthr;
 
+    // We only attempt to register threads until a process exiting
+    // thread manages to set the process_exiting flag. Any threads
+    // that come through here after the process_exiting flag is set
+    // are unregistered and will be caught in the SuspendThread()
+    // infinite loop below.
+    bool registered = false;
+
     // The first thread that reached this point, initializes the critical section.
     if (!InitOnceExecuteOnce(&init_once_crit_sect, init_crit_sect_call, &crit_sect, NULL)) {
       warning("crit_sect initialization failed in %s: %d\n", __FILE__, __LINE__);
@@ -3957,13 +3963,22 @@
                              0, FALSE, DUPLICATE_SAME_ACCESS)) {
           warning("DuplicateHandle failed (%u) in %s: %d\n",
                   GetLastError(), __FILE__, __LINE__);
+
+          // We can't register this thread (no more handles) so this thread
+          // may be racing with a thread that is calling exit(). If the thread
+          // that is calling exit() has managed to set the process_exiting
+          // flag, then this thread will be caught in the SuspendThread()
+          // infinite loop below which closes that race. A small timing
+          // window remains before the process_exiting flag is set, but it
+          // is only exposed when we are out of handles.
         } else {
           ++handle_count;
+          registered = true;
+
+          // The current exiting thread has stored its handle in the array, and now
+          // should leave the critical section before calling _endthreadex().
         }
 
-        // The current exiting thread has stored its handle in the array, and now
-        // should leave the critical section before calling _endthreadex().
-
       } else if (what != EPT_THREAD && handle_count > 0) {
         jlong start_time, finish_time, timeout_left;
         // Before ending the process, make sure all the threads that had called
@@ -4012,10 +4027,11 @@
       LeaveCriticalSection(&crit_sect);
     }
 
-    if (OrderAccess::load_acquire(&process_exiting) != 0 &&
+    if (!registered &&
+        OrderAccess::load_acquire(&process_exiting) != 0 &&
         process_exiting != (jint)GetCurrentThreadId()) {
-      // Some other thread is about to call exit(), so we
-      // don't let the current thread proceed to exit() or _endthreadex()
+      // Some other thread is about to call exit(), so we don't let
+      // the current unregistered thread proceed to exit() or _endthreadex()
       while (true) {
         SuspendThread(GetCurrentThread());
         // Avoid busy-wait loop, if SuspendThread() failed.
@@ -4027,7 +4043,7 @@
   // We are here if either
   // - there's no 'race at exit' bug on this OS release;
   // - initialization of the critical section failed (unlikely);
-  // - the current thread has stored its handle and left the critical section;
+  // - the current thread has registered itself and left the critical section;
   // - the process-exiting thread has raised the flag and left the critical section.
   if (what == EPT_THREAD) {
     _endthreadex((unsigned)exit_code);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/os_cpu/aix_ppc/vm/bytes_aix_ppc.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef OS_CPU_AIX_PPC_VM_BYTES_AIX_PPC_INLINE_HPP
+#define OS_CPU_AIX_PPC_VM_BYTES_AIX_PPC_INLINE_HPP
+
+#if defined(VM_LITTLE_ENDIAN)
+// Aix is not little endian.
+#endif // VM_LITTLE_ENDIAN
+
+#endif // OS_CPU_AIX_PPC_VM_BYTES_AIX_PPC_INLINE_HPP
--- a/hotspot/src/os_cpu/aix_ppc/vm/os_aix_ppc.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os_cpu/aix_ppc/vm/os_aix_ppc.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -34,7 +34,6 @@
 #include "interpreter/interpreter.hpp"
 #include "jvm_aix.h"
 #include "memory/allocation.inline.hpp"
-#include "mutex_aix.inline.hpp"
 #include "nativeInst_ppc.hpp"
 #include "os_share_aix.hpp"
 #include "prims/jniFastGetField.hpp"
--- a/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -33,7 +33,6 @@
 #include "interpreter/interpreter.hpp"
 #include "jvm_bsd.h"
 #include "memory/allocation.inline.hpp"
-#include "mutex_bsd.inline.hpp"
 #include "os_share_bsd.hpp"
 #include "prims/jniFastGetField.hpp"
 #include "prims/jvm.h"
--- a/hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -38,7 +38,6 @@
 #include "interpreter/interpreter.hpp"
 #include "jvm_bsd.h"
 #include "memory/allocation.inline.hpp"
-#include "mutex_bsd.inline.hpp"
 #include "nativeInst_zero.hpp"
 #include "os_share_bsd.hpp"
 #include "prims/jniFastGetField.hpp"
--- a/hotspot/src/os_cpu/linux_aarch64/vm/os_linux_aarch64.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os_cpu/linux_aarch64/vm/os_linux_aarch64.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -35,7 +35,6 @@
 #include "interpreter/interpreter.hpp"
 #include "jvm_linux.h"
 #include "memory/allocation.inline.hpp"
-#include "mutex_linux.inline.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
 #include "prims/jvm.h"
--- a/hotspot/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -34,7 +34,6 @@
 #include "interpreter/interpreter.hpp"
 #include "jvm_linux.h"
 #include "memory/allocation.inline.hpp"
-#include "mutex_linux.inline.hpp"
 #include "nativeInst_ppc.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
--- a/hotspot/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -33,7 +33,6 @@
 #include "interpreter/interpreter.hpp"
 #include "jvm_linux.h"
 #include "memory/allocation.inline.hpp"
-#include "mutex_linux.inline.hpp"
 #include "nativeInst_sparc.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
--- a/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -33,7 +33,6 @@
 #include "interpreter/interpreter.hpp"
 #include "jvm_linux.h"
 #include "memory/allocation.inline.hpp"
-#include "mutex_linux.inline.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
 #include "prims/jvm.h"
--- a/hotspot/src/os_cpu/linux_zero/vm/os_linux_zero.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os_cpu/linux_zero/vm/os_linux_zero.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -33,7 +33,6 @@
 #include "interpreter/interpreter.hpp"
 #include "jvm_linux.h"
 #include "memory/allocation.inline.hpp"
-#include "mutex_linux.inline.hpp"
 #include "nativeInst_zero.hpp"
 #include "os_share_linux.hpp"
 #include "prims/jniFastGetField.hpp"
--- a/hotspot/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -34,7 +34,6 @@
 #include "interpreter/interpreter.hpp"
 #include "jvm_solaris.h"
 #include "memory/allocation.inline.hpp"
-#include "mutex_solaris.inline.hpp"
 #include "nativeInst_sparc.hpp"
 #include "os_share_solaris.hpp"
 #include "prims/jniFastGetField.hpp"
@@ -74,7 +73,6 @@
 # include <sys/systeminfo.h>
 # include <sys/socket.h>
 # include <sys/lwp.h>
-# include <pwd.h>
 # include <poll.h>
 # include <sys/lwp.h>
 
--- a/hotspot/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -33,7 +33,6 @@
 #include "interpreter/interpreter.hpp"
 #include "jvm_solaris.h"
 #include "memory/allocation.inline.hpp"
-#include "mutex_solaris.inline.hpp"
 #include "os_share_solaris.hpp"
 #include "prims/jniFastGetField.hpp"
 #include "prims/jvm.h"
@@ -74,7 +73,6 @@
 # include <sys/socket.h>
 # include <sys/trap.h>
 # include <sys/lwp.h>
-# include <pwd.h>
 # include <poll.h>
 # include <sys/lwp.h>
 # include <procfs.h>     //  see comment in <sys/procfs.h>
--- a/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -34,7 +34,6 @@
 #include "jvm_windows.h"
 #include "memory/allocation.inline.hpp"
 #include "memory/resourceArea.hpp"
-#include "mutex_windows.inline.hpp"
 #include "nativeInst_x86.hpp"
 #include "os_share_windows.hpp"
 #include "prims/jniFastGetField.hpp"
--- a/hotspot/src/share/vm/asm/assembler.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/asm/assembler.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,7 @@
 #include "runtime/vm_version.hpp"
 #include "utilities/debug.hpp"
 #include "utilities/growableArray.hpp"
+#include "utilities/macros.hpp"
 
 // This file contains platform-independent assembler declarations.
 
@@ -417,24 +418,6 @@
 
 };
 
-#ifdef TARGET_ARCH_x86
-# include "assembler_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "assembler_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "assembler_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "assembler_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "assembler_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "assembler_aarch64.hpp"
-#endif
-
+#include CPU_HEADER(assembler)
 
 #endif // SHARE_VM_ASM_ASSEMBLER_HPP
--- a/hotspot/src/share/vm/asm/assembler.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/asm/assembler.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,23 +27,6 @@
 
 #include "asm/assembler.hpp"
 
-#ifdef TARGET_ARCH_x86
-# include "assembler_x86.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "assembler_sparc.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "assembler_zero.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "assembler_arm.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "assembler_ppc.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "assembler_aarch64.inline.hpp"
-#endif
+#include CPU_HEADER_INLINE(assembler)
 
 #endif // SHARE_VM_ASM_ASSEMBLER_INLINE_HPP
--- a/hotspot/src/share/vm/asm/codeBuffer.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/asm/codeBuffer.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -28,6 +28,7 @@
 #include "code/oopRecorder.hpp"
 #include "code/relocInfo.hpp"
 #include "utilities/debug.hpp"
+#include "utilities/macros.hpp"
 
 class CodeStrings;
 class PhaseCFG;
@@ -633,24 +634,7 @@
 
 
   // The following header contains architecture-specific implementations
-#ifdef TARGET_ARCH_x86
-# include "codeBuffer_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "codeBuffer_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "codeBuffer_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "codeBuffer_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "codeBuffer_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "codeBuffer_aarch64.hpp"
-#endif
+#include CPU_HEADER(codeBuffer)
 
 };
 
--- a/hotspot/src/share/vm/asm/macroAssembler.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/asm/macroAssembler.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,24 +26,8 @@
 #define SHARE_VM_ASM_MACROASSEMBLER_HPP
 
 #include "asm/assembler.hpp"
+#include "utilities/macros.hpp"
 
-#ifdef TARGET_ARCH_x86
-# include "macroAssembler_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "macroAssembler_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "assembler_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "macroAssembler_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "macroAssembler_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "macroAssembler_aarch64.hpp"
-#endif
+#include CPU_HEADER(macroAssembler)
 
 #endif // SHARE_VM_ASM_MACROASSEMBLER_HPP
--- a/hotspot/src/share/vm/asm/macroAssembler.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/asm/macroAssembler.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,24 +26,6 @@
 #define SHARE_VM_ASM_MACROASSEMBLER_INLINE_HPP
 
 #include "asm/macroAssembler.hpp"
-
-#ifdef TARGET_ARCH_x86
-// no macroAssembler_x86.inline.hpp
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "macroAssembler_sparc.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "assembler_zero.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "macroAssembler_arm.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "macroAssembler_ppc.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "macroAssembler_aarch64.inline.hpp"
-#endif
+#include CPU_HEADER_INLINE(macroAssembler)
 
 #endif // SHARE_VM_ASM_MACROASSEMBLER_INLINE_HPP
--- a/hotspot/src/share/vm/asm/register.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/asm/register.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 
 #include "utilities/debug.hpp"
 #include "utilities/globalDefinitions.hpp"
+#include "utilities/macros.hpp"
 
 // Use AbstractRegister as shortcut
 class AbstractRegisterImpl;
@@ -94,25 +95,7 @@
 #define REGISTER_DEFINITION(type, name) \
 const type name = ((type)name##_##type##EnumValue)
 
-#ifdef TARGET_ARCH_x86
-# include "register_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "register_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "register_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "register_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "register_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "register_aarch64.hpp"
-#endif
-
+#include CPU_HEADER(register)
 
 // Debugging support
 
--- a/hotspot/src/share/vm/c1/c1_Defs.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/c1/c1_Defs.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,8 +25,9 @@
 #ifndef SHARE_VM_C1_C1_DEFS_HPP
 #define SHARE_VM_C1_C1_DEFS_HPP
 
+#include "asm/register.hpp"
 #include "utilities/globalDefinitions.hpp"
-#include "asm/register.hpp"
+#include "utilities/macros.hpp"
 
 // set frame size and return address offset to these values in blobs
 // (if the compiled frame uses ebp as link pointer on IA; otherwise,
@@ -35,23 +36,7 @@
   no_frame_size            = -1
 };
 
-
-#ifdef TARGET_ARCH_x86
-# include "c1_Defs_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "c1_Defs_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "c1_Defs_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "c1_Defs_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "c1_Defs_aarch64.hpp"
-#endif
-
+#include CPU_HEADER(c1_Defs)
 
 // native word offsets from memory address
 enum {
--- a/hotspot/src/share/vm/c1/c1_FpuStackSim.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/c1/c1_FpuStackSim.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,26 +27,12 @@
 
 #include "c1/c1_FrameMap.hpp"
 #include "memory/allocation.hpp"
+#include "utilities/macros.hpp"
 
 // Provides location for forward declaration of this class, which is
 // only implemented on Intel
 class FpuStackSim;
 
-#ifdef TARGET_ARCH_x86
-# include "c1_FpuStackSim_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "c1_FpuStackSim_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "c1_FpuStackSim_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "c1_FpuStackSim_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "c1_FpuStackSim_aarch64.hpp"
-#endif
-
+#include CPU_HEADER(c1_FpuStackSim)
 
 #endif // SHARE_VM_C1_C1_FPUSTACKSIM_HPP
--- a/hotspot/src/share/vm/c1/c1_FrameMap.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/c1/c1_FrameMap.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -33,6 +33,7 @@
 #include "runtime/frame.hpp"
 #include "runtime/synchronizer.hpp"
 #include "utilities/globalDefinitions.hpp"
+#include "utilities/macros.hpp"
 
 class ciMethod;
 class CallingConvention;
@@ -80,22 +81,7 @@
     spill_slot_size_in_bytes = 4
   };
 
-#ifdef TARGET_ARCH_x86
-# include "c1_FrameMap_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "c1_FrameMap_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "c1_FrameMap_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "c1_FrameMap_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "c1_FrameMap_aarch64.hpp"
-#endif
-
+#include CPU_HEADER(c1_FrameMap)
 
   friend class LIR_OprDesc;
 
--- a/hotspot/src/share/vm/c1/c1_LIRAssembler.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/c1/c1_LIRAssembler.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
 #include "c1/c1_CodeStubs.hpp"
 #include "ci/ciMethodData.hpp"
 #include "oops/methodData.hpp"
+#include "utilities/macros.hpp"
 
 class Compilation;
 class ScopeValue;
@@ -257,21 +258,7 @@
 
   void atomic_op(LIR_Code code, LIR_Opr src, LIR_Opr data, LIR_Opr dest, LIR_Opr tmp);
 
-#ifdef TARGET_ARCH_x86
-# include "c1_LIRAssembler_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "c1_LIRAssembler_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "c1_LIRAssembler_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "c1_LIRAssembler_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "c1_LIRAssembler_aarch64.hpp"
-#endif
+#include CPU_HEADER(c1_LIRAssembler)
 
 };
 
--- a/hotspot/src/share/vm/c1/c1_LinearScan.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/c1/c1_LinearScan.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -31,6 +31,7 @@
 #include "c1/c1_Instruction.hpp"
 #include "c1/c1_LIR.hpp"
 #include "c1/c1_LIRGenerator.hpp"
+#include "utilities/macros.hpp"
 
 class DebugInfoCache;
 class FpuStackAllocator;
@@ -959,23 +960,7 @@
 
 #endif // ifndef PRODUCT
 
-
 // Pick up platform-dependent implementation details
-#ifdef TARGET_ARCH_x86
-# include "c1_LinearScan_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "c1_LinearScan_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "c1_LinearScan_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "c1_LinearScan_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "c1_LinearScan_aarch64.hpp"
-#endif
-
+#include CPU_HEADER(c1_LinearScan)
 
 #endif // SHARE_VM_C1_C1_LINEARSCAN_HPP
--- a/hotspot/src/share/vm/c1/c1_MacroAssembler.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/c1/c1_MacroAssembler.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 
 #include "asm/macroAssembler.hpp"
 #include "asm/macroAssembler.inline.hpp"
+#include "utilities/macros.hpp"
 
 class CodeEmitInfo;
 
@@ -47,21 +48,7 @@
   void verify_stack_oop(int offset) PRODUCT_RETURN;
   void verify_not_null_oop(Register r)  PRODUCT_RETURN;
 
-#ifdef TARGET_ARCH_x86
-# include "c1_MacroAssembler_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "c1_MacroAssembler_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "c1_MacroAssembler_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "c1_MacroAssembler_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "c1_MacroAssembler_aarch64.hpp"
-#endif
+#include CPU_HEADER(c1_MacroAssembler)
 
 };
 
--- a/hotspot/src/share/vm/c1/c1_globals.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/c1/c1_globals.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -26,36 +26,10 @@
 #define SHARE_VM_C1_C1_GLOBALS_HPP
 
 #include "runtime/globals.hpp"
-#ifdef TARGET_ARCH_x86
-# include "c1_globals_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "c1_globals_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "c1_globals_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "c1_globals_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "c1_globals_aarch64.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_linux
-# include "c1_globals_linux.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "c1_globals_solaris.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "c1_globals_windows.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "c1_globals_aix.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "c1_globals_bsd.hpp"
-#endif
+#include "utilities/macros.hpp"
+
+#include CPU_HEADER(c1_globals)
+#include OS_HEADER(c1_globals)
 
 //
 // Defines all global flags used by the client compiler.
--- a/hotspot/src/share/vm/classfile/classFileParser.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classFileParser.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -5406,7 +5406,6 @@
                                  Symbol* name,
                                  ClassLoaderData* loader_data,
                                  Handle protection_domain,
-                                 TempNewSymbol* parsed_name,
                                  const Klass* host_klass,
                                  GrowableArray<Handle>* cp_patches,
                                  Publicity pub_level,
@@ -5416,7 +5415,6 @@
   _loader_data(loader_data),
   _host_klass(host_klass),
   _cp_patches(cp_patches),
-  _parsed_name(parsed_name),
   _super_klass(),
   _cp(NULL),
   _fields(NULL),
@@ -5657,15 +5655,6 @@
   Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index);
   assert(class_name_in_cp != NULL, "class_name can't be null");
 
-  if (_parsed_name != NULL) {
-    // It's important to set parsed_name *before* resolving the super class.
-    // (it's used for cleanup by the caller if parsing fails)
-    *_parsed_name = class_name_in_cp;
-    // parsed_name is returned and can be used if there's an error, so add to
-    // its reference count.  Caller will decrement the refcount.
-    (*_parsed_name)->increment_refcount();
-  }
-
   // Update _class_name which could be null previously
   // to reflect the name in the constant pool
   _class_name = class_name_in_cp;
@@ -5692,6 +5681,10 @@
     return;
   }
 
+  // Verification prevents us from creating names with dots in them, this
+  // asserts that that's the case.
+  assert(is_internal_format(_class_name), "external class name format used internally");
+
   if (!is_internal()) {
     if (log_is_enabled(Debug, class, preorder)){
       ResourceMark rm(THREAD);
@@ -5900,3 +5893,20 @@
 
   return _stream->clone();
 }
+// ----------------------------------------------------------------------------
+// debugging
+
+#ifdef ASSERT
+
+// return true if class_name contains no '.' (internal format is '/')
+bool ClassFileParser::is_internal_format(Symbol* class_name) {
+  if (class_name != NULL) {
+    ResourceMark rm;
+    char* name = class_name->as_C_string();
+    return strchr(name, '.') == NULL;
+  } else {
+    return true;
+  }
+}
+
+#endif
--- a/hotspot/src/share/vm/classfile/classFileParser.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classFileParser.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -81,7 +81,6 @@
   mutable ClassLoaderData* _loader_data;
   const Klass* _host_klass;
   GrowableArray<Handle>* _cp_patches; // overrides for CP entries
-  TempNewSymbol* _parsed_name;
 
   // Metadata created before the instance klass is created.  Must be deallocated
   // if not transferred to the InstanceKlass upon successful class loading
@@ -475,7 +474,6 @@
                   Symbol* name,
                   ClassLoaderData* loader_data,
                   Handle protection_domain,
-                  TempNewSymbol* parsed_name,
                   const Klass* host_klass,
                   GrowableArray<Handle>* cp_patches,
                   Publicity pub_level,
@@ -514,6 +512,11 @@
   bool is_internal() const { return INTERNAL == _pub_level; }
 
   static bool verify_unqualified_name(const char* name, unsigned int length, int type);
+
+#ifdef ASSERT
+  static bool is_internal_format(Symbol* class_name);
+#endif
+
 };
 
 #endif // SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP
--- a/hotspot/src/share/vm/classfile/classLoader.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classLoader.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -141,11 +141,11 @@
 PerfCounter*    ClassLoader::_load_instance_class_failCounter = NULL;
 
 GrowableArray<ModuleClassPathList*>* ClassLoader::_xpatch_entries = NULL;
-ClassPathEntry* ClassLoader::_first_entry        = NULL;
-ClassPathEntry* ClassLoader::_last_entry         = NULL;
+GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = NULL;
+ClassPathEntry* ClassLoader::_jrt_entry = NULL;
+ClassPathEntry* ClassLoader::_first_append_entry = NULL;
+ClassPathEntry* ClassLoader::_last_append_entry  = NULL;
 int             ClassLoader::_num_entries        = 0;
-ClassPathEntry* ClassLoader::_first_append_entry = NULL;
-bool            ClassLoader::_has_jimage = false;
 #if INCLUDE_CDS
 GrowableArray<char*>* ClassLoader::_boot_modules_array = NULL;
 GrowableArray<char*>* ClassLoader::_platform_modules_array = NULL;
@@ -508,7 +508,7 @@
 #endif
 
       } else {
-        PackageEntry* package_entry = get_package_entry(name, ClassLoaderData::the_null_class_loader_data(), THREAD);
+        PackageEntry* package_entry = get_package_entry(name, ClassLoaderData::the_null_class_loader_data(), CHECK_NULL);
         if (package_entry != NULL) {
           ResourceMark rm;
           // Get the module name
@@ -651,7 +651,6 @@
 #endif
 
 void ClassLoader::setup_bootstrap_search_path() {
-  assert(_first_entry == NULL, "should not setup bootstrap class search path twice");
   const char* sys_class_path = Arguments::get_sysclasspath();
   const char* java_class_path = Arguments::get_appclasspath();
   if (PrintSharedArchiveAndExit) {
@@ -694,7 +693,10 @@
   GrowableArray<ModuleXPatchPath*>* xpatch_args = Arguments::get_xpatchprefix();
   int num_of_entries = xpatch_args->length();
 
-  // Set up the boot loader's xpatch_entries list
+  assert(!DumpSharedSpaces, "DumpSharedSpaces not supported with -Xpatch");
+  assert(!UseSharedSpaces, "UseSharedSpaces not supported with -Xpatch");
+
+  // Set up the boot loader's _xpatch_entries list
   _xpatch_entries = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleClassPathList*>(num_of_entries, true);
 
   for (int i = 0; i < num_of_entries; i++) {
@@ -742,10 +744,9 @@
 }
 
 void ClassLoader::setup_search_path(const char *class_path, bool bootstrap_search) {
-  int offset = 0;
   int len = (int)strlen(class_path);
   int end = 0;
-  bool mark_append_entry = false;
+  bool set_base_piece = bootstrap_search;
 
   // Iterate over class path entries
   for (int start = 0; start < len; start = end) {
@@ -754,21 +755,45 @@
     }
     EXCEPTION_MARK;
     ResourceMark rm(THREAD);
-    mark_append_entry = (mark_append_entry ||
-      (bootstrap_search && (start == Arguments::bootclassloader_append_index())));
     char* path = NEW_RESOURCE_ARRAY(char, end - start + 1);
     strncpy(path, &class_path[start], end - start);
     path[end - start] = '\0';
-    update_class_path_entry_list(path, false, mark_append_entry, false, bootstrap_search);
+
+    // The first time through the bootstrap_search setup, it must be determined
+    // what the base or core piece of the boot loader search is.  Either a java runtime
+    // image is present or this is an exploded module build situation.
+    if (set_base_piece) {
+      assert(string_ends_with(path, MODULES_IMAGE_NAME) || string_ends_with(path, "java.base"),
+             "Incorrect boot loader search path, no java runtime image or java.base exploded build");
+      struct stat st;
+      if (os::stat(path, &st) == 0) {
+        // Directory found
+        Thread* THREAD = Thread::current();
+        ClassPathEntry* new_entry = create_class_path_entry(path, &st, false, false, CHECK);
 
-    // Check on the state of the boot loader's append path
-    if (mark_append_entry && (_first_append_entry == NULL)) {
-      // Failure to mark the first append entry, most likely
-      // due to a non-existent path. Record the next entry
-      // as the first boot loader append entry.
-      mark_append_entry = true;
+        // Check for a jimage
+        if (Arguments::has_jimage()) {
+          assert(_jrt_entry == NULL, "should not setup bootstrap class search path twice");
+          assert(new_entry != NULL && new_entry->is_jrt(), "No java runtime image present");
+          _jrt_entry = new_entry;
+          ++_num_entries;
+#if INCLUDE_CDS
+          if (DumpSharedSpaces) {
+            JImageFile *jimage = _jrt_entry->jimage();
+            assert(jimage != NULL, "No java runtime image file present");
+            ClassLoader::initialize_module_loader_map(jimage);
+          }
+#endif
+        }
+      } else {
+        // If path does not exist, exit
+        vm_exit_during_initialization("Unable to establish the boot loader search path", path);
+      }
+      set_base_piece = false;
     } else {
-      mark_append_entry = false;
+      // Every entry on the system boot class path after the initial base piece,
+      // which is set by os::set_boot_path(), is considered an appended entry.
+      update_class_path_entry_list(path, false, bootstrap_search);
     }
 
 #if INCLUDE_CDS
@@ -782,6 +807,45 @@
   }
 }
 
+// During an exploded modules build, each module defined to the boot loader
+// will be added to the ClassLoader::_exploded_entries array.
+void ClassLoader::add_to_exploded_build_list(Symbol* module_sym, TRAPS) {
+  assert(!ClassLoader::has_jrt_entry(), "Exploded build not applicable");
+
+  // Set up the boot loader's _exploded_entries list
+  if (_exploded_entries == NULL) {
+    _exploded_entries = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleClassPathList*>(EXPLODED_ENTRY_SIZE, true);
+  }
+
+  // Find the module's symbol
+  ResourceMark rm(THREAD);
+  const char *module_name = module_sym->as_C_string();
+  const char *home = Arguments::get_java_home();
+  const char file_sep = os::file_separator()[0];
+  // 10 represents the length of "modules" + 2 file separators + \0
+  size_t len = strlen(home) + strlen(module_name) + 10;
+  char *path = NEW_C_HEAP_ARRAY(char, len, mtModule);
+  jio_snprintf(path, len, "%s%cmodules%c%s", home, file_sep, file_sep, module_name);
+
+  struct stat st;
+  if (os::stat(path, &st) == 0) {
+    // Directory found
+    ClassPathEntry* new_entry = create_class_path_entry(path, &st, false, false, CHECK);
+
+    // If the path specification is valid, enter it into this module's list.
+    // There is no need to check for duplicate modules in the exploded entry list,
+    // since no two modules with the same name can be defined to the boot loader.
+    // This is checked at module definition time in Modules::define_module.
+    if (new_entry != NULL) {
+      ModuleClassPathList* module_cpl = new ModuleClassPathList(module_sym);
+      module_cpl->add_to_list(new_entry);
+      _exploded_entries->push(module_cpl);
+      log_info(class, load)("path: %s", path);
+    }
+  }
+  FREE_C_HEAP_ARRAY(char, path);
+}
+
 ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const struct stat* st,
                                                      bool throw_exception,
                                                      bool is_boot_append, TRAPS) {
@@ -872,21 +936,9 @@
   return NULL;
 }
 
-// The boot class loader must adhere to specfic visibility rules.
-// Prior to loading a class in a named package, the package is checked
-// to see if it is in a module defined to the boot loader. If the
-// package is not in a module defined to the boot loader, the class
-// must be loaded only in the boot loader's append path, which
-// consists of [-Xbootclasspath/a]; [jvmti appended entries]
-void ClassLoader::set_first_append_entry(ClassPathEntry *new_entry) {
-  if (_first_append_entry == NULL) {
-    _first_append_entry = new_entry;
-  }
-}
-
 // returns true if entry already on class path
 bool ClassLoader::contains_entry(ClassPathEntry *entry) {
-  ClassPathEntry* e = _first_entry;
+  ClassPathEntry* e = _first_append_entry;
   while (e != NULL) {
     // assume zip entries have been canonicalized
     if (strcmp(entry->name(), e->name()) == 0) {
@@ -899,41 +951,24 @@
 
 void ClassLoader::add_to_list(ClassPathEntry *new_entry) {
   if (new_entry != NULL) {
-    if (_last_entry == NULL) {
-      _first_entry = _last_entry = new_entry;
+    if (_last_append_entry == NULL) {
+      assert(_first_append_entry == NULL, "boot loader's append class path entry list not empty");
+      _first_append_entry = _last_append_entry = new_entry;
     } else {
-      _last_entry->set_next(new_entry);
-      _last_entry = new_entry;
+      _last_append_entry->set_next(new_entry);
+      _last_append_entry = new_entry;
     }
   }
-  _num_entries ++;
-}
-
-void ClassLoader::prepend_to_list(ClassPathEntry *new_entry) {
-  if (new_entry != NULL) {
-    if (_last_entry == NULL) {
-      _first_entry = _last_entry = new_entry;
-    } else {
-      new_entry->set_next(_first_entry);
-      _first_entry = new_entry;
-    }
-  }
-  _num_entries ++;
+  _num_entries++;
 }
 
 void ClassLoader::add_to_list(const char *apath) {
-  update_class_path_entry_list((char*)apath, false, false, false, false);
-}
-
-void ClassLoader::prepend_to_list(const char *apath) {
-  update_class_path_entry_list((char*)apath, false, false, true, false);
+  update_class_path_entry_list((char*)apath, false, false);
 }
 
 // Returns true IFF the file/dir exists and the entry was successfully created.
 bool ClassLoader::update_class_path_entry_list(const char *path,
                                                bool check_for_duplicates,
-                                               bool mark_append_entry,
-                                               bool prepend_entry,
                                                bool is_boot_append,
                                                bool throw_exception) {
   struct stat st;
@@ -946,19 +981,10 @@
       return false;
     }
 
-    // Ensure that the first boot loader append entry will always be set correctly.
-    assert((!mark_append_entry ||
-            (mark_append_entry && (!check_for_duplicates || !contains_entry(new_entry)))),
-           "failed to mark boot loader's first append boundary");
-
     // Do not reorder the bootclasspath which would break get_system_package().
     // Add new entry to linked list
-
     if (!check_for_duplicates || !contains_entry(new_entry)) {
-      ClassLoaderExt::add_class_path_entry(path, check_for_duplicates, new_entry, prepend_entry);
-      if (mark_append_entry) {
-        set_first_append_entry(new_entry);
-      }
+      ClassLoaderExt::add_class_path_entry(path, check_for_duplicates, new_entry);
     }
     return true;
   } else {
@@ -971,30 +997,47 @@
   }
 }
 
+static void print_module_entry_table(const GrowableArray<ModuleClassPathList*>* const module_list) {
+  ResourceMark rm;
+  int num_of_entries = module_list->length();
+  for (int i = 0; i < num_of_entries; i++) {
+    ClassPathEntry* e;
+    ModuleClassPathList* mpl = module_list->at(i);
+    tty->print("%s=", mpl->module_name()->as_C_string());
+    e = mpl->module_first_entry();
+    while (e != NULL) {
+      tty->print("%s", e->name());
+      e = e->next();
+      if (e != NULL) {
+        tty->print("%s", os::path_separator());
+      }
+    }
+    tty->print(" ;");
+  }
+}
+
 void ClassLoader::print_bootclasspath() {
   ClassPathEntry* e;
   tty->print("[bootclasspath= ");
 
   // Print -Xpatch module/path specifications first
   if (_xpatch_entries != NULL) {
-    ResourceMark rm;
-    int num_of_entries = _xpatch_entries->length();
-    for (int i = 0; i < num_of_entries; i++) {
-      ModuleClassPathList* mpl = _xpatch_entries->at(i);
-      tty->print("%s=", mpl->module_name()->as_C_string());
-      e = mpl->module_first_entry();
-      while (e != NULL) {
-        tty->print("%s", e->name());
-        e = e->next();
-        if (e != NULL) {
-          tty->print("%s", os::path_separator());
-        }
-      }
-      tty->print(" ;");
+    print_module_entry_table(_xpatch_entries);
+  }
+
+  // [jimage | exploded modules build]
+  if (has_jrt_entry()) {
+    // Print the location of the java runtime image
+    tty->print("%s ;", _jrt_entry->name());
+  } else {
+    // Print exploded module build path specifications
+    if (_exploded_entries != NULL) {
+      print_module_entry_table(_exploded_entries);
     }
   }
 
-  e = _first_entry;
+  // appended entries
+  e = _first_append_entry;
   while (e != NULL) {
     tty->print("%s ;", e->name());
     e = e->next();
@@ -1298,6 +1341,60 @@
   return file_name;
 }
 
+// Search either the xpatch or exploded build entries for class
+ClassFileStream* ClassLoader::search_module_entries(const GrowableArray<ModuleClassPathList*>* const module_list,
+                                                    const char* const class_name, const char* const file_name, TRAPS) {
+  ClassFileStream* stream = NULL;
+
+  // Find the class' defining module in the boot loader's module entry table
+  PackageEntry* pkg_entry = get_package_entry(class_name, ClassLoaderData::the_null_class_loader_data(), CHECK_NULL);
+  ModuleEntry* mod_entry = (pkg_entry != NULL) ? pkg_entry->module() : NULL;
+
+  // If the module system has not defined java.base yet, then
+  // classes loaded are assumed to be defined to java.base.
+  // When java.base is eventually defined by the module system,
+  // all packages of classes that have been previously loaded
+  // are verified in ModuleEntryTable::verify_javabase_packages().
+  if (!Universe::is_module_initialized() &&
+      !ModuleEntryTable::javabase_defined() &&
+      mod_entry == NULL) {
+    mod_entry = ModuleEntryTable::javabase_module();
+  }
+
+  // The module must be a named module
+  if (mod_entry != NULL && mod_entry->is_named()) {
+    int num_of_entries = module_list->length();
+    const Symbol* class_module_name = mod_entry->name();
+
+    // Loop through all the modules in either the xpatch or exploded entries looking for module
+    for (int i = 0; i < num_of_entries; i++) {
+      ModuleClassPathList* module_cpl = module_list->at(i);
+      Symbol* module_cpl_name = module_cpl->module_name();
+
+      if (module_cpl_name->fast_compare(class_module_name) == 0) {
+        // Class' module has been located, attempt to load
+        // the class from the module's ClassPathEntry list.
+        ClassPathEntry* e = module_cpl->module_first_entry();
+        while (e != NULL) {
+          stream = e->open_stream(file_name, CHECK_NULL);
+          // No context.check is required since CDS is not supported
+          // for an exploded modules build or if -Xpatch is specified.
+          if (NULL != stream) {
+            return stream;
+          }
+          e = e->next();
+        }
+        // If the module was located, break out even if the class was not
+        // located successfully from that module's ClassPathEntry list.
+        // There will not be another valid entry for that module.
+        return NULL;
+      }
+    }
+  }
+
+  return NULL;
+}
+
 instanceKlassHandle ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS) {
   assert(name != NULL, "invariant");
   assert(THREAD->is_Java_thread(), "must be a JavaThread");
@@ -1321,18 +1418,19 @@
   s2 classpath_index = 0;
   ClassPathEntry* e = NULL;
 
-  // If DumpSharedSpaces is true, boot loader visibility boundaries are set
-  // to be _first_entry to the end (all path entries). No -Xpatch entries are
-  // included since CDS and AppCDS are not supported if -Xpatch is specified.
+  // If DumpSharedSpaces is true boot loader visibility boundaries are set to:
+  //   - [jimage] + [_first_append_entry to _last_append_entry] (all path entries).
+  // No -Xpatch entries or exploded module builds are included since CDS
+  // is not supported if -Xpatch or exploded module builds are used.
   //
   // If search_append_only is true, boot loader visibility boundaries are
   // set to be _first_append_entry to the end. This includes:
   //   [-Xbootclasspath/a]; [jvmti appended entries]
   //
   // If both DumpSharedSpaces and search_append_only are false, boot loader
-  // visibility boundaries are set to be _first_entry to the entry before
-  // the _first_append_entry.  This would include:
-  //   [-Xpatch:<module>=<file>(<pathsep><file>)*];  [exploded build | jimage]
+  // visibility boundaries are set to be the -Xpatch entries plus the base piece.
+  // This would include:
+  //   [-Xpatch:<module>=<file>(<pathsep><file>)*]; [jimage | exploded module build]
   //
   // DumpSharedSpaces and search_append_only are mutually exclusive and cannot
   // be true at the same time.
@@ -1341,85 +1439,37 @@
   // Load Attempt #1: -Xpatch
   // Determine the class' defining module.  If it appears in the _xpatch_entries,
   // attempt to load the class from those locations specific to the module.
+  // Specifications to -Xpatch can contain a partial number of classes
+  // that are part of the overall module definition.  So if a particular class is not
+  // found within its module specification, the search should continue to Load Attempt #2.
   // Note: The -Xpatch entries are never searched if the boot loader's
   //       visibility boundary is limited to only searching the append entries.
   if (_xpatch_entries != NULL && !search_append_only && !DumpSharedSpaces) {
-    // Find the module in the boot loader's module entry table
-    PackageEntry* pkg_entry = get_package_entry(class_name, ClassLoaderData::the_null_class_loader_data(), THREAD);
-    ModuleEntry* mod_entry = (pkg_entry != NULL) ? pkg_entry->module() : NULL;
-
-    // If the module system has not defined java.base yet, then
-    // classes loaded are assumed to be defined to java.base.
-    // When java.base is eventually defined by the module system,
-    // all packages of classes that have been previously loaded
-    // are verified in ModuleEntryTable::verify_javabase_packages().
-    if (!Universe::is_module_initialized() &&
-        !ModuleEntryTable::javabase_defined() &&
-        mod_entry == NULL) {
-      mod_entry = ModuleEntryTable::javabase_module();
-    }
-
-    // The module must be a named module
-    if (mod_entry != NULL && mod_entry->is_named()) {
-      int num_of_entries = _xpatch_entries->length();
-      const Symbol* class_module_name = mod_entry->name();
-
-      // Loop through all the xpatch entries looking for module
-      for (int i = 0; i < num_of_entries; i++) {
-        ModuleClassPathList* module_cpl = _xpatch_entries->at(i);
-        Symbol* module_cpl_name = module_cpl->module_name();
-
-        if (module_cpl_name->fast_compare(class_module_name) == 0) {
-          // Class' module has been located, attempt to load
-          // the class from the module's ClassPathEntry list.
-          e = module_cpl->module_first_entry();
-          while (e != NULL) {
-            stream = e->open_stream(file_name, CHECK_NULL);
-            // No context.check is required since both CDS
-            // and AppCDS are turned off if -Xpatch is specified.
-            if (NULL != stream) {
-              break;
-            }
-            e = e->next();
-          }
-          // If the module was located in the xpatch entries, break out
-          // even if the class was not located successfully from that module's
-          // ClassPathEntry list. There will not be another valid entry for
-          // that module in the _xpatch_entries array.
-          break;
-        }
-      }
-    }
+    stream = search_module_entries(_xpatch_entries, class_name, file_name, CHECK_NULL);
   }
 
-  // Load Attempt #2: [exploded build | jimage]
+  // Load Attempt #2: [jimage | exploded build]
   if (!search_append_only && (NULL == stream)) {
-    e = _first_entry;
-    while ((e != NULL) && (e != _first_append_entry)) {
-      stream = e->open_stream(file_name, CHECK_NULL);
+    if (has_jrt_entry()) {
+      e = _jrt_entry;
+      stream = _jrt_entry->open_stream(file_name, CHECK_NULL);
       if (!context.check(stream, classpath_index)) {
         return NULL;
       }
-      if (NULL != stream) {
-        break;
-      }
-      e = e->next();
-      ++classpath_index;
+    } else {
+      // Exploded build - attempt to locate class in its defining module's location.
+      assert(_exploded_entries != NULL, "No exploded build entries present");
+      stream = search_module_entries(_exploded_entries, class_name, file_name, CHECK_NULL);
     }
   }
 
   // Load Attempt #3: [-Xbootclasspath/a]; [jvmti appended entries]
   if ((search_append_only || DumpSharedSpaces) && (NULL == stream)) {
-    // For the boot loader append path search, must calculate
-    // the starting classpath_index prior to attempting to
-    // load the classfile.
-    if (search_append_only) {
-      ClassPathEntry *tmp_e = _first_entry;
-      while ((tmp_e != NULL) && (tmp_e != _first_append_entry)) {
-        tmp_e = tmp_e->next();
-        ++classpath_index;
-      }
-    }
+    // For the boot loader append path search, the starting classpath_index
+    // for the appended piece is always 1 to account for either the
+    // _jrt_entry or the _exploded_entries.
+    assert(classpath_index == 0, "The classpath_index has been incremented incorrectly");
+    classpath_index = 1;
 
     e = _first_append_entry;
     while (e != NULL) {
@@ -1453,7 +1503,6 @@
                                                                 protection_domain,
                                                                 NULL, // host_klass
                                                                 NULL, // cp_patches
-                                                                NULL, // parsed_name
                                                                 THREAD);
   if (HAS_PENDING_EXCEPTION) {
     if (DumpSharedSpaces) {
@@ -1597,16 +1646,25 @@
 }
 
 // Complete the ClassPathEntry setup for the boot loader
-void classLoader_init2() {
+void ClassLoader::classLoader_init2(TRAPS) {
+  // Create the moduleEntry for java.base
+  create_javabase();
+
   // Setup the list of module/path pairs for -Xpatch processing
   // This must be done after the SymbolTable is created in order
   // to use fast_compare on module names instead of a string compare.
   if (Arguments::get_xpatchprefix() != NULL) {
-    ClassLoader::setup_xpatch_entries();
+    setup_xpatch_entries();
   }
 
-  // Determine if this is an exploded build
-  ClassLoader::set_has_jimage();
+  // Setup the initial java.base/path pair for the exploded build entries.
+  // As more modules are defined during module system initialization, more
+  // entries will be added to the exploded build array.
+  if (!has_jrt_entry()) {
+    assert(!DumpSharedSpaces, "DumpSharedSpaces not supported with exploded module builds");
+    assert(!UseSharedSpaces, "UsedSharedSpaces not supported with exploded module builds");
+    add_to_exploded_build_list(vmSymbols::java_base(), CHECK);
+  }
 }
 
 
@@ -1654,26 +1712,6 @@
   }
 }
 
-void ClassLoader::set_has_jimage() {
-  // Determine if this is an exploded build. When looking for
-  // the jimage file, only search the piece of the boot
-  // loader's boot class path which contains [exploded build | jimage].
-  // Do not search the boot loader's xpatch entries or append path.
-  ClassPathEntry* e = _first_entry;
-  ClassPathEntry* last_e = _first_append_entry;
-  while ((e != NULL) && (e != last_e)) {
-    JImageFile *jimage = e->jimage();
-    if (jimage != NULL && e->is_jrt()) {
-      _has_jimage = true;
-#if INCLUDE_CDS
-      ClassLoader::initialize_module_loader_map(jimage);
-#endif
-      return;
-    }
-    e = e->next();
-  }
-}
-
 #ifndef PRODUCT
 
 // CompileTheWorld
@@ -1762,14 +1800,19 @@
   HandleMark hm(THREAD);
   ResourceMark rm(THREAD);
 
+  assert(has_jrt_entry(), "Compile The World not supported with exploded module build");
+
   // Find bootstrap loader
   Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
-  // Iterate over all bootstrap class path entries
-  ClassPathEntry* e = _first_entry;
   jlong start = os::javaTimeMillis();
+
+  // Compile the world for the modular java runtime image
+  _jrt_entry->compile_the_world(system_class_loader, CATCH);
+
+  // Iterate over all bootstrap class path appended entries
+  ClassPathEntry* e = _first_append_entry;
   while (e != NULL) {
-    // We stop at "modules" jimage, unless it is the first bootstrap path entry
-    if (e->is_jrt() && e != _first_entry) break;
+    assert(!e->is_jrt(), "A modular java runtime image is present on the list of appended entries");
     e->compile_the_world(system_class_loader, CATCH);
     e = e->next();
   }
--- a/hotspot/src/share/vm/classfile/classLoader.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classLoader.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -216,33 +216,34 @@
   //  1. the module/path pairs specified to -Xpatch
   //    -Xpatch:<module>=<file>(<pathsep><file>)*
   //  2. the base piece
-  //    [exploded build | jimage]
+  //    [jimage | build with exploded modules]
   //  3. boot loader append path
   //    [-Xbootclasspath/a]; [jvmti appended entries]
   //
   // The boot loader must obey this order when attempting
   // to load a class.
 
-  // Contains the module/path pairs specified to -Xpatch
+  // 1. Contains the module/path pairs specified to -Xpatch
   static GrowableArray<ModuleClassPathList*>* _xpatch_entries;
 
-  // Contains the ClassPathEntry instances that include
-  // both the base piece and the boot loader append path.
-  static ClassPathEntry* _first_entry;
-  // Last entry in linked list of ClassPathEntry instances
-  static ClassPathEntry* _last_entry;
-  static int _num_entries;
+  // 2. the base piece
+  //    Contains the ClassPathEntry of the modular java runtime image.
+  //    If no java runtime image is present, this indicates a
+  //    build with exploded modules is being used instead.
+  static ClassPathEntry* _jrt_entry;
+  static GrowableArray<ModuleClassPathList*>* _exploded_entries;
+  enum { EXPLODED_ENTRY_SIZE = 80 }; // Initial number of exploded modules
 
-  // Marks the start of:
-  //   - the boot loader's append path
-  //     [-Xbootclasspath/a]; [jvmti appended entries]
-  // within the linked list of ClassPathEntry instances.
+  // 3. the boot loader's append path
+  //    [-Xbootclasspath/a]; [jvmti appended entries]
+  //    Note: boot loader append path does not support named modules.
   static ClassPathEntry* _first_append_entry;
-
-  static const char* _shared_archive;
+  // Last entry in linked list of appended ClassPathEntry instances
+  static ClassPathEntry* _last_append_entry;
 
-  // True if the boot path has a "modules" jimage
-  static bool _has_jimage;
+  // Note: _num_entries includes the java runtime image and all
+  //       the entries on the _first_append_entry linked list.
+  static int _num_entries;
 
   // Array of module names associated with the boot class loader
   CDS_ONLY(static GrowableArray<char*>* _boot_modules_array;)
@@ -253,9 +254,14 @@
   // Info used by CDS
   CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;)
 
-  // Initialization
+  // Initialization:
+  //   - setup the boot loader's system class path
+  //   - setup the boot loader's xpatch entries, if present
+  //   - create the ModuleEntry for java.base
   static void setup_bootstrap_search_path();
   static void setup_search_path(const char *class_path, bool setting_bootstrap);
+  static void setup_xpatch_entries();
+  static void create_javabase();
 
   static void load_zip_library();
   static void load_jimage_library();
@@ -285,8 +291,6 @@
   static int crc32(int crc, const char* buf, int len);
   static bool update_class_path_entry_list(const char *path,
                                            bool check_for_duplicates,
-                                           bool mark_append_entry,
-                                           bool prepend_entry,
                                            bool is_boot_append,
                                            bool throw_exception=true);
   static void print_bootclasspath();
@@ -352,15 +356,17 @@
     return _load_instance_class_failCounter;
   }
 
-  // Set up the module/path pairs as specified to -Xpatch
-  static void setup_xpatch_entries();
+  // Modular java runtime image is present vs. a build with exploded modules
+  static bool has_jrt_entry() { return (_jrt_entry != NULL); }
+  static ClassPathEntry* get_jrt_entry() { return _jrt_entry; }
 
-  // Sets _has_jimage to TRUE if "modules" jimage file exists
-  static void set_has_jimage();
-  static bool has_jimage() { return _has_jimage; }
+  // Add a module's exploded directory to the boot loader's exploded module build list
+  static void add_to_exploded_build_list(Symbol* module_name, TRAPS);
 
-  // Create the ModuleEntry for java.base
-  static void create_javabase();
+  // Attempt load of individual class from either the xpatch or exploded modules build lists
+  static ClassFileStream* search_module_entries(const GrowableArray<ModuleClassPathList*>* const module_list,
+                                                const char* const class_name,
+                                                const char* const file_name, TRAPS);
 
   // Load individual .class file
   static instanceKlassHandle load_class(Symbol* class_name, bool search_append_only, TRAPS);
@@ -381,17 +387,28 @@
 
   // Initialization
   static void initialize();
+  static void classLoader_init2(TRAPS);
   CDS_ONLY(static void initialize_shared_path();)
 
   static int compute_Object_vtable();
 
   static ClassPathEntry* classpath_entry(int n) {
-    ClassPathEntry* e = ClassLoader::_first_entry;
-    while (--n >= 0) {
-      assert(e != NULL, "Not that many classpath entries.");
-      e = e->next();
+    if (n == 0) {
+      assert(has_jrt_entry(), "No class path entry at 0 for exploded module builds");
+      return ClassLoader::_jrt_entry;
+    } else {
+      // The java runtime image is always the first entry
+      // in the FileMapInfo::_classpath_entry_table. Even though
+      // the _jrt_entry is not included in the _first_append_entry
+      // linked list, it must be accounted for when comparing the
+      // class path vs. the shared archive class path.
+      ClassPathEntry* e = ClassLoader::_first_append_entry;
+      while (--n >= 1) {
+        assert(e != NULL, "Not that many classpath entries.");
+        e = e->next();
+      }
+      return e;
     }
-    return e;
   }
 
 #if INCLUDE_CDS
@@ -429,18 +446,12 @@
   // adds a class path list
   static void add_to_list(ClassPathEntry* new_entry);
 
-  // prepends a class path list
-  static void prepend_to_list(ClassPathEntry* new_entry);
-
   // creates a class path zip entry (returns NULL if JAR file cannot be opened)
   static ClassPathZipEntry* create_class_path_zip_entry(const char *apath, bool is_boot_append);
 
   // add a path to class path list
   static void add_to_list(const char* apath);
 
-  // prepend a path to class path list
-  static void prepend_to_list(const char* apath);
-
   static bool string_ends_with(const char* str, const char* str_to_find);
 
   // obtain package name from a fully qualified class name
--- a/hotspot/src/share/vm/classfile/classLoaderExt.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classLoaderExt.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -71,22 +71,11 @@
 
 
   static void add_class_path_entry(const char* path, bool check_for_duplicates,
-                                   ClassPathEntry* new_entry, bool prepend_entry) {
-    if (prepend_entry) {
-      ClassLoader::prepend_to_list(new_entry);
-    } else {
-      ClassLoader::add_to_list(new_entry);
-    }
+                                   ClassPathEntry* new_entry) {
+    ClassLoader::add_to_list(new_entry);
   }
   static void append_boot_classpath(ClassPathEntry* new_entry) {
     ClassLoader::add_to_list(new_entry);
-    // During jvmti live phase an entry can be appended to the boot
-    // loader's ClassPathEntry instances.  Need to mark the start
-    // of the boot loader's append path in case there was no reason
-    // to mark it initially in setup_bootstrap_search_path.
-    if (ClassLoader::_first_append_entry == NULL) {
-      ClassLoader::set_first_append_entry(new_entry);
-    }
   }
   static void setup_search_paths() {}
   static bool is_boot_classpath(int classpath_index) {
--- a/hotspot/src/share/vm/classfile/dictionary.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/dictionary.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -396,14 +396,15 @@
 DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
                                        Symbol* class_name,
                                        ClassLoaderData* loader_data) {
-  debug_only(_lookup_count++);
+  DEBUG_ONLY(_lookup_count++);
   for (DictionaryEntry* entry = bucket(index);
                         entry != NULL;
                         entry = entry->next()) {
     if (entry->hash() == hash && entry->equals(class_name, loader_data)) {
+      DEBUG_ONLY(bucket_count_hit(index));
       return entry;
     }
-    debug_only(_lookup_length++);
+    DEBUG_ONLY(_lookup_length++);
   }
   return NULL;
 }
@@ -596,7 +597,7 @@
   }
   guarantee(number_of_entries() == element_count,
             "Verify of protection domain cache table failed");
-  debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
+  DEBUG_ONLY(verify_lookup_length((double)number_of_entries() / table_size()));
 }
 
 void ProtectionDomainCacheEntry::verify() {
@@ -737,19 +738,65 @@
                    table_size(), number_of_entries());
     tty->print_cr("^ indicates that initiating loader is different from "
                   "defining loader");
+    tty->print_cr("1st number: th bucket index");
+    tty->print_cr("2nd number: the entry's index within this bucket");
+#ifdef ASSERT
+    tty->print_cr("3rd number: the hit percentage of this entry");
+    tty->print_cr("4th number: the hash index of this entry");
+#endif
   }
 
+#ifdef ASSERT
+  // find top buckets with highest lookup count
+  #define TOP_COUNT 16
+  int topItemsIndicies[TOP_COUNT];
+  for (int i = 0; i < TOP_COUNT; i++) {
+    topItemsIndicies[i] = i;
+  }
+  double total = 0.0;
+  for (int i = 0; i < table_size(); i++) {
+    // find the total count number, so later on we can
+    // express bucket lookup count as a percentage of all lookups
+    unsigned value = bucket_hits(i);
+    total += value;
+
+    // find the entry with min value
+    int index = 0;
+    unsigned min = bucket_hits(topItemsIndicies[index]);
+    for (int j = 1; j < TOP_COUNT; j++) {
+      if (bucket_hits(topItemsIndicies[j]) < min) {
+        min = bucket_hits(topItemsIndicies[j]);
+        index = j;
+      }
+    }
+    // if the bucket loookup value is bigger than the current min
+    // move that bucket index into the top list
+    if (value > min) {
+      topItemsIndicies[index] = i;
+    }
+  }
+#endif
+
   for (int index = 0; index < table_size(); index++) {
+#ifdef ASSERT
+    double percentage = 100.0 * (double)bucket_hits(index)/total;
+#endif
+    int chain = 0;
     for (DictionaryEntry* probe = bucket(index);
                           probe != NULL;
                           probe = probe->next()) {
-      if (Verbose) tty->print("%4d: ", index);
       Klass* e = probe->klass();
       ClassLoaderData* loader_data =  probe->loader_data();
       bool is_defining_class =
          (loader_data == e->class_loader_data());
+      if (details) {
+        tty->print("%4d: %3d: ", index, chain);
+#ifdef ASSERT
+        tty->print("%5.2f%%: %10u:", percentage, probe->hash());
+#endif
+      }
       tty->print("%s%s", ((!details) || is_defining_class) ? " " : "^",
-                   e->external_name());
+                 e->external_name());
 
       if (details) {
         tty->print(", loader ");
@@ -760,9 +807,30 @@
         }
       }
       tty->cr();
+
+      chain++;
+    }
+    if (details && (chain == 0)) {
+      tty->print("%4d:", index);
+      tty->cr();
     }
   }
 
+#ifdef ASSERT
+  // print out the TOP_COUNT of buckets with highest lookup count (unsorted)
+  if (details) {
+    tty->cr();
+    tty->print("Top %d buckets:", TOP_COUNT);
+    tty->cr();
+    for (int i = 0; i < TOP_COUNT; i++) {
+      tty->print("%4d: hits %5.2f%%",
+                 topItemsIndicies[i],
+                 100.0*(double)bucket_hits(topItemsIndicies[i])/total);
+      tty->cr();
+    }
+  }
+#endif
+
   if (details) {
     tty->cr();
     _pd_cache_table->print();
@@ -795,7 +863,7 @@
   }
   guarantee(number_of_entries() == element_count,
             "Verify of system dictionary failed");
-  debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
+  DEBUG_ONLY(if (!verify_lookup_length((double)number_of_entries() / table_size())) this->print(true));
 
   _pd_cache_table->verify();
 }
--- a/hotspot/src/share/vm/classfile/javaClasses.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/javaClasses.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -777,9 +777,6 @@
     static Handle create(Handle loader, Handle module_name, TRAPS);
 
     // Testers
-    static bool is_subclass(Klass* klass) {
-      return klass->is_subclass_of(SystemDictionary::reflect_Module_klass());
-    }
     static bool is_instance(oop obj);
 
     // Accessors
--- a/hotspot/src/share/vm/classfile/javaClasses.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/javaClasses.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -168,11 +168,8 @@
   return obj != NULL && is_subclass(obj->klass());
 }
 
-
-
-
 inline bool java_lang_reflect_Module::is_instance(oop obj) {
-  return obj != NULL && is_subclass(obj->klass());
+  return obj != NULL && obj->klass() == SystemDictionary::reflect_Module_klass();
 }
 
 inline int Backtrace::merge_bci_and_version(int bci, int version) {
--- a/hotspot/src/share/vm/classfile/klassFactory.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/klassFactory.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -96,7 +96,6 @@
                                                      Handle protection_domain,
                                                      const Klass* host_klass,
                                                      GrowableArray<Handle>* cp_patches,
-                                                     TempNewSymbol* parsed_name,
                                                      TRAPS) {
 
   assert(stream != NULL, "invariant");
@@ -123,7 +122,6 @@
                          name,
                          loader_data,
                          protection_domain,
-                         parsed_name,
                          host_klass,
                          cp_patches,
                          ClassFileParser::BROADCAST, // publicity level
--- a/hotspot/src/share/vm/classfile/klassFactory.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/klassFactory.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
@@ -74,7 +74,6 @@
                                                 Handle protection_domain,
                                                 const Klass* host_klass,
                                                 GrowableArray<Handle>* cp_patches,
-                                                TempNewSymbol* parsed_name,
                                                 TRAPS);
 };
 
--- a/hotspot/src/share/vm/classfile/modules.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/modules.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -102,7 +102,8 @@
 static ModuleEntry* get_module_entry(jobject module, TRAPS) {
   Handle module_h(THREAD, JNIHandles::resolve(module));
   if (!java_lang_reflect_Module::is_instance(module_h())) {
-    THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Bad module object");
+    THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
+                   "module is not an instance of type java.lang.reflect.Module");
   }
   return java_lang_reflect_Module::module_entry(module_h(), CHECK_NULL);
 }
@@ -133,36 +134,6 @@
   return NULL;
 }
 
-// If using exploded build, append <java.home>/modules/module_name, if it exists,
-// to the system boot class path in order for the boot loader to locate class files.
-static void add_to_exploded_build_list(char *module_name, TRAPS) {
-  assert(!ClassLoader::has_jimage(), "Exploded build not applicable");
-  // java.base is handled by os::set_boot_path
-  assert(strcmp(module_name, "java.base") != 0, "Unexpected java.base module name");
-
-  char file_sep = os::file_separator()[0];
-  size_t module_len = strlen(module_name);
-
-  const char* home = Arguments::get_java_home();
-  size_t len = strlen(home) + module_len + 32;
-  char* path = NEW_C_HEAP_ARRAY(char, len, mtModule);
-  jio_snprintf(path, len, "%s%cmodules%c%s", home, file_sep, file_sep, module_name);
-  struct stat st;
-  // See if exploded module path exists
-  if ((os::stat(path, &st) != 0)) {
-    FREE_C_HEAP_ARRAY(char, path);
-    path = NULL;
-  }
-
-  if (path != NULL) {
-    HandleMark hm;
-    Handle loader_lock = Handle(THREAD, SystemDictionary::system_loader_lock());
-    ObjectLocker ol(loader_lock, THREAD);
-    log_info(class, load)("opened: %s", path);
-    ClassLoader::add_to_list(path);
-  }
-}
-
 bool Modules::is_package_defined(Symbol* package, Handle h_loader, TRAPS) {
   PackageEntry* res = get_package_entry_by_name(package, h_loader, CHECK_false);
   return res != NULL;
@@ -297,9 +268,9 @@
     THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object");
   }
   Handle module_handle(THREAD, JNIHandles::resolve(module));
-  if (!java_lang_reflect_Module::is_subclass(module_handle->klass())) {
+  if (!java_lang_reflect_Module::is_instance(module_handle())) {
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-              "module is not a subclass of java.lang.reflect.Module");
+              "module is not an instance of type java.lang.reflect.Module");
   }
 
   char* module_name = get_module_name(module_handle(), CHECK);
@@ -470,8 +441,8 @@
   // used, prepend <java.home>/modules/modules_name, if it exists, to the system boot class path.
   if (loader == NULL &&
       !Universe::is_module_initialized() &&
-      !ClassLoader::has_jimage()) {
-    add_to_exploded_build_list(module_name, CHECK);
+      !ClassLoader::has_jrt_entry()) {
+    ClassLoader::add_to_exploded_build_list(module_symbol, CHECK);
   }
 }
 
@@ -482,9 +453,9 @@
     THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object");
   }
   Handle module_handle(THREAD, JNIHandles::resolve(module));
-  if (!java_lang_reflect_Module::is_subclass(module_handle->klass())) {
+  if (!java_lang_reflect_Module::is_instance(module_handle())) {
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-              "module is not a subclass of java.lang.reflect.Module");
+              "module is not an instance of type java.lang.reflect.Module");
   }
 
   // Ensure that this is an unnamed module
@@ -758,7 +729,7 @@
   oop module = java_lang_Class::module(mirror);
 
   assert(module != NULL, "java.lang.Class module field not set");
-  assert(java_lang_reflect_Module::is_subclass(module->klass()), "Module is not a java.lang.reflect.Module");
+  assert(java_lang_reflect_Module::is_instance(module), "module is not an instance of type java.lang.reflect.Module");
 
   if (log_is_enabled(Debug, modules)) {
     ResourceMark rm(THREAD);
--- a/hotspot/src/share/vm/classfile/sharedPathsMiscInfo.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/sharedPathsMiscInfo.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,7 +29,7 @@
 #include "runtime/os.hpp"
 
 // During dumping time, when processing class paths, we build up the dump-time
-// classpath. The JAR files that exist are stored in the list ClassLoader::_first_entry.
+// classpath. The JAR files that exist are stored in the list ClassLoader::_first_append_entry.
 // However, we need to store other "misc" information for run-time checking, such as
 //
 // + The values of Arguments::get_sysclasspath() used during dumping.
--- a/hotspot/src/share/vm/classfile/systemDictionary.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -70,7 +70,6 @@
 #include "services/threadService.hpp"
 #include "trace/traceMacros.hpp"
 #include "utilities/macros.hpp"
-#include "utilities/stringUtils.hpp"
 #include "utilities/ticks.hpp"
 #if INCLUDE_CDS
 #include "classfile/sharedClassUtil.hpp"
@@ -140,24 +139,6 @@
 }
 
 // ----------------------------------------------------------------------------
-// debugging
-
-#ifdef ASSERT
-
-// return true if class_name contains no '.' (internal format is '/')
-bool SystemDictionary::is_internal_format(Symbol* class_name) {
-  if (class_name != NULL) {
-    ResourceMark rm;
-    char* name = class_name->as_C_string();
-    return strchr(name, '.') == NULL;
-  } else {
-    return true;
-  }
-}
-
-#endif
-
-// ----------------------------------------------------------------------------
 // Parallel class loading check
 
 bool SystemDictionary::is_parallelCapable(Handle class_loader) {
@@ -335,6 +316,10 @@
 // Must be called, even if superclass is null, since this is
 // where the placeholder entry is created which claims this
 // thread is loading this class/classloader.
+// Be careful when modifying this code: once you have run
+// placeholders()->find_and_add(PlaceholderTable::LOAD_SUPER),
+// you need to find_and_remove it before returning.
+// So be careful to not exit with a CHECK_ macro betweeen these calls.
 Klass* SystemDictionary::resolve_super_or_fail(Symbol* child_name,
                                                  Symbol* class_name,
                                                  Handle class_loader,
@@ -399,6 +384,7 @@
       }
     }
     if (!throw_circularity_error) {
+      // Be careful not to exit resolve_super
       PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, class_name, THREAD);
     }
   }
@@ -655,6 +641,24 @@
 #endif // INCLUDE_TRACE
 }
 
+// utility function for class define event
+static void class_define_event(instanceKlassHandle k) {
+#if INCLUDE_TRACE
+  EventClassDefine event(UNTIMED);
+  if (event.should_commit()) {
+    event.set_definedClass(k());
+    oop defining_class_loader = k->class_loader();
+    event.set_definingClassLoader(defining_class_loader != NULL ?
+      defining_class_loader->klass() : (Klass*)NULL);
+    event.commit();
+  }
+#endif // INCLUDE_TRACE
+}
+
+// Be careful when modifying this code: once you have run
+// placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
+// you need to find_and_remove it before returning.
+// So be careful to not exit with a CHECK_ macro betweeen these calls.
 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
                                                         Handle class_loader,
                                                         Handle protection_domain,
@@ -1016,8 +1020,9 @@
 }
 
 // Note: this method is much like resolve_from_stream, but
-// updates no supplemental data structures.
-// TODO consolidate the two methods with a helper routine?
+// does not publish the classes via the SystemDictionary.
+// Handles unsafe_DefineAnonymousClass and redefineclasses
+// RedefinedClasses do not add to the class hierarchy
 Klass* SystemDictionary::parse_stream(Symbol* class_name,
                                       Handle class_loader,
                                       Handle protection_domain,
@@ -1054,8 +1059,7 @@
                                                            protection_domain,
                                                            host_klass,
                                                            cp_patches,
-                                                           NULL, // parsed_name
-                                                           THREAD);
+                                                           CHECK_NULL);
 
   if (host_klass != NULL && k.not_null()) {
     // If it's anonymous, initialize it now, since nobody else will.
@@ -1126,8 +1130,6 @@
   // already be present in the SystemDictionary, otherwise we would not
   // throw potential ClassFormatErrors.
   //
-  // Note: "parsed_name" is updated.
-  TempNewSymbol parsed_name = NULL;
 
  instanceKlassHandle k;
 
@@ -1139,9 +1141,7 @@
                                                  CHECK_NULL);
 #endif
 
-  if (k.not_null()) {
-    parsed_name = k->name();
-  } else {
+  if (k.is_null()) {
     if (st->buffer() == NULL) {
       return NULL;
     }
@@ -1151,64 +1151,28 @@
                                          protection_domain,
                                          NULL, // host_klass
                                          NULL, // cp_patches
-                                         &parsed_name,
-                                         THREAD);
+                                         CHECK_NULL);
   }
 
-  const char* pkg = "java/";
-  if (!HAS_PENDING_EXCEPTION &&
-      !class_loader.is_null() &&
-      !SystemDictionary::is_platform_class_loader(class_loader) &&
-      parsed_name != NULL &&
-      !strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) {
-    // It is illegal to define classes in the "java." package from
-    // JVM_DefineClass or jni_DefineClass unless you're the bootclassloader
-    ResourceMark rm(THREAD);
-    TempNewSymbol pkg_name = InstanceKlass::package_from_name(parsed_name, CHECK_NULL);
-    assert(pkg_name != NULL, "Error in parsing package name starting with 'java/'");
-    char* name = pkg_name->as_C_string();
-    StringUtils::replace_no_expand(name, "/", ".");
-    const char* msg_text = "Prohibited package name: ";
-    size_t len = strlen(msg_text) + strlen(name) + 1;
-    char* message = NEW_RESOURCE_ARRAY(char, len);
-    jio_snprintf(message, len, "%s%s", msg_text, name);
-    Exceptions::_throw_msg(THREAD_AND_LOCATION,
-      vmSymbols::java_lang_SecurityException(), message);
-  }
+  assert(k.not_null(), "no klass created");
+  Symbol* h_name = k->name();
+  assert(class_name == NULL || class_name == h_name, "name mismatch");
 
-  if (!HAS_PENDING_EXCEPTION) {
-    assert(parsed_name != NULL, "Sanity");
-    assert(class_name == NULL || class_name == parsed_name, "name mismatch");
-    // Verification prevents us from creating names with dots in them, this
-    // asserts that that's the case.
-    assert(is_internal_format(parsed_name),
-           "external class name format used internally");
-
-    // Add class just loaded
-    // If a class loader supports parallel classloading handle parallel define requests
-    // find_or_define_instance_class may return a different InstanceKlass
-    if (is_parallelCapable(class_loader)) {
-      k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
-    } else {
-      define_instance_class(k, THREAD);
-    }
+  // Add class just loaded
+  // If a class loader supports parallel classloading handle parallel define requests
+  // find_or_define_instance_class may return a different InstanceKlass
+  if (is_parallelCapable(class_loader)) {
+    k = find_or_define_instance_class(h_name, class_loader, k, CHECK_NULL);
+  } else {
+    define_instance_class(k, CHECK_NULL);
   }
 
   // Make sure we have an entry in the SystemDictionary on success
   debug_only( {
-    if (!HAS_PENDING_EXCEPTION) {
-      assert(parsed_name != NULL, "parsed_name is still null?");
-      Symbol*  h_name    = k->name();
-      ClassLoaderData *defining_loader_data = k->class_loader_data();
-
-      MutexLocker mu(SystemDictionary_lock, THREAD);
+    MutexLocker mu(SystemDictionary_lock, THREAD);
 
-      Klass* check = find_class(parsed_name, loader_data);
-      assert(check == k(), "should be present in the dictionary");
-
-      Klass* check2 = find_class(h_name, defining_loader_data);
-      assert(check == check2, "name inconsistancy in SystemDictionary");
-    }
+    Klass* check = find_class(h_name, k->class_loader_data());
+    assert(check == k(), "should be present in the dictionary");
   } );
 
   return k();
@@ -1246,12 +1210,16 @@
 
 instanceKlassHandle SystemDictionary::load_shared_class(
                  Symbol* class_name, Handle class_loader, TRAPS) {
-  instanceKlassHandle ik (THREAD, find_shared_class(class_name));
-  // Make sure we only return the boot class for the NULL classloader.
-  if (ik.not_null() &&
-      ik->is_shared_boot_class() && class_loader.is_null()) {
-    Handle protection_domain;
-    return load_shared_class(ik, class_loader, protection_domain, THREAD);
+  // Don't load shared class when JvmtiExport::should_post_class_file_load_hook()
+  // is enabled since posting CFLH is not supported when loading shared class.
+  if (!JvmtiExport::should_post_class_file_load_hook()) {
+    instanceKlassHandle ik (THREAD, find_shared_class(class_name));
+    // Make sure we only return the boot class for the NULL classloader.
+    if (ik.not_null() &&
+        ik->is_shared_boot_class() && class_loader.is_null()) {
+      Handle protection_domain;
+      return load_shared_class(ik, class_loader, protection_domain, THREAD);
+    }
   }
   return instanceKlassHandle();
 }
@@ -1334,8 +1302,14 @@
 instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik,
                                                         Handle class_loader,
                                                         Handle protection_domain, TRAPS) {
+  instanceKlassHandle nh = instanceKlassHandle(); // null Handle
+  if (JvmtiExport::should_post_class_file_load_hook()) {
+    // Don't load shared class when JvmtiExport::should_post_class_file_load_hook()
+    // is enabled since posting CFLH is not supported when loading shared class.
+    return nh;
+  }
+
   if (ik.not_null()) {
-    instanceKlassHandle nh = instanceKlassHandle(); // null Handle
     Symbol* class_name = ik->name();
 
     bool visible = is_shared_class_visible(
@@ -1400,6 +1374,8 @@
       Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
       check_loader_lock_contention(lockObject, THREAD);
       ObjectLocker ol(lockObject, THREAD, true);
+      // prohibited package check assumes all classes loaded from archive call
+      // restore_unshareable_info which calls ik->set_package()
       ik->restore_unshareable_info(loader_data, protection_domain, CHECK_(nh));
     }
 
@@ -1665,9 +1641,8 @@
       JvmtiExport::post_class_load((JavaThread *) THREAD, k());
 
   }
-
   TRACE_KLASS_DEFINITION(k, THREAD);
-
+  class_define_event(k);
 }
 
 // Support parallel classloading
@@ -1686,6 +1661,10 @@
 // findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they
 // potentially waste time reading and parsing the bytestream.
 // Note: VM callers should ensure consistency of k/class_name,class_loader
+// Be careful when modifying this code: once you have run
+// placeholders()->find_and_add(PlaceholderTable::DEFINE_CLASS),
+// you need to find_and_remove it before returning.
+// So be careful to not exit with a CHECK_ macro betweeen these calls.
 instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader, instanceKlassHandle k, TRAPS) {
 
   instanceKlassHandle nh = instanceKlassHandle(); // null Handle
@@ -2125,7 +2104,7 @@
 
   // Create the ModuleEntry for java.base.  This call needs to be done here,
   // after vmSymbols::initialize() is called but before any classes are pre-loaded.
-  ClassLoader::create_javabase();
+  ClassLoader::classLoader_init2(CHECK);
 
   // Preload commonly used klasses
   WKID scan = FIRST_WKID;
--- a/hotspot/src/share/vm/classfile/systemDictionary.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/classfile/systemDictionary.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -281,6 +281,7 @@
 
   // Parse new stream. This won't update the system dictionary or
   // class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses.
+  // Also used by Unsafe_DefineAnonymousClass
   static Klass* parse_stream(Symbol* class_name,
                              Handle class_loader,
                              Handle protection_domain,
@@ -413,10 +414,6 @@
   // Verification
   static void verify();
 
-#ifdef ASSERT
-  static bool is_internal_format(Symbol* class_name);
-#endif
-
   // Initialization
   static void initialize(TRAPS);
 
--- a/hotspot/src/share/vm/code/nativeInst.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/code/nativeInst.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,23 +25,8 @@
 #ifndef SHARE_VM_CODE_NATIVEINST_HPP
 #define SHARE_VM_CODE_NATIVEINST_HPP
 
-#ifdef TARGET_ARCH_x86
-# include "nativeInst_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "nativeInst_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "nativeInst_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "nativeInst_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "nativeInst_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "nativeInst_aarch64.hpp"
-#endif
+#include "utilities/macros.hpp"
+
+#include CPU_HEADER(nativeInst)
 
 #endif // SHARE_VM_CODE_NATIVEINST_HPP
--- a/hotspot/src/share/vm/code/nmethod.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/code/nmethod.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -51,21 +51,6 @@
 #include "utilities/events.hpp"
 #include "utilities/xmlstream.hpp"
 #include "logging/log.hpp"
-#ifdef TARGET_ARCH_x86
-# include "nativeInst_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "nativeInst_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "nativeInst_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "nativeInst_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "nativeInst_ppc.hpp"
-#endif
 #ifdef SHARK
 #include "shark/sharkCompiler.hpp"
 #endif
--- a/hotspot/src/share/vm/code/relocInfo.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/code/relocInfo.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -27,6 +27,7 @@
 
 #include "memory/allocation.hpp"
 #include "runtime/os.hpp"
+#include "utilities/macros.hpp"
 
 class nmethod;
 class CompiledMethod;
@@ -423,24 +424,7 @@
   static void remove_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type);
 
   // Machine dependent stuff
-#ifdef TARGET_ARCH_x86
-# include "relocInfo_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "relocInfo_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "relocInfo_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "relocInfo_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "relocInfo_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "relocInfo_aarch64.hpp"
-#endif
+#include CPU_HEADER(relocInfo)
 
  protected:
   // Derived constant, based on format_width which is PD:
--- a/hotspot/src/share/vm/code/vmreg.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/code/vmreg.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
 #include "asm/register.hpp"
 #include "memory/allocation.hpp"
 #include "utilities/globalDefinitions.hpp"
+#include "utilities/macros.hpp"
 #include "utilities/ostream.hpp"
 #ifdef COMPILER2
 #include "opto/adlcVMDeps.hpp"
@@ -139,25 +140,7 @@
 
   static void set_regName();
 
-#ifdef TARGET_ARCH_x86
-# include "vmreg_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "vmreg_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "vmreg_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "vmreg_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "vmreg_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "vmreg_aarch64.hpp"
-#endif
-
+#include CPU_HEADER(vmreg)
 
 };
 
--- a/hotspot/src/share/vm/code/vmreg.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/code/vmreg.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,23 +27,6 @@
 
 #include "asm/register.hpp"
 #include "code/vmreg.hpp"
-#ifdef TARGET_ARCH_x86
-# include "vmreg_x86.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "vmreg_sparc.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "vmreg_zero.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "vmreg_arm.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "vmreg_ppc.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "vmreg_aarch64.inline.hpp"
-#endif
+#include CPU_HEADER_INLINE(vmreg)
 
 #endif // SHARE_VM_CODE_VMREG_INLINE_HPP
--- a/hotspot/src/share/vm/compiler/disassembler.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/compiler/disassembler.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -35,24 +35,7 @@
 #include "runtime/os.hpp"
 #include "runtime/stubCodeGenerator.hpp"
 #include "runtime/stubRoutines.hpp"
-#ifdef TARGET_ARCH_x86
-# include "depChecker_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "depChecker_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "depChecker_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "depChecker_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "depChecker_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "depChecker_aarch64.hpp"
-#endif
+#include CPU_HEADER(depChecker)
 #ifdef SHARK
 #include "shark/sharkEntry.hpp"
 #endif
--- a/hotspot/src/share/vm/compiler/disassembler.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/compiler/disassembler.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 
 #include "asm/codeBuffer.hpp"
 #include "runtime/globals.hpp"
+#include "utilities/macros.hpp"
 
 class decode_env;
 
@@ -63,25 +64,7 @@
   static bool load_library();
 
   // Machine dependent stuff
-#ifdef TARGET_ARCH_x86
-# include "disassembler_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "disassembler_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "disassembler_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "disassembler_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "disassembler_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "disassembler_aarch64.hpp"
-#endif
-
+#include CPU_HEADER(disassembler)
 
  public:
   static bool can_decode() {
--- a/hotspot/src/share/vm/gc/g1/dirtyCardQueue.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/dirtyCardQueue.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -122,7 +122,7 @@
 
 // Determines how many mutator threads can process the buffers in parallel.
 uint DirtyCardQueueSet::num_par_ids() {
-  return (uint)os::processor_count();
+  return (uint)os::initial_active_processor_count();
 }
 
 void DirtyCardQueueSet::initialize(CardTableEntryClosure* cl,
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -4524,7 +4524,8 @@
 
 void G1CollectedHeap::free_region(HeapRegion* hr,
                                   FreeRegionList* free_list,
-                                  bool par,
+                                  bool skip_remset,
+                                  bool skip_hot_card_cache,
                                   bool locked) {
   assert(!hr->is_free(), "the region should not be free");
   assert(!hr->is_empty(), "the region should not be empty");
@@ -4539,20 +4540,20 @@
   // Clear the card counts for this region.
   // Note: we only need to do this if the region is not young
   // (since we don't refine cards in young regions).
-  if (!hr->is_young()) {
+  if (!skip_hot_card_cache && !hr->is_young()) {
     _hot_card_cache->reset_card_counts(hr);
   }
-  hr->hr_clear(par, true /* clear_space */, locked /* locked */);
+  hr->hr_clear(skip_remset, true /* clear_space */, locked /* locked */);
   free_list->add_ordered(hr);
 }
 
 void G1CollectedHeap::free_humongous_region(HeapRegion* hr,
                                             FreeRegionList* free_list,
-                                            bool par) {
+                                            bool skip_remset) {
   assert(hr->is_humongous(), "this is only for humongous regions");
   assert(free_list != NULL, "pre-condition");
   hr->clear_humongous();
-  free_region(hr, free_list, par);
+  free_region(hr, free_list, skip_remset);
 }
 
 void G1CollectedHeap::remove_from_old_sets(const uint old_regions_removed,
@@ -4600,137 +4601,280 @@
   workers()->run_task(&g1_par_scrub_rs_task);
 }
 
-class G1FreeCollectionSetClosure : public HeapRegionClosure {
+class G1FreeCollectionSetTask : public AbstractGangTask {
 private:
+
+  // Closure applied to all regions in the collection set to do work that needs to
+  // be done serially in a single thread.
+  class G1SerialFreeCollectionSetClosure : public HeapRegionClosure {
+  private:
+    EvacuationInfo* _evacuation_info;
+    const size_t* _surviving_young_words;
+
+    // Bytes used in successfully evacuated regions before the evacuation.
+    size_t _before_used_bytes;
+    // Bytes used in unsucessfully evacuated regions before the evacuation
+    size_t _after_used_bytes;
+
+    size_t _bytes_allocated_in_old_since_last_gc;
+
+    size_t _failure_used_words;
+    size_t _failure_waste_words;
+
+    FreeRegionList _local_free_list;
+  public:
+    G1SerialFreeCollectionSetClosure(EvacuationInfo* evacuation_info, const size_t* surviving_young_words) :
+      HeapRegionClosure(),
+      _evacuation_info(evacuation_info),
+      _surviving_young_words(surviving_young_words),
+      _before_used_bytes(0),
+      _after_used_bytes(0),
+      _bytes_allocated_in_old_since_last_gc(0),
+      _failure_used_words(0),
+      _failure_waste_words(0),
+      _local_free_list("Local Region List for CSet Freeing") {
+    }
+
+    virtual bool doHeapRegion(HeapRegion* r) {
+      G1CollectedHeap* g1h = G1CollectedHeap::heap();
+
+      assert(r->in_collection_set(), "Region %u should be in collection set.", r->hrm_index());
+      g1h->clear_in_cset(r);
+
+      if (r->is_young()) {
+        assert(r->young_index_in_cset() != -1 && (uint)r->young_index_in_cset() < g1h->collection_set()->young_region_length(),
+               "Young index %d is wrong for region %u of type %s with %u young regions",
+               r->young_index_in_cset(),
+               r->hrm_index(),
+               r->get_type_str(),
+               g1h->collection_set()->young_region_length());
+        size_t words_survived = _surviving_young_words[r->young_index_in_cset()];
+        r->record_surv_words_in_group(words_survived);
+      }
+
+      if (!r->evacuation_failed()) {
+        assert(r->not_empty(), "Region %u is an empty region in the collection set.", r->hrm_index());
+        _before_used_bytes += r->used();
+        g1h->free_region(r,
+                         &_local_free_list,
+                         true, /* skip_remset */
+                         true, /* skip_hot_card_cache */
+                         true  /* locked */);
+      } else {
+        r->uninstall_surv_rate_group();
+        r->set_young_index_in_cset(-1);
+        r->set_evacuation_failed(false);
+        // When moving a young gen region to old gen, we "allocate" that whole region
+        // there. This is in addition to any already evacuated objects. Notify the
+        // policy about that.
+        // Old gen regions do not cause an additional allocation: both the objects
+        // still in the region and the ones already moved are accounted for elsewhere.
+        if (r->is_young()) {
+          _bytes_allocated_in_old_since_last_gc += HeapRegion::GrainBytes;
+        }
+        // The region is now considered to be old.
+        r->set_old();
+        // Do some allocation statistics accounting. Regions that failed evacuation
+        // are always made old, so there is no need to update anything in the young
+        // gen statistics, but we need to update old gen statistics.
+        size_t used_words = r->marked_bytes() / HeapWordSize;
+
+        _failure_used_words += used_words;
+        _failure_waste_words += HeapRegion::GrainWords - used_words;
+
+        g1h->old_set_add(r);
+        _after_used_bytes += r->used();
+      }
+      return false;
+    }
+
+    void complete_work() {
+      G1CollectedHeap* g1h = G1CollectedHeap::heap();
+
+      _evacuation_info->set_regions_freed(_local_free_list.length());
+      _evacuation_info->increment_collectionset_used_after(_after_used_bytes);
+
+      g1h->prepend_to_freelist(&_local_free_list);
+      g1h->decrement_summary_bytes(_before_used_bytes);
+
+      G1Policy* policy = g1h->g1_policy();
+      policy->add_bytes_allocated_in_old_since_last_gc(_bytes_allocated_in_old_since_last_gc);
+
+      g1h->alloc_buffer_stats(InCSetState::Old)->add_failure_used_and_waste(_failure_used_words, _failure_waste_words);
+    }
+  };
+
+  G1CollectionSet* _collection_set;
+  G1SerialFreeCollectionSetClosure _cl;
   const size_t* _surviving_young_words;
 
-  FreeRegionList _local_free_list;
   size_t _rs_lengths;
-  // Bytes used in successfully evacuated regions before the evacuation.
-  size_t _before_used_bytes;
-  // Bytes used in unsucessfully evacuated regions before the evacuation
-  size_t _after_used_bytes;
-
-  size_t _bytes_allocated_in_old_since_last_gc;
-
-  size_t _failure_used_words;
-  size_t _failure_waste_words;
-
-  double _young_time;
-  double _non_young_time;
-public:
-  G1FreeCollectionSetClosure(const size_t* surviving_young_words) :
-    HeapRegionClosure(),
-    _surviving_young_words(surviving_young_words),
-    _local_free_list("Local Region List for CSet Freeing"),
-    _rs_lengths(0),
-    _before_used_bytes(0),
-    _after_used_bytes(0),
-    _bytes_allocated_in_old_since_last_gc(0),
-    _failure_used_words(0),
-    _failure_waste_words(0),
-    _young_time(0.0),
-    _non_young_time(0.0) {
+
+  volatile jint _serial_work_claim;
+
+  struct WorkItem {
+    uint region_idx;
+    bool is_young;
+    bool evacuation_failed;
+
+    WorkItem(HeapRegion* r) {
+      region_idx = r->hrm_index();
+      is_young = r->is_young();
+      evacuation_failed = r->evacuation_failed();
+    }
+  };
+
+  volatile size_t _parallel_work_claim;
+  size_t _num_work_items;
+  WorkItem* _work_items;
+
+  void do_serial_work() {
+    // Need to grab the lock to be allowed to modify the old region list.
+    MutexLockerEx x(OldSets_lock, Mutex::_no_safepoint_check_flag);
+    _collection_set->iterate(&_cl);
   }
 
-  virtual bool doHeapRegion(HeapRegion* r) {
-    double start_time = os::elapsedTime();
-
-    bool is_young = r->is_young();
-
+  void do_parallel_work_for_region(uint region_idx, bool is_young, bool evacuation_failed) {
     G1CollectedHeap* g1h = G1CollectedHeap::heap();
+
+    HeapRegion* r = g1h->region_at(region_idx);
     assert(!g1h->is_on_master_free_list(r), "sanity");
 
-    _rs_lengths += r->rem_set()->occupied_locked();
-
-    assert(r->in_collection_set(), "Region %u should be in collection set.", r->hrm_index());
-    g1h->clear_in_cset(r);
-
-    if (is_young) {
-      int index = r->young_index_in_cset();
-      assert(index != -1, "Young index in collection set must not be -1 for region %u", r->hrm_index());
-      assert((uint) index < g1h->collection_set()->young_region_length(), "invariant");
-      size_t words_survived = _surviving_young_words[index];
-      r->record_surv_words_in_group(words_survived);
-    } else {
-      assert(r->young_index_in_cset() == -1, "Young index for old region %u in collection set must be -1", r->hrm_index());
+    Atomic::add(r->rem_set()->occupied_locked(), &_rs_lengths);
+
+    if (!is_young) {
+      g1h->_hot_card_cache->reset_card_counts(r);
+    }
+
+    if (!evacuation_failed) {
+      r->rem_set()->clear_locked();
+    }
+  }
+
+  class G1PrepareFreeCollectionSetClosure : public HeapRegionClosure {
+  private:
+    size_t _cur_idx;
+    WorkItem* _work_items;
+  public:
+    G1PrepareFreeCollectionSetClosure(WorkItem* work_items) : HeapRegionClosure(), _cur_idx(0), _work_items(work_items) { }
+
+    virtual bool doHeapRegion(HeapRegion* r) {
+      _work_items[_cur_idx++] = WorkItem(r);
+      return false;
     }
-
-    if (!r->evacuation_failed()) {
-      assert(r->not_empty(), "Region %u is an empty region in the collection set.", r->hrm_index());
-      _before_used_bytes += r->used();
-      g1h->free_region(r, &_local_free_list, false /* par */, true /* locked */);
-    } else {
-      r->uninstall_surv_rate_group();
-      r->set_young_index_in_cset(-1);
-      r->set_evacuation_failed(false);
-      // When moving a young gen region to old gen, we "allocate" that whole region
-      // there. This is in addition to any already evacuated objects. Notify the
-      // policy about that.
-      // Old gen regions do not cause an additional allocation: both the objects
-      // still in the region and the ones already moved are accounted for elsewhere.
-      if (is_young) {
-        _bytes_allocated_in_old_since_last_gc += HeapRegion::GrainBytes;
+  };
+
+  void prepare_work() {
+    G1PrepareFreeCollectionSetClosure cl(_work_items);
+    _collection_set->iterate(&cl);
+  }
+
+  void complete_work() {
+    _cl.complete_work();
+
+    G1Policy* policy = G1CollectedHeap::heap()->g1_policy();
+    policy->record_max_rs_lengths(_rs_lengths);
+    policy->cset_regions_freed();
+  }
+public:
+  G1FreeCollectionSetTask(G1CollectionSet* collection_set, EvacuationInfo* evacuation_info, const size_t* surviving_young_words) :
+    AbstractGangTask("G1 Free Collection Set"),
+    _cl(evacuation_info, surviving_young_words),
+    _collection_set(collection_set),
+    _surviving_young_words(surviving_young_words),
+    _serial_work_claim(0),
+    _rs_lengths(0),
+    _parallel_work_claim(0),
+    _num_work_items(collection_set->region_length()),
+    _work_items(NEW_C_HEAP_ARRAY(WorkItem, _num_work_items, mtGC)) {
+    prepare_work();
+  }
+
+  ~G1FreeCollectionSetTask() {
+    complete_work();
+    FREE_C_HEAP_ARRAY(WorkItem, _work_items);
+  }
+
+  // Chunk size for work distribution. The chosen value has been determined experimentally
+  // to be a good tradeoff between overhead and achievable parallelism.
+  static uint chunk_size() { return 32; }
+
+  virtual void work(uint worker_id) {
+    G1GCPhaseTimes* timer = G1CollectedHeap::heap()->g1_policy()->phase_times();
+
+    // Claim serial work.
+    if (_serial_work_claim == 0) {
+      jint value = Atomic::add(1, &_serial_work_claim) - 1;
+      if (value == 0) {
+        double serial_time = os::elapsedTime();
+        do_serial_work();
+        timer->record_serial_free_cset_time_ms((os::elapsedTime() - serial_time) * 1000.0);
       }
-      // The region is now considered to be old.
-      r->set_old();
-      // Do some allocation statistics accounting. Regions that failed evacuation
-      // are always made old, so there is no need to update anything in the young
-      // gen statistics, but we need to update old gen statistics.
-      size_t used_words = r->marked_bytes() / HeapWordSize;
-
-      _failure_used_words += used_words;
-      _failure_waste_words += HeapRegion::GrainWords - used_words;
-
-      g1h->old_set_add(r);
-      _after_used_bytes += r->used();
     }
 
-    if (is_young) {
-      _young_time += os::elapsedTime() - start_time;
-    } else {
-      _non_young_time += os::elapsedTime() - start_time;
+    // Start parallel work.
+    double young_time = 0.0;
+    bool has_young_time = false;
+    double non_young_time = 0.0;
+    bool has_non_young_time = false;
+
+    while (true) {
+      size_t end = Atomic::add(chunk_size(), &_parallel_work_claim);
+      size_t cur = end - chunk_size();
+
+      if (cur >= _num_work_items) {
+        break;
+      }
+
+      double start_time = os::elapsedTime();
+
+      end = MIN2(end, _num_work_items);
+
+      for (; cur < end; cur++) {
+        bool is_young = _work_items[cur].is_young;
+
+        do_parallel_work_for_region(_work_items[cur].region_idx, is_young, _work_items[cur].evacuation_failed);
+
+        double end_time = os::elapsedTime();
+        double time_taken = end_time - start_time;
+        if (is_young) {
+          young_time += time_taken;
+          has_young_time = true;
+        } else {
+          non_young_time += time_taken;
+          has_non_young_time = true;
+        }
+        start_time = end_time;
+      }
     }
-    return false;
+
+    if (has_young_time) {
+      timer->record_time_secs(G1GCPhaseTimes::YoungFreeCSet, worker_id, young_time);
+    }
+    if (has_non_young_time) {
+      timer->record_time_secs(G1GCPhaseTimes::NonYoungFreeCSet, worker_id, young_time);
+    }
   }
-
-  FreeRegionList* local_free_list() { return &_local_free_list; }
-  size_t rs_lengths() const { return _rs_lengths; }
-  size_t before_used_bytes() const { return _before_used_bytes; }
-  size_t after_used_bytes() const { return _after_used_bytes; }
-
-  size_t bytes_allocated_in_old_since_last_gc() const { return _bytes_allocated_in_old_since_last_gc; }
-
-  size_t failure_used_words() const { return _failure_used_words; }
-  size_t failure_waste_words() const { return _failure_waste_words; }
-
-  double young_time() const { return _young_time; }
-  double non_young_time() const { return _non_young_time; }
 };
 
 void G1CollectedHeap::free_collection_set(G1CollectionSet* collection_set, EvacuationInfo& evacuation_info, const size_t* surviving_young_words) {
   _eden.clear();
 
-  G1FreeCollectionSetClosure cl(surviving_young_words);
-  collection_set_iterate(&cl);
-
-  evacuation_info.set_regions_freed(cl.local_free_list()->length());
-  evacuation_info.increment_collectionset_used_after(cl.after_used_bytes());
-
-  G1Policy* policy = g1_policy();
-
-  policy->record_max_rs_lengths(cl.rs_lengths());
-  policy->cset_regions_freed();
-
-  prepend_to_freelist(cl.local_free_list());
-  decrement_summary_bytes(cl.before_used_bytes());
-
-  policy->add_bytes_allocated_in_old_since_last_gc(cl.bytes_allocated_in_old_since_last_gc());
-
-  _old_evac_stats.add_failure_used_and_waste(cl.failure_used_words(), cl.failure_waste_words());
-
-  policy->phase_times()->record_young_free_cset_time_ms(cl.young_time() * 1000.0);
-  policy->phase_times()->record_non_young_free_cset_time_ms(cl.non_young_time() * 1000.0);
+  double free_cset_start_time = os::elapsedTime();
+
+  {
+    uint const num_chunks = MAX2(_collection_set.region_length() / G1FreeCollectionSetTask::chunk_size(), 1U);
+    uint const num_workers = MIN2(workers()->active_workers(), num_chunks);
+
+    G1FreeCollectionSetTask cl(collection_set, &evacuation_info, surviving_young_words);
+
+    log_debug(gc, ergo)("Running %s using %u workers for collection set length %u",
+                        cl.name(),
+                        num_workers,
+                        _collection_set.region_length());
+    workers()->run_task(&cl, num_workers);
+  }
+  g1_policy()->phase_times()->record_total_free_cset_time_ms((os::elapsedTime() - free_cset_start_time) * 1000.0);
 
   collection_set->clear();
 }
@@ -4825,7 +4969,7 @@
       _freed_bytes += r->used();
       r->set_containing_set(NULL);
       _humongous_regions_removed++;
-      g1h->free_humongous_region(r, _free_region_list, false);
+      g1h->free_humongous_region(r, _free_region_list, false /* skip_remset */ );
       r = next;
     } while (r != NULL);
 
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -118,6 +118,7 @@
 };
 
 class G1CollectedHeap : public CollectedHeap {
+  friend class G1FreeCollectionSetTask;
   friend class VM_CollectForMetadataAllocation;
   friend class VM_G1CollectForAllocation;
   friend class VM_G1CollectFull;
@@ -642,13 +643,15 @@
   // adding it to the free list that's passed as a parameter (this is
   // usually a local list which will be appended to the master free
   // list later). The used bytes of freed regions are accumulated in
-  // pre_used. If par is true, the region's RSet will not be freed
-  // up. The assumption is that this will be done later.
+  // pre_used. If skip_remset is true, the region's RSet will not be freed
+  // up. If skip_hot_card_cache is true, the region's hot card cache will not
+  // be freed up. The assumption is that this will be done later.
   // The locked parameter indicates if the caller has already taken
   // care of proper synchronization. This may allow some optimizations.
   void free_region(HeapRegion* hr,
                    FreeRegionList* free_list,
-                   bool par,
+                   bool skip_remset,
+                   bool skip_hot_card_cache = false,
                    bool locked = false);
 
   // It dirties the cards that cover the block so that the post
@@ -662,11 +665,11 @@
   // will be added to the free list that's passed as a parameter (this
   // is usually a local list which will be appended to the master free
   // list later). The used bytes of freed regions are accumulated in
-  // pre_used. If par is true, the region's RSet will not be freed
+  // pre_used. If skip_remset is true, the region's RSet will not be freed
   // up. The assumption is that this will be done later.
   void free_humongous_region(HeapRegion* hr,
                              FreeRegionList* free_list,
-                             bool par);
+                             bool skip_remset);
 
   // Facility for allocating in 'archive' regions in high heap memory and
   // recording the allocated ranges. These should all be called from the
--- a/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -132,109 +132,114 @@
                    heapWordToOffset(mr.end()), false);
 }
 
-G1CMMarkStack::G1CMMarkStack(G1ConcurrentMark* cm) :
-  _base(NULL), _cm(cm)
-{}
-
-bool G1CMMarkStack::allocate(size_t capacity) {
-  // allocate a stack of the requisite depth
-  ReservedSpace rs(ReservedSpace::allocation_align_size_up(capacity * sizeof(oop)));
+G1CMMarkStack::G1CMMarkStack() :
+  _reserved_space(),
+  _base(NULL),
+  _capacity(0),
+  _saved_index((size_t)AllBits),
+  _should_expand(false) {
+  set_empty();
+}
+
+bool G1CMMarkStack::resize(size_t new_capacity) {
+  assert(is_empty(), "Only resize when stack is empty.");
+  assert(new_capacity <= MarkStackSizeMax,
+         "Trying to resize stack to " SIZE_FORMAT " elements when the maximum is " SIZE_FORMAT, new_capacity, MarkStackSizeMax);
+
+  size_t reservation_size = ReservedSpace::allocation_align_size_up(new_capacity * sizeof(oop));
+
+  ReservedSpace rs(reservation_size);
   if (!rs.is_reserved()) {
-    log_warning(gc)("ConcurrentMark MarkStack allocation failure");
+    log_warning(gc)("Failed to reserve memory for new overflow mark stack with " SIZE_FORMAT " elements and size " SIZE_FORMAT "B.", new_capacity, reservation_size);
     return false;
   }
-  MemTracker::record_virtual_memory_type((address)rs.base(), mtGC);
-  if (!_virtual_space.initialize(rs, rs.size())) {
-    log_warning(gc)("ConcurrentMark MarkStack backing store failure");
-    // Release the virtual memory reserved for the marking stack
+
+  VirtualSpace vs;
+
+  if (!vs.initialize(rs, rs.size())) {
     rs.release();
+    log_warning(gc)("Failed to commit memory for new overflow mark stack of size " SIZE_FORMAT "B.", rs.size());
     return false;
   }
-  assert(_virtual_space.committed_size() == rs.size(),
-         "Didn't reserve backing store for all of G1ConcurrentMark stack?");
-  _base = (oop*) _virtual_space.low();
-  setEmpty();
-  _capacity = (jint) capacity;
-  _saved_index = -1;
+
+  assert(vs.committed_size() == rs.size(), "Failed to commit all of the mark stack.");
+
+  // Release old mapping.
+  _reserved_space.release();
+
+  // Save new mapping for future unmapping.
+  _reserved_space = rs;
+
+  MemTracker::record_virtual_memory_type((address)_reserved_space.base(), mtGC);
+
+  _base = (oop*) vs.low();
+  _capacity = new_capacity;
+  set_empty();
   _should_expand = false;
+
   return true;
 }
 
+bool G1CMMarkStack::allocate(size_t capacity) {
+  return resize(capacity);
+}
+
 void G1CMMarkStack::expand() {
-  // Called, during remark, if we've overflown the marking stack during marking.
-  assert(isEmpty(), "stack should been emptied while handling overflow");
-  assert(_capacity <= (jint) MarkStackSizeMax, "stack bigger than permitted");
   // Clear expansion flag
   _should_expand = false;
-  if (_capacity == (jint) MarkStackSizeMax) {
-    log_trace(gc)("(benign) Can't expand marking stack capacity, at max size limit");
+
+  if (_capacity == MarkStackSizeMax) {
+    log_debug(gc)("Can not expand overflow mark stack further, already at maximum capacity of " SIZE_FORMAT " elements.", _capacity);
     return;
   }
+  size_t old_capacity = _capacity;
   // Double capacity if possible
-  jint new_capacity = MIN2(_capacity*2, (jint) MarkStackSizeMax);
-  // Do not give up existing stack until we have managed to
-  // get the double capacity that we desired.
-  ReservedSpace rs(ReservedSpace::allocation_align_size_up(new_capacity *
-                                                           sizeof(oop)));
-  if (rs.is_reserved()) {
-    // Release the backing store associated with old stack
-    _virtual_space.release();
-    // Reinitialize virtual space for new stack
-    if (!_virtual_space.initialize(rs, rs.size())) {
-      fatal("Not enough swap for expanded marking stack capacity");
-    }
-    _base = (oop*)(_virtual_space.low());
-    _index = 0;
-    _capacity = new_capacity;
+  size_t new_capacity = MIN2(old_capacity * 2, MarkStackSizeMax);
+
+  if (resize(new_capacity)) {
+    log_debug(gc)("Expanded marking stack capacity from " SIZE_FORMAT " to " SIZE_FORMAT " elements",
+                  old_capacity, new_capacity);
   } else {
-    // Failed to double capacity, continue;
-    log_trace(gc)("(benign) Failed to expand marking stack capacity from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
-                  _capacity / K, new_capacity / K);
+    log_warning(gc)("Failed to expand marking stack capacity from " SIZE_FORMAT " to " SIZE_FORMAT " elements",
+                    old_capacity, new_capacity);
   }
 }
 
-void G1CMMarkStack::set_should_expand() {
-  // If we're resetting the marking state because of an
-  // marking stack overflow, record that we should, if
-  // possible, expand the stack.
-  _should_expand = _cm->has_overflown();
-}
-
 G1CMMarkStack::~G1CMMarkStack() {
   if (_base != NULL) {
     _base = NULL;
-    _virtual_space.release();
+    _reserved_space.release();
   }
 }
 
-void G1CMMarkStack::par_push_arr(oop* ptr_arr, int n) {
+void G1CMMarkStack::par_push_arr(oop* buffer, size_t n) {
   MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag);
-  jint start = _index;
-  jint next_index = start + n;
+  size_t start = _index;
+  size_t next_index = start + n;
   if (next_index > _capacity) {
     _overflow = true;
     return;
   }
   // Otherwise.
   _index = next_index;
-  for (int i = 0; i < n; i++) {
-    int ind = start + i;
+  for (size_t i = 0; i < n; i++) {
+    size_t ind = start + i;
     assert(ind < _capacity, "By overflow test above.");
-    _base[ind] = ptr_arr[i];
+    _base[ind] = buffer[i];
   }
 }
 
-bool G1CMMarkStack::par_pop_arr(oop* ptr_arr, int max, int* n) {
+bool G1CMMarkStack::par_pop_arr(oop* buffer, size_t max, size_t* n) {
   MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag);
-  jint index = _index;
+  size_t index = _index;
   if (index == 0) {
     *n = 0;
     return false;
   } else {
-    int k = MIN2(max, index);
-    jint  new_ind = index - k;
-    for (int j = 0; j < k; j++) {
-      ptr_arr[j] = _base[new_ind + j];
+    size_t k = MIN2(max, index);
+    size_t new_ind = index - k;
+    for (size_t j = 0; j < k; j++) {
+      buffer[j] = _base[new_ind + j];
     }
     _index = new_ind;
     *n = k;
@@ -243,20 +248,14 @@
 }
 
 void G1CMMarkStack::note_start_of_gc() {
-  assert(_saved_index == -1,
-         "note_start_of_gc()/end_of_gc() bracketed incorrectly");
+  assert(_saved_index == (size_t)AllBits, "note_start_of_gc()/end_of_gc() calls bracketed incorrectly");
   _saved_index = _index;
 }
 
 void G1CMMarkStack::note_end_of_gc() {
-  // This is intentionally a guarantee, instead of an assert. If we
-  // accidentally add something to the mark stack during GC, it
-  // will be a correctness issue so it's better if we crash. we'll
-  // only check this once per GC anyway, so it won't be a performance
-  // issue in any way.
-  guarantee(_saved_index == _index,
-            "saved index: %d index: %d", _saved_index, _index);
-  _saved_index = -1;
+  guarantee(!stack_modified(), "Saved index " SIZE_FORMAT " must be the same as " SIZE_FORMAT, _saved_index, _index);
+
+  _saved_index = (size_t)AllBits;
 }
 
 G1CMRootRegions::G1CMRootRegions() :
@@ -351,7 +350,7 @@
   _prevMarkBitMap(&_markBitMap1),
   _nextMarkBitMap(&_markBitMap2),
 
-  _markStack(this),
+  _global_mark_stack(),
   // _finger set in set_non_marking_state
 
   _max_worker_id(ParallelGCThreads),
@@ -417,11 +416,10 @@
     double overall_cm_overhead =
       (double) MaxGCPauseMillis * marking_overhead /
       (double) GCPauseIntervalMillis;
-    double cpu_ratio = 1.0 / (double) os::processor_count();
+    double cpu_ratio = 1.0 / os::initial_active_processor_count();
     double marking_thread_num = ceil(overall_cm_overhead / cpu_ratio);
     double marking_task_overhead =
-      overall_cm_overhead / marking_thread_num *
-                                              (double) os::processor_count();
+      overall_cm_overhead / marking_thread_num * os::initial_active_processor_count();
     double sleep_factor =
                        (1.0 - marking_task_overhead) / marking_task_overhead;
 
@@ -485,8 +483,8 @@
     }
   }
 
-  if (!_markStack.allocate(MarkStackSize)) {
-    log_warning(gc)("Failed to allocate CM marking stack");
+  if (!_global_mark_stack.allocate(MarkStackSize)) {
+    vm_exit_during_initialization("Failed to allocate initial concurrent mark overflow mark stack.");
     return;
   }
 
@@ -541,8 +539,8 @@
 
 
 void G1ConcurrentMark::reset_marking_state(bool clear_overflow) {
-  _markStack.set_should_expand();
-  _markStack.setEmpty();        // Also clears the _markStack overflow flag
+  _global_mark_stack.set_should_expand(has_overflown());
+  _global_mark_stack.set_empty();        // Also clears the overflow stack's overflow flag
   if (clear_overflow) {
     clear_has_overflown();
   } else {
@@ -1076,7 +1074,7 @@
   weakRefsWork(clear_all_soft_refs);
 
   if (has_overflown()) {
-    // Oops.  We overflowed.  Restart concurrent marking.
+    // We overflowed.  Restart concurrent marking.
     _restart_for_overflow = true;
 
     // Verify the heap w.r.t. the previous marking bitmap.
@@ -1109,8 +1107,8 @@
   }
 
   // Expand the marking stack, if we have to and if we can.
-  if (_markStack.should_expand()) {
-    _markStack.expand();
+  if (_global_mark_stack.should_expand()) {
+    _global_mark_stack.expand();
   }
 
   // Statistics
@@ -1160,10 +1158,10 @@
       hr->set_containing_set(NULL);
       if (hr->is_humongous()) {
         _humongous_regions_removed++;
-        _g1->free_humongous_region(hr, _local_cleanup_list, true);
+        _g1->free_humongous_region(hr, _local_cleanup_list, true /* skip_remset */);
       } else {
         _old_regions_removed++;
-        _g1->free_region(hr, _local_cleanup_list, true);
+        _g1->free_region(hr, _local_cleanup_list, true /* skip_remset */);
       }
     } else {
       hr->rem_set()->do_cleanup_work(_hrrs_cleanup_task);
@@ -1637,7 +1635,7 @@
 
     // Set the soft reference policy
     rp->setup_policy(clear_all_soft_refs);
-    assert(_markStack.isEmpty(), "mark stack should be empty");
+    assert(_global_mark_stack.is_empty(), "mark stack should be empty");
 
     // Instances of the 'Keep Alive' and 'Complete GC' closures used
     // in serial reference processing. Note these closures are also
@@ -1692,10 +1690,10 @@
     // oop closures will set the has_overflown flag if we overflow the
     // global marking stack.
 
-    assert(_markStack.overflow() || _markStack.isEmpty(),
+    assert(_global_mark_stack.overflow() || _global_mark_stack.is_empty(),
             "mark stack should be empty (unless it overflowed)");
 
-    if (_markStack.overflow()) {
+    if (_global_mark_stack.overflow()) {
       // This should have been done already when we tried to push an
       // entry on to the global mark stack. But let's do it again.
       set_has_overflown();
@@ -1714,7 +1712,7 @@
     return;
   }
 
-  assert(_markStack.isEmpty(), "Marking should have completed");
+  assert(_global_mark_stack.is_empty(), "Marking should have completed");
 
   // Unload Klasses, String, Symbols, Code Cache, etc.
   if (ClassUnloadingWithConcurrentMark) {
@@ -1967,7 +1965,7 @@
   }
 
   // Verify entries on the global mark stack
-  _markStack.iterate(VerifyNoCSetOops("Stack"));
+  _global_mark_stack.iterate(VerifyNoCSetOops("Stack"));
 
   // Verify entries on the task queues
   for (uint i = 0; i < _max_worker_id; ++i) {
@@ -2366,13 +2364,13 @@
   // local array where we'll store the entries that will be popped
   // from the global stack.
   oop buffer[global_stack_transfer_size];
-  int n;
+  size_t n;
   _cm->mark_stack_pop(buffer, global_stack_transfer_size, &n);
   assert(n <= global_stack_transfer_size,
          "we should not pop more than the given limit");
   if (n > 0) {
     // yes, we did actually pop at least one entry
-    for (int i = 0; i < n; ++i) {
+    for (size_t i = 0; i < n; ++i) {
       bool success = _task_queue->push(buffer[i]);
       // We only call this when the local queue is empty or under a
       // given target limit. So, we do not expect this push to fail.
--- a/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -145,53 +145,56 @@
   void clear_range(MemRegion mr);
 };
 
-// Represents a marking stack used by ConcurrentMarking in the G1 collector.
+// Represents the overflow mark stack used by concurrent marking.
+//
+// Stores oops in a huge buffer in virtual memory that is always fully committed.
+// Resizing may only happen during a STW pause when the stack is empty.
 class G1CMMarkStack VALUE_OBJ_CLASS_SPEC {
-  VirtualSpace _virtual_space;   // Underlying backing store for actual stack
-  G1ConcurrentMark* _cm;
-  oop* _base;        // bottom of stack
-  jint _index;       // one more than last occupied index
-  jint _capacity;    // max #elements
-  jint _saved_index; // value of _index saved at start of GC
+  ReservedSpace _reserved_space; // Space currently reserved for the mark stack.
+
+  oop* _base;                    // Bottom address of allocated memory area.
+  size_t _capacity;              // Maximum number of elements.
+  size_t _index;                 // One more than last occupied index.
+
+  size_t _saved_index;           // Value of _index saved at start of GC to detect mark stack modifications during that time.
 
   bool  _overflow;
   bool  _should_expand;
 
+  // Resizes the mark stack to the given new capacity. Releases any previous
+  // memory if successful.
+  bool resize(size_t new_capacity);
+
+  bool stack_modified() const { return _index != _saved_index; }
  public:
-  G1CMMarkStack(G1ConcurrentMark* cm);
+  G1CMMarkStack();
   ~G1CMMarkStack();
 
   bool allocate(size_t capacity);
 
-  // Pushes the first "n" elements of "ptr_arr" on the stack.
-  // Locking impl: concurrency is allowed only with
-  // "par_push_arr" and/or "par_pop_arr" operations, which use the same
-  // locking strategy.
-  void par_push_arr(oop* ptr_arr, int n);
+  // Pushes the first "n" elements of the given buffer on the stack.
+  void par_push_arr(oop* buffer, size_t n);
 
-  // If returns false, the array was empty.  Otherwise, removes up to "max"
-  // elements from the stack, and transfers them to "ptr_arr" in an
-  // unspecified order.  The actual number transferred is given in "n" ("n
-  // == 0" is deliberately redundant with the return value.)  Locking impl:
-  // concurrency is allowed only with "par_push_arr" and/or "par_pop_arr"
-  // operations, which use the same locking strategy.
-  bool par_pop_arr(oop* ptr_arr, int max, int* n);
+  // Moves up to max elements from the stack into the given buffer. Returns
+  // the number of elements pushed, and false if the array has been empty.
+  // Returns true if the buffer contains at least one element.
+  bool par_pop_arr(oop* buffer, size_t max, size_t* n);
 
-  bool isEmpty()    { return _index == 0; }
-  int  maxElems()   { return _capacity; }
+  bool is_empty() const { return _index == 0; }
+  size_t capacity() const  { return _capacity; }
 
-  bool overflow() { return _overflow; }
+  bool overflow() const { return _overflow; }
   void clear_overflow() { _overflow = false; }
 
   bool should_expand() const { return _should_expand; }
-  void set_should_expand();
+  void set_should_expand(bool value) { _should_expand = value; }
 
   // Expand the stack, typically in response to an overflow condition
   void expand();
 
-  int  size() { return _index; }
+  size_t size() const { return _index; }
 
-  void setEmpty()   { _index = 0; clear_overflow(); }
+  void set_empty() { _index = 0; clear_overflow(); }
 
   // Record the current index.
   void note_start_of_gc();
@@ -308,7 +311,7 @@
   G1CMRootRegions         _root_regions;
 
   // For gray objects
-  G1CMMarkStack           _markStack; // Grey objects behind global finger
+  G1CMMarkStack           _global_mark_stack; // Grey objects behind global finger
   HeapWord* volatile      _finger;  // The global finger, region aligned,
                                     // always points to the end of the
                                     // last claimed region
@@ -478,21 +481,21 @@
   // The push and pop operations are used by tasks for transfers
   // between task-local queues and the global mark stack, and use
   // locking for concurrency safety.
-  bool mark_stack_push(oop* arr, int n) {
-    _markStack.par_push_arr(arr, n);
-    if (_markStack.overflow()) {
+  bool mark_stack_push(oop* arr, size_t n) {
+    _global_mark_stack.par_push_arr(arr, n);
+    if (_global_mark_stack.overflow()) {
       set_has_overflown();
       return false;
     }
     return true;
   }
-  void mark_stack_pop(oop* arr, int max, int* n) {
-    _markStack.par_pop_arr(arr, max, n);
+  void mark_stack_pop(oop* arr, size_t max, size_t* n) {
+    _global_mark_stack.par_pop_arr(arr, max, n);
   }
-  size_t mark_stack_size()                { return _markStack.size(); }
-  size_t partial_mark_stack_size_target() { return _markStack.maxElems()/3; }
-  bool mark_stack_overflow()              { return _markStack.overflow(); }
-  bool mark_stack_empty()                 { return _markStack.isEmpty(); }
+  size_t mark_stack_size()                { return _global_mark_stack.size(); }
+  size_t partial_mark_stack_size_target() { return _global_mark_stack.capacity()/3; }
+  bool mark_stack_overflow()              { return _global_mark_stack.overflow(); }
+  bool mark_stack_empty()                 { return _global_mark_stack.is_empty(); }
 
   G1CMRootRegions* root_regions() { return &_root_regions; }
 
@@ -598,12 +601,12 @@
 
   // Notify data structures that a GC has started.
   void note_start_of_gc() {
-    _markStack.note_start_of_gc();
+    _global_mark_stack.note_start_of_gc();
   }
 
   // Notify data structures that a GC is finished.
   void note_end_of_gc() {
-    _markStack.note_end_of_gc();
+    _global_mark_stack.note_end_of_gc();
   }
 
   // Verify that there are no CSet oops on the stacks (taskqueues /
@@ -660,17 +663,17 @@
 class G1CMTask : public TerminatorTerminator {
 private:
   enum PrivateConstants {
-    // the regular clock call is called once the scanned words reaches
+    // The regular clock call is called once the scanned words reaches
     // this limit
     words_scanned_period          = 12*1024,
-    // the regular clock call is called once the number of visited
+    // The regular clock call is called once the number of visited
     // references reaches this limit
     refs_reached_period           = 384,
-    // initial value for the hash seed, used in the work stealing code
+    // Initial value for the hash seed, used in the work stealing code
     init_hash_seed                = 17,
-    // how many entries will be transferred between global stack and
-    // local queues
-    global_stack_transfer_size    = 16
+    // How many entries will be transferred between global stack and
+    // local queues at once.
+    global_stack_transfer_size    = 1024
   };
 
   uint                        _worker_id;
--- a/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -91,8 +91,9 @@
 
 template<typename Fn>
 inline void G1CMMarkStack::iterate(Fn fn) {
-  assert(_saved_index == _index, "saved index: %d index: %d", _saved_index, _index);
-  for (int i = 0; i < _index; ++i) {
+  assert_at_safepoint(true);
+  assert(!stack_modified(), "Saved index " SIZE_FORMAT " must be the same as " SIZE_FORMAT, _saved_index, _index);
+  for (size_t i = 0; i < _index; ++i) {
     fn(_base[i]);
   }
 }
--- a/hotspot/src/share/vm/gc/g1/g1DefaultPolicy.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1DefaultPolicy.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -97,47 +97,64 @@
   phase_times()->note_gc_start();
 }
 
-bool G1DefaultPolicy::predict_will_fit(uint young_length,
-                                       double base_time_ms,
-                                       uint base_free_regions,
-                                       double target_pause_time_ms) const {
-  if (young_length >= base_free_regions) {
-    // end condition 1: not enough space for the young regions
-    return false;
-  }
+class G1YoungLengthPredictor VALUE_OBJ_CLASS_SPEC {
+  const bool _during_cm;
+  const double _base_time_ms;
+  const double _base_free_regions;
+  const double _target_pause_time_ms;
+  const G1DefaultPolicy* const _policy;
 
-  double accum_surv_rate = accum_yg_surv_rate_pred((int) young_length - 1);
-  size_t bytes_to_copy =
-               (size_t) (accum_surv_rate * (double) HeapRegion::GrainBytes);
-  double copy_time_ms = _analytics->predict_object_copy_time_ms(bytes_to_copy,
-                                                                collector_state()->during_concurrent_mark());
-  double young_other_time_ms = _analytics->predict_young_other_time_ms(young_length);
-  double pause_time_ms = base_time_ms + copy_time_ms + young_other_time_ms;
-  if (pause_time_ms > target_pause_time_ms) {
-    // end condition 2: prediction is over the target pause time
-    return false;
-  }
+ public:
+  G1YoungLengthPredictor(bool during_cm,
+                         double base_time_ms,
+                         double base_free_regions,
+                         double target_pause_time_ms,
+                         const G1DefaultPolicy* policy) :
+    _during_cm(during_cm),
+    _base_time_ms(base_time_ms),
+    _base_free_regions(base_free_regions),
+    _target_pause_time_ms(target_pause_time_ms),
+    _policy(policy) {}
+
+  bool will_fit(uint young_length) const {
+    if (young_length >= _base_free_regions) {
+      // end condition 1: not enough space for the young regions
+      return false;
+    }
 
-  size_t free_bytes = (base_free_regions - young_length) * HeapRegion::GrainBytes;
+    const double accum_surv_rate = _policy->accum_yg_surv_rate_pred((int) young_length - 1);
+    const size_t bytes_to_copy =
+                 (size_t) (accum_surv_rate * (double) HeapRegion::GrainBytes);
+    const double copy_time_ms =
+      _policy->analytics()->predict_object_copy_time_ms(bytes_to_copy, _during_cm);
+    const double young_other_time_ms = _policy->analytics()->predict_young_other_time_ms(young_length);
+    const double pause_time_ms = _base_time_ms + copy_time_ms + young_other_time_ms;
+    if (pause_time_ms > _target_pause_time_ms) {
+      // end condition 2: prediction is over the target pause time
+      return false;
+    }
+
+    const size_t free_bytes = (_base_free_regions - young_length) * HeapRegion::GrainBytes;
 
-  // When copying, we will likely need more bytes free than is live in the region.
-  // Add some safety margin to factor in the confidence of our guess, and the
-  // natural expected waste.
-  // (100.0 / G1ConfidencePercent) is a scale factor that expresses the uncertainty
-  // of the calculation: the lower the confidence, the more headroom.
-  // (100 + TargetPLABWastePct) represents the increase in expected bytes during
-  // copying due to anticipated waste in the PLABs.
-  double safety_factor = (100.0 / G1ConfidencePercent) * (100 + TargetPLABWastePct) / 100.0;
-  size_t expected_bytes_to_copy = (size_t)(safety_factor * bytes_to_copy);
+    // When copying, we will likely need more bytes free than is live in the region.
+    // Add some safety margin to factor in the confidence of our guess, and the
+    // natural expected waste.
+    // (100.0 / G1ConfidencePercent) is a scale factor that expresses the uncertainty
+    // of the calculation: the lower the confidence, the more headroom.
+    // (100 + TargetPLABWastePct) represents the increase in expected bytes during
+    // copying due to anticipated waste in the PLABs.
+    const double safety_factor = (100.0 / G1ConfidencePercent) * (100 + TargetPLABWastePct) / 100.0;
+    const size_t expected_bytes_to_copy = (size_t)(safety_factor * bytes_to_copy);
 
-  if (expected_bytes_to_copy > free_bytes) {
-    // end condition 3: out-of-space
-    return false;
+    if (expected_bytes_to_copy > free_bytes) {
+      // end condition 3: out-of-space
+      return false;
+    }
+
+    // success!
+    return true;
   }
-
-  // success!
-  return true;
-}
+};
 
 void G1DefaultPolicy::record_new_heap_size(uint new_number_of_regions) {
   // re-calculate the necessary reserve
@@ -279,31 +296,32 @@
   assert(desired_max_length > base_min_length, "invariant");
   uint max_young_length = desired_max_length - base_min_length;
 
-  double target_pause_time_ms = _mmu_tracker->max_gc_time() * 1000.0;
-  double survivor_regions_evac_time = predict_survivor_regions_evac_time();
-  size_t pending_cards = _analytics->predict_pending_cards();
-  size_t adj_rs_lengths = rs_lengths + _analytics->predict_rs_length_diff();
-  size_t scanned_cards = _analytics->predict_card_num(adj_rs_lengths, /* gcs_are_young */ true);
-  double base_time_ms =
+  const double target_pause_time_ms = _mmu_tracker->max_gc_time() * 1000.0;
+  const double survivor_regions_evac_time = predict_survivor_regions_evac_time();
+  const size_t pending_cards = _analytics->predict_pending_cards();
+  const size_t adj_rs_lengths = rs_lengths + _analytics->predict_rs_length_diff();
+  const size_t scanned_cards = _analytics->predict_card_num(adj_rs_lengths, /* gcs_are_young */ true);
+  const double base_time_ms =
     predict_base_elapsed_time_ms(pending_cards, scanned_cards) +
     survivor_regions_evac_time;
-  uint available_free_regions = _free_regions_at_end_of_collection;
-  uint base_free_regions = 0;
-  if (available_free_regions > _reserve_regions) {
-    base_free_regions = available_free_regions - _reserve_regions;
-  }
+  const uint available_free_regions = _free_regions_at_end_of_collection;
+  const uint base_free_regions =
+    available_free_regions > _reserve_regions ? available_free_regions - _reserve_regions : 0;
 
   // Here, we will make sure that the shortest young length that
   // makes sense fits within the target pause time.
 
-  if (predict_will_fit(min_young_length, base_time_ms,
-                       base_free_regions, target_pause_time_ms)) {
+  G1YoungLengthPredictor p(collector_state()->during_concurrent_mark(),
+                           base_time_ms,
+                           base_free_regions,
+                           target_pause_time_ms,
+                           this);
+  if (p.will_fit(min_young_length)) {
     // The shortest young length will fit into the target pause time;
     // we'll now check whether the absolute maximum number of young
     // regions will fit in the target pause time. If not, we'll do
     // a binary search between min_young_length and max_young_length.
-    if (predict_will_fit(max_young_length, base_time_ms,
-                         base_free_regions, target_pause_time_ms)) {
+    if (p.will_fit(max_young_length)) {
       // The maximum young length will fit into the target pause time.
       // We are done so set min young length to the maximum length (as
       // the result is assumed to be returned in min_young_length).
@@ -328,8 +346,7 @@
       uint diff = (max_young_length - min_young_length) / 2;
       while (diff > 0) {
         uint young_length = min_young_length + diff;
-        if (predict_will_fit(young_length, base_time_ms,
-                             base_free_regions, target_pause_time_ms)) {
+        if (p.will_fit(young_length)) {
           min_young_length = young_length;
         } else {
           max_young_length = young_length;
@@ -344,12 +361,10 @@
       assert(min_young_length < max_young_length,
              "otherwise we should have discovered that max_young_length "
              "fits into the pause target and not done the binary search");
-      assert(predict_will_fit(min_young_length, base_time_ms,
-                              base_free_regions, target_pause_time_ms),
+      assert(p.will_fit(min_young_length),
              "min_young_length, the result of the binary search, should "
              "fit into the pause target");
-      assert(!predict_will_fit(min_young_length + 1, base_time_ms,
-                               base_free_regions, target_pause_time_ms),
+      assert(!p.will_fit(min_young_length + 1),
              "min_young_length, the result of the binary search, should be "
              "optimal, so no larger length should fit into the pause target");
     }
@@ -501,13 +516,12 @@
 
 double G1DefaultPolicy::young_other_time_ms() const {
   return phase_times()->young_cset_choice_time_ms() +
-         phase_times()->young_free_cset_time_ms();
+         phase_times()->average_time_ms(G1GCPhaseTimes::YoungFreeCSet);
 }
 
 double G1DefaultPolicy::non_young_other_time_ms() const {
   return phase_times()->non_young_cset_choice_time_ms() +
-         phase_times()->non_young_free_cset_time_ms();
-
+         phase_times()->average_time_ms(G1GCPhaseTimes::NonYoungFreeCSet);
 }
 
 double G1DefaultPolicy::other_time_ms(double pause_time_ms) const {
@@ -515,7 +529,7 @@
 }
 
 double G1DefaultPolicy::constant_other_time_ms(double pause_time_ms) const {
-  return other_time_ms(pause_time_ms) - young_other_time_ms() - non_young_other_time_ms();
+  return other_time_ms(pause_time_ms) - phase_times()->total_free_cset_time_ms();
 }
 
 CollectionSetChooser* G1DefaultPolicy::cset_chooser() const {
--- a/hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -91,6 +91,9 @@
   _redirtied_cards = new WorkerDataArray<size_t>(max_gc_threads, "Redirtied Cards:");
   _gc_par_phases[RedirtyCards]->link_thread_work_items(_redirtied_cards);
 
+  _gc_par_phases[YoungFreeCSet] = new WorkerDataArray<double>(max_gc_threads, "Young Free Collection Set (ms):");
+  _gc_par_phases[NonYoungFreeCSet] = new WorkerDataArray<double>(max_gc_threads, "Non-Young Free Collection Set (ms):");
+
   _gc_par_phases[PreserveCMReferents] = new WorkerDataArray<double>(max_gc_threads, "Parallel Preserve CM Refs (ms):");
 }
 
@@ -278,10 +281,11 @@
   info_line_and_account("Clear Card Table", _cur_clear_ct_time_ms);
   info_line_and_account("Expand Heap After Collection", _cur_expand_heap_time_ms);
 
-  double free_cset_time = _recorded_young_free_cset_time_ms + _recorded_non_young_free_cset_time_ms;
-  info_line_and_account("Free Collection Set", free_cset_time);
-  debug_line("Young Free Collection Set", _recorded_young_free_cset_time_ms);
-  debug_line("Non-Young Free Collection Set", _recorded_non_young_free_cset_time_ms);
+  info_line_and_account("Free Collection Set", _recorded_total_free_cset_time_ms);
+  debug_line("Free Collection Set Serial", _recorded_serial_free_cset_time_ms);
+  debug_phase(_gc_par_phases[YoungFreeCSet]);
+  debug_phase(_gc_par_phases[NonYoungFreeCSet]);
+
   info_line_and_account("Merge Per-Thread State", _recorded_merge_pss_time_ms);
 
   info_line("Other", _gc_pause_time_ms - accounted_time_ms);
--- a/hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -67,6 +67,8 @@
     StringDedupTableFixup,
     RedirtyCards,
     PreserveCMReferents,
+    YoungFreeCSet,
+    NonYoungFreeCSet,
     GCParPhasesSentinel
   };
 
@@ -110,8 +112,9 @@
 
   double _recorded_merge_pss_time_ms;
 
-  double _recorded_young_free_cset_time_ms;
-  double _recorded_non_young_free_cset_time_ms;
+  double _recorded_total_free_cset_time_ms;
+
+  double _recorded_serial_free_cset_time_ms;
 
   double _cur_fast_reclaim_humongous_time_ms;
   double _cur_fast_reclaim_humongous_register_time_ms;
@@ -199,12 +202,12 @@
     _root_region_scan_wait_time_ms = time_ms;
   }
 
-  void record_young_free_cset_time_ms(double time_ms) {
-    _recorded_young_free_cset_time_ms = time_ms;
+  void record_total_free_cset_time_ms(double time_ms) {
+    _recorded_total_free_cset_time_ms = time_ms;
   }
 
-  void record_non_young_free_cset_time_ms(double time_ms) {
-    _recorded_non_young_free_cset_time_ms = time_ms;
+  void record_serial_free_cset_time_ms(double time_ms) {
+    _recorded_serial_free_cset_time_ms = time_ms;
   }
 
   void record_fast_reclaim_humongous_stats(double time_ms, size_t total, size_t candidates) {
@@ -278,18 +281,14 @@
     return _recorded_young_cset_choice_time_ms;
   }
 
-  double young_free_cset_time_ms() {
-    return _recorded_young_free_cset_time_ms;
+  double total_free_cset_time_ms() {
+    return _recorded_total_free_cset_time_ms;
   }
 
   double non_young_cset_choice_time_ms() {
     return _recorded_non_young_cset_choice_time_ms;
   }
 
-  double non_young_free_cset_time_ms() {
-    return _recorded_non_young_free_cset_time_ms;
-  }
-
   double fast_reclaim_humongous_time_ms() {
     return _cur_fast_reclaim_humongous_time_ms;
   }
--- a/hotspot/src/share/vm/gc/g1/g1MarkSweep.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1MarkSweep.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -340,7 +340,7 @@
   hr->set_containing_set(NULL);
   _humongous_regions_removed++;
 
-  _g1h->free_humongous_region(hr, &dummy_free_list, false /* par */);
+  _g1h->free_humongous_region(hr, &dummy_free_list, false /* skip_remset */);
   prepare_for_compaction(hr, end);
   dummy_free_list.remove_all();
 }
--- a/hotspot/src/share/vm/gc/g1/g1PageBasedVirtualSpace.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1PageBasedVirtualSpace.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,22 +26,8 @@
 #include "gc/g1/g1PageBasedVirtualSpace.hpp"
 #include "oops/markOop.hpp"
 #include "oops/oop.inline.hpp"
+#include "runtime/os.inline.hpp"
 #include "services/memTracker.hpp"
-#ifdef TARGET_OS_FAMILY_linux
-# include "os_linux.inline.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "os_solaris.inline.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "os_windows.inline.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "os_aix.inline.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "os_bsd.inline.hpp"
-#endif
 #include "utilities/bitMap.inline.hpp"
 
 G1PageBasedVirtualSpace::G1PageBasedVirtualSpace(ReservedSpace rs, size_t used_size, size_t page_size) :
--- a/hotspot/src/share/vm/gc/g1/g1YoungGenSizer.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1YoungGenSizer.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -45,7 +45,7 @@
                             "A new max generation size of " SIZE_FORMAT "k will be used.",
                             NewSize/K, MaxNewSize/K, NewSize/K);
     }
-    MaxNewSize = NewSize;
+    FLAG_SET_ERGO(size_t, MaxNewSize, NewSize);
   }
 
   if (FLAG_IS_CMDLINE(NewSize)) {
--- a/hotspot/src/share/vm/gc/g1/heapRegion.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/heapRegion.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -167,7 +167,7 @@
   init_top_at_mark_start();
 }
 
-void HeapRegion::hr_clear(bool par, bool clear_space, bool locked) {
+void HeapRegion::hr_clear(bool keep_remset, bool clear_space, bool locked) {
   assert(_humongous_start_region == NULL,
          "we should have already filtered out humongous regions");
   assert(!in_collection_set(),
@@ -179,15 +179,14 @@
   set_free();
   reset_pre_dummy_top();
 
-  if (!par) {
-    // If this is parallel, this will be done later.
-    HeapRegionRemSet* hrrs = rem_set();
+  if (!keep_remset) {
     if (locked) {
-      hrrs->clear_locked();
+      rem_set()->clear_locked();
     } else {
-      hrrs->clear();
+      rem_set()->clear();
     }
   }
+
   zero_marked_bytes();
 
   init_top_at_mark_start();
--- a/hotspot/src/share/vm/gc/g1/heapRegion.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/heapRegion.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -512,8 +512,11 @@
 #endif // ASSERT
 
 
-  // Reset HR stuff to default values.
-  void hr_clear(bool par, bool clear_space, bool locked = false);
+  // Reset the HeapRegion to default values.
+  // If skip_remset is true, do not clear the remembered set.
+  void hr_clear(bool skip_remset, bool clear_space, bool locked = false);
+  // Clear the parts skipped by skip_remset in hr_clear() in the HeapRegion during
+  // a concurrent phase.
   void par_clear();
 
   // Get the start of the unmarked area in this region.
--- a/hotspot/src/share/vm/gc/shared/collectorPolicy.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/collectorPolicy.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -50,7 +50,6 @@
     _initial_heap_byte_size(InitialHeapSize),
     _max_heap_byte_size(MaxHeapSize),
     _min_heap_byte_size(Arguments::min_heap_size()),
-    _max_heap_size_cmdline(false),
     _size_policy(NULL),
     _should_clear_all_soft_refs(false),
     _all_soft_refs_clear(false)
@@ -92,7 +91,6 @@
     if (_min_heap_byte_size != 0 && MaxHeapSize < _min_heap_byte_size) {
       vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified");
     }
-    _max_heap_size_cmdline = true;
   }
 
   // Check heap parameter properties
@@ -285,7 +283,7 @@
          "heap_alignment: " SIZE_FORMAT " not aligned by gen_alignment: " SIZE_FORMAT,
          _heap_alignment, _gen_alignment);
 
-  // All generational heaps have a youngest gen; handle those flags here
+  // All generational heaps have a young gen; handle those flags here
 
   // Make sure the heap is large enough for two generations
   size_t smallest_new_size = young_gen_size_lower_bound();
@@ -307,7 +305,7 @@
   // Make sure NewSize allows an old generation to fit even if set on the command line
   if (FLAG_IS_CMDLINE(NewSize) && NewSize >= _initial_heap_byte_size) {
     log_warning(gc, ergo)("NewSize was set larger than initial heap size, will use initial heap size.");
-    NewSize = bound_minus_alignment(NewSize, _initial_heap_byte_size);
+    FLAG_SET_ERGO(size_t, NewSize, bound_minus_alignment(NewSize, _initial_heap_byte_size));
   }
 
   // Now take the actual NewSize into account. We will silently increase NewSize
@@ -315,10 +313,7 @@
   size_t bounded_new_size = bound_minus_alignment(NewSize, MaxHeapSize);
   bounded_new_size = MAX2(smallest_new_size, (size_t)align_size_down(bounded_new_size, _gen_alignment));
   if (bounded_new_size != NewSize) {
-    // Do not use FLAG_SET_ERGO to update NewSize here, since this will override
-    // if NewSize was set on the command line or not. This information is needed
-    // later when setting the initial and minimum young generation size.
-    NewSize = bounded_new_size;
+    FLAG_SET_ERGO(size_t, NewSize, bounded_new_size);
   }
   _min_young_size = smallest_new_size;
   _initial_young_size = NewSize;
@@ -361,11 +356,11 @@
     vm_exit_during_initialization("Invalid young gen ratio specified");
   }
 
-  OldSize = MAX2(OldSize, old_gen_size_lower_bound());
+  if (OldSize < old_gen_size_lower_bound()) {
+    FLAG_SET_ERGO(size_t, OldSize, old_gen_size_lower_bound());
+  }
   if (!is_size_aligned(OldSize, _gen_alignment)) {
-    // Setting OldSize directly to preserve information about the possible
-    // setting of OldSize on the command line.
-    OldSize = align_size_down(OldSize, _gen_alignment);
+    FLAG_SET_ERGO(size_t, OldSize, align_size_down(OldSize, _gen_alignment));
   }
 
   if (FLAG_IS_CMDLINE(OldSize) && FLAG_IS_DEFAULT(MaxHeapSize)) {
@@ -384,7 +379,7 @@
 
   // Adjust NewSize and OldSize or MaxHeapSize to match each other
   if (NewSize + OldSize > MaxHeapSize) {
-    if (_max_heap_size_cmdline) {
+    if (FLAG_IS_CMDLINE(MaxHeapSize)) {
       // Somebody has set a maximum heap size with the intention that we should not
       // exceed it. Adjust New/OldSize as necessary.
       size_t calculated_size = NewSize + OldSize;
@@ -927,8 +922,23 @@
 
     save_flags();
 
+    // If NewSize has been ergonomically set, the collector policy
+    // should use it for min but calculate the initial young size
+    // using NewRatio.
+    flag_value = 20 * M;
+    set_basic_flag_values();
+    FLAG_SET_ERGO(size_t, NewSize, flag_value);
+    verify_young_min(flag_value);
+
+    set_basic_flag_values();
+    FLAG_SET_ERGO(size_t, NewSize, flag_value);
+    verify_scaled_young_initial(InitialHeapSize);
+
     // If NewSize is set on the command line, it should be used
     // for both min and initial young size if less than min heap.
+    // Note that once a flag has been set with FLAG_SET_CMDLINE it
+    // will be treated as it have been set on the command line for
+    // the rest of the VM lifetime. This is an irreversible change.
     flag_value = 20 * M;
     set_basic_flag_values();
     FLAG_SET_CMDLINE(size_t, NewSize, flag_value);
@@ -945,18 +955,6 @@
     FLAG_SET_CMDLINE(size_t, NewSize, flag_value);
     verify_young_initial(flag_value);
 
-    // If NewSize has been ergonomically set, the collector policy
-    // should use it for min but calculate the initial young size
-    // using NewRatio.
-    flag_value = 20 * M;
-    set_basic_flag_values();
-    FLAG_SET_ERGO(size_t, NewSize, flag_value);
-    verify_young_min(flag_value);
-
-    set_basic_flag_values();
-    FLAG_SET_ERGO(size_t, NewSize, flag_value);
-    verify_scaled_young_initial(InitialHeapSize);
-
     restore_flags();
   }
 
--- a/hotspot/src/share/vm/gc/shared/collectorPolicy.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/collectorPolicy.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -72,10 +72,6 @@
   size_t _space_alignment;
   size_t _heap_alignment;
 
-  // Needed to keep information if MaxHeapSize was set on the command line
-  // when the flag value is aligned etc by ergonomics.
-  bool _max_heap_size_cmdline;
-
   // The sizing of the heap is controlled by a sizing policy.
   AdaptiveSizePolicy* _size_policy;
 
--- a/hotspot/src/share/vm/gc/shared/concurrentGCThread.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/concurrentGCThread.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -43,7 +43,7 @@
     // unless "aggressive mode" set; priority
     // should be just less than that of VMThread.
     os::set_priority(this, prio);
-    if (!_should_terminate && !DisableStartThread) {
+    if (!_should_terminate) {
       os::start_thread(this);
     }
   }
--- a/hotspot/src/share/vm/gc/shared/gcTraceSend.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/gcTraceSend.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -278,7 +278,7 @@
     evt.set_gcId(GCId::current());
     evt.set_threshold(threshold);
     evt.set_targetOccupancy(target_occupancy);
-    evt.set_thresholdPercentage(target_occupancy > 0 ? (threshold * 100 / target_occupancy) : 0);
+    evt.set_thresholdPercentage(target_occupancy > 0 ? ((double)threshold / target_occupancy) : 0.0);
     evt.set_currentOccupancy(current_occupancy);
     evt.set_lastAllocationSize(last_allocation_size);
     evt.set_lastAllocationDuration(last_allocation_duration);
@@ -299,7 +299,7 @@
   if (evt.should_commit()) {
     evt.set_gcId(GCId::current());
     evt.set_threshold(threshold);
-    evt.set_thresholdPercentage(internal_target_occupancy > 0 ? (threshold * 100 / internal_target_occupancy) : 0);
+    evt.set_thresholdPercentage(internal_target_occupancy > 0 ? ((double)threshold / internal_target_occupancy) : 0.0);
     evt.set_internalTargetOccupancy(internal_target_occupancy);
     evt.set_currentOccupancy(current_occupancy);
     evt.set_additionalBufferSize(additional_buffer_size);
--- a/hotspot/src/share/vm/gc/shared/memset_with_concurrent_readers.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/memset_with_concurrent_readers.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,9 +25,10 @@
 #ifndef SRC_SHARE_VM_GC_SHARED_MEMSETWITHCONCURRENTREADERS_HPP
 #define SRC_SHARE_VM_GC_SHARED_MEMSETWITHCONCURRENTREADERS_HPP
 
+#include "utilities/macros.hpp"
+
 #include <stddef.h>
 #include <string.h>
-#include "utilities/macros.hpp"
 
 // Only used by concurrent collectors.
 #if INCLUDE_ALL_GCS
@@ -36,7 +37,7 @@
 // understanding that there may be concurrent readers of that memory.
 void memset_with_concurrent_readers(void* to, int value, size_t size);
 
-#ifdef TARGET_ARCH_sparc
+#ifdef SPARC
 
 // SPARC requires special handling.  See SPARC-specific definition.
 
@@ -51,4 +52,4 @@
 
 #endif // INCLUDE_ALL_GCS
 
-#endif // include guard
+#endif // SRC_SHARE_VM_GC_SHARED_MEMSETWITHCONCURRENTREADERS_HPP
--- a/hotspot/src/share/vm/interpreter/bytecodeInterpreter.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/bytecodeInterpreter.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -32,6 +32,7 @@
 #include "runtime/frame.hpp"
 #include "runtime/globals.hpp"
 #include "utilities/globalDefinitions.hpp"
+#include "utilities/macros.hpp"
 
 #ifdef CC_INTERP
 
@@ -572,7 +573,7 @@
 void print();
 #endif // PRODUCT
 
-#ifdef TARGET_ARCH_zero
+#ifdef ZERO
 # include "bytecodeInterpreter_zero.hpp"
 #else
 #error "Only Zero Bytecode Interpreter is supported"
--- a/hotspot/src/share/vm/interpreter/bytecodeInterpreter.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/bytecodeInterpreter.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 
 #include "interpreter/bytecodeInterpreter.hpp"
 #include "runtime/stubRoutines.hpp"
+#include "utilities/macros.hpp"
 
 // This file holds platform-independent bodies of inline functions for the C++ based interpreter
 
@@ -42,7 +43,7 @@
 #define VERIFY_OOP(o)
 #endif
 
-#ifdef TARGET_ARCH_zero
+#ifdef ZERO
 # include "bytecodeInterpreter_zero.inline.hpp"
 #else
 #error "Only Zero Bytecode Interpreter is supported"
--- a/hotspot/src/share/vm/interpreter/cppInterpreter.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/cppInterpreter.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,8 @@
 #define SHARE_VM_INTERPRETER_CPPINTERPRETER_HPP
 
 #include "interpreter/abstractInterpreter.hpp"
+#include "utilities/macros.hpp"
+
 #ifdef CC_INTERP
 
 class InterpreterCodelet;
@@ -60,7 +62,7 @@
                          address   entry_point,
                          address   osr_buf,
                          TRAPS);
-#ifdef TARGET_ARCH_zero
+#ifdef ZERO
 # include "cppInterpreter_zero.hpp"
 #endif
 
--- a/hotspot/src/share/vm/interpreter/interp_masm.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/interp_masm.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,19 +26,8 @@
 #define SHARE_VM_INTERPRETER_INTERP_MASM_HPP
 
 #include "asm/macroAssembler.hpp"
+#include "utilities/macros.hpp"
 
-#if defined INTERP_MASM_MD_HPP
-# include INTERP_MASM_MD_HPP
-#elif defined TARGET_ARCH_x86
-# include "interp_masm_x86.hpp"
-#elif defined TARGET_ARCH_MODEL_sparc
-# include "interp_masm_sparc.hpp"
-#elif defined TARGET_ARCH_MODEL_zero
-# include "interp_masm_zero.hpp"
-#elif defined TARGET_ARCH_MODEL_ppc_64
-# include "interp_masm_ppc_64.hpp"
-#elif defined TARGET_ARCH_MODEL_aarch64
-# include "interp_masm_aarch64.hpp"
-#endif
+#include CPU_HEADER(interp_masm)
 
 #endif // SHARE_VM_INTERPRETER_INTERP_MASM_HPP
--- a/hotspot/src/share/vm/interpreter/interpreterRuntime.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/interpreterRuntime.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -32,6 +32,7 @@
 #include "runtime/frame.inline.hpp"
 #include "runtime/signature.hpp"
 #include "runtime/thread.hpp"
+#include "utilities/macros.hpp"
 
 // The InterpreterRuntime is called by the interpreter for everything
 // that cannot/should not be dealt with in assembly and needs C support.
@@ -167,24 +168,7 @@
   static intptr_t trace_bytecode(JavaThread* thread, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2) PRODUCT_RETURN0;
 
   // Platform dependent stuff
-#ifdef TARGET_ARCH_x86
-# include "interpreterRT_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "interpreterRT_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "interpreterRT_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "interpreterRT_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "interpreterRT_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "interpreterRT_aarch64.hpp"
-#endif
+#include CPU_HEADER(interpreterRT)
 
   // optional normalization of fingerprints to reduce the number of adapters
   static uint64_t normalize_fast_native_fingerprint(uint64_t fingerprint);
--- a/hotspot/src/share/vm/interpreter/templateInterpreterGenerator.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/templateInterpreterGenerator.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -476,7 +476,7 @@
   case Interpreter::java_lang_Double_doubleToRawLongBits:
     native = true;
     break;
-#endif // defined(TARGET_ARCH_x86) && !defined(_LP64)
+#endif // !IA32
   default:
     fatal("unexpected method kind: %d", kind);
     break;
--- a/hotspot/src/share/vm/interpreter/templateTable.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/templateTable.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
 #include "interpreter/bytecodes.hpp"
 #include "memory/allocation.hpp"
 #include "runtime/frame.hpp"
+#include "utilities/macros.hpp"
 
 #ifndef CC_INTERP
 // All the necessary definitions used for (bytecode) template generation. Instead of
@@ -349,17 +350,7 @@
   static Template* template_for_wide(Bytecodes::Code code)  { Bytecodes::wide_check(code); return &_template_table_wide[code]; }
 
   // Platform specifics
-#if defined TEMPLATETABLE_MD_HPP
-# include TEMPLATETABLE_MD_HPP
-#elif defined (TARGET_ARCH_MODEL_x86_32) || defined (TARGET_ARCH_MODEL_x86_64)
-# include "templateTable_x86.hpp"
-#elif defined TARGET_ARCH_MODEL_sparc
-# include "templateTable_sparc.hpp"
-#elif defined TARGET_ARCH_MODEL_ppc_64
-# include "templateTable_ppc_64.hpp"
-#elif defined TARGET_ARCH_MODEL_aarch64
-# include "templateTable_aarch64.hpp"
-#endif
+#include CPU_HEADER(templateTable)
 
 };
 #endif /* !CC_INTERP */
--- a/hotspot/src/share/vm/jvmci/jvmciCodeInstaller.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/jvmciCodeInstaller.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -22,38 +22,21 @@
  */
 
 #include "precompiled.hpp"
+#include "asm/register.hpp"
+#include "classfile/vmSymbols.hpp"
 #include "code/compiledIC.hpp"
+#include "code/vmreg.inline.hpp"
 #include "compiler/compileBroker.hpp"
 #include "compiler/disassembler.hpp"
-#include "oops/oop.inline.hpp"
-#include "oops/objArrayOop.inline.hpp"
-#include "runtime/javaCalls.hpp"
 #include "jvmci/jvmciEnv.hpp"
 #include "jvmci/jvmciCompiler.hpp"
 #include "jvmci/jvmciCodeInstaller.hpp"
 #include "jvmci/jvmciJavaClasses.hpp"
 #include "jvmci/jvmciCompilerToVM.hpp"
 #include "jvmci/jvmciRuntime.hpp"
-#include "asm/register.hpp"
-#include "classfile/vmSymbols.hpp"
-#include "code/vmreg.hpp"
-
-#ifdef TARGET_ARCH_x86
-# include "vmreg_x86.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "vmreg_sparc.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "vmreg_zero.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "vmreg_arm.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "vmreg_ppc.inline.hpp"
-#endif
-
+#include "oops/oop.inline.hpp"
+#include "oops/objArrayOop.inline.hpp"
+#include "runtime/javaCalls.hpp"
 
 // frequently used constants
 // Allocate them with new so they are never destroyed (otherwise, a
--- a/hotspot/src/share/vm/jvmci/jvmciRuntime.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/jvmciRuntime.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -44,6 +44,7 @@
 #include "runtime/sharedRuntime.hpp"
 #include "utilities/debug.hpp"
 #include "utilities/defaultStream.hpp"
+#include "utilities/macros.hpp"
 
 #if defined(_MSC_VER)
 #define strtoll _strtoi64
@@ -770,14 +771,14 @@
   }
 
 #ifdef _LP64
-#ifndef TARGET_ARCH_sparc
+#ifndef SPARC
   uintptr_t heap_end = (uintptr_t) Universe::heap()->reserved_region().end();
   uintptr_t allocation_end = heap_end + ((uintptr_t)16) * 1024 * 1024 * 1024;
   guarantee(heap_end < allocation_end, "heap end too close to end of address space (might lead to erroneous TLAB allocations)");
-#endif // TARGET_ARCH_sparc
+#endif // !SPARC
 #else
   fatal("check TLAB allocation code for address space conflicts");
-#endif
+#endif // _LP64
 
   JVMCIRuntime::initialize_well_known_classes(CHECK);
 
--- a/hotspot/src/share/vm/jvmci/vmStructs_jvmci.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/vmStructs_jvmci.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -591,31 +591,31 @@
 #endif // INCLUDE_ALL_GCS
 
 
-#ifdef TARGET_OS_FAMILY_linux
+#ifdef LINUX
 
 #define VM_ADDRESSES_OS(declare_address, declare_preprocessor_address, declare_function) \
   declare_preprocessor_address("RTLD_DEFAULT", RTLD_DEFAULT)
 
-#endif // TARGET_OS_FAMILY_linux
+#endif
 
 
-#ifdef TARGET_OS_FAMILY_bsd
+#ifdef BSD
 
 #define VM_ADDRESSES_OS(declare_address, declare_preprocessor_address, declare_function) \
   declare_preprocessor_address("RTLD_DEFAULT", RTLD_DEFAULT)
 
-#endif // TARGET_OS_FAMILY_bsd
+#endif
 
-
+// AARCH64 is defined in closed port, too. TARGET_ARCH_aarch64 is not.
 #ifdef TARGET_ARCH_aarch64
 
 #define VM_STRUCTS_CPU(nonstatic_field, static_field, unchecked_nonstatic_field, volatile_nonstatic_field, nonproduct_nonstatic_field, c2_nonstatic_field, unchecked_c1_static_field, unchecked_c2_static_field) \
   volatile_nonstatic_field(JavaFrameAnchor, _last_Java_fp, intptr_t*)
 
-#endif // TARGET_ARCH_aarch64
+#endif
 
 
-#ifdef TARGET_ARCH_x86
+#ifdef X86
 
 #define VM_STRUCTS_CPU(nonstatic_field, static_field, unchecked_nonstatic_field, volatile_nonstatic_field, nonproduct_nonstatic_field, c2_nonstatic_field, unchecked_c1_static_field, unchecked_c2_static_field) \
   volatile_nonstatic_field(JavaFrameAnchor, _last_Java_fp, intptr_t*)
@@ -661,10 +661,10 @@
   declare_preprocessor_constant("VM_Version::CPU_AVX512VL", CPU_AVX512VL) \
   declare_preprocessor_constant("VM_Version::CPU_SHA", CPU_SHA)
 
-#endif // TARGET_ARCH_x86
+#endif
 
 
-#ifdef TARGET_ARCH_sparc
+#ifdef SPARC
 
 #define VM_STRUCTS_CPU(nonstatic_field, static_field, unchecked_nonstatic_field, volatile_nonstatic_field, nonproduct_nonstatic_field, c2_nonstatic_field, unchecked_c1_static_field, unchecked_c2_static_field) \
   volatile_nonstatic_field(JavaFrameAnchor, _flags, int)
@@ -694,7 +694,7 @@
   declare_constant(VM_Version::sha256_instruction_m)                      \
   declare_constant(VM_Version::sha512_instruction_m)
 
-#endif // TARGET_ARCH_sparc
+#endif
 
 
 /*
--- a/hotspot/src/share/vm/memory/filemap.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/memory/filemap.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -199,11 +199,45 @@
   size_t entry_size = SharedClassUtil::shared_class_path_entry_size();
 
   for (int pass=0; pass<2; pass++) {
-    ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
 
-    for (int cur_entry = 0 ; cpe != NULL; cpe = cpe->next(), cur_entry++) {
+    // Process the modular java runtime image first
+    ClassPathEntry* jrt_entry = ClassLoader::get_jrt_entry();
+    assert(jrt_entry != NULL,
+           "No modular java runtime image present when allocating the CDS classpath entry table");
+    const char *name = jrt_entry->name();
+    int name_bytes = (int)(strlen(name) + 1);
+    if (pass == 0) {
+      count++;
+      bytes += (int)entry_size;
+      bytes += name_bytes;
+      log_info(class, path)("add main shared path for modular java runtime image %s", name);
+    } else {
+      // The java runtime image is always in slot 0 on the shared class path.
+      SharedClassPathEntry* ent = shared_classpath(0);
+      struct stat st;
+      if (os::stat(name, &st) == 0) {
+        ent->_timestamp = st.st_mtime;
+        ent->_filesize = st.st_size;
+      }
+      if (ent->_filesize == 0) {
+        // unknown
+        ent->_filesize = -2;
+      }
+      ent->_name = strptr;
+      assert(strptr + name_bytes <= strptr_max, "miscalculated buffer size");
+      strncpy(strptr, name, (size_t)name_bytes); // name_bytes includes trailing 0.
+      strptr += name_bytes;
+    }
+
+    // Walk the appended entries, which includes the entries added for the classpath.
+    ClassPathEntry *cpe = ClassLoader::classpath_entry(1);
+
+    // Since the java runtime image is always in slot 0 on the shared class path, the
+    // appended entries are started at slot 1 immediately after.
+    for (int cur_entry = 1 ; cpe != NULL; cpe = cpe->next(), cur_entry++) {
       const char *name = cpe->name();
       int name_bytes = (int)(strlen(name) + 1);
+      assert(!cpe->is_jrt(), "A modular java runtime image is present on the list of appended entries");
 
       if (pass == 0) {
         count ++;
@@ -228,11 +262,7 @@
         } else {
           struct stat st;
           if (os::stat(name, &st) == 0) {
-            if (cpe->is_jrt()) {
-              // it's the "modules" jimage
-              ent->_timestamp = st.st_mtime;
-              ent->_filesize = st.st_size;
-            } else if ((st.st_mode & S_IFDIR) == S_IFDIR) {
+            if ((st.st_mode & S_IFDIR) == S_IFDIR) {
               if (!os::dir_is_empty(name)) {
                 ClassLoader::exit_with_path_failure(
                   "Cannot have non-empty directory in archived classpaths", name);
@@ -886,6 +916,11 @@
     return false;
   }
 
+  if (!Arguments::has_jimage()) {
+    FileMapInfo::fail_continue("The shared archive file cannot be used with an exploded module build.");
+    return false;
+  }
+
   if (_version != current_version()) {
     FileMapInfo::fail_continue("The shared archive file is the wrong version.");
     return false;
--- a/hotspot/src/share/vm/memory/metaspace.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/memory/metaspace.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -3164,39 +3164,47 @@
 #endif // _LP64
 #endif // INCLUDE_CDS
   } else {
-    // If using shared space, open the file that contains the shared space
-    // and map in the memory before initializing the rest of metaspace (so
-    // the addresses don't conflict)
-    address cds_address = NULL;
+#if INCLUDE_CDS
     if (UseSharedSpaces) {
-#if INCLUDE_CDS
+      // If using shared space, open the file that contains the shared space
+      // and map in the memory before initializing the rest of metaspace (so
+      // the addresses don't conflict)
+      address cds_address = NULL;
       FileMapInfo* mapinfo = new FileMapInfo();
 
-      // Open the shared archive file, read and validate the header. If
-      // initialization fails, shared spaces [UseSharedSpaces] are
-      // disabled and the file is closed.
-      // Map in spaces now also
-      if (mapinfo->initialize() && MetaspaceShared::map_shared_spaces(mapinfo)) {
-        cds_total = FileMapInfo::shared_spaces_size();
-        cds_address = (address)mapinfo->header()->region_addr(0);
+      if (JvmtiExport::should_post_class_file_load_hook()) {
+        // Currently CDS does not support JVMTI CFLH when loading shared class.
+        // If JvmtiExport::should_post_class_file_load_hook is already enabled,
+        // just disable UseSharedSpaces.
+        FileMapInfo::fail_continue("Tool agent requires sharing to be disabled.");
+        delete mapinfo;
+      } else {
+        // Open the shared archive file, read and validate the header. If
+        // initialization fails, shared spaces [UseSharedSpaces] are
+        // disabled and the file is closed.
+        // Map in spaces now also
+        if (mapinfo->initialize() && MetaspaceShared::map_shared_spaces(mapinfo)) {
+          cds_total = FileMapInfo::shared_spaces_size();
+          cds_address = (address)mapinfo->header()->region_addr(0);
 #ifdef _LP64
-        if (using_class_space()) {
-          char* cds_end = (char*)(cds_address + cds_total);
-          cds_end = (char *)align_ptr_up(cds_end, _reserve_alignment);
-          // If UseCompressedClassPointers is set then allocate the metaspace area
-          // above the heap and above the CDS area (if it exists).
-          allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address);
-          // Map the shared string space after compressed pointers
-          // because it relies on compressed class pointers setting to work
-          mapinfo->map_string_regions();
+          if (using_class_space()) {
+            char* cds_end = (char*)(cds_address + cds_total);
+            cds_end = (char *)align_ptr_up(cds_end, _reserve_alignment);
+            // If UseCompressedClassPointers is set then allocate the metaspace area
+            // above the heap and above the CDS area (if it exists).
+            allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address);
+            // Map the shared string space after compressed pointers
+            // because it relies on compressed class pointers setting to work
+            mapinfo->map_string_regions();
+          }
+#endif // _LP64
+        } else {
+          assert(!mapinfo->is_open() && !UseSharedSpaces,
+                 "archive file not closed or shared spaces not disabled.");
         }
-#endif // _LP64
-      } else {
-        assert(!mapinfo->is_open() && !UseSharedSpaces,
-               "archive file not closed or shared spaces not disabled.");
       }
+    }
 #endif // INCLUDE_CDS
-    }
 
 #ifdef _LP64
     if (!UseSharedSpaces && using_class_space()) {
--- a/hotspot/src/share/vm/memory/virtualspace.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/memory/virtualspace.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -676,7 +676,7 @@
 
 
 void VirtualSpace::release() {
-  // This does not release memory it never reserved.
+  // This does not release memory it reserved.
   // Caller must release via rs.release();
   _low_boundary           = NULL;
   _high_boundary          = NULL;
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -67,6 +67,7 @@
 #include "services/threadService.hpp"
 #include "utilities/dtrace.hpp"
 #include "utilities/macros.hpp"
+#include "utilities/stringUtils.hpp"
 #include "logging/log.hpp"
 #ifdef COMPILER1
 #include "c1/c1_Compiler.hpp"
@@ -2225,9 +2226,14 @@
 }
 
 void InstanceKlass::set_package(ClassLoaderData* loader_data, TRAPS) {
+
+  // ensure java/ packages only loaded by boot or platform builtin loaders
+  check_prohibited_package(name(), loader_data->class_loader(), CHECK);
+
   TempNewSymbol pkg_name = package_from_name(name(), CHECK);
 
   if (pkg_name != NULL && loader_data != NULL) {
+
     // Find in class loader's package entry table.
     _package_entry = loader_data->packages()->lookup_only(pkg_name);
 
@@ -2376,6 +2382,31 @@
 }
 */
 
+// Only boot and platform class loaders can define classes in "java/" packages.
+void InstanceKlass::check_prohibited_package(Symbol* class_name,
+                                                Handle class_loader,
+                                                TRAPS) {
+  const char* javapkg = "java/";
+  ResourceMark rm(THREAD);
+  if (!class_loader.is_null() &&
+      !SystemDictionary::is_platform_class_loader(class_loader) &&
+      class_name != NULL &&
+      strncmp(class_name->as_C_string(), javapkg, strlen(javapkg)) == 0) {
+    TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK);
+    assert(pkg_name != NULL, "Error in parsing package name starting with 'java/'");
+    char* name = pkg_name->as_C_string();
+    const char* class_loader_name = InstanceKlass::cast(class_loader()->klass())->name()->as_C_string();
+    StringUtils::replace_no_expand(name, "/", ".");
+    const char* msg_text1 = "Class loader (instance of): ";
+    const char* msg_text2 = " tried to load prohibited package name: ";
+    size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + strlen(name) + 1;
+    char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len);
+    jio_snprintf(message, len, "%s%s%s%s", msg_text1, class_loader_name, msg_text2, name);
+    THROW_MSG(vmSymbols::java_lang_SecurityException(), message);
+  }
+  return;
+}
+
 // tell if two classes have the same enclosing class (at package level)
 bool InstanceKlass::is_same_package_member_impl(const InstanceKlass* class1,
                                                 const Klass* class2,
--- a/hotspot/src/share/vm/oops/instanceKlass.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/oops/instanceKlass.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -470,6 +470,12 @@
   static bool find_inner_classes_attr(instanceKlassHandle k,
                                       int* ooff, int* noff, TRAPS);
 
+ private:
+  // Check prohibited package ("java/" only loadable by boot or platform loaders)
+  static void check_prohibited_package(Symbol* class_name,
+                                       Handle class_loader,
+                                       TRAPS);
+ public:
   // tell if two classes have the same enclosing class (at package level)
   bool is_same_package_member(const Klass* class2, TRAPS) const {
     return is_same_package_member_impl(this, class2, THREAD);
@@ -786,7 +792,9 @@
   static void purge_previous_versions(InstanceKlass* ik) { return; };
   static bool has_previous_versions() { return false; }
 
-  void set_cached_class_file(JvmtiCachedClassFileData *data) { ShouldNotReachHere(); }
+  void set_cached_class_file(JvmtiCachedClassFileData *data) {
+    assert(data == NULL, "unexpected call with JVMTI disabled");
+  }
   JvmtiCachedClassFileData * get_cached_class_file() { return (JvmtiCachedClassFileData *)NULL; }
 
 #endif // INCLUDE_JVMTI
--- a/hotspot/src/share/vm/oops/symbol.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/oops/symbol.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -91,12 +91,6 @@
 // The allocation (or lookup) of K increments the reference count for K
 // and the destructor decrements the reference count.
 //
-// Another example of TempNewSymbol usage is parsed_name used in
-// ClassFileParser::parseClassFile() where parsed_name is used in the cleanup
-// after a failed attempt to load a class.  Here parsed_name is a
-// TempNewSymbol (passed in as a parameter) so the reference count on its symbol
-// will be decremented when it goes out of scope.
-
 // This cannot be inherited from ResourceObj because it cannot have a vtable.
 // Since sometimes this is allocated from Metadata, pick a base allocation
 // type without virtual functions.
--- a/hotspot/src/share/vm/opto/ad.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/opto/ad.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,20 +25,9 @@
 #ifndef SHARE_VM_OPTO_AD_HPP
 #define SHARE_VM_OPTO_AD_HPP
 
-#if defined AD_MD_HPP
-# include AD_MD_HPP
-#elif defined TARGET_ARCH_MODEL_x86_32
-# include "adfiles/ad_x86_32.hpp"
-#elif defined TARGET_ARCH_MODEL_x86_64
-# include "adfiles/ad_x86_64.hpp"
-#elif defined TARGET_ARCH_MODEL_sparc
-# include "adfiles/ad_sparc.hpp"
-#elif defined TARGET_ARCH_MODEL_zero
-# include "adfiles/ad_zero.hpp"
-#elif defined TARGET_ARCH_MODEL_ppc_64
-# include "adfiles/ad_ppc_64.hpp"
-#elif defined TARGET_ARCH_MODEL_aarch64
-# include "adfiles/ad_aarch64.hpp"
-#endif
+
+#include "utilities/macros.hpp"
+
+#include CPU_HEADER(adfiles/ad)
 
 #endif // SHARE_VM_OPTO_AD_HPP
--- a/hotspot/src/share/vm/opto/c2_globals.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/opto/c2_globals.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -26,36 +26,10 @@
 #define SHARE_VM_OPTO_C2_GLOBALS_HPP
 
 #include "runtime/globals.hpp"
-#ifdef TARGET_ARCH_x86
-# include "c2_globals_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "c2_globals_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "c2_globals_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "c2_globals_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "c2_globals_aarch64.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_linux
-# include "c2_globals_linux.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "c2_globals_solaris.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "c2_globals_windows.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "c2_globals_aix.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "c2_globals_bsd.hpp"
-#endif
+#include "utilities/macros.hpp"
+
+#include CPU_HEADER(c2_globals)
+#include OS_HEADER(c2_globals)
 
 //
 // Defines all globals flags used by the server compiler.
--- a/hotspot/src/share/vm/opto/library_call.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/opto/library_call.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -3304,7 +3304,7 @@
   // drop through to next case
   set_control( _gvn.transform(new IfTrueNode(iff_bit)));
 
-#ifndef TARGET_OS_FAMILY_windows
+#ifndef _WINDOWS
   // (c) Or, if interrupt bit is set and clear_int is false, use 2nd fast path.
   Node* clr_arg = argument(1);
   Node* cmp_arg = _gvn.transform(new CmpINode(clr_arg, intcon(0)));
@@ -3321,7 +3321,7 @@
 #else
   // To return true on Windows you must read the _interrupted field
   // and check the event state i.e. take the slow path.
-#endif // TARGET_OS_FAMILY_windows
+#endif // _WINDOWS
 
   // (d) Otherwise, go to the slow path.
   slow_region->add_req(control());
--- a/hotspot/src/share/vm/opto/optoreg.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/opto/optoreg.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,23 +25,11 @@
 #ifndef SHARE_VM_OPTO_OPTOREG_HPP
 #define SHARE_VM_OPTO_OPTOREG_HPP
 
+#include "utilities/macros.hpp"
+
 // AdGlobals contains c2 specific register handling code as specified
 // in the .ad files.
-#if defined ADGLOBALS_MD_HPP
-# include ADGLOBALS_MD_HPP
-#elif defined TARGET_ARCH_MODEL_x86_32
-# include "adfiles/adGlobals_x86_32.hpp"
-#elif defined TARGET_ARCH_MODEL_x86_64
-# include "adfiles/adGlobals_x86_64.hpp"
-#elif defined TARGET_ARCH_MODEL_sparc
-# include "adfiles/adGlobals_sparc.hpp"
-#elif defined TARGET_ARCH_MODEL_zero
-# include "adfiles/adGlobals_zero.hpp"
-#elif defined TARGET_ARCH_MODEL_ppc_64
-# include "adfiles/adGlobals_ppc_64.hpp"
-#elif defined TARGET_ARCH_MODEL_aarch64
-# include "adfiles/adGlobals_aarch64.hpp"
-#endif
+#include CPU_HEADER(adfiles/adGlobals)
 
 //------------------------------OptoReg----------------------------------------
 // We eventually need Registers for the Real World.  Registers are essentially
--- a/hotspot/src/share/vm/opto/runtime.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/opto/runtime.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -59,6 +59,7 @@
 #include "opto/mulnode.hpp"
 #include "opto/runtime.hpp"
 #include "opto/subnode.hpp"
+#include "prims/jvmtiThreadState.hpp"
 #include "runtime/atomic.inline.hpp"
 #include "runtime/fprofiler.hpp"
 #include "runtime/handles.inline.hpp"
@@ -1451,6 +1452,11 @@
   }
 #endif
 
+  JvmtiThreadState *state = thread->jvmti_thread_state();
+  if (state != NULL) {
+    state->set_exception_detected();
+  }
+
   thread->set_vm_result(exception);
   // Frame not compiled (handles deoptimization blob)
   return SharedRuntime::raw_exception_handler_for_return_address(thread, ret_pc);
--- a/hotspot/src/share/vm/prims/jni_md.h	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/prims/jni_md.h	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,26 +23,10 @@
  * questions.
  */
 
+#include "utilities/macros.hpp"
+
 /* Switch to the correct jni_md.h file without reliance on -I options. */
-#ifdef TARGET_ARCH_x86
-# include "jni_x86.h"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "jni_sparc.h"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "jni_zero.h"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "jni_arm.h"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "jni_ppc.h"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "jni_aarch64.h"
-#endif
-
+#include CPU_HEADER_H(jni)
 
 /*
   The local copies of JNI header files may be refreshed
--- a/hotspot/src/share/vm/prims/jvm.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvm.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -84,21 +84,6 @@
 #include "classfile/sharedClassUtil.hpp"
 #include "classfile/systemDictionaryShared.hpp"
 #endif
-#ifdef TARGET_OS_FAMILY_linux
-# include "jvm_linux.h"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "jvm_solaris.h"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "jvm_windows.h"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "jvm_aix.h"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "jvm_bsd.h"
-#endif
 
 #include <errno.h>
 
--- a/hotspot/src/share/vm/prims/jvm.h	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvm.h	Fri Jul 29 16:11:55 2016 -0700
@@ -26,21 +26,9 @@
 #define SHARE_VM_PRIMS_JVM_H
 
 #include "prims/jni.h"
-#ifdef TARGET_OS_FAMILY_linux
-# include "jvm_linux.h"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "jvm_solaris.h"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "jvm_windows.h"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "jvm_aix.h"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "jvm_bsd.h"
-#endif
+#include "utilities/macros.hpp"
+
+#include OS_HEADER_H(jvm)
 
 #ifndef _JAVASOFT_JVM_H_
 #define _JAVASOFT_JVM_H_
--- a/hotspot/src/share/vm/prims/methodHandles.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/prims/methodHandles.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -30,13 +30,13 @@
 #include "runtime/frame.inline.hpp"
 #include "runtime/globals.hpp"
 #include "runtime/interfaceSupport.hpp"
+#include "utilities/macros.hpp"
 
-#ifdef TARGET_ARCH_zero
+#ifdef ZERO
 # include "entry_zero.hpp"
 #endif
 
 
-
 class MacroAssembler;
 class Label;
 
@@ -192,25 +192,7 @@
             ref_kind == JVM_REF_invokeInterface);
   }
 
-
-#ifdef TARGET_ARCH_x86
-# include "methodHandles_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "methodHandles_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "methodHandles_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "methodHandles_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "methodHandles_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "methodHandles_aarch64.hpp"
-#endif
+#include CPU_HEADER(methodHandles)
 
   // Tracing
   static void trace_method_handle(MacroAssembler* _masm, const char* adaptername) PRODUCT_RETURN;
--- a/hotspot/src/share/vm/prims/stackwalk.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/prims/stackwalk.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
--- a/hotspot/src/share/vm/prims/stackwalk.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/prims/stackwalk.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -85,7 +85,6 @@
 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
 int    Arguments::_sun_java_launcher_pid        = -1;
 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
-int    Arguments::_bootclassloader_append_index = -1;
 
 // These parameters are reset in method parse_vm_init_args()
 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
@@ -113,6 +112,7 @@
 
 GrowableArray<ModuleXPatchPath*> *Arguments::_xpatchprefix = NULL;
 PathString *Arguments::_system_boot_class_path = NULL;
+bool Arguments::_has_jimage = false;
 
 char* Arguments::_ext_dirs = NULL;
 
@@ -1305,6 +1305,11 @@
     }
     sp = sp->next();
   }
+
+  // Check for an exploded module build in use with -Xshare:dump.
+  if (!has_jimage()) {
+    vm_exit_during_initialization("Dumping the shared archive is not supported with an exploded module build");
+  }
 }
 #endif
 
@@ -1779,11 +1784,7 @@
     if (should_auto_select_low_pause_collector()) {
       FLAG_SET_ERGO_IF_DEFAULT(bool, UseConcMarkSweepGC, true);
     } else {
-#if defined(JAVASE_EMBEDDED)
-      FLAG_SET_ERGO_IF_DEFAULT(bool, UseParallelGC, true);
-#else
       FLAG_SET_ERGO_IF_DEFAULT(bool, UseG1GC, true);
-#endif
     }
   } else {
     FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
@@ -2676,7 +2677,6 @@
         return JNI_EINVAL;
     // -bootclasspath/a:
     } else if (match_option(option, "-Xbootclasspath/a:", &tail)) {
-      Arguments::set_bootclassloader_append_index((int)strlen(Arguments::get_sysclasspath())+1);
       Arguments::append_sysclasspath(tail);
     // -bootclasspath/p:
     } else if (match_option(option, "-Xbootclasspath/p:", &tail)) {
@@ -3323,18 +3323,6 @@
   _xpatchprefix->push(new ModuleXPatchPath(module_name, path));
 }
 
-// Set property jdk.boot.class.path.append to the contents of the bootclasspath
-// that follows either the jimage file or exploded module directories.  The
-// property will contain -Xbootclasspath/a and/or jvmti appended additions.
-void Arguments::set_jdkbootclasspath_append() {
-  char *sysclasspath = get_sysclasspath();
-  assert(sysclasspath != NULL, "NULL sysclasspath");
-  int bcp_a_idx = bootclassloader_append_index();
-  if (bcp_a_idx != -1 && bcp_a_idx < (int)strlen(sysclasspath)) {
-    _jdk_boot_class_path_append->set_value(sysclasspath + bcp_a_idx);
-  }
-}
-
 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
 //
 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
@@ -3457,8 +3445,6 @@
     return JNI_ERR;
   }
 
-  Arguments::set_bootclassloader_append_index(((int)strlen(Arguments::get_sysclasspath()))+1);
-
   // This must be done after all arguments have been processed.
   // java_compiler() true means set to "NONE" or empty.
   if (java_compiler() && !xdebug_mode()) {
--- a/hotspot/src/share/vm/runtime/arguments.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/arguments.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -363,6 +363,9 @@
   // -Xbootclasspath/p was supported.
   static PathString *_system_boot_class_path;
 
+  // Set if a modular java runtime image is present vs. a build with exploded modules
+  static bool _has_jimage;
+
   // temporary: to emit warning if the default ext dirs are not empty.
   // remove this variable when the warning is no longer needed.
   static char* _ext_dirs;
@@ -411,11 +414,6 @@
   static void set_java_compiler(bool arg) { _java_compiler = arg; }
   static bool java_compiler()   { return _java_compiler; }
 
-  // Capture the index location of -Xbootclasspath\a within sysclasspath.
-  // Used when setting up the bootstrap search path in order to
-  // mark the boot loader's append path observability boundary.
-  static int _bootclassloader_append_index;
-
   // -Xdebug flag
   static bool _xdebug_mode;
   static void set_xdebug_mode(bool arg) { _xdebug_mode = arg; }
@@ -669,17 +667,6 @@
   static size_t min_heap_size()             { return _min_heap_size; }
   static void  set_min_heap_size(size_t v)  { _min_heap_size = v;  }
 
-  // -Xbootclasspath/a
-  static int  bootclassloader_append_index() {
-    return _bootclassloader_append_index;
-  }
-  static void set_bootclassloader_append_index(int value) {
-    // Set only if the index has not been set yet
-    if (_bootclassloader_append_index == -1) {
-      _bootclassloader_append_index = value;
-    }
-  }
-
   // -Xrun
   static AgentLibrary* libraries()          { return _libraryList.first(); }
   static bool init_libraries_at_startup()   { return !_libraryList.is_empty(); }
@@ -739,19 +726,21 @@
 
   // Set up the underlying pieces of the system boot class path
   static void add_xpatchprefix(const char *module_name, const char *path, bool* xpatch_javabase);
-  static void set_sysclasspath(const char *value) {
+  static void set_sysclasspath(const char *value, bool has_jimage) {
+    // During start up, set by os::set_boot_path()
+    assert(get_sysclasspath() == NULL, "System boot class path previously set");
     _system_boot_class_path->set_value(value);
-    set_jdkbootclasspath_append();
+    _has_jimage = has_jimage;
   }
   static void append_sysclasspath(const char *value) {
     _system_boot_class_path->append_value(value);
-    set_jdkbootclasspath_append();
+    _jdk_boot_class_path_append->append_value(value);
   }
-  static void set_jdkbootclasspath_append();
 
   static GrowableArray<ModuleXPatchPath*>* get_xpatchprefix() { return _xpatchprefix; }
   static char* get_sysclasspath() { return _system_boot_class_path->value(); }
   static char* get_jdk_boot_class_path_append() { return _jdk_boot_class_path_append->value(); }
+  static bool has_jimage() { return _has_jimage; }
 
   static char* get_java_home()    { return _java_home->value(); }
   static char* get_dll_dir()      { return _sun_boot_library_path->value(); }
--- a/hotspot/src/share/vm/runtime/atomic.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/atomic.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,52 +26,9 @@
 #define SHARE_VM_RUNTIME_ATOMIC_INLINE_HPP
 
 #include "runtime/atomic.hpp"
-
-// Linux
-#ifdef TARGET_OS_ARCH_linux_x86
-# include "atomic_linux_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_sparc
-# include "atomic_linux_sparc.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_zero
-# include "atomic_linux_zero.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_arm
-# include "atomic_linux_arm.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_ppc
-# include "atomic_linux_ppc.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_aarch64
-# include "atomic_linux_aarch64.inline.hpp"
-#endif
+#include "utilities/macros.hpp"
 
-// Solaris
-#ifdef TARGET_OS_ARCH_solaris_x86
-# include "atomic_solaris_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_sparc
-# include "atomic_solaris_sparc.inline.hpp"
-#endif
-
-// Windows
-#ifdef TARGET_OS_ARCH_windows_x86
-# include "atomic_windows_x86.inline.hpp"
-#endif
-
-// AIX
-#ifdef TARGET_OS_ARCH_aix_ppc
-# include "atomic_aix_ppc.inline.hpp"
-#endif
-
-// BSD
-#ifdef TARGET_OS_ARCH_bsd_x86
-# include "atomic_bsd_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_zero
-# include "atomic_bsd_zero.inline.hpp"
-#endif
+#include OS_CPU_HEADER_INLINE(atomic)
 
 // size_t casts...
 #if (SIZE_MAX != UINTPTR_MAX)
--- a/hotspot/src/share/vm/runtime/frame.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/frame.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -29,7 +29,8 @@
 #include "runtime/basicLock.hpp"
 #include "runtime/monitorChunk.hpp"
 #include "runtime/registerMap.hpp"
-#ifdef TARGET_ARCH_zero
+#include "utilities/macros.hpp"
+#ifdef ZERO
 # include "stack_zero.hpp"
 #endif
 
@@ -415,24 +416,7 @@
 
   int pd_oop_map_offset_adjustment() const;
 
-#ifdef TARGET_ARCH_x86
-# include "frame_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "frame_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "frame_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "frame_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "frame_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "frame_aarch64.hpp"
-#endif
+#include CPU_HEADER(frame)
 
 };
 
--- a/hotspot/src/share/vm/runtime/frame.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/frame.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,13 +31,16 @@
 #include "oops/method.hpp"
 #include "runtime/frame.hpp"
 #include "runtime/signature.hpp"
-#ifdef TARGET_ARCH_zero
+#include "utilities/macros.hpp"
+#ifdef ZERO
 # include "entryFrame_zero.hpp"
 # include "fakeStubFrame_zero.hpp"
 # include "interpreterFrame_zero.hpp"
 # include "sharkFrame_zero.hpp"
 #endif
 
+#include CPU_HEADER_INLINE(frame)
+
 inline bool frame::is_entry_frame() const {
   return StubRoutines::returns_to_call_stub(pc());
 }
@@ -50,26 +53,4 @@
   return is_entry_frame() && entry_frame_is_first();
 }
 
-// here are the platform-dependent bodies:
-
-#ifdef TARGET_ARCH_x86
-# include "frame_x86.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "frame_sparc.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "frame_zero.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "frame_arm.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "frame_ppc.inline.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "frame_aarch64.inline.hpp"
-#endif
-
-
 #endif // SHARE_VM_RUNTIME_FRAME_INLINE_HPP
--- a/hotspot/src/share/vm/runtime/globals.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/globals.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -334,7 +334,8 @@
 
 void Flag::set_origin(Flags origin) {
   assert((origin & VALUE_ORIGIN_MASK) == origin, "sanity");
-  _flags = Flags((_flags & ~VALUE_ORIGIN_MASK) | origin);
+  Flags new_origin = Flags((origin == COMMAND_LINE) ? Flags(origin | ORIG_COMMAND_LINE) : origin);
+  _flags = Flags((_flags & ~VALUE_ORIGIN_MASK) | new_origin);
 }
 
 bool Flag::is_default() {
@@ -346,7 +347,11 @@
 }
 
 bool Flag::is_command_line() {
-  return (get_origin() == COMMAND_LINE);
+  return (_flags & ORIG_COMMAND_LINE) != 0;
+}
+
+void Flag::set_command_line() {
+  _flags = Flags(_flags | ORIG_COMMAND_LINE);
 }
 
 bool Flag::is_product() const {
@@ -464,25 +469,31 @@
   }
 
   if (!printRanges) {
-
-    st->print("%9s %-40s %c= ", _type, _name, (!is_default() ? ':' : ' '));
+    // The print below assumes that the flag name is 40 characters or less.
+    // This works for most flags, but there are exceptions. Our longest flag
+    // name right now is UseAdaptiveGenerationSizePolicyAtMajorCollection and
+    // its minor collection buddy. These are 48 characters. We use a buffer of
+    // 10 spaces below to adjust the space between the flag value and the
+    // column of flag type and origin that is printed in the end of the line.
+    char spaces[10 + 1] = "          ";
+    st->print("%9s %-40s = ", _type, _name);
 
     if (is_bool()) {
-      st->print("%-16s", get_bool() ? "true" : "false");
+      st->print("%-20s", get_bool() ? "true" : "false");
     } else if (is_int()) {
-      st->print("%-16d", get_int());
+      st->print("%-20d", get_int());
     } else if (is_uint()) {
-      st->print("%-16u", get_uint());
+      st->print("%-20u", get_uint());
     } else if (is_intx()) {
-      st->print(INTX_FORMAT_W(-16), get_intx());
+      st->print(INTX_FORMAT_W(-20), get_intx());
     } else if (is_uintx()) {
-      st->print(UINTX_FORMAT_W(-16), get_uintx());
+      st->print(UINTX_FORMAT_W(-20), get_uintx());
     } else if (is_uint64_t()) {
-      st->print(UINT64_FORMAT_W(-16), get_uint64_t());
+      st->print(UINT64_FORMAT_W(-20), get_uint64_t());
     } else if (is_size_t()) {
-      st->print(SIZE_FORMAT_W(-16), get_size_t());
+      st->print(SIZE_FORMAT_W(-20), get_size_t());
     } else if (is_double()) {
-      st->print("%-16f", get_double());
+      st->print("%-20f", get_double());
     } else if (is_ccstr()) {
       const char* cp = get_ccstr();
       if (cp != NULL) {
@@ -494,13 +505,14 @@
           cp = eol+1;
           st->print("%5s %-35s += ", "", _name);
         }
-        st->print("%-16s", cp);
+        st->print("%-20s", cp);
       }
-      else st->print("%-16s", "");
+      else st->print("%-20s", "");
     }
-
-    st->print("%-20s", " ");
-    print_kind(st);
+    assert(strlen(_name) < 50, "Flag name is longer than expected");
+    spaces[50 - MAX2((size_t)40, strlen(_name))] = '\0';
+    st->print("%s", spaces);
+    print_kind_and_origin(st);
 
 #ifndef PRODUCT
     if (withComments) {
@@ -533,8 +545,8 @@
     }
     CommandLineFlagRangeList::print(st, _name, func);
 
-    st->print(" %-20s", " ");
-    print_kind(st);
+    st->print(" %-16s", " ");
+    print_kind_and_origin(st);
 
 #ifndef PRODUCT
     if (withComments) {
@@ -546,7 +558,7 @@
   }
 }
 
-void Flag::print_kind(outputStream* st) {
+void Flag::print_kind_and_origin(outputStream* st) {
   struct Data {
     int flag;
     const char* name;
@@ -572,23 +584,58 @@
   };
 
   if ((_flags & KIND_MASK) != 0) {
-    st->print("{");
     bool is_first = true;
+    const size_t buffer_size = 64;
+    size_t buffer_used = 0;
+    char kind[buffer_size];
 
+    jio_snprintf(kind, buffer_size, "{");
+    buffer_used++;
     for (int i = 0; data[i].flag != -1; i++) {
       Data d = data[i];
       if ((_flags & d.flag) != 0) {
         if (is_first) {
           is_first = false;
         } else {
-          st->print(" ");
+          assert(buffer_used + 1 < buffer_size, "Too small buffer");
+          jio_snprintf(kind + buffer_used, buffer_size - buffer_used, " ");
+          buffer_used++;
         }
-        st->print("%s", d.name);
+        size_t length = strlen(d.name);
+        assert(buffer_used + length < buffer_size, "Too small buffer");
+        jio_snprintf(kind + buffer_used, buffer_size - buffer_used, "%s", d.name);
+        buffer_used += length;
       }
     }
+    assert(buffer_used + 2 <= buffer_size, "Too small buffer");
+    jio_snprintf(kind + buffer_used, buffer_size - buffer_used, "}");
+    st->print("%20s", kind);
+  }
 
-    st->print("}");
+  int origin = _flags & VALUE_ORIGIN_MASK;
+  st->print(" {");
+  switch(origin) {
+    case DEFAULT:
+      st->print("default"); break;
+    case COMMAND_LINE:
+      st->print("command line"); break;
+    case ENVIRON_VAR:
+      st->print("environment"); break;
+    case CONFIG_FILE:
+      st->print("config file"); break;
+    case MANAGEMENT:
+      st->print("management"); break;
+    case ERGONOMIC:
+      if (_flags & ORIG_COMMAND_LINE) {
+        st->print("command line, ");
+      }
+      st->print("ergonomic"); break;
+    case ATTACH_ON_DEMAND:
+      st->print("attach"); break;
+    case INTERNAL:
+      st->print("internal"); break;
   }
+  st->print("}");
 }
 
 void Flag::print_as_flag(outputStream* st) {
@@ -918,6 +965,12 @@
   return true;
 }
 
+void CommandLineFlagsEx::setOnCmdLine(CommandLineFlagWithType flag) {
+  Flag* faddr = address_of_flag(flag);
+  assert(faddr != NULL, "Unknown flag");
+  faddr->set_command_line();
+}
+
 template<class E, class T>
 static void trace_flag_changed(const char* name, const T old_value, const T new_value, const Flag::Flags origin) {
   E e;
--- a/hotspot/src/share/vm/runtime/globals.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/globals.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -26,6 +26,8 @@
 #define SHARE_VM_RUNTIME_GLOBALS_HPP
 
 #include "utilities/debug.hpp"
+#include "utilities/macros.hpp"
+
 #include <float.h> // for DBL_MAX
 
 // use this for flags that are true per default in the tiered build
@@ -38,141 +40,19 @@
 #define falseInTiered true
 #endif
 
-#ifdef TARGET_ARCH_x86
-# include "globals_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "globals_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "globals_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "globals_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "globals_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "globals_aarch64.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_linux
-# include "globals_linux.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "globals_solaris.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "globals_windows.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "globals_aix.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "globals_bsd.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_x86
-# include "globals_linux_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_sparc
-# include "globals_linux_sparc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_zero
-# include "globals_linux_zero.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_x86
-# include "globals_solaris_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_sparc
-# include "globals_solaris_sparc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_windows_x86
-# include "globals_windows_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_arm
-# include "globals_linux_arm.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_ppc
-# include "globals_linux_ppc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_aarch64
-# include "globals_linux_aarch64.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_aix_ppc
-# include "globals_aix_ppc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_x86
-# include "globals_bsd_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_zero
-# include "globals_bsd_zero.hpp"
-#endif
+#include CPU_HEADER(globals)
+#include OS_HEADER(globals)
+#include OS_CPU_HEADER(globals)
 #ifdef COMPILER1
-#ifdef TARGET_ARCH_x86
-# include "c1_globals_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "c1_globals_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "c1_globals_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "c1_globals_aarch64.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_linux
-# include "c1_globals_linux.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "c1_globals_solaris.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "c1_globals_windows.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "c1_globals_aix.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "c1_globals_bsd.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "c1_globals_ppc.hpp"
-#endif
+#include CPU_HEADER(c1_globals)
+#include OS_HEADER(c1_globals)
 #endif
 #ifdef COMPILER2
-#ifdef TARGET_ARCH_x86
-# include "c2_globals_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "c2_globals_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "c2_globals_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "c2_globals_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "c2_globals_aarch64.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_linux
-# include "c2_globals_linux.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "c2_globals_solaris.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "c2_globals_windows.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "c2_globals_aix.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "c2_globals_bsd.hpp"
-#endif
+#include CPU_HEADER(c2_globals)
+#include OS_HEADER(c2_globals)
 #endif
 #ifdef SHARK
-#ifdef TARGET_ARCH_zero
+#ifdef ZERO
 # include "shark_globals_zero.hpp"
 #endif
 #endif
@@ -229,7 +109,7 @@
 
 struct Flag {
   enum Flags {
-    // value origin
+    // latest value origin
     DEFAULT          = 0,
     COMMAND_LINE     = 1,
     ENVIRON_VAR      = 2,
@@ -260,7 +140,10 @@
     KIND_COMMERCIAL         = 1 << 17,
     KIND_JVMCI              = 1 << 18,
 
-    KIND_MASK = ~VALUE_ORIGIN_MASK
+    // set this bit if the flag was set on the command line
+    ORIG_COMMAND_LINE       = 1 << 19,
+
+    KIND_MASK = ~(VALUE_ORIGIN_MASK | ORIG_COMMAND_LINE)
   };
 
   enum Error {
@@ -272,7 +155,7 @@
     MISSING_VALUE,
     // error parsing the textual form of the value
     WRONG_FORMAT,
-    // flag is not writeable
+    // flag is not writable
     NON_WRITABLE,
     // flag value is outside of its bounds
     OUT_OF_BOUNDS,
@@ -367,6 +250,7 @@
   bool is_default();
   bool is_ergonomic();
   bool is_command_line();
+  void set_command_line();
 
   bool is_product() const;
   bool is_manageable() const;
@@ -396,7 +280,7 @@
 
   // printRanges will print out flags type, name and range values as expected by -XX:+PrintFlagsRanges
   void print_on(outputStream* st, bool withComments = false, bool printRanges = false);
-  void print_kind(outputStream* st);
+  void print_kind_and_origin(outputStream* st);
   void print_as_flag(outputStream* st);
 
   static const char* flag_error_str(Flag::Error error);
@@ -574,12 +458,6 @@
 #define falseInProduct true
 #endif
 
-#ifdef JAVASE_EMBEDDED
-#define falseInEmbedded false
-#else
-#define falseInEmbedded true
-#endif
-
 // develop flags are settable / visible only during development and are constant in the PRODUCT version
 // product flags are always settable / visible
 // notproduct flags are settable / visible only during development and are not declared in the PRODUCT version
@@ -708,7 +586,7 @@
   product_pd(bool, UseMembar,                                               \
           "(Unstable) Issues membars on thread state transitions")          \
                                                                             \
-  develop(bool, CleanChunkPoolAsync, falseInEmbedded,                       \
+  develop(bool, CleanChunkPoolAsync, true,                                  \
           "Clean the chunk pool asynchronously")                            \
                                                                             \
   experimental(bool, AlwaysSafeConstructors, false,                         \
@@ -3006,15 +2884,10 @@
                                                                             \
   /* notice: the max range value here is max_jint, not max_intx  */         \
   /* because of overflow issue                                   */         \
-  NOT_EMBEDDED(diagnostic(intx, GuaranteedSafepointInterval, 1000,          \
+  diagnostic(intx, GuaranteedSafepointInterval, 1000,                       \
           "Guarantee a safepoint (at least) every so many milliseconds "    \
-          "(0 means none)"))                                                \
-  NOT_EMBEDDED(range(0, max_jint))                                          \
-                                                                            \
-  EMBEDDED_ONLY(product(intx, GuaranteedSafepointInterval, 0,               \
-          "Guarantee a safepoint (at least) every so many milliseconds "    \
-          "(0 means none)"))                                                \
-  EMBEDDED_ONLY(range(0, max_jint))                                         \
+          "(0 means none)")                                                 \
+          range(0, max_jint)                                                \
                                                                             \
   product(intx, SafepointTimeoutDelay, 10000,                               \
           "Delay in milliseconds for option SafepointTimeout")              \
@@ -3916,7 +3789,7 @@
                                                                             \
   /* flags for performance data collection */                               \
                                                                             \
-  product(bool, UsePerfData, falseInEmbedded,                               \
+  product(bool, UsePerfData, true,                                          \
           "Flag to disable jvmstat instrumentation for performance testing "\
           "and problem isolation purposes")                                 \
                                                                             \
--- a/hotspot/src/share/vm/runtime/globals_extension.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/globals_extension.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -334,8 +334,9 @@
 
 #define FLAG_SET_DEFAULT(name, value) ((name) = (value))
 
-#define FLAG_SET_CMDLINE(type, name, value) (CommandLineFlagsEx::type##AtPut(FLAG_MEMBER_WITH_TYPE(name,type), (type)(value), Flag::COMMAND_LINE))
-#define FLAG_SET_ERGO(type, name, value)    (CommandLineFlagsEx::type##AtPut(FLAG_MEMBER_WITH_TYPE(name,type), (type)(value), Flag::ERGONOMIC))
+#define FLAG_SET_CMDLINE(type, name, value) (CommandLineFlagsEx::setOnCmdLine(FLAG_MEMBER_WITH_TYPE(name, type)), \
+                                             CommandLineFlagsEx::type##AtPut(FLAG_MEMBER_WITH_TYPE(name, type), (type)(value), Flag::COMMAND_LINE))
+#define FLAG_SET_ERGO(type, name, value)    (CommandLineFlagsEx::type##AtPut(FLAG_MEMBER_WITH_TYPE(name, type), (type)(value), Flag::ERGONOMIC))
 #define FLAG_SET_ERGO_IF_DEFAULT(type, name, value) \
   do {                                              \
     if (FLAG_IS_DEFAULT(name)) {                    \
@@ -361,6 +362,8 @@
   static bool is_default(CommandLineFlag flag);
   static bool is_ergo(CommandLineFlag flag);
   static bool is_cmdline(CommandLineFlag flag);
+
+  static void setOnCmdLine(CommandLineFlagWithType flag);
 };
 
 #endif // SHARE_VM_RUNTIME_GLOBALS_EXTENSION_HPP
--- a/hotspot/src/share/vm/runtime/icache.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/icache.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 
 #include "memory/allocation.hpp"
 #include "runtime/stubCodeGenerator.hpp"
+#include "utilities/macros.hpp"
 
 // Interface for updating the instruction cache.  Whenever the VM modifies
 // code, part of the processor instruction cache potentially has to be flushed.
@@ -68,26 +69,7 @@
 // Must be included before the definition of ICacheStubGenerator
 // because ICacheStubGenerator uses ICache definitions.
 
-#ifdef TARGET_ARCH_x86
-# include "icache_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "icache_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "icache_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "icache_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "icache_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "icache_aarch64.hpp"
-#endif
-
-
+#include CPU_HEADER(icache)
 
 class ICacheStubGenerator : public StubCodeGenerator {
  public:
--- a/hotspot/src/share/vm/runtime/init.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/init.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -53,7 +53,6 @@
 void management_init();
 void bytecodes_init();
 void classLoader_init1();
-void classLoader_init2(); // note: ClassLoader need 2-phase init
 void compilationPolicy_init();
 void codeCache_init();
 void VM_Version_init();
@@ -117,7 +116,6 @@
   if (status != JNI_OK)
     return status;
 
-  classLoader_init2();  // after SymbolTable creation, set up -Xpatch entries
   CodeCacheExtensions::complete_step(CodeCacheExtensionsSteps::Universe);
   interpreter_init();  // before any methods loaded
   CodeCacheExtensions::complete_step(CodeCacheExtensionsSteps::Interpreter);
--- a/hotspot/src/share/vm/runtime/interfaceSupport.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/interfaceSupport.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -34,6 +34,7 @@
 #include "runtime/thread.inline.hpp"
 #include "runtime/vmThread.hpp"
 #include "utilities/globalDefinitions.hpp"
+#include "utilities/macros.hpp"
 #include "utilities/preserveException.hpp"
 
 // Wrapper for all entry points to the virtual machine.
@@ -90,21 +91,8 @@
 
  public:
   // OS dependent stuff
-#ifdef TARGET_OS_FAMILY_linux
-# include "interfaceSupport_linux.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "interfaceSupport_solaris.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "interfaceSupport_windows.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "interfaceSupport_aix.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "interfaceSupport_bsd.hpp"
-#endif
+
+#include OS_HEADER(interfaceSupport)
 
 };
 
--- a/hotspot/src/share/vm/runtime/javaCalls.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/javaCalls.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,24 +31,9 @@
 #include "runtime/javaFrameAnchor.hpp"
 #include "runtime/thread.hpp"
 #include "runtime/vmThread.hpp"
-#ifdef TARGET_ARCH_x86
-# include "jniTypes_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "jniTypes_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "jniTypes_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "jniTypes_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "jniTypes_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "jniTypes_aarch64.hpp"
-#endif
+#include "utilities/macros.hpp"
+
+#include CPU_HEADER(jniTypes)
 
 // A JavaCallWrapper is constructed before each JavaCall and destructed after the call.
 // Its purpose is to allocate/deallocate a new handle block and to save/restore the last
--- a/hotspot/src/share/vm/runtime/javaFrameAnchor.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/javaFrameAnchor.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,8 +25,9 @@
 #ifndef SHARE_VM_RUNTIME_JAVAFRAMEANCHOR_HPP
 #define SHARE_VM_RUNTIME_JAVAFRAMEANCHOR_HPP
 
+#include "runtime/orderAccess.inline.hpp"
 #include "utilities/globalDefinitions.hpp"
-#include "runtime/orderAccess.inline.hpp"
+#include "utilities/macros.hpp"
 
 //
 // An object for encapsulating the machine/os dependent part of a JavaThread frame state
@@ -77,25 +78,7 @@
   // and no one should look at the other fields.
   void zap(void)                                     { _last_Java_sp = NULL; }
 
-#ifdef TARGET_ARCH_x86
-# include "javaFrameAnchor_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "javaFrameAnchor_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "javaFrameAnchor_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "javaFrameAnchor_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "javaFrameAnchor_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "javaFrameAnchor_aarch64.hpp"
-#endif
-
+#include CPU_HEADER(javaFrameAnchor)
 
 public:
   JavaFrameAnchor()                              { clear(); }
--- a/hotspot/src/share/vm/runtime/mutex.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/mutex.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -30,18 +30,7 @@
 #include "runtime/osThread.hpp"
 #include "runtime/thread.inline.hpp"
 #include "utilities/events.hpp"
-#ifdef TARGET_OS_FAMILY_linux
-# include "mutex_linux.inline.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "mutex_solaris.inline.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "mutex_windows.inline.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "mutex_bsd.inline.hpp"
-#endif
+#include "utilities/macros.hpp"
 
 // o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
 //
--- a/hotspot/src/share/vm/runtime/orderAccess.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/orderAccess.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2014 SAP SE. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -28,52 +28,9 @@
 
 #include "runtime/atomic.inline.hpp"
 #include "runtime/orderAccess.hpp"
-
-// Linux
-#ifdef TARGET_OS_ARCH_linux_x86
-# include "orderAccess_linux_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_sparc
-# include "orderAccess_linux_sparc.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_zero
-# include "orderAccess_linux_zero.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_arm
-# include "orderAccess_linux_arm.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_aarch64
-# include "orderAccess_linux_aarch64.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_ppc
-# include "orderAccess_linux_ppc.inline.hpp"
-#endif
+#include "utilities/macros.hpp"
 
-// Solaris
-#ifdef TARGET_OS_ARCH_solaris_x86
-# include "orderAccess_solaris_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_sparc
-# include "orderAccess_solaris_sparc.inline.hpp"
-#endif
-
-// Windows
-#ifdef TARGET_OS_ARCH_windows_x86
-# include "orderAccess_windows_x86.inline.hpp"
-#endif
-
-// AIX
-#ifdef TARGET_OS_ARCH_aix_ppc
-# include "orderAccess_aix_ppc.inline.hpp"
-#endif
-
-// BSD
-#ifdef TARGET_OS_ARCH_bsd_x86
-# include "orderAccess_bsd_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_zero
-# include "orderAccess_bsd_zero.inline.hpp"
-#endif
+#include OS_CPU_HEADER_INLINE(orderAccess)
 
 #ifdef VM_HAS_GENERALIZED_ORDER_ACCESS
 
--- a/hotspot/src/share/vm/runtime/os.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/os.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -71,6 +71,7 @@
 uintptr_t         os::_serialize_page_mask = 0;
 long              os::_rand_seed          = 1;
 int               os::_processor_count    = 0;
+int               os::_initial_active_processor_count = 0;
 size_t            os::_page_sizes[os::page_sizes_max];
 
 #ifndef PRODUCT
@@ -315,6 +316,7 @@
 }
 
 void os::init_before_ergo() {
+  initialize_initial_active_processor_count();
   // We need to initialize large page support here because ergonomics takes some
   // decisions depending on large page support and the calculated large page size.
   large_page_init();
@@ -829,7 +831,11 @@
   st->print("CPU:");
   st->print("total %d", os::processor_count());
   // It's not safe to query number of active processors after crash
-  // st->print("(active %d)", os::active_processor_count());
+  // st->print("(active %d)", os::active_processor_count()); but we can
+  // print the initial number of active processors.
+  // We access the raw value here because the assert in the accessor will
+  // fail if the crash occurs before initialization of this value.
+  st->print(" (initial active %d)", _initial_active_processor_count);
   st->print(" %s", VM_Version::features_string());
   st->cr();
   pd_print_cpu_info(st, buf, buflen);
@@ -1207,7 +1213,7 @@
   if (jimage == NULL) return false;
   bool has_jimage = (os::stat(jimage, &st) == 0);
   if (has_jimage) {
-    Arguments::set_sysclasspath(jimage);
+    Arguments::set_sysclasspath(jimage, true);
     FREE_C_HEAP_ARRAY(char, jimage);
     return true;
   }
@@ -1217,7 +1223,7 @@
   char* base_classes = format_boot_path("%/modules/java.base", home, home_len, fileSep, pathSep);
   if (base_classes == NULL) return false;
   if (os::stat(base_classes, &st) == 0) {
-    Arguments::set_sysclasspath(base_classes);
+    Arguments::set_sysclasspath(base_classes, false);
     FREE_C_HEAP_ARRAY(char, base_classes);
     return true;
   }
@@ -1597,6 +1603,12 @@
   return result;
 }
 
+void os::initialize_initial_active_processor_count() {
+  assert(_initial_active_processor_count == 0, "Initial active processor count already set.");
+  _initial_active_processor_count = active_processor_count();
+  log_debug(os)("Initial active processor count set to %d" , _initial_active_processor_count);
+}
+
 void os::SuspendedThreadTask::run() {
   assert(Threads_lock->owned_by_self() || (_thread == VMThread::vm_thread()), "must have threads lock to call this");
   internal_do_task();
@@ -1742,7 +1754,7 @@
   pd_realign_memory(addr, bytes, alignment_hint);
 }
 
-#ifndef TARGET_OS_FAMILY_windows
+#ifndef _WINDOWS
 /* try to switch state from state "from" to state "to"
  * returns the state set after the method is complete
  */
--- a/hotspot/src/share/vm/runtime/os.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/os.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -26,29 +26,15 @@
 #define SHARE_VM_RUNTIME_OS_HPP
 
 #include "jvmtifiles/jvmti.h"
+#include "prims/jvm.h"
 #include "runtime/extendedPC.hpp"
 #include "runtime/handles.hpp"
-#ifdef TARGET_OS_FAMILY_linux
-# include "jvm_linux.h"
-# include <setjmp.h>
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "jvm_solaris.h"
+#include "utilities/macros.hpp"
+#ifndef _WINDOWS
 # include <setjmp.h>
 #endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "jvm_windows.h"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "jvm_aix.h"
-# include <setjmp.h>
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "jvm_bsd.h"
-# include <setjmp.h>
-# ifdef __APPLE__
-#  include <mach/mach_time.h>
-# endif
+#ifdef __APPLE__
+# include <mach/mach_time.h>
 #endif
 
 class AgentLibrary;
@@ -154,6 +140,7 @@
   static void  get_summary_cpu_info(char* buf, size_t buflen);
   static void  get_summary_os_info(char* buf, size_t buflen);
 
+  static void initialize_initial_active_processor_count();
  public:
   static void init(void);                      // Called before command line parsing
   static void init_before_ergo(void);          // Called after command line parsing
@@ -241,6 +228,13 @@
   // Note that on some OSes this can change dynamically.
   static int active_processor_count();
 
+  // At startup the number of active CPUs this process is allowed to run on.
+  // This value does not change dynamically. May be different from active_processor_count().
+  static int initial_active_processor_count() {
+    assert(_initial_active_processor_count > 0, "Initial active processor count not set yet.");
+    return _initial_active_processor_count;
+  }
+
   // Bind processes to processors.
   //     This is a two step procedure:
   //     first you generate a distribution of processes to processors,
@@ -816,61 +810,11 @@
   };
 
   // Platform dependent stuff
-#ifdef TARGET_OS_FAMILY_linux
-# include "os_linux.hpp"
-# include "os_posix.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "os_solaris.hpp"
-# include "os_posix.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "os_windows.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "os_aix.hpp"
+#ifndef _WINDOWS
 # include "os_posix.hpp"
 #endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "os_posix.hpp"
-# include "os_bsd.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_x86
-# include "os_linux_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_sparc
-# include "os_linux_sparc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_zero
-# include "os_linux_zero.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_x86
-# include "os_solaris_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_sparc
-# include "os_solaris_sparc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_windows_x86
-# include "os_windows_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_arm
-# include "os_linux_arm.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_ppc
-# include "os_linux_ppc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_aix_ppc
-# include "os_aix_ppc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_aarch64
-# include "os_linux_aarch64.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_x86
-# include "os_bsd_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_zero
-# include "os_bsd_zero.hpp"
-#endif
+#include OS_CPU_HEADER(os)
+#include OS_HEADER(os)
 
 #ifndef OS_NATIVE_THREAD_CREATION_FAILED_MSG
 #define OS_NATIVE_THREAD_CREATION_FAILED_MSG "unable to create native thread: possibly out of memory or process/resource limits reached"
@@ -937,7 +881,7 @@
     bool _done;
   };
 
-#ifndef TARGET_OS_FAMILY_windows
+#ifndef _WINDOWS
   // Suspend/resume support
   // Protocol:
   //
@@ -1008,12 +952,13 @@
       return _state == SR_SUSPENDED;
     }
   };
-#endif
+#endif // !WINDOWS
 
 
  protected:
-  static long _rand_seed;                   // seed for random number generator
-  static int _processor_count;              // number of processors
+  static long _rand_seed;                     // seed for random number generator
+  static int _processor_count;                // number of processors
+  static int _initial_active_processor_count; // number of active processors during initialization.
 
   static char* format_boot_path(const char* format_string,
                                 const char* home,
--- a/hotspot/src/share/vm/runtime/os.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/os.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,20 +27,6 @@
 
 #include "runtime/os.hpp"
 
-#ifdef TARGET_OS_FAMILY_linux
-# include "os_linux.inline.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "os_solaris.inline.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "os_windows.inline.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "os_aix.inline.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "os_bsd.inline.hpp"
-#endif
+#include OS_HEADER_INLINE(os)
 
 #endif // SHARE_VM_RUNTIME_OS_INLINE_HPP
--- a/hotspot/src/share/vm/runtime/osThread.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/osThread.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
 #include "runtime/handles.hpp"
 #include "runtime/javaFrameAnchor.hpp"
 #include "runtime/objectMonitor.hpp"
+#include "utilities/macros.hpp"
 
 // The OSThread class holds OS-specific thread information.  It is equivalent
 // to the sys_thread_t structure of the classic JVM implementation.
@@ -96,21 +97,7 @@
   static ByteSize interrupted_offset()            { return byte_offset_of(OSThread, _interrupted); }
 
   // Platform dependent stuff
-#ifdef TARGET_OS_FAMILY_linux
-# include "osThread_linux.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "osThread_solaris.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "osThread_windows.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "osThread_aix.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "osThread_bsd.hpp"
-#endif
+#include OS_HEADER(osThread)
 
  public:
   static ByteSize thread_id_offset()              { return byte_offset_of(OSThread, _thread_id); }
--- a/hotspot/src/share/vm/runtime/prefetch.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/prefetch.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,51 +26,7 @@
 #define SHARE_VM_RUNTIME_PREFETCH_INLINE_HPP
 
 #include "runtime/prefetch.hpp"
-
-// Linux
-#ifdef TARGET_OS_ARCH_linux_x86
-# include "prefetch_linux_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_sparc
-# include "prefetch_linux_sparc.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_zero
-# include "prefetch_linux_zero.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_arm
-# include "prefetch_linux_arm.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_aarch64
-# include "prefetch_linux_aarch64.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_ppc
-# include "prefetch_linux_ppc.inline.hpp"
-#endif
-
-// Solaris
-#ifdef TARGET_OS_ARCH_solaris_x86
-# include "prefetch_solaris_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_sparc
-# include "prefetch_solaris_sparc.inline.hpp"
-#endif
-
-// Windows
-#ifdef TARGET_OS_ARCH_windows_x86
-# include "prefetch_windows_x86.inline.hpp"
-#endif
-
-// AIX
-#ifdef TARGET_OS_ARCH_aix_ppc
-# include "prefetch_aix_ppc.inline.hpp"
-#endif
-
-// BSD
-#ifdef TARGET_OS_ARCH_bsd_x86
-# include "prefetch_bsd_x86.inline.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_zero
-# include "prefetch_bsd_zero.inline.hpp"
-#endif
+#include "utilities/macros.hpp"
+#include OS_CPU_HEADER_INLINE(prefetch)
 
 #endif // SHARE_VM_RUNTIME_PREFETCH_INLINE_HPP
--- a/hotspot/src/share/vm/runtime/registerMap.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/registerMap.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 
 #include "code/vmreg.hpp"
 #include "utilities/globalDefinitions.hpp"
+#include "utilities/macros.hpp"
 
 class JavaThread;
 
@@ -120,24 +121,7 @@
   void print() const;
 
   // the following contains the definition of pd_xxx methods
-#ifdef TARGET_ARCH_x86
-# include "registerMap_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "registerMap_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "registerMap_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "registerMap_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "registerMap_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "registerMap_aarch64.hpp"
-#endif
+#include CPU_HEADER(registerMap)
 
 };
 
--- a/hotspot/src/share/vm/runtime/semaphore.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/semaphore.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,11 +27,11 @@
 
 #include "memory/allocation.hpp"
 
-#if defined(TARGET_OS_FAMILY_linux) || defined(TARGET_OS_FAMILY_solaris) || defined(TARGET_OS_FAMILY_aix)
+#if defined(LINUX) || defined(SOLARIS) || defined(AIX)
 # include "semaphore_posix.hpp"
-#elif defined(TARGET_OS_FAMILY_bsd)
+#elif defined(BSD)
 # include "semaphore_bsd.hpp"
-#elif defined(TARGET_OS_FAMILY_windows)
+#elif defined(_WINDOWS)
 # include "semaphore_windows.hpp"
 #else
 # error "No semaphore implementation provided for this OS"
--- a/hotspot/src/share/vm/runtime/stubRoutines.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/stubRoutines.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -30,6 +30,7 @@
 #include "runtime/frame.hpp"
 #include "runtime/mutexLocker.hpp"
 #include "runtime/stubCodeGenerator.hpp"
+#include "utilities/macros.hpp"
 
 // StubRoutines provides entry points to assembly routines used by
 // compiled code and the run-time system. Platform-specific entry
@@ -83,21 +84,8 @@
 
   // Dependencies
   friend class StubGenerator;
-#if defined STUBROUTINES_MD_HPP
-# include STUBROUTINES_MD_HPP
-#elif defined TARGET_ARCH_MODEL_x86_32
-# include "stubRoutines_x86_32.hpp"
-#elif defined TARGET_ARCH_MODEL_x86_64
-# include "stubRoutines_x86_64.hpp"
-#elif defined TARGET_ARCH_MODEL_sparc
-# include "stubRoutines_sparc.hpp"
-#elif defined TARGET_ARCH_MODEL_zero
-# include "stubRoutines_zero.hpp"
-#elif defined TARGET_ARCH_MODEL_ppc_64
-# include "stubRoutines_ppc_64.hpp"
-#elif defined TARGET_ARCH_MODEL_aarch64
-# include "stubRoutines_aarch64.hpp"
-#endif
+
+#include CPU_HEADER(stubRoutines)
 
   static jint    _verify_oop_count;
   static address _verify_oop_subroutine_entry;
--- a/hotspot/src/share/vm/runtime/thread.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/thread.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -50,7 +50,7 @@
 #include "gc/g1/dirtyCardQueue.hpp"
 #include "gc/g1/satbMarkQueue.hpp"
 #endif // INCLUDE_ALL_GCS
-#ifdef TARGET_ARCH_zero
+#ifdef ZERO
 # include "stack_zero.hpp"
 #endif
 
@@ -1905,43 +1905,7 @@
 #endif // INCLUDE_ALL_GCS
 
   // Machine dependent stuff
-#ifdef TARGET_OS_ARCH_linux_x86
-# include "thread_linux_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_sparc
-# include "thread_linux_sparc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_zero
-# include "thread_linux_zero.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_x86
-# include "thread_solaris_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_sparc
-# include "thread_solaris_sparc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_windows_x86
-# include "thread_windows_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_arm
-# include "thread_linux_arm.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_ppc
-# include "thread_linux_ppc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_aarch64
-# include "thread_linux_aarch64.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_aix_ppc
-# include "thread_aix_ppc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_x86
-# include "thread_bsd_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_zero
-# include "thread_bsd_zero.hpp"
-#endif
-
+#include OS_CPU_HEADER(thread)
 
  public:
   void set_blocked_on_compilation(bool value) {
--- a/hotspot/src/share/vm/runtime/vmStructs.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/vmStructs.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -107,77 +107,9 @@
 #include "utilities/hashtable.hpp"
 #include "utilities/macros.hpp"
 
-#ifdef TARGET_OS_FAMILY_linux
-# include "vmStructs_linux.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_solaris
-# include "vmStructs_solaris.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_windows
-# include "vmStructs_windows.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_aix
-# include "vmStructs_aix.hpp"
-#endif
-#ifdef TARGET_OS_FAMILY_bsd
-# include "vmStructs_bsd.hpp"
-#endif
-
-#ifdef TARGET_ARCH_x86
-# include "vmStructs_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "vmStructs_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "vmStructs_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "vmStructs_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "vmStructs_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "vmStructs_aarch64.hpp"
-#endif
-
-#ifdef TARGET_OS_ARCH_linux_x86
-# include "vmStructs_linux_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_sparc
-# include "vmStructs_linux_sparc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_zero
-# include "vmStructs_linux_zero.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_x86
-# include "vmStructs_solaris_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_solaris_sparc
-# include "vmStructs_solaris_sparc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_windows_x86
-# include "vmStructs_windows_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_arm
-# include "vmStructs_linux_arm.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_ppc
-# include "vmStructs_linux_ppc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_linux_aarch64
-# include "vmStructs_linux_aarch64.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_aix_ppc
-# include "vmStructs_aix_ppc.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_x86
-# include "vmStructs_bsd_x86.hpp"
-#endif
-#ifdef TARGET_OS_ARCH_bsd_zero
-# include "vmStructs_bsd_zero.hpp"
-#endif
+#include CPU_HEADER(vmStructs)
+#include OS_HEADER(vmStructs)
+#include OS_CPU_HEADER(vmStructs)
 
 #if INCLUDE_ALL_GCS
 #include "gc/cms/compactibleFreeListSpace.hpp"
--- a/hotspot/src/share/vm/runtime/vm_version.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/vm_version.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -110,7 +110,7 @@
 #ifndef HOTSPOT_VM_DISTRO
   #error HOTSPOT_VM_DISTRO must be defined
 #endif
-#define VMNAME HOTSPOT_VM_DISTRO " " VMLP EMBEDDED_ONLY("Embedded ") VMTYPE " VM"
+#define VMNAME HOTSPOT_VM_DISTRO " " VMLP VMTYPE " VM"
 
 const char* Abstract_VM_Version::vm_name() {
   return VMNAME;
@@ -295,7 +295,7 @@
     // processor after the first 8.  For example, on a 72 cpu machine
     // and a chosen fraction of 5/8
     // use 8 + (72 - 8) * (5/8) == 48 worker threads.
-    unsigned int ncpus = (unsigned int) os::active_processor_count();
+    unsigned int ncpus = (unsigned int) os::initial_active_processor_count();
     threads = (ncpus <= switch_pt) ?
              ncpus :
              (switch_pt + ((ncpus - switch_pt) * num) / den);
--- a/hotspot/src/share/vm/runtime/vm_version.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/runtime/vm_version.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -27,6 +27,7 @@
 
 #include "memory/allocation.hpp"
 #include "utilities/ostream.hpp"
+#include "utilities/macros.hpp"
 
 // VM_Version provides information about the VM.
 
@@ -160,20 +161,6 @@
   static bool supports_on_spin_wait() { return false; }
 };
 
-#ifdef TARGET_ARCH_x86
-# include "vm_version_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "vm_version_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "vm_version_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "vm_version_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "vm_version_ppc.hpp"
-#endif
+#include CPU_HEADER(vm_version)
 
 #endif // SHARE_VM_RUNTIME_VM_VERSION_HPP
--- a/hotspot/src/share/vm/services/diagnosticArgument.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/services/diagnosticArgument.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -98,7 +98,7 @@
     strncpy(buf, str, len);
     buf[len] = '\0';
     Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(),
-      "Integer parsing error in command argument '%s'. Could not parse: %s.", _name, buf);
+      "Integer parsing error in command argument '%s'. Could not parse: %s.\n", _name, buf);
   }
 }
 
@@ -132,7 +132,7 @@
       strncpy(buf, str, len);
       buf[len] = '\0';
       Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(),
-        "Boolean parsing error in command argument '%s'. Could not parse: %s.", _name, buf);
+        "Boolean parsing error in command argument '%s'. Could not parse: %s.\n", _name, buf);
     }
   }
 }
@@ -183,13 +183,13 @@
                                                  size_t len, TRAPS) {
   if (str == NULL) {
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-              "Integer parsing error nanotime value: syntax error, value is null");
+              "Integer parsing error nanotime value: syntax error, value is null\n");
   }
 
   int argc = sscanf(str, JLONG_FORMAT, &_value._time);
   if (argc != 1) {
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-              "Integer parsing error nanotime value: syntax error");
+              "Integer parsing error nanotime value: syntax error\n");
   }
   size_t idx = 0;
   while(idx < len && isdigit(str[idx])) {
@@ -199,7 +199,7 @@
     // only accept missing unit if the value is 0
     if (_value._time != 0) {
       THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-                "Integer parsing error nanotime value: unit required");
+                "Integer parsing error nanotime value: unit required\n");
     } else {
       _value._nanotime = 0;
       strcpy(_value._unit, "ns");
@@ -207,7 +207,7 @@
     }
   } else if(len - idx > 2) {
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-              "Integer parsing error nanotime value: illegal unit");
+              "Integer parsing error nanotime value: illegal unit\n");
   } else {
     strncpy(_value._unit, &str[idx], len - idx);
     /*Write an extra null termination. This is safe because _value._unit
@@ -234,7 +234,7 @@
     _value._nanotime = _value._time * 24 * 60 * 60 * 1000 * 1000 * 1000;
   } else {
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-               "Integer parsing error nanotime value: illegal unit");
+               "Integer parsing error nanotime value: illegal unit\n");
   }
 }
 
@@ -280,12 +280,11 @@
                                                   size_t len, TRAPS) {
   if (str == NULL) {
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-               "Parsing error memory size value: syntax error, value is null");
+               "Parsing error memory size value: syntax error, value is null\n");
   }
-
   if (*str == '-') {
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-               "Parsing error memory size value: negative values not allowed");
+               "Parsing error memory size value: negative values not allowed\n");
   }
   int res = sscanf(str, UINT64_FORMAT "%c", &_value._val, &_value._multiplier);
   if (res == 2) {
@@ -310,7 +309,7 @@
      _value._size = _value._val;
    } else {
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-               "Parsing error memory size value: invalid value");
+               "Parsing error memory size value: invalid value\n");
    }
 }
 
--- a/hotspot/src/share/vm/services/lowMemoryDetector.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/services/lowMemoryDetector.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -281,8 +281,6 @@
 }
 
 void SensorInfo::process_pending_requests(TRAPS) {
-  assert(has_pending_requests(), "Must have pending request");
-
   int pending_count = pending_trigger_count();
   if (pending_clear_count() > 0) {
     clear(pending_count, CHECK);
--- a/hotspot/src/share/vm/shark/sharkRuntime.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/shark/sharkRuntime.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2008, 2009, 2010 Red Hat, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -30,7 +30,8 @@
 #include "runtime/thread.hpp"
 #include "shark/llvmHeaders.hpp"
 #include "shark/sharkRuntime.hpp"
-#ifdef TARGET_ARCH_zero
+#include "utilities/macros.hpp"
+#ifdef ZERO
 # include "stack_zero.inline.hpp"
 #endif
 
--- a/hotspot/src/share/vm/shark/shark_globals.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/shark/shark_globals.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -27,7 +27,8 @@
 #define SHARE_VM_SHARK_SHARK_GLOBALS_HPP
 
 #include "runtime/globals.hpp"
-#ifdef TARGET_ARCH_zero
+#include "utilities/macros.hpp"
+#ifdef ZERO
 # include "shark_globals_zero.hpp"
 #endif
 
--- a/hotspot/src/share/vm/trace/traceevents.xml	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/trace/traceevents.xml	Fri Jul 29 16:11:55 2016 -0700
@@ -116,6 +116,12 @@
     <value type="CLASS" field="initiatingClassLoader" label="Initiating Class Loader"/>
   </event>
 
+  <event id="ClassDefine" path="vm/class/define" label="Class Define"
+          has_thread="true" has_stacktrace="true" is_instant="true">
+    <value type="CLASS" field="definedClass" label="Defined Class"/>
+    <value type="CLASS" field="definingClassLoader" label="Defining Class Loader"/>
+  </event>
+
   <event id="ClassUnload" path="vm/class/unload" label="Class Unload"
       has_thread="true" is_instant="true">
     <value type="CLASS" field="unloadedClass" label="Unloaded Class"/>
@@ -374,7 +380,7 @@
          description="Basic statistics related to current IHOP calculation">
     <value type="UINT" field="gcId" label="GC ID" relation="GC_ID"/>
     <value type="BYTES64" field="threshold" label="Current IHOP threshold" description="Current IHOP threshold in bytes"/>
-    <value type="BYTES64" field="thresholdPercentage" label="Current IHOP threshold in percent" description="Current IHOP threshold in percent of old gen"/>
+    <value type="PERCENTAGE" field="thresholdPercentage" label="Current IHOP threshold in percent" description="Current IHOP threshold in percent of old gen"/>
     <value type="BYTES64" field="targetOccupancy" label="Target occupancy" description="Target old gen occupancy to reach at the start of mixed GC in bytes"/>
     <value type="BYTES64" field="currentOccupancy" label="Current occupancy" description="Current old gen occupancy in bytes"/>
     <value type="BYTES64" field="lastAllocationSize" label="Last mutator allocation size" description="Mutator allocation during mutator operation since last GC in bytes"/>
@@ -387,7 +393,7 @@
          description="Statistics related to current adaptive IHOP calculation">
     <value type="UINT" field="gcId" label="GC ID" relation="GC_ID"/>
     <value type="BYTES64" field="threshold" label="Current IHOP threshold" description="Current IHOP threshold in bytes"/>
-    <value type="BYTES64" field="thresholdPercentage" label="Current IHOP threshold in percent" description="Current IHOP threshold in percent of the internal target occupancy"/>
+    <value type="PERCENTAGE" field="thresholdPercentage" label="Current IHOP threshold in percent" description="Current IHOP threshold in percent of the internal target occupancy"/>
     <value type="BYTES64" field="internalTargetOccupancy" label="Target occupancy" description="Internal target old gen occupancy to reach at the start of mixed GC in bytes"/>
     <value type="BYTES64" field="currentOccupancy" label="Current occupancy" description="Current old gen occupancy in bytes"/>
     <value type="BYTES64" field="additionalBufferSize" label="Additional buffer size" description="Additional buffer size in bytes"/>
--- a/hotspot/src/share/vm/utilities/bytes.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/utilities/bytes.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,23 +25,8 @@
 #ifndef SHARE_VM_UTILITIES_BYTES_HPP
 #define SHARE_VM_UTILITIES_BYTES_HPP
 
-#ifdef TARGET_ARCH_x86
-# include "bytes_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "bytes_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "bytes_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "bytes_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "bytes_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "bytes_aarch64.hpp"
-#endif
+#include "utilities/macros.hpp"
+
+#include CPU_HEADER(bytes)
 
 #endif // SHARE_VM_UTILITIES_BYTES_HPP
--- a/hotspot/src/share/vm/utilities/copy.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/utilities/copy.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -26,6 +26,7 @@
 #define SHARE_VM_UTILITIES_COPY_HPP
 
 #include "runtime/stubRoutines.hpp"
+#include "utilities/macros.hpp"
 
 // Assembly code for platforms that need it.
 extern "C" {
@@ -332,24 +333,7 @@
   }
 
   // Platform dependent implementations of the above methods.
-#ifdef TARGET_ARCH_x86
-# include "copy_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "copy_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "copy_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "copy_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "copy_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "copy_aarch64.hpp"
-#endif
+#include CPU_HEADER(copy)
 
 };
 
--- a/hotspot/src/share/vm/utilities/globalDefinitions.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/utilities/globalDefinitions.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -73,7 +73,6 @@
 #define ATTRIBUTE_SCANF(fmt, vargs)
 #endif
 
-
 #include "utilities/macros.hpp"
 
 // This file holds all globally used constants & types, class (forward)
@@ -456,24 +455,7 @@
 // Allow targets to reduce the default size of the code cache.
 #define CODE_CACHE_DEFAULT_LIMIT CODE_CACHE_SIZE_LIMIT
 
-#ifdef TARGET_ARCH_x86
-# include "globalDefinitions_x86.hpp"
-#endif
-#ifdef TARGET_ARCH_sparc
-# include "globalDefinitions_sparc.hpp"
-#endif
-#ifdef TARGET_ARCH_zero
-# include "globalDefinitions_zero.hpp"
-#endif
-#ifdef TARGET_ARCH_arm
-# include "globalDefinitions_arm.hpp"
-#endif
-#ifdef TARGET_ARCH_ppc
-# include "globalDefinitions_ppc.hpp"
-#endif
-#ifdef TARGET_ARCH_aarch64
-# include "globalDefinitions_aarch64.hpp"
-#endif
+#include CPU_HEADER(globalDefinitions)
 
 #ifndef INCLUDE_RTM_OPT
 #define INCLUDE_RTM_OPT 0
--- a/hotspot/src/share/vm/utilities/hashtable.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/utilities/hashtable.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -342,13 +342,18 @@
 
 #ifdef ASSERT
 
-template <MEMFLAGS F> void BasicHashtable<F>::verify_lookup_length(double load) {
-  if ((double)_lookup_length / (double)_lookup_count > load * 2.0) {
+template <MEMFLAGS F> bool BasicHashtable<F>::verify_lookup_length(double load) {
+  if ((!_lookup_warning) && (_lookup_count != 0)
+      && ((double)_lookup_length / (double)_lookup_count > load * 2.0)) {
     warning("Performance bug: SystemDictionary lookup_count=%d "
             "lookup_length=%d average=%lf load=%f",
             _lookup_count, _lookup_length,
-            (double) _lookup_length / _lookup_count, load);
+            (double)_lookup_length / _lookup_count, load);
+    _lookup_warning = true;
+
+    return false;
   }
+  return true;
 }
 
 #endif
--- a/hotspot/src/share/vm/utilities/hashtable.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/utilities/hashtable.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -124,9 +124,17 @@
   // Instance variable
   BasicHashtableEntry<F>*       _entry;
 
+#ifdef ASSERT
+private:
+  unsigned _hits;
+public:
+  unsigned hits()   { return _hits; }
+  void count_hit()  { _hits++; }
+#endif
+
 public:
   // Accessing
-  void clear()                        { _entry = NULL; }
+  void clear()                        { _entry = NULL; DEBUG_ONLY(_hits = 0); }
 
   // The following methods use order access methods to avoid race
   // conditions in multiprocessor systems.
@@ -135,6 +143,7 @@
 
   // The following method is not MT-safe and must be done under lock.
   BasicHashtableEntry<F>** entry_addr()  { return &_entry; }
+
 };
 
 
@@ -173,9 +182,10 @@
 protected:
 
 #ifdef ASSERT
+  bool              _lookup_warning;
   mutable int       _lookup_count;
   mutable int       _lookup_length;
-  void verify_lookup_length(double load);
+  bool verify_lookup_length(double load);
 #endif
 
   void initialize(int table_size, int entry_size, int number_of_entries);
@@ -226,6 +236,15 @@
   int number_of_entries() { return _number_of_entries; }
 
   void verify() PRODUCT_RETURN;
+
+#ifdef ASSERT
+  void bucket_count_hit(int i) const {
+    _buckets[i].count_hit();
+  }
+  unsigned bucket_hits(int i) const {
+    return _buckets[i].hits();
+  }
+#endif
 };
 
 
--- a/hotspot/src/share/vm/utilities/hashtable.inline.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/utilities/hashtable.inline.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -65,6 +65,7 @@
   _end_block = NULL;
   _number_of_entries = number_of_entries;
 #ifdef ASSERT
+  _lookup_warning = false;
   _lookup_count = 0;
   _lookup_length = 0;
 #endif
--- a/hotspot/src/share/vm/utilities/macros.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/utilities/macros.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -316,6 +316,7 @@
 #endif
 
 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
+#define BSD
 #define BSD_ONLY(code) code
 #define NOT_BSD(code)
 #else
@@ -429,6 +430,10 @@
 #define NOT_E500V2(code) code
 #endif
 
+// Note: There are three ARM ports. They set the following in the makefiles:
+// 1. Closed 32-bit port:   -DARM -DARM32           -DTARGET_ARCH_arm
+// 2. Closed 64-bit port:   -DARM -DAARCH64 -D_LP64 -DTARGET_ARCH_arm
+// 3. Open   64-bit port:         -DAARCH64 -D_LP64 -DTARGET_ARCH_aaarch64
 #ifdef ARM
 #define ARM_ONLY(code) code
 #define NOT_ARM(code)
@@ -453,14 +458,32 @@
 #define NOT_AARCH64(code) code
 #endif
 
-#ifdef JAVASE_EMBEDDED
-#define EMBEDDED_ONLY(code) code
-#define NOT_EMBEDDED(code)
-#else
-#define EMBEDDED_ONLY(code)
-#define NOT_EMBEDDED(code) code
-#endif
-
 #define define_pd_global(type, name, value) const type pd_##name = value;
 
+// Helper macros for constructing file names for includes.
+#define CPU_HEADER_STEM(basename) PASTE_TOKENS(basename, INCLUDE_SUFFIX_CPU)
+#define OS_HEADER_STEM(basename) PASTE_TOKENS(basename, INCLUDE_SUFFIX_OS)
+#define OS_CPU_HEADER_STEM(basename) PASTE_TOKENS(basename, PASTE_TOKENS(INCLUDE_SUFFIX_OS, INCLUDE_SUFFIX_CPU))
+
+// Include platform dependent files.
+//
+// This macro constructs from basename and INCLUDE_SUFFIX_OS /
+// INCLUDE_SUFFIX_CPU, which are set on the command line, the name of
+// platform dependent files to be included.
+// Example: INCLUDE_SUFFIX_OS=_linux / INCLUDE_SUFFIX_CPU=_sparc
+//   CPU_HEADER_INLINE(macroAssembler) --> macroAssembler_sparc.inline.hpp
+//   OS_CPU_HEADER(vmStructs)          --> vmStructs_linux_sparc.hpp
+//
+// basename<cpu>.hpp / basename<cpu>.inline.hpp
+#define CPU_HEADER_H(basename)         XSTR(CPU_HEADER_STEM(basename).h)
+#define CPU_HEADER(basename)           XSTR(CPU_HEADER_STEM(basename).hpp)
+#define CPU_HEADER_INLINE(basename)    XSTR(CPU_HEADER_STEM(basename).inline.hpp)
+// basename<os>.hpp / basename<os>.inline.hpp
+#define OS_HEADER_H(basename)          XSTR(OS_HEADER_STEM(basename).h)
+#define OS_HEADER(basename)            XSTR(OS_HEADER_STEM(basename).hpp)
+#define OS_HEADER_INLINE(basename)     XSTR(OS_HEADER_STEM(basename).inline.hpp)
+// basename<os><cpu>.hpp / basename<os><cpu>.inline.hpp
+#define OS_CPU_HEADER(basename)        XSTR(OS_CPU_HEADER_STEM(basename).hpp)
+#define OS_CPU_HEADER_INLINE(basename) XSTR(OS_CPU_HEADER_STEM(basename).inline.hpp)
+
 #endif // SHARE_VM_UTILITIES_MACROS_HPP
--- a/hotspot/src/share/vm/utilities/resourceHash.cpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/utilities/resourceHash.cpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 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
--- a/hotspot/src/share/vm/utilities/resourceHash.hpp	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/src/share/vm/utilities/resourceHash.hpp	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
--- a/hotspot/test/compiler/arguments/CheckCICompilerCount.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/compiler/arguments/CheckCICompilerCount.java	Fri Jul 29 16:11:55 2016 -0700
@@ -72,14 +72,14 @@
             "Improperly specified VM option 'CICompilerCount=0'"
         },
         {
-            "intx CICompilerCount                          := 1                                   {product}"
+            "intx CICompilerCount                          = 1                                        {product} {command line}"
         },
         {
             "CICompilerCount (0) must be at least 1",
             "Improperly specified VM option 'CICompilerCount=0'"
         },
         {
-            "intx CICompilerCount                          := 1                                   {product}"
+            "intx CICompilerCount                          = 1                                        {product} {command line}"
         }
     };
 
@@ -127,14 +127,14 @@
             "Improperly specified VM option 'CICompilerCount=1'"
         },
         {
-            "intx CICompilerCount                          := 2                                   {product}"
+            "intx CICompilerCount                          = 2                                        {product} {command line, ergonomic}"
         },
         {
             "CICompilerCount (1) must be at least 2",
             "Improperly specified VM option 'CICompilerCount=1'"
         },
         {
-            "intx CICompilerCount                          := 2                                   {product}"
+            "intx CICompilerCount                          = 2                                        {product} {command line, ergonomic}"
         }
     };
 
--- a/hotspot/test/compiler/arguments/CheckCompileThresholdScaling.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/compiler/arguments/CheckCompileThresholdScaling.java	Fri Jul 29 16:11:55 2016 -0700
@@ -105,25 +105,25 @@
 
     private static final String[][] NON_TIERED_EXPECTED_OUTPUTS = {
         {
-            "intx CompileThreshold                         := 1000                                {pd product}",
-            "double CompileThresholdScaling                   = 1.000000                            {product}"
+            "intx CompileThreshold                         = 1000                                  {pd product} {command line}",
+            "double CompileThresholdScaling                  = 1.000000                                 {product} {default}"
         },
         {
-            "intx CompileThreshold                         := 1250                                {pd product}",
-            "double CompileThresholdScaling                  := 1.250000                            {product}"
+            "intx CompileThreshold                         = 1250                                  {pd product} {command line, ergonomic}",
+            "double CompileThresholdScaling                  = 1.250000                                 {product} {command line}"
         },
         {
-            "intx CompileThreshold                         := 750                                 {pd product}",
-            "double CompileThresholdScaling                  := 0.750000                            {product}"
+            "intx CompileThreshold                         = 750                                   {pd product} {command line, ergonomic}",
+            "double CompileThresholdScaling                  = 0.750000                                 {product} {command line}"
         },
         {
-            "intx CompileThreshold                         := 1000                                {pd product}",
-            "double CompileThresholdScaling                  := 0.000000                            {product}",
+            "intx CompileThreshold                         = 1000                                  {pd product} {command line}",
+            "double CompileThresholdScaling                  = 0.000000                                 {product} {command line}",
             "interpreted mode"
         },
         {
-            "intx CompileThreshold                         := 0                                   {pd product}",
-            "double CompileThresholdScaling                  := 0.750000                            {product}",
+            "intx CompileThreshold                         = 0                                     {pd product} {command line, ergonomic}",
+            "double CompileThresholdScaling                  = 0.750000                                 {product} {command line}",
             "interpreted mode"
         }
     };
@@ -237,94 +237,94 @@
 
     private static final String[][] TIERED_EXPECTED_OUTPUTS = {
         {
-            "intx Tier0BackedgeNotifyFreqLog               := 10                                  {product}",
-            "intx Tier0InvokeNotifyFreqLog                 := 7                                   {product}",
-            "intx Tier23InlineeNotifyFreqLog               := 20                                  {product}",
-            "intx Tier2BackedgeNotifyFreqLog               := 14                                  {product}",
-            "intx Tier2InvokeNotifyFreqLog                 := 11                                  {product}",
-            "intx Tier3BackEdgeThreshold                   := 60000                               {product}",
-            "intx Tier3BackedgeNotifyFreqLog               := 13                                  {product}",
-            "intx Tier3CompileThreshold                    := 2000                                {product}",
-            "intx Tier3InvocationThreshold                 := 200                                 {product}",
-            "intx Tier3InvokeNotifyFreqLog                 := 10                                  {product}",
-            "intx Tier3MinInvocationThreshold              := 100                                 {product}",
-            "intx Tier4BackEdgeThreshold                   := 40000                               {product}",
-            "intx Tier4CompileThreshold                    := 15000                               {product}",
-            "intx Tier4InvocationThreshold                 := 5000                                {product}",
-            "intx Tier4MinInvocationThreshold              := 600                                 {product}",
-            "double CompileThresholdScaling                   = 1.000000                            {product}"
+            "intx Tier0BackedgeNotifyFreqLog               = 10                                       {product} {command line}",
+            "intx Tier0InvokeNotifyFreqLog                 = 7                                        {product} {command line}",
+            "intx Tier23InlineeNotifyFreqLog               = 20                                       {product} {command line}",
+            "intx Tier2BackedgeNotifyFreqLog               = 14                                       {product} {command line}",
+            "intx Tier2InvokeNotifyFreqLog                 = 11                                       {product} {command line}",
+            "intx Tier3BackEdgeThreshold                   = 60000                                    {product} {command line}",
+            "intx Tier3BackedgeNotifyFreqLog               = 13                                       {product} {command line}",
+            "intx Tier3CompileThreshold                    = 2000                                     {product} {command line}",
+            "intx Tier3InvocationThreshold                 = 200                                      {product} {command line}",
+            "intx Tier3InvokeNotifyFreqLog                 = 10                                       {product} {command line}",
+            "intx Tier3MinInvocationThreshold              = 100                                      {product} {command line}",
+            "intx Tier4BackEdgeThreshold                   = 40000                                    {product} {command line}",
+            "intx Tier4CompileThreshold                    = 15000                                    {product} {command line}",
+            "intx Tier4InvocationThreshold                 = 5000                                     {product} {command line}",
+            "intx Tier4MinInvocationThreshold              = 600                                      {product} {command line}",
+            "double CompileThresholdScaling                  = 1.000000                                 {product} {default}"
         },
         {
-            "intx Tier0BackedgeNotifyFreqLog               := 9                                   {product}",
-            "intx Tier0InvokeNotifyFreqLog                 := 6                                   {product}",
-            "intx Tier23InlineeNotifyFreqLog               := 19                                  {product}",
-            "intx Tier2BackedgeNotifyFreqLog               := 13                                  {product}",
-            "intx Tier2InvokeNotifyFreqLog                 := 10                                  {product}",
-            "intx Tier3BackEdgeThreshold                   := 45000                               {product}",
-            "intx Tier3BackedgeNotifyFreqLog               := 12                                  {product}",
-            "intx Tier3CompileThreshold                    := 1500                                {product}",
-            "intx Tier3InvocationThreshold                 := 150                                 {product}",
-            "intx Tier3InvokeNotifyFreqLog                 := 9                                   {product}",
-            "intx Tier3MinInvocationThreshold              := 75                                  {product}",
-            "intx Tier4BackEdgeThreshold                   := 30000                               {product}",
-            "intx Tier4CompileThreshold                    := 11250                               {product}",
-            "intx Tier4InvocationThreshold                 := 3750                                {product}",
-            "intx Tier4MinInvocationThreshold              := 450                                 {product}",
-            "double CompileThresholdScaling                  := 0.750000                            {product}"
+            "intx Tier0BackedgeNotifyFreqLog               = 9                                        {product} {command line, ergonomic}",
+            "intx Tier0InvokeNotifyFreqLog                 = 6                                        {product} {command line, ergonomic}",
+            "intx Tier23InlineeNotifyFreqLog               = 19                                       {product} {command line, ergonomic}",
+            "intx Tier2BackedgeNotifyFreqLog               = 13                                       {product} {command line, ergonomic}",
+            "intx Tier2InvokeNotifyFreqLog                 = 10                                       {product} {command line, ergonomic}",
+            "intx Tier3BackEdgeThreshold                   = 45000                                    {product} {command line, ergonomic}",
+            "intx Tier3BackedgeNotifyFreqLog               = 12                                       {product} {command line, ergonomic}",
+            "intx Tier3CompileThreshold                    = 1500                                     {product} {command line, ergonomic}",
+            "intx Tier3InvocationThreshold                 = 150                                      {product} {command line, ergonomic}",
+            "intx Tier3InvokeNotifyFreqLog                 = 9                                        {product} {command line, ergonomic}",
+            "intx Tier3MinInvocationThreshold              = 75                                       {product} {command line, ergonomic}",
+            "intx Tier4BackEdgeThreshold                   = 30000                                    {product} {command line, ergonomic}",
+            "intx Tier4CompileThreshold                    = 11250                                    {product} {command line, ergonomic}",
+            "intx Tier4InvocationThreshold                 = 3750                                     {product} {command line, ergonomic}",
+            "intx Tier4MinInvocationThreshold              = 450                                      {product} {command line, ergonomic}",
+            "double CompileThresholdScaling                  = 0.750000                                 {product} {command line}"
         },
         {
-            "intx Tier0BackedgeNotifyFreqLog               := 10                                  {product}",
-            "intx Tier0InvokeNotifyFreqLog                 := 7                                   {product}",
-            "intx Tier23InlineeNotifyFreqLog               := 20                                  {product}",
-            "intx Tier2BackedgeNotifyFreqLog               := 14                                  {product}",
-            "intx Tier2InvokeNotifyFreqLog                 := 11                                  {product}",
-            "intx Tier3BackEdgeThreshold                   := 75000                               {product}",
-            "intx Tier3BackedgeNotifyFreqLog               := 13                                  {product}",
-            "intx Tier3CompileThreshold                    := 2500                                {product}",
-            "intx Tier3InvocationThreshold                 := 250                                 {product}",
-            "intx Tier3InvokeNotifyFreqLog                 := 10                                  {product}",
-            "intx Tier3MinInvocationThreshold              := 125                                 {product}",
-            "intx Tier4BackEdgeThreshold                   := 50000                               {product}",
-            "intx Tier4CompileThreshold                    := 18750                               {product}",
-            "intx Tier4InvocationThreshold                 := 6250                                {product}",
-            "intx Tier4MinInvocationThreshold              := 750                                 {product}",
-            "double CompileThresholdScaling                  := 1.250000                            {product}"
+            "intx Tier0BackedgeNotifyFreqLog               = 10                                       {product} {command line, ergonomic}",
+            "intx Tier0InvokeNotifyFreqLog                 = 7                                        {product} {command line, ergonomic}",
+            "intx Tier23InlineeNotifyFreqLog               = 20                                       {product} {command line, ergonomic}",
+            "intx Tier2BackedgeNotifyFreqLog               = 14                                       {product} {command line, ergonomic}",
+            "intx Tier2InvokeNotifyFreqLog                 = 11                                       {product} {command line, ergonomic}",
+            "intx Tier3BackEdgeThreshold                   = 75000                                    {product} {command line, ergonomic}",
+            "intx Tier3BackedgeNotifyFreqLog               = 13                                       {product} {command line, ergonomic}",
+            "intx Tier3CompileThreshold                    = 2500                                     {product} {command line, ergonomic}",
+            "intx Tier3InvocationThreshold                 = 250                                      {product} {command line, ergonomic}",
+            "intx Tier3InvokeNotifyFreqLog                 = 10                                       {product} {command line, ergonomic}",
+            "intx Tier3MinInvocationThreshold              = 125                                      {product} {command line, ergonomic}",
+            "intx Tier4BackEdgeThreshold                   = 50000                                    {product} {command line, ergonomic}",
+            "intx Tier4CompileThreshold                    = 18750                                    {product} {command line, ergonomic}",
+            "intx Tier4InvocationThreshold                 = 6250                                     {product} {command line, ergonomic}",
+            "intx Tier4MinInvocationThreshold              = 750                                      {product} {command line, ergonomic}",
+            "double CompileThresholdScaling                  = 1.250000                                 {product} {command line}"
         },
         {
-            "intx Tier0BackedgeNotifyFreqLog               := 11                                  {product}",
-            "intx Tier0InvokeNotifyFreqLog                 := 8                                   {product}",
-            "intx Tier23InlineeNotifyFreqLog               := 21                                  {product}",
-            "intx Tier2BackedgeNotifyFreqLog               := 15                                  {product}",
-            "intx Tier2InvokeNotifyFreqLog                 := 12                                  {product}",
-            "intx Tier3BackEdgeThreshold                   := 120000                              {product}",
-            "intx Tier3BackedgeNotifyFreqLog               := 14                                  {product}",
-            "intx Tier3CompileThreshold                    := 4000                                {product}",
-            "intx Tier3InvocationThreshold                 := 400                                 {product}",
-            "intx Tier3InvokeNotifyFreqLog                 := 11                                  {product}",
-            "intx Tier3MinInvocationThreshold              := 200                                 {product}",
-            "intx Tier4BackEdgeThreshold                   := 80000                               {product}",
-            "intx Tier4CompileThreshold                    := 30000                               {product}",
-            "intx Tier4InvocationThreshold                 := 10000                               {product}",
-            "intx Tier4MinInvocationThreshold              := 1200                                {product}",
-            "double CompileThresholdScaling                  := 2.000000                            {product}"
+            "intx Tier0BackedgeNotifyFreqLog               = 11                                       {product} {command line, ergonomic}",
+            "intx Tier0InvokeNotifyFreqLog                 = 8                                        {product} {command line, ergonomic}",
+            "intx Tier23InlineeNotifyFreqLog               = 21                                       {product} {command line, ergonomic}",
+            "intx Tier2BackedgeNotifyFreqLog               = 15                                       {product} {command line, ergonomic}",
+            "intx Tier2InvokeNotifyFreqLog                 = 12                                       {product} {command line, ergonomic}",
+            "intx Tier3BackEdgeThreshold                   = 120000                                   {product} {command line, ergonomic}",
+            "intx Tier3BackedgeNotifyFreqLog               = 14                                       {product} {command line, ergonomic}",
+            "intx Tier3CompileThreshold                    = 4000                                     {product} {command line, ergonomic}",
+            "intx Tier3InvocationThreshold                 = 400                                      {product} {command line, ergonomic}",
+            "intx Tier3InvokeNotifyFreqLog                 = 11                                       {product} {command line, ergonomic}",
+            "intx Tier3MinInvocationThreshold              = 200                                      {product} {command line, ergonomic}",
+            "intx Tier4BackEdgeThreshold                   = 80000                                    {product} {command line, ergonomic}",
+            "intx Tier4CompileThreshold                    = 30000                                    {product} {command line, ergonomic}",
+            "intx Tier4InvocationThreshold                 = 10000                                    {product} {command line, ergonomic}",
+            "intx Tier4MinInvocationThreshold              = 1200                                     {product} {command line, ergonomic}",
+            "double CompileThresholdScaling                  = 2.000000                                 {product} {command line}"
         },
         {
-            "intx Tier0BackedgeNotifyFreqLog               := 10                                  {product}",
-            "intx Tier0InvokeNotifyFreqLog                 := 7                                   {product}",
-            "intx Tier23InlineeNotifyFreqLog               := 20                                  {product}",
-            "intx Tier2BackedgeNotifyFreqLog               := 14                                  {product}",
-            "intx Tier2InvokeNotifyFreqLog                 := 11                                  {product}",
-            "intx Tier3BackEdgeThreshold                   := 60000                               {product}",
-            "intx Tier3BackedgeNotifyFreqLog               := 13                                  {product}",
-            "intx Tier3CompileThreshold                    := 2000                                {product}",
-            "intx Tier3InvocationThreshold                 := 200                                 {product}",
-            "intx Tier3InvokeNotifyFreqLog                 := 10                                  {product}",
-            "intx Tier3MinInvocationThreshold              := 100                                 {product}",
-            "intx Tier4BackEdgeThreshold                   := 40000                               {product}",
-            "intx Tier4CompileThreshold                    := 15000                               {product}",
-            "intx Tier4InvocationThreshold                 := 5000                                {product}",
-            "intx Tier4MinInvocationThreshold              := 600                                 {product}",
-            "double CompileThresholdScaling                  := 0.000000                            {product}",
+            "intx Tier0BackedgeNotifyFreqLog               = 10                                       {product} {command line}",
+            "intx Tier0InvokeNotifyFreqLog                 = 7                                        {product} {command line}",
+            "intx Tier23InlineeNotifyFreqLog               = 20                                       {product} {command line}",
+            "intx Tier2BackedgeNotifyFreqLog               = 14                                       {product} {command line}",
+            "intx Tier2InvokeNotifyFreqLog                 = 11                                       {product} {command line}",
+            "intx Tier3BackEdgeThreshold                   = 60000                                    {product} {command line}",
+            "intx Tier3BackedgeNotifyFreqLog               = 13                                       {product} {command line}",
+            "intx Tier3CompileThreshold                    = 2000                                     {product} {command line}",
+            "intx Tier3InvocationThreshold                 = 200                                      {product} {command line}",
+            "intx Tier3InvokeNotifyFreqLog                 = 10                                       {product} {command line}",
+            "intx Tier3MinInvocationThreshold              = 100                                      {product} {command line}",
+            "intx Tier4BackEdgeThreshold                   = 40000                                    {product} {command line}",
+            "intx Tier4CompileThreshold                    = 15000                                    {product} {command line}",
+            "intx Tier4InvocationThreshold                 = 5000                                     {product} {command line}",
+            "intx Tier4MinInvocationThreshold              = 600                                      {product} {command line}",
+            "double CompileThresholdScaling                  = 0.000000                                 {product} {command line}",
             "interpreted mode"
         }
     };
--- a/hotspot/test/compiler/arraycopy/TestEliminatedArrayCopyDeopt.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/compiler/arraycopy/TestEliminatedArrayCopyDeopt.java	Fri Jul 29 16:11:55 2016 -0700
@@ -25,6 +25,7 @@
  * @test
  * @bug 8130847 8156760
  * @summary Eliminated instance/array written to by an array copy variant must be correctly initialized when reallocated at a deopt
+ * @ignore 8136818
  * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestEliminatedArrayCopyDeopt
  * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:+IgnoreUnrecognizedVMOptions -XX:-ReduceInitialCardMarks TestEliminatedArrayCopyDeopt
  */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/intrinsics/unsafe/ByteBufferTest.java	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,750 @@
+/*
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Red Hat Inc. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import jdk.test.lib.Utils;
+
+import java.nio.Buffer;
+import java.nio.BufferOverflowException;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.CharBuffer;
+import java.nio.DoubleBuffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.LongBuffer;
+import java.nio.ShortBuffer;
+import java.util.Arrays;
+import java.util.Random;
+
+import static java.nio.ByteOrder.BIG_ENDIAN;
+import static java.nio.ByteOrder.LITTLE_ENDIAN;
+
+// A wrapper for a ByteBuffer which maintains a backing array and a
+// position.  Whenever this wrapper is written the backing array and
+// the wrapped byte buffer are updated together, and whenever it is
+// read we check that the ByteBuffer and the backing array are identical.
+
+class MyByteBuffer {
+    final ByteBuffer buf;
+    final byte[] bytes;
+    int pos;
+    ByteOrder byteOrder = BIG_ENDIAN;
+
+    MyByteBuffer(ByteBuffer buf) {
+        this.buf = buf;
+        this.bytes = new byte[buf.capacity()];
+        pos = 0;
+    }
+
+    public final MyByteBuffer order(ByteOrder bo) {
+        byteOrder = bo;
+        buf.order(bo);
+        return this;
+    }
+
+    static MyByteBuffer allocate(int capacity) {
+        return new MyByteBuffer(ByteBuffer.allocate(capacity));
+    }
+
+    static MyByteBuffer allocateDirect(int capacity) {
+        return new MyByteBuffer(ByteBuffer.allocateDirect(capacity));
+    }
+
+    int capacity() { return bytes.length; }
+    int position() {
+        if (buf.position() != pos)
+            throw new RuntimeException();
+        return buf.position();
+    }
+
+    byte[] actualArray() {
+        buf.rewind();
+        byte[] actual = new byte[bytes.length];
+        buf.get(actual, 0, actual.length);
+        buf.rewind();
+
+        return actual;
+    }
+    byte[] expectedArray() { return bytes; }
+
+    private static byte long7(long x) { return (byte)(x >> 56); }
+    private static byte long6(long x) { return (byte)(x >> 48); }
+    private static byte long5(long x) { return (byte)(x >> 40); }
+    private static byte long4(long x) { return (byte)(x >> 32); }
+    private static byte long3(long x) { return (byte)(x >> 24); }
+    private static byte long2(long x) { return (byte)(x >> 16); }
+    private static byte long1(long x) { return (byte)(x >>  8); }
+    private static byte long0(long x) { return (byte)(x      ); }
+
+    private static byte int3(int x) { return (byte)(x >> 24); }
+    private static byte int2(int x) { return (byte)(x >> 16); }
+    private static byte int1(int x) { return (byte)(x >>  8); }
+    private static byte int0(int x) { return (byte)(x      ); }
+
+    private static byte short1(short x) { return (byte)(x >> 8); }
+    private static byte short0(short x) { return (byte)(x     ); }
+
+    byte _get(long i) { return bytes[(int)i]; }
+    void _put(long i, byte x) { bytes[(int)i] = x; }
+
+    private void putLongX(long a, long x) {
+        if (byteOrder == BIG_ENDIAN) {
+            x = Long.reverseBytes(x);
+        }
+        _put(a + 7, long7(x));
+        _put(a + 6, long6(x));
+        _put(a + 5, long5(x));
+        _put(a + 4, long4(x));
+        _put(a + 3, long3(x));
+        _put(a + 2, long2(x));
+        _put(a + 1, long1(x));
+        _put(a    , long0(x));
+    }
+
+    private void putIntX(long a, int x) {
+        if (byteOrder == BIG_ENDIAN) {
+            x = Integer.reverseBytes(x);
+        }
+        _put(a + 3, int3(x));
+        _put(a + 2, int2(x));
+        _put(a + 1, int1(x));
+        _put(a    , int0(x));
+    }
+
+    private void putShortX(int bi, short x) {
+        if (byteOrder == BIG_ENDIAN) {
+            x = Short.reverseBytes(x);
+        }
+        _put(bi    , short0(x));
+        _put(bi + 1, short1(x));
+    }
+
+    static private int makeInt(byte b3, byte b2, byte b1, byte b0) {
+        return (((b3       ) << 24) |
+                ((b2 & 0xff) << 16) |
+                ((b1 & 0xff) <<  8) |
+                ((b0 & 0xff)      ));
+    }
+    int getIntX(long a) {
+        int x = makeInt(_get(a + 3),
+                _get(a + 2),
+                _get(a + 1),
+                _get(a));
+        if (byteOrder == BIG_ENDIAN) {
+            x = Integer.reverseBytes(x);
+        }
+        return x;
+    }
+
+    static private long makeLong(byte b7, byte b6, byte b5, byte b4,
+                                 byte b3, byte b2, byte b1, byte b0)
+    {
+        return ((((long)b7       ) << 56) |
+                (((long)b6 & 0xff) << 48) |
+                (((long)b5 & 0xff) << 40) |
+                (((long)b4 & 0xff) << 32) |
+                (((long)b3 & 0xff) << 24) |
+                (((long)b2 & 0xff) << 16) |
+                (((long)b1 & 0xff) <<  8) |
+                (((long)b0 & 0xff)      ));
+    }
+
+    long getLongX(long a) {
+        long x = makeLong(_get(a + 7),
+                _get(a + 6),
+                _get(a + 5),
+                _get(a + 4),
+                _get(a + 3),
+                _get(a + 2),
+                _get(a + 1),
+                _get(a));
+        if (byteOrder == BIG_ENDIAN) {
+            x = Long.reverseBytes(x);
+        }
+        return x;
+    }
+
+    static private short makeShort(byte b1, byte b0) {
+        return (short)((b1 << 8) | (b0 & 0xff));
+    }
+
+    short getShortX(long a) {
+        short x = makeShort(_get(a + 1),
+                            _get(a    ));
+        if (byteOrder == BIG_ENDIAN) {
+            x = Short.reverseBytes(x);
+        }
+        return x;
+    }
+
+    double getDoubleX(long a) {
+        long x = getLongX(a);
+        return Double.longBitsToDouble(x);
+    }
+
+    double getFloatX(long a) {
+        int x = getIntX(a);
+        return Float.intBitsToFloat(x);
+    }
+
+    void ck(long x, long y) {
+        if (x != y) {
+            throw new RuntimeException(" x = " + Long.toHexString(x) + ", y = " + Long.toHexString(y));
+        }
+    }
+
+    void ck(double x, double y) {
+        if (x == x && y == y && x != y) {
+            ck(x, y);
+        }
+    }
+
+    // Method accessors
+
+    long getLong(int i) { ck(buf.getLong(i), getLongX(i)); return buf.getLong(i); }
+    int getInt(int i) { ck(buf.getInt(i), getIntX(i)); return buf.getInt(i); }
+    short getShort(int i) { ck(buf.getShort(i), getShortX(i)); return buf.getShort(i); }
+    char getChar(int i) { ck(buf.getChar(i), (char)getShortX(i)); return buf.getChar(i); }
+    double getDouble(int i) { ck(buf.getDouble(i), getDoubleX(i)); return buf.getDouble(i); }
+    float getFloat(int i) { ck(buf.getFloat(i), getFloatX(i)); return buf.getFloat(i); }
+
+    void putLong(int i, long x) { buf.putLong(i, x); putLongX(i, x); }
+    void putInt(int i, int x) { buf.putInt(i, x); putIntX(i, x); }
+    void putShort(int i, short x) { buf.putShort(i, x); putShortX(i, x); }
+    void putChar(int i, char x) { buf.putChar(i, x); putShortX(i, (short)x); }
+    void putDouble(int i, double x) { buf.putDouble(i, x); putLongX(i, Double.doubleToRawLongBits(x)); }
+    void putFloat(int i, float x) { buf.putFloat(i, x); putIntX(i, Float.floatToRawIntBits(x)); }
+
+    long getLong() { ck(buf.getLong(buf.position()), getLongX(pos)); long x = buf.getLong(); pos += 8; return x; }
+    int getInt() { ck(buf.getInt(buf.position()), getIntX(pos)); int x = buf.getInt(); pos += 4; return x; }
+    short getShort() { ck(buf.getShort(buf.position()), getShortX(pos)); short x = buf.getShort(); pos += 2; return x; }
+    char getChar() {  ck(buf.getChar(buf.position()), (char)getShortX(pos)); char x = buf.getChar(); pos += 2; return x; }
+    double getDouble() { ck(buf.getDouble(buf.position()), getDoubleX(pos)); double x = buf.getDouble(); pos += 8; return x; }
+    float getFloat() { ck(buf.getFloat(buf.position()), getFloatX(pos)); float x = buf.getFloat(); pos += 4; return x; }
+
+    void putLong(long x) { putLongX(pos, x); pos += 8; buf.putLong(x); }
+    void putInt(int x) { putIntX(pos, x); pos += 4; buf.putInt(x); }
+    void putShort(short x) { putShortX(pos, x); pos += 2; buf.putShort(x); }
+    void putChar(char x) { putShortX(pos, (short)x); pos += 2; buf.putChar(x); }
+    void putDouble(double x) { putLongX(pos, Double.doubleToRawLongBits(x)); pos += 8; buf.putDouble(x); }
+    void putFloat(float x) { putIntX(pos, Float.floatToRawIntBits(x)); pos += 4; buf.putFloat(x); }
+
+    // View accessors
+
+    long getLong(LongBuffer vb, int i) { ck(vb.get(i / 8), getLongX(i)); return vb.get(i / 8); }
+    int getInt(IntBuffer vb, int i) { ck(vb.get(i / 4), getIntX(i)); return vb.get(i / 4); }
+    short getShort(ShortBuffer vb, int i) { ck(vb.get(i / 2), getShortX(i)); return vb.get(i / 2); }
+    char getChar(CharBuffer vb, int i) { ck(vb.get(i / 2), (char)getShortX(i)); return vb.get(i / 2); }
+    double getDouble(DoubleBuffer vb, int i) { ck(vb.get(i / 8), getDoubleX(i)); return vb.get(i / 8); }
+    float getFloat(FloatBuffer vb, int i) { ck(vb.get(i / 4), getFloatX(i)); return vb.get(i / 4); }
+
+    void putLong(LongBuffer vb, int i, long x) { vb.put(i / 8, x); putLongX(i, x); }
+    void putInt(IntBuffer vb, int i, int x) { vb.put(i / 4, x); putIntX(i, x); }
+    void putShort(ShortBuffer vb, int i, short x) { vb.put(i / 2, x); putShortX(i, x); }
+    void putChar(CharBuffer vb, int i, char x) { vb.put(i / 2, x); putShortX(i, (short)x); }
+    void putDouble(DoubleBuffer vb, int i, double x) { vb.put(i / 8, x); putLongX(i, Double.doubleToRawLongBits(x)); }
+    void putFloat(FloatBuffer vb, int i, float x) { vb.put(i / 4, x); putIntX(i, Float.floatToRawIntBits(x)); }
+
+    long getLong(LongBuffer v) { ck(v.get(v.position()), getLongX(pos)); long x = v.get(); pos += 8; return x; }
+    int getInt(IntBuffer v) { ck(v.get(v.position()), getIntX(pos)); int x = v.get(); pos += 4; return x; }
+    short getShort(ShortBuffer v) { ck(v.get(v.position()), getShortX(pos)); short x = v.get(); pos += 2; return x; }
+    char getChar(CharBuffer v) { ck(v.get(v.position()), (char)getShortX(pos)); char x = v.get(); pos += 2; return x; }
+    double getDouble(DoubleBuffer v) { ck(v.get(v.position()), getDoubleX(pos)); double x = v.get(); pos += 8; return x; }
+    float getFloat(FloatBuffer v) { ck(v.get(v.position()), getFloatX(pos)); float x = v.get(); pos += 4; return x; }
+
+    void putLong(LongBuffer v, long x) { putLongX(pos, x); pos += 8; v.put(x); }
+    void putInt(IntBuffer v, int x) { putIntX(pos, x); pos += 4; v.put(x); }
+    void putShort(ShortBuffer v, short x) { putShortX(pos, x); pos += 2; v.put(x); }
+    void putChar(CharBuffer v, char x) { putShortX(pos, (short)x); pos += 2; v.put(x); }
+    void putDouble(DoubleBuffer v, double x) { putLongX(pos, Double.doubleToRawLongBits(x)); pos += 8; v.put(x); }
+    void putFloat(FloatBuffer v, float x) { putIntX(pos, Float.floatToRawIntBits(x)); pos += 4; v.put(x); }
+
+    void rewind() { pos = 0; buf.rewind(); }
+}
+
+public abstract class ByteBufferTest implements Runnable {
+
+    Random random = Utils.getRandomInstance();
+    MyByteBuffer data;
+
+    static int randomOffset(Random r, MyByteBuffer buf, int size) {
+        return r.nextInt(buf.capacity() - size);
+    }
+
+    static int randomAlignedOffset(Random r, MyByteBuffer buf, int unitSize) {
+        return r.nextInt(buf.capacity() / unitSize) * unitSize;
+    }
+
+    long iterations;
+
+    ByteBufferTest(long iterations, boolean direct) {
+        this.iterations = iterations;
+        data = direct
+               ? MyByteBuffer.allocateDirect(1024)
+               : MyByteBuffer.allocate(1024);
+    }
+
+    // The core of the test.  Walk over the buffer reading and writing
+    // random data, XORing it as we go.  We can detect writes in the
+    // wrong place, writes which are too long or too short, and reads
+    // or writes of the wrong data,
+    void step(Random r) {
+        stepUsingAccessors(r);
+        stepUsingViews(r);
+    }
+
+    void stepUsingAccessors(Random r) {
+        data.order((r.nextInt() & 1) != 0 ? BIG_ENDIAN : LITTLE_ENDIAN);
+
+        data.rewind();
+        while (data.position() < data.capacity())
+            data.putLong(data.getLong() ^ random.nextLong());
+
+        data.rewind();
+        while (data.position() < data.capacity())
+            data.putInt(data.getInt() ^ random.nextInt());
+
+        data.rewind();
+        while (data.position() < data.capacity())
+            data.putShort((short)(data.getShort() ^ random.nextInt()));
+
+        data.rewind();
+        while (data.position() < data.capacity())
+            data.putChar((char)(data.getChar() ^ random.nextInt()));
+
+        data.rewind();
+        while (data.position() < data.capacity())
+            data.putDouble(combine(data.getDouble(), random.nextLong()));
+
+        data.rewind();
+        while (data.position() < data.capacity())
+            data.putFloat(combine(data.getFloat(), random.nextInt()));
+
+        for (int i = 0; i < 100; i++) {
+            int offset = randomOffset(r, data, Long.BYTES);
+            data.putLong(offset, data.getLong(offset) ^ random.nextLong());
+        }
+        for (int i = 0; i < 100; i++) {
+            int offset = randomOffset(r, data, Integer.BYTES);
+            data.putInt(offset, data.getInt(offset) ^ random.nextInt());
+        }
+        for (int i = 0; i < 100; i++) {
+            int offset = randomOffset(r, data, Short.BYTES);
+            data.putShort(offset, (short)(data.getShort(offset) ^ random.nextInt()));
+        }
+        for (int i = 0; i < 100; i++) {
+            int offset = randomOffset(r, data, Character.BYTES);
+            data.putChar(offset, (char)(data.getChar(offset) ^ random.nextInt()));
+        }
+        for (int i = 0; i < 100; i++) {
+            int offset = randomOffset(r, data, Double.BYTES);
+            data.putDouble(offset, combine(data.getDouble(offset), random.nextLong()));
+        }
+        for (int i = 0; i < 100; i++) {
+            int offset = randomOffset(r, data, Float.BYTES);
+            data.putFloat(offset, combine(data.getFloat(offset), random.nextInt()));
+        }
+    }
+
+    void stepUsingViews(Random r) {
+        data.order((r.nextInt() & 1) != 0 ? BIG_ENDIAN : LITTLE_ENDIAN);
+
+        data.rewind();
+        LongBuffer lbuf = data.buf.asLongBuffer();
+        while (lbuf.position() < data.capacity() / Long.BYTES)
+            data.putLong(lbuf, data.getLong(lbuf) ^ random.nextLong());
+
+        data.rewind();
+        IntBuffer ibuf = data.buf.asIntBuffer();
+        while (ibuf.position() < data.capacity() / Integer.BYTES)
+            data.putInt(ibuf, data.getInt(ibuf) ^ random.nextInt());
+
+        data.rewind();
+        ShortBuffer sbuf = data.buf.asShortBuffer();
+        while (sbuf.position() < data.capacity() / Short.BYTES)
+            data.putShort(sbuf, (short)(data.getShort(sbuf) ^ random.nextInt()));
+
+        data.rewind();
+        CharBuffer cbuf = data.buf.asCharBuffer();
+        while (cbuf.position() < data.capacity() / Character.BYTES)
+            data.putChar(cbuf, (char)(data.getChar(cbuf) ^ random.nextInt()));
+
+        data.rewind();
+        DoubleBuffer dbuf = data.buf.asDoubleBuffer();
+        while (dbuf.position() < data.capacity() / Double.BYTES)
+            data.putDouble(dbuf, combine(data.getDouble(dbuf), random.nextLong()));
+
+        data.rewind();
+        FloatBuffer fbuf = data.buf.asFloatBuffer();
+        while (fbuf.position() < data.capacity() / Float.BYTES)
+            data.putFloat(fbuf, combine(data.getFloat(fbuf), random.nextInt()));
+
+        for (int i = 0; i < 100; i++) {
+            int offset = randomAlignedOffset(r, data, Long.BYTES);
+            data.putLong(lbuf, offset, data.getLong(lbuf, offset) ^ random.nextLong());
+        }
+        for (int i = 0; i < 100; i++) {
+            int offset = randomAlignedOffset(r, data, Integer.BYTES);
+            data.putInt(ibuf, offset, data.getInt(ibuf, offset) ^ random.nextInt());
+        }
+        for (int i = 0; i < 100; i++) {
+            int offset = randomAlignedOffset(r, data, Short.BYTES);
+            data.putShort(sbuf, offset, (short)(data.getShort(sbuf, offset) ^ random.nextInt()));
+        }
+        for (int i = 0; i < 100; i++) {
+            int offset = randomAlignedOffset(r, data, Character.BYTES);
+            data.putChar(cbuf, offset, (char)(data.getChar(cbuf, offset) ^ random.nextInt()));
+        }
+        for (int i = 0; i < 100; i++) {
+            int offset = randomAlignedOffset(r, data, Double.BYTES);
+            data.putDouble(dbuf, offset, combine(data.getDouble(dbuf, offset), random.nextLong()));
+        }
+        for (int i = 0; i < 100; i++) {
+            int offset = randomAlignedOffset(r, data, Float.BYTES);
+            data.putFloat(fbuf, offset, combine(data.getFloat(fbuf, offset), random.nextInt()));
+        }
+    }
+
+    // XOR the bit pattern of a double and a long, returning the
+    // result as a double.
+    //
+    // We convert signalling NaNs to quiet NaNs.  We need to do this
+    // because some platforms (in particular legacy 80x87) do not
+    // provide transparent conversions between integer and
+    // floating-point types even when using raw conversions but
+    // quietly convert sNaN to qNaN.  This causes spurious test
+    // failures when the template interpreter uses 80x87 and the JITs
+    // use XMM registers.
+    //
+    public double combine(double prev, long bits) {
+        bits ^= Double.doubleToRawLongBits(prev);
+        double result = Double.longBitsToDouble(bits);
+        if (Double.isNaN(result)) {
+            result = Double.longBitsToDouble(bits | 0x8000000000000l);
+        }
+        return result;
+    }
+
+    // XOR the bit pattern of a float and an int, returning the result
+    // as a float.  Convert sNaNs to qNaNs.
+    public Float combine(float prev, int bits) {
+        bits ^= Float.floatToRawIntBits(prev);
+        Float result = Float.intBitsToFloat(bits);
+        if (Float.isNaN(result)) {
+            result = Float.intBitsToFloat(bits | 0x400000);
+        }
+        return result;
+    }
+
+    enum PrimitiveType {
+        BYTE(1), CHAR(2), SHORT(2), INT(4), LONG(8), FLOAT(4), DOUBLE(8);
+
+        public final int size;
+        PrimitiveType(int size) {
+            this.size = size;
+        }
+    }
+
+    Buffer asView(ByteBuffer b, PrimitiveType t) {
+        switch (t) {
+            case BYTE: return b;
+            case CHAR: return b.asCharBuffer();
+            case SHORT: return b.asShortBuffer();
+            case INT: return b.asIntBuffer();
+            case LONG: return b.asLongBuffer();
+            case FLOAT: return b.asFloatBuffer();
+            case DOUBLE: return b.asDoubleBuffer();
+        }
+        throw new InternalError("Should not reach here");
+    }
+
+    void getOne(ByteBuffer b, PrimitiveType t) {
+        switch (t) {
+        case BYTE: b.get(); break;
+        case CHAR: b.getChar(); break;
+        case SHORT: b.getShort(); break;
+        case INT: b.getInt(); break;
+        case LONG: b.getLong(); break;
+        case FLOAT: b.getFloat(); break;
+        case DOUBLE: b.getDouble(); break;
+        }
+    }
+
+    void putOne(ByteBuffer b, PrimitiveType t) {
+        switch (t) {
+        case BYTE: b.put((byte)0); break;
+        case CHAR: b.putChar('0'); break;
+        case SHORT: b.putShort((short)0); break;
+        case INT: b.putInt(0); break;
+        case LONG: b.putLong(0); break;
+        case FLOAT: b.putFloat(0); break;
+        case DOUBLE: b.putDouble(0); break;
+        }
+    }
+
+    void asViewGetOne(ByteBuffer b, PrimitiveType t) {
+        switch (t) {
+            case BYTE: b.get(); break;
+            case CHAR: b.asCharBuffer().get(); break;
+            case SHORT: b.asShortBuffer().get(); break;
+            case INT: b.asIntBuffer().get(); break;
+            case LONG: b.asLongBuffer().get(); break;
+            case FLOAT: b.asFloatBuffer().get(); break;
+            case DOUBLE: b.asDoubleBuffer().get(); break;
+        }
+    }
+
+    void asViewPutOne(ByteBuffer b, PrimitiveType t) {
+        switch (t) {
+            case BYTE: b.put((byte)0); break;
+            case CHAR: b.asCharBuffer().put('0'); break;
+            case SHORT: b.asShortBuffer().put((short)0); break;
+            case INT: b.asIntBuffer().put(0); break;
+            case LONG: b.asLongBuffer().put(0); break;
+            case FLOAT: b.asFloatBuffer().put(0); break;
+            case DOUBLE: b.asDoubleBuffer().put(0); break;
+        }
+    }
+
+    void getOne(ByteBuffer b, PrimitiveType t, int index) {
+        switch (t) {
+        case BYTE: b.get(index); break;
+        case CHAR: b.getChar(index); break;
+        case SHORT: b.getShort(index); break;
+        case INT: b.getInt(index); break;
+        case LONG: b.getLong(index); break;
+        case FLOAT: b.getFloat(index); break;
+        case DOUBLE: b.getDouble(index); break;
+        }
+    }
+
+    void putOne(ByteBuffer b, PrimitiveType t, int index) {
+        switch (t) {
+        case BYTE: b.put(index, (byte)0); break;
+        case CHAR: b.putChar(index, '0'); break;
+        case SHORT: b.putShort(index, (short)0); break;
+        case INT: b.putInt(index, 0); break;
+        case LONG: b.putLong(index, 0); break;
+        case FLOAT: b.putFloat(index, 0); break;
+        case DOUBLE: b.putDouble(index, 0); break;
+        }
+    }
+
+    void asViewGetOne(Buffer v, PrimitiveType t, int index) {
+        switch (t) {
+            case BYTE: ((ByteBuffer) v).get(index); break;
+            case CHAR: ((CharBuffer) v).get(index); break;
+            case SHORT: ((ShortBuffer) v).get(index); break;
+            case INT: ((IntBuffer) v).get(index); break;
+            case LONG: ((LongBuffer) v).get(index); break;
+            case FLOAT: ((FloatBuffer) v).get(index); break;
+            case DOUBLE: ((DoubleBuffer) v).get(index); break;
+        }
+    }
+
+    void asViewPutOne(Buffer v, PrimitiveType t, int index) {
+        switch (t) {
+            case BYTE: ((ByteBuffer) v).put(index, (byte)0); break;
+            case CHAR: ((CharBuffer) v).put(index, '0'); break;
+            case SHORT: ((ShortBuffer) v).put(index, (short)0); break;
+            case INT: ((IntBuffer) v).put(index, 0); break;
+            case LONG: ((LongBuffer) v).put(index, 0); break;
+            case FLOAT: ((FloatBuffer) v).put(index, 0); break;
+            case DOUBLE: ((DoubleBuffer) v).put(index, 0); break;
+        }
+    }
+
+    void checkBoundaryConditions() {
+        for (int i = 0; i < 100; i++) {
+            int bufSize = random.nextInt(16);
+            ByteBuffer buf = data.buf.isDirect()
+                    ? ByteBuffer.allocateDirect(bufSize)
+                    : ByteBuffer.allocate(bufSize);
+            for (PrimitiveType t : PrimitiveType.values()) {
+                buf.rewind();
+                Buffer viewBuf = asView(buf, t);
+                for (int j = 0; j < 100; j++) {
+                    int offset = random.nextInt(32) - 8;
+                    int threw = 0;
+                    int checks = 6;
+                    try {
+                        try {
+                            buf.position(offset);
+                            getOne(buf, t);
+                        }
+                        catch (BufferUnderflowException e) {
+                            if (offset + t.size < bufSize)
+                                throw new RuntimeException
+                                        ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
+                            threw++;
+                        }
+                        catch (IllegalArgumentException e) {
+                            if (offset >= 0 && offset + t.size < bufSize)
+                                throw new RuntimeException
+                                        ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
+                            threw++;
+                        }
+
+                        try {
+                            buf.position(offset);
+                            asViewGetOne(buf, t);
+                        }
+                        catch (BufferUnderflowException e) {
+                            if (offset + t.size < bufSize)
+                                throw new RuntimeException
+                                        ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
+                            threw++;
+                        }
+                        catch (IllegalArgumentException e) {
+                            if (offset >= 0 && offset + t.size < bufSize)
+                                throw new RuntimeException
+                                        ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
+                            threw++;
+                        }
+
+                        try {
+                            buf.position(offset);
+                            putOne(buf, t);
+                        }
+                        catch (BufferOverflowException e) {
+                            if (offset + t.size < bufSize)
+                                throw new RuntimeException
+                                        ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
+                            threw++;
+                        }
+                        catch (IllegalArgumentException e) {
+                            if (offset >= 0 && offset + t.size < bufSize)
+                                throw new RuntimeException
+                                        ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
+                            threw++;
+                        }
+
+                        try {
+                            buf.position(offset);
+                            asViewPutOne(buf, t);
+                        }
+                        catch (BufferOverflowException e) {
+                            if (offset + t.size < bufSize)
+                                throw new RuntimeException
+                                        ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
+                            threw++;
+                        }
+                        catch (IllegalArgumentException e) {
+                            if (offset >= 0 && offset + t.size < bufSize)
+                                throw new RuntimeException
+                                        ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
+                            threw++;
+                        }
+
+                        try {
+                            putOne(buf, t, offset);
+                        }
+                        catch (IndexOutOfBoundsException e) {
+                            if (offset >= 0 && offset + t.size < bufSize)
+                                throw new RuntimeException
+                                        ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
+                            threw++;
+                        }
+
+                        try {
+                            getOne(buf, t, offset);
+                        }
+                        catch (IndexOutOfBoundsException e) {
+                            if (offset >= 0 && offset + t.size < bufSize)
+                                throw new RuntimeException
+                                        ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
+                            threw++;
+                        }
+
+                        // If offset is aligned access using the view
+                        if (offset % t.size == 0) {
+                            checks = 8;
+                            int viewOffset = offset / t.size;
+
+
+                            try {
+                                asViewPutOne(viewBuf, t, viewOffset);
+                            }
+                            catch (IndexOutOfBoundsException e) {
+                                if (offset >= 0 && offset + t.size < bufSize)
+                                    throw new RuntimeException
+                                            ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
+                                threw++;
+                            }
+
+                            try {
+                                asViewGetOne(viewBuf, t, viewOffset);
+                            }
+                            catch (IndexOutOfBoundsException e) {
+                                if (offset >= 0 && offset + t.size < bufSize)
+                                    throw new RuntimeException
+                                            ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
+                                threw++;
+                            }
+                        }
+
+                        if (threw == 0) {
+                            // Make sure that we should not have thrown.
+                            if (offset < 0 || offset + t.size > bufSize) {
+                                throw new RuntimeException
+                                        ("should have thrown but did not, type = " + t
+                                         + ", offset = " + offset + ", bufSize = " + bufSize);
+                            }
+                        }
+                        else if (threw != checks) {
+                            // If one of the {get,put} operations threw
+                            // due to an invalid offset then all four of
+                            // them should have thrown.
+                            throw new RuntimeException
+                                    ("should have thrown but at least one did not, type = " + t
+                                     + ", offset = " + offset + ", bufSize = " + bufSize);
+                        }
+                    }
+                    catch (Throwable th) {
+                        throw new RuntimeException
+                                ("unexpected throw: type  = " + t + ", offset = " + offset + ", bufSize = " + bufSize, th);
+
+                    }
+                }
+            }
+        }
+    }
+
+    public void run() {
+        checkBoundaryConditions();
+
+        for (int i = 0; i < data.capacity(); i += 8) {
+            data.putLong(i, random.nextLong());
+        }
+
+        for (int i = 0; i < iterations; i++) {
+            step(random);
+        }
+
+        if (!Arrays.equals(data.actualArray(), data.expectedArray())) {
+            throw new RuntimeException();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/intrinsics/unsafe/DirectByteBufferTest.java	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, Red Hat Inc. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8026049 8151163
+ * @modules java.base/jdk.internal.misc
+ * @library /testlibrary
+ * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:-UseUnalignedAccesses -Djdk.test.lib.random.seed=0 DirectByteBufferTest
+ * @run main/othervm -Djdk.test.lib.random.seed=0 DirectByteBufferTest
+ * @summary Verify that direct byte buffers are correctly accessed.
+ */
+
+public class DirectByteBufferTest extends ByteBufferTest {
+
+    public DirectByteBufferTest(long iterations, boolean direct) {
+        super(iterations, direct);
+    }
+
+    public static void main(String[] args) {
+        // The number of iterations is high to ensure that tiered
+        // compilation kicks in all the way up to C2.
+        long iterations = 100000;
+        if (args.length > 0)
+            iterations = Long.parseLong(args[0]);
+
+        new DirectByteBufferTest(iterations, true).run();
+    }
+}
--- a/hotspot/test/compiler/intrinsics/unsafe/HeapByteBufferTest.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/compiler/intrinsics/unsafe/HeapByteBufferTest.java	Fri Jul 29 16:11:55 2016 -0700
@@ -1,506 +1,41 @@
-//
-// Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
-// Copyright (c) 2015, Red Hat Inc. All rights reserved.
-// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-//
-// This code is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License version 2 only, as
-// published by the Free Software Foundation.
-//
-// This code is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-// version 2 for more details (a copy is included in the LICENSE file that
-// accompanied this code).
-//
-// You should have received a copy of the GNU General Public License version
-// 2 along with this work; if not, write to the Free Software Foundation,
-// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-// or visit www.oracle.com if you need additional information or have any
-// questions.
-//
-//
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ByteBuffer;
-import static java.nio.ByteOrder.BIG_ENDIAN;
-import static java.nio.ByteOrder.LITTLE_ENDIAN;
-import java.nio.ByteOrder;
-import java.util.Arrays;
-import java.util.Random;
-import jdk.test.lib.Utils;
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, Red Hat Inc. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
 
 /**
  * @test
- * @bug 8026049
+ * @bug 8026049 8151163
  * @modules java.base/jdk.internal.misc
  * @library /testlibrary
  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:-UseUnalignedAccesses -Djdk.test.lib.random.seed=0 HeapByteBufferTest
  * @run main/othervm -Djdk.test.lib.random.seed=0 HeapByteBufferTest
- * @summary Verify that byte buffers are correctly accessed.
+ * @summary Verify that heap byte buffers are correctly accessed.
  */
 
-// A wrapper for a ByteBuffer which maintains a backing array and a
-// position.  Whenever this wrapper is written the backing array and
-// the wrapped byte buffer are updated together, and whenever it is
-// read we check that the ByteBuffer and the backing array are identical.
-
-class MyByteBuffer {
-    final ByteBuffer buf;
-    final byte[] bytes;
-    int pos;
-    ByteOrder byteOrder = BIG_ENDIAN;
-
-    MyByteBuffer(ByteBuffer buf, byte[] bytes) {
-        this.buf = buf;
-        this.bytes = Arrays.copyOf(bytes, bytes.length);
-        pos = 0;
-    }
-
-    public final MyByteBuffer order(ByteOrder bo) {
-        byteOrder = bo;
-        buf.order(bo);
-        return this;
-    }
-
-    static MyByteBuffer wrap(byte[] bytes) {
-        return new MyByteBuffer(ByteBuffer.wrap(bytes), bytes);
-    }
-
-    int capacity() { return bytes.length; }
-    int position() {
-        if (buf.position() != pos)
-            throw new RuntimeException();
-        return buf.position();
-    }
-
-    byte[] array() { return buf.array(); }
-    byte[] backingArray() { return bytes; }
-
-    private static byte long7(long x) { return (byte)(x >> 56); }
-    private static byte long6(long x) { return (byte)(x >> 48); }
-    private static byte long5(long x) { return (byte)(x >> 40); }
-    private static byte long4(long x) { return (byte)(x >> 32); }
-    private static byte long3(long x) { return (byte)(x >> 24); }
-    private static byte long2(long x) { return (byte)(x >> 16); }
-    private static byte long1(long x) { return (byte)(x >>  8); }
-    private static byte long0(long x) { return (byte)(x      ); }
-
-    private static byte int3(int x) { return (byte)(x >> 24); }
-    private static byte int2(int x) { return (byte)(x >> 16); }
-    private static byte int1(int x) { return (byte)(x >>  8); }
-    private static byte int0(int x) { return (byte)(x      ); }
-
-    private static byte short1(short x) { return (byte)(x >> 8); }
-    private static byte short0(short x) { return (byte)(x     ); }
-
-    byte _get(long i) { return bytes[(int)i]; }
-    void _put(long i, byte x) { bytes[(int)i] = x; }
-
-    private void putLongX(long a, long x) {
-        if (byteOrder == BIG_ENDIAN) {
-            x = Long.reverseBytes(x);
-        }
-        _put(a + 7, long7(x));
-        _put(a + 6, long6(x));
-        _put(a + 5, long5(x));
-        _put(a + 4, long4(x));
-        _put(a + 3, long3(x));
-        _put(a + 2, long2(x));
-        _put(a + 1, long1(x));
-        _put(a    , long0(x));
-    }
-
-    private void putIntX(long a, int x) {
-        if (byteOrder == BIG_ENDIAN) {
-            x = Integer.reverseBytes(x);
-        }
-        _put(a + 3, int3(x));
-        _put(a + 2, int2(x));
-        _put(a + 1, int1(x));
-        _put(a    , int0(x));
-    }
-
-    private void putShortX(int bi, short x) {
-        if (byteOrder == BIG_ENDIAN) {
-            x = Short.reverseBytes(x);
-        }
-        _put(bi    , short0(x));
-        _put(bi + 1, short1(x));
-    }
-
-    static private int makeInt(byte b3, byte b2, byte b1, byte b0) {
-        return (((b3       ) << 24) |
-                ((b2 & 0xff) << 16) |
-                ((b1 & 0xff) <<  8) |
-                ((b0 & 0xff)      ));
-    }
-    int getIntX(long a) {
-        int x = makeInt(_get(a + 3),
-                _get(a + 2),
-                _get(a + 1),
-                _get(a));
-        if (byteOrder == BIG_ENDIAN) {
-            x = Integer.reverseBytes(x);
-        }
-        return x;
-    }
-
-    static private long makeLong(byte b7, byte b6, byte b5, byte b4,
-                                 byte b3, byte b2, byte b1, byte b0)
-    {
-        return ((((long)b7       ) << 56) |
-                (((long)b6 & 0xff) << 48) |
-                (((long)b5 & 0xff) << 40) |
-                (((long)b4 & 0xff) << 32) |
-                (((long)b3 & 0xff) << 24) |
-                (((long)b2 & 0xff) << 16) |
-                (((long)b1 & 0xff) <<  8) |
-                (((long)b0 & 0xff)      ));
-    }
-
-    long getLongX(long a) {
-        long x = makeLong(_get(a + 7),
-                _get(a + 6),
-                _get(a + 5),
-                _get(a + 4),
-                _get(a + 3),
-                _get(a + 2),
-                _get(a + 1),
-                _get(a));
-        if (byteOrder == BIG_ENDIAN) {
-            x = Long.reverseBytes(x);
-        }
-        return x;
-    }
-
-    static private short makeShort(byte b1, byte b0) {
-        return (short)((b1 << 8) | (b0 & 0xff));
-    }
-
-    short getShortX(long a) {
-        short x = makeShort(_get(a + 1),
-                            _get(a    ));
-        if (byteOrder == BIG_ENDIAN) {
-            x = Short.reverseBytes(x);
-        }
-        return x;
-    }
-
-    double getDoubleX(long a) {
-        long x = getLongX(a);
-        return Double.longBitsToDouble(x);
-    }
-
-    double getFloatX(long a) {
-        int x = getIntX(a);
-        return Float.intBitsToFloat(x);
-    }
-
-    void ck(long x, long y) {
-        if (x != y) {
-            throw new RuntimeException(" x = " + Long.toHexString(x) + ", y = " + Long.toHexString(y));
-        }
-    }
-
-    void ck(double x, double y) {
-        if (x == x && y == y && x != y) {
-            ck(x, y);
-        }
-    }
-
-    long getLong(int i) { ck(buf.getLong(i), getLongX(i)); return buf.getLong(i); }
-    int getInt(int i) { ck(buf.getInt(i), getIntX(i)); return buf.getInt(i); }
-    short getShort(int i) { ck(buf.getShort(i), getShortX(i)); return buf.getShort(i); }
-    char getChar(int i) { ck(buf.getChar(i), (char)getShortX(i)); return buf.getChar(i); }
-    double getDouble(int i) { ck(buf.getDouble(i), getDoubleX(i)); return buf.getDouble(i); }
-    float getFloat(int i) { ck(buf.getFloat(i), getFloatX(i)); return buf.getFloat(i); }
-
-    void putLong(int i, long x) { buf.putLong(i, x); putLongX(i, x); }
-    void putInt(int i, int x) { buf.putInt(i, x); putIntX(i, x); }
-    void putShort(int i, short x) { buf.putShort(i, x); putShortX(i, x); }
-    void putChar(int i, char x) { buf.putChar(i, x); putShortX(i, (short)x); }
-    void putDouble(int i, double x) { buf.putDouble(i, x); putLongX(i, Double.doubleToRawLongBits(x)); }
-    void putFloat(int i, float x) { buf.putFloat(i, x); putIntX(i, Float.floatToRawIntBits(x)); }
-
-    long getLong() { ck(buf.getLong(buf.position()), getLongX(pos)); long x = buf.getLong(); pos += 8; return x; }
-    int getInt() { ck(buf.getInt(buf.position()), getIntX(pos)); int x = buf.getInt(); pos += 4; return x; }
-    short getShort() { ck(buf.getShort(buf.position()), getShortX(pos)); short x = buf.getShort(); pos += 2; return x; }
-    char getChar() {  ck(buf.getChar(buf.position()), (char)getShortX(pos)); char x = buf.getChar(); pos += 2; return x; }
-    double getDouble() { ck(buf.getDouble(buf.position()), getDoubleX(pos)); double x = buf.getDouble(); pos += 8; return x; }
-    float getFloat() { ck(buf.getFloat(buf.position()), getFloatX(pos)); float x = buf.getFloat(); pos += 4; return x; }
-
-    void putLong(long x) { putLongX(pos, x); pos += 8; buf.putLong(x); }
-    void putInt(int x) { putIntX(pos, x); pos += 4; buf.putInt(x); }
-    void putShort(short x) { putShortX(pos, x); pos += 2; buf.putShort(x); }
-    void putChar(char x) { putShortX(pos, (short)x); pos += 2; buf.putChar(x); }
-    void putDouble(double x) { putLongX(pos, Double.doubleToRawLongBits(x)); pos += 8; buf.putDouble(x); }
-    void putFloat(float x) { putIntX(pos, Float.floatToRawIntBits(x)); pos += 4; buf.putFloat(x); }
-
-    void rewind() { pos = 0; buf.rewind(); }
-}
-
-public class HeapByteBufferTest implements Runnable {
-
-    Random random = Utils.getRandomInstance();
-    MyByteBuffer data = MyByteBuffer.wrap(new byte[1024]);
-
-    int randomOffset(Random r, MyByteBuffer buf, int size) {
-        return r.nextInt(buf.capacity() - size);
-    }
-
-    long iterations;
-
-    HeapByteBufferTest(long iterations) {
-        this.iterations = iterations;
-    }
-
-    // The core of the test.  Walk over the buffer reading and writing
-    // random data, XORing it as we go.  We can detect writes in the
-    // wrong place, writes which are too long or too short, and reads
-    // or writes of the wrong data,
-    void step(Random r) {
-        data.order((r.nextInt() & 1) != 0 ? BIG_ENDIAN : LITTLE_ENDIAN);
-
-        data.rewind();
-        while (data.position() < data.capacity())
-            data.putLong(data.getLong() ^ random.nextLong());
+public class HeapByteBufferTest extends ByteBufferTest {
 
-        data.rewind();
-        while (data.position() < data.capacity())
-            data.putInt(data.getInt() ^ random.nextInt());
-
-        data.rewind();
-        while (data.position() < data.capacity())
-            data.putShort((short)(data.getShort() ^ random.nextInt()));
-
-        data.rewind();
-        while (data.position() < data.capacity())
-            data.putChar((char)(data.getChar() ^ random.nextInt()));
-
-        data.rewind();
-        while (data.position() < data.capacity()) {
-            data.putDouble(combine(data.getDouble(), random.nextLong()));
-        }
-
-        data.rewind();
-        while (data.position() < data.capacity())
-            data.putFloat(combine(data.getFloat(), random.nextInt()));
-
-        for (int i = 0; i < 100; i++) {
-            int offset = randomOffset(r, data, 8);
-            data.putLong(offset, data.getLong(offset) ^ random.nextLong());
-        }
-        for (int i = 0; i < 100; i++) {
-            int offset = randomOffset(r, data, 4);
-            data.putInt(offset, data.getInt(offset) ^ random.nextInt());
-        }
-        for (int i = 0; i < 100; i++) {
-            int offset = randomOffset(r, data, 2);
-            data.putShort(offset, (short)(data.getShort(offset) ^ random.nextInt()));
-        }
-        for (int i = 0; i < 100; i++) {
-            int offset = randomOffset(r, data, 2);
-            data.putChar(offset, (char)(data.getChar(offset) ^ random.nextInt()));
-        }
-        for (int i = 0; i < 100; i++) {
-            int offset = randomOffset(r, data, 8);
-            data.putDouble(offset, combine(data.getDouble(offset), random.nextLong()));
-        }
-        for (int i = 0; i < 100; i++) {
-            int offset = randomOffset(r, data, 4);
-            data.putFloat(offset, combine(data.getFloat(offset), random.nextInt()));
-        }
-    }
-
-    // XOR the bit pattern of a double and a long, returning the
-    // result as a double.
-    //
-    // We convert signalling NaNs to quiet NaNs.  We need to do this
-    // because some platforms (in particular legacy 80x87) do not
-    // provide transparent conversions between integer and
-    // floating-point types even when using raw conversions but
-    // quietly convert sNaN to qNaN.  This causes spurious test
-    // failures when the template interpreter uses 80x87 and the JITs
-    // use XMM registers.
-    //
-    public double combine(double prev, long bits) {
-        bits ^= Double.doubleToRawLongBits(prev);
-        double result = Double.longBitsToDouble(bits);
-        if (Double.isNaN(result)) {
-            result = Double.longBitsToDouble(bits | 0x8000000000000l);
-        }
-        return result;
-    }
-
-    // XOR the bit pattern of a float and an int, returning the result
-    // as a float.  Convert sNaNs to qNaNs.
-    public Float combine(float prev, int bits) {
-        bits ^= Float.floatToRawIntBits(prev);
-        Float result = Float.intBitsToFloat(bits);
-        if (Float.isNaN(result)) {
-            result = Float.intBitsToFloat(bits | 0x400000);
-        }
-        return result;
-    }
-
-    enum PrimitiveType {
-        BYTE(1), CHAR(2), SHORT(2), INT(4), LONG(8), FLOAT(4), DOUBLE(8);
-
-        public final int size;
-        PrimitiveType(int size) {
-            this.size = size;
-        }
-    }
-
-    void getOne(ByteBuffer b, PrimitiveType t) {
-        switch (t) {
-        case BYTE: b.get(); break;
-        case CHAR: b.getChar(); break;
-        case SHORT: b.getShort(); break;
-        case INT: b.getInt(); break;
-        case LONG: b.getLong(); break;
-        case FLOAT: b.getFloat(); break;
-        case DOUBLE: b.getDouble(); break;
-        }
-    }
-
-    void putOne(ByteBuffer b, PrimitiveType t) {
-        switch (t) {
-        case BYTE: b.put((byte)0); break;
-        case CHAR: b.putChar('0'); break;
-        case SHORT: b.putShort((short)0); break;
-        case INT: b.putInt(0); break;
-        case LONG: b.putLong(0); break;
-        case FLOAT: b.putFloat(0); break;
-        case DOUBLE: b.putDouble(0); break;
-        }
-    }
-
-    void getOne(ByteBuffer b, PrimitiveType t, int index) {
-        switch (t) {
-        case BYTE: b.get(index); break;
-        case CHAR: b.getChar(index); break;
-        case SHORT: b.getShort(index); break;
-        case INT: b.getInt(index); break;
-        case LONG: b.getLong(index); break;
-        case FLOAT: b.getFloat(index); break;
-        case DOUBLE: b.getDouble(index); break;
-        }
-    }
-
-    void putOne(ByteBuffer b, PrimitiveType t, int index) {
-        switch (t) {
-        case BYTE: b.put(index, (byte)0); break;
-        case CHAR: b.putChar(index, '0'); break;
-        case SHORT: b.putShort(index, (short)0); break;
-        case INT: b.putInt(index, 0); break;
-        case LONG: b.putLong(index, 0); break;
-        case FLOAT: b.putFloat(index, 0); break;
-        case DOUBLE: b.putDouble(index, 0); break;
-        }
-    }
-
-    void checkBoundaryConditions() {
-        for (int i = 0; i < 100; i++) {
-            int bufSize = random.nextInt(16);
-            byte[] bytes = new byte[bufSize];
-            ByteBuffer buf = ByteBuffer.wrap(bytes);
-            for (int j = 0; j < 100; j++) {
-                int offset = random.nextInt(32) - 8;
-                for (PrimitiveType t : PrimitiveType.values()) {
-                    int threw = 0;
-                    try {
-                        try {
-                            buf.position(offset);
-                            getOne(buf, t);
-                        } catch (BufferUnderflowException e) {
-                            if (offset + t.size < bufSize)
-                                throw new RuntimeException
-                                    ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
-                            threw++;
-                        } catch (IllegalArgumentException e) {
-                            if (offset >= 0 && offset + t.size < bufSize)
-                                throw new RuntimeException
-                                    ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
-                            threw++;
-                        }
-
-                        try {
-                            buf.position(offset);
-                            putOne(buf, t);
-                        } catch (BufferOverflowException e) {
-                            if (offset + t.size < bufSize)
-                                throw new RuntimeException
-                                    ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
-                            threw++;
-                        } catch (IllegalArgumentException e) {
-                            if (offset >= 0 && offset + t.size < bufSize)
-                                throw new RuntimeException
-                                    ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
-                            threw++;
-                        }
-
-                        try {
-                            putOne(buf, t, offset);
-                        } catch (IndexOutOfBoundsException e) {
-                            if (offset >= 0 && offset + t.size < bufSize)
-                                throw new RuntimeException
-                                    ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
-                            threw++;
-                        }
-
-                        try {
-                            getOne(buf, t, offset);
-                        } catch (IndexOutOfBoundsException e) {
-                            if (offset >= 0 && offset + t.size < bufSize)
-                                throw new RuntimeException
-                                    ("type = " + t + ", offset = " + offset + ", bufSize = " + bufSize, e);
-                            threw++;
-                        }
-
-                        if (threw == 0) {
-                            // Make sure that we should not have thrown.
-                            if (offset < 0 || offset + t.size > bufSize) {
-                                throw new RuntimeException
-                                    ("should have thrown but did not, type = " + t
-                                     + ", offset = " + offset + ", bufSize = " + bufSize);
-                            }
-                        } else if (threw != 4) {
-                            // If one of the {get,put} operations threw
-                            // due to an invalid offset then all four of
-                            // them should have thrown.
-                            throw new RuntimeException
-                                ("should have thrown but at least one did not, type = " + t
-                                 + ", offset = " + offset + ", bufSize = " + bufSize);
-                        }
-                    } catch (Throwable th) {
-                        throw new RuntimeException
-                            ("unexpected throw: type  = " + t + ", offset = " + offset + ", bufSize = " + bufSize, th);
-
-                    }
-                }
-            }
-        }
-    }
-
-    public void run() {
-        checkBoundaryConditions();
-
-        for (int i = 0; i < data.capacity(); i += 8) {
-            data.putLong(i, random.nextLong());
-        }
-
-        for (int i = 0; i < iterations; i++) {
-            step(random);
-        }
-
-        if (!Arrays.equals(data.array(), data.backingArray())) {
-            throw new RuntimeException();
-        }
+    public HeapByteBufferTest(long iterations, boolean direct) {
+        super(iterations, direct);
     }
 
     public static void main(String[] args) {
@@ -510,6 +45,6 @@
         if (args.length > 0)
             iterations = Long.parseLong(args[0]);
 
-        new HeapByteBufferTest(iterations).run();
+        new HeapByteBufferTest(iterations, false).run();
     }
-}
+}
\ No newline at end of file
--- a/hotspot/test/compiler/rtm/cli/RTMGenericCommandLineOptionTest.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/compiler/rtm/cli/RTMGenericCommandLineOptionTest.java	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -89,7 +89,7 @@
     @Override
     public void runTestCases() throws Throwable {
         if (Platform.isX86() || Platform.isX64() || Platform.isPPC()) {
-            if (Platform.isServer() && !Platform.isEmbedded()) {
+            if (Platform.isServer()) {
                 runX86SupportedVMTestCases();
             } else {
                 runX86UnsupportedVMTestCases();
--- a/hotspot/test/compiler/testlibrary/rtm/predicate/SupportedVM.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/compiler/testlibrary/rtm/predicate/SupportedVM.java	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,6 @@
 public class SupportedVM implements BooleanSupplier {
     @Override
     public boolean getAsBoolean() {
-        return Platform.isServer() && !Platform.isEmbedded();
+        return Platform.isServer();
     }
 }
--- a/hotspot/test/gc/TestSmallHeap.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/gc/TestSmallHeap.java	Fri Jul 29 16:11:55 2016 -0700
@@ -27,7 +27,6 @@
  * @requires vm.gc=="null"
  * @summary Verify that starting the VM with a small heap works
  * @library /testlibrary /test/lib /test/lib/share/classes
- * @ignore 8161552
  * @modules java.base/jdk.internal.misc
  * @modules java.management/sun.management
  * @build TestSmallHeap
@@ -35,7 +34,7 @@
  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestSmallHeap
  */
 
-/* Note: It would be nice to verify the minimal supported heap size (2m) here,
+/* Note: It would be nice to verify the minimal supported heap size here,
  * but we align the heap size based on the card table size. And the card table
  * size is aligned based on the minimal pages size provided by the os. This
  * means that on most platforms, where the minimal page size is 4k, we get a
@@ -44,14 +43,18 @@
  * we get a minimal heap size of 32m. We never use large pages for the card table.
  *
  * There is also no check in the VM for verifying that the maximum heap size
- * is larger than the supported minimal heap size. This means that specifying
- * -Xmx1m on the command line is fine but will give a heap of 2m (or 4m or 32m).
+ * is larger than the supported minimal heap size.
  *
- * To work around these rather strange behaviors this test uses -Xmx2m but then
+ * To work around these behaviors this test uses -Xmx4m but then
  * calculates what the expected heap size should be. The calculation is a
  * simplified version of the code in the VM. We assume that the card table will
  * use one page. Each byte in the card table corresponds to 512 bytes on the heap.
  * So, the expected heap size is page_size * 512.
+ *
+ * There is no formal requirement for the minimal value of the maximum heap size
+ * the VM should support. In most cases the VM could start with -Xmx2m.
+ * But with 2m limit GC could be triggered before VM initialization completed.
+ * Therefore we start the VM with 4M heap.
  */
 
 import jdk.test.lib.Asserts;
@@ -80,9 +83,10 @@
     }
 
     private static void verifySmallHeapSize(String gc, long expectedMaxHeap) throws Exception {
+        long minMaxHeap = 4 * 1024 * 1024;
         LinkedList<String> vmOptions = new LinkedList<>();
         vmOptions.add(gc);
-        vmOptions.add("-Xmx2m");
+        vmOptions.add("-Xmx" + minMaxHeap);
         vmOptions.add("-XX:+PrintFlagsFinal");
         vmOptions.add(VerifyHeapSize.class.getName());
 
@@ -90,6 +94,7 @@
         OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
         analyzer.shouldHaveExitValue(0);
 
+        expectedMaxHeap = Math.max(expectedMaxHeap, minMaxHeap);
         long maxHeapSize = Long.parseLong(analyzer.firstMatch("MaxHeapSize.+=\\s+(\\d+)",1));
         long actualHeapSize = Long.parseLong(analyzer.firstMatch(VerifyHeapSize.actualMsg + "(\\d+)",1));
         Asserts.assertEQ(maxHeapSize, expectedMaxHeap);
--- a/hotspot/test/gc/arguments/TestMaxHeapSizeTools.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/gc/arguments/TestMaxHeapSizeTools.java	Fri Jul 29 16:11:55 2016 -0700
@@ -106,7 +106,6 @@
   }
 
   public static void checkGenMaxHeapErgo(String gcflag) throws Exception {
-    TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 3);
     TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 4);
     TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 5);
   }
@@ -132,7 +131,6 @@
   }
 
   private static void checkValidInitialMaxHeapCombinations(String gcflag) throws Exception {
-    expectValid(new String[] { gcflag, "-XX:MaxHeapSize=2048K", "-version" });
     expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-XX:MaxHeapSize=8M", "-version" });
     expectValid(new String[] { gcflag, "-XX:MaxHeapSize=8M", "-XX:InitialHeapSize=4M", "-version" });
     expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=4M", "-version" });
--- a/hotspot/test/gc/arguments/TestParallelHeapSizeFlags.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/gc/arguments/TestParallelHeapSizeFlags.java	Fri Jul 29 16:11:55 2016 -0700
@@ -29,7 +29,6 @@
  * parallel collectors.
  * @requires vm.gc=="null"
  * @library /testlibrary /test/lib
- * @ignore 8161552
  * @modules java.base/jdk.internal.misc
  *          java.management
  * @build TestParallelHeapSizeFlags TestMaxHeapSizeTools
--- a/hotspot/test/gc/arguments/TestSelectDefaultGC.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/gc/arguments/TestSelectDefaultGC.java	Fri Jul 29 16:11:55 2016 -0700
@@ -55,14 +55,10 @@
         output.shouldHaveExitValue(0);
 
         final boolean isServer = actAsServer;
-        final boolean isEmbedded = Platform.isEmbedded();
 
         // Verify GC selection
-        // G1 is default for non-embedded server class machines
-        assertVMOption(output, "UseG1GC",            isServer && !isEmbedded);
-        // Parallel is default for embedded server class machines
-        assertVMOption(output, "UseParallelGC",      isServer && isEmbedded);
-        assertVMOption(output, "UseParallelOldGC",   isServer && isEmbedded);
+        // G1 is default for server class machines
+        assertVMOption(output, "UseG1GC",            isServer);
         // Serial is default for non-server class machines
         assertVMOption(output, "UseSerialGC",        !isServer);
         // CMS is never default
--- a/hotspot/test/gc/g1/TestGCLogMessages.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/gc/g1/TestGCLogMessages.java	Fri Jul 29 16:11:55 2016 -0700
@@ -95,6 +95,8 @@
         new LogMessageWithLevel("String Dedup Fixup", Level.INFO),
         new LogMessageWithLevel("Expand Heap After Collection", Level.INFO),
         // Free CSet
+        new LogMessageWithLevel("Free Collection Set", Level.INFO),
+        new LogMessageWithLevel("Free Collection Set Serial", Level.DEBUG),
         new LogMessageWithLevel("Young Free Collection Set", Level.DEBUG),
         new LogMessageWithLevel("Non-Young Free Collection Set", Level.DEBUG),
         // Humongous Eager Reclaim
--- a/hotspot/test/gc/g1/TestShrinkAuxiliaryData.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/gc/g1/TestShrinkAuxiliaryData.java	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -44,6 +44,7 @@
     private static final int REGION_SIZE = 1024 * 1024;
 
     private final static String[] initialOpts = new String[]{
+        "-XX:NewSize=16m",
         "-XX:MinHeapFreeRatio=10",
         "-XX:MaxHeapFreeRatio=11",
         "-XX:+UseG1GC",
--- a/hotspot/test/gc/logging/TestUnifiedLoggingSwitchStress.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/gc/logging/TestUnifiedLoggingSwitchStress.java	Fri Jul 29 16:11:55 2016 -0700
@@ -43,6 +43,7 @@
  * @summary Switches gc log level on fly while stressing memory/gc
  * @key gc
  * @key stress
+ * @requires !vm.flightRecorder
  * @library /testlibrary /test/lib /
  * @modules java.management java.base/jdk.internal.misc
  *
--- a/hotspot/test/gc/metaspace/TestMetaspaceSizeFlags.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/gc/metaspace/TestMetaspaceSizeFlags.java	Fri Jul 29 16:11:55 2016 -0700
@@ -74,8 +74,8 @@
     OutputAnalyzer output = run(maxMetaspaceSize, metaspaceSize);
     output.shouldNotMatch("Error occurred during initialization of VM\n.*");
 
-    String stringMaxMetaspaceSize = output.firstMatch(".* MaxMetaspaceSize .* := (\\d+).*", 1);
-    String stringMetaspaceSize = output.firstMatch(".* MetaspaceSize .* := (\\d+).*", 1);
+    String stringMaxMetaspaceSize = output.firstMatch(".* MaxMetaspaceSize .* = (\\d+).*", 1);
+    String stringMetaspaceSize = output.firstMatch(".* MetaspaceSize .* = (\\d+).*", 1);
 
     return new MetaspaceFlags(Long.parseLong(stringMaxMetaspaceSize),
                               Long.parseLong(stringMetaspaceSize));
--- a/hotspot/test/gc/stress/TestStressG1Humongous.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/gc/stress/TestStressG1Humongous.java	Fri Jul 29 16:11:55 2016 -0700
@@ -53,6 +53,7 @@
     private static final int THREAD_COUNT = Integer.getInteger("threads", 2);
     private static final int REGION_SIZE = Integer.getInteger("regionsize", 1) * 1024 * 1024;
     private static final int HUMONGOUS_SIZE = (int) (REGION_SIZE * Double.parseDouble(System.getProperty("humongoussize", "1.5")));
+    private static final int NUMBER_OF_FREE_REGIONS = 2;
 
     private volatile boolean isRunning;
     private final ExecutorService threadExecutor;
@@ -92,8 +93,12 @@
     private int getExpectedAmountOfObjects() {
         long maxMem = Runtime.getRuntime().maxMemory();
         int expectedHObjects = (int) (maxMem / HUMONGOUS_SIZE);
-        // Will allocate 1 region less to give some free space for VM.
-        int checkedAmountOfHObjects = checkHeapCapacity(expectedHObjects) - 1;
+        // Will allocate NUMBER_OF_FREE_REGIONS region less to give some free space for VM.
+        int checkedAmountOfHObjects = checkHeapCapacity(expectedHObjects) - NUMBER_OF_FREE_REGIONS;
+        if (checkedAmountOfHObjects <= 0) {
+            throw new RuntimeException("Cannot start testing because selected maximum heap "
+                    + "is not large enough to contain more than " + NUMBER_OF_FREE_REGIONS + " regions");
+        }
         return checkedAmountOfHObjects;
     }
 
--- a/hotspot/test/runtime/7107135/Test.java	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2011 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.
- */
-
-class Test {
-
-    static boolean loadLib(String libName){
-        try {
-            System.loadLibrary(libName);
-            System.out.println("Loaded library "+ libName + ".");
-            return true;
-        } catch (SecurityException e) {
-            System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n");
-        } catch (UnsatisfiedLinkError e) {
-            System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n");
-        }
-        return false;
-    }
-
-    public static int counter = 1;
-
-    static int Runner() {
-        counter = counter * -1;
-        int i = counter;
-        if(counter < 2) counter += Runner();
-        return i;
-    }
-
-    public static int run() {
-        try{
-            Runner();
-        } catch (StackOverflowError e) {
-            System.out.println("Caught stack overflow error.");
-            return 0;
-        } catch (OutOfMemoryError e) {
-            return 0;
-        }
-        return 2;
-    }
-
-    public static void main(String argv[]) {
-        loadLib(argv[0]);
-        System.exit(run());
-    }
-}
--- a/hotspot/test/runtime/7107135/Test7107135.sh	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-#!/bin/sh
-
-#
-#  Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
-#  Copyright (c) 2011 SAP SE. All rights reserved.
-#  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-#  This code is free software; you can redistribute it and/or modify it
-#  under the terms of the GNU General Public License version 2 only, as
-#  published by the Free Software Foundation.
-#
-#  This code is distributed in the hope that it will be useful, but WITHOUT
-#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-#  version 2 for more details (a copy is included in the LICENSE file that
-#  accompanied this code).
-#
-#  You should have received a copy of the GNU General Public License version
-#  2 along with this work; if not, write to the Free Software Foundation,
-#  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-#  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-#  or visit www.oracle.com if you need additional information or have any
-#  questions.
-#
-
-##
-## @test Test7107135.sh
-## @bug 7107135
-## @bug 8021296
-## @bug 8025519
-## @summary Stack guard pages lost after loading library with executable stack.
-## @run shell Test7107135.sh
-##
-
-if [ "${TESTSRC}" = "" ]
-then
-  TESTSRC=${PWD}
-  echo "TESTSRC not set.  Using "${TESTSRC}" as default"
-fi
-echo "TESTSRC=${TESTSRC}"
-## Adding common setup Variables for running shell tests.
-. ${TESTSRC}/../../test_env.sh
-
-# set platform-dependent variables
-OS=`uname -s`
-case "$OS" in
-  Linux)
-    echo "Testing on Linux"
-    gcc_cmd=`which gcc`
-    if [ "x$gcc_cmd" == "x" ]; then
-        echo "WARNING: gcc not found. Cannot execute test." 2>&1
-        exit 0;
-    fi
-    ;;
-  *)
-    echo "Test passed; only valid for Linux"
-    exit 0;
-    ;;
-esac
-
-ARCH=`uname -m`
-
-THIS_DIR=.
-
-cp ${TESTSRC}${FS}*.java ${THIS_DIR}
-${COMPILEJAVA}${FS}bin${FS}javac *.java
-
-$gcc_cmd -fPIC -shared -c -o test.o \
-    -I${COMPILEJAVA}${FS}include -I${COMPILEJAVA}${FS}include${FS}linux \
-    ${TESTSRC}${FS}test.c
-
-ld -shared -z   execstack -o libtest-rwx.so test.o
-ld -shared -z noexecstack -o libtest-rw.so  test.o
-
-
-LD_LIBRARY_PATH=${THIS_DIR}
-echo   LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}
-export LD_LIBRARY_PATH
-
-# This should not fail.
-echo Check testprogram. Expected to pass:
-echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rw
-${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rw
-
-echo
-echo Test changing of stack protection:
-echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rwx
-${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rwx
-JAVA_RETVAL=$?
-
-if [ "$JAVA_RETVAL" == "0" ]
-then
-  echo
-  echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} TestMT test-rwx
-  ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} TestMT test-rwx
-  JAVA_RETVAL=$?
-fi
-
-exit $JAVA_RETVAL
--- a/hotspot/test/runtime/7107135/TestMT.java	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2011 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.
- */
-
-class TestMT {
-
-    static boolean loadLib(String libName) {
-        try {
-            System.loadLibrary(libName);
-            System.out.println("Loaded library "+ libName + ".");
-            return true;
-        } catch (SecurityException e) {
-            System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n");
-        } catch (UnsatisfiedLinkError e) {
-            System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n");
-        }
-        return false;
-    }
-
-    public static int counter        = 1;
-    static int Runner() {
-        counter = counter * -1;
-        int i = counter;
-        if (counter < 2) counter += Runner();
-        return i;
-    }
-
-    public static int run(String msg) {
-        try {
-            Runner();
-        } catch (StackOverflowError e) {
-            System.out.println(msg + " caught stack overflow error.");
-            return 0;
-        } catch (OutOfMemoryError e) {
-            return 0;
-        }
-        return 2;
-    }
-
-    public static void main(String argv[]) {
-        try {
-            for (int i = 0; i < 20; i++) {
-                Thread t = new DoStackOverflow("SpawnedThread " + i);
-                t.start();
-            }
-            run("Main thread");
-            loadLib("test-rwx");
-            run("Main thread");
-        } catch (Exception e) {
-            System.out.println(e);
-        }
-    }
-
-    static class DoStackOverflow extends Thread {
-        public DoStackOverflow(String name) {
-            super(name);
-        }
-        public void run() {
-            for (int i = 0; i < 10; ++i) {
-                TestMT.run(getName());
-                yield();
-            }
-        }
-    }
-}
--- a/hotspot/test/runtime/7107135/test.c	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2011 SAP SE. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include "jni.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-JNIEXPORT jint JNICALL Java_Test_someMethod(JNIEnv *env, jobject mainObject) {
-  return 3;
-}
-
-#ifdef __cplusplus
-}
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/StackGuardPages/exeinvoke.c	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,289 @@
+/*
+ * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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.
+ *
+ */
+
+/* This code tests the fact that we actually remove stack guard page when calling
+ * JavaThread::exit() i.e. when detaching from current thread.
+ * We overflow the stack and check that we get access error because of a guard page.
+ * Than we detach from vm thread and overflow stack once again. This time we shouldn't
+ * get access error because stack guard page is removed
+ *
+ * Notice: due a complicated interaction of signal handlers, the test may crash.
+ * It's OK - don't file a bug.
+ */
+
+#include <assert.h>
+#include <jni.h>
+#include <alloca.h>
+#include <signal.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <sys/ucontext.h>
+#include <setjmp.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <errno.h>
+
+#include <pthread.h>
+
+#define CLASS_PATH_OPT "-Djava.class.path="
+
+JavaVM* _jvm;
+
+static jmp_buf  context;
+
+static int _last_si_code = -1;
+static int _failures = 0;
+static int _rec_count = 0;
+static int _kp_rec_count = 0;
+
+pid_t gettid() {
+  return (pid_t) syscall(SYS_gettid);
+}
+
+static void handler(int sig, siginfo_t *si, void *unused) {
+  _last_si_code = si->si_code;
+  printf("Got SIGSEGV(%d) at address: 0x%lx\n",si->si_code, (long) si->si_addr);
+  longjmp(context, 1);
+}
+
+void set_signal_handler() {
+  static char altstack[SIGSTKSZ];
+
+  stack_t ss = {
+    .ss_size = SIGSTKSZ,
+    .ss_flags = 0,
+    .ss_sp = altstack
+  };
+
+  struct sigaction sa = {
+    .sa_sigaction = handler,
+    .sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESETHAND
+  };
+
+  _last_si_code = -1;
+
+  sigaltstack(&ss, 0);
+  sigemptyset(&sa.sa_mask);
+  if (sigaction(SIGSEGV, &sa, NULL) == -1) {
+    fprintf(stderr, "Test ERROR. Can't set sigaction (%d)\n", errno);
+    exit(7);
+  }
+}
+
+void *run_java_overflow (void *p) {
+  JNIEnv *env;
+  jclass class_id;
+  jmethodID method_id;
+  int res;
+
+  res = (*_jvm)->AttachCurrentThread(_jvm, (void**)&env, NULL);
+  if (res != JNI_OK) {
+    fprintf(stderr, "Test ERROR. Can't attach to current thread\n");
+    exit(7);
+  }
+
+  class_id = (*env)->FindClass (env, "DoOverflow");
+  if (class_id == NULL) {
+    fprintf(stderr, "Test ERROR. Can't load class DoOverflow\n");
+    exit(7);
+  }
+
+  method_id = (*env)->GetStaticMethodID(env, class_id, "printIt", "()V");
+  if (method_id == NULL) {
+    fprintf(stderr, "Test ERROR. Can't find method DoOverflow.printIt\n");
+    exit(7);
+  }
+
+  (*env)->CallStaticVoidMethod(env, class_id, method_id, NULL);
+
+  res = (*_jvm)->DetachCurrentThread(_jvm);
+  if (res != JNI_OK) {
+    fprintf(stderr, "Test ERROR. Can't call detach from current thread\n");
+    exit(7);
+  }
+  return NULL;
+}
+
+void do_overflow(){
+  int *p = alloca(sizeof(int));
+  if (_kp_rec_count == 0 || _rec_count < _kp_rec_count) {
+      _rec_count ++;
+      do_overflow();
+  }
+}
+
+void *run_native_overflow(void *p) {
+  // Test that stack guard page is correctly set for initial and non initial thread
+  // and correctly removed for the initial thread
+  JNIEnv *env;
+  jclass class_id;
+  jmethodID method_id;
+  int res;
+
+  printf("run_native_overflow %ld\n", (long) gettid());
+
+  res = (*_jvm)->AttachCurrentThread(_jvm, (void **)&env, NULL);
+  if (res != JNI_OK) {
+    fprintf(stderr, "Test ERROR. Can't attach to current thread\n");
+    exit(7);
+  }
+
+  class_id = (*env)->FindClass (env, "DoOverflow");
+  if (class_id == NULL) {
+    fprintf(stderr, "Test ERROR. Can't load class DoOverflow\n");
+    exit(7);
+  }
+
+  method_id = (*env)->GetStaticMethodID (env, class_id, "printAlive", "()V");
+  if (method_id == NULL) {
+    fprintf(stderr, "Test ERROR. Can't find method DoOverflow.printAlive\n");
+    exit(7);
+  }
+
+  (*env)->CallStaticVoidMethod (env, class_id, method_id, NULL);
+
+  set_signal_handler();
+  if (! setjmp(context)) {
+    do_overflow();
+  }
+
+  if (_last_si_code == SEGV_ACCERR) {
+    printf("Test PASSED. Got access violation accessing guard page at %d\n", _rec_count);
+  }
+
+  res = (*_jvm)->DetachCurrentThread(_jvm);
+  if (res != JNI_OK) {
+    fprintf(stderr, "Test ERROR. Can't call detach from current thread\n");
+    exit(7);
+  }
+
+  if (getpid() != gettid()) {
+    // For non-initial thread we don't unmap the region but call os::uncommit_memory and keep PROT_NONE
+    // so if host has enough swap space we will get the same SEGV with code SEGV_ACCERR(2) trying
+    // to access it as if the guard page is present.
+    // We have no way to check this, so bail out, marking test as succeeded
+    printf("Test PASSED. Not initial thread\n");
+    return NULL;
+  }
+
+  // Limit depth of recursion for second run. It can't exceed one for first run.
+  _kp_rec_count = _rec_count;
+  _rec_count = 0;
+
+  set_signal_handler();
+  if (! setjmp(context)) {
+    do_overflow();
+  }
+
+  if (_last_si_code == SEGV_ACCERR) {
+      ++ _failures;
+      fprintf(stderr,"Test FAILED. Stack guard page is still there at %d\n", _rec_count);
+  } else if (_last_si_code == -1) {
+      printf("Test PASSED. No stack guard page is present. Maximum recursion level reached at %d\n", _rec_count);
+  }
+  else{
+      printf("Test PASSED. No stack guard page is present. SIGSEGV(%d) at %d\n", _last_si_code, _rec_count);
+  }
+
+  return NULL;
+}
+
+void usage() {
+  fprintf(stderr, "Usage: invoke test_java_overflow\n");
+  fprintf(stderr, "       invoke test_native_overflow\n");
+}
+
+
+int main (int argc, const char** argv) {
+  JavaVMInitArgs vm_args;
+  JavaVMOption options[3];
+  JNIEnv* env;
+  int optlen;
+  char *javaclasspath = NULL;
+  char javaclasspathopt[4096];
+
+  printf("Test started with pid: %ld\n", (long) getpid());
+
+  /* set the java class path so the DoOverflow class can be found */
+  javaclasspath = getenv("CLASSPATH");
+
+  if (javaclasspath == NULL) {
+    fprintf(stderr, "Test ERROR. CLASSPATH is not set\n");
+    exit(7);
+  }
+  optlen = strlen(CLASS_PATH_OPT) + strlen(javaclasspath) + 1;
+  if (optlen > 4096) {
+    fprintf(stderr, "Test ERROR. CLASSPATH is too long\n");
+    exit(7);
+  }
+  snprintf(javaclasspathopt, sizeof(javaclasspathopt), "%s%s",
+      CLASS_PATH_OPT, javaclasspath);
+
+  options[0].optionString = "-Xint";
+  options[1].optionString = "-Xss328k";
+  options[2].optionString = javaclasspathopt;
+
+  vm_args.version = JNI_VERSION_1_2;
+  vm_args.ignoreUnrecognized = JNI_TRUE;
+  vm_args.options = options;
+  vm_args.nOptions = 3;
+
+  if (JNI_CreateJavaVM (&_jvm, (void **)&env, &vm_args) < 0 ) {
+    fprintf(stderr, "Test ERROR. Can't create JavaVM\n");
+    exit(7);
+  }
+
+  pthread_t thr;
+
+  if (argc > 1 && strcmp(argv[1], "test_java_overflow") == 0) {
+    printf("\nTesting JAVA_OVERFLOW\n");
+
+    printf("Testing stack guard page behaviour for other thread\n");
+    pthread_create (&thr, NULL, run_java_overflow, NULL);
+    pthread_join (thr, NULL);
+
+    printf("Testing stack guard page behaviour for initial thread\n");
+    run_java_overflow(NULL);
+    // This test crash on error
+    exit(0);
+  }
+
+  if (argc > 1 && strcmp(argv[1], "test_native_overflow") == 0) {
+    printf("\nTesting NATIVE_OVERFLOW\n");
+
+    printf("Testing stack guard page behaviour for other thread\n");
+    pthread_create (&thr, NULL, run_native_overflow, NULL);
+    pthread_join (thr, NULL);
+
+    printf("Testing stack guard page behaviour for initial thread\n");
+    run_native_overflow(NULL);
+
+    exit((_failures > 0) ? 1 : 0);
+  }
+
+  fprintf(stderr, "Test ERROR. Unknown parameter %s\n", ((argc > 1) ? argv[1] : "none"));
+  usage();
+  exit(7);
+}
--- a/hotspot/test/runtime/StackGuardPages/invoke.c	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,266 +0,0 @@
-/*
- * Copyright (c) 2010, 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.
- *
- */
-
-/* This code tests the fact that we actually remove stack guard page when calling
- * JavaThread::exit() i.e. when detaching from current thread.
- * We overflow the stack and check that we get access error because of a guard page.
- * Than we detach from vm thread and overflow stack once again. This time we shouldn't
- * get access error because stack guard page is removed
- *
- * Notice: due a complicated interaction of signal handlers, the test may crash.
- * It's OK - don't file a bug.
- */
-
-#include <assert.h>
-#include <jni.h>
-#include <alloca.h>
-#include <signal.h>
-#include <sys/mman.h>
-#include <stdlib.h>
-#include <sys/ucontext.h>
-#include <setjmp.h>
-#include <unistd.h>
-#include <sys/syscall.h>
-#include <errno.h>
-
-#include <pthread.h>
-
-JavaVM* _jvm;
-
-static jmp_buf  context;
-
-static int _last_si_code = -1;
-static int _failures = 0;
-static int _rec_count = 0;
-static int _kp_rec_count = 0;
-
-pid_t gettid() {
-  return (pid_t) syscall(SYS_gettid);
-}
-
-static void handler(int sig, siginfo_t *si, void *unused) {
-  _last_si_code = si->si_code;
-  printf("Got SIGSEGV(%d) at address: 0x%lx\n",si->si_code, (long) si->si_addr);
-  longjmp(context, 1);
-}
-
-void set_signal_handler() {
-  static char altstack[SIGSTKSZ];
-
-  stack_t ss = {
-    .ss_size = SIGSTKSZ,
-    .ss_flags = 0,
-    .ss_sp = altstack
-  };
-
-  struct sigaction sa = {
-    .sa_sigaction = handler,
-    .sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESETHAND
-  };
-
-  _last_si_code = -1;
-
-  sigaltstack(&ss, 0);
-  sigemptyset(&sa.sa_mask);
-  if (sigaction(SIGSEGV, &sa, NULL) == -1) {
-    fprintf(stderr, "Test ERROR. Can't set sigaction (%d)\n", errno);
-    exit(7);
-  }
-}
-
-void *run_java_overflow (void *p) {
-  JNIEnv *env;
-  jclass class_id;
-  jmethodID method_id;
-  int res;
-
-  res = (*_jvm)->AttachCurrentThread(_jvm, (void**)&env, NULL);
-  if (res != JNI_OK) {
-    fprintf(stderr, "Test ERROR. Can't attach to current thread\n");
-    exit(7);
-  }
-
-  class_id = (*env)->FindClass (env, "DoOverflow");
-  if (class_id == NULL) {
-    fprintf(stderr, "Test ERROR. Can't load class DoOverflow\n");
-    exit(7);
-  }
-
-  method_id = (*env)->GetStaticMethodID(env, class_id, "printIt", "()V");
-  if (method_id == NULL) {
-    fprintf(stderr, "Test ERROR. Can't find method DoOverflow.printIt\n");
-    exit(7);
-  }
-
-  (*env)->CallStaticVoidMethod(env, class_id, method_id, NULL);
-
-  res = (*_jvm)->DetachCurrentThread(_jvm);
-  if (res != JNI_OK) {
-    fprintf(stderr, "Test ERROR. Can't call detach from current thread\n");
-    exit(7);
-  }
-}
-
-void do_overflow(){
-  int *p = alloca(sizeof(int));
-  if (_kp_rec_count == 0 || _rec_count < _kp_rec_count) {
-      _rec_count ++;
-      do_overflow();
-  }
-}
-
-void *run_native_overflow(void *p) {
-  // Test that stack guard page is correctly set for initial and non initial thread
-  // and correctly removed for the initial thread
-  JNIEnv *env;
-  jclass class_id;
-  jmethodID method_id;
-  int res;
-
-  printf("run_native_overflow %ld\n", (long) gettid());
-
-  res = (*_jvm)->AttachCurrentThread(_jvm, (void **)&env, NULL);
-  if (res != JNI_OK) {
-    fprintf(stderr, "Test ERROR. Can't attach to current thread\n");
-    exit(7);
-  }
-
-  class_id = (*env)->FindClass (env, "DoOverflow");
-  if (class_id == NULL) {
-    fprintf(stderr, "Test ERROR. Can't load class DoOverflow\n");
-    exit(7);
-  }
-
-  method_id = (*env)->GetStaticMethodID (env, class_id, "printAlive", "()V");
-  if (method_id == NULL) {
-    fprintf(stderr, "Test ERROR. Can't find method DoOverflow.printAlive\n");
-    exit(7);
-  }
-
-  (*env)->CallStaticVoidMethod (env, class_id, method_id, NULL);
-
-  set_signal_handler();
-  if (! setjmp(context)) {
-    do_overflow();
-  }
-
-  if (_last_si_code == SEGV_ACCERR) {
-    printf("Test PASSED. Got access violation accessing guard page at %d\n", _rec_count);
-  }
-
-  res = (*_jvm)->DetachCurrentThread(_jvm);
-  if (res != JNI_OK) {
-    fprintf(stderr, "Test ERROR. Can't call detach from current thread\n");
-    exit(7);
-  }
-
-  if (getpid() != gettid()) {
-    // For non-initial thread we don't unmap the region but call os::uncommit_memory and keep PROT_NONE
-    // so if host has enough swap space we will get the same SEGV with code SEGV_ACCERR(2) trying
-    // to access it as if the guard page is present.
-    // We have no way to check this, so bail out, marking test as succeeded
-    printf("Test PASSED. Not initial thread\n");
-    return NULL;
-  }
-
-  // Limit depth of recursion for second run. It can't exceed one for first run.
-  _kp_rec_count = _rec_count;
-  _rec_count = 0;
-
-  set_signal_handler();
-  if (! setjmp(context)) {
-    do_overflow();
-  }
-
-  if (_last_si_code == SEGV_ACCERR) {
-      ++ _failures;
-      fprintf(stderr,"Test FAILED. Stack guard page is still there at %d\n", _rec_count);
-  } else if (_last_si_code == -1) {
-      printf("Test PASSED. No stack guard page is present. Maximum recursion level reached at %d\n", _rec_count);
-  }
-  else{
-      printf("Test PASSED. No stack guard page is present. SIGSEGV(%d) at %d\n", _last_si_code, _rec_count);
-  }
-
-  return NULL;
-}
-
-void usage() {
-  fprintf(stderr, "Usage: invoke test_java_overflow\n");
-  fprintf(stderr, "       invoke test_native_overflow\n");
-  exit(7);
-}
-
-
-int main (int argc, const char** argv) {
-  JavaVMInitArgs vm_args;
-  JavaVMOption options[2];
-  JNIEnv* env;
-
-  printf("Test started with pid: %ld\n", (long) getpid());
-
-  options[0].optionString = "-Xint";
-  options[1].optionString = "-Xss512k";
-
-  vm_args.version = JNI_VERSION_1_2;
-  vm_args.ignoreUnrecognized = JNI_TRUE;
-  vm_args.options = options;
-  vm_args.nOptions = 2;
-
-  if (JNI_CreateJavaVM (&_jvm, (void **)&env, &vm_args) < 0 ) {
-    fprintf(stderr, "Test ERROR. Can't create JavaVM\n");
-    exit(7);
-  }
-
-  pthread_t thr;
-
-  if (argc > 1 && strcmp(argv[1], "test_java_overflow") == 0) {
-    printf("\nTesting JAVA_OVERFLOW\n");
-
-    printf("Testing stack guard page behaviour for other thread\n");
-    pthread_create (&thr, NULL, run_java_overflow, NULL);
-    pthread_join (thr, NULL);
-
-    printf("Testing stack guard page behaviour for initial thread\n");
-    run_java_overflow(NULL);
-    // This test crash on error
-    exit(0);
-  }
-
-  if (argc > 1 && strcmp(argv[1], "test_native_overflow") == 0) {
-    printf("\nTesting NATIVE_OVERFLOW\n");
-
-    printf("Testing stack guard page behaviour for other thread\n");
-    pthread_create (&thr, NULL, run_native_overflow, NULL);
-    pthread_join (thr, NULL);
-
-    printf("Testing stack guard page behaviour for initial thread\n");
-    run_native_overflow(NULL);
-
-    exit((_failures > 0) ? 1 : 0);
-  }
-
-  fprintf(stderr, "Test ERROR. Unknown parameter %s\n", ((argc > 1) ? argv[1] : "none"));
-  usage();
-}
--- a/hotspot/test/runtime/StackGuardPages/testme.sh	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/runtime/StackGuardPages/testme.sh	Fri Jul 29 16:11:55 2016 -0700
@@ -1,8 +1,29 @@
+# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
 #!/bin/sh
 
 #
 # @test testme.sh
 # @summary Stack guard pages should be installed correctly and removed when thread is detached
+# @compile DoOverflow.java
 # @run shell testme.sh
 #
 
@@ -21,40 +42,10 @@
   exit 0
 fi
 
-gcc_cmd=`which gcc`
-if [ "x$gcc_cmd" = "x" ]; then
-  echo "WARNING: gcc not found. Cannot execute test." 2>&1
-  exit 0;
-fi
-
-CFLAGS=-m${VM_BITS}
-
 LD_LIBRARY_PATH=.:${TESTJAVA}/jre/lib/${VM_CPU}/${VM_TYPE}:${TESTJAVA}/lib/${VM_CPU}/${VM_TYPE}:/usr/lib:$LD_LIBRARY_PATH
 export LD_LIBRARY_PATH
 
-echo "Architecture: ${VM_CPU}"
-echo "Compilation flag: ${CFLAGS}"
-echo "VM type: ${VM_TYPE}"
-echo "LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}"
-
-# Note pthread may not be found thus invoke creation will fail to be created.
-# Check to ensure you have a /usr/lib/libpthread.so if you don't please look
-# for /usr/lib/`uname -m`-linux-gnu version ensure to add that path to below compilation.
-
-cp ${TESTSRC}/DoOverflow.java .
-${COMPILEJAVA}/bin/javac DoOverflow.java
-
-$gcc_cmd -DLINUX -g3 ${CFLAGS} -o invoke \
-    -I${TESTJAVA}/include -I${TESTJAVA}/include/linux \
-    -L${TESTJAVA}/jre/lib/${VM_CPU}/${VM_TYPE} \
-    -L${TESTJAVA}/lib/${VM_CPU}/${VM_TYPE} \
-     ${TESTSRC}/invoke.c -ljvm -lpthread
-
-if [ $? -ne 0 ] ; then
-    echo "Compile failed, Ignoring failed compilation and forcing the test to pass"
-    exit 0
-fi
-
-./invoke test_java_overflow
-./invoke test_native_overflow
+# Run the test for a java and native overflow
+${TESTNATIVEPATH}/invoke test_java_overflow
+${TESTNATIVEPATH}/invoke test_native_overflow
 exit $?
--- a/hotspot/test/runtime/Unsafe/GetUnsafe.java	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-/*
- * @test
- * @summary Verifies that getUnsafe() actually throws SecurityException when unsafeAccess is prohibited.
- * @library /testlibrary
- * @modules java.base/jdk.internal.misc
- * @ignore 8161947
- * @run main GetUnsafe
- */
-
-import jdk.internal.misc.Unsafe;
-import static jdk.test.lib.Asserts.*;
-
-public class GetUnsafe {
-    public static void main(String args[]) throws Exception {
-        try {
-            Unsafe unsafe = Unsafe.getUnsafe();
-        } catch (SecurityException e) {
-            // Expected
-            return;
-        }
-        throw new RuntimeException("Did not get expected SecurityException");
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/execstack/Test.java	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2002-2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011 SAP AG.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+class Test {
+
+    static boolean loadLib(String libName){
+        try {
+            System.loadLibrary(libName);
+            System.out.println("Loaded library "+ libName + ".");
+            return true;
+        } catch (SecurityException e) {
+            System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n");
+        } catch (UnsatisfiedLinkError e) {
+            System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n");
+        }
+        return false;
+    }
+
+    public static int counter = 1;
+
+    static int Runner() {
+        counter = counter * -1;
+        int i = counter;
+        if (counter < 2) counter += Runner();
+        return i;
+    }
+
+    public static int run() {
+        try{
+            Runner();
+        } catch (StackOverflowError e) {
+            System.out.println("Caught stack overflow error.");
+            return 0;
+        } catch (OutOfMemoryError e) {
+            return 0;
+        }
+        return 2;
+    }
+
+    public static void main(String argv[]) {
+        loadLib(argv[0]);
+        System.exit(run());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/execstack/TestMT.java	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2002-2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011 SAP AG.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+class TestMT {
+
+    static boolean loadLib(String libName) {
+        try {
+            System.loadLibrary(libName);
+            System.out.println("Loaded library "+ libName + ".");
+            return true;
+        } catch (SecurityException e) {
+            System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n");
+        } catch (UnsatisfiedLinkError e) {
+            System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n");
+        }
+        return false;
+    }
+
+    public static int counter = 1;
+    static int Runner() {
+        counter = counter * -1;
+        int i = counter;
+        if (counter < 2) counter += Runner();
+        return i;
+    }
+
+    public static int run(String msg) {
+        try {
+            Runner();
+        } catch (StackOverflowError e) {
+            System.out.println(msg + " caught stack overflow error.");
+            return 0;
+        } catch (OutOfMemoryError e) {
+            return 0;
+        }
+        return 2;
+    }
+
+    public static void main(String argv[]) {
+        try {
+            for (int i = 0; i < 20; i++) {
+                Thread t = new DoStackOverflow("SpawnedThread " + i);
+                t.start();
+            }
+            run("Main thread");
+            loadLib("test-rwx");
+            run("Main thread");
+        } catch (Exception e) {
+            System.out.println(e);
+        }
+    }
+
+    static class DoStackOverflow extends Thread {
+        public DoStackOverflow(String name) {
+            super(name);
+        }
+        public void run() {
+            for (int i = 0; i < 10; ++i) {
+                TestMT.run(getName());
+                yield();
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/execstack/Testexecstack.java	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test Testexecstack.java
+ * @bug 7107135
+ * @bug 8021296
+ * @bug 8025519
+ * @summary Stack guard pages lost after loading library with executable stack.
+ * @requires (os.family == "linux")
+ * @library /testlibrary
+ * @build jdk.test.lib.*
+ * @compile Test.java
+ * @compile TestMT.java
+ * @run driver Testexecstack
+ */
+
+import jdk.test.lib.*;
+
+public class Testexecstack {
+
+    public static void main(String[] args) throws Throwable {
+
+        // Get the library path property
+        String libpath = System.getProperty("java.library.path");
+
+        // Create a new java process for the Test Java/JNI test without
+        // an executeable stack
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+            "-Djava.library.path=" + libpath + ":.", "Test", "test-rw");
+
+        // Start the process and check the output
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        output.shouldHaveExitValue(0);
+
+        // Create a new java process for the Test Java/JNI test with an
+        // executable stack
+        pb = ProcessTools.createJavaProcessBuilder(
+            "-Djava.library.path=" + libpath + ":.", "Test", "test-rwx");
+
+        // Start the process and check the output
+        output = new OutputAnalyzer(pb.start());
+        output.shouldHaveExitValue(0);
+
+        // Create a new java process for the TestMT Java/JNI test with an
+        // executable stack
+        pb = ProcessTools.createJavaProcessBuilder(
+            "-Djava.library.path=" + libpath + ":.", "TestMT", "test-rwx");
+
+        // Start the process and check the output
+        output = new OutputAnalyzer(pb.start());
+        output.shouldHaveExitValue(0);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/execstack/libtest-rw.c	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2002-2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011 SAP AG.  All Rights Reserved.
+ * 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.
+ */
+
+/*
+ * This source file is the same as libtest-rwx.c and needs to be a separate
+ * file so it can be built with "-z noexecstack" by the build process.
+ * If any changes are made they probably also need to be made to libtest-rwx.c.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "jni.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+JNIEXPORT jint JNICALL Java_Test_someMethod(JNIEnv *env, jobject mainObject) {
+  return 3;
+}
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/execstack/libtest-rwx.c	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2002-2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011 SAP AG.  All Rights Reserved.
+ * 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.
+ */
+
+/*
+ * This source file is the same as libtest-rw.c and needs to be a separate
+ * file so it can be built with "-z execstack" by the build process.
+ * If any changes are made they probably also need to be made to libtest-rwx.c.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "jni.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+JNIEXPORT jint JNICALL Java_Test_someMethod(JNIEnv *env, jobject mainObject) {
+  return 3;
+}
+
+#ifdef __cplusplus
+}
+#endif
--- a/hotspot/test/runtime/jsig/Test8017498.sh	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-#!/bin/sh
-
-#
-#  Copyright (c) 2013, 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.
-#
-
-##
-## @test Test8017498.sh
-## @bug 8017498
-## @bug 8020791
-## @bug 8021296
-## @bug 8022301
-## @bug 8025519
-## @summary sigaction(sig) results in process hang/timed-out if sig is much greater than SIGRTMAX
-## @run shell/timeout=60 Test8017498.sh
-##
-
-if [ -z "${TESTSRC}" ]; then
-  TESTSRC="${PWD}"
-  echo "TESTSRC not set.  Using "${TESTSRC}" as default"
-fi
-
-echo "TESTSRC=${TESTSRC}"
-## Adding common setup Variables for running shell tests.
-. ${TESTSRC}/../../test_env.sh
-
-EXTRA_CFLAG=
-
-# set platform-dependent variables
-OS=`uname -s`
-case "$OS" in
-  Linux)
-    echo "Testing on Linux"
-    gcc_cmd=`which gcc`
-    if [ -z "$gcc_cmd" ]; then
-        echo "WARNING: gcc not found. Cannot execute test." 2>&1
-        exit 0;
-    fi
-    MY_LD_PRELOAD=${TESTJAVA}${FS}jre${FS}lib${FS}${VM_CPU}${FS}libjsig.so
-    if [ "$VM_BITS" = "32" ] && [ "$VM_CPU" != "arm" ] && [ "$VM_CPU" != "ppc" ]; then
-        EXTRA_CFLAG=-m32
-    fi
-    echo MY_LD_PRELOAD = ${MY_LD_PRELOAD}
-    ;;
-  *)
-    echo "Test passed; only valid for Linux"
-    exit 0;
-    ;;
-esac
-
-THIS_DIR=.
-
-cp "${TESTSRC}${FS}"*.java "${THIS_DIR}"
-${COMPILEJAVA}${FS}bin${FS}javac *.java
-
-$gcc_cmd -DLINUX -fPIC -shared \
-    ${EXTRA_CFLAG} -z noexecstack \
-    -o libTestJNI.so \
-    -I${COMPILEJAVA}${FS}include \
-    -I${COMPILEJAVA}${FS}include${FS}linux \
-    ${TESTSRC}${FS}TestJNI.c
-
-if [ $? -ne 0 ] ; then
-    echo "Compile failed, Ignoring failed compilation and forcing the test to pass"
-    exit 0
-fi
-
-# run the java test in the background
-cmd="LD_PRELOAD=$MY_LD_PRELOAD \
-    ${TESTJAVA}${FS}bin${FS}java \
-    -Djava.library.path=. -server TestJNI 100"
-echo "$cmd > test.out"
-eval $cmd > test.out
-
-if grep "old handler" test.out > ${NULL}; then
-    echo "Test Passed"
-    exit 0
-fi
-
-echo "Test Failed"
-exit 1
--- a/hotspot/test/runtime/jsig/TestJNI.c	Wed Jul 05 22:01:28 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#include <stdio.h>
-#include <jni.h>
-#include <signal.h>
-#include <sys/ucontext.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void sig_handler(int sig, siginfo_t *info, ucontext_t *context) {
-
-    printf( " HANDLER (1) " );
-}
-
-JNIEXPORT void JNICALL Java_TestJNI_doSomething(JNIEnv *env, jclass klass, jint val) {
-    struct sigaction act;
-    struct sigaction oact;
-
-    act.sa_flags = SA_ONSTACK|SA_RESTART|SA_SIGINFO;
-    sigfillset(&act.sa_mask);
-    act.sa_handler = SIG_DFL;
-    act.sa_sigaction = (void (*)())sig_handler;
-    sigaction(0x20+val, &act, &oact);
-
-    printf( " doSomething(%d) " , val);
-    printf( " old handler = %p " , oact.sa_handler);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/jsig/libTestJNI.c	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <stdio.h>
+#include <jni.h>
+#include <signal.h>
+#include <sys/ucontext.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void sig_handler(int sig, siginfo_t *info, ucontext_t *context) {
+
+    printf( " HANDLER (1) " );
+}
+
+JNIEXPORT void JNICALL Java_TestJNI_doSomething(JNIEnv *env, jclass klass, jint val) {
+    struct sigaction act;
+    struct sigaction oact;
+
+    act.sa_flags = SA_ONSTACK|SA_RESTART|SA_SIGINFO;
+    sigfillset(&act.sa_mask);
+    act.sa_handler = SIG_DFL;
+    act.sa_sigaction = (void (*)())sig_handler;
+    sigaction(0x20+val, &act, &oact);
+
+    printf( " doSomething(%d) " , val);
+    printf( " old handler = %p " , oact.sa_handler);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
--- a/hotspot/test/runtime/logging/MonitorMismatchTest.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/runtime/logging/MonitorMismatchTest.java	Fri Jul 29 16:11:55 2016 -0700
@@ -39,23 +39,21 @@
 public class MonitorMismatchTest {
 
     public static void main(String... args) throws Exception {
-        if (!Platform.isEmbedded()){
-            // monitormismatch should turn on.
-            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xcomp",
-                                                                      "-XX:+TieredCompilation",
-                                                                      "-Xlog:monitormismatch=info",
-                                                                      "MonitorMismatchHelper");
-            OutputAnalyzer o = new OutputAnalyzer(pb.start());
-            o.shouldContain("[monitormismatch] Monitor mismatch in method");
+        // monitormismatch should turn on.
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xcomp",
+                                                                  "-XX:+TieredCompilation",
+                                                                  "-Xlog:monitormismatch=info",
+                                                                  "MonitorMismatchHelper");
+        OutputAnalyzer o = new OutputAnalyzer(pb.start());
+        o.shouldContain("[monitormismatch] Monitor mismatch in method");
 
-            // monitormismatch should turn off.
-            pb = ProcessTools.createJavaProcessBuilder("-Xcomp",
-                                                       "-XX:+TieredCompilation",
-                                                       "-Xlog:monitormismatch=off",
-                                                       "MonitorMismatchHelper");
-            o = new OutputAnalyzer(pb.start());
-            o.shouldNotContain("[monitormismatch]");
-        }
+        // monitormismatch should turn off.
+        pb = ProcessTools.createJavaProcessBuilder("-Xcomp",
+                                                   "-XX:+TieredCompilation",
+                                                   "-Xlog:monitormismatch=off",
+                                                   "MonitorMismatchHelper");
+        o = new OutputAnalyzer(pb.start());
+        o.shouldNotContain("[monitormismatch]");
     };
 
 }
--- a/hotspot/test/runtime/modules/JVMDefineModule.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/runtime/modules/JVMDefineModule.java	Fri Jul 29 16:11:55 2016 -0700
@@ -77,7 +77,7 @@
             ModuleHelper.DefineModule(new Object(),  "9.0", "mymodule/here", new String[] { "mypackage1" });
             throw new RuntimeException("Failed to get expected IAE or NPE for bad module");
         } catch(IllegalArgumentException e) {
-            if (!e.getMessage().contains("module is not a subclass")) {
+            if (!e.getMessage().contains("module is not an instance of type java.lang.reflect.Module")) {
               throw new RuntimeException("Failed to get expected IAE message for bad module: " + e.getMessage());
             }
         }
--- a/hotspot/test/serviceability/dcmd/compiler/CompilerQueueTest.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/serviceability/dcmd/compiler/CompilerQueueTest.java	Fri Jul 29 16:11:55 2016 -0700
@@ -29,6 +29,10 @@
  *          java.compiler
  *          java.management
  *          jdk.jvmstat/sun.jvmstat.monitor
+ * @summary Test of diagnostic command Compiler.queue
+ * Fails intermittently on 32-bit VMs due to 8158756 so quarantine
+ * it on those platforms:
+ * @requires vm.bits != "32"
  * @build jdk.test.lib.*
  *        jdk.test.lib.dcmd.*
  *        sun.hotspot.WhiteBox
@@ -38,7 +42,6 @@
  * @run testng/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -Xmixed -XX:+WhiteBoxAPI CompilerQueueTest
  * @run testng/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -Xmixed -XX:-TieredCompilation -XX:+WhiteBoxAPI CompilerQueueTest
  * @run testng/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -Xint -XX:+WhiteBoxAPI CompilerQueueTest
- * @summary Test of diagnostic command Compiler.queue
  */
 
 import compiler.testlibrary.CompilerUtils;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/serviceability/jvmti/ExceptionCaughtOutOfPhase/ExceptionCaughtOutOfPhaseTest.java	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/*
+ * @test
+ * @bug 8134434
+ * @summary JVM_DoPrivileged() fires assert(_exception_caught == false) failed: _exception_caught is out of phase
+ * @run main/othervm -agentlib:jdwp=transport=dt_socket,address=9000,server=y,suspend=n -Xbatch ExceptionCaughtOutOfPhaseTest
+ */
+
+public class ExceptionCaughtOutOfPhaseTest {
+    public static void main(String[] args) {
+        PrivilegedAction action = new HotThrowingAction();
+        System.out.println("### Warm-up");
+        for(int i=0; i<11000; i++) {
+            try {
+                action.run(); // call run() to get it compiled
+            } catch(Throwable t) {
+                // ignored
+            }
+        }
+
+        System.out.println("### Warm-up done");
+        System.out.println("### Executing privileged action");
+
+        try {
+            AccessController.doPrivileged(action);
+        } catch (Error e) {
+            // ignored
+        }
+    }
+
+    public static class HotThrowingAction implements PrivilegedAction {
+        public Object run() {
+            throw new Error();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/serviceability/jvmti/GetModulesInfo/JvmtiGetAllModulesTest.java	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary Verifies the JVMTI GetAllModules API
+ * @library /testlibrary
+ * @run main/othervm -agentlib:JvmtiGetAllModulesTest JvmtiGetAllModulesTest
+ *
+ */
+import java.lang.reflect.Layer;
+import java.lang.reflect.Module;
+import java.lang.module.ModuleReference;
+import java.lang.module.ModuleFinder;
+import java.lang.module.ModuleReader;
+import java.lang.module.ModuleDescriptor;
+import java.lang.module.Configuration;
+import java.util.Arrays;
+import java.util.Set;
+import java.util.Map;
+import java.util.function.Supplier;
+import java.util.Objects;
+import java.util.Optional;
+import java.net.URI;
+import java.util.HashSet;
+import java.util.HashMap;
+import java.util.stream.Collectors;
+import jdk.test.lib.Asserts;
+
+public class JvmtiGetAllModulesTest {
+
+    private static native Module[] getModulesNative();
+
+    private static Set<Module> getModulesJVMTI() {
+
+        Set<Module> modules = Arrays.stream(getModulesNative()).collect(Collectors.toSet());
+
+        // JVMTI reports unnamed modules, Java API does not
+        // remove the unnamed modules here, so the resulting report can be expected
+        // to be equal to what Java reports
+        modules.removeIf(mod -> !mod.isNamed());
+
+        return modules;
+    }
+
+    public static void main(String[] args) throws Exception {
+
+        final String MY_MODULE_NAME = "myModule";
+
+        // Verify that JVMTI reports exactly the same info as Java regarding the named modules
+        Asserts.assertEquals(Layer.boot().modules(), getModulesJVMTI());
+
+        // Load a new named module
+        ModuleDescriptor descriptor
+                = new ModuleDescriptor.Builder(MY_MODULE_NAME)
+                .build();
+        ModuleFinder finder = finderOf(descriptor);
+        ClassLoader loader = new ClassLoader() {};
+        Configuration parent = Layer.boot().configuration();
+        Configuration cf = parent.resolveRequires(finder, ModuleFinder.of(), Set.of(MY_MODULE_NAME));
+        Layer my = Layer.boot().defineModules(cf, m -> loader);
+
+        // Verify that the loaded module is indeed reported by JVMTI
+        Set<Module> jvmtiModules = getModulesJVMTI();
+        for (Module mod : my.modules()) {
+            if (!jvmtiModules.contains(mod)) {
+                throw new RuntimeException("JVMTI did not report the loaded named module: " + mod.getName());
+            }
+        }
+
+    }
+
+    /**
+     * Returns a ModuleFinder that finds modules with the given module
+     * descriptors.
+     */
+    static ModuleFinder finderOf(ModuleDescriptor... descriptors) {
+
+        // Create a ModuleReference for each module
+        Map<String, ModuleReference> namesToReference = new HashMap<>();
+
+        for (ModuleDescriptor descriptor : descriptors) {
+            String name = descriptor.name();
+
+            URI uri = URI.create("module:/" + name);
+
+            Supplier<ModuleReader> supplier = () -> {
+                throw new UnsupportedOperationException();
+            };
+
+            ModuleReference mref = new ModuleReference(descriptor, uri, supplier);
+
+            namesToReference.put(name, mref);
+        }
+
+        return new ModuleFinder() {
+            @Override
+            public Optional<ModuleReference> find(String name) {
+                Objects.requireNonNull(name);
+                return Optional.ofNullable(namesToReference.get(name));
+            }
+
+            @Override
+            public Set<ModuleReference> findAll() {
+                return new HashSet<>(namesToReference.values());
+            }
+        };
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/serviceability/jvmti/GetModulesInfo/libJvmtiGetAllModulesTest.c	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <jvmti.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    static jvmtiEnv *jvmti = NULL;
+
+    JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
+        int err = (*jvm)->GetEnv(jvm, (void**) &jvmti, JVMTI_VERSION_9);
+        if (err != JNI_OK) {
+            return JNI_ERR;
+        }
+        return JNI_OK;
+    }
+
+    JNIEXPORT jobjectArray JNICALL
+    Java_JvmtiGetAllModulesTest_getModulesNative(JNIEnv *env, jclass cls) {
+
+        jvmtiError err;
+        jint modules_count = -1;
+        jobject* modules_ptr;
+        jobjectArray array = NULL;
+        int i = 0;
+
+        err = (*jvmti)->GetAllModules(jvmti, &modules_count, &modules_ptr);
+        if (err != JVMTI_ERROR_NONE) {
+            return NULL;
+        }
+
+        array = (*env)->NewObjectArray(env, modules_count, (*env)->FindClass(env, "java/lang/reflect/Module"), NULL);
+
+        for (i = 0; i < modules_count; ++i) {
+            (*env)->SetObjectArrayElement(env, array, i, modules_ptr[i]);
+        }
+
+        return array;
+    }
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/serviceability/sa/TestInstanceKlassSize.java	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,198 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import sun.jvm.hotspot.HotSpotAgent;
+import sun.jvm.hotspot.utilities.SystemDictionaryHelper;
+import sun.jvm.hotspot.debugger.*;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.Platform;
+import jdk.test.lib.ProcessTools;
+import jdk.test.lib.OutputAnalyzer;
+import jdk.test.lib.Utils;
+import jdk.test.lib.apps.LingeredApp;
+import jdk.test.lib.Asserts;
+
+import java.io.*;
+import java.util.*;
+
+/*
+ * @test
+ * @library /test/lib/share/classes
+ * @library /testlibrary
+ * @build jdk.test.lib.*
+ * @build jdk.test.lib.apps.*
+ * @modules java.base/jdk.internal.misc
+ * @modules jdk.hotspot.agent
+ * @modules jdk.hotspot.agent/sun.jvm.hotspot
+ * @modules jdk.hotspot.agent/sun.jvm.hotspot.utilities
+ * @modules jdk.hotspot.agent/sun.jvm.hotspot.oops
+ * @compile -XDignore.symbol.file=true -Xmodule:jdk.hotspot.agent TestInstanceKlassSize.java
+ * @run main/othervm  TestInstanceKlassSize
+ */
+
+public class TestInstanceKlassSize {
+
+    private static String getJcmdInstanceKlassSize(OutputAnalyzer output,
+                                                   String instanceKlassName) {
+        for (String s : output.asLines()) {
+            if (s.contains(instanceKlassName)) {
+                String tokens[];
+                System.out.println(s);
+                tokens = s.split("\\s+");
+                return tokens[3];
+            }
+        }
+        return null;
+    }
+
+    private static OutputAnalyzer jcmd(Long pid,
+                                       String... toolArgs) throws Exception {
+        ProcessBuilder processBuilder = new ProcessBuilder();
+        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jcmd");
+        launcher.addToolArg(Long.toString(pid));
+        if (toolArgs != null) {
+            for (String toolArg : toolArgs) {
+                launcher.addToolArg(toolArg);
+            }
+        }
+
+        processBuilder.command(launcher.getCommand());
+        System.out.println(
+            processBuilder.command().stream().collect(Collectors.joining(" ")));
+        return ProcessTools.executeProcess(processBuilder);
+    }
+
+    private static void startMeWithArgs() throws Exception {
+
+        LingeredApp app = null;
+        OutputAnalyzer output = null;
+        try {
+            List<String> vmArgs = new ArrayList<String>();
+            vmArgs.add("-XX:+UnlockDiagnosticVMOptions");
+            vmArgs.add("-XX:+UsePerfData");
+            vmArgs.addAll(Utils.getVmOptions());
+            app = LingeredApp.startApp(vmArgs);
+            System.out.println ("Started LingeredApp with pid " + app.getPid());
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            throw new RuntimeException(ex);
+        }
+        try {
+            String[] instanceKlassNames = new String[] {
+                                              " java.lang.Object",
+                                              " java.util.Vector",
+                                              " sun.util.PreHashedMap",
+                                              " java.lang.String",
+                                              " java.lang.Thread",
+                                              " java.lang.Byte",
+                                          };
+            String[] toolArgs = {
+                "-XX:+UnlockDiagnosticVMOptions",
+                "-XaddExports:jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED",
+                "-XaddExports:jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED",
+                "-XaddExports:jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED",
+                "TestInstanceKlassSize",
+                Long.toString(app.getPid())
+            };
+
+            OutputAnalyzer jcmdOutput = jcmd(
+                           app.getPid(),
+                           "GC.class_stats", "VTab,ITab,OopMap,KlassBytes");
+            ProcessBuilder processBuilder = ProcessTools
+                                            .createJavaProcessBuilder(toolArgs);
+            output = ProcessTools.executeProcess(processBuilder);
+            System.out.println(output.getOutput());
+            output.shouldHaveExitValue(0);
+
+            // Check whether the size matches that which jcmd outputs
+            for (String instanceKlassName : instanceKlassNames) {
+                System.out.println ("Trying to match for" + instanceKlassName);
+                String jcmdInstanceKlassSize = getJcmdInstanceKlassSize(
+                                                      jcmdOutput,
+                                                      instanceKlassName);
+                for (String s : output.asLines()) {
+                    if (s.contains(instanceKlassName)) {
+                       Asserts.assertTrue(
+                          s.contains(jcmdInstanceKlassSize),
+                          "The size computed by SA for" +
+                          instanceKlassName + " does not match.");
+                    }
+                }
+            }
+        } finally {
+            LingeredApp.stopApp(app);
+        }
+    }
+
+    private static void SAInstanceKlassSize(int pid,
+                                            String[] SAInstanceKlassNames) {
+        HotSpotAgent agent = new HotSpotAgent();
+        try {
+            agent.attach(pid);
+        }
+        catch (DebuggerException e) {
+            System.out.println(e.getMessage());
+            System.err.println("Unable to connect to process ID: " + pid);
+
+            agent.detach();
+            e.printStackTrace();
+        }
+
+        for (String SAInstanceKlassName : SAInstanceKlassNames) {
+            Long size = SystemDictionaryHelper.findInstanceKlass(
+                            SAInstanceKlassName).getSize();
+            System.out.println("SA: The size of " + SAInstanceKlassName +
+                               " is " + size);
+        }
+        agent.detach();
+    }
+
+    public static void main(String[] args) throws Exception {
+
+        if (!Platform.shouldSAAttach()) {
+            System.out.println("SA attach not expected to work - test skipped.");
+            return;
+        }
+
+        if (args == null || args.length == 0) {
+            System.out.println ("No args run. Starting with args now.");
+            startMeWithArgs();
+        } else {
+            String[] SAInstanceKlassNames = new String[] {
+                                                "java.lang.Object",
+                                                "java.util.Vector",
+                                                "sun.util.PreHashedMap",
+                                                "java.lang.String",
+                                                "java.lang.Thread",
+                                                "java.lang.Byte"
+                                             };
+            SAInstanceKlassSize(Integer.parseInt(args[0]), SAInstanceKlassNames);
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/serviceability/sa/TestInstanceKlassSizeForInterface.java	Fri Jul 29 16:11:55 2016 -0700
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import sun.jvm.hotspot.HotSpotAgent;
+import sun.jvm.hotspot.utilities.SystemDictionaryHelper;
+import sun.jvm.hotspot.oops.InstanceKlass;
+import sun.jvm.hotspot.debugger.*;
+
+import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.JDKToolFinder;
+import jdk.test.lib.Platform;
+import jdk.test.lib.ProcessTools;
+import jdk.test.lib.OutputAnalyzer;
+import jdk.test.lib.Utils;
+import jdk.test.lib.Asserts;
+
+/*
+ * @test
+ * @library /test/lib/share/classes
+ * @library /testlibrary
+ * @build jdk.test.lib.*
+ * @build jdk.test.lib.apps.*
+ * @modules java.base/jdk.internal.misc
+ * @modules jdk.hotspot.agent
+ * @modules jdk.hotspot.agent/sun.jvm.hotspot
+ * @modules jdk.hotspot.agent/sun.jvm.hotspot.utilities
+ * @modules jdk.hotspot.agent/sun.jvm.hotspot.oops
+ * @compile -XDignore.symbol.file=true -Xmodule:jdk.hotspot.agent TestInstanceKlassSizeForInterface.java
+ * @run main/othervm TestInstanceKlassSizeForInterface
+ */
+
+interface Language {
+    static final long nbrOfWords = 99999;
+    public abstract long getNbrOfWords();
+}
+
+class ParselTongue implements Language {
+    public long getNbrOfWords() {
+      return nbrOfWords * 4;
+    }
+}
+
+public class TestInstanceKlassSizeForInterface {
+
+    private static void SAInstanceKlassSize(int pid,
+                                            String[] instanceKlassNames) {
+
+        HotSpotAgent agent = new HotSpotAgent();
+        try {
+            agent.attach((int)pid);
+        }
+        catch (DebuggerException e) {
+            System.out.println(e.getMessage());
+            System.err.println("Unable to connect to process ID: " + pid);
+
+            agent.detach();
+            e.printStackTrace();
+        }
+
+        for (String instanceKlassName : instanceKlassNames) {
+            InstanceKlass iKlass = SystemDictionaryHelper.findInstanceKlass(
+                                       instanceKlassName);
+            System.out.println("SA: The size of " + instanceKlassName +
+                               " is " + iKlass.getSize());
+        }
+        agent.detach();
+    }
+
+    private static String getJcmdInstanceKlassSize(OutputAnalyzer output,
+                                                   String instanceKlassName) {
+        for (String s : output.asLines()) {
+            if (s.contains(instanceKlassName)) {
+                String tokens[];
+                System.out.println(s);
+                tokens = s.split("\\s+");
+                return tokens[3];
+            }
+        }
+        return null;
+    }
+
+    private static void createAnotherToAttach(
+                            String[] instanceKlassNames) throws Exception {
+
+        ProcessBuilder pb = new ProcessBuilder();
+
+        // Grab the pid from the current java process and pass it
+        String[] toolArgs = {
+            "-XX:+UnlockDiagnosticVMOptions",
+            "-XaddExports:jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED",
+            "-XaddExports:jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED",
+            "-XaddExports:jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED",
+            "TestInstanceKlassSizeForInterface",
+            Long.toString(ProcessTools.getProcessId())
+        };
+
+        pb.command(new String[] {
+                          JDKToolFinder.getJDKTool("jcmd"),
+                          Long.toString(ProcessTools.getProcessId()),
+                          "GC.class_stats",
+                          "VTab,ITab,OopMap,KlassBytes"
+                      }
+                  );
+
+        // Start a new process to attach to the current process
+        ProcessBuilder processBuilder = ProcessTools
+                  .createJavaProcessBuilder(toolArgs);
+        OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);
+        System.out.println(SAOutput.getOutput());
+
+        OutputAnalyzer jcmdOutput = new OutputAnalyzer(pb.start());
+        System.out.println(jcmdOutput.getOutput());
+
+        // Match the sizes from both the output streams
+        for (String instanceKlassName : instanceKlassNames) {
+            System.out.println ("Trying to match for " + instanceKlassName);
+            String jcmdInstanceKlassSize = getJcmdInstanceKlassSize(
+                                                      jcmdOutput,
+                                                      instanceKlassName);
+            for (String s : SAOutput.asLines()) {
+                if (s.contains(instanceKlassName)) {
+                   Asserts.assertTrue(
+                      s.contains(jcmdInstanceKlassSize),
+                      "The size computed by SA for " +
+                      instanceKlassName + " does not match.");
+                }
+            }
+        }
+    }
+
+    public static void main (String... args) throws Exception {
+        String[] instanceKlassNames = new String[] {
+                                          "Language",
+                                          "ParselTongue",
+                                          "TestInstanceKlassSizeForInterface$1"
+                                      };
+
+        if (!Platform.shouldSAAttach()) {
+            System.out.println(
+               "SA attach not expected to work - test skipped.");
+            return;
+        }
+
+        if ( args == null || args.length == 0 ) {
+            ParselTongue lang = new ParselTongue();
+
+            Language ventro = new Language() {
+                public long getNbrOfWords() {
+                    return nbrOfWords * 8;
+                }
+            };
+
+            // Not tested at this point. The test needs to be enhanced
+            // later to test for the sizes of the Lambda MetaFactory
+            // generated anonymous classes too. (After JDK-8160228 gets
+            // fixed.)
+            Runnable r2 = () -> System.out.println("Hello world!");
+            r2.run();
+
+            createAnotherToAttach(instanceKlassNames);
+        } else {
+            SAInstanceKlassSize(Integer.parseInt(args[0]), instanceKlassNames);
+        }
+    }
+}
--- a/hotspot/test/testlibrary/jdk/test/lib/Platform.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/testlibrary/jdk/test/lib/Platform.java	Fri Jul 29 16:11:55 2016 -0700
@@ -60,10 +60,6 @@
         return vmName.endsWith(" Minimal VM");
     }
 
-    public static boolean isEmbedded() {
-        return vmName.contains("Embedded");
-    }
-
     public static boolean isTieredSupported() {
         return compiler.contains("Tiered Compilers");
     }
--- a/hotspot/test/testlibrary/jdk/test/lib/Utils.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/testlibrary/jdk/test/lib/Utils.java	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -317,8 +317,8 @@
             output = ProcessTools.executeProcess(jcmdLauncher.getCommand());
             output.shouldHaveExitValue(0);
 
-            // Search for a line starting with numbers (pid), follwed by the key.
-            Pattern pattern = Pattern.compile("([0-9]+)\\s.*(" + key + ").*\\r?\\n");
+            // Search for a line starting with numbers (pid), followed by the key.
+            Pattern pattern = Pattern.compile("^([0-9]+)\\s.*(" + key + ")", Pattern.MULTILINE);
             Matcher matcher = pattern.matcher(output.getStdout());
 
             int pid = -1;
--- a/hotspot/test/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/hotspot/test/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java	Fri Jul 29 16:11:55 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -49,7 +49,7 @@
         BITNESS("is32bit", "is64bit"),
         OS("isAix", "isLinux", "isOSX", "isSolaris", "isWindows"),
         VM_TYPE("isClient", "isServer", "isGraal", "isMinimal", "isZero"),
-        IGNORED("isEmbedded", "isDebugBuild", "shouldSAAttach",
+        IGNORED("isDebugBuild", "shouldSAAttach",
                 "canPtraceAttachLinux", "canAttachOSX", "isTieredSupported");
 
         public final List<String> methodNames;