src/hotspot/share/classfile/moduleEntry.cpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 58083 9046db64ca39
permissions -rw-r--r--
8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently Summary: Increase the use of type signature constants instead of hard coded characters within the JVM. Reviewed-by: coleenp, dholmes, fparain Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
53471
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
     2
 * Copyright (c) 2016, 2019, 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
#include "precompiled.hpp"
47659
a8e9aff89f7b 8189608: Remove duplicated jni.h
ihse
parents: 47216
diff changeset
    26
#include "jni.h"
54347
235883996bc7 8221698: Remove redundant includes from popular header files
iklam
parents: 53471
diff changeset
    27
#include "classfile/classLoader.hpp"
49824
e242740a92b8 8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents: 49816
diff changeset
    28
#include "classfile/classLoaderData.inline.hpp"
50378
fceae121625e 8202758: SIGSEGV calling Class.forName(String,Boolean,ClassLoader) with mocked loader
lfoltan
parents: 50113
diff changeset
    29
#include "classfile/javaClasses.inline.hpp"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    30
#include "classfile/moduleEntry.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    31
#include "logging/log.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    32
#include "memory/resourceArea.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54347
diff changeset
    33
#include "memory/universe.hpp"
49816
a3e79f97e86b 8200555: OopHandle should use Access API
coleenp
parents: 47659
diff changeset
    34
#include "oops/oopHandle.inline.hpp"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    35
#include "oops/symbol.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    36
#include "runtime/handles.inline.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    37
#include "runtime/safepoint.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    38
#include "utilities/events.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    39
#include "utilities/growableArray.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    40
#include "utilities/hashtable.inline.hpp"
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
    41
#include "utilities/ostream.hpp"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    42
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    43
ModuleEntry* ModuleEntryTable::_javabase_module = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    44
49816
a3e79f97e86b 8200555: OopHandle should use Access API
coleenp
parents: 47659
diff changeset
    45
