src/hotspot/share/classfile/modules.cpp
author naoto
Tue, 09 Jul 2019 08:05:38 -0700
changeset 55627 9c1885fb2a42
parent 54847 59ea39bb2809
child 58177 4932dce35882
permissions -rw-r--r--
8227127: Era designator not displayed correctly using the COMPAT provider Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
53441
5c2c9555afc1 8217450: Add PackageEntry::locked_lookup_only
redestad
parents: 51197
diff changeset
     2
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     4
*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     5
* This code is free software; you can redistribute it and/or modify it
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     6
* under the terms of the GNU General Public License version 2 only, as
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     7
* published by the Free Software Foundation.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     8
*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     9
* This code is distributed in the hope that it will be useful, but WITHOUT
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    11
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    12
* version 2 for more details (a copy is included in the LICENSE file that
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    13
* accompanied this code).
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    14
*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    15
* You should have received a copy of the GNU General Public License version
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    16
* 2 along with this work; if not, write to the Free Software Foundation,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    18
*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    20
* or visit www.oracle.com if you need additional information or have any
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    21
* questions.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    22
*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    23
*/
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    24
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    25
#include "precompiled.hpp"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    26
#include "jvm.h"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    27
#include "classfile/classFileParser.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    28
#include "classfile/classLoader.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    29
#include "classfile/classLoaderData.inline.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    30
#include "classfile/javaAssertions.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    31
#include "classfile/javaClasses.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    32
#include "classfile/javaClasses.inline.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    33
#include "classfile/moduleEntry.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    34
#include "classfile/modules.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    35
#include "classfile/packageEntry.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    36
#include "classfile/stringTable.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    37
#include "classfile/symbolTable.hpp"
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
    38
#include "classfile/systemDictionary.hpp"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    39
#include "classfile/vmSymbols.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    40
#include "logging/log.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
    41
#include "logging/logStream.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37242
diff changeset
    42
#include "memory/resourceArea.hpp"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    43
#include "oops/instanceKlass.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    44
#include "runtime/arguments.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    45
#include "runtime/handles.inline.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    46
#include "runtime/javaCalls.hpp"
49192
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 47765
diff changeset
    47
#include "runtime/jniHandles.inline.hpp"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    48
#include "runtime/reflection.hpp"
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
    49
#include "utilities/stringUtils.hpp"
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
#include "utilities/utf8.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    51
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
    52
static bool verify_module_name(const char *module_name) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
  if (module_name == NULL) return false;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
  int len = (int)strlen(module_name);
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
    55
  return (len > 0 && len <= Symbol::max_length());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    56
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    57
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
    58
bool Modules::verify_package_name(const char* package_name) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    59
  if (package_name == NULL) return false;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    60
  int len = (int)strlen(package_name);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    61
  return (len > 0 && len <= Symbol::max_length() &&
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
    62
    UTF8::is_legal_utf8((const unsigned char *)package_name, len, false) &&
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    ClassFileParser::verify_unqualified_name(package_name, len,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    64
    ClassFileParser::LegalClass));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    65
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    66
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    67
static char* get_module_name(oop module, TRAPS) {
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
    68
  oop name_oop = java_lang_Module::name(module);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    69
  if (name_oop == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), "Null module name");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    71
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    72
  char* module_name = java_lang_String::as_utf8_string(name_oop);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    73
  if (!verify_module_name(module_name)) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    74
    THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    75
                   err_msg("Invalid module name: %s",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    76
                           module_name != NULL ? module_name : "NULL"));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    77
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    78
  return module_name;
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
static const char* get_module_version(jstring version) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    82
  if (version == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    return NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    84
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    85
  return java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(version));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    86
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    87
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49348
diff changeset
    88
ModuleEntryTable* Modules::get_module_entry_table(Handle h_loader) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    89
  // This code can be called during start-up, before the classLoader's classLoader data got
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    90
  // created.  So, call register_loader() to make sure the classLoader data gets created.
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49192
diff changeset
    91
  ClassLoaderData *loader_cld = SystemDictionary::register_loader(h_loader);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    92
  return loader_cld->modules();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    93
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    94
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49192
diff changeset
    95
