Bug Summary

File:jdk/src/hotspot/share/classfile/classLoader.cpp
Warning:line 1571, column 32
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name classLoader.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/libjvm/objs/precompiled -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D _GNU_SOURCE -D _REENTRANT -D LIBC=gnu -D LINUX -D VM_LITTLE_ENDIAN -D _LP64=1 -D ASSERT -D CHECK_UNHANDLED_OOPS -D TARGET_ARCH_x86 -D INCLUDE_SUFFIX_OS=_linux -D INCLUDE_SUFFIX_CPU=_x86 -D INCLUDE_SUFFIX_COMPILER=_gcc -D TARGET_COMPILER_gcc -D AMD64 -D HOTSPOT_LIB_ARCH="amd64" -D COMPILER1 -D COMPILER2 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -I /home/daniel/Projects/java/jdk/src/hotspot/share/precompiled -I /home/daniel/Projects/java/jdk/src/hotspot/share/include -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix/include -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base/linux -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjimage -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -D _FORTIFY_SOURCE=2 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-format-zero-length -Wno-unused-parameter -Wno-unused -Wno-parentheses -Wno-comment -Wno-unknown-pragmas -Wno-address -Wno-delete-non-virtual-dtor -Wno-char-subscripts -Wno-array-bounds -Wno-int-in-bool-context -Wno-ignored-qualifiers -Wno-missing-field-initializers -Wno-implicit-fallthrough -Wno-empty-body -Wno-strict-overflow -Wno-sequence-point -Wno-maybe-uninitialized -Wno-misleading-indentation -Wno-cast-function-type -Wno-shift-negative-value -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make/hotspot -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -stack-protector 1 -fno-rtti -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c++ /home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp
1/*
2 * Copyright (c) 1997, 2021, 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 *
23 */
24
25#include "precompiled.hpp"
26#include "jvm.h"
27#include "jimage.hpp"
28#include "cds/filemap.hpp"
29#include "classfile/classFileStream.hpp"
30#include "classfile/classLoader.inline.hpp"
31#include "classfile/classLoaderData.inline.hpp"
32#include "classfile/classLoaderExt.hpp"
33#include "classfile/classLoadInfo.hpp"
34#include "classfile/javaClasses.hpp"
35#include "classfile/moduleEntry.hpp"
36#include "classfile/modules.hpp"
37#include "classfile/packageEntry.hpp"
38#include "classfile/klassFactory.hpp"
39#include "classfile/symbolTable.hpp"
40#include "classfile/systemDictionary.hpp"
41#include "classfile/systemDictionaryShared.hpp"
42#include "classfile/vmClasses.hpp"
43#include "classfile/vmSymbols.hpp"
44#include "compiler/compileBroker.hpp"
45#include "interpreter/bytecodeStream.hpp"
46#include "interpreter/oopMapCache.hpp"
47#include "logging/log.hpp"
48#include "logging/logStream.hpp"
49#include "logging/logTag.hpp"
50#include "memory/allocation.inline.hpp"
51#include "memory/oopFactory.hpp"
52#include "memory/resourceArea.hpp"
53#include "memory/universe.hpp"
54#include "oops/instanceKlass.hpp"
55#include "oops/instanceRefKlass.hpp"
56#include "oops/klass.inline.hpp"
57#include "oops/method.inline.hpp"
58#include "oops/objArrayOop.inline.hpp"
59#include "oops/oop.inline.hpp"
60#include "oops/symbol.hpp"
61#include "prims/jvm_misc.hpp"
62#include "runtime/arguments.hpp"
63#include "runtime/handles.inline.hpp"
64#include "runtime/init.hpp"
65#include "runtime/interfaceSupport.inline.hpp"
66#include "runtime/java.hpp"
67#include "runtime/javaCalls.hpp"
68#include "runtime/os.hpp"
69#include "runtime/perfData.hpp"
70#include "runtime/threadCritical.hpp"
71#include "runtime/timer.hpp"
72#include "runtime/vm_version.hpp"
73#include "services/management.hpp"
74#include "services/threadService.hpp"
75#include "utilities/classpathStream.hpp"
76#include "utilities/events.hpp"
77#include "utilities/hashtable.inline.hpp"
78#include "utilities/macros.hpp"
79#include "utilities/utf8.hpp"
80
81// Entry point in java.dll for path canonicalization
82
83typedef int (*canonicalize_fn_t)(const char *orig, char *out, int len);
84
85static canonicalize_fn_t CanonicalizeEntry = NULL__null;
86
87// Entry points in zip.dll for loading zip/jar file entries
88
89typedef void * * (*ZipOpen_t)(const char *name, char **pmsg);
90typedef void (*ZipClose_t)(jzfile *zip);
91typedef jzentry* (*FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen);
92typedef jboolean (*ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf);
93typedef jzentry* (*GetNextEntry_t)(jzfile *zip, jint n);
94typedef jint (*Crc32_t)(jint crc, const jbyte *buf, jint len);
95
96static ZipOpen_t ZipOpen = NULL__null;
97static ZipClose_t ZipClose = NULL__null;
98static FindEntry_t FindEntry = NULL__null;
99static ReadEntry_t ReadEntry = NULL__null;
100static GetNextEntry_t GetNextEntry = NULL__null;
101static Crc32_t Crc32 = NULL__null;
102int ClassLoader::_libzip_loaded = 0;
103
104// Entry points for jimage.dll for loading jimage file entries
105
106static JImageOpen_t JImageOpen = NULL__null;
107static JImageClose_t JImageClose = NULL__null;
108static JImageFindResource_t JImageFindResource = NULL__null;
109static JImageGetResource_t JImageGetResource = NULL__null;
110
111// JimageFile pointer, or null if exploded JDK build.
112static JImageFile* JImage_file = NULL__null;
113
114// Globals
115
116PerfCounter* ClassLoader::_perf_accumulated_time = NULL__null;
117PerfCounter* ClassLoader::_perf_classes_inited = NULL__null;
118PerfCounter* ClassLoader::_perf_class_init_time = NULL__null;
119PerfCounter* ClassLoader::_perf_class_init_selftime = NULL__null;
120PerfCounter* ClassLoader::_perf_classes_verified = NULL__null;
121PerfCounter* ClassLoader::_perf_class_verify_time = NULL__null;
122PerfCounter* ClassLoader::_perf_class_verify_selftime = NULL__null;
123PerfCounter* ClassLoader::_perf_classes_linked = NULL__null;
124PerfCounter* ClassLoader::_perf_class_link_time = NULL__null;
125PerfCounter* ClassLoader::_perf_class_link_selftime = NULL__null;
126PerfCounter* ClassLoader::_perf_sys_class_lookup_time = NULL__null;
127PerfCounter* ClassLoader::_perf_shared_classload_time = NULL__null;
128PerfCounter* ClassLoader::_perf_sys_classload_time = NULL__null;
129PerfCounter* ClassLoader::_perf_app_classload_time = NULL__null;
130PerfCounter* ClassLoader::_perf_app_classload_selftime = NULL__null;
131PerfCounter* ClassLoader::_perf_app_classload_count = NULL__null;
132PerfCounter* ClassLoader::_perf_define_appclasses = NULL__null;
133PerfCounter* ClassLoader::_perf_define_appclass_time = NULL__null;
134PerfCounter* ClassLoader::_perf_define_appclass_selftime = NULL__null;
135PerfCounter* ClassLoader::_perf_app_classfile_bytes_read = NULL__null;
136PerfCounter* ClassLoader::_perf_sys_classfile_bytes_read = NULL__null;
137PerfCounter* ClassLoader::_unsafe_defineClassCallCounter = NULL__null;
138
139GrowableArray<ModuleClassPathList*>* ClassLoader::_patch_mod_entries = NULL__null;
140GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = NULL__null;
141ClassPathEntry* ClassLoader::_jrt_entry = NULL__null;
142
143ClassPathEntry* volatile ClassLoader::_first_append_entry_list = NULL__null;
144ClassPathEntry* volatile ClassLoader::_last_append_entry = NULL__null;
145#if INCLUDE_CDS1
146ClassPathEntry* ClassLoader::_app_classpath_entries = NULL__null;
147ClassPathEntry* ClassLoader::_last_app_classpath_entry = NULL__null;
148ClassPathEntry* ClassLoader::_module_path_entries = NULL__null;
149ClassPathEntry* ClassLoader::_last_module_path_entry = NULL__null;
150#endif
151
152// helper routines
153bool string_starts_with(const char* str, const char* str_to_find) {
154 size_t str_len = strlen(str);
155 size_t str_to_find_len = strlen(str_to_find);
156 if (str_to_find_len > str_len) {
157 return false;
158 }
159 return (strncmp(str, str_to_find, str_to_find_len) == 0);
160}
161
162static const char* get_jimage_version_string() {
163 static char version_string[10] = "";
164 if (version_string[0] == '\0') {
165 jio_snprintf(version_string, sizeof(version_string), "%d.%d",
166 VM_Version::vm_major_version(), VM_Version::vm_minor_version());
167 }
168 return (const char*)version_string;
169}
170
171bool ClassLoader::string_ends_with(const char* str, const char* str_to_find) {
172 size_t str_len = strlen(str);
173 size_t str_to_find_len = strlen(str_to_find);
174 if (str_to_find_len > str_len) {
175 return false;
176 }
177 return (strncmp(str + (str_len - str_to_find_len), str_to_find, str_to_find_len) == 0);
178}
179
180// Used to obtain the package name from a fully qualified class name.
181Symbol* ClassLoader::package_from_class_name(const Symbol* name, bool* bad_class_name) {
182 if (name == NULL__null) {
183 if (bad_class_name != NULL__null) {
184 *bad_class_name = true;
185 }
186 return NULL__null;
187 }
188
189 int utf_len = name->utf8_length();
190 const jbyte* base = (const jbyte*)name->base();
191 const jbyte* start = base;
192 const jbyte* end = UTF8::strrchr(start, utf_len, JVM_SIGNATURE_SLASH);
193 if (end == NULL__null) {
194 return NULL__null;
195 }
196 // Skip over '['s
197 if (*start == JVM_SIGNATURE_ARRAY) {
198 do {
199 start++;
200 } while (start < end && *start == JVM_SIGNATURE_ARRAY);
201
202 // Fully qualified class names should not contain a 'L'.
203 // Set bad_class_name to true to indicate that the package name
204 // could not be obtained due to an error condition.
205 // In this situation, is_same_class_package returns false.
206 if (*start == JVM_SIGNATURE_CLASS) {
207 if (bad_class_name != NULL__null) {
208 *bad_class_name = true;
209 }
210 return NULL__null;
211 }
212 }
213 // A class name could have just the slash character in the name,
214 // in which case start > end
215 if (start >= end) {
216 // No package name
217 if (bad_class_name != NULL__null) {
218 *bad_class_name = true;
219 }
220 return NULL__null;
221 }
222 return SymbolTable::new_symbol(name, start - base, end - base);
223}
224
225// Given a fully qualified package name, find its defining package in the class loader's
226// package entry table.
227PackageEntry* ClassLoader::get_package_entry(Symbol* pkg_name, ClassLoaderData* loader_data) {
228 if (pkg_name == NULL__null) {
229 return NULL__null;
230 }
231 PackageEntryTable* pkgEntryTable = loader_data->packages();
232 return pkgEntryTable->lookup_only(pkg_name);
233}
234
235const char* ClassPathEntry::copy_path(const char* path) {
236 char* copy = NEW_C_HEAP_ARRAY(char, strlen(path)+1, mtClass)(char*) (AllocateHeap((strlen(path)+1) * sizeof(char), mtClass
))
;
237 strcpy(copy, path);
238 return copy;
239}
240
241ClassFileStream* ClassPathDirEntry::open_stream(JavaThread* current, const char* name) {
242 // construct full path name
243 assert((_dir != NULL) && (name != NULL), "sanity")do { if (!((_dir != __null) && (name != __null))) { (
*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 243, "assert(" "(_dir != __null) && (name != __null)"
") failed", "sanity"); ::breakpoint(); } } while (0)
;
244 size_t path_len = strlen(_dir) + strlen(name) + strlen(os::file_separator()) + 1;
245 char* path = NEW_RESOURCE_ARRAY_IN_THREAD(current, char, path_len)(char*) resource_allocate_bytes(current, (path_len) * sizeof(
char))
;
246 int len = jio_snprintf(path, path_len, "%s%s%s", _dir, os::file_separator(), name);
247 assert(len == (int)(path_len - 1), "sanity")do { if (!(len == (int)(path_len - 1))) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 247, "assert(" "len == (int)(path_len - 1)" ") failed", "sanity"
); ::breakpoint(); } } while (0)
;
248 // check if file exists
249 struct stat st;
250 if (os::stat(path, &st) == 0) {
251 // found file, open it
252 int file_handle = os::open(path, 0, 0);
253 if (file_handle != -1) {
254 // read contents into resource array
255 u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size)(u1*) resource_allocate_bytes((st.st_size) * sizeof(u1));
256 size_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
257 // close file
258 os::close(file_handle);
259 // construct ClassFileStream
260 if (num_read == (size_t)st.st_size) {
261 if (UsePerfData) {
262 ClassLoader::perf_sys_classfile_bytes_read()->inc(num_read);
263 }
264 FREE_RESOURCE_ARRAY(char, path, path_len)resource_free_bytes((char*)(path), (path_len) * sizeof(char));
265 // Resource allocated
266 return new ClassFileStream(buffer,
267 st.st_size,
268 _dir,
269 ClassFileStream::verify);
270 }
271 }
272 }
273 FREE_RESOURCE_ARRAY(char, path, path_len)resource_free_bytes((char*)(path), (path_len) * sizeof(char));
274 return NULL__null;
275}
276
277ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name,
278 bool is_boot_append, bool from_class_path_attr) : ClassPathEntry() {
279 _zip = zip;
280 _zip_name = copy_path(zip_name);
281 _from_class_path_attr = from_class_path_attr;
282}
283
284ClassPathZipEntry::~ClassPathZipEntry() {
285 (*ZipClose)(_zip);
286 FREE_C_HEAP_ARRAY(char, _zip_name)FreeHeap((char*)(_zip_name));
287}
288
289u1* ClassPathZipEntry::open_entry(JavaThread* current, const char* name, jint* filesize, bool nul_terminate) {
290 // enable call to C land
291 ThreadToNativeFromVM ttn(current);
292 // check whether zip archive contains name
293 jint name_len;
294 jzentry* entry = (*FindEntry)(_zip, name, filesize, &name_len);
295 if (entry == NULL__null) return NULL__null;
296 u1* buffer;
297 char name_buf[128];
298 char* filename;
299 if (name_len < 128) {
300 filename = name_buf;
301 } else {
302 filename = NEW_RESOURCE_ARRAY(char, name_len + 1)(char*) resource_allocate_bytes((name_len + 1) * sizeof(char)
)
;
303 }
304
305 // read contents into resource array
306 int size = (*filesize) + ((nul_terminate) ? 1 : 0);
307 buffer = NEW_RESOURCE_ARRAY(u1, size)(u1*) resource_allocate_bytes((size) * sizeof(u1));
308 if (!(*ReadEntry)(_zip, entry, buffer, filename)) return NULL__null;
309
310 // return result
311 if (nul_terminate) {
312 buffer[*filesize] = 0;
313 }
314 return buffer;
315}
316
317ClassFileStream* ClassPathZipEntry::open_stream(JavaThread* current, const char* name) {
318 jint filesize;
319 u1* buffer = open_entry(current, name, &filesize, false);
320 if (buffer == NULL__null) {
321 return NULL__null;
322 }
323 if (UsePerfData) {
324 ClassLoader::perf_sys_classfile_bytes_read()->inc(filesize);
325 }
326 // Resource allocated
327 return new ClassFileStream(buffer,
328 filesize,
329 _zip_name,
330 ClassFileStream::verify);
331}
332
333// invoke function for each entry in the zip file
334void ClassPathZipEntry::contents_do(void f(const char* name, void* context), void* context) {
335 JavaThread* thread = JavaThread::current();
336 HandleMark handle_mark(thread);
337 ThreadToNativeFromVM ttn(thread);
338 for (int n = 0; ; n++) {
339 jzentry * ze = ((*GetNextEntry)(_zip, n));
340 if (ze == NULL__null) break;
341 (*f)(ze->name, context);
342 }
343}
344
345DEBUG_ONLY(ClassPathImageEntry* ClassPathImageEntry::_singleton = NULL;)ClassPathImageEntry* ClassPathImageEntry::_singleton = __null
;
346
347JImageFile* ClassPathImageEntry::jimage() const {
348 return JImage_file;
349}
350
351JImageFile* ClassPathImageEntry::jimage_non_null() const {
352 assert(ClassLoader::has_jrt_entry(), "must be")do { if (!(ClassLoader::has_jrt_entry())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 352, "assert(" "ClassLoader::has_jrt_entry()" ") failed", "must be"
); ::breakpoint(); } } while (0)
;
353 assert(jimage() != NULL, "should have been opened by ClassLoader::lookup_vm_options "do { if (!(jimage() != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 354, "assert(" "jimage() != __null" ") failed", "should have been opened by ClassLoader::lookup_vm_options "
"and remained throughout normal JVM lifetime"); ::breakpoint
(); } } while (0)
354 "and remained throughout normal JVM lifetime")do { if (!(jimage() != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 354, "assert(" "jimage() != __null" ") failed", "should have been opened by ClassLoader::lookup_vm_options "
"and remained throughout normal JVM lifetime"); ::breakpoint
(); } } while (0)
;
355 return jimage();
356}
357
358void ClassPathImageEntry::close_jimage() {
359 if (jimage() != NULL__null) {
360 (*JImageClose)(jimage());
361 JImage_file = NULL__null;
362 }
363}
364
365ClassPathImageEntry::ClassPathImageEntry(JImageFile* jimage, const char* name) :
366 ClassPathEntry() {
367 guarantee(jimage != NULL, "jimage file is null")do { if (!(jimage != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 367, "guarantee(" "jimage != NULL" ") failed", "jimage file is null"
); ::breakpoint(); } } while (0)
;
368 guarantee(name != NULL, "jimage file name is null")do { if (!(name != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 368, "guarantee(" "name != NULL" ") failed", "jimage file name is null"
); ::breakpoint(); } } while (0)
;
369 assert(_singleton == NULL, "VM supports only one jimage")do { if (!(_singleton == __null)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 369, "assert(" "_singleton == __null" ") failed", "VM supports only one jimage"
); ::breakpoint(); } } while (0)
;
370 DEBUG_ONLY(_singleton = this)_singleton = this;
371 size_t len = strlen(name) + 1;
372 _name = copy_path(name);
373}
374
375ClassFileStream* ClassPathImageEntry::open_stream(JavaThread* current, const char* name) {
376 return open_stream_for_loader(current, name, ClassLoaderData::the_null_class_loader_data());
377}
378
379// For a class in a named module, look it up in the jimage file using this syntax:
380// /<module-name>/<package-name>/<base-class>
381//
382// Assumptions:
383// 1. There are no unnamed modules in the jimage file.
384// 2. A package is in at most one module in the jimage file.
385//
386ClassFileStream* ClassPathImageEntry::open_stream_for_loader(JavaThread* current, const char* name, ClassLoaderData* loader_data) {
387 jlong size;
388 JImageLocationRef location = (*JImageFindResource)(jimage_non_null(), "", get_jimage_version_string(), name, &size);
389
390 if (location == 0) {
391 TempNewSymbol class_name = SymbolTable::new_symbol(name);
392 TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name);
393
394 if (pkg_name != NULL__null) {
395 if (!Universe::is_module_initialized()) {
396 location = (*JImageFindResource)(jimage_non_null(), JAVA_BASE_NAME"java.base", get_jimage_version_string(), name, &size);
397 } else {
398 PackageEntry* package_entry = ClassLoader::get_package_entry(pkg_name, loader_data);
399 if (package_entry != NULL__null) {
400 ResourceMark rm(current);
401 // Get the module name
402 ModuleEntry* module = package_entry->module();
403 assert(module != NULL, "Boot classLoader package missing module")do { if (!(module != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 403, "assert(" "module != __null" ") failed", "Boot classLoader package missing module"
); ::breakpoint(); } } while (0)
;
404 assert(module->is_named(), "Boot classLoader package is in unnamed module")do { if (!(module->is_named())) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 404, "assert(" "module->is_named()" ") failed", "Boot classLoader package is in unnamed module"
); ::breakpoint(); } } while (0)
;
405 const char* module_name = module->name()->as_C_string();
406 if (module_name != NULL__null) {
407 location = (*JImageFindResource)(jimage_non_null(), module_name, get_jimage_version_string(), name, &size);
408 }
409 }
410 }
411 }
412 }
413 if (location != 0) {
414 if (UsePerfData) {
415 ClassLoader::perf_sys_classfile_bytes_read()->inc(size);
416 }
417 char* data = NEW_RESOURCE_ARRAY(char, size)(char*) resource_allocate_bytes((size) * sizeof(char));
418 (*JImageGetResource)(jimage_non_null(), location, data, size);
419 // Resource allocated
420 assert(this == (ClassPathImageEntry*)ClassLoader::get_jrt_entry(), "must be")do { if (!(this == (ClassPathImageEntry*)ClassLoader::get_jrt_entry
())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 420, "assert(" "this == (ClassPathImageEntry*)ClassLoader::get_jrt_entry()"
") failed", "must be"); ::breakpoint(); } } while (0)
;
421 return new ClassFileStream((u1*)data,
422 (int)size,
423 _name,
424 ClassFileStream::verify,
425 true); // from_boot_loader_modules_image
426 }
427
428 return NULL__null;
429}
430
431JImageLocationRef ClassLoader::jimage_find_resource(JImageFile* jf,
432 const char* module_name,
433 const char* file_name,
434 jlong &size) {
435 return ((*JImageFindResource)(jf, module_name, get_jimage_version_string(), file_name, &size));
436}
437
438bool ClassPathImageEntry::is_modules_image() const {
439 assert(this == _singleton, "VM supports a single jimage")do { if (!(this == _singleton)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 439, "assert(" "this == _singleton" ") failed", "VM supports a single jimage"
); ::breakpoint(); } } while (0)
;
440 assert(this == (ClassPathImageEntry*)ClassLoader::get_jrt_entry(), "must be used for jrt entry")do { if (!(this == (ClassPathImageEntry*)ClassLoader::get_jrt_entry
())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 440, "assert(" "this == (ClassPathImageEntry*)ClassLoader::get_jrt_entry()"
") failed", "must be used for jrt entry"); ::breakpoint(); }
} while (0)
;
441 return true;
442}
443
444#if INCLUDE_CDS1
445void ClassLoader::exit_with_path_failure(const char* error, const char* message) {
446 Arguments::assert_is_dumping_archive();
447 tty->print_cr("Hint: enable -Xlog:class+path=info to diagnose the failure");
448 vm_exit_during_initialization(error, message);
449}
450#endif
451
452ModuleClassPathList::ModuleClassPathList(Symbol* module_name) {
453 _module_name = module_name;
454 _module_first_entry = NULL__null;
455 _module_last_entry = NULL__null;
456}
457
458ModuleClassPathList::~ModuleClassPathList() {
459 // Clean out each ClassPathEntry on list
460 ClassPathEntry* e = _module_first_entry;
461 while (e != NULL__null) {
462 ClassPathEntry* next_entry = e->next();
463 delete e;
464 e = next_entry;
465 }
466}
467
468void ModuleClassPathList::add_to_list(ClassPathEntry* new_entry) {
469 if (new_entry != NULL__null) {
470 if (_module_last_entry == NULL__null) {
471 _module_first_entry = _module_last_entry = new_entry;
472 } else {
473 _module_last_entry->set_next(new_entry);
474 _module_last_entry = new_entry;
475 }
476 }
477}
478
479void ClassLoader::trace_class_path(const char* msg, const char* name) {
480 LogTarget(Info, class, path)LogTargetImpl<LogLevel::Info, (LogTag::_class), (LogTag::_path
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
, (LogTag::__NO_TAG)>
lt;
481 if (lt.is_enabled()) {
482 LogStream ls(lt);
483 if (msg) {
484 ls.print("%s", msg);
485 }
486 if (name) {
487 if (strlen(name) < 256) {
488 ls.print("%s", name);
489 } else {
490 // For very long paths, we need to print each character separately,
491 // as print_cr() has a length limit
492 while (name[0] != '\0') {
493 ls.print("%c", name[0]);
494 name++;
495 }
496 }
497 }
498 ls.cr();
499 }
500}
501
502void ClassLoader::setup_bootstrap_search_path(JavaThread* current) {
503 const char* sys_class_path = Arguments::get_sysclasspath();
504 assert(sys_class_path != NULL, "System boot class path must not be NULL")do { if (!(sys_class_path != __null)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 504, "assert(" "sys_class_path != __null" ") failed", "System boot class path must not be NULL"
); ::breakpoint(); } } while (0)
;
505 if (PrintSharedArchiveAndExit) {
506 // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
507 // the same as the bootcp of the shared archive.
508 } else {
509 trace_class_path("bootstrap loader class path=", sys_class_path);
510 }
511 setup_bootstrap_search_path_impl(current, sys_class_path);
512}
513
514#if INCLUDE_CDS1
515void ClassLoader::setup_app_search_path(JavaThread* current, const char *class_path) {
516 Arguments::assert_is_dumping_archive();
517
518 ResourceMark rm(current);
519 ClasspathStream cp_stream(class_path);
520
521 while (cp_stream.has_next()) {
522 const char* path = cp_stream.get_next();
523 update_class_path_entry_list(current, path, false, false, false);
524 }
525}
526
527void ClassLoader::add_to_module_path_entries(const char* path,
528 ClassPathEntry* entry) {
529 assert(entry != NULL, "ClassPathEntry should not be NULL")do { if (!(entry != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 529, "assert(" "entry != __null" ") failed", "ClassPathEntry should not be NULL"
); ::breakpoint(); } } while (0)
;
530 Arguments::assert_is_dumping_archive();
531
532 // The entry does not exist, add to the list
533 if (_module_path_entries == NULL__null) {
534 assert(_last_module_path_entry == NULL, "Sanity")do { if (!(_last_module_path_entry == __null)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 534, "assert(" "_last_module_path_entry == __null" ") failed"
, "Sanity"); ::breakpoint(); } } while (0)
;
535 _module_path_entries = _last_module_path_entry = entry;
536 } else {
537 _last_module_path_entry->set_next(entry);
538 _last_module_path_entry = entry;
539 }
540}
541
542// Add a module path to the _module_path_entries list.
543void ClassLoader::setup_module_search_path(JavaThread* current, const char* path) {
544 Arguments::assert_is_dumping_archive();
545 struct stat st;
546 if (os::stat(path, &st) != 0) {
547 tty->print_cr("os::stat error %d (%s). CDS dump aborted (path was \"%s\").",
548 errno(*__errno_location ()), os::errno_name(errno(*__errno_location ())), path);
549 vm_exit_during_initialization();
550 }
551 // File or directory found
552 ClassPathEntry* new_entry = NULL__null;
553 new_entry = create_class_path_entry(current, path, &st,
554 false /*is_boot_append */, false /* from_class_path_attr */);
555 if (new_entry != NULL__null) {
556 add_to_module_path_entries(path, new_entry);
557 }
558}
559
560#endif // INCLUDE_CDS
561
562void ClassLoader::close_jrt_image() {
563 // Not applicable for exploded builds
564 if (!ClassLoader::has_jrt_entry()) return;
565 _jrt_entry->close_jimage();
566}
567
568// Construct the array of module/path pairs as specified to --patch-module
569// for the boot loader to search ahead of the jimage, if the class being
570// loaded is defined to a module that has been specified to --patch-module.
571void ClassLoader::setup_patch_mod_entries() {
572 JavaThread* current = JavaThread::current();
573 GrowableArray<ModulePatchPath*>* patch_mod_args = Arguments::get_patch_mod_prefix();
574 int num_of_entries = patch_mod_args->length();
575
576 // Set up the boot loader's _patch_mod_entries list
577 _patch_mod_entries = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleClassPathList*>(num_of_entries, mtModule);
578
579 for (int i = 0; i < num_of_entries; i++) {
580 const char* module_name = (patch_mod_args->at(i))->module_name();
581 Symbol* const module_sym = SymbolTable::new_symbol(module_name);
582 assert(module_sym != NULL, "Failed to obtain Symbol for module name")do { if (!(module_sym != __null)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 582, "assert(" "module_sym != __null" ") failed", "Failed to obtain Symbol for module name"
); ::breakpoint(); } } while (0)
;
583 ModuleClassPathList* module_cpl = new ModuleClassPathList(module_sym);
584
585 char* class_path = (patch_mod_args->at(i))->path_string();
586 ResourceMark rm(current);
587 ClasspathStream cp_stream(class_path);
588
589 while (cp_stream.has_next()) {
590 const char* path = cp_stream.get_next();
591 struct stat st;
592 if (os::stat(path, &st) == 0) {
593 // File or directory found
594 ClassPathEntry* new_entry = create_class_path_entry(current, path, &st, false, false);
595 // If the path specification is valid, enter it into this module's list
596 if (new_entry != NULL__null) {
597 module_cpl->add_to_list(new_entry);
598 }
599 }
600 }
601
602 // Record the module into the list of --patch-module entries only if
603 // valid ClassPathEntrys have been created
604 if (module_cpl->module_first_entry() != NULL__null) {
605 _patch_mod_entries->push(module_cpl);
606 }
607 }
608}
609
610// Determine whether the module has been patched via the command-line
611// option --patch-module
612bool ClassLoader::is_in_patch_mod_entries(Symbol* module_name) {
613 if (_patch_mod_entries != NULL__null && _patch_mod_entries->is_nonempty()) {
614 int table_len = _patch_mod_entries->length();
615 for (int i = 0; i < table_len; i++) {
616 ModuleClassPathList* patch_mod = _patch_mod_entries->at(i);
617 if (module_name->fast_compare(patch_mod->module_name()) == 0) {
618 return true;
619 }
620 }
621 }
622 return false;
623}
624
625// Set up the _jrt_entry if present and boot append path
626void ClassLoader::setup_bootstrap_search_path_impl(JavaThread* current, const char *class_path) {
627 ResourceMark rm(current);
628 ClasspathStream cp_stream(class_path);
629 bool set_base_piece = true;
630
631#if INCLUDE_CDS1
632 if (Arguments::is_dumping_archive()) {
633 if (!Arguments::has_jimage()) {
634 vm_exit_during_initialization("CDS is not supported in exploded JDK build", NULL__null);
635 }
636 }
637#endif
638
639 while (cp_stream.has_next()) {
640 const char* path = cp_stream.get_next();
641
642 if (set_base_piece) {
643 // The first time through the bootstrap_search setup, it must be determined
644 // what the base or core piece of the boot loader search is. Either a java runtime
645 // image is present or this is an exploded module build situation.
646 assert(string_ends_with(path, MODULES_IMAGE_NAME) || string_ends_with(path, JAVA_BASE_NAME),do { if (!(string_ends_with(path, "modules") || string_ends_with
(path, "java.base"))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 647, "assert(" "string_ends_with(path, \"modules\") || string_ends_with(path, \"java.base\")"
") failed", "Incorrect boot loader search path, no java runtime image or "
"java.base" " exploded build"); ::breakpoint(); } } while (0
)
647 "Incorrect boot loader search path, no java runtime image or " JAVA_BASE_NAME " exploded build")do { if (!(string_ends_with(path, "modules") || string_ends_with
(path, "java.base"))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 647, "assert(" "string_ends_with(path, \"modules\") || string_ends_with(path, \"java.base\")"
") failed", "Incorrect boot loader search path, no java runtime image or "
"java.base" " exploded build"); ::breakpoint(); } } while (0
)
;
648 struct stat st;
649 if (os::stat(path, &st) == 0) {
650 // Directory found
651 if (JImage_file != NULL__null) {
652 assert(Arguments::has_jimage(), "sanity check")do { if (!(Arguments::has_jimage())) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 652, "assert(" "Arguments::has_jimage()" ") failed", "sanity check"
); ::breakpoint(); } } while (0)
;
653 const char* canonical_path = get_canonical_path(path, current);
654 assert(canonical_path != NULL, "canonical_path issue")do { if (!(canonical_path != __null)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 654, "assert(" "canonical_path != __null" ") failed", "canonical_path issue"
); ::breakpoint(); } } while (0)
;
655
656 _jrt_entry = new ClassPathImageEntry(JImage_file, canonical_path);
657 assert(_jrt_entry != NULL && _jrt_entry->is_modules_image(), "No java runtime image present")do { if (!(_jrt_entry != __null && _jrt_entry->is_modules_image
())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 657, "assert(" "_jrt_entry != __null && _jrt_entry->is_modules_image()"
") failed", "No java runtime image present"); ::breakpoint()
; } } while (0)
;
658 assert(_jrt_entry->jimage() != NULL, "No java runtime image")do { if (!(_jrt_entry->jimage() != __null)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 658, "assert(" "_jrt_entry->jimage() != __null" ") failed"
, "No java runtime image"); ::breakpoint(); } } while (0)
;
659 } else {
660 // It's an exploded build.
661 ClassPathEntry* new_entry = create_class_path_entry(current, path, &st, false, false);
662 }
663 } else {
664 // If path does not exist, exit
665 vm_exit_during_initialization("Unable to establish the boot loader search path", path);
666 }
667 set_base_piece = false;
668 } else {
669 // Every entry on the system boot class path after the initial base piece,
670 // which is set by os::set_boot_path(), is considered an appended entry.
671 update_class_path_entry_list(current, path, false, true, false);
672 }
673 }
674}
675
676// During an exploded modules build, each module defined to the boot loader
677// will be added to the ClassLoader::_exploded_entries array.
678void ClassLoader::add_to_exploded_build_list(JavaThread* current, Symbol* module_sym) {
679 assert(!ClassLoader::has_jrt_entry(), "Exploded build not applicable")do { if (!(!ClassLoader::has_jrt_entry())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 679, "assert(" "!ClassLoader::has_jrt_entry()" ") failed", "Exploded build not applicable"
); ::breakpoint(); } } while (0)
;
680 assert(_exploded_entries != NULL, "_exploded_entries was not initialized")do { if (!(_exploded_entries != __null)) { (*g_assert_poison)
= 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 680, "assert(" "_exploded_entries != __null" ") failed", "_exploded_entries was not initialized"
); ::breakpoint(); } } while (0)
;
681
682 // Find the module's symbol
683 ResourceMark rm(current);
684 const char *module_name = module_sym->as_C_string();
685 const char *home = Arguments::get_java_home();
686 const char file_sep = os::file_separator()[0];
687 // 10 represents the length of "modules" + 2 file separators + \0
688 size_t len = strlen(home) + strlen(module_name) + 10;
689 char *path = NEW_RESOURCE_ARRAY(char, len)(char*) resource_allocate_bytes((len) * sizeof(char));
690 jio_snprintf(path, len, "%s%cmodules%c%s", home, file_sep, file_sep, module_name);
691
692 struct stat st;
693 if (os::stat(path, &st) == 0) {
694 // Directory found
695 ClassPathEntry* new_entry = create_class_path_entry(current, path, &st, false, false);
696
697 // If the path specification is valid, enter it into this module's list.
698 // There is no need to check for duplicate modules in the exploded entry list,
699 // since no two modules with the same name can be defined to the boot loader.
700 // This is checked at module definition time in Modules::define_module.
701 if (new_entry != NULL__null) {
702 ModuleClassPathList* module_cpl = new ModuleClassPathList(module_sym);
703 module_cpl->add_to_list(new_entry);
704 {
705 MutexLocker ml(current, Module_lock);
706 _exploded_entries->push(module_cpl);
707 }
708 log_info(class, load)(!(LogImpl<(LogTag::_class), (LogTag::_load), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Info))) ? (void)0 : LogImpl<(LogTag
::_class), (LogTag::_load), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Info>
("path: %s", path);
709 }
710 }
711}
712
713jzfile* ClassLoader::open_zip_file(const char* canonical_path, char** error_msg, JavaThread* thread) {
714 // enable call to C land
715 ThreadToNativeFromVM ttn(thread);
716 HandleMark hm(thread);
717 load_zip_library_if_needed();
718 return (*ZipOpen)(canonical_path, error_msg);
719}
720
721ClassPathEntry* ClassLoader::create_class_path_entry(JavaThread* current,
722 const char *path, const struct stat* st,
723 bool is_boot_append,
724 bool from_class_path_attr) {
725 ClassPathEntry* new_entry = NULL__null;
726 if ((st->st_mode & S_IFMT0170000) == S_IFREG0100000) {
727 ResourceMark rm(current);
728 // Regular file, should be a zip file
729 // Canonicalized filename
730 const char* canonical_path = get_canonical_path(path, current);
731 if (canonical_path == NULL__null) {
732 return NULL__null;
733 }
734 char* error_msg = NULL__null;
735 jzfile* zip = open_zip_file(canonical_path, &error_msg, current);
736 if (zip != NULL__null && error_msg == NULL__null) {
737 new_entry = new ClassPathZipEntry(zip, path, is_boot_append, from_class_path_attr);
738 } else {
739#if INCLUDE_CDS1
740 ClassLoaderExt::set_has_non_jar_in_classpath();
741#endif
742 return NULL__null;
743 }
744 log_info(class, path)(!(LogImpl<(LogTag::_class), (LogTag::_path), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Info))) ? (void)0 : LogImpl<(LogTag
::_class), (LogTag::_path), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Info>
("opened: %s", path);
745 log_info(class, load)(!(LogImpl<(LogTag::_class), (LogTag::_load), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Info))) ? (void)0 : LogImpl<(LogTag
::_class), (LogTag::_load), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Info>
("opened: %s", path);
746 } else {
747 // Directory
748 new_entry = new ClassPathDirEntry(path);
749 log_info(class, load)(!(LogImpl<(LogTag::_class), (LogTag::_load), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Info))) ? (void)0 : LogImpl<(LogTag
::_class), (LogTag::_load), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Info>
("path: %s", path);
750 }
751 return new_entry;
752}
753
754
755// Create a class path zip entry for a given path (return NULL if not found
756// or zip/JAR file cannot be opened)
757ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path, bool is_boot_append) {
758 // check for a regular file
759 struct stat st;
760 if (os::stat(path, &st) == 0) {
761 if ((st.st_mode & S_IFMT0170000) == S_IFREG0100000) {
762 JavaThread* thread = JavaThread::current();
763 ResourceMark rm(thread);
764 const char* canonical_path = get_canonical_path(path, thread);
765 if (canonical_path != NULL__null) {
766 char* error_msg = NULL__null;
767 jzfile* zip = open_zip_file(canonical_path, &error_msg, thread);
768 if (zip != NULL__null && error_msg == NULL__null) {
769 // create using canonical path
770 return new ClassPathZipEntry(zip, canonical_path, is_boot_append, false);
771 }
772 }
773 }
774 }
775 return NULL__null;
776}
777
778// The boot append entries are added with a lock, and read lock free.
779void ClassLoader::add_to_boot_append_entries(ClassPathEntry *new_entry) {
780 if (new_entry != NULL__null) {
781 MutexLocker ml(Bootclasspath_lock, Mutex::_no_safepoint_check_flag);
782 if (_last_append_entry == NULL__null) {
783 _last_append_entry = new_entry;
784 assert(first_append_entry() == NULL, "boot loader's append class path entry list not empty")do { if (!(first_append_entry() == __null)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 784, "assert(" "first_append_entry() == __null" ") failed",
"boot loader's append class path entry list not empty"); ::breakpoint
(); } } while (0)
;
785 Atomic::release_store(&_first_append_entry_list, new_entry);
786 } else {
787 _last_append_entry->set_next(new_entry);
788 _last_append_entry = new_entry;
789 }
790 }
791}
792
793// Record the path entries specified in -cp during dump time. The recorded
794// information will be used at runtime for loading the archived app classes.
795//
796// Note that at dump time, ClassLoader::_app_classpath_entries are NOT used for
797// loading app classes. Instead, the app class are loaded by the
798// jdk/internal/loader/ClassLoaders$AppClassLoader instance.
799void ClassLoader::add_to_app_classpath_entries(JavaThread* current,
800 const char* path,
801 ClassPathEntry* entry,
802 bool check_for_duplicates) {
803#if INCLUDE_CDS1
804 assert(entry != NULL, "ClassPathEntry should not be NULL")do { if (!(entry != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 804, "assert(" "entry != __null" ") failed", "ClassPathEntry should not be NULL"
); ::breakpoint(); } } while (0)
;
805 ClassPathEntry* e = _app_classpath_entries;
806 if (check_for_duplicates) {
807 while (e != NULL__null) {
808 if (strcmp(e->name(), entry->name()) == 0) {
809 // entry already exists
810 return;
811 }
812 e = e->next();
813 }
814 }
815
816 // The entry does not exist, add to the list
817 if (_app_classpath_entries == NULL__null) {
818 assert(_last_app_classpath_entry == NULL, "Sanity")do { if (!(_last_app_classpath_entry == __null)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 818, "assert(" "_last_app_classpath_entry == __null" ") failed"
, "Sanity"); ::breakpoint(); } } while (0)
;
819 _app_classpath_entries = _last_app_classpath_entry = entry;
820 } else {
821 _last_app_classpath_entry->set_next(entry);
822 _last_app_classpath_entry = entry;
823 }
824
825 if (entry->is_jar_file()) {
826 ClassLoaderExt::process_jar_manifest(current, entry, check_for_duplicates);
827 }
828#endif
829}
830
831// Returns true IFF the file/dir exists and the entry was successfully created.
832bool ClassLoader::update_class_path_entry_list(JavaThread* current,
833 const char *path,
834 bool check_for_duplicates,
835 bool is_boot_append,
836 bool from_class_path_attr) {
837 struct stat st;
838 if (os::stat(path, &st) == 0) {
839 // File or directory found
840 ClassPathEntry* new_entry = NULL__null;
841 new_entry = create_class_path_entry(current, path, &st, is_boot_append, from_class_path_attr);
842 if (new_entry == NULL__null) {
843 return false;
844 }
845
846 // Do not reorder the bootclasspath which would break get_system_package().
847 // Add new entry to linked list
848 if (is_boot_append) {
849 add_to_boot_append_entries(new_entry);
850 } else {
851 add_to_app_classpath_entries(current, path, new_entry, check_for_duplicates);
852 }
853 return true;
854 } else {
855 return false;
856 }
857}
858
859static void print_module_entry_table(const GrowableArray<ModuleClassPathList*>* const module_list) {
860 ResourceMark rm;
861 int num_of_entries = module_list->length();
862 for (int i = 0; i < num_of_entries; i++) {
863 ClassPathEntry* e;
864 ModuleClassPathList* mpl = module_list->at(i);
865 tty->print("%s=", mpl->module_name()->as_C_string());
866 e = mpl->module_first_entry();
867 while (e != NULL__null) {
868 tty->print("%s", e->name());
869 e = e->next();
870 if (e != NULL__null) {
871 tty->print("%s", os::path_separator());
872 }
873 }
874 tty->print(" ;");
875 }
876}
877
878void ClassLoader::print_bootclasspath() {
879 ClassPathEntry* e;
880 tty->print("[bootclasspath= ");
881
882 // Print --patch-module module/path specifications first
883 if (_patch_mod_entries != NULL__null) {
884 print_module_entry_table(_patch_mod_entries);
885 }
886
887 // [jimage | exploded modules build]
888 if (has_jrt_entry()) {
889 // Print the location of the java runtime image
890 tty->print("%s ;", _jrt_entry->name());
891 } else {
892 // Print exploded module build path specifications
893 if (_exploded_entries != NULL__null) {
894 print_module_entry_table(_exploded_entries);
895 }
896 }
897
898 // appended entries
899 e = first_append_entry();
900 while (e != NULL__null) {
901 tty->print("%s ;", e->name());
902 e = e->next();
903 }
904 tty->print_cr("]");
905}
906
907void* ClassLoader::dll_lookup(void* lib, const char* name, const char* path) {
908 void* func = os::dll_lookup(lib, name);
909 if (func == NULL__null) {
910 char msg[256] = "";
911 jio_snprintf(msg, sizeof(msg), "Could not resolve \"%s\"", name);
912 vm_exit_during_initialization(msg, path);
913 }
914 return func;
915}
916
917void ClassLoader::load_java_library() {
918 assert(CanonicalizeEntry == NULL, "should not load java library twice")do { if (!(CanonicalizeEntry == __null)) { (*g_assert_poison)
= 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 918, "assert(" "CanonicalizeEntry == __null" ") failed", "should not load java library twice"
); ::breakpoint(); } } while (0)
;
919 void *javalib_handle = os::native_java_library();
920 if (javalib_handle == NULL__null) {
921 vm_exit_during_initialization("Unable to load java library", NULL__null);
922 }
923
924 CanonicalizeEntry = CAST_TO_FN_PTR(canonicalize_fn_t, dll_lookup(javalib_handle, "JDK_Canonicalize", NULL))(reinterpret_cast<canonicalize_fn_t>(dll_lookup(javalib_handle
, "JDK_Canonicalize", __null)))
;
925}
926
927void ClassLoader::release_load_zip_library() {
928 MutexLocker locker(Zip_lock, Monitor::_no_safepoint_check_flag);
929 if (_libzip_loaded == 0) {
930 load_zip_library();
931 Atomic::release_store(&_libzip_loaded, 1);
932 }
933}
934
935void ClassLoader::load_zip_library() {
936 assert(ZipOpen == NULL, "should not load zip library twice")do { if (!(ZipOpen == __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 936, "assert(" "ZipOpen == __null" ") failed", "should not load zip library twice"
); ::breakpoint(); } } while (0)
;
937 char path[JVM_MAXPATHLEN4096 + 1];
938 char ebuf[1024];
939 void* handle = NULL__null;
940 if (os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), "zip")) {
941 handle = os::dll_load(path, ebuf, sizeof ebuf);
942 }
943 if (handle == NULL__null) {
944 vm_exit_during_initialization("Unable to load zip library", path);
945 }
946
947 ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, dll_lookup(handle, "ZIP_Open", path))(reinterpret_cast<ZipOpen_t>(dll_lookup(handle, "ZIP_Open"
, path)))
;
948 ZipClose = CAST_TO_FN_PTR(ZipClose_t, dll_lookup(handle, "ZIP_Close", path))(reinterpret_cast<ZipClose_t>(dll_lookup(handle, "ZIP_Close"
, path)))
;
949 FindEntry = CAST_TO_FN_PTR(FindEntry_t, dll_lookup(handle, "ZIP_FindEntry", path))(reinterpret_cast<FindEntry_t>(dll_lookup(handle, "ZIP_FindEntry"
, path)))
;
950 ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, dll_lookup(handle, "ZIP_ReadEntry", path))(reinterpret_cast<ReadEntry_t>(dll_lookup(handle, "ZIP_ReadEntry"
, path)))
;
951 GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, dll_lookup(handle, "ZIP_GetNextEntry", path))(reinterpret_cast<GetNextEntry_t>(dll_lookup(handle, "ZIP_GetNextEntry"
, path)))
;
952 Crc32 = CAST_TO_FN_PTR(Crc32_t, dll_lookup(handle, "ZIP_CRC32", path))(reinterpret_cast<Crc32_t>(dll_lookup(handle, "ZIP_CRC32"
, path)))
;
953}
954
955void ClassLoader::load_jimage_library() {
956 assert(JImageOpen == NULL, "should not load jimage library twice")do { if (!(JImageOpen == __null)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 956, "assert(" "JImageOpen == __null" ") failed", "should not load jimage library twice"
); ::breakpoint(); } } while (0)
;
957 char path[JVM_MAXPATHLEN4096 + 1];
958 char ebuf[1024];
959 void* handle = NULL__null;
960 if (os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), "jimage")) {
961 handle = os::dll_load(path, ebuf, sizeof ebuf);
962 }
963 if (handle == NULL__null) {
964 vm_exit_during_initialization("Unable to load jimage library", path);
965 }
966
967 JImageOpen = CAST_TO_FN_PTR(JImageOpen_t, dll_lookup(handle, "JIMAGE_Open", path))(reinterpret_cast<JImageOpen_t>(dll_lookup(handle, "JIMAGE_Open"
, path)))
;
968 JImageClose = CAST_TO_FN_PTR(JImageClose_t, dll_lookup(handle, "JIMAGE_Close", path))(reinterpret_cast<JImageClose_t>(dll_lookup(handle, "JIMAGE_Close"
, path)))
;
969 JImageFindResource = CAST_TO_FN_PTR(JImageFindResource_t, dll_lookup(handle, "JIMAGE_FindResource", path))(reinterpret_cast<JImageFindResource_t>(dll_lookup(handle
, "JIMAGE_FindResource", path)))
;
970 JImageGetResource = CAST_TO_FN_PTR(JImageGetResource_t, dll_lookup(handle, "JIMAGE_GetResource", path))(reinterpret_cast<JImageGetResource_t>(dll_lookup(handle
, "JIMAGE_GetResource", path)))
;
971}
972
973int ClassLoader::crc32(int crc, const char* buf, int len) {
974 load_zip_library_if_needed();
975 return (*Crc32)(crc, (const jbyte*)buf, len);
976}
977
978oop ClassLoader::get_system_package(const char* name, TRAPSJavaThread* __the_thread__) {
979 // Look up the name in the boot loader's package entry table.
980 if (name != NULL__null) {
981 TempNewSymbol package_sym = SymbolTable::new_symbol(name);
982 // Look for the package entry in the boot loader's package entry table.
983 PackageEntry* package =
984 ClassLoaderData::the_null_class_loader_data()->packages()->lookup_only(package_sym);
985
986 // Return NULL if package does not exist or if no classes in that package
987 // have been loaded.
988 if (package != NULL__null && package->has_loaded_class()) {
989 ModuleEntry* module = package->module();
990 if (module->location() != NULL__null) {
991 ResourceMark rm(THREAD__the_thread__);
992 Handle ml = java_lang_String::create_from_str(
993 module->location()->as_C_string(), THREAD__the_thread__);
994 return ml();
995 }
996 // Return entry on boot loader class path.
997 Handle cph = java_lang_String::create_from_str(
998 ClassLoader::classpath_entry(package->classpath_index())->name(), THREAD__the_thread__);
999 return cph();
1000 }
1001 }
1002 return NULL__null;
1003}
1004
1005objArrayOop ClassLoader::get_system_packages(TRAPSJavaThread* __the_thread__) {
1006 ResourceMark rm(THREAD__the_thread__);
1007 // List of pointers to PackageEntrys that have loaded classes.
1008 GrowableArray<PackageEntry*>* loaded_class_pkgs = new GrowableArray<PackageEntry*>(50);
1009 {
1010 MutexLocker ml(THREAD__the_thread__, Module_lock);
1011
1012 PackageEntryTable* pe_table =
1013 ClassLoaderData::the_null_class_loader_data()->packages();
1014
1015 // Collect the packages that have at least one loaded class.
1016 for (int x = 0; x < pe_table->table_size(); x++) {
1017 for (PackageEntry* package_entry = pe_table->bucket(x);
1018 package_entry != NULL__null;
1019 package_entry = package_entry->next()) {
1020 if (package_entry->has_loaded_class()) {
1021 loaded_class_pkgs->append(package_entry);
1022 }
1023 }
1024 }
1025 }
1026
1027
1028 // Allocate objArray and fill with java.lang.String
1029 objArrayOop r = oopFactory::new_objArray(vmClasses::String_klass(),
1030 loaded_class_pkgs->length(), CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1031 objArrayHandle result(THREAD__the_thread__, r);
1032 for (int x = 0; x < loaded_class_pkgs->length(); x++) {
1033 PackageEntry* package_entry = loaded_class_pkgs->at(x);
1034 Handle str = java_lang_String::create_from_symbol(package_entry->name(), CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1035 result->obj_at_put(x, str());
1036 }
1037 return result();
1038}
1039
1040// caller needs ResourceMark
1041const char* ClassLoader::file_name_for_class_name(const char* class_name,
1042 int class_name_len) {
1043 assert(class_name != NULL, "invariant")do { if (!(class_name != __null)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1043, "assert(" "class_name != __null" ") failed", "invariant"
); ::breakpoint(); } } while (0)
;
1044 assert((int)strlen(class_name) == class_name_len, "invariant")do { if (!((int)strlen(class_name) == class_name_len)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1044, "assert(" "(int)strlen(class_name) == class_name_len"
") failed", "invariant"); ::breakpoint(); } } while (0)
;
1045
1046 static const char class_suffix[] = ".class";
1047 size_t class_suffix_len = sizeof(class_suffix);
1048
1049 char* const file_name = NEW_RESOURCE_ARRAY(char,(char*) resource_allocate_bytes((class_name_len + class_suffix_len
) * sizeof(char))
1050 class_name_len +(char*) resource_allocate_bytes((class_name_len + class_suffix_len
) * sizeof(char))
1051 class_suffix_len)(char*) resource_allocate_bytes((class_name_len + class_suffix_len
) * sizeof(char))
; // includes term NULL
1052
1053 strncpy(file_name, class_name, class_name_len);
1054 strncpy(&file_name[class_name_len], class_suffix, class_suffix_len);
1055
1056 return file_name;
1057}
1058
1059ClassPathEntry* find_first_module_cpe(ModuleEntry* mod_entry,
1060 const GrowableArray<ModuleClassPathList*>* const module_list) {
1061 int num_of_entries = module_list->length();
1062 const Symbol* class_module_name = mod_entry->name();
1063
1064 // Loop through all the modules in either the patch-module or exploded entries looking for module
1065 for (int i = 0; i < num_of_entries; i++) {
1066 ModuleClassPathList* module_cpl = module_list->at(i);
1067 Symbol* module_cpl_name = module_cpl->module_name();
1068
1069 if (module_cpl_name->fast_compare(class_module_name) == 0) {
1070 // Class' module has been located.
1071 return module_cpl->module_first_entry();
1072 }
1073 }
1074 return NULL__null;
1075}
1076
1077
1078// Search either the patch-module or exploded build entries for class.
1079ClassFileStream* ClassLoader::search_module_entries(JavaThread* current,
1080 const GrowableArray<ModuleClassPathList*>* const module_list,
1081 const char* const class_name,
1082 const char* const file_name) {
1083 ClassFileStream* stream = NULL__null;
1084
1085 // Find the class' defining module in the boot loader's module entry table
1086 TempNewSymbol class_name_symbol = SymbolTable::new_symbol(class_name);
1087 TempNewSymbol pkg_name = package_from_class_name(class_name_symbol);
1088 PackageEntry* pkg_entry = get_package_entry(pkg_name, ClassLoaderData::the_null_class_loader_data());
1089 ModuleEntry* mod_entry = (pkg_entry != NULL__null) ? pkg_entry->module() : NULL__null;
1090
1091 // If the module system has not defined java.base yet, then
1092 // classes loaded are assumed to be defined to java.base.
1093 // When java.base is eventually defined by the module system,
1094 // all packages of classes that have been previously loaded
1095 // are verified in ModuleEntryTable::verify_javabase_packages().
1096 if (!Universe::is_module_initialized() &&
1097 !ModuleEntryTable::javabase_defined() &&
1098 mod_entry == NULL__null) {
1099 mod_entry = ModuleEntryTable::javabase_moduleEntry();
1100 }
1101
1102 // The module must be a named module
1103 ClassPathEntry* e = NULL__null;
1104 if (mod_entry != NULL__null && mod_entry->is_named()) {
1105 if (module_list == _exploded_entries) {
1106 // The exploded build entries can be added to at any time so a lock is
1107 // needed when searching them.
1108 assert(!ClassLoader::has_jrt_entry(), "Must be exploded build")do { if (!(!ClassLoader::has_jrt_entry())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1108, "assert(" "!ClassLoader::has_jrt_entry()" ") failed",
"Must be exploded build"); ::breakpoint(); } } while (0)
;
1109 MutexLocker ml(current, Module_lock);
1110 e = find_first_module_cpe(mod_entry, module_list);
1111 } else {
1112 e = find_first_module_cpe(mod_entry, module_list);
1113 }
1114 }
1115
1116 // Try to load the class from the module's ClassPathEntry list.
1117 while (e != NULL__null) {
1118 stream = e->open_stream(current, file_name);
1119 // No context.check is required since CDS is not supported
1120 // for an exploded modules build or if --patch-module is specified.
1121 if (NULL__null != stream) {
1122 return stream;
1123 }
1124 e = e->next();
1125 }
1126 // If the module was located, break out even if the class was not
1127 // located successfully from that module's ClassPathEntry list.
1128 // There will not be another valid entry for that module.
1129 return NULL__null;
1130}
1131
1132// Called by the boot classloader to load classes
1133InstanceKlass* ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPSJavaThread* __the_thread__) {
1134 assert(name != NULL, "invariant")do { if (!(name != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1134, "assert(" "name != __null" ") failed", "invariant"); ::
breakpoint(); } } while (0)
;
1135
1136 ResourceMark rm(THREAD__the_thread__);
1137 HandleMark hm(THREAD__the_thread__);
1138
1139 const char* const class_name = name->as_C_string();
1140
1141 EventMarkClassLoading m("Loading class %s", class_name);
1142
1143 const char* const file_name = file_name_for_class_name(class_name,
1144 name->utf8_length());
1145 assert(file_name != NULL, "invariant")do { if (!(file_name != __null)) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1145, "assert(" "file_name != __null" ") failed", "invariant"
); ::breakpoint(); } } while (0)
;
1146
1147 // Lookup stream for parsing .class file
1148 ClassFileStream* stream = NULL__null;
1149 s2 classpath_index = 0;
1150 ClassPathEntry* e = NULL__null;
1151
1152 // If search_append_only is true, boot loader visibility boundaries are
1153 // set to be _first_append_entry to the end. This includes:
1154 // [-Xbootclasspath/a]; [jvmti appended entries]
1155 //
1156 // If search_append_only is false, boot loader visibility boundaries are
1157 // set to be the --patch-module entries plus the base piece. This includes:
1158 // [--patch-module=<module>=<file>(<pathsep><file>)*]; [jimage | exploded module build]
1159 //
1160
1161 // Load Attempt #1: --patch-module
1162 // Determine the class' defining module. If it appears in the _patch_mod_entries,
1163 // attempt to load the class from those locations specific to the module.
1164 // Specifications to --patch-module can contain a partial number of classes
1165 // that are part of the overall module definition. So if a particular class is not
1166 // found within its module specification, the search should continue to Load Attempt #2.
1167 // Note: The --patch-module entries are never searched if the boot loader's
1168 // visibility boundary is limited to only searching the append entries.
1169 if (_patch_mod_entries != NULL__null && !search_append_only) {
1170 // At CDS dump time, the --patch-module entries are ignored. That means a
1171 // class is still loaded from the runtime image even if it might
1172 // appear in the _patch_mod_entries. The runtime shared class visibility
1173 // check will determine if a shared class is visible based on the runtime
1174 // environemnt, including the runtime --patch-module setting.
1175 //
1176 // DynamicDumpSharedSpaces requires UseSharedSpaces to be enabled. Since --patch-module
1177 // is not supported with UseSharedSpaces, it is not supported with DynamicDumpSharedSpaces.
1178 assert(!DynamicDumpSharedSpaces, "sanity")do { if (!(!DynamicDumpSharedSpaces)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1178, "assert(" "!DynamicDumpSharedSpaces" ") failed", "sanity"
); ::breakpoint(); } } while (0)
;
1179 if (!DumpSharedSpaces) {
1180 stream = search_module_entries(THREAD__the_thread__, _patch_mod_entries, class_name, file_name);
1181 }
1182 }
1183
1184 // Load Attempt #2: [jimage | exploded build]
1185 if (!search_append_only && (NULL__null == stream)) {
1186 if (has_jrt_entry()) {
1187 e = _jrt_entry;
1188 stream = _jrt_entry->open_stream(THREAD__the_thread__, file_name);
1189 } else {
1190 // Exploded build - attempt to locate class in its defining module's location.
1191 assert(_exploded_entries != NULL, "No exploded build entries present")do { if (!(_exploded_entries != __null)) { (*g_assert_poison)
= 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1191, "assert(" "_exploded_entries != __null" ") failed", "No exploded build entries present"
); ::breakpoint(); } } while (0)
;
1192 stream = search_module_entries(THREAD__the_thread__, _exploded_entries, class_name, file_name);
1193 }
1194 }
1195
1196 // Load Attempt #3: [-Xbootclasspath/a]; [jvmti appended entries]
1197 if (search_append_only && (NULL__null == stream)) {
1198 // For the boot loader append path search, the starting classpath_index
1199 // for the appended piece is always 1 to account for either the
1200 // _jrt_entry or the _exploded_entries.
1201 assert(classpath_index == 0, "The classpath_index has been incremented incorrectly")do { if (!(classpath_index == 0)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1201, "assert(" "classpath_index == 0" ") failed", "The classpath_index has been incremented incorrectly"
); ::breakpoint(); } } while (0)
;
1202 classpath_index = 1;
1203
1204 e = first_append_entry();
1205 while (e != NULL__null) {
1206 stream = e->open_stream(THREAD__the_thread__, file_name);
1207 if (NULL__null != stream) {
1208 break;
1209 }
1210 e = e->next();
1211 ++classpath_index;
1212 }
1213 }
1214
1215 if (NULL__null == stream) {
1216 return NULL__null;
1217 }
1218
1219 stream->set_verify(ClassLoaderExt::should_verify(classpath_index));
1220
1221 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
1222 Handle protection_domain;
1223 ClassLoadInfo cl_info(protection_domain);
1224
1225 InstanceKlass* result = KlassFactory::create_from_stream(stream,
1226 name,
1227 loader_data,
1228 cl_info,
1229 CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1230 result->set_classpath_index(classpath_index);
1231 return result;
1232}
1233
1234#if INCLUDE_CDS1
1235char* ClassLoader::skip_uri_protocol(char* source) {
1236 if (strncmp(source, "file:", 5) == 0) {
1237 // file: protocol path could start with file:/ or file:///
1238 // locate the char after all the forward slashes
1239 int offset = 5;
1240 while (*(source + offset) == '/') {
1241 offset++;
1242 }
1243 source += offset;
1244 // for non-windows platforms, move back one char as the path begins with a '/'
1245#ifndef _WINDOWS
1246 source -= 1;
1247#endif
1248 } else if (strncmp(source, "jrt:/", 5) == 0) {
1249 source += 5;
1250 }
1251 return source;
1252}
1253
1254// Record the shared classpath index and loader type for classes loaded
1255// by the builtin loaders at dump time.
1256void ClassLoader::record_result(JavaThread* current, InstanceKlass* ik,
1257 const ClassFileStream* stream, bool redefined) {
1258 Arguments::assert_is_dumping_archive();
1259 assert(stream != NULL, "sanity")do { if (!(stream != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1259, "assert(" "stream != __null" ") failed", "sanity"); ::
breakpoint(); } } while (0)
;
1260
1261 if (ik->is_hidden()) {
1262 // We do not archive hidden classes.
1263 return;
1264 }
1265
1266 oop loader = ik->class_loader();
1267 char* src = (char*)stream->source();
1268 if (src == NULL__null) {
1269 if (loader == NULL__null) {
1270 // JFR classes
1271 ik->set_shared_classpath_index(0);
1272 ik->set_shared_class_loader_type(ClassLoader::BOOT_LOADER);
1273 }
1274 return;
1275 }
1276
1277 assert(has_jrt_entry(), "CDS dumping does not support exploded JDK build")do { if (!(has_jrt_entry())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1277, "assert(" "has_jrt_entry()" ") failed", "CDS dumping does not support exploded JDK build"
); ::breakpoint(); } } while (0)
;
1278
1279 ResourceMark rm(current);
1280 int classpath_index = -1;
1281 PackageEntry* pkg_entry = ik->package();
1282
1283 if (FileMapInfo::get_number_of_shared_paths() > 0) {
1284 // Save the path from the file: protocol or the module name from the jrt: protocol
1285 // if no protocol prefix is found, path is the same as stream->source(). This path
1286 // must be valid since the class has been successfully parsed.
1287 char* path = skip_uri_protocol(src);
1288 assert(path != NULL, "sanity")do { if (!(path != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1288, "assert(" "path != __null" ") failed", "sanity"); ::breakpoint
(); } } while (0)
;
1289 for (int i = 0; i < FileMapInfo::get_number_of_shared_paths(); i++) {
1290 SharedClassPathEntry* ent = FileMapInfo::shared_path(i);
1291 // A shared path has been validated during its creation in ClassLoader::create_class_path_entry(),
1292 // it must be valid here.
1293 assert(ent->name() != NULL, "sanity")do { if (!(ent->name() != __null)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1293, "assert(" "ent->name() != __null" ") failed", "sanity"
); ::breakpoint(); } } while (0)
;
1294 // If the path (from the class stream source) is the same as the shared
1295 // class or module path, then we have a match.
1296 // src may come from the App/Platform class loaders, which would canonicalize
1297 // the file name. We cannot use strcmp to check for equality against ent->name().
1298 // We must use os::same_files (which is faster than canonicalizing ent->name()).
1299 if (os::same_files(ent->name(), path)) {
1300 // NULL pkg_entry and pkg_entry in an unnamed module implies the class
1301 // is from the -cp or boot loader append path which consists of -Xbootclasspath/a
1302 // and jvmti appended entries.
1303 if ((pkg_entry == NULL__null) || (pkg_entry->in_unnamed_module())) {
1304 // Ensure the index is within the -cp range before assigning
1305 // to the classpath_index.
1306 if (SystemDictionary::is_system_class_loader(loader) &&
1307 (i >= ClassLoaderExt::app_class_paths_start_index()) &&
1308 (i < ClassLoaderExt::app_module_paths_start_index())) {
1309 classpath_index = i;
1310 break;
1311 } else {
1312 if ((i >= 1) &&
1313 (i < ClassLoaderExt::app_class_paths_start_index())) {
1314 // The class must be from boot loader append path which consists of
1315 // -Xbootclasspath/a and jvmti appended entries.
1316 assert(loader == NULL, "sanity")do { if (!(loader == __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1316, "assert(" "loader == __null" ") failed", "sanity"); ::
breakpoint(); } } while (0)
;
1317 classpath_index = i;
1318 break;
1319 }
1320 }
1321 } else {
1322 // A class from a named module from the --module-path. Ensure the index is
1323 // within the --module-path range before assigning to the classpath_index.
1324 if ((pkg_entry != NULL__null) && !(pkg_entry->in_unnamed_module()) && (i > 0)) {
1325 if (i >= ClassLoaderExt::app_module_paths_start_index() &&
1326 i < FileMapInfo::get_number_of_shared_paths()) {
1327 classpath_index = i;
1328 break;
1329 }
1330 }
1331 }
1332 }
1333 // for index 0 and the stream->source() is the modules image or has the jrt: protocol.
1334 // The class must be from the runtime modules image.
1335 if (i == 0 && (stream->from_boot_loader_modules_image() || string_starts_with(src, "jrt:"))) {
1336 classpath_index = i;
1337 break;
1338 }
1339 }
1340
1341 // No path entry found for this class: most likely a shared class loaded by the
1342 // user defined classloader.
1343 if (classpath_index < 0 && !SystemDictionaryShared::is_builtin_loader(ik->class_loader_data())) {
1344 assert(ik->shared_classpath_index() < 0, "not assigned yet")do { if (!(ik->shared_classpath_index() < 0)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1344, "assert(" "ik->shared_classpath_index() < 0" ") failed"
, "not assigned yet"); ::breakpoint(); } } while (0)
;
1345 ik->set_shared_classpath_index(UNREGISTERED_INDEX-9999);
1346 SystemDictionaryShared::set_shared_class_misc_info(ik, (ClassFileStream*)stream);
1347 return;
1348 }
1349 } else {
1350 // The shared path table is set up after module system initialization.
1351 // The path table contains no entry before that. Any classes loaded prior
1352 // to the setup of the shared path table must be from the modules image.
1353 assert(stream->from_boot_loader_modules_image(), "stream must be loaded by boot loader from modules image")do { if (!(stream->from_boot_loader_modules_image())) { (*
g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1353, "assert(" "stream->from_boot_loader_modules_image()"
") failed", "stream must be loaded by boot loader from modules image"
); ::breakpoint(); } } while (0)
;
1354 assert(FileMapInfo::get_number_of_shared_paths() == 0, "shared path table must not have been setup")do { if (!(FileMapInfo::get_number_of_shared_paths() == 0)) {
(*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1354, "assert(" "FileMapInfo::get_number_of_shared_paths() == 0"
") failed", "shared path table must not have been setup"); ::
breakpoint(); } } while (0)
;
1355 classpath_index = 0;
1356 }
1357
1358 const char* const class_name = ik->name()->as_C_string();
1359 const char* const file_name = file_name_for_class_name(class_name,
1360 ik->name()->utf8_length());
1361 assert(file_name != NULL, "invariant")do { if (!(file_name != __null)) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1361, "assert(" "file_name != __null" ") failed", "invariant"
); ::breakpoint(); } } while (0)
;
1362
1363 ClassLoaderExt::record_result(classpath_index, ik, redefined);
1364}
1365#endif // INCLUDE_CDS
1366
1367// Initialize the class loader's access to methods in libzip. Parse and
1368// process the boot classpath into a list ClassPathEntry objects. Once
1369// this list has been created, it must not change order (see class PackageInfo)
1370// it can be appended to and is by jvmti.
1371
1372void ClassLoader::initialize(TRAPSJavaThread* __the_thread__) {
1373 if (UsePerfData) {
1374 // jvmstat performance counters
1375 NEWPERFTICKCOUNTER(_perf_accumulated_time, SUN_CLS, "time"){_perf_accumulated_time = PerfDataManager::create_counter(SUN_CLS
, "time", PerfData::U_Ticks,__the_thread__); if ((((ThreadShadow
*)__the_thread__)->has_pending_exception())) return ; (void
)(0);}
;
1376 NEWPERFTICKCOUNTER(_perf_class_init_time, SUN_CLS, "classInitTime"){_perf_class_init_time = PerfDataManager::create_counter(SUN_CLS
, "classInitTime", PerfData::U_Ticks,__the_thread__); if ((((
ThreadShadow*)__the_thread__)->has_pending_exception())) return
; (void)(0);}
;
1377 NEWPERFTICKCOUNTER(_perf_class_init_selftime, SUN_CLS, "classInitTime.self"){_perf_class_init_selftime = PerfDataManager::create_counter(
SUN_CLS, "classInitTime.self", PerfData::U_Ticks,__the_thread__
); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0);}
;
1378 NEWPERFTICKCOUNTER(_perf_class_verify_time, SUN_CLS, "classVerifyTime"){_perf_class_verify_time = PerfDataManager::create_counter(SUN_CLS
, "classVerifyTime", PerfData::U_Ticks,__the_thread__); if ((
((ThreadShadow*)__the_thread__)->has_pending_exception()))
return ; (void)(0);}
;
1379 NEWPERFTICKCOUNTER(_perf_class_verify_selftime, SUN_CLS, "classVerifyTime.self"){_perf_class_verify_selftime = PerfDataManager::create_counter
(SUN_CLS, "classVerifyTime.self", PerfData::U_Ticks,__the_thread__
); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0);}
;
1380 NEWPERFTICKCOUNTER(_perf_class_link_time, SUN_CLS, "classLinkedTime"){_perf_class_link_time = PerfDataManager::create_counter(SUN_CLS
, "classLinkedTime", PerfData::U_Ticks,__the_thread__); if ((
((ThreadShadow*)__the_thread__)->has_pending_exception()))
return ; (void)(0);}
;
1381 NEWPERFTICKCOUNTER(_perf_class_link_selftime, SUN_CLS, "classLinkedTime.self"){_perf_class_link_selftime = PerfDataManager::create_counter(
SUN_CLS, "classLinkedTime.self", PerfData::U_Ticks,__the_thread__
); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0);}
;
1382 NEWPERFEVENTCOUNTER(_perf_classes_inited, SUN_CLS, "initializedClasses"){_perf_classes_inited = PerfDataManager::create_counter(SUN_CLS
, "initializedClasses", PerfData::U_Events,__the_thread__); if
((((ThreadShadow*)__the_thread__)->has_pending_exception(
))) return ; (void)(0);}
;
1383 NEWPERFEVENTCOUNTER(_perf_classes_linked, SUN_CLS, "linkedClasses"){_perf_classes_linked = PerfDataManager::create_counter(SUN_CLS
, "linkedClasses", PerfData::U_Events,__the_thread__); if (((
(ThreadShadow*)__the_thread__)->has_pending_exception())) return
; (void)(0);}
;
1384 NEWPERFEVENTCOUNTER(_perf_classes_verified, SUN_CLS, "verifiedClasses"){_perf_classes_verified = PerfDataManager::create_counter(SUN_CLS
, "verifiedClasses", PerfData::U_Events,__the_thread__); if (
(((ThreadShadow*)__the_thread__)->has_pending_exception())
) return ; (void)(0);}
;
1385
1386 NEWPERFTICKCOUNTER(_perf_sys_class_lookup_time, SUN_CLS, "lookupSysClassTime"){_perf_sys_class_lookup_time = PerfDataManager::create_counter
(SUN_CLS, "lookupSysClassTime", PerfData::U_Ticks,__the_thread__
); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0);}
;
1387 NEWPERFTICKCOUNTER(_perf_shared_classload_time, SUN_CLS, "sharedClassLoadTime"){_perf_shared_classload_time = PerfDataManager::create_counter
(SUN_CLS, "sharedClassLoadTime", PerfData::U_Ticks,__the_thread__
); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0);}
;
1388 NEWPERFTICKCOUNTER(_perf_sys_classload_time, SUN_CLS, "sysClassLoadTime"){_perf_sys_classload_time = PerfDataManager::create_counter(SUN_CLS
, "sysClassLoadTime", PerfData::U_Ticks,__the_thread__); if (
(((ThreadShadow*)__the_thread__)->has_pending_exception())
) return ; (void)(0);}
;
1389 NEWPERFTICKCOUNTER(_perf_app_classload_time, SUN_CLS, "appClassLoadTime"){_perf_app_classload_time = PerfDataManager::create_counter(SUN_CLS
, "appClassLoadTime", PerfData::U_Ticks,__the_thread__); if (
(((ThreadShadow*)__the_thread__)->has_pending_exception())
) return ; (void)(0);}
;
1390 NEWPERFTICKCOUNTER(_perf_app_classload_selftime, SUN_CLS, "appClassLoadTime.self"){_perf_app_classload_selftime = PerfDataManager::create_counter
(SUN_CLS, "appClassLoadTime.self", PerfData::U_Ticks,__the_thread__
); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0);}
;
1391 NEWPERFEVENTCOUNTER(_perf_app_classload_count, SUN_CLS, "appClassLoadCount"){_perf_app_classload_count = PerfDataManager::create_counter(
SUN_CLS, "appClassLoadCount", PerfData::U_Events,__the_thread__
); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0);}
;
1392 NEWPERFTICKCOUNTER(_perf_define_appclasses, SUN_CLS, "defineAppClasses"){_perf_define_appclasses = PerfDataManager::create_counter(SUN_CLS
, "defineAppClasses", PerfData::U_Ticks,__the_thread__); if (
(((ThreadShadow*)__the_thread__)->has_pending_exception())
) return ; (void)(0);}
;
1393 NEWPERFTICKCOUNTER(_perf_define_appclass_time, SUN_CLS, "defineAppClassTime"){_perf_define_appclass_time = PerfDataManager::create_counter
(SUN_CLS, "defineAppClassTime", PerfData::U_Ticks,__the_thread__
); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0);}
;
1394 NEWPERFTICKCOUNTER(_perf_define_appclass_selftime, SUN_CLS, "defineAppClassTime.self"){_perf_define_appclass_selftime = PerfDataManager::create_counter
(SUN_CLS, "defineAppClassTime.self", PerfData::U_Ticks,__the_thread__
); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0);}
;
1395 NEWPERFBYTECOUNTER(_perf_app_classfile_bytes_read, SUN_CLS, "appClassBytes"){_perf_app_classfile_bytes_read = PerfDataManager::create_counter
(SUN_CLS, "appClassBytes", PerfData::U_Bytes,__the_thread__);
if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0);}
;
1396 NEWPERFBYTECOUNTER(_perf_sys_classfile_bytes_read, SUN_CLS, "sysClassBytes"){_perf_sys_classfile_bytes_read = PerfDataManager::create_counter
(SUN_CLS, "sysClassBytes", PerfData::U_Bytes,__the_thread__);
if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0);}
;
1397
1398 NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS, "unsafeDefineClassCalls"){_unsafe_defineClassCallCounter = PerfDataManager::create_counter
(SUN_CLS, "unsafeDefineClassCalls", PerfData::U_Events,__the_thread__
); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0);}
;
1399 }
1400
1401 // lookup java library entry points
1402 load_java_library();
1403 // jimage library entry points are loaded below, in lookup_vm_options
1404 setup_bootstrap_search_path(THREAD__the_thread__);
1405}
1406
1407char* lookup_vm_resource(JImageFile *jimage, const char *jimage_version, const char *path) {
1408 jlong size;
1409 JImageLocationRef location = (*JImageFindResource)(jimage, "java.base", jimage_version, path, &size);
1410 if (location == 0)
1411 return NULL__null;
1412 char *val = NEW_C_HEAP_ARRAY(char, size+1, mtClass)(char*) (AllocateHeap((size+1) * sizeof(char), mtClass));
1413 (*JImageGetResource)(jimage, location, val, size);
1414 val[size] = '\0';
1415 return val;
1416}
1417
1418// Lookup VM options embedded in the modules jimage file
1419char* ClassLoader::lookup_vm_options() {
1420 jint error;
1421 char modules_path[JVM_MAXPATHLEN4096 + 1];
1422 const char* fileSep = os::file_separator();
1423
1424 // Initialize jimage library entry points
1425 load_jimage_library();
1426
1427 jio_snprintf(modules_path, JVM_MAXPATHLEN4096 + 1, "%s%slib%smodules", Arguments::get_java_home(), fileSep, fileSep);
1428 JImage_file =(*JImageOpen)(modules_path, &error);
1429 if (JImage_file == NULL__null) {
1430 return NULL__null;
1431 }
1432
1433 const char *jimage_version = get_jimage_version_string();
1434 char *options = lookup_vm_resource(JImage_file, jimage_version, "jdk/internal/vm/options");
1435 return options;
1436}
1437
1438#if INCLUDE_CDS1
1439void ClassLoader::initialize_shared_path(JavaThread* current) {
1440 if (Arguments::is_dumping_archive()) {
1441 ClassLoaderExt::setup_search_paths(current);
1442 }
1443}
1444
1445void ClassLoader::initialize_module_path(TRAPSJavaThread* __the_thread__) {
1446 if (Arguments::is_dumping_archive()) {
1447 ClassLoaderExt::setup_module_paths(THREAD__the_thread__);
1448 FileMapInfo::allocate_shared_path_table(CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
1449 }
1450}
1451
1452// Helper function used by CDS code to get the number of module path
1453// entries during shared classpath setup time.
1454int ClassLoader::num_module_path_entries() {
1455 Arguments::assert_is_dumping_archive();
1456 int num_entries = 0;
1457 ClassPathEntry* e= ClassLoader::_module_path_entries;
1458 while (e != NULL__null) {
1459 num_entries ++;
1460 e = e->next();
1461 }
1462 return num_entries;
1463}
1464#endif
1465
1466jlong ClassLoader::classloader_time_ms() {
1467 return UsePerfData ?
1468 Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1469}
1470
1471jlong ClassLoader::class_init_count() {
1472 return UsePerfData ? _perf_classes_inited->get_value() : -1;
1473}
1474
1475jlong ClassLoader::class_init_time_ms() {
1476 return UsePerfData ?
1477 Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1;
1478}
1479
1480jlong ClassLoader::class_verify_time_ms() {
1481 return UsePerfData ?
1482 Management::ticks_to_ms(_perf_class_verify_time->get_value()) : -1;
1483}
1484
1485jlong ClassLoader::class_link_count() {
1486 return UsePerfData ? _perf_classes_linked->get_value() : -1;
1487}
1488
1489jlong ClassLoader::class_link_time_ms() {
1490 return UsePerfData ?
1491 Management::ticks_to_ms(_perf_class_link_time->get_value()) : -1;
1492}
1493
1494int ClassLoader::compute_Object_vtable() {
1495 // hardwired for JDK1.2 -- would need to duplicate class file parsing
1496 // code to determine actual value from file
1497 // Would be value '11' if finals were in vtable
1498 int JDK_1_2_Object_vtable_size = 5;
1499 return JDK_1_2_Object_vtable_size * vtableEntry::size();
1500}
1501
1502
1503void classLoader_init1() {
1504 EXCEPTION_MARKExceptionMark __em; JavaThread* __the_thread__ = __em.thread(
);
;
1505 ClassLoader::initialize(THREAD__the_thread__);
1506 if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) {
1507 vm_exit_during_initialization("ClassLoader::initialize() failed unexpectedly");
1508 }
1509}
1510
1511// Complete the ClassPathEntry setup for the boot loader
1512void ClassLoader::classLoader_init2(JavaThread* current) {
1513 // Setup the list of module/path pairs for --patch-module processing
1514 // This must be done after the SymbolTable is created in order
1515 // to use fast_compare on module names instead of a string compare.
1516 if (Arguments::get_patch_mod_prefix() != NULL__null) {
1
Assuming the condition is false
2
Taking false branch
1517 setup_patch_mod_entries();
1518 }
1519
1520 // Create the ModuleEntry for java.base (must occur after setup_patch_mod_entries
1521 // to successfully determine if java.base has been patched)
1522 create_javabase();
3
Calling 'ClassLoader::create_javabase'
1523
1524 // Setup the initial java.base/path pair for the exploded build entries.
1525 // As more modules are defined during module system initialization, more
1526 // entries will be added to the exploded build array.
1527 if (!has_jrt_entry()) {
1528 assert(!DumpSharedSpaces, "DumpSharedSpaces not supported with exploded module builds")do { if (!(!DumpSharedSpaces)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1528, "assert(" "!DumpSharedSpaces" ") failed", "DumpSharedSpaces not supported with exploded module builds"
); ::breakpoint(); } } while (0)
;
1529 assert(!DynamicDumpSharedSpaces, "DynamicDumpSharedSpaces not supported with exploded module builds")do { if (!(!DynamicDumpSharedSpaces)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1529, "assert(" "!DynamicDumpSharedSpaces" ") failed", "DynamicDumpSharedSpaces not supported with exploded module builds"
); ::breakpoint(); } } while (0)
;
1530 assert(!UseSharedSpaces, "UsedSharedSpaces not supported with exploded module builds")do { if (!(!UseSharedSpaces)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1530, "assert(" "!UseSharedSpaces" ") failed", "UsedSharedSpaces not supported with exploded module builds"
); ::breakpoint(); } } while (0)
;
1531 // Set up the boot loader's _exploded_entries list. Note that this gets
1532 // done before loading any classes, by the same thread that will
1533 // subsequently do the first class load. So, no lock is needed for this.
1534 assert(_exploded_entries == NULL, "Should only get initialized once")do { if (!(_exploded_entries == __null)) { (*g_assert_poison)
= 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1534, "assert(" "_exploded_entries == __null" ") failed", "Should only get initialized once"
); ::breakpoint(); } } while (0)
;
1535 _exploded_entries = new (ResourceObj::C_HEAP, mtModule)
1536 GrowableArray<ModuleClassPathList*>(EXPLODED_ENTRY_SIZE, mtModule);
1537 add_to_exploded_build_list(current, vmSymbols::java_base());
1538 }
1539}
1540
1541char* ClassLoader::get_canonical_path(const char* orig, Thread* thread) {
1542 assert(orig != NULL, "bad arguments")do { if (!(orig != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1542, "assert(" "orig != __null" ") failed", "bad arguments"
); ::breakpoint(); } } while (0)
;
1543 // caller needs to allocate ResourceMark for the following output buffer
1544 char* canonical_path = NEW_RESOURCE_ARRAY_IN_THREAD(thread, char, JVM_MAXPATHLEN)(char*) resource_allocate_bytes(thread, (4096 + 1) * sizeof(char
))
;
1545 ResourceMark rm(thread);
1546 // os::native_path writes into orig_copy
1547 char* orig_copy = NEW_RESOURCE_ARRAY_IN_THREAD(thread, char, strlen(orig)+1)(char*) resource_allocate_bytes(thread, (strlen(orig)+1) * sizeof
(char))
;
1548 strcpy(orig_copy, orig);
1549 if ((CanonicalizeEntry)(os::native_path(orig_copy), canonical_path, JVM_MAXPATHLEN4096 + 1) < 0) {
1550 return NULL__null;
1551 }
1552 return canonical_path;
1553}
1554
1555void ClassLoader::create_javabase() {
1556 JavaThread* current = JavaThread::current();
1557
1558 // Create java.base's module entry for the boot
1559 // class loader prior to loading j.l.Ojbect.
1560 ClassLoaderData* null_cld = ClassLoaderData::the_null_class_loader_data();
1561
1562 // Get module entry table
1563 ModuleEntryTable* null_cld_modules = null_cld->modules();
4
'null_cld_modules' initialized here
1564 if (null_cld_modules == NULL__null) {
5
Assuming 'null_cld_modules' is equal to NULL
6
Taking true branch
1565 vm_exit_during_initialization("No ModuleEntryTable for the boot class loader");
1566 }
1567
1568 {
1569 MutexLocker ml(current, Module_lock);
1570 if (ModuleEntryTable::javabase_moduleEntry() == NULL__null) { // may have been inited by CDS.
7
Assuming the condition is true
8
Taking true branch
1571 ModuleEntry* jb_module = null_cld_modules->locked_create_entry(Handle(),
9
Called C++ object pointer is null
1572 false, vmSymbols::java_base(), NULL__null, NULL__null, null_cld);
1573 if (jb_module == NULL__null) {
1574 vm_exit_during_initialization("Unable to create ModuleEntry for " JAVA_BASE_NAME"java.base");
1575 }
1576 ModuleEntryTable::set_javabase_moduleEntry(jb_module);
1577 }
1578 }
1579}
1580
1581// Please keep following two functions at end of this file. With them placed at top or in middle of the file,
1582// they could get inlined by agressive compiler, an unknown trick, see bug 6966589.
1583void PerfClassTraceTime::initialize() {
1584 if (!UsePerfData) return;
1585
1586 if (_eventp != NULL__null) {
1587 // increment the event counter
1588 _eventp->inc();
1589 }
1590
1591 // stop the current active thread-local timer to measure inclusive time
1592 _prev_active_event = -1;
1593 for (int i=0; i < EVENT_TYPE_COUNT; i++) {
1594 if (_timers[i].is_active()) {
1595 assert(_prev_active_event == -1, "should have only one active timer")do { if (!(_prev_active_event == -1)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/classLoader.cpp"
, 1595, "assert(" "_prev_active_event == -1" ") failed", "should have only one active timer"
); ::breakpoint(); } } while (0)
;
1596 _prev_active_event = i;
1597 _timers[i].stop();
1598 }
1599 }
1600
1601 if (_recursion_counters == NULL__null || (_recursion_counters[_event_type])++ == 0) {
1602 // start the inclusive timer if not recursively called
1603 _t.start();
1604 }
1605
1606 // start thread-local timer of the given event type
1607 if (!_timers[_event_type].is_active()) {
1608 _timers[_event_type].start();
1609 }
1610}
1611
1612PerfClassTraceTime::~PerfClassTraceTime() {
1613 if (!UsePerfData) return;
1614
1615 // stop the thread-local timer as the event completes
1616 // and resume the thread-local timer of the event next on the stack
1617 _timers[_event_type].stop();
1618 jlong selftime = _timers[_event_type].ticks();
1619
1620 if (_prev_active_event >= 0) {
1621 _timers[_prev_active_event].start();
1622 }
1623
1624 if (_recursion_counters != NULL__null && --(_recursion_counters[_event_type]) > 0) return;
1625
1626 // increment the counters only on the leaf call
1627 _t.stop();
1628 _timep->inc(_t.ticks());
1629 if (_selftimep != NULL__null) {
1630 _selftimep->inc(selftime);
1631 }
1632 // add all class loading related event selftime to the accumulated time counter
1633 ClassLoader::perf_accumulated_time()->inc(selftime);
1634
1635 // reset the timer
1636 _timers[_event_type].reset();
1637}