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;
54 bool ClassLoaderExt::_has_platform_classes = false;
55
56 void ClassLoaderExt::append_boot_classpath(ClassPathEntry* new_entry) {
57 if (UseSharedSpaces) {
58 warning("Sharing is only supported for boot loader classes because bootstrap classpath has been appended");
59 FileMapInfo::current_info()->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 ClassLoader::setup_app_search_path(app_class_path);
78 }
79 }
80
81 void ClassLoaderExt::process_module_table(ModuleEntryTable* met, TRAPS) {
82 ResourceMark rm(THREAD);
83 for (int i = 0; i < met->table_size(); i++) {
84 for (ModuleEntry* m = met->bucket(i); m != NULL;) {
85 char* path = m->location()->as_C_string();
86 if (strncmp(path, "file:", 5) == 0) {
87 path = ClassLoader::skip_uri_protocol(path);
88 ClassLoader::setup_module_search_path(path, THREAD);
89 }
90 m = m->next();
91 }
92 }
93 }
94 void ClassLoaderExt::setup_module_paths(TRAPS) {
95 assert(DumpSharedSpaces || DynamicDumpSharedSpaces,
96 "this function is only used with CDS dump time");
97 _app_module_paths_start_index = ClassLoader::num_boot_classpath_entries() +
98 ClassLoader::num_app_classpath_entries();
99 Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
100 ModuleEntryTable* met = Modules::get_module_entry_table(system_class_loader);
101 process_module_table(met, THREAD);
102 }
103
104 char* ClassLoaderExt::read_manifest(ClassPathEntry* entry, jint *manifest_size, bool clean_text, TRAPS) {
105 const char* name = "META-INF/MANIFEST.MF";
106 char* manifest;
107 jint size;
108
109 assert(entry->is_jar_file(), "must be");
110 manifest = (char*) ((ClassPathZipEntry*)entry )->open_entry(name, &size, true, CHECK_NULL);
111
112 if (manifest == NULL) { // No Manifest
113 *manifest_size = 0;
114 return NULL;
115 }
116
214 if (ClassLoader::update_class_path_entry_list(libname, true, false, true /* from_class_path_attr */)) {
215 trace_class_path("library = ", libname);
216 } else {
217 trace_class_path("library (non-existent) = ", libname);
218 FileMapInfo::record_non_existent_class_path_entry(libname);
219 }
220 }
221
222 file_start = file_end;
223 }
224 }
225 }
226
227 void ClassLoaderExt::setup_search_paths() {
228 ClassLoaderExt::setup_app_search_path();
229 }
230
231 void ClassLoaderExt::record_result(const s2 classpath_index,
232 InstanceKlass* result,
233 TRAPS) {
234 assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "Sanity");
235
236 // We need to remember where the class comes from during dumping.
237 oop loader = result->class_loader();
238 s2 classloader_type = ClassLoader::BOOT_LOADER;
239 if (SystemDictionary::is_system_class_loader(loader)) {
240 classloader_type = ClassLoader::APP_LOADER;
241 ClassLoaderExt::set_has_app_classes();
242 } else if (SystemDictionary::is_platform_class_loader(loader)) {
243 classloader_type = ClassLoader::PLATFORM_LOADER;
244 ClassLoaderExt::set_has_platform_classes();
245 }
246 if (classpath_index > ClassLoaderExt::max_used_path_index()) {
247 ClassLoaderExt::set_max_used_path_index(classpath_index);
248 }
249 result->set_shared_classpath_index(classpath_index);
250 result->set_class_loader_type(classloader_type);
251 }
252
253 // Load the class of the given name from the location given by path. The path is specified by
254 // the "source:" in the class list file (see classListParser.cpp), and can be a directory or
|
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;
54 bool ClassLoaderExt::_has_platform_classes = false;
55
56 void ClassLoaderExt::append_boot_classpath(ClassPathEntry* new_entry) {
57 if (UseSharedSpaces) {
58 warning("Sharing is only supported for boot loader classes because bootstrap classpath has been appended");
59 FileMapInfo::current_info()->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 Arguments::assert_is_dumping_archive();
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 Arguments::assert_is_dumping_archive();
95 _app_module_paths_start_index = ClassLoader::num_boot_classpath_entries() +
96 ClassLoader::num_app_classpath_entries();
97 Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
98 ModuleEntryTable* met = Modules::get_module_entry_table(system_class_loader);
99 process_module_table(met, THREAD);
100 }
101
102 char* ClassLoaderExt::read_manifest(ClassPathEntry* entry, jint *manifest_size, bool clean_text, TRAPS) {
103 const char* name = "META-INF/MANIFEST.MF";
104 char* manifest;
105 jint size;
106
107 assert(entry->is_jar_file(), "must be");
108 manifest = (char*) ((ClassPathZipEntry*)entry )->open_entry(name, &size, true, CHECK_NULL);
109
110 if (manifest == NULL) { // No Manifest
111 *manifest_size = 0;
112 return NULL;
113 }
114
212 if (ClassLoader::update_class_path_entry_list(libname, true, false, true /* from_class_path_attr */)) {
213 trace_class_path("library = ", libname);
214 } else {
215 trace_class_path("library (non-existent) = ", libname);
216 FileMapInfo::record_non_existent_class_path_entry(libname);
217 }
218 }
219
220 file_start = file_end;
221 }
222 }
223 }
224
225 void ClassLoaderExt::setup_search_paths() {
226 ClassLoaderExt::setup_app_search_path();
227 }
228
229 void ClassLoaderExt::record_result(const s2 classpath_index,
230 InstanceKlass* result,
231 TRAPS) {
232 Arguments::assert_is_dumping_archive();
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 // Load the class of the given name from the location given by path. The path is specified by
252 // the "source:" in the class list file (see classListParser.cpp), and can be a directory or
|