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