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