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