< prev index next >

src/share/vm/classfile/systemDictionary.hpp

Print this page




  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  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_CLASSFILE_SYSTEMDICTIONARY_HPP
  26 #define SHARE_VM_CLASSFILE_SYSTEMDICTIONARY_HPP
  27 
  28 #include "classfile/classFileStream.hpp"
  29 #include "classfile/classLoader.hpp"
  30 #include "oops/objArrayOop.hpp"
  31 #include "oops/symbol.hpp"
  32 #include "runtime/java.hpp"
  33 #include "runtime/reflectionUtils.hpp"
  34 #include "utilities/hashtable.hpp"
  35 #include "utilities/hashtable.inline.hpp"

  36 
  37 
  38 // The system dictionary stores all loaded classes and maps:
  39 //
  40 //   [class name,class loader] -> class   i.e.  [Symbol*,oop] -> Klass*
  41 //
  42 // Classes are loaded lazily. The default VM class loader is
  43 // represented as NULL.
  44 
  45 // The underlying data structure is an open hash table with a fixed number
  46 // of buckets. During loading the loader object is locked, (for the VM loader
  47 // a private lock object is used). Class loading can thus be done concurrently,
  48 // but only by different loaders.
  49 //
  50 // During loading a placeholder (name, loader) is temporarily placed in
  51 // a side data structure, and is used to detect ClassCircularityErrors
  52 // and to perform verification during GC.  A GC can occur in the midst
  53 // of class loading, as we call out to Java, have to take locks, etc.
  54 //
  55 // When class loading is finished, a new entry is added to the system


 175   do_klass(URLClassLoader_klass,                        java_net_URLClassLoader,                   Pre                 ) \
 176   do_klass(URL_klass,                                   java_net_URL,                              Pre                 ) \
 177   do_klass(Jar_Manifest_klass,                          java_util_jar_Manifest,                    Pre                 ) \
 178   do_klass(sun_misc_Launcher_klass,                     sun_misc_Launcher,                         Pre                 ) \
 179   do_klass(CodeSource_klass,                            java_security_CodeSource,                  Pre                 ) \
 180                                                                                                                          \
 181   /* It's NULL in non-1.4 JDKs. */                                                                                       \
 182   do_klass(StackTraceElement_klass,                     java_lang_StackTraceElement,               Opt                 ) \
 183   /* It's okay if this turns out to be NULL in non-1.4 JDKs. */                                                          \
 184   do_klass(nio_Buffer_klass,                            java_nio_Buffer,                           Opt                 ) \
 185                                                                                                                          \
 186   /* Preload boxing klasses */                                                                                           \
 187   do_klass(Boolean_klass,                               java_lang_Boolean,                         Pre                 ) \
 188   do_klass(Character_klass,                             java_lang_Character,                       Pre                 ) \
 189   do_klass(Float_klass,                                 java_lang_Float,                           Pre                 ) \
 190   do_klass(Double_klass,                                java_lang_Double,                          Pre                 ) \
 191   do_klass(Byte_klass,                                  java_lang_Byte,                            Pre                 ) \
 192   do_klass(Short_klass,                                 java_lang_Short,                           Pre                 ) \
 193   do_klass(Integer_klass,                               java_lang_Integer,                         Pre                 ) \
 194   do_klass(Long_klass,                                  java_lang_Long,                            Pre                 ) \




 195   /*end*/
 196 
 197 
 198 class SystemDictionary : AllStatic {
 199   friend class VMStructs;
 200   friend class SystemDictionaryHandles;
 201 
 202  public:
 203   enum WKID {
 204     NO_WKID = 0,
 205 
 206     #define WK_KLASS_ENUM(name, symbol, ignore_o) WK_KLASS_ENUM_NAME(name), WK_KLASS_ENUM_NAME(symbol) = WK_KLASS_ENUM_NAME(name),
 207     WK_KLASSES_DO(WK_KLASS_ENUM)
 208     #undef WK_KLASS_ENUM
 209 
 210     WKID_LIMIT,
 211 





 212     FIRST_WKID = NO_WKID + 1
 213   };
 214 
 215   enum InitOption {
 216     Pre,                        // preloaded; error if not present
 217 
 218     // Order is significant.  Options before this point require resolve_or_fail.
 219     // Options after this point will use resolve_or_null instead.
 220 
 221     Opt,                        // preload tried; NULL if not present



 222     OPTION_LIMIT,
 223     CEIL_LG_OPTION_LIMIT = 2    // OPTION_LIMIT <= (1<<CEIL_LG_OPTION_LIMIT)
 224   };
 225 
 226 
 227   // Returns a class with a given class name and class loader.  Loads the
 228   // class if needed. If not found a NoClassDefFoundError or a
 229   // ClassNotFoundException is thrown, depending on the value on the
 230   // throw_error flag.  For most uses the throw_error argument should be set
 231   // to true.
 232 
 233   static Klass* resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS);
 234   // Convenient call for null loader and protection domain.
 235   static Klass* resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS);
 236 protected:
 237   // handle error translation for resolve_or_null results
 238   static Klass* handle_resolution_exception(Symbol* class_name, bool throw_error, KlassHandle klass_h, TRAPS);
 239 
 240 public:
 241 


 381 
 382   // Verification
 383   static void verify();
 384 
 385 #ifdef ASSERT
 386   static bool is_internal_format(Symbol* class_name);
 387 #endif
 388 
 389   // Initialization
 390   static void initialize(TRAPS);
 391 
 392   // Fast access to commonly used classes (preloaded)
 393   static Klass* check_klass(Klass* k) {
 394     assert(k != NULL, "preloaded klass not initialized");
 395     return k;
 396   }
 397 
 398   static Klass* check_klass_Pre(       Klass* k) { return check_klass(k); }
 399   static Klass* check_klass_Opt(       Klass* k) { return k; }
 400 


 401   static bool initialize_wk_klass(WKID id, int init_opt, TRAPS);
 402   static void initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS);
 403   static void initialize_wk_klasses_through(WKID end_id, WKID &start_id, TRAPS) {
 404     int limit = (int)end_id + 1;
 405     initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
 406   }
 407 
 408 public:
 409   #define WK_KLASS_DECLARE(name, symbol, option) \
 410     static Klass* name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } \
 411     static Klass** name##_addr() {                                                                       \
 412       return &SystemDictionary::_well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)];           \
 413     }
 414   WK_KLASSES_DO(WK_KLASS_DECLARE);
 415   #undef WK_KLASS_DECLARE
 416 
 417   static Klass* well_known_klass(WKID id) {
 418     assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
 419     return _well_known_klasses[id];
 420   }




  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  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_CLASSFILE_SYSTEMDICTIONARY_HPP
  26 #define SHARE_VM_CLASSFILE_SYSTEMDICTIONARY_HPP
  27 
  28 #include "classfile/classFileStream.hpp"
  29 #include "classfile/classLoader.hpp"
  30 #include "oops/objArrayOop.hpp"
  31 #include "oops/symbol.hpp"
  32 #include "runtime/java.hpp"
  33 #include "runtime/reflectionUtils.hpp"
  34 #include "utilities/hashtable.hpp"
  35 #include "utilities/hashtable.inline.hpp"
  36 #include "jvmci/systemDictionary_jvmci.hpp"
  37 
  38 
  39 // The system dictionary stores all loaded classes and maps:
  40 //
  41 //   [class name,class loader] -> class   i.e.  [Symbol*,oop] -> Klass*
  42 //
  43 // Classes are loaded lazily. The default VM class loader is
  44 // represented as NULL.
  45 
  46 // The underlying data structure is an open hash table with a fixed number
  47 // of buckets. During loading the loader object is locked, (for the VM loader
  48 // a private lock object is used). Class loading can thus be done concurrently,
  49 // but only by different loaders.
  50 //
  51 // During loading a placeholder (name, loader) is temporarily placed in
  52 // a side data structure, and is used to detect ClassCircularityErrors
  53 // and to perform verification during GC.  A GC can occur in the midst
  54 // of class loading, as we call out to Java, have to take locks, etc.
  55 //
  56 // When class loading is finished, a new entry is added to the system


 176   do_klass(URLClassLoader_klass,                        java_net_URLClassLoader,                   Pre                 ) \
 177   do_klass(URL_klass,                                   java_net_URL,                              Pre                 ) \
 178   do_klass(Jar_Manifest_klass,                          java_util_jar_Manifest,                    Pre                 ) \
 179   do_klass(sun_misc_Launcher_klass,                     sun_misc_Launcher,                         Pre                 ) \
 180   do_klass(CodeSource_klass,                            java_security_CodeSource,                  Pre                 ) \
 181                                                                                                                          \
 182   /* It's NULL in non-1.4 JDKs. */                                                                                       \
 183   do_klass(StackTraceElement_klass,                     java_lang_StackTraceElement,               Opt                 ) \
 184   /* It's okay if this turns out to be NULL in non-1.4 JDKs. */                                                          \
 185   do_klass(nio_Buffer_klass,                            java_nio_Buffer,                           Opt                 ) \
 186                                                                                                                          \
 187   /* Preload boxing klasses */                                                                                           \
 188   do_klass(Boolean_klass,                               java_lang_Boolean,                         Pre                 ) \
 189   do_klass(Character_klass,                             java_lang_Character,                       Pre                 ) \
 190   do_klass(Float_klass,                                 java_lang_Float,                           Pre                 ) \
 191   do_klass(Double_klass,                                java_lang_Double,                          Pre                 ) \
 192   do_klass(Byte_klass,                                  java_lang_Byte,                            Pre                 ) \
 193   do_klass(Short_klass,                                 java_lang_Short,                           Pre                 ) \
 194   do_klass(Integer_klass,                               java_lang_Integer,                         Pre                 ) \
 195   do_klass(Long_klass,                                  java_lang_Long,                            Pre                 ) \
 196                                                                                                                          \
 197   /* JVMCI classes. These are loaded on-demand. */                                                                       \
 198   JVMCI_WK_KLASSES_DO(do_klass) \
 199 
 200   /*end*/
 201 
 202 
 203 class SystemDictionary : AllStatic {
 204   friend class VMStructs;
 205   friend class SystemDictionaryHandles;
 206 
 207  public:
 208   enum WKID {
 209     NO_WKID = 0,
 210 
 211     #define WK_KLASS_ENUM(name, symbol, ignore_o) WK_KLASS_ENUM_NAME(name), WK_KLASS_ENUM_NAME(symbol) = WK_KLASS_ENUM_NAME(name),
 212     WK_KLASSES_DO(WK_KLASS_ENUM)
 213     #undef WK_KLASS_ENUM
 214 
 215     WKID_LIMIT,
 216 
 217 #if INCLUDE_JVMCI
 218     FIRST_JVMCI_WKID = WK_KLASS_ENUM_NAME(HotSpotCompiledCode_klass),
 219     LAST_JVMCI_WKID  = WK_KLASS_ENUM_NAME(Value_klass),
 220 #endif
 221 
 222     FIRST_WKID = NO_WKID + 1
 223   };
 224 
 225   enum InitOption {
 226     Pre,                        // preloaded; error if not present
 227 
 228     // Order is significant.  Options before this point require resolve_or_fail.
 229     // Options after this point will use resolve_or_null instead.
 230 
 231     Opt,                        // preload tried; NULL if not present
 232 #if INCLUDE_JVMCI
 233     Jvmci,                      // preload tried; error if not present, use only with JVMCI
 234 #endif
 235     OPTION_LIMIT,
 236     CEIL_LG_OPTION_LIMIT = 2    // OPTION_LIMIT <= (1<<CEIL_LG_OPTION_LIMIT)
 237   };
 238 
 239 
 240   // Returns a class with a given class name and class loader.  Loads the
 241   // class if needed. If not found a NoClassDefFoundError or a
 242   // ClassNotFoundException is thrown, depending on the value on the
 243   // throw_error flag.  For most uses the throw_error argument should be set
 244   // to true.
 245 
 246   static Klass* resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS);
 247   // Convenient call for null loader and protection domain.
 248   static Klass* resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS);
 249 protected:
 250   // handle error translation for resolve_or_null results
 251   static Klass* handle_resolution_exception(Symbol* class_name, bool throw_error, KlassHandle klass_h, TRAPS);
 252 
 253 public:
 254 


 394 
 395   // Verification
 396   static void verify();
 397 
 398 #ifdef ASSERT
 399   static bool is_internal_format(Symbol* class_name);
 400 #endif
 401 
 402   // Initialization
 403   static void initialize(TRAPS);
 404 
 405   // Fast access to commonly used classes (preloaded)
 406   static Klass* check_klass(Klass* k) {
 407     assert(k != NULL, "preloaded klass not initialized");
 408     return k;
 409   }
 410 
 411   static Klass* check_klass_Pre(       Klass* k) { return check_klass(k); }
 412   static Klass* check_klass_Opt(       Klass* k) { return k; }
 413 
 414   JVMCI_ONLY(static Klass* check_klass_Jvmci(Klass* k) { return k; })
 415 
 416   static bool initialize_wk_klass(WKID id, int init_opt, TRAPS);
 417   static void initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS);
 418   static void initialize_wk_klasses_through(WKID end_id, WKID &start_id, TRAPS) {
 419     int limit = (int)end_id + 1;
 420     initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
 421   }
 422 
 423 public:
 424   #define WK_KLASS_DECLARE(name, symbol, option) \
 425     static Klass* name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } \
 426     static Klass** name##_addr() {                                                                       \
 427       return &SystemDictionary::_well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)];           \
 428     }
 429   WK_KLASSES_DO(WK_KLASS_DECLARE);
 430   #undef WK_KLASS_DECLARE
 431 
 432   static Klass* well_known_klass(WKID id) {
 433     assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
 434     return _well_known_klasses[id];
 435   }


< prev index next >