static PackageEntryTable* get_package_entry_table(Handle h_loader) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    96
  // This code can be called during start-up, before the classLoader's classLoader data got
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    97
  // created.  So, call register_loader() to make sure the classLoader data gets created.
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49192
diff changeset
    98
  ClassLoaderData *loader_cld = SystemDictionary::register_loader(h_loader);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    99
  return loader_cld->packages();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   100
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   101
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   102
static ModuleEntry* get_module_entry(jobject module, TRAPS) {
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49192
diff changeset
   103
  oop m = JNIHandles::resolve(module);
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49192
diff changeset
   104
  if (!java_lang_Module::is_instance(m)) {
40020
20738e6bef83 8160487: JVM should validate a module by checking for an instance of java.lang.reflect.Module
lfoltan
parents: 40013
diff changeset
   105
    THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   106
                   "module is not an instance of type java.lang.Module");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   107
  }
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49192
diff changeset
   108
  return java_lang_Module::module_entry(m);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   109
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   110
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   111
static PackageEntry* get_package_entry(ModuleEntry* module_entry, const char* package_name, TRAPS) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   112
  ResourceMark rm(THREAD);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   113
  if (package_name == NULL) return NULL;
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 53664
diff changeset
   114
  TempNewSymbol pkg_symbol = SymbolTable::new_symbol(package_name);
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
   115
  PackageEntryTable* package_entry_table = module_entry->loader_data()->packages();
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   116
  assert(package_entry_table != NULL, "Unexpected null package entry table");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   117
  return package_entry_table->lookup_only(pkg_symbol);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   118
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   119
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   120
static PackageEntry* get_package_entry_by_name(Symbol* package,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                                               Handle h_loader,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                                               TRAPS) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   123
  if (package != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    ResourceMark rm(THREAD);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   125
    if (Modules::verify_package_name(package->as_C_string())) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   126
      PackageEntryTable* const package_entry_table =
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49192
diff changeset
   127
        get_package_entry_table(h_loader);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   128
      assert(package_entry_table != NULL, "Unexpected null package entry table");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   129
      return package_entry_table->lookup_only(package);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   130
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   131
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   132
  return NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   133
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   134
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   135
bool Modules::is_package_defined(Symbol* package, Handle h_loader, TRAPS) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   136
  PackageEntry* res = get_package_entry_by_name(package, h_loader, CHECK_false);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   137
  return res != NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   138
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   139
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   140
static void define_javabase_module(jobject module, jstring version,
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   141
                                   jstring location, const char* const* packages,
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   142
                                   jsize num_packages, TRAPS) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   143
  ResourceMark rm(THREAD);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   144
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   145
  Handle module_handle(THREAD, JNIHandles::resolve(module));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   146
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   147
  // Obtain java.base's module version
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   148
  const char* module_version = get_module_version(version);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   149
  TempNewSymbol version_symbol;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   150
  if (module_version != NULL) {
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 53664
diff changeset
   151
    version_symbol = SymbolTable::new_symbol(module_version);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   152
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   153
    version_symbol = NULL;
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
  // Obtain java.base's location
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   157
  const char* module_location = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   158
  TempNewSymbol location_symbol = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   159
  if (location != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   160
    module_location =
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   161
      java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(location));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    if (module_location != NULL) {
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 53664
diff changeset
   163
      location_symbol = SymbolTable::new_symbol(module_location);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   165
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   166
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   167
46322
25836096c89d 8172514: Stop checking for duplicate packages in the JVM_DefineModule() package list
hseigel
parents: 46296
diff changeset
   168
  // Check that the packages are syntactically ok.
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   169
  GrowableArray<Symbol*>* pkg_list = new GrowableArray<Symbol*>(num_packages);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   170
  for (int x = 0; x < num_packages; x++) {
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   171
    const char *package_name = packages[x];
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   172
    if (!Modules::verify_package_name(package_name)) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   173
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
42636
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 41691
diff changeset
   174
                err_msg("Invalid package name: %s for module: " JAVA_BASE_NAME, package_name));
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   175
    }
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 53664
diff changeset
   176
    Symbol* pkg_symbol = SymbolTable::new_symbol(package_name);
46322
25836096c89d 8172514: Stop checking for duplicate packages in the JVM_DefineModule() package list
hseigel
parents: 46296
diff changeset
   177
    pkg_list->append(pkg_symbol);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   178
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   179
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   180
  // Validate java_base's loader is the boot loader.
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   181
  oop loader = java_lang_Module::loader(module_handle());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   182
  if (loader != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   183
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   184
              "Class loader must be the boot class loader");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   185
  }
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42656
diff changeset
   186
  Handle h_loader(THREAD, loader);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   187
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   188
  // Ensure the boot loader's PackageEntryTable has been created
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49192
diff changeset
   189
  PackageEntryTable* package_table = get_package_entry_table(h_loader);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   190
  assert(pkg_list->length() == 0 || package_table != NULL, "Bad package_table");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   191
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   192
  // Ensure java.base's ModuleEntry has been created
42636
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 41691
diff changeset
   193
  assert(ModuleEntryTable::javabase_moduleEntry() != NULL, "No ModuleEntry for " JAVA_BASE_NAME);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   194
38732
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   195
  bool duplicate_javabase = false;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   196
  {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   197
    MutexLocker m1(Module_lock, THREAD);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   198
38014
8731fa11f766 8152949: Jigsaw crash when Klass in _fixup_module_field_list is unloaded
lfoltan
parents: 37248
diff changeset
   199
    if (ModuleEntryTable::javabase_defined()) {
38732
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   200
      duplicate_javabase = true;
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   201
    } else {
38014
8731fa11f766 8152949: Jigsaw crash when Klass in _fixup_module_field_list is unloaded
lfoltan
parents: 37248
diff changeset
   202
38732
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   203
      // Verify that all java.base packages created during bootstrapping are in
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   204
      // pkg_list.  If any are not in pkg_list, than a non-java.base class was
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   205
      // loaded erroneously pre java.base module definition.
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   206
      package_table->verify_javabase_packages(pkg_list);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   207
38732
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   208
      // loop through and add any new packages for java.base
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   209
      for (int x = 0; x < pkg_list->length(); x++) {
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   210
        // Some of java.base's packages were added early in bootstrapping, ignore duplicates.
53471
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 53441
diff changeset
   211
        package_table->locked_create_entry_if_not_exist(pkg_list->at(x),
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 53441
diff changeset
   212
                                                        ModuleEntryTable::javabase_moduleEntry());
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 53441
diff changeset
   213
        assert(package_table->locked_lookup_only(pkg_list->at(x)) != NULL,
53441
5c2c9555afc1 8217450: Add PackageEntry::locked_lookup_only
redestad
parents: 51197
diff changeset
   214
               "Unable to create a " JAVA_BASE_NAME " package entry");
38732
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   215
        // Unable to have a GrowableArray of TempNewSymbol.  Must decrement the refcount of
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   216
        // the Symbol* that was created above for each package. The refcount was incremented
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   217
        // by SymbolTable::new_symbol and as well by the PackageEntry creation.
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   218
        pkg_list->at(x)->decrement_refcount();
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   219
      }
38732
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   220
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   221
      // Finish defining java.base's ModuleEntry
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   222
      ModuleEntryTable::finalize_javabase(module_handle, version_symbol, location_symbol);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   223
    }
38732
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   224
  }
bb77e0dcc7e5 8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
hseigel
parents: 38207
diff changeset
   225
  if (duplicate_javabase) {
43446
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   226
    THROW_MSG(vmSymbols::java_lang_InternalError(),
42636
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 41691
diff changeset
   227
              "Module " JAVA_BASE_NAME " is already defined");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   228
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   229
41691
1be281ee5de4 8166364: fatal error: acquiring lock DirtyCardQ_CBL_mon/16 out of order with lock Module_lock/6 -- possible deadlock
hseigel
parents: 41183
diff changeset
   230
  // Only the thread that actually defined the base module will get here,
1be281ee5de4 8166364: fatal error: acquiring lock DirtyCardQ_CBL_mon/16 out of order with lock Module_lock/6 -- possible deadlock
hseigel
parents: 41183
diff changeset
   231
  // so no locking is needed.
1be281ee5de4 8166364: fatal error: acquiring lock DirtyCardQ_CBL_mon/16 out of order with lock Module_lock/6 -- possible deadlock
hseigel
parents: 41183
diff changeset
   232
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   233
  // Patch any previously loaded class's module field with java.base's java.lang.Module.
41691
1be281ee5de4 8166364: fatal error: acquiring lock DirtyCardQ_CBL_mon/16 out of order with lock Module_lock/6 -- possible deadlock
hseigel
parents: 41183
diff changeset
   234
  ModuleEntryTable::patch_javabase_entries(module_handle);
1be281ee5de4 8166364: fatal error: acquiring lock DirtyCardQ_CBL_mon/16 out of order with lock Module_lock/6 -- possible deadlock
hseigel
parents: 41183
diff changeset
   235
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   236
  log_info(module, load)(JAVA_BASE_NAME " location: %s",
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   237
                         module_location != NULL ? module_location : "NULL");
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   238
  log_debug(module)("define_javabase_module(): Definition of module: "
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   239
                    JAVA_BASE_NAME ", version: %s, location: %s, package #: %d",
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   240
                    module_version != NULL ? module_version : "NULL",
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   241
                    module_location != NULL ? module_location : "NULL",
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   242
                    pkg_list->length());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   243
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   244
  // packages defined to java.base
46458
kvn
parents: 46404 44993
diff changeset
   245
  if (log_is_enabled(Trace, module)) {
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   246
    for (int x = 0; x < pkg_list->length(); x++) {
46458
kvn
parents: 46404 44993
diff changeset
   247
      log_trace(module)("define_javabase_module(): creation of package %s for module " JAVA_BASE_NAME,
kvn
parents: 46404 44993
diff changeset
   248
                        (pkg_list->at(x))->as_C_string());
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   249
    }
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   250
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   251
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   252
43446
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   253
// Caller needs ResourceMark.
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   254
void throw_dup_pkg_exception(const char* module_name, PackageEntry* package, TRAPS) {
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   255
  const char* package_name = package->name()->as_C_string();
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   256
  if (package->module()->is_named()) {
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   257
    THROW_MSG(vmSymbols::java_lang_IllegalStateException(),
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   258
      err_msg("Package %s for module %s is already in another module, %s, defined to the class loader",
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   259
              package_name, module_name, package->module()->name()->as_C_string()));
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   260
  } else {
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   261
    THROW_MSG(vmSymbols::java_lang_IllegalStateException(),
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   262
      err_msg("Package %s for module %s is already in the unnamed module defined to the class loader",
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   263
              package_name, module_name));
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   264
  }
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   265
}
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   266
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   267
void Modules::define_module(jobject module, jboolean is_open, jstring version,
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   268
                            jstring location, const char* const* packages,
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   269
                            jsize num_packages, TRAPS) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   270
  ResourceMark rm(THREAD);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   271
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   272
  if (module == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   273
    THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   274
  }
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   275
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   276
  if (num_packages < 0) {
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   277
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   278
              "num_packages must be >= 0");
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   279
  }
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   280
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   281
  if (packages == NULL && num_packages > 0) {
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   282
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   283
              "num_packages should be zero if packages is null");
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   284
  }
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   285
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   286
  Handle module_handle(THREAD, JNIHandles::resolve(module));
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   287
  if (!java_lang_Module::is_instance(module_handle())) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   288
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   289
              "module is not an instance of type java.lang.Module");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   290
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   291
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   292
  char* module_name = get_module_name(module_handle(), CHECK);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   293
  if (module_name == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   294
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   295
              "Module name cannot be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   296
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   297
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   298
  // Special handling of java.base definition
42636
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 41691
diff changeset
   299
  if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   300
    assert(is_open == JNI_FALSE, "java.base module cannot be open");
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   301
    define_javabase_module(module, version, location, packages, num_packages, CHECK);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   302
    return;
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
  const char* module_version = get_module_version(version);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   306
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   307
  oop loader = java_lang_Module::loader(module_handle());
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   308
  // Make sure loader is not the jdk.internal.reflect.DelegatingClassLoader.
51197
3a6be93c9660 8204970: Remaing object comparisons need to use oopDesc::equals()
rkennke
parents: 50634
diff changeset
   309
  if (!oopDesc::equals(loader, java_lang_ClassLoader::non_reflection_class_loader(loader))) {
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   310
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   311
              "Class loader is an invalid delegating class loader");
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   312
  }
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   313
  Handle h_loader = Handle(THREAD, loader);
