hotspot/src/share/vm/classfile/modules.hpp
author alanb
Fri, 07 Apr 2017 08:04:46 +0000
changeset 44520 0553e129e0ec
parent 43466 add500644443
child 45628 ea212c4584d7
child 46388 d7a164ad6b7f
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: lfoltan, sspitsyn Contributed-by: alan.bateman@oracle.com, harold.seigel@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43466
diff changeset
     2
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     4
*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     5
* This code is free software; you can redistribute it and/or modify it
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     6
* under the terms of the GNU General Public License version 2 only, as
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     7
* published by the Free Software Foundation.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     8
*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     9
* This code is distributed in the hope that it will be useful, but WITHOUT
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    11
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    12
* version 2 for more details (a copy is included in the LICENSE file that
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    13
* accompanied this code).
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    14
*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    15
* You should have received a copy of the GNU General Public License version
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    16
* 2 along with this work; if not, write to the Free Software Foundation,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    18
*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    20
* or visit www.oracle.com if you need additional information or have any
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    21
* questions.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    22
*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    23
*/
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    24
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    25
#ifndef SHARE_VM_CLASSFILE_MODULES_HPP
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    26
#define SHARE_VM_CLASSFILE_MODULES_HPP
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    27
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    28
#include "memory/allocation.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    29
#include "runtime/handles.hpp"
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    30
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    31
class Symbol;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    32
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    33
class Modules : AllStatic {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    34
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    35
public:
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    36
  // define_module defines a module containing the specified packages. It binds the
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    37
  // module to its class loader by creating the ModuleEntry record in the
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    38
  // ClassLoader's ModuleEntry table, and creates PackageEntry records in the class
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    39
  // loader's PackageEntry table.  As in JVM_DefineClass the jstring format for all
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    40
  // package names must use "/" and not "."
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    41
  //
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    42
  //  IllegalArgumentExceptions are thrown for the following :
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    43
  // * Module's Class loader is not a subclass of java.lang.ClassLoader
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    44
  // * Module's Class loader already has a module with that name
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    45
  // * Module's Class loader has already defined types for any of the module's packages
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    46
  // * Module_name is syntactically bad
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    47
  // * Packages contains an illegal package name
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    48
  // * Packages contains a duplicate package name
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    49
  // * A package already exists in another module for this class loader
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
  // * Module is an unnamed module
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 42307
diff changeset
    51
  // * num_packages is negative
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 42307
diff changeset
    52
  // * num_packages is non-zero when packages is null
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
  //  NullPointerExceptions are thrown if module is null.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
  static void define_module(jobject module, jstring version,
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 42307
diff changeset
    55
                            jstring location, const char* const* packages,
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 42307
diff changeset
    56
                            jsize num_packages, TRAPS);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    57
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43466
diff changeset
    58
  // Provides the java.lang.Module for the unnamed module defined
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    59
  // to the boot loader.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    60
  //
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    61
  //  IllegalArgumentExceptions are thrown for the following :
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    62
  //  * Module has a name
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43466
diff changeset
    63
  //  * Module is not a subclass of java.lang.Module
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    64
  //  * Module's class loader is not the boot loader
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    65
  //  NullPointerExceptions are thrown if module is null.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    66
  static void set_bootloader_unnamed_module(jobject module, TRAPS);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    67
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    68
  // This either does a qualified export of package in module from_module to module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    69
  // to_module or, if to_module is null, does an unqualified export of package.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    70
  // The format for the package name must use "/' not ".".
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    71
  //
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    72
  // Error conditions causing IlegalArgumentException to be throw :
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    73
  // * Module from_module does not exist
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    74
  // * Module to_module is not null and does not exist
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    75
  // * Package is not syntactically correct
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    76
  // * Package is not defined for from_module's class loader
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    77
  // * Package is not in module from_module.
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 42307
diff changeset
    78
  static void add_module_exports(jobject from_module, const char* package, jobject to_module, TRAPS);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    79
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    80
  // This does a qualified export of package in module from_module to module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    81
  // to_module.  The format for the package name must use "/' not ".".
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    82
  //
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    83
  // Error conditions causing IlegalArgumentException to be throw :
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    84
  // * Module from_module does not exist
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    85
  // * Module to_module does not exist
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    86
  // * Package is not syntactically correct
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    87
  // * Package is not defined for from_module's class loader
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    88
  // * Package is not in module from_module.
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 42307
diff changeset
    89
  static void add_module_exports_qualified(jobject from_module, const char* package, jobject to_module, TRAPS);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    90
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    91
  // add_reads_module adds module to_module to the list of modules that from_module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    92
  // can read.  If from_module is the same as to_module then this is a no-op.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    93
  // If to_module is null then from_module is marked as a loose module (meaning that
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    94
  // from_module can read all current and future unnamed  modules).
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    95
  // An IllegalArgumentException is thrown if from_module is null or either (non-null)
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    96
  // module does not exist.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    97
  static void add_reads_module(jobject from_module, jobject to_module, TRAPS);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    98
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43466
diff changeset
    99
  // Return the java.lang.Module object for this class object.
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   100
  static jobject get_module(jclass clazz, TRAPS);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   101
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43466
diff changeset
   102
  // Return the java.lang.Module object for this class loader and package.
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   103
  // Returns NULL if the class loader has not loaded any classes in the package.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   104
  // The package should contain /'s, not .'s, as in java/lang, not java.lang.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   105
  // NullPointerException is thrown if package is null.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   106
  // IllegalArgumentException is thrown if loader is neither null nor a subtype of
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   107
  // java/lang/ClassLoader.
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 42307
diff changeset
   108
  static jobject get_module_by_package_name(jobject loader, const char* package, TRAPS);
39706
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents: 36508
diff changeset
   109
  static jobject get_named_module(Handle h_loader, const char* package, TRAPS);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   110
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   111
  // If package is defined by loader, return the
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43466
diff changeset
   112
  // java.lang.Module object for the module in which the package is defined.
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   113
  // Returns NULL if package is invalid or not defined by loader.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   114
  static jobject get_module(Symbol* package_name, Handle h_loader, TRAPS);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   115
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   116
  // This adds package to module.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   117
  // It throws IllegalArgumentException if:
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   118
  // * Module is bad
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   119
  // * Module is unnamed
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   120
  // * Package is not syntactically correct
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   121
  // * Package is already defined for module's class loader.
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 42307
diff changeset
   122
  static void add_module_package(jobject module, const char* package, TRAPS);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   123
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   124
  // Marks the specified package as exported to all unnamed modules.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   125
  // If either module or package is null then NullPointerException is thrown.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   126
  // If module or package is bad, or module is unnamed, or package is not in
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   127
  // module then IllegalArgumentException is thrown.
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 42307
diff changeset
   128
  static void add_module_exports_to_all_unnamed(jobject module, const char* package, TRAPS);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   129
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   130
  // Return TRUE if package_name is syntactically valid, false otherwise.
43466
add500644443 8171855: Move package name transformations during module bootstrap into native code
redestad
parents: 42307
diff changeset
   131
  static bool verify_package_name(const char *package_name);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   132
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   133
  // Return TRUE iff package is defined by loader
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   134
  static bool is_package_defined(Symbol* package_name, Handle h_loader, TRAPS);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   135
};
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   136
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   137
#endif // SHARE_VM_CLASSFILE_MODULES_HPP