src/hotspot/share/classfile/moduleEntry.hpp
author coleenp
Fri, 04 Jan 2019 15:06:01 -0500
changeset 53149 259c36ef27df
parent 51444 3e5d28e6de32
child 53244 9807daeb47c4
permissions -rw-r--r--
8215731: Move forward class definitions out of globalDefinitions.hpp Summary: redistribute the forward declarations to the header files that need them. Reviewed-by: dholmes, lfoltan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
48871
120d6893f32f 8190235: Clarify ClassLoaderData::is_*_class_loader_data() method implementations
hseigel
parents: 47659
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 */
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    24
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    25
#ifndef SHARE_VM_CLASSFILE_MODULEENTRY_HPP
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    26
#define SHARE_VM_CLASSFILE_MODULEENTRY_HPP
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    27
47659
a8e9aff89f7b 8189608: Remove duplicated jni.h
ihse
parents: 47216
diff changeset
    28
#include "jni.h"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    29
#include "classfile/classLoaderData.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    30
#include "classfile/vmSymbols.hpp"
46961
c9094b1e5f87 8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents: 46773
diff changeset
    31
#include "oops/oopHandle.hpp"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    32
#include "oops/symbol.hpp"
46773
fb17cc9a6847 8185717: Make ModuleEntry->module() return an oop not a jobject
hseigel
parents: 46404
diff changeset
    33
#include "runtime/jniHandles.hpp"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    34
#include "runtime/mutexLocker.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    35
#include "utilities/growableArray.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    36
#include "utilities/hashtable.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49816
diff changeset
    37
#include "utilities/macros.hpp"
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
    38
#include "utilities/ostream.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49816
diff changeset
    39
#if INCLUDE_JFR
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49816
diff changeset
    40
#include "jfr/support/jfrTraceIdExtension.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49816
diff changeset
    41
#endif
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    42
50761
cb07f4b539fc 8169559: Add class loader names to relevant VM messages
lfoltan
parents: 50569
diff changeset
    43
#define UNNAMED_MODULE "unnamed module"
cb07f4b539fc 8169559: Add class loader names to relevant VM messages
lfoltan
parents: 50569
diff changeset
    44
#define UNNAMED_MODULE_LEN 14
44326
6c59cca7ff07 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42647
diff changeset
    45
#define JAVAPKG "java"
6c59cca7ff07 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42647
diff changeset
    46
#define JAVAPKG_LEN 4
42575
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 41183
diff changeset
    47
#define JAVA_BASE_NAME "java.base"
50761
cb07f4b539fc 8169559: Add class loader names to relevant VM messages
lfoltan
parents: 50569
diff changeset
    48
#define JAVA_BASE_NAME_LEN 9
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    49
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
class ModuleClosure;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    51
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    52
// A ModuleEntry describes a module that has been defined by a call to JVM_DefineModule.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
// It contains:
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
//   - Symbol* containing the module's name.
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
    55
//   - pointer to the java.lang.Module for this module.
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
    56
//   - pointer to the java.security.ProtectionDomain shared by classes defined to this module.
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    57
//   - ClassLoaderData*, class loader of this module.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    58
//   - a growable array containg other module entries that this module can read.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    59
//   - a flag indicating if this module can read all unnamed modules.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    60
//
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    61
// The Mutex Module_lock is shared between ModuleEntry and PackageEntry, to lock either
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    62
// data structure.
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 37503
diff changeset
    63
