8190235: Clarify ClassLoaderData::is_*_class_loader_data() method implementations
authorhseigel
Tue, 06 Feb 2018 13:41:49 -0500
changeset 48871 120d6893f32f
parent 48870 90990a7ff502
child 48872 c7774afc93e3
8190235: Clarify ClassLoaderData::is_*_class_loader_data() method implementations Summary: Add comments, fix a small issue with the boot loader, and add an assert. Reviewed-by: coleenp, lfoltan, gtriantafill
src/hotspot/share/classfile/classLoaderData.cpp
src/hotspot/share/classfile/classLoaderData.hpp
src/hotspot/share/classfile/moduleEntry.hpp
--- a/src/hotspot/share/classfile/classLoaderData.cpp	Tue Feb 06 09:35:05 2018 -0800
+++ b/src/hotspot/share/classfile/classLoaderData.cpp	Tue Feb 06 13:41:49 2018 -0500
@@ -693,23 +693,26 @@
   }
 }
 
-// Returns true if this class loader data is for the system class loader.
+// 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 anonymous.)
 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 anonymous.)
 bool ClassLoaderData::is_platform_class_loader_data() const {
   return SystemDictionary::is_platform_class_loader(class_loader());
 }
 
-// Returns true if this class loader data is one of the 3 builtin
-// (boot, application/system or platform) class loaders.  Note that
-// if the class loader data is for an anonymous class then it may get
-// freed by a GC even if its class loader is one of the 3 builtin
-// loaders.
+// Returns true if the class loader for this class loader data is one of
+// the 3 builtin (boot application/system or platform) class loaders,
+// including a user-defined system class loader.  Note that if the class
+// loader data is for an anonymous class then it may get freed by a GC
+// even if its class loader is one of these loaders.
 bool ClassLoaderData::is_builtin_class_loader_data() const {
-  return (is_the_null_class_loader_data() ||
+  return (is_boot_class_loader_data() ||
           SystemDictionary::is_system_class_loader(class_loader()) ||
           SystemDictionary::is_platform_class_loader(class_loader()));
 }
--- a/src/hotspot/share/classfile/classLoaderData.hpp	Tue Feb 06 09:35:05 2018 -0800
+++ b/src/hotspot/share/classfile/classLoaderData.hpp	Tue Feb 06 13:41:49 2018 -0500
@@ -344,6 +344,13 @@
   }
   bool is_system_class_loader_data() const;
   bool is_platform_class_loader_data() const;
+
+  // 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;
+  }
+
   bool is_builtin_class_loader_data() const;
   bool is_permanent_class_loader_data() const;
 
--- a/src/hotspot/share/classfile/moduleEntry.hpp	Tue Feb 06 09:35:05 2018 -0800
+++ b/src/hotspot/share/classfile/moduleEntry.hpp	Tue Feb 06 13:41:49 2018 -0500
@@ -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
@@ -103,7 +103,11 @@
   void             set_shared_protection_domain(ClassLoaderData *loader_data, Handle pd);
 
   ClassLoaderData* loader_data() const                 { return _loader_data; }
-  void             set_loader_data(ClassLoaderData* l) { _loader_data = l; }
+
+  void set_loader_data(ClassLoaderData* cld) {
+    assert(!cld->is_anonymous(), "Unexpected anonymous class loader data");
+    _loader_data = cld;
+  }
 
   Symbol*          version() const                     { return _version; }
   void             set_version(Symbol* version);