1 /*
2 * Copyright (c) 1997, 2025, 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 *
82 }
83 virtual ~ClassPathDirEntry();
84 ClassFileStream* open_stream(JavaThread* current, const char* name);
85 };
86
87 class ClassPathZipEntry: public ClassPathEntry {
88 private:
89 jzfile* _zip; // The zip archive
90 const char* _zip_name; // Name of zip archive
91 public:
92 bool is_jar_file() const { return true; }
93 const char* name() const { return _zip_name; }
94 ClassPathZipEntry(jzfile* zip, const char* zip_name);
95 virtual ~ClassPathZipEntry();
96 bool has_entry(JavaThread* current, const char* name);
97 u1* open_entry(JavaThread* current, const char* name, jint* filesize, bool nul_terminate);
98 ClassFileStream* open_stream(JavaThread* current, const char* name);
99 };
100
101
102 // For java image files
103 class ClassPathImageEntry: public ClassPathEntry {
104 private:
105 const char* _name;
106 DEBUG_ONLY(static ClassPathImageEntry* _singleton;)
107 public:
108 bool is_modules_image() const;
109 const char* name() const { return _name == nullptr ? "" : _name; }
110 JImageFile* jimage() const;
111 JImageFile* jimage_non_null() const;
112 void close_jimage();
113 ClassPathImageEntry(JImageFile* jimage, const char* name);
114 virtual ~ClassPathImageEntry() { ShouldNotReachHere(); }
115 ClassFileStream* open_stream(JavaThread* current, const char* name);
116 ClassFileStream* open_stream_for_loader(JavaThread* current, const char* name, ClassLoaderData* loader_data);
117 };
118
119 // ModuleClassPathList contains a linked list of ClassPathEntry's
120 // that have been specified for a specific module. Currently,
121 // the only way to specify a module/path pair is via the --patch-module
122 // command line option.
123 class ModuleClassPathList : public CHeapObj<mtClass> {
124 private:
125 Symbol* _module_name;
126 // First and last entries of class path entries for a specific module
127 ClassPathEntry* _module_first_entry;
128 ClassPathEntry* _module_last_entry;
129 public:
130 Symbol* module_name() const { return _module_name; }
131 ClassPathEntry* module_first_entry() const { return _module_first_entry; }
132 ModuleClassPathList(Symbol* module_name);
133 ~ModuleClassPathList();
134 void add_to_list(ClassPathEntry* new_entry);
184
185 // Count the time taken to hash the scondary superclass arrays.
186 static PerfCounter* _perf_secondary_hash_time;
187 static PerfCounter* _perf_change_wx_time;
188
189 // The boot class path consists of 3 ordered pieces:
190 // 1. the module/path pairs specified to --patch-module
191 // --patch-module=<module>=<file>(<pathsep><file>)*
192 // 2. the base piece
193 // [jimage | build with exploded modules]
194 // 3. boot loader append path
195 // [-Xbootclasspath/a]; [jvmti appended entries]
196 //
197 // The boot loader must obey this order when attempting
198 // to load a class.
199
200 // 1. Contains the module/path pairs specified to --patch-module
201 static GrowableArray<ModuleClassPathList*>* _patch_mod_entries;
202
203 // 2. the base piece
204 // Contains the ClassPathEntry of the modular java runtime image.
205 // If no java runtime image is present, this indicates a
206 // build with exploded modules is being used instead.
207 static ClassPathEntry* _jrt_entry;
208 static GrowableArray<ModuleClassPathList*>* _exploded_entries;
209 enum { EXPLODED_ENTRY_SIZE = 80 }; // Initial number of exploded modules
210
211 // 3. the boot loader's append path
212 // [-Xbootclasspath/a]; [jvmti appended entries]
213 // Note: boot loader append path does not support named modules.
214 static ClassPathEntry* volatile _first_append_entry_list;
215 static ClassPathEntry* first_append_entry() {
216 return AtomicAccess::load_acquire(&_first_append_entry_list);
217 }
218
219 // Last entry in linked list of appended ClassPathEntry instances
220 static ClassPathEntry* volatile _last_append_entry;
221
222 public:
223
224 static bool has_bootclasspath_append() { return first_append_entry() != nullptr; }
225
226 protected:
227 // Initialization:
316 static ClassFileStream* search_module_entries(JavaThread* current,
317 const GrowableArray<ModuleClassPathList*>* const module_list,
318 PackageEntry* pkg_entry, // Java package entry derived from the class name
319 const char* const file_name);
320
321 // Load individual .class file
322 static InstanceKlass* load_class(Symbol* class_name, PackageEntry* pkg_entry, bool search_append_only, TRAPS);
323
324 // If the specified package has been loaded by the system, then returns
325 // the name of the directory or ZIP file that the package was loaded from.
326 // Returns null if the package was not loaded.
327 // Note: The specified name can either be the name of a class or package.
328 // If a package name is specified, then it must be "/"-separator and also
329 // end with a trailing "/".
330 static oop get_system_package(const char* name, TRAPS);
331
332 // Returns an array of Java strings representing all of the currently
333 // loaded system packages.
334 // Note: The package names returned are "/"-separated and end with a
335 // trailing "/".
336 static objArrayOop get_system_packages(TRAPS);
337
338 // Initialization
339 static void initialize(TRAPS);
340 static void classLoader_init2(JavaThread* current);
341
342 static int compute_Object_vtable();
343
344 static ClassPathEntry* classpath_entry(int n);
345
346 static bool is_in_patch_mod_entries(Symbol* module_name);
347
348 #if INCLUDE_CDS
349 static char* uri_to_path(const char* uri);
350 static void record_result(JavaThread* current, InstanceKlass* ik,
351 const ClassFileStream* stream, bool redefined);
352 static void record_result_for_builtin_loader(s2 classpath_index, InstanceKlass* result, bool redefined);
353 static void record_hidden_class(InstanceKlass* ik);
354 static void append_boot_classpath(ClassPathEntry* new_entry);
355 #endif
356
357 static char* lookup_vm_options();
358
359 // Determines if the named module is present in the
360 // modules jimage file or in the exploded modules directory.
361 static bool is_module_observable(const char* module_name);
362
363 static JImageLocationRef jimage_find_resource(JImageFile* jf, const char* module_name,
364 const char* file_name, jlong &size);
365
366 static void trace_class_path(const char* msg, const char* name = nullptr);
367
368 // VM monitoring and management support
369 static jlong classloader_time_ms();
370 static jlong class_method_total_size();
371 static jlong class_init_count();
372 static jlong class_init_time_ms();
373 static jlong class_verify_time_ms();
374 static jlong class_link_count();
375 static jlong class_link_time_ms();
376
377 // adds a class path to the boot append entries
378 static void add_to_boot_append_entries(ClassPathEntry* new_entry);
379
380 // creates a class path zip entry (returns null if JAR file cannot be opened)
381 static ClassPathZipEntry* create_class_path_zip_entry(const char *path);
382
383 static bool string_ends_with(const char* str, const char* str_to_find);
384
385 // Extract package name from a fully qualified class name
|
1 /*
2 * Copyright (c) 1997, 2026, 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 *
82 }
83 virtual ~ClassPathDirEntry();
84 ClassFileStream* open_stream(JavaThread* current, const char* name);
85 };
86
87 class ClassPathZipEntry: public ClassPathEntry {
88 private:
89 jzfile* _zip; // The zip archive
90 const char* _zip_name; // Name of zip archive
91 public:
92 bool is_jar_file() const { return true; }
93 const char* name() const { return _zip_name; }
94 ClassPathZipEntry(jzfile* zip, const char* zip_name);
95 virtual ~ClassPathZipEntry();
96 bool has_entry(JavaThread* current, const char* name);
97 u1* open_entry(JavaThread* current, const char* name, jint* filesize, bool nul_terminate);
98 ClassFileStream* open_stream(JavaThread* current, const char* name);
99 };
100
101
102 // A singleton path entry which takes ownership of the initialized JImageFile
103 // reference. Not used for exploded builds.
104 class ClassPathImageEntry: public ClassPathEntry {
105 private:
106 const char* _name;
107 DEBUG_ONLY(static ClassPathImageEntry* _singleton;)
108 public:
109 bool is_modules_image() const;
110 const char* name() const { return _name == nullptr ? "" : _name; }
111 // Called to close the JImage during os::abort (normally not called).
112 void close_jimage();
113 // Takes effective ownership of the static JImageFile pointer.
114 ClassPathImageEntry(const char* name);
115 virtual ~ClassPathImageEntry() { ShouldNotReachHere(); }
116
117 ClassFileStream* open_stream(JavaThread* current, const char* name);
118 ClassFileStream* open_stream_for_loader(JavaThread* current, const char* name, ClassLoaderData* loader_data);
119 };
120
121 // ModuleClassPathList contains a linked list of ClassPathEntry's
122 // that have been specified for a specific module. Currently,
123 // the only way to specify a module/path pair is via the --patch-module
124 // command line option.
125 class ModuleClassPathList : public CHeapObj<mtClass> {
126 private:
127 Symbol* _module_name;
128 // First and last entries of class path entries for a specific module
129 ClassPathEntry* _module_first_entry;
130 ClassPathEntry* _module_last_entry;
131 public:
132 Symbol* module_name() const { return _module_name; }
133 ClassPathEntry* module_first_entry() const { return _module_first_entry; }
134 ModuleClassPathList(Symbol* module_name);
135 ~ModuleClassPathList();
136 void add_to_list(ClassPathEntry* new_entry);
186
187 // Count the time taken to hash the scondary superclass arrays.
188 static PerfCounter* _perf_secondary_hash_time;
189 static PerfCounter* _perf_change_wx_time;
190
191 // The boot class path consists of 3 ordered pieces:
192 // 1. the module/path pairs specified to --patch-module
193 // --patch-module=<module>=<file>(<pathsep><file>)*
194 // 2. the base piece
195 // [jimage | build with exploded modules]
196 // 3. boot loader append path
197 // [-Xbootclasspath/a]; [jvmti appended entries]
198 //
199 // The boot loader must obey this order when attempting
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 ClassPathImageEntry 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 ClassPathImageEntry* _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* volatile _first_append_entry_list;
217 static ClassPathEntry* first_append_entry() {
218 return AtomicAccess::load_acquire(&_first_append_entry_list);
219 }
220
221 // Last entry in linked list of appended ClassPathEntry instances
222 static ClassPathEntry* volatile _last_append_entry;
223
224 public:
225
226 static bool has_bootclasspath_append() { return first_append_entry() != nullptr; }
227
228 protected:
229 // Initialization:
318 static ClassFileStream* search_module_entries(JavaThread* current,
319 const GrowableArray<ModuleClassPathList*>* const module_list,
320 PackageEntry* pkg_entry, // Java package entry derived from the class name
321 const char* const file_name);
322
323 // Load individual .class file
324 static InstanceKlass* load_class(Symbol* class_name, PackageEntry* pkg_entry, bool search_append_only, TRAPS);
325
326 // If the specified package has been loaded by the system, then returns
327 // the name of the directory or ZIP file that the package was loaded from.
328 // Returns null if the package was not loaded.
329 // Note: The specified name can either be the name of a class or package.
330 // If a package name is specified, then it must be "/"-separator and also
331 // end with a trailing "/".
332 static oop get_system_package(const char* name, TRAPS);
333
334 // Returns an array of Java strings representing all of the currently
335 // loaded system packages.
336 // Note: The package names returned are "/"-separated and end with a
337 // trailing "/".
338 static refArrayOop get_system_packages(TRAPS);
339
340 // Initialization
341 static void initialize(TRAPS);
342 static void classLoader_init2(JavaThread* current);
343
344 static int compute_Object_vtable();
345
346 static ClassPathEntry* classpath_entry(int n);
347
348 static bool is_in_patch_mod_entries(Symbol* module_name);
349
350 #if INCLUDE_CDS
351 static char* uri_to_path(const char* uri);
352 static void record_result(JavaThread* current, InstanceKlass* ik,
353 const ClassFileStream* stream, bool redefined);
354 static void record_result_for_builtin_loader(s2 classpath_index, InstanceKlass* result, bool redefined);
355 static void record_hidden_class(InstanceKlass* ik);
356 static void append_boot_classpath(ClassPathEntry* new_entry);
357 #endif
358
359 // Retrieves additional VM options prior to flags processing. Options held
360 // in the JImage file are retrieved without fully initializing it. (this is
361 // the only JImage lookup which can succeed before init_jimage() is called).
362 static char* lookup_vm_options();
363
364 // Called once, after all flags are processed, to finish initializing the
365 // JImage file. Until this is called, jimage_find_resource(), and any other
366 // JImage resource lookups or access will fail.
367 static void set_preview_mode(bool enable_preview);
368
369 // Determines if the named module is present in the
370 // modules jimage file or in the exploded modules directory.
371 static bool is_module_observable(const char* module_name);
372
373 static void trace_class_path(const char* msg, const char* name = nullptr);
374
375 // VM monitoring and management support
376 static jlong classloader_time_ms();
377 static jlong class_method_total_size();
378 static jlong class_init_count();
379 static jlong class_init_time_ms();
380 static jlong class_verify_time_ms();
381 static jlong class_link_count();
382 static jlong class_link_time_ms();
383
384 // adds a class path to the boot append entries
385 static void add_to_boot_append_entries(ClassPathEntry* new_entry);
386
387 // creates a class path zip entry (returns null if JAR file cannot be opened)
388 static ClassPathZipEntry* create_class_path_zip_entry(const char *path);
389
390 static bool string_ends_with(const char* str, const char* str_to_find);
391
392 // Extract package name from a fully qualified class name
|