comparison src/share/vm/classfile/systemDictionary.hpp @ 2181:d25d4ca69222

Merge.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Wed, 16 Feb 2011 13:47:20 +0100
parents 89bf01e6b049 3582bf76420e
children a2babfb34c24
comparison
equal deleted inserted replaced
2108:50b45e2d9725 2181:d25d4ca69222
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
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
169 \ 169 \
170 /* If this class isn't present, it won't be referenced. */ \ 170 /* If this class isn't present, it won't be referenced. */ \
171 template(sun_misc_AtomicLongCSImpl_klass, sun_misc_AtomicLongCSImpl, Opt) \ 171 template(sun_misc_AtomicLongCSImpl_klass, sun_misc_AtomicLongCSImpl, Opt) \
172 \ 172 \
173 template(sun_jkernel_DownloadManager_klass, sun_jkernel_DownloadManager, Opt_Kernel) \ 173 template(sun_jkernel_DownloadManager_klass, sun_jkernel_DownloadManager, Opt_Kernel) \
174 \
175 template(sun_misc_PostVMInitHook_klass, sun_misc_PostVMInitHook, Opt) \
174 \ 176 \
175 /* Preload boxing klasses */ \ 177 /* Preload boxing klasses */ \
176 template(Boolean_klass, java_lang_Boolean, Pre) \ 178 template(Boolean_klass, java_lang_Boolean, Pre) \
177 template(Character_klass, java_lang_Character, Pre) \ 179 template(Character_klass, java_lang_Character, Pre) \
178 template(Float_klass, java_lang_Float, Pre) \ 180 template(Float_klass, java_lang_Float, Pre) \
255 // class if needed. If not found a NoClassDefFoundError or a 257 // class if needed. If not found a NoClassDefFoundError or a
256 // ClassNotFoundException is thrown, depending on the value on the 258 // ClassNotFoundException is thrown, depending on the value on the
257 // throw_error flag. For most uses the throw_error argument should be set 259 // throw_error flag. For most uses the throw_error argument should be set
258 // to true. 260 // to true.
259 261
260 static klassOop resolve_or_fail(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS); 262 static klassOop resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS);
261 // Convenient call for null loader and protection domain. 263 // Convenient call for null loader and protection domain.
262 static klassOop resolve_or_fail(symbolHandle class_name, bool throw_error, TRAPS); 264 static klassOop resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS);
263 private: 265 private:
264 // handle error translation for resolve_or_null results 266 // handle error translation for resolve_or_null results
265 static klassOop handle_resolution_exception(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS); 267 static klassOop handle_resolution_exception(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS);
266 268
267 public: 269 public:
268 270
269 // Returns a class with a given class name and class loader. 271 // Returns a class with a given class name and class loader.
270 // Loads the class if needed. If not found NULL is returned. 272 // Loads the class if needed. If not found NULL is returned.
271 static klassOop resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); 273 static klassOop resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
272 // Version with null loader and protection domain 274 // Version with null loader and protection domain
273 static klassOop resolve_or_null(symbolHandle class_name, TRAPS); 275 static klassOop resolve_or_null(Symbol* class_name, TRAPS);
274 276
275 // Resolve a superclass or superinterface. Called from ClassFileParser, 277 // Resolve a superclass or superinterface. Called from ClassFileParser,
276 // parse_interfaces, resolve_instance_class_or_null, load_shared_class 278 // parse_interfaces, resolve_instance_class_or_null, load_shared_class
277 // "child_name" is the class whose super class or interface is being resolved. 279 // "child_name" is the class whose super class or interface is being resolved.
278 static klassOop resolve_super_or_fail(symbolHandle child_name, 280 static klassOop resolve_super_or_fail(Symbol* child_name,
279 symbolHandle class_name, 281 Symbol* class_name,
280 Handle class_loader, 282 Handle class_loader,
281 Handle protection_domain, 283 Handle protection_domain,
282 bool is_superclass, 284 bool is_superclass,
283 TRAPS); 285 TRAPS);
284 286
285 // Parse new stream. This won't update the system dictionary or 287 // Parse new stream. This won't update the system dictionary or
286 // class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses. 288 // class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses.
287 static klassOop parse_stream(symbolHandle class_name, 289 static klassOop parse_stream(Symbol* class_name,
288 Handle class_loader, 290 Handle class_loader,
289 Handle protection_domain, 291 Handle protection_domain,
290 ClassFileStream* st, 292 ClassFileStream* st,
291 TRAPS) { 293 TRAPS) {
292 KlassHandle nullHandle; 294 KlassHandle nullHandle;
293 return parse_stream(class_name, class_loader, protection_domain, st, nullHandle, NULL, THREAD); 295 return parse_stream(class_name, class_loader, protection_domain, st, nullHandle, NULL, THREAD);
294 } 296 }
295 static klassOop parse_stream(symbolHandle class_name, 297 static klassOop parse_stream(Symbol* class_name,
296 Handle class_loader, 298 Handle class_loader,
297 Handle protection_domain, 299 Handle protection_domain,
298 ClassFileStream* st, 300 ClassFileStream* st,
299 KlassHandle host_klass, 301 KlassHandle host_klass,
300 GrowableArray<Handle>* cp_patches, 302 GrowableArray<Handle>* cp_patches,
301 TRAPS); 303 TRAPS);
302 304
303 // Resolve from stream (called by jni_DefineClass and JVM_DefineClass) 305 // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
304 static klassOop resolve_from_stream(symbolHandle class_name, Handle class_loader, 306 static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
305 Handle protection_domain, 307 Handle protection_domain,
306 ClassFileStream* st, bool verify, TRAPS); 308 ClassFileStream* st, bool verify, TRAPS);
307 309
308 // Lookup an already loaded class. If not found NULL is returned. 310 // Lookup an already loaded class. If not found NULL is returned.
309 static klassOop find(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); 311 static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
310 312
311 // Lookup an already loaded instance or array class. 313 // Lookup an already loaded instance or array class.
312 // Do not make any queries to class loaders; consult only the cache. 314 // Do not make any queries to class loaders; consult only the cache.
313 // If not found NULL is returned. 315 // If not found NULL is returned.
314 static klassOop find_instance_or_array_klass(symbolHandle class_name, 316 static klassOop find_instance_or_array_klass(Symbol* class_name,
315 Handle class_loader, 317 Handle class_loader,
316 Handle protection_domain, 318 Handle protection_domain,
317 TRAPS); 319 TRAPS);
318 320
319 // If the given name is known to vmSymbols, return the well-know klass: 321 // If the given name is known to vmSymbols, return the well-know klass:
320 static klassOop find_well_known_klass(symbolOop class_name); 322 static klassOop find_well_known_klass(Symbol* class_name);
321 323
322 // Lookup an instance or array class that has already been loaded 324 // Lookup an instance or array class that has already been loaded
323 // either into the given class loader, or else into another class 325 // either into the given class loader, or else into another class
324 // loader that is constrained (via loader constraints) to produce 326 // loader that is constrained (via loader constraints) to produce
325 // a consistent class. Do not take protection domains into account. 327 // a consistent class. Do not take protection domains into account.
338 // 4. Loading was attempted, but there was a linkage error of some sort. 340 // 4. Loading was attempted, but there was a linkage error of some sort.
339 // In all of these cases, the loader constraints on this type are 341 // In all of these cases, the loader constraints on this type are
340 // satisfied, and it is safe for classes in the given class loader 342 // satisfied, and it is safe for classes in the given class loader
341 // to manipulate strongly-typed values of the found class, subject 343 // to manipulate strongly-typed values of the found class, subject
342 // to local linkage and access checks. 344 // to local linkage and access checks.
343 static klassOop find_constrained_instance_or_array_klass(symbolHandle class_name, 345 static klassOop find_constrained_instance_or_array_klass(Symbol* class_name,
344 Handle class_loader, 346 Handle class_loader,
345 TRAPS); 347 TRAPS);
346 348
347 // Iterate over all klasses in dictionary 349 // Iterate over all klasses in dictionary
348 // Just the classes from defining class loaders 350 // Just the classes from defining class loaders
353 static void classes_do(void f(klassOop, oop)); 355 static void classes_do(void f(klassOop, oop));
354 // All classes, and their class loaders 356 // All classes, and their class loaders
355 // (added for helpers that use HandleMarks and ResourceMarks) 357 // (added for helpers that use HandleMarks and ResourceMarks)
356 static void classes_do(void f(klassOop, oop, TRAPS), TRAPS); 358 static void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
357 // All entries in the placeholder table and their class loaders 359 // All entries in the placeholder table and their class loaders
358 static void placeholders_do(void f(symbolOop, oop)); 360 static void placeholders_do(void f(Symbol*, oop));
359 361
360 // Iterate over all methods in all klasses in dictionary 362 // Iterate over all methods in all klasses in dictionary
361 static void methods_do(void f(methodOop)); 363 static void methods_do(void f(methodOop));
362 364
363 // Garbage collection support 365 // Garbage collection support
412 414
413 // Verification 415 // Verification
414 static void verify(); 416 static void verify();
415 417
416 #ifdef ASSERT 418 #ifdef ASSERT
417 static bool is_internal_format(symbolHandle class_name); 419 static bool is_internal_format(Symbol* class_name);
418 #endif 420 #endif
419 421
420 // Verify class is in dictionary 422 // Verify class is in dictionary
421 static void verify_obj_klass_present(Handle obj, 423 static void verify_obj_klass_present(Handle obj,
422 symbolHandle class_name, 424 Symbol* class_name,
423 Handle class_loader); 425 Handle class_loader);
424 426
425 // Initialization 427 // Initialization
426 static void initialize(TRAPS); 428 static void initialize(TRAPS);
427 429
498 500
499 public: 501 public:
500 // Note: java_lang_Class::primitive_type is the inverse of java_mirror 502 // Note: java_lang_Class::primitive_type is the inverse of java_mirror
501 503
502 // Check class loader constraints 504 // Check class loader constraints
503 static bool add_loader_constraint(symbolHandle name, Handle loader1, 505 static bool add_loader_constraint(Symbol* name, Handle loader1,
504 Handle loader2, TRAPS); 506 Handle loader2, TRAPS);
505 static char* check_signature_loaders(symbolHandle signature, Handle loader1, 507 static char* check_signature_loaders(Symbol* signature, Handle loader1,
506 Handle loader2, bool is_method, TRAPS); 508 Handle loader2, bool is_method, TRAPS);
507 509
508 // JSR 292 510 // JSR 292
509 // find the java.dyn.MethodHandles::invoke method for a given signature 511 // find the java.dyn.MethodHandles::invoke method for a given signature
510 static methodOop find_method_handle_invoke(symbolHandle name, 512 static methodOop find_method_handle_invoke(Symbol* name,
511 symbolHandle signature, 513 Symbol* signature,
512 KlassHandle accessing_klass, 514 KlassHandle accessing_klass,
513 TRAPS); 515 TRAPS);
514 // ask Java to compute a java.dyn.MethodType object for a given signature 516 // ask Java to compute a java.dyn.MethodType object for a given signature
515 static Handle find_method_handle_type(symbolHandle signature, 517 static Handle find_method_handle_type(Symbol* signature,
516 KlassHandle accessing_klass, 518 KlassHandle accessing_klass,
517 bool for_invokeGeneric, 519 bool for_invokeGeneric,
518 bool& return_bcp_flag, 520 bool& return_bcp_flag,
519 TRAPS); 521 TRAPS);
520 // ask Java to compute a java.dyn.MethodHandle object for a given CP entry 522 // ask Java to compute a java.dyn.MethodHandle object for a given CP entry
521 static Handle link_method_handle_constant(KlassHandle caller, 523 static Handle link_method_handle_constant(KlassHandle caller,
522 int ref_kind, //e.g., JVM_REF_invokeVirtual 524 int ref_kind, //e.g., JVM_REF_invokeVirtual
523 KlassHandle callee, 525 KlassHandle callee,
524 symbolHandle name, 526 Symbol* name,
525 symbolHandle signature, 527 Symbol* signature,
526 TRAPS); 528 TRAPS);
527 // ask Java to create a dynamic call site, while linking an invokedynamic op 529 // ask Java to create a dynamic call site, while linking an invokedynamic op
528 static Handle make_dynamic_call_site(Handle bootstrap_method, 530 static Handle make_dynamic_call_site(Handle bootstrap_method,
529 // Callee information: 531 // Callee information:
530 symbolHandle name, 532 Symbol* name,
531 methodHandle signature_invoker, 533 methodHandle signature_invoker,
532 Handle info, 534 Handle info,
533 // Caller information: 535 // Caller information:
534 methodHandle caller_method, 536 methodHandle caller_method,
535 int caller_bci, 537 int caller_bci,
548 instanceKlass::cast((loader)->klass())->name()->as_C_string() ); 550 instanceKlass::cast((loader)->klass())->name()->as_C_string() );
549 } 551 }
550 552
551 // Record the error when the first attempt to resolve a reference from a constant 553 // Record the error when the first attempt to resolve a reference from a constant
552 // pool entry to a class fails. 554 // pool entry to a class fails.
553 static void add_resolution_error(constantPoolHandle pool, int which, symbolHandle error); 555 static void add_resolution_error(constantPoolHandle pool, int which, Symbol* error);
554 static symbolOop find_resolution_error(constantPoolHandle pool, int which); 556 static Symbol* find_resolution_error(constantPoolHandle pool, int which);
555 557
556 private: 558 private:
557 559
558 enum Constants { 560 enum Constants {
559 _loader_constraint_size = 107, // number of entries in constraint table 561 _loader_constraint_size = 107, // number of entries in constraint table
609 static LoaderConstraintTable* constraints() { return _loader_constraints; } 611 static LoaderConstraintTable* constraints() { return _loader_constraints; }
610 static ResolutionErrorTable* resolution_errors() { return _resolution_errors; } 612 static ResolutionErrorTable* resolution_errors() { return _resolution_errors; }
611 static SymbolPropertyTable* invoke_method_table() { return _invoke_method_table; } 613 static SymbolPropertyTable* invoke_method_table() { return _invoke_method_table; }
612 614
613 // Basic loading operations 615 // Basic loading operations
614 static klassOop resolve_instance_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); 616 static klassOop resolve_instance_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
615 static klassOop resolve_array_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); 617 static klassOop resolve_array_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
616 static instanceKlassHandle handle_parallel_super_load(symbolHandle class_name, symbolHandle supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS); 618 static instanceKlassHandle handle_parallel_super_load(Symbol* class_name, Symbol* supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS);
617 // Wait on SystemDictionary_lock; unlocks lockObject before 619 // Wait on SystemDictionary_lock; unlocks lockObject before
618 // waiting; relocks lockObject with correct recursion count 620 // waiting; relocks lockObject with correct recursion count
619 // after waiting, but before reentering SystemDictionary_lock 621 // after waiting, but before reentering SystemDictionary_lock
620 // to preserve lock order semantics. 622 // to preserve lock order semantics.
621 static void double_lock_wait(Handle lockObject, TRAPS); 623 static void double_lock_wait(Handle lockObject, TRAPS);
622 static void define_instance_class(instanceKlassHandle k, TRAPS); 624 static void define_instance_class(instanceKlassHandle k, TRAPS);
623 static instanceKlassHandle find_or_define_instance_class(symbolHandle class_name, 625 static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
624 Handle class_loader, 626 Handle class_loader,
625 instanceKlassHandle k, TRAPS); 627 instanceKlassHandle k, TRAPS);
626 static instanceKlassHandle load_shared_class(symbolHandle class_name, 628 static instanceKlassHandle load_shared_class(Symbol* class_name,
627 Handle class_loader, TRAPS); 629 Handle class_loader, TRAPS);
628 static instanceKlassHandle load_shared_class(instanceKlassHandle ik, 630 static instanceKlassHandle load_shared_class(instanceKlassHandle ik,
629 Handle class_loader, TRAPS); 631 Handle class_loader, TRAPS);
630 static instanceKlassHandle load_instance_class(symbolHandle class_name, Handle class_loader, TRAPS); 632 static instanceKlassHandle load_instance_class(Symbol* class_name, Handle class_loader, TRAPS);
631 static Handle compute_loader_lock_object(Handle class_loader, TRAPS); 633 static Handle compute_loader_lock_object(Handle class_loader, TRAPS);
632 static void check_loader_lock_contention(Handle loader_lock, TRAPS); 634 static void check_loader_lock_contention(Handle loader_lock, TRAPS);
633 static bool is_parallelCapable(Handle class_loader); 635 static bool is_parallelCapable(Handle class_loader);
634 static bool is_parallelDefine(Handle class_loader); 636 static bool is_parallelDefine(Handle class_loader);
635 637
636 static klassOop find_shared_class(symbolHandle class_name); 638 static klassOop find_shared_class(Symbol* class_name);
637 639
638 // Setup link to hierarchy 640 // Setup link to hierarchy
639 static void add_to_hierarchy(instanceKlassHandle k, TRAPS); 641 static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
640 642
641 private: 643 private:
642 // We pass in the hashtable index so we can calculate it outside of 644 // We pass in the hashtable index so we can calculate it outside of
643 // the SystemDictionary_lock. 645 // the SystemDictionary_lock.
644 646
645 // Basic find on loaded classes 647 // Basic find on loaded classes
646 static klassOop find_class(int index, unsigned int hash, 648 static klassOop find_class(int index, unsigned int hash,
647 symbolHandle name, Handle loader); 649 Symbol* name, Handle loader);
650 static klassOop find_class(Symbol* class_name, Handle class_loader);
648 651
649 // Basic find on classes in the midst of being loaded 652 // Basic find on classes in the midst of being loaded
650 static symbolOop find_placeholder(int index, unsigned int hash, 653 static Symbol* find_placeholder(Symbol* name, Handle loader);
651 symbolHandle name, Handle loader);
652
653 // Basic find operation of loaded classes and classes in the midst
654 // of loading; used for assertions and verification only.
655 static oop find_class_or_placeholder(symbolHandle class_name,
656 Handle class_loader);
657 654
658 // Updating entry in dictionary 655 // Updating entry in dictionary
659 // Add a completely loaded class 656 // Add a completely loaded class
660 static void add_klass(int index, symbolHandle class_name, 657 static void add_klass(int index, Symbol* class_name,
661 Handle class_loader, KlassHandle obj); 658 Handle class_loader, KlassHandle obj);
662 659
663 // Add a placeholder for a class being loaded 660 // Add a placeholder for a class being loaded
664 static void add_placeholder(int index, 661 static void add_placeholder(int index,
665 symbolHandle class_name, 662 Symbol* class_name,
666 Handle class_loader); 663 Handle class_loader);
667 static void remove_placeholder(int index, 664 static void remove_placeholder(int index,
668 symbolHandle class_name, 665 Symbol* class_name,
669 Handle class_loader); 666 Handle class_loader);
670 667
671 // Performs cleanups after resolve_super_or_fail. This typically needs 668 // Performs cleanups after resolve_super_or_fail. This typically needs
672 // to be called on failure. 669 // to be called on failure.
673 // Won't throw, but can block. 670 // Won't throw, but can block.
674 static void resolution_cleanups(symbolHandle class_name, 671 static void resolution_cleanups(Symbol* class_name,
675 Handle class_loader, 672 Handle class_loader,
676 TRAPS); 673 TRAPS);
677 674
678 // Initialization 675 // Initialization
679 static void initialize_preloaded_classes(TRAPS); 676 static void initialize_preloaded_classes(TRAPS);
699 696
700 static bool _has_loadClassInternal; 697 static bool _has_loadClassInternal;
701 static bool _has_checkPackageAccess; 698 static bool _has_checkPackageAccess;
702 }; 699 };
703 700
704 // Cf. vmSymbols vs. vmSymbolHandles
705 class SystemDictionaryHandles : AllStatic { 701 class SystemDictionaryHandles : AllStatic {
706 public: 702 public:
707 #define WK_KLASS_HANDLE_DECLARE(name, ignore_symbol, option) \ 703 #define WK_KLASS_HANDLE_DECLARE(name, ignore_symbol, option) \
708 static KlassHandle name() { \ 704 static KlassHandle name() { \
709 SystemDictionary::name(); \ 705 SystemDictionary::name(); \