changeset 11448:72fa30e09fcd

Merge
author thartmann
date Tue, 07 Jun 2016 09:11:32 +0000
parents 10d071c3fa1f 4fce6a99a262
children 8805ad288804
files test/runtime/Unsafe/GetKlassPointerGetJavaMirror.java
diffstat 106 files changed, 1680 insertions(+), 558 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Mon Jun 06 23:24:46 2016 -0700
+++ b/.hgtags	Tue Jun 07 09:11:32 2016 +0000
@@ -522,3 +522,4 @@
 88170d3642905b9e6cac03e8efcc976885a7e6da jdk-9+117
 9b1075cac08dc836ec32e7b368415cbe3aceaf8c jdk-9+118
 15f3fe264872766bcb205696198f0c1502420e17 jdk-9+119
+0be6f4f5d18671184e62583668cb1d783dffa128 jdk-9+120
--- a/LICENSE	Mon Jun 06 23:24:46 2016 -0700
+++ b/LICENSE	Tue Jun 07 09:11:32 2016 +0000
@@ -3,7 +3,7 @@
 Version 2, June 1991
 
 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 Everyone is permitted to copy and distribute verbatim copies of this license
 document, but changing it is not allowed.
@@ -287,8 +287,8 @@
     more details.
 
     You should have received a copy of the GNU General Public License along
-    with this program; if not, write to the Free Software Foundation, Inc., 59
-    Temple Place, Suite 330, Boston, MA 02111-1307 USA
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 Also add information on how to contact you by electronic and paper mail.
 
--- a/src/cpu/ppc/vm/assembler_ppc.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/cpu/ppc/vm/assembler_ppc.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -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, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1547,6 +1547,10 @@
   inline void ld(   Register d, int si16,    Register s1);
   inline void ldu(  Register d, int si16,    Register s1);
 
+  // For convenience. Load pointer into d from b+s1.
+  inline void ld_ptr(Register d, int b, Register s1);
+  DEBUG_ONLY(inline void ld_ptr(Register d, ByteSize b, Register s1);)
+
   //  PPC 1, section 3.3.3 Fixed-Point Store Instructions
   inline void stwx( Register d, Register s1, Register s2);
   inline void stw(  Register d, int si16,    Register s1);
@@ -2215,7 +2219,8 @@
   void add( Register d, RegisterOrConstant roc, Register s1);
   void subf(Register d, RegisterOrConstant roc, Register s1);
   void cmpd(ConditionRegister d, RegisterOrConstant roc, Register s1);
-
+  // Load pointer d from s1+roc.
+  void ld_ptr(Register d, RegisterOrConstant roc, Register s1 = noreg) { ld(d, roc, s1); }
 
   // Emit several instructions to load a 64 bit constant. This issues a fixed
   // instruction pattern so that the constant can be patched later on.
--- a/src/cpu/ppc/vm/assembler_ppc.inline.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/cpu/ppc/vm/assembler_ppc.inline.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -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, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -328,6 +328,9 @@
 inline void Assembler::ldx(  Register d, Register s1, Register s2) { emit_int32(LDX_OPCODE | rt(d) | ra0mem(s1) | rb(s2));}
 inline void Assembler::ldu(  Register d, int si16,    Register s1) { assert(d != s1, "according to ibm manual"); emit_int32(LDU_OPCODE | rt(d) | ds(si16) | rta0mem(s1));}
 
+inline void Assembler::ld_ptr(Register d, int b, Register s1) { ld(d, b, s1); }
+DEBUG_ONLY(inline void Assembler::ld_ptr(Register d, ByteSize b, Register s1) { ld(d, in_bytes(b), s1); })
+
 //  PPC 1, section 3.3.3 Fixed-Point Store Instructions
 inline void Assembler::stwx( Register d, Register s1, Register s2) { emit_int32(STWX_OPCODE | rs(d) | ra0mem(s1) | rb(s2));}
 inline void Assembler::stw(  Register d, int si16,    Register s1) { emit_int32(STW_OPCODE  | rs(d) | d1(si16)   | ra0mem(s1));}
--- a/src/cpu/ppc/vm/c1_LIRAssembler_ppc.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/cpu/ppc/vm/c1_LIRAssembler_ppc.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1242,7 +1242,7 @@
 
 
 void LIR_Assembler::return_op(LIR_Opr result) {
-  const Register return_pc        = R11;
+  const Register return_pc        = R31;  // Must survive C-call to enable_stack_reserved_zone().
   const Register polling_page     = R12;
 
   // Pop the stack before the safepoint code.
@@ -1265,6 +1265,10 @@
   // Move return pc to LR.
   __ mtlr(return_pc);
 
+  if (StackReservedPages > 0 && compilation()->has_reserved_stack_access()) {
+    __ reserved_stack_check(return_pc);
+  }
+
   // We need to mark the code position where the load from the safepoint
   // polling page was emitted as relocInfo::poll_return_type here.
   __ relocate(relocInfo::poll_return_type);
--- a/src/cpu/ppc/vm/globalDefinitions_ppc.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/cpu/ppc/vm/globalDefinitions_ppc.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -52,4 +52,6 @@
 #define INCLUDE_RTM_OPT 1
 #endif
 
+#define SUPPORT_RESERVED_STACK_AREA
+
 #endif // CPU_PPC_VM_GLOBALDEFINITIONS_PPC_HPP
--- a/src/cpu/ppc/vm/globals_ppc.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/cpu/ppc/vm/globals_ppc.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -43,7 +43,7 @@
 #define DEFAULT_STACK_YELLOW_PAGES (6)
 #define DEFAULT_STACK_RED_PAGES (1)
 #define DEFAULT_STACK_SHADOW_PAGES (6 DEBUG_ONLY(+2))
-#define DEFAULT_STACK_RESERVED_PAGES (0)
+#define DEFAULT_STACK_RESERVED_PAGES (1)
 
 #define MIN_STACK_YELLOW_PAGES DEFAULT_STACK_YELLOW_PAGES
 #define MIN_STACK_RED_PAGES DEFAULT_STACK_RED_PAGES
--- a/src/cpu/ppc/vm/interp_masm_ppc_64.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/cpu/ppc/vm/interp_masm_ppc_64.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
+ * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -480,6 +480,7 @@
 
 void InterpreterMacroAssembler::generate_stack_overflow_check_with_compare_and_throw(Register Rmem_frame_size, Register Rscratch1) {
   Label done;
+  BLOCK_COMMENT("stack_overflow_check_with_compare_and_throw {");
   sub(Rmem_frame_size, R1_SP, Rmem_frame_size);
   ld(Rscratch1, thread_(stack_overflow_limit));
   cmpld(CCR0/*is_stack_overflow*/, Rmem_frame_size, Rscratch1);
@@ -501,6 +502,7 @@
 
   align(32, 12);
   bind(done);
+  BLOCK_COMMENT("} stack_overflow_check_with_compare_and_throw");
 }
 
 // Separate these two to allow for delay slot in middle.
@@ -805,16 +807,41 @@
 void InterpreterMacroAssembler::remove_activation(TosState state,
                                                   bool throw_monitor_exception,
                                                   bool install_monitor_exception) {
+  BLOCK_COMMENT("remove_activation {");
   unlock_if_synchronized_method(state, throw_monitor_exception, install_monitor_exception);
 
   // Save result (push state before jvmti call and pop it afterwards) and notify jvmti.
   notify_method_exit(false, state, NotifyJVMTI, true);
 
+  BLOCK_COMMENT("reserved_stack_check:");
+  if (StackReservedPages > 0) {
+    // Test if reserved zone needs to be enabled.
+    Label no_reserved_zone_enabling;
+
+    // Compare frame pointers. There is no good stack pointer, as with stack
+    // frame compression we can get different SPs when we do calls. A subsequent
+    // call could have a smaller SP, so that this compare succeeds for an
+    // inner call of the method annotated with ReservedStack.
+    ld_ptr(R0, JavaThread::reserved_stack_activation_offset(), R16_thread);
+    ld_ptr(R11_scratch1, _abi(callers_sp), R1_SP); // Load frame pointer.
+    cmpld(CCR0, R11_scratch1, R0);
+    blt_predict_taken(CCR0, no_reserved_zone_enabling);
+
+    // Enable reserved zone again, throw stack overflow exception.
+    call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), R16_thread);
+    call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_delayed_StackOverflowError));
+
+    should_not_reach_here();
+
+    bind(no_reserved_zone_enabling);
+  }
+
   verify_oop(R17_tos, state);
   verify_thread();
 
   merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);
   mtlr(R0);
+  BLOCK_COMMENT("} remove_activation");
 }
 
 // Lock object
--- a/src/cpu/ppc/vm/macroAssembler_ppc.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/cpu/ppc/vm/macroAssembler_ppc.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1400,6 +1400,28 @@
 #endif
 }
 
+void MacroAssembler::reserved_stack_check(Register return_pc) {
+  // Test if reserved zone needs to be enabled.
+  Label no_reserved_zone_enabling;
+
+  ld_ptr(R0, JavaThread::reserved_stack_activation_offset(), R16_thread);
+  cmpld(CCR0, R1_SP, R0);
+  blt_predict_taken(CCR0, no_reserved_zone_enabling);
+
+  // Enable reserved zone again, throw stack overflow exception.
+  push_frame_reg_args(0, R0);
+  call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), R16_thread);
+  pop_frame();
+  mtlr(return_pc);
+  load_const_optimized(R0, StubRoutines::throw_delayed_StackOverflowError_entry());
+  mtctr(R0);
+  bctr();
+
+  should_not_reach_here();
+
+  bind(no_reserved_zone_enabling);
+}
+
 // CmpxchgX sets condition register to cmpX(current, compare).
 void MacroAssembler::cmpxchgw(ConditionRegister flag, Register dest_current_value,
                               Register compare_value, Register exchange_value,
--- a/src/cpu/ppc/vm/macroAssembler_ppc.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/cpu/ppc/vm/macroAssembler_ppc.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -411,6 +411,10 @@
   // stdux, return the banged address. Otherwise, return 0.
   static address get_stack_bang_address(int instruction, void* ucontext);
 
+  // Check for reserved stack access in method being exited. If the reserved
+  // stack area was accessed, protect it again and throw StackOverflowError.
+  void reserved_stack_check(Register return_pc);
+
   // Atomics
   // CmpxchgX sets condition register to cmpX(current, compare).
   // (flag == ne) => (dest_current_value != compare_value), (!swapped)
--- a/src/cpu/ppc/vm/ppc.ad	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/cpu/ppc/vm/ppc.ad	Tue Jun 07 09:11:32 2016 +0000
@@ -1432,7 +1432,7 @@
 
   const bool method_needs_polling = do_polling() && C->is_method_compilation();
   const bool method_is_frameless  = false /* TODO: PPC port C->is_frameless_method()*/;
-  const Register return_pc        = R11;
+  const Register return_pc        = R31;  // Must survive C-call to enable_stack_reserved_zone().
   const Register polling_page     = R12;
 
   if (!method_is_frameless) {
@@ -1456,6 +1456,10 @@
     __ addi(R1_SP, R1_SP, (int)framesize);
   }
 
+  if (StackReservedPages > 0 && C->has_reserved_stack_access()) {
+    __ reserved_stack_check(return_pc);
+  }
+
   if (method_needs_polling) {
     // We need to mark the code position where the load from the safepoint
     // polling page was emitted as relocInfo::poll_return_type here.
--- a/src/cpu/ppc/vm/stubGenerator_ppc.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/cpu/ppc/vm/stubGenerator_ppc.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -3123,6 +3123,9 @@
     StubRoutines::_throw_StackOverflowError_entry   =
       generate_throw_exception("StackOverflowError throw_exception",
                                CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError), false);
+    StubRoutines::_throw_delayed_StackOverflowError_entry =
+      generate_throw_exception("delayed StackOverflowError throw_exception",
+                               CAST_FROM_FN_PTR(address, SharedRuntime::throw_delayed_StackOverflowError), false);
 
     // CRC32 Intrinsics.
     if (UseCRC32Intrinsics) {
--- a/src/cpu/ppc/vm/templateInterpreterGenerator_ppc.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/cpu/ppc/vm/templateInterpreterGenerator_ppc.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2015 SAP SE. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -562,10 +562,16 @@
   return NULL;
 }
 
-// Actually we should never reach here since we do stack overflow checks before pushing any frame.
 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
   address entry = __ pc();
-  __ unimplemented("generate_StackOverflowError_handler");
+
+  // Expression stack must be empty before entering the VM if an
+  // exception happened.
+  __ empty_expression_stack();
+  // Throw exception.
+  __ call_VM(noreg,
+             CAST_FROM_FN_PTR(address,
+                              InterpreterRuntime::throw_StackOverflowError));
   return entry;
 }
 
@@ -944,7 +950,7 @@
 // The top most frame needs an abi space of 112 bytes. This space is needed,
 // since we call to c. The c function may spill their arguments to the caller
 // frame. When we call to java, we don't need these spill slots. In order to save
-// space on the stack, we resize the caller. However, java local reside in
+// space on the stack, we resize the caller. However, java locals reside in
 // the caller frame and the frame has to be increased. The frame_size for the
 // current frame was calculated based on max_stack as size for the expression
 // stack. At the call, just a part of the expression stack might be used.
@@ -1007,7 +1013,7 @@
   // parent_frame_resize = (locals-parameters) - (ESP-SP-ABI48) Rounded to frame alignment size.
   // Enlarge by locals-parameters (not in case of native_call), shrink by ESP-SP-ABI48.
 
-  {
+  if (!native_call) {
     // --------------------------------------------------------------------------
     // Stack overflow check
 
@@ -1047,7 +1053,7 @@
   __ addi(R26_monitor, R1_SP, - frame::ijava_state_size);
   __ addi(R15_esp, R26_monitor, - Interpreter::stackElementSize);
 
-  // Get mirror and store it in the frame as GC root for this Method*
+  // Get mirror and store it in the frame as GC root for this Method*.
   __ load_mirror(R12_scratch2, R19_method);
 
   // Store values.
@@ -1133,6 +1139,29 @@
   return entry;
 }
 
+void TemplateInterpreterGenerator::bang_stack_shadow_pages(bool native_call) {
+  // Quick & dirty stack overflow checking: bang the stack & handle trap.
+  // Note that we do the banging after the frame is setup, since the exception
+  // handling code expects to find a valid interpreter frame on the stack.
+  // Doing the banging earlier fails if the caller frame is not an interpreter
+  // frame.
+  // (Also, the exception throwing code expects to unlock any synchronized
+  // method receiever, so do the banging after locking the receiver.)
+
+  // Bang each page in the shadow zone. We can't assume it's been done for
+  // an interpreter frame with greater than a page of locals, so each page
+  // needs to be checked.  Only true for non-native.
+  if (UseStackBanging) {
+    const int page_size = os::vm_page_size();
+    const int n_shadow_pages = ((int)JavaThread::stack_shadow_zone_size()) / page_size;
+    const int start_page = native_call ? n_shadow_pages : 1;
+    BLOCK_COMMENT("bang_stack_shadow_pages:");
+    for (int pages = start_page; pages <= n_shadow_pages; pages++) {
+      __ bang_stack_with_offset(pages*page_size);
+    }
+  }
+}
+
 // Interpreter stub for calling a native method. (asm interpreter)
 // This sets up a somewhat different looking stack for calling the
 // native method than the typical interpreter frame setup.
@@ -1156,7 +1185,7 @@
   // This is not a full-blown interpreter frame, but in particular, the
   // following registers are valid after this:
   // - R19_method
-  // - R18_local (points to start of argumuments to native function)
+  // - R18_local (points to start of arguments to native function)
   //
   //   abstract stack (grows up)
   //     [  IJava (caller of JNI callee)  ]  <-- ASP
@@ -1207,6 +1236,11 @@
     generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
 
     BIND(continue_after_compile);
+  }
+
+  bang_stack_shadow_pages(true);
+
+  if (inc_counter) {
     // Reset the _do_not_unlock_if_synchronized flag.
     if (synchronized) {
       __ li(R0, 0);
@@ -1595,6 +1629,7 @@
   Register Rsize_of_parameters = R4_ARG2, // Written by generate_fixed_frame.
            Rsize_of_locals     = R5_ARG3; // Written by generate_fixed_frame.
 
+  // Does also a stack check to assure this frame fits on the stack.
   generate_fixed_frame(false, Rsize_of_parameters, Rsize_of_locals);
 
   // --------------------------------------------------------------------------
@@ -1651,7 +1686,11 @@
     }
 
     __ bind(profile_method_continue);
+  }
 
