< prev index next >

src/hotspot/share/classfile/packageEntry.hpp

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_CLASSFILE_PACKAGEENTRY_HPP
  26 #define SHARE_CLASSFILE_PACKAGEENTRY_HPP
  27 
  28 #include "classfile/moduleEntry.hpp"
  29 #include "oops/symbol.hpp"

  30 #include "utilities/growableArray.hpp"
  31 #include "utilities/hashtable.hpp"
  32 #include "utilities/macros.hpp"
  33 #include "utilities/ostream.hpp"
  34 #if INCLUDE_JFR
  35 #include "jfr/support/jfrTraceIdExtension.hpp"
  36 #endif
  37 
  38 
  39 // A PackageEntry basically represents a Java package.  It contains:
  40 //   - Symbol* containing the package's name.
  41 //   - ModuleEntry* for this package's containing module.
  42 //   - a field indicating if the package is exported unqualifiedly or to all
  43 //     unnamed modules.
  44 //   - a growable array containing other module entries that this
  45 //     package is exported to.
  46 //
  47 // Packages can be exported in the following 3 ways:
  48 //   - not exported:        the package does not have qualified or unqualified exports.
  49 //   - qualified exports:   the package has been explicitly qualified to at least


  77 // Valid states are:
  78 //
  79 //   1. Package is not exported
  80 //      _export_flags is zero and _qualified_exports is null
  81 //   2. Package is unqualifiedly exported
  82 //      _export_flags is set to PKG_EXP_UNQUALIFIED
  83 //      _qualified_exports may or may not be null depending on whether the package
  84 //        transitioned from qualifiedly exported to unqualifiedly exported.
  85 //   3. Package is qualifiedly exported
  86 //      _export_flags may be set to PKG_EXP_ALLUNNAMED if the package is also
  87 //        exported to all unnamed modules
  88 //      _qualified_exports will be non-null
  89 //   4. Package is exported to all unnamed modules
  90 //      _export_flags is set to PKG_EXP_ALLUNNAMED
  91 //      _qualified_exports may or may not be null depending on whether the package
  92 //        is also qualifiedly exported to one or more named modules.
  93 #define PKG_EXP_UNQUALIFIED  0x0001
  94 #define PKG_EXP_ALLUNNAMED   0x0002
  95 #define PKG_EXP_UNQUALIFIED_OR_ALL_UNAMED (PKG_EXP_UNQUALIFIED | PKG_EXP_ALLUNNAMED)
  96 


  97 class PackageEntry : public HashtableEntry<Symbol*, mtModule> {
  98 private:
  99   ModuleEntry* _module;
 100   // Indicates if package is exported unqualifiedly or to all unnamed. Access to
 101   // this field is protected by the Module_lock.
 102   int _export_flags;
 103   // Used to indicate for packages with classes loaded by the boot loader that
 104   // a class in that package has been loaded.  And, for packages with classes
 105   // loaded by the boot loader from -Xbootclasspath/a in an unnamed module, it
 106   // indicates from which class path entry.
 107   s2 _classpath_index;
 108   bool _must_walk_exports;
 109   // Contains list of modules this package is qualifiedly exported to.  Access
 110   // to this list is protected by the Module_lock.
 111   GrowableArray<ModuleEntry*>* _qualified_exports;
 112   JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
 113 
 114   // Initial size of a package entry's list of qualified exports.
 115   enum {QUAL_EXP_SIZE = 43};
 116 


 117 public:
 118   void init() {
 119     _module = NULL;
 120     _export_flags = 0;
 121     _classpath_index = -1;
 122     _must_walk_exports = false;
 123     _qualified_exports = NULL;

 124   }
 125 
 126   // package name
 127   Symbol*            name() const               { return literal(); }
 128 
 129   // the module containing the package definition
 130   ModuleEntry*       module() const             { return _module; }
 131   void               set_module(ModuleEntry* m) { _module = m; }
 132 
 133   // package's export state
 134   bool is_exported() const { // qualifiedly or unqualifiedly exported
 135     assert_locked_or_safepoint(Module_lock);
 136     return module()->is_open() ||
 137             ((_export_flags & PKG_EXP_UNQUALIFIED_OR_ALL_UNAMED) != 0) ||
 138             has_qual_exports_list();
 139   }
 140   // Returns true if the package has any explicit qualified exports or is exported to all unnamed
 141   bool is_qual_exported() const {
 142     assert_locked_or_safepoint(Module_lock);
 143     return (has_qual_exports_list() || is_exported_allUnnamed());


 195 
 196   PackageEntry* next() const {
 197     return (PackageEntry*)HashtableEntry<Symbol*, mtModule>::next();
 198   }
 199 
 200   PackageEntry** next_addr() {
 201     return (PackageEntry**)HashtableEntry<Symbol*, mtModule>::next_addr();
 202   }
 203 
 204   // iteration of qualified exports
 205   void package_exports_do(ModuleClosure* f);
 206 
 207   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
 208 
 209   // Purge dead weak references out of exported list when any given class loader is unloaded.
 210   void purge_qualified_exports();
 211   void delete_qualified_exports();
 212 
 213   void print(outputStream* st = tty);
 214   void verify();












 215 };
 216 
 217 // The PackageEntryTable is a Hashtable containing a list of all packages defined
 218 // by a particular class loader.  Each package is represented as a PackageEntry node.
 219 // The PackageEntryTable's lookup is lock free.
 220 //
 221 class PackageEntryTable : public Hashtable<Symbol*, mtModule> {
 222   friend class VMStructs;
 223 public:
 224   enum Constants {
 225     _packagetable_entry_size = 109  // number of entries in package entry table
 226   };
 227 
 228 private:
 229   PackageEntry* new_entry(unsigned int hash, Symbol* name, ModuleEntry* module);
 230   void add_entry(int index, PackageEntry* new_entry);
 231 
 232   int entry_size() const { return BasicHashtable<mtModule>::entry_size(); }
 233 
 234   PackageEntry** bucket_addr(int i) {




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_CLASSFILE_PACKAGEENTRY_HPP
  26 #define SHARE_CLASSFILE_PACKAGEENTRY_HPP
  27 
  28 #include "classfile/moduleEntry.hpp"
  29 #include "oops/symbol.hpp"
  30 #include "runtime/atomic.hpp"
  31 #include "utilities/growableArray.hpp"
  32 #include "utilities/hashtable.hpp"
  33 #include "utilities/macros.hpp"
  34 #include "utilities/ostream.hpp"
  35 #if INCLUDE_JFR
  36 #include "jfr/support/jfrTraceIdExtension.hpp"
  37 #endif
  38 
  39 
  40 // A PackageEntry basically represents a Java package.  It contains:
  41 //   - Symbol* containing the package's name.
  42 //   - ModuleEntry* for this package's containing module.
  43 //   - a field indicating if the package is exported unqualifiedly or to all
  44 //     unnamed modules.
  45 //   - a growable array containing other module entries that this
  46 //     package is exported to.
  47 //
  48 // Packages can be exported in the following 3 ways:
  49 //   - not exported:        the package does not have qualified or unqualified exports.
  50 //   - qualified exports:   the package has been explicitly qualified to at least


  78 // Valid states are:
  79 //
  80 //   1. Package is not exported
  81 //      _export_flags is zero and _qualified_exports is null
  82 //   2. Package is unqualifiedly exported
  83 //      _export_flags is set to PKG_EXP_UNQUALIFIED
  84 //      _qualified_exports may or may not be null depending on whether the package
  85 //        transitioned from qualifiedly exported to unqualifiedly exported.
  86 //   3. Package is qualifiedly exported
  87 //      _export_flags may be set to PKG_EXP_ALLUNNAMED if the package is also
  88 //        exported to all unnamed modules
  89 //      _qualified_exports will be non-null
  90 //   4. Package is exported to all unnamed modules
  91 //      _export_flags is set to PKG_EXP_ALLUNNAMED
  92 //      _qualified_exports may or may not be null depending on whether the package
  93 //        is also qualifiedly exported to one or more named modules.
  94 #define PKG_EXP_UNQUALIFIED  0x0001
  95 #define PKG_EXP_ALLUNNAMED   0x0002
  96 #define PKG_EXP_UNQUALIFIED_OR_ALL_UNAMED (PKG_EXP_UNQUALIFIED | PKG_EXP_ALLUNNAMED)
  97 
  98 #define MAX_BITMAP_BITS 32
  99 
 100 class PackageEntry : public HashtableEntry<Symbol*, mtModule> {
 101 private:
 102   ModuleEntry* _module;
 103   // Indicates if package is exported unqualifiedly or to all unnamed. Access to
 104   // this field is protected by the Module_lock.
 105   int _export_flags;
 106   // Used to indicate for packages with classes loaded by the boot loader that
 107   // a class in that package has been loaded.  And, for packages with classes
 108   // loaded by the boot loader from -Xbootclasspath/a in an unnamed module, it
 109   // indicates from which class path entry.
 110   s2 _classpath_index;
 111   bool _must_walk_exports;
 112   // Contains list of modules this package is qualifiedly exported to.  Access
 113   // to this list is protected by the Module_lock.
 114   GrowableArray<ModuleEntry*>* _qualified_exports;
 115   JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
 116 
 117   // Initial size of a package entry's list of qualified exports.
 118   enum {QUAL_EXP_SIZE = 43};
 119 
 120   volatile intptr_t _defined_in_class_path; // a Package java object has been define via CDS
 121 
 122 public:
 123   void init() {
 124     _module = NULL;
 125     _export_flags = 0;
 126     _classpath_index = -1;
 127     _must_walk_exports = false;
 128     _qualified_exports = NULL;
 129     _defined_in_class_path = 0;
 130   }
 131 
 132   // package name
 133   Symbol*            name() const               { return literal(); }
 134 
 135   // the module containing the package definition
 136   ModuleEntry*       module() const             { return _module; }
 137   void               set_module(ModuleEntry* m) { _module = m; }
 138 
 139   // package's export state
 140   bool is_exported() const { // qualifiedly or unqualifiedly exported
 141     assert_locked_or_safepoint(Module_lock);
 142     return module()->is_open() ||
 143             ((_export_flags & PKG_EXP_UNQUALIFIED_OR_ALL_UNAMED) != 0) ||
 144             has_qual_exports_list();
 145   }
 146   // Returns true if the package has any explicit qualified exports or is exported to all unnamed
 147   bool is_qual_exported() const {
 148     assert_locked_or_safepoint(Module_lock);
 149     return (has_qual_exports_list() || is_exported_allUnnamed());


 201 
 202   PackageEntry* next() const {
 203     return (PackageEntry*)HashtableEntry<Symbol*, mtModule>::next();
 204   }
 205 
 206   PackageEntry** next_addr() {
 207     return (PackageEntry**)HashtableEntry<Symbol*, mtModule>::next_addr();
 208   }
 209 
 210   // iteration of qualified exports
 211   void package_exports_do(ModuleClosure* f);
 212 
 213   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
 214 
 215   // Purge dead weak references out of exported list when any given class loader is unloaded.
 216   void purge_qualified_exports();
 217   void delete_qualified_exports();
 218 
 219   void print(outputStream* st = tty);
 220   void verify();
 221 
 222   bool is_defined_by_cds_in_class_path(intptr_t idx) const {
 223     return((Atomic::load(&_defined_in_class_path) & ((intptr_t)1 << idx)) != 0);
 224   }
 225   void set_defined_in_class_path(intptr_t idx) {
 226     intptr_t old_val = 0;
 227     intptr_t new_val = 0;
 228     do {
 229       old_val = Atomic::load(&_defined_in_class_path);
 230       new_val = old_val | ((intptr_t)1 << idx);
 231     } while (Atomic::cmpxchg(&_defined_in_class_path, old_val, new_val) != old_val);
 232   }
 233 };
 234 
 235 // The PackageEntryTable is a Hashtable containing a list of all packages defined
 236 // by a particular class loader.  Each package is represented as a PackageEntry node.
 237 // The PackageEntryTable's lookup is lock free.
 238 //
 239 class PackageEntryTable : public Hashtable<Symbol*, mtModule> {
 240   friend class VMStructs;
 241 public:
 242   enum Constants {
 243     _packagetable_entry_size = 109  // number of entries in package entry table
 244   };
 245 
 246 private:
 247   PackageEntry* new_entry(unsigned int hash, Symbol* name, ModuleEntry* module);
 248   void add_entry(int index, PackageEntry* new_entry);
 249 
 250   int entry_size() const { return BasicHashtable<mtModule>::entry_size(); }
 251 
 252   PackageEntry** bucket_addr(int i) {


< prev index next >