50634
c349d409262a 8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents: 49739
diff changeset
   314
  // define_module can be called during start-up, before the class loader's ClassLoaderData
c349d409262a 8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents: 49739
diff changeset
   315
  // has been created.  SystemDictionary::register_loader ensures creation, if needed.
c349d409262a 8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents: 49739
diff changeset
   316
  ClassLoaderData* loader_data = SystemDictionary::register_loader(h_loader);
c349d409262a 8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents: 49739
diff changeset
   317
  assert(loader_data != NULL, "class loader data shouldn't be null");
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   318
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   319
  // Check that the list of packages has no duplicates and that the
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   320
  // packages are syntactically ok.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   321
  GrowableArray<Symbol*>* pkg_list = new GrowableArray<Symbol*>(num_packages);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   322
  for (int x = 0; x < num_packages; x++) {
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   323
    const char* package_name = packages[x];
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   324
    if (!verify_package_name(package_name)) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   325
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   326
                err_msg("Invalid package name: %s for module: %s",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   327
                        package_name, module_name));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   328
    }
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   329
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   330
    // Only modules defined to either the boot or platform class loader, can define a "java/" package.
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   331
    if (!h_loader.is_null() &&
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42656
diff changeset
   332
        !SystemDictionary::is_platform_class_loader(h_loader()) &&
44326
6c59cca7ff07 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43471
diff changeset
   333
        (strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0 &&
6c59cca7ff07 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43471
diff changeset
   334
          (package_name[JAVAPKG_LEN] == '/' || package_name[JAVAPKG_LEN] == '\0'))) {
50634
c349d409262a 8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents: 49739
diff changeset
   335
      const char* class_loader_name = loader_data->loader_name_and_id();
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   336
      size_t pkg_len = strlen(package_name);
53664
2f4c2bc90b22 8218581: Incorrect exception message generation
mikael
parents: 53471
diff changeset
   337
      char* pkg_name = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, pkg_len + 1);
