Mercurial > hg > graal-jvmci-8
annotate src/share/vm/classfile/systemDictionary.cpp @ 2044:06f017f7daa7
Merge.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Fri, 07 Jan 2011 18:18:08 +0100 |
parents | 2d26b0046e0d f2da85a9b08e |
children | d25d4ca69222 |
rev | line source |
---|---|
0 | 1 /* |
1903 | 2 * Copyright (c) 1997, 2010, 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:
1508
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1508
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:
1508
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/dictionary.hpp" | |
27 #include "classfile/javaClasses.hpp" | |
28 #include "classfile/loaderConstraints.hpp" | |
29 #include "classfile/placeholders.hpp" | |
30 #include "classfile/resolutionErrors.hpp" | |
31 #include "classfile/systemDictionary.hpp" | |
32 #include "classfile/vmSymbols.hpp" | |
33 #include "interpreter/bytecodeStream.hpp" | |
34 #include "interpreter/interpreter.hpp" | |
35 #include "memory/gcLocker.hpp" | |
36 #include "memory/oopFactory.hpp" | |
37 #include "oops/instanceKlass.hpp" | |
38 #include "oops/instanceRefKlass.hpp" | |
39 #include "oops/klass.inline.hpp" | |
40 #include "oops/methodDataOop.hpp" | |
41 #include "oops/objArrayKlass.hpp" | |
42 #include "oops/oop.inline.hpp" | |
43 #include "oops/oop.inline2.hpp" | |
44 #include "oops/typeArrayKlass.hpp" | |
45 #include "prims/jvmtiEnvBase.hpp" | |
46 #include "prims/methodHandles.hpp" | |
47 #include "runtime/biasedLocking.hpp" | |
48 #include "runtime/fieldType.hpp" | |
49 #include "runtime/handles.inline.hpp" | |
50 #include "runtime/java.hpp" | |
51 #include "runtime/javaCalls.hpp" | |
52 #include "runtime/mutexLocker.hpp" | |
53 #include "runtime/signature.hpp" | |
54 #include "services/classLoadingService.hpp" | |
55 #include "services/threadService.hpp" | |
0 | 56 |
57 | |
1903 | 58 Dictionary* SystemDictionary::_dictionary = NULL; |
59 PlaceholderTable* SystemDictionary::_placeholders = NULL; | |
60 Dictionary* SystemDictionary::_shared_dictionary = NULL; | |
61 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL; | |
62 ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL; | |
63 SymbolPropertyTable* SystemDictionary::_invoke_method_table = NULL; | |
0 | 64 |
65 | |
66 int SystemDictionary::_number_of_modifications = 0; | |
67 | |
68 oop SystemDictionary::_system_loader_lock_obj = NULL; | |
69 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
70 klassOop SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT] |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
71 = { NULL /*, NULL...*/ }; |
0 | 72 |
73 klassOop SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ }; | |
74 | |
75 oop SystemDictionary::_java_system_loader = NULL; | |
76 | |
77 bool SystemDictionary::_has_loadClassInternal = false; | |
78 bool SystemDictionary::_has_checkPackageAccess = false; | |
79 | |
80 // lazily initialized klass variables | |
81 volatile klassOop SystemDictionary::_abstract_ownable_synchronizer_klass = NULL; | |
82 | |
83 | |
84 // ---------------------------------------------------------------------------- | |
85 // Java-level SystemLoader | |
86 | |
87 oop SystemDictionary::java_system_loader() { | |
88 return _java_system_loader; | |
89 } | |
90 | |
91 void SystemDictionary::compute_java_system_loader(TRAPS) { | |
1142 | 92 KlassHandle system_klass(THREAD, WK_KLASS(ClassLoader_klass)); |
0 | 93 JavaValue result(T_OBJECT); |
94 JavaCalls::call_static(&result, | |
1142 | 95 KlassHandle(THREAD, WK_KLASS(ClassLoader_klass)), |
0 | 96 vmSymbolHandles::getSystemClassLoader_name(), |
97 vmSymbolHandles::void_classloader_signature(), | |
98 CHECK); | |
99 | |
100 _java_system_loader = (oop)result.get_jobject(); | |
101 } | |
102 | |
103 | |
104 // ---------------------------------------------------------------------------- | |
105 // debugging | |
106 | |
107 #ifdef ASSERT | |
108 | |
109 // return true if class_name contains no '.' (internal format is '/') | |
110 bool SystemDictionary::is_internal_format(symbolHandle class_name) { | |
111 if (class_name.not_null()) { | |
112 ResourceMark rm; | |
113 char* name = class_name->as_C_string(); | |
114 return strchr(name, '.') == NULL; | |
115 } else { | |
116 return true; | |
117 } | |
118 } | |
119 | |
120 #endif | |
121 | |
122 // ---------------------------------------------------------------------------- | |
514 | 123 // Parallel class loading check |
124 | |
125 bool SystemDictionary::is_parallelCapable(Handle class_loader) { | |
126 if (UnsyncloadClass || class_loader.is_null()) return true; | |
127 if (AlwaysLockClassLoader) return false; | |
128 return java_lang_Class::parallelCapable(class_loader()); | |
129 } | |
130 // ---------------------------------------------------------------------------- | |
1075
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
131 // ParallelDefineClass flag does not apply to bootclass loader |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
132 bool SystemDictionary::is_parallelDefine(Handle class_loader) { |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
133 if (class_loader.is_null()) return false; |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
134 if (AllowParallelDefineClass && java_lang_Class::parallelCapable(class_loader())) { |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
135 return true; |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
136 } |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
137 return false; |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
138 } |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
139 // ---------------------------------------------------------------------------- |
0 | 140 // Resolving of classes |
141 | |
142 // Forwards to resolve_or_null | |
143 | |
144 klassOop SystemDictionary::resolve_or_fail(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) { | |
145 klassOop klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD); | |
146 if (HAS_PENDING_EXCEPTION || klass == NULL) { | |
147 KlassHandle k_h(THREAD, klass); | |
148 // can return a null klass | |
149 klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD); | |
150 } | |
151 return klass; | |
152 } | |
153 | |
154 klassOop SystemDictionary::handle_resolution_exception(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS) { | |
155 if (HAS_PENDING_EXCEPTION) { | |
156 // If we have a pending exception we forward it to the caller, unless throw_error is true, | |
157 // in which case we have to check whether the pending exception is a ClassNotFoundException, | |
158 // and if so convert it to a NoClassDefFoundError | |
159 // And chain the original ClassNotFoundException | |
1142 | 160 if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass())) { |
0 | 161 ResourceMark rm(THREAD); |
162 assert(klass_h() == NULL, "Should not have result with exception pending"); | |
163 Handle e(THREAD, PENDING_EXCEPTION); | |
164 CLEAR_PENDING_EXCEPTION; | |
165 THROW_MSG_CAUSE_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e); | |
166 } else { | |
167 return NULL; | |
168 } | |
169 } | |
170 // Class not found, throw appropriate error or exception depending on value of throw_error | |
171 if (klass_h() == NULL) { | |
172 ResourceMark rm(THREAD); | |
173 if (throw_error) { | |
174 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string()); | |
175 } else { | |
176 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string()); | |
177 } | |
178 } | |
179 return (klassOop)klass_h(); | |
180 } | |
181 | |
182 | |
183 klassOop SystemDictionary::resolve_or_fail(symbolHandle class_name, | |
184 bool throw_error, TRAPS) | |
185 { | |
186 return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD); | |
187 } | |
188 | |
189 | |
190 // Forwards to resolve_instance_class_or_null | |
191 | |
192 klassOop SystemDictionary::resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS) { | |
1407
09e7826ecf01
Can now call to Java code from the VM.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1339
diff
changeset
|
193 // (tw) May we do this? |
09e7826ecf01
Can now call to Java code from the VM.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1339
diff
changeset
|
194 // assert(!THREAD->is_Compiler_thread(), "Can not load classes with the Compiler thread"); |
0 | 195 if (FieldType::is_array(class_name())) { |
196 return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); | |
197 } else { | |
198 return resolve_instance_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); | |
199 } | |
200 } | |
201 | |
202 klassOop SystemDictionary::resolve_or_null(symbolHandle class_name, TRAPS) { | |
203 return resolve_or_null(class_name, Handle(), Handle(), THREAD); | |
204 } | |
205 | |
206 // Forwards to resolve_instance_class_or_null | |
207 | |
208 klassOop SystemDictionary::resolve_array_class_or_null(symbolHandle class_name, | |
209 Handle class_loader, | |
210 Handle protection_domain, | |
211 TRAPS) { | |
212 assert(FieldType::is_array(class_name()), "must be array"); | |
213 jint dimension; | |
214 symbolOop object_key; | |
215 klassOop k = NULL; | |
216 // dimension and object_key are assigned as a side-effect of this call | |
217 BasicType t = FieldType::get_array_info(class_name(), | |
218 &dimension, | |
219 &object_key, | |
220 CHECK_NULL); | |
221 | |
222 if (t == T_OBJECT) { | |
223 symbolHandle h_key(THREAD, object_key); | |
224 // naked oop "k" is OK here -- we assign back into it | |
225 k = SystemDictionary::resolve_instance_class_or_null(h_key, | |
226 class_loader, | |
227 protection_domain, | |
228 CHECK_NULL); | |
229 if (k != NULL) { | |
230 k = Klass::cast(k)->array_klass(dimension, CHECK_NULL); | |
231 } | |
232 } else { | |
233 k = Universe::typeArrayKlassObj(t); | |
234 k = typeArrayKlass::cast(k)->array_klass(dimension, CHECK_NULL); | |
235 } | |
236 return k; | |
237 } | |
238 | |
239 | |
240 // Must be called for any super-class or super-interface resolution | |
241 // during class definition to allow class circularity checking | |
242 // super-interface callers: | |
243 // parse_interfaces - for defineClass & jvmtiRedefineClasses | |
244 // super-class callers: | |
245 // ClassFileParser - for defineClass & jvmtiRedefineClasses | |
246 // load_shared_class - while loading a class from shared archive | |
514 | 247 // resolve_instance_class_or_null: |
248 // via: handle_parallel_super_load | |
0 | 249 // when resolving a class that has an existing placeholder with |
250 // a saved superclass [i.e. a defineClass is currently in progress] | |
251 // if another thread is trying to resolve the class, it must do | |
252 // super-class checks on its own thread to catch class circularity | |
253 // This last call is critical in class circularity checking for cases | |
254 // where classloading is delegated to different threads and the | |
255 // classloader lock is released. | |
256 // Take the case: Base->Super->Base | |
257 // 1. If thread T1 tries to do a defineClass of class Base | |
258 // resolve_super_or_fail creates placeholder: T1, Base (super Super) | |
259 // 2. resolve_instance_class_or_null does not find SD or placeholder for Super | |
260 // so it tries to load Super | |
261 // 3. If we load the class internally, or user classloader uses same thread | |
262 // loadClassFromxxx or defineClass via parseClassFile Super ... | |
263 // 3.1 resolve_super_or_fail creates placeholder: T1, Super (super Base) | |
264 // 3.3 resolve_instance_class_or_null Base, finds placeholder for Base | |
265 // 3.4 calls resolve_super_or_fail Base | |
266 // 3.5 finds T1,Base -> throws class circularity | |
267 //OR 4. If T2 tries to resolve Super via defineClass Super ... | |
268 // 4.1 resolve_super_or_fail creates placeholder: T2, Super (super Base) | |
269 // 4.2 resolve_instance_class_or_null Base, finds placeholder for Base (super Super) | |
270 // 4.3 calls resolve_super_or_fail Super in parallel on own thread T2 | |
271 // 4.4 finds T2, Super -> throws class circularity | |
272 // Must be called, even if superclass is null, since this is | |
273 // where the placeholder entry is created which claims this | |
274 // thread is loading this class/classloader. | |
275 klassOop SystemDictionary::resolve_super_or_fail(symbolHandle child_name, | |
276 symbolHandle class_name, | |
277 Handle class_loader, | |
278 Handle protection_domain, | |
279 bool is_superclass, | |
280 TRAPS) { | |
281 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
282 // Try to get one of the well-known klasses. |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
283 // They are trusted, and do not participate in circularities. |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
284 if (LinkWellKnownClasses) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
285 klassOop k = find_well_known_klass(class_name()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
286 if (k != NULL) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
287 return k; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
288 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
289 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
290 |
0 | 291 // Double-check, if child class is already loaded, just return super-class,interface |
292 // Don't add a placedholder if already loaded, i.e. already in system dictionary | |
293 // Make sure there's a placeholder for the *child* before resolving. | |
294 // Used as a claim that this thread is currently loading superclass/classloader | |
295 // Used here for ClassCircularity checks and also for heap verification | |
296 // (every instanceKlass in the heap needs to be in the system dictionary | |
297 // or have a placeholder). | |
298 // Must check ClassCircularity before checking if super class is already loaded | |
299 // | |
300 // We might not already have a placeholder if this child_name was | |
301 // first seen via resolve_from_stream (jni_DefineClass or JVM_DefineClass); | |
302 // the name of the class might not be known until the stream is actually | |
303 // parsed. | |
304 // Bugs 4643874, 4715493 | |
305 // compute_hash can have a safepoint | |
306 | |
307 unsigned int d_hash = dictionary()->compute_hash(child_name, class_loader); | |
308 int d_index = dictionary()->hash_to_index(d_hash); | |
309 unsigned int p_hash = placeholders()->compute_hash(child_name, class_loader); | |
310 int p_index = placeholders()->hash_to_index(p_hash); | |
311 // can't throw error holding a lock | |
312 bool child_already_loaded = false; | |
313 bool throw_circularity_error = false; | |
314 { | |
315 MutexLocker mu(SystemDictionary_lock, THREAD); | |
316 klassOop childk = find_class(d_index, d_hash, child_name, class_loader); | |
317 klassOop quicksuperk; | |
318 // to support // loading: if child done loading, just return superclass | |
319 // if class_name, & class_loader don't match: | |
320 // if initial define, SD update will give LinkageError | |
321 // if redefine: compare_class_versions will give HIERARCHY_CHANGED | |
322 // so we don't throw an exception here. | |
323 // see: nsk redefclass014 & java.lang.instrument Instrument032 | |
324 if ((childk != NULL ) && (is_superclass) && | |
325 ((quicksuperk = instanceKlass::cast(childk)->super()) != NULL) && | |
326 | |
327 ((Klass::cast(quicksuperk)->name() == class_name()) && | |
328 (Klass::cast(quicksuperk)->class_loader() == class_loader()))) { | |
329 return quicksuperk; | |
330 } else { | |
331 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader); | |
332 if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) { | |
333 throw_circularity_error = true; | |
334 } | |
514 | 335 } |
336 if (!throw_circularity_error) { | |
0 | 337 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, class_loader, PlaceholderTable::LOAD_SUPER, class_name, THREAD); |
338 } | |
339 } | |
340 if (throw_circularity_error) { | |
341 ResourceMark rm(THREAD); | |
342 THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string()); | |
343 } | |
344 | |
345 // java.lang.Object should have been found above | |
346 assert(class_name() != NULL, "null super class for resolving"); | |
347 // Resolve the super class or interface, check results on return | |
348 klassOop superk = NULL; | |
349 superk = SystemDictionary::resolve_or_null(class_name, | |
350 class_loader, | |
351 protection_domain, | |
352 THREAD); | |
353 | |
354 KlassHandle superk_h(THREAD, superk); | |
355 | |
356 // Note: clean up of placeholders currently in callers of | |
357 // resolve_super_or_fail - either at update_dictionary time | |
358 // or on error | |
359 { | |
360 MutexLocker mu(SystemDictionary_lock, THREAD); | |
361 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader); | |
362 if (probe != NULL) { | |
363 probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER); | |
364 } | |
365 } | |
366 if (HAS_PENDING_EXCEPTION || superk_h() == NULL) { | |
367 // can null superk | |
368 superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, class_loader, protection_domain, true, superk_h, THREAD)); | |
369 } | |
370 | |
371 return superk_h(); | |
372 } | |
373 | |
374 void SystemDictionary::validate_protection_domain(instanceKlassHandle klass, | |
375 Handle class_loader, | |
376 Handle protection_domain, | |
377 TRAPS) { | |
378 if(!has_checkPackageAccess()) return; | |
379 | |
380 // Now we have to call back to java to check if the initating class has access | |
381 JavaValue result(T_VOID); | |
382 if (TraceProtectionDomainVerification) { | |
383 // Print out trace information | |
384 tty->print_cr("Checking package access"); | |
385 tty->print(" - class loader: "); class_loader()->print_value_on(tty); tty->cr(); | |
386 tty->print(" - protection domain: "); protection_domain()->print_value_on(tty); tty->cr(); | |
387 tty->print(" - loading: "); klass()->print_value_on(tty); tty->cr(); | |
388 } | |
389 | |
390 assert(class_loader() != NULL, "should not have non-null protection domain for null classloader"); | |
391 | |
1142 | 392 KlassHandle system_loader(THREAD, SystemDictionary::ClassLoader_klass()); |
0 | 393 JavaCalls::call_special(&result, |
394 class_loader, | |
395 system_loader, | |
396 vmSymbolHandles::checkPackageAccess_name(), | |
397 vmSymbolHandles::class_protectiondomain_signature(), | |
398 Handle(THREAD, klass->java_mirror()), | |
399 protection_domain, | |
400 THREAD); | |
401 | |
402 if (TraceProtectionDomainVerification) { | |
403 if (HAS_PENDING_EXCEPTION) { | |
404 tty->print_cr(" -> DENIED !!!!!!!!!!!!!!!!!!!!!"); | |
405 } else { | |
406 tty->print_cr(" -> granted"); | |
407 } | |
408 tty->cr(); | |
409 } | |
410 | |
411 if (HAS_PENDING_EXCEPTION) return; | |
412 | |
413 // If no exception has been thrown, we have validated the protection domain | |
414 // Insert the protection domain of the initiating class into the set. | |
415 { | |
416 // We recalculate the entry here -- we've called out to java since | |
417 // the last time it was calculated. | |
418 symbolHandle kn(THREAD, klass->name()); | |
419 unsigned int d_hash = dictionary()->compute_hash(kn, class_loader); | |
420 int d_index = dictionary()->hash_to_index(d_hash); | |
421 | |
422 MutexLocker mu(SystemDictionary_lock, THREAD); | |
423 { | |
424 // Note that we have an entry, and entries can be deleted only during GC, | |
425 // so we cannot allow GC to occur while we're holding this entry. | |
426 | |
427 // We're using a No_Safepoint_Verifier to catch any place where we | |
428 // might potentially do a GC at all. | |
429 // SystemDictionary::do_unloading() asserts that classes are only | |
430 // unloaded at a safepoint. | |
431 No_Safepoint_Verifier nosafepoint; | |
432 dictionary()->add_protection_domain(d_index, d_hash, klass, class_loader, | |
433 protection_domain, THREAD); | |
434 } | |
435 } | |
436 } | |
437 | |
438 // We only get here if this thread finds that another thread | |
439 // has already claimed the placeholder token for the current operation, | |
440 // but that other thread either never owned or gave up the | |
441 // object lock | |
442 // Waits on SystemDictionary_lock to indicate placeholder table updated | |
443 // On return, caller must recheck placeholder table state | |
444 // | |
445 // We only get here if | |
446 // 1) custom classLoader, i.e. not bootstrap classloader | |
447 // 2) UnsyncloadClass not set | |
448 // 3) custom classLoader has broken the class loader objectLock | |
449 // so another thread got here in parallel | |
450 // | |
451 // lockObject must be held. | |
452 // Complicated dance due to lock ordering: | |
453 // Must first release the classloader object lock to | |
454 // allow initial definer to complete the class definition | |
455 // and to avoid deadlock | |
456 // Reclaim classloader lock object with same original recursion count | |
457 // Must release SystemDictionary_lock after notify, since | |
458 // class loader lock must be claimed before SystemDictionary_lock | |
459 // to prevent deadlocks | |
460 // | |
461 // The notify allows applications that did an untimed wait() on | |
462 // the classloader object lock to not hang. | |
463 void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) { | |
464 assert_lock_strong(SystemDictionary_lock); | |
465 | |
466 bool calledholdinglock | |
467 = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject); | |
468 assert(calledholdinglock,"must hold lock for notify"); | |
514 | 469 assert((!(lockObject() == _system_loader_lock_obj) && !is_parallelCapable(lockObject)), "unexpected double_lock_wait"); |
0 | 470 ObjectSynchronizer::notifyall(lockObject, THREAD); |
471 intptr_t recursions = ObjectSynchronizer::complete_exit(lockObject, THREAD); | |
472 SystemDictionary_lock->wait(); | |
473 SystemDictionary_lock->unlock(); | |
474 ObjectSynchronizer::reenter(lockObject, recursions, THREAD); | |
475 SystemDictionary_lock->lock(); | |
476 } | |
477 | |
478 // If the class in is in the placeholder table, class loading is in progress | |
479 // For cases where the application changes threads to load classes, it | |
480 // is critical to ClassCircularity detection that we try loading | |
481 // the superclass on the same thread internally, so we do parallel | |
482 // super class loading here. | |
483 // This also is critical in cases where the original thread gets stalled | |
484 // even in non-circularity situations. | |
485 // Note: only one thread can define the class, but multiple can resolve | |
486 // Note: must call resolve_super_or_fail even if null super - | |
514 | 487 // to force placeholder entry creation for this class for circularity detection |
0 | 488 // Caller must check for pending exception |
489 // Returns non-null klassOop if other thread has completed load | |
490 // and we are done, | |
491 // If return null klassOop and no pending exception, the caller must load the class | |
492 instanceKlassHandle SystemDictionary::handle_parallel_super_load( | |
493 symbolHandle name, symbolHandle superclassname, Handle class_loader, | |
494 Handle protection_domain, Handle lockObject, TRAPS) { | |
495 | |
496 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | |
497 unsigned int d_hash = dictionary()->compute_hash(name, class_loader); | |
498 int d_index = dictionary()->hash_to_index(d_hash); | |
499 unsigned int p_hash = placeholders()->compute_hash(name, class_loader); | |
500 int p_index = placeholders()->hash_to_index(p_hash); | |
501 | |
502 // superk is not used, resolve_super called for circularity check only | |
503 // This code is reached in two situations. One if this thread | |
504 // is loading the same class twice (e.g. ClassCircularity, or | |
505 // java.lang.instrument). | |
506 // The second is if another thread started the resolve_super first | |
507 // and has not yet finished. | |
508 // In both cases the original caller will clean up the placeholder | |
509 // entry on error. | |
510 klassOop superk = SystemDictionary::resolve_super_or_fail(name, | |
511 superclassname, | |
512 class_loader, | |
513 protection_domain, | |
514 true, | |
515 CHECK_(nh)); | |
516 // We don't redefine the class, so we just need to clean up if there | |
517 // was not an error (don't want to modify any system dictionary | |
518 // data structures). | |
519 { | |
520 MutexLocker mu(SystemDictionary_lock, THREAD); | |
521 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | |
522 SystemDictionary_lock->notify_all(); | |
523 } | |
524 | |
514 | 525 // parallelCapable class loaders do NOT wait for parallel superclass loads to complete |
526 // Serial class loaders and bootstrap classloader do wait for superclass loads | |
527 if (!class_loader.is_null() && is_parallelCapable(class_loader)) { | |
0 | 528 MutexLocker mu(SystemDictionary_lock, THREAD); |
529 // Check if classloading completed while we were loading superclass or waiting | |
530 klassOop check = find_class(d_index, d_hash, name, class_loader); | |
531 if (check != NULL) { | |
532 // Klass is already loaded, so just return it | |
533 return(instanceKlassHandle(THREAD, check)); | |
534 } else { | |
535 return nh; | |
536 } | |
537 } | |
538 | |
539 // must loop to both handle other placeholder updates | |
540 // and spurious notifications | |
541 bool super_load_in_progress = true; | |
542 PlaceholderEntry* placeholder; | |
543 while (super_load_in_progress) { | |
544 MutexLocker mu(SystemDictionary_lock, THREAD); | |
545 // Check if classloading completed while we were loading superclass or waiting | |
546 klassOop check = find_class(d_index, d_hash, name, class_loader); | |
547 if (check != NULL) { | |
548 // Klass is already loaded, so just return it | |
549 return(instanceKlassHandle(THREAD, check)); | |
550 } else { | |
551 placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader); | |
552 if (placeholder && placeholder->super_load_in_progress() ){ | |
553 // Before UnsyncloadClass: | |
554 // We only get here if the application has released the | |
555 // classloader lock when another thread was in the middle of loading a | |
556 // superclass/superinterface for this class, and now | |
557 // this thread is also trying to load this class. | |
558 // To minimize surprises, the first thread that started to | |
559 // load a class should be the one to complete the loading | |
560 // with the classfile it initially expected. | |
561 // This logic has the current thread wait once it has done | |
562 // all the superclass/superinterface loading it can, until | |
563 // the original thread completes the class loading or fails | |
564 // If it completes we will use the resulting instanceKlass | |
565 // which we will find below in the systemDictionary. | |
566 // We also get here for parallel bootstrap classloader | |
567 if (class_loader.is_null()) { | |
568 SystemDictionary_lock->wait(); | |
569 } else { | |
570 double_lock_wait(lockObject, THREAD); | |
571 } | |
572 } else { | |
573 // If not in SD and not in PH, other thread's load must have failed | |
574 super_load_in_progress = false; | |
575 } | |
576 } | |
577 } | |
578 return (nh); | |
579 } | |
580 | |
581 | |
582 klassOop SystemDictionary::resolve_instance_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS) { | |
583 assert(class_name.not_null() && !FieldType::is_array(class_name()), "invalid class name"); | |
584 // First check to see if we should remove wrapping L and ; | |
585 symbolHandle name; | |
586 if (FieldType::is_obj(class_name())) { | |
587 ResourceMark rm(THREAD); | |
588 // Ignore wrapping L and ;. | |
589 name = oopFactory::new_symbol_handle(class_name()->as_C_string() + 1, class_name()->utf8_length() - 2, CHECK_NULL); | |
590 } else { | |
591 name = class_name; | |
592 } | |
593 | |
594 // UseNewReflection | |
595 // Fix for 4474172; see evaluation for more details | |
596 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); | |
597 | |
598 // Do lookup to see if class already exist and the protection domain | |
599 // has the right access | |
600 unsigned int d_hash = dictionary()->compute_hash(name, class_loader); | |
601 int d_index = dictionary()->hash_to_index(d_hash); | |
602 klassOop probe = dictionary()->find(d_index, d_hash, name, class_loader, | |
603 protection_domain, THREAD); | |
604 if (probe != NULL) return probe; | |
605 | |
606 | |
607 // Non-bootstrap class loaders will call out to class loader and | |
608 // define via jvm/jni_DefineClass which will acquire the | |
609 // class loader object lock to protect against multiple threads | |
610 // defining the class in parallel by accident. | |
611 // This lock must be acquired here so the waiter will find | |
612 // any successful result in the SystemDictionary and not attempt | |
613 // the define | |
514 | 614 // ParallelCapable Classloaders and the bootstrap classloader, |
0 | 615 // or all classloaders with UnsyncloadClass do not acquire lock here |
616 bool DoObjectLock = true; | |
514 | 617 if (is_parallelCapable(class_loader)) { |
0 | 618 DoObjectLock = false; |
619 } | |
620 | |
621 unsigned int p_hash = placeholders()->compute_hash(name, class_loader); | |
622 int p_index = placeholders()->hash_to_index(p_hash); | |
623 | |
624 // Class is not in SystemDictionary so we have to do loading. | |
625 // Make sure we are synchronized on the class loader before we proceed | |
626 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); | |
627 check_loader_lock_contention(lockObject, THREAD); | |
628 ObjectLocker ol(lockObject, THREAD, DoObjectLock); | |
629 | |
630 // Check again (after locking) if class already exist in SystemDictionary | |
631 bool class_has_been_loaded = false; | |
632 bool super_load_in_progress = false; | |
633 bool havesupername = false; | |
634 instanceKlassHandle k; | |
635 PlaceholderEntry* placeholder; | |
636 symbolHandle superclassname; | |
637 | |
638 { | |
639 MutexLocker mu(SystemDictionary_lock, THREAD); | |
640 klassOop check = find_class(d_index, d_hash, name, class_loader); | |
641 if (check != NULL) { | |
642 // Klass is already loaded, so just return it | |
643 class_has_been_loaded = true; | |
644 k = instanceKlassHandle(THREAD, check); | |
645 } else { | |
646 placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader); | |
647 if (placeholder && placeholder->super_load_in_progress()) { | |
648 super_load_in_progress = true; | |
649 if (placeholder->havesupername() == true) { | |
650 superclassname = symbolHandle(THREAD, placeholder->supername()); | |
651 havesupername = true; | |
652 } | |
653 } | |
654 } | |
655 } | |
656 | |
657 // If the class in is in the placeholder table, class loading is in progress | |
658 if (super_load_in_progress && havesupername==true) { | |
659 k = SystemDictionary::handle_parallel_super_load(name, superclassname, | |
660 class_loader, protection_domain, lockObject, THREAD); | |
661 if (HAS_PENDING_EXCEPTION) { | |
662 return NULL; | |
663 } | |
664 if (!k.is_null()) { | |
665 class_has_been_loaded = true; | |
666 } | |
667 } | |
668 | |
669 if (!class_has_been_loaded) { | |
670 | |
671 // add placeholder entry to record loading instance class | |
672 // Five cases: | |
673 // All cases need to prevent modifying bootclasssearchpath | |
674 // in parallel with a classload of same classname | |
514 | 675 // Redefineclasses uses existence of the placeholder for the duration |
676 // of the class load to prevent concurrent redefinition of not completely | |
677 // defined classes. | |
0 | 678 // case 1. traditional classloaders that rely on the classloader object lock |
679 // - no other need for LOAD_INSTANCE | |
680 // case 2. traditional classloaders that break the classloader object lock | |
681 // as a deadlock workaround. Detection of this case requires that | |
682 // this check is done while holding the classloader object lock, | |
683 // and that lock is still held when calling classloader's loadClass. | |
684 // For these classloaders, we ensure that the first requestor | |
685 // completes the load and other requestors wait for completion. | |
686 // case 3. UnsyncloadClass - don't use objectLocker | |
687 // With this flag, we allow parallel classloading of a | |
688 // class/classloader pair | |
689 // case4. Bootstrap classloader - don't own objectLocker | |
690 // This classloader supports parallelism at the classloader level, | |
691 // but only allows a single load of a class/classloader pair. | |
692 // No performance benefit and no deadlock issues. | |
514 | 693 // case 5. parallelCapable user level classloaders - without objectLocker |
694 // Allow parallel classloading of a class/classloader pair | |
0 | 695 symbolHandle nullsymbolHandle; |
696 bool throw_circularity_error = false; | |
697 { | |
698 MutexLocker mu(SystemDictionary_lock, THREAD); | |
514 | 699 if (class_loader.is_null() || !is_parallelCapable(class_loader)) { |
0 | 700 PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader); |
701 if (oldprobe) { | |
702 // only need check_seen_thread once, not on each loop | |
703 // 6341374 java/lang/Instrument with -Xcomp | |
704 if (oldprobe->check_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE)) { | |
705 throw_circularity_error = true; | |
706 } else { | |
707 // case 1: traditional: should never see load_in_progress. | |
708 while (!class_has_been_loaded && oldprobe && oldprobe->instance_load_in_progress()) { | |
709 | |
710 // case 4: bootstrap classloader: prevent futile classloading, | |
711 // wait on first requestor | |
712 if (class_loader.is_null()) { | |
713 SystemDictionary_lock->wait(); | |
714 } else { | |
715 // case 2: traditional with broken classloader lock. wait on first | |
716 // requestor. | |
717 double_lock_wait(lockObject, THREAD); | |
718 } | |
719 // Check if classloading completed while we were waiting | |
720 klassOop check = find_class(d_index, d_hash, name, class_loader); | |
721 if (check != NULL) { | |
722 // Klass is already loaded, so just return it | |
723 k = instanceKlassHandle(THREAD, check); | |
724 class_has_been_loaded = true; | |
725 } | |
726 // check if other thread failed to load and cleaned up | |
727 oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader); | |
728 } | |
729 } | |
730 } | |
731 } | |
732 // All cases: add LOAD_INSTANCE | |
514 | 733 // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try |
0 | 734 // LOAD_INSTANCE in parallel |
735 // add placeholder entry even if error - callers will remove on error | |
514 | 736 if (!throw_circularity_error && !class_has_been_loaded) { |
0 | 737 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, class_loader, PlaceholderTable::LOAD_INSTANCE, nullsymbolHandle, THREAD); |
738 // For class loaders that do not acquire the classloader object lock, | |
739 // if they did not catch another thread holding LOAD_INSTANCE, | |
740 // need a check analogous to the acquire ObjectLocker/find_class | |
741 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL | |
742 // one final check if the load has already completed | |
514 | 743 // class loaders holding the ObjectLock shouldn't find the class here |
0 | 744 klassOop check = find_class(d_index, d_hash, name, class_loader); |
745 if (check != NULL) { | |
746 // Klass is already loaded, so just return it | |
747 k = instanceKlassHandle(THREAD, check); | |
748 class_has_been_loaded = true; | |
749 newprobe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE); | |
514 | 750 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); |
751 SystemDictionary_lock->notify_all(); | |
0 | 752 } |
753 } | |
754 } | |
755 // must throw error outside of owning lock | |
756 if (throw_circularity_error) { | |
757 ResourceMark rm(THREAD); | |
758 THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string()); | |
759 } | |
760 | |
761 if (!class_has_been_loaded) { | |
762 | |
763 // Do actual loading | |
764 k = load_instance_class(name, class_loader, THREAD); | |
765 | |
1075
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
766 // For UnsyncloadClass only |
0 | 767 // If they got a linkageError, check if a parallel class load succeeded. |
768 // If it did, then for bytecode resolution the specification requires | |
769 // that we return the same result we did for the other thread, i.e. the | |
770 // successfully loaded instanceKlass | |
771 // Should not get here for classloaders that support parallelism | |
1075
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
772 // with the new cleaner mechanism, even with AllowParallelDefineClass |
514 | 773 // Bootstrap goes through here to allow for an extra guarantee check |
0 | 774 if (UnsyncloadClass || (class_loader.is_null())) { |
775 if (k.is_null() && HAS_PENDING_EXCEPTION | |
1142 | 776 && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) { |
0 | 777 MutexLocker mu(SystemDictionary_lock, THREAD); |
778 klassOop check = find_class(d_index, d_hash, name, class_loader); | |
779 if (check != NULL) { | |
780 // Klass is already loaded, so just use it | |
781 k = instanceKlassHandle(THREAD, check); | |
782 CLEAR_PENDING_EXCEPTION; | |
783 guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?"); | |
784 } | |
785 } | |
786 } | |
787 | |
788 // clean up placeholder entries for success or error | |
789 // This cleans up LOAD_INSTANCE entries | |
790 // It also cleans up LOAD_SUPER entries on errors from | |
791 // calling load_instance_class | |
792 { | |
793 MutexLocker mu(SystemDictionary_lock, THREAD); | |
794 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name, class_loader); | |
795 if (probe != NULL) { | |
796 probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE); | |
797 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | |
798 SystemDictionary_lock->notify_all(); | |
799 } | |
800 } | |
801 | |
802 // If everything was OK (no exceptions, no null return value), and | |
803 // class_loader is NOT the defining loader, do a little more bookkeeping. | |
804 if (!HAS_PENDING_EXCEPTION && !k.is_null() && | |
805 k->class_loader() != class_loader()) { | |
806 | |
807 check_constraints(d_index, d_hash, k, class_loader, false, THREAD); | |
808 | |
809 // Need to check for a PENDING_EXCEPTION again; check_constraints | |
810 // can throw and doesn't use the CHECK macro. | |
811 if (!HAS_PENDING_EXCEPTION) { | |
812 { // Grabbing the Compile_lock prevents systemDictionary updates | |
813 // during compilations. | |
814 MutexLocker mu(Compile_lock, THREAD); | |
815 update_dictionary(d_index, d_hash, p_index, p_hash, | |
816 k, class_loader, THREAD); | |
817 } | |
818 if (JvmtiExport::should_post_class_load()) { | |
819 Thread *thread = THREAD; | |
820 assert(thread->is_Java_thread(), "thread->is_Java_thread()"); | |
821 JvmtiExport::post_class_load((JavaThread *) thread, k()); | |
822 } | |
823 } | |
824 } | |
825 if (HAS_PENDING_EXCEPTION || k.is_null()) { | |
826 // On error, clean up placeholders | |
827 { | |
828 MutexLocker mu(SystemDictionary_lock, THREAD); | |
829 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | |
830 SystemDictionary_lock->notify_all(); | |
831 } | |
832 return NULL; | |
833 } | |
834 } | |
835 } | |
836 | |
837 #ifdef ASSERT | |
838 { | |
839 Handle loader (THREAD, k->class_loader()); | |
840 MutexLocker mu(SystemDictionary_lock, THREAD); | |
841 oop kk = find_class_or_placeholder(name, loader); | |
842 assert(kk == k(), "should be present in dictionary"); | |
843 } | |
844 #endif | |
845 | |
846 // return if the protection domain in NULL | |
847 if (protection_domain() == NULL) return k(); | |
848 | |
849 // Check the protection domain has the right access | |
850 { | |
851 MutexLocker mu(SystemDictionary_lock, THREAD); | |
852 // Note that we have an entry, and entries can be deleted only during GC, | |
853 // so we cannot allow GC to occur while we're holding this entry. | |
854 // We're using a No_Safepoint_Verifier to catch any place where we | |
855 // might potentially do a GC at all. | |
856 // SystemDictionary::do_unloading() asserts that classes are only | |
857 // unloaded at a safepoint. | |
858 No_Safepoint_Verifier nosafepoint; | |
859 if (dictionary()->is_valid_protection_domain(d_index, d_hash, name, | |
860 class_loader, | |
861 protection_domain)) { | |
862 return k(); | |
863 } | |
864 } | |
865 | |
866 // Verify protection domain. If it fails an exception is thrown | |
867 validate_protection_domain(k, class_loader, protection_domain, CHECK_(klassOop(NULL))); | |
868 | |
869 return k(); | |
870 } | |
871 | |
872 | |
873 // This routine does not lock the system dictionary. | |
874 // | |
875 // Since readers don't hold a lock, we must make sure that system | |
876 // dictionary entries are only removed at a safepoint (when only one | |
877 // thread is running), and are added to in a safe way (all links must | |
878 // be updated in an MT-safe manner). | |
879 // | |
880 // Callers should be aware that an entry could be added just after | |
881 // _dictionary->bucket(index) is read here, so the caller will not see | |
882 // the new entry. | |
883 | |
884 klassOop SystemDictionary::find(symbolHandle class_name, | |
885 Handle class_loader, | |
886 Handle protection_domain, | |
887 TRAPS) { | |
888 | |
556
48bb4a49b7ac
6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents:
431
diff
changeset
|
889 // UseNewReflection |
48bb4a49b7ac
6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents:
431
diff
changeset
|
890 // The result of this call should be consistent with the result |
48bb4a49b7ac
6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents:
431
diff
changeset
|
891 // of the call to resolve_instance_class_or_null(). |
48bb4a49b7ac
6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents:
431
diff
changeset
|
892 // See evaluation 6790209 and 4474172 for more details. |
48bb4a49b7ac
6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents:
431
diff
changeset
|
893 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
48bb4a49b7ac
6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents:
431
diff
changeset
|
894 |
0 | 895 unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader); |
896 int d_index = dictionary()->hash_to_index(d_hash); | |
897 | |
898 { | |
899 // Note that we have an entry, and entries can be deleted only during GC, | |
900 // so we cannot allow GC to occur while we're holding this entry. | |
901 // We're using a No_Safepoint_Verifier to catch any place where we | |
902 // might potentially do a GC at all. | |
903 // SystemDictionary::do_unloading() asserts that classes are only | |
904 // unloaded at a safepoint. | |
905 No_Safepoint_Verifier nosafepoint; | |
906 return dictionary()->find(d_index, d_hash, class_name, class_loader, | |
907 protection_domain, THREAD); | |
908 } | |
909 } | |
910 | |
911 | |
912 // Look for a loaded instance or array klass by name. Do not do any loading. | |
913 // return NULL in case of error. | |
914 klassOop SystemDictionary::find_instance_or_array_klass(symbolHandle class_name, | |
915 Handle class_loader, | |
916 Handle protection_domain, | |
917 TRAPS) { | |
918 klassOop k = NULL; | |
919 assert(class_name() != NULL, "class name must be non NULL"); | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
920 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
921 // Try to get one of the well-known klasses. |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
922 if (LinkWellKnownClasses) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
923 k = find_well_known_klass(class_name()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
924 if (k != NULL) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
925 return k; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
926 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
927 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
928 |
0 | 929 if (FieldType::is_array(class_name())) { |
930 // The name refers to an array. Parse the name. | |
931 jint dimension; | |
932 symbolOop object_key; | |
933 | |
934 // dimension and object_key are assigned as a side-effect of this call | |
935 BasicType t = FieldType::get_array_info(class_name(), &dimension, | |
936 &object_key, CHECK_(NULL)); | |
937 if (t != T_OBJECT) { | |
938 k = Universe::typeArrayKlassObj(t); | |
939 } else { | |
940 symbolHandle h_key(THREAD, object_key); | |
941 k = SystemDictionary::find(h_key, class_loader, protection_domain, THREAD); | |
942 } | |
943 if (k != NULL) { | |
944 k = Klass::cast(k)->array_klass_or_null(dimension); | |
945 } | |
946 } else { | |
947 k = find(class_name, class_loader, protection_domain, THREAD); | |
948 } | |
949 return k; | |
950 } | |
951 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
952 // Quick range check for names of well-known classes: |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
953 static symbolOop wk_klass_name_limits[2] = {NULL, NULL}; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
954 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
955 #ifndef PRODUCT |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
956 static int find_wkk_calls, find_wkk_probes, find_wkk_wins; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
957 // counts for "hello world": 3983, 1616, 1075 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
958 // => 60% hit after limit guard, 25% total win rate |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
959 #endif |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
960 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
961 klassOop SystemDictionary::find_well_known_klass(symbolOop class_name) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
962 // A bounds-check on class_name will quickly get a negative result. |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
963 NOT_PRODUCT(find_wkk_calls++); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
964 if (class_name >= wk_klass_name_limits[0] && |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
965 class_name <= wk_klass_name_limits[1]) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
966 NOT_PRODUCT(find_wkk_probes++); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
967 vmSymbols::SID sid = vmSymbols::find_sid(class_name); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
968 if (sid != vmSymbols::NO_SID) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
969 klassOop k = NULL; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
970 switch (sid) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
971 #define WK_KLASS_CASE(name, symbol, ignore_option) \ |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
972 case vmSymbols::VM_SYMBOL_ENUM_NAME(symbol): \ |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
973 k = WK_KLASS(name); break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
974 WK_KLASSES_DO(WK_KLASS_CASE) |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
975 #undef WK_KLASS_CASE |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
976 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
977 NOT_PRODUCT(if (k != NULL) find_wkk_wins++); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
978 return k; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
979 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
980 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
981 return NULL; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
982 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
983 |
0 | 984 // Note: this method is much like resolve_from_stream, but |
985 // updates no supplemental data structures. | |
986 // TODO consolidate the two methods with a helper routine? | |
987 klassOop SystemDictionary::parse_stream(symbolHandle class_name, | |
988 Handle class_loader, | |
989 Handle protection_domain, | |
990 ClassFileStream* st, | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
991 KlassHandle host_klass, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
992 GrowableArray<Handle>* cp_patches, |
0 | 993 TRAPS) { |
994 symbolHandle parsed_name; | |
995 | |
996 // Parse the stream. Note that we do this even though this klass might | |
997 // already be present in the SystemDictionary, otherwise we would not | |
998 // throw potential ClassFormatErrors. | |
999 // | |
1000 // Note: "name" is updated. | |
1001 // Further note: a placeholder will be added for this class when | |
1002 // super classes are loaded (resolve_super_or_fail). We expect this | |
1003 // to be called for all classes but java.lang.Object; and we preload | |
1004 // java.lang.Object through resolve_or_fail, not this path. | |
1005 | |
1006 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, | |
1007 class_loader, | |
1008 protection_domain, | |
710 | 1009 host_klass, |
1010 cp_patches, | |
0 | 1011 parsed_name, |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
875
diff
changeset
|
1012 true, |
0 | 1013 THREAD); |
1014 | |
514 | 1015 |
0 | 1016 // We don't redefine the class, so we just need to clean up whether there |
1017 // was an error or not (don't want to modify any system dictionary | |
1018 // data structures). | |
1019 // Parsed name could be null if we threw an error before we got far | |
1020 // enough along to parse it -- in that case, there is nothing to clean up. | |
1021 if (!parsed_name.is_null()) { | |
1022 unsigned int p_hash = placeholders()->compute_hash(parsed_name, | |
1023 class_loader); | |
1024 int p_index = placeholders()->hash_to_index(p_hash); | |
1025 { | |
1026 MutexLocker mu(SystemDictionary_lock, THREAD); | |
1027 placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD); | |
1028 SystemDictionary_lock->notify_all(); | |
1029 } | |
1030 } | |
1031 | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1032 if (host_klass.not_null() && k.not_null()) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1033 assert(AnonymousClasses, ""); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1034 // If it's anonymous, initialize it now, since nobody else will. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1035 k->set_host_klass(host_klass()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1036 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1037 { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1038 MutexLocker mu_r(Compile_lock, THREAD); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1039 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1040 // Add to class hierarchy, initialize vtables, and do possible |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1041 // deoptimizations. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1042 add_to_hierarchy(k, CHECK_NULL); // No exception, but can block |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1043 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1044 // But, do not add to system dictionary. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1045 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1046 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1047 k->eager_initialize(THREAD); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1048 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1049 // notify jvmti |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1050 if (JvmtiExport::should_post_class_load()) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1051 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1052 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1053 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1054 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1055 |
0 | 1056 return k(); |
1057 } | |
1058 | |
1059 // Add a klass to the system from a stream (called by jni_DefineClass and | |
1060 // JVM_DefineClass). | |
1061 // Note: class_name can be NULL. In that case we do not know the name of | |
1062 // the class until we have parsed the stream. | |
1063 | |
1064 klassOop SystemDictionary::resolve_from_stream(symbolHandle class_name, | |
1065 Handle class_loader, | |
1066 Handle protection_domain, | |
1067 ClassFileStream* st, | |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
875
diff
changeset
|
1068 bool verify, |
0 | 1069 TRAPS) { |
1070 | |
514 | 1071 // Classloaders that support parallelism, e.g. bootstrap classloader, |
1072 // or all classloaders with UnsyncloadClass do not acquire lock here | |
1073 bool DoObjectLock = true; | |
1074 if (is_parallelCapable(class_loader)) { | |
1075 DoObjectLock = false; | |
1076 } | |
1077 | |
1078 // Make sure we are synchronized on the class loader before we proceed | |
0 | 1079 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
1080 check_loader_lock_contention(lockObject, THREAD); | |
514 | 1081 ObjectLocker ol(lockObject, THREAD, DoObjectLock); |
0 | 1082 |
1083 symbolHandle parsed_name; | |
1084 | |
1085 // Parse the stream. Note that we do this even though this klass might | |
1086 // already be present in the SystemDictionary, otherwise we would not | |
1087 // throw potential ClassFormatErrors. | |
1088 // | |
1089 // Note: "name" is updated. | |
1090 // Further note: a placeholder will be added for this class when | |
1091 // super classes are loaded (resolve_super_or_fail). We expect this | |
1092 // to be called for all classes but java.lang.Object; and we preload | |
1093 // java.lang.Object through resolve_or_fail, not this path. | |
1094 | |
1095 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, | |
1096 class_loader, | |
1097 protection_domain, | |
1098 parsed_name, | |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
875
diff
changeset
|
1099 verify, |
0 | 1100 THREAD); |
1101 | |
1102 const char* pkg = "java/"; | |
1103 if (!HAS_PENDING_EXCEPTION && | |
1104 !class_loader.is_null() && | |
1105 !parsed_name.is_null() && | |
1106 !strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) { | |
1107 // It is illegal to define classes in the "java." package from | |
1108 // JVM_DefineClass or jni_DefineClass unless you're the bootclassloader | |
1109 ResourceMark rm(THREAD); | |
1110 char* name = parsed_name->as_C_string(); | |
1111 char* index = strrchr(name, '/'); | |
1112 *index = '\0'; // chop to just the package name | |
1113 while ((index = strchr(name, '/')) != NULL) { | |
1114 *index = '.'; // replace '/' with '.' in package name | |
1115 } | |
1116 const char* fmt = "Prohibited package name: %s"; | |
1117 size_t len = strlen(fmt) + strlen(name); | |
1118 char* message = NEW_RESOURCE_ARRAY(char, len); | |
1119 jio_snprintf(message, len, fmt, name); | |
1120 Exceptions::_throw_msg(THREAD_AND_LOCATION, | |
1121 vmSymbols::java_lang_SecurityException(), message); | |
1122 } | |
1123 | |
1124 if (!HAS_PENDING_EXCEPTION) { | |
1125 assert(!parsed_name.is_null(), "Sanity"); | |
1126 assert(class_name.is_null() || class_name() == parsed_name(), | |
1127 "name mismatch"); | |
1128 // Verification prevents us from creating names with dots in them, this | |
1129 // asserts that that's the case. | |
1130 assert(is_internal_format(parsed_name), | |
1131 "external class name format used internally"); | |
1132 | |
1133 // Add class just loaded | |
514 | 1134 // If a class loader supports parallel classloading handle parallel define requests |
1135 // find_or_define_instance_class may return a different instanceKlass | |
1136 if (is_parallelCapable(class_loader)) { | |
1137 k = find_or_define_instance_class(class_name, class_loader, k, THREAD); | |
1138 } else { | |
1139 define_instance_class(k, THREAD); | |
1140 } | |
0 | 1141 } |
1142 | |
1143 // If parsing the class file or define_instance_class failed, we | |
1144 // need to remove the placeholder added on our behalf. But we | |
1145 // must make sure parsed_name is valid first (it won't be if we had | |
1146 // a format error before the class was parsed far enough to | |
1147 // find the name). | |
1148 if (HAS_PENDING_EXCEPTION && !parsed_name.is_null()) { | |
1149 unsigned int p_hash = placeholders()->compute_hash(parsed_name, | |
1150 class_loader); | |
1151 int p_index = placeholders()->hash_to_index(p_hash); | |
1152 { | |
1153 MutexLocker mu(SystemDictionary_lock, THREAD); | |
1154 placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD); | |
1155 SystemDictionary_lock->notify_all(); | |
1156 } | |
1157 return NULL; | |
1158 } | |
1159 | |
1160 // Make sure that we didn't leave a place holder in the | |
1161 // SystemDictionary; this is only done on success | |
1162 debug_only( { | |
1163 if (!HAS_PENDING_EXCEPTION) { | |
1164 assert(!parsed_name.is_null(), "parsed_name is still null?"); | |
1165 symbolHandle h_name (THREAD, k->name()); | |
1166 Handle h_loader (THREAD, k->class_loader()); | |
1167 | |
1168 MutexLocker mu(SystemDictionary_lock, THREAD); | |
1169 | |
1170 oop check = find_class_or_placeholder(parsed_name, class_loader); | |
1171 assert(check == k(), "should be present in the dictionary"); | |
1172 | |
1173 oop check2 = find_class_or_placeholder(h_name, h_loader); | |
1174 assert(check == check2, "name inconsistancy in SystemDictionary"); | |
1175 } | |
1176 } ); | |
1177 | |
1178 return k(); | |
1179 } | |
1180 | |
1181 | |
1182 void SystemDictionary::set_shared_dictionary(HashtableBucket* t, int length, | |
1183 int number_of_entries) { | |
1184 assert(length == _nof_buckets * sizeof(HashtableBucket), | |
1185 "bad shared dictionary size."); | |
1186 _shared_dictionary = new Dictionary(_nof_buckets, t, number_of_entries); | |
1187 } | |
1188 | |
1189 | |
1190 // If there is a shared dictionary, then find the entry for the | |
1191 // given shared system class, if any. | |
1192 | |
1193 klassOop SystemDictionary::find_shared_class(symbolHandle class_name) { | |
1194 if (shared_dictionary() != NULL) { | |
1195 unsigned int d_hash = dictionary()->compute_hash(class_name, Handle()); | |
1196 int d_index = dictionary()->hash_to_index(d_hash); | |
1197 return shared_dictionary()->find_shared_class(d_index, d_hash, class_name); | |
1198 } else { | |
1199 return NULL; | |
1200 } | |
1201 } | |
1202 | |
1203 | |
1204 // Load a class from the shared spaces (found through the shared system | |
1205 // dictionary). Force the superclass and all interfaces to be loaded. | |
1206 // Update the class definition to include sibling classes and no | |
1207 // subclasses (yet). [Classes in the shared space are not part of the | |
1208 // object hierarchy until loaded.] | |
1209 | |
1210 instanceKlassHandle SystemDictionary::load_shared_class( | |
1211 symbolHandle class_name, Handle class_loader, TRAPS) { | |
1212 instanceKlassHandle ik (THREAD, find_shared_class(class_name)); | |
1213 return load_shared_class(ik, class_loader, THREAD); | |
1214 } | |
1215 | |
1216 // Note well! Changes to this method may affect oop access order | |
1217 // in the shared archive. Please take care to not make changes that | |
1218 // adversely affect cold start time by changing the oop access order | |
1219 // that is specified in dump.cpp MarkAndMoveOrderedReadOnly and | |
1220 // MarkAndMoveOrderedReadWrite closures. | |
1221 instanceKlassHandle SystemDictionary::load_shared_class( | |
1222 instanceKlassHandle ik, Handle class_loader, TRAPS) { | |
1223 assert(class_loader.is_null(), "non-null classloader for shared class?"); | |
1224 if (ik.not_null()) { | |
1225 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | |
1226 symbolHandle class_name(THREAD, ik->name()); | |
1227 | |
1228 // Found the class, now load the superclass and interfaces. If they | |
1229 // are shared, add them to the main system dictionary and reset | |
1230 // their hierarchy references (supers, subs, and interfaces). | |
1231 | |
1232 if (ik->super() != NULL) { | |
1233 symbolHandle cn(THREAD, ik->super()->klass_part()->name()); | |
1234 resolve_super_or_fail(class_name, cn, | |
1235 class_loader, Handle(), true, CHECK_(nh)); | |
1236 } | |
1237 | |
1238 objArrayHandle interfaces (THREAD, ik->local_interfaces()); | |
1239 int num_interfaces = interfaces->length(); | |
1240 for (int index = 0; index < num_interfaces; index++) { | |
1241 klassOop k = klassOop(interfaces->obj_at(index)); | |
1242 | |
1243 // Note: can not use instanceKlass::cast here because | |
1244 // interfaces' instanceKlass's C++ vtbls haven't been | |
1245 // reinitialized yet (they will be once the interface classes | |
1246 // are loaded) | |
1247 symbolHandle name (THREAD, k->klass_part()->name()); | |
1248 resolve_super_or_fail(class_name, name, class_loader, Handle(), false, CHECK_(nh)); | |
1249 } | |
1250 | |
1251 // Adjust methods to recover missing data. They need addresses for | |
1252 // interpreter entry points and their default native method address | |
1253 // must be reset. | |
1254 | |
1255 // Updating methods must be done under a lock so multiple | |
1256 // threads don't update these in parallel | |
1257 // Shared classes are all currently loaded by the bootstrap | |
1258 // classloader, so this will never cause a deadlock on | |
1259 // a custom class loader lock. | |
1260 | |
1261 { | |
1262 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); | |
1263 check_loader_lock_contention(lockObject, THREAD); | |
1264 ObjectLocker ol(lockObject, THREAD, true); | |
1265 | |
1266 objArrayHandle methods (THREAD, ik->methods()); | |
1267 int num_methods = methods->length(); | |
1268 for (int index2 = 0; index2 < num_methods; ++index2) { | |
1269 methodHandle m(THREAD, methodOop(methods->obj_at(index2))); | |
1270 m()->link_method(m, CHECK_(nh)); | |
1271 } | |
1272 } | |
1273 | |
1274 if (TraceClassLoading) { | |
1275 ResourceMark rm; | |
1276 tty->print("[Loaded %s", ik->external_name()); | |
1277 tty->print(" from shared objects file"); | |
1278 tty->print_cr("]"); | |
1279 } | |
1280 // notify a class loaded from shared object | |
1281 ClassLoadingService::notify_class_loaded(instanceKlass::cast(ik()), | |
1282 true /* shared class */); | |
1283 } | |
1284 return ik; | |
1285 } | |
1286 | |
1287 #ifdef KERNEL | |
1288 // Some classes on the bootstrap class path haven't been installed on the | |
1289 // system yet. Call the DownloadManager method to make them appear in the | |
1290 // bootstrap class path and try again to load the named class. | |
1291 // Note that with delegation class loaders all classes in another loader will | |
1292 // first try to call this so it'd better be fast!! | |
1293 static instanceKlassHandle download_and_retry_class_load( | |
1294 symbolHandle class_name, | |
1295 TRAPS) { | |
1296 | |
1297 klassOop dlm = SystemDictionary::sun_jkernel_DownloadManager_klass(); | |
1298 instanceKlassHandle nk; | |
1299 | |
1300 // If download manager class isn't loaded just return. | |
1301 if (dlm == NULL) return nk; | |
1302 | |
1303 { HandleMark hm(THREAD); | |
1304 ResourceMark rm(THREAD); | |
1305 Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nk)); | |
1306 Handle class_string = java_lang_String::externalize_classname(s, CHECK_(nk)); | |
1307 | |
1308 // return value | |
1309 JavaValue result(T_OBJECT); | |
1310 | |
1311 // Call the DownloadManager. We assume that it has a lock because | |
1312 // multiple classes could be not found and downloaded at the same time. | |
1313 // class sun.misc.DownloadManager; | |
1314 // public static String getBootClassPathEntryForClass(String className); | |
1315 JavaCalls::call_static(&result, | |
1316 KlassHandle(THREAD, dlm), | |
1317 vmSymbolHandles::getBootClassPathEntryForClass_name(), | |
1318 vmSymbolHandles::string_string_signature(), | |
1319 class_string, | |
1320 CHECK_(nk)); | |
1321 | |
1322 // Get result.string and add to bootclasspath | |
1323 assert(result.get_type() == T_OBJECT, "just checking"); | |
1324 oop obj = (oop) result.get_jobject(); | |
1325 if (obj == NULL) { return nk; } | |
1326 | |
22
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
1327 Handle h_obj(THREAD, obj); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
1328 char* new_class_name = java_lang_String::as_platform_dependent_str(h_obj, |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
1329 CHECK_(nk)); |
0 | 1330 |
1331 // lock the loader | |
1332 // we use this lock because JVMTI does. | |
1333 Handle loader_lock(THREAD, SystemDictionary::system_loader_lock()); | |
1334 | |
1335 ObjectLocker ol(loader_lock, THREAD); | |
1336 // add the file to the bootclasspath | |
1337 ClassLoader::update_class_path_entry_list(new_class_name, true); | |
1338 } // end HandleMark | |
1339 | |
1340 if (TraceClassLoading) { | |
1341 ClassLoader::print_bootclasspath(); | |
1342 } | |
1343 return ClassLoader::load_classfile(class_name, CHECK_(nk)); | |
1344 } | |
1345 #endif // KERNEL | |
1346 | |
1347 | |
1348 instanceKlassHandle SystemDictionary::load_instance_class(symbolHandle class_name, Handle class_loader, TRAPS) { | |
1349 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | |
1350 if (class_loader.is_null()) { | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1351 |
0 | 1352 // Search the shared system dictionary for classes preloaded into the |
1353 // shared spaces. | |
1354 instanceKlassHandle k; | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1355 { |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1356 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time()); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1357 k = load_shared_class(class_name, class_loader, THREAD); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1358 } |
0 | 1359 |
1360 if (k.is_null()) { | |
1361 // Use VM class loader | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1362 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time()); |
0 | 1363 k = ClassLoader::load_classfile(class_name, CHECK_(nh)); |
1364 } | |
1365 | |
1366 #ifdef KERNEL | |
1367 // If the VM class loader has failed to load the class, call the | |
1368 // DownloadManager class to make it magically appear on the classpath | |
1369 // and try again. This is only configured with the Kernel VM. | |
1370 if (k.is_null()) { | |
1371 k = download_and_retry_class_load(class_name, CHECK_(nh)); | |
1372 } | |
1373 #endif // KERNEL | |
1374 | |
514 | 1375 // find_or_define_instance_class may return a different instanceKlass |
0 | 1376 if (!k.is_null()) { |
1377 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh)); | |
1378 } | |
1379 return k; | |
1380 } else { | |
1381 // Use user specified class loader to load class. Call loadClass operation on class_loader. | |
1382 ResourceMark rm(THREAD); | |
1383 | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1384 assert(THREAD->is_Java_thread(), "must be a JavaThread"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1385 JavaThread* jt = (JavaThread*) THREAD; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1386 |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1387 PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(), |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1388 ClassLoader::perf_app_classload_selftime(), |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1389 ClassLoader::perf_app_classload_count(), |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1390 jt->get_thread_stat()->perf_recursion_counts_addr(), |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1391 jt->get_thread_stat()->perf_timers_addr(), |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1392 PerfClassTraceTime::CLASS_LOAD); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
726
diff
changeset
|
1393 |
0 | 1394 Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nh)); |
1395 // Translate to external class name format, i.e., convert '/' chars to '.' | |
1396 Handle string = java_lang_String::externalize_classname(s, CHECK_(nh)); | |
1397 | |
1398 JavaValue result(T_OBJECT); | |
1399 | |
1142 | 1400 KlassHandle spec_klass (THREAD, SystemDictionary::ClassLoader_klass()); |
0 | 1401 |
514 | 1402 // Call public unsynchronized loadClass(String) directly for all class loaders |
1403 // for parallelCapable class loaders. JDK >=7, loadClass(String, boolean) will | |
1404 // acquire a class-name based lock rather than the class loader object lock. | |
1405 // JDK < 7 already acquire the class loader lock in loadClass(String, boolean), | |
1406 // so the call to loadClassInternal() was not required. | |
1407 // | |
1408 // UnsyncloadClass flag means both call loadClass(String) and do | |
1409 // not acquire the class loader lock even for class loaders that are | |
1410 // not parallelCapable. This was a risky transitional | |
1411 // flag for diagnostic purposes only. It is risky to call | |
0 | 1412 // custom class loaders without synchronization. |
1413 // WARNING If a custom class loader does NOT synchronizer findClass, or callers of | |
514 | 1414 // findClass, the UnsyncloadClass flag risks unexpected timing bugs in the field. |
0 | 1415 // Do NOT assume this will be supported in future releases. |
514 | 1416 // |
1417 // Added MustCallLoadClassInternal in case we discover in the field | |
1418 // a customer that counts on this call | |
1419 if (MustCallLoadClassInternal && has_loadClassInternal()) { | |
0 | 1420 JavaCalls::call_special(&result, |
1421 class_loader, | |
1422 spec_klass, | |
1423 vmSymbolHandles::loadClassInternal_name(), | |
1424 vmSymbolHandles::string_class_signature(), | |
1425 string, | |
1426 CHECK_(nh)); | |
1427 } else { | |
1428 JavaCalls::call_virtual(&result, | |
1429 class_loader, | |
1430 spec_klass, | |
1431 vmSymbolHandles::loadClass_name(), | |
1432 vmSymbolHandles::string_class_signature(), | |
1433 string, | |
1434 CHECK_(nh)); | |
1435 } | |
1436 | |
1437 assert(result.get_type() == T_OBJECT, "just checking"); | |
1438 oop obj = (oop) result.get_jobject(); | |
1439 | |
1440 // Primitive classes return null since forName() can not be | |
1441 // used to obtain any of the Class objects representing primitives or void | |
1442 if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) { | |
1443 instanceKlassHandle k = | |
1444 instanceKlassHandle(THREAD, java_lang_Class::as_klassOop(obj)); | |
1445 // For user defined Java class loaders, check that the name returned is | |
1446 // the same as that requested. This check is done for the bootstrap | |
1447 // loader when parsing the class file. | |
1448 if (class_name() == k->name()) { | |
1449 return k; | |
1450 } | |
1451 } | |
1452 // Class is not found or has the wrong name, return NULL | |
1453 return nh; | |
1454 } | |
1455 } | |
1456 | |
1457 void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) { | |
1458 | |
1459 Handle class_loader_h(THREAD, k->class_loader()); | |
1460 | |
514 | 1461 // for bootstrap and other parallel classloaders don't acquire lock, |
1462 // use placeholder token | |
1463 // If a parallelCapable class loader calls define_instance_class instead of | |
1464 // find_or_define_instance_class to get here, we have a timing | |
1465 // hole with systemDictionary updates and check_constraints | |
1466 if (!class_loader_h.is_null() && !is_parallelCapable(class_loader_h)) { | |
0 | 1467 assert(ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, |
1468 compute_loader_lock_object(class_loader_h, THREAD)), | |
1469 "define called without lock"); | |
1470 } | |
1471 | |
1472 // Check class-loading constraints. Throw exception if violation is detected. | |
1473 // Grabs and releases SystemDictionary_lock | |
1474 // The check_constraints/find_class call and update_dictionary sequence | |
1475 // must be "atomic" for a specific class/classloader pair so we never | |
1476 // define two different instanceKlasses for that class/classloader pair. | |
1477 // Existing classloaders will call define_instance_class with the | |
1478 // classloader lock held | |
1479 // Parallel classloaders will call find_or_define_instance_class | |
1480 // which will require a token to perform the define class | |
1481 symbolHandle name_h(THREAD, k->name()); | |
1482 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h); | |
1483 int d_index = dictionary()->hash_to_index(d_hash); | |
1484 check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK); | |
1485 | |
1486 // Register class just loaded with class loader (placed in Vector) | |
1487 // Note we do this before updating the dictionary, as this can | |
1488 // fail with an OutOfMemoryError (if it does, we will *not* put this | |
1489 // class in the dictionary and will not update the class hierarchy). | |
1490 if (k->class_loader() != NULL) { | |
1491 methodHandle m(THREAD, Universe::loader_addClass_method()); | |
1492 JavaValue result(T_VOID); | |
1493 JavaCallArguments args(class_loader_h); | |
1494 args.push_oop(Handle(THREAD, k->java_mirror())); | |
1495 JavaCalls::call(&result, m, &args, CHECK); | |
1496 } | |
1497 | |
1498 // Add the new class. We need recompile lock during update of CHA. | |
1499 { | |
1500 unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader_h); | |
1501 int p_index = placeholders()->hash_to_index(p_hash); | |
1502 | |
1503 MutexLocker mu_r(Compile_lock, THREAD); | |
1504 | |
1505 // Add to class hierarchy, initialize vtables, and do possible | |
1506 // deoptimizations. | |
1507 add_to_hierarchy(k, CHECK); // No exception, but can block | |
1508 | |
1509 // Add to systemDictionary - so other classes can see it. | |
1510 // Grabs and releases SystemDictionary_lock | |
1511 update_dictionary(d_index, d_hash, p_index, p_hash, | |
1512 k, class_loader_h, THREAD); | |
1513 } | |
1514 k->eager_initialize(THREAD); | |
1515 | |
1516 // notify jvmti | |
1517 if (JvmtiExport::should_post_class_load()) { | |
1518 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); | |
1519 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); | |
1520 | |
1521 } | |
1522 } | |
1523 | |
1524 // Support parallel classloading | |
1075
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
1525 // All parallel class loaders, including bootstrap classloader |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
1526 // lock a placeholder entry for this class/class_loader pair |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
1527 // to allow parallel defines of different classes for this class loader |
514 | 1528 // With AllowParallelDefine flag==true, in case they do not synchronize around |
1529 // FindLoadedClass/DefineClass, calls, we check for parallel | |
0 | 1530 // loading for them, wait if a defineClass is in progress |
1531 // and return the initial requestor's results | |
1075
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
1532 // This flag does not apply to the bootstrap classloader. |
514 | 1533 // With AllowParallelDefine flag==false, call through to define_instance_class |
1534 // which will throw LinkageError: duplicate class definition. | |
1075
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
1535 // False is the requested default. |
0 | 1536 // For better performance, the class loaders should synchronize |
514 | 1537 // findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they |
0 | 1538 // potentially waste time reading and parsing the bytestream. |
1539 // Note: VM callers should ensure consistency of k/class_name,class_loader | |
1540 instanceKlassHandle SystemDictionary::find_or_define_instance_class(symbolHandle class_name, Handle class_loader, instanceKlassHandle k, TRAPS) { | |
1541 | |
1542 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | |
515 | 1543 symbolHandle name_h(THREAD, k->name()); // passed in class_name may be null |
0 | 1544 |
515 | 1545 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader); |
0 | 1546 int d_index = dictionary()->hash_to_index(d_hash); |
1547 | |
1548 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS | |
515 | 1549 unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader); |
0 | 1550 int p_index = placeholders()->hash_to_index(p_hash); |
1551 PlaceholderEntry* probe; | |
1552 | |
1553 { | |
1554 MutexLocker mu(SystemDictionary_lock, THREAD); | |
1555 // First check if class already defined | |
1075
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
1556 if (UnsyncloadClass || (is_parallelDefine(class_loader))) { |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
1557 klassOop check = find_class(d_index, d_hash, name_h, class_loader); |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
1558 if (check != NULL) { |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
1559 return(instanceKlassHandle(THREAD, check)); |
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
1560 } |
0 | 1561 } |
1562 | |
1563 // Acquire define token for this class/classloader | |
1564 symbolHandle nullsymbolHandle; | |
515 | 1565 probe = placeholders()->find_and_add(p_index, p_hash, name_h, class_loader, PlaceholderTable::DEFINE_CLASS, nullsymbolHandle, THREAD); |
514 | 1566 // Wait if another thread defining in parallel |
1567 // All threads wait - even those that will throw duplicate class: otherwise | |
1568 // caller is surprised by LinkageError: duplicate, but findLoadedClass fails | |
1569 // if other thread has not finished updating dictionary | |
1570 while (probe->definer() != NULL) { | |
1571 SystemDictionary_lock->wait(); | |
1572 } | |
1573 // Only special cases allow parallel defines and can use other thread's results | |
1574 // Other cases fall through, and may run into duplicate defines | |
1575 // caught by finding an entry in the SystemDictionary | |
1075
a75edfd400ea
6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents:
1039
diff
changeset
|
1576 if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instanceKlass() != NULL)) { |
0 | 1577 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); |
515 | 1578 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD); |
514 | 1579 SystemDictionary_lock->notify_all(); |
0 | 1580 #ifdef ASSERT |
515 | 1581 klassOop check = find_class(d_index, d_hash, name_h, class_loader); |
514 | 1582 assert(check != NULL, "definer missed recording success"); |
0 | 1583 #endif |
514 | 1584 return(instanceKlassHandle(THREAD, probe->instanceKlass())); |
0 | 1585 } else { |
514 | 1586 // This thread will define the class (even if earlier thread tried and had an error) |
1587 probe->set_definer(THREAD); | |
0 | 1588 } |
1589 } | |
1590 | |
1591 define_instance_class(k, THREAD); | |
1592 | |
1593 Handle linkage_exception = Handle(); // null handle | |
1594 | |
1595 // definer must notify any waiting threads | |
1596 { | |
1597 MutexLocker mu(SystemDictionary_lock, THREAD); | |
515 | 1598 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name_h, class_loader); |
0 | 1599 assert(probe != NULL, "DEFINE_CLASS placeholder lost?"); |
1600 if (probe != NULL) { | |
1601 if (HAS_PENDING_EXCEPTION) { | |
1602 linkage_exception = Handle(THREAD,PENDING_EXCEPTION); | |
1603 CLEAR_PENDING_EXCEPTION; | |
1604 } else { | |
1605 probe->set_instanceKlass(k()); | |
1606 } | |
1607 probe->set_definer(NULL); | |
1608 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); | |
515 | 1609 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD); |
0 | 1610 SystemDictionary_lock->notify_all(); |
1611 } | |
1612 } | |
1613 | |
1614 // Can't throw exception while holding lock due to rank ordering | |
1615 if (linkage_exception() != NULL) { | |
1616 THROW_OOP_(linkage_exception(), nh); // throws exception and returns | |
1617 } | |
1618 | |
1619 return k; | |
1620 } | |
1621 Handle SystemDictionary::compute_loader_lock_object(Handle class_loader, TRAPS) { | |
1622 // If class_loader is NULL we synchronize on _system_loader_lock_obj | |
1623 if (class_loader.is_null()) { | |
1624 return Handle(THREAD, _system_loader_lock_obj); | |
1625 } else { | |
1626 return class_loader; | |
1627 } | |
1628 } | |
1629 | |
1630 // This method is added to check how often we have to wait to grab loader | |
1631 // lock. The results are being recorded in the performance counters defined in | |
1632 // ClassLoader::_sync_systemLoaderLockContentionRate and | |
1633 // ClassLoader::_sync_nonSystemLoaderLockConteionRate. | |
1634 void SystemDictionary::check_loader_lock_contention(Handle loader_lock, TRAPS) { | |
1635 if (!UsePerfData) { | |
1636 return; | |
1637 } | |
1638 | |
1639 assert(!loader_lock.is_null(), "NULL lock object"); | |
1640 | |
1641 if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader_lock) | |
1642 == ObjectSynchronizer::owner_other) { | |
1643 // contention will likely happen, so increment the corresponding | |
1644 // contention counter. | |
1645 if (loader_lock() == _system_loader_lock_obj) { | |
1646 ClassLoader::sync_systemLoaderLockContentionRate()->inc(); | |
1647 } else { | |
1648 ClassLoader::sync_nonSystemLoaderLockContentionRate()->inc(); | |
1649 } | |
1650 } | |
1651 } | |
1652 | |
1653 // ---------------------------------------------------------------------------- | |
1654 // Lookup | |
1655 | |
1656 klassOop SystemDictionary::find_class(int index, unsigned int hash, | |
1657 symbolHandle class_name, | |
1658 Handle class_loader) { | |
1659 assert_locked_or_safepoint(SystemDictionary_lock); | |
1660 assert (index == dictionary()->index_for(class_name, class_loader), | |
1661 "incorrect index?"); | |
1662 | |
1663 klassOop k = dictionary()->find_class(index, hash, class_name, class_loader); | |
1664 return k; | |
1665 } | |
1666 | |
1667 | |
1668 // Basic find on classes in the midst of being loaded | |
1669 symbolOop SystemDictionary::find_placeholder(int index, unsigned int hash, | |
1670 symbolHandle class_name, | |
1671 Handle class_loader) { | |
1672 assert_locked_or_safepoint(SystemDictionary_lock); | |
1673 | |
1674 return placeholders()->find_entry(index, hash, class_name, class_loader); | |
1675 } | |
1676 | |
1677 | |
1678 // Used for assertions and verification only | |
1679 oop SystemDictionary::find_class_or_placeholder(symbolHandle class_name, | |
1680 Handle class_loader) { | |
1681 #ifndef ASSERT | |
1682 guarantee(VerifyBeforeGC || | |
1683 VerifyDuringGC || | |
1684 VerifyBeforeExit || | |
1685 VerifyAfterGC, "too expensive"); | |
1686 #endif | |
1687 assert_locked_or_safepoint(SystemDictionary_lock); | |
1688 symbolOop class_name_ = class_name(); | |
1689 oop class_loader_ = class_loader(); | |
1690 | |
1691 // First look in the loaded class array | |
1692 unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader); | |
1693 int d_index = dictionary()->hash_to_index(d_hash); | |
1694 oop lookup = find_class(d_index, d_hash, class_name, class_loader); | |
1695 | |
1696 if (lookup == NULL) { | |
1697 // Next try the placeholders | |
1698 unsigned int p_hash = placeholders()->compute_hash(class_name,class_loader); | |
1699 int p_index = placeholders()->hash_to_index(p_hash); | |
1700 lookup = find_placeholder(p_index, p_hash, class_name, class_loader); | |
1701 } | |
1702 | |
1703 return lookup; | |
1704 } | |
1705 | |
1706 | |
1707 // Get the next class in the diictionary. | |
1708 klassOop SystemDictionary::try_get_next_class() { | |
1709 return dictionary()->try_get_next_class(); | |
1710 } | |
1711 | |
1712 | |
1713 // ---------------------------------------------------------------------------- | |
1714 // Update hierachy. This is done before the new klass has been added to the SystemDictionary. The Recompile_lock | |
1715 // is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in | |
1716 // before a new class is used. | |
1717 | |
1718 void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) { | |
1719 assert(k.not_null(), "just checking"); | |
1720 // Link into hierachy. Make sure the vtables are initialized before linking into | |
1721 k->append_to_sibling_list(); // add to superklass/sibling list | |
1722 k->process_interfaces(THREAD); // handle all "implements" declarations | |
1723 k->set_init_state(instanceKlass::loaded); | |
1724 // Now flush all code that depended on old class hierarchy. | |
1725 // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97) | |
1726 // Also, first reinitialize vtable because it may have gotten out of synch | |
1727 // while the new class wasn't connected to the class hierarchy. | |
1728 Universe::flush_dependents_on(k); | |
1729 } | |
1730 | |
1731 | |
1732 // ---------------------------------------------------------------------------- | |
1733 // GC support | |
1734 | |
1735 // Following roots during mark-sweep is separated in two phases. | |
1736 // | |
1737 // The first phase follows preloaded classes and all other system | |
1738 // classes, since these will never get unloaded anyway. | |
1739 // | |
1740 // The second phase removes (unloads) unreachable classes from the | |
1741 // system dictionary and follows the remaining classes' contents. | |
1742 | |
1743 void SystemDictionary::always_strong_oops_do(OopClosure* blk) { | |
1744 // Follow preloaded classes/mirrors and system loader object | |
1745 blk->do_oop(&_java_system_loader); | |
1746 preloaded_oops_do(blk); | |
1747 always_strong_classes_do(blk); | |
1748 } | |
1749 | |
1750 | |
1751 void SystemDictionary::always_strong_classes_do(OopClosure* blk) { | |
1752 // Follow all system classes and temporary placeholders in dictionary | |
1753 dictionary()->always_strong_classes_do(blk); | |
1754 | |
1755 // Placeholders. These are *always* strong roots, as they | |
1756 // represent classes we're actively loading. | |
1757 placeholders_do(blk); | |
1758 | |
710 | 1759 // Visit extra methods |
1903 | 1760 invoke_method_table()->oops_do(blk); |
710 | 1761 |
0 | 1762 // Loader constraints. We must keep the symbolOop used in the name alive. |
1763 constraints()->always_strong_classes_do(blk); | |
1764 | |
1765 // Resolution errors keep the symbolOop for the error alive | |
1766 resolution_errors()->always_strong_classes_do(blk); | |
1767 } | |
1768 | |
1769 | |
1770 void SystemDictionary::placeholders_do(OopClosure* blk) { | |
1771 placeholders()->oops_do(blk); | |
1772 } | |
1773 | |
1774 | |
1775 bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) { | |
1776 bool result = dictionary()->do_unloading(is_alive); | |
1777 constraints()->purge_loader_constraints(is_alive); | |
1778 resolution_errors()->purge_resolution_errors(is_alive); | |
1779 return result; | |
1780 } | |
1781 | |
1782 | |
1783 // The mirrors are scanned by shared_oops_do() which is | |
1784 // not called by oops_do(). In order to process oops in | |
1785 // a necessary order, shared_oops_do() is call by | |
1786 // Universe::oops_do(). | |
1787 void SystemDictionary::oops_do(OopClosure* f) { | |
1788 // Adjust preloaded classes and system loader object | |
1789 f->do_oop(&_java_system_loader); | |
1790 preloaded_oops_do(f); | |
1791 | |
1792 lazily_loaded_oops_do(f); | |
1793 | |
1794 // Adjust dictionary | |
1795 dictionary()->oops_do(f); | |
1796 | |
710 | 1797 // Visit extra methods |
1903 | 1798 invoke_method_table()->oops_do(f); |
710 | 1799 |
0 | 1800 // Partially loaded classes |
1801 placeholders()->oops_do(f); | |
1802 | |
1803 // Adjust constraint table | |
1804 constraints()->oops_do(f); | |
1805 | |
1806 // Adjust resolution error table | |
1807 resolution_errors()->oops_do(f); | |
1808 } | |
1809 | |
1810 | |
1811 void SystemDictionary::preloaded_oops_do(OopClosure* f) { | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1812 f->do_oop((oop*) &wk_klass_name_limits[0]); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1813 f->do_oop((oop*) &wk_klass_name_limits[1]); |
0 | 1814 |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1815 for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1816 f->do_oop((oop*) &_well_known_klasses[k]); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1817 } |
0 | 1818 |
1819 { | |
1820 for (int i = 0; i < T_VOID+1; i++) { | |
1821 if (_box_klasses[i] != NULL) { | |
1822 assert(i >= T_BOOLEAN, "checking"); | |
1823 f->do_oop((oop*) &_box_klasses[i]); | |
1824 } | |
1825 } | |
1826 } | |
1827 | |
1828 // The basic type mirrors would have already been processed in | |
1829 // Universe::oops_do(), via a call to shared_oops_do(), so should | |
1830 // not be processed again. | |
1831 | |
1832 f->do_oop((oop*) &_system_loader_lock_obj); | |
1833 FilteredFieldsMap::klasses_oops_do(f); | |
1834 } | |
1835 | |
1836 void SystemDictionary::lazily_loaded_oops_do(OopClosure* f) { | |
1837 f->do_oop((oop*) &_abstract_ownable_synchronizer_klass); | |
1838 } | |
1839 | |
1840 // Just the classes from defining class loaders | |
1841 // Don't iterate over placeholders | |
1842 void SystemDictionary::classes_do(void f(klassOop)) { | |
1843 dictionary()->classes_do(f); | |
1844 } | |
1845 | |
1846 // Added for initialize_itable_for_klass | |
1847 // Just the classes from defining class loaders | |
1848 // Don't iterate over placeholders | |
1849 void SystemDictionary::classes_do(void f(klassOop, TRAPS), TRAPS) { | |
1850 dictionary()->classes_do(f, CHECK); | |
1851 } | |
1852 | |
1853 // All classes, and their class loaders | |
1854 // Don't iterate over placeholders | |
1855 void SystemDictionary::classes_do(void f(klassOop, oop)) { | |
1856 dictionary()->classes_do(f); | |
1857 } | |
1858 | |
1859 // All classes, and their class loaders | |
1860 // (added for helpers that use HandleMarks and ResourceMarks) | |
1861 // Don't iterate over placeholders | |
1862 void SystemDictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) { | |
1863 dictionary()->classes_do(f, CHECK); | |
1864 } | |
1865 | |
1866 void SystemDictionary::placeholders_do(void f(symbolOop, oop)) { | |
1867 placeholders()->entries_do(f); | |
1868 } | |
1869 | |
1870 void SystemDictionary::methods_do(void f(methodOop)) { | |
1871 dictionary()->methods_do(f); | |
1903 | 1872 invoke_method_table()->methods_do(f); |
0 | 1873 } |
1874 | |
1875 // ---------------------------------------------------------------------------- | |
1876 // Lazily load klasses | |
1877 | |
1878 void SystemDictionary::load_abstract_ownable_synchronizer_klass(TRAPS) { | |
1879 assert(JDK_Version::is_gte_jdk16x_version(), "Must be JDK 1.6 or later"); | |
1880 | |
1881 // if multiple threads calling this function, only one thread will load | |
1882 // the class. The other threads will find the loaded version once the | |
1883 // class is loaded. | |
1884 klassOop aos = _abstract_ownable_synchronizer_klass; | |
1885 if (aos == NULL) { | |
1886 klassOop k = resolve_or_fail(vmSymbolHandles::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK); | |
1887 // Force a fence to prevent any read before the write completes | |
1888 OrderAccess::fence(); | |
1889 _abstract_ownable_synchronizer_klass = k; | |
1890 } | |
1891 } | |
1892 | |
1893 // ---------------------------------------------------------------------------- | |
1894 // Initialization | |
1895 | |
1896 void SystemDictionary::initialize(TRAPS) { | |
1897 // Allocate arrays | |
1898 assert(dictionary() == NULL, | |
1899 "SystemDictionary should only be initialized once"); | |
1903 | 1900 _dictionary = new Dictionary(_nof_buckets); |
1901 _placeholders = new PlaceholderTable(_nof_buckets); | |
0 | 1902 _number_of_modifications = 0; |
1903 | 1903 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size); |
1904 _resolution_errors = new ResolutionErrorTable(_resolution_error_size); | |
1905 _invoke_method_table = new SymbolPropertyTable(_invoke_method_size); | |
0 | 1906 |
1907 // Allocate private object used as system class loader lock | |
1908 _system_loader_lock_obj = oopFactory::new_system_objArray(0, CHECK); | |
1909 // Initialize basic classes | |
1910 initialize_preloaded_classes(CHECK); | |
1911 } | |
1912 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1913 // Compact table of directions on the initialization of klasses: |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1914 static const short wk_init_info[] = { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1915 #define WK_KLASS_INIT_INFO(name, symbol, option) \ |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1916 ( ((int)vmSymbols::VM_SYMBOL_ENUM_NAME(symbol) \ |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1917 << SystemDictionary::CEIL_LG_OPTION_LIMIT) \ |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1918 | (int)SystemDictionary::option ), |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1919 WK_KLASSES_DO(WK_KLASS_INIT_INFO) |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1920 #undef WK_KLASS_INIT_INFO |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1921 0 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1922 }; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1923 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1924 bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1925 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1926 int info = wk_init_info[id - FIRST_WKID]; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1927 int sid = (info >> CEIL_LG_OPTION_LIMIT); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1928 symbolHandle symbol = vmSymbolHandles::symbol_handle_at((vmSymbols::SID)sid); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1929 klassOop* klassp = &_well_known_klasses[id]; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1930 bool must_load = (init_opt < SystemDictionary::Opt); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1931 bool try_load = true; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1932 if (init_opt == SystemDictionary::Opt_Kernel) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1933 #ifndef KERNEL |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1934 try_load = false; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1935 #endif //KERNEL |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1936 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1937 if ((*klassp) == NULL && try_load) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1938 if (must_load) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1939 (*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1940 } else { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1941 (*klassp) = resolve_or_null(symbol, CHECK_0); // load optional klass |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1942 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1943 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1944 return ((*klassp) != NULL); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1945 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1946 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1947 void SystemDictionary::initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1948 assert((int)start_id <= (int)limit_id, "IDs are out of order!"); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1949 for (int id = (int)start_id; id < (int)limit_id; id++) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1950 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1951 int info = wk_init_info[id - FIRST_WKID]; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1952 int sid = (info >> CEIL_LG_OPTION_LIMIT); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1953 int opt = (info & right_n_bits(CEIL_LG_OPTION_LIMIT)); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1954 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1955 initialize_wk_klass((WKID)id, opt, CHECK); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1956 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1957 // Update limits, so find_well_known_klass can be very fast: |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1958 symbolOop s = vmSymbols::symbol_at((vmSymbols::SID)sid); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1959 if (wk_klass_name_limits[1] == NULL) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1960 wk_klass_name_limits[0] = wk_klass_name_limits[1] = s; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1961 } else if (wk_klass_name_limits[1] < s) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1962 wk_klass_name_limits[1] = s; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1963 } else if (wk_klass_name_limits[0] > s) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1964 wk_klass_name_limits[0] = s; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1965 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1966 } |
710 | 1967 |
1968 // move the starting value forward to the limit: | |
1969 start_id = limit_id; | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1970 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1971 |
0 | 1972 |
1973 void SystemDictionary::initialize_preloaded_classes(TRAPS) { | |
1142 | 1974 assert(WK_KLASS(Object_klass) == NULL, "preloaded classes should only be initialized once"); |
0 | 1975 // Preload commonly used klasses |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1976 WKID scan = FIRST_WKID; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1977 // first do Object, String, Class |
1142 | 1978 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1979 |
1142 | 1980 debug_only(instanceKlass::verify_class_klass_nonstatic_oop_maps(WK_KLASS(Class_klass))); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1981 |
0 | 1982 // Fixup mirrors for classes loaded before java.lang.Class. |
1983 // These calls iterate over the objects currently in the perm gen | |
1984 // so calling them at this point is matters (not before when there | |
1985 // are fewer objects and not later after there are more objects | |
1986 // in the perm gen. | |
1987 Universe::initialize_basic_type_mirrors(CHECK); | |
1988 Universe::fixup_mirrors(CHECK); | |
1989 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1990 // do a bunch more: |
1142 | 1991 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK); |
0 | 1992 |
1993 // Preload ref klasses and set reference types | |
1142 | 1994 instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER); |
1995 instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass)); | |
0 | 1996 |
1142 | 1997 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK); |
1998 instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT); | |
1999 instanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK); | |
2000 instanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL); | |
2001 instanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM); | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
2002 |
710 | 2003 WKID meth_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass); |
2004 WKID meth_group_end = WK_KLASS_ENUM_NAME(WrongMethodTypeException_klass); | |
2005 initialize_wk_klasses_until(meth_group_start, scan, CHECK); | |
2006 if (EnableMethodHandles) { | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
993
diff
changeset
|
2007 initialize_wk_klasses_through(meth_group_end, scan, CHECK); |
710 | 2008 } |
2009 if (_well_known_klasses[meth_group_start] == NULL) { | |
2010 // Skip the rest of the method handle classes, if MethodHandle is not loaded. | |
2011 scan = WKID(meth_group_end+1); | |
2012 } | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2013 WKID indy_group_start = WK_KLASS_ENUM_NAME(Linkage_klass); |
2001
f2da85a9b08e
7001363: java/dyn/InvokeDynamic should not be a well-known class in the JVM
twisti
parents:
1972
diff
changeset
|
2014 WKID indy_group_end = WK_KLASS_ENUM_NAME(CallSite_klass); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2015 initialize_wk_klasses_until(indy_group_start, scan, CHECK); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2016 if (EnableInvokeDynamic) { |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
1039
diff
changeset
|
2017 initialize_wk_klasses_through(indy_group_end, scan, CHECK); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2018 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2019 if (_well_known_klasses[indy_group_start] == NULL) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2020 // Skip the rest of the dynamic typing classes, if Linkage is not loaded. |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2021 scan = WKID(indy_group_end+1); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2022 } |
710 | 2023 |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
2024 initialize_wk_klasses_until(WKID_LIMIT, scan, CHECK); |
0 | 2025 |
1142 | 2026 _box_klasses[T_BOOLEAN] = WK_KLASS(Boolean_klass); |
2027 _box_klasses[T_CHAR] = WK_KLASS(Character_klass); | |
2028 _box_klasses[T_FLOAT] = WK_KLASS(Float_klass); | |
2029 _box_klasses[T_DOUBLE] = WK_KLASS(Double_klass); | |
2030 _box_klasses[T_BYTE] = WK_KLASS(Byte_klass); | |
2031 _box_klasses[T_SHORT] = WK_KLASS(Short_klass); | |
2032 _box_klasses[T_INT] = WK_KLASS(Integer_klass); | |
2033 _box_klasses[T_LONG] = WK_KLASS(Long_klass); | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
2034 //_box_klasses[T_OBJECT] = WK_KLASS(object_klass); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
2035 //_box_klasses[T_ARRAY] = WK_KLASS(object_klass); |
0 | 2036 |
2037 #ifdef KERNEL | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
2038 if (sun_jkernel_DownloadManager_klass() == NULL) { |
0 | 2039 warning("Cannot find sun/jkernel/DownloadManager"); |
2040 } | |
2041 #endif // KERNEL | |
514 | 2042 |
0 | 2043 { // Compute whether we should use loadClass or loadClassInternal when loading classes. |
1142 | 2044 methodOop method = instanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature()); |
0 | 2045 _has_loadClassInternal = (method != NULL); |
2046 } | |
2047 { // Compute whether we should use checkPackageAccess or NOT | |
1142 | 2048 methodOop method = instanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature()); |
0 | 2049 _has_checkPackageAccess = (method != NULL); |
2050 } | |
2051 } | |
2052 | |
2053 // Tells if a given klass is a box (wrapper class, such as java.lang.Integer). | |
2054 // If so, returns the basic type it holds. If not, returns T_OBJECT. | |
2055 BasicType SystemDictionary::box_klass_type(klassOop k) { | |
2056 assert(k != NULL, ""); | |
2057 for (int i = T_BOOLEAN; i < T_VOID+1; i++) { | |
2058 if (_box_klasses[i] == k) | |
2059 return (BasicType)i; | |
2060 } | |
2061 return T_OBJECT; | |
2062 } | |
2063 | |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2064 KlassHandle SystemDictionaryHandles::box_klass(BasicType t) { |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2065 if (t >= T_BOOLEAN && t <= T_VOID) |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2066 return KlassHandle(&SystemDictionary::_box_klasses[t], true); |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2067 else |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2068 return KlassHandle(); |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2069 } |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2070 |
0 | 2071 // Constraints on class loaders. The details of the algorithm can be |
2072 // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java | |
2073 // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is | |
2074 // that the system dictionary needs to maintain a set of contraints that | |
2075 // must be satisfied by all classes in the dictionary. | |
2076 // if defining is true, then LinkageError if already in systemDictionary | |
2077 // if initiating loader, then ok if instanceKlass matches existing entry | |
2078 | |
2079 void SystemDictionary::check_constraints(int d_index, unsigned int d_hash, | |
2080 instanceKlassHandle k, | |
2081 Handle class_loader, bool defining, | |
2082 TRAPS) { | |
2083 const char *linkage_error = NULL; | |
2084 { | |
2085 symbolHandle name (THREAD, k->name()); | |
2086 MutexLocker mu(SystemDictionary_lock, THREAD); | |
2087 | |
2088 klassOop check = find_class(d_index, d_hash, name, class_loader); | |
2089 if (check != (klassOop)NULL) { | |
2090 // if different instanceKlass - duplicate class definition, | |
2091 // else - ok, class loaded by a different thread in parallel, | |
2092 // we should only have found it if it was done loading and ok to use | |
2093 // system dictionary only holds instance classes, placeholders | |
2094 // also holds array classes | |
2095 | |
2096 assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary"); | |
2097 if ((defining == true) || (k() != check)) { | |
2098 linkage_error = "loader (instance of %s): attempted duplicate class " | |
2099 "definition for name: \"%s\""; | |
2100 } else { | |
2101 return; | |
2102 } | |
2103 } | |
2104 | |
2105 #ifdef ASSERT | |
2106 unsigned int p_hash = placeholders()->compute_hash(name, class_loader); | |
2107 int p_index = placeholders()->hash_to_index(p_hash); | |
2108 symbolOop ph_check = find_placeholder(p_index, p_hash, name, class_loader); | |
2109 assert(ph_check == NULL || ph_check == name(), "invalid symbol"); | |
2110 #endif | |
2111 | |
2112 if (linkage_error == NULL) { | |
2113 if (constraints()->check_or_update(k, class_loader, name) == false) { | |
2114 linkage_error = "loader constraint violation: loader (instance of %s)" | |
2115 " previously initiated loading for a different type with name \"%s\""; | |
2116 } | |
2117 } | |
2118 } | |
2119 | |
2120 // Throw error now if needed (cannot throw while holding | |
2121 // SystemDictionary_lock because of rank ordering) | |
2122 | |
2123 if (linkage_error) { | |
2124 ResourceMark rm(THREAD); | |
2125 const char* class_loader_name = loader_name(class_loader()); | |
2126 char* type_name = k->name()->as_C_string(); | |
2127 size_t buflen = strlen(linkage_error) + strlen(class_loader_name) + | |
2128 strlen(type_name); | |
2129 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); | |
2130 jio_snprintf(buf, buflen, linkage_error, class_loader_name, type_name); | |
2131 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); | |
2132 } | |
2133 } | |
2134 | |
2135 | |
2136 // Update system dictionary - done after check_constraint and add_to_hierachy | |
2137 // have been called. | |
2138 void SystemDictionary::update_dictionary(int d_index, unsigned int d_hash, | |
2139 int p_index, unsigned int p_hash, | |
2140 instanceKlassHandle k, | |
2141 Handle class_loader, | |
2142 TRAPS) { | |
2143 // Compile_lock prevents systemDictionary updates during compilations | |
2144 assert_locked_or_safepoint(Compile_lock); | |
2145 symbolHandle name (THREAD, k->name()); | |
2146 | |
2147 { | |
2148 MutexLocker mu1(SystemDictionary_lock, THREAD); | |
2149 | |
2150 // See whether biased locking is enabled and if so set it for this | |
2151 // klass. | |
2152 // Note that this must be done past the last potential blocking | |
2153 // point / safepoint. We enable biased locking lazily using a | |
2154 // VM_Operation to iterate the SystemDictionary and installing the | |
2155 // biasable mark word into each instanceKlass's prototype header. | |
2156 // To avoid race conditions where we accidentally miss enabling the | |
2157 // optimization for one class in the process of being added to the | |
2158 // dictionary, we must not safepoint after the test of | |
2159 // BiasedLocking::enabled(). | |
2160 if (UseBiasedLocking && BiasedLocking::enabled()) { | |
2161 // Set biased locking bit for all loaded classes; it will be | |
2162 // cleared if revocation occurs too often for this type | |
2163 // NOTE that we must only do this when the class is initally | |
2164 // defined, not each time it is referenced from a new class loader | |
2165 if (k->class_loader() == class_loader()) { | |
2166 k->set_prototype_header(markOopDesc::biased_locking_prototype()); | |
2167 } | |
2168 } | |
2169 | |
2170 // Check for a placeholder. If there, remove it and make a | |
2171 // new system dictionary entry. | |
2172 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | |
2173 klassOop sd_check = find_class(d_index, d_hash, name, class_loader); | |
2174 if (sd_check == NULL) { | |
2175 dictionary()->add_klass(name, class_loader, k); | |
2176 notice_modification(); | |
2177 } | |
2178 #ifdef ASSERT | |
2179 sd_check = find_class(d_index, d_hash, name, class_loader); | |
2180 assert (sd_check != NULL, "should have entry in system dictionary"); | |
2181 // Changed to allow PH to remain to complete class circularity checking | |
2182 // while only one thread can define a class at one time, multiple | |
2183 // classes can resolve the superclass for a class at one time, | |
2184 // and the placeholder is used to track that | |
2185 // symbolOop ph_check = find_placeholder(p_index, p_hash, name, class_loader); | |
2186 // assert (ph_check == NULL, "should not have a placeholder entry"); | |
2187 #endif | |
2188 SystemDictionary_lock->notify_all(); | |
2189 } | |
2190 } | |
2191 | |
2192 | |
2193 klassOop SystemDictionary::find_constrained_instance_or_array_klass( | |
2194 symbolHandle class_name, Handle class_loader, TRAPS) { | |
2195 | |
2196 // First see if it has been loaded directly. | |
2197 // Force the protection domain to be null. (This removes protection checks.) | |
2198 Handle no_protection_domain; | |
2199 klassOop klass = find_instance_or_array_klass(class_name, class_loader, | |
2200 no_protection_domain, CHECK_NULL); | |
2201 if (klass != NULL) | |
2202 return klass; | |
2203 | |
2204 // Now look to see if it has been loaded elsewhere, and is subject to | |
2205 // a loader constraint that would require this loader to return the | |
2206 // klass that is already loaded. | |
2207 if (FieldType::is_array(class_name())) { | |
1336 | 2208 // For array classes, their klassOops are not kept in the |
2209 // constraint table. The element klassOops are. | |
0 | 2210 jint dimension; |
2211 symbolOop object_key; | |
2212 BasicType t = FieldType::get_array_info(class_name(), &dimension, | |
2213 &object_key, CHECK_(NULL)); | |
2214 if (t != T_OBJECT) { | |
2215 klass = Universe::typeArrayKlassObj(t); | |
2216 } else { | |
2217 symbolHandle elem_name(THREAD, object_key); | |
2218 MutexLocker mu(SystemDictionary_lock, THREAD); | |
1336 | 2219 klass = constraints()->find_constrained_klass(elem_name, class_loader); |
0 | 2220 } |
1336 | 2221 // If element class already loaded, allocate array klass |
0 | 2222 if (klass != NULL) { |
2223 klass = Klass::cast(klass)->array_klass_or_null(dimension); | |
2224 } | |
2225 } else { | |
2226 MutexLocker mu(SystemDictionary_lock, THREAD); | |
2227 // Non-array classes are easy: simply check the constraint table. | |
2228 klass = constraints()->find_constrained_klass(class_name, class_loader); | |
2229 } | |
2230 | |
2231 return klass; | |
2232 } | |
2233 | |
2234 | |
2235 bool SystemDictionary::add_loader_constraint(symbolHandle class_name, | |
2236 Handle class_loader1, | |
2237 Handle class_loader2, | |
2238 Thread* THREAD) { | |
1336 | 2239 symbolHandle constraint_name; |
2240 if (!FieldType::is_array(class_name())) { | |
2241 constraint_name = class_name; | |
2242 } else { | |
2243 // For array classes, their klassOops are not kept in the | |
2244 // constraint table. The element classes are. | |
2245 jint dimension; | |
2246 symbolOop object_key; | |
2247 BasicType t = FieldType::get_array_info(class_name(), &dimension, | |
2248 &object_key, CHECK_(false)); | |
2249 // primitive types always pass | |
2250 if (t != T_OBJECT) { | |
2251 return true; | |
2252 } else { | |
2253 constraint_name = symbolHandle(THREAD, object_key); | |
2254 } | |
2255 } | |
2256 unsigned int d_hash1 = dictionary()->compute_hash(constraint_name, class_loader1); | |
0 | 2257 int d_index1 = dictionary()->hash_to_index(d_hash1); |
2258 | |
1336 | 2259 unsigned int d_hash2 = dictionary()->compute_hash(constraint_name, class_loader2); |
0 | 2260 int d_index2 = dictionary()->hash_to_index(d_hash2); |
2261 { | |
1336 | 2262 MutexLocker mu_s(SystemDictionary_lock, THREAD); |
0 | 2263 |
1336 | 2264 // Better never do a GC while we're holding these oops |
2265 No_Safepoint_Verifier nosafepoint; | |
0 | 2266 |
1336 | 2267 klassOop klass1 = find_class(d_index1, d_hash1, constraint_name, class_loader1); |
2268 klassOop klass2 = find_class(d_index2, d_hash2, constraint_name, class_loader2); | |
2269 return constraints()->add_entry(constraint_name, klass1, class_loader1, | |
2270 klass2, class_loader2); | |
0 | 2271 } |
2272 } | |
2273 | |
2274 // Add entry to resolution error table to record the error when the first | |
2275 // attempt to resolve a reference to a class has failed. | |
2276 void SystemDictionary::add_resolution_error(constantPoolHandle pool, int which, symbolHandle error) { | |
2277 unsigned int hash = resolution_errors()->compute_hash(pool, which); | |
2278 int index = resolution_errors()->hash_to_index(hash); | |
2279 { | |
2280 MutexLocker ml(SystemDictionary_lock, Thread::current()); | |
2281 resolution_errors()->add_entry(index, hash, pool, which, error); | |
2282 } | |
2283 } | |
2284 | |
2285 // Lookup resolution error table. Returns error if found, otherwise NULL. | |
2286 symbolOop SystemDictionary::find_resolution_error(constantPoolHandle pool, int which) { | |
2287 unsigned int hash = resolution_errors()->compute_hash(pool, which); | |
2288 int index = resolution_errors()->hash_to_index(hash); | |
2289 { | |
2290 MutexLocker ml(SystemDictionary_lock, Thread::current()); | |
2291 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which); | |
2292 return (entry != NULL) ? entry->error() : (symbolOop)NULL; | |
2293 } | |
2294 } | |
2295 | |
2296 | |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2297 // Signature constraints ensure that callers and callees agree about |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2298 // the meaning of type names in their signatures. This routine is the |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2299 // intake for constraints. It collects them from several places: |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2300 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2301 // * LinkResolver::resolve_method (if check_access is true) requires |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2302 // that the resolving class (the caller) and the defining class of |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2303 // the resolved method (the callee) agree on each type in the |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2304 // method's signature. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2305 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2306 // * LinkResolver::resolve_interface_method performs exactly the same |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2307 // checks. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2308 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2309 // * LinkResolver::resolve_field requires that the constant pool |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2310 // attempting to link to a field agree with the field's defining |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2311 // class about the type of the field signature. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2312 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2313 // * klassVtable::initialize_vtable requires that, when a class |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2314 // overrides a vtable entry allocated by a superclass, that the |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2315 // overriding method (i.e., the callee) agree with the superclass |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2316 // on each type in the method's signature. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2317 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2318 // * klassItable::initialize_itable requires that, when a class fills |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2319 // in its itables, for each non-abstract method installed in an |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2320 // itable, the method (i.e., the callee) agree with the interface |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2321 // on each type in the method's signature. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2322 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2323 // All those methods have a boolean (check_access, checkconstraints) |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2324 // which turns off the checks. This is used from specialized contexts |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2325 // such as bootstrapping, dumping, and debugging. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2326 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2327 // No direct constraint is placed between the class and its |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2328 // supertypes. Constraints are only placed along linked relations |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2329 // between callers and callees. When a method overrides or implements |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2330 // an abstract method in a supertype (superclass or interface), the |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2331 // constraints are placed as if the supertype were the caller to the |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2332 // overriding method. (This works well, since callers to the |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2333 // supertype have already established agreement between themselves and |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2334 // the supertype.) As a result of all this, a class can disagree with |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2335 // its supertype about the meaning of a type name, as long as that |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2336 // class neither calls a relevant method of the supertype, nor is |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2337 // called (perhaps via an override) from the supertype. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2338 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2339 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2340 // SystemDictionary::check_signature_loaders(sig, l1, l2) |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2341 // |
0 | 2342 // Make sure all class components (including arrays) in the given |
2343 // signature will be resolved to the same class in both loaders. | |
2344 // Returns the name of the type that failed a loader constraint check, or | |
2345 // NULL if no constraint failed. The returned C string needs cleaning up | |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2346 // with a ResourceMark in the caller. No exception except OOME is thrown. |
1336 | 2347 // Arrays are not added to the loader constraint table, their elements are. |
0 | 2348 char* SystemDictionary::check_signature_loaders(symbolHandle signature, |
2349 Handle loader1, Handle loader2, | |
2350 bool is_method, TRAPS) { | |
2351 // Nothing to do if loaders are the same. | |
2352 if (loader1() == loader2()) { | |
2353 return NULL; | |
2354 } | |
2355 | |
2356 SignatureStream sig_strm(signature, is_method); | |
2357 while (!sig_strm.is_done()) { | |
2358 if (sig_strm.is_object()) { | |
2359 symbolOop s = sig_strm.as_symbol(CHECK_NULL); | |
2360 symbolHandle sig (THREAD, s); | |
2361 if (!add_loader_constraint(sig, loader1, loader2, THREAD)) { | |
2362 return sig()->as_C_string(); | |
2363 } | |
2364 } | |
2365 sig_strm.next(); | |
2366 } | |
2367 return NULL; | |
2368 } | |
2369 | |
2370 | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2371 methodOop SystemDictionary::find_method_handle_invoke(symbolHandle name, |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2372 symbolHandle signature, |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2373 KlassHandle accessing_klass, |
710 | 2374 TRAPS) { |
2375 if (!EnableMethodHandles) return NULL; | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2376 vmSymbols::SID name_id = vmSymbols::find_sid(name()); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2377 assert(name_id != vmSymbols::NO_SID, "must be a known name"); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2378 unsigned int hash = invoke_method_table()->compute_hash(signature, name_id); |
710 | 2379 int index = invoke_method_table()->hash_to_index(hash); |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2380 SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, name_id); |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2381 methodHandle non_cached_result; |
710 | 2382 if (spe == NULL || spe->property_oop() == NULL) { |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2383 spe = NULL; |
710 | 2384 // Must create lots of stuff here, but outside of the SystemDictionary lock. |
1410
b30a2cd5e3a2
Added methods to c1x_VMExits.cpp
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1407
diff
changeset
|
2385 // (tw) May we do this? |
b30a2cd5e3a2
Added methods to c1x_VMExits.cpp
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1407
diff
changeset
|
2386 //if (THREAD->is_Compiler_thread()) |
b30a2cd5e3a2
Added methods to c1x_VMExits.cpp
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1407
diff
changeset
|
2387 // return NULL; // do not attempt from within compiler |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2388 bool for_invokeGeneric = (name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name)); |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2389 bool found_on_bcp = false; |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2390 Handle mt = find_method_handle_type(signature(), accessing_klass, |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2391 for_invokeGeneric, |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2392 found_on_bcp, CHECK_NULL); |
710 | 2393 KlassHandle mh_klass = SystemDictionaryHandles::MethodHandle_klass(); |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2394 methodHandle m = methodOopDesc::make_invoke_method(mh_klass, name, signature, |
710 | 2395 mt, CHECK_NULL); |
2396 // Now grab the lock. We might have to throw away the new method, | |
2397 // if a racing thread has managed to install one at the same time. | |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2398 if (found_on_bcp) { |
710 | 2399 MutexLocker ml(SystemDictionary_lock, Thread::current()); |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2400 spe = invoke_method_table()->find_entry(index, hash, signature, name_id); |
710 | 2401 if (spe == NULL) |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2402 spe = invoke_method_table()->add_entry(index, hash, signature, name_id); |
710 | 2403 if (spe->property_oop() == NULL) |
2404 spe->set_property_oop(m()); | |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2405 } else { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2406 non_cached_result = m; |
710 | 2407 } |
2408 } | |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2409 if (spe != NULL && spe->property_oop() != NULL) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2410 assert(spe->property_oop()->is_method(), ""); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2411 return (methodOop) spe->property_oop(); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2412 } else { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2413 return non_cached_result(); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2414 } |
710 | 2415 } |
2416 | |
2417 // Ask Java code to find or construct a java.dyn.MethodType for the given | |
2418 // signature, as interpreted relative to the given class loader. | |
2419 // Because of class loader constraints, all method handle usage must be | |
2420 // consistent with this loader. | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2421 Handle SystemDictionary::find_method_handle_type(symbolHandle signature, |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2422 KlassHandle accessing_klass, |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2423 bool for_invokeGeneric, |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2424 bool& return_bcp_flag, |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2425 TRAPS) { |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2426 Handle class_loader, protection_domain; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2427 bool is_on_bcp = true; // keep this true as long as we can materialize from the boot classloader |
710 | 2428 Handle empty; |
2429 int npts = ArgumentCount(signature()).size(); | |
1142 | 2430 objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::Class_klass(), npts, CHECK_(empty)); |
710 | 2431 int arg = 0; |
2432 Handle rt; // the return type from the signature | |
2433 for (SignatureStream ss(signature()); !ss.is_done(); ss.next()) { | |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2434 oop mirror = NULL; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2435 if (is_on_bcp) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2436 mirror = ss.as_java_mirror(class_loader, protection_domain, |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2437 SignatureStream::ReturnNull, CHECK_(empty)); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2438 if (mirror == NULL) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2439 // fall back from BCP to accessing_klass |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2440 if (accessing_klass.not_null()) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2441 class_loader = Handle(THREAD, instanceKlass::cast(accessing_klass())->class_loader()); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2442 protection_domain = Handle(THREAD, instanceKlass::cast(accessing_klass())->protection_domain()); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2443 } |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2444 is_on_bcp = false; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2445 } |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2446 } |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2447 if (!is_on_bcp) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2448 // Resolve, throwing a real error if it doesn't work. |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2449 mirror = ss.as_java_mirror(class_loader, protection_domain, |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2450 SignatureStream::NCDFError, CHECK_(empty)); |
710 | 2451 } |
2452 if (ss.at_return_type()) | |
2453 rt = Handle(THREAD, mirror); | |
2454 else | |
2455 pts->obj_at_put(arg++, mirror); | |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2456 // Check accessibility. |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2457 if (ss.is_object() && accessing_klass.not_null()) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2458 klassOop sel_klass = java_lang_Class::as_klassOop(mirror); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2459 // Emulate constantPoolOopDesc::verify_constant_pool_resolve. |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2460 if (Klass::cast(sel_klass)->oop_is_objArray()) |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2461 sel_klass = objArrayKlass::cast(sel_klass)->bottom_klass(); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2462 if (Klass::cast(sel_klass)->oop_is_instance()) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2463 KlassHandle sel_kh(THREAD, sel_klass); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2464 LinkResolver::check_klass_accessability(accessing_klass, sel_kh, CHECK_(empty)); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2465 } |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2466 } |
710 | 2467 } |
2468 assert(arg == npts, ""); | |
2469 | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2470 // call sun.dyn.MethodHandleNatives::findMethodType(Class rt, Class[] pts) -> MethodType |
710 | 2471 JavaCallArguments args(Handle(THREAD, rt())); |
2472 args.push_oop(pts()); | |
2473 JavaValue result(T_OBJECT); | |
2474 JavaCalls::call_static(&result, | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2475 SystemDictionary::MethodHandleNatives_klass(), |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2476 vmSymbols::findMethodHandleType_name(), |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2477 vmSymbols::findMethodHandleType_signature(), |
710 | 2478 &args, CHECK_(empty)); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2479 Handle method_type(THREAD, (oop) result.get_jobject()); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2480 |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2481 if (for_invokeGeneric) { |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2482 // call sun.dyn.MethodHandleNatives::notifyGenericMethodType(MethodType) -> void |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2483 JavaCallArguments args(Handle(THREAD, method_type())); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2484 JavaValue no_result(T_VOID); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2485 JavaCalls::call_static(&no_result, |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2486 SystemDictionary::MethodHandleNatives_klass(), |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2487 vmSymbols::notifyGenericMethodType_name(), |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2488 vmSymbols::notifyGenericMethodType_signature(), |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2489 &args, THREAD); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2490 if (HAS_PENDING_EXCEPTION) { |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2491 // If the notification fails, just kill it. |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2492 CLEAR_PENDING_EXCEPTION; |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2493 } |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2494 } |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2495 |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2496 // report back to the caller with the MethodType and the "on_bcp" flag |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
2497 return_bcp_flag = is_on_bcp; |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2498 return method_type; |
710 | 2499 } |
2500 | |
1602 | 2501 // Ask Java code to find or construct a method handle constant. |
2502 Handle SystemDictionary::link_method_handle_constant(KlassHandle caller, | |
2503 int ref_kind, //e.g., JVM_REF_invokeVirtual | |
2504 KlassHandle callee, | |
2505 symbolHandle name_sym, | |
2506 symbolHandle signature, | |
2507 TRAPS) { | |
2508 Handle empty; | |
2509 Handle name = java_lang_String::create_from_symbol(name_sym(), CHECK_(empty)); | |
2510 Handle type; | |
2511 if (signature->utf8_length() > 0 && signature->byte_at(0) == '(') { | |
2512 bool ignore_is_on_bcp = false; | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1660
diff
changeset
|
2513 type = find_method_handle_type(signature, caller, false, ignore_is_on_bcp, CHECK_(empty)); |
1602 | 2514 } else { |
2515 SignatureStream ss(signature(), false); | |
2516 if (!ss.is_done()) { | |
2517 oop mirror = ss.as_java_mirror(caller->class_loader(), caller->protection_domain(), | |
2518 SignatureStream::NCDFError, CHECK_(empty)); | |
2519 type = Handle(THREAD, mirror); | |
2520 ss.next(); | |
2521 if (!ss.is_done()) type = Handle(); // error! | |
2522 } | |
2523 } | |
2524 if (type.is_null()) { | |
2525 THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad signature", empty); | |
2526 } | |
2527 | |
2528 // call sun.dyn.MethodHandleNatives::linkMethodHandleConstant(Class caller, int refKind, Class callee, String name, Object type) -> MethodHandle | |
2529 JavaCallArguments args; | |
2530 args.push_oop(caller->java_mirror()); // the referring class | |
2531 args.push_int(ref_kind); | |
2532 args.push_oop(callee->java_mirror()); // the target class | |
2533 args.push_oop(name()); | |
2534 args.push_oop(type()); | |
2535 JavaValue result(T_OBJECT); | |
2536 JavaCalls::call_static(&result, | |
2537 SystemDictionary::MethodHandleNatives_klass(), | |
2538 vmSymbols::linkMethodHandleConstant_name(), | |
2539 vmSymbols::linkMethodHandleConstant_signature(), | |
2540 &args, CHECK_(empty)); | |
2541 return Handle(THREAD, (oop) result.get_jobject()); | |
2542 } | |
710 | 2543 |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2544 // Ask Java code to find or construct a java.dyn.CallSite for the given |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2545 // name and signature, as interpreted relative to the given class loader. |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2546 Handle SystemDictionary::make_dynamic_call_site(Handle bootstrap_method, |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2547 symbolHandle name, |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2548 methodHandle signature_invoker, |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2549 Handle info, |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2550 methodHandle caller_method, |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2551 int caller_bci, |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2552 TRAPS) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2553 Handle empty; |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2554 guarantee(bootstrap_method.not_null() && |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2555 java_dyn_MethodHandle::is_instance(bootstrap_method()), |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2556 "caller must supply a valid BSM"); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2557 |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2558 Handle caller_mname = MethodHandles::new_MemberName(CHECK_(empty)); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2559 MethodHandles::init_MemberName(caller_mname(), caller_method()); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2560 |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2561 // call sun.dyn.MethodHandleNatives::makeDynamicCallSite(bootm, name, mtype, info, caller_mname, caller_pos) |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2562 oop name_str_oop = StringTable::intern(name(), CHECK_(empty)); // not a handle! |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2563 JavaCallArguments args(Handle(THREAD, bootstrap_method())); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2564 args.push_oop(name_str_oop); |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2565 args.push_oop(signature_invoker->method_handle_type()); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2566 args.push_oop(info()); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2567 args.push_oop(caller_mname()); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2568 args.push_int(caller_bci); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2569 JavaValue result(T_OBJECT); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2570 JavaCalls::call_static(&result, |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2571 SystemDictionary::MethodHandleNatives_klass(), |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2572 vmSymbols::makeDynamicCallSite_name(), |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2573 vmSymbols::makeDynamicCallSite_signature(), |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2574 &args, CHECK_(empty)); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2575 oop call_site_oop = (oop) result.get_jobject(); |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
875
diff
changeset
|
2576 assert(call_site_oop->is_oop() |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
1039
diff
changeset
|
2577 /*&& java_dyn_CallSite::is_instance(call_site_oop)*/, "must be sane"); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2578 if (TraceMethodHandles) { |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
1039
diff
changeset
|
2579 #ifndef PRODUCT |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2580 tty->print_cr("Linked invokedynamic bci=%d site="INTPTR_FORMAT":", caller_bci, call_site_oop); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2581 call_site_oop->print(); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2582 tty->cr(); |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
1039
diff
changeset
|
2583 #endif //PRODUCT |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2584 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2585 return call_site_oop; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2586 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2587 |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2588 Handle SystemDictionary::find_bootstrap_method(methodHandle caller_method, int caller_bci, |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2589 int cache_index, |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2590 Handle& argument_info_result, |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2591 TRAPS) { |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2592 Handle empty; |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2593 |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2594 constantPoolHandle pool; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2595 { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2596 klassOop caller = caller_method->method_holder(); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2597 if (!Klass::cast(caller)->oop_is_instance()) return empty; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2598 pool = constantPoolHandle(THREAD, instanceKlass::cast(caller)->constants()); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2599 } |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2600 |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2601 int constant_pool_index = pool->cache()->entry_at(cache_index)->constant_pool_index(); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2602 constantTag tag = pool->tag_at(constant_pool_index); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2603 |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2604 if (tag.is_invoke_dynamic()) { |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2605 // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&type], plus optional arguments |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2606 // The bootm, being a JVM_CONSTANT_MethodHandle, has its own cache entry. |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2607 int bsm_index = pool->invoke_dynamic_bootstrap_method_ref_index_at(constant_pool_index); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2608 if (bsm_index != 0) { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2609 int bsm_index_in_cache = pool->cache()->entry_at(cache_index)->bootstrap_method_index_in_cache(); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2610 DEBUG_ONLY(int bsm_index_2 = pool->cache()->entry_at(bsm_index_in_cache)->constant_pool_index()); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2611 assert(bsm_index == bsm_index_2, "BSM constant lifted to cache"); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2612 if (TraceMethodHandles) { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2613 tty->print_cr("resolving bootstrap method for "PTR_FORMAT" at %d at cache[%d]CP[%d]...", |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2614 (intptr_t) caller_method(), caller_bci, cache_index, constant_pool_index); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2615 } |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2616 oop bsm_oop = pool->resolve_cached_constant_at(bsm_index_in_cache, CHECK_(empty)); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2617 if (TraceMethodHandles) { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2618 tty->print_cr("bootstrap method for "PTR_FORMAT" at %d retrieved as "PTR_FORMAT":", |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2619 (intptr_t) caller_method(), caller_bci, (intptr_t) bsm_oop); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2620 } |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2621 assert(bsm_oop->is_oop(), "must be sane"); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2622 // caller must verify that it is of type MethodHandle |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2623 Handle bsm(THREAD, bsm_oop); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2624 bsm_oop = NULL; // safety |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2625 |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2626 // Extract the optional static arguments. |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2627 Handle argument_info; // either null, or one arg, or Object[]{arg...} |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2628 int argc = pool->invoke_dynamic_argument_count_at(constant_pool_index); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2629 if (TraceInvokeDynamic) { |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2630 tty->print_cr("find_bootstrap_method: [%d/%d] CONSTANT_InvokeDynamic: %d[%d]", |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2631 constant_pool_index, cache_index, bsm_index, argc); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2632 } |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2633 if (argc > 0) { |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2634 objArrayHandle arg_array; |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2635 if (argc > 1) { |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2636 objArrayOop arg_array_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), argc, CHECK_(empty)); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2637 arg_array = objArrayHandle(THREAD, arg_array_oop); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2638 argument_info = arg_array; |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2639 } |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2640 for (int arg_i = 0; arg_i < argc; arg_i++) { |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2641 int arg_index = pool->invoke_dynamic_argument_index_at(constant_pool_index, arg_i); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2642 oop arg_oop = pool->resolve_possibly_cached_constant_at(arg_index, CHECK_(empty)); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2643 if (arg_array.is_null()) { |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2644 argument_info = Handle(THREAD, arg_oop); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2645 } else { |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2646 arg_array->obj_at_put(arg_i, arg_oop); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2647 } |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2648 } |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2649 } |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2650 |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2651 argument_info_result = argument_info; // return argument_info to caller |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2652 return bsm; |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2653 } |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2654 // else null BSM; fall through |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2655 } else if (tag.is_name_and_type()) { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2656 // JSR 292 EDR does not have JVM_CONSTANT_InvokeDynamic |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2657 // a bare name&type defaults its BSM to null, so fall through... |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2658 } else { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2659 ShouldNotReachHere(); // verifier does not allow this |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2660 } |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2661 |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2662 // Fall through to pick up the per-class bootstrap method. |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2663 // This mechanism may go away in the PFD. |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2664 assert(AllowTransitionalJSR292, "else the verifier should have stopped us already"); |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2665 argument_info_result = empty; // return no argument_info to caller |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2666 oop bsm_oop = instanceKlass::cast(caller_method->method_holder())->bootstrap_method(); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2667 if (bsm_oop != NULL) { |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
1039
diff
changeset
|
2668 if (TraceMethodHandles) { |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2669 tty->print_cr("bootstrap method for "PTR_FORMAT" registered as "PTR_FORMAT":", |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2670 (intptr_t) caller_method(), (intptr_t) bsm_oop); |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
1039
diff
changeset
|
2671 } |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1903
diff
changeset
|
2672 assert(bsm_oop->is_oop(), "must be sane"); |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
2673 return Handle(THREAD, bsm_oop); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2674 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2675 |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1339
diff
changeset
|
2676 return empty; |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2677 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2678 |
0 | 2679 // Since the identity hash code for symbols changes when the symbols are |
2680 // moved from the regular perm gen (hash in the mark word) to the shared | |
2681 // spaces (hash is the address), the classes loaded into the dictionary | |
2682 // may be in the wrong buckets. | |
2683 | |
2684 void SystemDictionary::reorder_dictionary() { | |
2685 dictionary()->reorder_dictionary(); | |
2686 } | |
2687 | |
2688 | |
2689 void SystemDictionary::copy_buckets(char** top, char* end) { | |
2690 dictionary()->copy_buckets(top, end); | |
2691 } | |
2692 | |
2693 | |
2694 void SystemDictionary::copy_table(char** top, char* end) { | |
2695 dictionary()->copy_table(top, end); | |
2696 } | |
2697 | |
2698 | |
2699 void SystemDictionary::reverse() { | |
2700 dictionary()->reverse(); | |
2701 } | |
2702 | |
2703 int SystemDictionary::number_of_classes() { | |
2704 return dictionary()->number_of_entries(); | |
2705 } | |
2706 | |
2707 | |
2708 // ---------------------------------------------------------------------------- | |
2709 #ifndef PRODUCT | |
2710 | |
2711 void SystemDictionary::print() { | |
2712 dictionary()->print(); | |
2713 | |
2714 // Placeholders | |
2715 GCMutexLocker mu(SystemDictionary_lock); | |
2716 placeholders()->print(); | |
2717 | |
2718 // loader constraints - print under SD_lock | |
2719 constraints()->print(); | |
2720 } | |
2721 | |
2722 #endif | |
2723 | |
2724 void SystemDictionary::verify() { | |
2725 guarantee(dictionary() != NULL, "Verify of system dictionary failed"); | |
2726 guarantee(constraints() != NULL, | |
2727 "Verify of loader constraints failed"); | |
2728 guarantee(dictionary()->number_of_entries() >= 0 && | |
2729 placeholders()->number_of_entries() >= 0, | |
2730 "Verify of system dictionary failed"); | |
2731 | |
2732 // Verify dictionary | |
2733 dictionary()->verify(); | |
2734 | |
2735 GCMutexLocker mu(SystemDictionary_lock); | |
2736 placeholders()->verify(); | |
2737 | |
2738 // Verify constraint table | |
2739 guarantee(constraints() != NULL, "Verify of loader constraints failed"); | |
1258
38836cf1d8d2
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1142
diff
changeset
|
2740 constraints()->verify(dictionary(), placeholders()); |
0 | 2741 } |
2742 | |
2743 | |
2744 void SystemDictionary::verify_obj_klass_present(Handle obj, | |
2745 symbolHandle class_name, | |
2746 Handle class_loader) { | |
2747 GCMutexLocker mu(SystemDictionary_lock); | |
2748 oop probe = find_class_or_placeholder(class_name, class_loader); | |
2749 if (probe == NULL) { | |
2750 probe = SystemDictionary::find_shared_class(class_name); | |
2751 } | |
2752 guarantee(probe != NULL && | |
2753 (!probe->is_klass() || probe == obj()), | |
2754 "Loaded klasses should be in SystemDictionary"); | |
2755 } | |
2756 | |
2757 #ifndef PRODUCT | |
2758 | |
2759 // statistics code | |
2760 class ClassStatistics: AllStatic { | |
2761 private: | |
2762 static int nclasses; // number of classes | |
2763 static int nmethods; // number of methods | |
2764 static int nmethoddata; // number of methodData | |
2765 static int class_size; // size of class objects in words | |
2766 static int method_size; // size of method objects in words | |
2767 static int debug_size; // size of debug info in methods | |
2768 static int methoddata_size; // size of methodData objects in words | |
2769 | |
2770 static void do_class(klassOop k) { | |
2771 nclasses++; | |
2772 class_size += k->size(); | |
2773 if (k->klass_part()->oop_is_instance()) { | |
2774 instanceKlass* ik = (instanceKlass*)k->klass_part(); | |
2775 class_size += ik->methods()->size(); | |
2776 class_size += ik->constants()->size(); | |
2777 class_size += ik->local_interfaces()->size(); | |
2778 class_size += ik->transitive_interfaces()->size(); | |
2779 // We do not have to count implementors, since we only store one! | |
2780 class_size += ik->fields()->size(); | |
2781 } | |
2782 } | |
2783 | |
2784 static void do_method(methodOop m) { | |
2785 nmethods++; | |
2786 method_size += m->size(); | |
2787 // class loader uses same objArray for empty vectors, so don't count these | |
2788 if (m->exception_table()->length() != 0) method_size += m->exception_table()->size(); | |
2789 if (m->has_stackmap_table()) { | |
2790 method_size += m->stackmap_data()->size(); | |
2791 } | |
2792 | |
2793 methodDataOop mdo = m->method_data(); | |
2794 if (mdo != NULL) { | |
2795 nmethoddata++; | |
2796 methoddata_size += mdo->size(); | |
2797 } | |
2798 } | |
2799 | |
2800 public: | |
2801 static void print() { | |
2802 SystemDictionary::classes_do(do_class); | |
2803 SystemDictionary::methods_do(do_method); | |
2804 tty->print_cr("Class statistics:"); | |
2805 tty->print_cr("%d classes (%d bytes)", nclasses, class_size * oopSize); | |
2806 tty->print_cr("%d methods (%d bytes = %d base + %d debug info)", nmethods, | |
2807 (method_size + debug_size) * oopSize, method_size * oopSize, debug_size * oopSize); | |
2808 tty->print_cr("%d methoddata (%d bytes)", nmethoddata, methoddata_size * oopSize); | |
2809 } | |
2810 }; | |
2811 | |
2812 | |
2813 int ClassStatistics::nclasses = 0; | |
2814 int ClassStatistics::nmethods = 0; | |
2815 int ClassStatistics::nmethoddata = 0; | |
2816 int ClassStatistics::class_size = 0; | |
2817 int ClassStatistics::method_size = 0; | |
2818 int ClassStatistics::debug_size = 0; | |
2819 int ClassStatistics::methoddata_size = 0; | |
2820 | |
2821 void SystemDictionary::print_class_statistics() { | |
2822 ResourceMark rm; | |
2823 ClassStatistics::print(); | |
2824 } | |
2825 | |
2826 | |
2827 class MethodStatistics: AllStatic { | |
2828 public: | |
2829 enum { | |
2830 max_parameter_size = 10 | |
2831 }; | |
2832 private: | |
2833 | |
2834 static int _number_of_methods; | |
2835 static int _number_of_final_methods; | |
2836 static int _number_of_static_methods; | |
2837 static int _number_of_native_methods; | |
2838 static int _number_of_synchronized_methods; | |
2839 static int _number_of_profiled_methods; | |
2840 static int _number_of_bytecodes; | |
2841 static int _parameter_size_profile[max_parameter_size]; | |
2842 static int _bytecodes_profile[Bytecodes::number_of_java_codes]; | |
2843 | |
2844 static void initialize() { | |
2845 _number_of_methods = 0; | |
2846 _number_of_final_methods = 0; | |
2847 _number_of_static_methods = 0; | |
2848 _number_of_native_methods = 0; | |
2849 _number_of_synchronized_methods = 0; | |
2850 _number_of_profiled_methods = 0; | |
2851 _number_of_bytecodes = 0; | |
2852 for (int i = 0; i < max_parameter_size ; i++) _parameter_size_profile[i] = 0; | |
2853 for (int j = 0; j < Bytecodes::number_of_java_codes; j++) _bytecodes_profile [j] = 0; | |
2854 }; | |
2855 | |
2856 static void do_method(methodOop m) { | |
2857 _number_of_methods++; | |
2858 // collect flag info | |
2859 if (m->is_final() ) _number_of_final_methods++; | |
2860 if (m->is_static() ) _number_of_static_methods++; | |
2861 if (m->is_native() ) _number_of_native_methods++; | |
2862 if (m->is_synchronized()) _number_of_synchronized_methods++; | |
2863 if (m->method_data() != NULL) _number_of_profiled_methods++; | |
2864 // collect parameter size info (add one for receiver, if any) | |
2865 _parameter_size_profile[MIN2(m->size_of_parameters() + (m->is_static() ? 0 : 1), max_parameter_size - 1)]++; | |
2866 // collect bytecodes info | |
2867 { | |
2868 Thread *thread = Thread::current(); | |
2869 HandleMark hm(thread); | |
2870 BytecodeStream s(methodHandle(thread, m)); | |
2871 Bytecodes::Code c; | |
2872 while ((c = s.next()) >= 0) { | |
2873 _number_of_bytecodes++; | |
2874 _bytecodes_profile[c]++; | |
2875 } | |
2876 } | |
2877 } | |
2878 | |
2879 public: | |
2880 static void print() { | |
2881 initialize(); | |
2882 SystemDictionary::methods_do(do_method); | |
2883 // generate output | |
2884 tty->cr(); | |
2885 tty->print_cr("Method statistics (static):"); | |
2886 // flag distribution | |
2887 tty->cr(); | |
2888 tty->print_cr("%6d final methods %6.1f%%", _number_of_final_methods , _number_of_final_methods * 100.0F / _number_of_methods); | |
2889 tty->print_cr("%6d static methods %6.1f%%", _number_of_static_methods , _number_of_static_methods * 100.0F / _number_of_methods); | |
2890 tty->print_cr("%6d native methods %6.1f%%", _number_of_native_methods , _number_of_native_methods * 100.0F / _number_of_methods); | |
2891 tty->print_cr("%6d synchronized methods %6.1f%%", _number_of_synchronized_methods, _number_of_synchronized_methods * 100.0F / _number_of_methods); | |
2892 tty->print_cr("%6d profiled methods %6.1f%%", _number_of_profiled_methods, _number_of_profiled_methods * 100.0F / _number_of_methods); | |
2893 // parameter size profile | |
2894 tty->cr(); | |
2895 { int tot = 0; | |
2896 int avg = 0; | |
2897 for (int i = 0; i < max_parameter_size; i++) { | |
2898 int n = _parameter_size_profile[i]; | |
2899 tot += n; | |
2900 avg += n*i; | |
2901 tty->print_cr("parameter size = %1d: %6d methods %5.1f%%", i, n, n * 100.0F / _number_of_methods); | |
2902 } | |
2903 assert(tot == _number_of_methods, "should be the same"); | |
2904 tty->print_cr(" %6d methods 100.0%%", _number_of_methods); | |
2905 tty->print_cr("(average parameter size = %3.1f including receiver, if any)", (float)avg / _number_of_methods); | |
2906 } | |
2907 // bytecodes profile | |
2908 tty->cr(); | |
2909 { int tot = 0; | |
2910 for (int i = 0; i < Bytecodes::number_of_java_codes; i++) { | |
2911 if (Bytecodes::is_defined(i)) { | |
2912 Bytecodes::Code c = Bytecodes::cast(i); | |
2913 int n = _bytecodes_profile[c]; | |
2914 tot += n; | |
2915 tty->print_cr("%9d %7.3f%% %s", n, n * 100.0F / _number_of_bytecodes, Bytecodes::name(c)); | |
2916 } | |
2917 } | |
2918 assert(tot == _number_of_bytecodes, "should be the same"); | |
2919 tty->print_cr("%9d 100.000%%", _number_of_bytecodes); | |
2920 } | |
2921 tty->cr(); | |
2922 } | |
2923 }; | |
2924 | |
2925 int MethodStatistics::_number_of_methods; | |
2926 int MethodStatistics::_number_of_final_methods; | |
2927 int MethodStatistics::_number_of_static_methods; | |
2928 int MethodStatistics::_number_of_native_methods; | |
2929 int MethodStatistics::_number_of_synchronized_methods; | |
2930 int MethodStatistics::_number_of_profiled_methods; | |
2931 int MethodStatistics::_number_of_bytecodes; | |
2932 int MethodStatistics::_parameter_size_profile[MethodStatistics::max_parameter_size]; | |
2933 int MethodStatistics::_bytecodes_profile[Bytecodes::number_of_java_codes]; | |
2934 | |
2935 | |
2936 void SystemDictionary::print_method_statistics() { | |
2937 MethodStatistics::print(); | |
2938 } | |
2939 | |
2940 #endif // PRODUCT |