changeset 59290:130434292f7a nestmates

Summary: Remove term "weak", mangle hidden class using &ik, change short-lived to has_class_mirror_holder, remove loader arg from JVM_LookupDefineClass(), and other small changes. Reviewed-by: lfoltan, mchung
author hseigel
date Mon, 23 Mar 2020 20:05:49 +0000
parents 40c00294e1df
children 0b032112c89e
files src/hotspot/share/ci/ciInstanceKlass.cpp src/hotspot/share/classfile/classFileParser.cpp src/hotspot/share/classfile/classFileParser.hpp src/hotspot/share/classfile/classLoaderData.cpp src/hotspot/share/classfile/classLoaderData.hpp src/hotspot/share/classfile/classLoaderDataGraph.cpp src/hotspot/share/classfile/classLoaderDataGraph.hpp src/hotspot/share/classfile/classLoaderHierarchyDCmd.cpp src/hotspot/share/classfile/classLoaderStats.cpp src/hotspot/share/classfile/classLoaderStats.hpp src/hotspot/share/classfile/dictionary.cpp src/hotspot/share/classfile/klassFactory.cpp src/hotspot/share/classfile/moduleEntry.cpp src/hotspot/share/classfile/moduleEntry.hpp src/hotspot/share/classfile/systemDictionary.cpp src/hotspot/share/classfile/systemDictionary.hpp src/hotspot/share/include/jvm.h src/hotspot/share/jfr/metadata/metadata.xml src/hotspot/share/jfr/periodic/jfrPeriodic.cpp src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceId.cpp src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp src/hotspot/share/memory/metaspace.cpp src/hotspot/share/memory/metaspace.hpp src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.cpp src/hotspot/share/memory/metaspace/spaceManager.cpp src/hotspot/share/memory/metaspaceTracer.cpp src/hotspot/share/oops/instanceKlass.cpp src/hotspot/share/oops/instanceMirrorKlass.inline.hpp src/hotspot/share/oops/klass.cpp src/hotspot/share/oops/klass.hpp src/hotspot/share/prims/jvm.cpp src/hotspot/share/prims/unsafe.cpp src/hotspot/share/runtime/vmStructs.cpp src/java.base/share/native/libjava/ClassLoader.c src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/classfile/ClassLoaderData.java test/hotspot/gtest/memory/test_metaspace_allocation.cpp test/hotspot/jtreg/serviceability/dcmd/vm/ClassLoaderStatsTest.java test/jdk/jdk/jfr/event/runtime/TestClassLoaderStatsEvent.java
diffstat 39 files changed, 198 insertions(+), 185 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/ci/ciInstanceKlass.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/ci/ciInstanceKlass.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -74,7 +74,7 @@
   // InstanceKlass are created for both weak and strong metadata.  Ensuring this metadata
   // alive covers the cases where there are weak roots without performance cost.
   oop holder = ik->klass_holder();
-  if (ik->class_loader_data()->is_shortlived()) {
+  if (ik->class_loader_data()->has_class_mirror_holder()) {
     // Though ciInstanceKlass records class loader oop, it's not enough to keep
     // VM weak hidden and unsafe anonymous classes alive (loader == NULL). Klass holder should
     // be used instead. It is enough to record a ciObject, since cached elements are never removed
--- a/src/hotspot/share/classfile/classFileParser.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -5611,6 +5611,10 @@
   InstanceKlass* const ik =
     InstanceKlass::allocate_instance_klass(*this, CHECK_NULL);
 
+  if (is_hidden()) {
+    mangle_hidden_class_name(ik);
+  }
+
   fill_instance_klass(ik, changed_by_loadhook, cl_inst_info, CHECK_NULL);
 
   assert(_klass == ik, "invariant");
@@ -5734,10 +5738,6 @@
   Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl));
   ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh());
   ik->set_package(cld, CHECK);
-  // Obtain this_klass' module entry
-  ModuleEntry* module_entry = ik->module();
-  assert(module_entry != NULL, "module_entry should always be set");
-
 
   const Array<Method*>* const methods = ik->methods();
   assert(methods != NULL, "invariant");
@@ -5798,6 +5798,10 @@
     check_illegal_static_method(ik, CHECK);
   }
 
+  // Obtain this_klass' module entry
+  ModuleEntry* module_entry = ik->module();
+  assert(module_entry != NULL, "module_entry should always be set");
+
   // Obtain java.lang.Module
   Handle module_handle(THREAD, module_entry->module());
 
@@ -6288,7 +6292,6 @@
   // un-named, hidden or unsafe-anonymous class.
 
   if (_is_hidden) {
-    ResourceMark rm(THREAD);
     assert(_class_name != NULL, "Unexpected null _class_name");
 #ifdef ASSERT
     if (_need_verify) {
@@ -6296,32 +6299,6 @@
     }
 #endif
 
-    // Construct hidden name from _class_name, "+", and &_cp. Note that we can't
-    // use a '/' because that confuses finding the class's package.  Also, can't
-    // use an illegal char such as ';' because that causes serialization issues
-    // and issues with hidden classes that create their own hidden classes.
-    char addr_buf[20];
-    jio_snprintf(addr_buf, 20, INTPTR_FORMAT, p2i(_cp));
-    size_t new_name_len = _class_name->utf8_length() + 2 + strlen(addr_buf);
-    char* new_name = NEW_RESOURCE_ARRAY(char, new_name_len);
-    jio_snprintf(new_name, new_name_len, "%s+%s",
-                 _class_name->as_C_string(), addr_buf);
-    update_class_name(SymbolTable::new_symbol(new_name));
-
-    // Add a Utf8 entry containing the hidden name.
-    assert(_class_name != NULL, "Unexpected null _class_name");
-    int hidden_index = _orig_cp_size; // this is an extra slot we added
-    cp->symbol_at_put(hidden_index, _class_name);
-
-    // Update this_class_index's slot in the constant pool with the new Utf8 entry.
-    // We have to update the resolved_klass_index and the name_index together
-    // so extract the existing resolved_klass_index first.
-    CPKlassSlot cp_klass_slot = cp->klass_slot_at(_this_class_index);
-    int resolved_klass_index = cp_klass_slot.resolved_klass_index();
-    cp->unresolved_klass_at_put(_this_class_index, hidden_index, resolved_klass_index);
-    assert(cp->klass_slot_at(_this_class_index).name_index() == _orig_cp_size,
-           "Bad name_index");
-
   // NOTE: !_is_hidden does not imply "findable" as it could be an old-style
   //       "hidden" unsafe-anonymous class
 
@@ -6473,6 +6450,35 @@
   // all bytes in stream read and parsed
 }
 
