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 #include "precompiled.hpp"
26 #include "classfile/classFileParser.hpp"
27 #include "classfile/classFileStream.hpp"
28 #include "classfile/classLoader.inline.hpp"
29 #include "classfile/classLoaderExt.hpp"
30 #include "classfile/classLoaderData.inline.hpp"
31 #include "classfile/klassFactory.hpp"
32 #include "classfile/modules.hpp"
33 #include "classfile/sharedPathsMiscInfo.hpp"
34 #include "classfile/systemDictionaryShared.hpp"
35 #include "classfile/vmSymbols.hpp"
36 #include "memory/allocation.inline.hpp"
37 #include "memory/filemap.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "oops/instanceKlass.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "oops/symbol.hpp"
42 #include "runtime/arguments.hpp"
43 #include "runtime/handles.inline.hpp"
44 #include "runtime/java.hpp"
45 #include "runtime/javaCalls.hpp"
46 #include "runtime/os.hpp"
47 #include "services/threadService.hpp"
48 #include "utilities/stringUtils.hpp"
49
50 jshort ClassLoaderExt::_app_class_paths_start_index = ClassLoaderExt::max_classpath_index;
51 jshort ClassLoaderExt::_app_module_paths_start_index = ClassLoaderExt::max_classpath_index;
52 jshort ClassLoaderExt::_max_used_path_index = 0;
53 bool ClassLoaderExt::_has_app_classes = false;
57 if (UseSharedSpaces) {
58 warning("Sharing is only supported for boot loader classes because bootstrap classpath has been appended");
59 FileMapInfo::current_info()->header()->set_has_platform_or_app_classes(false);
60 }
61 ClassLoader::add_to_boot_append_entries(new_entry);
62 }
63
64 void ClassLoaderExt::setup_app_search_path() {
65 assert(DumpSharedSpaces || DynamicDumpSharedSpaces,
66 "this function is only used at CDS dump time");
67 _app_class_paths_start_index = ClassLoader::num_boot_classpath_entries();
68 char* app_class_path = os::strdup(Arguments::get_appclasspath());
69
70 if (strcmp(app_class_path, ".") == 0) {
71 // This doesn't make any sense, even for AppCDS, so let's skip it. We
72 // don't want to throw an error here because -cp "." is usually assigned
73 // by the launcher when classpath is not specified.
74 trace_class_path("app loader class path (skipped)=", app_class_path);
75 } else {
76 trace_class_path("app loader class path=", app_class_path);
77 shared_paths_misc_info()->add_app_classpath(app_class_path);
78 ClassLoader::setup_app_search_path(app_class_path);
79 }
80 }
81
82 void ClassLoaderExt::process_module_table(ModuleEntryTable* met, TRAPS) {
83 ResourceMark rm(THREAD);
84 for (int i = 0; i < met->table_size(); i++) {
85 for (ModuleEntry* m = met->bucket(i); m != NULL;) {
86 char* path = m->location()->as_C_string();
87 if (strncmp(path, "file:", 5) == 0) {
88 path = ClassLoader::skip_uri_protocol(path);
89 ClassLoader::setup_module_search_path(path, THREAD);
90 }
91 m = m->next();
92 }
93 }
94 }
95 void ClassLoaderExt::setup_module_paths(TRAPS) {
96 assert(DumpSharedSpaces || DynamicDumpSharedSpaces,
97 "this function is only used with CDS dump time");
205 file_end = end;
206 }
207
208 size_t name_len = strlen(file_start);
209 if (name_len > 0) {
210 ResourceMark rm(THREAD);
211 size_t libname_len = dir_len + name_len;
212 char* libname = NEW_RESOURCE_ARRAY(char, libname_len + 1);
213 int n = os::snprintf(libname, libname_len + 1, "%.*s%s", dir_len, dir_name, file_start);
214 assert((size_t)n == libname_len, "Unexpected number of characters in string");
215 trace_class_path("library = ", libname);
216 ClassLoader::update_class_path_entry_list(libname, true, false, true /* from_class_path_attr */);
217 }
218
219 file_start = file_end;
220 }
221 }
222 }
223
224 void ClassLoaderExt::setup_search_paths() {
225 shared_paths_misc_info()->record_app_offset();
226 ClassLoaderExt::setup_app_search_path();
227 }
228
229 void ClassLoaderExt::record_result(const s2 classpath_index,
230 InstanceKlass* result,
231 TRAPS) {
232 assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "Sanity");
233
234 // We need to remember where the class comes from during dumping.
235 oop loader = result->class_loader();
236 s2 classloader_type = ClassLoader::BOOT_LOADER;
237 if (SystemDictionary::is_system_class_loader(loader)) {
238 classloader_type = ClassLoader::APP_LOADER;
239 ClassLoaderExt::set_has_app_classes();
240 } else if (SystemDictionary::is_platform_class_loader(loader)) {
241 classloader_type = ClassLoader::PLATFORM_LOADER;
242 ClassLoaderExt::set_has_platform_classes();
243 }
244 if (classpath_index > ClassLoaderExt::max_used_path_index()) {
245 ClassLoaderExt::set_max_used_path_index(classpath_index);
246 }
247 result->set_shared_classpath_index(classpath_index);
248 result->set_class_loader_type(classloader_type);
249 }
250
251 void ClassLoaderExt::finalize_shared_paths_misc_info() {
252 if (!_has_app_classes) {
253 shared_paths_misc_info()->pop_app();
254 }
255 }
256
257 // Load the class of the given name from the location given by path. The path is specified by
258 // the "source:" in the class list file (see classListParser.cpp), and can be a directory or
259 // a JAR file.
260 InstanceKlass* ClassLoaderExt::load_class(Symbol* name, const char* path, TRAPS) {
261 assert(name != NULL, "invariant");
262 assert(DumpSharedSpaces, "this function is only used with -Xshare:dump");
263 ResourceMark rm(THREAD);
264 const char* class_name = name->as_C_string();
265
266 const char* file_name = file_name_for_class_name(class_name,
267 name->utf8_length());
268 assert(file_name != NULL, "invariant");
269
270 // Lookup stream for parsing .class file
271 ClassFileStream* stream = NULL;
272 ClassPathEntry* e = find_classpath_entry_from_cache(path, CHECK_NULL);
273 if (e == NULL) {
274 return NULL;
|
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 #include "precompiled.hpp"
26 #include "classfile/classFileParser.hpp"
27 #include "classfile/classFileStream.hpp"
28 #include "classfile/classLoader.inline.hpp"
29 #include "classfile/classLoaderExt.hpp"
30 #include "classfile/classLoaderData.inline.hpp"
31 #include "classfile/klassFactory.hpp"
32 #include "classfile/modules.hpp"
33 #include "classfile/systemDictionaryShared.hpp"
34 #include "classfile/vmSymbols.hpp"
35 #include "memory/allocation.inline.hpp"
36 #include "memory/filemap.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/instanceKlass.hpp"
39 #include "oops/oop.inline.hpp"
40 #include "oops/symbol.hpp"
41 #include "runtime/arguments.hpp"
42 #include "runtime/handles.inline.hpp"
43 #include "runtime/java.hpp"
44 #include "runtime/javaCalls.hpp"
45 #include "runtime/os.hpp"
46 #include "services/threadService.hpp"
47 #include "utilities/stringUtils.hpp"
48
49 jshort ClassLoaderExt::_app_class_paths_start_index = ClassLoaderExt::max_classpath_index;
50 jshort ClassLoaderExt::_app_module_paths_start_index = ClassLoaderExt::max_classpath_index;
51 jshort ClassLoaderExt::_max_used_path_index = 0;
52 bool ClassLoaderExt::_has_app_classes = false;
56 if (UseSharedSpaces) {
57 warning("Sharing is only supported for boot loader classes because bootstrap classpath has been appended");
58 FileMapInfo::current_info()->header()->set_has_platform_or_app_classes(false);
59 }
60 ClassLoader::add_to_boot_append_entries(new_entry);
61 }
62
63 void ClassLoaderExt::setup_app_search_path() {
64 assert(DumpSharedSpaces || DynamicDumpSharedSpaces,
65 "this function is only used at CDS dump time");
66 _app_class_paths_start_index = ClassLoader::num_boot_classpath_entries();
67 char* app_class_path = os::strdup(Arguments::get_appclasspath());
68
69 if (strcmp(app_class_path, ".") == 0) {
70 // This doesn't make any sense, even for AppCDS, so let's skip it. We
71 // don't want to throw an error here because -cp "." is usually assigned
72 // by the launcher when classpath is not specified.
73 trace_class_path("app loader class path (skipped)=", app_class_path);
74 } else {
75 trace_class_path("app loader class path=", app_class_path);
76 ClassLoader::setup_app_search_path(app_class_path);
77 }
78 }
79
80 void ClassLoaderExt::process_module_table(ModuleEntryTable* met, TRAPS) {
81 ResourceMark rm(THREAD);
82 for (int i = 0; i < met->table_size(); i++) {
83 for (ModuleEntry* m = met->bucket(i); m != NULL;) {
84 char* path = m->location()->as_C_string();
85 if (strncmp(path, "file:", 5) == 0) {
86 path = ClassLoader::skip_uri_protocol(path);
87 ClassLoader::setup_module_search_path(path, THREAD);
88 }
89 m = m->next();
90 }
91 }
92 }
93 void ClassLoaderExt::setup_module_paths(TRAPS) {
94 assert(DumpSharedSpaces || DynamicDumpSharedSpaces,
95 "this function is only used with CDS dump time");
203 file_end = end;
204 }
205
206 size_t name_len = strlen(file_start);
207 if (name_len > 0) {
208 ResourceMark rm(THREAD);
209 size_t libname_len = dir_len + name_len;
210 char* libname = NEW_RESOURCE_ARRAY(char, libname_len + 1);
211 int n = os::snprintf(libname, libname_len + 1, "%.*s%s", dir_len, dir_name, file_start);
212 assert((size_t)n == libname_len, "Unexpected number of characters in string");
213 trace_class_path("library = ", libname);
214 ClassLoader::update_class_path_entry_list(libname, true, false, true /* from_class_path_attr */);
215 }
216
217 file_start = file_end;
218 }
219 }
220 }
221
222 void ClassLoaderExt::setup_search_paths() {
223 ClassLoaderExt::setup_app_search_path();
224 }
225
226 void ClassLoaderExt::record_result(const s2 classpath_index,
227 InstanceKlass* result,
228 TRAPS) {
229 assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "Sanity");
230
231 // We need to remember where the class comes from during dumping.
232 oop loader = result->class_loader();
233 s2 classloader_type = ClassLoader::BOOT_LOADER;
234 if (SystemDictionary::is_system_class_loader(loader)) {
235 classloader_type = ClassLoader::APP_LOADER;
236 ClassLoaderExt::set_has_app_classes();
237 } else if (SystemDictionary::is_platform_class_loader(loader)) {
238 classloader_type = ClassLoader::PLATFORM_LOADER;
239 ClassLoaderExt::set_has_platform_classes();
240 }
241 if (classpath_index > ClassLoaderExt::max_used_path_index()) {
242 ClassLoaderExt::set_max_used_path_index(classpath_index);
243 }
244 result->set_shared_classpath_index(classpath_index);
245 result->set_class_loader_type(classloader_type);
246 }
247
248 // Load the class of the given name from the location given by path. The path is specified by
249 // the "source:" in the class list file (see classListParser.cpp), and can be a directory or
250 // a JAR file.
251 InstanceKlass* ClassLoaderExt::load_class(Symbol* name, const char* path, TRAPS) {
252 assert(name != NULL, "invariant");
253 assert(DumpSharedSpaces, "this function is only used with -Xshare:dump");
254 ResourceMark rm(THREAD);
255 const char* class_name = name->as_C_string();
256
257 const char* file_name = file_name_for_class_name(class_name,
258 name->utf8_length());
259 assert(file_name != NULL, "invariant");
260
261 // Lookup stream for parsing .class file
262 ClassFileStream* stream = NULL;
263 ClassPathEntry* e = find_classpath_entry_from_cache(path, CHECK_NULL);
264 if (e == NULL) {
265 return NULL;
|