Merge epsilon-gc-branch
authorshade
Thu, 19 Apr 2018 14:17:54 +0200
branchepsilon-gc-branch
changeset 56458 7d42ec654589
parent 56452 ec435d4e0673 (current diff)
parent 49831 81e8cdf31b5a (diff)
child 56461 d661341c153a
Merge
src/hotspot/cpu/sparc/templateTable_sparc.cpp
src/hotspot/share/memory/universe.cpp
test/langtools/tools/javac/6410653/T6410653.java
test/langtools/tools/javac/T8009640/CheckRejectProfileBCPOptionsIfUsedTogetherTest.java
test/langtools/tools/javac/options/release/ReleaseOptionClashes.java
--- a/make/langtools/tools/propertiesparser/parser/MessageType.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/make/langtools/tools/propertiesparser/parser/MessageType.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -86,13 +86,17 @@
         NAME("name", "Name", "com.sun.tools.javac.util"),
         NUMBER("number", "int", null),
         OPTION_NAME("option name", "Option", "com.sun.tools.javac.main"),
+        PROFILE("profile", "Profile", "com.sun.tools.javac.jvm"),
+        SOURCE("source", "Source", "com.sun.tools.javac.code"),
         SOURCE_VERSION("source version", "SourceVersion", "javax.lang.model"),
         STRING("string", "String", null),
         SYMBOL("symbol", "Symbol", "com.sun.tools.javac.code"),
         SYMBOL_KIND("symbol kind", "Kind", "com.sun.tools.javac.code.Kinds"),
         KIND_NAME("kind name", "KindName", "com.sun.tools.javac.code.Kinds"),
+        TARGET("target", "Target", "com.sun.tools.javac.jvm"),
         TOKEN("token", "TokenKind", "com.sun.tools.javac.parser.Tokens"),
         TYPE("type", "Type", "com.sun.tools.javac.code"),
+        URL("url", "URL", "java.net"),
         SET("set", "Set", "java.util"),
         LIST("list", "List", "java.util"),
         OBJECT("object", "Object", null),
--- a/src/hotspot/cpu/aarch64/gc/g1/g1BarrierSetAssembler_aarch64.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/aarch64/gc/g1/g1BarrierSetAssembler_aarch64.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -29,6 +29,9 @@
 #include "gc/g1/g1CardTable.hpp"
 #include "gc/g1/g1ThreadLocalData.hpp"
 #include "gc/g1/heapRegion.hpp"
+#include "gc/shared/collectedHeap.hpp"
+#include "runtime/sharedRuntime.hpp"
+#include "runtime/thread.hpp"
 #include "interpreter/interp_masm.hpp"
 #include "runtime/sharedRuntime.hpp"
 
--- a/src/hotspot/cpu/aarch64/gc/shared/modRefBarrierSetAssembler_aarch64.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/aarch64/gc/shared/modRefBarrierSetAssembler_aarch64.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -44,12 +44,6 @@
   }
 }
 
-
-void ModRefBarrierSetAssembler::oop_store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
-                                             Address dst, Register val, Register tmp1, Register tmp2) {
-  BarrierSetAssembler::store_at(masm, decorators, type, dst, val, tmp1, tmp2);
-}
-
 void ModRefBarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
                                          Address dst, Register val, Register tmp1, Register tmp2) {
   if (type == T_OBJECT || type == T_ARRAY) {
--- a/src/hotspot/cpu/aarch64/gc/shared/modRefBarrierSetAssembler_aarch64.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/aarch64/gc/shared/modRefBarrierSetAssembler_aarch64.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -40,7 +40,7 @@
                                                 Register start, Register end, Register tmp, RegSet saved_regs) {}
 
   virtual void oop_store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
-                            Address dst, Register val, Register tmp1, Register tmp2);
+                            Address dst, Register val, Register tmp1, Register tmp2) = 0;
 
 public:
   virtual void arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop,
--- a/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -265,22 +265,21 @@
 
 // Load object from cpool->resolved_references(index)
 void InterpreterMacroAssembler::load_resolved_reference_at_index(
-                                           Register result, Register index) {
+                                           Register result, Register index, Register tmp) {
   assert_different_registers(result, index);
   // convert from field index to resolved_references() index and from
   // word index to byte offset. Since this is a java object, it can be compressed
-  Register tmp = index;  // reuse
-  lslw(tmp, tmp, LogBytesPerHeapOop);
+  lslw(index, index, LogBytesPerHeapOop);
 
   get_constant_pool(result);
   // load pointer for resolved_references[] objArray
   ldr(result, Address(result, ConstantPool::cache_offset_in_bytes()));
   ldr(result, Address(result, ConstantPoolCache::resolved_references_offset_in_bytes()));
-  resolve_oop_handle(result);
+  resolve_oop_handle(result, tmp);
   // Add in the index
-  add(result, result, tmp);
+  add(result, result, index);
   BarrierSetAssembler *bs = BarrierSet::barrier_set()->barrier_set_assembler();
-  bs->load_at(this, IN_HEAP, T_OBJECT, result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)), /*tmp1*/ noreg, /*tmp_thread*/ noreg);
+  bs->load_at(this, IN_HEAP, T_OBJECT, result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)), tmp, /*tmp_thread*/ noreg);
 }
 
 void InterpreterMacroAssembler::load_resolved_klass_at_offset(
--- a/src/hotspot/cpu/aarch64/interp_masm_aarch64.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/aarch64/interp_masm_aarch64.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, 2015, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -122,7 +122,7 @@
   void get_method_counters(Register method, Register mcs, Label& skip);
 
   // load cpool->resolved_references(index);
-  void load_resolved_reference_at_index(Register result, Register index);
+  void load_resolved_reference_at_index(Register result, Register index, Register tmp = r5);
 
   // load cpool->resolved_klass_at(index);
   void load_resolved_klass_at_offset(Register cpool, Register index, Register klass, Register temp);
--- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -2108,7 +2108,7 @@
 
   bind(not_weak);
   // Resolve (untagged) jobject.
-  bs->load_at(this, IN_ROOT | ON_STRONG_OOP_REF, T_OBJECT,
+  bs->load_at(this, IN_ROOT | IN_CONCURRENT_ROOT, T_OBJECT,
                     value, Address(value, 0), tmp, thread);
   verify_oop(value);
   bind(done);
@@ -3642,18 +3642,20 @@
 }
 
 // ((OopHandle)result).resolve();
-void MacroAssembler::resolve_oop_handle(Register result) {
+void MacroAssembler::resolve_oop_handle(Register result, Register tmp) {
   // OopHandle::resolve is an indirection.
-  ldr(result, Address(result, 0));
-}
-
-void MacroAssembler::load_mirror(Register dst, Register method) {
+  BarrierSetAssembler *bs = BarrierSet::barrier_set()->barrier_set_assembler();
+  bs->load_at(this, IN_ROOT | IN_CONCURRENT_ROOT, T_OBJECT,
+                    result, Address(result, 0), tmp, rthread);
+}
+
+void MacroAssembler::load_mirror(Register dst, Register method, Register tmp) {
   const int mirror_offset = in_bytes(Klass::java_mirror_offset());
   ldr(dst, Address(rmethod, Method::const_offset()));
   ldr(dst, Address(dst, ConstMethod::constants_offset()));
   ldr(dst, Address(dst, ConstantPool::pool_holder_offset_in_bytes()));
   ldr(dst, Address(dst, mirror_offset));
-  resolve_oop_handle(dst);
+  resolve_oop_handle(dst, tmp);
 }
 
 void MacroAssembler::cmp_klass(Register oop, Register trial_klass, Register tmp) {
--- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -803,8 +803,8 @@
   void store_klass(Register dst, Register src);
   void cmp_klass(Register oop, Register trial_klass, Register tmp);
 
-  void resolve_oop_handle(Register result);
-  void load_mirror(Register dst, Register method);
+  void resolve_oop_handle(Register result, Register tmp = r5);
+  void load_mirror(Register dst, Register method, Register tmp = r5);
 
   void load_heap_oop(Register dst, Address src);
 
--- a/src/hotspot/cpu/ppc/gc/shared/modRefBarrierSetAssembler_ppc.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/ppc/gc/shared/modRefBarrierSetAssembler_ppc.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -56,12 +56,6 @@
   }
 }
 
-void ModRefBarrierSetAssembler::oop_store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
-                                             Register base, RegisterOrConstant ind_or_offs, Register val,
-                                             Register tmp1, Register tmp2, Register tmp3, bool needs_frame) {
-  BarrierSetAssembler::store_at(masm, decorators, type, base, ind_or_offs, val, tmp1, tmp2, tmp3, needs_frame);
-}
-
 void ModRefBarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
                                          Register base, RegisterOrConstant ind_or_offs, Register val,
                                          Register tmp1, Register tmp2, Register tmp3, bool needs_frame) {
--- a/src/hotspot/cpu/ppc/gc/shared/modRefBarrierSetAssembler_ppc.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/ppc/gc/shared/modRefBarrierSetAssembler_ppc.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -41,7 +41,7 @@
 
   virtual void oop_store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
                             Register base, RegisterOrConstant ind_or_offs, Register val,
-                            Register tmp1, Register tmp2, Register tmp3, bool needs_frame);
+                            Register tmp1, Register tmp2, Register tmp3, bool needs_frame) = 0;
 public:
   virtual void arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
                                   Register src, Register dst, Register count, Register preserve1, Register preserve2);
--- a/src/hotspot/cpu/s390/gc/shared/modRefBarrierSetAssembler_s390.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/s390/gc/shared/modRefBarrierSetAssembler_s390.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -50,11 +50,6 @@
   }
 }
 
-void ModRefBarrierSetAssembler::oop_store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
-                                             const Address& dst, Register val, Register tmp1, Register tmp2, Register tmp3) {
-  BarrierSetAssembler::store_at(masm, decorators, type, dst, val, tmp1, tmp2, tmp3);
-}
-
 void ModRefBarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
                                          const Address& dst, Register val, Register tmp1, Register tmp2, Register tmp3) {
   if (type == T_OBJECT || type == T_ARRAY) {
--- a/src/hotspot/cpu/s390/gc/shared/modRefBarrierSetAssembler_s390.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/s390/gc/shared/modRefBarrierSetAssembler_s390.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -39,7 +39,7 @@
   virtual void gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators, Register addr, Register count,
                                                 bool do_return);
   virtual void oop_store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
-                            const Address& dst, Register val, Register tmp1, Register tmp2, Register tmp3);
+                            const Address& dst, Register val, Register tmp1, Register tmp2, Register tmp3) = 0;
 public:
   virtual void arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
                                   Register src, Register dst, Register count);
--- a/src/hotspot/cpu/sparc/interp_masm_sparc.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/sparc/interp_masm_sparc.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -739,20 +739,19 @@
 
 // Load object from cpool->resolved_references(index)
 void InterpreterMacroAssembler::load_resolved_reference_at_index(
-                                           Register result, Register index) {
-  assert_different_registers(result, index);
+                                           Register result, Register index, Register tmp) {
+  assert_different_registers(result, index, tmp);
   assert_not_delayed();
   // convert from field index to resolved_references() index and from
   // word index to byte offset. Since this is a java object, it can be compressed
-  Register tmp = index;  // reuse
-  sll(index, LogBytesPerHeapOop, tmp);
+  sll(index, LogBytesPerHeapOop, index);
   get_constant_pool(result);
   // load pointer for resolved_references[] objArray
   ld_ptr(result, ConstantPool::cache_offset_in_bytes(), result);
   ld_ptr(result, ConstantPoolCache::resolved_references_offset_in_bytes(), result);
-  resolve_oop_handle(result);
+  resolve_oop_handle(result, tmp);
   // Add in the index
-  add(result, tmp, result);
+  add(result, index, result);
   load_heap_oop(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT), result, tmp);
 }
 
--- a/src/hotspot/cpu/sparc/interp_masm_sparc.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/sparc/interp_masm_sparc.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -183,7 +183,7 @@
   void get_cache_index_at_bcp(Register temp, Register index, int bcp_offset, size_t index_size = sizeof(u2));
 
   // load cpool->resolved_references(index);
-  void load_resolved_reference_at_index(Register result, Register index);
+  void load_resolved_reference_at_index(Register result, Register index, Register tmp);
 
   // load cpool->resolved_klass_at(index)
   void load_resolved_klass_at_offset(Register Rcpool, Register Roffset, Register Rklass);
--- a/src/hotspot/cpu/sparc/macroAssembler_sparc.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/sparc/macroAssembler_sparc.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -3392,18 +3392,19 @@
   bind(no_reserved_zone_enabling);
 }
 // ((OopHandle)result).resolve();
-void MacroAssembler::resolve_oop_handle(Register result) {
+void MacroAssembler::resolve_oop_handle(Register result, Register tmp) {
   // OopHandle::resolve is an indirection.
-  ld_ptr(result, 0, result);
+  access_load_at(T_OBJECT, IN_ROOT | IN_CONCURRENT_ROOT,
+                 Address(result, 0), result, tmp);
 }
 
-void MacroAssembler::load_mirror(Register mirror, Register method) {
+void MacroAssembler::load_mirror(Register mirror, Register method, Register tmp) {
   const int mirror_offset = in_bytes(Klass::java_mirror_offset());
   ld_ptr(method, in_bytes(Method::const_offset()), mirror);
   ld_ptr(mirror, in_bytes(ConstMethod::constants_offset()), mirror);
   ld_ptr(mirror, ConstantPool::pool_holder_offset_in_bytes(), mirror);
   ld_ptr(mirror, mirror_offset, mirror);
-  resolve_oop_handle(mirror);
+  resolve_oop_handle(mirror, tmp);
 }
 
 void MacroAssembler::load_klass(Register src_oop, Register klass) {
--- a/src/hotspot/cpu/sparc/macroAssembler_sparc.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/sparc/macroAssembler_sparc.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -968,8 +968,8 @@
   inline void ldbool(const Address& a, Register d);
   inline void movbool( bool boolconst, Register d);
 
-  void resolve_oop_handle(Register result);
-  void load_mirror(Register mirror, Register method);
+  void resolve_oop_handle(Register result, Register tmp);
+  void load_mirror(Register mirror, Register method, Register tmp);
 
   // klass oop manipulations if compressed
   void load_klass(Register src_oop, Register klass);
--- a/src/hotspot/cpu/sparc/templateInterpreterGenerator_sparc.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/sparc/templateInterpreterGenerator_sparc.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -502,7 +502,7 @@
     __ delayed()->ld_ptr(Llocals, Interpreter::local_offset_in_bytes(0), O0); // get receiver for not-static case
 
     // lock the mirror, not the Klass*
-    __ load_mirror(O0, Lmethod);
+    __ load_mirror(O0, Lmethod, Lscratch);
 
 #ifdef ASSERT
     __ tst(O0);
@@ -810,7 +810,7 @@
   __ mov( G5_method, Lmethod);                 // set Lmethod
   // Get mirror and store it in the frame as GC root for this Method*
   Register mirror = LcpoolCache;
-  __ load_mirror(mirror, Lmethod);
+  __ load_mirror(mirror, Lmethod, Lscratch);
   __ st_ptr(mirror, FP, (frame::interpreter_frame_mirror_offset * wordSize) + STACK_BIAS);
   __ get_constant_pool_cache(LcpoolCache);     // set LcpoolCache
   __ sub(FP, rounded_vm_local_words * BytesPerWord, Lmonitors ); // set Lmonitors
@@ -1280,7 +1280,7 @@
     // get native function entry point(O0 is a good temp until the very end)
     __ delayed()->ld_ptr(Lmethod, in_bytes(Method::native_function_offset()), O0);
     // for static methods insert the mirror argument
-    __ load_mirror(O1, Lmethod);
+    __ load_mirror(O1, Lmethod, G3_scratch);
 #ifdef ASSERT
     if (!PrintSignatureHandlers)  // do not dirty the output with this
     { Label L;
--- a/src/hotspot/cpu/sparc/templateTable_sparc.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/sparc/templateTable_sparc.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -326,7 +326,7 @@
   // non-null object (CallSite, etc.)
   assert_different_registers(Otos_i, G3_scratch);
   __ get_cache_index_at_bcp(Otos_i, G3_scratch, 1, index_size);  // load index => G3_scratch
-  __ load_resolved_reference_at_index(Otos_i, G3_scratch);
+  __ load_resolved_reference_at_index(Otos_i, G3_scratch, Lscratch);
   __ tst(Otos_i);
   __ br(Assembler::notEqual, false, Assembler::pt, resolved);
   __ delayed()->set((int)bytecode(), O1);
@@ -2016,7 +2016,7 @@
                                               Register Roffset,
                                               Register Rflags,
                                               bool is_static) {
-  assert_different_registers(Rcache, Rflags, Roffset);
+  assert_different_registers(Rcache, Rflags, Roffset, Lscratch);
 
   ByteSize cp_base_offset = ConstantPoolCache::base_offset();
 
@@ -2026,7 +2026,7 @@
     __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::f1_offset(), Robj);
     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
     __ ld_ptr( Robj, mirror_offset, Robj);
-    __ resolve_oop_handle(Robj);
+    __ resolve_oop_handle(Robj, Lscratch);
   }
 }
 
@@ -2847,7 +2847,7 @@
     // This must be done before we get the receiver,
     // since the parameter_size includes it.
     assert(ConstantPoolCacheEntry::_indy_resolved_references_appendix_offset == 0, "appendix expected at index+0");
-    __ load_resolved_reference_at_index(temp, index);
+    __ load_resolved_reference_at_index(temp, index, /*tmp*/recv);
     __ verify_oop(temp);
     __ push_ptr(temp);  // push appendix (MethodType, CallSite, etc.)
     __ bind(L_no_push);
--- a/src/hotspot/cpu/x86/interp_masm_x86.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/x86/interp_masm_x86.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -502,20 +502,19 @@
 
 // Load object from cpool->resolved_references(index)
 void InterpreterMacroAssembler::load_resolved_reference_at_index(
-                                           Register result, Register index) {
+                                           Register result, Register index, Register tmp) {
   assert_different_registers(result, index);
   // convert from field index to resolved_references() index and from
   // word index to byte offset. Since this is a java object, it can be compressed
-  Register tmp = index;  // reuse
-  shll(tmp, LogBytesPerHeapOop);
+  shll(index, LogBytesPerHeapOop);
 
   get_constant_pool(result);
   // load pointer for resolved_references[] objArray
   movptr(result, Address(result, ConstantPool::cache_offset_in_bytes()));
   movptr(result, Address(result, ConstantPoolCache::resolved_references_offset_in_bytes()));
-  resolve_oop_handle(result);
+  resolve_oop_handle(result, tmp);
   // Add in the index
-  addptr(result, tmp);
+  addptr(result, index);
   load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)), tmp);
 }
 
--- a/src/hotspot/cpu/x86/interp_masm_x86.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/x86/interp_masm_x86.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -122,7 +122,7 @@
                               size_t index_size = sizeof(u2));
 
   // load cpool->resolved_references(index);
-  void load_resolved_reference_at_index(Register result, Register index);
+  void load_resolved_reference_at_index(Register result, Register index, Register tmp = rscratch2);
 
   // load cpool->resolved_klass_at(index)
   void load_resolved_klass_at_index(Register cpool,  // the constant pool (corrupted on return)
--- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -6274,19 +6274,22 @@
 }
 
 // ((OopHandle)result).resolve();
-void MacroAssembler::resolve_oop_handle(Register result) {
-  // OopHandle::resolve is an indirection.
-  movptr(result, Address(result, 0));
-}
-
-void MacroAssembler::load_mirror(Register mirror, Register method) {
+void MacroAssembler::resolve_oop_handle(Register result, Register tmp) {
+  // Only 64 bit platforms support GCs that require a tmp register
+  // Only IN_HEAP loads require a thread_tmp register
+  // OopHandle::resolve is an indirection like jobject.
+  access_load_at(T_OBJECT, IN_ROOT | IN_CONCURRENT_ROOT,
+                 result, Address(result, 0), tmp, /*tmp_thread*/noreg);
+}
+
+void MacroAssembler::load_mirror(Register mirror, Register method, Register tmp) {
   // get mirror
   const int mirror_offset = in_bytes(Klass::java_mirror_offset());
   movptr(mirror, Address(method, Method::const_offset()));
   movptr(mirror, Address(mirror, ConstMethod::constants_offset()));
   movptr(mirror, Address(mirror, ConstantPool::pool_holder_offset_in_bytes()));
   movptr(mirror, Address(mirror, mirror_offset));
-  resolve_oop_handle(mirror);
+  resolve_oop_handle(mirror, tmp);
 }
 
 void MacroAssembler::load_klass(Register dst, Register src) {
--- a/src/hotspot/cpu/x86/macroAssembler_x86.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/cpu/x86/macroAssembler_x86.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -307,8 +307,8 @@
   void movbool(Address dst, Register src);
   void testbool(Register dst);
 
-  void resolve_oop_handle(Register result);
-  void load_mirror(Register mirror, Register method);
+  void resolve_oop_handle(Register result, Register tmp = rscratch2);
+  void load_mirror(Register mirror, Register method, Register tmp = rscratch2);
 
   // oop manipulations
   void load_klass(Register dst, Register src);
--- a/src/hotspot/os_cpu/linux_sparc/os_linux_sparc.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/os_cpu/linux_sparc/os_linux_sparc.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -374,7 +374,7 @@
 }
 
 inline static bool checkPollingPage(address pc, address fault, address* stub) {
-  if (fault == os::get_polling_page()) {
+  if (os::is_poll_address(fault)) {
     *stub = SharedRuntime::get_poll_stub(pc);
     return true;
   }
--- a/src/hotspot/share/classfile/classLoaderData.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/classLoaderData.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -54,6 +54,7 @@
 #include "classfile/metadataOnStackMark.hpp"
 #include "classfile/moduleEntry.hpp"
 #include "classfile/packageEntry.hpp"
+#include "classfile/symbolTable.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "logging/log.hpp"
 #include "logging/logStream.hpp"
@@ -64,6 +65,7 @@
 #include "memory/universe.hpp"
 #include "oops/access.inline.hpp"
 #include "oops/oop.inline.hpp"
+#include "oops/oopHandle.inline.hpp"
 #include "oops/weakHandle.inline.hpp"
 #include "runtime/atomic.hpp"
 #include "runtime/handles.inline.hpp"
@@ -101,8 +103,25 @@
   }
 }
 
+// JFR and logging support so that the name and klass are available after the
+// class_loader oop is no longer alive, during unloading.
+void ClassLoaderData::initialize_name_and_klass(Handle class_loader) {
+  _class_loader_klass = class_loader->klass();
+  oop class_loader_name = java_lang_ClassLoader::name(class_loader());
+  if (class_loader_name != NULL) {
+    Thread* THREAD = Thread::current();
+    ResourceMark rm(THREAD);
+    const char* class_loader_instance_name =
+      java_lang_String::as_utf8_string(class_loader_name);
+
+    if (class_loader_instance_name != NULL && class_loader_instance_name[0] != '\0') {
+      // Can't throw InternalError and SymbolTable doesn't throw OOM anymore.
+      _class_loader_name = SymbolTable::new_symbol(class_loader_instance_name, CATCH);
+    }
+  }
+}
+
 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous) :
-  _class_loader(h_class_loader()),
   _is_anonymous(is_anonymous),
   // An anonymous class loader data doesn't have anything to keep
   // it from being unloaded during parsing of the anonymous class.
@@ -113,9 +132,14 @@
   _claimed(0), _modified_oops(true), _accumulated_modified_oops(false),
   _jmethod_ids(NULL), _handles(), _deallocate_list(NULL),
   _next(NULL),
+  _class_loader_klass(NULL), _class_loader_name(NULL),
   _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true,
                             Monitor::_safepoint_check_never)) {
 
+  if (!h_class_loader.is_null()) {
+    _class_loader = _handles.add(h_class_loader());
+  }
+
   if (!is_anonymous) {
     // The holder is initialized later for anonymous classes, and before calling anything
     // that call class_loader().
@@ -268,7 +292,6 @@
     clear_modified_oops();
   }
 
-  f->do_oop(&_class_loader);
   _handles.oops_do(f);
 }
 
@@ -555,7 +578,7 @@
   if (lt.is_enabled()) {
     ResourceMark rm;
     LogStream ls(lt);
-    ls.print("unload ");
+    ls.print("unload");
     print_value_on(&ls);
     ls.cr();
   }
@@ -630,7 +653,7 @@
 // Unloading support
 bool ClassLoaderData::is_alive() const {
   bool alive = keep_alive()         // null class loader and incomplete anonymous klasses.
-      || (_holder.peek() != NULL);  // not cleaned by weak reference processing
+      || (_holder.peek() != NULL);  // and not cleaned by the GC weak handle processing.
 
   return alive;
 }