+void ClassFileParser::mangle_hidden_class_name(InstanceKlass* const ik) {
+  ResourceMark rm;
+  // Construct hidden name from _class_name, "+", and &ik. Note that we can't
+  // use a '/' because that confuses finding the class's package.  Also, can't
+  // use an illegal char such as ';' because that causes serialization issues
+  // and issues with hidden classes that create their own hidden classes.
+  char addr_buf[20];
+  jio_snprintf(addr_buf, 20, INTPTR_FORMAT, p2i(ik));
+  size_t new_name_len = _class_name->utf8_length() + 2 + strlen(addr_buf);
+  char* new_name = NEW_RESOURCE_ARRAY(char, new_name_len);
+  jio_snprintf(new_name, new_name_len, "%s+%s",
+               _class_name->as_C_string(), addr_buf);
+  update_class_name(SymbolTable::new_symbol(new_name));
+
+  // Add a Utf8 entry containing the hidden name.
+  assert(_class_name != NULL, "Unexpected null _class_name");
+  int hidden_index = _orig_cp_size; // this is an extra slot we added
+  _cp->symbol_at_put(hidden_index, _class_name);
+
+  // Update this_class_index's slot in the constant pool with the new Utf8 entry.
+  // We have to update the resolved_klass_index and the name_index together
+  // so extract the existing resolved_klass_index first.
+  CPKlassSlot cp_klass_slot = _cp->klass_slot_at(_this_class_index);
+  int resolved_klass_index = cp_klass_slot.resolved_klass_index();
+  _cp->unresolved_klass_at_put(_this_class_index, hidden_index, resolved_klass_index);
+  assert(_cp->klass_slot_at(_this_class_index).name_index() == _orig_cp_size,
+         "Bad name_index");
+}
+
 void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const stream,
                                                  ConstantPool* cp,
                                                  TRAPS) {
--- a/src/hotspot/share/classfile/classFileParser.hpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/classFileParser.hpp	Mon Mar 23 20:05:49 2020 +0000
@@ -203,6 +203,8 @@
 
   void parse_stream(const ClassFileStream* const stream, TRAPS);
 
+  void mangle_hidden_class_name(InstanceKlass* const ik);
+
   void post_process_parsed_stream(const ClassFileStream* const stream,
                                   ConstantPool* cp,
                                   TRAPS);
--- a/src/hotspot/share/classfile/classLoaderData.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/classLoaderData.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -126,16 +126,16 @@
   _name_and_id = SymbolTable::new_symbol(cl_instance_name_and_id);
 }
 
-ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_shortlived) :
+ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool has_class_mirror_holder) :
   _metaspace(NULL),
   _metaspace_lock(new Mutex(Mutex::leaf+1, "Metaspace allocation lock", true,
                             Mutex::_safepoint_check_never)),
-  _unloading(false), _is_shortlived(is_shortlived),
+  _unloading(false), _has_class_mirror_holder(has_class_mirror_holder),
   _modified_oops(true), _accumulated_modified_oops(false),
   // An unsafe anonymous class loader data doesn't have anything to keep
   // it from being unloaded during parsing of the unsafe anonymous class.
   // The null-class-loader should always be kept alive.
-  _keep_alive((is_shortlived || h_class_loader.is_null()) ? 1 : 0),
+  _keep_alive((has_class_mirror_holder || h_class_loader.is_null()) ? 1 : 0),
   _claim(0),
   _handles(),
   _klasses(NULL), _packages(NULL), _modules(NULL), _unnamed_module(NULL), _dictionary(NULL),
@@ -150,7 +150,7 @@
     initialize_name(h_class_loader);
   }
 