oop ModuleEntry::module() const { return _module.resolve(); }
a3e79f97e86b 8200555: OopHandle should use Access API
coleenp
parents: 47659
diff changeset
    46
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    47
void ModuleEntry::set_location(Symbol* location) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    48
  if (_location != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    49
    // _location symbol's refcounts are managed by ModuleEntry,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    // must decrement the old one before updating.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    _location->decrement_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    52
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
  _location = location;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    55
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    56
  if (location != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    location->increment_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    58
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    59
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    60
50569
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    61
// Return true if the module's version should be displayed in error messages,
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    62
// logging, etc.
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    63
// Return false if the module's version is null, if it is unnamed, or if the
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    64
// module is not an upgradeable module.
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    65
// Detect if the module is not upgradeable by checking:
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    66
//     1. Module location is "jrt:/java." and its loader is boot or platform
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    67
//     2. Module location is "jrt:/jdk.", its loader is one of the builtin loaders
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    68
//        and its version is the same as module java.base's version
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    69
// The above check is imprecise but should work in almost all cases.
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    70
bool ModuleEntry::should_show_version() {
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    71
  if (version() == NULL || !is_named()) return false;
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    72
42575
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    73
  if (location() != NULL) {
50569
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    74
    ResourceMark rm;
42575
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    75
    const char* loc = location()->as_C_string();
50569
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    76
    ClassLoaderData* cld = loader_data();
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    77
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    78
    if ((cld->is_the_null_class_loader_data() || cld->is_platform_class_loader_data()) &&
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    79
        (strncmp(loc, "jrt:/java.", 10) == 0)) {
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    80
      return false;
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    81
    }
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    82
    if ((ModuleEntryTable::javabase_moduleEntry()->version()->fast_compare(version()) == 0) &&
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    83
        cld->is_permanent_class_loader_data() && (strncmp(loc, "jrt:/jdk.", 9) == 0)) {
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    84
      return false;
42575
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    85
    }
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    86
  }
50569
60d66a249db6 8204620: ModuleEntry::is_non_jdk_module() determination for what is a jdk module is incorrect
hseigel
parents: 50378
diff changeset
    87
  return true;
42575
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    88
}
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    89
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    90
void ModuleEntry::set_version(Symbol* version) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    91
  if (_version != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    92
    // _version symbol's refcounts are managed by ModuleEntry,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    93
    // must decrement the old one before updating.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    94
    _version->decrement_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    95
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    96
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    97
  _version = version;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    98
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    99
  if (version != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   100
    version->increment_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   101
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   102
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   103
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   104
// Returns the shared ProtectionDomain
46961
c9094b1e5f87 8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents: 46729
diff changeset
   105
oop ModuleEntry::shared_protection_domain() {
c9094b1e5f87 8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents: 46729
diff changeset
   106
  return _pd.resolve();
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   107
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   108
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   109
// Set the shared ProtectionDomain atomically
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   110
void ModuleEntry::set_shared_protection_domain(ClassLoaderData *loader_data,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                                               Handle pd_h) {
44084
501b6d07e6dd 8168914: Crash in ClassLoaderData/JNIHandleBlock::oops_do during concurrent marking
ehelin
parents: 42866
diff changeset
   112
  // Create a handle for the shared ProtectionDomain and save it atomically.
46961
c9094b1e5f87 8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents: 46729
diff changeset
   113
  // init_handle_locked checks if someone beats us setting the _pd cache.
c9094b1e5f87 8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents: 46729
diff changeset
   114
  loader_data->init_handle_locked(_pd, pd_h);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   115
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   116
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   117
// Returns true if this module can read module m
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   118
bool ModuleEntry::can_read(ModuleEntry* m) const {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   119
  assert(m != NULL, "No module to lookup in this module's reads list");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   120
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   121
  // Unnamed modules read everyone and all modules
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   122
  // read java.base.  If either of these conditions
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   123
  // hold, readability has been established.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   124
  if (!this->is_named() ||
41183
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39625
diff changeset
   125
      (m == ModuleEntryTable::javabase_moduleEntry())) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    return true;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   127
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   128
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   129
  MutexLocker m1(Module_lock);
42866
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   130
  // This is a guard against possible race between agent threads that redefine
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   131
  // or retransform classes in this module. Only one of them is adding the
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   132
  // default read edges to the unnamed modules of the boot and app class loaders
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   133
  // with an upcall to jdk.internal.module.Modules.transformedByAgent.
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   134
  // At the same time, another thread can instrument the module classes by
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   135
  // injecting dependencies that require the default read edges for resolution.
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   136
  if (this->has_default_read_edges() && !m->is_named()) {
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   137
    ClassLoaderData* cld = m->loader_data();
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   138
    if (cld->is_the_null_class_loader_data() || cld->is_system_class_loader_data()) {
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   139
      return true; // default read edge
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   140
    }
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   141
  }
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   142
  if (!has_reads_list()) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    return false;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   144
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    return _reads->contains(m);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   146
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   147
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   148
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   149
// Add a new module to this module's reads list
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   150
void ModuleEntry::add_read(ModuleEntry* m) {
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   151
  // Unnamed module is special cased and can read all modules
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   152
  if (!is_named()) {
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   153
    return;
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   154
  }
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   155
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   156
  MutexLocker m1(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   157
  if (m == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   158
    set_can_read_all_unnamed();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   159
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   160
    if (_reads == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   161
      // Lazily create a module's reads list
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 38014
diff changeset
   162
      _reads = new (ResourceObj::C_HEAP, mtModule)GrowableArray<ModuleEntry*>(MODULE_READS_SIZE, true);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   163
    }
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   164
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   165
    // Determine, based on this newly established read edge to module m,
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   166
    // if this module's read list should be walked at a GC safepoint.
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   167
    set_read_walk_required(m->loader_data());
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   168
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   169
    // Establish readability to module m
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   170
    _reads->append_if_missing(m);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   171
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   172
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   173
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   174
// If the module's loader, that a read edge is being established to, is
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   175
// not the same loader as this module's and is not one of the 3 builtin
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   176
// class loaders, then this module's reads list must be walked at GC
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   177
// safepoint. Modules have the same life cycle as their defining class
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   178
// loaders and should be removed if dead.
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   179
void ModuleEntry::set_read_walk_required(ClassLoaderData* m_loader_data) {
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   180
  assert(is_named(), "Cannot call set_read_walk_required on unnamed module");
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   181
  assert_locked_or_safepoint(Module_lock);
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   182
  if (!_must_walk_reads &&
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   183
      loader_data() != m_loader_data &&
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   184
      !m_loader_data->is_builtin_class_loader_data()) {
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   185
    _must_walk_reads = true;
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   186
    if (log_is_enabled(Trace, module)) {
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   187
      ResourceMark rm;
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   188
      log_trace(module)("ModuleEntry::set_read_walk_required(): module %s reads list must be walked",
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   189
                        (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   190
    }
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   191
  }
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   192
}
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   193
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   194
// Set whether the module is open, i.e. all its packages are unqualifiedly exported
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   195
void ModuleEntry::set_is_open(bool is_open) {
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   196
  assert_lock_strong(Module_lock);
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   197
  _is_open = is_open;
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   198
}
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   199
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   200
// Returns true if the module has a non-empty reads list. As such, the unnamed
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   201
// module will return false.
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   202
bool ModuleEntry::has_reads_list() const {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   203
  assert_locked_or_safepoint(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   204
  return ((_reads != NULL) && !_reads->is_empty());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   205
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   206
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   207
// Purge dead module entries out of reads list.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   208
void ModuleEntry::purge_reads() {
52587
6cd56deebb0d 8213092: Add more runtime locks for concurrent class unloading
coleenp
parents: 51375
diff changeset
   209
  assert_locked_or_safepoint(Module_lock);
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   210
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   211
  if (_must_walk_reads && has_reads_list()) {
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   212
    // This module's _must_walk_reads flag will be reset based
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   213
    // on the remaining live modules on the reads list.
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   214
    _must_walk_reads = false;
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   215
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   216
    if (log_is_enabled(Trace, module)) {
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   217
      ResourceMark rm;
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   218
      log_trace(module)("ModuleEntry::purge_reads(): module %s reads list being walked",
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   219
                        (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   220
    }
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   221
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   222
    // Go backwards because this removes entries that are dead.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   223
    int len = _reads->length();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   224
    for (int idx = len - 1; idx >= 0; idx--) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   225
      ModuleEntry* module_idx = _reads->at(idx);
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   226
      ClassLoaderData* cld_idx = module_idx->loader_data();
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   227
      if (cld_idx->is_unloading()) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   228
        _reads->delete_at(idx);
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   229
      } else {
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   230
        // Update the need to walk this module's reads based on live modules
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   231
        set_read_walk_required(cld_idx);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   232
      }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   233
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   234
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   235
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   236
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49824
diff changeset
   237
void ModuleEntry::module_reads_do(ModuleClosure* f) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   238
  assert_locked_or_safepoint(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   239
  assert(f != NULL, "invariant");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   240
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   241
  if (has_reads_list()) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   242
    int reads_len = _reads->length();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   243
    for (int i = 0; i < reads_len; ++i) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   244
      f->do_module(_reads->at(i));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   245
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   246
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   247
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   248
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   249
void ModuleEntry::delete_reads() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   250
  delete _reads;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   251
  _reads = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   252
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   253
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   254
ModuleEntry* ModuleEntry::create_unnamed_module(ClassLoaderData* cld) {
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   255
  // The java.lang.Module for this loader's
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   256
  // corresponding unnamed module can be found in the java.lang.ClassLoader object.
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   257
  oop module = java_lang_ClassLoader::unnamedModule(cld->class_loader());
50378
fceae121625e 8202758: SIGSEGV calling Class.forName(String,Boolean,ClassLoader) with mocked loader
lfoltan
parents: 50113
diff changeset
   258
fceae121625e 8202758: SIGSEGV calling Class.forName(String,Boolean,ClassLoader) with mocked loader
lfoltan
parents: 50113
diff changeset
   259
  // Ensure that the unnamed module was correctly set when the class loader was constructed.
fceae121625e 8202758: SIGSEGV calling Class.forName(String,Boolean,ClassLoader) with mocked loader
lfoltan
parents: 50113
diff changeset
   260
  // Guarantee will cause a recognizable crash if the user code has circumvented calling the ClassLoader constructor.
fceae121625e 8202758: SIGSEGV calling Class.forName(String,Boolean,ClassLoader) with mocked loader
lfoltan
parents: 50113
diff changeset
   261
  ResourceMark rm;
fceae121625e 8202758: SIGSEGV calling Class.forName(String,Boolean,ClassLoader) with mocked loader
lfoltan
parents: 50113
diff changeset
   262
  guarantee(java_lang_Module::is_instance(module),
fceae121625e 8202758: SIGSEGV calling Class.forName(String,Boolean,ClassLoader) with mocked loader
lfoltan
parents: 50113
diff changeset
   263
            "The unnamed module for ClassLoader %s, is null or not an instance of java.lang.Module. The class loader has not been initialized correctly.",
50634
c349d409262a 8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents: 50569
diff changeset
   264
            cld->loader_name_and_id());
50378
fceae121625e 8202758: SIGSEGV calling Class.forName(String,Boolean,ClassLoader) with mocked loader
lfoltan
parents: 50113
diff changeset
   265
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   266
  ModuleEntry* unnamed_module = new_unnamed_module_entry(Handle(Thread::current(), module), cld);
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   267
50378
fceae121625e 8202758: SIGSEGV calling Class.forName(String,Boolean,ClassLoader) with mocked loader
lfoltan
parents: 50113
diff changeset
   268
  // Store pointer to the ModuleEntry in the unnamed module's java.lang.Module object.
46388
jwilhelm
parents: 46387 44520
diff changeset
   269
  java_lang_Module::set_module_entry(module, unnamed_module);
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   270
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   271
  return unnamed_module;
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   272
}
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   273
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   274
ModuleEntry* ModuleEntry::create_boot_unnamed_module(ClassLoaderData* cld) {
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   275
  // For the boot loader, the java.lang.Module for the unnamed module
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   276
  // is not known until a call to JVM_SetBootLoaderUnnamedModule is made. At
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   277
  // this point initially create the ModuleEntry for the unnamed module.
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   278
  ModuleEntry* unnamed_module = new_unnamed_module_entry(Handle(), cld);
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   279
  assert(unnamed_module != NULL, "boot loader unnamed module should not be null");
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   280
  return unnamed_module;
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   281
}
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   282
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   283
// When creating an unnamed module, this is called without holding the Module_lock.
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   284
// This is okay because the unnamed module gets created before the ClassLoaderData
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   285
// is available to other threads.
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   286
ModuleEntry* ModuleEntry::new_unnamed_module_entry(Handle module_handle, ClassLoaderData* cld) {
58083
9046db64ca39 8227168: Cleanup usage of NEW_C_HEAP_ARRAY
lkorinth
parents: 54786
diff changeset
   287
  ModuleEntry* entry = NEW_C_HEAP_OBJ(ModuleEntry, mtModule);
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   288
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   289
  // Initialize everything BasicHashtable would
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   290
  entry->set_next(NULL);
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   291
  entry->set_hash(0);
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   292
  entry->set_literal(NULL);
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   293
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   294
  // Initialize fields specific to a ModuleEntry
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   295
  entry->init();
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   296
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   297
  // Unnamed modules can read all other unnamed modules.
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   298
  entry->set_can_read_all_unnamed();
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   299
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   300
  if (!module_handle.is_null()) {
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   301
    entry->set_module(cld->add_handle(module_handle));
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   302
  }
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   303
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   304
  entry->set_loader_data(cld);
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   305
  entry->_is_open = true;
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   306
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49824
diff changeset
   307
  JFR_ONLY(INIT_ID(entry);)
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   308
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   309
  return entry;
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   310
}
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   311
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   312
void ModuleEntry::delete_unnamed_module() {
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   313
  // Do not need unlink_entry() since the unnamed module is not in the hashtable
58083
9046db64ca39 8227168: Cleanup usage of NEW_C_HEAP_ARRAY
lkorinth
parents: 54786
diff changeset
   314
  FREE_C_HEAP_OBJ(this);
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   315
}
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   316
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   317
ModuleEntryTable::ModuleEntryTable(int table_size)
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   318
  : Hashtable<Symbol*, mtModule>(table_size, sizeof(ModuleEntry))
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   319
{
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   320
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   321
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   322
ModuleEntryTable::~ModuleEntryTable() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   323
  // Walk through all buckets and all entries in each bucket,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   324
  // freeing each entry.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   325
  for (int i = 0; i < table_size(); ++i) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   326
    for (ModuleEntry* m = bucket(i); m != NULL;) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   327
      ModuleEntry* to_remove = m;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   328
      // read next before freeing.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   329
      m = m->next();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   330
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   331
      ResourceMark rm;
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   332
      if (to_remove->name() != NULL) {
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   333
        log_info(module, unload)("unloading module %s", to_remove->name()->as_C_string());
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   334
      }
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   335
      log_debug(module)("ModuleEntryTable: deleting module: %s", to_remove->name() != NULL ?
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   336
                        to_remove->name()->as_C_string() : UNNAMED_MODULE);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   337
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   338
      // Clean out the C heap allocated reads list first before freeing the entry
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   339
      to_remove->delete_reads();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   340
      if (to_remove->name() != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   341
        to_remove->name()->decrement_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   342
      }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   343
      if (to_remove->version() != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   344
        to_remove->version()->decrement_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   345
      }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   346
      if (to_remove->location() != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   347
        to_remove->location()->decrement_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   348
      }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   349
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   350
      // Unlink from the Hashtable prior to freeing
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   351
      unlink_entry(to_remove);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   352
      FREE_C_HEAP_ARRAY(char, to_remove);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   353
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   354
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   355
  assert(number_of_entries() == 0, "should have removed all entries");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   356
  assert(new_entry_free_list() == NULL, "entry present on ModuleEntryTable's free list");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   357
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   358
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   359
ModuleEntry* ModuleEntryTable::new_entry(unsigned int hash, Handle module_handle,
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   360
                                         bool is_open, Symbol* name,
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   361
                                         Symbol* version, Symbol* location,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   362
                                         ClassLoaderData* loader_data) {
39290
0cc9f5028562 8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents: 38733
diff changeset
   363
  assert(Module_lock->owned_by_self(), "should have the Module_lock");
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46475
diff changeset
   364
  ModuleEntry* entry = (ModuleEntry*)Hashtable<Symbol*, mtModule>::allocate_new_entry(hash, name);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   365
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   366
  // Initialize fields specific to a ModuleEntry
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   367
  entry->init();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   368
  if (name != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   369
    name->increment_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   370
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   371
    // Unnamed modules can read all other unnamed modules.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   372
    entry->set_can_read_all_unnamed();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   373
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   374
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   375
  if (!module_handle.is_null()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   376
    entry->set_module(loader_data->add_handle(module_handle));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   377
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   378
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   379
  entry->set_loader_data(loader_data);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   380
  entry->set_version(version);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   381
  entry->set_location(location);
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   382
  entry->set_is_open(is_open);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   383
42634
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   384
  if (ClassLoader::is_in_patch_mod_entries(name)) {
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   385
    entry->set_is_patched();
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   386
    if (log_is_enabled(Trace, module, patch)) {
42634
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   387
      ResourceMark rm;
51070
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 50634
diff changeset
   388
      log_trace(module, patch)("Marked module %s as patched from --patch-module",
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 50634
diff changeset
   389
                               name != NULL ? name->as_C_string() : UNNAMED_MODULE);
42634
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   390
    }
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   391
  }
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   392
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49824
diff changeset
   393
  JFR_ONLY(INIT_ID(entry);)
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   394
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   395
  return entry;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   396
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   397
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   398
void ModuleEntryTable::add_entry(int index, ModuleEntry* new_entry) {
39290
0cc9f5028562 8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents: 38733
diff changeset
   399
  assert(Module_lock->owned_by_self(), "should have the Module_lock");
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 38014
diff changeset
   400
  Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   401
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   402
53471
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   403
// Create an entry in the class loader's module_entry_table.  It is the
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   404
// caller's responsibility to ensure that the entry has not already been
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   405
// created.
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   406
ModuleEntry* ModuleEntryTable::locked_create_entry(Handle module_handle,
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   407
                                                   bool is_open,
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   408
                                                   Symbol* module_name,
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   409
                                                   Symbol* module_version,
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   410
                                                   Symbol* module_location,
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   411
                                                   ClassLoaderData* loader_data) {
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   412
  assert(module_name != NULL, "ModuleEntryTable locked_create_entry should never be called for unnamed module.");
39290
0cc9f5028562 8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents: 38733
diff changeset
   413
  assert(Module_lock->owned_by_self(), "should have the Module_lock");
53471
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   414
  assert(lookup_only(module_name) == NULL, "Module already exists");
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   415
  ModuleEntry* entry = new_entry(compute_hash(module_name), module_handle, is_open, module_name,
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   416
                                 module_version, module_location, loader_data);
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   417
  add_entry(index_for(module_name), entry);
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 52631
diff changeset
   418
  return entry;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   419
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   420
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   421
// lookup_only by Symbol* to find a ModuleEntry.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   422
ModuleEntry* ModuleEntryTable::lookup_only(Symbol* name) {
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46338
diff changeset
   423
  assert(name != NULL, "name cannot be NULL");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   424
  int index = index_for(name);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   425
  for (ModuleEntry* m = bucket(index); m != NULL; m = m->next()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   426
    if (m->name()->fast_compare(name) == 0) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   427
      return m;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   428
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   429
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   430
  return NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   431
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   432
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   433
// Remove dead modules from all other alive modules' reads list.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   434
// This should only occur at class unloading.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   435
void ModuleEntryTable::purge_all_module_reads() {
51375
b812a85b3aa4 8207778: Add locking to ModuleEntry and PackageEntry tables
hseigel
parents: 51070
diff changeset
   436
  assert_locked_or_safepoint(Module_lock);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   437
  for (int i = 0; i < table_size(); i++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   438
    for (ModuleEntry* entry = bucket(i);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   439
                      entry != NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   440
                      entry = entry->next()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   441
      entry->purge_reads();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   442
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   443
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   444
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   445
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   446
void ModuleEntryTable::finalize_javabase(Handle module_handle, Symbol* version, Symbol* location) {
39290
0cc9f5028562 8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents: 38733
diff changeset
   447
  assert(Module_lock->owned_by_self(), "should have the Module_lock");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   448
  ClassLoaderData* boot_loader_data = ClassLoaderData::the_null_class_loader_data();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   449
  ModuleEntryTable* module_table = boot_loader_data->modules();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   450
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   451
  assert(module_table != NULL, "boot loader's ModuleEntryTable not defined");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   452
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   453
  if (module_handle.is_null()) {
42636
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 42634
diff changeset
   454
    fatal("Unable to finalize module definition for " JAVA_BASE_NAME);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   455
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   456
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   457
  // Set java.lang.Module, version and location for java.base
41183
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39625
diff changeset
   458
  ModuleEntry* jb_module = javabase_moduleEntry();
42636
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 42634
diff changeset
   459
  assert(jb_module != NULL, JAVA_BASE_NAME " ModuleEntry not defined");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   460
  jb_module->set_version(version);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   461
  jb_module->set_location(location);
41183
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39625
diff changeset
   462
  // Once java.base's ModuleEntry _module field is set with the known
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   463
  // java.lang.Module, java.base is considered "defined" to the VM.
41183
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39625
diff changeset
   464
  jb_module->set_module(boot_loader_data->add_handle(module_handle));
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39625
diff changeset
   465
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   466
  // Store pointer to the ModuleEntry for java.base in the java.lang.Module object.
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   467
  java_lang_Module::set_module_entry(module_handle(), jb_module);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   468
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   469
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   470
// Within java.lang.Class instances there is a java.lang.Module field that must
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   471
// be set with the defining module.  During startup, prior to java.base's definition,
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   472
// classes needing their module field set are added to the fixup_module_list.
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   473
// Their module field is set once java.base's java.lang.Module is known to the VM.
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   474
void ModuleEntryTable::patch_javabase_entries(Handle module_handle) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   475
  if (module_handle.is_null()) {
42636
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 42634
diff changeset
   476
    fatal("Unable to patch the module field of classes loaded prior to "
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   477
          JAVA_BASE_NAME "'s definition, invalid java.lang.Module");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   478
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   479
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   480
  // Do the fixups for the basic primitive types
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   481
  java_lang_Class::set_module(Universe::int_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   482
  java_lang_Class::set_module(Universe::float_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   483
  java_lang_Class::set_module(Universe::double_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   484
  java_lang_Class::set_module(Universe::byte_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   485
  java_lang_Class::set_module(Universe::bool_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   486
  java_lang_Class::set_module(Universe::char_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   487
  java_lang_Class::set_module(Universe::long_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   488
  java_lang_Class::set_module(Universe::short_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   489
  java_lang_Class::set_module(Universe::void_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   490
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   491
  // Do the fixups for classes that have already been created.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   492
  GrowableArray <Klass*>* list = java_lang_Class::fixup_module_field_list();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   493
  int list_length = list->length();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   494
  for (int i = 0; i < list_length; i++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   495
    Klass* k = list->at(i);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   496
    assert(k->is_klass(), "List should only hold classes");
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46271
diff changeset
   497
    java_lang_Class::fixup_module_field(k, module_handle);
38014
8731fa11f766 8152949: Jigsaw crash when Klass in _fixup_module_field_list is unloaded
lfoltan
parents: 37503
diff changeset
   498
    k->class_loader_data()->dec_keep_alive();
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   499
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   500
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   501
  delete java_lang_Class::fixup_module_field_list();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   502
  java_lang_Class::set_fixup_module_field_list(NULL);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   503
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   504
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   505
void ModuleEntryTable::print(outputStream* st) {
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   506
  st->print_cr("Module Entry Table (table_size=%d, entries=%d)",
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   507
               table_size(), number_of_entries());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   508
  for (int i = 0; i < table_size(); i++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   509
    for (ModuleEntry* probe = bucket(i);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   510
                              probe != NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   511
                              probe = probe->next()) {
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   512
      probe->print(st);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   513
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   514
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   515
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   516
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   517
void ModuleEntry::print(outputStream* st) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   518
  ResourceMark rm;
39625
8702e5b9bfed 8160356: invalid suffix on literal warning is occurred with GCC 6
kbarrett
parents: 39616
diff changeset
   519
  st->print_cr("entry " PTR_FORMAT " name %s module " PTR_FORMAT " loader %s version %s location %s strict %s next " PTR_FORMAT,
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   520
               p2i(this),
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   521
               name() == NULL ? UNNAMED_MODULE : name()->as_C_string(),
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   522
               p2i(module()),
50634
c349d409262a 8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents: 50569
diff changeset
   523
               loader_data()->loader_name_and_id(),
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   524
               version() != NULL ? version()->as_C_string() : "NULL",
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   525
               location() != NULL ? location()->as_C_string() : "NULL",
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   526
               BOOL_TO_STR(!can_read_all_unnamed()), p2i(next()));
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   527
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   528
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   529
void ModuleEntryTable::verify() {
46475
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46458
diff changeset
   530
  verify_table<ModuleEntry>("Module Entry Table");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   531
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   532
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   533
void ModuleEntry::verify() {
39616
f82b1f888578 8159262: Walking PackageEntry Export and ModuleEntry Reads Must Occur Only When Neccessary And Wait Until ClassLoader's Aliveness Determined
lfoltan
parents: 39290
diff changeset
   534
  guarantee(loader_data() != NULL, "A module entry must be associated with a loader.");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   535
}