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_CLASSLOADEREXT_HPP
26 #define SHARE_VM_CLASSFILE_CLASSLOADEREXT_HPP
27
28 #include "classfile/classLoader.hpp"
29 #include "classfile/moduleEntry.hpp"
30 #include "utilities/macros.hpp"
31
32 CDS_ONLY(class SharedPathsMiscInfoExt;)
33 CDS_ONLY(class ClassListParser;)
34
35 class ClassLoaderExt: public ClassLoader { // AllStatic
36 public:
37 enum SomeConstants {
38 max_classpath_index = 0x7fff
39 };
40 // ClassLoaderExt::Context --
41 //
42 // This is used by DumpSharedSpaces only - it enforces the same classloader
43 // delegation model as would be in run-time. I.e.,
44 // + classes defined by the NULL class loader cannot load classes in the PLATFORM or APP paths.
45 // + classes defined by the PLATFORM class loader cannot load classes in the APP paths.
46 class Context {
47 static Thread* _dump_thread;
48 const char* _class_name;
49 const char* _file_name;
50 public:
51 const char* class_name() {
52 return _class_name;
53 }
54 const char* file_name() {
55 return _file_name;
56 }
57
58 Context(const char* class_name, const char* file_name, TRAPS) {
59 _class_name = class_name;
60 _file_name = file_name;
61 #if INCLUDE_CDS
62 if (!DumpSharedSpaces && !UseSharedSpaces) {
63 // Must not modify _app_class_paths_start_index if we're not using CDS.
64 assert(_app_class_paths_start_index == ClassLoaderExt::max_classpath_index, "must be");
65 }
66 #endif
67 }
68
69 bool should_verify(int classpath_index) {
70 CDS_ONLY(return (classpath_index >= _app_class_paths_start_index);)
71 NOT_CDS(return false;)
72 }
73
74 void record_result(Symbol* class_name,
75 const s2 classpath_index,
76 InstanceKlass* result,
77 TRAPS) {
78 #if INCLUDE_CDS
79 ClassLoaderExt::record_result(this, class_name, classpath_index, result, THREAD);
80 #endif
81 }
82
83 ~Context() {
84 #if INCLUDE_CDS
85 if (!DumpSharedSpaces && !UseSharedSpaces) {
86 // Must not modify app_class_paths_start_index if we're not using CDS.
87 assert(_app_class_paths_start_index == ClassLoaderExt::max_classpath_index, "must be");
88 }
89 #endif
90 }
91 }; // end ClassLoaderExt::Context
92
93 private:
94 #if INCLUDE_CDS
95 static char* get_class_path_attr(const char* jar_path, char* manifest, jint manifest_size);
96 static void setup_app_search_path(); // Only when -Xshare:dump
97 static void process_module_table(ModuleEntryTable* met, TRAPS);
98 static SharedPathsMiscInfoExt* shared_paths_misc_info() {
99 return (SharedPathsMiscInfoExt*)_shared_paths_misc_info;
100 }
101 // index of first app JAR in shared classpath entry table
102 static jshort _app_class_paths_start_index;
103 // index of first modular JAR in shared modulepath entry table
104 static jshort _app_module_paths_start_index;
105
106 static bool _has_app_classes;
107 static bool _has_platform_classes;
108 #endif
109
110 public:
111 CDS_ONLY(static void process_jar_manifest(ClassPathEntry* entry, bool check_for_duplicates);)
112
113 // Called by JVMTI code to add boot classpath
114 static void append_boot_classpath(ClassPathEntry* new_entry);
115
116 static void setup_search_paths() NOT_CDS_RETURN;
117 static void setup_module_paths(TRAPS) NOT_CDS_RETURN;
118
119 #if INCLUDE_CDS
120 private:
121 static char* read_manifest(ClassPathEntry* entry, jint *manifest_size, bool clean_text, TRAPS);
122 static ClassPathEntry* find_classpath_entry_from_cache(const char* path, TRAPS);
123
124 public:
125 static char* read_manifest(ClassPathEntry* entry, jint *manifest_size, TRAPS) {
126 // Remove all the new-line continuations (which wrap long lines at 72 characters, see
127 // http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Manifest), so
128 // that the manifest is easier to parse.
129 return read_manifest(entry, manifest_size, true, THREAD);
130 }
131 static char* read_raw_manifest(ClassPathEntry* entry, jint *manifest_size, TRAPS) {
132 // Do not remove new-line continuations, so we can easily pass it as an argument to
139 static jshort app_class_paths_start_index() { return _app_class_paths_start_index; }
140
141 static jshort app_module_paths_start_index() { return _app_module_paths_start_index; }
142
143 static void init_paths_start_index(jshort app_start) {
144 _app_class_paths_start_index = app_start;
145 }
146
147 static void init_app_module_paths_start_index(jshort module_start) {
148 _app_module_paths_start_index = module_start;
149 }
150
151 static bool is_boot_classpath(int classpath_index) {
152 return classpath_index < _app_class_paths_start_index;
153 }
154
155 static bool has_platform_or_app_classes() {
156 return _has_app_classes || _has_platform_classes;
157 }
158
159 static void record_result(class ClassLoaderExt::Context *context,
160 Symbol* class_name,
161 const s2 classpath_index,
162 InstanceKlass* result, TRAPS);
163 static InstanceKlass* load_class(Symbol* h_name, const char* path, TRAPS);
164 static Klass* load_one_class(ClassListParser* parser, TRAPS);
165 static void set_has_app_classes() {
166 _has_app_classes = true;
167 }
168 static void set_has_platform_classes() {
169 _has_platform_classes = true;
170 }
171 #endif
172 };
173
174 #endif // SHARE_VM_CLASSFILE_CLASSLOADEREXT_HPP
|
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_CLASSLOADEREXT_HPP
26 #define SHARE_VM_CLASSFILE_CLASSLOADEREXT_HPP
27
28 #include "classfile/classLoader.hpp"
29 #include "classfile/moduleEntry.hpp"
30 #include "utilities/macros.hpp"
31
32 class ClassListParser;
33
34 class ClassLoaderExt: public ClassLoader { // AllStatic
35 public:
36 enum SomeConstants {
37 max_classpath_index = 0x7fff
38 };
39
40 private:
41 #if INCLUDE_CDS
42 static char* get_class_path_attr(const char* jar_path, char* manifest, jint manifest_size);
43 static void setup_app_search_path(); // Only when -Xshare:dump
44 static void process_module_table(ModuleEntryTable* met, TRAPS);
45 static SharedPathsMiscInfo* shared_paths_misc_info() {
46 return (SharedPathsMiscInfo*)_shared_paths_misc_info;
47 }
48 // index of first app JAR in shared classpath entry table
49 static jshort _app_class_paths_start_index;
50 // index of first modular JAR in shared modulepath entry table
51 static jshort _app_module_paths_start_index;
52
53 static bool _has_app_classes;
54 static bool _has_platform_classes;
55 #endif
56
57 public:
58 CDS_ONLY(static void process_jar_manifest(ClassPathEntry* entry, bool check_for_duplicates);)
59
60 static bool should_verify(int classpath_index) {
61 CDS_ONLY(return (classpath_index >= _app_class_paths_start_index);)
62 NOT_CDS(return false;)
63 }
64 // Called by JVMTI code to add boot classpath
65 static void append_boot_classpath(ClassPathEntry* new_entry);
66
67 static void setup_search_paths() NOT_CDS_RETURN;
68 static void setup_module_paths(TRAPS) NOT_CDS_RETURN;
69
70 #if INCLUDE_CDS
71 private:
72 static char* read_manifest(ClassPathEntry* entry, jint *manifest_size, bool clean_text, TRAPS);
73 static ClassPathEntry* find_classpath_entry_from_cache(const char* path, TRAPS);
74
75 public:
76 static char* read_manifest(ClassPathEntry* entry, jint *manifest_size, TRAPS) {
77 // Remove all the new-line continuations (which wrap long lines at 72 characters, see
78 // http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Manifest), so
79 // that the manifest is easier to parse.
80 return read_manifest(entry, manifest_size, true, THREAD);
81 }
82 static char* read_raw_manifest(ClassPathEntry* entry, jint *manifest_size, TRAPS) {
83 // Do not remove new-line continuations, so we can easily pass it as an argument to
90 static jshort app_class_paths_start_index() { return _app_class_paths_start_index; }
91
92 static jshort app_module_paths_start_index() { return _app_module_paths_start_index; }
93
94 static void init_paths_start_index(jshort app_start) {
95 _app_class_paths_start_index = app_start;
96 }
97
98 static void init_app_module_paths_start_index(jshort module_start) {
99 _app_module_paths_start_index = module_start;
100 }
101
102 static bool is_boot_classpath(int classpath_index) {
103 return classpath_index < _app_class_paths_start_index;
104 }
105
106 static bool has_platform_or_app_classes() {
107 return _has_app_classes || _has_platform_classes;
108 }
109
110 static void record_result(const s2 classpath_index,
111 InstanceKlass* result, TRAPS);
112 static InstanceKlass* load_class(Symbol* h_name, const char* path, TRAPS);
113 static Klass* load_one_class(ClassListParser* parser, TRAPS);
114 static void set_has_app_classes() {
115 _has_app_classes = true;
116 }
117 static void set_has_platform_classes() {
118 _has_platform_classes = true;
119 }
120 #endif
121 };
122
123 #endif // SHARE_VM_CLASSFILE_CLASSLOADEREXT_HPP
|