1 /*
2 * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24 
25 #ifndef SHARE_CLASSFILE_MODULES_HPP
26 #define SHARE_CLASSFILE_MODULES_HPP
27 
28 #include "memory/allocation.hpp"
29 #include "runtime/handles.hpp"
30 
31 class ModuleEntryTable;
32 class Symbol;
33 
34 class Modules : AllStatic {
35   static void check_cds_restrictions(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
36 
37 public:
38   // define_module defines a module containing the specified packages. It binds the
39   // module to its class loader by creating the ModuleEntry record in the
40   // ClassLoader's ModuleEntry table, and creates PackageEntry records in the class
41   // loader's PackageEntry table.  The jstring for all package names will convert "."
42   // to "/"
43   //
44   //  IllegalArgumentExceptions are thrown for the following :
45   // * Module's Class loader is not a subclass of java.lang.ClassLoader
46   // * Module's Class loader already has a module with that name
47   // * Module's Class loader has already defined types for any of the module's packages
48   // * Module_name is syntactically bad
49   // * Packages contains an illegal package name or a non-String object
50   // * A package already exists in another module for this class loader
51   // * Module is an unnamed module
52   //  NullPointerExceptions are thrown if module is null.
53   static void define_module(jobject module, jboolean is_open, jstring version,
54                             jstring location, jobjectArray packages, TRAPS);
55 
56   static void define_archived_modules(jobject platform_loader, jobject system_loader,
57                                       TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
58 
59   // Provides the java.lang.Module for the unnamed module defined
60   // to the boot loader.
61   //
62   //  IllegalArgumentExceptions are thrown for the following :
63   //  * Module has a name
64   //  * Module is not a subclass of java.lang.Module
65   //  * Module's class loader is not the boot loader
66   //  NullPointerExceptions are thrown if module is null.
67   static void set_bootloader_unnamed_module(jobject module, TRAPS);
68 
69   // This either does a qualified export of package in module from_module to module
70   // to_module or, if to_module is null, does an unqualified export of package.
71   // Any "." in the package name will be converted to "/"
72   //
73   // Error conditions causing IlegalArgumentException to be throw :
74   // * Module from_module does not exist
75   // * Module to_module is not null and does not exist
76   // * Package is not syntactically correct
77   // * Package is not defined for from_module's class loader
78   // * Package is not in module from_module.
79   static void add_module_exports(jobject from_module, jstring package, jobject to_module, TRAPS);
80 
81   // This does a qualified export of package in module from_module to module
82   // to_module.  Any "." in the package name will be converted to "/"
83   //
84   // Error conditions causing IlegalArgumentException to be throw :
85   // * Module from_module does not exist
86   // * Module to_module does not exist
87   // * Package is not syntactically correct
88   // * Package is not defined for from_module's class loader
89   // * Package is not in module from_module.
90   static void add_module_exports_qualified(jobject from_module, jstring package, jobject to_module, TRAPS);
91 
92   // add_reads_module adds module to_module to the list of modules that from_module
93   // can read.  If from_module is the same as to_module then this is a no-op.
94   // If to_module is null then from_module is marked as a loose module (meaning that
95   // from_module can read all current and future unnamed  modules).
96   // An IllegalArgumentException is thrown if from_module is null or either (non-null)
97   // module does not exist.
98   static void add_reads_module(jobject from_module, jobject to_module, TRAPS);
99 
100   // Return the java.lang.Module object for this class object.
101   static jobject get_module(jclass clazz, TRAPS);
102 
103   // Return the java.lang.Module object for this class loader and package.
104   // Returns NULL if the class loader has not loaded any classes in the package.
105   // The package should contain /'s, not .'s, as in java/lang, not java.lang.
106   // NullPointerException is thrown if package is null.
107   // IllegalArgumentException is thrown if loader is neither null nor a subtype of
108   // java/lang/ClassLoader.
109   static jobject get_named_module(Handle h_loader, const char* package, TRAPS);
110 
111   // Marks the specified package as exported to all unnamed modules.
112   // If either module or package is null then NullPointerException is thrown.
113   // If module or package is bad, or module is unnamed, or package is not in
114   // module then IllegalArgumentException is thrown.
115   static void add_module_exports_to_all_unnamed(jobject module, jstring package, TRAPS);
116 
117   // Return TRUE iff package is defined by loader
118   static bool is_package_defined(Symbol* package_name, Handle h_loader, TRAPS);
119   static ModuleEntryTable* get_module_entry_table(Handle h_loader);
120 };
121 
122 #endif // SHARE_CLASSFILE_MODULES_HPP
123