< prev index next >

src/share/vm/classfile/moduleEntry.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_VM_CLASSFILE_MODULEENTRY_HPP
  26 #define SHARE_VM_CLASSFILE_MODULEENTRY_HPP
  27 
  28 #include "classfile/classLoaderData.hpp"
  29 #include "classfile/vmSymbols.hpp"

  30 #include "oops/symbol.hpp"
  31 #include "prims/jni.h"
  32 #include "runtime/jniHandles.hpp"
  33 #include "runtime/mutexLocker.hpp"
  34 #include "trace/traceMacros.hpp"
  35 #include "utilities/growableArray.hpp"
  36 #include "utilities/hashtable.hpp"
  37 #include "utilities/ostream.hpp"
  38 
  39 #define UNNAMED_MODULE "Unnamed Module"
  40 #define JAVAPKG "java"
  41 #define JAVAPKG_LEN 4
  42 #define JAVA_BASE_NAME "java.base"
  43 
  44 class ModuleClosure;
  45 
  46 // A ModuleEntry describes a module that has been defined by a call to JVM_DefineModule.
  47 // It contains:
  48 //   - Symbol* containing the module's name.
  49 //   - pointer to the java.lang.Module for this module.
  50 //   - pointer to the java.security.ProtectionDomain shared by classes defined to this module.
  51 //   - ClassLoaderData*, class loader of this module.
  52 //   - a growable array containg other module entries that this module can read.
  53 //   - a flag indicating if this module can read all unnamed modules.
  54 //
  55 // The Mutex Module_lock is shared between ModuleEntry and PackageEntry, to lock either
  56 // data structure.
  57 class ModuleEntry : public HashtableEntry<Symbol*, mtModule> {
  58 private:
  59   jobject _module;                     // java.lang.Module
  60   jobject _pd;                         // java.security.ProtectionDomain, cached
  61                                        // for shared classes from this module
  62   ClassLoaderData* _loader_data;
  63   GrowableArray<ModuleEntry*>* _reads; // list of modules that are readable by this module
  64   Symbol* _version;                    // module version number
  65   Symbol* _location;                   // module location
  66   bool _can_read_all_unnamed;
  67   bool _has_default_read_edges;        // JVMTI redefine/retransform support
  68   bool _must_walk_reads;               // walk module's reads list at GC safepoints to purge out dead modules
  69   bool _is_open;                       // whether the packages in the module are all unqualifiedly exported
  70   bool _is_patched;                    // whether the module is patched via --patch-module
  71   TRACE_DEFINE_TRACE_ID_FIELD;
  72   enum {MODULE_READS_SIZE = 101};      // Initial size of list of modules that the module can read.
  73 
  74 public:
  75   void init() {
  76     _module = NULL;
  77     _loader_data = NULL;
  78     _pd = NULL;
  79     _reads = NULL;
  80     _version = NULL;
  81     _location = NULL;
  82     _can_read_all_unnamed = false;
  83     _has_default_read_edges = false;
  84     _must_walk_reads = false;
  85     _is_patched = false;
  86     _is_open = false;
  87   }
  88 
  89   Symbol*          name() const                        { return literal(); }
  90   void             set_name(Symbol* n)                 { set_literal(n); }
  91 
  92   oop              module() const                      { return JNIHandles::resolve(_module); }
  93   jobject          module_handle() const               { return _module; }
  94   void             set_module(jobject j)               { _module = j; }
  95 
  96   // The shared ProtectionDomain reference is set once the VM loads a shared class
  97   // originated from the current Module. The referenced ProtectionDomain object is
  98   // created by the ClassLoader when loading a class (shared or non-shared) from the
  99   // Module for the first time. This ProtectionDomain object is used for all
 100   // classes from the Module loaded by the same ClassLoader.
 101   Handle           shared_protection_domain();
 102   void             set_shared_protection_domain(ClassLoaderData *loader_data, Handle pd);
 103 
 104   ClassLoaderData* loader_data() const                 { return _loader_data; }
 105   void             set_loader_data(ClassLoaderData* l) { _loader_data = l; }
 106 
 107   Symbol*          version() const                     { return _version; }
 108   void             set_version(Symbol* version);
 109 
 110   Symbol*          location() const                    { return _location; }
 111   void             set_location(Symbol* location);
 112   bool             is_non_jdk_module();
 113 
 114   bool             can_read(ModuleEntry* m) const;
 115   bool             has_reads_list() const;
 116   void             add_read(ModuleEntry* m);
 117   void             set_read_walk_required(ClassLoaderData* m_loader_data);
 118 
 119   bool             is_open() const                     { return _is_open; }
 120   void             set_is_open(bool is_open);
 121 


 229   // Create module in loader's module entry table, if already exists then
 230   // return null.  Assume Module_lock has been locked by caller.
 231   ModuleEntry* locked_create_entry_or_null(Handle module_handle,
 232                                            bool is_open,
 233                                            Symbol* module_name,
 234                                            Symbol* module_version,
 235                                            Symbol* module_location,
 236                                            ClassLoaderData* loader_data);
 237 
 238   // Only lookup module within loader's module entry table.  The table read is lock-free.
 239   ModuleEntry* lookup_only(Symbol* name);
 240 
 241   // purge dead weak references out of reads list
 242   void purge_all_module_reads();
 243 
 244   // Special handling for java.base
 245   static ModuleEntry* javabase_moduleEntry()                   { return _javabase_module; }
 246   static void set_javabase_moduleEntry(ModuleEntry* java_base) { _javabase_module = java_base; }
 247 
 248   static bool javabase_defined() { return ((_javabase_module != NULL) &&
 249                                            (_javabase_module->module_handle() != NULL)); }
 250   static void finalize_javabase(Handle module_handle, Symbol* version, Symbol* location);
 251   static void patch_javabase_entries(Handle module_handle);
 252 
 253   void print(outputStream* st = tty);
 254   void verify();
 255 };
 256 
 257 #endif // SHARE_VM_CLASSFILE_MODULEENTRY_HPP


  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_VM_CLASSFILE_MODULEENTRY_HPP
  26 #define SHARE_VM_CLASSFILE_MODULEENTRY_HPP
  27 
  28 #include "classfile/classLoaderData.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "oops/oopHandle.hpp"
  31 #include "oops/symbol.hpp"
  32 #include "prims/jni.h"
  33 #include "runtime/jniHandles.hpp"
  34 #include "runtime/mutexLocker.hpp"
  35 #include "trace/traceMacros.hpp"
  36 #include "utilities/growableArray.hpp"
  37 #include "utilities/hashtable.hpp"
  38 #include "utilities/ostream.hpp"
  39 
  40 #define UNNAMED_MODULE "Unnamed Module"
  41 #define JAVAPKG "java"
  42 #define JAVAPKG_LEN 4
  43 #define JAVA_BASE_NAME "java.base"
  44 
  45 class ModuleClosure;
  46 
  47 // A ModuleEntry describes a module that has been defined by a call to JVM_DefineModule.
  48 // It contains:
  49 //   - Symbol* containing the module's name.
  50 //   - pointer to the java.lang.Module for this module.
  51 //   - pointer to the java.security.ProtectionDomain shared by classes defined to this module.
  52 //   - ClassLoaderData*, class loader of this module.
  53 //   - a growable array containg other module entries that this module can read.
  54 //   - a flag indicating if this module can read all unnamed modules.
  55 //
  56 // The Mutex Module_lock is shared between ModuleEntry and PackageEntry, to lock either
  57 // data structure.
  58 class ModuleEntry : public HashtableEntry<Symbol*, mtModule> {
  59 private:
  60   OopHandle _module;                   // java.lang.Module
  61   OopHandle _pd;                       // java.security.ProtectionDomain, cached
  62                                        // for shared classes from this module
  63   ClassLoaderData* _loader_data;
  64   GrowableArray<ModuleEntry*>* _reads; // list of modules that are readable by this module
  65   Symbol* _version;                    // module version number
  66   Symbol* _location;                   // module location
  67   bool _can_read_all_unnamed;
  68   bool _has_default_read_edges;        // JVMTI redefine/retransform support
  69   bool _must_walk_reads;               // walk module's reads list at GC safepoints to purge out dead modules
  70   bool _is_open;                       // whether the packages in the module are all unqualifiedly exported
  71   bool _is_patched;                    // whether the module is patched via --patch-module
  72   TRACE_DEFINE_TRACE_ID_FIELD;
  73   enum {MODULE_READS_SIZE = 101};      // Initial size of list of modules that the module can read.
  74 
  75 public:
  76   void init() {
  77     _module = NULL;
  78     _loader_data = NULL;
  79     _pd = NULL;
  80     _reads = NULL;
  81     _version = NULL;
  82     _location = NULL;
  83     _can_read_all_unnamed = false;
  84     _has_default_read_edges = false;
  85     _must_walk_reads = false;
  86     _is_patched = false;
  87     _is_open = false;
  88   }
  89 
  90   Symbol*          name() const                        { return literal(); }
  91   void             set_name(Symbol* n)                 { set_literal(n); }
  92 
  93   oop              module() const                      { return _module.resolve(); }
  94   OopHandle        module_handle() const               { return _module; }
  95   void             set_module(OopHandle j)             { _module = j; }
  96 
  97   // The shared ProtectionDomain reference is set once the VM loads a shared class
  98   // originated from the current Module. The referenced ProtectionDomain object is
  99   // created by the ClassLoader when loading a class (shared or non-shared) from the
 100   // Module for the first time. This ProtectionDomain object is used for all
 101   // classes from the Module loaded by the same ClassLoader.
 102   oop              shared_protection_domain();
 103   void             set_shared_protection_domain(ClassLoaderData *loader_data, Handle pd);
 104 
 105   ClassLoaderData* loader_data() const                 { return _loader_data; }
 106   void             set_loader_data(ClassLoaderData* l) { _loader_data = l; }
 107 
 108   Symbol*          version() const                     { return _version; }
 109   void             set_version(Symbol* version);
 110 
 111   Symbol*          location() const                    { return _location; }
 112   void             set_location(Symbol* location);
 113   bool             is_non_jdk_module();
 114 
 115   bool             can_read(ModuleEntry* m) const;
 116   bool             has_reads_list() const;
 117   void             add_read(ModuleEntry* m);
 118   void             set_read_walk_required(ClassLoaderData* m_loader_data);
 119 
 120   bool             is_open() const                     { return _is_open; }
 121   void             set_is_open(bool is_open);
 122 


 230   // Create module in loader's module entry table, if already exists then
 231   // return null.  Assume Module_lock has been locked by caller.
 232   ModuleEntry* locked_create_entry_or_null(Handle module_handle,
 233                                            bool is_open,
 234                                            Symbol* module_name,
 235                                            Symbol* module_version,
 236                                            Symbol* module_location,
 237                                            ClassLoaderData* loader_data);
 238 
 239   // Only lookup module within loader's module entry table.  The table read is lock-free.
 240   ModuleEntry* lookup_only(Symbol* name);
 241 
 242   // purge dead weak references out of reads list
 243   void purge_all_module_reads();
 244 
 245   // Special handling for java.base
 246   static ModuleEntry* javabase_moduleEntry()                   { return _javabase_module; }
 247   static void set_javabase_moduleEntry(ModuleEntry* java_base) { _javabase_module = java_base; }
 248 
 249   static bool javabase_defined() { return ((_javabase_module != NULL) &&
 250                                            (_javabase_module->module() != NULL)); }
 251   static void finalize_javabase(Handle module_handle, Symbol* version, Symbol* location);
 252   static void patch_javabase_entries(Handle module_handle);
 253 
 254   void print(outputStream* st = tty);
 255   void verify();
 256 };
 257 
 258 #endif // SHARE_VM_CLASSFILE_MODULEENTRY_HPP
< prev index next >