< prev index next >

src/hotspot/share/classfile/systemDictionaryShared.hpp

Print this page


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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_SYSTEMDICTIONARYSHARED_HPP
  26 #define SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
  27 
  28 #include "classfile/systemDictionary.hpp"
  29 #include "classfile/dictionary.hpp"














































































  30 
  31 class ClassFileStream;
  32 

















































































  33 class SystemDictionaryShared: public SystemDictionary {






























































































  34 public:
  35   static void initialize(TRAPS) {}


  36   static InstanceKlass* find_or_load_shared_class(Symbol* class_name,
  37                                                   Handle class_loader,
  38                                                   TRAPS) {
  39     return NULL;





  40   }
  41   static void roots_oops_do(OopClosure* blk) {}
  42   static void oops_do(OopClosure* f) {}
  43   static bool is_sharing_possible(ClassLoaderData* loader_data) {
  44     oop class_loader = loader_data->class_loader();
  45     return (class_loader == NULL);



  46   }
  47   static bool is_shared_class_visible_for_classloader(
  48                                       InstanceKlass* ik,
  49                                       Handle class_loader,
  50                                       const char* pkg_string,
  51                                       Symbol* pkg_name,
  52                                       PackageEntry* pkg_entry,
  53                                       ModuleEntry* mod_entry,
  54                                       TRAPS) {
  55     return false;






  56   }
  57 


  58   static Klass* dump_time_resolve_super_or_fail(Symbol* child_name,
  59                                                 Symbol* class_name,
  60                                                 Handle class_loader,
  61                                                 Handle protection_domain,
  62                                                 bool is_superclass,
  63                                                 TRAPS) {
  64     return NULL;
  65   }
  66 
  67   static size_t dictionary_entry_size() {
  68     return sizeof(DictionaryEntry);







  69   }
  70 
  71   static void init_shared_dictionary_entry(Klass* k, DictionaryEntry* entry) {}
  72   static bool is_builtin(DictionaryEntry* entry) { return true; }



  73 
  74   static InstanceKlass* lookup_from_stream(Symbol* class_name,












  75                                            Handle class_loader,
  76                                            Handle protection_domain,
  77                                            const ClassFileStream* st,
  78                                            TRAPS) {
  79     return NULL;
  80   }
  81 
  82   // The (non-application) CDS implementation supports only classes in the boot
  83   // class loader, which ensures that the verification constraints are the same
  84   // during archive creation time and runtime. Thus we can do the constraint checks
  85   // entirely during archive creation time.


  86   static bool add_verification_constraint(Klass* k, Symbol* name,
  87                   Symbol* from_name, bool from_field_is_protected,
  88                   bool from_is_array, bool from_is_object) {return false;}
  89   static void finalize_verification_constraints() {}
  90   static void check_verification_constraints(InstanceKlass* klass,
  91                                               TRAPS) {}
  92 };
  93 
  94 class SharedDictionaryEntry : public DictionaryEntry {
  95 public:
  96   void metaspace_pointers_do(MetaspaceClosure* it) {}
  97 };
  98 
  99 #endif // SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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_SYSTEMDICTIONARYSHARED_HPP
  26 #define SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
  27 
  28 #include "oops/klass.hpp"
  29 #include "classfile/dictionary.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "memory/filemap.hpp"
  32 
  33 
  34 /*===============================================================================
  35 
  36     Handling of the classes in the AppCDS archive
  37 
  38     To ensure safety and to simplify the implementation, archived classes are
  39     "segregated" into several types. The following rules describe how they
  40     are stored and looked up.
  41 
  42 [1] Category of archived classes
  43 
  44     There are 3 disjoint groups of classes stored in the AppCDS archive. They are
  45     categorized as by their SharedDictionaryEntry::loader_type()
  46 
  47     BUILTIN:              These classes may be defined ONLY by the BOOT/PLATFORM/APP
  48                           loaders.
  49 
  50     UNREGISTERED:         These classes may be defined ONLY by a ClassLoader
  51                           instance that's not listed above (using fingerprint matching)
  52 
  53 [2] How classes from different categories are specified in the classlist:
  54 
  55     Starting from JDK9, each class in the classlist may be specified with
  56     these keywords: "id", "super", "interfaces", "loader" and "source".
  57 
  58 
  59     BUILTIN               Only the "id" keyword may be (optionally) specified. All other
  60                           keywords are forbidden.
  61 
  62                           The named class is looked up from the jimage and from
  63                           Xbootclasspath/a and CLASSPATH.
  64 
  65     UNREGISTERED:         The "id", "super", and "source" keywords must all be
  66                           specified.
  67 
  68                           The "interfaces" keyword must be specified if the class implements
  69                           one or more local interfaces. The "interfaces" keyword must not be
  70                           specified if the class does not implement local interfaces.
  71 
  72                           The named class is looked up from the location specified in the
  73                           "source" keyword.
  74 
  75     Example classlist:
  76 
  77     # BUILTIN
  78     java/lang/Object id: 0
  79     java/lang/Cloneable id: 1
  80     java/lang/String
  81 
  82     # UNREGISTERED
  83     Bar id: 3 super: 0 interfaces: 1 source: /foo.jar
  84 
  85 
  86 [3] Identifying the loader_type of archived classes in the shared dictionary
  87 
  88     Each archived Klass* C is associated with a SharedDictionaryEntry* E
  89 
  90     BUILTIN:              (C->shared_classpath_index() >= 0)
  91     UNREGISTERED:         (C->shared_classpath_index() <  0)
  92 
  93 [4] Lookup of archived classes at run time:
  94 
  95     (a) BUILTIN loaders:
  96 
  97         Search the shared directory for a BUILTIN class with a matching name.
  98 
  99     (b) UNREGISTERED loaders:
 100 
 101         The search originates with SystemDictionaryShared::lookup_from_stream().
 102 
 103         Search the shared directory for a UNREGISTERED class with a matching
 104         (name, clsfile_len, clsfile_crc32) tuple.
 105 
 106 ===============================================================================*/
 107 #define UNREGISTERED_INDEX -9999
 108 
 109 class ClassFileStream;
 110 
 111 // Archived classes need extra information not needed by traditionally loaded classes.
 112 // To keep footprint small, we add these in the dictionary entry instead of the InstanceKlass.
 113 class SharedDictionaryEntry : public DictionaryEntry {
 114 
 115 public:
 116   enum LoaderType {
 117     LT_BUILTIN,
 118     LT_UNREGISTERED
 119   };
 120 
 121   enum {
 122     FROM_FIELD_IS_PROTECTED = 1 << 0,
 123     FROM_IS_ARRAY           = 1 << 1,
 124     FROM_IS_OBJECT          = 1 << 2
 125   };
 126 
 127   int             _id;
 128   int             _clsfile_size;
 129   int             _clsfile_crc32;
 130   void*           _verifier_constraints; // FIXME - use a union here to avoid type casting??
 131   void*           _verifier_constraint_flags;
 132 
 133   // See "Identifying the loader_type of archived classes" comments above.
 134   LoaderType loader_type() const {
 135     Klass* k = (Klass*)literal();
 136 
 137     if ((k->shared_classpath_index() != UNREGISTERED_INDEX)) {
 138       return LT_BUILTIN;
 139     } else {
 140       return LT_UNREGISTERED;
 141     }
 142   }
 143 
 144   SharedDictionaryEntry* next() {
 145     return (SharedDictionaryEntry*)(DictionaryEntry::next());
 146   }
 147 
 148   bool is_builtin() const {
 149     return loader_type() == LT_BUILTIN;
 150   }
 151   bool is_unregistered() const {
 152     return loader_type() == LT_UNREGISTERED;
 153   }
 154 
 155   void add_verification_constraint(Symbol* name,
 156          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object);
 157   int finalize_verification_constraints();
 158   void check_verification_constraints(InstanceKlass* klass, TRAPS);
 159   void metaspace_pointers_do(MetaspaceClosure* it) NOT_CDS_RETURN;
 160 };
 161 
 162 class SharedDictionary : public Dictionary {
 163   SharedDictionaryEntry* get_entry_for_builtin_loader(const Symbol* name) const;
 164   SharedDictionaryEntry* get_entry_for_unregistered_loader(const Symbol* name,
 165                                                            int clsfile_size,
 166                                                            int clsfile_crc32) const;
 167 
 168   // Convenience functions
 169   SharedDictionaryEntry* bucket(int index) const {
 170     return (SharedDictionaryEntry*)(Dictionary::bucket(index));
 171   }
 172 
 173 public:
 174   SharedDictionaryEntry* find_entry_for(Klass* klass);
 175   void finalize_verification_constraints();
 176 
 177   bool add_non_builtin_klass(const Symbol* class_name,
 178                              ClassLoaderData* loader_data,
 179                              InstanceKlass* obj);
 180 
 181   void update_entry(Klass* klass, int id);
 182 
 183   Klass* find_class_for_builtin_loader(const Symbol* name) const;
 184   Klass* find_class_for_unregistered_loader(const Symbol* name,
 185                                             int clsfile_size,
 186                                             int clsfile_crc32) const;
 187   bool class_exists_for_unregistered_loader(const Symbol* name) {
 188     return (get_entry_for_unregistered_loader(name, -1, -1) != NULL);
 189   }
 190 };
 191 
 192 class SystemDictionaryShared: public SystemDictionary {
 193 private:
 194   // These _shared_xxxs arrays are used to initialize the java.lang.Package and
 195   // java.security.ProtectionDomain objects associated with each shared class.
 196   //
 197   // See SystemDictionaryShared::init_security_info for more info.
 198   static objArrayOop _shared_protection_domains;
 199   static objArrayOop _shared_jar_urls;
 200   static objArrayOop _shared_jar_manifests;
 201 
 202   static InstanceKlass* load_shared_class_for_builtin_loader(
 203                                                Symbol* class_name,
 204                                                Handle class_loader,
 205                                                TRAPS);
 206   static Handle get_package_name(Symbol*  class_name, TRAPS);
 207 
 208 
 209   // Package handling:
 210   //
 211   // 1. For named modules in the runtime image
 212   //    BOOT classes: Reuses the existing JVM_GetSystemPackage(s) interfaces
 213   //                  to get packages in named modules for shared classes.
 214   //                  Package for non-shared classes in named module is also
 215   //                  handled using JVM_GetSystemPackage(s).
 216   //
 217   //    APP  classes: VM calls ClassLoaders.AppClassLoader::definePackage(String, Module)
 218   //                  to define package for shared app classes from named
 219   //                  modules.
 220   //
 221   //    PLATFORM  classes: VM calls ClassLoaders.PlatformClassLoader::definePackage(String, Module)
 222   //                  to define package for shared platform classes from named
 223   //                  modules.
 224   //
 225   // 2. For unnamed modules
 226   //    BOOT classes: Reuses the existing JVM_GetSystemPackage(s) interfaces to
 227   //                  get packages for shared boot classes in unnamed modules.
 228   //
 229   //    APP  classes: VM calls ClassLoaders.AppClassLoader::defineOrCheckPackage()
 230   //                  with with the manifest and url from archived data.
 231   //
 232   //    PLATFORM  classes: No package is defined.
 233   //
 234   // The following two define_shared_package() functions are used to define
 235   // package for shared APP and PLATFORM classes.
 236   static void define_shared_package(Symbol*  class_name,
 237                                     Handle class_loader,
 238                                     Handle manifest,
 239                                     Handle url,
 240                                     TRAPS);
 241   static void define_shared_package(Symbol* class_name,
 242                                     Handle class_loader,
 243                                     ModuleEntry* mod_entry,
 244                                     TRAPS);
 245 
 246   static Handle get_shared_jar_manifest(int shared_path_index, TRAPS);
 247   static Handle get_shared_jar_url(int shared_path_index, TRAPS);
 248   static Handle get_protection_domain_from_classloader(Handle class_loader,
 249                                                        Handle url, TRAPS);
 250   static Handle get_shared_protection_domain(Handle class_loader,
 251                                              int shared_path_index,
 252                                              Handle url,
 253                                              TRAPS);
 254   static Handle get_shared_protection_domain(Handle class_loader,
 255                                              ModuleEntry* mod, TRAPS);
 256   static Handle init_security_info(Handle class_loader, InstanceKlass* ik, TRAPS);
 257 
 258   static void atomic_set_array_index(objArrayOop array, int index, oop o) {
 259     // Benign race condition:  array.obj_at(index) may already be filled in.
 260     // The important thing here is that all threads pick up the same result.
 261     // It doesn't matter which racing thread wins, as long as only one
 262     // result is used by all threads, and all future queries.
 263     array->atomic_compare_exchange_oop(index, o, NULL);
 264   }
 265 
 266   static oop shared_protection_domain(int index);
 267   static void atomic_set_shared_protection_domain(int index, oop pd) {
 268     atomic_set_array_index(_shared_protection_domains, index, pd);
 269   }
 270   static void allocate_shared_protection_domain_array(int size, TRAPS);
 271   static oop shared_jar_url(int index);
 272   static void atomic_set_shared_jar_url(int index, oop url) {
 273     atomic_set_array_index(_shared_jar_urls, index, url);
 274   }
 275   static void allocate_shared_jar_url_array(int size, TRAPS);
 276   static oop shared_jar_manifest(int index);
 277   static void atomic_set_shared_jar_manifest(int index, oop man) {
 278     atomic_set_array_index(_shared_jar_manifests, index, man);
 279   }
 280   static void allocate_shared_jar_manifest_array(int size, TRAPS);
 281   static InstanceKlass* acquire_class_for_current_thread(
 282                                  InstanceKlass *ik,
 283                                  Handle class_loader,
 284                                  Handle protection_domain,
 285                                  TRAPS);
 286 
 287 public:
 288   static void initialize(TRAPS);
 289 
 290   // Called by PLATFORM/APP loader only
 291   static InstanceKlass* find_or_load_shared_class(Symbol* class_name,
 292                                                Handle class_loader,
 293                                                TRAPS);
 294 
 295 
 296   static void allocate_shared_data_arrays(int size, TRAPS);
 297   static void oops_do(OopClosure* f);
 298   static void roots_oops_do(OopClosure* f) {
 299     oops_do(f);
 300   }
 301 
 302   // Check if sharing is supported for the class loader.
 303   static bool is_sharing_possible(ClassLoaderData* loader_data) {
 304     oop class_loader = loader_data->class_loader();
 305     return (class_loader == NULL ||
 306             (UseAppCDS && (SystemDictionary::is_system_class_loader(class_loader) ||
 307                            SystemDictionary::is_platform_class_loader(class_loader)))
 308             );
 309   }
 310   static bool is_shared_class_visible_for_classloader(InstanceKlass* ik,

 311                                                       Handle class_loader,
 312                                                       const char* pkg_string,
 313                                                       Symbol* pkg_name,
 314                                                       PackageEntry* pkg_entry,
 315                                                       ModuleEntry* mod_entry,
 316                                                       TRAPS);
 317   static PackageEntry* get_package_entry(Symbol* pkg,
 318                                          ClassLoaderData *loader_data) {
 319     if (loader_data != NULL) {
 320       PackageEntryTable* pkgEntryTable = loader_data->packages();
 321       return pkgEntryTable->lookup_only(pkg);
 322     }
 323     return NULL;
 324   }
 325 
 326   static bool add_non_builtin_klass(Symbol* class_name, ClassLoaderData* loader_data,
 327                                     InstanceKlass* k, TRAPS);
 328   static Klass* dump_time_resolve_super_or_fail(Symbol* child_name,
 329                                                 Symbol* class_name,
 330                                                 Handle class_loader,
 331                                                 Handle protection_domain,
 332                                                 bool is_superclass,
 333                                                 TRAPS);


 334 
 335   static size_t dictionary_entry_size() {
 336     return (DumpSharedSpaces) ? sizeof(SharedDictionaryEntry) : sizeof(DictionaryEntry);
 337   }
 338   static void init_shared_dictionary_entry(Klass* k, DictionaryEntry* entry) NOT_CDS_RETURN;
 339   static bool is_builtin(DictionaryEntry* ent) {
 340     // Can't use virtual function is_builtin because DictionaryEntry doesn't initialize
 341     // vtable because it's not constructed properly.
 342     SharedDictionaryEntry* entry = (SharedDictionaryEntry*)ent;
 343     return entry->is_builtin();
 344   }
 345 
 346   // For convenient access to the SharedDictionaryEntry's of the archived classes.
 347   static SharedDictionary* shared_dictionary() {
 348     assert(!DumpSharedSpaces, "not for dumping");
 349     return (SharedDictionary*)SystemDictionary::shared_dictionary();
 350   }
 351 
 352   static SharedDictionary* boot_loader_dictionary() {
 353     return (SharedDictionary*)ClassLoaderData::the_null_class_loader_data()->dictionary();
 354   }
 355 
 356   static void update_shared_entry(Klass* klass, int id) {
 357     assert(DumpSharedSpaces, "sanity");
 358     assert((SharedDictionary*)(klass->class_loader_data()->dictionary()) != NULL, "sanity");
 359     ((SharedDictionary*)(klass->class_loader_data()->dictionary()))->update_entry(klass, id);
 360   }
 361 
 362   static void set_shared_class_misc_info(Klass* k, ClassFileStream* cfs);
 363 
 364   static InstanceKlass* lookup_from_stream(const Symbol* class_name,
 365                                            Handle class_loader,
 366                                            Handle protection_domain,
 367                                            const ClassFileStream* st,
 368                                            TRAPS);
 369   // "verification_constraints" are a set of checks performed by
 370   // VerificationType::is_reference_assignable_from when verifying a shared class during
 371   // dump time.
 372   //
 373   // With AppCDS, it is possible to override archived classes by calling
 374   // ClassLoader.defineClass() directly. SystemDictionary::load_shared_class() already
 375   // ensures that you cannot load a shared class if its super type(s) are changed. However,
 376   // we need an additional check to ensure that the verification_constraints did not change
 377   // between dump time and runtime.
 378   static bool add_verification_constraint(Klass* k, Symbol* name,
 379                   Symbol* from_name, bool from_field_is_protected,
 380                   bool from_is_array, bool from_is_object) NOT_CDS_RETURN_(false);
 381   static void finalize_verification_constraints() NOT_CDS_RETURN;
 382   static void check_verification_constraints(InstanceKlass* klass,
 383                                               TRAPS) NOT_CDS_RETURN;





 384 };
 385 
 386 #endif // SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
< prev index next >