hotspot/src/share/vm/classfile/packageEntry.cpp
author hseigel
Wed, 01 Jun 2016 11:14:58 -0400
changeset 38733 2b65f4db449e
parent 37503 77531df4dad3
child 38940 7de797f32b5f
permissions -rw-r--r--
8156156: Add module specific NMT MemoryType Summary: Change NMT tag for allocations for modules support to mtModule Reviewed-by: coleenp, lfoltan, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
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/moduleEntry.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    27
#include "classfile/packageEntry.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    28
#include "memory/resourceArea.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    29
#include "oops/symbol.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    30
#include "runtime/handles.inline.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    31
#include "trace/traceMacros.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    32
#include "utilities/events.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    33
#include "utilities/growableArray.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    34
#include "utilities/hashtable.inline.hpp"
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
    35
#include "utilities/ostream.hpp"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    36
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    37
// Return true if this package is exported to m.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    38
bool PackageEntry::is_qexported_to(ModuleEntry* m) const {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    39
  assert(m != NULL, "No module to lookup in this package's qualified exports list");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    40
  MutexLocker m1(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    41
  if (!_is_exported) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    42
    return false;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    43
  } else if (_is_exported_allUnnamed && !m->is_named()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    44
    return true;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    45
  } else if (_qualified_exports == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    return false;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    47
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    48
    return _qualified_exports->contains(m);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    49
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    51
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    52
// Add a module to the package's qualified export list.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
void PackageEntry::add_qexport(ModuleEntry* m) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
  assert_locked_or_safepoint(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    55
  assert(_is_exported == true, "Adding a qualified export to a package that is not exported");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    56
  if (_qualified_exports == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    // Lazily create a package's qualified exports list.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    // Initial size is small, do not anticipate export lists to be large.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    _qualified_exports =
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 37503
diff changeset
    60
      new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleEntry*>(QUAL_EXP_SIZE, true);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    61
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    62
  _qualified_exports->append_if_missing(m);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    63
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    64
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    65
// Set the package's exported state based on the value of the ModuleEntry.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    66
void PackageEntry::set_exported(ModuleEntry* m) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    67
  MutexLocker m1(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    68
  if (is_unqual_exported()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    // An exception could be thrown, but choose to simply ignore.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    // Illegal to convert an unqualified exported package to be qualifiedly exported
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    return;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    72
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    73
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    74
  if (m == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    // NULL indicates the package is being unqualifiedly exported
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    76
    if (_is_exported && _qualified_exports != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    77
      // Legit to transition a package from being qualifiedly exported
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    78
      // to unqualified.  Clean up the qualified lists at the next
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    79
      // safepoint.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    80
      _exported_pending_delete = _qualified_exports;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    81
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    82
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    // Mark package as unqualifiedly exported
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    84
    set_unqual_exported();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    85
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    86
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    87
    // Add the exported module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    88
    _is_exported = true;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    89
    add_qexport(m);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    90
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    91
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    92
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    93
// Remove dead module entries within the package's exported list.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    94
void PackageEntry::purge_qualified_exports() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    95
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    96
  if (_qualified_exports != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    97
    // Go backwards because this removes entries that are dead.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    int len = _qualified_exports->length();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    99
    for (int idx = len - 1; idx >= 0; idx--) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   100
      ModuleEntry* module_idx = _qualified_exports->at(idx);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   101
      ClassLoaderData* cld = module_idx->loader();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   102
      if (cld->is_unloading()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        _qualified_exports->delete_at(idx);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   104
      }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   105
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   106
  }
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
void PackageEntry::delete_qualified_exports() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   110
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   111
  if (_exported_pending_delete != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   112
    // If a transition occurred from qualified to unqualified, the _qualified_exports
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   113
    // field should have been NULL'ed out.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   114
    assert(_qualified_exports == NULL, "Package's exported pending delete, exported list should not be active");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   115
    delete _exported_pending_delete;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   116
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   117
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   118
  if (_qualified_exports != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   119
    delete _qualified_exports;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   120
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   121
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   122
  _exported_pending_delete = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   123
  _qualified_exports = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   124
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   125
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   126
PackageEntryTable::PackageEntryTable(int table_size)
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 37503
diff changeset
   127
  : Hashtable<Symbol*, mtModule>(table_size, sizeof(PackageEntry))
36508
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
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   131
PackageEntryTable::~PackageEntryTable() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   132
  assert_locked_or_safepoint(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   133
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   134
  // Walk through all buckets and all entries in each bucket,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   135
  // freeing each entry.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   136
  for (int i = 0; i < table_size(); ++i) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   137
    for (PackageEntry* p = bucket(i); p != NULL;) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   138
      PackageEntry* to_remove = p;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   139
      // read next before freeing.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   140
      p = p->next();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   141
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   142
      // Clean out the C heap allocated qualified exports list first before freeing the entry
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   143
      to_remove->delete_qualified_exports();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   144
      to_remove->name()->decrement_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   145
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   146
      // Unlink from the Hashtable prior to freeing
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   147
      unlink_entry(to_remove);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   148
      FREE_C_HEAP_ARRAY(char, to_remove);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   149
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   150
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   151
  assert(number_of_entries() == 0, "should have removed all entries");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   152
  assert(new_entry_free_list() == NULL, "entry present on PackageEntryTable's free list");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   153
  free_buckets();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   154
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   155
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   156
PackageEntry* PackageEntryTable::new_entry(unsigned int hash, Symbol* name, ModuleEntry* module) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   157
  assert_locked_or_safepoint(Module_lock);
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 37503
diff changeset
   158
  PackageEntry* entry = (PackageEntry*) NEW_C_HEAP_ARRAY(char, entry_size(), mtModule);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   159
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   160
  // Initialize everything BasicHashtable would
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   161
  entry->set_next(NULL);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   162
  entry->set_hash(hash);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   163
  entry->set_literal(name);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   164
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   165
  TRACE_INIT_PACKAGE_ID(entry);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   166
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   167
  // Initialize fields specific to a PackageEntry
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   168
  entry->init();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   169
  entry->name()->increment_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   170
  if (!module->is_named()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   171
    // Set the exported state to true because all packages
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   172
    // within the unnamed module are unqualifiedly exported
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   173
    entry->set_exported(true);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   174
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   175
  entry->set_module(module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   176
  return entry;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   177
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   178
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   179
void PackageEntryTable::add_entry(int index, PackageEntry* new_entry) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   180
  assert_locked_or_safepoint(Module_lock);
38733
2b65f4db449e 8156156: Add module specific NMT MemoryType
hseigel
parents: 37503
diff changeset
   181
  Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   182
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   183
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   184
// Create package in loader's package entry table and return the entry.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   185
// If entry already exists, return null.  Assume Module lock was taken by caller.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   186
PackageEntry* PackageEntryTable::locked_create_entry_or_null(Symbol* name, ModuleEntry* module) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   187
  assert_locked_or_safepoint(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   188
  // Check if package already exists.  Return NULL if it does.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   189
  if (lookup_only(name) != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   190
    return NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   191
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   192
    PackageEntry* entry = new_entry(compute_hash(name), name, module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   193
    add_entry(index_for(name), entry);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   194
    return entry;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   195
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   196
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   197
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   198
PackageEntry* PackageEntryTable::lookup(Symbol* name, ModuleEntry* module) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   199
  PackageEntry* p = lookup_only(name);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   200
  if (p != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   201
    return p;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   202
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   203
    // If not found, add to table. Grab the PackageEntryTable lock first.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   204
    MutexLocker ml(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   205
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   206
    // Since look-up was done lock-free, we need to check if another thread beat
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   207
    // us in the race to insert the package.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   208
    PackageEntry* test = lookup_only(name);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   209
    if (test != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   210
      // A race occurred and another thread introduced the package.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   211
      return test;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   212
    } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   213
      assert(module != NULL, "module should never be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   214
      PackageEntry* entry = new_entry(compute_hash(name), name, module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   215
      add_entry(index_for(name), entry);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   216
      return entry;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   217
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   218
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   219
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   220
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   221
PackageEntry* PackageEntryTable::lookup_only(Symbol* name) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   222
  int index = index_for(name);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   223
  for (PackageEntry* p = bucket(index); p != NULL; p = p->next()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   224
    if (p->name()->fast_compare(name) == 0) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   225
      return p;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   226
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   227
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   228
  return NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   229
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   230
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   231
// Called when a define module for java.base is being processed.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   232
// Verify the packages loaded thus far are in java.base's package list.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   233
void PackageEntryTable::verify_javabase_packages(GrowableArray<Symbol*> *pkg_list) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   234
  for (int i = 0; i < table_size(); i++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   235
    for (PackageEntry* entry = bucket(i);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                       entry != NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   237
                       entry = entry->next()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   238
      ModuleEntry* m = entry->module();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   239
      Symbol* module_name = (m == NULL ? NULL : m->name());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   240
      if (module_name != NULL &&
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   241
          (module_name->fast_compare(vmSymbols::java_base()) == 0) &&
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   242
          !pkg_list->contains(entry->name())) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        ResourceMark rm;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        vm_exit_during_initialization("A non-java.base package was loaded prior to module system initialization", entry->name()->as_C_string());
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
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   250
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   251
// Remove dead entries from all packages' exported list
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   252
void PackageEntryTable::purge_all_package_exports() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   253
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   254
  for (int i = 0; i < table_size(); i++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   255
    for (PackageEntry* entry = bucket(i);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   256
                       entry != NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                       entry = entry->next()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   258
      if (entry->exported_pending_delete()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        // exported list is pending deletion due to a transition
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        // from qualified to unqualified
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   261
        entry->delete_qualified_exports();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   262
      } else if (entry->is_qual_exported()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        entry->purge_qualified_exports();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   264
      }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   265
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   266
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   267
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   268
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   269
void PackageEntryTable::print(outputStream* st) {
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   270
  st->print_cr("Package Entry Table (table_size=%d, entries=%d)",
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   271
               table_size(), number_of_entries());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   272
  for (int i = 0; i < table_size(); i++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   273
    for (PackageEntry* probe = bucket(i);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                       probe != NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   275
                       probe = probe->next()) {
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   276
      probe->print(st);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   277
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   278
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   279
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   280
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   281
void PackageEntry::print(outputStream* st) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   282
  ResourceMark rm;
37503
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   283
  st->print_cr("package entry "PTR_FORMAT" name %s module %s classpath_index "
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   284
               INT32_FORMAT " is_exported %d is_exported_allUnnamed %d " "next "PTR_FORMAT,
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   285
               p2i(this), name()->as_C_string(),
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   286
               (module()->is_named() ? module()->name()->as_C_string() : UNNAMED_MODULE),
77531df4dad3 8152845: Improve PackageEntry and ModuleEntry print methods for future logging
rprotacio
parents: 36508
diff changeset
   287
               _classpath_index, _is_exported, _is_exported_allUnnamed, p2i(next()));
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   288
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   289
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   290
void PackageEntryTable::verify() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   291
  int element_count = 0;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   292
  for (int index = 0; index < table_size(); index++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   293
    for (PackageEntry* probe = bucket(index);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   294
                              probe != NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   295
                              probe = probe->next()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   296
      probe->verify();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   297
      element_count++;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   298
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   299
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   300
  guarantee(number_of_entries() == element_count,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   301
            "Verify of Package Entry Table failed");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   302
  debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   303
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   304
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   305
void PackageEntry::verify() {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   306
  guarantee(name() != NULL, "A package entry must have a corresponding symbol name.");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   307
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   308
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   309
// iteration of qualified exports
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   310
void PackageEntry::package_exports_do(ModuleClosure* const f) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   311
  assert_locked_or_safepoint(Module_lock);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   312
  assert(f != NULL, "invariant");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   313
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   314
  if (is_qual_exported()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   315
    int qe_len = _qualified_exports->length();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   316
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   317
    for (int i = 0; i < qe_len; ++i) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   318
      f->do_module(_qualified_exports->at(i));
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
}