-  if (!is_shortlived) {
+  if (!has_class_mirror_holder) {
     // The holder is initialized later for weak hidden and unsafe anonymous classes,
     // and before calling anything that call class_loader().
     initialize_holder(h_class_loader);
@@ -297,14 +297,14 @@
 // ClassLoaderData, no other non-GC thread has knowledge of the hidden or unsafe anonymous class while
 // it is being defined, therefore _keep_alive is not volatile or atomic.
 void ClassLoaderData::inc_keep_alive() {
-  if (is_shortlived()) {
+  if (has_class_mirror_holder()) {
     assert(_keep_alive > 0, "Invalid keep alive increment count");
     _keep_alive++;
   }
 }
 
 void ClassLoaderData::dec_keep_alive() {
-  if (is_shortlived()) {
+  if (has_class_mirror_holder()) {
     assert(_keep_alive > 0, "Invalid keep alive decrement count");
     _keep_alive--;
   }
@@ -410,14 +410,14 @@
 
   // Do not need to record dependency if the dependency is to a class whose
   // class loader data is never freed.  (i.e. the dependency's class loader
-  // is one of the three builtin class loaders and the dependency is not
-  // short-lived.)
+  // is one of the three builtin class loaders and the dependency's class
+  // loader data has a ClassLoader holder, not a Class holder.)
   if (to_cld->is_permanent_class_loader_data()) {
     return;
   }
 
   oop to;
-  if (to_cld->is_shortlived()) {
+  if (to_cld->has_class_mirror_holder()) {
     // Just return if a weak hidden or unsafe anonymous class is attempting to record a dependency
     // to itself.  (Note that every weak hidden or unsafe anonymous class has its own unique class
     // loader data.)
@@ -572,7 +572,7 @@
 const int _default_loader_dictionary_size = 107;
 
 Dictionary* ClassLoaderData::create_dictionary() {
-  assert(!is_shortlived(), "short lived class loader data do not have a dictionary");
+  assert(!has_class_mirror_holder(), "class mirror holder cld does not have a dictionary");
   int size;
   bool resizable = false;
   if (_the_null_class_loader_data == NULL) {
@@ -716,13 +716,13 @@
 
 // Returns true if this class loader data is for the app class loader
 // or a user defined system class loader.  (Note that the class loader
-// data may be short-lived.)
+// data may have a Class holder.)
 bool ClassLoaderData::is_system_class_loader_data() const {
   return SystemDictionary::is_system_class_loader(class_loader());
 }
 
 // Returns true if this class loader data is for the platform class loader.
-// (Note that the class loader data may be short-lived.)
+// (Note that the class loader data may have a Class holder.)
 bool ClassLoaderData::is_platform_class_loader_data() const {
   return SystemDictionary::is_platform_class_loader(class_loader());
 }
@@ -742,7 +742,7 @@
 // that is not ever freed by a GC.  It must be the CLD for one of the builtin
 // class loaders and not the CLD for a weak hidden or unsafe anonymous class.
 bool ClassLoaderData::is_permanent_class_loader_data() const {
-  return is_builtin_class_loader_data() && !is_shortlived();
+  return is_builtin_class_loader_data() && !has_class_mirror_holder();
 }
 
 ClassLoaderMetaspace* ClassLoaderData::metaspace_non_null() {
@@ -759,8 +759,8 @@
       if (this == the_null_class_loader_data()) {
         assert (class_loader() == NULL, "Must be");
         metaspace = new ClassLoaderMetaspace(_metaspace_lock, Metaspace::BootMetaspaceType);
-      } else if (is_shortlived()) {
-        metaspace = new ClassLoaderMetaspace(_metaspace_lock, Metaspace::ShortLivedMetaspaceType);
+      } else if (has_class_mirror_holder()) {
+        metaspace = new ClassLoaderMetaspace(_metaspace_lock, Metaspace::ClassMirrorHolderMetaspaceType);
       } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
         metaspace = new ClassLoaderMetaspace(_metaspace_lock, Metaspace::ReflectionMetaspaceType);
       } else {
@@ -878,7 +878,7 @@
 }
 
 // These CLDs are to contain weak hidden or unsafe anonymous classes used for JSR292
-ClassLoaderData* ClassLoaderData::shortlived_class_loader_data(Handle loader) {
+ClassLoaderData* ClassLoaderData::has_class_mirror_holder_cld(Handle loader) {
   // Add a new class loader data to the graph.
   return ClassLoaderDataGraph::add(loader, true);
 }
@@ -920,8 +920,8 @@
     // loader data: 0xsomeaddr of 'bootstrap'
     out->print("loader data: " INTPTR_FORMAT " of %s", p2i(this), loader_name_and_id());
   }
-  if (_is_shortlived) {
-    out->print(" short-lived");
+  if (_has_class_mirror_holder) {
+    out->print(" has a class holder");
   }
 }
 
@@ -931,7 +931,7 @@
 void ClassLoaderData::print_on(outputStream* out) const {
   out->print("ClassLoaderData CLD: " PTR_FORMAT ", loader: " PTR_FORMAT ", loader_klass: %s {",
               p2i(this), p2i(_class_loader.ptr_raw()), loader_name_and_id());
-  if (is_shortlived()) out->print(" short-lived");
+  if (has_class_mirror_holder()) out->print(" has a class holder");
   if (claimed()) out->print(" claimed");
   if (is_unloading()) out->print(" unloading");
   out->print(" metaspace: " INTPTR_FORMAT, p2i(metaspace_or_null()));
@@ -951,8 +951,8 @@
   assert_locked_or_safepoint(_metaspace_lock);
   oop cl = class_loader();
 
-  guarantee(this == class_loader_data(cl) || is_shortlived(), "Must be the same");
-  guarantee(cl != NULL || this == ClassLoaderData::the_null_class_loader_data() || is_shortlived(), "must be");
+  guarantee(this == class_loader_data(cl) || has_class_mirror_holder(), "Must be the same");
+  guarantee(cl != NULL || this == ClassLoaderData::the_null_class_loader_data() || has_class_mirror_holder(), "must be");
 
   // Verify the integrity of the allocated space.
   if (metaspace_or_null() != NULL) {
--- a/src/hotspot/share/classfile/classLoaderData.hpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/classLoaderData.hpp	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -117,8 +117,10 @@
                                     // classes in the class loader are allocated.
   Mutex* _metaspace_lock;  // Locks the metaspace for allocations and setup.
   bool _unloading;         // true if this class loader goes away
-  bool _is_shortlived;     // CLD is dedicated to one class and that class determines the CLDs lifecycle.
-                           // For example, a weak hidden or an unsafe anonymous class.
+  bool _has_class_mirror_holder; // If true, CLD is dedicated to one class and that class determines
+                                 // the CLDs lifecycle.  For example, a non-strong hidden class or an
+                                 // unsafe anonymous class.  Arrays of these classes are also assigned
+                                 // to these class loader datas.
 
   // Remembered sets support for the oops in the class loader data.
   bool _modified_oops;             // Card Table Equivalent (YC/CMS support)
@@ -162,7 +164,7 @@
   void set_next(ClassLoaderData* next) { _next = next; }
   ClassLoaderData* next() const        { return Atomic::load(&_next); }
 
-  ClassLoaderData(Handle h_class_loader, bool is_shortlived);
+  ClassLoaderData(Handle h_class_loader, bool has_class_mirror_holder);
   ~ClassLoaderData();
 
   // The CLD are not placed in the Heap, so the Card Table or
@@ -231,7 +233,7 @@
 
   Mutex* metaspace_lock() const { return _metaspace_lock; }
 
-  bool is_shortlived() const { return _is_shortlived; }
+  bool has_class_mirror_holder() const { return _has_class_mirror_holder; }
 
   static void init_null_class_loader_data();
 
@@ -313,7 +315,7 @@
 
   static ClassLoaderData* class_loader_data(oop loader);
   static ClassLoaderData* class_loader_data_or_null(oop loader);
-  static ClassLoaderData* shortlived_class_loader_data(Handle loader);
+  static ClassLoaderData* has_class_mirror_holder_cld(Handle loader);
 
   // Returns Klass* of associated class loader, or NULL if associated loader is 'bootstrap'.
   // Also works if unloading.
--- a/src/hotspot/share/classfile/classLoaderDataGraph.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/classLoaderDataGraph.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -192,7 +192,7 @@
 
 // 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_to_graph(Handle loader, bool is_shortlived) {
+ClassLoaderData* ClassLoaderDataGraph::add_to_graph(Handle loader, bool has_class_mirror_holder) {
 
   assert_lock_strong(ClassLoaderDataGraph_lock);
 
@@ -200,7 +200,7 @@
 
   // First check if another thread beat us to creating the CLD and installing
   // it into the loader while we were waiting for the lock.
-  if (!is_shortlived && loader.not_null()) {
+  if (!has_class_mirror_holder && loader.not_null()) {
     cld = java_lang_ClassLoader::loader_data_acquire(loader());
     if (cld != NULL) {
       return cld;
@@ -212,14 +212,14 @@
   // loader oop in all collections, particularly young collections.
   NoSafepointVerifier no_safepoints;
 
-  cld = new ClassLoaderData(loader, is_shortlived);
+  cld = new ClassLoaderData(loader, has_class_mirror_holder);
 
   // First install the new CLD to the Graph.
   cld->set_next(_head);
   Atomic::release_store(&_head, cld);
 
   // Next associate with the class_loader.
-  if (!is_shortlived) {
+  if (!has_class_mirror_holder) {
     // Use OrderAccess, since readers need to get the loader_data only after
     // it's added to the Graph
     java_lang_ClassLoader::release_set_loader_data(loader(), cld);
@@ -237,9 +237,9 @@
   return cld;
 }
 
-ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_shortlived) {
+ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool has_class_mirror_holder) {
   MutexLocker ml(ClassLoaderDataGraph_lock);
-  ClassLoaderData* loader_data = add_to_graph(loader, is_shortlived);
+  ClassLoaderData* loader_data = add_to_graph(loader, has_class_mirror_holder);
   return loader_data;
 }
 
--- a/src/hotspot/share/classfile/classLoaderDataGraph.hpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/classLoaderDataGraph.hpp	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -56,8 +56,8 @@
   static volatile size_t  _num_instance_classes;
   static volatile size_t  _num_array_classes;
 
-  static ClassLoaderData* add_to_graph(Handle class_loader, bool is_shortlived);
-  static ClassLoaderData* add(Handle class_loader, bool is_shortlived);
+  static ClassLoaderData* add_to_graph(Handle class_loader, bool has_class_mirror_holder);
+  static ClassLoaderData* add(Handle class_loader, bool has_class_mirror_holder);
 
  public:
   static ClassLoaderData* find_or_create(Handle class_loader);
--- a/src/hotspot/share/classfile/classLoaderHierarchyDCmd.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/classLoaderHierarchyDCmd.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -180,7 +180,7 @@
     if (_cld->is_the_null_class_loader_data()) {
       st->print(" <bootstrap>");
     } else {
-      assert(!_cld->is_shortlived(), "_cld must be the primary cld");
+      assert(!_cld->has_class_mirror_holder(), "_cld must be the primary cld");
       if (loader_name != NULL) {
         st->print(" \"%s\",", loader_name->as_C_string());
       }
@@ -353,10 +353,10 @@
     _next = info;
   }
 
-  void add_classes(LoadedClassInfo* first_class, int num_classes, bool is_shortlived) {
+  void add_classes(LoadedClassInfo* first_class, int num_classes, bool has_class_mirror_holder) {
     LoadedClassInfo** p_list_to_add_to;
     bool is_hidden = first_class->_klass->is_hidden();
-    if (is_shortlived) {
+    if (has_class_mirror_holder) {
       p_list_to_add_to = is_hidden ? &_hidden_weak_classes : &_anon_classes;
     } else {
       p_list_to_add_to = &_classes;
@@ -366,7 +366,7 @@
       p_list_to_add_to = &(*p_list_to_add_to)->_next;
     }
     *p_list_to_add_to = first_class;
-    if (is_shortlived) {
+    if (has_class_mirror_holder) {
       if (is_hidden) {
         _num_hidden_weak_classes += num_classes;
       } else {
@@ -465,7 +465,7 @@
     LoadedClassCollectClosure lccc(cld);
     const_cast<ClassLoaderData*>(cld)->classes_do(&lccc);
     if (lccc._num_classes > 0) {
-      info->add_classes(lccc._list, lccc._num_classes, cld->is_shortlived());
+      info->add_classes(lccc._list, lccc._num_classes, cld->has_class_mirror_holder());
     }
   }
 
@@ -525,7 +525,7 @@
     assert(info != NULL, "must be");
 
     // Update CLD in node, but only if this is the primary CLD for this loader.
-    if (cld->is_shortlived() == false) {
+    if (cld->has_class_mirror_holder() == false) {
       assert(info->cld() == NULL, "there should be only one primary CLD per loader");
       info->set_cld(cld);
     }
--- a/src/hotspot/share/classfile/classLoaderStats.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/classLoaderStats.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -60,7 +60,7 @@
     cls = *cls_ptr;
   }
 
-  if (!cld->is_shortlived()) {
+  if (!cld->has_class_mirror_holder()) {
     cls->_cld = cld;
   }
 
@@ -73,8 +73,8 @@
   ClassStatsClosure csc;
   cld->classes_do(&csc);
   bool is_hidden = false;
-  if(cld->is_shortlived()) {
-    // if cld is short lived then it must be either hidden or unsafe anonymous.
+  if(cld->has_class_mirror_holder()) {
+    // if cld has a class holder then it must be either hidden or unsafe anonymous.
     Klass* k = cld->klasses();
     // if it's an array class then need to see if bottom class is hidden.
     if (k->is_array_klass()) {
@@ -82,7 +82,7 @@
     }
     is_hidden = k->is_hidden();
     if (is_hidden) {
-      cls->_hidden_weak_classes_count += csc._num_classes;
+      cls->_hidden_classes_count += csc._num_classes;
     } else {
       cls->_anon_classes_count += csc._num_classes;
     }
@@ -93,10 +93,10 @@
 
   ClassLoaderMetaspace* ms = cld->metaspace_or_null();
   if (ms != NULL) {
-    if(cld->is_shortlived()) {
+    if(cld->has_class_mirror_holder()) {
       if (is_hidden) {
-        cls->_hidden_weak_chunk_sz += ms->allocated_chunks_bytes();
-        cls->_hidden_weak_block_sz += ms->allocated_blocks_bytes();
+        cls->_hidden_chunk_sz += ms->allocated_chunks_bytes();
+        cls->_hidden_block_sz += ms->allocated_blocks_bytes();
       } else {
         cls->_anon_chunk_sz += ms->allocated_chunks_bytes();
         cls->_anon_block_sz += ms->allocated_blocks_bytes();
@@ -139,11 +139,11 @@
         cls->_anon_classes_count,
         cls->_anon_chunk_sz, cls->_anon_block_sz);
   }
-  if (cls->_hidden_weak_classes_count > 0) {
-    _out->print_cr(SPACE SPACE SPACE "                                    " UINTX_FORMAT_W(6) "  " SIZE_FORMAT_W(8) "  " SIZE_FORMAT_W(8) "   + hidden weak classes",
+  if (cls->_hidden_classes_count > 0) {
+    _out->print_cr(SPACE SPACE SPACE "                                    " UINTX_FORMAT_W(6) "  " SIZE_FORMAT_W(8) "  " SIZE_FORMAT_W(8) "   + hidden classes",
         "", "", "",
-        cls->_hidden_weak_classes_count,
-        cls->_hidden_weak_chunk_sz, cls->_hidden_weak_block_sz);
+        cls->_hidden_classes_count,
+        cls->_hidden_chunk_sz, cls->_hidden_block_sz);
   }
   return true;
 }
--- a/src/hotspot/share/classfile/classLoaderStats.hpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/classLoaderStats.hpp	Mon Mar 23 20:05:49 2020 +0000
@@ -81,9 +81,9 @@
   size_t            _anon_block_sz;
   uintx             _anon_classes_count;
 
-  size_t            _hidden_weak_chunk_sz;
-  size_t            _hidden_weak_block_sz;
-  uintx             _hidden_weak_classes_count;
+  size_t            _hidden_chunk_sz;
+  size_t            _hidden_block_sz;
+  uintx             _hidden_classes_count;
 
   ClassLoaderStats() :
     _cld(0),
@@ -95,9 +95,9 @@
     _anon_chunk_sz(0),
     _anon_block_sz(0),
     _anon_classes_count(0),
-    _hidden_weak_chunk_sz(0),
-    _hidden_weak_block_sz(0),
-    _hidden_weak_classes_count(0) {
+    _hidden_chunk_sz(0),
+    _hidden_block_sz(0),
+    _hidden_classes_count(0) {
   }
 };
 
--- a/src/hotspot/share/classfile/dictionary.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/dictionary.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -354,7 +354,7 @@
 // since been unreferenced, so this entry should be cleared.
 void Dictionary::clean_cached_protection_domains() {
   assert_locked_or_safepoint(SystemDictionary_lock);
-  assert(!loader_data()->is_shortlived(), "class loader data shouldn't be short-lived");
+  assert(!loader_data()->has_class_mirror_holder(), "cld should have a ClassLoader holder not a Class holder");
 
   if (loader_data()->is_the_null_class_loader_data()) {
     // Classes in the boot loader are not loaded with protection domains
@@ -483,7 +483,7 @@
   ResourceMark rm;
 
   assert(loader_data() != NULL, "loader data should not be null");
-  assert(!loader_data()->is_shortlived(), "class loader data shouldn't be short-lived");
+  assert(!loader_data()->has_class_mirror_holder(), "cld should have a ClassLoader holder not a Class holder");
   st->print_cr("Java dictionary (table_size=%d, classes=%d, resizable=%s)",
                table_size(), number_of_entries(), BOOL_TO_STR(_resizable));
   st->print_cr("^ indicates that initiating loader is different from defining loader");
--- a/src/hotspot/share/classfile/klassFactory.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/klassFactory.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
+* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
@@ -213,11 +213,6 @@
 
   const ClassInstanceInfo* cl_inst_info = cl_info.class_hidden_info_ptr();
   InstanceKlass* result = parser.create_instance_klass(old_stream != stream, *cl_inst_info, CHECK_NULL);
-#ifdef ASSERT
-  // Need a NULL dynamic_nest_host here otherwise set_nest_host() may assert.
-  ClassInstanceInfo cl_inst_info_null(NULL, cl_inst_info->class_data());
-  assert(result == parser.create_instance_klass(old_stream != stream, cl_inst_info_null, THREAD), "invariant");
-#endif
 
   if (result == NULL) {
     return NULL;
--- a/src/hotspot/share/classfile/moduleEntry.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/moduleEntry.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -75,7 +75,7 @@
     const char* loc = location()->as_C_string();
     ClassLoaderData* cld = loader_data();
 
-    assert(!cld->is_shortlived(), "cld for module shouldn't be short-lived");
+    assert(!cld->has_class_mirror_holder(), "module's cld should have a ClassLoader holder not a Class holder");
     if ((cld->is_the_null_class_loader_data() || cld->is_platform_class_loader_data()) &&
         (strncmp(loc, "jrt:/java.", 10) == 0)) {
       return false;
@@ -136,7 +136,7 @@
   // injecting dependencies that require the default read edges for resolution.
   if (this->has_default_read_edges() && !m->is_named()) {
     ClassLoaderData* cld = m->loader_data();
-    assert(!cld->is_shortlived(), "cld for module shouldn't be short-lived");
+    assert(!cld->has_class_mirror_holder(), "module's cld should have a ClassLoader holder not a Class holder");
     if (cld->is_the_null_class_loader_data() || cld->is_system_class_loader_data()) {
       return true; // default read edge
     }
--- a/src/hotspot/share/classfile/moduleEntry.hpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/moduleEntry.hpp	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -110,7 +110,7 @@
   ClassLoaderData* loader_data() const                 { return _loader_data; }
 
   void set_loader_data(ClassLoaderData* cld) {
-    assert(!cld->is_shortlived(), "Unexpected short-lived class loader data");
+    assert(!cld->has_class_mirror_holder(), "Unexpected has_class_mirror_holder cld");
     _loader_data = cld;
   }
 
--- a/src/hotspot/share/classfile/systemDictionary.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/systemDictionary.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -118,7 +118,7 @@
   _class_hidden_info._dynamic_nest_host = NULL;
   _class_hidden_info._class_data = Handle();
   _is_hidden = false;
-  _is_weak_hidden = false;
+  _is_strong_hidden = false;
   _can_access_vm_annotations = false;
 }
 
@@ -129,7 +129,7 @@
   _class_hidden_info._dynamic_nest_host = NULL;
   _class_hidden_info._class_data = Handle();
   _is_hidden = false;
-  _is_weak_hidden = false;
+  _is_strong_hidden = false;
   _can_access_vm_annotations = false;
 }
 
@@ -139,7 +139,7 @@
                              InstanceKlass* dynamic_nest_host,
                              Handle class_data,
                              bool is_hidden,
-                             bool is_weak_hidden,
+                             bool is_strong_hidden,
                              bool can_access_vm_annotations) {
   _protection_domain = protection_domain;
   _unsafe_anonymous_host = unsafe_anonymous_host;
@@ -147,7 +147,7 @@
   _class_hidden_info._dynamic_nest_host = dynamic_nest_host;
   _class_hidden_info._class_data = class_data;
   _is_hidden = is_hidden;
-  _is_weak_hidden = is_weak_hidden;
+  _is_strong_hidden = is_strong_hidden;
   _can_access_vm_annotations = can_access_vm_annotations;
 }
 
@@ -1034,18 +1034,20 @@
 
   ClassLoaderData* loader_data;
 
-  if (cl_info.unsafe_anonymous_host() != NULL) {
-    // - for unsafe anonymous class: create a new short-lived CLD that uses the same
-    //                               class loader as the unsafe_anonymous_host.
+  bool is_unsafe_anon_class = cl_info.unsafe_anonymous_host() != NULL;
+
+  if (is_unsafe_anon_class) {
+    // - for unsafe anonymous class: create a new CLD whith a class holder that uses
+    //                               the same class loader as the unsafe_anonymous_host.
     guarantee(cl_info.unsafe_anonymous_host()->class_loader() == class_loader(),
               "should be the same");
-    loader_data = ClassLoaderData::shortlived_class_loader_data(class_loader);
+    loader_data = ClassLoaderData::has_class_mirror_holder_cld(class_loader);
   } else if (cl_info.is_hidden()) {
-    // - for weak hidden class: create a new short-lived CLD whose loader is
-    //                               the Lookup class' loader.
+    // - for hidden classes that are not strong: create a new CLD that has a class holder and
+    //                                           whose loader is the Lookup class' loader.
     // - for hidden class: add the class to the Lookup class' loader's CLD.
-    if (cl_info.is_weak_hidden()) {
-      loader_data = ClassLoaderData::shortlived_class_loader_data(class_loader);
+    if (!cl_info.is_strong_hidden()) {
+      loader_data = ClassLoaderData::has_class_mirror_holder_cld(class_loader);
     } else {
       // This hidden class goes into the regular CLD pool for this loader.
       loader_data = register_loader(class_loader);
@@ -1068,10 +1070,11 @@
                                                       cl_info,
                                                       CHECK_NULL);
 
-  if ((cl_info.is_hidden() || (cl_info.unsafe_anonymous_host() != NULL)) && k != NULL) {
-    // Weak hidden and unsafe anonymous classes must update ClassLoaderData holder
-    // so that they can be unloaded when the mirror is no longer referenced.
-    if (cl_info.is_weak_hidden() || (cl_info.unsafe_anonymous_host() != NULL)) {
+  if ((cl_info.is_hidden() || is_unsafe_anon_class) && k != NULL) {
+    // Hidden classes that are not strong and unsafe anonymous classes must update
+    // ClassLoaderData holder so that they can be unloaded when the mirror is no
+    // longer referenced.
+    if (!cl_info.is_strong_hidden() || is_unsafe_anon_class) {
       k->class_loader_data()->initialize_holder(Handle(THREAD, k->java_mirror()));
     }
 
@@ -1091,7 +1094,7 @@
     }
 
     // If it's anonymous, initialize it now, since nobody else will.
-    if (cl_info.unsafe_anonymous_host() != NULL) {
+    if (is_unsafe_anon_class) {
       k->eager_initialize(CHECK_NULL);
     }
 
@@ -1104,7 +1107,7 @@
       post_class_load_event(&class_load_start_event, k, loader_data);
     }
   }
-  assert(cl_info.unsafe_anonymous_host() != NULL || NULL == cl_info.cp_patches(),
+  assert(is_unsafe_anon_class || NULL == cl_info.cp_patches(),
          "cp_patches only found with unsafe_anonymous_host");
 
   return k;
--- a/src/hotspot/share/classfile/systemDictionary.hpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/classfile/systemDictionary.hpp	Mon Mar 23 20:05:49 2020 +0000
@@ -61,7 +61,7 @@
   GrowableArray<Handle>* _cp_patches;
   ClassInstanceInfo      _class_hidden_info;
   bool                   _is_hidden;
-  bool                   _is_weak_hidden;
+  bool                   _is_strong_hidden;
   bool                   _can_access_vm_annotations;
 
  public:
@@ -69,7 +69,7 @@
   ClassLoadInfo(Handle protection_domain);
   ClassLoadInfo(Handle protection_domain, const InstanceKlass* unsafe_anonymous_host,
                 GrowableArray<Handle>* cp_patches, InstanceKlass* dynamic_nest_host,
-                Handle class_data, bool is_hidden, bool is_weak_hidden,
+                Handle class_data, bool is_hidden, bool is_strong_hidden,
                 bool can_access_vm_annotations);
 
   Handle protection_domain()             const { return _protection_domain; }
@@ -77,7 +77,7 @@
   GrowableArray<Handle>* cp_patches()    const { return _cp_patches; }
   const ClassInstanceInfo* class_hidden_info_ptr() const { return &_class_hidden_info; }
   bool is_hidden()                       const { return _is_hidden; }
-  bool is_weak_hidden()                  const { return _is_weak_hidden; }
+  bool is_strong_hidden()                const { return _is_strong_hidden; }
   bool can_access_vm_annotations()       const { return _can_access_vm_annotations; }
 };
 
@@ -319,6 +319,9 @@
                                               bool is_superclass,
                                               TRAPS);
 
+  // Parse new stream. This won't update the dictionary or class
+  // hierarchy, simply parse the stream. Used by JVMTI RedefineClasses
+  // and by Unsafe_DefineAnonymousClass and jvm_lookup_define_class.
   static InstanceKlass* parse_stream(Symbol* class_name,
                                      Handle class_loader,
                                      ClassFileStream* st,
--- a/src/hotspot/share/include/jvm.h	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/include/jvm.h	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -401,8 +401,8 @@
  *  classData: private static pre-initialized field; may be null
  */
 JNIEXPORT jclass JNICALL
-JVM_LookupDefineClass(JNIEnv *env, jclass lookup, const char *name, jobject loader,
-                      const jbyte *buf, jsize len, jobject pd, jboolean init, int flags, jobject classData);
+JVM_LookupDefineClass(JNIEnv *env, jclass lookup, const char *name, const jbyte *buf,
+                      jsize len, jobject pd, jboolean init, int flags, jobject classData);
 
 /*
  * Module support funcions
--- a/src/hotspot/share/jfr/metadata/metadata.xml	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/jfr/metadata/metadata.xml	Mon Mar 23 20:05:49 2020 +0000
@@ -219,7 +219,7 @@
     stackTrace="true">
     <Field type="ClassLoader" name="classLoader" label="Class Loader" />
     <Field type="boolean" name="unsafeAnonymousClassLoader" label="Unsafe Anonymous Class Loader" />
-    <Field type="boolean" name="hiddenWeakClassLoader" label="Hidden Weak Class Loader" />
+    <Field type="boolean" name="hiddenClassLoader" label="Hidden Class Loader" />
     <Field type="ulong" contentType="bytes" name="size" label="Size" />
     <Field type="MetadataType" name="metadataType" label="Metadata Type" />
     <Field type="MetaspaceObjectType" name="metaspaceObjectType" label="Metaspace Object Type" />
@@ -228,7 +228,7 @@
   <Event name="MetaspaceOOM" category="Java Virtual Machine, GC, Metaspace" label="Metaspace Out of Memory" startTime="false" stackTrace="true">
     <Field type="ClassLoader" name="classLoader" label="Class Loader" />
     <Field type="boolean" name="unsafeAnonymousClassLoader" label="Unsafe Anonymous Class Loader" />
-    <Field type="boolean" name="hiddenWeakClassLoader" label="Hidden Weak Class Loader" />
+    <Field type="boolean" name="hiddenClassLoader" label="Hidden Class Loader" />
     <Field type="ulong" contentType="bytes" name="size" label="Size" />
     <Field type="MetadataType" name="metadataType" label="Metadata Type" />
     <Field type="MetaspaceObjectType" name="metaspaceObjectType" label="Metaspace Object Type" />
@@ -726,11 +726,11 @@
       description="Total size of all allocated metaspace chunks for unsafe anonymous classes (each chunk has several blocks)" />
     <Field type="ulong" contentType="bytes" name="unsafeAnonymousBlockSize" label="Total Unsafe Anonymous Classes Block Size"
       description="Total size of all allocated metaspace blocks for unsafe anonymous classes (each chunk has several blocks)" />
-    <Field type="long" name="hiddenWeakClassCount" label="Hidden Weak Classes" description="Number of hidden weak classes" />
-    <Field type="ulong" contentType="bytes" name="hiddenWeakChunkSize" label="Total Hidden Weak Classes Chunk Size"
-      description="Total size of all allocated metaspace chunks for hidden weak classes (each chunk has several blocks)" />
-    <Field type="ulong" contentType="bytes" name="hiddenWeakBlockSize" label="Total Hidden Weak Classes Block Size"
-      description="Total size of all allocated metaspace blocks for hidden weak classes (each chunk has several blocks)" />
+    <Field type="long" name="hiddenClassCount" label="Hidden Classes" description="Number of hidden classes" />
+    <Field type="ulong" contentType="bytes" name="hiddenChunkSize" label="Total Hidden Classes Chunk Size"
+      description="Total size of all allocated metaspace chunks for hidden classes (each chunk has several blocks)" />
+    <Field type="ulong" contentType="bytes" name="hiddenBlockSize" label="Total Hidden Classes Block Size"
+      description="Total size of all allocated metaspace blocks for hidden classes (each chunk has several blocks)" />
   </Event>
 
   <Event name="SymbolTableStatistics" category="Java Virtual Machine, Runtime, Tables" label="Symbol Table Statistics" period="everyChunk">
--- a/src/hotspot/share/jfr/periodic/jfrPeriodic.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/jfr/periodic/jfrPeriodic.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -483,9 +483,9 @@
     event.set_unsafeAnonymousClassCount(cls->_anon_classes_count);
     event.set_unsafeAnonymousChunkSize(cls->_anon_chunk_sz);
     event.set_unsafeAnonymousBlockSize(cls->_anon_block_sz);
-    event.set_hiddenWeakClassCount(cls->_hidden_weak_classes_count);
-    event.set_hiddenWeakChunkSize(cls->_hidden_weak_chunk_sz);
-    event.set_hiddenWeakBlockSize(cls->_hidden_weak_block_sz);
+    event.set_hiddenClassCount(cls->_hidden_classes_count);
+    event.set_hiddenChunkSize(cls->_hidden_chunk_sz);
+    event.set_hiddenBlockSize(cls->_hidden_block_sz);
     event.commit();
     return true;
   }
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -605,7 +605,7 @@
   CLDCallback() {}
   void do_cld(ClassLoaderData* cld) {
     assert(cld != NULL, "invariant");
-    if (cld->is_shortlived()) {
+    if (cld->has_class_mirror_holder()) {
       return;
     }
     do_class_loader_data(cld);
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceId.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceId.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
  * 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,7 +140,7 @@
 
 void JfrTraceId::assign(const ClassLoaderData* cld) {
   assert(cld != NULL, "invariant");
-  if (cld->is_shortlived()) {
+  if (cld->has_class_mirror_holder()) {
     cld->set_trace_id(0);
     return;
   }
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp	Mon Mar 23 20:05:49 2020 +0000
@@ -114,7 +114,7 @@
 
 inline traceid JfrTraceId::use(const ClassLoaderData* cld) {
   assert(cld != NULL, "invariant");
-  return cld->is_shortlived() ? 0 : set_used_and_get(cld);
+  return cld->has_class_mirror_holder() ? 0 : set_used_and_get(cld);
 }
 
 inline void JfrTraceId::set_leakp(const Klass* klass, const Method* method) {
--- a/src/hotspot/share/memory/metaspace.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/memory/metaspace.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -64,7 +64,7 @@
   switch (t) {
     case Metaspace::StandardMetaspaceType: s = "Standard"; break;
     case Metaspace::BootMetaspaceType: s = "Boot"; break;
-    case Metaspace::ShortLivedMetaspaceType: s = "ShortLived"; break;
+    case Metaspace::ClassMirrorHolderMetaspaceType: s = "ClassMirrorHolder"; break;
     case Metaspace::ReflectionMetaspaceType: s = "Reflection"; break;
     default: ShouldNotReachHere();
   }
--- a/src/hotspot/share/memory/metaspace.hpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/memory/metaspace.hpp	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -104,8 +104,8 @@
     ZeroMetaspaceType = 0,
     StandardMetaspaceType = ZeroMetaspaceType,
     BootMetaspaceType = StandardMetaspaceType + 1,
-    ShortLivedMetaspaceType = BootMetaspaceType + 1,
-    ReflectionMetaspaceType = ShortLivedMetaspaceType + 1,
+    ClassMirrorHolderMetaspaceType = BootMetaspaceType + 1,
+    ReflectionMetaspaceType = ClassMirrorHolderMetaspaceType + 1,
     MetaspaceTypeCount
   };
 
--- a/src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -128,7 +128,7 @@
       _out->print(" (unloading)");
     }
     _out->print(":");
-    if (cld->is_shortlived()) {
+    if (cld->has_class_mirror_holder()) {
       _out->print(" <weak hidden or anonymous class>, loaded by");
     }
     if (name != NULL) {
--- a/src/hotspot/share/memory/metaspace/spaceManager.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/memory/metaspace/spaceManager.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -75,14 +75,14 @@
   if (is_class()) {
     switch (type) {
     case Metaspace::BootMetaspaceType:              requested = Metaspace::first_class_chunk_word_size(); break;
-    case Metaspace::ShortLivedMetaspaceType:        requested = ClassSpecializedChunk; break;
+    case Metaspace::ClassMirrorHolderMetaspaceType: requested = ClassSpecializedChunk; break;
     case Metaspace::ReflectionMetaspaceType:        requested = ClassSpecializedChunk; break;
     default:                                        requested = ClassSmallChunk; break;
     }
   } else {
     switch (type) {
     case Metaspace::BootMetaspaceType:              requested = Metaspace::first_chunk_word_size(); break;
-    case Metaspace::ShortLivedMetaspaceType:        requested = SpecializedChunk; break;
+    case Metaspace::ClassMirrorHolderMetaspaceType: requested = SpecializedChunk; break;
     case Metaspace::ReflectionMetaspaceType:        requested = SpecializedChunk; break;
     default:                                        requested = SmallChunk; break;
     }
@@ -115,14 +115,14 @@
   size_t chunk_word_size;
 
   // Special case for hidden metadata space.
-  // ShortLived metadata space is usually small since it is used for
+  // ClassMirrorHolder metadata space is usually small since it is used for
   // class loader data's whose life cycle is governed by one class such as a
   // weak hidden or unsafe anonymous class.  The majority within 1K - 2K range and
   // rarely about 4K (64-bits JVM).
   // Instead of jumping to SmallChunk after initial chunk exhausted, keeping allocation
   // from SpecializeChunk up to _anon_or_delegating_metadata_specialize_chunk_limit (4)
   // reduces space waste from 60+% to around 30%.
-  if ((_space_type == Metaspace::ShortLivedMetaspaceType || _space_type == Metaspace::ReflectionMetaspaceType) &&
+  if ((_space_type == Metaspace::ClassMirrorHolderMetaspaceType || _space_type == Metaspace::ReflectionMetaspaceType) &&
       _mdtype == Metaspace::NonClassType &&
       num_chunks_by_type(SpecializedIndex) < anon_and_delegating_metadata_specialize_chunk_limit &&
       word_size + Metachunk::overhead() <= SpecializedChunk) {
--- a/src/hotspot/share/memory/metaspaceTracer.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/memory/metaspaceTracer.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -63,11 +63,11 @@
   if (event.should_commit()) {
     event.set_classLoader(cld);
     event.set_unsafeAnonymousClassLoader(false); // initialize these
-    event.set_hiddenWeakClassLoader(false);
-    if (cld->is_shortlived()) {
+    event.set_hiddenClassLoader(false);
+    if (cld->has_class_mirror_holder()) {
       assert(cld->klasses() != NULL, "unexpected NULL for cld->klasses()");
       if (cld->klasses()->is_hidden_weak()) {
-        event.set_hiddenWeakClassLoader(true);
+        event.set_hiddenClassLoader(true);
       } else {
         event.set_unsafeAnonymousClassLoader(true);
       }
--- a/src/hotspot/share/oops/instanceKlass.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -2746,9 +2746,9 @@
 
   if (is_hidden() &&
       in_unnamed_package() &&
-      class_loader_data()->is_shortlived()) {
+      class_loader_data()->has_class_mirror_holder()) {
     // For a weak hidden class defined to an unnamed package,
-    // the short-lived CLD will not have an unnamed module created for it.
+    // its (class held) CLD will not have an unnamed module created for it.
     // Two choices to find the correct ModuleEntry:
     // 1. If hidden class is within a nest, use nest host's module
     // 2. Find the unnamed module off from the class loader
--- a/src/hotspot/share/oops/instanceMirrorKlass.inline.hpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/oops/instanceMirrorKlass.inline.hpp	Mon Mar 23 20:05:49 2020 +0000
@@ -1,4 +1,5 @@
-/* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
+/*
+ * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -51,7 +52,7 @@
     Klass* klass = java_lang_Class::as_Klass_raw(obj);
     // We'll get NULL for primitive mirrors.
     if (klass != NULL) {
-      if (klass->is_instance_klass() && klass->class_loader_data()->is_shortlived()) {
+      if (klass->is_instance_klass() && klass->class_loader_data()->has_class_mirror_holder()) {
         // A weak hidden or an unsafe anonymous class doesn't have its own class loader,
         // so when handling the java mirror for the class we need to make sure its class
         // loader data is claimed, this is done by calling do_cld explicitly.
--- a/src/hotspot/share/oops/klass.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/oops/klass.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -673,7 +673,7 @@
 }
 
 // Replace the last '+' char with '/'.
-char* Klass::convert_hidden_name_to_java(Symbol* name) {
+static char* convert_hidden_name_to_java(Symbol* name) {
   size_t name_len = name->utf8_length();
   char* result = NEW_RESOURCE_ARRAY(char, name_len + 1);
   name->as_klass_external_name(result, (int)name_len + 1);
--- a/src/hotspot/share/oops/klass.hpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/oops/klass.hpp	Mon Mar 23 20:05:49 2020 +0000
@@ -618,7 +618,7 @@
   bool is_hidden() const                { return access_flags().is_hidden_class(); }
   void set_is_hidden()                  { _access_flags.set_is_hidden_class(); }
   bool is_hidden_weak() const           { return access_flags().is_hidden_class() &&
-                                          class_loader_data()->is_shortlived(); }
+                                          class_loader_data()->has_class_mirror_holder(); }
 
   bool is_cloneable() const;
   void set_is_cloneable();
@@ -687,7 +687,6 @@
   virtual void oop_print_on      (oop obj, outputStream* st);
 
   virtual const char* internal_name() const = 0;
-  static char* convert_hidden_name_to_java(Symbol* name);
 
   // Verification
   virtual void verify_on(outputStream* st);
--- a/src/hotspot/share/prims/jvm.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/prims/jvm.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -997,7 +997,7 @@
  * hidden, or strongly referenced from class loader.
  */
 static jclass jvm_lookup_define_class(JNIEnv *env, jclass lookup, const char *name,
-                                      jobject loader, const jbyte *buf, jsize len, jobject pd,
+                                      const jbyte *buf, jsize len, jobject pd,
                                       jboolean init, int flags, jobject classData, TRAPS) {
   assert(THREAD->is_Java_thread(), "must be a JavaThread");
   JavaThread* jt = (JavaThread*) THREAD;
@@ -1010,6 +1010,9 @@
   }
   assert(lookup_k->is_instance_klass(), "Lookup class must be an instance klass");
 
+  oop loader = lookup_k->class_loader();
+  Handle class_loader (THREAD, loader);
+
   jboolean is_nestmate = (flags & NESTMATE) == NESTMATE;
   jboolean is_hidden = (flags & HIDDEN_CLASS) == HIDDEN_CLASS;
   jboolean is_strong = (flags & STRONG_LOADER_LINK) == STRONG_LOADER_LINK;
@@ -1069,7 +1072,6 @@
     class_name = SymbolTable::new_symbol(name, str_len);
   }
 
-  Handle class_loader (THREAD, JNIHandles::resolve(loader));
   Handle protection_domain (THREAD, JNIHandles::resolve(pd));
   const char* source = is_nestmate ? host_class->external_name() : "__JVM_LookupDefineClass__";
   ClassFileStream st((u1*)buf, len, source, ClassFileStream::verify);
@@ -1093,7 +1095,7 @@
                           host_class,
                           classData_h,
                           is_hidden,
-                          !is_strong,
+                          is_strong,
                           vm_annotations);
     defined_k = SystemDictionary::parse_stream(class_name,
                                                class_loader,
@@ -1151,8 +1153,8 @@
  *  flags:   properties of the class
  *  classData: private static pre-initialized field
  */
-JVM_ENTRY(jclass, JVM_LookupDefineClass(JNIEnv *env, jclass lookup, const char *name, jobject loader,
-                      const jbyte *buf, jsize len, jobject pd, jboolean initialize, int flags, jobject classData))
+JVM_ENTRY(jclass, JVM_LookupDefineClass(JNIEnv *env, jclass lookup, const char *name, const jbyte *buf,
+          jsize len, jobject pd, jboolean initialize, int flags, jobject classData))
   JVMWrapper("JVM_LookupDefineClass");
 
   if (lookup == NULL) {
@@ -1161,7 +1163,7 @@
 
   assert(buf != NULL, "buf must not be NULL");
 
-  return jvm_lookup_define_class(env, lookup, name, loader, buf, len, pd, initialize, flags, classData, THREAD);
+  return jvm_lookup_define_class(env, lookup, name, buf, len, pd, initialize, flags, classData, THREAD);
 JVM_END
 
 JVM_ENTRY(jclass, JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source))
--- a/src/hotspot/share/prims/unsafe.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/prims/unsafe.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -856,7 +856,7 @@
                         NULL,     // dynamic_nest_host
                         Handle(), // classData
                         false,    // is_hidden
-                        false,    // is_weak_hidden
+                        false,    // is_strong_hidden
                         true);    // can_access_vm_annotations
 
   Klass* anonk = SystemDictionary::parse_stream(no_class_name,
--- a/src/hotspot/share/runtime/vmStructs.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/hotspot/share/runtime/vmStructs.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -522,7 +522,7 @@
   nonstatic_field(ClassLoaderData,             _class_loader,                                 OopHandle)                             \
   nonstatic_field(ClassLoaderData,             _next,                                         ClassLoaderData*)                      \
   volatile_nonstatic_field(ClassLoaderData,    _klasses,                                      Klass*)                                \
-  nonstatic_field(ClassLoaderData,             _is_shortlived,                                bool)                                  \
+  nonstatic_field(ClassLoaderData,             _has_class_mirror_holder,                      bool)                                  \
   volatile_nonstatic_field(ClassLoaderData,    _dictionary,                                   Dictionary*)                           \
                                                                                                                                      \
   static_ptr_volatile_field(ClassLoaderDataGraph, _head,                                      ClassLoaderData*)                      \
--- a/src/java.base/share/native/libjava/ClassLoader.c	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/java.base/share/native/libjava/ClassLoader.c	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -261,7 +261,7 @@
         utfName = NULL;
     }
 
-    return JVM_LookupDefineClass(env, lookup, utfName, loader, body, length, pd, initialize, flags, classData);
+    return JVM_LookupDefineClass(env, lookup, utfName, body, length, pd, initialize, flags, classData);
 
  free_body:
     free(body);
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/classfile/ClassLoaderData.java	Mon Mar 23 17:05:02 2020 +0000
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/classfile/ClassLoaderData.java	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -44,14 +44,14 @@
     classLoaderFieldOffset = type.getAddressField("_class_loader").getOffset();
     nextField = type.getAddressField("_next");
     klassesField = new MetadataField(type.getAddressField("_klasses"), 0);
-    isShortlivedField = new CIntField(type.getCIntegerField("_is_shortlived"), 0);
+    hasClassMirrorHolderField = new CIntField(type.getCIntegerField("_has_class_mirror_holder"), 0);
     dictionaryField = type.getAddressField("_dictionary");
   }
 
   private static long classLoaderFieldOffset;
   private static AddressField nextField;
   private static MetadataField  klassesField;
-  private static CIntField isShortlivedField;
+  private static CIntField hasClassMirrorHolderField;
   private static AddressField dictionaryField;
 
   public ClassLoaderData(Address addr) {
@@ -76,8 +76,8 @@
     return vmOopHandle.resolve();
   }
 
-  public boolean getisShortlived() {
-    return isShortlivedField.getValue(this) != 0;
+  public boolean gethasClassMirrorHolder() {
+    return hasClassMirrorHolderField.getValue(this) != 0;
   }
 
   public ClassLoaderData next() {
--- a/test/hotspot/gtest/memory/test_metaspace_allocation.cpp	Mon Mar 23 17:05:02 2020 +0000
+++ b/test/hotspot/gtest/memory/test_metaspace_allocation.cpp	Mon Mar 23 20:05:49 2020 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2018, SAP.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -104,7 +104,7 @@
     }
     // Let every ~10th space be a short-lived one to test different allocation patterns.
     const Metaspace::MetaspaceType msType = (os::random() % 100 < 10) ?
-      Metaspace::ShortLivedMetaspaceType : Metaspace::StandardMetaspaceType;
+      Metaspace::ClassMirrorHolderMetaspaceType : Metaspace::StandardMetaspaceType;
     {
       // Pull lock during space creation, since this is what happens in the VM too
       // (see ClassLoaderData::metaspace_non_null(), which we mimick here).
--- a/test/hotspot/jtreg/serviceability/dcmd/vm/ClassLoaderStatsTest.java	Mon Mar 23 17:05:02 2020 +0000
+++ b/test/hotspot/jtreg/serviceability/dcmd/vm/ClassLoaderStatsTest.java	Mon Mar 23 20:05:49 2020 +0000
@@ -113,7 +113,7 @@
 
                     next = lines.next();
                     System.out.println("DummyClassLoader next: " + next);
-                    if (!next.contains("hidden weak classes")) {
+                    if (!next.contains("hidden classes")) {
                         Assert.fail("Should have a hidden class");
                     }
                     Matcher m2 = anonLine.matcher(next);
--- a/test/jdk/jdk/jfr/event/runtime/TestClassLoaderStatsEvent.java	Mon Mar 23 17:05:02 2020 +0000
+++ b/test/jdk/jdk/jfr/event/runtime/TestClassLoaderStatsEvent.java	Mon Mar 23 20:05:49 2020 +0000
@@ -84,9 +84,9 @@
                 Events.assertField(event, "unsafeAnonymousClassCount").equal(2L);
                 Events.assertField(event, "unsafeAnonymousChunkSize").above(0L);
                 Events.assertField(event, "unsafeAnonymousBlockSize").above(0L);
-                Events.assertField(event, "hiddenWeakClassCount").equal(2L);
-                Events.assertField(event, "hiddenWeakChunkSize").above(0L);
-                Events.assertField(event, "hiddenWeakBlockSize").above(0L);
+                Events.assertField(event, "hiddenClassCount").equal(2L);
+                Events.assertField(event, "hiddenChunkSize").above(0L);
+                Events.assertField(event, "hiddenBlockSize").above(0L);
                 isAnyFound = true;
             }
         }