@@ -886,13 +909,23 @@
 }
 
 const char* ClassLoaderData::loader_name() const {
-  // Handles null class loader
-  return SystemDictionary::loader_name(class_loader());
+  if (is_unloading()) {
+    if (_class_loader_klass == NULL) {
+      return "<bootloader>";
+    } else if (_class_loader_name != NULL) {
+      return _class_loader_name->as_C_string();
+    } else {
+      return _class_loader_klass->name()->as_C_string();
+    }
+  } else {
+    // Handles null class loader
+    return SystemDictionary::loader_name(class_loader());
+  }
 }
 
 
 void ClassLoaderData::print_value_on(outputStream* out) const {
-  if (class_loader() != NULL) {
+  if (!is_unloading() && class_loader() != NULL) {
     out->print("loader data: " INTPTR_FORMAT " for instance ", p2i(this));
     class_loader()->print_value_on(out);  // includes loader_name() and address of class loader instance
   } else {
@@ -907,7 +940,7 @@
 #ifndef PRODUCT
 void ClassLoaderData::print_on(outputStream* out) const {
   out->print("ClassLoaderData CLD: " PTR_FORMAT ", loader: " PTR_FORMAT ", loader_klass: %s {",
-              p2i(this), p2i((void *)class_loader()), loader_name());
+              p2i(this), p2i(_class_loader.ptr_raw()), loader_name());
   if (is_anonymous()) out->print(" anonymous");
   if (claimed()) out->print(" claimed");
   if (is_unloading()) out->print(" unloading");
@@ -961,10 +994,10 @@
 
 // Add a new class loader data node to the list.  Assign the newly created
 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field
-ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous) {
+ClassLoaderData* ClassLoaderDataGraph::add_to_graph(Handle loader, bool is_anonymous) {
   NoSafepointVerifier no_safepoints; // we mustn't GC until we've installed the
                                      // ClassLoaderData in the graph since the CLD
-                                     // contains unhandled oops
+                                     // contains oops in _handles that must be walked.
 
   ClassLoaderData* cld = new ClassLoaderData(loader, is_anonymous);
 
@@ -1001,6 +1034,16 @@
   } while (true);
 }
 
+ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous) {
+  ClassLoaderData* loader_data = add_to_graph(loader, is_anonymous);
+  // Initialize name and class after the loader data is added to the CLDG
+  // because adding the Symbol for the name might safepoint.
+  if (loader.not_null()) {
+    loader_data->initialize_name_and_klass(loader);
+  }
+  return loader_data;
+}
+
 void ClassLoaderDataGraph::oops_do(OopClosure* f, bool must_claim) {
   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
     cld->oops_do(f, must_claim);
@@ -1236,8 +1279,7 @@
 
 // Move class loader data from main list to the unloaded list for unloading
 // and deallocation later.
-bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive_closure,
-                                        bool clean_previous_versions) {
+bool ClassLoaderDataGraph::do_unloading(bool clean_previous_versions) {
 
   ClassLoaderData* data = _head;
   ClassLoaderData* prev = NULL;
@@ -1295,7 +1337,7 @@
       // Remove entries in the dictionary of live class loader that have
       // initiated loading classes in a dead class loader.
       if (data->dictionary() != NULL) {
-        data->dictionary()->do_unloading(is_alive_closure);
+        data->dictionary()->do_unloading();
       }
       // Walk a ModuleEntry's reads, and a PackageEntry's exports
       // lists to determine if there are modules on those lists that are now
--- a/src/hotspot/share/classfile/classLoaderData.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/classLoaderData.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -28,7 +28,6 @@
 #include "memory/allocation.hpp"
 #include "memory/memRegion.hpp"
 #include "memory/metaspace.hpp"
-#include "memory/metaspaceCounters.hpp"
 #include "oops/oopHandle.hpp"
 #include "oops/weakHandle.hpp"
 #include "runtime/mutex.hpp"
@@ -84,6 +83,7 @@
   static volatile size_t  _num_instance_classes;
   static volatile size_t  _num_array_classes;
 
+  static ClassLoaderData* add_to_graph(Handle class_loader, bool anonymous);
   static ClassLoaderData* add(Handle class_loader, bool anonymous);
   static void post_class_unload_events();
  public:
@@ -114,7 +114,7 @@
   static void packages_unloading_do(void f(PackageEntry*));
   static void loaded_classes_do(KlassClosure* klass_closure);
   static void classes_unloading_do(void f(Klass* const));
-  static bool do_unloading(BoolObjectClosure* is_alive_closure, bool clean_previous_versions);
+  static bool do_unloading(bool clean_previous_versions);
 
   // dictionary do
   // Iterate over all klasses in dictionary, but
@@ -221,7 +221,7 @@
   static ClassLoaderData * _the_null_class_loader_data;
 
   WeakHandle<vm_class_loader_data> _holder; // The oop that determines lifetime of this class loader
-  oop _class_loader;          // The instance of java/lang/ClassLoader associated with
+  OopHandle _class_loader;    // The instance of java/lang/ClassLoader associated with
                               // this ClassLoaderData
 
   ClassLoaderMetaspace * volatile _metaspace;  // Meta-space where meta-data defined by the
@@ -234,7 +234,7 @@
   bool _modified_oops;             // Card Table Equivalent (YC/CMS support)
   bool _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
 
-  s2 _keep_alive;          // if this CLD is kept alive without a keep_alive_object().
+  s2 _keep_alive;          // if this CLD is kept alive.
                            // Used for anonymous classes and the boot class
                            // loader. _keep_alive does not need to be volatile or
                            // atomic since there is one unique CLD per anonymous class.
@@ -265,6 +265,9 @@
   // Support for walking class loader data objects
   ClassLoaderData* _next; /// Next loader_datas created
 
+  // JFR support
+  Klass*  _class_loader_klass;
+  Symbol* _class_loader_name;
   TRACE_DEFINE_TRACE_ID_FIELD;
 
   void set_next(ClassLoaderData* next) { _next = next; }
@@ -305,6 +308,8 @@
   MetaWord* allocate(size_t size);
 
   Dictionary* create_dictionary();
+
+  void initialize_name_and_klass(Handle class_loader);
  public:
   // GC interface.
   void clear_claimed() { _claimed = 0; }
@@ -340,9 +345,7 @@
 
   // Returns true if this class loader data is for the boot class loader.
   // (Note that the class loader data may be anonymous.)
-  bool is_boot_class_loader_data() const {
-    return class_loader() == NULL;
-  }
+  inline bool is_boot_class_loader_data() const;
 
   bool is_builtin_class_loader_data() const;
   bool is_permanent_class_loader_data() const;
@@ -351,10 +354,7 @@
   // method will allocate a Metaspace if needed.
   ClassLoaderMetaspace* metaspace_non_null();
 
-  oop class_loader() const { return _class_loader; }
-
-  // The object the GC is using to keep this ClassLoaderData alive.
-  oop keep_alive_object() const;
+  inline oop class_loader() const;
 
   // Returns true if this class loader data is for a loader going away.
   bool is_unloading() const     {
@@ -363,7 +363,7 @@
   }
 
   // Used to refcount an anonymous class's CLD in order to
-  // indicate their aliveness without a keep_alive_object().
+  // indicate their aliveness.
   void inc_keep_alive();
   void dec_keep_alive();
 
@@ -407,6 +407,9 @@
   static ClassLoaderData* class_loader_data_or_null(oop loader);
   static ClassLoaderData* anonymous_class_loader_data(Handle loader);
 
+
+  Klass* class_loader_klass() const { return _class_loader_klass; }
+  Symbol* class_loader_name() const { return _class_loader_name; }
   TRACE_DEFINE_TRACE_ID_METHODS;
 };
 
--- a/src/hotspot/share/classfile/classLoaderData.inline.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/classLoaderData.inline.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -28,6 +28,18 @@
 #include "classfile/classLoaderData.hpp"
 #include "classfile/javaClasses.hpp"
 #include "oops/oop.inline.hpp"
+#include "oops/oopHandle.inline.hpp"
+#include "oops/weakHandle.inline.hpp"
+
+inline oop ClassLoaderData::class_loader() const {
+  assert(!_unloading, "This oop is not available to unloading class loader data");
+  assert(_holder.is_null() || _holder.peek() != NULL , "This class loader data holder must be alive");
+  return _class_loader.resolve();
+}
+
+inline bool ClassLoaderData::is_boot_class_loader_data() const {
+    return class_loader() == NULL;
+  }
 
 inline ClassLoaderData* ClassLoaderData::class_loader_data_or_null(oop loader) {
   if (loader == NULL) {
--- a/src/hotspot/share/classfile/classLoaderStats.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/classLoaderStats.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * 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,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "classfile/classLoaderData.inline.hpp"
 #include "classfile/classLoaderStats.hpp"
 #include "oops/oop.inline.hpp"
 #include "utilities/globalDefinitions.hpp"
--- a/src/hotspot/share/classfile/dictionary.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/dictionary.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -214,13 +214,13 @@
 
 // During class loading we may have cached a protection domain that has
 // since been unreferenced, so this entry should be cleared.
-void Dictionary::clean_cached_protection_domains(BoolObjectClosure* is_alive, DictionaryEntry* probe) {
+void Dictionary::clean_cached_protection_domains(DictionaryEntry* probe) {
   assert_locked_or_safepoint(SystemDictionary_lock);
 
   ProtectionDomainEntry* current = probe->pd_set();
   ProtectionDomainEntry* prev = NULL;
   while (current != NULL) {
-    if (!is_alive->do_object_b(current->object_no_keepalive())) {
+    if (current->object_no_keepalive() == NULL) {
       LogTarget(Debug, protectiondomain) lt;
       if (lt.is_enabled()) {
         ResourceMark rm;
@@ -228,7 +228,6 @@
         LogStream ls(lt);
         ls.print_cr("PD in set is not alive:");
         ls.print("class loader: "); loader_data()->class_loader()->print_value_on(&ls);
-        ls.print(" protection domain: "); current->object_no_keepalive()->print_value_on(&ls);
         ls.print(" loading: "); probe->instance_klass()->print_value_on(&ls);
         ls.cr();
       }
@@ -249,7 +248,7 @@
 }
 
 
-void Dictionary::do_unloading(BoolObjectClosure* is_alive) {
+void Dictionary::do_unloading() {
   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 
   // The NULL class loader doesn't initiate loading classes from other class loaders
@@ -276,7 +275,7 @@
         continue;
       }
       // Clean pd_set
-      clean_cached_protection_domains(is_alive, probe);
+      clean_cached_protection_domains(probe);
       p = probe->next_addr();
     }
   }
--- a/src/hotspot/share/classfile/dictionary.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/dictionary.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -52,7 +52,7 @@
 
   DictionaryEntry* get_entry(int index, unsigned int hash, Symbol* name);
 
-  void clean_cached_protection_domains(BoolObjectClosure* is_alive, DictionaryEntry* probe);
+  void clean_cached_protection_domains(DictionaryEntry* probe);
 
 protected:
   static size_t entry_size();
@@ -72,20 +72,16 @@
 
   InstanceKlass* find_shared_class(int index, unsigned int hash, Symbol* name);
 
-  // GC support
-  void oops_do(OopClosure* f);
-  void roots_oops_do(OopClosure* strong, OopClosure* weak);
-
   void classes_do(void f(InstanceKlass*));
   void classes_do(void f(InstanceKlass*, TRAPS), TRAPS);
   void all_entries_do(void f(InstanceKlass*, ClassLoaderData*));
   void classes_do(MetaspaceClosure* it);
 
-  void unlink(BoolObjectClosure* is_alive);
+  void unlink();
   void remove_classes_in_error_state();
 
   // Unload classes whose defining loaders are unloaded
-  void do_unloading(BoolObjectClosure* is_alive);
+  void do_unloading();
 
   // Protection domains
   InstanceKlass* find(unsigned int hash, Symbol* name, Handle protection_domain);
--- a/src/hotspot/share/classfile/loaderConstraints.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/loaderConstraints.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -99,7 +99,7 @@
       InstanceKlass* klass = probe->klass();
       // Remove klass that is no longer alive
       if (klass != NULL &&
-          klass->class_loader_data()->is_unloading()) {
+          !klass->is_loader_alive()) {
         probe->set_klass(NULL);
         if (lt.is_enabled()) {
           ResourceMark rm;
@@ -116,31 +116,31 @@
       int n = 0;
       while (n < probe->num_loaders()) {
         if (probe->loader_data(n)->is_unloading()) {
-            if (lt.is_enabled()) {
-              ResourceMark rm;
-              lt.print("purging loader %s from constraint for name %s",
-                            probe->loader_data(n)->loader_name(),
-                            probe->name()->as_C_string()
-                            );
-            }
+          if (lt.is_enabled()) {
+            ResourceMark rm;
+            lt.print("purging loader %s from constraint for name %s",
+                     probe->loader_data(n)->loader_name(),
+                     probe->name()->as_C_string()
+                     );
+          }
 
-            // Compact array
-            int num = probe->num_loaders() - 1;
-            probe->set_num_loaders(num);
+          // Compact array
+          int num = probe->num_loaders() - 1;
+          probe->set_num_loaders(num);
           probe->set_loader_data(n, probe->loader_data(num));
           probe->set_loader_data(num, NULL);
 
-            if (lt.is_enabled()) {
-              ResourceMark rm;
-              lt.print("new loader list:");
-              for (int i = 0; i < probe->num_loaders(); i++) {
-                lt.print("    [%d]: %s", i,
-                              probe->loader_data(i)->loader_name());
-              }
+          if (lt.is_enabled()) {
+            ResourceMark rm;
+            lt.print("new loader list:");
+            for (int i = 0; i < probe->num_loaders(); i++) {
+              lt.print("    [%d]: %s", i,
+                            probe->loader_data(i)->loader_name());
             }
+          }
 
-            continue;  // current element replaced, so restart without
-                       // incrementing n
+          continue;  // current element replaced, so restart without
+                     // incrementing n
           }
         n++;
       }
@@ -159,9 +159,7 @@
       } else {
 #ifdef ASSERT
         if (probe->klass() != NULL) {
-          ClassLoaderData* loader_data =
-            probe->klass()->class_loader_data();
-          assert(!loader_data->is_unloading(), "klass should be live");
+          assert(probe->klass()->is_loader_alive(), "klass should be live");
         }
 #endif
         // Go to next entry
--- a/src/hotspot/share/classfile/moduleEntry.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/moduleEntry.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
  * 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,11 +24,12 @@
 
 #include "precompiled.hpp"
 #include "jni.h"
-#include "classfile/classLoaderData.hpp"
+#include "classfile/classLoaderData.inline.hpp"
 #include "classfile/javaClasses.hpp"
 #include "classfile/moduleEntry.hpp"
 #include "logging/log.hpp"
 #include "memory/resourceArea.hpp"
+#include "oops/oopHandle.inline.hpp"
 #include "oops/symbol.hpp"
 #include "runtime/handles.inline.hpp"
 #include "runtime/safepoint.hpp"
@@ -40,6 +41,8 @@
 
 ModuleEntry* ModuleEntryTable::_javabase_module = NULL;
 
+oop ModuleEntry::module() const { return _module.resolve(); }
+
 void ModuleEntry::set_location(Symbol* location) {
   if (_location != NULL) {
     // _location symbol's refcounts are managed by ModuleEntry,
--- a/src/hotspot/share/classfile/moduleEntry.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/moduleEntry.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -90,7 +90,7 @@
   Symbol*          name() const                        { return literal(); }
   void             set_name(Symbol* n)                 { set_literal(n); }
 
-  oop              module() const                      { return _module.resolve(); }
+  oop              module() const;
   OopHandle        module_handle() const               { return _module; }
   void             set_module(OopHandle j)             { _module = j; }
 
--- a/src/hotspot/share/classfile/placeholders.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/placeholders.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * 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,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "classfile/classLoaderData.inline.hpp"
 #include "classfile/placeholders.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "oops/oop.inline.hpp"
--- a/src/hotspot/share/classfile/protectionDomainCache.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/protectionDomainCache.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -30,6 +30,7 @@
 #include "memory/iterator.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/oop.inline.hpp"
+#include "oops/weakHandle.inline.hpp"
 #include "utilities/hashtable.inline.hpp"
 
 unsigned int ProtectionDomainCacheTable::compute_hash(Handle protection_domain) {
@@ -42,26 +43,26 @@
 }
 
 ProtectionDomainCacheTable::ProtectionDomainCacheTable(int table_size)
-  : Hashtable<oop, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry))
+  : Hashtable<ClassLoaderWeakHandle, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry))
 {
 }
 
-void ProtectionDomainCacheTable::unlink(BoolObjectClosure* is_alive) {
+void ProtectionDomainCacheTable::unlink() {
   assert(SafepointSynchronize::is_at_safepoint(), "must be");
   for (int i = 0; i < table_size(); ++i) {
     ProtectionDomainCacheEntry** p = bucket_addr(i);
     ProtectionDomainCacheEntry* entry = bucket(i);
     while (entry != NULL) {
-      if (is_alive->do_object_b(entry->object_no_keepalive())) {
+      oop pd = entry->object_no_keepalive();
+      if (pd != NULL) {
         p = entry->next_addr();
       } else {
         LogTarget(Debug, protectiondomain) lt;
         if (lt.is_enabled()) {
           LogStream ls(lt);
-          ls.print("protection domain unlinked: ");
-          entry->object_no_keepalive()->print_value_on(&ls);
-          ls.cr();
+          ls.print_cr("protection domain unlinked at %d", i);
         }
+        entry->literal().release();
         *p = entry->next();
         free_entry(entry);
       }
@@ -70,16 +71,6 @@
   }
 }
 
-void ProtectionDomainCacheTable::oops_do(OopClosure* f) {
-  for (int index = 0; index < table_size(); index++) {
-    for (ProtectionDomainCacheEntry* probe = bucket(index);
-                                     probe != NULL;
-                                     probe = probe->next()) {
-      probe->oops_do(f);
-    }
-  }
-}
-
 void ProtectionDomainCacheTable::print_on(outputStream* st) const {
   st->print_cr("Protection domain cache table (table_size=%d, classes=%d)",
                table_size(), number_of_entries());
@@ -97,7 +88,7 @@
 }
 
 oop ProtectionDomainCacheEntry::object() {
-  return RootAccess<ON_PHANTOM_OOP_REF>::oop_load(literal_addr());
+  return literal().resolve();
 }
 
 oop ProtectionDomainEntry::object() {
@@ -108,7 +99,7 @@
 // keeping it alive. This is okay to do in the VM thread state if it is not
 // leaked out to become strongly reachable.
 oop ProtectionDomainCacheEntry::object_no_keepalive() {
-  return RootAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(literal_addr());
+  return literal().peek();
 }
 
 oop ProtectionDomainEntry::object_no_keepalive() {
@@ -116,7 +107,7 @@
 }
 
 void ProtectionDomainCacheEntry::verify() {
-  guarantee(oopDesc::is_oop(object_no_keepalive()), "must be an oop");
+  guarantee(object_no_keepalive() == NULL || oopDesc::is_oop(object_no_keepalive()), "must be an oop");
 }
 
 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(Handle protection_domain) {
@@ -127,6 +118,8 @@
   if (entry == NULL) {
     entry = add_entry(index, hash, protection_domain);
   }
+  // keep entry alive
+  (void)entry->object();
   return entry;
 }
 
@@ -145,7 +138,8 @@
   assert(index == index_for(protection_domain), "incorrect index?");
   assert(find_entry(index, protection_domain) == NULL, "no double entry");
 
-  ProtectionDomainCacheEntry* p = new_entry(hash, protection_domain);
-  Hashtable<oop, mtClass>::add_entry(index, p);
+  ClassLoaderWeakHandle w = ClassLoaderWeakHandle::create(protection_domain);
+  ProtectionDomainCacheEntry* p = new_entry(hash, w);
+  Hashtable<ClassLoaderWeakHandle, mtClass>::add_entry(index, p);
   return p;
 }
--- a/src/hotspot/share/classfile/protectionDomainCache.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/protectionDomainCache.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -26,6 +26,7 @@
 #define SHARE_VM_CLASSFILE_PROTECTIONDOMAINCACHE_HPP
 
 #include "oops/oop.hpp"
+#include "oops/weakHandle.hpp"
 #include "memory/iterator.hpp"
 #include "utilities/hashtable.hpp"
 
@@ -34,22 +35,18 @@
 // to dictionary.hpp pd_set for more information about how protection domain entries
 // are used.
 // This table is walked during GC, rather than the class loader data graph dictionaries.
-class ProtectionDomainCacheEntry : public HashtableEntry<oop, mtClass> {
+class ProtectionDomainCacheEntry : public HashtableEntry<ClassLoaderWeakHandle, mtClass> {
   friend class VMStructs;
  public:
   oop object();
   oop object_no_keepalive();
 
   ProtectionDomainCacheEntry* next() {
-    return (ProtectionDomainCacheEntry*)HashtableEntry<oop, mtClass>::next();
+    return (ProtectionDomainCacheEntry*)HashtableEntry<ClassLoaderWeakHandle, mtClass>::next();
   }
 
   ProtectionDomainCacheEntry** next_addr() {
-    return (ProtectionDomainCacheEntry**)HashtableEntry<oop, mtClass>::next_addr();
-  }
-
-  void oops_do(OopClosure* f) {
-    f->do_oop(literal_addr());
+    return (ProtectionDomainCacheEntry**)HashtableEntry<ClassLoaderWeakHandle, mtClass>::next_addr();
   }
 
   void verify();
@@ -64,20 +61,21 @@
 // we only need to iterate over this set.
 // The amount of different protection domains used is typically magnitudes smaller
 // than the number of system dictionary entries (loaded classes).
-class ProtectionDomainCacheTable : public Hashtable<oop, mtClass> {
+class ProtectionDomainCacheTable : public Hashtable<ClassLoaderWeakHandle, mtClass> {
   friend class VMStructs;
 private:
   ProtectionDomainCacheEntry* bucket(int i) const {
-    return (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::bucket(i);
+    return (ProtectionDomainCacheEntry*) Hashtable<ClassLoaderWeakHandle, mtClass>::bucket(i);
   }
 
   // The following method is not MT-safe and must be done under lock.
   ProtectionDomainCacheEntry** bucket_addr(int i) {
-    return (ProtectionDomainCacheEntry**) Hashtable<oop, mtClass>::bucket_addr(i);
+    return (ProtectionDomainCacheEntry**) Hashtable<ClassLoaderWeakHandle, mtClass>::bucket_addr(i);
   }
 
-  ProtectionDomainCacheEntry* new_entry(unsigned int hash, Handle protection_domain) {
-    ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain());
+  ProtectionDomainCacheEntry* new_entry(unsigned int hash, ClassLoaderWeakHandle protection_domain) {
+    ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*)
+      Hashtable<ClassLoaderWeakHandle, mtClass>::new_entry(hash, protection_domain);
     return entry;
   }
 
@@ -91,10 +89,7 @@
   ProtectionDomainCacheTable(int table_size);
   ProtectionDomainCacheEntry* get(Handle protection_domain);
 
-  void unlink(BoolObjectClosure* cl);
-
-  // GC support
-  void oops_do(OopClosure* f);
+  void unlink();
 
   void print_on(outputStream* st) const;
   void verify();
--- a/src/hotspot/share/classfile/resolutionErrors.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/resolutionErrors.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -125,9 +125,8 @@
       assert(entry->pool() != (ConstantPool*)NULL, "resolution error table is corrupt");
       ConstantPool* pool = entry->pool();
       assert(pool->pool_holder() != NULL, "Constant pool without a class?");
-      ClassLoaderData* loader_data =
-              pool->pool_holder()->class_loader_data();
-      if (!loader_data->is_unloading()) {
+
+      if (pool->pool_holder()->is_loader_alive()) {
         p = entry->next_addr();
       } else {
         *p = entry->next();
--- a/src/hotspot/share/classfile/systemDictionary.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/systemDictionary.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1831,24 +1831,6 @@
 }
 
 
-#ifdef ASSERT
-class VerifySDReachableAndLiveClosure : public OopClosure {
-private:
-  BoolObjectClosure* _is_alive;
-
-  template <class T> void do_oop_work(T* p) {
-    oop obj = RawAccess<>::oop_load(p);
-    guarantee(_is_alive->do_object_b(obj), "Oop in protection domain cache table must be live");
-  }
-
-public:
-  VerifySDReachableAndLiveClosure(BoolObjectClosure* is_alive) : OopClosure(), _is_alive(is_alive) { }
-
-  virtual void do_oop(oop* p)       { do_oop_work(p); }
-  virtual void do_oop(narrowOop* p) { do_oop_work(p); }
-};
-#endif
-
 // Assumes classes in the SystemDictionary are only unloaded at a safepoint
 // Note: anonymous classes are not in the SD.
 bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive,
@@ -1865,8 +1847,7 @@
     GCTraceTime(Debug, gc, phases) t("ClassLoaderData", gc_timer);
 
     // First, mark for unload all ClassLoaderData referencing a dead class loader.
-    unloading_occurred = ClassLoaderDataGraph::do_unloading(is_alive,
-                                                            do_cleaning);
+    unloading_occurred = ClassLoaderDataGraph::do_unloading(do_cleaning);
   }
 
   if (unloading_occurred) {
@@ -1880,17 +1861,12 @@
     // Oops referenced by the protection domain cache table may get unreachable independently
     // of the class loader (eg. cached protection domain oops). So we need to
     // explicitly unlink them here.
-    _pd_cache_table->unlink(is_alive);
-
-#ifdef ASSERT
-    VerifySDReachableAndLiveClosure cl(is_alive);
-    _pd_cache_table->oops_do(&cl);
-#endif
+    _pd_cache_table->unlink();
   }
 
   if (do_cleaning) {
     GCTraceTime(Debug, gc, phases) t("ResolvedMethodTable", gc_timer);
-    ResolvedMethodTable::unlink(is_alive);
+    ResolvedMethodTable::unlink();
   }
 
   return unloading_occurred;
@@ -1906,21 +1882,15 @@
   if (strong == weak || !ClassUnloading) {
     // Only the protection domain oops contain references into the heap. Iterate
     // over all of them.
-    _pd_cache_table->oops_do(strong);
     vm_weak_oop_storage()->oops_do(strong);
   } else {
    if (weak != NULL) {
-     _pd_cache_table->oops_do(weak);
      vm_weak_oop_storage()->oops_do(weak);
    }
   }
 
   // Visit extra methods
   invoke_method_table()->oops_do(strong);
-
-  if (weak != NULL) {
-    ResolvedMethodTable::oops_do(weak);
-  }
 }
 
 void SystemDictionary::oops_do(OopClosure* f) {
@@ -1929,15 +1899,9 @@
   f->do_oop(&_system_loader_lock_obj);
   CDS_ONLY(SystemDictionaryShared::oops_do(f);)
 
-  // Only the protection domain oops contain references into the heap. Iterate
-  // over all of them.
-  _pd_cache_table->oops_do(f);
-
   // Visit extra methods
   invoke_method_table()->oops_do(f);
 
-  ResolvedMethodTable::oops_do(f);
-
   vm_weak_oop_storage()->oops_do(f);
 }
 
--- a/src/hotspot/share/classfile/systemDictionaryShared.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/systemDictionaryShared.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -357,6 +357,14 @@
   return pd;
 }
 
+bool SystemDictionaryShared::is_sharing_possible(ClassLoaderData* loader_data) {
+  oop class_loader = loader_data->class_loader();
+  return (class_loader == NULL ||
+          (UseAppCDS && (SystemDictionary::is_system_class_loader(class_loader) ||
+                         SystemDictionary::is_platform_class_loader(class_loader)))
+          );
+}
+
 // Currently AppCDS only archives classes from the run-time image, the
 // -Xbootclasspath/a path, the class path, and the module path.
 //
--- a/src/hotspot/share/classfile/systemDictionaryShared.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/classfile/systemDictionaryShared.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -300,13 +300,7 @@
   }
 
   // Check if sharing is supported for the class loader.
-  static bool is_sharing_possible(ClassLoaderData* loader_data) {
-    oop class_loader = loader_data->class_loader();
-    return (class_loader == NULL ||
-            (UseAppCDS && (SystemDictionary::is_system_class_loader(class_loader) ||
-                           SystemDictionary::is_platform_class_loader(class_loader)))
-            );
-  }
+  static bool is_sharing_possible(ClassLoaderData* loader_data);
   static bool is_shared_class_visible_for_classloader(InstanceKlass* ik,
                                                       Handle class_loader,
                                                       const char* pkg_string,
--- a/src/hotspot/share/code/codeHeapState.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/code/codeHeapState.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -613,16 +613,22 @@
       //---<  some sanity checks  >---
       // Do not assert here, just check, print error message and return.
       // This is a diagnostic function. It is not supposed to tear down the VM.
-      if ((char*)h <  low_bound ) {
+      if ((char*)h <  low_bound) {
         insane = true; ast->print_cr("Sanity check: HeapBlock @%p below low bound (%p)", (char*)h, low_bound);
       }
-      if (ix_end   >= granules  ) {
+      if ((char*)h >  (low_bound + res_size)) {
+        insane = true; ast->print_cr("Sanity check: HeapBlock @%p outside reserved range (%p)", (char*)h, low_bound + res_size);
+      }
+      if ((char*)h >  (low_bound + size)) {
+        insane = true; ast->print_cr("Sanity check: HeapBlock @%p outside used range (%p)", (char*)h, low_bound + size);
+      }
+      if (ix_end   >= granules) {
         insane = true; ast->print_cr("Sanity check: end index (%d) out of bounds (" SIZE_FORMAT ")", ix_end, granules);
       }
       if (size     != heap->capacity()) {
         insane = true; ast->print_cr("Sanity check: code heap capacity has changed (" SIZE_FORMAT "K to " SIZE_FORMAT "K)", size/(size_t)K, heap->capacity()/(size_t)K);
       }
-      if (ix_beg   >  ix_end    ) {
+      if (ix_beg   >  ix_end) {
         insane = true; ast->print_cr("Sanity check: end index (%d) lower than begin index (%d)", ix_end, ix_beg);
       }
       if (insane) {
@@ -988,6 +994,11 @@
       ast->print_cr("  deadSpace      = " SIZE_FORMAT_W(8) "k, nBlocks_dead     = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", deadSpace/(size_t)K,     nBlocks_dead,     (100.0*deadSpace)/size,     (100.0*deadSpace)/res_size);
       ast->print_cr("  stubSpace      = " SIZE_FORMAT_W(8) "k, nBlocks_stub     = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", stubSpace/(size_t)K,     nBlocks_stub,     (100.0*stubSpace)/size,     (100.0*stubSpace)/res_size);
       ast->print_cr("ZombieBlocks     = %8d. These are HeapBlocks which could not be identified as CodeBlobs.", nBlocks_zomb);
+      ast->cr();
+      ast->print_cr("Segment start          = " INTPTR_FORMAT ", used space      = " SIZE_FORMAT_W(8)"k", p2i(low_bound), size/K);
+      ast->print_cr("Segment end (used)     = " INTPTR_FORMAT ", remaining space = " SIZE_FORMAT_W(8)"k", p2i(low_bound) + size, (res_size - size)/K);
+      ast->print_cr("Segment end (reserved) = " INTPTR_FORMAT ", reserved space  = " SIZE_FORMAT_W(8)"k", p2i(low_bound) + res_size, res_size/K);
+      ast->cr();
       ast->print_cr("latest allocated compilation id = %d", latest_compilation_id);
       ast->print_cr("highest observed compilation id = %d", highest_compilation_id);
       ast->print_cr("Building TopSizeList iterations = %ld", total_iterations);
@@ -1218,14 +1229,14 @@
           blob_name = this_blob->name();
           nm        = this_blob->as_nmethod_or_null();
           //---<  blob address  >---
-          ast->print("%p", this_blob);
+          ast->print(INTPTR_FORMAT, p2i(this_blob));
           ast->fill_to(19);
           //---<  blob offset from CodeHeap begin  >---
           ast->print("(+" PTR32_FORMAT ")", (unsigned int)((char*)this_blob-low_bound));
           ast->fill_to(33);
         } else {
           //---<  block address  >---
-          ast->print("%p", TopSizeArray[i].start);
+          ast->print(INTPTR_FORMAT, p2i(TopSizeArray[i].start));
           ast->fill_to(19);
           //---<  block offset from CodeHeap begin  >---
           ast->print("(+" PTR32_FORMAT ")", (unsigned int)((char*)TopSizeArray[i].start-low_bound));
@@ -1404,7 +1415,7 @@
 
     unsigned int ix = 0;
     for (ix = 0; ix < alloc_freeBlocks-1; ix++) {
-      ast->print("%p: Len[%4d] = " HEX32_FORMAT ",", FreeArray[ix].start, ix, FreeArray[ix].len);
+      ast->print(INTPTR_FORMAT ": Len[%4d] = " HEX32_FORMAT ",", p2i(FreeArray[ix].start), ix, FreeArray[ix].len);
       ast->fill_to(38);
       ast->print("Gap[%4d..%4d]: " HEX32_FORMAT " bytes,", ix, ix+1, FreeArray[ix].gap);
       ast->fill_to(71);
@@ -1414,7 +1425,7 @@
       }
       STRINGSTREAM_FLUSH_LOCKED("\n")
     }
-    ast->print_cr("%p: Len[%4d] = " HEX32_FORMAT, FreeArray[ix].start, ix, FreeArray[ix].len);
+    ast->print_cr(INTPTR_FORMAT ": Len[%4d] = " HEX32_FORMAT, p2i(FreeArray[ix].start), ix, FreeArray[ix].len);
     STRINGSTREAM_FLUSH_LOCKED("\n\n")
   }
 
@@ -2039,10 +2050,16 @@
 }
 
 
+#define JDK8200450_REMEDY
+#define JDK8200450_TRACE
 void CodeHeapState::print_names(outputStream* out, CodeHeap* heap) {
   if (!initialization_complete) {
     return;
   }
+#ifdef JDK8200450_TRACE
+  out->print_cr("print_names() entered for heap @ " INTPTR_FORMAT, p2i(heap));
+  out->flush();
+#endif
 
   const char* heapName   = get_heapName(heap);
   get_HeapStatGlobals(out, heapName);
@@ -2057,7 +2074,7 @@
   CodeBlob*    last_blob          = NULL;
   bool         name_in_addr_range = true;
 
-  //---<  print at least 128K per block  >---
+  //---<  print at least 128K per block (i.e. between headers)  >---
   if (granules_per_line*granule_size < 128*K) {
     granules_per_line = (unsigned int)((128*K)/granule_size);
   }
@@ -2067,7 +2084,7 @@
                 "  Due to the living nature of the code heap and because the CodeCache_lock\n"
                 "  is not continuously held, the displayed name might be wrong or no name\n"
                 "  might be found at all. The likelihood for that to happen increases\n"
-                "  over time passed between analysis and print step.\n");
+                "  over time passed between aggregtion and print steps.\n");
   STRINGSTREAM_FLUSH_LOCKED("")
 
   for (unsigned int ix = 0; ix < alloc_granules; ix++) {
@@ -2078,23 +2095,69 @@
       }
       name_in_addr_range = false;
 
+      size_t end_ix = (ix+granules_per_line <= alloc_granules) ? ix+granules_per_line : alloc_granules;
       ast->cr();
       ast->print_cr("--------------------------------------------------------------------");
-      ast->print_cr("Address range [%p,%p), " SIZE_FORMAT "k", low_bound+ix*granule_size, low_bound+(ix+granules_per_line)*granule_size, granules_per_line*granule_size/(size_t)K);
+      ast->print_cr("Address range [" INTPTR_FORMAT "," INTPTR_FORMAT "), " SIZE_FORMAT "k", p2i(low_bound+ix*granule_size), p2i(low_bound + end_ix*granule_size), (end_ix - ix)*granule_size/(size_t)K);
       ast->print_cr("--------------------------------------------------------------------");
       STRINGSTREAM_FLUSH_LOCKED("")
     }
     // Only check granule if it contains at least one blob.
     unsigned int nBlobs  = StatArray[ix].t1_count   + StatArray[ix].t2_count + StatArray[ix].tx_count +
                            StatArray[ix].stub_count + StatArray[ix].dead_count;
-    if (nBlobs > 0 ) {
+#ifdef JDK8200450_REMEDY
+    if (nBlobs > 0 )
+#endif
+    {
     for (unsigned int is = 0; is < granule_size; is+=(unsigned int)seg_size) {
       // heap->find_start() is safe. Only working with _segmap. Returns NULL or void*. Returned CodeBlob may be uninitialized.
       CodeBlob* this_blob = (CodeBlob *)(heap->find_start(low_bound+ix*granule_size+is));
-      bool blob_initialized = (this_blob != NULL) &&
-                              ((char*)this_blob + this_blob->header_size() == (char*)(this_blob->relocation_begin())) &&
-                              ((char*)this_blob + CodeBlob::align_code_offset(this_blob->header_size() + this_blob->relocation_size()) == (char*)(this_blob->content_begin()));
+#ifndef JDK8200450_REMEDY
+      bool blob_initialized = (this_blob != NULL)
+#else
+#ifndef JDK8200450_TRACE
+      bool blob_initialized = (this_blob != NULL) && (this_blob->header_size() >= 0) && (this_blob->relocation_size() >= 0) &&
+                              ((address)this_blob + this_blob->header_size() == (address)(this_blob->relocation_begin())) &&
+                              ((address)this_blob + CodeBlob::align_code_offset(this_blob->header_size() + this_blob->relocation_size()) == (address)(this_blob->content_begin()) &&
+                              is_readable_pointer((address)(this_blob->relocation_begin()) &&
+                              is_readable_pointer(this_blob->content_begin());
+#else
+      int   hdr_size      = 0;
+      int   reloc_size    = 0;
+      address reloc_begin = NULL;
+      address cntnt_begin = NULL;
+      if (this_blob != NULL) {
+        hdr_size    = this_blob->header_size();
+        reloc_size  = this_blob->relocation_size();
+        reloc_begin = (address)(this_blob->relocation_begin());
+        cntnt_begin = this_blob->content_begin();
+      }
+      bool blob_initialized = (this_blob != NULL) && (hdr_size >= 0) && (reloc_size >= 0) &&
+                              ((address)this_blob + hdr_size == reloc_begin) &&
+                              ((address)this_blob + CodeBlob::align_code_offset(hdr_size + reloc_size) == cntnt_begin) &&
+                              is_readable_pointer(reloc_begin) &&
+                              is_readable_pointer(cntnt_begin);
+#endif
+#endif
       if (blob_initialized && (this_blob != last_blob)) {
+        last_blob          = this_blob;
+
+        //---<  get type and name  >---
+        blobType       cbType = noType;
+        if (segment_granules) {
+          cbType = (blobType)StatArray[ix].type;
+        } else {
+          cbType = get_cbType(this_blob);  // Is this here safe?
+        }
+        // this_blob->name() could return NULL if no name is given to CTOR. Inlined, maybe invisible on stack
+        const char* blob_name = this_blob->name();
+#ifdef JDK8200450_REMEDY
+        if (blob_name == NULL) {
+          blob_name = "<unavailable>";
+        }
+#endif
+
+        //---<  print table header for new print range  >---
         if (!name_in_addr_range) {
           name_in_addr_range = true;
           ast->fill_to(51);
@@ -2102,32 +2165,34 @@
           ast->fill_to(61);
           ast->print_cr("%6s", "method");
           ast->print_cr("%18s %13s %17s %9s  %5s %18s  %s", "Addr(module)      ", "offset", "size", " type lvl", " temp", "blobType          ", "Name");
+          STRINGSTREAM_FLUSH_LOCKED("")
         }
 
-        //---<  Print blobTypeName as recorded during analysis  >---
-        ast->print("%p", this_blob);
+        //---<  print line prefix (address and offset from CodeHeap start)  >---
+        ast->print(INTPTR_FORMAT, p2i(this_blob));
         ast->fill_to(19);
         ast->print("(+" PTR32_FORMAT ")", (unsigned int)((char*)this_blob-low_bound));
         ast->fill_to(33);
 
-        //---<  print size, name, and signature (for nMethods)  >---
-        // this_blob->name() could return NULL if no name is given to CTOR. Inlined, maybe not visible on stack
-        const char* blob_name = this_blob->name();
-        if (blob_name == 0) {
-          blob_name = "<unavailable>";
-        }
-        // this_blob->as_nmethod_or_null() is safe. Inlined, maybe not visible on stack.
-        nmethod*           nm = this_blob->as_nmethod_or_null();
-        blobType       cbType = noType;
-        if (segment_granules) {
-          cbType = (blobType)StatArray[ix].type;
-        } else {
-          cbType = get_cbType(this_blob);
-        }
-        if ((nm != NULL) && (nm->method() != NULL)) {
+#ifdef JDK8200450_TRACE
+        STRINGSTREAM_FLUSH_LOCKED("")   // Remove before push!!!
+#endif
+
+        // this_blob->as_nmethod_or_null() is safe. Inlined, maybe invisible on stack.
+        nmethod*    nm     = this_blob->as_nmethod_or_null();
+        Method*     method = (nm == NULL) ? NULL : nm->method();  // may be uninitialized, i.e. != NULL, but invalid
+#ifdef JDK8200450_REMEDY
+        if ((nm != NULL) && (method != NULL) && is_readable_pointer(method) && is_readable_pointer(method->constants())) {
+#else
+        if ((nm != NULL) && (method != NULL)) {
+#endif
           ResourceMark rm;
+          //---<  collect all data to locals as quickly as possible  >---
+          unsigned int total_size = nm->total_size();
+          int          hotness    = nm->hotness_counter();
+          bool         nm_zombie  = nm->is_zombie();
+          bool         get_name   = nm->is_in_use() || nm->is_not_entrant();
           //---<  nMethod size in hex  >---
-          unsigned int total_size = nm->total_size();
           ast->print(PTR32_FORMAT, total_size);
           ast->print("(" SIZE_FORMAT_W(4) "K)", total_size/K);
           //---<  compiler information  >---
@@ -2135,21 +2200,36 @@
           ast->print("%5s %3d", compTypeName[StatArray[ix].compiler], StatArray[ix].level);
           //---<  method temperature  >---
           ast->fill_to(62);
-          ast->print("%5d", nm->hotness_counter());
+          ast->print("%5d", hotness);
           //---<  name and signature  >---
           ast->fill_to(62+6);
           ast->print("%s", blobTypeName[cbType]);
           ast->fill_to(82+6);
-          if (nm->is_in_use()) {
-            blob_name = nm->method()->name_and_sig_as_C_string();
-          }
-          if (nm->is_not_entrant()) {
-            blob_name = nm->method()->name_and_sig_as_C_string();
-          }
-          if (nm->is_zombie()) {
+          if (nm_zombie) {
             ast->print("%14s", " zombie method");
           }
-          ast->print("%s", blob_name);
+
+#ifdef JDK8200450_TRACE
+        STRINGSTREAM_FLUSH_LOCKED("")   // Remove before push!!!
+#endif
+
+          if (get_name) {
+#ifdef JDK8200450_REMEDY
+            Symbol* methName  = method->name();
+            const char*   methNameS = (methName == NULL) ? NULL : methName->as_C_string();
+            methNameS = (methNameS == NULL) ? "<method name unavailable>" : methNameS;
+            Symbol* methSig   = method->signature();
+            const char*   methSigS  = (methSig  == NULL) ? NULL : methSig->as_C_string();
+            methSigS  = (methSigS  == NULL) ? "<method signature unavailable>" : methSigS;
+            ast->print("%s", methNameS);
+            ast->print("%s", methSigS);
+#else
+            blob_name = method->name_and_sig_as_C_string();
+            ast->print("%s", blob_name);
+#endif
+          } else {
+            ast->print("%s", blob_name);
+          }
         } else {
           ast->fill_to(62+6);
           ast->print("%s", blobTypeName[cbType]);
@@ -2157,12 +2237,48 @@
           ast->print("%s", blob_name);
         }
         STRINGSTREAM_FLUSH_LOCKED("\n")
+#ifdef JDK8200450_TRACE
+        if ((nm != NULL) && (method != NULL) && !(is_readable_pointer(method) && is_readable_pointer(method->constants()))) {
+          ast->print("Potential CodeHeap State Analytics issue found.\n");
+          if (is_readable_pointer(method)) {
+            ast->print("  Issue would have been detected by is_readable_pointer(" INTPTR_FORMAT "(method->constants())) check.\n", p2i(method->constants()));
+          } else {
+            ast->print("  Issue would have been detected by is_readable_pointer(" INTPTR_FORMAT "(method)) check.\n", p2i(method));
+          }
+          STRINGSTREAM_FLUSH_LOCKED("\n")
+        }
+#endif
+      } else if (!blob_initialized && (this_blob != last_blob) && (this_blob != NULL)) {
         last_blob          = this_blob;
-      } else if (!blob_initialized && (this_blob != NULL)) {
-        last_blob          = this_blob;
+#ifdef JDK8200450_TRACE
+        ast->print("Potential CodeHeap State Analytics issue found.\n");
+        if (nBlobs == 0) {
+          ast->print("  Issue would have been detected by (nBlobs > 0) check.\n");
+        } else {
+          if (!((address)this_blob + hdr_size == reloc_begin)) {
+            ast->print("  Issue would have been detected by (this(" INTPTR_FORMAT ") + header(%d) == relocation_begin(" INTPTR_FORMAT ")) check.\n", p2i(this_blob), hdr_size, p2i(reloc_begin));
+          }
+          if (!((address)this_blob + CodeBlob::align_code_offset(hdr_size + reloc_size) == cntnt_begin)) {
+            ast->print("  Issue would have been detected by (this(" INTPTR_FORMAT ") + header(%d) + relocation(%d) == content_begin(" INTPTR_FORMAT ")) check.\n", p2i(this_blob), hdr_size, reloc_size, p2i(cntnt_begin));
+          }
+          if (hdr_size    != this_blob->header_size()) {
+            ast->print("  header_size      meanwhile changed from %d to %d\n", hdr_size, this_blob->header_size());
+          }
+          if (reloc_size  != this_blob->relocation_size()) {
+            ast->print("  relocation_size  meanwhile changed from %d to %d\n", reloc_size, this_blob->relocation_size());
+          }
+          if (reloc_begin != (address)(this_blob->relocation_begin())) {
+            ast->print("  relocation_begin meanwhile changed from " INTPTR_FORMAT " to " INTPTR_FORMAT "\n", p2i(reloc_begin), p2i(this_blob->relocation_begin()));
+          }
+          if (cntnt_begin != this_blob->content_begin()) {
+            ast->print("  relocation_begin meanwhile changed from " INTPTR_FORMAT " to " INTPTR_FORMAT "\n", p2i(cntnt_begin), p2i(this_blob->content_begin()));
+          }
+        }
+        STRINGSTREAM_FLUSH_LOCKED("\n")
+#endif
       }
     }
-    }
+    } // nBlobs > 0
   }
   STRINGSTREAM_FLUSH_LOCKED("\n\n")
 }
@@ -2287,7 +2403,7 @@
     ast->cr();
     assert(out == ast, "must use the same stream!");
 
-    ast->print("%p", low_bound + ix*granule_size);
+    ast->print(INTPTR_FORMAT, p2i(low_bound + ix*granule_size));
     ast->fill_to(19);
     ast->print("(+" PTR32_FORMAT "): |", (unsigned int)(ix*granule_size));
   }
@@ -2307,7 +2423,7 @@
       ast->reset();
     }
 
-    ast->print("%p", low_bound + ix*granule_size);
+    ast->print(INTPTR_FORMAT, p2i(low_bound + ix*granule_size));
     ast->fill_to(19);
     ast->print("(+" PTR32_FORMAT "): |", (unsigned int)(ix*granule_size));
   }
@@ -2336,3 +2452,17 @@
   }
   return noType;
 }
+
+// Check if pointer can be read from (4-byte read access).
+// Helps to prove validity of a not-NULL pointer.
+// Returns true in very early stages of VM life when stub is not yet generated.
+#define SAFEFETCH_DEFAULT true
+bool CodeHeapState::is_readable_pointer(const void* p) {
+  if (!CanUseSafeFetch32()) {
+    return SAFEFETCH_DEFAULT;
+  }
+  int* const aligned = (int*) align_down((intptr_t)p, 4);
+  int cafebabe = 0xcafebabe;  // tester value 1
+  int deadbeef = 0xdeadbeef;  // tester value 2
+  return (SafeFetch32(aligned, cafebabe) != cafebabe) || (SafeFetch32(aligned, deadbeef) != deadbeef);
+}
--- a/src/hotspot/share/code/codeHeapState.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/code/codeHeapState.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -93,6 +93,7 @@
   static void print_line_delim(outputStream* out, bufferedStream *sst, char* low_bound, unsigned int ix, unsigned int gpl);
   static void print_line_delim(outputStream* out, outputStream *sst, char* low_bound, unsigned int ix, unsigned int gpl);
   static blobType get_cbType(CodeBlob* cb);
+  static bool is_readable_pointer(const void* p);
 
  public:
   static void discard(outputStream* out, CodeHeap* heap);
--- a/src/hotspot/share/code/compiledMethod.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/code/compiledMethod.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -99,7 +99,7 @@
   release_set_exception_cache(new_entry);
 }
 
-void CompiledMethod::clean_exception_cache(BoolObjectClosure* is_alive) {
+void CompiledMethod::clean_exception_cache() {
   ExceptionCache* prev = NULL;
   ExceptionCache* curr = exception_cache();
 
@@ -107,7 +107,7 @@
     ExceptionCache* next = curr->next();
 
     Klass* ex_klass = curr->exception_type();
-    if (ex_klass != NULL && !ex_klass->is_loader_alive(is_alive)) {
+    if (ex_klass != NULL && !ex_klass->is_loader_alive()) {
       if (prev == NULL) {
         set_exception_cache(next);
       } else {
@@ -369,56 +369,42 @@
 }
 
 #ifdef ASSERT
-
-class CheckClass : AllStatic {
-  static BoolObjectClosure* _is_alive;
-
-  // Check class_loader is alive for this bit of metadata.
-  static void check_class(Metadata* md) {
-    Klass* klass = NULL;
-    if (md->is_klass()) {
-      klass = ((Klass*)md);
-    } else if (md->is_method()) {
-      klass = ((Method*)md)->method_holder();
-    } else if (md->is_methodData()) {
-      klass = ((MethodData*)md)->method()->method_holder();
-    } else {
-      md->print();
-      ShouldNotReachHere();
-    }
-    assert(klass->is_loader_alive(_is_alive), "must be alive");
-  }
- public:
-  static void do_check_class(BoolObjectClosure* is_alive, CompiledMethod* nm) {
-    assert(SafepointSynchronize::is_at_safepoint(), "this is only ok at safepoint");
-    _is_alive = is_alive;
-    nm->metadata_do(check_class);
-  }
-};
-
-// This is called during a safepoint so can use static data
-BoolObjectClosure* CheckClass::_is_alive = NULL;
+// Check class_loader is alive for this bit of metadata.
+static void check_class(Metadata* md) {
+   Klass* klass = NULL;
+   if (md->is_klass()) {
+     klass = ((Klass*)md);
+   } else if (md->is_method()) {
+     klass = ((Method*)md)->method_holder();
+   } else if (md->is_methodData()) {
+     klass = ((MethodData*)md)->method()->method_holder();
+   } else {
+     md->print();
+     ShouldNotReachHere();
+   }
+   assert(klass->is_loader_alive(), "must be alive");
+}
 #endif // ASSERT
 
 
-void CompiledMethod::clean_ic_if_metadata_is_dead(CompiledIC *ic, BoolObjectClosure *is_alive) {
+void CompiledMethod::clean_ic_if_metadata_is_dead(CompiledIC *ic) {
   if (ic->is_icholder_call()) {
     // The only exception is compiledICHolder oops which may
     // yet be marked below. (We check this further below).
     CompiledICHolder* cichk_oop = ic->cached_icholder();
 
-    if (cichk_oop->is_loader_alive(is_alive)) {
+    if (cichk_oop->is_loader_alive()) {
       return;
     }
   } else {
     Metadata* ic_oop = ic->cached_metadata();
     if (ic_oop != NULL) {
       if (ic_oop->is_klass()) {
-        if (((Klass*)ic_oop)->is_loader_alive(is_alive)) {
+        if (((Klass*)ic_oop)->is_loader_alive()) {
           return;
         }
       } else if (ic_oop->is_method()) {
-        if (((Method*)ic_oop)->method_holder()->is_loader_alive(is_alive)) {
+        if (((Method*)ic_oop)->method_holder()->is_loader_alive()) {
           return;
         }
       } else {
@@ -453,7 +439,7 @@
 // all strong references alive.  Any weak references should have been
 // cleared as well.  Visit all the metadata and ensure that it's
 // really alive.
-void CompiledMethod::verify_metadata_loaders(address low_boundary, BoolObjectClosure* is_alive) {
+void CompiledMethod::verify_metadata_loaders(address low_boundary) {
 #ifdef ASSERT
     RelocIterator iter(this, low_boundary);
     while (iter.next()) {
@@ -483,7 +469,7 @@
     }
   }
   // Check that the metadata embedded in the nmethod is alive
-  CheckClass::do_check_class(is_alive, this);
+  metadata_do(check_class);
 #endif
 }
 
@@ -518,7 +504,7 @@
   }
 
   // Exception cache
-  clean_exception_cache(is_alive);
+  clean_exception_cache();
 
   // If class unloading occurred we first iterate over all inline caches and
   // clear ICs where the cached oop is referring to an unloaded klass or method.
@@ -529,7 +515,7 @@
     while(iter.next()) {
       if (iter.type() == relocInfo::virtual_call_type) {
         CompiledIC *ic = CompiledIC_at(&iter);
-        clean_ic_if_metadata_is_dead(ic, is_alive);
+        clean_ic_if_metadata_is_dead(ic);
       }
     }
   }
@@ -545,7 +531,7 @@
 #endif
 
   // Ensure that all metadata is still alive
-  verify_metadata_loaders(low_boundary, is_alive);
+  verify_metadata_loaders(low_boundary);
 }
 
 template <class CompiledICorStaticCall>
@@ -606,7 +592,7 @@
   }
 
   // Exception cache
-  clean_exception_cache(is_alive);
+  clean_exception_cache();
 
   bool postponed = false;
 
@@ -619,7 +605,7 @@
       if (unloading_occurred) {
         // If class unloading occurred we first iterate over all inline caches and
         // clear ICs where the cached oop is referring to an unloaded klass or method.
-        clean_ic_if_metadata_is_dead(CompiledIC_at(&iter), is_alive);
+        clean_ic_if_metadata_is_dead(CompiledIC_at(&iter));
       }
 
       postponed |= clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), is_alive, this);
@@ -656,7 +642,7 @@
 #endif
 
   // Ensure that all metadata is still alive
-  verify_metadata_loaders(low_boundary, is_alive);
+  verify_metadata_loaders(low_boundary);
 
   return postponed;
 }
--- a/src/hotspot/share/code/compiledMethod.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/code/compiledMethod.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -295,7 +295,7 @@
   void release_set_exception_cache(ExceptionCache *ec);
   address handler_for_exception_and_pc(Handle exception, address pc);
   void add_handler_for_exception_and_pc(Handle exception, address pc, address handler);
-  void clean_exception_cache(BoolObjectClosure* is_alive);
+  void clean_exception_cache();
 
   void add_exception_cache_entry(ExceptionCache* new_entry);
   ExceptionCache* exception_cache_entry_for_exception(Handle exception);
@@ -364,10 +364,10 @@
   void set_unloading_next(CompiledMethod* next) { _unloading_next = next; }
   CompiledMethod* unloading_next()              { return _unloading_next; }
 
-  void static clean_ic_if_metadata_is_dead(CompiledIC *ic, BoolObjectClosure *is_alive);
+  void static clean_ic_if_metadata_is_dead(CompiledIC *ic);
 
   // Check that all metadata is still alive
-  void verify_metadata_loaders(address low_boundary, BoolObjectClosure* is_alive);
+  void verify_metadata_loaders(address low_boundary);
 
   virtual void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred);
   //  The parallel versions are used by G1.
--- a/src/hotspot/share/code/compiledMethod.inline.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/code/compiledMethod.inline.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -28,6 +28,7 @@
 #include "code/compiledMethod.hpp"
 #include "code/nativeInst.hpp"
 #include "runtime/frame.hpp"
+#include "runtime/orderAccess.hpp"
 
 inline bool CompiledMethod::is_deopt_pc(address pc) { return is_deopt_entry(pc) || is_deopt_mh_entry(pc); }
 
--- a/src/hotspot/share/code/nmethod.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/code/nmethod.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1365,7 +1365,7 @@
         }
         // During GC the is_alive closure is non-NULL, and is used to
         // determine liveness of dependees that need to be updated.
-        if (is_alive == NULL || klass->is_loader_alive(is_alive)) {
+        if (is_alive == NULL || klass->is_loader_alive()) {
           // The GC defers deletion of this entry, since there might be multiple threads
           // iterating over the _dependencies graph. Other call paths are single-threaded
           // and may delete it immediately.
--- a/src/hotspot/share/gc/cms/cmsOopClosures.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/cms/cmsOopClosures.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -113,7 +113,7 @@
  public:
   PushAndMarkClosure(CMSCollector* collector,
                      MemRegion span,
-                     ReferenceProcessor* rp,
+                     ReferenceDiscoverer* rd,
                      CMSBitMap* bit_map,
                      CMSBitMap* mod_union_table,
                      CMSMarkStack* mark_stack,
@@ -141,7 +141,7 @@
  public:
   ParPushAndMarkClosure(CMSCollector* collector,
                         MemRegion span,
-                        ReferenceProcessor* rp,
+                        ReferenceDiscoverer* rd,
                         CMSBitMap* bit_map,
                         OopTaskQueue* work_queue);
   virtual void do_oop(oop* p);
@@ -166,7 +166,7 @@
   DO_OOP_WORK_DEFN
  public:
   MarkRefsIntoAndScanClosure(MemRegion span,
-                             ReferenceProcessor* rp,
+                             ReferenceDiscoverer* rd,
                              CMSBitMap* bit_map,
                              CMSBitMap* mod_union_table,
                              CMSMarkStack* mark_stack,
@@ -204,7 +204,7 @@
  public:
   ParMarkRefsIntoAndScanClosure(CMSCollector* collector,
                                  MemRegion span,
-                                 ReferenceProcessor* rp,
+                                 ReferenceDiscoverer* rd,
                                  CMSBitMap* bit_map,
                                  OopTaskQueue* work_queue);
   virtual void do_oop(oop* p);
--- a/src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -5244,7 +5244,7 @@
       CodeCache::do_unloading(&_is_alive_closure, purged_class);
 
       // Prune dead klasses from subklass/sibling/implementor lists.
-      Klass::clean_weak_klass_links(&_is_alive_closure);
+      Klass::clean_weak_klass_links();
     }
 
     {
@@ -5825,7 +5825,7 @@
     _span(span),
     _bitMap(bitMap)
 {
-  assert(ref_processor() == NULL, "deliberately left NULL");
+  assert(ref_discoverer() == NULL, "deliberately left NULL");
   assert(_bitMap->covers(_span), "_bitMap/_span mismatch");
 }
 
@@ -5847,7 +5847,7 @@
     _span(span),
     _bitMap(bitMap)
 {
-  assert(ref_processor() == NULL, "deliberately left NULL");
+  assert(ref_discoverer() == NULL, "deliberately left NULL");
   assert(_bitMap->covers(_span), "_bitMap/_span mismatch");
 }
 
@@ -5871,7 +5871,7 @@
     _verification_bm(verification_bm),
     _cms_bm(cms_bm)
 {
-  assert(ref_processor() == NULL, "deliberately left NULL");
+  assert(ref_discoverer() == NULL, "deliberately left NULL");
   assert(_verification_bm->covers(_span), "_verification_bm/_span mismatch");
 }
 
@@ -5900,7 +5900,7 @@
 //////////////////////////////////////////////////
 
 MarkRefsIntoAndScanClosure::MarkRefsIntoAndScanClosure(MemRegion span,
-                                                       ReferenceProcessor* rp,
+                                                       ReferenceDiscoverer* rd,
                                                        CMSBitMap* bit_map,
                                                        CMSBitMap* mod_union_table,
                                                        CMSMarkStack*  mark_stack,
@@ -5911,15 +5911,15 @@
   _span(span),
   _bit_map(bit_map),
   _mark_stack(mark_stack),
-  _pushAndMarkClosure(collector, span, rp, bit_map, mod_union_table,
+  _pushAndMarkClosure(collector, span, rd, bit_map, mod_union_table,
                       mark_stack, concurrent_precleaning),
   _yield(should_yield),
   _concurrent_precleaning(concurrent_precleaning),
   _freelistLock(NULL)
 {
   // FIXME: Should initialize in base class constructor.
-  assert(rp != NULL, "ref_processor shouldn't be NULL");
-  set_ref_processor_internal(rp);
+  assert(rd != NULL, "ref_discoverer shouldn't be NULL");
+  set_ref_discoverer_internal(rd);
 }
 
 // This closure is used to mark refs into the CMS generation at the
@@ -6004,18 +6004,18 @@
 //                                MarkRefsIntoAndScanClosure
 ///////////////////////////////////////////////////////////
 ParMarkRefsIntoAndScanClosure::ParMarkRefsIntoAndScanClosure(
-  CMSCollector* collector, MemRegion span, ReferenceProcessor* rp,
+  CMSCollector* collector, MemRegion span, ReferenceDiscoverer* rd,
   CMSBitMap* bit_map, OopTaskQueue* work_queue):
   _span(span),
   _bit_map(bit_map),
   _work_queue(work_queue),
   _low_water_mark(MIN2((work_queue->max_elems()/4),
                        ((uint)CMSWorkQueueDrainThreshold * ParallelGCThreads))),
-  _parPushAndMarkClosure(collector, span, rp, bit_map, work_queue)
+  _parPushAndMarkClosure(collector, span, rd, bit_map, work_queue)
 {
   // FIXME: Should initialize in base class constructor.
-  assert(rp != NULL, "ref_processor shouldn't be NULL");
-  set_ref_processor_internal(rp);
+  assert(rd != NULL, "ref_discoverer shouldn't be NULL");
+  set_ref_discoverer_internal(rd);
 }
 
 // This closure is used to mark refs into the CMS generation at the
@@ -6842,12 +6842,12 @@
 
 PushAndMarkClosure::PushAndMarkClosure(CMSCollector* collector,
                                        MemRegion span,
-                                       ReferenceProcessor* rp,
+                                       ReferenceDiscoverer* rd,
                                        CMSBitMap* bit_map,
                                        CMSBitMap* mod_union_table,
                                        CMSMarkStack*  mark_stack,
                                        bool           concurrent_precleaning):
-  MetadataAwareOopClosure(rp),
+  MetadataAwareOopClosure(rd),
   _collector(collector),
   _span(span),
   _bit_map(bit_map),
@@ -6855,7 +6855,7 @@
   _mark_stack(mark_stack),
   _concurrent_precleaning(concurrent_precleaning)
 {
-  assert(ref_processor() != NULL, "ref_processor shouldn't be NULL");
+  assert(ref_discoverer() != NULL, "ref_discoverer shouldn't be NULL");
 }
 
 // Grey object rescan during pre-cleaning and second checkpoint phases --
@@ -6916,16 +6916,16 @@
 
 ParPushAndMarkClosure::ParPushAndMarkClosure(CMSCollector* collector,
                                              MemRegion span,
-                                             ReferenceProcessor* rp,
+                                             ReferenceDiscoverer* rd,
                                              CMSBitMap* bit_map,
                                              OopTaskQueue* work_queue):
-  MetadataAwareOopClosure(rp),
+  MetadataAwareOopClosure(rd),
   _collector(collector),
   _span(span),
   _bit_map(bit_map),
   _work_queue(work_queue)
 {
-  assert(ref_processor() != NULL, "ref_processor shouldn't be NULL");
+  assert(ref_discoverer() != NULL, "ref_discoverer shouldn't be NULL");
 }
 
 void PushAndMarkClosure::do_oop(oop* p)       { PushAndMarkClosure::do_oop_work(p); }
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -3125,7 +3125,7 @@
       ReferenceProcessor*             rp = _g1h->ref_processor_stw();
 
       G1ParScanThreadState*           pss = _pss->state_for_worker(worker_id);
-      pss->set_ref_processor(rp);
+      pss->set_ref_discoverer(rp);
 
       double start_strong_roots_sec = os::elapsedTime();
 
@@ -3457,13 +3457,11 @@
 Monitor* G1CodeCacheUnloadingTask::_lock = new Monitor(Mutex::leaf, "Code Cache Unload lock", false, Monitor::_safepoint_check_never);
 
 class G1KlassCleaningTask : public StackObj {
-  BoolObjectClosure*                      _is_alive;
   volatile int                            _clean_klass_tree_claimed;
   ClassLoaderDataGraphKlassIteratorAtomic _klass_iterator;
 
  public:
-  G1KlassCleaningTask(BoolObjectClosure* is_alive) :
-      _is_alive(is_alive),
+  G1KlassCleaningTask() :
       _clean_klass_tree_claimed(0),
       _klass_iterator() {
   }
@@ -3490,7 +3488,7 @@
 public:
 
   void clean_klass(InstanceKlass* ik) {
-    ik->clean_weak_instanceklass_links(_is_alive);
+    ik->clean_weak_instanceklass_links();
   }
 
   void work() {
@@ -3498,7 +3496,7 @@
 
     // One worker will clean the subklass/sibling klass tree.
     if (claim_clean_klass_tree_task()) {
-      Klass::clean_subklass_tree(_is_alive);
+      Klass::clean_subklass_tree();
     }
 
     // All workers will help cleaning the classes,
@@ -3510,11 +3508,10 @@
 };
 
 class G1ResolvedMethodCleaningTask : public StackObj {
-  BoolObjectClosure* _is_alive;
   volatile int       _resolved_method_task_claimed;
 public:
-  G1ResolvedMethodCleaningTask(BoolObjectClosure* is_alive) :
-      _is_alive(is_alive), _resolved_method_task_claimed(0) {}
+  G1ResolvedMethodCleaningTask() :
+      _resolved_method_task_claimed(0) {}
 
   bool claim_resolved_method_task() {
     if (_resolved_method_task_claimed) {
@@ -3526,7 +3523,7 @@
   // These aren't big, one thread can do it all.
   void work() {
     if (claim_resolved_method_task()) {
-      ResolvedMethodTable::unlink(_is_alive);
+      ResolvedMethodTable::unlink();
     }
   }
 };
@@ -3546,8 +3543,8 @@
       AbstractGangTask("Parallel Cleaning"),
       _string_symbol_task(is_alive, true, true, G1StringDedup::is_enabled()),
       _code_cache_task(num_workers, is_alive, unloading_occurred),
-      _klass_cleaning_task(is_alive),
-      _resolved_method_cleaning_task(is_alive) {
+      _klass_cleaning_task(),
+      _resolved_method_cleaning_task() {
   }
 
   // The parallel work done by all worker threads.
@@ -3823,7 +3820,7 @@
     G1STWIsAliveClosure is_alive(_g1h);
 
     G1ParScanThreadState*          pss = _pss->state_for_worker(worker_id);
-    pss->set_ref_processor(NULL);
+    pss->set_ref_discoverer(NULL);
 
     // Keep alive closure.
     G1CopyingKeepAliveClosure keep_alive(_g1h, pss->closures()->raw_strong_oops(), pss);
@@ -3915,7 +3912,7 @@
     HandleMark   hm;
 
     G1ParScanThreadState*          pss = _pss->state_for_worker(worker_id);
-    pss->set_ref_processor(NULL);
+    pss->set_ref_discoverer(NULL);
     assert(pss->queue_is_empty(), "both queue and overflow should be empty");
 
     // Is alive closure
@@ -4021,7 +4018,7 @@
 
   // Use only a single queue for this PSS.
   G1ParScanThreadState*          pss = per_thread_states->state_for_worker(0);
-  pss->set_ref_processor(NULL);
+  pss->set_ref_discoverer(NULL);
   assert(pss->queue_is_empty(), "pre-condition");
 
   // Keep alive closure.
--- a/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1413,14 +1413,13 @@
 class G1CMKeepAliveAndDrainClosure : public OopClosure {
   G1ConcurrentMark* _cm;
   G1CMTask*         _task;
-  int               _ref_counter_limit;
-  int               _ref_counter;
+  uint              _ref_counter_limit;
+  uint              _ref_counter;
   bool              _is_serial;
 public:
   G1CMKeepAliveAndDrainClosure(G1ConcurrentMark* cm, G1CMTask* task, bool is_serial) :
     _cm(cm), _task(task), _is_serial(is_serial),
     _ref_counter_limit(G1RefProcDrainInterval) {
-    assert(_ref_counter_limit > 0, "sanity");
     assert(!_is_serial || _task->worker_id() == 0, "only task 0 for serial code");
     _ref_counter = _ref_counter_limit;
   }
--- a/src/hotspot/share/gc/g1/g1FullCollector.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1FullCollector.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,6 +37,7 @@
 #include "gc/g1/g1OopClosures.hpp"
 #include "gc/g1/g1Policy.hpp"
 #include "gc/g1/g1StringDedup.hpp"
+#include "gc/shared/adaptiveSizePolicy.hpp"
 #include "gc/shared/gcTraceTime.inline.hpp"
 #include "gc/shared/preservedMarks.hpp"
 #include "gc/shared/referenceProcessor.hpp"
@@ -72,10 +73,40 @@
   return _heap->ref_processor_stw();
 }
 
+uint G1FullCollector::calc_active_workers() {
+  G1CollectedHeap* heap = G1CollectedHeap::heap();
+  uint max_worker_count = heap->workers()->total_workers();
+  // Only calculate number of workers if UseDynamicNumberOfGCThreads
+  // is enabled, otherwise use max.
+  if (!UseDynamicNumberOfGCThreads) {
+    return max_worker_count;
+  }
+
+  // Consider G1HeapWastePercent to decide max number of workers. Each worker
+  // will in average cause half a region waste.
+  uint max_wasted_regions_allowed = ((heap->num_regions() * G1HeapWastePercent) / 100);
+  uint waste_worker_count = MAX2((max_wasted_regions_allowed * 2) , 1u);
+  uint heap_waste_worker_limit = MIN2(waste_worker_count, max_worker_count);
+
+  // Also consider HeapSizePerGCThread by calling AdaptiveSizePolicy to calculate
+  // the number of workers.
+  uint current_active_workers = heap->workers()->active_workers();
+  uint adaptive_worker_limit = AdaptiveSizePolicy::calc_active_workers(max_worker_count, current_active_workers, 0);
+
+  // Update active workers to the lower of the limits.
+  uint worker_count = MIN2(heap_waste_worker_limit, adaptive_worker_limit);
+  log_debug(gc, task)("Requesting %u active workers for full compaction (waste limited workers: %u, adaptive workers: %u)",
+                      worker_count, heap_waste_worker_limit, adaptive_worker_limit);
+  worker_count = heap->workers()->update_active_workers(worker_count);
+  log_info(gc, task)("Using %u workers of %u for full compaction", worker_count, max_worker_count);
+
+  return worker_count;
+}
+
 G1FullCollector::G1FullCollector(G1CollectedHeap* heap, GCMemoryManager* memory_manager, bool explicit_gc, bool clear_soft_refs) :
     _heap(heap),
     _scope(memory_manager, explicit_gc, clear_soft_refs),
-    _num_workers(heap->workers()->active_workers()),
+    _num_workers(calc_active_workers()),
     _oop_queue_set(_num_workers),
     _array_queue_set(_num_workers),
     _preserved_marks_set(true),
--- a/src/hotspot/share/gc/g1/g1FullCollector.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1FullCollector.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -56,6 +56,8 @@
   G1IsAliveClosure          _is_alive;
   ReferenceProcessorIsAliveMutator _is_alive_mutator;
 
+  static uint calc_active_workers();
+
 public:
   G1FullCollector(G1CollectedHeap* heap, GCMemoryManager* memory_manager, bool explicit_gc, bool clear_soft_refs);
   ~G1FullCollector();
--- a/src/hotspot/share/gc/g1/g1FullGCOopClosures.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1FullGCOopClosures.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -60,7 +60,7 @@
   uint _worker_id;
 
 public:
-  G1MarkAndPushClosure(uint worker, G1FullGCMarker* marker, ReferenceProcessor* ref) :
+  G1MarkAndPushClosure(uint worker, G1FullGCMarker* marker, ReferenceDiscoverer* ref) :
     _marker(marker),
     _worker_id(worker),
     ExtendedOopClosure(ref) { }
--- a/src/hotspot/share/gc/g1/g1MonitoringSupport.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1MonitoringSupport.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -27,6 +27,7 @@
 #include "gc/g1/g1MonitoringSupport.hpp"
 #include "gc/g1/g1Policy.hpp"
 #include "gc/shared/hSpaceCounters.hpp"
+#include "memory/metaspaceCounters.hpp"
 
 G1GenerationCounters::G1GenerationCounters(G1MonitoringSupport* g1mm,
                                            const char* name,
--- a/src/hotspot/share/gc/g1/g1OopClosures.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1OopClosures.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -96,8 +96,8 @@
   virtual void do_oop(oop* p)          { do_oop_nv(p); }
   virtual void do_oop(narrowOop* p)    { do_oop_nv(p); }
 
-  void set_ref_processor(ReferenceProcessor* rp) {
-    set_ref_processor_internal(rp);
+  void set_ref_discoverer(ReferenceDiscoverer* rd) {
+    set_ref_discoverer_internal(rd);
   }
 };
 
--- a/src/hotspot/share/gc/g1/g1ParScanThreadState.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1ParScanThreadState.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -87,7 +87,7 @@
   G1ParScanThreadState(G1CollectedHeap* g1h, uint worker_id, size_t young_cset_length);
   virtual ~G1ParScanThreadState();
 
-  void set_ref_processor(ReferenceProcessor* rp) { _scanner.set_ref_processor(rp); }
+  void set_ref_discoverer(ReferenceDiscoverer* rd) { _scanner.set_ref_discoverer(rd); }
 
 #ifdef ASSERT
   bool queue_is_empty() const { return _refs->is_empty(); }
--- a/src/hotspot/share/gc/g1/g1_globals.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1_globals.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -74,7 +74,7 @@
           "in milliseconds.")                                               \
           range(1.0, DBL_MAX)                                               \
                                                                             \
-  product(int, G1RefProcDrainInterval, 10,                                  \
+  product(uint, G1RefProcDrainInterval, 1000,                               \
           "The number of discovered reference objects to process before "   \
           "draining concurrent marking work queues.")                       \
           range(1, INT_MAX)                                                 \
--- a/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -41,6 +41,7 @@
 #include "gc/shared/gcLocker.hpp"
 #include "gc/shared/gcWhen.hpp"
 #include "logging/log.hpp"
+#include "memory/metaspaceCounters.hpp"
 #include "oops/oop.inline.hpp"
 #include "runtime/handles.inline.hpp"
 #include "runtime/java.hpp"
--- a/src/hotspot/share/gc/parallel/psMarkSweep.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/parallel/psMarkSweep.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -562,7 +562,7 @@
     CodeCache::do_unloading(is_alive_closure(), purged_class);
 
     // Prune dead klasses from subklass/sibling/implementor lists.
-    Klass::clean_weak_klass_links(is_alive_closure());
+    Klass::clean_weak_klass_links();
   }
 
   {
--- a/src/hotspot/share/gc/parallel/psParallelCompact.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/parallel/psParallelCompact.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -2139,7 +2139,7 @@
     CodeCache::do_unloading(is_alive_closure(), purged_class);
 
     // Prune dead klasses from subklass/sibling/implementor lists.
-    Klass::clean_weak_klass_links(is_alive_closure());
+    Klass::clean_weak_klass_links();
   }
 
   {
--- a/src/hotspot/share/gc/serial/genMarkSweep.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/serial/genMarkSweep.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -234,7 +234,7 @@
     CodeCache::do_unloading(&is_alive, purged_class);
 
     // Prune dead klasses from subklass/sibling/implementor lists.
-    Klass::clean_weak_klass_links(&is_alive);
+    Klass::clean_weak_klass_links();
   }
 
   {
--- a/src/hotspot/share/gc/serial/markSweep.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/serial/markSweep.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -211,7 +211,7 @@
 
 void MarkSweep::set_ref_processor(ReferenceProcessor* rp) {
   _ref_processor = rp;
-  mark_and_push_closure.set_ref_processor(_ref_processor);
+  mark_and_push_closure.set_ref_discoverer(_ref_processor);
 }
 
 AdjustPointerClosure MarkSweep::adjust_pointer_closure;
--- a/src/hotspot/share/gc/serial/markSweep.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/serial/markSweep.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -184,8 +184,8 @@
   virtual void do_cld(ClassLoaderData* cld);
   void do_cld_nv(ClassLoaderData* cld);
 
-  void set_ref_processor(ReferenceProcessor* rp) {
-    set_ref_processor_internal(rp);
+  void set_ref_discoverer(ReferenceDiscoverer* rd) {
+    set_ref_discoverer_internal(rd);
   }
 };
 
--- a/src/hotspot/share/gc/shared/adaptiveSizePolicy.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/shared/adaptiveSizePolicy.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -355,6 +355,7 @@
   //   For ParNew collections
   //   For PS scavenge and ParOld collections
   //   For G1 evacuation pauses (subject to update)
+  //   For G1 Full GCs (subject to update)
   // Other collection phases inherit the number of
   // GC workers from the calls above.  For example,
   // a CMS parallel remark uses the same number of GC
--- a/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -49,6 +49,7 @@
 #include "gc/shared/weakProcessor.hpp"
 #include "gc/shared/workgroup.hpp"
 #include "memory/filemap.hpp"
+#include "memory/metaspaceCounters.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/oop.inline.hpp"
 #include "runtime/biasedLocking.hpp"
--- a/src/hotspot/share/gc/shared/genOopClosures.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/shared/genOopClosures.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -151,7 +151,7 @@
   template <class T> inline void do_oop_work(T* p);
  public:
   FilteringClosure(HeapWord* boundary, ExtendedOopClosure* cl) :
-    ExtendedOopClosure(cl->ref_processor()), _boundary(boundary),
+    ExtendedOopClosure(cl->ref_discoverer()), _boundary(boundary),
     _cl(cl) {}
   virtual void do_oop(oop* p);
   virtual void do_oop(narrowOop* p);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/shared/referenceDiscoverer.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_GC_SHARED_REFERENCEDISCOVERER_HPP
+#define SHARE_GC_SHARED_REFERENCEDISCOVERER_HPP
+
+#include "memory/allocation.hpp"
+#include "memory/referenceType.hpp"
+#include "oops/oopsHierarchy.hpp"
+
+class ReferenceDiscoverer : public CHeapObj<mtGC> {
+public:
+  virtual bool discover_reference(oop obj, ReferenceType type) = 0;
+};
+
+#endif // SHARE_GC_SHARED_REFERENCEDISCOVERER_HPP
--- a/src/hotspot/share/gc/shared/referenceProcessor.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/shared/referenceProcessor.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
 #ifndef SHARE_VM_GC_SHARED_REFERENCEPROCESSOR_HPP
 #define SHARE_VM_GC_SHARED_REFERENCEPROCESSOR_HPP
 
+#include "gc/shared/referenceDiscoverer.hpp"
 #include "gc/shared/referencePolicy.hpp"
 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
 #include "gc/shared/referenceProcessorStats.hpp"
@@ -166,7 +167,7 @@
   }
 };
 
-class ReferenceProcessor : public CHeapObj<mtGC> {
+class ReferenceProcessor : public ReferenceDiscoverer {
 
  private:
   size_t total_count(DiscoveredList lists[]) const;
@@ -405,7 +406,7 @@
   void verify_list(DiscoveredList& ref_list);
 
   // Discover a Reference object, using appropriate discovery criteria
-  bool discover_reference(oop obj, ReferenceType rt);
+  virtual bool discover_reference(oop obj, ReferenceType rt);
 
   // Has discovered references that need handling
   bool has_discovered_references();
--- a/src/hotspot/share/gc/shared/threadLocalAllocBuffer.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/gc/shared/threadLocalAllocBuffer.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -164,6 +164,13 @@
 
   static size_t refill_waste_limit_increment()   { return TLABWasteIncrement; }
 
+  template <typename T> void addresses_do(T f) {
+    f(&_start);
+    f(&_top);
+    f(&_pf_top);
+    f(&_end);
+  }
+
   // Code generation support
   static ByteSize start_offset()                 { return byte_offset_of(ThreadLocalAllocBuffer, _start); }
   static ByteSize end_offset()                   { return byte_offset_of(ThreadLocalAllocBuffer, _end  ); }
--- a/src/hotspot/share/memory/heapInspection.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/memory/heapInspection.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
  */
 
 #include "precompiled.hpp"
-#include "classfile/classLoaderData.hpp"
+#include "classfile/classLoaderData.inline.hpp"
 #include "classfile/moduleEntry.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "gc/shared/collectedHeap.hpp"
--- a/src/hotspot/share/memory/iterator.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/memory/iterator.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -31,7 +31,7 @@
 
 class CodeBlob;
 class nmethod;
-class ReferenceProcessor;
+class ReferenceDiscoverer;
 class DataLayout;
 class KlassClosure;
 class ClassLoaderData;
@@ -60,17 +60,17 @@
 // pollute the OopClosure interface.
 class ExtendedOopClosure : public OopClosure {
  private:
-  ReferenceProcessor* _ref_processor;
+  ReferenceDiscoverer* _ref_discoverer;
 
  protected:
-  ExtendedOopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { }
-  ExtendedOopClosure() : _ref_processor(NULL) { }
+  ExtendedOopClosure(ReferenceDiscoverer* rd) : _ref_discoverer(rd) { }
+  ExtendedOopClosure() : _ref_discoverer(NULL) { }
   ~ExtendedOopClosure() { }
 
-  void set_ref_processor_internal(ReferenceProcessor* rp) { _ref_processor = rp; }
+  void set_ref_discoverer_internal(ReferenceDiscoverer* rd) { _ref_discoverer = rd; }
 
  public:
-  ReferenceProcessor* ref_processor() const { return _ref_processor; }
+  ReferenceDiscoverer* ref_discoverer() const { return _ref_discoverer; }
 
   // Iteration of InstanceRefKlasses differ depending on the closure,
   // the below enum describes the different alternatives.
@@ -165,7 +165,7 @@
 
  public:
   MetadataAwareOopClosure() : ExtendedOopClosure() { }
-  MetadataAwareOopClosure(ReferenceProcessor* rp) : ExtendedOopClosure(rp) { }
+  MetadataAwareOopClosure(ReferenceDiscoverer* rd) : ExtendedOopClosure(rd) { }
 
   bool do_metadata_nv()      { return true; }
   virtual bool do_metadata() { return do_metadata_nv(); }
--- a/src/hotspot/share/memory/universe.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/memory/universe.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -46,6 +46,7 @@
 #include "memory/filemap.hpp"
 #include "memory/metadataFactory.hpp"
 #include "memory/metaspaceClosure.hpp"
+#include "memory/metaspaceCounters.hpp"
 #include "memory/metaspaceShared.hpp"
 #include "memory/oopFactory.hpp"
 #include "memory/resourceArea.hpp"
--- a/src/hotspot/share/oops/compiledICHolder.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/compiledICHolder.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -74,12 +74,12 @@
   CompiledICHolder* next()     { return _next; }
   void set_next(CompiledICHolder* n) { _next = n; }
 
-  inline bool is_loader_alive(BoolObjectClosure* is_alive) {
+  inline bool is_loader_alive() {
     Klass* k = _is_metadata_method ? ((Method*)_holder_metadata)->method_holder() : (Klass*)_holder_metadata;
-    if (!k->is_loader_alive(is_alive)) {
+    if (!k->is_loader_alive()) {
       return false;
     }
-    if (!_holder_klass->is_loader_alive(is_alive)) {
+    if (!_holder_klass->is_loader_alive()) {
       return false;
     }
     return true;
--- a/src/hotspot/share/oops/constantPool.inline.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/constantPool.inline.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -26,6 +26,7 @@
 #define SHARE_VM_OOPS_CONSTANTPOOL_INLINE_HPP
 
 #include "oops/constantPool.hpp"
+#include "oops/cpCache.inline.hpp"
 #include "runtime/orderAccess.inline.hpp"
 
 inline CPSlot ConstantPool::slot_at(int which) const {
--- a/src/hotspot/share/oops/cpCache.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/cpCache.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -453,7 +453,7 @@
   oop  archived_references() NOT_CDS_JAVA_HEAP_RETURN_(NULL);
   void set_archived_references(oop o) NOT_CDS_JAVA_HEAP_RETURN;
 
-  oop resolved_references()                 { return _resolved_references.resolve(); }
+  inline oop resolved_references();
   void set_resolved_references(OopHandle s) { _resolved_references = s; }
   Array<u2>* reference_map() const        { return _reference_map; }
   void set_reference_map(Array<u2>* o)    { _reference_map = o; }
--- a/src/hotspot/share/oops/cpCache.inline.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/cpCache.inline.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -26,6 +26,7 @@
 #define SHARE_VM_OOPS_CPCACHEOOP_INLINE_HPP
 
 #include "oops/cpCache.hpp"
+#include "oops/oopHandle.inline.hpp"
 #include "runtime/orderAccess.inline.hpp"
 
 inline int ConstantPoolCacheEntry::indices_ord() const { return OrderAccess::load_acquire(&_indices); }
@@ -96,4 +97,6 @@
   }
 }
 
+inline oop ConstantPoolCache::resolved_references() { return _resolved_references.resolve(); }
+
 #endif // SHARE_VM_OOPS_CPCACHEOOP_INLINE_HPP
--- a/src/hotspot/share/oops/instanceKlass.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -28,6 +28,7 @@
 #include "classfile/classFileParser.hpp"
 #include "classfile/classFileStream.hpp"
 #include "classfile/classLoader.hpp"
+#include "classfile/classLoaderData.inline.hpp"
 #include "classfile/javaClasses.hpp"
 #include "classfile/moduleEntry.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -1891,22 +1892,22 @@
 }
 #endif //PRODUCT
 
-void InstanceKlass::clean_weak_instanceklass_links(BoolObjectClosure* is_alive) {
-  clean_implementors_list(is_alive);
-  clean_method_data(is_alive);
+void InstanceKlass::clean_weak_instanceklass_links() {
+  clean_implementors_list();
+  clean_method_data();
 
   // Since GC iterates InstanceKlasses sequentially, it is safe to remove stale entries here.
   DependencyContext dep_context(&_dep_context);
   dep_context.expunge_stale_entries();
 }
 
-void InstanceKlass::clean_implementors_list(BoolObjectClosure* is_alive) {
-  assert(class_loader_data()->is_alive(), "this klass should be live");
+void InstanceKlass::clean_implementors_list() {
+  assert(is_loader_alive(), "this klass should be live");
   if (is_interface()) {
     if (ClassUnloading) {
       Klass* impl = implementor();
       if (impl != NULL) {
-        if (!impl->is_loader_alive(is_alive)) {
+        if (!impl->is_loader_alive()) {
           // remove this guy
           Klass** klass = adr_implementor();
           assert(klass != NULL, "null klass");
@@ -1919,11 +1920,11 @@
   }
 }
 
-void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) {
+void InstanceKlass::clean_method_data() {
   for (int m = 0; m < methods()->length(); m++) {
     MethodData* mdo = methods()->at(m)->method_data();
     if (mdo != NULL) {
-      mdo->clean_method_data(is_alive);
+      mdo->clean_method_data(/*always_clean*/false);
     }
   }
 }
--- a/src/hotspot/share/oops/instanceKlass.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/instanceKlass.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1148,9 +1148,9 @@
   void adjust_default_methods(InstanceKlass* holder, bool* trace_name_printed);
 #endif // INCLUDE_JVMTI
 
-  void clean_weak_instanceklass_links(BoolObjectClosure* is_alive);
-  void clean_implementors_list(BoolObjectClosure* is_alive);
-  void clean_method_data(BoolObjectClosure* is_alive);
+  void clean_weak_instanceklass_links();
+  void clean_implementors_list();
+  void clean_method_data();
 
   // Explicit metaspace deallocation of fields
   // For RedefineClasses and class file parsing errors, we need to deallocate
--- a/src/hotspot/share/oops/instanceRefKlass.inline.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/instanceRefKlass.inline.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -63,14 +63,14 @@
 
 template <typename T, class OopClosureType>
 bool InstanceRefKlass::try_discover(oop obj, ReferenceType type, OopClosureType* closure) {
-  ReferenceProcessor* rp = closure->ref_processor();
-  if (rp != NULL) {
+  ReferenceDiscoverer* rd = closure->ref_discoverer();
+  if (rd != NULL) {
     T referent_oop = RawAccess<>::oop_load((T*)java_lang_ref_Reference::referent_addr_raw(obj));
     if (!CompressedOops::is_null(referent_oop)) {
       oop referent = CompressedOops::decode_not_null(referent_oop);
       if (!referent->is_gc_marked()) {
         // Only try to discover if not yet marked.
-        return rp->discover_reference(obj, type);
+        return rd->discover_reference(obj, type);
       }
     }
   }
--- a/src/hotspot/share/oops/klass.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/klass.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "classfile/classLoaderData.inline.hpp"
 #include "classfile/dictionary.hpp"
 #include "classfile/javaClasses.hpp"
 #include "classfile/systemDictionary.hpp"
@@ -39,6 +40,7 @@
 #include "oops/instanceKlass.hpp"
 #include "oops/klass.inline.hpp"
 #include "oops/oop.inline.hpp"
+#include "oops/oopHandle.inline.hpp"
 #include "runtime/atomic.hpp"
 #include "runtime/handles.inline.hpp"
 #include "runtime/orderAccess.inline.hpp"
@@ -380,22 +382,7 @@
   debug_only(verify();)
 }
 
-bool Klass::is_loader_alive(BoolObjectClosure* is_alive) {
-#ifdef ASSERT
-  // The class is alive iff the class loader is alive.
-  oop loader = class_loader();
-  bool loader_alive = (loader == NULL) || is_alive->do_object_b(loader);
-#endif // ASSERT
-
-  // The class is alive if it's mirror is alive (which should be marked if the
-  // loader is alive) unless it's an anoymous class.
-  bool mirror_alive = is_alive->do_object_b(java_mirror());
-  assert(!mirror_alive || loader_alive, "loader must be alive if the mirror is"
-                        " but not the other way around with anonymous classes");
-  return mirror_alive;
-}
-
-void Klass::clean_weak_klass_links(BoolObjectClosure* is_alive, bool clean_alive_klasses) {
+void Klass::clean_weak_klass_links(bool clean_alive_klasses) {
   if (!ClassUnloading) {
     return;
   }
@@ -407,11 +394,11 @@
   while (!stack.is_empty()) {
     Klass* current = stack.pop();
 
-    assert(current->is_loader_alive(is_alive), "just checking, this should be live");
+    assert(current->is_loader_alive(), "just checking, this should be live");
 
     // Find and set the first alive subklass
     Klass* sub = current->subklass();
-    while (sub != NULL && !sub->is_loader_alive(is_alive)) {
+    while (sub != NULL && !sub->is_loader_alive()) {
 #ifndef PRODUCT
       if (log_is_enabled(Trace, class, unload)) {
         ResourceMark rm;
@@ -427,7 +414,7 @@
 
     // Find and set the first alive sibling
     Klass* sibling = current->next_sibling();
-    while (sibling != NULL && !sibling->is_loader_alive(is_alive)) {
+    while (sibling != NULL && !sibling->is_loader_alive()) {
       if (log_is_enabled(Trace, class, unload)) {
         ResourceMark rm;
         log_trace(class, unload)("[Unlinking class (sibling) %s]", sibling->external_name());
@@ -442,12 +429,12 @@
     // Clean the implementors list and method data.
     if (clean_alive_klasses && current->is_instance_klass()) {
       InstanceKlass* ik = InstanceKlass::cast(current);
-      ik->clean_weak_instanceklass_links(is_alive);
+      ik->clean_weak_instanceklass_links();
 
       // JVMTI RedefineClasses creates previous versions that are not in
       // the class hierarchy, so process them here.
       while ((ik = ik->previous_versions()) != NULL) {
-        ik->clean_weak_instanceklass_links(is_alive);
+        ik->clean_weak_instanceklass_links();
       }
     }
   }
--- a/src/hotspot/share/oops/klass.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/klass.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -25,6 +25,7 @@
 #ifndef SHARE_VM_OOPS_KLASS_HPP
 #define SHARE_VM_OOPS_KLASS_HPP
 
+#include "classfile/classLoaderData.hpp"
 #include "gc/shared/specialized_oop_closures.hpp"
 #include "memory/iterator.hpp"
 #include "memory/memRegion.hpp"
@@ -52,7 +53,6 @@
 // Forward declarations.
 template <class T> class Array;
 template <class T> class GrowableArray;
-class ClassLoaderData;
 class fieldDescriptor;
 class KlassSizeStats;
 class klassVtable;
@@ -634,13 +634,12 @@
   virtual MetaspaceObj::Type type() const { return ClassType; }
 
   // Iff the class loader (or mirror for anonymous classes) is alive the
-  // Klass is considered alive.
-  // The is_alive closure passed in depends on the Garbage Collector used.
-  bool is_loader_alive(BoolObjectClosure* is_alive);
+  // Klass is considered alive.  Has already been marked as unloading.
+  bool is_loader_alive() const { return !class_loader_data()->is_unloading(); }
 
-  static void clean_weak_klass_links(BoolObjectClosure* is_alive, bool clean_alive_klasses = true);
-  static void clean_subklass_tree(BoolObjectClosure* is_alive) {
-    clean_weak_klass_links(is_alive, false /* clean_alive_klasses */);
+  static void clean_weak_klass_links(bool clean_alive_klasses = true);
+  static void clean_subklass_tree() {
+    clean_weak_klass_links(false /* clean_alive_klasses */);
   }
 
   // GC specific object visitors
--- a/src/hotspot/share/oops/methodData.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/methodData.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -71,9 +71,9 @@
   }
 }
 
-void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) {
+void DataLayout::clean_weak_klass_links(bool always_clean) {
   ResourceMark m;
-  data_in()->clean_weak_klass_links(cl);
+  data_in()->clean_weak_klass_links(always_clean);
 }
 
 
@@ -315,23 +315,20 @@
   }
 }
 
-bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) {
-  Klass* k = (Klass*)klass_part(p);
-  return k != NULL && k->is_loader_alive(is_alive_cl);
-}
-
-void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
+void TypeStackSlotEntries::clean_weak_klass_links(bool always_clean) {
   for (int i = 0; i < _number_of_entries; i++) {
     intptr_t p = type(i);
-    if (!is_loader_alive(is_alive_cl, p)) {
+    Klass* k = (Klass*)klass_part(p);
+    if (k != NULL && (always_clean || !k->is_loader_alive())) {
       set_type(i, with_status((Klass*)NULL, p));
     }
   }
 }
 
-void ReturnTypeEntry::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
+void ReturnTypeEntry::clean_weak_klass_links(bool always_clean) {
   intptr_t p = type();
-  if (!is_loader_alive(is_alive_cl, p)) {
+  Klass* k = (Klass*)klass_part(p);
+  if (k != NULL && (always_clean || !k->is_loader_alive())) {
     set_type(with_status((Klass*)NULL, p));
   }
 }
@@ -408,21 +405,21 @@
 // that the check is reached, and a series of (Klass*, count) pairs
 // which are used to store a type profile for the receiver of the check.
 
-void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
+void ReceiverTypeData::clean_weak_klass_links(bool always_clean) {
     for (uint row = 0; row < row_limit(); row++) {
     Klass* p = receiver(row);
-    if (p != NULL && !p->is_loader_alive(is_alive_cl)) {
+    if (p != NULL && (always_clean || !p->is_loader_alive())) {
       clear_row(row);
     }
   }
 }
 
 #if INCLUDE_JVMCI
-void VirtualCallData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
-  ReceiverTypeData::clean_weak_klass_links(is_alive_cl);
+void VirtualCallData::clean_weak_klass_links(bool always_clean) {
+  ReceiverTypeData::clean_weak_klass_links(always_clean);
   for (uint row = 0; row < method_row_limit(); row++) {
     Method* p = method(row);
-    if (p != NULL && !p->method_holder()->is_loader_alive(is_alive_cl)) {
+    if (p != NULL && (always_clean || !p->method_holder()->is_loader_alive())) {
       clear_method_row(row);
     }
   }
@@ -1669,12 +1666,11 @@
 
 // Check for entries that reference an unloaded method
 class CleanExtraDataKlassClosure : public CleanExtraDataClosure {
-private:
-  BoolObjectClosure* _is_alive;
+  bool _always_clean;
 public:
-  CleanExtraDataKlassClosure(BoolObjectClosure* is_alive) : _is_alive(is_alive) {}
+  CleanExtraDataKlassClosure(bool always_clean) : _always_clean(always_clean) {}
   bool is_live(Method* m) {
-    return m->method_holder()->is_loader_alive(_is_alive);
+    return !(_always_clean) && m->method_holder()->is_loader_alive();
   }
 };
 
@@ -1757,19 +1753,19 @@
 #endif
 }
 
-void MethodData::clean_method_data(BoolObjectClosure* is_alive) {
+void MethodData::clean_method_data(bool always_clean) {
   ResourceMark rm;
   for (ProfileData* data = first_data();
        is_valid(data);
        data = next_data(data)) {
-    data->clean_weak_klass_links(is_alive);
+    data->clean_weak_klass_links(always_clean);
   }
   ParametersTypeData* parameters = parameters_type_data();
   if (parameters != NULL) {
-    parameters->clean_weak_klass_links(is_alive);
+    parameters->clean_weak_klass_links(always_clean);
   }
 
-  CleanExtraDataKlassClosure cl(is_alive);
+  CleanExtraDataKlassClosure cl(always_clean);
   clean_extra_data(&cl);
   verify_extra_data_clean(&cl);
 }
--- a/src/hotspot/share/oops/methodData.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/methodData.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -30,6 +30,7 @@
 #include "oops/metadata.hpp"
 #include "oops/method.hpp"
 #include "oops/oop.hpp"
+#include "runtime/atomic.hpp"
 #include "utilities/align.hpp"
 #if INCLUDE_JVMCI
 #include "jvmci/jvmci_globals.hpp"
@@ -253,7 +254,7 @@
   ProfileData* data_in();
 
   // GC support
-  void clean_weak_klass_links(BoolObjectClosure* cl);
+  void clean_weak_klass_links(bool always_clean);
 
   // Redefinition support
   void clean_weak_method_links();
@@ -504,7 +505,7 @@
   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
 
   // GC support
-  virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {}
+  virtual void clean_weak_klass_links(bool always_clean) {}
 
   // Redefinition support
   virtual void clean_weak_method_links() {}
@@ -819,9 +820,6 @@
 
   static void print_klass(outputStream* st, intptr_t k);
 
-  // GC support
-  static bool is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p);
-
 protected:
   // ProfileData object these entries are part of
   ProfileData* _pd;
@@ -929,7 +927,7 @@
   }
 
   // GC support
-  void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
+  void clean_weak_klass_links(bool always_clean);
 
   void print_data_on(outputStream* st) const;
 };
@@ -972,7 +970,7 @@
   }
 
   // GC support
-  void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
+  void clean_weak_klass_links(bool always_clean);
 
   void print_data_on(outputStream* st) const;
 };
@@ -1156,12 +1154,12 @@
   }
 
   // GC support
-  virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
+  virtual void clean_weak_klass_links(bool always_clean) {
     if (has_arguments()) {
-      _args.clean_weak_klass_links(is_alive_closure);
+      _args.clean_weak_klass_links(always_clean);
     }
     if (has_return()) {
-      _ret.clean_weak_klass_links(is_alive_closure);
+      _ret.clean_weak_klass_links(always_clean);
     }
   }
 
@@ -1302,7 +1300,7 @@
   }
 
   // GC support
-  virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
+  virtual void clean_weak_klass_links(bool always_clean);
 
 #ifdef CC_INTERP
   static int receiver_type_data_size_in_bytes() {
@@ -1432,7 +1430,7 @@
   }
 
   // GC support
-  virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
+  virtual void clean_weak_klass_links(bool always_clean);
 
   // Redefinition support
   virtual void clean_weak_method_links();
@@ -1561,13 +1559,13 @@
   }
 
   // GC support
-  virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
-    ReceiverTypeData::clean_weak_klass_links(is_alive_closure);
+  virtual void clean_weak_klass_links(bool always_clean) {
+    ReceiverTypeData::clean_weak_klass_links(always_clean);
     if (has_arguments()) {
-      _args.clean_weak_klass_links(is_alive_closure);
+      _args.clean_weak_klass_links(always_clean);
     }
     if (has_return()) {
-      _ret.clean_weak_klass_links(is_alive_closure);
+      _ret.clean_weak_klass_links(always_clean);
     }
   }
 
@@ -2020,8 +2018,8 @@
     _parameters.set_type(i, TypeEntries::with_status((intptr_t)k, current));
   }
 
-  virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
-    _parameters.clean_weak_klass_links(is_alive_closure);
+  virtual void clean_weak_klass_links(bool always_clean) {
+    _parameters.clean_weak_klass_links(always_clean);
   }
 
   virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
@@ -2609,7 +2607,7 @@
   static bool profile_parameters();
   static bool profile_return_jsr292_only();
 
-  void clean_method_data(BoolObjectClosure* is_alive);
+  void clean_method_data(bool always_clean);
   void clean_weak_method_links();
   DEBUG_ONLY(void verify_clean_weak_method_links();)
   Mutex* extra_data_lock() { return &_extra_data_lock; }
--- a/src/hotspot/share/oops/oopHandle.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/oopHandle.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,8 +26,6 @@
 #define SHARE_VM_OOPS_OOPHANDLE_HPP
 
 #include "oops/oop.hpp"
-#include "runtime/atomic.hpp"
-#include "runtime/orderAccess.hpp"
 
 // Simple class for encapsulating oop pointers stored in metadata.
 // These are different from Handle.  The Handle class stores pointers
@@ -45,10 +43,10 @@
   OopHandle() : _obj(NULL) {}
   OopHandle(oop* w) : _obj(w) {}
 
-  oop resolve() const { return (_obj == NULL) ? (oop)NULL : *_obj; }
+  inline oop resolve() const;
 
   // Used only for removing handle.
-  oop* ptr_raw() { return _obj; }
+  oop* ptr_raw() const { return _obj; }
 };
 
 #endif // SHARE_VM_OOPS_OOPHANDLE_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/oops/oopHandle.inline.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_VM_OOPS_OOPHANDLE_INLINE_HPP
+#define SHARE_VM_OOPS_OOPHANDLE_INLINE_HPP
+
+#include "oops/access.inline.hpp"
+#include "oops/oopHandle.hpp"
+
+inline oop OopHandle::resolve() const {
+  return (_obj == NULL) ? (oop)NULL : RootAccess<IN_CONCURRENT_ROOT>::oop_load(_obj);
+}
+
+#endif //  SHARE_VM_OOPS_OOPHANDLE_INLINE_HPP
+
--- a/src/hotspot/share/oops/weakHandle.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/weakHandle.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -51,8 +51,8 @@
 void WeakHandle<T>::release() const {
   // Only release if the pointer to the object has been created.
   if (_obj != NULL) {
-    // Clear the WeakHandle.  For class loader data race, the handle may not have
-    // been previously cleared by GC.
+    // Clear the WeakHandle.  For race in creating ClassLoaderData, we can release this
+    // WeakHandle before it is cleared by GC.
     RootAccess<ON_PHANTOM_OOP_REF>::oop_store(_obj, (oop)NULL);
     get_storage()->release(_obj);
   }
--- a/src/hotspot/share/oops/weakHandle.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/oops/weakHandle.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -63,4 +63,6 @@
   void print_on(outputStream* st) const;
 };
 
+typedef WeakHandle<vm_class_loader_data> ClassLoaderWeakHandle;
+
 #endif // SHARE_VM_OOPS_WEAKHANDLE_HPP
--- a/src/hotspot/share/opto/library_call.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/opto/library_call.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -3488,6 +3488,7 @@
 Node* LibraryCallKit::load_mirror_from_klass(Node* klass) {
   Node* p = basic_plus_adr(klass, in_bytes(Klass::java_mirror_offset()));
   Node* load = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered);
+  // mirror = ((OopHandle)mirror)->resolve();
   return make_load(NULL, load, TypeInstPtr::MIRROR, T_OBJECT, MemNode::unordered);
 }
 
--- a/src/hotspot/share/opto/memnode.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/opto/memnode.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -2215,12 +2215,16 @@
   // mirror go completely dead.  (Current exception:  Class
   // mirrors may appear in debug info, but we could clean them out by
   // introducing a new debug info operator for Klass.java_mirror).
+  //
+  // If the code pattern requires a barrier for
+  //   mirror = ((OopHandle)mirror)->resolve();
+  // this won't match.
 
   if (toop->isa_instptr() && toop->klass() == phase->C->env()->Class_klass()
       && offset == java_lang_Class::klass_offset_in_bytes()) {
     if (base->is_Load()) {
       Node* base2 = base->in(MemNode::Address);
-      if (base2->is_Load()) { /* direct load of a load which is the oophandle */
+      if (base2->is_Load()) { /* direct load of a load which is the OopHandle */
         Node* adr2 = base2->in(MemNode::Address);
         const TypeKlassPtr* tkls = phase->type(adr2)->isa_klassptr();
         if (tkls != NULL && !tkls->empty()
--- a/src/hotspot/share/opto/phaseX.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/opto/phaseX.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1628,8 +1628,11 @@
       Node* imem = use->as_Initialize()->proj_out_or_null(TypeFunc::Memory);
       if (imem != NULL)  add_users_to_worklist0(imem);
     }
-    // Loading the java mirror from a klass oop requires two loads and the type
+    // Loading the java mirror from a Klass requires two loads and the type
     // of the mirror load depends on the type of 'n'. See LoadNode::Value().
+    // If the code pattern requires a barrier for
+    //   mirror = ((OopHandle)mirror)->resolve();
+    // this won't match.
     if (use_op == Op_LoadP && use->bottom_type()->isa_rawptr()) {
       for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
         Node* u = use->fast_out(i2);
@@ -1774,8 +1777,11 @@
             worklist.push(phi);
           }
         }
-        // Loading the java mirror from a klass oop requires two loads and the type
+        // Loading the java mirror from a Klass requires two loads and the type
         // of the mirror load depends on the type of 'n'. See LoadNode::Value().
+        // If the code pattern requires a barrier for
+        //   mirror = ((OopHandle)mirror)->resolve();
+        // this won't match.
         if (m_op == Op_LoadP && m->bottom_type()->isa_rawptr()) {
           for (DUIterator_Fast i2max, i2 = m->fast_outs(i2max); i2 < i2max; i2++) {
             Node* u = m->fast_out(i2);
--- a/src/hotspot/share/opto/subnode.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/opto/subnode.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -886,7 +886,7 @@
   if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL;
 
   Node* adr = n->in(MemNode::Address);
-  // First load from OopHandle
+  // First load from OopHandle: ((OopHandle)mirror)->resolve(); may need barrier.
   if (adr->Opcode() != Op_LoadP || !phase->type(adr)->isa_rawptr()) return NULL;
   adr = adr->in(MemNode::Address);
 
--- a/src/hotspot/share/prims/jvmtiEnvBase.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/prims/jvmtiEnvBase.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -29,6 +29,7 @@
 #include "oops/objArrayKlass.hpp"
 #include "oops/objArrayOop.hpp"
 #include "oops/oop.inline.hpp"
+#include "oops/oopHandle.inline.hpp"
 #include "prims/jvmtiEnvBase.hpp"
 #include "prims/jvmtiEventController.inline.hpp"
 #include "prims/jvmtiExtensions.hpp"
@@ -1478,6 +1479,13 @@
 
 GrowableArray<OopHandle>* JvmtiModuleClosure::_tbl = NULL;
 
+void JvmtiModuleClosure::do_module(ModuleEntry* entry) {
+  assert_locked_or_safepoint(Module_lock);
+  OopHandle module = entry->module_handle();
+  guarantee(module.resolve() != NULL, "module object is NULL");
+  _tbl->push(module);
+}
+
 jvmtiError
 JvmtiModuleClosure::get_all_modules(JvmtiEnv* env, jint* module_count_ptr, jobject** modules_ptr) {
   ResourceMark rm;
--- a/src/hotspot/share/prims/jvmtiEnvBase.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/prims/jvmtiEnvBase.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -639,13 +639,7 @@
 private:
   static GrowableArray<OopHandle> *_tbl; // Protected with Module_lock
 
-  static void do_module(ModuleEntry* entry) {
-    assert_locked_or_safepoint(Module_lock);
-    OopHandle module = entry->module_handle();
-    guarantee(module.resolve() != NULL, "module object is NULL");
-    _tbl->push(module);
-  }
-
+  static void do_module(ModuleEntry* entry);
 public:
   jvmtiError get_all_modules(JvmtiEnv* env, jint* module_count_ptr, jobject** modules_ptr);
 };
--- a/src/hotspot/share/prims/jvmtiGetLoadedClasses.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/prims/jvmtiGetLoadedClasses.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "classfile/classLoaderData.inline.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "gc/shared/collectedHeap.hpp"
 #include "memory/universe.hpp"
--- a/src/hotspot/share/prims/resolvedMethodTable.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/prims/resolvedMethodTable.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -30,6 +30,7 @@
 #include "oops/oop.inline.hpp"
 #include "oops/method.hpp"
 #include "oops/symbol.hpp"
+#include "oops/weakHandle.inline.hpp"
 #include "prims/resolvedMethodTable.hpp"
 #include "runtime/handles.inline.hpp"
 #include "runtime/mutexLocker.hpp"
@@ -39,7 +40,7 @@
 
 
 oop ResolvedMethodEntry::object() {
-  return RootAccess<ON_PHANTOM_OOP_REF>::oop_load(literal_addr());
+  return literal().resolve();
 }
 
 oop ResolvedMethodEntry::object_no_keepalive() {
@@ -48,11 +49,11 @@
   // not leak out past a thread transition where a safepoint can happen.
   // A subsequent oop_load without AS_NO_KEEPALIVE (the object() accessor)
   // keeps the oop alive before doing so.
-  return RootAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(literal_addr());
+  return literal().peek();
 }
 
 ResolvedMethodTable::ResolvedMethodTable()
-  : Hashtable<oop, mtClass>(_table_size, sizeof(ResolvedMethodEntry)) { }
+  : Hashtable<ClassLoaderWeakHandle, mtClass>(_table_size, sizeof(ResolvedMethodEntry)) { }
 
 oop ResolvedMethodTable::lookup(int index, unsigned int hash, Method* method) {
   for (ResolvedMethodEntry* p = bucket(index); p != NULL; p = p->next()) {
@@ -62,7 +63,7 @@
       oop target = p->object_no_keepalive();
 
       // The method is in the table as a target already
-      if (java_lang_invoke_ResolvedMethodName::vmtarget(target) == method) {
+      if (target != NULL && java_lang_invoke_ResolvedMethodName::vmtarget(target) == method) {
         ResourceMark rm;
         log_debug(membername, table) ("ResolvedMethod entry found for %s index %d",
                                        method->name_and_sig_as_C_string(), index);
@@ -88,7 +89,7 @@
   return lookup(index, hash, method);
 }
 
-oop ResolvedMethodTable::basic_add(Method* method, oop rmethod_name) {
+oop ResolvedMethodTable::basic_add(Method* method, Handle rmethod_name) {
   assert_locked_or_safepoint(ResolvedMethodTable_lock);
 
   unsigned int hash = compute_hash(method);
@@ -100,12 +101,13 @@
     return entry;
   }
 
-  ResolvedMethodEntry* p = (ResolvedMethodEntry*) Hashtable<oop, mtClass>::new_entry(hash, rmethod_name);
-  Hashtable<oop, mtClass>::add_entry(index, p);
+  ClassLoaderWeakHandle w = ClassLoaderWeakHandle::create(rmethod_name);
+  ResolvedMethodEntry* p = (ResolvedMethodEntry*) Hashtable<ClassLoaderWeakHandle, mtClass>::new_entry(hash, w);
+  Hashtable<ClassLoaderWeakHandle, mtClass>::add_entry(index, p);
   ResourceMark rm;
   log_debug(membername, table) ("ResolvedMethod entry added for %s index %d",
                                  method->name_and_sig_as_C_string(), index);
-  return rmethod_name;
+  return rmethod_name();
 }
 
 ResolvedMethodTable* ResolvedMethodTable::_the_table = NULL;
@@ -134,7 +136,7 @@
   // have any membernames in the table.
   method->method_holder()->set_has_resolved_methods();
 
-  return _the_table->basic_add(method, resolved_method_name());
+  return _the_table->basic_add(method, resolved_method_name);
 }
 
 // Removing entries
@@ -143,7 +145,7 @@
 
 // Serially invoke removed unused oops from the table.
 // This is done late during GC.
-void ResolvedMethodTable::unlink(BoolObjectClosure* is_alive) {
+void ResolvedMethodTable::unlink() {
   _oops_removed = 0;
   _oops_counted = 0;
   for (int i = 0; i < _the_table->table_size(); ++i) {
@@ -151,38 +153,27 @@
     ResolvedMethodEntry* entry = _the_table->bucket(i);
     while (entry != NULL) {
       _oops_counted++;
-      if (is_alive->do_object_b(entry->object_no_keepalive())) {
+      oop l = entry->object_no_keepalive();
+      if (l != NULL) {
         p = entry->next_addr();
       } else {
+        // Entry has been removed.
         _oops_removed++;
         if (log_is_enabled(Debug, membername, table)) {
-          Method* m = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(entry->object_no_keepalive());
-          ResourceMark rm;
-          log_debug(membername, table) ("ResolvedMethod entry removed for %s index %d",
-                                           m->name_and_sig_as_C_string(), i);
+          log_debug(membername, table) ("ResolvedMethod entry removed for index %d", i);
         }
+        entry->literal().release();
         *p = entry->next();
         _the_table->free_entry(entry);
       }
       // get next entry
-      entry = (ResolvedMethodEntry*)HashtableEntry<oop, mtClass>::make_ptr(*p);
+      entry = (ResolvedMethodEntry*)HashtableEntry<ClassLoaderWeakHandle, mtClass>::make_ptr(*p);
     }
   }
   log_debug(membername, table) ("ResolvedMethod entries counted %d removed %d",
                                 _oops_counted, _oops_removed);
 }
 
-// Serially invoke "f->do_oop" on the locations of all oops in the table.
-void ResolvedMethodTable::oops_do(OopClosure* f) {
-  for (int i = 0; i < _the_table->table_size(); ++i) {
-    ResolvedMethodEntry* entry = _the_table->bucket(i);
-    while (entry != NULL) {
-      f->do_oop(entry->literal_addr());
-      entry = entry->next();
-    }
-  }
-}
-
 #ifndef PRODUCT
 void ResolvedMethodTable::print() {
   for (int i = 0; i < table_size(); ++i) {
@@ -190,9 +181,11 @@
     while (entry != NULL) {
       tty->print("%d : ", i);
       oop rmethod_name = entry->object_no_keepalive();
-      rmethod_name->print();
-      Method* m = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(rmethod_name);
-      m->print();
+      if (rmethod_name != NULL) {
+        rmethod_name->print();
+        Method* m = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(rmethod_name);
+        m->print();
+      }
       entry = entry->next();
     }
   }
@@ -205,9 +198,15 @@
   assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
   // For each entry in RMT, change to new method
   for (int i = 0; i < _the_table->table_size(); ++i) {
-    ResolvedMethodEntry* entry = _the_table->bucket(i);
-    while (entry != NULL) {
+    for (ResolvedMethodEntry* entry = _the_table->bucket(i);
+         entry != NULL;
+         entry = entry->next()) {
+
       oop mem_name = entry->object_no_keepalive();
+      // except ones removed
+      if (mem_name == NULL) {
+        continue;
+      }
       Method* old_method = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(mem_name);
 
       if (old_method->is_old()) {
@@ -235,7 +234,6 @@
           ("ResolvedMethod method update: %s(%s)",
            new_method->name()->as_C_string(), new_method->signature()->as_C_string());
       }
-      entry = entry->next();
     }
   }
 }
--- a/src/hotspot/share/prims/resolvedMethodTable.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/prims/resolvedMethodTable.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,22 +26,23 @@
 #define SHARE_VM_PRIMS_RESOLVEDMETHOD_HPP
 
 #include "oops/symbol.hpp"
+#include "oops/weakHandle.hpp"
 #include "utilities/hashtable.hpp"
 
 // Hashtable to record Method* used in ResolvedMethods, via. ResolvedMethod oops.
 // This is needed for redefinition to replace Method* with redefined versions.
 
-// Entry in a ResolvedMethodTable, mapping a single oop of java_lang_invoke_ResolvedMethodName which
-// holds JVM Method* in vmtarget.
+// Entry in a ResolvedMethodTable, mapping a ClassLoaderWeakHandle for a single oop of
+// java_lang_invoke_ResolvedMethodName which holds JVM Method* in vmtarget.
 
-class ResolvedMethodEntry : public HashtableEntry<oop, mtClass> {
+class ResolvedMethodEntry : public HashtableEntry<ClassLoaderWeakHandle, mtClass> {
  public:
   ResolvedMethodEntry* next() const {
-    return (ResolvedMethodEntry*)HashtableEntry<oop, mtClass>::next();
+    return (ResolvedMethodEntry*)HashtableEntry<ClassLoaderWeakHandle, mtClass>::next();
   }
 
   ResolvedMethodEntry** next_addr() {
-    return (ResolvedMethodEntry**)HashtableEntry<oop, mtClass>::next_addr();
+    return (ResolvedMethodEntry**)HashtableEntry<ClassLoaderWeakHandle, mtClass>::next_addr();
   }
 
   oop object();
@@ -50,7 +51,7 @@
   void print_on(outputStream* st) const;
 };
 
-class ResolvedMethodTable : public Hashtable<oop, mtClass> {
+class ResolvedMethodTable : public Hashtable<ClassLoaderWeakHandle, mtClass> {
   enum Constants {
     _table_size  = 1007
   };
@@ -61,11 +62,11 @@
   static ResolvedMethodTable* _the_table;
 private:
   ResolvedMethodEntry* bucket(int i) {
-    return (ResolvedMethodEntry*) Hashtable<oop, mtClass>::bucket(i);
+    return (ResolvedMethodEntry*) Hashtable<ClassLoaderWeakHandle, mtClass>::bucket(i);
   }
 
   ResolvedMethodEntry** bucket_addr(int i) {
-    return (ResolvedMethodEntry**) Hashtable<oop, mtClass>::bucket_addr(i);
+    return (ResolvedMethodEntry**) Hashtable<ClassLoaderWeakHandle, mtClass>::bucket_addr(i);
   }
 
   unsigned int compute_hash(Method* method);
@@ -75,7 +76,7 @@
   oop lookup(Method* method);
 
   // must be done under ResolvedMethodTable_lock
-  oop basic_add(Method* method, oop rmethod_name);
+  oop basic_add(Method* method, Handle rmethod_name);
 
 public:
   ResolvedMethodTable();
@@ -95,8 +96,7 @@
 #endif // INCLUDE_JVMTI
 
   // Cleanup cleared entries
-  static void unlink(BoolObjectClosure* is_alive);
-  static void oops_do(OopClosure* f);
+  static void unlink();
 
 #ifndef PRODUCT
   void print();
--- a/src/hotspot/share/prims/whitebox.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/prims/whitebox.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -933,8 +933,6 @@
   return result;
 WB_END
 
-static AlwaysFalseClosure always_false;
-
 WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method))
   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
   CHECK_JNI_EXCEPTION(env);
@@ -951,7 +949,7 @@
       mdo->set_arg_modified(i, 0);
     }
     MutexLockerEx mu(mdo->extra_data_lock());
-    mdo->clean_method_data(&always_false);
+    mdo->clean_method_data(/*always_clean*/true);
   }
 
   mh->clear_not_c1_compilable();
--- a/src/hotspot/share/runtime/javaFrameAnchor.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/runtime/javaFrameAnchor.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -25,6 +25,7 @@
 #ifndef SHARE_VM_RUNTIME_JAVAFRAMEANCHOR_HPP
 #define SHARE_VM_RUNTIME_JAVAFRAMEANCHOR_HPP
 
+#include "runtime/orderAccess.hpp"
 #include "utilities/globalDefinitions.hpp"
 #include "utilities/macros.hpp"
 
--- a/src/hotspot/share/runtime/mutex.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/runtime/mutex.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -106,7 +106,8 @@
        access         = event          +   1,
        special        = access         +   2,
        suspend_resume = special        +   1,
-       leaf           = suspend_resume +   2,
+       vmweak         = suspend_resume +   2,
+       leaf           = vmweak         +   2,
        safepoint      = leaf           +  10,
        barrier        = safepoint      +   1,
        nonleaf        = barrier        +   1,
--- a/src/hotspot/share/runtime/mutexLocker.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/runtime/mutexLocker.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -182,6 +182,9 @@
   def(CGC_lock                     , PaddedMonitor, special,     true,  Monitor::_safepoint_check_never);      // coordinate between fore- and background GC
   def(STS_lock                     , PaddedMonitor, leaf,        true,  Monitor::_safepoint_check_never);
 
+  def(VMWeakAlloc_lock             , PaddedMutex  , vmweak,      true,  Monitor::_safepoint_check_never);
+  def(VMWeakActive_lock            , PaddedMutex  , vmweak-1,    true,  Monitor::_safepoint_check_never);
+
   if (UseConcMarkSweepGC || UseG1GC) {
     def(FullGCCount_lock           , PaddedMonitor, leaf,        true,  Monitor::_safepoint_check_never);      // in support of ExplicitGCInvokesConcurrent
   }
@@ -262,8 +265,6 @@
   def(JNIGlobalActive_lock         , PaddedMutex  , nonleaf-1,   true,  Monitor::_safepoint_check_never);
   def(JNIWeakAlloc_lock            , PaddedMutex  , nonleaf,     true,  Monitor::_safepoint_check_never);
   def(JNIWeakActive_lock           , PaddedMutex  , nonleaf-1,   true,  Monitor::_safepoint_check_never);
-  def(VMWeakAlloc_lock             , PaddedMutex  , nonleaf,     true,  Monitor::_safepoint_check_never);
-  def(VMWeakActive_lock            , PaddedMutex  , nonleaf-1,   true,  Monitor::_safepoint_check_never);
   def(JNICritical_lock             , PaddedMonitor, nonleaf,     true,  Monitor::_safepoint_check_always);     // used for JNI critical regions
   def(AdapterHandlerLibrary_lock   , PaddedMutex  , nonleaf,     true,  Monitor::_safepoint_check_always);
 
--- a/src/hotspot/share/runtime/safepoint.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/runtime/safepoint.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -28,6 +28,7 @@
 #include "asm/assembler.hpp"
 #include "code/nmethod.hpp"
 #include "memory/allocation.hpp"
+#include "runtime/atomic.hpp"
 #include "runtime/extendedPC.hpp"
 #include "runtime/mutexLocker.hpp"
 #include "runtime/os.hpp"
--- a/src/hotspot/share/runtime/vmStructs.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/runtime/vmStructs.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -543,7 +543,7 @@
   /*******************/                                                                                                              \
   /* ClassLoaderData */                                                                                                              \
   /*******************/                                                                                                              \
-  nonstatic_field(ClassLoaderData,             _class_loader,                                 oop)                                   \
+  nonstatic_field(ClassLoaderData,             _class_loader,                                 OopHandle)                             \
   nonstatic_field(ClassLoaderData,             _next,                                         ClassLoaderData*)                      \
   volatile_nonstatic_field(ClassLoaderData,    _klasses,                                      Klass*)                                \
   nonstatic_field(ClassLoaderData,             _is_anonymous,                                 bool)                                  \
--- a/src/hotspot/share/services/classLoadingService.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/services/classLoadingService.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -53,7 +53,7 @@
       len = name->utf8_length();                    \
     }                                               \
     HOTSPOT_CLASS_##type( /* type = unloaded, loaded */ \
-      data, len, (void*)(clss)->class_loader(), (shared)); \
+      data, len, (void*)(clss)->class_loader_data(), (shared)); \
   }
 
 #else //  ndef DTRACE_ENABLED
--- a/src/hotspot/share/services/diagnosticCommand.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/services/diagnosticCommand.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -931,7 +931,7 @@
 //---<  BEGIN  >--- CodeHeap State Analytics.
 CodeHeapAnalyticsDCmd::CodeHeapAnalyticsDCmd(outputStream* output, bool heap) :
                                              DCmdWithParser(output, heap),
-  _function("function", "Function to be performed (aggregate, UsedSpace, FreeSpace, MethodCount, MethodSpace, MethodAge, discard", "STRING", false, "all"),
+  _function("function", "Function to be performed (aggregate, UsedSpace, FreeSpace, MethodCount, MethodSpace, MethodAge, MethodNames, discard", "STRING", false, "all"),
   _granularity("granularity", "Detail level - smaller value -> more detail", "STRING", false, "4096") {
   _dcmdparser.add_dcmd_argument(&_function);
   _dcmdparser.add_dcmd_argument(&_granularity);
--- a/src/hotspot/share/trace/traceStream.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/trace/traceStream.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
 #include "precompiled.hpp"
 #include "trace/traceStream.hpp"
 #if INCLUDE_TRACE
-#include "classfile/classLoaderData.hpp"
+#include "classfile/classLoaderData.inline.hpp"
 #include "classfile/javaClasses.inline.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/klass.hpp"
--- a/src/hotspot/share/utilities/bitMap.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/utilities/bitMap.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -72,7 +72,7 @@
 };
 
 template <class Allocator>
-BitMap::bm_word_t* BitMap::reallocate(const Allocator& allocator, bm_word_t* old_map, idx_t old_size_in_bits, idx_t new_size_in_bits) {
+BitMap::bm_word_t* BitMap::reallocate(const Allocator& allocator, bm_word_t* old_map, idx_t old_size_in_bits, idx_t new_size_in_bits, bool clear) {
   size_t old_size_in_words = calc_size_in_words(old_size_in_bits);
   size_t new_size_in_words = calc_size_in_words(new_size_in_bits);
 
@@ -86,7 +86,7 @@
                            MIN2(old_size_in_words, new_size_in_words));
     }
 
-    if (new_size_in_words > old_size_in_words) {
+    if (clear && new_size_in_words > old_size_in_words) {
       clear_range_of_words(map, old_size_in_words, new_size_in_words);
     }
   }
@@ -99,9 +99,9 @@
 }
 
 template <class Allocator>
-bm_word_t* BitMap::allocate(const Allocator& allocator, idx_t size_in_bits) {
+bm_word_t* BitMap::allocate(const Allocator& allocator, idx_t size_in_bits, bool clear) {
   // Reuse reallocate to ensure that the new memory is cleared.
-  return reallocate(allocator, NULL, 0, size_in_bits);
+  return reallocate(allocator, NULL, 0, size_in_bits, clear);
 }
 
 template <class Allocator>
@@ -153,8 +153,8 @@
     : BitMap(allocate(ArenaBitMapAllocator(arena), size_in_bits), size_in_bits) {
 }
 
-CHeapBitMap::CHeapBitMap(idx_t size_in_bits, MEMFLAGS flags)
-    : BitMap(allocate(CHeapBitMapAllocator(flags), size_in_bits), size_in_bits), _flags(flags) {
+CHeapBitMap::CHeapBitMap(idx_t size_in_bits, MEMFLAGS flags, bool clear)
+    : BitMap(allocate(CHeapBitMapAllocator(flags), size_in_bits, clear), size_in_bits), _flags(flags) {
 }
 
 CHeapBitMap::~CHeapBitMap() {
--- a/src/hotspot/share/utilities/bitMap.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/utilities/bitMap.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -123,11 +123,11 @@
 
   // Allocates and clears the bitmap memory.
   template <class Allocator>
-  static bm_word_t* allocate(const Allocator&, idx_t size_in_bits);
+  static bm_word_t* allocate(const Allocator&, idx_t size_in_bits, bool clear = true);
 
   // Reallocates and clears the new bitmap memory.
   template <class Allocator>
-  static bm_word_t* reallocate(const Allocator&, bm_word_t* map, idx_t old_size_in_bits, idx_t new_size_in_bits);
+  static bm_word_t* reallocate(const Allocator&, bm_word_t* map, idx_t old_size_in_bits, idx_t new_size_in_bits, bool clear = true);
 
   // Free the bitmap memory.
   template <class Allocator>
@@ -359,7 +359,7 @@
  public:
   CHeapBitMap(MEMFLAGS flags = mtInternal) : BitMap(NULL, 0), _flags(flags) {}
   // Clears the bitmap memory.
-  CHeapBitMap(idx_t size_in_bits, MEMFLAGS flags = mtInternal);
+  CHeapBitMap(idx_t size_in_bits, MEMFLAGS flags = mtInternal, bool clear = true);
   ~CHeapBitMap();
 
   // Resize the backing bitmap memory.
--- a/src/hotspot/share/utilities/globalCounter.inline.hpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/utilities/globalCounter.inline.hpp	Thu Apr 19 14:17:54 2018 +0200
@@ -26,7 +26,7 @@
 #define SHARE_UTILITIES_GLOBAL_COUNTER_INLINE_HPP
 
 #include "runtime/orderAccess.inline.hpp"
-#include "runtime/thread.hpp"
+#include "runtime/thread.inline.hpp"
 #include "utilities/globalCounter.hpp"
 
 inline void GlobalCounter::critical_section_begin(Thread *thread) {
--- a/src/hotspot/share/utilities/hashtable.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/hotspot/share/utilities/hashtable.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,6 +35,7 @@
 #include "memory/metaspaceShared.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/oop.inline.hpp"
+#include "oops/weakHandle.inline.hpp"
 #include "runtime/safepoint.hpp"
 #include "utilities/dtrace.hpp"
 #include "utilities/hashtable.hpp"
@@ -148,7 +149,6 @@
   }
   // give the new table the free list as well
   new_table->copy_freelist(this);
-  assert(new_table->number_of_entries() == saved_entry_count, "lost entry on dictionary copy?");
 
   // Destroy memory used by the buckets in the hashtable.  The memory
   // for the elements has been used in a new table and is not
@@ -263,6 +263,10 @@
   }
 }
 
+static int literal_size(ClassLoaderWeakHandle v) {
+  return literal_size(v.peek());
+}
+
 template <MEMFLAGS F> bool BasicHashtable<F>::resize(int new_size) {
   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 
@@ -382,6 +386,13 @@
 }
 
 #ifndef PRODUCT
+template <class T> void print_literal(T l) {
+  l->print();
+}
+
+static void print_literal(ClassLoaderWeakHandle l) {
+  l.print();
+}
 
 template <class T, MEMFLAGS F> void Hashtable<T, F>::print() {
   ResourceMark rm;
@@ -390,7 +401,7 @@
     HashtableEntry<T, F>* entry = bucket(i);
     while(entry != NULL) {
       tty->print("%d : ", i);
-      entry->literal()->print();
+      print_literal(entry->literal());
       tty->cr();
       entry = entry->next();
     }
@@ -443,21 +454,19 @@
 #endif
 template class Hashtable<ConstantPool*, mtClass>;
 template class RehashableHashtable<Symbol*, mtSymbol>;
-template class RehashableHashtable<oopDesc*, mtSymbol>;
+template class RehashableHashtable<oop, mtSymbol>;
 template class Hashtable<Symbol*, mtSymbol>;
 template class Hashtable<Klass*, mtClass>;
 template class Hashtable<InstanceKlass*, mtClass>;
-template class Hashtable<oop, mtClass>;
+template class Hashtable<ClassLoaderWeakHandle, mtClass>;
 template class Hashtable<Symbol*, mtModule>;
-#if defined(SOLARIS) || defined(CHECK_UNHANDLED_OOPS)
 template class Hashtable<oop, mtSymbol>;
-template class RehashableHashtable<oop, mtSymbol>;
-#endif // SOLARIS || CHECK_UNHANDLED_OOPS
-template class Hashtable<oopDesc*, mtSymbol>;
+template class Hashtable<ClassLoaderWeakHandle, mtSymbol>;
 template class Hashtable<Symbol*, mtClass>;
 template class HashtableEntry<Symbol*, mtSymbol>;
 template class HashtableEntry<Symbol*, mtClass>;
 template class HashtableEntry<oop, mtSymbol>;
+template class HashtableEntry<ClassLoaderWeakHandle, mtSymbol>;
 template class HashtableBucket<mtClass>;
 template class BasicHashtableEntry<mtSymbol>;
 template class BasicHashtableEntry<mtCode>;
--- a/src/java.base/share/classes/java/util/Optional.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/java.base/share/classes/java/util/Optional.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -160,6 +160,17 @@
     }
 
     /**
+     * If a value is  not present, returns {@code true}, otherwise
+     * {@code false}.
+     *
+     * @return  {@code true} if a value is not present, otherwise {@code false}
+     * @since   11
+     */
+    public boolean isEmpty() {
+        return value == null;
+    }
+
+    /**
      * If a value is present, performs the given action with the value,
      * otherwise does nothing.
      *
--- a/src/java.base/share/classes/java/util/OptionalDouble.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/java.base/share/classes/java/util/OptionalDouble.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -140,6 +140,17 @@
     }
 
     /**
+     * If a value is not present, returns {@code true}, otherwise
+     * {@code false}.
+     *
+     * @return  {@code true} if a value is not present, otherwise {@code false}
+     * @since   11
+     */
+    public boolean isEmpty() {
+        return !isPresent;
+    }
+
+    /**
      * If a value is present, performs the given action with the value,
      * otherwise does nothing.
      *
--- a/src/java.base/share/classes/java/util/OptionalInt.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/java.base/share/classes/java/util/OptionalInt.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -140,6 +140,17 @@
     }
 
     /**
+     * If a value is not present, returns {@code true}, otherwise
+     * {@code false}.
+     *
+     * @return  {@code true} if a value is not present, otherwise {@code false}
+     * @since   11
+     */
+    public boolean isEmpty() {
+        return !isPresent;
+    }
+
+    /**
      * If a value is present, performs the given action with the value,
      * otherwise does nothing.
      *
--- a/src/java.base/share/classes/java/util/OptionalLong.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/java.base/share/classes/java/util/OptionalLong.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -140,6 +140,17 @@
     }
 
     /**
+     * If a value is not present, returns {@code true}, otherwise
+     * {@code false}.
+     *
+     * @return  {@code true} if a value is not present, otherwise {@code false}
+     * @since   11
+     */
+    public boolean isEmpty() {
+        return !isPresent;
+    }
+
+    /**
      * If a value is present, performs the given action with the value,
      * otherwise does nothing.
      *
--- a/src/java.base/share/classes/sun/launcher/resources/launcher.properties	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/java.base/share/classes/sun/launcher/resources/launcher.properties	Thu Apr 19 14:17:54 2018 +0200
@@ -113,6 +113,8 @@
 \                  one or more argument files containing options\n\
 \    -disable-@files\n\
 \                  prevent further argument file expansion\n\
+\    --enable-preview\n\
+\                  allow classes to depend on preview features of this release
 \To specify an argument for a long option, you can use --<name>=<value> or\n\
 \--<name> <value>.\n
 
--- a/src/java.base/unix/native/libnet/Inet4AddressImpl.c	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/java.base/unix/native/libnet/Inet4AddressImpl.c	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -68,6 +68,7 @@
     hostname[0] = '\0';
     if (gethostname(hostname, NI_MAXHOST) != 0) {
         strcpy(hostname, "localhost");
+#if defined(__solaris__)
     } else {
         // try to resolve hostname via nameservice
         // if it is known but getnameinfo fails, hostname will still be the
@@ -86,6 +87,12 @@
             freeaddrinfo(res);
         }
     }
+#else
+    } else {
+        // make sure string is null-terminated
+        hostname[NI_MAXHOST] = '\0';
+    }
+#endif
     return (*env)->NewStringUTF(env, hostname);
 }
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -172,7 +172,7 @@
             if (compiler == null || compiler.errorCount() == 0
                     || Options.instance(context).isSet("dev")) {
                 Log log = Log.instance(context);
-                log.printLines(PrefixKind.JAVAC, "msg.bug", JavaCompiler.version());
+                log.printLines("msg.bug", JavaCompiler.version());
                 ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
             }
             return abnormalErrorResult;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java	Thu Apr 19 14:17:54 2018 +0200
@@ -54,7 +54,6 @@
 import com.sun.tools.doclint.DocLint;
 import com.sun.tools.javac.code.Lint.LintCategory;
 import com.sun.tools.javac.code.Source;
-import com.sun.tools.javac.code.Source.Feature;
 import com.sun.tools.javac.file.BaseFileManager;
 import com.sun.tools.javac.file.JavacFileManager;
 import com.sun.tools.javac.jvm.Profile;
@@ -66,6 +65,7 @@
 import com.sun.tools.javac.resources.CompilerProperties.Warnings;
 import com.sun.tools.javac.util.Context;
 import com.sun.tools.javac.util.JCDiagnostic;
+import com.sun.tools.javac.util.JCDiagnostic.DiagnosticInfo;
 import com.sun.tools.javac.util.List;
 import com.sun.tools.javac.util.ListBuffer;
 import com.sun.tools.javac.util.Log;
@@ -295,7 +295,7 @@
         String platformString = options.get(Option.RELEASE);
 
         checkOptionAllowed(platformString == null,
-                option -> error("err.release.bootclasspath.conflict", option.getPrimaryName()),
+                option -> reportDiag(Errors.ReleaseBootclasspathConflict(option)),
                 Option.BOOT_CLASS_PATH, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND,
                 Option.XBOOTCLASSPATH_PREPEND,
                 Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
@@ -308,7 +308,7 @@
                     PlatformUtils.lookupPlatformDescription(platformString);
 
             if (platformDescription == null) {
-                error("err.unsupported.release.version", platformString);
+                reportDiag(Errors.UnsupportedReleaseVersion(platformString));
                 return false;
             }
 
@@ -363,7 +363,7 @@
         while (argIter.hasNext()) {
             String arg = argIter.next();
             if (arg.isEmpty()) {
-                error("err.invalid.flag", arg);
+                reportDiag(Errors.InvalidFlag(arg));
                 return false;
             }
 
@@ -392,7 +392,7 @@
             }
 
             // none of the above
-            error("err.invalid.flag", arg);
+            reportDiag(Errors.InvalidFlag(arg));
             return false;
         }
 
@@ -457,9 +457,9 @@
             if (!emptyAllowed) {
                 if (!errors) {
                     if (JavaCompiler.explicitAnnotationProcessingRequested(options)) {
-                        error("err.no.source.files.classes");
+                        reportDiag(Errors.NoSourceFilesClasses);
                     } else {
-                        error("err.no.source.files");
+                        reportDiag(Errors.NoSourceFiles);
                     }
                 }
                 return false;
@@ -520,13 +520,9 @@
             if (target.compareTo(source.requiredTarget()) < 0) {
                 if (targetString != null) {
                     if (sourceString == null) {
-                        error("warn.target.default.source.conflict",
-                                targetString,
-                                source.requiredTarget().name);
+                        reportDiag(Warnings.TargetDefaultSourceConflict(targetString, source.requiredTarget()));
                     } else {
-                        error("warn.source.target.conflict",
-                                sourceString,
-                                source.requiredTarget().name);
+                        reportDiag(Warnings.SourceTargetConflict(sourceString, source.requiredTarget()));
                     }
                     return false;
                 } else {
@@ -539,13 +535,11 @@
         if (options.isSet(Option.PREVIEW)) {
             if (sourceString == null) {
                 //enable-preview must be used with explicit -source or --release
-                error("err.preview.without.source.or.release");
+                report(Errors.PreviewWithoutSourceOrRelease);
                 return false;
             } else if (source != Source.DEFAULT) {
                 //enable-preview must be used with latest source version
-                error("err.preview.not.latest",
-                        sourceString,
-                        Source.DEFAULT.name);
+                report(Errors.PreviewNotLatest(sourceString, Source.DEFAULT));
                 return false;
             }
         }
@@ -554,18 +548,18 @@
         if (profileString != null) {
             Profile profile = Profile.lookup(profileString);
             if (!profile.isValid(target)) {
-                error("warn.profile.target.conflict", profileString, target.name);
+                reportDiag(Warnings.ProfileTargetConflict(profile, target));
             }
 
             // This check is only effective in command line mode,
             // where the file manager options are added to options
             if (options.get(Option.BOOT_CLASS_PATH) != null) {
-                error("err.profile.bootclasspath.conflict");
+                reportDiag(Errors.ProfileBootclasspathConflict);
             }
         }
 
         if (options.isSet(Option.SOURCE_PATH) && options.isSet(Option.MODULE_SOURCE_PATH)) {
-            error("err.sourcepath.modulesourcepath.conflict");
+            reportDiag(Errors.SourcepathModulesourcepathConflict);
         }
 
         boolean lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option);
@@ -586,15 +580,15 @@
         }
 
         if (target.compareTo(Target.MIN) < 0) {
-            log.error(Errors.OptionRemovedTarget(target.name, Target.MIN.name));
+            log.error(Errors.OptionRemovedTarget(target, Target.MIN));
         } else if (target == Target.MIN && lintOptions) {
-            log.warning(LintCategory.OPTIONS, Warnings.OptionObsoleteTarget(target.name));
+            log.warning(LintCategory.OPTIONS, Warnings.OptionObsoleteTarget(target));
             obsoleteOptionFound = true;
         }
 
         final Target t = target;
         checkOptionAllowed(t.compareTo(Target.JDK1_8) <= 0,
-                option -> error("err.option.not.allowed.with.target", option.getPrimaryName(), t.name),
+                option -> reportDiag(Errors.OptionNotAllowedWithTarget(option, t)),
                 Option.BOOT_CLASS_PATH,
                 Option.XBOOTCLASSPATH_PREPEND, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND,
                 Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
@@ -602,7 +596,7 @@
                 Option.PROFILE);
 
         checkOptionAllowed(t.compareTo(Target.JDK1_9) >= 0,
-                option -> error("err.option.not.allowed.with.target", option.getPrimaryName(), t.name),
+                option -> reportDiag(Errors.OptionNotAllowedWithTarget(option, t)),
                 Option.MODULE_SOURCE_PATH, Option.UPGRADE_MODULE_PATH,
                 Option.SYSTEM, Option.MODULE_PATH, Option.ADD_MODULES,
                 Option.ADD_EXPORTS, Option.ADD_OPENS, Option.ADD_READS,
@@ -610,7 +604,7 @@
                 Option.PATCH_MODULE);
 
         if (lintOptions && options.isSet(Option.PARAMETERS) && !target.hasMethodParameters()) {
-            log.warning(Warnings.OptionParametersUnsupported(target.name, Target.JDK1_8.name));
+            log.warning(Warnings.OptionParametersUnsupported(target, Target.JDK1_8));
         }
 
         if (fm.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) {
@@ -871,7 +865,7 @@
         }
         Path file = Paths.get(value);
         if (Files.exists(file) && !Files.isDirectory(file)) {
-            error("err.file.not.directory", value);
+            reportDiag(Errors.FileNotDirectory(value));
             return false;
         }
         return true;
@@ -889,35 +883,19 @@
         }
     }
 
-    void error(JCDiagnostic.Error error) {
+    void reportDiag(DiagnosticInfo diag) {
         errors = true;
         switch (errorMode) {
             case ILLEGAL_ARGUMENT: {
-                String msg = log.localize(error);
+                String msg = log.localize(diag);
                 throw new PropagatedException(new IllegalArgumentException(msg));
             }
             case ILLEGAL_STATE: {
-                String msg = log.localize(error);
+                String msg = log.localize(diag);
                 throw new PropagatedException(new IllegalStateException(msg));
             }
             case LOG:
-                report(error);
-        }
-    }
-
-    void error(String key, Object... args) {
-        errors = true;
-        switch (errorMode) {
-            case ILLEGAL_ARGUMENT: {
-                String msg = log.localize(PrefixKind.JAVAC, key, args);
-                throw new PropagatedException(new IllegalArgumentException(msg));
-            }
-            case ILLEGAL_STATE: {
-                String msg = log.localize(PrefixKind.JAVAC, key, args);
-                throw new PropagatedException(new IllegalStateException(msg));
-            }
-            case LOG:
-                report(key, args);
+                report(diag);
         }
     }
 
@@ -932,22 +910,17 @@
                 throw new PropagatedException(new IllegalStateException(msg, f.getCause()));
             }
             case LOG:
-                log.printRawLines(ownName + ": " + msg);
+                log.printRawLines(msg);
         }
     }
 
-    void warning(String key, Object... args) {
-        report(key, args);
-    }
-
-    private void report(String key, Object... args) {
+    private void report(DiagnosticInfo diag) {
         // Would be good to have support for -XDrawDiagnostics here
-        log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
-    }
-
-    private void report(JCDiagnostic.Error error) {
-        // Would be good to have support for -XDrawDiagnostics here
-        log.printRawLines(ownName + ": " + log.localize(error));
+        if (diag instanceof JCDiagnostic.Error) {
+            log.error((JCDiagnostic.Error)diag);
+        } else if (diag instanceof JCDiagnostic.Warning){
+            log.warning((JCDiagnostic.Warning)diag);
+        }
     }
 
     private JavaFileManager getFileManager() {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Main.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Main.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -49,7 +49,9 @@
 import com.sun.tools.javac.main.CommandLine.UnmatchedQuote;
 import com.sun.tools.javac.platform.PlatformDescription;
 import com.sun.tools.javac.processing.AnnotationProcessingError;
+import com.sun.tools.javac.resources.CompilerProperties.Errors;
 import com.sun.tools.javac.util.*;
+import com.sun.tools.javac.util.JCDiagnostic.DiagnosticInfo;
 import com.sun.tools.javac.util.Log.PrefixKind;
 import com.sun.tools.javac.util.Log.WriterKind;
 
@@ -138,19 +140,22 @@
 
     /** Report a usage error.
      */
-    void error(String key, Object... args) {
+    void reportDiag(DiagnosticInfo diag) {
         if (apiMode) {
-            String msg = log.localize(PrefixKind.JAVAC, key, args);
+            String msg = log.localize(diag);
             throw new PropagatedException(new IllegalStateException(msg));
         }
-        warning(key, args);
+        reportHelper(diag);
         log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
     }
 
-    /** Report a warning.
+    /** Report helper.
      */
-    void warning(String key, Object... args) {
-        log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
+    void reportHelper(DiagnosticInfo diag) {
+        String msg = log.localize(diag);
+        String errorPrefix = log.localize(Errors.Error);
+        msg = msg.startsWith(errorPrefix) ? msg : errorPrefix + msg;
+        log.printRawLines(msg);
     }
 
 
@@ -209,10 +214,10 @@
         try {
             argv = CommandLine.parse(ENV_OPT_NAME, argv);
         } catch (UnmatchedQuote ex) {
-            error("err.unmatched.quote", ex.variableName);
+            reportDiag(Errors.UnmatchedQuote(ex.variableName));
             return Result.CMDERR;
         } catch (FileNotFoundException | NoSuchFileException e) {
-            warning("err.file.not.found", e.getMessage());
+            reportHelper(Errors.FileNotFound(e.getMessage()));
             return Result.SYSERR;
         } catch (IOException ex) {
             log.printLines(PrefixKind.JAVAC, "msg.io");
@@ -366,11 +371,10 @@
                     CodeSource otherClassCodeSource = otherClass.getProtectionDomain().getCodeSource();
                     CodeSource javacCodeSource = this.getClass().getProtectionDomain().getCodeSource();
                     if (otherClassCodeSource != null && javacCodeSource != null) {
-                        log.printLines(PrefixKind.JAVAC, "err.two.class.loaders.2",
-                                otherClassCodeSource.getLocation(),
-                                javacCodeSource.getLocation());
+                        log.printLines(Errors.TwoClassLoaders2(otherClassCodeSource.getLocation(),
+                                javacCodeSource.getLocation()));
                     } else {
-                        log.printLines(PrefixKind.JAVAC, "err.two.class.loaders.1");
+                        log.printLines(Errors.TwoClassLoaders1);
                     }
                     return true;
                 }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java	Thu Apr 19 14:17:54 2018 +0200
@@ -59,6 +59,7 @@
 import com.sun.tools.javac.jvm.Target;
 import com.sun.tools.javac.platform.PlatformProvider;
 import com.sun.tools.javac.processing.JavacProcessingEnvironment;
+import com.sun.tools.javac.resources.CompilerProperties.Errors;
 import com.sun.tools.javac.util.Assert;
 import com.sun.tools.javac.util.Log;
 import com.sun.tools.javac.util.Log.PrefixKind;
@@ -197,7 +198,7 @@
         @Override
         public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
             if (arg.isEmpty()) {
-                throw helper.newInvalidValueException("err.no.value.for.option", option);
+                throw helper.newInvalidValueException(Errors.NoValueForOption(option));
             } else if (getPattern().matcher(arg).matches()) {
                 String prev = helper.get(PATCH_MODULE);
                 if (prev == null) {
@@ -209,13 +210,13 @@
                             .collect(Collectors.toSet())
                             .contains(argModulePackage);
                     if (isRepeated) {
-                        throw helper.newInvalidValueException("err.repeated.value.for.patch.module", argModulePackage);
+                        throw helper.newInvalidValueException(Errors.RepeatedValueForPatchModule(argModulePackage));
                     } else {
                         super.process(helper, option, prev + '\0' + arg);
                     }
                 }
             } else {
-                throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+                throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
             }
         }
 
@@ -290,7 +291,7 @@
         public void process(OptionHelper helper, String option, String operand) throws InvalidValueException {
             Source source = Source.lookup(operand);
             if (source == null) {
-                throw helper.newInvalidValueException("err.invalid.source", operand);
+                throw helper.newInvalidValueException(Errors.InvalidSource(operand));
             }
             super.process(helper, option, operand);
         }
@@ -301,7 +302,7 @@
         public void process(OptionHelper helper, String option, String operand) throws InvalidValueException {
             Target target = Target.lookup(operand);
             if (target == null) {
-                throw helper.newInvalidValueException("err.invalid.target", operand);
+                throw helper.newInvalidValueException(Errors.InvalidTarget(operand));
             }
             super.process(helper, option, operand);
         }
@@ -337,7 +338,7 @@
         public void process(OptionHelper helper, String option, String operand) throws InvalidValueException {
             Profile profile = Profile.lookup(operand);
             if (profile == null) {
-                throw helper.newInvalidValueException("err.invalid.profile", operand);
+                throw helper.newInvalidValueException(Errors.InvalidProfile(operand));
             }
             super.process(helper, option, operand);
         }
@@ -392,12 +393,12 @@
         public void process(OptionHelper helper, String option) throws InvalidValueException {
             int argLength = option.length();
             if (argLength == 2) {
-                throw helper.newInvalidValueException("err.empty.A.argument");
+                throw helper.newInvalidValueException(Errors.EmptyAArgument);
             }
             int sepIndex = option.indexOf('=');
             String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) );
             if (!JavacProcessingEnvironment.isValidOptionName(key)) {
-                throw helper.newInvalidValueException("err.invalid.A.key", option);
+                throw helper.newInvalidValueException(Errors.InvalidAKey(option));
             }
             helper.put(option, option);
         }
@@ -410,14 +411,13 @@
         public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
             String prev = helper.get(DEFAULT_MODULE_FOR_CREATED_FILES);
             if (prev != null) {
-                throw helper.newInvalidValueException("err.option.too.many",
-                                                      DEFAULT_MODULE_FOR_CREATED_FILES.primaryName);
+                throw helper.newInvalidValueException(Errors.OptionTooMany(DEFAULT_MODULE_FOR_CREATED_FILES.primaryName));
             } else if (arg.isEmpty()) {
-                throw helper.newInvalidValueException("err.no.value.for.option", option);
+                throw helper.newInvalidValueException(Errors.NoValueForOption(option));
             } else if (getPattern().matcher(arg).matches()) {
                 helper.put(DEFAULT_MODULE_FOR_CREATED_FILES.primaryName, arg);
             } else {
-                throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+                throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
             }
         }
 
@@ -487,7 +487,7 @@
                 Log log = helper.getLog();
                 log.setWriters(new PrintWriter(new FileWriter(arg), true));
             } catch (java.io.IOException e) {
-                throw helper.newInvalidValueException("err.error.writing.file", arg, e);
+                throw helper.newInvalidValueException(Errors.ErrorWritingFile(arg, e.getMessage()));
             }
             super.process(helper, option, arg);
         }
@@ -570,12 +570,12 @@
         @Override
         public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
             if (arg.isEmpty()) {
-                throw helper.newInvalidValueException("err.no.value.for.option", option);
+                throw helper.newInvalidValueException(Errors.NoValueForOption(option));
             } else if (getPattern().matcher(arg).matches()) {
                 String prev = helper.get(ADD_EXPORTS);
                 helper.put(ADD_EXPORTS.primaryName, (prev == null) ? arg : prev + '\0' + arg);
             } else {
-                throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+                throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
             }
         }
 
@@ -591,12 +591,12 @@
         @Override
         public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
             if (arg.isEmpty()) {
-                throw helper.newInvalidValueException("err.no.value.for.option", option);
+                throw helper.newInvalidValueException(Errors.NoValueForOption(option));
             } else if (getPattern().matcher(arg).matches()) {
                 String prev = helper.get(ADD_READS);
                 helper.put(ADD_READS.primaryName, (prev == null) ? arg : prev + '\0' + arg);
             } else {
-                throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+                throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
             }
         }
 
@@ -612,14 +612,14 @@
         @Override
         public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
             if (arg.isEmpty()) {
-                throw helper.newInvalidValueException("err.no.value.for.option", option);
+                throw helper.newInvalidValueException(Errors.NoValueForOption(option));
             } else if (getPattern().matcher(arg).matches()) {
                 String prev = helper.get(ADD_MODULES);
                 // since the individual values are simple names, we can simply join the
                 // values of multiple --add-modules options with ','
                 helper.put(ADD_MODULES.primaryName, (prev == null) ? arg : prev + ',' + arg);
             } else {
-                throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+                throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
             }
         }
 
@@ -633,11 +633,11 @@
         @Override
         public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
             if (arg.isEmpty()) {
-                throw helper.newInvalidValueException("err.no.value.for.option", option);
+                throw helper.newInvalidValueException(Errors.NoValueForOption(option));
             } else if (getPattern().matcher(arg).matches()) {
                 helper.put(LIMIT_MODULES.primaryName, arg); // last one wins
             } else {
-                throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+                throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
             }
         }
 
@@ -651,13 +651,13 @@
         @Override
         public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
             if (arg.isEmpty()) {
-                throw helper.newInvalidValueException("err.no.value.for.option", option);
+                throw helper.newInvalidValueException(Errors.NoValueForOption(option));
             } else {
                 // use official parser if available
                 try {
                     ModuleDescriptor.Version.parse(arg);
                 } catch (IllegalArgumentException e) {
-                    throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
+                    throw helper.newInvalidValueException(Errors.BadValueForOption(option, arg));
                 }
             }
             super.process(helper, option, arg);
@@ -692,10 +692,10 @@
             if (option.endsWith(".java") ) {
                 Path p = Paths.get(option);
                 if (!Files.exists(p)) {
-                    throw helper.newInvalidValueException("err.file.not.found", p);
+                    throw helper.newInvalidValueException(Errors.FileNotFound(p.toString()));
                 }
                 if (!Files.isRegularFile(p)) {
-                    throw helper.newInvalidValueException("err.file.not.file", p);
+                    throw helper.newInvalidValueException(Errors.FileNotFile(p));
                 }
                 helper.addFile(p);
             } else {
@@ -1078,7 +1078,7 @@
                 operand = arg.substring(sep + 1);
             } else {
                 if (!rest.hasNext()) {
-                    throw helper.newInvalidValueException("err.req.arg", arg);
+                    throw helper.newInvalidValueException(Errors.ReqArg(this.primaryName));
                 }
                 option = arg;
                 operand = rest.next();
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/OptionHelper.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/OptionHelper.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,9 @@
 
 import java.nio.file.Path;
 
+import com.sun.tools.javac.resources.CompilerProperties.Errors;
 import com.sun.tools.javac.util.JCDiagnostic;
+import com.sun.tools.javac.util.JCDiagnostic.Error;
 import com.sun.tools.javac.util.Log;
 import com.sun.tools.javac.util.Log.PrefixKind;
 
@@ -89,8 +91,8 @@
      * @param args the arguments, if any, for the resource string
      * @return the InvalidValueException
      */
-    Option.InvalidValueException newInvalidValueException(String key, Object... args) {
-        return new Option.InvalidValueException(getLog().localize(PrefixKind.JAVAC, key, args));
+    Option.InvalidValueException newInvalidValueException(Error error) {
+        return new Option.InvalidValueException(getLog().localize(error));
     }
 
     /** Record a file to be compiled. */
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Thu Apr 19 14:17:54 2018 +0200
@@ -39,13 +39,18 @@
 # name              a name, typically a Java identifier
 # number            an integer
 # option name       the name of a command line option
-# source version    a source version number, such as 1.5, 1.6, 1.7
+# path              a path
+# profile           a profile name
+# source            a source version number, such as 1.5, 1.6, 1.7, taken from a com.sun.tools.javac.code.Source
+# source version    a source version number, such as 1.5, 1.6, 1.7, taken from a javax.lang.model.SourceVersion
 # string            a general string
 # symbol            the name of a declared type
 # symbol kind       the kind of a symbol (i.e. method, variable)
 # kind name         an informative description of the kind of a declaration; see compiler.misc.kindname.*
+# target            a target version number, such as 1.5, 1.6, 1.7, taken from a com.sun.tools.javac.jvm.Target
 # token             the name of a non-terminal in source code; see compiler.misc.token.*
 # type              a Java type; e.g. int, X, X<T>
+# url               a URL
 # object            a Java object (unspecified)
 # unused            the value is not used in this message
 #
@@ -1779,7 +1784,7 @@
 compiler.warn.option.obsolete.source=\
     source value {0} is obsolete and will be removed in a future release
 
-# 0: string
+# 0: target
 compiler.warn.option.obsolete.target=\
     target value {0} is obsolete and will be removed in a future release
 
@@ -1787,12 +1792,12 @@
 compiler.err.option.removed.source=\
     Source option {0} is no longer supported. Use {1} or later.
 
-# 0: string, 1: string
+# 0: target, 1: target
 compiler.err.option.removed.target=\
     Target option {0} is no longer supported. Use {1} or later.
 
 
-# 0: string, 1: string
+# 0: target, 1: target
 compiler.warn.option.parameters.unsupported=\
     -parameters is not supported for target value {0}. Use {1} or later.
 
@@ -3257,3 +3262,123 @@
 # 0: string, 1: string
 compiler.err.illegal.argument.for.option=\
     illegal argument for {0}: {1}
+
+
+############################################
+# messages previouly at javac.properties
+
+compiler.err.empty.A.argument=\
+    -A requires an argument; use ''-Akey'' or ''-Akey=value''
+
+# 0: string
+compiler.err.invalid.A.key=\
+    key in annotation processor option ''{0}'' is not a dot-separated sequence of identifiers
+
+# 0: string
+compiler.err.invalid.flag=\
+    invalid flag: {0}
+
+compiler.err.profile.bootclasspath.conflict=\
+    profile and bootclasspath options cannot be used together
+
+# 0: string
+compiler.err.invalid.profile=\
+    invalid profile: {0}
+
+# 0: string
+compiler.err.invalid.target=\
+    invalid target release: {0}
+
+# 0: option name, 1: target
+compiler.err.option.not.allowed.with.target=\
+    option {0} not allowed with target {1}
+
+# 0: string
+compiler.err.option.too.many=\
+    option {0} can only be specified once
+
+compiler.err.no.source.files=\
+    no source files
+
+compiler.err.no.source.files.classes=\
+    no source files or class names
+
+# 0: string
+compiler.err.req.arg=\
+    {0} requires an argument
+
+# 0: string
+compiler.err.invalid.source=\
+    invalid source release: {0}
+
+# 0: string, 1: string
+compiler.err.error.writing.file=\
+    error writing {0}; {1}
+
+compiler.err.sourcepath.modulesourcepath.conflict=\
+    cannot specify both --source-path and --module-source-path
+
+# 0: string, 1: target
+compiler.warn.source.target.conflict=\
+    source release {0} requires target release {1}
+
+# 0: string, 1: target
+compiler.warn.target.default.source.conflict=\
+    target release {0} conflicts with default source release {1}
+
+# 0: profile, 1: target
+compiler.warn.profile.target.conflict=\
+    profile {0} is not valid for target release {1}
+
+# 0: string
+compiler.err.file.not.directory=\
+    not a directory: {0}
+
+# 0: object
+compiler.err.file.not.file=\
+    not a file: {0}
+
+compiler.err.two.class.loaders.1=\
+    javac is split between multiple class loaders: check your configuration
+
+# 0: url, 1: url
+compiler.err.two.class.loaders.2=\
+    javac is split between multiple class loaders:\n\
+    one class comes from file: {0}\n\
+    while javac comes from {1}
+
+# 0: string, 1: string
+compiler.err.bad.value.for.option=\
+    bad value for {0} option: ''{1}''
+
+# 0: string
+compiler.err.no.value.for.option=\
+    no value for {0} option
+
+# 0: string
+compiler.err.repeated.value.for.patch.module=\
+    --patch-module specified more than once for {0}
+
+# 0: string
+compiler.err.unmatched.quote=\
+    unmatched quote in environment variable {0}
+
+# 0: option name
+compiler.err.release.bootclasspath.conflict=\
+    option {0} cannot be used together with --release
+
+# 0: string
+compiler.err.unsupported.release.version=\
+    release version {0} not supported
+
+# 0: string
+compiler.err.file.not.found=\
+    file not found: {0}
+
+# 0: string, 1: source
+compiler.err.preview.not.latest=\
+    invalid source release {0} with --enable-preview\n\
+    (preview language features are only supported for release {1})
+
+compiler.err.preview.without.source.or.release=\
+    --enable-preview must be used with either -source or --release
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties	Thu Apr 19 14:17:54 2018 +0200
@@ -335,71 +335,6 @@
 javac.opt.default.module.for.created.files=\
     Fallback target module for files created by annotation processors, if none specified or inferred.
 
-## errors
-
-javac.err.empty.A.argument=\
-    -A requires an argument; use ''-Akey'' or ''-Akey=value''
-javac.err.invalid.arg=\
-    invalid argument: {0}
-javac.err.invalid.A.key=\
-     key in annotation processor option ''{0}'' is not a dot-separated sequence of identifiers
-javac.err.invalid.flag=\
-    invalid flag: {0}
-javac.err.profile.bootclasspath.conflict=\
-    profile and bootclasspath options cannot be used together
-javac.err.invalid.profile=\
-    invalid profile: {0}
-javac.err.invalid.target=\
-    invalid target release: {0}
-javac.err.option.not.allowed.with.target=\
-    option {0} not allowed with target {1}
-javac.err.option.too.many=\
-    option {0} can only be specified once
-javac.err.no.source.files=\
-    no source files
-javac.err.no.source.files.classes=\
-    no source files or class names
-javac.err.req.arg=\
-    {0} requires an argument
-javac.err.invalid.source=\
-    invalid source release: {0}
-javac.err.error.writing.file=\
-    error writing {0}; {1}
-javac.err.sourcepath.modulesourcepath.conflict=\
-    cannot specify both --source-path and --module-source-path
-javac.warn.source.target.conflict=\
-    source release {0} requires target release {1}
-javac.warn.target.default.source.conflict=\
-    target release {0} conflicts with default source release {1}
-javac.warn.profile.target.conflict=\
-    profile {0} is not valid for target release {1}
-javac.err.preview.not.latest=\
-    invalid source release {0} with --enable-preview\n\
-    (preview language features are only supported for release {1})
-javac.err.preview.without.source.or.release=\
-    --enable-preview must be used with either -source or --release
-javac.err.file.not.found=\
-    file not found: {0}
-javac.err.file.not.directory=\
-    not a directory: {0}
-javac.err.file.not.file=\
-    not a file: {0}
-javac.err.two.class.loaders.1=\
-    javac is split between multiple class loaders: check your configuration
-javac.err.two.class.loaders.2=\
-    javac is split between multiple class loaders:\n\
-    one class comes from file: {0}\n\
-    while javac comes from {1}
-javac.err.bad.value.for.option=\
-    bad value for {0} option: ''{1}''
-javac.err.no.value.for.option=\
-    no value for {0} option
-javac.err.repeated.value.for.patch.module=\
-    --patch-module specified more than once for {0}
-
-javac.err.unmatched.quote=\
-    unmatched quote in environment variable %s
-
 ## messages
 
 javac.msg.usage.header=\
@@ -437,9 +372,3 @@
 
 javac.version={0} {1}
 javac.fullVersion={0} full version "{1}"
-
-javac.err.release.bootclasspath.conflict=\
-    option {0} cannot be used together with --release
-
-javac.err.unsupported.release.version=\
-    release version {0} not supported
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -43,11 +43,13 @@
 import com.sun.tools.javac.api.Formattable;
 import com.sun.tools.javac.code.Lint.LintCategory;
 import com.sun.tools.javac.code.Printer;
+import com.sun.tools.javac.code.Source;
 import com.sun.tools.javac.code.Symbol;
 import com.sun.tools.javac.code.Type;
 import com.sun.tools.javac.code.Type.CapturedType;
 import com.sun.tools.javac.file.PathFileObject;
 import com.sun.tools.javac.jvm.Profile;
+import com.sun.tools.javac.jvm.Target;
 import com.sun.tools.javac.main.Option;
 import com.sun.tools.javac.tree.JCTree.*;
 import com.sun.tools.javac.tree.Pretty;
@@ -211,6 +213,12 @@
         else if (arg instanceof Formattable) {
             return ((Formattable)arg).toString(l, messages);
         }
+        else if (arg instanceof Target) {
+            return ((Target)arg).name;
+        }
+        else if (arg instanceof Source) {
+            return ((Source)arg).name;
+        }
         else {
             return String.valueOf(arg);
         }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JavacMessages.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JavacMessages.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
 package com.sun.tools.javac.util;
 
 import com.sun.tools.javac.api.Messages;
+
 import java.lang.ref.SoftReference;
 import java.util.ResourceBundle;
 import java.util.MissingResourceException;
@@ -34,6 +35,10 @@
 import java.util.Locale;
 import java.util.Map;
 
+import com.sun.tools.javac.api.DiagnosticFormatter;
+import com.sun.tools.javac.util.JCDiagnostic.Factory;
+import com.sun.tools.javac.resources.CompilerProperties.Errors;
+
 /**
  *  Support for formatted localized messages.
  *
@@ -61,6 +66,9 @@
     private Locale currentLocale;
     private List<ResourceBundle> currentBundles;
 
+    private DiagnosticFormatter<JCDiagnostic> diagFormatter;
+    private JCDiagnostic.Factory diagFactory;
+
     public Locale getCurrentLocale() {
         return currentLocale;
     }
@@ -73,11 +81,18 @@
         this.currentLocale = locale;
     }
 
+    Context context;
+
     /** Creates a JavacMessages object.
      */
     public JavacMessages(Context context) {
         this(defaultBundleName, context.get(Locale.class));
+        this.context = context;
         context.put(messagesKey, this);
+        Options options = Options.instance(context);
+        boolean rawDiagnostics = options.isSet("rawDiagnostics");
+        this.diagFormatter = rawDiagnostics ? new RawDiagnosticFormatter(options) :
+                                                  new BasicDiagnosticFormatter(options, this);
     }
 
     /** Creates a JavacMessages object.
@@ -140,6 +155,10 @@
         return getLocalizedString(currentLocale, key, args);
     }
 
+    public String getLocalizedString(JCDiagnostic.DiagnosticInfo diagInfo) {
+        return getLocalizedString(currentLocale, diagInfo);
+    }
+
     @Override
     public String getLocalizedString(Locale l, String key, Object... args) {
         if (l == null)
@@ -147,6 +166,12 @@
         return getLocalizedString(getBundles(l), key, args);
     }
 
+    public String getLocalizedString(Locale l, JCDiagnostic.DiagnosticInfo diagInfo) {
+        if (l == null)
+            l = getCurrentLocale();
+        return getLocalizedString(getBundles(l), diagInfo);
+    }
+
     /* Static access:
      * javac has a firmly entrenched notion of a default message bundle
      * which it can access from any static context. This is used to get
@@ -185,7 +210,7 @@
         }
     }
 
-    private static String getLocalizedString(List<ResourceBundle> bundles,
+    static private String getLocalizedString(List<ResourceBundle> bundles,
                                              String key,
                                              Object... args) {
        String msg = null;
@@ -205,6 +230,36 @@
        return MessageFormat.format(msg, args);
     }
 
+    private String getLocalizedString(List<ResourceBundle> bundles, JCDiagnostic.DiagnosticInfo diagInfo) {
+        String msg = null;
+        for (List<ResourceBundle> l = bundles; l.nonEmpty() && msg == null; l = l.tail) {
+            ResourceBundle rb = l.head;
+            try {
+                msg = rb.getString(diagInfo.key());
+            }
+            catch (MissingResourceException e) {
+                // ignore, try other bundles in list
+            }
+        }
+        if (msg == null) {
+            msg = "compiler message file broken: key=" + diagInfo.key() +
+                " arguments={0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}";
+        }
+        if (diagInfo == Errors.Error) {
+            return MessageFormat.format(msg, new Object[0]);
+        } else {
+            return diagFormatter.format(getDiagFactory().create(DiagnosticSource.NO_SOURCE, null, diagInfo),
+                    getCurrentLocale());
+        }
+    }
+
+    JCDiagnostic.Factory getDiagFactory() {
+        if (diagFactory == null) {
+            this.diagFactory = JCDiagnostic.Factory.instance(context);
+        }
+        return diagFactory;
+    }
+
     /**
      * This provides a way for the JavacMessager to retrieve a
      * ResourceBundle from another module such as jdk.javadoc.
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * 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 @@
 import com.sun.tools.javac.main.Option;
 import com.sun.tools.javac.tree.EndPosTable;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
+import com.sun.tools.javac.util.JCDiagnostic.DiagnosticInfo;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
 
@@ -597,6 +598,11 @@
         printRawLines(noticeWriter, localize(key, args));
     }
 
+    public void printLines(DiagnosticInfo diag) {
+        PrintWriter noticeWriter = writers.get(WriterKind.NOTICE);
+        printRawLines(noticeWriter, localize(diag));
+    }
+
     public void printLines(PrefixKind pk, String key, Object... args) {
         PrintWriter noticeWriter = writers.get(WriterKind.NOTICE);
         printRawLines(noticeWriter, localize(pk, key, args));
@@ -789,7 +795,7 @@
         if (useRawMessages) {
             return diagInfo.key();
         } else {
-            return messages.getLocalizedString(diagInfo.key(), diagInfo.args);
+            return messages.getLocalizedString(diagInfo);
         }
     }
 
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/classfile/ClassLoaderData.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/classfile/ClassLoaderData.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  * 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,14 +42,14 @@
 
   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
     Type type      = db.lookupType("ClassLoaderData");
-    classLoaderField = type.getOopField("_class_loader");
+    classLoaderField = type.getAddressField("_class_loader");
     nextField = type.getAddressField("_next");
     klassesField = new MetadataField(type.getAddressField("_klasses"), 0);
     isAnonymousField = new CIntField(type.getCIntegerField("_is_anonymous"), 0);
     dictionaryField = type.getAddressField("_dictionary");
   }
 
-  private static sun.jvm.hotspot.types.OopField classLoaderField;
+  private static AddressField   classLoaderField;
   private static AddressField nextField;
   private static MetadataField  klassesField;
   private static CIntField isAnonymousField;
@@ -72,7 +72,13 @@
   }
 
   public Oop getClassLoader() {
-    return VM.getVM().getObjectHeap().newOop(classLoaderField.getValue(getAddress()));
+    Address handle = classLoaderField.getValue(getAddress());
+    if (handle != null) {
+      // Load through the handle
+      OopHandle refs = handle.getOopHandleAt(0);
+      return (Instance)VM.getVM().getObjectHeap().newOop(refs);
+    }
+    return null;
   }
 
   public boolean getIsAnonymous() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.internal.vm.compiler.management/share/classes/org.graalvm.compiler.hotspot.management/src/org/graalvm/compiler/hotspot/management/HotSpotGraalManagement.java	Thu Apr 19 14:17:54 2018 +0200
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2018, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.graalvm.compiler.hotspot.management;
+
+/**
+ * Placeholder until next Graal update.
+ */
+public final class HotSpotGraalManagement  {
+}
--- a/test/hotspot/gtest/utilities/test_globalCounter.cpp	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/hotspot/gtest/utilities/test_globalCounter.cpp	Thu Apr 19 14:17:54 2018 +0200
@@ -29,8 +29,8 @@
 #include "utilities/globalCounter.inline.hpp"
 #include "utilitiesHelper.inline.hpp"
 
-#define GOOD 1337
-#define BAD  4711
+#define GOOD_VALUE 1337
+#define BAD_VALUE  4711
 
 struct TestData {
   long test_value;
@@ -50,13 +50,13 @@
       GlobalCounter::critical_section_begin(this);
       volatile TestData* test = OrderAccess::load_acquire(_test);
       long value = OrderAccess::load_acquire(&test->test_value);
-      ASSERT_EQ(value, GOOD);
+      ASSERT_EQ(value, GOOD_VALUE);
       GlobalCounter::critical_section_end(this);
       {
         GlobalCounter::CriticalSection cs(this);
         volatile TestData* test = OrderAccess::load_acquire(_test);
         long value = OrderAccess::load_acquire(&test->test_value);
-        ASSERT_EQ(value, GOOD);
+        ASSERT_EQ(value, GOOD_VALUE);
       }
     }
   }
@@ -81,7 +81,7 @@
     RCUReaderThread* reader4 = new RCUReaderThread(&post, &test, &wrt_start);
 
     TestData* tmp = new TestData();
-    tmp->test_value = GOOD;
+    tmp->test_value = GOOD_VALUE;
     OrderAccess::release_store_fence(&test, tmp);
 
     reader1->doit();
@@ -98,10 +98,10 @@
     for (int i = 0; i < 100000 && stop_ms > os::javaTimeMillis(); i++) {
       volatile TestData* free_tmp = test;
       tmp = new TestData();
-      tmp->test_value = GOOD;
+      tmp->test_value = GOOD_VALUE;
       OrderAccess::release_store(&test, tmp);
       GlobalCounter::write_synchronize();
-      free_tmp->test_value = BAD;
+      free_tmp->test_value = BAD_VALUE;
       delete free_tmp;
     }
     RCUReaderThread::_exit = true;
--- a/test/hotspot/jtreg/runtime/MemberName/MemberNameLeak.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/hotspot/jtreg/runtime/MemberName/MemberNameLeak.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -61,7 +61,7 @@
         OutputAnalyzer output = new OutputAnalyzer(pb.start());
         output.shouldContain("ResolvedMethod entry added for MemberNameLeak$Leak.callMe()V");
         output.shouldContain("ResolvedMethod entry found for MemberNameLeak$Leak.callMe()V");
-        output.shouldContain("ResolvedMethod entry removed for MemberNameLeak$Leak.callMe()V");
+        output.shouldContain("ResolvedMethod entry removed");
         output.shouldHaveExitValue(0);
     }
 
--- a/test/jdk/TEST.groups	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/jdk/TEST.groups	Thu Apr 19 14:17:54 2018 +0200
@@ -1,4 +1,4 @@
-#  Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
+#  Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
 #  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 #  This code is free software; you can redistribute it and/or modify it
@@ -34,12 +34,14 @@
     java/nio/Buffer \
     com/sun/crypto/provider/Cipher \
     :jdk_math \
-    tools/pack200
+    tools/pack200 \
+    -java/util/Arrays/TimSortStackSize2.java
 
 tier2 = \
     :tier2_part1 \
     :tier2_part2 \
-    :tier2_part3
+    :tier2_part3 \
+    java/util/Arrays/TimSortStackSize2.java
 
 # com/sun/crypto/provider/Cipher is in tier1 because of JDK-8132855
 tier2_part1 = \
--- a/test/jdk/java/util/Arrays/TimSortStackSize2.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/jdk/java/util/Arrays/TimSortStackSize2.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,7 @@
  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  *     -XX:+WhiteBoxAPI TimSortStackSize2
  * @summary Test TimSort stack size on big arrays
+ * @key intermittent
  */
 import java.util.ArrayList;
 import java.util.Arrays;
--- a/test/jdk/java/util/Optional/Basic.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/jdk/java/util/Optional/Basic.java	Thu Apr 19 14:17:54 2018 +0200
@@ -52,6 +52,7 @@
         assertFalse(empty.equals("unexpected"));
 
         assertFalse(empty.isPresent());
+        assertTrue(empty.isEmpty());
         assertEquals(empty.hashCode(), 0);
         assertEquals(empty.orElse("x"), "x");
         assertEquals(empty.orElseGet(() -> "y"), "y");
@@ -87,6 +88,7 @@
         assertFalse(opt.equals("unexpected"));
 
         assertTrue(opt.isPresent());
+        assertFalse(opt.isEmpty());
         assertEquals(opt.hashCode(), expected.hashCode());
         assertEquals(opt.orElse("unexpected"), expected);
         assertEquals(opt.orElseGet(() -> "unexpected"), expected);
--- a/test/jdk/java/util/Optional/BasicDouble.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/jdk/java/util/Optional/BasicDouble.java	Thu Apr 19 14:17:54 2018 +0200
@@ -51,6 +51,7 @@
         assertFalse(empty.equals("unexpected"));
 
         assertFalse(empty.isPresent());
+        assertTrue(empty.isEmpty());
         assertEquals(empty.hashCode(), 0);
         assertEquals(empty.orElse(UNEXPECTED), UNEXPECTED);
         assertEquals(empty.orElseGet(() -> UNEXPECTED), UNEXPECTED);
@@ -86,6 +87,7 @@
         assertFalse(opt.equals("unexpected"));
 
         assertTrue(opt.isPresent());
+        assertFalse(opt.isEmpty());
         assertEquals(opt.hashCode(), Double.hashCode(expected));
         assertEquals(opt.orElse(UNEXPECTED), expected);
         assertEquals(opt.orElseGet(() -> UNEXPECTED), expected);
--- a/test/jdk/java/util/Optional/BasicInt.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/jdk/java/util/Optional/BasicInt.java	Thu Apr 19 14:17:54 2018 +0200
@@ -52,6 +52,7 @@
         assertFalse(empty.equals("unexpected"));
 
         assertFalse(empty.isPresent());
+        assertTrue(empty.isEmpty());
         assertEquals(empty.hashCode(), 0);
         assertEquals(empty.orElse(UNEXPECTED), UNEXPECTED);
         assertEquals(empty.orElseGet(() -> UNEXPECTED), UNEXPECTED);
@@ -87,6 +88,7 @@
         assertFalse(opt.equals("unexpected"));
 
         assertTrue(opt.isPresent());
+        assertFalse(opt.isEmpty());
         assertEquals(opt.hashCode(), Integer.hashCode(expected));
         assertEquals(opt.orElse(UNEXPECTED), expected);
         assertEquals(opt.orElseGet(() -> UNEXPECTED), expected);
--- a/test/jdk/java/util/Optional/BasicLong.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/jdk/java/util/Optional/BasicLong.java	Thu Apr 19 14:17:54 2018 +0200
@@ -51,6 +51,7 @@
         assertFalse(empty.equals("unexpected"));
 
         assertFalse(empty.isPresent());
+        assertTrue(empty.isEmpty());
         assertEquals(empty.hashCode(), 0);
         assertEquals(empty.orElse(UNEXPECTED), UNEXPECTED);
         assertEquals(empty.orElseGet(() -> UNEXPECTED), UNEXPECTED);
@@ -86,6 +87,7 @@
         assertFalse(opt.equals("unexpected"));
 
         assertTrue(opt.isPresent());
+        assertFalse(opt.isEmpty());
         assertEquals(opt.hashCode(), Long.hashCode(expected));
         assertEquals(opt.orElse(UNEXPECTED), expected);
         assertEquals(opt.orElseGet(() -> UNEXPECTED), expected);
--- a/test/jdk/jdk/modules/etc/UpgradeableModules.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/jdk/jdk/modules/etc/UpgradeableModules.java	Thu Apr 19 14:17:54 2018 +0200
@@ -46,6 +46,7 @@
         List.of("java.compiler",
                 "java.jnlp",
                 "jdk.internal.vm.compiler",
+                "jdk.internal.vm.compiler.management",
                 "jdk.deploy",
                 "jdk.javaws",
                 "jdk.plugin",
--- a/test/langtools/jdk/javadoc/tool/BadOptionsTest.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/jdk/javadoc/tool/BadOptionsTest.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -79,7 +79,7 @@
                 .run(Task.Expect.FAIL)
                 .writeAll();
         checkFound(result.getOutput(Task.OutputKind.DIRECT),
-                "javadoc: error - no value for --add-modules option");
+                "javadoc: error - error: no value for --add-modules option");
         checkNotFound(result, "Exception", "at jdk.javadoc/");
     }
 
@@ -104,7 +104,7 @@
                 .run(Task.Expect.FAIL)
                 .writeAll();
         checkFound(result.getOutput(Task.OutputKind.DIRECT),
-                "javadoc: error - no value for --add-exports option");
+                "javadoc: error - error: no value for --add-exports option");
         checkNotFound(result, "Exception", "at jdk.javadoc/");
     }
 
@@ -116,7 +116,7 @@
                 .run(Task.Expect.FAIL)
                 .writeAll();
         checkFound(result.getOutput(Task.OutputKind.DIRECT),
-                "javadoc: error - bad value for --add-exports option");
+                "javadoc: error - error: bad value for --add-exports option: 'm/p'");
         checkNotFound(result, "Exception", "at jdk.javadoc/");
     }
 
@@ -146,7 +146,7 @@
                 .run(Task.Expect.FAIL)
                 .writeAll();
         checkFound(result.getOutput(Task.OutputKind.DIRECT),
-                "javadoc: cannot specify both --source-path and --module-source-path");
+                "error: cannot specify both --source-path and --module-source-path");
         checkFound(result.getOutput(Task.OutputKind.DIRECT),
                 "1 error");
     }
--- a/test/langtools/tools/javac/6410653/T6410653.java	Wed Apr 18 13:54:07 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * 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     6410653 6401277
- * @summary REGRESSION: javac crashes if -d or -s argument is a file
- * @author  Peter von der Ah\u00e9
- * @modules java.compiler
- *          jdk.compiler/com.sun.tools.javac.util:open
- */
-
-import java.lang.reflect.Field;
-import java.io.File;
-import java.io.ByteArrayOutputStream;
-import javax.tools.*;
-
-public class T6410653 {
-    public static void main(String... args) throws Exception {
-        File testSrc = new File(System.getProperty("test.src"));
-        String source = new File(testSrc, "T6410653.java").getPath();
-        Tool compiler = ToolProvider.getSystemJavaCompiler();
-        Module compilerModule = compiler.getClass().getModule();
-        Class<?> log = Class.forName(compilerModule, "com.sun.tools.javac.util.Log");
-        Field useRawMessages = log.getDeclaredField("useRawMessages");
-        useRawMessages.setAccessible(true);
-        useRawMessages.setBoolean(null, true);
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        compiler.run(null, null, out, "-d", source, source);
-        System.err.println(">>>" + out + "<<<");
-        useRawMessages.setBoolean(null, false);
-        if (!out.toString().equals(String.format("%s%n",
-                                                 "javac: javac.err.file.not.directory"))) {
-            throw new AssertionError(out);
-        }
-        System.out.println("Test PASSED.  Running javac again to see localized output:");
-        compiler.run(null, null, System.out, "-d", source, source);
-    }
-}
--- a/test/langtools/tools/javac/T8009640/CheckRejectProfileBCPOptionsIfUsedTogetherTest.java	Wed Apr 18 13:54:07 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*
- * 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
- * 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 8009640
- * @summary -profile <compact> does not work when -bootclasspath specified
- * @library /tools/lib
- * @modules jdk.compiler/com.sun.tools.javac.api
- *          jdk.compiler/com.sun.tools.javac.main
- *          jdk.compiler/com.sun.tools.javac.util
- *          jdk.jdeps/com.sun.tools.javap
- * @build toolbox.ToolBox toolbox.JavacTask
- * @run main CheckRejectProfileBCPOptionsIfUsedTogetherTest
- */
-
-import java.nio.file.Paths;
-
-import com.sun.tools.javac.util.Assert;
-
-import toolbox.JavacTask;
-import toolbox.Task;
-import toolbox.ToolBox;
-
-public class CheckRejectProfileBCPOptionsIfUsedTogetherTest {
-
-    private static final String TestSrc =
-        "public class Test {\n" +
-        "    javax.swing.JButton b;\n" +
-        "}";
-
-    public static void main(String args[]) throws Exception {
-        ToolBox tb = new ToolBox();
-        tb.writeFile("Test.java", TestSrc);
-
-        Task.Result result = new JavacTask(tb, Task.Mode.CMDLINE)
-                .options("-profile", "compact1",
-                        "-bootclasspath", Paths.get(ToolBox.testJDK, "jre/lib/rt.jar").toString())
-                .files("Test.java")
-                .run(Task.Expect.FAIL)
-                .writeAll();
-
-        String out = result.getOutput(Task.OutputKind.DIRECT);
-        Assert.check(out.startsWith(
-                "javac: profile and bootclasspath options cannot be used together"),
-                "Incorrect javac error output");
-    }
-
-}
--- a/test/langtools/tools/javac/diags/CheckResourceKeys.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/diags/CheckResourceKeys.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -233,7 +233,6 @@
         "compiler.misc.non.denotable.type",                 // UNUSED
         "compiler.misc.unnamed.package",                    // should be required, CR 6964147
         "compiler.warn.proc.type.already.exists",           // TODO in JavacFiler
-        "javac.err.invalid.arg",                            // UNUSED ??
         "javac.opt.arg.class",                              // UNUSED ??
         "javac.opt.arg.pathname",                           // UNUSED ??
         "javac.opt.moreinfo",                               // option commented out
--- a/test/langtools/tools/javac/diags/examples.not-yet.txt	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/diags/examples.not-yet.txt	Thu Apr 19 14:17:54 2018 +0200
@@ -157,3 +157,35 @@
 compiler.err.locn.module-info.not.allowed.on.patch.path
 compiler.misc.cant.resolve.modules
 compiler.misc.file.does.not.contain.module
+
+# these keys were in javac.properties and examples are hard to be produced for them
+# basically because in most cases the compilation ends with an exception
+compiler.err.bad.value.for.option
+compiler.err.empty.A.argument
+compiler.err.error.writing.file
+compiler.err.file.not.directory
+compiler.err.file.not.file
+compiler.err.file.not.found
+compiler.err.invalid.A.key
+compiler.err.invalid.flag
+compiler.err.invalid.profile
+compiler.err.invalid.source
+compiler.err.invalid.target
+compiler.err.no.source.files.classes
+compiler.err.no.value.for.option
+compiler.err.option.not.allowed.with.target
+compiler.err.option.too.many
+compiler.err.profile.bootclasspath.conflict
+compiler.err.release.bootclasspath.conflict
+compiler.err.repeated.value.for.patch.module
+compiler.err.req.arg
+compiler.err.sourcepath.modulesourcepath.conflict
+compiler.err.two.class.loaders.1
+compiler.err.two.class.loaders.2
+compiler.err.unmatched.quote
+compiler.err.unsupported.release.version
+compiler.warn.profile.target.conflict
+compiler.warn.source.target.conflict
+compiler.warn.target.default.source.conflict
+compiler.err.preview.not.latest
+compiler.err.preview.without.source.or.release
\ No newline at end of file
--- a/test/langtools/tools/javac/diags/examples/DirPathElementNotDirectory/DirPathElementNotDirectory.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/diags/examples/DirPathElementNotDirectory/DirPathElementNotDirectory.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,5 +22,6 @@
  */
 
 // key: compiler.warn.dir.path.element.not.directory
+// key: compiler.err.no.source.files
 // options: -Xlint:path
 // run: simple
--- a/test/langtools/tools/javac/doclint/DocLintTest.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/doclint/DocLintTest.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -84,7 +84,7 @@
         DL_ERR9(ERROR, "Test.java:9:14: compiler.err.proc.messager: reference not found"),
         DL_WRN12(WARNING, "Test.java:12:9: compiler.warn.proc.messager: no description for @return"),
 
-        OPT_BADARG(ERROR, "invalid flag: -Xdoclint:badarg");
+        OPT_BADARG(ERROR, "error: invalid flag: -Xdoclint:badarg");
 
         final Diagnostic.Kind kind;
         final String text;
--- a/test/langtools/tools/javac/doclint/IncludePackagesTest.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/doclint/IncludePackagesTest.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -96,7 +96,7 @@
         p1sp1sp2T(ERROR, "p1sp1sp2T.java:2:12: compiler.err.proc.messager: malformed HTML"),
         p2T(ERROR, "p2T.java:2:12: compiler.err.proc.messager: malformed HTML"),
         Default(ERROR, "Default.java:1:12: compiler.err.proc.messager: malformed HTML"),
-        INVALID_PACKAGE_ERROR(ERROR, "invalid flag: -Xdoclint/package:wrong+package");
+        INVALID_PACKAGE_ERROR(ERROR, "error: invalid flag: -Xdoclint/package:wrong+package");
 
         final Diagnostic.Kind kind;
         final String text;
--- a/test/langtools/tools/javac/modules/AddExportsTest.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/modules/AddExportsTest.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -62,7 +62,7 @@
                 .getOutput(Task.OutputKind.DIRECT);
 
         checkOutputContains(log,
-            "javac: no value for --add-exports option");
+            "error: no value for --add-exports option");
     }
 
     @Test
@@ -123,7 +123,7 @@
                 .getOutput(Task.OutputKind.DIRECT);
 
         checkOutputContains(log,
-            "javac: bad value for --add-exports option: '" + option + "'");
+            "error: bad value for --add-exports option: '" + option + "'");
     }
 
     @Test
@@ -158,7 +158,7 @@
                 .getOutput(Task.OutputKind.DIRECT);
 
         checkOutputContains(log,
-            "javac: bad value for --add-exports option: '" + option + "'");
+            "error: bad value for --add-exports option: '" + option + "'");
     }
 
     @Test
--- a/test/langtools/tools/javac/modules/AddLimitMods.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/modules/AddLimitMods.java	Thu Apr 19 14:17:54 2018 +0200
@@ -264,7 +264,7 @@
                    .writeAll()
                    .getOutputLines(Task.OutputKind.DIRECT);
 
-        if (!actual.contains("javac: option --add-modules not allowed with target 1.8")) {
+        if (!actual.contains("- compiler.err.option.not.allowed.with.target: --add-modules, 1.8")) {
             throw new IllegalStateException("incorrect errors; actual=" + actual);
         }
 
--- a/test/langtools/tools/javac/modules/AddModulesTest.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/modules/AddModulesTest.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -73,7 +73,7 @@
                 .getOutput(Task.OutputKind.DIRECT);
 
         checkOutputContains(log,
-            "javac: no value for --add-modules option");
+            "error: no value for --add-modules option");
     }
 
     @Test
@@ -120,7 +120,7 @@
                 .getOutput(Task.OutputKind.DIRECT);
 
         checkOutputContains(log,
-            "javac: bad value for --add-modules option");
+            "error: bad value for --add-modules option");
     }
 
     @Test
--- a/test/langtools/tools/javac/modules/AddReadsTest.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/modules/AddReadsTest.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -352,7 +352,7 @@
                 .getOutput(Task.OutputKind.DIRECT);
 
         checkOutputContains(log,
-            "javac: no value for --add-reads option");
+            "error: no value for --add-reads option");
     }
 
     @Test
@@ -421,7 +421,7 @@
                 .getOutput(Task.OutputKind.DIRECT);
 
         checkOutputContains(log,
-            "javac: bad value for --add-reads option: '" + option + "'");
+            "error: bad value for --add-reads option: '" + option + "'");
     }
 
     @Test
@@ -572,7 +572,7 @@
                 .getOutput(Task.OutputKind.DIRECT);
 
         checkOutputContains(log,
-            "javac: bad value for --add-reads option: 'm1x:m2x'");
+            "error: bad value for --add-reads option: 'm1x:m2x'");
     }
 
     @Test
--- a/test/langtools/tools/javac/modules/LimitModulesTest.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/modules/LimitModulesTest.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -58,7 +58,7 @@
                 .writeAll()
                 .getOutput(Task.OutputKind.DIRECT);
 
-        if (!log.contains("javac: no value for --limit-modules option"))
+        if (!log.contains("error: no value for --limit-modules option"))
             throw new Exception("expected output not found");
 
         log = new JavacTask(tb, Task.Mode.CMDLINE)
@@ -70,7 +70,7 @@
                 .writeAll()
                 .getOutput(Task.OutputKind.DIRECT);
 
-        if (!log.contains("javac: no value for --limit-modules option"))
+        if (!log.contains("error: no value for --limit-modules option"))
             throw new Exception("expected output not found");
     }
 
@@ -127,7 +127,7 @@
                 .writeAll()
                 .getOutput(Task.OutputKind.DIRECT);
 
-        if (!log.contains("javac: bad value for --limit-modules option"))
+        if (!log.contains("error: bad value for --limit-modules option"))
             throw new Exception("expected output not found");
     }
 
--- a/test/langtools/tools/javac/modules/ModuleSourcePathTest.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/modules/ModuleSourcePathTest.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -76,7 +76,7 @@
                 .writeAll()
                 .getOutput(Task.OutputKind.DIRECT);
 
-        if (!log.contains("cannot specify both --source-path and --module-source-path"))
+        if (!log.contains("compiler.err.sourcepath.modulesourcepath.conflict"))
             throw new Exception("expected diagnostic not found");
     }
 
--- a/test/langtools/tools/javac/modules/PatchModulesTest.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/modules/PatchModulesTest.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -98,19 +98,19 @@
     @Test
     public void testDuplicates(Path base) throws Exception {
         test(asList("java.base=a", "java.compiler=b", "java.base=c"),
-            false, "--patch-module specified more than once for java.base");
+            false, "error: --patch-module specified more than once for java.base");
     }
 
     @Test
     public void testEmpty(Path base) throws Exception {
         test(asList(""),
-            false, "no value for --patch-module option");
+            false, "error: no value for --patch-module option");
     }
 
     @Test
     public void testInvalid(Path base) throws Exception {
         test(asList("java.base/java.lang=."),
-            false, "bad value for --patch-module option: 'java.base/java.lang=.'");
+            false, "error: bad value for --patch-module option: 'java.base/java.lang=.'");
     }
 
     void test(List<String> patches, String expect) throws Exception {
--- a/test/langtools/tools/javac/options/release/ReleaseOptionClashes.java	Wed Apr 18 13:54:07 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * @test
- * @bug 8072480
- * @summary Verify option clash between --release and -source is reported correctly.
- * @modules jdk.compiler/com.sun.tools.javac.util:open
- */
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.tools.Tool;
-import javax.tools.ToolProvider;
-
-public class ReleaseOptionClashes {
-    public static void main(String... args) throws Exception {
-        new ReleaseOptionClashes().run();
-    }
-
-    void run() throws Exception {
-        doRunTest("7", "-bootclasspath", "any");
-        doRunTest("7", "-Xbootclasspath:any");
-        doRunTest("7", "-Xbootclasspath/a:any");
-        doRunTest("7", "-Xbootclasspath/p:any");
-        doRunTest("7", "-endorseddirs", "any");
-        doRunTest("7", "-extdirs", "any");
-        doRunTest("7", "-source", "8");
-        doRunTest("7", "-target", "8");
-        doRunTest("9", "--system", "none");
-        doRunTest("9", "--upgrade-module-path", "any");
-    }
-
-    void doRunTest(String release, String... args) throws Exception {
-        System.out.println("Testing clashes for arguments: " + Arrays.asList(args));
-        Class<?> log = Class.forName("com.sun.tools.javac.util.Log", true, cl);
-        Field useRawMessages = log.getDeclaredField("useRawMessages");
-        useRawMessages.setAccessible(true);
-        useRawMessages.setBoolean(null, true);
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        List<String> options = new ArrayList<>();
-        options.addAll(Arrays.asList("--release", release));
-        options.addAll(Arrays.asList(args));
-        options.add(System.getProperty("test.src") + File.separator + "ReleaseOptionClashes.java");
-        compiler.run(null, null, out, options.toArray(new String[0]));
-        useRawMessages.setBoolean(null, false);
-        if (!out.toString().equals(String.format("%s%n%s%n",
-                                                 "javac: javac.err.release.bootclasspath.conflict",
-                                                 "javac.msg.usage")) &&
-            //-Xbootclasspath:any produces two warnings: one for -bootclasspath and one for -Xbootclasspath:
-            !out.toString().equals(String.format("%s%n%s%n%s%n%s%n",
-                                                 "javac: javac.err.release.bootclasspath.conflict",
-                                                 "javac.msg.usage",
-                                                 "javac: javac.err.release.bootclasspath.conflict",
-                                                 "javac.msg.usage"))) {
-            throw new AssertionError(out);
-        }
-        System.out.println("Test PASSED.  Running javac again to see localized output:");
-        compiler.run(null, null, System.out, options.toArray(new String[0]));
-    }
-
-    Tool compiler = ToolProvider.getSystemJavaCompiler();
-    ClassLoader cl = compiler.getClass().getClassLoader();
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/options/smokeTests/OptionSmokeTest.java	Thu Apr 19 14:17:54 2018 +0200
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * 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 8196433
+ * @summary use the new error diagnostic approach at javac.Main
+ * @library /tools/lib
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ *          jdk.compiler/com.sun.tools.javac.main
+ *          jdk.compiler/com.sun.tools.javac.util
+ *          jdk.jdeps/com.sun.tools.javap
+ * @build toolbox.ToolBox toolbox.JavacTask toolbox.TestRunner
+ * @run main OptionSmokeTest
+ */
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import com.sun.tools.javac.util.Assert;
+
+import toolbox.TestRunner;
+import toolbox.ToolBox;
+import toolbox.JavacTask;
+import toolbox.Task;
+
+public class OptionSmokeTest extends TestRunner {
+    ToolBox tb = new ToolBox();
+
+    public OptionSmokeTest() {
+        super(System.err);
+    }
+
+    protected void runTests() throws Exception {
+        runTests(m -> new Object[] { Paths.get(m.getName()) });
+    }
+
+    Path[] findJavaFiles(Path... paths) throws Exception {
+        return tb.findJavaFiles(paths);
+    }
+
+    public static void main(String... args) throws Exception {
+        new OptionSmokeTest().runTests();
+    }
+
+    @Test
+    public void optionA1(Path base) throws Exception {
+        doTest(base,
+                "error: -A requires an argument; use '-Akey' or '-Akey=value'",
+                "-A");
+    }
+
+    @Test
+    public void optionA2(Path base) throws Exception {
+        doTest(base,
+                "error: key in annotation processor option '-A1e=2' is not a dot-separated sequence of identifiers",
+                "-A1e=2");
+    }
+
+    @Test
+    public void noFlag(Path base) throws Exception {
+        doTest(base, "error: invalid flag: -noFlag", "-noFlag");
+    }
+
+    @Test
+    public void profileAndBSP(Path base) throws Exception {
+        doTest(base, "error: profile and bootclasspath options cannot be used together",
+                "-profile compact1 -bootclasspath . -target 8 -source 8");
+    }
+
+    @Test
+    public void invalidProfile(Path base) throws Exception {
+        doTest(base, "error: invalid profile: noProfile",
+                "-profile noProfile");
+    }
+
+    @Test
+    public void invalidTarget(Path base) throws Exception {
+        doTest(base, "error: invalid target release: 999999",
+                "-target 999999");
+    }
+
+    @Test
+    public void optionNotAvailableWithTarget(Path base) throws Exception {
+        doTest(base, "error: option -profile not allowed with target 11",
+                "-profile compact1 -target 11");
+    }
+
+    @Test
+    public void optionTooMany(Path base) throws Exception {
+        doTest(base, "error: option --default-module-for-created-files can only be specified once",
+                "--default-module-for-created-files=m1x --default-module-for-created-files=m1x");
+    }
+
+    @Test
+    public void noSrcFiles(Path base) throws Exception {
+        doTestNoSource(base, "error: no source files", "-target 11");
+    }
+
+    @Test
+    public void requiresArg(Path base) throws Exception {
+        doTestNoSource(base, "error: -target requires an argument", "-target");
+    }
+
+    @Test
+    public void invalidSource(Path base) throws Exception {
+        doTestNoSource(base, "error: invalid source release: 999999", "-source 999999");
+    }
+
+    @Test
+    public void sourceAndModuleSourceCantBeTogether(Path base) throws Exception {
+        doTest(base, "error: cannot specify both --source-path and --module-source-path",
+                "--source-path . --module-source-path .");
+    }
+
+    @Test
+    public void sourceAndTargetMismatch(Path base) throws Exception {
+        doTest(base, "warning: source release 11 requires target release 11",
+                "-source 11 -target 10");
+    }
+
+    @Test
+    public void targetConflictsWithDefaultSource(Path base) throws Exception {
+        doTest(base, "warning: target release 10 conflicts with default source release 11",
+                "-target 10");
+    }
+
+    @Test
+    public void profileNotValidForTarget(Path base) throws Exception {
+        doTest(base, "warning: profile compact2 is not valid for target release 1.7",
+                "-profile compact2 -target 7 -source 7");
+    }
+
+    @Test
+    public void fileNotFound(Path base) throws Exception {
+        String log = new JavacTask(tb, Task.Mode.CMDLINE)
+                .files("notExistent/T.java")
+                .run(Task.Expect.FAIL)
+                .writeAll()
+                .getOutput(Task.OutputKind.DIRECT);
+        Assert.check(log.startsWith("error: file not found: notExistent" + fileSeparator + "T.java"),
+                "real value of log:" + log);
+    }
+
+    static final String fileSeparator = System.getProperty("file.separator");
+
+    @Test
+    public void notADirectory(Path base) throws Exception {
+        doTest(base, "error: not a directory: notADirectory" + fileSeparator + "src" + fileSeparator + "Dummy.java",
+                "-d notADirectory" + fileSeparator + "src" + fileSeparator + "Dummy.java");
+    }
+
+    @Test
+    public void notAFile(Path base) throws Exception {
+        // looks like a java file, it is a directory
+        Path dir = base.resolve("dir.java");
+        tb.createDirectories(dir);
+        String log = new JavacTask(tb, Task.Mode.CMDLINE)
+                .spaceSeparatedOptions("-XDsourcefile " + dir)
+                .run(Task.Expect.FAIL)
+                .writeAll()
+                .getOutput(Task.OutputKind.DIRECT);
+        Assert.check(log.startsWith("error: not a file: notAFile" + fileSeparator + "dir.java"));
+    }
+
+    @Test
+    public void badValueForOption(Path base) throws Exception {
+        doTestNoSource(base, "error: bad value for --patch-module option: \'notExistent\'",
+                "--patch-module notExistent");
+    }
+
+    @Test
+    public void patchModuleMoreThanOnce(Path base) throws Exception {
+        doTestNoSource(base, "error: --patch-module specified more than once for m",
+                "--patch-module m=. --patch-module m=.");
+    }
+
+    @Test
+    public void unmatchedQuoteInEnvVar(Path base) throws Exception {
+        Path src = base.resolve("src");
+        tb.writeJavaFiles(src, "class Dummy {}");
+        String log = new JavacTask(tb, Task.Mode.EXEC)
+                .envVar("JDK_JAVAC_OPTIONS", "--add-exports jdk.compiler" + fileSeparator + "com.sun.tools.javac.jvm=\"ALL-UNNAMED")
+                .files(findJavaFiles(src))
+                .run(Task.Expect.FAIL)
+                .writeAll()
+                .getOutput(Task.OutputKind.STDERR);
+        Assert.check(log.startsWith("error: unmatched quote in environment variable JDK_JAVAC_OPTIONS"));
+    }
+
+    @Test
+    public void optionCantBeUsedWithRelease(Path base) throws Exception {
+        doTestNoSource(base, "error: option -source cannot be used together with --release",
+                "--release 7 -source 7");
+    }
+
+    @Test
+    public void releaseVersionNotSupported(Path base) throws Exception {
+        doTestNoSource(base, "error: release version 99999999 not supported",
+                "--release 99999999");
+    }
+
+    // taken from former test: tools/javac/options/release/ReleaseOptionClashes
+    @Test
+    public void releaseAndBootclasspath(Path base) throws Exception {
+        doTestNoSource(base, "error: option --boot-class-path cannot be used together with --release",
+                "--release 7 -bootclasspath any");
+        doTestNoSource(base, "error: option -Xbootclasspath: cannot be used together with --release",
+                "--release 7 -Xbootclasspath:any");
+        doTestNoSource(base, "error: option -Xbootclasspath/p: cannot be used together with --release",
+                "--release 7 -Xbootclasspath/p:any");
+        doTestNoSource(base, "error: option -endorseddirs cannot be used together with --release",
+                "--release 7 -endorseddirs any");
+        doTestNoSource(base, "error: option -extdirs cannot be used together with --release",
+                "--release 7 -extdirs any");
+        doTestNoSource(base, "error: option -source cannot be used together with --release",
+                "--release 7 -source 8");
+        doTestNoSource(base, "error: option -target cannot be used together with --release",
+                "--release 7 -target 8");
+        doTestNoSource(base, "error: option --system cannot be used together with --release",
+                "--release 9 --system none");
+        doTestNoSource(base, "error: option --upgrade-module-path cannot be used together with --release",
+                "--release 9 --upgrade-module-path any");
+    }
+
+    void doTest(Path base, String output, String options) throws Exception {
+        Path src = base.resolve("src");
+        tb.writeJavaFiles(src, "class Dummy { }");
+        String log = new JavacTask(tb, Task.Mode.CMDLINE)
+                .spaceSeparatedOptions(options)
+                .files(findJavaFiles(src))
+                .run(Task.Expect.FAIL)
+                .writeAll()
+                .getOutput(Task.OutputKind.DIRECT);
+        Assert.check(log.startsWith(output), "expected:\n" + output + '\n' + "found:\n" + log);
+    }
+
+    void doTestNoSource(Path base, String output, String options) throws Exception {
+        String log = new JavacTask(tb, Task.Mode.CMDLINE)
+                .spaceSeparatedOptions(options)
+                .run(Task.Expect.FAIL)
+                .writeAll()
+                .getOutput(Task.OutputKind.DIRECT);
+        Assert.check(log.startsWith(output), "expected:\n" + output + '\n' + "found:\n" + log);
+    }
+}
--- a/test/langtools/tools/javac/platform/PlatformProviderTest.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javac/platform/PlatformProviderTest.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -141,7 +141,7 @@
         List<String> expectedOutput =
                 Arrays.asList("getSupportedPlatformNames",
                               "getPlatform(fail, )",
-                              "javac: javac.err.unsupported.release.version",
+                              "error: release version fail not supported",
                               "javac.msg.usage");
         List<String> actualOutput = result.getOutputLines(Task.OutputKind.STDERR);
         result.writeAll();
--- a/test/langtools/tools/javadoc/BadOptionsTest.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/javadoc/BadOptionsTest.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -96,7 +96,7 @@
                 .run(Task.Expect.FAIL)
                 .writeAll();
         checkFound(result.getOutput(Task.OutputKind.DIRECT),
-                "javadoc: error - no value for --add-modules option");
+                "javadoc: error - error: no value for --add-modules option");
         checkNotFound(result, "Exception", "at jdk.javadoc/");
     }
 