+  bang_stack_shadow_pages(false);
+
+  if (inc_counter || ProfileInterpreter) {
     // Reset the _do_not_unlock_if_synchronized flag.
     if (synchronized) {
       __ li(R0, 0);
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/CommandProcessor.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/CommandProcessor.java	Tue Jun 07 09:11:32 2016 +0000
@@ -1712,7 +1712,8 @@
     // called after debuggee attach
     private void postAttach() {
         // create JavaScript engine and start it
-        jsengine = new JSJavaScriptEngine() {
+        try {
+            jsengine = new JSJavaScriptEngine() {
                         private ObjectReader reader = new ObjectReader();
                         private JSJavaFactory factory = new JSJavaFactoryImpl();
                         public ObjectReader getObjectReader() {
@@ -1735,17 +1736,24 @@
                             return err;
                         }
                    };
-        try {
-            jsengine.defineFunction(this,
+            try {
+                jsengine.defineFunction(this,
                      this.getClass().getMethod("registerCommand",
                                 new Class[] {
                                      String.class, String.class, String.class
                                 }));
-        } catch (NoSuchMethodException exp) {
-            // should not happen, see below...!!
-            exp.printStackTrace();
+            } catch (NoSuchMethodException exp) {
+                  // should not happen, see below...!!
+                  exp.printStackTrace();
+            }
+            jsengine.start();
         }
-        jsengine.start();
+        catch (Exception ex) {
+            System.out.println("Warning! JS Engine can't start, some commands will not be available.");
+            if (verboseExceptions) {
+                ex.printStackTrace(out);
+            }
+        }
     }
 
     public void registerCommand(String cmd, String usage, final String func) {
--- a/src/os/aix/vm/os_aix.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/os/aix/vm/os_aix.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2013, 2015 SAP SE. All rights reserved.
+ * Copyright (c) 2013, 2016 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -128,6 +128,8 @@
   // Set PC into context. Needed for continuation after signal.
   static void ucontext_set_pc(ucontext_t* uc, address pc);
 
+  static bool get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr);
+
   // This boolean allows users to forward their own non-matching signals
   // to JVM_handle_aix_signal, harmlessly.
   static bool signal_handlers_are_installed;
--- a/src/os_cpu/aix_ppc/vm/os_aix_ppc.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/os_cpu/aix_ppc/vm/os_aix_ppc.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2014 SAP SE. All rights reserved.
+ * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
  */
 
 // no precompiled headers
-#include "assembler_ppc.inline.hpp"
+#include "asm/assembler.inline.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
@@ -145,6 +145,41 @@
   return fr;
 }
 
+bool os::Aix::get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr) {
+  address pc = (address) os::Aix::ucontext_get_pc(uc);
+  if (Interpreter::contains(pc)) {
+    // Interpreter performs stack banging after the fixed frame header has
+    // been generated while the compilers perform it before. To maintain
+    // semantic consistency between interpreted and compiled frames, the
+    // method returns the Java sender of the current frame.
+    *fr = os::fetch_frame_from_context(uc);
+    if (!fr->is_first_java_frame()) {
+      assert(fr->safe_for_sender(thread), "Safety check");
+      *fr = fr->java_sender();
+    }
+  } else {
+    // More complex code with compiled code.
+    assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
+    CodeBlob* cb = CodeCache::find_blob(pc);
+    if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
+      // Not sure where the pc points to, fallback to default
+      // stack overflow handling. In compiled code, we bang before
+      // the frame is complete.
+      return false;
+    } else {
+      intptr_t* sp = os::Aix::ucontext_get_sp(uc);
+      *fr = frame(sp, (address)*sp);
+      if (!fr->is_java_frame()) {
+        assert(fr->safe_for_sender(thread), "Safety check");
+        assert(!fr->is_first_frame(), "Safety check");
+        *fr = fr->java_sender();
+      }
+    }
+  }
+  assert(fr->is_java_frame(), "Safety check");
+  return true;
+}
+
 frame os::get_sender_for_C_frame(frame* fr) {
   if (*fr->sp() == NULL) {
     // fr is the last C frame
@@ -246,14 +281,32 @@
       // to continue with yellow zone disabled, but that doesn't buy us much and prevents
       // hs_err_pid files.
       if (thread->in_stack_yellow_reserved_zone(addr)) {
-        thread->disable_stack_yellow_reserved_zone();
         if (thread->thread_state() == _thread_in_Java) {
+            if (thread->in_stack_reserved_zone(addr)) {
+              frame fr;
+              if (os::Aix::get_frame_at_stack_banging_point(thread, uc, &fr)) {
+                assert(fr.is_java_frame(), "Must be a Javac frame");
+                frame activation =
+                  SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr);
+                if (activation.sp() != NULL) {
+                  thread->disable_stack_reserved_zone();
+                  if (activation.is_interpreted_frame()) {
+                    thread->set_reserved_stack_activation((address)activation.fp());
+                  } else {
+                    thread->set_reserved_stack_activation((address)activation.unextended_sp());
+                  }
+                  return 1;
+                }
+              }
+            }
           // Throw a stack overflow exception.
           // Guard pages will be reenabled while unwinding the stack.
+          thread->disable_stack_yellow_reserved_zone();
           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
           goto run_stub;
         } else {
           // Thread was in the vm or native code. Return and try to finish.
+          thread->disable_stack_yellow_reserved_zone();
           return 1;
         }
       } else if (thread->in_stack_red_zone(addr)) {
--- a/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
+ * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
  */
 
 // no precompiled headers
-#include "assembler_ppc.inline.hpp"
+#include "asm/assembler.inline.hpp"
 #include "classfile/classLoader.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
@@ -157,6 +157,42 @@
   return frame(sp, epc.pc());
 }
 
+bool os::Linux::get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr) {
+  address pc = (address) os::Linux::ucontext_get_pc(uc);
+  if (Interpreter::contains(pc)) {
+    // Interpreter performs stack banging after the fixed frame header has
+    // been generated while the compilers perform it before. To maintain
+    // semantic consistency between interpreted and compiled frames, the
+    // method returns the Java sender of the current frame.
+    *fr = os::fetch_frame_from_context(uc);
+    if (!fr->is_first_java_frame()) {
+      assert(fr->safe_for_sender(thread), "Safety check");
+      *fr = fr->java_sender();
+    }
+  } else {
+    // More complex code with compiled code.
+    assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
+    CodeBlob* cb = CodeCache::find_blob(pc);
+    if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
+      // Not sure where the pc points to, fallback to default
+      // stack overflow handling. In compiled code, we bang before
+      // the frame is complete.
+      return false;
+    } else {
+      intptr_t* fp = os::Linux::ucontext_get_fp(uc);
+      intptr_t* sp = os::Linux::ucontext_get_sp(uc);
+      *fr = frame(sp, (address)*sp);
+      if (!fr->is_java_frame()) {
+        assert(fr->safe_for_sender(thread), "Safety check");
+        assert(!fr->is_first_frame(), "Safety check");
+        *fr = fr->java_sender();
+      }
+    }
+  }
+  assert(fr->is_java_frame(), "Safety check");
+  return true;
+}
+
 frame os::get_sender_for_C_frame(frame* fr) {
   if (*fr->sp() == 0) {
     // fr is the last C frame
@@ -243,13 +279,31 @@
       if (thread->on_local_stack(addr)) {
         // stack overflow
         if (thread->in_stack_yellow_reserved_zone(addr)) {
-          thread->disable_stack_yellow_reserved_zone();
           if (thread->thread_state() == _thread_in_Java) {
+            if (thread->in_stack_reserved_zone(addr)) {
+              frame fr;
+              if (os::Linux::get_frame_at_stack_banging_point(thread, uc, &fr)) {
+                assert(fr.is_java_frame(), "Must be a Javac frame");
+                frame activation =
+                  SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr);
+                if (activation.sp() != NULL) {
+                  thread->disable_stack_reserved_zone();
+                  if (activation.is_interpreted_frame()) {
+                    thread->set_reserved_stack_activation((address)activation.fp());
+                  } else {
+                    thread->set_reserved_stack_activation((address)activation.unextended_sp());
+                  }
+                  return 1;
+                }
+              }
+            }
             // Throw a stack overflow exception.
             // Guard pages will be reenabled while unwinding the stack.
+            thread->disable_stack_yellow_reserved_zone();
             stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
           } else {
             // Thread was in the vm or native code. Return and try to finish.
+            thread->disable_stack_yellow_reserved_zone();
             return 1;
           }
         } else if (thread->in_stack_red_zone(addr)) {
--- a/src/share/vm/ci/ciEnv.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/ci/ciEnv.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -704,13 +704,14 @@
                                InstanceKlass*  holder,
                                Symbol*       name,
                                Symbol*       sig,
-                               Bytecodes::Code bc) {
+                               Bytecodes::Code bc,
+                               constantTag    tag) {
   EXCEPTION_CONTEXT;
   KlassHandle h_accessor(THREAD, accessor);
   KlassHandle h_holder(THREAD, holder);
   LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL));
   methodHandle dest_method;
-  LinkInfo link_info(h_holder, name, sig, h_accessor, /*check_access*/true);
+  LinkInfo link_info(h_holder, name, sig, h_accessor, LinkInfo::needs_access_check, tag);
   switch (bc) {
   case Bytecodes::_invokestatic:
     dest_method =
@@ -796,7 +797,9 @@
 
     if (holder_is_accessible) {  // Our declared holder is loaded.
       InstanceKlass* lookup = declared_holder->get_instanceKlass();
-      Method* m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc);
+      constantTag tag = cpool->tag_ref_at(index);
+      assert(accessor->get_instanceKlass() == cpool->pool_holder(), "not the pool holder?");
+      Method* m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc, tag);
       if (m != NULL &&
           (bc == Bytecodes::_invokestatic
            ?  m->method_holder()->is_not_initialized()
--- a/src/share/vm/ci/ciEnv.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/ci/ciEnv.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -156,7 +156,8 @@
                            InstanceKlass*  holder,
                            Symbol*         name,
                            Symbol*         sig,
-                           Bytecodes::Code bc);
+                           Bytecodes::Code bc,
+                           constantTag     tag);
 
   // Get a ciObject from the object factory.  Ensures uniqueness
   // of ciObjects.
--- a/src/share/vm/ci/ciMethod.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/ci/ciMethod.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -789,7 +789,8 @@
    Symbol* h_name      = name()->get_symbol();
    Symbol* h_signature = signature()->get_symbol();
 
-   LinkInfo link_info(h_resolved, h_name, h_signature, caller_klass, check_access);
+   LinkInfo link_info(h_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.
--- a/src/share/vm/classfile/classLoader.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/classfile/classLoader.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -657,7 +657,7 @@
   int num_of_entries = xpatch_args->length();
 
   // Set up the boot loader's xpatch_entries list
-  _xpatch_entries = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<ModuleClassPathList*>(num_of_entries, true);
+  _xpatch_entries = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleClassPathList*>(num_of_entries, true);
 
   for (int i = 0; i < num_of_entries; i++) {
     const char* module_name = (xpatch_args->at(i))->module_name();
@@ -1069,9 +1069,9 @@
   char* begin_ptr = char_buf;
   char* end_ptr = strchr(begin_ptr, '\n');
   bool process_boot_modules = false;
-  _boot_modules_array = new (ResourceObj::C_HEAP, mtInternal)
+  _boot_modules_array = new (ResourceObj::C_HEAP, mtModule)
     GrowableArray<char*>(INITIAL_BOOT_MODULES_ARRAY_SIZE, true);
-  _platform_modules_array = new (ResourceObj::C_HEAP, mtInternal)
+  _platform_modules_array = new (ResourceObj::C_HEAP, mtModule)
     GrowableArray<char*>(INITIAL_PLATFORM_MODULES_ARRAY_SIZE, true);
   while (end_ptr != NULL && (end_ptr - char_buf) < buflen) {
     // Allocate a buffer from the C heap to be appended to the _boot_modules_array
--- a/src/share/vm/classfile/classLoaderData.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/classfile/classLoaderData.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -67,6 +67,7 @@
 #include "runtime/javaCalls.hpp"
 #include "runtime/jniHandles.hpp"
 #include "runtime/mutex.hpp"
+#include "runtime/orderAccess.hpp"
 #include "runtime/safepoint.hpp"
 #include "runtime/synchronizer.hpp"
 #include "utilities/growableArray.hpp"
@@ -76,6 +77,11 @@
 #include "trace/tracing.hpp"
 #endif
 
+// helper function to avoid in-line casts
+template <typename T> static T* load_ptr_acquire(T* volatile *p) {
+  return static_cast<T*>(OrderAccess::load_ptr_acquire(p));
+}
+
 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
 
 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
@@ -147,20 +153,23 @@
 }
 
 void ClassLoaderData::classes_do(KlassClosure* klass_closure) {
-  for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
+  // Lock-free access requires load_ptr_acquire
+  for (Klass* k = load_ptr_acquire(&_klasses); k != NULL; k = k->next_link()) {
     klass_closure->do_klass(k);
     assert(k != k->next_link(), "no loops!");
   }
 }
 
 void ClassLoaderData::classes_do(void f(Klass * const)) {
+  assert_locked_or_safepoint(_metaspace_lock);
   for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
     f(k);
   }
 }
 
 void ClassLoaderData::methods_do(void f(Method*)) {
-  for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
+  // Lock-free access requires load_ptr_acquire
+  for (Klass* k = load_ptr_acquire(&_klasses); k != NULL; k = k->next_link()) {
     if (k->is_instance_klass()) {
       InstanceKlass::cast(k)->methods_do(f);
     }
@@ -179,7 +188,8 @@
 }
 
 void ClassLoaderData::classes_do(void f(InstanceKlass*)) {
-  for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
+  // Lock-free access requires load_ptr_acquire
+  for (Klass* k = load_ptr_acquire(&_klasses); k != NULL; k = k->next_link()) {
     if (k->is_instance_klass()) {
       f(InstanceKlass::cast(k));
     }
@@ -188,6 +198,7 @@
 }
 
 void ClassLoaderData::modules_do(void f(ModuleEntry*)) {
+  assert_locked_or_safepoint(Module_lock);
   if (_modules != NULL) {
     for (int i = 0; i < _modules->table_size(); i++) {
       for (ModuleEntry* entry = _modules->bucket(i);
@@ -200,9 +211,11 @@
 }
 
 void ClassLoaderData::packages_do(void f(PackageEntry*)) {
-  if (_packages != NULL) {
-    for (int i = 0; i < _packages->table_size(); i++) {
-      for (PackageEntry* entry = _packages->bucket(i);
+  // Lock-free access requires load_ptr_acquire
+  PackageEntryTable* packages = load_ptr_acquire(&_packages);
+  if (packages != NULL) {
+    for (int i = 0; i < packages->table_size(); i++) {
+      for (PackageEntry* entry = packages->bucket(i);
                               entry != NULL;
                               entry = entry->next()) {
         f(entry);
@@ -325,10 +338,9 @@
     MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
     Klass* old_value = _klasses;
     k->set_next_link(old_value);
-    // Make sure linked class is stable, since the class list is walked without a lock
-    OrderAccess::storestore();
-    // link the new item into the list
-    _klasses = k;
+    // Link the new item into the list, making sure the linked class is stable
+    // since the list can be walked without a lock
+    OrderAccess::release_store_ptr(&_klasses, k);
   }
 
   if (publicize && k->class_loader_data() != NULL) {
@@ -343,11 +355,10 @@
   }
 }
 
-// This is called by InstanceKlass::deallocate_contents() to remove the
-// scratch_class for redefine classes.  We need a lock because there it may not
-// be called at a safepoint if there's an error.
+// Remove a klass from the _klasses list for scratch_class during redefinition
+// or parsed class in the case of an error.
 void ClassLoaderData::remove_class(Klass* scratch_class) {
-  MutexLockerEx ml(metaspace_lock(),  Mutex::_no_safepoint_check_flag);
+  assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
   Klass* prev = NULL;
   for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
     if (k == scratch_class) {
@@ -390,42 +401,46 @@
 
 PackageEntryTable* ClassLoaderData::packages() {
   // Lazily create the package entry table at first request.
-  if (_packages == NULL) {
+  // Lock-free access requires load_ptr_acquire.
+  PackageEntryTable* packages = load_ptr_acquire(&_packages);
+  if (packages == NULL) {
     MutexLockerEx m1(metaspace_lock(), Mutex::_no_safepoint_check_flag);
     // Check if _packages got allocated while we were waiting for this lock.
-    if (_packages == NULL) {
-      _packages = new PackageEntryTable(PackageEntryTable::_packagetable_entry_size);
+    if ((packages = _packages) == NULL) {
+      packages = new PackageEntryTable(PackageEntryTable::_packagetable_entry_size);
+      // Ensure _packages is stable, since it is examined without a lock
+      OrderAccess::release_store_ptr(&_packages, packages);
     }
   }
-  return _packages;
+  return packages;
 }
 
 ModuleEntryTable* ClassLoaderData::modules() {
   // Lazily create the module entry table at first request.
-  if (_modules == NULL) {
+  // Lock-free access requires load_ptr_acquire.
+  ModuleEntryTable* modules = load_ptr_acquire(&_modules);
+  if (modules == NULL) {
     MutexLocker m1(Module_lock);
-    // Check again if _modules has been allocated while we were getting this lock.
-    if (_modules != NULL) {
-      return _modules;
-    }
+    // Check if _modules got allocated while we were waiting for this lock.
+    if ((modules = _modules) == NULL) {
+      modules = new ModuleEntryTable(ModuleEntryTable::_moduletable_entry_size);
+      // Each loader has one unnamed module entry. Create it before
+      // any classes, loaded by this loader, are defined in case
+      // they end up being defined in loader's unnamed module.
+      modules->create_unnamed_module(this);
 
-    ModuleEntryTable* temp_table = new ModuleEntryTable(ModuleEntryTable::_moduletable_entry_size);
-    // Each loader has one unnamed module entry. Create it before
-    // any classes, loaded by this loader, are defined in case
-    // they end up being defined in loader's unnamed module.
-    temp_table->create_unnamed_module(this);
-
-    {
-      MutexLockerEx m1(metaspace_lock(), Mutex::_no_safepoint_check_flag);
-      // Ensure _modules is stable, since it is examined without a lock
-      OrderAccess::storestore();
-      _modules = temp_table;
+      {
+        MutexLockerEx m1(metaspace_lock(), Mutex::_no_safepoint_check_flag);
+        // Ensure _modules is stable, since it is examined without a lock
+        OrderAccess::release_store_ptr(&_modules, modules);
+      }
     }
   }
-  return _modules;
+  return modules;
 }
 
 oop ClassLoaderData::keep_alive_object() const {
+  assert_locked_or_safepoint(_metaspace_lock);
   assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
   return is_anonymous() ? _klasses->java_mirror() : class_loader();
 }
@@ -499,30 +514,33 @@
   // to create smaller arena for Reflection class loaders also.
   // The reason for the delayed allocation is because some class loaders are
   // simply for delegating with no metadata of their own.
-  if (_metaspace == NULL) {
-    MutexLockerEx ml(metaspace_lock(),  Mutex::_no_safepoint_check_flag);
-    // Check again if metaspace has been allocated while we were getting this lock.
-    if (_metaspace != NULL) {
-      return _metaspace;
-    }
-    if (this == the_null_class_loader_data()) {
-      assert (class_loader() == NULL, "Must be");
-      set_metaspace(new Metaspace(_metaspace_lock, Metaspace::BootMetaspaceType));
-    } else if (is_anonymous()) {
-      if (class_loader() != NULL) {
-        log_trace(class, loader, data)("is_anonymous: %s", class_loader()->klass()->internal_name());
+  // Lock-free access requires load_ptr_acquire.
+  Metaspace* metaspace = load_ptr_acquire(&_metaspace);
+  if (metaspace == NULL) {
+    MutexLockerEx ml(_metaspace_lock,  Mutex::_no_safepoint_check_flag);
+    // Check if _metaspace got allocated while we were waiting for this lock.
+    if ((metaspace = _metaspace) == NULL) {
+      if (this == the_null_class_loader_data()) {
+        assert (class_loader() == NULL, "Must be");
+        metaspace = new Metaspace(_metaspace_lock, Metaspace::BootMetaspaceType);
+      } else if (is_anonymous()) {
+        if (class_loader() != NULL) {
+          log_trace(class, loader, data)("is_anonymous: %s", class_loader()->klass()->internal_name());
+        }
+        metaspace = new Metaspace(_metaspace_lock, Metaspace::AnonymousMetaspaceType);
+      } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
+        if (class_loader() != NULL) {
+          log_trace(class, loader, data)("is_reflection: %s", class_loader()->klass()->internal_name());
+        }
+        metaspace = new Metaspace(_metaspace_lock, Metaspace::ReflectionMetaspaceType);
+      } else {
+        metaspace = new Metaspace(_metaspace_lock, Metaspace::StandardMetaspaceType);
       }
-      set_metaspace(new Metaspace(_metaspace_lock, Metaspace::AnonymousMetaspaceType));
-    } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
-      if (class_loader() != NULL) {
-        log_trace(class, loader, data)("is_reflection: %s", class_loader()->klass()->internal_name());
-      }
-      set_metaspace(new Metaspace(_metaspace_lock, Metaspace::ReflectionMetaspaceType));
-    } else {
-      set_metaspace(new Metaspace(_metaspace_lock, Metaspace::StandardMetaspaceType));
+      // Ensure _metaspace is stable, since it is examined without a lock
+      OrderAccess::release_store_ptr(&_metaspace, metaspace);
     }
   }
-  return _metaspace;
+  return metaspace;
 }
 
 JNIHandleBlock* ClassLoaderData::handles() const           { return _handles; }
@@ -638,6 +656,7 @@
 #endif // PRODUCT
 
 void ClassLoaderData::verify() {
+  assert_locked_or_safepoint(_metaspace_lock);
   oop cl = class_loader();
 
   guarantee(this == class_loader_data(cl) || is_anonymous(), "Must be the same");
@@ -656,7 +675,8 @@
 }
 
 bool ClassLoaderData::contains_klass(Klass* klass) {
-  for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
+  // Lock-free access requires load_ptr_acquire
+  for (Klass* k = load_ptr_acquire(&_klasses); k != NULL; k = k->next_link()) {
     if (k == klass) return true;
   }
   return false;
@@ -1046,6 +1066,7 @@
 
   // Find the first klass in the CLDG.
   while (cld != NULL) {
+    assert_locked_or_safepoint(cld->metaspace_lock());
     klass = cld->_klasses;
     if (klass != NULL) {
       _next_klass = klass;
@@ -1063,6 +1084,7 @@
 
   // No more klasses in the current CLD. Time to find a new CLD.
   ClassLoaderData* cld = klass->class_loader_data();
+  assert_locked_or_safepoint(cld->metaspace_lock());
   while (next == NULL) {
     cld = cld->next();
     if (cld == NULL) {
--- a/src/share/vm/classfile/classLoaderData.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/classfile/classLoaderData.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -171,8 +171,8 @@
   Dependencies _dependencies; // holds dependencies from this class loader
                               // data to others.
 
-  Metaspace * _metaspace;  // Meta-space where meta-data defined by the
-                           // classes in the class loader are allocated.
+  Metaspace * volatile _metaspace;  // Meta-space where meta-data defined by the
+                                    // classes in the class loader are allocated.
   Mutex* _metaspace_lock;  // Locks the metaspace for allocations and setup.
   bool _unloading;         // true if this class loader goes away
   bool _is_anonymous;      // if this CLD is for an anonymous class
@@ -186,9 +186,9 @@
   JNIHandleBlock* _handles; // Handles to constant pool arrays, Modules, etc, which
                             // have the same life cycle of the corresponding ClassLoader.
 
-  Klass* _klasses;         // The classes defined by the class loader.
-  PackageEntryTable* _packages; // The packages defined by the class loader.
-  ModuleEntryTable* _modules;   // The modules defined by the class loader.
+  Klass* volatile _klasses;              // The classes defined by the class loader.
+  PackageEntryTable* volatile _packages; // The packages defined by the class loader.
+  ModuleEntryTable* volatile _modules;   // The modules defined by the class loader.
 
   // These method IDs are created for the class loader and set to NULL when the
   // class loader is unloaded.  They are rarely freed, only for redefine classes
@@ -216,8 +216,6 @@
   ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies);
   ~ClassLoaderData();
 
-  void set_metaspace(Metaspace* m) { _metaspace = m; }
-
   JNIHandleBlock* handles() const;
   void set_handles(JNIHandleBlock* handles);
 
--- a/src/share/vm/classfile/javaClasses.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/classfile/javaClasses.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -848,7 +848,7 @@
     if (!ModuleEntryTable::javabase_defined()) {
       if (fixup_module_field_list() == NULL) {
         GrowableArray<Klass*>* list =
-          new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(500, true);
+          new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true);
         set_fixup_module_field_list(list);
       }
       k->class_loader_data()->inc_keep_alive();
--- a/src/share/vm/classfile/moduleEntry.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/classfile/moduleEntry.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -113,7 +113,7 @@
   } else {
     if (_reads == NULL) {
       // Lazily create a module's reads list
-      _reads = new (ResourceObj::C_HEAP, mtClass)GrowableArray<ModuleEntry*>(MODULE_READS_SIZE, true);
+      _reads = new (ResourceObj::C_HEAP, mtModule)GrowableArray<ModuleEntry*>(MODULE_READS_SIZE, true);
     }
     _reads->append_if_missing(m);
   }
@@ -159,7 +159,7 @@
 }
 
 ModuleEntryTable::ModuleEntryTable(int table_size)
-  : Hashtable<Symbol*, mtClass>(table_size, sizeof(ModuleEntry)), _unnamed_module(NULL)
+  : Hashtable<Symbol*, mtModule>(table_size, sizeof(ModuleEntry)), _unnamed_module(NULL)
 {
 }
 
@@ -228,7 +228,7 @@
                                          Symbol* version, Symbol* location,
                                          ClassLoaderData* loader_data) {
   assert_locked_or_safepoint(Module_lock);
-  ModuleEntry* entry = (ModuleEntry*) NEW_C_HEAP_ARRAY(char, entry_size(), mtClass);
+  ModuleEntry* entry = (ModuleEntry*) NEW_C_HEAP_ARRAY(char, entry_size(), mtModule);
 
   // Initialize everything BasicHashtable would
   entry->set_next(NULL);
@@ -259,7 +259,7 @@
 
 void ModuleEntryTable::add_entry(int index, ModuleEntry* new_entry) {
   assert_locked_or_safepoint(Module_lock);
-  Hashtable<Symbol*, mtClass>::add_entry(index, (HashtableEntry<Symbol*, mtClass>*)new_entry);
+  Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry);
 }
 
 ModuleEntry* ModuleEntryTable::locked_create_entry_or_null(Handle module_handle,
--- a/src/share/vm/classfile/moduleEntry.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/classfile/moduleEntry.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -49,7 +49,7 @@
 //
 // The Mutex Module_lock is shared between ModuleEntry and PackageEntry, to lock either
 // data structure.
-class ModuleEntry : public HashtableEntry<Symbol*, mtClass> {
+class ModuleEntry : public HashtableEntry<Symbol*, mtModule> {
 private:
   jobject _module;                     // java.lang.reflect.Module
   jobject _pd;                         // java.security.ProtectionDomain, cached
@@ -127,10 +127,10 @@
   }
 
   ModuleEntry* next() const {
-    return (ModuleEntry*)HashtableEntry<Symbol*, mtClass>::next();
+    return (ModuleEntry*)HashtableEntry<Symbol*, mtModule>::next();
   }
   ModuleEntry** next_addr() {
-    return (ModuleEntry**)HashtableEntry<Symbol*, mtClass>::next_addr();
+    return (ModuleEntry**)HashtableEntry<Symbol*, mtModule>::next_addr();
   }
 
   // iteration support for readability
@@ -166,7 +166,7 @@
 //
 // The ModuleEntryTable's lookup is lock free.
 //
-class ModuleEntryTable : public Hashtable<Symbol*, mtClass> {
+class ModuleEntryTable : public Hashtable<Symbol*, mtModule> {
   friend class VMStructs;
 public:
   enum Constants {
@@ -181,10 +181,10 @@
                          Symbol* location, ClassLoaderData* class_loader);
   void add_entry(int index, ModuleEntry* new_entry);
 
-  int entry_size() const { return BasicHashtable<mtClass>::entry_size(); }
+  int entry_size() const { return BasicHashtable<mtModule>::entry_size(); }
 
   ModuleEntry** bucket_addr(int i) {
-    return (ModuleEntry**)Hashtable<Symbol*, mtClass>::bucket_addr(i);
+    return (ModuleEntry**)Hashtable<Symbol*, mtModule>::bucket_addr(i);
   }
 
   static unsigned int compute_hash(Symbol* name) { return ((name == NULL) ? 0 : (unsigned int)(name->identity_hash())); }
@@ -195,7 +195,7 @@
   ~ModuleEntryTable();
 
   ModuleEntry* bucket(int i) {
-    return (ModuleEntry*)Hashtable<Symbol*, mtClass>::bucket(i);
+    return (ModuleEntry*)Hashtable<Symbol*, mtModule>::bucket(i);
   }
 
   // Create module in loader's module entry table, if already exists then
--- a/src/share/vm/classfile/modules.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/classfile/modules.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -145,7 +145,7 @@
 
   const char* home = Arguments::get_java_home();
   size_t len = strlen(home) + module_len + 32;
-  char* path = NEW_C_HEAP_ARRAY(char, len, mtInternal);
+  char* path = NEW_C_HEAP_ARRAY(char, len, mtModule);
   jio_snprintf(path, len, "%s%cmodules%c%s", home, file_sep, file_sep, module_name);
   struct stat st;
   // See if exploded module path exists
@@ -237,35 +237,40 @@
   // Ensure java.base's ModuleEntry has been created
   assert(ModuleEntryTable::javabase_module() != NULL, "No ModuleEntry for java.base");
 
+  bool duplicate_javabase = false;
   {
     MutexLocker m1(Module_lock, THREAD);
 
     if (ModuleEntryTable::javabase_defined()) {
-      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-                "Module java.base is already defined");
+      duplicate_javabase = true;
+    } else {
+
+      // Verify that all java.base packages created during bootstrapping are in
+      // pkg_list.  If any are not in pkg_list, than a non-java.base class was
+      // loaded erroneously pre java.base module definition.
+      package_table->verify_javabase_packages(pkg_list);
+
+      // loop through and add any new packages for java.base
+      PackageEntry* pkg;
+      for (int x = 0; x < pkg_list->length(); x++) {
+        // Some of java.base's packages were added early in bootstrapping, ignore duplicates.
+        if (package_table->lookup_only(pkg_list->at(x)) == NULL) {
+          pkg = package_table->locked_create_entry_or_null(pkg_list->at(x), ModuleEntryTable::javabase_module());
+          assert(pkg != NULL, "Unable to create a java.base package entry");
+        }
+        // Unable to have a GrowableArray of TempNewSymbol.  Must decrement the refcount of
+        // the Symbol* that was created above for each package. The refcount was incremented
+        // by SymbolTable::new_symbol and as well by the PackageEntry creation.
+        pkg_list->at(x)->decrement_refcount();
+      }
+
+      // Finish defining java.base's ModuleEntry
+      ModuleEntryTable::finalize_javabase(module_handle, version_symbol, location_symbol);
     }
-
-    // Verify that all java.base packages created during bootstrapping are in
-    // pkg_list.  If any are not in pkg_list, than a non-java.base class was
-    // loaded erroneously pre java.base module definition.
-    package_table->verify_javabase_packages(pkg_list);
-
-    // loop through and add any new packages for java.base
-    PackageEntry* pkg;
-    for (int x = 0; x < pkg_list->length(); x++) {
-      // Some of java.base's packages were added early in bootstrapping, ignore duplicates.
-      if (package_table->lookup_only(pkg_list->at(x)) == NULL) {
-        pkg = package_table->locked_create_entry_or_null(pkg_list->at(x), ModuleEntryTable::javabase_module());
-        assert(pkg != NULL, "Unable to create a java.base package entry");
-      }
-      // Unable to have a GrowableArray of TempNewSymbol.  Must decrement the refcount of
-      // the Symbol* that was created above for each package. The refcount was incremented
-      // by SymbolTable::new_symbol and as well by the PackageEntry creation.
-      pkg_list->at(x)->decrement_refcount();
-    }
-
-    // Finish defining java.base's ModuleEntry
-    ModuleEntryTable::finalize_javabase(module_handle, version_symbol, location_symbol);
+  }
+  if (duplicate_javabase) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              "Module java.base is already defined");
   }
 
   log_debug(modules)("define_javabase_module(): Definition of module: java.base,"
--- a/src/share/vm/classfile/packageEntry.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/classfile/packageEntry.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -34,15 +34,13 @@
 #include "utilities/hashtable.inline.hpp"
 #include "utilities/ostream.hpp"
 
-// Return true if this package is exported to m.
+// Returns true if this package specifies m as a qualified export, including through an unnamed export
 bool PackageEntry::is_qexported_to(ModuleEntry* m) const {
   assert(m != NULL, "No module to lookup in this package's qualified exports list");
   MutexLocker m1(Module_lock);
-  if (!_is_exported) {
-    return false;
-  } else if (_is_exported_allUnnamed && !m->is_named()) {
+  if (is_exported_allUnnamed() && !m->is_named()) {
     return true;
-  } else if (_qualified_exports == NULL) {
+  } else if (!has_qual_exports_list()) {
     return false;
   } else {
     return _qualified_exports->contains(m);
@@ -52,17 +50,16 @@
 // Add a module to the package's qualified export list.
 void PackageEntry::add_qexport(ModuleEntry* m) {
   assert_locked_or_safepoint(Module_lock);
-  assert(_is_exported == true, "Adding a qualified export to a package that is not exported");
-  if (_qualified_exports == NULL) {
+  if (!has_qual_exports_list()) {
     // Lazily create a package's qualified exports list.
     // Initial size is small, do not anticipate export lists to be large.
     _qualified_exports =
-      new (ResourceObj::C_HEAP, mtClass) GrowableArray<ModuleEntry*>(QUAL_EXP_SIZE, true);
+      new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleEntry*>(QUAL_EXP_SIZE, true);
   }
   _qualified_exports->append_if_missing(m);
 }
 
-// Set the package's exported state based on the value of the ModuleEntry.
+// Set the package's exported states based on the value of the ModuleEntry.
 void PackageEntry::set_exported(ModuleEntry* m) {
   MutexLocker m1(Module_lock);
   if (is_unqual_exported()) {
@@ -73,7 +70,7 @@
 
   if (m == NULL) {
     // NULL indicates the package is being unqualifiedly exported
-    if (_is_exported && _qualified_exports != NULL) {
+    if (has_qual_exports_list()) {
       // Legit to transition a package from being qualifiedly exported
       // to unqualified.  Clean up the qualified lists at the next
       // safepoint.
@@ -85,11 +82,17 @@
 
   } else {
     // Add the exported module
-    _is_exported = true;
     add_qexport(m);
   }
 }
 
+void PackageEntry::set_is_exported_allUnnamed() {
+  MutexLocker m1(Module_lock);
+  if (!is_unqual_exported()) {
+   _is_exported_allUnnamed = true;
+  }
+}
+
 // Remove dead module entries within the package's exported list.
 void PackageEntry::purge_qualified_exports() {
   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
@@ -124,7 +127,7 @@
 }
 
 PackageEntryTable::PackageEntryTable(int table_size)
-  : Hashtable<Symbol*, mtClass>(table_size, sizeof(PackageEntry))
+  : Hashtable<Symbol*, mtModule>(table_size, sizeof(PackageEntry))
 {
 }
 
@@ -155,7 +158,7 @@
 
 PackageEntry* PackageEntryTable::new_entry(unsigned int hash, Symbol* name, ModuleEntry* module) {
   assert_locked_or_safepoint(Module_lock);
-  PackageEntry* entry = (PackageEntry*) NEW_C_HEAP_ARRAY(char, entry_size(), mtClass);
+  PackageEntry* entry = (PackageEntry*) NEW_C_HEAP_ARRAY(char, entry_size(), mtModule);
 
   // Initialize everything BasicHashtable would
   entry->set_next(NULL);
@@ -170,7 +173,7 @@
   if (!module->is_named()) {
     // Set the exported state to true because all packages
     // within the unnamed module are unqualifiedly exported
-    entry->set_exported(true);
+    entry->set_unqual_exported();
   }
   entry->set_module(module);
   return entry;
@@ -178,7 +181,7 @@
 
 void PackageEntryTable::add_entry(int index, PackageEntry* new_entry) {
   assert_locked_or_safepoint(Module_lock);
-  Hashtable<Symbol*, mtClass>::add_entry(index, (HashtableEntry<Symbol*, mtClass>*)new_entry);
+  Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry);
 }
 
 // Create package in loader's package entry table and return the entry.
@@ -248,6 +251,20 @@
 
 }
 
+// iteration of qualified exports
+void PackageEntry::package_exports_do(ModuleClosure* const f) {
+  assert_locked_or_safepoint(Module_lock);
+  assert(f != NULL, "invariant");
+
+  if (has_qual_exports_list()) {
+    int qe_len = _qualified_exports->length();
+
+    for (int i = 0; i < qe_len; ++i) {
+      f->do_module(_qualified_exports->at(i));
+    }
+  }
+}
+
 // Remove dead entries from all packages' exported list
 void PackageEntryTable::purge_all_package_exports() {
   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
@@ -281,10 +298,10 @@
 void PackageEntry::print(outputStream* st) {
   ResourceMark rm;
   st->print_cr("package entry "PTR_FORMAT" name %s module %s classpath_index "
-               INT32_FORMAT " is_exported %d is_exported_allUnnamed %d " "next "PTR_FORMAT,
+               INT32_FORMAT " is_exported_unqualified %d is_exported_allUnnamed %d " "next "PTR_FORMAT,
                p2i(this), name()->as_C_string(),
                (module()->is_named() ? module()->name()->as_C_string() : UNNAMED_MODULE),
-               _classpath_index, _is_exported, _is_exported_allUnnamed, p2i(next()));
+               _classpath_index, _is_exported_unqualified, _is_exported_allUnnamed, p2i(next()));
 }
 
 void PackageEntryTable::verify() {
@@ -305,17 +322,3 @@
 void PackageEntry::verify() {
   guarantee(name() != NULL, "A package entry must have a corresponding symbol name.");
 }
-
-// iteration of qualified exports
-void PackageEntry::package_exports_do(ModuleClosure* const f) {
-  assert_locked_or_safepoint(Module_lock);
-  assert(f != NULL, "invariant");
-
-  if (is_qual_exported()) {
-    int qe_len = _qualified_exports->length();
-
-    for (int i = 0; i < qe_len; ++i) {
-      f->do_module(_qualified_exports->at(i));
-    }
-  }
-}
--- a/src/share/vm/classfile/packageEntry.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/classfile/packageEntry.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -34,20 +34,36 @@
 // A PackageEntry basically represents a Java package.  It contains:
 //   - Symbol* containing the package's name.
 //   - ModuleEntry* for this package's containing module.
-//   - a flag indicating if package is exported, either qualifiedly or
-//     unqualifiedly.
+//   - a flag indicating if package is exported unqualifiedly
 //   - a flag indicating if this package is exported to all unnamed modules.
 //   - a growable array containing other module entries that this
 //     package is exported to.
 //
-// Packages that are:
-//   - not exported:        _qualified_exports = NULL  && _is_exported is false
-//   - qualified exports:   (_qualified_exports != NULL || _is_exported_allUnnamed is true) && _is_exported is true
-//   - unqualified exports: (_qualified_exports = NULL && _is_exported_allUnnamed is false) && _is_exported is true
+// Packages can be exported in the following 3 ways:
+//   - not exported:        the package has not been explicitly qualified to a
+//                            particular module nor has it been specified to be
+//                            unqualifiedly exported to all modules. If all states
+//                            of exportedness are false, the package is considered
+//                            not exported.
+//   - qualified exports:   the package has been explicitly qualified to at least
+//                            one particular module or has been qualifiedly exported
+//                            to all unnamed modules.
+//                            Note: _is_exported_allUnnamed is a form of a qualified
+//                            export. It is equivalent to the package being
+//                            explicitly exported to all current and future unnamed modules.
+//   - unqualified exports: the package is exported to all modules.
+//
+// A package can transition from:
+//   - being not exported, to being exported either in a qualified or unqualified manner
+//   - being qualifiedly exported, to unqualifiedly exported. Its exported scope is widened.
+//
+// A package cannot transition from:
+//   - being unqualifiedly exported, to exported qualifiedly to a specific module.
+//       This transition attempt is silently ignored in set_exported.
 //
 // The Mutex Module_lock is shared between ModuleEntry and PackageEntry, to lock either
 // data structure.
-class PackageEntry : public HashtableEntry<Symbol*, mtClass> {
+class PackageEntry : public HashtableEntry<Symbol*, mtModule> {
 private:
   ModuleEntry* _module;
   // Used to indicate for packages with classes loaded by the boot loader that
@@ -55,7 +71,7 @@
   // loaded by the boot loader from -Xbootclasspath/a in an unnamed module, it
   // indicates from which class path entry.
   s2 _classpath_index;
-  bool _is_exported;
+  bool _is_exported_unqualified;
   bool _is_exported_allUnnamed;
   GrowableArray<ModuleEntry*>* _exported_pending_delete; // transitioned from qualified to unqualified, delete at safepoint
   GrowableArray<ModuleEntry*>* _qualified_exports;
@@ -68,7 +84,7 @@
   void init() {
     _module = NULL;
     _classpath_index = -1;
-    _is_exported = false;
+    _is_exported_unqualified = false;
     _is_exported_allUnnamed = false;
     _exported_pending_delete = NULL;
     _qualified_exports = NULL;
@@ -83,34 +99,41 @@
   void               set_module(ModuleEntry* m) { _module = m; }
 
   // package's export state
-  bool is_exported() const { return _is_exported; } // qualifiedly or unqualifiedly exported
+  bool is_exported() const { // qualifiedly or unqualifiedly exported
+      return (is_unqual_exported() || has_qual_exports_list() || is_exported_allUnnamed());
+  }
+  // Returns true if the package has any explicit qualified exports or is exported to all unnamed
   bool is_qual_exported() const {
-    return (_is_exported && (_qualified_exports != NULL || _is_exported_allUnnamed));
+    return (has_qual_exports_list() || is_exported_allUnnamed());
+  }
+  // Returns true if there are any explicit qualified exports
+  bool has_qual_exports_list() const {
+    assert(!(_qualified_exports != NULL && _is_exported_unqualified),
+           "_qualified_exports set at same time as _is_exported_unqualified");
+    return (_qualified_exports != NULL);
+  }
+  bool is_exported_allUnnamed() const {
+    assert(!(_is_exported_allUnnamed && _is_exported_unqualified),
+           "_is_exported_allUnnamed set at same time as _is_exported_unqualified");
+    return _is_exported_allUnnamed;
   }
   bool is_unqual_exported() const {
-    return (_is_exported && (_qualified_exports == NULL && !_is_exported_allUnnamed));
+    assert(!(_qualified_exports != NULL && _is_exported_unqualified),
+           "_qualified_exports set at same time as _is_exported_unqualified");
+    assert(!(_is_exported_allUnnamed && _is_exported_unqualified),
+           "_is_exported_allUnnamed set at same time as _is_exported_unqualified");
+    return _is_exported_unqualified;
   }
   void set_unqual_exported() {
-    _is_exported = true;
+    _is_exported_unqualified = true;
     _is_exported_allUnnamed = false;
     _qualified_exports = NULL;
   }
   bool exported_pending_delete() const     { return (_exported_pending_delete != NULL); }
 
-  void set_exported(bool e)                { _is_exported = e; }
   void set_exported(ModuleEntry* m);
 
-  void set_is_exported_allUnnamed() {
-    if (!is_unqual_exported()) {
-     _is_exported_allUnnamed = true;
-     _is_exported = true;
-    }
-  }
-  bool is_exported_allUnnamed() const {
-    assert(_is_exported || !_is_exported_allUnnamed,
-           "is_allUnnamed set without is_exported being set");
-    return _is_exported_allUnnamed;
-  }
+  void set_is_exported_allUnnamed();
 
   void set_classpath_index(s2 classpath_index) {
     _classpath_index = classpath_index;
@@ -122,18 +145,18 @@
   // returns true if the package is defined in the unnamed module
   bool in_unnamed_module() const  { return !_module->is_named(); }
 
-  // returns true if the package specifies m as a qualified export
+  // returns true if the package specifies m as a qualified export, including through an unnamed export
   bool is_qexported_to(ModuleEntry* m) const;
 
   // add the module to the package's qualified exports
   void add_qexport(ModuleEntry* m);
 
   PackageEntry* next() const {
-    return (PackageEntry*)HashtableEntry<Symbol*, mtClass>::next();
+    return (PackageEntry*)HashtableEntry<Symbol*, mtModule>::next();
   }
 
   PackageEntry** next_addr() {
-    return (PackageEntry**)HashtableEntry<Symbol*, mtClass>::next_addr();
+    return (PackageEntry**)HashtableEntry<Symbol*, mtModule>::next_addr();
   }
 
   // iteration of qualified exports
@@ -153,7 +176,7 @@
 // by a particular class loader.  Each package is represented as a PackageEntry node.
 // The PackageEntryTable's lookup is lock free.
 //
-class PackageEntryTable : public Hashtable<Symbol*, mtClass> {
+class PackageEntryTable : public Hashtable<Symbol*, mtModule> {
   friend class VMStructs;
 public:
   enum Constants {
@@ -164,10 +187,10 @@
   PackageEntry* new_entry(unsigned int hash, Symbol* name, ModuleEntry* module);
   void add_entry(int index, PackageEntry* new_entry);
 
-  int entry_size() const { return BasicHashtable<mtClass>::entry_size(); }
+  int entry_size() const { return BasicHashtable<mtModule>::entry_size(); }
 
   PackageEntry** bucket_addr(int i) {
-    return (PackageEntry**)Hashtable<Symbol*, mtClass>::bucket_addr(i);
+    return (PackageEntry**)Hashtable<Symbol*, mtModule>::bucket_addr(i);
   }
 
   static unsigned int compute_hash(Symbol* name) { return (unsigned int)(name->identity_hash()); }
@@ -178,7 +201,7 @@
   ~PackageEntryTable();
 
   PackageEntry* bucket(int i) {
-    return (PackageEntry*)Hashtable<Symbol*, mtClass>::bucket(i);
+    return (PackageEntry*)Hashtable<Symbol*, mtModule>::bucket(i);
   }
 
   // Create package in loader's package entry table and return the entry.
--- a/src/share/vm/classfile/systemDictionary.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/classfile/systemDictionary.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1336,9 +1336,12 @@
       return nh;
     }
 
-    // Found the class, now load the superclass and interfaces.  If they
-    // are shared, add them to the main system dictionary and reset
-    // their hierarchy references (supers, subs, and interfaces).
+    // Resolve the superclass and interfaces. They must be the same
+    // as in dump time, because the layout of <ik> depends on
+    // the specific layout of ik->super() and ik->local_interfaces().
+    //
+    // If unexpected superclass or interfaces are found, we cannot
+    // load <ik> from the shared archive.
 
     if (ik->super() != NULL) {
       Symbol*  cn = ik->super()->name();
@@ -1348,6 +1351,8 @@
         // The dynamically resolved super class is not the same as the one we used during dump time,
         // so we cannot use ik.
         return nh;
+      } else {
+        assert(s->is_shared(), "must be");
       }
     }
 
@@ -1366,6 +1371,8 @@
         // The dynamically resolved interface class is not the same as the one we used during dump time,
         // so we cannot use ik.
         return nh;
+      } else {
+        assert(i->is_shared(), "must be");
       }
     }
 
--- a/src/share/vm/classfile/systemDictionary.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/classfile/systemDictionary.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -420,9 +420,9 @@
   // Initialization
   static void initialize(TRAPS);
 
-  // Fast access to commonly used classes (preloaded)
+  // Checked fast access to commonly used classes - mostly preloaded
   static InstanceKlass* check_klass(InstanceKlass* k) {
-    assert(k != NULL, "preloaded klass not initialized");
+    assert(k != NULL, "klass not loaded");
     return k;
   }
 
--- a/src/share/vm/interpreter/bytecodes.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/interpreter/bytecodes.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -386,15 +386,16 @@
   static Code       non_breakpoint_code_at(const Method* method, address bcp);
 
   // Bytecode attributes
-  static bool        is_defined     (int  code)    { return 0 <= code && code < number_of_codes && flags(code, false) != 0; }
+  static bool        is_valid       (int  code)    { return 0 <= code && code < number_of_codes; }
+  static bool        is_defined     (int  code)    { return is_valid(code) && flags(code, false) != 0; }
   static bool        wide_is_defined(int  code)    { return is_defined(code) && flags(code, true) != 0; }
   static const char* name           (Code code)    { check(code);      return _name          [code]; }
   static BasicType   result_type    (Code code)    { check(code);      return _result_type   [code]; }
   static int         depth          (Code code)    { check(code);      return _depth         [code]; }
   // Note: Length functions must return <=0 for invalid bytecodes.
   // Calling check(code) in length functions would throw an unwanted assert.
-  static int         length_for     (Code code)    { /*no check*/      return _lengths       [code] & 0xF; }
-  static int         wide_length_for(Code code)    { /*no check*/      return _lengths       [code] >> 4; }
+  static int         length_for     (Code code)    { return is_valid(code) ? _lengths[code] & 0xF : -1; }
+  static int         wide_length_for(Code code)    { return is_valid(code) ? _lengths[code]  >> 4 : -1; }
   static bool        can_trap       (Code code)    { check(code);      return has_all_flags(code, _bc_can_trap, false); }
   static Code        java_code      (Code code)    { check(code);      return _java_code     [code]; }
   static bool        can_rewrite    (Code code)    { check(code);      return has_all_flags(code, _bc_can_rewrite, false); }
--- a/src/share/vm/interpreter/linkResolver.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/interpreter/linkResolver.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -231,6 +231,7 @@
   // 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());
 
   // Coming from the constant pool always checks access
@@ -573,7 +574,7 @@
     Symbol* method_signature = pool->signature_ref_at(index);
     KlassHandle  current_klass(THREAD, pool->pool_holder());
     LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass);
-    return resolve_method(link_info, /*require_methodref*/false, THREAD);
+    return resolve_method(link_info, code, THREAD);
   }
 
   LinkInfo link_info(pool, index, CHECK_NULL);
@@ -591,9 +592,9 @@
   if (code == Bytecodes::_invokeinterface) {
     return resolve_interface_method(link_info, code, THREAD);
   } else if (code == Bytecodes::_invokevirtual) {
-    return resolve_method(link_info, /*require_methodref*/true, THREAD);
+    return resolve_method(link_info, code, THREAD);
   } else if (!resolved_klass->is_interface()) {
-    return resolve_method(link_info, /*require_methodref*/false, THREAD);
+    return resolve_method(link_info, code, THREAD);
   } else {
     return resolve_interface_method(link_info, code, THREAD);
   }
@@ -663,13 +664,13 @@
 }
 
 methodHandle LinkResolver::resolve_method(const LinkInfo& link_info,
-                                          bool require_methodref, TRAPS) {
+                                          Bytecodes::Code code, TRAPS) {
 
   Handle nested_exception;
   KlassHandle resolved_klass = link_info.resolved_klass();
 
-  // 1. check if methodref required, that resolved_klass is not interfacemethodref
-  if (require_methodref && resolved_klass->is_interface()) {
+  // 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",
@@ -677,11 +678,20 @@
     THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
   }
 
-  // 2. lookup method in resolved klass and its super klasses
+  // 2. check constant pool tag for called method - must be JVM_CONSTANT_Methodref
+  if (!link_info.tag().is_invalid() && !link_info.tag().is_method()) {
+    ResourceMark rm(THREAD);
+    char buf[200];
+    jio_snprintf(buf, sizeof(buf), "Method %s must be Methodref constant", link_info.method_string());
+    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
+  }
+
+
+  // 3. lookup method in resolved klass and its super klasses
   methodHandle resolved_method = lookup_method_in_klasses(link_info, true, false, CHECK_NULL);
 
+  // 4. lookup method in all the interfaces implemented by the resolved klass
   if (resolved_method.is_null() && !resolved_klass->is_array_klass()) { // not found in the class hierarchy
-    // 3. lookup method in all the interfaces implemented by the resolved klass
     resolved_method = lookup_method_in_interfaces(link_info, CHECK_NULL);
 
     if (resolved_method.is_null()) {
@@ -694,8 +704,8 @@
     }
   }
 
+  // 5. method lookup failed
   if (resolved_method.is_null()) {
-    // 4. method lookup failed
     ResourceMark rm(THREAD);
     THROW_MSG_CAUSE_(vmSymbols::java_lang_NoSuchMethodError(),
                     Method::name_and_sig_as_C_string(resolved_klass(),
@@ -704,7 +714,7 @@
                     nested_exception, NULL);
   }
 
-  // 5. access checks, access checking may be turned off when calling from within the VM.
+  // 6. access checks, access checking may be turned off when calling from within the VM.
   KlassHandle current_klass = link_info.current_klass();
   if (link_info.check_access()) {
     assert(current_klass.not_null() , "current_klass should not be null");
@@ -766,6 +776,14 @@
     THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
   }
 
+  // check constant pool tag for called method - must be JVM_CONSTANT_InterfaceMethodref
+  if (!link_info.tag().is_invalid() && !link_info.tag().is_interface_method()) {
+    ResourceMark rm(THREAD);
+    char buf[200];
+    jio_snprintf(buf, sizeof(buf), "Method %s must be InterfaceMethodref constant", link_info.method_string());
+    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
+  }
+
   // lookup method in this interface or its super, java.lang.Object
   // JDK8: also look for static methods
   methodHandle resolved_method = lookup_method_in_klasses(link_info, false, true, CHECK_NULL);
@@ -948,19 +966,18 @@
   methodHandle resolved_method = linktime_resolve_static_method(link_info, CHECK);
 
   // The resolved class can change as a result of this resolution.
-  KlassHandle resolved_klass = KlassHandle(THREAD, resolved_method->method_holder());
+  KlassHandle resolved_klass(THREAD, resolved_method->method_holder());
 
-  Method* save_resolved_method = resolved_method();
   // Initialize klass (this should only happen if everything is ok)
   if (initialize_class && resolved_klass->should_be_initialized()) {
     resolved_klass->initialize(CHECK);
-    // Use updated LinkInfo (to reresolve with resolved_klass as method_holder?)
+    // Use updated LinkInfo to reresolve with resolved method holder
     LinkInfo new_info(resolved_klass, link_info.name(), link_info.signature(),
-                      link_info.current_klass(), link_info.check_access());
+                      link_info.current_klass(),
+                      link_info.check_access() ? LinkInfo::needs_access_check : LinkInfo::skip_access_check);
     resolved_method = linktime_resolve_static_method(new_info, CHECK);
   }
 
-  assert(save_resolved_method == resolved_method(), "does this change?");
   // setup result
   result.set_static(resolved_klass, resolved_method, CHECK);
 }
@@ -971,7 +988,7 @@
   KlassHandle resolved_klass = link_info.resolved_klass();
   methodHandle resolved_method;
   if (!resolved_klass->is_interface()) {
-    resolved_method = resolve_method(link_info, /*require_methodref*/false, CHECK_NULL);
+    resolved_method = resolve_method(link_info, Bytecodes::_invokestatic, CHECK_NULL);
   } else {
     resolved_method = resolve_interface_method(link_info, Bytecodes::_invokestatic, CHECK_NULL);
   }
@@ -1014,7 +1031,7 @@
   methodHandle resolved_method;
 
   if (!resolved_klass->is_interface()) {
-    resolved_method = resolve_method(link_info, /*require_methodref*/false, CHECK_NULL);
+    resolved_method = resolve_method(link_info, Bytecodes::_invokespecial, CHECK_NULL);
   } else {
     resolved_method = resolve_interface_method(link_info, Bytecodes::_invokespecial, CHECK_NULL);
   }
@@ -1164,7 +1181,7 @@
 methodHandle LinkResolver::linktime_resolve_virtual_method(const LinkInfo& link_info,
                                                            TRAPS) {
   // normal method resolution
-  methodHandle resolved_method = resolve_method(link_info, /*require_methodref*/true, CHECK_NULL);
+  methodHandle resolved_method = resolve_method(link_info, Bytecodes::_invokevirtual, CHECK_NULL);
 
   assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier");
   assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier");
@@ -1173,6 +1190,7 @@
   KlassHandle resolved_klass = link_info.resolved_klass();
   KlassHandle 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];
@@ -1482,7 +1500,7 @@
   KlassHandle defc = attached_method->method_holder();
   Symbol* name = attached_method->name();
   Symbol* type = attached_method->signature();
-  LinkInfo link_info(defc, name, type, KlassHandle(), /*check_access=*/false);
+  LinkInfo link_info(defc, name, type);
   switch(byte) {
     case Bytecodes::_invokevirtual:
       resolve_virtual_call(result, recv, recv->klass(), link_info,
--- a/src/share/vm/interpreter/linkResolver.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/interpreter/linkResolver.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -137,20 +137,35 @@
   KlassHandle _resolved_klass;  // class that the constant pool entry points to
   KlassHandle _current_klass;   // class that owns the constant pool
   bool        _check_access;
+  constantTag _tag;
  public:
+  enum AccessCheck {
+     needs_access_check,
+     skip_access_check
+  };
+
   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, bool check_access = true) :
+  LinkInfo(KlassHandle resolved_klass, Symbol* name, Symbol* signature, KlassHandle 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),
-    _check_access(check_access) {}
+    _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) :
+    _resolved_klass(resolved_klass),
+    _name(name), _signature(signature), _current_klass(NULL),
+    _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; }
+  constantTag tag() const            { return _tag; }
   bool check_access() const          { return _check_access; }
   char* method_string() const;
 
@@ -192,7 +207,7 @@
                                              KlassHandle sel_klass, TRAPS);
 
   static methodHandle resolve_interface_method(const LinkInfo& link_info, Bytecodes::Code code, TRAPS);
-  static methodHandle resolve_method          (const LinkInfo& link_info, bool require_methodref, TRAPS);
+  static methodHandle resolve_method          (const LinkInfo& link_info, Bytecodes::Code code, TRAPS);
 
   static methodHandle linktime_resolve_static_method    (const LinkInfo& link_info, TRAPS);
   static methodHandle linktime_resolve_special_method   (const LinkInfo& link_info, TRAPS);
--- a/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -661,8 +661,7 @@
   Symbol* h_name      = method->name();
   Symbol* h_signature = method->signature();
 
-  bool check_access = true;
-  LinkInfo link_info(h_resolved, h_name, h_signature, caller_klass, check_access);
+  LinkInfo link_info(h_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.
--- a/src/share/vm/jvmci/jvmciEnv.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/jvmci/jvmciEnv.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -286,11 +286,12 @@
                                instanceKlassHandle h_holder,
                                Symbol*       name,
                                Symbol*       sig,
-                               Bytecodes::Code bc) {
+                               Bytecodes::Code bc,
+                               constantTag   tag) {
   JVMCI_EXCEPTION_CONTEXT;
   LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL));
   methodHandle dest_method;
-  LinkInfo link_info(h_holder, name, sig, h_accessor, /*check_access*/true);
+  LinkInfo link_info(h_holder, name, sig, h_accessor, LinkInfo::needs_access_check, tag);
   switch (bc) {
   case Bytecodes::_invokestatic:
     dest_method =
@@ -363,7 +364,8 @@
 
   if (holder_is_accessible) { // Our declared holder is loaded.
     instanceKlassHandle lookup = get_instance_klass_for_declared_method_holder(holder);
-    methodHandle m = lookup_method(accessor, lookup, name_sym, sig_sym, bc);
+    constantTag tag = cpool->tag_ref_at(index);
+    methodHandle m = lookup_method(accessor, lookup, name_sym, sig_sym, bc, tag);
     if (!m.is_null() &&
         (bc == Bytecodes::_invokestatic
          ?  InstanceKlass::cast(m->method_holder())->is_not_initialized()
--- a/src/share/vm/jvmci/jvmciEnv.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/jvmci/jvmciEnv.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -130,7 +130,8 @@
                            instanceKlassHandle  holder,
                            Symbol*         name,
                            Symbol*         sig,
-                           Bytecodes::Code bc);
+                           Bytecodes::Code bc,
+                           constantTag     tag);
 
   private:
 
--- a/src/share/vm/logging/logConfiguration.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/logging/logConfiguration.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -415,7 +415,9 @@
 void LogConfiguration::describe_current_configuration(outputStream* out){
   out->print_cr("Log output configuration:");
   for (size_t i = 0; i < _n_outputs; i++) {
-    out->print("#" SIZE_FORMAT ": %s %s ", i, _outputs[i]->name(), _outputs[i]->config_string());
+    out->print("#" SIZE_FORMAT ": %s ", i, _outputs[i]->name());
+    out->print_raw(_outputs[i]->config_string());
+    out->print(" ");
     char delimiter[2] = {0};
     for (size_t d = 0; d < LogDecorators::Count; d++) {
       LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(d);
--- a/src/share/vm/memory/allocation.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/memory/allocation.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -144,8 +144,9 @@
   mtTracing           = 0x0E,  // memory used for Tracing
   mtLogging           = 0x0F,  // memory for logging
   mtArguments         = 0x10,  // memory for argument processing
-  mtNone              = 0x11,  // undefined
-  mt_number_of_types  = 0x12   // number of memory types (mtDontTrack
+  mtModule            = 0x11,  // memory for module processing
+  mtNone              = 0x12,  // undefined
+  mt_number_of_types  = 0x13   // number of memory types (mtDontTrack
                                  // is not included as validate type)
 };
 
--- a/src/share/vm/memory/metaspaceShared.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/memory/metaspaceShared.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -191,7 +191,12 @@
     case Bytecodes::_getfield:      *bcs.bcp() = Bytecodes::_nofast_getfield;      break;
     case Bytecodes::_putfield:      *bcs.bcp() = Bytecodes::_nofast_putfield;      break;
     case Bytecodes::_aload_0:       *bcs.bcp() = Bytecodes::_nofast_aload_0;       break;
-    case Bytecodes::_iload:         *bcs.bcp() = Bytecodes::_nofast_iload;         break;
+    case Bytecodes::_iload: {
+      if (!bcs.is_wide()) {
+        *bcs.bcp() = Bytecodes::_nofast_iload;
+      }
+      break;
+    }
     default: break;
     }
   }
--- a/src/share/vm/oops/constantPool.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/oops/constantPool.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -417,6 +417,19 @@
   return extract_high_short_from_int(ref_index);
 }
 
+constantTag ConstantPool::impl_tag_ref_at(int which, bool uncached) {
+  int pool_index = which;
+  if (!uncached && cache() != NULL) {
+    if (ConstantPool::is_invokedynamic_index(which)) {
+      // Invokedynamic index is index into resolved_references
+      pool_index = invokedynamic_cp_cache_entry_at(which)->constant_pool_index();
+    } else {
+      // change byte-ordering and go via cache
+      pool_index = remap_instruction_operand_from_cache(which);
+    }
+  }
+  return tag_at(pool_index);
+}
 
 int ConstantPool::impl_klass_ref_index_at(int which, bool uncached) {
   guarantee(!ConstantPool::is_invokedynamic_index(which),
@@ -672,6 +685,7 @@
       int callee_index             = this_cp->method_handle_klass_index_at(index);
       Symbol*  name =      this_cp->method_handle_name_ref_at(index);
       Symbol*  signature = this_cp->method_handle_signature_ref_at(index);
+      constantTag m_tag  = this_cp->tag_at(this_cp->method_handle_index_at(index));
       { ResourceMark rm(THREAD);
         log_debug(class, resolve)("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s",
                               ref_kind, index, this_cp->method_handle_index_at(index),
@@ -681,6 +695,15 @@
       { Klass* k = klass_at_impl(this_cp, callee_index, true, CHECK_NULL);
         callee = KlassHandle(THREAD, k);
       }
+      if ((callee->is_interface() && m_tag.is_method()) ||
+          (!callee->is_interface() && m_tag.is_interface_method())) {
+        ResourceMark rm(THREAD);
+        char buf[200];
+        jio_snprintf(buf, sizeof(buf), "Inconsistent constant data for %s.%s%s at index %d",
+          callee->name()->as_C_string(), name->as_C_string(), signature->as_C_string(), index);
+        THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
+      }
+
       KlassHandle klass(THREAD, this_cp->pool_holder());
       Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind,
                                                                    callee, name, signature,
--- a/src/share/vm/oops/constantPool.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/oops/constantPool.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -643,6 +643,8 @@
 
   int remap_instruction_operand_from_cache(int operand);  // operand must be biased by CPCACHE_INDEX_TAG
 
+  constantTag tag_ref_at(int cp_cache_index)      { return impl_tag_ref_at(cp_cache_index, false); }
+
   // Lookup for entries consisting of (name_index, signature_index)
   int name_ref_index_at(int which_nt);            // ==  low-order jshort of name_and_type_at(which_nt)
   int signature_ref_index_at(int which_nt);       // == high-order jshort of name_and_type_at(which_nt)
@@ -763,6 +765,7 @@
   Symbol* impl_signature_ref_at(int which, bool uncached);
   int       impl_klass_ref_index_at(int which, bool uncached);
   int       impl_name_and_type_ref_index_at(int which, bool uncached);
+  constantTag impl_tag_ref_at(int which, bool uncached);
 
   // Used while constructing constant pool (only by ClassFileParser)
   jint klass_index_at(int which) {
--- a/src/share/vm/oops/instanceKlass.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/oops/instanceKlass.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1104,21 +1104,21 @@
 
 void InstanceKlass::mask_for(const methodHandle& method, int bci,
   InterpreterOopMap* entry_for) {
-  // Dirty read, then double-check under a lock.
-  if (_oop_map_cache == NULL) {
-    // Otherwise, allocate a new one.
+  // Lazily create the _oop_map_cache at first request
+  // Lock-free access requires load_ptr_acquire.
+  OopMapCache* oop_map_cache =
+      static_cast<OopMapCache*>(OrderAccess::load_ptr_acquire(&_oop_map_cache));
+  if (oop_map_cache == NULL) {
     MutexLocker x(OopMapCacheAlloc_lock);
-    // First time use. Allocate a cache in C heap
-    if (_oop_map_cache == NULL) {
-      // Release stores from OopMapCache constructor before assignment
-      // to _oop_map_cache. C++ compilers on ppc do not emit the
-      // required memory barrier only because of the volatile
-      // qualifier of _oop_map_cache.
-      OrderAccess::release_store_ptr(&_oop_map_cache, new OopMapCache());
+    // Check if _oop_map_cache was allocated while we were waiting for this lock
+    if ((oop_map_cache = _oop_map_cache) == NULL) {
+      oop_map_cache = new OopMapCache();
+      // Ensure _oop_map_cache is stable, since it is examined without a lock
+      OrderAccess::release_store_ptr(&_oop_map_cache, oop_map_cache);
     }
   }
-  // _oop_map_cache is constant after init; lookup below does is own locking.
-  _oop_map_cache->lookup(method, bci, entry_for);
+  // _oop_map_cache is constant after init; lookup below does its own locking.
+  oop_map_cache->lookup(method, bci, entry_for);
 }
 
 
--- a/src/share/vm/prims/methodHandles.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/prims/methodHandles.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -713,12 +713,16 @@
   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::needs_access_check :
+                                              LinkInfo::skip_access_check;
+
   // Time to do the lookup.
   switch (flags & ALL_KINDS) {
   case IS_METHOD:
     {
       CallInfo result;
-      LinkInfo link_info(defc, name, type, caller, caller.not_null());
+      LinkInfo link_info(defc, name, type, caller, access_check);
       {
         assert(!HAS_PENDING_EXCEPTION, "");
         if (ref_kind == JVM_REF_invokeStatic) {
@@ -755,7 +759,7 @@
   case IS_CONSTRUCTOR:
     {
       CallInfo result;
-      LinkInfo link_info(defc, name, type, caller, caller.not_null());
+      LinkInfo link_info(defc, name, type, caller, access_check);
       {
         assert(!HAS_PENDING_EXCEPTION, "");
         if (name == vmSymbols::object_initializer_name()) {
@@ -776,7 +780,7 @@
       fieldDescriptor result; // find_field initializes fd if found
       {
         assert(!HAS_PENDING_EXCEPTION, "");
-        LinkInfo link_info(defc, name, type, caller, /*check_access*/false);
+        LinkInfo link_info(defc, name, type, caller, LinkInfo::skip_access_check);
         LinkResolver::resolve_field(result, link_info, Bytecodes::_nop, false, THREAD);
         if (HAS_PENDING_EXCEPTION) {
           return empty;
--- a/src/share/vm/prims/unsafe.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/prims/unsafe.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -356,19 +356,6 @@
   return JNIHandles::make_local(env, v);
 } UNSAFE_END
 
-UNSAFE_ENTRY(jclass, Unsafe_GetJavaMirror(JNIEnv *env, jobject unsafe, jlong metaspace_klass)) {
-  Klass* klass = (Klass*) (address) metaspace_klass;
-
-  return (jclass) JNIHandles::make_local(klass->java_mirror());
-} UNSAFE_END
-
-UNSAFE_ENTRY(jlong, Unsafe_GetKlassPointer(JNIEnv *env, jobject unsafe, jobject obj)) {
-  oop o = JNIHandles::resolve(obj);
-  jlong klass = (jlong) (address) o->klass();
-
-  return klass;
-} UNSAFE_END
-
 #ifndef SUPPORTS_NATIVE_CX8
 
 // VM_Version::supports_cx8() is a surrogate for 'supports atomic long memory ops'.
@@ -1152,8 +1139,6 @@
     {CC "putObjectVolatile",CC "(" OBJ "J" OBJ ")V",  FN_PTR(Unsafe_PutObjectVolatile)},
 
     {CC "getUncompressedObject", CC "(" ADR ")" OBJ,  FN_PTR(Unsafe_GetUncompressedObject)},
-    {CC "getJavaMirror",         CC "(" ADR ")" CLS,  FN_PTR(Unsafe_GetJavaMirror)},
-    {CC "getKlassPointer",       CC "(" OBJ ")" ADR,  FN_PTR(Unsafe_GetKlassPointer)},
 
     DECLARE_GETPUTOOP(Boolean, Z),
     DECLARE_GETPUTOOP(Byte, B),
--- a/src/share/vm/prims/whitebox.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/prims/whitebox.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -278,6 +278,49 @@
                                         (size_t) magnitude, (size_t) iterations);
 WB_END
 
+static const jint serial_code   = 1;
+static const jint parallel_code = 2;
+static const jint cms_code      = 4;
+static const jint g1_code       = 8;
+
+WB_ENTRY(jint, WB_CurrentGC(JNIEnv* env, jobject o, jobject obj))
+  if (UseSerialGC) {
+    return serial_code;
+  } else if (UseParallelGC || UseParallelOldGC) {
+    return parallel_code;
+  } if (UseConcMarkSweepGC) {
+    return cms_code;
+  } else if (UseG1GC) {
+    return g1_code;
+  }
+  ShouldNotReachHere();
+  return 0;
+WB_END
+
+WB_ENTRY(jint, WB_AllSupportedGC(JNIEnv* env, jobject o, jobject obj))
+#if INCLUDE_ALL_GCS
+  return serial_code | parallel_code | cms_code | g1_code;
+#else
+  return serial_code;
+#endif // INCLUDE_ALL_GCS
+WB_END
+
+WB_ENTRY(jboolean, WB_GCSelectedByErgo(JNIEnv* env, jobject o, jobject obj))
+  if (UseSerialGC) {
+    return FLAG_IS_ERGO(UseSerialGC);
+  } else if (UseParallelGC) {
+    return FLAG_IS_ERGO(UseParallelGC);
+  } else if (UseParallelOldGC) {
+    return FLAG_IS_ERGO(UseParallelOldGC);
+  } else if (UseConcMarkSweepGC) {
+    return FLAG_IS_ERGO(UseConcMarkSweepGC);
+  } else if (UseG1GC) {
+    return FLAG_IS_ERGO(UseG1GC);
+  }
+  ShouldNotReachHere();
+  return false;
+WB_END
+
 WB_ENTRY(jboolean, WB_isObjectInOldGen(JNIEnv* env, jobject o, jobject obj))
   oop p = JNIHandles::resolve(obj);
 #if INCLUDE_ALL_GCS
@@ -1833,7 +1876,10 @@
   {CC"clearInlineCaches0",  CC"(Z)V",                 (void*)&WB_ClearInlineCaches },
   {CC"addCompilerDirective",    CC"(Ljava/lang/String;)I",
                                                       (void*)&WB_AddCompilerDirective },
-  {CC"removeCompilerDirective", CC"(I)V",             (void*)&WB_RemoveCompilerDirective },
+  {CC"removeCompilerDirective",   CC"(I)V",             (void*)&WB_RemoveCompilerDirective },
+  {CC"currentGC",                 CC"()I",            (void*)&WB_CurrentGC},
+  {CC"allSupportedGC",            CC"()I",            (void*)&WB_AllSupportedGC},
+  {CC"gcSelectedByErgo",          CC"()Z",            (void*)&WB_GCSelectedByErgo},
 };
 
 #undef CC
--- a/src/share/vm/runtime/javaCalls.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/runtime/javaCalls.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -183,7 +183,7 @@
   CallInfo callinfo;
   Handle receiver = args->receiver();
   KlassHandle recvrKlass(THREAD, receiver.is_null() ? (Klass*)NULL : receiver->klass());
-  LinkInfo link_info(spec_klass, name, signature, KlassHandle(), /*check_access*/false);
+  LinkInfo link_info(spec_klass, name, signature);
   LinkResolver::resolve_virtual_call(
           callinfo, receiver, recvrKlass, link_info, true, CHECK);
   methodHandle method = callinfo.selected_method();
@@ -220,7 +220,7 @@
 
 void JavaCalls::call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
   CallInfo callinfo;
-  LinkInfo link_info(klass, name, signature, KlassHandle(), /*check_access*/false);
+  LinkInfo link_info(klass, name, signature);
   LinkResolver::resolve_special_call(callinfo, link_info, CHECK);
   methodHandle method = callinfo.selected_method();
   assert(method.not_null(), "should have thrown exception");
@@ -255,7 +255,7 @@
 
 void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
   CallInfo callinfo;
-  LinkInfo link_info(klass, name, signature, KlassHandle(), /*check_access*/false);
+  LinkInfo link_info(klass, name, signature);
   LinkResolver::resolve_static_call(callinfo, link_info, true, CHECK);
   methodHandle method = callinfo.selected_method();
   assert(method.not_null(), "should have thrown exception");
--- a/src/share/vm/runtime/os.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/runtime/os.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1336,12 +1336,10 @@
   const int framesize_in_bytes =
     Interpreter::size_top_interpreter_activation(method()) * wordSize;
 
-  assert((thread->stack_base() - thread->stack_size()) +
-         (JavaThread::stack_guard_zone_size() +
-          JavaThread::stack_shadow_zone_size() + framesize_in_bytes) ==
-         ((JavaThread*)thread)->stack_overflow_limit() + framesize_in_bytes, "sanity");
+  address limit = ((JavaThread*)thread)->stack_end() +
+                  (JavaThread::stack_guard_zone_size() + JavaThread::stack_shadow_zone_size());
 
-  return (sp > ((JavaThread*)thread)->stack_overflow_limit() + framesize_in_bytes);
+  return sp > (limit + framesize_in_bytes);
 }
 
 size_t os::page_size_for_region(size_t region_size, size_t min_pages, bool must_be_aligned) {
--- a/src/share/vm/runtime/reflection.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/runtime/reflection.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -998,7 +998,7 @@
   Symbol*  signature  = method->signature();
   Symbol*  name       = method->name();
   LinkResolver::resolve_interface_call(info, receiver, recv_klass,
-                                       LinkInfo(klass, name, signature, KlassHandle(), false),
+                                       LinkInfo(klass, name, signature),
                                        true,
                                        CHECK_(methodHandle()));
   return info.selected_method();
--- a/src/share/vm/runtime/thread.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/runtime/thread.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1371,10 +1371,10 @@
   //  |  reserved pages                      |
   //  |                                      |
   //  --  <-- stack_reserved_zone_base()    ---      ---
-  //                                                 /|\  shadow
+  //                                                 /|\  shadow     <--  stack_overflow_limit() (somewhere in here)
   //                                                  |   zone
   //                                                 \|/  size
-  //  some untouched memory                          ---         <--  stack_overflow_limit()
+  //  some untouched memory                          ---
   //
   //
   //  --
@@ -1522,9 +1522,8 @@
 
   address stack_overflow_limit() { return _stack_overflow_limit; }
   void set_stack_overflow_limit() {
-    _stack_overflow_limit = stack_end() +
-                            (JavaThread::stack_guard_zone_size() +
-                             JavaThread::stack_shadow_zone_size());
+    _stack_overflow_limit =
+      stack_end() + MAX2(JavaThread::stack_guard_zone_size(), JavaThread::stack_shadow_zone_size());
   }
 
   // Misc. accessors/mutators
--- a/src/share/vm/runtime/vm_operations.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/runtime/vm_operations.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -201,10 +201,12 @@
 }
 
 bool VM_PrintThreads::doit_prologue() {
-  assert(Thread::current()->is_Java_thread(), "just checking");
-
   // Make sure AbstractOwnableSynchronizer is loaded
-  java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(JavaThread::current());
+  JavaThread* jt = JavaThread::current();
+  java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(jt);
+  if (jt->has_pending_exception()) {
+    return false;
+  }
 
   // Get Heap_lock if concurrent locks will be dumped
   if (_print_concurrent_locks) {
@@ -240,11 +242,13 @@
 }
 
 bool VM_FindDeadlocks::doit_prologue() {
-  assert(Thread::current()->is_Java_thread(), "just checking");
-
-  // Load AbstractOwnableSynchronizer class
   if (_concurrent_locks) {
-    java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(JavaThread::current());
+    // Make sure AbstractOwnableSynchronizer is loaded
+    JavaThread* jt = JavaThread::current();
+    java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(jt);
+    if (jt->has_pending_exception()) {
+      return false;
+    }
   }
 
   return true;
@@ -298,10 +302,12 @@
 }
 
 bool VM_ThreadDump::doit_prologue() {
-  assert(Thread::current()->is_Java_thread(), "just checking");
-
-  // Load AbstractOwnableSynchronizer class before taking thread snapshots
-  java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(JavaThread::current());
+  // Make sure AbstractOwnableSynchronizer is loaded
+  JavaThread* jt = JavaThread::current();
+  java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(jt);
+  if (jt->has_pending_exception()) {
+    return false;
+  }
 
   if (_with_locked_synchronizers) {
     // Acquire Heap_lock to dump concurrent locks
--- a/src/share/vm/services/nmtCommon.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/services/nmtCommon.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,6 +42,7 @@
   "Tracing",
   "Logging",
   "Arguments",
+  "Module",
   "Unknown"
 };
 
--- a/src/share/vm/services/virtualMemoryTracker.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/services/virtualMemoryTracker.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -23,7 +23,10 @@
  */
 #include "precompiled.hpp"
 
+#include "runtime/atomic.inline.hpp"
+#include "runtime/os.hpp"
 #include "runtime/threadCritical.hpp"
+#include "services/memTracker.hpp"
 #include "services/virtualMemoryTracker.hpp"
 
 size_t VirtualMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)];
@@ -52,46 +55,41 @@
   if (all_committed()) return true;
 
   CommittedMemoryRegion committed_rgn(addr, size, stack);
-  LinkedListNode<CommittedMemoryRegion>* node = _committed_regions.find_node(committed_rgn);
-  if (node != NULL) {
+  LinkedListNode<CommittedMemoryRegion>* node = _committed_regions.head();
+
+  while (node != NULL) {
     CommittedMemoryRegion* rgn = node->data();
     if (rgn->same_region(addr, size)) {
       return true;
     }
 
     if (rgn->adjacent_to(addr, size)) {
-      // check if the next region covers this committed region,
-      // the regions may not be merged due to different call stacks
-      LinkedListNode<CommittedMemoryRegion>* next =
-        node->next();
-      if (next != NULL && next->data()->contain_region(addr, size)) {
-        if (next->data()->same_region(addr, size)) {
-          next->data()->set_call_stack(stack);
-        }
-        return true;
-      }
-      if (rgn->call_stack()->equals(stack)) {
+      // special case to expand prior region if there is no next region
+      LinkedListNode<CommittedMemoryRegion>* next = node->next();
+      if (next == NULL && rgn->call_stack()->equals(stack)) {
         VirtualMemorySummary::record_uncommitted_memory(rgn->size(), flag());
         // the two adjacent regions have the same call stack, merge them
         rgn->expand_region(addr, size);
         VirtualMemorySummary::record_committed_memory(rgn->size(), flag());
         return true;
       }
-      VirtualMemorySummary::record_committed_memory(size, flag());
-      if (rgn->base() > addr) {
-        return _committed_regions.insert_before(committed_rgn, node) != NULL;
-      } else {
-        return _committed_regions.insert_after(committed_rgn, node) != NULL;
       }
+
+    if (rgn->overlap_region(addr, size)) {
+      // Clear a space for this region in the case it overlaps with any regions.
+      remove_uncommitted_region(addr, size);
+      break;  // commit below
     }
-    assert(rgn->contain_region(addr, size), "Must cover this region");
-    return true;
-  } else {
+    if (rgn->end() >= addr + size){
+      break;
+    }
+    node = node->next();
+  }
+
     // New committed region
     VirtualMemorySummary::record_committed_memory(size, flag());
     return add_committed_region(committed_rgn);
   }
-}
 
 void ReservedMemoryRegion::set_all_committed(bool b) {
   if (all_committed() != b) {
@@ -175,48 +173,52 @@
       }
     }
   } else {
-    // we have to walk whole list to remove the committed regions in
-    // specified range
-    LinkedListNode<CommittedMemoryRegion>* head =
-      _committed_regions.head();
+    CommittedMemoryRegion del_rgn(addr, sz, *call_stack());
+    address end = addr + sz;
+
+    LinkedListNode<CommittedMemoryRegion>* head = _committed_regions.head();
     LinkedListNode<CommittedMemoryRegion>* prev = NULL;
-    VirtualMemoryRegion uncommitted_rgn(addr, sz);
+    CommittedMemoryRegion* crgn;
 
-    while (head != NULL && !uncommitted_rgn.is_empty()) {
-      CommittedMemoryRegion* crgn = head->data();
-      // this committed region overlaps to region to uncommit
-      if (crgn->overlap_region(uncommitted_rgn.base(), uncommitted_rgn.size())) {
-        if (crgn->same_region(uncommitted_rgn.base(), uncommitted_rgn.size())) {
-          // find matched region, remove the node will do
-          VirtualMemorySummary::record_uncommitted_memory(uncommitted_rgn.size(), flag());
+    while (head != NULL) {
+      crgn = head->data();
+
+      if (crgn->same_region(addr, sz)) {
+        VirtualMemorySummary::record_uncommitted_memory(crgn->size(), flag());
           _committed_regions.remove_after(prev);
           return true;
-        } else if (crgn->contain_region(uncommitted_rgn.base(), uncommitted_rgn.size())) {
-          // this committed region contains whole uncommitted region
-          VirtualMemorySummary::record_uncommitted_memory(uncommitted_rgn.size(), flag());
-          return remove_uncommitted_region(head, uncommitted_rgn.base(), uncommitted_rgn.size());
-        } else if (uncommitted_rgn.contain_region(crgn->base(), crgn->size())) {
-          // this committed region has been uncommitted
-          size_t exclude_size = crgn->end() - uncommitted_rgn.base();
-          uncommitted_rgn.exclude_region(uncommitted_rgn.base(), exclude_size);
+      }
+
+      // del_rgn contains crgn
+      if (del_rgn.contain_region(crgn->base(), crgn->size())) {
           VirtualMemorySummary::record_uncommitted_memory(crgn->size(), flag());
-          LinkedListNode<CommittedMemoryRegion>* tmp = head;
           head = head->next();
           _committed_regions.remove_after(prev);
-          continue;
-        } else if (crgn->contain_address(uncommitted_rgn.base())) {
-          size_t toUncommitted = crgn->end() - uncommitted_rgn.base();
-          crgn->exclude_region(uncommitted_rgn.base(), toUncommitted);
-          uncommitted_rgn.exclude_region(uncommitted_rgn.base(), toUncommitted);
-          VirtualMemorySummary::record_uncommitted_memory(toUncommitted, flag());
-        } else if (uncommitted_rgn.contain_address(crgn->base())) {
-          size_t toUncommitted = uncommitted_rgn.end() - crgn->base();
-          crgn->exclude_region(crgn->base(), toUncommitted);
-          uncommitted_rgn.exclude_region(uncommitted_rgn.end() - toUncommitted,
-            toUncommitted);
-          VirtualMemorySummary::record_uncommitted_memory(toUncommitted, flag());
+        continue;  // don't update head or prev
         }
+
+      // Found addr in the current crgn. There are 2 subcases:
+      if (crgn->contain_address(addr)) {
+
+        // (1) Found addr+size in current crgn as well. (del_rgn is contained in crgn)
+        if (crgn->contain_address(end - 1)) {
+          VirtualMemorySummary::record_uncommitted_memory(sz, flag());
+          return remove_uncommitted_region(head, addr, sz); // done!
+        } else {
+          // (2) Did not find del_rgn's end in crgn.
+          size_t size = crgn->end() - del_rgn.base();
+          crgn->exclude_region(addr, size);
+          VirtualMemorySummary::record_uncommitted_memory(size, flag());
       }
+
+      } else if (crgn->contain_address(end - 1)) {
+      // Found del_rgn's end, but not its base addr.
+        size_t size = del_rgn.end() - crgn->base();
+        crgn->exclude_region(crgn->base(), size);
+        VirtualMemorySummary::record_uncommitted_memory(size, flag());
+        return true;  // should be done if the list is sorted properly!
+      }
+
       prev = head;
       head = head->next();
     }
@@ -386,7 +388,8 @@
 
   assert(reserved_rgn != NULL, "No reserved region");
   assert(reserved_rgn->contain_region(addr, size), "Not completely contained");
-  return reserved_rgn->add_committed_region(addr, size, stack);
+  bool result = reserved_rgn->add_committed_region(addr, size, stack);
+  return result;
 }
 
 bool VirtualMemoryTracker::remove_uncommitted_region(address addr, size_t size) {
@@ -398,7 +401,8 @@
   ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn);
   assert(reserved_rgn != NULL, "No reserved region");
   assert(reserved_rgn->contain_region(addr, size), "Not completely contained");
-  return reserved_rgn->remove_uncommitted_region(addr, size);
+  bool result = reserved_rgn->remove_uncommitted_region(addr, size);
+  return result;
 }
 
 bool VirtualMemoryTracker::remove_released_region(address addr, size_t size) {
@@ -488,5 +492,3 @@
 
   return true;
 }
-
-
--- a/src/share/vm/services/virtualMemoryTracker.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/services/virtualMemoryTracker.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -261,8 +261,7 @@
     VirtualMemoryRegion(addr, size), _stack(stack) { }
 
   inline int compare(const CommittedMemoryRegion& rgn) const {
-    if (overlap_region(rgn.base(), rgn.size()) ||
-        adjacent_to   (rgn.base(), rgn.size())) {
+    if (overlap_region(rgn.base(), rgn.size())) {
       return 0;
     } else {
       if (base() == rgn.base()) {
--- a/src/share/vm/services/writeableFlags.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/services/writeableFlags.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -93,12 +93,12 @@
 
 // set a boolean global flag
 Flag::Error WriteableFlags::set_bool_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
-  int value = true;
-
-  if (sscanf(arg, "%d", &value)) {
-    return set_bool_flag(name, value != 0, origin, err_msg);
+  if ((strcasecmp(arg, "true") == 0) || (*arg == '1' && *(arg + 1) == 0)) {
+    return set_bool_flag(name, true, origin, err_msg);
+  } else if ((strcasecmp(arg, "false") == 0) || (*arg == '0' && *(arg + 1) == 0)) {
+    return set_bool_flag(name, false, origin, err_msg);
   }
-  err_msg.print("flag value must be a boolean (1 or 0)");
+  err_msg.print("flag value must be a boolean (1/0 or true/false)");
   return Flag::WRONG_FORMAT;
 }
 
--- a/src/share/vm/utilities/hashtable.cpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/utilities/hashtable.cpp	Tue Jun 07 09:11:32 2016 +0000
@@ -383,6 +383,7 @@
 template class BasicHashtable<mtSymbol>;
 template class BasicHashtable<mtCode>;
 template class BasicHashtable<mtInternal>;
+template class BasicHashtable<mtModule>;
 #if INCLUDE_TRACE
 template class Hashtable<Symbol*, mtTracing>;
 template class HashtableEntry<Symbol*, mtTracing>;
--- a/src/share/vm/utilities/linkedlist.hpp	Mon Jun 06 23:24:46 2016 -0700
+++ b/src/share/vm/utilities/linkedlist.hpp	Tue Jun 07 09:11:32 2016 +0000
@@ -259,6 +259,11 @@
 
   virtual bool remove(LinkedListNode<E>* node) {
     LinkedListNode<E>* p = this->head();
+    if (p == node) {
+      this->set_head(p->next());
+      delete_node(node);
+      return true;
+    }
     while (p != NULL && p->next() != node) {
       p = p->next();
     }
--- a/test/Makefile	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/Makefile	Tue Jun 07 09:11:32 2016 +0000
@@ -306,7 +306,10 @@
 endif
 
 ifdef CONCURRENCY
-  EXTRA_JTREG_OPTIONS += -concurrency:$(CONCURRENCY)
+  JTREG_BASIC_OPTIONS += -concurrency:$(CONCURRENCY)
+endif
+ifdef EXTRA_JTREG_OPTIONS
+  JTREG_BASIC_OPTIONS += $(EXTRA_JTREG_OPTIONS)
 endif
 
 # Default JTREG to run
@@ -326,8 +329,6 @@
 # Multiply by 4 the timeout factor
 JTREG_TIMEOUT_OPTION =  -timeoutFactor:4
 JTREG_BASIC_OPTIONS += $(JTREG_TIMEOUT_OPTION)
-# Add any extra options
-JTREG_BASIC_OPTIONS += $(EXTRA_JTREG_OPTIONS)
 # Set other vm and test options
 JTREG_TEST_OPTIONS = $(JAVA_ARGS:%=-javaoptions:%) $(JAVA_OPTIONS:%=-vmoption:%) $(JAVA_VM_ARGS:%=-vmoption:%)
 
--- a/test/compiler/jvmci/compilerToVM/GetConstantPoolTest.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/compiler/jvmci/compilerToVM/GetConstantPoolTest.java	Tue Jun 07 09:11:32 2016 +0000
@@ -138,17 +138,6 @@
                 return CompilerToVMHelper.getConstantPool(cpInst, ptr);
             }
         },
-        OBJECT_TYPE_BASE {
-            @Override
-            ConstantPool getConstantPool() {
-                HotSpotResolvedObjectType type
-                        = HotSpotResolvedObjectType.fromObjectClass(
-                                OBJECT_TYPE_BASE.getClass());
-                long ptrToClass = UNSAFE.getKlassPointer(OBJECT_TYPE_BASE);
-                return CompilerToVMHelper.getConstantPool(type,
-                        getPtrToCpAddress() - ptrToClass);
-            }
-        },
         ;
         abstract ConstantPool getConstantPool();
     }
--- a/test/compiler/jvmci/compilerToVM/GetResolvedJavaTypeTest.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/compiler/jvmci/compilerToVM/GetResolvedJavaTypeTest.java	Tue Jun 07 09:11:32 2016 +0000
@@ -24,6 +24,7 @@
 /*
  * @test
  * @bug 8136421
+ * @ignore 8158860
  * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
  * @library / /testlibrary /test/lib
  * @library ../common/patches
@@ -149,25 +150,12 @@
                         ptr, COMPRESSED);
             }
         },
-        OBJECT_TYPE_BASE {
-            @Override
-            HotSpotResolvedObjectType getResolvedJavaType() {
-                HotSpotResolvedObjectType type
-                        = HotSpotResolvedObjectType.fromObjectClass(
-                        OBJECT_TYPE_BASE.getClass());
-                long ptrToClass = UNSAFE.getKlassPointer(OBJECT_TYPE_BASE);
-                return CompilerToVMHelper.getResolvedJavaType(type,
-                        getPtrToKlass() - ptrToClass, COMPRESSED);
-            }
-        },
         ;
         abstract HotSpotResolvedObjectType getResolvedJavaType();
     }
 
     private static final Unsafe UNSAFE = Utils.getUnsafe();
     private static final WhiteBox WB = WhiteBox.getWhiteBox();
-    private static final long PTR = UNSAFE.getKlassPointer(
-            new GetResolvedJavaTypeTest());
     private static final Class TEST_CLASS = GetResolvedJavaTypeTest.class;
     /* a compressed parameter for tested method is set to false because
        unsafe.getKlassPointer always returns uncompressed pointer */
--- a/test/gc/TestSmallHeap.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/gc/TestSmallHeap.java	Tue Jun 07 09:11:32 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,22 +23,15 @@
 
 /**
  * @test TestSmallHeap
- * @bug 8067438
+ * @bug 8067438 8152239
  * @requires vm.gc=="null"
- * @requires (vm.opt.AggressiveOpts=="null") | (vm.opt.AggressiveOpts=="false")
- * @requires vm.compMode != "Xcomp"
- * @requires vm.opt.UseCompressedOops != false
  * @summary Verify that starting the VM with a small heap works
- * @library /testlibrary /test/lib
+ * @library /testlibrary /test/lib /test/lib/share/classes
  * @modules java.base/jdk.internal.misc
  * @modules java.management/sun.management
- * @ignore 8076621
  * @build TestSmallHeap
  * @run main ClassFileInstaller sun.hotspot.WhiteBox
- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx2m -XX:+UseParallelGC TestSmallHeap
- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx2m -XX:+UseSerialGC TestSmallHeap
- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx2m -XX:+UseG1GC TestSmallHeap
- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx2m -XX:+UseConcMarkSweepGC TestSmallHeap
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestSmallHeap
  */
 
 /* Note: It would be nice to verify the minimal supported heap size (2m) here,
@@ -60,23 +53,55 @@
  * So, the expected heap size is page_size * 512.
  */
 
-import jdk.test.lib.*;
-import com.sun.management.HotSpotDiagnosticMXBean;
-import java.lang.management.ManagementFactory;
-import static jdk.test.lib.Asserts.*;
+import jdk.test.lib.Asserts;
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.process.ProcessTools;
+
+import java.util.LinkedList;
 
 import sun.hotspot.WhiteBox;
 
 public class TestSmallHeap {
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception {
+        // Do all work in the VM driving the test, the VM
+        // with the small heap size should do as little as
+        // possible to avoid hitting an OOME.
         WhiteBox wb = WhiteBox.getWhiteBox();
         int pageSize = wb.getVMPageSize();
         int heapBytesPerCard = 512;
         long expectedMaxHeap = pageSize * heapBytesPerCard;
-        String maxHeap
-            = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class)
-                .getVMOption("MaxHeapSize").getValue();
-        assertEQ(Long.parseLong(maxHeap), expectedMaxHeap);
+
+        verifySmallHeapSize("-XX:+UseParallelGC", expectedMaxHeap);
+        verifySmallHeapSize("-XX:+UseSerialGC", expectedMaxHeap);
+        verifySmallHeapSize("-XX:+UseG1GC", expectedMaxHeap);
+        verifySmallHeapSize("-XX:+UseConcMarkSweepGC", expectedMaxHeap);
+    }
+
+    private static void verifySmallHeapSize(String gc, long expectedMaxHeap) throws Exception {
+        LinkedList<String> vmOptions = new LinkedList<>();
+        vmOptions.add(gc);
+        vmOptions.add("-Xmx2m");
+        vmOptions.add("-XX:+PrintFlagsFinal");
+        vmOptions.add(VerifyHeapSize.class.getName());
+
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[0]));
+        OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
+        analyzer.shouldHaveExitValue(0);
+
+        long maxHeapSize = Long.parseLong(analyzer.firstMatch("MaxHeapSize.+=\\s+(\\d+)",1));
+        long actualHeapSize = Long.parseLong(analyzer.firstMatch(VerifyHeapSize.actualMsg + "(\\d+)",1));
+        Asserts.assertEQ(maxHeapSize, expectedMaxHeap);
+        Asserts.assertLessThanOrEqual(actualHeapSize, maxHeapSize);
     }
 }
+
+class VerifyHeapSize {
+    public static final String actualMsg = "Actual heap size: ";
+
+    public static void main(String args[]) {
+        // Avoid string concatenation
+        System.out.print(actualMsg);
+        System.out.println(Runtime.getRuntime().maxMemory());
+    }
+}
--- a/test/gc/g1/ihop/TestIHOPErgo.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/gc/g1/ihop/TestIHOPErgo.java	Tue Jun 07 09:11:32 2016 +0000
@@ -28,6 +28,7 @@
  * @requires vm.gc=="G1" | vm.gc=="null"
  * @requires vm.opt.FlightRecorder != true
  * @requires vm.opt.ExplicitGCInvokesConcurrent != true
+ * @requires vm.opt.MaxGCPauseMillis == "null"
  * @library /testlibrary /test/lib /
  * @modules java.base/jdk.internal.misc
  * @modules java.management
--- a/test/gc/g1/mixedgc/TestLogging.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/gc/g1/mixedgc/TestLogging.java	Tue Jun 07 09:11:32 2016 +0000
@@ -25,6 +25,7 @@
  * @test TestLogging
  * @summary Check that a mixed GC is reflected in the gc logs
  * @requires vm.gc=="G1" | vm.gc=="null"
+ * @requires vm.opt.MaxGCPauseMillis == "null"
  * @library /testlibrary /test/lib
  * @modules java.base/jdk.internal.misc
  * @modules java.management
--- a/test/gc/g1/plab/TestPLABPromotion.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/gc/g1/plab/TestPLABPromotion.java	Tue Jun 07 09:11:32 2016 +0000
@@ -122,10 +122,7 @@
             List<String> options = PLABUtils.prepareOptions(testCase.toOptions());
             options.add(AppPLABPromotion.class.getName());
             OutputAnalyzer out = ProcessTools.executeTestJvm(options.toArray(new String[options.size()]));
-            if (out.getExitValue() != 0) {
-                System.out.println(out.getOutput());
-                throw new RuntimeException("Expect exit code 0.");
-            }
+            PLABUtils.commonCheck(out);
             output = out.getOutput();
             checkResults(testCase);
         }
--- a/test/gc/g1/plab/TestPLABResize.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/gc/g1/plab/TestPLABResize.java	Tue Jun 07 09:11:32 2016 +0000
@@ -94,10 +94,7 @@
             List<String> options = PLABUtils.prepareOptions(testCase.toOptions());
             options.add(AppPLABResize.class.getName());
             OutputAnalyzer out = ProcessTools.executeTestJvm(options.toArray(new String[options.size()]));
-            if (out.getExitValue() != 0) {
-                System.out.println(out.getOutput());
-                throw new RuntimeException("Exit code is not 0");
-            }
+            PLABUtils.commonCheck(out);
             checkResults(out.getOutput(), testCase);
         }
     }
@@ -124,6 +121,11 @@
         // The test case does 3 rounds of allocations.  The second round of N allocations and GC's
         // has a decreasing size of allocations so that iterations N to 2*N -1 will be of decreasing size.
         // The third round with iterations 2*N to 3*N -1 has increasing sizes of allocation.
+        if ( plabSizes.size() != testCase.iterations * 3 ) {
+            System.out.println(output);
+            throw new RuntimeException ("Expects for " + testCase.iterations * 3 + " PLAB entries in log, found " + plabSizes.size());
+        }
+
         long startDesiredPLABSize = plabSizes.get(testCase.getIterations());
         long endDesiredPLABSize = plabSizes.get(testCase.getIterations() * 2 - 1);
 
--- a/test/gc/g1/plab/lib/LogParser.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/gc/g1/plab/lib/LogParser.java	Tue Jun 07 09:11:32 2016 +0000
@@ -169,7 +169,12 @@
      * @return
      **/
     public PlabInfo getSpecifiedStats(long specifiedGcId, LogParser.ReportType type, List<String> fieldsName) {
-        return getSpecifiedStats(Arrays.asList(specifiedGcId), type, fieldsName, true).get(specifiedGcId);
+        PlabInfo info = getSpecifiedStats(Arrays.asList(specifiedGcId), type, fieldsName, true).get(specifiedGcId);
+        if (info == null) {
+            System.out.println(log);
+            throw new RuntimeException("Cannot find PLAB statistics in log ( GC_ID=" + specifiedGcId + " type=" + type + " )");
+        }
+        return info;
     }
 
     /**
--- a/test/gc/g1/plab/lib/PLABUtils.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/gc/g1/plab/lib/PLABUtils.java	Tue Jun 07 09:11:32 2016 +0000
@@ -26,6 +26,7 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import jdk.test.lib.OutputAnalyzer;
 import jdk.test.lib.Utils;
 
 /**
@@ -50,7 +51,7 @@
      * GC logging options list.
      */
     private final static String G1_PLAB_LOGGING_OPTIONS[] = {
-        "-Xlog:gc=debug,gc+plab=debug"
+        "-Xlog:gc=debug,gc+plab=debug,gc+heap=debug"
     };
 
     /**
@@ -81,4 +82,18 @@
         executionOtions.addAll(options);
         return executionOtions;
     }
+
+    /**
+     * Common check for test PLAB application's results.
+     * @param out OutputAnalyzer for checking
+     * @throws RuntimeException
+     */
+    public static void commonCheck(OutputAnalyzer out) throws RuntimeException {
+        if (out.getExitValue() != 0) {
+            System.out.println(out.getOutput());
+            throw new RuntimeException("Exit code is not 0");
+        }
+        // Test expects only WhiteBox initiated GC.
+        out.shouldNotContain("Pause Young (G1 Evacuation Pause)");
+    }
 }
--- a/test/gc/stress/TestMultiThreadStressRSet.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/gc/stress/TestMultiThreadStressRSet.java	Tue Jun 07 09:11:32 2016 +0000
@@ -33,6 +33,7 @@
  * @key stress
  * @requires vm.gc=="G1" | vm.gc=="null"
  * @requires os.maxMemory > 2G
+ * @requires vm.opt.MaxGCPauseMillis == "null"
  *
  * @summary Stress G1 Remembered Set using multiple threads
  * @modules java.base/jdk.internal.misc
--- a/test/gc/stress/TestStressRSetCoarsening.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/gc/stress/TestStressRSetCoarsening.java	Tue Jun 07 09:11:32 2016 +0000
@@ -30,6 +30,7 @@
  * @bug 8146984 8147087
  * @requires vm.gc=="G1" | vm.gc=="null"
  * @requires os.maxMemory > 3G
+ * @requires vm.opt.MaxGCPauseMillis == "null"
  *
  * @summary Stress G1 Remembered Set by creating a lot of cross region links
  * @modules java.base/jdk.internal.misc
@@ -102,7 +103,7 @@
 
     private static final WhiteBox WB = WhiteBox.getWhiteBox();
 
-    public final Object[][] storage;
+    public final ObjStorage storage;
 
     /**
      * Number of objects per region. This is a test parameter.
@@ -161,6 +162,8 @@
         long totalFree = rt.maxMemory() - used;
         regionCount = (int) ((totalFree / regionSize) * heapFractionToAllocate);
         long toAllocate = regionCount * regionSize;
+        long freeMemoryLimit = totalFree - toAllocate;
+
         System.out.println("%% Test parameters");
         System.out.println("%%   Objects per region              : " + K);
         System.out.println("%%   Heap fraction to allocate       : " + (int) (heapFractionToAllocate * 100) + "%");
@@ -212,9 +215,15 @@
                 "  (sizeOf(new Object[" + N + "])");
         System.out.println("%%   Reference size        : " + refSize);
 
-        storage = new Object[regionCount * K][];
-        for (int i = 0; i < storage.length; i++) {
-            storage[i] = new Object[N];
+        // Maximum number of objects to allocate is regionCount * K.
+        storage = new ObjStorage(regionCount * K);
+
+        // Add objects as long as there is space in the storage
+        // and we haven't used more memory than planned.
+        while (!storage.isFull() && (rt.maxMemory() - used) > freeMemoryLimit) {
+            storage.addArray(new Object[N]);
+            // Update used memory
+            used = rt.totalMemory() - rt.freeMemory();
         }
     }
 
@@ -255,7 +264,7 @@
                     // The celebrity will be referred from all other regions.
                     // If the number of references after should be less than they
                     // were before, select NULL.
-                    Object celebrity = cur > pre ? storage[to * K] : null;
+                    Object celebrity = cur > pre ? storage.getArrayAt(to * K) : null;
                     for (int from = 0; from < regionCount; from++) {
                         if (to == from) {
                             continue; // no need to refer to itself
@@ -263,7 +272,8 @@
 
                         int step = cur > pre ? +1 : -1;
                         for (int rn = pre; rn != cur; rn += step) {
-                            storage[getY(to, from, rn)][getX(to, from, rn)] = celebrity;
+                            Object[] rnArray = storage.getArrayAt(getY(to, from, rn));
+                            rnArray[getX(to, from, rn)] = celebrity;
                             if (System.currentTimeMillis() > finishAt) {
                                 throw new TimeoutException();
                             }
@@ -290,14 +300,15 @@
                             continue; // no need to refer to itself
                         }
                         for (int rn = 0; rn <= cur; rn++) {
-                            storage[getY(to, from, rn)][getX(to, from, rn)] = null;
+                            Object[] rnArray = storage.getArrayAt(getY(to, from, rn));
+                            rnArray[getX(to, from, rn)] = null;
                         }
                     }
                     // 'Refresh' storage elements for the region 'to'
                     // After that loop all 'old' objects in the region 'to'
                     // should become unreachable.
                     for (int k = 0; k < K; k++) {
-                        storage[(to * K + k) % storage.length] = new Object[N];
+                        storage.setArrayAt(to * K + k, new Object[N]);
                     }
                 }
             }
@@ -340,3 +351,36 @@
     }
 }
 
+//Helper class to encapsulate the object array storage.
+class ObjStorage {
+    public final Object[][] storage;
+    public int usedCount;
+
+    ObjStorage(int size) {
+        storage  = new Object[size][];
+        usedCount = 0;
+    }
+
+    public boolean isFull() {
+        return usedCount >= storage.length;
+    }
+
+    public void addArray(Object[] objects) {
+        if (isFull()) {
+            throw new IllegalStateException("Storage full maximum number of allowed elements: " + usedCount);
+        }
+        storage[usedCount++] = objects;
+    }
+
+    // Limit by usedCount since memory limits can cause the storage
+    // to have unused slots in the end.
+    public void setArrayAt(int i, Object[] objects) {
+        storage[i % usedCount] = objects;
+    }
+
+    // Limit by usedCount since memory limits can cause the storage
+    // to have unused slots in the end.
+    public Object[] getArrayAt(int i) {
+        return storage[i % usedCount];
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/native/GTestWrapper.java	Tue Jun 07 09:11:32 2016 +0000
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/* @test
+ * @summary a jtreg wrapper for gtest tests
+ * @library /test/lib/share/classes
+ * @modules java.base/jdk.internal.misc
+ * @run main/native GTestWrapper
+ */
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Stream;
+import java.util.stream.Collectors;
+
+import java.nio.file.Paths;
+import java.nio.file.Path;
+
+import jdk.test.lib.Platform;
+import jdk.test.lib.Utils;
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+
+public class GTestWrapper {
+    public static void main(String[] args) throws Throwable {
+        // gtestLauncher is located in <test_image>/hotspot/gtest/<vm_variant>/
+        // nativePath points either to <test_image>/hotspot/jtreg/native or to <test_image>/hotspot/gtest
+        Path nativePath = Paths.get(System.getProperty("test.nativepath"));
+        String jvmVariantDir = getJVMVariantSubDir();
+        // let's assume it's <test_image>/hotspot/gtest
+        Path path = nativePath.resolve(jvmVariantDir);
+        if (!path.toFile().exists()) {
+            // maybe it is <test_image>/hotspot/jtreg/native
+            path = nativePath.getParent()
+                             .getParent()
+                             .resolve("gtest")
+                             .resolve(jvmVariantDir);
+        }
+        if (!path.toFile().exists()) {
+            throw new Error("TESTBUG: the library has not been found in " + nativePath);
+        }
+        path = path.resolve("gtestLauncher" + (Platform.isWindows() ? ".exe" : ""));
+        ProcessTools.executeCommand(new String[] {
+                path.toString(),
+                "-jdk",
+                System.getProperty("test.jdk")
+        }).shouldHaveExitValue(0);
+    }
+
+    private static String getJVMVariantSubDir() {
+        if (Platform.isServer()) {
+            return "server";
+        } else if (Platform.isClient()) {
+            return "client";
+        } else if (Platform.isMinimal()) {
+            return "minimal";
+        } else {
+            throw new Error("TESTBUG: unsuppported vm variant");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/runtime/ConstantPool/BadMethodHandles.java	Tue Jun 07 09:11:32 2016 +0000
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8087223
+ * @summary Adding constantTag to keep method call consistent with it.
+ * @library /testlibrary
+ * @modules java.base/jdk.internal.org.objectweb.asm
+ *          java.base/jdk.internal.misc
+ *          java.management
+ * @compile -XDignore.symbol.file BadMethodHandles.java
+ * @run main/othervm BadMethodHandles
+ */
+
+import jdk.internal.org.objectweb.asm.*;
+import java.io.FileOutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import static jdk.internal.org.objectweb.asm.Opcodes.*;
+
+public class BadMethodHandles {
+
+    static byte[] dumpBadInterfaceMethodref() {
+        ClassWriter cw = new ClassWriter(0);
+        cw.visit(52, ACC_PUBLIC | ACC_SUPER, "BadInterfaceMethodref", null, "java/lang/Object", null);
+        Handle handle1 =
+            new Handle(Opcodes.H_INVOKEINTERFACE, "BadInterfaceMethodref", "m", "()V");
+        Handle handle2 =
+            new Handle(Opcodes.H_INVOKEINTERFACE, "BadInterfaceMethodref", "staticM", "()V");
+
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+            mv.visitCode();
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(1, 1);
+            mv.visitEnd();
+        }
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "m", "()V", null, null);
+            mv.visitCode();
+            mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
+            mv.visitLdcInsn("hello from m");
+            mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false/*intf*/);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(3, 1);
+            mv.visitEnd();
+        }
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "staticM", "()V", null, null);
+            mv.visitCode();
+            mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
+            mv.visitLdcInsn("hello from staticM");
+            mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false/*intf*/);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(3, 1);
+            mv.visitEnd();
+        }
+
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "runm", "()V", null, null);
+            mv.visitCode();
+            // REF_invokeStatic
+            mv.visitLdcInsn(handle1);
+            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invoke", "()V", false);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(1, 1);
+            mv.visitEnd();
+        }
+
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "runStaticM", "()V", null, null);
+            mv.visitCode();
+            // REF_invokeStatic
+            mv.visitLdcInsn(handle2);
+            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invoke", "()V", false);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(1, 1);
+            mv.visitEnd();
+        }
+
+        cw.visitEnd();
+        return cw.toByteArray();
+    }
+
+    static byte[] dumpIBad() {
+        ClassWriter cw = new ClassWriter(0);
+        cw.visit(52, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "IBad", null, "java/lang/Object", null);
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "m", "()V", null, null);
+            mv.visitCode();
+            mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
+            mv.visitLdcInsn("hello from m");
+            mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false/*intf*/);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(3, 1);
+            mv.visitEnd();
+        }
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "staticM", "()V", null, null);
+            mv.visitCode();
+            mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
+            mv.visitLdcInsn("hello from staticM");
+            mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false/*intf*/);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(3, 1);
+            mv.visitEnd();
+        }
+        cw.visitEnd();
+        return cw.toByteArray();
+    }
+
+    static byte[] dumpBadMethodref() {
+        ClassWriter cw = new ClassWriter(0);
+        cw.visit(52, ACC_PUBLIC | ACC_SUPER,  "BadMethodref", null, "java/lang/Object", new String[]{"IBad"});
+        Handle handle1 =
+            new Handle(Opcodes.H_INVOKEINTERFACE, "BadMethodref", "m", "()V");
+        Handle handle2 =
+            new Handle(Opcodes.H_INVOKEINTERFACE, "BadMethodref", "staticM", "()V");
+
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+            mv.visitCode();
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(1, 1);
+            mv.visitEnd();
+        }
+
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "runm", "()V", null, null);
+            mv.visitCode();
+            // REF_invokeStatic
+            mv.visitLdcInsn(handle1);
+            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invoke", "()V", false);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(1, 1);
+            mv.visitEnd();
+        }
+
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "runStaticM", "()V", null, null);
+            mv.visitCode();
+            // REF_invokeStatic
+            mv.visitLdcInsn(handle2);
+            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invoke", "()V", false);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(1, 1);
+            mv.visitEnd();
+        }
+
+        cw.visitEnd();
+        return cw.toByteArray();
+    }
+    static class CL extends ClassLoader {
+        @Override
+        protected Class<?> findClass(String name) throws ClassNotFoundException {
+            byte[] classBytes = null;
+            switch (name) {
+            case "BadInterfaceMethodref": classBytes = dumpBadInterfaceMethodref(); break;
+            case "BadMethodref"         : classBytes = dumpBadMethodref(); break;
+            case "IBad"                 : classBytes = dumpIBad(); break;
+            default                     : throw new ClassNotFoundException(name);
+            }
+            return defineClass(name, classBytes, 0, classBytes.length);
+        }
+    }
+
+    public static void main(String[] args) throws Throwable {
+        try (FileOutputStream fos = new FileOutputStream("BadInterfaceMethodref.class")) {
+          fos.write(dumpBadInterfaceMethodref());
+        }
+        try (FileOutputStream fos = new FileOutputStream("IBad.class")) {
+          fos.write(dumpIBad());
+        }
+        try (FileOutputStream fos = new FileOutputStream("BadMethodref.class")) {
+          fos.write(dumpBadMethodref());
+        }
+
+        Class<?> cls = (new CL()).loadClass("BadInterfaceMethodref");
+        String[] methods = {"runm", "runStaticM"};
+        System.out.println("Test BadInterfaceMethodref:");
+        int success = 0;
+        for (String name : methods) {
+            try {
+                System.out.printf("invoke %s: \n", name);
+                cls.getMethod(name).invoke(cls.newInstance());
+                System.out.println("FAILED - ICCE should be thrown");
+            } catch (Throwable e) {
+                if (e instanceof InvocationTargetException && e.getCause() != null &&
+                    e.getCause() instanceof IncompatibleClassChangeError) {
+                    System.out.println("PASSED - expected ICCE thrown");
+                    success++;
+                    continue;
+                } else {
+                    System.out.println("FAILED with wrong exception" + e);
+                    throw e;
+                }
+            }
+        }
+        if (success != methods.length) {
+           throw new Exception("BadInterfaceMethodRef Failed to catch IncompatibleClassChangeError");
+        }
+        System.out.println("Test BadMethodref:");
+        cls = (new CL()).loadClass("BadMethodref");
+        success = 0;
+        for (String name : methods) {
+            try {
+                System.out.printf("invoke %s: \n", name);
+                cls.getMethod(name).invoke(cls.newInstance());
+                System.out.println("FAILED - ICCE should be thrown");
+            } catch (Throwable e) {
+                if (e instanceof InvocationTargetException && e.getCause() != null &&
+                    e.getCause() instanceof IncompatibleClassChangeError) {
+                    System.out.println("PASSED - expected ICCE thrown");
+                    success++;
+                    continue;
+                } else {
+                    System.out.println("FAILED with wrong exception" + e);
+                    throw e;
+                }
+            }
+         }
+         if (success != methods.length) {
+            throw new Exception("BadMethodRef Failed to catch IncompatibleClassChangeError");
+         }
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/runtime/ConstantPool/IntfMethod.java	Tue Jun 07 09:11:32 2016 +0000
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * $bug 8087223
+ * @summary Adding constantTag to keep method call consistent with it.
+ * @library /testlibrary
+ * @modules java.base/jdk.internal.org.objectweb.asm
+ *          java.base/jdk.internal.misc
+ *          java.management
+ * @compile -XDignore.symbol.file IntfMethod.java
+ * @run main/othervm IntfMethod
+ * @run main/othervm -Xint IntfMethod
+ * @run main/othervm -Xcomp IntfMethod
+ */
+
+
+import jdk.internal.org.objectweb.asm.*;
+import java.io.FileOutputStream;
+import java.lang.reflect.InvocationTargetException;
+import static jdk.internal.org.objectweb.asm.Opcodes.*;
+
+public class IntfMethod {
+    static byte[] dumpC() {
+        ClassWriter cw = new ClassWriter(0);
+        cw.visit(52, ACC_PUBLIC | ACC_SUPER, "C", null, "java/lang/Object", new String[]{"I"});
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+            mv.visitCode();
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(1, 1);
+            mv.visitEnd();
+        }
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "testSpecialIntf", "()V", null, null);
+            mv.visitCode();
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitMethodInsn(INVOKESPECIAL, "I", "f1", "()V", /*itf=*/false);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(1, 1);
+            mv.visitEnd();
+        }
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "testStaticIntf", "()V", null, null);
+            mv.visitCode();
+            mv.visitMethodInsn(INVOKESTATIC, "I", "f2", "()V", /*itf=*/false);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(1, 1);
+            mv.visitEnd();
+        }
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "testSpecialClass", "()V", null, null);
+            mv.visitCode();
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitMethodInsn(INVOKESPECIAL, "C", "f1", "()V", /*itf=*/true);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(1, 1);
+            mv.visitEnd();
+        }
+
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "f2", "()V", null, null);
+            mv.visitCode();
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(0, 1);
+            mv.visitEnd();
+        }
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "testStaticClass", "()V", null, null);
+            mv.visitCode();
+            mv.visitMethodInsn(INVOKESTATIC, "C", "f2", "()V", /*itf=*/true);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(1, 1);
+            mv.visitEnd();
+        }
+        cw.visitEnd();
+        return cw.toByteArray();
+    }
+
+    static byte[] dumpI() {
+        ClassWriter cw = new ClassWriter(0);
+        cw.visit(52, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "I", null, "java/lang/Object", null);
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "f1", "()V", null, null);
+            mv.visitCode();
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(0, 1);
+            mv.visitEnd();
+        }
+        {
+            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "f2", "()V", null, null);
+            mv.visitCode();
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(0, 1);
+            mv.visitEnd();
+        }
+        cw.visitEnd();
+        return cw.toByteArray();
+    }
+
+    static class CL extends ClassLoader {
+        @Override
+        protected Class<?> findClass(String name) throws ClassNotFoundException {
+            byte[] classFile;
+            switch (name) {
+                case "I": classFile = dumpI(); break;
+                case "C": classFile = dumpC(); break;
+                default:
+                    throw new ClassNotFoundException(name);
+            }
+            return defineClass(name, classFile, 0, classFile.length);
+        }
+    }
+
+    public static void main(String[] args) throws Throwable {
+        Class<?> cls = (new CL()).loadClass("C");
+        try (FileOutputStream fos = new FileOutputStream("I.class")) { fos.write(dumpI()); }
+        try (FileOutputStream fos = new FileOutputStream("C.class")) { fos.write(dumpC()); }
+
+        int success = 0;
+        for (String name : new String[] { "testSpecialIntf", "testStaticIntf", "testSpecialClass", "testStaticClass"}) {
+            System.out.printf("%s: ", name);
+            try {
+                cls.getMethod(name).invoke(cls.newInstance());
+                System.out.println("FAILED - ICCE not thrown");
+            } catch (Throwable e) {
+                if (e instanceof InvocationTargetException &&
+                    e.getCause() != null && e.getCause() instanceof IncompatibleClassChangeError) {
+                    System.out.println("PASSED - expected ICCE thrown");
+                    success++;
+                    continue;
+                }
+            }
+        }
+        if (success != 4) throw new Exception("Failed to catch ICCE");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/runtime/NMT/CommitOverlappingRegions.java	Tue Jun 07 09:11:32 2016 +0000
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary Test commits of overlapping regions of memory.
+ * @key nmt jcmd
+ * @library /testlibrary /test/lib
+ * @modules java.base/jdk.internal.misc
+ *          java.management
+ * @build   CommitOverlappingRegions
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail CommitOverlappingRegions
+ */
+
+import jdk.test.lib.*;
+import sun.hotspot.WhiteBox;
+
+public class CommitOverlappingRegions {
+    public static WhiteBox wb = WhiteBox.getWhiteBox();
+    public static void main(String args[]) throws Exception {
+        OutputAnalyzer output;
+        long size = 32 * 1024;
+        long addr = wb.NMTReserveMemory(8*size);
+
+        String pid = Long.toString(ProcessTools.getProcessId());
+        ProcessBuilder pb = new ProcessBuilder();
+
+        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail"});
+        System.out.println("Address is " + Long.toHexString(addr));
+
+        // Start: . . . . . . . .
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Test (reserved=256KB, committed=0KB)");
+
+        // Committing: * * * . . . . .
+        // Region:     * * * . . . . .
+        // Expected Total: 3 x 32KB = 96KB
+        wb.NMTCommitMemory(addr + 0*size, 3*size);
+
+        // Committing: . . . . * * * .
+        // Region:     * * * . * * * .
+        // Expected Total: 6 x 32KB = 192KB
+        wb.NMTCommitMemory(addr + 4*size, 3*size);
+
+        // Check output after first 2 commits.
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Test (reserved=256KB, committed=192KB)");
+
+        // Committing: . . * * * . . .
+        // Region:     * * * * * * * .
+        // Expected Total: 7 x 32KB = 224KB
+        wb.NMTCommitMemory(addr + 2*size, 3*size);
+
+        // Check output after overlapping commit.
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Test (reserved=256KB, committed=224KB)");
+
+        // Uncommitting: * * * * * * * *
+        // Region:       . . . . . . . .
+        // Expected Total: 0 x 32KB = 0KB
+        wb.NMTUncommitMemory(addr + 0*size, 8*size);
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Test (reserved=256KB, committed=0KB)");
+
+        // Committing: * * . . . . . .
+        // Region:     * * . . . . . .
+        // Expected Total: 2 x 32KB = 64KB
+        wb.NMTCommitMemory(addr + 0*size, 2*size);
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Test (reserved=256KB, committed=64KB)");
+
+        // Committing: . * * * . . . .
+        // Region:     * * * * . . . .
+        // Expected Total: 4 x 32KB = 128KB
+        wb.NMTCommitMemory(addr + 1*size, 3*size);
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Test (reserved=256KB, committed=128KB)");
+
+        // Uncommitting: * * * . . . . .
+        // Region:       . . . * . . . .
+        // Expected Total: 1 x 32KB = 32KB
+        wb.NMTUncommitMemory(addr + 0*size, 3*size);
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Test (reserved=256KB, committed=32KB)");
+
+        // Committing: . . . * * . . .
+        // Region:     . . . * * . . .
+        // Expected Total: 2 x 32KB = 64KB
+        wb.NMTCommitMemory(addr + 3*size, 2*size);
+        System.out.println("Address is " + Long.toHexString(addr + 3*size));
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Test (reserved=256KB, committed=64KB)");
+
+        // Committing: . . . . * * . .
+        // Region:     . . . * * * . .
+        // Expected Total: 3 x 32KB = 96KB
+        wb.NMTCommitMemory(addr + 4*size, 2*size);
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Test (reserved=256KB, committed=96KB)");
+
+        // Committing: . . . . . * * .
+        // Region:     . . . * * * * .
+        // Expected Total: 4 x 32KB = 128KB
+        wb.NMTCommitMemory(addr + 5*size, 2*size);
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Test (reserved=256KB, committed=128KB)");
+
+        // Committing: . . . . . . * *
+        // Region:     . . . * * * * *
+        // Expected Total: 5 x 32KB = 160KB
+        wb.NMTCommitMemory(addr + 6*size, 2*size);
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Test (reserved=256KB, committed=160KB)");
+
+        // Uncommitting: * * * * * * * *
+        // Region:       . . . . . . . .
+        // Expected Total: 0 x 32KB = 32KB
+        wb.NMTUncommitMemory(addr + 0*size, 8*size);
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Test (reserved=256KB, committed=0KB)");
+    }
+}
--- a/test/runtime/NMT/PrintNMTStatistics.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/NMT/PrintNMTStatistics.java	Tue Jun 07 09:11:32 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -48,6 +48,9 @@
     output_detail.shouldNotContain("error");
     output_detail.shouldHaveExitValue(0);
 
+    // Make sure memory reserved for Module processing is recorded.
+    output_detail.shouldContain(" Module (reserved=");
+
     ProcessBuilder pb1 = ProcessTools.createJavaProcessBuilder(
       "-XX:+UnlockDiagnosticVMOptions",
       "-XX:+PrintNMTStatistics",
--- a/test/runtime/ReservedStack/ReservedStackTest.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/ReservedStack/ReservedStackTest.java	Tue Jun 07 09:11:32 2016 +0000
@@ -27,6 +27,7 @@
  * @modules java.base/jdk.internal.misc
  * @modules java.base/jdk.internal.vm.annotation
  * @build jdk.test.lib.*
+ * @run main/othervm -Xint ReservedStackTest
  * @run main/othervm -XX:-Inline -XX:CompileCommand=exclude,java/util/concurrent/locks/AbstractOwnableSynchronizer.setExclusiveOwnerThread ReservedStackTest
  */
 
@@ -196,9 +197,12 @@
             System.out.println("Test started execution at frame = " + (counter - deframe));
             String result = test.getResult();
             // The feature is not fully implemented on all platforms,
-            // corruptions are still possible
-            boolean supportedPlatform = Platform.isSolaris() || Platform.isOSX()
-                || (Platform.isLinux() && (Platform.isX86() || Platform.isX64()));
+            // corruptions are still possible.
+            boolean supportedPlatform =
+                Platform.isAix() ||
+                (Platform.isLinux() && (Platform.isPPC() || Platform.isX64() || Platform.isX86())) ||
+                Platform.isOSX() ||
+                Platform.isSolaris();
             if (supportedPlatform && !result.contains("PASSED")) {
                 System.out.println(result);
                 throw new Error(result);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/runtime/ReservedStack/ReservedStackTestCompiler.java	Tue Jun 07 09:11:32 2016 +0000
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test ReservedStackTestCompiler
+ * @summary Run ReservedStackTest with dedicated compilers C1 and C2.
+ * @requires vm.flavor == "server"
+ * @library /testlibrary
+ * @modules java.base/jdk.internal.misc
+ * @modules java.base/jdk.internal.vm.annotation
+ * @build jdk.test.lib.* ReservedStackTest
+ * @run main/othervm -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:-Inline -XX:CompileCommand=exclude,java/util/concurrent/locks/AbstractOwnableSynchronizer.setExclusiveOwnerThread ReservedStackTest
+ * @run main/othervm -XX:-TieredCompilation                         -XX:-Inline -XX:CompileCommand=exclude,java/util/concurrent/locks/AbstractOwnableSynchronizer.setExclusiveOwnerThread ReservedStackTest
+ */
+
+// Intentionally left blank. Just runs ReservedStackTest with @requires annotation.
--- a/test/runtime/SelectionResolution/classes/selectionresolution/Clazz.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/SelectionResolution/classes/selectionresolution/Clazz.java	Tue Jun 07 09:11:32 2016 +0000
@@ -72,6 +72,6 @@
     public Clazz(String name, String extending, int access, int classFileVersion, int index, String... implementing) {
         super(name, extending == null ? "java/lang/Object" : extending, access + ACC_SUPER, classFileVersion, index, implementing);
         // Add the default constructor
-        addMethod("<init>", "()V", ACC_PUBLIC).makeConstructor(extending);
+        addMethod("<init>", "()V", ACC_PUBLIC).makeConstructor(extending, false);
     }
 }
--- a/test/runtime/SelectionResolution/classes/selectionresolution/Method.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/SelectionResolution/classes/selectionresolution/Method.java	Tue Jun 07 09:11:32 2016 +0000
@@ -59,14 +59,12 @@
     private final String ownerClassName;
     private final ClassVisitor cv;
     private final MethodVisitor mv;
-    private final boolean isInterface;
     private final ClassBuilder.ExecutionMode execMode;
 
     public Method(ClassConstruct ownerClass, ClassVisitor cv, String name, String descriptor, int access,
                   ClassBuilder.ExecutionMode execMode) {
         this.ownerClassName = ownerClass.getName();
         this.ownerClass = ownerClass;
-        this.isInterface = ownerClass.isInterface();
         this.execMode = execMode;
         this.cv = cv;
         mv = cv.visitMethod(access, name, descriptor, null, null);
@@ -91,12 +89,12 @@
 
     public void makeSuperCallMethod(int invokeInstruction, String className) {
         mv.visitVarInsn(ALOAD, 0);
-        makeCall(invokeInstruction, className);
+        makeCall(invokeInstruction, className, false);
         mv.visitInsn(POP);
         done();
     }
 
-    public void defaultInvoke(int instr, String className, String objectRef) {
+    public void defaultInvoke(int instr, String className, String objectRef, boolean isInterface) {
         switch (instr) {
             case INVOKEVIRTUAL:
                 defaultInvokeVirtual(className, objectRef);
@@ -105,10 +103,10 @@
                 defaultInvokeInterface(className, objectRef);
                 break;
             case INVOKESTATIC:
-                defaultInvokeStatic(className);
+                defaultInvokeStatic(className, isInterface);
                 break;
             case INVOKESPECIAL:
-                defaultInvokeSpecial(className, objectRef);
+                defaultInvokeSpecial(className, objectRef, isInterface);
                 break;
             default:
                 break;
@@ -118,30 +116,26 @@
         mv.visitEnd();
     }
 
-    public void defaultInvokeVirtual(String className, String objectRef) {
+    private void defaultInvokeVirtual(String className, String objectRef) {
         String objectRefPackageName = objectRef.substring(0, objectRef.lastIndexOf("/"));
         makeNewObject(objectRef, objectRefPackageName);
         makeCall(INVOKEVIRTUAL, className, false);
     }
 
-    public void defaultInvokeInterface(String className, String objectRef) {
+    private void defaultInvokeInterface(String className, String objectRef) {
         String objectRefPackageName = objectRef.substring(0, objectRef.lastIndexOf("/"));
         makeNewObject(objectRef, objectRefPackageName);
         makeCall(INVOKEINTERFACE, className, true);
     }
 
-    public void defaultInvokeSpecial(String className, String objectRef) {
+    private void defaultInvokeSpecial(String className, String objectRef, boolean isInterface) {
         String objectRefPackageName = objectRef.substring(0, objectRef.lastIndexOf("/"));
         makeNewObject(objectRef, objectRefPackageName);
-        makeCall(INVOKESPECIAL, className, false);
+        makeCall(INVOKESPECIAL, className, isInterface);
     }
 
-    public void defaultInvokeStatic(String className) {
-        makeCall(INVOKESTATIC, className);
-    }
-
-    private Method makeCall(int invokeInstruction, String className) {
-        return makeCall(invokeInstruction, className, isInterface);
+    private void defaultInvokeStatic(String className, boolean isInterface) {
+        makeCall(INVOKESTATIC, className, isInterface);
     }
 
     private Method makeCall(int invokeInstruction, String className, boolean isInterface) {
@@ -219,7 +213,7 @@
         String className = objectRef.substring(objectRef.lastIndexOf("/") + 1);
         makeStaticCall( objectRefPackageName + "/Helper",
                         "get" + className,
-                        "()L" + objectRef + ";");
+                        "()L" + objectRef + ";", false);
         mv.visitVarInsn(ASTORE, 1);
         mv.visitVarInsn(ALOAD, 1);
     }
@@ -236,12 +230,12 @@
         mv.visitEnd();
     }
 
-    public Method makeStaticCall(String classname, String method, String descriptor) {
+    public Method makeStaticCall(String classname, String method, String descriptor, boolean isInterface) {
         mv.visitMethodInsn(INVOKESTATIC, classname, method, descriptor, isInterface);
         return this;
     }
 
-    public void makeConstructor(String extending) {
+    public void makeConstructor(String extending, boolean isInterface) {
         mv.visitVarInsn(ALOAD, 0);
         mv.visitMethodInsn(INVOKESPECIAL, extending == null ? "java/lang/Object" : extending, "<init>", "()V", isInterface);
         mv.visitInsn(RETURN);
--- a/test/runtime/SelectionResolution/classes/selectionresolution/TestBuilder.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/SelectionResolution/classes/selectionresolution/TestBuilder.java	Tue Jun 07 09:11:32 2016 +0000
@@ -53,9 +53,10 @@
         Method m = clazz.addMethod("test", "()Ljava/lang/Integer;", ACC_PUBLIC + ACC_STATIC, execMode);
         m.defaultInvoke(getInvokeInstruction(testcase.invoke),
                     getName(testcase.methodref),
-                    getName(testcase.objectref));
+                    getName(testcase.objectref),
+                    testcase.hier.isInterface(testcase.methodref));
 
-        mainMethod.makeStaticCall(clazz.getName(), "test", "()Ljava/lang/Integer;").done();
+        mainMethod.makeStaticCall(clazz.getName(), "test", "()Ljava/lang/Integer;", false).done();
     }
 
     private static int getInvokeInstruction(SelectionResolutionTestCase.InvokeInstruction instr) {
--- a/test/runtime/Unsafe/GetKlassPointerGetJavaMirror.java	Mon Jun 06 23:24:46 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/* @test
- * @bug 8022853
- * @library /testlibrary
- * @modules java.base/jdk.internal.misc
- * @build jdk.test.lib.*
- * @run main GetKlassPointerGetJavaMirror
- */
-
-import static jdk.test.lib.Asserts.*;
-
-import jdk.test.lib.*;
-import jdk.internal.misc.Unsafe;
-
-public class GetKlassPointerGetJavaMirror {
-
-    public static void main(String args[]) throws Exception {
-        Unsafe unsafe = Utils.getUnsafe();
-        Object o = new GetKlassPointerGetJavaMirror();
-        final long metaspaceKlass = unsafe.getKlassPointer(o);
-        Class<?> c = unsafe.getJavaMirror(metaspaceKlass);
-        assertEquals(o.getClass(), c);
-    }
-
-}
--- a/test/runtime/modules/AccessCheck/CheckRead.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/CheckRead.java	Tue Jun 07 09:11:32 2016 +0000
@@ -103,7 +103,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/DiffCL_CheckRead.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/DiffCL_CheckRead.java	Tue Jun 07 09:11:32 2016 +0000
@@ -103,7 +103,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/DiffCL_ExpQualOther.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/DiffCL_ExpQualOther.java	Tue Jun 07 09:11:32 2016 +0000
@@ -105,7 +105,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/DiffCL_ExpQualToM1.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/DiffCL_ExpQualToM1.java	Tue Jun 07 09:11:32 2016 +0000
@@ -91,7 +91,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/DiffCL_ExpUnqual.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/DiffCL_ExpUnqual.java	Tue Jun 07 09:11:32 2016 +0000
@@ -92,7 +92,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/DiffCL_PkgNotExp.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/DiffCL_PkgNotExp.java	Tue Jun 07 09:11:32 2016 +0000
@@ -91,7 +91,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/DiffCL_Umod.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/DiffCL_Umod.java	Tue Jun 07 09:11:32 2016 +0000
@@ -92,7 +92,7 @@
      // Resolves "m1"
      Configuration cf = Layer.boot()
              .configuration()
-             .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+             .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
      MyDiffClassLoader.loader1 = new MyDiffClassLoader();
      MyDiffClassLoader.loader2 = new MyDiffClassLoader();
@@ -141,7 +141,7 @@
      // Resolves "m1"
      Configuration cf = Layer.boot()
              .configuration()
-             .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+             .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
      MyDiffClassLoader.loader1 = new MyDiffClassLoader();
      MyDiffClassLoader.loader2 = new MyDiffClassLoader();
@@ -190,7 +190,7 @@
      // Resolves "m1"
      Configuration cf = Layer.boot()
              .configuration()
-             .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+             .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
      MyDiffClassLoader.loader1 = new MyDiffClassLoader();
      MyDiffClassLoader.loader2 = new MyDiffClassLoader();
--- a/test/runtime/modules/AccessCheck/DiffCL_UmodUpkg.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/DiffCL_UmodUpkg.java	Tue Jun 07 09:11:32 2016 +0000
@@ -87,7 +87,7 @@
      // Resolves "m1"
      Configuration cf = Layer.boot()
              .configuration()
-             .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+             .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
      MyDiffClassLoader.loader1 = new MyDiffClassLoader();
      MyDiffClassLoader.loader2 = new MyDiffClassLoader();
@@ -136,7 +136,7 @@
      // Resolves "m1"
      Configuration cf = Layer.boot()
              .configuration()
-             .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+             .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
      MyDiffClassLoader.loader1 = new MyDiffClassLoader();
      MyDiffClassLoader.loader2 = new MyDiffClassLoader();
--- a/test/runtime/modules/AccessCheck/ExpQualOther.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/ExpQualOther.java	Tue Jun 07 09:11:32 2016 +0000
@@ -105,7 +105,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/ExpQualToM1.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/ExpQualToM1.java	Tue Jun 07 09:11:32 2016 +0000
@@ -81,7 +81,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to the same class loader for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/ExpUnqual.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/ExpUnqual.java	Tue Jun 07 09:11:32 2016 +0000
@@ -81,7 +81,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to the same class loader for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/ExportAllUnnamed.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/ExportAllUnnamed.java	Tue Jun 07 09:11:32 2016 +0000
@@ -93,7 +93,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/PkgNotExp.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/PkgNotExp.java	Tue Jun 07 09:11:32 2016 +0000
@@ -91,7 +91,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to the same class loader for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/Umod.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/Umod.java	Tue Jun 07 09:11:32 2016 +0000
@@ -92,7 +92,7 @@
      // Resolves "m1"
      Configuration cf = Layer.boot()
              .configuration()
-             .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+             .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
      // map module m1 to class loader.
      // class c2 will be loaded in an unnamed module/loader.
@@ -138,7 +138,7 @@
      // Resolves "m1"
      Configuration cf = Layer.boot()
              .configuration()
-             .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+             .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
      MySameClassLoader loader = new MySameClassLoader();
      // map module m1 to class loader.
@@ -184,7 +184,7 @@
      // Resolves "m1"
      Configuration cf = Layer.boot()
              .configuration()
-             .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+             .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
      MySameClassLoader loader = new MySameClassLoader();
      // map module m1 to class loader.
--- a/test/runtime/modules/AccessCheck/UmodDiffCL_ExpQualOther.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/UmodDiffCL_ExpQualOther.java	Tue Jun 07 09:11:32 2016 +0000
@@ -92,7 +92,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/UmodDiffCL_ExpUnqual.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/UmodDiffCL_ExpUnqual.java	Tue Jun 07 09:11:32 2016 +0000
@@ -92,7 +92,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/UmodDiffCL_PkgNotExp.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/UmodDiffCL_PkgNotExp.java	Tue Jun 07 09:11:32 2016 +0000
@@ -91,7 +91,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/UmodUPkg.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/UmodUPkg.java	Tue Jun 07 09:11:32 2016 +0000
@@ -87,7 +87,7 @@
      // Resolves "m1"
      Configuration cf = Layer.boot()
              .configuration()
-             .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+             .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
      // map module m1 to class loader.
      // class c4 will be loaded in an unnamed module/loader.
@@ -133,7 +133,7 @@
      // Resolves "m1"
      Configuration cf = Layer.boot()
              .configuration()
-             .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+             .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
      MySameClassLoader loader = new MySameClassLoader();
      // map module m1 to class loader.
--- a/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_ExpQualOther.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_ExpQualOther.java	Tue Jun 07 09:11:32 2016 +0000
@@ -92,7 +92,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_NotExp.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_NotExp.java	Tue Jun 07 09:11:32 2016 +0000
@@ -91,7 +91,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/UmodUpkg_ExpQualOther.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/UmodUpkg_ExpQualOther.java	Tue Jun 07 09:11:32 2016 +0000
@@ -101,7 +101,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/UmodUpkg_NotExp.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/UmodUpkg_NotExp.java	Tue Jun 07 09:11:32 2016 +0000
@@ -89,7 +89,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to the same class loader for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/Umod_ExpQualOther.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/Umod_ExpQualOther.java	Tue Jun 07 09:11:32 2016 +0000
@@ -101,7 +101,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/Umod_ExpUnqual.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/Umod_ExpUnqual.java	Tue Jun 07 09:11:32 2016 +0000
@@ -91,7 +91,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to differing class loaders for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/runtime/modules/AccessCheck/Umod_PkgNotExp.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/runtime/modules/AccessCheck/Umod_PkgNotExp.java	Tue Jun 07 09:11:32 2016 +0000
@@ -89,7 +89,7 @@
         // Resolves "m1"
         Configuration cf = Layer.boot()
                 .configuration()
-                .resolveRequires(finder, ModuleFinder.empty(), Set.of("m1"));
+                .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
 
         // map each module to the same class loader for this test
         Map<String, ClassLoader> map = new HashMap<>();
--- a/test/serviceability/dcmd/vm/SetVMFlagTest.java	Mon Jun 06 23:24:46 2016 -0700
+++ b/test/serviceability/dcmd/vm/SetVMFlagTest.java	Tue Jun 07 09:11:32 2016 +0000
@@ -56,6 +56,25 @@
         run(new JMXExecutor());
     }
 
+    private void setMutableFlagInternal(CommandExecutor executor, String flag,
+                                        boolean val, boolean isNumeric) {
+        String strFlagVal;
+        if (isNumeric) {
+            strFlagVal = val ? "1" : "0";
+        } else {
+            strFlagVal = val ? "true" : "false";
+        }
+
+        OutputAnalyzer out = executor.execute("VM.set_flag " + flag + " " + strFlagVal);
+        out.stderrShouldBeEmpty();
+
+        out = getAllFlags(executor);
+
+        String newFlagVal = out.firstMatch(MANAGEABLE_PATTERN.replace("(\\S+)", flag), 1);
+
+        assertNotEquals(newFlagVal, val ? "1" : "0");
+    }
+
     private void setMutableFlag(CommandExecutor executor) {
         OutputAnalyzer out = getAllFlags(executor);
         String flagName = out.firstMatch(MANAGEABLE_PATTERN, 1);
@@ -69,15 +88,8 @@
         }
 
         Boolean blnVal = Boolean.parseBoolean(flagVal);
-
-        out = executor.execute("VM.set_flag " + flagName + " " + (blnVal ? 0 : 1));
-        out.stderrShouldBeEmpty();
-
-        out = getAllFlags(executor);
-
-        String newFlagVal = out.firstMatch(MANAGEABLE_PATTERN.replace("(\\S+)", flagName), 1);
-
-        assertNotEquals(newFlagVal, flagVal);
+        setMutableFlagInternal(executor, flagName, !blnVal, true);
+        setMutableFlagInternal(executor, flagName, blnVal, false);
     }
 
     private void setMutableFlagWithInvalidValue(CommandExecutor executor) {
@@ -95,7 +107,7 @@
         // a boolean flag accepts only 0/1 as its value
         out = executor.execute("VM.set_flag " + flagName + " unexpected_value");
         out.stderrShouldBeEmpty();
-        out.stdoutShouldContain("flag value must be a boolean (1 or 0)");
+        out.stdoutShouldContain("flag value must be a boolean (1/0 or true/false)");
 
         out = getAllFlags(executor);