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