Mercurial > hg > truffle
comparison src/share/vm/classfile/systemDictionary.hpp @ 2177:3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
Summary: move symbols from permgen into C heap and reference count them
Reviewed-by: never, acorn, jmasa, stefank
author | coleenp |
---|---|
date | Thu, 27 Jan 2011 16:11:27 -0800 |
parents | 8f8dfba37802 |
children | d25d4ca69222 72dee110246f |
comparison
equal
deleted
inserted
replaced
2176:27e4ea99855d | 2177:3582bf76420e |
---|---|
26 #define SHARE_VM_CLASSFILE_SYSTEMDICTIONARY_HPP | 26 #define SHARE_VM_CLASSFILE_SYSTEMDICTIONARY_HPP |
27 | 27 |
28 #include "classfile/classFileStream.hpp" | 28 #include "classfile/classFileStream.hpp" |
29 #include "classfile/classLoader.hpp" | 29 #include "classfile/classLoader.hpp" |
30 #include "oops/objArrayOop.hpp" | 30 #include "oops/objArrayOop.hpp" |
31 #include "oops/symbolOop.hpp" | 31 #include "oops/symbol.hpp" |
32 #include "runtime/java.hpp" | 32 #include "runtime/java.hpp" |
33 #include "runtime/reflectionUtils.hpp" | 33 #include "runtime/reflectionUtils.hpp" |
34 #include "utilities/hashtable.hpp" | 34 #include "utilities/hashtable.hpp" |
35 | 35 |
36 // The system dictionary stores all loaded classes and maps: | 36 // The system dictionary stores all loaded classes and maps: |
37 // | 37 // |
38 // [class name,class loader] -> class i.e. [symbolOop,oop] -> klassOop | 38 // [class name,class loader] -> class i.e. [Symbol*,oop] -> klassOop |
39 // | 39 // |
40 // Classes are loaded lazily. The default VM class loader is | 40 // Classes are loaded lazily. The default VM class loader is |
41 // represented as NULL. | 41 // represented as NULL. |
42 | 42 |
43 // The underlying data structure is an open hash table with a fixed number | 43 // The underlying data structure is an open hash table with a fixed number |
224 // class if needed. If not found a NoClassDefFoundError or a | 224 // class if needed. If not found a NoClassDefFoundError or a |
225 // ClassNotFoundException is thrown, depending on the value on the | 225 // ClassNotFoundException is thrown, depending on the value on the |
226 // throw_error flag. For most uses the throw_error argument should be set | 226 // throw_error flag. For most uses the throw_error argument should be set |
227 // to true. | 227 // to true. |
228 | 228 |
229 static klassOop resolve_or_fail(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS); | 229 static klassOop resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS); |
230 // Convenient call for null loader and protection domain. | 230 // Convenient call for null loader and protection domain. |
231 static klassOop resolve_or_fail(symbolHandle class_name, bool throw_error, TRAPS); | 231 static klassOop resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS); |
232 private: | 232 private: |
233 // handle error translation for resolve_or_null results | 233 // handle error translation for resolve_or_null results |
234 static klassOop handle_resolution_exception(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS); | 234 static klassOop handle_resolution_exception(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS); |
235 | 235 |
236 public: | 236 public: |
237 | 237 |
238 // Returns a class with a given class name and class loader. | 238 // Returns a class with a given class name and class loader. |
239 // Loads the class if needed. If not found NULL is returned. | 239 // Loads the class if needed. If not found NULL is returned. |
240 static klassOop resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); | 240 static klassOop resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); |
241 // Version with null loader and protection domain | 241 // Version with null loader and protection domain |
242 static klassOop resolve_or_null(symbolHandle class_name, TRAPS); | 242 static klassOop resolve_or_null(Symbol* class_name, TRAPS); |
243 | 243 |
244 // Resolve a superclass or superinterface. Called from ClassFileParser, | 244 // Resolve a superclass or superinterface. Called from ClassFileParser, |
245 // parse_interfaces, resolve_instance_class_or_null, load_shared_class | 245 // parse_interfaces, resolve_instance_class_or_null, load_shared_class |
246 // "child_name" is the class whose super class or interface is being resolved. | 246 // "child_name" is the class whose super class or interface is being resolved. |
247 static klassOop resolve_super_or_fail(symbolHandle child_name, | 247 static klassOop resolve_super_or_fail(Symbol* child_name, |
248 symbolHandle class_name, | 248 Symbol* class_name, |
249 Handle class_loader, | 249 Handle class_loader, |
250 Handle protection_domain, | 250 Handle protection_domain, |
251 bool is_superclass, | 251 bool is_superclass, |
252 TRAPS); | 252 TRAPS); |
253 | 253 |
254 // Parse new stream. This won't update the system dictionary or | 254 // Parse new stream. This won't update the system dictionary or |
255 // class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses. | 255 // class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses. |
256 static klassOop parse_stream(symbolHandle class_name, | 256 static klassOop parse_stream(Symbol* class_name, |
257 Handle class_loader, | 257 Handle class_loader, |
258 Handle protection_domain, | 258 Handle protection_domain, |
259 ClassFileStream* st, | 259 ClassFileStream* st, |
260 TRAPS) { | 260 TRAPS) { |
261 KlassHandle nullHandle; | 261 KlassHandle nullHandle; |
262 return parse_stream(class_name, class_loader, protection_domain, st, nullHandle, NULL, THREAD); | 262 return parse_stream(class_name, class_loader, protection_domain, st, nullHandle, NULL, THREAD); |
263 } | 263 } |
264 static klassOop parse_stream(symbolHandle class_name, | 264 static klassOop parse_stream(Symbol* class_name, |
265 Handle class_loader, | 265 Handle class_loader, |
266 Handle protection_domain, | 266 Handle protection_domain, |
267 ClassFileStream* st, | 267 ClassFileStream* st, |
268 KlassHandle host_klass, | 268 KlassHandle host_klass, |
269 GrowableArray<Handle>* cp_patches, | 269 GrowableArray<Handle>* cp_patches, |
270 TRAPS); | 270 TRAPS); |
271 | 271 |
272 // Resolve from stream (called by jni_DefineClass and JVM_DefineClass) | 272 // Resolve from stream (called by jni_DefineClass and JVM_DefineClass) |
273 static klassOop resolve_from_stream(symbolHandle class_name, Handle class_loader, | 273 static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader, |
274 Handle protection_domain, | 274 Handle protection_domain, |
275 ClassFileStream* st, bool verify, TRAPS); | 275 ClassFileStream* st, bool verify, TRAPS); |
276 | 276 |
277 // Lookup an already loaded class. If not found NULL is returned. | 277 // Lookup an already loaded class. If not found NULL is returned. |
278 static klassOop find(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); | 278 static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); |
279 | 279 |
280 // Lookup an already loaded instance or array class. | 280 // Lookup an already loaded instance or array class. |
281 // Do not make any queries to class loaders; consult only the cache. | 281 // Do not make any queries to class loaders; consult only the cache. |
282 // If not found NULL is returned. | 282 // If not found NULL is returned. |
283 static klassOop find_instance_or_array_klass(symbolHandle class_name, | 283 static klassOop find_instance_or_array_klass(Symbol* class_name, |
284 Handle class_loader, | 284 Handle class_loader, |
285 Handle protection_domain, | 285 Handle protection_domain, |
286 TRAPS); | 286 TRAPS); |
287 | 287 |
288 // If the given name is known to vmSymbols, return the well-know klass: | 288 // If the given name is known to vmSymbols, return the well-know klass: |
289 static klassOop find_well_known_klass(symbolOop class_name); | 289 static klassOop find_well_known_klass(Symbol* class_name); |
290 | 290 |
291 // Lookup an instance or array class that has already been loaded | 291 // Lookup an instance or array class that has already been loaded |
292 // either into the given class loader, or else into another class | 292 // either into the given class loader, or else into another class |
293 // loader that is constrained (via loader constraints) to produce | 293 // loader that is constrained (via loader constraints) to produce |
294 // a consistent class. Do not take protection domains into account. | 294 // a consistent class. Do not take protection domains into account. |
307 // 4. Loading was attempted, but there was a linkage error of some sort. | 307 // 4. Loading was attempted, but there was a linkage error of some sort. |
308 // In all of these cases, the loader constraints on this type are | 308 // In all of these cases, the loader constraints on this type are |
309 // satisfied, and it is safe for classes in the given class loader | 309 // satisfied, and it is safe for classes in the given class loader |
310 // to manipulate strongly-typed values of the found class, subject | 310 // to manipulate strongly-typed values of the found class, subject |
311 // to local linkage and access checks. | 311 // to local linkage and access checks. |
312 static klassOop find_constrained_instance_or_array_klass(symbolHandle class_name, | 312 static klassOop find_constrained_instance_or_array_klass(Symbol* class_name, |
313 Handle class_loader, | 313 Handle class_loader, |
314 TRAPS); | 314 TRAPS); |
315 | 315 |
316 // Iterate over all klasses in dictionary | 316 // Iterate over all klasses in dictionary |
317 // Just the classes from defining class loaders | 317 // Just the classes from defining class loaders |
322 static void classes_do(void f(klassOop, oop)); | 322 static void classes_do(void f(klassOop, oop)); |
323 // All classes, and their class loaders | 323 // All classes, and their class loaders |
324 // (added for helpers that use HandleMarks and ResourceMarks) | 324 // (added for helpers that use HandleMarks and ResourceMarks) |
325 static void classes_do(void f(klassOop, oop, TRAPS), TRAPS); | 325 static void classes_do(void f(klassOop, oop, TRAPS), TRAPS); |
326 // All entries in the placeholder table and their class loaders | 326 // All entries in the placeholder table and their class loaders |
327 static void placeholders_do(void f(symbolOop, oop)); | 327 static void placeholders_do(void f(Symbol*, oop)); |
328 | 328 |
329 // Iterate over all methods in all klasses in dictionary | 329 // Iterate over all methods in all klasses in dictionary |
330 static void methods_do(void f(methodOop)); | 330 static void methods_do(void f(methodOop)); |
331 | 331 |
332 // Garbage collection support | 332 // Garbage collection support |
381 | 381 |
382 // Verification | 382 // Verification |
383 static void verify(); | 383 static void verify(); |
384 | 384 |
385 #ifdef ASSERT | 385 #ifdef ASSERT |
386 static bool is_internal_format(symbolHandle class_name); | 386 static bool is_internal_format(Symbol* class_name); |
387 #endif | 387 #endif |
388 | 388 |
389 // Verify class is in dictionary | 389 // Verify class is in dictionary |
390 static void verify_obj_klass_present(Handle obj, | 390 static void verify_obj_klass_present(Handle obj, |
391 symbolHandle class_name, | 391 Symbol* class_name, |
392 Handle class_loader); | 392 Handle class_loader); |
393 | 393 |
394 // Initialization | 394 // Initialization |
395 static void initialize(TRAPS); | 395 static void initialize(TRAPS); |
396 | 396 |
467 | 467 |
468 public: | 468 public: |
469 // Note: java_lang_Class::primitive_type is the inverse of java_mirror | 469 // Note: java_lang_Class::primitive_type is the inverse of java_mirror |
470 | 470 |
471 // Check class loader constraints | 471 // Check class loader constraints |
472 static bool add_loader_constraint(symbolHandle name, Handle loader1, | 472 static bool add_loader_constraint(Symbol* name, Handle loader1, |
473 Handle loader2, TRAPS); | 473 Handle loader2, TRAPS); |
474 static char* check_signature_loaders(symbolHandle signature, Handle loader1, | 474 static char* check_signature_loaders(Symbol* signature, Handle loader1, |
475 Handle loader2, bool is_method, TRAPS); | 475 Handle loader2, bool is_method, TRAPS); |
476 | 476 |
477 // JSR 292 | 477 // JSR 292 |
478 // find the java.dyn.MethodHandles::invoke method for a given signature | 478 // find the java.dyn.MethodHandles::invoke method for a given signature |
479 static methodOop find_method_handle_invoke(symbolHandle name, | 479 static methodOop find_method_handle_invoke(Symbol* name, |
480 symbolHandle signature, | 480 Symbol* signature, |
481 KlassHandle accessing_klass, | 481 KlassHandle accessing_klass, |
482 TRAPS); | 482 TRAPS); |
483 // ask Java to compute a java.dyn.MethodType object for a given signature | 483 // ask Java to compute a java.dyn.MethodType object for a given signature |
484 static Handle find_method_handle_type(symbolHandle signature, | 484 static Handle find_method_handle_type(Symbol* signature, |
485 KlassHandle accessing_klass, | 485 KlassHandle accessing_klass, |
486 bool for_invokeGeneric, | 486 bool for_invokeGeneric, |
487 bool& return_bcp_flag, | 487 bool& return_bcp_flag, |
488 TRAPS); | 488 TRAPS); |
489 // ask Java to compute a java.dyn.MethodHandle object for a given CP entry | 489 // ask Java to compute a java.dyn.MethodHandle object for a given CP entry |
490 static Handle link_method_handle_constant(KlassHandle caller, | 490 static Handle link_method_handle_constant(KlassHandle caller, |
491 int ref_kind, //e.g., JVM_REF_invokeVirtual | 491 int ref_kind, //e.g., JVM_REF_invokeVirtual |
492 KlassHandle callee, | 492 KlassHandle callee, |
493 symbolHandle name, | 493 Symbol* name, |
494 symbolHandle signature, | 494 Symbol* signature, |
495 TRAPS); | 495 TRAPS); |
496 // ask Java to create a dynamic call site, while linking an invokedynamic op | 496 // ask Java to create a dynamic call site, while linking an invokedynamic op |
497 static Handle make_dynamic_call_site(Handle bootstrap_method, | 497 static Handle make_dynamic_call_site(Handle bootstrap_method, |
498 // Callee information: | 498 // Callee information: |
499 symbolHandle name, | 499 Symbol* name, |
500 methodHandle signature_invoker, | 500 methodHandle signature_invoker, |
501 Handle info, | 501 Handle info, |
502 // Caller information: | 502 // Caller information: |
503 methodHandle caller_method, | 503 methodHandle caller_method, |
504 int caller_bci, | 504 int caller_bci, |
517 instanceKlass::cast((loader)->klass())->name()->as_C_string() ); | 517 instanceKlass::cast((loader)->klass())->name()->as_C_string() ); |
518 } | 518 } |
519 | 519 |
520 // Record the error when the first attempt to resolve a reference from a constant | 520 // Record the error when the first attempt to resolve a reference from a constant |
521 // pool entry to a class fails. | 521 // pool entry to a class fails. |
522 static void add_resolution_error(constantPoolHandle pool, int which, symbolHandle error); | 522 static void add_resolution_error(constantPoolHandle pool, int which, Symbol* error); |
523 static symbolOop find_resolution_error(constantPoolHandle pool, int which); | 523 static Symbol* find_resolution_error(constantPoolHandle pool, int which); |
524 | 524 |
525 private: | 525 private: |
526 | 526 |
527 enum Constants { | 527 enum Constants { |
528 _loader_constraint_size = 107, // number of entries in constraint table | 528 _loader_constraint_size = 107, // number of entries in constraint table |
578 static LoaderConstraintTable* constraints() { return _loader_constraints; } | 578 static LoaderConstraintTable* constraints() { return _loader_constraints; } |
579 static ResolutionErrorTable* resolution_errors() { return _resolution_errors; } | 579 static ResolutionErrorTable* resolution_errors() { return _resolution_errors; } |
580 static SymbolPropertyTable* invoke_method_table() { return _invoke_method_table; } | 580 static SymbolPropertyTable* invoke_method_table() { return _invoke_method_table; } |
581 | 581 |
582 // Basic loading operations | 582 // Basic loading operations |
583 static klassOop resolve_instance_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); | 583 static klassOop resolve_instance_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); |
584 static klassOop resolve_array_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); | 584 static klassOop resolve_array_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); |
585 static instanceKlassHandle handle_parallel_super_load(symbolHandle class_name, symbolHandle supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS); | 585 static instanceKlassHandle handle_parallel_super_load(Symbol* class_name, Symbol* supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS); |
586 // Wait on SystemDictionary_lock; unlocks lockObject before | 586 // Wait on SystemDictionary_lock; unlocks lockObject before |
587 // waiting; relocks lockObject with correct recursion count | 587 // waiting; relocks lockObject with correct recursion count |
588 // after waiting, but before reentering SystemDictionary_lock | 588 // after waiting, but before reentering SystemDictionary_lock |
589 // to preserve lock order semantics. | 589 // to preserve lock order semantics. |
590 static void double_lock_wait(Handle lockObject, TRAPS); | 590 static void double_lock_wait(Handle lockObject, TRAPS); |
591 static void define_instance_class(instanceKlassHandle k, TRAPS); | 591 static void define_instance_class(instanceKlassHandle k, TRAPS); |
592 static instanceKlassHandle find_or_define_instance_class(symbolHandle class_name, | 592 static instanceKlassHandle find_or_define_instance_class(Symbol* class_name, |
593 Handle class_loader, | 593 Handle class_loader, |
594 instanceKlassHandle k, TRAPS); | 594 instanceKlassHandle k, TRAPS); |
595 static instanceKlassHandle load_shared_class(symbolHandle class_name, | 595 static instanceKlassHandle load_shared_class(Symbol* class_name, |
596 Handle class_loader, TRAPS); | 596 Handle class_loader, TRAPS); |
597 static instanceKlassHandle load_shared_class(instanceKlassHandle ik, | 597 static instanceKlassHandle load_shared_class(instanceKlassHandle ik, |
598 Handle class_loader, TRAPS); | 598 Handle class_loader, TRAPS); |
599 static instanceKlassHandle load_instance_class(symbolHandle class_name, Handle class_loader, TRAPS); | 599 static instanceKlassHandle load_instance_class(Symbol* class_name, Handle class_loader, TRAPS); |
600 static Handle compute_loader_lock_object(Handle class_loader, TRAPS); | 600 static Handle compute_loader_lock_object(Handle class_loader, TRAPS); |
601 static void check_loader_lock_contention(Handle loader_lock, TRAPS); | 601 static void check_loader_lock_contention(Handle loader_lock, TRAPS); |
602 static bool is_parallelCapable(Handle class_loader); | 602 static bool is_parallelCapable(Handle class_loader); |
603 static bool is_parallelDefine(Handle class_loader); | 603 static bool is_parallelDefine(Handle class_loader); |
604 | 604 |
605 static klassOop find_shared_class(symbolHandle class_name); | 605 static klassOop find_shared_class(Symbol* class_name); |
606 | 606 |
607 // Setup link to hierarchy | 607 // Setup link to hierarchy |
608 static void add_to_hierarchy(instanceKlassHandle k, TRAPS); | 608 static void add_to_hierarchy(instanceKlassHandle k, TRAPS); |
609 | 609 |
610 private: | 610 private: |
611 // We pass in the hashtable index so we can calculate it outside of | 611 // We pass in the hashtable index so we can calculate it outside of |
612 // the SystemDictionary_lock. | 612 // the SystemDictionary_lock. |
613 | 613 |
614 // Basic find on loaded classes | 614 // Basic find on loaded classes |
615 static klassOop find_class(int index, unsigned int hash, | 615 static klassOop find_class(int index, unsigned int hash, |
616 symbolHandle name, Handle loader); | 616 Symbol* name, Handle loader); |
617 static klassOop find_class(Symbol* class_name, Handle class_loader); | |
617 | 618 |
618 // Basic find on classes in the midst of being loaded | 619 // Basic find on classes in the midst of being loaded |
619 static symbolOop find_placeholder(int index, unsigned int hash, | 620 static Symbol* find_placeholder(Symbol* name, Handle loader); |
620 symbolHandle name, Handle loader); | |
621 | |
622 // Basic find operation of loaded classes and classes in the midst | |
623 // of loading; used for assertions and verification only. | |
624 static oop find_class_or_placeholder(symbolHandle class_name, | |
625 Handle class_loader); | |
626 | 621 |
627 // Updating entry in dictionary | 622 // Updating entry in dictionary |
628 // Add a completely loaded class | 623 // Add a completely loaded class |
629 static void add_klass(int index, symbolHandle class_name, | 624 static void add_klass(int index, Symbol* class_name, |
630 Handle class_loader, KlassHandle obj); | 625 Handle class_loader, KlassHandle obj); |
631 | 626 |
632 // Add a placeholder for a class being loaded | 627 // Add a placeholder for a class being loaded |
633 static void add_placeholder(int index, | 628 static void add_placeholder(int index, |
634 symbolHandle class_name, | 629 Symbol* class_name, |
635 Handle class_loader); | 630 Handle class_loader); |
636 static void remove_placeholder(int index, | 631 static void remove_placeholder(int index, |
637 symbolHandle class_name, | 632 Symbol* class_name, |
638 Handle class_loader); | 633 Handle class_loader); |
639 | 634 |
640 // Performs cleanups after resolve_super_or_fail. This typically needs | 635 // Performs cleanups after resolve_super_or_fail. This typically needs |
641 // to be called on failure. | 636 // to be called on failure. |
642 // Won't throw, but can block. | 637 // Won't throw, but can block. |
643 static void resolution_cleanups(symbolHandle class_name, | 638 static void resolution_cleanups(Symbol* class_name, |
644 Handle class_loader, | 639 Handle class_loader, |
645 TRAPS); | 640 TRAPS); |
646 | 641 |
647 // Initialization | 642 // Initialization |
648 static void initialize_preloaded_classes(TRAPS); | 643 static void initialize_preloaded_classes(TRAPS); |
668 | 663 |
669 static bool _has_loadClassInternal; | 664 static bool _has_loadClassInternal; |
670 static bool _has_checkPackageAccess; | 665 static bool _has_checkPackageAccess; |
671 }; | 666 }; |
672 | 667 |
673 // Cf. vmSymbols vs. vmSymbolHandles | |
674 class SystemDictionaryHandles : AllStatic { | 668 class SystemDictionaryHandles : AllStatic { |
675 public: | 669 public: |
676 #define WK_KLASS_HANDLE_DECLARE(name, ignore_symbol, option) \ | 670 #define WK_KLASS_HANDLE_DECLARE(name, ignore_symbol, option) \ |
677 static KlassHandle name() { \ | 671 static KlassHandle name() { \ |
678 SystemDictionary::name(); \ | 672 SystemDictionary::name(); \ |