hotspot/src/share/vm/classfile/moduleEntry.cpp
author alanb
Fri, 07 Apr 2017 08:04:46 +0000
changeset 44520 0553e129e0ec
parent 44084 501b6d07e6dd
child 44993 f61bcd80ec1f
child 46388 d7a164ad6b7f
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: lfoltan, sspitsyn Contributed-by: alan.bateman@oracle.com, harold.seigel@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
44084
501b6d07e6dd 8168914: Crash in ClassLoaderData/JNIHandleBlock::oops_do during concurrent marking
ehelin
parents: 42866
diff changeset
     2
 * Copyright (c) 2016, 2017, 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"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    26
#include "classfile/classLoaderData.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    27
#include "classfile/javaClasses.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    28
#include "classfile/moduleEntry.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    29
#include "logging/log.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    30
#include "memory/resourceArea.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    31
#include "oops/symbol.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    32
#include "prims/jni.h"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    33
#include "runtime/handles.inline.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    34
#include "runtime/safepoint.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    35
#include "trace/traceMacros.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    36
#include "utilities/events.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    37
#include "utilities/growableArray.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    38
#include "utilities/hashtable.inline.hpp"
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
    39
#include "utilities/ostream.hpp"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    40
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    41
ModuleEntry* ModuleEntryTable::_javabase_module = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    42
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    43
void ModuleEntry::set_location(Symbol* location) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    44
  if (_location != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    45
    // _location symbol's refcounts are managed by ModuleEntry,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    // must decrement the old one before updating.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    47
    _location->decrement_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    48
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    49
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
  _location = location;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    51
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    52
  if (location != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    location->increment_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    55
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    56
42575
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    57
bool ModuleEntry::is_non_jdk_module() {
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    58
  ResourceMark rm;
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    59
  if (location() != NULL) {
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    60
    const char* loc = location()->as_C_string();
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    61
    if (strncmp(loc, "jrt:/java.", 10) != 0 && strncmp(loc, "jrt:/jdk.", 9) != 0) {
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    62
      return true;
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    63
    }
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    64
  }
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    65
  return false;
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    66
}
bd1618170c93 8165550: Add class loader names to ClassCastException message
rprotacio
parents: 42073
diff changeset
    67
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    68
void ModuleEntry::set_version(Symbol* version) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    69
  if (_version != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    // _version symbol's refcounts are managed by ModuleEntry,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    // must decrement the old one before updating.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    72
    _version->decrement_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    73
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    74
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    75
  _version = version;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    76
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    77
  if (version != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    78
    version->increment_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    79
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    80
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    81
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    82
// Returns the shared ProtectionDomain
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    83
Handle ModuleEntry::shared_protection_domain() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    84
  return Handle(JNIHandles::resolve(_pd));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    85
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    86
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    87
// Set the shared ProtectionDomain atomically
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    88
void ModuleEntry::set_shared_protection_domain(ClassLoaderData *loader_data,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    89
                                               Handle pd_h) {
44084
501b6d07e6dd 8168914: Crash in ClassLoaderData/JNIHandleBlock::oops_do during concurrent marking
ehelin
parents: 42866
diff changeset
    90
  // Create a handle for the shared ProtectionDomain and save it atomically.
501b6d07e6dd 8168914: Crash in ClassLoaderData/JNIHandleBlock::oops_do during concurrent marking
ehelin
parents: 42866
diff changeset
    91
  // If someone beats us setting the _pd cache, the created handle is destroyed.
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    92
  jobject obj = loader_data->add_handle(pd_h);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    93
  if (Atomic::cmpxchg_ptr(obj, &_pd, NULL) != NULL) {
44084
501b6d07e6dd 8168914: Crash in ClassLoaderData/JNIHandleBlock::oops_do during concurrent marking
ehelin
parents: 42866
diff changeset
    94
    loader_data->remove_handle_unsafe(obj);
36508
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
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    98
// Returns true if this module can read module m
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    99
bool ModuleEntry::can_read(ModuleEntry* m) const {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   100
  assert(m != NULL, "No module to lookup in this module's reads list");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   101
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   102
  // Unnamed modules read everyone and all modules
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   103
  // read java.base.  If either of these conditions
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   104
  // hold, readability has been established.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   105
  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
   106
      (m == ModuleEntryTable::javabase_moduleEntry())) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   107
    return true;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   108
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   109
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   110
  MutexLocker m1(Module_lock);
42866
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   111
  // 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
   112
  // 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
   113
  // 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
   114
  // with an upcall to jdk.internal.module.Modules.transformedByAgent.
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   115
  // 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
   116
  // 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
   117
  if (this->has_default_read_edges() && !m->is_named()) {
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   118
    ClassLoaderData* cld = m->loader_data();
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   119
    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
   120
      return true; // default read edge
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   121
    }
97de8ed6c6b3 8139566: need proper sync for adding default read edges
sspitsyn
parents: 42639
diff changeset
   122
  }
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   123
  if (!has_reads()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    return false;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   125
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    return _reads->contains(m);
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
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   130
// Add a new module to this module's reads list
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   131
void ModuleEntry::add_read(ModuleEntry* m) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   132
  MutexLocker m1(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   133
  if (m == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   134
    set_can_read_all_unnamed();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   135
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   136
    if (_reads == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   137
      // Lazily create a module's reads list
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 38014
diff changeset
   138
      _reads = new (ResourceObj::C_HEAP, mtModule)GrowableArray<ModuleEntry*>(MODULE_READS_SIZE, true);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   139
    }
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
   140
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
   141
    // 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
   142
    // 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
   143
    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
   144
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
   145
    // Establish readability to module m
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   146
    _reads->append_if_missing(m);
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
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
   150
// 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
   151
// 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
   152
// 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
   153
// 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
   154
// 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
   155
void ModuleEntry::set_read_walk_required(ClassLoaderData* 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
   156
  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
   157
  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
   158
      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
   159
      !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
   160
    _must_walk_reads = true;
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
   161
    if (log_is_enabled(Trace, 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
   162
      ResourceMark rm;
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
   163
      log_trace(modules)("ModuleEntry::set_read_walk_required(): module %s reads list must be walked",
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
                         (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
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
    }
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
  }
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
}
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
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   169
bool ModuleEntry::has_reads() const {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   170
  assert_locked_or_safepoint(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   171
  return ((_reads != NULL) && !_reads->is_empty());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   172
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   173
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   174
// Purge dead module entries out of reads list.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   175
void ModuleEntry::purge_reads() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   176
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
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
   177
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
  if (_must_walk_reads && has_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
   179
    // 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
   180
    // 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
   181
    _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
   182
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
    if (log_is_enabled(Trace, 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
   184
      ResourceMark rm;
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
      log_trace(modules)("ModuleEntry::purge_reads(): module %s reads list being walked",
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
   186
                         (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
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
    }
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
   188
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   189
    // Go backwards because this removes entries that are dead.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   190
    int len = _reads->length();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   191
    for (int idx = len - 1; idx >= 0; idx--) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   192
      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
   193
      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
   194
      if (cld_idx->is_unloading()) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   195
        _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
   196
      } 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
   197
        // 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
   198
        set_read_walk_required(cld_idx);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   199
      }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   200
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   201
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   202
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   203
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   204
void ModuleEntry::module_reads_do(ModuleClosure* const f) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   205
  assert_locked_or_safepoint(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   206
  assert(f != NULL, "invariant");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   207
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   208
  if (has_reads()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   209
    int reads_len = _reads->length();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   210
    for (int i = 0; i < reads_len; ++i) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   211
      f->do_module(_reads->at(i));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   212
    }
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
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   216
void ModuleEntry::delete_reads() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   217
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   218
  delete _reads;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   219
  _reads = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   220
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   221
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   222
ModuleEntryTable::ModuleEntryTable(int table_size)
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 38014
diff changeset
   223
  : Hashtable<Symbol*, mtModule>(table_size, sizeof(ModuleEntry)), _unnamed_module(NULL)
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   224
{
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   225
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   226
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   227
ModuleEntryTable::~ModuleEntryTable() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   228
  assert_locked_or_safepoint(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   229
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   230
  // Walk through all buckets and all entries in each bucket,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   231
  // freeing each entry.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   232
  for (int i = 0; i < table_size(); ++i) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   233
    for (ModuleEntry* m = bucket(i); m != NULL;) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   234
      ModuleEntry* to_remove = m;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   235
      // read next before freeing.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   236
      m = m->next();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   237
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   238
      ResourceMark rm;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   239
      log_debug(modules)("ModuleEntryTable: deleting module: %s", to_remove->name() != NULL ?
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   240
                         to_remove->name()->as_C_string() : UNNAMED_MODULE);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   241
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   242
      // Clean out the C heap allocated reads list first before freeing the entry
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   243
      to_remove->delete_reads();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   244
      if (to_remove->name() != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        to_remove->name()->decrement_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   246
      }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   247
      if (to_remove->version() != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   248
        to_remove->version()->decrement_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   249
      }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   250
      if (to_remove->location() != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   251
        to_remove->location()->decrement_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   252
      }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   253
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   254
      // Unlink from the Hashtable prior to freeing
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   255
      unlink_entry(to_remove);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   256
      FREE_C_HEAP_ARRAY(char, to_remove);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   257
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   258
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   259
  assert(number_of_entries() == 0, "should have removed all entries");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   260
  assert(new_entry_free_list() == NULL, "entry present on ModuleEntryTable's free list");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   261
  free_buckets();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   262
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   263
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   264
void ModuleEntryTable::create_unnamed_module(ClassLoaderData* loader_data) {
39290
0cc9f5028562 8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents: 38733
diff changeset
   265
  assert(Module_lock->owned_by_self(), "should have the Module_lock");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   266
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   267
  // Each ModuleEntryTable has exactly one unnamed module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   268
  if (loader_data->is_the_null_class_loader_data()) {
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   269
    // For the boot loader, the java.lang.Module for the unnamed module
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   270
    // is not known until a call to JVM_SetBootLoaderUnnamedModule is made. At
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   271
    // this point initially create the ModuleEntry for the unnamed module.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   272
    _unnamed_module = new_entry(0, Handle(NULL), NULL, NULL, NULL, loader_data);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   273
  } else {
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   274
    // For all other class loaders the java.lang.Module for their
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   275
    // corresponding unnamed module can be found in the java.lang.ClassLoader object.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   276
    oop module = java_lang_ClassLoader::unnamedModule(loader_data->class_loader());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   277
    _unnamed_module = new_entry(0, Handle(module), NULL, NULL, NULL, loader_data);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   278
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   279
    // Store pointer to the ModuleEntry in the unnamed module's java.lang.Module
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   280
    // object.
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   281
    java_lang_Module::set_module_entry(module, _unnamed_module);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   282
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   283
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   284
  // Add to bucket 0, no name to hash on
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   285
  add_entry(0, _unnamed_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   286
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   287
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   288
ModuleEntry* ModuleEntryTable::new_entry(unsigned int hash, Handle module_handle, Symbol* name,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   289
                                         Symbol* version, Symbol* location,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   290
                                         ClassLoaderData* loader_data) {
39290
0cc9f5028562 8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents: 38733
diff changeset
   291
  assert(Module_lock->owned_by_self(), "should have the Module_lock");
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 38014
diff changeset
   292
  ModuleEntry* entry = (ModuleEntry*) NEW_C_HEAP_ARRAY(char, entry_size(), mtModule);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   293
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   294
  // Initialize everything BasicHashtable would
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   295
  entry->set_next(NULL);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   296
  entry->set_hash(hash);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   297
  entry->set_literal(name);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   298
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   299
  // Initialize fields specific to a ModuleEntry
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   300
  entry->init();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   301
  if (name != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   302
    name->increment_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   303
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   304
    // Unnamed modules can read all other unnamed modules.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   305
    entry->set_can_read_all_unnamed();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   306
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   307
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   308
  if (!module_handle.is_null()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   309
    entry->set_module(loader_data->add_handle(module_handle));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   310
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   311
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
   312
  entry->set_loader_data(loader_data);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   313
  entry->set_version(version);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   314
  entry->set_location(location);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   315
42634
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   316
  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
   317
    entry->set_is_patched();
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   318
    if (log_is_enabled(Trace, modules, patch)) {
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   319
      ResourceMark rm;
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   320
      log_trace(modules, patch)("Marked module %s as patched from --patch-module", name->as_C_string());
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   321
    }
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   322
  }
7459867ebf98 8168850: Mark module entries that have been specified by --patch-module
rprotacio
parents: 42575
diff changeset
   323
42639
762117d57d05 8170672: Event-based tracing to support classloader instances
mgronlun
parents: 42636
diff changeset
   324
  TRACE_INIT_ID(entry);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   325
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   326
  return entry;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   327
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   328
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   329
void ModuleEntryTable::add_entry(int index, ModuleEntry* new_entry) {
39290
0cc9f5028562 8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents: 38733
diff changeset
   330
  assert(Module_lock->owned_by_self(), "should have the Module_lock");
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 38014
diff changeset
   331
  Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   332
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   333
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   334
ModuleEntry* ModuleEntryTable::locked_create_entry_or_null(Handle module_handle,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   335
                                                           Symbol* module_name,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   336
                                                           Symbol* module_version,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   337
                                                           Symbol* module_location,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   338
                                                           ClassLoaderData* loader_data) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   339
  assert(module_name != NULL, "ModuleEntryTable locked_create_entry_or_null should never be called for unnamed module.");
39290
0cc9f5028562 8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents: 38733
diff changeset
   340
  assert(Module_lock->owned_by_self(), "should have the Module_lock");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   341
  // Check if module already exists.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   342
  if (lookup_only(module_name) != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   343
    return NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   344
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   345
    ModuleEntry* entry = new_entry(compute_hash(module_name), module_handle, module_name,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   346
                                   module_version, module_location, loader_data);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   347
    add_entry(index_for(module_name), entry);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   348
    return entry;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   349
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   350
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   351
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   352
// lookup_only by Symbol* to find a ModuleEntry.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   353
ModuleEntry* ModuleEntryTable::lookup_only(Symbol* name) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   354
  if (name == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   355
    // Return this table's unnamed module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   356
    return unnamed_module();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   357
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   358
  int index = index_for(name);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   359
  for (ModuleEntry* m = bucket(index); m != NULL; m = m->next()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   360
    if (m->name()->fast_compare(name) == 0) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   361
      return m;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   362
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   363
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   364
  return NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   365
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   366
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   367
// Remove dead modules from all other alive modules' reads list.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   368
// This should only occur at class unloading.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   369
void ModuleEntryTable::purge_all_module_reads() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   370
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   371
  for (int i = 0; i < table_size(); i++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   372
    for (ModuleEntry* entry = bucket(i);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   373
                      entry != NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   374
                      entry = entry->next()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   375
      entry->purge_reads();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   376
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   377
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   378
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   379
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   380
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
   381
  assert(Module_lock->owned_by_self(), "should have the Module_lock");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   382
  ClassLoaderData* boot_loader_data = ClassLoaderData::the_null_class_loader_data();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   383
  ModuleEntryTable* module_table = boot_loader_data->modules();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   384
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   385
  assert(module_table != NULL, "boot loader's ModuleEntryTable not defined");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   386
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   387
  if (module_handle.is_null()) {
42636
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 42634
diff changeset
   388
    fatal("Unable to finalize module definition for " JAVA_BASE_NAME);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   389
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   390
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   391
  // 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
   392
  ModuleEntry* jb_module = javabase_moduleEntry();
42636
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 42634
diff changeset
   393
  assert(jb_module != NULL, JAVA_BASE_NAME " ModuleEntry not defined");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   394
  jb_module->set_version(version);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   395
  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
   396
  // 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
   397
  // 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
   398
  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
   399
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   400
  // 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
   401
  java_lang_Module::set_module_entry(module_handle(), jb_module);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   402
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   403
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44084
diff changeset
   404
// 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
   405
// 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
   406
// 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
   407
// 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
   408
void ModuleEntryTable::patch_javabase_entries(Handle module_handle) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   409
  if (module_handle.is_null()) {
42636
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 42634
diff changeset
   410
    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
   411
          JAVA_BASE_NAME "'s definition, invalid java.lang.Module");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   412
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   413
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   414
  // Do the fixups for the basic primitive types
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   415
  java_lang_Class::set_module(Universe::int_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   416
  java_lang_Class::set_module(Universe::float_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   417
  java_lang_Class::set_module(Universe::double_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   418
  java_lang_Class::set_module(Universe::byte_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   419
  java_lang_Class::set_module(Universe::bool_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   420
  java_lang_Class::set_module(Universe::char_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   421
  java_lang_Class::set_module(Universe::long_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   422
  java_lang_Class::set_module(Universe::short_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   423
  java_lang_Class::set_module(Universe::void_mirror(), module_handle());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   424
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   425
  // Do the fixups for classes that have already been created.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   426
  GrowableArray <Klass*>* list = java_lang_Class::fixup_module_field_list();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   427
  int list_length = list->length();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   428
  for (int i = 0; i < list_length; i++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   429
    Klass* k = list->at(i);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   430
    assert(k->is_klass(), "List should only hold classes");
41183
207b92e69457 8163406: The fixup_module_list must be protected by Module_lock when inserting new entries
lfoltan
parents: 39625
diff changeset
   431
    java_lang_Class::fixup_module_field(KlassHandle(k), module_handle);
38014
8731fa11f766 8152949: Jigsaw crash when Klass in _fixup_module_field_list is unloaded
lfoltan
parents: 37503
diff changeset
   432
    k->class_loader_data()->dec_keep_alive();
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   433
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   434
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   435
  delete java_lang_Class::fixup_module_field_list();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   436
  java_lang_Class::set_fixup_module_field_list(NULL);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   437
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   438
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   439
void ModuleEntryTable::print(outputStream* st) {
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   440
  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
   441
               table_size(), number_of_entries());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   442
  for (int i = 0; i < table_size(); i++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   443
    for (ModuleEntry* probe = bucket(i);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   444
                              probe != NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   445
                              probe = probe->next()) {
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   446
      probe->print(st);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   447
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   448
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   449
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   450
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   451
void ModuleEntry::print(outputStream* st) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   452
  ResourceMark rm;
39625
8702e5b9bfed 8160356: invalid suffix on literal warning is occurred with GCC 6
kbarrett
parents: 39616
diff changeset
   453
  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
   454
               p2i(this),
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   455
               name() == NULL ? UNNAMED_MODULE : name()->as_C_string(),
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   456
               p2i(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
   457
               loader_data()->loader_name(),
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   458
               version() != NULL ? version()->as_C_string() : "NULL",
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   459
               location() != NULL ? location()->as_C_string() : "NULL",
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   460
               BOOL_TO_STR(!can_read_all_unnamed()), p2i(next()));
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   461
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   462
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   463
void ModuleEntryTable::verify() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   464
  int element_count = 0;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   465
  for (int i = 0; i < table_size(); i++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   466
    for (ModuleEntry* probe = bucket(i);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   467
                              probe != NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   468
                              probe = probe->next()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   469
      probe->verify();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   470
      element_count++;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   471
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   472
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   473
  guarantee(number_of_entries() == element_count,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   474
            "Verify of Module Entry Table failed");
42073
89e056fd82cc 8166145: runtime/threads/ThreadInterruptTest3 fails with ExitCode 0
gziemski
parents: 41691
diff changeset
   475
  DEBUG_ONLY(verify_lookup_length((double)number_of_entries() / table_size(), "Module Entry Table"));
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   476
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   477
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   478
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
   479
  guarantee(loader_data() != NULL, "A module entry must be associated with a loader.");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   480
}