2f4c2bc90b22 8218581: Incorrect exception message generation
mikael
parents: 53471
diff changeset
   338
      strncpy(pkg_name, package_name, pkg_len + 1);
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   339
      StringUtils::replace_no_expand(pkg_name, "/", ".");
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   340
      const char* msg_text1 = "Class loader (instance of): ";
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   341
      const char* msg_text2 = " tried to define prohibited package name: ";
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   342
      size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + pkg_len + 1;
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   343
      char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len);
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   344
      jio_snprintf(message, len, "%s%s%s%s", msg_text1, class_loader_name, msg_text2, pkg_name);
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   345
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), message);
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   346
    }
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41691
diff changeset
   347
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 53664
diff changeset
   348
    Symbol* pkg_symbol = SymbolTable::new_symbol(package_name);
46322
25836096c89d 8172514: Stop checking for duplicate packages in the JVM_DefineModule() package list
hseigel
parents: 46296
diff changeset
   349
    pkg_list->append(pkg_symbol);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   350
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   351
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49192
diff changeset
   352
  ModuleEntryTable* module_table = get_module_entry_table(h_loader);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   353
  assert(module_table != NULL, "module entry table shouldn't be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   354
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   355
  // Create symbol* entry for module name.
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 53664
diff changeset
   356
  TempNewSymbol module_symbol = SymbolTable::new_symbol(module_name);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   357
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   358
  bool dupl_modules = false;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   359
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   360
  // Create symbol* entry for module version.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   361
  TempNewSymbol version_symbol;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   362
  if (module_version != NULL) {
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 53664
diff changeset
   363
    version_symbol = SymbolTable::new_symbol(module_version);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   364
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   365
    version_symbol = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   366
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   367
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   368
  // Create symbol* entry for module location.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   369
  const char* module_location = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   370
  TempNewSymbol location_symbol = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   371
  if (location != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   372
    module_location =
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   373
      java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(location));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   374
    if (module_location != NULL) {
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 53664
diff changeset
   375
      location_symbol = SymbolTable::new_symbol(module_location);
36508
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
  PackageEntryTable* package_table = NULL;
43446
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   380
  PackageEntry* existing_pkg = NULL;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   381
  {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   382
    MutexLocker ml(Module_lock, THREAD);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   383
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   384
    if (num_packages > 0) {
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49192
diff changeset
   385
      package_table = get_package_entry_table(h_loader);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   386
      assert(package_table != NULL, "Missing package_table");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   387
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   388
      // Check that none of the packages exist in the class loader's package table.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   389
      for (int x = 0; x < pkg_list->length(); x++) {
53441
5c2c9555afc1 8217450: Add PackageEntry::locked_lookup_only
redestad
parents: 51197
diff changeset
   390
        existing_pkg = package_table->locked_lookup_only(pkg_list->at(x));
43446
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   391
        if (existing_pkg != NULL) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   392
          // This could be because the module was already defined.  If so,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   393
          // report that error instead of the package error.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   394
          if (module_table->lookup_only(module_symbol) != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   395
            dupl_modules = true;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   396
          }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   397
          break;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   398
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   399
      }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   400
    }  // if (num_packages > 0)...
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   401
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   402
    // Add the module and its packages.
43446
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   403
    if (!dupl_modules && existing_pkg == NULL) {
53471
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 53441
diff changeset
   404
      if (module_table->lookup_only(module_symbol) == NULL) {
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 53441
diff changeset
   405
        // Create the entry for this module in the class loader's module entry table.
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 53441
diff changeset
   406
        ModuleEntry* module_entry = module_table->locked_create_entry(module_handle,
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   407
                                    (is_open == JNI_TRUE), module_symbol,
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   408
                                    version_symbol, location_symbol, loader_data);
53471
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 53441
diff changeset
   409
        assert(module_entry != NULL, "module_entry creation failed");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   410
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   411
        // Add the packages.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   412
        assert(pkg_list->length() == 0 || package_table != NULL, "Bad package table");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   413
        for (int y = 0; y < pkg_list->length(); y++) {
53471
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 53441
diff changeset
   414
          package_table->locked_create_entry(pkg_list->at(y), module_entry);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   415
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   416
          // Unable to have a GrowableArray of TempNewSymbol.  Must decrement the refcount of
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   417
          // the Symbol* that was created above for each package. The refcount was incremented
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   418
          // by SymbolTable::new_symbol and as well by the PackageEntry creation.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   419
          pkg_list->at(y)->decrement_refcount();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   420
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   421
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   422
        // Store pointer to ModuleEntry record in java.lang.Module object.
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   423
        java_lang_Module::set_module_entry(module_handle(), module_entry);
53471
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 53441
diff changeset
   424
      } else {
525f212f1bda 8217660: Refactor module related locked_create_entry_or_null() functions
hseigel
parents: 53441
diff changeset
   425
         dupl_modules = true;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   426
      }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   427
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   428
  }  // Release the lock
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   429
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   430
  // any errors ?
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   431
  if (dupl_modules) {
43446
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   432
     THROW_MSG(vmSymbols::java_lang_IllegalStateException(),
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   433
               err_msg("Module %s is already defined", module_name));
43446
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   434
  } else if (existing_pkg != NULL) {
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42656
diff changeset
   435
      throw_dup_pkg_exception(module_name, existing_pkg, CHECK);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   436
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   437
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   438
  log_info(module, load)("%s location: %s", module_name,
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   439
                         module_location != NULL ? module_location : "NULL");
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   440
  LogTarget(Debug, module) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   441
  if (lt.is_enabled()) {
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   442
    LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   443
    ls.print("define_module(): creation of module: %s, version: %s, location: %s, ",
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   444
                 module_name, module_version != NULL ? module_version : "NULL",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   445
                 module_location != NULL ? module_location : "NULL");
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   446
    loader_data->print_value_on(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   447
    ls.print_cr(", package #: %d", pkg_list->length());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   448
    for (int y = 0; y < pkg_list->length(); y++) {
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   449
      log_trace(module)("define_module(): creation of package %s for module %s",
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   450
                        (pkg_list->at(y))->as_C_string(), module_name);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   451
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   452
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   453
37773
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents: 37248
diff changeset
   454
  // If the module is defined to the boot loader and an exploded build is being
46463
4bd2ca84df7a 8178604: JVM does not allow defining boot loader modules in exploded build after module system initialization
hseigel
parents: 46458
diff changeset
   455
  // used, prepend <java.home>/modules/modules_name to the system boot class path.
4bd2ca84df7a 8178604: JVM does not allow defining boot loader modules in exploded build after module system initialization
hseigel
parents: 46458
diff changeset
   456
  if (loader == NULL && !ClassLoader::has_jrt_entry()) {
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 39706
diff changeset
   457
    ClassLoader::add_to_exploded_build_list(module_symbol, CHECK);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   458
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   459
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   460
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   461
void Modules::set_bootloader_unnamed_module(jobject module, TRAPS) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   462
  ResourceMark rm(THREAD);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   463
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   464
  if (module == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   465
    THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   466
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   467
  Handle module_handle(THREAD, JNIHandles::resolve(module));
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   468
  if (!java_lang_Module::is_instance(module_handle())) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   469
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   470
              "module is not an instance of type java.lang.Module");
36508
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
  // Ensure that this is an unnamed module
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   474
  oop name = java_lang_Module::name(module_handle());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   475
  if (name != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   476
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   477
              "boot loader's unnamed module's java.lang.Module has a name");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   478
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   479
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   480
  // Validate java_base's loader is the boot loader.
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   481
  oop loader = java_lang_Module::loader(module_handle());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   482
  if (loader != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   483
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   484
              "Class loader must be the boot class loader");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   485
  }
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42656
diff changeset
   486
  Handle h_loader(THREAD, loader);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   487
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   488
  log_debug(module)("set_bootloader_unnamed_module(): recording unnamed module for boot loader");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   489
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   490
  // Set java.lang.Module for the boot loader's unnamed module
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46369
diff changeset
   491
  ClassLoaderData* boot_loader_data = ClassLoaderData::the_null_class_loader_data();
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46369
diff changeset
   492
  ModuleEntry* unnamed_module = boot_loader_data->unnamed_module();
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   493
  assert(unnamed_module != NULL, "boot loader's unnamed ModuleEntry not defined");
46387
c46632622b17 8176472: Lazily create ModuleEntryTable
rprotacio
parents: 46369
diff changeset
   494
  unnamed_module->set_module(boot_loader_data->add_handle(module_handle));
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   495
  // Store pointer to the ModuleEntry in the unnamed module's java.lang.Module object.
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   496
  java_lang_Module::set_module_entry(module_handle(), unnamed_module);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   497
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   498
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   499
void Modules::add_module_exports(jobject from_module, const char* package_name, jobject to_module, TRAPS) {
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   500
  if (package_name == NULL) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   501
    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   502
              "package is null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   503
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   504
  if (from_module == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   505
    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   506
              "from_module is null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   507
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   508
  ModuleEntry* from_module_entry = get_module_entry(from_module, CHECK);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   509
  if (from_module_entry == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   510
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   511
              "from_module cannot be found");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   512
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   513
46404
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   514
  // All packages in unnamed and open modules are exported by default.
ae62ba99a1a7 8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents: 46388
diff changeset
   515
  if (!from_module_entry->is_named() || from_module_entry->is_open()) return;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   516
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   517
  ModuleEntry* to_module_entry;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   518
  if (to_module == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   519
    to_module_entry = NULL;  // It's an unqualified export.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   520
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   521
    to_module_entry = get_module_entry(to_module, CHECK);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   522
    if (to_module_entry == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   523
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   524
                "to_module is invalid");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   525
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   526
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   527
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   528
  PackageEntry *package_entry = get_package_entry(from_module_entry, package_name, CHECK);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   529
  ResourceMark rm(THREAD);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   530
  if (package_entry == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   531
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   532
              err_msg("Package %s not found in from_module %s",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   533
                      package_name != NULL ? package_name : "",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   534
                      from_module_entry->name()->as_C_string()));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   535
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   536
  if (package_entry->module() != from_module_entry) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   537
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   538
              err_msg("Package: %s found in module %s, not in from_module: %s",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   539
                      package_entry->name()->as_C_string(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   540
                      package_entry->module()->name()->as_C_string(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   541
                      from_module_entry->name()->as_C_string()));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   542
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   543
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   544
  log_debug(module)("add_module_exports(): package %s in module %s is exported to module %s",
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   545
                    package_entry->name()->as_C_string(),
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   546
                    from_module_entry->name()->as_C_string(),
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   547
                    to_module_entry == NULL ? "NULL" :
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   548
                      to_module_entry->is_named() ?
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   549
                        to_module_entry->name()->as_C_string() : UNNAMED_MODULE);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   550
39290
0cc9f5028562 8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents: 38733
diff changeset
   551
  // Do nothing if modules are the same.
0cc9f5028562 8156871: Possible concurrency issue with JVM_AddModuleExports
lfoltan
parents: 38733
diff changeset
   552
  if (from_module_entry != to_module_entry) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   553
    package_entry->set_exported(to_module_entry);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   554
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   555
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   556
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   557
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   558
void Modules::add_module_exports_qualified(jobject from_module, const char* package,
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   559
                                           jobject to_module, TRAPS) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   560
  if (to_module == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   561
    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   562
              "to_module is null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   563
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   564
  add_module_exports(from_module, package, to_module, CHECK);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   565
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   566
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   567
void Modules::add_reads_module(jobject from_module, jobject to_module, TRAPS) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   568
  if (from_module == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   569
    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   570
              "from_module is null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   571
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   572
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   573
  ModuleEntry* from_module_entry = get_module_entry(from_module, CHECK);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   574
  if (from_module_entry == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   575
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   576
              "from_module is not valid");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   577
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   578
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   579
  ModuleEntry* to_module_entry;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   580
  if (to_module != NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   581
    to_module_entry = get_module_entry(to_module, CHECK);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   582
    if (to_module_entry == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   583
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   584
                "to_module is invalid");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   585
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   586
  } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   587
    to_module_entry = NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   588
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   589
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   590
  ResourceMark rm(THREAD);
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   591
  log_debug(module)("add_reads_module(): Adding read from module %s to module %s",
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   592
                    from_module_entry->is_named() ?
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   593
                    from_module_entry->name()->as_C_string() : UNNAMED_MODULE,
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   594
                    to_module_entry == NULL ? "all unnamed" :
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   595
                      (to_module_entry->is_named() ?
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   596
                       to_module_entry->name()->as_C_string() : UNNAMED_MODULE));
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   597
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   598
  // if modules are the same or if from_module is unnamed then no need to add the read.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   599
  if (from_module_entry != to_module_entry && from_module_entry->is_named()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   600
    from_module_entry->add_read(to_module_entry);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   601
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   602
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   603
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   604
// This method is called by JFR and JNI.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   605
jobject Modules::get_module(jclass clazz, TRAPS) {
42636
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 41691
diff changeset
   606
  assert(ModuleEntryTable::javabase_defined(),
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 41691
diff changeset
   607
         "Attempt to call get_module before " JAVA_BASE_NAME " is defined");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   608
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   609
  if (clazz == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   610
    THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   611
               "class is null", JNI_FALSE);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   612
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   613
  oop mirror = JNIHandles::resolve_non_null(clazz);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   614
  if (mirror == NULL) {
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   615
    log_debug(module)("get_module(): no mirror, returning NULL");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   616
    return NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   617
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   618
  if (!java_lang_Class::is_instance(mirror)) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   619
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   620
               "Invalid class", JNI_FALSE);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   621
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   622
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   623
  oop module = java_lang_Class::module(mirror);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   624
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   625
  assert(module != NULL, "java.lang.Class module field not set");
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   626
  assert(java_lang_Module::is_instance(module), "module is not an instance of type java.lang.Module");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   627
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   628
  LogTarget(Debug,module) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   629
  if (lt.is_enabled()) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   630
    ResourceMark rm(THREAD);
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   631
    LogStream ls(lt);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   632
    Klass* klass = java_lang_Class::as_Klass(mirror);
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44326
diff changeset
   633
    oop module_name = java_lang_Module::name(module);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   634
    if (module_name != NULL) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   635
      ls.print("get_module(): module ");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   636
      java_lang_String::print(module_name, tty);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   637
    } else {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   638
      ls.print("get_module(): Unamed Module");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   639
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   640
    if (klass != NULL) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   641
      ls.print_cr(" for class %s", klass->external_name());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   642
    } else {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46632
diff changeset
   643
      ls.print_cr(" for primitive class");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   644
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   645
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   646
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   647
  return JNIHandles::make_local(THREAD, module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   648
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   649
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   650
jobject Modules::get_named_module(Handle h_loader, const char* package_name, TRAPS) {
39706
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   651
  assert(ModuleEntryTable::javabase_defined(),
42636
aafc434ba580 8169734: Update uses of string "java.base" to macro
rprotacio
parents: 41691
diff changeset
   652
         "Attempt to call get_named_module before " JAVA_BASE_NAME " is defined");
39706
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   653
  assert(h_loader.is_null() || java_lang_ClassLoader::is_subclass(h_loader->klass()),
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   654
         "Class loader is not a subclass of java.lang.ClassLoader");
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   655
  assert(package_name != NULL, "the package_name should not be NULL");
39706
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   656
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   657
  if (strlen(package_name) == 0) {
39706
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   658
    return NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   659
  }
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 53664
diff changeset
   660
  TempNewSymbol package_sym = SymbolTable::new_symbol(package_name);
39706
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   661
  const PackageEntry* const pkg_entry =
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   662
    get_package_entry_by_name(package_sym, h_loader, THREAD);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   663
  const ModuleEntry* const module_entry = (pkg_entry != NULL ? pkg_entry->module() : NULL);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   664
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   665
  if (module_entry != NULL && module_entry->module() != NULL && module_entry->is_named()) {
46773
fb17cc9a6847 8185717: Make ModuleEntry->module() return an oop not a jobject
hseigel
parents: 46701
diff changeset
   666
    return JNIHandles::make_local(THREAD, module_entry->module());
39706
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   667
  }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   668
  return NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   669
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   670
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 39616
diff changeset
   671
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   672
// This method is called by JFR and by the above method.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   673
jobject Modules::get_module(Symbol* package_name, Handle h_loader, TRAPS) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   674
  const PackageEntry* const pkg_entry =
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   675
    get_package_entry_by_name(package_name, h_loader, THREAD);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   676
  const ModuleEntry* const module_entry = (pkg_entry != NULL ? pkg_entry->module() : NULL);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   677
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   678
  if (module_entry != NULL &&
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   679
      module_entry->module() != NULL) {
46773
fb17cc9a6847 8185717: Make ModuleEntry->module() return an oop not a jobject
hseigel
parents: 46701
diff changeset
   680
    return JNIHandles::make_local(THREAD, module_entry->module());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   681
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   682
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   683
  return NULL;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   684
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   685
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   686
// Export package in module to all unnamed modules.
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   687
void Modules::add_module_exports_to_all_unnamed(jobject module, const char* package_name, TRAPS) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   688
  if (module == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   689
    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   690
              "module is null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   691
  }
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   692
  if (package_name == NULL) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   693
    THROW_MSG(vmSymbols::java_lang_NullPointerException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   694
              "package is null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   695
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   696
  ModuleEntry* module_entry = get_module_entry(module, CHECK);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   697
  if (module_entry == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   698
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   699
              "module is invalid");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   700
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   701
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   702
  if (module_entry->is_named()) { // No-op for unnamed module.
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 43446
diff changeset
   703
    PackageEntry *package_entry = get_package_entry(module_entry, package_name, CHECK);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   704
    ResourceMark rm(THREAD);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   705
    if (package_entry == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   706
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   707
                err_msg("Package %s not found in module %s",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   708
                        package_name != NULL ? package_name : "",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   709
                        module_entry->name()->as_C_string()));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   710
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   711
    if (package_entry->module() != module_entry) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   712
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   713
                err_msg("Package: %s found in module %s, not in module: %s",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   714
                        package_entry->name()->as_C_string(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   715
                        package_entry->module()->name()->as_C_string(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   716
                        module_entry->name()->as_C_string()));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   717
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   718
44993
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   719
    log_debug(module)("add_module_exports_to_all_unnamed(): package %s in module"
f61bcd80ec1f 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44520
diff changeset
   720
                      " %s is exported to all unnamed modules",
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   721
                       package_entry->name()->as_C_string(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   722
                       module_entry->name()->as_C_string());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   723
43471
bfb383279a16 8171971: Fix timing bug in JVM management of package export lists
hseigel
parents: 43466
diff changeset
   724
    // Mark package as exported to all unnamed modules.
bfb383279a16 8171971: Fix timing bug in JVM management of package export lists
hseigel
parents: 43466
diff changeset
   725
    package_entry->set_is_exported_allUnnamed();
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   726
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   727
}