Mercurial > hg > truffle
annotate src/share/vm/classfile/classLoader.cpp @ 5073:2db1ad9dd385
rename PiNode.value to PiNode.object and UnsafeCastNode.x to UnsafeCastNode.object
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Wed, 14 Mar 2012 16:57:18 +0100 |
parents | 532be189cf09 |
children | 957c266d8bc5 |
rev | line source |
---|---|
0 | 1 /* |
2426
1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
2323
diff
changeset
|
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1188
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1188
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1188
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/classFileParser.hpp" | |
27 #include "classfile/classFileStream.hpp" | |
28 #include "classfile/classLoader.hpp" | |
29 #include "classfile/javaClasses.hpp" | |
30 #include "classfile/systemDictionary.hpp" | |
31 #include "classfile/vmSymbols.hpp" | |
32 #include "compiler/compileBroker.hpp" | |
33 #include "gc_interface/collectedHeap.inline.hpp" | |
34 #include "interpreter/bytecodeStream.hpp" | |
35 #include "interpreter/oopMapCache.hpp" | |
36 #include "memory/allocation.inline.hpp" | |
37 #include "memory/generation.hpp" | |
38 #include "memory/oopFactory.hpp" | |
39 #include "memory/universe.inline.hpp" | |
40 #include "oops/constantPoolKlass.hpp" | |
41 #include "oops/instanceKlass.hpp" | |
42 #include "oops/instanceRefKlass.hpp" | |
43 #include "oops/oop.inline.hpp" | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2139
diff
changeset
|
44 #include "oops/symbol.hpp" |
1972 | 45 #include "prims/jvm_misc.hpp" |
46 #include "runtime/arguments.hpp" | |
47 #include "runtime/compilationPolicy.hpp" | |
48 #include "runtime/fprofiler.hpp" | |
49 #include "runtime/handles.hpp" | |
50 #include "runtime/handles.inline.hpp" | |
51 #include "runtime/init.hpp" | |
52 #include "runtime/interfaceSupport.hpp" | |
53 #include "runtime/java.hpp" | |
54 #include "runtime/javaCalls.hpp" | |
55 #include "runtime/threadCritical.hpp" | |
56 #include "runtime/timer.hpp" | |
57 #include "services/management.hpp" | |
58 #include "services/threadService.hpp" | |
59 #include "utilities/events.hpp" | |
60 #include "utilities/hashtable.hpp" | |
61 #include "utilities/hashtable.inline.hpp" | |
62 #ifdef TARGET_OS_FAMILY_linux | |
63 # include "os_linux.inline.hpp" | |
64 #endif | |
65 #ifdef TARGET_OS_FAMILY_solaris | |
66 # include "os_solaris.inline.hpp" | |
67 #endif | |
68 #ifdef TARGET_OS_FAMILY_windows | |
69 # include "os_windows.inline.hpp" | |
70 #endif | |
3960 | 71 #ifdef TARGET_OS_FAMILY_bsd |
72 # include "os_bsd.inline.hpp" | |
73 #endif | |
0 | 74 |
75 | |
76 // Entry points in zip.dll for loading zip/jar file entries | |
77 | |
78 typedef void * * (JNICALL *ZipOpen_t)(const char *name, char **pmsg); | |
79 typedef void (JNICALL *ZipClose_t)(jzfile *zip); | |
80 typedef jzentry* (JNICALL *FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen); | |
81 typedef jboolean (JNICALL *ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf); | |
82 typedef jboolean (JNICALL *ReadMappedEntry_t)(jzfile *zip, jzentry *entry, unsigned char **buf, char *namebuf); | |
83 typedef jzentry* (JNICALL *GetNextEntry_t)(jzfile *zip, jint n); | |
84 | |
85 static ZipOpen_t ZipOpen = NULL; | |
86 static ZipClose_t ZipClose = NULL; | |
87 static FindEntry_t FindEntry = NULL; | |
88 static ReadEntry_t ReadEntry = NULL; | |
89 static ReadMappedEntry_t ReadMappedEntry = NULL; | |
90 static GetNextEntry_t GetNextEntry = NULL; | |
91 static canonicalize_fn_t CanonicalizeEntry = NULL; | |
92 | |
93 // Globals | |
94 | |
95 PerfCounter* ClassLoader::_perf_accumulated_time = NULL; | |
96 PerfCounter* ClassLoader::_perf_classes_inited = NULL; | |
97 PerfCounter* ClassLoader::_perf_class_init_time = NULL; | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
98 PerfCounter* ClassLoader::_perf_class_init_selftime = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
99 PerfCounter* ClassLoader::_perf_classes_verified = NULL; |
0 | 100 PerfCounter* ClassLoader::_perf_class_verify_time = NULL; |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
101 PerfCounter* ClassLoader::_perf_class_verify_selftime = NULL; |
0 | 102 PerfCounter* ClassLoader::_perf_classes_linked = NULL; |
103 PerfCounter* ClassLoader::_perf_class_link_time = NULL; | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
104 PerfCounter* ClassLoader::_perf_class_link_selftime = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
105 PerfCounter* ClassLoader::_perf_class_parse_time = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
106 PerfCounter* ClassLoader::_perf_class_parse_selftime = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
107 PerfCounter* ClassLoader::_perf_sys_class_lookup_time = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
108 PerfCounter* ClassLoader::_perf_shared_classload_time = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
109 PerfCounter* ClassLoader::_perf_sys_classload_time = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
110 PerfCounter* ClassLoader::_perf_app_classload_time = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
111 PerfCounter* ClassLoader::_perf_app_classload_selftime = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
112 PerfCounter* ClassLoader::_perf_app_classload_count = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
113 PerfCounter* ClassLoader::_perf_define_appclasses = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
114 PerfCounter* ClassLoader::_perf_define_appclass_time = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
115 PerfCounter* ClassLoader::_perf_define_appclass_selftime = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
116 PerfCounter* ClassLoader::_perf_app_classfile_bytes_read = NULL; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
117 PerfCounter* ClassLoader::_perf_sys_classfile_bytes_read = NULL; |
0 | 118 PerfCounter* ClassLoader::_sync_systemLoaderLockContentionRate = NULL; |
119 PerfCounter* ClassLoader::_sync_nonSystemLoaderLockContentionRate = NULL; | |
120 PerfCounter* ClassLoader::_sync_JVMFindLoadedClassLockFreeCounter = NULL; | |
121 PerfCounter* ClassLoader::_sync_JVMDefineClassLockFreeCounter = NULL; | |
122 PerfCounter* ClassLoader::_sync_JNIDefineClassLockFreeCounter = NULL; | |
123 PerfCounter* ClassLoader::_unsafe_defineClassCallCounter = NULL; | |
124 PerfCounter* ClassLoader::_isUnsyncloadClass = NULL; | |
125 PerfCounter* ClassLoader::_load_instance_class_failCounter = NULL; | |
126 | |
127 ClassPathEntry* ClassLoader::_first_entry = NULL; | |
128 ClassPathEntry* ClassLoader::_last_entry = NULL; | |
129 PackageHashtable* ClassLoader::_package_hash_table = NULL; | |
130 | |
131 // helper routines | |
132 bool string_starts_with(const char* str, const char* str_to_find) { | |
133 size_t str_len = strlen(str); | |
134 size_t str_to_find_len = strlen(str_to_find); | |
135 if (str_to_find_len > str_len) { | |
136 return false; | |
137 } | |
138 return (strncmp(str, str_to_find, str_to_find_len) == 0); | |
139 } | |
140 | |
141 bool string_ends_with(const char* str, const char* str_to_find) { | |
142 size_t str_len = strlen(str); | |
143 size_t str_to_find_len = strlen(str_to_find); | |
144 if (str_to_find_len > str_len) { | |
145 return false; | |
146 } | |
147 return (strncmp(str + (str_len - str_to_find_len), str_to_find, str_to_find_len) == 0); | |
148 } | |
149 | |
150 | |
151 MetaIndex::MetaIndex(char** meta_package_names, int num_meta_package_names) { | |
152 if (num_meta_package_names == 0) { | |
153 _meta_package_names = NULL; | |
154 _num_meta_package_names = 0; | |
155 } else { | |
156 _meta_package_names = NEW_C_HEAP_ARRAY(char*, num_meta_package_names); | |
157 _num_meta_package_names = num_meta_package_names; | |
158 memcpy(_meta_package_names, meta_package_names, num_meta_package_names * sizeof(char*)); | |
159 } | |
160 } | |
161 | |
162 | |
163 MetaIndex::~MetaIndex() { | |
164 FREE_C_HEAP_ARRAY(char*, _meta_package_names); | |
165 } | |
166 | |
167 | |
168 bool MetaIndex::may_contain(const char* class_name) { | |
169 if ( _num_meta_package_names == 0) { | |
170 return false; | |
171 } | |
172 size_t class_name_len = strlen(class_name); | |
173 for (int i = 0; i < _num_meta_package_names; i++) { | |
174 char* pkg = _meta_package_names[i]; | |
175 size_t pkg_len = strlen(pkg); | |
176 size_t min_len = MIN2(class_name_len, pkg_len); | |
177 if (!strncmp(class_name, pkg, min_len)) { | |
178 return true; | |
179 } | |
180 } | |
181 return false; | |
182 } | |
183 | |
184 | |
185 ClassPathEntry::ClassPathEntry() { | |
186 set_next(NULL); | |
187 } | |
188 | |
189 | |
190 bool ClassPathEntry::is_lazy() { | |
191 return false; | |
192 } | |
193 | |
194 ClassPathDirEntry::ClassPathDirEntry(char* dir) : ClassPathEntry() { | |
195 _dir = NEW_C_HEAP_ARRAY(char, strlen(dir)+1); | |
196 strcpy(_dir, dir); | |
197 } | |
198 | |
199 | |
200 ClassFileStream* ClassPathDirEntry::open_stream(const char* name) { | |
201 // construct full path name | |
202 char path[JVM_MAXPATHLEN]; | |
203 if (jio_snprintf(path, sizeof(path), "%s%s%s", _dir, os::file_separator(), name) == -1) { | |
204 return NULL; | |
205 } | |
206 // check if file exists | |
207 struct stat st; | |
208 if (os::stat(path, &st) == 0) { | |
209 // found file, open it | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
210 int file_handle = os::open(path, 0, 0); |
0 | 211 if (file_handle != -1) { |
212 // read contents into resource array | |
213 u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size); | |
214 size_t num_read = os::read(file_handle, (char*) buffer, st.st_size); | |
215 // close file | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
216 os::close(file_handle); |
0 | 217 // construct ClassFileStream |
218 if (num_read == (size_t)st.st_size) { | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
219 if (UsePerfData) { |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
220 ClassLoader::perf_sys_classfile_bytes_read()->inc(num_read); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
221 } |
0 | 222 return new ClassFileStream(buffer, st.st_size, _dir); // Resource allocated |
223 } | |
224 } | |
225 } | |
226 return NULL; | |
227 } | |
228 | |
229 | |
230 ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name) : ClassPathEntry() { | |
231 _zip = zip; | |
232 _zip_name = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1); | |
233 strcpy(_zip_name, zip_name); | |
234 } | |
235 | |
236 ClassPathZipEntry::~ClassPathZipEntry() { | |
237 if (ZipClose != NULL) { | |
238 (*ZipClose)(_zip); | |
239 } | |
240 FREE_C_HEAP_ARRAY(char, _zip_name); | |
241 } | |
242 | |
243 ClassFileStream* ClassPathZipEntry::open_stream(const char* name) { | |
244 // enable call to C land | |
245 JavaThread* thread = JavaThread::current(); | |
246 ThreadToNativeFromVM ttn(thread); | |
247 // check whether zip archive contains name | |
248 jint filesize, name_len; | |
249 jzentry* entry = (*FindEntry)(_zip, name, &filesize, &name_len); | |
250 if (entry == NULL) return NULL; | |
251 u1* buffer; | |
252 char name_buf[128]; | |
253 char* filename; | |
254 if (name_len < 128) { | |
255 filename = name_buf; | |
256 } else { | |
257 filename = NEW_RESOURCE_ARRAY(char, name_len + 1); | |
258 } | |
259 | |
260 // file found, get pointer to class in mmaped jar file. | |
261 if (ReadMappedEntry == NULL || | |
262 !(*ReadMappedEntry)(_zip, entry, &buffer, filename)) { | |
263 // mmaped access not available, perhaps due to compression, | |
264 // read contents into resource array | |
265 buffer = NEW_RESOURCE_ARRAY(u1, filesize); | |
266 if (!(*ReadEntry)(_zip, entry, buffer, filename)) return NULL; | |
267 } | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
268 if (UsePerfData) { |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
269 ClassLoader::perf_sys_classfile_bytes_read()->inc(filesize); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
270 } |
0 | 271 // return result |
272 return new ClassFileStream(buffer, filesize, _zip_name); // Resource allocated | |
273 } | |
274 | |
275 // invoke function for each entry in the zip file | |
276 void ClassPathZipEntry::contents_do(void f(const char* name, void* context), void* context) { | |
277 JavaThread* thread = JavaThread::current(); | |
278 HandleMark handle_mark(thread); | |
279 ThreadToNativeFromVM ttn(thread); | |
280 for (int n = 0; ; n++) { | |
281 jzentry * ze = ((*GetNextEntry)(_zip, n)); | |
282 if (ze == NULL) break; | |
283 (*f)(ze->name, context); | |
284 } | |
285 } | |
286 | |
287 LazyClassPathEntry::LazyClassPathEntry(char* path, struct stat st) : ClassPathEntry() { | |
288 _path = strdup(path); | |
289 _st = st; | |
290 _meta_index = NULL; | |
291 _resolved_entry = NULL; | |
292 } | |
293 | |
294 bool LazyClassPathEntry::is_jar_file() { | |
295 return ((_st.st_mode & S_IFREG) == S_IFREG); | |
296 } | |
297 | |
298 ClassPathEntry* LazyClassPathEntry::resolve_entry() { | |
299 if (_resolved_entry != NULL) { | |
300 return (ClassPathEntry*) _resolved_entry; | |
301 } | |
302 ClassPathEntry* new_entry = NULL; | |
303 ClassLoader::create_class_path_entry(_path, _st, &new_entry, false); | |
304 assert(new_entry != NULL, "earlier code should have caught this"); | |
305 { | |
306 ThreadCritical tc; | |
307 if (_resolved_entry == NULL) { | |
308 _resolved_entry = new_entry; | |
309 return new_entry; | |
310 } | |
311 } | |
312 assert(_resolved_entry != NULL, "bug in MT-safe resolution logic"); | |
313 delete new_entry; | |
314 return (ClassPathEntry*) _resolved_entry; | |
315 } | |
316 | |
317 ClassFileStream* LazyClassPathEntry::open_stream(const char* name) { | |
318 if (_meta_index != NULL && | |
319 !_meta_index->may_contain(name)) { | |
320 return NULL; | |
321 } | |
322 return resolve_entry()->open_stream(name); | |
323 } | |
324 | |
325 bool LazyClassPathEntry::is_lazy() { | |
326 return true; | |
327 } | |
328 | |
329 static void print_meta_index(LazyClassPathEntry* entry, | |
330 GrowableArray<char*>& meta_packages) { | |
331 tty->print("[Meta index for %s=", entry->name()); | |
332 for (int i = 0; i < meta_packages.length(); i++) { | |
333 if (i > 0) tty->print(" "); | |
334 tty->print(meta_packages.at(i)); | |
335 } | |
336 tty->print_cr("]"); | |
337 } | |
338 | |
339 | |
340 void ClassLoader::setup_meta_index() { | |
341 // Set up meta index which allows us to open boot jars lazily if | |
342 // class data sharing is enabled | |
343 const char* known_version = "% VERSION 2"; | |
344 char* meta_index_path = Arguments::get_meta_index_path(); | |
345 char* meta_index_dir = Arguments::get_meta_index_dir(); | |
346 FILE* file = fopen(meta_index_path, "r"); | |
347 int line_no = 0; | |
348 if (file != NULL) { | |
349 ResourceMark rm; | |
350 LazyClassPathEntry* cur_entry = NULL; | |
351 GrowableArray<char*> boot_class_path_packages(10); | |
352 char package_name[256]; | |
353 bool skipCurrentJar = false; | |
354 while (fgets(package_name, sizeof(package_name), file) != NULL) { | |
355 ++line_no; | |
356 // Remove trailing newline | |
357 package_name[strlen(package_name) - 1] = '\0'; | |
358 switch(package_name[0]) { | |
359 case '%': | |
360 { | |
361 if ((line_no == 1) && (strcmp(package_name, known_version) != 0)) { | |
362 if (TraceClassLoading && Verbose) { | |
363 tty->print("[Unsupported meta index version]"); | |
364 } | |
365 fclose(file); | |
366 return; | |
367 } | |
368 } | |
369 | |
370 // These directives indicate jar files which contain only | |
371 // classes, only non-classfile resources, or a combination of | |
372 // the two. See src/share/classes/sun/misc/MetaIndex.java and | |
373 // make/tools/MetaIndex/BuildMetaIndex.java in the J2SE | |
374 // workspace. | |
375 case '#': | |
376 case '!': | |
377 case '@': | |
378 { | |
379 // Hand off current packages to current lazy entry (if any) | |
380 if ((cur_entry != NULL) && | |
381 (boot_class_path_packages.length() > 0)) { | |
382 if (TraceClassLoading && Verbose) { | |
383 print_meta_index(cur_entry, boot_class_path_packages); | |
384 } | |
385 MetaIndex* index = new MetaIndex(boot_class_path_packages.adr_at(0), | |
386 boot_class_path_packages.length()); | |
387 cur_entry->set_meta_index(index); | |
388 } | |
389 cur_entry = NULL; | |
390 boot_class_path_packages.clear(); | |
391 | |
392 // Find lazy entry corresponding to this jar file | |
393 for (ClassPathEntry* entry = _first_entry; entry != NULL; entry = entry->next()) { | |
394 if (entry->is_lazy() && | |
395 string_starts_with(entry->name(), meta_index_dir) && | |
396 string_ends_with(entry->name(), &package_name[2])) { | |
397 cur_entry = (LazyClassPathEntry*) entry; | |
398 break; | |
399 } | |
400 } | |
401 | |
402 // If the first character is '@', it indicates the following jar | |
403 // file is a resource only jar file in which case, we should skip | |
404 // reading the subsequent entries since the resource loading is | |
405 // totally handled by J2SE side. | |
406 if (package_name[0] == '@') { | |
407 if (cur_entry != NULL) { | |
408 cur_entry->set_meta_index(new MetaIndex(NULL, 0)); | |
409 } | |
410 cur_entry = NULL; | |
411 skipCurrentJar = true; | |
412 } else { | |
413 skipCurrentJar = false; | |
414 } | |
415 | |
416 break; | |
417 } | |
418 | |
419 default: | |
420 { | |
421 if (!skipCurrentJar && cur_entry != NULL) { | |
422 char* new_name = strdup(package_name); | |
423 boot_class_path_packages.append(new_name); | |
424 } | |
425 } | |
426 } | |
427 } | |
428 // Hand off current packages to current lazy entry (if any) | |
429 if ((cur_entry != NULL) && | |
430 (boot_class_path_packages.length() > 0)) { | |
431 if (TraceClassLoading && Verbose) { | |
432 print_meta_index(cur_entry, boot_class_path_packages); | |
433 } | |
434 MetaIndex* index = new MetaIndex(boot_class_path_packages.adr_at(0), | |
435 boot_class_path_packages.length()); | |
436 cur_entry->set_meta_index(index); | |
437 } | |
438 fclose(file); | |
439 } | |
440 } | |
441 | |
442 void ClassLoader::setup_bootstrap_search_path() { | |
443 assert(_first_entry == NULL, "should not setup bootstrap class search path twice"); | |
444 char* sys_class_path = os::strdup(Arguments::get_sysclasspath()); | |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
445 #ifdef GRAAL |
3546
4aa80ca3dbec
Separate compiler bootstrappath from application bootstrappath.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2491
diff
changeset
|
446 char* compiler_class_path = os::strdup(Arguments::get_compilerclasspath()); |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
447 #endif |
0 | 448 if (TraceClassLoading && Verbose) { |
449 tty->print_cr("[Bootstrap loader class path=%s]", sys_class_path); | |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
450 #ifdef GRAAL |
3546
4aa80ca3dbec
Separate compiler bootstrappath from application bootstrappath.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2491
diff
changeset
|
451 tty->print_cr("[Compiler loader class path=%s]", compiler_class_path); |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
452 #endif |
0 | 453 } |
454 | |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
455 setup_bootstrap_search_path(sys_class_path); |
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
456 #ifdef GRAAL |
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
457 setup_bootstrap_search_path(compiler_class_path); |
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
458 #endif |
3546
4aa80ca3dbec
Separate compiler bootstrappath from application bootstrappath.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2491
diff
changeset
|
459 } |
4aa80ca3dbec
Separate compiler bootstrappath from application bootstrappath.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2491
diff
changeset
|
460 |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
461 void ClassLoader::setup_bootstrap_search_path(char* sys_class_path) { |
0 | 462 int len = (int)strlen(sys_class_path); |
463 int end = 0; | |
464 | |
465 // Iterate over class path entries | |
466 for (int start = 0; start < len; start = end) { | |
467 while (sys_class_path[end] && sys_class_path[end] != os::path_separator()[0]) { | |
468 end++; | |
469 } | |
470 char* path = NEW_C_HEAP_ARRAY(char, end-start+1); | |
471 strncpy(path, &sys_class_path[start], end-start); | |
472 path[end-start] = '\0'; | |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
473 update_class_path_entry_list(path, false); |
0 | 474 FREE_C_HEAP_ARRAY(char, path); |
475 while (sys_class_path[end] == os::path_separator()[0]) { | |
476 end++; | |
477 } | |
478 } | |
479 } | |
480 | |
481 void ClassLoader::create_class_path_entry(char *path, struct stat st, ClassPathEntry **new_entry, bool lazy) { | |
482 JavaThread* thread = JavaThread::current(); | |
483 if (lazy) { | |
484 *new_entry = new LazyClassPathEntry(path, st); | |
485 return; | |
486 } | |
487 if ((st.st_mode & S_IFREG) == S_IFREG) { | |
488 // Regular file, should be a zip file | |
489 // Canonicalized filename | |
490 char canonical_path[JVM_MAXPATHLEN]; | |
491 if (!get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) { | |
492 // This matches the classic VM | |
493 EXCEPTION_MARK; | |
494 THROW_MSG(vmSymbols::java_io_IOException(), "Bad pathname"); | |
495 } | |
496 char* error_msg = NULL; | |
497 jzfile* zip; | |
498 { | |
499 // enable call to C land | |
500 ThreadToNativeFromVM ttn(thread); | |
501 HandleMark hm(thread); | |
502 zip = (*ZipOpen)(canonical_path, &error_msg); | |
503 } | |
504 if (zip != NULL && error_msg == NULL) { | |
505 *new_entry = new ClassPathZipEntry(zip, path); | |
506 if (TraceClassLoading) { | |
507 tty->print_cr("[Opened %s]", path); | |
508 } | |
509 } else { | |
510 ResourceMark rm(thread); | |
511 char *msg; | |
512 if (error_msg == NULL) { | |
513 msg = NEW_RESOURCE_ARRAY(char, strlen(path) + 128); ; | |
514 jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path); | |
515 } else { | |
516 int len = (int)(strlen(path) + strlen(error_msg) + 128); | |
517 msg = NEW_RESOURCE_ARRAY(char, len); ; | |
518 jio_snprintf(msg, len - 1, "error in opening JAR file <%s> %s", error_msg, path); | |
519 } | |
520 EXCEPTION_MARK; | |
521 THROW_MSG(vmSymbols::java_lang_ClassNotFoundException(), msg); | |
522 } | |
523 } else { | |
524 // Directory | |
525 *new_entry = new ClassPathDirEntry(path); | |
526 if (TraceClassLoading) { | |
527 tty->print_cr("[Path %s]", path); | |
528 } | |
529 } | |
530 } | |
531 | |
532 | |
533 // Create a class path zip entry for a given path (return NULL if not found | |
534 // or zip/JAR file cannot be opened) | |
535 ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path) { | |
536 // check for a regular file | |
537 struct stat st; | |
538 if (os::stat(path, &st) == 0) { | |
539 if ((st.st_mode & S_IFREG) == S_IFREG) { | |
540 char orig_path[JVM_MAXPATHLEN]; | |
541 char canonical_path[JVM_MAXPATHLEN]; | |
542 | |
543 strcpy(orig_path, path); | |
544 if (get_canonical_path(orig_path, canonical_path, JVM_MAXPATHLEN)) { | |
545 char* error_msg = NULL; | |
546 jzfile* zip; | |
547 { | |
548 // enable call to C land | |
549 JavaThread* thread = JavaThread::current(); | |
550 ThreadToNativeFromVM ttn(thread); | |
551 HandleMark hm(thread); | |
552 zip = (*ZipOpen)(canonical_path, &error_msg); | |
553 } | |
554 if (zip != NULL && error_msg == NULL) { | |
555 // create using canonical path | |
556 return new ClassPathZipEntry(zip, canonical_path); | |
557 } | |
558 } | |
559 } | |
560 } | |
561 return NULL; | |
562 } | |
563 | |
564 // returns true if entry already on class path | |
565 bool ClassLoader::contains_entry(ClassPathEntry *entry) { | |
566 ClassPathEntry* e = _first_entry; | |
567 while (e != NULL) { | |
568 // assume zip entries have been canonicalized | |
4977
532be189cf09
Reducing diff to hsx24
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4559
diff
changeset
|
569 if (strcmp(entry->name(), e->name()) == 0) { |
0 | 570 return true; |
571 } | |
572 e = e->next(); | |
573 } | |
574 return false; | |
575 } | |
576 | |
577 void ClassLoader::add_to_list(ClassPathEntry *new_entry) { | |
578 if (new_entry != NULL) { | |
579 if (_last_entry == NULL) { | |
580 _first_entry = _last_entry = new_entry; | |
581 } else { | |
582 _last_entry->set_next(new_entry); | |
583 _last_entry = new_entry; | |
584 } | |
585 } | |
586 } | |
587 | |
588 void ClassLoader::update_class_path_entry_list(const char *path, | |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
589 bool check_for_duplicates) { |
0 | 590 struct stat st; |
591 if (os::stat((char *)path, &st) == 0) { | |
592 // File or directory found | |
593 ClassPathEntry* new_entry = NULL; | |
594 create_class_path_entry((char *)path, st, &new_entry, LazyBootClassLoader); | |
595 // The kernel VM adds dynamically to the end of the classloader path and | |
596 // doesn't reorder the bootclasspath which would break java.lang.Package | |
597 // (see PackageInfo). | |
598 // Add new entry to linked list | |
599 if (!check_for_duplicates || !contains_entry(new_entry)) { | |
600 add_to_list(new_entry); | |
601 } | |
602 } | |
603 } | |
604 | |
605 void ClassLoader::print_bootclasspath() { | |
606 ClassPathEntry* e = _first_entry; | |
607 tty->print("[bootclasspath= "); | |
608 while (e != NULL) { | |
609 tty->print("%s ;", e->name()); | |
610 e = e->next(); | |
611 } | |
612 tty->print_cr("]"); | |
613 } | |
614 | |
615 void ClassLoader::load_zip_library() { | |
616 assert(ZipOpen == NULL, "should not load zip library twice"); | |
617 // First make sure native library is loaded | |
618 os::native_java_library(); | |
619 // Load zip library | |
620 char path[JVM_MAXPATHLEN]; | |
621 char ebuf[1024]; | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
622 os::dll_build_name(path, sizeof(path), Arguments::get_dll_dir(), "zip"); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
623 void* handle = os::dll_load(path, ebuf, sizeof ebuf); |
0 | 624 if (handle == NULL) { |
625 vm_exit_during_initialization("Unable to load ZIP library", path); | |
626 } | |
627 // Lookup zip entry points | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
628 ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, os::dll_lookup(handle, "ZIP_Open")); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
629 ZipClose = CAST_TO_FN_PTR(ZipClose_t, os::dll_lookup(handle, "ZIP_Close")); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
630 FindEntry = CAST_TO_FN_PTR(FindEntry_t, os::dll_lookup(handle, "ZIP_FindEntry")); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
631 ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, os::dll_lookup(handle, "ZIP_ReadEntry")); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
632 ReadMappedEntry = CAST_TO_FN_PTR(ReadMappedEntry_t, os::dll_lookup(handle, "ZIP_ReadMappedEntry")); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
633 GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, os::dll_lookup(handle, "ZIP_GetNextEntry")); |
0 | 634 |
635 // ZIP_Close is not exported on Windows in JDK5.0 so don't abort if ZIP_Close is NULL | |
636 if (ZipOpen == NULL || FindEntry == NULL || ReadEntry == NULL || GetNextEntry == NULL) { | |
637 vm_exit_during_initialization("Corrupted ZIP library", path); | |
638 } | |
639 | |
640 // Lookup canonicalize entry in libjava.dll | |
641 void *javalib_handle = os::native_java_library(); | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
642 CanonicalizeEntry = CAST_TO_FN_PTR(canonicalize_fn_t, os::dll_lookup(javalib_handle, "Canonicalize")); |
0 | 643 // This lookup only works on 1.3. Do not check for non-null here |
644 } | |
645 | |
646 // PackageInfo data exists in order to support the java.lang.Package | |
647 // class. A Package object provides information about a java package | |
648 // (version, vendor, etc.) which originates in the manifest of the jar | |
649 // file supplying the package. For application classes, the ClassLoader | |
650 // object takes care of this. | |
651 | |
652 // For system (boot) classes, the Java code in the Package class needs | |
653 // to be able to identify which source jar file contained the boot | |
654 // class, so that it can extract the manifest from it. This table | |
655 // identifies java packages with jar files in the boot classpath. | |
656 | |
657 // Because the boot classpath cannot change, the classpath index is | |
658 // sufficient to identify the source jar file or directory. (Since | |
659 // directories have no manifests, the directory name is not required, | |
660 // but is available.) | |
661 | |
662 // When using sharing -- the pathnames of entries in the boot classpath | |
663 // may not be the same at runtime as they were when the archive was | |
664 // created (NFS, Samba, etc.). The actual files and directories named | |
665 // in the classpath must be the same files, in the same order, even | |
666 // though the exact name is not the same. | |
667 | |
668 class PackageInfo: public BasicHashtableEntry { | |
669 public: | |
670 const char* _pkgname; // Package name | |
671 int _classpath_index; // Index of directory or JAR file loaded from | |
672 | |
673 PackageInfo* next() { | |
674 return (PackageInfo*)BasicHashtableEntry::next(); | |
675 } | |
676 | |
677 const char* pkgname() { return _pkgname; } | |
678 void set_pkgname(char* pkgname) { _pkgname = pkgname; } | |
679 | |
680 const char* filename() { | |
681 return ClassLoader::classpath_entry(_classpath_index)->name(); | |
682 } | |
683 | |
684 void set_index(int index) { | |
685 _classpath_index = index; | |
686 } | |
687 }; | |
688 | |
689 | |
690 class PackageHashtable : public BasicHashtable { | |
691 private: | |
692 inline unsigned int compute_hash(const char *s, int n) { | |
693 unsigned int val = 0; | |
694 while (--n >= 0) { | |
695 val = *s++ + 31 * val; | |
696 } | |
697 return val; | |
698 } | |
699 | |
700 PackageInfo* bucket(int index) { | |
701 return (PackageInfo*)BasicHashtable::bucket(index); | |
702 } | |
703 | |
704 PackageInfo* get_entry(int index, unsigned int hash, | |
705 const char* pkgname, size_t n) { | |
706 for (PackageInfo* pp = bucket(index); pp != NULL; pp = pp->next()) { | |
707 if (pp->hash() == hash && | |
708 strncmp(pkgname, pp->pkgname(), n) == 0 && | |
709 pp->pkgname()[n] == '\0') { | |
710 return pp; | |
711 } | |
712 } | |
713 return NULL; | |
714 } | |
715 | |
716 public: | |
717 PackageHashtable(int table_size) | |
718 : BasicHashtable(table_size, sizeof(PackageInfo)) {} | |
719 | |
720 PackageHashtable(int table_size, HashtableBucket* t, int number_of_entries) | |
721 : BasicHashtable(table_size, sizeof(PackageInfo), t, number_of_entries) {} | |
722 | |
723 PackageInfo* get_entry(const char* pkgname, int n) { | |
724 unsigned int hash = compute_hash(pkgname, n); | |
725 return get_entry(hash_to_index(hash), hash, pkgname, n); | |
726 } | |
727 | |
728 PackageInfo* new_entry(char* pkgname, int n) { | |
729 unsigned int hash = compute_hash(pkgname, n); | |
730 PackageInfo* pp; | |
731 pp = (PackageInfo*)BasicHashtable::new_entry(hash); | |
732 pp->set_pkgname(pkgname); | |
733 return pp; | |
734 } | |
735 | |
736 void add_entry(PackageInfo* pp) { | |
737 int index = hash_to_index(pp->hash()); | |
738 BasicHashtable::add_entry(index, pp); | |
739 } | |
740 | |
741 void copy_pkgnames(const char** packages) { | |
742 int n = 0; | |
743 for (int i = 0; i < table_size(); ++i) { | |
744 for (PackageInfo* pp = bucket(i); pp != NULL; pp = pp->next()) { | |
745 packages[n++] = pp->pkgname(); | |
746 } | |
747 } | |
748 assert(n == number_of_entries(), "just checking"); | |
749 } | |
750 | |
751 void copy_table(char** top, char* end, PackageHashtable* table); | |
752 }; | |
753 | |
754 | |
755 void PackageHashtable::copy_table(char** top, char* end, | |
756 PackageHashtable* table) { | |
757 // Copy (relocate) the table to the shared space. | |
758 BasicHashtable::copy_table(top, end); | |
759 | |
760 // Calculate the space needed for the package name strings. | |
761 int i; | |
762 int n = 0; | |
763 for (i = 0; i < table_size(); ++i) { | |
764 for (PackageInfo* pp = table->bucket(i); | |
765 pp != NULL; | |
766 pp = pp->next()) { | |
767 n += (int)(strlen(pp->pkgname()) + 1); | |
768 } | |
769 } | |
770 if (*top + n + sizeof(intptr_t) >= end) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2139
diff
changeset
|
771 report_out_of_shared_space(SharedMiscData); |
0 | 772 } |
773 | |
774 // Copy the table data (the strings) to the shared space. | |
775 n = align_size_up(n, sizeof(HeapWord)); | |
776 *(intptr_t*)(*top) = n; | |
777 *top += sizeof(intptr_t); | |
778 | |
779 for (i = 0; i < table_size(); ++i) { | |
780 for (PackageInfo* pp = table->bucket(i); | |
781 pp != NULL; | |
782 pp = pp->next()) { | |
783 int n1 = (int)(strlen(pp->pkgname()) + 1); | |
784 pp->set_pkgname((char*)memcpy(*top, pp->pkgname(), n1)); | |
785 *top += n1; | |
786 } | |
787 } | |
788 *top = (char*)align_size_up((intptr_t)*top, sizeof(HeapWord)); | |
789 } | |
790 | |
791 | |
792 void ClassLoader::copy_package_info_buckets(char** top, char* end) { | |
793 _package_hash_table->copy_buckets(top, end); | |
794 } | |
795 | |
796 void ClassLoader::copy_package_info_table(char** top, char* end) { | |
797 _package_hash_table->copy_table(top, end, _package_hash_table); | |
798 } | |
799 | |
800 | |
801 PackageInfo* ClassLoader::lookup_package(const char *pkgname) { | |
802 const char *cp = strrchr(pkgname, '/'); | |
803 if (cp != NULL) { | |
804 // Package prefix found | |
805 int n = cp - pkgname + 1; | |
806 return _package_hash_table->get_entry(pkgname, n); | |
807 } | |
808 return NULL; | |
809 } | |
810 | |
811 | |
812 bool ClassLoader::add_package(const char *pkgname, int classpath_index, TRAPS) { | |
813 assert(pkgname != NULL, "just checking"); | |
814 // Bootstrap loader no longer holds system loader lock obj serializing | |
815 // load_instance_class and thereby add_package | |
816 { | |
817 MutexLocker ml(PackageTable_lock, THREAD); | |
818 // First check for previously loaded entry | |
819 PackageInfo* pp = lookup_package(pkgname); | |
820 if (pp != NULL) { | |
821 // Existing entry found, check source of package | |
822 pp->set_index(classpath_index); | |
823 return true; | |
824 } | |
825 | |
826 const char *cp = strrchr(pkgname, '/'); | |
827 if (cp != NULL) { | |
828 // Package prefix found | |
829 int n = cp - pkgname + 1; | |
830 | |
831 char* new_pkgname = NEW_C_HEAP_ARRAY(char, n + 1); | |
832 if (new_pkgname == NULL) { | |
833 return false; | |
834 } | |
835 | |
836 memcpy(new_pkgname, pkgname, n); | |
837 new_pkgname[n] = '\0'; | |
838 pp = _package_hash_table->new_entry(new_pkgname, n); | |
839 pp->set_index(classpath_index); | |
840 | |
841 // Insert into hash table | |
842 _package_hash_table->add_entry(pp); | |
843 } | |
844 return true; | |
845 } | |
846 } | |
847 | |
848 | |
849 oop ClassLoader::get_system_package(const char* name, TRAPS) { | |
850 PackageInfo* pp; | |
851 { | |
852 MutexLocker ml(PackageTable_lock, THREAD); | |
853 pp = lookup_package(name); | |
854 } | |
855 if (pp == NULL) { | |
856 return NULL; | |
857 } else { | |
858 Handle p = java_lang_String::create_from_str(pp->filename(), THREAD); | |
859 return p(); | |
860 } | |
861 } | |
862 | |
863 | |
864 objArrayOop ClassLoader::get_system_packages(TRAPS) { | |
865 ResourceMark rm(THREAD); | |
866 int nof_entries; | |
867 const char** packages; | |
868 { | |
869 MutexLocker ml(PackageTable_lock, THREAD); | |
870 // Allocate resource char* array containing package names | |
871 nof_entries = _package_hash_table->number_of_entries(); | |
872 if ((packages = NEW_RESOURCE_ARRAY(const char*, nof_entries)) == NULL) { | |
873 return NULL; | |
874 } | |
875 _package_hash_table->copy_pkgnames(packages); | |
876 } | |
877 // Allocate objArray and fill with java.lang.String | |
1142 | 878 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(), |
0 | 879 nof_entries, CHECK_0); |
880 objArrayHandle result(THREAD, r); | |
881 for (int i = 0; i < nof_entries; i++) { | |
882 Handle str = java_lang_String::create_from_str(packages[i], CHECK_0); | |
883 result->obj_at_put(i, str()); | |
884 } | |
885 | |
886 return result(); | |
887 } | |
888 | |
889 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2139
diff
changeset
|
890 instanceKlassHandle ClassLoader::load_classfile(Symbol* h_name, TRAPS) { |
0 | 891 ResourceMark rm(THREAD); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2139
diff
changeset
|
892 EventMark m("loading class " INTPTR_FORMAT, (address)h_name); |
0 | 893 ThreadProfilerMark tpm(ThreadProfilerMark::classLoaderRegion); |
894 | |
895 stringStream st; | |
896 // st.print() uses too much stack space while handling a StackOverflowError | |
897 // st.print("%s.class", h_name->as_utf8()); | |
898 st.print_raw(h_name->as_utf8()); | |
899 st.print_raw(".class"); | |
900 char* name = st.as_string(); | |
901 | |
902 // Lookup stream for parsing .class file | |
903 ClassFileStream* stream = NULL; | |
904 int classpath_index = 0; | |
905 { | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
906 PerfClassTraceTime vmtimer(perf_sys_class_lookup_time(), |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
907 ((JavaThread*) THREAD)->get_thread_stat()->perf_timers_addr(), |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
908 PerfClassTraceTime::CLASS_LOAD); |
3546
4aa80ca3dbec
Separate compiler bootstrappath from application bootstrappath.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2491
diff
changeset
|
909 ClassPathEntry* e = _first_entry; |
0 | 910 while (e != NULL) { |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
911 stream = e->open_stream(name); |
0 | 912 if (stream != NULL) { |
913 break; | |
914 } | |
915 e = e->next(); | |
916 ++classpath_index; | |
917 } | |
918 } | |
919 | |
3555
22d11b3bc561
Various hacks to be able to install machine code from a Java thread.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
3546
diff
changeset
|
920 if (stream == NULL && !(THREAD->is_Compiler_thread())) { |
22d11b3bc561
Various hacks to be able to install machine code from a Java thread.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
3546
diff
changeset
|
921 classpath_index = 0; |
22d11b3bc561
Various hacks to be able to install machine code from a Java thread.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
3546
diff
changeset
|
922 PerfClassTraceTime vmtimer(perf_sys_class_lookup_time(), |
22d11b3bc561
Various hacks to be able to install machine code from a Java thread.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
3546
diff
changeset
|
923 ((JavaThread*) THREAD)->get_thread_stat()->perf_timers_addr(), |
22d11b3bc561
Various hacks to be able to install machine code from a Java thread.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
3546
diff
changeset
|
924 PerfClassTraceTime::CLASS_LOAD); |
22d11b3bc561
Various hacks to be able to install machine code from a Java thread.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
3546
diff
changeset
|
925 ClassPathEntry* e = _first_entry; |
0 | 926 while (e != NULL) { |
927 stream = e->open_stream(name); | |
928 if (stream != NULL) { | |
929 break; | |
930 } | |
931 e = e->next(); | |
932 ++classpath_index; | |
933 } | |
934 } | |
935 | |
936 instanceKlassHandle h(THREAD, klassOop(NULL)); | |
937 if (stream != NULL) { | |
938 | |
939 // class file found, parse it | |
940 ClassFileParser parser(stream); | |
941 Handle class_loader; | |
942 Handle protection_domain; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2139
diff
changeset
|
943 TempNewSymbol parsed_name = NULL; |
0 | 944 instanceKlassHandle result = parser.parseClassFile(h_name, |
945 class_loader, | |
946 protection_domain, | |
947 parsed_name, | |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
882
diff
changeset
|
948 false, |
0 | 949 CHECK_(h)); |
950 | |
951 // add to package table | |
952 if (add_package(name, classpath_index, THREAD)) { | |
953 h = result; | |
954 } | |
955 } | |
956 | |
957 return h; | |
958 } | |
959 | |
960 | |
961 void ClassLoader::create_package_info_table(HashtableBucket *t, int length, | |
962 int number_of_entries) { | |
963 assert(_package_hash_table == NULL, "One package info table allowed."); | |
964 assert(length == package_hash_table_size * sizeof(HashtableBucket), | |
965 "bad shared package info size."); | |
966 _package_hash_table = new PackageHashtable(package_hash_table_size, t, | |
967 number_of_entries); | |
968 } | |
969 | |
970 | |
971 void ClassLoader::create_package_info_table() { | |
972 assert(_package_hash_table == NULL, "shouldn't have one yet"); | |
973 _package_hash_table = new PackageHashtable(package_hash_table_size); | |
974 } | |
975 | |
976 | |
977 // Initialize the class loader's access to methods in libzip. Parse and | |
978 // process the boot classpath into a list ClassPathEntry objects. Once | |
979 // this list has been created, it must not change order (see class PackageInfo) | |
980 // it can be appended to and is by jvmti and the kernel vm. | |
981 | |
982 void ClassLoader::initialize() { | |
983 assert(_package_hash_table == NULL, "should have been initialized by now."); | |
984 EXCEPTION_MARK; | |
985 | |
986 if (UsePerfData) { | |
987 // jvmstat performance counters | |
988 NEWPERFTICKCOUNTER(_perf_accumulated_time, SUN_CLS, "time"); | |
989 NEWPERFTICKCOUNTER(_perf_class_init_time, SUN_CLS, "classInitTime"); | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
990 NEWPERFTICKCOUNTER(_perf_class_init_selftime, SUN_CLS, "classInitTime.self"); |
0 | 991 NEWPERFTICKCOUNTER(_perf_class_verify_time, SUN_CLS, "classVerifyTime"); |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
992 NEWPERFTICKCOUNTER(_perf_class_verify_selftime, SUN_CLS, "classVerifyTime.self"); |
0 | 993 NEWPERFTICKCOUNTER(_perf_class_link_time, SUN_CLS, "classLinkedTime"); |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
994 NEWPERFTICKCOUNTER(_perf_class_link_selftime, SUN_CLS, "classLinkedTime.self"); |
0 | 995 NEWPERFEVENTCOUNTER(_perf_classes_inited, SUN_CLS, "initializedClasses"); |
996 NEWPERFEVENTCOUNTER(_perf_classes_linked, SUN_CLS, "linkedClasses"); | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
997 NEWPERFEVENTCOUNTER(_perf_classes_verified, SUN_CLS, "verifiedClasses"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
998 |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
999 NEWPERFTICKCOUNTER(_perf_class_parse_time, SUN_CLS, "parseClassTime"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1000 NEWPERFTICKCOUNTER(_perf_class_parse_selftime, SUN_CLS, "parseClassTime.self"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1001 NEWPERFTICKCOUNTER(_perf_sys_class_lookup_time, SUN_CLS, "lookupSysClassTime"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1002 NEWPERFTICKCOUNTER(_perf_shared_classload_time, SUN_CLS, "sharedClassLoadTime"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1003 NEWPERFTICKCOUNTER(_perf_sys_classload_time, SUN_CLS, "sysClassLoadTime"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1004 NEWPERFTICKCOUNTER(_perf_app_classload_time, SUN_CLS, "appClassLoadTime"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1005 NEWPERFTICKCOUNTER(_perf_app_classload_selftime, SUN_CLS, "appClassLoadTime.self"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1006 NEWPERFEVENTCOUNTER(_perf_app_classload_count, SUN_CLS, "appClassLoadCount"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1007 NEWPERFTICKCOUNTER(_perf_define_appclasses, SUN_CLS, "defineAppClasses"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1008 NEWPERFTICKCOUNTER(_perf_define_appclass_time, SUN_CLS, "defineAppClassTime"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1009 NEWPERFTICKCOUNTER(_perf_define_appclass_selftime, SUN_CLS, "defineAppClassTime.self"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1010 NEWPERFBYTECOUNTER(_perf_app_classfile_bytes_read, SUN_CLS, "appClassBytes"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1011 NEWPERFBYTECOUNTER(_perf_sys_classfile_bytes_read, SUN_CLS, "sysClassBytes"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
723
diff
changeset
|
1012 |
0 | 1013 |
1014 // The following performance counters are added for measuring the impact | |
1015 // of the bug fix of 6365597. They are mainly focused on finding out | |
1016 // the behavior of system & user-defined classloader lock, whether | |
1017 // ClassLoader.loadClass/findClass is being called synchronized or not. | |
1018 // Also two additional counters are created to see whether 'UnsyncloadClass' | |
1019 // flag is being set or not and how many times load_instance_class call | |
1020 // fails with linkageError etc. | |
1021 NEWPERFEVENTCOUNTER(_sync_systemLoaderLockContentionRate, SUN_CLS, | |
1022 "systemLoaderLockContentionRate"); | |
1023 NEWPERFEVENTCOUNTER(_sync_nonSystemLoaderLockContentionRate, SUN_CLS, | |
1024 "nonSystemLoaderLockContentionRate"); | |
1025 NEWPERFEVENTCOUNTER(_sync_JVMFindLoadedClassLockFreeCounter, SUN_CLS, | |
1026 "jvmFindLoadedClassNoLockCalls"); | |
1027 NEWPERFEVENTCOUNTER(_sync_JVMDefineClassLockFreeCounter, SUN_CLS, | |
1028 "jvmDefineClassNoLockCalls"); | |
1029 | |
1030 NEWPERFEVENTCOUNTER(_sync_JNIDefineClassLockFreeCounter, SUN_CLS, | |
1031 "jniDefineClassNoLockCalls"); | |
1032 | |
1033 NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS, | |
1034 "unsafeDefineClassCalls"); | |
1035 | |
1036 NEWPERFEVENTCOUNTER(_isUnsyncloadClass, SUN_CLS, "isUnsyncloadClassSet"); | |
1037 NEWPERFEVENTCOUNTER(_load_instance_class_failCounter, SUN_CLS, | |
1038 "loadInstanceClassFailRate"); | |
1039 | |
1040 // increment the isUnsyncloadClass counter if UnsyncloadClass is set. | |
1041 if (UnsyncloadClass) { | |
1042 _isUnsyncloadClass->inc(); | |
1043 } | |
1044 } | |
1045 | |
1046 // lookup zip library entry points | |
1047 load_zip_library(); | |
1048 // initialize search path | |
1049 setup_bootstrap_search_path(); | |
1050 if (LazyBootClassLoader) { | |
1051 // set up meta index which makes boot classpath initialization lazier | |
1052 setup_meta_index(); | |
1053 } | |
1054 } | |
1055 | |
1056 | |
1057 jlong ClassLoader::classloader_time_ms() { | |
1058 return UsePerfData ? | |
1059 Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1; | |
1060 } | |
1061 | |
1062 jlong ClassLoader::class_init_count() { | |
1063 return UsePerfData ? _perf_classes_inited->get_value() : -1; | |
1064 } | |
1065 | |
1066 jlong ClassLoader::class_init_time_ms() { | |
1067 return UsePerfData ? | |
1068 Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1; | |
1069 } | |
1070 | |
1071 jlong ClassLoader::class_verify_time_ms() { | |
1072 return UsePerfData ? | |
1073 Management::ticks_to_ms(_perf_class_verify_time->get_value()) : -1; | |
1074 } | |
1075 | |
1076 jlong ClassLoader::class_link_count() { | |
1077 return UsePerfData ? _perf_classes_linked->get_value() : -1; | |
1078 } | |
1079 | |
1080 jlong ClassLoader::class_link_time_ms() { | |
1081 return UsePerfData ? | |
1082 Management::ticks_to_ms(_perf_class_link_time->get_value()) : -1; | |
1083 } | |
1084 | |
1085 int ClassLoader::compute_Object_vtable() { | |
1086 // hardwired for JDK1.2 -- would need to duplicate class file parsing | |
1087 // code to determine actual value from file | |
1088 // Would be value '11' if finals were in vtable | |
1089 int JDK_1_2_Object_vtable_size = 5; | |
1090 return JDK_1_2_Object_vtable_size * vtableEntry::size(); | |
1091 } | |
1092 | |
1093 | |
1094 void classLoader_init() { | |
1095 ClassLoader::initialize(); | |
1096 } | |
1097 | |
1098 | |
1099 bool ClassLoader::get_canonical_path(char* orig, char* out, int len) { | |
1100 assert(orig != NULL && out != NULL && len > 0, "bad arguments"); | |
1101 if (CanonicalizeEntry != NULL) { | |
1102 JNIEnv* env = JavaThread::current()->jni_environment(); | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1103 if ((CanonicalizeEntry)(env, os::native_path(orig), out, len) < 0) { |
0 | 1104 return false; |
1105 } | |
1106 } else { | |
1107 // On JDK 1.2.2 the Canonicalize does not exist, so just do nothing | |
1108 strncpy(out, orig, len); | |
1109 out[len - 1] = '\0'; | |
1110 } | |
1111 return true; | |
1112 } | |
1113 | |
1114 #ifndef PRODUCT | |
1115 | |
1116 void ClassLoader::verify() { | |
1117 _package_hash_table->verify(); | |
1118 } | |
1119 | |
1120 | |
1121 // CompileTheWorld | |
1122 // | |
1123 // Iterates over all class path entries and forces compilation of all methods | |
1124 // in all classes found. Currently, only zip/jar archives are searched. | |
1125 // | |
1126 // The classes are loaded by the Java level bootstrap class loader, and the | |
1127 // initializer is called. If DelayCompilationDuringStartup is true (default), | |
1128 // the interpreter will run the initialization code. Note that forcing | |
1129 // initialization in this way could potentially lead to initialization order | |
1130 // problems, in which case we could just force the initialization bit to be set. | |
1131 | |
1132 | |
1133 // We need to iterate over the contents of a zip/jar file, so we replicate the | |
1134 // jzcell and jzfile definitions from zip_util.h but rename jzfile to real_jzfile, | |
1135 // since jzfile already has a void* definition. | |
1136 // | |
1137 // Note that this is only used in debug mode. | |
1138 // | |
1139 // HotSpot integration note: | |
1140 // Matches zip_util.h 1.14 99/06/01 from jdk1.3 beta H build | |
1141 | |
1142 | |
1143 // JDK 1.3 version | |
1144 typedef struct real_jzentry13 { /* Zip file entry */ | |
1145 char *name; /* entry name */ | |
1146 jint time; /* modification time */ | |
1147 jint size; /* size of uncompressed data */ | |
1148 jint csize; /* size of compressed data (zero if uncompressed) */ | |
1149 jint crc; /* crc of uncompressed data */ | |
1150 char *comment; /* optional zip file comment */ | |
1151 jbyte *extra; /* optional extra data */ | |
1152 jint pos; /* position of LOC header (if negative) or data */ | |
1153 } real_jzentry13; | |
1154 | |
1155 typedef struct real_jzfile13 { /* Zip file */ | |
1156 char *name; /* zip file name */ | |
1157 jint refs; /* number of active references */ | |
1158 jint fd; /* open file descriptor */ | |
1159 void *lock; /* read lock */ | |
1160 char *comment; /* zip file comment */ | |
1161 char *msg; /* zip error message */ | |
1162 void *entries; /* array of hash cells */ | |
1163 jint total; /* total number of entries */ | |
1164 unsigned short *table; /* Hash chain heads: indexes into entries */ | |
1165 jint tablelen; /* number of hash eads */ | |
1166 real_jzfile13 *next; /* next zip file in search list */ | |
1167 jzentry *cache; /* we cache the most recently freed jzentry */ | |
1168 /* Information on metadata names in META-INF directory */ | |
1169 char **metanames; /* array of meta names (may have null names) */ | |
1170 jint metacount; /* number of slots in metanames array */ | |
1171 /* If there are any per-entry comments, they are in the comments array */ | |
1172 char **comments; | |
1173 } real_jzfile13; | |
1174 | |
1175 // JDK 1.2 version | |
1176 typedef struct real_jzentry12 { /* Zip file entry */ | |
1177 char *name; /* entry name */ | |
1178 jint time; /* modification time */ | |
1179 jint size; /* size of uncompressed data */ | |
1180 jint csize; /* size of compressed data (zero if uncompressed) */ | |
1181 jint crc; /* crc of uncompressed data */ | |
1182 char *comment; /* optional zip file comment */ | |
1183 jbyte *extra; /* optional extra data */ | |
1184 jint pos; /* position of LOC header (if negative) or data */ | |
1185 struct real_jzentry12 *next; /* next entry in hash table */ | |
1186 } real_jzentry12; | |
1187 | |
1188 typedef struct real_jzfile12 { /* Zip file */ | |
1189 char *name; /* zip file name */ | |
1190 jint refs; /* number of active references */ | |
1191 jint fd; /* open file descriptor */ | |
1192 void *lock; /* read lock */ | |
1193 char *comment; /* zip file comment */ | |
1194 char *msg; /* zip error message */ | |
1195 real_jzentry12 *entries; /* array of zip entries */ | |
1196 jint total; /* total number of entries */ | |
1197 real_jzentry12 **table; /* hash table of entries */ | |
1198 jint tablelen; /* number of buckets */ | |
1199 jzfile *next; /* next zip file in search list */ | |
1200 } real_jzfile12; | |
1201 | |
1202 | |
1203 void ClassPathDirEntry::compile_the_world(Handle loader, TRAPS) { | |
1204 // For now we only compile all methods in all classes in zip/jar files | |
1205 tty->print_cr("CompileTheWorld : Skipped classes in %s", _dir); | |
1206 tty->cr(); | |
1207 } | |
1208 | |
1209 | |
1210 bool ClassPathDirEntry::is_rt_jar() { | |
1211 return false; | |
1212 } | |
1213 | |
1214 void ClassPathZipEntry::compile_the_world(Handle loader, TRAPS) { | |
1215 if (JDK_Version::is_jdk12x_version()) { | |
1216 compile_the_world12(loader, THREAD); | |
1217 } else { | |
1218 compile_the_world13(loader, THREAD); | |
1219 } | |
1220 if (HAS_PENDING_EXCEPTION) { | |
1221 if (PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) { | |
1222 CLEAR_PENDING_EXCEPTION; | |
1223 tty->print_cr("\nCompileTheWorld : Ran out of memory\n"); | |
1224 size_t used = Universe::heap()->permanent_used(); | |
1225 size_t capacity = Universe::heap()->permanent_capacity(); | |
1226 tty->print_cr("Permanent generation used %dK of %dK", used/K, capacity/K); | |
1227 tty->print_cr("Increase size by setting e.g. -XX:MaxPermSize=%dK\n", capacity*2/K); | |
1228 } else { | |
1229 tty->print_cr("\nCompileTheWorld : Unexpected exception occurred\n"); | |
1230 } | |
1231 } | |
1232 } | |
1233 | |
1234 // Version that works for JDK 1.3.x | |
1235 void ClassPathZipEntry::compile_the_world13(Handle loader, TRAPS) { | |
1236 real_jzfile13* zip = (real_jzfile13*) _zip; | |
1237 tty->print_cr("CompileTheWorld : Compiling all classes in %s", zip->name); | |
1238 tty->cr(); | |
1239 // Iterate over all entries in zip file | |
1240 for (int n = 0; ; n++) { | |
1241 real_jzentry13 * ze = (real_jzentry13 *)((*GetNextEntry)(_zip, n)); | |
1242 if (ze == NULL) break; | |
1243 ClassLoader::compile_the_world_in(ze->name, loader, CHECK); | |
1244 } | |
1245 } | |
1246 | |
1247 | |
1248 // Version that works for JDK 1.2.x | |
1249 void ClassPathZipEntry::compile_the_world12(Handle loader, TRAPS) { | |
1250 real_jzfile12* zip = (real_jzfile12*) _zip; | |
1251 tty->print_cr("CompileTheWorld : Compiling all classes in %s", zip->name); | |
1252 tty->cr(); | |
1253 // Iterate over all entries in zip file | |
1254 for (int n = 0; ; n++) { | |
1255 real_jzentry12 * ze = (real_jzentry12 *)((*GetNextEntry)(_zip, n)); | |
1256 if (ze == NULL) break; | |
1257 ClassLoader::compile_the_world_in(ze->name, loader, CHECK); | |
1258 } | |
1259 } | |
1260 | |
1261 bool ClassPathZipEntry::is_rt_jar() { | |
1262 if (JDK_Version::is_jdk12x_version()) { | |
1263 return is_rt_jar12(); | |
1264 } else { | |
1265 return is_rt_jar13(); | |
1266 } | |
1267 } | |
1268 | |
1269 // JDK 1.3 version | |
1270 bool ClassPathZipEntry::is_rt_jar13() { | |
1271 real_jzfile13* zip = (real_jzfile13*) _zip; | |
1272 int len = (int)strlen(zip->name); | |
1273 // Check whether zip name ends in "rt.jar" | |
1274 // This will match other archives named rt.jar as well, but this is | |
1275 // only used for debugging. | |
1276 return (len >= 6) && (strcasecmp(zip->name + len - 6, "rt.jar") == 0); | |
1277 } | |
1278 | |
1279 // JDK 1.2 version | |
1280 bool ClassPathZipEntry::is_rt_jar12() { | |
1281 real_jzfile12* zip = (real_jzfile12*) _zip; | |
1282 int len = (int)strlen(zip->name); | |
1283 // Check whether zip name ends in "rt.jar" | |
1284 // This will match other archives named rt.jar as well, but this is | |
1285 // only used for debugging. | |
1286 return (len >= 6) && (strcasecmp(zip->name + len - 6, "rt.jar") == 0); | |
1287 } | |
1288 | |
1289 void LazyClassPathEntry::compile_the_world(Handle loader, TRAPS) { | |
1290 resolve_entry()->compile_the_world(loader, CHECK); | |
1291 } | |
1292 | |
1293 bool LazyClassPathEntry::is_rt_jar() { | |
1294 return resolve_entry()->is_rt_jar(); | |
1295 } | |
1296 | |
1297 void ClassLoader::compile_the_world() { | |
1298 EXCEPTION_MARK; | |
1299 HandleMark hm(THREAD); | |
1300 ResourceMark rm(THREAD); | |
1301 // Make sure we don't run with background compilation | |
1302 BackgroundCompilation = false; | |
1303 // Find bootstrap loader | |
1304 Handle system_class_loader (THREAD, SystemDictionary::java_system_loader()); | |
1305 // Iterate over all bootstrap class path entries | |
1306 ClassPathEntry* e = _first_entry; | |
1307 while (e != NULL) { | |
1308 // We stop at rt.jar, unless it is the first bootstrap path entry | |
1309 if (e->is_rt_jar() && e != _first_entry) break; | |
1310 e->compile_the_world(system_class_loader, CATCH); | |
1311 e = e->next(); | |
1312 } | |
1313 tty->print_cr("CompileTheWorld : Done"); | |
1314 { | |
1315 // Print statistics as if before normal exit: | |
1316 extern void print_statistics(); | |
1317 print_statistics(); | |
1318 } | |
1319 vm_exit(0); | |
1320 } | |
1321 | |
1322 int ClassLoader::_compile_the_world_counter = 0; | |
1188
99af867dfa05
6919886: Sweep CodeCache more aggressively to reduce its usage for CompileTheWorld
kvn
parents:
1142
diff
changeset
|
1323 static int _codecache_sweep_counter = 0; |
0 | 1324 |
2257 | 1325 // Filter out all exceptions except OOMs |
1326 static void clear_pending_exception_if_not_oom(TRAPS) { | |
1327 if (HAS_PENDING_EXCEPTION && | |
1328 !PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) { | |
1329 CLEAR_PENDING_EXCEPTION; | |
1330 } | |
1331 // The CHECK at the caller will propagate the exception out | |
1332 } | |
1333 | |
0 | 1334 void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) { |
1335 int len = (int)strlen(name); | |
1336 if (len > 6 && strcmp(".class", name + len - 6) == 0) { | |
1337 // We have a .class file | |
1338 char buffer[2048]; | |
1339 strncpy(buffer, name, len - 6); | |
1340 buffer[len-6] = 0; | |
1341 // If the file has a period after removing .class, it's not really a | |
1342 // valid class file. The class loader will check everything else. | |
1343 if (strchr(buffer, '.') == NULL) { | |
1344 _compile_the_world_counter++; | |
723 | 1345 if (_compile_the_world_counter > CompileTheWorldStopAt) return; |
1346 | |
1347 // Construct name without extension | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2139
diff
changeset
|
1348 TempNewSymbol sym = SymbolTable::new_symbol(buffer, CHECK); |
723 | 1349 // Use loader to load and initialize class |
1350 klassOop ik = SystemDictionary::resolve_or_null(sym, loader, Handle(), THREAD); | |
1351 instanceKlassHandle k (THREAD, ik); | |
1352 if (k.not_null() && !HAS_PENDING_EXCEPTION) { | |
1353 k->initialize(THREAD); | |
1354 } | |
1355 bool exception_occurred = HAS_PENDING_EXCEPTION; | |
2257 | 1356 clear_pending_exception_if_not_oom(CHECK); |
723 | 1357 if (CompileTheWorldPreloadClasses && k.not_null()) { |
1358 constantPoolKlass::preload_and_initialize_all_classes(k->constants(), THREAD); | |
1359 if (HAS_PENDING_EXCEPTION) { | |
1360 // If something went wrong in preloading we just ignore it | |
2257 | 1361 clear_pending_exception_if_not_oom(CHECK); |
723 | 1362 tty->print_cr("Preloading failed for (%d) %s", _compile_the_world_counter, buffer); |
0 | 1363 } |
723 | 1364 } |
1365 | |
1366 if (_compile_the_world_counter >= CompileTheWorldStartAt) { | |
2323
bc6b27fb3568
6725983: Assertion "method->method_holder())->is_not_initialized(),"method holder must be initialized"
never
parents:
2257
diff
changeset
|
1367 if (k.is_null() || exception_occurred) { |
0 | 1368 // If something went wrong (e.g. ExceptionInInitializerError) we skip this class |
1369 tty->print_cr("CompileTheWorld (%d) : Skipping %s", _compile_the_world_counter, buffer); | |
1370 } else { | |
1371 tty->print_cr("CompileTheWorld (%d) : %s", _compile_the_world_counter, buffer); | |
1372 // Preload all classes to get around uncommon traps | |
1373 // Iterate over all methods in class | |
1374 for (int n = 0; n < k->methods()->length(); n++) { | |
1375 methodHandle m (THREAD, methodOop(k->methods()->obj_at(n))); | |
1783 | 1376 if (CompilationPolicy::can_be_compiled(m)) { |
1188
99af867dfa05
6919886: Sweep CodeCache more aggressively to reduce its usage for CompileTheWorld
kvn
parents:
1142
diff
changeset
|
1377 |
99af867dfa05
6919886: Sweep CodeCache more aggressively to reduce its usage for CompileTheWorld
kvn
parents:
1142
diff
changeset
|
1378 if (++_codecache_sweep_counter == CompileTheWorldSafepointInterval) { |
99af867dfa05
6919886: Sweep CodeCache more aggressively to reduce its usage for CompileTheWorld
kvn
parents:
1142
diff
changeset
|
1379 // Give sweeper a chance to keep up with CTW |
99af867dfa05
6919886: Sweep CodeCache more aggressively to reduce its usage for CompileTheWorld
kvn
parents:
1142
diff
changeset
|
1380 VM_ForceSafepoint op; |
99af867dfa05
6919886: Sweep CodeCache more aggressively to reduce its usage for CompileTheWorld
kvn
parents:
1142
diff
changeset
|
1381 VMThread::execute(&op); |
99af867dfa05
6919886: Sweep CodeCache more aggressively to reduce its usage for CompileTheWorld
kvn
parents:
1142
diff
changeset
|
1382 _codecache_sweep_counter = 0; |
99af867dfa05
6919886: Sweep CodeCache more aggressively to reduce its usage for CompileTheWorld
kvn
parents:
1142
diff
changeset
|
1383 } |
0 | 1384 // Force compilation |
3837
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
2426
diff
changeset
|
1385 CompileBroker::compile_method(m, InvocationEntryBci, CompilationPolicy::policy()->initial_compile_level(), |
0 | 1386 methodHandle(), 0, "CTW", THREAD); |
1387 if (HAS_PENDING_EXCEPTION) { | |
2257 | 1388 clear_pending_exception_if_not_oom(CHECK); |
0 | 1389 tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_counter, m->name()->as_C_string()); |
1390 } | |
3837
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
2426
diff
changeset
|
1391 if (TieredCompilation && TieredStopAtLevel >= CompLevel_full_optimization) { |
723 | 1392 // Clobber the first compile and force second tier compilation |
1393 nmethod* nm = m->code(); | |
1394 if (nm != NULL) { | |
1395 // Throw out the code so that the code cache doesn't fill up | |
1396 nm->make_not_entrant(); | |
1397 m->clear_code(); | |
1398 } | |
1783 | 1399 CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_full_optimization, |
723 | 1400 methodHandle(), 0, "CTW", THREAD); |
1401 if (HAS_PENDING_EXCEPTION) { | |
2257 | 1402 clear_pending_exception_if_not_oom(CHECK); |
723 | 1403 tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_counter, m->name()->as_C_string()); |
1404 } | |
0 | 1405 } |
1406 } | |
723 | 1407 |
1408 nmethod* nm = m->code(); | |
1409 if (nm != NULL) { | |
1410 // Throw out the code so that the code cache doesn't fill up | |
1411 nm->make_not_entrant(); | |
1412 m->clear_code(); | |
0 | 1413 } |
1414 } | |
1415 } | |
1416 } | |
1417 } | |
1418 } | |
1419 } | |
1420 | |
1421 #endif //PRODUCT | |
2139
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1422 |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1423 // Please keep following two functions at end of this file. With them placed at top or in middle of the file, |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1424 // they could get inlined by agressive compiler, an unknown trick, see bug 6966589. |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1425 void PerfClassTraceTime::initialize() { |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1426 if (!UsePerfData) return; |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1427 |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1428 if (_eventp != NULL) { |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1429 // increment the event counter |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1430 _eventp->inc(); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1431 } |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1432 |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1433 // stop the current active thread-local timer to measure inclusive time |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1434 _prev_active_event = -1; |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1435 for (int i=0; i < EVENT_TYPE_COUNT; i++) { |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1436 if (_timers[i].is_active()) { |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1437 assert(_prev_active_event == -1, "should have only one active timer"); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1438 _prev_active_event = i; |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1439 _timers[i].stop(); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1440 } |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1441 } |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1442 |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1443 if (_recursion_counters == NULL || (_recursion_counters[_event_type])++ == 0) { |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1444 // start the inclusive timer if not recursively called |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1445 _t.start(); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1446 } |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1447 |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1448 // start thread-local timer of the given event type |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1449 if (!_timers[_event_type].is_active()) { |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1450 _timers[_event_type].start(); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1451 } |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1452 } |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1453 |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1454 PerfClassTraceTime::~PerfClassTraceTime() { |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1455 if (!UsePerfData) return; |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1456 |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1457 // stop the thread-local timer as the event completes |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1458 // and resume the thread-local timer of the event next on the stack |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1459 _timers[_event_type].stop(); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1460 jlong selftime = _timers[_event_type].ticks(); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1461 |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1462 if (_prev_active_event >= 0) { |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1463 _timers[_prev_active_event].start(); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1464 } |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1465 |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1466 if (_recursion_counters != NULL && --(_recursion_counters[_event_type]) > 0) return; |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1467 |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1468 // increment the counters only on the leaf call |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1469 _t.stop(); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1470 _timep->inc(_t.ticks()); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1471 if (_selftimep != NULL) { |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1472 _selftimep->inc(selftime); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1473 } |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1474 // add all class loading related event selftime to the accumulated time counter |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1475 ClassLoader::perf_accumulated_time()->inc(selftime); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1476 |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1477 // reset the timer |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1478 _timers[_event_type].reset(); |
75efcee5ac47
6966589: hs16-b08 causes java.lang.StackOverflowError
minqi
parents:
1980
diff
changeset
|
1479 } |