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_CLASSLOADER_HPP
26 #define SHARE_CLASSFILE_CLASSLOADER_HPP
27
28 #include "jimage.hpp"
29 #include "runtime/handles.hpp"
30 #include "runtime/perfData.hpp"
31 #include "utilities/exceptions.hpp"
32 #include "utilities/macros.hpp"
33
34 // The VM class loader.
35 #include <sys/stat.h>
36
37 // Name of boot "modules" image
38 #define MODULES_IMAGE_NAME "modules"
39
40 // Class path entry (directory or zip file)
41
42 class JImageFile;
43 class ClassFileStream;
44 class PackageEntry;
45 template <typename T> class GrowableArray;
46
47 class ClassPathEntry : public CHeapObj<mtClass> {
48 private:
49 ClassPathEntry* volatile _next;
50 public:
51 ClassPathEntry* next() const;
52 virtual ~ClassPathEntry() {}
53 void set_next(ClassPathEntry* next);
54 virtual bool is_modules_image() const = 0;
55 virtual bool is_jar_file() const = 0;
56 virtual const char* name() const = 0;
57 virtual JImageFile* jimage() const = 0;
200 // to load a class.
201
202 // 1. Contains the module/path pairs specified to --patch-module
203 static GrowableArray<ModuleClassPathList*>* _patch_mod_entries;
204
205 // 2. the base piece
206 // Contains the ClassPathEntry of the modular java runtime image.
207 // If no java runtime image is present, this indicates a
208 // build with exploded modules is being used instead.
209 static ClassPathEntry* _jrt_entry;
210 static GrowableArray<ModuleClassPathList*>* _exploded_entries;
211 enum { EXPLODED_ENTRY_SIZE = 80 }; // Initial number of exploded modules
212
213 // 3. the boot loader's append path
214 // [-Xbootclasspath/a]; [jvmti appended entries]
215 // Note: boot loader append path does not support named modules.
216 static ClassPathEntry* _first_append_entry;
217 // Last entry in linked list of appended ClassPathEntry instances
218 static ClassPathEntry* _last_append_entry;
219
220 // Info used by CDS
221 CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;)
222
223 CDS_ONLY(static ClassPathEntry* _app_classpath_entries;)
224 CDS_ONLY(static ClassPathEntry* _last_app_classpath_entry;)
225 CDS_ONLY(static ClassPathEntry* _module_path_entries;)
226 CDS_ONLY(static ClassPathEntry* _last_module_path_entry;)
227 CDS_ONLY(static void setup_app_search_path(const char* class_path);)
228 CDS_ONLY(static void setup_module_search_path(const char* path, TRAPS);)
229 static void add_to_app_classpath_entries(const char* path,
230 ClassPathEntry* entry,
231 bool check_for_duplicates);
232 CDS_ONLY(static void add_to_module_path_entries(const char* path,
233 ClassPathEntry* entry);)
234 public:
235 CDS_ONLY(static ClassPathEntry* app_classpath_entries() {return _app_classpath_entries;})
236 CDS_ONLY(static ClassPathEntry* module_path_entries() {return _module_path_entries;})
237
238 protected:
239 // Initialization:
240 // - setup the boot loader's system class path
241 // - setup the boot loader's patch mod entries, if present
242 // - create the ModuleEntry for java.base
243 static void setup_bootstrap_search_path();
244 static void setup_boot_search_path(const char *class_path);
245 static void setup_patch_mod_entries();
246 static void create_javabase();
247
248 static void load_zip_library();
249 static void load_jimage_library();
250
251 public:
252 static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st,
253 bool throw_exception,
254 bool is_boot_append, TRAPS);
255
256 // If the package for the fully qualified class name is in the boot
257 // loader's package entry table then add_package() sets the classpath_index
258 // field so that get_system_package() will know to return a non-null value
259 // for the package's location. And, so that the package will be added to
260 // the list of packages returned by get_system_packages().
261 // For packages whose classes are loaded from the boot loader class path, the
262 // classpath_index indicates which entry on the boot loader class path.
263 static bool add_package(const char *fullq_class_name, s2 classpath_index, TRAPS);
264
265 // Canonicalizes path names, so strcmp will work properly. This is mainly
266 // to avoid confusing the zip library
267 static bool get_canonical_path(const char* orig, char* out, int len);
268 static const char* file_name_for_class_name(const char* class_name,
269 int class_name_len);
270 static PackageEntry* get_package_entry(const char* class_name, ClassLoaderData* loader_data, TRAPS);
422 static jlong class_verify_time_ms();
423 static jlong class_link_count();
424 static jlong class_link_time_ms();
425
426 // indicates if class path already contains a entry (exact match by name)
427 static bool contains_append_entry(const char* name);
428
429 // adds a class path to the boot append entries
430 static void add_to_boot_append_entries(ClassPathEntry* new_entry);
431
432 // creates a class path zip entry (returns NULL if JAR file cannot be opened)
433 static ClassPathZipEntry* create_class_path_zip_entry(const char *apath, bool is_boot_append);
434
435 static bool string_ends_with(const char* str, const char* str_to_find);
436
437 // obtain package name from a fully qualified class name
438 // *bad_class_name is set to true if there's a problem with parsing class_name, to
439 // distinguish from a class_name with no package name, as both cases have a NULL return value
440 static const char* package_from_name(const char* const class_name, bool* bad_class_name = NULL);
441
442 static bool is_modules_image(const char* name) { return string_ends_with(name, MODULES_IMAGE_NAME); }
443
444 // Debugging
445 static void verify() PRODUCT_RETURN;
446 };
447
448 // PerfClassTraceTime is used to measure time for class loading related events.
449 // This class tracks cumulative time and exclusive time for specific event types.
450 // During the execution of one event, other event types (e.g. class loading and
451 // resolution) as well as recursive calls of the same event type could happen.
452 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
453 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
454 // instances have been created as multiple events are happening.
455 class PerfClassTraceTime {
456 public:
457 enum {
458 CLASS_LOAD = 0,
459 PARSE_CLASS = 1,
460 CLASS_LINK = 2,
461 CLASS_VERIFY = 3,
462 CLASS_CLINIT = 4,
|
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_CLASSLOADER_HPP
26 #define SHARE_CLASSFILE_CLASSLOADER_HPP
27
28 #include "jimage.hpp"
29 #include "runtime/arguments.hpp"
30 #include "runtime/handles.hpp"
31 #include "runtime/perfData.hpp"
32 #include "utilities/exceptions.hpp"
33 #include "utilities/macros.hpp"
34
35 // The VM class loader.
36 #include <sys/stat.h>
37
38 // Name of boot "modules" image
39 // This macro may be used with caution. For most of the cases,
40 // ClassLoader::modules_image_name() should be used.
41 #define MODULES_IMAGE_NAME "modules"
42
43 // Class path entry (directory or zip file)
44
45 class JImageFile;
46 class ClassFileStream;
47 class PackageEntry;
48 template <typename T> class GrowableArray;
49
50 class ClassPathEntry : public CHeapObj<mtClass> {
51 private:
52 ClassPathEntry* volatile _next;
53 public:
54 ClassPathEntry* next() const;
55 virtual ~ClassPathEntry() {}
56 void set_next(ClassPathEntry* next);
57 virtual bool is_modules_image() const = 0;
58 virtual bool is_jar_file() const = 0;
59 virtual const char* name() const = 0;
60 virtual JImageFile* jimage() const = 0;
203 // to load a class.
204
205 // 1. Contains the module/path pairs specified to --patch-module
206 static GrowableArray<ModuleClassPathList*>* _patch_mod_entries;
207
208 // 2. the base piece
209 // Contains the ClassPathEntry of the modular java runtime image.
210 // If no java runtime image is present, this indicates a
211 // build with exploded modules is being used instead.
212 static ClassPathEntry* _jrt_entry;
213 static GrowableArray<ModuleClassPathList*>* _exploded_entries;
214 enum { EXPLODED_ENTRY_SIZE = 80 }; // Initial number of exploded modules
215
216 // 3. the boot loader's append path
217 // [-Xbootclasspath/a]; [jvmti appended entries]
218 // Note: boot loader append path does not support named modules.
219 static ClassPathEntry* _first_append_entry;
220 // Last entry in linked list of appended ClassPathEntry instances
221 static ClassPathEntry* _last_append_entry;
222
223 // The modules image name obtained from the canonical path.
224 static const char* _modules_image_name;
225
226 // Info used by CDS
227 CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;)
228
229 CDS_ONLY(static ClassPathEntry* _app_classpath_entries;)
230 CDS_ONLY(static ClassPathEntry* _last_app_classpath_entry;)
231 CDS_ONLY(static ClassPathEntry* _module_path_entries;)
232 CDS_ONLY(static ClassPathEntry* _last_module_path_entry;)
233 CDS_ONLY(static void setup_app_search_path(const char* class_path);)
234 CDS_ONLY(static void setup_module_search_path(const char* path, TRAPS);)
235 static void add_to_app_classpath_entries(const char* path,
236 ClassPathEntry* entry,
237 bool check_for_duplicates);
238 CDS_ONLY(static void add_to_module_path_entries(const char* path,
239 ClassPathEntry* entry);)
240 public:
241 CDS_ONLY(static ClassPathEntry* app_classpath_entries() {return _app_classpath_entries;})
242 CDS_ONLY(static ClassPathEntry* module_path_entries() {return _module_path_entries;})
243
244 protected:
245 // Initialization:
246 // - setup the boot loader's system class path
247 // - setup the boot loader's patch mod entries, if present
248 // - create the ModuleEntry for java.base
249 static void setup_bootstrap_search_path();
250 static void setup_boot_search_path(const char *class_path);
251 static void setup_patch_mod_entries();
252 static void create_javabase();
253
254 static void load_zip_library();
255 static void load_jimage_library();
256
257 static void init_modules_image_name(const char* modules_path);
258
259 public:
260 static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st,
261 bool throw_exception,
262 bool is_boot_append, TRAPS);
263
264 // If the package for the fully qualified class name is in the boot
265 // loader's package entry table then add_package() sets the classpath_index
266 // field so that get_system_package() will know to return a non-null value
267 // for the package's location. And, so that the package will be added to
268 // the list of packages returned by get_system_packages().
269 // For packages whose classes are loaded from the boot loader class path, the
270 // classpath_index indicates which entry on the boot loader class path.
271 static bool add_package(const char *fullq_class_name, s2 classpath_index, TRAPS);
272
273 // Canonicalizes path names, so strcmp will work properly. This is mainly
274 // to avoid confusing the zip library
275 static bool get_canonical_path(const char* orig, char* out, int len);
276 static const char* file_name_for_class_name(const char* class_name,
277 int class_name_len);
278 static PackageEntry* get_package_entry(const char* class_name, ClassLoaderData* loader_data, TRAPS);
430 static jlong class_verify_time_ms();
431 static jlong class_link_count();
432 static jlong class_link_time_ms();
433
434 // indicates if class path already contains a entry (exact match by name)
435 static bool contains_append_entry(const char* name);
436
437 // adds a class path to the boot append entries
438 static void add_to_boot_append_entries(ClassPathEntry* new_entry);
439
440 // creates a class path zip entry (returns NULL if JAR file cannot be opened)
441 static ClassPathZipEntry* create_class_path_zip_entry(const char *apath, bool is_boot_append);
442
443 static bool string_ends_with(const char* str, const char* str_to_find);
444
445 // obtain package name from a fully qualified class name
446 // *bad_class_name is set to true if there's a problem with parsing class_name, to
447 // distinguish from a class_name with no package name, as both cases have a NULL return value
448 static const char* package_from_name(const char* const class_name, bool* bad_class_name = NULL);
449
450 static const char* modules_image_name() { return _modules_image_name; }
451 static bool is_modules_image(const char* name) {
452 if (Arguments::has_jimage()) {
453 assert(_modules_image_name != NULL, "must be set");
454 return string_ends_with(name, _modules_image_name);
455 }
456 return false;
457 }
458
459 // Debugging
460 static void verify() PRODUCT_RETURN;
461 };
462
463 // PerfClassTraceTime is used to measure time for class loading related events.
464 // This class tracks cumulative time and exclusive time for specific event types.
465 // During the execution of one event, other event types (e.g. class loading and
466 // resolution) as well as recursive calls of the same event type could happen.
467 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
468 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
469 // instances have been created as multiple events are happening.
470 class PerfClassTraceTime {
471 public:
472 enum {
473 CLASS_LOAD = 0,
474 PARSE_CLASS = 1,
475 CLASS_LINK = 2,
476 CLASS_VERIFY = 3,
477 CLASS_CLINIT = 4,
|