@@ -122,7 +122,7 @@
                 .run(Task.Expect.FAIL)
                 .writeAll();
         checkFound(result.getOutput(Task.OutputKind.DIRECT),
-                "javadoc: error - no value for --add-exports option");
+                "javadoc: error - error: no value for --add-exports option");
         checkNotFound(result, "Exception", "at jdk.javadoc/");
     }
 
@@ -135,7 +135,7 @@
                 .run(Task.Expect.FAIL)
                 .writeAll();
         checkFound(result.getOutput(Task.OutputKind.DIRECT),
-                "javadoc: error - bad value for --add-exports option");
+                "javadoc: error - error: bad value for --add-exports option: 'm/p'");
         checkNotFound(result, "Exception", "at jdk.javadoc/");
     }
 
--- a/test/langtools/tools/lib/toolbox/JavacTask.java	Wed Apr 18 13:54:07 2018 +0200
+++ b/test/langtools/tools/lib/toolbox/JavacTask.java	Thu Apr 19 14:17:54 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -179,6 +179,16 @@
 
     /**
      * Sets the options.
+     * @param spaceSeparatedOption the space separated options
+     * @return this task object
+     */
+    public JavacTask spaceSeparatedOptions(String spaceSeparatedOption) {
+        this.options = Arrays.asList(spaceSeparatedOption.split("\\s+"));
+        return this;
+    }
+
+    /**
+     * Sets the options.
      * @param options the options
      * @return this task object
      */