36508
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, 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_VM_CLASSFILE_MODULES_HPP
|
|
26 |
#define SHARE_VM_CLASSFILE_MODULES_HPP
|
|
27 |
|
|
28 |
#include "memory/allocation.hpp"
|
|
29 |
#include "runtime/handles.hpp"
|
|
30 |
|
|
31 |
class Symbol;
|
|
32 |
|
|
33 |
class Modules : AllStatic {
|
|
34 |
|
|
35 |
public:
|
|
36 |
// define_module defines a module containing the specified packages. It binds the
|
|
37 |
// module to its class loader by creating the ModuleEntry record in the
|
|
38 |
// ClassLoader's ModuleEntry table, and creates PackageEntry records in the class
|
|
39 |
// loader's PackageEntry table. As in JVM_DefineClass the jstring format for all
|
|
40 |
// package names must use "/" and not "."
|
|
41 |
//
|
|
42 |
// IllegalArgumentExceptions are thrown for the following :
|
|
43 |
// * Module's Class loader is not a subclass of java.lang.ClassLoader
|
|
44 |
// * Module's Class loader already has a module with that name
|
|
45 |
// * Module's Class loader has already defined types for any of the module's packages
|
|
46 |
// * Module_name is syntactically bad
|
|
47 |
// * Packages contains an illegal package name
|
|
48 |
// * Packages contains a duplicate package name
|
|
49 |
// * A package already exists in another module for this class loader
|
|
50 |
// * Module is an unnamed module
|
|
51 |
// NullPointerExceptions are thrown if module is null.
|
|
52 |
static void define_module(jobject module, jstring version,
|
|
53 |
jstring location, jobjectArray packages, TRAPS);
|
|
54 |
|
|
55 |
// Provides the java.lang.reflect.Module for the unnamed module defined
|
|
56 |
// to the boot loader.
|
|
57 |
//
|
|
58 |
// IllegalArgumentExceptions are thrown for the following :
|
|
59 |
// * Module has a name
|
|
60 |
// * Module is not a subclass of java.lang.reflect.Module
|
|
61 |
// * Module's class loader is not the boot loader
|
|
62 |
// NullPointerExceptions are thrown if module is null.
|
|
63 |
static void set_bootloader_unnamed_module(jobject module, TRAPS);
|
|
64 |
|
|
65 |
// This either does a qualified export of package in module from_module to module
|
|
66 |
// to_module or, if to_module is null, does an unqualified export of package.
|
|
67 |
// The format for the package name must use "/' not ".".
|
|
68 |
//
|
|
69 |
// Error conditions causing IlegalArgumentException to be throw :
|
|
70 |
// * Module from_module does not exist
|
|
71 |
// * Module to_module is not null and does not exist
|
|
72 |
// * Package is not syntactically correct
|
|
73 |
// * Package is not defined for from_module's class loader
|
|
74 |
// * Package is not in module from_module.
|
|
75 |
static void add_module_exports(jobject from_module, jstring package, jobject to_module, TRAPS);
|
|
76 |
|
|
77 |
// This does a qualified export of package in module from_module to module
|
|
78 |
// to_module. The format for the package name must use "/' not ".".
|
|
79 |
//
|
|
80 |
// Error conditions causing IlegalArgumentException to be throw :
|
|
81 |
// * Module from_module does not exist
|
|
82 |
// * Module to_module does not exist
|
|
83 |
// * Package is not syntactically correct
|
|
84 |
// * Package is not defined for from_module's class loader
|
|
85 |
// * Package is not in module from_module.
|
|
86 |
static void add_module_exports_qualified(jobject from_module, jstring package, jobject to_module, TRAPS);
|
|
87 |
|
|
88 |
// add_reads_module adds module to_module to the list of modules that from_module
|
|
89 |
// can read. If from_module is the same as to_module then this is a no-op.
|
|
90 |
// If to_module is null then from_module is marked as a loose module (meaning that
|
|
91 |
// from_module can read all current and future unnamed modules).
|
|
92 |
// An IllegalArgumentException is thrown if from_module is null or either (non-null)
|
|
93 |
// module does not exist.
|
|
94 |
static void add_reads_module(jobject from_module, jobject to_module, TRAPS);
|
|
95 |
|
|
96 |
// can_read_module returns TRUE if module asking_module can read module target_module,
|
|
97 |
// or if they are the same module, or if the asking_module is loose and target_module
|
|
98 |
// is null.
|
|
99 |
//
|
|
100 |
// Throws IllegalArgumentException if:
|
|
101 |
// * either asking_module or target_module is not a java.lang.reflect.Module
|
|
102 |
static jboolean can_read_module(jobject asking_module, jobject target_module, TRAPS);
|
|
103 |
|
|
104 |
// If package is valid then this returns TRUE if module from_module exports
|
|
105 |
// package to module to_module, if from_module and to_module are the same
|
|
106 |
// module, or if package is exported without qualification.
|
|
107 |
//
|
|
108 |
// IllegalArgumentException is throw if:
|
|
109 |
// * Either to_module or from_module does not exist
|
|
110 |
// * package is syntactically incorrect
|
|
111 |
// * package is not in from_module
|
|
112 |
static jboolean is_exported_to_module(jobject from_module, jstring package, jobject to_module, TRAPS);
|
|
113 |
|
|
114 |
// Return the java.lang.reflect.Module object for this class object.
|
|
115 |
static jobject get_module(jclass clazz, TRAPS);
|
|
116 |
|
|
117 |
// Return the java.lang.reflect.Module object for this class loader and package.
|
|
118 |
// Returns NULL if the class loader has not loaded any classes in the package.
|
|
119 |
// The package should contain /'s, not .'s, as in java/lang, not java.lang.
|
|
120 |
// NullPointerException is thrown if package is null.
|
|
121 |
// IllegalArgumentException is thrown if loader is neither null nor a subtype of
|
|
122 |
// java/lang/ClassLoader.
|
|
123 |
static jobject get_module_by_package_name(jobject loader, jstring package, TRAPS);
|
|
124 |
|
|
125 |
// If package is defined by loader, return the
|
|
126 |
// java.lang.reflect.Module object for the module in which the package is defined.
|
|
127 |
// Returns NULL if package is invalid or not defined by loader.
|
|
128 |
static jobject get_module(Symbol* package_name, Handle h_loader, TRAPS);
|
|
129 |
|
|
130 |
// This adds package to module.
|
|
131 |
// It throws IllegalArgumentException if:
|
|
132 |
// * Module is bad
|
|
133 |
// * Module is unnamed
|
|
134 |
// * Package is not syntactically correct
|
|
135 |
// * Package is already defined for module's class loader.
|
|
136 |
static void add_module_package(jobject module, jstring package, TRAPS);
|
|
137 |
|
|
138 |
// Marks the specified package as exported to all unnamed modules.
|
|
139 |
// If either module or package is null then NullPointerException is thrown.
|
|
140 |
// If module or package is bad, or module is unnamed, or package is not in
|
|
141 |
// module then IllegalArgumentException is thrown.
|
|
142 |
static void add_module_exports_to_all_unnamed(jobject module, jstring package, TRAPS);
|
|
143 |
|
|
144 |
// Return TRUE if package_name is syntactically valid, false otherwise.
|
|
145 |
static bool verify_package_name(char *package_name);
|
|
146 |
|
|
147 |
// Return TRUE iff package is defined by loader
|
|
148 |
static bool is_package_defined(Symbol* package_name, Handle h_loader, TRAPS);
|
|
149 |
};
|
|
150 |
|
|
151 |
#endif // SHARE_VM_CLASSFILE_MODULES_HPP
|