class ModuleEntry : public HashtableEntry<Symbol*, mtModule> {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    64
private:
46961
c9094b1e5f87 8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents: 46773
diff changeset
    65
  OopHandle _module;                   // java.lang.Module
c9094b1e5f87 8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents: 46773
diff changeset
    66
  OopHandle _pd;                       // java.security.ProtectionDomain, cached
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    67
                                       // for shared classes from this module
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
    68
  ClassLoaderData* _loader_data;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    69
  GrowableArray<ModuleEntry*>* _reads; // list of modules that are readable by this module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    70
  Symbol* _version;                    // module version number
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    71
  Symbol* _location;                   // module location
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    72
  bool _can_read_all_unnamed;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    73
  bool _has_default_read_edges;        // JVMTI redefine/retransform support
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
    74
  bool _must_walk_reads;               // walk module's reads list at GC safepoints to purge out dead modules
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
    75
  bool _is_open;                       // whether the packages in the module are all unqualifiedly exported
42634
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
    76
  bool _is_patched;                    // whether the module is patched via --patch-module
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49816
diff changeset
    77
  JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    78
  enum {MODULE_READS_SIZE = 101};      // Initial size of list of modules that the module can read.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    79
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    80
public:
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    81
  void init() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    82
    _module = NULL;
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
    83
    _loader_data = NULL;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    84
    _pd = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    85
    _reads = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    86
    _version = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    87
    _location = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    88
    _can_read_all_unnamed = false;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    89
    _has_default_read_edges = false;
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
    90
    _must_walk_reads = false;
42634
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
    91
    _is_patched = false;
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
    92
    _is_open = false;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    93
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    94
41183
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39616
diff changeset
    95
  Symbol*          name() const                        { return literal(); }
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39616
diff changeset
    96
  void             set_name(Symbol* n)                 { set_literal(n); }
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    97
49816
a3e79f97e86b 8200555: OopHandle should use Access API
coleenp
parents: 48871
diff changeset
    98
  oop              module() const;
46961
c9094b1e5f87 8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents: 46773
diff changeset
    99
  OopHandle        module_handle() const               { return _module; }
c9094b1e5f87 8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents: 46773
diff changeset
   100
  void             set_module(OopHandle j)             { _module = j; }
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   101
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   102
  // The shared ProtectionDomain reference is set once the VM loads a shared class
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   103
  // originated from the current Module. The referenced ProtectionDomain object is
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   104
  // created by the ClassLoader when loading a class (shared or non-shared) from the
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   105
  // Module for the first time. This ProtectionDomain object is used for all
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   106
  // classes from the Module loaded by the same ClassLoader.
46961
c9094b1e5f87 8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents: 46773
diff changeset
   107
  oop              shared_protection_domain();
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
   108
  void             set_shared_protection_domain(ClassLoaderData *loader_data, Handle pd);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   109
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
   110
  ClassLoaderData* loader_data() const                 { return _loader_data; }
48871
120d6893f32f 8190235: Clarify ClassLoaderData::is_*_class_loader_data() method implementations
hseigel
parents: 47659
diff changeset
   111
120d6893f32f 8190235: Clarify ClassLoaderData::is_*_class_loader_data() method implementations
hseigel
parents: 47659
diff changeset
   112
  void set_loader_data(ClassLoaderData* cld) {
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 50761
diff changeset
   113
    assert(!cld->is_unsafe_anonymous(), "Unexpected unsafe anonymous class loader data");
48871
120d6893f32f 8190235: Clarify ClassLoaderData::is_*_class_loader_data() method implementations
hseigel
parents: 47659
diff changeset
   114
    _loader_data = cld;
120d6893f32f 8190235: Clarify ClassLoaderData::is_*_class_loader_data() method implementations
hseigel
parents: 47659
diff changeset
   115
  }
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
   116
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
   117
  Symbol*          version() const                     { return _version; }
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
   118
  void             set_version(Symbol* version);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   119
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
   120
  Symbol*          location() const                    { return _location; }
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
   121
  void             set_location(Symbol* location);
50569
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50113
diff changeset
   122
  bool             should_show_version();
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   123
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
   124
  bool             can_read(ModuleEntry* m) const;
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 44326
diff changeset
   125
  bool             has_reads_list() const;
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
   126
  void             add_read(ModuleEntry* m);
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
   127
  void             set_read_walk_required(ClassLoaderData* m_loader_data);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   128
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   129
  bool             is_open() const                     { return _is_open; }
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   130
  void             set_is_open(bool is_open);
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   131
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 38733
diff changeset
   132
  bool             is_named() const                    { return (name() != NULL); }
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   133
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   134
  bool can_read_all_unnamed() const {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   135
    assert(is_named() || _can_read_all_unnamed == true,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   136
           "unnamed modules can always read all unnamed modules");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   137
    return _can_read_all_unnamed;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   138
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   139
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   140
  // Modules can only go from strict to loose.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   141
  void set_can_read_all_unnamed() { _can_read_all_unnamed = true; }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   142
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   143
  bool has_default_read_edges() const {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   144
    return _has_default_read_edges;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   145
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   146
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   147
  // Sets true and returns the previous value.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   148
  bool set_has_default_read_edges() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   149
    MutexLocker ml(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   150
    bool prev = _has_default_read_edges;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    _has_default_read_edges = true;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   152
    return prev;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   153
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   154
42634
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   155
  void set_is_patched() {
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   156
      _is_patched = true;
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   157
  }
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   158
  bool is_patched() {
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   159
      return _is_patched;
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   160
  }
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   161
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   162
  ModuleEntry* next() const {
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 37503
diff changeset
   163
    return (ModuleEntry*)HashtableEntry<Symbol*, mtModule>::next();
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   164
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   165
  ModuleEntry** next_addr() {
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 37503
diff changeset
   166
    return (ModuleEntry**)HashtableEntry<Symbol*, mtModule>::next_addr();
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   167
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   168
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   169
  // iteration support for readability
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   170
  void module_reads_do(ModuleClosure* const f);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   171
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   172
  // Purge dead weak references out of reads list when any given class loader is unloaded.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   173
  void purge_reads();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   174
  void delete_reads();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   175
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 44326
diff changeset
   176
  // Special handling for unnamed module, one per class loader
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 44326
diff changeset
   177
  static ModuleEntry* create_unnamed_module(ClassLoaderData* cld);
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 44326
diff changeset
   178
  static ModuleEntry* create_boot_unnamed_module(ClassLoaderData* cld);
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 44326
diff changeset
   179
  static ModuleEntry* new_unnamed_module_entry(Handle module_handle, ClassLoaderData* cld);
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 44326
diff changeset
   180
  void delete_unnamed_module();
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 44326
diff changeset
   181
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   182
  void print(outputStream* st = tty);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   183
  void verify();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49816
diff changeset
   184
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49816
diff changeset
   185
  JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   186
};
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   187
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   188
// Iterator interface
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   189
class ModuleClosure: public StackObj {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   190
 public:
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49816
diff changeset
   191
  virtual void do_module(ModuleEntry* module) = 0;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   192
};
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   193
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   194
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   195
// The ModuleEntryTable is a Hashtable containing a list of all modules defined
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   196
// by a particular class loader.  Each module is represented as a ModuleEntry node.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   197
//
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   198
// Each ModuleEntryTable contains a _javabase_module field which allows for the
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   199
// creation of java.base's ModuleEntry very early in bootstrapping before the
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   200
// corresponding JVM_DefineModule call for java.base occurs during module system
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   201
// initialization.  Setting up java.base's ModuleEntry early enables classes,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   202
// loaded prior to the module system being initialized to be created with their
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   203
// PackageEntry node's correctly pointing at java.base's ModuleEntry.  No class
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   204
// outside of java.base is allowed to be loaded pre-module system initialization.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   205
//
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   206
// The ModuleEntryTable's lookup is lock free.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   207
//
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 37503
diff changeset
   208
class ModuleEntryTable : public Hashtable<Symbol*, mtModule> {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   209
  friend class VMStructs;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   210
public:
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   211
  enum Constants {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   212
    _moduletable_entry_size  = 109 // number of entries in module entry table
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   213
  };
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   214
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   215
private:
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   216
  static ModuleEntry* _javabase_module;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   217
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   218
  ModuleEntry* new_entry(unsigned int hash, Handle module_handle, bool is_open,
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   219
                         Symbol* name, Symbol* version, Symbol* location, ClassLoaderData* loader_data);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   220
  void add_entry(int index, ModuleEntry* new_entry);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   221
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 37503
diff changeset
   222
  int entry_size() const { return BasicHashtable<mtModule>::entry_size(); }
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   223
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   224
  ModuleEntry** bucket_addr(int i) {
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 37503
diff changeset
   225
    return (ModuleEntry**)Hashtable<Symbol*, mtModule>::bucket_addr(i);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   226
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   227
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   228
  static unsigned int compute_hash(Symbol* name) { return ((name == NULL) ? 0 : (unsigned int)(name->identity_hash())); }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   229
  int index_for(Symbol* name) const              { return hash_to_index(compute_hash(name)); }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   230
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   231
public:
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   232
  ModuleEntryTable(int table_size);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   233
  ~ModuleEntryTable();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   234
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   235
  ModuleEntry* bucket(int i) {
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 37503
diff changeset
   236
    return (ModuleEntry*)Hashtable<Symbol*, mtModule>::bucket(i);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   237
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   238
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   239
  // Create module in loader's module entry table, if already exists then
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   240
  // return null.  Assume Module_lock has been locked by caller.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   241
  ModuleEntry* locked_create_entry_or_null(Handle module_handle,
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   242
                                           bool is_open,
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                                           Symbol* module_name,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   244
                                           Symbol* module_version,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                                           Symbol* module_location,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                                           ClassLoaderData* loader_data);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   247
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   248
  // Only lookup module within loader's module entry table.  The table read is lock-free.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   249
  ModuleEntry* lookup_only(Symbol* name);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   250
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   251
  // purge dead weak references out of reads list
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   252
  void purge_all_module_reads();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   253
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   254
  // Special handling for java.base
41183
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39616
diff changeset
   255
  static ModuleEntry* javabase_moduleEntry()                   { return _javabase_module; }
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39616
diff changeset
   256
  static void set_javabase_moduleEntry(ModuleEntry* java_base) { _javabase_module = java_base; }
46773
fb17cc9a6847 8185717: Make ModuleEntry->module() return an oop not a jobject
hseigel
parents: 46404
diff changeset
   257
fb17cc9a6847 8185717: Make ModuleEntry->module() return an oop not a jobject
hseigel
parents: 46404
diff changeset
   258
  static bool javabase_defined() { return ((_javabase_module != NULL) &&
46961
c9094b1e5f87 8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents: 46773
diff changeset
   259
                                           (_javabase_module->module() != NULL)); }
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   260
  static void finalize_javabase(Handle module_handle, Symbol* version, Symbol* location);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   261
  static void patch_javabase_entries(Handle module_handle);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   262
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   263
  void print(outputStream* st = tty);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   264
  void verify();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   265
};
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   266
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   267
#endif // SHARE_VM_CLASSFILE_MODULEENTRY_HPP