Merge
authorjwilhelm
Thu, 16 Mar 2017 16:40:41 -0700
changeset 46338 e84b501fa52e
parent 46337 307e52ec20cd (diff)
parent 44236 d1cab6c7e608 (current diff)
child 46339 b80e814907b1
Merge
README-builds.html
README-builds.md
common/bin/update-build-readme.sh
corba/README
hotspot/README
hotspot/make/test/JtregNative.gmk
hotspot/src/cpu/aarch64/vm/templateInterpreterGenerator_aarch64.cpp
hotspot/src/cpu/arm/vm/interp_masm_arm.cpp
hotspot/src/cpu/arm/vm/interp_masm_arm.hpp
hotspot/src/cpu/arm/vm/macroAssembler_arm.hpp
hotspot/src/cpu/arm/vm/templateInterpreterGenerator_arm.cpp
hotspot/src/cpu/ppc/vm/macroAssembler_ppc.cpp
hotspot/src/cpu/ppc/vm/macroAssembler_ppc.hpp
hotspot/src/cpu/ppc/vm/templateInterpreterGenerator_ppc.cpp
hotspot/src/cpu/s390/vm/macroAssembler_s390.cpp
hotspot/src/cpu/s390/vm/macroAssembler_s390.hpp
hotspot/src/cpu/s390/vm/templateInterpreterGenerator_s390.cpp
hotspot/src/cpu/sparc/vm/templateInterpreterGenerator_sparc.cpp
hotspot/src/cpu/x86/vm/macroAssembler_x86.hpp
hotspot/src/cpu/x86/vm/templateInterpreterGenerator_x86.cpp
hotspot/src/share/vm/classfile/classLoaderData.cpp
hotspot/src/share/vm/classfile/classLoaderData.hpp
hotspot/src/share/vm/classfile/moduleEntry.cpp
hotspot/src/share/vm/jvmci/jvmciCompilerToVM.cpp
hotspot/src/share/vm/jvmci/jvmciCompilerToVM.hpp
hotspot/src/share/vm/prims/jni.cpp
hotspot/src/share/vm/prims/jvmtiEnv.cpp
hotspot/src/share/vm/runtime/javaCalls.cpp
hotspot/src/share/vm/runtime/javaCalls.hpp
jaxp/README
jaxws/README
jdk/README
jdk/src/java.datatransfer/share/classes/java/awt/datatransfer/package.html
jdk/src/java.desktop/macosx/classes/com/apple/eawt/event/package.html
jdk/src/java.desktop/macosx/classes/com/apple/eawt/package.html
jdk/src/java.desktop/macosx/classes/com/apple/eio/package.html
jdk/src/java.desktop/share/classes/java/applet/package.html
jdk/src/java.desktop/share/classes/java/awt/color/package.html
jdk/src/java.desktop/share/classes/java/awt/desktop/package.html
jdk/src/java.desktop/share/classes/java/awt/dnd/package.html
jdk/src/java.desktop/share/classes/java/awt/dnd/peer/package.html
jdk/src/java.desktop/share/classes/java/awt/event/package.html
jdk/src/java.desktop/share/classes/java/awt/font/package.html
jdk/src/java.desktop/share/classes/java/awt/geom/package.html
jdk/src/java.desktop/share/classes/java/awt/im/package.html
jdk/src/java.desktop/share/classes/java/awt/im/spi/package.html
jdk/src/java.desktop/share/classes/java/awt/image/package.html
jdk/src/java.desktop/share/classes/java/awt/image/renderable/package.html
jdk/src/java.desktop/share/classes/java/awt/package.html
jdk/src/java.desktop/share/classes/java/awt/peer/package.html
jdk/src/java.desktop/share/classes/java/awt/print/package.html
jdk/src/java.desktop/share/classes/java/beans/beancontext/package.html
jdk/src/java.desktop/share/classes/java/beans/package.html
jdk/src/java.desktop/share/classes/javax/accessibility/package.html
jdk/src/java.desktop/share/classes/javax/imageio/event/package.html
jdk/src/java.desktop/share/classes/javax/imageio/metadata/package.html
jdk/src/java.desktop/share/classes/javax/imageio/package.html
jdk/src/java.desktop/share/classes/javax/imageio/plugins/bmp/package.html
jdk/src/java.desktop/share/classes/javax/imageio/plugins/jpeg/package.html
jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/package.html
jdk/src/java.desktop/share/classes/javax/imageio/spi/package.html
jdk/src/java.desktop/share/classes/javax/imageio/stream/package.html
jdk/src/java.desktop/share/classes/javax/print/attribute/package.html
jdk/src/java.desktop/share/classes/javax/print/attribute/standard/package.html
jdk/src/java.desktop/share/classes/javax/print/event/package.html
jdk/src/java.desktop/share/classes/javax/print/package.html
jdk/src/java.desktop/share/classes/javax/sound/midi/package.html
jdk/src/java.desktop/share/classes/javax/sound/midi/spi/package.html
jdk/src/java.desktop/share/classes/javax/sound/sampled/package.html
jdk/src/java.desktop/share/classes/javax/sound/sampled/spi/package.html
jdk/src/java.desktop/share/classes/javax/swing/border/package.html
jdk/src/java.desktop/share/classes/javax/swing/colorchooser/package.html
jdk/src/java.desktop/share/classes/javax/swing/event/package.html
jdk/src/java.desktop/share/classes/javax/swing/filechooser/package.html
jdk/src/java.desktop/share/classes/javax/swing/package.html
jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/package.html
jdk/src/java.desktop/share/classes/javax/swing/plaf/metal/package.html
jdk/src/java.desktop/share/classes/javax/swing/plaf/multi/package.html
jdk/src/java.desktop/share/classes/javax/swing/plaf/nimbus/package.html
jdk/src/java.desktop/share/classes/javax/swing/plaf/package.html
jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/package.html
jdk/src/java.desktop/share/classes/javax/swing/table/package.html
jdk/src/java.desktop/share/classes/javax/swing/text/html/package.html
jdk/src/java.desktop/share/classes/javax/swing/text/html/parser/package.html
jdk/src/java.desktop/share/classes/javax/swing/text/package.html
jdk/src/java.desktop/share/classes/javax/swing/text/rtf/package.html
jdk/src/java.desktop/share/classes/javax/swing/tree/package.html
jdk/src/java.desktop/share/classes/javax/swing/undo/package.html
jdk/test/java/net/httpclient/HandshakePhase.java
jdk/test/java/util/concurrent/ArrayBlockingQueue/IteratorConsistency.java
jdk/test/javax/swing/text/TableView/I18nLayoutTest.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/doclet/taglet/Taglet.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/doclet/taglet/package-info.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/doclets/StandardDoclet.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/doclets/package-info.java
--- a/hotspot/make/lib/Lib-jdk.aot.gmk	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-#
-# 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.  Oracle designates this
-# particular file as subject to the "Classpath" exception as provided
-# by Oracle in the LICENSE file that accompanied this code.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-include $(SPEC)
-include NativeCompilation.gmk
-
-$(eval $(call IncludeCustomExtension, hotspot, lib/Lib-jdk.aot.gmk))
-
-##############################################################################
-# Build libjelfshim only when AOT is enabled.
-ifeq ($(ENABLE_AOT), true)
-  JELFSHIM_NAME := jelfshim
-
-  $(eval $(call SetupNativeCompilation, BUILD_LIBJELFSHIM, \
-      TOOLCHAIN := TOOLCHAIN_DEFAULT, \
-      OPTIMIZATION := LOW, \
-      LIBRARY := $(JELFSHIM_NAME), \
-      OUTPUT_DIR := $(call FindLibDirForModule, $(MODULE)), \
-      SRC := $(HOTSPOT_TOPDIR)/src/jdk.aot/unix/native/libjelfshim, \
-      CFLAGS := $(CFLAGS_JDKLIB) $(ELF_CFLAGS) \
-          -DAOT_VERSION_STRING='"$(VERSION_STRING)"' \
-          -I$(SUPPORT_OUTPUTDIR)/headers/$(MODULE), \
-      LDFLAGS := $(LDFLAGS_JDKLIB), \
-      OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/lib$(JELFSHIM_NAME), \
-      LIBS := $(ELF_LIBS) $(LIBS_JDKLIB), \
-  ))
-
-  TARGETS += $(BUILD_LIBJELFSHIM)
-endif
-
-##############################################################################
--- a/hotspot/make/test/JtregNative.gmk	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/make/test/JtregNative.gmk	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -35,12 +35,14 @@
 include MakeBase.gmk
 include TestFilesCompilation.gmk
 
+$(eval $(call IncludeCustomExtension, hotspot, test/JtregNative.gmk))
+
 ################################################################################
 # Targets for building the native tests themselves.
 ################################################################################
 
 # Add more directories here when needed.
-BUILD_HOTSPOT_JTREG_NATIVE_SRC := \
+BUILD_HOTSPOT_JTREG_NATIVE_SRC += \
     $(HOTSPOT_TOPDIR)/test/native_sanity \
     $(HOTSPOT_TOPDIR)/test/runtime/jni/8025979 \
     $(HOTSPOT_TOPDIR)/test/runtime/jni/8033445 \
--- a/hotspot/src/cpu/aarch64/vm/interp_masm_aarch64.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/aarch64/vm/interp_masm_aarch64.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, 2015, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -54,9 +54,6 @@
                             int number_of_arguments,
                             bool check_exceptions);
 
-  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, bool verifyoop = true);
 
@@ -67,6 +64,9 @@
 
   void jump_to_entry(address entry);
 
+  virtual void check_and_handle_popframe(Register java_thread);
+  virtual void check_and_handle_earlyret(Register java_thread);
+
   // Interpreter-specific registers
   void save_bcp() {
     str(rbcp, Address(rfp, frame::interpreter_frame_bcp_offset * wordSize));
--- a/hotspot/src/cpu/aarch64/vm/jvmciCodeInstaller_aarch64.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/aarch64/vm/jvmciCodeInstaller_aarch64.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -55,7 +55,7 @@
     }
   }
 #endif // ASSERT
-  Handle obj = HotSpotObjectConstantImpl::object(constant);
+  Handle obj(THREAD, HotSpotObjectConstantImpl::object(constant));
   jobject value = JNIHandles::make_local(obj());
   MacroAssembler::patch_oop(pc, (address)obj());
   int oop_index = _oop_recorder->find_index(value);
--- a/hotspot/src/cpu/aarch64/vm/macroAssembler_aarch64.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/aarch64/vm/macroAssembler_aarch64.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, 2015, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -77,12 +77,6 @@
     bool     check_exceptions          // whether to check for pending exceptions after return
   );
 
-  // These routines should emit JVMTI PopFrame and ForceEarlyReturn handling code.
-  // The implementation is only non-empty for the InterpreterMacroAssembler,
-  // as only the interpreter handles PopFrame and ForceEarlyReturn requests.
-  virtual void check_and_handle_popframe(Register java_thread);
-  virtual void check_and_handle_earlyret(Register java_thread);
-
   void call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions = true);
 
   // Maximum size of class area in Metaspace when compressed
@@ -97,6 +91,12 @@
              > (1u << log2_intptr(CompressedClassSpaceSize))));
   }
 
+ // These routines should emit JVMTI PopFrame and ForceEarlyReturn handling code.
+ // The implementation is only non-empty for the InterpreterMacroAssembler,
+ // as only the interpreter handles PopFrame and ForceEarlyReturn requests.
+ virtual void check_and_handle_popframe(Register java_thread);
+ virtual void check_and_handle_earlyret(Register java_thread);
+
   // Biased locking support
   // lock_reg and obj_reg must be loaded up with the appropriate values.
   // swap_reg is killed.
--- a/hotspot/src/cpu/aarch64/vm/metaspaceShared_aarch64.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-/*
- * Copyright (c) 2004, 2012, 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.
- *
- * 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 "asm/macroAssembler.hpp"
-#include "memory/metaspaceShared.hpp"
-
-// Generate the self-patching vtable method:
-//
-// This method will be called (as any other Klass virtual method) with
-// the Klass itself as the first argument.  Example:
-//
-//      oop obj;
-//      int size = obj->klass()->oop_size(this);
-//
-// for which the virtual method call is Klass::oop_size();
-//
-// The dummy method is called with the Klass object as the first
-// operand, and an object as the second argument.
-//
-
-//=====================================================================
-
-// All of the dummy methods in the vtable are essentially identical,
-// differing only by an ordinal constant, and they bear no relationship
-// to the original method which the caller intended. Also, there needs
-// to be 'vtbl_list_size' instances of the vtable in order to
-// differentiate between the 'vtable_list_size' original Klass objects.
-
-#define __ masm->
-
-extern "C" {
-  void aarch64_prolog(void);
-}
-
-void MetaspaceShared::generate_vtable_methods(void** vtbl_list,
-                                                   void** vtable,
-                                                   char** md_top,
-                                                   char* md_end,
-                                                   char** mc_top,
-                                                   char* mc_end) {
-
-#ifdef BUILTIN_SIM
-  // Write a dummy word to the writable shared metaspace.
-  // MetaspaceShared::initialize_shared_spaces will fill it with the
-  // address of aarch64_prolog().
-  address *prolog_ptr = (address*)*md_top;
-  *(intptr_t *)(*md_top) = (intptr_t)0;
-  (*md_top) += sizeof(intptr_t);
-#endif
-
-  intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*);
-  *(intptr_t *)(*md_top) = vtable_bytes;
-  *md_top += sizeof(intptr_t);
-  void** dummy_vtable = (void**)*md_top;
-  *vtable = dummy_vtable;
-  *md_top += vtable_bytes;
-
-  // Get ready to generate dummy methods.
-
-  CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top);
-  MacroAssembler* masm = new MacroAssembler(&cb);
-
-  Label common_code;
-  for (int i = 0; i < vtbl_list_size; ++i) {
-    for (int j = 0; j < num_virtuals; ++j) {
-      dummy_vtable[num_virtuals * i + j] = (void*)masm->pc();
-
-      // We're called directly from C code.
-#ifdef BUILTIN_SIM
-      __ c_stub_prolog(8, 0, MacroAssembler::ret_type_integral, prolog_ptr);
-#endif
-      // Load rscratch1 with a value indicating vtable/offset pair.
-      // -- bits[ 7..0]  (8 bits) which virtual method in table?
-      // -- bits[12..8]  (5 bits) which virtual method table?
-      __ mov(rscratch1, (i << 8) + j);
-      __ b(common_code);
-    }
-  }
-
-  __ bind(common_code);
-
-  Register tmp0 = r10, tmp1 = r11;       // AAPCS64 temporary registers
-  __ enter();
-  __ lsr(tmp0, rscratch1, 8);            // isolate vtable identifier.
-  __ mov(tmp1, (address)vtbl_list);      // address of list of vtable pointers.
-  __ ldr(tmp1, Address(tmp1, tmp0, Address::lsl(LogBytesPerWord))); // get correct vtable pointer.
-  __ str(tmp1, Address(c_rarg0));        // update vtable pointer in obj.
-  __ add(rscratch1, tmp1, rscratch1, ext::uxtb, LogBytesPerWord); // address of real method pointer.
-  __ ldr(rscratch1, Address(rscratch1)); // get real method pointer.
-  __ blrt(rscratch1, 8, 0, 1);           // jump to the real method.
-  __ leave();
-  __ ret(lr);
-
-  *mc_top = (char*)__ pc();
-}
-
-#ifdef BUILTIN_SIM
-void MetaspaceShared::relocate_vtbl_list(char **buffer) {
-  void **sim_entry = (void**)*buffer;
-  *sim_entry = (void*)aarch64_prolog;
-  *buffer += sizeof(intptr_t);
-}
-#endif
--- a/hotspot/src/cpu/aarch64/vm/methodHandles_aarch64.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/aarch64/vm/methodHandles_aarch64.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -63,7 +63,7 @@
                                  Register obj, SystemDictionary::WKID klass_id,
                                  const char* error_message) {
   InstanceKlass** klass_addr = SystemDictionary::well_known_klass_addr(klass_id);
-  KlassHandle klass = SystemDictionary::well_known_klass(klass_id);
+  Klass* klass = SystemDictionary::well_known_klass(klass_id);
   Register temp = rscratch2;
   Register temp2 = rscratch1; // used by MacroAssembler::cmpptr
   Label L_ok, L_bad;
--- a/hotspot/src/cpu/aarch64/vm/templateInterpreterGenerator_aarch64.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/aarch64/vm/templateInterpreterGenerator_aarch64.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -402,14 +402,6 @@
   return entry;
 }
 
-address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
-  address entry = __ pc();
-  // NULL last_sp until next java call
-  __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
-  __ dispatch_next(state);
-  return entry;
-}
-
 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
   address entry = __ pc();
 
@@ -444,6 +436,10 @@
     __ notify(Assembler::method_reentry);
   }
 #endif
+
+ __ check_and_handle_popframe(rthread);
+ __ check_and_handle_earlyret(rthread);
+
   __ get_dispatch();
   __ dispatch_next(state, step);
 
--- a/hotspot/src/cpu/arm/vm/abstractInterpreter_arm.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/arm/vm/abstractInterpreter_arm.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -234,8 +234,15 @@
 #ifdef AARCH64
   interpreter_frame->interpreter_frame_set_stack_top(stack_top);
 
+  // We have to add extra reserved slots to max_stack. There are 3 users of the extra slots,
+  // none of which are at the same time, so we just need to make sure there is enough room
+  // for the biggest user:
+  //   -reserved slot for exception handler
+  //   -reserved slots for JSR292. Method::extra_stack_entries() is the size.
+  //   -3 reserved slots so get_method_counters() can save some registers before call_VM().
+  int max_stack = method->constMethod()->max_stack() + MAX2(3, Method::extra_stack_entries());
   intptr_t* extended_sp = (intptr_t*) monbot  -
-    (method->max_stack() + 1) * Interpreter::stackElementWords - // +1 is reserved slot for exception handler
+    (max_stack * Interpreter::stackElementWords) -
     popframe_extra_args;
   extended_sp = (intptr_t*)round_down((intptr_t)extended_sp, StackAlignmentInBytes);
   interpreter_frame->interpreter_frame_set_extended_sp(extended_sp);
--- a/hotspot/src/cpu/arm/vm/interp_masm_arm.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/arm/vm/interp_masm_arm.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -2195,75 +2195,42 @@
 
 void InterpreterMacroAssembler::get_method_counters(Register method,
                                                     Register Rcounters,
-                                                    Label& skip) {
+                                                    Label& skip,
+                                                    bool saveRegs,
+                                                    Register reg1,
+                                                    Register reg2,
+                                                    Register reg3) {
   const Address method_counters(method, Method::method_counters_offset());
   Label has_counters;
 
   ldr(Rcounters, method_counters);
   cbnz(Rcounters, has_counters);
 
+  if (saveRegs) {
+    // Save and restore in use caller-saved registers since they will be trashed by call_VM
+    assert(reg1 != noreg, "must specify reg1");
+    assert(reg2 != noreg, "must specify reg2");
 #ifdef AARCH64
-  const Register tmp = Rcounters;
-  const int saved_regs_size = 20*wordSize;
-
-  // Note: call_VM will cut SP according to Rstack_top value before call, and restore SP to
-  // extended_sp value from frame after the call.
-  // So make sure there is enough stack space to save registers and adjust Rstack_top accordingly.
-  {
-    Label enough_stack_space;
-    check_extended_sp(tmp);
-    sub(Rstack_top, Rstack_top, saved_regs_size);
-    cmp(SP, Rstack_top);
-    b(enough_stack_space, ls);
-
-    align_reg(tmp, Rstack_top, StackAlignmentInBytes);
-    mov(SP, tmp);
-    str(tmp, Address(FP, frame::interpreter_frame_extended_sp_offset * wordSize));
-
-    bind(enough_stack_space);
-    check_stack_top();
-
-    int offset = 0;
-    stp(R0,  R1,  Address(Rstack_top, offset)); offset += 2*wordSize;
-    stp(R2,  R3,  Address(Rstack_top, offset)); offset += 2*wordSize;
-    stp(R4,  R5,  Address(Rstack_top, offset)); offset += 2*wordSize;
-    stp(R6,  R7,  Address(Rstack_top, offset)); offset += 2*wordSize;
-    stp(R8,  R9,  Address(Rstack_top, offset)); offset += 2*wordSize;
-    stp(R10, R11, Address(Rstack_top, offset)); offset += 2*wordSize;
-    stp(R12, R13, Address(Rstack_top, offset)); offset += 2*wordSize;
-    stp(R14, R15, Address(Rstack_top, offset)); offset += 2*wordSize;
-    stp(R16, R17, Address(Rstack_top, offset)); offset += 2*wordSize;
-    stp(R18, LR,  Address(Rstack_top, offset)); offset += 2*wordSize;
-    assert (offset == saved_regs_size, "should be");
+    assert(reg3 != noreg, "must specify reg3");
+    stp(reg1, reg2, Address(Rstack_top, -2*wordSize, pre_indexed));
+    stp(reg3, ZR, Address(Rstack_top, -2*wordSize, pre_indexed));
+#else
+    assert(reg3 == noreg, "must not specify reg3");
+    push(RegisterSet(reg1) | RegisterSet(reg2));
+#endif
   }
-#else
-  push(RegisterSet(R0, R3) | RegisterSet(R12) | RegisterSet(R14));
-#endif // AARCH64
 
   mov(R1, method);
-  call_VM(noreg, CAST_FROM_FN_PTR(address,
-          InterpreterRuntime::build_method_counters), R1);
-
+  call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::build_method_counters), R1);
+
+  if (saveRegs) {
 #ifdef AARCH64
-  {
-    int offset = 0;
-    ldp(R0,  R1,  Address(Rstack_top, offset)); offset += 2*wordSize;
-    ldp(R2,  R3,  Address(Rstack_top, offset)); offset += 2*wordSize;
-    ldp(R4,  R5,  Address(Rstack_top, offset)); offset += 2*wordSize;
-    ldp(R6,  R7,  Address(Rstack_top, offset)); offset += 2*wordSize;
-    ldp(R8,  R9,  Address(Rstack_top, offset)); offset += 2*wordSize;
-    ldp(R10, R11, Address(Rstack_top, offset)); offset += 2*wordSize;
-    ldp(R12, R13, Address(Rstack_top, offset)); offset += 2*wordSize;
-    ldp(R14, R15, Address(Rstack_top, offset)); offset += 2*wordSize;
-    ldp(R16, R17, Address(Rstack_top, offset)); offset += 2*wordSize;
-    ldp(R18, LR,  Address(Rstack_top, offset)); offset += 2*wordSize;
-    assert (offset == saved_regs_size, "should be");
-
-    add(Rstack_top, Rstack_top, saved_regs_size);
+    ldp(reg3, ZR, Address(Rstack_top, 2*wordSize, post_indexed));
+    ldp(reg1, reg2, Address(Rstack_top, 2*wordSize, post_indexed));
+#else
+    pop(RegisterSet(reg1) | RegisterSet(reg2));
+#endif
   }
-#else
-  pop(RegisterSet(R0, R3) | RegisterSet(R12) | RegisterSet(R14));
-#endif // AARCH64
 
   ldr(Rcounters, method_counters);
   cbz(Rcounters, skip); // No MethodCounters created, OutOfMemory
--- a/hotspot/src/cpu/arm/vm/interp_masm_arm.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/arm/vm/interp_masm_arm.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -53,9 +53,6 @@
   // Template interpreter specific version of call_VM_helper
   virtual void call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions);
 
-  virtual void check_and_handle_popframe();
-  virtual void check_and_handle_earlyret();
-
   // base routine for all dispatches
   typedef enum { DispatchDefault, DispatchNormal } DispatchTableMode;
   void dispatch_base(TosState state, DispatchTableMode table_mode, bool verifyoop = true);
@@ -63,6 +60,9 @@
  public:
   InterpreterMacroAssembler(CodeBuffer* code);
 
+  virtual void check_and_handle_popframe();
+  virtual void check_and_handle_earlyret();
+
   // Interpreter-specific registers
 #if defined(AARCH64) && defined(ASSERT)
 
@@ -349,7 +349,13 @@
 
   void trace_state(const char* msg) PRODUCT_RETURN;
 
-  void get_method_counters(Register method, Register Rcounters, Label& skip);
+void get_method_counters(Register method,
+                         Register Rcounters,
+                         Label& skip,
+                         bool saveRegs = false,
+                         Register reg1 = noreg,
+                         Register reg2 = noreg,
+                         Register reg3 = noreg);
 };
 
 #endif // CPU_ARM_VM_INTERP_MASM_ARM_HPP
--- a/hotspot/src/cpu/arm/vm/macroAssembler_arm.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/arm/vm/macroAssembler_arm.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -206,6 +206,9 @@
   // may customize this version by overriding it for its purposes (e.g., to save/restore
   // additional registers when doing a VM call).
   virtual void call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions);
+public:
+
+  MacroAssembler(CodeBuffer* code) : Assembler(code) {}
 
   // These routines should emit JVMTI PopFrame and ForceEarlyReturn handling code.
   // The implementation is only non-empty for the InterpreterMacroAssembler,
@@ -213,10 +216,6 @@
   virtual void check_and_handle_popframe() {}
   virtual void check_and_handle_earlyret() {}
 
-public:
-
-  MacroAssembler(CodeBuffer* code) : Assembler(code) {}
-
   // By default, we do not need relocation information for non
   // patchable absolute addresses. However, when needed by some
   // extensions, ignore_non_patchable_relocations can be modified,
--- a/hotspot/src/cpu/arm/vm/metaspaceShared_arm.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2008, 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.
- *
- */
-
-#include "precompiled.hpp"
-#include "asm/macroAssembler.hpp"
-#include "assembler_arm.inline.hpp"
-#include "memory/metaspaceShared.hpp"
-
-// Generate the self-patching vtable method:
-//
-// This method will be called (as any other Klass virtual method) with
-// the Klass itself as the first argument.  Example:
-//
-//      oop obj;
-//      int size = obj->klass()->oop_size(this);
-//
-// for which the virtual method call is Klass::oop_size();
-//
-// The dummy method is called with the Klass object as the first
-// operand, and an object as the second argument.
-//
-
-//=====================================================================
-
-// All of the dummy methods in the vtable are essentially identical,
-// differing only by an ordinal constant, and they bear no relationship
-// to the original method which the caller intended. Also, there needs
-// to be 'vtbl_list_size' instances of the vtable in order to
-// differentiate between the 'vtable_list_size' original Klass objects.
-
-#define __ masm->
-
-void MetaspaceShared::generate_vtable_methods(void** vtbl_list,
-                                                   void** vtable,
-                                                   char** md_top,
-                                                   char* md_end,
-                                                   char** mc_top,
-                                                   char* mc_end) {
-  intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*);
-  *(intptr_t *)(*md_top) = vtable_bytes;
-  *md_top += sizeof(intptr_t);
-  void** dummy_vtable = (void**)*md_top;
-  *vtable = dummy_vtable;
-  *md_top += vtable_bytes;
-
-  CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top);
-  MacroAssembler* masm = new MacroAssembler(&cb);
-
-  for (int i = 0; i < vtbl_list_size; ++i) {
-    Label common_code;
-    for (int j = 0; j < num_virtuals; ++j) {
-      dummy_vtable[num_virtuals * i + j] = (void*) __ pc();
-      __ mov(Rtemp, j);  // Rtemp contains an index of a virtual method in the table
-      __ b(common_code);
-    }
-
-    InlinedAddress vtable_address((address)&vtbl_list[i]);
-    __ bind(common_code);
-    const Register tmp2 = AARCH64_ONLY(Rtemp2) NOT_AARCH64(R4);
-    assert_different_registers(Rtemp, tmp2);
-#ifndef AARCH64
-    __ push(tmp2);
-#endif // !AARCH64
-    // Do not use ldr_global since the code must be portable across all ARM architectures
-    __ ldr_literal(tmp2, vtable_address);
-    __ ldr(tmp2, Address(tmp2));                              // get correct vtable address
-    __ ldr(Rtemp, Address::indexed_ptr(tmp2, Rtemp));         // get real method pointer
-    __ str(tmp2, Address(R0));                                // update vtable. R0 = "this"
-#ifndef AARCH64
-    __ pop(tmp2);
-#endif // !AARCH64
-    __ jump(Rtemp);
-    __ bind_literal(vtable_address);
-  }
-
-  __ flush();
-  *mc_top = (char*) __ pc();
-}
--- a/hotspot/src/cpu/arm/vm/methodHandles_arm.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/arm/vm/methodHandles_arm.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -67,7 +67,7 @@
                                  Register obj, Register temp1, Register temp2, SystemDictionary::WKID klass_id,
                                  const char* error_message) {
   InstanceKlass** klass_addr = SystemDictionary::well_known_klass_addr(klass_id);
-  KlassHandle klass = SystemDictionary::well_known_klass(klass_id);
+  Klass* klass = SystemDictionary::well_known_klass(klass_id);
   Label L_ok, L_bad;
   BLOCK_COMMENT("verify_klass {");
   __ verify_oop(obj);
--- a/hotspot/src/cpu/arm/vm/templateInterpreterGenerator_arm.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/arm/vm/templateInterpreterGenerator_arm.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -270,12 +270,6 @@
   return entry;
 }
 
-address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
-  // Not used.
-  STOP("generate_continuation_for");
-  return NULL;
-}
-
 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
   address entry = __ pc();
 
@@ -310,6 +304,9 @@
   __ convert_retval_to_tos(state);
 #endif // !AARCH64
 
+ __ check_and_handle_popframe();
+ __ check_and_handle_earlyret();
+
   __ dispatch_next(state, step);
 
   return entry;
@@ -1404,7 +1401,13 @@
 #ifdef AARCH64
   // setup RmaxStack
   __ ldrh(RmaxStack, Address(RconstMethod, ConstMethod::max_stack_offset()));
-  __ add(RmaxStack, RmaxStack, MAX2(1, Method::extra_stack_entries())); // reserve slots for exception handler and JSR292 appendix argument
+  // We have to add extra reserved slots to max_stack. There are 3 users of the extra slots,
+  // none of which are at the same time, so we just need to make sure there is enough room
+  // for the biggest user:
+  //   -reserved slot for exception handler
+  //   -reserved slots for JSR292. Method::extra_stack_entries() is the size.
+  //   -3 reserved slots so get_method_counters() can save some registers before call_VM().
+  __ add(RmaxStack, RmaxStack, MAX2(3, Method::extra_stack_entries()));
 #endif // AARCH64
 
   // see if we've got enough room on the stack for locals plus overhead.
--- a/hotspot/src/cpu/arm/vm/templateTable_arm.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/arm/vm/templateTable_arm.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -2286,13 +2286,18 @@
       }
       __ bind(no_mdo);
       // Increment backedge counter in MethodCounters*
-      __ get_method_counters(Rmethod, Rcounters, dispatch);
+      // Note Rbumped_taken_count is a callee saved registers for ARM32, but caller saved for ARM64
+      __ get_method_counters(Rmethod, Rcounters, dispatch, true /*saveRegs*/,
+                             Rdisp, R3_bytecode,
+                             AARCH64_ONLY(Rbumped_taken_count) NOT_AARCH64(noreg));
       const Address mask(Rcounters, in_bytes(MethodCounters::backedge_mask_offset()));
       __ increment_mask_and_jump(Address(Rcounters, be_offset), increment, mask,
                                  Rcnt, R4_tmp, eq, &backedge_counter_overflow);
     } else {
-      // increment counter
-      __ get_method_counters(Rmethod, Rcounters, dispatch);
+      // Increment backedge counter in MethodCounters*
+      __ get_method_counters(Rmethod, Rcounters, dispatch, true /*saveRegs*/,
+                             Rdisp, R3_bytecode,
+                             AARCH64_ONLY(Rbumped_taken_count) NOT_AARCH64(noreg));
       __ ldr_u32(Rtemp, Address(Rcounters, be_offset));           // load backedge counter
       __ add(Rtemp, Rtemp, InvocationCounter::count_increment);   // increment counter
       __ str_32(Rtemp, Address(Rcounters, be_offset));            // store counter
--- a/hotspot/src/cpu/ppc/vm/c1_LIRAssembler_ppc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/c1_LIRAssembler_ppc.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -3177,9 +3177,8 @@
   assert_different_registers(val, crc, res);
 
   __ load_const_optimized(res, StubRoutines::crc_table_addr(), R0);
-  __ nand(crc, crc, crc); // ~crc
-  __ update_byte_crc32(crc, val, res);
-  __ nand(res, crc, crc); // ~crc
+  __ kernel_crc32_singleByteReg(crc, val, res, true);
+  __ mr(res, crc);
 }
 
 #undef __
--- a/hotspot/src/cpu/ppc/vm/c1_LIRGenerator_ppc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/c1_LIRGenerator_ppc.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -63,18 +63,6 @@
 }
 
 
-inline void load_int_as_long(LIR_List *ll, LIRItem &li, LIR_Opr dst) {
-  LIR_Opr r = li.value()->operand();
-  if (r->is_register()) {
-    LIR_Opr dst_l = FrameMap::as_long_opr(dst->as_register());
-    ll->convert(Bytecodes::_i2l, li.result(), dst_l); // Convert.
-  } else {
-    // Constants or memory get loaded with sign extend on this platform.
-    ll->move(li.result(), dst);
-  }
-}
-
-
 //--------------------------------------------------------------
 //               LIRGenerator
 //--------------------------------------------------------------
@@ -1419,10 +1407,9 @@
               arg2 = cc->at(1),
               arg3 = cc->at(2);
 
-      // CCallingConventionRequiresIntsAsLongs
       crc.load_item_force(arg1); // We skip int->long conversion here, because CRC32 stub doesn't care about high bits.
       __ leal(LIR_OprFact::address(a), arg2);
-      load_int_as_long(gen()->lir(), len, arg3);
+      len.load_item_force(arg3); // We skip int->long conversion here, , because CRC32 stub expects int.
 
       __ call_runtime_leaf(StubRoutines::updateBytesCRC32(), LIR_OprFact::illegalOpr, result_reg, cc->args());
       __ move(result_reg, result);
@@ -1434,6 +1421,66 @@
   }
 }
 
+void LIRGenerator::do_update_CRC32C(Intrinsic* x) {
+  assert(UseCRC32CIntrinsics, "or should not be here");
+  LIR_Opr result = rlock_result(x);
+
+  switch (x->id()) {
+    case vmIntrinsics::_updateBytesCRC32C:
+    case vmIntrinsics::_updateDirectByteBufferCRC32C: {
+      bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32C);
+
+      LIRItem crc(x->argument_at(0), this);
+      LIRItem buf(x->argument_at(1), this);
+      LIRItem off(x->argument_at(2), this);
+      LIRItem len(x->argument_at(3), this);
+      buf.load_item();
+      off.load_nonconstant();
+
+      LIR_Opr index = off.result();
+      int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
+      if (off.result()->is_constant()) {
+        index = LIR_OprFact::illegalOpr;
+        offset += off.result()->as_jint();
+      }
+      LIR_Opr base_op = buf.result();
+      LIR_Address* a = NULL;
+
+      if (index->is_valid()) {
+        LIR_Opr tmp = new_register(T_LONG);
+        __ convert(Bytecodes::_i2l, index, tmp);
+        index = tmp;
+        __ add(index, LIR_OprFact::intptrConst(offset), index);
+        a = new LIR_Address(base_op, index, T_BYTE);
+      } else {
+        a = new LIR_Address(base_op, offset, T_BYTE);
+      }
+
+      BasicTypeList signature(3);
+      signature.append(T_INT);
+      signature.append(T_ADDRESS);
+      signature.append(T_INT);
+      CallingConvention* cc = frame_map()->c_calling_convention(&signature);
+      const LIR_Opr result_reg = result_register_for(x->type());
+
+      LIR_Opr arg1 = cc->at(0),
+              arg2 = cc->at(1),
+              arg3 = cc->at(2);
+
+      crc.load_item_force(arg1); // We skip int->long conversion here, because CRC32 stub doesn't care about high bits.
+      __ leal(LIR_OprFact::address(a), arg2);
+      len.load_item_force(arg3); // We skip int->long conversion here, , because CRC32 stub expects int.
+
+      __ call_runtime_leaf(StubRoutines::updateBytesCRC32C(), LIR_OprFact::illegalOpr, result_reg, cc->args());
+      __ move(result_reg, result);
+      break;
+    }
+    default: {
+      ShouldNotReachHere();
+    }
+  }
+}
+
 void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) {
   assert(x->number_of_arguments() == 3, "wrong type");
   assert(UseFMA, "Needs FMA instructions support.");
@@ -1460,7 +1507,3 @@
 void LIRGenerator::do_vectorizedMismatch(Intrinsic* x) {
   fatal("vectorizedMismatch intrinsic is not implemented on this platform");
 }
-
-void LIRGenerator::do_update_CRC32C(Intrinsic* x) {
-  Unimplemented();
-}
--- a/hotspot/src/cpu/ppc/vm/interp_masm_ppc.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/interp_masm_ppc.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -45,8 +45,8 @@
 #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);
+  virtual void check_and_handle_popframe(Register scratch_reg);
+  virtual void check_and_handle_earlyret(Register scratch_reg);
 
   // Base routine for all dispatches.
   void dispatch_base(TosState state, address* table);
--- a/hotspot/src/cpu/ppc/vm/macroAssembler_ppc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/macroAssembler_ppc.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -4092,7 +4092,7 @@
  * @param table register pointing to CRC table
  */
 void MacroAssembler::update_byteLoop_crc32(Register crc, Register buf, Register len, Register table,
-                                           Register data, bool loopAlignment, bool invertCRC) {
+                                           Register data, bool loopAlignment) {
   assert_different_registers(crc, buf, len, table, data);
 
   Label L_mainLoop, L_done;
@@ -4103,10 +4103,6 @@
   clrldi_(len, len, 32);                         // Enforce 32 bit. Anything to do?
   beq(CCR0, L_done);
 
-  if (invertCRC) {
-    nand(crc, crc, crc);                         // ~c
-  }
-
   mtctr(len);
   align(mainLoop_alignment);
   BIND(L_mainLoop);
@@ -4115,10 +4111,6 @@
     update_byte_crc32(crc, data, table);
     bdnz(L_mainLoop);                            // Iterate.
 
-  if (invertCRC) {
-    nand(crc, crc, crc);                         // ~c
-  }
-
   bind(L_done);
 }
 
@@ -4175,7 +4167,8 @@
  */
 void MacroAssembler::kernel_crc32_2word(Register crc, Register buf, Register len, Register table,
                                         Register t0,  Register t1,  Register t2,  Register t3,
-                                        Register tc0, Register tc1, Register tc2, Register tc3) {
+                                        Register tc0, Register tc1, Register tc2, Register tc3,
+                                        bool invertCRC) {
   assert_different_registers(crc, buf, len, table);
 
   Label L_mainLoop, L_tail;
@@ -4189,14 +4182,16 @@
   const int complexThreshold   = 2*mainLoop_stepping;
 
   // Don't test for len <= 0 here. This pathological case should not occur anyway.
-  // Optimizing for it by adding a test and a branch seems to be a waste of CPU cycles.
-  // The situation itself is detected and handled correctly by the conditional branches
-  // following  aghi(len, -stepping) and aghi(len, +stepping).
+  // Optimizing for it by adding a test and a branch seems to be a waste of CPU cycles
+  // for all well-behaved cases. The situation itself is detected and handled correctly
+  // within update_byteLoop_crc32.
   assert(tailLoop_stepping == 1, "check tailLoop_stepping!");
 
   BLOCK_COMMENT("kernel_crc32_2word {");
 
-  nand(crc, crc, crc);                           // ~c
+  if (invertCRC) {
+    nand(crc, crc, crc);                      // 1s complement of crc
+  }
 
   // Check for short (<mainLoop_stepping) buffer.
   cmpdi(CCR0, len, complexThreshold);
@@ -4217,7 +4212,7 @@
       blt(CCR0, L_tail);                         // For less than one mainloop_stepping left, do only tail processing
       mr(len, tmp);                              // remaining bytes for main loop (>=mainLoop_stepping is guaranteed).
     }
-    update_byteLoop_crc32(crc, buf, tmp2, table, data, false, false);
+    update_byteLoop_crc32(crc, buf, tmp2, table, data, false);
   }
 
   srdi(tmp2, len, log_stepping);                 // #iterations for mainLoop
@@ -4253,9 +4248,11 @@
 
   // Process last few (<complexThreshold) bytes of buffer.
   BIND(L_tail);
-  update_byteLoop_crc32(crc, buf, len, table, data, false, false);
-
-  nand(crc, crc, crc);                           // ~c
+  update_byteLoop_crc32(crc, buf, len, table, data, false);
+
+  if (invertCRC) {
+    nand(crc, crc, crc);                      // 1s complement of crc
+  }
   BLOCK_COMMENT("} kernel_crc32_2word");
 }
 
@@ -4269,7 +4266,8 @@
  */
 void MacroAssembler::kernel_crc32_1word(Register crc, Register buf, Register len, Register table,
                                         Register t0,  Register t1,  Register t2,  Register t3,
-                                        Register tc0, Register tc1, Register tc2, Register tc3) {
+                                        Register tc0, Register tc1, Register tc2, Register tc3,
+                                        bool invertCRC) {
   assert_different_registers(crc, buf, len, table);
 
   Label L_mainLoop, L_tail;
@@ -4283,14 +4281,16 @@
   const int complexThreshold   = 2*mainLoop_stepping;
 
   // Don't test for len <= 0 here. This pathological case should not occur anyway.
-  // Optimizing for it by adding a test and a branch seems to be a waste of CPU cycles.
-  // The situation itself is detected and handled correctly by the conditional branches
-  // following  aghi(len, -stepping) and aghi(len, +stepping).
+  // Optimizing for it by adding a test and a branch seems to be a waste of CPU cycles
+  // for all well-behaved cases. The situation itself is detected and handled correctly
+  // within update_byteLoop_crc32.
   assert(tailLoop_stepping == 1, "check tailLoop_stepping!");
 
   BLOCK_COMMENT("kernel_crc32_1word {");
 
-  nand(crc, crc, crc);                           // ~c
+  if (invertCRC) {
+    nand(crc, crc, crc);                      // 1s complement of crc
+  }
 
   // Check for short (<mainLoop_stepping) buffer.
   cmpdi(CCR0, len, complexThreshold);
@@ -4311,7 +4311,7 @@
       blt(CCR0, L_tail);                         // For less than one mainloop_stepping left, do only tail processing
       mr(len, tmp);                              // remaining bytes for main loop (>=mainLoop_stepping is guaranteed).
     }
-    update_byteLoop_crc32(crc, buf, tmp2, table, data, false, false);
+    update_byteLoop_crc32(crc, buf, tmp2, table, data, false);
   }
 
   srdi(tmp2, len, log_stepping);                 // #iterations for mainLoop
@@ -4346,9 +4346,11 @@
 
   // Process last few (<complexThreshold) bytes of buffer.
   BIND(L_tail);
-  update_byteLoop_crc32(crc, buf, len, table, data, false, false);
-
-  nand(crc, crc, crc);                           // ~c
+  update_byteLoop_crc32(crc, buf, len, table, data, false);
+
+  if (invertCRC) {
+    nand(crc, crc, crc);                      // 1s complement of crc
+  }
   BLOCK_COMMENT("} kernel_crc32_1word");
 }
 
@@ -4361,16 +4363,24 @@
  * Uses R7_ARG5, R8_ARG6 as work registers.
  */
 void MacroAssembler::kernel_crc32_1byte(Register crc, Register buf, Register len, Register table,
-                                        Register t0,  Register t1,  Register t2,  Register t3) {
+                                        Register t0,  Register t1,  Register t2,  Register t3,
+                                        bool invertCRC) {
   assert_different_registers(crc, buf, len, table);
 
   Register  data = t0;                   // Holds the current byte to be folded into crc.
 
   BLOCK_COMMENT("kernel_crc32_1byte {");
 
+  if (invertCRC) {
+    nand(crc, crc, crc);                      // 1s complement of crc
+  }
+
   // Process all bytes in a single-byte loop.
-  update_byteLoop_crc32(crc, buf, len, table, data, true, true);
-
+  update_byteLoop_crc32(crc, buf, len, table, data, true);
+
+  if (invertCRC) {
+    nand(crc, crc, crc);                      // 1s complement of crc
+  }
   BLOCK_COMMENT("} kernel_crc32_1byte");
 }
 
@@ -4388,7 +4398,8 @@
  */
 void MacroAssembler::kernel_crc32_1word_vpmsumd(Register crc, Register buf, Register len, Register table,
                                                 Register constants,  Register barretConstants,
-                                                Register t0,  Register t1, Register t2, Register t3, Register t4) {
+                                                Register t0,  Register t1, Register t2, Register t3, Register t4,
+                                                bool invertCRC) {
   assert_different_registers(crc, buf, len, table);
 
   Label L_alignedHead, L_tail, L_alignTail, L_start, L_end;
@@ -4406,13 +4417,15 @@
     Register tc0 = t4;
     Register tc1 = constants;
     Register tc2 = barretConstants;
-    kernel_crc32_1word(crc, buf, len, table,t0, t1, t2, t3, tc0, tc1, tc2, table);
+    kernel_crc32_1word(crc, buf, len, table,t0, t1, t2, t3, tc0, tc1, tc2, table, invertCRC);
     b(L_end);
 
   BIND(L_start);
 
     // 2. ~c
-    nand(crc, crc, crc);
+    if (invertCRC) {
+      nand(crc, crc, crc);                      // 1s complement of crc
+    }
 
     // 3. calculate from 0 to first 128bit-aligned address
     clrldi_(prealign, buf, 57);
@@ -4421,7 +4434,7 @@
     subfic(prealign, prealign, 128);
 
     subf(len, prealign, len);
-    update_byteLoop_crc32(crc, buf, prealign, table, t2, false, false);
+    update_byteLoop_crc32(crc, buf, prealign, table, t2, false);
 
     // 4. calculate from first 128bit-aligned address to last 128bit-aligned address
     BIND(L_alignedHead);
@@ -4436,12 +4449,14 @@
     cmpdi(CCR0, postalign, 0);
     beq(CCR0, L_tail);
 
-    update_byteLoop_crc32(crc, buf, postalign, table, t2, false, false);
+    update_byteLoop_crc32(crc, buf, postalign, table, t2, false);
 
     BIND(L_tail);
 
     // 6. ~c
-    nand(crc, crc, crc);
+    if (invertCRC) {
+      nand(crc, crc, crc);                      // 1s complement of crc
+    }
 
   BIND(L_end);
 
@@ -4933,16 +4948,35 @@
   offsetInt -= 8;  ld(R31, offsetInt, R1_SP);
 }
 
-void MacroAssembler::kernel_crc32_singleByte(Register crc, Register buf, Register len, Register table, Register tmp) {
+void MacroAssembler::kernel_crc32_singleByte(Register crc, Register buf, Register len, Register table, Register tmp, bool invertCRC) {
   assert_different_registers(crc, buf, /* len,  not used!! */ table, tmp);
 
   BLOCK_COMMENT("kernel_crc32_singleByte:");
-  nand(crc, crc, crc);       // ~c
-
-  lbz(tmp, 0, buf);          // Byte from buffer, zero-extended.
+  if (invertCRC) {
+    nand(crc, crc, crc);                // 1s complement of crc
+  }
+
+  lbz(tmp, 0, buf);                     // Byte from buffer, zero-extended.
   update_byte_crc32(crc, tmp, table);
 
-  nand(crc, crc, crc);       // ~c
+  if (invertCRC) {
+    nand(crc, crc, crc);                // 1s complement of crc
+  }
+}
+
+void MacroAssembler::kernel_crc32_singleByteReg(Register crc, Register val, Register table, bool invertCRC) {
+  assert_different_registers(crc, val, table);
+
+  BLOCK_COMMENT("kernel_crc32_singleByteReg:");
+  if (invertCRC) {
+    nand(crc, crc, crc);                // 1s complement of crc
+  }
+
+  update_byte_crc32(crc, val, table);
+
+  if (invertCRC) {
+    nand(crc, crc, crc);                // 1s complement of crc
+  }
 }
 
 // dest_lo += src1 + src2
--- a/hotspot/src/cpu/ppc/vm/macroAssembler_ppc.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/macroAssembler_ppc.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -817,33 +817,47 @@
                        Register tmp6, Register tmp7, Register tmp8, Register tmp9, Register tmp10,
                        Register tmp11, Register tmp12, Register tmp13);
 
-  // CRC32 Intrinsics.
+  // Emitters for CRC32 calculation.
+  // A note on invertCRC:
+  //   Unfortunately, internal representation of crc differs between CRC32 and CRC32C.
+  //   CRC32 holds it's current crc value in the externally visible representation.
+  //   CRC32C holds it's current crc value in internal format, ready for updating.
+  //   Thus, the crc value must be bit-flipped before updating it in the CRC32 case.
+  //   In the CRC32C case, it must be bit-flipped when it is given to the outside world (getValue()).
+  //   The bool invertCRC parameter indicates whether bit-flipping is required before updates.
   void load_reverse_32(Register dst, Register src);
   int  crc32_table_columns(Register table, Register tc0, Register tc1, Register tc2, Register tc3);
   void fold_byte_crc32(Register crc, Register val, Register table, Register tmp);
   void fold_8bit_crc32(Register crc, Register table, Register tmp);
   void update_byte_crc32(Register crc, Register val, Register table);
   void update_byteLoop_crc32(Register crc, Register buf, Register len, Register table,
-                             Register data, bool loopAlignment, bool invertCRC);
+                             Register data, bool loopAlignment);
   void update_1word_crc32(Register crc, Register buf, Register table, int bufDisp, int bufInc,
                           Register t0,  Register t1,  Register t2,  Register t3,
                           Register tc0, Register tc1, Register tc2, Register tc3);
   void kernel_crc32_2word(Register crc, Register buf, Register len, Register table,
                           Register t0,  Register t1,  Register t2,  Register t3,
-                          Register tc0, Register tc1, Register tc2, Register tc3);
+                          Register tc0, Register tc1, Register tc2, Register tc3,
+                          bool invertCRC);
   void kernel_crc32_1word(Register crc, Register buf, Register len, Register table,
                           Register t0,  Register t1,  Register t2,  Register t3,
-                          Register tc0, Register tc1, Register tc2, Register tc3);
+                          Register tc0, Register tc1, Register tc2, Register tc3,
+                          bool invertCRC);
   void kernel_crc32_1byte(Register crc, Register buf, Register len, Register table,
-                          Register t0,  Register t1,  Register t2,  Register t3);
+                          Register t0,  Register t1,  Register t2,  Register t3,
+                          bool invertCRC);
   void kernel_crc32_1word_vpmsumd(Register crc, Register buf, Register len, Register table,
                           Register constants, Register barretConstants,
-                          Register t0,  Register t1, Register t2, Register t3, Register t4);
+                          Register t0,  Register t1, Register t2, Register t3, Register t4,
+                          bool invertCRC);
   void kernel_crc32_1word_aligned(Register crc, Register buf, Register len,
                           Register constants, Register barretConstants,
                           Register t0, Register t1, Register t2);
 
-  void kernel_crc32_singleByte(Register crc, Register buf, Register len, Register table, Register tmp);
+  void kernel_crc32_singleByte(Register crc, Register buf, Register len, Register table, Register tmp,
+                               bool invertCRC);
+  void kernel_crc32_singleByteReg(Register crc, Register val, Register table,
+                                  bool invertCRC);
 
   //
   // Debugging
--- a/hotspot/src/cpu/ppc/vm/metaspaceShared_ppc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2013 SAP SE. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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 "asm/macroAssembler.inline.hpp"
-#include "asm/codeBuffer.hpp"
-#include "memory/metaspaceShared.hpp"
-
-// Generate the self-patching vtable method:
-//
-// This method will be called (as any other Klass virtual method) with
-// the Klass itself as the first argument.  Example:
-//
-//   oop obj;
-//   int size = obj->klass()->klass_part()->oop_size(this);
-//
-// for which the virtual method call is Klass::oop_size();
-//
-// The dummy method is called with the Klass object as the first
-// operand, and an object as the second argument.
-//
-
-//=====================================================================
-
-// All of the dummy methods in the vtable are essentially identical,
-// differing only by an ordinal constant, and they bear no releationship
-// to the original method which the caller intended. Also, there needs
-// to be 'vtbl_list_size' instances of the vtable in order to
-// differentiate between the 'vtable_list_size' original Klass objects.
-
-#define __ masm->
-
-void MetaspaceShared::generate_vtable_methods(void** vtbl_list,
-                                              void** vtable,
-                                              char** md_top,
-                                              char* md_end,
-                                              char** mc_top,
-                                              char* mc_end) {
-  intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*);
-  *(intptr_t *)(*md_top) = vtable_bytes;
-  *md_top += sizeof(intptr_t);
-  void** dummy_vtable = (void**)*md_top;
-  *vtable = dummy_vtable;
-  *md_top += vtable_bytes;
-
-  // Get ready to generate dummy methods.
-
-  CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top);
-  MacroAssembler* masm = new MacroAssembler(&cb);
-
-  // There are more general problems with CDS on ppc, so I can not
-  // really test this. But having this instead of Unimplementd() allows
-  // us to pass TestOptionsWithRanges.java.
-  __ unimplemented();
-}
-
--- a/hotspot/src/cpu/ppc/vm/methodHandles_ppc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/methodHandles_ppc.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -71,7 +71,7 @@
                                  Register temp_reg, Register temp2_reg,
                                  const char* error_message) {
   InstanceKlass** klass_addr = SystemDictionary::well_known_klass_addr(klass_id);
-  KlassHandle klass = SystemDictionary::well_known_klass(klass_id);
+  Klass* klass = SystemDictionary::well_known_klass(klass_id);
   Label L_ok, L_bad;
   BLOCK_COMMENT("verify_klass {");
   __ verify_oop(obj_reg);
--- a/hotspot/src/cpu/ppc/vm/stubGenerator_ppc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/stubGenerator_ppc.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -3276,6 +3276,36 @@
     return start;
   }
 
+
+  // Compute CRC32/CRC32C function.
+  void generate_CRC_updateBytes(const char* name, Register table, bool invertCRC) {
+
+      // arguments to kernel_crc32:
+      const Register crc     = R3_ARG1;  // Current checksum, preset by caller or result from previous call.
+      const Register data    = R4_ARG2;  // source byte array
+      const Register dataLen = R5_ARG3;  // #bytes to process
+
+      const Register t0      = R2;
+      const Register t1      = R7;
+      const Register t2      = R8;
+      const Register t3      = R9;
+      const Register tc0     = R10;
+      const Register tc1     = R11;
+      const Register tc2     = R12;
+
+      BLOCK_COMMENT("Stub body {");
+      assert_different_registers(crc, data, dataLen, table);
+
+      __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, tc0, tc1, tc2, table, invertCRC);
+
+      BLOCK_COMMENT("return");
+      __ mr_if_needed(R3_RET, crc);      // Updated crc is function result. No copying required (R3_ARG1 == R3_RET).
+      __ blr();
+
+      BLOCK_COMMENT("} Stub body");
+  }
+
+
   /**
    * Arguments:
    *
@@ -3296,14 +3326,14 @@
     StubCodeMark mark(this, "StubRoutines", name);
     address start = __ function_entry();  // Remember stub start address (is rtn value).
 
+    const Register table   = R6;       // crc table address
+
+#ifdef VM_LITTLE_ENDIAN
     // arguments to kernel_crc32:
     const Register crc     = R3_ARG1;  // Current checksum, preset by caller or result from previous call.
     const Register data    = R4_ARG2;  // source byte array
     const Register dataLen = R5_ARG3;  // #bytes to process
 
-    const Register table   = R6;       // crc table address
-
-#ifdef VM_LITTLE_ENDIAN
     if (VM_Version::has_vpmsumb()) {
       const Register constants    = R2;  // constants address
       const Register bconstants   = R8;  // barret table address
@@ -3321,7 +3351,7 @@
       StubRoutines::ppc64::generate_load_crc_constants_addr(_masm, constants);
       StubRoutines::ppc64::generate_load_crc_barret_constants_addr(_masm, bconstants);
 
-      __ kernel_crc32_1word_vpmsumd(crc, data, dataLen, table, constants, bconstants, t0, t1, t2, t3, t4);
+      __ kernel_crc32_1word_vpmsumd(crc, data, dataLen, table, constants, bconstants, t0, t1, t2, t3, t4, true);
 
       BLOCK_COMMENT("return");
       __ mr_if_needed(R3_RET, crc);      // Updated crc is function result. No copying required (R3_ARG1 == R3_RET).
@@ -3331,31 +3361,79 @@
     } else
 #endif
     {
-      const Register t0      = R2;
-      const Register t1      = R7;
-      const Register t2      = R8;
-      const Register t3      = R9;
-      const Register tc0     = R10;
-      const Register tc1     = R11;
-      const Register tc2     = R12;
+      StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
+      generate_CRC_updateBytes(name, table, true);
+    }
+
+    return start;
+  }
+
+
+  /**
+   * Arguments:
+   *
+   * Inputs:
+   *   R3_ARG1    - int   crc
+   *   R4_ARG2    - byte* buf
+   *   R5_ARG3    - int   length (of buffer)
+   *
+   * scratch:
+   *   R2, R6-R12
+   *
+   * Ouput:
+   *   R3_RET     - int   crc result
+   */
+  // Compute CRC32C function.
+  address generate_CRC32C_updateBytes(const char* name) {
+    __ align(CodeEntryAlignment);
+    StubCodeMark mark(this, "StubRoutines", name);
+    address start = __ function_entry();  // Remember stub start address (is rtn value).
+
+    const Register table   = R6;       // crc table address
+
+#if 0   // no vector support yet for CRC32C
+#ifdef VM_LITTLE_ENDIAN
+    // arguments to kernel_crc32:
+    const Register crc     = R3_ARG1;  // Current checksum, preset by caller or result from previous call.
+    const Register data    = R4_ARG2;  // source byte array
+    const Register dataLen = R5_ARG3;  // #bytes to process
+
+    if (VM_Version::has_vpmsumb()) {
+      const Register constants    = R2;  // constants address
+      const Register bconstants   = R8;  // barret table address
+
+      const Register t0      = R9;
+      const Register t1      = R10;
+      const Register t2      = R11;
+      const Register t3      = R12;
+      const Register t4      = R7;
 
       BLOCK_COMMENT("Stub body {");
       assert_different_registers(crc, data, dataLen, table);
 
-      StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
-
-      __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, tc0, tc1, tc2, table);
+      StubRoutines::ppc64::generate_load_crc32c_table_addr(_masm, table);
+      StubRoutines::ppc64::generate_load_crc32c_constants_addr(_masm, constants);
+      StubRoutines::ppc64::generate_load_crc32c_barret_constants_addr(_masm, bconstants);
+
+      __ kernel_crc32_1word_vpmsumd(crc, data, dataLen, table, constants, bconstants, t0, t1, t2, t3, t4, false);
 
       BLOCK_COMMENT("return");
       __ mr_if_needed(R3_RET, crc);      // Updated crc is function result. No copying required (R3_ARG1 == R3_RET).
       __ blr();
 
       BLOCK_COMMENT("} Stub body");
+    } else
+#endif
+#endif
+    {
+      StubRoutines::ppc64::generate_load_crc32c_table_addr(_masm, table);
+      generate_CRC_updateBytes(name, table, false);
     }
 
     return start;
   }
 
+
   // Initialization
   void generate_initial() {
     // Generates all stubs and initializes the entry points
@@ -3383,6 +3461,12 @@
       StubRoutines::_crc_table_adr    = (address)StubRoutines::ppc64::_crc_table;
       StubRoutines::_updateBytesCRC32 = generate_CRC32_updateBytes("CRC32_updateBytes");
     }
+
+    // CRC32C Intrinsics.
+    if (UseCRC32CIntrinsics) {
+      StubRoutines::_crc32c_table_addr = (address)StubRoutines::ppc64::_crc32c_table;
+      StubRoutines::_updateBytesCRC32C = generate_CRC32C_updateBytes("CRC32C_updateBytes");
+    }
   }
 
   void generate_all() {
--- a/hotspot/src/cpu/ppc/vm/stubRoutines_ppc.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/stubRoutines_ppc.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -55,13 +55,16 @@
 
   // CRC32 Intrinsics.
   static juint _crc_table[CRC32_TABLES][CRC32_COLUMN_SIZE];
+  static juint _crc32c_table[CRC32_TABLES][CRC32_COLUMN_SIZE];
   static juint* _constants;
   static juint* _barret_constants;
 
  public:
 
   // CRC32 Intrinsics.
+  static void generate_load_table_addr(MacroAssembler* masm, Register table, address table_addr, uint64_t table_contents);
   static void generate_load_crc_table_addr(MacroAssembler* masm, Register table);
+  static void generate_load_crc32c_table_addr(MacroAssembler* masm, Register table);
   static void generate_load_crc_constants_addr(MacroAssembler* masm, Register table);
   static void generate_load_crc_barret_constants_addr(MacroAssembler* masm, Register table);
   static juint* generate_crc_constants();
--- a/hotspot/src/cpu/ppc/vm/stubRoutines_ppc_64.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/stubRoutines_ppc_64.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
+ * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,7 +32,11 @@
 
 #define __ masm->
 
-// CRC32 Intrinsics.
+// CRC32(C) Intrinsics.
+void StubRoutines::ppc64::generate_load_crc32c_table_addr(MacroAssembler* masm, Register table) {
+  __ load_const_optimized(table, StubRoutines::_crc32c_table_addr, R0);
+}
+
 void StubRoutines::ppc64::generate_load_crc_table_addr(MacroAssembler* masm, Register table) {
   __ load_const_optimized(table, StubRoutines::_crc_table_adr, R0);
 }
@@ -347,441 +351,592 @@
  *  crc_table[] from jdk/src/share/native/java/util/zip/zlib-1.2.8/crc32.h
  */
 juint StubRoutines::ppc64::_crc_table[CRC32_TABLES][CRC32_COLUMN_SIZE] = {
-  {
-    0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
-    0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
-    0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
-    0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
-    0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
-    0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
-    0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
-    0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
-    0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
-    0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
-    0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
-    0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
-    0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
-    0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
-    0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
-    0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
-    0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
-    0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
-    0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
-    0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
-    0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
-    0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
-    0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
-    0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
-    0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
-    0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
-    0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
-    0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
-    0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
-    0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
-    0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
-    0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
-    0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
-    0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
-    0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
-    0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
-    0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
-    0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
-    0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
-    0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
-    0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
-    0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
-    0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
-    0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
-    0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
-    0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
-    0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
-    0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
-    0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
-    0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
-    0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
-    0x2d02ef8dUL
-#ifdef  CRC32_BYFOUR
-  },
-  {
-    0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
-    0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
-    0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
-    0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
-    0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
-    0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
-    0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
-    0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
-    0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
-    0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
-    0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
-    0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
-    0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
-    0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
-    0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
-    0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
-    0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
-    0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
-    0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
-    0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
-    0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
-    0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
-    0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
-    0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
-    0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
-    0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
-    0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
-    0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
-    0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
-    0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
-    0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
-    0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
-    0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
-    0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
-    0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
-    0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
-    0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
-    0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
-    0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
-    0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
-    0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
-    0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
-    0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
-    0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
-    0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
-    0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
-    0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
-    0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
-    0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
-    0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
-    0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
-    0x9324fd72UL
-  },
-  {
-    0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
-    0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
-    0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
-    0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
-    0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
-    0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
-    0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
-    0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
-    0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
-    0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
-    0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
-    0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
-    0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
-    0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
-    0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
-    0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
-    0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
-    0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
-    0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
-    0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
-    0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
-    0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
-    0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
-    0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
-    0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
-    0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
-    0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
-    0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
-    0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
-    0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
-    0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
-    0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
-    0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
-    0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
-    0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
-    0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
-    0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
-    0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
-    0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
-    0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
-    0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
-    0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
-    0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
-    0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
-    0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
-    0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
-    0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
-    0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
-    0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
-    0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
-    0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
-    0xbe9834edUL
-  },
-  {
-    0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
-    0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
-    0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
-    0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
-    0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
-    0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
-    0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
-    0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
-    0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
-    0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
-    0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
-    0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
-    0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
-    0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
-    0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
-    0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
-    0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
-    0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
-    0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
-    0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
-    0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
-    0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
-    0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
-    0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
-    0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
-    0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
-    0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
-    0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
-    0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
-    0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
-    0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
-    0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
-    0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
-    0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
-    0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
-    0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
-    0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
-    0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
-    0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
-    0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
-    0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
-    0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
-    0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
-    0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
-    0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
-    0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
-    0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
-    0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
-    0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
-    0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
-    0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
-    0xde0506f1UL
-  },
-  {
-    0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
-    0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
-    0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
-    0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
-    0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
-    0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
-    0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
-    0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
-    0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
-    0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
-    0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
-    0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
-    0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
-    0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
-    0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
-    0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
-    0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
-    0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
-    0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
-    0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
-    0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
-    0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
-    0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
-    0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
-    0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
-    0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
-    0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
-    0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
-    0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
-    0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
-    0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
-    0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
-    0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
-    0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
-    0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
-    0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
-    0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
-    0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
-    0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
-    0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
-    0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
-    0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
-    0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
-    0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
-    0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
-    0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
-    0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
-    0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
-    0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
-    0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
-    0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
-    0x8def022dUL
-  },
-  {
-    0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
-    0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
-    0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
-    0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
-    0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
-    0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
-    0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
-    0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
-    0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
-    0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
-    0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
-    0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
-    0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
-    0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
-    0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
-    0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
-    0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
-    0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
-    0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
-    0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
-    0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
-    0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
-    0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
-    0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
-    0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
-    0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
-    0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
-    0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
-    0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
-    0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
-    0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
-    0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
-    0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
-    0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
-    0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
-    0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
-    0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
-    0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
-    0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
-    0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
-    0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
-    0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
-    0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
-    0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
-    0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
-    0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
-    0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
-    0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
-    0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
-    0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
-    0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
-    0x72fd2493UL
-  },
-  {
-    0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
-    0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
-    0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
-    0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
-    0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
-    0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
-    0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
-    0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
-    0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
-    0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
-    0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
-    0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
-    0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
-    0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
-    0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
-    0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
-    0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
-    0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
-    0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
-    0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
-    0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
-    0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
-    0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
-    0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
-    0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
-    0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
-    0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
-    0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
-    0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
-    0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
-    0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
-    0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
-    0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
-    0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
-    0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
-    0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
-    0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
-    0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
-    0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
-    0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
-    0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
-    0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
-    0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
-    0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
-    0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
-    0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
-    0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
-    0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
-    0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
-    0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
-    0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
-    0xed3498beUL
-  },
-  {
-    0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
-    0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
-    0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
-    0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
-    0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
-    0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
-    0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
-    0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
-    0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
-    0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
-    0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
-    0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
-    0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
-    0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
-    0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
-    0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
-    0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
-    0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
-    0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
-    0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
-    0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
-    0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
-    0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
-    0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
-    0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
-    0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
-    0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
-    0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
-    0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
-    0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
-    0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
-    0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
-    0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
-    0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
-    0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
-    0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
-    0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
-    0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
-    0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
-    0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
-    0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
-    0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
-    0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
-    0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
-    0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
-    0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
-    0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
-    0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
-    0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
-    0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
-    0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
-    0xf10605deUL
-#endif
-  }
-};
+    /* polyBits = 7976584769 0x00000001db710641L, shifted = 0xedb88320 */
+    /* CRC32 table for single bytes, auto-generated.  DO NOT MODIFY!  */
+    /* CRC32 table 0 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U, 0x706af48fU, 0xe963a535U, 0x9e6495a3U
+      /* 8 */  , 0x0edb8832U, 0x79dcb8a4U, 0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U, 0x90bf1d91U
+      /* 16 */  , 0x1db71064U, 0x6ab020f2U, 0xf3b97148U, 0x84be41deU, 0x1adad47dU, 0x6ddde4ebU, 0xf4d4b551U, 0x83d385c7U
+      /* 24 */  , 0x136c9856U, 0x646ba8c0U, 0xfd62f97aU, 0x8a65c9ecU, 0x14015c4fU, 0x63066cd9U, 0xfa0f3d63U, 0x8d080df5U
+      /* 32 */  , 0x3b6e20c8U, 0x4c69105eU, 0xd56041e4U, 0xa2677172U, 0x3c03e4d1U, 0x4b04d447U, 0xd20d85fdU, 0xa50ab56bU
+      /* 40 */  , 0x35b5a8faU, 0x42b2986cU, 0xdbbbc9d6U, 0xacbcf940U, 0x32d86ce3U, 0x45df5c75U, 0xdcd60dcfU, 0xabd13d59U
+      /* 48 */  , 0x26d930acU, 0x51de003aU, 0xc8d75180U, 0xbfd06116U, 0x21b4f4b5U, 0x56b3c423U, 0xcfba9599U, 0xb8bda50fU
+      /* 56 */  , 0x2802b89eU, 0x5f058808U, 0xc60cd9b2U, 0xb10be924U, 0x2f6f7c87U, 0x58684c11U, 0xc1611dabU, 0xb6662d3dU
+      /* 64 */  , 0x76dc4190U, 0x01db7106U, 0x98d220bcU, 0xefd5102aU, 0x71b18589U, 0x06b6b51fU, 0x9fbfe4a5U, 0xe8b8d433U
+      /* 72 */  , 0x7807c9a2U, 0x0f00f934U, 0x9609a88eU, 0xe10e9818U, 0x7f6a0dbbU, 0x086d3d2dU, 0x91646c97U, 0xe6635c01U
+      /* 80 */  , 0x6b6b51f4U, 0x1c6c6162U, 0x856530d8U, 0xf262004eU, 0x6c0695edU, 0x1b01a57bU, 0x8208f4c1U, 0xf50fc457U
+      /* 88 */  , 0x65b0d9c6U, 0x12b7e950U, 0x8bbeb8eaU, 0xfcb9887cU, 0x62dd1ddfU, 0x15da2d49U, 0x8cd37cf3U, 0xfbd44c65U
+      /* 96 */  , 0x4db26158U, 0x3ab551ceU, 0xa3bc0074U, 0xd4bb30e2U, 0x4adfa541U, 0x3dd895d7U, 0xa4d1c46dU, 0xd3d6f4fbU
+      /* 104 */  , 0x4369e96aU, 0x346ed9fcU, 0xad678846U, 0xda60b8d0U, 0x44042d73U, 0x33031de5U, 0xaa0a4c5fU, 0xdd0d7cc9U
+      /* 112 */  , 0x5005713cU, 0x270241aaU, 0xbe0b1010U, 0xc90c2086U, 0x5768b525U, 0x206f85b3U, 0xb966d409U, 0xce61e49fU
+      /* 120 */  , 0x5edef90eU, 0x29d9c998U, 0xb0d09822U, 0xc7d7a8b4U, 0x59b33d17U, 0x2eb40d81U, 0xb7bd5c3bU, 0xc0ba6cadU
+      /* 128 */  , 0xedb88320U, 0x9abfb3b6U, 0x03b6e20cU, 0x74b1d29aU, 0xead54739U, 0x9dd277afU, 0x04db2615U, 0x73dc1683U
+      /* 136 */  , 0xe3630b12U, 0x94643b84U, 0x0d6d6a3eU, 0x7a6a5aa8U, 0xe40ecf0bU, 0x9309ff9dU, 0x0a00ae27U, 0x7d079eb1U
+      /* 144 */  , 0xf00f9344U, 0x8708a3d2U, 0x1e01f268U, 0x6906c2feU, 0xf762575dU, 0x806567cbU, 0x196c3671U, 0x6e6b06e7U
+      /* 152 */  , 0xfed41b76U, 0x89d32be0U, 0x10da7a5aU, 0x67dd4accU, 0xf9b9df6fU, 0x8ebeeff9U, 0x17b7be43U, 0x60b08ed5U
+      /* 160 */  , 0xd6d6a3e8U, 0xa1d1937eU, 0x38d8c2c4U, 0x4fdff252U, 0xd1bb67f1U, 0xa6bc5767U, 0x3fb506ddU, 0x48b2364bU
+      /* 168 */  , 0xd80d2bdaU, 0xaf0a1b4cU, 0x36034af6U, 0x41047a60U, 0xdf60efc3U, 0xa867df55U, 0x316e8eefU, 0x4669be79U
+      /* 176 */  , 0xcb61b38cU, 0xbc66831aU, 0x256fd2a0U, 0x5268e236U, 0xcc0c7795U, 0xbb0b4703U, 0x220216b9U, 0x5505262fU
+      /* 184 */  , 0xc5ba3bbeU, 0xb2bd0b28U, 0x2bb45a92U, 0x5cb36a04U, 0xc2d7ffa7U, 0xb5d0cf31U, 0x2cd99e8bU, 0x5bdeae1dU
+      /* 192 */  , 0x9b64c2b0U, 0xec63f226U, 0x756aa39cU, 0x026d930aU, 0x9c0906a9U, 0xeb0e363fU, 0x72076785U, 0x05005713U
+      /* 200 */  , 0x95bf4a82U, 0xe2b87a14U, 0x7bb12baeU, 0x0cb61b38U, 0x92d28e9bU, 0xe5d5be0dU, 0x7cdcefb7U, 0x0bdbdf21U
+      /* 208 */  , 0x86d3d2d4U, 0xf1d4e242U, 0x68ddb3f8U, 0x1fda836eU, 0x81be16cdU, 0xf6b9265bU, 0x6fb077e1U, 0x18b74777U
+      /* 216 */  , 0x88085ae6U, 0xff0f6a70U, 0x66063bcaU, 0x11010b5cU, 0x8f659effU, 0xf862ae69U, 0x616bffd3U, 0x166ccf45U
+      /* 224 */  , 0xa00ae278U, 0xd70dd2eeU, 0x4e048354U, 0x3903b3c2U, 0xa7672661U, 0xd06016f7U, 0x4969474dU, 0x3e6e77dbU
+      /* 232 */  , 0xaed16a4aU, 0xd9d65adcU, 0x40df0b66U, 0x37d83bf0U, 0xa9bcae53U, 0xdebb9ec5U, 0x47b2cf7fU, 0x30b5ffe9U
+      /* 240 */  , 0xbdbdf21cU, 0xcabac28aU, 0x53b39330U, 0x24b4a3a6U, 0xbad03605U, 0xcdd70693U, 0x54de5729U, 0x23d967bfU
+      /* 248 */  , 0xb3667a2eU, 0xc4614ab8U, 0x5d681b02U, 0x2a6f2b94U, 0xb40bbe37U, 0xc30c8ea1U, 0x5a05df1bU, 0x2d02ef8dU
+    }
+  #ifdef  CRC32_BYFOUR
+    ,
+    /* CRC32 table 1 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x191b3141U, 0x32366282U, 0x2b2d53c3U, 0x646cc504U, 0x7d77f445U, 0x565aa786U, 0x4f4196c7U
+      /* 8 */  , 0xc8d98a08U, 0xd1c2bb49U, 0xfaefe88aU, 0xe3f4d9cbU, 0xacb54f0cU, 0xb5ae7e4dU, 0x9e832d8eU, 0x87981ccfU
+      /* 16 */  , 0x4ac21251U, 0x53d92310U, 0x78f470d3U, 0x61ef4192U, 0x2eaed755U, 0x37b5e614U, 0x1c98b5d7U, 0x05838496U
+      /* 24 */  , 0x821b9859U, 0x9b00a918U, 0xb02dfadbU, 0xa936cb9aU, 0xe6775d5dU, 0xff6c6c1cU, 0xd4413fdfU, 0xcd5a0e9eU
+      /* 32 */  , 0x958424a2U, 0x8c9f15e3U, 0xa7b24620U, 0xbea97761U, 0xf1e8e1a6U, 0xe8f3d0e7U, 0xc3de8324U, 0xdac5b265U
+      /* 40 */  , 0x5d5daeaaU, 0x44469febU, 0x6f6bcc28U, 0x7670fd69U, 0x39316baeU, 0x202a5aefU, 0x0b07092cU, 0x121c386dU
+      /* 48 */  , 0xdf4636f3U, 0xc65d07b2U, 0xed705471U, 0xf46b6530U, 0xbb2af3f7U, 0xa231c2b6U, 0x891c9175U, 0x9007a034U
+      /* 56 */  , 0x179fbcfbU, 0x0e848dbaU, 0x25a9de79U, 0x3cb2ef38U, 0x73f379ffU, 0x6ae848beU, 0x41c51b7dU, 0x58de2a3cU
+      /* 64 */  , 0xf0794f05U, 0xe9627e44U, 0xc24f2d87U, 0xdb541cc6U, 0x94158a01U, 0x8d0ebb40U, 0xa623e883U, 0xbf38d9c2U
+      /* 72 */  , 0x38a0c50dU, 0x21bbf44cU, 0x0a96a78fU, 0x138d96ceU, 0x5ccc0009U, 0x45d73148U, 0x6efa628bU, 0x77e153caU
+      /* 80 */  , 0xbabb5d54U, 0xa3a06c15U, 0x888d3fd6U, 0x91960e97U, 0xded79850U, 0xc7cca911U, 0xece1fad2U, 0xf5facb93U
+      /* 88 */  , 0x7262d75cU, 0x6b79e61dU, 0x4054b5deU, 0x594f849fU, 0x160e1258U, 0x0f152319U, 0x243870daU, 0x3d23419bU
+      /* 96 */  , 0x65fd6ba7U, 0x7ce65ae6U, 0x57cb0925U, 0x4ed03864U, 0x0191aea3U, 0x188a9fe2U, 0x33a7cc21U, 0x2abcfd60U
+      /* 104 */  , 0xad24e1afU, 0xb43fd0eeU, 0x9f12832dU, 0x8609b26cU, 0xc94824abU, 0xd05315eaU, 0xfb7e4629U, 0xe2657768U
+      /* 112 */  , 0x2f3f79f6U, 0x362448b7U, 0x1d091b74U, 0x04122a35U, 0x4b53bcf2U, 0x52488db3U, 0x7965de70U, 0x607eef31U
+      /* 120 */  , 0xe7e6f3feU, 0xfefdc2bfU, 0xd5d0917cU, 0xcccba03dU, 0x838a36faU, 0x9a9107bbU, 0xb1bc5478U, 0xa8a76539U
+      /* 128 */  , 0x3b83984bU, 0x2298a90aU, 0x09b5fac9U, 0x10aecb88U, 0x5fef5d4fU, 0x46f46c0eU, 0x6dd93fcdU, 0x74c20e8cU
+      /* 136 */  , 0xf35a1243U, 0xea412302U, 0xc16c70c1U, 0xd8774180U, 0x9736d747U, 0x8e2de606U, 0xa500b5c5U, 0xbc1b8484U
+      /* 144 */  , 0x71418a1aU, 0x685abb5bU, 0x4377e898U, 0x5a6cd9d9U, 0x152d4f1eU, 0x0c367e5fU, 0x271b2d9cU, 0x3e001cddU
+      /* 152 */  , 0xb9980012U, 0xa0833153U, 0x8bae6290U, 0x92b553d1U, 0xddf4c516U, 0xc4eff457U, 0xefc2a794U, 0xf6d996d5U
+      /* 160 */  , 0xae07bce9U, 0xb71c8da8U, 0x9c31de6bU, 0x852aef2aU, 0xca6b79edU, 0xd37048acU, 0xf85d1b6fU, 0xe1462a2eU
+      /* 168 */  , 0x66de36e1U, 0x7fc507a0U, 0x54e85463U, 0x4df36522U, 0x02b2f3e5U, 0x1ba9c2a4U, 0x30849167U, 0x299fa026U
+      /* 176 */  , 0xe4c5aeb8U, 0xfdde9ff9U, 0xd6f3cc3aU, 0xcfe8fd7bU, 0x80a96bbcU, 0x99b25afdU, 0xb29f093eU, 0xab84387fU
+      /* 184 */  , 0x2c1c24b0U, 0x350715f1U, 0x1e2a4632U, 0x07317773U, 0x4870e1b4U, 0x516bd0f5U, 0x7a468336U, 0x635db277U
+      /* 192 */  , 0xcbfad74eU, 0xd2e1e60fU, 0xf9ccb5ccU, 0xe0d7848dU, 0xaf96124aU, 0xb68d230bU, 0x9da070c8U, 0x84bb4189U
+      /* 200 */  , 0x03235d46U, 0x1a386c07U, 0x31153fc4U, 0x280e0e85U, 0x674f9842U, 0x7e54a903U, 0x5579fac0U, 0x4c62cb81U
+      /* 208 */  , 0x8138c51fU, 0x9823f45eU, 0xb30ea79dU, 0xaa1596dcU, 0xe554001bU, 0xfc4f315aU, 0xd7626299U, 0xce7953d8U
+      /* 216 */  , 0x49e14f17U, 0x50fa7e56U, 0x7bd72d95U, 0x62cc1cd4U, 0x2d8d8a13U, 0x3496bb52U, 0x1fbbe891U, 0x06a0d9d0U
+      /* 224 */  , 0x5e7ef3ecU, 0x4765c2adU, 0x6c48916eU, 0x7553a02fU, 0x3a1236e8U, 0x230907a9U, 0x0824546aU, 0x113f652bU
+      /* 232 */  , 0x96a779e4U, 0x8fbc48a5U, 0xa4911b66U, 0xbd8a2a27U, 0xf2cbbce0U, 0xebd08da1U, 0xc0fdde62U, 0xd9e6ef23U
+      /* 240 */  , 0x14bce1bdU, 0x0da7d0fcU, 0x268a833fU, 0x3f91b27eU, 0x70d024b9U, 0x69cb15f8U, 0x42e6463bU, 0x5bfd777aU
+      /* 248 */  , 0xdc656bb5U, 0xc57e5af4U, 0xee530937U, 0xf7483876U, 0xb809aeb1U, 0xa1129ff0U, 0x8a3fcc33U, 0x9324fd72U
+    }
+    ,
+    /* CRC32 table 2 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x01c26a37U, 0x0384d46eU, 0x0246be59U, 0x0709a8dcU, 0x06cbc2ebU, 0x048d7cb2U, 0x054f1685U
+      /* 8 */  , 0x0e1351b8U, 0x0fd13b8fU, 0x0d9785d6U, 0x0c55efe1U, 0x091af964U, 0x08d89353U, 0x0a9e2d0aU, 0x0b5c473dU
+      /* 16 */  , 0x1c26a370U, 0x1de4c947U, 0x1fa2771eU, 0x1e601d29U, 0x1b2f0bacU, 0x1aed619bU, 0x18abdfc2U, 0x1969b5f5U
+      /* 24 */  , 0x1235f2c8U, 0x13f798ffU, 0x11b126a6U, 0x10734c91U, 0x153c5a14U, 0x14fe3023U, 0x16b88e7aU, 0x177ae44dU
+      /* 32 */  , 0x384d46e0U, 0x398f2cd7U, 0x3bc9928eU, 0x3a0bf8b9U, 0x3f44ee3cU, 0x3e86840bU, 0x3cc03a52U, 0x3d025065U
+      /* 40 */  , 0x365e1758U, 0x379c7d6fU, 0x35dac336U, 0x3418a901U, 0x3157bf84U, 0x3095d5b3U, 0x32d36beaU, 0x331101ddU
+      /* 48 */  , 0x246be590U, 0x25a98fa7U, 0x27ef31feU, 0x262d5bc9U, 0x23624d4cU, 0x22a0277bU, 0x20e69922U, 0x2124f315U
+      /* 56 */  , 0x2a78b428U, 0x2bbade1fU, 0x29fc6046U, 0x283e0a71U, 0x2d711cf4U, 0x2cb376c3U, 0x2ef5c89aU, 0x2f37a2adU
+      /* 64 */  , 0x709a8dc0U, 0x7158e7f7U, 0x731e59aeU, 0x72dc3399U, 0x7793251cU, 0x76514f2bU, 0x7417f172U, 0x75d59b45U
+      /* 72 */  , 0x7e89dc78U, 0x7f4bb64fU, 0x7d0d0816U, 0x7ccf6221U, 0x798074a4U, 0x78421e93U, 0x7a04a0caU, 0x7bc6cafdU
+      /* 80 */  , 0x6cbc2eb0U, 0x6d7e4487U, 0x6f38fadeU, 0x6efa90e9U, 0x6bb5866cU, 0x6a77ec5bU, 0x68315202U, 0x69f33835U
+      /* 88 */  , 0x62af7f08U, 0x636d153fU, 0x612bab66U, 0x60e9c151U, 0x65a6d7d4U, 0x6464bde3U, 0x662203baU, 0x67e0698dU
+      /* 96 */  , 0x48d7cb20U, 0x4915a117U, 0x4b531f4eU, 0x4a917579U, 0x4fde63fcU, 0x4e1c09cbU, 0x4c5ab792U, 0x4d98dda5U
+      /* 104 */  , 0x46c49a98U, 0x4706f0afU, 0x45404ef6U, 0x448224c1U, 0x41cd3244U, 0x400f5873U, 0x4249e62aU, 0x438b8c1dU
+      /* 112 */  , 0x54f16850U, 0x55330267U, 0x5775bc3eU, 0x56b7d609U, 0x53f8c08cU, 0x523aaabbU, 0x507c14e2U, 0x51be7ed5U
+      /* 120 */  , 0x5ae239e8U, 0x5b2053dfU, 0x5966ed86U, 0x58a487b1U, 0x5deb9134U, 0x5c29fb03U, 0x5e6f455aU, 0x5fad2f6dU
+      /* 128 */  , 0xe1351b80U, 0xe0f771b7U, 0xe2b1cfeeU, 0xe373a5d9U, 0xe63cb35cU, 0xe7fed96bU, 0xe5b86732U, 0xe47a0d05U
+      /* 136 */  , 0xef264a38U, 0xeee4200fU, 0xeca29e56U, 0xed60f461U, 0xe82fe2e4U, 0xe9ed88d3U, 0xebab368aU, 0xea695cbdU
+      /* 144 */  , 0xfd13b8f0U, 0xfcd1d2c7U, 0xfe976c9eU, 0xff5506a9U, 0xfa1a102cU, 0xfbd87a1bU, 0xf99ec442U, 0xf85cae75U
+      /* 152 */  , 0xf300e948U, 0xf2c2837fU, 0xf0843d26U, 0xf1465711U, 0xf4094194U, 0xf5cb2ba3U, 0xf78d95faU, 0xf64fffcdU
+      /* 160 */  , 0xd9785d60U, 0xd8ba3757U, 0xdafc890eU, 0xdb3ee339U, 0xde71f5bcU, 0xdfb39f8bU, 0xddf521d2U, 0xdc374be5U
+      /* 168 */  , 0xd76b0cd8U, 0xd6a966efU, 0xd4efd8b6U, 0xd52db281U, 0xd062a404U, 0xd1a0ce33U, 0xd3e6706aU, 0xd2241a5dU
+      /* 176 */  , 0xc55efe10U, 0xc49c9427U, 0xc6da2a7eU, 0xc7184049U, 0xc25756ccU, 0xc3953cfbU, 0xc1d382a2U, 0xc011e895U
+      /* 184 */  , 0xcb4dafa8U, 0xca8fc59fU, 0xc8c97bc6U, 0xc90b11f1U, 0xcc440774U, 0xcd866d43U, 0xcfc0d31aU, 0xce02b92dU
+      /* 192 */  , 0x91af9640U, 0x906dfc77U, 0x922b422eU, 0x93e92819U, 0x96a63e9cU, 0x976454abU, 0x9522eaf2U, 0x94e080c5U
+      /* 200 */  , 0x9fbcc7f8U, 0x9e7eadcfU, 0x9c381396U, 0x9dfa79a1U, 0x98b56f24U, 0x99770513U, 0x9b31bb4aU, 0x9af3d17dU
+      /* 208 */  , 0x8d893530U, 0x8c4b5f07U, 0x8e0de15eU, 0x8fcf8b69U, 0x8a809decU, 0x8b42f7dbU, 0x89044982U, 0x88c623b5U
+      /* 216 */  , 0x839a6488U, 0x82580ebfU, 0x801eb0e6U, 0x81dcdad1U, 0x8493cc54U, 0x8551a663U, 0x8717183aU, 0x86d5720dU
+      /* 224 */  , 0xa9e2d0a0U, 0xa820ba97U, 0xaa6604ceU, 0xaba46ef9U, 0xaeeb787cU, 0xaf29124bU, 0xad6fac12U, 0xacadc625U
+      /* 232 */  , 0xa7f18118U, 0xa633eb2fU, 0xa4755576U, 0xa5b73f41U, 0xa0f829c4U, 0xa13a43f3U, 0xa37cfdaaU, 0xa2be979dU
+      /* 240 */  , 0xb5c473d0U, 0xb40619e7U, 0xb640a7beU, 0xb782cd89U, 0xb2cddb0cU, 0xb30fb13bU, 0xb1490f62U, 0xb08b6555U
+      /* 248 */  , 0xbbd72268U, 0xba15485fU, 0xb853f606U, 0xb9919c31U, 0xbcde8ab4U, 0xbd1ce083U, 0xbf5a5edaU, 0xbe9834edU
+    }
+    ,
+    /* CRC32 table 3 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0xb8bc6765U, 0xaa09c88bU, 0x12b5afeeU, 0x8f629757U, 0x37def032U, 0x256b5fdcU, 0x9dd738b9U
+      /* 8 */  , 0xc5b428efU, 0x7d084f8aU, 0x6fbde064U, 0xd7018701U, 0x4ad6bfb8U, 0xf26ad8ddU, 0xe0df7733U, 0x58631056U
+      /* 16 */  , 0x5019579fU, 0xe8a530faU, 0xfa109f14U, 0x42acf871U, 0xdf7bc0c8U, 0x67c7a7adU, 0x75720843U, 0xcdce6f26U
+      /* 24 */  , 0x95ad7f70U, 0x2d111815U, 0x3fa4b7fbU, 0x8718d09eU, 0x1acfe827U, 0xa2738f42U, 0xb0c620acU, 0x087a47c9U
+      /* 32 */  , 0xa032af3eU, 0x188ec85bU, 0x0a3b67b5U, 0xb28700d0U, 0x2f503869U, 0x97ec5f0cU, 0x8559f0e2U, 0x3de59787U
+      /* 40 */  , 0x658687d1U, 0xdd3ae0b4U, 0xcf8f4f5aU, 0x7733283fU, 0xeae41086U, 0x525877e3U, 0x40edd80dU, 0xf851bf68U
+      /* 48 */  , 0xf02bf8a1U, 0x48979fc4U, 0x5a22302aU, 0xe29e574fU, 0x7f496ff6U, 0xc7f50893U, 0xd540a77dU, 0x6dfcc018U
+      /* 56 */  , 0x359fd04eU, 0x8d23b72bU, 0x9f9618c5U, 0x272a7fa0U, 0xbafd4719U, 0x0241207cU, 0x10f48f92U, 0xa848e8f7U
+      /* 64 */  , 0x9b14583dU, 0x23a83f58U, 0x311d90b6U, 0x89a1f7d3U, 0x1476cf6aU, 0xaccaa80fU, 0xbe7f07e1U, 0x06c36084U
+      /* 72 */  , 0x5ea070d2U, 0xe61c17b7U, 0xf4a9b859U, 0x4c15df3cU, 0xd1c2e785U, 0x697e80e0U, 0x7bcb2f0eU, 0xc377486bU
+      /* 80 */  , 0xcb0d0fa2U, 0x73b168c7U, 0x6104c729U, 0xd9b8a04cU, 0x446f98f5U, 0xfcd3ff90U, 0xee66507eU, 0x56da371bU
+      /* 88 */  , 0x0eb9274dU, 0xb6054028U, 0xa4b0efc6U, 0x1c0c88a3U, 0x81dbb01aU, 0x3967d77fU, 0x2bd27891U, 0x936e1ff4U
+      /* 96 */  , 0x3b26f703U, 0x839a9066U, 0x912f3f88U, 0x299358edU, 0xb4446054U, 0x0cf80731U, 0x1e4da8dfU, 0xa6f1cfbaU
+      /* 104 */  , 0xfe92dfecU, 0x462eb889U, 0x549b1767U, 0xec277002U, 0x71f048bbU, 0xc94c2fdeU, 0xdbf98030U, 0x6345e755U
+      /* 112 */  , 0x6b3fa09cU, 0xd383c7f9U, 0xc1366817U, 0x798a0f72U, 0xe45d37cbU, 0x5ce150aeU, 0x4e54ff40U, 0xf6e89825U
+      /* 120 */  , 0xae8b8873U, 0x1637ef16U, 0x048240f8U, 0xbc3e279dU, 0x21e91f24U, 0x99557841U, 0x8be0d7afU, 0x335cb0caU
+      /* 128 */  , 0xed59b63bU, 0x55e5d15eU, 0x47507eb0U, 0xffec19d5U, 0x623b216cU, 0xda874609U, 0xc832e9e7U, 0x708e8e82U
+      /* 136 */  , 0x28ed9ed4U, 0x9051f9b1U, 0x82e4565fU, 0x3a58313aU, 0xa78f0983U, 0x1f336ee6U, 0x0d86c108U, 0xb53aa66dU
+      /* 144 */  , 0xbd40e1a4U, 0x05fc86c1U, 0x1749292fU, 0xaff54e4aU, 0x322276f3U, 0x8a9e1196U, 0x982bbe78U, 0x2097d91dU
+      /* 152 */  , 0x78f4c94bU, 0xc048ae2eU, 0xd2fd01c0U, 0x6a4166a5U, 0xf7965e1cU, 0x4f2a3979U, 0x5d9f9697U, 0xe523f1f2U
+      /* 160 */  , 0x4d6b1905U, 0xf5d77e60U, 0xe762d18eU, 0x5fdeb6ebU, 0xc2098e52U, 0x7ab5e937U, 0x680046d9U, 0xd0bc21bcU
+      /* 168 */  , 0x88df31eaU, 0x3063568fU, 0x22d6f961U, 0x9a6a9e04U, 0x07bda6bdU, 0xbf01c1d8U, 0xadb46e36U, 0x15080953U
+      /* 176 */  , 0x1d724e9aU, 0xa5ce29ffU, 0xb77b8611U, 0x0fc7e174U, 0x9210d9cdU, 0x2aacbea8U, 0x38191146U, 0x80a57623U
+      /* 184 */  , 0xd8c66675U, 0x607a0110U, 0x72cfaefeU, 0xca73c99bU, 0x57a4f122U, 0xef189647U, 0xfdad39a9U, 0x45115eccU
+      /* 192 */  , 0x764dee06U, 0xcef18963U, 0xdc44268dU, 0x64f841e8U, 0xf92f7951U, 0x41931e34U, 0x5326b1daU, 0xeb9ad6bfU
+      /* 200 */  , 0xb3f9c6e9U, 0x0b45a18cU, 0x19f00e62U, 0xa14c6907U, 0x3c9b51beU, 0x842736dbU, 0x96929935U, 0x2e2efe50U
+      /* 208 */  , 0x2654b999U, 0x9ee8defcU, 0x8c5d7112U, 0x34e11677U, 0xa9362eceU, 0x118a49abU, 0x033fe645U, 0xbb838120U
+      /* 216 */  , 0xe3e09176U, 0x5b5cf613U, 0x49e959fdU, 0xf1553e98U, 0x6c820621U, 0xd43e6144U, 0xc68bceaaU, 0x7e37a9cfU
+      /* 224 */  , 0xd67f4138U, 0x6ec3265dU, 0x7c7689b3U, 0xc4caeed6U, 0x591dd66fU, 0xe1a1b10aU, 0xf3141ee4U, 0x4ba87981U
+      /* 232 */  , 0x13cb69d7U, 0xab770eb2U, 0xb9c2a15cU, 0x017ec639U, 0x9ca9fe80U, 0x241599e5U, 0x36a0360bU, 0x8e1c516eU
+      /* 240 */  , 0x866616a7U, 0x3eda71c2U, 0x2c6fde2cU, 0x94d3b949U, 0x090481f0U, 0xb1b8e695U, 0xa30d497bU, 0x1bb12e1eU
+      /* 248 */  , 0x43d23e48U, 0xfb6e592dU, 0xe9dbf6c3U, 0x516791a6U, 0xccb0a91fU, 0x740cce7aU, 0x66b96194U, 0xde0506f1U
+    }
+    ,
+    /* CRC32 table 4 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x96300777U, 0x2c610eeeU, 0xba510999U, 0x19c46d07U, 0x8ff46a70U, 0x35a563e9U, 0xa395649eU
+      /* 8 */  , 0x3288db0eU, 0xa4b8dc79U, 0x1ee9d5e0U, 0x88d9d297U, 0x2b4cb609U, 0xbd7cb17eU, 0x072db8e7U, 0x911dbf90U
+      /* 16 */  , 0x6410b71dU, 0xf220b06aU, 0x4871b9f3U, 0xde41be84U, 0x7dd4da1aU, 0xebe4dd6dU, 0x51b5d4f4U, 0xc785d383U
+      /* 24 */  , 0x56986c13U, 0xc0a86b64U, 0x7af962fdU, 0xecc9658aU, 0x4f5c0114U, 0xd96c0663U, 0x633d0ffaU, 0xf50d088dU
+      /* 32 */  , 0xc8206e3bU, 0x5e10694cU, 0xe44160d5U, 0x727167a2U, 0xd1e4033cU, 0x47d4044bU, 0xfd850dd2U, 0x6bb50aa5U
+      /* 40 */  , 0xfaa8b535U, 0x6c98b242U, 0xd6c9bbdbU, 0x40f9bcacU, 0xe36cd832U, 0x755cdf45U, 0xcf0dd6dcU, 0x593dd1abU
+      /* 48 */  , 0xac30d926U, 0x3a00de51U, 0x8051d7c8U, 0x1661d0bfU, 0xb5f4b421U, 0x23c4b356U, 0x9995bacfU, 0x0fa5bdb8U
+      /* 56 */  , 0x9eb80228U, 0x0888055fU, 0xb2d90cc6U, 0x24e90bb1U, 0x877c6f2fU, 0x114c6858U, 0xab1d61c1U, 0x3d2d66b6U
+      /* 64 */  , 0x9041dc76U, 0x0671db01U, 0xbc20d298U, 0x2a10d5efU, 0x8985b171U, 0x1fb5b606U, 0xa5e4bf9fU, 0x33d4b8e8U
+      /* 72 */  , 0xa2c90778U, 0x34f9000fU, 0x8ea80996U, 0x18980ee1U, 0xbb0d6a7fU, 0x2d3d6d08U, 0x976c6491U, 0x015c63e6U
+      /* 80 */  , 0xf4516b6bU, 0x62616c1cU, 0xd8306585U, 0x4e0062f2U, 0xed95066cU, 0x7ba5011bU, 0xc1f40882U, 0x57c40ff5U
+      /* 88 */  , 0xc6d9b065U, 0x50e9b712U, 0xeab8be8bU, 0x7c88b9fcU, 0xdf1ddd62U, 0x492dda15U, 0xf37cd38cU, 0x654cd4fbU
+      /* 96 */  , 0x5861b24dU, 0xce51b53aU, 0x7400bca3U, 0xe230bbd4U, 0x41a5df4aU, 0xd795d83dU, 0x6dc4d1a4U, 0xfbf4d6d3U
+      /* 104 */  , 0x6ae96943U, 0xfcd96e34U, 0x468867adU, 0xd0b860daU, 0x732d0444U, 0xe51d0333U, 0x5f4c0aaaU, 0xc97c0dddU
+      /* 112 */  , 0x3c710550U, 0xaa410227U, 0x10100bbeU, 0x86200cc9U, 0x25b56857U, 0xb3856f20U, 0x09d466b9U, 0x9fe461ceU
+      /* 120 */  , 0x0ef9de5eU, 0x98c9d929U, 0x2298d0b0U, 0xb4a8d7c7U, 0x173db359U, 0x810db42eU, 0x3b5cbdb7U, 0xad6cbac0U
+      /* 128 */  , 0x2083b8edU, 0xb6b3bf9aU, 0x0ce2b603U, 0x9ad2b174U, 0x3947d5eaU, 0xaf77d29dU, 0x1526db04U, 0x8316dc73U
+      /* 136 */  , 0x120b63e3U, 0x843b6494U, 0x3e6a6d0dU, 0xa85a6a7aU, 0x0bcf0ee4U, 0x9dff0993U, 0x27ae000aU, 0xb19e077dU
+      /* 144 */  , 0x44930ff0U, 0xd2a30887U, 0x68f2011eU, 0xfec20669U, 0x5d5762f7U, 0xcb676580U, 0x71366c19U, 0xe7066b6eU
+      /* 152 */  , 0x761bd4feU, 0xe02bd389U, 0x5a7ada10U, 0xcc4add67U, 0x6fdfb9f9U, 0xf9efbe8eU, 0x43beb717U, 0xd58eb060U
+      /* 160 */  , 0xe8a3d6d6U, 0x7e93d1a1U, 0xc4c2d838U, 0x52f2df4fU, 0xf167bbd1U, 0x6757bca6U, 0xdd06b53fU, 0x4b36b248U
+      /* 168 */  , 0xda2b0dd8U, 0x4c1b0aafU, 0xf64a0336U, 0x607a0441U, 0xc3ef60dfU, 0x55df67a8U, 0xef8e6e31U, 0x79be6946U
+      /* 176 */  , 0x8cb361cbU, 0x1a8366bcU, 0xa0d26f25U, 0x36e26852U, 0x95770cccU, 0x03470bbbU, 0xb9160222U, 0x2f260555U
+      /* 184 */  , 0xbe3bbac5U, 0x280bbdb2U, 0x925ab42bU, 0x046ab35cU, 0xa7ffd7c2U, 0x31cfd0b5U, 0x8b9ed92cU, 0x1daede5bU
+      /* 192 */  , 0xb0c2649bU, 0x26f263ecU, 0x9ca36a75U, 0x0a936d02U, 0xa906099cU, 0x3f360eebU, 0x85670772U, 0x13570005U
+      /* 200 */  , 0x824abf95U, 0x147ab8e2U, 0xae2bb17bU, 0x381bb60cU, 0x9b8ed292U, 0x0dbed5e5U, 0xb7efdc7cU, 0x21dfdb0bU
+      /* 208 */  , 0xd4d2d386U, 0x42e2d4f1U, 0xf8b3dd68U, 0x6e83da1fU, 0xcd16be81U, 0x5b26b9f6U, 0xe177b06fU, 0x7747b718U
+      /* 216 */  , 0xe65a0888U, 0x706a0fffU, 0xca3b0666U, 0x5c0b0111U, 0xff9e658fU, 0x69ae62f8U, 0xd3ff6b61U, 0x45cf6c16U
+      /* 224 */  , 0x78e20aa0U, 0xeed20dd7U, 0x5483044eU, 0xc2b30339U, 0x612667a7U, 0xf71660d0U, 0x4d476949U, 0xdb776e3eU
+      /* 232 */  , 0x4a6ad1aeU, 0xdc5ad6d9U, 0x660bdf40U, 0xf03bd837U, 0x53aebca9U, 0xc59ebbdeU, 0x7fcfb247U, 0xe9ffb530U
+      /* 240 */  , 0x1cf2bdbdU, 0x8ac2bacaU, 0x3093b353U, 0xa6a3b424U, 0x0536d0baU, 0x9306d7cdU, 0x2957de54U, 0xbf67d923U
+      /* 248 */  , 0x2e7a66b3U, 0xb84a61c4U, 0x021b685dU, 0x942b6f2aU, 0x37be0bb4U, 0xa18e0cc3U, 0x1bdf055aU, 0x8def022dU
+    }
+    ,
+    /* CRC32 table 5 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x41311b19U, 0x82623632U, 0xc3532d2bU, 0x04c56c64U, 0x45f4777dU, 0x86a75a56U, 0xc796414fU
+      /* 8 */  , 0x088ad9c8U, 0x49bbc2d1U, 0x8ae8effaU, 0xcbd9f4e3U, 0x0c4fb5acU, 0x4d7eaeb5U, 0x8e2d839eU, 0xcf1c9887U
+      /* 16 */  , 0x5112c24aU, 0x1023d953U, 0xd370f478U, 0x9241ef61U, 0x55d7ae2eU, 0x14e6b537U, 0xd7b5981cU, 0x96848305U
+      /* 24 */  , 0x59981b82U, 0x18a9009bU, 0xdbfa2db0U, 0x9acb36a9U, 0x5d5d77e6U, 0x1c6c6cffU, 0xdf3f41d4U, 0x9e0e5acdU
+      /* 32 */  , 0xa2248495U, 0xe3159f8cU, 0x2046b2a7U, 0x6177a9beU, 0xa6e1e8f1U, 0xe7d0f3e8U, 0x2483dec3U, 0x65b2c5daU
+      /* 40 */  , 0xaaae5d5dU, 0xeb9f4644U, 0x28cc6b6fU, 0x69fd7076U, 0xae6b3139U, 0xef5a2a20U, 0x2c09070bU, 0x6d381c12U
+      /* 48 */  , 0xf33646dfU, 0xb2075dc6U, 0x715470edU, 0x30656bf4U, 0xf7f32abbU, 0xb6c231a2U, 0x75911c89U, 0x34a00790U
+      /* 56 */  , 0xfbbc9f17U, 0xba8d840eU, 0x79dea925U, 0x38efb23cU, 0xff79f373U, 0xbe48e86aU, 0x7d1bc541U, 0x3c2ade58U
+      /* 64 */  , 0x054f79f0U, 0x447e62e9U, 0x872d4fc2U, 0xc61c54dbU, 0x018a1594U, 0x40bb0e8dU, 0x83e823a6U, 0xc2d938bfU
+      /* 72 */  , 0x0dc5a038U, 0x4cf4bb21U, 0x8fa7960aU, 0xce968d13U, 0x0900cc5cU, 0x4831d745U, 0x8b62fa6eU, 0xca53e177U
+      /* 80 */  , 0x545dbbbaU, 0x156ca0a3U, 0xd63f8d88U, 0x970e9691U, 0x5098d7deU, 0x11a9ccc7U, 0xd2fae1ecU, 0x93cbfaf5U
+      /* 88 */  , 0x5cd76272U, 0x1de6796bU, 0xdeb55440U, 0x9f844f59U, 0x58120e16U, 0x1923150fU, 0xda703824U, 0x9b41233dU
+      /* 96 */  , 0xa76bfd65U, 0xe65ae67cU, 0x2509cb57U, 0x6438d04eU, 0xa3ae9101U, 0xe29f8a18U, 0x21cca733U, 0x60fdbc2aU
+      /* 104 */  , 0xafe124adU, 0xeed03fb4U, 0x2d83129fU, 0x6cb20986U, 0xab2448c9U, 0xea1553d0U, 0x29467efbU, 0x687765e2U
+      /* 112 */  , 0xf6793f2fU, 0xb7482436U, 0x741b091dU, 0x352a1204U, 0xf2bc534bU, 0xb38d4852U, 0x70de6579U, 0x31ef7e60U
+      /* 120 */  , 0xfef3e6e7U, 0xbfc2fdfeU, 0x7c91d0d5U, 0x3da0cbccU, 0xfa368a83U, 0xbb07919aU, 0x7854bcb1U, 0x3965a7a8U
+      /* 128 */  , 0x4b98833bU, 0x0aa99822U, 0xc9fab509U, 0x88cbae10U, 0x4f5def5fU, 0x0e6cf446U, 0xcd3fd96dU, 0x8c0ec274U
+      /* 136 */  , 0x43125af3U, 0x022341eaU, 0xc1706cc1U, 0x804177d8U, 0x47d73697U, 0x06e62d8eU, 0xc5b500a5U, 0x84841bbcU
+      /* 144 */  , 0x1a8a4171U, 0x5bbb5a68U, 0x98e87743U, 0xd9d96c5aU, 0x1e4f2d15U, 0x5f7e360cU, 0x9c2d1b27U, 0xdd1c003eU
+      /* 152 */  , 0x120098b9U, 0x533183a0U, 0x9062ae8bU, 0xd153b592U, 0x16c5f4ddU, 0x57f4efc4U, 0x94a7c2efU, 0xd596d9f6U
+      /* 160 */  , 0xe9bc07aeU, 0xa88d1cb7U, 0x6bde319cU, 0x2aef2a85U, 0xed796bcaU, 0xac4870d3U, 0x6f1b5df8U, 0x2e2a46e1U
+      /* 168 */  , 0xe136de66U, 0xa007c57fU, 0x6354e854U, 0x2265f34dU, 0xe5f3b202U, 0xa4c2a91bU, 0x67918430U, 0x26a09f29U
+      /* 176 */  , 0xb8aec5e4U, 0xf99fdefdU, 0x3accf3d6U, 0x7bfde8cfU, 0xbc6ba980U, 0xfd5ab299U, 0x3e099fb2U, 0x7f3884abU
+      /* 184 */  , 0xb0241c2cU, 0xf1150735U, 0x32462a1eU, 0x73773107U, 0xb4e17048U, 0xf5d06b51U, 0x3683467aU, 0x77b25d63U
+      /* 192 */  , 0x4ed7facbU, 0x0fe6e1d2U, 0xccb5ccf9U, 0x8d84d7e0U, 0x4a1296afU, 0x0b238db6U, 0xc870a09dU, 0x8941bb84U
+      /* 200 */  , 0x465d2303U, 0x076c381aU, 0xc43f1531U, 0x850e0e28U, 0x42984f67U, 0x03a9547eU, 0xc0fa7955U, 0x81cb624cU
+      /* 208 */  , 0x1fc53881U, 0x5ef42398U, 0x9da70eb3U, 0xdc9615aaU, 0x1b0054e5U, 0x5a314ffcU, 0x996262d7U, 0xd85379ceU
+      /* 216 */  , 0x174fe149U, 0x567efa50U, 0x952dd77bU, 0xd41ccc62U, 0x138a8d2dU, 0x52bb9634U, 0x91e8bb1fU, 0xd0d9a006U
+      /* 224 */  , 0xecf37e5eU, 0xadc26547U, 0x6e91486cU, 0x2fa05375U, 0xe836123aU, 0xa9070923U, 0x6a542408U, 0x2b653f11U
+      /* 232 */  , 0xe479a796U, 0xa548bc8fU, 0x661b91a4U, 0x272a8abdU, 0xe0bccbf2U, 0xa18dd0ebU, 0x62defdc0U, 0x23efe6d9U
+      /* 240 */  , 0xbde1bc14U, 0xfcd0a70dU, 0x3f838a26U, 0x7eb2913fU, 0xb924d070U, 0xf815cb69U, 0x3b46e642U, 0x7a77fd5bU
+      /* 248 */  , 0xb56b65dcU, 0xf45a7ec5U, 0x370953eeU, 0x763848f7U, 0xb1ae09b8U, 0xf09f12a1U, 0x33cc3f8aU, 0x72fd2493U
+    }
+    ,
+    /* CRC32 table 6 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x376ac201U, 0x6ed48403U, 0x59be4602U, 0xdca80907U, 0xebc2cb06U, 0xb27c8d04U, 0x85164f05U
+      /* 8 */  , 0xb851130eU, 0x8f3bd10fU, 0xd685970dU, 0xe1ef550cU, 0x64f91a09U, 0x5393d808U, 0x0a2d9e0aU, 0x3d475c0bU
+      /* 16 */  , 0x70a3261cU, 0x47c9e41dU, 0x1e77a21fU, 0x291d601eU, 0xac0b2f1bU, 0x9b61ed1aU, 0xc2dfab18U, 0xf5b56919U
+      /* 24 */  , 0xc8f23512U, 0xff98f713U, 0xa626b111U, 0x914c7310U, 0x145a3c15U, 0x2330fe14U, 0x7a8eb816U, 0x4de47a17U
+      /* 32 */  , 0xe0464d38U, 0xd72c8f39U, 0x8e92c93bU, 0xb9f80b3aU, 0x3cee443fU, 0x0b84863eU, 0x523ac03cU, 0x6550023dU
+      /* 40 */  , 0x58175e36U, 0x6f7d9c37U, 0x36c3da35U, 0x01a91834U, 0x84bf5731U, 0xb3d59530U, 0xea6bd332U, 0xdd011133U
+      /* 48 */  , 0x90e56b24U, 0xa78fa925U, 0xfe31ef27U, 0xc95b2d26U, 0x4c4d6223U, 0x7b27a022U, 0x2299e620U, 0x15f32421U
+      /* 56 */  , 0x28b4782aU, 0x1fdeba2bU, 0x4660fc29U, 0x710a3e28U, 0xf41c712dU, 0xc376b32cU, 0x9ac8f52eU, 0xada2372fU
+      /* 64 */  , 0xc08d9a70U, 0xf7e75871U, 0xae591e73U, 0x9933dc72U, 0x1c259377U, 0x2b4f5176U, 0x72f11774U, 0x459bd575U
+      /* 72 */  , 0x78dc897eU, 0x4fb64b7fU, 0x16080d7dU, 0x2162cf7cU, 0xa4748079U, 0x931e4278U, 0xcaa0047aU, 0xfdcac67bU
+      /* 80 */  , 0xb02ebc6cU, 0x87447e6dU, 0xdefa386fU, 0xe990fa6eU, 0x6c86b56bU, 0x5bec776aU, 0x02523168U, 0x3538f369U
+      /* 88 */  , 0x087faf62U, 0x3f156d63U, 0x66ab2b61U, 0x51c1e960U, 0xd4d7a665U, 0xe3bd6464U, 0xba032266U, 0x8d69e067U
+      /* 96 */  , 0x20cbd748U, 0x17a11549U, 0x4e1f534bU, 0x7975914aU, 0xfc63de4fU, 0xcb091c4eU, 0x92b75a4cU, 0xa5dd984dU
+      /* 104 */  , 0x989ac446U, 0xaff00647U, 0xf64e4045U, 0xc1248244U, 0x4432cd41U, 0x73580f40U, 0x2ae64942U, 0x1d8c8b43U
+      /* 112 */  , 0x5068f154U, 0x67023355U, 0x3ebc7557U, 0x09d6b756U, 0x8cc0f853U, 0xbbaa3a52U, 0xe2147c50U, 0xd57ebe51U
+      /* 120 */  , 0xe839e25aU, 0xdf53205bU, 0x86ed6659U, 0xb187a458U, 0x3491eb5dU, 0x03fb295cU, 0x5a456f5eU, 0x6d2fad5fU
+      /* 128 */  , 0x801b35e1U, 0xb771f7e0U, 0xeecfb1e2U, 0xd9a573e3U, 0x5cb33ce6U, 0x6bd9fee7U, 0x3267b8e5U, 0x050d7ae4U
+      /* 136 */  , 0x384a26efU, 0x0f20e4eeU, 0x569ea2ecU, 0x61f460edU, 0xe4e22fe8U, 0xd388ede9U, 0x8a36abebU, 0xbd5c69eaU
+      /* 144 */  , 0xf0b813fdU, 0xc7d2d1fcU, 0x9e6c97feU, 0xa90655ffU, 0x2c101afaU, 0x1b7ad8fbU, 0x42c49ef9U, 0x75ae5cf8U
+      /* 152 */  , 0x48e900f3U, 0x7f83c2f2U, 0x263d84f0U, 0x115746f1U, 0x944109f4U, 0xa32bcbf5U, 0xfa958df7U, 0xcdff4ff6U
+      /* 160 */  , 0x605d78d9U, 0x5737bad8U, 0x0e89fcdaU, 0x39e33edbU, 0xbcf571deU, 0x8b9fb3dfU, 0xd221f5ddU, 0xe54b37dcU
+      /* 168 */  , 0xd80c6bd7U, 0xef66a9d6U, 0xb6d8efd4U, 0x81b22dd5U, 0x04a462d0U, 0x33cea0d1U, 0x6a70e6d3U, 0x5d1a24d2U
+      /* 176 */  , 0x10fe5ec5U, 0x27949cc4U, 0x7e2adac6U, 0x494018c7U, 0xcc5657c2U, 0xfb3c95c3U, 0xa282d3c1U, 0x95e811c0U
+      /* 184 */  , 0xa8af4dcbU, 0x9fc58fcaU, 0xc67bc9c8U, 0xf1110bc9U, 0x740744ccU, 0x436d86cdU, 0x1ad3c0cfU, 0x2db902ceU
+      /* 192 */  , 0x4096af91U, 0x77fc6d90U, 0x2e422b92U, 0x1928e993U, 0x9c3ea696U, 0xab546497U, 0xf2ea2295U, 0xc580e094U
+      /* 200 */  , 0xf8c7bc9fU, 0xcfad7e9eU, 0x9613389cU, 0xa179fa9dU, 0x246fb598U, 0x13057799U, 0x4abb319bU, 0x7dd1f39aU
+      /* 208 */  , 0x3035898dU, 0x075f4b8cU, 0x5ee10d8eU, 0x698bcf8fU, 0xec9d808aU, 0xdbf7428bU, 0x82490489U, 0xb523c688U
+      /* 216 */  , 0x88649a83U, 0xbf0e5882U, 0xe6b01e80U, 0xd1dadc81U, 0x54cc9384U, 0x63a65185U, 0x3a181787U, 0x0d72d586U
+      /* 224 */  , 0xa0d0e2a9U, 0x97ba20a8U, 0xce0466aaU, 0xf96ea4abU, 0x7c78ebaeU, 0x4b1229afU, 0x12ac6fadU, 0x25c6adacU
+      /* 232 */  , 0x1881f1a7U, 0x2feb33a6U, 0x765575a4U, 0x413fb7a5U, 0xc429f8a0U, 0xf3433aa1U, 0xaafd7ca3U, 0x9d97bea2U
+      /* 240 */  , 0xd073c4b5U, 0xe71906b4U, 0xbea740b6U, 0x89cd82b7U, 0x0cdbcdb2U, 0x3bb10fb3U, 0x620f49b1U, 0x55658bb0U
+      /* 248 */  , 0x6822d7bbU, 0x5f4815baU, 0x06f653b8U, 0x319c91b9U, 0xb48adebcU, 0x83e01cbdU, 0xda5e5abfU, 0xed3498beU
+    }
+    ,
+    /* CRC32 table 7 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x6567bcb8U, 0x8bc809aaU, 0xeeafb512U, 0x5797628fU, 0x32f0de37U, 0xdc5f6b25U, 0xb938d79dU
+      /* 8 */  , 0xef28b4c5U, 0x8a4f087dU, 0x64e0bd6fU, 0x018701d7U, 0xb8bfd64aU, 0xddd86af2U, 0x3377dfe0U, 0x56106358U
+      /* 16 */  , 0x9f571950U, 0xfa30a5e8U, 0x149f10faU, 0x71f8ac42U, 0xc8c07bdfU, 0xada7c767U, 0x43087275U, 0x266fcecdU
+      /* 24 */  , 0x707fad95U, 0x1518112dU, 0xfbb7a43fU, 0x9ed01887U, 0x27e8cf1aU, 0x428f73a2U, 0xac20c6b0U, 0xc9477a08U
+      /* 32 */  , 0x3eaf32a0U, 0x5bc88e18U, 0xb5673b0aU, 0xd00087b2U, 0x6938502fU, 0x0c5fec97U, 0xe2f05985U, 0x8797e53dU
+      /* 40 */  , 0xd1878665U, 0xb4e03addU, 0x5a4f8fcfU, 0x3f283377U, 0x8610e4eaU, 0xe3775852U, 0x0dd8ed40U, 0x68bf51f8U
+      /* 48 */  , 0xa1f82bf0U, 0xc49f9748U, 0x2a30225aU, 0x4f579ee2U, 0xf66f497fU, 0x9308f5c7U, 0x7da740d5U, 0x18c0fc6dU
+      /* 56 */  , 0x4ed09f35U, 0x2bb7238dU, 0xc518969fU, 0xa07f2a27U, 0x1947fdbaU, 0x7c204102U, 0x928ff410U, 0xf7e848a8U
+      /* 64 */  , 0x3d58149bU, 0x583fa823U, 0xb6901d31U, 0xd3f7a189U, 0x6acf7614U, 0x0fa8caacU, 0xe1077fbeU, 0x8460c306U
+      /* 72 */  , 0xd270a05eU, 0xb7171ce6U, 0x59b8a9f4U, 0x3cdf154cU, 0x85e7c2d1U, 0xe0807e69U, 0x0e2fcb7bU, 0x6b4877c3U
+      /* 80 */  , 0xa20f0dcbU, 0xc768b173U, 0x29c70461U, 0x4ca0b8d9U, 0xf5986f44U, 0x90ffd3fcU, 0x7e5066eeU, 0x1b37da56U
+      /* 88 */  , 0x4d27b90eU, 0x284005b6U, 0xc6efb0a4U, 0xa3880c1cU, 0x1ab0db81U, 0x7fd76739U, 0x9178d22bU, 0xf41f6e93U
+      /* 96 */  , 0x03f7263bU, 0x66909a83U, 0x883f2f91U, 0xed589329U, 0x546044b4U, 0x3107f80cU, 0xdfa84d1eU, 0xbacff1a6U
+      /* 104 */  , 0xecdf92feU, 0x89b82e46U, 0x67179b54U, 0x027027ecU, 0xbb48f071U, 0xde2f4cc9U, 0x3080f9dbU, 0x55e74563U
+      /* 112 */  , 0x9ca03f6bU, 0xf9c783d3U, 0x176836c1U, 0x720f8a79U, 0xcb375de4U, 0xae50e15cU, 0x40ff544eU, 0x2598e8f6U
+      /* 120 */  , 0x73888baeU, 0x16ef3716U, 0xf8408204U, 0x9d273ebcU, 0x241fe921U, 0x41785599U, 0xafd7e08bU, 0xcab05c33U
+      /* 128 */  , 0x3bb659edU, 0x5ed1e555U, 0xb07e5047U, 0xd519ecffU, 0x6c213b62U, 0x094687daU, 0xe7e932c8U, 0x828e8e70U
+      /* 136 */  , 0xd49eed28U, 0xb1f95190U, 0x5f56e482U, 0x3a31583aU, 0x83098fa7U, 0xe66e331fU, 0x08c1860dU, 0x6da63ab5U
+      /* 144 */  , 0xa4e140bdU, 0xc186fc05U, 0x2f294917U, 0x4a4ef5afU, 0xf3762232U, 0x96119e8aU, 0x78be2b98U, 0x1dd99720U
+      /* 152 */  , 0x4bc9f478U, 0x2eae48c0U, 0xc001fdd2U, 0xa566416aU, 0x1c5e96f7U, 0x79392a4fU, 0x97969f5dU, 0xf2f123e5U
+      /* 160 */  , 0x05196b4dU, 0x607ed7f5U, 0x8ed162e7U, 0xebb6de5fU, 0x528e09c2U, 0x37e9b57aU, 0xd9460068U, 0xbc21bcd0U
+      /* 168 */  , 0xea31df88U, 0x8f566330U, 0x61f9d622U, 0x049e6a9aU, 0xbda6bd07U, 0xd8c101bfU, 0x366eb4adU, 0x53090815U
+      /* 176 */  , 0x9a4e721dU, 0xff29cea5U, 0x11867bb7U, 0x74e1c70fU, 0xcdd91092U, 0xa8beac2aU, 0x46111938U, 0x2376a580U
+      /* 184 */  , 0x7566c6d8U, 0x10017a60U, 0xfeaecf72U, 0x9bc973caU, 0x22f1a457U, 0x479618efU, 0xa939adfdU, 0xcc5e1145U
+      /* 192 */  , 0x06ee4d76U, 0x6389f1ceU, 0x8d2644dcU, 0xe841f864U, 0x51792ff9U, 0x341e9341U, 0xdab12653U, 0xbfd69aebU
+      /* 200 */  , 0xe9c6f9b3U, 0x8ca1450bU, 0x620ef019U, 0x07694ca1U, 0xbe519b3cU, 0xdb362784U, 0x35999296U, 0x50fe2e2eU
+      /* 208 */  , 0x99b95426U, 0xfcdee89eU, 0x12715d8cU, 0x7716e134U, 0xce2e36a9U, 0xab498a11U, 0x45e63f03U, 0x208183bbU
+      /* 216 */  , 0x7691e0e3U, 0x13f65c5bU, 0xfd59e949U, 0x983e55f1U, 0x2106826cU, 0x44613ed4U, 0xaace8bc6U, 0xcfa9377eU
+      /* 224 */  , 0x38417fd6U, 0x5d26c36eU, 0xb389767cU, 0xd6eecac4U, 0x6fd61d59U, 0x0ab1a1e1U, 0xe41e14f3U, 0x8179a84bU
+      /* 232 */  , 0xd769cb13U, 0xb20e77abU, 0x5ca1c2b9U, 0x39c67e01U, 0x80fea99cU, 0xe5991524U, 0x0b36a036U, 0x6e511c8eU
+      /* 240 */  , 0xa7166686U, 0xc271da3eU, 0x2cde6f2cU, 0x49b9d394U, 0xf0810409U, 0x95e6b8b1U, 0x7b490da3U, 0x1e2eb11bU
+      /* 248 */  , 0x483ed243U, 0x2d596efbU, 0xc3f6dbe9U, 0xa6916751U, 0x1fa9b0ccU, 0x7ace0c74U, 0x9461b966U, 0xf10605deU
+    }
+  #endif
+  };
+
+juint StubRoutines::ppc64::_crc32c_table[CRC32_TABLES][CRC32_COLUMN_SIZE] = {
+    /* polyBits = 4394350321 0x0000000105ec76f1L, shifted = 0x82f63b78 */
+    /* CRC32C table for single bytes, auto-generated.  DO NOT MODIFY!  */
+    /* CRC32C table 0 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0xf26b8303U, 0xe13b70f7U, 0x1350f3f4U, 0xc79a971fU, 0x35f1141cU, 0x26a1e7e8U, 0xd4ca64ebU
+      /* 8 */  , 0x8ad958cfU, 0x78b2dbccU, 0x6be22838U, 0x9989ab3bU, 0x4d43cfd0U, 0xbf284cd3U, 0xac78bf27U, 0x5e133c24U
+      /* 16 */  , 0x105ec76fU, 0xe235446cU, 0xf165b798U, 0x030e349bU, 0xd7c45070U, 0x25afd373U, 0x36ff2087U, 0xc494a384U
+      /* 24 */  , 0x9a879fa0U, 0x68ec1ca3U, 0x7bbcef57U, 0x89d76c54U, 0x5d1d08bfU, 0xaf768bbcU, 0xbc267848U, 0x4e4dfb4bU
+      /* 32 */  , 0x20bd8edeU, 0xd2d60dddU, 0xc186fe29U, 0x33ed7d2aU, 0xe72719c1U, 0x154c9ac2U, 0x061c6936U, 0xf477ea35U
+      /* 40 */  , 0xaa64d611U, 0x580f5512U, 0x4b5fa6e6U, 0xb93425e5U, 0x6dfe410eU, 0x9f95c20dU, 0x8cc531f9U, 0x7eaeb2faU
+      /* 48 */  , 0x30e349b1U, 0xc288cab2U, 0xd1d83946U, 0x23b3ba45U, 0xf779deaeU, 0x05125dadU, 0x1642ae59U, 0xe4292d5aU
+      /* 56 */  , 0xba3a117eU, 0x4851927dU, 0x5b016189U, 0xa96ae28aU, 0x7da08661U, 0x8fcb0562U, 0x9c9bf696U, 0x6ef07595U
+      /* 64 */  , 0x417b1dbcU, 0xb3109ebfU, 0xa0406d4bU, 0x522bee48U, 0x86e18aa3U, 0x748a09a0U, 0x67dafa54U, 0x95b17957U
+      /* 72 */  , 0xcba24573U, 0x39c9c670U, 0x2a993584U, 0xd8f2b687U, 0x0c38d26cU, 0xfe53516fU, 0xed03a29bU, 0x1f682198U
+      /* 80 */  , 0x5125dad3U, 0xa34e59d0U, 0xb01eaa24U, 0x42752927U, 0x96bf4dccU, 0x64d4cecfU, 0x77843d3bU, 0x85efbe38U
+      /* 88 */  , 0xdbfc821cU, 0x2997011fU, 0x3ac7f2ebU, 0xc8ac71e8U, 0x1c661503U, 0xee0d9600U, 0xfd5d65f4U, 0x0f36e6f7U
+      /* 96 */  , 0x61c69362U, 0x93ad1061U, 0x80fde395U, 0x72966096U, 0xa65c047dU, 0x5437877eU, 0x4767748aU, 0xb50cf789U
+      /* 104 */  , 0xeb1fcbadU, 0x197448aeU, 0x0a24bb5aU, 0xf84f3859U, 0x2c855cb2U, 0xdeeedfb1U, 0xcdbe2c45U, 0x3fd5af46U
+      /* 112 */  , 0x7198540dU, 0x83f3d70eU, 0x90a324faU, 0x62c8a7f9U, 0xb602c312U, 0x44694011U, 0x5739b3e5U, 0xa55230e6U
+      /* 120 */  , 0xfb410cc2U, 0x092a8fc1U, 0x1a7a7c35U, 0xe811ff36U, 0x3cdb9bddU, 0xceb018deU, 0xdde0eb2aU, 0x2f8b6829U
+      /* 128 */  , 0x82f63b78U, 0x709db87bU, 0x63cd4b8fU, 0x91a6c88cU, 0x456cac67U, 0xb7072f64U, 0xa457dc90U, 0x563c5f93U
+      /* 136 */  , 0x082f63b7U, 0xfa44e0b4U, 0xe9141340U, 0x1b7f9043U, 0xcfb5f4a8U, 0x3dde77abU, 0x2e8e845fU, 0xdce5075cU
+      /* 144 */  , 0x92a8fc17U, 0x60c37f14U, 0x73938ce0U, 0x81f80fe3U, 0x55326b08U, 0xa759e80bU, 0xb4091bffU, 0x466298fcU
+      /* 152 */  , 0x1871a4d8U, 0xea1a27dbU, 0xf94ad42fU, 0x0b21572cU, 0xdfeb33c7U, 0x2d80b0c4U, 0x3ed04330U, 0xccbbc033U
+      /* 160 */  , 0xa24bb5a6U, 0x502036a5U, 0x4370c551U, 0xb11b4652U, 0x65d122b9U, 0x97baa1baU, 0x84ea524eU, 0x7681d14dU
+      /* 168 */  , 0x2892ed69U, 0xdaf96e6aU, 0xc9a99d9eU, 0x3bc21e9dU, 0xef087a76U, 0x1d63f975U, 0x0e330a81U, 0xfc588982U
+      /* 176 */  , 0xb21572c9U, 0x407ef1caU, 0x532e023eU, 0xa145813dU, 0x758fe5d6U, 0x87e466d5U, 0x94b49521U, 0x66df1622U
+      /* 184 */  , 0x38cc2a06U, 0xcaa7a905U, 0xd9f75af1U, 0x2b9cd9f2U, 0xff56bd19U, 0x0d3d3e1aU, 0x1e6dcdeeU, 0xec064eedU
+      /* 192 */  , 0xc38d26c4U, 0x31e6a5c7U, 0x22b65633U, 0xd0ddd530U, 0x0417b1dbU, 0xf67c32d8U, 0xe52cc12cU, 0x1747422fU
+      /* 200 */  , 0x49547e0bU, 0xbb3ffd08U, 0xa86f0efcU, 0x5a048dffU, 0x8ecee914U, 0x7ca56a17U, 0x6ff599e3U, 0x9d9e1ae0U
+      /* 208 */  , 0xd3d3e1abU, 0x21b862a8U, 0x32e8915cU, 0xc083125fU, 0x144976b4U, 0xe622f5b7U, 0xf5720643U, 0x07198540U
+      /* 216 */  , 0x590ab964U, 0xab613a67U, 0xb831c993U, 0x4a5a4a90U, 0x9e902e7bU, 0x6cfbad78U, 0x7fab5e8cU, 0x8dc0dd8fU
+      /* 224 */  , 0xe330a81aU, 0x115b2b19U, 0x020bd8edU, 0xf0605beeU, 0x24aa3f05U, 0xd6c1bc06U, 0xc5914ff2U, 0x37faccf1U
+      /* 232 */  , 0x69e9f0d5U, 0x9b8273d6U, 0x88d28022U, 0x7ab90321U, 0xae7367caU, 0x5c18e4c9U, 0x4f48173dU, 0xbd23943eU
+      /* 240 */  , 0xf36e6f75U, 0x0105ec76U, 0x12551f82U, 0xe03e9c81U, 0x34f4f86aU, 0xc69f7b69U, 0xd5cf889dU, 0x27a40b9eU
+      /* 248 */  , 0x79b737baU, 0x8bdcb4b9U, 0x988c474dU, 0x6ae7c44eU, 0xbe2da0a5U, 0x4c4623a6U, 0x5f16d052U, 0xad7d5351U
+    }
+  #ifdef  CRC32_BYFOUR
+    ,
+    /* CRC32C table 1 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x13a29877U, 0x274530eeU, 0x34e7a899U, 0x4e8a61dcU, 0x5d28f9abU, 0x69cf5132U, 0x7a6dc945U
+      /* 8 */  , 0x9d14c3b8U, 0x8eb65bcfU, 0xba51f356U, 0xa9f36b21U, 0xd39ea264U, 0xc03c3a13U, 0xf4db928aU, 0xe7790afdU
+      /* 16 */  , 0x3fc5f181U, 0x2c6769f6U, 0x1880c16fU, 0x0b225918U, 0x714f905dU, 0x62ed082aU, 0x560aa0b3U, 0x45a838c4U
+      /* 24 */  , 0xa2d13239U, 0xb173aa4eU, 0x859402d7U, 0x96369aa0U, 0xec5b53e5U, 0xfff9cb92U, 0xcb1e630bU, 0xd8bcfb7cU
+      /* 32 */  , 0x7f8be302U, 0x6c297b75U, 0x58ced3ecU, 0x4b6c4b9bU, 0x310182deU, 0x22a31aa9U, 0x1644b230U, 0x05e62a47U
+      /* 40 */  , 0xe29f20baU, 0xf13db8cdU, 0xc5da1054U, 0xd6788823U, 0xac154166U, 0xbfb7d911U, 0x8b507188U, 0x98f2e9ffU
+      /* 48 */  , 0x404e1283U, 0x53ec8af4U, 0x670b226dU, 0x74a9ba1aU, 0x0ec4735fU, 0x1d66eb28U, 0x298143b1U, 0x3a23dbc6U
+      /* 56 */  , 0xdd5ad13bU, 0xcef8494cU, 0xfa1fe1d5U, 0xe9bd79a2U, 0x93d0b0e7U, 0x80722890U, 0xb4958009U, 0xa737187eU
+      /* 64 */  , 0xff17c604U, 0xecb55e73U, 0xd852f6eaU, 0xcbf06e9dU, 0xb19da7d8U, 0xa23f3fafU, 0x96d89736U, 0x857a0f41U
+      /* 72 */  , 0x620305bcU, 0x71a19dcbU, 0x45463552U, 0x56e4ad25U, 0x2c896460U, 0x3f2bfc17U, 0x0bcc548eU, 0x186eccf9U
+      /* 80 */  , 0xc0d23785U, 0xd370aff2U, 0xe797076bU, 0xf4359f1cU, 0x8e585659U, 0x9dface2eU, 0xa91d66b7U, 0xbabffec0U
+      /* 88 */  , 0x5dc6f43dU, 0x4e646c4aU, 0x7a83c4d3U, 0x69215ca4U, 0x134c95e1U, 0x00ee0d96U, 0x3409a50fU, 0x27ab3d78U
+      /* 96 */  , 0x809c2506U, 0x933ebd71U, 0xa7d915e8U, 0xb47b8d9fU, 0xce1644daU, 0xddb4dcadU, 0xe9537434U, 0xfaf1ec43U
+      /* 104 */  , 0x1d88e6beU, 0x0e2a7ec9U, 0x3acdd650U, 0x296f4e27U, 0x53028762U, 0x40a01f15U, 0x7447b78cU, 0x67e52ffbU
+      /* 112 */  , 0xbf59d487U, 0xacfb4cf0U, 0x981ce469U, 0x8bbe7c1eU, 0xf1d3b55bU, 0xe2712d2cU, 0xd69685b5U, 0xc5341dc2U
+      /* 120 */  , 0x224d173fU, 0x31ef8f48U, 0x050827d1U, 0x16aabfa6U, 0x6cc776e3U, 0x7f65ee94U, 0x4b82460dU, 0x5820de7aU
+      /* 128 */  , 0xfbc3faf9U, 0xe861628eU, 0xdc86ca17U, 0xcf245260U, 0xb5499b25U, 0xa6eb0352U, 0x920cabcbU, 0x81ae33bcU
+      /* 136 */  , 0x66d73941U, 0x7575a136U, 0x419209afU, 0x523091d8U, 0x285d589dU, 0x3bffc0eaU, 0x0f186873U, 0x1cbaf004U
+      /* 144 */  , 0xc4060b78U, 0xd7a4930fU, 0xe3433b96U, 0xf0e1a3e1U, 0x8a8c6aa4U, 0x992ef2d3U, 0xadc95a4aU, 0xbe6bc23dU
+      /* 152 */  , 0x5912c8c0U, 0x4ab050b7U, 0x7e57f82eU, 0x6df56059U, 0x1798a91cU, 0x043a316bU, 0x30dd99f2U, 0x237f0185U
+      /* 160 */  , 0x844819fbU, 0x97ea818cU, 0xa30d2915U, 0xb0afb162U, 0xcac27827U, 0xd960e050U, 0xed8748c9U, 0xfe25d0beU
+      /* 168 */  , 0x195cda43U, 0x0afe4234U, 0x3e19eaadU, 0x2dbb72daU, 0x57d6bb9fU, 0x447423e8U, 0x70938b71U, 0x63311306U
+      /* 176 */  , 0xbb8de87aU, 0xa82f700dU, 0x9cc8d894U, 0x8f6a40e3U, 0xf50789a6U, 0xe6a511d1U, 0xd242b948U, 0xc1e0213fU
+      /* 184 */  , 0x26992bc2U, 0x353bb3b5U, 0x01dc1b2cU, 0x127e835bU, 0x68134a1eU, 0x7bb1d269U, 0x4f567af0U, 0x5cf4e287U
+      /* 192 */  , 0x04d43cfdU, 0x1776a48aU, 0x23910c13U, 0x30339464U, 0x4a5e5d21U, 0x59fcc556U, 0x6d1b6dcfU, 0x7eb9f5b8U
+      /* 200 */  , 0x99c0ff45U, 0x8a626732U, 0xbe85cfabU, 0xad2757dcU, 0xd74a9e99U, 0xc4e806eeU, 0xf00fae77U, 0xe3ad3600U
+      /* 208 */  , 0x3b11cd7cU, 0x28b3550bU, 0x1c54fd92U, 0x0ff665e5U, 0x759baca0U, 0x663934d7U, 0x52de9c4eU, 0x417c0439U
+      /* 216 */  , 0xa6050ec4U, 0xb5a796b3U, 0x81403e2aU, 0x92e2a65dU, 0xe88f6f18U, 0xfb2df76fU, 0xcfca5ff6U, 0xdc68c781U
+      /* 224 */  , 0x7b5fdfffU, 0x68fd4788U, 0x5c1aef11U, 0x4fb87766U, 0x35d5be23U, 0x26772654U, 0x12908ecdU, 0x013216baU
+      /* 232 */  , 0xe64b1c47U, 0xf5e98430U, 0xc10e2ca9U, 0xd2acb4deU, 0xa8c17d9bU, 0xbb63e5ecU, 0x8f844d75U, 0x9c26d502U
+      /* 240 */  , 0x449a2e7eU, 0x5738b609U, 0x63df1e90U, 0x707d86e7U, 0x0a104fa2U, 0x19b2d7d5U, 0x2d557f4cU, 0x3ef7e73bU
+      /* 248 */  , 0xd98eedc6U, 0xca2c75b1U, 0xfecbdd28U, 0xed69455fU, 0x97048c1aU, 0x84a6146dU, 0xb041bcf4U, 0xa3e32483U
+    }
+    ,
+    /* CRC32C table 2 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0xa541927eU, 0x4f6f520dU, 0xea2ec073U, 0x9edea41aU, 0x3b9f3664U, 0xd1b1f617U, 0x74f06469U
+      /* 8 */  , 0x38513ec5U, 0x9d10acbbU, 0x773e6cc8U, 0xd27ffeb6U, 0xa68f9adfU, 0x03ce08a1U, 0xe9e0c8d2U, 0x4ca15aacU
+      /* 16 */  , 0x70a27d8aU, 0xd5e3eff4U, 0x3fcd2f87U, 0x9a8cbdf9U, 0xee7cd990U, 0x4b3d4beeU, 0xa1138b9dU, 0x045219e3U
+      /* 24 */  , 0x48f3434fU, 0xedb2d131U, 0x079c1142U, 0xa2dd833cU, 0xd62de755U, 0x736c752bU, 0x9942b558U, 0x3c032726U
+      /* 32 */  , 0xe144fb14U, 0x4405696aU, 0xae2ba919U, 0x0b6a3b67U, 0x7f9a5f0eU, 0xdadbcd70U, 0x30f50d03U, 0x95b49f7dU
+      /* 40 */  , 0xd915c5d1U, 0x7c5457afU, 0x967a97dcU, 0x333b05a2U, 0x47cb61cbU, 0xe28af3b5U, 0x08a433c6U, 0xade5a1b8U
+      /* 48 */  , 0x91e6869eU, 0x34a714e0U, 0xde89d493U, 0x7bc846edU, 0x0f382284U, 0xaa79b0faU, 0x40577089U, 0xe516e2f7U
+      /* 56 */  , 0xa9b7b85bU, 0x0cf62a25U, 0xe6d8ea56U, 0x43997828U, 0x37691c41U, 0x92288e3fU, 0x78064e4cU, 0xdd47dc32U
+      /* 64 */  , 0xc76580d9U, 0x622412a7U, 0x880ad2d4U, 0x2d4b40aaU, 0x59bb24c3U, 0xfcfab6bdU, 0x16d476ceU, 0xb395e4b0U
+      /* 72 */  , 0xff34be1cU, 0x5a752c62U, 0xb05bec11U, 0x151a7e6fU, 0x61ea1a06U, 0xc4ab8878U, 0x2e85480bU, 0x8bc4da75U
+      /* 80 */  , 0xb7c7fd53U, 0x12866f2dU, 0xf8a8af5eU, 0x5de93d20U, 0x29195949U, 0x8c58cb37U, 0x66760b44U, 0xc337993aU
+      /* 88 */  , 0x8f96c396U, 0x2ad751e8U, 0xc0f9919bU, 0x65b803e5U, 0x1148678cU, 0xb409f5f2U, 0x5e273581U, 0xfb66a7ffU
+      /* 96 */  , 0x26217bcdU, 0x8360e9b3U, 0x694e29c0U, 0xcc0fbbbeU, 0xb8ffdfd7U, 0x1dbe4da9U, 0xf7908ddaU, 0x52d11fa4U
+      /* 104 */  , 0x1e704508U, 0xbb31d776U, 0x511f1705U, 0xf45e857bU, 0x80aee112U, 0x25ef736cU, 0xcfc1b31fU, 0x6a802161U
+      /* 112 */  , 0x56830647U, 0xf3c29439U, 0x19ec544aU, 0xbcadc634U, 0xc85da25dU, 0x6d1c3023U, 0x8732f050U, 0x2273622eU
+      /* 120 */  , 0x6ed23882U, 0xcb93aafcU, 0x21bd6a8fU, 0x84fcf8f1U, 0xf00c9c98U, 0x554d0ee6U, 0xbf63ce95U, 0x1a225cebU
+      /* 128 */  , 0x8b277743U, 0x2e66e53dU, 0xc448254eU, 0x6109b730U, 0x15f9d359U, 0xb0b84127U, 0x5a968154U, 0xffd7132aU
+      /* 136 */  , 0xb3764986U, 0x1637dbf8U, 0xfc191b8bU, 0x595889f5U, 0x2da8ed9cU, 0x88e97fe2U, 0x62c7bf91U, 0xc7862defU
+      /* 144 */  , 0xfb850ac9U, 0x5ec498b7U, 0xb4ea58c4U, 0x11abcabaU, 0x655baed3U, 0xc01a3cadU, 0x2a34fcdeU, 0x8f756ea0U
+      /* 152 */  , 0xc3d4340cU, 0x6695a672U, 0x8cbb6601U, 0x29faf47fU, 0x5d0a9016U, 0xf84b0268U, 0x1265c21bU, 0xb7245065U
+      /* 160 */  , 0x6a638c57U, 0xcf221e29U, 0x250cde5aU, 0x804d4c24U, 0xf4bd284dU, 0x51fcba33U, 0xbbd27a40U, 0x1e93e83eU
+      /* 168 */  , 0x5232b292U, 0xf77320ecU, 0x1d5de09fU, 0xb81c72e1U, 0xccec1688U, 0x69ad84f6U, 0x83834485U, 0x26c2d6fbU
+      /* 176 */  , 0x1ac1f1ddU, 0xbf8063a3U, 0x55aea3d0U, 0xf0ef31aeU, 0x841f55c7U, 0x215ec7b9U, 0xcb7007caU, 0x6e3195b4U
+      /* 184 */  , 0x2290cf18U, 0x87d15d66U, 0x6dff9d15U, 0xc8be0f6bU, 0xbc4e6b02U, 0x190ff97cU, 0xf321390fU, 0x5660ab71U
+      /* 192 */  , 0x4c42f79aU, 0xe90365e4U, 0x032da597U, 0xa66c37e9U, 0xd29c5380U, 0x77ddc1feU, 0x9df3018dU, 0x38b293f3U
+      /* 200 */  , 0x7413c95fU, 0xd1525b21U, 0x3b7c9b52U, 0x9e3d092cU, 0xeacd6d45U, 0x4f8cff3bU, 0xa5a23f48U, 0x00e3ad36U
+      /* 208 */  , 0x3ce08a10U, 0x99a1186eU, 0x738fd81dU, 0xd6ce4a63U, 0xa23e2e0aU, 0x077fbc74U, 0xed517c07U, 0x4810ee79U
+      /* 216 */  , 0x04b1b4d5U, 0xa1f026abU, 0x4bdee6d8U, 0xee9f74a6U, 0x9a6f10cfU, 0x3f2e82b1U, 0xd50042c2U, 0x7041d0bcU
+      /* 224 */  , 0xad060c8eU, 0x08479ef0U, 0xe2695e83U, 0x4728ccfdU, 0x33d8a894U, 0x96993aeaU, 0x7cb7fa99U, 0xd9f668e7U
+      /* 232 */  , 0x9557324bU, 0x3016a035U, 0xda386046U, 0x7f79f238U, 0x0b899651U, 0xaec8042fU, 0x44e6c45cU, 0xe1a75622U
+      /* 240 */  , 0xdda47104U, 0x78e5e37aU, 0x92cb2309U, 0x378ab177U, 0x437ad51eU, 0xe63b4760U, 0x0c158713U, 0xa954156dU
+      /* 248 */  , 0xe5f54fc1U, 0x40b4ddbfU, 0xaa9a1dccU, 0x0fdb8fb2U, 0x7b2bebdbU, 0xde6a79a5U, 0x3444b9d6U, 0x91052ba8U
+    }
+    ,
+    /* CRC32C table 3 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0xdd45aab8U, 0xbf672381U, 0x62228939U, 0x7b2231f3U, 0xa6679b4bU, 0xc4451272U, 0x1900b8caU
+      /* 8 */  , 0xf64463e6U, 0x2b01c95eU, 0x49234067U, 0x9466eadfU, 0x8d665215U, 0x5023f8adU, 0x32017194U, 0xef44db2cU
+      /* 16 */  , 0xe964b13dU, 0x34211b85U, 0x560392bcU, 0x8b463804U, 0x924680ceU, 0x4f032a76U, 0x2d21a34fU, 0xf06409f7U
+      /* 24 */  , 0x1f20d2dbU, 0xc2657863U, 0xa047f15aU, 0x7d025be2U, 0x6402e328U, 0xb9474990U, 0xdb65c0a9U, 0x06206a11U
+      /* 32 */  , 0xd725148bU, 0x0a60be33U, 0x6842370aU, 0xb5079db2U, 0xac072578U, 0x71428fc0U, 0x136006f9U, 0xce25ac41U
+      /* 40 */  , 0x2161776dU, 0xfc24ddd5U, 0x9e0654ecU, 0x4343fe54U, 0x5a43469eU, 0x8706ec26U, 0xe524651fU, 0x3861cfa7U
+      /* 48 */  , 0x3e41a5b6U, 0xe3040f0eU, 0x81268637U, 0x5c632c8fU, 0x45639445U, 0x98263efdU, 0xfa04b7c4U, 0x27411d7cU
+      /* 56 */  , 0xc805c650U, 0x15406ce8U, 0x7762e5d1U, 0xaa274f69U, 0xb327f7a3U, 0x6e625d1bU, 0x0c40d422U, 0xd1057e9aU
+      /* 64 */  , 0xaba65fe7U, 0x76e3f55fU, 0x14c17c66U, 0xc984d6deU, 0xd0846e14U, 0x0dc1c4acU, 0x6fe34d95U, 0xb2a6e72dU
+      /* 72 */  , 0x5de23c01U, 0x80a796b9U, 0xe2851f80U, 0x3fc0b538U, 0x26c00df2U, 0xfb85a74aU, 0x99a72e73U, 0x44e284cbU
+      /* 80 */  , 0x42c2eedaU, 0x9f874462U, 0xfda5cd5bU, 0x20e067e3U, 0x39e0df29U, 0xe4a57591U, 0x8687fca8U, 0x5bc25610U
+      /* 88 */  , 0xb4868d3cU, 0x69c32784U, 0x0be1aebdU, 0xd6a40405U, 0xcfa4bccfU, 0x12e11677U, 0x70c39f4eU, 0xad8635f6U
+      /* 96 */  , 0x7c834b6cU, 0xa1c6e1d4U, 0xc3e468edU, 0x1ea1c255U, 0x07a17a9fU, 0xdae4d027U, 0xb8c6591eU, 0x6583f3a6U
+      /* 104 */  , 0x8ac7288aU, 0x57828232U, 0x35a00b0bU, 0xe8e5a1b3U, 0xf1e51979U, 0x2ca0b3c1U, 0x4e823af8U, 0x93c79040U
+      /* 112 */  , 0x95e7fa51U, 0x48a250e9U, 0x2a80d9d0U, 0xf7c57368U, 0xeec5cba2U, 0x3380611aU, 0x51a2e823U, 0x8ce7429bU
+      /* 120 */  , 0x63a399b7U, 0xbee6330fU, 0xdcc4ba36U, 0x0181108eU, 0x1881a844U, 0xc5c402fcU, 0xa7e68bc5U, 0x7aa3217dU
+      /* 128 */  , 0x52a0c93fU, 0x8fe56387U, 0xedc7eabeU, 0x30824006U, 0x2982f8ccU, 0xf4c75274U, 0x96e5db4dU, 0x4ba071f5U
+      /* 136 */  , 0xa4e4aad9U, 0x79a10061U, 0x1b838958U, 0xc6c623e0U, 0xdfc69b2aU, 0x02833192U, 0x60a1b8abU, 0xbde41213U
+      /* 144 */  , 0xbbc47802U, 0x6681d2baU, 0x04a35b83U, 0xd9e6f13bU, 0xc0e649f1U, 0x1da3e349U, 0x7f816a70U, 0xa2c4c0c8U
+      /* 152 */  , 0x4d801be4U, 0x90c5b15cU, 0xf2e73865U, 0x2fa292ddU, 0x36a22a17U, 0xebe780afU, 0x89c50996U, 0x5480a32eU
+      /* 160 */  , 0x8585ddb4U, 0x58c0770cU, 0x3ae2fe35U, 0xe7a7548dU, 0xfea7ec47U, 0x23e246ffU, 0x41c0cfc6U, 0x9c85657eU
+      /* 168 */  , 0x73c1be52U, 0xae8414eaU, 0xcca69dd3U, 0x11e3376bU, 0x08e38fa1U, 0xd5a62519U, 0xb784ac20U, 0x6ac10698U
+      /* 176 */  , 0x6ce16c89U, 0xb1a4c631U, 0xd3864f08U, 0x0ec3e5b0U, 0x17c35d7aU, 0xca86f7c2U, 0xa8a47efbU, 0x75e1d443U
+      /* 184 */  , 0x9aa50f6fU, 0x47e0a5d7U, 0x25c22ceeU, 0xf8878656U, 0xe1873e9cU, 0x3cc29424U, 0x5ee01d1dU, 0x83a5b7a5U
+      /* 192 */  , 0xf90696d8U, 0x24433c60U, 0x4661b559U, 0x9b241fe1U, 0x8224a72bU, 0x5f610d93U, 0x3d4384aaU, 0xe0062e12U
+      /* 200 */  , 0x0f42f53eU, 0xd2075f86U, 0xb025d6bfU, 0x6d607c07U, 0x7460c4cdU, 0xa9256e75U, 0xcb07e74cU, 0x16424df4U
+      /* 208 */  , 0x106227e5U, 0xcd278d5dU, 0xaf050464U, 0x7240aedcU, 0x6b401616U, 0xb605bcaeU, 0xd4273597U, 0x09629f2fU
+      /* 216 */  , 0xe6264403U, 0x3b63eebbU, 0x59416782U, 0x8404cd3aU, 0x9d0475f0U, 0x4041df48U, 0x22635671U, 0xff26fcc9U
+      /* 224 */  , 0x2e238253U, 0xf36628ebU, 0x9144a1d2U, 0x4c010b6aU, 0x5501b3a0U, 0x88441918U, 0xea669021U, 0x37233a99U
+      /* 232 */  , 0xd867e1b5U, 0x05224b0dU, 0x6700c234U, 0xba45688cU, 0xa345d046U, 0x7e007afeU, 0x1c22f3c7U, 0xc167597fU
+      /* 240 */  , 0xc747336eU, 0x1a0299d6U, 0x782010efU, 0xa565ba57U, 0xbc65029dU, 0x6120a825U, 0x0302211cU, 0xde478ba4U
+      /* 248 */  , 0x31035088U, 0xec46fa30U, 0x8e647309U, 0x5321d9b1U, 0x4a21617bU, 0x9764cbc3U, 0xf54642faU, 0x2803e842U
+    }
+    ,
+    /* CRC32C table 4 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x03836bf2U, 0xf7703be1U, 0xf4f35013U, 0x1f979ac7U, 0x1c14f135U, 0xe8e7a126U, 0xeb64cad4U
+      /* 8 */  , 0xcf58d98aU, 0xccdbb278U, 0x3828e26bU, 0x3bab8999U, 0xd0cf434dU, 0xd34c28bfU, 0x27bf78acU, 0x243c135eU
+      /* 16 */  , 0x6fc75e10U, 0x6c4435e2U, 0x98b765f1U, 0x9b340e03U, 0x7050c4d7U, 0x73d3af25U, 0x8720ff36U, 0x84a394c4U
+      /* 24 */  , 0xa09f879aU, 0xa31cec68U, 0x57efbc7bU, 0x546cd789U, 0xbf081d5dU, 0xbc8b76afU, 0x487826bcU, 0x4bfb4d4eU
+      /* 32 */  , 0xde8ebd20U, 0xdd0dd6d2U, 0x29fe86c1U, 0x2a7ded33U, 0xc11927e7U, 0xc29a4c15U, 0x36691c06U, 0x35ea77f4U
+      /* 40 */  , 0x11d664aaU, 0x12550f58U, 0xe6a65f4bU, 0xe52534b9U, 0x0e41fe6dU, 0x0dc2959fU, 0xf931c58cU, 0xfab2ae7eU
+      /* 48 */  , 0xb149e330U, 0xb2ca88c2U, 0x4639d8d1U, 0x45bab323U, 0xaede79f7U, 0xad5d1205U, 0x59ae4216U, 0x5a2d29e4U
+      /* 56 */  , 0x7e113abaU, 0x7d925148U, 0x8961015bU, 0x8ae26aa9U, 0x6186a07dU, 0x6205cb8fU, 0x96f69b9cU, 0x9575f06eU
+      /* 64 */  , 0xbc1d7b41U, 0xbf9e10b3U, 0x4b6d40a0U, 0x48ee2b52U, 0xa38ae186U, 0xa0098a74U, 0x54fada67U, 0x5779b195U
+      /* 72 */  , 0x7345a2cbU, 0x70c6c939U, 0x8435992aU, 0x87b6f2d8U, 0x6cd2380cU, 0x6f5153feU, 0x9ba203edU, 0x9821681fU
+      /* 80 */  , 0xd3da2551U, 0xd0594ea3U, 0x24aa1eb0U, 0x27297542U, 0xcc4dbf96U, 0xcfced464U, 0x3b3d8477U, 0x38beef85U
+      /* 88 */  , 0x1c82fcdbU, 0x1f019729U, 0xebf2c73aU, 0xe871acc8U, 0x0315661cU, 0x00960deeU, 0xf4655dfdU, 0xf7e6360fU
+      /* 96 */  , 0x6293c661U, 0x6110ad93U, 0x95e3fd80U, 0x96609672U, 0x7d045ca6U, 0x7e873754U, 0x8a746747U, 0x89f70cb5U
+      /* 104 */  , 0xadcb1febU, 0xae487419U, 0x5abb240aU, 0x59384ff8U, 0xb25c852cU, 0xb1dfeedeU, 0x452cbecdU, 0x46afd53fU
+      /* 112 */  , 0x0d549871U, 0x0ed7f383U, 0xfa24a390U, 0xf9a7c862U, 0x12c302b6U, 0x11406944U, 0xe5b33957U, 0xe63052a5U
+      /* 120 */  , 0xc20c41fbU, 0xc18f2a09U, 0x357c7a1aU, 0x36ff11e8U, 0xdd9bdb3cU, 0xde18b0ceU, 0x2aebe0ddU, 0x29688b2fU
+      /* 128 */  , 0x783bf682U, 0x7bb89d70U, 0x8f4bcd63U, 0x8cc8a691U, 0x67ac6c45U, 0x642f07b7U, 0x90dc57a4U, 0x935f3c56U
+      /* 136 */  , 0xb7632f08U, 0xb4e044faU, 0x401314e9U, 0x43907f1bU, 0xa8f4b5cfU, 0xab77de3dU, 0x5f848e2eU, 0x5c07e5dcU
+      /* 144 */  , 0x17fca892U, 0x147fc360U, 0xe08c9373U, 0xe30ff881U, 0x086b3255U, 0x0be859a7U, 0xff1b09b4U, 0xfc986246U
+      /* 152 */  , 0xd8a47118U, 0xdb271aeaU, 0x2fd44af9U, 0x2c57210bU, 0xc733ebdfU, 0xc4b0802dU, 0x3043d03eU, 0x33c0bbccU
+      /* 160 */  , 0xa6b54ba2U, 0xa5362050U, 0x51c57043U, 0x52461bb1U, 0xb922d165U, 0xbaa1ba97U, 0x4e52ea84U, 0x4dd18176U
+      /* 168 */  , 0x69ed9228U, 0x6a6ef9daU, 0x9e9da9c9U, 0x9d1ec23bU, 0x767a08efU, 0x75f9631dU, 0x810a330eU, 0x828958fcU
+      /* 176 */  , 0xc97215b2U, 0xcaf17e40U, 0x3e022e53U, 0x3d8145a1U, 0xd6e58f75U, 0xd566e487U, 0x2195b494U, 0x2216df66U
+      /* 184 */  , 0x062acc38U, 0x05a9a7caU, 0xf15af7d9U, 0xf2d99c2bU, 0x19bd56ffU, 0x1a3e3d0dU, 0xeecd6d1eU, 0xed4e06ecU
+      /* 192 */  , 0xc4268dc3U, 0xc7a5e631U, 0x3356b622U, 0x30d5ddd0U, 0xdbb11704U, 0xd8327cf6U, 0x2cc12ce5U, 0x2f424717U
+      /* 200 */  , 0x0b7e5449U, 0x08fd3fbbU, 0xfc0e6fa8U, 0xff8d045aU, 0x14e9ce8eU, 0x176aa57cU, 0xe399f56fU, 0xe01a9e9dU
+      /* 208 */  , 0xabe1d3d3U, 0xa862b821U, 0x5c91e832U, 0x5f1283c0U, 0xb4764914U, 0xb7f522e6U, 0x430672f5U, 0x40851907U
+      /* 216 */  , 0x64b90a59U, 0x673a61abU, 0x93c931b8U, 0x904a5a4aU, 0x7b2e909eU, 0x78adfb6cU, 0x8c5eab7fU, 0x8fddc08dU
+      /* 224 */  , 0x1aa830e3U, 0x192b5b11U, 0xedd80b02U, 0xee5b60f0U, 0x053faa24U, 0x06bcc1d6U, 0xf24f91c5U, 0xf1ccfa37U
+      /* 232 */  , 0xd5f0e969U, 0xd673829bU, 0x2280d288U, 0x2103b97aU, 0xca6773aeU, 0xc9e4185cU, 0x3d17484fU, 0x3e9423bdU
+      /* 240 */  , 0x756f6ef3U, 0x76ec0501U, 0x821f5512U, 0x819c3ee0U, 0x6af8f434U, 0x697b9fc6U, 0x9d88cfd5U, 0x9e0ba427U
+      /* 248 */  , 0xba37b779U, 0xb9b4dc8bU, 0x4d478c98U, 0x4ec4e76aU, 0xa5a02dbeU, 0xa623464cU, 0x52d0165fU, 0x51537dadU
+    }
+    ,
+    /* CRC32C table 5 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x7798a213U, 0xee304527U, 0x99a8e734U, 0xdc618a4eU, 0xabf9285dU, 0x3251cf69U, 0x45c96d7aU
+      /* 8 */  , 0xb8c3149dU, 0xcf5bb68eU, 0x56f351baU, 0x216bf3a9U, 0x64a29ed3U, 0x133a3cc0U, 0x8a92dbf4U, 0xfd0a79e7U
+      /* 16 */  , 0x81f1c53fU, 0xf669672cU, 0x6fc18018U, 0x1859220bU, 0x5d904f71U, 0x2a08ed62U, 0xb3a00a56U, 0xc438a845U
+      /* 24 */  , 0x3932d1a2U, 0x4eaa73b1U, 0xd7029485U, 0xa09a3696U, 0xe5535becU, 0x92cbf9ffU, 0x0b631ecbU, 0x7cfbbcd8U
+      /* 32 */  , 0x02e38b7fU, 0x757b296cU, 0xecd3ce58U, 0x9b4b6c4bU, 0xde820131U, 0xa91aa322U, 0x30b24416U, 0x472ae605U
+      /* 40 */  , 0xba209fe2U, 0xcdb83df1U, 0x5410dac5U, 0x238878d6U, 0x664115acU, 0x11d9b7bfU, 0x8871508bU, 0xffe9f298U
+      /* 48 */  , 0x83124e40U, 0xf48aec53U, 0x6d220b67U, 0x1abaa974U, 0x5f73c40eU, 0x28eb661dU, 0xb1438129U, 0xc6db233aU
+      /* 56 */  , 0x3bd15addU, 0x4c49f8ceU, 0xd5e11ffaU, 0xa279bde9U, 0xe7b0d093U, 0x90287280U, 0x098095b4U, 0x7e1837a7U
+      /* 64 */  , 0x04c617ffU, 0x735eb5ecU, 0xeaf652d8U, 0x9d6ef0cbU, 0xd8a79db1U, 0xaf3f3fa2U, 0x3697d896U, 0x410f7a85U
+      /* 72 */  , 0xbc050362U, 0xcb9da171U, 0x52354645U, 0x25ade456U, 0x6064892cU, 0x17fc2b3fU, 0x8e54cc0bU, 0xf9cc6e18U
+      /* 80 */  , 0x8537d2c0U, 0xf2af70d3U, 0x6b0797e7U, 0x1c9f35f4U, 0x5956588eU, 0x2ecefa9dU, 0xb7661da9U, 0xc0febfbaU
+      /* 88 */  , 0x3df4c65dU, 0x4a6c644eU, 0xd3c4837aU, 0xa45c2169U, 0xe1954c13U, 0x960dee00U, 0x0fa50934U, 0x783dab27U
+      /* 96 */  , 0x06259c80U, 0x71bd3e93U, 0xe815d9a7U, 0x9f8d7bb4U, 0xda4416ceU, 0xaddcb4ddU, 0x347453e9U, 0x43ecf1faU
+      /* 104 */  , 0xbee6881dU, 0xc97e2a0eU, 0x50d6cd3aU, 0x274e6f29U, 0x62870253U, 0x151fa040U, 0x8cb74774U, 0xfb2fe567U
+      /* 112 */  , 0x87d459bfU, 0xf04cfbacU, 0x69e41c98U, 0x1e7cbe8bU, 0x5bb5d3f1U, 0x2c2d71e2U, 0xb58596d6U, 0xc21d34c5U
+      /* 120 */  , 0x3f174d22U, 0x488fef31U, 0xd1270805U, 0xa6bfaa16U, 0xe376c76cU, 0x94ee657fU, 0x0d46824bU, 0x7ade2058U
+      /* 128 */  , 0xf9fac3fbU, 0x8e6261e8U, 0x17ca86dcU, 0x605224cfU, 0x259b49b5U, 0x5203eba6U, 0xcbab0c92U, 0xbc33ae81U
+      /* 136 */  , 0x4139d766U, 0x36a17575U, 0xaf099241U, 0xd8913052U, 0x9d585d28U, 0xeac0ff3bU, 0x7368180fU, 0x04f0ba1cU
+      /* 144 */  , 0x780b06c4U, 0x0f93a4d7U, 0x963b43e3U, 0xe1a3e1f0U, 0xa46a8c8aU, 0xd3f22e99U, 0x4a5ac9adU, 0x3dc26bbeU
+      /* 152 */  , 0xc0c81259U, 0xb750b04aU, 0x2ef8577eU, 0x5960f56dU, 0x1ca99817U, 0x6b313a04U, 0xf299dd30U, 0x85017f23U
+      /* 160 */  , 0xfb194884U, 0x8c81ea97U, 0x15290da3U, 0x62b1afb0U, 0x2778c2caU, 0x50e060d9U, 0xc94887edU, 0xbed025feU
+      /* 168 */  , 0x43da5c19U, 0x3442fe0aU, 0xadea193eU, 0xda72bb2dU, 0x9fbbd657U, 0xe8237444U, 0x718b9370U, 0x06133163U
+      /* 176 */  , 0x7ae88dbbU, 0x0d702fa8U, 0x94d8c89cU, 0xe3406a8fU, 0xa68907f5U, 0xd111a5e6U, 0x48b942d2U, 0x3f21e0c1U
+      /* 184 */  , 0xc22b9926U, 0xb5b33b35U, 0x2c1bdc01U, 0x5b837e12U, 0x1e4a1368U, 0x69d2b17bU, 0xf07a564fU, 0x87e2f45cU
+      /* 192 */  , 0xfd3cd404U, 0x8aa47617U, 0x130c9123U, 0x64943330U, 0x215d5e4aU, 0x56c5fc59U, 0xcf6d1b6dU, 0xb8f5b97eU
+      /* 200 */  , 0x45ffc099U, 0x3267628aU, 0xabcf85beU, 0xdc5727adU, 0x999e4ad7U, 0xee06e8c4U, 0x77ae0ff0U, 0x0036ade3U
+      /* 208 */  , 0x7ccd113bU, 0x0b55b328U, 0x92fd541cU, 0xe565f60fU, 0xa0ac9b75U, 0xd7343966U, 0x4e9cde52U, 0x39047c41U
+      /* 216 */  , 0xc40e05a6U, 0xb396a7b5U, 0x2a3e4081U, 0x5da6e292U, 0x186f8fe8U, 0x6ff72dfbU, 0xf65fcacfU, 0x81c768dcU
+      /* 224 */  , 0xffdf5f7bU, 0x8847fd68U, 0x11ef1a5cU, 0x6677b84fU, 0x23bed535U, 0x54267726U, 0xcd8e9012U, 0xba163201U
+      /* 232 */  , 0x471c4be6U, 0x3084e9f5U, 0xa92c0ec1U, 0xdeb4acd2U, 0x9b7dc1a8U, 0xece563bbU, 0x754d848fU, 0x02d5269cU
+      /* 240 */  , 0x7e2e9a44U, 0x09b63857U, 0x901edf63U, 0xe7867d70U, 0xa24f100aU, 0xd5d7b219U, 0x4c7f552dU, 0x3be7f73eU
+      /* 248 */  , 0xc6ed8ed9U, 0xb1752ccaU, 0x28ddcbfeU, 0x5f4569edU, 0x1a8c0497U, 0x6d14a684U, 0xf4bc41b0U, 0x8324e3a3U
+    }
+    ,
+    /* CRC32C table 6 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x7e9241a5U, 0x0d526f4fU, 0x73c02eeaU, 0x1aa4de9eU, 0x64369f3bU, 0x17f6b1d1U, 0x6964f074U
+      /* 8 */  , 0xc53e5138U, 0xbbac109dU, 0xc86c3e77U, 0xb6fe7fd2U, 0xdf9a8fa6U, 0xa108ce03U, 0xd2c8e0e9U, 0xac5aa14cU
+      /* 16 */  , 0x8a7da270U, 0xf4efe3d5U, 0x872fcd3fU, 0xf9bd8c9aU, 0x90d97ceeU, 0xee4b3d4bU, 0x9d8b13a1U, 0xe3195204U
+      /* 24 */  , 0x4f43f348U, 0x31d1b2edU, 0x42119c07U, 0x3c83dda2U, 0x55e72dd6U, 0x2b756c73U, 0x58b54299U, 0x2627033cU
+      /* 32 */  , 0x14fb44e1U, 0x6a690544U, 0x19a92baeU, 0x673b6a0bU, 0x0e5f9a7fU, 0x70cddbdaU, 0x030df530U, 0x7d9fb495U
+      /* 40 */  , 0xd1c515d9U, 0xaf57547cU, 0xdc977a96U, 0xa2053b33U, 0xcb61cb47U, 0xb5f38ae2U, 0xc633a408U, 0xb8a1e5adU
+      /* 48 */  , 0x9e86e691U, 0xe014a734U, 0x93d489deU, 0xed46c87bU, 0x8422380fU, 0xfab079aaU, 0x89705740U, 0xf7e216e5U
+      /* 56 */  , 0x5bb8b7a9U, 0x252af60cU, 0x56ead8e6U, 0x28789943U, 0x411c6937U, 0x3f8e2892U, 0x4c4e0678U, 0x32dc47ddU
+      /* 64 */  , 0xd98065c7U, 0xa7122462U, 0xd4d20a88U, 0xaa404b2dU, 0xc324bb59U, 0xbdb6fafcU, 0xce76d416U, 0xb0e495b3U
+      /* 72 */  , 0x1cbe34ffU, 0x622c755aU, 0x11ec5bb0U, 0x6f7e1a15U, 0x061aea61U, 0x7888abc4U, 0x0b48852eU, 0x75dac48bU
+      /* 80 */  , 0x53fdc7b7U, 0x2d6f8612U, 0x5eafa8f8U, 0x203de95dU, 0x49591929U, 0x37cb588cU, 0x440b7666U, 0x3a9937c3U
+      /* 88 */  , 0x96c3968fU, 0xe851d72aU, 0x9b91f9c0U, 0xe503b865U, 0x8c674811U, 0xf2f509b4U, 0x8135275eU, 0xffa766fbU
+      /* 96 */  , 0xcd7b2126U, 0xb3e96083U, 0xc0294e69U, 0xbebb0fccU, 0xd7dfffb8U, 0xa94dbe1dU, 0xda8d90f7U, 0xa41fd152U
+      /* 104 */  , 0x0845701eU, 0x76d731bbU, 0x05171f51U, 0x7b855ef4U, 0x12e1ae80U, 0x6c73ef25U, 0x1fb3c1cfU, 0x6121806aU
+      /* 112 */  , 0x47068356U, 0x3994c2f3U, 0x4a54ec19U, 0x34c6adbcU, 0x5da25dc8U, 0x23301c6dU, 0x50f03287U, 0x2e627322U
+      /* 120 */  , 0x8238d26eU, 0xfcaa93cbU, 0x8f6abd21U, 0xf1f8fc84U, 0x989c0cf0U, 0xe60e4d55U, 0x95ce63bfU, 0xeb5c221aU
+      /* 128 */  , 0x4377278bU, 0x3de5662eU, 0x4e2548c4U, 0x30b70961U, 0x59d3f915U, 0x2741b8b0U, 0x5481965aU, 0x2a13d7ffU
+      /* 136 */  , 0x864976b3U, 0xf8db3716U, 0x8b1b19fcU, 0xf5895859U, 0x9ceda82dU, 0xe27fe988U, 0x91bfc762U, 0xef2d86c7U
+      /* 144 */  , 0xc90a85fbU, 0xb798c45eU, 0xc458eab4U, 0xbacaab11U, 0xd3ae5b65U, 0xad3c1ac0U, 0xdefc342aU, 0xa06e758fU
+      /* 152 */  , 0x0c34d4c3U, 0x72a69566U, 0x0166bb8cU, 0x7ff4fa29U, 0x16900a5dU, 0x68024bf8U, 0x1bc26512U, 0x655024b7U
+      /* 160 */  , 0x578c636aU, 0x291e22cfU, 0x5ade0c25U, 0x244c4d80U, 0x4d28bdf4U, 0x33bafc51U, 0x407ad2bbU, 0x3ee8931eU
+      /* 168 */  , 0x92b23252U, 0xec2073f7U, 0x9fe05d1dU, 0xe1721cb8U, 0x8816ecccU, 0xf684ad69U, 0x85448383U, 0xfbd6c226U
+      /* 176 */  , 0xddf1c11aU, 0xa36380bfU, 0xd0a3ae55U, 0xae31eff0U, 0xc7551f84U, 0xb9c75e21U, 0xca0770cbU, 0xb495316eU
+      /* 184 */  , 0x18cf9022U, 0x665dd187U, 0x159dff6dU, 0x6b0fbec8U, 0x026b4ebcU, 0x7cf90f19U, 0x0f3921f3U, 0x71ab6056U
+      /* 192 */  , 0x9af7424cU, 0xe46503e9U, 0x97a52d03U, 0xe9376ca6U, 0x80539cd2U, 0xfec1dd77U, 0x8d01f39dU, 0xf393b238U
+      /* 200 */  , 0x5fc91374U, 0x215b52d1U, 0x529b7c3bU, 0x2c093d9eU, 0x456dcdeaU, 0x3bff8c4fU, 0x483fa2a5U, 0x36ade300U
+      /* 208 */  , 0x108ae03cU, 0x6e18a199U, 0x1dd88f73U, 0x634aced6U, 0x0a2e3ea2U, 0x74bc7f07U, 0x077c51edU, 0x79ee1048U
+      /* 216 */  , 0xd5b4b104U, 0xab26f0a1U, 0xd8e6de4bU, 0xa6749feeU, 0xcf106f9aU, 0xb1822e3fU, 0xc24200d5U, 0xbcd04170U
+      /* 224 */  , 0x8e0c06adU, 0xf09e4708U, 0x835e69e2U, 0xfdcc2847U, 0x94a8d833U, 0xea3a9996U, 0x99fab77cU, 0xe768f6d9U
+      /* 232 */  , 0x4b325795U, 0x35a01630U, 0x466038daU, 0x38f2797fU, 0x5196890bU, 0x2f04c8aeU, 0x5cc4e644U, 0x2256a7e1U
+      /* 240 */  , 0x0471a4ddU, 0x7ae3e578U, 0x0923cb92U, 0x77b18a37U, 0x1ed57a43U, 0x60473be6U, 0x1387150cU, 0x6d1554a9U
+      /* 248 */  , 0xc14ff5e5U, 0xbfddb440U, 0xcc1d9aaaU, 0xb28fdb0fU, 0xdbeb2b7bU, 0xa5796adeU, 0xd6b94434U, 0xa82b0591U
+    }
+    ,
+    /* CRC32C table 7 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0xb8aa45ddU, 0x812367bfU, 0x39892262U, 0xf331227bU, 0x4b9b67a6U, 0x721245c4U, 0xcab80019U
+      /* 8 */  , 0xe66344f6U, 0x5ec9012bU, 0x67402349U, 0xdfea6694U, 0x1552668dU, 0xadf82350U, 0x94710132U, 0x2cdb44efU
+      /* 16 */  , 0x3db164e9U, 0x851b2134U, 0xbc920356U, 0x0438468bU, 0xce804692U, 0x762a034fU, 0x4fa3212dU, 0xf70964f0U
+      /* 24 */  , 0xdbd2201fU, 0x637865c2U, 0x5af147a0U, 0xe25b027dU, 0x28e30264U, 0x904947b9U, 0xa9c065dbU, 0x116a2006U
+      /* 32 */  , 0x8b1425d7U, 0x33be600aU, 0x0a374268U, 0xb29d07b5U, 0x782507acU, 0xc08f4271U, 0xf9066013U, 0x41ac25ceU
+      /* 40 */  , 0x6d776121U, 0xd5dd24fcU, 0xec54069eU, 0x54fe4343U, 0x9e46435aU, 0x26ec0687U, 0x1f6524e5U, 0xa7cf6138U
+      /* 48 */  , 0xb6a5413eU, 0x0e0f04e3U, 0x37862681U, 0x8f2c635cU, 0x45946345U, 0xfd3e2698U, 0xc4b704faU, 0x7c1d4127U
+      /* 56 */  , 0x50c605c8U, 0xe86c4015U, 0xd1e56277U, 0x694f27aaU, 0xa3f727b3U, 0x1b5d626eU, 0x22d4400cU, 0x9a7e05d1U
+      /* 64 */  , 0xe75fa6abU, 0x5ff5e376U, 0x667cc114U, 0xded684c9U, 0x146e84d0U, 0xacc4c10dU, 0x954de36fU, 0x2de7a6b2U
+      /* 72 */  , 0x013ce25dU, 0xb996a780U, 0x801f85e2U, 0x38b5c03fU, 0xf20dc026U, 0x4aa785fbU, 0x732ea799U, 0xcb84e244U
+      /* 80 */  , 0xdaeec242U, 0x6244879fU, 0x5bcda5fdU, 0xe367e020U, 0x29dfe039U, 0x9175a5e4U, 0xa8fc8786U, 0x1056c25bU
+      /* 88 */  , 0x3c8d86b4U, 0x8427c369U, 0xbdaee10bU, 0x0504a4d6U, 0xcfbca4cfU, 0x7716e112U, 0x4e9fc370U, 0xf63586adU
+      /* 96 */  , 0x6c4b837cU, 0xd4e1c6a1U, 0xed68e4c3U, 0x55c2a11eU, 0x9f7aa107U, 0x27d0e4daU, 0x1e59c6b8U, 0xa6f38365U
+      /* 104 */  , 0x8a28c78aU, 0x32828257U, 0x0b0ba035U, 0xb3a1e5e8U, 0x7919e5f1U, 0xc1b3a02cU, 0xf83a824eU, 0x4090c793U
+      /* 112 */  , 0x51fae795U, 0xe950a248U, 0xd0d9802aU, 0x6873c5f7U, 0xa2cbc5eeU, 0x1a618033U, 0x23e8a251U, 0x9b42e78cU
+      /* 120 */  , 0xb799a363U, 0x0f33e6beU, 0x36bac4dcU, 0x8e108101U, 0x44a88118U, 0xfc02c4c5U, 0xc58be6a7U, 0x7d21a37aU
+      /* 128 */  , 0x3fc9a052U, 0x8763e58fU, 0xbeeac7edU, 0x06408230U, 0xccf88229U, 0x7452c7f4U, 0x4ddbe596U, 0xf571a04bU
+      /* 136 */  , 0xd9aae4a4U, 0x6100a179U, 0x5889831bU, 0xe023c6c6U, 0x2a9bc6dfU, 0x92318302U, 0xabb8a160U, 0x1312e4bdU
+      /* 144 */  , 0x0278c4bbU, 0xbad28166U, 0x835ba304U, 0x3bf1e6d9U, 0xf149e6c0U, 0x49e3a31dU, 0x706a817fU, 0xc8c0c4a2U
+      /* 152 */  , 0xe41b804dU, 0x5cb1c590U, 0x6538e7f2U, 0xdd92a22fU, 0x172aa236U, 0xaf80e7ebU, 0x9609c589U, 0x2ea38054U
+      /* 160 */  , 0xb4dd8585U, 0x0c77c058U, 0x35fee23aU, 0x8d54a7e7U, 0x47eca7feU, 0xff46e223U, 0xc6cfc041U, 0x7e65859cU
+      /* 168 */  , 0x52bec173U, 0xea1484aeU, 0xd39da6ccU, 0x6b37e311U, 0xa18fe308U, 0x1925a6d5U, 0x20ac84b7U, 0x9806c16aU
+      /* 176 */  , 0x896ce16cU, 0x31c6a4b1U, 0x084f86d3U, 0xb0e5c30eU, 0x7a5dc317U, 0xc2f786caU, 0xfb7ea4a8U, 0x43d4e175U
+      /* 184 */  , 0x6f0fa59aU, 0xd7a5e047U, 0xee2cc225U, 0x568687f8U, 0x9c3e87e1U, 0x2494c23cU, 0x1d1de05eU, 0xa5b7a583U
+      /* 192 */  , 0xd89606f9U, 0x603c4324U, 0x59b56146U, 0xe11f249bU, 0x2ba72482U, 0x930d615fU, 0xaa84433dU, 0x122e06e0U
+      /* 200 */  , 0x3ef5420fU, 0x865f07d2U, 0xbfd625b0U, 0x077c606dU, 0xcdc46074U, 0x756e25a9U, 0x4ce707cbU, 0xf44d4216U
+      /* 208 */  , 0xe5276210U, 0x5d8d27cdU, 0x640405afU, 0xdcae4072U, 0x1616406bU, 0xaebc05b6U, 0x973527d4U, 0x2f9f6209U
+      /* 216 */  , 0x034426e6U, 0xbbee633bU, 0x82674159U, 0x3acd0484U, 0xf075049dU, 0x48df4140U, 0x71566322U, 0xc9fc26ffU
+      /* 224 */  , 0x5382232eU, 0xeb2866f3U, 0xd2a14491U, 0x6a0b014cU, 0xa0b30155U, 0x18194488U, 0x219066eaU, 0x993a2337U
+      /* 232 */  , 0xb5e167d8U, 0x0d4b2205U, 0x34c20067U, 0x8c6845baU, 0x46d045a3U, 0xfe7a007eU, 0xc7f3221cU, 0x7f5967c1U
+      /* 240 */  , 0x6e3347c7U, 0xd699021aU, 0xef102078U, 0x57ba65a5U, 0x9d0265bcU, 0x25a82061U, 0x1c210203U, 0xa48b47deU
+      /* 248 */  , 0x88500331U, 0x30fa46ecU, 0x0973648eU, 0xb1d92153U, 0x7b61214aU, 0xc3cb6497U, 0xfa4246f5U, 0x42e80328U
+    }
+  #endif
+  };
 
 juint* StubRoutines::ppc64::_constants = StubRoutines::ppc64::generate_crc_constants();
 
--- a/hotspot/src/cpu/ppc/vm/templateInterpreterGenerator_ppc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/templateInterpreterGenerator_ppc.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2015, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -646,12 +646,6 @@
   return entry;
 }
 
-address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
-  address entry = __ pc();
-  __ unimplemented("generate_continuation_for");
-  return entry;
-}
-
 // This entry is returned to when a call returns to the interpreter.
 // When we arrive here, we expect that the callee stack frame is already popped.
 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
@@ -695,6 +689,10 @@
 #endif
   __ sldi(size, size, Interpreter::logStackElementSize);
   __ add(R15_esp, R15_esp, size);
+
+ __ check_and_handle_popframe(R11_scratch1);
+ __ check_and_handle_earlyret(R11_scratch1);
+
   __ dispatch_next(state, step);
   return entry;
 }
@@ -1897,7 +1895,7 @@
     __ lwz(crc,  2*wordSize, argP);    // Current crc state, zero extend to 64 bit to have a clean register.
 
     StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
-    __ kernel_crc32_singleByte(crc, data, dataLen, table, tmp);
+    __ kernel_crc32_singleByte(crc, data, dataLen, table, tmp, true);
 
     // Restore caller sp for c2i case and return.
     __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
@@ -1913,6 +1911,10 @@
   return NULL;
 }
 
+// TODO: generate_CRC32_updateBytes_entry and generate_CRC32C_updateBytes_entry are identical
+//       except for using different crc tables and some block comment strings.
+//       We should provide a common implementation.
+
 // CRC32 Intrinsics.
 /**
  * Method entry for static native methods:
@@ -1989,7 +1991,7 @@
     // Performance measurements show the 1word and 2word variants to be almost equivalent,
     // with very light advantages for the 1word variant. We chose the 1word variant for
     // code compactness.
-    __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, tc0, tc1, tc2, tc3);
+    __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, tc0, tc1, tc2, tc3, true);
 
     // Restore caller sp for c2i case and return.
     __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
@@ -2005,8 +2007,84 @@
   return NULL;
 }
 
-// Not supported
+// CRC32C Intrinsics.
+/**
+ * Method entry for static native methods:
+ *   int java.util.zip.CRC32C.updateBytes(           int crc, byte[] b,  int off, int len)
+ *   int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long* buf, int off, int len)
+ **/
 address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
+  if (UseCRC32CIntrinsics) {
+    address start = __ pc();  // Remember stub start address (is rtn value).
+
+    // We don't generate local frame and don't align stack because
+    // we not even call stub code (we generate the code inline)
+    // and there is no safepoint on this path.
+
+    // Load parameters.
+    // Z_esp is callers operand stack pointer, i.e. it points to the parameters.
+    const Register argP    = R15_esp;
+    const Register crc     = R3_ARG1;  // crc value
+    const Register data    = R4_ARG2;  // address of java byte array
+    const Register dataLen = R5_ARG3;  // source data len
+    const Register table   = R6_ARG4;  // address of crc32c table
+
+    const Register t0      = R9;       // scratch registers for crc calculation
+    const Register t1      = R10;
+    const Register t2      = R11;
+    const Register t3      = R12;
+
+    const Register tc0     = R2;       // registers to hold pre-calculated column addresses
+    const Register tc1     = R7;
+    const Register tc2     = R8;
+    const Register tc3     = table;    // table address is reconstructed at the end of kernel_crc32_* emitters
+
+    const Register tmp     = t0;       // Only used very locally to calculate byte buffer address.
+
+    // Arguments are reversed on java expression stack.
+    // Calculate address of start element.
+    if (kind == Interpreter::java_util_zip_CRC32C_updateDirectByteBuffer) { // Used for "updateDirectByteBuffer".
+      BLOCK_COMMENT("CRC32C_updateDirectByteBuffer {");
+      // crc     @ (SP + 5W) (32bit)
+      // buf     @ (SP + 3W) (64bit ptr to long array)
+      // off     @ (SP + 2W) (32bit)
+      // dataLen @ (SP + 1W) (32bit)
+      // data = buf + off
+      __ ld(  data,    3*wordSize, argP);  // start of byte buffer
+      __ lwa( tmp,     2*wordSize, argP);  // byte buffer offset
+      __ lwa( dataLen, 1*wordSize, argP);  // #bytes to process
+      __ lwz( crc,     5*wordSize, argP);  // current crc state
+      __ add( data, data, tmp);            // Add byte buffer offset.
+    } else {                                                         // Used for "updateBytes update".
+      BLOCK_COMMENT("CRC32C_updateBytes {");
+      // crc     @ (SP + 4W) (32bit)
+      // buf     @ (SP + 3W) (64bit ptr to byte array)
+      // off     @ (SP + 2W) (32bit)
+      // dataLen @ (SP + 1W) (32bit)
+      // data = buf + off + base_offset
+      __ ld(  data,    3*wordSize, argP);  // start of byte buffer
+      __ lwa( tmp,     2*wordSize, argP);  // byte buffer offset
+      __ lwa( dataLen, 1*wordSize, argP);  // #bytes to process
+      __ add( data, data, tmp);            // add byte buffer offset
+      __ lwz( crc,     4*wordSize, argP);  // current crc state
+      __ addi(data, data, arrayOopDesc::base_offset_in_bytes(T_BYTE));
+    }
+
+    StubRoutines::ppc64::generate_load_crc32c_table_addr(_masm, table);
+
+    // Performance measurements show the 1word and 2word variants to be almost equivalent,
+    // with very light advantages for the 1word variant. We chose the 1word variant for
+    // code compactness.
+    __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, tc0, tc1, tc2, tc3, false);
+
+    // Restore caller sp for c2i case and return.
+    __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
+    __ blr();
+
+    BLOCK_COMMENT("} CRC32C_update{Bytes|DirectByteBuffer}");
+    return start;
+  }
+
   return NULL;
 }
 
--- a/hotspot/src/cpu/ppc/vm/vm_version_ppc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/ppc/vm/vm_version_ppc.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -172,18 +172,27 @@
 
   assert(AllocatePrefetchStyle >= 0, "AllocatePrefetchStyle should be positive");
 
-  // Implementation does not use any of the vector instructions
-  // available with Power8. Their exploitation is still pending.
+  // If defined(VM_LITTLE_ENDIAN) and running on Power8 or newer hardware,
+  // the implementation uses the vector instructions available with Power8.
+  // In all other cases, the implementation uses only generally available instructions.
   if (!UseCRC32Intrinsics) {
     if (FLAG_IS_DEFAULT(UseCRC32Intrinsics)) {
       FLAG_SET_DEFAULT(UseCRC32Intrinsics, true);
     }
   }
 
-  if (UseCRC32CIntrinsics) {
-    if (!FLAG_IS_DEFAULT(UseCRC32CIntrinsics))
-      warning("CRC32C intrinsics are not available on this CPU");
-    FLAG_SET_DEFAULT(UseCRC32CIntrinsics, false);
+  // Implementation does not use any of the vector instructions available with Power8.
+  // Their exploitation is still pending (aka "work in progress").
+  if (!UseCRC32CIntrinsics) {
+    if (FLAG_IS_DEFAULT(UseCRC32CIntrinsics)) {
+      FLAG_SET_DEFAULT(UseCRC32CIntrinsics, true);
+    }
+  }
+
+  // TODO: Provide implementation.
+  if (UseAdler32Intrinsics) {
+    warning("Adler32Intrinsics not available on this CPU.");
+    FLAG_SET_DEFAULT(UseAdler32Intrinsics, false);
   }
 
   // The AES intrinsic stubs require AES instruction support.
@@ -245,11 +254,6 @@
     FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
   }
 
-  if (UseAdler32Intrinsics) {
-    warning("Adler32Intrinsics not available on this CPU.");
-    FLAG_SET_DEFAULT(UseAdler32Intrinsics, false);
-  }
-
   if (FLAG_IS_DEFAULT(UseMultiplyToLenIntrinsic)) {
     UseMultiplyToLenIntrinsic = true;
   }
--- a/hotspot/src/cpu/s390/vm/assembler_s390.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/assembler_s390.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -28,8 +28,6 @@
 
 #undef  LUCY_DBG
 
-#define NearLabel Label
-
 // Immediate is an abstraction to represent the various immediate
 // operands which exist on z/Architecture. Neither this class nor
 // instances hereof have an own state. It consists of methods only.
--- a/hotspot/src/cpu/s390/vm/c1_LIRAssembler_s390.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/c1_LIRAssembler_s390.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -3048,9 +3048,8 @@
   assert_different_registers(val, crc, res);
 
   __ load_const_optimized(res, StubRoutines::crc_table_addr());
-  __ not_(crc, noreg, false); // ~crc
-  __ update_byte_crc32(crc, val, res);
-  __ not_(res, crc, false); // ~crc
+  __ kernel_crc32_singleByteReg(crc, val, res, true);
+  __ z_lgfr(res, crc);
 }
 
 #undef __
--- a/hotspot/src/cpu/s390/vm/c1_LIRGenerator_s390.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/c1_LIRGenerator_s390.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -61,20 +61,6 @@
   }
 }
 
-inline void load_int_as_long(LIR_List *ll, LIRItem &li, LIR_Opr dst) {
-  LIR_Opr r = li.value()->operand();
-  if (r->is_constant()) {
-    // Constants get loaded with sign extend on this platform.
-    ll->move(li.result(), dst);
-  } else {
-    if (!r->is_register()) {
-      li.load_item_force(dst);
-    }
-    LIR_Opr dst_l = FrameMap::as_long_opr(dst->as_register());
-    ll->convert(Bytecodes::_i2l, li.result(), dst_l); // Convert.
-  }
-}
-
 //--------------------------------------------------------------
 //               LIRGenerator
 //--------------------------------------------------------------
@@ -1217,10 +1203,9 @@
       LIR_Opr arg2 = cc->at(1);
       LIR_Opr arg3 = cc->at(2);
 
-      // CCallingConventionRequiresIntsAsLongs
       crc.load_item_force(arg1); // We skip int->long conversion here, because CRC32 stub doesn't care about high bits.
       __ leal(LIR_OprFact::address(a), arg2);
-      load_int_as_long(gen()->lir(), len, arg3);
+      len.load_item_force(arg3); // We skip int->long conversion here, because CRC32 stub expects int.
 
       __ call_runtime_leaf(StubRoutines::updateBytesCRC32(), LIR_OprFact::illegalOpr, result_reg, cc->args());
       __ move(result_reg, result);
@@ -1233,7 +1218,60 @@
 }
 
 void LIRGenerator::do_update_CRC32C(Intrinsic* x) {
-  Unimplemented();
+  assert(UseCRC32CIntrinsics, "or should not be here");
+  LIR_Opr result = rlock_result(x);
+
+  switch (x->id()) {
+    case vmIntrinsics::_updateBytesCRC32C:
+    case vmIntrinsics::_updateDirectByteBufferCRC32C: {
+      bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32C);
+
+      LIRItem crc(x->argument_at(0), this);
+      LIRItem buf(x->argument_at(1), this);
+      LIRItem off(x->argument_at(2), this);
+      LIRItem len(x->argument_at(3), this);
+      buf.load_item();
+      off.load_nonconstant();
+
+      LIR_Opr index = off.result();
+      int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
+      if (off.result()->is_constant()) {
+        index = LIR_OprFact::illegalOpr;
+        offset += off.result()->as_jint();
+      }
+      LIR_Opr base_op = buf.result();
+
+      if (index->is_valid()) {
+        LIR_Opr tmp = new_register(T_LONG);
+        __ convert(Bytecodes::_i2l, index, tmp);
+        index = tmp;
+      }
+
+      LIR_Address* a = new LIR_Address(base_op, index, offset, T_BYTE);
+
+      BasicTypeList signature(3);
+      signature.append(T_INT);
+      signature.append(T_ADDRESS);
+      signature.append(T_INT);
+      CallingConvention* cc = frame_map()->c_calling_convention(&signature);
+      const LIR_Opr result_reg = result_register_for (x->type());
+
+      LIR_Opr arg1 = cc->at(0);
+      LIR_Opr arg2 = cc->at(1);
+      LIR_Opr arg3 = cc->at(2);
+
+      crc.load_item_force(arg1); // We skip int->long conversion here, because CRC32C stub doesn't care about high bits.
+      __ leal(LIR_OprFact::address(a), arg2);
+      len.load_item_force(arg3); // We skip int->long conversion here, because CRC32C stub expects int.
+
+      __ call_runtime_leaf(StubRoutines::updateBytesCRC32C(), LIR_OprFact::illegalOpr, result_reg, cc->args());
+      __ move(result_reg, result);
+      break;
+    }
+    default: {
+      ShouldNotReachHere();
+    }
+  }
 }
 
 void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) {
@@ -1264,4 +1302,3 @@
 void LIRGenerator::do_vectorizedMismatch(Intrinsic* x) {
   fatal("vectorizedMismatch intrinsic is not implemented on this platform");
 }
-
--- a/hotspot/src/cpu/s390/vm/interp_masm_s390.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/interp_masm_s390.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2016 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -48,9 +48,6 @@
                             bool allow_relocation,
                             bool check_exceptions);
 
-  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);
 
@@ -58,6 +55,9 @@
   InterpreterMacroAssembler(CodeBuffer* c)
     : MacroAssembler(c) {}
 
+  virtual void check_and_handle_popframe(Register java_thread);
+  virtual void check_and_handle_earlyret(Register java_thread);
+
   void jump_to_entry(address entry, Register Rscratch);
 
   virtual void load_earlyret_value(TosState state);
--- a/hotspot/src/cpu/s390/vm/macroAssembler_s390.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/macroAssembler_s390.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1616,6 +1616,8 @@
   if (branch_target.is_bound()) {
     address branch_addr = target(branch_target);
     branch_optimized(cond, branch_addr);
+  } else if (branch_target.is_near()) {
+    z_brc(cond, branch_target);  // Caller assures that the target will be in range for z_brc.
   } else {
     z_brcl(cond, branch_target); // Let's hope target is in range. Otherwise, we will abort at patch time.
   }
@@ -1674,7 +1676,8 @@
                                                   bool     has_sign) {
   address      branch_origin = pc();
   bool         x2_imm8       = (has_sign && Immediate::is_simm8(x2)) || (!has_sign && Immediate::is_uimm8(x2));
-  bool         is_RelAddr16  = (branch_target.is_bound() &&
+  bool         is_RelAddr16  = branch_target.is_near() ||
+                               (branch_target.is_bound() &&
                                 RelAddr::is_in_range_of_RelAddr16(target(branch_target), branch_origin));
   unsigned int casenum       = (len64?2:0)+(has_sign?0:1);
 
@@ -1744,13 +1747,21 @@
                                                   Label&   branch_target,
                                                   bool     len64,
                                                   bool     has_sign) {
-  unsigned int casenum = (len64?2:0)+(has_sign?0:1);
+  unsigned int casenum = (len64 ? 2 : 0) + (has_sign ? 0 : 1);
 
   if (branch_target.is_bound()) {
     address branch_addr = target(branch_target);
     compare_and_branch_optimized(r1, r2, cond, branch_addr, len64, has_sign);
   } else {
-    {
+    if (VM_Version::has_CompareBranch() && branch_target.is_near()) {
+      switch (casenum) {
+        case 0: z_crj(  r1, r2, cond, branch_target); break;
+        case 1: z_clrj( r1, r2, cond, branch_target); break;
+        case 2: z_cgrj( r1, r2, cond, branch_target); break;
+        case 3: z_clgrj(r1, r2, cond, branch_target); break;
+        default: ShouldNotReachHere(); break;
+      }
+    } else {
       switch (casenum) {
         case 0: z_cr( r1, r2); break;
         case 1: z_clr(r1, r2); break;
@@ -2741,11 +2752,11 @@
   BLOCK_COMMENT("lookup_interface_method {");
 
   // Load start of itable entries into itable_entry_addr.
-  z_llgf(vtable_len, Address(recv_klass, InstanceKlass::vtable_length_offset()));
+  z_llgf(vtable_len, Address(recv_klass, Klass::vtable_length_offset()));
   z_sllg(vtable_len, vtable_len, exact_log2(vtableEntry::size_in_bytes()));
 
   // Loop over all itable entries until desired interfaceOop(Rinterface) found.
-  const int vtable_base_offset = in_bytes(InstanceKlass::vtable_start_offset());
+  const int vtable_base_offset = in_bytes(Klass::vtable_start_offset());
 
   add2reg_with_index(itable_entry_addr,
                      vtable_base_offset + itableOffsetEntry::interface_offset_in_bytes(),
@@ -5899,8 +5910,7 @@
  * @param len   register containing number of bytes
  * @param table register pointing to CRC table
  */
-void MacroAssembler::update_byteLoop_crc32(Register crc, Register buf, Register len, Register table,
-                                           Register data, bool invertCRC) {
+void MacroAssembler::update_byteLoop_crc32(Register crc, Register buf, Register len, Register table, Register data) {
   assert_different_registers(crc, buf, len, table, data);
 
   Label L_mainLoop, L_done;
@@ -5910,20 +5920,12 @@
   z_ltr(len, len);
   z_brnh(L_done);
 
-  if (invertCRC) {
-    not_(crc, noreg, false); // ~c
-  }
-
   bind(L_mainLoop);
     z_llgc(data, Address(buf, (intptr_t)0));// Current byte of input buffer (zero extended). Avoids garbage in upper half of register.
     add2reg(buf, mainLoop_stepping);        // Advance buffer position.
     update_byte_crc32(crc, data, table);
     z_brct(len, L_mainLoop);                // Iterate.
 
-  if (invertCRC) {
-    not_(crc, noreg, false); // ~c
-  }
-
   bind(L_done);
 }
 
@@ -5940,6 +5942,7 @@
   //         c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
   //             crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
   // #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
+  // Pre-calculate (constant) column offsets, use columns 4..7 for big-endian.
   const int ix0 = 4*(4*CRC32_COLUMN_SIZE);
   const int ix1 = 5*(4*CRC32_COLUMN_SIZE);
   const int ix2 = 6*(4*CRC32_COLUMN_SIZE);
@@ -5958,17 +5961,12 @@
   rotate_then_insert(t1, t0, 56-2, 63-2, 2-16, true);  // ((c >> 16) & 0xff) << 2
   rotate_then_insert(t0, t0, 56-2, 63-2, 2-24, true);  // ((c >> 24) & 0xff) << 2
 
-  // Load pre-calculated table values.
-  // Use columns 4..7 for big-endian.
-  z_ly(t3, Address(table, t3, (intptr_t)ix0));
+  // XOR indexed table values to calculate updated crc.
   z_ly(t2, Address(table, t2, (intptr_t)ix1));
-  z_ly(t1, Address(table, t1, (intptr_t)ix2));
   z_ly(t0, Address(table, t0, (intptr_t)ix3));
-
-  // Calculate new crc from table values.
-  z_xr(t2, t3);
-  z_xr(t0, t1);
-  z_xr(t0, t2);  // Now crc contains the final checksum value.
+  z_xy(t2, Address(table, t3, (intptr_t)ix0));
+  z_xy(t0, Address(table, t1, (intptr_t)ix2));
+  z_xr(t0, t2);           // Now t0 contains the updated CRC value.
   lgr_if_needed(crc, t0);
 }
 
@@ -5981,7 +5979,8 @@
  * uses Z_R10..Z_R13 as work register. Must be saved/restored by caller!
  */
 void MacroAssembler::kernel_crc32_2word(Register crc, Register buf, Register len, Register table,
-                                        Register t0,  Register t1,  Register t2,  Register t3) {
+                                        Register t0,  Register t1,  Register t2,  Register t3,
+                                        bool invertCRC) {
   assert_different_registers(crc, buf, len, table);
 
   Label L_mainLoop, L_tail;
@@ -5996,7 +5995,9 @@
   // The situation itself is detected and handled correctly by the conditional branches
   // following aghi(len, -stepping) and aghi(len, +stepping).
 
-  not_(crc, noreg, false);             // 1s complement of crc
+  if (invertCRC) {
+    not_(crc, noreg, false);           // 1s complement of crc
+  }
 
 #if 0
   {
@@ -6011,7 +6012,7 @@
     rotate_then_insert(ctr, ctr, 62, 63, 0, true); // TODO: should set cc
     z_sgfr(len, ctr);                  // Remaining len after alignment.
 
-    update_byteLoop_crc32(crc, buf, ctr, table, data, false);
+    update_byteLoop_crc32(crc, buf, ctr, table, data);
   }
 #endif
 
@@ -6019,21 +6020,23 @@
   z_srag(ctr, len, log_stepping);
   z_brnh(L_tail);
 
-  z_lrvr(crc, crc);             // Revert byte order because we are dealing with big-endian data.
+  z_lrvr(crc, crc);          // Revert byte order because we are dealing with big-endian data.
   rotate_then_insert(len, len, 64-log_stepping, 63, 0, true); // #bytes for tailLoop
 
   BIND(L_mainLoop);
     update_1word_crc32(crc, buf, table, 0, 0, crc, t1, t2, t3);
     update_1word_crc32(crc, buf, table, 4, mainLoop_stepping, crc, t1, t2, t3);
-    z_brct(ctr, L_mainLoop);    // Iterate.
-
-  z_lrvr(crc, crc);        // Revert byte order back to original.
+    z_brct(ctr, L_mainLoop); // Iterate.
+
+  z_lrvr(crc, crc);          // Revert byte order back to original.
 
   // Process last few (<8) bytes of buffer.
   BIND(L_tail);
-  update_byteLoop_crc32(crc, buf, len, table, data, false);
-
-  not_(crc, noreg, false); // 1s complement of crc
+  update_byteLoop_crc32(crc, buf, len, table, data);
+
+  if (invertCRC) {
+    not_(crc, noreg, false);           // 1s complement of crc
+  }
 }
 
 /**
@@ -6045,7 +6048,8 @@
  * uses Z_R10..Z_R13 as work register. Must be saved/restored by caller!
  */
 void MacroAssembler::kernel_crc32_1word(Register crc, Register buf, Register len, Register table,
-                                        Register t0,  Register t1,  Register t2,  Register t3) {
+                                        Register t0,  Register t1,  Register t2,  Register t3,
+                                        bool invertCRC) {
   assert_different_registers(crc, buf, len, table);
 
   Label L_mainLoop, L_tail;
@@ -6059,7 +6063,9 @@
   // The situation itself is detected and handled correctly by the conditional branches
   // following aghi(len, -stepping) and aghi(len, +stepping).
 
-  not_(crc, noreg, false); // 1s complement of crc
+  if (invertCRC) {
+    not_(crc, noreg, false);           // 1s complement of crc
+  }
 
   // Check for short (<4 bytes) buffer.
   z_srag(ctr, len, log_stepping);
@@ -6071,13 +6077,16 @@
   BIND(L_mainLoop);
     update_1word_crc32(crc, buf, table, 0, mainLoop_stepping, crc, t1, t2, t3);
     z_brct(ctr, L_mainLoop); // Iterate.
+
   z_lrvr(crc, crc);          // Revert byte order back to original.
 
   // Process last few (<8) bytes of buffer.
   BIND(L_tail);
-  update_byteLoop_crc32(crc, buf, len, table, data, false);
-
-  not_(crc, noreg, false); // 1s complement of crc
+  update_byteLoop_crc32(crc, buf, len, table, data);
+
+  if (invertCRC) {
+    not_(crc, noreg, false);           // 1s complement of crc
+  }
 }
 
 /**
@@ -6087,22 +6096,51 @@
  * @param table register pointing to CRC table
  */
 void MacroAssembler::kernel_crc32_1byte(Register crc, Register buf, Register len, Register table,
-                                        Register t0,  Register t1,  Register t2,  Register t3) {
+                                        Register t0,  Register t1,  Register t2,  Register t3,
+                                        bool invertCRC) {
   assert_different_registers(crc, buf, len, table);
   Register data = t0;
 
-  update_byteLoop_crc32(crc, buf, len, table, data, true);
-}
-
-void MacroAssembler::kernel_crc32_singleByte(Register crc, Register buf, Register len, Register table, Register tmp) {
+  if (invertCRC) {
+    not_(crc, noreg, false);           // 1s complement of crc
+  }
+
+  update_byteLoop_crc32(crc, buf, len, table, data);
+
+  if (invertCRC) {
+    not_(crc, noreg, false);           // 1s complement of crc
+  }
+}
+
+void MacroAssembler::kernel_crc32_singleByte(Register crc, Register buf, Register len, Register table, Register tmp,
+                                             bool invertCRC) {
   assert_different_registers(crc, buf, len, table, tmp);
 
-  not_(crc, noreg, false); // ~c
+  if (invertCRC) {
+    not_(crc, noreg, false);           // 1s complement of crc
+  }
 
   z_llgc(tmp, Address(buf, (intptr_t)0));  // Current byte of input buffer (zero extended). Avoids garbage in upper half of register.
   update_byte_crc32(crc, tmp, table);
 
-  not_(crc, noreg, false); // ~c
+  if (invertCRC) {
+    not_(crc, noreg, false);           // 1s complement of crc
+  }
+}
+
+void MacroAssembler::kernel_crc32_singleByteReg(Register crc, Register val, Register table,
+                                                bool invertCRC) {
+  assert_different_registers(crc, val, table);
+
+  if (invertCRC) {
+    not_(crc, noreg, false);           // 1s complement of crc
+  }
+
+  update_byte_crc32(crc, val, table);
+
+  if (invertCRC) {
+    not_(crc, noreg, false);           // 1s complement of crc
+  }
 }
 
 //
--- a/hotspot/src/cpu/s390/vm/macroAssembler_s390.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/macroAssembler_s390.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1009,22 +1009,35 @@
                    int before = 0, int after = 0) PRODUCT_RETURN;
 
   // Emitters for CRC32 calculation.
+  // A note on invertCRC:
+  //   Unfortunately, internal representation of crc differs between CRC32 and CRC32C.
+  //   CRC32 holds it's current crc value in the externally visible representation.
+  //   CRC32C holds it's current crc value in internal format, ready for updating.
+  //   Thus, the crc value must be bit-flipped before updating it in the CRC32 case.
+  //   In the CRC32C case, it must be bit-flipped when it is given to the outside world (getValue()).
+  //   The bool invertCRC parameter indicates whether bit-flipping is required before updates.
  private:
   void fold_byte_crc32(Register crc, Register table, Register val, Register tmp);
   void fold_8bit_crc32(Register crc, Register table, Register tmp);
+  void update_byte_crc32( Register crc, Register val, Register table);
   void update_byteLoop_crc32(Register crc, Register buf, Register len, Register table,
-                             Register data, bool invertCRC);
+                             Register data);
   void update_1word_crc32(Register crc, Register buf, Register table, int bufDisp, int bufInc,
                           Register t0,  Register t1,  Register t2,  Register t3);
  public:
-  void update_byte_crc32( Register crc, Register val, Register table);
-  void kernel_crc32_singleByte(Register crc, Register buf, Register len, Register table, Register tmp);
+  void kernel_crc32_singleByteReg(Register crc, Register val, Register table,
+                                  bool invertCRC);
+  void kernel_crc32_singleByte(Register crc, Register buf, Register len, Register table, Register tmp,
+                               bool invertCRC);
   void kernel_crc32_1byte(Register crc, Register buf, Register len, Register table,
-                          Register t0,  Register t1,  Register t2,  Register t3);
+                          Register t0,  Register t1,  Register t2,  Register t3,
+                          bool invertCRC);
   void kernel_crc32_1word(Register crc, Register buf, Register len, Register table,
-                          Register t0,  Register t1,  Register t2,  Register t3);
+                          Register t0,  Register t1,  Register t2,  Register t3,
+                          bool invertCRC);
   void kernel_crc32_2word(Register crc, Register buf, Register len, Register table,
-                          Register t0,  Register t1,  Register t2,  Register t3);
+                          Register t0,  Register t1,  Register t2,  Register t3,
+                          bool invertCRC);
 
   // Emitters for BigInteger.multiplyToLen intrinsic
   // note: length of result array (zlen) is passed on the stack
--- a/hotspot/src/cpu/s390/vm/metaspaceShared_s390.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-#include "precompiled.hpp"
-#include "asm/codeBuffer.hpp"
-#include "asm/macroAssembler.inline.hpp"
-#include "memory/metaspaceShared.hpp"
-
-// Generate the self-patching vtable method:
-//
-// This method will be called (as any other Klass virtual method) with
-// the Klass itself as the first argument. Example:
-//
-//   oop obj;
-//   int size = obj->klass()->klass_part()->oop_size(this);
-//
-// for which the virtual method call is Klass::oop_size();.
-//
-// The dummy method is called with the Klass object as the first
-// operand, and an object as the second argument.
-//
-
-//=====================================================================
-
-// All of the dummy methods in the vtable are essentially identical,
-// differing only by an ordinal constant, and they bear no releationship
-// to the original method which the caller intended. Also, there needs
-// to be 'vtbl_list_size' instances of the vtable in order to
-// differentiate between the 'vtable_list_size' original Klass objects.
-
-#undef __
-#define __ masm->
-
-void MetaspaceShared::generate_vtable_methods(void** vtbl_list,
-                                              void** vtable,
-                                              char** md_top,
-                                              char* md_end,
-                                              char** mc_top,
-                                              char* mc_end) {
-
-  intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*);
-  *(intptr_t *)(*md_top) = vtable_bytes;
-  *md_top += sizeof(intptr_t);
-  void** dummy_vtable = (void**)*md_top;
-  *vtable = dummy_vtable;
-  *md_top += vtable_bytes;
-
-  // Get ready to generate dummy methods.
-
-  CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top);
-  MacroAssembler* masm = new MacroAssembler(&cb);
-
-  __ unimplemented();
-}
--- a/hotspot/src/cpu/s390/vm/methodHandles_s390.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/methodHandles_s390.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2016 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -73,7 +73,7 @@
                                  const char* error_message) {
 
   InstanceKlass** klass_addr = SystemDictionary::well_known_klass_addr(klass_id);
-  KlassHandle klass = SystemDictionary::well_known_klass(klass_id);
+  KLass* klass = SystemDictionary::well_known_klass(klass_id);
 
   assert(temp_reg != Z_R0 && // Is used as base register!
          temp_reg != noreg && temp2_reg != noreg, "need valid registers!");
--- a/hotspot/src/cpu/s390/vm/s390.ad	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/s390.ad	Thu Mar 16 16:40:41 2017 -0700
@@ -6768,6 +6768,7 @@
   format %{ "SLL     $dst,$src,$nbits\t# use RISC-like SLLG also for int" %}
   ins_encode %{
     int Nbit = $nbits$$constant;
+    assert((Nbit & (BitsPerJavaInteger - 1)) == Nbit, "Check shift mask in ideal graph");
     __ z_sllg($dst$$Register, $src$$Register, Nbit & (BitsPerJavaInteger - 1), Z_R0);
   %}
   ins_pipe(pipe_class_dummy);
@@ -6841,6 +6842,7 @@
   format %{ "SRA     $dst,$src" %}
   ins_encode %{
     int Nbit = $src$$constant;
+    assert((Nbit & (BitsPerJavaInteger - 1)) == Nbit, "Check shift mask in ideal graph");
     __ z_sra($dst$$Register, Nbit & (BitsPerJavaInteger - 1), Z_R0);
   %}
   ins_pipe(pipe_class_dummy);
@@ -6893,6 +6895,7 @@
   format %{ "SRL     $dst,$src" %}
   ins_encode %{
     int Nbit = $src$$constant;
+    assert((Nbit & (BitsPerJavaInteger - 1)) == Nbit, "Check shift mask in ideal graph");
     __ z_srl($dst$$Register, Nbit & (BitsPerJavaInteger - 1), Z_R0);
   %}
   ins_pipe(pipe_class_dummy);
--- a/hotspot/src/cpu/s390/vm/stubGenerator_s390.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/stubGenerator_s390.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -623,26 +623,6 @@
 #define __ (Verbose ? (_masm->block_comment(FILE_AND_LINE),_masm):_masm)->
 #endif
 
-  //----------------------------------------------------------------------
-  // The following routine generates a subroutine to throw an asynchronous
-  // UnknownError when an unsafe access gets a fault that could not be
-  // reasonably prevented by the programmer. (Example: SIGBUS/OBJERR.)
-  //
-  // Arguments:
-  //   trapping PC: ??
-  //
-  // Results:
-  //   Posts an asynchronous exception, skips the trapping instruction.
-  //
-  address generate_handler_for_unsafe_access() {
-    StubCodeMark mark(this, "StubRoutines", "handler_for_unsafe_access");
-    {
-      address start = __ pc();
-      __ unimplemented("StubRoutines::handler_for_unsafe_access", 86);
-      return start;
-    }
-  }
-
   // Support for uint StubRoutine::zarch::partial_subtype_check(Klass
   // sub, Klass super);
   //
@@ -2330,26 +2310,25 @@
   }
 
 
-
-  // Arguments:
-  //   Z_ARG1  - int   crc
-  //   Z_ARG2  - byte* buf
-  //   Z_ARG3  - int   length (of buffer)
-  //
-  // Result:
-  //   Z_RET   - int   crc result
-  //
-  // Compute CRC32 function.
-  address generate_CRC32_updateBytes(const char* name) {
-    __ align(CodeEntryAlignment);
-    StubCodeMark mark(this, "StubRoutines", name);
-    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
+  /**
+   *  Arguments:
+   *
+   * Inputs:
+   *   Z_ARG1    - int   crc
+   *   Z_ARG2    - byte* buf
+   *   Z_ARG3    - int   length (of buffer)
+   *
+   * Result:
+   *   Z_RET     - int   crc result
+   **/
+  // Compute CRC function (generic, for all polynomials).
+  void generate_CRC_updateBytes(const char* name, Register table, bool invertCRC) {
 
     // arguments to kernel_crc32:
     Register       crc     = Z_ARG1;  // Current checksum, preset by caller or result from previous call, int.
     Register       data    = Z_ARG2;  // source byte array
     Register       dataLen = Z_ARG3;  // #bytes to process, int
-    Register       table   = Z_ARG4;  // crc table address
+//    Register       table   = Z_ARG4;  // crc table address. Preloaded and passed in by caller.
     const Register t0      = Z_R10;   // work reg for kernel* emitters
     const Register t1      = Z_R11;   // work reg for kernel* emitters
     const Register t2      = Z_R12;   // work reg for kernel* emitters
@@ -2361,16 +2340,50 @@
     // Crc used as int.
     __ z_llgfr(dataLen, dataLen);
 
-    StubRoutines::zarch::generate_load_crc_table_addr(_masm, table);
-
     __ resize_frame(-(6*8), Z_R0, true); // Resize frame to provide add'l space to spill 5 registers.
     __ z_stmg(Z_R10, Z_R13, 1*8, Z_SP);  // Spill regs 10..11 to make them available as work registers.
-    __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3);
+    __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, invertCRC);
     __ z_lmg(Z_R10, Z_R13, 1*8, Z_SP);   // Spill regs 10..11 back from stack.
     __ resize_frame(+(6*8), Z_R0, true); // Resize frame to provide add'l space to spill 5 registers.
 
     __ z_llgfr(Z_RET, crc);  // Updated crc is function result. No copying required, just zero upper 32 bits.
     __ z_br(Z_R14);          // Result already in Z_RET == Z_ARG1.
+  }
+
+
+  // Compute CRC32 function.
+  address generate_CRC32_updateBytes(const char* name) {
+    __ align(CodeEntryAlignment);
+    StubCodeMark mark(this, "StubRoutines", name);
+    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
+
+    assert(UseCRC32Intrinsics, "should not generate this stub (%s) with CRC32 intrinsics disabled", name);
+
+    BLOCK_COMMENT("CRC32_updateBytes {");
+    Register       table   = Z_ARG4;  // crc32 table address.
+    StubRoutines::zarch::generate_load_crc_table_addr(_masm, table);
+
+    generate_CRC_updateBytes(name, table, true);
+    BLOCK_COMMENT("} CRC32_updateBytes");
+
+    return __ addr_at(start_off);
+  }
+
+
+  // Compute CRC32C function.
+  address generate_CRC32C_updateBytes(const char* name) {
+    __ align(CodeEntryAlignment);
+    StubCodeMark mark(this, "StubRoutines", name);
+    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
+
+    assert(UseCRC32CIntrinsics, "should not generate this stub (%s) with CRC32C intrinsics disabled", name);
+
+    BLOCK_COMMENT("CRC32C_updateBytes {");
+    Register       table   = Z_ARG4;  // crc32c table address.
+    StubRoutines::zarch::generate_load_crc32c_table_addr(_masm, table);
+
+    generate_CRC_updateBytes(name, table, false);
+    BLOCK_COMMENT("} CRC32C_updateBytes");
 
     return __ addr_at(start_off);
   }
@@ -2441,9 +2454,13 @@
     // Entry points that are platform specific.
 
     if (UseCRC32Intrinsics) {
-      // We have no CRC32 table on z/Architecture.
-      StubRoutines::_crc_table_adr    = (address)StubRoutines::zarch::_crc_table;
-      StubRoutines::_updateBytesCRC32 = generate_CRC32_updateBytes("CRC32_updateBytes");
+      StubRoutines::_crc_table_adr     = (address)StubRoutines::zarch::_crc_table;
+      StubRoutines::_updateBytesCRC32  = generate_CRC32_updateBytes("CRC32_updateBytes");
+    }
+
+    if (UseCRC32CIntrinsics) {
+      StubRoutines::_crc32c_table_addr = (address)StubRoutines::zarch::_crc32c_table;
+      StubRoutines::_updateBytesCRC32C = generate_CRC32C_updateBytes("CRC32C_updateBytes");
     }
 
     // Comapct string intrinsics: Translate table for string inflate intrinsic. Used by trot instruction.
@@ -2461,8 +2478,6 @@
     StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError),  false);
     StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call), false);
 
-    StubRoutines::zarch::_handler_for_unsafe_access_entry  =  generate_handler_for_unsafe_access();
-
     // Support for verify_oop (must happen after universe_init).
     StubRoutines::_verify_oop_subroutine_entry             = generate_verify_oop_subroutine();
 
--- a/hotspot/src/cpu/s390/vm/stubRoutines_s390.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/stubRoutines_s390.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,8 +33,6 @@
 // Implementation of the platform-specific part of StubRoutines - for
 // a description of how to extend it, see the stubRoutines.hpp file.
 
-address StubRoutines::zarch::_handler_for_unsafe_access_entry = NULL;
-
 address StubRoutines::zarch::_partial_subtype_check = NULL;
 
 // Comapct string intrinsics: Translate table for string inflate intrinsic. Used by trot instruction.
@@ -44,14 +42,15 @@
 
 #define __ masm->
 
-void StubRoutines::zarch::generate_load_crc_table_addr(MacroAssembler* masm, Register table) {
+void StubRoutines::zarch::generate_load_absolute_address(MacroAssembler* masm, Register table, address table_addr, uint64_t table_contents) {
+  __ load_absolute_address(table, table_addr);
 
-  __ load_absolute_address(table, StubRoutines::_crc_table_adr);
 #ifdef ASSERT
-  assert(_crc_table_adr != NULL, "CRC lookup table address must be initialized by now");
+  assert(table_addr != NULL, "CRC lookup table address must be initialized by now");
+  assert(*((uint32_t*)(table_addr+4)) == (uint32_t)table_contents, "Bad CRC lookup table: 0x%8.8x, expected 0x%8.8x", *((uint32_t*)(table_addr+4)), (uint32_t)table_contents);
   {
     Label L;
-    __ load_const_optimized(Z_R0, StubRoutines::_crc_table_adr);
+    __ load_const_optimized(Z_R0, table_addr);
     __ z_cgr(table, Z_R0);  // safety net
     __ z_bre(L);
     __ z_illtrap();
@@ -60,7 +59,7 @@
   }
   {
     Label L;
-    __ load_const_optimized(Z_R0, 0x77073096UL);
+    __ load_const_optimized(Z_R0, table_contents); // crc_table: data @ offset(4)
     __ z_cl(Z_R0, Address(table, 4));  // safety net
     __ z_bre(L);
     __ z_l(Z_R0, Address(table, 4));   // Load data from memory, we know the constant we compared against.
@@ -71,6 +70,17 @@
 #endif
 }
 
+void StubRoutines::zarch::generate_load_crc_table_addr(MacroAssembler* masm, Register table) {
+  const uint64_t table_contents = 0x77073096UL;  // required contents of table[1]
+  generate_load_absolute_address(masm, table, StubRoutines::_crc_table_adr, table_contents);
+}
+
+void StubRoutines::zarch::generate_load_crc32c_table_addr(MacroAssembler* masm, Register table) {
+  const uint64_t table_contents = 0xf26b8303UL;  // required contents of table[1]
+  generate_load_absolute_address(masm, table, StubRoutines::_crc32c_table_addr, table_contents);
+}
+
+
 // Comapct string intrinsics: Translate table for string inflate intrinsic. Used by trot instruction.
 void StubRoutines::zarch::generate_load_trot_table_addr(MacroAssembler* masm, Register table) {
 
@@ -130,440 +140,590 @@
   };
 
 
-// crc_table[] from jdk/src/share/native/java/util/zip/zlib-1.2.8/crc32.h
 juint StubRoutines::zarch::_crc_table[CRC32_TABLES][CRC32_COLUMN_SIZE] = {
-  {
-    0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
-    0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
-    0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
-    0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
-    0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
-    0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
-    0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
-    0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
-    0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
-    0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
-    0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
-    0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
-    0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
-    0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
-    0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
-    0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
-    0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
-    0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
-    0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
-    0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
-    0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
-    0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
-    0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
-    0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
-    0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
-    0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
-    0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
-    0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
-    0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
-    0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
-    0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
-    0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
-    0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
-    0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
-    0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
-    0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
-    0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
-    0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
-    0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
-    0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
-    0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
-    0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
-    0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
-    0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
-    0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
-    0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
-    0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
-    0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
-    0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
-    0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
-    0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
-    0x2d02ef8dUL
-#ifdef  CRC32_BYFOUR
-  },
-  {
-    0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
-    0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
-    0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
-    0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
-    0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
-    0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
-    0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
-    0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
-    0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
-    0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
-    0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
-    0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
-    0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
-    0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
-    0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
-    0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
-    0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
-    0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
-    0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
-    0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
-    0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
-    0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
-    0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
-    0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
-    0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
-    0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
-    0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
-    0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
-    0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
-    0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
-    0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
-    0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
-    0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
-    0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
-    0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
-    0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
-    0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
-    0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
-    0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
-    0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
-    0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
-    0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
-    0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
-    0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
-    0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
-    0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
-    0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
-    0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
-    0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
-    0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
-    0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
-    0x9324fd72UL
-  },
-  {
-    0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
-    0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
-    0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
-    0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
-    0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
-    0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
-    0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
-    0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
-    0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
-    0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
-    0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
-    0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
-    0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
-    0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
-    0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
-    0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
-    0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
-    0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
-    0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
-    0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
-    0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
-    0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
-    0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
-    0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
-    0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
-    0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
-    0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
-    0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
-    0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
-    0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
-    0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
-    0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
-    0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
-    0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
-    0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
-    0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
-    0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
-    0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
-    0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
-    0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
-    0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
-    0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
-    0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
-    0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
-    0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
-    0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
-    0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
-    0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
-    0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
-    0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
-    0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
-    0xbe9834edUL
-  },
-  {
-    0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
-    0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
-    0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
-    0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
-    0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
-    0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
-    0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
-    0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
-    0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
-    0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
-    0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
-    0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
-    0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
-    0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
-    0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
-    0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
-    0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
-    0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
-    0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
-    0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
-    0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
-    0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
-    0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
-    0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
-    0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
-    0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
-    0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
-    0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
-    0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
-    0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
-    0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
-    0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
-    0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
-    0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
-    0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
-    0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
-    0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
-    0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
-    0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
-    0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
-    0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
-    0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
-    0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
-    0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
-    0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
-    0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
-    0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
-    0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
-    0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
-    0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
-    0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
-    0xde0506f1UL
-  },
-  {
-    0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
-    0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
-    0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
-    0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
-    0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
-    0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
-    0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
-    0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
-    0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
-    0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
-    0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
-    0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
-    0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
-    0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
-    0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
-    0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
-    0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
-    0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
-    0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
-    0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
-    0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
-    0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
-    0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
-    0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
-    0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
-    0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
-    0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
-    0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
-    0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
-    0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
-    0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
-    0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
-    0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
-    0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
-    0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
-    0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
-    0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
-    0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
-    0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
-    0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
-    0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
-    0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
-    0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
-    0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
-    0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
-    0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
-    0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
-    0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
-    0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
-    0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
-    0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
-    0x8def022dUL
-  },
-  {
-    0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
-    0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
-    0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
-    0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
-    0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
-    0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
-    0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
-    0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
-    0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
-    0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
-    0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
-    0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
-    0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
-    0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
-    0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
-    0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
-    0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
-    0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
-    0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
-    0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
-    0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
-    0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
-    0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
-    0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
-    0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
-    0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
-    0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
-    0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
-    0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
-    0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
-    0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
-    0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
-    0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
-    0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
-    0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
-    0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
-    0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
-    0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
-    0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
-    0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
-    0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
-    0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
-    0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
-    0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
-    0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
-    0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
-    0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
-    0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
-    0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
-    0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
-    0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
-    0x72fd2493UL
-  },
-  {
-    0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
-    0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
-    0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
-    0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
-    0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
-    0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
-    0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
-    0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
-    0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
-    0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
-    0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
-    0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
-    0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
-    0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
-    0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
-    0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
-    0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
-    0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
-    0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
-    0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
-    0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
-    0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
-    0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
-    0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
-    0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
-    0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
-    0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
-    0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
-    0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
-    0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
-    0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
-    0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
-    0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
-    0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
-    0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
-    0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
-    0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
-    0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
-    0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
-    0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
-    0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
-    0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
-    0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
-    0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
-    0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
-    0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
-    0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
-    0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
-    0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
-    0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
-    0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
-    0xed3498beUL
-  },
-  {
-    0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
-    0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
-    0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
-    0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
-    0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
-    0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
-    0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
-    0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
-    0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
-    0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
-    0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
-    0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
-    0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
-    0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
-    0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
-    0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
-    0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
-    0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
-    0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
-    0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
-    0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
-    0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
-    0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
-    0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
-    0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
-    0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
-    0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
-    0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
-    0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
-    0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
-    0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
-    0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
-    0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
-    0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
-    0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
-    0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
-    0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
-    0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
-    0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
-    0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
-    0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
-    0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
-    0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
-    0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
-    0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
-    0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
-    0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
-    0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
-    0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
-    0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
-    0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
-    0xf10605deUL
-#endif
-  }
-};
+    /* polyBits = 7976584769 0x00000001db710641L, shifted = 0xedb88320 */
+    /* CRC32 table for single bytes, auto-generated.  DO NOT MODIFY!  */
+    /* CRC32 table 0 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U, 0x706af48fU, 0xe963a535U, 0x9e6495a3U
+      /* 8 */  , 0x0edb8832U, 0x79dcb8a4U, 0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U, 0x90bf1d91U
+      /* 16 */  , 0x1db71064U, 0x6ab020f2U, 0xf3b97148U, 0x84be41deU, 0x1adad47dU, 0x6ddde4ebU, 0xf4d4b551U, 0x83d385c7U
+      /* 24 */  , 0x136c9856U, 0x646ba8c0U, 0xfd62f97aU, 0x8a65c9ecU, 0x14015c4fU, 0x63066cd9U, 0xfa0f3d63U, 0x8d080df5U
+      /* 32 */  , 0x3b6e20c8U, 0x4c69105eU, 0xd56041e4U, 0xa2677172U, 0x3c03e4d1U, 0x4b04d447U, 0xd20d85fdU, 0xa50ab56bU
+      /* 40 */  , 0x35b5a8faU, 0x42b2986cU, 0xdbbbc9d6U, 0xacbcf940U, 0x32d86ce3U, 0x45df5c75U, 0xdcd60dcfU, 0xabd13d59U
+      /* 48 */  , 0x26d930acU, 0x51de003aU, 0xc8d75180U, 0xbfd06116U, 0x21b4f4b5U, 0x56b3c423U, 0xcfba9599U, 0xb8bda50fU
+      /* 56 */  , 0x2802b89eU, 0x5f058808U, 0xc60cd9b2U, 0xb10be924U, 0x2f6f7c87U, 0x58684c11U, 0xc1611dabU, 0xb6662d3dU
+      /* 64 */  , 0x76dc4190U, 0x01db7106U, 0x98d220bcU, 0xefd5102aU, 0x71b18589U, 0x06b6b51fU, 0x9fbfe4a5U, 0xe8b8d433U
+      /* 72 */  , 0x7807c9a2U, 0x0f00f934U, 0x9609a88eU, 0xe10e9818U, 0x7f6a0dbbU, 0x086d3d2dU, 0x91646c97U, 0xe6635c01U
+      /* 80 */  , 0x6b6b51f4U, 0x1c6c6162U, 0x856530d8U, 0xf262004eU, 0x6c0695edU, 0x1b01a57bU, 0x8208f4c1U, 0xf50fc457U
+      /* 88 */  , 0x65b0d9c6U, 0x12b7e950U, 0x8bbeb8eaU, 0xfcb9887cU, 0x62dd1ddfU, 0x15da2d49U, 0x8cd37cf3U, 0xfbd44c65U
+      /* 96 */  , 0x4db26158U, 0x3ab551ceU, 0xa3bc0074U, 0xd4bb30e2U, 0x4adfa541U, 0x3dd895d7U, 0xa4d1c46dU, 0xd3d6f4fbU
+      /* 104 */  , 0x4369e96aU, 0x346ed9fcU, 0xad678846U, 0xda60b8d0U, 0x44042d73U, 0x33031de5U, 0xaa0a4c5fU, 0xdd0d7cc9U
+      /* 112 */  , 0x5005713cU, 0x270241aaU, 0xbe0b1010U, 0xc90c2086U, 0x5768b525U, 0x206f85b3U, 0xb966d409U, 0xce61e49fU
+      /* 120 */  , 0x5edef90eU, 0x29d9c998U, 0xb0d09822U, 0xc7d7a8b4U, 0x59b33d17U, 0x2eb40d81U, 0xb7bd5c3bU, 0xc0ba6cadU
+      /* 128 */  , 0xedb88320U, 0x9abfb3b6U, 0x03b6e20cU, 0x74b1d29aU, 0xead54739U, 0x9dd277afU, 0x04db2615U, 0x73dc1683U
+      /* 136 */  , 0xe3630b12U, 0x94643b84U, 0x0d6d6a3eU, 0x7a6a5aa8U, 0xe40ecf0bU, 0x9309ff9dU, 0x0a00ae27U, 0x7d079eb1U
+      /* 144 */  , 0xf00f9344U, 0x8708a3d2U, 0x1e01f268U, 0x6906c2feU, 0xf762575dU, 0x806567cbU, 0x196c3671U, 0x6e6b06e7U
+      /* 152 */  , 0xfed41b76U, 0x89d32be0U, 0x10da7a5aU, 0x67dd4accU, 0xf9b9df6fU, 0x8ebeeff9U, 0x17b7be43U, 0x60b08ed5U
+      /* 160 */  , 0xd6d6a3e8U, 0xa1d1937eU, 0x38d8c2c4U, 0x4fdff252U, 0xd1bb67f1U, 0xa6bc5767U, 0x3fb506ddU, 0x48b2364bU
+      /* 168 */  , 0xd80d2bdaU, 0xaf0a1b4cU, 0x36034af6U, 0x41047a60U, 0xdf60efc3U, 0xa867df55U, 0x316e8eefU, 0x4669be79U
+      /* 176 */  , 0xcb61b38cU, 0xbc66831aU, 0x256fd2a0U, 0x5268e236U, 0xcc0c7795U, 0xbb0b4703U, 0x220216b9U, 0x5505262fU
+      /* 184 */  , 0xc5ba3bbeU, 0xb2bd0b28U, 0x2bb45a92U, 0x5cb36a04U, 0xc2d7ffa7U, 0xb5d0cf31U, 0x2cd99e8bU, 0x5bdeae1dU
+      /* 192 */  , 0x9b64c2b0U, 0xec63f226U, 0x756aa39cU, 0x026d930aU, 0x9c0906a9U, 0xeb0e363fU, 0x72076785U, 0x05005713U
+      /* 200 */  , 0x95bf4a82U, 0xe2b87a14U, 0x7bb12baeU, 0x0cb61b38U, 0x92d28e9bU, 0xe5d5be0dU, 0x7cdcefb7U, 0x0bdbdf21U
+      /* 208 */  , 0x86d3d2d4U, 0xf1d4e242U, 0x68ddb3f8U, 0x1fda836eU, 0x81be16cdU, 0xf6b9265bU, 0x6fb077e1U, 0x18b74777U
+      /* 216 */  , 0x88085ae6U, 0xff0f6a70U, 0x66063bcaU, 0x11010b5cU, 0x8f659effU, 0xf862ae69U, 0x616bffd3U, 0x166ccf45U
+      /* 224 */  , 0xa00ae278U, 0xd70dd2eeU, 0x4e048354U, 0x3903b3c2U, 0xa7672661U, 0xd06016f7U, 0x4969474dU, 0x3e6e77dbU
+      /* 232 */  , 0xaed16a4aU, 0xd9d65adcU, 0x40df0b66U, 0x37d83bf0U, 0xa9bcae53U, 0xdebb9ec5U, 0x47b2cf7fU, 0x30b5ffe9U
+      /* 240 */  , 0xbdbdf21cU, 0xcabac28aU, 0x53b39330U, 0x24b4a3a6U, 0xbad03605U, 0xcdd70693U, 0x54de5729U, 0x23d967bfU
+      /* 248 */  , 0xb3667a2eU, 0xc4614ab8U, 0x5d681b02U, 0x2a6f2b94U, 0xb40bbe37U, 0xc30c8ea1U, 0x5a05df1bU, 0x2d02ef8dU
+    }
+  #ifdef  CRC32_BYFOUR
+    ,
+    /* CRC32 table 1 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x191b3141U, 0x32366282U, 0x2b2d53c3U, 0x646cc504U, 0x7d77f445U, 0x565aa786U, 0x4f4196c7U
+      /* 8 */  , 0xc8d98a08U, 0xd1c2bb49U, 0xfaefe88aU, 0xe3f4d9cbU, 0xacb54f0cU, 0xb5ae7e4dU, 0x9e832d8eU, 0x87981ccfU
+      /* 16 */  , 0x4ac21251U, 0x53d92310U, 0x78f470d3U, 0x61ef4192U, 0x2eaed755U, 0x37b5e614U, 0x1c98b5d7U, 0x05838496U
+      /* 24 */  , 0x821b9859U, 0x9b00a918U, 0xb02dfadbU, 0xa936cb9aU, 0xe6775d5dU, 0xff6c6c1cU, 0xd4413fdfU, 0xcd5a0e9eU
+      /* 32 */  , 0x958424a2U, 0x8c9f15e3U, 0xa7b24620U, 0xbea97761U, 0xf1e8e1a6U, 0xe8f3d0e7U, 0xc3de8324U, 0xdac5b265U
+      /* 40 */  , 0x5d5daeaaU, 0x44469febU, 0x6f6bcc28U, 0x7670fd69U, 0x39316baeU, 0x202a5aefU, 0x0b07092cU, 0x121c386dU
+      /* 48 */  , 0xdf4636f3U, 0xc65d07b2U, 0xed705471U, 0xf46b6530U, 0xbb2af3f7U, 0xa231c2b6U, 0x891c9175U, 0x9007a034U
+      /* 56 */  , 0x179fbcfbU, 0x0e848dbaU, 0x25a9de79U, 0x3cb2ef38U, 0x73f379ffU, 0x6ae848beU, 0x41c51b7dU, 0x58de2a3cU
+      /* 64 */  , 0xf0794f05U, 0xe9627e44U, 0xc24f2d87U, 0xdb541cc6U, 0x94158a01U, 0x8d0ebb40U, 0xa623e883U, 0xbf38d9c2U
+      /* 72 */  , 0x38a0c50dU, 0x21bbf44cU, 0x0a96a78fU, 0x138d96ceU, 0x5ccc0009U, 0x45d73148U, 0x6efa628bU, 0x77e153caU
+      /* 80 */  , 0xbabb5d54U, 0xa3a06c15U, 0x888d3fd6U, 0x91960e97U, 0xded79850U, 0xc7cca911U, 0xece1fad2U, 0xf5facb93U
+      /* 88 */  , 0x7262d75cU, 0x6b79e61dU, 0x4054b5deU, 0x594f849fU, 0x160e1258U, 0x0f152319U, 0x243870daU, 0x3d23419bU
+      /* 96 */  , 0x65fd6ba7U, 0x7ce65ae6U, 0x57cb0925U, 0x4ed03864U, 0x0191aea3U, 0x188a9fe2U, 0x33a7cc21U, 0x2abcfd60U
+      /* 104 */  , 0xad24e1afU, 0xb43fd0eeU, 0x9f12832dU, 0x8609b26cU, 0xc94824abU, 0xd05315eaU, 0xfb7e4629U, 0xe2657768U
+      /* 112 */  , 0x2f3f79f6U, 0x362448b7U, 0x1d091b74U, 0x04122a35U, 0x4b53bcf2U, 0x52488db3U, 0x7965de70U, 0x607eef31U
+      /* 120 */  , 0xe7e6f3feU, 0xfefdc2bfU, 0xd5d0917cU, 0xcccba03dU, 0x838a36faU, 0x9a9107bbU, 0xb1bc5478U, 0xa8a76539U
+      /* 128 */  , 0x3b83984bU, 0x2298a90aU, 0x09b5fac9U, 0x10aecb88U, 0x5fef5d4fU, 0x46f46c0eU, 0x6dd93fcdU, 0x74c20e8cU
+      /* 136 */  , 0xf35a1243U, 0xea412302U, 0xc16c70c1U, 0xd8774180U, 0x9736d747U, 0x8e2de606U, 0xa500b5c5U, 0xbc1b8484U
+      /* 144 */  , 0x71418a1aU, 0x685abb5bU, 0x4377e898U, 0x5a6cd9d9U, 0x152d4f1eU, 0x0c367e5fU, 0x271b2d9cU, 0x3e001cddU
+      /* 152 */  , 0xb9980012U, 0xa0833153U, 0x8bae6290U, 0x92b553d1U, 0xddf4c516U, 0xc4eff457U, 0xefc2a794U, 0xf6d996d5U
+      /* 160 */  , 0xae07bce9U, 0xb71c8da8U, 0x9c31de6bU, 0x852aef2aU, 0xca6b79edU, 0xd37048acU, 0xf85d1b6fU, 0xe1462a2eU
+      /* 168 */  , 0x66de36e1U, 0x7fc507a0U, 0x54e85463U, 0x4df36522U, 0x02b2f3e5U, 0x1ba9c2a4U, 0x30849167U, 0x299fa026U
+      /* 176 */  , 0xe4c5aeb8U, 0xfdde9ff9U, 0xd6f3cc3aU, 0xcfe8fd7bU, 0x80a96bbcU, 0x99b25afdU, 0xb29f093eU, 0xab84387fU
+      /* 184 */  , 0x2c1c24b0U, 0x350715f1U, 0x1e2a4632U, 0x07317773U, 0x4870e1b4U, 0x516bd0f5U, 0x7a468336U, 0x635db277U
+      /* 192 */  , 0xcbfad74eU, 0xd2e1e60fU, 0xf9ccb5ccU, 0xe0d7848dU, 0xaf96124aU, 0xb68d230bU, 0x9da070c8U, 0x84bb4189U
+      /* 200 */  , 0x03235d46U, 0x1a386c07U, 0x31153fc4U, 0x280e0e85U, 0x674f9842U, 0x7e54a903U, 0x5579fac0U, 0x4c62cb81U
+      /* 208 */  , 0x8138c51fU, 0x9823f45eU, 0xb30ea79dU, 0xaa1596dcU, 0xe554001bU, 0xfc4f315aU, 0xd7626299U, 0xce7953d8U
+      /* 216 */  , 0x49e14f17U, 0x50fa7e56U, 0x7bd72d95U, 0x62cc1cd4U, 0x2d8d8a13U, 0x3496bb52U, 0x1fbbe891U, 0x06a0d9d0U
+      /* 224 */  , 0x5e7ef3ecU, 0x4765c2adU, 0x6c48916eU, 0x7553a02fU, 0x3a1236e8U, 0x230907a9U, 0x0824546aU, 0x113f652bU
+      /* 232 */  , 0x96a779e4U, 0x8fbc48a5U, 0xa4911b66U, 0xbd8a2a27U, 0xf2cbbce0U, 0xebd08da1U, 0xc0fdde62U, 0xd9e6ef23U
+      /* 240 */  , 0x14bce1bdU, 0x0da7d0fcU, 0x268a833fU, 0x3f91b27eU, 0x70d024b9U, 0x69cb15f8U, 0x42e6463bU, 0x5bfd777aU
+      /* 248 */  , 0xdc656bb5U, 0xc57e5af4U, 0xee530937U, 0xf7483876U, 0xb809aeb1U, 0xa1129ff0U, 0x8a3fcc33U, 0x9324fd72U
+    }
+    ,
+    /* CRC32 table 2 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x01c26a37U, 0x0384d46eU, 0x0246be59U, 0x0709a8dcU, 0x06cbc2ebU, 0x048d7cb2U, 0x054f1685U
+      /* 8 */  , 0x0e1351b8U, 0x0fd13b8fU, 0x0d9785d6U, 0x0c55efe1U, 0x091af964U, 0x08d89353U, 0x0a9e2d0aU, 0x0b5c473dU
+      /* 16 */  , 0x1c26a370U, 0x1de4c947U, 0x1fa2771eU, 0x1e601d29U, 0x1b2f0bacU, 0x1aed619bU, 0x18abdfc2U, 0x1969b5f5U
+      /* 24 */  , 0x1235f2c8U, 0x13f798ffU, 0x11b126a6U, 0x10734c91U, 0x153c5a14U, 0x14fe3023U, 0x16b88e7aU, 0x177ae44dU
+      /* 32 */  , 0x384d46e0U, 0x398f2cd7U, 0x3bc9928eU, 0x3a0bf8b9U, 0x3f44ee3cU, 0x3e86840bU, 0x3cc03a52U, 0x3d025065U
+      /* 40 */  , 0x365e1758U, 0x379c7d6fU, 0x35dac336U, 0x3418a901U, 0x3157bf84U, 0x3095d5b3U, 0x32d36beaU, 0x331101ddU
+      /* 48 */  , 0x246be590U, 0x25a98fa7U, 0x27ef31feU, 0x262d5bc9U, 0x23624d4cU, 0x22a0277bU, 0x20e69922U, 0x2124f315U
+      /* 56 */  , 0x2a78b428U, 0x2bbade1fU, 0x29fc6046U, 0x283e0a71U, 0x2d711cf4U, 0x2cb376c3U, 0x2ef5c89aU, 0x2f37a2adU
+      /* 64 */  , 0x709a8dc0U, 0x7158e7f7U, 0x731e59aeU, 0x72dc3399U, 0x7793251cU, 0x76514f2bU, 0x7417f172U, 0x75d59b45U
+      /* 72 */  , 0x7e89dc78U, 0x7f4bb64fU, 0x7d0d0816U, 0x7ccf6221U, 0x798074a4U, 0x78421e93U, 0x7a04a0caU, 0x7bc6cafdU
+      /* 80 */  , 0x6cbc2eb0U, 0x6d7e4487U, 0x6f38fadeU, 0x6efa90e9U, 0x6bb5866cU, 0x6a77ec5bU, 0x68315202U, 0x69f33835U
+      /* 88 */  , 0x62af7f08U, 0x636d153fU, 0x612bab66U, 0x60e9c151U, 0x65a6d7d4U, 0x6464bde3U, 0x662203baU, 0x67e0698dU
+      /* 96 */  , 0x48d7cb20U, 0x4915a117U, 0x4b531f4eU, 0x4a917579U, 0x4fde63fcU, 0x4e1c09cbU, 0x4c5ab792U, 0x4d98dda5U
+      /* 104 */  , 0x46c49a98U, 0x4706f0afU, 0x45404ef6U, 0x448224c1U, 0x41cd3244U, 0x400f5873U, 0x4249e62aU, 0x438b8c1dU
+      /* 112 */  , 0x54f16850U, 0x55330267U, 0x5775bc3eU, 0x56b7d609U, 0x53f8c08cU, 0x523aaabbU, 0x507c14e2U, 0x51be7ed5U
+      /* 120 */  , 0x5ae239e8U, 0x5b2053dfU, 0x5966ed86U, 0x58a487b1U, 0x5deb9134U, 0x5c29fb03U, 0x5e6f455aU, 0x5fad2f6dU
+      /* 128 */  , 0xe1351b80U, 0xe0f771b7U, 0xe2b1cfeeU, 0xe373a5d9U, 0xe63cb35cU, 0xe7fed96bU, 0xe5b86732U, 0xe47a0d05U
+      /* 136 */  , 0xef264a38U, 0xeee4200fU, 0xeca29e56U, 0xed60f461U, 0xe82fe2e4U, 0xe9ed88d3U, 0xebab368aU, 0xea695cbdU
+      /* 144 */  , 0xfd13b8f0U, 0xfcd1d2c7U, 0xfe976c9eU, 0xff5506a9U, 0xfa1a102cU, 0xfbd87a1bU, 0xf99ec442U, 0xf85cae75U
+      /* 152 */  , 0xf300e948U, 0xf2c2837fU, 0xf0843d26U, 0xf1465711U, 0xf4094194U, 0xf5cb2ba3U, 0xf78d95faU, 0xf64fffcdU
+      /* 160 */  , 0xd9785d60U, 0xd8ba3757U, 0xdafc890eU, 0xdb3ee339U, 0xde71f5bcU, 0xdfb39f8bU, 0xddf521d2U, 0xdc374be5U
+      /* 168 */  , 0xd76b0cd8U, 0xd6a966efU, 0xd4efd8b6U, 0xd52db281U, 0xd062a404U, 0xd1a0ce33U, 0xd3e6706aU, 0xd2241a5dU
+      /* 176 */  , 0xc55efe10U, 0xc49c9427U, 0xc6da2a7eU, 0xc7184049U, 0xc25756ccU, 0xc3953cfbU, 0xc1d382a2U, 0xc011e895U
+      /* 184 */  , 0xcb4dafa8U, 0xca8fc59fU, 0xc8c97bc6U, 0xc90b11f1U, 0xcc440774U, 0xcd866d43U, 0xcfc0d31aU, 0xce02b92dU
+      /* 192 */  , 0x91af9640U, 0x906dfc77U, 0x922b422eU, 0x93e92819U, 0x96a63e9cU, 0x976454abU, 0x9522eaf2U, 0x94e080c5U
+      /* 200 */  , 0x9fbcc7f8U, 0x9e7eadcfU, 0x9c381396U, 0x9dfa79a1U, 0x98b56f24U, 0x99770513U, 0x9b31bb4aU, 0x9af3d17dU
+      /* 208 */  , 0x8d893530U, 0x8c4b5f07U, 0x8e0de15eU, 0x8fcf8b69U, 0x8a809decU, 0x8b42f7dbU, 0x89044982U, 0x88c623b5U
+      /* 216 */  , 0x839a6488U, 0x82580ebfU, 0x801eb0e6U, 0x81dcdad1U, 0x8493cc54U, 0x8551a663U, 0x8717183aU, 0x86d5720dU
+      /* 224 */  , 0xa9e2d0a0U, 0xa820ba97U, 0xaa6604ceU, 0xaba46ef9U, 0xaeeb787cU, 0xaf29124bU, 0xad6fac12U, 0xacadc625U
+      /* 232 */  , 0xa7f18118U, 0xa633eb2fU, 0xa4755576U, 0xa5b73f41U, 0xa0f829c4U, 0xa13a43f3U, 0xa37cfdaaU, 0xa2be979dU
+      /* 240 */  , 0xb5c473d0U, 0xb40619e7U, 0xb640a7beU, 0xb782cd89U, 0xb2cddb0cU, 0xb30fb13bU, 0xb1490f62U, 0xb08b6555U
+      /* 248 */  , 0xbbd72268U, 0xba15485fU, 0xb853f606U, 0xb9919c31U, 0xbcde8ab4U, 0xbd1ce083U, 0xbf5a5edaU, 0xbe9834edU
+    }
+    ,
+    /* CRC32 table 3 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0xb8bc6765U, 0xaa09c88bU, 0x12b5afeeU, 0x8f629757U, 0x37def032U, 0x256b5fdcU, 0x9dd738b9U
+      /* 8 */  , 0xc5b428efU, 0x7d084f8aU, 0x6fbde064U, 0xd7018701U, 0x4ad6bfb8U, 0xf26ad8ddU, 0xe0df7733U, 0x58631056U
+      /* 16 */  , 0x5019579fU, 0xe8a530faU, 0xfa109f14U, 0x42acf871U, 0xdf7bc0c8U, 0x67c7a7adU, 0x75720843U, 0xcdce6f26U
+      /* 24 */  , 0x95ad7f70U, 0x2d111815U, 0x3fa4b7fbU, 0x8718d09eU, 0x1acfe827U, 0xa2738f42U, 0xb0c620acU, 0x087a47c9U
+      /* 32 */  , 0xa032af3eU, 0x188ec85bU, 0x0a3b67b5U, 0xb28700d0U, 0x2f503869U, 0x97ec5f0cU, 0x8559f0e2U, 0x3de59787U
+      /* 40 */  , 0x658687d1U, 0xdd3ae0b4U, 0xcf8f4f5aU, 0x7733283fU, 0xeae41086U, 0x525877e3U, 0x40edd80dU, 0xf851bf68U
+      /* 48 */  , 0xf02bf8a1U, 0x48979fc4U, 0x5a22302aU, 0xe29e574fU, 0x7f496ff6U, 0xc7f50893U, 0xd540a77dU, 0x6dfcc018U
+      /* 56 */  , 0x359fd04eU, 0x8d23b72bU, 0x9f9618c5U, 0x272a7fa0U, 0xbafd4719U, 0x0241207cU, 0x10f48f92U, 0xa848e8f7U
+      /* 64 */  , 0x9b14583dU, 0x23a83f58U, 0x311d90b6U, 0x89a1f7d3U, 0x1476cf6aU, 0xaccaa80fU, 0xbe7f07e1U, 0x06c36084U
+      /* 72 */  , 0x5ea070d2U, 0xe61c17b7U, 0xf4a9b859U, 0x4c15df3cU, 0xd1c2e785U, 0x697e80e0U, 0x7bcb2f0eU, 0xc377486bU
+      /* 80 */  , 0xcb0d0fa2U, 0x73b168c7U, 0x6104c729U, 0xd9b8a04cU, 0x446f98f5U, 0xfcd3ff90U, 0xee66507eU, 0x56da371bU
+      /* 88 */  , 0x0eb9274dU, 0xb6054028U, 0xa4b0efc6U, 0x1c0c88a3U, 0x81dbb01aU, 0x3967d77fU, 0x2bd27891U, 0x936e1ff4U
+      /* 96 */  , 0x3b26f703U, 0x839a9066U, 0x912f3f88U, 0x299358edU, 0xb4446054U, 0x0cf80731U, 0x1e4da8dfU, 0xa6f1cfbaU
+      /* 104 */  , 0xfe92dfecU, 0x462eb889U, 0x549b1767U, 0xec277002U, 0x71f048bbU, 0xc94c2fdeU, 0xdbf98030U, 0x6345e755U
+      /* 112 */  , 0x6b3fa09cU, 0xd383c7f9U, 0xc1366817U, 0x798a0f72U, 0xe45d37cbU, 0x5ce150aeU, 0x4e54ff40U, 0xf6e89825U
+      /* 120 */  , 0xae8b8873U, 0x1637ef16U, 0x048240f8U, 0xbc3e279dU, 0x21e91f24U, 0x99557841U, 0x8be0d7afU, 0x335cb0caU
+      /* 128 */  , 0xed59b63bU, 0x55e5d15eU, 0x47507eb0U, 0xffec19d5U, 0x623b216cU, 0xda874609U, 0xc832e9e7U, 0x708e8e82U
+      /* 136 */  , 0x28ed9ed4U, 0x9051f9b1U, 0x82e4565fU, 0x3a58313aU, 0xa78f0983U, 0x1f336ee6U, 0x0d86c108U, 0xb53aa66dU
+      /* 144 */  , 0xbd40e1a4U, 0x05fc86c1U, 0x1749292fU, 0xaff54e4aU, 0x322276f3U, 0x8a9e1196U, 0x982bbe78U, 0x2097d91dU
+      /* 152 */  , 0x78f4c94bU, 0xc048ae2eU, 0xd2fd01c0U, 0x6a4166a5U, 0xf7965e1cU, 0x4f2a3979U, 0x5d9f9697U, 0xe523f1f2U
+      /* 160 */  , 0x4d6b1905U, 0xf5d77e60U, 0xe762d18eU, 0x5fdeb6ebU, 0xc2098e52U, 0x7ab5e937U, 0x680046d9U, 0xd0bc21bcU
+      /* 168 */  , 0x88df31eaU, 0x3063568fU, 0x22d6f961U, 0x9a6a9e04U, 0x07bda6bdU, 0xbf01c1d8U, 0xadb46e36U, 0x15080953U
+      /* 176 */  , 0x1d724e9aU, 0xa5ce29ffU, 0xb77b8611U, 0x0fc7e174U, 0x9210d9cdU, 0x2aacbea8U, 0x38191146U, 0x80a57623U
+      /* 184 */  , 0xd8c66675U, 0x607a0110U, 0x72cfaefeU, 0xca73c99bU, 0x57a4f122U, 0xef189647U, 0xfdad39a9U, 0x45115eccU
+      /* 192 */  , 0x764dee06U, 0xcef18963U, 0xdc44268dU, 0x64f841e8U, 0xf92f7951U, 0x41931e34U, 0x5326b1daU, 0xeb9ad6bfU
+      /* 200 */  , 0xb3f9c6e9U, 0x0b45a18cU, 0x19f00e62U, 0xa14c6907U, 0x3c9b51beU, 0x842736dbU, 0x96929935U, 0x2e2efe50U
+      /* 208 */  , 0x2654b999U, 0x9ee8defcU, 0x8c5d7112U, 0x34e11677U, 0xa9362eceU, 0x118a49abU, 0x033fe645U, 0xbb838120U
+      /* 216 */  , 0xe3e09176U, 0x5b5cf613U, 0x49e959fdU, 0xf1553e98U, 0x6c820621U, 0xd43e6144U, 0xc68bceaaU, 0x7e37a9cfU
+      /* 224 */  , 0xd67f4138U, 0x6ec3265dU, 0x7c7689b3U, 0xc4caeed6U, 0x591dd66fU, 0xe1a1b10aU, 0xf3141ee4U, 0x4ba87981U
+      /* 232 */  , 0x13cb69d7U, 0xab770eb2U, 0xb9c2a15cU, 0x017ec639U, 0x9ca9fe80U, 0x241599e5U, 0x36a0360bU, 0x8e1c516eU
+      /* 240 */  , 0x866616a7U, 0x3eda71c2U, 0x2c6fde2cU, 0x94d3b949U, 0x090481f0U, 0xb1b8e695U, 0xa30d497bU, 0x1bb12e1eU
+      /* 248 */  , 0x43d23e48U, 0xfb6e592dU, 0xe9dbf6c3U, 0x516791a6U, 0xccb0a91fU, 0x740cce7aU, 0x66b96194U, 0xde0506f1U
+    }
+    ,
+    /* CRC32 table 4 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x96300777U, 0x2c610eeeU, 0xba510999U, 0x19c46d07U, 0x8ff46a70U, 0x35a563e9U, 0xa395649eU
+      /* 8 */  , 0x3288db0eU, 0xa4b8dc79U, 0x1ee9d5e0U, 0x88d9d297U, 0x2b4cb609U, 0xbd7cb17eU, 0x072db8e7U, 0x911dbf90U
+      /* 16 */  , 0x6410b71dU, 0xf220b06aU, 0x4871b9f3U, 0xde41be84U, 0x7dd4da1aU, 0xebe4dd6dU, 0x51b5d4f4U, 0xc785d383U
+      /* 24 */  , 0x56986c13U, 0xc0a86b64U, 0x7af962fdU, 0xecc9658aU, 0x4f5c0114U, 0xd96c0663U, 0x633d0ffaU, 0xf50d088dU
+      /* 32 */  , 0xc8206e3bU, 0x5e10694cU, 0xe44160d5U, 0x727167a2U, 0xd1e4033cU, 0x47d4044bU, 0xfd850dd2U, 0x6bb50aa5U
+      /* 40 */  , 0xfaa8b535U, 0x6c98b242U, 0xd6c9bbdbU, 0x40f9bcacU, 0xe36cd832U, 0x755cdf45U, 0xcf0dd6dcU, 0x593dd1abU
+      /* 48 */  , 0xac30d926U, 0x3a00de51U, 0x8051d7c8U, 0x1661d0bfU, 0xb5f4b421U, 0x23c4b356U, 0x9995bacfU, 0x0fa5bdb8U
+      /* 56 */  , 0x9eb80228U, 0x0888055fU, 0xb2d90cc6U, 0x24e90bb1U, 0x877c6f2fU, 0x114c6858U, 0xab1d61c1U, 0x3d2d66b6U
+      /* 64 */  , 0x9041dc76U, 0x0671db01U, 0xbc20d298U, 0x2a10d5efU, 0x8985b171U, 0x1fb5b606U, 0xa5e4bf9fU, 0x33d4b8e8U
+      /* 72 */  , 0xa2c90778U, 0x34f9000fU, 0x8ea80996U, 0x18980ee1U, 0xbb0d6a7fU, 0x2d3d6d08U, 0x976c6491U, 0x015c63e6U
+      /* 80 */  , 0xf4516b6bU, 0x62616c1cU, 0xd8306585U, 0x4e0062f2U, 0xed95066cU, 0x7ba5011bU, 0xc1f40882U, 0x57c40ff5U
+      /* 88 */  , 0xc6d9b065U, 0x50e9b712U, 0xeab8be8bU, 0x7c88b9fcU, 0xdf1ddd62U, 0x492dda15U, 0xf37cd38cU, 0x654cd4fbU
+      /* 96 */  , 0x5861b24dU, 0xce51b53aU, 0x7400bca3U, 0xe230bbd4U, 0x41a5df4aU, 0xd795d83dU, 0x6dc4d1a4U, 0xfbf4d6d3U
+      /* 104 */  , 0x6ae96943U, 0xfcd96e34U, 0x468867adU, 0xd0b860daU, 0x732d0444U, 0xe51d0333U, 0x5f4c0aaaU, 0xc97c0dddU
+      /* 112 */  , 0x3c710550U, 0xaa410227U, 0x10100bbeU, 0x86200cc9U, 0x25b56857U, 0xb3856f20U, 0x09d466b9U, 0x9fe461ceU
+      /* 120 */  , 0x0ef9de5eU, 0x98c9d929U, 0x2298d0b0U, 0xb4a8d7c7U, 0x173db359U, 0x810db42eU, 0x3b5cbdb7U, 0xad6cbac0U
+      /* 128 */  , 0x2083b8edU, 0xb6b3bf9aU, 0x0ce2b603U, 0x9ad2b174U, 0x3947d5eaU, 0xaf77d29dU, 0x1526db04U, 0x8316dc73U
+      /* 136 */  , 0x120b63e3U, 0x843b6494U, 0x3e6a6d0dU, 0xa85a6a7aU, 0x0bcf0ee4U, 0x9dff0993U, 0x27ae000aU, 0xb19e077dU
+      /* 144 */  , 0x44930ff0U, 0xd2a30887U, 0x68f2011eU, 0xfec20669U, 0x5d5762f7U, 0xcb676580U, 0x71366c19U, 0xe7066b6eU
+      /* 152 */  , 0x761bd4feU, 0xe02bd389U, 0x5a7ada10U, 0xcc4add67U, 0x6fdfb9f9U, 0xf9efbe8eU, 0x43beb717U, 0xd58eb060U
+      /* 160 */  , 0xe8a3d6d6U, 0x7e93d1a1U, 0xc4c2d838U, 0x52f2df4fU, 0xf167bbd1U, 0x6757bca6U, 0xdd06b53fU, 0x4b36b248U
+      /* 168 */  , 0xda2b0dd8U, 0x4c1b0aafU, 0xf64a0336U, 0x607a0441U, 0xc3ef60dfU, 0x55df67a8U, 0xef8e6e31U, 0x79be6946U
+      /* 176 */  , 0x8cb361cbU, 0x1a8366bcU, 0xa0d26f25U, 0x36e26852U, 0x95770cccU, 0x03470bbbU, 0xb9160222U, 0x2f260555U
+      /* 184 */  , 0xbe3bbac5U, 0x280bbdb2U, 0x925ab42bU, 0x046ab35cU, 0xa7ffd7c2U, 0x31cfd0b5U, 0x8b9ed92cU, 0x1daede5bU
+      /* 192 */  , 0xb0c2649bU, 0x26f263ecU, 0x9ca36a75U, 0x0a936d02U, 0xa906099cU, 0x3f360eebU, 0x85670772U, 0x13570005U
+      /* 200 */  , 0x824abf95U, 0x147ab8e2U, 0xae2bb17bU, 0x381bb60cU, 0x9b8ed292U, 0x0dbed5e5U, 0xb7efdc7cU, 0x21dfdb0bU
+      /* 208 */  , 0xd4d2d386U, 0x42e2d4f1U, 0xf8b3dd68U, 0x6e83da1fU, 0xcd16be81U, 0x5b26b9f6U, 0xe177b06fU, 0x7747b718U
+      /* 216 */  , 0xe65a0888U, 0x706a0fffU, 0xca3b0666U, 0x5c0b0111U, 0xff9e658fU, 0x69ae62f8U, 0xd3ff6b61U, 0x45cf6c16U
+      /* 224 */  , 0x78e20aa0U, 0xeed20dd7U, 0x5483044eU, 0xc2b30339U, 0x612667a7U, 0xf71660d0U, 0x4d476949U, 0xdb776e3eU
+      /* 232 */  , 0x4a6ad1aeU, 0xdc5ad6d9U, 0x660bdf40U, 0xf03bd837U, 0x53aebca9U, 0xc59ebbdeU, 0x7fcfb247U, 0xe9ffb530U
+      /* 240 */  , 0x1cf2bdbdU, 0x8ac2bacaU, 0x3093b353U, 0xa6a3b424U, 0x0536d0baU, 0x9306d7cdU, 0x2957de54U, 0xbf67d923U
+      /* 248 */  , 0x2e7a66b3U, 0xb84a61c4U, 0x021b685dU, 0x942b6f2aU, 0x37be0bb4U, 0xa18e0cc3U, 0x1bdf055aU, 0x8def022dU
+    }
+    ,
+    /* CRC32 table 5 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x41311b19U, 0x82623632U, 0xc3532d2bU, 0x04c56c64U, 0x45f4777dU, 0x86a75a56U, 0xc796414fU
+      /* 8 */  , 0x088ad9c8U, 0x49bbc2d1U, 0x8ae8effaU, 0xcbd9f4e3U, 0x0c4fb5acU, 0x4d7eaeb5U, 0x8e2d839eU, 0xcf1c9887U
+      /* 16 */  , 0x5112c24aU, 0x1023d953U, 0xd370f478U, 0x9241ef61U, 0x55d7ae2eU, 0x14e6b537U, 0xd7b5981cU, 0x96848305U
+      /* 24 */  , 0x59981b82U, 0x18a9009bU, 0xdbfa2db0U, 0x9acb36a9U, 0x5d5d77e6U, 0x1c6c6cffU, 0xdf3f41d4U, 0x9e0e5acdU
+      /* 32 */  , 0xa2248495U, 0xe3159f8cU, 0x2046b2a7U, 0x6177a9beU, 0xa6e1e8f1U, 0xe7d0f3e8U, 0x2483dec3U, 0x65b2c5daU
+      /* 40 */  , 0xaaae5d5dU, 0xeb9f4644U, 0x28cc6b6fU, 0x69fd7076U, 0xae6b3139U, 0xef5a2a20U, 0x2c09070bU, 0x6d381c12U
+      /* 48 */  , 0xf33646dfU, 0xb2075dc6U, 0x715470edU, 0x30656bf4U, 0xf7f32abbU, 0xb6c231a2U, 0x75911c89U, 0x34a00790U
+      /* 56 */  , 0xfbbc9f17U, 0xba8d840eU, 0x79dea925U, 0x38efb23cU, 0xff79f373U, 0xbe48e86aU, 0x7d1bc541U, 0x3c2ade58U
+      /* 64 */  , 0x054f79f0U, 0x447e62e9U, 0x872d4fc2U, 0xc61c54dbU, 0x018a1594U, 0x40bb0e8dU, 0x83e823a6U, 0xc2d938bfU
+      /* 72 */  , 0x0dc5a038U, 0x4cf4bb21U, 0x8fa7960aU, 0xce968d13U, 0x0900cc5cU, 0x4831d745U, 0x8b62fa6eU, 0xca53e177U
+      /* 80 */  , 0x545dbbbaU, 0x156ca0a3U, 0xd63f8d88U, 0x970e9691U, 0x5098d7deU, 0x11a9ccc7U, 0xd2fae1ecU, 0x93cbfaf5U
+      /* 88 */  , 0x5cd76272U, 0x1de6796bU, 0xdeb55440U, 0x9f844f59U, 0x58120e16U, 0x1923150fU, 0xda703824U, 0x9b41233dU
+      /* 96 */  , 0xa76bfd65U, 0xe65ae67cU, 0x2509cb57U, 0x6438d04eU, 0xa3ae9101U, 0xe29f8a18U, 0x21cca733U, 0x60fdbc2aU
+      /* 104 */  , 0xafe124adU, 0xeed03fb4U, 0x2d83129fU, 0x6cb20986U, 0xab2448c9U, 0xea1553d0U, 0x29467efbU, 0x687765e2U
+      /* 112 */  , 0xf6793f2fU, 0xb7482436U, 0x741b091dU, 0x352a1204U, 0xf2bc534bU, 0xb38d4852U, 0x70de6579U, 0x31ef7e60U
+      /* 120 */  , 0xfef3e6e7U, 0xbfc2fdfeU, 0x7c91d0d5U, 0x3da0cbccU, 0xfa368a83U, 0xbb07919aU, 0x7854bcb1U, 0x3965a7a8U
+      /* 128 */  , 0x4b98833bU, 0x0aa99822U, 0xc9fab509U, 0x88cbae10U, 0x4f5def5fU, 0x0e6cf446U, 0xcd3fd96dU, 0x8c0ec274U
+      /* 136 */  , 0x43125af3U, 0x022341eaU, 0xc1706cc1U, 0x804177d8U, 0x47d73697U, 0x06e62d8eU, 0xc5b500a5U, 0x84841bbcU
+      /* 144 */  , 0x1a8a4171U, 0x5bbb5a68U, 0x98e87743U, 0xd9d96c5aU, 0x1e4f2d15U, 0x5f7e360cU, 0x9c2d1b27U, 0xdd1c003eU
+      /* 152 */  , 0x120098b9U, 0x533183a0U, 0x9062ae8bU, 0xd153b592U, 0x16c5f4ddU, 0x57f4efc4U, 0x94a7c2efU, 0xd596d9f6U
+      /* 160 */  , 0xe9bc07aeU, 0xa88d1cb7U, 0x6bde319cU, 0x2aef2a85U, 0xed796bcaU, 0xac4870d3U, 0x6f1b5df8U, 0x2e2a46e1U
+      /* 168 */  , 0xe136de66U, 0xa007c57fU, 0x6354e854U, 0x2265f34dU, 0xe5f3b202U, 0xa4c2a91bU, 0x67918430U, 0x26a09f29U
+      /* 176 */  , 0xb8aec5e4U, 0xf99fdefdU, 0x3accf3d6U, 0x7bfde8cfU, 0xbc6ba980U, 0xfd5ab299U, 0x3e099fb2U, 0x7f3884abU
+      /* 184 */  , 0xb0241c2cU, 0xf1150735U, 0x32462a1eU, 0x73773107U, 0xb4e17048U, 0xf5d06b51U, 0x3683467aU, 0x77b25d63U
+      /* 192 */  , 0x4ed7facbU, 0x0fe6e1d2U, 0xccb5ccf9U, 0x8d84d7e0U, 0x4a1296afU, 0x0b238db6U, 0xc870a09dU, 0x8941bb84U
+      /* 200 */  , 0x465d2303U, 0x076c381aU, 0xc43f1531U, 0x850e0e28U, 0x42984f67U, 0x03a9547eU, 0xc0fa7955U, 0x81cb624cU
+      /* 208 */  , 0x1fc53881U, 0x5ef42398U, 0x9da70eb3U, 0xdc9615aaU, 0x1b0054e5U, 0x5a314ffcU, 0x996262d7U, 0xd85379ceU
+      /* 216 */  , 0x174fe149U, 0x567efa50U, 0x952dd77bU, 0xd41ccc62U, 0x138a8d2dU, 0x52bb9634U, 0x91e8bb1fU, 0xd0d9a006U
+      /* 224 */  , 0xecf37e5eU, 0xadc26547U, 0x6e91486cU, 0x2fa05375U, 0xe836123aU, 0xa9070923U, 0x6a542408U, 0x2b653f11U
+      /* 232 */  , 0xe479a796U, 0xa548bc8fU, 0x661b91a4U, 0x272a8abdU, 0xe0bccbf2U, 0xa18dd0ebU, 0x62defdc0U, 0x23efe6d9U
+      /* 240 */  , 0xbde1bc14U, 0xfcd0a70dU, 0x3f838a26U, 0x7eb2913fU, 0xb924d070U, 0xf815cb69U, 0x3b46e642U, 0x7a77fd5bU
+      /* 248 */  , 0xb56b65dcU, 0xf45a7ec5U, 0x370953eeU, 0x763848f7U, 0xb1ae09b8U, 0xf09f12a1U, 0x33cc3f8aU, 0x72fd2493U
+    }
+    ,
+    /* CRC32 table 6 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x376ac201U, 0x6ed48403U, 0x59be4602U, 0xdca80907U, 0xebc2cb06U, 0xb27c8d04U, 0x85164f05U
+      /* 8 */  , 0xb851130eU, 0x8f3bd10fU, 0xd685970dU, 0xe1ef550cU, 0x64f91a09U, 0x5393d808U, 0x0a2d9e0aU, 0x3d475c0bU
+      /* 16 */  , 0x70a3261cU, 0x47c9e41dU, 0x1e77a21fU, 0x291d601eU, 0xac0b2f1bU, 0x9b61ed1aU, 0xc2dfab18U, 0xf5b56919U
+      /* 24 */  , 0xc8f23512U, 0xff98f713U, 0xa626b111U, 0x914c7310U, 0x145a3c15U, 0x2330fe14U, 0x7a8eb816U, 0x4de47a17U
+      /* 32 */  , 0xe0464d38U, 0xd72c8f39U, 0x8e92c93bU, 0xb9f80b3aU, 0x3cee443fU, 0x0b84863eU, 0x523ac03cU, 0x6550023dU
+      /* 40 */  , 0x58175e36U, 0x6f7d9c37U, 0x36c3da35U, 0x01a91834U, 0x84bf5731U, 0xb3d59530U, 0xea6bd332U, 0xdd011133U
+      /* 48 */  , 0x90e56b24U, 0xa78fa925U, 0xfe31ef27U, 0xc95b2d26U, 0x4c4d6223U, 0x7b27a022U, 0x2299e620U, 0x15f32421U
+      /* 56 */  , 0x28b4782aU, 0x1fdeba2bU, 0x4660fc29U, 0x710a3e28U, 0xf41c712dU, 0xc376b32cU, 0x9ac8f52eU, 0xada2372fU
+      /* 64 */  , 0xc08d9a70U, 0xf7e75871U, 0xae591e73U, 0x9933dc72U, 0x1c259377U, 0x2b4f5176U, 0x72f11774U, 0x459bd575U
+      /* 72 */  , 0x78dc897eU, 0x4fb64b7fU, 0x16080d7dU, 0x2162cf7cU, 0xa4748079U, 0x931e4278U, 0xcaa0047aU, 0xfdcac67bU
+      /* 80 */  , 0xb02ebc6cU, 0x87447e6dU, 0xdefa386fU, 0xe990fa6eU, 0x6c86b56bU, 0x5bec776aU, 0x02523168U, 0x3538f369U
+      /* 88 */  , 0x087faf62U, 0x3f156d63U, 0x66ab2b61U, 0x51c1e960U, 0xd4d7a665U, 0xe3bd6464U, 0xba032266U, 0x8d69e067U
+      /* 96 */  , 0x20cbd748U, 0x17a11549U, 0x4e1f534bU, 0x7975914aU, 0xfc63de4fU, 0xcb091c4eU, 0x92b75a4cU, 0xa5dd984dU
+      /* 104 */  , 0x989ac446U, 0xaff00647U, 0xf64e4045U, 0xc1248244U, 0x4432cd41U, 0x73580f40U, 0x2ae64942U, 0x1d8c8b43U
+      /* 112 */  , 0x5068f154U, 0x67023355U, 0x3ebc7557U, 0x09d6b756U, 0x8cc0f853U, 0xbbaa3a52U, 0xe2147c50U, 0xd57ebe51U
+      /* 120 */  , 0xe839e25aU, 0xdf53205bU, 0x86ed6659U, 0xb187a458U, 0x3491eb5dU, 0x03fb295cU, 0x5a456f5eU, 0x6d2fad5fU
+      /* 128 */  , 0x801b35e1U, 0xb771f7e0U, 0xeecfb1e2U, 0xd9a573e3U, 0x5cb33ce6U, 0x6bd9fee7U, 0x3267b8e5U, 0x050d7ae4U
+      /* 136 */  , 0x384a26efU, 0x0f20e4eeU, 0x569ea2ecU, 0x61f460edU, 0xe4e22fe8U, 0xd388ede9U, 0x8a36abebU, 0xbd5c69eaU
+      /* 144 */  , 0xf0b813fdU, 0xc7d2d1fcU, 0x9e6c97feU, 0xa90655ffU, 0x2c101afaU, 0x1b7ad8fbU, 0x42c49ef9U, 0x75ae5cf8U
+      /* 152 */  , 0x48e900f3U, 0x7f83c2f2U, 0x263d84f0U, 0x115746f1U, 0x944109f4U, 0xa32bcbf5U, 0xfa958df7U, 0xcdff4ff6U
+      /* 160 */  , 0x605d78d9U, 0x5737bad8U, 0x0e89fcdaU, 0x39e33edbU, 0xbcf571deU, 0x8b9fb3dfU, 0xd221f5ddU, 0xe54b37dcU
+      /* 168 */  , 0xd80c6bd7U, 0xef66a9d6U, 0xb6d8efd4U, 0x81b22dd5U, 0x04a462d0U, 0x33cea0d1U, 0x6a70e6d3U, 0x5d1a24d2U
+      /* 176 */  , 0x10fe5ec5U, 0x27949cc4U, 0x7e2adac6U, 0x494018c7U, 0xcc5657c2U, 0xfb3c95c3U, 0xa282d3c1U, 0x95e811c0U
+      /* 184 */  , 0xa8af4dcbU, 0x9fc58fcaU, 0xc67bc9c8U, 0xf1110bc9U, 0x740744ccU, 0x436d86cdU, 0x1ad3c0cfU, 0x2db902ceU
+      /* 192 */  , 0x4096af91U, 0x77fc6d90U, 0x2e422b92U, 0x1928e993U, 0x9c3ea696U, 0xab546497U, 0xf2ea2295U, 0xc580e094U
+      /* 200 */  , 0xf8c7bc9fU, 0xcfad7e9eU, 0x9613389cU, 0xa179fa9dU, 0x246fb598U, 0x13057799U, 0x4abb319bU, 0x7dd1f39aU
+      /* 208 */  , 0x3035898dU, 0x075f4b8cU, 0x5ee10d8eU, 0x698bcf8fU, 0xec9d808aU, 0xdbf7428bU, 0x82490489U, 0xb523c688U
+      /* 216 */  , 0x88649a83U, 0xbf0e5882U, 0xe6b01e80U, 0xd1dadc81U, 0x54cc9384U, 0x63a65185U, 0x3a181787U, 0x0d72d586U
+      /* 224 */  , 0xa0d0e2a9U, 0x97ba20a8U, 0xce0466aaU, 0xf96ea4abU, 0x7c78ebaeU, 0x4b1229afU, 0x12ac6fadU, 0x25c6adacU
+      /* 232 */  , 0x1881f1a7U, 0x2feb33a6U, 0x765575a4U, 0x413fb7a5U, 0xc429f8a0U, 0xf3433aa1U, 0xaafd7ca3U, 0x9d97bea2U
+      /* 240 */  , 0xd073c4b5U, 0xe71906b4U, 0xbea740b6U, 0x89cd82b7U, 0x0cdbcdb2U, 0x3bb10fb3U, 0x620f49b1U, 0x55658bb0U
+      /* 248 */  , 0x6822d7bbU, 0x5f4815baU, 0x06f653b8U, 0x319c91b9U, 0xb48adebcU, 0x83e01cbdU, 0xda5e5abfU, 0xed3498beU
+    }
+    ,
+    /* CRC32 table 7 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x6567bcb8U, 0x8bc809aaU, 0xeeafb512U, 0x5797628fU, 0x32f0de37U, 0xdc5f6b25U, 0xb938d79dU
+      /* 8 */  , 0xef28b4c5U, 0x8a4f087dU, 0x64e0bd6fU, 0x018701d7U, 0xb8bfd64aU, 0xddd86af2U, 0x3377dfe0U, 0x56106358U
+      /* 16 */  , 0x9f571950U, 0xfa30a5e8U, 0x149f10faU, 0x71f8ac42U, 0xc8c07bdfU, 0xada7c767U, 0x43087275U, 0x266fcecdU
+      /* 24 */  , 0x707fad95U, 0x1518112dU, 0xfbb7a43fU, 0x9ed01887U, 0x27e8cf1aU, 0x428f73a2U, 0xac20c6b0U, 0xc9477a08U
+      /* 32 */  , 0x3eaf32a0U, 0x5bc88e18U, 0xb5673b0aU, 0xd00087b2U, 0x6938502fU, 0x0c5fec97U, 0xe2f05985U, 0x8797e53dU
+      /* 40 */  , 0xd1878665U, 0xb4e03addU, 0x5a4f8fcfU, 0x3f283377U, 0x8610e4eaU, 0xe3775852U, 0x0dd8ed40U, 0x68bf51f8U
+      /* 48 */  , 0xa1f82bf0U, 0xc49f9748U, 0x2a30225aU, 0x4f579ee2U, 0xf66f497fU, 0x9308f5c7U, 0x7da740d5U, 0x18c0fc6dU
+      /* 56 */  , 0x4ed09f35U, 0x2bb7238dU, 0xc518969fU, 0xa07f2a27U, 0x1947fdbaU, 0x7c204102U, 0x928ff410U, 0xf7e848a8U
+      /* 64 */  , 0x3d58149bU, 0x583fa823U, 0xb6901d31U, 0xd3f7a189U, 0x6acf7614U, 0x0fa8caacU, 0xe1077fbeU, 0x8460c306U
+      /* 72 */  , 0xd270a05eU, 0xb7171ce6U, 0x59b8a9f4U, 0x3cdf154cU, 0x85e7c2d1U, 0xe0807e69U, 0x0e2fcb7bU, 0x6b4877c3U
+      /* 80 */  , 0xa20f0dcbU, 0xc768b173U, 0x29c70461U, 0x4ca0b8d9U, 0xf5986f44U, 0x90ffd3fcU, 0x7e5066eeU, 0x1b37da56U
+      /* 88 */  , 0x4d27b90eU, 0x284005b6U, 0xc6efb0a4U, 0xa3880c1cU, 0x1ab0db81U, 0x7fd76739U, 0x9178d22bU, 0xf41f6e93U
+      /* 96 */  , 0x03f7263bU, 0x66909a83U, 0x883f2f91U, 0xed589329U, 0x546044b4U, 0x3107f80cU, 0xdfa84d1eU, 0xbacff1a6U
+      /* 104 */  , 0xecdf92feU, 0x89b82e46U, 0x67179b54U, 0x027027ecU, 0xbb48f071U, 0xde2f4cc9U, 0x3080f9dbU, 0x55e74563U
+      /* 112 */  , 0x9ca03f6bU, 0xf9c783d3U, 0x176836c1U, 0x720f8a79U, 0xcb375de4U, 0xae50e15cU, 0x40ff544eU, 0x2598e8f6U
+      /* 120 */  , 0x73888baeU, 0x16ef3716U, 0xf8408204U, 0x9d273ebcU, 0x241fe921U, 0x41785599U, 0xafd7e08bU, 0xcab05c33U
+      /* 128 */  , 0x3bb659edU, 0x5ed1e555U, 0xb07e5047U, 0xd519ecffU, 0x6c213b62U, 0x094687daU, 0xe7e932c8U, 0x828e8e70U
+      /* 136 */  , 0xd49eed28U, 0xb1f95190U, 0x5f56e482U, 0x3a31583aU, 0x83098fa7U, 0xe66e331fU, 0x08c1860dU, 0x6da63ab5U
+      /* 144 */  , 0xa4e140bdU, 0xc186fc05U, 0x2f294917U, 0x4a4ef5afU, 0xf3762232U, 0x96119e8aU, 0x78be2b98U, 0x1dd99720U
+      /* 152 */  , 0x4bc9f478U, 0x2eae48c0U, 0xc001fdd2U, 0xa566416aU, 0x1c5e96f7U, 0x79392a4fU, 0x97969f5dU, 0xf2f123e5U
+      /* 160 */  , 0x05196b4dU, 0x607ed7f5U, 0x8ed162e7U, 0xebb6de5fU, 0x528e09c2U, 0x37e9b57aU, 0xd9460068U, 0xbc21bcd0U
+      /* 168 */  , 0xea31df88U, 0x8f566330U, 0x61f9d622U, 0x049e6a9aU, 0xbda6bd07U, 0xd8c101bfU, 0x366eb4adU, 0x53090815U
+      /* 176 */  , 0x9a4e721dU, 0xff29cea5U, 0x11867bb7U, 0x74e1c70fU, 0xcdd91092U, 0xa8beac2aU, 0x46111938U, 0x2376a580U
+      /* 184 */  , 0x7566c6d8U, 0x10017a60U, 0xfeaecf72U, 0x9bc973caU, 0x22f1a457U, 0x479618efU, 0xa939adfdU, 0xcc5e1145U
+      /* 192 */  , 0x06ee4d76U, 0x6389f1ceU, 0x8d2644dcU, 0xe841f864U, 0x51792ff9U, 0x341e9341U, 0xdab12653U, 0xbfd69aebU
+      /* 200 */  , 0xe9c6f9b3U, 0x8ca1450bU, 0x620ef019U, 0x07694ca1U, 0xbe519b3cU, 0xdb362784U, 0x35999296U, 0x50fe2e2eU
+      /* 208 */  , 0x99b95426U, 0xfcdee89eU, 0x12715d8cU, 0x7716e134U, 0xce2e36a9U, 0xab498a11U, 0x45e63f03U, 0x208183bbU
+      /* 216 */  , 0x7691e0e3U, 0x13f65c5bU, 0xfd59e949U, 0x983e55f1U, 0x2106826cU, 0x44613ed4U, 0xaace8bc6U, 0xcfa9377eU
+      /* 224 */  , 0x38417fd6U, 0x5d26c36eU, 0xb389767cU, 0xd6eecac4U, 0x6fd61d59U, 0x0ab1a1e1U, 0xe41e14f3U, 0x8179a84bU
+      /* 232 */  , 0xd769cb13U, 0xb20e77abU, 0x5ca1c2b9U, 0x39c67e01U, 0x80fea99cU, 0xe5991524U, 0x0b36a036U, 0x6e511c8eU
+      /* 240 */  , 0xa7166686U, 0xc271da3eU, 0x2cde6f2cU, 0x49b9d394U, 0xf0810409U, 0x95e6b8b1U, 0x7b490da3U, 0x1e2eb11bU
+      /* 248 */  , 0x483ed243U, 0x2d596efbU, 0xc3f6dbe9U, 0xa6916751U, 0x1fa9b0ccU, 0x7ace0c74U, 0x9461b966U, 0xf10605deU
+    }
+  #endif
+  };
+
+juint StubRoutines::zarch::_crc32c_table[CRC32_TABLES][CRC32_COLUMN_SIZE] = {
+    /* polyBits = 4394350321 0x0000000105ec76f1L, shifted = 0x82f63b78 */
+    /* CRC32C table for single bytes, auto-generated.  DO NOT MODIFY!  */
+    /* CRC32C table 0 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0xf26b8303U, 0xe13b70f7U, 0x1350f3f4U, 0xc79a971fU, 0x35f1141cU, 0x26a1e7e8U, 0xd4ca64ebU
+      /* 8 */  , 0x8ad958cfU, 0x78b2dbccU, 0x6be22838U, 0x9989ab3bU, 0x4d43cfd0U, 0xbf284cd3U, 0xac78bf27U, 0x5e133c24U
+      /* 16 */  , 0x105ec76fU, 0xe235446cU, 0xf165b798U, 0x030e349bU, 0xd7c45070U, 0x25afd373U, 0x36ff2087U, 0xc494a384U
+      /* 24 */  , 0x9a879fa0U, 0x68ec1ca3U, 0x7bbcef57U, 0x89d76c54U, 0x5d1d08bfU, 0xaf768bbcU, 0xbc267848U, 0x4e4dfb4bU
+      /* 32 */  , 0x20bd8edeU, 0xd2d60dddU, 0xc186fe29U, 0x33ed7d2aU, 0xe72719c1U, 0x154c9ac2U, 0x061c6936U, 0xf477ea35U
+      /* 40 */  , 0xaa64d611U, 0x580f5512U, 0x4b5fa6e6U, 0xb93425e5U, 0x6dfe410eU, 0x9f95c20dU, 0x8cc531f9U, 0x7eaeb2faU
+      /* 48 */  , 0x30e349b1U, 0xc288cab2U, 0xd1d83946U, 0x23b3ba45U, 0xf779deaeU, 0x05125dadU, 0x1642ae59U, 0xe4292d5aU
+      /* 56 */  , 0xba3a117eU, 0x4851927dU, 0x5b016189U, 0xa96ae28aU, 0x7da08661U, 0x8fcb0562U, 0x9c9bf696U, 0x6ef07595U
+      /* 64 */  , 0x417b1dbcU, 0xb3109ebfU, 0xa0406d4bU, 0x522bee48U, 0x86e18aa3U, 0x748a09a0U, 0x67dafa54U, 0x95b17957U
+      /* 72 */  , 0xcba24573U, 0x39c9c670U, 0x2a993584U, 0xd8f2b687U, 0x0c38d26cU, 0xfe53516fU, 0xed03a29bU, 0x1f682198U
+      /* 80 */  , 0x5125dad3U, 0xa34e59d0U, 0xb01eaa24U, 0x42752927U, 0x96bf4dccU, 0x64d4cecfU, 0x77843d3bU, 0x85efbe38U
+      /* 88 */  , 0xdbfc821cU, 0x2997011fU, 0x3ac7f2ebU, 0xc8ac71e8U, 0x1c661503U, 0xee0d9600U, 0xfd5d65f4U, 0x0f36e6f7U
+      /* 96 */  , 0x61c69362U, 0x93ad1061U, 0x80fde395U, 0x72966096U, 0xa65c047dU, 0x5437877eU, 0x4767748aU, 0xb50cf789U
+      /* 104 */  , 0xeb1fcbadU, 0x197448aeU, 0x0a24bb5aU, 0xf84f3859U, 0x2c855cb2U, 0xdeeedfb1U, 0xcdbe2c45U, 0x3fd5af46U
+      /* 112 */  , 0x7198540dU, 0x83f3d70eU, 0x90a324faU, 0x62c8a7f9U, 0xb602c312U, 0x44694011U, 0x5739b3e5U, 0xa55230e6U
+      /* 120 */  , 0xfb410cc2U, 0x092a8fc1U, 0x1a7a7c35U, 0xe811ff36U, 0x3cdb9bddU, 0xceb018deU, 0xdde0eb2aU, 0x2f8b6829U
+      /* 128 */  , 0x82f63b78U, 0x709db87bU, 0x63cd4b8fU, 0x91a6c88cU, 0x456cac67U, 0xb7072f64U, 0xa457dc90U, 0x563c5f93U
+      /* 136 */  , 0x082f63b7U, 0xfa44e0b4U, 0xe9141340U, 0x1b7f9043U, 0xcfb5f4a8U, 0x3dde77abU, 0x2e8e845fU, 0xdce5075cU
+      /* 144 */  , 0x92a8fc17U, 0x60c37f14U, 0x73938ce0U, 0x81f80fe3U, 0x55326b08U, 0xa759e80bU, 0xb4091bffU, 0x466298fcU
+      /* 152 */  , 0x1871a4d8U, 0xea1a27dbU, 0xf94ad42fU, 0x0b21572cU, 0xdfeb33c7U, 0x2d80b0c4U, 0x3ed04330U, 0xccbbc033U
+      /* 160 */  , 0xa24bb5a6U, 0x502036a5U, 0x4370c551U, 0xb11b4652U, 0x65d122b9U, 0x97baa1baU, 0x84ea524eU, 0x7681d14dU
+      /* 168 */  , 0x2892ed69U, 0xdaf96e6aU, 0xc9a99d9eU, 0x3bc21e9dU, 0xef087a76U, 0x1d63f975U, 0x0e330a81U, 0xfc588982U
+      /* 176 */  , 0xb21572c9U, 0x407ef1caU, 0x532e023eU, 0xa145813dU, 0x758fe5d6U, 0x87e466d5U, 0x94b49521U, 0x66df1622U
+      /* 184 */  , 0x38cc2a06U, 0xcaa7a905U, 0xd9f75af1U, 0x2b9cd9f2U, 0xff56bd19U, 0x0d3d3e1aU, 0x1e6dcdeeU, 0xec064eedU
+      /* 192 */  , 0xc38d26c4U, 0x31e6a5c7U, 0x22b65633U, 0xd0ddd530U, 0x0417b1dbU, 0xf67c32d8U, 0xe52cc12cU, 0x1747422fU
+      /* 200 */  , 0x49547e0bU, 0xbb3ffd08U, 0xa86f0efcU, 0x5a048dffU, 0x8ecee914U, 0x7ca56a17U, 0x6ff599e3U, 0x9d9e1ae0U
+      /* 208 */  , 0xd3d3e1abU, 0x21b862a8U, 0x32e8915cU, 0xc083125fU, 0x144976b4U, 0xe622f5b7U, 0xf5720643U, 0x07198540U
+      /* 216 */  , 0x590ab964U, 0xab613a67U, 0xb831c993U, 0x4a5a4a90U, 0x9e902e7bU, 0x6cfbad78U, 0x7fab5e8cU, 0x8dc0dd8fU
+      /* 224 */  , 0xe330a81aU, 0x115b2b19U, 0x020bd8edU, 0xf0605beeU, 0x24aa3f05U, 0xd6c1bc06U, 0xc5914ff2U, 0x37faccf1U
+      /* 232 */  , 0x69e9f0d5U, 0x9b8273d6U, 0x88d28022U, 0x7ab90321U, 0xae7367caU, 0x5c18e4c9U, 0x4f48173dU, 0xbd23943eU
+      /* 240 */  , 0xf36e6f75U, 0x0105ec76U, 0x12551f82U, 0xe03e9c81U, 0x34f4f86aU, 0xc69f7b69U, 0xd5cf889dU, 0x27a40b9eU
+      /* 248 */  , 0x79b737baU, 0x8bdcb4b9U, 0x988c474dU, 0x6ae7c44eU, 0xbe2da0a5U, 0x4c4623a6U, 0x5f16d052U, 0xad7d5351U
+    }
+  #ifdef  CRC32_BYFOUR
+    ,
+    /* CRC32C table 1 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x13a29877U, 0x274530eeU, 0x34e7a899U, 0x4e8a61dcU, 0x5d28f9abU, 0x69cf5132U, 0x7a6dc945U
+      /* 8 */  , 0x9d14c3b8U, 0x8eb65bcfU, 0xba51f356U, 0xa9f36b21U, 0xd39ea264U, 0xc03c3a13U, 0xf4db928aU, 0xe7790afdU
+      /* 16 */  , 0x3fc5f181U, 0x2c6769f6U, 0x1880c16fU, 0x0b225918U, 0x714f905dU, 0x62ed082aU, 0x560aa0b3U, 0x45a838c4U
+      /* 24 */  , 0xa2d13239U, 0xb173aa4eU, 0x859402d7U, 0x96369aa0U, 0xec5b53e5U, 0xfff9cb92U, 0xcb1e630bU, 0xd8bcfb7cU
+      /* 32 */  , 0x7f8be302U, 0x6c297b75U, 0x58ced3ecU, 0x4b6c4b9bU, 0x310182deU, 0x22a31aa9U, 0x1644b230U, 0x05e62a47U
+      /* 40 */  , 0xe29f20baU, 0xf13db8cdU, 0xc5da1054U, 0xd6788823U, 0xac154166U, 0xbfb7d911U, 0x8b507188U, 0x98f2e9ffU
+      /* 48 */  , 0x404e1283U, 0x53ec8af4U, 0x670b226dU, 0x74a9ba1aU, 0x0ec4735fU, 0x1d66eb28U, 0x298143b1U, 0x3a23dbc6U
+      /* 56 */  , 0xdd5ad13bU, 0xcef8494cU, 0xfa1fe1d5U, 0xe9bd79a2U, 0x93d0b0e7U, 0x80722890U, 0xb4958009U, 0xa737187eU
+      /* 64 */  , 0xff17c604U, 0xecb55e73U, 0xd852f6eaU, 0xcbf06e9dU, 0xb19da7d8U, 0xa23f3fafU, 0x96d89736U, 0x857a0f41U
+      /* 72 */  , 0x620305bcU, 0x71a19dcbU, 0x45463552U, 0x56e4ad25U, 0x2c896460U, 0x3f2bfc17U, 0x0bcc548eU, 0x186eccf9U
+      /* 80 */  , 0xc0d23785U, 0xd370aff2U, 0xe797076bU, 0xf4359f1cU, 0x8e585659U, 0x9dface2eU, 0xa91d66b7U, 0xbabffec0U
+      /* 88 */  , 0x5dc6f43dU, 0x4e646c4aU, 0x7a83c4d3U, 0x69215ca4U, 0x134c95e1U, 0x00ee0d96U, 0x3409a50fU, 0x27ab3d78U
+      /* 96 */  , 0x809c2506U, 0x933ebd71U, 0xa7d915e8U, 0xb47b8d9fU, 0xce1644daU, 0xddb4dcadU, 0xe9537434U, 0xfaf1ec43U
+      /* 104 */  , 0x1d88e6beU, 0x0e2a7ec9U, 0x3acdd650U, 0x296f4e27U, 0x53028762U, 0x40a01f15U, 0x7447b78cU, 0x67e52ffbU
+      /* 112 */  , 0xbf59d487U, 0xacfb4cf0U, 0x981ce469U, 0x8bbe7c1eU, 0xf1d3b55bU, 0xe2712d2cU, 0xd69685b5U, 0xc5341dc2U
+      /* 120 */  , 0x224d173fU, 0x31ef8f48U, 0x050827d1U, 0x16aabfa6U, 0x6cc776e3U, 0x7f65ee94U, 0x4b82460dU, 0x5820de7aU
+      /* 128 */  , 0xfbc3faf9U, 0xe861628eU, 0xdc86ca17U, 0xcf245260U, 0xb5499b25U, 0xa6eb0352U, 0x920cabcbU, 0x81ae33bcU
+      /* 136 */  , 0x66d73941U, 0x7575a136U, 0x419209afU, 0x523091d8U, 0x285d589dU, 0x3bffc0eaU, 0x0f186873U, 0x1cbaf004U
+      /* 144 */  , 0xc4060b78U, 0xd7a4930fU, 0xe3433b96U, 0xf0e1a3e1U, 0x8a8c6aa4U, 0x992ef2d3U, 0xadc95a4aU, 0xbe6bc23dU
+      /* 152 */  , 0x5912c8c0U, 0x4ab050b7U, 0x7e57f82eU, 0x6df56059U, 0x1798a91cU, 0x043a316bU, 0x30dd99f2U, 0x237f0185U
+      /* 160 */  , 0x844819fbU, 0x97ea818cU, 0xa30d2915U, 0xb0afb162U, 0xcac27827U, 0xd960e050U, 0xed8748c9U, 0xfe25d0beU
+      /* 168 */  , 0x195cda43U, 0x0afe4234U, 0x3e19eaadU, 0x2dbb72daU, 0x57d6bb9fU, 0x447423e8U, 0x70938b71U, 0x63311306U
+      /* 176 */  , 0xbb8de87aU, 0xa82f700dU, 0x9cc8d894U, 0x8f6a40e3U, 0xf50789a6U, 0xe6a511d1U, 0xd242b948U, 0xc1e0213fU
+      /* 184 */  , 0x26992bc2U, 0x353bb3b5U, 0x01dc1b2cU, 0x127e835bU, 0x68134a1eU, 0x7bb1d269U, 0x4f567af0U, 0x5cf4e287U
+      /* 192 */  , 0x04d43cfdU, 0x1776a48aU, 0x23910c13U, 0x30339464U, 0x4a5e5d21U, 0x59fcc556U, 0x6d1b6dcfU, 0x7eb9f5b8U
+      /* 200 */  , 0x99c0ff45U, 0x8a626732U, 0xbe85cfabU, 0xad2757dcU, 0xd74a9e99U, 0xc4e806eeU, 0xf00fae77U, 0xe3ad3600U
+      /* 208 */  , 0x3b11cd7cU, 0x28b3550bU, 0x1c54fd92U, 0x0ff665e5U, 0x759baca0U, 0x663934d7U, 0x52de9c4eU, 0x417c0439U
+      /* 216 */  , 0xa6050ec4U, 0xb5a796b3U, 0x81403e2aU, 0x92e2a65dU, 0xe88f6f18U, 0xfb2df76fU, 0xcfca5ff6U, 0xdc68c781U
+      /* 224 */  , 0x7b5fdfffU, 0x68fd4788U, 0x5c1aef11U, 0x4fb87766U, 0x35d5be23U, 0x26772654U, 0x12908ecdU, 0x013216baU
+      /* 232 */  , 0xe64b1c47U, 0xf5e98430U, 0xc10e2ca9U, 0xd2acb4deU, 0xa8c17d9bU, 0xbb63e5ecU, 0x8f844d75U, 0x9c26d502U
+      /* 240 */  , 0x449a2e7eU, 0x5738b609U, 0x63df1e90U, 0x707d86e7U, 0x0a104fa2U, 0x19b2d7d5U, 0x2d557f4cU, 0x3ef7e73bU
+      /* 248 */  , 0xd98eedc6U, 0xca2c75b1U, 0xfecbdd28U, 0xed69455fU, 0x97048c1aU, 0x84a6146dU, 0xb041bcf4U, 0xa3e32483U
+    }
+    ,
+    /* CRC32C table 2 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0xa541927eU, 0x4f6f520dU, 0xea2ec073U, 0x9edea41aU, 0x3b9f3664U, 0xd1b1f617U, 0x74f06469U
+      /* 8 */  , 0x38513ec5U, 0x9d10acbbU, 0x773e6cc8U, 0xd27ffeb6U, 0xa68f9adfU, 0x03ce08a1U, 0xe9e0c8d2U, 0x4ca15aacU
+      /* 16 */  , 0x70a27d8aU, 0xd5e3eff4U, 0x3fcd2f87U, 0x9a8cbdf9U, 0xee7cd990U, 0x4b3d4beeU, 0xa1138b9dU, 0x045219e3U
+      /* 24 */  , 0x48f3434fU, 0xedb2d131U, 0x079c1142U, 0xa2dd833cU, 0xd62de755U, 0x736c752bU, 0x9942b558U, 0x3c032726U
+      /* 32 */  , 0xe144fb14U, 0x4405696aU, 0xae2ba919U, 0x0b6a3b67U, 0x7f9a5f0eU, 0xdadbcd70U, 0x30f50d03U, 0x95b49f7dU
+      /* 40 */  , 0xd915c5d1U, 0x7c5457afU, 0x967a97dcU, 0x333b05a2U, 0x47cb61cbU, 0xe28af3b5U, 0x08a433c6U, 0xade5a1b8U
+      /* 48 */  , 0x91e6869eU, 0x34a714e0U, 0xde89d493U, 0x7bc846edU, 0x0f382284U, 0xaa79b0faU, 0x40577089U, 0xe516e2f7U
+      /* 56 */  , 0xa9b7b85bU, 0x0cf62a25U, 0xe6d8ea56U, 0x43997828U, 0x37691c41U, 0x92288e3fU, 0x78064e4cU, 0xdd47dc32U
+      /* 64 */  , 0xc76580d9U, 0x622412a7U, 0x880ad2d4U, 0x2d4b40aaU, 0x59bb24c3U, 0xfcfab6bdU, 0x16d476ceU, 0xb395e4b0U
+      /* 72 */  , 0xff34be1cU, 0x5a752c62U, 0xb05bec11U, 0x151a7e6fU, 0x61ea1a06U, 0xc4ab8878U, 0x2e85480bU, 0x8bc4da75U
+      /* 80 */  , 0xb7c7fd53U, 0x12866f2dU, 0xf8a8af5eU, 0x5de93d20U, 0x29195949U, 0x8c58cb37U, 0x66760b44U, 0xc337993aU
+      /* 88 */  , 0x8f96c396U, 0x2ad751e8U, 0xc0f9919bU, 0x65b803e5U, 0x1148678cU, 0xb409f5f2U, 0x5e273581U, 0xfb66a7ffU
+      /* 96 */  , 0x26217bcdU, 0x8360e9b3U, 0x694e29c0U, 0xcc0fbbbeU, 0xb8ffdfd7U, 0x1dbe4da9U, 0xf7908ddaU, 0x52d11fa4U
+      /* 104 */  , 0x1e704508U, 0xbb31d776U, 0x511f1705U, 0xf45e857bU, 0x80aee112U, 0x25ef736cU, 0xcfc1b31fU, 0x6a802161U
+      /* 112 */  , 0x56830647U, 0xf3c29439U, 0x19ec544aU, 0xbcadc634U, 0xc85da25dU, 0x6d1c3023U, 0x8732f050U, 0x2273622eU
+      /* 120 */  , 0x6ed23882U, 0xcb93aafcU, 0x21bd6a8fU, 0x84fcf8f1U, 0xf00c9c98U, 0x554d0ee6U, 0xbf63ce95U, 0x1a225cebU
+      /* 128 */  , 0x8b277743U, 0x2e66e53dU, 0xc448254eU, 0x6109b730U, 0x15f9d359U, 0xb0b84127U, 0x5a968154U, 0xffd7132aU
+      /* 136 */  , 0xb3764986U, 0x1637dbf8U, 0xfc191b8bU, 0x595889f5U, 0x2da8ed9cU, 0x88e97fe2U, 0x62c7bf91U, 0xc7862defU
+      /* 144 */  , 0xfb850ac9U, 0x5ec498b7U, 0xb4ea58c4U, 0x11abcabaU, 0x655baed3U, 0xc01a3cadU, 0x2a34fcdeU, 0x8f756ea0U
+      /* 152 */  , 0xc3d4340cU, 0x6695a672U, 0x8cbb6601U, 0x29faf47fU, 0x5d0a9016U, 0xf84b0268U, 0x1265c21bU, 0xb7245065U
+      /* 160 */  , 0x6a638c57U, 0xcf221e29U, 0x250cde5aU, 0x804d4c24U, 0xf4bd284dU, 0x51fcba33U, 0xbbd27a40U, 0x1e93e83eU
+      /* 168 */  , 0x5232b292U, 0xf77320ecU, 0x1d5de09fU, 0xb81c72e1U, 0xccec1688U, 0x69ad84f6U, 0x83834485U, 0x26c2d6fbU
+      /* 176 */  , 0x1ac1f1ddU, 0xbf8063a3U, 0x55aea3d0U, 0xf0ef31aeU, 0x841f55c7U, 0x215ec7b9U, 0xcb7007caU, 0x6e3195b4U
+      /* 184 */  , 0x2290cf18U, 0x87d15d66U, 0x6dff9d15U, 0xc8be0f6bU, 0xbc4e6b02U, 0x190ff97cU, 0xf321390fU, 0x5660ab71U
+      /* 192 */  , 0x4c42f79aU, 0xe90365e4U, 0x032da597U, 0xa66c37e9U, 0xd29c5380U, 0x77ddc1feU, 0x9df3018dU, 0x38b293f3U
+      /* 200 */  , 0x7413c95fU, 0xd1525b21U, 0x3b7c9b52U, 0x9e3d092cU, 0xeacd6d45U, 0x4f8cff3bU, 0xa5a23f48U, 0x00e3ad36U
+      /* 208 */  , 0x3ce08a10U, 0x99a1186eU, 0x738fd81dU, 0xd6ce4a63U, 0xa23e2e0aU, 0x077fbc74U, 0xed517c07U, 0x4810ee79U
+      /* 216 */  , 0x04b1b4d5U, 0xa1f026abU, 0x4bdee6d8U, 0xee9f74a6U, 0x9a6f10cfU, 0x3f2e82b1U, 0xd50042c2U, 0x7041d0bcU
+      /* 224 */  , 0xad060c8eU, 0x08479ef0U, 0xe2695e83U, 0x4728ccfdU, 0x33d8a894U, 0x96993aeaU, 0x7cb7fa99U, 0xd9f668e7U
+      /* 232 */  , 0x9557324bU, 0x3016a035U, 0xda386046U, 0x7f79f238U, 0x0b899651U, 0xaec8042fU, 0x44e6c45cU, 0xe1a75622U
+      /* 240 */  , 0xdda47104U, 0x78e5e37aU, 0x92cb2309U, 0x378ab177U, 0x437ad51eU, 0xe63b4760U, 0x0c158713U, 0xa954156dU
+      /* 248 */  , 0xe5f54fc1U, 0x40b4ddbfU, 0xaa9a1dccU, 0x0fdb8fb2U, 0x7b2bebdbU, 0xde6a79a5U, 0x3444b9d6U, 0x91052ba8U
+    }
+    ,
+    /* CRC32C table 3 for quad-bytes (little-endian), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0xdd45aab8U, 0xbf672381U, 0x62228939U, 0x7b2231f3U, 0xa6679b4bU, 0xc4451272U, 0x1900b8caU
+      /* 8 */  , 0xf64463e6U, 0x2b01c95eU, 0x49234067U, 0x9466eadfU, 0x8d665215U, 0x5023f8adU, 0x32017194U, 0xef44db2cU
+      /* 16 */  , 0xe964b13dU, 0x34211b85U, 0x560392bcU, 0x8b463804U, 0x924680ceU, 0x4f032a76U, 0x2d21a34fU, 0xf06409f7U
+      /* 24 */  , 0x1f20d2dbU, 0xc2657863U, 0xa047f15aU, 0x7d025be2U, 0x6402e328U, 0xb9474990U, 0xdb65c0a9U, 0x06206a11U
+      /* 32 */  , 0xd725148bU, 0x0a60be33U, 0x6842370aU, 0xb5079db2U, 0xac072578U, 0x71428fc0U, 0x136006f9U, 0xce25ac41U
+      /* 40 */  , 0x2161776dU, 0xfc24ddd5U, 0x9e0654ecU, 0x4343fe54U, 0x5a43469eU, 0x8706ec26U, 0xe524651fU, 0x3861cfa7U
+      /* 48 */  , 0x3e41a5b6U, 0xe3040f0eU, 0x81268637U, 0x5c632c8fU, 0x45639445U, 0x98263efdU, 0xfa04b7c4U, 0x27411d7cU
+      /* 56 */  , 0xc805c650U, 0x15406ce8U, 0x7762e5d1U, 0xaa274f69U, 0xb327f7a3U, 0x6e625d1bU, 0x0c40d422U, 0xd1057e9aU
+      /* 64 */  , 0xaba65fe7U, 0x76e3f55fU, 0x14c17c66U, 0xc984d6deU, 0xd0846e14U, 0x0dc1c4acU, 0x6fe34d95U, 0xb2a6e72dU
+      /* 72 */  , 0x5de23c01U, 0x80a796b9U, 0xe2851f80U, 0x3fc0b538U, 0x26c00df2U, 0xfb85a74aU, 0x99a72e73U, 0x44e284cbU
+      /* 80 */  , 0x42c2eedaU, 0x9f874462U, 0xfda5cd5bU, 0x20e067e3U, 0x39e0df29U, 0xe4a57591U, 0x8687fca8U, 0x5bc25610U
+      /* 88 */  , 0xb4868d3cU, 0x69c32784U, 0x0be1aebdU, 0xd6a40405U, 0xcfa4bccfU, 0x12e11677U, 0x70c39f4eU, 0xad8635f6U
+      /* 96 */  , 0x7c834b6cU, 0xa1c6e1d4U, 0xc3e468edU, 0x1ea1c255U, 0x07a17a9fU, 0xdae4d027U, 0xb8c6591eU, 0x6583f3a6U
+      /* 104 */  , 0x8ac7288aU, 0x57828232U, 0x35a00b0bU, 0xe8e5a1b3U, 0xf1e51979U, 0x2ca0b3c1U, 0x4e823af8U, 0x93c79040U
+      /* 112 */  , 0x95e7fa51U, 0x48a250e9U, 0x2a80d9d0U, 0xf7c57368U, 0xeec5cba2U, 0x3380611aU, 0x51a2e823U, 0x8ce7429bU
+      /* 120 */  , 0x63a399b7U, 0xbee6330fU, 0xdcc4ba36U, 0x0181108eU, 0x1881a844U, 0xc5c402fcU, 0xa7e68bc5U, 0x7aa3217dU
+      /* 128 */  , 0x52a0c93fU, 0x8fe56387U, 0xedc7eabeU, 0x30824006U, 0x2982f8ccU, 0xf4c75274U, 0x96e5db4dU, 0x4ba071f5U
+      /* 136 */  , 0xa4e4aad9U, 0x79a10061U, 0x1b838958U, 0xc6c623e0U, 0xdfc69b2aU, 0x02833192U, 0x60a1b8abU, 0xbde41213U
+      /* 144 */  , 0xbbc47802U, 0x6681d2baU, 0x04a35b83U, 0xd9e6f13bU, 0xc0e649f1U, 0x1da3e349U, 0x7f816a70U, 0xa2c4c0c8U
+      /* 152 */  , 0x4d801be4U, 0x90c5b15cU, 0xf2e73865U, 0x2fa292ddU, 0x36a22a17U, 0xebe780afU, 0x89c50996U, 0x5480a32eU
+      /* 160 */  , 0x8585ddb4U, 0x58c0770cU, 0x3ae2fe35U, 0xe7a7548dU, 0xfea7ec47U, 0x23e246ffU, 0x41c0cfc6U, 0x9c85657eU
+      /* 168 */  , 0x73c1be52U, 0xae8414eaU, 0xcca69dd3U, 0x11e3376bU, 0x08e38fa1U, 0xd5a62519U, 0xb784ac20U, 0x6ac10698U
+      /* 176 */  , 0x6ce16c89U, 0xb1a4c631U, 0xd3864f08U, 0x0ec3e5b0U, 0x17c35d7aU, 0xca86f7c2U, 0xa8a47efbU, 0x75e1d443U
+      /* 184 */  , 0x9aa50f6fU, 0x47e0a5d7U, 0x25c22ceeU, 0xf8878656U, 0xe1873e9cU, 0x3cc29424U, 0x5ee01d1dU, 0x83a5b7a5U
+      /* 192 */  , 0xf90696d8U, 0x24433c60U, 0x4661b559U, 0x9b241fe1U, 0x8224a72bU, 0x5f610d93U, 0x3d4384aaU, 0xe0062e12U
+      /* 200 */  , 0x0f42f53eU, 0xd2075f86U, 0xb025d6bfU, 0x6d607c07U, 0x7460c4cdU, 0xa9256e75U, 0xcb07e74cU, 0x16424df4U
+      /* 208 */  , 0x106227e5U, 0xcd278d5dU, 0xaf050464U, 0x7240aedcU, 0x6b401616U, 0xb605bcaeU, 0xd4273597U, 0x09629f2fU
+      /* 216 */  , 0xe6264403U, 0x3b63eebbU, 0x59416782U, 0x8404cd3aU, 0x9d0475f0U, 0x4041df48U, 0x22635671U, 0xff26fcc9U
+      /* 224 */  , 0x2e238253U, 0xf36628ebU, 0x9144a1d2U, 0x4c010b6aU, 0x5501b3a0U, 0x88441918U, 0xea669021U, 0x37233a99U
+      /* 232 */  , 0xd867e1b5U, 0x05224b0dU, 0x6700c234U, 0xba45688cU, 0xa345d046U, 0x7e007afeU, 0x1c22f3c7U, 0xc167597fU
+      /* 240 */  , 0xc747336eU, 0x1a0299d6U, 0x782010efU, 0xa565ba57U, 0xbc65029dU, 0x6120a825U, 0x0302211cU, 0xde478ba4U
+      /* 248 */  , 0x31035088U, 0xec46fa30U, 0x8e647309U, 0x5321d9b1U, 0x4a21617bU, 0x9764cbc3U, 0xf54642faU, 0x2803e842U
+    }
+    ,
+    /* CRC32C table 4 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x03836bf2U, 0xf7703be1U, 0xf4f35013U, 0x1f979ac7U, 0x1c14f135U, 0xe8e7a126U, 0xeb64cad4U
+      /* 8 */  , 0xcf58d98aU, 0xccdbb278U, 0x3828e26bU, 0x3bab8999U, 0xd0cf434dU, 0xd34c28bfU, 0x27bf78acU, 0x243c135eU
+      /* 16 */  , 0x6fc75e10U, 0x6c4435e2U, 0x98b765f1U, 0x9b340e03U, 0x7050c4d7U, 0x73d3af25U, 0x8720ff36U, 0x84a394c4U
+      /* 24 */  , 0xa09f879aU, 0xa31cec68U, 0x57efbc7bU, 0x546cd789U, 0xbf081d5dU, 0xbc8b76afU, 0x487826bcU, 0x4bfb4d4eU
+      /* 32 */  , 0xde8ebd20U, 0xdd0dd6d2U, 0x29fe86c1U, 0x2a7ded33U, 0xc11927e7U, 0xc29a4c15U, 0x36691c06U, 0x35ea77f4U
+      /* 40 */  , 0x11d664aaU, 0x12550f58U, 0xe6a65f4bU, 0xe52534b9U, 0x0e41fe6dU, 0x0dc2959fU, 0xf931c58cU, 0xfab2ae7eU
+      /* 48 */  , 0xb149e330U, 0xb2ca88c2U, 0x4639d8d1U, 0x45bab323U, 0xaede79f7U, 0xad5d1205U, 0x59ae4216U, 0x5a2d29e4U
+      /* 56 */  , 0x7e113abaU, 0x7d925148U, 0x8961015bU, 0x8ae26aa9U, 0x6186a07dU, 0x6205cb8fU, 0x96f69b9cU, 0x9575f06eU
+      /* 64 */  , 0xbc1d7b41U, 0xbf9e10b3U, 0x4b6d40a0U, 0x48ee2b52U, 0xa38ae186U, 0xa0098a74U, 0x54fada67U, 0x5779b195U
+      /* 72 */  , 0x7345a2cbU, 0x70c6c939U, 0x8435992aU, 0x87b6f2d8U, 0x6cd2380cU, 0x6f5153feU, 0x9ba203edU, 0x9821681fU
+      /* 80 */  , 0xd3da2551U, 0xd0594ea3U, 0x24aa1eb0U, 0x27297542U, 0xcc4dbf96U, 0xcfced464U, 0x3b3d8477U, 0x38beef85U
+      /* 88 */  , 0x1c82fcdbU, 0x1f019729U, 0xebf2c73aU, 0xe871acc8U, 0x0315661cU, 0x00960deeU, 0xf4655dfdU, 0xf7e6360fU
+      /* 96 */  , 0x6293c661U, 0x6110ad93U, 0x95e3fd80U, 0x96609672U, 0x7d045ca6U, 0x7e873754U, 0x8a746747U, 0x89f70cb5U
+      /* 104 */  , 0xadcb1febU, 0xae487419U, 0x5abb240aU, 0x59384ff8U, 0xb25c852cU, 0xb1dfeedeU, 0x452cbecdU, 0x46afd53fU
+      /* 112 */  , 0x0d549871U, 0x0ed7f383U, 0xfa24a390U, 0xf9a7c862U, 0x12c302b6U, 0x11406944U, 0xe5b33957U, 0xe63052a5U
+      /* 120 */  , 0xc20c41fbU, 0xc18f2a09U, 0x357c7a1aU, 0x36ff11e8U, 0xdd9bdb3cU, 0xde18b0ceU, 0x2aebe0ddU, 0x29688b2fU
+      /* 128 */  , 0x783bf682U, 0x7bb89d70U, 0x8f4bcd63U, 0x8cc8a691U, 0x67ac6c45U, 0x642f07b7U, 0x90dc57a4U, 0x935f3c56U
+      /* 136 */  , 0xb7632f08U, 0xb4e044faU, 0x401314e9U, 0x43907f1bU, 0xa8f4b5cfU, 0xab77de3dU, 0x5f848e2eU, 0x5c07e5dcU
+      /* 144 */  , 0x17fca892U, 0x147fc360U, 0xe08c9373U, 0xe30ff881U, 0x086b3255U, 0x0be859a7U, 0xff1b09b4U, 0xfc986246U
+      /* 152 */  , 0xd8a47118U, 0xdb271aeaU, 0x2fd44af9U, 0x2c57210bU, 0xc733ebdfU, 0xc4b0802dU, 0x3043d03eU, 0x33c0bbccU
+      /* 160 */  , 0xa6b54ba2U, 0xa5362050U, 0x51c57043U, 0x52461bb1U, 0xb922d165U, 0xbaa1ba97U, 0x4e52ea84U, 0x4dd18176U
+      /* 168 */  , 0x69ed9228U, 0x6a6ef9daU, 0x9e9da9c9U, 0x9d1ec23bU, 0x767a08efU, 0x75f9631dU, 0x810a330eU, 0x828958fcU
+      /* 176 */  , 0xc97215b2U, 0xcaf17e40U, 0x3e022e53U, 0x3d8145a1U, 0xd6e58f75U, 0xd566e487U, 0x2195b494U, 0x2216df66U
+      /* 184 */  , 0x062acc38U, 0x05a9a7caU, 0xf15af7d9U, 0xf2d99c2bU, 0x19bd56ffU, 0x1a3e3d0dU, 0xeecd6d1eU, 0xed4e06ecU
+      /* 192 */  , 0xc4268dc3U, 0xc7a5e631U, 0x3356b622U, 0x30d5ddd0U, 0xdbb11704U, 0xd8327cf6U, 0x2cc12ce5U, 0x2f424717U
+      /* 200 */  , 0x0b7e5449U, 0x08fd3fbbU, 0xfc0e6fa8U, 0xff8d045aU, 0x14e9ce8eU, 0x176aa57cU, 0xe399f56fU, 0xe01a9e9dU
+      /* 208 */  , 0xabe1d3d3U, 0xa862b821U, 0x5c91e832U, 0x5f1283c0U, 0xb4764914U, 0xb7f522e6U, 0x430672f5U, 0x40851907U
+      /* 216 */  , 0x64b90a59U, 0x673a61abU, 0x93c931b8U, 0x904a5a4aU, 0x7b2e909eU, 0x78adfb6cU, 0x8c5eab7fU, 0x8fddc08dU
+      /* 224 */  , 0x1aa830e3U, 0x192b5b11U, 0xedd80b02U, 0xee5b60f0U, 0x053faa24U, 0x06bcc1d6U, 0xf24f91c5U, 0xf1ccfa37U
+      /* 232 */  , 0xd5f0e969U, 0xd673829bU, 0x2280d288U, 0x2103b97aU, 0xca6773aeU, 0xc9e4185cU, 0x3d17484fU, 0x3e9423bdU
+      /* 240 */  , 0x756f6ef3U, 0x76ec0501U, 0x821f5512U, 0x819c3ee0U, 0x6af8f434U, 0x697b9fc6U, 0x9d88cfd5U, 0x9e0ba427U
+      /* 248 */  , 0xba37b779U, 0xb9b4dc8bU, 0x4d478c98U, 0x4ec4e76aU, 0xa5a02dbeU, 0xa623464cU, 0x52d0165fU, 0x51537dadU
+    }
+    ,
+    /* CRC32C table 5 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x7798a213U, 0xee304527U, 0x99a8e734U, 0xdc618a4eU, 0xabf9285dU, 0x3251cf69U, 0x45c96d7aU
+      /* 8 */  , 0xb8c3149dU, 0xcf5bb68eU, 0x56f351baU, 0x216bf3a9U, 0x64a29ed3U, 0x133a3cc0U, 0x8a92dbf4U, 0xfd0a79e7U
+      /* 16 */  , 0x81f1c53fU, 0xf669672cU, 0x6fc18018U, 0x1859220bU, 0x5d904f71U, 0x2a08ed62U, 0xb3a00a56U, 0xc438a845U
+      /* 24 */  , 0x3932d1a2U, 0x4eaa73b1U, 0xd7029485U, 0xa09a3696U, 0xe5535becU, 0x92cbf9ffU, 0x0b631ecbU, 0x7cfbbcd8U
+      /* 32 */  , 0x02e38b7fU, 0x757b296cU, 0xecd3ce58U, 0x9b4b6c4bU, 0xde820131U, 0xa91aa322U, 0x30b24416U, 0x472ae605U
+      /* 40 */  , 0xba209fe2U, 0xcdb83df1U, 0x5410dac5U, 0x238878d6U, 0x664115acU, 0x11d9b7bfU, 0x8871508bU, 0xffe9f298U
+      /* 48 */  , 0x83124e40U, 0xf48aec53U, 0x6d220b67U, 0x1abaa974U, 0x5f73c40eU, 0x28eb661dU, 0xb1438129U, 0xc6db233aU
+      /* 56 */  , 0x3bd15addU, 0x4c49f8ceU, 0xd5e11ffaU, 0xa279bde9U, 0xe7b0d093U, 0x90287280U, 0x098095b4U, 0x7e1837a7U
+      /* 64 */  , 0x04c617ffU, 0x735eb5ecU, 0xeaf652d8U, 0x9d6ef0cbU, 0xd8a79db1U, 0xaf3f3fa2U, 0x3697d896U, 0x410f7a85U
+      /* 72 */  , 0xbc050362U, 0xcb9da171U, 0x52354645U, 0x25ade456U, 0x6064892cU, 0x17fc2b3fU, 0x8e54cc0bU, 0xf9cc6e18U
+      /* 80 */  , 0x8537d2c0U, 0xf2af70d3U, 0x6b0797e7U, 0x1c9f35f4U, 0x5956588eU, 0x2ecefa9dU, 0xb7661da9U, 0xc0febfbaU
+      /* 88 */  , 0x3df4c65dU, 0x4a6c644eU, 0xd3c4837aU, 0xa45c2169U, 0xe1954c13U, 0x960dee00U, 0x0fa50934U, 0x783dab27U
+      /* 96 */  , 0x06259c80U, 0x71bd3e93U, 0xe815d9a7U, 0x9f8d7bb4U, 0xda4416ceU, 0xaddcb4ddU, 0x347453e9U, 0x43ecf1faU
+      /* 104 */  , 0xbee6881dU, 0xc97e2a0eU, 0x50d6cd3aU, 0x274e6f29U, 0x62870253U, 0x151fa040U, 0x8cb74774U, 0xfb2fe567U
+      /* 112 */  , 0x87d459bfU, 0xf04cfbacU, 0x69e41c98U, 0x1e7cbe8bU, 0x5bb5d3f1U, 0x2c2d71e2U, 0xb58596d6U, 0xc21d34c5U
+      /* 120 */  , 0x3f174d22U, 0x488fef31U, 0xd1270805U, 0xa6bfaa16U, 0xe376c76cU, 0x94ee657fU, 0x0d46824bU, 0x7ade2058U
+      /* 128 */  , 0xf9fac3fbU, 0x8e6261e8U, 0x17ca86dcU, 0x605224cfU, 0x259b49b5U, 0x5203eba6U, 0xcbab0c92U, 0xbc33ae81U
+      /* 136 */  , 0x4139d766U, 0x36a17575U, 0xaf099241U, 0xd8913052U, 0x9d585d28U, 0xeac0ff3bU, 0x7368180fU, 0x04f0ba1cU
+      /* 144 */  , 0x780b06c4U, 0x0f93a4d7U, 0x963b43e3U, 0xe1a3e1f0U, 0xa46a8c8aU, 0xd3f22e99U, 0x4a5ac9adU, 0x3dc26bbeU
+      /* 152 */  , 0xc0c81259U, 0xb750b04aU, 0x2ef8577eU, 0x5960f56dU, 0x1ca99817U, 0x6b313a04U, 0xf299dd30U, 0x85017f23U
+      /* 160 */  , 0xfb194884U, 0x8c81ea97U, 0x15290da3U, 0x62b1afb0U, 0x2778c2caU, 0x50e060d9U, 0xc94887edU, 0xbed025feU
+      /* 168 */  , 0x43da5c19U, 0x3442fe0aU, 0xadea193eU, 0xda72bb2dU, 0x9fbbd657U, 0xe8237444U, 0x718b9370U, 0x06133163U
+      /* 176 */  , 0x7ae88dbbU, 0x0d702fa8U, 0x94d8c89cU, 0xe3406a8fU, 0xa68907f5U, 0xd111a5e6U, 0x48b942d2U, 0x3f21e0c1U
+      /* 184 */  , 0xc22b9926U, 0xb5b33b35U, 0x2c1bdc01U, 0x5b837e12U, 0x1e4a1368U, 0x69d2b17bU, 0xf07a564fU, 0x87e2f45cU
+      /* 192 */  , 0xfd3cd404U, 0x8aa47617U, 0x130c9123U, 0x64943330U, 0x215d5e4aU, 0x56c5fc59U, 0xcf6d1b6dU, 0xb8f5b97eU
+      /* 200 */  , 0x45ffc099U, 0x3267628aU, 0xabcf85beU, 0xdc5727adU, 0x999e4ad7U, 0xee06e8c4U, 0x77ae0ff0U, 0x0036ade3U
+      /* 208 */  , 0x7ccd113bU, 0x0b55b328U, 0x92fd541cU, 0xe565f60fU, 0xa0ac9b75U, 0xd7343966U, 0x4e9cde52U, 0x39047c41U
+      /* 216 */  , 0xc40e05a6U, 0xb396a7b5U, 0x2a3e4081U, 0x5da6e292U, 0x186f8fe8U, 0x6ff72dfbU, 0xf65fcacfU, 0x81c768dcU
+      /* 224 */  , 0xffdf5f7bU, 0x8847fd68U, 0x11ef1a5cU, 0x6677b84fU, 0x23bed535U, 0x54267726U, 0xcd8e9012U, 0xba163201U
+      /* 232 */  , 0x471c4be6U, 0x3084e9f5U, 0xa92c0ec1U, 0xdeb4acd2U, 0x9b7dc1a8U, 0xece563bbU, 0x754d848fU, 0x02d5269cU
+      /* 240 */  , 0x7e2e9a44U, 0x09b63857U, 0x901edf63U, 0xe7867d70U, 0xa24f100aU, 0xd5d7b219U, 0x4c7f552dU, 0x3be7f73eU
+      /* 248 */  , 0xc6ed8ed9U, 0xb1752ccaU, 0x28ddcbfeU, 0x5f4569edU, 0x1a8c0497U, 0x6d14a684U, 0xf4bc41b0U, 0x8324e3a3U
+    }
+    ,
+    /* CRC32C table 6 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0x7e9241a5U, 0x0d526f4fU, 0x73c02eeaU, 0x1aa4de9eU, 0x64369f3bU, 0x17f6b1d1U, 0x6964f074U
+      /* 8 */  , 0xc53e5138U, 0xbbac109dU, 0xc86c3e77U, 0xb6fe7fd2U, 0xdf9a8fa6U, 0xa108ce03U, 0xd2c8e0e9U, 0xac5aa14cU
+      /* 16 */  , 0x8a7da270U, 0xf4efe3d5U, 0x872fcd3fU, 0xf9bd8c9aU, 0x90d97ceeU, 0xee4b3d4bU, 0x9d8b13a1U, 0xe3195204U
+      /* 24 */  , 0x4f43f348U, 0x31d1b2edU, 0x42119c07U, 0x3c83dda2U, 0x55e72dd6U, 0x2b756c73U, 0x58b54299U, 0x2627033cU
+      /* 32 */  , 0x14fb44e1U, 0x6a690544U, 0x19a92baeU, 0x673b6a0bU, 0x0e5f9a7fU, 0x70cddbdaU, 0x030df530U, 0x7d9fb495U
+      /* 40 */  , 0xd1c515d9U, 0xaf57547cU, 0xdc977a96U, 0xa2053b33U, 0xcb61cb47U, 0xb5f38ae2U, 0xc633a408U, 0xb8a1e5adU
+      /* 48 */  , 0x9e86e691U, 0xe014a734U, 0x93d489deU, 0xed46c87bU, 0x8422380fU, 0xfab079aaU, 0x89705740U, 0xf7e216e5U
+      /* 56 */  , 0x5bb8b7a9U, 0x252af60cU, 0x56ead8e6U, 0x28789943U, 0x411c6937U, 0x3f8e2892U, 0x4c4e0678U, 0x32dc47ddU
+      /* 64 */  , 0xd98065c7U, 0xa7122462U, 0xd4d20a88U, 0xaa404b2dU, 0xc324bb59U, 0xbdb6fafcU, 0xce76d416U, 0xb0e495b3U
+      /* 72 */  , 0x1cbe34ffU, 0x622c755aU, 0x11ec5bb0U, 0x6f7e1a15U, 0x061aea61U, 0x7888abc4U, 0x0b48852eU, 0x75dac48bU
+      /* 80 */  , 0x53fdc7b7U, 0x2d6f8612U, 0x5eafa8f8U, 0x203de95dU, 0x49591929U, 0x37cb588cU, 0x440b7666U, 0x3a9937c3U
+      /* 88 */  , 0x96c3968fU, 0xe851d72aU, 0x9b91f9c0U, 0xe503b865U, 0x8c674811U, 0xf2f509b4U, 0x8135275eU, 0xffa766fbU
+      /* 96 */  , 0xcd7b2126U, 0xb3e96083U, 0xc0294e69U, 0xbebb0fccU, 0xd7dfffb8U, 0xa94dbe1dU, 0xda8d90f7U, 0xa41fd152U
+      /* 104 */  , 0x0845701eU, 0x76d731bbU, 0x05171f51U, 0x7b855ef4U, 0x12e1ae80U, 0x6c73ef25U, 0x1fb3c1cfU, 0x6121806aU
+      /* 112 */  , 0x47068356U, 0x3994c2f3U, 0x4a54ec19U, 0x34c6adbcU, 0x5da25dc8U, 0x23301c6dU, 0x50f03287U, 0x2e627322U
+      /* 120 */  , 0x8238d26eU, 0xfcaa93cbU, 0x8f6abd21U, 0xf1f8fc84U, 0x989c0cf0U, 0xe60e4d55U, 0x95ce63bfU, 0xeb5c221aU
+      /* 128 */  , 0x4377278bU, 0x3de5662eU, 0x4e2548c4U, 0x30b70961U, 0x59d3f915U, 0x2741b8b0U, 0x5481965aU, 0x2a13d7ffU
+      /* 136 */  , 0x864976b3U, 0xf8db3716U, 0x8b1b19fcU, 0xf5895859U, 0x9ceda82dU, 0xe27fe988U, 0x91bfc762U, 0xef2d86c7U
+      /* 144 */  , 0xc90a85fbU, 0xb798c45eU, 0xc458eab4U, 0xbacaab11U, 0xd3ae5b65U, 0xad3c1ac0U, 0xdefc342aU, 0xa06e758fU
+      /* 152 */  , 0x0c34d4c3U, 0x72a69566U, 0x0166bb8cU, 0x7ff4fa29U, 0x16900a5dU, 0x68024bf8U, 0x1bc26512U, 0x655024b7U
+      /* 160 */  , 0x578c636aU, 0x291e22cfU, 0x5ade0c25U, 0x244c4d80U, 0x4d28bdf4U, 0x33bafc51U, 0x407ad2bbU, 0x3ee8931eU
+      /* 168 */  , 0x92b23252U, 0xec2073f7U, 0x9fe05d1dU, 0xe1721cb8U, 0x8816ecccU, 0xf684ad69U, 0x85448383U, 0xfbd6c226U
+      /* 176 */  , 0xddf1c11aU, 0xa36380bfU, 0xd0a3ae55U, 0xae31eff0U, 0xc7551f84U, 0xb9c75e21U, 0xca0770cbU, 0xb495316eU
+      /* 184 */  , 0x18cf9022U, 0x665dd187U, 0x159dff6dU, 0x6b0fbec8U, 0x026b4ebcU, 0x7cf90f19U, 0x0f3921f3U, 0x71ab6056U
+      /* 192 */  , 0x9af7424cU, 0xe46503e9U, 0x97a52d03U, 0xe9376ca6U, 0x80539cd2U, 0xfec1dd77U, 0x8d01f39dU, 0xf393b238U
+      /* 200 */  , 0x5fc91374U, 0x215b52d1U, 0x529b7c3bU, 0x2c093d9eU, 0x456dcdeaU, 0x3bff8c4fU, 0x483fa2a5U, 0x36ade300U
+      /* 208 */  , 0x108ae03cU, 0x6e18a199U, 0x1dd88f73U, 0x634aced6U, 0x0a2e3ea2U, 0x74bc7f07U, 0x077c51edU, 0x79ee1048U
+      /* 216 */  , 0xd5b4b104U, 0xab26f0a1U, 0xd8e6de4bU, 0xa6749feeU, 0xcf106f9aU, 0xb1822e3fU, 0xc24200d5U, 0xbcd04170U
+      /* 224 */  , 0x8e0c06adU, 0xf09e4708U, 0x835e69e2U, 0xfdcc2847U, 0x94a8d833U, 0xea3a9996U, 0x99fab77cU, 0xe768f6d9U
+      /* 232 */  , 0x4b325795U, 0x35a01630U, 0x466038daU, 0x38f2797fU, 0x5196890bU, 0x2f04c8aeU, 0x5cc4e644U, 0x2256a7e1U
+      /* 240 */  , 0x0471a4ddU, 0x7ae3e578U, 0x0923cb92U, 0x77b18a37U, 0x1ed57a43U, 0x60473be6U, 0x1387150cU, 0x6d1554a9U
+      /* 248 */  , 0xc14ff5e5U, 0xbfddb440U, 0xcc1d9aaaU, 0xb28fdb0fU, 0xdbeb2b7bU, 0xa5796adeU, 0xd6b94434U, 0xa82b0591U
+    }
+    ,
+    /* CRC32C table 7 for quad-bytes (  big-endian ), auto-generated. DO NOT MODIFY! */
+    {
+      /* 0 */    0x00000000U, 0xb8aa45ddU, 0x812367bfU, 0x39892262U, 0xf331227bU, 0x4b9b67a6U, 0x721245c4U, 0xcab80019U
+      /* 8 */  , 0xe66344f6U, 0x5ec9012bU, 0x67402349U, 0xdfea6694U, 0x1552668dU, 0xadf82350U, 0x94710132U, 0x2cdb44efU
+      /* 16 */  , 0x3db164e9U, 0x851b2134U, 0xbc920356U, 0x0438468bU, 0xce804692U, 0x762a034fU, 0x4fa3212dU, 0xf70964f0U
+      /* 24 */  , 0xdbd2201fU, 0x637865c2U, 0x5af147a0U, 0xe25b027dU, 0x28e30264U, 0x904947b9U, 0xa9c065dbU, 0x116a2006U
+      /* 32 */  , 0x8b1425d7U, 0x33be600aU, 0x0a374268U, 0xb29d07b5U, 0x782507acU, 0xc08f4271U, 0xf9066013U, 0x41ac25ceU
+      /* 40 */  , 0x6d776121U, 0xd5dd24fcU, 0xec54069eU, 0x54fe4343U, 0x9e46435aU, 0x26ec0687U, 0x1f6524e5U, 0xa7cf6138U
+      /* 48 */  , 0xb6a5413eU, 0x0e0f04e3U, 0x37862681U, 0x8f2c635cU, 0x45946345U, 0xfd3e2698U, 0xc4b704faU, 0x7c1d4127U
+      /* 56 */  , 0x50c605c8U, 0xe86c4015U, 0xd1e56277U, 0x694f27aaU, 0xa3f727b3U, 0x1b5d626eU, 0x22d4400cU, 0x9a7e05d1U
+      /* 64 */  , 0xe75fa6abU, 0x5ff5e376U, 0x667cc114U, 0xded684c9U, 0x146e84d0U, 0xacc4c10dU, 0x954de36fU, 0x2de7a6b2U
+      /* 72 */  , 0x013ce25dU, 0xb996a780U, 0x801f85e2U, 0x38b5c03fU, 0xf20dc026U, 0x4aa785fbU, 0x732ea799U, 0xcb84e244U
+      /* 80 */  , 0xdaeec242U, 0x6244879fU, 0x5bcda5fdU, 0xe367e020U, 0x29dfe039U, 0x9175a5e4U, 0xa8fc8786U, 0x1056c25bU
+      /* 88 */  , 0x3c8d86b4U, 0x8427c369U, 0xbdaee10bU, 0x0504a4d6U, 0xcfbca4cfU, 0x7716e112U, 0x4e9fc370U, 0xf63586adU
+      /* 96 */  , 0x6c4b837cU, 0xd4e1c6a1U, 0xed68e4c3U, 0x55c2a11eU, 0x9f7aa107U, 0x27d0e4daU, 0x1e59c6b8U, 0xa6f38365U
+      /* 104 */  , 0x8a28c78aU, 0x32828257U, 0x0b0ba035U, 0xb3a1e5e8U, 0x7919e5f1U, 0xc1b3a02cU, 0xf83a824eU, 0x4090c793U
+      /* 112 */  , 0x51fae795U, 0xe950a248U, 0xd0d9802aU, 0x6873c5f7U, 0xa2cbc5eeU, 0x1a618033U, 0x23e8a251U, 0x9b42e78cU
+      /* 120 */  , 0xb799a363U, 0x0f33e6beU, 0x36bac4dcU, 0x8e108101U, 0x44a88118U, 0xfc02c4c5U, 0xc58be6a7U, 0x7d21a37aU
+      /* 128 */  , 0x3fc9a052U, 0x8763e58fU, 0xbeeac7edU, 0x06408230U, 0xccf88229U, 0x7452c7f4U, 0x4ddbe596U, 0xf571a04bU
+      /* 136 */  , 0xd9aae4a4U, 0x6100a179U, 0x5889831bU, 0xe023c6c6U, 0x2a9bc6dfU, 0x92318302U, 0xabb8a160U, 0x1312e4bdU
+      /* 144 */  , 0x0278c4bbU, 0xbad28166U, 0x835ba304U, 0x3bf1e6d9U, 0xf149e6c0U, 0x49e3a31dU, 0x706a817fU, 0xc8c0c4a2U
+      /* 152 */  , 0xe41b804dU, 0x5cb1c590U, 0x6538e7f2U, 0xdd92a22fU, 0x172aa236U, 0xaf80e7ebU, 0x9609c589U, 0x2ea38054U
+      /* 160 */  , 0xb4dd8585U, 0x0c77c058U, 0x35fee23aU, 0x8d54a7e7U, 0x47eca7feU, 0xff46e223U, 0xc6cfc041U, 0x7e65859cU
+      /* 168 */  , 0x52bec173U, 0xea1484aeU, 0xd39da6ccU, 0x6b37e311U, 0xa18fe308U, 0x1925a6d5U, 0x20ac84b7U, 0x9806c16aU
+      /* 176 */  , 0x896ce16cU, 0x31c6a4b1U, 0x084f86d3U, 0xb0e5c30eU, 0x7a5dc317U, 0xc2f786caU, 0xfb7ea4a8U, 0x43d4e175U
+      /* 184 */  , 0x6f0fa59aU, 0xd7a5e047U, 0xee2cc225U, 0x568687f8U, 0x9c3e87e1U, 0x2494c23cU, 0x1d1de05eU, 0xa5b7a583U
+      /* 192 */  , 0xd89606f9U, 0x603c4324U, 0x59b56146U, 0xe11f249bU, 0x2ba72482U, 0x930d615fU, 0xaa84433dU, 0x122e06e0U
+      /* 200 */  , 0x3ef5420fU, 0x865f07d2U, 0xbfd625b0U, 0x077c606dU, 0xcdc46074U, 0x756e25a9U, 0x4ce707cbU, 0xf44d4216U
+      /* 208 */  , 0xe5276210U, 0x5d8d27cdU, 0x640405afU, 0xdcae4072U, 0x1616406bU, 0xaebc05b6U, 0x973527d4U, 0x2f9f6209U
+      /* 216 */  , 0x034426e6U, 0xbbee633bU, 0x82674159U, 0x3acd0484U, 0xf075049dU, 0x48df4140U, 0x71566322U, 0xc9fc26ffU
+      /* 224 */  , 0x5382232eU, 0xeb2866f3U, 0xd2a14491U, 0x6a0b014cU, 0xa0b30155U, 0x18194488U, 0x219066eaU, 0x993a2337U
+      /* 232 */  , 0xb5e167d8U, 0x0d4b2205U, 0x34c20067U, 0x8c6845baU, 0x46d045a3U, 0xfe7a007eU, 0xc7f3221cU, 0x7f5967c1U
+      /* 240 */  , 0x6e3347c7U, 0xd699021aU, 0xef102078U, 0x57ba65a5U, 0x9d0265bcU, 0x25a82061U, 0x1c210203U, 0xa48b47deU
+      /* 248 */  , 0x88500331U, 0x30fa46ecU, 0x0973648eU, 0xb1d92153U, 0x7b61214aU, 0xc3cb6497U, 0xfa4246f5U, 0x42e80328U
+    }
+  #endif
+  };
--- a/hotspot/src/cpu/s390/vm/stubRoutines_s390.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/stubRoutines_s390.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -68,12 +68,11 @@
   };
 
  private:
-  static address _handler_for_unsafe_access_entry;
-
   static int _atomic_memory_operation_lock;
 
   static address _partial_subtype_check;
   static juint   _crc_table[CRC32_TABLES][CRC32_COLUMN_SIZE];
+  static juint   _crc32c_table[CRC32_TABLES][CRC32_COLUMN_SIZE];
 
   // Comapct string intrinsics: Translate table for string inflate intrinsic. Used by trot instruction.
   static address _trot_table_addr;
@@ -91,11 +90,11 @@
   static int atomic_memory_operation_lock() { return _atomic_memory_operation_lock; }
   static void set_atomic_memory_operation_lock(int value) { _atomic_memory_operation_lock = value; }
 
-  static address handler_for_unsafe_access_entry()        { return _handler_for_unsafe_access_entry; }
-
   static address partial_subtype_check()                  { return _partial_subtype_check; }
 
+  static void generate_load_absolute_address(MacroAssembler* masm, Register table, address table_addr, uint64_t table_contents);
   static void generate_load_crc_table_addr(MacroAssembler* masm, Register table);
+  static void generate_load_crc32c_table_addr(MacroAssembler* masm, Register table);
 
   // Comapct string intrinsics: Translate table for string inflate intrinsic. Used by trot instruction.
   static void generate_load_trot_table_addr(MacroAssembler* masm, Register table);
--- a/hotspot/src/cpu/s390/vm/templateInterpreterGenerator_s390.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/templateInterpreterGenerator_s390.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -642,13 +642,6 @@
   return entry;
 }
 
-// Unused, should never pass by.
-address TemplateInterpreterGenerator::generate_continuation_for (TosState state) {
-  address entry = __ pc();
-  __ should_not_reach_here();
-  return entry;
-}
-
 address TemplateInterpreterGenerator::generate_return_entry_for (TosState state, int step, size_t index_size) {
   address entry = __ pc();
 
@@ -683,6 +676,10 @@
   __ z_llgc(size, Address(cache, offset, flags_offset+(sizeof(size_t)-1)));
   __ z_sllg(size, size, Interpreter::logStackElementSize); // Each argument size in bytes.
   __ z_agr(Z_esp, size);                                   // Pop arguments.
+
+  __ check_and_handle_popframe(Z_thread);
+  __ check_and_handle_earlyret(Z_thread);
+
   __ dispatch_next(state, step);
 
   BLOCK_COMMENT("} return_entry");
@@ -1967,7 +1964,7 @@
     __ z_llgf(crc, 2 * wordSize, argP); // Current crc state, zero extend to 64 bit to have a clean register.
 
     StubRoutines::zarch::generate_load_crc_table_addr(_masm, table);
-    __ kernel_crc32_singleByte(crc, data, dataLen, table, Z_R1);
+    __ kernel_crc32_singleByte(crc, data, dataLen, table, Z_R1, true);
 
     // Restore caller sp for c2i case.
     __ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started.
@@ -2023,10 +2020,10 @@
       // data = buf + off
       BLOCK_COMMENT("CRC32_updateByteBuffer {");
       __ z_llgf(crc,    5*wordSize, argP);  // current crc state
-      __ z_lg(data,    3*wordSize, argP);   // start of byte buffer
+      __ z_lg(data,     3*wordSize, argP);  // start of byte buffer
       __ z_agf(data,    2*wordSize, argP);  // Add byte buffer offset.
       __ z_lgf(dataLen, 1*wordSize, argP);  // #bytes to process
-    } else {                         // Used for "updateBytes update".
+    } else {                                                         // Used for "updateBytes update".
       // crc     @ (SP + 4W) (32bit)
       // buf     @ (SP + 3W) (64bit ptr to byte array)
       // off     @ (SP + 2W) (32bit)
@@ -2034,7 +2031,7 @@
       // data = buf + off + base_offset
       BLOCK_COMMENT("CRC32_updateBytes {");
       __ z_llgf(crc,    4*wordSize, argP);  // current crc state
-      __ z_lg(data,    3*wordSize, argP);   // start of byte buffer
+      __ z_lg(data,     3*wordSize, argP);  // start of byte buffer
       __ z_agf(data,    2*wordSize, argP);  // Add byte buffer offset.
       __ z_lgf(dataLen, 1*wordSize, argP);  // #bytes to process
       __ z_aghi(data, arrayOopDesc::base_offset_in_bytes(T_BYTE));
@@ -2044,7 +2041,7 @@
 
     __ resize_frame(-(6*8), Z_R0, true); // Resize frame to provide add'l space to spill 5 registers.
     __ z_stmg(t0, t3, 1*8, Z_SP);        // Spill regs 10..13 to make them available as work registers.
-    __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3);
+    __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, true);
     __ z_lmg(t0, t3, 1*8, Z_SP);         // Spill regs 10..13 back from stack.
 
     // Restore caller sp for c2i case.
@@ -2063,8 +2060,73 @@
   return NULL;
 }
 
-// Not supported
+
+// Method entry for static native methods:
+//   int java.util.zip.CRC32C.updateBytes(int crc, byte[] b, int off, int len)
+//   int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long buf, int off, int len)
 address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
+
+  if (UseCRC32CIntrinsics) {
+    uint64_t entry_off = __ offset();
+
+    // We don't generate local frame and don't align stack because
+    // we call stub code and there is no safepoint on this path.
+
+    // Load parameters.
+    // Z_esp is callers operand stack pointer, i.e. it points to the parameters.
+    const Register argP    = Z_esp;
+    const Register crc     = Z_ARG1;  // crc value
+    const Register data    = Z_ARG2;  // address of java byte array
+    const Register dataLen = Z_ARG3;  // source data len
+    const Register table   = Z_ARG4;  // address of crc32 table
+    const Register t0      = Z_R10;   // work reg for kernel* emitters
+    const Register t1      = Z_R11;   // work reg for kernel* emitters
+    const Register t2      = Z_R12;   // work reg for kernel* emitters
+    const Register t3      = Z_R13;   // work reg for kernel* emitters
+
+    // Arguments are reversed on java expression stack.
+    // Calculate address of start element.
+    if (kind == Interpreter::java_util_zip_CRC32C_updateDirectByteBuffer) { // Used for "updateByteBuffer direct".
+      // crc     @ (SP + 5W) (32bit)
+      // buf     @ (SP + 3W) (64bit ptr to long array)
+      // off     @ (SP + 2W) (32bit)
+      // dataLen @ (SP + 1W) (32bit)
+      // data = buf + off
+      BLOCK_COMMENT("CRC32C_updateDirectByteBuffer {");
+      __ z_llgf(crc,    5*wordSize, argP);  // current crc state
+      __ z_lg(data,     3*wordSize, argP);  // start of byte buffer
+      __ z_agf(data,    2*wordSize, argP);  // Add byte buffer offset.
+      __ z_lgf(dataLen, 1*wordSize, argP);  // #bytes to process
+    } else {                                                                // Used for "updateBytes update".
+      // crc     @ (SP + 4W) (32bit)
+      // buf     @ (SP + 3W) (64bit ptr to byte array)
+      // off     @ (SP + 2W) (32bit)
+      // dataLen @ (SP + 1W) (32bit)
+      // data = buf + off + base_offset
+      BLOCK_COMMENT("CRC32C_updateBytes {");
+      __ z_llgf(crc,    4*wordSize, argP);  // current crc state
+      __ z_lg(data,     3*wordSize, argP);  // start of byte buffer
+      __ z_agf(data,    2*wordSize, argP);  // Add byte buffer offset.
+      __ z_lgf(dataLen, 1*wordSize, argP);  // #bytes to process
+      __ z_aghi(data, arrayOopDesc::base_offset_in_bytes(T_BYTE));
+    }
+
+    StubRoutines::zarch::generate_load_crc32c_table_addr(_masm, table);
+
+    __ resize_frame(-(6*8), Z_R0, true); // Resize frame to provide add'l space to spill 5 registers.
+    __ z_stmg(t0, t3, 1*8, Z_SP);        // Spill regs 10..13 to make them available as work registers.
+    __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, false);
+    __ z_lmg(t0, t3, 1*8, Z_SP);         // Spill regs 10..13 back from stack.
+
+    // Restore caller sp for c2i case.
+    __ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started.
+
+    __ z_br(Z_R14);
+
+    BLOCK_COMMENT("} CRC32C_update{Bytes|DirectByteBuffer}");
+    return __ addr_at(entry_off);
+  }
+
   return NULL;
 }
 
--- a/hotspot/src/cpu/s390/vm/templateTable_s390.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/templateTable_s390.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -3466,7 +3466,7 @@
   __ z_sllg(index, index, exact_log2(vtableEntry::size_in_bytes()));
   __ mem2reg_opt(method,
                  Address(Z_tmp_2, index,
-                         InstanceKlass::vtable_start_offset() + in_ByteSize(vtableEntry::method_offset_in_bytes())));
+                         Klass::vtable_start_offset() + in_ByteSize(vtableEntry::method_offset_in_bytes())));
   __ profile_arguments_type(Z_ARG4, method, Z_ARG5, true);
   __ jump_from_interpreted(method, Z_ARG4);
   BLOCK_COMMENT("} invokevirtual_helper");
--- a/hotspot/src/cpu/s390/vm/vm_version_s390.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/vm_version_s390.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -111,13 +111,23 @@
     ContendedPaddingWidth = cache_line_size;
   }
 
-  // On z/Architecture, the CRC32 intrinsics had to be implemented "by hand".
-  // They cannot be based on the CHECKSUM instruction which has been there
-  // since the very beginning (of z/Architecture). It computes "some kind of" a checksum
-  // which has nothing to do with the CRC32 algorithm.
+  // On z/Architecture, the CRC32/CRC32C intrinsics are implemented "by hand".
+  // TODO: Provide implementation based on the vector instructions available from z13.
+  // Note: The CHECKSUM instruction, which has been there since the very beginning
+  //       (of z/Architecture), computes "some kind of" a checksum.
+  //       It has nothing to do with the CRC32 algorithm.
   if (FLAG_IS_DEFAULT(UseCRC32Intrinsics)) {
     FLAG_SET_DEFAULT(UseCRC32Intrinsics, true);
   }
+  if (FLAG_IS_DEFAULT(UseCRC32CIntrinsics)) {
+    FLAG_SET_DEFAULT(UseCRC32CIntrinsics, true);
+  }
+
+  // TODO: Provide implementation.
+  if (UseAdler32Intrinsics) {
+    warning("Adler32Intrinsics not available on this CPU.");
+    FLAG_SET_DEFAULT(UseAdler32Intrinsics, false);
+  }
 
   // On z/Architecture, we take UseAES as the general switch to enable/disable the AES intrinsics.
   // The specific, and yet to be defined, switches UseAESxxxIntrinsics will then be set
@@ -195,11 +205,6 @@
     FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
   }
 
-  if (UseAdler32Intrinsics) {
-    warning("Adler32Intrinsics not available on this CPU.");
-    FLAG_SET_DEFAULT(UseAdler32Intrinsics, false);
-  }
-
   if (FLAG_IS_DEFAULT(UseMultiplyToLenIntrinsic)) {
     FLAG_SET_DEFAULT(UseMultiplyToLenIntrinsic, true);
   }
--- a/hotspot/src/cpu/s390/vm/vtableStubs_s390.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/s390/vm/vtableStubs_s390.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -83,7 +83,7 @@
   __ load_klass(rcvr_klass, Z_ARG1);
 
   // Set method (in case of interpreted method), and destination address.
-  int entry_offset = in_bytes(InstanceKlass::vtable_start_offset()) +
+  int entry_offset = in_bytes(Klass::vtable_start_offset()) +
                      vtable_index * vtableEntry::size_in_bytes();
 
 #ifndef PRODUCT
@@ -96,8 +96,8 @@
     //                  worst case             actual size
     padding_bytes += __ load_const_size() - __ load_const_optimized_rtn_len(vtable_idx, vtable_index*vtableEntry::size_in_bytes(), true);
 
-    assert(Immediate::is_uimm12(in_bytes(InstanceKlass::vtable_length_offset())), "disp to large");
-    __ z_cl(vtable_idx, in_bytes(InstanceKlass::vtable_length_offset()), rcvr_klass);
+    assert(Immediate::is_uimm12(in_bytes(Klass::vtable_length_offset())), "disp to large");
+    __ z_cl(vtable_idx, in_bytes(Klass::vtable_length_offset()), rcvr_klass);
     __ z_brl(L);
     __ z_lghi(Z_ARG3, vtable_index);  // Debug code, don't optimize.
     __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), Z_ARG1, Z_ARG3, false);
@@ -187,11 +187,11 @@
   __ load_klass(rcvr_klass, Z_ARG1);
 
   // Load start of itable entries into itable_entry.
-  __ z_llgf(vtable_len, Address(rcvr_klass, InstanceKlass::vtable_length_offset()));
+  __ z_llgf(vtable_len, Address(rcvr_klass, Klass::vtable_length_offset()));
   __ z_sllg(vtable_len, vtable_len, exact_log2(vtableEntry::size_in_bytes()));
 
   // Loop over all itable entries until desired interfaceOop(Rinterface) found.
-  const int vtable_base_offset = in_bytes(InstanceKlass::vtable_start_offset());
+  const int vtable_base_offset = in_bytes(Klass::vtable_start_offset());
   // Count unused bytes.
   start_pc = __ pc();
   __ add2reg_with_index(itable_entry_addr, vtable_base_offset + itableOffsetEntry::interface_offset_in_bytes(), rcvr_klass, vtable_len);
--- a/hotspot/src/cpu/sparc/vm/interp_masm_sparc.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/sparc/vm/interp_masm_sparc.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -70,9 +70,6 @@
     bool            check_exception=true
   );
 
-  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);
 
@@ -80,6 +77,9 @@
   InterpreterMacroAssembler(CodeBuffer* c)
     : MacroAssembler(c) {}
 
+ virtual void check_and_handle_popframe(Register scratch_reg);
+ virtual void check_and_handle_earlyret(Register scratch_reg);
+
   void jump_to_entry(address entry);
 
   virtual void load_earlyret_value(TosState state);
--- a/hotspot/src/cpu/sparc/vm/jvmciCodeInstaller_sparc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/sparc/vm/jvmciCodeInstaller_sparc.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,7 @@
 
 void CodeInstaller::pd_patch_OopConstant(int pc_offset, Handle constant, TRAPS) {
   address pc = _instructions->start() + pc_offset;
-  Handle obj = HotSpotObjectConstantImpl::object(constant);
+  Handle obj(THREAD, HotSpotObjectConstantImpl::object(constant));
   jobject value = JNIHandles::make_local(obj());
   if (HotSpotObjectConstantImpl::compressed(constant)) {
 #ifdef _LP64
--- a/hotspot/src/cpu/sparc/vm/macroAssembler_sparc.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/sparc/vm/macroAssembler_sparc.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -604,15 +604,15 @@
     bool            check_exception=true    // flag which indicates if exception should be checked
   );
 
+ public:
+  MacroAssembler(CodeBuffer* code) : Assembler(code) {}
+
   // This routine should emit JVMTI PopFrame and ForceEarlyReturn handling code.
   // The implementation is only non-empty for the InterpreterMacroAssembler,
   // as only the interpreter handles and ForceEarlyReturn PopFrame requests.
   virtual void check_and_handle_popframe(Register scratch_reg);
   virtual void check_and_handle_earlyret(Register scratch_reg);
 
- public:
-  MacroAssembler(CodeBuffer* code) : Assembler(code) {}
-
   // Support for NULL-checks
   //
   // Generates code that causes a NULL OS exception if the content of reg is NULL.
--- a/hotspot/src/cpu/sparc/vm/metaspaceShared_sparc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-#include "precompiled.hpp"
-#include "asm/macroAssembler.inline.hpp"
-#include "asm/codeBuffer.hpp"
-#include "memory/metaspaceShared.hpp"
-
-// Generate the self-patching vtable method:
-//
-// This method will be called (as any other Klass virtual method) with
-// the Klass itself as the first argument.  Example:
-//
-//      oop obj;
-//      int size = obj->klass()->oop_size(this);
-//
-// for which the virtual method call is Klass::oop_size();
-//
-// The dummy method is called with the Klass object as the first
-// operand, and an object as the second argument.
-//
-
-//=====================================================================
-
-// All of the dummy methods in the vtable are essentially identical,
-// differing only by an ordinal constant, and they bear no relationship
-// to the original method which the caller intended. Also, there needs
-// to be 'vtbl_list_size' instances of the vtable in order to
-// differentiate between the 'vtable_list_size' original Klass objects.
-
-#define __ masm->
-
-void MetaspaceShared::generate_vtable_methods(void** vtbl_list,
-                                                   void** vtable,
-                                                   char** md_top,
-                                                   char* md_end,
-                                                   char** mc_top,
-                                                   char* mc_end) {
-
-  intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*);
-  *(intptr_t *)(*md_top) = vtable_bytes;
-  *md_top += sizeof(intptr_t);
-  void** dummy_vtable = (void**)*md_top;
-  *vtable = dummy_vtable;
-  *md_top += vtable_bytes;
-
-  // Get ready to generate dummy methods.
-
-  CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top);
-  MacroAssembler* masm = new MacroAssembler(&cb);
-
-  Label common_code;
-  for (int i = 0; i < vtbl_list_size; ++i) {
-    for (int j = 0; j < num_virtuals; ++j) {
-      dummy_vtable[num_virtuals * i + j] = (void*)masm->pc();
-      __ save(SP, -256, SP);
-      int offset = (i << 8) + j;
-      Register src = G0;
-      if (!Assembler::is_simm13(offset)) {
-        __ sethi(offset, L0);
-        src = L0;
-        offset = offset & ((1 << 10) - 1);
-      }
-      __ brx(Assembler::always, false, Assembler::pt, common_code);
-
-      // Load L0 with a value indicating vtable/offset pair.
-      // -- bits[ 7..0]  (8 bits) which virtual method in table?
-      // -- bits[13..8]  (6 bits) which virtual method table?
-      __ delayed()->or3(src, offset, L0);
-    }
-  }
-
-  __ bind(common_code);
-
-  // Expecting to be called with the "this" pointer in O0/I0 (where
-  // "this" is a Klass object).  In addition, L0 was set (above) to
-  // identify the method and table.
-
-  // Look up the correct vtable pointer.
-
-  __ set((intptr_t)vtbl_list, L2);      // L2 = address of new vtable list.
-  __ srl(L0, 8, L3);                    // Isolate L3 = vtable identifier.
-  __ sll(L3, LogBytesPerWord, L3);
-  __ ld_ptr(L2, L3, L3);                // L3 = new (correct) vtable pointer.
-  __ st_ptr(L3, Address(I0, 0));        // Save correct vtable ptr in entry.
-
-  // Restore registers and jump to the correct method;
-
-  __ and3(L0, 255, L4);                 // Isolate L3 = method offset;.
-  __ sll(L4, LogBytesPerWord, L4);
-  __ ld_ptr(L3, L4, L4);                // Get address of correct virtual method
-  __ jmpl(L4, 0, G0);                   // Jump to correct method.
-  __ delayed()->restore();              // Restore registers.
-
-  __ flush();
-  *mc_top = (char*)__ pc();
-
-  guarantee(*mc_top <= mc_end, "Insufficient space for method wrappers.");
-}
--- a/hotspot/src/cpu/sparc/vm/methodHandles_sparc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/sparc/vm/methodHandles_sparc.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -71,7 +71,7 @@
                                  Register temp_reg, Register temp2_reg,
                                  const char* error_message) {
   InstanceKlass** klass_addr = SystemDictionary::well_known_klass_addr(klass_id);
-  KlassHandle klass = SystemDictionary::well_known_klass(klass_id);
+  Klass* klass = SystemDictionary::well_known_klass(klass_id);
   bool did_save = false;
   if (temp_reg == noreg || temp2_reg == noreg) {
     temp_reg = L1;
--- a/hotspot/src/cpu/sparc/vm/templateInterpreterGenerator_sparc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/sparc/vm/templateInterpreterGenerator_sparc.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -374,6 +374,10 @@
   __ and3(flags, ConstantPoolCacheEntry::parameter_size_mask, parameter_size);  // argument size in words
   __ sll(parameter_size, Interpreter::logStackElementSize, parameter_size);     // each argument size in bytes
   __ add(Lesp, parameter_size, Lesp);                                           // pop arguments
+
+  __ check_and_handle_popframe(Gtemp);
+  __ check_and_handle_earlyret(Gtemp);
+
   __ dispatch_next(state, step);
 
   return entry;
@@ -466,12 +470,6 @@
 }
 
 
-address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
-  address entry = __ pc();
-  __ dispatch_next(state);
-  return entry;
-}
-
 //
 // Helpers for commoning out cases in the various type of method entries.
 //
--- a/hotspot/src/cpu/x86/vm/compiledIC_aot_x86_64.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/x86/vm/compiledIC_aot_x86_64.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,6 +21,8 @@
  * questions.
  */
 
+#include "precompiled.hpp"
+
 #include "aot/compiledIC_aot.hpp"
 #include "code/codeCache.hpp"
 #include "memory/resourceArea.hpp"
--- a/hotspot/src/cpu/x86/vm/interp_masm_x86.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/x86/vm/interp_masm_x86.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -48,9 +48,6 @@
                             int number_of_arguments,
                             bool check_exceptions);
 
-  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, bool verifyoop = true);
 
@@ -61,6 +58,9 @@
 
   void jump_to_entry(address entry);
 
+ virtual void check_and_handle_popframe(Register java_thread);
+ virtual void check_and_handle_earlyret(Register java_thread);
+
   void load_earlyret_value(TosState state);
 
   // Interpreter-specific registers
--- a/hotspot/src/cpu/x86/vm/jvmciCodeInstaller_x86.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/x86/vm/jvmciCodeInstaller_x86.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -65,7 +65,7 @@
 
 void CodeInstaller::pd_patch_OopConstant(int pc_offset, Handle constant, TRAPS) {
   address pc = _instructions->start() + pc_offset;
-  Handle obj = HotSpotObjectConstantImpl::object(constant);
+  Handle obj(THREAD, HotSpotObjectConstantImpl::object(constant));
   jobject value = JNIHandles::make_local(obj());
   if (HotSpotObjectConstantImpl::compressed(constant)) {
 #ifdef _LP64
--- a/hotspot/src/cpu/x86/vm/macroAssembler_x86.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/x86/vm/macroAssembler_x86.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -71,12 +71,6 @@
     bool     check_exceptions          // whether to check for pending exceptions after return
   );
 
-  // These routines should emit JVMTI PopFrame and ForceEarlyReturn handling code.
-  // The implementation is only non-empty for the InterpreterMacroAssembler,
-  // as only the interpreter handles PopFrame and ForceEarlyReturn requests.
-  virtual void check_and_handle_popframe(Register java_thread);
-  virtual void check_and_handle_earlyret(Register java_thread);
-
   void call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions = true);
 
   // helpers for FPU flag access
@@ -87,6 +81,12 @@
  public:
   MacroAssembler(CodeBuffer* code) : Assembler(code) {}
 
+ // These routines should emit JVMTI PopFrame and ForceEarlyReturn handling code.
+ // The implementation is only non-empty for the InterpreterMacroAssembler,
+ // as only the interpreter handles PopFrame and ForceEarlyReturn requests.
+ virtual void check_and_handle_popframe(Register java_thread);
+ virtual void check_and_handle_earlyret(Register java_thread);
+
   // Support for NULL-checks
   //
   // Generates code that causes a NULL OS exception if the content of reg is NULL.
--- a/hotspot/src/cpu/x86/vm/metaspaceShared_x86_32.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,124 +0,0 @@
-/*
- * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-#include "precompiled.hpp"
-#include "asm/macroAssembler.hpp"
-#include "asm/codeBuffer.hpp"
-#include "memory/metaspaceShared.hpp"
-
-// Generate the self-patching vtable method:
-//
-// This method will be called (as any other Klass virtual method) with
-// the Klass itself as the first argument.  Example:
-//
-//      oop obj;
-//      int size = obj->klass()->oop_size(this);
-//
-// for which the virtual method call is Klass::oop_size();
-//
-// The dummy method is called with the Klass object as the first
-// operand, and an object as the second argument.
-//
-
-//=====================================================================
-
-// All of the dummy methods in the vtable are essentially identical,
-// differing only by an ordinal constant, and they bear no relationship
-// to the original method which the caller intended. Also, there needs
-// to be 'vtbl_list_size' instances of the vtable in order to
-// differentiate between the 'vtable_list_size' original Klass objects.
-
-#define __ masm->
-
-void MetaspaceShared::generate_vtable_methods(void** vtbl_list,
-                                                   void** vtable,
-                                                   char** md_top,
-                                                   char* md_end,
-                                                   char** mc_top,
-                                                   char* mc_end) {
-
-  intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*);
-  *(intptr_t *)(*md_top) = vtable_bytes;
-  *md_top += sizeof(intptr_t);
-  void** dummy_vtable = (void**)*md_top;
-  *vtable = dummy_vtable;
-  *md_top += vtable_bytes;
-
-  // Get ready to generate dummy methods.
-
-  CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top);
-  MacroAssembler* masm = new MacroAssembler(&cb);
-
-  Label common_code;
-  for (int i = 0; i < vtbl_list_size; ++i) {
-    for (int j = 0; j < num_virtuals; ++j) {
-      dummy_vtable[num_virtuals * i + j] = (void*)masm->pc();
-
-      // Load rax, with a value indicating vtable/offset pair.
-      // -- bits[ 7..0]  (8 bits) which virtual method in table?
-      // -- bits[12..8]  (5 bits) which virtual method table?
-      // -- must fit in 13-bit instruction immediate field.
-      __ movl(rax, (i << 8) + j);
-      __ jmp(common_code);
-    }
-  }
-
-  __ bind(common_code);
-
-#ifdef WIN32
-  // Expecting to be called with "thiscall" conventions -- the arguments
-  // are on the stack, except that the "this" pointer is in rcx.
-#else
-  // Expecting to be called with Unix conventions -- the arguments
-  // are on the stack, including the "this" pointer.
-#endif
-
-  // In addition, rax was set (above) to the offset of the method in the
-  // table.
-
-#ifdef WIN32
-  __ push(rcx);                         // save "this"
-#endif
-  __ mov(rcx, rax);
-  __ shrptr(rcx, 8);                    // isolate vtable identifier.
-  __ shlptr(rcx, LogBytesPerWord);
-  Address index(noreg, rcx,  Address::times_1);
-  ExternalAddress vtbl((address)vtbl_list);
-  __ movptr(rdx, ArrayAddress(vtbl, index)); // get correct vtable address.
-#ifdef WIN32
-  __ pop(rcx);                          // restore "this"
-#else
-  __ movptr(rcx, Address(rsp, BytesPerWord));   // fetch "this"
-#endif
-  __ movptr(Address(rcx, 0), rdx);      // update vtable pointer.
-
-  __ andptr(rax, 0x00ff);                       // isolate vtable method index
-  __ shlptr(rax, LogBytesPerWord);
-  __ addptr(rax, rdx);                  // address of real method pointer.
-  __ jmp(Address(rax, 0));              // get real method pointer.
-
-  __ flush();
-
-  *mc_top = (char*)__ pc();
-}
--- a/hotspot/src/cpu/x86/vm/metaspaceShared_x86_64.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-#include "precompiled.hpp"
-#include "asm/macroAssembler.hpp"
-#include "asm/codeBuffer.hpp"
-#include "memory/metaspaceShared.hpp"
-
-// Generate the self-patching vtable method:
-//
-// This method will be called (as any other Klass virtual method) with
-// the Klass itself as the first argument.  Example:
-//
-//      oop obj;
-//      int size = obj->klass()->oop_size(this);
-//
-// for which the virtual method call is Klass::oop_size();
-//
-// The dummy method is called with the Klass object as the first
-// operand, and an object as the second argument.
-//
-
-//=====================================================================
-
-// All of the dummy methods in the vtable are essentially identical,
-// differing only by an ordinal constant, and they bear no relationship
-// to the original method which the caller intended. Also, there needs
-// to be 'vtbl_list_size' instances of the vtable in order to
-// differentiate between the 'vtable_list_size' original Klass objects.
-
-#define __ masm->
-
-void MetaspaceShared::generate_vtable_methods(void** vtbl_list,
-                                                   void** vtable,
-                                                   char** md_top,
-                                                   char* md_end,
-                                                   char** mc_top,
-                                                   char* mc_end) {
-
-  intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*);
-  *(intptr_t *)(*md_top) = vtable_bytes;
-  *md_top += sizeof(intptr_t);
-  void** dummy_vtable = (void**)*md_top;
-  *vtable = dummy_vtable;
-  *md_top += vtable_bytes;
-
-  // Get ready to generate dummy methods.
-
-  CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top);
-  MacroAssembler* masm = new MacroAssembler(&cb);
-
-  Label common_code;
-  for (int i = 0; i < vtbl_list_size; ++i) {
-    for (int j = 0; j < num_virtuals; ++j) {
-      dummy_vtable[num_virtuals * i + j] = (void*)masm->pc();
-
-      // Load eax with a value indicating vtable/offset pair.
-      // -- bits[ 7..0]  (8 bits) which virtual method in table?
-      // -- bits[12..8]  (5 bits) which virtual method table?
-      // -- must fit in 13-bit instruction immediate field.
-      __ movl(rax, (i << 8) + j);
-      __ jmp(common_code);
-    }
-  }
-
-  __ bind(common_code);
-
-  // Expecting to be called with "thiscall" convections -- the arguments
-  // are on the stack and the "this" pointer is in c_rarg0. In addition, rax
-  // was set (above) to the offset of the method in the table.
-
-  __ push(c_rarg1);                     // save & free register
-  __ push(c_rarg0);                     // save "this"
-  __ mov(c_rarg0, rax);
-  __ shrptr(c_rarg0, 8);                // isolate vtable identifier.
-  __ shlptr(c_rarg0, LogBytesPerWord);
-  __ lea(c_rarg1, ExternalAddress((address)vtbl_list)); // ptr to correct vtable list.
-  __ addptr(c_rarg1, c_rarg0);          // ptr to list entry.
-  __ movptr(c_rarg1, Address(c_rarg1, 0));      // get correct vtable address.
-  __ pop(c_rarg0);                      // restore "this"
-  __ movptr(Address(c_rarg0, 0), c_rarg1);      // update vtable pointer.
-
-  __ andptr(rax, 0x00ff);                       // isolate vtable method index
-  __ shlptr(rax, LogBytesPerWord);
-  __ addptr(rax, c_rarg1);              // address of real method pointer.
-  __ pop(c_rarg1);                      // restore register.
-  __ movptr(rax, Address(rax, 0));      // get real method pointer.
-  __ jmp(rax);                          // jump to the real method.
-
-  __ flush();
-
-  *mc_top = (char*)__ pc();
-}
--- a/hotspot/src/cpu/x86/vm/methodHandles_x86.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/x86/vm/methodHandles_x86.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -65,7 +65,7 @@
                                  Register obj, SystemDictionary::WKID klass_id,
                                  const char* error_message) {
   InstanceKlass** klass_addr = SystemDictionary::well_known_klass_addr(klass_id);
-  KlassHandle klass = SystemDictionary::well_known_klass(klass_id);
+  Klass* klass = SystemDictionary::well_known_klass(klass_id);
   Register temp = rdi;
   Register temp2 = noreg;
   LP64_ONLY(temp2 = rscratch1);  // used by MacroAssembler::cmpptr
--- a/hotspot/src/cpu/x86/vm/templateInterpreterGenerator_x86.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/cpu/x86/vm/templateInterpreterGenerator_x86.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -171,16 +171,6 @@
   return entry;
 }
 
-
-address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
-  address entry = __ pc();
-  // NULL last_sp until next java call
-  __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
-  __ dispatch_next(state);
-  return entry;
-}
-
-
 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
   address entry = __ pc();
 
@@ -230,6 +220,17 @@
   __ movl(flags, Address(cache, index, Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
   __ andl(flags, ConstantPoolCacheEntry::parameter_size_mask);
   __ lea(rsp, Address(rsp, flags, Interpreter::stackElementScale()));
+
+   const Register java_thread = NOT_LP64(rcx) LP64_ONLY(r15_thread);
+   if (JvmtiExport::can_pop_frame()) {
+     NOT_LP64(__ get_thread(java_thread));
+     __ check_and_handle_popframe(java_thread);
+   }
+   if (JvmtiExport::can_force_early_return()) {
+     NOT_LP64(__ get_thread(java_thread));
+     __ check_and_handle_earlyret(java_thread);
+   }
+
   __ dispatch_next(state, step);
 
   return entry;
--- a/hotspot/src/cpu/zero/vm/metaspaceShared_zero.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2007 Red Hat, Inc.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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 "assembler_zero.inline.hpp"
-#include "memory/metaspaceShared.hpp"
-
-void MetaspaceShared::generate_vtable_methods(void** vtbl_list,
-                                                   void** vtable,
-                                                   char** md_top,
-                                                   char*  md_end,
-                                                   char** mc_top,
-                                                   char*  mc_end) {
-  ShouldNotCallThis();
-}
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/BinaryContainer.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/BinaryContainer.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,6 +36,8 @@
 import jdk.tools.jaotc.binformat.Symbol.Binding;
 import jdk.tools.jaotc.binformat.Symbol.Kind;
 import jdk.tools.jaotc.binformat.elf.JELFRelocObject;
+import jdk.tools.jaotc.binformat.macho.JMachORelocObject;
+import jdk.tools.jaotc.binformat.pecoff.JPECoffRelocObject;
 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
 
@@ -44,7 +46,7 @@
  *
  * <p>
  * This class holds information necessary to create platform-specific binary containers such as
- * ELFContainer for Linux and Solaris operating systems or yet-to be created MachOContainer for Mac
+ * ELFContainer for Linux and Solaris operating systems or MachOContainer for Mac
  * OS or PEContainer for MS Windows operating systems.
  *
  * <p>
@@ -264,29 +266,29 @@
 
         // read only, code
         codeContainer = new CodeContainer(".text", this);
-        extLinkageContainer = new CodeContainer(".hotspot.linkage.plt", this);
+        extLinkageContainer = new CodeContainer(".hs.plt.linkage", this);
 
         // read only, info
         configContainer = new ReadOnlyDataContainer(".config", this);
-        metaspaceNamesContainer = new ReadOnlyDataContainer(".metaspace.names", this);
+        metaspaceNamesContainer = new ReadOnlyDataContainer(".meta.names", this);
         methodsOffsetsContainer = new ReadOnlyDataContainer(".methods.offsets", this);
-        klassesOffsetsContainer = new ReadOnlyDataContainer(".klasses.offsets", this);
-        klassesDependenciesContainer = new ReadOnlyDataContainer(".klasses.dependencies", this);
+        klassesOffsetsContainer = new ReadOnlyDataContainer(".kls.offsets", this);
+        klassesDependenciesContainer = new ReadOnlyDataContainer(".kls.dependencies", this);
 
         headerContainer = new HeaderContainer(jvmVersion, new ReadOnlyDataContainer(".header", this));
         stubsOffsetsContainer = new ReadOnlyDataContainer(".stubs.offsets", this);
         codeSegmentsContainer = new ReadOnlyDataContainer(".code.segments", this);
-        constantDataContainer = new ReadOnlyDataContainer(".method.constdata", this);
+        constantDataContainer = new ReadOnlyDataContainer(".meth.constdata", this);
 
         // needs relocation patching at load time by the loader
-        methodMetadataContainer = new ReadOnlyDataContainer(".method.metadata", this);
+        methodMetadataContainer = new ReadOnlyDataContainer(".meth.metadata", this);
 
         // writable sections
-        metaspaceGotContainer = new ByteContainer(".metaspace.got", this);
+        metaspaceGotContainer = new ByteContainer(".meta.got", this);
         metadataGotContainer = new ByteContainer(".metadata.got", this);
-        methodStateContainer = new ByteContainer(".method.state", this);
+        methodStateContainer = new ByteContainer(".meth.state", this);
         oopGotContainer = new ByteContainer(".oop.got", this);
-        extLinkageGOTContainer = new ByteContainer(".hotspot.linkage.got", this);
+        extLinkageGOTContainer = new ByteContainer(".hs.got.linkage", this);
 
         addGlobalSymbols();
 
@@ -497,11 +499,21 @@
         switch (osName) {
             case "Linux":
             case "SunOS":
-                JELFRelocObject elfso = new JELFRelocObject(this, outputFileName, aotVersion);
-                elfso.createELFRelocObject(relocationTable, symbolTable.values());
+                JELFRelocObject elfobj = new JELFRelocObject(this, outputFileName, aotVersion);
+                elfobj.createELFRelocObject(relocationTable, symbolTable.values());
+                break;
+            case "Mac OS X":
+                JMachORelocObject machobj = new JMachORelocObject(this, outputFileName);
+                machobj.createMachORelocObject(relocationTable, symbolTable.values());
                 break;
             default:
-                throw new InternalError("Unsupported platform: " + osName);
+                if (osName.startsWith("Windows")) {
+                    JPECoffRelocObject pecoffobj = new JPECoffRelocObject(this, outputFileName, aotVersion);
+                    pecoffobj.createPECoffRelocObject(relocationTable, symbolTable.values());
+                    break;
+                }
+                else
+                    throw new InternalError("Unsupported platform: " + osName);
         }
     }
 
@@ -742,11 +754,11 @@
     }
 
     /**
-     * Add constant data as follows. - Adding the data to the method.constdata section
+     * Add constant data as follows. - Adding the data to the meth.constdata section
      *
      * @param data
      * @param alignment
-     * @return the offset in the method.constdata of the data
+     * @return the offset in the meth.constdata of the data
      */
     public int addConstantData(byte[] data, int alignment) {
         // Get the current length of the metaspaceNameContainer
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/ByteContainer.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/ByteContainer.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
 
 import jdk.tools.jaotc.binformat.Symbol.Binding;
 import jdk.tools.jaotc.binformat.Symbol.Kind;
-import jdk.tools.jaotc.jnilibelf.ELFContainer;
+import jdk.tools.jaotc.binformat.Container;
 
 import java.io.ByteArrayOutputStream;
 import java.nio.ByteBuffer;
@@ -41,7 +41,7 @@
  * The method {@code putIntAt} updates the content of {@code contentBytes}. Changes are not
  * reflected in {@code contentStream}.
  */
-public class ByteContainer implements ELFContainer {
+public class ByteContainer implements Container {
     /**
      * {@code ByteBuffer} representation of {@code BinaryContainer}.
      */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/Container.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat;
+
+public interface Container {
+
+    String getContainerName();
+
+    int getSectionId();
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/NativeSymbol.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat;
+
+/**
+ * This class represents ia native OS specific Symbol
+ */
+public abstract class NativeSymbol {
+
+    /** String table index. */
+    private int index;
+
+    public NativeSymbol(int index) {
+        this.index = index;
+    }
+
+    /**
+     * @return the index
+     */
+    public int getIndex() {
+        return index;
+    }
+
+    /**
+     * @index
+     */
+    public void setIndex(int index) {
+        this.index = index;
+    }
+}
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/Symbol.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/Symbol.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
 
 import java.util.Objects;
 
-import jdk.tools.jaotc.jnilibelf.ELFSymbol;
+import jdk.tools.jaotc.binformat.NativeSymbol;
 
 public class Symbol {
 
@@ -51,7 +51,7 @@
     private final Kind kind;
 
     private ByteContainer section;
-    private ELFSymbol elfSymbol;
+    private NativeSymbol nativeSymbol;
 
     /**
      * Create symbol info.
@@ -77,12 +77,12 @@
         return name;
     }
 
-    public ELFSymbol getElfSymbol() {
-        return elfSymbol;
+    public NativeSymbol getNativeSymbol() {
+        return nativeSymbol;
     }
 
-    public void setElfSymbol(ELFSymbol elfSymbol) {
-        this.elfSymbol = elfSymbol;
+    public void setNativeSymbol(NativeSymbol nativeSym) {
+        this.nativeSymbol = nativeSym;
     }
 
     public Binding getBinding() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/Elf.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,256 @@
+/*
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.elf;
+
+/**
+ *
+ * Support for the creation of Elf Object files.
+ * Current support is limited to 64 bit x86_64.
+ *
+ */
+
+public class Elf {
+
+    /**
+     * Elf64_Ehdr structure defines
+     */
+    public enum Elf64_Ehdr {
+               e_ident( 0,16),
+                e_type(16, 2),
+             e_machine(18, 2),
+             e_version(20, 4),
+               e_entry(24, 8),
+               e_phoff(32, 8),
+               e_shoff(40, 8),
+               e_flags(48, 4),
+              e_ehsize(52, 2),
+           e_phentsize(54, 2),
+               e_phnum(56, 2),
+           e_shentsize(58, 2),
+               e_shnum(60, 2),
+            e_shstrndx(62, 2);
+
+        public final int off;
+        public final int sz;
+
+        Elf64_Ehdr(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 64;
+
+        /**
+         * Elf64_Ehdr defines
+         */
+
+        /**
+         * e_ident
+         */
+        public static final int  EI_MAG0             = 0;
+        public static final byte ELFMAG0             = 0x7f;
+        public static final int  EI_MAG1             = 1;
+        public static final byte ELFMAG1             = 0x45;
+        public static final int  EI_MAG2             = 2;
+        public static final byte ELFMAG2             = 0x4c;
+        public static final int  EI_MAG3             = 3;
+        public static final byte ELFMAG3             = 0x46;
+
+        public static final int  EI_CLASS            = 4;
+        public static final byte ELFCLASS64          = 0x2;
+
+        public static final int  EI_DATA             = 5;
+        public static final byte ELFDATA2LSB         = 0x1;
+
+        public static final int  EI_VERSION          = 6;
+        public static final byte EV_CURRENT          = 0x1;
+
+        public static final int  EI_OSABI            = 7;
+        public static final byte ELFOSABI_NONE       = 0x0;
+
+        /**
+         * e_type
+         */
+        public static final char ET_REL              = 0x1;
+
+        /**
+         * e_machine
+         */
+        public static final char EM_NONE             = 0;
+        public static final char EM_X86_64           = 62;
+        public static final char EM_AARCH64          = 183;
+
+        /**
+         * e_version
+         */
+        // public static final int EV_CURRENT           = 1;
+
+    }
+
+    /**
+     * Elf64_Shdr structure defines
+     */
+    public enum Elf64_Shdr {
+               sh_name( 0, 4),
+               sh_type( 4, 4),
+              sh_flags( 8, 8),
+               sh_addr(16, 8),
+             sh_offset(24, 8),
+               sh_size(32, 8),
+               sh_link(40, 4),
+               sh_info(44, 4),
+          sh_addralign(48, 8),
+            sh_entsize(56, 8);
+
+        public final int off;
+        public final int sz;
+
+        Elf64_Shdr(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 64;
+
+        /**
+         * Elf64_Shdr defines
+         */
+
+        /**
+         * sh_type
+         */
+        public static final int SHT_PROGBITS         = 0x1;
+        public static final int SHT_SYMTAB           = 0x2;
+        public static final int SHT_STRTAB           = 0x3;
+        public static final int SHT_RELA             = 0x4;
+        public static final int SHT_NOBITS           = 0x8;
+        public static final int SHT_REL              = 0x9;
+
+        public static final byte SHN_UNDEF           = 0x0;
+
+        /**
+         * sh_flag
+         */
+        public static final int SHF_WRITE            = 0x1;
+        public static final int SHF_ALLOC            = 0x2;
+        public static final int SHF_EXECINSTR        = 0x4;
+
+    }
+
+    /**
+     * Symbol table entry definitions
+     *
+     * Elf64_Sym structure defines
+     */
+    public enum Elf64_Sym {
+               st_name( 0, 4),
+               st_info( 4, 1),
+              st_other( 5, 1),
+              st_shndx( 6, 2),
+              st_value( 8, 8),
+               st_size(16, 8);
+
+        public final int off;
+        public final int sz;
+
+        Elf64_Sym(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 24;
+
+        /* ST_BIND is in bits 4-7 of st_info.  ST_TYPE is in low 4 bits */
+        public static final byte STB_LOCAL           = 0x0;
+        public static final byte STB_GLOBAL          = 0x1;
+
+        public static final byte STT_NOTYPE          = 0x0;
+        public static final byte STT_OBJECT          = 0x1;
+        public static final byte STT_FUNC            = 0x2;
+
+        public static byte ELF64_ST_INFO(byte bind, byte type) {
+            return (byte)(((bind) << 4) + ((type) & 0xf));
+        }
+
+    }
+
+    /**
+     * Elf64_Rel structure defines
+     */
+    public enum Elf64_Rel {
+              r_offset( 0, 8),
+                r_info( 8, 8);
+
+        public final int off;
+        public final int sz;
+
+        Elf64_Rel(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 16;
+
+        /**
+         * Relocation types
+         */
+        public static final int R_X86_64_NONE        = 0x0;
+        public static final int R_X86_64_64          = 0x1;
+        public static final int R_X86_64_PC32        = 0x2;
+        public static final int R_X86_64_PLT32       = 0x4;
+        public static final int R_X86_64_GOTPCREL    = 0x9;
+
+    }
+
+    /**
+     * Elf64_Rela structure defines
+     */
+    public enum Elf64_Rela {
+              r_offset( 0, 8),
+                r_info( 8, 8),
+              r_addend(16, 8);
+
+        public final int off;
+        public final int sz;
+
+        Elf64_Rela(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 24;
+
+        public static final int R_X86_64_NONE        = 0x0;
+        public static final int R_X86_64_64          = 0x1;
+        public static final int R_X86_64_PC32        = 0x2;
+        public static final int R_X86_64_PLT32       = 0x4;
+        public static final int R_X86_64_GOTPCREL    = 0x9;
+
+        public static long ELF64_R_INFO(int symidx, int type) {
+            return (((long)symidx << 32) + ((long)type));
+        }
+
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfByteBuffer.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.elf;
+
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
+import jdk.tools.jaotc.binformat.elf.ElfTargetInfo;
+
+public class ElfByteBuffer {
+
+    public static ByteBuffer allocate(int size) {
+        ByteBuffer buf = ByteBuffer.allocate(size);
+        if (ElfTargetInfo.getElfEndian() == Elf64_Ehdr.ELFDATA2LSB)
+            buf.order(ByteOrder.LITTLE_ENDIAN);
+        else
+            buf.order(ByteOrder.BIG_ENDIAN);
+        return (buf);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfContainer.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.elf;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+public class ElfContainer {
+
+    File outputFile;
+    FileOutputStream outputStream;
+    long fileOffset;
+
+    public ElfContainer(String fileName, String aotVersion) {
+        String baseName;
+
+        outputFile = new File(fileName);
+        if (outputFile.exists()) {
+            outputFile.delete();
+        }
+
+        try {
+            outputStream = new FileOutputStream(outputFile);
+        } catch (Exception e) {
+            System.out.println("ElfContainer: Can't create file " + fileName);
+        }
+        fileOffset = 0;
+    }
+
+    public void close() {
+        try {
+            outputStream.close();
+        } catch (Exception e) {
+            System.out.println("ElfContainer: close failed");
+        }
+    }
+
+    public void writeBytes(byte [] bytes) {
+        if (bytes == null) return;
+        try {
+            outputStream.write(bytes);
+        } catch (Exception e) {
+            System.out.println("ElfContainer: writeBytes failed");
+        }
+        fileOffset += bytes.length;
+    }
+
+    // Write bytes to output file with up front alignment padding
+    public void writeBytes(byte [] bytes, int alignment) {
+        if (bytes == null) return;
+        try {
+            // Pad to alignment
+            while ((fileOffset & (long)(alignment-1)) != 0) {
+                outputStream.write(0);
+                fileOffset++;
+            }
+            outputStream.write(bytes);
+        } catch (Exception e) {
+            System.out.println("ElfContainer: writeBytes failed");
+        }
+        fileOffset += bytes.length;
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfHeader.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.elf;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.elf.Elf;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Shdr;
+import jdk.tools.jaotc.binformat.elf.ElfTargetInfo;
+import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
+
+public class ElfHeader {
+    ByteBuffer header;
+
+    public ElfHeader() {
+        header = ElfByteBuffer.allocate(Elf64_Ehdr.totalsize);
+
+        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_MAG0, Elf64_Ehdr.ELFMAG0);
+        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_MAG1, Elf64_Ehdr.ELFMAG1);
+        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_MAG2, Elf64_Ehdr.ELFMAG2);
+        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_MAG3, Elf64_Ehdr.ELFMAG3);
+        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_CLASS, Elf64_Ehdr.ELFCLASS64);
+        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_DATA, Elf64_Ehdr.ELFDATA2LSB);
+        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_VERSION, Elf64_Ehdr.EV_CURRENT);
+        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_OSABI, Elf64_Ehdr.ELFOSABI_NONE);
+
+        header.putChar(Elf64_Ehdr.e_type.off, Elf64_Ehdr.ET_REL);
+        header.putChar(Elf64_Ehdr.e_machine.off, ElfTargetInfo.getElfArch());
+        header.putInt(Elf64_Ehdr.e_version.off, Elf64_Ehdr.EV_CURRENT);
+        header.putChar(Elf64_Ehdr.e_ehsize.off, (char)Elf64_Ehdr.totalsize);
+        header.putChar(Elf64_Ehdr.e_shentsize.off, (char)Elf64_Shdr.totalsize);
+
+    }
+
+    // Update header with file offset of first section
+    public void setSectionOff(int offset) {
+        header.putLong(Elf64_Ehdr.e_shoff.off, offset);
+    }
+
+    // Update header with the number of total sections
+    public void setSectionNum(int count) {
+        header.putChar(Elf64_Ehdr.e_shnum.off, (char)count);
+    }
+
+    // Update header with the section index containing the
+    // string table for section names
+    public void setSectionStrNdx(int index) {
+        header.putChar(Elf64_Ehdr.e_shstrndx.off, (char)index);
+    }
+
+    public byte[] getArray() {
+        return header.array();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfRelocEntry.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.elf;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.elf.Elf;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rela;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
+import jdk.tools.jaotc.binformat.elf.ElfTargetInfo;
+import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
+
+public class ElfRelocEntry {
+    ByteBuffer entry;
+
+    public ElfRelocEntry(int offset, int symno, int type, int addend) {
+
+        entry = ElfByteBuffer.allocate(Elf64_Rela.totalsize);
+
+        entry.putLong(Elf64_Rela.r_offset.off, offset);
+        entry.putLong(Elf64_Rela.r_info.off, Elf64_Rela.ELF64_R_INFO(symno,type));
+        entry.putLong(Elf64_Rela.r_addend.off, addend);
+    }
+
+    public byte[] getArray() {
+        return entry.array();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfRelocTable.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.elf;
+
+import java.util.ArrayList;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.elf.ElfRelocEntry;
+import jdk.tools.jaotc.binformat.elf.ElfTargetInfo;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rela;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
+import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
+
+public class ElfRelocTable {
+    ArrayList<ArrayList<ElfRelocEntry>> relocEntries;
+
+    public ElfRelocTable(int numsects) {
+        relocEntries = new ArrayList<ArrayList<ElfRelocEntry>>(numsects);
+        for (int i = 0; i < numsects; i++)
+            relocEntries.add(new ArrayList<ElfRelocEntry>());
+    }
+
+    public void createRelocationEntry(int sectindex,
+                                      int offset,
+                                      int symno,
+                                      int type,
+                                      int addend) {
+
+        ElfRelocEntry entry = new ElfRelocEntry(offset,
+                                                symno,
+                                                type,
+                                                addend);
+        relocEntries.get(sectindex).add(entry);
+    }
+
+    public int getNumRelocs(int section_index) {
+        return relocEntries.get(section_index).size();
+    }
+
+    // Return the relocation entries for a single section
+    //   or null if no entries added to section
+    public byte [] getRelocData(int section_index) {
+        ArrayList<ElfRelocEntry> entryList = relocEntries.get(section_index);
+
+        if (entryList.size() == 0)
+            return null;
+
+        ByteBuffer relocData = ElfByteBuffer.allocate(entryList.size() * Elf64_Rela.totalsize);
+
+        // Copy each entry to a single ByteBuffer
+        for (int i = 0; i < entryList.size(); i++) {
+            ElfRelocEntry entry = entryList.get(i);
+            relocData.put(entry.getArray());
+        }
+
+        return (relocData.array());
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSection.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.elf;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.elf.Elf;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Shdr;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rel;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rela;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Sym;
+import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
+
+public class ElfSection {
+    String name;
+    ByteBuffer section;
+    byte [] data;
+    boolean hasrelocations;
+    int sectionIndex;
+
+    /**
+     * String holding section name strings
+     */
+    private static StringBuilder sectNameTab = new StringBuilder();
+
+    /**
+     * Keeps track of bytes in section string table since strTabContent.length()
+     * is number of chars, not bytes.
+     */
+    private static int shStrTabNrOfBytes = 0;
+
+    public ElfSection(String sectName, byte [] sectData, int sectFlags,
+                      int sectType, boolean hasRelocations, int sectIndex) {
+
+        long align;
+
+        section = ElfByteBuffer.allocate(Elf64_Shdr.totalsize);
+
+        // Return all 0's for NULL section
+        if (sectIndex == 0) {
+            sectNameTab.append('\0');
+            shStrTabNrOfBytes += 1;
+            data = null;
+            hasrelocations = false;
+            sectionIndex = 0;
+            return;
+        }
+
+        section.putInt(Elf64_Shdr.sh_name.off, shStrTabNrOfBytes);
+        sectNameTab.append(sectName).append('\0');
+        shStrTabNrOfBytes += (sectName.getBytes().length + 1);
+        name = sectName;
+
+        section.putInt(Elf64_Shdr.sh_type.off, sectType);
+        section.putLong(Elf64_Shdr.sh_flags.off, sectFlags);
+        section.putLong(Elf64_Shdr.sh_addr.off, 0);
+        section.putLong(Elf64_Shdr.sh_offset.off, 0);
+
+        if (sectName.equals(".shstrtab")) {
+            section.putLong(Elf64_Shdr.sh_size.off, shStrTabNrOfBytes);
+            data = sectNameTab.toString().getBytes();
+        }
+        else {
+            data = sectData;
+            section.putLong(Elf64_Shdr.sh_size.off, sectData.length);
+        }
+
+        section.putLong(Elf64_Shdr.sh_entsize.off, 0);
+
+        // Determine the alignment and entrysize
+        // based on type of section
+        switch (sectType) {
+            case Elf64_Shdr.SHT_PROGBITS:
+                if ((sectFlags & Elf64_Shdr.SHF_EXECINSTR) != 0)
+                    align = 16;
+                else
+                    align = 4;
+                break;
+            case Elf64_Shdr.SHT_SYMTAB:
+                align = 8;
+                section.putLong(Elf64_Shdr.sh_entsize.off, Elf64_Sym.totalsize);
+                break;
+            case Elf64_Shdr.SHT_STRTAB:
+                align = 1;
+                break;
+            case Elf64_Shdr.SHT_RELA:
+                align = 8;
+                section.putLong(Elf64_Shdr.sh_entsize.off, Elf64_Rela.totalsize);
+                break;
+            case Elf64_Shdr.SHT_REL:
+                align = 8;
+                section.putLong(Elf64_Shdr.sh_entsize.off, Elf64_Rel.totalsize);
+                break;
+            case Elf64_Shdr.SHT_NOBITS:
+                align = 4;
+                break;
+            default:
+                align = 8;
+                break;
+        }
+        section.putLong(Elf64_Shdr.sh_addralign.off, align);
+
+        hasrelocations = hasRelocations;
+        sectionIndex = sectIndex;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public long getSize() {
+        return section.getLong(Elf64_Shdr.sh_size.off);
+    }
+
+    public int getDataAlign() {
+        return ((int)section.getLong(Elf64_Shdr.sh_addralign.off));
+    }
+
+    // Alignment requirements for the Elf64_Shdr structures
+    public static int getShdrAlign() {
+        return (4);
+    }
+
+    public byte[] getArray() {
+        return section.array();
+    }
+
+    public byte[] getDataArray() {
+        return data;
+    }
+
+    public void setOffset(long offset) {
+        section.putLong(Elf64_Shdr.sh_offset.off, offset);
+    }
+
+    public void setLink(int link) {
+        section.putInt(Elf64_Shdr.sh_link.off, link);
+    }
+
+    public void setInfo(int info) {
+        section.putInt(Elf64_Shdr.sh_info.off, info);
+    }
+
+    public long getOffset() {
+        return (section.getLong(Elf64_Shdr.sh_offset.off));
+    }
+
+    public boolean hasRelocations() {
+        return hasrelocations;
+    }
+
+    public int getSectionId() {
+        return sectionIndex;
+    }
+
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSymbol.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.elf;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.NativeSymbol;
+import jdk.tools.jaotc.binformat.elf.Elf;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Sym;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
+import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
+
+public class ElfSymbol extends NativeSymbol {
+    ByteBuffer sym;
+
+    public ElfSymbol(int symbolindex, int strindex, byte type, byte bind,
+                     byte sectindex, long offset, long size) {
+        super(symbolindex);
+        sym = ElfByteBuffer.allocate(Elf64_Sym.totalsize);
+
+        sym.putInt(Elf64_Sym.st_name.off, strindex);
+        sym.put(Elf64_Sym.st_info.off, Elf64_Sym.ELF64_ST_INFO(bind, type));
+        sym.put(Elf64_Sym.st_other.off, (byte)0);
+        // Section indexes start at 1 but we manage the index internally
+        // as 0 relative
+        sym.putChar(Elf64_Sym.st_shndx.off, (char)(sectindex));
+        sym.putLong(Elf64_Sym.st_value.off, offset);
+        sym.putLong(Elf64_Sym.st_size.off, size);
+    }
+
+    public byte[] getArray() {
+        return sym.array();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSymtab.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.elf;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+
+import jdk.tools.jaotc.binformat.elf.Elf;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Sym;
+import jdk.tools.jaotc.binformat.elf.ElfSymbol;
+import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
+
+public class ElfSymtab {
+
+    ArrayList<ElfSymbol>localSymbols = new ArrayList<ElfSymbol>();
+    ArrayList<ElfSymbol>globalSymbols = new ArrayList<ElfSymbol>();
+
+    /**
+     * number of symbols added
+     */
+    int symbolCount;
+
+    /**
+     * String holding symbol table strings
+     */
+    private StringBuilder strTabContent = new StringBuilder();
+
+    /**
+     * Keeps track of bytes in string table since strTabContent.length()
+     * is number of chars, not bytes.
+     */
+    private int strTabNrOfBytes = 0;
+
+    public ElfSymtab() {
+        symbolCount = 0;
+    }
+
+    public ElfSymbol addSymbolEntry(String name, byte type, byte bind,
+                                    byte secHdrIndex, long offset, long size) {
+        // Get the current symbol index and append symbol name to string table.
+        int index;
+        ElfSymbol sym;
+
+        if (name.isEmpty()) {
+            index = 0;
+            strTabContent.append('\0');
+            strTabNrOfBytes += 1;
+            sym = new ElfSymbol(symbolCount, index, type, bind, secHdrIndex, offset, size);
+            localSymbols.add(sym);
+        } else {
+            // We can't trust strTabContent.length() since that is
+            // chars (UTF16), keep track of bytes on our own.
+            index = strTabNrOfBytes;
+            // strTabContent.append("_").append(name).append('\0');
+            strTabContent.append(name).append('\0');
+            // + 1 for null, + 1 for "_"
+            //strTabNrOfBytes += (name.getBytes().length + 1 + 1);
+            strTabNrOfBytes += (name.getBytes().length + 1);
+
+            sym = new ElfSymbol(symbolCount, index, type, bind, secHdrIndex, offset, size);
+            if ((bind & Elf64_Sym.STB_GLOBAL) != 0)
+                globalSymbols.add(sym);
+            else
+                localSymbols.add(sym);
+        }
+        symbolCount++;
+        return (sym);
+    }
+
+    // Update the symbol indexes once all symbols have been added.
+    // This is required since we'll be reordering the symbols in the
+    // file to be in the order of Local then global.
+    public void updateIndexes() {
+        int index = 0;
+
+        // Update the local symbol indexes
+        for (int i = 0; i < localSymbols.size(); i++ ) {
+            ElfSymbol sym = localSymbols.get(i);
+            sym.setIndex(index++);
+        }
+
+        // Update the global symbol indexes
+        for (int i = 0; i < globalSymbols.size(); i++ ) {
+            ElfSymbol sym = globalSymbols.get(i);
+            sym.setIndex(index++);
+        }
+    }
+
+    public int getNumLocalSyms()  { return localSymbols.size();  }
+    public int getNumGlobalSyms() { return globalSymbols.size(); }
+
+
+    // Create a single byte array that contains the symbol table entries
+    public byte[] getSymtabArray() {
+        int index = 0;
+        ByteBuffer symtabData = ElfByteBuffer.allocate(symbolCount*Elf64_Sym.totalsize);
+        byte [] retarray;
+
+        updateIndexes();
+
+        // Add the local symbols
+        for (int i = 0; i < localSymbols.size(); i++ ) {
+            ElfSymbol sym = localSymbols.get(i);
+            byte [] arr = sym.getArray();
+            symtabData.put(arr);
+        }
+        // Add the global symbols
+        for (int i = 0; i < globalSymbols.size(); i++ ) {
+            ElfSymbol sym = globalSymbols.get(i);
+            byte [] arr = sym.getArray();
+            symtabData.put(arr);
+        }
+        retarray = symtabData.array();
+
+        return (retarray);
+    }
+
+    // Return the string table array
+    public byte[] getStrtabArray() {
+        byte [] strs = strTabContent.toString().getBytes();
+        return (strs);
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfTargetInfo.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.elf;
+
+import java.nio.ByteOrder;
+import jdk.tools.jaotc.binformat.elf.Elf;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
+
+/**
+ * Class that abstracts MACH-O target details.
+ *
+ */
+public class ElfTargetInfo {
+    /**
+     * Target architecture.
+     */
+    private static final char arch;
+
+    /**
+     * Architecture endian-ness.
+     */
+    private static final int endian = Elf64_Ehdr.ELFDATA2LSB;
+
+    /**
+     * Target OS string.
+     */
+    private static String osName;
+
+    static {
+        // Find the target arch details
+        String archStr = System.getProperty("os.arch").toLowerCase();
+        if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) {
+            System.out.println("Only Little Endian byte order supported!");
+        }
+
+        if (archStr.equals("amd64") || archStr.equals("x86_64")) {
+            arch = Elf64_Ehdr.EM_X86_64;
+        } else {
+            System.out.println("Unsupported architecture " + archStr);
+            arch = Elf64_Ehdr.EM_NONE;
+        }
+
+        osName = System.getProperty("os.name").toLowerCase();
+        if (!osName.equals("linux") && !osName.equals("sunos")) {
+            System.out.println("Unsupported Operating System " + osName);
+            osName = "Unknown";
+        }
+    }
+
+    public static char getElfArch() {
+        return arch;
+    }
+
+    public static int getElfEndian() {
+        return endian;
+    }
+
+    public static String getOsName() {
+        return osName;
+    }
+}
+
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/JELFRelocObject.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/JELFRelocObject.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,7 @@
 import java.util.List;
 import java.util.Map;
 
+import jdk.tools.jaotc.binformat.Container;
 import jdk.tools.jaotc.binformat.BinaryContainer;
 import jdk.tools.jaotc.binformat.ByteContainer;
 import jdk.tools.jaotc.binformat.CodeContainer;
@@ -37,36 +38,60 @@
 import jdk.tools.jaotc.binformat.Relocation;
 import jdk.tools.jaotc.binformat.Relocation.RelocType;
 import jdk.tools.jaotc.binformat.Symbol;
+import jdk.tools.jaotc.binformat.NativeSymbol;
 import jdk.tools.jaotc.binformat.Symbol.Binding;
 import jdk.tools.jaotc.binformat.Symbol.Kind;
-import jdk.tools.jaotc.jnilibelf.ELFContainer;
-import jdk.tools.jaotc.jnilibelf.ELFSymbol;
-import jdk.tools.jaotc.jnilibelf.JNIELFContainer;
-import jdk.tools.jaotc.jnilibelf.JNIELFRelocation;
-import jdk.tools.jaotc.jnilibelf.JNIELFTargetInfo;
-import jdk.tools.jaotc.jnilibelf.JNILibELFAPI.ELF;
-import jdk.tools.jaotc.jnilibelf.JNILibELFAPI.LibELF.Elf_Cmd;
-import jdk.tools.jaotc.jnilibelf.JNILibELFAPI.LibELF.Elf_Type;
-import jdk.tools.jaotc.jnilibelf.Pointer;
+
+import jdk.tools.jaotc.binformat.elf.Elf;
+import jdk.tools.jaotc.binformat.elf.ElfSymbol;
+import jdk.tools.jaotc.binformat.elf.ElfTargetInfo;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Shdr;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Sym;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rel;
+import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rela;
 
 public class JELFRelocObject {
 
     private final BinaryContainer binContainer;
 
-    private final JNIELFContainer elfContainer;
+    private final ElfContainer elfContainer;
 
     private final int segmentSize;
 
     public JELFRelocObject(BinaryContainer binContainer, String outputFileName, String aotVersion) {
         this.binContainer = binContainer;
-        this.elfContainer = new JNIELFContainer(outputFileName, aotVersion);
+        this.elfContainer = new ElfContainer(outputFileName, aotVersion);
         this.segmentSize = binContainer.getCodeSegmentSize();
     }
 
-    private void createByteSection(ByteContainer c, int scnFlags) {
+    private ElfSection createByteSection(ArrayList<ElfSection>sections,
+                                         String sectName,
+                                         byte [] scnData,
+                                         boolean hasRelocs,
+                                         int scnFlags,
+                                         int scnType) {
+
+        ElfSection sect = new ElfSection(sectName,
+                                         scnData,
+                                         scnFlags,
+                                         scnType,
+                                         hasRelocs,
+                                         sections.size());
+        // Add this section to our list
+        sections.add(sect);
+
+        return (sect);
+    }
+
+    private void createByteSection(ArrayList<ElfSection>sections,
+                                   ByteContainer c, int scnFlags) {
+        ElfSection sect;
+        boolean hasRelocs = c.hasRelocations();
         byte[] scnData = c.getByteArray();
-        int scnType = ELF.SHT_PROGBITS;
-        boolean zeros = !c.hasRelocations();
+
+        int scnType = Elf64_Shdr.SHT_PROGBITS;
+        boolean zeros = hasRelocs;
         if (zeros) {
             for (byte b : scnData) {
                 if (b != 0) {
@@ -75,30 +100,30 @@
                 }
             }
             if (zeros) {
-                scnType = ELF.SHT_NOBITS;
+                scnType = Elf64_Shdr.SHT_NOBITS;
             }
         }
 
-        int sectionId = elfContainer.createSection(c.getContainerName(), scnData, Elf_Type.ELF_T_BYTE, segmentSize, scnType, scnFlags, ELF.SHN_UNDEF, 0);
-        c.setSectionId(sectionId);
-        // Clear out code section data to allow for GC
-        c.clear();
+        sect = createByteSection(sections, c.getContainerName(),
+                                 scnData, hasRelocs,
+                                 scnFlags, scnType);
+        c.setSectionId(sect.getSectionId());
     }
 
-    private void createCodeSection(CodeContainer c) {
-        createByteSection(c, ELF.SHF_ALLOC | ELF.SHF_EXECINSTR);
+    private void createCodeSection(ArrayList<ElfSection>sections, CodeContainer c) {
+        createByteSection(sections, c, Elf64_Shdr.SHF_ALLOC | Elf64_Shdr.SHF_EXECINSTR);
     }
 
-    private void createReadOnlySection(ReadOnlyDataContainer c) {
-        createByteSection(c, ELF.SHF_ALLOC);
+    private void createReadOnlySection(ArrayList<ElfSection>sections, ReadOnlyDataContainer c) {
+        createByteSection(sections, c, Elf64_Shdr.SHF_ALLOC);
     }
 
-    private void createReadWriteSection(ByteContainer c) {
-        createByteSection(c, ELF.SHF_ALLOC | ELF.SHF_WRITE);
+    private void createReadWriteSection(ArrayList<ElfSection>sections, ByteContainer c) {
+        createByteSection(sections, c, Elf64_Shdr.SHF_ALLOC | Elf64_Shdr.SHF_WRITE);
     }
 
     /**
-     * Create an ELF relocatable object using jdk.tools.jaotc.jnilibelf API.
+     * Create an ELF relocatable object
      *
      * @param relocationTable
      * @param symbols
@@ -106,145 +131,171 @@
      */
     public void createELFRelocObject(Map<Symbol, List<Relocation>> relocationTable, Collection<Symbol> symbols) throws IOException {
         // Allocate ELF Header
-        elfContainer.createELFHeader(ELF.ET_REL);
+        ElfHeader eh = new ElfHeader();
+
+        ArrayList<ElfSection> sections = new ArrayList<ElfSection>();
+
+        // Create the null section
+        createByteSection(sections, null, null, false, 0, 0);
 
         // Create text section
-        createCodeSection(binContainer.getCodeContainer());
-        createReadOnlySection(binContainer.getMetaspaceNamesContainer());
-        createReadOnlySection(binContainer.getKlassesOffsetsContainer());
-        createReadOnlySection(binContainer.getMethodsOffsetsContainer());
-        createReadOnlySection(binContainer.getKlassesDependenciesContainer());
-        createReadWriteSection(binContainer.getMetaspaceGotContainer());
-        createReadWriteSection(binContainer.getMetadataGotContainer());
-        createReadWriteSection(binContainer.getMethodStateContainer());
-        createReadWriteSection(binContainer.getOopGotContainer());
-        createReadWriteSection(binContainer.getMethodMetadataContainer());
-        createReadOnlySection(binContainer.getStubsOffsetsContainer());
-        createReadOnlySection(binContainer.getHeaderContainer().getContainer());
-        createReadOnlySection(binContainer.getCodeSegmentsContainer());
-        createReadOnlySection(binContainer.getConstantDataContainer());
-        createReadOnlySection(binContainer.getConfigContainer());
+        createCodeSection(sections, binContainer.getCodeContainer());
+        createReadOnlySection(sections, binContainer.getMetaspaceNamesContainer());
+        createReadOnlySection(sections, binContainer.getKlassesOffsetsContainer());
+        createReadOnlySection(sections, binContainer.getMethodsOffsetsContainer());
+        createReadOnlySection(sections, binContainer.getKlassesDependenciesContainer());
+        createReadWriteSection(sections, binContainer.getMetaspaceGotContainer());
+        createReadWriteSection(sections, binContainer.getMetadataGotContainer());
+        createReadWriteSection(sections, binContainer.getMethodStateContainer());
+        createReadWriteSection(sections, binContainer.getOopGotContainer());
+        createReadWriteSection(sections, binContainer.getMethodMetadataContainer());
+        createReadOnlySection(sections, binContainer.getStubsOffsetsContainer());
+        createReadOnlySection(sections, binContainer.getHeaderContainer().getContainer());
+        createReadOnlySection(sections, binContainer.getCodeSegmentsContainer());
+        createReadOnlySection(sections, binContainer.getConstantDataContainer());
+        createReadOnlySection(sections, binContainer.getConfigContainer());
 
         // createExternalLinkage();
 
-        createCodeSection(binContainer.getExtLinkageContainer());
-        createReadWriteSection(binContainer.getExtLinkageGOTContainer());
+        createCodeSection(sections, binContainer.getExtLinkageContainer());
+        createReadWriteSection(sections, binContainer.getExtLinkageGOTContainer());
 
         // Get ELF symbol data from BinaryContainer object's symbol tables
-        createELFSymbolTables(symbols);
+        ElfSymtab symtab = createELFSymbolTables(sections, symbols);
 
         // Create string table section and symbol table sections in
-        // that order since symtab section needs to set the index of strtab in sh_link field
-        int strTabSectionIndex = elfContainer.createSection(".strtab", elfContainer.getStrTabContent().getBytes(StandardCharsets.UTF_8), Elf_Type.ELF_T_BYTE, 1, ELF.SHT_STRTAB, 0, ELF.SHN_UNDEF, 0);
+        // that order since symtab section needs to set the index of
+        // strtab in sh_link field
+        ElfSection strTabSection = createByteSection(sections,
+                                                     ".strtab",
+                                                     symtab.getStrtabArray(),
+                                                     false,
+                                                     0,
+                                                     Elf64_Shdr.SHT_STRTAB);
 
-        // Now create .symtab section with the symtab data constructed. On Linux, sh_link of symtab
-        // contains the index of string table its symbols reference and
-        // sh_info contains the index of first non-local symbol
-        int scnInfo = elfContainer.getFirstNonLocalSymbolIndex();
-        int symTabSectionIndex = elfContainer.createSection(".symtab", getELFSymbolTableData(), Elf_Type.ELF_T_SYM, 8, ELF.SHT_SYMTAB, ELF.SHF_ALLOC, strTabSectionIndex, scnInfo);
+        // Now create .symtab section with the symtab data constructed.
+        // On Linux, sh_link of symtab contains the index of string table
+        // its symbols reference and sh_info contains the index of first
+        // non-local symbol
+        ElfSection symTabSection = createByteSection(sections,
+                                                    ".symtab",
+                                                    symtab.getSymtabArray(),
+                                                    false,
+                                                    0,
+                                                    Elf64_Shdr.SHT_SYMTAB);
+        symTabSection.setLink(strTabSection.getSectionId());
+        symTabSection.setInfo(symtab.getNumLocalSyms());
 
-        buildRelocations(relocationTable, symTabSectionIndex);
+        ElfRelocTable elfRelocTable = createElfRelocTable(sections,
+                                                          relocationTable);
+
+        createElfRelocSections(sections, elfRelocTable, symTabSection.getSectionId());
 
         // Now, finally, after creating all sections, create shstrtab section
-        elfContainer.createSection(".shstrtab", elfContainer.getShStrTabContent().getBytes(StandardCharsets.UTF_8), Elf_Type.ELF_T_BYTE, 1, ELF.SHT_STRTAB, 0, ELF.SHN_UNDEF, 0);
+        ElfSection shStrTabSection = createByteSection(sections,
+                                                    ".shstrtab",
+                                                    null,
+                                                    false,
+                                                    0,
+                                                    Elf64_Shdr.SHT_STRTAB);
+        eh.setSectionStrNdx(shStrTabSection.getSectionId());
+
+        // Update all section offsets and the Elf header section offset
+        // Write the Header followed by the contents of each section
+        // and then the section structures (section table).
+        int file_offset = Elf64_Ehdr.totalsize;
 
-        // Run elf_update
-        elfContainer.elfUpdate(Elf_Cmd.ELF_C_NULL);
+        // and round it up
+        file_offset = (file_offset + (sections.get(1).getDataAlign()-1)) &
+                      ~((sections.get(1).getDataAlign()-1));
+
+        // Calc file offsets for section data skipping null section
+        for (int i = 1; i < sections.size(); i++) {
+            ElfSection sect = sections.get(i);
+            file_offset = (file_offset + (sect.getDataAlign()-1)) &
+                           ~((sect.getDataAlign()-1));
+            sect.setOffset(file_offset);
+            file_offset += sect.getSize();
+        }
 
-        // Run elfUpdate again to write it out.
-        elfContainer.elfUpdate(Elf_Cmd.ELF_C_WRITE);
-        // Finish ELF processing
-        elfContainer.elfEnd();
+        // Align the section table
+        file_offset = (file_offset + (ElfSection.getShdrAlign()-1)) &
+                      ~((ElfSection.getShdrAlign()-1));
+
+        // Update the Elf Header with the offset of the first Elf64_Shdr
+        // and the number of sections.
+        eh.setSectionOff(file_offset);
+        eh.setSectionNum(sections.size());
+
+        // Write out the Header
+        elfContainer.writeBytes(eh.getArray());
+
+        // Write out each section contents skipping null section
+        for (int i = 1; i < sections.size(); i++) {
+            ElfSection sect = sections.get(i);
+            elfContainer.writeBytes(sect.getDataArray(), sect.getDataAlign());
+        }
+
+        // Write out the section table
+        for (int i = 0; i < sections.size(); i++) {
+            ElfSection sect = sections.get(i);
+            elfContainer.writeBytes(sect.getArray(), ElfSection.getShdrAlign());
+        }
+
+        elfContainer.close();
     }
-
-    private void buildRelocations(Map<Symbol, List<Relocation>> relocationTable, final int symTabSectionIndex) {
-        /*
-         * Create relocation sections. This needs to be done after symbol table sections were
-         * created since relocation entries will need indices of sections to which they apply.
-         */
-        createELFRelocationTables(relocationTable);
-        createAllRelocationSections(new SymTabELFContainer(symTabSectionIndex));
-    }
-
     /**
      * Construct ELF symbol data from BinaryContainer object's symbol tables. Both dynamic ELF
      * symbol table and ELF symbol table are created from BinaryContainer's symbol info.
      *
      * @param symbols
      */
-    private void createELFSymbolTables(Collection<Symbol> symbols) {
+    private ElfSymtab createELFSymbolTables(ArrayList<ElfSection> sections, Collection<Symbol> symbols) {
+        ElfSymtab symtab = new ElfSymtab();
+
         // First, create the initial null symbol. This is a local symbol.
-        elfContainer.createELFSymbolEntry("", 0, 0, ELF.SHN_UNDEF, 0, 0, true);
+        symtab.addSymbolEntry("", (byte)0, (byte)0, Elf64_Shdr.SHN_UNDEF, 0, 0);
 
         // Now create ELF symbol entries for all symbols.
         for (Symbol symbol : symbols) {
             // Get the index of section this symbol is defined in.
             int secHdrIndex = symbol.getSection().getSectionId();
-            boolean isLocal = (symbol.getBinding() == Binding.LOCAL);
-            ELFSymbol elfSymbol = elfContainer.createELFSymbolEntry(symbol.getName(), getELFTypeOf(symbol), getELFBindOf(symbol), secHdrIndex, symbol.getSize(), symbol.getOffset(), isLocal);
-            symbol.setElfSymbol(elfSymbol);
+            ElfSymbol elfSymbol = symtab.addSymbolEntry(symbol.getName(), getELFTypeOf(symbol), getELFBindOf(symbol), (byte)secHdrIndex, symbol.getOffset(), symbol.getSize());
+            symbol.setNativeSymbol((NativeSymbol)elfSymbol);
         }
+        return (symtab);
+    }
+
+    private static byte getELFTypeOf(Symbol sym) {
+        Kind kind = sym.getKind();
+        if (kind == Symbol.Kind.NATIVE_FUNCTION || kind == Symbol.Kind.JAVA_FUNCTION) {
+            return Elf64_Sym.STT_FUNC;
+        } else if (kind == Symbol.Kind.OBJECT) {
+            return Elf64_Sym.STT_OBJECT;
+        }
+        return Elf64_Sym.STT_NOTYPE;
+    }
+
+    private static byte getELFBindOf(Symbol sym) {
+        Binding binding = sym.getBinding();
+        if (binding == Symbol.Binding.GLOBAL) {
+            return Elf64_Sym.STB_GLOBAL;
+        }
+        return Elf64_Sym.STB_LOCAL;
     }
 
     /**
-     * Construct ELF symbol data from BinaryContainer object's symbol tables.
+     * Construct a Elf relocation table from BinaryContainer object's relocation tables.
      *
-     * @return a byte array containing the symbol table
-     */
-    private byte[] getELFSymbolTableData() {
-        final int entrySize = JNIELFTargetInfo.sizeOfSymtabEntry();
-
-        // First, add all local symbols.
-        List<ELFSymbol> localSymbols = elfContainer.getLocalSymbols();
-        List<ELFSymbol> globalSymbols = elfContainer.getGlobalSymbols();
-
-        int localSymCount = localSymbols.size();
-        int globalSymCount = globalSymbols.size();
-        byte[] sectionDataArray = new byte[(localSymCount + globalSymCount) * entrySize];
-
-        for (int i = 0; i < localSymCount; i++) {
-            ELFSymbol symbol = localSymbols.get(i);
-            Pointer address = symbol.getAddress();
-            address.copyBytesTo(sectionDataArray, entrySize, i * entrySize);
-        }
-
-        // Next, add all global symbols.
-
-        for (int i = 0; i < globalSymCount; i++) {
-            ELFSymbol symbol = globalSymbols.get(i);
-            Pointer address = symbol.getAddress();
-            address.copyBytesTo(sectionDataArray, entrySize, (localSymCount + i) * entrySize);
-        }
-
-        return sectionDataArray;
-    }
-
-    private static int getELFTypeOf(Symbol sym) {
-        Kind kind = sym.getKind();
-        if (kind == Symbol.Kind.NATIVE_FUNCTION || kind == Symbol.Kind.JAVA_FUNCTION) {
-            return ELF.STT_FUNC;
-        } else if (kind == Symbol.Kind.OBJECT) {
-            return ELF.STT_OBJECT;
-        }
-        return ELF.STT_NOTYPE;
-    }
-
-    private static int getELFBindOf(Symbol sym) {
-        Binding binding = sym.getBinding();
-        if (binding == Symbol.Binding.GLOBAL) {
-            return ELF.STB_GLOBAL;
-        }
-        return ELF.STB_LOCAL;
-    }
-
-    /**
-     * Construct ELF relocation section data from BinaryContainer object's relocation tables.
-     *
+     * @param sections
      * @param relocationTable
      */
-    private void createELFRelocationTables(Map<Symbol, List<Relocation>> relocationTable) {
+    private ElfRelocTable createElfRelocTable(ArrayList<ElfSection> sections,
+                                              Map<Symbol, List<Relocation>> relocationTable) {
+
+        ElfRelocTable elfRelocTable = new ElfRelocTable(sections.size());
         /*
-         * For each of the symbols with associated relocation records, create an ELF relocation
+         * For each of the symbols with associated relocation records, create a Elf relocation
          * entry.
          */
         for (Map.Entry<Symbol, List<Relocation>> entry : relocationTable.entrySet()) {
@@ -252,18 +303,26 @@
             Symbol symbol = entry.getKey();
 
             for (Relocation reloc : relocs) {
-                createRelocation(symbol, reloc);
+                createRelocation(symbol, reloc, elfRelocTable);
             }
         }
 
         for (Map.Entry<Symbol, Relocation> entry : binContainer.getUniqueRelocationTable().entrySet()) {
-            createRelocation(entry.getKey(), entry.getValue());
+            createRelocation(entry.getKey(), entry.getValue(), elfRelocTable);
         }
+
+        return (elfRelocTable);
     }
 
-    private void createRelocation(Symbol symbol, Relocation reloc) {
+    private void createRelocation(Symbol symbol, Relocation reloc, ElfRelocTable elfRelocTable) {
         RelocType relocType = reloc.getType();
+
         int elfRelocType = getELFRelocationType(relocType);
+        ElfSymbol sym = (ElfSymbol)symbol.getNativeSymbol();
+        int symno = sym.getIndex();
+        int sectindex = reloc.getSection().getSectionId();
+        int offset = reloc.getOffset();
+        int addend = 0;
 
         switch (relocType) {
             case FOREIGN_CALL_DIRECT:
@@ -271,85 +330,89 @@
             case STUB_CALL_DIRECT:
             case FOREIGN_CALL_INDIRECT_GOT: {
                 // Create relocation entry
-                int addend = -4; // Size in bytes of the patch location
+                // System.out.println("getELFRelocationType: PLT relocation type using X86_64_RELOC_BRANCH");
+                addend = -4; // Size in bytes of the patch location
                 // Relocation should be applied at the location after call operand
-                int offset = reloc.getOffset() + reloc.getSize() + addend;
-                elfContainer.createELFRelocationEntry(reloc.getSection(), offset, elfRelocType, addend, symbol.getElfSymbol());
+                offset = offset + reloc.getSize() + addend;
                 break;
             }
             case FOREIGN_CALL_DIRECT_FAR: {
                 // Create relocation entry
-                int addend = -8; // Size in bytes of the patch location
+                addend = -8; // Size in bytes of the patch location
                 // Relocation should be applied at the location after call operand
                 // 10 = 2 (jmp [r]) + 8 (imm64)
-                int offset = reloc.getOffset() + reloc.getSize() + addend - 2;
-                elfContainer.createELFRelocationEntry(reloc.getSection(), offset, elfRelocType, addend, symbol.getElfSymbol());
+                offset = offset + reloc.getSize() + addend - 2;
                 break;
             }
             case FOREIGN_CALL_INDIRECT:
             case JAVA_CALL_INDIRECT:
             case STUB_CALL_INDIRECT: {
                 // Do nothing.
-                break;
+                return;
             }
             case EXTERNAL_DATA_REFERENCE_FAR: {
                 // Create relocation entry
-                int addend = -4; // Size of 32-bit address of the GOT
+                addend = -4; // Size of 32-bit address of the GOT
                 /*
                  * Relocation should be applied before the test instruction to the move instruction.
-                 * reloc.getOffset() points to the test instruction after the instruction that loads
+                 * offset points to the test instruction after the instruction that loads
                  * the address of polling page. So set the offset appropriately.
                  */
-                int offset = reloc.getOffset() + addend;
-                elfContainer.createELFRelocationEntry(reloc.getSection(), offset, elfRelocType, addend, symbol.getElfSymbol());
+                offset = offset + addend;
                 break;
             }
             case METASPACE_GOT_REFERENCE:
             case EXTERNAL_PLT_TO_GOT:
             case STATIC_STUB_TO_STATIC_METHOD:
             case STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT: {
-                int addend = -4; // Size of 32-bit address of the GOT
+                addend = -4; // Size of 32-bit address of the GOT
                 /*
-                 * Relocation should be applied before the test instruction to the move instruction.
-                 * reloc.getOffset() points to the test instruction after the instruction that loads
-                 * the address of polling page. So set the offset appropriately.
+                 * Relocation should be applied before the test instruction to
+                 * the move instruction. reloc.getOffset() points to the
+                 * test instruction after the instruction that loads the
+                 * address of polling page. So set the offset appropriately.
                  */
-                int offset = reloc.getOffset() + addend;
-                elfContainer.createELFRelocationEntry(reloc.getSection(), offset, elfRelocType, addend, symbol.getElfSymbol());
+                offset = offset + addend;
                 break;
             }
             case EXTERNAL_GOT_TO_PLT:
             case LOADTIME_ADDRESS: {
                 // this is load time relocations
-                elfContainer.createELFRelocationEntry(reloc.getSection(), reloc.getOffset(), elfRelocType, 0, symbol.getElfSymbol());
                 break;
             }
             default:
                 throw new InternalError("Unhandled relocation type: " + relocType);
         }
+        elfRelocTable.createRelocationEntry(sectindex, offset, symno, elfRelocType, addend);
     }
 
-    // TODO: Populate the mapping of RelocType to ELF relocation types
     private static int getELFRelocationType(RelocType relocType) {
         int elfRelocType = 0; // R_<ARCH>_NONE if #define'd to 0 for all values of ARCH
-        switch (JNIELFTargetInfo.getELFArch()) {
-            case ELF.EM_X64_64:
+        switch (ElfTargetInfo.getElfArch()) {
+            case Elf64_Ehdr.EM_X86_64:
                 // Return R_X86_64_* entries based on relocType
-                if (relocType == RelocType.FOREIGN_CALL_DIRECT || relocType == RelocType.JAVA_CALL_DIRECT || relocType == RelocType.FOREIGN_CALL_INDIRECT_GOT) {
-                    elfRelocType = JNIELFRelocation.X86_64.R_X86_64_PLT32;
+                if (relocType == RelocType.FOREIGN_CALL_DIRECT ||
+                    relocType == RelocType.JAVA_CALL_DIRECT ||
+                    relocType == RelocType.FOREIGN_CALL_INDIRECT_GOT) {
+                    elfRelocType = Elf64_Rela.R_X86_64_PLT32;
                 } else if (relocType == RelocType.STUB_CALL_DIRECT) {
-                    elfRelocType = JNIELFRelocation.X86_64.R_X86_64_PC32;
+                    elfRelocType = Elf64_Rela.R_X86_64_PC32;
                 } else if (relocType == RelocType.FOREIGN_CALL_DIRECT_FAR) {
-                    elfRelocType = JNIELFRelocation.X86_64.R_X86_64_64;
-                } else if (relocType == RelocType.FOREIGN_CALL_INDIRECT || relocType == RelocType.JAVA_CALL_INDIRECT || relocType == RelocType.STUB_CALL_INDIRECT) {
-                    elfRelocType = JNIELFRelocation.X86_64.R_X86_64_NONE;
+                    elfRelocType = Elf64_Rela.R_X86_64_64;
+                } else if (relocType == RelocType.FOREIGN_CALL_INDIRECT ||
+                           relocType == RelocType.JAVA_CALL_INDIRECT ||
+                           relocType == RelocType.STUB_CALL_INDIRECT) {
+                    elfRelocType = Elf64_Rela.R_X86_64_NONE;
                 } else if ((relocType == RelocType.EXTERNAL_DATA_REFERENCE_FAR)) {
-                    elfRelocType = JNIELFRelocation.X86_64.R_X86_64_GOTPCREL;
-                } else if (relocType == RelocType.METASPACE_GOT_REFERENCE || relocType == RelocType.EXTERNAL_PLT_TO_GOT || relocType == RelocType.STATIC_STUB_TO_STATIC_METHOD ||
-                                relocType == RelocType.STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT) {
-                    elfRelocType = JNIELFRelocation.X86_64.R_X86_64_PC32;
-                } else if (relocType == RelocType.EXTERNAL_GOT_TO_PLT || relocType == RelocType.LOADTIME_ADDRESS) {
-                    elfRelocType = JNIELFRelocation.X86_64.R_X86_64_64;
+                    elfRelocType = Elf64_Rela.R_X86_64_GOTPCREL;
+                } else if (relocType == RelocType.METASPACE_GOT_REFERENCE ||
+                           relocType == RelocType.EXTERNAL_PLT_TO_GOT ||
+                           relocType == RelocType.STATIC_STUB_TO_STATIC_METHOD ||
+                           relocType == RelocType.STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT) {
+                    elfRelocType = Elf64_Rela.R_X86_64_PC32;
+                } else if (relocType == RelocType.EXTERNAL_GOT_TO_PLT ||
+                           relocType == RelocType.LOADTIME_ADDRESS) {
+                    elfRelocType = Elf64_Rela.R_X86_64_64;
                 } else {
                     assert false : "Unhandled relocation type: " + relocType;
                 }
@@ -360,61 +423,26 @@
         return elfRelocType;
     }
 
-    private void createAllRelocationSections(ELFContainer symtab) {
-        for (Map.Entry<ELFContainer, ArrayList<Pointer>> entry : elfContainer.getRelocTables().entrySet()) {
-            createRelocationSection(entry.getKey(), entry.getValue(), symtab);
-        }
-    }
+    private void createElfRelocSections(ArrayList<ElfSection> sections,
+                                        ElfRelocTable elfRelocTable,
+                                        int symtabsectidx) {
 
-    private void createRelocationSection(ELFContainer container, ArrayList<Pointer> relocations, ELFContainer symtab) {
-        String secName = container.getContainerName();
-        int entrySize = JNIELFTargetInfo.sizeOfRelocEntry();
-        int numEntries = relocations.size();
-        byte[] sectionDataBytes = new byte[numEntries * entrySize];
+        // Grab count before we create new sections
+        int count = sections.size();
 
-        for (int index = 0; index < relocations.size(); index++) {
-            Pointer entry = relocations.get(index);
-            entry.copyBytesTo(sectionDataBytes, entrySize, index * entrySize);
-        }
-        String fullSecName;
-        // If relocDat is non-null create section
-        if (sectionDataBytes.length > 0) {
-            int scnType;
-            Elf_Type dataType;
-            if (JNIELFTargetInfo.createReloca() == 0) {
-                scnType = ELF.SHT_REL;
-                dataType = Elf_Type.ELF_T_REL;
-                fullSecName = ".rel" + secName;
-            } else {
-                scnType = ELF.SHT_RELA;
-                dataType = Elf_Type.ELF_T_RELA;
-                fullSecName = ".rela" + secName;
+        for (int i = 0; i < count; i++) {
+            if (elfRelocTable.getNumRelocs(i) > 0) {
+                ElfSection sect = sections.get(i);
+                String relname = ".rela" + sect.getName();
+                ElfSection relocSection = createByteSection(sections,
+                                                            relname,
+                                                            elfRelocTable.getRelocData(i),
+                                                            false,
+                                                            0,
+                                                            Elf64_Shdr.SHT_RELA);
+                relocSection.setLink(symtabsectidx);
+                relocSection.setInfo(sect.getSectionId());
             }
-            // assert compareBytes(relocData.toByteArray(), sectionDataBytes) : "******* Bad array
-            // copy";
-            // sh_link holds the index of section header of symbol table associated with this
-            // relocation table.
-            // sh_info holds the index of section header to which this relocation table applies
-            // to.
-            elfContainer.createSection(fullSecName, sectionDataBytes, dataType, 8, scnType, ELF.SHF_ALLOC, symtab.getSectionId(), container.getSectionId());
-        }
-    }
-
-    private static class SymTabELFContainer implements ELFContainer {
-        private final int symTabSectionIndex;
-
-        public SymTabELFContainer(int symTabSectionIndex) {
-            this.symTabSectionIndex = symTabSectionIndex;
-        }
-
-        @Override
-        public String getContainerName() {
-            return ".symtab";
-        }
-
-        @Override
-        public int getSectionId() {
-            return symTabSectionIndex;
         }
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/JMachORelocObject.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,474 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ *
+ * File Layout generated by JMachORelocObject
+ *
+ * MachO Header
+ * Load Commands
+ *   LC_SEGMENT_64
+ *    - Sections
+ *   LC_VERSION_MIN_MAX
+ *   LC_SYMTAB
+ *   LC_DYSYMTAB
+ * Section Data
+ * Relocation entries
+ * Symbol table
+ *
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import jdk.tools.jaotc.binformat.BinaryContainer;
+import jdk.tools.jaotc.binformat.ByteContainer;
+import jdk.tools.jaotc.binformat.CodeContainer;
+import jdk.tools.jaotc.binformat.ReadOnlyDataContainer;
+import jdk.tools.jaotc.binformat.Relocation;
+import jdk.tools.jaotc.binformat.Relocation.RelocType;
+import jdk.tools.jaotc.binformat.Symbol;
+import jdk.tools.jaotc.binformat.NativeSymbol;
+import jdk.tools.jaotc.binformat.Symbol.Binding;
+import jdk.tools.jaotc.binformat.Symbol.Kind;
+
+import jdk.tools.jaotc.binformat.macho.MachO;
+import jdk.tools.jaotc.binformat.macho.MachO.section_64;
+import jdk.tools.jaotc.binformat.macho.MachO.mach_header_64;
+import jdk.tools.jaotc.binformat.macho.MachO.segment_command_64;
+import jdk.tools.jaotc.binformat.macho.MachO.version_min_command;
+import jdk.tools.jaotc.binformat.macho.MachO.symtab_command;
+import jdk.tools.jaotc.binformat.macho.MachO.dysymtab_command;
+import jdk.tools.jaotc.binformat.macho.MachO.nlist_64;
+import jdk.tools.jaotc.binformat.macho.MachO.reloc_info;
+import jdk.tools.jaotc.binformat.macho.MachOContainer;
+import jdk.tools.jaotc.binformat.macho.MachOTargetInfo;
+import jdk.tools.jaotc.binformat.macho.MachOSymtab;
+import jdk.tools.jaotc.binformat.macho.MachORelocTable;
+
+public class JMachORelocObject {
+
+    private final BinaryContainer binContainer;
+
+    private final MachOContainer machoContainer;
+
+    private final int segmentSize;
+
+    public JMachORelocObject(BinaryContainer binContainer, String outputFileName) {
+        this.binContainer = binContainer;
+        this.machoContainer = new MachOContainer(outputFileName);
+        this.segmentSize = binContainer.getCodeSegmentSize();
+    }
+
+    private void createByteSection(ArrayList<MachOSection>sections,
+                                   ByteContainer c, String sectName, String segName, int scnFlags) {
+
+        if (c.getByteArray().length == 0) {
+            // System.out.println("Skipping creation of " + sectName + " section, no data\n");
+        }
+
+        MachOSection sect = new MachOSection(sectName,
+                                             segName,
+                                             c.getByteArray(),
+                                             scnFlags,
+                                             c.hasRelocations());
+        // Add this section to our list
+        sections.add(sect);
+
+        // Record the section Id (0 relative)
+        c.setSectionId(sections.size()-1);
+
+        // TODO: Clear out code section data to allow for GC
+        // c.clear();
+    }
+
+    private void createCodeSection(ArrayList<MachOSection>sections, CodeContainer c) {
+        createByteSection(sections, c, /*c.getContainerName()*/ "__text", "__TEXT",
+                          section_64.S_ATTR_PURE_INSTRUCTIONS|
+                          section_64.S_ATTR_SOME_INSTRUCTIONS);
+    }
+
+    private void createReadOnlySection(ArrayList<MachOSection>sections, ReadOnlyDataContainer c) {
+        createByteSection(sections, c, c.getContainerName(), "__TEXT",
+                          section_64.S_ATTR_SOME_INSTRUCTIONS);
+    }
+
+    private void createReadWriteSection(ArrayList<MachOSection>sections, ByteContainer c) {
+        createByteSection(sections, c, c.getContainerName(), "__DATA", section_64.S_REGULAR);
+    }
+
+    /**
+     * Create an MachO relocatable object
+     *
+     * @param relocationTable
+     * @param symbols
+     * @throws IOException throws {@code IOException} as a result of file system access failures.
+     */
+    public void createMachORelocObject(Map<Symbol, List<Relocation>> relocationTable, Collection<Symbol> symbols) throws IOException {
+        // Allocate MachO Header
+        // with 4 load commands
+        //   LC_SEGMENT_64
+        //   LC_VERSION_MIN_MACOSX
+        //   LC_SYMTAB
+        //   LC_DYSYMTAB
+
+        MachOHeader mh = new MachOHeader();
+
+        ArrayList<MachOSection> sections = new ArrayList<MachOSection>();
+
+        // Create Sections contained in the main Segment LC_SEGMENT_64
+
+        createCodeSection(sections, binContainer.getCodeContainer());
+        createReadOnlySection(sections, binContainer.getMetaspaceNamesContainer());
+        createReadOnlySection(sections, binContainer.getKlassesOffsetsContainer());
+        createReadOnlySection(sections, binContainer.getMethodsOffsetsContainer());
+        createReadOnlySection(sections, binContainer.getKlassesDependenciesContainer());
+        createReadWriteSection(sections, binContainer.getMetaspaceGotContainer());
+        createReadWriteSection(sections, binContainer.getMetadataGotContainer());
+        createReadWriteSection(sections, binContainer.getMethodStateContainer());
+        createReadWriteSection(sections, binContainer.getOopGotContainer());
+        createReadWriteSection(sections, binContainer.getMethodMetadataContainer());
+        createReadOnlySection(sections, binContainer.getStubsOffsetsContainer());
+        createReadOnlySection(sections, binContainer.getHeaderContainer().getContainer());
+        createReadOnlySection(sections, binContainer.getCodeSegmentsContainer());
+        createReadOnlySection(sections, binContainer.getConstantDataContainer());
+        createReadOnlySection(sections, binContainer.getConfigContainer());
+
+        // createExternalLinkage();
+
+        createCodeSection(sections, binContainer.getExtLinkageContainer());
+        createReadWriteSection(sections, binContainer.getExtLinkageGOTContainer());
+        // Update the Header sizeofcmds size.
+        // This doesn't include the Header struct size
+        mh.setCmdSizes(4, segment_command_64.totalsize +
+                          (section_64.totalsize * sections.size()) +
+                          version_min_command.totalsize +
+                          symtab_command.totalsize +
+                          dysymtab_command.totalsize);
+
+        // Initialize file offset for data past commands
+        int file_offset = mach_header_64.totalsize + mh.getCmdSize();
+        // and round it up
+        file_offset = (file_offset + (sections.get(0).getAlign()-1)) & ~((sections.get(0).getAlign()-1));
+        long address = 0;
+        int segment_offset = file_offset;
+
+        for (int i = 0; i < sections.size(); i++) {
+            MachOSection sect = sections.get(i);
+            file_offset = (file_offset + (sect.getAlign()-1)) & ~((sect.getAlign()-1));
+            address = (address + (sect.getAlign()-1)) & ~((sect.getAlign()-1));
+            sect.setOffset(file_offset);
+            sect.setAddr(address);
+            file_offset += sect.getSize();
+            address += sect.getSize();
+        }
+
+        // File size for Segment data
+        int segment_size = file_offset - segment_offset;
+
+        // Create the LC_SEGMENT_64 Segment which contains the MachOSections
+        MachOSegment seg = new MachOSegment(segment_command_64.totalsize +
+                                            (section_64.totalsize * sections.size()),
+                                            segment_offset,
+                                            segment_size,
+                                            sections.size());
+
+
+        MachOVersion vers = new MachOVersion();
+
+        // Get symbol data from BinaryContainer object's symbol tables
+        MachOSymtab symtab = createMachOSymbolTables(sections, symbols);
+
+        // Create LC_DYSYMTAB command
+        MachODySymtab dysymtab = new MachODySymtab(symtab.getNumLocalSyms(),
+                                                   symtab.getNumGlobalSyms(),
+                                                   symtab.getNumUndefSyms());
+
+        // Create the Relocation Tables
+        MachORelocTable machORelocs = createMachORelocTable(sections, relocationTable, symtab);
+        // Calculate file offset for relocation data
+        file_offset = (file_offset + (machORelocs.getAlign()-1)) & ~((machORelocs.getAlign()-1));
+
+        // Update relocation sizing information in each section
+        for (int i = 0; i < sections.size(); i++) {
+            MachOSection sect = sections.get(i);
+            if (sect.hasRelocations()) {
+                int nreloc = machORelocs.getNumRelocs(i);
+                sect.setReloff(file_offset);
+                sect.setRelcount(nreloc);
+                file_offset += (nreloc * reloc_info.totalsize);
+            }
+        }
+
+        // Calculate and set file offset for symbol table data
+        file_offset = (file_offset + (symtab.getAlign()-1)) & ~((symtab.getAlign()-1));
+        symtab.setOffset(file_offset);
+
+
+        // Write Out Header
+        machoContainer.writeBytes(mh.getArray());
+        // Write out first Segment
+        machoContainer.writeBytes(seg.getArray());
+        // Write out sections within first Segment
+        for (int i = 0; i < sections.size(); i++) {
+            MachOSection sect = sections.get(i);
+            machoContainer.writeBytes(sect.getArray());
+        }
+
+        // Write out LC_VERSION_MIN_MACOSX command
+        machoContainer.writeBytes(vers.getArray());
+
+        // Write out LC_SYMTAB command
+        symtab.calcSizes();
+        machoContainer.writeBytes(symtab.getCmdArray());
+
+        // Write out LC_DYSYMTAB command
+        machoContainer.writeBytes(dysymtab.getArray());
+
+        // Write out data associated with each Section
+        for (int i = 0; i < sections.size(); i++) {
+            MachOSection sect = sections.get(i);
+            machoContainer.writeBytes(sect.getDataArray(), sect.getAlign());
+        }
+
+        // Write out the relocation tables for all sections
+        for (int i = 0; i < sections.size(); i++) {
+            if (machORelocs.getNumRelocs(i) > 0)
+                machoContainer.writeBytes(machORelocs.getRelocData(i), machORelocs.getAlign());
+        }
+
+        // Write out data associated with LC_SYMTAB
+        machoContainer.writeBytes(symtab.getDataArray(), symtab.getAlign());
+
+        machoContainer.close();
+    }
+
+    /**
+     * Construct MachO symbol data from BinaryContainer object's symbol tables. Both dynamic MachO
+     * symbol table and MachO symbol table are created from BinaryContainer's symbol info.
+     *
+     * @param symbols
+     * @param symtab
+     */
+    private MachOSymtab createMachOSymbolTables(ArrayList<MachOSection>sections,
+                                         Collection<Symbol> symbols) {
+        MachOSymtab symtab = new MachOSymtab();
+        // First, create the initial null symbol. This is a local symbol.
+        symtab.addSymbolEntry("", (byte)nlist_64.N_UNDF, (byte)0, (long)0);
+
+        // Now create MachO symbol entries for all symbols.
+        for (Symbol symbol : symbols) {
+            int sectionId = symbol.getSection().getSectionId();
+
+            // Symbol offsets are relative to the section memory addr
+            long sectionAddr = sections.get(sectionId).getAddr();
+
+            MachOSymbol machoSymbol = symtab.addSymbolEntry(symbol.getName(),
+                                         getMachOTypeOf(symbol),
+                                         (byte)sectionId,
+                                         symbol.getOffset() + sectionAddr);
+            symbol.setNativeSymbol((NativeSymbol)machoSymbol);
+        }
+
+        // Now that all symbols are enterred, update the
+        // symbol indexes.  This is necessary since they will
+        // be reordered based on local, global and undefined.
+        symtab.updateIndexes();
+
+        return (symtab);
+    }
+
+    private static byte getMachOTypeOf(Symbol sym) {
+        Kind kind = sym.getKind();
+        byte type = nlist_64.N_UNDF;
+
+        // Global or Local
+        if (sym.getBinding() == Symbol.Binding.GLOBAL)
+            type = nlist_64.N_EXT;
+
+        // If Function or Data, add section type
+        if (kind == Symbol.Kind.NATIVE_FUNCTION ||
+            kind == Symbol.Kind.JAVA_FUNCTION   ||
+            kind == Symbol.Kind.OBJECT) {
+            type |= (nlist_64.N_SECT);
+        }
+
+        return (type);
+    }
+
+    /**
+     * Construct a MachO relocation table from BinaryContainer object's relocation tables.
+     *
+     * @param sections
+     * @param relocationTable
+     * @param symtab
+     */
+    private MachORelocTable createMachORelocTable(ArrayList<MachOSection> sections,
+                                                  Map<Symbol, List<Relocation>> relocationTable,
+                                                  MachOSymtab symtab) {
+
+        MachORelocTable machORelocTable = new MachORelocTable(sections.size());
+        /*
+         * For each of the symbols with associated relocation records, create a MachO relocation
+         * entry.
+         */
+        for (Map.Entry<Symbol, List<Relocation>> entry : relocationTable.entrySet()) {
+            List<Relocation> relocs = entry.getValue();
+            Symbol symbol = entry.getKey();
+
+            for (Relocation reloc : relocs) {
+                createRelocation(symbol, reloc, machORelocTable);
+            }
+        }
+
+        for (Map.Entry<Symbol, Relocation> entry : binContainer.getUniqueRelocationTable().entrySet()) {
+            createRelocation(entry.getKey(), entry.getValue(), machORelocTable);
+        }
+
+        return (machORelocTable);
+    }
+
+    private void createRelocation(Symbol symbol, Relocation reloc, MachORelocTable machORelocTable) {
+        RelocType relocType = reloc.getType();
+
+        int machORelocType = getMachORelocationType(relocType);
+        MachOSymbol sym = (MachOSymbol)symbol.getNativeSymbol();
+        int symno = sym.getIndex();
+        int sectindex = reloc.getSection().getSectionId();
+        int offset = reloc.getOffset();
+        int pcrel = 0;
+        int length = 0;
+        int isextern = 1;
+
+/*
+        System.out.println("reloctype: " + relocType + " size is " +
+                            reloc.getSize() + " offset is " + offset +
+                            " Section Index is " + (sectindex) +
+                            " Symbol Index is " + symno +
+                            " Symbol Name is " + symbol.getName() + "\n");
+*/
+
+        switch (relocType) {
+            case FOREIGN_CALL_DIRECT:
+            case JAVA_CALL_DIRECT:
+            case STUB_CALL_DIRECT:
+            case FOREIGN_CALL_INDIRECT_GOT: {
+                // Create relocation entry
+                // System.out.println("getMachORelocationType: PLT relocation type using X86_64_RELOC_BRANCH");
+                int addend = -4; // Size in bytes of the patch location
+                // Relocation should be applied at the location after call operand
+                offset = offset + reloc.getSize() + addend;
+                pcrel = 1; length = 2;
+                break;
+            }
+            case FOREIGN_CALL_DIRECT_FAR: {
+                // Create relocation entry
+                int addend = -8; // Size in bytes of the patch location
+                // Relocation should be applied at the location after call operand
+                // 10 = 2 (jmp [r]) + 8 (imm64)
+                offset = offset + reloc.getSize() + addend - 2;
+                pcrel = 0; length = 3;
+                break;
+            }
+            case FOREIGN_CALL_INDIRECT:
+            case JAVA_CALL_INDIRECT:
+            case STUB_CALL_INDIRECT: {
+                // Do nothing.
+                return;
+            }
+            case EXTERNAL_DATA_REFERENCE_FAR: {
+                // Create relocation entry
+                int addend = -4; // Size of 32-bit address of the GOT
+                /*
+                 * Relocation should be applied before the test instruction to the move instruction.
+                 * offset points to the test instruction after the instruction that loads
+                 * the address of polling page. So set the offset appropriately.
+                 */
+                offset = offset + addend;
+                pcrel = 0; length = 2;
+                break;
+            }
+            case METASPACE_GOT_REFERENCE:
+            case EXTERNAL_PLT_TO_GOT:
+            case STATIC_STUB_TO_STATIC_METHOD:
+            case STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT: {
+                int addend = -4; // Size of 32-bit address of the GOT
+                /*
+                 * Relocation should be applied before the test instruction to
+                 * the move instruction. reloc.getOffset() points to the
+                 * test instruction after the instruction that loads the
+                 * address of polling page. So set the offset appropriately.
+                 */
+                offset = offset + addend;
+                pcrel = 1; length = 2;
+                break;
+            }
+            case EXTERNAL_GOT_TO_PLT:
+            case LOADTIME_ADDRESS: {
+                // this is load time relocations
+                pcrel = 0; length = 3;
+                break;
+            }
+            default:
+                throw new InternalError("Unhandled relocation type: " + relocType);
+        }
+        machORelocTable.createRelocationEntry(sectindex, offset, symno,
+                                              pcrel, length, isextern,
+                                              machORelocType);
+    }
+
+    private static int getMachORelocationType(RelocType relocType) {
+        int machORelocType = 0;
+        switch (MachOTargetInfo.getMachOArch()) {
+            case mach_header_64.CPU_TYPE_X86_64:
+                // Return X86_64_RELOC_* entries based on relocType
+                if (relocType == RelocType.FOREIGN_CALL_DIRECT || relocType == RelocType.JAVA_CALL_DIRECT || relocType == RelocType.FOREIGN_CALL_INDIRECT_GOT) {
+                    machORelocType = reloc_info.X86_64_RELOC_BRANCH;
+                } else if (relocType == RelocType.STUB_CALL_DIRECT) {
+                    machORelocType = reloc_info.X86_64_RELOC_BRANCH;
+                } else if (relocType == RelocType.FOREIGN_CALL_DIRECT_FAR) {
+                    machORelocType = reloc_info.X86_64_RELOC_UNSIGNED;
+                } else if (relocType == RelocType.FOREIGN_CALL_INDIRECT || relocType == RelocType.JAVA_CALL_INDIRECT || relocType == RelocType.STUB_CALL_INDIRECT) {
+                    machORelocType = reloc_info.X86_64_RELOC_NONE;
+                } else if ((relocType == RelocType.EXTERNAL_DATA_REFERENCE_FAR)) {
+                    machORelocType = reloc_info.X86_64_RELOC_GOT;
+                } else if (relocType == RelocType.METASPACE_GOT_REFERENCE || relocType == RelocType.EXTERNAL_PLT_TO_GOT || relocType == RelocType.STATIC_STUB_TO_STATIC_METHOD ||
+                                relocType == RelocType.STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT) {
+                    machORelocType = reloc_info.X86_64_RELOC_BRANCH;
+                } else if (relocType == RelocType.EXTERNAL_GOT_TO_PLT || relocType == RelocType.LOADTIME_ADDRESS) {
+                    machORelocType = reloc_info.X86_64_RELOC_UNSIGNED;
+                } else {
+                    assert false : "Unhandled relocation type: " + relocType;
+                }
+                break;
+            default:
+                System.out.println("Relocation Type mapping: Unhandled architecture");
+        }
+        return machORelocType;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachO.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,307 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+/**
+ *
+ * Support for the creation of Mach-o Object files.
+ * Current support is limited to 64 bit x86_64.
+ *
+ * File Format Overview:
+ *
+ *   mach_header
+ *   load_commands
+ *      Typical Mac OSX 64-bit object files have these 4 load_commands
+ *      (LC_SEGMENT_64, LC_SYMTAB, LC_VERSIN_MIN_MACOSX, LC_DYSYMTAB)
+ *   Segments corresponding to load_commands
+ *      (which each include multiple Sections)
+ */
+
+public class MachO {
+
+    /**
+     * mach_header_64 structure defines
+     */
+    public enum mach_header_64 {
+                 magic( 0, 4),
+               cputype( 4, 4),
+            cpusubtype( 8, 4),
+              filetype(12, 4),
+                 ncmds(16, 4),
+            sizeofcmds(20, 4),
+                 flags(24, 4),
+              reserved(28, 4);
+
+        public final int off;
+        public final int sz;
+
+        mach_header_64(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 32;
+
+        /**
+         * mach_header_64 defines
+         */
+        public static final int MH_MAGIC                   = 0xfeedface;
+        public static final int MH_MAGIC_64                = 0xfeedfacf;
+        public static final int MH_SUBSECTIONS_VIA_SYMBOLS = 0x2000;
+
+        /**
+         * filetype
+         */
+        public static final int MH_OBJECT = 0x1;
+
+        /**
+         * cputype
+         */
+        public static final int CPU_TYPE_ANY              = -1;
+        public static final int CPU_ARCH_ABI64            = 0x1000000;
+        public static final int CPU_TYPE_X86_64           = 0x1000007;
+        public static final int CPU_TYPE_ARM64            = 0x100000c;
+        /**
+         * cpusubtype
+         */
+        public static final int CPU_SUBTYPE_I386_ALL      = 3;
+        public static final int CPU_SUBTYPE_ARM64_ALL     = 0;
+        public static final int CPU_SUBTYPE_LITTLE_ENDIAN = 0;
+        public static final int CPU_SUBTYPE_BIG_ENDIAN    = 1;
+
+    }
+
+    /**
+     * segment_command_64 structure defines
+     */
+    public enum segment_command_64 {
+                   cmd( 0, 4),
+               cmdsize( 4, 4),
+               segname( 8,16),
+                vmaddr(24, 8),
+                vmsize(32, 8),
+               fileoff(40, 8),
+              filesize(48, 8),
+               maxprot(56, 4),
+              initprot(60, 4),
+                nsects(64, 4),
+                 flags(68, 4);
+
+        public final int off;
+        public final int sz;
+
+        segment_command_64(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 72;
+
+        public static final int LC_SEGMENT_64           = 0x19;
+    }
+
+    /**
+     * section_64 structure defines
+     */
+    public enum section_64 {
+              sectname( 0,16),
+               segname(16,16),
+                  addr(32, 8),
+                  size(40, 8),
+                offset(48, 4),
+                 align(52, 4),
+                reloff(56, 4),
+                nreloc(60, 4),
+                 flags(64, 4),
+             reserved1(68, 4),
+             reserved2(72, 4),
+             reserved3(76, 4);
+
+        public final int off;
+        public final int sz;
+
+        section_64(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 80;
+
+        public static int S_REGULAR                = 0x0;
+        public static int S_CSTRING_LITERALS       = 0x2;
+        public static int S_ATTR_PURE_INSTRUCTIONS = 0x80000000;
+        public static int S_ATTR_SOME_INSTRUCTIONS = 0x400;
+    }
+
+    /**
+     * version_min_command structure defines
+     */
+    public enum version_min_command {
+                   cmd( 0, 4),
+               cmdsize( 4, 4),
+               version( 8, 4),
+                   sdk(12, 4);
+
+        public final int off;
+        public final int sz;
+
+        version_min_command(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 16;
+
+        public static final int LC_VERSION_MIN_MACOSX   = 0x24;
+        public static final int LC_VERSION_MIN_IPHONEOS = 0x25;
+    }
+
+    /**
+     * symtab_command structure defines
+     */
+    public enum symtab_command {
+                   cmd( 0, 4),
+               cmdsize( 4, 4),
+                symoff( 8, 4),
+                 nsyms(12, 4),
+                stroff(16, 4),
+               strsize(20, 4);
+
+        public final int off;
+        public final int sz;
+
+        symtab_command(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 24;
+
+        public static final int LC_SYMTAB               = 0x2;
+    }
+
+    /**
+     * Symbol table entry definitions
+     *
+     * nlist_64 structure defines
+     */
+    public enum nlist_64 {
+                n_strx( 0, 4),
+                n_type( 4, 1),
+                n_sect( 5, 1),
+                n_desc( 6, 2),
+               n_value( 8, 8);
+
+        public final int off;
+        public final int sz;
+
+        nlist_64(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 16;
+
+        public static final int N_EXT                = 0x1;
+        public static final int N_TYPE               = 0xe;
+        public static final int N_UNDF               = 0x0;
+        public static final int N_SECT               = 0xe;
+    }
+
+    /**
+     * dysymtab_command structure defines
+     */
+    public enum dysymtab_command {
+                   cmd( 0, 4),
+               cmdsize( 4, 4),
+             ilocalsym( 8, 4),
+             nlocalsym(12, 4),
+            iextdefsym(16, 4),
+            nextdefsym(20, 4),
+             iundefsym(24, 4),
+             nundefsym(28, 4),
+                tocoff(32, 4),
+                  ntoc(36, 4),
+             modtaboff(40, 4),
+               nmodtab(44, 4),
+          extrefsymoff(48, 4),
+           nextrefsyms(52, 4),
+        indirectsymoff(56, 4),
+         nindirectsyms(60, 4),
+             extreloff(64, 4),
+               nextrel(68, 4),
+             locreloff(72, 4),
+               nlocrel(76, 4);
+
+        public final int off;
+        public final int sz;
+
+        dysymtab_command(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 80;
+
+        public static final int LC_DYSYMTAB             = 0xb;
+    }
+
+    /**
+     * relocation_info structure defines
+     */
+    public enum reloc_info {
+             r_address( 0, 4),
+           r_relocinfo( 4, 4);
+
+        public final int off;
+        public final int sz;
+
+        reloc_info(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 8;
+
+        public static final int REL_SYMNUM_MASK         = 0xffffff;
+        public static final int REL_SYMNUM_SHIFT        = 0x0;
+        public static final int REL_PCREL_MASK          = 0x1;
+        public static final int REL_PCREL_SHIFT         = 0x18;
+        public static final int REL_LENGTH_MASK         = 0x3;
+        public static final int REL_LENGTH_SHIFT        = 0x19;
+        public static final int REL_EXTERN_MASK         = 0x1;
+        public static final int REL_EXTERN_SHIFT        = 0x1b;
+        public static final int REL_TYPE_MASK           = 0xf;
+        public static final int REL_TYPE_SHIFT          = 0x1c;
+
+        /* reloc_type_x86_64 defines */
+
+        public static final int X86_64_RELOC_NONE      = 0x0;
+        public static final int X86_64_RELOC_BRANCH    = 0x2;
+        public static final int X86_64_RELOC_GOT       = 0x4;
+        public static final int X86_64_RELOC_GOT_LOAD  = 0x3;
+        public static final int X86_64_RELOC_SIGNED    = 0x1;
+        public static final int X86_64_RELOC_UNSIGNED  = 0x0;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOByteBuffer.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import jdk.tools.jaotc.binformat.macho.MachOTargetInfo;
+import jdk.tools.jaotc.binformat.macho.MachO.mach_header_64;
+
+public class MachOByteBuffer {
+
+    public static ByteBuffer allocate(int size) {
+        ByteBuffer buf = ByteBuffer.allocate(size);
+        if (MachOTargetInfo.getMachOEndian() ==
+            MachO.mach_header_64.CPU_SUBTYPE_LITTLE_ENDIAN)
+            buf.order(ByteOrder.LITTLE_ENDIAN);
+        else
+            buf.order(ByteOrder.BIG_ENDIAN);
+        return (buf);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOContainer.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+public class MachOContainer {
+
+    File outputFile;
+    FileOutputStream outputStream;
+    long fileOffset;
+
+    public MachOContainer(String fileName) {
+        String baseName;
+
+        outputFile = new File(fileName);
+        if (outputFile.exists()) {
+            outputFile.delete();
+        }
+
+        try {
+            outputStream = new FileOutputStream(outputFile);
+        } catch (Exception e) {
+            System.out.println("MachOContainer: Can't create file " + fileName);
+        }
+        fileOffset = 0;
+    }
+
+    public void close() {
+        try {
+            outputStream.close();
+        } catch (Exception e) {
+            System.out.println("MachOContainer: close failed");
+        }
+    }
+
+    public void writeBytes(byte [] bytes) {
+        try {
+            outputStream.write(bytes);
+        } catch (Exception e) {
+            System.out.println("MachOContainer: writeBytes failed");
+        }
+        fileOffset += bytes.length;
+    }
+
+    // Write bytes to output file with up front alignment padding
+    public void writeBytes(byte [] bytes, int alignment) {
+        try {
+            // Pad to alignment
+            while ((fileOffset & (long)(alignment-1)) != 0) {
+                outputStream.write(0);
+                fileOffset++;
+            }
+            outputStream.write(bytes);
+        } catch (Exception e) {
+            System.out.println("MachOContainer: writeBytes failed");
+        }
+        fileOffset += bytes.length;
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachODySymtab.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.macho.MachO;
+import jdk.tools.jaotc.binformat.macho.MachO.dysymtab_command;
+import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
+
+public class MachODySymtab {
+    ByteBuffer dysymtab;
+
+    public MachODySymtab(int nlocal, int nglobal, int nundef) {
+        dysymtab = MachOByteBuffer.allocate(dysymtab_command.totalsize);
+
+        dysymtab.putInt(dysymtab_command.cmd.off, dysymtab_command.LC_DYSYMTAB);
+        dysymtab.putInt(dysymtab_command.cmdsize.off, dysymtab_command.totalsize);
+        dysymtab.putInt(dysymtab_command.ilocalsym.off, 0);
+        dysymtab.putInt(dysymtab_command.nlocalsym.off, nlocal);
+        dysymtab.putInt(dysymtab_command.iextdefsym.off, nlocal);
+        dysymtab.putInt(dysymtab_command.nextdefsym.off, nglobal);
+        dysymtab.putInt(dysymtab_command.iundefsym.off, nlocal+nglobal);
+        dysymtab.putInt(dysymtab_command.nundefsym.off, nundef);
+    }
+
+    public byte[] getArray() {
+        return dysymtab.array();
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOHeader.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.macho.MachO;
+import jdk.tools.jaotc.binformat.macho.MachO.mach_header_64;
+import jdk.tools.jaotc.binformat.macho.MachOTargetInfo;
+import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
+
+public class MachOHeader {
+    ByteBuffer header;
+
+    public MachOHeader() {
+        header = MachOByteBuffer.allocate(mach_header_64.totalsize);
+
+        header.putInt(mach_header_64.magic.off, mach_header_64.MH_MAGIC_64);
+        header.putInt(mach_header_64.cputype.off, MachOTargetInfo.getMachOArch());
+        header.putInt(mach_header_64.cpusubtype.off, MachOTargetInfo.getMachOSubArch());
+        header.putInt(mach_header_64.flags.off, 0x2000);
+        header.putInt(mach_header_64.filetype.off, mach_header_64.MH_OBJECT);
+    }
+
+    public void setCmdSizes(int ncmds, int sizeofcmds) {
+        header.putInt(mach_header_64.ncmds.off, ncmds);
+        header.putInt(mach_header_64.sizeofcmds.off, sizeofcmds);
+    }
+
+    public int getCmdSize() {
+        return (header.getInt(mach_header_64.sizeofcmds.off));
+    }
+
+    public byte[] getArray() {
+        return header.array();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachORelocEntry.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.macho.MachO;
+import jdk.tools.jaotc.binformat.macho.MachO.reloc_info;
+import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
+
+public class MachORelocEntry {
+    ByteBuffer entry;
+
+    public MachORelocEntry(int offset,
+                           int symno,
+                           int pcrel,
+                           int length,
+                           int isextern,
+                           int type) {
+
+        entry = MachOByteBuffer.allocate(reloc_info.totalsize);
+
+        entry.putInt(reloc_info.r_address.off, offset);
+
+        // Encode and store the relocation entry bitfields
+        entry.putInt(reloc_info.r_relocinfo.off,
+            ((symno & reloc_info.REL_SYMNUM_MASK)
+             << reloc_info.REL_SYMNUM_SHIFT) |
+            ((pcrel & reloc_info.REL_PCREL_MASK)
+             << reloc_info.REL_PCREL_SHIFT) |
+            ((length & reloc_info.REL_LENGTH_MASK)
+             << reloc_info.REL_LENGTH_SHIFT) |
+            ((isextern & reloc_info.REL_EXTERN_MASK)
+             << reloc_info.REL_EXTERN_SHIFT) |
+            ((type & reloc_info.REL_TYPE_MASK)
+             << reloc_info.REL_TYPE_SHIFT));
+    }
+
+    public byte[] getArray() {
+        return entry.array();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachORelocTable.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+import java.util.ArrayList;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.macho.MachORelocEntry;
+import jdk.tools.jaotc.binformat.macho.MachOTargetInfo;
+import jdk.tools.jaotc.binformat.macho.MachO.reloc_info;
+import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
+
+public class MachORelocTable {
+    ArrayList<ArrayList<MachORelocEntry>> relocEntries;
+    int fileOffset;
+
+    public MachORelocTable(int numsects) {
+        relocEntries = new ArrayList<ArrayList<MachORelocEntry>>(numsects);
+        for (int i = 0; i < numsects; i++)
+            relocEntries.add(new ArrayList<MachORelocEntry>());
+    }
+
+    public void createRelocationEntry(int sectindex,
+                                 int offset,
+                                 int symno,
+                                 int pcrel,
+                                 int length,
+                                 int isextern,
+                                 int type) {
+
+        MachORelocEntry entry = new MachORelocEntry(offset,
+                                                    symno,
+                                                    pcrel,
+                                                    length,
+                                                    isextern,
+                                                    type);
+        relocEntries.get(sectindex).add(entry);
+    }
+
+    public int getAlign() {
+        return (4);
+    }
+
+    public int getNumRelocs(int section_index) {
+        return relocEntries.get(section_index).size();
+    }
+
+    // Return the relocation entries for a single section
+    //   or null if no entries added to section
+    public byte [] getRelocData(int section_index) {
+        ArrayList<MachORelocEntry> entryList = relocEntries.get(section_index);
+
+        if (entryList.size() == 0)
+            return null;
+
+        ByteBuffer relocData = MachOByteBuffer.allocate(entryList.size() * reloc_info.totalsize);
+
+        // Copy each entry to a single ByteBuffer
+        for (int i = 0; i < entryList.size(); i++) {
+            MachORelocEntry entry = entryList.get(i);
+            relocData.put(entry.getArray());
+        }
+
+        return (relocData.array());
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.macho.MachO;
+import jdk.tools.jaotc.binformat.macho.MachO.section_64;
+import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
+
+public class MachOSection {
+    ByteBuffer section;
+    byte [] data;
+    boolean hasrelocations;
+
+    public MachOSection(String sectName, String segName, byte [] sectData, int sectFlags, boolean hasRelocations) {
+        section = MachOByteBuffer.allocate(section_64.totalsize);
+
+        // TODO: Hotspot uses long section names.
+        //       They are getting truncated.
+        //       Is this a problem??
+        byte[] sectNameBytes = sectName.getBytes();
+        int sectNameMax = section_64.sectname.sz < sectNameBytes.length ?
+                         section_64.sectname.sz : sectNameBytes.length;
+
+        for (int i = 0; i < sectNameMax; i++)
+            section.put(section_64.sectname.off+i, sectNameBytes[i]);
+
+        byte[] segNameBytes = segName.getBytes();
+        int segNameMax = section_64.segname.sz < segNameBytes.length ?
+                         section_64.segname.sz : segNameBytes.length;
+
+        for (int i = 0; i < segNameMax; i++)
+            section.put(section_64.segname.off+i, segNameBytes[i]);
+
+        section.putLong(section_64.size.off, sectData.length);
+
+        // For now use 8 byte alignment
+        section.putInt(section_64.align.off, 3);
+
+        section.putInt(section_64.flags.off, sectFlags);
+
+        data = sectData;
+
+        hasrelocations = hasRelocations;
+    }
+
+    public long getSize() {
+        return section.getLong(section_64.size.off);
+    }
+
+    public int getAlign() {
+        return (1 << section.getInt(section_64.align.off));
+    }
+
+    public byte[] getArray() {
+        return section.array();
+    }
+
+    public byte[] getDataArray() {
+        return data;
+    }
+
+    public void setAddr(long addr) {
+        section.putLong(section_64.addr.off, addr);
+    }
+
+    public long getAddr() {
+        return (section.getLong(section_64.addr.off));
+    }
+
+    public void setOffset(int offset) {
+        section.putInt(section_64.offset.off, offset);
+    }
+
+    public int getOffset() {
+        return (section.getInt(section_64.offset.off));
+    }
+
+    public void setReloff(int offset) {
+        section.putInt(section_64.reloff.off, offset);
+    }
+
+    public void setRelcount(int count) {
+        section.putInt(section_64.nreloc.off, count);
+    }
+
+    public boolean hasRelocations() {
+        return hasrelocations;
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSegment.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.macho.MachO;
+import jdk.tools.jaotc.binformat.macho.MachO.segment_command_64;
+import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
+
+public class MachOSegment {
+    ByteBuffer segment;
+
+    public MachOSegment(int size, int fileoff, int filesize, int nsects) {
+        segment = MachOByteBuffer.allocate(segment_command_64.totalsize);
+
+        segment.putInt(segment_command_64.cmd.off, segment_command_64.LC_SEGMENT_64);
+        segment.putInt(segment_command_64.cmdsize.off, size);
+        segment.putInt(segment_command_64.maxprot.off, 7);
+        segment.putInt(segment_command_64.initprot.off, 7);
+        segment.putInt(segment_command_64.nsects.off, nsects);
+        segment.putInt(segment_command_64.flags.off, 0);
+        segment.putLong(segment_command_64.vmaddr.off, 0);
+        segment.putLong(segment_command_64.vmsize.off, filesize);
+        segment.putLong(segment_command_64.fileoff.off, fileoff);
+        segment.putLong(segment_command_64.filesize.off, filesize);
+    }
+
+    public byte[] getArray() {
+        return segment.array();
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSymbol.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.NativeSymbol;
+import jdk.tools.jaotc.binformat.macho.MachO;
+import jdk.tools.jaotc.binformat.macho.MachO.nlist_64;
+import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
+
+public class MachOSymbol extends NativeSymbol {
+    ByteBuffer sym;
+
+    public MachOSymbol(int symbolindex, int strindex, byte type, byte sectindex, long offset) {
+        super(symbolindex);
+        sym = MachOByteBuffer.allocate(nlist_64.totalsize);
+
+        sym.putInt(nlist_64.n_strx.off, strindex);
+        sym.put(nlist_64.n_type.off, type);
+        // Section indexes start at 1 but we manage the index internally
+        // as 0 relative
+        sym.put(nlist_64.n_sect.off, (byte)(sectindex+1));
+        sym.putChar(nlist_64.n_desc.off, (char )0);
+        sym.putLong(nlist_64.n_value.off, offset);
+    }
+
+    public byte[] getArray() {
+        return sym.array();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSymtab.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+
+import jdk.tools.jaotc.binformat.macho.MachO;
+import jdk.tools.jaotc.binformat.macho.MachO.symtab_command;
+import jdk.tools.jaotc.binformat.macho.MachO.nlist_64;
+import jdk.tools.jaotc.binformat.macho.MachOSymbol;
+import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
+
+public class MachOSymtab {
+
+    /**
+     * ByteBuffer holding the LC_SYMTAB command contents
+     */
+    ByteBuffer symtabCmd;
+
+    /**
+     * ByteBuffer holding the symbol table entries and strings
+     */
+    ByteBuffer symtabData;
+
+    int symtabDataSize;
+
+    ArrayList<MachOSymbol>localSymbols = new ArrayList<MachOSymbol>();
+    ArrayList<MachOSymbol>globalSymbols = new ArrayList<MachOSymbol>();
+    ArrayList<MachOSymbol>undefSymbols = new ArrayList<MachOSymbol>();
+
+    /**
+     * number of symbols added
+     */
+    int symbolCount;
+
+    /**
+     * String holding symbol table strings
+     */
+    private StringBuilder strTabContent = new StringBuilder();
+
+    /**
+     * Keeps track of bytes in string table since strTabContent.length()
+     * is number of chars, not bytes.
+     */
+    private int strTabNrOfBytes = 0;
+
+    public MachOSymtab() {
+        symtabCmd = MachOByteBuffer.allocate(symtab_command.totalsize);
+
+        symtabCmd.putInt(symtab_command.cmd.off, symtab_command.LC_SYMTAB);
+        symtabCmd.putInt(symtab_command.cmdsize.off, symtab_command.totalsize);
+
+        symbolCount = 0;
+
+    }
+
+    public int getAlign() {
+        return (4);
+    }
+
+    public MachOSymbol addSymbolEntry(String name, byte type, byte secHdrIndex, long offset) {
+        // Get the current symbol index and append symbol name to string table.
+        int index;
+        MachOSymbol sym;
+
+        if (name.isEmpty()) {
+            index = 0;
+            strTabContent.append('\0');
+            strTabNrOfBytes += 1;
+            sym = new MachOSymbol(symbolCount, index, type, secHdrIndex, offset);
+            localSymbols.add(sym);
+        } else {
+            // We can't trust strTabContent.length() since that is
+            // chars (UTF16), keep track of bytes on our own.
+            index = strTabNrOfBytes;
+            strTabContent.append("_").append(name).append('\0');
+            // + 1 for null, + 1 for "_"
+            strTabNrOfBytes += (name.getBytes().length + 1 + 1);
+
+            sym = new MachOSymbol(symbolCount, index, type, secHdrIndex, offset);
+            switch (type) {
+                case nlist_64.N_EXT:
+                    undefSymbols.add(sym);
+                    break;
+                case nlist_64.N_SECT:
+                case nlist_64.N_UNDF:  // null symbol
+                    localSymbols.add(sym);
+                    break;
+                case nlist_64.N_SECT|nlist_64.N_EXT:
+                    globalSymbols.add(sym);
+                    break;
+                default:
+                    System.out.println("Unsupported Symbol type " + type);
+                    break;
+            }
+        }
+        symbolCount++;
+        return (sym);
+    }
+
+    public void setOffset(int symoff) {
+        symtabCmd.putInt(symtab_command.symoff.off, symoff);
+    }
+
+    // Update the symbol indexes once all symbols have been added.
+    // This is required since we'll be reordering the symbols in the
+    // file to be in the order of Local, global and Undefined.
+    public void updateIndexes() {
+        int index = 0;
+
+        // Update the local symbol indexes
+        for (int i = 0; i < localSymbols.size(); i++ ) {
+            MachOSymbol sym = localSymbols.get(i);
+            sym.setIndex(index++);
+        }
+
+        // Update the global symbol indexes
+        for (int i = 0; i < globalSymbols.size(); i++ ) {
+            MachOSymbol sym = globalSymbols.get(i);
+            sym.setIndex(index++);
+        }
+
+        // Update the undefined symbol indexes
+        for (int i = index; i < undefSymbols.size(); i++ ) {
+            MachOSymbol sym = undefSymbols.get(i);
+            sym.setIndex(index++);
+        }
+    }
+
+    // Update LC_SYMTAB command fields based on the number of symbols added
+    // return the file size taken up by symbol table entries and strings
+    public int calcSizes() {
+        int stroff;
+
+        stroff = symtabCmd.getInt(symtab_command.symoff.off) + (nlist_64.totalsize * symbolCount);
+        symtabCmd.putInt(symtab_command.nsyms.off, symbolCount);
+        symtabCmd.putInt(symtab_command.stroff.off, stroff);
+        symtabCmd.putInt(symtab_command.strsize.off, strTabNrOfBytes);
+        symtabDataSize = (nlist_64.totalsize * symbolCount) + strTabNrOfBytes;
+
+        return (symtabDataSize);
+    }
+
+    public int getNumLocalSyms()  { return localSymbols.size();  }
+    public int getNumGlobalSyms() { return globalSymbols.size(); }
+    public int getNumUndefSyms()  { return undefSymbols.size();  }
+
+    public byte[] getCmdArray() {
+        return symtabCmd.array();
+    }
+
+    // Create a single byte array that contains the symbol table entries
+    // and string table
+    public byte[] getDataArray() {
+        int index = 0;
+        symtabData = MachOByteBuffer.allocate(symtabDataSize);
+        byte [] retarray;
+
+        // Add the local symbols
+        for (int i = 0; i < localSymbols.size(); i++ ) {
+            MachOSymbol sym = localSymbols.get(i);
+            byte [] arr = sym.getArray();
+            symtabData.put(arr);
+        }
+        // Add the global symbols
+        for (int i = 0; i < globalSymbols.size(); i++ ) {
+            MachOSymbol sym = globalSymbols.get(i);
+            byte [] arr = sym.getArray();
+            symtabData.put(arr);
+        }
+        // Add the undefined symbols
+        for (int i = 0; i < undefSymbols.size(); i++ ) {
+            MachOSymbol sym = undefSymbols.get(i);
+            byte [] arr = sym.getArray();
+            symtabData.put(arr);
+        }
+
+        // Add the stringtable
+        byte [] strs = strTabContent.toString().getBytes();
+        symtabData.put(strs);
+
+        retarray = symtabData.array();
+
+        return (retarray);
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOTargetInfo.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+import java.nio.ByteOrder;
+import jdk.tools.jaotc.binformat.macho.MachO;
+import jdk.tools.jaotc.binformat.macho.MachO.mach_header_64;
+
+/**
+ * Class that abstracts MACH-O target details.
+ *
+ */
+public class MachOTargetInfo {
+    /**
+     * Target architecture and subtype.
+     */
+    private static final int arch;
+    private static final int subarch;
+
+    /**
+     * Architecture endian-ness.
+     */
+    private static final int endian = mach_header_64.CPU_SUBTYPE_LITTLE_ENDIAN;
+
+    /**
+     * Target OS string.
+     */
+    private static final String osName;
+
+    static {
+        // Find the target arch details
+        String archStr = System.getProperty("os.arch").toLowerCase();
+
+        if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) {
+            System.out.println("Only Little Endian byte order supported!");
+        }
+
+        if (archStr.equals("amd64") || archStr.equals("x86_64")) {
+            arch = mach_header_64.CPU_TYPE_X86_64;
+            subarch = mach_header_64.CPU_SUBTYPE_I386_ALL;
+        } else {
+            System.out.println("Unsupported architecture " + archStr);
+            arch = mach_header_64.CPU_TYPE_ANY;
+            subarch = 0;
+        }
+
+        osName = System.getProperty("os.name").toLowerCase();
+    }
+
+    public static int getMachOArch() {
+        return arch;
+    }
+
+    public static int getMachOSubArch() {
+        return subarch;
+    }
+
+    public static int getMachOEndian() {
+        return endian;
+    }
+
+    public static String getOsName() {
+        return osName;
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOVersion.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.macho;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.macho.MachO;
+import jdk.tools.jaotc.binformat.macho.MachO.version_min_command;
+import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
+
+public class MachOVersion {
+    ByteBuffer version;
+
+    public MachOVersion() {
+        version = MachOByteBuffer.allocate(version_min_command.totalsize);
+
+        version.putInt(version_min_command.cmd.off, version_min_command.LC_VERSION_MIN_MACOSX);
+        version.putInt(version_min_command.cmdsize.off, version_min_command.totalsize);
+        version.putInt(version_min_command.version.off, (10 << 16) | (10 << 8)); /* MacOSX 10.10 */
+        version.putInt(version_min_command.sdk.off, 0); /* N/A SDK */
+    }
+
+    public byte[] getArray() {
+        return version.array();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/JPECoffRelocObject.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,422 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.pecoff;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import jdk.tools.jaotc.binformat.Container;
+import jdk.tools.jaotc.binformat.BinaryContainer;
+import jdk.tools.jaotc.binformat.ByteContainer;
+import jdk.tools.jaotc.binformat.CodeContainer;
+import jdk.tools.jaotc.binformat.ReadOnlyDataContainer;
+import jdk.tools.jaotc.binformat.Relocation;
+import jdk.tools.jaotc.binformat.Relocation.RelocType;
+import jdk.tools.jaotc.binformat.Symbol;
+import jdk.tools.jaotc.binformat.NativeSymbol;
+import jdk.tools.jaotc.binformat.Symbol.Binding;
+import jdk.tools.jaotc.binformat.Symbol.Kind;
+
+import jdk.tools.jaotc.binformat.pecoff.PECoff;
+import jdk.tools.jaotc.binformat.pecoff.PECoffSymbol;
+import jdk.tools.jaotc.binformat.pecoff.PECoffTargetInfo;
+import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_FILE_HEADER;
+import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_SECTION_HEADER;
+import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_SYMBOL;
+import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_RELOCATION;
+
+public class JPECoffRelocObject {
+
+    private final BinaryContainer binContainer;
+
+    private final PECoffContainer pecoffContainer;
+
+    private final int segmentSize;
+
+    public JPECoffRelocObject(BinaryContainer binContainer, String outputFileName, String aotVersion) {
+        this.binContainer = binContainer;
+        this.pecoffContainer = new PECoffContainer(outputFileName, aotVersion);
+        this.segmentSize = binContainer.getCodeSegmentSize();
+    }
+
+    private PECoffSection createByteSection(ArrayList<PECoffSection>sections,
+                                         String sectName,
+                                         byte [] scnData,
+                                         boolean hasRelocs,
+                                         int scnFlags) {
+
+        PECoffSection sect = new PECoffSection(sectName,
+                                         scnData,
+                                         scnFlags,
+                                         hasRelocs,
+                                         sections.size());
+        // Add this section to our list
+        sections.add(sect);
+
+        return (sect);
+    }
+
+    private void createByteSection(ArrayList<PECoffSection>sections,
+                                   ByteContainer c, int scnFlags) {
+        PECoffSection sect;
+        boolean hasRelocs = c.hasRelocations();
+        byte[] scnData = c.getByteArray();
+
+        sect = createByteSection(sections, c.getContainerName(),
+                                 scnData, hasRelocs,
+                                 scnFlags);
+
+        c.setSectionId(sect.getSectionId());
+    }
+
+    private void createCodeSection(ArrayList<PECoffSection>sections, CodeContainer c) {
+        createByteSection(sections, c, IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_READ |
+                                       IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_EXECUTE |
+                                       IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_16BYTES |
+                                       IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_CODE);
+    }
+
+    private void createReadOnlySection(ArrayList<PECoffSection>sections, ReadOnlyDataContainer c) {
+        createByteSection(sections, c, IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_READ |
+                                       IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_16BYTES |
+                                       IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_INITIALIZED_DATA);
+    }
+
+    private void createReadWriteSection(ArrayList<PECoffSection>sections, ByteContainer c) {
+        int scnFlags = IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_READ |
+                       IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_WRITE |
+                       IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_8BYTES;
+
+        if (c.getByteArray().length > 0)
+            scnFlags |= IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_INITIALIZED_DATA;
+        else
+            scnFlags |= IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_UNINITIALIZED_DATA;
+
+        createByteSection(sections, c, scnFlags);
+    }
+
+    /**
+     * Create an PECoff relocatable object
+     *
+     * @param relocationTable
+     * @param symbols
+     * @throws IOException throws {@code IOException} as a result of file system access failures.
+     */
+    public void createPECoffRelocObject(Map<Symbol, List<Relocation>> relocationTable, Collection<Symbol> symbols) throws IOException {
+        ArrayList<PECoffSection> sections = new ArrayList<PECoffSection>();
+
+        // Create text section
+        createCodeSection(sections, binContainer.getCodeContainer());
+        createReadOnlySection(sections, binContainer.getMetaspaceNamesContainer());
+        createReadOnlySection(sections, binContainer.getKlassesOffsetsContainer());
+        createReadOnlySection(sections, binContainer.getMethodsOffsetsContainer());
+        createReadOnlySection(sections, binContainer.getKlassesDependenciesContainer());
+        createReadWriteSection(sections, binContainer.getMetaspaceGotContainer());
+        createReadWriteSection(sections, binContainer.getMetadataGotContainer());
+        createReadWriteSection(sections, binContainer.getMethodStateContainer());
+        createReadWriteSection(sections, binContainer.getOopGotContainer());
+        createReadWriteSection(sections, binContainer.getMethodMetadataContainer());
+        createReadOnlySection(sections, binContainer.getStubsOffsetsContainer());
+        createReadOnlySection(sections, binContainer.getHeaderContainer().getContainer());
+        createReadOnlySection(sections, binContainer.getCodeSegmentsContainer());
+        createReadOnlySection(sections, binContainer.getConstantDataContainer());
+        createReadOnlySection(sections, binContainer.getConfigContainer());
+
+        // createExternalLinkage();
+
+        createCodeSection(sections, binContainer.getExtLinkageContainer());
+        createReadWriteSection(sections, binContainer.getExtLinkageGOTContainer());
+
+        // Allocate PECoff Header
+        PECoffHeader header = new PECoffHeader();
+
+        // Get PECoff symbol data from BinaryContainer object's symbol tables
+        PECoffSymtab symtab = createPECoffSymbolTables(sections, symbols);
+
+        // Add Linker Directives Section
+        createByteSection(sections, ".drectve",
+                          symtab.getDirectiveArray(), false,
+                          IMAGE_SECTION_HEADER.IMAGE_SCN_LNK_INFO |
+                          IMAGE_SECTION_HEADER.IMAGE_SCN_LNK_REMOVE |
+                          IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_1BYTES);
+
+        // Create the Relocation Tables
+        PECoffRelocTable pecoffRelocs = createPECoffRelocTable(sections, relocationTable);
+
+        // File Output Order
+        //
+        //   HEADER           (Need address of Symbol Table + symbol count)
+        //   SECTIONS         (Need pointer to Section Data, Relocation Table)
+        //   DIRECTIVES
+        //   SYMBOL TABLE
+        //   SYMBOLS
+        //   SECTION DATA
+        //   RELOCATION TABLE
+
+        // Calculate Offset for Symbol table
+        int file_offset = IMAGE_FILE_HEADER.totalsize +
+                          (IMAGE_SECTION_HEADER.totalsize*sections.size());
+
+        // Update Header fields
+        header.setSectionCount(sections.size());
+        header.setSymbolCount(symtab.getSymtabCount());
+        header.setSymbolOff(file_offset);
+
+        // Calculate file offset for first section
+        file_offset += ((symtab.getSymtabCount() * IMAGE_SYMBOL.totalsize) +
+                        symtab.getStrtabSize());
+        // And round it up
+        file_offset = (file_offset + (sections.get(0).getDataAlign()-1)) &
+                      ~((sections.get(0).getDataAlign()-1));
+
+        // Calc file offsets for section data
+        for (int i = 0; i < sections.size(); i++) {
+            PECoffSection sect = sections.get(i);
+            file_offset = (file_offset + (sect.getDataAlign()-1)) &
+                           ~((sect.getDataAlign()-1));
+            sect.setOffset(file_offset);
+            file_offset += sect.getSize();
+        }
+
+        // Update relocation sizing information in each section
+        for (int i = 0; i < sections.size(); i++) {
+            PECoffSection sect = sections.get(i);
+            if (sect.hasRelocations()) {
+                int nreloc = pecoffRelocs.getNumRelocs(i);
+                sect.setReloff(file_offset);
+                sect.setRelcount(nreloc);
+                // extended relocations add an addition entry
+                if (nreloc > 0xFFFF) nreloc++;
+                file_offset += (nreloc * IMAGE_RELOCATION.totalsize);
+            }
+        }
+
+        // Write out the Header
+        pecoffContainer.writeBytes(header.getArray());
+
+        // Write out the section table
+        for (int i = 0; i < sections.size(); i++) {
+            PECoffSection sect = sections.get(i);
+            pecoffContainer.writeBytes(sect.getArray(), PECoffSection.getShdrAlign());
+        }
+
+        // Write out the symbol table and string table
+        pecoffContainer.writeBytes(symtab.getSymtabArray(), 4);
+        pecoffContainer.writeBytes(symtab.getStrtabArray(), 1);
+
+        // Write out each section contents
+        for (int i = 0; i < sections.size(); i++) {
+            PECoffSection sect = sections.get(i);
+            pecoffContainer.writeBytes(sect.getDataArray(), sect.getDataAlign());
+        }
+
+        // Write out Relocation Tables
+        for (int i = 0; i < sections.size(); i++) {
+            if (pecoffRelocs.getNumRelocs(i) > 0) {
+                pecoffContainer.writeBytes(pecoffRelocs.getRelocData(i));
+            }
+        }
+        pecoffContainer.close();
+    }
+
+    /**
+     * Construct PECoff symbol data from BinaryContainer object's symbol tables. Both dynamic PECoff
+     * symbol table and PECoff symbol table are created from BinaryContainer's symbol info.
+     *
+     * @param symbols
+     */
+    private PECoffSymtab createPECoffSymbolTables(ArrayList<PECoffSection> sections, Collection<Symbol> symbols) {
+        PECoffSymtab symtab = new PECoffSymtab();
+
+        // First, create the initial null symbol. This is a local symbol.
+        // symtab.addSymbolEntry("", (byte)0, (byte)0, (byte)0, 0, 0);
+
+        // Now create PECoff symbol entries for all symbols.
+        for (Symbol symbol : symbols) {
+            // Get the index of section this symbol is defined in.
+            int secHdrIndex = symbol.getSection().getSectionId();
+            PECoffSymbol pecoffSymbol = symtab.addSymbolEntry(symbol.getName(), getPECoffTypeOf(symbol), getPECoffClassOf(symbol), (byte)secHdrIndex, symbol.getOffset(), symbol.getSize());
+            symbol.setNativeSymbol((NativeSymbol)pecoffSymbol);
+        }
+        return (symtab);
+    }
+
+    private static byte getPECoffTypeOf(Symbol sym) {
+        Kind kind = sym.getKind();
+        if (kind == Symbol.Kind.NATIVE_FUNCTION || kind == Symbol.Kind.JAVA_FUNCTION) {
+            return IMAGE_SYMBOL.IMAGE_SYM_DTYPE_FUNCTION;
+        }
+        return IMAGE_SYMBOL.IMAGE_SYM_DTYPE_NONE;
+    }
+
+    private static byte getPECoffClassOf(Symbol sym) {
+        Binding binding = sym.getBinding();
+        if (binding == Symbol.Binding.GLOBAL) {
+            return IMAGE_SYMBOL.IMAGE_SYM_CLASS_EXTERNAL;
+        }
+        return IMAGE_SYMBOL.IMAGE_SYM_CLASS_STATIC;
+    }
+
+    /**
+     * Construct a PECoff relocation table from BinaryContainer object's relocation tables.
+     *
+     * @param sections
+     * @param relocationTable
+     */
+    private PECoffRelocTable createPECoffRelocTable(ArrayList<PECoffSection> sections,
+                                              Map<Symbol, List<Relocation>> relocationTable) {
+
+        PECoffRelocTable pecoffRelocTable = new PECoffRelocTable(sections.size());
+        /*
+         * For each of the symbols with associated relocation records, create a PECoff relocation
+         * entry.
+         */
+        for (Map.Entry<Symbol, List<Relocation>> entry : relocationTable.entrySet()) {
+            List<Relocation> relocs = entry.getValue();
+            Symbol symbol = entry.getKey();
+
+            for (Relocation reloc : relocs) {
+                createRelocation(symbol, reloc, pecoffRelocTable);
+            }
+        }
+
+        for (Map.Entry<Symbol, Relocation> entry : binContainer.getUniqueRelocationTable().entrySet()) {
+            createRelocation(entry.getKey(), entry.getValue(), pecoffRelocTable);
+        }
+
+        return (pecoffRelocTable);
+    }
+
+    private void createRelocation(Symbol symbol, Relocation reloc, PECoffRelocTable pecoffRelocTable) {
+        RelocType relocType = reloc.getType();
+
+        int pecoffRelocType = getPECoffRelocationType(relocType);
+        PECoffSymbol sym = (PECoffSymbol)symbol.getNativeSymbol();
+        int symno = sym.getIndex();
+        int sectindex = reloc.getSection().getSectionId();
+        int offset = reloc.getOffset();
+        int addend = 0;
+
+        switch (relocType) {
+            case FOREIGN_CALL_DIRECT:
+            case JAVA_CALL_DIRECT:
+            case STUB_CALL_DIRECT:
+            case FOREIGN_CALL_INDIRECT_GOT: {
+                // Create relocation entry
+                addend = -4; // Size in bytes of the patch location
+                // Relocation should be applied at the location after call operand
+                offset = offset + reloc.getSize() + addend;
+                break;
+            }
+            case FOREIGN_CALL_DIRECT_FAR: {
+                // Create relocation entry
+                addend = -8; // Size in bytes of the patch location
+                // Relocation should be applied at the location after call operand
+                // 10 = 2 (jmp [r]) + 8 (imm64)
+                offset = offset + reloc.getSize() + addend - 2;
+                break;
+            }
+            case FOREIGN_CALL_INDIRECT:
+            case JAVA_CALL_INDIRECT:
+            case STUB_CALL_INDIRECT: {
+                // Do nothing.
+                return;
+            }
+            case EXTERNAL_DATA_REFERENCE_FAR: {
+                // Create relocation entry
+                addend = -4; // Size of 32-bit address of the GOT
+                /*
+                 * Relocation should be applied before the test instruction to the move instruction.
+                 * offset points to the test instruction after the instruction that loads
+                 * the address of polling page. So set the offset appropriately.
+                 */
+                offset = offset + addend;
+                break;
+            }
+            case METASPACE_GOT_REFERENCE:
+            case EXTERNAL_PLT_TO_GOT:
+            case STATIC_STUB_TO_STATIC_METHOD:
+            case STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT: {
+                addend = -4; // Size of 32-bit address of the GOT
+                /*
+                 * Relocation should be applied before the test instruction to
+                 * the move instruction. reloc.getOffset() points to the
+                 * test instruction after the instruction that loads the
+                 * address of polling page. So set the offset appropriately.
+                 */
+                offset = offset + addend;
+                break;
+            }
+            case EXTERNAL_GOT_TO_PLT:
+            case LOADTIME_ADDRESS: {
+                // this is load time relocations
+                break;
+            }
+            default:
+                throw new InternalError("Unhandled relocation type: " + relocType);
+        }
+        pecoffRelocTable.createRelocationEntry(sectindex, offset, symno, pecoffRelocType);
+    }
+
+    // Return IMAGE_RELOCATION Type based on relocType
+    private static int getPECoffRelocationType(RelocType relocType) {
+        int pecoffRelocType = 0; // R_<ARCH>_NONE if #define'd to 0 for all values of ARCH
+        switch (PECoffTargetInfo.getPECoffArch()) {
+            case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64:
+                if (relocType == RelocType.FOREIGN_CALL_DIRECT ||
+                    relocType == RelocType.JAVA_CALL_DIRECT ||
+                    relocType == RelocType.FOREIGN_CALL_INDIRECT_GOT) {
+                    pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_REL32;
+                } else if (relocType == RelocType.STUB_CALL_DIRECT) {
+                    pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_REL32;
+                } else if (relocType == RelocType.FOREIGN_CALL_DIRECT_FAR) {
+                    pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_ADDR64;
+                } else if (relocType == RelocType.FOREIGN_CALL_INDIRECT ||
+                           relocType == RelocType.JAVA_CALL_INDIRECT ||
+                           relocType == RelocType.STUB_CALL_INDIRECT) {
+                    pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_ABSOLUTE;
+                } else if ((relocType == RelocType.EXTERNAL_DATA_REFERENCE_FAR)) {
+                    pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_REL32;
+                } else if (relocType == RelocType.METASPACE_GOT_REFERENCE ||
+                           relocType == RelocType.EXTERNAL_PLT_TO_GOT ||
+                           relocType == RelocType.STATIC_STUB_TO_STATIC_METHOD ||
+                           relocType == RelocType.STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT) {
+                    pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_REL32;
+                } else if (relocType == RelocType.EXTERNAL_GOT_TO_PLT ||
+                           relocType == RelocType.LOADTIME_ADDRESS) {
+                    pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_ADDR64;
+                } else {
+                    assert false : "Unhandled relocation type: " + relocType;
+                }
+                break;
+            default:
+                System.out.println("Relocation Type mapping: Unhandled architecture");
+        }
+        return pecoffRelocType;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoff.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.pecoff;
+
+/**
+ *
+ * Support for the creation of Coff files.
+ * Current support is limited to 64 bit x86_64.
+ *
+ */
+
+public class PECoff {
+
+    /**
+     * IMAGE_FILE_HEADER structure defines
+     */
+    public enum IMAGE_FILE_HEADER {
+                     Machine( 0, 2),
+            NumberOfSections( 2, 2),
+               TimeDateStamp( 4, 4),
+        PointerToSymbolTable( 8, 4),
+             NumberOfSymbols(12, 4),
+        SizeOfOptionalHeader(16, 2),
+             Characteristics(18, 2);
+
+        public final int off;
+        public final int sz;
+
+        IMAGE_FILE_HEADER(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 20;
+
+        /**
+         * IMAGE_FILE_HEADER defines
+         */
+
+        /**
+         * Machine
+         */
+        public static final char IMAGE_FILE_MACHINE_UNKNOWN = 0x0;
+        public static final char IMAGE_FILE_MACHINE_AMD64   = 0x8664;
+
+    }
+
+    /**
+     * IMAGE_SECTION_HEADER structure defines
+     */
+    public enum IMAGE_SECTION_HEADER {
+                        Name( 0, 8),
+             PhysicalAddress( 8, 4),
+                 VirtualSize( 8, 4),
+              VirtualAddress(12, 4),
+               SizeOfRawData(16, 4),
+            PointerToRawData(20, 4),
+        PointerToRelocations(24, 4),
+        PointerToLinenumbers(28, 4),
+         NumberOfRelocations(32, 2),
+         NumberOfLinenumbers(34, 2),
+             Characteristics(36, 4);
+
+        public final int off;
+        public final int sz;
+
+        IMAGE_SECTION_HEADER(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 40;
+
+        /**
+         * IMAGE_SECTION_HEADER defines
+         */
+
+        /**
+         * Characteristics
+         */
+        public static final int IMAGE_SCN_CNT_CODE               = 0x20;
+        public static final int IMAGE_SCN_CNT_INITIALIZED_DATA   = 0x40;
+        public static final int IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x80;
+        public static final int IMAGE_SCN_LNK_COMDAT             = 0x1000;
+        public static final int IMAGE_SCN_LNK_INFO               = 0x200;
+        public static final int IMAGE_SCN_LNK_REMOVE             = 0x800;
+
+        public static final int IMAGE_SCN_ALIGN_1BYTES           = 0x100000;
+        public static final int IMAGE_SCN_ALIGN_2BYTES           = 0x200000;
+        public static final int IMAGE_SCN_ALIGN_4BYTES           = 0x300000;
+        public static final int IMAGE_SCN_ALIGN_8BYTES           = 0x400000;
+        public static final int IMAGE_SCN_ALIGN_16BYTES          = 0x500000;
+        public static final int IMAGE_SCN_ALIGN_MASK             = 0xf00000;
+        public static final int IMAGE_SCN_ALIGN_SHIFT            = 20;
+
+        public static final int IMAGE_SCN_LNK_NRELOC_OVFL        = 0x01000000;
+
+        public static final int IMAGE_SCN_MEM_SHARED             = 0x10000000;
+        public static final int IMAGE_SCN_MEM_EXECUTE            = 0x20000000;
+        public static final int IMAGE_SCN_MEM_READ               = 0x40000000;
+        public static final int IMAGE_SCN_MEM_WRITE              = 0x80000000;
+
+    }
+
+    /**
+     * Symbol table entry definitions
+     *
+     * IMAGE_SYMBOL structure defines
+     */
+    public enum IMAGE_SYMBOL {
+                   ShortName( 0, 8),
+                       Short( 0, 4),
+                        Long( 4, 4),
+                       Value( 8, 4),
+               SectionNumber(12, 2),
+                        Type(14, 2),
+                StorageClass(16, 1),
+          NumberOfAuxSymbols(17, 1);
+
+        public final int off;
+        public final int sz;
+
+        IMAGE_SYMBOL(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 18;
+
+        /**
+         * Type
+         */
+        public static final int IMAGE_SYM_DTYPE_NONE     = 0x0;
+        public static final int IMAGE_SYM_DTYPE_FUNCTION = 0x20;
+
+        /**
+         * StorageClass
+         */
+        public static final int IMAGE_SYM_CLASS_NULL     = 0x0;
+        public static final int IMAGE_SYM_CLASS_EXTERNAL = 0x2;
+        public static final int IMAGE_SYM_CLASS_STATIC   = 0x3;
+        public static final int IMAGE_SYM_CLASS_LABEL    = 0x6;
+
+    }
+
+    /**
+     * IMAGE_RELOCATION structure defines
+     */
+    public enum IMAGE_RELOCATION {
+              VirtualAddress( 0, 4),
+            SymbolTableIndex( 4, 4),
+                        Type( 8, 2);
+
+        public final int off;
+        public final int sz;
+
+        IMAGE_RELOCATION(int offset, int size) {
+            this.off = offset;
+            this.sz = size;
+        }
+
+        public static int totalsize = 10;
+
+        /**
+         * Relocation types
+         */
+        public static final int IMAGE_REL_AMD64_ABSOLUTE = 0x0;
+        public static final int IMAGE_REL_AMD64_ADDR32   = 0x2;
+        public static final int IMAGE_REL_AMD64_ADDR64   = 0x1;
+        public static final int IMAGE_REL_AMD64_REL32    = 0x4;
+        public static final int IMAGE_REL_AMD64_REL32_1  = 0x5;
+        public static final int IMAGE_REL_AMD64_REL32_2  = 0x6;
+        public static final int IMAGE_REL_AMD64_REL32_3  = 0x7;
+        public static final int IMAGE_REL_AMD64_REL32_4  = 0x8;
+        public static final int IMAGE_REL_AMD64_REL32_5  = 0x9;
+
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffByteBuffer.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.pecoff;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+public class PECoffByteBuffer {
+
+    public static ByteBuffer allocate(int size) {
+        ByteBuffer buf = ByteBuffer.allocate(size);
+        // Only support Little Endian on Windows
+        buf.order(ByteOrder.LITTLE_ENDIAN);
+        return (buf);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffContainer.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.pecoff;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+public class PECoffContainer {
+
+    File outputFile;
+    FileOutputStream outputStream;
+    long fileOffset;
+
+    public PECoffContainer(String fileName, String aotVersion) {
+        String baseName;
+
+        outputFile = new File(fileName);
+        if (outputFile.exists()) {
+            outputFile.delete();
+        }
+
+        try {
+            outputStream = new FileOutputStream(outputFile);
+        } catch (Exception e) {
+            System.out.println("PECoffContainer: Can't create file " + fileName);
+        }
+        fileOffset = 0;
+    }
+
+    public void close() {
+        try {
+            outputStream.close();
+        } catch (Exception e) {
+            System.out.println("PECoffContainer: close failed");
+        }
+    }
+
+    public void writeBytes(byte [] bytes) {
+        if (bytes == null) return;
+        try {
+            outputStream.write(bytes);
+        } catch (Exception e) {
+            System.out.println("PECoffContainer: writeBytes failed");
+        }
+        fileOffset += bytes.length;
+    }
+
+    // Write bytes to output file with up front alignment padding
+    public void writeBytes(byte [] bytes, int alignment) {
+        if (bytes == null) return;
+        try {
+            // Pad to alignment
+            while ((fileOffset & (long)(alignment-1)) != 0) {
+                outputStream.write(0);
+                fileOffset++;
+            }
+            outputStream.write(bytes);
+        } catch (Exception e) {
+            System.out.println("PECoffContainer: writeBytes failed");
+        }
+        fileOffset += bytes.length;
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffHeader.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.pecoff;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.pecoff.PECoff;
+import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_FILE_HEADER;
+import jdk.tools.jaotc.binformat.pecoff.PECoffTargetInfo;
+import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
+
+public class PECoffHeader {
+    ByteBuffer header;
+
+    public PECoffHeader() {
+        header = PECoffByteBuffer.allocate(IMAGE_FILE_HEADER.totalsize);
+
+        header.putChar(IMAGE_FILE_HEADER.Machine.off, IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64);
+        header.putInt(IMAGE_FILE_HEADER.TimeDateStamp.off, (int)(System.currentTimeMillis()/1000));
+        header.putInt(IMAGE_FILE_HEADER.PointerToSymbolTable.off, 0);
+        header.putInt(IMAGE_FILE_HEADER.NumberOfSymbols.off, 0);
+        header.putChar(IMAGE_FILE_HEADER.SizeOfOptionalHeader.off, (char)0);
+        header.putChar(IMAGE_FILE_HEADER.Characteristics.off, (char)0);
+
+    }
+
+    // Update header with the number of total sections
+    public void setSectionCount(int count) {
+        header.putChar(IMAGE_FILE_HEADER.NumberOfSections.off, (char)count);
+    }
+
+    // Update header with the number of total symbols
+    public void setSymbolCount(int count) {
+        header.putInt(IMAGE_FILE_HEADER.NumberOfSymbols.off, count);
+    }
+
+    // Update header with the offset of symbol table
+    public void setSymbolOff(int offset) {
+        header.putInt(IMAGE_FILE_HEADER.PointerToSymbolTable.off, offset);
+    }
+
+    public byte[] getArray() {
+        return header.array();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffRelocEntry.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.pecoff;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.pecoff.PECoff;
+import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_RELOCATION;
+import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
+
+public class PECoffRelocEntry {
+    ByteBuffer entry;
+
+    public PECoffRelocEntry(int offset, int symno, int type) {
+
+        entry = PECoffByteBuffer.allocate(IMAGE_RELOCATION.totalsize);
+
+        entry.putInt(IMAGE_RELOCATION.VirtualAddress.off, offset);
+        entry.putInt(IMAGE_RELOCATION.SymbolTableIndex.off, symno);
+        entry.putChar(IMAGE_RELOCATION.Type.off, (char)type);
+    }
+
+    public byte[] getArray() {
+        return entry.array();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffRelocTable.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.pecoff;
+
+import java.util.ArrayList;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.pecoff.PECoff;
+import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_RELOCATION;
+import jdk.tools.jaotc.binformat.pecoff.PECoffRelocEntry;
+import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
+
+public class PECoffRelocTable {
+    ArrayList<ArrayList<PECoffRelocEntry>> relocEntries;
+
+    public PECoffRelocTable(int numsects) {
+        relocEntries = new ArrayList<ArrayList<PECoffRelocEntry>>(numsects);
+        for (int i = 0; i < numsects; i++)
+            relocEntries.add(new ArrayList<PECoffRelocEntry>());
+    }
+
+    public void createRelocationEntry(int sectindex,
+                                      int offset,
+                                      int symno,
+                                      int type) {
+
+        PECoffRelocEntry entry = new PECoffRelocEntry(offset,
+                                                symno,
+                                                type);
+        relocEntries.get(sectindex).add(entry);
+    }
+
+    public int getAlign() { return (4); }
+
+    public int getNumRelocs(int section_index) {
+        return relocEntries.get(section_index).size();
+    }
+
+    // Return the relocation entries for a single section
+    //   or null if no entries added to section
+    public byte [] getRelocData(int section_index) {
+        ArrayList<PECoffRelocEntry> entryList = relocEntries.get(section_index);
+        int entryCount = entryList.size();
+        int allocCount = entryCount;
+
+        if (entryCount == 0)
+            return null;
+
+        if (entryCount > 0xFFFF)
+            allocCount++;
+
+        ByteBuffer relocData = PECoffByteBuffer.allocate(allocCount * IMAGE_RELOCATION.totalsize);
+
+        // If number of relocs exceeds 65K, add the real size
+        // in a dummy first reloc entry
+        if (entryCount > 0xFFFF) {
+            PECoffRelocEntry entry = new PECoffRelocEntry(allocCount, 0, 0);
+            relocData.put(entry.getArray());
+        }
+
+        // Copy each entry to a single ByteBuffer
+        for (int i = 0; i < entryCount; i++) {
+            PECoffRelocEntry entry = entryList.get(i);
+            relocData.put(entry.getArray());
+        }
+
+        return (relocData.array());
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffSection.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.pecoff;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.pecoff.PECoff;
+import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_SECTION_HEADER;
+import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
+
+public class PECoffSection {
+    ByteBuffer section;
+    byte [] data;
+    boolean hasrelocations;
+    int sectionIndex;
+    int align;
+
+    public PECoffSection(String sectName, byte [] sectData, int sectFlags,
+                         boolean hasRelocations, int sectIndex) {
+
+        section = PECoffByteBuffer.allocate(IMAGE_SECTION_HEADER.totalsize);
+
+        // bug: If JVM.oop.got section is empty, VM exits since JVM.oop.got
+        //      symbol ends up as external forwarded reference.
+        if (sectData.length == 0) sectData = new byte[8];
+
+        // Copy only Max allowed bytes to Section Entry
+        byte [] Name = sectName.getBytes();
+        int max = Name.length <= IMAGE_SECTION_HEADER.Name.sz ?
+                  Name.length : IMAGE_SECTION_HEADER.Name.sz;
+
+        section.put(Name, IMAGE_SECTION_HEADER.Name.off, max);
+
+        section.putInt(IMAGE_SECTION_HEADER.VirtualSize.off, 0);
+        section.putInt(IMAGE_SECTION_HEADER.VirtualAddress.off, 0);
+        section.putInt(IMAGE_SECTION_HEADER.SizeOfRawData.off, sectData.length);
+        section.putInt(IMAGE_SECTION_HEADER.PointerToLinenumbers.off, 0);
+        section.putChar(IMAGE_SECTION_HEADER.NumberOfLinenumbers.off, (char)0);
+
+        section.putInt(IMAGE_SECTION_HEADER.Characteristics.off, sectFlags);
+
+        // Extract alignment from Characteristics field
+        int alignshift = (sectFlags & IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_MASK) >>
+                                       IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_SHIFT;
+
+        // Use 8 byte alignment if not specified
+        if (alignshift == 0)
+            alignshift = 3;
+        else
+            --alignshift;
+
+        align = 1 << alignshift;
+
+        data = sectData;
+        hasrelocations = hasRelocations;
+        sectionIndex = sectIndex;
+    }
+
+    public long getSize() {
+        return section.getInt(IMAGE_SECTION_HEADER.SizeOfRawData.off);
+    }
+
+    public int getDataAlign() {
+        return (align);
+    }
+
+    // Alignment requirements for the IMAGE_SECTION_HEADER structures
+    public static int getShdrAlign() {
+        return (4);
+    }
+
+    public byte[] getArray() {
+        return section.array();
+    }
+
+    public byte[] getDataArray() {
+        return data;
+    }
+
+    public void setOffset(long offset) {
+        section.putInt(IMAGE_SECTION_HEADER.PointerToRawData.off, (int)offset);
+    }
+
+    public long getOffset() {
+        return (section.getInt(IMAGE_SECTION_HEADER.PointerToRawData.off));
+    }
+
+    public void setReloff(int offset) {
+        section.putInt(IMAGE_SECTION_HEADER.PointerToRelocations.off, offset);
+    }
+
+    public void setRelcount(int count) {
+        // If the number of relocs is larger than 65K, then set
+        // the overflow bit.  The real count will be written to
+        // the first reloc entry for this section.
+        if (count > 0xFFFF) {
+            int flags;
+            section.putChar(IMAGE_SECTION_HEADER.NumberOfRelocations.off, (char)0xFFFF);
+            flags = section.getInt(IMAGE_SECTION_HEADER.Characteristics.off);
+            flags |= IMAGE_SECTION_HEADER.IMAGE_SCN_LNK_NRELOC_OVFL;
+            section.putInt(IMAGE_SECTION_HEADER.Characteristics.off, flags);
+        }
+        else {
+            section.putChar(IMAGE_SECTION_HEADER.NumberOfRelocations.off, (char)count);
+        }
+    }
+
+    public boolean hasRelocations() {
+        return hasrelocations;
+    }
+
+    public int getSectionId() {
+        return sectionIndex;
+    }
+
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffSymbol.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.pecoff;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import jdk.tools.jaotc.binformat.NativeSymbol;
+import jdk.tools.jaotc.binformat.pecoff.PECoff;
+import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_SYMBOL;
+import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
+
+public class PECoffSymbol extends NativeSymbol {
+    ByteBuffer sym;
+
+    public PECoffSymbol(int symbolindex, int strindex, byte type, byte storageclass,
+                        byte sectindex, long offset, long size) {
+        super(symbolindex);
+        sym = PECoffByteBuffer.allocate(IMAGE_SYMBOL.totalsize);
+
+        // We don't use short names
+        sym.putInt(IMAGE_SYMBOL.Short.off, 0);
+
+        sym.putInt(IMAGE_SYMBOL.Long.off, strindex);
+        sym.putInt(IMAGE_SYMBOL.Value.off, (int)offset);
+
+        // Section indexes start at 1 but we manage the index internally
+        // as 0 relative except in this structure
+        sym.putChar(IMAGE_SYMBOL.SectionNumber.off, (char)(sectindex+1));
+
+        sym.putChar(IMAGE_SYMBOL.Type.off, (char)type);
+        sym.put(IMAGE_SYMBOL.StorageClass.off, storageclass);
+        sym.put(IMAGE_SYMBOL.NumberOfAuxSymbols.off, (byte)0);
+    }
+
+    public byte[] getArray() {
+        return sym.array();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffSymtab.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.pecoff;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+
+import jdk.tools.jaotc.binformat.pecoff.PECoff;
+import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_SYMBOL;
+import jdk.tools.jaotc.binformat.pecoff.PECoffSymbol;
+import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
+
+public class PECoffSymtab {
+    ArrayList<PECoffSymbol>symbols = new ArrayList<PECoffSymbol>();
+
+    /**
+     * number of symbols added
+     */
+    int symbolCount;
+
+    /**
+     * String holding symbol table strings
+     */
+    private StringBuilder strTabContent;
+
+    /**
+     * Keeps track of bytes in string table since strTabContent.length()
+     * is number of chars, not bytes.
+     */
+    private int strTabNrOfBytes;
+
+    /**
+     * String holding Linker Directives
+     */
+    private StringBuilder directives;
+
+    public PECoffSymtab() {
+        symbolCount = 0;
+        strTabContent = new StringBuilder();
+        directives = new StringBuilder();
+
+        // The first 4 bytes of the string table contain
+        // the length of the table (including this length field).
+        strTabNrOfBytes = 4;
+
+        // Make room for the 4 byte length field
+        strTabContent.append('\0').append('\0').append('\0').append('\0');
+
+        // Linker Directives start with 3 spaces to signify ANSI
+        directives.append("   ");
+    }
+
+    public PECoffSymbol addSymbolEntry(String name, byte type, byte storageclass,
+                                    byte secHdrIndex, long offset, long size) {
+        // Get the current symbol index and append symbol name to string table.
+        int index;
+        PECoffSymbol sym;
+
+        if (name.isEmpty()) {
+            index = 0;
+            strTabContent.append('\0');
+            strTabNrOfBytes += 1;
+            sym = new PECoffSymbol(symbolCount, index, type, storageclass, secHdrIndex, offset, size);
+            symbols.add(sym);
+        } else {
+            int nameSize = name.getBytes().length;
+
+            // We can't trust strTabContent.length() since that is
+            // chars (UTF16), keep track of bytes on our own.
+            index = strTabNrOfBytes;
+            // strTabContent.append('_').append(name).append('\0');
+            strTabContent.append(name).append('\0');
+            strTabNrOfBytes += (nameSize + 1);
+
+            sym = new PECoffSymbol(symbolCount, index, type, storageclass, secHdrIndex, offset, size);
+            symbols.add(sym);
+            if (storageclass == IMAGE_SYMBOL.IMAGE_SYM_CLASS_EXTERNAL)
+                addDirective(name, type);
+        }
+        symbolCount++;
+        return (sym);
+    }
+
+    private void addDirective(String name, byte type) {
+        directives.append("/EXPORT:" + name);
+        if(type != IMAGE_SYMBOL.IMAGE_SYM_DTYPE_FUNCTION) {
+            directives.append(",DATA");
+        }
+        directives.append(" ");
+    }
+
+    public int getSymtabCount() {
+        return symbolCount;
+    }
+
+    public int getStrtabSize() {
+        return strTabNrOfBytes;
+    }
+
+    // Return a byte array that contains the symbol table entries
+    public byte[] getSymtabArray() {
+        ByteBuffer symtabData = PECoffByteBuffer.allocate(symbolCount*IMAGE_SYMBOL.totalsize);
+        symtabData.order(ByteOrder.LITTLE_ENDIAN);
+
+        // copy all symbols
+        for (int i = 0; i < symbolCount; i++ ) {
+            PECoffSymbol sym = symbols.get(i);
+            byte [] arr = sym.getArray();
+            symtabData.put(arr);
+        }
+        return (symtabData.array());
+    }
+
+    // Return the string table array
+    public byte[] getStrtabArray() {
+        byte [] strs = strTabContent.toString().getBytes();
+
+        // Update the size of the string table
+        ByteBuffer buff = ByteBuffer.wrap(strs);
+        buff.order(ByteOrder.LITTLE_ENDIAN);
+        buff.putInt(0, strTabNrOfBytes);
+
+        return (strs);
+    }
+
+    public byte[] getDirectiveArray() {
+        return (directives.toString().getBytes());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffTargetInfo.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.tools.jaotc.binformat.pecoff;
+
+import java.nio.ByteOrder;
+import jdk.tools.jaotc.binformat.pecoff.PECoff;
+import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_FILE_HEADER;
+
+/**
+ * Class that abstracts MACH-O target details.
+ *
+ */
+public class PECoffTargetInfo {
+    /**
+     * Target architecture.
+     */
+    private static final char arch;
+
+    /**
+     * Target OS string.
+     */
+    private static String osName;
+
+    static {
+        // Find the target arch details
+        String archStr = System.getProperty("os.arch").toLowerCase();
+        if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) {
+            System.out.println("Only Little Endian byte order supported!");
+        }
+
+        if (archStr.equals("amd64") || archStr.equals("x86_64")) {
+            arch = IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64;
+        } else {
+            System.out.println("Unsupported architecture " + archStr);
+            arch = IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_UNKNOWN;
+        }
+
+        osName = System.getProperty("os.name").toLowerCase();
+        if (!osName.contains("windows")) {
+            System.out.println("Unsupported Operating System " + osName);
+            osName = "Unknown";
+        }
+    }
+
+    public static char getPECoffArch() {
+        return arch;
+    }
+
+    public static String getOsName() {
+        return osName;
+    }
+}
+
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.jnilibelf/src/jdk/tools/jaotc/jnilibelf/ELFContainer.java	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/*
- * 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.
- */
-
-package jdk.tools.jaotc.jnilibelf;
-
-public interface ELFContainer {
-
-    String getContainerName();
-
-    int getSectionId();
-
-}
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.jnilibelf/src/jdk/tools/jaotc/jnilibelf/ELFSymbol.java	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/*
- * 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.
- */
-
-package jdk.tools.jaotc.jnilibelf;
-
-/**
- * This class represents a {@code Elf32_Sym} or {@code Elf64_Sym} as defined in {@code elf.h}.
- */
-public class ELFSymbol {
-    /** Symbol name. */
-    private final String name;
-
-    /** String table index. */
-    private final int index;
-
-    /** Native memory address of ELF sym entry. */
-    private final Pointer address;
-    private final boolean isLocal;
-
-    public ELFSymbol(String name, int index, Pointer address, boolean isLocal) {
-        this.name = name;
-        this.index = index;
-        this.address = address;
-        this.isLocal = isLocal;
-    }
-
-    /**
-     * @return the name
-     */
-    public String getName() {
-        return name;
-    }
-
-    /**
-     * @return the index
-     */
-    public int getIndex() {
-        return index;
-    }
-
-    /**
-     * @return the address
-     */
-    public Pointer getAddress() {
-        return address;
-    }
-
-    @Override
-    public String toString() {
-        return "name=" + name + ", index=" + index + ", address=" + address;
-    }
-
-    public boolean isLocal() {
-        return isLocal;
-    }
-}
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.jnilibelf/src/jdk/tools/jaotc/jnilibelf/JNIELFContainer.java	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,476 +0,0 @@
-/*
- * 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.
- */
-
-package jdk.tools.jaotc.jnilibelf;
-
-import static jdk.tools.jaotc.jnilibelf.UnsafeAccess.UNSAFE;
-
-import java.io.File;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import jdk.tools.jaotc.jnilibelf.JNILibELFAPI.ELF;
-import jdk.tools.jaotc.jnilibelf.JNILibELFAPI.LibELF;
-import jdk.tools.jaotc.jnilibelf.JNILibELFAPI.LibELF.Elf_Type;
-
-/**
- * A class abstraction of an ELF file.
- *
- */
-public class JNIELFContainer {
-
-    private String outputFileName;
-    private File outFile;
-    private int outFileDesc;
-
-    /**
-     * Pointer to Elf file. This is the same as struct Elf found in libelf.h
-     */
-    private Pointer elfPtr;
-
-    /**
-     * Class of the ELF container - one of ELFCLASS32 or ELFCLASS64.
-     */
-    private final int elfClass;
-
-    /**
-     * Pointer to ELF Header.
-     */
-    private Pointer ehdrPtr;
-
-    /**
-     * Pointer to Program Header.
-     */
-    private Pointer phdrPtr;
-
-    /**
-     * String holding .shstrtab contents.
-     */
-    private String shStrTabContent = "";
-
-    /**
-     * Map of local symbol indexes to ELF symbol entries.
-     */
-    private List<ELFSymbol> localSymbolIndex = new ArrayList<>();
-
-    /**
-     * Map of global symbol indexes to ELF symbol entries.
-     */
-    private List<ELFSymbol> globalSymbolIndex = new ArrayList<>();
-
-    /**
-     * String holding .strtab contents.
-     */
-    private StringBuilder strTabContent = new StringBuilder();
-
-    /**
-     * Keeps track of nr of bytes in .strtab since strTabContent.length() is number of chars, not
-     * bytes.
-     */
-    private int strTabNrOfBytes = 0;
-
-    /**
-     * A hashtable that holds (section-name, relocation-table) pairs. For example, [(".rela.text",
-     * rela-text-reloc-entries), (".rela.plt", rela-plt-reloc-entries), ...].
-     */
-    private Map<ELFContainer, ArrayList<Pointer>> relocTables = new HashMap<>();
-
-    /**
-     * Create reloca; 0 => false and non-zero => true.
-     */
-    private final int createReloca;
-
-    /**
-     * Construct an ELFContainer in preparation for a disk image with file {@code prefix}.
-     *
-     * @param fileName name of ELF file to be created
-     */
-    public JNIELFContainer(String fileName, String aotVersion) {
-        // Check for version compatibility
-        if (!JNILibELFAPI.elfshim_version().equals(aotVersion)) {
-            throw new InternalError("libelfshim version mismatch: " + JNILibELFAPI.elfshim_version() + " vs " + aotVersion);
-        }
-
-        elfClass = JNIELFTargetInfo.getELFClass();
-        createReloca = JNIELFTargetInfo.createReloca();
-        outputFileName = fileName;
-    }
-
-    /**
-     * Get the local ELF symbol table.
-     *
-     * @return local symbol table
-     */
-    public List<ELFSymbol> getLocalSymbols() {
-        return localSymbolIndex;
-    }
-
-    /**
-     * Get the global ELF symbol table.
-     *
-     * @return list of global ELF symbol table entries
-     */
-    public List<ELFSymbol> getGlobalSymbols() {
-        return globalSymbolIndex;
-    }
-
-    /**
-     * Get string table content (.strtab).
-     *
-     * @return string table content
-     */
-    public String getStrTabContent() {
-        return strTabContent.toString();
-    }
-
-    /**
-     * Get section header string table content (.shstrtab).
-     *
-     * @return section header string table content
-     */
-    public String getShStrTabContent() {
-        return shStrTabContent;
-    }
-
-    /**
-     * Get relocation tables.
-     *
-     * @return relocation tables
-     */
-    public Map<ELFContainer, ArrayList<Pointer>> getRelocTables() {
-        return relocTables;
-    }
-
-    /**
-     * Get the index of first non-local symbol in symbol table.
-     *
-     * @return symbol table index
-     */
-    public int getFirstNonLocalSymbolIndex() {
-        return localSymbolIndex.size();
-    }
-
-    /**
-     * Create ELF header of type {@code ececType}.
-     *
-     * @param type type of ELF executable
-     */
-    public void createELFHeader(int type) {
-        // Check for version compatibility
-        if (JNILibELFAPI.elf_version(ELF.EV_CURRENT) == ELF.EV_NONE) {
-            throw new InternalError("ELF version mismatch");
-        }
-
-        outFile = constructRelocFile(outputFileName);
-        // Open a temporary file for the shared library to be created
-        // TODO: Revisit file permissions; need to add execute permission
-        outFileDesc = JNILibELFAPI.open_rw(outFile.getPath());
-
-        if (outFileDesc == -1) {
-            System.out.println("Failed to open file " + outFile.getPath() + " to write relocatable object.");
-        }
-
-        elfPtr = JNILibELFAPI.elf_begin(outFileDesc, LibELF.Elf_Cmd.ELF_C_WRITE.intValue(), new Pointer(0L));
-        if (elfPtr == null) {
-            throw new InternalError("elf_begin failed");
-        }
-
-        // Allocate new Ehdr of current architecture class
-
-        ehdrPtr = JNILibELFAPI.gelf_newehdr(elfPtr, elfClass);
-
-        JNILibELFAPI.ehdr_set_data_encoding(ehdrPtr, JNIELFTargetInfo.getELFEndian());
-        JNILibELFAPI.set_Ehdr_e_machine(elfClass, ehdrPtr, JNIELFTargetInfo.getELFArch());
-        JNILibELFAPI.set_Ehdr_e_type(elfClass, ehdrPtr, type);
-        JNILibELFAPI.set_Ehdr_e_version(elfClass, ehdrPtr, ELF.EV_CURRENT);
-    }
-
-    /**
-     * If the file name has a .so extension, replace it with .o extension. Else just add .o
-     * extension
-     *
-     * @param fileName
-     * @return File object
-     */
-    private static File constructRelocFile(String fileName) {
-        File relocFile = new File(fileName);
-        if (relocFile.exists()) {
-            if (!relocFile.delete()) {
-                throw new InternalError("Failed to delete existing " + fileName + " file");
-            }
-        }
-        return relocFile;
-    }
-
-    /**
-     * Create {@code count} number of Program headers.
-     *
-     * @param count number of program headers to create
-     * @return true upon success; false upon failure
-     */
-    public boolean createProgramHeader(int count) {
-        phdrPtr = JNILibELFAPI.gelf_newphdr(elfPtr, count);
-        if (phdrPtr == null) {
-            System.out.println("gelf_newphdr error");
-            return false;
-        }
-        return true;
-    }
-
-    /**
-     * Set program header to be of type self.
-     *
-     * @return true
-     */
-    public boolean setProgHdrTypeToSelf() {
-        // Set program header to be of type self
-        JNILibELFAPI.phdr_set_type_self(elfClass, ehdrPtr, phdrPtr);
-        // And thus mark it as dirty so that elfUpdate can recompute the structures
-        JNILibELFAPI.elf_flagphdr(elfPtr, LibELF.Elf_Cmd.ELF_C_SET.intValue(), LibELF.ELF_F_DIRTY);
-        // TODO: Error checking; look at the return value of elf_update
-        // and call elf_errmsg appropriately.
-        return true;
-    }
-
-    /**
-     * Create a section. The corresponding section header and section data are created by calling
-     * the necessary libelf APIs. The section that is created is inserted into the ELF container.
-     *
-     * @param secName name of the section
-     * @param scnData section data
-     * @param dataType data type
-     * @param align section alignment
-     * @param scnType section type
-     * @param scnFlags section flags
-     * @param scnLink sh_link field of Elf{32,64}_Shdr
-     * @param scnInfo sh_info field of Elf{32,64}_Shdr
-     * @return section index
-     */
-    public int createSection(String secName, byte[] scnData, Elf_Type dataType, int align, int scnType, int scnFlags, int scnLink, int scnInfo) {
-        // Create a new section
-        Pointer scnPtr = JNILibELFAPI.elf_newscn(elfPtr);
-        if (scnPtr == null) {
-            throw new InternalError("elf_newscn error");
-        }
-
-        // Allocate section data for the section
-        Pointer scnDataPtr = JNILibELFAPI.elf_newdata(scnPtr);
-        if (scnDataPtr == null) {
-            String errMsg = JNILibELFAPI.elf_errmsg(-1);
-            throw new InternalError("elf_newdata error: " + errMsg);
-        }
-
-        // Get the pointer to section header associated with the new section
-        Pointer scnHdrPtr = JNILibELFAPI.elf64_getshdr(scnPtr);
-
-        // Add name of the section to section name string
-        // If secName is null, point the name to the 0th index
-        // that holds `\0'
-        byte[] modScnData;
-        if (secName.isEmpty()) {
-            JNILibELFAPI.set_Shdr_sh_name(elfClass, scnHdrPtr, 0);
-            modScnData = scnData;
-        } else {
-            if (secName.equals(".shstrtab")) {
-                // Modify .shstrtab data by inserting '\0' at index 0
-                String shstrtabSecName = ".shstrtab" + '\0';
-                // Additional byte for the '\0' at position 0
-                ByteBuffer nbuf = ByteBuffer.allocate(scnData.length + 1 + shstrtabSecName.length());
-                nbuf.put(0, (byte) 0);
-                nbuf.position(1);
-                nbuf.put(scnData);
-                nbuf.position(scnData.length + 1);
-                // Add the section name ".shstrtab" to its own data
-                nbuf.put(shstrtabSecName.getBytes(StandardCharsets.UTF_8));
-                modScnData = nbuf.array();
-                JNILibELFAPI.set_Shdr_sh_name(elfClass, scnHdrPtr, scnData.length + 1);
-                // Set strtab section index
-                JNILibELFAPI.set_Ehdr_e_shstrndx(elfClass, ehdrPtr, JNILibELFAPI.elf_ndxscn(scnPtr));
-            } else if (secName.equals(".strtab")) {
-                // Modify strtab section data to insert '\0' at position 0.
-                // Additional byte for the '\0' at position 0
-                ByteBuffer nbuf = ByteBuffer.allocate(scnData.length + 1);
-                nbuf.put(0, (byte) 0);
-                nbuf.position(1);
-                nbuf.put(scnData);
-                modScnData = nbuf.array();
-                // Set the sh_name
-                JNILibELFAPI.set_Shdr_sh_name(elfClass, scnHdrPtr, shStrTabContent.length() + 1);
-                // Add scnName to stringList
-                shStrTabContent += secName + '\0';
-            } else {
-                // Set the sh_name
-                JNILibELFAPI.set_Shdr_sh_name(elfClass, scnHdrPtr, shStrTabContent.length() + 1);
-                // Add scnName to stringList
-                shStrTabContent += secName + '\0';
-                modScnData = scnData;
-            }
-        }
-
-        final int scnDataBufSize = modScnData.length;
-
-        Pointer scnDataBufPtr = null;
-        if (scnType != ELF.SHT_NOBITS) {
-        // Allocate native memory for section data
-          final long address = UNSAFE.allocateMemory(scnDataBufSize + 1);
-          scnDataBufPtr = new Pointer(address);
-          scnDataBufPtr.put(modScnData);
-        } else {
-          scnDataBufPtr = new Pointer(0L);
-        }
-
-        // Set data descriptor fields
-        JNILibELFAPI.set_Data_d_align(scnDataPtr, align);
-        JNILibELFAPI.set_Data_d_buf(scnDataPtr, scnDataBufPtr);
-        JNILibELFAPI.set_Data_d_size(scnDataPtr, scnDataBufSize);
-        JNILibELFAPI.set_Data_d_off(scnDataPtr, 0);
-        JNILibELFAPI.set_Data_d_type(scnDataPtr, dataType.intValue());
-        JNILibELFAPI.set_Data_d_version(scnDataPtr, ELF.EV_CURRENT);
-
-        JNILibELFAPI.set_Shdr_sh_type(elfClass, scnHdrPtr, scnType);
-        JNILibELFAPI.set_Shdr_sh_flags(elfClass, scnHdrPtr, scnFlags);
-        JNILibELFAPI.set_Shdr_sh_entsize(elfClass, scnHdrPtr, 0); // TODO: Is this right??
-        JNILibELFAPI.set_Shdr_sh_link(elfClass, scnHdrPtr, scnLink);
-        JNILibELFAPI.set_Shdr_sh_info(elfClass, scnHdrPtr, scnInfo);
-
-        // Add hash section to section pointer list
-        int index = JNILibELFAPI.elf_ndxscn(scnPtr);
-        return index;
-    }
-
-    /**
-     * Create an ELF symbol entry for a symbol with the given properties.
-     *
-     * @param name name of the section in which symName is referenced
-     * @param type type of symName
-     * @param bind binding of symName
-     * @param secHdrIndex section header index of the section in which symName is referenced
-     *            (st_shndx of ELF symbol entry)
-     * @param size symName size (st_size of ELF symbol entry)
-     * @param value symName value (st_value of ELF symbol entry)
-     * @param isLocal true if symbol is local.
-     */
-    public ELFSymbol createELFSymbolEntry(String name, int type, int bind, int secHdrIndex, int size, int value, boolean isLocal) {
-        // Get the current symbol index and append symbol name to string table.
-        int index;
-        if (name.isEmpty()) {
-            index = 0;
-        } else {
-            // NOTE: The +1 comes from the null symbol!
-            // We can't trust strTabContent.length() since that is chars (UTF16), keep track of
-            // bytes on our own.
-            index = strTabNrOfBytes + 1;
-            strTabContent.append(name).append('\0');
-            strTabNrOfBytes += name.getBytes(StandardCharsets.UTF_8).length + 1;
-        }
-
-        // Create ELF symbol entry
-        long address = JNILibELFAPI.create_sym_entry(elfClass, index, type, bind, secHdrIndex, size, value);
-        if (address == 0) {
-            throw new InternalError("create_sym_entry failed");
-        }
-        Pointer ptr = new Pointer(address);
-
-        if (isLocal) {
-            final int localIndex = localSymbolIndex.size();
-            ELFSymbol symbol = new ELFSymbol(name, localIndex, ptr, isLocal);
-            localSymbolIndex.add(symbol);
-            return symbol;
-        } else {
-            final int globalIndex = globalSymbolIndex.size();
-            ELFSymbol symbol = new ELFSymbol(name, globalIndex, ptr, isLocal);
-            globalSymbolIndex.add(symbol);
-            return symbol;
-        }
-    }
-
-    /**
-     * Create an ELF relocation entry for given symbol {@code name} to section {@code secname}.
-     *
-     * @param container the section
-     * @param offset offset into the section contents at which the relocation needs to be applied
-     * @param type ELF type of the relocation entry
-     * @param addend Addend for for relocation of type reloca
-     */
-    public void createELFRelocationEntry(ELFContainer container, int offset, int type, int addend, ELFSymbol elfSymbol) {
-        // Get the index of the symbol.
-        int index;
-        if (elfSymbol.isLocal()) {
-            index = elfSymbol.getIndex();
-        } else {
-            /*
-             * For global symbol entries the index will be offset by the number of local symbols
-             * which will be listed first in the symbol table.
-             */
-            index = elfSymbol.getIndex() + localSymbolIndex.size();
-        }
-
-        long address = JNILibELFAPI.create_reloc_entry(elfClass, offset, index, type, addend, createReloca);
-        if (address == 0) {
-            throw new InternalError("create_reloc_entry failed");
-        }
-        Pointer ptr = new Pointer(address);
-        /*
-         * If section name associated with this symbol is set to undefined i.e., secname is null,
-         * symIndex is undef i.e., 0.
-         */
-        if (relocTables.get(container) == null) {
-            // Allocate a new table and add it to the hash table of reloc tables
-            relocTables.put(container, new ArrayList<>());
-        }
-
-        // Add the entry
-        relocTables.get(container).add(ptr);
-    }
-
-    /**
-     * Invokes native libelf function loff_t elf_update (Elf *elfPtr, Elf_Cmd cmd).
-     *
-     * @param cmd command
-     * @return return value of the native function called
-     */
-    public boolean elfUpdate(LibELF.Elf_Cmd cmd) {
-        JNILibELFAPI.elf_update(elfPtr, cmd.intValue());
-        // TODO: Error checking; look at the return value of elf_update
-        // and call elf_errmsg appropriately.
-        return true;
-    }
-
-    /**
-     * Wrapper function that invokes int elf_end (Elf *elfPtr). and closes ELF output file
-     * descriptor
-     *
-     * @return true
-     */
-    public boolean elfEnd() {
-        // Finish ELF processing
-        JNILibELFAPI.elf_end(elfPtr);
-        // Close file descriptor
-        JNILibELFAPI.close(outFileDesc);
-        return true;
-    }
-}
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.jnilibelf/src/jdk/tools/jaotc/jnilibelf/JNIELFRelocation.java	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-/*
- * 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.
- */
-
-package jdk.tools.jaotc.jnilibelf;
-
-/**
- * Class that abstracts ELF relocations.
- *
- */
-public interface JNIELFRelocation {
-    int R_UNDEF = -1;
-
-    /**
-     * x86-specific relocation types.
-     *
-     */
-    public interface I386 {
-        /* i386 relocs. */
-
-        int R_386_NONE = 0; /* No reloc */
-        int R_386_32 = 1; /* Direct 32 bit */
-        int R_386_PC32 = 2; /* PC relative 32 bit */
-        int R_386_GOT32 = 3; /* 32 bit GOT entry */
-        int R_386_PLT32 = 4; /* 32 bit PLT address */
-        int R_386_COPY = 5; /* Copy symbol at runtime */
-        int R_386_GLOB_DAT = 6; /* Create GOT entry */
-        int R_386_JMP_SLOT = 7; /* Create PLT entry */
-        int R_386_RELATIVE = 8; /* Adjust by program base */
-        int R_386_GOTOFF = 9; /* 32 bit offset to GOT */
-        int R_386_GOTPC = 10; /* 32 bit PC relative offset to GOT */
-        int R_386_32PLT = 11;
-        int R_386_TLS_TPOFF = 14; /* Offset in static TLS block */
-        int R_386_TLS_IE = 15; /* Address of GOT entry for static TLS block offset */
-        int R_386_TLS_GOTIE = 16; /* GOT entry for static TLS block offset */
-        int R_386_TLS_LE = 17; /* Offset relative to static TLS block */
-        int R_386_TLS_GD = 18; /* Direct 32 bit for GNU version of general dynamic thread local data */
-        int R_386_TLS_LDM = 19; /*
-                                 * Direct 32 bit for GNU version of local dynamic thread local data
-                                 * in LE code
-                                 */
-        int R_386_16 = 20;
-        int R_386_PC16 = 21;
-        int R_386_8 = 22;
-        int R_386_PC8 = 23;
-        int R_386_TLS_GD_32 = 24; /* Direct 32 bit for general dynamic thread local data */
-        int R_386_TLS_GD_PUSH = 25; /* Tag for pushl in GD TLS code */
-        int R_386_TLS_GD_CALL = 26; /* Relocation for call to __tls_get_addr() */
-        int R_386_TLS_GD_POP = 27; /* Tag for popl in GD TLS code */
-        int R_386_TLS_LDM_32 = 28; /* Direct 32 bit for local dynamic thread local data in LE code */
-        int R_386_TLS_LDM_PUSH = 29; /* Tag for pushl in LDM TLS code */
-        int R_386_TLS_LDM_CALL = 30; /* Relocation for call to __tls_get_addr() in LDM code */
-        int R_386_TLS_LDM_POP = 31; /* Tag for popl in LDM TLS code */
-        int R_386_TLS_LDO_32 = 32; /* Offset relative to TLS block */
-        int R_386_TLS_IE_32 = 33; /* GOT entry for negated static TLS block offset */
-        int R_386_TLS_LE_32 = 34; /* Negated offset relative to static TLS block */
-        int R_386_TLS_DTPMOD32 = 35; /* ID of module containing symbol */
-        int R_386_TLS_DTPOFF32 = 36; /* Offset in TLS block */
-        int R_386_TLS_TPOFF32 = 37; /* Negated offset in static TLS block */
-        int R_386_SIZE32 = 38; /* 32-bit symbol size */
-        int R_386_TLS_GOTDESC = 39; /* GOT offset for TLS descriptor. */
-        int R_386_TLS_DESC_CALL = 40; /* Marker of call through TLS descriptor for relaxation. */
-        int R_386_TLS_DESC = 41; /*
-                                  * TLS descriptor containing pointer to code and to argument,
-                                  * returning the TLS offset for the symbol.
-                                  */
-        int R_386_IRELATIVE = 42; /* Adjust indirectly by program base */
-        /* Keep this the last entry. */
-        int R_386_NUM = 43;
-    }
-
-    /**
-     * x86_64-specific relocation types.
-     */
-    public interface X86_64 {
-        /* AMD x86-64 relocations. */
-        int R_X86_64_NONE = 0; /* No reloc */
-        int R_X86_64_64 = 1; /* Direct 64 bit */
-        int R_X86_64_PC32 = 2; /* PC relative 32 bit signed */
-        int R_X86_64_GOT32 = 3; /* 32 bit GOT entry */
-        int R_X86_64_PLT32 = 4; /* 32 bit PLT address */
-        int R_X86_64_COPY = 5; /* Copy symbol at runtime */
-        int R_X86_64_GLOB_DAT = 6; /* Create GOT entry */
-        int R_X86_64_JUMP_SLOT = 7; /* Create PLT entry */
-        int R_X86_64_RELATIVE = 8; /* Adjust by program base */
-        int R_X86_64_GOTPCREL = 9; /* 32 bit signed PC relative offset to GOT */
-        int R_X86_64_32 = 10; /* Direct 32 bit zero extended */
-        int R_X86_64_32S = 11; /* Direct 32 bit sign extended */
-        int R_X86_64_16 = 12; /* Direct 16 bit zero extended */
-        int R_X86_64_PC16 = 13; /* 16 bit sign extended pc relative */
-        int R_X86_64_8 = 14; /* Direct 8 bit sign extended */
-        int R_X86_64_PC8 = 15; /* 8 bit sign extended pc relative */
-        int R_X86_64_DTPMOD64 = 16; /* ID of module containing symbol */
-        int R_X86_64_DTPOFF64 = 17; /* Offset in module's TLS block */
-        int R_X86_64_TPOFF64 = 18; /* Offset in initial TLS block */
-        int R_X86_64_TLSGD = 19; /*
-                                  * 32 bit signed PC relative offset to two GOT entries for GD
-                                  * symbol
-                                  */
-        int R_X86_64_TLSLD = 20; /*
-                                  * 32 bit signed PC relative offset to two GOT entries for LD
-                                  * symbol
-                                  */
-        int R_X86_64_DTPOFF32 = 21; /* Offset in TLS block */
-        int R_X86_64_GOTTPOFF = 22; /*
-                                     * 32 bit signed PC relative offset to GOT entry for IE symbol
-                                     */
-        int R_X86_64_TPOFF32 = 23; /* Offset in initial TLS block */
-        int R_X86_64_PC64 = 24; /* PC relative 64 bit */
-        int R_X86_64_GOTOFF64 = 25; /* 64 bit offset to GOT */
-        int R_X86_64_GOTPC32 = 26; /* 32 bit signed pc relative offset to GOT */
-        int R_X86_64_GOT64 = 27; /* 64-bit GOT entry offset */
-        int R_X86_64_GOTPCREL64 = 28; /* 64-bit PC relative offset to GOT entry */
-        int R_X86_64_GOTPC64 = 29; /* 64-bit PC relative offset to GOT */
-        int R_X86_64_GOTPLT64 = 30; /* like GOT64, says PLT entry needed */
-        int R_X86_64_PLTOFF64 = 31; /* 64-bit GOT relative offset to PLT entry */
-        int R_X86_64_SIZE32 = 32; /* Size of symbol plus 32-bit addend */
-        int R_X86_64_SIZE64 = 33; /* Size of symbol plus 64-bit addend */
-        int R_X86_64_GOTPC32_TLSDESC = 34; /* GOT offset for TLS descriptor. */
-        int R_X86_64_TLSDESC_CALL = 35; /*
-                                         * Marker for call through TLS descriptor.
-                                         */
-        int R_X86_64_TLSDESC = 36; /* TLS descriptor. */
-        int R_X86_64_IRELATIVE = 37; /* Adjust indirectly by program base */
-        int R_X86_64_RELATIVE64 = 38; /* 64-bit adjust by program base */
-
-        int R_X86_64_NUM = 39;
-    }
-}
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.jnilibelf/src/jdk/tools/jaotc/jnilibelf/JNIELFTargetInfo.java	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,127 +0,0 @@
-/*
- * 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.
- */
-
-package jdk.tools.jaotc.jnilibelf;
-
-import java.nio.ByteOrder;
-
-import jdk.tools.jaotc.jnilibelf.JNILibELFAPI.ELF;
-
-/**
- * Class that abstracts ELF target details.
- *
- */
-public class JNIELFTargetInfo {
-    /**
-     * ELF Class of the target.
-     */
-    private static final int elfClass;
-    /**
-     * Target architecture.
-     */
-    private static final int arch;
-    /**
-     * Architecture endian-ness.
-     */
-    private static final int endian;
-
-    /**
-     * Target OS string.
-     */
-    private static final String osName;
-
-    static {
-        // Find the target arch details
-        String archStr = System.getProperty("os.arch").toLowerCase();
-        String datamodelStr = System.getProperty("sun.arch.data.model");
-
-        if (datamodelStr.equals("32")) {
-            elfClass = ELF.ELFCLASS32;
-        } else if (datamodelStr.equals("64")) {
-            elfClass = ELF.ELFCLASS64;
-        } else {
-            System.out.println("Failed to discover ELF class!");
-            elfClass = ELF.ELFCLASSNONE;
-        }
-
-        ByteOrder bo = ByteOrder.nativeOrder();
-        if (bo == ByteOrder.LITTLE_ENDIAN) {
-            endian = ELF.ELFDATA2LSB;
-        } else if (bo == ByteOrder.BIG_ENDIAN) {
-            endian = ELF.ELFDATA2MSB;
-        } else {
-            System.out.println("Failed to discover endian-ness!");
-            endian = ELF.ELFDATANONE;
-        }
-
-        if (archStr.equals("x86")) {
-            arch = ELF.EM_386;
-        } else if (archStr.equals("amd64") || archStr.equals("x86_64")) {
-            arch = ELF.EM_X64_64;
-        } else if (archStr.equals("sparcv9")) {
-            arch = ELF.EM_SPARCV9;
-        } else {
-            System.out.println("Unsupported architecture " + archStr);
-            arch = ELF.EM_NONE;
-        }
-
-        osName = System.getProperty("os.name").toLowerCase();
-    }
-
-    public static int getELFArch() {
-        return arch;
-    }
-
-    public static int getELFClass() {
-        return elfClass;
-    }
-
-    public static int getELFEndian() {
-        return endian;
-    }
-
-    public static String getOsName() {
-        return osName;
-    }
-
-    public static int createReloca() {
-        switch (arch) {
-            case ELF.EM_X64_64:
-                return 1;
-            default:
-                return 0;
-        }
-    }
-
-    public static int sizeOfSymtabEntry() {
-        return JNILibELFAPI.size_of_Sym(elfClass);
-    }
-
-    public static int sizeOfRelocEntry() {
-        if (createReloca() == 1) {
-            return JNILibELFAPI.size_of_Rela(elfClass);
-        } else {
-            return JNILibELFAPI.size_of_Rel(elfClass);
-        }
-    }
-}
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.jnilibelf/src/jdk/tools/jaotc/jnilibelf/JNILibELFAPI.java	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,677 +0,0 @@
-/*
- * 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.
- */
-
-package jdk.tools.jaotc.jnilibelf;
-
-public class JNILibELFAPI {
-
-    static {
-        System.loadLibrary("jelfshim");
-    }
-
-    /**
-     * Definitions for file open.
-     */
-    public static enum OpenFlags {
-        O_RDONLY(0x0),
-        O_WRONLY(0x1),
-        O_RDWR(0x2),
-        O_CREAT(0x40);
-
-        private final int intVal;
-
-        private OpenFlags(int v) {
-            intVal = v;
-        }
-
-        public int intValue() {
-            return intVal;
-        }
-    }
-
-    /**
-     * Definitions reflecting those in elf.h.
-     *
-     */
-    public interface ELF {
-        int EI_NIDENT = 16;
-
-        int EI_CLASS = 4; /* File class byte index */
-        int ELFCLASSNONE = 0; /* Invalid class */
-        int ELFCLASS32 = 1; /* 32-bit objects */
-        int ELFCLASS64 = 2; /* 64-bit objects */
-        int ELFCLASSNUM = 3;
-
-        int EI_DATA = 5; /* Data encoding byte index */
-        int ELFDATANONE = 0; /* Invalid data encoding */
-        int ELFDATA2LSB = 1; /* 2's complement, little endian */
-        int ELFDATA2MSB = 2; /* 2's complement, big endian */
-        int ELFDATANUM = 3;
-
-        // Legal architecture values for e_machine (add others as needed)
-        int EM_NONE = 0; /* No machine */
-        int EM_SPARC = 2; /* SUN SPARC */
-        int EM_386 = 3; /* Intel 80386 */
-        int EM_SPARCV9 = 43; /* SPARC v9 64-bit */
-        int EM_X64_64 = 62; /* AMD x86-64 architecture */
-
-        /* Legal values for e_type (object file type). */
-
-        int ET_NONE = 0; /* No file type */
-        int ET_REL = 1; /* Relocatable file */
-        int ET_EXEC = 2; /* Executable file */
-        int ET_DYN = 3; /* Shared object file */
-        int ET_CORE = 4; /* Core file */
-        int ET_NUM = 5; /* Number of defined types */
-        int ET_LOOS = 0xfe00; /* OS-specific range start */
-        int ET_HIOS = 0xfeff; /* OS-specific range end */
-        int ET_LOPROC = 0xff00; /* Processor-specific range start */
-        int ET_HIPROC = 0xffff; /* Processor-specific range end */
-
-        /* Legal values for e_version (version). */
-
-        int EV_NONE = 0; /* Invalid ELF version */
-        int EV_CURRENT = 1; /* Current version */
-        int EV_NUM = 2;
-
-        /* Legal values for p_type (segment type). */
-
-        int PT_NULL = 0; /* Program header table entry unused */
-        int PT_LOAD = 1; /* Loadable program segment */
-        int PT_DYNAMIC = 2; /* Dynamic linking information */
-        int PT_INTERP = 3; /* Program interpreter */
-        int PT_NOTE = 4; /* Auxiliary information */
-        int PT_SHLIB = 5; /* Reserved */
-        int PT_PHDR = 6; /* Entry for header table itself */
-        int PT_TLS = 7; /* Thread-local storage segment */
-        int PT_NUM = 8; /* Number of defined types */
-        int PT_LOOS = 0x60000000; /* Start of OS-specific */
-        int PT_GNU_EH_FRAME = 0x6474e550; /* GCC .eh_frame_hdr segment */
-        int PT_GNU_STACK = 0x6474e551; /* Indicates stack executability */
-        int PT_GNU_RELRO = 0x6474e552; /* Read-only after relocation */
-        int PT_LOSUNW = 0x6ffffffa;
-        int PT_SUNWBSS = 0x6ffffffa; /* Sun Specific segment */
-        int PT_SUNWSTACK = 0x6ffffffb; /* Stack segment */
-        int PT_HISUNW = 0x6fffffff;
-        int PT_HIOS = 0x6fffffff; /* End of OS-specific */
-        int PT_LOPROC = 0x70000000; /* Start of processor-specific */
-        int PT_HIPROC = 0x7fffffff; /* End of processor-specific */
-
-        /* Special section indices. */
-
-        int SHN_UNDEF = 0; /* Undefined section */
-        int SHN_LORESERVE = 0xff00; /* Start of reserved indices */
-        int SHN_LOPROC = 0xff00; /* Start of processor-specific */
-        int SHN_BEFORE = 0xff00; /* Order section before all others (Solaris). */
-        int SHN_AFTER = 0xff01; /* Order section after all others (Solaris). */
-        int SHN_HIPROC = 0xff1f; /* End of processor-specific */
-        int SHN_LOOS = 0xff20; /* Start of OS-specific */
-        int SHN_HIOS = 0xff3f; /* End of OS-specific */
-        int SHN_ABS = 0xfff1; /* Associated symbol is absolute */
-        int SHN_COMMON = 0xfff2; /* Associated symbol is common */
-        int SHN_XINDEX = 0xffff; /* Index is in extra table. */
-        int SHN_HIRESERVE = 0xffff; /* End of reserved indices */
-
-        /* Legal values for sh_type (section type). */
-
-        int SHT_NULL = 0; /* Section header table entry unused */
-        int SHT_PROGBITS = 1; /* Program data */
-        int SHT_SYMTAB = 2; /* Symbol table */
-        int SHT_STRTAB = 3; /* String table */
-        int SHT_RELA = 4; /* Relocation entries with addends */
-        int SHT_HASH = 5; /* Symbol hash table */
-        int SHT_DYNAMIC = 6; /* Dynamic linking information */
-        int SHT_NOTE = 7; /* Notes */
-        int SHT_NOBITS = 8; /* Program space with no data (bss) */
-        int SHT_REL = 9; /* Relocation entries, no addends */
-        int SHT_SHLIB = 10; /* Reserved */
-        int SHT_DYNSYM = 11; /* Dynamic linker symbol table */
-        int SHT_INIT_ARRAY = 14; /* Array of constructors */
-        int SHT_FINI_ARRAY = 15; /* Array of destructors */
-        int SHT_PREINIT_ARRAY = 16; /* Array of pre-constructors */
-        int SHT_GROUP = 17; /* Section group */
-        int SHT_SYMTAB_SHNDX = 18; /* Extended section indeces */
-        int SHT_NUM = 19; /* Number of defined types. */
-        int SHT_LOOS = 0x60000000; /* Start OS-specific. */
-        int SHT_GNU_ATTRIBUTES = 0x6ffffff5; /* Object attributes. */
-        int SHT_GNU_HASH = 0x6ffffff6; /* GNU-style hash table. */
-        int SHT_GNU_LIBLIST = 0x6ffffff7; /* Prelink library list */
-        int SHT_CHECKSUM = 0x6ffffff8; /* Checksum for DSO content. */
-        int SHT_LOSUNW = 0x6ffffffa; /* Sun-specific low bound. */
-        int SHT_SUNW_move = 0x6ffffffa;
-        int SHT_SUNW_COMDAT = 0x6ffffffb;
-        int SHT_SUNW_syminfo = 0x6ffffffc;
-        int SHT_GNU_verdef = 0x6ffffffd; /* Version definition section. */
-        int SHT_GNU_verneed = 0x6ffffffe; /* Version needs section. */
-        int SHT_GNU_versym = 0x6fffffff; /* Version symbol table. */
-        int SHT_HISUNW = 0x6fffffff; /* Sun-specific high bound. */
-        int SHT_HIOS = 0x6fffffff; /* End OS-specific type */
-        int SHT_LOPROC = 0x70000000; /* Start of processor-specific */
-        int SHT_HIPROC = 0x7fffffff; /* End of processor-specific */
-        int SHT_LOUSER = 0x80000000; /* Start of application-specific */
-        int SHT_HIUSER = 0x8fffffff; /* End of application-specific */
-
-        /* Legal values for sh_flags (section flags). */
-
-        int SHF_WRITE = (1 << 0); /* Writable */
-        int SHF_ALLOC = (1 << 1); /* Occupies memory during execution */
-        int SHF_EXECINSTR = (1 << 2); /* Executable */
-        int SHF_MERGE = (1 << 4); /* Might be merged */
-        int SHF_STRINGS = (1 << 5); /* Contains nul-terminated strings */
-        int SHF_INFO_LINK = (1 << 6); /* `sh_info' contains SHT index */
-        int SHF_LINK_ORDER = (1 << 7); /* Preserve order after combining */
-        int SHF_OS_NONCONFORMING = (1 << 8); /* Non-standard OS specific handling required */
-        int SHF_GROUP = (1 << 9); /* Section is member of a group. */
-        int SHF_TLS = (1 << 10); /* Section hold thread-local data. */
-        int SHF_MASKOS = 0x0ff00000; /* OS-specific. */
-        int SHF_MASKPROC = 0xf0000000; /* Processor-specific */
-        int SHF_ORDERED = (1 << 30); /* Special ordering requirement (Solaris). */
-        int SHF_EXCLUDE = (1 << 31); /*
-                                      * Section is excluded unless referenced or allocated
-                                      * (Solaris).
-                                      */
-
-        /* Legal values for ST_BIND subfield of st_info (symbol binding). */
-
-        int STB_LOCAL = 0; /* Local symbol */
-        int STB_GLOBAL = 1; /* Global symbol */
-        int STB_WEAK = 2; /* Weak symbol */
-        int STB_NUM = 3; /* Number of defined types. */
-        int STB_LOOS = 10; /* Start of OS-specific */
-        int STB_GNU_UNIQUE = 10; /* Unique symbol. */
-        int STB_HIOS = 12; /* End of OS-specific */
-        int STB_LOPROC = 13; /* Start of processor-specific */
-        int STB_HIPROC = 15; /* End of processor-specific */
-
-        /* Legal values for ST_TYPE subfield of st_info (symbol type). */
-
-        int STT_NOTYPE = 0; /* Symbol type is unspecified */
-        int STT_OBJECT = 1; /* Symbol is a data object */
-        int STT_FUNC = 2; /* Symbol is a code object */
-        int STT_SECTION = 3; /* Symbol associated with a section */
-        int STT_FILE = 4; /* Symbol's name is file name */
-        int STT_COMMON = 5; /* Symbol is a common data object */
-        int STT_TLS = 6; /* Symbol is thread-local data object */
-        int STT_NUM = 7; /* Number of defined types. */
-        int STT_LOOS = 10; /* Start of OS-specific */
-        int STT_GNU_IFUNC = 10; /* Symbol is indirect code object */
-        int STT_HIOS = 12; /* End of OS-specific */
-        int STT_LOPROC = 13; /* Start of processor-specific */
-        int STT_HIPROC = 15; /* End of processor-specific */
-    }
-
-    /**
-     * Definitions reflecting those in libelf.h.
-     *
-     */
-    public interface LibELF {
-
-        public static enum Elf_Cmd {
-            ELF_C_NULL("NULL"), /* Nothing, terminate, or compute only. */
-            ELF_C_READ("READ"), /* Read .. */
-            ELF_C_RDWR("RDWR"), /* Read and write .. */
-            ELF_C_WRITE("WRITE"), /* Write .. */
-            ELF_C_CLR("CLR"), /* Clear flag. */
-            ELF_C_SET("SET"), /* Set flag. */
-            ELF_C_FDDONE("FDDONE"), /*
-                                     * Signal that file descriptor will not be used anymore.
-                                     */
-            ELF_C_FDREAD("FDREAD"), /*
-                                     * Read rest of data so that file descriptor is not used
-                                     * anymore.
-                                     */
-            /* The following are Linux-only extensions. */
-            ELF_C_READ_MMAP("READ_MMAP"), /* Read, but mmap the file if possible. */
-            ELF_C_RDWR_MMAP("RDWR_MMAP"), /* Read and write, with mmap. */
-            ELF_C_WRITE_MMAP("WRITE_MMAP"), /* Write, with mmap. */
-            ELF_C_READ_MMAP_PRIVATE("READ_MMAP_PRIVATE"), /*
-                                                           * Read, but memory is writable, results
-                                                           * are not written to the file.
-                                                           */
-            ELF_C_EMPTY("EMPTY"), /* Copy basic file data but not the content. */
-            /* The following are SunOS-only enums */
-            ELF_C_WRIMAGE("WRIMAGE"),
-            ELF_C_IMAGE("IMAGE"),
-            /* Common last entry. */
-            ELF_C_NUM("NUM");
-            private final int intVal;
-            private final String name;
-
-            private Elf_Cmd(String cmd) {
-                name = "ELF_C_" + cmd;
-                switch (cmd) {
-                    case "NULL":
-                        // ELF_C_NULL has the same enum ordinal on both Linux and SunOS
-                        intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_NULL.ordinal();
-                        break;
-
-                    case "READ":
-                        // ELF_C_READ has the same enum ordinal on both Linux and SunOS
-                        intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_READ.ordinal();
-                        break;
-
-                    // Enums defined in libelf.h of both Linux and SunOS
-                    // but with different ordinals
-                    case "RDWR":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_RDWR.ordinal();
-                        } else if (JNIELFTargetInfo.getOsName().equals("sunos")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.sunos.Elf_Cmd.ELF_C_RDWR.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-
-                    case "WRITE":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_WRITE.ordinal();
-                        } else if (JNIELFTargetInfo.getOsName().equals("sunos")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.sunos.Elf_Cmd.ELF_C_WRITE.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-
-                    case "CLR":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_CLR.ordinal();
-                        } else if (JNIELFTargetInfo.getOsName().equals("sunos")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.sunos.Elf_Cmd.ELF_C_CLR.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-
-                    case "SET":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_SET.ordinal();
-                        } else if (JNIELFTargetInfo.getOsName().equals("sunos")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.sunos.Elf_Cmd.ELF_C_SET.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-
-                    case "FDDONE":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_FDDONE.ordinal();
-                        } else if (JNIELFTargetInfo.getOsName().equals("sunos")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.sunos.Elf_Cmd.ELF_C_FDDONE.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-
-                    case "FDREAD":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_FDREAD.ordinal();
-                        } else if (JNIELFTargetInfo.getOsName().equals("sunos")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.sunos.Elf_Cmd.ELF_C_FDREAD.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-
-                    case "NUM":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_NUM.ordinal();
-                        } else if (JNIELFTargetInfo.getOsName().equals("sunos")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.sunos.Elf_Cmd.ELF_C_NUM.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-
-                    // Linux-only Elf_Cmd enums
-                    case "READ_MMAP":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_READ_MMAP.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-
-                    case "RDWR_MMAP":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_RDWR_MMAP.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-
-                    case "WRITE_MMAP":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_WRITE_MMAP.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-
-                    case "READ_MMAP_PRIVATE":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_READ_MMAP_PRIVATE.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-
-                    case "EMPTY":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.linux.Elf_Cmd.ELF_C_EMPTY.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-                    // SunOS-only Elf_Cmd enums
-                    case "WRIMAGE":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.sunos.Elf_Cmd.ELF_C_WRIMAGE.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-                    case "IMAGE":
-                        if (JNIELFTargetInfo.getOsName().equals("linux")) {
-                            intVal = jdk.tools.jaotc.jnilibelf.sunos.Elf_Cmd.ELF_C_IMAGE.ordinal();
-                        } else {
-                            // Unsupported platform
-                            intVal = -1;
-                        }
-                        break;
-                    default:
-                        intVal = -1;
-                }
-            }
-
-            public int intValue() {
-                assert intVal != -1 : "enum " + name + "not supported on " + JNIELFTargetInfo.getOsName();
-                return intVal;
-            }
-
-            public String getName() {
-                return name;
-            }
-        }
-
-        public static enum Elf_Type {
-            ELF_T_BYTE(0), /* unsigned char */
-            ELF_T_ADDR(1), /* Elf32_Addr, Elf64_Addr, ... */
-            ELF_T_DYN(2), /* Dynamic section record. */
-            ELF_T_EHDR(3), /* ELF header. */
-            ELF_T_HALF(4), /* Elf32_Half, Elf64_Half, ... */
-            ELF_T_OFF(5), /* Elf32_Off, Elf64_Off, ... */
-            ELF_T_PHDR(6), /* Program header. */
-            ELF_T_RELA(7), /* Relocation entry with addend. */
-            ELF_T_REL(8), /* Relocation entry. */
-            ELF_T_SHDR(9), /* Section header. */
-            ELF_T_SWORD(10), /* Elf32_Sword, Elf64_Sword, ... */
-            ELF_T_SYM(11), /* Symbol record. */
-            ELF_T_WORD(12), /* Elf32_Word, Elf64_Word, ... */
-            ELF_T_XWORD(13), /* Elf32_Xword, Elf64_Xword, ... */
-            ELF_T_SXWORD(14), /* Elf32_Sxword, Elf64_Sxword, ... */
-            ELF_T_VDEF(15), /* Elf32_Verdef, Elf64_Verdef, ... */
-            ELF_T_VDAUX(16), /* Elf32_Verdaux, Elf64_Verdaux, ... */
-            ELF_T_VNEED(17), /* Elf32_Verneed, Elf64_Verneed, ... */
-            ELF_T_VNAUX(18), /* Elf32_Vernaux, Elf64_Vernaux, ... */
-            ELF_T_NHDR(19), /* Elf32_Nhdr, Elf64_Nhdr, ... */
-            ELF_T_SYMINFO(20), /* Elf32_Syminfo, Elf64_Syminfo, ... */
-            ELF_T_MOVE(21), /* Elf32_Move, Elf64_Move, ... */
-            ELF_T_LIB(22), /* Elf32_Lib, Elf64_Lib, ... */
-            ELF_T_GNUHASH(23), /* GNU-style hash section. */
-            ELF_T_AUXV(24), /* Elf32_auxv_t, Elf64_auxv_t, ... */
-            /* Keep this the last entry. */
-            ELF_T_NUM(25);
-
-            private final int intVal;
-
-            private Elf_Type(int v) {
-                intVal = v;
-            }
-
-            public int intValue() {
-                return intVal;
-            }
-        }
-
-        /* Flags for the ELF structures. */
-        int ELF_F_DIRTY = 0x1;
-        int ELF_F_LAYOUT = 0x4;
-        int ELF_F_PERMISSIVE = 0x8;
-
-        public static enum Elf_Kind {
-            ELF_K_NONE(0), /* Unknown. */
-            ELF_K_AR(1), /* Archive. */
-            ELF_K_COFF(2), /* Stupid old COFF. */
-            ELF_K_ELF(3), /* ELF file. */
-            /* Keep this the last entry. */
-            ELF_K_NUM(4);
-            private final int intVal;
-
-            private Elf_Kind(int v) {
-                intVal = v;
-            }
-
-            public int intValue() {
-                return intVal;
-            }
-        }
-    }
-
-    /**
-     * Invoke native libelf function unsigned int elf_version (unsigned int v).
-     *
-     * @param v version
-     * @return return value of native call
-     */
-    // Checkstyle: stop method name check
-    static native int elf_version(int v);
-
-    /**
-     * Return version recorded in libelfshim.
-     *
-     * @return return version string
-     */
-    // Checkstyle: stop method name check
-    static native String elfshim_version();
-
-    /**
-     * Invoke native libelf function Elf *elf_begin (int fildes, Elf_Cmd cmd, Elf *elfPtr).
-     *
-     * @param fildes open file descriptor
-     * @param elfCRead command
-     * @param elfHdrPtr pointer to ELF header
-     * @return return value of native call
-     */
-    static native Pointer elf_begin(int fildes, int elfCRead, Pointer elfHdrPtr);
-
-    /**
-     * Invoke native libelf function elf_end (Elf *elfPtr).
-     *
-     * @param elfPtr pointer to ELF header
-     * @return return value of native call
-     */
-    static native int elf_end(Pointer elfPtr);
-
-    /**
-     * Invoke native libelf function elf_end (Elf *elfPtr).
-     *
-     * @param elfPtr pointer to ELF header
-     * @return return value of native call
-     */
-    static native int elf_kind(Pointer elfPtr);
-
-    /**
-     * Invoke native libelf function unsigned int elf_flagphdr (Elf *elf, Elf_Cmd cmd, unsigned int
-     * flags).
-     *
-     * @param elfPtr Pointer to ELF descriptor
-     * @param cmd command
-     * @param flags flags
-     * @return return value of native call
-     */
-    static native int elf_flagphdr(Pointer elfPtr, int cmd, int flags);
-
-    /**
-     * Invoke native libelf function Elf_Scn *elf_newscn (Elf *elfPtr).
-     *
-     * @param elfPtr Elf header pointer
-     * @return return value of native call
-     */
-    static native Pointer elf_newscn(Pointer elfPtr);
-
-    /**
-     * Invoke native libelf function Elf_Data *elf_newdata (Elf_Scn *scn).
-     *
-     * @param scnPtr pointer to section for which the new data descriptor is to be created
-     * @return return value of native call
-     */
-    static native Pointer elf_newdata(Pointer scnPtr);
-
-    /**
-     * Invoke native libelf function Elf64_Shdr *elf64_getshdr (Elf_Scn *scnPtr).
-     *
-     * @param scnPtr pointer to section whose header information is to be retrieved
-     * @return return value of native call
-     */
-    static native Pointer elf64_getshdr(Pointer scnPtr);
-
-    /**
-     * Invoke native libelf function loff_t elf_update (Elf *elfPtr, Elf_Cmd cmd).
-     *
-     * @param elfPtr Pointer to ELF descriptor
-     * @param cmd command
-     * @return return value of native call
-     */
-    static native long elf_update(Pointer elfPtr, int cmd);
-
-    /**
-     * Invoke native libelf function char *elf_errmsg (int error).
-     *
-     * @param error error
-     * @return return value of native call
-     */
-    static native String elf_errmsg(int error);
-
-    /**
-     * Invoke native libelf function size_t elf_ndxscn (Elf_Scn *scn).
-     *
-     * @param scn section pointer
-     * @return return value of native call
-     */
-    static native int elf_ndxscn(Pointer scn);
-
-    /**
-     * GELF interfaces
-     */
-    /**
-     * Invoke native libelf function unsigned long int gelf_newehdr (Elf *elf, int elfClass).
-     *
-     * @param elf ELF Header pointer
-     * @param elfclass ELF class
-     * @return return value of native call boxed as a pointer
-     */
-    static native Pointer gelf_newehdr(Pointer elf, int elfclass);
-
-    /**
-     * Invoke native libelf function unsigned long int gelf_newphdr (Elf *elf, size_t phnum).
-     *
-     * @param elf ELF header pointer
-     * @param phnum number of program headers
-     * @return return value of native call boxed as a pointer
-     */
-    static native Pointer gelf_newphdr(Pointer elf, int phnum);
-
-    /**
-     * Miscellaneous convenience native methods that help peek and poke ELF data structures.
-     */
-    static native int size_of_Sym(int elfClass);
-
-    static native int size_of_Rela(int elfClass);
-
-    static native int size_of_Rel(int elfClass);
-
-    static native void ehdr_set_data_encoding(Pointer ehdr, int val);
-
-    static native void set_Ehdr_e_machine(int elfclass, Pointer structPtr, int val);
-
-    static native void set_Ehdr_e_type(int elfclass, Pointer structPtr, int val);
-
-    static native void set_Ehdr_e_version(int elfclass, Pointer structPtr, int val);
-
-    static native void set_Ehdr_e_shstrndx(int elfclass, Pointer structPtr, int val);
-
-    static native void phdr_set_type_self(int elfclass, Pointer ehdr, Pointer phdr);
-
-    static native void set_Shdr_sh_name(int elfclass, Pointer structPtr, int val);
-
-    static native void set_Shdr_sh_type(int elfclass, Pointer structPtr, int val);
-
-    static native void set_Shdr_sh_flags(int elfclass, Pointer structPtr, int val);
-
-    static native void set_Shdr_sh_entsize(int elfclass, Pointer structPtr, int val);
-
-    static native void set_Shdr_sh_link(int elfclass, Pointer structPtr, int val);
-
-    static native void set_Shdr_sh_info(int elfclass, Pointer structPtr, int val);
-
-    static native void set_Data_d_align(Pointer structPtr, int val);
-
-    static native void set_Data_d_off(Pointer structPtr, int val);
-
-    static native void set_Data_d_buf(Pointer structPtr, Pointer val);
-
-    static native void set_Data_d_type(Pointer structPtr, int val);
-
-    static native void set_Data_d_size(Pointer structPtr, int val);
-
-    static native void set_Data_d_version(Pointer structPtr, int val);
-
-    static native long create_sym_entry(int elfclass, int index, int type, int bind, int shndx, int size, int value);
-
-    static native long create_reloc_entry(int elfclass, int roffset, int symtabIdx, int relocType, int raddend, int reloca);
-
-    /**
-     * File Operations.
-     */
-    static native int open_rw(String fileName);
-
-    static native int open(String fileName, int flags);
-
-    static native int open(String fileName, int flags, int mode);
-
-    static native int close(int fd);
-    // Checkstyle: resume method name check
-}
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.jnilibelf/src/jdk/tools/jaotc/jnilibelf/Pointer.java	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-/*
- * 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.
- */
-
-package jdk.tools.jaotc.jnilibelf;
-
-import jdk.internal.misc.Unsafe;
-
-import static jdk.tools.jaotc.jnilibelf.UnsafeAccess.UNSAFE;
-
-public class Pointer {
-
-    private final long address;
-
-    public Pointer(long val) {
-        address = val;
-    }
-
-    /**
-     * Put (i.e., copy) content of byte array at consecutive addresses beginning at this Pointer.
-     *
-     * @param src source byte array
-     */
-    public void put(byte[] src) {
-        UNSAFE.copyMemory(src, Unsafe.ARRAY_BYTE_BASE_OFFSET, null, address, src.length);
-    }
-
-    /**
-     * Get (i.e., copy) content at this Pointer to the given byte array.
-     *
-     * @param dst destination byte array
-     */
-    public void get(byte[] dst) {
-        UNSAFE.copyMemory(null, address, dst, Unsafe.ARRAY_BYTE_BASE_OFFSET, dst.length);
-    }
-
-    /**
-     * Read {@code readSize} number of bytes to copy them starting at {@code startIndex} of
-     * {@code byteArray}
-     *
-     * @param byteArray target array to copy bytes
-     * @param readSize number of bytes to copy
-     * @param startIndex index of the array to start copy at
-     */
-    public void copyBytesTo(byte[] byteArray, int readSize, int startIndex) {
-        long end = (long)startIndex + (long)readSize;
-        if (end > byteArray.length) {
-            throw new IllegalArgumentException("writing beyond array bounds");
-        }
-        UNSAFE.copyMemory(null, address, byteArray, Unsafe.ARRAY_BYTE_BASE_OFFSET+startIndex, readSize);
-    }
-
-}
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.jnilibelf/src/jdk/tools/jaotc/jnilibelf/UnsafeAccess.java	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * 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.
- */
-
-package jdk.tools.jaotc.jnilibelf;
-
-import jdk.internal.misc.Unsafe;
-
-/**
- * Package private access to the {@link Unsafe} capability.
- */
-class UnsafeAccess {
-
-    static final Unsafe UNSAFE = Unsafe.getUnsafe();
-
-}
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.jnilibelf/src/jdk/tools/jaotc/jnilibelf/linux/Elf_Cmd.java	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/*
- * 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.
- */
-
-package jdk.tools.jaotc.jnilibelf.linux;
-
-/**
- * Represent Elf_Cmd enums defined in libelf.h on Linux as they slightly different from libelf.h on
- * SunOS.
- */
-public enum Elf_Cmd {
-    /** Nothing, terminate, or compute only. */
-    ELF_C_NULL,
-
-    /** Read. */
-    ELF_C_READ,
-
-    /** Read and write. */
-    ELF_C_RDWR,
-
-    /** Write. */
-    ELF_C_WRITE,
-
-    /** Clear flag. */
-    ELF_C_CLR,
-
-    /** Set flag. */
-    ELF_C_SET,
-
-    /**
-     * Signal that file descriptor will not be used anymore.
-     */
-    ELF_C_FDDONE,
-
-    /**
-     * Read rest of data so that file descriptor is not used anymore.
-     */
-    ELF_C_FDREAD,
-
-    /* The following are extensions. */
-
-    /** Read, but mmap the file if possible. */
-    ELF_C_READ_MMAP,
-
-    /** Read and write, with mmap. */
-    ELF_C_RDWR_MMAP,
-
-    /** Write, with mmap. */
-    ELF_C_WRITE_MMAP,
-
-    /**
-     * Read, but memory is writable, results are not written to the file.
-     */
-    ELF_C_READ_MMAP_PRIVATE,
-
-    /** Copy basic file data but not the content. */
-    ELF_C_EMPTY,
-
-    /** Keep this the last entry. */
-    ELF_C_NUM;
-}
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.jnilibelf/src/jdk/tools/jaotc/jnilibelf/sunos/Elf_Cmd.java	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*
- * 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.
- */
-
-package jdk.tools.jaotc.jnilibelf.sunos;
-
-/**
- * Represent Elf_Cmd enums defined in libelf.h on SunOS as they slightly different from libelf.h on
- * Linux.
- */
-public enum Elf_Cmd {
-    /** Must be first, 0. */
-    ELF_C_NULL,
-
-    ELF_C_READ,
-    ELF_C_WRITE,
-    ELF_C_CLR,
-    ELF_C_SET,
-    ELF_C_FDDONE,
-    ELF_C_FDREAD,
-    ELF_C_RDWR,
-    ELF_C_WRIMAGE,
-    ELF_C_IMAGE,
-
-    /** Must be last. */
-    ELF_C_NUM
-
-}
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java	Thu Mar 16 16:40:41 2017 -0700
@@ -136,9 +136,6 @@
         @Override
         void process(Main task, String opt, String arg) {
             String name = arg;
-            if (name.endsWith(".so")) {
-                name = name.substring(0, name.length() - ".so".length());
-            }
             task.options.outputName = name;
         }
     }, new Option("  --class-name <class names> List of classes to compile", true, "--class-name", "--classname") {
@@ -234,6 +231,11 @@
         void process(Main task, String opt, String arg) {
             task.options.version = true;
         }
+    }, new Option("  --linker-path              Full path to linker executable", true, "--linker-path") {
+        @Override
+        void process(Main task, String opt, String arg) {
+            task.options.linkerpath = arg;
+        }
     }, new Option("  -J<flag>                   Pass <flag> directly to the runtime system", false, "-J") {
         @Override
         void process(Main task, String opt, String arg) {
@@ -242,9 +244,10 @@
 
     public static class Options {
         public List<SearchFor> files = new LinkedList<>();
-        public String outputName = "unnamed";
+        public String outputName = "unnamed.so";
         public String methodList;
         public List<ClassSource> sources = new ArrayList<>();
+        public String linkerpath = null;
         public SearchPath searchPath = new SearchPath();
 
         /**
@@ -347,6 +350,62 @@
         }
     }
 
+    /**
+     * Visual Studio supported versions
+     * Search Order is:  VS2013, VS2015, VS2012
+     */
+    public enum VSVERSIONS {
+        VS2013("VS120COMNTOOLS", "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin\\amd64\\link.exe"),
+        VS2015("VS140COMNTOOLS", "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\link.exe"),
+        VS2012("VS110COMNTOOLS", "C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\bin\\amd64\\link.exe");
+
+        private final String envvariable;
+        private final String wkp;
+
+        VSVERSIONS(String envvariable, String wellknownpath) {
+            this.envvariable = envvariable;
+            this.wkp = wellknownpath;
+        }
+
+        String EnvVariable()   { return envvariable; }
+        String WellKnownPath() { return wkp; }
+    }
+
+    /**
+     * Search for Visual Studio link.exe
+     * Search Order is:  VS2013, VS2015, VS2012
+     */
+    private static String getWindowsLinkPath() {
+        String link = "\\VC\\bin\\amd64\\link.exe";
+
+        /**
+         * First try searching the paths pointed to by
+         * the VS environment variables.
+         */
+        for (VSVERSIONS vs : VSVERSIONS.values()) {
+            String vspath = System.getenv(vs.EnvVariable());
+            if (vspath != null) {
+                File commonTools = new File(vspath);
+                File vsRoot = commonTools.getParentFile().getParentFile();
+                File linkPath = new File(vsRoot, link);
+                if (linkPath.exists()) return linkPath.getPath();
+            }
+        }
+
+        /**
+         * If we didn't find via the VS environment variables,
+         * try the well known paths
+         */
+        for (VSVERSIONS vs : VSVERSIONS.values()) {
+            String wkp = vs.WellKnownPath();
+            if (new File(wkp).exists()) {
+                return wkp;
+            }
+        }
+
+        return null;
+    }
+
     @SuppressWarnings("try")
     private boolean run() throws Exception {
         openLog();
@@ -451,8 +510,62 @@
                 System.gc();
             }
 
-            String objectFileName = options.outputName + ".o";
-            String libraryFileName = options.outputName + ".so";
+            String name = options.outputName;
+            String objectFileName = name;
+
+            // [TODO] The jtregs tests expect .so extension so don't
+            // override with platform specific file extension until the
+            // tests are fixed.
+            String libraryFileName = name;
+
+            String linkerCmd;
+            String linkerPath;
+            String osName = System.getProperty("os.name");
+
+            if (name.endsWith(".so")) {
+                objectFileName = name.substring(0, name.length() - ".so".length());
+            }
+            else if (name.endsWith(".dylib")) {
+                objectFileName = name.substring(0, name.length() - ".dylib".length());
+            }
+            else if (name.endsWith(".dll")) {
+                objectFileName = name.substring(0, name.length() - ".dll".length());
+            }
+
+            switch (osName) {
+                case "Linux":
+                    // libraryFileName = options.outputName + ".so";
+                    objectFileName = objectFileName + ".o";
+                    linkerPath = (options.linkerpath != null) ?  options.linkerpath : "ld";
+                    linkerCmd = linkerPath + " -shared -z noexecstack -o " + libraryFileName + " " + objectFileName;
+                    break;
+                case "SunOS":
+                    // libraryFileName = options.outputName + ".so";
+                    objectFileName = objectFileName + ".o";
+                    linkerPath = (options.linkerpath != null) ?  options.linkerpath : "ld";
+                    linkerCmd = linkerPath + " -shared -o " + libraryFileName + " " + objectFileName;
+                    break;
+                case "Mac OS X":
+                    // libraryFileName = options.outputName + ".dylib";
+                    objectFileName = objectFileName + ".o";
+                    linkerPath = (options.linkerpath != null) ?  options.linkerpath : "ld";
+                    linkerCmd = linkerPath + " -dylib -o " + libraryFileName + " " + objectFileName;
+                    break;
+                default:
+                    if (osName.startsWith("Windows")) {
+                        // libraryFileName = options.outputName + ".dll";
+                        objectFileName = objectFileName + ".obj";
+                        linkerPath = (options.linkerpath != null) ?
+                            options.linkerpath : getWindowsLinkPath();
+                        if (linkerPath == null) {
+                            throw new InternalError("Can't locate Microsoft Visual Studio amd64 link.exe");
+                        }
+                        linkerCmd = linkerPath + " /DLL /OPT:NOREF /NOLOGO /NOENTRY" + " /OUT:" + libraryFileName + " " + objectFileName;
+                        break;
+                    }
+                    else
+                        throw new InternalError("Unsupported platform: " + osName);
+            }
 
             try (Timer t = new Timer(this, "Creating binary: " + objectFileName)) {
                 binaryContainer.createBinary(objectFileName, JVM_VERSION);
@@ -466,7 +579,7 @@
             }
 
             try (Timer t = new Timer(this, "Creating shared library: " + libraryFileName)) {
-                Process p = Runtime.getRuntime().exec("ld -shared -z noexecstack -o " + libraryFileName + " " + objectFileName);
+                Process p = Runtime.getRuntime().exec(linkerCmd);
                 final int exitCode = p.waitFor();
                 if (exitCode != 0) {
                     InputStream stderr = p.getErrorStream();
@@ -484,7 +597,7 @@
                 }
                 // Make non-executable for all.
                 File libFile = new File(libraryFileName);
-                if (libFile.exists()) {
+                if (libFile.exists() && !osName.startsWith("Windows")) {
                     if (!libFile.setExecutable(false, false)) {
                         throw new InternalError("Failed to change attribute for " + libraryFileName + " file");
                     }
--- a/hotspot/src/jdk.aot/unix/native/libjelfshim/jdk_tools_jaotc_jnilibelf_JNILibELFAPI.c	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,526 +0,0 @@
-/*
- * 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 "jdk_tools_jaotc_jnilibelf_JNILibELFAPI.h"
-
-// For file open and close
-#include <fcntl.h>
-#include <unistd.h>
-#include <err.h>
-#include <sysexits.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <assert.h>
-
-// For libelf interfaces
-#include <libelf.h>
-#include <gelf.h>
-
-// Convenience macro to shut the compiler warnings
-#ifdef UNUSED
-#elif defined(__GNUC__)
-# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
-#elif defined(__LCLINT__)
-# define UNUSED(x) /*@unused@*/ x
-#else
-# define UNUSED(x) x
-#endif
-
-/**
- * libelfshim version
- */
-#ifndef AOT_VERSION_STRING
-  #error AOT_VERSION_STRING must be defined
-#endif
-
-JNIEXPORT jstring JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elfshim_1version
-(JNIEnv* env, jclass UNUSED(c))  {
-   const char* ver = AOT_VERSION_STRING;
-   return (*env)->NewStringUTF(env, ver);
-}
-
-JNIEXPORT jint JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf_1version
-(JNIEnv* UNUSED(env), jclass UNUSED(c), jint v)  {
-    return elf_version(v);
-}
-
-/**
- * Unbox the Pointer object the encapsulated native address.
- */
-
-static jlong getNativeAddress(JNIEnv* env, jobject ptrObj) {
-   jlong nativeAddress = -1;
-   assert (ptrObj != NULL);
-   // Get a reference to ptr object's class
-   jclass ptrClass = (*env)->GetObjectClass(env, ptrObj);
-   if (ptrClass != NULL) {
-       // Get the Field ID of the instance variables "address"
-       jfieldID fidNumber = (*env)->GetFieldID(env, ptrClass, "address", "J");
-       if (fidNumber != NULL) {
-           // Get the long given the Field ID
-           nativeAddress = (*env)->GetLongField(env, ptrObj, fidNumber);
-       }
-   }
-   // fprintf(stderr, "Native address : %lx\n", nativeAddress);
-   return nativeAddress;
-}
-
-/**
- * Box the nativeAddress as a Pointer object.
- */
-static jobject makePointerObject(JNIEnv* env, jlong nativeAddr) {
-   jobject retObj = NULL;
-   jclass ptrClass = (*env)->FindClass(env, "jdk/tools/jaotc/jnilibelf/Pointer");
-   if (ptrClass != NULL) {
-       // Call back constructor to allocate a Pointer object, with an int argument
-       jmethodID constructorId = (*env)->GetMethodID(env, ptrClass, "<init>", "(J)V");
-       if (constructorId != NULL) {
-           retObj = (*env)->NewObject(env, ptrClass, constructorId, nativeAddr);
-       }
-   }
-   return retObj;
-}
-
-JNIEXPORT jobject JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf_1begin
-(JNIEnv* env, jclass UNUSED(class), jint filedes, jint cmd, jobject ptrObj) {
-
-   Elf* elfPtr = NULL;
-   jlong addr = getNativeAddress(env, ptrObj);
-
-   if (addr != -1) {
-       // Call libelf function
-       if ((elfPtr = elf_begin(filedes, cmd, (Elf *) addr)) == NULL) {
-           errx(EX_SOFTWARE, "elf_begin() failed: %s.", elf_errmsg(-1));
-       }
-   } else {
-       fprintf(stderr, "Failed to get native address to call elf_begin()\n");
-   }
-
-   return makePointerObject(env, (jlong) elfPtr);
-}
-
-JNIEXPORT jint JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf_1end
-(JNIEnv* env, jclass UNUSED(class), jobject ptrObj) {
-
-   jlong addr = getNativeAddress(env, ptrObj);
-
-   if (addr != -1) {
-       // Call libelf function
-       return elf_end((Elf *) addr);
-   } else {
-       fprintf(stderr, "Failed to get native address to call elf_end()\n");
-       return -1;
-   }
-}
-
-JNIEXPORT jint JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf_1kind
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj) {
-   jlong addr = getNativeAddress(env, ptrObj);
-
-   if (addr != -1) {
-       // Call libelf function
-       return elf_kind((Elf *) addr);
-   } else {
-       fprintf(stderr, "Failed to get native address to call elf_kind()\n");
-       return -1;
-   }
-}
-JNIEXPORT jint JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf_1flagphdr
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj, jint cmd, jint flags) {
-
-   jlong addr = getNativeAddress(env, ptrObj);
-   unsigned int retVal = 0;
-
-   if (addr != -1) {
-       // Call libelf function
-       if ((retVal = elf_flagphdr((Elf *) addr, cmd, flags)) == 0) {
-           errx(EX_SOFTWARE, "elf_flagphdr() failed: %s.", elf_errmsg(-1));
-       }
-   } else {
-       fprintf(stderr, "Failed to get native address to call elf_flagphdr()\n");
-   }
-   return retVal;
-}
-
-JNIEXPORT jobject JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf_1newscn
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj) {
-
-   Elf_Scn* elfSecPtr = NULL;
-   jlong addr = getNativeAddress(env, ptrObj);
-
-   if (addr != -1) {
-       // Call libelf function
-       if ((elfSecPtr = elf_newscn((Elf *) addr)) == NULL) {
-           errx(EX_SOFTWARE, "elf_newscn() failed: %s.", elf_errmsg(-1));
-       }
-   } else {
-       fprintf(stderr, "Failed to get native address to call elf_newscn()\n");
-   }
-
-   return makePointerObject(env, (jlong) elfSecPtr);
-}
-
-JNIEXPORT jobject JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf_1newdata
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj) {
-
-   Elf_Data* elfDataPtr = NULL;
-   jlong addr = getNativeAddress(env, ptrObj);
-
-   if (addr != -1) {
-       // Call libelf function
-       if ((elfDataPtr = elf_newdata((Elf_Scn *) addr)) == NULL) {
-           errx(EX_SOFTWARE, "elf_newdata() failed: %s.", elf_errmsg(-1));
-       }
-   } else {
-       fprintf(stderr, "Failed to get native address to call elf_newdata()\n");
-   }
-   return makePointerObject(env, (jlong) elfDataPtr);
-}
-
-JNIEXPORT jobject JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf64_1getshdr
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj) {
-
-   Elf64_Shdr* elf64ShdrPtr = NULL;
-   jlong addr = getNativeAddress(env, ptrObj);
-
-   if (addr != -1) {
-       // Call libelf function
-       if ((elf64ShdrPtr = elf64_getshdr((Elf_Scn *) addr)) == NULL) {
-           errx(EX_SOFTWARE, "elf64_getshdr() failed: %s.", elf_errmsg(-1));
-       }
-   } else {
-       fprintf(stderr, "Failed to get native address to call elf_getshdr()\n");
-   }
-   return makePointerObject(env, (jlong) elf64ShdrPtr);
-}
-
-JNIEXPORT jlong JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf_1update
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj, jint cmd) {
-
-   off_t size = -1;
-   jlong addr = getNativeAddress(env, ptrObj);
-
-   if (addr != -1) {
-       // Call libelf function
-       if ((size = elf_update((Elf*) addr, cmd)) == -1) {
-           errx(EX_SOFTWARE, "elf_update() failed: %s size (%d) cmd (%d).", elf_errmsg(-1), (int)size, cmd);
-       }
-   } else {
-       fprintf(stderr, "Failed to get native address to call elf_update()\n");
-   }
-   return size;
-}
-
-JNIEXPORT jstring JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf_1errmsg
-(JNIEnv* env, jclass UNUSED(c), jint errno) {
-
-   const char * retPtr = NULL;
-   // Call libelf function
-   if ((retPtr = elf_errmsg(errno)) == NULL) {
-       errx(EX_SOFTWARE, "elf_errmsg() failed: %s.", elf_errmsg(-1));
-   }
-   return (*env)->NewStringUTF(env, retPtr);
-}
-
-JNIEXPORT jint JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf_1ndxscn
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj) {
-   jint secnum = SHN_UNDEF;
-   jlong addr = getNativeAddress(env, ptrObj);
-   if (addr != -1) {
-       // Call libelf function
-       secnum = elf_ndxscn((Elf_Scn*) addr);
-   } else {
-       fprintf(stderr, "Failed to get native address to call elf_ndxscn()\n");
-   }
-   return secnum;
-}
-
-JNIEXPORT jobject JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_gelf_1newehdr
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj, jint elfClass) {
-   unsigned long int retPtr = 0;
-   jlong addr = getNativeAddress(env, ptrObj);
-   if (addr != -1) {
-       // Call libelf function
-       if ((retPtr = gelf_newehdr((Elf*) addr, elfClass)) == 0) {
-           errx(EX_SOFTWARE, "gelf_newehdr() failed: %s.", elf_errmsg(-1));
-       }
-   } else {
-       fprintf(stderr, "Failed to get native address to call elf_newehdr()\n");
-   }
-   return makePointerObject(env, (jlong) retPtr);
-}
-
-JNIEXPORT jobject JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_gelf_1newphdr
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj, jint phnum) {
-   unsigned long int retPtr = 0;
-   jlong addr = getNativeAddress(env, ptrObj);
-   if (addr != -1) {
-       // Call libelf function
-       if ((retPtr = gelf_newphdr((Elf*) addr, phnum)) == 0) {
-           errx(EX_SOFTWARE, "gelf_newphdr() failed: %s.", elf_errmsg(-1));
-       }
-   } else {
-       fprintf(stderr, "Failed to get native address to call elf_newphdr()\n");
-   }
-   return makePointerObject(env, (jlong) retPtr);
-}
-
-
-/* File operations */
-
-JNIEXPORT jint JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_open_1rw
-(JNIEnv * env, jclass UNUSED(class), jstring jfileName)  {
-    int flags = O_RDWR | O_CREAT | O_TRUNC;
-    int mode  = 0666;
-    int retVal;
-    const char* cfileName = (*env)->GetStringUTFChars(env, jfileName, NULL);
-    if (cfileName == NULL) {
-        return -1;
-    }
-    retVal = open(cfileName, flags, mode);
-    if (retVal < 0) {
-       err(EX_NOINPUT, "open %s failed", cfileName);
-    }
-    (*env)->ReleaseStringUTFChars(env, jfileName, cfileName);
-
-    return retVal;
-}
-
-JNIEXPORT jint JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_open__Ljava_lang_String_2I
-(JNIEnv * env, jclass UNUSED(class), jstring jfileName, jint flags)  {
-    int retVal;
-    const char* cfileName = (*env)->GetStringUTFChars(env, jfileName, NULL);
-    if (cfileName == NULL) {
-        return -1;
-    }
-    retVal = open(cfileName, flags);
-    if (retVal < 0) {
-       err(EX_NOINPUT, "open %s failed", cfileName);
-    }
-    (*env)->ReleaseStringUTFChars(env, jfileName, cfileName);
-
-    return retVal;
-}
-
-JNIEXPORT jint JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_open__Ljava_lang_String_2II
-(JNIEnv * env, jclass UNUSED(class), jstring jfileName, jint flags, jint mode)  {
-    int retVal;
-    const char* cfileName = (*env)->GetStringUTFChars(env, jfileName, NULL);
-    if (cfileName == NULL) {
-        return -1;
-    }
-    retVal = open(cfileName, flags, mode);
-    if (retVal < 0) {
-       err(EX_NOINPUT, "open %s failed", cfileName);
-    }
-    (*env)->ReleaseStringUTFChars(env, jfileName, cfileName);
-
-    return retVal;
-}
-
-
-JNIEXPORT jint JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_close
-(JNIEnv* UNUSED(env), jclass UNUSED(class), jint fd) {
-    return close(fd);
-}
-
-/**
- * Miscellaneous ELF data structure peek-poke functions in
- * shim_functions.c. No corresponding .h file exists yet.
- * So each function needs to be declared as extern
- */
-
-extern int size_of_Sym(int elfclass);
-extern int size_of_Rel(int elfclass);
-extern int size_of_Rela(int elfclass);
-
-extern void ehdr_set_data_encoding(void * ehdr, int val);
-extern void set_Ehdr_e_machine(int elfclass, void * structPtr, int val);
-extern void set_Ehdr_e_type(int elfclass, void * structPtr, int val);
-extern void set_Ehdr_e_version(int elfclass, void * structPtr, int val);
-extern void set_Ehdr_e_shstrndx(int elfclass, void * structPtr, int val);
-
-extern void phdr_set_type_self(int elfclass, void * ehdr, void * phdr);
-extern void phdr_set_type_self(int elfclass, void * ehdr, void * phdr);
-
-extern void set_Shdr_sh_name(int elfclass, void* structPtr, int val);
-extern void set_Shdr_sh_type(int elfclass, void* structPtr, int val);
-extern void set_Shdr_sh_flags(int elfclass, void* structPtr, int val);
-extern void set_Shdr_sh_entsize(int elfclass, void* structPtr, int val);
-extern void set_Shdr_sh_link(int elfclass, void* structPtr, int val);
-extern void set_Shdr_sh_info(int elfclass, void* structPtr, int val);
-
-extern void set_Data_d_align(void* structPtr, int val);
-extern void set_Data_d_off(void* structPtr, int val);
-extern void set_Data_d_buf(void* structPtr, void* val);
-extern void set_Data_d_type(void* structPtr, int val);
-extern void set_Data_d_size(void* structPtr, int val);
-extern void set_Data_d_version(void* structPtr, int val);
-
-extern void* create_sym_entry(int elfclass, int index, int type, int bind,
-                               int shndx, int size, int value);
-extern void * create_reloc_entry(int elfclass, int roffset, int symtabIdx,
-                                 int relocType, int raddend, int reloca);
-
-JNIEXPORT jint JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_size_1of_1Sym
-(JNIEnv* UNUSED(env), jclass UNUSED(c), jint elfClass) {
-    return size_of_Sym(elfClass);
-}
-
-JNIEXPORT jint JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_size_1of_1Rela
-(JNIEnv* UNUSED(env), jclass UNUSED(c), jint elfClass) {
-    return size_of_Rela(elfClass);
-}
-
-JNIEXPORT jint JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_size_1of_1Rel
-(JNIEnv* UNUSED(env), jclass UNUSED(c), jint elfClass) {
-    return size_of_Rel(elfClass);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_ehdr_1set_1data_1encoding
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj, jint val) {
-    void* ehdr = (void*) getNativeAddress(env, ptrObj);
-    ehdr_set_data_encoding(ehdr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Ehdr_1e_1machine
-(JNIEnv* env, jclass UNUSED(c), jint elfClass, jobject ptrObj, jint val) {
-    void* ehdr = (void*) getNativeAddress(env, ptrObj);
-    set_Ehdr_e_machine(elfClass, ehdr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Ehdr_1e_1type
-(JNIEnv* env, jclass UNUSED(c), jint elfClass, jobject ptrObj, jint val) {
-    void* ehdr = (void*) getNativeAddress(env, ptrObj);
-    set_Ehdr_e_type(elfClass, ehdr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Ehdr_1e_1version
-(JNIEnv* env, jclass UNUSED(c), jint elfClass, jobject ptrObj, jint val) {
-    void* ehdr = (void*) getNativeAddress(env, ptrObj);
-    set_Ehdr_e_version(elfClass, ehdr, val);
-}
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Ehdr_1e_1shstrndx
-(JNIEnv* env, jclass UNUSED(c), jint elfClass, jobject ptrObj, jint val) {
-    void* shdr = (void*) getNativeAddress(env, ptrObj);
-    set_Ehdr_e_shstrndx(elfClass, shdr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_phdr_1set_1type_1self
-(JNIEnv* env, jclass UNUSED(c), jint elfClass, jobject ehdrPtr, jobject phdrPtr) {
-    void* ehdr = (void*) getNativeAddress(env, ehdrPtr);
-    void* phdr = (void*) getNativeAddress(env, phdrPtr);
-    phdr_set_type_self(elfClass, ehdr, phdr);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Shdr_1sh_1name
-(JNIEnv* env, jclass UNUSED(c), jint elfClass, jobject ptrObj, jint val) {
-    void* shdr = (void*) getNativeAddress(env, ptrObj);
-    set_Shdr_sh_name(elfClass, shdr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Shdr_1sh_1type
-(JNIEnv* env, jclass UNUSED(c), jint elfClass, jobject ptrObj, jint val) {
-    void* shdr = (void*) getNativeAddress(env, ptrObj);
-    set_Shdr_sh_type(elfClass, shdr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Shdr_1sh_1flags
-(JNIEnv* env, jclass UNUSED(c), jint elfClass, jobject ptrObj, jint val) {
-    void* shdr = (void*) getNativeAddress(env, ptrObj);
-    set_Shdr_sh_flags(elfClass, shdr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Shdr_1sh_1entsize
-(JNIEnv* env, jclass UNUSED(c), jint elfClass, jobject ptrObj, jint val) {
-    void* shdr = (void*) getNativeAddress(env, ptrObj);
-    set_Shdr_sh_entsize(elfClass, shdr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Shdr_1sh_1info
-(JNIEnv* env, jclass UNUSED(c), jint elfClass, jobject ptrObj, jint val) {
-    void* shdr = (void*) getNativeAddress(env, ptrObj);
-    set_Shdr_sh_info(elfClass, shdr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Shdr_1sh_1link
-(JNIEnv* env, jclass UNUSED(c), jint elfClass, jobject ptrObj, jint val) {
-    void* shdr = (void*) getNativeAddress(env, ptrObj);
-    set_Shdr_sh_link(elfClass, shdr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Data_1d_1align
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj, jint val) {
-    void* dptr = (void*) getNativeAddress(env, ptrObj);
-    set_Data_d_align(dptr, val);
-}
-
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Data_1d_1off
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj, jint val) {
-    void* dptr = (void*) getNativeAddress(env, ptrObj);
-    set_Data_d_off(dptr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Data_1d_1buf
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj, jobject bufPtr) {
-    void* dptr = (void*) getNativeAddress(env, ptrObj);
-    void* bptr = (void*) getNativeAddress(env, bufPtr);
-    set_Data_d_buf(dptr, bptr);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Data_1d_1type
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj, jint val) {
-    void* dptr = (void*) getNativeAddress(env, ptrObj);
-    set_Data_d_type(dptr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Data_1d_1size
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj, jint val) {
-    void* dptr = (void*) getNativeAddress(env, ptrObj);
-    set_Data_d_size(dptr, val);
-}
-
-JNIEXPORT void JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_set_1Data_1d_1version
-(JNIEnv* env, jclass UNUSED(c), jobject ptrObj, jint val) {
-    void* dptr = (void*) getNativeAddress(env, ptrObj);
-    set_Data_d_version(dptr, val);
-}
-
-JNIEXPORT jlong JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_create_1sym_1entry
-(JNIEnv* UNUSED(env), jclass UNUSED(c), jint elfClass, jint index, jint type,
- jint bind, jint shndx, jint size, jint value) {
-   void * retVal = create_sym_entry(elfClass, index, type, bind,
-                                    shndx, size, value);
-   return (jlong)retVal;
-}
-
-JNIEXPORT jlong JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_create_1reloc_1entry
-(JNIEnv* UNUSED(env), jclass UNUSED(c), jint elfClass, jint roffset,
- jint symTabIdx, jint relocType, jint raddend, jint reloca) {
-   void * retVal = create_reloc_entry(elfClass, roffset, symTabIdx,
-                                      relocType, raddend, reloca);
-   return (jlong)retVal;
-}
-
--- a/hotspot/src/jdk.aot/unix/native/libjelfshim/shim_functions.c	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,226 +0,0 @@
-/*
- * 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 <libelf.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-/**
- * TODO: This is an intial and crude attempt to access structure
- * fields of some ELF structrures. Need to figure out a way to access the
- * given field of a given structure instead of writing one shim function
- * per access of each of the structure field.
- **/
-
-#define STRINGIFYHELPER(x) #x
-#define STRINGIFY(x) STRINGIFYHELPER(x)
-#define FUNC_NAME(S, F) set_ ## S ## _ ## F
-#define CAST_STRUCT(S, F) ((Elf_ ## S *) structPtr)
-#define CAST_STRUCT32(S, F) ((Elf32_ ## S *) structPtr)
-#define CAST_STRUCT64(S, F) ((Elf64_ ## S *) structPtr)
-#define ACCESS_FIELD(S, F) CAST_STRUCT(S, F)-> F
-#define ACCESS_FIELD32(S, F) CAST_STRUCT32(S, F)-> F
-#define ACCESS_FIELD64(S, F) CAST_STRUCT64(S, F)-> F
-
-/*
-   Example:
-   SET_TYPE_BASED_FIELD(Ehdr, e_machine, int)
-   expands to
-   set_Ehdr_e_machine(int elfclass, void * strPtr, int val) {
-}
-*/
-
-#define SET_TYPE_BASED_FIELD(S, F, T)                               \
-    void FUNC_NAME(S, F)(int elfclass, void * structPtr, T val) {   \
-       if (elfclass == ELFCLASS32)  {                               \
-           ACCESS_FIELD32(S, F) = val;                    \
-       } else if (elfclass == ELFCLASS64) {               \
-           ACCESS_FIELD64(S, F) = val;                    \
-       } else {                                           \
-           printf("%s: Unknown ELF Class %d provided\n", STRINGIFY(FUNC_NAME(S, F)), elfclass); \
-    }  \
-    return; \
-}
-
-/*
-   Example:
-   SET_FIELD(Ehdr, e_machine, int)
-   expands to
-   set_Ehdr_e_machine(void * strPtr, int val) {
-}
-*/
-
-#define SET_FIELD(S, F, T)                               \
-    void FUNC_NAME(S, F)(void * structPtr, T val) {      \
-       ACCESS_FIELD(S, F) = val;                         \
-       return; \
-}
-
-int size_of_Sym(int elfclass) {
-    if (elfclass == ELFCLASS32)  {
-        return sizeof(Elf32_Sym);
-    } else if (elfclass == ELFCLASS64) {
-        return sizeof(Elf64_Sym);
-    } else {
-        printf("Unknown ELF Class %d provided\n", elfclass);
-    }
-    return -1;
-}
-
-int size_of_Rela(int elfclass) {
-    if (elfclass == ELFCLASS32)  {
-        return sizeof(Elf32_Rela);
-    } else if (elfclass == ELFCLASS64) {
-        return sizeof(Elf64_Rela);
-    } else {
-        printf("Unknown ELF Class %d provided\n", elfclass);
-    }
-    return -1;
-}
-
-int size_of_Rel(int elfclass) {
-    if (elfclass == ELFCLASS32)  {
-        return sizeof(Elf32_Rel);
-    } else if (elfclass == ELFCLASS64) {
-        return sizeof(Elf64_Rel);
-    } else {
-        printf("Unknown ELF Class %d provided\n", elfclass);
-    }
-    return -1;
-}
-
-/* ELF Header field access */
-
-void ehdr_set_data_encoding(void * ehdr, int val)  {
-    ((Elf32_Ehdr *) ehdr)->e_ident[EI_DATA] = val;
-    return;
-}
-
-SET_TYPE_BASED_FIELD(Ehdr, e_machine, int)
-SET_TYPE_BASED_FIELD(Ehdr, e_type, int)
-SET_TYPE_BASED_FIELD(Ehdr, e_version, int)
-SET_TYPE_BASED_FIELD(Ehdr, e_shstrndx, int)
-
-/* Data descriptor field access */
-SET_FIELD(Data, d_align, int)
-SET_FIELD(Data, d_off, int)
-SET_FIELD(Data, d_buf, void*)
-SET_FIELD(Data, d_type, int)
-SET_FIELD(Data, d_size, int)
-SET_FIELD(Data, d_version, int)
-
-/* Section Header Access functions */
-SET_TYPE_BASED_FIELD(Shdr, sh_name, int)
-SET_TYPE_BASED_FIELD(Shdr, sh_type, int)
-SET_TYPE_BASED_FIELD(Shdr, sh_flags, int)
-SET_TYPE_BASED_FIELD(Shdr, sh_entsize, int)
-SET_TYPE_BASED_FIELD(Shdr, sh_link, int)
-SET_TYPE_BASED_FIELD(Shdr, sh_info, int)
-
-/* Set the Program Header to be of PH_PHDR type and initialize other
-   related fields of the program header.
-*/
-void phdr_set_type_self(int elfclass, void * ehdr, void * phdr)  {
-    if (elfclass == ELFCLASS32) {
-        Elf32_Ehdr * ehdr32 = (Elf32_Ehdr *) ehdr;
-        Elf32_Phdr * phdr32 = (Elf32_Phdr *) phdr;
-        phdr32->p_type = PT_PHDR;
-        phdr32->p_offset = ehdr32->e_phoff;
-        phdr32->p_filesz = elf32_fsize(ELF_T_PHDR, 1, EV_CURRENT);
-    } else if (elfclass == ELFCLASS64) {
-        Elf64_Ehdr * ehdr64 = (Elf64_Ehdr *) ehdr;
-        Elf64_Phdr * phdr64 = (Elf64_Phdr *) phdr;
-        phdr64->p_type = PT_PHDR;
-        phdr64->p_offset = ehdr64->e_phoff;
-        phdr64->p_filesz = elf64_fsize(ELF_T_PHDR, 1, EV_CURRENT);
-    } else {
-        printf("phdr_set_type_self: Unknown ELF Class %d provided\n", elfclass);
-    }
-    return;
-}
-
-/*
-  Create symbol table entry with given type and binding
-*/
-void * create_sym_entry(int elfclass, int index, int type, int bind,
-                        int shndx, int size, int value) {
-  void * symentry = NULL;
-    if (elfclass == ELFCLASS32) {
-      Elf32_Sym * sym32 = (Elf32_Sym *) malloc(sizeof(Elf32_Sym));
-      sym32->st_name = index;
-      sym32->st_value = value;
-      sym32->st_size = size;
-      sym32->st_info = ELF32_ST_INFO(bind, type);
-      sym32->st_other = 0;  // TODO: Add an argument to get this value ??
-      sym32->st_shndx = shndx;
-      symentry = sym32;
-    } else if (elfclass == ELFCLASS64) {
-      Elf64_Sym * sym64 = (Elf64_Sym *) malloc(sizeof(Elf64_Sym));
-      sym64->st_name = index;
-      sym64->st_value = value;
-      sym64->st_size = size;
-      sym64->st_info = ELF64_ST_INFO(bind, type);
-      sym64->st_other = 0;  // TODO: Add an argument to get this value ??
-      sym64->st_shndx = shndx;
-      symentry = sym64;
-    } else {
-        printf("create_sym_entry: Unknown ELF Class %d provided\n", elfclass);
-    }
-    return (void *) symentry;
-}
-
-// Create a reloc (or reloca entry if argument reloca is non-zero)
-void * create_reloc_entry(int elfclass, int roffset, int symtabIdx,
-                          int relocType, int raddend, int reloca) {
-  void * relocentry = NULL;
-  if (elfclass == ELFCLASS32) {
-    if (reloca) {
-      Elf32_Rela * rela32 = (Elf32_Rela *) malloc(sizeof(Elf32_Rela));
-      rela32->r_offset = roffset;
-      rela32->r_info = ELF32_R_INFO(symtabIdx, relocType);
-      rela32->r_addend = raddend;
-      relocentry = rela32;
-    } else {
-      Elf32_Rel * rel32 = (Elf32_Rel *) malloc(sizeof(Elf32_Rel));
-      rel32->r_offset = roffset;
-      rel32->r_info = ELF32_R_INFO(symtabIdx, relocType);
-      relocentry = rel32;
-    }
-  } else if (elfclass == ELFCLASS64) {
-    if (reloca) {
-      Elf64_Rela * rela64 = (Elf64_Rela *) malloc(sizeof(Elf64_Rela));
-      rela64->r_offset = roffset;
-      rela64->r_info = ELF64_R_INFO(symtabIdx, relocType);
-      rela64->r_addend = raddend;
-      relocentry = rela64;
-    } else {
-      Elf64_Rel * rel64 = (Elf64_Rel *) malloc(sizeof(Elf64_Rel));
-      rel64->r_offset = roffset;
-      rel64->r_info = ELF64_R_INFO(symtabIdx, relocType);
-      relocentry = rel64;
-    }
-  } else {
-    printf("create_reloc_entry: Unknown ELF Class %d provided\n", elfclass);
-  }
-  return (void *) relocentry;
-}
--- a/hotspot/src/os/aix/vm/os_aix.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os/aix/vm/os_aix.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1576,7 +1576,7 @@
   Dl_info dlinfo;
   int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
   assert(ret != 0, "cannot locate libjvm");
-  char* rp = realpath((char *)dlinfo.dli_fname, buf);
+  char* rp = os::Posix::realpath((char *)dlinfo.dli_fname, buf, buflen);
   assert(rp != NULL, "error in realpath(): maybe the 'path' argument is too long?");
 
   strncpy(saved_jvm_path, buf, sizeof(saved_jvm_path));
--- a/hotspot/src/os/bsd/vm/os_bsd.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os/bsd/vm/os_bsd.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1754,7 +1754,7 @@
   assert(ret, "cannot locate libjvm");
   char *rp = NULL;
   if (ret && dli_fname[0] != '\0') {
-    rp = realpath(dli_fname, buf);
+    rp = os::Posix::realpath(dli_fname, buf, buflen);
   }
   if (rp == NULL) {
     return;
@@ -1786,7 +1786,7 @@
         p = strrchr(buf, '/');
         assert(strstr(p, "/libjvm") == p, "invalid library name");
 
-        rp = realpath(java_home_var, buf);
+        rp = os::Posix::realpath(java_home_var, buf, buflen);
         if (rp == NULL) {
           return;
         }
@@ -1820,7 +1820,7 @@
           snprintf(buf + len, buflen-len, "/libjvm%s", JNI_LIB_SUFFIX);
         } else {
           // Fall back to path of current library
-          rp = realpath(dli_fname, buf);
+          rp = os::Posix::realpath(dli_fname, buf, buflen);
           if (rp == NULL) {
             return;
           }
--- a/hotspot/src/os/linux/vm/os_linux.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os/linux/vm/os_linux.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -2318,7 +2318,7 @@
   assert(ret, "cannot locate libjvm");
   char *rp = NULL;
   if (ret && dli_fname[0] != '\0') {
-    rp = realpath(dli_fname, buf);
+    rp = os::Posix::realpath(dli_fname, buf, buflen);
   }
   if (rp == NULL) {
     return;
@@ -2352,7 +2352,7 @@
         }
         assert(strstr(p, "/libjvm") == p, "invalid library name");
 
-        rp = realpath(java_home_var, buf);
+        rp = os::Posix::realpath(java_home_var, buf, buflen);
         if (rp == NULL) {
           return;
         }
@@ -2373,7 +2373,7 @@
           snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
         } else {
           // Go back to path of .so
-          rp = realpath(dli_fname, buf);
+          rp = os::Posix::realpath(dli_fname, buf, buflen);
           if (rp == NULL) {
             return;
           }
--- a/hotspot/src/os/posix/vm/os_posix.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os/posix/vm/os_posix.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1105,6 +1105,48 @@
   return buf;
 }
 
+char* os::Posix::realpath(const char* filename, char* outbuf, size_t outbuflen) {
+
+  if (filename == NULL || outbuf == NULL || outbuflen < 1) {
+    assert(false, "os::Posix::realpath: invalid arguments.");
+    errno = EINVAL;
+    return NULL;
+  }
+
+  char* result = NULL;
+
+  // This assumes platform realpath() is implemented according to POSIX.1-2008.
+  // POSIX.1-2008 allows to specify NULL for the output buffer, in which case
+  // output buffer is dynamically allocated and must be ::free()'d by the caller.
+  char* p = ::realpath(filename, NULL);
+  if (p != NULL) {
+    if (strlen(p) < outbuflen) {
+      strcpy(outbuf, p);
+      result = outbuf;
+    } else {
+      errno = ENAMETOOLONG;
+    }
+    ::free(p); // *not* os::free
+  } else {
+    // Fallback for platforms struggling with modern Posix standards (AIX 5.3, 6.1). If realpath
+    // returns EINVAL, this may indicate that realpath is not POSIX.1-2008 compatible and
+    // that it complains about the NULL we handed down as user buffer.
+    // In this case, use the user provided buffer but at least check whether realpath caused
+    // a memory overwrite.
+    if (errno == EINVAL) {
+      outbuf[outbuflen - 1] = '\0';
+      p = ::realpath(filename, outbuf);
+      if (p != NULL) {
+        guarantee(outbuf[outbuflen - 1] == '\0', "realpath buffer overwrite detected.");
+        result = p;
+      }
+    }
+  }
+  return result;
+
+}
+
+
 // Check minimum allowable stack sizes for thread creation and to initialize
 // the java system classes, including StackOverflowError - depends on page
 // size.
--- a/hotspot/src/os/posix/vm/os_posix.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os/posix/vm/os_posix.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -96,6 +96,13 @@
   // to buf with len buflen; buf is returned.
   static char* describe_pthread_attr(char* buf, size_t buflen, const pthread_attr_t* attr);
 
+  // A safe implementation of realpath which will not cause a buffer overflow if the resolved path
+  //   is longer than PATH_MAX.
+  // On success, returns 'outbuf', which now contains the path.
+  // On error, it will return NULL and set errno. The content of 'outbuf' is undefined.
+  // On truncation error ('outbuf' too small), it will return NULL and set errno to ENAMETOOLONG.
+  static char* realpath(const char* filename, char* outbuf, size_t outbuflen);
+
 };
 
 /*
--- a/hotspot/src/os/posix/vm/vmError_posix.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os/posix/vm/vmError_posix.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -59,6 +59,21 @@
 static int resettedSigflags[NUM_SIGNALS];
 static address resettedSighandler[NUM_SIGNALS];
 
+// Needed for cancelable steps.
+static volatile pthread_t reporter_thread_id;
+
+void VMError::reporting_started() {
+  // record pthread id of reporter thread.
+  reporter_thread_id = ::pthread_self();
+}
+
+void VMError::interrupt_reporting_thread() {
+  // We misuse SIGILL here, but it does not really matter. We need
+  //  a signal which is handled by crash_handler and not likely to
+  //  occurr during error reporting itself.
+  ::pthread_kill(reporter_thread_id, SIGILL);
+}
+
 static void save_signal(int idx, int sig)
 {
   struct sigaction sa;
--- a/hotspot/src/os/solaris/vm/jvm_solaris.h	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os/solaris/vm/jvm_solaris.h	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -85,7 +85,7 @@
 /* Signal definitions */
 
 #define BREAK_SIGNAL     SIGQUIT           /* Thread dumping support.    */
-#define ASYNC_SIGNAL     SIGUSR2           /* Watcher & async err support. */
+#define ASYNC_SIGNAL     SIGJVM2           /* Event-based suspend/resume support */
 #define SHUTDOWN1_SIGNAL SIGHUP            /* Shutdown Hooks support.    */
 #define SHUTDOWN2_SIGNAL SIGINT
 #define SHUTDOWN3_SIGNAL SIGTERM
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1013,21 +1013,9 @@
   return true;
 }
 
-// defined for >= Solaris 10. This allows builds on earlier versions
-// of Solaris to take advantage of the newly reserved Solaris JVM signals.
-// With SIGJVM1, SIGJVM2, ASYNC_SIGNAL is SIGJVM2. Previously INTERRUPT_SIGNAL
-// was SIGJVM1.
-//
-#if !defined(SIGJVM1)
-  #define SIGJVM1 39
-  #define SIGJVM2 40
-#endif
-
 debug_only(static bool signal_sets_initialized = false);
 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
 
-int os::Solaris::_SIGasync = ASYNC_SIGNAL;
-
 bool os::Solaris::is_sig_ignored(int sig) {
   struct sigaction oact;
   sigaction(sig, (struct sigaction*)NULL, &oact);
@@ -1040,12 +1028,6 @@
   }
 }
 
-// Note: SIGRTMIN is a macro that calls sysconf() so it will
-// dynamically detect SIGRTMIN value for the system at runtime, not buildtime
-static bool isJVM1available() {
-  return SIGJVM1 < SIGRTMIN;
-}
-
 void os::Solaris::signal_sets_init() {
   // Should also have an assertion stating we are still single-threaded.
   assert(!signal_sets_initialized, "Already initialized");
@@ -1068,12 +1050,7 @@
   sigaddset(&unblocked_sigs, SIGSEGV);
   sigaddset(&unblocked_sigs, SIGBUS);
   sigaddset(&unblocked_sigs, SIGFPE);
-
-  // Always true on Solaris 10+
-  guarantee(isJVM1available(), "SIGJVM1/2 missing!");
-  os::Solaris::set_SIGasync(SIGJVM2);
-
-  sigaddset(&unblocked_sigs, os::Solaris::SIGasync());
+  sigaddset(&unblocked_sigs, ASYNC_SIGNAL);
 
   if (!ReduceSignalUsage) {
     if (!os::Solaris::is_sig_ignored(SHUTDOWN1_SIGNAL)) {
@@ -1918,7 +1895,6 @@
 
 // Moved from whole group, because we need them here for diagnostic
 // prints.
-#define OLDMAXSIGNUM 32
 static int Maxsignum = 0;
 static int *ourSigFlags = NULL;
 
@@ -2011,7 +1987,6 @@
   print_signal_handler(st, SHUTDOWN1_SIGNAL , buf, buflen);
   print_signal_handler(st, SHUTDOWN2_SIGNAL , buf, buflen);
   print_signal_handler(st, SHUTDOWN3_SIGNAL, buf, buflen);
-  print_signal_handler(st, os::Solaris::SIGasync(), buf, buflen);
 }
 
 static char saved_jvm_path[MAXPATHLEN] = { 0 };
@@ -2034,7 +2009,9 @@
   int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
   assert(ret != 0, "cannot locate libjvm");
   if (ret != 0 && dlinfo.dli_fname != NULL) {
-    realpath((char *)dlinfo.dli_fname, buf);
+    if (os::Posix::realpath((char *)dlinfo.dli_fname, buf, buflen) == NULL) {
+      return;
+    }
   } else {
     buf[0] = '\0';
     return;
@@ -2065,7 +2042,9 @@
         p = strrchr(buf, '/');
         assert(strstr(p, "/libjvm") == p, "invalid library name");
 
-        realpath(java_home_var, buf);
+        if (os::Posix::realpath(java_home_var, buf, buflen) == NULL) {
+          return;
+        }
         // determine if this is a legacy image or modules image
         // modules image doesn't have "jre" subdirectory
         len = strlen(buf);
@@ -2082,7 +2061,9 @@
           snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
         } else {
           // Go back to path of .so
-          realpath((char *)dlinfo.dli_fname, buf);
+          if (os::Posix::realpath((char *)dlinfo.dli_fname, buf, buflen) == NULL) {
+            return;
+          }
         }
       }
     }
@@ -2173,14 +2154,12 @@
 
 // a counter for each possible signal value
 static int Sigexit = 0;
-static int Maxlibjsigsigs;
 static jint *pending_signals = NULL;
 static int *preinstalled_sigs = NULL;
 static struct sigaction *chainedsigactions = NULL;
 static sema_t sig_sem;
 typedef int (*version_getting_t)();
 version_getting_t os::Solaris::get_libjsig_version = NULL;
-static int libjsigversion = NULL;
 
 int os::sigexitnum_pd() {
   assert(Sigexit > 0, "signal memory not yet initialized");
@@ -2193,8 +2172,6 @@
   Sigexit = Maxsignum+1;
   assert(Maxsignum >0, "Unable to obtain max signal number");
 
-  Maxlibjsigsigs = Maxsignum;
-
   // pending_signals has one int per signal
   // The additional signal is for SIGEXIT - exit signal to signal_thread
   pending_signals = (jint *)os::malloc(sizeof(jint) * (Sigexit+1), mtInternal);
@@ -3558,7 +3535,7 @@
 
       // get current set of blocked signals and unblock resume signal
       pthread_sigmask(SIG_BLOCK, NULL, &suspend_set);
-      sigdelset(&suspend_set, os::Solaris::SIGasync());
+      sigdelset(&suspend_set, ASYNC_SIGNAL);
 
       sr_semaphore.signal();
       // wait here until we are resumed
@@ -3613,7 +3590,7 @@
 }
 
 static int sr_notify(OSThread* osthread) {
-  int status = thr_kill(osthread->thread_id(), os::Solaris::SIGasync());
+  int status = thr_kill(osthread->thread_id(), ASYNC_SIGNAL);
   assert_status(status == 0, status, "thr_kill");
   return status;
 }
@@ -3758,7 +3735,7 @@
 //
 // This routine may recognize any of the following kinds of signals:
 // SIGBUS, SIGSEGV, SIGILL, SIGFPE, BREAK_SIGNAL, SIGPIPE, SIGXFSZ,
-// os::Solaris::SIGasync
+// ASYNC_SIGNAL.
 // It should be consulted by handlers for any of those signals.
 //
 // The caller of this routine must pass in the three arguments supplied
@@ -3793,7 +3770,7 @@
 struct sigaction* os::Solaris::get_chained_signal_action(int sig) {
   struct sigaction *actp = NULL;
 
-  if ((libjsig_is_loaded)  && (sig <= Maxlibjsigsigs)) {
+  if ((libjsig_is_loaded)  && (sig <= Maxsignum)) {
     // Retrieve the old signal handler from libjsig
     actp = (*get_signal_action)(sig);
   }
@@ -3958,6 +3935,7 @@
   DO_SIGNAL_CHECK(SIGBUS);
   DO_SIGNAL_CHECK(SIGPIPE);
   DO_SIGNAL_CHECK(SIGXFSZ);
+  DO_SIGNAL_CHECK(ASYNC_SIGNAL);
 
   // ReduceSignalUsage allows the user to override these handlers
   // see comments at the very top and jvm_solaris.h
@@ -3967,10 +3945,6 @@
     DO_SIGNAL_CHECK(SHUTDOWN3_SIGNAL);
     DO_SIGNAL_CHECK(BREAK_SIGNAL);
   }
-
-  // See comments above for using JVM1/JVM2
-  DO_SIGNAL_CHECK(os::Solaris::SIGasync());
-
 }
 
 typedef int (*os_sigaction_t)(int, const struct sigaction *, struct sigaction *);
@@ -4002,6 +3976,7 @@
   case SIGPIPE:
   case SIGXFSZ:
   case SIGILL:
+  case ASYNC_SIGNAL:
     jvmHandler = CAST_FROM_FN_PTR(address, signalHandler);
     break;
 
@@ -4013,16 +3988,8 @@
     break;
 
   default:
-    int asynsig = os::Solaris::SIGasync();
-
-    if (sig == asynsig) {
-      jvmHandler = CAST_FROM_FN_PTR(address, signalHandler);
-    } else {
       return;
-    }
-    break;
-  }
-
+  }
 
   if (thisHandler != jvmHandler) {
     tty->print("Warning: %s handler ", exception_name(sig, buf, O_BUFLEN));
@@ -4055,7 +4022,6 @@
 }
 
 void os::Solaris::install_signal_handlers() {
-  bool libjsigdone = false;
   signal_handlers_are_installed = true;
 
   // signal-chaining
@@ -4073,7 +4039,8 @@
                                          dlsym(RTLD_DEFAULT, "JVM_get_libjsig_version"));
     libjsig_is_loaded = true;
     if (os::Solaris::get_libjsig_version != NULL) {
-      libjsigversion =  (*os::Solaris::get_libjsig_version)();
+      int libjsigversion =  (*os::Solaris::get_libjsig_version)();
+      assert(libjsigversion == JSIG_VERSION_1_4_1, "libjsig version mismatch");
     }
     assert(UseSignalChaining, "should enable signal-chaining");
   }
@@ -4088,21 +4055,9 @@
   set_signal_handler(SIGBUS, true, true);
   set_signal_handler(SIGILL, true, true);
   set_signal_handler(SIGFPE, true, true);
-
-
-  if (os::Solaris::SIGasync() > OLDMAXSIGNUM) {
-    // Pre-1.4.1 Libjsig limited to signal chaining signals <= 32 so
-    // can not register overridable signals which might be > 32
-    if (libjsig_is_loaded && libjsigversion <= JSIG_VERSION_1_4_1) {
-      // Tell libjsig jvm has finished setting signal handlers
-      (*end_signal_setting)();
-      libjsigdone = true;
-    }
-  }
-
-  set_signal_handler(os::Solaris::SIGasync(), true, true);
-
-  if (libjsig_is_loaded && !libjsigdone) {
+  set_signal_handler(ASYNC_SIGNAL, true, true);
+
+  if (libjsig_is_loaded) {
     // Tell libjsig jvm finishes setting signal handlers
     (*end_signal_setting)();
   }
@@ -4402,10 +4357,6 @@
   Solaris::init_signal_mem();
   Solaris::install_signal_handlers();
 
-  if (libjsigversion < JSIG_VERSION_1_4_1) {
-    Maxlibjsigsigs = OLDMAXSIGNUM;
-  }
-
   // initialize synchronization primitives to use either thread or
   // lwp synchronization (controlled by UseLWPSynchronization)
   Solaris::synchronization_init();
--- a/hotspot/src/os/solaris/vm/os_solaris.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os/solaris/vm/os_solaris.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -109,9 +109,6 @@
   static int (*get_libjsig_version)();
   static void save_preinstalled_handler(int, struct sigaction&);
   static void check_signal_handler(int sig);
-  // For overridable signals
-  static int _SIGasync;                      // user-overridable ASYNC_SIGNAL
-  static void set_SIGasync(int newsig) { _SIGasync = newsig; }
 
   typedef int (*pthread_setname_np_func_t)(pthread_t, const char*);
   static pthread_setname_np_func_t _pthread_setname_np;
@@ -120,7 +117,6 @@
   // Large Page Support--ISM.
   static bool largepage_range(char* addr, size_t size);
 
-  static int SIGasync() { return _SIGasync; }
   static address handler_start, handler_end; // start and end pc of thr_sighndlrinfo
 
   static bool valid_stack_address(Thread* thread, address sp);
--- a/hotspot/src/os/windows/vm/vmError_windows.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os/windows/vm/vmError_windows.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -66,3 +66,10 @@
     }
   }
 }
+
+// Error reporting cancellation: there is no easy way to implement this on Windows, because we do
+// not have an easy way to send signals to threads (aka to cause a win32 Exception in another
+// thread). We would need something like "RaiseException(HANDLE thread)"...
+void VMError::reporting_started() {}
+void VMError::interrupt_reporting_thread() {}
+
--- a/hotspot/src/os_cpu/linux_aarch64/vm/copy_linux_aarch64.inline.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os_cpu/linux_aarch64/vm/copy_linux_aarch64.inline.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -159,7 +159,6 @@
 }
 
 static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) {
-  assert(!UseCompressedOops, "foo!");
   assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
   _Copy_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
 }
--- a/hotspot/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -362,14 +362,14 @@
     }
   }
 
-  if (sig == os::Solaris::SIGasync()) {
+  if (sig == ASYNC_SIGNAL) {
     if (thread || vmthread) {
       OSThread::SR_handler(t, uc);
       return true;
     } else if (os::Solaris::chained_handler(sig, info, ucVoid)) {
       return true;
     } else {
-      // If os::Solaris::SIGasync not chained, and this is a non-vm and
+      // If ASYNC_SIGNAL not chained, and this is a non-vm and
       // non-java thread
       return true;
     }
--- a/hotspot/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -437,14 +437,14 @@
     }
   }
 
-  if (sig == os::Solaris::SIGasync()) {
+  if (sig == ASYNC_SIGNAL) {
     if(thread || vmthread){
       OSThread::SR_handler(t, uc);
       return true;
     } else if (os::Solaris::chained_handler(sig, info, ucVoid)) {
       return true;
     } else {
-      // If os::Solaris::SIGasync not chained, and this is a non-vm and
+      // If ASYNC_SIGNAL not chained, and this is a non-vm and
       // non-java thread
       return true;
     }
--- a/hotspot/src/share/vm/aot/aotCodeHeap.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/aot/aotCodeHeap.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,7 +41,7 @@
 int  AOTLib::_narrow_klass_shift = 0;
 
 address AOTLib::load_symbol(const char *name) {
-  address symbol = (address) dlsym(_dl_handle, name);
+  address symbol = (address) os::dll_lookup(_dl_handle, name);
   if (symbol == NULL) {
     tty->print_cr("Shared file %s error: missing %s", _name, name);
     vm_exit(1);
@@ -225,16 +225,15 @@
   _method_count = _lib->header()->_method_count;
 
   // Collect metaspace info: names -> address in .got section
-  _metaspace_names = (const char*) _lib->load_symbol("JVM.metaspace.names");
-  _method_metadata =     (address) _lib->load_symbol("JVM.method.metadata");
+  _metaspace_names = (const char*) _lib->load_symbol("JVM.meta.names");
+  _method_metadata =     (address) _lib->load_symbol("JVM.meth.metadata");
   _methods_offsets =     (address) _lib->load_symbol("JVM.methods.offsets");
-  _klasses_offsets =     (address) _lib->load_symbol("JVM.klasses.offsets");
-  _dependencies    =     (address) _lib->load_symbol("JVM.klasses.dependencies");
+  _klasses_offsets =     (address) _lib->load_symbol("JVM.kls.offsets");
+  _dependencies    =     (address) _lib->load_symbol("JVM.kls.dependencies");
   _code_space      =     (address) _lib->load_symbol("JVM.text");
 
   // First cell is number of elements.
-  jlong* got_sect;
-  _metaspace_got      = (Metadata**) _lib->load_symbol("JVM.metaspace.got");
+  _metaspace_got      = (Metadata**) _lib->load_symbol("JVM.meta.got");
   _metaspace_got_size = _lib->header()->_metaspace_got_size;
 
   _metadata_got      = (Metadata**) _lib->load_symbol("JVM.metadata.got");
@@ -250,7 +249,7 @@
   _code_segments = (address) _lib->load_symbol("JVM.code.segments");
 
   // method state
-  _method_state = (jlong*) _lib->load_symbol("JVM.method.state");
+  _method_state = (jlong*) _lib->load_symbol("JVM.meth.state");
 
   // Create a table for mapping classes
   _classes = NEW_C_HEAP_ARRAY(AOTClass, _class_count, mtCode);
@@ -341,7 +340,7 @@
     BasicType t = (BasicType)i;
     if (is_java_primitive(t)) {
       const Klass* arr_klass = Universe::typeArrayKlassObj(t);
-      AOTKlassData* klass_data = (AOTKlassData*) dlsym(_lib->dl_handle(), arr_klass->signature_name());
+      AOTKlassData* klass_data = (AOTKlassData*) os::dll_lookup(_lib->dl_handle(), arr_klass->signature_name());
       if (klass_data != NULL) {
         // Set both GOT cells, resolved and initialized klass pointers.
         // _got_index points to second cell - resolved klass pointer.
@@ -394,13 +393,9 @@
 
 #define SET_AOT_GLOBAL_SYMBOL_VALUE(AOTSYMNAME, AOTSYMTYPE, VMSYMVAL) \
   {                                                                   \
-    char* error;                                                      \
-    /* Clear any existing error */                                    \
-    dlerror();                                                        \
-    AOTSYMTYPE * adr = (AOTSYMTYPE *) dlsym(_lib->dl_handle(), AOTSYMNAME);  \
-    /* Check for any dlsym lookup error */                            \
-    error = dlerror();                                                \
-    guarantee(error == NULL, "%s", error);                            \
+    AOTSYMTYPE * adr = (AOTSYMTYPE *) os::dll_lookup(_lib->dl_handle(), AOTSYMNAME);  \
+    /* Check for a lookup error */                                    \
+    guarantee(adr != NULL, "AOT Symbol not found %s", AOTSYMNAME);    \
     *adr = (AOTSYMTYPE) VMSYMVAL;                                     \
   }
 
@@ -565,7 +560,7 @@
 }
 #endif
 
-Method* AOTCodeHeap::find_method(KlassHandle klass, Thread* thread, const char* method_name) {
+Method* AOTCodeHeap::find_method(Klass* klass, Thread* thread, const char* method_name) {
   int method_name_len = build_u2_from((address)method_name);
   method_name += 2;
   const char* signature_name = method_name + method_name_len;
@@ -583,14 +578,14 @@
              name == vmSymbols::class_initializer_name()) {
     // Never search superclasses for constructors
     if (klass->is_instance_klass()) {
-      m = InstanceKlass::cast(klass())->find_method(name, signature);
+      m = InstanceKlass::cast(klass)->find_method(name, signature);
     } else {
       m = NULL;
     }
   } else {
     m = klass->lookup_method(name, signature);
     if (m == NULL && klass->is_instance_klass()) {
-      m = InstanceKlass::cast(klass())->lookup_method_in_ordered_interfaces(name, signature);
+      m = InstanceKlass::cast(klass)->lookup_method_in_ordered_interfaces(name, signature);
     }
   }
   if (m == NULL) {
@@ -604,9 +599,9 @@
     memcpy(&meta_name[klass_len + 1 + method_name_len], signature_name, signature_name_len);
     meta_name[klass_len + 1 + method_name_len + signature_name_len] = '\0';
     Handle exception = Exceptions::new_exception(thread, vmSymbols::java_lang_NoSuchMethodError(), meta_name);
-    java_lang_Throwable::print(exception, tty);
+    java_lang_Throwable::print(exception(), tty);
     tty->cr();
-    java_lang_Throwable::print_stack_trace(exception(), tty);
+    java_lang_Throwable::print_stack_trace(exception, tty);
     tty->cr();
     fatal("Failed to find method '%s'", meta_name);
   }
@@ -616,7 +611,7 @@
 
 AOTKlassData* AOTCodeHeap::find_klass(InstanceKlass* ik) {
   ResourceMark rm;
-  AOTKlassData* klass_data = (AOTKlassData*) dlsym(_lib->dl_handle(), ik->signature_name());
+  AOTKlassData* klass_data = (AOTKlassData*) os::dll_lookup(_lib->dl_handle(), ik->signature_name());
   return klass_data;
 }
 
@@ -674,28 +669,28 @@
   }
 }
 
-bool AOTCodeHeap::load_klass_data(instanceKlassHandle kh, Thread* thread) {
+bool AOTCodeHeap::load_klass_data(InstanceKlass* ik, Thread* thread) {
   ResourceMark rm;
 
   NOT_PRODUCT( klasses_seen++; )
 
-  AOTKlassData* klass_data = find_klass(kh());
+  AOTKlassData* klass_data = find_klass(ik);
   if (klass_data == NULL) {
     return false;
   }
 
-  if (!kh->has_passed_fingerprint_check()) {
+  if (!ik->has_passed_fingerprint_check()) {
     NOT_PRODUCT( aot_klasses_fp_miss++; )
     log_trace(aot, class, fingerprint)("class  %s%s  has bad fingerprint in  %s tid=" INTPTR_FORMAT,
-                                   kh->internal_name(), kh->is_shared() ? " (shared)" : "",
+                                   ik->internal_name(), ik->is_shared() ? " (shared)" : "",
                                    _lib->name(), p2i(thread));
     sweep_dependent_methods(klass_data);
     return false;
   }
 
-  if (kh->has_been_redefined()) {
+  if (ik->has_been_redefined()) {
     log_trace(aot, class, load)("class  %s%s in %s  has been redefined tid=" INTPTR_FORMAT,
-                                   kh->internal_name(), kh->is_shared() ? " (shared)" : "",
+                                   ik->internal_name(), ik->is_shared() ? " (shared)" : "",
                                    _lib->name(), p2i(thread));
     sweep_dependent_methods(klass_data);
     return false;
@@ -703,26 +698,26 @@
 
   assert(klass_data->_class_id < _class_count, "invalid class id");
   AOTClass* aot_class = &_classes[klass_data->_class_id];
-  if (aot_class->_classloader != NULL && aot_class->_classloader != kh->class_loader_data()) {
+  if (aot_class->_classloader != NULL && aot_class->_classloader != ik->class_loader_data()) {
     log_trace(aot, class, load)("class  %s  in  %s already loaded for classloader %p vs %p tid=" INTPTR_FORMAT,
-                             kh->internal_name(), _lib->name(), aot_class->_classloader, kh->class_loader_data(), p2i(thread));
+                             ik->internal_name(), _lib->name(), aot_class->_classloader, ik->class_loader_data(), p2i(thread));
     NOT_PRODUCT( aot_klasses_cl_miss++; )
     return false;
   }
 
-  if (_lib->config()->_omitAssertions && JavaAssertions::enabled(kh->name()->as_C_string(), kh->class_loader() == NULL)) {
-    log_trace(aot, class, load)("class  %s  in  %s does not have java assertions in compiled code, but assertions are enabled for this execution.", kh->internal_name(), _lib->name());
+  if (_lib->config()->_omitAssertions && JavaAssertions::enabled(ik->name()->as_C_string(), ik->class_loader() == NULL)) {
+    log_trace(aot, class, load)("class  %s  in  %s does not have java assertions in compiled code, but assertions are enabled for this execution.", ik->internal_name(), _lib->name());
     sweep_dependent_methods(klass_data);
     return false;
   }
 
   NOT_PRODUCT( aot_klasses_found++; )
 
-  log_trace(aot, class, load)("found  %s  in  %s for classloader %p tid=" INTPTR_FORMAT, kh->internal_name(), _lib->name(), kh->class_loader_data(), p2i(thread));
+  log_trace(aot, class, load)("found  %s  in  %s for classloader %p tid=" INTPTR_FORMAT, ik->internal_name(), _lib->name(), ik->class_loader_data(), p2i(thread));
 
-  aot_class->_classloader = kh->class_loader_data();
+  aot_class->_classloader = ik->class_loader_data();
   // Set klass's Resolve (second) got cell.
-  _metaspace_got[klass_data->_got_index] = kh();
+  _metaspace_got[klass_data->_got_index] = ik;
 
   // Initialize global symbols of the DSO to the corresponding VM symbol values.
   link_global_lib_symbols();
@@ -750,7 +745,7 @@
       // aot_name format: "<u2_size>Ljava/lang/ThreadGroup;<u2_size>addUnstarted<u2_size>()V"
       int klass_len = build_u2_from((address)aot_name);
       const char* method_name = aot_name + 2 + klass_len;
-      Method* m = AOTCodeHeap::find_method(kh, thread, method_name);
+      Method* m = AOTCodeHeap::find_method(ik, thread, method_name);
       methodHandle mh(thread, m);
       if (mh->code() != NULL) { // Does it have already compiled code?
         continue; // Don't overwrite
@@ -871,7 +866,7 @@
 }
 #endif
 
-void AOTCodeHeap::flush_evol_dependents_on(instanceKlassHandle dependee) {
+void AOTCodeHeap::flush_evol_dependents_on(InstanceKlass* dependee) {
   for (int index = 0; index < _method_count; index++) {
     if (_code_to_aot[index]._state != in_use) {
       continue; // Skip uninitialized entries.
--- a/hotspot/src/share/vm/aot/aotCodeHeap.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/aot/aotCodeHeap.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -253,7 +253,7 @@
   virtual void* next(void *p) const;
 
   AOTKlassData* find_klass(InstanceKlass* ik);
-  bool load_klass_data(instanceKlassHandle kh, Thread* thread);
+  bool load_klass_data(InstanceKlass* ik, Thread* thread);
   Klass* get_klass_from_got(const char* klass_name, int klass_len, const Method* method);
   void sweep_dependent_methods(AOTKlassData* klass_data);
   bool is_dependent_method(Klass* dependee, AOTCompiledMethod* aot);
@@ -289,13 +289,13 @@
     return NULL;
   }
 
-  static Method* find_method(KlassHandle klass, Thread* thread, const char* method_name);
+  static Method* find_method(Klass* klass, Thread* thread, const char* method_name);
 
   void cleanup_inline_caches();
 
   DEBUG_ONLY( int verify_icholder_relocations(); )
 
-  void flush_evol_dependents_on(instanceKlassHandle dependee);
+  void flush_evol_dependents_on(InstanceKlass* dependee);
 
   void alive_methods_do(void f(CompiledMethod* nm));
 
--- a/hotspot/src/share/vm/aot/aotCompiledMethod.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/aot/aotCompiledMethod.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,6 @@
 #include "utilities/array.hpp"
 #include "utilities/xmlstream.hpp"
 
-#include <dlfcn.h>
 #include <stdio.h>
 
 #if 0
@@ -144,9 +143,8 @@
       int full_len = 2 + klass_len + 2 + method_name_len + 2 + signature_len;
       if (!klass_matched || memcmp(_name, meta_name, full_len) != 0) { // Does not match?
         Thread* thread = Thread::current();
-        KlassHandle klass = KlassHandle(thread, k);
         const char* method_name = klass_name + klass_len;
-        m = AOTCodeHeap::find_method(klass, thread, method_name);
+        m = AOTCodeHeap::find_method(k, thread, method_name);
       }
       meta = ((intptr_t)m) | 1;
       *entry = (Metadata*)meta; // Should be atomic on x64
@@ -240,7 +238,7 @@
 
 // We don't have full dependencies for AOT methods, so flushing is
 // more conservative than for nmethods.
-void AOTCompiledMethod::flush_evol_dependents_on(instanceKlassHandle dependee) {
+void AOTCompiledMethod::flush_evol_dependents_on(InstanceKlass* dependee) {
   if (is_java_method()) {
     cleanup_inline_caches();
     mark_for_deoptimization();
--- a/hotspot/src/share/vm/aot/aotCompiledMethod.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/aot/aotCompiledMethod.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -240,7 +240,7 @@
 
 #ifdef HOTSWAP
   // Flushing and deoptimization in case of evolution
-  void flush_evol_dependents_on(instanceKlassHandle dependee);
+  void flush_evol_dependents_on(InstanceKlass* dependee);
 #endif // HOTSWAP
 
   virtual void metadata_do(void f(Metadata*));
--- a/hotspot/src/share/vm/aot/aotLoader.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/aot/aotLoader.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 #include "aot/aotLoader.inline.hpp"
 #include "jvmci/jvmciRuntime.hpp"
 #include "oops/method.hpp"
+#include "runtime/os.hpp"
 
 GrowableArray<AOTCodeHeap*>* AOTLoader::_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<AOTCodeHeap*> (2, true);
 GrowableArray<AOTLib*>* AOTLoader::_libraries = new(ResourceObj::C_HEAP, mtCode) GrowableArray<AOTLib*> (2, true);
@@ -36,10 +37,10 @@
 // Iterate over all AOT Libraries
 #define FOR_ALL_AOT_LIBRARIES(lib) for (GrowableArrayIterator<AOTLib*> lib = libraries()->begin(); lib != libraries()->end(); ++lib)
 
-void AOTLoader::load_for_klass(instanceKlassHandle kh, Thread* thread) {
+void AOTLoader::load_for_klass(InstanceKlass* ik, Thread* thread) {
   if (UseAOT) {
     FOR_ALL_AOT_HEAPS(heap) {
-      (*heap)->load_klass_data(kh, thread);
+      (*heap)->load_klass_data(ik, thread);
     }
   }
 }
@@ -97,7 +98,7 @@
 }
 
 // Flushing and deoptimization in case of evolution
-void AOTLoader::flush_evol_dependents_on(instanceKlassHandle dependee) {
+void AOTLoader::flush_evol_dependents_on(InstanceKlass* dependee) {
   // make non entrant and mark for deoptimization
   FOR_ALL_AOT_HEAPS(heap) {
     (*heap)->flush_evol_dependents_on(dependee);
@@ -146,13 +147,13 @@
 
     for (int i = 0; i < (int) (sizeof(modules) / sizeof(const char*)); i++) {
       char library[JVM_MAXPATHLEN];
-      jio_snprintf(library, sizeof(library), "%s%slib%slib%s%s%s.so", home, file_separator, file_separator, modules[i], UseCompressedOops ? "-coop" : "", UseG1GC ? "" : "-nong1");
+      jio_snprintf(library, sizeof(library), "%s%slib%slib%s%s%s%s", home, file_separator, file_separator, modules[i], UseCompressedOops ? "-coop" : "", UseG1GC ? "" : "-nong1", os::dll_file_extension());
       load_library(library, false);
     }
 
     // Scan the AOTLibrary option.
     if (AOTLibrary != NULL) {
-      const int len = strlen(AOTLibrary);
+      const int len = (int)strlen(AOTLibrary);
       char* cp  = NEW_C_HEAP_ARRAY(char, len+1, mtCode);
       if (cp != NULL) { // No memory?
         memcpy(cp, AOTLibrary, len);
@@ -234,10 +235,11 @@
 }
 
 void AOTLoader::load_library(const char* name, bool exit_on_error) {
-  void* handle = dlopen(name, RTLD_LAZY);
+  char ebuf[1024];
+  void* handle = os::dll_load(name, ebuf, sizeof ebuf);
   if (handle == NULL) {
     if (exit_on_error) {
-      tty->print_cr("error opening file: %s", dlerror());
+      tty->print_cr("error opening file: %s", ebuf);
       vm_exit(1);
     }
     return;
@@ -246,7 +248,7 @@
   AOTLib* lib = new AOTLib(handle, name, dso_id);
   if (!lib->is_valid()) {
     delete lib;
-    dlclose(handle);
+    os::dll_unload(handle);
     return;
   }
   add_library(lib);
--- a/hotspot/src/share/vm/aot/aotLoader.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/aot/aotLoader.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -58,7 +58,7 @@
   static void universe_init() NOT_AOT_RETURN;
   static void set_narrow_klass_shift() NOT_AOT_RETURN;
   static bool contains(address p) NOT_AOT({ return false; });
-  static void load_for_klass(instanceKlassHandle, Thread* thread) NOT_AOT_RETURN;
+  static void load_for_klass(InstanceKlass* ik, Thread* thread) NOT_AOT_RETURN;
   static bool find_klass(InstanceKlass* ik) NOT_AOT({ return false; });
   static uint64_t get_saved_fingerprint(InstanceKlass* ik) NOT_AOT({ return 0; });
   static void oops_do(OopClosure* f) NOT_AOT_RETURN;
@@ -69,7 +69,7 @@
 
 #ifdef HOTSWAP
   // Flushing and deoptimization in case of evolution
-  static void flush_evol_dependents_on(instanceKlassHandle dependee) NOT_AOT_RETURN;
+  static void flush_evol_dependents_on(InstanceKlass* dependee) NOT_AOT_RETURN;
 #endif // HOTSWAP
 
 };
--- a/hotspot/src/share/vm/aot/compiledIC_aot.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/aot/compiledIC_aot.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,6 +21,8 @@
  * questions.
  */
 
+#include "precompiled.hpp"
+
 #include "aot/compiledIC_aot.hpp"
 
 bool CompiledPltStaticCall::is_call_to_interpreted() const {
--- a/hotspot/src/share/vm/asm/assembler.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/asm/assembler.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -93,6 +93,10 @@
   GrowableArray<int>* _patch_overflow;
 
   Label(const Label&) { ShouldNotReachHere(); }
+ protected:
+
+  // The label will be bound to a location near its users.
+  bool _is_near;
 
  public:
 
@@ -126,6 +130,10 @@
   bool is_unbound() const  { return _loc == -1 && _patch_index > 0; }
   bool is_unused() const   { return _loc == -1 && _patch_index == 0; }
 
+  // The label will be bound to a location near its users. Users can
+  // optimize on this information, e.g. generate short branches.
+  bool is_near()           { return _is_near; }
+
   /**
    * Adds a reference to an unresolved displacement instruction to
    * this unbound label
@@ -145,6 +153,7 @@
     _loc = -1;
     _patch_index = 0;
     _patch_overflow = NULL;
+    _is_near = false;
   }
 
   Label() {
@@ -152,6 +161,13 @@
   }
 };
 
+// A NearLabel must be bound to a location near its users. Users can
+// optimize on this information, e.g. generate short branches.
+class NearLabel : public Label {
+ public:
+  NearLabel() : Label() { _is_near = true; }
+};
+
 // A union type for code which has to assemble both constant and
 // non-constant operands, when the distinction cannot be made
 // statically.
--- a/hotspot/src/share/vm/c1/c1_Compiler.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/c1/c1_Compiler.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -212,7 +212,7 @@
   case vmIntrinsics::_updateCRC32:
   case vmIntrinsics::_updateBytesCRC32:
   case vmIntrinsics::_updateByteBufferCRC32:
-#ifdef SPARC
+#if defined(SPARC) || defined(S390) || defined(PPC64)
   case vmIntrinsics::_updateBytesCRC32C:
   case vmIntrinsics::_updateDirectByteBufferCRC32C:
 #endif
--- a/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -4297,6 +4297,8 @@
   }
 #endif // INCLUDE_TRACE
 
+  CompileTask::print_inlining_ul(callee, scope()->level(), bci(), msg);
+
   if (!compilation()->directive()->PrintInliningOption) {
     return;
   }
--- a/hotspot/src/share/vm/c1/c1_Runtime1.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/c1/c1_Runtime1.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -331,7 +331,7 @@
 
   assert(klass->is_klass(), "not a class");
   Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
-  instanceKlassHandle h(thread, klass);
+  InstanceKlass* h = InstanceKlass::cast(klass);
   h->check_valid_for_instantiation(true, CHECK);
   // make sure klass is initialized
   h->initialize(CHECK);
@@ -857,8 +857,8 @@
   bool deoptimize_for_volatile = false;
   bool deoptimize_for_atomic = false;
   int patch_field_offset = -1;
-  KlassHandle init_klass(THREAD, NULL); // klass needed by load_klass_patching code
-  KlassHandle load_klass(THREAD, NULL); // klass needed by load_klass_patching code
+  Klass* init_klass = NULL; // klass needed by load_klass_patching code
+  Klass* load_klass = NULL; // klass needed by load_klass_patching code
   Handle mirror(THREAD, NULL);                    // oop needed by load_mirror_patching code
   Handle appendix(THREAD, NULL);                  // oop needed by appendix_patching code
   bool load_klass_or_mirror_patch_id =
@@ -905,7 +905,7 @@
       case Bytecodes::_putstatic:
       case Bytecodes::_getstatic:
         { Klass* klass = resolve_field_return_klass(caller_method, bci, CHECK);
-          init_klass = KlassHandle(THREAD, klass);
+          init_klass = klass;
           mirror = Handle(THREAD, klass->java_mirror());
         }
         break;
@@ -945,8 +945,7 @@
         break;
       default: fatal("unexpected bytecode for load_klass_or_mirror_patch_id");
     }
-    // convert to handle
-    load_klass = KlassHandle(THREAD, k);
+    load_klass = k;
   } else if (stub_id == load_appendix_patching_id) {
     Bytecode_invoke bytecode(caller_method, bci);
     Bytecodes::Code bc = bytecode.invoke_code();
@@ -961,13 +960,13 @@
         assert(cache_index >= 0 && cache_index < pool->cache()->length(), "unexpected cache index");
         ConstantPoolCacheEntry* cpce = pool->cache()->entry_at(cache_index);
         cpce->set_method_handle(pool, info);
-        appendix = cpce->appendix_if_resolved(pool); // just in case somebody already resolved the entry
+        appendix = Handle(THREAD, cpce->appendix_if_resolved(pool)); // just in case somebody already resolved the entry
         break;
       }
       case Bytecodes::_invokedynamic: {
         ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(index);
         cpce->set_dynamic_call(pool, info);
-        appendix = cpce->appendix_if_resolved(pool); // just in case somebody already resolved the entry
+        appendix = Handle(THREAD, cpce->appendix_if_resolved(pool)); // just in case somebody already resolved the entry
         break;
       }
       default: fatal("unexpected bytecode for load_appendix_patching_id");
@@ -1067,7 +1066,7 @@
           // initializing thread are forced to come into the VM and
           // block.
           do_patch = (code != Bytecodes::_getstatic && code != Bytecodes::_putstatic) ||
-                     InstanceKlass::cast(init_klass())->is_initialized();
+                     InstanceKlass::cast(init_klass)->is_initialized();
           NativeGeneralJump* jump = nativeGeneralJump_at(instr_pc);
           if (jump->jump_destination() == being_initialized_entry) {
             assert(do_patch == true, "initialization must be complete at this point");
@@ -1079,8 +1078,8 @@
                    n_copy->data() == (intptr_t)Universe::non_oop_word(),
                    "illegal init value");
             if (stub_id == Runtime1::load_klass_patching_id) {
-              assert(load_klass() != NULL, "klass not set");
-              n_copy->set_data((intx) (load_klass()));
+              assert(load_klass != NULL, "klass not set");
+              n_copy->set_data((intx) (load_klass));
             } else {
               assert(mirror() != NULL, "klass not set");
               // Don't need a G1 pre-barrier here since we assert above that data isn't an oop.
@@ -1131,7 +1130,7 @@
               assert(stub_id == Runtime1::load_klass_patching_id, "wrong stub id");
               metadata_Relocation* r = mds.metadata_reloc();
               Metadata** metadata_adr = r->metadata_addr();
-              *metadata_adr = load_klass();
+              *metadata_adr = load_klass;
               r->fix_metadata_relocation();
               found = true;
             }
--- a/hotspot/src/share/vm/ci/ciArrayKlass.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciArrayKlass.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
 // ciArrayKlass::ciArrayKlass
 //
 // Loaded array klass.
-ciArrayKlass::ciArrayKlass(KlassHandle h_k) : ciKlass(h_k) {
+ciArrayKlass::ciArrayKlass(Klass* k) : ciKlass(k) {
   assert(get_Klass()->is_array_klass(), "wrong type");
   _dimension = get_ArrayKlass()->dimension();
 }
--- a/hotspot/src/share/vm/ci/ciArrayKlass.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciArrayKlass.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
   jint _dimension;
 
 protected:
-  ciArrayKlass(KlassHandle h_k);
+  ciArrayKlass(Klass* k);
   ciArrayKlass(ciSymbol* name, int dimension, BasicType bt);
 
   ArrayKlass* get_ArrayKlass() {
--- a/hotspot/src/share/vm/ci/ciEnv.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciEnv.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -278,7 +278,7 @@
     if (!HAS_PENDING_EXCEPTION && k != NULL) {
       oop obj = InstanceKlass::cast(k)->allocate_instance(THREAD);
       if (!HAS_PENDING_EXCEPTION)
-        objh = JNIHandles::make_global(obj);
+        objh = JNIHandles::make_global(Handle(THREAD, obj));
     }
     if (HAS_PENDING_EXCEPTION) {
       CLEAR_PENDING_EXCEPTION;
@@ -376,7 +376,7 @@
   }
   if (resolved_klass->is_instance_klass()) {
     return (Reflection::verify_class_access(accessing_klass->get_Klass(),
-                                            resolved_klass,
+                                            InstanceKlass::cast(resolved_klass),
                                             true) == Reflection::ACCESS_OK);
   }
   return true;
@@ -426,7 +426,7 @@
   } else {
     fail_type = _unloaded_ciinstance_klass;
   }
-  KlassHandle found_klass;
+  Klass* found_klass;
   {
     ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
     MutexLocker ml(Compile_lock);
@@ -438,7 +438,7 @@
       kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain,
                                                            KILL_COMPILE_ON_FATAL_(fail_type));
     }
-    found_klass = KlassHandle(THREAD, kls);
+    found_klass = kls;
   }
 
   // If we fail to find an array klass, look again for its element type.
@@ -467,22 +467,22 @@
     }
   }
 
-  if (found_klass() == NULL && !cpool.is_null() && cpool->has_preresolution()) {
+  if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
     // Look inside the constant pool for pre-resolved class entries.
     for (int i = cpool->length() - 1; i >= 1; i--) {
       if (cpool->tag_at(i).is_klass()) {
         Klass* kls = cpool->resolved_klass_at(i);
         if (kls->name() == sym) {
-          found_klass = KlassHandle(THREAD, kls);
+          found_klass = kls;
           break;
         }
       }
     }
   }
 
-  if (found_klass() != NULL) {
+  if (found_klass != NULL) {
     // Found it.  Build a CI handle.
-    return get_klass(found_klass());
+    return get_klass(found_klass);
   }
 
   if (require_local)  return NULL;
@@ -512,21 +512,21 @@
                                         bool& is_accessible,
                                         ciInstanceKlass* accessor) {
   EXCEPTION_CONTEXT;
-  KlassHandle klass; // = NULL;
+  Klass* klass = NULL;
   Symbol* klass_name = NULL;
 
   if (cpool->tag_at(index).is_symbol()) {
     klass_name = cpool->symbol_at(index);
   } else {
     // Check if it's resolved if it's not a symbol constant pool entry.
-    klass = KlassHandle(THREAD, ConstantPool::klass_at_if_loaded(cpool, index));
+    klass =  ConstantPool::klass_at_if_loaded(cpool, index);
     // Try to look it up by name.
-  if (klass.is_null()) {
+    if (klass == NULL) {
       klass_name = cpool->klass_name_at(index);
-  }
+    }
   }
 
-  if (klass.is_null()) {
+  if (klass == NULL) {
     // Not found in constant pool.  Use the name to do the lookup.
     ciKlass* k = get_klass_by_name_impl(accessor,
                                         cpool,
@@ -548,7 +548,7 @@
 
   // Check for prior unloaded klass.  The SystemDictionary's answers
   // can vary over time but the compiler needs consistency.
-  ciSymbol* name = get_symbol(klass()->name());
+  ciSymbol* name = get_symbol(klass->name());
   ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name);
   if (unloaded_klass != NULL) {
     is_accessible = false;
@@ -557,7 +557,7 @@
 
   // It is known to be accessible, since it was found in the constant pool.
   is_accessible = true;
-  return get_klass(klass());
+  return get_klass(klass);
 }
 
 // ------------------------------------------------------------------
@@ -713,10 +713,10 @@
   // Accessibility checks are performed in ciEnv::get_method_by_index_impl.
   assert(check_klass_accessibility(accessor, holder->get_Klass()), "holder not accessible");
 
-  KlassHandle h_accessor(accessor->get_instanceKlass());
-  KlassHandle h_holder(holder->get_Klass());
+  InstanceKlass* accessor_klass = accessor->get_instanceKlass();
+  Klass* holder_klass = holder->get_Klass();
   methodHandle dest_method;
-  LinkInfo link_info(h_holder, name, sig, h_accessor, LinkInfo::needs_access_check, tag);
+  LinkInfo link_info(holder_klass, name, sig, accessor_klass, LinkInfo::needs_access_check, tag);
   switch (bc) {
   case Bytecodes::_invokestatic:
     dest_method =
--- a/hotspot/src/share/vm/ci/ciInstance.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciInstance.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -58,8 +58,8 @@
 // ------------------------------------------------------------------
 // ciInstance::field_value_impl
 ciConstant ciInstance::field_value_impl(BasicType field_btype, int offset) {
-  Handle obj = get_oop();
-  assert(!obj.is_null(), "bad oop");
+  oop obj = get_oop();
+  assert(obj != NULL, "bad oop");
   switch(field_btype) {
     case T_BYTE:    return ciConstant(field_btype, obj->byte_field(offset));
     case T_CHAR:    return ciConstant(field_btype, obj->char_field(offset));
--- a/hotspot/src/share/vm/ci/ciInstanceKlass.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciInstanceKlass.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -44,8 +44,8 @@
 // ciInstanceKlass::ciInstanceKlass
 //
 // Loaded instance klass.
-ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) :
-  ciKlass(h_k)
+ciInstanceKlass::ciInstanceKlass(Klass* k) :
+  ciKlass(k)
 {
   assert(get_Klass()->is_instance_klass(), "wrong type");
   assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
@@ -83,7 +83,7 @@
   _java_mirror = NULL;
 
   if (is_shared()) {
-    if (h_k() != SystemDictionary::Object_klass()) {
+    if (k != SystemDictionary::Object_klass()) {
       super();
     }
     //compute_nonstatic_fields();  // done outside of constructor
--- a/hotspot/src/share/vm/ci/ciInstanceKlass.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciInstanceKlass.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -77,7 +77,7 @@
   bool compute_injected_fields_helper();
 
 protected:
-  ciInstanceKlass(KlassHandle h_k);
+  ciInstanceKlass(Klass* k);
   ciInstanceKlass(ciSymbol* name, jobject loader, jobject protection_domain);
 
   InstanceKlass* get_instanceKlass() const {
--- a/hotspot/src/share/vm/ci/ciKlass.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciKlass.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,11 +35,11 @@
 
 // ------------------------------------------------------------------
 // ciKlass::ciKlass
-ciKlass::ciKlass(KlassHandle h_k) : ciType(h_k) {
+ciKlass::ciKlass(Klass* k) : ciType(k) {
   assert(get_Klass()->is_klass(), "wrong type");
-  Klass* k = get_Klass();
-  _layout_helper = k->layout_helper();
-  Symbol* klass_name = k->name();
+  Klass* klass = get_Klass();
+  _layout_helper = klass->layout_helper();
+  Symbol* klass_name = klass->name();
   assert(klass_name != NULL, "wrong ciKlass constructor");
   _name = CURRENT_ENV->get_symbol(klass_name);
 }
@@ -48,7 +48,7 @@
 // ciKlass::ciKlass
 //
 // Nameless klass variant.
-ciKlass::ciKlass(KlassHandle h_k, ciSymbol* name) : ciType(h_k) {
+ciKlass::ciKlass(Klass* k, ciSymbol* name) : ciType(k) {
   assert(get_Klass()->is_klass(), "wrong type");
   _name = name;
   _layout_helper = Klass::_lh_neutral_value;
--- a/hotspot/src/share/vm/ci/ciKlass.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciKlass.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -51,7 +51,7 @@
   jint _layout_helper;
 
 protected:
-  ciKlass(KlassHandle k_h, ciSymbol* name);
+  ciKlass(Klass* k, ciSymbol* name);
   ciKlass(ciSymbol* name, BasicType bt);
 
   Klass* get_Klass() const {
@@ -72,7 +72,7 @@
   void print_impl(outputStream* st);
 
 public:
-  ciKlass(KlassHandle k_h);
+  ciKlass(Klass* k);
 
   // What is the name of this klass?
   ciSymbol* name() const { return _name; }
--- a/hotspot/src/share/vm/ci/ciMethod.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciMethod.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -504,10 +504,11 @@
           morphism++;
         }
         int epsilon = 0;
-        if (TieredCompilation && ProfileInterpreter) {
-          // Interpreter and C1 treat final and special invokes differently.
-          // C1 will record a type, whereas the interpreter will just
-          // increment the count. Detect this case.
+        if (TieredCompilation) {
+          // For a call, it is assumed that either the type of the receiver(s)
+          // is recorded or an associated counter is incremented, but not both. With
+          // tiered compilation, however, both can happen due to the interpreter and
+          // C1 profiling invocations differently. Address that inconsistency here.
           if (morphism == 1 && count > 0) {
             epsilon = count;
             count = 0;
@@ -525,8 +526,8 @@
           // we will set result._method also.
         }
         // Determine call site's morphism.
-        // The call site count is 0 with known morphism (onlt 1 or 2 receivers)
-        // or < 0 in the case of a type check failured for checkcast, aastore, instanceof.
+        // The call site count is 0 with known morphism (only 1 or 2 receivers)
+        // or < 0 in the case of a type check failure for checkcast, aastore, instanceof.
         // The call site count is > 0 in the case of a polymorphic virtual call.
         if (morphism > 0 && morphism == result._limit) {
            // The morphism <= MorphismLimit.
@@ -782,24 +783,24 @@
    check_is_loaded();
    VM_ENTRY_MARK;
 
-   KlassHandle caller_klass (THREAD, caller->get_Klass());
-   KlassHandle h_recv       (THREAD, exact_receiver->get_Klass());
-   KlassHandle h_resolved   (THREAD, holder()->get_Klass());
+   Klass* caller_klass = caller->get_Klass();
+   Klass* recv         = exact_receiver->get_Klass();
+   Klass* resolved     = holder()->get_Klass();
    Symbol* h_name      = name()->get_symbol();
    Symbol* h_signature = signature()->get_symbol();
 
-   LinkInfo link_info(h_resolved, h_name, h_signature, caller_klass,
+   LinkInfo link_info(resolved, h_name, h_signature, caller_klass,
                       check_access ? LinkInfo::needs_access_check : LinkInfo::skip_access_check);
    methodHandle m;
    // Only do exact lookup if receiver klass has been linked.  Otherwise,
    // the vtable has not been setup, and the LinkResolver will fail.
-   if (h_recv->is_array_klass()
+   if (recv->is_array_klass()
         ||
-       InstanceKlass::cast(h_recv())->is_linked() && !exact_receiver->is_interface()) {
+       InstanceKlass::cast(recv)->is_linked() && !exact_receiver->is_interface()) {
      if (holder()->is_interface()) {
-       m = LinkResolver::resolve_interface_call_or_null(h_recv, link_info);
+       m = LinkResolver::resolve_interface_call_or_null(recv, link_info);
      } else {
-       m = LinkResolver::resolve_virtual_call_or_null(h_recv, link_info);
+       m = LinkResolver::resolve_virtual_call_or_null(recv, link_info);
      }
    }
 
@@ -838,13 +839,13 @@
            receiver->as_instance_klass()->is_linked())) {
      VM_ENTRY_MARK;
 
-     KlassHandle caller_klass (THREAD, caller->get_Klass());
-     KlassHandle h_recv       (THREAD, receiver->get_Klass());
+     Klass* caller_klass = caller->get_Klass();
+     Klass* recv         = receiver->get_Klass();
      Symbol* h_name = name()->get_symbol();
      Symbol* h_signature = signature()->get_symbol();
 
-     LinkInfo link_info(h_recv, h_name, h_signature, caller_klass);
-     vtable_index = LinkResolver::resolve_virtual_vtable_index(h_recv, link_info);
+     LinkInfo link_info(recv, h_name, h_signature, caller_klass);
+     vtable_index = LinkResolver::resolve_virtual_vtable_index(recv, link_info);
      if (vtable_index == Method::nonvirtual_vtable_index) {
        // A statically bound method.  Return "no such index".
        vtable_index = Method::invalid_vtable_index;
--- a/hotspot/src/share/vm/ci/ciObjArrayKlass.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciObjArrayKlass.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -38,7 +38,7 @@
 // ciObjArrayKlass::ciObjArrayKlass
 //
 // Constructor for loaded object array klasses.
-ciObjArrayKlass::ciObjArrayKlass(KlassHandle h_k) : ciArrayKlass(h_k) {
+ciObjArrayKlass::ciObjArrayKlass(Klass* k) : ciArrayKlass(k) {
   assert(get_Klass()->is_objArray_klass(), "wrong type");
   Klass* element_Klass = get_ObjArrayKlass()->bottom_klass();
   _base_element_klass = CURRENT_ENV->get_klass(element_Klass);
--- a/hotspot/src/share/vm/ci/ciObjArrayKlass.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciObjArrayKlass.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@
   ciKlass* _base_element_klass;
 
 protected:
-  ciObjArrayKlass(KlassHandle h_k);
+  ciObjArrayKlass(Klass* k);
   ciObjArrayKlass(ciSymbol* array_name,
                   ciKlass* base_element_klass,
                   int dimension);
--- a/hotspot/src/share/vm/ci/ciObject.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciObject.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -54,7 +54,8 @@
   if (ciObjectFactory::is_initialized()) {
     _handle = JNIHandles::make_local(o);
   } else {
-    _handle = JNIHandles::make_global(o);
+    Handle obj(Thread::current(), o);
+    _handle = JNIHandles::make_global(obj);
   }
   _klass = NULL;
   init_flags_from(o);
--- a/hotspot/src/share/vm/ci/ciObjectFactory.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciObjectFactory.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -249,7 +249,7 @@
 
   // The ciObject does not yet exist.  Create it and insert it
   // into the cache.
-  Handle keyHandle(key);
+  Handle keyHandle(Thread::current(), key);
   ciObject* new_object = create_new_object(keyHandle());
   assert(keyHandle() == new_object->get_oop(), "must be properly recorded");
   init_ident_of(new_object);
@@ -377,14 +377,13 @@
   }
 
   if (o->is_klass()) {
-    KlassHandle h_k(THREAD, (Klass*)o);
     Klass* k = (Klass*)o;
     if (k->is_instance_klass()) {
-      return new (arena()) ciInstanceKlass(h_k);
+      return new (arena()) ciInstanceKlass(k);
     } else if (k->is_objArray_klass()) {
-      return new (arena()) ciObjArrayKlass(h_k);
+      return new (arena()) ciObjArrayKlass(k);
     } else if (k->is_typeArray_klass()) {
-      return new (arena()) ciTypeArrayKlass(h_k);
+      return new (arena()) ciTypeArrayKlass(k);
     }
   } else if (o->is_method()) {
     methodHandle h_m(THREAD, (Method*)o);
--- a/hotspot/src/share/vm/ci/ciReplay.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciReplay.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -751,7 +751,7 @@
 
     assert(k->is_initialized(), "must be");
 
-    const char* field_name = parse_escaped_string();;
+    const char* field_name = parse_escaped_string();
     const char* field_signature = parse_string();
     fieldDescriptor fd;
     Symbol* name = SymbolTable::lookup(field_name, (int)strlen(field_name), CHECK);
@@ -799,8 +799,8 @@
         } else if (strcmp(field_signature, "[J") == 0) {
           value = oopFactory::new_longArray(length, CHECK);
         } else if (field_signature[0] == '[' && field_signature[1] == 'L') {
-          KlassHandle kelem = resolve_klass(field_signature + 1, CHECK);
-          value = oopFactory::new_objArray(kelem(), length, CHECK);
+          Klass* kelem = resolve_klass(field_signature + 1, CHECK);
+          value = oopFactory::new_objArray(kelem, length, CHECK);
         } else {
           report_error("unhandled array staticfield");
         }
@@ -840,9 +840,8 @@
         Handle value = java_lang_String::create_from_str(string_value, CHECK);
         java_mirror->obj_field_put(fd.offset(), value());
       } else if (field_signature[0] == 'L') {
-        Symbol* klass_name = SymbolTable::lookup(field_signature, (int)strlen(field_signature), CHECK);
-        KlassHandle kelem = resolve_klass(field_signature, CHECK);
-        oop value = InstanceKlass::cast(kelem())->allocate_instance(CHECK);
+        Klass* k = resolve_klass(string_value, CHECK);
+        oop value = InstanceKlass::cast(k)->allocate_instance(CHECK);
         java_mirror->obj_field_put(fd.offset(), value);
       } else {
         report_error("unhandled staticfield");
--- a/hotspot/src/share/vm/ci/ciType.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciType.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -45,8 +45,8 @@
   _basic_type = basic_type;
 }
 
-ciType::ciType(KlassHandle k) : ciMetadata(k()) {
-  _basic_type = k()->is_array_klass() ? T_ARRAY : T_OBJECT;
+ciType::ciType(Klass* k) : ciMetadata(k) {
+  _basic_type = k->is_array_klass() ? T_ARRAY : T_OBJECT;
 }
 
 
--- a/hotspot/src/share/vm/ci/ciType.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciType.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@
   BasicType _basic_type;
 
   ciType(BasicType t);     // for primitive and unloaded types
-  ciType(KlassHandle k);   // for subclasses (reference types)
+  ciType(Klass* k);        // for subclasses (reference types)
 
   const char* type_string() { return "ciType"; }
 
--- a/hotspot/src/share/vm/ci/ciTypeArrayKlass.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciTypeArrayKlass.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,7 +33,7 @@
 
 // ------------------------------------------------------------------
 // ciTypeArrayKlass::ciTypeArrayKlass
-ciTypeArrayKlass::ciTypeArrayKlass(KlassHandle h_k) : ciArrayKlass(h_k) {
+ciTypeArrayKlass::ciTypeArrayKlass(Klass* k) : ciArrayKlass(k) {
   assert(get_Klass()->is_typeArray_klass(), "wrong type");
   assert(element_type() == get_TypeArrayKlass()->element_type(), "");
 }
--- a/hotspot/src/share/vm/ci/ciTypeArrayKlass.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/ci/ciTypeArrayKlass.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,7 +35,7 @@
   CI_PACKAGE_ACCESS
 
 protected:
-  ciTypeArrayKlass(KlassHandle h_k);
+  ciTypeArrayKlass(Klass* k);
 
   TypeArrayKlass* get_TypeArrayKlass() {
     return (TypeArrayKlass*)get_Klass();
--- a/hotspot/src/share/vm/classfile/classFileError.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classFileError.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -68,6 +68,16 @@
                      msg, index, name, _class_name->as_C_string());
 }
 
+void ClassFileParser::classfile_parse_error(const char* msg,
+                                            const char* name,
+                                            const char* signature,
+                                            TRAPS) const {
+  assert(_class_name != NULL, "invariant");
+  ResourceMark rm(THREAD);
+  Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_ClassFormatError(),
+                     msg, name, signature, _class_name->as_C_string());
+}
+
 PRAGMA_DIAG_POP
 
 void StackMapStream::stackmap_format_error(const char* msg, TRAPS) {
--- a/hotspot/src/share/vm/classfile/classFileParser.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classFileParser.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -815,13 +815,13 @@
     int index;
     for (index = 0; index < itfs_len; index++) {
       const u2 interface_index = stream->get_u2(CHECK);
-      KlassHandle interf;
+      Klass* interf;
       check_property(
         valid_klass_reference_at(interface_index),
         "Interface name has bad constant pool index %u in class file %s",
         interface_index, CHECK);
       if (cp->tag_at(interface_index).is_klass()) {
-        interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
+        interf = cp->resolved_klass_at(interface_index);
       } else {
         Symbol* const unresolved_klass  = cp->klass_name_at(interface_index);
 
@@ -831,25 +831,24 @@
                            "Bad interface name in class file %s", CHECK);
 
         // Call resolve_super so classcircularity is checked
-        const Klass* const k =
-          SystemDictionary::resolve_super_or_fail(_class_name,
+        interf = SystemDictionary::resolve_super_or_fail(
+                                                  _class_name,
                                                   unresolved_klass,
-                                                  _loader_data->class_loader(),
+                                                  Handle(THREAD, _loader_data->class_loader()),
                                                   _protection_domain,
                                                   false,
                                                   CHECK);
-        interf = KlassHandle(THREAD, k);
       }
 
-      if (!interf()->is_interface()) {
+      if (!interf->is_interface()) {
         THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
                    "Implementing class");
       }
 
-      if (InstanceKlass::cast(interf())->has_nonstatic_concrete_methods()) {
+      if (InstanceKlass::cast(interf)->has_nonstatic_concrete_methods()) {
         *has_nonstatic_concrete_methods = true;
       }
-      _local_interfaces->at_put(index, interf());
+      _local_interfaces->at_put(index, interf);
     }
 
     if (!_need_verify || itfs_len <= 1) {
@@ -863,11 +862,12 @@
                                                                  HASH_ROW_SIZE);
     initialize_hashtable(interface_names);
     bool dup = false;
+    const Symbol* name = NULL;
     {
       debug_only(NoSafepointVerifier nsv;)
       for (index = 0; index < itfs_len; index++) {
         const Klass* const k = _local_interfaces->at(index);
-        const Symbol* const name = InstanceKlass::cast(k)->name();
+        name = InstanceKlass::cast(k)->name();
         // If no duplicates, add (name, NULL) in hashtable interface_names.
         if (!put_after_lookup(name, NULL, interface_names)) {
           dup = true;
@@ -876,7 +876,8 @@
       }
     }
     if (dup) {
-      classfile_parse_error("Duplicate interface name in class file %s", CHECK);
+      classfile_parse_error("Duplicate interface name \"%s\" in class file %s",
+                             name->as_C_string(), CHECK);
     }
   }
 }
@@ -1628,11 +1629,13 @@
       THREAD, NameSigHash*, HASH_ROW_SIZE);
     initialize_hashtable(names_and_sigs);
     bool dup = false;
+    const Symbol* name = NULL;
+    const Symbol* sig = NULL;
     {
       debug_only(NoSafepointVerifier nsv;)
       for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) {
-        const Symbol* const name = fs.name();
-        const Symbol* const sig = fs.signature();
+        name = fs.name();
+        sig = fs.signature();
         // If no duplicates, add name/signature in hashtable names_and_sigs.
         if (!put_after_lookup(name, sig, names_and_sigs)) {
           dup = true;
@@ -1641,8 +1644,8 @@
       }
     }
     if (dup) {
-      classfile_parse_error("Duplicate field name&signature in class file %s",
-                            CHECK);
+      classfile_parse_error("Duplicate field name \"%s\" with signature \"%s\" in class file %s",
+                             name->as_C_string(), sig->as_klass_external_name(), CHECK);
     }
   }
 }
@@ -2858,7 +2861,6 @@
                                                    NULL,
                                                    CHECK);
 
-    HandleMark hm(THREAD);
     for (int index = 0; index < length; index++) {
       Method* method = parse_method(cfs,
                                     is_interface,
@@ -2885,20 +2887,24 @@
         THREAD, NameSigHash*, HASH_ROW_SIZE);
       initialize_hashtable(names_and_sigs);
       bool dup = false;
+      const Symbol* name = NULL;
+      const Symbol* sig = NULL;
       {
         debug_only(NoSafepointVerifier nsv;)
         for (int i = 0; i < length; i++) {
           const Method* const m = _methods->at(i);
+          name = m->name();
+          sig = m->signature();
           // If no duplicates, add name/signature in hashtable names_and_sigs.
-          if (!put_after_lookup(m->name(), m->signature(), names_and_sigs)) {
+          if (!put_after_lookup(name, sig, names_and_sigs)) {
             dup = true;
             break;
           }
         }
       }
       if (dup) {
-        classfile_parse_error("Duplicate method name&signature in class file %s",
-                              CHECK);
+        classfile_parse_error("Duplicate method name \"%s\" with signature \"%s\" in class file %s",
+                               name->as_C_string(), sig->as_klass_external_name(), CHECK);
       }
     }
   }
@@ -4388,10 +4394,12 @@
     }
 
     Reflection::VerifyClassAccessResults vca_result =
-      Reflection::verify_class_access(this_klass, super, false);
+      Reflection::verify_class_access(this_klass, InstanceKlass::cast(super), false);
     if (vca_result != Reflection::ACCESS_OK) {
       ResourceMark rm(THREAD);
-      char* msg =  Reflection::verify_class_access_msg(this_klass, super, vca_result);
+      char* msg = Reflection::verify_class_access_msg(this_klass,
+                                                      InstanceKlass::cast(super),
+                                                      vca_result);
       if (msg == NULL) {
         Exceptions::fthrow(
           THREAD_AND_LOCATION,
@@ -4420,10 +4428,12 @@
     Klass* const k = local_interfaces->at(i);
     assert (k != NULL && k->is_interface(), "invalid interface");
     Reflection::VerifyClassAccessResults vca_result =
-      Reflection::verify_class_access(this_klass, k, false);
+      Reflection::verify_class_access(this_klass, InstanceKlass::cast(k), false);
     if (vca_result != Reflection::ACCESS_OK) {
       ResourceMark rm(THREAD);
-      char* msg =  Reflection::verify_class_access_msg(this_klass, k, vca_result);
+      char* msg = Reflection::verify_class_access_msg(this_klass,
+                                                      InstanceKlass::cast(k),
+                                                      vca_result);
       if (msg == NULL) {
         Exceptions::fthrow(
           THREAD_AND_LOCATION,
@@ -5377,7 +5387,7 @@
   // Allocate mirror and initialize static fields
   // The create_mirror() call will also call compute_modifiers()
   java_lang_Class::create_mirror(ik,
-                                 _loader_data->class_loader(),
+                                 Handle(THREAD, _loader_data->class_loader()),
                                  module_handle,
                                  _protection_domain,
                                  CHECK);
@@ -5942,10 +5952,11 @@
         "Interfaces must have java.lang.Object as superclass in class file %s",
         CHECK);
     }
+    Handle loader(THREAD, _loader_data->class_loader());
     _super_klass = (const InstanceKlass*)
                        SystemDictionary::resolve_super_or_fail(_class_name,
                                                                super_class_name,
-                                                               _loader_data->class_loader(),
+                                                               loader,
                                                                _protection_domain,
                                                                true,
                                                                CHECK);
@@ -5987,6 +5998,7 @@
 
   _all_mirandas = new GrowableArray<Method*>(20);
 
+  Handle loader(THREAD, _loader_data->class_loader());
   klassVtable::compute_vtable_size_and_num_mirandas(&_vtable_size,
                                                     &_num_miranda_methods,
                                                     _all_mirandas,
@@ -5994,7 +6006,7 @@
                                                     _methods,
                                                     _access_flags,
                                                     _major_version,
-                                                    _loader_data->class_loader(),
+                                                    loader,
                                                     _class_name,
                                                     _local_interfaces,
                                                     CHECK);
--- a/hotspot/src/share/vm/classfile/classFileParser.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classFileParser.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -301,6 +301,10 @@
                              int index,
                              const char *name,
                              TRAPS) const;
+  void classfile_parse_error(const char* msg,
+                             const char* name,
+                             const char* signature,
+                             TRAPS) const;
 
   inline void guarantee_property(bool b, const char* msg, TRAPS) const {
     if (!b) { classfile_parse_error(msg, CHECK); }
--- a/hotspot/src/share/vm/classfile/classLoader.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classLoader.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1405,7 +1405,7 @@
   return NULL;
 }
 
-instanceKlassHandle ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS) {
+InstanceKlass* ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS) {
   assert(name != NULL, "invariant");
   assert(THREAD->is_Java_thread(), "must be a JavaThread");
 
@@ -1512,13 +1512,13 @@
   ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
   Handle protection_domain;
 
-  instanceKlassHandle result = KlassFactory::create_from_stream(stream,
-                                                                name,
-                                                                loader_data,
-                                                                protection_domain,
-                                                                NULL, // host_klass
-                                                                NULL, // cp_patches
-                                                                THREAD);
+  InstanceKlass* result = KlassFactory::create_from_stream(stream,
+                                                           name,
+                                                           loader_data,
+                                                           protection_domain,
+                                                           NULL, // host_klass
+                                                           NULL, // cp_patches
+                                                           THREAD);
   if (HAS_PENDING_EXCEPTION) {
     if (DumpSharedSpaces) {
       tty->print_cr("Preload Error: Failed to load %s", class_name);
@@ -1720,7 +1720,7 @@
 
   {
     MutexLocker ml(Module_lock, THREAD);
-    ModuleEntry* jb_module = null_cld_modules->locked_create_entry_or_null(Handle(NULL), vmSymbols::java_base(), NULL, NULL, null_cld);
+    ModuleEntry* jb_module = null_cld_modules->locked_create_entry_or_null(Handle(), vmSymbols::java_base(), NULL, NULL, null_cld);
     if (jb_module == NULL) {
       vm_exit_during_initialization("Unable to create ModuleEntry for " JAVA_BASE_NAME);
     }
@@ -1891,15 +1891,15 @@
       // Construct name without extension
       TempNewSymbol sym = SymbolTable::new_symbol(buffer, CHECK);
       // Use loader to load and initialize class
-      Klass* ik = SystemDictionary::resolve_or_null(sym, loader, Handle(), THREAD);
-      instanceKlassHandle k (THREAD, ik);
-      if (k.not_null() && !HAS_PENDING_EXCEPTION) {
+      Klass* k = SystemDictionary::resolve_or_null(sym, loader, Handle(), THREAD);
+      if (k != NULL && !HAS_PENDING_EXCEPTION) {
         k->initialize(THREAD);
       }
       bool exception_occurred = HAS_PENDING_EXCEPTION;
       clear_pending_exception_if_not_oom(CHECK);
-      if (CompileTheWorldPreloadClasses && k.not_null()) {
-        ConstantPool::preload_and_initialize_all_classes(k->constants(), THREAD);
+      if (CompileTheWorldPreloadClasses && k != NULL) {
+        InstanceKlass* ik = InstanceKlass::cast(k);
+        ConstantPool::preload_and_initialize_all_classes(ik->constants(), THREAD);
         if (HAS_PENDING_EXCEPTION) {
           // If something went wrong in preloading we just ignore it
           clear_pending_exception_if_not_oom(CHECK);
@@ -1908,7 +1908,7 @@
       }
 
       if (_compile_the_world_class_counter >= CompileTheWorldStartAt) {
-        if (k.is_null() || exception_occurred) {
+        if (k == NULL || exception_occurred) {
           // If something went wrong (e.g. ExceptionInInitializerError) we skip this class
           tty->print_cr("CompileTheWorld (%d) : Skipping %s", _compile_the_world_class_counter, buffer);
         } else {
@@ -1916,8 +1916,9 @@
           // Preload all classes to get around uncommon traps
           // Iterate over all methods in class
           int comp_level = CompilationPolicy::policy()->initial_compile_level();
-          for (int n = 0; n < k->methods()->length(); n++) {
-            methodHandle m (THREAD, k->methods()->at(n));
+          InstanceKlass* ik = InstanceKlass::cast(k);
+          for (int n = 0; n < ik->methods()->length(); n++) {
+            methodHandle m (THREAD, ik->methods()->at(n));
             if (can_be_compiled(m, comp_level)) {
               if (++_codecache_sweep_counter == CompileTheWorldSafepointInterval) {
                 // Give sweeper a chance to keep up with CTW
--- a/hotspot/src/share/vm/classfile/classLoader.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classLoader.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -371,7 +371,7 @@
                                                 const char* const file_name, TRAPS);
 
   // Load individual .class file
-  static instanceKlassHandle load_class(Symbol* class_name, bool search_append_only, TRAPS);
+  static InstanceKlass* load_class(Symbol* class_name, bool search_append_only, TRAPS);
 
   // If the specified package has been loaded by the system, then returns
   // the name of the directory or ZIP file that the package was loaded from.
--- a/hotspot/src/share/vm/classfile/classLoaderData.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classLoaderData.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -586,10 +586,9 @@
 // (boot, application/system or platform) class loaders. Note, the
 // builtin loaders are not freed by a GC.
 bool ClassLoaderData::is_builtin_class_loader_data() const {
-  Handle classLoaderHandle = class_loader();
   return (is_the_null_class_loader_data() ||
-          SystemDictionary::is_system_class_loader(classLoaderHandle) ||
-          SystemDictionary::is_platform_class_loader(classLoaderHandle));
+          SystemDictionary::is_system_class_loader(class_loader()) ||
+          SystemDictionary::is_platform_class_loader(class_loader()));
 }
 
 Metaspace* ClassLoaderData::metaspace_non_null() {
@@ -686,7 +685,8 @@
 // These anonymous class loaders are to contain classes used for JSR292
 ClassLoaderData* ClassLoaderData::anonymous_class_loader_data(oop loader, TRAPS) {
   // Add a new class loader data to the graph.
-  return ClassLoaderDataGraph::add(loader, true, THREAD);
+  Handle lh(THREAD, loader);
+  return ClassLoaderDataGraph::add(lh, true, THREAD);
 }
 
 const char* ClassLoaderData::loader_name() {
@@ -818,7 +818,7 @@
     // Include the result of loader.toString() in the output. This allows
     // the user of the log to identify the class loader instance.
     JavaValue result(T_OBJECT);
-    KlassHandle spec_klass(THREAD, SystemDictionary::ClassLoader_klass());
+    Klass* spec_klass = SystemDictionary::ClassLoader_klass();
     JavaCalls::call_virtual(&result,
                             loader,
                             spec_klass,
@@ -826,7 +826,7 @@
                             vmSymbols::void_string_signature(),
                             CHECK);
     assert(result.get_type() == T_OBJECT, "just checking");
-    string = (oop)result.get_jobject();
+    string = Handle(THREAD, (oop)result.get_jobject());
   }
 
   ResourceMark rm;
--- a/hotspot/src/share/vm/classfile/classLoaderData.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classLoaderData.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -284,7 +284,7 @@
     assert(ClassLoaderDataGraph::_head == NULL, "cannot initialize twice");
 
     // We explicitly initialize the Dependencies object at a later phase in the initialization
-    _the_null_class_loader_data = new ClassLoaderData((oop)NULL, false, Dependencies());
+    _the_null_class_loader_data = new ClassLoaderData(Handle(), false, Dependencies());
     ClassLoaderDataGraph::_head = _the_null_class_loader_data;
     assert(_the_null_class_loader_data->is_the_null_class_loader_data(), "Must be");
     if (DumpSharedSpaces) {
--- a/hotspot/src/share/vm/classfile/classLoaderExt.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classLoaderExt.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -49,10 +49,10 @@
       return false;
     }
 
-    instanceKlassHandle record_result(Symbol* class_name,
-                                      ClassPathEntry* e,
-                                      const s2 classpath_index,
-                                      instanceKlassHandle result, TRAPS) {
+    InstanceKlass* record_result(Symbol* class_name,
+                                 ClassPathEntry* e,
+                                 const s2 classpath_index,
+                                 InstanceKlass* result, TRAPS) {
       if (ClassLoader::add_package(_file_name, classpath_index, THREAD)) {
 #if INCLUDE_CDS
         if (DumpSharedSpaces) {
@@ -64,7 +64,7 @@
 #endif
         return result;
       } else {
-        return instanceKlassHandle(); // NULL
+        return NULL;
       }
     }
   };
--- a/hotspot/src/share/vm/classfile/dictionary.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/dictionary.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -46,7 +46,7 @@
 }
 
 Dictionary::Dictionary(int table_size)
-  : TwoOopHashtable<Klass*, mtClass>(table_size, (int)entry_size()) {
+  : TwoOopHashtable<InstanceKlass*, mtClass>(table_size, (int)entry_size()) {
   _current_class_index = 0;
   _current_class_entry = NULL;
   _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
@@ -55,19 +55,19 @@
 
 Dictionary::Dictionary(int table_size, HashtableBucket<mtClass>* t,
                        int number_of_entries)
-  : TwoOopHashtable<Klass*, mtClass>(table_size, (int)entry_size(), t, number_of_entries) {
+  : TwoOopHashtable<InstanceKlass*, mtClass>(table_size, (int)entry_size(), t, number_of_entries) {
   _current_class_index = 0;
   _current_class_entry = NULL;
   _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
 };
 
-ProtectionDomainCacheEntry* Dictionary::cache_get(oop protection_domain) {
+ProtectionDomainCacheEntry* Dictionary::cache_get(Handle protection_domain) {
   return _pd_cache_table->get(protection_domain);
 }
 
-DictionaryEntry* Dictionary::new_entry(unsigned int hash, Klass* klass,
+DictionaryEntry* Dictionary::new_entry(unsigned int hash, InstanceKlass* klass,
                                        ClassLoaderData* loader_data) {
-  DictionaryEntry* entry = (DictionaryEntry*)Hashtable<Klass*, mtClass>::new_entry(hash, klass);
+  DictionaryEntry* entry = (DictionaryEntry*)Hashtable<InstanceKlass*, mtClass>::new_entry(hash, klass);
   entry->set_loader_data(loader_data);
   entry->set_pd_set(NULL);
   assert(klass->is_instance_klass(), "Must be");
@@ -85,7 +85,7 @@
     entry->set_pd_set(to_delete->next());
     delete to_delete;
   }
-  Hashtable<Klass*, mtClass>::free_entry(entry);
+  Hashtable<InstanceKlass*, mtClass>::free_entry(entry);
 }
 
 
@@ -123,9 +123,9 @@
 }
 
 
-void DictionaryEntry::add_protection_domain(Dictionary* dict, oop protection_domain) {
+void DictionaryEntry::add_protection_domain(Dictionary* dict, Handle protection_domain) {
   assert_locked_or_safepoint(SystemDictionary_lock);
-  if (!contains_protection_domain(protection_domain)) {
+  if (!contains_protection_domain(protection_domain())) {
     ProtectionDomainCacheEntry* entry = dict->cache_get(protection_domain);
     ProtectionDomainEntry* new_head =
                 new ProtectionDomainEntry(entry, _pd_set);
@@ -351,10 +351,10 @@
   _pd_cache_table->unlink(is_alive);
 }
 
-Klass* Dictionary::try_get_next_class() {
+InstanceKlass* Dictionary::try_get_next_class() {
   while (true) {
     if (_current_class_entry != NULL) {
-      Klass* k = _current_class_entry->klass();
+      InstanceKlass* k = _current_class_entry->klass();
       _current_class_entry = _current_class_entry->next();
       return k;
     }
@@ -371,15 +371,15 @@
 // by the compilers.
 
 void Dictionary::add_klass(Symbol* class_name, ClassLoaderData* loader_data,
-                           KlassHandle obj) {
+                           InstanceKlass* obj) {
   assert_locked_or_safepoint(SystemDictionary_lock);
-  assert(obj() != NULL, "adding NULL obj");
-  assert(obj()->name() == class_name, "sanity check on name");
+  assert(obj != NULL, "adding NULL obj");
+  assert(obj->name() == class_name, "sanity check on name");
   assert(loader_data != NULL, "Must be non-NULL");
 
   unsigned int hash = compute_hash(class_name, loader_data);
   int index = hash_to_index(hash);
-  DictionaryEntry* entry = new_entry(hash, obj(), loader_data);
+  DictionaryEntry* entry = new_entry(hash, obj, loader_data);
   add_entry(index, entry);
 }
 
@@ -410,8 +410,8 @@
 }
 
 
-Klass* Dictionary::find(int index, unsigned int hash, Symbol* name,
-                          ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
+InstanceKlass* Dictionary::find(int index, unsigned int hash, Symbol* name,
+                                ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
   DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
   if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
     return entry->klass();
@@ -421,30 +421,30 @@
 }
 
 
-Klass* Dictionary::find_class(int index, unsigned int hash,
-                                Symbol* name, ClassLoaderData* loader_data) {
+InstanceKlass* Dictionary::find_class(int index, unsigned int hash,
+                                      Symbol* name, ClassLoaderData* loader_data) {
   assert_locked_or_safepoint(SystemDictionary_lock);
   assert (index == index_for(name, loader_data), "incorrect index?");
 
   DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
-  return (entry != NULL) ? entry->klass() : (Klass*)NULL;
+  return (entry != NULL) ? entry->klass() : NULL;
 }
 
 
 // Variant of find_class for shared classes.  No locking required, as
 // that table is static.
 
-Klass* Dictionary::find_shared_class(int index, unsigned int hash,
-                                       Symbol* name) {
+InstanceKlass* Dictionary::find_shared_class(int index, unsigned int hash,
+                                             Symbol* name) {
   assert (index == index_for(name, NULL), "incorrect index?");
 
   DictionaryEntry* entry = get_entry(index, hash, name, NULL);
-  return (entry != NULL) ? entry->klass() : (Klass*)NULL;
+  return (entry != NULL) ? entry->klass() : NULL;
 }
 
 
 void Dictionary::add_protection_domain(int index, unsigned int hash,
-                                       instanceKlassHandle klass,
+                                       InstanceKlass* klass,
                                        ClassLoaderData* loader_data, Handle protection_domain,
                                        TRAPS) {
   Symbol*  klass_name = klass->name();
@@ -454,7 +454,7 @@
   assert(protection_domain() != NULL,
          "real protection domain should be present");
 
-  entry->add_protection_domain(this, protection_domain());
+  entry->add_protection_domain(this, protection_domain);
 
   assert(entry->contains_protection_domain(protection_domain()),
          "now protection domain should be present");
@@ -505,11 +505,12 @@
 }
 
 
-unsigned int ProtectionDomainCacheTable::compute_hash(oop protection_domain) {
+unsigned int ProtectionDomainCacheTable::compute_hash(Handle protection_domain) {
+  // Identity hash can safepoint, so keep protection domain in a Handle.
   return (unsigned int)(protection_domain->identity_hash());
 }
 
-int ProtectionDomainCacheTable::index_for(oop protection_domain) {
+int ProtectionDomainCacheTable::index_for(Handle protection_domain) {
   return hash_to_index(compute_hash(protection_domain));
 }
 
@@ -619,7 +620,7 @@
   }
 }
 
-ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(oop protection_domain) {
+ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(Handle protection_domain) {
   unsigned int hash = compute_hash(protection_domain);
   int index = hash_to_index(hash);
 
@@ -630,9 +631,9 @@
   return entry;
 }
 
-ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, oop protection_domain) {
+ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, Handle protection_domain) {
   for (ProtectionDomainCacheEntry* e = bucket(index); e != NULL; e = e->next()) {
-    if (e->protection_domain() == protection_domain) {
+    if (e->protection_domain() == protection_domain()) {
       return e;
     }
   }
@@ -640,7 +641,7 @@
   return NULL;
 }
 
-ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, unsigned int hash, oop protection_domain) {
+ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, unsigned int hash, Handle protection_domain) {
   assert_locked_or_safepoint(SystemDictionary_lock);
   assert(index == index_for(protection_domain), "incorrect index?");
   assert(find_entry(index, protection_domain) == NULL, "no double entry");
@@ -651,7 +652,7 @@
 }
 
 void ProtectionDomainCacheTable::free(ProtectionDomainCacheEntry* to_delete) {
-  unsigned int hash = compute_hash(to_delete->protection_domain());
+  unsigned int hash = compute_hash(Handle(Thread::current(), to_delete->protection_domain()));
   int index = hash_to_index(hash);
 
   ProtectionDomainCacheEntry** p = bucket_addr(index);
@@ -731,7 +732,6 @@
 
 void Dictionary::print(bool details) {
   ResourceMark rm;
-  HandleMark   hm;
 
   if (details) {
     tty->print_cr("Java system dictionary (table_size=%d, classes=%d)",
@@ -777,7 +777,6 @@
 void Dictionary::printPerformanceInfoDetails() {
   if (log_is_enabled(Info, hashtables)) {
     ResourceMark rm;
-    HandleMark   hm;
 
     log_info(hashtables)(" ");
     log_info(hashtables)("Java system dictionary (table_size=%d, classes=%d)",
--- a/hotspot/src/share/vm/classfile/dictionary.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/dictionary.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,7 +41,7 @@
 // The data structure for the system dictionary (and the shared system
 // dictionary).
 
-class Dictionary : public TwoOopHashtable<Klass*, mtClass> {
+class Dictionary : public TwoOopHashtable<InstanceKlass*, mtClass> {
   friend class VMStructs;
 private:
   // current iteration index.
@@ -56,16 +56,16 @@
 
 protected:
   DictionaryEntry* bucket(int i) const {
-    return (DictionaryEntry*)Hashtable<Klass*, mtClass>::bucket(i);
+    return (DictionaryEntry*)Hashtable<InstanceKlass*, mtClass>::bucket(i);
   }
 
   // The following method is not MT-safe and must be done under lock.
   DictionaryEntry** bucket_addr(int i) {
-    return (DictionaryEntry**)Hashtable<Klass*, mtClass>::bucket_addr(i);
+    return (DictionaryEntry**)Hashtable<InstanceKlass*, mtClass>::bucket_addr(i);
   }
 
   void add_entry(int index, DictionaryEntry* new_entry) {
-    Hashtable<Klass*, mtClass>::add_entry(index, (HashtableEntry<Klass*, mtClass>*)new_entry);
+    Hashtable<InstanceKlass*, mtClass>::add_entry(index, (HashtableEntry<InstanceKlass*, mtClass>*)new_entry);
   }
 
   static size_t entry_size();
@@ -73,21 +73,21 @@
   Dictionary(int table_size);
   Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries);
 
-  DictionaryEntry* new_entry(unsigned int hash, Klass* klass, ClassLoaderData* loader_data);
+  DictionaryEntry* new_entry(unsigned int hash, InstanceKlass* klass, ClassLoaderData* loader_data);
 
   DictionaryEntry* new_entry();
 
   void free_entry(DictionaryEntry* entry);
 
-  void add_klass(Symbol* class_name, ClassLoaderData* loader_data,KlassHandle obj);
+  void add_klass(Symbol* class_name, ClassLoaderData* loader_data, InstanceKlass* obj);
 
-  Klass* find_class(int index, unsigned int hash,
-                      Symbol* name, ClassLoaderData* loader_data);
+  InstanceKlass* find_class(int index, unsigned int hash,
+                            Symbol* name, ClassLoaderData* loader_data);
 
-  Klass* find_shared_class(int index, unsigned int hash, Symbol* name);
+  InstanceKlass* find_shared_class(int index, unsigned int hash, Symbol* name);
 
   // Compiler support
-  Klass* try_get_next_class();
+  InstanceKlass* try_get_next_class();
 
   // GC support
   void oops_do(OopClosure* f);
@@ -116,19 +116,19 @@
   void do_unloading();
 
   // Protection domains
-  Klass* find(int index, unsigned int hash, Symbol* name,
-                ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
+  InstanceKlass* find(int index, unsigned int hash, Symbol* name,
+                      ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
   bool is_valid_protection_domain(int index, unsigned int hash,
                                   Symbol* name, ClassLoaderData* loader_data,
                                   Handle protection_domain);
   void add_protection_domain(int index, unsigned int hash,
-                             instanceKlassHandle klass, ClassLoaderData* loader_data,
+                             InstanceKlass* klass, ClassLoaderData* loader_data,
                              Handle protection_domain, TRAPS);
 
   // Sharing support
   void reorder_dictionary();
 
-  ProtectionDomainCacheEntry* cache_get(oop protection_domain);
+  ProtectionDomainCacheEntry* cache_get(Handle protection_domain);
 
   void print(bool details = true);
 #ifdef ASSERT
@@ -194,23 +194,23 @@
     return (ProtectionDomainCacheEntry**) Hashtable<oop, mtClass>::bucket_addr(i);
   }
 
-  ProtectionDomainCacheEntry* new_entry(unsigned int hash, oop protection_domain) {
-    ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain);
+  ProtectionDomainCacheEntry* new_entry(unsigned int hash, Handle protection_domain) {
+    ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain());
     entry->init();
     return entry;
   }
 
-  static unsigned int compute_hash(oop protection_domain);
+  static unsigned int compute_hash(Handle protection_domain);
 
-  int index_for(oop protection_domain);
-  ProtectionDomainCacheEntry* add_entry(int index, unsigned int hash, oop protection_domain);
-  ProtectionDomainCacheEntry* find_entry(int index, oop protection_domain);
+  int index_for(Handle protection_domain);
+  ProtectionDomainCacheEntry* add_entry(int index, unsigned int hash, Handle protection_domain);
+  ProtectionDomainCacheEntry* find_entry(int index, Handle protection_domain);
 
 public:
 
   ProtectionDomainCacheTable(int table_size);
 
-  ProtectionDomainCacheEntry* get(oop protection_domain);
+  ProtectionDomainCacheEntry* get(Handle protection_domain);
   void free(ProtectionDomainCacheEntry* entry);
 
   void unlink(BoolObjectClosure* cl);
@@ -243,9 +243,9 @@
 };
 
 // An entry in the system dictionary, this describes a class as
-// { Klass*, loader, protection_domain }.
+// { InstanceKlass*, loader, protection_domain }.
 
-class DictionaryEntry : public HashtableEntry<Klass*, mtClass> {
+class DictionaryEntry : public HashtableEntry<InstanceKlass*, mtClass> {
   friend class VMStructs;
  private:
   // Contains the set of approved protection domains that can access
@@ -275,17 +275,17 @@
   // Tells whether a protection is in the approved set.
   bool contains_protection_domain(oop protection_domain) const;
   // Adds a protection domain to the approved set.
-  void add_protection_domain(Dictionary* dict, oop protection_domain);
+  void add_protection_domain(Dictionary* dict, Handle protection_domain);
 
-  Klass* klass() const { return (Klass*)literal(); }
-  Klass** klass_addr() { return (Klass**)literal_addr(); }
+  InstanceKlass* klass() const { return (InstanceKlass*)literal(); }
+  InstanceKlass** klass_addr() { return (InstanceKlass**)literal_addr(); }
 
   DictionaryEntry* next() const {
-    return (DictionaryEntry*)HashtableEntry<Klass*, mtClass>::next();
+    return (DictionaryEntry*)HashtableEntry<InstanceKlass*, mtClass>::next();
   }
 
   DictionaryEntry** next_addr() {
-    return (DictionaryEntry**)HashtableEntry<Klass*, mtClass>::next_addr();
+    return (DictionaryEntry**)HashtableEntry<InstanceKlass*, mtClass>::next_addr();
   }
 
   ClassLoaderData* loader_data() const { return _loader_data; }
@@ -323,7 +323,7 @@
   }
 
   bool equals(const Symbol* class_name, ClassLoaderData* loader_data) const {
-    Klass* klass = (Klass*)literal();
+    InstanceKlass* klass = (InstanceKlass*)literal();
     return (klass->name() == class_name && _loader_data == loader_data);
   }
 
--- a/hotspot/src/share/vm/classfile/javaAssertions.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/javaAssertions.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -96,7 +96,7 @@
 oop JavaAssertions::createAssertionStatusDirectives(TRAPS) {
   Symbol* asd_sym = vmSymbols::java_lang_AssertionStatusDirectives();
   Klass* k = SystemDictionary::resolve_or_fail(asd_sym, true, CHECK_NULL);
-  instanceKlassHandle asd_klass (THREAD, k);
+  InstanceKlass* asd_klass = InstanceKlass::cast(k);
   asd_klass->initialize(CHECK_NULL);
   Handle h = asd_klass->allocate_instance_handle(CHECK_NULL);
 
--- a/hotspot/src/share/vm/classfile/javaClasses.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/javaClasses.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -514,11 +514,10 @@
   return result;
 }
 
-Symbol* java_lang_String::as_symbol(Handle java_string, TRAPS) {
-  oop          obj    = java_string();
-  typeArrayOop value  = java_lang_String::value(obj);
-  int          length = java_lang_String::length(obj);
-  bool      is_latin1 = java_lang_String::is_latin1(obj);
+Symbol* java_lang_String::as_symbol(oop java_string, TRAPS) {
+  typeArrayOop value  = java_lang_String::value(java_string);
+  int          length = java_lang_String::length(java_string);
+  bool      is_latin1 = java_lang_String::is_latin1(java_string);
   if (!is_latin1) {
     jchar* base = (length == 0) ? NULL : value->char_at_addr(0);
     Symbol* sym = SymbolTable::lookup_unicode(base, length, THREAD);
@@ -736,7 +735,7 @@
 }
 
 
-void java_lang_Class::fixup_mirror(KlassHandle k, TRAPS) {
+void java_lang_Class::fixup_mirror(Klass* k, TRAPS) {
   assert(InstanceMirrorKlass::offset_of_static_fields() != 0, "must have been computed already");
 
   // If the offset was read from the shared archive, it was fixed up already
@@ -745,7 +744,7 @@
       // During bootstrap, java.lang.Class wasn't loaded so static field
       // offsets were computed without the size added it.  Go back and
       // update all the static field offsets to included the size.
-        for (JavaFieldStream fs(InstanceKlass::cast(k())); !fs.done(); fs.next()) {
+        for (JavaFieldStream fs(InstanceKlass::cast(k)); !fs.done(); fs.next()) {
         if (fs.access_flags().is_static()) {
           int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields();
           fs.set_offset(real_offset);
@@ -753,10 +752,10 @@
       }
     }
   }
-  create_mirror(k, Handle(NULL), Handle(NULL), Handle(NULL), CHECK);
-}
-
-void java_lang_Class::initialize_mirror_fields(KlassHandle k,
+  create_mirror(k, Handle(), Handle(), Handle(), CHECK);
+}
+
+void java_lang_Class::initialize_mirror_fields(Klass* k,
                                                Handle mirror,
                                                Handle protection_domain,
                                                TRAPS) {
@@ -770,11 +769,11 @@
   set_protection_domain(mirror(), protection_domain());
 
   // Initialize static fields
-  InstanceKlass::cast(k())->do_local_static_fields(&initialize_static_field, mirror, CHECK);
+  InstanceKlass::cast(k)->do_local_static_fields(&initialize_static_field, mirror, CHECK);
 }
 
 // Set the java.lang.reflect.Module module field in the java_lang_Class mirror
-void java_lang_Class::set_mirror_module_field(KlassHandle k, Handle mirror, Handle module, TRAPS) {
+void java_lang_Class::set_mirror_module_field(Klass* k, Handle mirror, Handle module, TRAPS) {
   if (module.is_null()) {
     // During startup, the module may be NULL only if java.base has not been defined yet.
     // Put the class on the fixup_module_list to patch later when the java.lang.reflect.Module
@@ -792,7 +791,7 @@
           set_fixup_module_field_list(list);
         }
         k->class_loader_data()->inc_keep_alive();
-        fixup_module_field_list()->push(k());
+        fixup_module_field_list()->push(k);
       } else {
         javabase_was_defined = true;
       }
@@ -815,7 +814,7 @@
   }
 }
 
-void java_lang_Class::create_mirror(KlassHandle k, Handle class_loader,
+void java_lang_Class::create_mirror(Klass* k, Handle class_loader,
                                     Handle module, Handle protection_domain, TRAPS) {
   assert(k->java_mirror() == NULL, "should only assign mirror once");
   // Use this moment of initialization to cache modifier_flags also,
@@ -828,11 +827,12 @@
   // the mirror.
   if (SystemDictionary::Class_klass_loaded()) {
     // Allocate mirror (java.lang.Class instance)
-    Handle mirror = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
+    oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
+    Handle mirror(THREAD, mirror_oop);
 
     // Setup indirection from mirror->klass
-    if (!k.is_null()) {
-      java_lang_Class::set_klass(mirror(), k());
+    if (k != NULL) {
+      java_lang_Class::set_klass(mirror(), k);
     }
 
     InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
@@ -842,22 +842,22 @@
 
     // It might also have a component mirror.  This mirror must already exist.
     if (k->is_array_klass()) {
-      Handle comp_mirror;
+      oop comp_mirror;
       if (k->is_typeArray_klass()) {
-        BasicType type = TypeArrayKlass::cast(k())->element_type();
+        BasicType type = TypeArrayKlass::cast(k)->element_type();
         comp_mirror = Universe::java_mirror(type);
       } else {
         assert(k->is_objArray_klass(), "Must be");
-        Klass* element_klass = ObjArrayKlass::cast(k())->element_klass();
+        Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
         assert(element_klass != NULL, "Must have an element klass");
         comp_mirror = element_klass->java_mirror();
       }
-      assert(comp_mirror.not_null(), "must have a mirror");
+      assert(comp_mirror != NULL, "must have a mirror");
 
       // Two-way link between the array klass and its component mirror:
       // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
-      set_component_mirror(mirror(), comp_mirror());
-      set_array_klass(comp_mirror(), k());
+      set_component_mirror(mirror(), comp_mirror);
+      set_array_klass(comp_mirror, k);
     } else {
       assert(k->is_instance_klass(), "Must be");
 
@@ -881,7 +881,7 @@
 
     // Setup indirection from klass->mirror last
     // after any exceptions can happen during allocations.
-    if (!k.is_null()) {
+    if (k != NULL) {
       k->set_java_mirror(mirror());
     }
   } else {
@@ -890,11 +890,11 @@
        new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true);
       set_fixup_mirror_list(list);
     }
-    fixup_mirror_list()->push(k());
+    fixup_mirror_list()->push(k);
   }
 }
 
-void java_lang_Class::fixup_module_field(KlassHandle k, Handle module) {
+void java_lang_Class::fixup_module_field(Klass* k, Handle module) {
   assert(_module_offset != 0, "must have been computed already");
   java_lang_Class::set_module(k->java_mirror(), module());
 }
@@ -1518,7 +1518,7 @@
   throwable->int_field_put(depth_offset, value);
 }
 
-oop java_lang_Throwable::message(Handle throwable) {
+oop java_lang_Throwable::message(oop throwable) {
   return throwable->obj_field(detailMessage_offset);
 }
 
@@ -1547,7 +1547,7 @@
 }
 
 
-void java_lang_Throwable::print(Handle throwable, outputStream* st) {
+void java_lang_Throwable::print(oop throwable, outputStream* st) {
   ResourceMark rm;
   Klass* k = throwable->klass();
   assert(k != NULL, "just checking");
@@ -1578,7 +1578,7 @@
   typeArrayOop    _methods;
   typeArrayOop    _bcis;
   objArrayOop     _mirrors;
-  typeArrayOop    _cprefs; // needed to insulate method name against redefinition
+  typeArrayOop    _names; // needed to insulate method name against redefinition
   int             _index;
   NoSafepointVerifier _nsv;
 
@@ -1586,7 +1586,7 @@
     trace_methods_offset = java_lang_Throwable::trace_methods_offset,
     trace_bcis_offset    = java_lang_Throwable::trace_bcis_offset,
     trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset,
-    trace_cprefs_offset  = java_lang_Throwable::trace_cprefs_offset,
+    trace_names_offset   = java_lang_Throwable::trace_names_offset,
     trace_next_offset    = java_lang_Throwable::trace_next_offset,
     trace_size           = java_lang_Throwable::trace_size,
     trace_chunk_size     = java_lang_Throwable::trace_chunk_size
@@ -1608,32 +1608,34 @@
     assert(mirrors != NULL, "mirror array should be initialized in backtrace");
     return mirrors;
   }
-  static typeArrayOop get_cprefs(objArrayHandle chunk) {
-    typeArrayOop cprefs = typeArrayOop(chunk->obj_at(trace_cprefs_offset));
-    assert(cprefs != NULL, "cprefs array should be initialized in backtrace");
-    return cprefs;
+  static typeArrayOop get_names(objArrayHandle chunk) {
+    typeArrayOop names = typeArrayOop(chunk->obj_at(trace_names_offset));
+    assert(names != NULL, "names array should be initialized in backtrace");
+    return names;
   }
 
  public:
 
   // constructor for new backtrace
-  BacktraceBuilder(TRAPS): _methods(NULL), _bcis(NULL), _head(NULL), _mirrors(NULL), _cprefs(NULL) {
+  BacktraceBuilder(TRAPS): _methods(NULL), _bcis(NULL), _head(NULL), _mirrors(NULL), _names(NULL) {
     expand(CHECK);
-    _backtrace = _head;
+    _backtrace = Handle(THREAD, _head);
     _index = 0;
   }
 
-  BacktraceBuilder(objArrayHandle backtrace) {
+  BacktraceBuilder(Thread* thread, objArrayHandle backtrace) {
     _methods = get_methods(backtrace);
     _bcis = get_bcis(backtrace);
     _mirrors = get_mirrors(backtrace);
-    _cprefs = get_cprefs(backtrace);
+    _names = get_names(backtrace);
     assert(_methods->length() == _bcis->length() &&
-           _methods->length() == _mirrors->length(),
+           _methods->length() == _mirrors->length() &&
+           _mirrors->length() == _names->length(),
            "method and source information arrays should match");
 
     // head is the preallocated backtrace
-    _backtrace = _head = backtrace();
+    _head = backtrace();
+    _backtrace = Handle(thread, _head);
     _index = 0;
   }
 
@@ -1653,8 +1655,8 @@
     objArrayOop mirrors = oopFactory::new_objectArray(trace_chunk_size, CHECK);
     objArrayHandle new_mirrors(THREAD, mirrors);
 
-    typeArrayOop cprefs = oopFactory::new_shortArray(trace_chunk_size, CHECK);
-    typeArrayHandle new_cprefs(THREAD, cprefs);
+    typeArrayOop names = oopFactory::new_symbolArray(trace_chunk_size, CHECK);
+    typeArrayHandle new_names(THREAD, names);
 
     if (!old_head.is_null()) {
       old_head->obj_at_put(trace_next_offset, new_head());
@@ -1662,13 +1664,13 @@
     new_head->obj_at_put(trace_methods_offset, new_methods());
     new_head->obj_at_put(trace_bcis_offset, new_bcis());
     new_head->obj_at_put(trace_mirrors_offset, new_mirrors());
-    new_head->obj_at_put(trace_cprefs_offset, new_cprefs());
+    new_head->obj_at_put(trace_names_offset, new_names());
 
     _head    = new_head();
     _methods = new_methods();
     _bcis = new_bcis();
     _mirrors = new_mirrors();
-    _cprefs  = new_cprefs();
+    _names  = new_names();
     _index = 0;
   }
 
@@ -1690,7 +1692,11 @@
 
     _methods->short_at_put(_index, method->orig_method_idnum());
     _bcis->int_at_put(_index, Backtrace::merge_bci_and_version(bci, method->constants()->version()));
-    _cprefs->short_at_put(_index, method->name_index());
+
+    // Note:this doesn't leak symbols because the mirror in the backtrace keeps the
+    // klass owning the symbols alive so their refcounts aren't decremented.
+    Symbol* name = method->name();
+    _names->symbol_at_put(_index, name);
 
     // We need to save the mirrors in the backtrace to keep the class
     // from being unloaded while we still have this stack trace.
@@ -1705,10 +1711,10 @@
   int _method_id;
   int _bci;
   int _version;
-  int _cpref;
+  Symbol* _name;
   Handle _mirror;
-  BacktraceElement(Handle mirror, int mid, int version, int bci, int cpref) :
-                   _mirror(mirror), _method_id(mid), _version(version), _bci(bci), _cpref(cpref) {}
+  BacktraceElement(Handle mirror, int mid, int version, int bci, Symbol* name) :
+                   _mirror(mirror), _method_id(mid), _version(version), _bci(bci), _name(name) {}
 };
 
 class BacktraceIterator : public StackObj {
@@ -1717,7 +1723,7 @@
   objArrayHandle  _mirrors;
   typeArrayHandle _methods;
   typeArrayHandle _bcis;
-  typeArrayHandle _cprefs;
+  typeArrayHandle _names;
 
   void init(objArrayHandle result, Thread* thread) {
     // Get method id, bci, version and mirror from chunk
@@ -1726,7 +1732,7 @@
       _methods = typeArrayHandle(thread, BacktraceBuilder::get_methods(_result));
       _bcis = typeArrayHandle(thread, BacktraceBuilder::get_bcis(_result));
       _mirrors = objArrayHandle(thread, BacktraceBuilder::get_mirrors(_result));
-      _cprefs = typeArrayHandle(thread, BacktraceBuilder::get_cprefs(_result));
+      _names = typeArrayHandle(thread, BacktraceBuilder::get_names(_result));
       _index = 0;
     }
   }
@@ -1741,7 +1747,7 @@
                         _methods->short_at(_index),
                         Backtrace::version_at(_bcis->int_at(_index)),
                         Backtrace::bci_at(_bcis->int_at(_index)),
-                        _cprefs->short_at(_index));
+                        _names->symbol_at(_index));
     _index++;
 
     if (_index >= java_lang_Throwable::trace_chunk_size) {
@@ -1761,7 +1767,7 @@
 
 // Print stack trace element to resource allocated buffer
 static void print_stack_element_to_stream(outputStream* st, Handle mirror, int method_id,
-                                          int version, int bci, int cpref) {
+                                          int version, int bci, Symbol* name) {
   ResourceMark rm;
 
   // Get strings and string lengths
@@ -1769,11 +1775,7 @@
   const char* klass_name  = holder->external_name();
   int buf_len = (int)strlen(klass_name);
 
-  Method* method = holder->method_with_orig_idnum(method_id, version);
-
-  // The method can be NULL if the requested class version is gone
-  Symbol* sym = (method != NULL) ? method->name() : holder->constants()->symbol_at(cpref);
-  char* method_name = sym->as_C_string();
+  char* method_name = name->as_C_string();
   buf_len += (int)strlen(method_name);
 
   char* source_file_name = NULL;
@@ -1809,6 +1811,8 @@
     }
   }
 
+  // The method can be NULL if the requested class version is gone
+  Method* method = holder->method_with_orig_idnum(method_id, version);
   if (!version_matches(method, version)) {
     strcat(buf, "Redefined)");
   } else {
@@ -1837,11 +1841,10 @@
 }
 
 void java_lang_Throwable::print_stack_element(outputStream *st, const methodHandle& method, int bci) {
-  Handle mirror = method->method_holder()->java_mirror();
+  Handle mirror (Thread::current(),  method->method_holder()->java_mirror());
   int method_id = method->orig_method_idnum();
   int version = method->constants()->version();
-  int cpref = method->name_index();
-  print_stack_element_to_stream(st, mirror, method_id, version, bci, cpref);
+  print_stack_element_to_stream(st, mirror, method_id, version, bci, method->name());
 }
 
 /**
@@ -1850,7 +1853,7 @@
  */
 void java_lang_Throwable::print_stack_trace(Handle throwable, outputStream* st) {
   // First, print the message.
-  print(throwable, st);
+  print(throwable(), st);
   st->cr();
 
   // Now print the stack trace.
@@ -1865,7 +1868,7 @@
 
     while (iter.repeat()) {
       BacktraceElement bte = iter.next(THREAD);
-      print_stack_element_to_stream(st, bte._mirror, bte._method_id, bte._version, bte._bci, bte._cpref);
+      print_stack_element_to_stream(st, bte._mirror, bte._method_id, bte._version, bte._bci, bte._name);
     }
     {
       // Call getCause() which doesn't necessarily return the _cause field.
@@ -1873,7 +1876,7 @@
       JavaValue cause(T_OBJECT);
       JavaCalls::call_virtual(&cause,
                               throwable,
-                              KlassHandle(THREAD, throwable->klass()),
+                              throwable->klass(),
                               vmSymbols::getCause_name(),
                               vmSymbols::void_throwable_signature(),
                               THREAD);
@@ -1885,7 +1888,7 @@
         throwable = Handle(THREAD, (oop) cause.get_jobject());
         if (throwable.not_null()) {
           st->print("Caused by: ");
-          print(throwable, st);
+          print(throwable(), st);
           st->cr();
         }
       }
@@ -1901,7 +1904,7 @@
   JavaValue result(T_VOID);
   JavaCalls::call_virtual(&result,
                           throwable,
-                          KlassHandle(THREAD, SystemDictionary::Throwable_klass()),
+                          SystemDictionary::Throwable_klass(),
                           vmSymbols::printStackTrace_name(),
                           vmSymbols::void_method_signature(),
                           THREAD);
@@ -2089,7 +2092,7 @@
   ResourceMark rm(THREAD);
   vframeStream st(THREAD);
 
-  BacktraceBuilder bt(backtrace);
+  BacktraceBuilder bt(THREAD, backtrace);
 
   // Unlike fill_in_stack_trace we do not skip fillInStackTrace or throwable init
   // methods as preallocated errors aren't created by "java" code.
@@ -2144,30 +2147,28 @@
                                          method,
                                          bte._version,
                                          bte._bci,
-                                         bte._cpref, CHECK);
+                                         bte._name, CHECK);
   }
 }
 
 oop java_lang_StackTraceElement::create(const methodHandle& method, int bci, TRAPS) {
   // Allocate java.lang.StackTraceElement instance
-  Klass* k = SystemDictionary::StackTraceElement_klass();
+  InstanceKlass* k = SystemDictionary::StackTraceElement_klass();
   assert(k != NULL, "must be loaded in 1.4+");
-  instanceKlassHandle ik (THREAD, k);
-  if (ik->should_be_initialized()) {
-    ik->initialize(CHECK_0);
+  if (k->should_be_initialized()) {
+    k->initialize(CHECK_0);
   }
 
-  Handle element = ik->allocate_instance_handle(CHECK_0);
-
-  int cpref = method->name_index();
+  Handle element = k->allocate_instance_handle(CHECK_0);
+
   int version = method->constants()->version();
-  fill_in(element, method->method_holder(), method, version, bci, cpref, CHECK_0);
+  fill_in(element, method->method_holder(), method, version, bci, method->name(), CHECK_0);
   return element();
 }
 
 void java_lang_StackTraceElement::fill_in(Handle element,
                                           InstanceKlass* holder, const methodHandle& method,
-                                          int version, int bci, int cpref, TRAPS) {
+                                          int version, int bci, Symbol* name, TRAPS) {
   assert(element->is_a(SystemDictionary::StackTraceElement_klass()), "sanity check");
 
   // Fill in class name
@@ -2184,11 +2185,8 @@
       java_lang_StackTraceElement::set_classLoaderName(element(), loader_name);
   }
 
-  // The method can be NULL if the requested class version is gone
-  Symbol* sym = !method.is_null() ? method->name() : holder->constants()->symbol_at(cpref);
-
   // Fill in method name
-  oop methodname = StringTable::intern(sym, CHECK);
+  oop methodname = StringTable::intern(name, CHECK);
   java_lang_StackTraceElement::set_methodName(element(), methodname);
 
   // Fill in module name and version
@@ -2205,7 +2203,7 @@
     java_lang_StackTraceElement::set_moduleVersion(element(), module_version);
   }
 
-  if (!version_matches(method(), version)) {
+  if (method() == NULL || !version_matches(method(), version)) {
     // The method was redefined, accurate line number information isn't available
     java_lang_StackTraceElement::set_fileName(element(), NULL);
     java_lang_StackTraceElement::set_lineNumber(element(), -1);
@@ -2232,7 +2230,7 @@
 
 void java_lang_StackFrameInfo::set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci) {
   // set Method* or mid/cpref
-  oop mname = stackFrame->obj_field(_memberName_offset);
+  Handle mname(Thread::current(), stackFrame->obj_field(_memberName_offset));
   InstanceKlass* ik = method->method_holder();
   CallInfo info(method(), ik);
   MethodHandles::init_method_MemberName(mname, info);
@@ -2252,8 +2250,8 @@
 
   short version = stackFrame->short_field(_version_offset);
   short bci = stackFrame->short_field(_bci_offset);
-  int cpref = method->name_index();
-  java_lang_StackTraceElement::fill_in(stack_trace_element, holder, method, version, bci, cpref, CHECK);
+  Symbol* name = method->name();
+  java_lang_StackTraceElement::fill_in(stack_trace_element, holder, method, version, bci, name, CHECK);
 }
 
 void java_lang_StackFrameInfo::compute_offsets() {
@@ -2490,10 +2488,10 @@
   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
   Symbol* name = vmSymbols::java_lang_reflect_Constructor();
   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
-  instanceKlassHandle klass (THREAD, k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
   // Ensure it is initialized
-  klass->initialize(CHECK_NH);
-  return klass->allocate_instance_handle(THREAD);
+  ik->initialize(CHECK_NH);
+  return ik->allocate_instance_handle(THREAD);
 }
 
 oop java_lang_reflect_Constructor::clazz(oop reflect) {
@@ -2630,10 +2628,10 @@
   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
   Symbol* name = vmSymbols::java_lang_reflect_Field();
   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
-  instanceKlassHandle klass (THREAD, k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
   // Ensure it is initialized
-  klass->initialize(CHECK_NH);
-  return klass->allocate_instance_handle(THREAD);
+  ik->initialize(CHECK_NH);
+  return ik->allocate_instance_handle(THREAD);
 }
 
 oop java_lang_reflect_Field::clazz(oop reflect) {
@@ -2757,10 +2755,10 @@
   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
   Symbol* name = vmSymbols::java_lang_reflect_Parameter();
   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
-  instanceKlassHandle klass (THREAD, k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
   // Ensure it is initialized
-  klass->initialize(CHECK_NH);
-  return klass->allocate_instance_handle(THREAD);
+  ik->initialize(CHECK_NH);
+  return ik->allocate_instance_handle(THREAD);
 }
 
 oop java_lang_reflect_Parameter::name(oop param) {
@@ -2813,11 +2811,10 @@
 
   Symbol* name = vmSymbols::java_lang_reflect_Module();
   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
-  instanceKlassHandle klass (THREAD, k);
-
-  Handle jlrmh = klass->allocate_instance_handle(CHECK_NH);
+  InstanceKlass* ik = InstanceKlass::cast(k);
+  Handle jlrmh = ik->allocate_instance_handle(CHECK_NH);
   JavaValue result(T_VOID);
-  JavaCalls::call_special(&result, jlrmh, KlassHandle(THREAD, klass()),
+  JavaCalls::call_special(&result, jlrmh, ik,
                           vmSymbols::object_initializer_name(),
                           vmSymbols::java_lang_reflect_module_init_signature(),
                           loader, module_name, CHECK_NH);
@@ -2880,11 +2877,10 @@
 
 Handle reflect_ConstantPool::create(TRAPS) {
   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
-  Klass* k = SystemDictionary::reflect_ConstantPool_klass();
-  instanceKlassHandle klass (THREAD, k);
+  InstanceKlass* k = SystemDictionary::reflect_ConstantPool_klass();
   // Ensure it is initialized
-  klass->initialize(CHECK_NH);
-  return klass->allocate_instance_handle(THREAD);
+  k->initialize(CHECK_NH);
+  return k->allocate_instance_handle(THREAD);
 }
 
 
@@ -2922,9 +2918,9 @@
 oop java_lang_boxing_object::initialize_and_allocate(BasicType type, TRAPS) {
   Klass* k = SystemDictionary::box_klass(type);
   if (k == NULL)  return NULL;
-  instanceKlassHandle h (THREAD, k);
-  if (!h->is_initialized())  h->initialize(CHECK_0);
-  return h->allocate_instance(THREAD);
+  InstanceKlass* ik = InstanceKlass::cast(k);
+  if (!ik->is_initialized())  ik->initialize(CHECK_0);
+  return ik->allocate_instance(THREAD);
 }
 
 
@@ -3895,10 +3891,10 @@
   fieldDescriptor fd;
   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
-  instanceKlassHandle h_klass (THREAD, k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
-  if (!h_klass->find_local_field(f_name, f_sig, &fd)) {
+  if (!ik->find_local_field(f_name, f_sig, &fd)) {
     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);
     return false;
   }
@@ -3921,10 +3917,10 @@
   fieldDescriptor fd;
   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
-  instanceKlassHandle h_klass (THREAD, k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
-  if (!h_klass->find_local_field(f_name, f_sig, &fd)) {
+  if (!ik->find_local_field(f_name, f_sig, &fd)) {
     tty->print_cr("Static field %s.%s not found", klass_name, field_name);
     return false;
   }
@@ -3946,10 +3942,10 @@
   fieldDescriptor fd;
   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
-  instanceKlassHandle h_klass (THREAD, k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
-  if (!h_klass->find_local_field(f_name, f_sig, &fd)) {
+  if (!ik->find_local_field(f_name, f_sig, &fd)) {
     tty->print_cr("Static field %s.%s not found", klass_name, field_name);
     return false;
   }
@@ -3975,7 +3971,6 @@
 
 void JavaClasses::check_offsets() {
   bool valid = true;
-  HandleMark hm;
 
 #define CHECK_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
   valid &= check_offset(klass_name, cpp_klass_name :: field_name ## _offset, #field_name, field_sig)
--- a/hotspot/src/share/vm/classfile/javaClasses.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/javaClasses.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -155,7 +155,7 @@
   static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
 
   // Conversion
-  static Symbol* as_symbol(Handle java_string, TRAPS);
+  static Symbol* as_symbol(oop java_string, TRAPS);
   static Symbol* as_symbol_or_null(oop java_string);
 
   // Testers
@@ -209,29 +209,23 @@
   static void set_protection_domain(oop java_class, oop protection_domain);
   static void set_class_loader(oop java_class, oop class_loader);
   static void set_component_mirror(oop java_class, oop comp_mirror);
-  static void initialize_mirror_fields(KlassHandle k, Handle mirror, Handle protection_domain, TRAPS);
-  static void set_mirror_module_field(KlassHandle K, Handle mirror, Handle module, TRAPS);
+  static void initialize_mirror_fields(Klass* k, Handle mirror, Handle protection_domain, TRAPS);
+  static void set_mirror_module_field(Klass* K, Handle mirror, Handle module, TRAPS);
  public:
   static void compute_offsets();
 
   // Instance creation
-  static void create_mirror(KlassHandle k, Handle class_loader, Handle module,
+  static void create_mirror(Klass* k, Handle class_loader, Handle module,
                             Handle protection_domain, TRAPS);
-  static void fixup_mirror(KlassHandle k, TRAPS);
+  static void fixup_mirror(Klass* k, TRAPS);
   static oop  create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
 
-  static void fixup_module_field(KlassHandle k, Handle module);
+  static void fixup_module_field(Klass* k, Handle module);
 
   // Conversion
   static Klass* as_Klass(oop java_class);
   static void set_klass(oop java_class, Klass* klass);
   static BasicType as_BasicType(oop java_class, Klass** reference_klass = NULL);
-  static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {
-    Klass* refk_oop = NULL;
-    BasicType result = as_BasicType(java_class, &refk_oop);
-    (*reference_klass) = KlassHandle(refk_oop);
-    return result;
-  }
   static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS);
   static void print_signature(oop java_class, outputStream *st);
   static const char* as_external_name(oop java_class);
@@ -457,7 +451,7 @@
     trace_methods_offset = 0,
     trace_bcis_offset    = 1,
     trace_mirrors_offset = 2,
-    trace_cprefs_offset  = 3,
+    trace_names_offset   = 3,
     trace_next_offset    = 4,
     trace_size           = 5,
     trace_chunk_size     = 32
@@ -485,7 +479,7 @@
   static int get_backtrace_offset() { return backtrace_offset;}
   static int get_detailMessage_offset() { return detailMessage_offset;}
   // Message
-  static oop message(Handle throwable);
+  static oop message(oop throwable);
   static void set_message(oop throwable, oop value);
   static Symbol* detail_message(oop throwable);
   static void print_stack_element(outputStream *st, const methodHandle& method, int bci);
@@ -503,7 +497,7 @@
   // Programmatic access to stack trace
   static void get_stack_trace_elements(Handle throwable, objArrayHandle stack_trace, TRAPS);
   // Printing
-  static void print(Handle throwable, outputStream* st);
+  static void print(oop throwable, outputStream* st);
   static void print_stack_trace(Handle throwable, outputStream* st);
   static void java_printStackTrace(Handle throwable, TRAPS);
   // Debugging
@@ -1324,7 +1318,7 @@
   static oop create(const methodHandle& method, int bci, TRAPS);
 
   static void fill_in(Handle element, InstanceKlass* holder, const methodHandle& method,
-                      int version, int bci, int cpref, TRAPS);
+                      int version, int bci, Symbol* name, TRAPS);
 
   // Debugging
   friend class JavaClasses;
--- a/hotspot/src/share/vm/classfile/klassFactory.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/klassFactory.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
@@ -37,14 +37,14 @@
 #include "trace/traceMacros.hpp"
 
 // called during initial loading of a shared class
-instanceKlassHandle KlassFactory::check_shared_class_file_load_hook(
-                                          instanceKlassHandle ik,
+InstanceKlass* KlassFactory::check_shared_class_file_load_hook(
+                                          InstanceKlass* ik,
                                           Symbol* class_name,
                                           Handle class_loader,
                                           Handle protection_domain, TRAPS) {
 #if INCLUDE_CDS && INCLUDE_JVMTI
-  assert(ik.not_null(), "sanity");
-  assert(ik()->is_shared(), "expecting a shared class");
+  assert(ik != NULL, "sanity");
+  assert(ik->is_shared(), "expecting a shared class");
 
   if (JvmtiExport::should_post_class_file_load_hook()) {
     assert(THREAD->is_Java_thread(), "must be JavaThread");
@@ -84,8 +84,8 @@
                              NULL,
                              ClassFileParser::BROADCAST, // publicity level
                              CHECK_NULL);
-      instanceKlassHandle new_ik = parser.create_instance_klass(true /* changed_by_loadhook */,
-                                                                CHECK_NULL);
+      InstanceKlass* new_ik = parser.create_instance_klass(true /* changed_by_loadhook */,
+                                                           CHECK_NULL);
       if (cached_class_file != NULL) {
         new_ik->set_cached_class_file(cached_class_file);
       }
@@ -128,14 +128,11 @@
     JvmtiThreadState* state = jt->jvmti_thread_state();
 
     if (state != NULL) {
-      KlassHandle* h_class_being_redefined =
-        state->get_class_being_redefined();
+      Klass* k = state->get_class_being_redefined();
 
-      if (h_class_being_redefined != NULL) {
-        instanceKlassHandle ikh_class_being_redefined =
-          instanceKlassHandle(THREAD, (*h_class_being_redefined)());
-
-        *cached_class_file = ikh_class_being_redefined->get_cached_class_file();
+      if (k != NULL) {
+        InstanceKlass* class_being_redefined = InstanceKlass::cast(k);
+        *cached_class_file = class_being_redefined->get_cached_class_file();
       }
     }
 
@@ -163,13 +160,13 @@
 }
 
 
-instanceKlassHandle KlassFactory::create_from_stream(ClassFileStream* stream,
-                                                     Symbol* name,
-                                                     ClassLoaderData* loader_data,
-                                                     Handle protection_domain,
-                                                     const InstanceKlass* host_klass,
-                                                     GrowableArray<Handle>* cp_patches,
-                                                     TRAPS) {
+InstanceKlass* KlassFactory::create_from_stream(ClassFileStream* stream,
+                                                Symbol* name,
+                                                ClassLoaderData* loader_data,
+                                                Handle protection_domain,
+                                                const InstanceKlass* host_klass,
+                                                GrowableArray<Handle>* cp_patches,
+                                                TRAPS) {
   assert(stream != NULL, "invariant");
   assert(loader_data != NULL, "invariant");
   assert(THREAD->is_Java_thread(), "must be a JavaThread");
@@ -200,10 +197,10 @@
                          ClassFileParser::BROADCAST, // publicity level
                          CHECK_NULL);
 
-  instanceKlassHandle result = parser.create_instance_klass(old_stream != stream, CHECK_NULL);
+  InstanceKlass* result = parser.create_instance_klass(old_stream != stream, CHECK_NULL);
   assert(result == parser.create_instance_klass(old_stream != stream, THREAD), "invariant");
 
-  if (result.is_null()) {
+  if (result == NULL) {
     return NULL;
   }
 
--- a/hotspot/src/share/vm/classfile/klassFactory.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/klassFactory.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
@@ -68,16 +68,16 @@
   friend class SystemDictionary;
 
  private:
-  static instanceKlassHandle create_from_stream(ClassFileStream* stream,
-                                                Symbol* name,
-                                                ClassLoaderData* loader_data,
-                                                Handle protection_domain,
-                                                const InstanceKlass* host_klass,
-                                                GrowableArray<Handle>* cp_patches,
-                                                TRAPS);
+  static InstanceKlass* create_from_stream(ClassFileStream* stream,
+                                           Symbol* name,
+                                           ClassLoaderData* loader_data,
+                                           Handle protection_domain,
+                                           const InstanceKlass* host_klass,
+                                           GrowableArray<Handle>* cp_patches,
+                                           TRAPS);
  public:
-  static instanceKlassHandle check_shared_class_file_load_hook(
-                                          instanceKlassHandle ik,
+  static InstanceKlass* check_shared_class_file_load_hook(
+                                          InstanceKlass* ik,
                                           Symbol* class_name,
                                           Handle class_loader,
                                           Handle protection_domain, TRAPS);
--- a/hotspot/src/share/vm/classfile/loaderConstraints.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/loaderConstraints.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,15 +36,15 @@
 }
 
 LoaderConstraintTable::LoaderConstraintTable(int nof_buckets)
-  : Hashtable<Klass*, mtClass>(nof_buckets, sizeof(LoaderConstraintEntry)) {};
+  : Hashtable<InstanceKlass*, mtClass>(nof_buckets, sizeof(LoaderConstraintEntry)) {};
 
 
 LoaderConstraintEntry* LoaderConstraintTable::new_entry(
                                  unsigned int hash, Symbol* name,
-                                 Klass* klass, int num_loaders,
+                                 InstanceKlass* klass, int num_loaders,
                                  int max_loaders) {
   LoaderConstraintEntry* entry;
-  entry = (LoaderConstraintEntry*)Hashtable<Klass*, mtClass>::new_entry(hash, klass);
+  entry = (LoaderConstraintEntry*)Hashtable<InstanceKlass*, mtClass>::new_entry(hash, klass);
   entry->set_name(name);
   entry->set_num_loaders(num_loaders);
   entry->set_max_loaders(max_loaders);
@@ -54,7 +54,7 @@
 void LoaderConstraintTable::free_entry(LoaderConstraintEntry *entry) {
   // decrement name refcount before freeing
   entry->name()->decrement_refcount();
-  Hashtable<Klass*, mtClass>::free_entry(entry);
+  Hashtable<InstanceKlass*, mtClass>::free_entry(entry);
 }
 
 // Enhanced Class Redefinition support
@@ -106,7 +106,7 @@
     LoaderConstraintEntry** p = bucket_addr(index);
     while(*p) {
       LoaderConstraintEntry* probe = *p;
-      Klass* klass = probe->klass();
+      InstanceKlass* klass = probe->klass();
       // Remove klass that is no longer alive
       if (klass != NULL &&
           klass->class_loader_data()->is_unloading()) {
@@ -186,14 +186,14 @@
 }
 
 bool LoaderConstraintTable::add_entry(Symbol* class_name,
-                                      Klass* klass1, Handle class_loader1,
-                                      Klass* klass2, Handle class_loader2) {
+                                      InstanceKlass* klass1, Handle class_loader1,
+                                      InstanceKlass* klass2, Handle class_loader2) {
   int failure_code = 0; // encode different reasons for failing
 
   if (klass1 != NULL && klass2 != NULL && klass1 != klass2) {
     failure_code = 1;
   } else {
-    Klass* klass = klass1 != NULL ? klass1 : klass2;
+    InstanceKlass* klass = klass1 != NULL ? klass1 : klass2;
 
     LoaderConstraintEntry** pp1 = find_loader_constraint(class_name,
                                                          class_loader1);
@@ -295,11 +295,11 @@
 
 // return true if the constraint was updated, false if the constraint is
 // violated
-bool LoaderConstraintTable::check_or_update(instanceKlassHandle k,
-                                                   Handle loader,
-                                                   Symbol* name) {
+bool LoaderConstraintTable::check_or_update(InstanceKlass* k,
+                                            Handle loader,
+                                            Symbol* name) {
   LoaderConstraintEntry* p = *(find_loader_constraint(name, loader));
-  if (p && p->klass() != NULL && p->klass() != k()) {
+  if (p && p->klass() != NULL && p->klass() != k) {
     if (log_is_enabled(Info, class, loader, constraints)) {
       ResourceMark rm;
       outputStream* out = Log(class, loader, constraints)::info_stream();
@@ -311,7 +311,7 @@
     return false;
   } else {
     if (p && p->klass() == NULL) {
-      p->set_klass(k());
+      p->set_klass(k);
       if (log_is_enabled(Info, class, loader, constraints)) {
         ResourceMark rm;
         outputStream* out = Log(class, loader, constraints)::info_stream();
@@ -325,11 +325,12 @@
   }
 }
 
-Klass* LoaderConstraintTable::find_constrained_klass(Symbol* name,
+InstanceKlass* LoaderConstraintTable::find_constrained_klass(Symbol* name,
                                                        Handle loader) {
   LoaderConstraintEntry *p = *(find_loader_constraint(name, loader));
   if (p != NULL && p->klass() != NULL) {
-    if (p->klass()->is_instance_klass() && !InstanceKlass::cast(p->klass())->is_loaded()) {
+    assert(p->klass()->is_instance_klass(), "sanity");
+    if (p->klass()->is_loaded()) {
       // Only return fully loaded classes.  Classes found through the
       // constraints might still be in the process of loading.
       return NULL;
@@ -357,7 +358,7 @@
 
 void LoaderConstraintTable::extend_loader_constraint(LoaderConstraintEntry* p,
                                                      Handle loader,
-                                                     Klass* klass) {
+                                                     InstanceKlass* klass) {
   ensure_loader_constraint_capacity(p, 1);
   int num = p->num_loaders();
   p->set_loader(num, loader());
@@ -383,7 +384,7 @@
 void LoaderConstraintTable::merge_loader_constraints(
                                                    LoaderConstraintEntry** pp1,
                                                    LoaderConstraintEntry** pp2,
-                                                   Klass* klass) {
+                                                   InstanceKlass* klass) {
   // make sure *pp1 has higher capacity
   if ((*pp1)->max_loaders() < (*pp2)->max_loaders()) {
     LoaderConstraintEntry** tmp = pp2;
@@ -447,13 +448,13 @@
                                 probe != NULL;
                                 probe = probe->next()) {
       if (probe->klass() != NULL) {
-        InstanceKlass* ik = InstanceKlass::cast(probe->klass());
+        InstanceKlass* ik = probe->klass();
         guarantee(ik->name() == probe->name(), "name should match");
         Symbol* name = ik->name();
         ClassLoaderData* loader_data = ik->class_loader_data();
         unsigned int d_hash = dictionary->compute_hash(name, loader_data);
         int d_index = dictionary->hash_to_index(d_hash);
-        Klass* k = dictionary->find_class(d_index, d_hash, name, loader_data);
+        InstanceKlass* k = dictionary->find_class(d_index, d_hash, name, loader_data);
         if (k != NULL) {
           // We found the class in the system dictionary, so we should
           // make sure that the Klass* matches what we already have.
--- a/hotspot/src/share/vm/classfile/loaderConstraints.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/loaderConstraints.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,7 +32,7 @@
 class LoaderConstraintEntry;
 class Symbol;
 
-class LoaderConstraintTable : public Hashtable<Klass*, mtClass> {
+class LoaderConstraintTable : public Hashtable<InstanceKlass*, mtClass> {
   friend class VMStructs;
 private:
 
@@ -49,43 +49,41 @@
   LoaderConstraintTable(int nof_buckets);
 
   LoaderConstraintEntry* new_entry(unsigned int hash, Symbol* name,
-                                   Klass* klass, int num_loaders,
+                                   InstanceKlass* klass, int num_loaders,
                                    int max_loaders);
   void free_entry(LoaderConstraintEntry *entry);
 
   LoaderConstraintEntry* bucket(int i) {
-    return (LoaderConstraintEntry*)Hashtable<Klass*, mtClass>::bucket(i);
+    return (LoaderConstraintEntry*)Hashtable<InstanceKlass*, mtClass>::bucket(i);
   }
 
   LoaderConstraintEntry** bucket_addr(int i) {
-    return (LoaderConstraintEntry**)Hashtable<Klass*, mtClass>::bucket_addr(i);
+    return (LoaderConstraintEntry**)Hashtable<InstanceKlass*, mtClass>::bucket_addr(i);
   }
 
   // Enhanced Class Redefinition support
   void classes_do(KlassClosure* f);
 
   // Check class loader constraints
-  bool add_entry(Symbol* name, Klass* klass1, Handle loader1,
-                                    Klass* klass2, Handle loader2);
+  bool add_entry(Symbol* name, InstanceKlass* klass1, Handle loader1,
+                                    InstanceKlass* klass2, Handle loader2);
 
   // Note:  The main entry point for this module is via SystemDictionary.
   // SystemDictionary::check_signature_loaders(Symbol* signature,
   //                                           Handle loader1, Handle loader2,
   //                                           bool is_method, TRAPS)
 
-  Klass* find_constrained_klass(Symbol* name, Handle loader);
+  InstanceKlass* find_constrained_klass(Symbol* name, Handle loader);
 
   // Class loader constraints
 
   void ensure_loader_constraint_capacity(LoaderConstraintEntry *p, int nfree);
   void extend_loader_constraint(LoaderConstraintEntry* p, Handle loader,
-                                Klass* klass);
+                                InstanceKlass* klass);
   void merge_loader_constraints(LoaderConstraintEntry** pp1,
-                                LoaderConstraintEntry** pp2, Klass* klass);
+                                LoaderConstraintEntry** pp2, InstanceKlass* klass);
 
-  bool check_or_update(instanceKlassHandle k, Handle loader,
-                              Symbol* name);
-
+  bool check_or_update(InstanceKlass* k, Handle loader, Symbol* name);
 
   void purge_loader_constraints();
 
@@ -95,7 +93,7 @@
 #endif
 };
 
-class LoaderConstraintEntry : public HashtableEntry<Klass*, mtClass> {
+class LoaderConstraintEntry : public HashtableEntry<InstanceKlass*, mtClass> {
   friend class VMStructs;
 private:
   Symbol*                _name;                   // class name
@@ -108,19 +106,19 @@
 
 public:
 
-  Klass* klass() { return literal(); }
-  Klass** klass_addr() { return literal_addr(); }
-  void set_klass(Klass* k) { set_literal(k); }
+  InstanceKlass* klass() { return literal(); }
+  InstanceKlass** klass_addr() { return literal_addr(); }
+  void set_klass(InstanceKlass* k) { set_literal(k); }
 
   LoaderConstraintEntry* next() {
-    return (LoaderConstraintEntry*)HashtableEntry<Klass*, mtClass>::next();
+    return (LoaderConstraintEntry*)HashtableEntry<InstanceKlass*, mtClass>::next();
   }
 
   LoaderConstraintEntry** next_addr() {
-    return (LoaderConstraintEntry**)HashtableEntry<Klass*, mtClass>::next_addr();
+    return (LoaderConstraintEntry**)HashtableEntry<InstanceKlass*, mtClass>::next_addr();
   }
   void set_next(LoaderConstraintEntry* next) {
-    HashtableEntry<Klass*, mtClass>::set_next(next);
+    HashtableEntry<InstanceKlass*, mtClass>::set_next(next);
   }
 
   Symbol* name() { return _name; }
--- a/hotspot/src/share/vm/classfile/moduleEntry.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/moduleEntry.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -81,7 +81,7 @@
 
 // Returns the shared ProtectionDomain
 Handle ModuleEntry::shared_protection_domain() {
-  return Handle(JNIHandles::resolve(_pd));
+  return Handle(Thread::current(), JNIHandles::resolve(_pd));
 }
 
 // Set the shared ProtectionDomain atomically
@@ -269,12 +269,12 @@
     // For the boot loader, the java.lang.reflect.Module for the unnamed module
     // is not known until a call to JVM_SetBootLoaderUnnamedModule is made. At
     // this point initially create the ModuleEntry for the unnamed module.
-    _unnamed_module = new_entry(0, Handle(NULL), NULL, NULL, NULL, loader_data);
+    _unnamed_module = new_entry(0, Handle(), NULL, NULL, NULL, loader_data);
   } else {
     // For all other class loaders the java.lang.reflect.Module for their
     // corresponding unnamed module can be found in the java.lang.ClassLoader object.
     oop module = java_lang_ClassLoader::unnamedModule(loader_data->class_loader());
-    _unnamed_module = new_entry(0, Handle(module), NULL, NULL, NULL, loader_data);
+    _unnamed_module = new_entry(0, Handle(Thread::current(), module), NULL, NULL, NULL, loader_data);
 
     // Store pointer to the ModuleEntry in the unnamed module's java.lang.reflect.Module
     // object.
@@ -428,7 +428,7 @@
   for (int i = 0; i < list_length; i++) {
     Klass* k = list->at(i);
     assert(k->is_klass(), "List should only hold classes");
-    java_lang_Class::fixup_module_field(KlassHandle(k), module_handle);
+    java_lang_Class::fixup_module_field(k, module_handle);
     k->class_loader_data()->dec_keep_alive();
   }
 
--- a/hotspot/src/share/vm/classfile/modules.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/modules.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -162,8 +162,7 @@
   }
 
 
-  // Check that the list of packages has no duplicates and that the
-  // packages are syntactically ok.
+  // Check that the packages are syntactically ok.
   GrowableArray<Symbol*>* pkg_list = new GrowableArray<Symbol*>(num_packages);
   for (int x = 0; x < num_packages; x++) {
     const char *package_name = packages[x];
@@ -172,12 +171,7 @@
                 err_msg("Invalid package name: %s for module: " JAVA_BASE_NAME, package_name));
     }
     Symbol* pkg_symbol = SymbolTable::new_symbol(package_name, CHECK);
-    // append_if_missing() returns FALSE if entry already exists.
-    if (!pkg_list->append_if_missing(pkg_symbol)) {
-      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-                err_msg("Duplicate package name: %s for module " JAVA_BASE_NAME,
-                        package_name));
-    }
+    pkg_list->append(pkg_symbol);
   }
 
   // Validate java_base's loader is the boot loader.
@@ -186,7 +180,7 @@
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
               "Class loader must be the boot class loader");
   }
-  Handle h_loader = Handle(THREAD, loader);
+  Handle h_loader(THREAD, loader);
 
   // Ensure the boot loader's PackageEntryTable has been created
   PackageEntryTable* package_table = get_package_entry_table(h_loader, CHECK);
@@ -324,7 +318,7 @@
 
     // Only modules defined to either the boot or platform class loader, can define a "java/" package.
     if (!h_loader.is_null() &&
-        !SystemDictionary::is_platform_class_loader(h_loader) &&
+        !SystemDictionary::is_platform_class_loader(h_loader()) &&
         strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0) {
       const char* class_loader_name = SystemDictionary::loader_name(h_loader());
       size_t pkg_len = strlen(package_name);
@@ -340,12 +334,7 @@
     }
 
     Symbol* pkg_symbol = SymbolTable::new_symbol(package_name, CHECK);
-    // append_if_missing() returns FALSE if entry already exists.
-    if (!pkg_list->append_if_missing(pkg_symbol)) {
-      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-                err_msg("Duplicate package name: %s for module %s",
-                        package_name, module_name));
-    }
+    pkg_list->append(pkg_symbol);
   }
 
   ModuleEntryTable* module_table = get_module_entry_table(h_loader, CHECK);
@@ -484,7 +473,7 @@
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
               "Class loader must be the boot class loader");
   }
-  Handle h_loader = Handle(THREAD, loader);
+  Handle h_loader(THREAD, loader);
 
   log_debug(modules)("set_bootloader_unnamed_module(): recording unnamed module for boot loader");
 
@@ -649,39 +638,6 @@
   return JNIHandles::make_local(THREAD, module);
 }
 
-
-jobject Modules::get_module_by_package_name(jobject loader, const char* package_name, TRAPS) {
-  ResourceMark rm(THREAD);
-  assert(ModuleEntryTable::javabase_defined(),
-         "Attempt to call get_module_from_pkg before " JAVA_BASE_NAME " is defined");
-
-  if (package_name == NULL) {
-    THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
-               "package is null", JNI_FALSE);
-  }
-
-  Handle h_loader (THREAD, JNIHandles::resolve(loader));
-  // Check that loader is a subclass of java.lang.ClassLoader.
-  if (loader != NULL && !java_lang_ClassLoader::is_subclass(h_loader->klass())) {
-    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
-               "Class loader is not a subclass of java.lang.ClassLoader", JNI_FALSE);
-  }
-
-  if (strlen(package_name) == 0) {
-    // Return the unnamed module
-    ModuleEntryTable* module_table = get_module_entry_table(h_loader, CHECK_NULL);
-    if (NULL == module_table) return NULL;
-    const ModuleEntry* const unnamed_module = module_table->unnamed_module();
-    return JNIHandles::make_local(THREAD, JNIHandles::resolve(unnamed_module->module()));
-
-  } else {
-    TempNewSymbol package_sym = SymbolTable::new_symbol(package_name, CHECK_NULL);
-    return get_module(package_sym, h_loader, CHECK_NULL);
-  }
-  return NULL;
-}
-
-
 jobject Modules::get_named_module(Handle h_loader, const char* package_name, TRAPS) {
   assert(ModuleEntryTable::javabase_defined(),
          "Attempt to call get_named_module before " JAVA_BASE_NAME " is defined");
--- a/hotspot/src/share/vm/classfile/modules.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/modules.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
@@ -45,7 +45,6 @@
   // * Module's Class loader has already defined types for any of the module's packages
   // * Module_name is syntactically bad
   // * Packages contains an illegal package name
-  // * Packages contains a duplicate package name
   // * A package already exists in another module for this class loader
   // * Module is an unnamed module
   // * num_packages is negative
@@ -105,7 +104,6 @@
   // NullPointerException is thrown if package is null.
   // IllegalArgumentException is thrown if loader is neither null nor a subtype of
   // java/lang/ClassLoader.
-  static jobject get_module_by_package_name(jobject loader, const char* package, TRAPS);
   static jobject get_named_module(Handle h_loader, const char* package, TRAPS);
 
   // If package is defined by loader, return the
--- a/hotspot/src/share/vm/classfile/placeholders.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/placeholders.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -163,7 +163,7 @@
   bool              _havesupername; // distinguish between null supername, and unknown
   Symbol*           _supername;
   Thread*           _definer;       // owner of define token
-  Klass*            _instanceKlass; // InstanceKlass from successful define
+  InstanceKlass*    _instanceKlass; // InstanceKlass from successful define
   SeenThread*       _superThreadQ;  // doubly-linked queue of Threads loading a superclass for this class
   SeenThread*       _loadInstanceThreadQ;  // loadInstance thread
                                     // can be multiple threads if classloader object lock broken by application
@@ -193,8 +193,8 @@
   Thread*            definer()             const {return _definer; }
   void               set_definer(Thread* definer) { _definer = definer; }
 
-  Klass*             instance_klass()      const {return _instanceKlass; }
-  void               set_instance_klass(Klass* ik) { _instanceKlass = ik; }
+  InstanceKlass*     instance_klass()      const {return _instanceKlass; }
+  void               set_instance_klass(InstanceKlass* ik) { _instanceKlass = ik; }
 
   SeenThread*        superThreadQ()        const { return _superThreadQ; }
   void               set_superThreadQ(SeenThread* SeenThread) { _superThreadQ = SeenThread; }
--- a/hotspot/src/share/vm/classfile/stringTable.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/stringTable.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -236,6 +236,7 @@
   assert(!Universe::heap()->is_in_reserved(name),
          "proposed name of symbol must be stable");
 
+  HandleMark hm(THREAD);  // cleanup strings created
   Handle string;
   // try to reuse the string if possible
   if (!string_or_null.is_null()) {
--- a/hotspot/src/share/vm/classfile/systemDictionary.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -120,10 +120,10 @@
 }
 
 void SystemDictionary::compute_java_system_loader(TRAPS) {
-  KlassHandle system_klass(THREAD, WK_KLASS(ClassLoader_klass));
+  Klass* system_klass = WK_KLASS(ClassLoader_klass);
   JavaValue result(T_OBJECT);
   JavaCalls::call_static(&result,
-                         KlassHandle(THREAD, WK_KLASS(ClassLoader_klass)),
+                         WK_KLASS(ClassLoader_klass),
                          vmSymbols::getSystemClassLoader_name(),
                          vmSymbols::void_classloader_signature(),
                          CHECK);
@@ -160,17 +160,17 @@
 // Returns true if the passed class loader is the builtin application class loader
 // or a custom system class loader. A customer system class loader can be
 // specified via -Djava.system.class.loader.
-bool SystemDictionary::is_system_class_loader(Handle class_loader) {
-  if (class_loader.is_null()) {
+bool SystemDictionary::is_system_class_loader(oop class_loader) {
+  if (class_loader == NULL) {
     return false;
   }
   return (class_loader->klass() == SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass() ||
-          class_loader() == _java_system_loader);
+          class_loader == _java_system_loader);
 }
 
 // Returns true if the passed class loader is the platform class loader.
-bool SystemDictionary::is_platform_class_loader(Handle class_loader) {
-  if (class_loader.is_null()) {
+bool SystemDictionary::is_platform_class_loader(oop class_loader) {
+  if (class_loader == NULL) {
     return false;
   }
   return (class_loader->klass() == SystemDictionary::jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass());
@@ -184,16 +184,15 @@
 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) {
   Klass* klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD);
   if (HAS_PENDING_EXCEPTION || klass == NULL) {
-    KlassHandle k_h(THREAD, klass);
     // can return a null klass
-    klass = handle_resolution_exception(class_name, throw_error, k_h, THREAD);
+    klass = handle_resolution_exception(class_name, throw_error, klass, THREAD);
   }
   return klass;
 }
 
 Klass* SystemDictionary::handle_resolution_exception(Symbol* class_name,
                                                      bool throw_error,
-                                                     KlassHandle klass_h, TRAPS) {
+                                                     Klass* klass, TRAPS) {
   if (HAS_PENDING_EXCEPTION) {
     // If we have a pending exception we forward it to the caller, unless throw_error is true,
     // in which case we have to check whether the pending exception is a ClassNotFoundException,
@@ -201,7 +200,7 @@
     // And chain the original ClassNotFoundException
     if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass())) {
       ResourceMark rm(THREAD);
-      assert(klass_h() == NULL, "Should not have result with exception pending");
+      assert(klass == NULL, "Should not have result with exception pending");
       Handle e(THREAD, PENDING_EXCEPTION);
       CLEAR_PENDING_EXCEPTION;
       THROW_MSG_CAUSE_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e);
@@ -210,7 +209,7 @@
     }
   }
   // Class not found, throw appropriate error or exception depending on value of throw_error
-  if (klass_h() == NULL) {
+  if (klass == NULL) {
     ResourceMark rm(THREAD);
     if (throw_error) {
       THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string());
@@ -218,7 +217,7 @@
       THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
     }
   }
-  return (Klass*)klass_h();
+  return klass;
 }
 
 
@@ -256,9 +255,9 @@
 // Forwards to resolve_instance_class_or_null
 
 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
-                                                       Handle class_loader,
-                                                       Handle protection_domain,
-                                                       TRAPS) {
+                                                     Handle class_loader,
+                                                     Handle protection_domain,
+                                                     TRAPS) {
   assert(FieldType::is_array(class_name), "must be array");
   Klass* k = NULL;
   FieldArrayInfo fd;
@@ -398,11 +397,9 @@
   assert(class_name != NULL, "null super class for resolving");
   // Resolve the super class or interface, check results on return
   Klass* superk = SystemDictionary::resolve_or_null(class_name,
-                                                 class_loader,
-                                                 protection_domain,
-                                                 THREAD);
-
-  KlassHandle superk_h(THREAD, superk);
+                                                    class_loader,
+                                                    protection_domain,
+                                                    THREAD);
 
   // Clean up of placeholders moved so that each classloadAction registrar self-cleans up
   // It is no longer necessary to keep the placeholder table alive until update_dictionary
@@ -415,15 +412,15 @@
     placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
     SystemDictionary_lock->notify_all();
   }
-  if (HAS_PENDING_EXCEPTION || superk_h() == NULL) {
+  if (HAS_PENDING_EXCEPTION || superk == NULL) {
     // can null superk
-    superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, true, superk_h, THREAD));
+    superk = handle_resolution_exception(class_name, true, superk, THREAD);
   }
 
-  return superk_h();
+  return superk;
 }
 
-void SystemDictionary::validate_protection_domain(instanceKlassHandle klass,
+void SystemDictionary::validate_protection_domain(InstanceKlass* klass,
                                                   Handle class_loader,
                                                   Handle protection_domain,
                                                   TRAPS) {
@@ -438,11 +435,11 @@
     log->print_cr("Checking package access");
     log->print("class loader: "); class_loader()->print_value_on(log);
     log->print(" protection domain: "); protection_domain()->print_value_on(log);
-    log->print(" loading: "); klass()->print_value_on(log);
+    log->print(" loading: "); klass->print_value_on(log);
     log->cr();
   }
 
-  KlassHandle system_loader(THREAD, SystemDictionary::ClassLoader_klass());
+  InstanceKlass* system_loader = SystemDictionary::ClassLoader_klass();
   JavaCalls::call_special(&result,
                          class_loader,
                          system_loader,
@@ -540,11 +537,10 @@
 // Returns non-null Klass* if other thread has completed load
 // and we are done,
 // If return null Klass* and no pending exception, the caller must load the class
-instanceKlassHandle SystemDictionary::handle_parallel_super_load(
+InstanceKlass* SystemDictionary::handle_parallel_super_load(
     Symbol* name, Symbol* superclassname, Handle class_loader,
     Handle protection_domain, Handle lockObject, TRAPS) {
 
-  instanceKlassHandle nh = instanceKlassHandle(); // null Handle
   ClassLoaderData* loader_data = class_loader_data(class_loader);
   unsigned int d_hash = dictionary()->compute_hash(name, loader_data);
   int d_index = dictionary()->hash_to_index(d_hash);
@@ -564,20 +560,14 @@
                                                           class_loader,
                                                           protection_domain,
                                                           true,
-                                                          CHECK_(nh));
+                                                          CHECK_NULL);
 
   // parallelCapable class loaders do NOT wait for parallel superclass loads to complete
   // Serial class loaders and bootstrap classloader do wait for superclass loads
  if (!class_loader.is_null() && is_parallelCapable(class_loader)) {
     MutexLocker mu(SystemDictionary_lock, THREAD);
     // Check if classloading completed while we were loading superclass or waiting
-    Klass* check = find_class(d_index, d_hash, name, loader_data);
-    if (check != NULL) {
-      // Klass is already loaded, so just return it
-      return(instanceKlassHandle(THREAD, check));
-    } else {
-      return nh;
-    }
+    return find_class(d_index, d_hash, name, loader_data);
   }
 
   // must loop to both handle other placeholder updates
@@ -587,10 +577,10 @@
   while (super_load_in_progress) {
     MutexLocker mu(SystemDictionary_lock, THREAD);
     // Check if classloading completed while we were loading superclass or waiting
-    Klass* check = find_class(d_index, d_hash, name, loader_data);
+    InstanceKlass* check = find_class(d_index, d_hash, name, loader_data);
     if (check != NULL) {
       // Klass is already loaded, so just return it
-      return(instanceKlassHandle(THREAD, check));
+      return check;
     } else {
       placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data);
       if (placeholder && placeholder->super_load_in_progress() ){
@@ -619,17 +609,17 @@
       }
     }
   }
-  return (nh);
+  return NULL;
 }
 
 static void post_class_load_event(const Ticks& start_time,
-                                  instanceKlassHandle k,
+                                  InstanceKlass* k,
                                   const ClassLoaderData* init_cld) {
 #if INCLUDE_TRACE
   EventClassLoad event(UNTIMED);
   if (event.should_commit()) {
     event.set_starttime(start_time);
-    event.set_loadedClass(k());
+    event.set_loadedClass(k);
     event.set_definingClassLoader(k->class_loader_data());
     event.set_initiatingClassLoader(init_cld);
     event.commit();
@@ -637,12 +627,12 @@
 #endif // INCLUDE_TRACE
 }
 
-static void class_define_event(instanceKlassHandle k,
+static void class_define_event(InstanceKlass* k,
                                const ClassLoaderData* def_cld) {
 #if INCLUDE_TRACE
   EventClassDefine event;
   if (event.should_commit()) {
-    event.set_definedClass(k());
+    event.set_definedClass(k);
     event.set_definingClassLoader(def_cld);
     event.commit();
   }
@@ -662,6 +652,8 @@
 
   Ticks class_load_start_time = Ticks::now();
 
+  HandleMark hm(THREAD);
+
   // Fix for 4474172; see evaluation for more details
   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
   ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL);
@@ -706,17 +698,17 @@
   bool class_has_been_loaded   = false;
   bool super_load_in_progress  = false;
   bool havesupername = false;
-  instanceKlassHandle k;
+  InstanceKlass* k = NULL;
   PlaceholderEntry* placeholder;
   Symbol* superclassname = NULL;
 
   {
     MutexLocker mu(SystemDictionary_lock, THREAD);
-    Klass* check = find_class(d_index, d_hash, name, loader_data);
+    InstanceKlass* check = find_class(d_index, d_hash, name, loader_data);
     if (check != NULL) {
       // Klass is already loaded, so just return it
       class_has_been_loaded = true;
-      k = instanceKlassHandle(THREAD, check);
+      k = check;
     } else {
       placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data);
       if (placeholder && placeholder->super_load_in_progress()) {
@@ -731,12 +723,15 @@
 
   // If the class is in the placeholder table, class loading is in progress
   if (super_load_in_progress && havesupername==true) {
-    k = SystemDictionary::handle_parallel_super_load(name, superclassname,
-        class_loader, protection_domain, lockObject, THREAD);
+    k = handle_parallel_super_load(name,
+                                   superclassname,
+                                   class_loader,
+                                   protection_domain,
+                                   lockObject, THREAD);
     if (HAS_PENDING_EXCEPTION) {
       return NULL;
     }
-    if (!k.is_null()) {
+    if (k != NULL) {
       class_has_been_loaded = true;
     }
   }
@@ -793,10 +788,10 @@
                 double_lock_wait(lockObject, THREAD);
               }
               // Check if classloading completed while we were waiting
-              Klass* check = find_class(d_index, d_hash, name, loader_data);
+              InstanceKlass* check = find_class(d_index, d_hash, name, loader_data);
               if (check != NULL) {
                 // Klass is already loaded, so just return it
-                k = instanceKlassHandle(THREAD, check);
+                k = check;
                 class_has_been_loaded = true;
               }
               // check if other thread failed to load and cleaned up
@@ -818,10 +813,10 @@
         // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL
         // one final check if the load has already completed
         // class loaders holding the ObjectLock shouldn't find the class here
-        Klass* check = find_class(d_index, d_hash, name, loader_data);
+        InstanceKlass* check = find_class(d_index, d_hash, name, loader_data);
         if (check != NULL) {
         // Klass is already loaded, so return it after checking/adding protection domain
-          k = instanceKlassHandle(THREAD, check);
+          k = check;
           class_has_been_loaded = true;
         }
       }
@@ -848,13 +843,13 @@
       // with the new cleaner mechanism, even with AllowParallelDefineClass
       // Bootstrap goes through here to allow for an extra guarantee check
       if (UnsyncloadClass || (class_loader.is_null())) {
-        if (k.is_null() && HAS_PENDING_EXCEPTION
+        if (k == NULL && HAS_PENDING_EXCEPTION
           && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
           MutexLocker mu(SystemDictionary_lock, THREAD);
-          Klass* check = find_class(d_index, d_hash, name, loader_data);
+          InstanceKlass* check = find_class(d_index, d_hash, name, loader_data);
           if (check != NULL) {
             // Klass is already loaded, so just use it
-            k = instanceKlassHandle(THREAD, check);
+            k = check;
             CLEAR_PENDING_EXCEPTION;
             guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?");
           }
@@ -863,7 +858,7 @@
 
       // If everything was OK (no exceptions, no null return value), and
       // class_loader is NOT the defining loader, do a little more bookkeeping.
-      if (!HAS_PENDING_EXCEPTION && !k.is_null() &&
+      if (!HAS_PENDING_EXCEPTION && k != NULL &&
         k->class_loader() != class_loader()) {
 
         check_constraints(d_index, d_hash, k, class_loader, false, THREAD);
@@ -881,7 +876,7 @@
           if (JvmtiExport::should_post_class_load()) {
             Thread *thread = THREAD;
             assert(thread->is_Java_thread(), "thread->is_Java_thread()");
-            JvmtiExport::post_class_load((JavaThread *) thread, k());
+            JvmtiExport::post_class_load((JavaThread *) thread, k);
           }
         }
       }
@@ -897,7 +892,7 @@
     }
   }
 
-  if (HAS_PENDING_EXCEPTION || k.is_null()) {
+  if (HAS_PENDING_EXCEPTION || k == NULL) {
     return NULL;
   }
 
@@ -908,12 +903,12 @@
     ClassLoaderData* loader_data = k->class_loader_data();
     MutexLocker mu(SystemDictionary_lock, THREAD);
     Klass* kk = find_class(name, loader_data);
-    assert(kk == k(), "should be present in dictionary");
+    assert(kk == k, "should be present in dictionary");
   }
 #endif
 
   // return if the protection domain in NULL
-  if (protection_domain() == NULL) return k();
+  if (protection_domain() == NULL) return k;
 
   // Check the protection domain has the right access
   {
@@ -928,14 +923,14 @@
     if (dictionary()->is_valid_protection_domain(d_index, d_hash, name,
                                                  loader_data,
                                                  protection_domain)) {
-      return k();
+      return k;
     }
   }
 
   // Verify protection domain. If it fails an exception is thrown
   validate_protection_domain(k, class_loader, protection_domain, CHECK_NULL);
 
-  return k();
+  return k;
 }
 
 
@@ -1017,13 +1012,13 @@
 // 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,
-                                      ClassFileStream* st,
-                                      const InstanceKlass* host_klass,
-                                      GrowableArray<Handle>* cp_patches,
-                                      TRAPS) {
+InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
+                                              Handle class_loader,
+                                              Handle protection_domain,
+                                              ClassFileStream* st,
+                                              const InstanceKlass* host_klass,
+                                              GrowableArray<Handle>* cp_patches,
+                                              TRAPS) {
 
   Ticks class_load_start_time = Ticks::now();
 
@@ -1047,15 +1042,15 @@
   // already be present in the SystemDictionary, otherwise we would not
   // throw potential ClassFormatErrors.
 
-  instanceKlassHandle k = KlassFactory::create_from_stream(st,
-                                                           class_name,
-                                                           loader_data,
-                                                           protection_domain,
-                                                           host_klass,
-                                                           cp_patches,
-                                                           CHECK_NULL);
-
-  if (host_klass != NULL && k.not_null()) {
+  InstanceKlass* k = KlassFactory::create_from_stream(st,
+                                                      class_name,
+                                                      loader_data,
+                                                      protection_domain,
+                                                      host_klass,
+                                                      cp_patches,
+                                                      CHECK_NULL);
+
+  if (host_klass != NULL && k != NULL) {
     // If it's anonymous, initialize it now, since nobody else will.
 
     {
@@ -1081,7 +1076,7 @@
     // notify jvmti
     if (JvmtiExport::should_post_class_load()) {
         assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
-        JvmtiExport::post_class_load((JavaThread *) THREAD, k());
+        JvmtiExport::post_class_load((JavaThread *) THREAD, k);
     }
 
     post_class_load_event(class_load_start_time, k, loader_data);
@@ -1089,7 +1084,7 @@
   assert(host_klass != NULL || NULL == cp_patches,
          "cp_patches only found with host_klass");
 
-  return k();
+  return k;
 }
 
 // Add a klass to the system from a stream (called by jni_DefineClass and
@@ -1097,11 +1092,13 @@
 // Note: class_name can be NULL. In that case we do not know the name of
 // the class until we have parsed the stream.
 
-Klass* SystemDictionary::resolve_from_stream(Symbol* class_name,
-                                             Handle class_loader,
-                                             Handle protection_domain,
-                                             ClassFileStream* st,
-                                             TRAPS) {
+InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name,
+                                                     Handle class_loader,
+                                                     Handle protection_domain,
+                                                     ClassFileStream* st,
+                                                     TRAPS) {
+
+  HandleMark hm(THREAD);
 
   // Classloaders that support parallelism, e.g. bootstrap classloader,
   // or all classloaders with UnsyncloadClass do not acquire lock here
@@ -1123,9 +1120,7 @@
   // Note that we do this even though this klass might
   // already be present in the SystemDictionary, otherwise we would not
   // throw potential ClassFormatErrors.
-  //
-
- instanceKlassHandle k;
+ InstanceKlass* k = NULL;
 
 #if INCLUDE_CDS
   k = SystemDictionaryShared::lookup_from_stream(class_name,
@@ -1135,7 +1130,7 @@
                                                  CHECK_NULL);
 #endif
 
-  if (k.is_null()) {
+  if (k == NULL) {
     if (st->buffer() == NULL) {
       return NULL;
     }
@@ -1148,7 +1143,7 @@
                                          CHECK_NULL);
   }
 
-  assert(k.not_null(), "no klass created");
+  assert(k != NULL, "no klass created");
   Symbol* h_name = k->name();
   assert(class_name == NULL || class_name == h_name, "name mismatch");
 
@@ -1156,11 +1151,11 @@
   // 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)) {
-    instanceKlassHandle defined_k = find_or_define_instance_class(h_name, class_loader, k, THREAD);
-    if (!HAS_PENDING_EXCEPTION && defined_k() != k()) {
+    InstanceKlass* defined_k = find_or_define_instance_class(h_name, class_loader, k, THREAD);
+    if (!HAS_PENDING_EXCEPTION && defined_k != k) {
       // If a parallel capable class loader already defined this class, register 'k' for cleanup.
-      assert(defined_k.not_null(), "Should have a klass if there's no exception");
-      loader_data->add_to_deallocate_list(k());
+      assert(defined_k != NULL, "Should have a klass if there's no exception");
+      loader_data->add_to_deallocate_list(k);
       k = defined_k;
     }
   } else {
@@ -1169,8 +1164,8 @@
 
   // If defining the class throws an exception register 'k' for cleanup.
   if (HAS_PENDING_EXCEPTION) {
-    assert(k.not_null(), "Must have an instance klass here!");
-    loader_data->add_to_deallocate_list(k());
+    assert(k != NULL, "Must have an instance klass here!");
+    loader_data->add_to_deallocate_list(k);
     return NULL;
   }
 
@@ -1179,10 +1174,10 @@
     MutexLocker mu(SystemDictionary_lock, THREAD);
 
     Klass* check = find_class(h_name, k->class_loader_data());
-    assert(check == k(), "should be present in the dictionary");
+    assert(check == k, "should be present in the dictionary");
   } );
 
-  return k();
+  return k;
 }
 
 #if INCLUDE_CDS
@@ -1197,7 +1192,7 @@
 // If there is a shared dictionary, then find the entry for the
 // given shared system class, if any.
 
-Klass* SystemDictionary::find_shared_class(Symbol* class_name) {
+InstanceKlass* SystemDictionary::find_shared_class(Symbol* class_name) {
   if (shared_dictionary() != NULL) {
     unsigned int d_hash = shared_dictionary()->compute_hash(class_name, NULL);
     int d_index = shared_dictionary()->hash_to_index(d_hash);
@@ -1215,16 +1210,16 @@
 // subclasses (yet).  [Classes in the shared space are not part of the
 // object hierarchy until loaded.]
 
-instanceKlassHandle SystemDictionary::load_shared_class(
+InstanceKlass* SystemDictionary::load_shared_class(
                  Symbol* class_name, Handle class_loader, TRAPS) {
-  instanceKlassHandle ik (THREAD, find_shared_class(class_name));
+  InstanceKlass* ik = find_shared_class(class_name);
   // Make sure we only return the boot class for the NULL classloader.
-  if (ik.not_null() &&
+  if (ik != 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();
+  return NULL;
 }
 
 // Check if a shared class can be loaded by the specific classloader:
@@ -1234,7 +1229,7 @@
 //   - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
 //     be defined in an unnamed module.
 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
-                                               instanceKlassHandle ik,
+                                               InstanceKlass* ik,
                                                Handle class_loader, TRAPS) {
   assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
          "Cannot use sharing if java.base is patched");
@@ -1311,18 +1306,17 @@
   }
 }
 
-instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik,
-                                                        Handle class_loader,
-                                                        Handle protection_domain, TRAPS) {
-  instanceKlassHandle nh = instanceKlassHandle(); // null Handle
-
-  if (ik.not_null()) {
+InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
+                                                   Handle class_loader,
+                                                   Handle protection_domain, TRAPS) {
+
+  if (ik != NULL) {
     Symbol* class_name = ik->name();
 
     bool visible = is_shared_class_visible(
-                            class_name, ik, class_loader, CHECK_(nh));
+                            class_name, ik, class_loader, CHECK_NULL);
     if (!visible) {
-      return nh;
+      return NULL;
     }
 
     // Resolve the superclass and interfaces. They must be the same
@@ -1335,11 +1329,11 @@
     if (ik->super() != NULL) {
       Symbol*  cn = ik->super()->name();
       Klass *s = resolve_super_or_fail(class_name, cn,
-                                       class_loader, protection_domain, true, CHECK_(nh));
+                                       class_loader, protection_domain, true, CHECK_NULL);
       if (s != ik->super()) {
         // The dynamically resolved super class is not the same as the one we used during dump time,
         // so we cannot use ik.
-        return nh;
+        return NULL;
       } else {
         assert(s->is_shared(), "must be");
       }
@@ -1349,25 +1343,20 @@
     int num_interfaces = interfaces->length();
     for (int index = 0; index < num_interfaces; index++) {
       Klass* k = interfaces->at(index);
-
-      // Note: can not use InstanceKlass::cast here because
-      // interfaces' InstanceKlass's C++ vtbls haven't been
-      // reinitialized yet (they will be once the interface classes
-      // are loaded)
       Symbol*  name  = k->name();
-      Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_(nh));
+      Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_NULL);
       if (k != i) {
         // The dynamically resolved interface class is not the same as the one we used during dump time,
         // so we cannot use ik.
-        return nh;
+        return NULL;
       } else {
         assert(i->is_shared(), "must be");
       }
     }
 
-    instanceKlassHandle new_ik = KlassFactory::check_shared_class_file_load_hook(
-        ik, class_name, class_loader, protection_domain, CHECK_(nh));
-    if (new_ik.not_null()) {
+    InstanceKlass* new_ik = KlassFactory::check_shared_class_file_load_hook(
+        ik, class_name, class_loader, protection_domain, CHECK_NULL);
+    if (new_ik != NULL) {
       // The class is changed by CFLH. Return the new class. The shared class is
       // not used.
       return new_ik;
@@ -1386,21 +1375,22 @@
 
     ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
     {
+      HandleMark hm(THREAD);
       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));
+      ik->restore_unshareable_info(loader_data, protection_domain, CHECK_NULL);
     }
 
     if (log_is_enabled(Info, class, load)) {
-      ik()->print_loading_log(LogLevel::Info, loader_data, NULL, NULL);
+      ik->print_loading_log(LogLevel::Info, loader_data, NULL, NULL);
     }
     // No 'else' here as logging levels are not mutually exclusive
 
     if (log_is_enabled(Debug, class, load)) {
-      ik()->print_loading_log(LogLevel::Debug, loader_data, NULL, NULL);
+      ik->print_loading_log(LogLevel::Debug, loader_data, NULL, NULL);
     }
 
     // For boot loader, ensure that GetSystemPackage knows that a class in this
@@ -1421,12 +1411,12 @@
     }
 
     // notify a class loaded from shared object
-    ClassLoadingService::notify_class_loaded(ik(), true /* shared class */);
+    ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
   }
 
   ik->set_has_passed_fingerprint_check(false);
   if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
-    uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik());
+    uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);
     uint64_t cds_fp = ik->get_stored_fingerprint();
     if (aot_fp != 0 && aot_fp == cds_fp) {
       // This class matches with a class saved in an AOT library
@@ -1440,8 +1430,7 @@
 }
 #endif // INCLUDE_CDS
 
-instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
-  instanceKlassHandle nh = instanceKlassHandle(); // null Handle
+InstanceKlass* SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
 
   if (class_loader.is_null()) {
     ResourceMark rm;
@@ -1473,14 +1462,14 @@
           // and its package will be checked later by
           // ModuleEntryTable::verify_javabase_packages.
           if (ModuleEntryTable::javabase_defined()) {
-            return nh;
+            return NULL;
           }
         } else {
           // Check that the class' package is defined within java.base.
           ModuleEntry* mod_entry = pkg_entry->module();
           Symbol* mod_entry_name = mod_entry->name();
           if (mod_entry_name->fast_compare(vmSymbols::java_base()) != 0) {
-            return nh;
+            return NULL;
           }
         }
       }
@@ -1506,7 +1495,7 @@
 
     // Search the shared system dictionary for classes preloaded into the
     // shared spaces.
-    instanceKlassHandle k;
+    InstanceKlass* k = NULL;
     {
 #if INCLUDE_CDS
       PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
@@ -1514,24 +1503,24 @@
 #endif
     }
 
-    if (k.is_null()) {
+    if (k == NULL) {
       // Use VM class loader
       PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
-      k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_(nh));
+      k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL);
     }
 
     // find_or_define_instance_class may return a different InstanceKlass
-    if (!k.is_null()) {
-      instanceKlassHandle defined_k =
+    if (k != NULL) {
+      InstanceKlass* defined_k =
         find_or_define_instance_class(class_name, class_loader, k, THREAD);
-      if (!HAS_PENDING_EXCEPTION && defined_k() != k()) {
+      if (!HAS_PENDING_EXCEPTION && defined_k != k) {
         // If a parallel capable class loader already defined this class, register 'k' for cleanup.
-        assert(defined_k.not_null(), "Should have a klass if there's no exception");
-        loader_data->add_to_deallocate_list(k());
+        assert(defined_k != NULL, "Should have a klass if there's no exception");
+        loader_data->add_to_deallocate_list(k);
         k = defined_k;
       } else if (HAS_PENDING_EXCEPTION) {
-        loader_data->add_to_deallocate_list(k());
-        return nh;
+        loader_data->add_to_deallocate_list(k);
+        return NULL;
       }
     }
     return k;
@@ -1549,13 +1538,13 @@
                                jt->get_thread_stat()->perf_timers_addr(),
                                PerfClassTraceTime::CLASS_LOAD);
 
-    Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nh));
+    Handle s = java_lang_String::create_from_symbol(class_name, CHECK_NULL);
     // Translate to external class name format, i.e., convert '/' chars to '.'
-    Handle string = java_lang_String::externalize_classname(s, CHECK_(nh));
+    Handle string = java_lang_String::externalize_classname(s, CHECK_NULL);
 
     JavaValue result(T_OBJECT);
 
-    KlassHandle spec_klass (THREAD, SystemDictionary::ClassLoader_klass());
+    InstanceKlass* spec_klass = SystemDictionary::ClassLoader_klass();
 
     // Call public unsynchronized loadClass(String) directly for all class loaders
     // for parallelCapable class loaders. JDK >=7, loadClass(String, boolean) will
@@ -1581,7 +1570,7 @@
                               vmSymbols::loadClassInternal_name(),
                               vmSymbols::string_class_signature(),
                               string,
-                              CHECK_(nh));
+                              CHECK_NULL);
     } else {
       JavaCalls::call_virtual(&result,
                               class_loader,
@@ -1589,7 +1578,7 @@
                               vmSymbols::loadClass_name(),
                               vmSymbols::string_class_signature(),
                               string,
-                              CHECK_(nh));
+                              CHECK_NULL);
     }
 
     assert(result.get_type() == T_OBJECT, "just checking");
@@ -1598,8 +1587,7 @@
     // Primitive classes return null since forName() can not be
     // used to obtain any of the Class objects representing primitives or void
     if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) {
-      instanceKlassHandle k =
-                instanceKlassHandle(THREAD, java_lang_Class::as_Klass(obj));
+      InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(obj));
       // For user defined Java class loaders, check that the name returned is
       // the same as that requested.  This check is done for the bootstrap
       // loader when parsing the class file.
@@ -1608,12 +1596,13 @@
       }
     }
     // Class is not found or has the wrong name, return NULL
-    return nh;
+    return NULL;
   }
 }
 
-void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
-
+void SystemDictionary::define_instance_class(InstanceKlass* k, TRAPS) {
+
+  HandleMark hm(THREAD);
   ClassLoaderData* loader_data = k->class_loader_data();
   Handle class_loader_h(THREAD, loader_data->class_loader());
 
@@ -1676,7 +1665,7 @@
   // notify jvmti
   if (JvmtiExport::should_post_class_load()) {
       assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
-      JvmtiExport::post_class_load((JavaThread *) THREAD, k());
+      JvmtiExport::post_class_load((JavaThread *) THREAD, k);
 
   }
   class_define_event(k, loader_data);
@@ -1702,16 +1691,16 @@
 // 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
+InstanceKlass* SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader,
+                                                               InstanceKlass* k, TRAPS) {
+
   Symbol*  name_h = k->name(); // passed in class_name may be null
   ClassLoaderData* loader_data = class_loader_data(class_loader);
 
   unsigned int d_hash = dictionary()->compute_hash(name_h, loader_data);
   int d_index = dictionary()->hash_to_index(d_hash);
 
-// Hold SD lock around find_class and placeholder creation for DEFINE_CLASS
+  // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS
   unsigned int p_hash = placeholders()->compute_hash(name_h, loader_data);
   int p_index = placeholders()->hash_to_index(p_hash);
   PlaceholderEntry* probe;
@@ -1720,9 +1709,9 @@
     MutexLocker mu(SystemDictionary_lock, THREAD);
     // First check if class already defined
     if (UnsyncloadClass || (is_parallelDefine(class_loader))) {
-      Klass* check = find_class(d_index, d_hash, name_h, loader_data);
+      InstanceKlass* check = find_class(d_index, d_hash, name_h, loader_data);
       if (check != NULL) {
-        return(instanceKlassHandle(THREAD, check));
+        return check;
       }
     }
 
@@ -1742,10 +1731,10 @@
         placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD);
         SystemDictionary_lock->notify_all();
 #ifdef ASSERT
-        Klass* check = find_class(d_index, d_hash, name_h, loader_data);
+        InstanceKlass* check = find_class(d_index, d_hash, name_h, loader_data);
         assert(check != NULL, "definer missed recording success");
 #endif
-        return(instanceKlassHandle(THREAD, probe->instance_klass()));
+        return probe->instance_klass();
     } else {
       // This thread will define the class (even if earlier thread tried and had an error)
       probe->set_definer(THREAD);
@@ -1766,7 +1755,7 @@
         linkage_exception = Handle(THREAD,PENDING_EXCEPTION);
         CLEAR_PENDING_EXCEPTION;
       } else {
-        probe->set_instance_klass(k());
+        probe->set_instance_klass(k);
       }
       probe->set_definer(NULL);
       placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD);
@@ -1776,7 +1765,7 @@
 
   // Can't throw exception while holding lock due to rank ordering
   if (linkage_exception() != NULL) {
-    THROW_OOP_(linkage_exception(), nh); // throws exception and returns
+    THROW_OOP_(linkage_exception(), NULL); // throws exception and returns
   }
 
   return k;
@@ -1816,15 +1805,14 @@
 // ----------------------------------------------------------------------------
 // Lookup
 
-Klass* SystemDictionary::find_class(int index, unsigned int hash,
-                                      Symbol* class_name,
-                                      ClassLoaderData* loader_data) {
+InstanceKlass* SystemDictionary::find_class(int index, unsigned int hash,
+                                            Symbol* class_name,
+                                            ClassLoaderData* loader_data) {
   assert_locked_or_safepoint(SystemDictionary_lock);
   assert (index == dictionary()->index_for(class_name, loader_data),
           "incorrect index?");
 
-  Klass* k = dictionary()->find_class(index, hash, class_name, loader_data);
-  return k;
+  return dictionary()->find_class(index, hash, class_name, loader_data);
 }
 
 
@@ -1839,7 +1827,7 @@
 
 
 // Used for assertions and verification only
-Klass* SystemDictionary::find_class(Symbol* class_name, ClassLoaderData* loader_data) {
+InstanceKlass* SystemDictionary::find_class(Symbol* class_name, ClassLoaderData* loader_data) {
   #ifndef ASSERT
   guarantee(VerifyBeforeGC      ||
             VerifyDuringGC      ||
@@ -1867,8 +1855,8 @@
 // is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in
 // before a new class is used.
 
-void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
-  assert(k.not_null(), "just checking");
+void SystemDictionary::add_to_hierarchy(InstanceKlass* k, TRAPS) {
+  assert(k != NULL, "just checking");
   assert_locked_or_safepoint(Compile_lock);
 
   // Link into hierachy. Make sure the vtables are initialized before linking into
@@ -2149,8 +2137,7 @@
   if (UseSharedSpaces) {
     initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK);
     // Initialize the constant pool for the Object_class
-    InstanceKlass* ik = InstanceKlass::cast(Object_klass());
-    ik->constants()->restore_unshareable_info(CHECK);
+    Object_klass()->constants()->restore_unshareable_info(CHECK);
     initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
   } else {
     initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
@@ -2230,7 +2217,7 @@
 // if initiating loader, then ok if InstanceKlass matches existing entry
 
 void SystemDictionary::check_constraints(int d_index, unsigned int d_hash,
-                                         instanceKlassHandle k,
+                                         InstanceKlass* k,
                                          Handle class_loader, bool defining,
                                          TRAPS) {
   const char *linkage_error1 = NULL;
@@ -2241,8 +2228,8 @@
 
     MutexLocker mu(SystemDictionary_lock, THREAD);
 
-    Klass* check = find_class(d_index, d_hash, name, loader_data);
-    if (check != (Klass*)NULL) {
+    InstanceKlass* check = find_class(d_index, d_hash, name, loader_data);
+    if (check != NULL) {
       // if different InstanceKlass - duplicate class definition,
       // else - ok, class loaded by a different thread in parallel,
       // we should only have found it if it was done loading and ok to use
@@ -2250,9 +2237,9 @@
       // also holds array classes
 
       assert(check->is_instance_klass(), "noninstance in systemdictionary");
-      if ((defining == true) || (k() != check)) {
-        linkage_error1 = "loader (instance of  ";
-        linkage_error2 = "): attempted  duplicate class definition for name: \"";
+      if ((defining == true) || (k != check)) {
+        linkage_error1 = "loader (instance of ";
+        linkage_error2 = "): attempted duplicate class definition for name: \"";
       } else {
         return;
       }
@@ -2291,7 +2278,7 @@
 // have been called.
 void SystemDictionary::update_dictionary(int d_index, unsigned int d_hash,
                                          int p_index, unsigned int p_hash,
-                                         instanceKlassHandle k,
+                                         InstanceKlass* k,
                                          Handle class_loader,
                                          TRAPS) {
   // Compile_lock prevents systemDictionary updates during compilations
@@ -2323,7 +2310,7 @@
   }
 
   // Make a new system dictionary entry.
-  Klass* sd_check = find_class(d_index, d_hash, name, loader_data);
+  InstanceKlass* sd_check = find_class(d_index, d_hash, name, loader_data);
   if (sd_check == NULL) {
     dictionary()->add_klass(name, loader_data, k);
     notice_modification();
@@ -2414,8 +2401,8 @@
   // Better never do a GC while we're holding these oops
   NoSafepointVerifier nosafepoint;
 
-  Klass* klass1 = find_class(d_index1, d_hash1, constraint_name, loader_data1);
-  Klass* klass2 = find_class(d_index2, d_hash2, constraint_name, loader_data2);
+  InstanceKlass* klass1 = find_class(d_index1, d_hash1, constraint_name, loader_data1);
+  InstanceKlass* klass2 = find_class(d_index2, d_hash2, constraint_name, loader_data2);
   return constraints()->add_entry(constraint_name, klass1, class_loader1,
                                   klass2, class_loader2);
   }
@@ -2575,7 +2562,7 @@
 
 // Helper for unpacking the return value from linkMethod and linkCallSite.
 static methodHandle unpack_method_and_appendix(Handle mname,
-                                               KlassHandle accessing_klass,
+                                               Klass* accessing_klass,
                                                objArrayHandle appendix_box,
                                                Handle* appendix_result,
                                                TRAPS) {
@@ -2599,7 +2586,7 @@
       // MethodName is dropped we need a way to make sure the
       // class_loader containing this method is kept alive.
       // FIXME: the appendix might also preserve this dependency.
-      ClassLoaderData* this_key = InstanceKlass::cast(accessing_klass())->class_loader_data();
+      ClassLoaderData* this_key = accessing_klass->class_loader_data();
       this_key->record_dependency(m->method_holder(), CHECK_NULL); // Can throw OOM
       return methodHandle(THREAD, m);
     }
@@ -2608,10 +2595,10 @@
   return empty;
 }
 
-methodHandle SystemDictionary::find_method_handle_invoker(KlassHandle klass,
+methodHandle SystemDictionary::find_method_handle_invoker(Klass* klass,
                                                           Symbol* name,
                                                           Symbol* signature,
-                                                          KlassHandle accessing_klass,
+                                                          Klass* accessing_klass,
                                                           Handle *appendix_result,
                                                           Handle *method_type_result,
                                                           TRAPS) {
@@ -2621,23 +2608,24 @@
     SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty));
 
   int ref_kind = JVM_REF_invokeVirtual;
-  Handle name_str = StringTable::intern(name, CHECK_(empty));
-  objArrayHandle appendix_box = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK_(empty));
+  oop name_oop = StringTable::intern(name, CHECK_(empty));
+  Handle name_str (THREAD, name_oop);
+  objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty));
   assert(appendix_box->obj_at(0) == NULL, "");
 
   // This should not happen.  JDK code should take care of that.
-  if (accessing_klass.is_null() || method_type.is_null()) {
+  if (accessing_klass == NULL || method_type.is_null()) {
     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokehandle", empty);
   }
 
   // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName
   JavaCallArguments args;
-  args.push_oop(accessing_klass()->java_mirror());
+  args.push_oop(Handle(THREAD, accessing_klass->java_mirror()));
   args.push_int(ref_kind);
-  args.push_oop(klass()->java_mirror());
-  args.push_oop(name_str());
-  args.push_oop(method_type());
-  args.push_oop(appendix_box());
+  args.push_oop(Handle(THREAD, klass->java_mirror()));
+  args.push_oop(name_str);
+  args.push_oop(method_type);
+  args.push_oop(appendix_box);
   JavaValue result(T_OBJECT);
   JavaCalls::call_static(&result,
                          SystemDictionary::MethodHandleNatives_klass(),
@@ -2673,7 +2661,7 @@
 // Because of class loader constraints, all method handle usage must be
 // consistent with this loader.
 Handle SystemDictionary::find_method_handle_type(Symbol* signature,
-                                                 KlassHandle accessing_klass,
+                                                 Klass* accessing_klass,
                                                  TRAPS) {
   Handle empty;
   vmIntrinsics::ID null_iid = vmIntrinsics::_none;  // distinct from all method handle invoker intrinsics
@@ -2689,13 +2677,13 @@
   }
 
   Handle class_loader, protection_domain;
-  if (accessing_klass.not_null()) {
-    class_loader      = Handle(THREAD, InstanceKlass::cast(accessing_klass())->class_loader());
-    protection_domain = Handle(THREAD, InstanceKlass::cast(accessing_klass())->protection_domain());
+  if (accessing_klass != NULL) {
+    class_loader      = Handle(THREAD, accessing_klass->class_loader());
+    protection_domain = Handle(THREAD, accessing_klass->protection_domain());
   }
   bool can_be_cached = true;
   int npts = ArgumentCount(signature).size();
-  objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::Class_klass(), npts, CHECK_(empty));
+  objArrayHandle pts = oopFactory::new_objArray_handle(SystemDictionary::Class_klass(), npts, CHECK_(empty));
   int arg = 0;
   Handle rt; // the return type from the signature
   ResourceMark rm(THREAD);
@@ -2722,15 +2710,14 @@
       pts->obj_at_put(arg++, mirror);
 
     // Check accessibility.
-    if (ss.is_object() && accessing_klass.not_null()) {
+    if (ss.is_object() && accessing_klass != NULL) {
       Klass* sel_klass = java_lang_Class::as_Klass(mirror);
       mirror = NULL;  // safety
       // Emulate ConstantPool::verify_constant_pool_resolve.
       if (sel_klass->is_objArray_klass())
         sel_klass = ObjArrayKlass::cast(sel_klass)->bottom_klass();
       if (sel_klass->is_instance_klass()) {
-        KlassHandle sel_kh(THREAD, sel_klass);
-        LinkResolver::check_klass_accessability(accessing_klass, sel_kh, CHECK_(empty));
+        LinkResolver::check_klass_accessability(accessing_klass, sel_klass, CHECK_(empty));
       }
     }
   }
@@ -2738,7 +2725,7 @@
 
   // call java.lang.invoke.MethodHandleNatives::findMethodHandleType(Class rt, Class[] pts) -> MethodType
   JavaCallArguments args(Handle(THREAD, rt()));
-  args.push_oop(pts());
+  args.push_oop(pts);
   JavaValue result(T_OBJECT);
   JavaCalls::call_static(&result,
                          SystemDictionary::MethodHandleNatives_klass(),
@@ -2763,9 +2750,9 @@
 }
 
 // Ask Java code to find or construct a method handle constant.
-Handle SystemDictionary::link_method_handle_constant(KlassHandle caller,
+Handle SystemDictionary::link_method_handle_constant(Klass* caller,
                                                      int ref_kind, //e.g., JVM_REF_invokeVirtual
-                                                     KlassHandle callee,
+                                                     Klass* callee,
                                                      Symbol* name_sym,
                                                      Symbol* signature,
                                                      TRAPS) {
@@ -2774,14 +2761,15 @@
   Handle type;
   if (signature->utf8_length() > 0 && signature->byte_at(0) == '(') {
     type = find_method_handle_type(signature, caller, CHECK_(empty));
-  } else if (caller.is_null()) {
+  } else if (caller == NULL) {
     // This should not happen.  JDK code should take care of that.
     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad MH constant", empty);
   } else {
     ResourceMark rm(THREAD);
     SignatureStream ss(signature, false);
     if (!ss.is_done()) {
-      oop mirror = ss.as_java_mirror(caller->class_loader(), caller->protection_domain(),
+      oop mirror = ss.as_java_mirror(Handle(THREAD, caller->class_loader()),
+                                     Handle(THREAD, caller->protection_domain()),
                                      SignatureStream::NCDFError, CHECK_(empty));
       type = Handle(THREAD, mirror);
       ss.next();
@@ -2794,11 +2782,11 @@
 
   // call java.lang.invoke.MethodHandleNatives::linkMethodHandleConstant(Class caller, int refKind, Class callee, String name, Object type) -> MethodHandle
   JavaCallArguments args;
-  args.push_oop(caller->java_mirror());  // the referring class
+  args.push_oop(Handle(THREAD, caller->java_mirror()));  // the referring class
   args.push_int(ref_kind);
-  args.push_oop(callee->java_mirror());  // the target class
-  args.push_oop(name());
-  args.push_oop(type());
+  args.push_oop(Handle(THREAD, callee->java_mirror()));  // the target class
+  args.push_oop(name);
+  args.push_oop(type);
   JavaValue result(T_OBJECT);
   JavaCalls::call_static(&result,
                          SystemDictionary::MethodHandleNatives_klass(),
@@ -2810,7 +2798,7 @@
 
 // Ask Java code to find or construct a java.lang.invoke.CallSite for the given
 // name and signature, as interpreted relative to the given class loader.
-methodHandle SystemDictionary::find_dynamic_call_site_invoker(KlassHandle caller,
+methodHandle SystemDictionary::find_dynamic_call_site_invoker(Klass* caller,
                                                               Handle bootstrap_specifier,
                                                               Symbol* name,
                                                               Symbol* type,
@@ -2841,20 +2829,20 @@
   Handle method_type = find_method_handle_type(type, caller, CHECK_(empty));
 
   // This should not happen.  JDK code should take care of that.
-  if (caller.is_null() || method_type.is_null()) {
+  if (caller == NULL || method_type.is_null()) {
     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokedynamic", empty);
   }
 
-  objArrayHandle appendix_box = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK_(empty));
+  objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty));
   assert(appendix_box->obj_at(0) == NULL, "");
 
   // call java.lang.invoke.MethodHandleNatives::linkCallSite(caller, bsm, name, mtype, info, &appendix)
   JavaCallArguments args;
-  args.push_oop(caller->java_mirror());
-  args.push_oop(bsm());
-  args.push_oop(method_name());
-  args.push_oop(method_type());
-  args.push_oop(info());
+  args.push_oop(Handle(THREAD, caller->java_mirror()));
+  args.push_oop(bsm);
+  args.push_oop(method_name);
+  args.push_oop(method_type);
+  args.push_oop(info);
   args.push_oop(appendix_box);
   JavaValue result(T_OBJECT);
   JavaCalls::call_static(&result,
--- a/hotspot/src/share/vm/classfile/systemDictionary.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/systemDictionary.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -259,7 +259,7 @@
   static Klass* resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS);
 protected:
   // handle error translation for resolve_or_null results
-  static Klass* handle_resolution_exception(Symbol* class_name, bool throw_error, KlassHandle klass_h, TRAPS);
+  static Klass* handle_resolution_exception(Symbol* class_name, bool throw_error, Klass* klass, TRAPS);
 
 public:
 
@@ -282,11 +282,11 @@
   // 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,
-                             ClassFileStream* st,
-                             TRAPS) {
+  static InstanceKlass* parse_stream(Symbol* class_name,
+                                     Handle class_loader,
+                                     Handle protection_domain,
+                                     ClassFileStream* st,
+                                     TRAPS) {
     return parse_stream(class_name,
                         class_loader,
                         protection_domain,
@@ -295,20 +295,20 @@
                         NULL, // cp_patches
                         THREAD);
   }
-  static Klass* parse_stream(Symbol* class_name,
-                             Handle class_loader,
-                             Handle protection_domain,
-                             ClassFileStream* st,
-                             const InstanceKlass* host_klass,
-                             GrowableArray<Handle>* cp_patches,
-                             TRAPS);
+  static InstanceKlass* parse_stream(Symbol* class_name,
+                                     Handle class_loader,
+                                     Handle protection_domain,
+                                     ClassFileStream* st,
+                                     const InstanceKlass* host_klass,
+                                     GrowableArray<Handle>* cp_patches,
+                                     TRAPS);
 
   // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
-  static Klass* resolve_from_stream(Symbol* class_name,
-                                    Handle class_loader,
-                                    Handle protection_domain,
-                                    ClassFileStream* st,
-                                    TRAPS);
+  static InstanceKlass* resolve_from_stream(Symbol* class_name,
+                                            Handle class_loader,
+                                            Handle protection_domain,
+                                            ClassFileStream* st,
+                                            TRAPS);
 
   // Lookup an already loaded class. If not found NULL is returned.
   static Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
@@ -516,10 +516,10 @@
   // JSR 292
   // find a java.lang.invoke.MethodHandle.invoke* method for a given signature
   // (asks Java to compute it if necessary, except in a compiler thread)
-  static methodHandle find_method_handle_invoker(KlassHandle klass,
+  static methodHandle find_method_handle_invoker(Klass* klass,
                                                  Symbol* name,
                                                  Symbol* signature,
-                                                 KlassHandle accessing_klass,
+                                                 Klass* accessing_klass,
                                                  Handle *appendix_result,
                                                  Handle *method_type_result,
                                                  TRAPS);
@@ -531,19 +531,19 @@
   // find a java.lang.invoke.MethodType object for a given signature
   // (asks Java to compute it if necessary, except in a compiler thread)
   static Handle    find_method_handle_type(Symbol* signature,
-                                           KlassHandle accessing_klass,
+                                           Klass* accessing_klass,
                                            TRAPS);
 
   // ask Java to compute a java.lang.invoke.MethodHandle object for a given CP entry
-  static Handle    link_method_handle_constant(KlassHandle caller,
+  static Handle    link_method_handle_constant(Klass* caller,
                                                int ref_kind, //e.g., JVM_REF_invokeVirtual
-                                               KlassHandle callee,
+                                               Klass* callee,
                                                Symbol* name,
                                                Symbol* signature,
                                                TRAPS);
 
   // ask Java to create a dynamic call site, while linking an invokedynamic op
-  static methodHandle find_dynamic_call_site_invoker(KlassHandle caller,
+  static methodHandle find_dynamic_call_site_invoker(Klass* caller,
                                                      Handle bootstrap_method,
                                                      Symbol* name,
                                                      Symbol* type,
@@ -615,7 +615,7 @@
   static Klass* try_get_next_class();
 
 protected:
-  static void validate_protection_domain(instanceKlassHandle klass,
+  static void validate_protection_domain(InstanceKlass* klass,
                                          Handle class_loader,
                                          Handle protection_domain, TRAPS);
 
@@ -631,48 +631,48 @@
   // Basic loading operations
   static Klass* resolve_instance_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
   static Klass* resolve_array_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
-  static instanceKlassHandle handle_parallel_super_load(Symbol* class_name, Symbol* supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS);
+  static InstanceKlass* handle_parallel_super_load(Symbol* class_name, Symbol* supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS);
   // Wait on SystemDictionary_lock; unlocks lockObject before
   // waiting; relocks lockObject with correct recursion count
   // after waiting, but before reentering SystemDictionary_lock
   // to preserve lock order semantics.
   static void double_lock_wait(Handle lockObject, TRAPS);
-  static void define_instance_class(instanceKlassHandle k, TRAPS);
-  static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
+  static void define_instance_class(InstanceKlass* k, TRAPS);
+  static InstanceKlass* find_or_define_instance_class(Symbol* class_name,
                                                 Handle class_loader,
-                                                instanceKlassHandle k, TRAPS);
-  static bool is_shared_class_visible(Symbol* class_name, instanceKlassHandle ik,
+                                                InstanceKlass* k, TRAPS);
+  static bool is_shared_class_visible(Symbol* class_name, InstanceKlass* ik,
                                       Handle class_loader, TRAPS);
-  static instanceKlassHandle load_shared_class(instanceKlassHandle ik,
-                                               Handle class_loader,
-                                               Handle protection_domain,
-                                               TRAPS);
-  static instanceKlassHandle load_instance_class(Symbol* class_name, Handle class_loader, TRAPS);
+  static InstanceKlass* load_shared_class(InstanceKlass* ik,
+                                          Handle class_loader,
+                                          Handle protection_domain,
+                                          TRAPS);
+  static InstanceKlass* load_instance_class(Symbol* class_name, Handle class_loader, TRAPS);
   static Handle compute_loader_lock_object(Handle class_loader, TRAPS);
   static void check_loader_lock_contention(Handle loader_lock, TRAPS);
   static bool is_parallelCapable(Handle class_loader);
   static bool is_parallelDefine(Handle class_loader);
 
 public:
-  static instanceKlassHandle load_shared_class(Symbol* class_name,
-                                               Handle class_loader,
-                                               TRAPS);
-  static bool is_system_class_loader(Handle class_loader);
-  static bool is_platform_class_loader(Handle class_loader);
+  static InstanceKlass* load_shared_class(Symbol* class_name,
+                                          Handle class_loader,
+                                          TRAPS);
+  static bool is_system_class_loader(oop class_loader);
+  static bool is_platform_class_loader(oop class_loader);
 
 protected:
-  static Klass* find_shared_class(Symbol* class_name);
+  static InstanceKlass* find_shared_class(Symbol* class_name);
 
   // Setup link to hierarchy
-  static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
+  static void add_to_hierarchy(InstanceKlass* k, TRAPS);
 
   // We pass in the hashtable index so we can calculate it outside of
   // the SystemDictionary_lock.
 
   // Basic find on loaded classes
-  static Klass* find_class(int index, unsigned int hash,
-                             Symbol* name, ClassLoaderData* loader_data);
-  static Klass* find_class(Symbol* class_name, ClassLoaderData* loader_data);
+  static InstanceKlass* find_class(int index, unsigned int hash,
+                                   Symbol* name, ClassLoaderData* loader_data);
+  static InstanceKlass* find_class(Symbol* class_name, ClassLoaderData* loader_data);
 
   // Basic find on classes in the midst of being loaded
   static Symbol* find_placeholder(Symbol* name, ClassLoaderData* loader_data);
@@ -697,11 +697,11 @@
 
   // Class loader constraints
   static void check_constraints(int index, unsigned int hash,
-                                instanceKlassHandle k, Handle loader,
+                                InstanceKlass* k, Handle loader,
                                 bool defining, TRAPS);
   static void update_dictionary(int d_index, unsigned int d_hash,
                                 int p_index, unsigned int p_hash,
-                                instanceKlassHandle k, Handle loader,
+                                InstanceKlass* k, Handle loader,
                                 TRAPS);
 
   // Variables holding commonly used klasses (preloaded)
--- a/hotspot/src/share/vm/classfile/systemDictionaryShared.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/systemDictionaryShared.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,10 +33,10 @@
 class SystemDictionaryShared: public SystemDictionary {
 public:
   static void initialize(TRAPS) {}
-  static instanceKlassHandle find_or_load_shared_class(Symbol* class_name,
-                                                       Handle class_loader,
-                                                       TRAPS) {
-    return instanceKlassHandle();
+  static InstanceKlass* find_or_load_shared_class(Symbol* class_name,
+                                                  Handle class_loader,
+                                                  TRAPS) {
+    return NULL;
   }
   static void roots_oops_do(OopClosure* blk) {}
   static void oops_do(OopClosure* f) {}
@@ -45,7 +45,7 @@
     return (class_loader == NULL);
   }
   static bool is_shared_class_visible_for_classloader(
-                                      instanceKlassHandle ik,
+                                      InstanceKlass* ik,
                                       Handle class_loader,
                                       const char* pkg_string,
                                       Symbol* pkg_name,
@@ -86,7 +86,7 @@
                   Symbol* from_name, bool from_field_is_protected,
                   bool from_is_array, bool from_is_object) {return false;}
   static void finalize_verification_constraints() {}
-  static void check_verification_constraints(instanceKlassHandle klass,
+  static void check_verification_constraints(InstanceKlass* klass,
                                               TRAPS) {}
 };
 
--- a/hotspot/src/share/vm/classfile/verificationType.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/verificationType.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,17 +42,16 @@
   }
 }
 
-bool VerificationType::resolve_and_check_assignability(instanceKlassHandle klass, Symbol* name,
+bool VerificationType::resolve_and_check_assignability(InstanceKlass* klass, Symbol* name,
          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object, TRAPS) {
-  Klass* obj = SystemDictionary::resolve_or_fail(
+  HandleMark hm(THREAD);
+  Klass* this_class = SystemDictionary::resolve_or_fail(
       name, Handle(THREAD, klass->class_loader()),
       Handle(THREAD, klass->protection_domain()), true, CHECK_false);
   if (log_is_enabled(Debug, class, resolve)) {
-    Verifier::trace_class_resolution(obj, klass());
+    Verifier::trace_class_resolution(this_class, klass);
   }
 
-  KlassHandle this_class(THREAD, obj);
-
   if (this_class->is_interface() && (!from_field_is_protected ||
       from_name != vmSymbols::java_lang_Object())) {
     // If we are not trying to access a protected field or method in
@@ -67,9 +66,9 @@
         from_name, Handle(THREAD, klass->class_loader()),
         Handle(THREAD, klass->protection_domain()), true, CHECK_false);
     if (log_is_enabled(Debug, class, resolve)) {
-      Verifier::trace_class_resolution(from_class, klass());
+      Verifier::trace_class_resolution(from_class, klass);
     }
-    return InstanceKlass::cast(from_class)->is_subclass_of(this_class());
+    return InstanceKlass::cast(from_class)->is_subclass_of(this_class);
   }
 
   return false;
@@ -78,7 +77,7 @@
 bool VerificationType::is_reference_assignable_from(
     const VerificationType& from, ClassVerifier* context,
     bool from_field_is_protected, TRAPS) const {
-  instanceKlassHandle klass = context->current_class();
+  InstanceKlass* klass = context->current_class();
   if (from.is_null()) {
     // null is assignable to any reference
     return true;
@@ -93,7 +92,7 @@
       return true;
     }
 
-    if (DumpSharedSpaces && SystemDictionaryShared::add_verification_constraint(klass(),
+    if (DumpSharedSpaces && SystemDictionaryShared::add_verification_constraint(klass,
               name(), from.name(), from_field_is_protected, from.is_array(),
               from.is_object())) {
       // If add_verification_constraint() returns true, the resolution/check should be
@@ -101,7 +100,7 @@
       return true;
     }
 
-    return resolve_and_check_assignability(klass(), name(), from.name(),
+    return resolve_and_check_assignability(klass, name(), from.name(),
           from_field_is_protected, from.is_array(), from.is_object(), THREAD);
   } else if (is_array() && from.is_array()) {
     VerificationType comp_this = get_component(context, CHECK_false);
--- a/hotspot/src/share/vm/classfile/verificationType.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/verificationType.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -336,7 +336,7 @@
     TRAPS) const;
 
  public:
-  static bool resolve_and_check_assignability(instanceKlassHandle klass, Symbol* name,
+  static bool resolve_and_check_assignability(InstanceKlass* klass, Symbol* name,
                                               Symbol* from_name, bool from_field_is_protected,
                                               bool from_is_array, bool from_is_object,
                                               TRAPS);
--- a/hotspot/src/share/vm/classfile/verifier.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/verifier.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -125,8 +125,8 @@
   st->print_cr("End class verification for: %s", klassName);
 }
 
-bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
-  HandleMark hm;
+bool Verifier::verify(InstanceKlass* klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
+  HandleMark hm(THREAD);
   ResourceMark rm(THREAD);
 
   // Eagerly allocate the identity hash code for a klass. This is a fallout
@@ -203,13 +203,13 @@
     return true; // verifcation succeeded
   } else { // VerifyError or ClassFormatError to be created and thrown
     ResourceMark rm(THREAD);
-    instanceKlassHandle kls =
+    Klass* kls =
       SystemDictionary::resolve_or_fail(exception_name, true, CHECK_false);
     if (log_is_enabled(Debug, class, resolve)) {
-      Verifier::trace_class_resolution(kls(), klass());
+      Verifier::trace_class_resolution(kls, klass);
     }
 
-    while (!kls.is_null()) {
+    while (kls != NULL) {
       if (kls == klass) {
         // If the class being verified is the exception we're creating
         // or one of it's superclasses, we're in trouble and are going
@@ -224,7 +224,7 @@
   }
 }
 
-bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class) {
+bool Verifier::is_eligible_for_verification(InstanceKlass* klass, bool should_verify_class) {
   Symbol* name = klass->name();
   Klass* refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass();
 
@@ -243,7 +243,7 @@
     // already been rewritten to contain constant pool cache indices,
     // which the verifier can't understand.
     // Shared classes shouldn't have stackmaps either.
-    !klass()->is_shared() &&
+    !klass->is_shared() &&
 
     // As of the fix for 4486457 we disable verification for all of the
     // dynamically-generated bytecodes associated with the 1.4
@@ -256,7 +256,7 @@
 }
 
 Symbol* Verifier::inference_verify(
-    instanceKlassHandle klass, char* message, size_t message_len, TRAPS) {
+    InstanceKlass* klass, char* message, size_t message_len, TRAPS) {
   JavaThread* thread = (JavaThread*)THREAD;
   JNIEnv *env = thread->jni_environment();
 
@@ -559,7 +559,7 @@
 // Methods in ClassVerifier
 
 ClassVerifier::ClassVerifier(
-    instanceKlassHandle klass, TRAPS)
+    InstanceKlass* klass, TRAPS)
     : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
   _this_type = VerificationType::reference_type(klass->name());
   // Create list to hold symbols in reference area.
@@ -1991,6 +1991,7 @@
 }
 
 Klass* ClassVerifier::load_class(Symbol* name, TRAPS) {
+  HandleMark hm(THREAD);
   // Get current loader and protection domain first.
   oop loader = current_class()->class_loader();
   oop protection_domain = current_class()->protection_domain();
@@ -2000,13 +2001,13 @@
     true, THREAD);
 
   if (log_is_enabled(Debug, class, resolve)) {
-    instanceKlassHandle cur_class = current_class();
-    Verifier::trace_class_resolution(kls, cur_class());
+    InstanceKlass* cur_class = InstanceKlass::cast(current_class());
+    Verifier::trace_class_resolution(kls, cur_class);
   }
   return kls;
 }
 
-bool ClassVerifier::is_protected_access(instanceKlassHandle this_class,
+bool ClassVerifier::is_protected_access(InstanceKlass* this_class,
                                         Klass* target_class,
                                         Symbol* field_name,
                                         Symbol* field_sig,
@@ -2169,7 +2170,7 @@
 }
 
 bool ClassVerifier::name_in_supers(
-    Symbol* ref_name, instanceKlassHandle current) {
+    Symbol* ref_name, InstanceKlass* current) {
   Klass* super = current->super();
   while (super != NULL) {
     if (super->name() == ref_name) {
@@ -2599,8 +2600,8 @@
         Klass::find_overpass);
       // Do nothing if method is not found.  Let resolution detect the error.
       if (m != NULL) {
-        instanceKlassHandle mh(THREAD, m->method_holder());
-        if (m->is_protected() && !mh->is_same_class_package(_klass())) {
+        InstanceKlass* mh = m->method_holder();
+        if (m->is_protected() && !mh->is_same_class_package(_klass)) {
           bool assignable = current_type().is_assignable_from(
             objectref_type, this, true, CHECK_VERIFY(this));
           if (!assignable) {
@@ -2630,7 +2631,7 @@
 }
 
 bool ClassVerifier::is_same_or_direct_interface(
-    instanceKlassHandle klass,
+    InstanceKlass* klass,
     VerificationType klass_type,
     VerificationType ref_class_type) {
   if (ref_class_type.equals(klass_type)) return true;
--- a/hotspot/src/share/vm/classfile/verifier.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/classfile/verifier.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -51,7 +51,7 @@
    * error.
    */
   static void log_end_verification(outputStream* st, const char* klassName, Symbol* exception_name, TRAPS);
-  static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
+  static bool verify(InstanceKlass* klass, Mode mode, bool should_verify_class, TRAPS);
 
   // Return false if the class is loaded by the bootstrap loader,
   // or if defineClass was called requesting skipping verification
@@ -65,9 +65,9 @@
   static void trace_class_resolution(Klass* resolve_class, InstanceKlass* verify_class);
 
  private:
-  static bool is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class);
+  static bool is_eligible_for_verification(InstanceKlass* klass, bool should_verify_class);
   static Symbol* inference_verify(
-    instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS);
+    InstanceKlass* klass, char* msg, size_t msg_len, TRAPS);
 };
 
 class RawBytecodeStream;
@@ -275,7 +275,7 @@
   }
 
   bool is_protected_access(
-    instanceKlassHandle this_class, Klass* target_class,
+    InstanceKlass* this_class, Klass* target_class,
     Symbol* field_name, Symbol* field_sig, bool is_method);
 
   void verify_cp_index(u2 bci, const constantPoolHandle& cp, int index, TRAPS);
@@ -344,11 +344,11 @@
   void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS);
   void verify_iinc  (u2 index, StackMapFrame* current_frame, TRAPS);
 
-  bool name_in_supers(Symbol* ref_name, instanceKlassHandle current);
+  bool name_in_supers(Symbol* ref_name, InstanceKlass* current);
 
   VerificationType object_type() const;
 
-  instanceKlassHandle _klass;  // the class being verified
+  InstanceKlass*      _klass;  // the class being verified
   methodHandle        _method; // current method being verified
   VerificationType    _this_type; // the verification type of the current class
 
@@ -362,7 +362,7 @@
   // that a class has been verified and prepared for execution.
   bool was_recursively_verified() { return _klass->is_rewritten(); }
 
-  bool is_same_or_direct_interface(instanceKlassHandle klass,
+  bool is_same_or_direct_interface(InstanceKlass* klass,
     VerificationType klass_type, VerificationType ref_class_type);
 
  public:
@@ -372,14 +372,14 @@
   };
 
   // constructor
-  ClassVerifier(instanceKlassHandle klass, TRAPS);
+  ClassVerifier(InstanceKlass* klass, TRAPS);
 
   // destructor
   ~ClassVerifier();
 
   Thread* thread()             { return _thread; }
   const methodHandle& method() { return _method; }
-  instanceKlassHandle current_class() const { return _klass; }
+  InstanceKlass* current_class() const { return _klass; }
   VerificationType current_type() const { return _this_type; }
 
   // Verifies the class.  If a verify or class file format error occurs,
--- a/hotspot/src/share/vm/code/codeBlob.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/code/codeBlob.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -209,7 +209,6 @@
 }
 
 void CodeBlob::print_code() {
-  HandleMark hm;
   ResourceMark m;
   Disassembler::decode(this, tty);
 }
--- a/hotspot/src/share/vm/code/codeCache.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/code/codeCache.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1141,7 +1141,7 @@
 }
 
 #ifdef HOTSWAP
-int CodeCache::mark_for_evol_deoptimization(instanceKlassHandle dependee) {
+int CodeCache::mark_for_evol_deoptimization(InstanceKlass* dependee) {
   MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   int number_of_marked_CodeBlobs = 0;
 
@@ -1162,7 +1162,7 @@
     CompiledMethod* nm = iter.method();
     if (nm->is_marked_for_deoptimization()) {
       // ...Already marked in the previous pass; don't count it again.
-    } else if (nm->is_evol_dependent_on(dependee())) {
+    } else if (nm->is_evol_dependent_on(dependee)) {
       ResourceMark rm;
       nm->mark_for_deoptimization();
       number_of_marked_CodeBlobs++;
@@ -1218,7 +1218,7 @@
 }
 
 // Flushes compiled methods dependent on dependee.
-void CodeCache::flush_dependents_on(instanceKlassHandle dependee) {
+void CodeCache::flush_dependents_on(InstanceKlass* dependee) {
   assert_lock_strong(Compile_lock);
 
   if (number_of_nmethods_with_dependencies() == 0) return;
@@ -1239,7 +1239,7 @@
 
 #ifdef HOTSWAP
 // Flushes compiled methods dependent on dependee in the evolutionary sense
-void CodeCache::flush_evol_dependents_on(instanceKlassHandle ev_k_h) {
+void CodeCache::flush_evol_dependents_on(InstanceKlass* ev_k) {
   // --- Compile_lock is not held. However we are at a safepoint.
   assert_locked_or_safepoint(Compile_lock);
   if (number_of_nmethods_with_dependencies() == 0 && !UseAOT) return;
@@ -1249,7 +1249,7 @@
   // holding the CodeCache_lock.
 
   // Compute the dependent nmethods
-  if (mark_for_evol_deoptimization(ev_k_h) > 0) {
+  if (mark_for_evol_deoptimization(ev_k) > 0) {
     // At least one nmethod has been marked for deoptimization
 
     // All this already happens inside a VM_Operation, so we'll do all the work here.
@@ -1310,6 +1310,8 @@
 }
 
 // A CodeHeap is full. Print out warning and report event.
+PRAGMA_DIAG_PUSH
+PRAGMA_FORMAT_NONLITERAL_IGNORED
 void CodeCache::report_codemem_full(int code_blob_type, bool print) {
   // Get nmethod heap for the given CodeBlobType and build CodeCacheFull event
   CodeHeap* heap = get_code_heap(code_blob_type);
@@ -1318,11 +1320,27 @@
   if ((heap->full_count() == 0) || print) {
     // Not yet reported for this heap, report
     if (SegmentedCodeCache) {
-      warning("%s is full. Compiler has been disabled.", get_code_heap_name(code_blob_type));
-      warning("Try increasing the code heap size using -XX:%s=", get_code_heap_flag_name(code_blob_type));
+      ResourceMark rm;
+      stringStream msg1_stream, msg2_stream;
+      msg1_stream.print("%s is full. Compiler has been disabled.",
+                        get_code_heap_name(code_blob_type));
+      msg2_stream.print("Try increasing the code heap size using -XX:%s=",
+                 get_code_heap_flag_name(code_blob_type));
+      const char *msg1 = msg1_stream.as_string();
+      const char *msg2 = msg2_stream.as_string();
+
+      log_warning(codecache)(msg1);
+      log_warning(codecache)(msg2);
+      warning(msg1);
+      warning(msg2);
     } else {
-      warning("CodeCache is full. Compiler has been disabled.");
-      warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
+      const char *msg1 = "CodeCache is full. Compiler has been disabled.";
+      const char *msg2 = "Try increasing the code cache size using -XX:ReservedCodeCacheSize=";
+
+      log_warning(codecache)(msg1);
+      log_warning(codecache)(msg2);
+      warning(msg1);
+      warning(msg2);
     }
     ResourceMark rm;
     stringStream s;
@@ -1351,6 +1369,7 @@
     event.commit();
   }
 }
+PRAGMA_DIAG_POP
 
 void CodeCache::print_memory_overhead() {
   size_t wasted_bytes = 0;
--- a/hotspot/src/share/vm/code/codeCache.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/code/codeCache.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -260,7 +260,7 @@
  private:
   static int  mark_for_deoptimization(KlassDepChange& changes);
 #ifdef HOTSWAP
-  static int  mark_for_evol_deoptimization(instanceKlassHandle dependee);
+  static int  mark_for_evol_deoptimization(InstanceKlass* dependee);
 #endif // HOTSWAP
 
  public:
@@ -269,10 +269,10 @@
   static void make_marked_nmethods_not_entrant();
 
   // Flushing and deoptimization
-  static void flush_dependents_on(instanceKlassHandle dependee);
+  static void flush_dependents_on(InstanceKlass* dependee);
 #ifdef HOTSWAP
   // Flushing and deoptimization in case of evolution
-  static void flush_evol_dependents_on(instanceKlassHandle dependee);
+  static void flush_evol_dependents_on(InstanceKlass* dependee);
 #endif // HOTSWAP
   // Support for fullspeed debugging
   static void flush_dependents_on_method(methodHandle dependee);
--- a/hotspot/src/share/vm/code/compiledIC.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/code/compiledIC.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -457,7 +457,7 @@
 // null check, while a static_bound won't. A static_bound (but not optimized) must
 // therefore use the unverified entry point.
 void CompiledIC::compute_monomorphic_entry(const methodHandle& method,
-                                           KlassHandle receiver_klass,
+                                           Klass* receiver_klass,
                                            bool is_optimized,
                                            bool static_bound,
                                            bool caller_is_nmethod,
@@ -494,7 +494,7 @@
   bool far_c2a = entry != NULL && caller_is_nmethod && method_code->is_far_code();
   if (entry != NULL && !far_c2a) {
     // Call to near compiled code (nmethod or aot).
-    info.set_compiled_entry(entry, (static_bound || is_optimized) ? NULL : receiver_klass(), is_optimized);
+    info.set_compiled_entry(entry, (static_bound || is_optimized) ? NULL : receiver_klass, is_optimized);
   } else {
     if (is_optimized) {
       if (far_c2a) {
@@ -507,7 +507,7 @@
     } else {
       // Use icholder entry
       assert(method_code == NULL || method_code->is_compiled(), "must be compiled");
-      CompiledICHolder* holder = new CompiledICHolder(method(), receiver_klass());
+      CompiledICHolder* holder = new CompiledICHolder(method(), receiver_klass);
       info.set_icholder_entry(method()->get_c2i_unverified_entry(), holder);
     }
   }
--- a/hotspot/src/share/vm/code/compiledIC.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/code/compiledIC.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -266,7 +266,7 @@
   // allocation in the code cache fails.
   bool set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS);
 
-  static void compute_monomorphic_entry(const methodHandle& method, KlassHandle receiver_klass,
+  static void compute_monomorphic_entry(const methodHandle& method, Klass* receiver_klass,
                                         bool is_optimized, bool static_bound, bool caller_is_nmethod,
                                         CompiledICInfo& info, TRAPS);
 
--- a/hotspot/src/share/vm/code/debugInfo.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/code/debugInfo.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -224,7 +224,7 @@
 // ConstantOopReadValue
 
 ConstantOopReadValue::ConstantOopReadValue(DebugInfoReadStream* stream) {
-  _value = Handle(stream->read_oop());
+  _value = Handle(Thread::current(), stream->read_oop());
   assert(_value() == NULL ||
          Universe::heap()->is_in_reserved(_value()), "Should be in heap");
 }
--- a/hotspot/src/share/vm/code/debugInfo.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/code/debugInfo.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,7 @@
 #include "code/nmethod.hpp"
 #include "code/oopRecorder.hpp"
 #include "runtime/stackValue.hpp"
+#include "runtime/thread.hpp"
 #include "utilities/growableArray.hpp"
 
 // Classes used for serializing debugging information.
@@ -127,7 +128,7 @@
   Handle                      value() const             { return _value; }
   bool                        is_visited() const        { return _visited; }
 
-  void                        set_value(oop value)      { _value = Handle(value); }
+  void                        set_value(oop value)      { _value = Handle(Thread::current(), value); }
   void                        set_visited(bool visited) { _visited = false; }
 
   // Serialization of debugging information
--- a/hotspot/src/share/vm/code/dependencies.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/code/dependencies.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -714,7 +714,8 @@
   if (xtty == NULL) {
     return;
   }
-  ResourceMark rm;
+  Thread* thread = Thread::current();
+  HandleMark rm(thread);
   ttyLocker ttyl;
   int ctxkj = dep_context_arg(dept);  // -1 if no context arg
   if (witness != NULL) {
@@ -732,14 +733,14 @@
     DepArgument arg = args->at(j);
     if (j == 1) {
       if (arg.is_oop()) {
-        xtty->object("x", arg.oop_value());
+        xtty->object("x", Handle(thread, arg.oop_value()));
       } else {
         xtty->object("x", arg.metadata_value());
       }
     } else {
       char xn[10]; sprintf(xn, "x%d", j);
       if (arg.is_oop()) {
-        xtty->object(xn, arg.oop_value());
+        xtty->object(xn, Handle(thread, arg.oop_value()));
       } else {
         xtty->object(xn, arg.metadata_value());
       }
--- a/hotspot/src/share/vm/code/dependencies.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/code/dependencies.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -737,13 +737,13 @@
 class KlassDepChange : public DepChange {
  private:
   // each change set is rooted in exactly one new type (at present):
-  KlassHandle _new_type;
+  Klass* _new_type;
 
   void initialize();
 
  public:
   // notes the new type, marks it and all its super-types
-  KlassDepChange(KlassHandle new_type)
+  KlassDepChange(Klass* new_type)
     : _new_type(new_type)
   {
     initialize();
@@ -759,7 +759,7 @@
     nm->mark_for_deoptimization(/*inc_recompile_counts=*/true);
   }
 
-  Klass* new_type() { return _new_type(); }
+  Klass* new_type() { return _new_type; }
 
   // involves_context(k) is true if k is new_type or any of the super types
   bool involves_context(Klass* k);
--- a/hotspot/src/share/vm/code/nmethod.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/code/nmethod.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1134,8 +1134,11 @@
       xtty->end_elem();
     }
   }
+
+  const char *state_msg = _state == zombie ? "made zombie" : "made not entrant";
+  CompileTask::print_ul(this, state_msg);
   if (PrintCompilation && _state != unloaded) {
-    print_on(tty, _state == zombie ? "made zombie" : "made not entrant");
+    print_on(tty, state_msg);
   }
 }
 
--- a/hotspot/src/share/vm/compiler/compileBroker.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/compiler/compileBroker.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -683,7 +683,7 @@
                                        AbstractCompiler* comp, bool compiler_thread, TRAPS) {
   JavaThread* thread = NULL;
   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK_0);
-  instanceKlassHandle klass (THREAD, k);
+  InstanceKlass* klass = InstanceKlass::cast(k);
   instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_0);
   Handle string = java_lang_String::create_from_str(name, CHECK_0);
 
@@ -1765,6 +1765,7 @@
 // Compile a method.
 //
 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
+  task->print_ul();
   if (PrintCompilation) {
     ResourceMark rm;
     task->print_tty();
--- a/hotspot/src/share/vm/compiler/compileTask.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/compiler/compileTask.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -86,9 +86,10 @@
                              bool is_blocking) {
   assert(!_lock->is_locked(), "bad locking");
 
+  Thread* thread = Thread::current();
   _compile_id = compile_id;
   _method = method();
-  _method_holder = JNIHandles::make_global(method->method_holder()->klass_holder());
+  _method_holder = JNIHandles::make_global(Handle(thread, method->method_holder()->klass_holder()));
   _osr_bci = osr_bci;
   _is_blocking = is_blocking;
   JVMCI_ONLY(_has_waiter = CompileBroker::compiler(comp_level)->is_jvmci();)
@@ -115,7 +116,7 @@
       } else {
         _hot_method = hot_method();
         // only add loader or mirror if different from _method_holder
-        _hot_method_holder = JNIHandles::make_global(hot_method->method_holder()->klass_holder());
+        _hot_method_holder = JNIHandles::make_global(Handle(thread, hot_method->method_holder()->klass_holder()));
       }
     }
   }
--- a/hotspot/src/share/vm/compiler/compileTask.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/compiler/compileTask.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -180,11 +180,27 @@
 
 public:
   void         print(outputStream* st = tty, const char* msg = NULL, bool short_form = false, bool cr = true);
+  void         print_ul(const char* msg = NULL){
+    Log(jit, compilation) log;
+    if (log.is_debug()) {
+      print(log.debug_stream(), msg, /* short form */ true, /* cr */ true);
+    }
+  }
   static void  print(outputStream* st, const nmethod* nm, const char* msg = NULL, bool short_form = false, bool cr = true) {
     print_impl(st, nm->method(), nm->compile_id(), nm->comp_level(),
                            nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false,
                            msg, short_form, cr);
   }
+  static void  print_ul(const nmethod* nm, const char* msg = NULL) {
+    Log(jit, compilation) log;
+    if (log.is_debug()) {
+      print_impl(log.debug_stream(), nm->method(), nm->compile_id(),
+                 nm->comp_level(), nm->is_osr_method(),
+                 nm->is_osr_method() ? nm->osr_entry_bci() : -1,
+                 /*is_blocking*/ false,
+                 msg, /* short form */ true, /* cr */ true);
+    }
+  }
 
   static void  print_inline_indent(int inline_level, outputStream* st = tty);
 
@@ -206,6 +222,12 @@
   static void print_inlining_tty(ciMethod* method, int inline_level, int bci, const char* msg = NULL) {
     print_inlining_inner(tty, method, inline_level, bci, msg);
   }
+  static void print_inlining_ul(ciMethod* method, int inline_level, int bci, const char* msg = NULL) {
+    Log(jit, inlining) log;
+    if (log.is_debug()) {
+      print_inlining_inner(log.debug_stream(), method, inline_level, bci, msg);
+    }
+  }
 };
 
 #endif // SHARE_VM_COMPILER_COMPILETASK_HPP
--- a/hotspot/src/share/vm/gc/g1/dirtyCardQueue.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/dirtyCardQueue.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -301,9 +301,7 @@
 
 void DirtyCardQueueSet::concatenate_log(DirtyCardQueue& dcq) {
   if (!dcq.is_empty()) {
-    enqueue_complete_buffer(
-      BufferNode::make_node_from_buffer(dcq.get_buf(), dcq.get_index()));
-    dcq.reinitialize();
+    dcq.flush();
   }
 }
 
--- a/hotspot/src/share/vm/gc/g1/dirtyCardQueue.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/dirtyCardQueue.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -52,10 +52,6 @@
   // Process queue entries and release resources.
   void flush() { flush_impl(); }
 
-  void **get_buf() { return _buf;}
-  size_t get_index() { return _index;}
-  void reinitialize() { _buf = 0; _sz = 0; _index = 0;}
-
   // Compiler support.
   static ByteSize byte_offset_of_index() {
     return PtrQueue::byte_offset_of_index<DirtyCardQueue>();
--- a/hotspot/src/share/vm/gc/g1/g1Allocator.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1Allocator.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,6 @@
 #include "gc/g1/g1AllocRegion.inline.hpp"
 #include "gc/g1/g1EvacStats.inline.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
-#include "gc/g1/g1MarkSweep.hpp"
 #include "gc/g1/heapRegion.inline.hpp"
 #include "gc/g1/heapRegionSet.inline.hpp"
 
@@ -333,11 +332,14 @@
   }
 }
 
+bool G1ArchiveAllocator::_archive_check_enabled = false;
+G1ArchiveRegionMap G1ArchiveAllocator::_archive_region_map;
+
 G1ArchiveAllocator* G1ArchiveAllocator::create_allocator(G1CollectedHeap* g1h) {
   // Create the archive allocator, and also enable archive object checking
   // in mark-sweep, since we will be creating archive regions.
   G1ArchiveAllocator* result =  new G1ArchiveAllocator(g1h);
-  G1MarkSweep::enable_archive_object_check();
+  enable_archive_object_check();
   return result;
 }
 
@@ -362,7 +364,7 @@
   _max = _bottom + HeapRegion::min_region_size_in_words();
 
   // Tell mark-sweep that objects in this region are not to be marked.
-  G1MarkSweep::set_range_archive(MemRegion(_bottom, HeapRegion::GrainWords), true);
+  set_range_archive(MemRegion(_bottom, HeapRegion::GrainWords), true);
 
   // Since we've modified the old set, call update_sizes.
   _g1h->g1mm()->update_sizes();
--- a/hotspot/src/share/vm/gc/g1/g1Allocator.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1Allocator.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -312,12 +312,19 @@
   virtual void waste(size_t& wasted, size_t& undo_wasted);
 };
 
+// G1ArchiveRegionMap is a boolean array used to mark G1 regions as
+// archive regions.  This allows a quick check for whether an object
+// should not be marked because it is in an archive region.
+class G1ArchiveRegionMap : public G1BiasedMappedArray<bool> {
+protected:
+  bool default_value() const { return false; }
+};
+
 // G1ArchiveAllocator is used to allocate memory in archive
 // regions. Such regions are not modifiable by GC, being neither
 // scavenged nor compacted, or even marked in the object header.
 // They can contain no pointers to non-archive heap regions,
 class G1ArchiveAllocator : public CHeapObj<mtGC> {
-
 protected:
   G1CollectedHeap* _g1h;
 
@@ -378,6 +385,24 @@
     _summary_bytes_used = 0;
   }
 
+  // Create the _archive_region_map which is used to identify archive objects.
+  static inline void enable_archive_object_check();
+
+  // Set the regions containing the specified address range as archive/non-archive.
+  static inline void set_range_archive(MemRegion range, bool is_archive);
+
+  static inline bool is_archive_object(oop object);
+
+private:
+  static bool _archive_check_enabled;
+  static G1ArchiveRegionMap  _archive_region_map;
+
+  // Check if an object is in an archive region using the _archive_region_map.
+  static inline bool in_archive_range(oop object);
+
+  // Check if archive object checking is enabled, to avoid calling in_archive_range
+  // unnecessarily.
+  static inline bool archive_check_enabled();
 };
 
 #endif // SHARE_VM_GC_G1_G1ALLOCATOR_HPP
--- a/hotspot/src/share/vm/gc/g1/g1Allocator.inline.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1Allocator.inline.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -55,4 +55,37 @@
   }
 }
 
+// Create the _archive_region_map which is used to identify archive objects.
+inline void G1ArchiveAllocator::enable_archive_object_check() {
+  assert(!_archive_check_enabled, "archive range check already enabled");
+  _archive_check_enabled = true;
+  size_t length = Universe::heap()->max_capacity();
+  _archive_region_map.initialize((HeapWord*)Universe::heap()->base(),
+                                 (HeapWord*)Universe::heap()->base() + length,
+                                 HeapRegion::GrainBytes);
+}
+
+// Set the regions containing the specified address range as archive/non-archive.
+inline void G1ArchiveAllocator::set_range_archive(MemRegion range, bool is_archive) {
+  assert(_archive_check_enabled, "archive range check not enabled");
+  _archive_region_map.set_by_address(range, is_archive);
+}
+
+// Check if an object is in an archive region using the _archive_region_map.
+inline bool G1ArchiveAllocator::in_archive_range(oop object) {
+  // This is the out-of-line part of is_archive_object test, done separately
+  // to avoid additional performance impact when the check is not enabled.
+  return _archive_region_map.get_by_address((HeapWord*)object);
+}
+
+// Check if archive object checking is enabled, to avoid calling in_archive_range
+// unnecessarily.
+inline bool G1ArchiveAllocator::archive_check_enabled() {
+  return _archive_check_enabled;
+}
+
+inline bool G1ArchiveAllocator::is_archive_object(oop object) {
+  return (archive_check_enabled() && in_archive_range(object));
+}
+
 #endif // SHARE_VM_GC_G1_G1ALLOCATOR_HPP
--- a/hotspot/src/share/vm/gc/g1/g1BlockOffsetTable.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1BlockOffsetTable.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -79,7 +79,9 @@
   _space(gsp),
   _next_offset_threshold(NULL),
   _next_offset_index(0)
-{ }
+{
+  debug_only(_object_can_span = false;)
+}
 
 // The arguments follow the normal convention of denoting
 // a right-open interval: [start, end)
@@ -364,6 +366,12 @@
   }
 }
 
+#ifdef ASSERT
+void G1BlockOffsetTablePart::set_object_can_span(bool can_span) {
+  _object_can_span = can_span;
+}
+#endif
+
 #ifndef PRODUCT
 void
 G1BlockOffsetTablePart::print_on(outputStream* out) {
--- a/hotspot/src/share/vm/gc/g1/g1BlockOffsetTable.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1BlockOffsetTable.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -117,6 +117,9 @@
   HeapWord* _next_offset_threshold;
   size_t    _next_offset_index;      // index corresponding to that boundary
 
+  // Indicates if an object can span into this G1BlockOffsetTablePart.
+  debug_only(bool _object_can_span;)
+
   // This is the global BlockOffsetTable.
   G1BlockOffsetTable* _bot;
 
@@ -224,6 +227,7 @@
   }
 
   void set_for_starts_humongous(HeapWord* obj_top, size_t fill_size);
+  void set_object_can_span(bool can_span) NOT_DEBUG_RETURN;
 
   void print_on(outputStream* out) PRODUCT_RETURN;
 };
--- a/hotspot/src/share/vm/gc/g1/g1BlockOffsetTable.inline.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1BlockOffsetTable.inline.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -107,7 +107,9 @@
 inline HeapWord* G1BlockOffsetTablePart::block_at_or_preceding(const void* addr,
                                                                bool has_max_index,
                                                                size_t max_index) const {
-  assert(_bot->offset_array(0) == 0, "objects can't cross covered areas");
+  assert(_object_can_span || _bot->offset_array(_bot->index_for(_space->bottom())) == 0,
+         "Object crossed region boundary, found offset %u instead of 0",
+         (uint) _bot->offset_array(_bot->index_for(_space->bottom())));
   size_t index = _bot->index_for(addr);
   // We must make sure that the offset table entry we use is valid.  If
   // "addr" is past the end, start at the last known one and go forward.
--- a/hotspot/src/share/vm/gc/g1/g1CodeBlobClosure.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CodeBlobClosure.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
   if (!oopDesc::is_null(oop_or_narrowoop)) {
     oop o = oopDesc::decode_heap_oop_not_null(oop_or_narrowoop);
     HeapRegion* hr = _g1h->heap_region_containing(o);
-    assert(!_g1h->obj_in_cs(o) || hr->rem_set()->strong_code_roots_list_contains(_nm), "if o still in collection set then evacuation failed and nm must already be in the remset");
+    assert(!_g1h->is_in_cset(o) || hr->rem_set()->strong_code_roots_list_contains(_nm), "if o still in collection set then evacuation failed and nm must already be in the remset");
     hr->add_strong_code_root(_nm);
   }
 }
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -699,9 +699,9 @@
   // when mmap'ing archived heap data in, so pre-touching is wasted.
   FlagSetting fs(AlwaysPreTouch, false);
 
-  // Enable archive object checking in G1MarkSweep. We have to let it know
+  // Enable archive object checking used by G1MarkSweep. We have to let it know
   // about each archive range, so that objects in those ranges aren't marked.
-  G1MarkSweep::enable_archive_object_check();
+  G1ArchiveAllocator::enable_archive_object_check();
 
   // For each specified MemRegion range, allocate the corresponding G1
   // regions and mark them as archive regions. We expect the ranges in
@@ -773,7 +773,7 @@
     }
 
     // Notify mark-sweep of the archive range.
-    G1MarkSweep::set_range_archive(curr_range, true);
+    G1ArchiveAllocator::set_range_archive(curr_range, true);
   }
   return true;
 }
@@ -924,7 +924,7 @@
     }
 
     // Notify mark-sweep that this is no longer an archive range.
-    G1MarkSweep::set_range_archive(ranges[i], false);
+    G1ArchiveAllocator::set_range_archive(ranges[i], false);
   }
 
   if (uncommitted_regions != 0) {
@@ -1378,10 +1378,9 @@
       }
       _verifier->check_bitmaps("Full GC End");
 
-      // Start a new incremental collection set for the next pause
-      collection_set()->start_incremental_building();
-
-      clear_cset_fast_test();
+      double start = os::elapsedTime();
+      start_new_collection_set();
+      g1_policy()->phase_times()->record_start_new_cset_time_ms((os::elapsedTime() - start) * 1000.0);
 
       _allocator->init_mutator_alloc_region();
 
@@ -2364,11 +2363,6 @@
 }
 #endif
 
-bool G1CollectedHeap::obj_in_cs(oop obj) {
-  HeapRegion* r = _hrm.addr_to_region((HeapWord*) obj);
-  return r != NULL && r->in_collection_set();
-}
-
 // Iteration functions.
 
 // Applies an ExtendedOopClosure onto all references of objects within a HeapRegion.
@@ -2699,9 +2693,12 @@
 void G1CollectedHeap::gc_prologue(bool full /* Ignored */) {
   // always_do_update_barrier = false;
   assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer");
+
+  double start = os::elapsedTime();
   // Fill TLAB's and such
   accumulate_statistics_all_tlabs();
   ensure_parsability(true);
+  g1_policy()->phase_times()->record_prepare_tlab_time_ms((os::elapsedTime() - start) * 1000.0);
 
   g1_rem_set()->print_periodic_summary_info("Before GC RS summary", total_collections());
 }
@@ -2718,7 +2715,10 @@
 #endif
   // always_do_update_barrier = true;
 
+  double start = os::elapsedTime();
   resize_all_tlabs();
+  g1_policy()->phase_times()->record_resize_tlab_time_ms((os::elapsedTime() - start) * 1000.0);
+
   allocation_context_stats().update(full);
 
   // We have just completed a GC. Update the soft reference
@@ -3001,6 +3001,15 @@
   }
 };
 
+void G1CollectedHeap::start_new_collection_set() {
+  collection_set()->start_incremental_building();
+
+  clear_cset_fast_test();
+
+  guarantee(_eden.length() == 0, "eden should have been cleared");
+  g1_policy()->transfer_survivors_to_cset(survivor());
+}
+
 bool
 G1CollectedHeap::do_collection_pause_at_safepoint(double target_pause_time_ms) {
   assert_at_safepoint(true /* should_be_vm_thread */);
@@ -3203,13 +3212,7 @@
         _survivor_evac_stats.adjust_desired_plab_sz();
         _old_evac_stats.adjust_desired_plab_sz();
 
-        // Start a new incremental collection set for the next pause.
-        collection_set()->start_incremental_building();
-
-        clear_cset_fast_test();
-
-        guarantee(_eden.length() == 0, "eden should have been cleared");
-        g1_policy()->transfer_survivors_to_cset(survivor());
+        start_new_collection_set();
 
         if (evacuation_failed()) {
           set_used(recalculate_used());
@@ -4527,7 +4530,9 @@
 
   redirty_logged_cards();
 #if defined(COMPILER2) || INCLUDE_JVMCI
+  double start = os::elapsedTime();
   DerivedPointerTable::update_pointers();
+  g1_policy()->phase_times()->record_derived_pointer_table_update_time((os::elapsedTime() - start) * 1000.0);
 #endif
   g1_policy()->print_age_table();
 }
@@ -5274,8 +5279,6 @@
 HeapRegion* G1CollectedHeap::new_mutator_alloc_region(size_t word_size,
                                                       bool force) {
   assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);
-  assert(!force || g1_policy()->can_expand_young_list(),
-         "if force is true we should be able to expand the young list");
   bool should_allocate = g1_policy()->should_allocate_mutator_region();
   if (force || should_allocate) {
     HeapRegion* new_alloc_region = new_region(word_size,
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -159,6 +159,8 @@
   HeapRegionSet _humongous_set;
 
   void eagerly_reclaim_humongous_regions();
+  // Start a new incremental collection set for the next pause.
+  void start_new_collection_set();
 
   // The number of regions we could create by expansion.
   uint _expansion_regions;
@@ -1129,9 +1131,7 @@
 #endif
 
   // Return "TRUE" iff the given object address is within the collection
-  // set. Slow implementation.
-  bool obj_in_cs(oop obj);
-
+  // set. Assumes that the reference points into the heap.
   inline bool is_in_cset(const HeapRegion *hr);
   inline bool is_in_cset(oop obj);
 
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.inline.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.inline.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -142,16 +142,8 @@
   return _cm->nextMarkBitMap()->isMarked((HeapWord *)obj);
 }
 
-// This is a fast test on whether a reference points into the
-// collection set or not. Assume that the reference
-// points into the heap.
 inline bool G1CollectedHeap::is_in_cset(oop obj) {
-  bool ret = _in_cset_fast_test.is_in_cset((HeapWord*)obj);
-  // let's make sure the result is consistent with what the slower
-  // test returns
-  assert( ret || !obj_in_cs(obj), "sanity");
-  assert(!ret ||  obj_in_cs(obj), "sanity");
-  return ret;
+  return _in_cset_fast_test.is_in_cset((HeapWord*)obj);
 }
 
 bool G1CollectedHeap::is_in_cset(const HeapRegion* hr) {
--- a/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -136,7 +136,6 @@
   _max_chunk_capacity(0),
   _base(NULL),
   _chunk_capacity(0),
-  _out_of_memory(false),
   _should_expand(false) {
   set_empty();
 }
@@ -146,15 +145,15 @@
   assert(new_capacity <= _max_chunk_capacity,
          "Trying to resize stack to " SIZE_FORMAT " chunks when the maximum is " SIZE_FORMAT, new_capacity, _max_chunk_capacity);
 
-  OopChunk* new_base = MmapArrayAllocator<OopChunk, mtGC>::allocate_or_null(new_capacity);
+  TaskQueueEntryChunk* new_base = MmapArrayAllocator<TaskQueueEntryChunk, mtGC>::allocate_or_null(new_capacity);
 
   if (new_base == NULL) {
-    log_warning(gc)("Failed to reserve memory for new overflow mark stack with " SIZE_FORMAT " chunks and size " SIZE_FORMAT "B.", new_capacity, new_capacity * sizeof(OopChunk));
+    log_warning(gc)("Failed to reserve memory for new overflow mark stack with " SIZE_FORMAT " chunks and size " SIZE_FORMAT "B.", new_capacity, new_capacity * sizeof(TaskQueueEntryChunk));
     return false;
   }
   // Release old mapping.
   if (_base != NULL) {
-    MmapArrayAllocator<OopChunk, mtGC>::free(_base, _chunk_capacity);
+    MmapArrayAllocator<TaskQueueEntryChunk, mtGC>::free(_base, _chunk_capacity);
   }
 
   _base = new_base;
@@ -166,16 +165,16 @@
 }
 
 size_t G1CMMarkStack::capacity_alignment() {
-  return (size_t)lcm(os::vm_allocation_granularity(), sizeof(OopChunk)) / sizeof(void*);
+  return (size_t)lcm(os::vm_allocation_granularity(), sizeof(TaskQueueEntryChunk)) / sizeof(G1TaskQueueEntry);
 }
 
 bool G1CMMarkStack::initialize(size_t initial_capacity, size_t max_capacity) {
   guarantee(_max_chunk_capacity == 0, "G1CMMarkStack already initialized.");
 
-  size_t const OopChunkSizeInVoidStar = sizeof(OopChunk) / sizeof(void*);
-
-  _max_chunk_capacity = (size_t)align_size_up(max_capacity, capacity_alignment()) / OopChunkSizeInVoidStar;
-  size_t initial_chunk_capacity = (size_t)align_size_up(initial_capacity, capacity_alignment()) / OopChunkSizeInVoidStar;
+  size_t const TaskEntryChunkSizeInVoidStar = sizeof(TaskQueueEntryChunk) / sizeof(G1TaskQueueEntry);
+
+  _max_chunk_capacity = (size_t)align_size_up(max_capacity, capacity_alignment()) / TaskEntryChunkSizeInVoidStar;
+  size_t initial_chunk_capacity = (size_t)align_size_up(initial_capacity, capacity_alignment()) / TaskEntryChunkSizeInVoidStar;
 
   guarantee(initial_chunk_capacity <= _max_chunk_capacity,
             "Maximum chunk capacity " SIZE_FORMAT " smaller than initial capacity " SIZE_FORMAT,
@@ -211,49 +210,49 @@
 
 G1CMMarkStack::~G1CMMarkStack() {
   if (_base != NULL) {
-    MmapArrayAllocator<OopChunk, mtGC>::free(_base, _chunk_capacity);
+    MmapArrayAllocator<TaskQueueEntryChunk, mtGC>::free(_base, _chunk_capacity);
   }
 }
 
-void G1CMMarkStack::add_chunk_to_list(OopChunk* volatile* list, OopChunk* elem) {
+void G1CMMarkStack::add_chunk_to_list(TaskQueueEntryChunk* volatile* list, TaskQueueEntryChunk* elem) {
   elem->next = *list;
   *list = elem;
 }
 
-void G1CMMarkStack::add_chunk_to_chunk_list(OopChunk* elem) {
+void G1CMMarkStack::add_chunk_to_chunk_list(TaskQueueEntryChunk* elem) {
   MutexLockerEx x(MarkStackChunkList_lock, Mutex::_no_safepoint_check_flag);
   add_chunk_to_list(&_chunk_list, elem);
   _chunks_in_chunk_list++;
 }
 
-void G1CMMarkStack::add_chunk_to_free_list(OopChunk* elem) {
+void G1CMMarkStack::add_chunk_to_free_list(TaskQueueEntryChunk* elem) {
   MutexLockerEx x(MarkStackFreeList_lock, Mutex::_no_safepoint_check_flag);
   add_chunk_to_list(&_free_list, elem);
 }
 
-G1CMMarkStack::OopChunk* G1CMMarkStack::remove_chunk_from_list(OopChunk* volatile* list) {
-  OopChunk* result = *list;
+G1CMMarkStack::TaskQueueEntryChunk* G1CMMarkStack::remove_chunk_from_list(TaskQueueEntryChunk* volatile* list) {
+  TaskQueueEntryChunk* result = *list;
   if (result != NULL) {
     *list = (*list)->next;
   }
   return result;
 }
 
-G1CMMarkStack::OopChunk* G1CMMarkStack::remove_chunk_from_chunk_list() {
+G1CMMarkStack::TaskQueueEntryChunk* G1CMMarkStack::remove_chunk_from_chunk_list() {
   MutexLockerEx x(MarkStackChunkList_lock, Mutex::_no_safepoint_check_flag);
-  OopChunk* result = remove_chunk_from_list(&_chunk_list);
+  TaskQueueEntryChunk* result = remove_chunk_from_list(&_chunk_list);
   if (result != NULL) {
     _chunks_in_chunk_list--;
   }
   return result;
 }
 
-G1CMMarkStack::OopChunk* G1CMMarkStack::remove_chunk_from_free_list() {
+G1CMMarkStack::TaskQueueEntryChunk* G1CMMarkStack::remove_chunk_from_free_list() {
   MutexLockerEx x(MarkStackFreeList_lock, Mutex::_no_safepoint_check_flag);
   return remove_chunk_from_list(&_free_list);
 }
 
-G1CMMarkStack::OopChunk* G1CMMarkStack::allocate_new_chunk() {
+G1CMMarkStack::TaskQueueEntryChunk* G1CMMarkStack::allocate_new_chunk() {
   // This dirty read of _hwm is okay because we only ever increase the _hwm in parallel code.
   // Further this limits _hwm to a value of _chunk_capacity + #threads, avoiding
   // wraparound of _hwm.
@@ -266,40 +265,39 @@
     return NULL;
   }
 
-  OopChunk* result = ::new (&_base[cur_idx]) OopChunk;
+  TaskQueueEntryChunk* result = ::new (&_base[cur_idx]) TaskQueueEntryChunk;
   result->next = NULL;
   return result;
 }
 
-bool G1CMMarkStack::par_push_chunk(oop* ptr_arr) {
+bool G1CMMarkStack::par_push_chunk(G1TaskQueueEntry* ptr_arr) {
   // Get a new chunk.
-  OopChunk* new_chunk = remove_chunk_from_free_list();
+  TaskQueueEntryChunk* new_chunk = remove_chunk_from_free_list();
 
   if (new_chunk == NULL) {
     // Did not get a chunk from the free list. Allocate from backing memory.
     new_chunk = allocate_new_chunk();
+
+    if (new_chunk == NULL) {
+      return false;
+    }
   }
 
-  if (new_chunk == NULL) {
-    _out_of_memory = true;
-    return false;
-  }
-
-  Copy::conjoint_memory_atomic(ptr_arr, new_chunk->data, OopsPerChunk * sizeof(oop));
+  Copy::conjoint_memory_atomic(ptr_arr, new_chunk->data, EntriesPerChunk * sizeof(G1TaskQueueEntry));
 
   add_chunk_to_chunk_list(new_chunk);
 
   return true;
 }
 
-bool G1CMMarkStack::par_pop_chunk(oop* ptr_arr) {
-  OopChunk* cur = remove_chunk_from_chunk_list();
+bool G1CMMarkStack::par_pop_chunk(G1TaskQueueEntry* ptr_arr) {
+  TaskQueueEntryChunk* cur = remove_chunk_from_chunk_list();
 
   if (cur == NULL) {
     return false;
   }
 
-  Copy::conjoint_memory_atomic(cur->data, ptr_arr, OopsPerChunk * sizeof(oop));
+  Copy::conjoint_memory_atomic(cur->data, ptr_arr, EntriesPerChunk * sizeof(G1TaskQueueEntry));
 
   add_chunk_to_free_list(cur);
   return true;
@@ -308,7 +306,6 @@
 void G1CMMarkStack::set_empty() {
   _chunks_in_chunk_list = 0;
   _hwm = 0;
-  clear_out_of_memory();
   _chunk_list = NULL;
   _free_list = NULL;
 }
@@ -592,14 +589,10 @@
 }
 
 
-void G1ConcurrentMark::reset_marking_state(bool clear_overflow) {
+void G1ConcurrentMark::reset_marking_state() {
   _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 {
-    assert(has_overflown(), "pre-condition");
-  }
+  _global_mark_stack.set_empty();
+  clear_has_overflown();
   _finger = _heap_start;
 
   for (uint i = 0; i < _max_worker_id; ++i) {
@@ -883,7 +876,7 @@
       // not clear the overflow flag since we rely on it being true when
       // we exit this method to abort the pause and restart concurrent
       // marking.
-      reset_marking_state(true /* clear_overflow */);
+      reset_marking_state();
 
       log_info(gc, marking)("Concurrent Mark reset for overflow");
     }
@@ -1749,14 +1742,8 @@
     // oop closures will set the has_overflown flag if we overflow the
     // global marking stack.
 
-    assert(_global_mark_stack.is_out_of_memory() || _global_mark_stack.is_empty(),
-            "Mark stack should be empty (unless it is out of memory)");
-
-    if (_global_mark_stack.is_out_of_memory()) {
-      // 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();
-    }
+    assert(has_overflown() || _global_mark_stack.is_empty(),
+            "Mark stack should be empty (unless it has overflown)");
 
     assert(rp->num_q() == active_workers, "why not");
 
@@ -2008,13 +1995,17 @@
     _info(info)
   { }
 
-  void operator()(oop obj) const {
-    guarantee(G1CMObjArrayProcessor::is_array_slice(obj) || obj->is_oop(),
+  void operator()(G1TaskQueueEntry task_entry) const {
+    if (task_entry.is_array_slice()) {
+      guarantee(_g1h->is_in_reserved(task_entry.slice()), "Slice " PTR_FORMAT " must be in heap.", p2i(task_entry.slice()));
+      return;
+    }
+    guarantee(task_entry.obj()->is_oop(),
               "Non-oop " PTR_FORMAT ", phase: %s, info: %d",
-              p2i(obj), _phase, _info);
-    guarantee(G1CMObjArrayProcessor::is_array_slice(obj) || !_g1h->obj_in_cs(obj),
+              p2i(task_entry.obj()), _phase, _info);
+    guarantee(!_g1h->is_in_cset(task_entry.obj()),
               "obj: " PTR_FORMAT " in CSet, phase: %s, info: %d",
-              p2i(obj), _phase, _info);
+              p2i(task_entry.obj()), _phase, _info);
   }
 };
 
@@ -2208,7 +2199,7 @@
     // We move that task's local finger along.
     _task->move_finger_to(addr);
 
-    _task->scan_object(oop(addr));
+    _task->scan_task_entry(G1TaskQueueEntry::from_oop(oop(addr)));
     // we only partially drain the local queue and global stack
     _task->drain_local_queue(true);
     _task->drain_global_stack(true);
@@ -2399,16 +2390,16 @@
 void G1CMTask::move_entries_to_global_stack() {
   // Local array where we'll store the entries that will be popped
   // from the local queue.
-  oop buffer[G1CMMarkStack::OopsPerChunk];
+  G1TaskQueueEntry buffer[G1CMMarkStack::EntriesPerChunk];
 
   size_t n = 0;
-  oop obj;
-  while (n < G1CMMarkStack::OopsPerChunk && _task_queue->pop_local(obj)) {
-    buffer[n] = obj;
+  G1TaskQueueEntry task_entry;
+  while (n < G1CMMarkStack::EntriesPerChunk && _task_queue->pop_local(task_entry)) {
+    buffer[n] = task_entry;
     ++n;
   }
-  if (n < G1CMMarkStack::OopsPerChunk) {
-    buffer[n] = NULL;
+  if (n < G1CMMarkStack::EntriesPerChunk) {
+    buffer[n] = G1TaskQueueEntry();
   }
 
   if (n > 0) {
@@ -2424,20 +2415,20 @@
 bool G1CMTask::get_entries_from_global_stack() {
   // Local array where we'll store the entries that will be popped
   // from the global stack.
-  oop buffer[G1CMMarkStack::OopsPerChunk];
+  G1TaskQueueEntry buffer[G1CMMarkStack::EntriesPerChunk];
 
   if (!_cm->mark_stack_pop(buffer)) {
     return false;
   }
 
   // We did actually pop at least one entry.
-  for (size_t i = 0; i < G1CMMarkStack::OopsPerChunk; ++i) {
-    oop elem = buffer[i];
-    if (elem == NULL) {
+  for (size_t i = 0; i < G1CMMarkStack::EntriesPerChunk; ++i) {
+    G1TaskQueueEntry task_entry = buffer[i];
+    if (task_entry.is_null()) {
       break;
     }
-    assert(G1CMObjArrayProcessor::is_array_slice(elem) || elem->is_oop(), "Element " PTR_FORMAT " must be an array slice or oop", p2i(elem));
-    bool success = _task_queue->push(elem);
+    assert(task_entry.is_array_slice() || task_entry.obj()->is_oop(), "Element " PTR_FORMAT " must be an array slice or oop", p2i(task_entry.obj()));
+    bool success = _task_queue->push(task_entry);
     // 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.
     assert(success, "invariant");
@@ -2464,14 +2455,14 @@
   }
 
   if (_task_queue->size() > target_size) {
-    oop obj;
-    bool ret = _task_queue->pop_local(obj);
+    G1TaskQueueEntry entry;
+    bool ret = _task_queue->pop_local(entry);
     while (ret) {
-      scan_object(obj);
+      scan_task_entry(entry);
       if (_task_queue->size() <= target_size || has_aborted()) {
         ret = false;
       } else {
-        ret = _task_queue->pop_local(obj);
+        ret = _task_queue->pop_local(entry);
       }
     }
   }
@@ -2552,8 +2543,8 @@
                        _step_times_ms.maximum(), _step_times_ms.sum());
 }
 
-bool G1ConcurrentMark::try_stealing(uint worker_id, int* hash_seed, oop& obj) {
-  return _task_queues->steal(worker_id, hash_seed, obj);
+bool G1ConcurrentMark::try_stealing(uint worker_id, int* hash_seed, G1TaskQueueEntry& task_entry) {
+  return _task_queues->steal(worker_id, hash_seed, task_entry);
 }
 
 /*****************************************************************************
@@ -2876,9 +2867,9 @@
     assert(_cm->out_of_regions() && _task_queue->size() == 0,
            "only way to reach here");
     while (!has_aborted()) {
-      oop obj;
-      if (_cm->try_stealing(_worker_id, &_hash_seed, obj)) {
-        scan_object(obj);
+      G1TaskQueueEntry entry;
+      if (_cm->try_stealing(_worker_id, &_hash_seed, entry)) {
+        scan_task_entry(entry);
 
         // And since we're towards the end, let's totally drain the
         // local queue and global stack.
@@ -2931,7 +2922,6 @@
       guarantee(_cm->mark_stack_empty(), "only way to reach here");
       guarantee(_task_queue->size() == 0, "only way to reach here");
       guarantee(!_cm->has_overflown(), "only way to reach here");
-      guarantee(!_cm->mark_stack_overflow(), "only way to reach here");
     } else {
       // Apparently there's more work to do. Let's abort this task. It
       // will restart it and we can hopefully find more things to do.
--- a/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -38,7 +38,62 @@
 class ConcurrentGCTimer;
 class G1OldTracer;
 class G1SurvivorRegions;
-typedef GenericTaskQueue<oop, mtGC>              G1CMTaskQueue;
+
+#ifdef _MSC_VER
+#pragma warning(push)
+// warning C4522: multiple assignment operators specified
+#pragma warning(disable:4522)
+#endif
+
+// This is a container class for either an oop or a continuation address for
+// mark stack entries. Both are pushed onto the mark stack.
+class G1TaskQueueEntry VALUE_OBJ_CLASS_SPEC {
+private:
+  void* _holder;
+
+  static const uintptr_t ArraySliceBit = 1;
+
+  G1TaskQueueEntry(oop obj) : _holder(obj) {
+    assert(_holder != NULL, "Not allowed to set NULL task queue element");
+  }
+  G1TaskQueueEntry(HeapWord* addr) : _holder((void*)((uintptr_t)addr | ArraySliceBit)) { }
+public:
+  G1TaskQueueEntry(const G1TaskQueueEntry& other) { _holder = other._holder; }
+  G1TaskQueueEntry() : _holder(NULL) { }
+
+  static G1TaskQueueEntry from_slice(HeapWord* what) { return G1TaskQueueEntry(what); }
+  static G1TaskQueueEntry from_oop(oop obj) { return G1TaskQueueEntry(obj); }
+
+  G1TaskQueueEntry& operator=(const G1TaskQueueEntry& t) {
+    _holder = t._holder;
+    return *this;
+  }
+
+  volatile G1TaskQueueEntry& operator=(const volatile G1TaskQueueEntry& t) volatile {
+    _holder = t._holder;
+    return *this;
+  }
+
+  oop obj() const {
+    assert(!is_array_slice(), "Trying to read array slice " PTR_FORMAT " as oop", p2i(_holder));
+    return (oop)_holder;
+  }
+
+  HeapWord* slice() const {
+    assert(is_array_slice(), "Trying to read oop " PTR_FORMAT " as array slice", p2i(_holder));
+    return (HeapWord*)((uintptr_t)_holder & ~ArraySliceBit);
+  }
+
+  bool is_oop() const { return !is_array_slice(); }
+  bool is_array_slice() const { return ((uintptr_t)_holder & ArraySliceBit) != 0; }
+  bool is_null() const { return _holder == NULL; }
+};
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+typedef GenericTaskQueue<G1TaskQueueEntry, mtGC> G1CMTaskQueue;
 typedef GenericTaskQueueSet<G1CMTaskQueue, mtGC> G1CMTaskQueueSet;
 
 // Closure used by CM during concurrent reference discovery
@@ -165,46 +220,44 @@
 // list connecting all empty chunks.
 class G1CMMarkStack VALUE_OBJ_CLASS_SPEC {
 public:
-  // Number of oops that can fit in a single chunk.
-  static const size_t OopsPerChunk = 1024 - 1 /* One reference for the next pointer */;
+  // Number of TaskQueueEntries that can fit in a single chunk.
+  static const size_t EntriesPerChunk = 1024 - 1 /* One reference for the next pointer */;
 private:
-  struct OopChunk {
-    OopChunk* next;
-    oop data[OopsPerChunk];
+  struct TaskQueueEntryChunk {
+    TaskQueueEntryChunk* next;
+    G1TaskQueueEntry data[EntriesPerChunk];
   };
 
-  size_t _max_chunk_capacity;    // Maximum number of OopChunk elements on the stack.
+  size_t _max_chunk_capacity;    // Maximum number of TaskQueueEntryChunk elements on the stack.
 
-  OopChunk* _base;               // Bottom address of allocated memory area.
-  size_t _chunk_capacity;        // Current maximum number of OopChunk elements.
+  TaskQueueEntryChunk* _base;    // Bottom address of allocated memory area.
+  size_t _chunk_capacity;        // Current maximum number of TaskQueueEntryChunk elements.
 
   char _pad0[DEFAULT_CACHE_LINE_SIZE];
-  OopChunk* volatile _free_list;  // Linked list of free chunks that can be allocated by users.
-  char _pad1[DEFAULT_CACHE_LINE_SIZE - sizeof(OopChunk*)];
-  OopChunk* volatile _chunk_list; // List of chunks currently containing data.
+  TaskQueueEntryChunk* volatile _free_list;  // Linked list of free chunks that can be allocated by users.
+  char _pad1[DEFAULT_CACHE_LINE_SIZE - sizeof(TaskQueueEntryChunk*)];
+  TaskQueueEntryChunk* volatile _chunk_list; // List of chunks currently containing data.
   volatile size_t _chunks_in_chunk_list;
-  char _pad2[DEFAULT_CACHE_LINE_SIZE - sizeof(OopChunk*) - sizeof(size_t)];
+  char _pad2[DEFAULT_CACHE_LINE_SIZE - sizeof(TaskQueueEntryChunk*) - sizeof(size_t)];
 
   volatile size_t _hwm;          // High water mark within the reserved space.
   char _pad4[DEFAULT_CACHE_LINE_SIZE - sizeof(size_t)];
 
   // Allocate a new chunk from the reserved memory, using the high water mark. Returns
   // NULL if out of memory.
-  OopChunk* allocate_new_chunk();
-
-  volatile bool _out_of_memory;
+  TaskQueueEntryChunk* allocate_new_chunk();
 
   // Atomically add the given chunk to the list.
-  void add_chunk_to_list(OopChunk* volatile* list, OopChunk* elem);
+  void add_chunk_to_list(TaskQueueEntryChunk* volatile* list, TaskQueueEntryChunk* elem);
   // Atomically remove and return a chunk from the given list. Returns NULL if the
   // list is empty.
-  OopChunk* remove_chunk_from_list(OopChunk* volatile* list);
+  TaskQueueEntryChunk* remove_chunk_from_list(TaskQueueEntryChunk* volatile* list);
 
-  void add_chunk_to_chunk_list(OopChunk* elem);
-  void add_chunk_to_free_list(OopChunk* elem);
+  void add_chunk_to_chunk_list(TaskQueueEntryChunk* elem);
+  void add_chunk_to_free_list(TaskQueueEntryChunk* elem);
 
-  OopChunk* remove_chunk_from_chunk_list();
-  OopChunk* remove_chunk_from_free_list();
+  TaskQueueEntryChunk* remove_chunk_from_chunk_list();
+  TaskQueueEntryChunk* remove_chunk_from_free_list();
 
   bool  _should_expand;
 
@@ -222,17 +275,17 @@
   // Allocate and initialize the mark stack with the given number of oops.
   bool initialize(size_t initial_capacity, size_t max_capacity);
 
-  // Pushes the given buffer containing at most OopsPerChunk elements on the mark
-  // stack. If less than OopsPerChunk elements are to be pushed, the array must
+  // Pushes the given buffer containing at most EntriesPerChunk elements on the mark
+  // stack. If less than EntriesPerChunk elements are to be pushed, the array must
   // be terminated with a NULL.
   // Returns whether the buffer contents were successfully pushed to the global mark
   // stack.
-  bool par_push_chunk(oop* buffer);
+  bool par_push_chunk(G1TaskQueueEntry* buffer);
 
   // Pops a chunk from this mark stack, copying them into the given buffer. This
-  // chunk may contain up to OopsPerChunk elements. If there are less, the last
+  // chunk may contain up to EntriesPerChunk elements. If there are less, the last
   // element in the array is a NULL pointer.
-  bool par_pop_chunk(oop* buffer);
+  bool par_pop_chunk(G1TaskQueueEntry* buffer);
 
   // Return whether the chunk list is empty. Racy due to unsynchronized access to
   // _chunk_list.
@@ -240,9 +293,6 @@
 
   size_t capacity() const  { return _chunk_capacity; }
 
-  bool is_out_of_memory() const { return _out_of_memory; }
-  void clear_out_of_memory() { _out_of_memory = false; }
-
   bool should_expand() const { return _should_expand; }
   void set_should_expand(bool value) { _should_expand = value; }
 
@@ -251,7 +301,7 @@
 
   // Return the approximate number of oops on this mark stack. Racy due to
   // unsynchronized access to _chunks_in_chunk_list.
-  size_t size() const { return _chunks_in_chunk_list * OopsPerChunk; }
+  size_t size() const { return _chunks_in_chunk_list * EntriesPerChunk; }
 
   void set_empty();
 
@@ -432,7 +482,7 @@
 
   // Resets all the marking data structures. Called when we have to restart
   // marking or when marking completes (via set_non_marking_state below).
-  void reset_marking_state(bool clear_overflow = true);
+  void reset_marking_state();
 
   // We do this after we're done with marking so that the marking data
   // structures are initialized to a sensible and predictable state.
@@ -531,19 +581,18 @@
   // Manipulation of the global mark stack.
   // The push and pop operations are used by tasks for transfers
   // between task-local queues and the global mark stack.
-  bool mark_stack_push(oop* arr) {
+  bool mark_stack_push(G1TaskQueueEntry* arr) {
     if (!_global_mark_stack.par_push_chunk(arr)) {
       set_has_overflown();
       return false;
     }
     return true;
   }
-  bool mark_stack_pop(oop* arr) {
+  bool mark_stack_pop(G1TaskQueueEntry* arr) {
     return _global_mark_stack.par_pop_chunk(arr);
   }
   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.is_out_of_memory(); }
   bool mark_stack_empty()                 { return _global_mark_stack.is_empty(); }
 
   G1CMRootRegions* root_regions() { return &_root_regions; }
@@ -573,7 +622,7 @@
   }
 
   // Attempts to steal an object from the task queues of other tasks
-  bool try_stealing(uint worker_id, int* hash_seed, oop& obj);
+  bool try_stealing(uint worker_id, int* hash_seed, G1TaskQueueEntry& task_entry);
 
   G1ConcurrentMark(G1CollectedHeap* g1h,
                    G1RegionToSpaceMapper* prev_bitmap_storage,
@@ -828,7 +877,7 @@
   // mark bitmap scan, and so needs to be pushed onto the mark stack.
   bool is_below_finger(oop obj, HeapWord* global_finger) const;
 
-  template<bool scan> void process_grey_object(oop obj);
+  template<bool scan> void process_grey_task_entry(G1TaskQueueEntry task_entry);
 public:
   // Apply the closure on the given area of the objArray. Return the number of words
   // scanned.
@@ -893,10 +942,10 @@
   inline void deal_with_reference(oop obj);
 
   // It scans an object and visits its children.
-  inline void scan_object(oop obj);
+  inline void scan_task_entry(G1TaskQueueEntry task_entry);
 
   // It pushes an object on the local queue.
-  inline void push(oop obj);
+  inline void push(G1TaskQueueEntry task_entry);
 
   // Move entries to the global stack.
   void move_entries_to_global_stack();
--- a/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.inline.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1ConcurrentMark.inline.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -97,12 +97,12 @@
 
   size_t num_chunks = 0;
 
-  OopChunk* cur = _chunk_list;
+  TaskQueueEntryChunk* cur = _chunk_list;
   while (cur != NULL) {
     guarantee(num_chunks <= _chunks_in_chunk_list, "Found " SIZE_FORMAT " oop chunks which is more than there should be", num_chunks);
 
-    for (size_t i = 0; i < OopsPerChunk; ++i) {
-      if (cur->data[i] == NULL) {
+    for (size_t i = 0; i < EntriesPerChunk; ++i) {
+      if (cur->data[i].is_null()) {
         break;
       }
       fn(cur->data[i]);
@@ -114,17 +114,16 @@
 #endif
 
 // It scans an object and visits its children.
-inline void G1CMTask::scan_object(oop obj) { process_grey_object<true>(obj); }
+inline void G1CMTask::scan_task_entry(G1TaskQueueEntry task_entry) { process_grey_task_entry<true>(task_entry); }
 
-inline void G1CMTask::push(oop obj) {
-  HeapWord* objAddr = (HeapWord*) obj;
-  assert(G1CMObjArrayProcessor::is_array_slice(obj) || _g1h->is_in_g1_reserved(objAddr), "invariant");
-  assert(G1CMObjArrayProcessor::is_array_slice(obj) || !_g1h->is_on_master_free_list(
-              _g1h->heap_region_containing((HeapWord*) objAddr)), "invariant");
-  assert(G1CMObjArrayProcessor::is_array_slice(obj) || !_g1h->is_obj_ill(obj), "invariant");
-  assert(G1CMObjArrayProcessor::is_array_slice(obj) || _nextMarkBitMap->isMarked(objAddr), "invariant");
+inline void G1CMTask::push(G1TaskQueueEntry task_entry) {
+  assert(task_entry.is_array_slice() || _g1h->is_in_g1_reserved(task_entry.obj()), "invariant");
+  assert(task_entry.is_array_slice() || !_g1h->is_on_master_free_list(
+              _g1h->heap_region_containing(task_entry.obj())), "invariant");
+  assert(task_entry.is_array_slice() || !_g1h->is_obj_ill(task_entry.obj()), "invariant");  // FIXME!!!
+  assert(task_entry.is_array_slice() || _nextMarkBitMap->isMarked((HeapWord*)task_entry.obj()), "invariant");
 
-  if (!_task_queue->push(obj)) {
+  if (!_task_queue->push(task_entry)) {
     // The local task queue looks full. We need to push some entries
     // to the global stack.
     move_entries_to_global_stack();
@@ -132,7 +131,7 @@
     // this should succeed since, even if we overflow the global
     // stack, we should have definitely removed some entries from the
     // local queue. So, there must be space on it.
-    bool success = _task_queue->push(obj);
+    bool success = _task_queue->push(task_entry);
     assert(success, "invariant");
   }
 }
@@ -168,18 +167,21 @@
 }
 
 template<bool scan>
-inline void G1CMTask::process_grey_object(oop obj) {
-  assert(scan || obj->is_typeArray(), "Skipping scan of grey non-typeArray");
-  assert(G1CMObjArrayProcessor::is_array_slice(obj) || _nextMarkBitMap->isMarked((HeapWord*) obj),
+inline void G1CMTask::process_grey_task_entry(G1TaskQueueEntry task_entry) {
+  assert(scan || (task_entry.is_oop() && task_entry.obj()->is_typeArray()), "Skipping scan of grey non-typeArray");
+  assert(task_entry.is_array_slice() || _nextMarkBitMap->isMarked((HeapWord*)task_entry.obj()),
          "Any stolen object should be a slice or marked");
 
   if (scan) {
-    if (G1CMObjArrayProcessor::is_array_slice(obj)) {
-      _words_scanned += _objArray_processor.process_slice(obj);
-    } else if (G1CMObjArrayProcessor::should_be_sliced(obj)) {
-      _words_scanned += _objArray_processor.process_obj(obj);
+    if (task_entry.is_array_slice()) {
+      _words_scanned += _objArray_processor.process_slice(task_entry.slice());
     } else {
-      _words_scanned += obj->oop_iterate_size(_cm_oop_closure);;
+      oop obj = task_entry.obj();
+      if (G1CMObjArrayProcessor::should_be_sliced(obj)) {
+        _words_scanned += _objArray_processor.process_obj(obj);
+      } else {
+        _words_scanned += obj->oop_iterate_size(_cm_oop_closure);;
+      }
     }
   }
   check_limits();
@@ -210,6 +212,7 @@
     // be pushed on the stack. So, some duplicate work, but no
     // correctness problems.
     if (is_below_finger(obj, global_finger)) {
+      G1TaskQueueEntry entry = G1TaskQueueEntry::from_oop(obj);
       if (obj->is_typeArray()) {
         // Immediately process arrays of primitive types, rather
         // than pushing on the mark stack.  This keeps us from
@@ -221,9 +224,9 @@
         // by only doing a bookkeeping update and avoiding the
         // actual scan of the object - a typeArray contains no
         // references, and the metadata is built-in.
-        process_grey_object<false>(obj);
+        process_grey_task_entry<false>(entry);
       } else {
-        push(obj);
+        push(entry);
       }
     }
   }
--- a/hotspot/src/share/vm/gc/g1/g1ConcurrentMarkObjArrayProcessor.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1ConcurrentMarkObjArrayProcessor.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,18 +26,8 @@
 #include "gc/g1/g1ConcurrentMark.inline.hpp"
 #include "gc/g1/g1ConcurrentMarkObjArrayProcessor.inline.hpp"
 
-oop G1CMObjArrayProcessor::encode_array_slice(HeapWord* addr) {
-  return oop((void*)((uintptr_t)addr | ArraySliceBit));
-}
-
-HeapWord* G1CMObjArrayProcessor::decode_array_slice(oop value) {
-  assert(is_array_slice(value), "Given value " PTR_FORMAT " is not an array slice", p2i(value));
-  return (HeapWord*)((uintptr_t)(void*)value & ~ArraySliceBit);
-}
-
 void G1CMObjArrayProcessor::push_array_slice(HeapWord* what) {
-  oop obj = encode_array_slice(what);
-  _task->push(obj);
+  _task->push(G1TaskQueueEntry::from_slice(what));
 }
 
 size_t G1CMObjArrayProcessor::process_array_slice(objArrayOop obj, HeapWord* start_from, size_t remaining) {
@@ -58,30 +48,29 @@
   return process_array_slice(objArrayOop(obj), (HeapWord*)obj, (size_t)objArrayOop(obj)->size());
 }
 
-size_t G1CMObjArrayProcessor::process_slice(oop obj) {
-  HeapWord* const decoded_address = decode_array_slice(obj);
+size_t G1CMObjArrayProcessor::process_slice(HeapWord* slice) {
 
   // Find the start address of the objArrayOop.
   // Shortcut the BOT access if the given address is from a humongous object. The BOT
   // slide is fast enough for "smaller" objects in non-humongous regions, but is slower
   // than directly using heap region table.
   G1CollectedHeap* g1h = G1CollectedHeap::heap();
-  HeapRegion* r = g1h->heap_region_containing(decoded_address);
+  HeapRegion* r = g1h->heap_region_containing(slice);
 
   HeapWord* const start_address = r->is_humongous() ?
                                   r->humongous_start_region()->bottom() :
-                                  g1h->block_start(decoded_address);
+                                  g1h->block_start(slice);
 
   assert(oop(start_address)->is_objArray(), "Address " PTR_FORMAT " does not refer to an object array ", p2i(start_address));
-  assert(start_address < decoded_address,
+  assert(start_address < slice,
          "Object start address " PTR_FORMAT " must be smaller than decoded address " PTR_FORMAT,
          p2i(start_address),
-         p2i(decoded_address));
+         p2i(slice));
 
   objArrayOop objArray = objArrayOop(start_address);
 
-  size_t already_scanned = decoded_address - start_address;
+  size_t already_scanned = slice - start_address;
   size_t remaining = objArray->size() - already_scanned;
 
-  return process_array_slice(objArray, decoded_address, remaining);
+  return process_array_slice(objArray, slice, remaining);
 }
--- a/hotspot/src/share/vm/gc/g1/g1ConcurrentMarkObjArrayProcessor.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1ConcurrentMarkObjArrayProcessor.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,32 +36,22 @@
 // This allows incremental processing of large objects.
 class G1CMObjArrayProcessor VALUE_OBJ_CLASS_SPEC {
 private:
-  // The bit mask for the continuation indicator of elements on the mark stack.
-  static const size_t ArraySliceBit = 1;
-
   // Reference to the task for doing the actual work.
   G1CMTask* _task;
 
-  // Encodes the given address as a continuation "oop".
-  oop encode_array_slice(HeapWord* addr);
-  // Remove the continuation marker from the given oop from the mark stack.
-  HeapWord* decode_array_slice(oop value);
-
   // Push the continuation at the given address onto the mark stack.
   void push_array_slice(HeapWord* addr);
 
   // Process (apply the closure) on the given continuation of the given objArray.
   size_t process_array_slice(objArrayOop const obj, HeapWord* start_from, size_t remaining);
 public:
-  static bool is_array_slice(void* obj) { return ((uintptr_t)obj & ArraySliceBit) != 0; }
-
   static bool should_be_sliced(oop obj);
 
   G1CMObjArrayProcessor(G1CMTask* task) : _task(task) {
   }
 
-  // Process the given continuation "oop". Returns the number of words scanned.
-  size_t process_slice(oop obj);
+  // Process the given continuation. Returns the number of words scanned.
+  size_t process_slice(HeapWord* slice);
   // Start processing the given objArrayOop by scanning the header and pushing its
   // continuation.
   size_t process_obj(oop obj);
--- a/hotspot/src/share/vm/gc/g1/g1EvacFailure.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1EvacFailure.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -216,14 +216,14 @@
   }
 
   bool doHeapRegion(HeapRegion *hr) {
-    bool during_initial_mark = _g1h->collector_state()->during_initial_mark_pause();
-    bool during_conc_mark = _g1h->collector_state()->mark_in_progress();
-
     assert(!hr->is_pinned(), "Unexpected pinned region at index %u", hr->hrm_index());
     assert(hr->in_collection_set(), "bad CS");
 
     if (_hrclaimer->claim_region(hr->hrm_index())) {
       if (hr->evacuation_failed()) {
+        bool during_initial_mark = _g1h->collector_state()->during_initial_mark_pause();
+        bool during_conc_mark = _g1h->collector_state()->mark_in_progress();
+
         hr->note_self_forwarding_removal_start(during_initial_mark,
                                                during_conc_mark);
         _g1h->verifier()->check_bitmaps("Self-Forwarding Ptr Removal", hr);
@@ -234,9 +234,7 @@
 
         hr->rem_set()->clean_strong_code_roots(hr);
 
-        hr->note_self_forwarding_removal_end(during_initial_mark,
-                                             during_conc_mark,
-                                             live_bytes);
+        hr->note_self_forwarding_removal_end(live_bytes);
       }
     }
     return false;
--- a/hotspot/src/share/vm/gc/g1/g1EvacStats.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1EvacStats.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -46,29 +46,7 @@
                       _failure_waste * HeapWordSize);
 }
 
-void G1EvacStats::adjust_desired_plab_sz() {
-  log_plab_allocation();
-
-  if (!ResizePLAB) {
-    // Clear accumulators for next round.
-    reset();
-    return;
-  }
-
-  assert(is_object_aligned(max_size()) && min_size() <= max_size(),
-         "PLAB clipping computation may be incorrect");
-
-  if (_allocated == 0) {
-    assert((_unused == 0),
-           "Inconsistency in PLAB stats: "
-           "_allocated: " SIZE_FORMAT ", "
-           "_wasted: " SIZE_FORMAT ", "
-           "_region_end_waste: " SIZE_FORMAT ", "
-           "_unused: " SIZE_FORMAT ", "
-           "_used  : " SIZE_FORMAT,
-           _allocated, _wasted, _region_end_waste, _unused, used());
-    _allocated = 1;
-  }
+size_t G1EvacStats::compute_desired_plab_sz() {
   // The size of the PLAB caps the amount of space that can be wasted at the
   // end of the collection. In the worst case the last PLAB could be completely
   // empty.
@@ -109,13 +87,7 @@
 
   size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct;
   size_t const cur_plab_sz = (size_t)((double)total_waste_allowed / G1LastPLABAverageOccupancy);
-  // Take historical weighted average
-  _filter.sample(cur_plab_sz);
-  _desired_net_plab_sz = MAX2(min_size(), (size_t)_filter.average());
-
-  log_sizing(cur_plab_sz, _desired_net_plab_sz);
-  // Clear accumulators for next round.
-  reset();
+  return cur_plab_sz;
 }
 
 G1EvacStats::G1EvacStats(const char* description, size_t desired_plab_sz_, unsigned wt) :
--- a/hotspot/src/share/vm/gc/g1/g1EvacStats.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1EvacStats.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -53,13 +53,13 @@
 
   virtual void log_plab_allocation();
 
+  virtual size_t compute_desired_plab_sz();
+
  public:
   G1EvacStats(const char* description, size_t desired_plab_sz_, unsigned wt);
 
   ~G1EvacStats();
 
-  virtual void adjust_desired_plab_sz();
-
   uint regions_filled() const { return _regions_filled; }
   size_t region_end_waste() const { return _region_end_waste; }
   size_t direct_allocated() const { return _direct_allocated; }
--- a/hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -112,6 +112,9 @@
   _cur_evac_fail_restore_remsets = 0.0;
   _cur_evac_fail_remove_self_forwards = 0.0;
   _cur_string_dedup_fixup_time_ms = 0.0;
+  _cur_prepare_tlab_time_ms = 0.0;
+  _cur_resize_tlab_time_ms = 0.0;
+  _cur_derived_pointer_table_update_time_ms = 0.0;
   _cur_clear_ct_time_ms = 0.0;
   _cur_expand_heap_time_ms = 0.0;
   _cur_ref_proc_time_ms = 0.0;
@@ -125,6 +128,7 @@
   _recorded_redirty_logged_cards_time_ms = 0.0;
   _recorded_preserve_cm_referents_time_ms = 0.0;
   _recorded_merge_pss_time_ms = 0.0;
+  _recorded_start_new_cset_time_ms = 0.0;
   _recorded_total_free_cset_time_ms = 0.0;
   _recorded_serial_free_cset_time_ms = 0.0;
   _cur_fast_reclaim_humongous_time_ms = 0.0;
@@ -288,6 +292,7 @@
   if (_root_region_scan_wait_time_ms > 0.0) {
     debug_time("Root Region Scan Waiting", _root_region_scan_wait_time_ms);
   }
+  debug_time("Prepare TLABs", _cur_prepare_tlab_time_ms);
   debug_time("Choose Collection Set", (_recorded_young_cset_choice_time_ms + _recorded_non_young_cset_choice_time_ms));
   if (G1EagerReclaimHumongousObjects) {
     debug_time("Humongous Register", _cur_fast_reclaim_humongous_register_time_ms);
@@ -375,6 +380,9 @@
   debug_time("Code Roots Purge", _cur_strong_code_root_purge_time_ms);
 
   debug_time("Redirty Cards", _recorded_redirty_logged_cards_time_ms);
+#if defined(COMPILER2) || INCLUDE_JVMCI
+  debug_time("DerivedPointerTable Update", _cur_derived_pointer_table_update_time_ms);
+#endif
   if (_recorded_clear_claimed_marks_time_ms > 0.0) {
     debug_time("Clear Claimed Marks", _recorded_clear_claimed_marks_time_ms);
   }
@@ -390,6 +398,10 @@
     debug_time("Humongous Reclaim", _cur_fast_reclaim_humongous_time_ms);
     trace_count("Humongous Reclaimed", _cur_fast_reclaim_humongous_reclaimed);
   }
+  debug_time("Start New Collection Set", _recorded_start_new_cset_time_ms);
+  if (UseTLAB && ResizeTLAB) {
+    debug_time("Resize TLABs", _cur_resize_tlab_time_ms);
+  }
   debug_time("Expand Heap After Collection", _cur_expand_heap_time_ms);
 
 
--- a/hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -97,6 +97,11 @@
 
   double _cur_string_dedup_fixup_time_ms;
 
+  double _cur_prepare_tlab_time_ms;
+  double _cur_resize_tlab_time_ms;
+
+  double _cur_derived_pointer_table_update_time_ms;
+
   double _cur_clear_ct_time_ms;
   double _cur_expand_heap_time_ms;
   double _cur_ref_proc_time_ms;
@@ -118,6 +123,8 @@
 
   double _recorded_merge_pss_time_ms;
 
+  double _recorded_start_new_cset_time_ms;
+
   double _recorded_total_free_cset_time_ms;
 
   double _recorded_serial_free_cset_time_ms;
@@ -172,6 +179,18 @@
 
  public:
 
+  void record_prepare_tlab_time_ms(double ms) {
+    _cur_prepare_tlab_time_ms = ms;
+  }
+
+  void record_resize_tlab_time_ms(double ms) {
+    _cur_resize_tlab_time_ms = ms;
+  }
+
+  void record_derived_pointer_table_update_time(double ms) {
+    _cur_derived_pointer_table_update_time_ms = ms;
+  }
+
   void record_clear_ct_time(double ms) {
     _cur_clear_ct_time_ms = ms;
   }
@@ -259,6 +278,10 @@
     _recorded_merge_pss_time_ms = time_ms;
   }
 
+  void record_start_new_cset_time_ms(double time_ms) {
+    _recorded_start_new_cset_time_ms = time_ms;
+  }
+
   void record_cur_collection_start_sec(double time_ms) {
     _cur_collection_start_sec = time_ms;
   }
--- a/hotspot/src/share/vm/gc/g1/g1HeapVerifier.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1HeapVerifier.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,10 +25,10 @@
 #include "precompiled.hpp"
 #include "logging/log.hpp"
 #include "gc/g1/concurrentMarkThread.hpp"
+#include "gc/g1/g1Allocator.inline.hpp"
 #include "gc/g1/g1CollectedHeap.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
 #include "gc/g1/g1HeapVerifier.hpp"
-#include "gc/g1/g1MarkSweep.hpp"
 #include "gc/g1/g1Policy.hpp"
 #include "gc/g1/g1RemSet.hpp"
 #include "gc/g1/g1RootProcessor.hpp"
@@ -239,7 +239,7 @@
 
   template <class T> void do_oop_work(T *p) {
     oop obj = oopDesc::load_decode_heap_oop(p);
-    guarantee(obj == NULL || G1MarkSweep::in_archive_range(obj),
+    guarantee(obj == NULL || G1ArchiveAllocator::is_archive_object(obj),
               "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
               p2i(p), p2i(obj));
   }
--- a/hotspot/src/share/vm/gc/g1/g1MarkSweep.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1MarkSweep.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -56,9 +56,6 @@
 
 class HeapRegion;
 
-bool G1MarkSweep::_archive_check_enabled = false;
-G1ArchiveRegionMap G1MarkSweep::_archive_region_map;
-
 void G1MarkSweep::invoke_at_safepoint(ReferenceProcessor* rp,
                                       bool clear_all_softrefs) {
   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
@@ -314,26 +311,6 @@
 
 }
 
-void G1MarkSweep::enable_archive_object_check() {
-  assert(!_archive_check_enabled, "archive range check already enabled");
-  _archive_check_enabled = true;
-  size_t length = Universe::heap()->max_capacity();
-  _archive_region_map.initialize((HeapWord*)Universe::heap()->base(),
-                                 (HeapWord*)Universe::heap()->base() + length,
-                                 HeapRegion::GrainBytes);
-}
-
-void G1MarkSweep::set_range_archive(MemRegion range, bool is_archive) {
-  assert(_archive_check_enabled, "archive range check not enabled");
-  _archive_region_map.set_by_address(range, is_archive);
-}
-
-bool G1MarkSweep::in_archive_range(oop object) {
-  // This is the out-of-line part of is_archive_object test, done separately
-  // to avoid additional performance impact when the check is not enabled.
-  return _archive_region_map.get_by_address((HeapWord*)object);
-}
-
 void G1MarkSweep::prepare_compaction_work(G1PrepareCompactClosure* blk) {
   G1CollectedHeap* g1h = G1CollectedHeap::heap();
   g1h->heap_region_iterate(blk);
--- a/hotspot/src/share/vm/gc/g1/g1MarkSweep.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1MarkSweep.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -55,23 +55,7 @@
   static STWGCTimer* gc_timer() { return GenMarkSweep::_gc_timer; }
   static SerialOldTracer* gc_tracer() { return GenMarkSweep::_gc_tracer; }
 
-  // Create the _archive_region_map which is used to identify archive objects.
-  static void enable_archive_object_check();
-
-  // Set the regions containing the specified address range as archive/non-archive.
-  static void set_range_archive(MemRegion range, bool is_archive);
-
-  // Check if an object is in an archive region using the _archive_region_map.
-  static bool in_archive_range(oop object);
-
-  // Check if archive object checking is enabled, to avoid calling in_archive_range
-  // unnecessarily.
-  static bool archive_check_enabled() { return G1MarkSweep::_archive_check_enabled; }
-
- private:
-  static bool _archive_check_enabled;
-  static G1ArchiveRegionMap  _archive_region_map;
-
+private:
   // Mark live objects
   static void mark_sweep_phase1(bool& marked_for_deopt,
                                 bool clear_all_softrefs);
@@ -109,12 +93,4 @@
   bool doHeapRegion(HeapRegion* hr);
 };
 
-// G1ArchiveRegionMap is a boolean array used to mark G1 regions as
-// archive regions.  This allows a quick check for whether an object
-// should not be marked because it is in an archive region.
-class G1ArchiveRegionMap : public G1BiasedMappedArray<bool> {
-protected:
-  bool default_value() const { return false; }
-};
-
 #endif // SHARE_VM_GC_G1_G1MARKSWEEP_HPP
--- a/hotspot/src/share/vm/gc/g1/g1OopClosures.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1OopClosures.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -143,29 +143,6 @@
   void do_klass(Klass* klass);
 };
 
-class FilterIntoCSClosure: public OopClosure {
-  G1CollectedHeap* _g1;
-  OopClosure* _oc;
-public:
-  FilterIntoCSClosure(G1CollectedHeap* g1, OopClosure* oc) : _g1(g1), _oc(oc) { }
-
-  template <class T> void do_oop_work(T* p);
-  virtual void do_oop(oop* p)        { do_oop_work(p); }
-  virtual void do_oop(narrowOop* p)  { do_oop_work(p); }
-};
-
-class FilterOutOfRegionClosure: public ExtendedOopClosure {
-  HeapWord* _r_bottom;
-  HeapWord* _r_end;
-  OopClosure* _oc;
-public:
-  FilterOutOfRegionClosure(HeapRegion* r, OopClosure* oc);
-  template <class T> void do_oop_nv(T* p);
-  virtual void do_oop(oop* p) { do_oop_nv(p); }
-  virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
-  bool apply_to_weak_ref_discovered_field() { return true; }
-};
-
 // Closure for iterating over object fields during concurrent marking
 class G1CMOopClosure : public MetadataAwareOopClosure {
 protected:
@@ -193,58 +170,16 @@
   virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
 };
 
-// Closure that applies the given two closures in sequence.
-// Used by the RSet refinement code (when updating RSets
-// during an evacuation pause) to record cards containing
-// pointers into the collection set.
-
-class G1Mux2Closure : public OopClosure {
-  OopClosure* _c1;
-  OopClosure* _c2;
-public:
-  G1Mux2Closure(OopClosure *c1, OopClosure *c2);
-  template <class T> inline void do_oop_work(T* p);
-  virtual inline void do_oop(oop* p);
-  virtual inline void do_oop(narrowOop* p);
-};
-
-// A closure that returns true if it is actually applied
-// to a reference
-
-class G1TriggerClosure : public OopClosure {
-  bool _triggered;
-public:
-  G1TriggerClosure();
-  bool triggered() const { return _triggered; }
-  template <class T> inline void do_oop_work(T* p);
-  virtual inline void do_oop(oop* p);
-  virtual inline void do_oop(narrowOop* p);
-};
-
-// A closure which uses a triggering closure to determine
-// whether to apply an oop closure.
-
-class G1InvokeIfNotTriggeredClosure: public OopClosure {
-  G1TriggerClosure* _trigger_cl;
-  OopClosure* _oop_cl;
-public:
-  G1InvokeIfNotTriggeredClosure(G1TriggerClosure* t, OopClosure* oc);
-  template <class T> inline void do_oop_work(T* p);
-  virtual inline void do_oop(oop* p);
-  virtual inline void do_oop(narrowOop* p);
-};
-
-class G1UpdateRSOrPushRefOopClosure: public OopClosure {
+class G1UpdateRSOrPushRefOopClosure: public ExtendedOopClosure {
   G1CollectedHeap* _g1;
-  G1RemSet* _g1_rem_set;
   HeapRegion* _from;
   G1ParPushHeapRSClosure* _push_ref_cl;
   bool _record_refs_into_cset;
   uint _worker_i;
+  bool _has_refs_into_cset;
 
 public:
   G1UpdateRSOrPushRefOopClosure(G1CollectedHeap* g1h,
-                                G1RemSet* rs,
                                 G1ParPushHeapRSClosure* push_ref_cl,
                                 bool record_refs_into_cset,
                                 uint worker_i = 0);
@@ -254,13 +189,17 @@
     _from = from;
   }
 
+  bool apply_to_weak_ref_discovered_field() { return true; }
+
   bool self_forwarded(oop obj) {
     markOop m = obj->mark();
     bool result = (m->is_marked() && ((oop)m->decode_pointer() == obj));
     return result;
   }
 
-  template <class T> inline void do_oop_work(T* p);
+  bool has_refs_into_cset() const { return _has_refs_into_cset; }
+
+  template <class T> inline void do_oop_nv(T* p);
   virtual inline void do_oop(narrowOop* p);
   virtual inline void do_oop(oop* p);
 };
--- a/hotspot/src/share/vm/gc/g1/g1OopClosures.inline.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1OopClosures.inline.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,31 +36,6 @@
 #include "memory/iterator.inline.hpp"
 #include "runtime/prefetch.inline.hpp"
 
-/*
- * This really ought to be an inline function, but apparently the C++
- * compiler sometimes sees fit to ignore inline declarations.  Sigh.
- */
-
-template <class T>
-inline void FilterIntoCSClosure::do_oop_work(T* p) {
-  T heap_oop = oopDesc::load_heap_oop(p);
-  if (!oopDesc::is_null(heap_oop) &&
-      _g1->is_in_cset_or_humongous(oopDesc::decode_heap_oop_not_null(heap_oop))) {
-    _oc->do_oop(p);
-  }
-}
-
-template <class T>
-inline void FilterOutOfRegionClosure::do_oop_nv(T* p) {
-  T heap_oop = oopDesc::load_heap_oop(p);
-  if (!oopDesc::is_null(heap_oop)) {
-    HeapWord* obj_hw = (HeapWord*)oopDesc::decode_heap_oop_not_null(heap_oop);
-    if (obj_hw < _r_bottom || obj_hw >= _r_end) {
-      _oc->do_oop(p);
-    }
-  }
-}
-
 // This closure is applied to the fields of the objects that have just been copied.
 template <class T>
 inline void G1ParScanClosure::do_oop_nv(T* p) {
@@ -114,7 +89,7 @@
     } else if (state.is_ext()) {
       _par_scan_state->do_oop_ext(p);
     } else {
-      assert(!_g1->obj_in_cs(obj), "checking");
+      assert(!_g1->is_in_cset(obj), "checking");
     }
   }
 }
@@ -136,33 +111,7 @@
 }
 
 template <class T>
-inline void G1Mux2Closure::do_oop_work(T* p) {
-  // Apply first closure; then apply the second.
-  _c1->do_oop(p);
-  _c2->do_oop(p);
-}
-void G1Mux2Closure::do_oop(oop* p)       { do_oop_work(p); }
-void G1Mux2Closure::do_oop(narrowOop* p) { do_oop_work(p); }
-
-template <class T>
-inline void G1TriggerClosure::do_oop_work(T* p) {
-  // Record that this closure was actually applied (triggered).
-  _triggered = true;
-}
-void G1TriggerClosure::do_oop(oop* p)       { do_oop_work(p); }
-void G1TriggerClosure::do_oop(narrowOop* p) { do_oop_work(p); }
-
-template <class T>
-inline void G1InvokeIfNotTriggeredClosure::do_oop_work(T* p) {
-  if (!_trigger_cl->triggered()) {
-    _oop_cl->do_oop(p);
-  }
-}
-void G1InvokeIfNotTriggeredClosure::do_oop(oop* p)       { do_oop_work(p); }
-void G1InvokeIfNotTriggeredClosure::do_oop(narrowOop* p) { do_oop_work(p); }
-
-template <class T>
-inline void G1UpdateRSOrPushRefOopClosure::do_oop_work(T* p) {
+inline void G1UpdateRSOrPushRefOopClosure::do_oop_nv(T* p) {
   oop obj = oopDesc::load_decode_heap_oop(p);
   if (obj == NULL) {
     return;
@@ -217,6 +166,7 @@
       // instance for this worker thread.
       _push_ref_cl->do_oop(p);
     }
+    _has_refs_into_cset = true;
 
     // Deferred updates to the CSet are either discarded (in the normal case),
     // or processed (if an evacuation failure occurs) at the end
@@ -232,8 +182,8 @@
     to->rem_set()->add_reference(p, _worker_i);
   }
 }
-void G1UpdateRSOrPushRefOopClosure::do_oop(oop* p)       { do_oop_work(p); }
-void G1UpdateRSOrPushRefOopClosure::do_oop(narrowOop* p) { do_oop_work(p); }
+void G1UpdateRSOrPushRefOopClosure::do_oop(oop* p)       { do_oop_nv(p); }
+void G1UpdateRSOrPushRefOopClosure::do_oop(narrowOop* p) { do_oop_nv(p); }
 
 template <class T>
 void G1ParCopyHelper::do_klass_barrier(T* p, oop new_obj) {
--- a/hotspot/src/share/vm/gc/g1/g1ParScanThreadState.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1ParScanThreadState.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -113,7 +113,7 @@
   if (has_partial_array_mask(ref)) {
     // Must be in the collection set--it's already been copied.
     oop p = clear_partial_array_mask(ref);
-    assert(_g1h->obj_in_cs(p),
+    assert(_g1h->is_in_cset(p),
            "ref=" PTR_FORMAT " p=" PTR_FORMAT, p2i(ref), p2i(p));
   } else {
     oop p = oopDesc::load_decode_heap_oop(ref);
@@ -372,7 +372,7 @@
 }
 
 oop G1ParScanThreadState::handle_evacuation_failure_par(oop old, markOop m) {
-  assert(_g1h->obj_in_cs(old), "Object " PTR_FORMAT " should be in the CSet", p2i(old));
+  assert(_g1h->is_in_cset(old), "Object " PTR_FORMAT " should be in the CSet", p2i(old));
 
   oop forward_ptr = old->forward_to_atomic(old);
   if (forward_ptr == NULL) {
@@ -394,7 +394,7 @@
     // Forward-to-self failed. Either someone else managed to allocate
     // space for this object (old != forward_ptr) or they beat us in
     // self-forwarding it (old == forward_ptr).
-    assert(old == forward_ptr || !_g1h->obj_in_cs(forward_ptr),
+    assert(old == forward_ptr || !_g1h->is_in_cset(forward_ptr),
            "Object " PTR_FORMAT " forwarded to: " PTR_FORMAT " "
            "should not be in the CSet",
            p2i(old), p2i(forward_ptr));
--- a/hotspot/src/share/vm/gc/g1/g1RemSet.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1RemSet.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -527,25 +527,16 @@
   _g1->heap_region_par_iterate(&scrub_cl, worker_num, hrclaimer);
 }
 
-G1TriggerClosure::G1TriggerClosure() :
-  _triggered(false) { }
-
-G1InvokeIfNotTriggeredClosure::G1InvokeIfNotTriggeredClosure(G1TriggerClosure* t_cl,
-                                                             OopClosure* oop_cl)  :
-  _trigger_cl(t_cl), _oop_cl(oop_cl) { }
-
-G1Mux2Closure::G1Mux2Closure(OopClosure *c1, OopClosure *c2) :
-  _c1(c1), _c2(c2) { }
-
-G1UpdateRSOrPushRefOopClosure::
-G1UpdateRSOrPushRefOopClosure(G1CollectedHeap* g1h,
-                              G1RemSet* rs,
-                              G1ParPushHeapRSClosure* push_ref_cl,
-                              bool record_refs_into_cset,
-                              uint worker_i) :
-  _g1(g1h), _g1_rem_set(rs), _from(NULL),
+G1UpdateRSOrPushRefOopClosure::G1UpdateRSOrPushRefOopClosure(G1CollectedHeap* g1h,
+                                                             G1ParPushHeapRSClosure* push_ref_cl,
+                                                             bool record_refs_into_cset,
+                                                             uint worker_i) :
+  _g1(g1h),
+  _from(NULL),
   _record_refs_into_cset(record_refs_into_cset),
-  _push_ref_cl(push_ref_cl), _worker_i(worker_i) { }
+  _has_refs_into_cset(false),
+  _push_ref_cl(push_ref_cl),
+  _worker_i(worker_i) { }
 
 // Returns true if the given card contains references that point
 // into the collection set, if we're checking for such references;
@@ -690,25 +681,14 @@
   assert(!dirty_region.is_empty(), "sanity");
 
   G1UpdateRSOrPushRefOopClosure update_rs_oop_cl(_g1,
-                                                 _g1->g1_rem_set(),
                                                  oops_in_heap_closure,
                                                  check_for_refs_into_cset,
                                                  worker_i);
   update_rs_oop_cl.set_from(r);
 
-  G1TriggerClosure trigger_cl;
-  FilterIntoCSClosure into_cs_cl(_g1, &trigger_cl);
-  G1InvokeIfNotTriggeredClosure invoke_cl(&trigger_cl, &into_cs_cl);
-  G1Mux2Closure mux(&invoke_cl, &update_rs_oop_cl);
-
-  FilterOutOfRegionClosure filter_then_update_rs_oop_cl(r,
-                        (check_for_refs_into_cset ?
-                                (OopClosure*)&mux :
-                                (OopClosure*)&update_rs_oop_cl));
-
   bool card_processed =
     r->oops_on_card_seq_iterate_careful(dirty_region,
-                                        &filter_then_update_rs_oop_cl);
+                                        &update_rs_oop_cl);
 
   // If unable to process the card then we encountered an unparsable
   // part of the heap (e.g. a partially allocated object) while
@@ -731,15 +711,15 @@
     _conc_refine_cards++;
   }
 
-  // This gets set to true if the card being refined has
-  // references that point into the collection set.
-  bool has_refs_into_cset = trigger_cl.triggered();
+  // This gets set to true if the card being refined has references that point
+  // into the collection set.
+  bool has_refs_into_cset = update_rs_oop_cl.has_refs_into_cset();
 
   // We should only be detecting that the card contains references
   // that point into the collection set if the current thread is
   // a GC worker thread.
   assert(!has_refs_into_cset || SafepointSynchronize::is_at_safepoint(),
-           "invalid result at non safepoint");
+         "invalid result at non safepoint");
 
   return has_refs_into_cset;
 }
--- a/hotspot/src/share/vm/gc/g1/g1RemSet.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1RemSet.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -149,18 +149,18 @@
   // If oops_in_heap_closure is not NULL, a true result is returned
   // if the given card contains oops that have references into the
   // current collection set.
-  virtual bool refine_card(jbyte* card_ptr,
-                           uint worker_i,
-                           G1ParPushHeapRSClosure* oops_in_heap_closure);
+  bool refine_card(jbyte* card_ptr,
+                   uint worker_i,
+                   G1ParPushHeapRSClosure* oops_in_heap_closure);
 
   // Print accumulated summary info from the start of the VM.
-  virtual void print_summary_info();
+  void print_summary_info();
 
   // Print accumulated summary info from the last time called.
-  virtual void print_periodic_summary_info(const char* header, uint period_count);
+  void print_periodic_summary_info(const char* header, uint period_count);
 
   // Prepare remembered set for verification.
-  virtual void prepare_for_verify();
+  void prepare_for_verify();
 
   size_t conc_refine_cards() const {
     return _conc_refine_cards;
--- a/hotspot/src/share/vm/gc/g1/g1RootClosures.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1RootClosures.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -59,7 +59,7 @@
 // The treatment of "weak" roots is selectable through the template parameter,
 // this is usually used to control unloading of classes and interned strings.
 template <G1Mark MarkWeak>
-class G1InitalMarkClosures : public G1EvacuationRootClosures {
+class G1InitialMarkClosures : public G1EvacuationRootClosures {
   G1SharedClosures<G1MarkFromRoot> _strong;
   G1SharedClosures<MarkWeak>       _weak;
 
@@ -74,8 +74,8 @@
   }
 
 public:
-  G1InitalMarkClosures(G1CollectedHeap* g1h,
-                       G1ParScanThreadState* pss) :
+  G1InitialMarkClosures(G1CollectedHeap* g1h,
+                        G1ParScanThreadState* pss) :
       _strong(g1h, pss, /* process_only_dirty_klasses */ false, /* must_claim_cld */ true),
       _weak(g1h, pss,   /* process_only_dirty_klasses */ false, /* must_claim_cld */ true) {}
 
@@ -118,9 +118,9 @@
 
   if (g1h->collector_state()->during_initial_mark_pause()) {
     if (ClassUnloadingWithConcurrentMark) {
-      res = new G1InitalMarkClosures<G1MarkPromotedFromRoot>(g1h, pss);
+      res = new G1InitialMarkClosures<G1MarkPromotedFromRoot>(g1h, pss);
     } else {
-      res = new G1InitalMarkClosures<G1MarkFromRoot>(g1h, pss);
+      res = new G1InitialMarkClosures<G1MarkFromRoot>(g1h, pss);
     }
   } else {
     res = new G1EvacuationClosures(g1h, pss, g1h->collector_state()->gcs_are_young());
--- a/hotspot/src/share/vm/gc/g1/g1_specialized_oop_closures.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1_specialized_oop_closures.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,14 +35,14 @@
 class G1ParScanClosure;
 class G1ParPushHeapRSClosure;
 
-class FilterOutOfRegionClosure;
+class G1UpdateRSOrPushRefOopClosure;
 class G1CMOopClosure;
 class G1RootRegionScanClosure;
 
 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_G1(f) \
       f(G1ParScanClosure,_nv)                      \
       f(G1ParPushHeapRSClosure,_nv)                \
-      f(FilterOutOfRegionClosure,_nv)              \
+      f(G1UpdateRSOrPushRefOopClosure,_nv)         \
       f(G1CMOopClosure,_nv)                        \
       f(G1RootRegionScanClosure,_nv)
 
--- a/hotspot/src/share/vm/gc/g1/heapRegion.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/heapRegion.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -55,10 +55,6 @@
   DirtyCardToOopClosure(hr, cl, precision, NULL),
   _hr(hr), _rs_scan(cl), _g1(g1) { }
 
-FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r,
-                                                   OopClosure* oc) :
-  _r_bottom(r->bottom()), _r_end(r->end()), _oc(oc) { }
-
 void HeapRegionDCTOC::walk_mem_region(MemRegion mr,
                                       HeapWord* bottom,
                                       HeapWord* top) {
@@ -267,6 +263,8 @@
   report_region_type_change(G1HeapRegionTraceType::ContinuesHumongous);
   _type.set_continues_humongous();
   _humongous_start_region = first_hr;
+
+  _bot_part.set_object_can_span(true);
 }
 
 void HeapRegion::clear_humongous() {
@@ -274,6 +272,8 @@
 
   assert(capacity() == HeapRegion::GrainBytes, "pre-condition");
   _humongous_start_region = NULL;
+
+  _bot_part.set_object_can_span(false);
 }
 
 HeapRegion::HeapRegion(uint hrm_index,
@@ -290,8 +290,7 @@
     _containing_set(NULL),
 #endif // ASSERT
      _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1),
-    _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0),
-    _predicted_bytes_to_copy(0)
+    _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0)
 {
   _rem_set = new HeapRegionRemSet(bot, this);
 
@@ -343,9 +342,7 @@
   }
 }
 
-void HeapRegion::note_self_forwarding_removal_end(bool during_initial_mark,
-                                                  bool during_conc_mark,
-                                                  size_t marked_bytes) {
+void HeapRegion::note_self_forwarding_removal_end(size_t marked_bytes) {
   assert(marked_bytes <= used(),
          "marked: " SIZE_FORMAT " used: " SIZE_FORMAT, marked_bytes, used());
   _prev_top_at_mark_start = top();
@@ -356,7 +353,7 @@
 // special handling for concurrent processing encountering an
 // in-progress allocation.
 static bool do_oops_on_card_in_humongous(MemRegion mr,
-                                         FilterOutOfRegionClosure* cl,
+                                         G1UpdateRSOrPushRefOopClosure* cl,
                                          HeapRegion* hr,
                                          G1CollectedHeap* g1h) {
   assert(hr->is_humongous(), "precondition");
@@ -397,7 +394,7 @@
 }
 
 bool HeapRegion::oops_on_card_seq_iterate_careful(MemRegion mr,
-                                                  FilterOutOfRegionClosure* cl) {
+                                                  G1UpdateRSOrPushRefOopClosure* cl) {
   assert(MemRegion(bottom(), end()).contains(mr), "Card region not in heap region");
   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 
@@ -483,7 +480,6 @@
 
 class VerifyStrongCodeRootOopClosure: public OopClosure {
   const HeapRegion* _hr;
-  nmethod* _nm;
   bool _failures;
   bool _has_oops_in_region;
 
@@ -510,7 +506,7 @@
   }
 
 public:
-  VerifyStrongCodeRootOopClosure(const HeapRegion* hr, nmethod* nm):
+  VerifyStrongCodeRootOopClosure(const HeapRegion* hr):
     _hr(hr), _failures(false), _has_oops_in_region(false) {}
 
   void do_oop(narrowOop* p) { do_oop_work(p); }
@@ -536,7 +532,7 @@
                               p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
         _failures = true;
       } else {
-        VerifyStrongCodeRootOopClosure oop_cl(_hr, nm);
+        VerifyStrongCodeRootOopClosure oop_cl(_hr);
         nm->oops_do(&oop_cl);
         if (!oop_cl.has_oops_in_region()) {
           log_error(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has nmethod " PTR_FORMAT " in its strong code roots with no pointers into region",
@@ -728,7 +724,6 @@
     Log(gc, verify) log;
     if (!oopDesc::is_null(heap_oop)) {
       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
-      bool failed = false;
       HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
       HeapRegion* to = _g1h->heap_region_containing(obj);
       if (from != NULL && to != NULL &&
@@ -763,13 +758,28 @@
           log.error("Obj head CTE = %d, field CTE = %d.", cv_obj, cv_field);
           log.error("----------");
           _failures = true;
-          if (!failed) _n_failures++;
+          _n_failures++;
         }
       }
     }
   }
 };
 
+// Closure that applies the given two closures in sequence.
+class G1Mux2Closure : public OopClosure {
+  OopClosure* _c1;
+  OopClosure* _c2;
+public:
+  G1Mux2Closure(OopClosure *c1, OopClosure *c2) { _c1 = c1; _c2 = c2; }
+  template <class T> inline void do_oop_work(T* p) {
+    // Apply first closure; then apply the second.
+    _c1->do_oop(p);
+    _c2->do_oop(p);
+  }
+  virtual inline void do_oop(oop* p) { do_oop_work(p); }
+  virtual inline void do_oop(narrowOop* p) { do_oop_work(p); }
+};
+
 // This really ought to be commoned up into OffsetTableContigSpace somehow.
 // We would need a mechanism to make that code skip dead objects.
 
--- a/hotspot/src/share/vm/gc/g1/heapRegion.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/heapRegion.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -311,10 +311,6 @@
   // for the collection set.
   double _predicted_elapsed_time_ms;
 
-  // The predicted number of bytes to copy that was added to
-  // the total value for the collection set.
-  size_t _predicted_bytes_to_copy;
-
  public:
   HeapRegion(uint hrm_index,
              G1BlockOffsetTable* bot,
@@ -554,9 +550,7 @@
 
   // Notify the region that we have finished processing self-forwarded
   // objects during evac failure handling.
-  void note_self_forwarding_removal_end(bool during_initial_mark,
-                                        bool during_conc_mark,
-                                        size_t marked_bytes);
+  void note_self_forwarding_removal_end(size_t marked_bytes);
 
   // Returns "false" iff no object in the region was allocated when the
   // last mark phase ended.
@@ -667,11 +661,10 @@
   // encountered; that only happens when invoked concurrently with the
   // mutator.
   bool oops_on_card_seq_iterate_careful(MemRegion mr,
-                                        FilterOutOfRegionClosure* cl);
+                                        G1UpdateRSOrPushRefOopClosure* cl);
 
   size_t recorded_rs_length() const        { return _recorded_rs_length; }
   double predicted_elapsed_time_ms() const { return _predicted_elapsed_time_ms; }
-  size_t predicted_bytes_to_copy() const   { return _predicted_bytes_to_copy; }
 
   void set_recorded_rs_length(size_t rs_length) {
     _recorded_rs_length = rs_length;
@@ -681,10 +674,6 @@
     _predicted_elapsed_time_ms = ms;
   }
 
-  void set_predicted_bytes_to_copy(size_t bytes) {
-    _predicted_bytes_to_copy = bytes;
-  }
-
   virtual CompactibleSpace* next_compaction_space() const;
 
   virtual void reset_after_compaction();
--- a/hotspot/src/share/vm/gc/g1/ptrQueue.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/ptrQueue.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@
 }
 
 void PtrQueue::flush_impl() {
-  if (!_permanent && _buf != NULL) {
+  if (_buf != NULL) {
     BufferNode* node = BufferNode::make_node_from_buffer(_buf, _index);
     if (is_empty()) {
       // No work to do.
--- a/hotspot/src/share/vm/gc/g1/ptrQueue.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/ptrQueue.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -69,7 +69,7 @@
   PtrQueueSet* qset() { return _qset; }
   bool is_permanent() const { return _permanent; }
 
-  // Process queue entries and release resources, if not permanent.
+  // Process queue entries and release resources.
   void flush_impl();
 
   // Initialize this queue to contain a null buffer, and be part of the
--- a/hotspot/src/share/vm/gc/parallel/mutableNUMASpace.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/parallel/mutableNUMASpace.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -30,11 +30,21 @@
 #include "runtime/atomic.hpp"
 #include "runtime/thread.inline.hpp"
 
-MutableNUMASpace::MutableNUMASpace(size_t alignment) : MutableSpace(alignment) {
+MutableNUMASpace::MutableNUMASpace(size_t alignment) : MutableSpace(alignment), _must_use_large_pages(false) {
   _lgrp_spaces = new (ResourceObj::C_HEAP, mtGC) GrowableArray<LGRPSpace*>(0, true);
   _page_size = os::vm_page_size();
   _adaptation_cycles = 0;
   _samples_count = 0;
+
+#ifdef LINUX
+  // Changing the page size can lead to freeing of memory. When using large pages
+  // and the memory has been both reserved and committed, Linux does not support
+  // freeing parts of it.
+    if (UseLargePages && !os::can_commit_large_page_memory()) {
+      _must_use_large_pages = true;
+    }
+#endif // LINUX
+
   update_layout(true);
 }
 
@@ -578,6 +588,10 @@
   // Try small pages if the chunk size is too small
   if (base_space_size_pages / lgrp_spaces()->length() == 0
       && page_size() > (size_t)os::vm_page_size()) {
+    // Changing the page size below can lead to freeing of memory. So we fail initialization.
+    if (_must_use_large_pages) {
+      vm_exit_during_initialization("Failed initializing NUMA with large pages. Too small heap size");
+    }
     set_page_size(os::vm_page_size());
     rounded_bottom = (HeapWord*)round_to((intptr_t) bottom(), page_size());
     rounded_end = (HeapWord*)round_down((intptr_t) end(), page_size());
--- a/hotspot/src/share/vm/gc/parallel/mutableNUMASpace.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/parallel/mutableNUMASpace.hpp	Thu Mar 16 16:40:41 2017 -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
@@ -145,6 +145,8 @@
   size_t _page_size;
   unsigned _adaptation_cycles, _samples_count;
 
+  bool _must_use_large_pages;
+
   void set_page_size(size_t psz)                     { _page_size = psz;          }
   size_t page_size() const                           { return _page_size;         }
 
--- a/hotspot/src/share/vm/gc/serial/markSweep.inline.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/serial/markSweep.inline.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,13 +30,12 @@
 #include "oops/markOop.inline.hpp"
 #include "oops/oop.inline.hpp"
 #if INCLUDE_ALL_GCS
-#include "gc/g1/g1MarkSweep.hpp"
+#include "gc/g1/g1Allocator.inline.hpp"
 #endif // INCLUDE_ALL_GCS
 
 inline bool MarkSweep::is_archive_object(oop object) {
 #if INCLUDE_ALL_GCS
-  return (G1MarkSweep::archive_check_enabled() &&
-          G1MarkSweep::in_archive_range(object));
+  return G1ArchiveAllocator::is_archive_object(object);
 #else
   return false;
 #endif
--- a/hotspot/src/share/vm/gc/shared/allocTracer.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/allocTracer.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,19 +28,19 @@
 #include "trace/tracing.hpp"
 #include "utilities/globalDefinitions.hpp"
 
-void AllocTracer::send_allocation_outside_tlab_event(KlassHandle klass, size_t alloc_size) {
+void AllocTracer::send_allocation_outside_tlab_event(Klass* klass, size_t alloc_size) {
   EventObjectAllocationOutsideTLAB event;
   if (event.should_commit()) {
-    event.set_objectClass(klass());
+    event.set_objectClass(klass);
     event.set_allocationSize(alloc_size);
     event.commit();
   }
 }
 
-void AllocTracer::send_allocation_in_new_tlab_event(KlassHandle klass, size_t tlab_size, size_t alloc_size) {
+void AllocTracer::send_allocation_in_new_tlab_event(Klass* klass, size_t tlab_size, size_t alloc_size) {
   EventObjectAllocationInNewTLAB event;
   if (event.should_commit()) {
-    event.set_objectClass(klass());
+    event.set_objectClass(klass);
     event.set_allocationSize(alloc_size);
     event.set_tlabSize(tlab_size);
     event.commit();
--- a/hotspot/src/share/vm/gc/shared/allocTracer.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/allocTracer.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,8 +30,8 @@
 
 class AllocTracer : AllStatic {
   public:
-    static void send_allocation_outside_tlab_event(KlassHandle klass, size_t alloc_size);
-    static void send_allocation_in_new_tlab_event(KlassHandle klass, size_t tlab_size, size_t alloc_size);
+    static void send_allocation_outside_tlab_event(Klass* klass, size_t alloc_size);
+    static void send_allocation_in_new_tlab_event(Klass* klass, size_t tlab_size, size_t alloc_size);
     static void send_allocation_requiring_gc_event(size_t size, uint gcId);
 };
 
--- a/hotspot/src/share/vm/gc/shared/cardTableRS.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/cardTableRS.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -282,7 +282,7 @@
 // cur-younger-gen                ==> cur_younger_gen
 // cur_youngergen_and_prev_nonclean_card ==> no change.
 void CardTableRS::write_ref_field_gc_par(void* field, oop new_val) {
-  jbyte* entry = _ct_bs->byte_for(field);
+  volatile jbyte* entry = _ct_bs->byte_for(field);
   do {
     jbyte entry_val = *entry;
     // We put this first because it's probably the most common case.
--- a/hotspot/src/share/vm/gc/shared/collectedHeap.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/collectedHeap.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -279,7 +279,7 @@
 }
 #endif
 
-HeapWord* CollectedHeap::allocate_from_tlab_slow(KlassHandle klass, Thread* thread, size_t size) {
+HeapWord* CollectedHeap::allocate_from_tlab_slow(Klass* klass, Thread* thread, size_t size) {
 
   // Retain tlab and allocate object in shared space if
   // the amount free in the tlab is too large to discard.
--- a/hotspot/src/share/vm/gc/shared/collectedHeap.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/collectedHeap.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -138,28 +138,28 @@
   virtual void resize_all_tlabs();
 
   // Allocate from the current thread's TLAB, with broken-out slow path.
-  inline static HeapWord* allocate_from_tlab(KlassHandle klass, Thread* thread, size_t size);
-  static HeapWord* allocate_from_tlab_slow(KlassHandle klass, Thread* thread, size_t size);
+  inline static HeapWord* allocate_from_tlab(Klass* klass, Thread* thread, size_t size);
+  static HeapWord* allocate_from_tlab_slow(Klass* klass, Thread* thread, size_t size);
 
   // Allocate an uninitialized block of the given size, or returns NULL if
   // this is impossible.
-  inline static HeapWord* common_mem_allocate_noinit(KlassHandle klass, size_t size, TRAPS);
+  inline static HeapWord* common_mem_allocate_noinit(Klass* klass, size_t size, TRAPS);
 
   // Like allocate_init, but the block returned by a successful allocation
   // is guaranteed initialized to zeros.
-  inline static HeapWord* common_mem_allocate_init(KlassHandle klass, size_t size, TRAPS);
+  inline static HeapWord* common_mem_allocate_init(Klass* klass, size_t size, TRAPS);
 
   // Helper functions for (VM) allocation.
-  inline static void post_allocation_setup_common(KlassHandle klass, HeapWord* obj);
-  inline static void post_allocation_setup_no_klass_install(KlassHandle klass,
+  inline static void post_allocation_setup_common(Klass* klass, HeapWord* obj);
+  inline static void post_allocation_setup_no_klass_install(Klass* klass,
                                                             HeapWord* objPtr);
 
-  inline static void post_allocation_setup_obj(KlassHandle klass, HeapWord* obj, int size);
+  inline static void post_allocation_setup_obj(Klass* klass, HeapWord* obj, int size);
 
-  inline static void post_allocation_setup_array(KlassHandle klass,
+  inline static void post_allocation_setup_array(Klass* klass,
                                                  HeapWord* obj, int length);
 
-  inline static void post_allocation_setup_class(KlassHandle klass, HeapWord* obj, int size);
+  inline static void post_allocation_setup_class(Klass* klass, HeapWord* obj, int size);
 
   // Clears an allocated object.
   inline static void init_obj(HeapWord* obj, size_t size);
@@ -299,10 +299,10 @@
   GCCause::Cause gc_cause() { return _gc_cause; }
 
   // General obj/array allocation facilities.
-  inline static oop obj_allocate(KlassHandle klass, int size, TRAPS);
-  inline static oop array_allocate(KlassHandle klass, int size, int length, TRAPS);
-  inline static oop array_allocate_nozero(KlassHandle klass, int size, int length, TRAPS);
-  inline static oop class_allocate(KlassHandle klass, int size, TRAPS);
+  inline static oop obj_allocate(Klass* klass, int size, TRAPS);
+  inline static oop array_allocate(Klass* klass, int size, int length, TRAPS);
+  inline static oop array_allocate_nozero(Klass* klass, int size, int length, TRAPS);
+  inline static oop class_allocate(Klass* klass, int size, TRAPS);
 
   // Raw memory allocation facilities
   // The obj and array allocate methods are covers for these methods.
--- a/hotspot/src/share/vm/gc/shared/collectedHeap.inline.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/collectedHeap.inline.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,26 +40,26 @@
 
 // Inline allocation implementations.
 
-void CollectedHeap::post_allocation_setup_common(KlassHandle klass,
+void CollectedHeap::post_allocation_setup_common(Klass* klass,
                                                  HeapWord* obj_ptr) {
   post_allocation_setup_no_klass_install(klass, obj_ptr);
   oop obj = (oop)obj_ptr;
 #if ! INCLUDE_ALL_GCS
-  obj->set_klass(klass());
+  obj->set_klass(klass);
 #else
   // Need a release store to ensure array/class length, mark word, and
   // object zeroing are visible before setting the klass non-NULL, for
   // concurrent collectors.
-  obj->release_set_klass(klass());
+  obj->release_set_klass(klass);
 #endif
 }
 
-void CollectedHeap::post_allocation_setup_no_klass_install(KlassHandle klass,
+void CollectedHeap::post_allocation_setup_no_klass_install(Klass* klass,
                                                            HeapWord* obj_ptr) {
   oop obj = (oop)obj_ptr;
 
   assert(obj != NULL, "NULL object pointer");
-  if (UseBiasedLocking && (klass() != NULL)) {
+  if (UseBiasedLocking && (klass != NULL)) {
     obj->set_mark(klass->prototype_header());
   } else {
     // May be bootstrapping
@@ -68,7 +68,7 @@
 }
 
 // Support for jvmti and dtrace
-inline void post_allocation_notify(KlassHandle klass, oop obj, int size) {
+inline void post_allocation_notify(Klass* klass, oop obj, int size) {
   // support low memory notifications (no-op if not enabled)
   LowMemoryDetector::detect_low_memory_for_collected_pools();
 
@@ -77,13 +77,13 @@
 
   if (DTraceAllocProbes) {
     // support for Dtrace object alloc event (no-op most of the time)
-    if (klass() != NULL && klass()->name() != NULL) {
+    if (klass != NULL && klass->name() != NULL) {
       SharedRuntime::dtrace_object_alloc(obj, size);
     }
   }
 }
 
-void CollectedHeap::post_allocation_setup_obj(KlassHandle klass,
+void CollectedHeap::post_allocation_setup_obj(Klass* klass,
                                               HeapWord* obj_ptr,
                                               int size) {
   post_allocation_setup_common(klass, obj_ptr);
@@ -94,7 +94,7 @@
   post_allocation_notify(klass, obj, size);
 }
 
-void CollectedHeap::post_allocation_setup_class(KlassHandle klass,
+void CollectedHeap::post_allocation_setup_class(Klass* klass,
                                                 HeapWord* obj_ptr,
                                                 int size) {
   // Set oop_size field before setting the _klass field because a
@@ -110,7 +110,7 @@
   post_allocation_notify(klass, new_cls, size);
 }
 
-void CollectedHeap::post_allocation_setup_array(KlassHandle klass,
+void CollectedHeap::post_allocation_setup_array(Klass* klass,
                                                 HeapWord* obj_ptr,
                                                 int length) {
   // Set array length before setting the _klass field because a
@@ -125,7 +125,7 @@
   post_allocation_notify(klass, new_obj, new_obj->size());
 }
 
-HeapWord* CollectedHeap::common_mem_allocate_noinit(KlassHandle klass, size_t size, TRAPS) {
+HeapWord* CollectedHeap::common_mem_allocate_noinit(Klass* klass, size_t size, TRAPS) {
 
   // Clear unhandled oops for memory allocation.  Memory allocation might
   // not take out a lock if from tlab, so clear here.
@@ -186,13 +186,13 @@
   }
 }
 
-HeapWord* CollectedHeap::common_mem_allocate_init(KlassHandle klass, size_t size, TRAPS) {
+HeapWord* CollectedHeap::common_mem_allocate_init(Klass* klass, size_t size, TRAPS) {
   HeapWord* obj = common_mem_allocate_noinit(klass, size, CHECK_NULL);
   init_obj(obj, size);
   return obj;
 }
 
-HeapWord* CollectedHeap::allocate_from_tlab(KlassHandle klass, Thread* thread, size_t size) {
+HeapWord* CollectedHeap::allocate_from_tlab(Klass* klass, Thread* thread, size_t size) {
   assert(UseTLAB, "should use UseTLAB");
 
   HeapWord* obj = thread->tlab().allocate(size);
@@ -211,7 +211,7 @@
   Copy::fill_to_aligned_words(obj + hs, size - hs);
 }
 
-oop CollectedHeap::obj_allocate(KlassHandle klass, int size, TRAPS) {
+oop CollectedHeap::obj_allocate(Klass* klass, int size, TRAPS) {
   debug_only(check_for_valid_allocation_state());
   assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
   assert(size >= 0, "int won't convert to size_t");
@@ -221,7 +221,7 @@
   return (oop)obj;
 }
 
-oop CollectedHeap::class_allocate(KlassHandle klass, int size, TRAPS) {
+oop CollectedHeap::class_allocate(Klass* klass, int size, TRAPS) {
   debug_only(check_for_valid_allocation_state());
   assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
   assert(size >= 0, "int won't convert to size_t");
@@ -231,7 +231,7 @@
   return (oop)obj;
 }
 
-oop CollectedHeap::array_allocate(KlassHandle klass,
+oop CollectedHeap::array_allocate(Klass* klass,
                                   int size,
                                   int length,
                                   TRAPS) {
@@ -244,7 +244,7 @@
   return (oop)obj;
 }
 
-oop CollectedHeap::array_allocate_nozero(KlassHandle klass,
+oop CollectedHeap::array_allocate_nozero(Klass* klass,
                                          int size,
                                          int length,
                                          TRAPS) {
--- a/hotspot/src/share/vm/gc/shared/plab.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/plab.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -154,30 +154,33 @@
   assert(is_object_aligned(max_size()) && min_size() <= max_size(),
          "PLAB clipping computation may be incorrect");
 
-  if (_allocated == 0) {
-    assert(_unused == 0,
-           "Inconsistency in PLAB stats: "
-           "_allocated: " SIZE_FORMAT ", "
-           "_wasted: " SIZE_FORMAT ", "
-           "_unused: " SIZE_FORMAT ", "
-           "_undo_wasted: " SIZE_FORMAT,
-           _allocated, _wasted, _unused, _undo_wasted);
+  assert(_allocated != 0 || _unused == 0,
+         "Inconsistency in PLAB stats: "
+         "_allocated: " SIZE_FORMAT ", "
+         "_wasted: " SIZE_FORMAT ", "
+         "_unused: " SIZE_FORMAT ", "
+         "_undo_wasted: " SIZE_FORMAT,
+         _allocated, _wasted, _unused, _undo_wasted);
 
-    _allocated = 1;
-  }
-  double wasted_frac    = (double)_unused / (double)_allocated;
+  size_t plab_sz = compute_desired_plab_sz();
+  // Take historical weighted average
+  _filter.sample(plab_sz);
+  _desired_net_plab_sz = MAX2(min_size(), (size_t)_filter.average());
+
+  log_sizing(plab_sz, _desired_net_plab_sz);
+  // Clear accumulators for next round
+  reset();
+}
+
+size_t PLABStats::compute_desired_plab_sz() {
+  size_t allocated      = MAX2(_allocated, size_t(1));
+  double wasted_frac    = (double)_unused / (double)allocated;
   size_t target_refills = (size_t)((wasted_frac * TargetSurvivorRatio) / TargetPLABWastePct);
   if (target_refills == 0) {
     target_refills = 1;
   }
-  size_t used = _allocated - _wasted - _unused;
+  size_t used = allocated - _wasted - _unused;
   // Assumed to have 1 gc worker thread
   size_t recent_plab_sz = used / target_refills;
-  // Take historical weighted average
-  _filter.sample(recent_plab_sz);
-  _desired_net_plab_sz = MAX2(min_size(), (size_t)_filter.average());
-
-  log_sizing(recent_plab_sz, _desired_net_plab_sz);
-
-  reset();
+  return recent_plab_sz;
 }
--- a/hotspot/src/share/vm/gc/shared/plab.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/gc/shared/plab.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -165,6 +165,10 @@
 
   virtual void log_plab_allocation();
   virtual void log_sizing(size_t calculated, size_t net_desired);
+
+  // helper for adjust_desired_plab_sz().
+  virtual size_t compute_desired_plab_sz();
+
  public:
   PLABStats(const char* description, size_t desired_net_plab_sz_, unsigned wt) :
     _description(description),
@@ -197,7 +201,7 @@
 
   // Updates the current desired PLAB size. Computes the new desired PLAB size with one gc worker thread,
   // updates _desired_plab_sz and clears sensor accumulators.
-  virtual void adjust_desired_plab_sz();
+  void adjust_desired_plab_sz();
 
   inline void add_allocated(size_t v);
 
--- a/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -138,8 +138,8 @@
 // Allocation
 
 IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, ConstantPool* pool, int index))
-  Klass* k_oop = pool->klass_at(index, CHECK);
-  instanceKlassHandle klass (THREAD, k_oop);
+  Klass* k = pool->klass_at(index, CHECK);
+  InstanceKlass* klass = InstanceKlass::cast(k);
 
   // Make sure we are not instantiating an abstract klass
   klass->check_valid_for_instantiation(true, CHECK);
@@ -461,8 +461,8 @@
     Exceptions::debug_check_abort(h_exception);
 
     // exception handler lookup
-    KlassHandle h_klass(THREAD, h_exception->klass());
-    handler_bci = Method::fast_exception_handler_bci_for(h_method, h_klass, current_bci, THREAD);
+    Klass* klass = h_exception->klass();
+    handler_bci = Method::fast_exception_handler_bci_for(h_method, klass, current_bci, THREAD);
     if (HAS_PENDING_EXCEPTION) {
       // We threw an exception while trying to find the exception handler.
       // Transfer the new exception to the exception handle which will
@@ -1070,15 +1070,15 @@
     // non-static field accessors have an object, but we need a handle
     h_obj = Handle(thread, obj);
   }
-  instanceKlassHandle h_cp_entry_f1(thread, (Klass*)cp_entry->f1_as_klass());
-  jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2_as_index(), is_static);
-  JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid);
+  InstanceKlass* cp_entry_f1 = InstanceKlass::cast(cp_entry->f1_as_klass());
+  jfieldID fid = jfieldIDWorkaround::to_jfieldID(cp_entry_f1, cp_entry->f2_as_index(), is_static);
+  JvmtiExport::post_field_access(thread, method(thread), bcp(thread), cp_entry_f1, h_obj, fid);
 IRT_END
 
 IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread,
   oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value))
 
-  Klass* k = (Klass*)cp_entry->f1_as_klass();
+  Klass* k = cp_entry->f1_as_klass();
 
   // check the access_flags for the field in the klass
   InstanceKlass* ik = InstanceKlass::cast(k);
@@ -1103,8 +1103,7 @@
   bool is_static = (obj == NULL);
 
   HandleMark hm(thread);
-  instanceKlassHandle h_klass(thread, k);
-  jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2_as_index(), is_static);
+  jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, cp_entry->f2_as_index(), is_static);
   jvalue fvalue;
 #ifdef _LP64
   fvalue = *value;
@@ -1128,7 +1127,7 @@
     h_obj = Handle(thread, obj);
   }
 
-  JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj,
+  JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), ik, h_obj,
                                            fid, sig_type, &fvalue);
 IRT_END
 
--- a/hotspot/src/share/vm/interpreter/linkResolver.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/linkResolver.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -55,14 +55,14 @@
 // Implementation of CallInfo
 
 
-void CallInfo::set_static(KlassHandle resolved_klass, const methodHandle& resolved_method, TRAPS) {
+void CallInfo::set_static(Klass* resolved_klass, const methodHandle& resolved_method, TRAPS) {
   int vtable_index = Method::nonvirtual_vtable_index;
   set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
 }
 
 
-void CallInfo::set_interface(KlassHandle resolved_klass,
-                             KlassHandle selected_klass,
+void CallInfo::set_interface(Klass* resolved_klass,
+                             Klass* selected_klass,
                              const methodHandle& resolved_method,
                              const methodHandle& selected_method,
                              int itable_index, TRAPS) {
@@ -75,8 +75,8 @@
   set_common(resolved_klass, selected_klass, resolved_method, selected_method, CallInfo::itable_call, itable_index, CHECK);
 }
 
-void CallInfo::set_virtual(KlassHandle resolved_klass,
-                           KlassHandle selected_klass,
+void CallInfo::set_virtual(Klass* resolved_klass,
+                           Klass* selected_klass,
                            const methodHandle& resolved_method,
                            const methodHandle& selected_method,
                            int vtable_index, TRAPS) {
@@ -93,7 +93,7 @@
   set_handle(SystemDictionary::MethodHandle_klass(), resolved_method, resolved_appendix, resolved_method_type, CHECK);
 }
 
-void CallInfo::set_handle(KlassHandle resolved_klass,
+void CallInfo::set_handle(Klass* resolved_klass,
                           const methodHandle& resolved_method,
                           Handle resolved_appendix,
                           Handle resolved_method_type, TRAPS) {
@@ -110,8 +110,8 @@
   _resolved_method_type = resolved_method_type;
 }
 
-void CallInfo::set_common(KlassHandle resolved_klass,
-                          KlassHandle selected_klass,
+void CallInfo::set_common(Klass* resolved_klass,
+                          Klass* selected_klass,
                           const methodHandle& resolved_method,
                           const methodHandle& selected_method,
                           CallKind kind,
@@ -162,8 +162,8 @@
 
 #ifdef ASSERT
     // Ensure that this is really the case.
-    KlassHandle object_klass = SystemDictionary::Object_klass();
-    Method * object_resolved_method = object_klass()->vtable()->method_at(index);
+    Klass* object_klass = SystemDictionary::Object_klass();
+    Method * object_resolved_method = object_klass->vtable()->method_at(index);
     assert(object_resolved_method->name() == resolved_method->name(),
       "Object and interface method names should match at vtable index %d, %s != %s",
       index, object_resolved_method->name()->as_C_string(), resolved_method->name()->as_C_string());
@@ -225,14 +225,13 @@
 
 LinkInfo::LinkInfo(const constantPoolHandle& pool, int index, methodHandle current_method, TRAPS) {
    // resolve klass
-  Klass* result = pool->klass_ref_at(index, CHECK);
-  _resolved_klass = KlassHandle(THREAD, result);
+  _resolved_klass = pool->klass_ref_at(index, CHECK);
 
   // Get name, signature, and static klass
   _name          = pool->name_ref_at(index);
   _signature     = pool->signature_ref_at(index);
   _tag           = pool->tag_ref_at(index);
-  _current_klass = KlassHandle(THREAD, pool->pool_holder());
+  _current_klass = pool->pool_holder();
   _current_method = current_method;
 
   // Coming from the constant pool always checks access
@@ -241,14 +240,13 @@
 
 LinkInfo::LinkInfo(const constantPoolHandle& pool, int index, TRAPS) {
    // resolve klass
-  Klass* result = pool->klass_ref_at(index, CHECK);
-  _resolved_klass = KlassHandle(THREAD, result);
+  _resolved_klass = pool->klass_ref_at(index, CHECK);
 
   // Get name, signature, and static klass
   _name          = pool->name_ref_at(index);
   _signature     = pool->signature_ref_at(index);
   _tag           = pool->tag_ref_at(index);
-  _current_klass = KlassHandle(THREAD, pool->pool_holder());
+  _current_klass = pool->pool_holder();
   _current_method = methodHandle();
 
   // Coming from the constant pool always checks access
@@ -256,7 +254,7 @@
 }
 
 char* LinkInfo::method_string() const {
-  return Method::name_and_sig_as_C_string(_resolved_klass(), _name, _signature);
+  return Method::name_and_sig_as_C_string(_resolved_klass, _name, _signature);
 }
 
 #ifndef PRODUCT
@@ -266,19 +264,21 @@
                 _resolved_klass->name()->as_C_string(),
                 _name->as_C_string(),
                 _signature->as_C_string(),
-                _current_klass.is_null() ? "(none)" : _current_klass->name()->as_C_string(),
+                _current_klass == NULL ? "(none)" : _current_klass->name()->as_C_string(),
                 _check_access ? "true" : "false");
 }
 #endif // PRODUCT
 //------------------------------------------------------------------------------------------------------------------------
 // Klass resolution
 
-void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
+void LinkResolver::check_klass_accessability(Klass* ref_klass, Klass* sel_klass, TRAPS) {
   Reflection::VerifyClassAccessResults vca_result =
-    Reflection::verify_class_access(ref_klass(), sel_klass(), true);
+    Reflection::verify_class_access(ref_klass, InstanceKlass::cast(sel_klass), true);
   if (vca_result != Reflection::ACCESS_OK) {
     ResourceMark rm(THREAD);
-    char* msg = Reflection::verify_class_access_msg(ref_klass(), sel_klass(), vca_result);
+    char* msg = Reflection::verify_class_access_msg(ref_klass,
+                                                    InstanceKlass::cast(sel_klass),
+                                                    vca_result);
     if (msg == NULL) {
       Exceptions::fthrow(
         THREAD_AND_LOCATION,
@@ -306,7 +306,7 @@
 methodHandle LinkResolver::lookup_method_in_klasses(const LinkInfo& link_info,
                                                     bool checkpolymorphism,
                                                     bool in_imethod_resolve, TRAPS) {
-  KlassHandle klass = link_info.resolved_klass();
+  Klass* klass = link_info.resolved_klass();
   Symbol* name = link_info.name();
   Symbol* signature = link_info.signature();
 
@@ -318,7 +318,7 @@
     return methodHandle(THREAD, result);
   }
 
-  InstanceKlass* ik = InstanceKlass::cast(klass());
+  InstanceKlass* ik = InstanceKlass::cast(klass);
 
   // JDK 8, JVMS 5.4.3.4: Interface method resolution should
   // ignore static and non-public methods of java.lang.Object,
@@ -356,7 +356,7 @@
 
 // returns first instance method
 // Looks up method in classes, then looks up local default methods
-methodHandle LinkResolver::lookup_instance_method_in_klasses(KlassHandle klass,
+methodHandle LinkResolver::lookup_instance_method_in_klasses(Klass* klass,
                                                              Symbol* name,
                                                              Symbol* signature, TRAPS) {
   Method* result = klass->uncached_lookup_method(name, signature, Klass::find_overpass);
@@ -372,7 +372,7 @@
   }
 
   if (result == NULL) {
-    Array<Method*>* default_methods = InstanceKlass::cast(klass())->default_methods();
+    Array<Method*>* default_methods = InstanceKlass::cast(klass)->default_methods();
     if (default_methods != NULL) {
       result = InstanceKlass::find_method(default_methods, name, signature);
       assert(result == NULL || !result->is_static(), "static defaults not allowed");
@@ -381,13 +381,13 @@
   return methodHandle(THREAD, result);
 }
 
-int LinkResolver::vtable_index_of_interface_method(KlassHandle klass,
+int LinkResolver::vtable_index_of_interface_method(Klass* klass,
                                                    const methodHandle& resolved_method) {
 
   int vtable_index = Method::invalid_vtable_index;
   Symbol* name = resolved_method->name();
   Symbol* signature = resolved_method->signature();
-  InstanceKlass* ik = InstanceKlass::cast(klass());
+  InstanceKlass* ik = InstanceKlass::cast(klass);
 
   // First check in default method array
   if (!resolved_method->is_abstract() && ik->default_methods() != NULL) {
@@ -408,7 +408,7 @@
 }
 
 methodHandle LinkResolver::lookup_method_in_interfaces(const LinkInfo& cp_info, TRAPS) {
-  InstanceKlass *ik = InstanceKlass::cast(cp_info.resolved_klass()());
+  InstanceKlass *ik = InstanceKlass::cast(cp_info.resolved_klass());
 
   // Specify 'true' in order to skip default methods when searching the
   // interfaces.  Function lookup_method_in_klasses() already looked for
@@ -423,7 +423,7 @@
                                              Handle *appendix_result_or_null,
                                              Handle *method_type_result,
                                              TRAPS) {
-  KlassHandle klass = link_info.resolved_klass();
+  Klass* klass = link_info.resolved_klass();
   Symbol* name = link_info.name();
   Symbol* full_signature = link_info.signature();
 
@@ -434,8 +434,8 @@
                   vmIntrinsics::name_at(iid), klass->external_name(),
                   name->as_C_string(), full_signature->as_C_string());
   }
-  if ((klass() == SystemDictionary::MethodHandle_klass() ||
-       klass() == SystemDictionary::VarHandle_klass()) &&
+  if ((klass == SystemDictionary::MethodHandle_klass() ||
+       klass == SystemDictionary::VarHandle_klass()) &&
       iid != vmIntrinsics::_none) {
     if (MethodHandles::is_signature_polymorphic_intrinsic(iid)) {
       // Most of these do not need an up-call to Java to resolve, so can be done anywhere.
@@ -529,9 +529,9 @@
   return NULL;
 }
 
-void LinkResolver::check_method_accessability(KlassHandle ref_klass,
-                                              KlassHandle resolved_klass,
-                                              KlassHandle sel_klass,
+void LinkResolver::check_method_accessability(Klass* ref_klass,
+                                              Klass* resolved_klass,
+                                              Klass* sel_klass,
                                               const methodHandle& sel_method,
                                               TRAPS) {
 
@@ -545,7 +545,7 @@
   // We'll check for the method name first, as that's most likely
   // to be false (so we'll short-circuit out of these tests).
   if (sel_method->name() == vmSymbols::clone_name() &&
-      sel_klass() == SystemDictionary::Object_klass() &&
+      sel_klass == SystemDictionary::Object_klass() &&
       resolved_klass->is_array_klass()) {
     // We need to change "protected" to "public".
     assert(flags.is_protected(), "clone not protected?");
@@ -556,9 +556,9 @@
   }
 //  assert(extra_arg_result_or_null != NULL, "must be able to return extra argument");
 
-  if (!Reflection::verify_field_access(ref_klass(),
-                                       resolved_klass(),
-                                       sel_klass(),
+  if (!Reflection::verify_field_access(ref_klass,
+                                       resolved_klass,
+                                       sel_klass,
                                        flags,
                                        true)) {
     ResourceMark rm(THREAD);
@@ -584,22 +584,21 @@
   // It appears to fail when applied to an invokeinterface call site.
   // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points.
   // resolve klass
-  KlassHandle resolved_klass;
   if (code == Bytecodes::_invokedynamic) {
-    resolved_klass = SystemDictionary::MethodHandle_klass();
+    Klass* resolved_klass = SystemDictionary::MethodHandle_klass();
     Symbol* method_name = vmSymbols::invoke_name();
     Symbol* method_signature = pool->signature_ref_at(index);
-    KlassHandle  current_klass(THREAD, pool->pool_holder());
+    Klass*  current_klass = pool->pool_holder();
     LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass);
     return resolve_method(link_info, code, THREAD);
   }
 
   LinkInfo link_info(pool, index, methodHandle(), CHECK_NULL);
-  resolved_klass = link_info.resolved_klass();
+  Klass* resolved_klass = link_info.resolved_klass();
 
   if (pool->has_preresolution()
-      || (resolved_klass() == SystemDictionary::MethodHandle_klass() &&
-          MethodHandles::is_signature_polymorphic_name(resolved_klass(), link_info.name()))) {
+      || (resolved_klass == SystemDictionary::MethodHandle_klass() &&
+          MethodHandles::is_signature_polymorphic_name(resolved_klass, link_info.name()))) {
     Method* result = ConstantPool::method_at_if_loaded(pool, index);
     if (result != NULL) {
       return methodHandle(THREAD, result);
@@ -650,8 +649,8 @@
 }
 
 void LinkResolver::check_field_loader_constraints(Symbol* field, Symbol* sig,
-                                                  KlassHandle current_klass,
-                                                  KlassHandle sel_klass, TRAPS) {
+                                                  Klass* current_klass,
+                                                  Klass* sel_klass, TRAPS) {
   Handle ref_loader(THREAD, current_klass->class_loader());
   Handle sel_loader(THREAD, sel_klass->class_loader());
 
@@ -684,14 +683,14 @@
                                           Bytecodes::Code code, TRAPS) {
 
   Handle nested_exception;
-  KlassHandle resolved_klass = link_info.resolved_klass();
+  Klass* resolved_klass = link_info.resolved_klass();
 
   // 1. For invokevirtual, cannot call an interface method
   if (code == Bytecodes::_invokevirtual && resolved_klass->is_interface()) {
     ResourceMark rm(THREAD);
     char buf[200];
     jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected",
-        resolved_klass()->external_name());
+        resolved_klass->external_name());
     THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
   }
 
@@ -725,21 +724,21 @@
   if (resolved_method.is_null()) {
     ResourceMark rm(THREAD);
     THROW_MSG_CAUSE_(vmSymbols::java_lang_NoSuchMethodError(),
-                    Method::name_and_sig_as_C_string(resolved_klass(),
+                    Method::name_and_sig_as_C_string(resolved_klass,
                                                      link_info.name(),
                                                      link_info.signature()),
                     nested_exception, NULL);
   }
 
-  // 6. access checks, access checking may be turned off when calling from within the VM.
-  KlassHandle current_klass = link_info.current_klass();
+  // 5. access checks, access checking may be turned off when calling from within the VM.
+  Klass* current_klass = link_info.current_klass();
   if (link_info.check_access()) {
-    assert(current_klass.not_null() , "current_klass should not be null");
+    assert(current_klass != NULL , "current_klass should not be null");
 
     // check if method can be accessed by the referring class
     check_method_accessability(current_klass,
                                resolved_klass,
-                               KlassHandle(THREAD, resolved_method->method_holder()),
+                               resolved_method->method_holder(),
                                resolved_method,
                                CHECK_NULL);
 
@@ -751,8 +750,8 @@
 }
 
 static void trace_method_resolution(const char* prefix,
-                                    KlassHandle klass,
-                                    KlassHandle resolved_klass,
+                                    Klass* klass,
+                                    Klass* resolved_klass,
                                     const methodHandle& method,
                                     bool logitables,
                                     int index = -1) {
@@ -766,9 +765,9 @@
   }
   st->print("%s%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ",
             prefix,
-            (klass.is_null() ? "<NULL>" : klass->internal_name()),
-            (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()),
-            Method::name_and_sig_as_C_string(resolved_klass(),
+            (klass == NULL ? "<NULL>" : klass->internal_name()),
+            (resolved_klass == NULL ? "<NULL>" : resolved_klass->internal_name()),
+            Method::name_and_sig_as_C_string(resolved_klass,
                                              method->name(),
                                              method->signature()),
             method->method_holder()->internal_name());
@@ -783,13 +782,13 @@
 // Do linktime resolution of a method in the interface within the context of the specied bytecode.
 methodHandle LinkResolver::resolve_interface_method(const LinkInfo& link_info, Bytecodes::Code code, TRAPS) {
 
-  KlassHandle resolved_klass = link_info.resolved_klass();
+  Klass* resolved_klass = link_info.resolved_klass();
 
   // check if klass is interface
   if (!resolved_klass->is_interface()) {
     ResourceMark rm(THREAD);
     char buf[200];
-    jio_snprintf(buf, sizeof(buf), "Found class %s, but interface was expected", resolved_klass()->external_name());
+    jio_snprintf(buf, sizeof(buf), "Found class %s, but interface was expected", resolved_klass->external_name());
     THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
   }
 
@@ -814,21 +813,21 @@
     // no method found
     ResourceMark rm(THREAD);
     THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(),
-                   Method::name_and_sig_as_C_string(resolved_klass(),
+                   Method::name_and_sig_as_C_string(resolved_klass,
                                                     link_info.name(),
                                                     link_info.signature()));
   }
 
   if (link_info.check_access()) {
     // JDK8 adds non-public interface methods, and accessability check requirement
-    KlassHandle current_klass = link_info.current_klass();
+    Klass* current_klass = link_info.current_klass();
 
-    assert(current_klass.not_null() , "current_klass should not be null");
+    assert(current_klass != NULL , "current_klass should not be null");
 
     // check if method can be accessed by the referring class
     check_method_accessability(current_klass,
                                resolved_klass,
-                               KlassHandle(THREAD, resolved_method->method_holder()),
+                               resolved_method->method_holder(),
                                resolved_method,
                                CHECK_NULL);
 
@@ -839,7 +838,7 @@
     ResourceMark rm(THREAD);
     char buf[200];
     jio_snprintf(buf, sizeof(buf), "Expected instance not static method %s",
-                 Method::name_and_sig_as_C_string(resolved_klass(),
+                 Method::name_and_sig_as_C_string(resolved_klass,
                  resolved_method->name(), resolved_method->signature()));
     THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
   }
@@ -848,12 +847,12 @@
     ResourceMark rm(THREAD);
     char buf[200];
 
-    KlassHandle current_klass = link_info.current_klass();
+    Klass* current_klass = link_info.current_klass();
     jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokeinterface: method %s, caller-class:%s",
-                 Method::name_and_sig_as_C_string(resolved_klass(),
+                 Method::name_and_sig_as_C_string(resolved_klass,
                                                   resolved_method->name(),
                                                   resolved_method->signature()),
-                                                  (current_klass.is_null() ? "<NULL>" : current_klass->internal_name()));
+                                                  (current_klass == NULL ? "<NULL>" : current_klass->internal_name()));
      THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
   }
 
@@ -871,14 +870,14 @@
 //------------------------------------------------------------------------------------------------------------------------
 // Field resolution
 
-void LinkResolver::check_field_accessability(KlassHandle ref_klass,
-                                             KlassHandle resolved_klass,
-                                             KlassHandle sel_klass,
+void LinkResolver::check_field_accessability(Klass* ref_klass,
+                                             Klass* resolved_klass,
+                                             Klass* sel_klass,
                                              const fieldDescriptor& fd,
                                              TRAPS) {
-  if (!Reflection::verify_field_access(ref_klass(),
-                                       resolved_klass(),
-                                       sel_klass(),
+  if (!Reflection::verify_field_access(ref_klass,
+                                       resolved_klass,
+                                       sel_klass,
                                        fd.access_flags(),
                                        true)) {
     ResourceMark rm(THREAD);
@@ -911,19 +910,19 @@
   bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic);
   bool is_put    = (byte == Bytecodes::_putfield  || byte == Bytecodes::_putstatic || byte == Bytecodes::_nofast_putfield);
   // Check if there's a resolved klass containing the field
-  KlassHandle resolved_klass = link_info.resolved_klass();
+  Klass* resolved_klass = link_info.resolved_klass();
   Symbol* field = link_info.name();
   Symbol* sig = link_info.signature();
 
-  if (resolved_klass.is_null()) {
+  if (resolved_klass == NULL) {
     ResourceMark rm(THREAD);
     THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
   }
 
   // Resolve instance field
-  KlassHandle sel_klass(THREAD, resolved_klass->find_field(field, sig, &fd));
+  Klass* sel_klass = resolved_klass->find_field(field, sig, &fd);
   // check if field exists; i.e., if a klass containing the field def has been selected
-  if (sel_klass.is_null()) {
+  if (sel_klass == NULL) {
     ResourceMark rm(THREAD);
     THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
   }
@@ -933,14 +932,14 @@
     return;
 
   // check access
-  KlassHandle current_klass = link_info.current_klass();
+  Klass* current_klass = link_info.current_klass();
   check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK);
 
   // check for errors
   if (is_static != fd.is_static()) {
     ResourceMark rm(THREAD);
     char msg[200];
-    jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string());
+    jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass->external_name(), fd.name()->as_C_string());
     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg);
   }
 
@@ -952,10 +951,10 @@
     ResourceMark rm(THREAD);
     stringStream ss;
 
-    if (sel_klass() != current_klass()) {
+    if (sel_klass != current_klass) {
       ss.print("Update to %s final field %s.%s attempted from a different class (%s) than the field's declaring class",
-                is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string(),
-                current_klass()->external_name());
+                is_static ? "static" : "non-static", resolved_klass->external_name(), fd.name()->as_C_string(),
+                current_klass->external_name());
       THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), ss.as_string());
     }
 
@@ -971,7 +970,7 @@
 
       if (is_initialized_static_final_update || is_initialized_instance_final_update) {
         ss.print("Update to %s final field %s.%s attempted from a different method (%s) than the initializer method %s ",
-                 is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string(),
+                 is_static ? "static" : "non-static", resolved_klass->external_name(), fd.name()->as_C_string(),
                  m()->name()->as_C_string(),
                  is_static ? "<clinit>" : "<init>");
         THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), ss.as_string());
@@ -989,7 +988,7 @@
     sel_klass->initialize(CHECK);
   }
 
-  if (sel_klass() != current_klass()) {
+  if (sel_klass != current_klass) {
     check_field_loader_constraints(field, sig, current_klass, sel_klass, CHECK);
   }
 
@@ -1015,7 +1014,7 @@
   methodHandle resolved_method = linktime_resolve_static_method(link_info, CHECK);
 
   // The resolved class can change as a result of this resolution.
-  KlassHandle resolved_klass(THREAD, resolved_method->method_holder());
+  Klass* resolved_klass = resolved_method->method_holder();
 
   // Initialize klass (this should only happen if everything is ok)
   if (initialize_class && resolved_klass->should_be_initialized()) {
@@ -1034,7 +1033,7 @@
 // throws linktime exceptions
 methodHandle LinkResolver::linktime_resolve_static_method(const LinkInfo& link_info, TRAPS) {
 
-  KlassHandle resolved_klass = link_info.resolved_klass();
+  Klass* resolved_klass = link_info.resolved_klass();
   methodHandle resolved_method;
   if (!resolved_klass->is_interface()) {
     resolved_method = resolve_method(link_info, Bytecodes::_invokestatic, CHECK_NULL);
@@ -1047,7 +1046,7 @@
   if (!resolved_method->is_static()) {
     ResourceMark rm(THREAD);
     char buf[200];
-    jio_snprintf(buf, sizeof(buf), "Expected static method %s", Method::name_and_sig_as_C_string(resolved_klass(),
+    jio_snprintf(buf, sizeof(buf), "Expected static method %s", Method::name_and_sig_as_C_string(resolved_klass,
                                                       resolved_method->name(),
                                                       resolved_method->signature()));
     THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
@@ -1076,7 +1075,7 @@
   // superclass.method, which can also resolve to a default method
   // and the selected method is recalculated relative to the direct superclass
   // superinterface.method, which explicitly does not check shadowing
-  KlassHandle resolved_klass = link_info.resolved_klass();
+  Klass* resolved_klass = link_info.resolved_klass();
   methodHandle resolved_method;
 
   if (!resolved_klass->is_interface()) {
@@ -1087,7 +1086,7 @@
 
   // check if method name is <init>, that it is found in same klass as static type
   if (resolved_method->name() == vmSymbols::object_initializer_name() &&
-      resolved_method->method_holder() != resolved_klass()) {
+      resolved_method->method_holder() != resolved_klass) {
     ResourceMark rm(THREAD);
     Exceptions::fthrow(
       THREAD_AND_LOCATION,
@@ -1101,24 +1100,25 @@
   }
 
   // check if invokespecial's interface method reference is in an indirect superinterface
-  KlassHandle current_klass = link_info.current_klass();
-  if (!current_klass.is_null() && resolved_klass->is_interface()) {
-    Klass *klass_to_check = !InstanceKlass::cast(current_klass())->is_anonymous() ?
-                                  current_klass() :
-                                  InstanceKlass::cast(current_klass())->host_klass();
+  Klass* current_klass = link_info.current_klass();
+  if (current_klass != NULL && resolved_klass->is_interface()) {
+    InstanceKlass* ck = InstanceKlass::cast(current_klass);
+    InstanceKlass *klass_to_check = !ck->is_anonymous() ?
+                                    ck :
+                                    InstanceKlass::cast(ck->host_klass());
     // Disable verification for the dynamically-generated reflection bytecodes.
     bool is_reflect = klass_to_check->is_subclass_of(
                         SystemDictionary::reflect_MagicAccessorImpl_klass());
 
     if (!is_reflect &&
-        !InstanceKlass::cast(klass_to_check)->is_same_or_direct_interface(resolved_klass())) {
+        !klass_to_check->is_same_or_direct_interface(resolved_klass)) {
       ResourceMark rm(THREAD);
       char buf[200];
       jio_snprintf(buf, sizeof(buf),
                    "Interface method reference: %s, is in an indirect superinterface of %s",
-                   Method::name_and_sig_as_C_string(resolved_klass(),
-                                                         resolved_method->name(),
-                                                         resolved_method->signature()),
+                   Method::name_and_sig_as_C_string(resolved_klass,
+                                                    resolved_method->name(),
+                                                    resolved_method->signature()),
                    current_klass->external_name());
       THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
     }
@@ -1130,7 +1130,7 @@
     char buf[200];
     jio_snprintf(buf, sizeof(buf),
                  "Expecting non-static method %s",
-                 Method::name_and_sig_as_C_string(resolved_klass(),
+                 Method::name_and_sig_as_C_string(resolved_klass,
                                                   resolved_method->name(),
                                                   resolved_method->signature()));
     THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
@@ -1147,8 +1147,8 @@
 // throws runtime exceptions
 void LinkResolver::runtime_resolve_special_method(CallInfo& result,
                                                   const methodHandle& resolved_method,
-                                                  KlassHandle resolved_klass,
-                                                  KlassHandle current_klass,
+                                                  Klass* resolved_klass,
+                                                  Klass* current_klass,
                                                   bool check_access, TRAPS) {
 
   // resolved method is selected method unless we have an old-style lookup
@@ -1158,33 +1158,29 @@
   methodHandle sel_method(THREAD, resolved_method());
 
   // check if this is an old-style super call and do a new lookup if so
-  { KlassHandle method_klass  = KlassHandle(THREAD,
-                                            resolved_method->method_holder());
-
-    if (check_access &&
-        // a) check if ACC_SUPER flag is set for the current class
-        (current_klass->is_super() || !AllowNonVirtualCalls) &&
-        // b) check if the class of the resolved_klass is a superclass
-        // (not supertype in order to exclude interface classes) of the current class.
-        // This check is not performed for super.invoke for interface methods
-        // in super interfaces.
-        current_klass->is_subclass_of(resolved_klass()) &&
-        current_klass() != resolved_klass() &&
-        // c) check if the method is not <init>
-        resolved_method->name() != vmSymbols::object_initializer_name()) {
-      // Lookup super method
-      KlassHandle super_klass(THREAD, current_klass->super());
-      sel_method = lookup_instance_method_in_klasses(super_klass,
-                           resolved_method->name(),
-                           resolved_method->signature(), CHECK);
-      // check if found
-      if (sel_method.is_null()) {
-        ResourceMark rm(THREAD);
-        THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
-                  Method::name_and_sig_as_C_string(resolved_klass(),
-                                            resolved_method->name(),
-                                            resolved_method->signature()));
-      }
+  if (check_access &&
+      // a) check if ACC_SUPER flag is set for the current class
+      (current_klass->is_super() || !AllowNonVirtualCalls) &&
+      // b) check if the class of the resolved_klass is a superclass
+      // (not supertype in order to exclude interface classes) of the current class.
+      // This check is not performed for super.invoke for interface methods
+      // in super interfaces.
+      current_klass->is_subclass_of(resolved_klass) &&
+      current_klass != resolved_klass &&
+      // c) check if the method is not <init>
+      resolved_method->name() != vmSymbols::object_initializer_name()) {
+    // Lookup super method
+    Klass* super_klass = current_klass->super();
+    sel_method = lookup_instance_method_in_klasses(super_klass,
+                         resolved_method->name(),
+                         resolved_method->signature(), CHECK);
+    // check if found
+    if (sel_method.is_null()) {
+      ResourceMark rm(THREAD);
+      THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
+                Method::name_and_sig_as_C_string(resolved_klass,
+                                          resolved_method->name(),
+                                          resolved_method->signature()));
     }
   }
 
@@ -1192,9 +1188,9 @@
   if (sel_method->is_static()) {
     ResourceMark rm(THREAD);
     char buf[200];
-    jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(),
-                                                                                                             resolved_method->name(),
-                                                                                                             resolved_method->signature()));
+    jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass,
+                                                                                      resolved_method->name(),
+                                                                                      resolved_method->signature()));
     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
   }
 
@@ -1202,7 +1198,7 @@
   if (sel_method->is_abstract()) {
     ResourceMark rm(THREAD);
     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
-              Method::name_and_sig_as_C_string(resolved_klass(),
+              Method::name_and_sig_as_C_string(resolved_klass,
                                                sel_method->name(),
                                                sel_method->signature()));
   }
@@ -1216,7 +1212,7 @@
   result.set_static(resolved_klass, sel_method, CHECK);
 }
 
-void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHandle receiver_klass,
+void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, Klass* receiver_klass,
                                         const LinkInfo& link_info,
                                         bool check_null_and_abstract, TRAPS) {
   methodHandle resolved_method = linktime_resolve_virtual_method(link_info, CHECK);
@@ -1236,18 +1232,18 @@
   assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier");
 
   // check if private interface method
-  KlassHandle resolved_klass = link_info.resolved_klass();
-  KlassHandle current_klass = link_info.current_klass();
+  Klass* resolved_klass = link_info.resolved_klass();
+  Klass* current_klass = link_info.current_klass();
 
   // This is impossible, if resolve_klass is an interface, we've thrown icce in resolve_method
   if (resolved_klass->is_interface() && resolved_method->is_private()) {
     ResourceMark rm(THREAD);
     char buf[200];
     jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokevirtual: method %s, caller-class:%s",
-                 Method::name_and_sig_as_C_string(resolved_klass(),
+                 Method::name_and_sig_as_C_string(resolved_klass,
                                                   resolved_method->name(),
                                                   resolved_method->signature()),
-                   (current_klass.is_null() ? "<NULL>" : current_klass->internal_name()));
+                   (current_klass == NULL ? "<NULL>" : current_klass->internal_name()));
     THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
   }
 
@@ -1255,9 +1251,9 @@
   if (resolved_method->is_static()) {
     ResourceMark rm(THREAD);
     char buf[200];
-    jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(),
-                                                                                                             resolved_method->name(),
-                                                                                                             resolved_method->signature()));
+    jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass,
+                                                                                           resolved_method->name(),
+                                                                                           resolved_method->signature()));
     THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
   }
 
@@ -1272,9 +1268,9 @@
 // throws runtime exceptions
 void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
                                                   const methodHandle& resolved_method,
-                                                  KlassHandle resolved_klass,
+                                                  Klass* resolved_klass,
                                                   Handle recv,
-                                                  KlassHandle recv_klass,
+                                                  Klass* recv_klass,
                                                   bool check_null_and_abstract,
                                                   TRAPS) {
 
@@ -1323,18 +1319,18 @@
   if (selected_method.is_null()) {
     ResourceMark rm(THREAD);
     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
-              Method::name_and_sig_as_C_string(resolved_klass(),
-                                                      resolved_method->name(),
-                                                      resolved_method->signature()));
+              Method::name_and_sig_as_C_string(resolved_klass,
+                                               resolved_method->name(),
+                                               resolved_method->signature()));
   }
 
   // check if abstract
   if (check_null_and_abstract && selected_method->is_abstract()) {
     ResourceMark rm(THREAD);
     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
-              Method::name_and_sig_as_C_string(resolved_klass(),
-                                                      selected_method->name(),
-                                                      selected_method->signature()));
+              Method::name_and_sig_as_C_string(resolved_klass,
+                                               selected_method->name(),
+                                               selected_method->signature()));
   }
 
   if (log_develop_is_enabled(Trace, vtables)) {
@@ -1346,7 +1342,7 @@
   result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK);
 }
 
-void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass,
+void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, Klass* recv_klass,
                                           const LinkInfo& link_info,
                                           bool check_null_and_abstract, TRAPS) {
   // throws linktime exceptions
@@ -1368,9 +1364,9 @@
 // throws runtime exceptions
 void LinkResolver::runtime_resolve_interface_method(CallInfo& result,
                                                     const methodHandle& resolved_method,
-                                                    KlassHandle resolved_klass,
+                                                    Klass* resolved_klass,
                                                     Handle recv,
-                                                    KlassHandle recv_klass,
+                                                    Klass* recv_klass,
                                                     bool check_null_and_abstract, TRAPS) {
   // check if receiver exists
   if (check_null_and_abstract && recv.is_null()) {
@@ -1378,12 +1374,12 @@
   }
 
   // check if receiver klass implements the resolved interface
-  if (!recv_klass->is_subtype_of(resolved_klass())) {
+  if (!recv_klass->is_subtype_of(resolved_klass)) {
     ResourceMark rm(THREAD);
     char buf[200];
     jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s",
-                 recv_klass()->external_name(),
-                 resolved_klass()->external_name());
+                 recv_klass->external_name(),
+                 resolved_klass->external_name());
     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
   }
 
@@ -1403,7 +1399,7 @@
   if (sel_method.is_null()) {
     ResourceMark rm(THREAD);
     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
-                   Method::name_and_sig_as_C_string(recv_klass(),
+                   Method::name_and_sig_as_C_string(recv_klass,
                                                     resolved_method->name(),
                                                     resolved_method->signature()));
   }
@@ -1412,7 +1408,7 @@
   if (!sel_method->is_public()) {
     ResourceMark rm(THREAD);
     THROW_MSG(vmSymbols::java_lang_IllegalAccessError(),
-              Method::name_and_sig_as_C_string(recv_klass(),
+              Method::name_and_sig_as_C_string(recv_klass,
                                                sel_method->name(),
                                                sel_method->signature()));
   }
@@ -1420,9 +1416,9 @@
   if (check_null_and_abstract && sel_method->is_abstract()) {
     ResourceMark rm(THREAD);
     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
-              Method::name_and_sig_as_C_string(recv_klass(),
-                                                      sel_method->name(),
-                                                      sel_method->signature()));
+              Method::name_and_sig_as_C_string(recv_klass,
+                                               sel_method->name(),
+                                               sel_method->signature()));
   }
 
   if (log_develop_is_enabled(Trace, itables)) {
@@ -1466,7 +1462,7 @@
 }
 
 methodHandle LinkResolver::resolve_virtual_call_or_null(
-                                                 KlassHandle receiver_klass,
+                                                 Klass* receiver_klass,
                                                  const LinkInfo& link_info) {
   EXCEPTION_MARK;
   CallInfo info;
@@ -1479,7 +1475,7 @@
 }
 
 methodHandle LinkResolver::resolve_interface_call_or_null(
-                                                 KlassHandle receiver_klass,
+                                                 Klass* receiver_klass,
                                                  const LinkInfo& link_info) {
   EXCEPTION_MARK;
   CallInfo info;
@@ -1491,7 +1487,7 @@
   return info.selected_method();
 }
 
-int LinkResolver::resolve_virtual_vtable_index(KlassHandle receiver_klass,
+int LinkResolver::resolve_virtual_vtable_index(Klass* receiver_klass,
                                                const LinkInfo& link_info) {
   EXCEPTION_MARK;
   CallInfo info;
@@ -1546,7 +1542,7 @@
 void LinkResolver::resolve_invoke(CallInfo& result, Handle& recv,
                              const methodHandle& attached_method,
                              Bytecodes::Code byte, TRAPS) {
-  KlassHandle defc = attached_method->method_holder();
+  Klass* defc = attached_method->method_holder();
   Symbol* name = attached_method->name();
   Symbol* type = attached_method->signature();
   LinkInfo link_info(defc, name, type);
@@ -1587,14 +1583,14 @@
                                           TRAPS) {
 
   LinkInfo link_info(pool, index, CHECK);
-  KlassHandle recvrKlass (THREAD, recv.is_null() ? (Klass*)NULL : recv->klass());
+  Klass* recvrKlass = recv.is_null() ? (Klass*)NULL : recv->klass();
   resolve_virtual_call(result, recv, recvrKlass, link_info, /*check_null_or_abstract*/true, CHECK);
 }
 
 
 void LinkResolver::resolve_invokeinterface(CallInfo& result, Handle recv, const constantPoolHandle& pool, int index, TRAPS) {
   LinkInfo link_info(pool, index, CHECK);
-  KlassHandle recvrKlass (THREAD, recv.is_null() ? (Klass*)NULL : recv->klass());
+  Klass* recvrKlass = recv.is_null() ? (Klass*)NULL : recv->klass();
   resolve_interface_call(result, recv, recvrKlass, link_info, true, CHECK);
 }
 
@@ -1614,9 +1610,9 @@
                                        const LinkInfo& link_info,
                                        TRAPS) {
   // JSR 292:  this must be an implicitly generated method MethodHandle.invokeExact(*...) or similar
-  KlassHandle resolved_klass = link_info.resolved_klass();
-  assert(resolved_klass() == SystemDictionary::MethodHandle_klass() ||
-         resolved_klass() == SystemDictionary::VarHandle_klass(), "");
+  Klass* resolved_klass = link_info.resolved_klass();
+  assert(resolved_klass == SystemDictionary::MethodHandle_klass() ||
+         resolved_klass == SystemDictionary::VarHandle_klass(), "");
   assert(MethodHandles::is_signature_polymorphic_name(link_info.name()), "");
   Handle       resolved_appendix;
   Handle       resolved_method_type;
@@ -1653,7 +1649,7 @@
 void LinkResolver::resolve_invokedynamic(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) {
   Symbol* method_name       = pool->name_ref_at(index);
   Symbol* method_signature  = pool->signature_ref_at(index);
-  KlassHandle current_klass = KlassHandle(THREAD, pool->pool_holder());
+  Klass* current_klass = pool->pool_holder();
 
   // Resolve the bootstrap specifier (BSM + optional arguments).
   Handle bootstrap_specifier;
@@ -1691,7 +1687,7 @@
 void LinkResolver::resolve_dynamic_call(CallInfo& result,
                                         Handle bootstrap_specifier,
                                         Symbol* method_name, Symbol* method_signature,
-                                        KlassHandle current_klass,
+                                        Klass* current_klass,
                                         TRAPS) {
   // JSR 292:  this must resolve to an implicitly generated method MH.linkToCallSite(*...)
   // The appendix argument is likely to be a freshly-created CallSite.
--- a/hotspot/src/share/vm/interpreter/linkResolver.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/linkResolver.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -47,8 +47,8 @@
     unknown_kind = -1
   };
  private:
-  KlassHandle  _resolved_klass;         // static receiver klass, resolved from a symbolic reference
-  KlassHandle  _selected_klass;         // dynamic receiver class (same as static, or subklass)
+  Klass*       _resolved_klass;         // static receiver klass, resolved from a symbolic reference
+  Klass*       _selected_klass;         // dynamic receiver class (same as static, or subklass)
   methodHandle _resolved_method;        // static target method
   methodHandle _selected_method;        // dynamic (actual) target method
   CallKind     _call_kind;              // kind of call (static(=bytecode static/special +
@@ -57,21 +57,21 @@
   Handle       _resolved_appendix;      // extra argument in constant pool (if CPCE::has_appendix)
   Handle       _resolved_method_type;   // MethodType (for invokedynamic and invokehandle call sites)
 
-  void set_static(KlassHandle resolved_klass, const methodHandle& resolved_method, TRAPS);
-  void set_interface(KlassHandle resolved_klass, KlassHandle selected_klass,
+  void set_static(Klass* resolved_klass, const methodHandle& resolved_method, TRAPS);
+  void set_interface(Klass* resolved_klass, Klass* selected_klass,
                      const methodHandle& resolved_method,
                      const methodHandle& selected_method,
                      int itable_index, TRAPS);
-  void set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass,
+  void set_virtual(Klass* resolved_klass, Klass* selected_klass,
                    const methodHandle& resolved_method,
                    const methodHandle& selected_method,
                    int vtable_index, TRAPS);
   void set_handle(const methodHandle& resolved_method,
                   Handle resolved_appendix, Handle resolved_method_type, TRAPS);
-  void set_handle(KlassHandle resolved_klass,
+  void set_handle(Klass* resolved_klass,
                   const methodHandle& resolved_method,
                   Handle resolved_appendix, Handle resolved_method_type, TRAPS);
-  void set_common(KlassHandle resolved_klass, KlassHandle selected_klass,
+  void set_common(Klass* resolved_klass, Klass* selected_klass,
                   const methodHandle& resolved_method,
                   const methodHandle& selected_method,
                   CallKind kind,
@@ -91,8 +91,8 @@
   // does not queue the method for compilation
   CallInfo(Method* resolved_method, Klass* resolved_klass = NULL);
 
-  KlassHandle  resolved_klass() const            { return _resolved_klass; }
-  KlassHandle  selected_klass() const            { return _selected_klass; }
+  Klass*  resolved_klass() const                 { return _resolved_klass; }
+  Klass*  selected_klass() const                 { return _selected_klass; }
   methodHandle resolved_method() const           { return _resolved_method; }
   methodHandle selected_method() const           { return _selected_method; }
   Handle       resolved_appendix() const         { return _resolved_appendix; }
@@ -135,8 +135,8 @@
 class LinkInfo : public StackObj {
   Symbol*     _name;            // extracted from JVM_CONSTANT_NameAndType
   Symbol*     _signature;
-  KlassHandle _resolved_klass;  // class that the constant pool entry points to
-  KlassHandle _current_klass;   // class that owns the constant pool
+  Klass*      _resolved_klass;  // class that the constant pool entry points to
+  Klass*      _current_klass;   // class that owns the constant pool
   methodHandle _current_method;  // sending method
   bool        _check_access;
   constantTag _tag;
@@ -151,14 +151,14 @@
   LinkInfo(const constantPoolHandle& pool, int index, TRAPS);
 
   // Condensed information from other call sites within the vm.
-  LinkInfo(KlassHandle resolved_klass, Symbol* name, Symbol* signature, KlassHandle current_klass,
+  LinkInfo(Klass* resolved_klass, Symbol* name, Symbol* signature, Klass* current_klass,
            AccessCheck check_access = needs_access_check,
            constantTag tag = JVM_CONSTANT_Invalid) :
     _resolved_klass(resolved_klass),
-    _name(name), _signature(signature), _current_klass(current_klass), _current_method(NULL),
+    _name(name), _signature(signature), _current_klass(current_klass), _current_method(methodHandle()),
     _check_access(check_access == needs_access_check), _tag(tag) {}
 
-  LinkInfo(KlassHandle resolved_klass, Symbol* name, Symbol* signature, methodHandle current_method,
+  LinkInfo(Klass* resolved_klass, Symbol* name, Symbol* signature, methodHandle current_method,
            AccessCheck check_access = needs_access_check,
            constantTag tag = JVM_CONSTANT_Invalid) :
     _resolved_klass(resolved_klass),
@@ -166,16 +166,16 @@
     _check_access(check_access == needs_access_check), _tag(tag) {}
 
   // Case where we just find the method and don't check access against the current class
-  LinkInfo(KlassHandle resolved_klass, Symbol*name, Symbol* signature) :
+  LinkInfo(Klass* resolved_klass, Symbol*name, Symbol* signature) :
     _resolved_klass(resolved_klass),
-    _name(name), _signature(signature), _current_klass(NULL), _current_method(NULL),
+    _name(name), _signature(signature), _current_klass(NULL), _current_method(methodHandle()),
     _check_access(false), _tag(JVM_CONSTANT_Invalid) {}
 
   // accessors
   Symbol* name() const               { return _name; }
   Symbol* signature() const          { return _signature; }
-  KlassHandle resolved_klass() const { return _resolved_klass; }
-  KlassHandle current_klass() const  { return _current_klass; }
+  Klass* resolved_klass() const      { return _resolved_klass; }
+  Klass* current_klass() const       { return _current_klass; }
   methodHandle current_method() const { return _current_method; }
   constantTag tag() const            { return _tag; }
   bool check_access() const          { return _check_access; }
@@ -206,7 +206,7 @@
  JVMCI_ONLY(public:) // Needed for CompilerToVM.resolveMethod()
   // Not Linktime so doesn't take LinkInfo
   static methodHandle lookup_instance_method_in_klasses (
-                                       KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
+                                       Klass* klass, Symbol* name, Symbol* signature, TRAPS);
  JVMCI_ONLY(private:)
 
   // Similar loader constraint checking functions that throw
@@ -215,8 +215,8 @@
                                               const methodHandle& resolved_method,
                                               const char* method_type, TRAPS);
   static void check_field_loader_constraints(Symbol* field, Symbol* sig,
-                                             KlassHandle current_klass,
-                                             KlassHandle sel_klass, TRAPS);
+                                             Klass* current_klass,
+                                             Klass* sel_klass, TRAPS);
 
   static methodHandle resolve_interface_method(const LinkInfo& link_info, Bytecodes::Code code, TRAPS);
   static methodHandle resolve_method          (const LinkInfo& link_info, Bytecodes::Code code, TRAPS);
@@ -228,29 +228,29 @@
 
   static void runtime_resolve_special_method    (CallInfo& result,
                                                  const methodHandle& resolved_method,
-                                                 KlassHandle resolved_klass,
-                                                 KlassHandle current_klass,
+                                                 Klass* resolved_klass,
+                                                 Klass* current_klass,
                                                  bool check_access, TRAPS);
   static void runtime_resolve_virtual_method    (CallInfo& result,
                                                  const methodHandle& resolved_method,
-                                                 KlassHandle resolved_klass,
+                                                 Klass* resolved_klass,
                                                  Handle recv,
-                                                 KlassHandle recv_klass,
+                                                 Klass* recv_klass,
                                                  bool check_null_and_abstract, TRAPS);
   static void runtime_resolve_interface_method  (CallInfo& result,
                                                  const methodHandle& resolved_method,
-                                                 KlassHandle resolved_klass,
+                                                 Klass* resolved_klass,
                                                  Handle recv,
-                                                 KlassHandle recv_klass,
+                                                 Klass* recv_klass,
                                                  bool check_null_and_abstract, TRAPS);
 
-  static void check_field_accessability(KlassHandle ref_klass,
-                                        KlassHandle resolved_klass,
-                                        KlassHandle sel_klass,
+  static void check_field_accessability(Klass* ref_klass,
+                                        Klass* resolved_klass,
+                                        Klass* sel_klass,
                                         const fieldDescriptor& fd, TRAPS);
-  static void check_method_accessability(KlassHandle ref_klass,
-                                         KlassHandle resolved_klass,
-                                         KlassHandle sel_klass,
+  static void check_method_accessability(Klass* ref_klass,
+                                         Klass* resolved_klass,
+                                         Klass* sel_klass,
                                          const methodHandle& sel_method, TRAPS);
 
   // runtime resolving from constant pool
@@ -268,7 +268,7 @@
                                       const constantPoolHandle& pool, int index, TRAPS);
  public:
   // constant pool resolving
-  static void check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS);
+  static void check_klass_accessability(Klass* ref_klass, Klass* sel_klass, TRAPS);
 
   // static resolving calls (will not run any Java code);
   // used only from Bytecode_invoke::static_target
@@ -291,31 +291,31 @@
   static void resolve_special_call  (CallInfo& result,
                                      const LinkInfo& link_info,
                                      TRAPS);
-  static void resolve_virtual_call  (CallInfo& result, Handle recv, KlassHandle recv_klass,
+  static void resolve_virtual_call  (CallInfo& result, Handle recv, Klass* recv_klass,
                                      const LinkInfo& link_info,
                                      bool check_null_and_abstract, TRAPS);
-  static void resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass,
+  static void resolve_interface_call(CallInfo& result, Handle recv, Klass* recv_klass,
                                      const LinkInfo& link_info,
                                      bool check_null_and_abstract, TRAPS);
   static void resolve_handle_call   (CallInfo& result,
                                      const LinkInfo& link_info, TRAPS);
   static void resolve_dynamic_call  (CallInfo& result, Handle bootstrap_specifier,
                                      Symbol* method_name, Symbol* method_signature,
-                                     KlassHandle current_klass, TRAPS);
+                                     Klass* current_klass, TRAPS);
 
   // same as above for compile-time resolution; but returns null handle instead of throwing
   // an exception on error also, does not initialize klass (i.e., no side effects)
-  static methodHandle resolve_virtual_call_or_null  (KlassHandle receiver_klass,
+  static methodHandle resolve_virtual_call_or_null  (Klass* receiver_klass,
                                                      const LinkInfo& link_info);
-  static methodHandle resolve_interface_call_or_null(KlassHandle receiver_klass,
+  static methodHandle resolve_interface_call_or_null(Klass* receiver_klass,
                                                      const LinkInfo& link_info);
   static methodHandle resolve_static_call_or_null   (const LinkInfo& link_info);
   static methodHandle resolve_special_call_or_null  (const LinkInfo& link_info);
 
-  static int vtable_index_of_interface_method(KlassHandle klass, const methodHandle& resolved_method);
+  static int vtable_index_of_interface_method(Klass* klass, const methodHandle& resolved_method);
 
   // same as above for compile-time resolution; returns vtable_index if current_klass if linked
-  static int resolve_virtual_vtable_index  (KlassHandle receiver_klass,
+  static int resolve_virtual_vtable_index  (Klass* receiver_klass,
                                             const LinkInfo& link_info);
 
   // static resolving for compiler (does not throw exceptions, returns null handle if unsuccessful)
--- a/hotspot/src/share/vm/interpreter/rewriter.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/rewriter.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -544,16 +544,16 @@
   patch_invokedynamic_bytecodes();
 }
 
-void Rewriter::rewrite(instanceKlassHandle klass, TRAPS) {
+void Rewriter::rewrite(InstanceKlass* klass, TRAPS) {
   if (!DumpSharedSpaces) {
-    assert(!MetaspaceShared::is_in_shared_space(klass()), "archive methods must not be rewritten at run time");
+    assert(!MetaspaceShared::is_in_shared_space(klass), "archive methods must not be rewritten at run time");
   }
   ResourceMark rm(THREAD);
   Rewriter     rw(klass, klass->constants(), klass->methods(), CHECK);
   // (That's all, folks.)
 }
 
-Rewriter::Rewriter(instanceKlassHandle klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS)
+Rewriter::Rewriter(InstanceKlass* klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS)
   : _klass(klass),
     _pool(cpool),
     _methods(methods),
--- a/hotspot/src/share/vm/interpreter/rewriter.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/rewriter.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,7 +34,7 @@
 
 class Rewriter: public StackObj {
  private:
-  instanceKlassHandle _klass;
+  InstanceKlass*      _klass;
   constantPoolHandle  _pool;
   Array<Method*>*     _methods;
   GrowableArray<int>  _cp_map;
@@ -188,7 +188,7 @@
   }
 
   // All the work goes in here:
-  Rewriter(instanceKlassHandle klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS);
+  Rewriter(InstanceKlass* klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS);
 
   void compute_index_maps();
   void make_constant_pool_cache(TRAPS);
@@ -211,7 +211,7 @@
   static methodHandle rewrite_jsrs(methodHandle m, TRAPS);
  public:
   // Driver routine:
-  static void rewrite(instanceKlassHandle klass, TRAPS);
+  static void rewrite(InstanceKlass* klass, TRAPS);
 };
 
 #endif // SHARE_VM_INTERPRETER_REWRITER_HPP
--- a/hotspot/src/share/vm/interpreter/templateInterpreter.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/templateInterpreter.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -193,7 +193,6 @@
 EntryPoint TemplateInterpreter::_return_entry[TemplateInterpreter::number_of_return_entries];
 EntryPoint TemplateInterpreter::_earlyret_entry;
 EntryPoint TemplateInterpreter::_deopt_entry [TemplateInterpreter::number_of_deopt_entries ];
-EntryPoint TemplateInterpreter::_continuation_entry;
 EntryPoint TemplateInterpreter::_safept_entry;
 
 address TemplateInterpreter::_invoke_return_entry[TemplateInterpreter::number_of_return_addrs];
--- a/hotspot/src/share/vm/interpreter/templateInterpreter.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/templateInterpreter.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -119,7 +119,6 @@
   static EntryPoint _return_entry[number_of_return_entries];    // entry points to return to from a call
   static EntryPoint _earlyret_entry;                            // entry point to return early from a call
   static EntryPoint _deopt_entry[number_of_deopt_entries];      // entry points to return to from a deoptimization
-  static EntryPoint _continuation_entry;
   static EntryPoint _safept_entry;
 
   static address _invoke_return_entry[number_of_return_addrs];           // for invokestatic, invokespecial, invokevirtual return entries
@@ -158,7 +157,6 @@
 #ifndef PRODUCT
   static address    trace_code    (TosState state)              { return _trace_code.entry(state); }
 #endif // !PRODUCT
-  static address    continuation  (TosState state)              { return _continuation_entry.entry(state); }
   static address*   dispatch_table(TosState state)              { return _active_table.table_for(state); }
   static address*   dispatch_table()                            { return _active_table.table_for(); }
   static int        distance_from_dispatch_table(TosState state){ return _active_table.distance_from(state); }
--- a/hotspot/src/share/vm/interpreter/templateInterpreterGenerator.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/templateInterpreterGenerator.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -165,21 +165,6 @@
     }
   }
 
-  { CodeletMark cm(_masm, "continuation entry points");
-    Interpreter::_continuation_entry =
-      EntryPoint(
-                 generate_continuation_for(btos),
-                 generate_continuation_for(ztos),
-                 generate_continuation_for(ctos),
-                 generate_continuation_for(stos),
-                 generate_continuation_for(atos),
-                 generate_continuation_for(itos),
-                 generate_continuation_for(ltos),
-                 generate_continuation_for(ftos),
-                 generate_continuation_for(dtos),
-                 generate_continuation_for(vtos)
-                 );
-  }
 
   { CodeletMark cm(_masm, "safepoint entry points");
     Interpreter::_safept_entry =
--- a/hotspot/src/share/vm/interpreter/templateInterpreterGenerator.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/templateInterpreterGenerator.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -52,7 +52,6 @@
   address generate_exception_handler_common(const char* name, const char* message, bool pass_oop);
   address generate_ClassCastException_handler();
   address generate_ArrayIndexOutOfBounds_handler(const char* name);
-  address generate_continuation_for(TosState state);
   address generate_return_entry_for(TosState state, int step, size_t index_size);
   address generate_earlyret_entry_for(TosState state);
   address generate_deopt_entry_for(TosState state, int step);
--- a/hotspot/src/share/vm/jvmci/jvmciCodeInstaller.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/jvmciCodeInstaller.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -59,7 +59,7 @@
     THROW_NULL(vmSymbols::java_lang_NullPointerException());
   }
 
-  Handle reg = code_Location::reg(location);
+  Handle reg(THREAD, code_Location::reg(location));
   jint offset = code_Location::offset(location);
 
   if (reg.not_null()) {
@@ -95,7 +95,7 @@
 
 // creates a HotSpot oop map out of the byte arrays provided by DebugInfo
 OopMap* CodeInstaller::create_oop_map(Handle debug_info, TRAPS) {
-  Handle reference_map = DebugInfo::referenceMap(debug_info);
+  Handle reference_map(THREAD, DebugInfo::referenceMap(debug_info));
   if (reference_map.is_null()) {
     THROW_NULL(vmSymbols::java_lang_NullPointerException());
   }
@@ -106,9 +106,9 @@
     _has_wide_vector = true;
   }
   OopMap* map = new OopMap(_total_frame_size, _parameter_count);
-  objArrayHandle objects = HotSpotReferenceMap::objects(reference_map);
-  objArrayHandle derivedBase = HotSpotReferenceMap::derivedBase(reference_map);
-  typeArrayHandle sizeInBytes = HotSpotReferenceMap::sizeInBytes(reference_map);
+  objArrayHandle objects(THREAD, HotSpotReferenceMap::objects(reference_map));
+  objArrayHandle derivedBase(THREAD, HotSpotReferenceMap::derivedBase(reference_map));
+  typeArrayHandle sizeInBytes(THREAD, HotSpotReferenceMap::sizeInBytes(reference_map));
   if (objects.is_null() || derivedBase.is_null() || sizeInBytes.is_null()) {
     THROW_NULL(vmSymbols::java_lang_NullPointerException());
   }
@@ -116,8 +116,8 @@
     JVMCI_ERROR_NULL("arrays in reference map have different sizes: %d %d %d", objects->length(), derivedBase->length(), sizeInBytes->length());
   }
   for (int i = 0; i < objects->length(); i++) {
-    Handle location = objects->obj_at(i);
-    Handle baseLocation = derivedBase->obj_at(i);
+    Handle location(THREAD, objects->obj_at(i));
+    Handle baseLocation(THREAD, derivedBase->obj_at(i));
     int bytes = sizeInBytes->int_at(i);
 
     VMReg vmReg = getVMRegFromLocation(location, _total_frame_size, CHECK_NULL);
@@ -149,12 +149,12 @@
     }
   }
 
-  Handle callee_save_info = (oop) DebugInfo::calleeSaveInfo(debug_info);
+  Handle callee_save_info(THREAD, (oop) DebugInfo::calleeSaveInfo(debug_info));
   if (callee_save_info.not_null()) {
-    objArrayHandle registers = RegisterSaveLayout::registers(callee_save_info);
-    typeArrayHandle slots = RegisterSaveLayout::slots(callee_save_info);
+    objArrayHandle registers(THREAD, RegisterSaveLayout::registers(callee_save_info));
+    typeArrayHandle slots(THREAD, RegisterSaveLayout::slots(callee_save_info));
     for (jint i = 0; i < slots->length(); i++) {
-      Handle jvmci_reg = registers->obj_at(i);
+      Handle jvmci_reg (THREAD, registers->obj_at(i));
       jint jvmci_reg_number = code_Register::number(jvmci_reg);
       VMReg hotspot_reg = CodeInstaller::get_hotspot_reg(jvmci_reg_number, CHECK_NULL);
       // HotSpot stack slots are 4 bytes
@@ -279,9 +279,9 @@
 }
 #endif
 
-Location::Type CodeInstaller::get_oop_type(Handle value) {
-  Handle valueKind = Value::valueKind(value);
-  Handle platformKind = ValueKind::platformKind(valueKind);
+Location::Type CodeInstaller::get_oop_type(Thread* thread, Handle value) {
+  Handle valueKind(thread, Value::valueKind(value));
+  Handle platformKind(thread, ValueKind::platformKind(valueKind));
 
   if (platformKind == word_kind()) {
     return Location::oop;
@@ -300,13 +300,13 @@
     }
     return _illegal_value;
   } else if (value->is_a(RegisterValue::klass())) {
-    Handle reg = RegisterValue::reg(value);
+    Handle reg(THREAD, RegisterValue::reg(value));
     jint number = code_Register::number(reg);
     VMReg hotspotRegister = get_hotspot_reg(number, CHECK_NULL);
     if (is_general_purpose_reg(hotspotRegister)) {
       Location::Type locationType;
       if (type == T_OBJECT) {
-        locationType = get_oop_type(value);
+        locationType = get_oop_type(THREAD, value);
       } else if (type == T_LONG) {
         locationType = Location::lng;
       } else if (type == T_INT || type == T_FLOAT || type == T_SHORT || type == T_CHAR || type == T_BYTE || type == T_BOOLEAN) {
@@ -343,7 +343,7 @@
 
     Location::Type locationType;
     if (type == T_OBJECT) {
-      locationType = get_oop_type(value);
+      locationType = get_oop_type(THREAD, value);
     } else if (type == T_LONG) {
       locationType = Location::lng;
     } else if (type == T_DOUBLE) {
@@ -364,7 +364,8 @@
         jlong prim = PrimitiveConstant::primitive(value);
         return new ConstantLongValue(prim);
       } else {
-        BasicType constantType = JVMCIRuntime::kindToBasicType(PrimitiveConstant::kind(value), CHECK_NULL);
+        Handle primitive_constant_kind(THREAD, PrimitiveConstant::kind(value));
+        BasicType constantType = JVMCIRuntime::kindToBasicType(primitive_constant_kind, CHECK_NULL);
         if (type != constantType) {
           JVMCI_ERROR_NULL("primitive constant type doesn't match, expected %s but got %s", basictype_to_str(type), basictype_to_str(constantType));
         }
@@ -421,18 +422,21 @@
 }
 
 void CodeInstaller::record_object_value(ObjectValue* sv, Handle value, GrowableArray<ScopeValue*>* objects, TRAPS) {
-  Handle type = VirtualObject::type(value);
+  // Might want a HandleMark here.
+  Handle type(THREAD, VirtualObject::type(value));
   int id = VirtualObject::id(value);
   oop javaMirror = HotSpotResolvedObjectTypeImpl::javaClass(type);
   Klass* klass = java_lang_Class::as_Klass(javaMirror);
   bool isLongArray = klass == Universe::longArrayKlassObj();
 
-  objArrayHandle values = VirtualObject::values(value);
-  objArrayHandle slotKinds = VirtualObject::slotKinds(value);
+  objArrayHandle values(THREAD, VirtualObject::values(value));
+  objArrayHandle slotKinds(THREAD, VirtualObject::slotKinds(value));
   for (jint i = 0; i < values->length(); i++) {
+    HandleMark hm(THREAD);
     ScopeValue* cur_second = NULL;
-    Handle object = values->obj_at(i);
-    BasicType type = JVMCIRuntime::kindToBasicType(slotKinds->obj_at(i), CHECK);
+    Handle object(THREAD, values->obj_at(i));
+    Handle slot_kind (THREAD, slotKinds->obj_at(i));
+    BasicType type = JVMCIRuntime::kindToBasicType(slot_kind, CHECK);
     ScopeValue* value = get_scope_value(object, type, objects, cur_second, CHECK);
 
     if (isLongArray && cur_second == NULL) {
@@ -458,10 +462,12 @@
   }
 
   ScopeValue* second = NULL;
-  ScopeValue* owner_value = get_scope_value(StackLockValue::owner(value), T_OBJECT, objects, second, CHECK_NULL);
+  Handle stack_lock_owner(THREAD, StackLockValue::owner(value));
+  ScopeValue* owner_value = get_scope_value(stack_lock_owner, T_OBJECT, objects, second, CHECK_NULL);
   assert(second == NULL, "monitor cannot occupy two stack slots");
 
-  ScopeValue* lock_data_value = get_scope_value(StackLockValue::slot(value), T_LONG, objects, second, CHECK_NULL);
+  Handle stack_lock_slot(THREAD, StackLockValue::slot(value));
+  ScopeValue* lock_data_value = get_scope_value(stack_lock_slot, T_LONG, objects, second, CHECK_NULL);
   assert(second == lock_data_value, "monitor is LONG value that occupies two stack slots");
   assert(lock_data_value->is_location(), "invalid monitor location");
   Location lock_data_loc = ((LocationValue*)lock_data_value)->location();
@@ -476,25 +482,26 @@
 
 void CodeInstaller::initialize_dependencies(oop compiled_code, OopRecorder* recorder, TRAPS) {
   JavaThread* thread = JavaThread::current();
+  assert(THREAD == thread, "");
   CompilerThread* compilerThread = thread->is_Compiler_thread() ? thread->as_CompilerThread() : NULL;
   _oop_recorder = recorder;
   _dependencies = new Dependencies(&_arena, _oop_recorder, compilerThread != NULL ? compilerThread->log() : NULL);
-  objArrayHandle assumptions = HotSpotCompiledCode::assumptions(compiled_code);
+  objArrayHandle assumptions(THREAD, HotSpotCompiledCode::assumptions(compiled_code));
   if (!assumptions.is_null()) {
     int length = assumptions->length();
     for (int i = 0; i < length; ++i) {
-      Handle assumption = assumptions->obj_at(i);
+      Handle assumption(THREAD, assumptions->obj_at(i));
       if (!assumption.is_null()) {
         if (assumption->klass() == Assumptions_NoFinalizableSubclass::klass()) {
-          assumption_NoFinalizableSubclass(assumption);
+          assumption_NoFinalizableSubclass(THREAD, assumption);
         } else if (assumption->klass() == Assumptions_ConcreteSubtype::klass()) {
-          assumption_ConcreteSubtype(assumption);
+          assumption_ConcreteSubtype(THREAD, assumption);
         } else if (assumption->klass() == Assumptions_LeafType::klass()) {
-          assumption_LeafType(assumption);
+          assumption_LeafType(THREAD, assumption);
         } else if (assumption->klass() == Assumptions_ConcreteMethod::klass()) {
-          assumption_ConcreteMethod(assumption);
+          assumption_ConcreteMethod(THREAD, assumption);
         } else if (assumption->klass() == Assumptions_CallSiteTargetValue::klass()) {
-          assumption_CallSiteTargetValue(assumption);
+          assumption_CallSiteTargetValue(THREAD, assumption);
         } else {
           JVMCI_ERROR("unexpected Assumption subclass %s", assumption->klass()->signature_name());
         }
@@ -502,11 +509,11 @@
     }
   }
   if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
-    objArrayHandle methods = HotSpotCompiledCode::methods(compiled_code);
+    objArrayHandle methods(THREAD, HotSpotCompiledCode::methods(compiled_code));
     if (!methods.is_null()) {
       int length = methods->length();
       for (int i = 0; i < length; ++i) {
-        Handle method_handle = methods->obj_at(i);
+        Handle method_handle(THREAD, methods->obj_at(i));
         methodHandle method = getMethodFromHotSpotMethod(method_handle());
         _dependencies->assert_evol_method(method());
       }
@@ -639,7 +646,7 @@
 
 void CodeInstaller::initialize_fields(oop target, oop compiled_code, TRAPS) {
   if (compiled_code->is_a(HotSpotCompiledNmethod::klass())) {
-    Handle hotspotJavaMethod = HotSpotCompiledNmethod::method(compiled_code);
+    Handle hotspotJavaMethod(THREAD, HotSpotCompiledNmethod::method(compiled_code));
     methodHandle method = getMethodFromHotSpotMethod(hotspotJavaMethod());
     _parameter_count = method->size_of_parameters();
     TRACE_jvmci_2("installing code for %s", method->name_and_sig_as_C_string());
@@ -728,7 +735,7 @@
 // perform data and call relocation on the CodeBuffer
 JVMCIEnv::CodeInstallResult CodeInstaller::initialize_buffer(CodeBuffer& buffer, bool check_size, TRAPS) {
   HandleMark hm;
-  objArrayHandle sites = this->sites();
+  objArrayHandle sites(THREAD, this->sites());
   int locs_buffer_size = sites->length() * (relocInfo::length_limit + sizeof(relocInfo));
 
   // Allocate enough space in the stub section for the static call
@@ -766,18 +773,19 @@
   _instructions->set_end(end_pc);
 
   for (int i = 0; i < data_section_patches()->length(); i++) {
-    Handle patch = data_section_patches()->obj_at(i);
+    HandleMark hm(THREAD);
+    Handle patch(THREAD, data_section_patches()->obj_at(i));
     if (patch.is_null()) {
       THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
     }
-    Handle reference = site_DataPatch::reference(patch);
+    Handle reference(THREAD, site_DataPatch::reference(patch));
     if (reference.is_null()) {
       THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
     }
     if (!reference->is_a(site_ConstantReference::klass())) {
       JVMCI_ERROR_OK("invalid patch in data section: %s", reference->klass()->signature_name());
     }
-    Handle constant = site_ConstantReference::constant(reference);
+    Handle constant(THREAD, site_ConstantReference::constant(reference));
     if (constant.is_null()) {
       THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
     }
@@ -793,7 +801,7 @@
         *((void**) dest) = record_metadata_reference(_constants, dest, constant, CHECK_OK);
       }
     } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
-      Handle obj = HotSpotObjectConstantImpl::object(constant);
+      Handle obj(THREAD, HotSpotObjectConstantImpl::object(constant));
       jobject value = JNIHandles::make_local(obj());
       int oop_index = _oop_recorder->find_index(value);
 
@@ -812,7 +820,8 @@
   }
   jint last_pc_offset = -1;
   for (int i = 0; i < sites->length(); i++) {
-    Handle site = sites->obj_at(i);
+    HandleMark hm(THREAD);
+    Handle site(THREAD, sites->obj_at(i));
     if (site.is_null()) {
       THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
     }
@@ -869,15 +878,15 @@
   return JVMCIEnv::ok;
 }
 
-void CodeInstaller::assumption_NoFinalizableSubclass(Handle assumption) {
-  Handle receiverType_handle = Assumptions_NoFinalizableSubclass::receiverType(assumption());
+void CodeInstaller::assumption_NoFinalizableSubclass(Thread* thread, Handle assumption) {
+  Handle receiverType_handle (thread, Assumptions_NoFinalizableSubclass::receiverType(assumption()));
   Klass* receiverType = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(receiverType_handle));
   _dependencies->assert_has_no_finalizable_subclasses(receiverType);
 }
 
-void CodeInstaller::assumption_ConcreteSubtype(Handle assumption) {
-  Handle context_handle = Assumptions_ConcreteSubtype::context(assumption());
-  Handle subtype_handle = Assumptions_ConcreteSubtype::subtype(assumption());
+void CodeInstaller::assumption_ConcreteSubtype(Thread* thread, Handle assumption) {
+  Handle context_handle (thread, Assumptions_ConcreteSubtype::context(assumption()));
+  Handle subtype_handle (thread, Assumptions_ConcreteSubtype::subtype(assumption()));
   Klass* context = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(context_handle));
   Klass* subtype = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(subtype_handle));
 
@@ -885,16 +894,16 @@
   _dependencies->assert_abstract_with_unique_concrete_subtype(context, subtype);
 }
 
-void CodeInstaller::assumption_LeafType(Handle assumption) {
-  Handle context_handle = Assumptions_LeafType::context(assumption());
+void CodeInstaller::assumption_LeafType(Thread* thread, Handle assumption) {
+  Handle context_handle (thread, Assumptions_LeafType::context(assumption()));
   Klass* context = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(context_handle));
 
   _dependencies->assert_leaf_type(context);
 }
 
-void CodeInstaller::assumption_ConcreteMethod(Handle assumption) {
-  Handle impl_handle = Assumptions_ConcreteMethod::impl(assumption());
-  Handle context_handle = Assumptions_ConcreteMethod::context(assumption());
+void CodeInstaller::assumption_ConcreteMethod(Thread* thread, Handle assumption) {
+  Handle impl_handle (thread, Assumptions_ConcreteMethod::impl(assumption()));
+  Handle context_handle (thread, Assumptions_ConcreteMethod::context(assumption()));
 
   methodHandle impl = getMethodFromHotSpotMethod(impl_handle());
   Klass* context = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(context_handle));
@@ -902,9 +911,9 @@
   _dependencies->assert_unique_concrete_method(context, impl());
 }
 
-void CodeInstaller::assumption_CallSiteTargetValue(Handle assumption) {
-  Handle callSite = Assumptions_CallSiteTargetValue::callSite(assumption());
-  Handle methodHandle = Assumptions_CallSiteTargetValue::methodHandle(assumption());
+void CodeInstaller::assumption_CallSiteTargetValue(Thread* thread, Handle assumption) {
+  Handle callSite(thread, Assumptions_CallSiteTargetValue::callSite(assumption()));
+  Handle methodHandle(thread, Assumptions_CallSiteTargetValue::methodHandle(assumption()));
 
   _dependencies->assert_call_site_target_value(callSite(), methodHandle());
 }
@@ -936,16 +945,17 @@
 }
 
 GrowableArray<ScopeValue*>* CodeInstaller::record_virtual_objects(Handle debug_info, TRAPS) {
-  objArrayHandle virtualObjects = DebugInfo::virtualObjectMapping(debug_info);
+  objArrayHandle virtualObjects(THREAD, DebugInfo::virtualObjectMapping(debug_info));
   if (virtualObjects.is_null()) {
     return NULL;
   }
   GrowableArray<ScopeValue*>* objects = new GrowableArray<ScopeValue*>(virtualObjects->length(), virtualObjects->length(), NULL);
   // Create the unique ObjectValues
   for (int i = 0; i < virtualObjects->length(); i++) {
-    Handle value = virtualObjects->obj_at(i);
+    HandleMark hm(THREAD);
+    Handle value(THREAD, virtualObjects->obj_at(i));
     int id = VirtualObject::id(value);
-    Handle type = VirtualObject::type(value);
+    Handle type(THREAD, VirtualObject::type(value));
     oop javaMirror = HotSpotResolvedObjectTypeImpl::javaClass(type);
     ObjectValue* sv = new ObjectValue(id, new ConstantOopWriteValue(JNIHandles::make_local(Thread::current(), javaMirror)));
     if (id < 0 || id >= objects->length()) {
@@ -959,7 +969,8 @@
   // All the values which could be referenced by the VirtualObjects
   // exist, so now describe all the VirtualObjects themselves.
   for (int i = 0; i < virtualObjects->length(); i++) {
-    Handle value = virtualObjects->obj_at(i);
+    HandleMark hm(THREAD);
+    Handle value(THREAD, virtualObjects->obj_at(i));
     int id = VirtualObject::id(value);
     record_object_value(objects->at(id)->as_ObjectValue(), value, objects, CHECK_NULL);
   }
@@ -968,7 +979,7 @@
 }
 
 void CodeInstaller::record_scope(jint pc_offset, Handle debug_info, ScopeMode scope_mode, bool return_oop, TRAPS) {
-  Handle position = DebugInfo::bytecodePosition(debug_info);
+  Handle position(THREAD, DebugInfo::bytecodePosition(debug_info));
   if (position.is_null()) {
     // Stubs do not record scope info, just oop maps
     return;
@@ -991,12 +1002,12 @@
     }
     frame = position;
   }
-  Handle caller_frame = BytecodePosition::caller(position);
+  Handle caller_frame (THREAD, BytecodePosition::caller(position));
   if (caller_frame.not_null()) {
     record_scope(pc_offset, caller_frame, scope_mode, objects, return_oop, CHECK);
   }
 
-  Handle hotspot_method = BytecodePosition::method(position);
+  Handle hotspot_method (THREAD, BytecodePosition::method(position));
   Method* method = getMethodFromHotSpotMethod(hotspot_method());
   jint bci = BytecodePosition::bci(position);
   if (bci == BytecodeFrame::BEFORE_BCI()) {
@@ -1027,8 +1038,8 @@
     jint local_count = BytecodeFrame::numLocals(frame);
     jint expression_count = BytecodeFrame::numStack(frame);
     jint monitor_count = BytecodeFrame::numLocks(frame);
-    objArrayHandle values = BytecodeFrame::values(frame);
-    objArrayHandle slotKinds = BytecodeFrame::slotKinds(frame);
+    objArrayHandle values(THREAD, BytecodeFrame::values(frame));
+    objArrayHandle slotKinds(THREAD, BytecodeFrame::slotKinds(frame));
 
     if (values.is_null() || slotKinds.is_null()) {
       THROW(vmSymbols::java_lang_NullPointerException());
@@ -1048,17 +1059,18 @@
     TRACE_jvmci_2("%d locals %d expressions, %d monitors", local_count, expression_count, monitor_count);
 
     for (jint i = 0; i < values->length(); i++) {
+      HandleMark hm(THREAD);
       ScopeValue* second = NULL;
-      Handle value = values->obj_at(i);
+      Handle value(THREAD, values->obj_at(i));
       if (i < local_count) {
-        BasicType type = JVMCIRuntime::kindToBasicType(slotKinds->obj_at(i), CHECK);
+        BasicType type = JVMCIRuntime::kindToBasicType(Handle(THREAD, slotKinds->obj_at(i)), CHECK);
         ScopeValue* first = get_scope_value(value, type, objects, second, CHECK);
         if (second != NULL) {
           locals->append(second);
         }
         locals->append(first);
       } else if (i < local_count + expression_count) {
-        BasicType type = JVMCIRuntime::kindToBasicType(slotKinds->obj_at(i), CHECK);
+        BasicType type = JVMCIRuntime::kindToBasicType(Handle(THREAD, slotKinds->obj_at(i)), CHECK);
         ScopeValue* first = get_scope_value(value, type, objects, second, CHECK);
         if (second != NULL) {
           expressions->append(second);
@@ -1088,7 +1100,7 @@
 }
 
 void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
-  Handle debug_info = site_Infopoint::debugInfo(site);
+  Handle debug_info (THREAD, site_Infopoint::debugInfo(site));
   if (debug_info.is_null()) {
     JVMCI_ERROR("debug info expected at safepoint at %i", pc_offset);
   }
@@ -1102,7 +1114,7 @@
 }
 
 void CodeInstaller::site_Infopoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
-  Handle debug_info = site_Infopoint::debugInfo(site);
+  Handle debug_info (THREAD, site_Infopoint::debugInfo(site));
   if (debug_info.is_null()) {
     JVMCI_ERROR("debug info expected at infopoint at %i", pc_offset);
   }
@@ -1117,7 +1129,7 @@
 }
 
 void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
-  Handle target = site_Call::target(site);
+  Handle target(THREAD, site_Call::target(site));
   InstanceKlass* target_klass = InstanceKlass::cast(target->klass());
 
   Handle hotspot_method; // JavaMethod
@@ -1129,7 +1141,7 @@
     hotspot_method = target;
   }
 
-  Handle debug_info = site_Call::debugInfo(site);
+  Handle debug_info (THREAD, site_Call::debugInfo(site));
 
   assert(hotspot_method.not_null() ^ foreign_call.not_null(), "Call site needs exactly one type");
 
@@ -1177,11 +1189,11 @@
 }
 
 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
-  Handle reference = site_DataPatch::reference(site);
+  Handle reference(THREAD, site_DataPatch::reference(site));
   if (reference.is_null()) {
     THROW(vmSymbols::java_lang_NullPointerException());
   } else if (reference->is_a(site_ConstantReference::klass())) {
-    Handle constant = site_ConstantReference::constant(reference);
+    Handle constant(THREAD, site_ConstantReference::constant(reference));
     if (constant.is_null()) {
       THROW(vmSymbols::java_lang_NullPointerException());
     } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
@@ -1213,7 +1225,7 @@
 }
 
 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
-  Handle id_obj = site_Mark::id(site);
+  Handle id_obj (THREAD, site_Mark::id(site));
 
   if (id_obj.not_null()) {
     if (!java_lang_boxing_object::is_instance(id_obj(), T_INT)) {
--- a/hotspot/src/share/vm/jvmci/jvmciCodeInstaller.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/jvmciCodeInstaller.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -212,7 +212,7 @@
   const OopMapSet* oopMapSet() const { return _debug_recorder->_oopmaps; }
 
 protected:
-  Location::Type get_oop_type(Handle value);
+  Location::Type get_oop_type(Thread* thread, Handle value);
   ScopeValue* get_scope_value(Handle value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, TRAPS);
   MonitorValue* get_monitor_value(Handle value, GrowableArray<ScopeValue*>* objects, TRAPS);
 
@@ -230,11 +230,11 @@
   // perform data and call relocation on the CodeBuffer
   JVMCIEnv::CodeInstallResult initialize_buffer(CodeBuffer& buffer, bool check_size, TRAPS);
 
-  void assumption_NoFinalizableSubclass(Handle assumption);
-  void assumption_ConcreteSubtype(Handle assumption);
-  void assumption_LeafType(Handle assumption);
-  void assumption_ConcreteMethod(Handle assumption);
-  void assumption_CallSiteTargetValue(Handle assumption);
+  void assumption_NoFinalizableSubclass(Thread* thread, Handle assumption);
+  void assumption_ConcreteSubtype(Thread* thread, Handle assumption);
+  void assumption_LeafType(Thread* thread, Handle assumption);
+  void assumption_ConcreteMethod(Thread* thread, Handle assumption);
+  void assumption_CallSiteTargetValue(Thread* thread, Handle assumption);
 
   void site_Safepoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS);
   void site_Infopoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS);
--- a/hotspot/src/share/vm/jvmci/jvmciCompiler.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/jvmciCompiler.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -148,7 +148,7 @@
   if (!HAS_PENDING_EXCEPTION) {
     JavaCallArguments args;
     args.push_oop(receiver);
-    args.push_oop((oop)method_result.get_jobject());
+    args.push_oop(Handle(THREAD, (oop)method_result.get_jobject()));
     args.push_int(entry_bci);
     args.push_long((jlong) (address) env);
     args.push_int(env->task()->compile_id());
@@ -202,7 +202,7 @@
   return level;
 }
 
-void JVMCICompiler::exit_on_pending_exception(Handle exception, const char* message) {
+void JVMCICompiler::exit_on_pending_exception(oop exception, const char* message) {
   JavaThread* THREAD = JavaThread::current();
   CLEAR_PENDING_EXCEPTION;
 
@@ -210,7 +210,8 @@
   if (!report_error && Atomic::cmpxchg(1, &report_error, 0) == 0) {
     // Only report an error once
     tty->print_raw_cr(message);
-    java_lang_Throwable::java_printStackTrace(exception, THREAD);
+    Handle ex(THREAD, exception);
+    java_lang_Throwable::java_printStackTrace(ex, THREAD);
   } else {
     // Allow error reporting thread to print the stack trace.
     os::sleep(THREAD, 200, false);
--- a/hotspot/src/share/vm/jvmci/jvmciCompiler.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/jvmciCompiler.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -50,7 +50,7 @@
   /**
    * Exits the VM due to an unexpected exception.
    */
-  static void exit_on_pending_exception(Handle exception, const char* message);
+  static void exit_on_pending_exception(oop exception, const char* message);
 
 public:
   JVMCICompiler();
--- a/hotspot/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -102,11 +102,11 @@
   return NULL;
 }
 
-oop CompilerToVM::get_jvmci_type(KlassHandle klass, TRAPS) {
-  if (klass() != NULL) {
+oop CompilerToVM::get_jvmci_type(Klass* klass, TRAPS) {
+  if (klass != NULL) {
     JavaValue result(T_OBJECT);
     JavaCallArguments args;
-    args.push_oop(klass->java_mirror());
+    args.push_oop(Handle(THREAD, klass->java_mirror()));
     JavaCalls::call_static(&result, SystemDictionary::HotSpotResolvedObjectTypeImpl_klass(), vmSymbols::fromMetaspace_name(), vmSymbols::klass_fromMetaspace_signature(), &args, CHECK_NULL);
 
     return (oop)result.get_jobject();
@@ -246,7 +246,7 @@
 }
 
 objArrayHandle CompilerToVM::initialize_intrinsics(TRAPS) {
-  objArrayHandle vmIntrinsics = oopFactory::new_objArray(VMIntrinsicMethod::klass(), (vmIntrinsics::ID_LIMIT - 1), CHECK_(objArrayHandle()));
+  objArrayHandle vmIntrinsics = oopFactory::new_objArray_handle(VMIntrinsicMethod::klass(), (vmIntrinsics::ID_LIMIT - 1), CHECK_(objArrayHandle()));
   int index = 0;
   // The intrinsics for a class are usually adjacent to each other.
   // When they are, the string for the class name can be reused.
@@ -351,7 +351,8 @@
     jvalue p; p.j = (jlong) (value); \
     Handle* e = longs.get(p.j); \
     if (e == NULL) { \
-      Handle h = java_lang_boxing_object::create(T_LONG, &p, CHECK_NULL); \
+      oop o = java_lang_boxing_object::create(T_LONG, &p, CHECK_NULL); \
+      Handle h(THREAD, o); \
       longs.put(p.j, h); \
       name = h(); \
     } else { \
@@ -367,9 +368,9 @@
       if (e == NULL) { \
         Handle h = java_lang_String::create_from_str(value, CHECK_NULL); \
         strings.put(value, h); \
-        name = h(); \
+        name = h; \
       } else { \
-        name = (*e)(); \
+        name = (*e); \
       } \
     } \
   } while (0)
@@ -383,8 +384,10 @@
   ResourceHashtable<const char*, Handle, &CompilerToVM::cstring_hash, &CompilerToVM::cstring_equals> strings;
 
   jvalue prim;
-  prim.z = true;  Handle boxedTrue =  java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK_NULL);
-  prim.z = false; Handle boxedFalse = java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK_NULL);
+  prim.z = true;  oop boxedTrueOop =  java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK_NULL);
+  Handle boxedTrue(THREAD, boxedTrueOop);
+  prim.z = false; oop boxedFalseOop = java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK_NULL);
+  Handle boxedFalse(THREAD, boxedFalseOop);
 
   CompilerToVM::Data::initialize(CHECK_NULL);
 
@@ -393,7 +396,7 @@
   VMIntrinsicMethod::klass()->initialize(CHECK_NULL);
 
   int len = JVMCIVMStructs::localHotSpotVMStructs_count();
-  objArrayHandle vmFields = oopFactory::new_objArray(VMField::klass(), len, CHECK_NULL);
+  objArrayHandle vmFields = oopFactory::new_objArray_handle(VMField::klass(), len, CHECK_NULL);
   for (int i = 0; i < len ; i++) {
     VMStructEntry vmField = JVMCIVMStructs::localHotSpotVMStructs[i];
     instanceHandle vmFieldObj = InstanceKlass::cast(VMField::klass())->allocate_instance_handle(CHECK_NULL);
@@ -435,7 +438,7 @@
   int ints_len = JVMCIVMStructs::localHotSpotVMIntConstants_count();
   int longs_len = JVMCIVMStructs::localHotSpotVMLongConstants_count();
   len = ints_len + longs_len;
-  objArrayHandle vmConstants = oopFactory::new_objArray(SystemDictionary::Object_klass(), len * 2, CHECK_NULL);
+  objArrayHandle vmConstants = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), len * 2, CHECK_NULL);
   int insert = 0;
   for (int i = 0; i < ints_len ; i++) {
     VMIntConstantEntry c = JVMCIVMStructs::localHotSpotVMIntConstants[i];
@@ -454,7 +457,7 @@
   assert(insert == len * 2, "must be");
 
   len = JVMCIVMStructs::localHotSpotVMAddresses_count();
-  objArrayHandle vmAddresses = oopFactory::new_objArray(SystemDictionary::Object_klass(), len * 2, CHECK_NULL);
+  objArrayHandle vmAddresses = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), len * 2, CHECK_NULL);
   for (int i = 0; i < len ; i++) {
     VMAddressEntry a = JVMCIVMStructs::localHotSpotVMAddresses[i];
     CSTRING_TO_JSTRING(name, a.name);
@@ -490,7 +493,7 @@
 #define ADD_UINTX_FLAG(name) ADD_FLAG(uintx, name, BOXED_LONG)
 
   len = 0 + PREDEFINED_CONFIG_FLAGS(COUNT_FLAG, COUNT_FLAG, COUNT_FLAG);
-  objArrayHandle vmFlags = oopFactory::new_objArray(VMFlag::klass(), len, CHECK_NULL);
+  objArrayHandle vmFlags = oopFactory::new_objArray_handle(VMFlag::klass(), len, CHECK_NULL);
   int i = 0;
   PREDEFINED_CONFIG_FLAGS(ADD_BOOL_FLAG, ADD_INTX_FLAG, ADD_UINTX_FLAG)
 
@@ -515,7 +518,7 @@
 C2V_VMENTRY(jobject, getFlagValue, (JNIEnv *, jobject c2vm, jobject name_handle))
 #define RETURN_BOXED_LONG(value) oop box; jvalue p; p.j = (jlong) (value); box = java_lang_boxing_object::create(T_LONG, &p, CHECK_NULL); return JNIHandles::make_local(THREAD, box);
 #define RETURN_BOXED_DOUBLE(value) oop box; jvalue p; p.d = (jdouble) (value); box = java_lang_boxing_object::create(T_DOUBLE, &p, CHECK_NULL); return JNIHandles::make_local(THREAD, box);
-  Handle name = JNIHandles::resolve(name_handle);
+  Handle name(THREAD, JNIHandles::resolve(name_handle));
   if (name.is_null()) {
     THROW_0(vmSymbols::java_lang_NullPointerException());
   }
@@ -701,7 +704,7 @@
 }
 
 C2V_VMENTRY(jobject, getResolvedJavaType, (JNIEnv *, jobject, jobject base, jlong offset, jboolean compressed))
-  KlassHandle klass;
+  Klass* klass = NULL;
   oop base_object = JNIHandles::resolve(base);
   jlong base_address = 0;
   if (base_object != NULL && offset == oopDesc::klass_offset_in_bytes()) {
@@ -726,7 +729,7 @@
     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
                 err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s", base_object->klass()->external_name(), offset, compressed ? "true" : "false"));
   }
-  assert (klass.is_null() || klass->is_klass(), "invalid read");
+  assert (klass == NULL || klass->is_klass(), "invalid read");
   oop result = CompilerToVM::get_jvmci_type(klass, CHECK_NULL);
   return JNIHandles::make_local(THREAD, result);
 }
@@ -734,7 +737,7 @@
 C2V_VMENTRY(jobject, findUniqueConcreteMethod, (JNIEnv *, jobject, jobject jvmci_type, jobject jvmci_method))
   ResourceMark rm;
   methodHandle method = CompilerToVM::asMethod(jvmci_method);
-  KlassHandle holder = CompilerToVM::asKlass(jvmci_type);
+  Klass* holder = CompilerToVM::asKlass(jvmci_type);
   if (holder->is_interface()) {
     THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Interface %s should be handled in Java code", holder->external_name()));
   }
@@ -742,7 +745,7 @@
   methodHandle ucm;
   {
     MutexLocker locker(Compile_lock);
-    ucm = Dependencies::find_unique_concrete_method(holder(), method());
+    ucm = Dependencies::find_unique_concrete_method(holder, method());
   }
   oop result = CompilerToVM::get_jvmci_method(ucm, CHECK_NULL);
   return JNIHandles::make_local(THREAD, result);
@@ -776,21 +779,19 @@
 
 C2V_VMENTRY(jobject, lookupType, (JNIEnv*, jobject, jstring jname, jclass accessing_class, jboolean resolve))
   ResourceMark rm;
-  Handle name = JNIHandles::resolve(jname);
-  Symbol* class_name = java_lang_String::as_symbol(name, CHECK_0);
+  Handle name(THREAD, JNIHandles::resolve(jname));
+  Symbol* class_name = java_lang_String::as_symbol(name(), CHECK_0);
   if (java_lang_String::length(name()) <= 1) {
     THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Primitive type %s should be handled in Java code", class_name->as_C_string()));
   }
 
   Klass* resolved_klass = NULL;
-  Handle class_loader;
-  Handle protection_domain;
   if (JNIHandles::resolve(accessing_class) == NULL) {
     THROW_0(vmSymbols::java_lang_NullPointerException());
   }
   Klass* accessing_klass = java_lang_Class::as_Klass(JNIHandles::resolve(accessing_class));
-  class_loader = accessing_klass->class_loader();
-  protection_domain = accessing_klass->protection_domain();
+  Handle class_loader(THREAD, accessing_klass->class_loader());
+  Handle protection_domain(THREAD, accessing_klass->protection_domain());
 
   if (resolve) {
     resolved_klass = SystemDictionary::resolve_or_null(class_name, class_loader, protection_domain, CHECK_0);
@@ -826,8 +827,8 @@
       }
     }
   }
-  Handle result = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
-  return JNIHandles::make_local(THREAD, result());
+  oop result = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
+  return JNIHandles::make_local(THREAD, result);
 C2V_END
 
 C2V_VMENTRY(jobject, resolveConstantInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
@@ -867,26 +868,27 @@
 C2V_VMENTRY(jobject, resolveTypeInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
   Klass* resolved_klass = cp->klass_at(index, CHECK_NULL);
-  Handle klass = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
-  return JNIHandles::make_local(THREAD, klass());
+  oop klass = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
+  return JNIHandles::make_local(THREAD, klass);
 C2V_END
 
 C2V_VMENTRY(jobject, lookupKlassInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode))
   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
-  KlassHandle loading_klass(cp->pool_holder());
+  Klass* loading_klass = cp->pool_holder();
   bool is_accessible = false;
-  KlassHandle klass = JVMCIEnv::get_klass_by_index(cp, index, is_accessible, loading_klass);
+  Klass* klass = JVMCIEnv::get_klass_by_index(cp, index, is_accessible, loading_klass);
   Symbol* symbol = NULL;
-  if (klass.is_null()) {
+  if (klass == NULL) {
     symbol = cp->klass_name_at(index);
   }
-  Handle result;
-  if (!klass.is_null()) {
-    result = CompilerToVM::get_jvmci_type(klass, CHECK_NULL);
+  oop result_oop;
+  if (klass != NULL) {
+    result_oop = CompilerToVM::get_jvmci_type(klass, CHECK_NULL);
   } else {
-    result = java_lang_String::create_from_symbol(symbol, CHECK_NULL);
+    Handle result = java_lang_String::create_from_symbol(symbol, CHECK_NULL);
+    result_oop = result();
   }
-  return JNIHandles::make_local(THREAD, result());
+  return JNIHandles::make_local(THREAD, result_oop);
 C2V_END
 
 C2V_VMENTRY(jobject, lookupAppendixInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
@@ -897,7 +899,7 @@
 
 C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode))
   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
-  instanceKlassHandle pool_holder(cp->pool_holder());
+  InstanceKlass* pool_holder = cp->pool_holder();
   Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
   methodHandle method = JVMCIEnv::get_method_by_index(cp, index, bc, pool_holder);
   oop result = CompilerToVM::get_jvmci_method(method, CHECK_NULL);
@@ -944,11 +946,11 @@
 C2V_END
 
 C2V_VMENTRY(jobject, resolveMethod, (JNIEnv *, jobject, jobject receiver_jvmci_type, jobject jvmci_method, jobject caller_jvmci_type))
-  KlassHandle recv_klass = CompilerToVM::asKlass(receiver_jvmci_type);
-  KlassHandle caller_klass = CompilerToVM::asKlass(caller_jvmci_type);
+  Klass* recv_klass = CompilerToVM::asKlass(receiver_jvmci_type);
+  Klass* caller_klass = CompilerToVM::asKlass(caller_jvmci_type);
   methodHandle method = CompilerToVM::asMethod(jvmci_method);
 
-  KlassHandle h_resolved   (THREAD, method->method_holder());
+  Klass* resolved     = method->method_holder();
   Symbol* h_name      = method->name();
   Symbol* h_signature = method->signature();
 
@@ -957,13 +959,13 @@
       return NULL;
   }
 
-  LinkInfo link_info(h_resolved, h_name, h_signature, caller_klass);
+  LinkInfo link_info(resolved, h_name, h_signature, caller_klass);
   methodHandle m;
   // Only do exact lookup if receiver klass has been linked.  Otherwise,
   // the vtable has not been setup, and the LinkResolver will fail.
   if (recv_klass->is_array_klass() ||
-      InstanceKlass::cast(recv_klass())->is_linked() && !recv_klass->is_interface()) {
-    if (h_resolved->is_interface()) {
+      InstanceKlass::cast(recv_klass)->is_linked() && !recv_klass->is_interface()) {
+    if (resolved->is_interface()) {
       m = LinkResolver::resolve_interface_call_or_null(recv_klass, link_info);
     } else {
       m = LinkResolver::resolve_virtual_call_or_null(recv_klass, link_info);
@@ -1013,11 +1015,11 @@
   HandleMark hm;
   JNIHandleMark jni_hm;
 
-  Handle target_handle = JNIHandles::resolve(target);
-  Handle compiled_code_handle = JNIHandles::resolve(compiled_code);
+  Handle target_handle(THREAD, JNIHandles::resolve(target));
+  Handle compiled_code_handle(THREAD, JNIHandles::resolve(compiled_code));
   CodeBlob* cb = NULL;
-  Handle installed_code_handle = JNIHandles::resolve(installed_code);
-  Handle speculation_log_handle = JNIHandles::resolve(speculation_log);
+  Handle installed_code_handle(THREAD, JNIHandles::resolve(installed_code));
+  Handle speculation_log_handle(THREAD, JNIHandles::resolve(speculation_log));
 
   JVMCICompiler* compiler = JVMCICompiler::instance(CHECK_JNI_ERR);
 
@@ -1075,9 +1077,9 @@
   ResourceMark rm;
   HandleMark hm;
 
-  Handle target_handle = JNIHandles::resolve(target);
-  Handle compiled_code_handle = JNIHandles::resolve(compiled_code);
-  Handle metadata_handle = JNIHandles::resolve(metadata);
+  Handle target_handle(THREAD, JNIHandles::resolve(target));
+  Handle compiled_code_handle(THREAD, JNIHandles::resolve(compiled_code));
+  Handle metadata_handle(THREAD, JNIHandles::resolve(metadata));
 
   CodeMetadata code_metadata;
   CodeBlob *cb = NULL;
@@ -1089,19 +1091,19 @@
   }
 
   if (code_metadata.get_nr_pc_desc() > 0) {
-    typeArrayHandle pcArrayOop = oopFactory::new_byteArray(sizeof(PcDesc) * code_metadata.get_nr_pc_desc(), CHECK_(JVMCIEnv::cache_full));
+    typeArrayHandle pcArrayOop = oopFactory::new_byteArray_handle(sizeof(PcDesc) * code_metadata.get_nr_pc_desc(), CHECK_(JVMCIEnv::cache_full));
     memcpy(pcArrayOop->byte_at_addr(0), code_metadata.get_pc_desc(), sizeof(PcDesc) * code_metadata.get_nr_pc_desc());
     HotSpotMetaData::set_pcDescBytes(metadata_handle, pcArrayOop());
   }
 
   if (code_metadata.get_scopes_size() > 0) {
-    typeArrayHandle scopesArrayOop = oopFactory::new_byteArray(code_metadata.get_scopes_size(), CHECK_(JVMCIEnv::cache_full));
+    typeArrayHandle scopesArrayOop = oopFactory::new_byteArray_handle(code_metadata.get_scopes_size(), CHECK_(JVMCIEnv::cache_full));
     memcpy(scopesArrayOop->byte_at_addr(0), code_metadata.get_scopes_desc(), code_metadata.get_scopes_size());
     HotSpotMetaData::set_scopesDescBytes(metadata_handle, scopesArrayOop());
   }
 
   RelocBuffer* reloc_buffer = code_metadata.get_reloc_buffer();
-  typeArrayHandle relocArrayOop = oopFactory::new_byteArray((int) reloc_buffer->size(), CHECK_(JVMCIEnv::cache_full));
+  typeArrayHandle relocArrayOop = oopFactory::new_byteArray_handle((int) reloc_buffer->size(), CHECK_(JVMCIEnv::cache_full));
   if (reloc_buffer->size() > 0) {
     memcpy(relocArrayOop->byte_at_addr(0), reloc_buffer->begin(), reloc_buffer->size());
   }
@@ -1112,7 +1114,7 @@
     ResourceMark mark;
     ImmutableOopMapBuilder builder(oopMapSet);
     int oopmap_size = builder.heap_size();
-    typeArrayHandle oopMapArrayHandle = oopFactory::new_byteArray(oopmap_size, CHECK_(JVMCIEnv::cache_full));
+    typeArrayHandle oopMapArrayHandle = oopFactory::new_byteArray_handle(oopmap_size, CHECK_(JVMCIEnv::cache_full));
     builder.generate_into((address) oopMapArrayHandle->byte_at_addr(0));
     HotSpotMetaData::set_oopMaps(metadata_handle, oopMapArrayHandle());
   }
@@ -1120,7 +1122,8 @@
   AOTOopRecorder* recorder = code_metadata.get_oop_recorder();
 
   int nr_meta_strings = recorder->nr_meta_strings();
-  objArrayHandle metadataArrayHandle = oopFactory::new_objectArray(nr_meta_strings, CHECK_(JVMCIEnv::cache_full));
+  objArrayOop metadataArray = oopFactory::new_objectArray(nr_meta_strings, CHECK_(JVMCIEnv::cache_full));
+  objArrayHandle metadataArrayHandle(THREAD, metadataArray);
   for (int i = 0; i < nr_meta_strings; ++i) {
     const char* element = recorder->meta_element(i);
     Handle java_string = java_lang_String::create_from_str(element, CHECK_(JVMCIEnv::cache_full));
@@ -1130,7 +1133,7 @@
 
   ExceptionHandlerTable* handler = code_metadata.get_exception_table();
   int table_size = handler->size_in_bytes();
-  typeArrayHandle exceptionArrayOop = oopFactory::new_byteArray(table_size, CHECK_(JVMCIEnv::cache_full));
+  typeArrayHandle exceptionArrayOop = oopFactory::new_byteArray_handle(table_size, CHECK_(JVMCIEnv::cache_full));
 
   if (table_size > 0) {
     handler->copy_bytes_to((address) exceptionArrayOop->byte_at_addr(0));
@@ -1309,7 +1312,7 @@
 
 
 C2V_VMENTRY(void, invalidateInstalledCode, (JNIEnv*, jobject, jobject installed_code))
-  Handle installed_code_handle = JNIHandles::resolve(installed_code);
+  Handle installed_code_handle(THREAD, JNIHandles::resolve(installed_code));
   nmethod::invalidate_installed_code(installed_code_handle, CHECK);
 C2V_END
 
@@ -1364,7 +1367,7 @@
   ResourceMark rm;
 
   if (!thread->has_last_Java_frame()) return NULL;
-  Handle result = HotSpotStackFrameReference::klass()->allocate_instance(thread);
+  Handle result = HotSpotStackFrameReference::klass()->allocate_instance_handle(thread);
   HotSpotStackFrameReference::klass()->initialize(thread);
 
   StackFrameStream fst(thread);
@@ -1423,7 +1426,8 @@
               Deoptimization::reassign_fields(fst.current(), fst.register_map(), scope->objects(), realloc_failures, false);
 
               GrowableArray<ScopeValue*>* local_values = scope->locals();
-              typeArrayHandle array = oopFactory::new_boolArray(local_values->length(), thread);
+              typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), thread);
+              typeArrayHandle array(THREAD, array_oop);
               for (int i = 0; i < local_values->length(); i++) {
                 ScopeValue* value = local_values->at(i);
                 if (value->is_object()) {
@@ -1464,7 +1468,8 @@
         HotSpotStackFrameReference::set_frameNumber(result, frame_number);
 
         // initialize the locals array
-        objArrayHandle array = oopFactory::new_objectArray(locals->size(), thread);
+        objArrayOop array_oop = oopFactory::new_objectArray(locals->size(), CHECK_NULL);
+        objArrayHandle array(THREAD, array_oop);
         for (int i = 0; i < locals->size(); i++) {
           StackValue* var = locals->at(i);
           if (var->type() == T_OBJECT) {
@@ -1505,18 +1510,18 @@
 
 C2V_VMENTRY(void, resolveInvokeHandleInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
-  KlassHandle holder = cp->klass_ref_at(index, CHECK);
+  Klass* holder = cp->klass_ref_at(index, CHECK);
   Symbol* name = cp->name_ref_at(index);
-  if (MethodHandles::is_signature_polymorphic_name(holder(), name)) {
+  if (MethodHandles::is_signature_polymorphic_name(holder, name)) {
     CallInfo callInfo;
     LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokehandle, CHECK);
-    ConstantPoolCacheEntry* cp_cache_entry = cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index));
+    ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index));
     cp_cache_entry->set_method_handle(cp, callInfo);
   }
 C2V_END
 
 C2V_VMENTRY(jobject, getSignaturePolymorphicHolders, (JNIEnv*, jobject))
-  objArrayHandle holders = oopFactory::new_objArray(SystemDictionary::String_klass(), 2, CHECK_NULL);
+  objArrayHandle holders = oopFactory::new_objArray_handle(SystemDictionary::String_klass(), 2, CHECK_NULL);
   Handle mh = java_lang_String::create_from_str("Ljava/lang/invoke/MethodHandle;", CHECK_NULL);
   Handle vh = java_lang_String::create_from_str("Ljava/lang/invoke/VarHandle;", CHECK_NULL);
   holders->obj_at_put(0, mh());
@@ -1623,7 +1628,7 @@
   HotSpotStackFrameReference::set_localIsVirtual(hs_frame, NULL);
 
   // update the locals array
-  objArrayHandle array = HotSpotStackFrameReference::locals(hs_frame);
+  objArrayHandle array(THREAD, HotSpotStackFrameReference::locals(hs_frame));
   StackValueCollection* locals = virtualFrames->at(last_frame_number)->locals();
   for (int i = 0; i < locals->size(); i++) {
     StackValue* var = locals->at(i);
@@ -1724,7 +1729,7 @@
 C2V_END
 
 C2V_VMENTRY(void, compileToBytecode, (JNIEnv*, jobject, jobject lambda_form_handle))
-  Handle lambda_form = JNIHandles::resolve_non_null(lambda_form_handle);
+  Handle lambda_form(THREAD, JNIHandles::resolve_non_null(lambda_form_handle));
   if (lambda_form->is_a(SystemDictionary::LambdaForm_klass())) {
     TempNewSymbol compileToBytecode = SymbolTable::new_symbol("compileToBytecode", CHECK);
     JavaValue result(T_VOID);
--- a/hotspot/src/share/vm/jvmci/jvmciCompilerToVM.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/jvmciCompilerToVM.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -161,7 +161,7 @@
 
   static oop get_jvmci_method(const methodHandle& method, TRAPS);
 
-  static oop get_jvmci_type(KlassHandle klass, TRAPS);
+  static oop get_jvmci_type(Klass* klass, TRAPS);
 };
 
 class JavaArgumentUnboxer : public SignatureIterator {
@@ -170,11 +170,11 @@
   arrayOop _args;
   int _index;
 
-  oop next_arg(BasicType expectedType) {
+  Handle next_arg(BasicType expectedType) {
     assert(_index < _args->length(), "out of bounds");
     oop arg=((objArrayOop) (_args))->obj_at(_index++);
     assert(expectedType == T_OBJECT || java_lang_boxing_object::is_instance(arg, expectedType), "arg type mismatch");
-    return arg;
+    return Handle(Thread::current(), arg);
   }
 
  public:
--- a/hotspot/src/share/vm/jvmci/jvmciEnv.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/jvmciEnv.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -65,9 +65,9 @@
 // ------------------------------------------------------------------
 // Note: the logic of this method should mirror the logic of
 // constantPoolOopDesc::verify_constant_pool_resolve.
-bool JVMCIEnv::check_klass_accessibility(KlassHandle accessing_klass, KlassHandle resolved_klass) {
+bool JVMCIEnv::check_klass_accessibility(Klass* accessing_klass, Klass* resolved_klass) {
   if (accessing_klass->is_objArray_klass()) {
-    accessing_klass = ObjArrayKlass::cast(accessing_klass())->bottom_klass();
+    accessing_klass = ObjArrayKlass::cast(accessing_klass)->bottom_klass();
   }
   if (!accessing_klass->is_instance_klass()) {
     return true;
@@ -75,21 +75,21 @@
 
   if (resolved_klass->is_objArray_klass()) {
     // Find the element klass, if this is an array.
-    resolved_klass = ObjArrayKlass::cast(resolved_klass())->bottom_klass();
+    resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass();
   }
   if (resolved_klass->is_instance_klass()) {
     Reflection::VerifyClassAccessResults result =
-      Reflection::verify_class_access(accessing_klass(), resolved_klass(), true);
+      Reflection::verify_class_access(accessing_klass, InstanceKlass::cast(resolved_klass), true);
     return result == Reflection::ACCESS_OK;
   }
   return true;
 }
 
 // ------------------------------------------------------------------
-KlassHandle JVMCIEnv::get_klass_by_name_impl(KlassHandle& accessing_klass,
-                                          const constantPoolHandle& cpool,
-                                          Symbol* sym,
-                                          bool require_local) {
+Klass* JVMCIEnv::get_klass_by_name_impl(Klass* accessing_klass,
+                                        const constantPoolHandle& cpool,
+                                        Symbol* sym,
+                                        bool require_local) {
   JVMCI_EXCEPTION_CONTEXT;
 
   // Now we need to check the SystemDictionary
@@ -99,28 +99,26 @@
     // Call recursive to keep scope of strippedsym.
     TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1,
                     sym->utf8_length()-2,
-                    CHECK_(KlassHandle()));
+                    CHECK_NULL);
     return get_klass_by_name_impl(accessing_klass, cpool, strippedsym, require_local);
   }
 
   Handle loader(THREAD, (oop)NULL);
   Handle domain(THREAD, (oop)NULL);
-  if (!accessing_klass.is_null()) {
+  if (accessing_klass != NULL) {
     loader = Handle(THREAD, accessing_klass->class_loader());
     domain = Handle(THREAD, accessing_klass->protection_domain());
   }
 
-  KlassHandle found_klass;
+  Klass* found_klass = NULL;
   {
     ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
     MutexLocker ml(Compile_lock);
-    Klass*  kls;
     if (!require_local) {
-      kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, CHECK_(KlassHandle()));
+      found_klass = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, CHECK_NULL);
     } else {
-      kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, CHECK_(KlassHandle()));
+      found_klass = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, CHECK_NULL);
     }
-    found_klass = KlassHandle(THREAD, kls);
   }
 
   // If we fail to find an array klass, look again for its element type.
@@ -135,21 +133,21 @@
     // Build it on the fly if the element class exists.
     TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1,
                                                  sym->utf8_length()-1,
-                                                 CHECK_(KlassHandle()));
+                                                 CHECK_NULL);
 
     // Get element Klass recursively.
-    KlassHandle elem_klass =
+    Klass* elem_klass =
       get_klass_by_name_impl(accessing_klass,
                              cpool,
                              elem_sym,
                              require_local);
-    if (!elem_klass.is_null()) {
+    if (elem_klass != NULL) {
       // Now make an array for it
-      return elem_klass->array_klass(CHECK_(KlassHandle()));
+      return elem_klass->array_klass(CHECK_NULL);
     }
   }
 
-  if (found_klass.is_null() && !cpool.is_null() && cpool->has_preresolution()) {
+  if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
     // Look inside the constant pool for pre-resolved class entries.
     for (int i = cpool->length() - 1; i >= 1; i--) {
       if (cpool->tag_at(i).is_klass()) {
@@ -161,45 +159,45 @@
     }
   }
 
-  return found_klass();
+  return found_klass;
 }
 
 // ------------------------------------------------------------------
-KlassHandle JVMCIEnv::get_klass_by_name(KlassHandle accessing_klass,
+Klass* JVMCIEnv::get_klass_by_name(Klass* accessing_klass,
                                   Symbol* klass_name,
                                   bool require_local) {
   ResourceMark rm;
   constantPoolHandle cpool;
   return get_klass_by_name_impl(accessing_klass,
-                                                 cpool,
-                                                 klass_name,
-                                                 require_local);
+                                cpool,
+                                klass_name,
+                                require_local);
 }
 
 // ------------------------------------------------------------------
 // Implementation of get_klass_by_index.
-KlassHandle JVMCIEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
+Klass* JVMCIEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
                                         int index,
                                         bool& is_accessible,
-                                        KlassHandle accessor) {
+                                        Klass* accessor) {
   JVMCI_EXCEPTION_CONTEXT;
-  KlassHandle klass (THREAD, ConstantPool::klass_at_if_loaded(cpool, index));
+  Klass* klass = ConstantPool::klass_at_if_loaded(cpool, index);
   Symbol* klass_name = NULL;
-  if (klass.is_null()) {
+  if (klass == NULL) {
     klass_name = cpool->klass_name_at(index);
   }
 
-  if (klass.is_null()) {
+  if (klass == NULL) {
     // Not found in constant pool.  Use the name to do the lookup.
-    KlassHandle k = get_klass_by_name_impl(accessor,
-                                        cpool,
-                                        klass_name,
-                                        false);
+    Klass* k = get_klass_by_name_impl(accessor,
+                                      cpool,
+                                      klass_name,
+                                      false);
     // Calculate accessibility the hard way.
-    if (k.is_null()) {
+    if (k == NULL) {
       is_accessible = false;
     } else if (k->class_loader() != accessor->class_loader() &&
-               get_klass_by_name_impl(accessor, cpool, k->name(), true).is_null()) {
+               get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) {
       // Loaded only remotely.  Not linked yet.
       is_accessible = false;
     } else {
@@ -207,7 +205,7 @@
       is_accessible = check_klass_accessibility(accessor, k);
     }
     if (!is_accessible) {
-      return KlassHandle();
+      return NULL;
     }
     return k;
   }
@@ -219,13 +217,12 @@
 
 // ------------------------------------------------------------------
 // Get a klass from the constant pool.
-KlassHandle JVMCIEnv::get_klass_by_index(const constantPoolHandle& cpool,
-                                   int index,
-                                   bool& is_accessible,
-                                   KlassHandle accessor) {
+Klass* JVMCIEnv::get_klass_by_index(const constantPoolHandle& cpool,
+                                    int index,
+                                    bool& is_accessible,
+                                    Klass* accessor) {
   ResourceMark rm;
-  KlassHandle result = get_klass_by_index_impl(cpool, index, is_accessible, accessor);
-  return result;
+  return get_klass_by_index_impl(cpool, index, is_accessible, accessor);
 }
 
 // ------------------------------------------------------------------
@@ -233,7 +230,7 @@
 //
 // Implementation note: the results of field lookups are cached
 // in the accessor klass.
-void JVMCIEnv::get_field_by_index_impl(instanceKlassHandle klass, fieldDescriptor& field_desc,
+void JVMCIEnv::get_field_by_index_impl(InstanceKlass* klass, fieldDescriptor& field_desc,
                                         int index) {
   JVMCI_EXCEPTION_CONTEXT;
 
@@ -251,9 +248,9 @@
   // Get the field's declared holder.
   int holder_index = cpool->klass_ref_index_at(index);
   bool holder_is_accessible;
-  KlassHandle declared_holder = get_klass_by_index(cpool, holder_index,
-                                               holder_is_accessible,
-                                               klass);
+  Klass* declared_holder = get_klass_by_index(cpool, holder_index,
+                                              holder_is_accessible,
+                                              klass);
 
   // The declared holder of this field may not have been loaded.
   // Bail out with partial field information.
@@ -264,7 +261,7 @@
 
   // Perform the field lookup.
   Klass*  canonical_holder =
-    InstanceKlass::cast(declared_holder())->find_field(name, signature, &field_desc);
+    InstanceKlass::cast(declared_holder)->find_field(name, signature, &field_desc);
   if (canonical_holder == NULL) {
     return;
   }
@@ -274,7 +271,7 @@
 
 // ------------------------------------------------------------------
 // Get a field by index from a klass's constant pool.
-void JVMCIEnv::get_field_by_index(instanceKlassHandle accessor, fieldDescriptor& fd, int index) {
+void JVMCIEnv::get_field_by_index(InstanceKlass* accessor, fieldDescriptor& fd, int index) {
   ResourceMark rm;
   return get_field_by_index_impl(accessor, fd, index);
 }
@@ -282,17 +279,17 @@
 // ------------------------------------------------------------------
 // Perform an appropriate method lookup based on accessor, holder,
 // name, signature, and bytecode.
-methodHandle JVMCIEnv::lookup_method(instanceKlassHandle h_accessor,
-                               KlassHandle   h_holder,
-                               Symbol*       name,
-                               Symbol*       sig,
+methodHandle JVMCIEnv::lookup_method(InstanceKlass* accessor,
+                               Klass*         holder,
+                               Symbol*        name,
+                               Symbol*        sig,
                                Bytecodes::Code bc,
                                constantTag   tag) {
   // Accessibility checks are performed in JVMCIEnv::get_method_by_index_impl().
-  assert(check_klass_accessibility(h_accessor, h_holder), "holder not accessible");
+  assert(check_klass_accessibility(accessor, holder), "holder not accessible");
 
   methodHandle dest_method;
-  LinkInfo link_info(h_holder, name, sig, h_accessor, LinkInfo::needs_access_check, tag);
+  LinkInfo link_info(holder, name, sig, accessor, LinkInfo::needs_access_check, tag);
   switch (bc) {
   case Bytecodes::_invokestatic:
     dest_method =
@@ -320,7 +317,7 @@
 // ------------------------------------------------------------------
 methodHandle JVMCIEnv::get_method_by_index_impl(const constantPoolHandle& cpool,
                                           int index, Bytecodes::Code bc,
-                                          instanceKlassHandle accessor) {
+                                          InstanceKlass* accessor) {
   if (bc == Bytecodes::_invokedynamic) {
     ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index);
     bool is_resolved = !cpce->is_f1_null();
@@ -336,15 +333,15 @@
 
   int holder_index = cpool->klass_ref_index_at(index);
   bool holder_is_accessible;
-  KlassHandle holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor);
+  Klass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor);
 
   // Get the method's name and signature.
   Symbol* name_sym = cpool->name_ref_at(index);
   Symbol* sig_sym  = cpool->signature_ref_at(index);
 
   if (cpool->has_preresolution()
-      || ((holder() == SystemDictionary::MethodHandle_klass() || holder() == SystemDictionary::VarHandle_klass()) &&
-          MethodHandles::is_signature_polymorphic_name(holder(), name_sym))) {
+      || ((holder == SystemDictionary::MethodHandle_klass() || holder == SystemDictionary::VarHandle_klass()) &&
+          MethodHandles::is_signature_polymorphic_name(holder, name_sym))) {
     // Short-circuit lookups for JSR 292-related call sites.
     // That is, do not rely only on name-based lookups, because they may fail
     // if the names are not resolvable in the boot class loader (7056328).
@@ -385,14 +382,14 @@
 }
 
 // ------------------------------------------------------------------
-instanceKlassHandle JVMCIEnv::get_instance_klass_for_declared_method_holder(KlassHandle method_holder) {
+InstanceKlass* JVMCIEnv::get_instance_klass_for_declared_method_holder(Klass* method_holder) {
   // For the case of <array>.clone(), the method holder can be an ArrayKlass*
   // instead of an InstanceKlass*.  For that case simply pretend that the
   // declared holder is Object.clone since that's where the call will bottom out.
   if (method_holder->is_instance_klass()) {
-    return instanceKlassHandle(method_holder());
+    return InstanceKlass::cast(method_holder);
   } else if (method_holder->is_array_klass()) {
-    return instanceKlassHandle(SystemDictionary::Object_klass());
+    return SystemDictionary::Object_klass();
   } else {
     ShouldNotReachHere();
   }
@@ -403,7 +400,7 @@
 // ------------------------------------------------------------------
 methodHandle JVMCIEnv::get_method_by_index(const constantPoolHandle& cpool,
                                      int index, Bytecodes::Code bc,
-                                     instanceKlassHandle accessor) {
+                                     InstanceKlass* accessor) {
   ResourceMark rm;
   return get_method_by_index_impl(cpool, index, bc, accessor);
 }
--- a/hotspot/src/share/vm/jvmci/jvmciEnv.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/jvmciEnv.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -79,20 +79,18 @@
   // The CI treats a klass as loaded if it is consistently defined in
   // another loader, even if it hasn't yet been loaded in all loaders
   // that could potentially see it via delegation.
-  static KlassHandle get_klass_by_name(KlassHandle accessing_klass,
-                             Symbol* klass_name,
-                             bool require_local);
+  static Klass* get_klass_by_name(Klass* accessing_klass, Symbol* klass_name, bool require_local);
 
   // Constant pool access.
-  static KlassHandle   get_klass_by_index(const constantPoolHandle& cpool,
-                                int klass_index,
-                                bool& is_accessible,
-                                KlassHandle loading_klass);
-  static void   get_field_by_index(instanceKlassHandle loading_klass, fieldDescriptor& fd,
-                                int field_index);
+  static Klass* get_klass_by_index(const constantPoolHandle& cpool,
+                                   int klass_index,
+                                   bool& is_accessible,
+                                   Klass* loading_klass);
+  static void   get_field_by_index(InstanceKlass* loading_klass, fieldDescriptor& fd,
+                                   int field_index);
   static methodHandle  get_method_by_index(const constantPoolHandle& cpool,
-                                 int method_index, Bytecodes::Code bc,
-                                 instanceKlassHandle loading_klass);
+                                    int method_index, Bytecodes::Code bc,
+                                    InstanceKlass* loading_klass);
 
   JVMCIEnv(CompileTask* task, int system_dictionary_modification_counter);
 
@@ -110,26 +108,26 @@
   bool  _jvmti_can_post_on_exceptions;
 
   // Implementation methods for loading and constant pool access.
-  static KlassHandle get_klass_by_name_impl(KlassHandle& accessing_klass,
+  static Klass* get_klass_by_name_impl(Klass* accessing_klass,
                                   const constantPoolHandle& cpool,
                                   Symbol* klass_name,
                                   bool require_local);
-  static KlassHandle   get_klass_by_index_impl(const constantPoolHandle& cpool,
+  static Klass* get_klass_by_index_impl(const constantPoolHandle& cpool,
                                      int klass_index,
                                      bool& is_accessible,
-                                     KlassHandle loading_klass);
-  static void   get_field_by_index_impl(instanceKlassHandle loading_klass, fieldDescriptor& fd,
+                                     Klass* loading_klass);
+  static void   get_field_by_index_impl(InstanceKlass* loading_klass, fieldDescriptor& fd,
                                      int field_index);
   static methodHandle  get_method_by_index_impl(const constantPoolHandle& cpool,
                                       int method_index, Bytecodes::Code bc,
-                                      instanceKlassHandle loading_klass);
+                                      InstanceKlass* loading_klass);
 
   // Helper methods
-  static bool       check_klass_accessibility(KlassHandle accessing_klass, KlassHandle resolved_klass);
-  static methodHandle  lookup_method(instanceKlassHandle  accessor,
-                           KlassHandle     holder,
-                           Symbol*         name,
-                           Symbol*         sig,
+  static bool       check_klass_accessibility(Klass* accessing_klass, Klass* resolved_klass);
+  static methodHandle  lookup_method(InstanceKlass*  accessor,
+                           Klass*         holder,
+                           Symbol*        name,
+                           Symbol*        sig,
                            Bytecodes::Code bc,
                            constantTag     tag);
 
@@ -180,7 +178,7 @@
   // InstanceKlass*.  This is needed since the holder of a method in
   // the bytecodes could be an array type.  Basically this converts
   // array types into java/lang/Object and other types stay as they are.
-  static instanceKlassHandle get_instance_klass_for_declared_method_holder(KlassHandle klass);
+  static InstanceKlass* get_instance_klass_for_declared_method_holder(Klass* klass);
 };
 
 #endif // SHARE_VM_JVMCI_JVMCIENV_HPP
--- a/hotspot/src/share/vm/jvmci/jvmciRuntime.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/jvmciRuntime.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -107,12 +107,12 @@
   JRT_BLOCK;
   assert(klass->is_klass(), "not a class");
   Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
-  instanceKlassHandle h(thread, klass);
-  h->check_valid_for_instantiation(true, CHECK);
+  InstanceKlass* ik = InstanceKlass::cast(klass);
+  ik->check_valid_for_instantiation(true, CHECK);
   // make sure klass is initialized
-  h->initialize(CHECK);
+  ik->initialize(CHECK);
   // allocate instance and return via TLS
-  oop obj = h->allocate_instance(CHECK);
+  oop obj = ik->allocate_instance(CHECK);
   thread->set_vm_result(obj);
   JRT_BLOCK_END;
 
@@ -187,7 +187,7 @@
 JRT_END
 
 JRT_ENTRY(void, JVMCIRuntime::dynamic_new_instance(JavaThread* thread, oopDesc* type_mirror))
-  instanceKlassHandle klass(THREAD, java_lang_Class::as_Klass(type_mirror));
+  InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(type_mirror));
 
   if (klass == NULL) {
     ResourceMark rm(THREAD);
@@ -641,7 +641,7 @@
 
 Handle JVMCIRuntime::callStatic(const char* className, const char* methodName, const char* signature, JavaCallArguments* args, TRAPS) {
   TempNewSymbol name = SymbolTable::new_symbol(className, CHECK_(Handle()));
-  KlassHandle klass = SystemDictionary::resolve_or_fail(name, true, CHECK_(Handle()));
+  Klass* klass = SystemDictionary::resolve_or_fail(name, true, CHECK_(Handle()));
   TempNewSymbol runtime = SymbolTable::new_symbol(methodName, CHECK_(Handle()));
   TempNewSymbol sig = SymbolTable::new_symbol(signature, CHECK_(Handle()));
   JavaValue result(T_OBJECT);
@@ -650,14 +650,14 @@
   } else {
     JavaCalls::call_static(&result, klass, runtime, sig, args, CHECK_(Handle()));
   }
-  return Handle((oop)result.get_jobject());
+  return Handle(THREAD, (oop)result.get_jobject());
 }
 
 void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(TRAPS) {
   guarantee(!_HotSpotJVMCIRuntime_initialized, "cannot reinitialize HotSpotJVMCIRuntime");
   JVMCIRuntime::initialize_well_known_classes(CHECK);
   // This should only be called in the context of the JVMCI class being initialized
-  instanceKlassHandle klass = InstanceKlass::cast(SystemDictionary::JVMCI_klass());
+  InstanceKlass* klass = SystemDictionary::JVMCI_klass();
   guarantee(klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD),
          "HotSpotJVMCIRuntime initialization should only be triggered through JVMCI initialization");
 
@@ -684,7 +684,7 @@
          "compilation level adjustment out of bounds");
   _comp_level_adjustment = (CompLevelAdjustment) adjustment;
   _HotSpotJVMCIRuntime_initialized = true;
-  _HotSpotJVMCIRuntime_instance = JNIHandles::make_global(result());
+  _HotSpotJVMCIRuntime_instance = JNIHandles::make_global(result);
 }
 
 void JVMCIRuntime::initialize_JVMCI(TRAPS) {
@@ -863,9 +863,9 @@
   JavaValue result(T_INT);
   JavaCallArguments args;
   args.push_oop(receiver);
-  args.push_oop(method->method_holder()->java_mirror());
-  args.push_oop(name());
-  args.push_oop(sig());
+  args.push_oop(Handle(THREAD, method->method_holder()->java_mirror()));
+  args.push_oop(name);
+  args.push_oop(sig);
   args.push_int(is_osr);
   args.push_int(level);
   JavaCalls::call_special(&result, receiver->klass(), vmSymbols::adjustCompilationLevel_name(),
--- a/hotspot/src/share/vm/jvmci/jvmciRuntime.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/jvmci/jvmciRuntime.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -75,7 +75,7 @@
    */
   static Handle get_HotSpotJVMCIRuntime(TRAPS) {
     initialize_JVMCI(CHECK_(Handle()));
-    return Handle(JNIHandles::resolve_non_null(_HotSpotJVMCIRuntime_instance));
+    return Handle(THREAD, JNIHandles::resolve_non_null(_HotSpotJVMCIRuntime_instance));
   }
 
   static jobject get_HotSpotJVMCIRuntime_jobject(TRAPS) {
--- a/hotspot/src/share/vm/logging/logTag.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/logging/logTag.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -48,7 +48,9 @@
   LOG_TAG(class) \
   LOG_TAG(classhisto) \
   LOG_TAG(cleanup) \
+  LOG_TAG(codecache) \
   LOG_TAG(compaction) \
+  LOG_TAG(compilation) \
   LOG_TAG(constraints) \
   LOG_TAG(constantpool) \
   LOG_TAG(coops) \
@@ -69,7 +71,9 @@
   LOG_TAG(ihop) \
   LOG_TAG(iklass) \
   LOG_TAG(init) \
+  LOG_TAG(inlining) \
   LOG_TAG(itables) \
+  LOG_TAG(jit) \
   LOG_TAG(jni) \
   LOG_TAG(jvmti) \
   LOG_TAG(liveness) \
--- a/hotspot/src/share/vm/memory/metaspace.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/memory/metaspace.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -74,6 +74,22 @@
   NumberOfInUseLists = 4
 };
 
+// Helper, returns a descriptive name for the given index.
+static const char* chunk_size_name(ChunkIndex index) {
+  switch (index) {
+    case SpecializedIndex:
+      return "specialized";
+    case SmallIndex:
+      return "small";
+    case MediumIndex:
+      return "medium";
+    case HumongousIndex:
+      return "humongous";
+    default:
+      return "Invalid index";
+  }
+}
+
 enum ChunkSizes {    // in words.
   ClassSpecializedChunk = 128,
   SpecializedChunk = 128,
@@ -102,20 +118,32 @@
   //   SpecializedChunk
   //   SmallChunk
   //   MediumChunk
-  //   HumongousChunk
   ChunkList _free_chunks[NumberOfFreeLists];
 
+  // Return non-humongous chunk list by its index.
+  ChunkList* free_chunks(ChunkIndex index);
+
+  // Returns non-humongous chunk list for the given chunk word size.
+  ChunkList* find_free_chunks_list(size_t word_size);
+
   //   HumongousChunk
   ChunkTreeDictionary _humongous_dictionary;
 
+  // Returns the humongous chunk dictionary.
+  ChunkTreeDictionary* humongous_dictionary() {
+    return &_humongous_dictionary;
+  }
+
   // ChunkManager in all lists of this type
   size_t _free_chunks_total;
   size_t _free_chunks_count;
 
   void dec_free_chunks_total(size_t v) {
-    assert(_free_chunks_count > 0 &&
-             _free_chunks_total > 0,
-             "About to go negative");
+    assert(_free_chunks_count > 0,
+      "ChunkManager::_free_chunks_count: about to go negative (" SIZE_FORMAT ").", _free_chunks_count);
+    assert(_free_chunks_total >= v,
+      "ChunkManager::_free_chunks_total: about to go negative"
+       "(now: " SIZE_FORMAT ", decrement value: " SIZE_FORMAT ").", _free_chunks_total, v);
     Atomic::add_ptr(-1, &_free_chunks_count);
     jlong minus_v = (jlong) - (jlong) v;
     Atomic::add_ptr(minus_v, &_free_chunks_total);
@@ -156,13 +184,20 @@
   // for special, small, medium, and humongous chunks.
   ChunkIndex list_index(size_t size);
 
-  // Remove the chunk from its freelist.  It is
-  // expected to be on one of the _free_chunks[] lists.
+  // Map a given index to the chunk size.
+  size_t size_by_index(ChunkIndex index);
+
+  // Take a chunk from the ChunkManager. The chunk is expected to be in
+  // the chunk manager (the freelist if non-humongous, the dictionary if
+  // humongous).
   void remove_chunk(Metachunk* chunk);
 
+  // Return a single chunk of type index to the ChunkManager.
+  void return_single_chunk(ChunkIndex index, Metachunk* chunk);
+
   // Add the simple linked list of chunks to the freelist of chunks
   // of type index.
-  void return_chunks(ChunkIndex index, Metachunk* chunks);
+  void return_chunk_list(ChunkIndex index, Metachunk* chunk);
 
   // Total of the space in the free chunks list
   size_t free_chunks_total_words();
@@ -175,14 +210,6 @@
     Atomic::add_ptr(count, &_free_chunks_count);
     Atomic::add_ptr(v, &_free_chunks_total);
   }
-  ChunkTreeDictionary* humongous_dictionary() {
-    return &_humongous_dictionary;
-  }
-
-  ChunkList* free_chunks(ChunkIndex index);
-
-  // Returns the list for the given chunk word size.
-  ChunkList* find_free_chunks_list(size_t word_size);
 
   // Remove from a list by size.  Selects list based on size of chunk.
   Metachunk* free_chunks_get(size_t chunk_word_size);
@@ -735,8 +762,6 @@
 
   Mutex* lock() const { return _lock; }
 
-  const char* chunk_size_name(ChunkIndex index) const;
-
  protected:
   void initialize();
 
@@ -1246,13 +1271,13 @@
   DEBUG_ONLY(verify_container_count();)
   for (int i = (int)MediumIndex; i >= (int)ZeroIndex; --i) {
     ChunkIndex index = (ChunkIndex)i;
-    size_t chunk_size = chunk_manager->free_chunks(index)->size();
+    size_t chunk_size = chunk_manager->size_by_index(index);
 
     while (free_words_in_vs() >= chunk_size) {
       Metachunk* chunk = get_chunk_vs(chunk_size);
       assert(chunk != NULL, "allocation should have been successful");
 
-      chunk_manager->return_chunks(index, chunk);
+      chunk_manager->return_single_chunk(index, chunk);
       chunk_manager->inc_free_chunks_total(chunk_size);
     }
     DEBUG_ONLY(verify_container_count();)
@@ -1743,6 +1768,28 @@
   return _free_chunks_count;
 }
 
+ChunkIndex ChunkManager::list_index(size_t size) {
+  if (size_by_index(SpecializedIndex) == size) {
+    return SpecializedIndex;
+  }
+  if (size_by_index(SmallIndex) == size) {
+    return SmallIndex;
+  }
+  const size_t med_size = size_by_index(MediumIndex);
+  if (med_size == size) {
+    return MediumIndex;
+  }
+
+  assert(size > med_size, "Not a humongous chunk");
+  return HumongousIndex;
+}
+
+size_t ChunkManager::size_by_index(ChunkIndex index) {
+  index_bounds_check(index);
+  assert(index != HumongousIndex, "Do not call for humongous chunks.");
+  return free_chunks(index)->size();
+}
+
 void ChunkManager::locked_verify_free_chunks_total() {
   assert_lock_strong(SpaceManager::expand_lock());
   assert(sum_free_chunks() == _free_chunks_total,
@@ -1923,6 +1970,73 @@
   return chunk;
 }
 
+void ChunkManager::return_single_chunk(ChunkIndex index, Metachunk* chunk) {
+  assert_lock_strong(SpaceManager::expand_lock());
+  assert(chunk != NULL, "Expected chunk.");
+  assert(chunk->container() != NULL, "Container should have been set.");
+  assert(chunk->is_tagged_free() == false, "Chunk should be in use.");
+  index_bounds_check(index);
+
+  // Note: mangle *before* returning the chunk to the freelist or dictionary. It does not
+  // matter for the freelist (non-humongous chunks), but the humongous chunk dictionary
+  // keeps tree node pointers in the chunk payload area which mangle will overwrite.
+  NOT_PRODUCT(chunk->mangle(badMetaWordVal);)
+
+  if (index != HumongousIndex) {
+    // Return non-humongous chunk to freelist.
+    ChunkList* list = free_chunks(index);
+    assert(list->size() == chunk->word_size(), "Wrong chunk type.");
+    list->return_chunk_at_head(chunk);
+    log_trace(gc, metaspace, freelist)("returned one %s chunk at " PTR_FORMAT " to freelist.",
+        chunk_size_name(index), p2i(chunk));
+  } else {
+    // Return humongous chunk to dictionary.
+    assert(chunk->word_size() > free_chunks(MediumIndex)->size(), "Wrong chunk type.");
+    assert(chunk->word_size() % free_chunks(SpecializedIndex)->size() == 0,
+           "Humongous chunk has wrong alignment.");
+    _humongous_dictionary.return_chunk(chunk);
+    log_trace(gc, metaspace, freelist)("returned one %s chunk at " PTR_FORMAT " (word size " SIZE_FORMAT ") to freelist.",
+        chunk_size_name(index), p2i(chunk), chunk->word_size());
+  }
+  chunk->container()->dec_container_count();
+  DEBUG_ONLY(chunk->set_is_tagged_free(true);)
+
+}
+
+void ChunkManager::return_chunk_list(ChunkIndex index, Metachunk* chunks) {
+  index_bounds_check(index);
+  if (chunks == NULL) {
+    return;
+  }
+  LogTarget(Trace, gc, metaspace, freelist) log;
+  if (log.is_enabled()) { // tracing
+    log.print("returning list of %s chunks...", chunk_size_name(index));
+  }
+  unsigned num_chunks_returned = 0;
+  size_t size_chunks_returned = 0;
+  Metachunk* cur = chunks;
+  while (cur != NULL) {
+    // Capture the next link before it is changed
+    // by the call to return_chunk_at_head();
+    Metachunk* next = cur->next();
+    if (log.is_enabled()) { // tracing
+      num_chunks_returned ++;
+      size_chunks_returned += cur->word_size();
+    }
+    return_single_chunk(index, cur);
+    cur = next;
+  }
+  if (log.is_enabled()) { // tracing
+    log.print("returned %u %s chunks to freelist, total word size " SIZE_FORMAT ".",
+        num_chunks_returned, chunk_size_name(index), size_chunks_returned);
+    if (index != HumongousIndex) {
+      log.print("updated freelist count: " SIZE_FORMAT ".", free_chunks(index)->size());
+    } else {
+      log.print("updated dictionary count " SIZE_FORMAT ".", _humongous_dictionary.total_count());
+    }
+  }
+}
+
 void ChunkManager::print_on(outputStream* out) const {
   const_cast<ChunkManager *>(this)->humongous_dictionary()->report_statistics(out);
 }
@@ -2256,32 +2370,6 @@
   log_trace(gc, metaspace, freelist)("SpaceManager(): " PTR_FORMAT, p2i(this));
 }
 
-void ChunkManager::return_chunks(ChunkIndex index, Metachunk* chunks) {
-  if (chunks == NULL) {
-    return;
-  }
-  ChunkList* list = free_chunks(index);
-  assert(list->size() == chunks->word_size(), "Mismatch in chunk sizes");
-  assert_lock_strong(SpaceManager::expand_lock());
-  Metachunk* cur = chunks;
-
-  // This returns chunks one at a time.  If a new
-  // class List can be created that is a base class
-  // of FreeList then something like FreeList::prepend()
-  // can be used in place of this loop
-  while (cur != NULL) {
-    assert(cur->container() != NULL, "Container should have been set");
-    cur->container()->dec_container_count();
-    // Capture the next link before it is changed
-    // by the call to return_chunk_at_head();
-    Metachunk* next = cur->next();
-    DEBUG_ONLY(cur->set_is_tagged_free(true);)
-    NOT_PRODUCT(cur->mangle(badMetaWordVal);)
-    list->return_chunk_at_head(cur);
-    cur = next;
-  }
-}
-
 SpaceManager::~SpaceManager() {
   // This call this->_lock which can't be done while holding expand_lock()
   assert(sum_capacity_in_chunks_in_use() == allocated_chunks_words(),
@@ -2317,42 +2405,12 @@
   // Follow each list of chunks-in-use and add them to the
   // free lists.  Each list is NULL terminated.
 
-  for (ChunkIndex i = ZeroIndex; i < HumongousIndex; i = next_chunk_index(i)) {
-    log.trace("returned " SIZE_FORMAT " %s chunks to freelist", sum_count_in_chunks_in_use(i), chunk_size_name(i));
+  for (ChunkIndex i = ZeroIndex; i <= HumongousIndex; i = next_chunk_index(i)) {
     Metachunk* chunks = chunks_in_use(i);
-    chunk_manager()->return_chunks(i, chunks);
+    chunk_manager()->return_chunk_list(i, chunks);
     set_chunks_in_use(i, NULL);
-    log.trace("updated freelist count " SSIZE_FORMAT " %s", chunk_manager()->free_chunks(i)->count(), chunk_size_name(i));
-    assert(i != HumongousIndex, "Humongous chunks are handled explicitly later");
   }
 
-  // The medium chunk case may be optimized by passing the head and
-  // tail of the medium chunk list to add_at_head().  The tail is often
-  // the current chunk but there are probably exceptions.
-
-  // Humongous chunks
-  log.trace("returned " SIZE_FORMAT " %s humongous chunks to dictionary",
-            sum_count_in_chunks_in_use(HumongousIndex), chunk_size_name(HumongousIndex));
-  log.trace("Humongous chunk dictionary: ");
-  // Humongous chunks are never the current chunk.
-  Metachunk* humongous_chunks = chunks_in_use(HumongousIndex);
-
-  while (humongous_chunks != NULL) {
-    DEBUG_ONLY(humongous_chunks->set_is_tagged_free(true);)
-    NOT_PRODUCT(humongous_chunks->mangle(badMetaWordVal);)
-    log.trace(PTR_FORMAT " (" SIZE_FORMAT ") ", p2i(humongous_chunks), humongous_chunks->word_size());
-    assert(humongous_chunks->word_size() == (size_t)
-           align_size_up(humongous_chunks->word_size(),
-                             smallest_chunk_size()),
-           "Humongous chunk size is wrong: word size " SIZE_FORMAT
-           " granularity " SIZE_FORMAT,
-           humongous_chunks->word_size(), smallest_chunk_size());
-    Metachunk* next_humongous_chunks = humongous_chunks->next();
-    humongous_chunks->container()->dec_container_count();
-    chunk_manager()->humongous_dictionary()->return_chunk(humongous_chunks);
-    humongous_chunks = next_humongous_chunks;
-  }
-  log.trace("updated dictionary count " SIZE_FORMAT " %s", chunk_manager()->humongous_dictionary()->total_count(), chunk_size_name(HumongousIndex));
   chunk_manager()->slow_locked_verify();
 
   if (_block_freelists != NULL) {
@@ -2360,36 +2418,6 @@
   }
 }
 
-const char* SpaceManager::chunk_size_name(ChunkIndex index) const {
-  switch (index) {
-    case SpecializedIndex:
-      return "Specialized";
-    case SmallIndex:
-      return "Small";
-    case MediumIndex:
-      return "Medium";
-    case HumongousIndex:
-      return "Humongous";
-    default:
-      return NULL;
-  }
-}
-
-ChunkIndex ChunkManager::list_index(size_t size) {
-  if (free_chunks(SpecializedIndex)->size() == size) {
-    return SpecializedIndex;
-  }
-  if (free_chunks(SmallIndex)->size() == size) {
-    return SmallIndex;
-  }
-  if (free_chunks(MediumIndex)->size() == size) {
-    return MediumIndex;
-  }
-
-  assert(size > free_chunks(MediumIndex)->size(), "Not a humongous chunk");
-  return HumongousIndex;
-}
-
 void SpaceManager::deallocate(MetaWord* p, size_t word_size) {
   assert_lock_strong(_lock);
   // Allocations and deallocations are in raw_word_size
@@ -3781,7 +3809,10 @@
   if (UseSharedSpaces && MetaspaceShared::is_in_shared_space(ptr)) {
     return true;
   }
-
+  return contains_non_shared(ptr);
+}
+
+bool Metaspace::contains_non_shared(const void* ptr) {
   if (using_class_space() && get_space_list(ClassType)->contains(ptr)) {
      return true;
   }
@@ -4070,6 +4101,273 @@
   }
 }
 
+// ChunkManagerReturnTest stresses taking/returning chunks from the ChunkManager. It takes and
+// returns chunks from/to the ChunkManager while keeping track of the expected ChunkManager
+// content.
+class ChunkManagerReturnTestImpl {
+
+  VirtualSpaceNode _vsn;
+  ChunkManager _cm;
+
+  // The expected content of the chunk manager.
+  unsigned _chunks_in_chunkmanager;
+  size_t _words_in_chunkmanager;
+
+  // A fixed size pool of chunks. Chunks may be in the chunk manager (free) or not (in use).
+  static const int num_chunks = 256;
+  Metachunk* _pool[num_chunks];
+
+  // Helper, return a random position into the chunk pool.
+  static int get_random_position() {
+    return os::random() % num_chunks;
+  }
+
+  // Asserts that ChunkManager counters match expectations.
+  void assert_counters() {
+    assert(_vsn.container_count() == num_chunks - _chunks_in_chunkmanager, "vsn counter mismatch.");
+    assert(_cm.free_chunks_count() == _chunks_in_chunkmanager, "cm counter mismatch.");
+    assert(_cm.free_chunks_total_words() == _words_in_chunkmanager, "cm counter mismatch.");
+  }
+
+  // Get a random chunk size. Equal chance to get spec/med/small chunk size or
+  // a humongous chunk size. The latter itself is random in the range of [med+spec..4*med).
+  size_t get_random_chunk_size() {
+    const size_t sizes [] = { SpecializedChunk, SmallChunk, MediumChunk };
+    const int rand = os::random() % 4;
+    if (rand < 3) {
+      return sizes[rand];
+    } else {
+      // Note: this affects the max. size of space (see _vsn initialization in ctor).
+      return align_size_up(MediumChunk + 1 + (os::random() % (MediumChunk * 4)), SpecializedChunk);
+    }
+  }
+
+  // Starting at pool index <start>+1, find the next chunk tagged as either free or in use, depending
+  // on <is_free>. Search wraps. Returns its position, or -1 if no matching chunk was found.
+  int next_matching_chunk(int start, bool is_free) const {
+    assert(start >= 0 && start < num_chunks, "invalid parameter");
+    int pos = start;
+    do {
+      if (++pos == num_chunks) {
+        pos = 0;
+      }
+      if (_pool[pos]->is_tagged_free() == is_free) {
+        return pos;
+      }
+    } while (pos != start);
+    return -1;
+  }
+
+  // A structure to keep information about a chunk list including which
+  // chunks are part of this list. This is needed to keep information about a chunk list
+  // we will to return to the ChunkManager, because the original list will be destroyed.
+  struct AChunkList {
+    Metachunk* head;
+    Metachunk* all[num_chunks];
+    size_t size;
+    int num;
+    ChunkIndex index;
+  };
+
+  // Assemble, from the in-use chunks (not in the chunk manager) in the pool,
+  // a random chunk list of max. length <list_size> of chunks with the same
+  // ChunkIndex (chunk size).
+  // Returns false if list cannot be assembled. List is returned in the <out>
+  // structure. Returned list may be smaller than <list_size>.
+  bool assemble_random_chunklist(AChunkList* out, int list_size) {
+    // Choose a random in-use chunk from the pool...
+    const int headpos = next_matching_chunk(get_random_position(), false);
+    if (headpos == -1) {
+      return false;
+    }
+    Metachunk* const head = _pool[headpos];
+    out->all[0] = head;
+    assert(head->is_tagged_free() == false, "Chunk state mismatch");
+    // ..then go from there, chain it up with up to list_size - 1 number of other
+    // in-use chunks of the same index.
+    const ChunkIndex index = _cm.list_index(head->word_size());
+    int num_added = 1;
+    size_t size_added = head->word_size();
+    int pos = headpos;
+    Metachunk* tail = head;
+    do {
+      pos = next_matching_chunk(pos, false);
+      if (pos != headpos) {
+        Metachunk* c = _pool[pos];
+        assert(c->is_tagged_free() == false, "Chunk state mismatch");
+        if (index == _cm.list_index(c->word_size())) {
+          tail->set_next(c);
+          c->set_prev(tail);
+          tail = c;
+          out->all[num_added] = c;
+          num_added ++;
+          size_added += c->word_size();
+        }
+      }
+    } while (num_added < list_size && pos != headpos);
+    out->head = head;
+    out->index = index;
+    out->size = size_added;
+    out->num = num_added;
+    return true;
+  }
+
+  // Take a single random chunk from the ChunkManager.
+  bool take_single_random_chunk_from_chunkmanager() {
+    assert_counters();
+    _cm.locked_verify();
+    int pos = next_matching_chunk(get_random_position(), true);
+    if (pos == -1) {
+      return false;
+    }
+    Metachunk* c = _pool[pos];
+    assert(c->is_tagged_free(), "Chunk state mismatch");
+    // Note: instead of using ChunkManager::remove_chunk on this one chunk, we call
+    // ChunkManager::free_chunks_get() with this chunk's word size. We really want
+    // to exercise ChunkManager::free_chunks_get() because that one gets called for
+    // normal chunk allocation.
+    Metachunk* c2 = _cm.free_chunks_get(c->word_size());
+    assert(c2 != NULL, "Unexpected.");
+    assert(!c2->is_tagged_free(), "Chunk state mismatch");
+    assert(c2->next() == NULL && c2->prev() == NULL, "Chunk should be outside of a list.");
+    _chunks_in_chunkmanager --;
+    _words_in_chunkmanager -= c->word_size();
+    assert_counters();
+    _cm.locked_verify();
+    return true;
+  }
+
+  // Returns a single random chunk to the chunk manager. Returns false if that
+  // was not possible (all chunks are already in the chunk manager).
+  bool return_single_random_chunk_to_chunkmanager() {
+    assert_counters();
+    _cm.locked_verify();
+    int pos = next_matching_chunk(get_random_position(), false);
+    if (pos == -1) {
+      return false;
+    }
+    Metachunk* c = _pool[pos];
+    assert(c->is_tagged_free() == false, "wrong chunk information");
+    _cm.return_single_chunk(_cm.list_index(c->word_size()), c);
+    _chunks_in_chunkmanager ++;
+    _words_in_chunkmanager += c->word_size();
+    // (Note: until 8170520 is fixed, internal ChunkManager counters have to be updated
+    // by the caller - but only when returning chunks, ChunkManager->remove_chunk()
+    // already updates the counter.)
+    _cm.inc_free_chunks_total(c->word_size(), 1);
+    assert(c->is_tagged_free() == true, "wrong chunk information");
+    assert_counters();
+    _cm.locked_verify();
+    return true;
+  }
+
+  // Return a random chunk list to the chunk manager. Returns the length of the
+  // returned list.
+  int return_random_chunk_list_to_chunkmanager(int list_size) {
+    assert_counters();
+    _cm.locked_verify();
+    AChunkList aChunkList;
+    if (!assemble_random_chunklist(&aChunkList, list_size)) {
+      return 0;
+    }
+    // Before returning chunks are returned, they should be tagged in use.
+    for (int i = 0; i < aChunkList.num; i ++) {
+      assert(!aChunkList.all[i]->is_tagged_free(), "chunk state mismatch.");
+    }
+    _cm.return_chunk_list(aChunkList.index, aChunkList.head);
+    _chunks_in_chunkmanager += aChunkList.num;
+    _words_in_chunkmanager += aChunkList.size;
+    // (Note: until 8170520 is fixed, internal ChunkManager counters have to be updated
+    // by the caller - but only when returning chunks, ChunkManager->remove_chunk()
+    // already updates the counter.)
+    _cm.inc_free_chunks_total(aChunkList.size, aChunkList.num);
+    // After all chunks are returned, check that they are now tagged free.
+    for (int i = 0; i < aChunkList.num; i ++) {
+      assert(aChunkList.all[i]->is_tagged_free(), "chunk state mismatch.");
+    }
+    assert_counters();
+    _cm.locked_verify();
+    return aChunkList.num;
+  }
+
+public:
+
+  ChunkManagerReturnTestImpl()
+    : _vsn(align_size_up(MediumChunk * num_chunks * 5 * sizeof(MetaWord), Metaspace::reserve_alignment()))
+    , _cm(SpecializedChunk, SmallChunk, MediumChunk)
+    , _chunks_in_chunkmanager(0)
+    , _words_in_chunkmanager(0)
+  {
+    MutexLockerEx ml(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
+    // Allocate virtual space and allocate random chunks. Keep these chunks in the _pool. These chunks are
+    // "in use", because not yet added to any chunk manager.
+    _vsn.initialize();
+    _vsn.expand_by(_vsn.reserved_words(), _vsn.reserved_words());
+    for (int i = 0; i < num_chunks; i ++) {
+      const size_t size = get_random_chunk_size();
+      _pool[i] = _vsn.get_chunk_vs(size);
+      assert(_pool[i] != NULL, "allocation failed");
+    }
+    assert_counters();
+    _cm.locked_verify();
+  }
+
+  // Test entry point.
+  // Return some chunks to the chunk manager (return phase). Take some chunks out (take phase). Repeat.
+  // Chunks are choosen randomly. Number of chunks to return or taken are choosen randomly, but affected
+  // by the <phase_length_factor> argument: a factor of 0.0 will cause the test to quickly alternate between
+  // returning and taking, whereas a factor of 1.0 will take/return all chunks from/to the
+  // chunks manager, thereby emptying or filling it completely.
+  void do_test(float phase_length_factor) {
+    MutexLockerEx ml(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
+    assert_counters();
+    // Execute n operations, and operation being the move of a single chunk to/from the chunk manager.
+    const int num_max_ops = num_chunks * 100;
+    int num_ops = num_max_ops;
+    const int average_phase_length = (int)(phase_length_factor * num_chunks);
+    int num_ops_until_switch = MAX2(1, (int)(average_phase_length + os::random() % 8 - 4));
+    bool return_phase = true;
+    while (num_ops > 0) {
+      int chunks_moved = 0;
+      if (return_phase) {
+        // Randomly switch between returning a single chunk or a random length chunk list.
+        if (os::random() % 2 == 0) {
+          if (return_single_random_chunk_to_chunkmanager()) {
+            chunks_moved = 1;
+          }
+        } else {
+          const int list_length = MAX2(1, (int)(os::random() % num_ops_until_switch));
+          chunks_moved = return_random_chunk_list_to_chunkmanager(list_length);
+        }
+      } else {
+        // Breath out.
+        if (take_single_random_chunk_from_chunkmanager()) {
+          chunks_moved = 1;
+        }
+      }
+      num_ops -= chunks_moved;
+      num_ops_until_switch -= chunks_moved;
+      if (chunks_moved == 0 || num_ops_until_switch <= 0) {
+        return_phase = !return_phase;
+        num_ops_until_switch = MAX2(1, (int)(average_phase_length + os::random() % 8 - 4));
+      }
+    }
+  }
+};
+
+void* setup_chunkmanager_returntests() {
+  ChunkManagerReturnTestImpl* p = new ChunkManagerReturnTestImpl();
+  return p;
+}
+
+void teardown_chunkmanager_returntests(void* p) {
+  delete (ChunkManagerReturnTestImpl*) p;
+}
+
+void run_chunkmanager_returntests(void* p, float phase_length) {
+  ChunkManagerReturnTestImpl* test = (ChunkManagerReturnTestImpl*) p;
+  test->do_test(phase_length);
+}
 
 // The following test is placed here instead of a gtest / unittest file
 // because the ChunkManager class is only available in this file.
--- a/hotspot/src/share/vm/memory/metaspace.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/memory/metaspace.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -243,6 +243,7 @@
   void deallocate(MetaWord* ptr, size_t byte_size, bool is_class);
 
   static bool contains(const void* ptr);
+  static bool contains_non_shared(const void* ptr);
 
   void dump(outputStream* const out) const;
 
--- a/hotspot/src/share/vm/memory/metaspaceShared.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/memory/metaspaceShared.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,8 +40,13 @@
 #include "memory/metaspace.hpp"
 #include "memory/metaspaceShared.hpp"
 #include "memory/resourceArea.hpp"
+#include "oops/instanceClassLoaderKlass.hpp"
+#include "oops/instanceMirrorKlass.hpp"
+#include "oops/instanceRefKlass.hpp"
+#include "oops/objArrayKlass.hpp"
 #include "oops/objArrayOop.hpp"
 #include "oops/oop.inline.hpp"
+#include "oops/typeArrayKlass.hpp"
 #include "runtime/timerTrace.hpp"
 #include "runtime/os.hpp"
 #include "runtime/signature.hpp"
@@ -229,85 +234,244 @@
   }
 }
 
-// Patch C++ vtable pointer in metadata.
-
-// Klass and other metadata objects contain references to c++ vtables in the
-// JVM library.
-// Fix them to point to our constructed vtables.  However, don't iterate
-// across the space while doing this, as that causes the vtables to be
-// patched, undoing our useful work.  Instead, iterate to make a list,
-// then use the list to do the fixing.
+// Objects of the Metadata types (such as Klass and ConstantPool) have C++ vtables.
+// (In GCC this is the field <Type>::_vptr, i.e., first word in the object.)
+//
+// Addresses of the vtables and the methods may be different across JVM runs,
+// if libjvm.so is dynamically loaded at a different base address.
+//
+// To ensure that the Metadata objects in the CDS archive always have the correct vtable:
 //
-// Our constructed vtables:
-// Dump time:
-//  1. init_self_patching_vtbl_list: table of pointers to current virtual method addrs
-//  2. generate_vtable_methods: create jump table, appended to above vtbl_list
-//  3. patch_klass_vtables: for Klass list, patch the vtable entry in klass and
-//     associated metadata to point to jump table rather than to current vtbl
-// Table layout: NOTE FIXED SIZE
-//   1. vtbl pointers
-//   2. #Klass X #virtual methods per Klass
-//   1 entry for each, in the order:
-//   Klass1:method1 entry, Klass1:method2 entry, ... Klass1:method<num_virtuals> entry
-//   Klass2:method1 entry, Klass2:method2 entry, ... Klass2:method<num_virtuals> entry
-//   ...
-//   Klass<vtbl_list_size>:method1 entry, Klass<vtbl_list_size>:method2 entry,
-//       ... Klass<vtbl_list_size>:method<num_virtuals> entry
-//  Sample entry: (Sparc):
-//   save(sp, -256, sp)
-//   ba,pt common_code
-//   mov XXX, %L0       %L0 gets: Klass index <<8 + method index (note: max method index 255)
+// + at dump time:  we redirect the _vptr to point to our own vtables inside
+//                  the CDS image
+// + at run time:   we clone the actual contents of the vtables from libjvm.so
+//                  into our own tables.
+
+// Currently, the archive contain ONLY the following types of objects that have C++ vtables.
+#define CPP_VTABLE_PATCH_TYPES_DO(f) \
+  f(ConstantPool) \
+  f(InstanceKlass) \
+  f(InstanceClassLoaderKlass) \
+  f(InstanceMirrorKlass) \
+  f(InstanceRefKlass) \
+  f(Method) \
+  f(ObjArrayKlass) \
+  f(TypeArrayKlass)
+
+class CppVtableInfo {
+  intptr_t _vtable_size;
+  intptr_t _cloned_vtable[1];
+public:
+  static int num_slots(int vtable_size) {
+    return 1 + vtable_size; // Need to add the space occupied by _vtable_size;
+  }
+  int vtable_size()           { return int(uintx(_vtable_size)); }
+  void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
+  intptr_t* cloned_vtable()   { return &_cloned_vtable[0]; }
+  void zero()                 { memset(_cloned_vtable, 0, sizeof(intptr_t) * vtable_size()); }
+  // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
+  intptr_t* next(int vtable_size) {
+    return &_cloned_vtable[vtable_size];
+  }
+};
+
+template <class T> class CppVtableCloner : public T {
+  static intptr_t* vtable_of(Metadata& m) {
+    return *((intptr_t**)&m);
+  }
+  static CppVtableInfo* _info;
+
+  static int get_vtable_length(const char* name);
+
+public:
+  // Allocate and initialize the C++ vtable, starting from top, but do not go past end.
+  static intptr_t* allocate(const char* name, intptr_t* top, intptr_t* end);
+
+  // Clone the vtable to ...
+  static intptr_t* clone_vtable(const char* name, CppVtableInfo* info);
+
+  static void zero_vtable_clone() {
+    assert(DumpSharedSpaces, "dump-time only");
+    _info->zero();
+  }
+
+  // Switch the vtable pointer to point to the cloned vtable.
+  static void patch(Metadata* obj) {
+    assert(DumpSharedSpaces, "dump-time only");
+    *(void**)obj = (void*)(_info->cloned_vtable());
+  }
+
+  static bool is_valid_shared_object(const T* obj) {
+    intptr_t* vptr = *(intptr_t**)obj;
+    return vptr == _info->cloned_vtable();
+  }
+};
+
+template <class T> CppVtableInfo* CppVtableCloner<T>::_info = NULL;
+
+template <class T>
+intptr_t* CppVtableCloner<T>::allocate(const char* name, intptr_t* top, intptr_t* end) {
+  int n = get_vtable_length(name);
+  _info = (CppVtableInfo*)top;
+  intptr_t* next = _info->next(n);
+
+  if (next > end) {
+    report_out_of_shared_space(SharedMiscData);
+  }
+  _info->set_vtable_size(n);
+
+  intptr_t* p = clone_vtable(name, _info);
+  assert(p == next, "must be");
+
+  return p;
+}
+
+template <class T>
+intptr_t* CppVtableCloner<T>::clone_vtable(const char* name, CppVtableInfo* info) {
+  if (!DumpSharedSpaces) {
+    assert(_info == 0, "_info is initialized only at dump time");
+    _info = info; // Remember it -- it will be used by MetaspaceShared::is_valid_shared_method()
+  }
+  T tmp; // Allocate temporary dummy metadata object to get to the original vtable.
+  int n = info->vtable_size();
+  intptr_t* srcvtable = vtable_of(tmp);
+  intptr_t* dstvtable = info->cloned_vtable();
+
+  // We already checked (and, if necessary, adjusted n) when the vtables were allocated, so we are
+  // safe to do memcpy.
+  if (PrintSharedSpaces) {
+    tty->print_cr("Copying %3d vtable entries for %s", n, name);
+  }
+  memcpy(dstvtable, srcvtable, sizeof(intptr_t) * n);
+  return dstvtable + n;
+}
+
+// To determine the size of the vtable for each type, we use the following
+// trick by declaring 2 subclasses:
 //
-// Restore time:
-//   1. initialize_shared_space: reserve space for table
-//   2. init_self_patching_vtbl_list: update pointers to NEW virtual method addrs in text
+//   class CppVtableTesterA: public InstanceKlass {virtual int   last_virtual_method() {return 1;}    };
+//   class CppVtableTesterB: public InstanceKlass {virtual void* last_virtual_method() {return NULL}; };
+//
+// CppVtableTesterA and CppVtableTesterB's vtables have the following properties:
+// - Their size (N+1) is exactly one more than the size of InstanceKlass's vtable (N)
+// - The first N entries have are exactly the same as in InstanceKlass's vtable.
+// - Their last entry is different.
+//
+// So to determine the value of N, we just walk CppVtableTesterA and CppVtableTesterB's tables
+// and find the first entry that's different.
 //
-// Execution time:
-//   First virtual method call for any object of these metadata types:
-//   1. object->klass
-//   2. vtable entry for that klass points to the jump table entries
-//   3. branches to common_code with %O0/klass, %L0: Klass index <<8 + method index
-//   4. common_code:
-//      Get address of new vtbl pointer for this Klass from updated table
-//      Update new vtbl pointer in the Klass: future virtual calls go direct
-//      Jump to method, using new vtbl pointer and method index
+// This works on all C++ compilers supported by Oracle, but you may need to tweak it for more
+// esoteric compilers.
+
+template <class T> class CppVtableTesterB: public T {
+public:
+  virtual int last_virtual_method() {return 1;}
+};
 
+template <class T> class CppVtableTesterA : public T {
+public:
+  virtual void* last_virtual_method() {
+    // Make this different than CppVtableTesterB::last_virtual_method so the C++
+    // compiler/linker won't alias the two functions.
+    return NULL;
+  }
+};
 
-static void* find_matching_vtbl_ptr(void** vtbl_list, void* new_vtable_start, void* obj) {
-  void* old_vtbl_ptr = *(void**)obj;
-  for (int i = 0; i < MetaspaceShared::vtbl_list_size; i++) {
-    if (vtbl_list[i] == old_vtbl_ptr) {
-      return (void**)new_vtable_start + i * MetaspaceShared::num_virtuals;
+template <class T>
+int CppVtableCloner<T>::get_vtable_length(const char* name) {
+  CppVtableTesterA<T> a;
+  CppVtableTesterB<T> b;
+
+  intptr_t* avtable = vtable_of(a);
+  intptr_t* bvtable = vtable_of(b);
+
+  // Start at slot 1, because slot 0 may be RTTI (on Solaris/Sparc)
+  int vtable_len = 1;
+  for (; ; vtable_len++) {
+    if (avtable[vtable_len] != bvtable[vtable_len]) {
+      break;
     }
   }
-  ShouldNotReachHere();
-  return NULL;
+  if (PrintSharedSpaces) {
+    tty->print_cr("Found   %3d vtable entries for %s", vtable_len, name);
+  }
+
+  return vtable_len;
+}
+
+#define ALLOC_CPP_VTABLE_CLONE(c) \
+  top = CppVtableCloner<c>::allocate(#c, top, end);
+
+#define CLONE_CPP_VTABLE(c) \
+  p = CppVtableCloner<c>::clone_vtable(#c, (CppVtableInfo*)p);
+
+#define ZERO_CPP_VTABLE(c) \
+ CppVtableCloner<c>::zero_vtable_clone();
+
+// This can be called at both dump time and run time.
+intptr_t* MetaspaceShared::clone_cpp_vtables(intptr_t* p) {
+  assert(DumpSharedSpaces || UseSharedSpaces, "sanity");
+  CPP_VTABLE_PATCH_TYPES_DO(CLONE_CPP_VTABLE);
+  return p;
 }
 
-// Assumes the vtable is in first slot in object.
-static void patch_klass_vtables(void** vtbl_list, void* new_vtable_start) {
+void MetaspaceShared::zero_cpp_vtable_clones_for_writing() {
+  assert(DumpSharedSpaces, "dump-time only");
+  CPP_VTABLE_PATCH_TYPES_DO(ZERO_CPP_VTABLE);
+}
+
+// Allocate and initialize the C++ vtables, starting from top, but do not go past end.
+intptr_t* MetaspaceShared::allocate_cpp_vtable_clones(intptr_t* top, intptr_t* end) {
+  assert(DumpSharedSpaces, "dump-time only");
+  // Layout (each slot is a intptr_t):
+  //   [number of slots in the first vtable = n1]
+  //   [ <n1> slots for the first vtable]
+  //   [number of slots in the first second = n2]
+  //   [ <n2> slots for the second vtable]
+  //   ...
+  // The order of the vtables is the same as the CPP_VTAB_PATCH_TYPES_DO macro.
+  CPP_VTABLE_PATCH_TYPES_DO(ALLOC_CPP_VTABLE_CLONE);
+  return top;
+}
+
+// Switch the vtable pointer to point to the cloned vtable. We assume the
+// vtable pointer is in first slot in object.
+void MetaspaceShared::patch_cpp_vtable_pointers() {
   int n = _global_klass_objects->length();
   for (int i = 0; i < n; i++) {
     Klass* obj = _global_klass_objects->at(i);
-    // Note is_instance_klass() is a virtual call in debug.  After patching vtables
-    // all virtual calls on the dummy vtables will restore the original!
     if (obj->is_instance_klass()) {
       InstanceKlass* ik = InstanceKlass::cast(obj);
-      *(void**)ik = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, ik);
+      if (ik->is_class_loader_instance_klass()) {
+        CppVtableCloner<InstanceClassLoaderKlass>::patch(ik);
+      } else if (ik->is_reference_instance_klass()) {
+        CppVtableCloner<InstanceRefKlass>::patch(ik);
+      } else if (ik->is_mirror_instance_klass()) {
+        CppVtableCloner<InstanceMirrorKlass>::patch(ik);
+      } else {
+        CppVtableCloner<InstanceKlass>::patch(ik);
+      }
       ConstantPool* cp = ik->constants();
-      *(void**)cp = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, cp);
+      CppVtableCloner<ConstantPool>::patch(cp);
       for (int j = 0; j < ik->methods()->length(); j++) {
         Method* m = ik->methods()->at(j);
-        *(void**)m = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, m);
+        CppVtableCloner<Method>::patch(m);
+        assert(CppVtableCloner<Method>::is_valid_shared_object(m), "must be");
       }
+    } else if (obj->is_objArray_klass()) {
+      CppVtableCloner<ObjArrayKlass>::patch(obj);
     } else {
-      // Array klasses
-      Klass* k = obj;
-      *(void**)k = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, k);
+      assert(obj->is_typeArray_klass(), "sanity");
+      CppVtableCloner<TypeArrayKlass>::patch(obj);
     }
   }
 }
 
+bool MetaspaceShared::is_valid_shared_method(const Method* m) {
+  assert(is_in_shared_space(m), "must be");
+  return CppVtableCloner<Method>::is_valid_shared_object(m);
+}
+
 // Closure for serializing initialization data out to a data area to be
 // written to the shared file.
 
@@ -618,24 +782,12 @@
   char* od_top = MetaspaceShared::optional_data_region()->alloc_top();
   char* od_end = _od_vs.high();
 
-  // Reserve space for the list of Klass*s whose vtables are used
-  // for patching others as needed.
-
-  void** vtbl_list = (void**)md_top;
-  int vtbl_list_size = MetaspaceShared::vtbl_list_size;
-  Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size);
+  char* vtbl_list = md_top;
+  md_top = (char*)MetaspaceShared::allocate_cpp_vtable_clones((intptr_t*)md_top, (intptr_t*)md_end);
 
-  md_top += vtbl_list_size * sizeof(void*);
-  void* vtable = md_top;
-
-  // Reserve space for a new dummy vtable for klass objects in the
-  // heap.  Generate self-patching vtable entries.
-
-  MetaspaceShared::generate_vtable_methods(vtbl_list, &vtable,
-                                     &md_top, md_end,
-                                     &mc_top, mc_end);
-
-  guarantee(md_top <= md_end, "Insufficient space for vtables.");
+  // We don't use MC section anymore. We will remove it in a future RFE. For now, put one
+  // byte inside so the region writing/mapping code works.
+  mc_top ++;
 
   // Reorder the system dictionary.  (Moving the symbols affects
   // how the hash table indices are calculated.)
@@ -709,20 +861,19 @@
   tty->print_cr("total   : " SIZE_FORMAT_W(9) " [100.0%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used]",
                  total_bytes, total_alloced, total_u_perc);
 
-  // Update the vtable pointers in all of the Klass objects in the
-  // heap. They should point to newly generated vtable.
-  patch_klass_vtables(vtbl_list, vtable);
+  // During patching, some virtual methods may be called, so at this point
+  // the vtables must contain valid methods (as filled in by CppVtableCloner::allocate).
+  MetaspaceShared::patch_cpp_vtable_pointers();
 
-  // dunno what this is for.
-  char* saved_vtbl = (char*)os::malloc(vtbl_list_size * sizeof(void*), mtClass);
-  memmove(saved_vtbl, vtbl_list, vtbl_list_size * sizeof(void*));
-  memset(vtbl_list, 0, vtbl_list_size * sizeof(void*));
+  // The vtable clones contain addresses of the current process.
+  // We don't want to write these addresses into the archive.
+  MetaspaceShared::zero_cpp_vtable_clones_for_writing();
 
   // Create and write the archive file that maps the shared spaces.
 
   FileMapInfo* mapinfo = new FileMapInfo();
   mapinfo->populate_header(MetaspaceShared::max_alignment());
-  mapinfo->set_misc_data_patching_start((char*)vtbl_list);
+  mapinfo->set_misc_data_patching_start(vtbl_list);
   mapinfo->set_cds_i2i_entry_code_buffers(MetaspaceShared::cds_i2i_entry_code_buffers());
   mapinfo->set_cds_i2i_entry_code_buffers_size(MetaspaceShared::cds_i2i_entry_code_buffers_size());
 
@@ -757,8 +908,8 @@
 
   mapinfo->close();
 
-  memmove(vtbl_list, saved_vtbl, vtbl_list_size * sizeof(void*));
-  os::free(saved_vtbl);
+  // Restore the vtable in case we invoke any virtual methods.
+  MetaspaceShared::clone_cpp_vtables((intptr_t*)vtbl_list);
 
   if (PrintSharedSpaces) {
     DumpAllocClosure dac;
@@ -1134,19 +1285,7 @@
   _cds_i2i_entry_code_buffers_size = mapinfo->cds_i2i_entry_code_buffers_size();
   char* buffer = mapinfo->misc_data_patching_start();
 
-  // Skip over (reserve space for) a list of addresses of C++ vtables
-  // for Klass objects.  They get filled in later.
-
-  void** vtbl_list = (void**)buffer;
-  buffer += MetaspaceShared::vtbl_list_size * sizeof(void*);
-  Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size);
-
-  // Skip over (reserve space for) dummy C++ vtables Klass objects.
-  // They are used as is.
-
-  intptr_t vtable_size = *(intptr_t*)buffer;
-  buffer += sizeof(intptr_t);
-  buffer += vtable_size;
+  buffer = (char*)clone_cpp_vtables((intptr_t*)buffer);
 
   int sharedDictionaryLen = *(intptr_t*)buffer;
   buffer += sizeof(intptr_t);
--- a/hotspot/src/share/vm/memory/metaspaceShared.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/memory/metaspaceShared.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,17 +32,6 @@
 #include "utilities/exceptions.hpp"
 #include "utilities/macros.hpp"
 
-#define DEFAULT_VTBL_LIST_SIZE          (17)  // number of entries in the shared space vtable list.
-#define DEFAULT_VTBL_VIRTUALS_COUNT     (200) // maximum number of virtual functions
-// If virtual functions are added to Metadata,
-// this number needs to be increased.  Also,
-// SharedMiscCodeSize will need to be increased.
-// The following 2 sizes were based on
-// MetaspaceShared::generate_vtable_methods()
-#define DEFAULT_VTBL_METHOD_SIZE        (16)  // conservative size of the mov1 and jmp instructions
-// for the x64 platform
-#define DEFAULT_VTBL_COMMON_CODE_SIZE   (1*K) // conservative size of the "common_code" for the x64 platform
-
 #define DEFAULT_SHARED_READ_WRITE_SIZE  (NOT_LP64(6*M) LP64_ONLY(10*M))
 #define MIN_SHARED_READ_WRITE_SIZE      (NOT_LP64(6*M) LP64_ONLY(10*M))
 
@@ -135,13 +124,6 @@
   static SharedMiscRegion _od;
  public:
   enum {
-    vtbl_list_size         = DEFAULT_VTBL_LIST_SIZE,
-    num_virtuals           = DEFAULT_VTBL_VIRTUALS_COUNT,
-    vtbl_method_size       = DEFAULT_VTBL_METHOD_SIZE,
-    vtbl_common_code_size  = DEFAULT_VTBL_COMMON_CODE_SIZE
-  };
-
-  enum {
     ro = 0,  // read-only shared space in the heap
     rw = 1,  // read-write shared space in the heap
     md = 2,  // miscellaneous data for initializing tables, etc.
@@ -194,10 +176,12 @@
 
   static bool is_string_region(int idx) NOT_CDS_RETURN_(false);
 
-  static void generate_vtable_methods(void** vtbl_list,
-                                      void** vtable,
-                                      char** md_top, char* md_end,
-                                      char** mc_top, char* mc_end);
+  static intptr_t* allocate_cpp_vtable_clones(intptr_t* top, intptr_t* end);
+  static intptr_t* clone_cpp_vtables(intptr_t* p);
+  static void zero_cpp_vtable_clones_for_writing();
+  static void patch_cpp_vtable_pointers();
+  static bool is_valid_shared_method(const Method* m);
+
   static void serialize(SerializeClosure* sc, GrowableArray<MemRegion> *string_space,
                         size_t* space_size);
 
--- a/hotspot/src/share/vm/memory/oopFactory.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/memory/oopFactory.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -57,17 +57,15 @@
   return result;
 }
 
-// Create a Java array that points to metadata.
-// As far as Java code is concerned, a metaData array is either an array of
-// int or long depending on pointer size.  Only a few things use this, like
-// stack trace elements in Throwable.  They cast Method* into this type.
-// Note:can't point to symbols because there's no way to unreference count
-// them when this object goes away.
-typeArrayOop oopFactory::new_metaDataArray(int length, TRAPS) {
+// Create a Java array that points to Symbol.
+// As far as Java code is concerned, a Symbol array is either an array of
+// int or long depending on pointer size.  Only stack trace elements in Throwable use
+// this.  They cast Symbol* into this type.
+typeArrayOop oopFactory::new_symbolArray(int length, TRAPS) {
   BasicType type = LP64_ONLY(T_LONG) NOT_LP64(T_INT);
   Klass* type_asKlassOop = Universe::typeArrayKlassObj(type);
   TypeArrayKlass* type_asArrayKlass = TypeArrayKlass::cast(type_asKlassOop);
-  typeArrayOop result = type_asArrayKlass->allocate_common(length, true, THREAD);
+  typeArrayOop result = type_asArrayKlass->allocate(length, THREAD);
   return result;
 }
 
@@ -87,3 +85,13 @@
     return InstanceKlass::cast(klass)->allocate_objArray(1, length, THREAD);
   }
 }
+
+objArrayHandle oopFactory::new_objArray_handle(Klass* klass, int length, TRAPS) {
+  objArrayOop obj = new_objArray(klass, length, CHECK_(objArrayHandle()));
+  return objArrayHandle(THREAD, obj);
+}
+
+typeArrayHandle oopFactory::new_byteArray_handle(int length, TRAPS) {
+  typeArrayOop obj = new_byteArray(length, CHECK_(typeArrayHandle()));
+  return typeArrayHandle(THREAD, obj);
+}
--- a/hotspot/src/share/vm/memory/oopFactory.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/memory/oopFactory.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -62,10 +62,14 @@
 
   static typeArrayOop    new_typeArray(BasicType type, int length, TRAPS);
   static typeArrayOop    new_typeArray_nozero(BasicType type, int length, TRAPS);
-  static typeArrayOop    new_metaDataArray(int length, TRAPS);
+  static typeArrayOop    new_symbolArray(int length, TRAPS);
 
   // Regular object arrays
   static objArrayOop     new_objArray(Klass* klass, int length, TRAPS);
+
+  // Helpers that return handles
+  static objArrayHandle  new_objArray_handle(Klass* klass, int length, TRAPS);
+  static typeArrayHandle new_byteArray_handle(int length, TRAPS);
 };
 
 #endif // SHARE_VM_MEMORY_OOPFACTORY_HPP
--- a/hotspot/src/share/vm/memory/universe.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/memory/universe.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -410,30 +410,6 @@
 
 }
 
-// CDS support for patching vtables in metadata in the shared archive.
-// All types inherited from Metadata have vtables, but not types inherited
-// from MetaspaceObj, because the latter does not have virtual functions.
-// If the metadata type has a vtable, it cannot be shared in the read-only
-// section of the CDS archive, because the vtable pointer is patched.
-static inline void add_vtable(void** list, int* n, void* o, int count) {
-  guarantee((*n) < count, "vtable list too small");
-  void* vtable = dereference_vptr(o);
-  assert(*(void**)(vtable) != NULL, "invalid vtable");
-  list[(*n)++] = vtable;
-}
-
-void Universe::init_self_patching_vtbl_list(void** list, int count) {
-  int n = 0;
-  { InstanceKlass o;          add_vtable(list, &n, &o, count); }
-  { InstanceClassLoaderKlass o; add_vtable(list, &n, &o, count); }
-  { InstanceMirrorKlass o;    add_vtable(list, &n, &o, count); }
-  { InstanceRefKlass o;       add_vtable(list, &n, &o, count); }
-  { TypeArrayKlass o;         add_vtable(list, &n, &o, count); }
-  { ObjArrayKlass o;          add_vtable(list, &n, &o, count); }
-  { Method o;                 add_vtable(list, &n, &o, count); }
-  { ConstantPool o;           add_vtable(list, &n, &o, count); }
-}
-
 void Universe::initialize_basic_type_mirrors(TRAPS) {
     assert(_int_mirror==NULL, "basic type mirrors already initialized");
     _int_mirror     =
@@ -484,9 +460,8 @@
     Klass* k = list->at(i);
     assert(k->is_klass(), "List should only hold classes");
     EXCEPTION_MARK;
-    KlassHandle kh(THREAD, k);
-    java_lang_Class::fixup_mirror(kh, CATCH);
-}
+    java_lang_Class::fixup_mirror(k, CATCH);
+  }
   delete java_lang_Class::fixup_mirror_list();
   java_lang_Class::set_fixup_mirror_list(NULL);
 }
@@ -530,7 +505,7 @@
   log_trace(ref)("Callback to run finalizers on exit");
   {
     PRESERVE_EXCEPTION_MARK;
-    KlassHandle finalizer_klass(THREAD, SystemDictionary::Finalizer_klass());
+    Klass* finalizer_klass = SystemDictionary::Finalizer_klass();
     JavaValue result(T_VOID);
     JavaCalls::call_static(
       &result,
@@ -549,16 +524,15 @@
 // 1) we specified true to initialize_vtable and
 // 2) this ran after gc was enabled
 // In case those ever change we use handles for oops
-void Universe::reinitialize_vtable_of(KlassHandle k_h, TRAPS) {
+void Universe::reinitialize_vtable_of(Klass* ko, TRAPS) {
   // init vtable of k and all subclasses
-  Klass* ko = k_h();
   klassVtable* vt = ko->vtable();
   if (vt) vt->initialize_vtable(false, CHECK);
   if (ko->is_instance_klass()) {
-    for (KlassHandle s_h(THREAD, ko->subklass());
-         s_h() != NULL;
-         s_h = KlassHandle(THREAD, s_h()->next_sibling())) {
-      reinitialize_vtable_of(s_h, CHECK);
+    for (Klass* sk = ko->subklass();
+         sk != NULL;
+         sk = sk->next_sibling()) {
+      reinitialize_vtable_of(sk, CHECK);
     }
   }
 }
@@ -615,20 +589,22 @@
     // return default
     return default_err;
   } else {
+    Thread* THREAD = Thread::current();
+    Handle default_err_h(THREAD, default_err);
     // get the error object at the slot and set set it to NULL so that the
     // array isn't keeping it alive anymore.
-    oop exc = preallocated_out_of_memory_errors()->obj_at(next);
-    assert(exc != NULL, "slot has been used already");
+    Handle exc(THREAD, preallocated_out_of_memory_errors()->obj_at(next));
+    assert(exc() != NULL, "slot has been used already");
     preallocated_out_of_memory_errors()->obj_at_put(next, NULL);
 
     // use the message from the default error
-    oop msg = java_lang_Throwable::message(default_err);
+    oop msg = java_lang_Throwable::message(default_err_h());
     assert(msg != NULL, "no message");
-    java_lang_Throwable::set_message(exc, msg);
+    java_lang_Throwable::set_message(exc(), msg);
 
     // populate the stack trace and return it.
     java_lang_Throwable::fill_in_stack_trace_of_preallocated_backtrace(exc);
-    return exc;
+    return exc();
   }
 }
 
@@ -986,28 +962,26 @@
     Interpreter::initialize();      // needed for interpreter entry points
     if (!UseSharedSpaces) {
       HandleMark hm(THREAD);
-      KlassHandle ok_h(THREAD, SystemDictionary::Object_klass());
-      Universe::reinitialize_vtable_of(ok_h, CHECK_false);
+      Klass* ok = SystemDictionary::Object_klass();
+      Universe::reinitialize_vtable_of(ok, CHECK_false);
       Universe::reinitialize_itables(CHECK_false);
     }
   }
 
   HandleMark hm(THREAD);
-  Klass* k;
-  instanceKlassHandle k_h;
   // Setup preallocated empty java.lang.Class array
   Universe::_the_empty_class_klass_array = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_false);
 
   // Setup preallocated OutOfMemoryError errors
-  k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_OutOfMemoryError(), true, CHECK_false);
-  k_h = instanceKlassHandle(THREAD, k);
-  Universe::_out_of_memory_error_java_heap = k_h->allocate_instance(CHECK_false);
-  Universe::_out_of_memory_error_metaspace = k_h->allocate_instance(CHECK_false);
-  Universe::_out_of_memory_error_class_metaspace = k_h->allocate_instance(CHECK_false);
-  Universe::_out_of_memory_error_array_size = k_h->allocate_instance(CHECK_false);
+  Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_OutOfMemoryError(), true, CHECK_false);
+  InstanceKlass* ik = InstanceKlass::cast(k);
+  Universe::_out_of_memory_error_java_heap = ik->allocate_instance(CHECK_false);
+  Universe::_out_of_memory_error_metaspace = ik->allocate_instance(CHECK_false);
+  Universe::_out_of_memory_error_class_metaspace = ik->allocate_instance(CHECK_false);
+  Universe::_out_of_memory_error_array_size = ik->allocate_instance(CHECK_false);
   Universe::_out_of_memory_error_gc_overhead_limit =
-    k_h->allocate_instance(CHECK_false);
-  Universe::_out_of_memory_error_realloc_objects = k_h->allocate_instance(CHECK_false);
+    ik->allocate_instance(CHECK_false);
+  Universe::_out_of_memory_error_realloc_objects = ik->allocate_instance(CHECK_false);
 
   // Setup preallocated cause message for delayed StackOverflowError
   if (StackReservedPages > 0) {
@@ -1028,8 +1002,8 @@
     vmSymbols::java_lang_VirtualMachineError(), true, CHECK_false);
   bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
   if (!linked) {
-    tty->print_cr("Unable to link/verify VirtualMachineError class");
-    return false; // initialization failed
+     tty->print_cr("Unable to link/verify VirtualMachineError class");
+     return false; // initialization failed
   }
   Universe::_virtual_machine_error_instance =
     InstanceKlass::cast(k)->allocate_instance(CHECK_false);
@@ -1062,12 +1036,12 @@
     // Setup the array of errors that have preallocated backtrace
     k = Universe::_out_of_memory_error_java_heap->klass();
     assert(k->name() == vmSymbols::java_lang_OutOfMemoryError(), "should be out of memory error");
-    k_h = instanceKlassHandle(THREAD, k);
+    ik = InstanceKlass::cast(k);
 
     int len = (StackTraceInThrowable) ? (int)PreallocatedOutOfMemoryErrorCount : 0;
-    Universe::_preallocated_out_of_memory_error_array = oopFactory::new_objArray(k_h(), len, CHECK_false);
+    Universe::_preallocated_out_of_memory_error_array = oopFactory::new_objArray(ik, len, CHECK_false);
     for (int i=0; i<len; i++) {
-      oop err = k_h->allocate_instance(CHECK_false);
+      oop err = ik->allocate_instance(CHECK_false);
       Handle err_h = Handle(THREAD, err);
       java_lang_Throwable::allocate_backtrace(err_h, CHECK_false);
       Universe::preallocated_out_of_memory_errors()->obj_at_put(i, err_h());
--- a/hotspot/src/share/vm/memory/universe.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/memory/universe.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -230,7 +230,7 @@
   static void initialize_basic_type_mirrors(TRAPS);
   static void fixup_mirrors(TRAPS);
 
-  static void reinitialize_vtable_of(KlassHandle h_k, TRAPS);
+  static void reinitialize_vtable_of(Klass* k, TRAPS);
   static void reinitialize_itables(TRAPS);
   static void compute_base_vtable_size();             // compute vtable size of class Object
 
@@ -480,9 +480,6 @@
   // SystemDictionary).
   static void basic_type_classes_do(void f(Klass*));
 
-  // For sharing -- fill in a list of known vtable pointers.
-  static void init_self_patching_vtbl_list(void** list, int count);
-
   // Debugging
   enum VERIFY_FLAGS {
     Verify_Threads = 1,
--- a/hotspot/src/share/vm/oops/arrayKlass.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/arrayKlass.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -96,9 +96,9 @@
 
 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
 // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
-void ArrayKlass::complete_create_array_klass(ArrayKlass* k, KlassHandle super_klass, ModuleEntry* module_entry, TRAPS) {
+void ArrayKlass::complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module_entry, TRAPS) {
   ResourceMark rm(THREAD);
-  k->initialize_supers(super_klass(), CHECK);
+  k->initialize_supers(super_klass, CHECK);
   k->vtable()->initialize_vtable(false, CHECK);
 
   // During bootstrapping, before java.base is defined, the module_entry may not be present yet.
@@ -107,7 +107,7 @@
   assert((module_entry != NULL) || ((module_entry == NULL) && !ModuleEntryTable::javabase_defined()),
          "module entry not available post " JAVA_BASE_NAME " definition");
   oop module = (module_entry != NULL) ? JNIHandles::resolve(module_entry->module()) : (oop)NULL;
-  java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(NULL), CHECK);
+  java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(), CHECK);
 }
 
 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots) {
--- a/hotspot/src/share/vm/oops/arrayKlass.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/arrayKlass.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -115,7 +115,7 @@
   void array_klasses_do(void f(Klass* k, TRAPS), TRAPS);
 
   // Return a handle.
-  static void     complete_create_array_klass(ArrayKlass* k, KlassHandle super_klass, ModuleEntry* module, TRAPS);
+  static void     complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module, TRAPS);
 
 
   // jvm support
--- a/hotspot/src/share/vm/oops/constantPool.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/constantPool.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -152,6 +152,7 @@
 
 // CDS support. Create a new resolved_references array.
 void ConstantPool::restore_unshareable_info(TRAPS) {
+  assert(is_constantPool(), "ensure C++ vtable is restored");
 
   // Only create the new resolved references array if it hasn't been attempted before
   if (resolved_references() != NULL) return;
@@ -192,7 +193,7 @@
   resolved_references()->obj_at_put(obj_index, str);
 }
 
-void ConstantPool::trace_class_resolution(const constantPoolHandle& this_cp, KlassHandle k) {
+void ConstantPool::trace_class_resolution(const constantPoolHandle& this_cp, Klass* k) {
   ResourceMark rm;
   int line_number = -1;
   const char * source_file = NULL;
@@ -207,7 +208,7 @@
       }
     }
   }
-  if (k() != this_cp->pool_holder()) {
+  if (k != this_cp->pool_holder()) {
     // only print something if the classes are different
     if (source_file != NULL) {
       log_debug(class, resolve)("%s %s %s:%d",
@@ -253,11 +254,10 @@
   Symbol* name = entry.get_symbol();
   Handle loader (THREAD, this_cp->pool_holder()->class_loader());
   Handle protection_domain (THREAD, this_cp->pool_holder()->protection_domain());
-  Klass* kk = SystemDictionary::resolve_or_fail(name, loader, protection_domain, true, THREAD);
-  KlassHandle k (THREAD, kk);
+  Klass* k = SystemDictionary::resolve_or_fail(name, loader, protection_domain, true, THREAD);
   if (!HAS_PENDING_EXCEPTION) {
     // preserve the resolved klass from unloading
-    mirror_handle = Handle(THREAD, kk->java_mirror());
+    mirror_handle = Handle(THREAD, k->java_mirror());
     // Do access check for klasses
     verify_constant_pool_resolve(this_cp, k, THREAD);
   }
@@ -281,13 +281,13 @@
 
   // Make this class loader depend upon the class loader owning the class reference
   ClassLoaderData* this_key = this_cp->pool_holder()->class_loader_data();
-  this_key->record_dependency(k(), CHECK_NULL); // Can throw OOM
+  this_key->record_dependency(k, CHECK_NULL); // Can throw OOM
 
   // logging for class+resolve.
   if (log_is_enabled(Debug, class, resolve)){
     trace_class_resolution(this_cp, k);
   }
-  this_cp->klass_at_put(which, k());
+  this_cp->klass_at_put(which, k);
   entry = this_cp->resolved_klass_at(which);
   assert(entry.is_resolved() && entry.get_klass()->is_klass(), "must be resolved at this point");
   return entry.get_klass();
@@ -316,14 +316,13 @@
     if (k != NULL) {
       // Make sure that resolving is legal
       EXCEPTION_MARK;
-      KlassHandle klass(THREAD, k);
       // return NULL if verification fails
-      verify_constant_pool_resolve(this_cp, klass, THREAD);
+      verify_constant_pool_resolve(this_cp, k, THREAD);
       if (HAS_PENDING_EXCEPTION) {
         CLEAR_PENDING_EXCEPTION;
         return NULL;
       }
-      return klass();
+      return k;
     } else {
       return k;
     }
@@ -455,16 +454,15 @@
 }
 
 
-void ConstantPool::verify_constant_pool_resolve(const constantPoolHandle& this_cp, KlassHandle k, TRAPS) {
+void ConstantPool::verify_constant_pool_resolve(const constantPoolHandle& this_cp, Klass* k, TRAPS) {
  if (k->is_instance_klass() || k->is_objArray_klass()) {
-    instanceKlassHandle holder (THREAD, this_cp->pool_holder());
-    Klass* elem = k->is_instance_klass() ? k() : ObjArrayKlass::cast(k())->bottom_klass();
-    KlassHandle element (THREAD, elem);
+    InstanceKlass* holder = this_cp->pool_holder();
+    Klass* elem = k->is_instance_klass() ? k : ObjArrayKlass::cast(k)->bottom_klass();
 
     // The element type could be a typeArray - we only need the access check if it is
     // an reference to another class
-    if (element->is_instance_klass()) {
-      LinkResolver::check_klass_accessability(holder, element, CHECK);
+    if (elem->is_instance_klass()) {
+      LinkResolver::check_klass_accessability(holder, elem, CHECK);
     }
   }
 }
@@ -692,8 +690,7 @@
                               callee_index, name->as_C_string(), signature->as_C_string());
       }
 
-      Klass* k = klass_at_impl(this_cp, callee_index, true, CHECK_NULL);
-      KlassHandle callee(THREAD, k);
+      Klass* callee = klass_at_impl(this_cp, callee_index, true, CHECK_NULL);
 
       // Check constant pool method consistency
       if ((callee->is_interface() && m_tag.is_method()) ||
@@ -709,7 +706,7 @@
         THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
       }
 
-      KlassHandle klass(THREAD, this_cp->pool_holder());
+      Klass* klass = this_cp->pool_holder();
       Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind,
                                                                    callee, name, signature,
                                                                    THREAD);
@@ -728,7 +725,7 @@
                               index, this_cp->method_type_index_at(index),
                               signature->as_C_string());
       }
-      KlassHandle klass(THREAD, this_cp->pool_holder());
+      Klass* klass = this_cp->pool_holder();
       Handle value = SystemDictionary::find_method_handle_type(signature, klass, THREAD);
       result_oop = value();
       if (HAS_PENDING_EXCEPTION) {
@@ -844,8 +841,7 @@
 }
 
 
-bool ConstantPool::klass_name_at_matches(instanceKlassHandle k,
-                                                int which) {
+bool ConstantPool::klass_name_at_matches(const InstanceKlass* k, int which) {
   // Names are interned, so we can compare Symbol*s directly
   Symbol* cp_name = klass_name_at(which);
   return (cp_name == k->name());
--- a/hotspot/src/share/vm/oops/constantPool.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/constantPool.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -693,7 +693,7 @@
   }
 
   // Klass name matches name at offset
-  bool klass_name_at_matches(instanceKlassHandle k, int which);
+  bool klass_name_at_matches(const InstanceKlass* k, int which);
 
   // Sizing
   int length() const                   { return _length; }
@@ -715,6 +715,11 @@
   friend class ClassFileParser;
   friend class SystemDictionary;
 
+  // Used by CDS. These classes need to access the private ConstantPool() constructor.
+  template <class T> friend class CppVtableTesterA;
+  template <class T> friend class CppVtableTesterB;
+  template <class T> friend class CppVtableCloner;
+
   // Used by compiler to prevent classloading.
   static Method*          method_at_if_loaded      (const constantPoolHandle& this_cp, int which);
   static bool       has_appendix_at_if_loaded      (const constantPoolHandle& this_cp, int which);
@@ -779,7 +784,7 @@
   }
 
   // Performs the LinkResolver checks
-  static void verify_constant_pool_resolve(const constantPoolHandle& this_cp, KlassHandle klass, TRAPS);
+  static void verify_constant_pool_resolve(const constantPoolHandle& this_cp, Klass* klass, TRAPS);
 
   // Implementation of methods that needs an exposed 'this' pointer, in order to
   // handle GC while executing the method
@@ -787,7 +792,7 @@
                               bool save_resolution_error, TRAPS);
   static oop string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS);
 
-  static void trace_class_resolution(const constantPoolHandle& this_cp, KlassHandle k);
+  static void trace_class_resolution(const constantPoolHandle& this_cp, Klass* k);
 
   // Resolve string constants (to prevent allocation during compilation)
   static void resolve_string_constants_impl(const constantPoolHandle& this_cp, TRAPS);
--- a/hotspot/src/share/vm/oops/cpCache.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/cpCache.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -101,14 +101,14 @@
 // are updated, lest other processors see a non-zero bytecode but zero f1/f2.
 void ConstantPoolCacheEntry::set_field(Bytecodes::Code get_code,
                                        Bytecodes::Code put_code,
-                                       KlassHandle field_holder,
+                                       Klass* field_holder,
                                        int field_index,
                                        int field_offset,
                                        TosState field_type,
                                        bool is_final,
                                        bool is_volatile,
                                        Klass* root_klass) {
-  set_f1(field_holder());
+  set_f1(field_holder);
   set_f2(field_offset);
   assert((field_index & field_index_mask) == field_index,
          "field index does not fit in low flag bits");
@@ -282,7 +282,7 @@
   // the lock, so that when the losing writer returns, he can use the linked
   // cache entry.
 
-  objArrayHandle resolved_references = cpool->resolved_references();
+  objArrayHandle resolved_references(Thread::current(), cpool->resolved_references());
   // Use the resolved_references() lock for this cpCache entry.
   // resolved_references are created for all classes with Invokedynamic, MethodHandle
   // or MethodType constant pool cache entries.
--- a/hotspot/src/share/vm/oops/cpCache.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/cpCache.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -217,7 +217,7 @@
   void set_field(                                // sets entry to resolved field state
     Bytecodes::Code get_code,                    // the bytecode used for reading the field
     Bytecodes::Code put_code,                    // the bytecode used for writing the field
-    KlassHandle     field_holder,                // the object/klass holding the field
+    Klass*          field_holder,                // the object/klass holding the field
     int             orig_field_index,            // the original field index in the field holder
     int             field_offset,                // the field offset in words in the field holder
     TosState        field_type,                  // the (machine) field type
--- a/hotspot/src/share/vm/oops/fieldStreams.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/fieldStreams.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -107,14 +107,6 @@
     init_generic_signature_start_slot();
     assert(klass == field_holder(), "");
   }
-  FieldStreamBase(instanceKlassHandle klass) {
-    _fields = klass->fields();
-    _constants = klass->constants();
-    _index = 0;
-    _limit = klass->java_fields_count();
-    init_generic_signature_start_slot();
-    assert(klass == field_holder(), "");
-  }
 
   // accessors
   int index() const                 { return _index; }
@@ -196,7 +188,7 @@
 // Iterate over only the internal fields
 class JavaFieldStream : public FieldStreamBase {
  public:
-  JavaFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {}
+  JavaFieldStream(const InstanceKlass* k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {}
 
   int name_index() const {
     assert(!field()->is_internal(), "regular only");
@@ -245,7 +237,6 @@
 class InternalFieldStream : public FieldStreamBase {
  public:
   InternalFieldStream(InstanceKlass* k):      FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {}
-  InternalFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), k->java_fields_count(), 0) {}
 };
 
 
@@ -253,7 +244,6 @@
  public:
   AllFieldStream(Array<u2>* fields, const constantPoolHandle& constants): FieldStreamBase(fields, constants) {}
   AllFieldStream(InstanceKlass* k):      FieldStreamBase(k->fields(), k->constants()) {}
-  AllFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants()) {}
 };
 
 #endif // SHARE_VM_OOPS_FIELDSTREAMS_HPP
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -374,7 +374,7 @@
 }
 
 klassItable* InstanceKlass::itable() const {
-  return new klassItable(instanceKlassHandle(this));
+  return new klassItable(const_cast<InstanceKlass*>(this));
 }
 
 void InstanceKlass::eager_initialize(Thread *thread) {
@@ -392,8 +392,7 @@
     if (!InstanceKlass::cast(super)->is_initialized()) return;
 
     // call body to expose the this pointer
-    instanceKlassHandle this_k(thread, this);
-    eager_initialize_impl(this_k);
+    eager_initialize_impl(this);
   }
 }
 
@@ -432,10 +431,11 @@
   assert(!is_not_initialized(), "class must be initialized now");
 }
 
-void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_k) {
+void InstanceKlass::eager_initialize_impl(InstanceKlass* this_k) {
   EXCEPTION_MARK;
-  oop init_lock = this_k->init_lock();
-  ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
+  HandleMark hm(THREAD);
+  Handle init_lock(THREAD, this_k->init_lock());
+  ObjectLocker ol(init_lock, THREAD, init_lock() != NULL);
 
   // abort if someone beat us to the initialization
   if (!this_k->is_not_initialized()) return;  // note: not equivalent to is_initialized()
@@ -469,9 +469,7 @@
 // Note: implementation moved to static method to expose the this pointer.
 void InstanceKlass::initialize(TRAPS) {
   if (this->should_be_initialized()) {
-    HandleMark hm(THREAD);
-    instanceKlassHandle this_k(THREAD, this);
-    initialize_impl(this_k, CHECK);
+    initialize_impl(this, CHECK);
     // Note: at this point the class may be initialized
     //       OR it may be in the state of being initialized
     //       in case of recursive initialization!
@@ -482,7 +480,7 @@
 
 
 bool InstanceKlass::verify_code(
-    instanceKlassHandle this_k, bool throw_verifyerror, TRAPS) {
+    InstanceKlass* this_k, bool throw_verifyerror, TRAPS) {
   // 1) Verify the bytecodes
   Verifier::Mode mode =
     throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
@@ -501,9 +499,7 @@
 void InstanceKlass::link_class(TRAPS) {
   assert(is_loaded(), "must be loaded");
   if (!is_linked()) {
-    HandleMark hm(THREAD);
-    instanceKlassHandle this_k(THREAD, this);
-    link_class_impl(this_k, true, CHECK);
+    link_class_impl(this, true, CHECK);
   }
 }
 
@@ -512,15 +508,13 @@
 bool InstanceKlass::link_class_or_fail(TRAPS) {
   assert(is_loaded(), "must be loaded");
   if (!is_linked()) {
-    HandleMark hm(THREAD);
-    instanceKlassHandle this_k(THREAD, this);
-    link_class_impl(this_k, false, CHECK_false);
+    link_class_impl(this, false, CHECK_false);
   }
   return is_linked();
 }
 
 bool InstanceKlass::link_class_impl(
-    instanceKlassHandle this_k, bool throw_verifyerror, TRAPS) {
+    InstanceKlass* this_k, bool throw_verifyerror, TRAPS) {
   if (DumpSharedSpaces && this_k->is_in_error_state()) {
     // This is for CDS dumping phase only -- we use the in_error_state to indicate that
     // the class has failed verification. Throwing the NoClassDefFoundError here is just
@@ -544,8 +538,8 @@
   JavaThread* jt = (JavaThread*)THREAD;
 
   // link super class before linking this class
-  instanceKlassHandle super(THREAD, this_k->super());
-  if (super.not_null()) {
+  Klass* super = this_k->super();
+  if (super != NULL) {
     if (super->is_interface()) {  // check if super class is an interface
       ResourceMark rm(THREAD);
       Exceptions::fthrow(
@@ -558,16 +552,16 @@
       return false;
     }
 
-    link_class_impl(super, throw_verifyerror, CHECK_false);
+    InstanceKlass* ik_super = InstanceKlass::cast(super);
+    link_class_impl(ik_super, throw_verifyerror, CHECK_false);
   }
 
   // link all interfaces implemented by this class before linking this class
   Array<Klass*>* interfaces = this_k->local_interfaces();
   int num_interfaces = interfaces->length();
   for (int index = 0; index < num_interfaces; index++) {
-    HandleMark hm(THREAD);
-    instanceKlassHandle ih(THREAD, interfaces->at(index));
-    link_class_impl(ih, throw_verifyerror, CHECK_false);
+    InstanceKlass* interk = InstanceKlass::cast(interfaces->at(index));
+    link_class_impl(interk, throw_verifyerror, CHECK_false);
   }
 
   // in case the class is linked in the process of linking its superclasses
@@ -586,11 +580,13 @@
 
   // verification & rewriting
   {
-    oop init_lock = this_k->init_lock();
-    ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
+    HandleMark hm(THREAD);
+    Handle init_lock(THREAD, this_k->init_lock());
+    ObjectLocker ol(init_lock, THREAD, init_lock() != NULL);
     // rewritten will have been set if loader constraint error found
     // on an earlier link attempt
     // don't verify or rewrite if already rewritten
+    //
 
     if (!this_k->is_linked()) {
       if (!this_k->is_rewritten()) {
@@ -643,7 +639,7 @@
       if (JvmtiExport::should_post_class_prepare()) {
         Thread *thread = THREAD;
         assert(thread->is_Java_thread(), "thread->is_Java_thread()");
-        JvmtiExport::post_class_prepare((JavaThread *) thread, this_k());
+        JvmtiExport::post_class_prepare((JavaThread *) thread, this_k);
       }
     }
   }
@@ -656,13 +652,12 @@
 // verification but before the first method of the class is executed.
 void InstanceKlass::rewrite_class(TRAPS) {
   assert(is_loaded(), "must be loaded");
-  instanceKlassHandle this_k(THREAD, this);
-  if (this_k->is_rewritten()) {
-    assert(this_k()->is_shared(), "rewriting an unshared class?");
+  if (is_rewritten()) {
+    assert(is_shared(), "rewriting an unshared class?");
     return;
   }
-  Rewriter::rewrite(this_k, CHECK);
-  this_k->set_rewritten();
+  Rewriter::rewrite(this, CHECK);
+  set_rewritten();
 }
 
 // Now relocate and link method entry points after class is rewritten.
@@ -679,7 +674,7 @@
 }
 
 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
-void InstanceKlass::initialize_super_interfaces(instanceKlassHandle this_k, TRAPS) {
+void InstanceKlass::initialize_super_interfaces(InstanceKlass* this_k, TRAPS) {
   assert (this_k->has_nonstatic_concrete_methods(), "caller should have checked this");
   for (int i = 0; i < this_k->local_interfaces()->length(); ++i) {
     Klass* iface = this_k->local_interfaces()->at(i);
@@ -699,20 +694,22 @@
   }
 }
 
-void InstanceKlass::initialize_impl(instanceKlassHandle this_k, TRAPS) {
+void InstanceKlass::initialize_impl(InstanceKlass* this_k, TRAPS) {
+  HandleMark hm(THREAD);
+
   // Make sure klass is linked (verified) before initialization
   // A class could already be verified, since it has been reflected upon.
   this_k->link_class(CHECK);
 
-  DTRACE_CLASSINIT_PROBE(required, this_k(), -1);
+  DTRACE_CLASSINIT_PROBE(required, this_k, -1);
 
   bool wait = false;
 
   // refer to the JVM book page 47 for description of steps
   // Step 1
   {
-    oop init_lock = this_k->init_lock();
-    ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
+    Handle init_lock(THREAD, this_k->init_lock());
+    ObjectLocker ol(init_lock, THREAD, init_lock() != NULL);
 
     Thread *self = THREAD; // it's passed the current thread
 
@@ -727,19 +724,19 @@
 
     // Step 3
     if (this_k->is_being_initialized() && this_k->is_reentrant_initialization(self)) {
-      DTRACE_CLASSINIT_PROBE_WAIT(recursive, this_k(), -1,wait);
+      DTRACE_CLASSINIT_PROBE_WAIT(recursive, this_k, -1,wait);
       return;
     }
 
     // Step 4
     if (this_k->is_initialized()) {
-      DTRACE_CLASSINIT_PROBE_WAIT(concurrent, this_k(), -1,wait);
+      DTRACE_CLASSINIT_PROBE_WAIT(concurrent, this_k, -1,wait);
       return;
     }
 
     // Step 5
     if (this_k->is_in_error_state()) {
-      DTRACE_CLASSINIT_PROBE_WAIT(erroneous, this_k(), -1,wait);
+      DTRACE_CLASSINIT_PROBE_WAIT(erroneous, this_k, -1,wait);
       ResourceMark rm(THREAD);
       const char* desc = "Could not initialize class ";
       const char* className = this_k->external_name();
@@ -785,7 +782,7 @@
         this_k->set_initialization_state_and_notify(initialization_error, THREAD);
         CLEAR_PENDING_EXCEPTION;
       }
-      DTRACE_CLASSINIT_PROBE_WAIT(super__failed, this_k(), -1,wait);
+      DTRACE_CLASSINIT_PROBE_WAIT(super__failed, this_k, -1,wait);
       THROW_OOP(e());
     }
   }
@@ -798,7 +795,7 @@
   {
     assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl");
     JavaThread* jt = (JavaThread*)THREAD;
-    DTRACE_CLASSINIT_PROBE_WAIT(clinit, this_k(), -1,wait);
+    DTRACE_CLASSINIT_PROBE_WAIT(clinit, this_k, -1,wait);
     // Timer includes any side effects of class initialization (resolution,
     // etc), but not recursive entry into call_class_initializer().
     PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
@@ -832,7 +829,7 @@
       // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
       JvmtiExport::clear_detected_exception((JavaThread*)THREAD);
     }
-    DTRACE_CLASSINIT_PROBE_WAIT(error, this_k(), -1,wait);
+    DTRACE_CLASSINIT_PROBE_WAIT(error, this_k, -1,wait);
     if (e->is_a(SystemDictionary::Error_klass())) {
       THROW_OOP(e());
     } else {
@@ -842,25 +839,24 @@
                 &args);
     }
   }
-  DTRACE_CLASSINIT_PROBE_WAIT(end, this_k(), -1,wait);
+  DTRACE_CLASSINIT_PROBE_WAIT(end, this_k, -1,wait);
 }
 
 
 // Note: implementation moved to static method to expose the this pointer.
 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
-  instanceKlassHandle kh(THREAD, this);
-  set_initialization_state_and_notify_impl(kh, state, CHECK);
+  set_initialization_state_and_notify_impl(this, state, CHECK);
 }
 
-void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_k, ClassState state, TRAPS) {
-  oop init_lock = this_k->init_lock();
-  if (init_lock != NULL) {
+void InstanceKlass::set_initialization_state_and_notify_impl(InstanceKlass* this_k, ClassState state, TRAPS) {
+  Handle init_lock(THREAD, this_k->init_lock());
+  if (init_lock() != NULL) {
     ObjectLocker ol(init_lock, THREAD);
     this_k->set_init_state(state);
     this_k->fence_and_clear_init_lock();
     ol.notify_all(CHECK);
   } else {
-    assert(init_lock != NULL, "The initialization state should never be set twice");
+    assert(init_lock() != NULL, "The initialization state should never be set twice");
     this_k->set_init_state(state);
   }
 }
@@ -994,9 +990,8 @@
   }
   int size = objArrayOopDesc::object_size(length);
   Klass* ak = array_klass(n, CHECK_NULL);
-  KlassHandle h_ak (THREAD, ak);
   objArrayOop o =
-    (objArrayOop)CollectedHeap::array_allocate(h_ak, size, length, CHECK_NULL);
+    (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_NULL);
   return o;
 }
 
@@ -1019,11 +1014,9 @@
   bool has_finalizer_flag = has_finalizer(); // Query before possible GC
   int size = size_helper();  // Query before forming handle.
 
-  KlassHandle h_k(THREAD, this);
-
   instanceOop i;
 
-  i = (instanceOop)CollectedHeap::obj_allocate(h_k, size, CHECK_NULL);
+  i = (instanceOop)CollectedHeap::obj_allocate(this, size, CHECK_NULL);
   if (has_finalizer_flag && !RegisterFinalizersAtInit) {
     i = register_finalizer(i, CHECK_NULL);
   }
@@ -1044,11 +1037,10 @@
 }
 
 Klass* InstanceKlass::array_klass_impl(bool or_null, int n, TRAPS) {
-  instanceKlassHandle this_k(THREAD, this);
-  return array_klass_impl(this_k, or_null, n, THREAD);
+  return array_klass_impl(this, or_null, n, THREAD);
 }
 
-Klass* InstanceKlass::array_klass_impl(instanceKlassHandle this_k, bool or_null, int n, TRAPS) {
+Klass* InstanceKlass::array_klass_impl(InstanceKlass* this_k, bool or_null, int n, TRAPS) {
   // Need load-acquire for lock-free read
   if (this_k->array_klasses_acquire() == NULL) {
     if (or_null) return NULL;
@@ -1081,13 +1073,12 @@
 }
 
 void InstanceKlass::call_class_initializer(TRAPS) {
-  instanceKlassHandle ik (THREAD, this);
-  call_class_initializer_impl(ik, THREAD);
+  call_class_initializer_impl(this, THREAD);
 }
 
 static int call_class_initializer_impl_counter = 0;   // for debugging
 
-Method* InstanceKlass::class_initializer() {
+Method* InstanceKlass::class_initializer() const {
   Method* clinit = find_method(
       vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
   if (clinit != NULL && clinit->has_valid_initializer_flags()) {
@@ -1096,7 +1087,7 @@
   return NULL;
 }
 
-void InstanceKlass::call_class_initializer_impl(instanceKlassHandle this_k, TRAPS) {
+void InstanceKlass::call_class_initializer_impl(InstanceKlass* this_k, TRAPS) {
   if (ReplayCompiles &&
       (ReplaySuppressInitializers == 1 ||
        ReplaySuppressInitializers >= 2 && this_k->class_loader() != NULL)) {
@@ -1111,7 +1102,7 @@
     outputStream* log = Log(class, init)::info_stream();
     log->print("%d Initializing ", call_class_initializer_impl_counter++);
     this_k->name()->print_value_on(log);
-    log->print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", p2i(this_k()));
+    log->print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", p2i(this_k));
   }
   if (h_method() != NULL) {
     JavaCallArguments args; // No arguments
@@ -1262,14 +1253,13 @@
 
 
 void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle mirror, TRAPS) {
-  instanceKlassHandle h_this(THREAD, this);
-  do_local_static_fields_impl(h_this, f, mirror, CHECK);
+  do_local_static_fields_impl(this, f, mirror, CHECK);
 }
 
 
-void InstanceKlass::do_local_static_fields_impl(instanceKlassHandle this_k,
+void InstanceKlass::do_local_static_fields_impl(InstanceKlass* this_k,
                              void f(fieldDescriptor* fd, Handle, TRAPS), Handle mirror, TRAPS) {
-  for (JavaFieldStream fs(this_k()); !fs.done(); fs.next()) {
+  for (JavaFieldStream fs(this_k); !fs.done(); fs.next()) {
     if (fs.access_flags().is_static()) {
       fieldDescriptor& fd = fs.field_descriptor();
       f(&fd, mirror, CHECK);
@@ -1628,13 +1618,13 @@
 }
 
 /* jni_id_for_impl for jfieldIds only */
-JNIid* InstanceKlass::jni_id_for_impl(instanceKlassHandle this_k, int offset) {
+JNIid* InstanceKlass::jni_id_for_impl(InstanceKlass* this_k, int offset) {
   MutexLocker ml(JfieldIdCreation_lock);
   // Retry lookup after we got the lock
   JNIid* probe = this_k->jni_ids() == NULL ? NULL : this_k->jni_ids()->find(offset);
   if (probe == NULL) {
     // Slow case, allocate new static field identifier
-    probe = new JNIid(this_k(), offset, this_k->jni_ids());
+    probe = new JNIid(this_k, offset, this_k->jni_ids());
     this_k->set_jni_ids(probe);
   }
   return probe;
@@ -1683,9 +1673,9 @@
 // locking has to be done very carefully to avoid deadlocks
 // and/or other cache consistency problems.
 //
-jmethodID InstanceKlass::get_jmethod_id(instanceKlassHandle ik_h, const methodHandle& method_h) {
+jmethodID InstanceKlass::get_jmethod_id(InstanceKlass* ik, const methodHandle& method_h) {
   size_t idnum = (size_t)method_h->method_idnum();
-  jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire();
+  jmethodID* jmeths = ik->methods_jmethod_ids_acquire();
   size_t length = 0;
   jmethodID id = NULL;
 
@@ -1709,7 +1699,7 @@
 
   if (jmeths != NULL) {
     // the cache already exists
-    if (!ik_h->idnum_can_increment()) {
+    if (!ik->idnum_can_increment()) {
       // the cache can't grow so we can just get the current values
       get_jmethod_id_length_value(jmeths, idnum, &length, &id);
     } else {
@@ -1743,7 +1733,7 @@
     jmethodID* new_jmeths = NULL;
     if (length <= idnum) {
       // allocate a new cache that might be used
-      size_t size = MAX2(idnum+1, (size_t)ik_h->idnum_allocated_count());
+      size_t size = MAX2(idnum+1, (size_t)ik->idnum_allocated_count());
       new_jmeths = NEW_C_HEAP_ARRAY(jmethodID, size+1, mtClass);
       memset(new_jmeths, 0, (size+1)*sizeof(jmethodID));
       // cache size is stored in element[0], other elements offset by one
@@ -1754,23 +1744,23 @@
     jmethodID new_id = NULL;
     if (method_h->is_old() && !method_h->is_obsolete()) {
       // The method passed in is old (but not obsolete), we need to use the current version
-      Method* current_method = ik_h->method_with_idnum((int)idnum);
+      Method* current_method = ik->method_with_idnum((int)idnum);
       assert(current_method != NULL, "old and but not obsolete, so should exist");
-      new_id = Method::make_jmethod_id(ik_h->class_loader_data(), current_method);
+      new_id = Method::make_jmethod_id(ik->class_loader_data(), current_method);
     } else {
       // It is the current version of the method or an obsolete method,
       // use the version passed in
-      new_id = Method::make_jmethod_id(ik_h->class_loader_data(), method_h());
+      new_id = Method::make_jmethod_id(ik->class_loader_data(), method_h());
     }
 
     if (Threads::number_of_threads() == 0 ||
         SafepointSynchronize::is_at_safepoint()) {
       // we're single threaded or at a safepoint - no locking needed
-      id = get_jmethod_id_fetch_or_update(ik_h, idnum, new_id, new_jmeths,
+      id = get_jmethod_id_fetch_or_update(ik, idnum, new_id, new_jmeths,
                                           &to_dealloc_id, &to_dealloc_jmeths);
     } else {
       MutexLocker ml(JmethodIdCreation_lock);
-      id = get_jmethod_id_fetch_or_update(ik_h, idnum, new_id, new_jmeths,
+      id = get_jmethod_id_fetch_or_update(ik, idnum, new_id, new_jmeths,
                                           &to_dealloc_id, &to_dealloc_jmeths);
     }
 
@@ -1781,7 +1771,7 @@
     }
     // free up the new ID since it wasn't needed
     if (to_dealloc_id != NULL) {
-      Method::destroy_jmethod_id(ik_h->class_loader_data(), to_dealloc_id);
+      Method::destroy_jmethod_id(ik->class_loader_data(), to_dealloc_id);
     }
   }
   return id;
@@ -1813,7 +1803,7 @@
 // the VMThread or have cache consistency issues.
 //
 jmethodID InstanceKlass::get_jmethod_id_fetch_or_update(
-            instanceKlassHandle ik_h, size_t idnum, jmethodID new_id,
+            InstanceKlass* ik, size_t idnum, jmethodID new_id,
             jmethodID* new_jmeths, jmethodID* to_dealloc_id_p,
             jmethodID** to_dealloc_jmeths_p) {
   assert(new_id != NULL, "sanity check");
@@ -1824,7 +1814,7 @@
          JmethodIdCreation_lock->owned_by_self(), "sanity check");
 
   // reacquire the cache - we are locked, single threaded or at a safepoint
-  jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire();
+  jmethodID* jmeths = ik->methods_jmethod_ids_acquire();
   jmethodID  id     = NULL;
   size_t     length = 0;
 
@@ -1837,7 +1827,7 @@
       }
       *to_dealloc_jmeths_p = jmeths;  // save old cache for later delete
     }
-    ik_h->release_set_methods_jmethod_ids(jmeths = new_jmeths);
+    ik->release_set_methods_jmethod_ids(jmeths = new_jmeths);
   } else {
     // fetch jmethodID (if any) from the existing cache
     id = jmeths[idnum+1];
@@ -2057,11 +2047,10 @@
 }
 
 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
-  instanceKlassHandle ik(THREAD, this);
-  ik->set_package(loader_data, CHECK);
+  set_package(loader_data, CHECK);
   Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
 
-  Array<Method*>* methods = ik->methods();
+  Array<Method*>* methods = this->methods();
   int num_methods = methods->length();
   for (int index2 = 0; index2 < num_methods; ++index2) {
     methodHandle m(THREAD, methods->at(index2));
@@ -2074,14 +2063,14 @@
     // vtables in the shared system dictionary, only the main one.
     // It also redefines the itable too so fix that too.
     ResourceMark rm(THREAD);
-    ik->vtable()->initialize_vtable(false, CHECK);
-    ik->itable()->initialize_itable(false, CHECK);
+    vtable()->initialize_vtable(false, CHECK);
+    itable()->initialize_itable(false, CHECK);
   }
 
   // restore constant pool resolved references
-  ik->constants()->restore_unshareable_info(CHECK);
-
-  ik->array_klasses_do(restore_unshareable_in_class, CHECK);
+  constants()->restore_unshareable_info(CHECK);
+
+  array_klasses_do(restore_unshareable_in_class, CHECK);
 }
 
 // returns true IFF is_in_error_state() has been changed as a result of this call.
@@ -2298,7 +2287,8 @@
 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);
+  Handle class_loader(THREAD, loader_data->class_loader());
+  check_prohibited_package(name(), class_loader, CHECK);
 
   TempNewSymbol pkg_name = package_from_name(name(), CHECK);
 
@@ -2446,7 +2436,7 @@
 }
 
 /* defined for now in jvm.cpp, for historical reasons *--
-Klass* InstanceKlass::compute_enclosing_class_impl(instanceKlassHandle self,
+Klass* InstanceKlass::compute_enclosing_class_impl(InstanceKlass* self,
                                                      Symbol*& simple_name_result, TRAPS) {
   ...
 }
@@ -2458,7 +2448,7 @@
                                              TRAPS) {
   ResourceMark rm(THREAD);
   if (!class_loader.is_null() &&
-      !SystemDictionary::is_platform_class_loader(class_loader) &&
+      !SystemDictionary::is_platform_class_loader(class_loader()) &&
       class_name != NULL &&
       strncmp(class_name->as_C_string(), JAVAPKG, JAVAPKG_LEN) == 0) {
     TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK);
@@ -2520,7 +2510,7 @@
   return false;
 }
 
-bool InstanceKlass::find_inner_classes_attr(instanceKlassHandle k, int* ooff, int* noff, TRAPS) {
+bool InstanceKlass::find_inner_classes_attr(const InstanceKlass* k, int* ooff, int* noff, TRAPS) {
   constantPoolHandle i_cp(THREAD, k->constants());
   for (InnerClassesIterator iter(k); !iter.done(); iter.next()) {
     int ioff = iter.inner_class_info_index();
@@ -2529,7 +2519,7 @@
       // before attempting to find the class.
       if (i_cp->klass_name_at_matches(k, ioff)) {
         Klass* inner_klass = i_cp->klass_at(ioff, CHECK_false);
-        if (k() == inner_klass) {
+        if (k == inner_klass) {
           *ooff = iter.outer_class_info_index();
           *noff = iter.inner_name_index();
           return true;
@@ -2578,8 +2568,7 @@
   jint access = access_flags().as_int();
 
   // But check if it happens to be member class.
-  instanceKlassHandle ik(THREAD, this);
-  InnerClassesIterator iter(ik);
+  InnerClassesIterator iter(this);
   for (; !iter.done(); iter.next()) {
     int ioff = iter.inner_class_info_index();
     // Inner class attribute can be zero, skip it.
@@ -2588,8 +2577,8 @@
 
     // only look at classes that are already loaded
     // since we are looking for the flags for our self.
-    Symbol* inner_name = ik->constants()->klass_name_at(ioff);
-    if ((ik->name() == inner_name)) {
+    Symbol* inner_name = constants()->klass_name_at(ioff);
+    if (name() == inner_name) {
       // This is really a member class.
       access = iter.inner_access_flags();
       break;
@@ -3141,7 +3130,7 @@
         // source is unknown
       }
     } else {
-      Handle class_loader(loader_data->class_loader());
+      oop class_loader = loader_data->class_loader();
       log->print(" source: %s", class_loader->klass()->external_name());
     }
   } else {
@@ -3610,7 +3599,7 @@
 // Save the scratch_class as the previous version if any of the methods are running.
 // The previous_versions are used to set breakpoints in EMCP methods and they are
 // also used to clean MethodData links to redefined methods that are no longer running.
-void InstanceKlass::add_previous_version(instanceKlassHandle scratch_class,
+void InstanceKlass::add_previous_version(InstanceKlass* scratch_class,
                                          int emcp_method_count) {
   assert(Thread::current()->is_VM_thread(),
          "only VMThread can add previous versions");
@@ -3636,7 +3625,7 @@
     log_trace(redefine, class, iklass, add)("scratch class not added; no methods are running");
     // For debugging purposes.
     scratch_class->set_is_scratch_class();
-    scratch_class->class_loader_data()->add_to_deallocate_list(scratch_class());
+    scratch_class->class_loader_data()->add_to_deallocate_list(scratch_class);
     return;
   }
 
@@ -3669,7 +3658,7 @@
   log_trace(redefine, class, iklass, add) ("scratch class added; one of its methods is on_stack.");
   assert(scratch_class->previous_versions() == NULL, "shouldn't have a previous version");
   scratch_class->link_previous_versions(previous_versions());
-  link_previous_versions(scratch_class());
+  link_previous_versions(scratch_class);
 } // end add_previous_version()
 
 #endif // INCLUDE_JVMTI
--- a/hotspot/src/share/vm/oops/instanceKlass.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/instanceKlass.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -472,7 +472,7 @@
                                                      TRAPS);
 
   // Find InnerClasses attribute for k and return outer_class_info_index & inner_name_index.
-  static bool find_inner_classes_attr(instanceKlassHandle k,
+  static bool find_inner_classes_attr(const InstanceKlass* k,
                                       int* ooff, int* noff, TRAPS);
 
  private:
@@ -524,7 +524,7 @@
   void unlink_class();
   void rewrite_class(TRAPS);
   void link_methods(TRAPS);
-  Method* class_initializer();
+  Method* class_initializer() const;
 
   // set the class to initialized if no static initializer is present
   void eager_initialize(Thread *thread);
@@ -711,7 +711,7 @@
   void set_is_being_redefined(bool value)  { _is_being_redefined = value; }
 
   // RedefineClasses() support for previous versions:
-  void add_previous_version(instanceKlassHandle ikh, int emcp_method_count);
+  void add_previous_version(InstanceKlass* ik, int emcp_method_count);
   void purge_previous_version_list();
 
   InstanceKlass* previous_versions() const { return _previous_versions; }
@@ -883,9 +883,9 @@
                                     u2 method_index);
 
   // jmethodID support
-  static jmethodID get_jmethod_id(instanceKlassHandle ik_h,
+  static jmethodID get_jmethod_id(InstanceKlass* ik,
                      const methodHandle& method_h);
-  static jmethodID get_jmethod_id_fetch_or_update(instanceKlassHandle ik_h,
+  static jmethodID get_jmethod_id_fetch_or_update(InstanceKlass* ik,
                      size_t idnum, jmethodID new_id, jmethodID* new_jmeths,
                      jmethodID* to_dealloc_id_p,
                      jmethodID** to_dealloc_jmeths_p);
@@ -1308,17 +1308,17 @@
 
   // Static methods that are used to implement member methods where an exposed this pointer
   // is needed due to possible GCs
-  static bool link_class_impl                           (instanceKlassHandle this_k, bool throw_verifyerror, TRAPS);
-  static bool verify_code                               (instanceKlassHandle this_k, bool throw_verifyerror, TRAPS);
-  static void initialize_impl                           (instanceKlassHandle this_k, TRAPS);
-  static void initialize_super_interfaces               (instanceKlassHandle this_k, TRAPS);
-  static void eager_initialize_impl                     (instanceKlassHandle this_k);
-  static void set_initialization_state_and_notify_impl  (instanceKlassHandle this_k, ClassState state, TRAPS);
-  static void call_class_initializer_impl               (instanceKlassHandle this_k, TRAPS);
-  static Klass* array_klass_impl                        (instanceKlassHandle this_k, bool or_null, int n, TRAPS);
-  static void do_local_static_fields_impl               (instanceKlassHandle this_k, void f(fieldDescriptor* fd, Handle, TRAPS), Handle, TRAPS);
+  static bool link_class_impl                           (InstanceKlass* this_k, bool throw_verifyerror, TRAPS);
+  static bool verify_code                               (InstanceKlass* this_k, bool throw_verifyerror, TRAPS);
+  static void initialize_impl                           (InstanceKlass* this_k, TRAPS);
+  static void initialize_super_interfaces               (InstanceKlass* this_k, TRAPS);
+  static void eager_initialize_impl                     (InstanceKlass* this_k);
+  static void set_initialization_state_and_notify_impl  (InstanceKlass* this_k, ClassState state, TRAPS);
+  static void call_class_initializer_impl               (InstanceKlass* this_k, TRAPS);
+  static Klass* array_klass_impl                        (InstanceKlass* this_k, bool or_null, int n, TRAPS);
+  static void do_local_static_fields_impl               (InstanceKlass* this_k, void f(fieldDescriptor* fd, Handle, TRAPS), Handle, TRAPS);
   /* jni_id_for_impl for jfieldID only */
-  static JNIid* jni_id_for_impl                         (instanceKlassHandle this_k, int offset);
+  static JNIid* jni_id_for_impl                         (InstanceKlass* this_k, int offset);
 
   // Returns the array class for the n'th dimension
   Klass* array_klass_impl(bool or_null, int n, TRAPS);
@@ -1447,7 +1447,7 @@
   int _idx;
  public:
 
-  InnerClassesIterator(instanceKlassHandle k) {
+  InnerClassesIterator(const InstanceKlass* k) {
     _inner_classes = k->inner_classes();
     if (k->inner_classes() != NULL) {
       _length = _inner_classes->length();
--- a/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/instanceMirrorKlass.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -39,23 +39,21 @@
 
 int InstanceMirrorKlass::_offset_of_static_fields = 0;
 
-int InstanceMirrorKlass::instance_size(KlassHandle k) {
-  if (k() != NULL && k->is_instance_klass()) {
-    return align_object_size(size_helper() + InstanceKlass::cast(k())->static_field_size());
+int InstanceMirrorKlass::instance_size(Klass* k) {
+  if (k != NULL && k->is_instance_klass()) {
+    return align_object_size(size_helper() + InstanceKlass::cast(k)->static_field_size());
   }
   return size_helper();
 }
 
-instanceOop InstanceMirrorKlass::allocate_instance(KlassHandle k, TRAPS) {
+instanceOop InstanceMirrorKlass::allocate_instance(Klass* k, TRAPS) {
   // Query before forming handle.
   int size = instance_size(k);
-  KlassHandle h_k(THREAD, this);
-
   assert(size > 0, "total object size must be positive: %d", size);
 
   // Since mirrors can be variable sized because of the static fields, store
   // the size in the mirror itself.
-  return (instanceOop)CollectedHeap::class_allocate(h_k, size, CHECK_NULL);
+  return (instanceOop)CollectedHeap::class_allocate(this, size, CHECK_NULL);
 }
 
 int InstanceMirrorKlass::oop_size(oop obj) const {
--- a/hotspot/src/share/vm/oops/instanceMirrorKlass.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/instanceMirrorKlass.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -82,10 +82,10 @@
   int compute_static_oop_field_count(oop obj);
 
   // Given a Klass return the size of the instance
-  int instance_size(KlassHandle k);
+  int instance_size(Klass* k);
 
   // allocation
-  instanceOop allocate_instance(KlassHandle k, TRAPS);
+  instanceOop allocate_instance(Klass* k, TRAPS);
 
   // GC specific object visitors
   //
--- a/hotspot/src/share/vm/oops/klass.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/klass.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -168,7 +168,7 @@
 
 // "Normal" instantiation is preceeded by a MetaspaceObj allocation
 // which zeros out memory - calloc equivalent.
-// The constructor is also used from init_self_patching_vtbl_list,
+// The constructor is also used from CppVtableCloner,
 // which doesn't zero out the memory before calling the constructor.
 // Need to set the _java_mirror field explicitly to not hit an assert that the field
 // should be NULL before setting it.
@@ -264,7 +264,6 @@
   }
 
   if (secondary_supers() == NULL) {
-    KlassHandle this_kh (THREAD, this);
 
     // Now compute the list of secondary supertypes.
     // Secondaries can occasionally be on the super chain,
@@ -286,7 +285,7 @@
 
     GrowableArray<Klass*>* primaries = new GrowableArray<Klass*>(extras);
 
-    for (p = this_kh->super(); !(p == NULL || p->can_be_primary_super()); p = p->super()) {
+    for (p = super(); !(p == NULL || p->can_be_primary_super()); p = p->super()) {
       int i;                    // Scan for overflow primaries being duplicates of 2nd'arys
 
       // This happens frequently for very deeply nested arrays: the
@@ -324,7 +323,7 @@
     }
   #endif
 
-    this_kh->set_secondary_supers(s2);
+    set_secondary_supers(s2);
   }
 }
 
@@ -501,6 +500,7 @@
 }
 
 void Klass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
+  assert(is_klass(), "ensure C++ vtable is restored");
   TRACE_RESTORE_ID(this);
 
   // If an exception happened during CDS restore, some of these fields may already be
@@ -519,7 +519,7 @@
   // Only recreate it if not present.  A previous attempt to restore may have
   // gotten an OOM later but keep the mirror if it was created.
   if (java_mirror() == NULL) {
-    Handle loader = loader_data->class_loader();
+    Handle loader(THREAD, loader_data->class_loader());
     ModuleEntry* module_entry = NULL;
     Klass* k = this;
     if (k->is_objArray_klass()) {
@@ -697,7 +697,7 @@
 }
 
 klassVtable* Klass::vtable() const {
-  return new klassVtable(this, start_of_vtable(), vtable_length() / vtableEntry::size());
+  return new klassVtable(const_cast<Klass*>(this), start_of_vtable(), vtable_length() / vtableEntry::size());
 }
 
 vtableEntry* Klass::start_of_vtable() const {
--- a/hotspot/src/share/vm/oops/klassVtable.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/klassVtable.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@
 #include "utilities/copy.hpp"
 
 inline InstanceKlass* klassVtable::ik() const {
-  return InstanceKlass::cast(_klass());
+  return InstanceKlass::cast(_klass);
 }
 
 bool klassVtable::is_preinitialized_vtable() {
@@ -128,8 +128,8 @@
 // Copy super class's vtable to the first part (prefix) of this class's vtable,
 // and return the number of entries copied.  Expects that 'super' is the Java
 // super class (arrays can have "array" super classes that must be skipped).
-int klassVtable::initialize_from_super(KlassHandle super) {
-  if (super.is_null()) {
+int klassVtable::initialize_from_super(Klass* super) {
+  if (super == NULL) {
     return 0;
   } else if (is_preinitialized_vtable()) {
     // A shared class' vtable is preinitialized at dump time. No need to copy
@@ -160,18 +160,18 @@
 void klassVtable::initialize_vtable(bool checkconstraints, TRAPS) {
 
   // Note:  Arrays can have intermediate array supers.  Use java_super to skip them.
-  KlassHandle super (THREAD, klass()->java_super());
+  Klass* super = _klass->java_super();
   int nofNewEntries = 0;
 
   bool is_shared = _klass->is_shared();
 
-  if (!klass()->is_array_klass()) {
+  if (!_klass->is_array_klass()) {
     ResourceMark rm(THREAD);
     log_develop_debug(vtables)("Initializing: %s", _klass->name()->as_C_string());
   }
 
 #ifdef ASSERT
-  oop* end_of_obj = (oop*)_klass() + _klass()->size();
+  oop* end_of_obj = (oop*)_klass + _klass->size();
   oop* end_of_vtable = (oop*)&table()[_length];
   assert(end_of_vtable <= end_of_obj, "vtable extends beyond end");
 #endif
@@ -184,7 +184,7 @@
   }
 
   int super_vtable_len = initialize_from_super(super);
-  if (klass()->is_array_klass()) {
+  if (_klass->is_array_klass()) {
     assert(super_vtable_len == _length, "arrays shouldn't introduce new methods");
   } else {
     assert(_klass->is_instance_klass(), "must be InstanceKlass");
@@ -327,7 +327,7 @@
 }
 
 static void log_vtables(int i, bool overrides, methodHandle target_method,
-                        KlassHandle target_klass, Method* super_method,
+                        Klass* target_klass, Method* super_method,
                         Thread* thread) {
 #ifndef PRODUCT
   if (log_develop_is_enabled(Trace, vtables)) {
@@ -432,7 +432,7 @@
   Symbol* name = target_method()->name();
   Symbol* signature = target_method()->signature();
 
-  KlassHandle target_klass(THREAD, target_method()->method_holder());
+  Klass* target_klass = target_method()->method_holder();
   if (target_klass == NULL) {
     target_klass = _klass;
   }
@@ -955,7 +955,7 @@
       if (!(*trace_name_printed)) {
         log_info(redefine, class, update)
           ("adjust: klassname=%s for methods from name=%s",
-           klass()->external_name(), old_method->method_holder()->external_name());
+           _klass->external_name(), old_method->method_holder()->external_name());
         *trace_name_printed = true;
       }
       log_debug(redefine, class, update, vtables)
@@ -1025,17 +1025,17 @@
   }
 }
 
-klassItable::klassItable(instanceKlassHandle klass) {
+klassItable::klassItable(InstanceKlass* klass) {
   _klass = klass;
 
   if (klass->itable_length() > 0) {
     itableOffsetEntry* offset_entry = (itableOffsetEntry*)klass->start_of_itable();
     if (offset_entry  != NULL && offset_entry->interface_klass() != NULL) { // Check that itable is initialized
       // First offset entry points to the first method_entry
-      intptr_t* method_entry  = (intptr_t *)(((address)klass()) + offset_entry->offset());
+      intptr_t* method_entry  = (intptr_t *)(((address)klass) + offset_entry->offset());
       intptr_t* end         = klass->end_of_itable();
 
-      _table_offset      = (intptr_t*)offset_entry - (intptr_t*)klass();
+      _table_offset      = (intptr_t*)offset_entry - (intptr_t*)klass;
       _size_offset_table = (method_entry - ((intptr_t*)offset_entry)) / itableOffsetEntry::size();
       _size_method_table = (end - method_entry)                  / itableMethodEntry::size();
       assert(_table_offset >= 0 && _size_offset_table >= 0 && _size_method_table >= 0, "wrong computation");
@@ -1056,7 +1056,7 @@
   if (_klass->is_interface()) {
     // This needs to go after vtable indices are assigned but
     // before implementors need to know the number of itable indices.
-    assign_itable_indices_for_interface(_klass());
+    assign_itable_indices_for_interface(_klass);
   }
 
   // Cannot be setup doing bootstrapping, interfaces don't have
@@ -1078,9 +1078,9 @@
     for(i = 0; i < num_interfaces; i++) {
       itableOffsetEntry* ioe = offset_entry(i);
       HandleMark hm(THREAD);
-      KlassHandle interf_h (THREAD, ioe->interface_klass());
-      assert(interf_h() != NULL && ioe->offset() != 0, "bad offset entry in itable");
-      initialize_itable_for_interface(ioe->offset(), interf_h, checkconstraints, CHECK);
+      Klass* interf = ioe->interface_klass();
+      assert(interf != NULL && ioe->offset() != 0, "bad offset entry in itable");
+      initialize_itable_for_interface(ioe->offset(), interf, checkconstraints, CHECK);
     }
 
   }
@@ -1169,14 +1169,14 @@
 }
 
 
-void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) {
-  Array<Method*>* methods = InstanceKlass::cast(interf_h())->methods();
+void klassItable::initialize_itable_for_interface(int method_table_offset, Klass* interf, bool checkconstraints, TRAPS) {
+  Array<Method*>* methods = InstanceKlass::cast(interf)->methods();
   int nof_methods = methods->length();
   HandleMark hm;
   assert(nof_methods > 0, "at least one method must exist for interface to be in vtable");
-  Handle interface_loader (THREAD, InstanceKlass::cast(interf_h())->class_loader());
+  Handle interface_loader (THREAD, InstanceKlass::cast(interf)->class_loader());
 
-  int ime_count = method_count_for_interface(interf_h());
+  int ime_count = method_count_for_interface(interf);
   for (int i = 0; i < nof_methods; i++) {
     Method* m = methods->at(i);
     methodHandle target;
@@ -1189,7 +1189,7 @@
       // Entry does not resolve. Leave it empty for AbstractMethodError.
         if (!(target == NULL) && !target->is_public()) {
           // Stuff an IllegalAccessError throwing method in there instead.
-          itableOffsetEntry::method_entry(_klass(), method_table_offset)[m->itable_index()].
+          itableOffsetEntry::method_entry(_klass, method_table_offset)[m->itable_index()].
               initialize(Universe::throw_illegal_access_error());
         }
     } else {
@@ -1215,7 +1215,7 @@
             const char* loader1 = SystemDictionary::loader_name(method_holder_loader());
             char* current = _klass->name()->as_C_string();
             const char* loader2 = SystemDictionary::loader_name(interface_loader());
-            char* iface = InstanceKlass::cast(interf_h())->name()->as_C_string();
+            char* iface = InstanceKlass::cast(interf)->name()->as_C_string();
             char* failed_type_name = failed_type_symbol->as_C_string();
             size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) +
               strlen(current) + strlen(loader2) + strlen(iface) +
@@ -1231,14 +1231,14 @@
       // ime may have moved during GC so recalculate address
       int ime_num = m->itable_index();
       assert(ime_num < ime_count, "oob");
-      itableOffsetEntry::method_entry(_klass(), method_table_offset)[ime_num].initialize(target());
+      itableOffsetEntry::method_entry(_klass, method_table_offset)[ime_num].initialize(target());
       if (log_develop_is_enabled(Trace, itables)) {
         ResourceMark rm(THREAD);
         if (target() != NULL) {
           outputStream* logst = Log(itables)::trace_stream();
           char* sig = target()->name_and_sig_as_C_string();
           logst->print("interface: %s, ime_num: %d, target: %s, method_holder: %s ",
-                       interf_h()->internal_name(), ime_num, sig,
+                       interf->internal_name(), ime_num, sig,
                        target()->method_holder()->internal_name());
           logst->print("target_method flags: ");
           target()->print_linkage_flags(logst);
@@ -1408,7 +1408,7 @@
 
 
 // Fill out offset table and interface klasses into the itable space
-void klassItable::setup_itable_offset_table(instanceKlassHandle klass) {
+void klassItable::setup_itable_offset_table(InstanceKlass* klass) {
   if (klass->itable_length() == 0) return;
   assert(!klass->is_interface(), "Should have zero length itable");
 
@@ -1433,7 +1433,7 @@
   assert((oop*)(end) == (oop*)(ime + nof_methods),                      "wrong offset calculation (2)");
 
   // Visit all interfaces and initialize itable offset table
-  SetupItableClosure sic((address)klass(), ioe, ime);
+  SetupItableClosure sic((address)klass, ioe, ime);
   visit_all_interfaces(klass->transitive_interfaces(), &sic);
 
 #ifdef ASSERT
@@ -1476,7 +1476,7 @@
   if (!forced && _verify_count == Universe::verify_count()) return;
   _verify_count = Universe::verify_count();
 #endif
-  oop* end_of_obj = (oop*)_klass() + _klass()->size();
+  oop* end_of_obj = (oop*)_klass + _klass->size();
   oop* end_of_vtable = (oop *)&table()[_length];
   if (end_of_vtable > end_of_obj) {
     fatal("klass %s: klass object too short (vtable extends beyond end)",
@@ -1516,8 +1516,7 @@
 
 void vtableEntry::verify(klassVtable* vt, outputStream* st) {
   NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
-  KlassHandle vtklass_h = vt->klass();
-  Klass* vtklass = vtklass_h();
+  Klass* vtklass = vt->klass();
   if (vtklass->is_instance_klass() &&
      (InstanceKlass::cast(vtklass)->major_version() >= klassVtable::VTABLE_TRANSITIVE_OVERRIDE_VERSION)) {
     assert(method() != NULL, "must have set method");
@@ -1525,7 +1524,7 @@
   if (method() != NULL) {
     method()->verify();
     // we sub_type, because it could be a miranda method
-    if (!vtklass_h->is_subtype_of(method()->method_holder())) {
+    if (!vtklass->is_subtype_of(method()->method_holder())) {
 #ifndef PRODUCT
       print();
 #endif
--- a/hotspot/src/share/vm/oops/klassVtable.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/klassVtable.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@
 class vtableEntry;
 
 class klassVtable : public ResourceObj {
-  KlassHandle  _klass;            // my klass
+  Klass*       _klass;            // my klass
   int          _tableOffset;      // offset of start of vtable data within klass
   int          _length;           // length of vtable (number of entries)
 #ifndef PRODUCT
@@ -57,13 +57,13 @@
   };
 
  public:
-  klassVtable(KlassHandle h_klass, void* base, int length) : _klass(h_klass) {
-    _tableOffset = (address)base - (address)h_klass(); _length = length;
+  klassVtable(Klass* klass, void* base, int length) : _klass(klass) {
+    _tableOffset = (address)base - (address)klass; _length = length;
   }
 
   // accessors
-  vtableEntry* table() const      { return (vtableEntry*)(address(_klass()) + _tableOffset); }
-  KlassHandle klass() const       { return _klass;  }
+  vtableEntry* table() const      { return (vtableEntry*)(address(_klass) + _tableOffset); }
+  Klass* klass() const            { return _klass;  }
   int length() const              { return _length; }
   inline Method* method_at(int i) const;
   inline Method* unchecked_method_at(int i) const;
@@ -125,7 +125,7 @@
 
  private:
   void copy_vtable_to(vtableEntry* start);
-  int  initialize_from_super(KlassHandle super);
+  int  initialize_from_super(Klass* super);
   int  index_of(Method* m, int len) const; // same as index_of, but search only up to len
   void put_method_at(Method* m, int index);
   static bool needs_new_vtable_entry(methodHandle m,
@@ -290,14 +290,14 @@
 //
 class klassItable : public ResourceObj {
  private:
-  instanceKlassHandle  _klass;             // my klass
+  InstanceKlass*       _klass;             // my klass
   int                  _table_offset;      // offset of start of itable data within klass (in words)
   int                  _size_offset_table; // size of offset table (in itableOffset entries)
   int                  _size_method_table; // size of methodtable (in itableMethodEntry entries)
 
-  void initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS);
+  void initialize_itable_for_interface(int method_table_offset, Klass* interf_h, bool checkconstraints, TRAPS);
  public:
-  klassItable(instanceKlassHandle klass);
+  klassItable(InstanceKlass* klass);
 
   itableOffsetEntry* offset_entry(int i) { assert(0 <= i && i <= _size_offset_table, "index out of bounds");
                                            return &((itableOffsetEntry*)vtable_start())[i]; }
@@ -329,7 +329,7 @@
   static int assign_itable_indices_for_interface(Klass* klass);
   static int method_count_for_interface(Klass* klass);
   static int compute_itable_size(Array<Klass*>* transitive_interfaces);
-  static void setup_itable_offset_table(instanceKlassHandle klass);
+  static void setup_itable_offset_table(InstanceKlass* klass);
 
   // Resolving of method to index
   static Method* method_for_itable_index(Klass* klass, int itable_index);
@@ -337,7 +337,7 @@
   // Debugging/Statistics
   static void print_statistics() PRODUCT_RETURN;
  private:
-  intptr_t* vtable_start() const { return ((intptr_t*)_klass()) + _table_offset; }
+  intptr_t* vtable_start() const { return ((intptr_t*)_klass) + _table_offset; }
   intptr_t* method_start() const { return vtable_start() + _size_offset_table * itableOffsetEntry::size(); }
 
   // Helper methods
--- a/hotspot/src/share/vm/oops/method.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/method.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -173,7 +173,7 @@
   return buf;
 }
 
-int Method::fast_exception_handler_bci_for(methodHandle mh, KlassHandle ex_klass, int throw_bci, TRAPS) {
+int Method::fast_exception_handler_bci_for(methodHandle mh, Klass* ex_klass, int throw_bci, TRAPS) {
   // exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index)
   // access exception table
   ExceptionTable table(mh());
@@ -192,16 +192,15 @@
       int klass_index = table.catch_type_index(i);
       if (klass_index == 0) {
         return handler_bci;
-      } else if (ex_klass.is_null()) {
+      } else if (ex_klass == NULL) {
         return handler_bci;
       } else {
         // we know the exception class => get the constraint class
         // this may require loading of the constraint class; if verification
         // fails or some other exception occurs, return handler_bci
         Klass* k = pool->klass_at(klass_index, CHECK_(handler_bci));
-        KlassHandle klass = KlassHandle(THREAD, k);
-        assert(klass.not_null(), "klass not loaded");
-        if (ex_klass->is_subtype_of(klass())) {
+        assert(k != NULL, "klass not loaded");
+        if (ex_klass->is_subtype_of(k)) {
           return handler_bci;
         }
       }
@@ -1101,12 +1100,11 @@
 }
 
 void Method::restore_unshareable_info(TRAPS) {
+  assert(is_method() && is_valid_method(), "ensure C++ vtable is restored");
+
   // Since restore_unshareable_info can be called more than once for a method, don't
   // redo any work.
   if (adapter() == NULL) {
-    // Restore Method's C++ vtable by calling a virtual function
-    restore_vtable();
-
     methodHandle mh(THREAD, this);
     link_method(mh, CHECK);
   }
@@ -1272,7 +1270,7 @@
   ResourceMark rm;
   methodHandle empty;
 
-  KlassHandle holder = SystemDictionary::MethodHandle_klass();
+  InstanceKlass* holder = SystemDictionary::MethodHandle_klass();
   Symbol* name = MethodHandles::signature_polymorphic_intrinsic_name(iid);
   assert(iid == MethodHandles::signature_polymorphic_name_id(name), "");
   if (TraceMethodHandles) {
@@ -1290,7 +1288,7 @@
     ConstantPool* cp_oop = ConstantPool::allocate(loader_data, cp_length, CHECK_(empty));
     cp = constantPoolHandle(THREAD, cp_oop);
   }
-  cp->set_pool_holder(InstanceKlass::cast(holder()));
+  cp->set_pool_holder(holder);
   cp->symbol_at_put(_imcp_invoke_name,       name);
   cp->symbol_at_put(_imcp_invoke_signature,  signature);
   cp->set_has_preresolution();
@@ -2166,7 +2164,6 @@
 bool Method::has_method_vptr(const void* ptr) {
   Method m;
   // This assumes that the vtbl pointer is the first word of a C++ object.
-  // This assumption is also in universe.cpp patch_klass_vtble
   return dereference_vptr(&m) == dereference_vptr(ptr);
 }
 
@@ -2177,10 +2174,12 @@
   } else if ((intptr_t(this) & (wordSize-1)) != 0) {
     // Quick sanity check on pointer.
     return false;
-  } else if (!is_metaspace_object()) {
+  } else if (MetaspaceShared::is_in_shared_space(this)) {
+    return MetaspaceShared::is_valid_shared_method(this);
+  } else if (Metaspace::contains_non_shared(this)) {
+    return has_method_vptr((const void*)this);
+  } else {
     return false;
-  } else {
-    return has_method_vptr((const void*)this);
   }
 }
 
--- a/hotspot/src/share/vm/oops/method.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/method.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -122,11 +122,6 @@
   // CDS and vtbl checking can create an empty Method to get vtbl pointer.
   Method(){}
 
-  // The Method vtable is restored by this call when the Method is in the
-  // shared archive.  See patch_klass_vtables() in metaspaceShared.cpp for
-  // all the gory details.  SA, dtrace and pstack helpers distinguish metadata
-  // by their vtable.
-  void restore_vtable() { guarantee(is_method(), "vtable restored by this call"); }
   bool is_method() const volatile { return true; }
 
   void restore_unshareable_info(TRAPS);
@@ -328,7 +323,7 @@
   // exception handler which caused the exception to be thrown, which
   // is needed for proper retries. See, for example,
   // InterpreterRuntime::exception_handler_for_exception.
-  static int fast_exception_handler_bci_for(methodHandle mh, KlassHandle ex_klass, int throw_bci, TRAPS);
+  static int fast_exception_handler_bci_for(methodHandle mh, Klass* ex_klass, int throw_bci, TRAPS);
 
   // method data access
   MethodData* method_data() const              {
@@ -816,8 +811,7 @@
   static void print_jmethod_ids(ClassLoaderData* loader_data, outputStream* out) PRODUCT_RETURN;
 
   // Get this method's jmethodID -- allocate if it doesn't exist
-  jmethodID jmethod_id()                            { methodHandle this_h(this);
-                                                      return InstanceKlass::get_jmethod_id(method_holder(), this_h); }
+  jmethodID jmethod_id()                            { return InstanceKlass::get_jmethod_id(method_holder(), this); }
 
   // Lookup the jmethodID for this method.  Return NULL if not found.
   // NOTE that this function can be called from a signal handler
--- a/hotspot/src/share/vm/oops/objArrayKlass.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/objArrayKlass.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -46,26 +46,26 @@
 #include "utilities/copy.hpp"
 #include "utilities/macros.hpp"
 
-ObjArrayKlass* ObjArrayKlass::allocate(ClassLoaderData* loader_data, int n, KlassHandle klass_handle, Symbol* name, TRAPS) {
+ObjArrayKlass* ObjArrayKlass::allocate(ClassLoaderData* loader_data, int n, Klass* k, Symbol* name, TRAPS) {
   assert(ObjArrayKlass::header_size() <= InstanceKlass::header_size(),
       "array klasses must be same size as InstanceKlass");
 
   int size = ArrayKlass::static_size(ObjArrayKlass::header_size());
 
-  return new (loader_data, size, THREAD) ObjArrayKlass(n, klass_handle, name);
+  return new (loader_data, size, THREAD) ObjArrayKlass(n, k, name);
 }
 
 Klass* ObjArrayKlass::allocate_objArray_klass(ClassLoaderData* loader_data,
-                                                int n, KlassHandle element_klass, TRAPS) {
+                                                int n, Klass* element_klass, TRAPS) {
 
   // Eagerly allocate the direct array supertype.
-  KlassHandle super_klass = KlassHandle();
+  Klass* super_klass = NULL;
   if (!Universe::is_bootstrapping() || SystemDictionary::Object_klass_loaded()) {
-    KlassHandle element_super (THREAD, element_klass->super());
-    if (element_super.not_null()) {
+    Klass* element_super = element_klass->super();
+    if (element_super != NULL) {
       // The element type has a direct super.  E.g., String[] has direct super of Object[].
-      super_klass = KlassHandle(THREAD, element_super->array_klass_or_null());
-      bool supers_exist = super_klass.not_null();
+      super_klass = element_super->array_klass_or_null();
+      bool supers_exist = super_klass != NULL;
       // Also, see if the element has secondary supertypes.
       // We need an array type for each.
       Array<Klass*>* element_supers = element_klass->secondary_supers();
@@ -78,34 +78,30 @@
       }
       if (!supers_exist) {
         // Oops.  Not allocated yet.  Back out, allocate it, and retry.
-        KlassHandle ek;
+        Klass* ek = NULL;
         {
           MutexUnlocker mu(MultiArray_lock);
           MutexUnlocker mc(Compile_lock);   // for vtables
-          Klass* sk = element_super->array_klass(CHECK_0);
-          super_klass = KlassHandle(THREAD, sk);
+          super_klass = element_super->array_klass(CHECK_0);
           for( int i = element_supers->length()-1; i >= 0; i-- ) {
-            KlassHandle elem_super (THREAD, element_supers->at(i));
+            Klass* elem_super = element_supers->at(i);
             elem_super->array_klass(CHECK_0);
           }
           // Now retry from the beginning
-          Klass* klass_oop = element_klass->array_klass(n, CHECK_0);
-          // Create a handle because the enclosing brace, when locking
-          // can cause a gc.  Better to have this function return a Handle.
-          ek = KlassHandle(THREAD, klass_oop);
+          ek = element_klass->array_klass(n, CHECK_0);
         }  // re-lock
-        return ek();
+        return ek;
       }
     } else {
       // The element type is already Object.  Object[] has direct super of Object.
-      super_klass = KlassHandle(THREAD, SystemDictionary::Object_klass());
+      super_klass = SystemDictionary::Object_klass();
     }
   }
 
   // Create type name for klass.
   Symbol* name = NULL;
   if (!element_klass->is_instance_klass() ||
-      (name = InstanceKlass::cast(element_klass())->array_name()) == NULL) {
+      (name = InstanceKlass::cast(element_klass)->array_name()) == NULL) {
 
     ResourceMark rm(THREAD);
     char *name_str = element_klass->name()->as_C_string();
@@ -124,7 +120,7 @@
     new_str[idx++] = '\0';
     name = SymbolTable::new_permanent_symbol(new_str, CHECK_0);
     if (element_klass->is_instance_klass()) {
-      InstanceKlass* ik = InstanceKlass::cast(element_klass());
+      InstanceKlass* ik = InstanceKlass::cast(element_klass);
       ik->set_array_name(name);
     }
   }
@@ -146,9 +142,9 @@
   return oak;
 }
 
-ObjArrayKlass::ObjArrayKlass(int n, KlassHandle element_klass, Symbol* name) : ArrayKlass(name) {
+ObjArrayKlass::ObjArrayKlass(int n, Klass* element_klass, Symbol* name) : ArrayKlass(name) {
   this->set_dimension(n);
-  this->set_element_klass(element_klass());
+  this->set_element_klass(element_klass);
   // decrement refcount because object arrays are not explicitly freed.  The
   // InstanceKlass array_name() keeps the name counted while the klass is
   // loaded.
@@ -156,9 +152,9 @@
 
   Klass* bk;
   if (element_klass->is_objArray_klass()) {
-    bk = ObjArrayKlass::cast(element_klass())->bottom_klass();
+    bk = ObjArrayKlass::cast(element_klass)->bottom_klass();
   } else {
-    bk = element_klass();
+    bk = element_klass;
   }
   assert(bk != NULL && (bk->is_instance_klass() || bk->is_typeArray_klass()), "invalid bottom klass");
   this->set_bottom_klass(bk);
@@ -178,8 +174,7 @@
   if (length >= 0) {
     if (length <= arrayOopDesc::max_array_length(T_OBJECT)) {
       int size = objArrayOopDesc::object_size(length);
-      KlassHandle h_k(THREAD, this);
-      return (objArrayOop)CollectedHeap::array_allocate(h_k, size, length, THREAD);
+      return (objArrayOop)CollectedHeap::array_allocate(this, size, length, THREAD);
     } else {
       report_java_out_of_memory("Requested array size exceeds VM limit");
       JvmtiExport::post_array_size_exhausted();
@@ -196,14 +191,14 @@
   int length = *sizes;
   // Call to lower_dimension uses this pointer, so most be called before a
   // possible GC
-  KlassHandle h_lower_dimension(THREAD, lower_dimension());
+  Klass* ld_klass = lower_dimension();
   // If length < 0 allocate will throw an exception.
   objArrayOop array = allocate(length, CHECK_NULL);
   objArrayHandle h_array (THREAD, array);
   if (rank > 1) {
     if (length != 0) {
       for (int index = 0; index < length; index++) {
-        ArrayKlass* ak = ArrayKlass::cast(h_lower_dimension());
+        ArrayKlass* ak = ArrayKlass::cast(ld_klass);
         oop sub_array = ak->multi_allocate(rank-1, &sizes[1], CHECK_NULL);
         h_array->obj_at_put(index, sub_array);
       }
--- a/hotspot/src/share/vm/oops/objArrayKlass.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/objArrayKlass.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -39,8 +39,8 @@
   Klass* _bottom_klass;             // The one-dimensional type (InstanceKlass or TypeArrayKlass)
 
   // Constructor
-  ObjArrayKlass(int n, KlassHandle element_klass, Symbol* name);
-  static ObjArrayKlass* allocate(ClassLoaderData* loader_data, int n, KlassHandle klass_handle, Symbol* name, TRAPS);
+  ObjArrayKlass(int n, Klass* element_klass, Symbol* name);
+  static ObjArrayKlass* allocate(ClassLoaderData* loader_data, int n, Klass* k, Symbol* name, TRAPS);
  public:
   // For dummy objects
   ObjArrayKlass() {}
@@ -69,7 +69,7 @@
 
   // Allocation
   static Klass* allocate_objArray_klass(ClassLoaderData* loader_data,
-                                          int n, KlassHandle element_klass, TRAPS);
+                                          int n, Klass* element_klass, TRAPS);
 
   objArrayOop allocate(int length, TRAPS);
   oop multi_allocate(int rank, jint* sizes, TRAPS);
--- a/hotspot/src/share/vm/oops/oop.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/oop.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -96,9 +96,10 @@
 
 intptr_t oopDesc::slow_identity_hash() {
   // slow case; we have to acquire the micro lock in order to locate the header
+  Thread* THREAD = Thread::current();
   ResetNoHandleMark rnm; // Might be called from LEAF/QUICK ENTRY
-  HandleMark hm;
-  Handle object(this);
+  HandleMark hm(THREAD);
+  Handle object(THREAD, this);
   return ObjectSynchronizer::identity_hash_value_for(object);
 }
 
--- a/hotspot/src/share/vm/oops/typeArrayKlass.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/typeArrayKlass.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -102,13 +102,12 @@
   if (length >= 0) {
     if (length <= max_length()) {
       size_t size = typeArrayOopDesc::object_size(layout_helper(), length);
-      KlassHandle h_k(THREAD, this);
       typeArrayOop t;
       CollectedHeap* ch = Universe::heap();
       if (do_zero) {
-        t = (typeArrayOop)CollectedHeap::array_allocate(h_k, (int)size, length, CHECK_NULL);
+        t = (typeArrayOop)CollectedHeap::array_allocate(this, (int)size, length, CHECK_NULL);
       } else {
-        t = (typeArrayOop)CollectedHeap::array_allocate_nozero(h_k, (int)size, length, CHECK_NULL);
+        t = (typeArrayOop)CollectedHeap::array_allocate_nozero(this, (int)size, length, CHECK_NULL);
       }
       return t;
     } else {
--- a/hotspot/src/share/vm/oops/typeArrayOop.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/typeArrayOop.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -122,19 +122,19 @@
   jbyte byte_at_acquire(int which) const              { return OrderAccess::load_acquire(byte_at_addr(which)); }
   void release_byte_at_put(int which, jbyte contents) { OrderAccess::release_store(byte_at_addr(which), contents); }
 
-  // Java thinks metadata arrays are just arrays of either long or int, since
+  // Java thinks Symbol arrays are just arrays of either long or int, since
   // there doesn't seem to be T_ADDRESS, so this is a bit of unfortunate
   // casting
 #ifdef _LP64
-  Metadata* metadata_at(int which) const {
-    return (Metadata*)*long_at_addr(which); }
-  void metadata_at_put(int which, Metadata* contents) {
+  Symbol* symbol_at(int which) const {
+    return (Symbol*)*long_at_addr(which); }
+  void symbol_at_put(int which, Symbol* contents) {
     *long_at_addr(which) = (jlong)contents;
   }
 #else
-  Metadata* metadata_at(int which) const {
-    return (Metadata*)*int_at_addr(which); }
-  void metadata_at_put(int which, Metadata* contents) {
+  Symbol* symbol_at(int which) const {
+    return (Symbol*)*int_at_addr(which); }
+  void symbol_at_put(int which, Symbol* contents) {
     *int_at_addr(which) = (int)contents;
   }
 #endif // _LP64
--- a/hotspot/src/share/vm/opto/bytecodeInfo.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/opto/bytecodeInfo.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -496,6 +496,8 @@
       C->log()->inline_fail(inline_msg);
     }
   }
+  CompileTask::print_inlining_ul(callee_method, inline_level(),
+                                               caller_bci, inline_msg);
   if (C->print_inlining()) {
     C->print_inlining(callee_method, inline_level(), caller_bci, inline_msg);
     if (callee_method == NULL) tty->print(" callee not monotonic or profiled");
--- a/hotspot/src/share/vm/opto/library_call.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/opto/library_call.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -388,8 +388,11 @@
   // Try to inline the intrinsic.
   if ((CheckIntrinsics ? callee->intrinsic_candidate() : true) &&
       kit.try_to_inline(_last_predicate)) {
+    const char *inline_msg = is_virtual() ? "(intrinsic, virtual)"
+                                          : "(intrinsic)";
+    CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, inline_msg);
     if (C->print_intrinsics() || C->print_inlining()) {
-      C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)");
+      C->print_inlining(callee, jvms->depth() - 1, bci, inline_msg);
     }
     C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
     if (C->log()) {
@@ -405,22 +408,30 @@
   }
 
   // The intrinsic bailed out
-  if (C->print_intrinsics() || C->print_inlining()) {
-    if (jvms->has_method()) {
-      // Not a root compile.
-      const char* msg;
-      if (callee->intrinsic_candidate()) {
-        msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)";
-      } else {
-        msg = is_virtual() ? "failed to inline (intrinsic, virtual), method not annotated"
-                           : "failed to inline (intrinsic), method not annotated";
-      }
+  if (jvms->has_method()) {
+    // Not a root compile.
+    const char* msg;
+    if (callee->intrinsic_candidate()) {
+      msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)";
+    } else {
+      msg = is_virtual() ? "failed to inline (intrinsic, virtual), method not annotated"
+                         : "failed to inline (intrinsic), method not annotated";
+    }
+    CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, msg);
+    if (C->print_intrinsics() || C->print_inlining()) {
       C->print_inlining(callee, jvms->depth() - 1, bci, msg);
-    } else {
-      // Root compile
-      tty->print("Did not generate intrinsic %s%s at bci:%d in",
-               vmIntrinsics::name_at(intrinsic_id()),
-               (is_virtual() ? " (virtual)" : ""), bci);
+    }
+  } else {
+    // Root compile
+    ResourceMark rm;
+    stringStream msg_stream;
+    msg_stream.print("Did not generate intrinsic %s%s at bci:%d in",
+                     vmIntrinsics::name_at(intrinsic_id()),
+                     is_virtual() ? " (virtual)" : "", bci);
+    const char *msg = msg_stream.as_string();
+    log_debug(jit, inlining)("%s", msg);
+    if (C->print_intrinsics() || C->print_inlining()) {
+      tty->print("%s", msg);
     }
   }
   C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed);
@@ -446,8 +457,11 @@
 
   Node* slow_ctl = kit.try_to_predicate(predicate);
   if (!kit.failing()) {
+    const char *inline_msg = is_virtual() ? "(intrinsic, virtual, predicate)"
+                                          : "(intrinsic, predicate)";
+    CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, inline_msg);
     if (C->print_intrinsics() || C->print_inlining()) {
-      C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual, predicate)" : "(intrinsic, predicate)");
+      C->print_inlining(callee, jvms->depth() - 1, bci, inline_msg);
     }
     C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
     if (C->log()) {
@@ -460,16 +474,24 @@
   }
 
   // The intrinsic bailed out
-  if (C->print_intrinsics() || C->print_inlining()) {
-    if (jvms->has_method()) {
-      // Not a root compile.
-      const char* msg = "failed to generate predicate for intrinsic";
+  if (jvms->has_method()) {
+    // Not a root compile.
+    const char* msg = "failed to generate predicate for intrinsic";
+    CompileTask::print_inlining_ul(kit.callee(), jvms->depth() - 1, bci, msg);
+    if (C->print_intrinsics() || C->print_inlining()) {
       C->print_inlining(kit.callee(), jvms->depth() - 1, bci, msg);
-    } else {
-      // Root compile
-      C->print_inlining_stream()->print("Did not generate predicate for intrinsic %s%s at bci:%d in",
-                                        vmIntrinsics::name_at(intrinsic_id()),
-                                        (is_virtual() ? " (virtual)" : ""), bci);
+    }
+  } else {
+    // Root compile
+    ResourceMark rm;
+    stringStream msg_stream;
+    msg_stream.print("Did not generate intrinsic %s%s at bci:%d in",
+                     vmIntrinsics::name_at(intrinsic_id()),
+                     is_virtual() ? " (virtual)" : "", bci);
+    const char *msg = msg_stream.as_string();
+    log_debug(jit, inlining)("%s", msg);
+    if (C->print_intrinsics() || C->print_inlining()) {
+      C->print_inlining_stream()->print("%s", msg);
     }
   }
   C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed);
--- a/hotspot/src/share/vm/opto/mulnode.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/opto/mulnode.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -630,23 +630,43 @@
 }
 
 //=============================================================================
+
+static int getShiftCon(PhaseGVN *phase, Node *shiftNode, int retVal) {
+  const Type *t = phase->type(shiftNode->in(2));
+  if (t == Type::TOP) return retVal;       // Right input is dead.
+  const TypeInt *t2 = t->isa_int();
+  if (!t2 || !t2->is_con()) return retVal; // Right input is a constant.
+
+  return t2->get_con();
+}
+
+static int maskShiftAmount(PhaseGVN *phase, Node *shiftNode, int nBits) {
+  int       shift = getShiftCon(phase, shiftNode, 0);
+  int maskedShift = shift & (nBits - 1);
+
+  if (maskedShift == 0) return 0;         // Let Identity() handle 0 shift count.
+
+  if (shift != maskedShift) {
+    shiftNode->set_req(2, phase->intcon(maskedShift)); // Replace shift count with masked value.
+    phase->igvn_rehash_node_delayed(shiftNode);
+  }
+
+  return maskedShift;
+}
+
 //------------------------------Identity---------------------------------------
 Node* LShiftINode::Identity(PhaseGVN* phase) {
-  const TypeInt *ti = phase->type( in(2) )->isa_int();  // shift count is an int
-  return ( ti && ti->is_con() && ( ti->get_con() & ( BitsPerInt - 1 ) ) == 0 ) ? in(1) : this;
+  return ((getShiftCon(phase, this, -1) & (BitsPerJavaInteger - 1)) == 0) ? in(1) : this;
 }
 
 //------------------------------Ideal------------------------------------------
 // If the right input is a constant, and the left input is an add of a
 // constant, flatten the tree: (X+con1)<<con0 ==> X<<con0 + con1<<con0
 Node *LShiftINode::Ideal(PhaseGVN *phase, bool can_reshape) {
-  const Type *t  = phase->type( in(2) );
-  if( t == Type::TOP ) return NULL;       // Right input is dead
-  const TypeInt *t2 = t->isa_int();
-  if( !t2 || !t2->is_con() ) return NULL; // Right input is a constant
-  const int con = t2->get_con() & ( BitsPerInt - 1 );  // masked shift count
-
-  if ( con == 0 )  return NULL; // let Identity() handle 0 shift count
+  int con = maskShiftAmount(phase, this, BitsPerJavaInteger);
+  if (con == 0) {
+    return NULL;
+  }
 
   // Left input is an add of a constant?
   Node *add1 = in(1);
@@ -744,21 +764,17 @@
 //=============================================================================
 //------------------------------Identity---------------------------------------
 Node* LShiftLNode::Identity(PhaseGVN* phase) {
-  const TypeInt *ti = phase->type( in(2) )->isa_int(); // shift count is an int
-  return ( ti && ti->is_con() && ( ti->get_con() & ( BitsPerLong - 1 ) ) == 0 ) ? in(1) : this;
+  return ((getShiftCon(phase, this, -1) & (BitsPerJavaLong - 1)) == 0) ? in(1) : this;
 }
 
 //------------------------------Ideal------------------------------------------
 // If the right input is a constant, and the left input is an add of a
 // constant, flatten the tree: (X+con1)<<con0 ==> X<<con0 + con1<<con0
 Node *LShiftLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
-  const Type *t  = phase->type( in(2) );
-  if( t == Type::TOP ) return NULL;       // Right input is dead
-  const TypeInt *t2 = t->isa_int();
-  if( !t2 || !t2->is_con() ) return NULL; // Right input is a constant
-  const int con = t2->get_con() & ( BitsPerLong - 1 );  // masked shift count
-
-  if ( con == 0 ) return NULL;  // let Identity() handle 0 shift count
+  int con = maskShiftAmount(phase, this, BitsPerJavaLong);
+  if (con == 0) {
+    return NULL;
+  }
 
   // Left input is an add of a constant?
   Node *add1 = in(1);
@@ -853,26 +869,24 @@
 //=============================================================================
 //------------------------------Identity---------------------------------------
 Node* RShiftINode::Identity(PhaseGVN* phase) {
-  const TypeInt *t2 = phase->type(in(2))->isa_int();
-  if( !t2 ) return this;
-  if ( t2->is_con() && ( t2->get_con() & ( BitsPerInt - 1 ) ) == 0 )
-    return in(1);
+  int shift = getShiftCon(phase, this, -1);
+  if (shift == -1) return this;
+  if ((shift & (BitsPerJavaInteger - 1)) == 0) return in(1);
 
   // Check for useless sign-masking
-  if( in(1)->Opcode() == Op_LShiftI &&
+  if (in(1)->Opcode() == Op_LShiftI &&
       in(1)->req() == 3 &&
-      in(1)->in(2) == in(2) &&
-      t2->is_con() ) {
-    uint shift = t2->get_con();
+      in(1)->in(2) == in(2)) {
     shift &= BitsPerJavaInteger-1; // semantics of Java shifts
     // Compute masks for which this shifting doesn't change
-    int lo = (-1 << (BitsPerJavaInteger - shift-1)); // FFFF8000
+    int lo = (-1 << (BitsPerJavaInteger - ((uint)shift)-1)); // FFFF8000
     int hi = ~lo;               // 00007FFF
     const TypeInt *t11 = phase->type(in(1)->in(1))->isa_int();
-    if( !t11 ) return this;
+    if (!t11) return this;
     // Does actual value fit inside of mask?
-    if( lo <= t11->_lo && t11->_hi <= hi )
+    if (lo <= t11->_lo && t11->_hi <= hi) {
       return in(1)->in(1);      // Then shifting is a nop
+    }
   }
 
   return this;
@@ -881,15 +895,13 @@
 //------------------------------Ideal------------------------------------------
 Node *RShiftINode::Ideal(PhaseGVN *phase, bool can_reshape) {
   // Inputs may be TOP if they are dead.
-  const TypeInt *t1 = phase->type( in(1) )->isa_int();
-  if( !t1 ) return NULL;        // Left input is an integer
-  const TypeInt *t2 = phase->type( in(2) )->isa_int();
-  if( !t2 || !t2->is_con() ) return NULL; // Right input is a constant
+  const TypeInt *t1 = phase->type(in(1))->isa_int();
+  if (!t1) return NULL;        // Left input is an integer
   const TypeInt *t3;  // type of in(1).in(2)
-  int shift = t2->get_con();
-  shift &= BitsPerJavaInteger-1;  // semantics of Java shifts
-
-  if ( shift == 0 ) return NULL;  // let Identity() handle 0 shift count
+  int shift = maskShiftAmount(phase, this, BitsPerJavaInteger);
+  if (shift == 0) {
+    return NULL;
+  }
 
   // Check for (x & 0xFF000000) >> 24, whose mask can be made smaller.
   // Such expressions arise normally from shift chains like (byte)(x >> 24).
@@ -1003,8 +1015,8 @@
 //=============================================================================
 //------------------------------Identity---------------------------------------
 Node* RShiftLNode::Identity(PhaseGVN* phase) {
-  const TypeInt *ti = phase->type( in(2) )->isa_int(); // shift count is an int
-  return ( ti && ti->is_con() && ( ti->get_con() & ( BitsPerLong - 1 ) ) == 0 ) ? in(1) : this;
+  const TypeInt *ti = phase->type(in(2))->isa_int(); // Shift count is an int.
+  return (ti && ti->is_con() && (ti->get_con() & (BitsPerJavaLong - 1)) == 0) ? in(1) : this;
 }
 
 //------------------------------Value------------------------------------------
@@ -1061,25 +1073,25 @@
 //=============================================================================
 //------------------------------Identity---------------------------------------
 Node* URShiftINode::Identity(PhaseGVN* phase) {
-  const TypeInt *ti = phase->type( in(2) )->isa_int();
-  if ( ti && ti->is_con() && ( ti->get_con() & ( BitsPerInt - 1 ) ) == 0 ) return in(1);
+  int shift = getShiftCon(phase, this, -1);
+  if ((shift & (BitsPerJavaInteger - 1)) == 0) return in(1);
 
   // Check for "((x << LogBytesPerWord) + (wordSize-1)) >> LogBytesPerWord" which is just "x".
   // Happens during new-array length computation.
   // Safe if 'x' is in the range [0..(max_int>>LogBytesPerWord)]
   Node *add = in(1);
-  if( add->Opcode() == Op_AddI ) {
-    const TypeInt *t2  = phase->type(add->in(2))->isa_int();
-    if( t2 && t2->is_con(wordSize - 1) &&
-        add->in(1)->Opcode() == Op_LShiftI ) {
-      // Check that shift_counts are LogBytesPerWord
+  if (add->Opcode() == Op_AddI) {
+    const TypeInt *t2 = phase->type(add->in(2))->isa_int();
+    if (t2 && t2->is_con(wordSize - 1) &&
+        add->in(1)->Opcode() == Op_LShiftI) {
+      // Check that shift_counts are LogBytesPerWord.
       Node          *lshift_count   = add->in(1)->in(2);
       const TypeInt *t_lshift_count = phase->type(lshift_count)->isa_int();
-      if( t_lshift_count && t_lshift_count->is_con(LogBytesPerWord) &&
-          t_lshift_count == phase->type(in(2)) ) {
+      if (t_lshift_count && t_lshift_count->is_con(LogBytesPerWord) &&
+          t_lshift_count == phase->type(in(2))) {
         Node          *x   = add->in(1)->in(1);
         const TypeInt *t_x = phase->type(x)->isa_int();
-        if( t_x != NULL && 0 <= t_x->_lo && t_x->_hi <= (max_jint>>LogBytesPerWord) ) {
+        if (t_x != NULL && 0 <= t_x->_lo && t_x->_hi <= (max_jint>>LogBytesPerWord)) {
           return x;
         }
       }
@@ -1091,10 +1103,11 @@
 
 //------------------------------Ideal------------------------------------------
 Node *URShiftINode::Ideal(PhaseGVN *phase, bool can_reshape) {
-  const TypeInt *t2 = phase->type( in(2) )->isa_int();
-  if( !t2 || !t2->is_con() ) return NULL; // Right input is a constant
-  const int con = t2->get_con() & 31; // Shift count is always masked
-  if ( con == 0 ) return NULL;  // let Identity() handle a 0 shift count
+  int con = maskShiftAmount(phase, this, BitsPerJavaInteger);
+  if (con == 0) {
+    return NULL;
+  }
+
   // We'll be wanting the right-shift amount as a mask of that many bits
   const int mask = right_n_bits(BitsPerJavaInteger - con);
 
@@ -1117,7 +1130,8 @@
   // If Q is "X << z" the rounding is useless.  Look for patterns like
   // ((X<<Z) + Y) >>> Z  and replace with (X + Y>>>Z) & Z-mask.
   Node *add = in(1);
-  if( in1_op == Op_AddI ) {
+  const TypeInt *t2 = phase->type(in(2))->isa_int();
+  if (in1_op == Op_AddI) {
     Node *lshl = add->in(1);
     if( lshl->Opcode() == Op_LShiftI &&
         phase->type(lshl->in(2)) == t2 ) {
@@ -1231,17 +1245,16 @@
 //=============================================================================
 //------------------------------Identity---------------------------------------
 Node* URShiftLNode::Identity(PhaseGVN* phase) {
-  const TypeInt *ti = phase->type( in(2) )->isa_int(); // shift count is an int
-  return ( ti && ti->is_con() && ( ti->get_con() & ( BitsPerLong - 1 ) ) == 0 ) ? in(1) : this;
+  return ((getShiftCon(phase, this, -1) & (BitsPerJavaLong - 1)) == 0) ? in(1) : this;
 }
 
 //------------------------------Ideal------------------------------------------
 Node *URShiftLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
-  const TypeInt *t2 = phase->type( in(2) )->isa_int();
-  if( !t2 || !t2->is_con() ) return NULL; // Right input is a constant
-  const int con = t2->get_con() & ( BitsPerLong - 1 ); // Shift count is always masked
-  if ( con == 0 ) return NULL;  // let Identity() handle a 0 shift count
-                              // note: mask computation below does not work for 0 shift count
+  int con = maskShiftAmount(phase, this, BitsPerJavaLong);
+  if (con == 0) {
+    return NULL;
+  }
+
   // We'll be wanting the right-shift amount as a mask of that many bits
   const jlong mask = jlong(max_julong >> con);
 
@@ -1250,7 +1263,8 @@
   // If Q is "X << z" the rounding is useless.  Look for patterns like
   // ((X<<Z) + Y) >>> Z  and replace with (X + Y>>>Z) & Z-mask.
   Node *add = in(1);
-  if( add->Opcode() == Op_AddL ) {
+  const TypeInt *t2 = phase->type(in(2))->isa_int();
+  if (add->Opcode() == Op_AddL) {
     Node *lshl = add->in(1);
     if( lshl->Opcode() == Op_LShiftL &&
         phase->type(lshl->in(2)) == t2 ) {
--- a/hotspot/src/share/vm/prims/jni.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jni.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2012 Red Hat, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -386,8 +386,8 @@
   Handle loader;
   Handle protection_domain;
   // Find calling class
-  instanceKlassHandle k (THREAD, thread->security_get_caller_class(0));
-  if (k.not_null()) {
+  Klass* k = thread->security_get_caller_class(0);
+  if (k != NULL) {
     loader = Handle(THREAD, k->class_loader());
     // Special handling to make sure JNI_OnLoad and JNI_OnUnload are executed
     // in the correct class context.
@@ -395,9 +395,9 @@
         k->name() == vmSymbols::java_lang_ClassLoader_NativeLibrary()) {
       JavaValue result(T_OBJECT);
       JavaCalls::call_static(&result, k,
-                                      vmSymbols::getFromClass_name(),
-                                      vmSymbols::void_class_signature(),
-                                      thread);
+                             vmSymbols::getFromClass_name(),
+                             vmSymbols::void_class_signature(),
+                             thread);
       if (HAS_PENDING_EXCEPTION) {
         Handle ex(thread, thread->pending_exception());
         CLEAR_PENDING_EXCEPTION;
@@ -455,12 +455,11 @@
     mirror = java_lang_reflect_Method::clazz(reflected);
     slot   = java_lang_reflect_Method::slot(reflected);
   }
-  Klass* k     = java_lang_Class::as_Klass(mirror);
-
-  KlassHandle k1(THREAD, k);
+  Klass* k1 = java_lang_Class::as_Klass(mirror);
+
   // Make sure class is initialized before handing id's out to methods
-  k1()->initialize(CHECK_NULL);
-  Method* m = InstanceKlass::cast(k1())->method_with_idnum(slot);
+  k1->initialize(CHECK_NULL);
+  Method* m = InstanceKlass::cast(k1)->method_with_idnum(slot);
   ret = m==NULL? NULL : m->jmethod_id();  // return NULL if reflected method deleted
   return ret;
 JNI_END
@@ -479,18 +478,17 @@
   // field is a handle to a java.lang.reflect.Field object
   oop reflected   = JNIHandles::resolve_non_null(field);
   oop mirror      = java_lang_reflect_Field::clazz(reflected);
-  Klass* k      = java_lang_Class::as_Klass(mirror);
+  Klass* k1       = java_lang_Class::as_Klass(mirror);
   int slot        = java_lang_reflect_Field::slot(reflected);
   int modifiers   = java_lang_reflect_Field::modifiers(reflected);
 
-  KlassHandle k1(THREAD, k);
   // Make sure class is initialized before handing id's out to fields
-  k1()->initialize(CHECK_NULL);
+  k1->initialize(CHECK_NULL);
 
   // First check if this is a static field
   if (modifiers & JVM_ACC_STATIC) {
-    intptr_t offset = InstanceKlass::cast(k1())->field_offset( slot );
-    JNIid* id = InstanceKlass::cast(k1())->jni_id_for(offset);
+    intptr_t offset = InstanceKlass::cast(k1)->field_offset( slot );
+    JNIid* id = InstanceKlass::cast(k1)->jni_id_for(offset);
     assert(id != NULL, "corrupt Field object");
     debug_only(id->set_is_static_field_id();)
     // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
@@ -501,9 +499,9 @@
   // The slot is the index of the field description in the field-array
   // The jfieldID is the offset of the field within the object
   // It may also have hash bits for k, if VerifyJNIFields is turned on.
-  intptr_t offset = InstanceKlass::cast(k1())->field_offset( slot );
-  assert(InstanceKlass::cast(k1())->contains_field_offset(offset), "stay within object");
-  ret = jfieldIDWorkaround::to_instance_jfieldID(k1(), offset);
+  intptr_t offset = InstanceKlass::cast(k1)->field_offset( slot );
+  assert(InstanceKlass::cast(k1)->contains_field_offset(offset), "stay within object");
+  ret = jfieldIDWorkaround::to_instance_jfieldID(k1, offset);
   return ret;
 JNI_END
 
@@ -677,8 +675,7 @@
         JavaValue result(T_VOID);
         JavaCalls::call_virtual(&result,
                                 ex,
-                                KlassHandle(THREAD,
-                                  SystemDictionary::Throwable_klass()),
+                                SystemDictionary::Throwable_klass(),
                                 vmSymbols::printStackTrace_name(),
                                 vmSymbols::void_method_signature(),
                                 THREAD);
@@ -1156,11 +1153,9 @@
       }
     } else {
       // interface call
-      KlassHandle h_holder(THREAD, holder);
-
       int itbl_index = m->itable_index();
       Klass* k = h_recv->klass();
-      selected_method = InstanceKlass::cast(k)->method_at_itable(h_holder(), itbl_index, CHECK);
+      selected_method = InstanceKlass::cast(k)->method_at_itable(holder, itbl_index, CHECK);
     }
   }
 
@@ -1192,14 +1187,14 @@
 
 
 static instanceOop alloc_object(jclass clazz, TRAPS) {
-  KlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
+  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
   if (k == NULL) {
     ResourceMark rm(THREAD);
     THROW_(vmSymbols::java_lang_InstantiationException(), NULL);
   }
-  k()->check_valid_for_instantiation(false, CHECK_NULL);
-  InstanceKlass::cast(k())->initialize(CHECK_NULL);
-  instanceOop ih = InstanceKlass::cast(k())->allocate_instance(THREAD);
+  k->check_valid_for_instantiation(false, CHECK_NULL);
+  k->initialize(CHECK_NULL);
+  instanceOop ih = InstanceKlass::cast(k)->allocate_instance(THREAD);
   return ih;
 }
 
@@ -1338,26 +1333,25 @@
     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str);
   }
 
-  KlassHandle klass(THREAD,
-               java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
+  Klass* klass = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
 
   // Make sure class is linked and initialized before handing id's out to
   // Method*s.
-  klass()->initialize(CHECK_NULL);
+  klass->initialize(CHECK_NULL);
 
   Method* m;
   if (name == vmSymbols::object_initializer_name() ||
       name == vmSymbols::class_initializer_name()) {
     // Never search superclasses for constructors
     if (klass->is_instance_klass()) {
-      m = InstanceKlass::cast(klass())->find_method(name, signature);
+      m = InstanceKlass::cast(klass)->find_method(name, signature);
     } else {
       m = NULL;
     }
   } else {
     m = klass->lookup_method(name, signature);
     if (m == NULL &&  klass->is_instance_klass()) {
-      m = InstanceKlass::cast(klass())->lookup_method_in_ordered_interfaces(name, signature);
+      m = InstanceKlass::cast(klass)->lookup_method_in_ordered_interfaces(name, signature);
     }
   }
   if (m == NULL || (m->is_static() != is_static)) {
@@ -1879,8 +1873,8 @@
   JavaValue jvalue(Tag); \
   JNI_ArgumentPusherVaArg ap(methodID, args); \
   /* Make sure class is initialized before trying to invoke its method */ \
-  KlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls))); \
-  k()->initialize(CHECK_0); \
+  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); \
+  k->initialize(CHECK_0); \
   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
   va_end(args); \
   ret = jvalue.get_##ResultType(); \
@@ -2037,20 +2031,19 @@
   if (fieldname == NULL || signame == NULL) {
     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
   }
-  KlassHandle k(THREAD,
-                java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
+  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
   // Make sure class is initialized before handing id's out to fields
-  k()->initialize(CHECK_NULL);
+  k->initialize(CHECK_NULL);
 
   fieldDescriptor fd;
-  if (!k()->is_instance_klass() ||
-      !InstanceKlass::cast(k())->find_field(fieldname, signame, false, &fd)) {
+  if (!k->is_instance_klass() ||
+      !InstanceKlass::cast(k)->find_field(fieldname, signame, false, &fd)) {
     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
   }
 
   // A jfieldID for a non-static field is simply the offset of the field within the instanceOop
   // It may also have hash bits for k, if VerifyJNIFields is turned on.
-  ret = jfieldIDWorkaround::to_instance_jfieldID(k(), fd.offset());
+  ret = jfieldIDWorkaround::to_instance_jfieldID(k, fd.offset());
   return ret;
 JNI_END
 
@@ -2292,14 +2285,13 @@
   if (fieldname == NULL || signame == NULL) {
     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
   }
-  KlassHandle k(THREAD,
-                java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
+  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
   // Make sure class is initialized before handing id's out to static fields
-  k()->initialize(CHECK_NULL);
+  k->initialize(CHECK_NULL);
 
   fieldDescriptor fd;
-  if (!k()->is_instance_klass() ||
-      !InstanceKlass::cast(k())->find_field(fieldname, signame, true, &fd)) {
+  if (!k->is_instance_klass() ||
+      !InstanceKlass::cast(k)->find_field(fieldname, signame, true, &fd)) {
     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
   }
 
@@ -2603,11 +2595,10 @@
  HOTSPOT_JNI_NEWOBJECTARRAY_ENTRY(env, length, elementClass, initialElement);
   jobjectArray ret = NULL;
   DT_RETURN_MARK(NewObjectArray, jobjectArray, (const jobjectArray&)ret);
-  KlassHandle ek(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(elementClass)));
-  Klass* ako = ek()->array_klass(CHECK_NULL);
-  KlassHandle ak = KlassHandle(THREAD, ako);
-  ObjArrayKlass::cast(ak())->initialize(CHECK_NULL);
-  objArrayOop result = ObjArrayKlass::cast(ak())->allocate(length, CHECK_NULL);
+  Klass* ek = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(elementClass));
+  Klass* ak = ek->array_klass(CHECK_NULL);
+  ObjArrayKlass::cast(ak)->initialize(CHECK_NULL);
+  objArrayOop result = ObjArrayKlass::cast(ak)->allocate(length, CHECK_NULL);
   oop initial_value = JNIHandles::resolve(initialElement);
   if (initial_value != NULL) {  // array already initialized with NULL
     for (int index = 0; index < length; index++) {
@@ -2936,8 +2927,7 @@
 // is not native.  Ask JVM TI what prefixes have been specified.  Then check
 // to see if the native method is now wrapped with the prefixes.  See the
 // SetNativeMethodPrefix(es) functions in the JVM TI Spec for details.
-static Method* find_prefixed_native(KlassHandle k,
-                                      Symbol* name, Symbol* signature, TRAPS) {
+static Method* find_prefixed_native(Klass* k, Symbol* name, Symbol* signature, TRAPS) {
 #if INCLUDE_JVMTI
   ResourceMark rm(THREAD);
   Method* method;
@@ -2958,7 +2948,7 @@
     if (trial_name == NULL) {
       continue; // no such symbol, so this prefix wasn't used, try the next prefix
     }
-    method = k()->lookup_method(trial_name, signature);
+    method = k->lookup_method(trial_name, signature);
     if (method == NULL) {
       continue; // signature doesn't match, try the next prefix
     }
@@ -2974,13 +2964,13 @@
   return NULL; // not found
 }
 
-static bool register_native(KlassHandle k, Symbol* name, Symbol* signature, address entry, TRAPS) {
-  Method* method = k()->lookup_method(name, signature);
+static bool register_native(Klass* k, Symbol* name, Symbol* signature, address entry, TRAPS) {
+  Method* method = k->lookup_method(name, signature);
   if (method == NULL) {
     ResourceMark rm;
     stringStream st;
     st.print("Method %s name or signature does not match",
-             Method::name_and_sig_as_C_string(k(), name, signature));
+             Method::name_and_sig_as_C_string(k, name, signature));
     THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
   }
   if (!method->is_native()) {
@@ -2990,7 +2980,7 @@
       ResourceMark rm;
       stringStream st;
       st.print("Method %s is not declared as native",
-               Method::name_and_sig_as_C_string(k(), name, signature));
+               Method::name_and_sig_as_C_string(k, name, signature));
       THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
     }
   }
@@ -3021,7 +3011,7 @@
   jint ret = 0;
   DT_RETURN_MARK(RegisterNatives, jint, (const jint&)ret);
 
-  KlassHandle h_k(thread, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
+  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
 
   for (int index = 0; index < nMethods; index++) {
     const char* meth_name = methods[index].name;
@@ -3037,12 +3027,12 @@
     if (name == NULL || signature == NULL) {
       ResourceMark rm;
       stringStream st;
-      st.print("Method %s.%s%s not found", h_k()->external_name(), meth_name, meth_sig);
+      st.print("Method %s.%s%s not found", k->external_name(), meth_name, meth_sig);
       // Must return negative value on failure
       THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), -1);
     }
 
-    bool res = register_native(h_k, name, signature,
+    bool res = register_native(k, name, signature,
                                (address) methods[index].fnPtr, THREAD);
     if (!res) {
       ret = -1;
--- a/hotspot/src/share/vm/prims/jvm.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvm.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -341,7 +341,7 @@
   Handle value_str  = java_lang_String::create_from_platform_dependent_str((value != NULL ? value : ""), CHECK);
   JavaCalls::call_virtual(&r,
                           props,
-                          KlassHandle(THREAD, SystemDictionary::Properties_klass()),
+                          SystemDictionary::Properties_klass(),
                           vmSymbols::put_name(),
                           vmSymbols::object_object_object_signature(),
                           key_str,
@@ -549,9 +549,9 @@
     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers", NULL);
   }
 
-  Handle result = StackWalk::walk(stackStream_h, mode, skip_frames, frame_count,
-                                  start_index, frames_array_h, CHECK_NULL);
-  return JNIHandles::make_local(env, result());
+  oop result = StackWalk::walk(stackStream_h, mode, skip_frames, frame_count,
+                               start_index, frames_array_h, CHECK_NULL);
+  return JNIHandles::make_local(env, result);
 JVM_END
 
 
@@ -621,7 +621,7 @@
 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
   JVMWrapper("JVM_Clone");
   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
-  const KlassHandle klass (THREAD, obj->klass());
+  Klass* klass = obj->klass();
   JvmtiVMObjectAllocEventCollector oam;
 
 #ifdef ASSERT
@@ -684,7 +684,7 @@
       // This can safepoint and redefine method, so need both new_obj and method
       // in a handle, for two different reasons.  new_obj can move, method can be
       // deleted if nothing is using it on the stack.
-      m->method_holder()->add_member_name(new_obj(), false);
+      m->method_holder()->add_member_name(new_obj, false);
     }
   }
 
@@ -997,9 +997,7 @@
   if (k == NULL) {
     // If the class is not already loaded, try to see if it's in the shared
     // archive for the current classloader (h_loader).
-    instanceKlassHandle ik = SystemDictionaryShared::find_or_load_shared_class(
-        klass_name, h_loader, CHECK_NULL);
-    k = ik();
+    k = SystemDictionaryShared::find_or_load_shared_class(klass_name, h_loader, CHECK_NULL);
   }
 #endif
   return (k == NULL) ? NULL :
@@ -1077,11 +1075,11 @@
     return (jobjectArray) JNIHandles::make_local(env, r);
   }
 
-  KlassHandle klass(thread, java_lang_Class::as_Klass(mirror));
+  Klass* klass = java_lang_Class::as_Klass(mirror);
   // Figure size of result array
   int size;
   if (klass->is_instance_klass()) {
-    size = InstanceKlass::cast(klass())->local_interfaces()->length();
+    size = InstanceKlass::cast(klass)->local_interfaces()->length();
   } else {
     assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
     size = 2;
@@ -1094,7 +1092,7 @@
   if (klass->is_instance_klass()) {
     // Regular instance klass, fill in all local interfaces
     for (int index = 0; index < size; index++) {
-      Klass* k = InstanceKlass::cast(klass())->local_interfaces()->at(index);
+      Klass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);
       result->obj_at_put(index, k->java_mirror());
     }
   } else {
@@ -1178,7 +1176,7 @@
 JVM_END
 
 
-static bool is_authorized(Handle context, instanceKlassHandle klass, TRAPS) {
+static bool is_authorized(Handle context, InstanceKlass* klass, TRAPS) {
   // If there is a security manager and protection domain, check the access
   // in the protection domain, otherwise it is authorized.
   if (java_lang_System::has_security_manager()) {
@@ -1218,7 +1216,7 @@
   Handle obj = pd_klass->allocate_instance_handle(CHECK_NULL);
   // Call constructor ProtectionDomain(null, null);
   JavaValue result(T_VOID);
-  JavaCalls::call_special(&result, obj, KlassHandle(THREAD, pd_klass),
+  JavaCalls::call_special(&result, obj, pd_klass,
                           vmSymbols::object_initializer_name(),
                           vmSymbols::codesource_permissioncollection_signature(),
                           Handle(), Handle(), CHECK_NULL);
@@ -1249,7 +1247,7 @@
   }
 
   Method* method        = vfst.method();
-  instanceKlassHandle klass (THREAD, method->method_holder());
+  InstanceKlass* klass  = method->method_holder();
 
   // Check that action object understands "Object run()"
   Handle h_context;
@@ -1452,7 +1450,7 @@
     return (jobjectArray)JNIHandles::make_local(env, result);
   }
 
-  instanceKlassHandle k(thread, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
+  InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
   InnerClassesIterator iter(k);
 
   if (iter.length() == 0) {
@@ -1479,9 +1477,9 @@
       // before attempting to find the class.
       if (cp->klass_name_at_matches(k, ooff)) {
         Klass* outer_klass = cp->klass_at(ooff, CHECK_NULL);
-        if (outer_klass == k()) {
+        if (outer_klass == k) {
            Klass* ik = cp->klass_at(ioff, CHECK_NULL);
-           instanceKlassHandle inner_klass (THREAD, ik);
+           InstanceKlass* inner_klass = InstanceKlass::cast(ik);
 
            // Throws an exception if outer klass has not declared k as
            // an inner klass
@@ -1532,7 +1530,7 @@
       !java_lang_Class::as_Klass(mirror)->is_instance_klass()) {
     return NULL;
   }
-  instanceKlassHandle k(THREAD, InstanceKlass::cast(java_lang_Class::as_Klass(mirror)));
+  InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
   int ooff = 0, noff = 0;
   if (InstanceKlass::find_inner_classes_attr(k, &ooff, &noff, THREAD)) {
     if (noff != 0) {
@@ -1590,19 +1588,19 @@
   int slot      = java_lang_reflect_Field::slot(reflected);
   int modifiers = java_lang_reflect_Field::modifiers(reflected);
 
-  KlassHandle kh(THREAD, k);
-  intptr_t offset = InstanceKlass::cast(kh())->field_offset(slot);
+  InstanceKlass* ik = InstanceKlass::cast(k);
+  intptr_t offset = ik->field_offset(slot);
 
   if (modifiers & JVM_ACC_STATIC) {
     // for static fields we only look in the current class
-    if (!InstanceKlass::cast(kh())->find_local_field_from_offset(offset, true, &fd)) {
+    if (!ik->find_local_field_from_offset(offset, true, &fd)) {
       assert(false, "cannot find static field");
       return false;
     }
   } else {
     // for instance fields we start with the current class and work
     // our way up through the superclass chain
-    if (!InstanceKlass::cast(kh())->find_field_from_offset(offset, false, &fd)) {
+    if (!ik->find_field_from_offset(offset, false, &fd)) {
       assert(false, "cannot find instance field");
       return false;
     }
@@ -1757,7 +1755,7 @@
     return (jobjectArray) JNIHandles::make_local(env, res);
   }
 
-  instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
+  InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
   constantPoolHandle cp(THREAD, k->constants());
 
   // Ensure class is linked
@@ -1768,7 +1766,7 @@
 
   if (publicOnly) {
     num_fields = 0;
-    for (JavaFieldStream fs(k()); !fs.done(); fs.next()) {
+    for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
       if (fs.access_flags().is_public()) ++num_fields;
     }
   } else {
@@ -1782,7 +1780,7 @@
   fieldDescriptor fd;
   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
     if (!publicOnly || fs.access_flags().is_public()) {
-      fd.reinitialize(k(), fs.index());
+      fd.reinitialize(k, fs.index());
       oop field = Reflection::new_field(&fd, CHECK_NULL);
       result->obj_at_put(out_idx, field);
       ++out_idx;
@@ -1817,7 +1815,7 @@
     return (jobjectArray) JNIHandles::make_local(env, res);
   }
 
-  instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
+  InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
 
   // Ensure class is linked
   k->link_class(CHECK_NULL);
@@ -1913,7 +1911,7 @@
   if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
     Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
     if (k->is_instance_klass()) {
-      instanceKlassHandle k_h(THREAD, k);
+      InstanceKlass* k_h = InstanceKlass::cast(k);
       Handle jcp = reflect_ConstantPool::create(CHECK_NULL);
       reflect_ConstantPool::set_cp(jcp(), k_h->constants());
       return JNIHandles::make_local(jcp());
@@ -1975,7 +1973,7 @@
     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
     if (k_o == NULL) return NULL;
   }
-  instanceKlassHandle k(THREAD, k_o);
+  InstanceKlass* k = InstanceKlass::cast(k_o);
   Symbol* name = cp->uncached_name_ref_at(index);
   Symbol* sig  = cp->uncached_signature_ref_at(index);
   methodHandle m (THREAD, k->find_method(name, sig));
@@ -2026,7 +2024,7 @@
     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
     if (k_o == NULL) return NULL;
   }
-  instanceKlassHandle k(THREAD, k_o);
+  InstanceKlass* k = InstanceKlass::cast(k_o);
   Symbol* name = cp->uncached_name_ref_at(index);
   Symbol* sig  = cp->uncached_signature_ref_at(index);
   fieldDescriptor fd;
@@ -2616,7 +2614,8 @@
     case JVM_CONSTANT_Fieldref: {
       Symbol* name      = cp->uncached_name_ref_at(cp_index);
       Symbol* signature = cp->uncached_signature_ref_at(cp_index);
-      for (JavaFieldStream fs(k_called); !fs.done(); fs.next()) {
+      InstanceKlass* ik = InstanceKlass::cast(k_called);
+      for (JavaFieldStream fs(ik); !fs.done(); fs.next()) {
         if (fs.name() == name && fs.signature() == signature) {
           return fs.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS;
         }
@@ -2770,7 +2769,7 @@
   JavaValue result(T_VOID);
   JavaCalls::call_virtual(&result,
                           obj,
-                          KlassHandle(THREAD, SystemDictionary::Thread_klass()),
+                          SystemDictionary::Thread_klass(),
                           vmSymbols::run_method_name(),
                           vmSymbols::void_method_signature(),
                           THREAD);
@@ -3226,7 +3225,7 @@
   }
 
   // Collect method holders
-  GrowableArray<KlassHandle>* klass_array = new GrowableArray<KlassHandle>();
+  GrowableArray<Klass*>* klass_array = new GrowableArray<Klass*>();
   for (; !vfst.at_end(); vfst.security_next()) {
     Method* m = vfst.method();
     // Native frames are not returned
@@ -3593,12 +3592,11 @@
   //   if there is no security manager in 3-arg Class.forName().
   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
 
-  KlassHandle klass_handle(THREAD, klass);
   // Check if we should initialize the class
-  if (init && klass_handle->is_instance_klass()) {
-    klass_handle->initialize(CHECK_NULL);
+  if (init && klass->is_instance_klass()) {
+    klass->initialize(CHECK_NULL);
   }
-  return (jclass) JNIHandles::make_local(env, klass_handle->java_mirror());
+  return (jclass) JNIHandles::make_local(env, klass->java_mirror());
 }
 
 
@@ -3746,25 +3744,25 @@
   if (!k->is_instance_klass()) {
     return NULL;
   }
-  instanceKlassHandle ik_h(THREAD, k);
-  int encl_method_class_idx = ik_h->enclosing_method_class_index();
+  InstanceKlass* ik = InstanceKlass::cast(k);
+  int encl_method_class_idx = ik->enclosing_method_class_index();
   if (encl_method_class_idx == 0) {
     return NULL;
   }
   objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::Object_klass(), 3, CHECK_NULL);
   objArrayHandle dest(THREAD, dest_o);
-  Klass* enc_k = ik_h->constants()->klass_at(encl_method_class_idx, CHECK_NULL);
+  Klass* enc_k = ik->constants()->klass_at(encl_method_class_idx, CHECK_NULL);
   dest->obj_at_put(0, enc_k->java_mirror());
-  int encl_method_method_idx = ik_h->enclosing_method_method_index();
+  int encl_method_method_idx = ik->enclosing_method_method_index();
   if (encl_method_method_idx != 0) {
-    Symbol* sym = ik_h->constants()->symbol_at(
+    Symbol* sym = ik->constants()->symbol_at(
                         extract_low_short_from_int(
-                          ik_h->constants()->name_and_type_at(encl_method_method_idx)));
+                          ik->constants()->name_and_type_at(encl_method_method_idx)));
     Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
     dest->obj_at_put(1, str());
-    sym = ik_h->constants()->symbol_at(
+    sym = ik->constants()->symbol_at(
               extract_high_short_from_int(
-                ik_h->constants()->name_and_type_at(encl_method_method_idx)));
+                ik->constants()->name_and_type_at(encl_method_method_idx)));
     str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
     dest->obj_at_put(2, str());
   }
@@ -3799,8 +3797,8 @@
   int num_flags = Arguments::num_jvm_flags();
   int num_args = Arguments::num_jvm_args();
 
-  instanceKlassHandle ik (THREAD, SystemDictionary::String_klass());
-  objArrayOop r = oopFactory::new_objArray(ik(), num_args + num_flags, CHECK_NULL);
+  InstanceKlass* ik = SystemDictionary::String_klass();
+  objArrayOop r = oopFactory::new_objArray(ik, num_args + num_flags, CHECK_NULL);
   objArrayHandle result_h(THREAD, r);
 
   int index = 0;
--- a/hotspot/src/share/vm/prims/jvmtiClassFileReconstituter.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiClassFileReconstituter.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,20 +40,20 @@
 // JVMSpec|     field_info fields[fields_count];
 void JvmtiClassFileReconstituter::write_field_infos() {
   HandleMark hm(thread());
-  Array<AnnotationArray*>* fields_anno = ikh()->fields_annotations();
-  Array<AnnotationArray*>* fields_type_anno = ikh()->fields_type_annotations();
+  Array<AnnotationArray*>* fields_anno = ik()->fields_annotations();
+  Array<AnnotationArray*>* fields_type_anno = ik()->fields_type_annotations();
 
   // Compute the real number of Java fields
-  int java_fields = ikh()->java_fields_count();
+  int java_fields = ik()->java_fields_count();
 
   write_u2(java_fields);
-  for (JavaFieldStream fs(ikh()); !fs.done(); fs.next()) {
+  for (JavaFieldStream fs(ik()); !fs.done(); fs.next()) {
     AccessFlags access_flags = fs.access_flags();
     int name_index = fs.name_index();
     int signature_index = fs.signature_index();
     int initial_value_index = fs.initval_index();
     guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field");
-    // int offset = ikh()->field_offset( index );
+    // int offset = ik()->field_offset( index );
     int generic_signature_index = fs.generic_signature_index();
     AnnotationArray* anno = fields_anno == NULL ? NULL : fields_anno->at(fs.index());
     AnnotationArray* type_anno = fields_type_anno == NULL ? NULL : fields_type_anno->at(fs.index());
@@ -278,11 +278,11 @@
 // JVMSpec|     u2 sourcefile_index;
 // JVMSpec|   }
 void JvmtiClassFileReconstituter::write_source_file_attribute() {
-  assert(ikh()->source_file_name() != NULL, "caller must check");
+  assert(ik()->source_file_name() != NULL, "caller must check");
 
   write_attribute_name_index("SourceFile");
   write_u4(2);  // always length 2
-  write_u2(symbol_to_cpool_index(ikh()->source_file_name()));
+  write_u2(symbol_to_cpool_index(ik()->source_file_name()));
 }
 
 // Write SourceDebugExtension attribute
@@ -292,12 +292,12 @@
 // JSR45|       u1 debug_extension[attribute_length];
 // JSR45|   }
 void JvmtiClassFileReconstituter::write_source_debug_extension_attribute() {
-  assert(ikh()->source_debug_extension() != NULL, "caller must check");
+  assert(ik()->source_debug_extension() != NULL, "caller must check");
 
   write_attribute_name_index("SourceDebugExtension");
-  int len = (int)strlen(ikh()->source_debug_extension());
+  int len = (int)strlen(ik()->source_debug_extension());
   write_u4(len);
-  u1* ext = (u1*)ikh()->source_debug_extension();
+  u1* ext = (u1*)ik()->source_debug_extension();
   for (int i=0; i<len; i++) {
     write_u1(ext[i]);
   }
@@ -317,7 +317,7 @@
 
 // Compute the number of entries in the InnerClasses attribute
 u2 JvmtiClassFileReconstituter::inner_classes_attribute_length() {
-  InnerClassesIterator iter(ikh());
+  InnerClassesIterator iter(ik());
   return iter.length();
 }
 
@@ -387,7 +387,7 @@
 // JVMSpec|     } classes[number_of_classes];
 // JVMSpec|   }
 void JvmtiClassFileReconstituter::write_inner_classes_attribute(int length) {
-  InnerClassesIterator iter(ikh());
+  InnerClassesIterator iter(ik());
   guarantee(iter.length() != 0 && iter.length() == length,
             "caller must check");
   u2 entry_count = length / InstanceKlass::inner_class_next_offset;
@@ -618,18 +618,18 @@
 // JVMSpec|     attribute_info attributes[attributes_count];
 void JvmtiClassFileReconstituter::write_class_attributes() {
   u2 inner_classes_length = inner_classes_attribute_length();
-  Symbol* generic_signature = ikh()->generic_signature();
-  AnnotationArray* anno = ikh()->class_annotations();
-  AnnotationArray* type_anno = ikh()->class_type_annotations();
+  Symbol* generic_signature = ik()->generic_signature();
+  AnnotationArray* anno = ik()->class_annotations();
+  AnnotationArray* type_anno = ik()->class_type_annotations();
 
   int attr_count = 0;
   if (generic_signature != NULL) {
     ++attr_count;
   }
-  if (ikh()->source_file_name() != NULL) {
+  if (ik()->source_file_name() != NULL) {
     ++attr_count;
   }
-  if (ikh()->source_debug_extension() != NULL) {
+  if (ik()->source_debug_extension() != NULL) {
     ++attr_count;
   }
   if (inner_classes_length > 0) {
@@ -650,10 +650,10 @@
   if (generic_signature != NULL) {
     write_signature_attribute(symbol_to_cpool_index(generic_signature));
   }
-  if (ikh()->source_file_name() != NULL) {
+  if (ik()->source_file_name() != NULL) {
     write_source_file_attribute();
   }
-  if (ikh()->source_debug_extension() != NULL) {
+  if (ik()->source_debug_extension() != NULL) {
     write_source_debug_extension_attribute();
   }
   if (inner_classes_length > 0) {
@@ -675,7 +675,7 @@
 // JVMSpec|     method_info methods[methods_count];
 void JvmtiClassFileReconstituter::write_method_infos() {
   HandleMark hm(thread());
-  Array<Method*>* methods = ikh()->methods();
+  Array<Method*>* methods = ik()->methods();
   int num_methods = methods->length();
   int num_overpass = 0;
 
@@ -697,7 +697,7 @@
 
     // invert the method order mapping
     for (index = 0; index < num_methods; index++) {
-      original_index = ikh()->method_ordering()->at(index);
+      original_index = ik()->method_ordering()->at(index);
       assert(original_index >= 0 && original_index < num_methods,
              "invalid original method index");
       method_order.at_put(original_index, index);
@@ -727,8 +727,8 @@
 
   // JVMSpec|           u2 minor_version;
   // JVMSpec|           u2 major_version;
-  write_u2(ikh()->minor_version());
-  u2 major = ikh()->major_version();
+  write_u2(ik()->minor_version());
+  u2 major = ik()->major_version();
   write_u2(major);
 
   // JVMSpec|           u2 constant_pool_count;
@@ -737,24 +737,24 @@
   copy_cpool_bytes(writeable_address(cpool_size()));
 
   // JVMSpec|           u2 access_flags;
-  write_u2(ikh()->access_flags().get_flags() & JVM_RECOGNIZED_CLASS_MODIFIERS);
+  write_u2(ik()->access_flags().get_flags() & JVM_RECOGNIZED_CLASS_MODIFIERS);
 
   // JVMSpec|           u2 this_class;
   // JVMSpec|           u2 super_class;
-  write_u2(class_symbol_to_cpool_index(ikh()->name()));
-  Klass* super_class = ikh()->super();
+  write_u2(class_symbol_to_cpool_index(ik()->name()));
+  Klass* super_class = ik()->super();
   write_u2(super_class == NULL? 0 :  // zero for java.lang.Object
                 class_symbol_to_cpool_index(super_class->name()));
 
   // JVMSpec|           u2 interfaces_count;
   // JVMSpec|           u2 interfaces[interfaces_count];
-  Array<Klass*>* interfaces =  ikh()->local_interfaces();
+  Array<Klass*>* interfaces =  ik()->local_interfaces();
   int num_interfaces = interfaces->length();
   write_u2(num_interfaces);
   for (int index = 0; index < num_interfaces; index++) {
     HandleMark hm(thread());
-    instanceKlassHandle iikh(thread(), interfaces->at(index));
-    write_u2(class_symbol_to_cpool_index(iikh->name()));
+    InstanceKlass* iik = InstanceKlass::cast(interfaces->at(index));
+    write_u2(class_symbol_to_cpool_index(iik->name()));
   }
 
   // JVMSpec|           u2 fields_count;
--- a/hotspot/src/share/vm/prims/jvmtiClassFileReconstituter.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiClassFileReconstituter.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,11 +34,11 @@
   SymbolHashMap*       _symmap;
   SymbolHashMap*       _classmap;
   constantPoolHandle   _cpool;
-  instanceKlassHandle  _ikh;
+  InstanceKlass*       _ik;
   jvmtiError           _err;
 
  protected:
-  instanceKlassHandle  ikh()     { return _ikh; };
+  InstanceKlass*  ik()           { return _ik; };
   constantPoolHandle   cpool()   { return _cpool; };
 
   u2 symbol_to_cpool_index(Symbol* sym) {
@@ -52,10 +52,10 @@
  public:
   // Calls to this constructor must be proceeded by a ResourceMark
   // and a HandleMark
-  JvmtiConstantPoolReconstituter(instanceKlassHandle ikh){
+  JvmtiConstantPoolReconstituter(InstanceKlass* ik){
     set_error(JVMTI_ERROR_NONE);
-    _ikh = ikh;
-    _cpool = constantPoolHandle(Thread::current(), ikh->constants());
+    _ik = ik;
+    _cpool = constantPoolHandle(Thread::current(), ik->constants());
     _symmap = new SymbolHashMap();
     _classmap = new SymbolHashMap();
     _cpool_size = _cpool->hash_entries_to(_symmap, _classmap);
@@ -138,8 +138,8 @@
  public:
   // Calls to this constructor must be proceeded by a ResourceMark
   // and a HandleMark
-  JvmtiClassFileReconstituter(instanceKlassHandle ikh) :
-                                      JvmtiConstantPoolReconstituter(ikh) {
+  JvmtiClassFileReconstituter(InstanceKlass* ik) :
+                                      JvmtiConstantPoolReconstituter(ik) {
     _buffer_size = initial_buffer_size;
     _buffer = _buffer_ptr = NEW_RESOURCE_ARRAY(u1, _buffer_size);
     _thread = Thread::current();
--- a/hotspot/src/share/vm/prims/jvmtiEnv.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiEnv.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -400,21 +400,20 @@
       return JVMTI_ERROR_UNMODIFIABLE_CLASS;
     }
 
-    Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
-    KlassHandle klass(current_thread, k_oop);
+    Klass* klass = java_lang_Class::as_Klass(k_mirror);
 
     jint status = klass->jvmti_class_status();
     if (status & (JVMTI_CLASS_STATUS_ERROR)) {
       return JVMTI_ERROR_INVALID_CLASS;
     }
 
-    instanceKlassHandle ikh(current_thread, k_oop);
-    if (ikh->get_cached_class_file_bytes() == NULL) {
+    InstanceKlass* ik = InstanceKlass::cast(klass);
+    if (ik->get_cached_class_file_bytes() == NULL) {
       // Not cached, we need to reconstitute the class file from the
       // VM representation. We don't attach the reconstituted class
       // bytes to the InstanceKlass here because they have not been
       // validated and we're not at a safepoint.
-      JvmtiClassFileReconstituter reconstituter(ikh);
+      JvmtiClassFileReconstituter reconstituter(ik);
       if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
         return reconstituter.get_error();
       }
@@ -424,8 +423,8 @@
                                                        reconstituter.class_file_bytes();
     } else {
       // it is cached, get it from the cache
-      class_definitions[index].class_byte_count = ikh->get_cached_class_file_len();
-      class_definitions[index].class_bytes      = ikh->get_cached_class_file_bytes();
+      class_definitions[index].class_byte_count = ik->get_cached_class_file_len();
+      class_definitions[index].class_bytes      = ik->get_cached_class_file_bytes();
     }
     class_definitions[index].klass              = jcls;
   }
@@ -667,8 +666,6 @@
       return JVMTI_ERROR_INTERNAL;
     }
 
-    instanceKlassHandle loader_ik(THREAD, loader->klass());
-
     // Invoke the appendToClassPathForInstrumentation method - if the method
     // is not found it means the loader doesn't support adding to the class path
     // in the live phase.
@@ -676,7 +673,7 @@
       JavaValue res(T_VOID);
       JavaCalls::call_special(&res,
                               loader,
-                              loader_ik,
+                              loader->klass(),
                               vmSymbols::appendToClassPathForInstrumentation_name(),
                               vmSymbols::appendToClassPathForInstrumentation_signature(),
                               path,
@@ -1781,7 +1778,7 @@
 jvmtiError
 JvmtiEnv::FollowReferences(jint heap_filter, jclass klass, jobject initial_object, const jvmtiHeapCallbacks* callbacks, const void* user_data) {
   // check klass if provided
-  Klass* k_oop = NULL;
+  Klass* k = NULL;
   if (klass != NULL) {
     oop k_mirror = JNIHandles::resolve_external_guard(klass);
     if (k_mirror == NULL) {
@@ -1790,18 +1787,17 @@
     if (java_lang_Class::is_primitive(k_mirror)) {
       return JVMTI_ERROR_NONE;
     }
-    k_oop = java_lang_Class::as_Klass(k_mirror);
-    if (k_oop == NULL) {
+    k = java_lang_Class::as_Klass(k_mirror);
+    if (klass == NULL) {
       return JVMTI_ERROR_INVALID_CLASS;
     }
   }
 
   Thread *thread = Thread::current();
   HandleMark hm(thread);
-  KlassHandle kh (thread, k_oop);
 
   TraceTime t("FollowReferences", TRACETIME_LOG(Debug, jvmti, objecttagging));
-  JvmtiTagMap::tag_map_for(this)->follow_references(heap_filter, kh, initial_object, callbacks, user_data);
+  JvmtiTagMap::tag_map_for(this)->follow_references(heap_filter, k, initial_object, callbacks, user_data);
   return JVMTI_ERROR_NONE;
 } /* end FollowReferences */
 
@@ -1812,7 +1808,7 @@
 jvmtiError
 JvmtiEnv::IterateThroughHeap(jint heap_filter, jclass klass, const jvmtiHeapCallbacks* callbacks, const void* user_data) {
   // check klass if provided
-  Klass* k_oop = NULL;
+  Klass* k = NULL;
   if (klass != NULL) {
     oop k_mirror = JNIHandles::resolve_external_guard(klass);
     if (k_mirror == NULL) {
@@ -1821,18 +1817,14 @@
     if (java_lang_Class::is_primitive(k_mirror)) {
       return JVMTI_ERROR_NONE;
     }
-    k_oop = java_lang_Class::as_Klass(k_mirror);
-    if (k_oop == NULL) {
+    k = java_lang_Class::as_Klass(k_mirror);
+    if (k == NULL) {
       return JVMTI_ERROR_INVALID_CLASS;
     }
   }
 
-  Thread *thread = Thread::current();
-  HandleMark hm(thread);
-  KlassHandle kh (thread, k_oop);
-
   TraceTime t("IterateThroughHeap", TRACETIME_LOG(Debug, jvmti, objecttagging));
-  JvmtiTagMap::tag_map_for(this)->iterate_through_heap(heap_filter, kh, callbacks, user_data);
+  JvmtiTagMap::tag_map_for(this)->iterate_through_heap(heap_filter, k, callbacks, user_data);
   return JVMTI_ERROR_NONE;
 } /* end IterateThroughHeap */
 
@@ -1909,7 +1901,7 @@
   TraceTime t("IterateOverHeap", TRACETIME_LOG(Debug, jvmti, objecttagging));
   Thread *thread = Thread::current();
   HandleMark hm(thread);
-  JvmtiTagMap::tag_map_for(this)->iterate_over_heap(object_filter, KlassHandle(), heap_object_callback, user_data);
+  JvmtiTagMap::tag_map_for(this)->iterate_over_heap(object_filter, NULL, heap_object_callback, user_data);
   return JVMTI_ERROR_NONE;
 } /* end IterateOverHeap */
 
@@ -1923,13 +1915,10 @@
     // DO PRIMITIVE CLASS PROCESSING
     return JVMTI_ERROR_NONE;
   }
-  Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
-  if (k_oop == NULL) {
+  Klass* klass = java_lang_Class::as_Klass(k_mirror);
+  if (klass == NULL) {
     return JVMTI_ERROR_INVALID_CLASS;
   }
-  Thread *thread = Thread::current();
-  HandleMark hm(thread);
-  KlassHandle klass (thread, k_oop);
   TraceTime t("IterateOverInstancesOfClass", TRACETIME_LOG(Debug, jvmti, objecttagging));
   JvmtiTagMap::tag_map_for(this)->iterate_over_heap(object_filter, klass, heap_object_callback, user_data);
   return JVMTI_ERROR_NONE;
@@ -2408,9 +2397,9 @@
     *methods_ptr = (jmethodID*) jvmtiMalloc(0 * sizeof(jmethodID));
     return JVMTI_ERROR_NONE;
   }
-  instanceKlassHandle instanceK_h(current_thread, k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
   // Allocate the result and fill it in
-  int result_length = instanceK_h->methods()->length();
+  int result_length = ik->methods()->length();
   jmethodID* result_list = (jmethodID*)jvmtiMalloc(result_length * sizeof(jmethodID));
   int index;
   bool jmethodids_found = true;
@@ -2419,8 +2408,8 @@
     // Use the original method ordering indices stored in the class, so we can emit
     // jmethodIDs in the order they appeared in the class file
     for (index = 0; index < result_length; index++) {
-      Method* m = instanceK_h->methods()->at(index);
-      int original_index = instanceK_h->method_ordering()->at(index);
+      Method* m = ik->methods()->at(index);
+      int original_index = ik->method_ordering()->at(index);
       assert(original_index >= 0 && original_index < result_length, "invalid original method index");
       jmethodID id;
       if (jmethodids_found) {
@@ -2429,7 +2418,7 @@
           // If we find an uninitialized value, make sure there is
           // enough space for all the uninitialized values we might
           // find.
-          instanceK_h->ensure_space_for_methodids(index);
+          ik->ensure_space_for_methodids(index);
           jmethodids_found = false;
           id = m->jmethod_id();
         }
@@ -2441,7 +2430,7 @@
   } else {
     // otherwise just copy in any order
     for (index = 0; index < result_length; index++) {
-      Method* m = instanceK_h->methods()->at(index);
+      Method* m = ik->methods()->at(index);
       jmethodID id;
       if (jmethodids_found) {
         id = m->find_jmethod_id_or_null();
@@ -2449,7 +2438,7 @@
           // If we find an uninitialized value, make sure there is
           // enough space for all the uninitialized values we might
           // find.
-          instanceK_h->ensure_space_for_methodids(index);
+          ik->ensure_space_for_methodids(index);
           jmethodids_found = false;
           id = m->jmethod_id();
         }
@@ -2494,11 +2483,11 @@
   }
 
 
-  instanceKlassHandle instanceK_h(current_thread, k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
 
   int result_count = 0;
   // First, count the fields.
-  FilteredFieldStream flds(instanceK_h, true, true);
+  FilteredFieldStream flds(ik, true, true);
   result_count = flds.field_count();
 
   // Allocate the result and fill it in
@@ -2507,9 +2496,9 @@
   // this is the reverse order of what FieldStream hands out.
   int id_index = (result_count - 1);
 
-  for (FilteredFieldStream src_st(instanceK_h, true, true); !src_st.eos(); src_st.next()) {
+  for (FilteredFieldStream src_st(ik, true, true); !src_st.eos(); src_st.next()) {
     result_list[id_index--] = jfieldIDWorkaround::to_jfieldID(
-                                            instanceK_h, src_st.offset(),
+                                            ik, src_st.offset(),
                                             src_st.access_flags().is_static());
   }
   assert(id_index == -1, "just checking");
@@ -2574,10 +2563,7 @@
   if (java_lang_Class::is_primitive(k_mirror)) {
     return JVMTI_ERROR_ABSENT_INFORMATION;
   }
-  Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
-  Thread *thread = Thread::current();
-  HandleMark hm(thread);
-  KlassHandle klass(thread, k_oop);
+  Klass* klass = java_lang_Class::as_Klass(k_mirror);
 
   jint status = klass->jvmti_class_status();
   if (status & (JVMTI_CLASS_STATUS_ERROR)) {
@@ -2587,7 +2573,7 @@
     return JVMTI_ERROR_ABSENT_INFORMATION;
   }
 
-  instanceKlassHandle ik(thread, k_oop);
+  InstanceKlass* ik = InstanceKlass::cast(klass);
   *minor_version_ptr = ik->minor_version();
   *major_version_ptr = ik->major_version();
 
@@ -2605,11 +2591,9 @@
     return JVMTI_ERROR_ABSENT_INFORMATION;
   }
 
-  Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
+  Klass* klass = java_lang_Class::as_Klass(k_mirror);
   Thread *thread = Thread::current();
-  HandleMark hm(thread);
   ResourceMark rm(thread);
-  KlassHandle klass(thread, k_oop);
 
   jint status = klass->jvmti_class_status();
   if (status & (JVMTI_CLASS_STATUS_ERROR)) {
@@ -2619,8 +2603,8 @@
     return JVMTI_ERROR_ABSENT_INFORMATION;
   }
 
-  instanceKlassHandle ikh(thread, k_oop);
-  JvmtiConstantPoolReconstituter reconstituter(ikh);
+  InstanceKlass* ik = InstanceKlass::cast(klass);
+  JvmtiConstantPoolReconstituter reconstituter(ik);
   if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
     return reconstituter.get_error();
   }
@@ -2639,7 +2623,7 @@
     return reconstituter.get_error();
   }
 
-  constantPoolHandle  constants(thread, ikh->constants());
+  constantPoolHandle  constants(thread, ik->constants());
   *constant_pool_count_ptr      = constants->length();
   *constant_pool_byte_count_ptr = cpool_size;
   *constant_pool_bytes_ptr      = cpool_bytes;
--- a/hotspot/src/share/vm/prims/jvmtiEnvBase.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiEnvBase.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -598,7 +598,8 @@
 jclass
 JvmtiEnvBase::get_jni_class_non_null(Klass* k) {
   assert(k != NULL, "k != NULL");
-  return (jclass)jni_reference(k->java_mirror());
+  Thread *thread = Thread::current();
+  return (jclass)jni_reference(Handle(thread, k->java_mirror()));
 }
 
 //
@@ -693,7 +694,7 @@
     *monitor_ptr = NULL;
   } else {
     HandleMark hm;
-    Handle     hobj(obj);
+    Handle     hobj(Thread::current(), obj);
     *monitor_ptr = jni_reference(calling_thread, hobj);
   }
   return JVMTI_ERROR_NONE;
@@ -813,7 +814,7 @@
     if (err != JVMTI_ERROR_NONE) {
         return err;
     }
-    Handle hobj(obj);
+    Handle hobj(Thread::current(), obj);
     jmsdi->monitor = jni_reference(calling_thread, hobj);
     jmsdi->stack_depth = stack_depth;
     owned_monitors_list->append(jmsdi);
@@ -953,6 +954,7 @@
   HandleMark hm;
   Handle hobj;
 
+  Thread* current_thread = Thread::current();
   bool at_safepoint = SafepointSynchronize::is_at_safepoint();
 
   // Check arguments
@@ -961,7 +963,7 @@
     NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
     NULL_CHECK(info_ptr, JVMTI_ERROR_NULL_POINTER);
 
-    hobj = Handle(mirror);
+    hobj = Handle(current_thread, mirror);
   }
 
   JavaThread *owning_thread = NULL;
@@ -1027,7 +1029,7 @@
           return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
         }
         HandleMark hm;
-        Handle     th(owning_thread->threadObj());
+        Handle     th(current_thread, owning_thread->threadObj());
         ret.owner = (jthread)jni_reference(calling_thread, th);
       }
       // implied else: no owner
@@ -1110,7 +1112,7 @@
             deallocate((unsigned char*)ret.notify_waiters);
             return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
           }
-          Handle th(pending_thread->threadObj());
+          Handle th(current_thread, pending_thread->threadObj());
           ret.waiters[i] = (jthread)jni_reference(calling_thread, th);
         }
       }
@@ -1130,7 +1132,7 @@
             // If the thread was found on the ObjectWaiter list, then
             // it has not been notified. This thread can't change the
             // state of the monitor so it doesn't need to be suspended.
-            Handle th(wjava_thread->threadObj());
+            Handle th(current_thread, wjava_thread->threadObj());
             ret.waiters[offset + j] = (jthread)jni_reference(calling_thread, th);
             ret.notify_waiters[j++] = (jthread)jni_reference(calling_thread, th);
           }
@@ -1362,15 +1364,15 @@
   // Check that the jobject class matches the return type signature.
   jobject jobj = value.l;
   if (tos == atos && jobj != NULL) { // NULL reference is allowed
-    Handle ob_h = Handle(current_thread, JNIHandles::resolve_external_guard(jobj));
+    Handle ob_h(current_thread, JNIHandles::resolve_external_guard(jobj));
     NULL_CHECK(ob_h, JVMTI_ERROR_INVALID_OBJECT);
-    KlassHandle ob_kh = KlassHandle(current_thread, ob_h()->klass());
-    NULL_CHECK(ob_kh, JVMTI_ERROR_INVALID_OBJECT);
+    Klass* ob_k = ob_h()->klass();
+    NULL_CHECK(ob_k, JVMTI_ERROR_INVALID_OBJECT);
 
     // Method return type signature.
     char* ty_sign = 1 + strchr(signature->as_C_string(), ')');
 
-    if (!VM_GetOrSetLocal::is_assignable(ty_sign, ob_kh(), current_thread)) {
+    if (!VM_GetOrSetLocal::is_assignable(ty_sign, ob_k, current_thread)) {
       return JVMTI_ERROR_TYPE_MISMATCH;
     }
     *ret_ob_h = ob_h;
@@ -1425,7 +1427,7 @@
       return JVMTI_ERROR_OPAQUE_FRAME;
     }
   }
-  Handle ret_ob_h = Handle();
+  Handle ret_ob_h;
   jvmtiError err = check_top_frame(current_thread, java_thread, value, tos, &ret_ob_h);
   if (err != JVMTI_ERROR_NONE) {
     return err;
@@ -1479,7 +1481,7 @@
         _error = err;
         return;
       }
-      Handle hobj(obj);
+      Handle hobj(Thread::current(), obj);
       jmsdi->monitor = _env->jni_reference(_calling_thread, hobj);
       // stack depth is unknown for this monitor.
       jmsdi->stack_depth = -1;
--- a/hotspot/src/share/vm/prims/jvmtiExport.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiExport.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -267,14 +267,14 @@
 
 public:
   JvmtiClassFileLoadEventMark(JavaThread *thread, Symbol* name,
-     Handle class_loader, Handle prot_domain, KlassHandle *class_being_redefined) : JvmtiThreadEventMark(thread) {
+     Handle class_loader, Handle prot_domain, Klass* class_being_redefined) : JvmtiThreadEventMark(thread) {
       _class_name = name != NULL? name->as_utf8() : NULL;
       _jloader = (jobject)to_jobject(class_loader());
       _protection_domain = (jobject)to_jobject(prot_domain());
       if (class_being_redefined == NULL) {
         _class_being_redefined = NULL;
       } else {
-        _class_being_redefined = (jclass)to_jclass((*class_being_redefined)());
+        _class_being_redefined = (jclass)to_jclass(class_being_redefined);
       }
   };
   const char *class_name() {
@@ -735,7 +735,7 @@
   JvmtiEnv *           _curr_env;
   JvmtiCachedClassFileData ** _cached_class_file_ptr;
   JvmtiThreadState *   _state;
-  KlassHandle *        _h_class_being_redefined;
+  Klass*               _class_being_redefined;
   JvmtiClassLoadKind   _load_kind;
   bool                 _has_been_modified;
 
@@ -758,9 +758,9 @@
 
     _state = _thread->jvmti_thread_state();
     if (_state != NULL) {
-      _h_class_being_redefined = _state->get_class_being_redefined();
+      _class_being_redefined = _state->get_class_being_redefined();
       _load_kind = _state->get_class_load_kind();
-      Klass* klass = (_h_class_being_redefined == NULL) ? NULL : (*_h_class_being_redefined)();
+      Klass* klass = (_class_being_redefined == NULL) ? NULL : _class_being_redefined;
       if (_load_kind != jvmti_class_load_kind_load && klass != NULL) {
         ModuleEntry* module_entry = InstanceKlass::cast(klass)->module();
         assert(module_entry != NULL, "module_entry should always be set");
@@ -783,7 +783,7 @@
       _state->clear_class_being_redefined();
     } else {
       // redefine and retransform will always set the thread state
-      _h_class_being_redefined = (KlassHandle *) NULL;
+      _class_being_redefined = NULL;
       _load_kind = jvmti_class_load_kind_load;
     }
   }
@@ -828,7 +828,7 @@
     jint new_len = 0;
     JvmtiClassFileLoadEventMark jem(_thread, _h_name, _class_loader,
                                     _h_protection_domain,
-                                    _h_class_being_redefined);
+                                    _class_being_redefined);
     JvmtiJavaThreadEventTransition jet(_thread);
     jvmtiEventClassFileLoadHook callback = env->callbacks()->ClassFileLoadHook;
     if (callback != NULL) {
@@ -1155,7 +1155,6 @@
     return;
   }
   HandleMark hm(thread);
-  KlassHandle kh(thread, klass);
 
   EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_LOAD, ("[%s] Trg Class Load triggered",
                       JvmtiTrace::safe_get_thread_name(thread)));
@@ -1172,8 +1171,8 @@
       }
       EVT_TRACE(JVMTI_EVENT_CLASS_LOAD, ("[%s] Evt Class Load sent %s",
                                          JvmtiTrace::safe_get_thread_name(thread),
-                                         kh()==NULL? "NULL" : kh()->external_name() ));
-      JvmtiClassEventMark jem(thread, kh());
+                                         klass==NULL? "NULL" : klass->external_name() ));
+      JvmtiClassEventMark jem(thread, klass);
       JvmtiJavaThreadEventTransition jet(thread);
       jvmtiEventClassLoad callback = env->callbacks()->ClassLoad;
       if (callback != NULL) {
@@ -1189,7 +1188,6 @@
     return;
   }
   HandleMark hm(thread);
-  KlassHandle kh(thread, klass);
 
   EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("[%s] Trg Class Prepare triggered",
                       JvmtiTrace::safe_get_thread_name(thread)));
@@ -1206,8 +1204,8 @@
       }
       EVT_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("[%s] Evt Class Prepare sent %s",
                                             JvmtiTrace::safe_get_thread_name(thread),
-                                            kh()==NULL? "NULL" : kh()->external_name() ));
-      JvmtiClassEventMark jem(thread, kh());
+                                            klass==NULL? "NULL" : klass->external_name() ));
+      JvmtiClassEventMark jem(thread, klass);
       JvmtiJavaThreadEventTransition jet(thread);
       jvmtiEventClassPrepare callback = env->callbacks()->ClassPrepare;
       if (callback != NULL) {
@@ -1223,7 +1221,6 @@
   }
   Thread *thread = Thread::current();
   HandleMark hm(thread);
-  KlassHandle kh(thread, klass);
 
   EVT_TRIG_TRACE(EXT_EVENT_CLASS_UNLOAD, ("[?] Trg Class Unload triggered" ));
   if (JvmtiEventController::is_enabled((jvmtiEvent)EXT_EVENT_CLASS_UNLOAD)) {
@@ -1244,12 +1241,12 @@
       }
       if (env->is_enabled((jvmtiEvent)EXT_EVENT_CLASS_UNLOAD)) {
         EVT_TRACE(EXT_EVENT_CLASS_UNLOAD, ("[?] Evt Class Unload sent %s",
-                  kh()==NULL? "NULL" : kh()->external_name() ));
+                  klass==NULL? "NULL" : klass->external_name() ));
 
         // do everything manually, since this is a proxy - needs special care
         JNIEnv* jni_env = real_thread->jni_environment();
         jthread jt = (jthread)JNIHandles::make_local(real_thread, real_thread->threadObj());
-        jclass jk = (jclass)JNIHandles::make_local(real_thread, kh()->java_mirror());
+        jclass jk = (jclass)JNIHandles::make_local(real_thread, klass->java_mirror());
 
         // Before we call the JVMTI agent, we have to set the state in the
         // thread for which we are proxying.
@@ -1595,7 +1592,7 @@
           current_bci = st.bci();
           do {
             should_repeat = false;
-            KlassHandle eh_klass(thread, exception_handle()->klass());
+            Klass* eh_klass = exception_handle()->klass();
             current_bci = Method::fast_exception_handler_bci_for(
               current_mh, eh_klass, current_bci, THREAD);
             if (HAS_PENDING_EXCEPTION) {
@@ -1743,7 +1740,6 @@
   if (!fd.is_field_access_watched()) return;
 
   HandleMark hm(thread);
-  KlassHandle h_klass(thread, klass);
   Handle h_obj;
   if (!is_static) {
     // non-static field accessors have an object, but we need a handle
@@ -1753,11 +1749,11 @@
   post_field_access(thread,
                     thread->last_frame().interpreter_frame_method(),
                     thread->last_frame().interpreter_frame_bcp(),
-                    h_klass, h_obj, fieldID);
+                    klass, h_obj, fieldID);
 }
 
 void JvmtiExport::post_field_access(JavaThread *thread, Method* method,
-  address location, KlassHandle field_klass, Handle object, jfieldID field) {
+  address location, Klass* field_klass, Handle object, jfieldID field) {
 
   HandleMark hm(thread);
   methodHandle mh(thread, method);
@@ -1779,7 +1775,7 @@
 
       JvmtiEnv *env = ets->get_env();
       JvmtiLocationEventMark jem(thread, mh, location);
-      jclass field_jclass = jem.to_jclass(field_klass());
+      jclass field_jclass = jem.to_jclass(field_klass);
       jobject field_jobject = jem.to_jobject(object());
       JvmtiJavaThreadEventTransition jet(thread);
       jvmtiEventFieldAccess callback = env->callbacks()->FieldAccess;
@@ -1847,22 +1843,21 @@
     assert(obj != NULL, "non-static needs an object");
     h_obj = Handle(thread, obj);
   }
-  KlassHandle h_klass(thread, klass);
   post_field_modification(thread,
                           thread->last_frame().interpreter_frame_method(),
                           thread->last_frame().interpreter_frame_bcp(),
-                          h_klass, h_obj, fieldID, sig_type, value);
+                          klass, h_obj, fieldID, sig_type, value);
 }
 
 void JvmtiExport::post_raw_field_modification(JavaThread *thread, Method* method,
-  address location, KlassHandle field_klass, Handle object, jfieldID field,
+  address location, Klass* field_klass, Handle object, jfieldID field,
   char sig_type, jvalue *value) {
 
   if (sig_type == 'I' || sig_type == 'Z' || sig_type == 'B' || sig_type == 'C' || sig_type == 'S') {
     // 'I' instructions are used for byte, char, short and int.
     // determine which it really is, and convert
     fieldDescriptor fd;
-    bool found = JvmtiEnv::get_field_descriptor(field_klass(), field, &fd);
+    bool found = JvmtiEnv::get_field_descriptor(field_klass, field, &fd);
     // should be found (if not, leave as is)
     if (found) {
       jint ival = value->i;
@@ -1917,7 +1912,7 @@
 }
 
 void JvmtiExport::post_field_modification(JavaThread *thread, Method* method,
-  address location, KlassHandle field_klass, Handle object, jfieldID field,
+  address location, Klass* field_klass, Handle object, jfieldID field,
   char sig_type, jvalue *value_ptr) {
 
   HandleMark hm(thread);
@@ -1943,7 +1938,7 @@
 
       JvmtiEnv *env = ets->get_env();
       JvmtiLocationEventMark jem(thread, mh, location);
-      jclass field_jclass = jem.to_jclass(field_klass());
+      jclass field_jclass = jem.to_jclass(field_klass);
       jobject field_jobject = jem.to_jobject(object());
       JvmtiJavaThreadEventTransition jet(thread);
       jvmtiEventFieldModification callback = env->callbacks()->FieldModification;
--- a/hotspot/src/share/vm/prims/jvmtiExport.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiExport.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -150,7 +150,7 @@
   };
 
   static void post_field_modification(JavaThread *thread, Method* method, address location,
-                                      KlassHandle field_klass, Handle object, jfieldID field,
+                                      Klass* field_klass, Handle object, jfieldID field,
                                       char sig_type, jvalue *value);
 
 
@@ -310,7 +310,7 @@
   static void post_field_access_by_jni   (JavaThread *thread, oop obj,
     Klass* klass, jfieldID fieldID, bool is_static) NOT_JVMTI_RETURN;
   static void post_field_access          (JavaThread *thread, Method* method,
-    address location, KlassHandle field_klass, Handle object, jfieldID field) NOT_JVMTI_RETURN;
+    address location, Klass* field_klass, Handle object, jfieldID field) NOT_JVMTI_RETURN;
   static oop jni_SetField_probe          (JavaThread *thread, jobject jobj,
     oop obj, Klass* klass, jfieldID fieldID, bool is_static, char sig_type,
     jvalue *value) NOT_JVMTI_RETURN_(NULL);
@@ -321,7 +321,7 @@
     Klass* klass, jfieldID fieldID, bool is_static, char sig_type,
     jvalue *value);
   static void post_raw_field_modification(JavaThread *thread, Method* method,
-    address location, KlassHandle field_klass, Handle object, jfieldID field,
+    address location, Klass* field_klass, Handle object, jfieldID field,
     char sig_type, jvalue *value) NOT_JVMTI_RETURN;
 
   static void post_method_entry          (JavaThread *thread, Method* method, frame current_frame) NOT_JVMTI_RETURN;
--- a/hotspot/src/share/vm/prims/jvmtiGetLoadedClasses.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiGetLoadedClasses.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,15 +36,16 @@
 private:
   Stack<jclass, mtInternal> _classStack;
   JvmtiEnv* _env;
+  Thread*   _cur_thread;
 
 public:
-  LoadedClassesClosure(JvmtiEnv* env) {
-    _env = env;
+  LoadedClassesClosure(Thread* thread, JvmtiEnv* env) : _cur_thread(thread), _env(env) {
+    assert(_cur_thread == Thread::current(), "must be current thread");
   }
 
   void do_klass(Klass* k) {
     // Collect all jclasses
-    _classStack.push((jclass) _env->jni_reference(k->java_mirror()));
+    _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, k->java_mirror())));
   }
 
   int extract(jclass* result_list) {
@@ -225,8 +226,9 @@
     if (that->available()) {
       oop class_loader = loader_data->class_loader();
       if (class_loader == JNIHandles::resolve(that->get_initiatingLoader())) {
+        Thread *thread = Thread::current();
         for (Klass* l = k; l != NULL; l = l->array_klass_or_null()) {
-          oop mirror = l->java_mirror();
+          Handle mirror(thread, l->java_mirror());
           that->set_element(that->get_index(), mirror);
           that->set_index(that->get_index() + 1);
         }
@@ -250,8 +252,9 @@
     JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
     assert(that != NULL, "no JvmtiGetLoadedClassesClosure");
     assert(that->available(), "no list");
+    Thread *thread = Thread::current();
     for (Klass* l = k; l != NULL; l = l->array_klass_or_null()) {
-      oop mirror = l->java_mirror();
+      Handle mirror(thread, l->java_mirror());
       that->set_element(that->get_index(), mirror);
       that->set_index(that->get_index() + 1);
     }
@@ -262,7 +265,7 @@
 jvmtiError
 JvmtiGetLoadedClasses::getLoadedClasses(JvmtiEnv *env, jint* classCountPtr, jclass** classesPtr) {
 
-  LoadedClassesClosure closure(env);
+  LoadedClassesClosure closure(Thread::current(), env);
   {
     // To get a consistent list of classes we need MultiArray_lock to ensure
     // array classes aren't created.
--- a/hotspot/src/share/vm/prims/jvmtiImpl.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiImpl.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -287,12 +287,12 @@
 
   // add/remove breakpoint to/from versions of the method that are EMCP.
   Thread *thread = Thread::current();
-  instanceKlassHandle ikh = instanceKlassHandle(thread, _method->method_holder());
+  InstanceKlass* ik = _method->method_holder();
   Symbol* m_name = _method->name();
   Symbol* m_signature = _method->signature();
 
   // search previous versions if they exist
-  for (InstanceKlass* pv_node = ikh->previous_versions();
+  for (InstanceKlass* pv_node = ik->previous_versions();
        pv_node != NULL;
        pv_node = pv_node->previous_versions()) {
     Array<Method*>* methods = pv_node->methods();
@@ -694,12 +694,12 @@
     JavaThread* cur_thread = JavaThread::current();
     HandleMark hm(cur_thread);
 
-    Handle obj = Handle(cur_thread, JNIHandles::resolve_external_guard(jobj));
+    Handle obj(cur_thread, JNIHandles::resolve_external_guard(jobj));
     NULL_CHECK(obj, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
-    KlassHandle ob_kh = KlassHandle(cur_thread, obj->klass());
-    NULL_CHECK(ob_kh, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
+    Klass* ob_k = obj->klass();
+    NULL_CHECK(ob_k, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
 
-    if (!is_assignable(signature, ob_kh(), cur_thread)) {
+    if (!is_assignable(signature, ob_k, cur_thread)) {
       _result = JVMTI_ERROR_TYPE_MISMATCH;
       return false;
     }
@@ -777,7 +777,7 @@
       case T_FLOAT:  locals->set_float_at (_index, _value.f); break;
       case T_DOUBLE: locals->set_double_at(_index, _value.d); break;
       case T_OBJECT: {
-        Handle ob_h(JNIHandles::resolve_external_guard(_value.l));
+        Handle ob_h(Thread::current(), JNIHandles::resolve_external_guard(_value.l));
         locals->set_obj_at (_index, ob_h);
         break;
       }
--- a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -58,7 +58,7 @@
 int         VM_RedefineClasses::_matching_methods_length = 0;
 int         VM_RedefineClasses::_deleted_methods_length  = 0;
 int         VM_RedefineClasses::_added_methods_length    = 0;
-Klass*      VM_RedefineClasses::_the_class_oop = NULL;
+Klass*      VM_RedefineClasses::_the_class = NULL;
 
 
 VM_RedefineClasses::VM_RedefineClasses(jint class_count,
@@ -227,8 +227,8 @@
   // Free os::malloc allocated memory.
   os::free(_scratch_classes);
 
-  // Reset the_class_oop to null for error printing.
-  _the_class_oop = NULL;
+  // Reset the_class to null for error printing.
+  _the_class = NULL;
 
   if (log_is_enabled(Info, redefine, class, timer)) {
     // Used to have separate timers for "doit" and "all", but the timer
@@ -657,8 +657,8 @@
 
 
 jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
-             instanceKlassHandle the_class,
-             instanceKlassHandle scratch_class) {
+             InstanceKlass* the_class,
+             InstanceKlass* scratch_class) {
   int i;
 
   // Check superclasses, or rather their names, since superclasses themselves can be
@@ -993,8 +993,8 @@
 jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
 
   // For consistency allocate memory using os::malloc wrapper.
-  _scratch_classes = (Klass**)
-    os::malloc(sizeof(Klass*) * _class_count, mtClass);
+  _scratch_classes = (InstanceKlass**)
+    os::malloc(sizeof(InstanceKlass*) * _class_count, mtClass);
   if (_scratch_classes == NULL) {
     return JVMTI_ERROR_OUT_OF_MEMORY;
   }
@@ -1014,7 +1014,7 @@
     // versions are deleted. Constant pools are deallocated while merging
     // constant pools
     HandleMark hm(THREAD);
-    instanceKlassHandle the_class(THREAD, get_ik(_class_defs[i].klass));
+    InstanceKlass* the_class = get_ik(_class_defs[i].klass);
     Symbol*  the_class_sym = the_class->name();
 
     log_debug(redefine, class, load)
@@ -1032,24 +1032,23 @@
     // Set redefined class handle in JvmtiThreadState class.
     // This redefined class is sent to agent event handler for class file
     // load hook event.
-    state->set_class_being_redefined(&the_class, _class_load_kind);
-
-    Klass* k = SystemDictionary::parse_stream(the_class_sym,
-                                                the_class_loader,
-                                                protection_domain,
-                                                &st,
-                                                THREAD);
+    state->set_class_being_redefined(the_class, _class_load_kind);
+
+    InstanceKlass* scratch_class = SystemDictionary::parse_stream(
+                                                      the_class_sym,
+                                                      the_class_loader,
+                                                      protection_domain,
+                                                      &st,
+                                                      THREAD);
     // Clear class_being_redefined just to be sure.
     state->clear_class_being_redefined();
 
     // TODO: if this is retransform, and nothing changed we can skip it
 
-    instanceKlassHandle scratch_class (THREAD, k);
-
     // Need to clean up allocated InstanceKlass if there's an error so assign
     // the result here. Caller deallocates all the scratch classes in case of
     // an error.
-    _scratch_classes[i] = k;
+    _scratch_classes[i] = scratch_class;
 
     if (HAS_PENDING_EXCEPTION) {
       Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
@@ -1106,7 +1105,7 @@
       // the_class to scratch_class in the JVM_* functions called by the
       // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
       // description.
-      RedefineVerifyMark rvm(&the_class, &scratch_class, state);
+      RedefineVerifyMark rvm(the_class, scratch_class, state);
       Verifier::verify(
         scratch_class, Verifier::ThrowException, true, THREAD);
     }
@@ -1138,7 +1137,7 @@
     if (VerifyMergedCPBytecodes) {
       // verify what we have done during constant pool merging
       {
-        RedefineVerifyMark rvm(&the_class, &scratch_class, state);
+        RedefineVerifyMark rvm(the_class, scratch_class, state);
         Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
       }
 
@@ -1434,7 +1433,7 @@
 // potentially rewrite bytecodes in scratch_class to use the merged
 // constant pool.
 jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
-             instanceKlassHandle the_class, instanceKlassHandle scratch_class,
+             InstanceKlass* the_class, InstanceKlass* scratch_class,
              TRAPS) {
   // worst case merged constant pool length is old and new combined
   int merge_cp_length = the_class->constants()->length()
@@ -1483,7 +1482,7 @@
   _operands_index_map_p = new intArray(operands_index_map_len, operands_index_map_len, -1);
 
   // reference to the cp holder is needed for copy_operands()
-  merge_cp->set_pool_holder(scratch_class());
+  merge_cp->set_pool_holder(scratch_class);
   bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
                   &merge_cp_length, THREAD);
   merge_cp->set_pool_holder(NULL);
@@ -1568,7 +1567,7 @@
 
 
 // Rewrite constant pool references in klass scratch_class.
-bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
+bool VM_RedefineClasses::rewrite_cp_refs(InstanceKlass* scratch_class,
        TRAPS) {
 
   // rewrite constant pool references in the methods:
@@ -1655,7 +1654,7 @@
 
 // Rewrite constant pool references in the methods.
 bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
-       instanceKlassHandle scratch_class, TRAPS) {
+       InstanceKlass* scratch_class, TRAPS) {
 
   Array<Method*>* methods = scratch_class->methods();
 
@@ -1834,7 +1833,7 @@
 
 // Rewrite constant pool references in the class_annotations field.
 bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
-       instanceKlassHandle scratch_class, TRAPS) {
+       InstanceKlass* scratch_class, TRAPS) {
 
   AnnotationArray* class_annotations = scratch_class->class_annotations();
   if (class_annotations == NULL || class_annotations->length() == 0) {
@@ -2124,7 +2123,7 @@
 
 // Rewrite constant pool references in a fields_annotations field.
 bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
-       instanceKlassHandle scratch_class, TRAPS) {
+       InstanceKlass* scratch_class, TRAPS) {
 
   Array<AnnotationArray*>* fields_annotations = scratch_class->fields_annotations();
 
@@ -2157,7 +2156,7 @@
 
 // Rewrite constant pool references in a methods_annotations field.
 bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
-       instanceKlassHandle scratch_class, TRAPS) {
+       InstanceKlass* scratch_class, TRAPS) {
 
   for (int i = 0; i < scratch_class->methods()->length(); i++) {
     Method* m = scratch_class->methods()->at(i);
@@ -2195,7 +2194,7 @@
 // }
 //
 bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
-       instanceKlassHandle scratch_class, TRAPS) {
+       InstanceKlass* scratch_class, TRAPS) {
 
   for (int i = 0; i < scratch_class->methods()->length(); i++) {
     Method* m = scratch_class->methods()->at(i);
@@ -2244,7 +2243,7 @@
 // }
 //
 bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
-       instanceKlassHandle scratch_class, TRAPS) {
+       InstanceKlass* scratch_class, TRAPS) {
 
   for (int i = 0; i < scratch_class->methods()->length(); i++) {
     Method* m = scratch_class->methods()->at(i);
@@ -2271,7 +2270,7 @@
 
 // Rewrite constant pool references in a class_type_annotations field.
 bool VM_RedefineClasses::rewrite_cp_refs_in_class_type_annotations(
-       instanceKlassHandle scratch_class, TRAPS) {
+       InstanceKlass* scratch_class, TRAPS) {
 
   AnnotationArray* class_type_annotations = scratch_class->class_type_annotations();
   if (class_type_annotations == NULL || class_type_annotations->length() == 0) {
@@ -2289,7 +2288,7 @@
 
 // Rewrite constant pool references in a fields_type_annotations field.
 bool VM_RedefineClasses::rewrite_cp_refs_in_fields_type_annotations(
-       instanceKlassHandle scratch_class, TRAPS) {
+       InstanceKlass* scratch_class, TRAPS) {
 
   Array<AnnotationArray*>* fields_type_annotations = scratch_class->fields_type_annotations();
   if (fields_type_annotations == NULL || fields_type_annotations->length() == 0) {
@@ -2321,7 +2320,7 @@
 
 // Rewrite constant pool references in a methods_type_annotations field.
 bool VM_RedefineClasses::rewrite_cp_refs_in_methods_type_annotations(
-       instanceKlassHandle scratch_class, TRAPS) {
+       InstanceKlass* scratch_class, TRAPS) {
 
   for (int i = 0; i < scratch_class->methods()->length(); i++) {
     Method* m = scratch_class->methods()->at(i);
@@ -3074,7 +3073,7 @@
 // smaller constant pool is associated with scratch_class.
 void VM_RedefineClasses::set_new_constant_pool(
        ClassLoaderData* loader_data,
-       instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
+       InstanceKlass* scratch_class, constantPoolHandle scratch_cp,
        int scratch_cp_length, TRAPS) {
   assert(scratch_cp->length() >= scratch_cp_length, "sanity check");
 
@@ -3091,7 +3090,7 @@
 
   // attach klass to new constant pool
   // reference to the cp holder is needed for copy_operands()
-  smaller_cp->set_pool_holder(scratch_class());
+  smaller_cp->set_pool_holder(scratch_class);
 
   scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
   if (HAS_PENDING_EXCEPTION) {
@@ -3268,11 +3267,11 @@
   // This is a very busy routine. We don't want too much tracing
   // printed out.
   bool trace_name_printed = false;
-  InstanceKlass *the_class = InstanceKlass::cast(_the_class_oop);
+  InstanceKlass *the_class = InstanceKlass::cast(_the_class);
 
   // If the class being redefined is java.lang.Object, we need to fix all
   // array class vtables also
-  if (k->is_array_klass() && _the_class_oop == SystemDictionary::Object_klass()) {
+  if (k->is_array_klass() && _the_class == SystemDictionary::Object_klass()) {
     k->vtable()->adjust_method_entries(the_class, &trace_name_printed);
 
   } else if (k->is_instance_klass()) {
@@ -3291,8 +3290,7 @@
     // If the current class being redefined has a user-defined class
     // loader as its defining class loader, then we can skip all
     // classes loaded by the bootstrap class loader.
-    bool is_user_defined =
-           InstanceKlass::cast(_the_class_oop)->class_loader() != NULL;
+    bool is_user_defined = (_the_class->class_loader() != NULL);
     if (is_user_defined && ik->class_loader() == NULL) {
       return;
     }
@@ -3311,9 +3309,9 @@
     // This must be done after we adjust the default_methods and
     // default_vtable_indices for methods already in the vtable.
     // If redefining Unsafe, walk all the vtables looking for entries.
-    if (ik->vtable_length() > 0 && (_the_class_oop->is_interface()
-        || _the_class_oop == SystemDictionary::internal_Unsafe_klass()
-        || ik->is_subtype_of(_the_class_oop))) {
+    if (ik->vtable_length() > 0 && (_the_class->is_interface()
+        || _the_class == SystemDictionary::internal_Unsafe_klass()
+        || ik->is_subtype_of(_the_class))) {
       // ik->vtable() creates a wrapper object; rm cleans it up
       ResourceMark rm(_thread);
 
@@ -3328,9 +3326,9 @@
     // every InstanceKlass that has an itable since there isn't a
     // subclass relationship between an interface and an InstanceKlass.
     // If redefining Unsafe, walk all the itables looking for entries.
-    if (ik->itable_length() > 0 && (_the_class_oop->is_interface()
-        || _the_class_oop == SystemDictionary::internal_Unsafe_klass()
-        || ik->is_subclass_of(_the_class_oop))) {
+    if (ik->itable_length() > 0 && (_the_class->is_interface()
+        || _the_class == SystemDictionary::internal_Unsafe_klass()
+        || ik->is_subclass_of(_the_class))) {
       // ik->itable() creates a wrapper object; rm cleans it up
       ResourceMark rm(_thread);
 
@@ -3353,7 +3351,7 @@
     constantPoolHandle other_cp;
     ConstantPoolCache* cp_cache;
 
-    if (ik != _the_class_oop) {
+    if (ik != _the_class) {
       // this klass' constant pool cache may need adjustment
       other_cp = constantPoolHandle(ik->constants());
       cp_cache = other_cp->cache();
@@ -3499,7 +3497,7 @@
       // obsolete methods need a unique idnum so they become new entries in
       // the jmethodID cache in InstanceKlass
       assert(old_method->method_idnum() == new_method->method_idnum(), "must match");
-      u2 num = InstanceKlass::cast(_the_class_oop)->next_method_idnum();
+      u2 num = InstanceKlass::cast(_the_class)->next_method_idnum();
       if (num != ConstMethod::UNSET_IDNUM) {
         old_method->set_method_idnum(num);
       }
@@ -3563,7 +3561,7 @@
 //
 class TransferNativeFunctionRegistration {
  private:
-  instanceKlassHandle the_class;
+  InstanceKlass* the_class;
   int prefix_count;
   char** prefixes;
 
@@ -3578,7 +3576,7 @@
                                      Symbol* signature) {
     TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
     if (name_symbol != NULL) {
-      Method* method = the_class()->lookup_method(name_symbol, signature);
+      Method* method = the_class->lookup_method(name_symbol, signature);
       if (method != NULL) {
         // Even if prefixed, intermediate methods must exist.
         if (method->is_native()) {
@@ -3641,7 +3639,7 @@
  public:
 
   // Construct a native method transfer processor for this class.
-  TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
+  TransferNativeFunctionRegistration(InstanceKlass* _the_class) {
     assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
 
     the_class = _the_class;
@@ -3668,7 +3666,7 @@
 };
 
 // Don't lose the association between a native method and its JNI function.
-void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
+void VM_RedefineClasses::transfer_old_native_function_registrations(InstanceKlass* the_class) {
   TransferNativeFunctionRegistration transfer(the_class);
   transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
   transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
@@ -3689,13 +3687,13 @@
 // subsequent calls to RedefineClasses need only throw away code
 // that depends on the class.
 //
-void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
+void VM_RedefineClasses::flush_dependent_code(InstanceKlass* ik, TRAPS) {
   assert_locked_or_safepoint(Compile_lock);
 
   // All dependencies have been recorded from startup or this is a second or
   // subsequent use of RedefineClasses
   if (JvmtiExport::all_dependencies_are_recorded()) {
-    CodeCache::flush_evol_dependents_on(k_h);
+    CodeCache::flush_evol_dependents_on(ik);
   } else {
     CodeCache::mark_all_nmethods_for_deoptimization();
 
@@ -3775,8 +3773,8 @@
 }
 
 
-void VM_RedefineClasses::swap_annotations(instanceKlassHandle the_class,
-                                          instanceKlassHandle scratch_class) {
+void VM_RedefineClasses::swap_annotations(InstanceKlass* the_class,
+                                          InstanceKlass* scratch_class) {
   // Swap annotation fields values
   Annotations* old_annotations = the_class->annotations();
   the_class->set_annotations(scratch_class->annotations());
@@ -3797,7 +3795,7 @@
 //      that we would like to pass to the helper method are saved in
 //      static global fields in the VM operation.
 void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
-       Klass* scratch_class_oop, TRAPS) {
+       InstanceKlass* scratch_class, TRAPS) {
 
   HandleMark hm(THREAD);   // make sure handles from this call are freed
 
@@ -3805,25 +3803,24 @@
     _timer_rsc_phase1.start();
   }
 
-  instanceKlassHandle scratch_class(THREAD, scratch_class_oop);
-  instanceKlassHandle the_class(THREAD, get_ik(the_jclass));
+  InstanceKlass* the_class = get_ik(the_jclass);
 
   // Remove all breakpoints in methods of this class
   JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
-  jvmti_breakpoints.clearall_in_class_at_safepoint(the_class());
+  jvmti_breakpoints.clearall_in_class_at_safepoint(the_class);
 
   // Deoptimize all compiled code that depends on this class
   flush_dependent_code(the_class, THREAD);
 
   _old_methods = the_class->methods();
   _new_methods = scratch_class->methods();
-  _the_class_oop = the_class();
+  _the_class = the_class;
   compute_added_deleted_matching_methods();
   update_jmethod_ids();
 
   // Attach new constant pool to the original klass. The original
   // klass still refers to the old constant pool (for now).
-  scratch_class->constants()->set_pool_holder(the_class());
+  scratch_class->constants()->set_pool_holder(the_class);
 
 #if 0
   // In theory, with constant pool merging in place we should be able
@@ -3853,13 +3850,11 @@
 
   {
     // walk all previous versions of the klass
-    InstanceKlass *ik = (InstanceKlass *)the_class();
+    InstanceKlass *ik = the_class;
     PreviousVersionWalker pvw(ik);
-    instanceKlassHandle ikh;
     do {
-      ikh = pvw.next_previous_version();
-      if (!ikh.is_null()) {
-        ik = ikh();
+      ik = pvw.next_previous_version();
+      if (ik != NULL) {
 
         // attach previous version of klass to the new constant pool
         ik->set_constants(scratch_class->constants());
@@ -3872,7 +3867,7 @@
           method->set_constants(scratch_class->constants());
         }
       }
-    } while (!ikh.is_null());
+    } while (ik != NULL);
   }
 #endif
 
@@ -4041,7 +4036,7 @@
   MemberNameTable* mnt = the_class->member_names();
   if (mnt != NULL) {
     bool trace_name_printed = false;
-    mnt->adjust_method_entries(the_class(), &trace_name_printed);
+    mnt->adjust_method_entries(the_class, &trace_name_printed);
   }
 
   if (the_class->oop_map_cache() != NULL) {
@@ -4050,11 +4045,11 @@
     the_class->oop_map_cache()->flush_obsolete_entries();
   }
 
+  increment_class_counter((InstanceKlass *)the_class, THREAD);
   {
     ResourceMark rm(THREAD);
     // increment the classRedefinedCount field in the_class and in any
     // direct and indirect subclasses of the_class
-    increment_class_counter((InstanceKlass *)the_class(), THREAD);
     log_info(redefine, class, load)
       ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
        the_class->external_name(), java_lang_Class::classRedefinedCount(the_class->java_mirror()), os::available_memory() >> 10);
@@ -4075,8 +4070,8 @@
   int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
   java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
 
-  if (class_oop != _the_class_oop) {
-    // _the_class_oop count is printed at end of redefine_single_class()
+  if (class_oop != _the_class) {
+    // _the_class count is printed at end of redefine_single_class()
     log_debug(redefine, class, subclass)("updated count in subclass=%s to %d", ik->external_name(), new_count);
   }
 
@@ -4212,8 +4207,8 @@
 
 void VM_RedefineClasses::print_on_error(outputStream* st) const {
   VM_Operation::print_on_error(st);
-  if (_the_class_oop != NULL) {
+  if (_the_class != NULL) {
     ResourceMark rm;
-    st->print_cr(", redefining class %s", _the_class_oop->external_name());
+    st->print_cr(", redefining class %s", _the_class->external_name());
   }
 }
--- a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -348,7 +348,7 @@
   static int             _matching_methods_length;
   static int             _deleted_methods_length;
   static int             _added_methods_length;
-  static Klass*          _the_class_oop;
+  static Klass*          _the_class;
 
   // The instance fields are used to pass information from
   // doit_prologue() to doit() and doit_epilogue().
@@ -371,7 +371,7 @@
   intArray *                  _operands_index_map_p;
 
   // ptr to _class_count scratch_classes
-  Klass**                     _scratch_classes;
+  InstanceKlass**             _scratch_classes;
   jvmtiError                  _res;
 
   // Performance measurement support. These timers do not cover all
@@ -393,7 +393,7 @@
   // the restrictions of RedefineClasses. Normalize the order of
   // overloaded methods as needed.
   jvmtiError compare_and_normalize_class_versions(
-    instanceKlassHandle the_class, instanceKlassHandle scratch_class);
+    InstanceKlass* the_class, InstanceKlass* scratch_class);
 
   // Figure out which new methods match old methods in name and signature,
   // which methods have been added, and which are no longer present
@@ -405,14 +405,14 @@
   // In addition to marking methods as old and/or obsolete, this routine
   // counts the number of methods that are EMCP (Equivalent Module Constant Pool).
   int check_methods_and_mark_as_obsolete();
-  void transfer_old_native_function_registrations(instanceKlassHandle the_class);
+  void transfer_old_native_function_registrations(InstanceKlass* the_class);
 
   // Install the redefinition of a class
   void redefine_single_class(jclass the_jclass,
-    Klass* scratch_class_oop, TRAPS);
+    InstanceKlass* scratch_class_oop, TRAPS);
 
-  void swap_annotations(instanceKlassHandle new_class,
-                        instanceKlassHandle scratch_class);
+  void swap_annotations(InstanceKlass* new_class,
+                        InstanceKlass* scratch_class);
 
   // Increment the classRedefinedCount field in the specific InstanceKlass
   // and in all direct and indirect subclasses.
@@ -437,18 +437,18 @@
   bool merge_constant_pools(const constantPoolHandle& old_cp,
     const constantPoolHandle& scratch_cp, constantPoolHandle *merge_cp_p,
     int *merge_cp_length_p, TRAPS);
-  jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
-    instanceKlassHandle scratch_class, TRAPS);
+  jvmtiError merge_cp_and_rewrite(InstanceKlass* the_class,
+    InstanceKlass* scratch_class, TRAPS);
   u2 rewrite_cp_ref_in_annotation_data(
     AnnotationArray* annotations_typeArray, int &byte_i_ref,
     const char * trace_mesg, TRAPS);
-  bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
+  bool rewrite_cp_refs(InstanceKlass* scratch_class, TRAPS);
   bool rewrite_cp_refs_in_annotation_struct(
     AnnotationArray* class_annotations, int &byte_i_ref, TRAPS);
   bool rewrite_cp_refs_in_annotations_typeArray(
     AnnotationArray* annotations_typeArray, int &byte_i_ref, TRAPS);
   bool rewrite_cp_refs_in_class_annotations(
-    instanceKlassHandle scratch_class, TRAPS);
+    InstanceKlass* scratch_class, TRAPS);
   bool rewrite_cp_refs_in_element_value(
     AnnotationArray* class_annotations, int &byte_i_ref, TRAPS);
   bool rewrite_cp_refs_in_type_annotations_typeArray(
@@ -463,31 +463,31 @@
   bool skip_type_annotation_type_path(
     AnnotationArray* type_annotations_typeArray, int &byte_i_ref, TRAPS);
   bool rewrite_cp_refs_in_fields_annotations(
-    instanceKlassHandle scratch_class, TRAPS);
+    InstanceKlass* scratch_class, TRAPS);
   void rewrite_cp_refs_in_method(methodHandle method,
     methodHandle * new_method_p, TRAPS);
-  bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
+  bool rewrite_cp_refs_in_methods(InstanceKlass* scratch_class, TRAPS);
   bool rewrite_cp_refs_in_methods_annotations(
-    instanceKlassHandle scratch_class, TRAPS);
+    InstanceKlass* scratch_class, TRAPS);
   bool rewrite_cp_refs_in_methods_default_annotations(
-    instanceKlassHandle scratch_class, TRAPS);
+    InstanceKlass* scratch_class, TRAPS);
   bool rewrite_cp_refs_in_methods_parameter_annotations(
-    instanceKlassHandle scratch_class, TRAPS);
+    InstanceKlass* scratch_class, TRAPS);
   bool rewrite_cp_refs_in_class_type_annotations(
-    instanceKlassHandle scratch_class, TRAPS);
+    InstanceKlass* scratch_class, TRAPS);
   bool rewrite_cp_refs_in_fields_type_annotations(
-    instanceKlassHandle scratch_class, TRAPS);
+    InstanceKlass* scratch_class, TRAPS);
   bool rewrite_cp_refs_in_methods_type_annotations(
-    instanceKlassHandle scratch_class, TRAPS);
+    InstanceKlass* scratch_class, TRAPS);
   void rewrite_cp_refs_in_stack_map_table(const methodHandle& method, TRAPS);
   void rewrite_cp_refs_in_verification_type_info(
          address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
          u1 frame_size, TRAPS);
   void set_new_constant_pool(ClassLoaderData* loader_data,
-         instanceKlassHandle scratch_class,
+         InstanceKlass* scratch_class,
          constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS);
 
-  void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
+  void flush_dependent_code(InstanceKlass* ik, TRAPS);
 
   // lock classes to redefine since constant pool merging isn't thread safe.
   void lock_classes();
--- a/hotspot/src/share/vm/prims/jvmtiTagMap.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiTagMap.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -783,7 +783,7 @@
   void add(int index, char type, int offset);
 
   // returns the field count for the given class
-  static int compute_field_count(instanceKlassHandle ikh);
+  static int compute_field_count(InstanceKlass* ik);
 
  public:
   ~ClassFieldMap();
@@ -819,16 +819,16 @@
 //
 ClassFieldMap* ClassFieldMap::create_map_of_static_fields(Klass* k) {
   HandleMark hm;
-  instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
 
   // create the field map
   ClassFieldMap* field_map = new ClassFieldMap();
 
-  FilteredFieldStream f(ikh, false, false);
+  FilteredFieldStream f(ik, false, false);
   int max_field_index = f.field_count()-1;
 
   int index = 0;
-  for (FilteredFieldStream fld(ikh, true, true); !fld.eos(); fld.next(), index++) {
+  for (FilteredFieldStream fld(ik, true, true); !fld.eos(); fld.next(), index++) {
     // ignore instance fields
     if (!fld.access_flags().is_static()) {
       continue;
@@ -844,17 +844,17 @@
 //
 ClassFieldMap* ClassFieldMap::create_map_of_instance_fields(oop obj) {
   HandleMark hm;
-  instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), obj->klass());
+  InstanceKlass* ik = InstanceKlass::cast(obj->klass());
 
   // create the field map
   ClassFieldMap* field_map = new ClassFieldMap();
 
-  FilteredFieldStream f(ikh, false, false);
+  FilteredFieldStream f(ik, false, false);
 
   int max_field_index = f.field_count()-1;
 
   int index = 0;
-  for (FilteredFieldStream fld(ikh, false, false); !fld.eos(); fld.next(), index++) {
+  for (FilteredFieldStream fld(ik, false, false); !fld.eos(); fld.next(), index++) {
     // ignore static fields
     if (fld.access_flags().is_static()) {
       continue;
@@ -1008,9 +1008,9 @@
 }
 
 // helper function to indicate if an object is filtered by a klass filter
-static inline bool is_filtered_by_klass_filter(oop obj, KlassHandle klass_filter) {
-  if (!klass_filter.is_null()) {
-    if (obj->klass() != klass_filter()) {
+static inline bool is_filtered_by_klass_filter(oop obj, Klass* klass_filter) {
+  if (klass_filter != NULL) {
+    if (obj->klass() != klass_filter) {
       return true;
     }
   }
@@ -1272,7 +1272,7 @@
 class IterateOverHeapObjectClosure: public ObjectClosure {
  private:
   JvmtiTagMap* _tag_map;
-  KlassHandle _klass;
+  Klass* _klass;
   jvmtiHeapObjectFilter _object_filter;
   jvmtiHeapObjectCallback _heap_object_callback;
   const void* _user_data;
@@ -1281,7 +1281,7 @@
   JvmtiTagMap* tag_map() const                    { return _tag_map; }
   jvmtiHeapObjectFilter object_filter() const     { return _object_filter; }
   jvmtiHeapObjectCallback object_callback() const { return _heap_object_callback; }
-  KlassHandle klass() const                       { return _klass; }
+  Klass* klass() const                            { return _klass; }
   const void* user_data() const                   { return _user_data; }
 
   // indicates if iteration has been aborted
@@ -1291,7 +1291,7 @@
 
  public:
   IterateOverHeapObjectClosure(JvmtiTagMap* tag_map,
-                               KlassHandle klass,
+                               Klass* klass,
                                jvmtiHeapObjectFilter object_filter,
                                jvmtiHeapObjectCallback heap_object_callback,
                                const void* user_data) :
@@ -1316,7 +1316,7 @@
   if (!ServiceUtil::visible_oop(o)) return;
 
   // instanceof check when filtering by klass
-  if (!klass().is_null() && !o->is_a(klass()())) {
+  if (klass() != NULL && !o->is_a(klass())) {
     return;
   }
   // prepare for the calllback
@@ -1345,7 +1345,7 @@
 class IterateThroughHeapObjectClosure: public ObjectClosure {
  private:
   JvmtiTagMap* _tag_map;
-  KlassHandle _klass;
+  Klass* _klass;
   int _heap_filter;
   const jvmtiHeapCallbacks* _callbacks;
   const void* _user_data;
@@ -1354,7 +1354,7 @@
   JvmtiTagMap* tag_map() const                     { return _tag_map; }
   int heap_filter() const                          { return _heap_filter; }
   const jvmtiHeapCallbacks* callbacks() const      { return _callbacks; }
-  KlassHandle klass() const                        { return _klass; }
+  Klass* klass() const                             { return _klass; }
   const void* user_data() const                    { return _user_data; }
 
   // indicates if the iteration has been aborted
@@ -1374,7 +1374,7 @@
 
  public:
   IterateThroughHeapObjectClosure(JvmtiTagMap* tag_map,
-                                  KlassHandle klass,
+                                  Klass* klass,
                                   int heap_filter,
                                   const jvmtiHeapCallbacks* heap_callbacks,
                                   const void* user_data) :
@@ -1470,7 +1470,7 @@
 
 // Deprecated function to iterate over all objects in the heap
 void JvmtiTagMap::iterate_over_heap(jvmtiHeapObjectFilter object_filter,
-                                    KlassHandle klass,
+                                    Klass* klass,
                                     jvmtiHeapObjectCallback heap_object_callback,
                                     const void* user_data)
 {
@@ -1487,7 +1487,7 @@
 
 // Iterates over all objects in the heap
 void JvmtiTagMap::iterate_through_heap(jint heap_filter,
-                                       KlassHandle klass,
+                                       Klass* klass,
                                        const jvmtiHeapCallbacks* callbacks,
                                        const void* user_data)
 {
@@ -1806,14 +1806,14 @@
 class AdvancedHeapWalkContext: public HeapWalkContext {
  private:
   jint _heap_filter;
-  KlassHandle _klass_filter;
+  Klass* _klass_filter;
   const jvmtiHeapCallbacks* _heap_callbacks;
 
  public:
   AdvancedHeapWalkContext() : HeapWalkContext(false) { }
 
   AdvancedHeapWalkContext(jint heap_filter,
-                           KlassHandle klass_filter,
+                           Klass* klass_filter,
                            const jvmtiHeapCallbacks* heap_callbacks) :
     HeapWalkContext(true),
     _heap_filter(heap_filter),
@@ -1823,7 +1823,7 @@
 
   // accessors
   jint heap_filter() const         { return _heap_filter; }
-  KlassHandle klass_filter() const { return _klass_filter; }
+  Klass* klass_filter() const      { return _klass_filter; }
 
   const jvmtiHeapReferenceCallback heap_reference_callback() const {
     return _heap_callbacks->heap_reference_callback;
@@ -3296,7 +3296,7 @@
 
 // follow references from an initial object or the GC roots
 void JvmtiTagMap::follow_references(jint heap_filter,
-                                    KlassHandle klass,
+                                    Klass* klass,
                                     jobject object,
                                     const jvmtiHeapCallbacks* callbacks,
                                     const void* user_data)
--- a/hotspot/src/share/vm/prims/jvmtiTagMap.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiTagMap.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -91,7 +91,7 @@
 
   // deprecated heap iteration functions
   void iterate_over_heap(jvmtiHeapObjectFilter object_filter,
-                         KlassHandle klass,
+                         Klass* klass,
                          jvmtiHeapObjectCallback heap_object_callback,
                          const void* user_data);
 
@@ -107,12 +107,12 @@
 
   // advanced (JVMTI 1.1) heap iteration functions
   void iterate_through_heap(jint heap_filter,
-                            KlassHandle klass,
+                            Klass* klass,
                             const jvmtiHeapCallbacks* callbacks,
                             const void* user_data);
 
   void follow_references(jint heap_filter,
-                         KlassHandle klass,
+                         Klass* klass,
                          jobject initial_object,
                          const jvmtiHeapCallbacks* callbacks,
                          const void* user_data);
--- a/hotspot/src/share/vm/prims/jvmtiThreadState.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiThreadState.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -93,7 +93,7 @@
 
   // Used to send class being redefined/retransformed and kind of transform
   // info to the class file load hook event handler.
-  KlassHandle           *_class_being_redefined;
+  Klass*                _class_being_redefined;
   JvmtiClassLoadKind    _class_load_kind;
 
   // This is only valid when is_interp_only_mode() returns true
@@ -220,8 +220,8 @@
   // when class file load hook event is posted.
   // It is set while loading redefined class and cleared before the
   // class file load hook event is posted.
-  inline void set_class_being_redefined(KlassHandle *h_class, JvmtiClassLoadKind kind) {
-    _class_being_redefined = h_class;
+  inline void set_class_being_redefined(Klass* k, JvmtiClassLoadKind kind) {
+    _class_being_redefined = k;
     _class_load_kind = kind;
   }
 
@@ -230,7 +230,7 @@
     _class_load_kind = jvmti_class_load_kind_load;
   }
 
-  inline KlassHandle *get_class_being_redefined() {
+  inline Klass* get_class_being_redefined() {
     return _class_being_redefined;
   }
 
@@ -271,12 +271,12 @@
   //   used by the verifier, so there is no extra performance issue with it.
 
  private:
-  KlassHandle *_the_class_for_redefinition_verification;
-  KlassHandle *_scratch_class_for_redefinition_verification;
+  Klass* _the_class_for_redefinition_verification;
+  Klass* _scratch_class_for_redefinition_verification;
 
  public:
-  inline void set_class_versions_map(KlassHandle *the_class,
-                                     KlassHandle *scratch_class) {
+  inline void set_class_versions_map(Klass* the_class,
+                                     Klass* scratch_class) {
     _the_class_for_redefinition_verification = the_class;
     _scratch_class_for_redefinition_verification = scratch_class;
   }
@@ -288,8 +288,8 @@
                                                     JavaThread *thread) {
     JvmtiThreadState *state = thread->jvmti_thread_state();
     if (state != NULL && state->_the_class_for_redefinition_verification != NULL) {
-      if ((*(state->_the_class_for_redefinition_verification))() == klass) {
-        klass = (*(state->_scratch_class_for_redefinition_verification))();
+      if (state->_the_class_for_redefinition_verification == klass) {
+        klass = state->_scratch_class_for_redefinition_verification;
       }
     }
     return klass;
@@ -409,17 +409,17 @@
 
 class RedefineVerifyMark : public StackObj {
  private:
-  JvmtiThreadState *_state;
-  KlassHandle       _scratch_class;
+  JvmtiThreadState* _state;
+  Klass*            _scratch_class;
   Handle            _scratch_mirror;
 
  public:
-  RedefineVerifyMark(KlassHandle *the_class, KlassHandle *scratch_class,
-                     JvmtiThreadState *state) : _state(state), _scratch_class(*scratch_class)
+  RedefineVerifyMark(Klass* the_class, Klass* scratch_class,
+                     JvmtiThreadState *state) : _state(state), _scratch_class(scratch_class)
   {
     _state->set_class_versions_map(the_class, scratch_class);
-    _scratch_mirror = Handle(_scratch_class->java_mirror());
-    (*scratch_class)->set_java_mirror((*the_class)->java_mirror());
+    _scratch_mirror = Handle(Thread::current(), _scratch_class->java_mirror());
+    _scratch_class->set_java_mirror(the_class->java_mirror());
   }
 
   ~RedefineVerifyMark() {
--- a/hotspot/src/share/vm/prims/methodHandles.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/methodHandles.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -124,7 +124,7 @@
 
 Handle MethodHandles::new_MemberName(TRAPS) {
   Handle empty;
-  instanceKlassHandle k(THREAD, SystemDictionary::MemberName_klass());
+  InstanceKlass* k = SystemDictionary::MemberName_klass();
   if (!k->is_initialized())  k->initialize(CHECK_(empty));
   return Handle(THREAD, k->allocate_instance(THREAD));
 }
@@ -138,9 +138,9 @@
   if (target_klass == SystemDictionary::reflect_Field_klass()) {
     oop clazz = java_lang_reflect_Field::clazz(target_oop); // fd.field_holder()
     int slot  = java_lang_reflect_Field::slot(target_oop);  // fd.index()
-    KlassHandle k(thread, java_lang_Class::as_Klass(clazz));
-    if (!k.is_null() && k->is_instance_klass()) {
-      fieldDescriptor fd(InstanceKlass::cast(k()), slot);
+    Klass* k = java_lang_Class::as_Klass(clazz);
+    if (k != NULL && k->is_instance_klass()) {
+      fieldDescriptor fd(InstanceKlass::cast(k), slot);
       oop mname2 = init_field_MemberName(mname, fd);
       if (mname2 != NULL) {
         // Since we have the reified name and type handy, add them to the result.
@@ -154,22 +154,22 @@
   } else if (target_klass == SystemDictionary::reflect_Method_klass()) {
     oop clazz  = java_lang_reflect_Method::clazz(target_oop);
     int slot   = java_lang_reflect_Method::slot(target_oop);
-    KlassHandle k(thread, java_lang_Class::as_Klass(clazz));
-    if (!k.is_null() && k->is_instance_klass()) {
-      Method* m = InstanceKlass::cast(k())->method_with_idnum(slot);
+    Klass* k = java_lang_Class::as_Klass(clazz);
+    if (k != NULL && k->is_instance_klass()) {
+      Method* m = InstanceKlass::cast(k)->method_with_idnum(slot);
       if (m == NULL || is_signature_polymorphic(m->intrinsic_id()))
         return NULL;            // do not resolve unless there is a concrete signature
-      CallInfo info(m, k());
+      CallInfo info(m, k);
       return init_method_MemberName(mname, info);
     }
   } else if (target_klass == SystemDictionary::reflect_Constructor_klass()) {
     oop clazz  = java_lang_reflect_Constructor::clazz(target_oop);
     int slot   = java_lang_reflect_Constructor::slot(target_oop);
-    KlassHandle k(thread, java_lang_Class::as_Klass(clazz));
-    if (!k.is_null() && k->is_instance_klass()) {
-      Method* m = InstanceKlass::cast(k())->method_with_idnum(slot);
+    Klass* k = java_lang_Class::as_Klass(clazz);
+    if (k != NULL && k->is_instance_klass()) {
+      Method* m = InstanceKlass::cast(k)->method_with_idnum(slot);
       if (m == NULL)  return NULL;
-      CallInfo info(m, k());
+      CallInfo info(m, k);
       return init_method_MemberName(mname, info);
     }
   }
@@ -180,8 +180,8 @@
   assert(info.resolved_appendix().is_null(), "only normal methods here");
   methodHandle m = info.resolved_method();
   assert(m.not_null(), "null method handle");
-  KlassHandle m_klass = m->method_holder();
-  assert(m.not_null(), "null holder for method handle");
+  Klass* m_klass = m->method_holder();
+  assert(m_klass != NULL, "null holder for method handle");
   int flags = (jushort)( m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS );
   int vmindex = Method::invalid_vtable_index;
 
@@ -208,12 +208,12 @@
   case CallInfo::vtable_call:
     vmindex = info.vtable_index();
     flags |= IS_METHOD | (JVM_REF_invokeVirtual << REFERENCE_KIND_SHIFT);
-    assert(info.resolved_klass()->is_subtype_of(m_klass()), "virtual call must be type-safe");
+    assert(info.resolved_klass()->is_subtype_of(m_klass), "virtual call must be type-safe");
     if (m_klass->is_interface()) {
       // This is a vtable call to an interface method (abstract "miranda method" or default method).
       // The vtable index is meaningless without a class (not interface) receiver type, so get one.
       // (LinkResolver should help us figure this out.)
-      KlassHandle m_klass_non_interface = info.resolved_klass();
+      Klass* m_klass_non_interface = info.resolved_klass();
       if (m_klass_non_interface->is_interface()) {
         m_klass_non_interface = SystemDictionary::Object_klass();
 #ifdef ASSERT
@@ -229,7 +229,7 @@
         assert(m->is_public(), "virtual call must be to public interface method");
         return NULL;  // elicit an error later in product build
       }
-      assert(info.resolved_klass()->is_subtype_of(m_klass_non_interface()), "virtual call must be type-safe");
+      assert(info.resolved_klass()->is_subtype_of(m_klass_non_interface), "virtual call must be type-safe");
       m_klass = m_klass_non_interface;
     }
     if (TraceInvokeDynamic) {
@@ -637,7 +637,7 @@
 // An unresolved member name is a mere symbolic reference.
 // Resolving it plants a vmtarget/vmindex in it,
 // which refers directly to JVM internals.
-Handle MethodHandles::resolve_MemberName(Handle mname, KlassHandle caller, TRAPS) {
+Handle MethodHandles::resolve_MemberName(Handle mname, Klass* caller, TRAPS) {
   Handle empty;
   assert(java_lang_invoke_MemberName::is_instance(mname()), "");
 
@@ -664,7 +664,7 @@
     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "nothing to resolve", empty);
   }
 
-  instanceKlassHandle defc;
+  InstanceKlass* defc = NULL;
   {
     Klass* defc_klass = java_lang_Class::as_Klass(defc_oop());
     if (defc_klass == NULL)  return empty;  // a primitive; no resolution possible
@@ -672,9 +672,9 @@
       if (!defc_klass->is_array_klass())  return empty;
       defc_klass = SystemDictionary::Object_klass();
     }
-    defc = instanceKlassHandle(THREAD, defc_klass);
+    defc = InstanceKlass::cast(defc_klass);
   }
-  if (defc.is_null()) {
+  if (defc == NULL) {
     THROW_MSG_(vmSymbols::java_lang_InternalError(), "primitive class", empty);
   }
   defc->link_class(CHECK_(empty));  // possible safepoint
@@ -687,7 +687,7 @@
 
   vmIntrinsics::ID mh_invoke_id = vmIntrinsics::_none;
   if ((flags & ALL_KINDS) == IS_METHOD &&
-      (defc() == SystemDictionary::MethodHandle_klass()) &&
+      (defc == SystemDictionary::MethodHandle_klass()) &&
       (ref_kind == JVM_REF_invokeVirtual ||
        ref_kind == JVM_REF_invokeSpecial ||
        // static invocation mode is required for _linkToVirtual, etc.:
@@ -705,7 +705,7 @@
   TempNewSymbol type = lookup_signature(type_str(), (mh_invoke_id != vmIntrinsics::_none), CHECK_(empty));
   if (type == NULL)  return empty;  // no such signature exists in the VM
 
-  LinkInfo::AccessCheck access_check = caller.not_null() ?
+  LinkInfo::AccessCheck access_check = caller != NULL ?
                                               LinkInfo::needs_access_check :
                                               LinkInfo::skip_access_check;
 
@@ -827,8 +827,8 @@
       }
       if (!have_name) {
         //not java_lang_String::create_from_symbol; let's intern member names
-        Handle name = StringTable::intern(m->name(), CHECK);
-        java_lang_invoke_MemberName::set_name(mname(), name());
+        oop name = StringTable::intern(m->name(), CHECK);
+        java_lang_invoke_MemberName::set_name(mname(), name);
       }
       if (!have_type) {
         Handle type = java_lang_String::create_from_symbol(m->signature(), CHECK);
@@ -840,7 +840,7 @@
     {
       assert(vmtarget->is_klass(), "field vmtarget is Klass*");
       if (!((Klass*) vmtarget)->is_instance_klass())  break;
-      instanceKlassHandle defc(THREAD, (Klass*) vmtarget);
+      InstanceKlass* defc = InstanceKlass::cast((Klass*) vmtarget);
       DEBUG_ONLY(vmtarget = NULL);  // safety
       bool is_static = ((flags & JVM_ACC_STATIC) != 0);
       fieldDescriptor fd; // find_field initializes fd if found
@@ -851,14 +851,14 @@
       }
       if (!have_name) {
         //not java_lang_String::create_from_symbol; let's intern member names
-        Handle name = StringTable::intern(fd.name(), CHECK);
-        java_lang_invoke_MemberName::set_name(mname(), name());
+        oop name = StringTable::intern(fd.name(), CHECK);
+        java_lang_invoke_MemberName::set_name(mname(), name);
       }
       if (!have_type) {
         // If it is a primitive field type, don't mess with short strings like "I".
-        Handle type = field_signature_type_or_null(fd.signature());
+        Handle type (THREAD, field_signature_type_or_null(fd.signature()));
         if (type.is_null()) {
-          java_lang_String::create_from_symbol(fd.signature(), CHECK);
+          type = java_lang_String::create_from_symbol(fd.signature(), CHECK);
         }
         java_lang_invoke_MemberName::set_type(mname(), type());
       }
@@ -868,15 +868,15 @@
   THROW_MSG(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format");
 }
 
-int MethodHandles::find_MemberNames(KlassHandle k,
+int MethodHandles::find_MemberNames(Klass* k,
                                     Symbol* name, Symbol* sig,
-                                    int mflags, KlassHandle caller,
+                                    int mflags, Klass* caller,
                                     int skip, objArrayHandle results) {
   // %%% take caller into account!
 
   Thread* thread = Thread::current();
 
-  if (k.is_null() || !k->is_instance_klass())  return -1;
+  if (k == NULL || !k->is_instance_klass())  return -1;
 
   int rfill = 0, rlimit = results->length(), rskip = skip;
   // overflow measurement:
@@ -904,7 +904,8 @@
   }
 
   if ((match_flags & IS_FIELD) != 0) {
-    for (FieldStream st(k(), local_only, !search_intfc); !st.eos(); st.next()) {
+    InstanceKlass* ik = InstanceKlass::cast(k);
+    for (FieldStream st(ik, local_only, !search_intfc); !st.eos(); st.next()) {
       if (name != NULL && st.name() != name)
           continue;
       if (sig != NULL && st.signature() != sig)
@@ -950,7 +951,8 @@
     } else {
       // caller will accept either sort; no need to adjust name
     }
-    for (MethodStream st(k(), local_only, !search_intfc); !st.eos(); st.next()) {
+    InstanceKlass* ik = InstanceKlass::cast(k);
+    for (MethodStream st(ik, local_only, !search_intfc); !st.eos(); st.next()) {
       Method* m = st.method();
       Symbol* m_name = m->name();
       if (m_name == clinit_name)
@@ -1015,7 +1017,7 @@
   assert_lock_strong(Compile_lock);
 
   int marked = 0;
-  CallSiteDepChange changes(call_site(), target());
+  CallSiteDepChange changes(call_site, target);
   {
     NoSafepointVerifier nsv;
     MutexLockerEx mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
@@ -1231,16 +1233,15 @@
       Klass* caller = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
       if (caller != SystemDictionary::Object_klass()
           && Reflection::verify_class_access(caller,
-                                             reference_klass,
+                                             InstanceKlass::cast(reference_klass),
                                              true) != Reflection::ACCESS_OK) {
         THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), reference_klass->external_name());
       }
     }
   }
 
-  KlassHandle caller(THREAD,
-                     caller_jh == NULL ? (Klass*) NULL :
-                     java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh)));
+  Klass* caller = caller_jh == NULL ? NULL :
+                     java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
   Handle resolved = MethodHandles::resolve_MemberName(mname, caller, CHECK_NULL);
 
   if (resolved.is_null()) {
@@ -1305,7 +1306,7 @@
   Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
   intptr_t vmindex  = java_lang_invoke_MemberName::vmindex(mname());
   Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(mname());
-  objArrayHandle result = oopFactory::new_objArray(SystemDictionary::Object_klass(), 2, CHECK_NULL);
+  objArrayHandle result = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 2, CHECK_NULL);
   jvalue vmindex_value; vmindex_value.j = (long)vmindex;
   oop x = java_lang_boxing_object::create(T_LONG, &vmindex_value, CHECK_NULL);
   result->obj_at_put(0, x);
@@ -1330,7 +1331,7 @@
                                jclass clazz_jh, jstring name_jh, jstring sig_jh,
                                int mflags, jclass caller_jh, jint skip, jobjectArray results_jh)) {
   if (clazz_jh == NULL || results_jh == NULL)  return -1;
-  KlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz_jh)));
+  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz_jh));
 
   objArrayHandle results(THREAD, (objArrayOop) JNIHandles::resolve(results_jh));
   if (results.is_null() || !results->is_objArray())  return -1;
@@ -1346,11 +1347,11 @@
     if (sig == NULL)  return 0; // a match is not possible
   }
 
-  KlassHandle caller;
+  Klass* caller = NULL;
   if (caller_jh != NULL) {
     oop caller_oop = JNIHandles::resolve_non_null(caller_jh);
     if (!java_lang_Class::is_instance(caller_oop))  return -1;
-    caller = KlassHandle(THREAD, java_lang_Class::as_Klass(caller_oop));
+    caller = java_lang_Class::as_Klass(caller_oop);
   }
 
   if (name != NULL && sig != NULL && results.not_null()) {
--- a/hotspot/src/share/vm/prims/methodHandles.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/methodHandles.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -61,15 +61,15 @@
 
  public:
   // working with member names
-  static Handle resolve_MemberName(Handle mname, KlassHandle caller, TRAPS); // compute vmtarget/vmindex from name/type
+  static Handle resolve_MemberName(Handle mname, Klass* caller, TRAPS); // compute vmtarget/vmindex from name/type
   static void expand_MemberName(Handle mname, int suppress, TRAPS);  // expand defc/name/type if missing
   static Handle new_MemberName(TRAPS);  // must be followed by init_MemberName
   static oop init_MemberName(Handle mname_h, Handle target_h); // compute vmtarget/vmindex from target
   static oop init_field_MemberName(Handle mname_h, fieldDescriptor& fd, bool is_setter = false);
   static oop init_method_MemberName(Handle mname_h, CallInfo& info, bool intern = true);
   static int method_ref_kind(Method* m, bool do_dispatch_if_possible = true);
-  static int find_MemberNames(KlassHandle k, Symbol* name, Symbol* sig,
-                              int mflags, KlassHandle caller,
+  static int find_MemberNames(Klass* k, Symbol* name, Symbol* sig,
+                              int mflags, Klass* caller,
                               int skip, objArrayHandle results);
   // bit values for suppress argument to expand_MemberName:
   enum { _suppress_defc = 1, _suppress_name = 2, _suppress_type = 4 };
--- a/hotspot/src/share/vm/prims/nativeLookup.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/nativeLookup.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -175,7 +175,7 @@
   }
 
   // Otherwise call static method findNative in ClassLoader
-  KlassHandle   klass (THREAD, SystemDictionary::ClassLoader_klass());
+  Klass*   klass = SystemDictionary::ClassLoader_klass();
   Handle name_arg = java_lang_String::create_from_str(jni_name, CHECK_NULL);
 
   JavaValue result(T_LONG);
@@ -345,9 +345,8 @@
     int wrapper_name_len = (int)strlen(wrapper_name);
     TempNewSymbol wrapper_symbol = SymbolTable::probe(wrapper_name, wrapper_name_len);
     if (wrapper_symbol != NULL) {
-      KlassHandle kh(method->method_holder());
-      Method* wrapper_method = kh()->lookup_method(wrapper_symbol,
-                                                                  method->signature());
+      Klass* k = method->method_holder();
+      Method* wrapper_method = k->lookup_method(wrapper_symbol, method->signature());
       if (wrapper_method != NULL && !wrapper_method->is_native()) {
         // we found a wrapper method, use its native entry
         method->set_is_prefixed_native();
@@ -402,7 +401,7 @@
 
   // Find the class
   Klass* k = SystemDictionary::resolve_or_fail(c_name, true, CATCH);
-  instanceKlassHandle klass (THREAD, k);
+  InstanceKlass* klass  = InstanceKlass::cast(k);
 
   // Find method and invoke standard lookup
   methodHandle method (THREAD,
--- a/hotspot/src/share/vm/prims/stackwalk.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/stackwalk.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -179,7 +179,7 @@
 oop LiveFrameStream::create_primitive_slot_instance(StackValueCollection* values,
                                                     int i, BasicType type, TRAPS) {
   Klass* k = SystemDictionary::resolve_or_null(vmSymbols::java_lang_LiveStackFrameInfo(), CHECK_NULL);
-  instanceKlassHandle ik (THREAD, k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
 
   JavaValue result(T_OBJECT);
   JavaCallArguments args;
@@ -272,7 +272,7 @@
 // Fill StackFrameInfo with declaringClass and bci and initialize memberName
 void BaseFrameStream::fill_stackframe(Handle stackFrame, const methodHandle& method) {
   java_lang_StackFrameInfo::set_declaringClass(stackFrame(), method->method_holder()->java_mirror());
-  java_lang_StackFrameInfo::set_method_and_bci(stackFrame(), method, bci());
+  java_lang_StackFrameInfo::set_method_and_bci(stackFrame, method, bci());
 }
 
 // Fill LiveStackFrameInfo with locals, monitors, and expressions
--- a/hotspot/src/share/vm/prims/unsafe.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/unsafe.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -845,7 +845,7 @@
 // not just a literal string.  For such ldc instructions, the verifier uses the
 // type Object instead of String, if the loaded constant is not in fact a String.
 
-static instanceKlassHandle
+static InstanceKlass*
 Unsafe_DefineAnonymousClass_impl(JNIEnv *env,
                                  jclass host_class, jbyteArray data, jobjectArray cp_patches_jh,
                                  u1** temp_alloc,
@@ -932,18 +932,17 @@
     return NULL;
   }
 
-  return instanceKlassHandle(THREAD, anonk);
+  return InstanceKlass::cast(anonk);
 }
 
 UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass0(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh)) {
   ResourceMark rm(THREAD);
 
-  instanceKlassHandle anon_klass;
   jobject res_jh = NULL;
   u1* temp_alloc = NULL;
 
-  anon_klass = Unsafe_DefineAnonymousClass_impl(env, host_class, data, cp_patches_jh, &temp_alloc, THREAD);
-  if (anon_klass() != NULL) {
+  InstanceKlass* anon_klass = Unsafe_DefineAnonymousClass_impl(env, host_class, data, cp_patches_jh, &temp_alloc, THREAD);
+  if (anon_klass != NULL) {
     res_jh = JNIHandles::make_local(env, anon_klass->java_mirror());
   }
 
@@ -955,7 +954,7 @@
   // The anonymous class loader data has been artificially been kept alive to
   // this point.   The mirror and any instances of this class have to keep
   // it alive afterwards.
-  if (anon_klass() != NULL) {
+  if (anon_klass != NULL) {
     anon_klass->class_loader_data()->dec_keep_alive();
   }
 
--- a/hotspot/src/share/vm/prims/whitebox.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/whitebox.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -126,8 +126,8 @@
 };
 
 WB_ENTRY(jboolean, WB_IsClassAlive(JNIEnv* env, jobject target, jstring name))
-  Handle h_name = JNIHandles::resolve(name);
-  if (h_name.is_null()) return false;
+  oop h_name = JNIHandles::resolve(name);
+  if (h_name == NULL) return false;
   Symbol* sym = java_lang_String::as_symbol(h_name, CHECK_false);
   TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return
 
@@ -782,8 +782,8 @@
 WB_END
 
 WB_ENTRY(jboolean, WB_EnqueueInitializerForCompilation(JNIEnv* env, jobject o, jclass klass, jint comp_level))
-  instanceKlassHandle ikh(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
-  return WhiteBox::compile_method(ikh->class_initializer(), comp_level, InvocationEntryBci, THREAD);
+  InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
+  return WhiteBox::compile_method(ik->class_initializer(), comp_level, InvocationEntryBci, THREAD);
 WB_END
 
 WB_ENTRY(jboolean, WB_ShouldPrintAssembly(JNIEnv* env, jobject o, jobject method, jint comp_level))
@@ -1466,15 +1466,6 @@
   Modules::add_module_package(module, package_name, CHECK);
 WB_END
 
-WB_ENTRY(jobject, WB_GetModuleByPackageName(JNIEnv* env, jobject o, jobject loader, jstring package))
-  ResourceMark rm(THREAD);
-  char* package_name = NULL;
-  if (package != NULL) {
-      package_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(package));
-  }
-  return Modules::get_module_by_package_name(loader, package_name, THREAD);
-WB_END
-
 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc))
   if (inc < 0) {
     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
@@ -1526,8 +1517,8 @@
 WB_END
 
 WB_ENTRY(jlong, WB_GetConstantPool(JNIEnv* env, jobject wb, jclass klass))
-  instanceKlassHandle ikh(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
-  return (jlong) ikh->constants();
+  InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
+  return (jlong) ik->constants();
 WB_END
 
 WB_ENTRY(jint, WB_GetConstantPoolCacheIndexTag(JNIEnv* env, jobject wb))
@@ -1535,8 +1526,8 @@
 WB_END
 
 WB_ENTRY(jint, WB_GetConstantPoolCacheLength(JNIEnv* env, jobject wb, jclass klass))
-  instanceKlassHandle ikh(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
-  ConstantPool* cp = ikh->constants();
+  InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
+  ConstantPool* cp = ik->constants();
   if (cp->cache() == NULL) {
       return -1;
   }
@@ -1544,8 +1535,8 @@
 WB_END
 
 WB_ENTRY(jint, WB_ConstantPoolRemapInstructionOperandFromCache(JNIEnv* env, jobject wb, jclass klass, jint index))
-  instanceKlassHandle ikh(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
-  ConstantPool* cp = ikh->constants();
+  InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
+  ConstantPool* cp = ik->constants();
   if (cp->cache() == NULL) {
     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), "Constant pool does not have a cache");
   }
@@ -1912,8 +1903,6 @@
                                                       (void*)&WB_AddReadsModule },
   {CC"AddModulePackage",   CC"(Ljava/lang/Object;Ljava/lang/String;)V",
                                                       (void*)&WB_AddModulePackage },
-  {CC"GetModuleByPackageName", CC"(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;",
-                                                      (void*)&WB_GetModuleByPackageName },
   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
@@ -1961,8 +1950,8 @@
   {
     if (WhiteBoxAPI) {
       // Make sure that wbclass is loaded by the null classloader
-      instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
-      Handle loader(ikh->class_loader());
+      InstanceKlass* ik = InstanceKlass::cast(JNIHandles::resolve(wbclass)->klass());
+      Handle loader(THREAD, ik->class_loader());
       if (loader.is_null()) {
         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
         WhiteBox::register_extended(env, wbclass, thread);
--- a/hotspot/src/share/vm/runtime/atomic.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/atomic.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -81,8 +81,6 @@
   inline static size_t   add    (size_t   add_value, volatile size_t*   dest);
   inline static intptr_t add_ptr(intptr_t add_value, volatile intptr_t* dest);
   inline static void*    add_ptr(intptr_t add_value, volatile void*     dest);
-  // See comment above about using jlong atomics on 32-bit platforms
-  inline static jlong    add    (jlong    add_value, volatile jlong*    dest);
 
   // Atomically increment location. inc*() provide:
   // <fence> increment-dest <membar StoreLoad|StoreStore>
@@ -199,16 +197,6 @@
                                        (jint)compare_value, order);
 }
 
-inline jlong Atomic::add(jlong    add_value, volatile jlong*    dest) {
-  jlong old = load(dest);
-  jlong new_value = old + add_value;
-  while (old != cmpxchg(new_value, dest, old)) {
-    old = load(dest);
-    new_value = old + add_value;
-  }
-  return old;
-}
-
 inline jshort Atomic::add(jshort add_value, volatile jshort* dest) {
   // Most platforms do not support atomic add on a 2-byte value. However,
   // if the value occupies the most significant 16 bits of an aligned 32-bit
--- a/hotspot/src/share/vm/runtime/deoptimization.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/deoptimization.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -452,7 +452,6 @@
   // Compute whether the root vframe returns a float or double value.
   BasicType return_type;
   {
-    HandleMark hm;
     methodHandle method(thread, array->element(0)->method());
     Bytecode_invoke invoke = Bytecode_invoke_check(method, array->element(0)->bci());
     return_type = invoke.is_valid() ? invoke.result_type() : T_ILLEGAL;
@@ -800,7 +799,7 @@
 
 #if defined(COMPILER2) || INCLUDE_JVMCI
 bool Deoptimization::realloc_objects(JavaThread* thread, frame* fr, GrowableArray<ScopeValue*>* objects, TRAPS) {
-  Handle pending_exception(thread->pending_exception());
+  Handle pending_exception(THREAD, thread->pending_exception());
   const char* exception_file = thread->exception_file();
   int exception_line = thread->exception_line();
   thread->clear_pending_exception();
@@ -811,19 +810,19 @@
     assert(objects->at(i)->is_object(), "invalid debug information");
     ObjectValue* sv = (ObjectValue*) objects->at(i);
 
-    KlassHandle k(java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()()));
+    Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
     oop obj = NULL;
 
     if (k->is_instance_klass()) {
-      InstanceKlass* ik = InstanceKlass::cast(k());
+      InstanceKlass* ik = InstanceKlass::cast(k);
       obj = ik->allocate_instance(THREAD);
     } else if (k->is_typeArray_klass()) {
-      TypeArrayKlass* ak = TypeArrayKlass::cast(k());
+      TypeArrayKlass* ak = TypeArrayKlass::cast(k);
       assert(sv->field_size() % type2size[ak->element_type()] == 0, "non-integral array length");
       int len = sv->field_size() / type2size[ak->element_type()];
       obj = ak->allocate(len, THREAD);
     } else if (k->is_objArray_klass()) {
-      ObjArrayKlass* ak = ObjArrayKlass::cast(k());
+      ObjArrayKlass* ak = ObjArrayKlass::cast(k);
       obj = ak->allocate(sv->field_size(), THREAD);
     }
 
@@ -1080,7 +1079,7 @@
 void Deoptimization::reassign_fields(frame* fr, RegisterMap* reg_map, GrowableArray<ScopeValue*>* objects, bool realloc_failures, bool skip_internal) {
   for (int i = 0; i < objects->length(); i++) {
     ObjectValue* sv = (ObjectValue*) objects->at(i);
-    KlassHandle k(java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()()));
+    Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
     Handle obj = sv->value();
     assert(obj.not_null() || realloc_failures, "reallocation was missed");
     if (PrintDeoptimizationDetails) {
@@ -1091,10 +1090,10 @@
     }
 
     if (k->is_instance_klass()) {
-      InstanceKlass* ik = InstanceKlass::cast(k());
+      InstanceKlass* ik = InstanceKlass::cast(k);
       reassign_fields_by_klass(ik, fr, reg_map, sv, 0, obj(), skip_internal);
     } else if (k->is_typeArray_klass()) {
-      TypeArrayKlass* ak = TypeArrayKlass::cast(k());
+      TypeArrayKlass* ak = TypeArrayKlass::cast(k);
       reassign_type_array_elements(fr, reg_map, sv, (typeArrayOop) obj(), ak->element_type());
     } else if (k->is_objArray_klass()) {
       reassign_object_array_elements(fr, reg_map, sv, (objArrayOop) obj());
@@ -1110,7 +1109,7 @@
     if (mon_info->eliminated()) {
       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
       if (!mon_info->owner_is_scalar_replaced()) {
-        Handle obj = Handle(mon_info->owner());
+        Handle obj(thread, mon_info->owner());
         markOop mark = obj->mark();
         if (UseBiasedLocking && mark->has_bias_pattern()) {
           // New allocated objects may have the mark set to anonymously biased.
@@ -1138,7 +1137,7 @@
 
   for (int i = 0; i < objects->length(); i++) {
     ObjectValue* sv = (ObjectValue*) objects->at(i);
-    KlassHandle k(java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()()));
+    Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
     Handle obj = sv->value();
 
     tty->print("     object <" INTPTR_FORMAT "> of type ", p2i(sv->value()()));
@@ -1247,10 +1246,11 @@
 
 static void collect_monitors(compiledVFrame* cvf, GrowableArray<Handle>* objects_to_revoke) {
   GrowableArray<MonitorInfo*>* monitors = cvf->monitors();
+  Thread* thread = Thread::current();
   for (int i = 0; i < monitors->length(); i++) {
     MonitorInfo* mon_info = monitors->at(i);
     if (!mon_info->eliminated() && mon_info->owner() != NULL) {
-      objects_to_revoke->append(Handle(mon_info->owner()));
+      objects_to_revoke->append(Handle(thread, mon_info->owner()));
     }
   }
 }
--- a/hotspot/src/share/vm/runtime/fieldDescriptor.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/fieldDescriptor.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -61,10 +61,10 @@
     reinitialize(ik, index);
   }
   Symbol* name() const {
-    return field()->name(_cp);
+    return field()->name(_cp());
   }
   Symbol* signature() const {
-    return field()->signature(_cp);
+    return field()->signature(_cp());
   }
   InstanceKlass* field_holder()   const    { return _cp->pool_holder(); }
   ConstantPool* constants()       const    { return _cp(); }
--- a/hotspot/src/share/vm/runtime/globals.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/globals.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -934,6 +934,9 @@
   notproduct(bool, TestSafeFetchInErrorHandler, false,                      \
           "If true, tests SafeFetch inside error handler.")                 \
                                                                             \
+  notproduct(bool, TestUnresponsiveErrorHandler, false,                     \
+          "If true, simulates an unresponsive error handler.")              \
+                                                                            \
   develop(bool, Verbose, false,                                             \
           "Print additional debugging information from other modes")        \
                                                                             \
--- a/hotspot/src/share/vm/runtime/handles.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/handles.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,15 +37,6 @@
   assert(obj->is_oop(), "not an oop: " INTPTR_FORMAT, p2i(obj));
   return real_allocate_handle(obj);
 }
-
-Handle::Handle(Thread* thread, oop obj) {
-  assert(thread == Thread::current(), "sanity check");
-  if (obj == NULL) {
-    _handle = NULL;
-  } else {
-    _handle = thread->handle_area()->allocate_handle(obj);
-  }
-}
 #endif
 
 // Copy constructors and destructors for metadata handles
@@ -227,9 +218,4 @@
   area->_no_handle_mark_nesting = _no_handle_mark_nesting;
 }
 
-bool instanceKlassHandle::is_instanceKlass(const Klass* k) {
-  // Need this to avoid circular include dependency
-  return k->is_instance_klass();
-}
-
 #endif
--- a/hotspot/src/share/vm/runtime/handles.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/handles.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -45,8 +45,7 @@
 // Handles are declared in a straight-forward manner, e.g.
 //
 //   oop obj = ...;
-//   Handle h1(obj);              // allocate new handle
-//   Handle h2(thread, obj);      // faster allocation when current thread is known
+//   Handle h2(thread, obj);      // allocate a new handle in thread
 //   Handle h3;                   // declare handle only, no allocation occurs
 //   ...
 //   h3 = h1;                     // make h3 refer to same indirection as h1
@@ -55,11 +54,7 @@
 //
 // Handles are specialized for different oop types to provide extra type
 // information and avoid unnecessary casting. For each oop type xxxOop
-// there is a corresponding handle called xxxHandle, e.g.
-//
-//   oop           Handle
-//   Method*       methodHandle
-//   instanceOop   instanceHandle
+// there is a corresponding handle called xxxHandle.
 
 //------------------------------------------------------------------------------------------------------------------------
 // Base class for all handles. Provides overloading of frequently
@@ -76,7 +71,6 @@
  public:
   // Constructors
   Handle()                                       { _handle = NULL; }
-  Handle(oop obj);
   Handle(Thread* thread, oop obj);
 
   // General access
@@ -113,10 +107,6 @@
    public:                                       \
     /* Constructors */                           \
     type##Handle ()                              : Handle()                 {} \
-    type##Handle (type##Oop obj) : Handle((oop)obj) {                         \
-      assert(is_null() || ((oop)obj)->is_a(),                                 \
-             "illegal type");                                                 \
-    }                                                                         \
     type##Handle (Thread* thread, type##Oop obj) : Handle(thread, (oop)obj) { \
       assert(is_null() || ((oop)obj)->is_a(), "illegal type");                \
     }                                                                         \
@@ -176,48 +166,6 @@
 DEF_METADATA_HANDLE(method, Method)
 DEF_METADATA_HANDLE(constantPool, ConstantPool)
 
-// Writing this class explicitly, since DEF_METADATA_HANDLE(klass) doesn't
-// provide the necessary Klass* <-> Klass* conversions. This Klass
-// could be removed when we don't have the Klass* typedef anymore.
-class KlassHandle : public StackObj {
-  Klass* _value;
- protected:
-   Klass* obj() const          { return _value; }
-   Klass* non_null_obj() const { assert(_value != NULL, "resolving NULL _value"); return _value; }
-
- public:
-   KlassHandle()                                 : _value(NULL) {}
-   KlassHandle(const Klass* obj)                 : _value(const_cast<Klass *>(obj)) {};
-   KlassHandle(Thread* thread, const Klass* obj) : _value(const_cast<Klass *>(obj)) {};
-
-   Klass* operator () () const { return obj(); }
-   Klass* operator -> () const { return non_null_obj(); }
-
-   bool operator == (Klass* o) const             { return obj() == o; }
-   bool operator == (const KlassHandle& h) const { return obj() == h.obj(); }
-
-    bool is_null() const  { return _value == NULL; }
-    bool not_null() const { return _value != NULL; }
-};
-
-class instanceKlassHandle : public KlassHandle {
- public:
-  /* Constructors */
-  instanceKlassHandle () : KlassHandle() {}
-  instanceKlassHandle (const Klass* k) : KlassHandle(k) {
-    assert(k == NULL || is_instanceKlass(k), "illegal type");
-  }
-  instanceKlassHandle (Thread* thread, const Klass* k) : KlassHandle(thread, k) {
-    assert(k == NULL || is_instanceKlass(k), "illegal type");
-  }
-  /* Access to klass part */
-  InstanceKlass*       operator () () const { return (InstanceKlass*)obj(); }
-  InstanceKlass*       operator -> () const { return (InstanceKlass*)obj(); }
-
-  debug_only(bool is_instanceKlass(const Klass* k));
-};
-
-
 //------------------------------------------------------------------------------------------------------------------------
 // Thread local handle area
 class HandleArea: public Arena {
@@ -277,7 +225,7 @@
 //   Handle h;
 //   {
 //     HandleMark hm;
-//     h = Handle(obj);
+//     h = Handle(THREAD, obj);
 //   }
 //   h()->print();       // WRONG, h destroyed by HandleMark destructor.
 //
--- a/hotspot/src/share/vm/runtime/handles.inline.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/handles.inline.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,16 +31,6 @@
 // these inline functions are in a separate file to break an include cycle
 // between Thread and Handle
 
-inline Handle::Handle(oop obj) {
-  if (obj == NULL) {
-    _handle = NULL;
-  } else {
-    _handle = Thread::current()->handle_area()->allocate_handle(obj);
-  }
-}
-
-
-#ifndef ASSERT
 inline Handle::Handle(Thread* thread, oop obj) {
   assert(thread == Thread::current(), "sanity check");
   if (obj == NULL) {
@@ -49,9 +39,8 @@
     _handle = thread->handle_area()->allocate_handle(obj);
   }
 }
-#endif // ASSERT
 
-// Constructors for metadata handles
+// Constructor for metadata handles
 #define DEF_METADATA_HANDLE_FN(name, type) \
 inline name##Handle::name##Handle(type* obj) : _value(obj), _thread(NULL) {       \
   if (obj != NULL) {                                                   \
--- a/hotspot/src/share/vm/runtime/java.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/java.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -99,9 +99,6 @@
 
 void collect_profiled_methods(Method* m) {
   Thread* thread = Thread::current();
-  // This HandleMark prevents a huge amount of handles from being added
-  // to the metadata_handles() array on the thread.
-  HandleMark hm(thread);
   methodHandle mh(thread, m);
   if ((m->method_data() != NULL) &&
       (PrintMethodData || CompilerOracle::should_print(mh))) {
@@ -722,6 +719,8 @@
     index += rc;
     if (_security > 0) {
       rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _security);
+      if (rc == -1) return;
+      index += rc;
     }
     if (_patch > 0) {
       rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _patch);
--- a/hotspot/src/share/vm/runtime/javaCalls.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/javaCalls.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -179,10 +179,10 @@
 
 // ============ Virtual calls ============
 
-void JavaCalls::call_virtual(JavaValue* result, KlassHandle spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
+void JavaCalls::call_virtual(JavaValue* result, Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
   CallInfo callinfo;
   Handle receiver = args->receiver();
-  KlassHandle recvrKlass(THREAD, receiver.is_null() ? (Klass*)NULL : receiver->klass());
+  Klass* recvrKlass = receiver.is_null() ? (Klass*)NULL : receiver->klass();
   LinkInfo link_info(spec_klass, name, signature);
   LinkResolver::resolve_virtual_call(
           callinfo, receiver, recvrKlass, link_info, true, CHECK);
@@ -194,13 +194,13 @@
 }
 
 
-void JavaCalls::call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, TRAPS) {
+void JavaCalls::call_virtual(JavaValue* result, Handle receiver, Klass* spec_klass, Symbol* name, Symbol* signature, TRAPS) {
   JavaCallArguments args(receiver); // One oop argument
   call_virtual(result, spec_klass, name, signature, &args, CHECK);
 }
 
 
-void JavaCalls::call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
+void JavaCalls::call_virtual(JavaValue* result, Handle receiver, Klass* spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
   JavaCallArguments args(receiver); // One oop argument
   args.push_oop(arg1);
   call_virtual(result, spec_klass, name, signature, &args, CHECK);
@@ -208,7 +208,7 @@
 
 
 
-void JavaCalls::call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
+void JavaCalls::call_virtual(JavaValue* result, Handle receiver, Klass* spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
   JavaCallArguments args(receiver); // One oop argument
   args.push_oop(arg1);
   args.push_oop(arg2);
@@ -218,7 +218,7 @@
 
 // ============ Special calls ============
 
-void JavaCalls::call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
+void JavaCalls::call_special(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
   CallInfo callinfo;
   LinkInfo link_info(klass, name, signature);
   LinkResolver::resolve_special_call(callinfo, link_info, CHECK);
@@ -230,20 +230,20 @@
 }
 
 
-void JavaCalls::call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
+void JavaCalls::call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, TRAPS) {
   JavaCallArguments args(receiver); // One oop argument
   call_special(result, klass, name, signature, &args, CHECK);
 }
 
 
-void JavaCalls::call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
+void JavaCalls::call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
   JavaCallArguments args(receiver); // One oop argument
   args.push_oop(arg1);
   call_special(result, klass, name, signature, &args, CHECK);
 }
 
 
-void JavaCalls::call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
+void JavaCalls::call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
   JavaCallArguments args(receiver); // One oop argument
   args.push_oop(arg1);
   args.push_oop(arg2);
@@ -253,7 +253,7 @@
 
 // ============ Static calls ============
 
-void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
+void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
   CallInfo callinfo;
   LinkInfo link_info(klass, name, signature);
   LinkResolver::resolve_static_call(callinfo, link_info, true, CHECK);
@@ -265,19 +265,19 @@
 }
 
 
-void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
+void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, TRAPS) {
   JavaCallArguments args; // No argument
   call_static(result, klass, name, signature, &args, CHECK);
 }
 
 
-void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
+void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
   JavaCallArguments args(arg1); // One oop argument
   call_static(result, klass, name, signature, &args, CHECK);
 }
 
 
-void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
+void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
   JavaCallArguments args; // One oop argument
   args.push_oop(arg1);
   args.push_oop(arg2);
@@ -285,7 +285,7 @@
 }
 
 
-void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, Handle arg3, TRAPS) {
+void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, Handle arg3, TRAPS) {
   JavaCallArguments args; // One oop argument
   args.push_oop(arg1);
   args.push_oop(arg2);
--- a/hotspot/src/share/vm/runtime/javaCalls.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/javaCalls.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -187,30 +187,30 @@
   // call_special
   // ------------
   // The receiver must be first oop in argument list
-  static void call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
+  static void call_special(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
 
-  static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); // No args
-  static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
-  static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
+  static void call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, TRAPS); // No args
+  static void call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
+  static void call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
 
   // virtual call
   // ------------
 
   // The receiver must be first oop in argument list
-  static void call_virtual(JavaValue* result, KlassHandle spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
+  static void call_virtual(JavaValue* result, Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
 
-  static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, TRAPS); // No args
-  static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
-  static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
+  static void call_virtual(JavaValue* result, Handle receiver, Klass* spec_klass, Symbol* name, Symbol* signature, TRAPS); // No args
+  static void call_virtual(JavaValue* result, Handle receiver, Klass* spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
+  static void call_virtual(JavaValue* result, Handle receiver, Klass* spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
 
   // Static call
   // -----------
-  static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
+  static void call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
 
-  static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
-  static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
-  static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
-  static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, Handle arg3, TRAPS);
+  static void call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, TRAPS);
+  static void call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
+  static void call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
+  static void call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, Handle arg3, TRAPS);
 
   // Low-level interface
   static void call(JavaValue* result, const methodHandle& method, JavaCallArguments* args, TRAPS);
--- a/hotspot/src/share/vm/runtime/jfieldIDWorkaround.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/jfieldIDWorkaround.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -150,13 +150,13 @@
     return result;
   }
 
-  static jfieldID to_jfieldID(instanceKlassHandle k, int offset, bool is_static) {
+  static jfieldID to_jfieldID(InstanceKlass* k, int offset, bool is_static) {
     if (is_static) {
       JNIid *id = k->jni_id_for(offset);
       debug_only(id->set_is_static_field_id());
       return jfieldIDWorkaround::to_static_jfieldID(id);
     } else {
-      return jfieldIDWorkaround::to_instance_jfieldID(k(), offset);
+      return jfieldIDWorkaround::to_instance_jfieldID(k, offset);
     }
   }
 };
--- a/hotspot/src/share/vm/runtime/mutexLocker.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/mutexLocker.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -124,7 +124,7 @@
 Monitor* PeriodicTask_lock            = NULL;
 Monitor* RedefineClasses_lock         = NULL;
 
-#ifdef INCLUDE_TRACE
+#if INCLUDE_TRACE
 Mutex*   JfrStacktrace_lock           = NULL;
 Monitor* JfrMsg_lock                  = NULL;
 Mutex*   JfrBuffer_lock               = NULL;
@@ -276,7 +276,7 @@
     def(Compilation_lock           , PaddedMonitor, leaf,        false, Monitor::_safepoint_check_never);
   }
 
-#ifdef INCLUDE_TRACE
+#if INCLUDE_TRACE
   def(JfrMsg_lock                  , PaddedMonitor, leaf,        true,  Monitor::_safepoint_check_always);
   def(JfrBuffer_lock               , PaddedMutex  , leaf,        true,  Monitor::_safepoint_check_never);
   def(JfrThreadGroups_lock         , PaddedMutex  , leaf,        true,  Monitor::_safepoint_check_always);
--- a/hotspot/src/share/vm/runtime/mutexLocker.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/mutexLocker.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -124,7 +124,7 @@
 extern Monitor* PeriodicTask_lock;               // protects the periodic task structure
 extern Monitor* RedefineClasses_lock;            // locks classes from parallel redefinition
 
-#ifdef INCLUDE_TRACE
+#if INCLUDE_TRACE
 extern Mutex*   JfrStacktrace_lock;              // used to guard access to the JFR stacktrace table
 extern Monitor* JfrMsg_lock;                     // protects JFR messaging
 extern Mutex*   JfrBuffer_lock;                  // protects JFR buffer operations
--- a/hotspot/src/share/vm/runtime/os.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/os.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -291,9 +291,8 @@
       default: {
         // Dispatch the signal to java
         HandleMark hm(THREAD);
-        Klass* k = SystemDictionary::resolve_or_null(vmSymbols::jdk_internal_misc_Signal(), THREAD);
-        KlassHandle klass (THREAD, k);
-        if (klass.not_null()) {
+        Klass* klass = SystemDictionary::resolve_or_null(vmSymbols::jdk_internal_misc_Signal(), THREAD);
+        if (klass != NULL) {
           JavaValue result(T_VOID);
           JavaCallArguments args;
           args.push_int(sig);
@@ -348,13 +347,12 @@
   VM_Version::init_before_ergo();
 }
 
-void os::signal_init() {
+void os::signal_init(TRAPS) {
   if (!ReduceSignalUsage) {
     // Setup JavaThread for processing signals
-    EXCEPTION_MARK;
     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK);
-    instanceKlassHandle klass (THREAD, k);
-    instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
+    InstanceKlass* ik = InstanceKlass::cast(k);
+    instanceHandle thread_oop = ik->allocate_instance_handle(CHECK);
 
     const char thread_name[] = "Signal Dispatcher";
     Handle string = java_lang_String::create_from_str(thread_name, CHECK);
@@ -363,14 +361,14 @@
     Handle thread_group (THREAD, Universe::system_thread_group());
     JavaValue result(T_VOID);
     JavaCalls::call_special(&result, thread_oop,
-                           klass,
+                           ik,
                            vmSymbols::object_initializer_name(),
                            vmSymbols::threadgroup_string_void_signature(),
                            thread_group,
                            string,
                            CHECK);
 
-    KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass());
+    Klass* group = SystemDictionary::ThreadGroup_klass();
     JavaCalls::call_special(&result,
                             thread_group,
                             group,
@@ -650,6 +648,12 @@
     return NULL;
   }
 
+  if (size == 0) {
+    // return a valid pointer if size is zero
+    // if NULL is returned the calling functions assume out of memory.
+    size = 1;
+  }
+
 #ifndef ASSERT
   NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
   NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size));
@@ -670,9 +674,6 @@
   // NMT support
   void* membase = MemTracker::malloc_base(memblock);
   verify_memory(membase);
-  if (size == 0) {
-    return NULL;
-  }
   // always move the block
   void* ptr = os::malloc(size, memflags, stack);
   if (PrintMalloc && tty != NULL) {
--- a/hotspot/src/share/vm/runtime/os.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/os.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -731,7 +731,7 @@
   static struct hostent* get_host_by_name(char* name);
 
   // Support for signals (see JVM_RaiseSignal, JVM_RegisterSignal)
-  static void  signal_init();
+  static void  signal_init(TRAPS);
   static void  signal_init_pd();
   static void  signal_notify(int signal_number);
   static void* signal(int signal_number, void* handler);
--- a/hotspot/src/share/vm/runtime/perfData.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/perfData.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -213,18 +213,9 @@
 }
 
 void PerfLongVariant::sample() {
-
-  // JJJ - This should not happen.  Maybe the first sample is taken
-  // while the _sample_helper is being null'ed out.
-  // assert(_sample_helper != NULL || _sampled != NULL, "unexpected state");
-  if (_sample_helper == NULL) return;
-
   if (_sample_helper != NULL) {
     *(jlong*)_valuep = _sample_helper->take_sample();
   }
-  else if (_sampled != NULL) {
-    *(jlong*)_valuep = *_sampled;
-  }
 }
 
 PerfByteArray::PerfByteArray(CounterNS ns, const char* namep, Units u,
--- a/hotspot/src/share/vm/runtime/reflection.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/reflection.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -477,7 +477,7 @@
  Note: a loose module is a module that can read all current and future unnamed modules.
 */
 Reflection::VerifyClassAccessResults Reflection::verify_class_access(
-  const Klass* current_class, const Klass* new_class, bool classloader_only) {
+  const Klass* current_class, const InstanceKlass* new_class, bool classloader_only) {
 
   // Verify that current_class can access new_class.  If the classloader_only
   // flag is set, we automatically allow any accesses in which current_class
@@ -504,13 +504,6 @@
     // Find the module entry for current_class, the accessor
     ModuleEntry* module_from = current_class->module();
     // Find the module entry for new_class, the accessee
-    if (new_class->is_objArray_klass()) {
-      new_class = ObjArrayKlass::cast(new_class)->bottom_klass();
-    }
-    if (new_class->is_typeArray_klass()) {
-      // A TypeArray's defining module is java.base, access to the TypeArray is allowed
-      return ACCESS_OK;
-    }
     ModuleEntry* module_to = new_class->module();
 
     // both in same (possibly unnamed) module
@@ -567,7 +560,7 @@
 // Return an error message specific to the specified Klass*'s and result.
 // This function must be called from within a block containing a ResourceMark.
 char* Reflection::verify_class_access_msg(const Klass* current_class,
-                                          const Klass* new_class,
+                                          const InstanceKlass* new_class,
                                           VerifyClassAccessResults result) {
   assert(result != ACCESS_OK, "must be failure result");
   char * msg = NULL;
@@ -715,7 +708,7 @@
 // If inner_is_member, require the inner to be a member of the outer.
 // If !inner_is_member, require the inner to be anonymous (a non-member).
 // Caller is responsible for figuring out in advance which case must be true.
-void Reflection::check_for_inner_class(instanceKlassHandle outer, instanceKlassHandle inner,
+void Reflection::check_for_inner_class(const InstanceKlass* outer, const InstanceKlass* inner,
                                        bool inner_is_member, TRAPS) {
   InnerClassesIterator iter(outer);
   constantPoolHandle cp   (THREAD, outer->constants());
@@ -725,9 +718,9 @@
 
      if (inner_is_member && ioff != 0 && ooff != 0) {
         Klass* o = cp->klass_at(ooff, CHECK);
-        if (o == outer()) {
+        if (o == outer) {
           Klass* i = cp->klass_at(ioff, CHECK);
-          if (i == inner()) {
+          if (i == inner) {
             return;
           }
         }
@@ -735,7 +728,7 @@
      if (!inner_is_member && ioff != 0 && ooff == 0 &&
          cp->klass_name_at_matches(inner, ioff)) {
         Klass* i = cp->klass_at(ioff, CHECK);
-        if (i == inner()) {
+        if (i == inner) {
           return;
         }
      }
@@ -809,7 +802,7 @@
   return method->resolved_checked_exceptions(THREAD);
 }
 
-static Handle new_type(Symbol* signature, KlassHandle k, TRAPS) {
+static Handle new_type(Symbol* signature, Klass* k, TRAPS) {
   // Basic types
   BasicType type = vmSymbols::signature_type(signature);
   if (type != T_OBJECT) {
@@ -836,7 +829,7 @@
   assert(!method()->is_initializer() ||
          (for_constant_pool_access && method()->is_static()),
          "should call new_constructor instead");
-  instanceKlassHandle holder (THREAD, method->method_holder());
+  InstanceKlass* holder = method->method_holder();
   int slot = method->method_idnum();
 
   Symbol*  signature  = method->signature();
@@ -897,7 +890,7 @@
 oop Reflection::new_constructor(const methodHandle& method, TRAPS) {
   assert(method()->is_initializer(), "should call new_method instead");
 
-  instanceKlassHandle  holder (THREAD, method->method_holder());
+  InstanceKlass* holder = method->method_holder();
   int slot = method->method_idnum();
 
   Symbol*  signature  = method->signature();
@@ -945,7 +938,7 @@
   oop name_oop = StringTable::intern(field_name, CHECK_NULL);
   Handle name = Handle(THREAD, name_oop);
   Symbol*  signature  = fd->signature();
-  instanceKlassHandle  holder    (THREAD, fd->field_holder());
+  InstanceKlass* holder = fd->field_holder();
   Handle type = new_type(signature, holder, CHECK_NULL);
   Handle rh  = java_lang_reflect_Field::create(CHECK_NULL);
 
@@ -992,9 +985,9 @@
 }
 
 
-static methodHandle resolve_interface_call(instanceKlassHandle klass,
+static methodHandle resolve_interface_call(InstanceKlass* klass,
                                            const methodHandle& method,
-                                           KlassHandle recv_klass,
+                                           Klass* recv_klass,
                                            Handle receiver,
                                            TRAPS) {
 
@@ -1042,7 +1035,7 @@
 
 
 // Method call (shared by invoke_method and invoke_constructor)
-static oop invoke(instanceKlassHandle klass,
+static oop invoke(InstanceKlass* klass,
                   methodHandle reflected_method,
                   Handle receiver,
                   bool override,
@@ -1055,7 +1048,7 @@
   ResourceMark rm(THREAD);
 
   methodHandle method;      // actual method to invoke
-  KlassHandle target_klass; // target klass, receiver's klass for non-static
+  Klass* target_klass;      // target klass, receiver's klass for non-static
 
   // Ensure klass is initialized
   klass->initialize(CHECK_NULL);
@@ -1071,11 +1064,11 @@
       THROW_0(vmSymbols::java_lang_NullPointerException());
     }
     // Check class of receiver against class declaring method
-    if (!receiver->is_a(klass())) {
+    if (!receiver->is_a(klass)) {
       THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "object is not an instance of declaring class");
     }
     // target klass is receiver's klass
-    target_klass = KlassHandle(THREAD, receiver->klass());
+    target_klass = receiver->klass();
     // no need to resolve if method is private or <init>
     if (reflected_method->is_private() || reflected_method->name() == vmSymbols::object_initializer_name()) {
       method = reflected_method;
@@ -1116,7 +1109,7 @@
             ResourceMark rm(THREAD);
             Handle h_origexception = Exceptions::new_exception(THREAD,
               vmSymbols::java_lang_AbstractMethodError(),
-              Method::name_and_sig_as_C_string(target_klass(),
+              Method::name_and_sig_as_C_string(target_klass,
               method->name(),
               method->signature()));
             JavaCallArguments args(h_origexception);
@@ -1134,7 +1127,7 @@
   if (method.is_null()) {
     ResourceMark rm(THREAD);
     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(),
-                Method::name_and_sig_as_C_string(klass(),
+                Method::name_and_sig_as_C_string(klass,
                 reflected_method->name(),
                 reflected_method->signature()));
   }
@@ -1236,7 +1229,7 @@
     rtype = T_OBJECT;
   }
 
-  instanceKlassHandle klass(THREAD, java_lang_Class::as_Klass(mirror));
+  InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
   Method* m = klass->method_with_idnum(slot);
   if (m == NULL) {
     THROW_MSG_0(vmSymbols::java_lang_InternalError(), "invoke");
@@ -1253,7 +1246,7 @@
   bool override          = java_lang_reflect_Constructor::override(constructor_mirror) != 0;
   objArrayHandle ptypes(THREAD, objArrayOop(java_lang_reflect_Constructor::parameter_types(constructor_mirror)));
 
-  instanceKlassHandle klass(THREAD, java_lang_Class::as_Klass(mirror));
+  InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
   Method* m = klass->method_with_idnum(slot);
   if (m == NULL) {
     THROW_MSG_0(vmSymbols::java_lang_InternalError(), "invoke");
--- a/hotspot/src/share/vm/runtime/reflection.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/reflection.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -82,12 +82,12 @@
 
   // Verification
   static VerifyClassAccessResults verify_class_access(const Klass* current_class,
-                                                      const Klass* new_class,
+                                                      const InstanceKlass* new_class,
                                                       bool classloader_only);
   // Return an error message specific to the specified Klass*'s and result.
   // This function must be called from within a block containing a ResourceMark.
   static char*    verify_class_access_msg(const Klass* current_class,
-                                          const Klass* new_class,
+                                          const InstanceKlass* new_class,
                                           const VerifyClassAccessResults result);
 
   static bool     verify_field_access(const Klass* current_class,
@@ -103,8 +103,8 @@
   // If inner_is_member, require the inner to be a member of the outer.
   // If !inner_is_member, require the inner to be anonymous (a non-member).
   // Caller is responsible for figuring out in advance which case must be true.
-  static void check_for_inner_class(instanceKlassHandle outer,
-                                    instanceKlassHandle inner,
+  static void check_for_inner_class(const InstanceKlass* outer,
+                                    const InstanceKlass* inner,
                                     bool inner_is_member,
                                     TRAPS);
 
--- a/hotspot/src/share/vm/runtime/reflectionUtils.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/reflectionUtils.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,7 @@
 #include "memory/universe.inline.hpp"
 #include "runtime/reflectionUtils.hpp"
 
-KlassStream::KlassStream(instanceKlassHandle klass, bool local_only,
+KlassStream::KlassStream(InstanceKlass* klass, bool local_only,
                          bool classes_only, bool walk_defaults) {
   _klass = _base_klass = klass;
   _base_class_search_defaults = false;
@@ -48,7 +48,7 @@
   if (_local_only) return true;
   if (!_klass->is_interface() && _klass->super() != NULL) {
     // go up superclass chain (not for interfaces)
-    _klass = _klass->super();
+    _klass = InstanceKlass::cast(_klass->super());
   // Next for method walks, walk default methods
   } else if (_walk_defaults && (_defaults_checked == false)  && (_base_klass->default_methods() != NULL)) {
       _base_class_search_defaults = true;
@@ -57,7 +57,7 @@
   } else {
     // Next walk transitive interfaces
     if (_interface_index > 0) {
-      _klass = _interfaces->at(--_interface_index);
+      _klass = InstanceKlass::cast(_interfaces->at(--_interface_index));
     } else {
       return true;
     }
--- a/hotspot/src/share/vm/runtime/reflectionUtils.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/reflectionUtils.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -45,8 +45,8 @@
 
 class KlassStream VALUE_OBJ_CLASS_SPEC {
  protected:
-  instanceKlassHandle _klass;           // current klass/interface iterated over
-  instanceKlassHandle _base_klass;      // initial klass/interface to iterate over
+  InstanceKlass*      _klass;           // current klass/interface iterated over
+  InstanceKlass*      _base_klass;      // initial klass/interface to iterate over
   Array<Klass*>*      _interfaces;      // transitive interfaces for initial class
   int                 _interface_index; // current interface being processed
   bool                _local_only;      // process initial class/interface only
@@ -60,7 +60,7 @@
 
  public:
   // constructor
-  KlassStream(instanceKlassHandle klass, bool local_only, bool classes_only, bool walk_defaults);
+  KlassStream(InstanceKlass* klass, bool local_only, bool classes_only, bool walk_defaults);
 
   // testing
   bool eos();
@@ -69,7 +69,7 @@
   virtual void next() = 0;
 
   // accessors
-  instanceKlassHandle klass() const { return _klass; }
+  InstanceKlass* klass() const      { return _klass; }
   int index() const                 { return _index; }
   bool base_class_search_defaults() const { return _base_class_search_defaults; }
   void base_class_search_defaults(bool b) { _base_class_search_defaults = b; }
@@ -97,7 +97,7 @@
     }
   }
  public:
-  MethodStream(instanceKlassHandle klass, bool local_only, bool classes_only)
+  MethodStream(InstanceKlass* klass, bool local_only, bool classes_only)
     : KlassStream(klass, local_only, classes_only, true) {
     _index = length();
     next();
@@ -125,7 +125,7 @@
   fieldDescriptor _fd_buf;
 
  public:
-  FieldStream(instanceKlassHandle klass, bool local_only, bool classes_only)
+  FieldStream(InstanceKlass* klass, bool local_only, bool classes_only)
     : KlassStream(klass, local_only, classes_only, false) {
     _index = length();
     next();
@@ -152,7 +152,7 @@
   // bridge to a heavier API:
   fieldDescriptor& field_descriptor() const {
     fieldDescriptor& field = const_cast<fieldDescriptor&>(_fd_buf);
-    field.reinitialize(_klass(), _index);
+    field.reinitialize(_klass, _index);
     return field;
   }
 };
@@ -222,15 +222,15 @@
   bool has_filtered_field() { return (_filtered_fields_count > 0); }
 
  public:
-  FilteredFieldStream(instanceKlassHandle klass, bool local_only, bool classes_only)
+  FilteredFieldStream(InstanceKlass* klass, bool local_only, bool classes_only)
     : FieldStream(klass, local_only, classes_only) {
-    _filtered_fields_count = FilteredFieldsMap::filtered_fields_count((Klass*)klass(), local_only);
+    _filtered_fields_count = FilteredFieldsMap::filtered_fields_count(klass, local_only);
   }
   int field_count();
   void next() {
     _index -= 1;
     if (has_filtered_field()) {
-      while (_index >=0 && FilteredFieldsMap::is_filtered_field((Klass*)_klass(), offset())) {
+      while (_index >=0 && FilteredFieldsMap::is_filtered_field((Klass*)_klass, offset())) {
         _index -= 1;
       }
     }
--- a/hotspot/src/share/vm/runtime/serviceThread.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/serviceThread.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@
 void ServiceThread::initialize() {
   EXCEPTION_MARK;
 
-  instanceKlassHandle klass (THREAD,  SystemDictionary::Thread_klass());
+  InstanceKlass* klass = SystemDictionary::Thread_klass();
   instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
 
   const char* name = "Service Thread";
--- a/hotspot/src/share/vm/runtime/sharedRuntime.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/sharedRuntime.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -675,7 +675,7 @@
     do {
       bool skip_scope_increment = false;
       // exception handler lookup
-      KlassHandle ek (THREAD, exception->klass());
+      Klass* ek = exception->klass();
       methodHandle mh(THREAD, sd->method());
       handler_bci = Method::fast_exception_handler_bci_for(mh, ek, bci, THREAD);
       if (HAS_PENDING_EXCEPTION) {
@@ -1185,7 +1185,7 @@
   // Check that the receiver klass is of the right subtype and that it is initialized for virtual calls
   if (has_receiver) {
     assert(receiver.not_null(), "should have thrown exception");
-    KlassHandle receiver_klass(THREAD, receiver->klass());
+    Klass* receiver_klass = receiver->klass();
     Klass* rk = NULL;
     if (attached_method.not_null()) {
       // In case there's resolved method attached, use its holder during the check.
@@ -1195,16 +1195,16 @@
       constantPoolHandle constants(THREAD, caller->constants());
       rk = constants->klass_ref_at(bytecode_index, CHECK_NH);
     }
-    KlassHandle static_receiver_klass(THREAD, rk);
+    Klass* static_receiver_klass = rk;
     methodHandle callee = callinfo.selected_method();
-    assert(receiver_klass->is_subtype_of(static_receiver_klass()),
+    assert(receiver_klass->is_subtype_of(static_receiver_klass),
            "actual receiver must be subclass of static receiver klass");
     if (receiver_klass->is_instance_klass()) {
-      if (InstanceKlass::cast(receiver_klass())->is_not_initialized()) {
+      if (InstanceKlass::cast(receiver_klass)->is_not_initialized()) {
         tty->print_cr("ERROR: Klass not yet initialized!!");
-        receiver_klass()->print();
+        receiver_klass->print();
       }
-      assert(!InstanceKlass::cast(receiver_klass())->is_not_initialized(), "receiver_klass must be initialized");
+      assert(!InstanceKlass::cast(receiver_klass)->is_not_initialized(), "receiver_klass must be initialized");
     }
   }
 #endif
@@ -1363,8 +1363,8 @@
   if (is_virtual) {
     assert(receiver.not_null() || invoke_code == Bytecodes::_invokehandle, "sanity check");
     bool static_bound = call_info.resolved_method()->can_be_statically_bound();
-    KlassHandle h_klass(THREAD, invoke_code == Bytecodes::_invokehandle ? NULL : receiver->klass());
-    CompiledIC::compute_monomorphic_entry(callee_method, h_klass,
+    Klass* klass = invoke_code == Bytecodes::_invokehandle ? NULL : receiver->klass();
+    CompiledIC::compute_monomorphic_entry(callee_method, klass,
                      is_optimized, static_bound, is_nmethod, virtual_call_info,
                      CHECK_(methodHandle()));
   } else {
@@ -1625,7 +1625,7 @@
         // and now we have (or had) a compiled entry. We correct the IC
         // by using a new icBuffer.
         CompiledICInfo info;
-        KlassHandle receiver_klass(THREAD, receiver()->klass());
+        Klass* receiver_klass = receiver()->klass();
         inline_cache->compute_monomorphic_entry(callee_method,
                                                 receiver_klass,
                                                 inline_cache->is_optimized(),
@@ -2891,9 +2891,11 @@
 
   // Install the generated code.
   if (nm != NULL) {
+    const char *msg = method->is_static() ? "(static)" : "";
+    CompileTask::print_ul(nm, msg);
     if (PrintCompilation) {
       ttyLocker ttyl;
-      CompileTask::print(tty, nm, method->is_static() ? "(static)" : "");
+      CompileTask::print(tty, nm, msg);
     }
     nm->post_compiled_method_load_event();
   }
--- a/hotspot/src/share/vm/runtime/stackValue.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/stackValue.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -103,7 +103,7 @@
         value.noop = *(narrowOop*) value_addr;
       }
       // Decode narrowoop and wrap a handle around the oop
-      Handle h(oopDesc::decode_heap_oop(value.noop));
+      Handle h(Thread::current(), oopDesc::decode_heap_oop(value.noop));
       return new StackValue(h);
     }
 #endif
@@ -118,7 +118,7 @@
          val = (oop)NULL;
       }
 #endif
-      Handle h(val); // Wrap a handle around the oop
+      Handle h(Thread::current(), val); // Wrap a handle around the oop
       return new StackValue(h);
     }
     case Location::addr: {
--- a/hotspot/src/share/vm/runtime/statSampler.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/statSampler.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -187,7 +187,7 @@
 
   // public static String getProperty(String key, String def);
   JavaCalls::call_static(&result,
-                         KlassHandle(THREAD, SystemDictionary::System_klass()),
+                         SystemDictionary::System_klass(),
                          vmSymbols::getProperty_name(),
                          vmSymbols::string_string_signature(),
                          key_str,
--- a/hotspot/src/share/vm/runtime/sweeper.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/sweeper.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -403,6 +403,8 @@
   ResourceMark rm;
   Ticks sweep_start_counter = Ticks::now();
 
+  log_debug(codecache, sweep, start)("CodeCache flushing");
+
   int flushed_count                = 0;
   int zombified_count              = 0;
   int flushed_c2_count     = 0;
@@ -500,6 +502,10 @@
   }
 #endif
 
+  Log(codecache, sweep) log;
+  if (log.is_debug()) {
+    CodeCache::print_summary(log.debug_stream(), false);
+  }
   log_sweep("finished");
 
   // Sweeper is the only case where memory is released, check here if it
@@ -513,6 +519,7 @@
   // cache. As a result, 'freed_memory' > 0 to restart the compiler.
   if (!CompileBroker::should_compile_new_jobs() && (freed_memory > 0)) {
     CompileBroker::set_should_compile_new_jobs(CompileBroker::run_compilation);
+    log.debug("restart compiler");
     log_sweep("restart_compiler");
   }
 }
--- a/hotspot/src/share/vm/runtime/synchronizer.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/synchronizer.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1762,7 +1762,7 @@
     if (mid->owner() == THREAD) {
       if (ObjectMonitor::Knob_VerifyMatch != 0) {
         ResourceMark rm;
-        Handle obj((oop) mid->object());
+        Handle obj(THREAD, (oop) mid->object());
         tty->print("INFO: unexpected locked object:");
         javaVFrame::print_locked_object_class_name(tty, obj, "locked");
         fatal("exiting JavaThread=" INTPTR_FORMAT
--- a/hotspot/src/share/vm/runtime/thread.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/thread.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -950,27 +950,27 @@
 // Creates the initial ThreadGroup
 static Handle create_initial_thread_group(TRAPS) {
   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ThreadGroup(), true, CHECK_NH);
-  instanceKlassHandle klass (THREAD, k);
-
-  Handle system_instance = klass->allocate_instance_handle(CHECK_NH);
+  InstanceKlass* ik = InstanceKlass::cast(k);
+
+  Handle system_instance = ik->allocate_instance_handle(CHECK_NH);
   {
     JavaValue result(T_VOID);
     JavaCalls::call_special(&result,
                             system_instance,
-                            klass,
+                            ik,
                             vmSymbols::object_initializer_name(),
                             vmSymbols::void_method_signature(),
                             CHECK_NH);
   }
   Universe::set_system_thread_group(system_instance());
 
-  Handle main_instance = klass->allocate_instance_handle(CHECK_NH);
+  Handle main_instance = ik->allocate_instance_handle(CHECK_NH);
   {
     JavaValue result(T_VOID);
     Handle string = java_lang_String::create_from_str("main", CHECK_NH);
     JavaCalls::call_special(&result,
                             main_instance,
-                            klass,
+                            ik,
                             vmSymbols::object_initializer_name(),
                             vmSymbols::threadgroup_string_void_signature(),
                             system_instance,
@@ -984,8 +984,8 @@
 static oop create_initial_thread(Handle thread_group, JavaThread* thread,
                                  TRAPS) {
   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK_NULL);
-  instanceKlassHandle klass (THREAD, k);
-  instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL);
+  InstanceKlass* ik = InstanceKlass::cast(k);
+  instanceHandle thread_oop = ik->allocate_instance_handle(CHECK_NULL);
 
   java_lang_Thread::set_thread(thread_oop(), thread);
   java_lang_Thread::set_priority(thread_oop(), NormPriority);
@@ -995,7 +995,7 @@
 
   JavaValue result(T_VOID);
   JavaCalls::call_special(&result, thread_oop,
-                          klass,
+                          ik,
                           vmSymbols::object_initializer_name(),
                           vmSymbols::threadgroup_string_void_signature(),
                           thread_group,
@@ -1054,9 +1054,8 @@
 // General purpose hook into Java code, run once when the VM is initialized.
 // The Java library method itself may be changed independently from the VM.
 static void call_postVMInitHook(TRAPS) {
-  Klass* k = SystemDictionary::resolve_or_null(vmSymbols::jdk_internal_vm_PostVMInitHook(), THREAD);
-  instanceKlassHandle klass (THREAD, k);
-  if (klass.not_null()) {
+  Klass* klass = SystemDictionary::resolve_or_null(vmSymbols::jdk_internal_vm_PostVMInitHook(), THREAD);
+  if (klass != NULL) {
     JavaValue result(T_VOID);
     JavaCalls::call_static(&result, klass, vmSymbols::run_method_name(),
                            vmSymbols::void_method_signature(),
@@ -1070,8 +1069,7 @@
   const char *vm_info = VM_Version::vm_info_string();
 
   // java.lang.System class
-  Klass* k =  SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
-  instanceKlassHandle klass (THREAD, k);
+  Klass* klass =  SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
 
   // setProperty arguments
   Handle key_str    = java_lang_String::create_from_str("java.vm.info", CHECK);
@@ -1097,8 +1095,8 @@
   assert(threadObj() == NULL, "should only create Java thread object once");
 
   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK);
-  instanceKlassHandle klass (THREAD, k);
-  instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
+  InstanceKlass* ik = InstanceKlass::cast(k);
+  instanceHandle thread_oop = ik->allocate_instance_handle(CHECK);
 
   java_lang_Thread::set_thread(thread_oop(), this);
   java_lang_Thread::set_priority(thread_oop(), NormPriority);
@@ -1110,7 +1108,7 @@
     // Thread gets assigned specified name and null target
     JavaCalls::call_special(&result,
                             thread_oop,
-                            klass,
+                            ik,
                             vmSymbols::object_initializer_name(),
                             vmSymbols::threadgroup_string_void_signature(),
                             thread_group, // Argument 1
@@ -1121,7 +1119,7 @@
     // (java.lang.Thread doesn't have a constructor taking only a ThreadGroup argument)
     JavaCalls::call_special(&result,
                             thread_oop,
-                            klass,
+                            ik,
                             vmSymbols::object_initializer_name(),
                             vmSymbols::threadgroup_runnable_void_signature(),
                             thread_group, // Argument 1
@@ -1138,7 +1136,7 @@
     return;
   }
 
-  KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass());
+  Klass* group =  SystemDictionary::ThreadGroup_klass();
   Handle threadObj(THREAD, this->threadObj());
 
   JavaCalls::call_special(&result,
@@ -1289,28 +1287,32 @@
     if (is_error_reported()) {
       // A fatal error has happened, the error handler(VMError::report_and_die)
       // should abort JVM after creating an error log file. However in some
-      // rare cases, the error handler itself might deadlock. Here we try to
-      // kill JVM if the fatal error handler fails to abort in 2 minutes.
-      //
+      // rare cases, the error handler itself might deadlock. Here periodically
+      // check for error reporting timeouts, and if it happens, just proceed to
+      // abort the VM.
+
       // This code is in WatcherThread because WatcherThread wakes up
       // periodically so the fatal error handler doesn't need to do anything;
       // also because the WatcherThread is less likely to crash than other
       // threads.
 
       for (;;) {
-        if (!ShowMessageBoxOnError
-            && (OnError == NULL || OnError[0] == '\0')
-            && Arguments::abort_hook() == NULL) {
-          os::sleep(this, (jlong)ErrorLogTimeout * 1000, false); // in seconds
+        // Note: we use naked sleep in this loop because we want to avoid using
+        // any kind of VM infrastructure which may be broken at this point.
+        if (VMError::check_timeout()) {
+          // We hit error reporting timeout. Error reporting was interrupted and
+          // will be wrapping things up now (closing files etc). Give it some more
+          // time, then quit the VM.
+          os::naked_short_sleep(200);
+          // Print a message to stderr.
           fdStream err(defaultStream::output_fd());
           err.print_raw_cr("# [ timer expired, abort... ]");
           // skip atexit/vm_exit/vm_abort hooks
           os::die();
         }
 
-        // Wake up 5 seconds later, the fatal handler may reset OnError or
-        // ShowMessageBoxOnError when it is ready to abort.
-        os::sleep(this, 5 * 1000, false);
+        // Wait a second, then recheck for timeout.
+        os::naked_short_sleep(999);
       }
     }
 
@@ -1775,7 +1777,7 @@
     if (uncaught_exception.not_null()) {
       EXCEPTION_MARK;
       // Call method Thread.dispatchUncaughtException().
-      KlassHandle thread_klass(THREAD, SystemDictionary::Thread_klass());
+      Klass* thread_klass = SystemDictionary::Thread_klass();
       JavaValue result(T_VOID);
       JavaCalls::call_virtual(&result,
                               threadObj, thread_klass,
@@ -1813,7 +1815,7 @@
       while (java_lang_Thread::threadGroup(threadObj()) != NULL && (count-- > 0)) {
         EXCEPTION_MARK;
         JavaValue result(T_VOID);
-        KlassHandle thread_klass(THREAD, SystemDictionary::Thread_klass());
+        Klass* thread_klass = SystemDictionary::Thread_klass();
         JavaCalls::call_virtual(&result,
                                 threadObj, thread_klass,
                                 vmSymbols::exit_method_name(),
@@ -3384,9 +3386,7 @@
 //     fields in, out, and err. Set up java signal handlers, OS-specific
 //     system settings, and thread group of the main thread.
 static void call_initPhase1(TRAPS) {
-  Klass* k =  SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
-  instanceKlassHandle klass (THREAD, k);
-
+  Klass* klass =  SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
   JavaValue result(T_VOID);
   JavaCalls::call_static(&result, klass, vmSymbols::initPhase1_name(),
                                          vmSymbols::void_method_signature(), CHECK);
@@ -3406,8 +3406,7 @@
 static void call_initPhase2(TRAPS) {
   TraceTime timer("Phase2 initialization", TRACETIME_LOG(Info, modules, startuptime));
 
-  Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
-  instanceKlassHandle klass (THREAD, k);
+  Klass* klass = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
 
   JavaValue result(T_VOID);
   JavaCalls::call_static(&result, klass, vmSymbols::initPhase2_name(),
@@ -3422,9 +3421,7 @@
 //     and system class loader may be a custom class loaded from -Xbootclasspath/a,
 //     other modules or the application's classpath.
 static void call_initPhase3(TRAPS) {
-  Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
-  instanceKlassHandle klass (THREAD, k);
-
+  Klass* klass = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
   JavaValue result(T_VOID);
   JavaCalls::call_static(&result, klass, vmSymbols::initPhase3_name(),
                                          vmSymbols::void_method_signature(), CHECK);
@@ -3717,7 +3714,7 @@
 #endif // INCLUDE_MANAGEMENT
 
   // Signal Dispatcher needs to be started before VMInit event is posted
-  os::signal_init();
+  os::signal_init(CHECK_JNI_ERR);
 
   // Start Attach Listener if +StartAttachListener or it can't be started lazily
   if (!DisableAttachMechanism) {
@@ -4060,10 +4057,10 @@
   }
 
   EXCEPTION_MARK;
-  Klass* k =
+  Klass* shutdown_klass =
     SystemDictionary::resolve_or_null(vmSymbols::java_lang_Shutdown(),
                                       THREAD);
-  if (k != NULL) {
+  if (shutdown_klass != NULL) {
     // SystemDictionary::resolve_or_null will return null if there was
     // an exception.  If we cannot load the Shutdown class, just don't
     // call Shutdown.shutdown() at all.  This will mean the shutdown hooks
@@ -4071,7 +4068,6 @@
     // Note that if a shutdown hook was registered or runFinalizersOnExit
     // was called, the Shutdown class would have already been loaded
     // (Runtime.addShutdownHook and runFinalizersOnExit will load it).
-    instanceKlassHandle shutdown_klass (THREAD, k);
     JavaValue result(T_VOID);
     JavaCalls::call_static(&result,
                            shutdown_klass,
--- a/hotspot/src/share/vm/runtime/vframe.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/vframe.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -155,7 +155,8 @@
 }
 
 void javaVFrame::print_lock_info_on(outputStream* st, int frame_count) {
-  ResourceMark rm;
+  Thread* THREAD = Thread::current();
+  ResourceMark rm(THREAD);
 
   // If this is the first frame and it is java.lang.Object.wait(...)
   // then print out the receiver. Locals are not always available,
@@ -201,8 +202,8 @@
           // format below for lockbits matches this one.
           st->print("\t- eliminated <owner is scalar replaced> (a %s)", k->external_name());
         } else {
-          oop obj = monitor->owner();
-          if (obj != NULL) {
+          Handle obj(THREAD, monitor->owner());
+          if (obj() != NULL) {
             print_locked_object_class_name(st, obj, "eliminated");
           }
         }
@@ -252,7 +253,7 @@
             mark = NULL;
           }
         }
-        print_locked_object_class_name(st, monitor->owner(), lock_state);
+        print_locked_object_class_name(st, Handle(THREAD, monitor->owner()), lock_state);
         if (ObjectMonitor::Knob_Verbose && mark != NULL) {
           st->print("\t- lockbits=");
           mark->print_on(st);
@@ -309,7 +310,7 @@
   // categorize using oop_mask
   if (oop_mask.is_oop(index)) {
     // reference (oop) "r"
-    Handle h(addr != NULL ? (*(oop*)addr) : (oop)NULL);
+    Handle h(Thread::current(), addr != NULL ? (*(oop*)addr) : (oop)NULL);
     return new StackValue(h);
   }
   // value (integer) "v"
@@ -520,14 +521,14 @@
 
   int    method_prefix_count = 0;
   char** method_prefixes = JvmtiExport::get_all_native_method_prefixes(&method_prefix_count);
-  KlassHandle prefixed_klass(method()->method_holder());
+  Klass* prefixed_klass = method()->method_holder();
   const char* prefixed_name = method()->name()->as_C_string();
   size_t prefixed_name_len = strlen(prefixed_name);
   int prefix_index = method_prefix_count-1;
 
   while (!at_end()) {
     next();
-    if (method()->method_holder() != prefixed_klass()) {
+    if (method()->method_holder() != prefixed_klass) {
       break; // classes don't match, can't be a wrapper
     }
     const char* name = method()->name()->as_C_string();
--- a/hotspot/src/share/vm/runtime/vframe_hp.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/vframe_hp.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -106,7 +106,7 @@
         break;
       case T_OBJECT:
         {
-          Handle obj((oop)val->value().l);
+          Handle obj(Thread::current(), (oop)val->value().l);
           result->set_obj_at(val->index(), obj);
         }
         break;
@@ -227,7 +227,7 @@
       // Put klass for scalar replaced object.
       ScopeValue* kv = ((ObjectValue *)ov)->klass();
       assert(kv->is_constant_oop(), "klass should be oop constant for scalar replaced object");
-      Handle k(((ConstantOopReadValue*)kv)->value()());
+      Handle k(Thread::current(), ((ConstantOopReadValue*)kv)->value()());
       assert(java_lang_Class::is_instance(k()), "must be");
       result->push(new MonitorInfo(k(), resolve_monitor_lock(mv->basic_lock()),
                                    mv->eliminated(), true));
--- a/hotspot/src/share/vm/runtime/vmStructs.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/vmStructs.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -194,9 +194,9 @@
 typedef Hashtable<Symbol*, mtSymbol>          SymbolHashtable;
 typedef HashtableEntry<Symbol*, mtClass>      SymbolHashtableEntry;
 typedef Hashtable<oop, mtSymbol>              StringHashtable;
-typedef TwoOopHashtable<Klass*, mtClass>      KlassTwoOopHashtable;
-typedef Hashtable<Klass*, mtClass>            KlassHashtable;
-typedef HashtableEntry<Klass*, mtClass>       KlassHashtableEntry;
+typedef TwoOopHashtable<InstanceKlass*, mtClass> KlassTwoOopHashtable;
+typedef Hashtable<InstanceKlass*, mtClass>       KlassHashtable;
+typedef HashtableEntry<InstanceKlass*, mtClass>  KlassHashtableEntry;
 typedef TwoOopHashtable<Symbol*, mtClass>     SymbolTwoOopHashtable;
 typedef CompactHashtable<Symbol*, char>       SymbolCompactHashTable;
 
--- a/hotspot/src/share/vm/runtime/vm_operations.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/runtime/vm_operations.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -292,7 +292,7 @@
 #ifndef PRODUCT
 class VM_DeoptimizeAll: public VM_Operation {
  private:
-  KlassHandle _dependee;
+  Klass* _dependee;
  public:
   VM_DeoptimizeAll() {}
   VMOp_Type type() const                         { return VMOp_DeoptimizeAll; }
--- a/hotspot/src/share/vm/services/attachListener.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/attachListener.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -46,13 +46,13 @@
 // Invokes VMSupport.serializePropertiesToByteArray to serialize
 // the system properties into a byte array.
 
-static Klass* load_and_initialize_klass(Symbol* sh, TRAPS) {
+static InstanceKlass* load_and_initialize_klass(Symbol* sh, TRAPS) {
   Klass* k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL);
-  instanceKlassHandle ik (THREAD, k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
   if (ik->should_be_initialized()) {
     ik->initialize(CHECK_NULL);
   }
-  return ik();
+  return ik;
 }
 
 static jint get_properties(AttachOperation* op, outputStream* out, Symbol* serializePropertiesMethod) {
@@ -61,13 +61,12 @@
 
   // load VMSupport
   Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport();
-  Klass* k = load_and_initialize_klass(klass, THREAD);
+  InstanceKlass* k = load_and_initialize_klass(klass, THREAD);
   if (HAS_PENDING_EXCEPTION) {
     java_lang_Throwable::print(PENDING_EXCEPTION, out);
     CLEAR_PENDING_EXCEPTION;
     return JNI_ERR;
   }
-  instanceKlassHandle ik(THREAD, k);
 
   // invoke the serializePropertiesToByteArray method
   JavaValue result(T_OBJECT);
@@ -76,11 +75,11 @@
 
   Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature();
   JavaCalls::call_static(&result,
-                           ik,
-                           serializePropertiesMethod,
-                           signature,
-                           &args,
-                           THREAD);
+                         k,
+                         serializePropertiesMethod,
+                         signature,
+                         &args,
+                         THREAD);
   if (HAS_PENDING_EXCEPTION) {
     java_lang_Throwable::print(PENDING_EXCEPTION, out);
     CLEAR_PENDING_EXCEPTION;
@@ -374,7 +373,7 @@
     return;
   }
 
-  instanceKlassHandle klass (THREAD, k);
+  InstanceKlass* klass = InstanceKlass::cast(k);
   instanceHandle thread_oop = klass->allocate_instance_handle(THREAD);
   if (has_init_error(THREAD)) {
     return;
@@ -401,7 +400,7 @@
     return;
   }
 
-  KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass());
+  Klass* group = SystemDictionary::ThreadGroup_klass();
   JavaCalls::call_special(&result,
                         thread_group,
                         group,
--- a/hotspot/src/share/vm/services/classLoadingService.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/classLoadingService.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -197,29 +197,4 @@
   LogConfiguration::configure_stdout(level, false, LOG_TAGS(class, unload));
 }
 
-GrowableArray<KlassHandle>* LoadedClassesEnumerator::_loaded_classes = NULL;
-Thread* LoadedClassesEnumerator::_current_thread = NULL;
-
-LoadedClassesEnumerator::LoadedClassesEnumerator(Thread* cur_thread) {
-  assert(cur_thread == Thread::current(), "Check current thread");
-
-  int init_size = ClassLoadingService::loaded_class_count();
-  _klass_handle_array = new GrowableArray<KlassHandle>(init_size);
-
-  // For consistency of the loaded classes, grab the SystemDictionary lock
-  MutexLocker sd_mutex(SystemDictionary_lock);
-
-  // Set _loaded_classes and _current_thread and begin enumerating all classes.
-  // Only one thread will do the enumeration at a time.
-  // These static variables are needed and they are used by the static method
-  // add_loaded_class called from classes_do().
-  _loaded_classes = _klass_handle_array;
-  _current_thread = cur_thread;
-
-  SystemDictionary::classes_do(&add_loaded_class);
-
-  // FIXME: Exclude array klasses for now
-  // Universe::basic_type_classes_do(&add_loaded_class);
-}
-
 #endif // INCLUDE_MANAGEMENT
--- a/hotspot/src/share/vm/services/classLoadingService.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/classLoadingService.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -117,33 +117,4 @@
   }
 };
 
-// FIXME: make this piece of code to be shared by M&M and JVMTI
-class LoadedClassesEnumerator : public StackObj {
-private:
-  static GrowableArray<KlassHandle>* _loaded_classes;
-  // _current_thread is for creating a KlassHandle with a faster version constructor
-  static Thread*                     _current_thread;
-
-  GrowableArray<KlassHandle>* _klass_handle_array;
-
-public:
-  LoadedClassesEnumerator(Thread* cur_thread);
-
-  int num_loaded_classes()         { return _klass_handle_array->length(); }
-  KlassHandle get_klass(int index) { return _klass_handle_array->at(index); }
-
-  static void add_loaded_class(Klass* k) {
-    // FIXME: For now - don't include array klasses
-    // The spec is unclear at this point to count array klasses or not
-    // and also indirect creation of array of super class and secondaries
-    //
-    // for (Klass* l = k; l != NULL; l = l->array_klass_or_null()) {
-    //  KlassHandle h(_current_thread, l);
-    //  _loaded_classes->append(h);
-    // }
-    KlassHandle h(_current_thread, k);
-    _loaded_classes->append(h);
-  }
-};
-
 #endif // SHARE_VM_SERVICES_CLASSLOADINGSERVICE_HPP
--- a/hotspot/src/share/vm/services/diagnosticCommand.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/diagnosticCommand.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -324,7 +324,7 @@
   // load VMSupport
   Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport();
   Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK);
-  instanceKlassHandle ik (THREAD, k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
   if (ik->should_be_initialized()) {
     ik->initialize(THREAD);
   }
@@ -405,9 +405,8 @@
 void RunFinalizationDCmd::execute(DCmdSource source, TRAPS) {
   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(),
                                                  true, CHECK);
-  instanceKlassHandle klass(THREAD, k);
   JavaValue result(T_VOID);
-  JavaCalls::call_static(&result, klass,
+  JavaCalls::call_static(&result, k,
                          vmSymbols::run_finalization_name(),
                          vmSymbols::void_method_signature(), CHECK);
 }
@@ -420,18 +419,15 @@
 void FinalizerInfoDCmd::execute(DCmdSource source, TRAPS) {
   ResourceMark rm;
 
+  Klass* k = SystemDictionary::resolve_or_fail(
+    vmSymbols::finalizer_histogram_klass(), true, CHECK);
 
-  Klass* k = SystemDictionary::resolve_or_null(
-    vmSymbols::finalizer_histogram_klass(), THREAD);
-  assert(k != NULL, "FinalizerHistogram class is not accessible");
-
-  instanceKlassHandle klass(THREAD, k);
   JavaValue result(T_ARRAY);
 
   // We are calling lang.ref.FinalizerHistogram.getFinalizerHistogram() method
   // and expect it to return array of FinalizerHistogramEntry as Object[]
 
-  JavaCalls::call_static(&result, klass,
+  JavaCalls::call_static(&result, k,
                          vmSymbols::get_finalizer_histogram_name(),
                          vmSymbols::void_finalizer_histogram_entry_array_signature(), CHECK);
 
@@ -755,7 +751,6 @@
 
     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
-    instanceKlassHandle ik (THREAD, k);
 
     JavaValue result(T_VOID);
 
@@ -809,7 +804,7 @@
 #undef PUT_OPTION
 
     Handle str = java_lang_String::create_from_str(options.as_string(), CHECK);
-    JavaCalls::call_static(&result, ik, vmSymbols::startRemoteAgent_name(), vmSymbols::string_void_signature(), str, CHECK);
+    JavaCalls::call_static(&result, k, vmSymbols::startRemoteAgent_name(), vmSymbols::string_void_signature(), str, CHECK);
 }
 
 JMXStartLocalDCmd::JMXStartLocalDCmd(outputStream *output, bool heap_allocated) :
@@ -828,10 +823,9 @@
 
     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
-    instanceKlassHandle ik (THREAD, k);
 
     JavaValue result(T_VOID);
-    JavaCalls::call_static(&result, ik, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK);
+    JavaCalls::call_static(&result, k, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK);
 }
 
 void JMXStopRemoteDCmd::execute(DCmdSource source, TRAPS) {
@@ -845,10 +839,9 @@
 
     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
-    instanceKlassHandle ik (THREAD, k);
 
     JavaValue result(T_VOID);
-    JavaCalls::call_static(&result, ik, vmSymbols::stopRemoteAgent_name(), vmSymbols::void_method_signature(), CHECK);
+    JavaCalls::call_static(&result, k, vmSymbols::stopRemoteAgent_name(), vmSymbols::void_method_signature(), CHECK);
 }
 
 JMXStatusDCmd::JMXStatusDCmd(outputStream *output, bool heap_allocated) :
@@ -866,10 +859,9 @@
 
   Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
-  instanceKlassHandle ik (THREAD, k);
 
   JavaValue result(T_OBJECT);
-  JavaCalls::call_static(&result, ik, vmSymbols::getAgentStatus_name(), vmSymbols::void_string_signature(), CHECK);
+  JavaCalls::call_static(&result, k, vmSymbols::getAgentStatus_name(), vmSymbols::void_string_signature(), CHECK);
 
   jvalue* jv = (jvalue*) result.get_value_addr();
   oop str = (oop) jv->l;
--- a/hotspot/src/share/vm/services/diagnosticFramework.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/diagnosticFramework.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -457,7 +457,7 @@
   if (notif) {
 
     Klass* k = Management::com_sun_management_internal_DiagnosticCommandImpl_klass(CHECK);
-    instanceKlassHandle dcmd_mbean_klass(THREAD, k);
+    InstanceKlass* dcmd_mbean_klass = InstanceKlass::cast(k);
 
     JavaValue result(T_OBJECT);
     JavaCalls::call_static(&result,
--- a/hotspot/src/share/vm/services/gcNotifier.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/gcNotifier.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -79,8 +79,7 @@
 
 static Handle getGcInfoBuilder(GCMemoryManager *gcManager,TRAPS) {
 
-  Klass* k = Management::com_sun_management_internal_GarbageCollectorExtImpl_klass(CHECK_NH);
-  instanceKlassHandle gcMBeanKlass (THREAD, k);
+  Klass* gcMBeanKlass = Management::com_sun_management_internal_GarbageCollectorExtImpl_klass(CHECK_NH);
 
   instanceOop i = gcManager->get_memory_manager_instance(THREAD);
   instanceHandle ih(THREAD, i);
@@ -102,16 +101,15 @@
   // Fill the arrays of MemoryUsage objects with before and after GC
   // per pool memory usage
 
-  Klass* mu_klass = Management::java_lang_management_MemoryUsage_klass(CHECK_NH);
-  instanceKlassHandle mu_kh(THREAD, mu_klass);
+  InstanceKlass* mu_klass = Management::java_lang_management_MemoryUsage_klass(CHECK_NH);
 
   // The array allocations below should use a handle containing mu_klass
   // as the first allocation could trigger a GC, causing the actual
   // klass oop to move, and leaving mu_klass pointing to the old
   // location.
-  objArrayOop bu = oopFactory::new_objArray(mu_kh(), MemoryService::num_memory_pools(), CHECK_NH);
+  objArrayOop bu = oopFactory::new_objArray(mu_klass, MemoryService::num_memory_pools(), CHECK_NH);
   objArrayHandle usage_before_gc_ah(THREAD, bu);
-  objArrayOop au = oopFactory::new_objArray(mu_kh(), MemoryService::num_memory_pools(), CHECK_NH);
+  objArrayOop au = oopFactory::new_objArray(mu_klass, MemoryService::num_memory_pools(), CHECK_NH);
   objArrayHandle usage_after_gc_ah(THREAD, au);
 
   for (int i = 0; i < MemoryService::num_memory_pools(); i++) {
@@ -135,8 +133,7 @@
   // The type is 'I'
   objArrayOop extra_args_array = oopFactory::new_objArray(SystemDictionary::Integer_klass(), 1, CHECK_NH);
   objArrayHandle extra_array (THREAD, extra_args_array);
-  Klass* itKlass = SystemDictionary::Integer_klass();
-  instanceKlassHandle intK(THREAD, itKlass);
+  InstanceKlass* intK = SystemDictionary::Integer_klass();
 
   instanceHandle extra_arg_val = intK->allocate_instance_handle(CHECK_NH);
 
@@ -155,10 +152,9 @@
   }
   extra_array->obj_at_put(0,extra_arg_val());
 
-  Klass* gcInfoklass = Management::com_sun_management_GcInfo_klass(CHECK_NH);
-  instanceKlassHandle ik(THREAD, gcInfoklass);
+  InstanceKlass* gcInfoklass = Management::com_sun_management_GcInfo_klass(CHECK_NH);
 
-  Handle gcInfo_instance = ik->allocate_instance_handle(CHECK_NH);
+  Handle gcInfo_instance = gcInfoklass->allocate_instance_handle(CHECK_NH);
 
   JavaValue constructor_result(T_VOID);
   JavaCallArguments constructor_args(16);
@@ -172,13 +168,13 @@
   constructor_args.push_oop(extra_array);
 
   JavaCalls::call_special(&constructor_result,
-                          ik,
+                          gcInfoklass,
                           vmSymbols::object_initializer_name(),
                           vmSymbols::com_sun_management_GcInfo_constructor_signature(),
                           &constructor_args,
                           CHECK_NH);
 
-  return Handle(gcInfo_instance());
+  return Handle(THREAD, gcInfo_instance());
 }
 
 void GCNotifier::sendNotification(TRAPS) {
@@ -216,13 +212,11 @@
     Handle objName = java_lang_String::create_from_str(request->gcManager->name(), CHECK);
     Handle objAction = java_lang_String::create_from_str(request->gcAction, CHECK);
     Handle objCause = java_lang_String::create_from_str(request->gcCause, CHECK);
-    Klass* k = Management::com_sun_management_internal_GarbageCollectorExtImpl_klass(CHECK);
-
-    instanceKlassHandle gc_mbean_klass(THREAD, k);
+    InstanceKlass* gc_mbean_klass = Management::com_sun_management_internal_GarbageCollectorExtImpl_klass(CHECK);
 
     instanceOop gc_mbean = request->gcManager->get_memory_manager_instance(THREAD);
     instanceHandle gc_mbean_h(THREAD, gc_mbean);
-    if (!gc_mbean_h->is_a(k)) {
+    if (!gc_mbean_h->is_a(gc_mbean_klass)) {
       THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
                 "This GCMemoryManager doesn't have a GarbageCollectorMXBean");
     }
--- a/hotspot/src/share/vm/services/heapDumper.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/heapDumper.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -814,11 +814,11 @@
 // returns the size of the instance of the given class
 u4 DumperSupport::instance_size(Klass* k) {
   HandleMark hm;
-  instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
 
   u4 size = 0;
 
-  for (FieldStream fld(ikh, false, false); !fld.eos(); fld.next()) {
+  for (FieldStream fld(ik, false, false); !fld.eos(); fld.next()) {
     if (!fld.access_flags().is_static()) {
       Symbol* sig = fld.signature();
       switch (sig->byte_at(0)) {
@@ -847,18 +847,18 @@
 // dumps static fields of the given class
 void DumperSupport::dump_static_fields(DumpWriter* writer, Klass* k) {
   HandleMark hm;
-  instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
 
   // pass 1 - count the static fields
   u2 field_count = 0;
-  for (FieldStream fldc(ikh, true, true); !fldc.eos(); fldc.next()) {
+  for (FieldStream fldc(ik, true, true); !fldc.eos(); fldc.next()) {
     if (fldc.access_flags().is_static()) field_count++;
   }
 
   writer->write_u2(field_count);
 
   // pass 2 - dump the field descriptors and raw values
-  for (FieldStream fld(ikh, true, true); !fld.eos(); fld.next()) {
+  for (FieldStream fld(ik, true, true); !fld.eos(); fld.next()) {
     if (fld.access_flags().is_static()) {
       Symbol* sig = fld.signature();
 
@@ -867,7 +867,7 @@
 
       // value
       int offset = fld.offset();
-      address addr = (address)ikh->java_mirror() + offset;
+      address addr = (address)ik->java_mirror() + offset;
 
       dump_field_value(writer, sig->byte_at(0), addr);
     }
@@ -877,9 +877,9 @@
 // dump the raw values of the instance fields of the given object
 void DumperSupport::dump_instance_fields(DumpWriter* writer, oop o) {
   HandleMark hm;
-  instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), o->klass());
+  InstanceKlass* ik = InstanceKlass::cast(o->klass());
 
-  for (FieldStream fld(ikh, false, false); !fld.eos(); fld.next()) {
+  for (FieldStream fld(ik, false, false); !fld.eos(); fld.next()) {
     if (!fld.access_flags().is_static()) {
       Symbol* sig = fld.signature();
       address addr = (address)o + fld.offset();
@@ -892,18 +892,18 @@
 // dumps the definition of the instance fields for a given class
 void DumperSupport::dump_instance_field_descriptors(DumpWriter* writer, Klass* k) {
   HandleMark hm;
-  instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), k);
+  InstanceKlass* ik = InstanceKlass::cast(k);
 
   // pass 1 - count the instance fields
   u2 field_count = 0;
-  for (FieldStream fldc(ikh, true, true); !fldc.eos(); fldc.next()) {
+  for (FieldStream fldc(ik, true, true); !fldc.eos(); fldc.next()) {
     if (!fldc.access_flags().is_static()) field_count++;
   }
 
   writer->write_u2(field_count);
 
   // pass 2 - dump the field descriptors
-  for (FieldStream fld(ikh, true, true); !fld.eos(); fld.next()) {
+  for (FieldStream fld(ik, true, true); !fld.eos(); fld.next()) {
     if (!fld.access_flags().is_static()) {
       Symbol* sig = fld.signature();
 
--- a/hotspot/src/share/vm/services/lowMemoryDetector.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/lowMemoryDetector.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -293,8 +293,7 @@
 void SensorInfo::trigger(int count, TRAPS) {
   assert(count <= _pending_trigger_count, "just checking");
   if (_sensor_obj != NULL) {
-    Klass* k = Management::sun_management_Sensor_klass(CHECK);
-    instanceKlassHandle sensorKlass (THREAD, k);
+    InstanceKlass* sensorKlass = Management::sun_management_Sensor_klass(CHECK);
     Handle sensor_h(THREAD, _sensor_obj);
     Handle usage_h = MemoryService::create_MemoryUsage_obj(_usage, CHECK);
 
@@ -337,8 +336,7 @@
   }
 
   if (_sensor_obj != NULL) {
-    Klass* k = Management::sun_management_Sensor_klass(CHECK);
-    instanceKlassHandle sensorKlass (THREAD, k);
+    InstanceKlass* sensorKlass = Management::sun_management_Sensor_klass(CHECK);
     Handle sensor(THREAD, _sensor_obj);
 
     JavaValue result(T_VOID);
--- a/hotspot/src/share/vm/services/mallocSiteTable.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/mallocSiteTable.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -62,7 +62,7 @@
  public:
   MallocSiteHashtableEntry() : _next(NULL) { }
 
-  MallocSiteHashtableEntry(NativeCallStack stack):
+  MallocSiteHashtableEntry(const NativeCallStack& stack):
     _malloc_site(stack), _next(NULL) { }
 
   inline const MallocSiteHashtableEntry* next() const {
--- a/hotspot/src/share/vm/services/mallocTracker.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/mallocTracker.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,8 +40,8 @@
  */
 class MemoryCounter VALUE_OBJ_CLASS_SPEC {
  private:
-  size_t   _count;
-  size_t   _size;
+  volatile size_t   _count;
+  volatile size_t   _size;
 
   DEBUG_ONLY(size_t   _peak_count;)
   DEBUG_ONLY(size_t   _peak_size; )
@@ -53,26 +53,28 @@
   }
 
   inline void allocate(size_t sz) {
-    Atomic::add(1, (volatile MemoryCounterType*)&_count);
+    Atomic::add(1, &_count);
     if (sz > 0) {
-      Atomic::add((MemoryCounterType)sz, (volatile MemoryCounterType*)&_size);
+      Atomic::add(sz, &_size);
       DEBUG_ONLY(_peak_size = MAX2(_peak_size, _size));
     }
     DEBUG_ONLY(_peak_count = MAX2(_peak_count, _count);)
   }
 
   inline void deallocate(size_t sz) {
-    assert(_count > 0, "Negative counter");
-    assert(_size >= sz, "Negative size");
-    Atomic::add(-1, (volatile MemoryCounterType*)&_count);
+    assert(_count > 0, "Nothing allocated yet");
+    assert(_size >= sz, "deallocation > allocated");
+    Atomic::add(-1, &_count);
     if (sz > 0) {
-      Atomic::add(-(MemoryCounterType)sz, (volatile MemoryCounterType*)&_size);
+      // unary minus operator applied to unsigned type, result still unsigned
+      #pragma warning(suppress: 4146)
+      Atomic::add(-sz, &_size);
     }
   }
 
   inline void resize(long sz) {
     if (sz != 0) {
-      Atomic::add((MemoryCounterType)sz, (volatile MemoryCounterType*)&_size);
+      Atomic::add(sz, &_size);
       DEBUG_ONLY(_peak_size = MAX2(_size, _peak_size);)
     }
   }
--- a/hotspot/src/share/vm/services/management.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/management.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -62,16 +62,16 @@
 PerfVariable* Management::_end_vm_creation_time = NULL;
 PerfVariable* Management::_vm_init_done_time = NULL;
 
-Klass* Management::_diagnosticCommandImpl_klass = NULL;
-Klass* Management::_garbageCollectorExtImpl_klass = NULL;
-Klass* Management::_garbageCollectorMXBean_klass = NULL;
-Klass* Management::_gcInfo_klass = NULL;
-Klass* Management::_managementFactoryHelper_klass = NULL;
-Klass* Management::_memoryManagerMXBean_klass = NULL;
-Klass* Management::_memoryPoolMXBean_klass = NULL;
-Klass* Management::_memoryUsage_klass = NULL;
-Klass* Management::_sensor_klass = NULL;
-Klass* Management::_threadInfo_klass = NULL;
+InstanceKlass* Management::_diagnosticCommandImpl_klass = NULL;
+InstanceKlass* Management::_garbageCollectorExtImpl_klass = NULL;
+InstanceKlass* Management::_garbageCollectorMXBean_klass = NULL;
+InstanceKlass* Management::_gcInfo_klass = NULL;
+InstanceKlass* Management::_managementFactoryHelper_klass = NULL;
+InstanceKlass* Management::_memoryManagerMXBean_klass = NULL;
+InstanceKlass* Management::_memoryPoolMXBean_klass = NULL;
+InstanceKlass* Management::_memoryUsage_klass = NULL;
+InstanceKlass* Management::_sensor_klass = NULL;
+InstanceKlass* Management::_threadInfo_klass = NULL;
 
 jmmOptionalSupport Management::_optional_support = {0};
 TimeStamp Management::_stamp;
@@ -156,11 +156,10 @@
       vm_exit_during_initialization("Management agent initialization failure: "
           "class jdk.internal.agent.Agent not found.");
     }
-    instanceKlassHandle ik (THREAD, k);
 
     JavaValue result(T_VOID);
     JavaCalls::call_static(&result,
-                           ik,
+                           k,
                            vmSymbols::startAgent_name(),
                            vmSymbols::void_method_signature(),
                            CHECK);
@@ -171,30 +170,28 @@
   memcpy(support, &_optional_support, sizeof(jmmOptionalSupport));
 }
 
-Klass* Management::load_and_initialize_klass(Symbol* sh, TRAPS) {
+InstanceKlass* Management::load_and_initialize_klass(Symbol* sh, TRAPS) {
   Klass* k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL);
-  Klass* ik = initialize_klass(k, CHECK_NULL);
-  return ik;
+  return initialize_klass(k, CHECK_NULL);
 }
 
-Klass* Management::load_and_initialize_klass_or_null(Symbol* sh, TRAPS) {
+InstanceKlass* Management::load_and_initialize_klass_or_null(Symbol* sh, TRAPS) {
   Klass* k = SystemDictionary::resolve_or_null(sh, CHECK_NULL);
   if (k == NULL) {
      return NULL;
   }
-  Klass* ik = initialize_klass(k, CHECK_NULL);
-  return ik;
+  return initialize_klass(k, CHECK_NULL);
 }
 
-Klass* Management::initialize_klass(Klass* k, TRAPS) {
-  instanceKlassHandle ik (THREAD, k);
+InstanceKlass* Management::initialize_klass(Klass* k, TRAPS) {
+  InstanceKlass* ik = InstanceKlass::cast(k);
   if (ik->should_be_initialized()) {
     ik->initialize(CHECK_NULL);
   }
   // If these classes change to not be owned by the boot loader, they need
   // to be walked to keep their class loader alive in oops_do.
   assert(ik->class_loader() == NULL, "need to follow in oops_do");
-  return ik();
+  return ik;
 }
 
 void Management::record_vm_startup_time(jlong begin, jlong duration) {
@@ -218,56 +215,56 @@
   ThreadService::oops_do(f);
 }
 
-Klass* Management::java_lang_management_ThreadInfo_klass(TRAPS) {
+InstanceKlass* Management::java_lang_management_ThreadInfo_klass(TRAPS) {
   if (_threadInfo_klass == NULL) {
     _threadInfo_klass = load_and_initialize_klass(vmSymbols::java_lang_management_ThreadInfo(), CHECK_NULL);
   }
   return _threadInfo_klass;
 }
 
-Klass* Management::java_lang_management_MemoryUsage_klass(TRAPS) {
+InstanceKlass* Management::java_lang_management_MemoryUsage_klass(TRAPS) {
   if (_memoryUsage_klass == NULL) {
     _memoryUsage_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryUsage(), CHECK_NULL);
   }
   return _memoryUsage_klass;
 }
 
-Klass* Management::java_lang_management_MemoryPoolMXBean_klass(TRAPS) {
+InstanceKlass* Management::java_lang_management_MemoryPoolMXBean_klass(TRAPS) {
   if (_memoryPoolMXBean_klass == NULL) {
     _memoryPoolMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryPoolMXBean(), CHECK_NULL);
   }
   return _memoryPoolMXBean_klass;
 }
 
-Klass* Management::java_lang_management_MemoryManagerMXBean_klass(TRAPS) {
+InstanceKlass* Management::java_lang_management_MemoryManagerMXBean_klass(TRAPS) {
   if (_memoryManagerMXBean_klass == NULL) {
     _memoryManagerMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryManagerMXBean(), CHECK_NULL);
   }
   return _memoryManagerMXBean_klass;
 }
 
-Klass* Management::java_lang_management_GarbageCollectorMXBean_klass(TRAPS) {
+InstanceKlass* Management::java_lang_management_GarbageCollectorMXBean_klass(TRAPS) {
   if (_garbageCollectorMXBean_klass == NULL) {
       _garbageCollectorMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_GarbageCollectorMXBean(), CHECK_NULL);
   }
   return _garbageCollectorMXBean_klass;
 }
 
-Klass* Management::sun_management_Sensor_klass(TRAPS) {
+InstanceKlass* Management::sun_management_Sensor_klass(TRAPS) {
   if (_sensor_klass == NULL) {
     _sensor_klass = load_and_initialize_klass(vmSymbols::sun_management_Sensor(), CHECK_NULL);
   }
   return _sensor_klass;
 }
 
-Klass* Management::sun_management_ManagementFactoryHelper_klass(TRAPS) {
+InstanceKlass* Management::sun_management_ManagementFactoryHelper_klass(TRAPS) {
   if (_managementFactoryHelper_klass == NULL) {
     _managementFactoryHelper_klass = load_and_initialize_klass(vmSymbols::sun_management_ManagementFactoryHelper(), CHECK_NULL);
   }
   return _managementFactoryHelper_klass;
 }
 
-Klass* Management::com_sun_management_internal_GarbageCollectorExtImpl_klass(TRAPS) {
+InstanceKlass* Management::com_sun_management_internal_GarbageCollectorExtImpl_klass(TRAPS) {
   if (_garbageCollectorExtImpl_klass == NULL) {
     _garbageCollectorExtImpl_klass =
                 load_and_initialize_klass_or_null(vmSymbols::com_sun_management_internal_GarbageCollectorExtImpl(), CHECK_NULL);
@@ -275,14 +272,14 @@
   return _garbageCollectorExtImpl_klass;
 }
 
-Klass* Management::com_sun_management_GcInfo_klass(TRAPS) {
+InstanceKlass* Management::com_sun_management_GcInfo_klass(TRAPS) {
   if (_gcInfo_klass == NULL) {
     _gcInfo_klass = load_and_initialize_klass(vmSymbols::com_sun_management_GcInfo(), CHECK_NULL);
   }
   return _gcInfo_klass;
 }
 
-Klass* Management::com_sun_management_internal_DiagnosticCommandImpl_klass(TRAPS) {
+InstanceKlass* Management::com_sun_management_internal_DiagnosticCommandImpl_klass(TRAPS) {
   if (_diagnosticCommandImpl_klass == NULL) {
     _diagnosticCommandImpl_klass = load_and_initialize_klass(vmSymbols::com_sun_management_internal_DiagnosticCommandImpl(), CHECK_NULL);
   }
@@ -333,8 +330,7 @@
 
 // Helper function to construct a ThreadInfo object
 instanceOop Management::create_thread_info_instance(ThreadSnapshot* snapshot, TRAPS) {
-  Klass* k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
-  instanceKlassHandle ik (THREAD, k);
+  InstanceKlass* ik = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
 
   JavaValue result(T_VOID);
   JavaCallArguments args(14);
@@ -363,8 +359,7 @@
                                                     typeArrayHandle depths_array,
                                                     objArrayHandle synchronizers_array,
                                                     TRAPS) {
-  Klass* k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
-  instanceKlassHandle ik (THREAD, k);
+  InstanceKlass* ik = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
 
   JavaValue result(T_VOID);
   JavaCallArguments args(17);
@@ -401,7 +396,7 @@
   oop mgr_obj = JNIHandles::resolve(mgr);
   instanceHandle h(THREAD, (instanceOop) mgr_obj);
 
-  Klass* k = Management::java_lang_management_GarbageCollectorMXBean_klass(CHECK_NULL);
+  InstanceKlass* k = Management::java_lang_management_GarbageCollectorMXBean_klass(CHECK_NULL);
   if (!h->is_a(k)) {
     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
                "the object is not an instance of java.lang.management.GarbageCollectorMXBean class",
@@ -507,9 +502,8 @@
   }
 
   // Allocate the resulting MemoryPoolMXBean[] object
-  Klass* k = Management::java_lang_management_MemoryPoolMXBean_klass(CHECK_NULL);
-  instanceKlassHandle ik (THREAD, k);
-  objArrayOop r = oopFactory::new_objArray(ik(), num_memory_pools, CHECK_NULL);
+  InstanceKlass* ik = Management::java_lang_management_MemoryPoolMXBean_klass(CHECK_NULL);
+  objArrayOop r = oopFactory::new_objArray(ik, num_memory_pools, CHECK_NULL);
   objArrayHandle poolArray(THREAD, r);
 
   if (mgr == NULL) {
@@ -552,9 +546,8 @@
   }
 
   // Allocate the resulting MemoryManagerMXBean[] object
-  Klass* k = Management::java_lang_management_MemoryManagerMXBean_klass(CHECK_NULL);
-  instanceKlassHandle ik (THREAD, k);
-  objArrayOop r = oopFactory::new_objArray(ik(), num_mgrs, CHECK_NULL);
+  InstanceKlass* ik = Management::java_lang_management_MemoryManagerMXBean_klass(CHECK_NULL);
+  objArrayOop r = oopFactory::new_objArray(ik, num_mgrs, CHECK_NULL);
   objArrayHandle mgrArray(THREAD, r);
 
   if (pool == NULL) {
@@ -629,7 +622,7 @@
     THROW(vmSymbols::java_lang_NullPointerException());
   }
 
-  Klass* sensor_klass = Management::sun_management_Sensor_klass(CHECK);
+  InstanceKlass* sensor_klass = Management::sun_management_Sensor_klass(CHECK);
   oop s = JNIHandles::resolve(sensorObj);
   assert(s->is_instance(), "Sensor should be an instanceOop");
   instanceHandle sensor_h(THREAD, (instanceOop) s);
@@ -1202,9 +1195,8 @@
   int num_snapshots = dump_result.num_snapshots();
 
   // create the result ThreadInfo[] object
-  Klass* k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
-  instanceKlassHandle ik (THREAD, k);
-  objArrayOop r = oopFactory::new_objArray(ik(), num_snapshots, CHECK_NULL);
+  InstanceKlass* ik = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
+  objArrayOop r = oopFactory::new_objArray(ik, num_snapshots, CHECK_NULL);
   objArrayHandle result_h(THREAD, r);
 
   int index = 0;
@@ -1299,25 +1291,6 @@
   return (jobjectArray) JNIHandles::make_local(env, result_h());
 JVM_END
 
-// Returns an array of Class objects.
-JVM_ENTRY(jobjectArray, jmm_GetLoadedClasses(JNIEnv *env))
-  ResourceMark rm(THREAD);
-
-  LoadedClassesEnumerator lce(THREAD);  // Pass current Thread as parameter
-
-  int num_classes = lce.num_loaded_classes();
-  objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), num_classes, CHECK_0);
-  objArrayHandle classes_ah(THREAD, r);
-
-  for (int i = 0; i < num_classes; i++) {
-    KlassHandle kh = lce.get_klass(i);
-    oop mirror = kh()->java_mirror();
-    classes_ah->obj_at_put(i, mirror);
-  }
-
-  return (jobjectArray) JNIHandles::make_local(env, classes_ah());
-JVM_END
-
 // Reset statistic.  Return true if the requested statistic is reset.
 // Otherwise, return false.
 //
@@ -1953,7 +1926,8 @@
     THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
                "Output file name cannot be null.", -1);
   }
-  char* name = java_lang_String::as_platform_dependent_str(on, CHECK_(-1));
+  Handle onhandle(THREAD, on);
+  char* name = java_lang_String::as_platform_dependent_str(onhandle, CHECK_(-1));
   if (name == NULL) {
     THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
                "Output file name cannot be null.", -1);
--- a/hotspot/src/share/vm/services/management.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/management.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,19 +42,19 @@
   static TimeStamp          _stamp; // Timestamp since vm init done time
 
   // Management klasses
-  static Klass*             _diagnosticCommandImpl_klass;
-  static Klass*             _garbageCollectorExtImpl_klass;
-  static Klass*             _garbageCollectorMXBean_klass;
-  static Klass*             _gcInfo_klass;
-  static Klass*             _managementFactoryHelper_klass;
-  static Klass*             _memoryManagerMXBean_klass;
-  static Klass*             _memoryPoolMXBean_klass;
-  static Klass*             _memoryUsage_klass;
-  static Klass*             _sensor_klass;
-  static Klass*             _threadInfo_klass;
-  static Klass* load_and_initialize_klass(Symbol* sh, TRAPS);
-  static Klass* load_and_initialize_klass_or_null(Symbol* sh, TRAPS);
-  static Klass* initialize_klass(Klass* k, TRAPS);
+  static InstanceKlass*     _diagnosticCommandImpl_klass;
+  static InstanceKlass*     _garbageCollectorExtImpl_klass;
+  static InstanceKlass*     _garbageCollectorMXBean_klass;
+  static InstanceKlass*     _gcInfo_klass;
+  static InstanceKlass*     _managementFactoryHelper_klass;
+  static InstanceKlass*     _memoryManagerMXBean_klass;
+  static InstanceKlass*     _memoryPoolMXBean_klass;
+  static InstanceKlass*     _memoryUsage_klass;
+  static InstanceKlass*     _sensor_klass;
+  static InstanceKlass*     _threadInfo_klass;
+  static InstanceKlass* load_and_initialize_klass(Symbol* sh, TRAPS);
+  static InstanceKlass* load_and_initialize_klass_or_null(Symbol* sh, TRAPS);
+  static InstanceKlass* initialize_klass(Klass* k, TRAPS);
 
 public:
   static void init();
@@ -67,7 +67,7 @@
   static void* get_jmm_interface(int version);
   static void  get_optional_support(jmmOptionalSupport* support);
 
-  static void get_loaded_classes(JavaThread* cur_thread, GrowableArray<KlassHandle>* klass_handle_array);
+  static void get_loaded_classes(JavaThread* cur_thread, GrowableArray<Klass*>* klass_array);
 
   static void  record_vm_startup_time(jlong begin, jlong duration)
       NOT_MANAGEMENT_RETURN;
@@ -87,21 +87,21 @@
   }
 
   // methods to return a Klass*.
-  static Klass* java_lang_management_ThreadInfo_klass(TRAPS);
-  static Klass* java_lang_management_MemoryUsage_klass(TRAPS)
+  static InstanceKlass* java_lang_management_ThreadInfo_klass(TRAPS);
+  static InstanceKlass* java_lang_management_MemoryUsage_klass(TRAPS)
       NOT_MANAGEMENT_RETURN_(NULL);
-  static Klass* java_lang_management_MemoryPoolMXBean_klass(TRAPS);
-  static Klass* java_lang_management_MemoryManagerMXBean_klass(TRAPS);
-  static Klass* java_lang_management_GarbageCollectorMXBean_klass(TRAPS);
-  static Klass* sun_management_ManagementFactoryHelper_klass(TRAPS)
+  static InstanceKlass* java_lang_management_MemoryPoolMXBean_klass(TRAPS);
+  static InstanceKlass* java_lang_management_MemoryManagerMXBean_klass(TRAPS);
+  static InstanceKlass* java_lang_management_GarbageCollectorMXBean_klass(TRAPS);
+  static InstanceKlass* sun_management_ManagementFactoryHelper_klass(TRAPS)
       NOT_MANAGEMENT_RETURN_(NULL);
-  static Klass* sun_management_Sensor_klass(TRAPS)
+  static InstanceKlass* sun_management_Sensor_klass(TRAPS)
       NOT_MANAGEMENT_RETURN_(NULL);
-  static Klass* com_sun_management_internal_GarbageCollectorExtImpl_klass(TRAPS)
+  static InstanceKlass* com_sun_management_internal_GarbageCollectorExtImpl_klass(TRAPS)
       NOT_MANAGEMENT_RETURN_(NULL);
-  static Klass* com_sun_management_GcInfo_klass(TRAPS)
+  static InstanceKlass* com_sun_management_GcInfo_klass(TRAPS)
       NOT_MANAGEMENT_RETURN_(NULL);
-  static Klass* com_sun_management_internal_DiagnosticCommandImpl_klass(TRAPS)
+  static InstanceKlass* com_sun_management_internal_DiagnosticCommandImpl_klass(TRAPS)
       NOT_MANAGEMENT_RETURN_(NULL);
 
   static instanceOop create_thread_info_instance(ThreadSnapshot* snapshot, TRAPS);
--- a/hotspot/src/share/vm/services/memoryManager.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/memoryManager.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -124,7 +124,7 @@
       signature = vmSymbols::createMemoryManager_signature();
     }
 
-    instanceKlassHandle ik(THREAD, k);
+    InstanceKlass* ik = InstanceKlass::cast(k);
 
     JavaCalls::call_static(&result,
                            ik,
--- a/hotspot/src/share/vm/services/memoryPool.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/memoryPool.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -86,8 +86,7 @@
   if (pool_obj == NULL) {
     // It's ok for more than one thread to execute the code up to the locked region.
     // Extra pool instances will just be gc'ed.
-    Klass* k = Management::sun_management_ManagementFactoryHelper_klass(CHECK_NULL);
-    instanceKlassHandle ik(THREAD, k);
+    InstanceKlass* ik = Management::sun_management_ManagementFactoryHelper_klass(CHECK_NULL);
 
     Handle pool_name = java_lang_String::create_from_str(_name, CHECK_NULL);
     jlong usage_threshold_value = (_usage_threshold->is_high_threshold_supported() ? 0 : -1L);
--- a/hotspot/src/share/vm/services/memoryService.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/memoryService.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -529,8 +529,7 @@
 }
 
 Handle MemoryService::create_MemoryUsage_obj(MemoryUsage usage, TRAPS) {
-  Klass* k = Management::java_lang_management_MemoryUsage_klass(CHECK_NH);
-  instanceKlassHandle ik(THREAD, k);
+  InstanceKlass* ik = Management::java_lang_management_MemoryUsage_klass(CHECK_NH);
 
   instanceHandle obj = ik->allocate_instance_handle(CHECK_NH);
 
--- a/hotspot/src/share/vm/services/nmtCommon.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/nmtCommon.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,13 +30,6 @@
 
 #define CALC_OBJ_SIZE_IN_TYPE(obj, type) (align_size_up_(sizeof(obj), sizeof(type))/sizeof(type))
 
-// Data type for memory counters
-#ifdef _LP64
-  typedef jlong    MemoryCounterType;
-#else
-  typedef jint     MemoryCounterType;
-#endif
-
 // Native memory tracking level
 enum NMT_TrackingLevel {
   NMT_unknown = 0xFF,
--- a/hotspot/src/share/vm/services/threadService.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/services/threadService.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -166,7 +166,7 @@
     // If obj == NULL, then ObjectMonitor is raw which doesn't count.
   }
 
-  Handle h(obj);
+  Handle h(Thread::current(), obj);
   return h;
 }
 
@@ -607,12 +607,11 @@
 }
 
 Handle ThreadStackTrace::allocate_fill_stack_trace_element_array(TRAPS) {
-  Klass* k = SystemDictionary::StackTraceElement_klass();
-  assert(k != NULL, "must be loaded in 1.4+");
-  instanceKlassHandle ik(THREAD, k);
+  InstanceKlass* ik = SystemDictionary::StackTraceElement_klass();
+  assert(ik != NULL, "must be loaded in 1.4+");
 
   // Allocate an array of java/lang/StackTraceElement object
-  objArrayOop ste = oopFactory::new_objArray(ik(), _depth, CHECK_NH);
+  objArrayOop ste = oopFactory::new_objArray(ik, _depth, CHECK_NH);
   objArrayHandle backtrace(THREAD, ste);
   for (int j = 0; j < _depth; j++) {
     StackFrameInfo* frame = _frames->at(j);
--- a/hotspot/src/share/vm/shark/sharkRuntime.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/shark/sharkRuntime.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2008, 2009, 2010 Red Hat, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -41,16 +41,15 @@
                                                     int*        indexes,
                                                     int         num_indexes))
   constantPoolHandle pool(thread, method(thread)->constants());
-  KlassHandle exc_klass(thread, ((oop) tos_at(thread, 0))->klass());
+  Klass* exc_klass = ((oop) tos_at(thread, 0))->klass();
 
   for (int i = 0; i < num_indexes; i++) {
     Klass* tmp = pool->klass_at(indexes[i], CHECK_0);
-    KlassHandle chk_klass(thread, tmp);
 
-    if (exc_klass() == chk_klass())
+    if (exc_klass() == tmp)
       return i;
 
-    if (exc_klass()->is_subtype_of(chk_klass()))
+    if (exc_klass()->is_subtype_of(tmp))
       return i;
   }
 
@@ -85,7 +84,7 @@
 
 JRT_ENTRY(void, SharkRuntime::new_instance(JavaThread* thread, int index))
   Klass* k_oop = method(thread)->constants()->klass_at(index, CHECK);
-  instanceKlassHandle klass(THREAD, k_oop);
+  InstanceKlass* klass = InstanceKlass::cast(k);
 
   // Make sure we are not instantiating an abstract klass
   klass->check_valid_for_instantiation(true, CHECK);
--- a/hotspot/src/share/vm/utilities/exceptions.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/utilities/exceptions.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -129,7 +129,7 @@
 // therefore the exception oop should be in the oopmap.
 void Exceptions::_throw_oop(Thread* thread, const char* file, int line, oop exception) {
   assert(exception != NULL, "exception should not be NULL");
-  Handle h_exception = Handle(thread, exception);
+  Handle h_exception(thread, exception);
   _throw(thread, file, line, h_exception);
 }
 
@@ -265,11 +265,10 @@
   Handle h_exception;
 
   // Resolve exception klass
-  Klass* ik = SystemDictionary::resolve_or_fail(name, h_loader, h_protection_domain, true, thread);
-  instanceKlassHandle klass(thread, ik);
+  InstanceKlass* klass = InstanceKlass::cast(SystemDictionary::resolve_or_fail(name, h_loader, h_protection_domain, true, thread));
 
   if (!thread->has_pending_exception()) {
-    assert(klass.not_null(), "klass must exist");
+    assert(klass != NULL, "klass must exist");
     // We are about to create an instance - so make sure that klass is initialized
     klass->initialize(thread);
     if (!thread->has_pending_exception()) {
@@ -496,7 +495,7 @@
 void Exceptions::debug_check_abort_helper(Handle exception, const char* message) {
   ResourceMark rm;
   if (message == NULL && exception->is_a(SystemDictionary::Throwable_klass())) {
-    oop msg = java_lang_Throwable::message(exception);
+    oop msg = java_lang_Throwable::message(exception());
     if (msg != NULL) {
       message = java_lang_String::as_utf8_string(msg);
     }
--- a/hotspot/src/share/vm/utilities/vmError.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/utilities/vmError.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -38,6 +38,7 @@
 #include "runtime/thread.inline.hpp"
 #include "runtime/vmThread.hpp"
 #include "runtime/vm_operations.hpp"
+#include "runtime/vm_version.hpp"
 #include "services/memTracker.hpp"
 #include "trace/traceMacros.hpp"
 #include "utilities/debug.hpp"
@@ -312,10 +313,41 @@
 int          VMError::_current_step;
 const char*  VMError::_current_step_info;
 
+volatile jlong VMError::_reporting_start_time = -1;
+volatile bool VMError::_reporting_did_timeout = false;
+volatile jlong VMError::_step_start_time = -1;
+volatile bool VMError::_step_did_timeout = false;
+
+// Helper, return current timestamp for timeout handling.
+jlong VMError::get_current_timestamp() {
+  return os::javaTimeNanos();
+}
+// Factor to translate the timestamp to seconds.
+#define TIMESTAMP_TO_SECONDS_FACTOR (1000 * 1000 * 1000)
+
+void VMError::record_reporting_start_time() {
+  const jlong now = get_current_timestamp();
+  Atomic::store(now, &_reporting_start_time);
+}
+
+jlong VMError::get_reporting_start_time() {
+  return Atomic::load(&_reporting_start_time);
+}
+
+void VMError::record_step_start_time() {
+  const jlong now = get_current_timestamp();
+  Atomic::store(now, &_step_start_time);
+}
+
+jlong VMError::get_step_start_time() {
+  return Atomic::load(&_step_start_time);
+}
+
 void VMError::report(outputStream* st, bool _verbose) {
 
 # define BEGIN if (_current_step == 0) { _current_step = __LINE__;
-# define STEP(s) } if (_current_step < __LINE__) { _current_step = __LINE__; _current_step_info = s;
+# define STEP(s) } if (_current_step < __LINE__) { _current_step = __LINE__; _current_step_info = s; \
+  record_step_start_time(); _step_did_timeout = false;
 # define END }
 
   // don't allocate large buffer on stack
@@ -352,6 +384,18 @@
       controlled_crash(TestCrashInErrorHandler);
     }
 
+  // TestUnresponsiveErrorHandler: We want to test both step timeouts and global timeout.
+  // Step to global timeout ratio is 4:1, so in order to be absolutely sure we hit the
+  // global timeout, let's execute the timeout step five times.
+  // See corresponding test in test/runtime/ErrorHandling/TimeoutInErrorHandlingTest.java
+  #define TIMEOUT_TEST_STEP STEP("test unresponsive error reporting step") \
+    if (_verbose && TestUnresponsiveErrorHandler) { os::infinite_sleep(); }
+  TIMEOUT_TEST_STEP
+  TIMEOUT_TEST_STEP
+  TIMEOUT_TEST_STEP
+  TIMEOUT_TEST_STEP
+  TIMEOUT_TEST_STEP
+
   STEP("test safefetch in error handler")
     // test whether it is safe to use SafeFetch32 in Crash Handler. Test twice
     // to test that resetting the signal handler works correctly.
@@ -1176,6 +1220,9 @@
     // first time
     set_error_reported();
 
+    reporting_started();
+    record_reporting_start_time();
+
     if (ShowMessageBoxOnError || PauseAtExit) {
       show_message_box(buffer, sizeof(buffer));
 
@@ -1216,17 +1263,31 @@
         os::die();
       }
 
-      jio_snprintf(buffer, sizeof(buffer),
-                   "[error occurred during error reporting (%s), id 0x%x]",
+      outputStream* const st = log.is_open() ? &log : &out;
+      st->cr();
+
+      // Timeout handling.
+      if (_step_did_timeout) {
+        // The current step had a timeout. Lets continue reporting with the next step.
+        st->print_raw("[timeout occurred during error reporting in step \"");
+        st->print_raw(_current_step_info);
+        st->print_cr("\"] after " INT64_FORMAT " s.",
+          (get_current_timestamp() - _step_start_time) / TIMESTAMP_TO_SECONDS_FACTOR);
+      } else if (_reporting_did_timeout) {
+        // We hit ErrorLogTimeout. Reporting will stop altogether. Let's wrap things
+        // up, the process is about to be stopped by the WatcherThread.
+        st->print_cr("------ Timeout during error reporting after " INT64_FORMAT " s. ------",
+          (get_current_timestamp() - _reporting_start_time) / TIMESTAMP_TO_SECONDS_FACTOR);
+        st->flush();
+        // Watcherthread is about to call os::die. Lets just wait.
+        os::infinite_sleep();
+      } else {
+        // Crash or assert during error reporting. Lets continue reporting with the next step.
+        jio_snprintf(buffer, sizeof(buffer),
+           "[error occurred during error reporting (%s), id 0x%x]",
                    _current_step_info, _id);
-      if (log.is_open()) {
-        log.cr();
-        log.print_raw_cr(buffer);
-        log.cr();
-      } else {
-        out.cr();
-        out.print_raw_cr(buffer);
-        out.cr();
+        st->print_raw_cr(buffer);
+        st->cr();
       }
     }
   }
@@ -1262,6 +1323,7 @@
     }
 
     report(&log, true);
+    log_done = true;
     _current_step = 0;
     _current_step_info = "";
 
@@ -1282,7 +1344,6 @@
     }
 
     log.set_fd(-1);
-    log_done = true;
   }
 
   static bool skip_replay = ReplayCompiles; // Do not overwrite file during replay
@@ -1421,3 +1482,50 @@
     yes = os::start_debugging(buf,buflen);
   } while (yes);
 }
+
+// Timeout handling: check if a timeout happened (either a single step did
+// timeout or the whole of error reporting hit ErrorLogTimeout). Interrupt
+// the reporting thread if that is the case.
+bool VMError::check_timeout() {
+
+  if (ErrorLogTimeout == 0) {
+    return false;
+  }
+
+  // Do not check for timeouts if we still have a message box to show to the
+  // user or if there are OnError handlers to be run.
+  if (ShowMessageBoxOnError
+      || (OnError != NULL && OnError[0] != '\0')
+      || Arguments::abort_hook() != NULL) {
+    return false;
+  }
+
+  const jlong reporting_start_time_l = get_reporting_start_time();
+  const jlong now = get_current_timestamp();
+  // Timestamp is stored in nanos.
+  if (reporting_start_time_l > 0) {
+    const jlong end = reporting_start_time_l + (jlong)ErrorLogTimeout * TIMESTAMP_TO_SECONDS_FACTOR;
+    if (end <= now) {
+      _reporting_did_timeout = true;
+      interrupt_reporting_thread();
+      return true; // global timeout
+    }
+  }
+
+  const jlong step_start_time_l = get_step_start_time();
+  if (step_start_time_l > 0) {
+    // A step times out after a quarter of the total timeout. Steps are mostly fast unless they
+    // hang for some reason, so this simple rule allows for three hanging step and still
+    // hopefully leaves time enough for the rest of the steps to finish.
+    const jlong end = step_start_time_l + (jlong)ErrorLogTimeout * TIMESTAMP_TO_SECONDS_FACTOR / 4;
+    if (end <= now) {
+      _step_did_timeout = true;
+      interrupt_reporting_thread();
+      return false; // (Not a global timeout)
+    }
+  }
+
+  return false;
+
+}
+
--- a/hotspot/src/share/vm/utilities/vmError.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/utilities/vmError.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -74,6 +74,16 @@
   // no core/minidump has been written to disk
   static char coredump_message[O_BUFLEN];
 
+  // Timeout handling:
+  // Timestamp at which error reporting started; -1 if no error reporting in progress.
+  static volatile jlong _reporting_start_time;
+  // Whether or not error reporting did timeout.
+  static volatile bool _reporting_did_timeout;
+  // Timestamp at which the last error reporting step started; -1 if no error reporting
+  //   in progress.
+  static volatile jlong _step_start_time;
+  // Whether or not the last error reporting step did timeout.
+  static volatile bool _step_did_timeout;
 
   // set signal handlers on Solaris/Linux or the default exception filter
   // on Windows, to handle recursive crashes.
@@ -104,6 +114,20 @@
   static fdStream out;
   static fdStream log; // error log used by VMError::report_and_die()
 
+  // Timeout handling.
+  // Hook functions for platform dependend functionality:
+  static void reporting_started();
+  static void interrupt_reporting_thread();
+
+  // Helper function to get the current timestamp.
+  static jlong get_current_timestamp();
+
+  // Accessors to get/set the start times for step and total timeout.
+  static void record_reporting_start_time();
+  static jlong get_reporting_start_time();
+  static void record_step_start_time();
+  static jlong get_step_start_time();
+
 public:
 
   // return a string to describe the error
@@ -147,6 +171,11 @@
   static bool fatal_error_in_progress() { return first_error_tid != -1; }
 
   static intptr_t get_first_error_tid() { return first_error_tid; }
+
+  // Called by the WatcherThread to check if error reporting has timed-out.
+  //  Returns true if error reporting has not completed within the ErrorLogTimeout limit.
+  static bool check_timeout();
+
 };
 
 #endif // SHARE_VM_UTILITIES_VMERROR_HPP
--- a/hotspot/src/share/vm/utilities/xmlstream.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/utilities/xmlstream.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -422,17 +422,17 @@
 // ------------------------------------------------------------------
 // Output a klass attribute, in the form " klass='pkg/cls'".
 // This is used only when there is no ciKlass available.
-void xmlStream::klass(KlassHandle klass) {
+void xmlStream::klass(Klass* klass) {
   assert_if_no_error(inside_attrs(), "printing attributes");
-  if (klass.is_null())  return;
+  if (klass == NULL) return;
   print_raw(" klass='");
   klass_text(klass);
   print_raw("'");
 }
 
-void xmlStream::klass_text(KlassHandle klass) {
+void xmlStream::klass_text(Klass* klass) {
   assert_if_no_error(inside_attrs(), "printing attributes");
-  if (klass.is_null())  return;
+  if (klass == NULL) return;
   //klass->print_short_name(log->out());
   klass->name()->print_symbol_on(out());
 }
--- a/hotspot/src/share/vm/utilities/xmlstream.hpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/src/share/vm/utilities/xmlstream.hpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -138,14 +138,14 @@
   // commonly used XML attributes
   void          stamp();                 // stamp='1.234'
   void          method(methodHandle m);  // method='k n s' ...
-  void          klass(KlassHandle k);    // klass='name'
+  void          klass(Klass* k);         // klass='name'
   void          name(const Symbol* s);   // name='name'
   void          object(const char* attr, Metadata* val);
   void          object(const char* attr, Handle val);
 
   // print the text alone (sans ''):
   void          method_text(methodHandle m);
-  void          klass_text(KlassHandle k);    // klass='name'
+  void          klass_text(Klass* k);         // klass='name'
   void          name_text(const Symbol* s);   // name='name'
   void          object_text(Metadata* x);
   void          object_text(Handle x);
--- a/hotspot/test/ProblemList.txt	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/ProblemList.txt	Thu Mar 16 16:40:41 2017 -0700
@@ -49,6 +49,64 @@
 compiler/types/correctness/CorrectnessTest.java 8066173 generic-all
 compiler/types/correctness/OffTest.java 8066173 generic-all
 
+# aot tests intermittently failing in jprt 8175791
+
+compiler/aot/RecompilationTest.java 8175791 windows-all
+compiler/aot/SharedUsageTest.java 8175791 windows-all
+compiler/aot/cli/MultipleAOTLibraryTest.java 8175791 windows-all
+compiler/aot/cli/DisabledAOTWithLibraryTest.java 8175791 windows-all
+compiler/aot/cli/SingleAOTLibraryTest.java 8175791 windows-all
+compiler/aot/cli/NonExistingAOTLibraryTest.java 8175791 windows-all
+compiler/aot/cli/SingleAOTOptionTest.java 8175791 windows-all
+compiler/aot/cli/jaotc/ClasspathOptionTest.java 8175791 windows-all
+compiler/aot/cli/jaotc/ListOptionTest.java 8175791 windows-all
+compiler/aot/cli/jaotc/CompileModuleTest.java 8175791 windows-all
+compiler/aot/cli/jaotc/CompileClassTest.java 8175791 windows-all
+compiler/aot/cli/jaotc/CompileJarTest.java 8175791 windows-all
+compiler/aot/cli/jaotc/ListOptionWrongFileTest.java 8175791 windows-all
+compiler/aot/cli/jaotc/CompileDirectoryTest.java 8175791 windows-all
+compiler/aot/cli/jaotc/ClasspathOptionUnknownClassTest.java 8175791 windows-all
+compiler/aot/cli/jaotc/ListOptionNotExistingTest.java 8175791 windows-all
+compiler/aot/cli/IncorrectAOTLibraryTest.java 8175791 windows-all
+compiler/aot/verification/vmflags/TrackedFlagTest.java 8175791 windows-all
+compiler/aot/verification/vmflags/NotTrackedFlagTest.java 8175791 windows-all
+compiler/aot/verification/ClassAndLibraryNotMatchTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeInterface2InterpretedTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeDynamic2CompiledTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeVirtual2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeVirtual2NativeTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeStatic2CompiledTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeStatic2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeSpecial2NativeTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeDynamic2InterpretedTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeVirtual2CompiledTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeSpecial2InterpretedTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeSpecial2CompiledTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeVirtual2InterpretedTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeStatic2InterpretedTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeInterface2CompiledTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeStatic2NativeTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeInterface2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeSpecial2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeDynamic2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeInterface2NativeTest.java 8175791 windows-all
+compiler/aot/calls/fromAot/AotInvokeDynamic2NativeTest.java 8175791 windows-all
+compiler/aot/calls/fromNative/NativeInvokeVirtual2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromNative/NativeInvokeStatic2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromNative/NativeInvokeSpecial2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromInterpreted/InterpretedInvokeDynamic2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromInterpreted/InterpretedInvokeSpecial2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromInterpreted/InterpretedInvokeStatic2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromInterpreted/InterpretedInvokeInterface2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromInterpreted/InterpretedInvokeVirtual2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromCompiled/CompiledInvokeStatic2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromCompiled/CompiledInvokeInterface2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromCompiled/CompiledInvokeSpecial2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromCompiled/CompiledInvokeVirtual2AotTest.java 8175791 windows-all
+compiler/aot/calls/fromCompiled/CompiledInvokeDynamic2AotTest.java 8175791 windows-all
+compiler/aot/DeoptimizationTest.java 8175791 windows-all
+
+
 #############################################################################
 
 # :hotspot_gc
--- a/hotspot/test/TEST.groups	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/TEST.groups	Thu Mar 16 16:40:41 2017 -0700
@@ -21,35 +21,6 @@
 # questions.
 #
 
-# Profile-based Test Group Definitions
-#
-# These groups define the tests that cover the different possible runtimes:
-# - compact1, compact2, compact3, full JRE, JDK
-#
-# In addition they support testing of the minimal VM on compact1 and compact2.
-# Essentially this defines groups based around the specified API's and VM
-# services available in the runtime.
-#
-# The groups are defined hierarchically in two forms:
-# - The need_xxx groups list all the tests that have a dependency on
-# a specific profile. This is either because it tests a feature in
-# that profile, or the test infrastructure uses a feature in that
-# profile.
-# - The primary groups are defined in terms of the other primary groups
-# combined with the needs_xxx groups (including and excluding them as
-# appropriate). For example the jre can run all tests from compact3, plus
-# those from needs_jre, but excluding those from need_jdk.
-#
-# The bottom group defines all the actual tests to be considered, simply
-# by listing the top-level test directories.
-#
-# To use a group simply list it on the jtreg command line eg:
-#   jtreg :jdk
-# runs all tests. While
-#   jtreg :compact2
-# runs those tests that only require compact1 and compact2 API's.
-#
-
 hotspot_all = \
   /
 
@@ -67,210 +38,16 @@
 
 hotspot_misc = \
   / \
+ -applications \
  -:hotspot_compiler \
  -:hotspot_gc \
  -:hotspot_runtime \
  -:hotspot_serviceability
 
-# Full JDK can run all tests
-#
-jdk = \
-  :jre \
-  :needs_jdk
-
-# Tests that require a full JDK to execute. Either they test a feature
-# only in the JDK or they use tools that are only in the JDK. The latter
-# can be resolved in some cases by using tools from the compile-jdk.
-#
-needs_jdk = \
-  compiler/aot \
-  gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java \
-  gc/metaspace/TestMetaspacePerfCounters.java \
-  gc/metaspace/TestPerfCountersAndMemoryPools.java \
-  runtime/6819213/TestBootNativeLibraryPath.java \
-  runtime/7158988/FieldMonitor.java \
-  runtime/Metaspace/FragmentMetaspace.java \
-  runtime/NMT/BaselineWithParameter.java \
-  runtime/NMT/JcmdBaselineDetail.java \
-  runtime/NMT/JcmdDetailDiff.java \
-  runtime/NMT/JcmdScaleDetail.java \
-  runtime/NMT/JcmdScale.java \
-  runtime/NMT/JcmdSummaryDiff.java \
-  runtime/NMT/JcmdWithNMTDisabled.java \
-  runtime/NMT/MallocRoundingReportTest.java \
-  runtime/NMT/MallocSiteHashOverflow.java \
-  runtime/NMT/MallocStressTest.java \
-  runtime/NMT/MallocTestType.java \
-  runtime/NMT/MallocTrackingVerify.java \
-  runtime/NMT/ReleaseCommittedMemory.java \
-  runtime/NMT/ReleaseNoCommit.java \
-  runtime/NMT/ShutdownTwice.java \
-  runtime/NMT/SummaryAfterShutdown.java \
-  runtime/NMT/SummarySanityCheck.java \
-  runtime/NMT/ThreadedMallocTestType.java \
-  runtime/NMT/ThreadedVirtualAllocTestType.java \
-  runtime/NMT/VirtualAllocCommitUncommitRecommit.java \
-  runtime/NMT/VirtualAllocTestType.java \
-  runtime/RedefineObject/TestRedefineObject.java \
-  runtime/Thread/TestThreadDumpMonitorContention.java \
-  runtime/Thread/ThreadPriorities.java \
-  runtime/XCheckJniJsig/XCheckJSig.java \
-  serviceability/attach/AttachWithStalePidFile.java \
-  serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java \
-  serviceability/dcmd/vm/DynLibsTest.java \
-  serviceability/tmtools
-
-
-# JRE adds further tests to compact3
-#
-jre = \
-  :compact3 \
-  :needs_jre \
- -:needs_jdk
-
-# Tests that require the full JRE
-#
-needs_jre = \
-  compiler/c2/Test6852078.java \
-  compiler/c2/Test7047069.java \
-  runtime/6294277/SourceDebugExtension.java \
-  runtime/ClassFile/JsrRewriting.java \
-  runtime/ClassFile/OomWhileParsingRepeatedJsr.java \
-  runtime/SharedArchiveFile/LimitSharedSizes.java \
-  runtime/SharedArchiveFile/SpaceUtilizationCheck.java
-
-# Compact 3 adds further tests to compact2
-#
-compact3 = \
-  :compact2 \
-  :needs_compact3 \
- -:needs_jre \
- -:needs_jdk
-
-
-# Tests that require compact3 API's
-#
-needs_compact3 = \
-  gc/TestFullGCCount.java \
-  gc/arguments/TestG1HeapRegionSize.java \
-  gc/arguments/TestDynMinHeapFreeRatio.java \
-  gc/arguments/TestDynMaxHeapFreeRatio.java \
-  gc/cms/TestMBeanCMS.java \
-  gc/g1/TestHumongousAllocInitialMark.java \
-  gc/g1/TestShrinkAuxiliaryData00.java \
-  gc/g1/TestShrinkAuxiliaryData05.java \
-  gc/g1/TestShrinkAuxiliaryData10.java \
-  gc/g1/TestShrinkAuxiliaryData15.java \
-  gc/g1/TestShrinkAuxiliaryData20.java \
-  gc/g1/TestShrinkAuxiliaryData25.java \
-  gc/g1/TestShrinkAuxiliaryData30.java \
-  gc/metaspace/TestMetaspaceMemoryPool.java \
-  gc/survivorAlignment \
-  runtime/InternalApi/ThreadCpuTimesDeadlock.java \
-  runtime/NMT/JcmdSummaryDiff.java \
-  runtime/RedefineTests/RedefineAnnotations.java \
-  serviceability/threads/TestFalseDeadLock.java \
-  compiler/codecache/jmx \
-  compiler/jsr292/RedefineMethodUsedByMultipleMethodHandles.java \
-  compiler/rangechecks/TestRangeCheckSmearing.java \
-  compiler/whitebox/DeoptimizeMultipleOSRTest.java \
-  serviceability/dcmd \
-  testlibrary_tests/whitebox/vm_flags
-
-# Compact 2 adds full VM tests
-compact2 = \
-  :compact2_minimal \
-  :compact1 \
-  :needs_full_vm_compact2 \
- -:needs_compact3 \
- -:needs_jre \
- -:needs_jdk
-
-# Tests that require compact2 API's and a full VM
-#
-needs_full_vm_compact2 =
-
-# Compact 1 adds full VM tests
-#
-compact1 = \
-  :compact1_minimal \
-  :needs_full_vm_compact1 \
- -:needs_compact2 \
- -:needs_full_vm_compact2 \
- -:needs_compact3 \
- -:needs_jre \
- -:needs_jdk
-
-# Tests that require compact1 API's and a full VM
-#
-needs_full_vm_compact1 = \
-  runtime/NMT \
-  gc/g1/TestRegionAlignment.java \
-  gc/g1/TestShrinkToOneRegion.java \
-  gc/metaspace/G1AddMetaspaceDependency.java \
-  gc/startup_warnings/TestCMS.java \
-  gc/startup_warnings/TestParallelGC.java \
-  gc/startup_warnings/TestParallelScavengeSerialOld.java \
-  runtime/SharedArchiveFile/SharedArchiveFile.java
-
-# Minimal VM on Compact 2 adds in some compact2 tests
-#
-compact2_minimal = \
-  :compact1_minimal \
-  :needs_compact2 \
- -:needs_full_vm_compact2 \
- -:needs_compact3 \
- -:needs_jre \
- -:needs_jdk
-
-# Tests that require compact2 API's
-#
-needs_compact2 = \
-  compiler/jsr292/CreatesInterfaceDotEqualsCallInfo.java
-
-# All tests that run on the most minimal configuration: Minimal VM on Compact 1
-compact1_minimal = \
-  serviceability/ \
-  compiler/ \
-  sanity/ \
-  runtime/ \
-  gc/ \
- -:needs_full_vm_compact1 \
- -:needs_full_vm_compact2 \
- -:needs_compact2 \
- -:needs_compact3 \
- -:needs_jre \
- -:needs_jdk
-
-# All tests that explicitly set the G1 GC
-#
-needs_g1gc = \
-  compiler/regalloc/C1ObjectSpillInLogicOp.java \
-  gc/TestHumongousReferenceObject.java \
-  gc/TestSmallHeap.java \
-  gc/TestSystemGC.java \
-  gc/arguments/TestAlignmentToUseLargePages.java \
-  gc/arguments/TestG1ConcRefinementThreads.java \
-  gc/arguments/TestG1HeapRegionSize.java \
-  gc/arguments/TestG1HeapSizeFlags.java \
-  gc/arguments/TestG1PercentageOptions.java \
-  gc/arguments/TestMaxHeapSizeTools.java \
-  gc/arguments/TestMaxNewSize.java \
-  gc/arguments/TestParallelGCThreads.java \
-  gc/arguments/TestUseCompressedOopsErgo.java \
-  gc/class_unloading/TestG1ClassUnloadingHWM.java \
-  gc/ergonomics/TestDynamicNumberOfGCThreads.java \
-  gc/g1/ \
-  gc/logging/TestGCId.java \
-  gc/metaspace/G1AddMetaspaceDependency.java \
-  gc/metaspace/TestMetaspacePerfCounters.java \
-  gc/startup_warnings/TestG1.java \
-  gc/whitebox/TestConcMarkCycleWB.java
-
 hotspot_native_sanity = \
   native_sanity
 
-hotspot_fast_compiler_1 = \
+hotspot_tier1_compiler_1 = \
   compiler/aot/ \
   compiler/arraycopy/ \
   compiler/c1/ \
@@ -286,7 +63,7 @@
   -compiler/c2/Test6603011.java \
   -compiler/c2/Test6912517.java \
 
-hotspot_fast_compiler_2 = \
+hotspot_tier1_compiler_2 = \
   compiler/classUnloading/ \
   compiler/codecache/ \
   compiler/codegen/ \
@@ -305,7 +82,7 @@
   -compiler/codecache/stress \
   -compiler/gcbarriers/PreserveFPRegistersTest.java
 
-hotspot_fast_compiler_3 = \
+hotspot_tier1_compiler_3 = \
   compiler/intrinsics/ \
   compiler/jsr292/ \
   compiler/loopopts/ \
@@ -326,20 +103,20 @@
   -compiler/loopopts/Test7052494.java \
   -compiler/runtime/Test6826736.java
 
-hotspot_fast_compiler_closed = \
+hotspot_tier1_compiler_closed = \
   sanity/ExecuteInternalVMTests.java
 
 hotspot_not_fast_compiler = \
   :hotspot_compiler \
-  -:hotspot_fast_compiler_1 \
-  -:hotspot_fast_compiler_2 \
-  -:hotspot_fast_compiler_3 \
-  -:hotspot_fast_compiler_closed
+  -:hotspot_tier1_compiler_1 \
+  -:hotspot_tier1_compiler_2 \
+  -:hotspot_tier1_compiler_3 \
+  -:hotspot_tier1_compiler_closed
 
-hotspot_fast_gc_1 = \
+hotspot_tier1_gc_1 = \
   gc/g1/
 
-hotspot_fast_gc_2 = \
+hotspot_tier1_gc_2 = \
   sanity/ExecuteInternalVMTests.java \
   gc/ \
   -gc/g1/ \
@@ -349,19 +126,19 @@
   -gc/cms/TestMBeanCMS.java \
   -gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java
 
-hotspot_fast_gc_closed = \
+hotspot_tier1_gc_closed = \
   sanity/ExecuteInternalVMTests.java
 
-hotspot_fast_gc_gcold = \
+hotspot_tier1_gc_gcold = \
   gc/stress/TestGCOld.java
 
-hotspot_fast_gc_gcbasher = \
+hotspot_tier1_gc_gcbasher = \
   gc/stress/gcbasher/TestGCBasherWithG1.java \
   gc/stress/gcbasher/TestGCBasherWithCMS.java \
   gc/stress/gcbasher/TestGCBasherWithSerial.java \
   gc/stress/gcbasher/TestGCBasherWithParallel.java
 
-hotspot_fast_runtime = \
+hotspot_tier1_runtime = \
   runtime/ \
  -runtime/6626217/Test6626217.sh \
  -runtime/7100935 \
@@ -371,6 +148,7 @@
  -runtime/ConstantPool/IntfMethod.java \
  -runtime/ErrorHandling/CreateCoredumpOnCrash.java \
  -runtime/ErrorHandling/ErrorHandler.java \
+ -runtime/ErrorHandling/TimeoutInErrorHandlingTest.java \
  -runtime/logging/MonitorMismatchTest.java \
  -runtime/memory/ReserveMemory.java \
  -runtime/memory/RunUnitTestsConcurrently.java \
@@ -405,58 +183,50 @@
   sanity/ \
   testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java
 
-hotspot_fast_serviceability = \
+hotspot_cds = \
+  runtime/SharedArchiveFile/ \
+  runtime/CompressedOops/
+
+
+hotspot_tier1_serviceability = \
   serviceability/dcmd/compiler \
   serviceability/logging
 
-hotspot_jprt = \
-  :hotspot_fast_compiler_1 \
-  :hotspot_fast_compiler_2 \
-  :hotspot_fast_compiler_3 \
-  :hotspot_fast_compiler_closed \
-  :hotspot_fast_gc_1 \
-  :hotspot_fast_gc_2 \
-  :hotspot_fast_gc_closed \
-  :hotspot_fast_gc_gcold \
-  :hotspot_fast_runtime \
-  :hotspot_fast_serviceability
+hotspot_tier1 = \
+  :hotspot_tier1_compiler_1 \
+  :hotspot_tier1_compiler_2 \
+  :hotspot_tier1_compiler_3 \
+  :hotspot_tier1_compiler_closed \
+  :hotspot_tier1_gc_1 \
+  :hotspot_tier1_gc_2 \
+  :hotspot_tier1_gc_closed \
+  :hotspot_tier1_gc_gcold \
+  :hotspot_tier1_runtime \
+  :hotspot_tier1_serviceability
 
-hotspot_runtime_tier2 = \
+hotspot_tier2_runtime = \
   runtime/ \
   serviceability/ \
  -runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java \
  -runtime/Thread/TestThreadDumpMonitorContention.java \
- -:hotspot_fast_runtime \
- -:hotspot_fast_serviceability \
- -:hotspot_runtime_tier2_platform_agnostic
+ -:hotspot_tier1_runtime \
+ -:hotspot_tier1_serviceability \
+ -:hotspot_tier2_runtime_platform_agnostic
 
-hotspot_runtime_tier2_platform_agnostic = \
+hotspot_tier2_runtime_platform_agnostic = \
   runtime/SelectionResolution \
- -:hotspot_fast_runtime
+ -:hotspot_tier1_runtime
 
-hotspot_runtime_tier3 = \
+hotspot_tier3_runtime = \
   runtime/ \
   serviceability/ \
- -:hotspot_fast_runtime \
- -:hotspot_fast_serviceability \
- -:hotspot_runtime_tier2_platform_agnostic \
- -:hotspot_runtime_tier2
+ -:hotspot_tier1_runtime \
+ -:hotspot_tier1_serviceability \
+ -:hotspot_tier2_runtime_platform_agnostic \
+ -:hotspot_tier2_runtime
 
 hotspot_runtime_minimalvm = \
   runtime/MinimalVM \
   runtime/ErrorHandling \
   runtime/logging
 
-#All tests that depends on nashorn extension.
-#
-needs_nashorn = \
-  compiler/jsr292/CreatesInterfaceDotEqualsCallInfo.java
-
-#All tests that do not depends on nashorn extension
-#
-not_needs_nashorn = \
-  :jdk \
-  -:needs_nashorn
-
-hotspot_tmtools = \
-  serviceability/tmtools
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/applications/scimark/Scimark.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @library /test/lib
+ * @run driver Scimark
+ */
+
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.artifacts.Artifact;
+import jdk.test.lib.artifacts.ArtifactResolver;
+import java.nio.file.Path;
+import java.util.HashMap;
+
+@Artifact(organization = "gov.nist.math", name = "scimark", revision = "2.0", extension = "zip")
+public class Scimark {
+    public static void main(String... args) throws Exception {
+        HashMap<String, Path> artifacts = ArtifactResolver.resolve(Scimark.class);
+
+        OutputAnalyzer output = new OutputAnalyzer(ProcessTools.createJavaProcessBuilder(
+            "-cp", artifacts.get("gov.nist.math.scimark-2.0").toString(),
+            "jnt.scimark2.commandline", "-large")
+            .start());
+        output.shouldHaveExitValue(0);
+    }
+}
--- a/hotspot/test/compiler/aot/DeoptimizationTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/DeoptimizationTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.aot.DeoptimizationTest
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/RecompilationTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/RecompilationTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.aot.RecompilationTest
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/SharedUsageTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/SharedUsageTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library /test/lib /testlibrary /
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @build compiler.aot.SharedUsageTest
  *        compiler.aot.AotCompiler
  * @run main compiler.aot.AotCompiler -libname libSharedUsageTest.so
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeDynamic2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeDynamic2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library /test/lib /testlibrary /
  * @ignore 8132547
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.org.objectweb.asm
  *          java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeDynamic
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeDynamic2CompiledTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeDynamic2CompiledTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library /test/lib /testlibrary /
  * @ignore 8132547
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.org.objectweb.asm
  *          java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeDynamic
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeDynamic2InterpretedTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeDynamic2InterpretedTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library /test/lib /testlibrary /
  * @ignore 8132547
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.org.objectweb.asm
  *          java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeDynamic
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeDynamic2NativeTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeDynamic2NativeTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library /test/lib /testlibrary /
  * @ignore 8132547
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.org.objectweb.asm
  *          java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeDynamic
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeInterface2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeInterface2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeInterface
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeInterface2CompiledTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeInterface2CompiledTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeInterface
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeInterface2InterpretedTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeInterface2InterpretedTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeInterface
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeInterface2NativeTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeInterface2NativeTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeInterface
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeSpecial2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeSpecial2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeSpecial
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeSpecial2CompiledTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeSpecial2CompiledTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeSpecial
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeSpecial2InterpretedTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeSpecial2InterpretedTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeSpecial
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeSpecial2NativeTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeSpecial2NativeTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeSpecial
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeStatic2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeStatic2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeStatic
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeStatic2CompiledTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeStatic2CompiledTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeStatic
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeStatic2InterpretedTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeStatic2InterpretedTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeStatic
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeStatic2NativeTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeStatic2NativeTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeStatic
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeVirtual2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeVirtual2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeVirtual
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeVirtual2CompiledTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeVirtual2CompiledTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeVirtual
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeVirtual2InterpretedTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeVirtual2InterpretedTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeVirtual
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromAot/AotInvokeVirtual2NativeTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromAot/AotInvokeVirtual2NativeTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeVirtual
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromCompiled/CompiledInvokeDynamic2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromCompiled/CompiledInvokeDynamic2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.org.objectweb.asm
  *          java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeDynamic
--- a/hotspot/test/compiler/aot/calls/fromCompiled/CompiledInvokeInterface2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromCompiled/CompiledInvokeInterface2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeInterface
  *      compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromCompiled/CompiledInvokeSpecial2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromCompiled/CompiledInvokeSpecial2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeSpecial
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromCompiled/CompiledInvokeStatic2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromCompiled/CompiledInvokeStatic2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeStatic
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromCompiled/CompiledInvokeVirtual2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromCompiled/CompiledInvokeVirtual2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeVirtual
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromInterpreted/InterpretedInvokeDynamic2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromInterpreted/InterpretedInvokeDynamic2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.org.objectweb.asm
  *          java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeDynamic
--- a/hotspot/test/compiler/aot/calls/fromInterpreted/InterpretedInvokeInterface2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromInterpreted/InterpretedInvokeInterface2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeInterface
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromInterpreted/InterpretedInvokeSpecial2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromInterpreted/InterpretedInvokeSpecial2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeSpecial
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromInterpreted/InterpretedInvokeStatic2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromInterpreted/InterpretedInvokeStatic2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeStatic
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromInterpreted/InterpretedInvokeVirtual2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromInterpreted/InterpretedInvokeVirtual2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeVirtual
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromNative/NativeInvokeSpecial2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromNative/NativeInvokeSpecial2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeSpecial
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromNative/NativeInvokeStatic2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromNative/NativeInvokeStatic2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeStatic
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/calls/fromNative/NativeInvokeVirtual2AotTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/calls/fromNative/NativeInvokeVirtual2AotTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.calls.common.InvokeVirtual
  *        compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/cli/DisabledAOTWithLibraryTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/DisabledAOTWithLibraryTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /testlibrary /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @build compiler.aot.cli.DisabledAOTWithLibraryTest
  *        compiler.aot.AotCompiler
  * @run driver compiler.aot.AotCompiler -libname libDisabledAOTWithLibraryTest.so
--- a/hotspot/test/compiler/aot/cli/IncorrectAOTLibraryTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/IncorrectAOTLibraryTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library /test/lib /testlibrary /
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @run driver ClassFileInstaller ClassFileInstaller
  * @run driver compiler.aot.cli.IncorrectAOTLibraryTest
  * @summary check if incorrect aot library is handled properly
--- a/hotspot/test/compiler/aot/cli/MultipleAOTLibraryTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/MultipleAOTLibraryTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library /test/lib /testlibrary /
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @build compiler.aot.cli.MultipleAOTLibraryTest
  *        compiler.aot.AotCompiler
  * @run driver compiler.aot.AotCompiler
--- a/hotspot/test/compiler/aot/cli/NonExistingAOTLibraryTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/NonExistingAOTLibraryTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library /test/lib /testlibrary /
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @run driver compiler.aot.cli.NonExistingAOTLibraryTest
  * @summary check if non-existing aot library is handled properly
  */
@@ -38,7 +38,7 @@
     private static final String PATH = "./NonExisting.so";
     private static final String OPTION = "-XX:AOTLibrary=" + PATH;
     private static final String[] EXPECTED_MESSAGES = new String[] {
-        "cannot open shared object file"
+        "error opening file"
     };
 
     public static void main(String args[]) {
--- a/hotspot/test/compiler/aot/cli/SingleAOTLibraryTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/SingleAOTLibraryTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library /test/lib / /testlibrary
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @build compiler.aot.cli.SingleAOTLibraryTest
  *        compiler.aot.AotCompiler
  * @run driver compiler.aot.AotCompiler -libname libSingleAOTLibraryTest.so
--- a/hotspot/test/compiler/aot/cli/SingleAOTOptionTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/SingleAOTOptionTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library /test/lib /testlibrary /
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @build compiler.aot.cli.SingleAOTOptionTest
  *        compiler.aot.AotCompiler
  * @run driver compiler.aot.AotCompiler -libname libSingleAOTOptionTest.so
--- a/hotspot/test/compiler/aot/cli/jaotc/ClasspathOptionUnknownClassTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/jaotc/ClasspathOptionUnknownClassTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library / /testlibrary/ /test/lib
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @compile data/HelloWorldOne.java
  * @run driver compiler.aot.cli.jaotc.ClasspathOptionUnknownClassTest
  * @summary check jaotc can't compile class not from classpath
--- a/hotspot/test/compiler/aot/cli/jaotc/CompileClassTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/jaotc/CompileClassTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library / /test/lib /testlibrary
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @build compiler.aot.cli.jaotc.CompileClassTest
  * @run driver ClassFileInstaller compiler.aot.cli.jaotc.data.HelloWorldOne
  * @run driver compiler.aot.cli.jaotc.CompileClassTest
--- a/hotspot/test/compiler/aot/cli/jaotc/CompileDirectoryTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/jaotc/CompileDirectoryTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library / /test/lib /testlibrary
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @build compiler.aot.cli.jaotc.CompileDirectoryTest
  * @run driver ClassFileInstaller compiler.aot.cli.jaotc.data.HelloWorldOne
  *                                compiler.aot.cli.jaotc.data.HelloWorldTwo
--- a/hotspot/test/compiler/aot/cli/jaotc/CompileJarTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/jaotc/CompileJarTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library / /test/lib /testlibrary
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @build compiler.aot.cli.jaotc.CompileJarTest
  * @run driver ClassFileInstaller compiler.aot.cli.jaotc.data.HelloWorldOne
  *                                compiler.aot.cli.jaotc.data.HelloWorldTwo
--- a/hotspot/test/compiler/aot/cli/jaotc/CompileModuleTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/jaotc/CompileModuleTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library / /test/lib /testlibrary
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @run driver compiler.aot.cli.jaotc.CompileModuleTest
  * @summary check jaotc can compile module
  */
--- a/hotspot/test/compiler/aot/cli/jaotc/JaotcTestHelper.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/jaotc/JaotcTestHelper.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -72,7 +72,7 @@
     }
 
     public static String getClassAotCompilationFilename(Class<?> classToCompile) {
-        return classToCompile.getName().replaceAll("\\.", File.separator) + ".class";
+        return classToCompile.getName().replaceAll("\\.","/") + ".class";
     }
 
     public static String getClassAotCompilationName(Class<?> classToCompile) {
--- a/hotspot/test/compiler/aot/cli/jaotc/ListOptionNotExistingTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/jaotc/ListOptionNotExistingTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library / /test/lib /testlibrary
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @build compiler.aot.cli.jaotc.ListOptionNotExistingTest
  * @run driver ClassFileInstaller compiler.aot.cli.jaotc.data.HelloWorldOne
  * @run driver compiler.aot.cli.jaotc.ListOptionNotExistingTest
--- a/hotspot/test/compiler/aot/cli/jaotc/ListOptionTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/jaotc/ListOptionTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library / /test/lib /testlibrary
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @build compiler.aot.cli.jaotc.ListOptionTest
  * @run driver ClassFileInstaller compiler.aot.cli.jaotc.data.HelloWorldOne
  * @run driver compiler.aot.cli.jaotc.ListOptionTest
--- a/hotspot/test/compiler/aot/cli/jaotc/ListOptionWrongFileTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/cli/jaotc/ListOptionWrongFileTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
  * @test
  * @library / /test/lib /testlibrary
  * @modules java.base/jdk.internal.misc
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @build compiler.aot.cli.jaotc.ListOptionWrongFileTest
  * @run driver ClassFileInstaller compiler.aot.cli.jaotc.data.HelloWorldOne
  * @run driver compiler.aot.cli.jaotc.ListOptionWrongFileTest
--- a/hotspot/test/compiler/aot/jdk.tools.jaotc.jnilibelf.test/src/jdk/tools/jaotc/jnilibelf/test/JNILibELFTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-/*
- * 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.
- */
-
-package jdk.tools.jaotc.jnilibelf.test;
-
-import java.nio.ByteBuffer;
-import java.nio.IntBuffer;
-
-import jdk.tools.jaotc.jnilibelf.JNIELFContainer;
-import jdk.tools.jaotc.jnilibelf.JNILibELFAPI.ELF;
-import jdk.tools.jaotc.jnilibelf.JNILibELFAPI.LibELF.Elf_Cmd;
-import jdk.tools.jaotc.jnilibelf.JNILibELFAPI.LibELF.Elf_Type;
-
-public class JNILibELFTest {
-
-    public static void main(String[] args) {
-        // if (args.length != 2) {
-        // System.out.println("Please provide file-name as argument");
-        // return;
-        // }
-        createSharedLib();
-    }
-
-    private static boolean createSharedLib() {
-
-        int numProgHdrs = 1;
-        JNIELFContainer elfContainer = new JNIELFContainer("ELF");
-
-        // Allocate ELF Header
-        elfContainer.createELFHeader(ELF.ET_DYN);
-
-        // Allocate 'numProgHdrs' program headers
-
-        if (!elfContainer.createProgramHeader(numProgHdrs)) {
-            System.out.println("Failed to create Program Headers");
-            return false;
-        }
-
-        // Hash table content
-        int[] bhashWords = {0x01234567, 0x89abcdef, 0xdeadc0de};
-        // int[] data = { 100, 200, 300, 400 };
-
-        ByteBuffer byteBuffer = ByteBuffer.allocate(bhashWords.length * 4);
-        IntBuffer intBuffer = byteBuffer.asIntBuffer();
-        intBuffer.put(bhashWords);
-
-        // byte[] int_hash_array = byteBuffer.array();
-
-        // Hash Table content
-        // ByteBuffer hash_words = ByteBuffer.allocate(14).putInt(0x01234567);
-        // hash_words.putInt(0x89abcdef);
-        // hash_words.putInt(0xdeadc0de);
-
-        // Create a hash section
-        // Setting sh_link as 0 since this is just a demo - the value should actually be the section
-        // header index
-        // of the symbol table to which the hash table applies.
-        int index = elfContainer.createSection(".hash", byteBuffer.array(), Elf_Type.ELF_T_WORD, 4, ELF.SHT_HASH, ELF.SHF_ALLOC, 0, 0);
-        if (index == 0) {
-            System.out.println("Failed to create hash section");
-            return false;
-        }
-
-        elfContainer.createSection(".strtab", elfContainer.getStrTabContent().getBytes(), Elf_Type.ELF_T_BYTE, 1, ELF.SHT_STRTAB, (ELF.SHF_STRINGS | ELF.SHF_ALLOC), ELF.SHN_UNDEF, 0);
-        // Now, finally, after creating all sections, create shstrtab section
-        elfContainer.createSection(".shstrtab", elfContainer.getShStrTabContent().getBytes(), Elf_Type.ELF_T_BYTE, 1, ELF.SHT_STRTAB, 0, ELF.SHN_UNDEF, 0);
-        // Run elf_update
-        elfContainer.elfUpdate(Elf_Cmd.ELF_C_NULL);
-
-        // Set program header type to self
-        elfContainer.setProgHdrTypeToSelf();
-        // Setting pheader to self type also sets it to be dirty. So run elfUpdate again
-        // to write it out.
-        elfContainer.elfUpdate(Elf_Cmd.ELF_C_WRITE);
-        // Finish ELF processing
-        elfContainer.elfEnd();
-        return true;
-    }
-}
--- a/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/NativeOrderOutputStreamTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/NativeOrderOutputStreamTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @requires os.family == "linux" & vm.bits == "64" & os.arch == "amd64"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules jdk.aot/jdk.tools.jaotc.utils
  * @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI jdk.tools.jaotc.test.NativeOrderOutputStreamTest
  */
--- a/hotspot/test/compiler/aot/verification/ClassAndLibraryNotMatchTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/verification/ClassAndLibraryNotMatchTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.aot.verification.ClassAndLibraryNotMatchTest
  * @run driver compiler.aot.verification.ClassAndLibraryNotMatchTest
--- a/hotspot/test/compiler/aot/verification/vmflags/NotTrackedFlagTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/verification/vmflags/NotTrackedFlagTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.aot.verification.vmflags.BasicFlagsChange
  * @run driver compiler.aot.verification.vmflags.BasicFlagsChange
--- a/hotspot/test/compiler/aot/verification/vmflags/TrackedFlagTest.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/compiler/aot/verification/vmflags/TrackedFlagTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @library /test/lib /
- * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
+ * @requires vm.bits == "64" & (os.arch == "amd64" | os.arch == "x86_64")
  * @modules java.base/jdk.internal.misc
  * @build compiler.aot.verification.vmflags.BasicFlagsChange
  * @run driver compiler.aot.verification.vmflags.BasicFlagsChange
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/arguments/TestSmallInitialHeapWithLargePageAndNUMA.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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 TestSmallInitialHeapWithLargePageAndNUMA
+ * @bug 8023905
+ * @requires os.family == "linux"
+ * @requires vm.gc.Parallel
+ * @summary Check large pages and NUMA are working together via the output message.
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ * @modules java.management/sun.management
+ * @build TestSmallInitialHeapWithLargePageAndNUMA
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UseHugeTLBFS -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestSmallInitialHeapWithLargePageAndNUMA
+*/
+
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+import sun.hotspot.WhiteBox;
+
+public class TestSmallInitialHeapWithLargePageAndNUMA {
+
+  private static final String MSG_EXIT_TOO_SMALL_HEAP = "Failed initializing NUMA with large pages. Too small heap size";
+  private static final String MSG_GC_TRIGGERED_BEFORE_INIT = "GC triggered before VM initialization completed.";
+
+  public static void main(String[] args) throws Exception {
+
+    WhiteBox wb = WhiteBox.getWhiteBox();
+    long heapAlignment = wb.getHeapAlignment();
+
+    // When using large pages, Linux does not support freeing parts of reserved and committed memory.
+    // And current Linux implementation uses page size as a condition to actually freeing memory.
+    // If we allocate pages less than NUMA node, NUMA will try to use default page size and
+    // this will free the memory which Linux does not support.
+    // Assume the minimum NUMA node as 2.
+    long initHeap = heapAlignment;
+    long maxHeap = heapAlignment * 2;
+
+    String[] vmArgs = {"-XX:+UseParallelGC",
+                       "-Xms" + String.valueOf(initHeap),
+                       "-Xmx" + String.valueOf(maxHeap),
+                       "-XX:+UseNUMA",
+                       "-XX:+UseHugeTLBFS",
+                       "-XX:+PrintFlagsFinal",
+                       "-version"};
+
+    ProcessBuilder pb_enabled = ProcessTools.createJavaProcessBuilder(vmArgs);
+    OutputAnalyzer analyzer = new OutputAnalyzer(pb_enabled.start());
+
+    if (largePageOrNumaEnabled(analyzer)) {
+      // We reach here, if both NUMA and HugeTLB are supported.
+      // However final flags will not be printed as NUMA initialization will be failed.
+      checkAnalyzerValues(analyzer, 1, MSG_EXIT_TOO_SMALL_HEAP);
+    }
+  }
+
+  // If both NUMA and large pages are enabled, VM will exit during NUMA initialization
+  // under the small heap configuration. So final flags will not be printed.
+  private static boolean largePageOrNumaEnabled(OutputAnalyzer analyzer) {
+    String output = analyzer.getOutput();
+
+    return !output.contains("[Global flags]");
+  }
+
+  // We need to test with small heap but fastdebug binary fails to initialize because of the small heap.
+  // So skip that case.
+  private static void checkAnalyzerValues(OutputAnalyzer analyzer, int expectedExitValue, String expectedMessage) {
+    String output = analyzer.getOutput();
+
+    // If the VM exits because of the small heap, skip checking the exit value.
+    if (!output.contains(MSG_GC_TRIGGERED_BEFORE_INIT)) {
+      analyzer.shouldHaveExitValue(expectedExitValue);
+    }
+    if (expectedMessage != null) {
+      analyzer.shouldContain(expectedMessage);
+    }
+  }
+}
--- a/hotspot/test/gc/g1/TestGCLogMessages.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/gc/g1/TestGCLogMessages.java	Thu Mar 16 16:40:41 2017 -0700
@@ -115,6 +115,12 @@
         new LogMessageWithLevel("Preserve CM Refs", Level.DEBUG),
         // Merge PSS
         new LogMessageWithLevel("Merge Per-Thread State", Level.DEBUG),
+        // TLAB handling
+        new LogMessageWithLevel("Prepare TLABs", Level.DEBUG),
+        new LogMessageWithLevel("Resize TLABs", Level.DEBUG),
+
+        new LogMessageWithLevel("DerivedPointerTable Update", Level.DEBUG),
+        new LogMessageWithLevel("Start New Collection Set", Level.DEBUG),
     };
 
     void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], Level level) throws Exception {
--- a/hotspot/test/native/memory/test_chunkManager.cpp	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/native/memory/test_chunkManager.cpp	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017 Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,26 @@
   // The ChunkManager is only available in metaspace.cpp,
   // so the test code is located in that file.
   ChunkManager_test_list_index();
+
 }
 
+extern void* setup_chunkmanager_returntests();
+extern void teardown_chunkmanager_returntests(void*);
+extern void run_chunkmanager_returntests(void* p, float phase_length_factor);
+
+class ChunkManagerReturnTest : public ::testing::Test {
+protected:
+  void* _test;
+  virtual void SetUp() {
+    _test = setup_chunkmanager_returntests();
+  }
+  virtual void TearDown() {
+    teardown_chunkmanager_returntests(_test);
+  }
+};
+
+TEST_VM_F(ChunkManagerReturnTest, test00) { run_chunkmanager_returntests(_test, 0.0f); }
+TEST_VM_F(ChunkManagerReturnTest, test05) { run_chunkmanager_returntests(_test, 0.5f); }
+TEST_VM_F(ChunkManagerReturnTest, test10) { run_chunkmanager_returntests(_test, 1.0f); }
+
 #endif // ASSERT
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/ErrorHandling/TimeoutInErrorHandlingTest.java	Thu Mar 16 16:40:41 2017 -0700
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.util.regex.Pattern;
+
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.Platform;
+import jdk.test.lib.process.ProcessTools;
+
+/*
+ * @test
+ * @bug 8166944
+ * @summary Hanging Error Reporting steps may lead to torn error logs
+ * @modules java.base/jdk.internal.misc
+ * @library /test/lib
+ * @requires (vm.debug == true) & (os.family != "windows")
+ * @author Thomas Stuefe (SAP)
+ */
+
+public class TimeoutInErrorHandlingTest {
+
+
+    public static void main(String[] args) throws Exception {
+
+        /* Start the VM and let it crash. Specify TestUnresponsiveErrorHandler which will
+         * let five subsequent error reporting steps hang. The Timeout handling triggered
+         * by the WatcherThread should kick in and interrupt those steps. In theory, the
+         * text "timeout occurred during error reporting in step .." (the little timeouts)
+         * should occur in the error log up to four times, followed by the final big timeout
+         * "------ Timeout during error reporting after xx s. ------"
+         *
+         * Note that there are a number of uncertainties which make writing a 100% foolproof
+         * test challenging. The time the error reporting thread takes to react to the
+         * timeout triggers is unknown. So it is difficult to predict how many little timeouts
+         * will be visible before the big timeout kicks in. Also, once the big timeout hits,
+         * error reporting thread and Watcherthread will race. The former writes his last
+         * message to the error logs and flushes, the latter waits 200ms and then exits the
+         * process without further synchronization with the error reporting thread.
+         *
+         * Because of all this and the desire to write a bullet proof test which does
+         * not fail sporadically, we will not test for the final timeout message nor for all
+         * of the optimally expected little timeout messages. We just test for two of the
+         * little timeout messages to see that repeated timeout handling is basically working.
+         */
+
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+            "-XX:+UnlockDiagnosticVMOptions",
+            "-Xmx100M",
+            "-XX:ErrorHandlerTest=14",
+            "-XX:+TestUnresponsiveErrorHandler",
+            "-XX:ErrorLogTimeout=16", // 16 seconds big timeout = 4 seconds per little timeout
+            "-XX:-CreateCoredumpOnCrash",
+            "-version");
+
+        OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());
+
+        // we should have crashed with a SIGSEGV
+        output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");
+        output_detail.shouldMatch("# +(?:SIGSEGV|EXCEPTION_ACCESS_VIOLATION).*");
+
+        // VM should have been aborted by WatcherThread
+        output_detail.shouldMatch(".*timer expired, abort.*");
+
+        // extract hs-err file
+        String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);
+        if (hs_err_file == null) {
+            throw new RuntimeException("Did not find hs-err file in output.\n");
+        }
+
+        File f = new File(hs_err_file);
+        if (!f.exists()) {
+            throw new RuntimeException("hs-err file missing at "
+                + f.getAbsolutePath() + ".\n");
+        }
+
+        System.out.println("Found hs_err file. Scanning...");
+
+        FileInputStream fis = new FileInputStream(f);
+        BufferedReader br = new BufferedReader(new InputStreamReader(fis));
+        String line = null;
+
+
+
+        Pattern [] pattern = new Pattern[] {
+            Pattern.compile(".*timeout occurred during error reporting in step.*"),
+            Pattern.compile(".*timeout occurred during error reporting in step.*")
+        };
+        int currentPattern = 0;
+
+        String lastLine = null;
+        while ((line = br.readLine()) != null) {
+            if (currentPattern < pattern.length) {
+              if (pattern[currentPattern].matcher(line).matches()) {
+                System.out.println("Found: " + line + ".");
+                currentPattern ++;
+              }
+            }
+            lastLine = line;
+        }
+        br.close();
+
+        if (currentPattern < pattern.length) {
+            throw new RuntimeException("hs-err file incomplete (first missing pattern: " +  currentPattern + ")");
+        }
+
+        System.out.println("OK.");
+
+    }
+
+}
+
--- a/hotspot/test/runtime/modules/JVMDefineModule.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/runtime/modules/JVMDefineModule.java	Thu Mar 16 16:40:41 2017 -0700
@@ -105,17 +105,6 @@
             }
         }
 
-        // Duplicates in package list, expect an IAE
-        m = ModuleHelper.ModuleObject("module.x", cl, new String[] { "mypackage4", "mypackage5" });
-        try {
-            ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage4", "mypackage5", "mypackage4" });
-            throw new RuntimeException("Failed to get IAE for duplicate packages");
-        } catch(IllegalArgumentException e) {
-            if (!e.getMessage().contains("Duplicate package name")) {
-              throw new RuntimeException("Failed to get expected IAE message for duplicate package: " + e.getMessage());
-            }
-        }
-
         // Empty entry in package list, expect an IAE
         m = ModuleHelper.ModuleObject("module.y", cl, new String[] { "mypackageX", "mypackageY" });
         try {
--- a/hotspot/test/runtime/modules/JVMGetModuleByPkgName.java	Wed Jul 05 23:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * 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
- * @modules java.base/jdk.internal.misc
- * @library /test/lib ..
- * @compile p2/c2.java
- * @build sun.hotspot.WhiteBox
- * @compile/module=java.base java/lang/reflect/ModuleHelper.java
- * @run main ClassFileInstaller sun.hotspot.WhiteBox
- *                              sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI JVMGetModuleByPkgName
- */
-
-import static jdk.test.lib.Asserts.*;
-import java.lang.ClassLoader;
-import java.lang.reflect.Module;
-
-public class JVMGetModuleByPkgName {
-
-    public static void main(String args[]) throws Throwable {
-
-        Module javaBase = ModuleHelper.GetModuleByPackageName(null, "java/lang");
-        if (!javaBase.getName().equals("java.base")) {
-            throw new RuntimeException(
-                "Failed to get module java.base for package java/lang");
-        }
-
-        if (ModuleHelper.GetModuleByPackageName(null, "bad.package.name") != null) {
-            throw new RuntimeException("Failed to get null for bad.package.name");
-        }
-
-        ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
-        if (ModuleHelper.GetModuleByPackageName(systemLoader, "java/lang") != null) {
-            throw new RuntimeException(
-                "Failed to get null for systemClassLoader and java/lang");
-        }
-
-        try {
-            ModuleHelper.GetModuleByPackageName(systemLoader, null);
-            throw new RuntimeException(
-                "Failed to throw NullPointerException for null package name");
-        } catch(NullPointerException e) {
-             // Expected
-        }
-
-        Module unnamedModule = ModuleHelper.GetModuleByPackageName(systemLoader, "");
-        if (unnamedModule.isNamed()) {
-            throw new RuntimeException(
-                "Unexpected named module returned for unnamed package");
-        }
-
-        p2.c2 obj = new p2.c2();
-        unnamedModule = ModuleHelper.GetModuleByPackageName(systemLoader, "p2");
-        if (unnamedModule.isNamed()) {
-            throw new RuntimeException(
-                "Unexpected named module returned for package p2 in unnamed module");
-        }
-
-        MyClassLoader cl1 = new MyClassLoader();
-        Module module_one = (Module)ModuleHelper.ModuleObject("module_one", cl1, new String[] { "mypackage" });
-        assertNotNull(module_one, "Module should not be null");
-        ModuleHelper.DefineModule(module_one, "9.0", "module_one/here", new String[] { "mypackage" });
-        if (ModuleHelper.GetModuleByPackageName(cl1, "mypackage") != module_one) {
-            throw new RuntimeException("Wrong module returned for cl1 mypackage");
-        }
-    }
-
-    static class MyClassLoader extends ClassLoader { }
-}
--- a/hotspot/test/runtime/modules/ModuleHelper.java	Wed Jul 05 23:02:24 2017 +0200
+++ b/hotspot/test/runtime/modules/ModuleHelper.java	Thu Mar 16 16:40:41 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -56,11 +56,6 @@
         java.lang.reflect.ModuleHelper.addPackageNoSync((Module)m, pkg);
     }
 
-    public static Module GetModuleByPackageName(Object ldr, String pkg) throws Throwable {
-        WhiteBox wb = WhiteBox.getWhiteBox();
-        return (Module)wb.GetModuleByPackageName(ldr, pkg);
-    }
-
     public static void AddModuleExportsToAllUnnamed(Object m, String pkg) throws Throwable {
         WhiteBox wb = WhiteBox.getWhiteBox();
         wb.AddModuleExportsToAllUnnamed(m, pkg);