src/share/vm/classfile/systemDictionary.hpp

Print this page
rev 2 : [mq]: wkk.patch


  47 // Clients of this class who are interested in finding if a class has
  48 // been completely loaded -- not classes in the process of being loaded --
  49 // can read the SystemDictionary unlocked. This is safe because
  50 //    - entries are only deleted at safepoints
  51 //    - readers cannot come to a safepoint while actively examining
  52 //         an entry  (an entry cannot be deleted from under a reader)
  53 //    - entries must be fully formed before they are available to concurrent
  54 //         readers (we must ensure write ordering)
  55 //
  56 // Note that placeholders are deleted at any time, as they are removed
  57 // when a class is completely loaded. Therefore, readers as well as writers
  58 // of placeholders must hold the SystemDictionary_lock.
  59 //
  60 
  61 class Dictionary;
  62 class PlaceholderTable;
  63 class LoaderConstraintTable;
  64 class HashtableBucket;
  65 class ResolutionErrorTable;
  66 




























































































  67 class SystemDictionary : AllStatic {
  68   friend class VMStructs;
  69   friend class CompactingPermGenGen;
  70   NOT_PRODUCT(friend class instanceKlassKlass;)
  71 
  72  public:
























  73   // Returns a class with a given class name and class loader.  Loads the
  74   // class if needed. If not found a NoClassDefFoundError or a
  75   // ClassNotFoundException is thrown, depending on the value on the
  76   // throw_error flag.  For most uses the throw_error argument should be set
  77   // to true.
  78 
  79   static klassOop resolve_or_fail(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS);
  80   // Convenient call for null loader and protection domain.
  81   static klassOop resolve_or_fail(symbolHandle class_name, bool throw_error, TRAPS);
  82 private:
  83   // handle error translation for resolve_or_null results
  84   static klassOop handle_resolution_exception(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS);
  85 
  86 public:
  87 
  88   // Returns a class with a given class name and class loader.
  89   // Loads the class if needed. If not found NULL is returned.
  90   static klassOop resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS);
  91   // Version with null loader and protection domain
  92   static klassOop resolve_or_null(symbolHandle class_name, TRAPS);


 106   static klassOop parse_stream(symbolHandle class_name,
 107                                Handle class_loader,
 108                                Handle protection_domain,
 109                                ClassFileStream* st,
 110                                TRAPS);
 111 
 112   // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
 113   static klassOop resolve_from_stream(symbolHandle class_name, Handle class_loader, Handle protection_domain, ClassFileStream* st, TRAPS);
 114 
 115   // Lookup an already loaded class. If not found NULL is returned.
 116   static klassOop find(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS);
 117 
 118   // Lookup an already loaded instance or array class.
 119   // Do not make any queries to class loaders; consult only the cache.
 120   // If not found NULL is returned.
 121   static klassOop find_instance_or_array_klass(symbolHandle class_name,
 122                                                Handle class_loader,
 123                                                Handle protection_domain,
 124                                                TRAPS);
 125 



 126   // Lookup an instance or array class that has already been loaded
 127   // either into the given class loader, or else into another class
 128   // loader that is constrained (via loader constraints) to produce
 129   // a consistent class.  Do not take protection domains into account.
 130   // Do not make any queries to class loaders; consult only the cache.
 131   // Return NULL if the class is not found.
 132   //
 133   // This function is a strict superset of find_instance_or_array_klass.
 134   // This function (the unchecked version) makes a conservative prediction
 135   // of the result of the checked version, assuming successful lookup.
 136   // If both functions return non-null, they must return the same value.
 137   // Also, the unchecked version may sometimes be non-null where the
 138   // checked version is null.  This can occur in several ways:
 139   //   1. No query has yet been made to the class loader.
 140   //   2. The class loader was queried, but chose not to delegate.
 141   //   3. ClassLoader.checkPackageAccess rejected a proposed protection domain.
 142   //   4. Loading was attempted, but there was a linkage error of some sort.
 143   // In all of these cases, the loader constraints on this type are
 144   // satisfied, and it is safe for classes in the given class loader
 145   // to manipulate strongly-typed values of the found class, subject


 218   static void verify();
 219 
 220 #ifdef ASSERT
 221   static bool is_internal_format(symbolHandle class_name);
 222 #endif
 223 
 224   // Verify class is in dictionary
 225   static void verify_obj_klass_present(Handle obj,
 226                                        symbolHandle class_name,
 227                                        Handle class_loader);
 228 
 229   // Initialization
 230   static void initialize(TRAPS);
 231 
 232   // Fast access to commonly used classes (preloaded)
 233   static klassOop check_klass(klassOop k) {
 234     assert(k != NULL, "preloaded klass not initialized");
 235     return k;
 236   }
 237 
 238 public:
 239   static klassOop object_klass()            { return check_klass(_object_klass); }
 240   static klassOop string_klass()            { return check_klass(_string_klass); }
 241   static klassOop class_klass()             { return check_klass(_class_klass); }
 242   static klassOop cloneable_klass()         { return check_klass(_cloneable_klass); }
 243   static klassOop classloader_klass()       { return check_klass(_classloader_klass); }
 244   static klassOop serializable_klass()      { return check_klass(_serializable_klass); }
 245   static klassOop system_klass()            { return check_klass(_system_klass); }
 246 
 247   static klassOop throwable_klass()         { return check_klass(_throwable_klass); }
 248   static klassOop error_klass()             { return check_klass(_error_klass); }
 249   static klassOop threaddeath_klass()       { return check_klass(_threaddeath_klass); }
 250   static klassOop exception_klass()         { return check_klass(_exception_klass); }
 251   static klassOop runtime_exception_klass() { return check_klass(_runtime_exception_klass); }
 252   static klassOop classNotFoundException_klass() { return check_klass(_classNotFoundException_klass); }
 253   static klassOop noClassDefFoundError_klass()   { return check_klass(_noClassDefFoundError_klass); }
 254   static klassOop linkageError_klass()       { return check_klass(_linkageError_klass); }
 255   static klassOop ClassCastException_klass() { return check_klass(_classCastException_klass); }
 256   static klassOop ArrayStoreException_klass() { return check_klass(_arrayStoreException_klass); }
 257   static klassOop virtualMachineError_klass()  { return check_klass(_virtualMachineError_klass); }
 258   static klassOop OutOfMemoryError_klass()  { return check_klass(_outOfMemoryError_klass); }
 259   static klassOop StackOverflowError_klass() { return check_klass(_StackOverflowError_klass); }
 260   static klassOop IllegalMonitorStateException_klass() { return check_klass(_illegalMonitorStateException_klass); }
 261   static klassOop protectionDomain_klass()  { return check_klass(_protectionDomain_klass); }
 262   static klassOop AccessControlContext_klass() { return check_klass(_AccessControlContext_klass); }
 263   static klassOop reference_klass()         { return check_klass(_reference_klass); }
 264   static klassOop soft_reference_klass()    { return check_klass(_soft_reference_klass); }
 265   static klassOop weak_reference_klass()    { return check_klass(_weak_reference_klass); }
 266   static klassOop final_reference_klass()   { return check_klass(_final_reference_klass); }
 267   static klassOop phantom_reference_klass() { return check_klass(_phantom_reference_klass); }
 268   static klassOop finalizer_klass()         { return check_klass(_finalizer_klass); }
 269 
 270   static klassOop thread_klass()            { return check_klass(_thread_klass); }
 271   static klassOop threadGroup_klass()       { return check_klass(_threadGroup_klass); }
 272   static klassOop properties_klass()        { return check_klass(_properties_klass); }
 273   static klassOop reflect_accessible_object_klass() { return check_klass(_reflect_accessible_object_klass); }
 274   static klassOop reflect_field_klass()     { return check_klass(_reflect_field_klass); }
 275   static klassOop reflect_method_klass()    { return check_klass(_reflect_method_klass); }
 276   static klassOop reflect_constructor_klass() { return check_klass(_reflect_constructor_klass); }
 277   static klassOop reflect_method_accessor_klass() {
 278     assert(JDK_Version::is_gte_jdk14x_version() && UseNewReflection, "JDK 1.4 only");
 279     return check_klass(_reflect_method_accessor_klass);
 280   }
 281   static klassOop reflect_constructor_accessor_klass() {
 282     assert(JDK_Version::is_gte_jdk14x_version() && UseNewReflection, "JDK 1.4 only");
 283     return check_klass(_reflect_constructor_accessor_klass);

 284   }
 285   // NOTE: needed too early in bootstrapping process to have checks based on JDK version
 286   static klassOop reflect_magic_klass()     { return _reflect_magic_klass; }
 287   static klassOop reflect_delegating_classloader_klass() { return _reflect_delegating_classloader_klass; }
 288   static klassOop reflect_constant_pool_klass() {
 289     assert(JDK_Version::is_gte_jdk15x_version(), "JDK 1.5 only");
 290     return _reflect_constant_pool_klass;
 291   }
 292   static klassOop reflect_unsafe_static_field_accessor_impl_klass() {
 293     assert(JDK_Version::is_gte_jdk15x_version(), "JDK 1.5 only");
 294     return _reflect_unsafe_static_field_accessor_impl_klass;
 295   }
 296 
 297   static klassOop vector_klass()            { return check_klass(_vector_klass); }
 298   static klassOop hashtable_klass()         { return check_klass(_hashtable_klass); }
 299   static klassOop stringBuffer_klass()      { return check_klass(_stringBuffer_klass); }
 300   static klassOop stackTraceElement_klass() { return check_klass(_stackTraceElement_klass); }

 301 
 302   static klassOop java_nio_Buffer_klass()   { return check_klass(_java_nio_Buffer_klass); }

 303 
 304   static klassOop sun_misc_AtomicLongCSImpl_klass() { return _sun_misc_AtomicLongCSImpl_klass; }
 305 
 306   // To support incremental JRE downloads (KERNEL JRE). Null if not present.
 307   static klassOop sun_jkernel_DownloadManager_klass() { return _sun_jkernel_DownloadManager_klass; }
 308 
 309   static klassOop boolean_klass()           { return check_klass(_boolean_klass); }
 310   static klassOop char_klass()              { return check_klass(_char_klass); }
 311   static klassOop float_klass()             { return check_klass(_float_klass); }
 312   static klassOop double_klass()            { return check_klass(_double_klass); }
 313   static klassOop byte_klass()              { return check_klass(_byte_klass); }
 314   static klassOop short_klass()             { return check_klass(_short_klass); }
 315   static klassOop int_klass()               { return check_klass(_int_klass); }
 316   static klassOop long_klass()              { return check_klass(_long_klass); }
 317 
 318   static klassOop box_klass(BasicType t) {
 319     assert((uint)t < T_VOID+1, "range check");
 320     return check_klass(_box_klasses[t]);
 321   }
 322   static BasicType box_klass_type(klassOop k);  // inverse of box_klass
 323 
 324   // methods returning lazily loaded klasses
 325   // The corresponding method to load the class must be called before calling them.
 326   static klassOop abstract_ownable_synchronizer_klass() { return check_klass(_abstract_ownable_synchronizer_klass); }
 327 
 328   static void load_abstract_ownable_synchronizer_klass(TRAPS);
 329 
 330 private:
 331   // Tells whether ClassLoader.loadClassInternal is present
 332   static bool has_loadClassInternal()       { return _has_loadClassInternal; }
 333 
 334 public:
 335   // Tells whether ClassLoader.checkPackageAccess is present
 336   static bool has_checkPackageAccess()      { return _has_checkPackageAccess; }
 337 
 338   static bool class_klass_loaded()          { return _class_klass != NULL; }
 339   static bool cloneable_klass_loaded()      { return _cloneable_klass != NULL; }
 340 
 341   // Returns default system loader
 342   static oop java_system_loader();
 343 
 344   // Compute the default system loader
 345   static void compute_java_system_loader(TRAPS);
 346 
 347 private:
 348   // Mirrors for primitive classes (created eagerly)
 349   static oop check_mirror(oop m) {
 350     assert(m != NULL, "mirror not initialized");
 351     return m;
 352   }
 353 
 354 public:
 355   // Note:  java_lang_Class::primitive_type is the inverse of java_mirror
 356 
 357   // Check class loader constraints
 358   static bool add_loader_constraint(symbolHandle name, Handle loader1,
 359                                     Handle loader2, TRAPS);


 481 
 482   // Performs cleanups after resolve_super_or_fail. This typically needs
 483   // to be called on failure.
 484   // Won't throw, but can block.
 485   static void resolution_cleanups(symbolHandle class_name,
 486                                   Handle class_loader,
 487                                   TRAPS);
 488 
 489   // Initialization
 490   static void initialize_preloaded_classes(TRAPS);
 491 
 492   // Class loader constraints
 493   static void check_constraints(int index, unsigned int hash,
 494                                 instanceKlassHandle k, Handle loader,
 495                                 bool defining, TRAPS);
 496   static void update_dictionary(int d_index, unsigned int d_hash,
 497                                 int p_index, unsigned int p_hash,
 498                                 instanceKlassHandle k, Handle loader, TRAPS);
 499 
 500   // Variables holding commonly used klasses (preloaded)
 501   static klassOop _object_klass;
 502   static klassOop _string_klass;
 503   static klassOop _class_klass;
 504   static klassOop _cloneable_klass;
 505   static klassOop _classloader_klass;
 506   static klassOop _serializable_klass;
 507   static klassOop _system_klass;
 508 
 509   static klassOop _throwable_klass;
 510   static klassOop _error_klass;
 511   static klassOop _threaddeath_klass;
 512   static klassOop _exception_klass;
 513   static klassOop _runtime_exception_klass;
 514   static klassOop _classNotFoundException_klass;
 515   static klassOop _noClassDefFoundError_klass;
 516   static klassOop _linkageError_klass;
 517   static klassOop _classCastException_klass;
 518   static klassOop _arrayStoreException_klass;
 519   static klassOop _virtualMachineError_klass;
 520   static klassOop _outOfMemoryError_klass;
 521   static klassOop _StackOverflowError_klass;
 522   static klassOop _illegalMonitorStateException_klass;
 523   static klassOop _protectionDomain_klass;
 524   static klassOop _AccessControlContext_klass;
 525   static klassOop _reference_klass;
 526   static klassOop _soft_reference_klass;
 527   static klassOop _weak_reference_klass;
 528   static klassOop _final_reference_klass;
 529   static klassOop _phantom_reference_klass;
 530   static klassOop _finalizer_klass;
 531 
 532   static klassOop _thread_klass;
 533   static klassOop _threadGroup_klass;
 534   static klassOop _properties_klass;
 535   static klassOop _reflect_accessible_object_klass;
 536   static klassOop _reflect_field_klass;
 537   static klassOop _reflect_method_klass;
 538   static klassOop _reflect_constructor_klass;
 539   // 1.4 reflection implementation
 540   static klassOop _reflect_magic_klass;
 541   static klassOop _reflect_method_accessor_klass;
 542   static klassOop _reflect_constructor_accessor_klass;
 543   static klassOop _reflect_delegating_classloader_klass;
 544   // 1.5 annotations implementation
 545   static klassOop _reflect_constant_pool_klass;
 546   static klassOop _reflect_unsafe_static_field_accessor_impl_klass;
 547 
 548   static klassOop _stringBuffer_klass;
 549   static klassOop _vector_klass;
 550   static klassOop _hashtable_klass;
 551 
 552   static klassOop _stackTraceElement_klass;
 553 
 554   static klassOop _java_nio_Buffer_klass;
 555 
 556   static klassOop _sun_misc_AtomicLongCSImpl_klass;
 557 
 558   // KERNEL JRE support.
 559   static klassOop _sun_jkernel_DownloadManager_klass;
 560 
 561   // Lazily loaded klasses
 562   static volatile klassOop _abstract_ownable_synchronizer_klass;
 563 
 564   // Box klasses
 565   static klassOop _boolean_klass;
 566   static klassOop _char_klass;
 567   static klassOop _float_klass;
 568   static klassOop _double_klass;
 569   static klassOop _byte_klass;
 570   static klassOop _short_klass;
 571   static klassOop _int_klass;
 572   static klassOop _long_klass;
 573 
 574   // table of same
 575   static klassOop _box_klasses[T_VOID+1];
 576 
 577   static oop  _java_system_loader;
 578 
 579   static bool _has_loadClassInternal;
 580   static bool _has_checkPackageAccess;
 581 };


  47 // Clients of this class who are interested in finding if a class has
  48 // been completely loaded -- not classes in the process of being loaded --
  49 // can read the SystemDictionary unlocked. This is safe because
  50 //    - entries are only deleted at safepoints
  51 //    - readers cannot come to a safepoint while actively examining
  52 //         an entry  (an entry cannot be deleted from under a reader)
  53 //    - entries must be fully formed before they are available to concurrent
  54 //         readers (we must ensure write ordering)
  55 //
  56 // Note that placeholders are deleted at any time, as they are removed
  57 // when a class is completely loaded. Therefore, readers as well as writers
  58 // of placeholders must hold the SystemDictionary_lock.
  59 //
  60 
  61 class Dictionary;
  62 class PlaceholderTable;
  63 class LoaderConstraintTable;
  64 class HashtableBucket;
  65 class ResolutionErrorTable;
  66 
  67 // Certain classes are preloaded, such as java.lang.Object and java.lang.String.
  68 // They are all "well-known", in the sense that no class loader is allowed
  69 // to provide a different definition.
  70 //
  71 // These klasses must all have names defined in vmSymbols.
  72 
  73 #define WK_KLASS_ENUM_NAME(kname)    kname##_knum
  74 
  75 // Each well-known class has a short klass name (like object_klass),
  76 // a vmSymbol name (like java_lang_Object), and a flag word
  77 // that makes some minor distinctions, like whether the klass
  78 // is preloaded, optional, release-specific, etc.
  79 // The order of these definitions is significant; it is the order in which
  80 // preloading is actually performed by initialize_preloaded_classes.
  81 
  82 #define WK_KLASSES_DO(template)                                               \
  83   /* well-known classes */                                                    \
  84   template(object_klass,                 java_lang_Object,               Pre) \
  85   template(string_klass,                 java_lang_String,               Pre) \
  86   template(class_klass,                  java_lang_Class,                Pre) \
  87   template(cloneable_klass,              java_lang_Cloneable,            Pre) \
  88   template(classloader_klass,            java_lang_ClassLoader,          Pre) \
  89   template(serializable_klass,           java_io_Serializable,           Pre) \
  90   template(system_klass,                 java_lang_System,               Pre) \
  91   template(throwable_klass,              java_lang_Throwable,            Pre) \
  92   template(error_klass,                  java_lang_Error,                Pre) \
  93   template(threaddeath_klass,            java_lang_ThreadDeath,          Pre) \
  94   template(exception_klass,              java_lang_Exception,            Pre) \
  95   template(runtime_exception_klass,      java_lang_RuntimeException,     Pre) \
  96   template(protectionDomain_klass,       java_security_ProtectionDomain, Pre) \
  97   template(AccessControlContext_klass,   java_security_AccessControlContext, Pre) \
  98   template(classNotFoundException_klass, java_lang_ClassNotFoundException, Pre) \
  99   template(noClassDefFoundError_klass,   java_lang_NoClassDefFoundError, Pre) \
 100   template(linkageError_klass,           java_lang_LinkageError,         Pre) \
 101   template(ClassCastException_klass,     java_lang_ClassCastException,   Pre) \
 102   template(ArrayStoreException_klass,    java_lang_ArrayStoreException,  Pre) \
 103   template(virtualMachineError_klass,    java_lang_VirtualMachineError,  Pre) \
 104   template(OutOfMemoryError_klass,       java_lang_OutOfMemoryError,     Pre) \
 105   template(StackOverflowError_klass,     java_lang_StackOverflowError,   Pre) \
 106   template(IllegalMonitorStateException_klass, java_lang_IllegalMonitorStateException, Pre) \
 107   template(reference_klass,              java_lang_ref_Reference,        Pre) \
 108                                                                               \
 109   /* Preload ref klasses and set reference types */                           \
 110   template(soft_reference_klass,         java_lang_ref_SoftReference,    Pre) \
 111   template(weak_reference_klass,         java_lang_ref_WeakReference,    Pre) \
 112   template(final_reference_klass,        java_lang_ref_FinalReference,   Pre) \
 113   template(phantom_reference_klass,      java_lang_ref_PhantomReference, Pre) \
 114   template(finalizer_klass,              java_lang_ref_Finalizer,        Pre) \
 115                                                                               \
 116   template(thread_klass,                 java_lang_Thread,               Pre) \
 117   template(threadGroup_klass,            java_lang_ThreadGroup,          Pre) \
 118   template(properties_klass,             java_util_Properties,           Pre) \
 119   template(reflect_accessible_object_klass, java_lang_reflect_AccessibleObject, Pre) \
 120   template(reflect_field_klass,          java_lang_reflect_Field,        Pre) \
 121   template(reflect_method_klass,         java_lang_reflect_Method,       Pre) \
 122   template(reflect_constructor_klass,    java_lang_reflect_Constructor,  Pre) \
 123                                                                               \
 124   /* NOTE: needed too early in bootstrapping process to have checks based on JDK version */ \
 125   /* Universe::is_gte_jdk14x_version() is not set up by this point. */        \
 126   /* It's okay if this turns out to be NULL in non-1.4 JDKs. */               \
 127   template(reflect_magic_klass,          sun_reflect_MagicAccessorImpl,  Opt) \
 128   template(reflect_method_accessor_klass, sun_reflect_MethodAccessorImpl, Opt_Only_JDK14NewRef) \
 129   template(reflect_constructor_accessor_klass, sun_reflect_ConstructorAccessorImpl, Opt_Only_JDK14NewRef) \
 130   template(reflect_delegating_classloader_klass, sun_reflect_DelegatingClassLoader, Opt) \
 131   template(reflect_constant_pool_klass,  sun_reflect_ConstantPool,       Opt_Only_JDK15) \
 132   template(reflect_unsafe_static_field_accessor_impl_klass, sun_reflect_UnsafeStaticFieldAccessorImpl, Opt_Only_JDK15) \
 133                                                                               \
 134   template(vector_klass,                 java_util_Vector,               Pre) \
 135   template(hashtable_klass,              java_util_Hashtable,            Pre) \
 136   template(stringBuffer_klass,           java_lang_StringBuffer,         Pre) \
 137                                                                               \
 138   /* It's NULL in non-1.4 JDKs. */                                            \
 139   template(stackTraceElement_klass,      java_lang_StackTraceElement,    Opt) \
 140   /* Universe::is_gte_jdk14x_version() is not set up by this point. */        \
 141   /* It's okay if this turns out to be NULL in non-1.4 JDKs. */               \
 142   template(java_nio_Buffer_klass,        java_nio_Buffer,                Opt) \
 143                                                                               \
 144   /* If this class isn't present, it won't be referenced. */                  \
 145   template(sun_misc_AtomicLongCSImpl_klass, sun_misc_AtomicLongCSImpl,      Opt) \
 146                                                                               \
 147   /* Preload boxing klasses */                                                \
 148   template(boolean_klass,                java_lang_Boolean,              Pre) \
 149   template(char_klass,                   java_lang_Character,            Pre) \
 150   template(float_klass,                  java_lang_Float,                Pre) \
 151   template(double_klass,                 java_lang_Double,               Pre) \
 152   template(byte_klass,                   java_lang_Byte,                 Pre) \
 153   template(short_klass,                  java_lang_Short,                Pre) \
 154   template(int_klass,                    java_lang_Integer,              Pre) \
 155   template(long_klass,                   java_lang_Long,                 Pre) \
 156   /*end*/
 157 
 158 
 159 class SystemDictionary : AllStatic {
 160   friend class VMStructs;
 161   friend class CompactingPermGenGen;
 162   NOT_PRODUCT(friend class instanceKlassKlass;)
 163 
 164  public:
 165   enum WKID {
 166     NO_WKID = 0,
 167 
 168     #define WK_KLASS_ENUM(name, ignore_s, ignore_o) WK_KLASS_ENUM_NAME(name),
 169     WK_KLASSES_DO(WK_KLASS_ENUM)
 170     #undef WK_KLASS_ENUM
 171 
 172     WKID_LIMIT,
 173 
 174     FIRST_WKID = NO_WKID + 1
 175   };
 176 
 177   enum InitOption {
 178     Pre,                        // preloaded; error if not present
 179 
 180     // Order is significant.  Options before this point require resolve_or_fail.
 181     // Options after this point will use resolve_or_null instead.
 182 
 183     Opt,                        // preload tried; NULL if not present
 184     Opt_Only_JDK14NewRef,       // preload tried; use only with NewReflection
 185     Opt_Only_JDK15              // preload tried; use only with JDK1.5+
 186   };
 187 
 188 
 189   // Returns a class with a given class name and class loader.  Loads the
 190   // class if needed. If not found a NoClassDefFoundError or a
 191   // ClassNotFoundException is thrown, depending on the value on the
 192   // throw_error flag.  For most uses the throw_error argument should be set
 193   // to true.
 194 
 195   static klassOop resolve_or_fail(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS);
 196   // Convenient call for null loader and protection domain.
 197   static klassOop resolve_or_fail(symbolHandle class_name, bool throw_error, TRAPS);
 198 private:
 199   // handle error translation for resolve_or_null results
 200   static klassOop handle_resolution_exception(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS);
 201 
 202 public:
 203 
 204   // Returns a class with a given class name and class loader.
 205   // Loads the class if needed. If not found NULL is returned.
 206   static klassOop resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS);
 207   // Version with null loader and protection domain
 208   static klassOop resolve_or_null(symbolHandle class_name, TRAPS);


 222   static klassOop parse_stream(symbolHandle class_name,
 223                                Handle class_loader,
 224                                Handle protection_domain,
 225                                ClassFileStream* st,
 226                                TRAPS);
 227 
 228   // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
 229   static klassOop resolve_from_stream(symbolHandle class_name, Handle class_loader, Handle protection_domain, ClassFileStream* st, TRAPS);
 230 
 231   // Lookup an already loaded class. If not found NULL is returned.
 232   static klassOop find(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS);
 233 
 234   // Lookup an already loaded instance or array class.
 235   // Do not make any queries to class loaders; consult only the cache.
 236   // If not found NULL is returned.
 237   static klassOop find_instance_or_array_klass(symbolHandle class_name,
 238                                                Handle class_loader,
 239                                                Handle protection_domain,
 240                                                TRAPS);
 241 
 242   // If the given name is known to vmSymbols, return the well-know klass:
 243   static klassOop find_well_known_klass(symbolOop class_name);
 244 
 245   // Lookup an instance or array class that has already been loaded
 246   // either into the given class loader, or else into another class
 247   // loader that is constrained (via loader constraints) to produce
 248   // a consistent class.  Do not take protection domains into account.
 249   // Do not make any queries to class loaders; consult only the cache.
 250   // Return NULL if the class is not found.
 251   //
 252   // This function is a strict superset of find_instance_or_array_klass.
 253   // This function (the unchecked version) makes a conservative prediction
 254   // of the result of the checked version, assuming successful lookup.
 255   // If both functions return non-null, they must return the same value.
 256   // Also, the unchecked version may sometimes be non-null where the
 257   // checked version is null.  This can occur in several ways:
 258   //   1. No query has yet been made to the class loader.
 259   //   2. The class loader was queried, but chose not to delegate.
 260   //   3. ClassLoader.checkPackageAccess rejected a proposed protection domain.
 261   //   4. Loading was attempted, but there was a linkage error of some sort.
 262   // In all of these cases, the loader constraints on this type are
 263   // satisfied, and it is safe for classes in the given class loader
 264   // to manipulate strongly-typed values of the found class, subject


 337   static void verify();
 338 
 339 #ifdef ASSERT
 340   static bool is_internal_format(symbolHandle class_name);
 341 #endif
 342 
 343   // Verify class is in dictionary
 344   static void verify_obj_klass_present(Handle obj,
 345                                        symbolHandle class_name,
 346                                        Handle class_loader);
 347 
 348   // Initialization
 349   static void initialize(TRAPS);
 350 
 351   // Fast access to commonly used classes (preloaded)
 352   static klassOop check_klass(klassOop k) {
 353     assert(k != NULL, "preloaded klass not initialized");
 354     return k;
 355   }
 356 
 357   static klassOop check_klass_Pre(klassOop k) { return check_klass(k); }
 358   static klassOop check_klass_Opt(klassOop k) { return k; }
 359   static klassOop check_klass_Opt_Only_JDK15(klassOop k) {
 360     assert(JDK_Version::is_gte_jdk15x_version(), "JDK 1.5 only");
 361     return k;





































 362   }
 363   static klassOop check_klass_Opt_Only_JDK14NewRef(klassOop k) {
 364     assert(JDK_Version::is_gte_jdk14x_version() && UseNewReflection, "JDK 1.4 only");
 365     // despite the optional loading, if you use this it must be present:
 366     return check_klass(k);
 367   }
 368 
 369   static bool initialize_wk_klass(WKID id, bool must_load, TRAPS);
 370   static void initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS);
 371   static void initialize_wk_klasses_through(WKID end_id, WKID &start_id, TRAPS) {
 372     int limit = (int)end_id + 1;
 373     initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
 374   }




 375 
 376 public:
 377   #define WK_KLASS_DECLARE(name, ignore_symbol, option) \
 378     static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
 379   WK_KLASSES_DO(WK_KLASS_DECLARE);
 380   #undef WK_KLASS_DECLARE
 381 
 382   // Local definition for direct access to the private array:
 383   #define WK_KLASS(name) _well_known_klasses[WK_KLASS_ENUM_NAME(name)]
 384 














 385   static klassOop box_klass(BasicType t) {
 386     assert((uint)t < T_VOID+1, "range check");
 387     return check_klass(_box_klasses[t]);
 388   }
 389   static BasicType box_klass_type(klassOop k);  // inverse of box_klass
 390 
 391   // methods returning lazily loaded klasses
 392   // The corresponding method to load the class must be called before calling them.
 393   static klassOop abstract_ownable_synchronizer_klass() { return check_klass(_abstract_ownable_synchronizer_klass); }
 394 
 395   static void load_abstract_ownable_synchronizer_klass(TRAPS);
 396 
 397 private:
 398   // Tells whether ClassLoader.loadClassInternal is present
 399   static bool has_loadClassInternal()       { return _has_loadClassInternal; }
 400 
 401 public:
 402   // Tells whether ClassLoader.checkPackageAccess is present
 403   static bool has_checkPackageAccess()      { return _has_checkPackageAccess; }
 404 
 405   static bool class_klass_loaded()          { return WK_KLASS(class_klass) != NULL; }
 406   static bool cloneable_klass_loaded()      { return WK_KLASS(cloneable_klass) != NULL; }
 407 
 408   // Returns default system loader
 409   static oop java_system_loader();
 410 
 411   // Compute the default system loader
 412   static void compute_java_system_loader(TRAPS);
 413 
 414 private:
 415   // Mirrors for primitive classes (created eagerly)
 416   static oop check_mirror(oop m) {
 417     assert(m != NULL, "mirror not initialized");
 418     return m;
 419   }
 420 
 421 public:
 422   // Note:  java_lang_Class::primitive_type is the inverse of java_mirror
 423 
 424   // Check class loader constraints
 425   static bool add_loader_constraint(symbolHandle name, Handle loader1,
 426                                     Handle loader2, TRAPS);


 548 
 549   // Performs cleanups after resolve_super_or_fail. This typically needs
 550   // to be called on failure.
 551   // Won't throw, but can block.
 552   static void resolution_cleanups(symbolHandle class_name,
 553                                   Handle class_loader,
 554                                   TRAPS);
 555 
 556   // Initialization
 557   static void initialize_preloaded_classes(TRAPS);
 558 
 559   // Class loader constraints
 560   static void check_constraints(int index, unsigned int hash,
 561                                 instanceKlassHandle k, Handle loader,
 562                                 bool defining, TRAPS);
 563   static void update_dictionary(int d_index, unsigned int d_hash,
 564                                 int p_index, unsigned int p_hash,
 565                                 instanceKlassHandle k, Handle loader, TRAPS);
 566 
 567   // Variables holding commonly used klasses (preloaded)
 568   static klassOop _well_known_klasses[];






 569 




















































 570   // Lazily loaded klasses
 571   static volatile klassOop _abstract_ownable_synchronizer_klass;
 572 
 573   // table of box klasses (int_klass, etc.)










 574   static klassOop _box_klasses[T_VOID+1];
 575 
 576   static oop  _java_system_loader;
 577 
 578   static bool _has_loadClassInternal;
 579   static bool _has_checkPackageAccess;
 580 };