< prev index next >

src/hotspot/share/classfile/classLoader.hpp

Print this page




   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_CLASSFILE_CLASSLOADER_HPP
  26 #define SHARE_CLASSFILE_CLASSLOADER_HPP
  27 
  28 #include "jimage.hpp"

  29 #include "runtime/handles.hpp"
  30 #include "runtime/perfData.hpp"
  31 #include "utilities/exceptions.hpp"
  32 #include "utilities/macros.hpp"
  33 
  34 // The VM class loader.
  35 #include <sys/stat.h>
  36 
  37 // Name of boot "modules" image





  38 #define  MODULES_IMAGE_NAME "modules"
  39 
  40 // Class path entry (directory or zip file)
  41 
  42 class JImageFile;
  43 class ClassFileStream;
  44 class PackageEntry;
  45 template <typename T> class GrowableArray;
  46 
  47 class ClassPathEntry : public CHeapObj<mtClass> {
  48 private:
  49   ClassPathEntry* volatile _next;
  50 public:
  51   ClassPathEntry* next() const;
  52   virtual ~ClassPathEntry() {}
  53   void set_next(ClassPathEntry* next);
  54   virtual bool is_modules_image() const = 0;
  55   virtual bool is_jar_file() const = 0;
  56   virtual const char* name() const = 0;
  57   virtual JImageFile* jimage() const = 0;


 200   // to load a class.
 201 
 202   // 1. Contains the module/path pairs specified to --patch-module
 203   static GrowableArray<ModuleClassPathList*>* _patch_mod_entries;
 204 
 205   // 2. the base piece
 206   //    Contains the ClassPathEntry of the modular java runtime image.
 207   //    If no java runtime image is present, this indicates a
 208   //    build with exploded modules is being used instead.
 209   static ClassPathEntry* _jrt_entry;
 210   static GrowableArray<ModuleClassPathList*>* _exploded_entries;
 211   enum { EXPLODED_ENTRY_SIZE = 80 }; // Initial number of exploded modules
 212 
 213   // 3. the boot loader's append path
 214   //    [-Xbootclasspath/a]; [jvmti appended entries]
 215   //    Note: boot loader append path does not support named modules.
 216   static ClassPathEntry* _first_append_entry;
 217   // Last entry in linked list of appended ClassPathEntry instances
 218   static ClassPathEntry* _last_append_entry;
 219 



 220   // Info used by CDS
 221   CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;)
 222 
 223   CDS_ONLY(static ClassPathEntry* _app_classpath_entries;)
 224   CDS_ONLY(static ClassPathEntry* _last_app_classpath_entry;)
 225   CDS_ONLY(static ClassPathEntry* _module_path_entries;)
 226   CDS_ONLY(static ClassPathEntry* _last_module_path_entry;)
 227   CDS_ONLY(static void setup_app_search_path(const char* class_path);)
 228   CDS_ONLY(static void setup_module_search_path(const char* path, TRAPS);)
 229   static void add_to_app_classpath_entries(const char* path,
 230                                            ClassPathEntry* entry,
 231                                            bool check_for_duplicates);
 232   CDS_ONLY(static void add_to_module_path_entries(const char* path,
 233                                            ClassPathEntry* entry);)
 234  public:
 235   CDS_ONLY(static ClassPathEntry* app_classpath_entries() {return _app_classpath_entries;})
 236   CDS_ONLY(static ClassPathEntry* module_path_entries() {return _module_path_entries;})
 237 
 238  protected:
 239   // Initialization:
 240   //   - setup the boot loader's system class path
 241   //   - setup the boot loader's patch mod entries, if present
 242   //   - create the ModuleEntry for java.base
 243   static void setup_bootstrap_search_path();
 244   static void setup_boot_search_path(const char *class_path);
 245   static void setup_patch_mod_entries();
 246   static void create_javabase();
 247 
 248   static void load_zip_library();
 249   static void load_jimage_library();
 250 



 251  public:
 252   static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st,
 253                                                  bool throw_exception,
 254                                                  bool is_boot_append, TRAPS);
 255 
 256   // If the package for the fully qualified class name is in the boot
 257   // loader's package entry table then add_package() sets the classpath_index
 258   // field so that get_system_package() will know to return a non-null value
 259   // for the package's location.  And, so that the package will be added to
 260   // the list of packages returned by get_system_packages().
 261   // For packages whose classes are loaded from the boot loader class path, the
 262   // classpath_index indicates which entry on the boot loader class path.
 263   static bool add_package(const char *fullq_class_name, s2 classpath_index, TRAPS);
 264 
 265   // Canonicalizes path names, so strcmp will work properly. This is mainly
 266   // to avoid confusing the zip library
 267   static bool get_canonical_path(const char* orig, char* out, int len);
 268   static const char* file_name_for_class_name(const char* class_name,
 269                                               int class_name_len);
 270   static PackageEntry* get_package_entry(const char* class_name, ClassLoaderData* loader_data, TRAPS);


 422   static jlong class_verify_time_ms();
 423   static jlong class_link_count();
 424   static jlong class_link_time_ms();
 425 
 426   // indicates if class path already contains a entry (exact match by name)
 427   static bool contains_append_entry(const char* name);
 428 
 429   // adds a class path to the boot append entries
 430   static void add_to_boot_append_entries(ClassPathEntry* new_entry);
 431 
 432   // creates a class path zip entry (returns NULL if JAR file cannot be opened)
 433   static ClassPathZipEntry* create_class_path_zip_entry(const char *apath, bool is_boot_append);
 434 
 435   static bool string_ends_with(const char* str, const char* str_to_find);
 436 
 437   // obtain package name from a fully qualified class name
 438   // *bad_class_name is set to true if there's a problem with parsing class_name, to
 439   // distinguish from a class_name with no package name, as both cases have a NULL return value
 440   static const char* package_from_name(const char* const class_name, bool* bad_class_name = NULL);
 441 
 442   static bool is_modules_image(const char* name) { return string_ends_with(name, MODULES_IMAGE_NAME); }







 443 
 444   // Debugging
 445   static void verify()              PRODUCT_RETURN;
 446 };
 447 
 448 // PerfClassTraceTime is used to measure time for class loading related events.
 449 // This class tracks cumulative time and exclusive time for specific event types.
 450 // During the execution of one event, other event types (e.g. class loading and
 451 // resolution) as well as recursive calls of the same event type could happen.
 452 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
 453 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
 454 // instances have been created as multiple events are happening.
 455 class PerfClassTraceTime {
 456  public:
 457   enum {
 458     CLASS_LOAD   = 0,
 459     PARSE_CLASS  = 1,
 460     CLASS_LINK   = 2,
 461     CLASS_VERIFY = 3,
 462     CLASS_CLINIT = 4,




   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_CLASSFILE_CLASSLOADER_HPP
  26 #define SHARE_CLASSFILE_CLASSLOADER_HPP
  27 
  28 #include "jimage.hpp"
  29 #include "runtime/arguments.hpp"
  30 #include "runtime/handles.hpp"
  31 #include "runtime/perfData.hpp"
  32 #include "utilities/exceptions.hpp"
  33 #include "utilities/macros.hpp"
  34 
  35 // The VM class loader.
  36 #include <sys/stat.h>
  37 
  38 // Name of boot "modules" image. This macro may be used with caution.
  39 //
  40 // For most of use cases, ClassLoader::modules_image_name(), which gives the
  41 // canonical name should be used. When dealing with the system boot path string
  42 // that's set up by os::set_boot_path(), then the canonical name cannot be
  43 // used and MODULES_IMAGE_NAME should be used directly.
  44 #define  MODULES_IMAGE_NAME "modules"
  45 
  46 // Class path entry (directory or zip file)
  47 
  48 class JImageFile;
  49 class ClassFileStream;
  50 class PackageEntry;
  51 template <typename T> class GrowableArray;
  52 
  53 class ClassPathEntry : public CHeapObj<mtClass> {
  54 private:
  55   ClassPathEntry* volatile _next;
  56 public:
  57   ClassPathEntry* next() const;
  58   virtual ~ClassPathEntry() {}
  59   void set_next(ClassPathEntry* next);
  60   virtual bool is_modules_image() const = 0;
  61   virtual bool is_jar_file() const = 0;
  62   virtual const char* name() const = 0;
  63   virtual JImageFile* jimage() const = 0;


 206   // to load a class.
 207 
 208   // 1. Contains the module/path pairs specified to --patch-module
 209   static GrowableArray<ModuleClassPathList*>* _patch_mod_entries;
 210 
 211   // 2. the base piece
 212   //    Contains the ClassPathEntry of the modular java runtime image.
 213   //    If no java runtime image is present, this indicates a
 214   //    build with exploded modules is being used instead.
 215   static ClassPathEntry* _jrt_entry;
 216   static GrowableArray<ModuleClassPathList*>* _exploded_entries;
 217   enum { EXPLODED_ENTRY_SIZE = 80 }; // Initial number of exploded modules
 218 
 219   // 3. the boot loader's append path
 220   //    [-Xbootclasspath/a]; [jvmti appended entries]
 221   //    Note: boot loader append path does not support named modules.
 222   static ClassPathEntry* _first_append_entry;
 223   // Last entry in linked list of appended ClassPathEntry instances
 224   static ClassPathEntry* _last_append_entry;
 225 
 226   // The modules image name obtained from the canonical path.
 227   static const char* _modules_image_name;
 228 
 229   // Info used by CDS
 230   CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;)
 231 
 232   CDS_ONLY(static ClassPathEntry* _app_classpath_entries;)
 233   CDS_ONLY(static ClassPathEntry* _last_app_classpath_entry;)
 234   CDS_ONLY(static ClassPathEntry* _module_path_entries;)
 235   CDS_ONLY(static ClassPathEntry* _last_module_path_entry;)
 236   CDS_ONLY(static void setup_app_search_path(const char* class_path);)
 237   CDS_ONLY(static void setup_module_search_path(const char* path, TRAPS);)
 238   static void add_to_app_classpath_entries(const char* path,
 239                                            ClassPathEntry* entry,
 240                                            bool check_for_duplicates);
 241   CDS_ONLY(static void add_to_module_path_entries(const char* path,
 242                                            ClassPathEntry* entry);)
 243  public:
 244   CDS_ONLY(static ClassPathEntry* app_classpath_entries() {return _app_classpath_entries;})
 245   CDS_ONLY(static ClassPathEntry* module_path_entries() {return _module_path_entries;})
 246 
 247  protected:
 248   // Initialization:
 249   //   - setup the boot loader's system class path
 250   //   - setup the boot loader's patch mod entries, if present
 251   //   - create the ModuleEntry for java.base
 252   static void setup_bootstrap_search_path();
 253   static void setup_boot_search_path(const char *class_path);
 254   static void setup_patch_mod_entries();
 255   static void create_javabase();
 256 
 257   static void load_zip_library();
 258   static void load_jimage_library();
 259 
 260   static const char* skip_directories(const char* path);
 261   static void init_modules_image_name(const char* modules_path);
 262 
 263  public:
 264   static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st,
 265                                                  bool throw_exception,
 266                                                  bool is_boot_append, TRAPS);
 267 
 268   // If the package for the fully qualified class name is in the boot
 269   // loader's package entry table then add_package() sets the classpath_index
 270   // field so that get_system_package() will know to return a non-null value
 271   // for the package's location.  And, so that the package will be added to
 272   // the list of packages returned by get_system_packages().
 273   // For packages whose classes are loaded from the boot loader class path, the
 274   // classpath_index indicates which entry on the boot loader class path.
 275   static bool add_package(const char *fullq_class_name, s2 classpath_index, TRAPS);
 276 
 277   // Canonicalizes path names, so strcmp will work properly. This is mainly
 278   // to avoid confusing the zip library
 279   static bool get_canonical_path(const char* orig, char* out, int len);
 280   static const char* file_name_for_class_name(const char* class_name,
 281                                               int class_name_len);
 282   static PackageEntry* get_package_entry(const char* class_name, ClassLoaderData* loader_data, TRAPS);


 434   static jlong class_verify_time_ms();
 435   static jlong class_link_count();
 436   static jlong class_link_time_ms();
 437 
 438   // indicates if class path already contains a entry (exact match by name)
 439   static bool contains_append_entry(const char* name);
 440 
 441   // adds a class path to the boot append entries
 442   static void add_to_boot_append_entries(ClassPathEntry* new_entry);
 443 
 444   // creates a class path zip entry (returns NULL if JAR file cannot be opened)
 445   static ClassPathZipEntry* create_class_path_zip_entry(const char *apath, bool is_boot_append);
 446 
 447   static bool string_ends_with(const char* str, const char* str_to_find);
 448 
 449   // obtain package name from a fully qualified class name
 450   // *bad_class_name is set to true if there's a problem with parsing class_name, to
 451   // distinguish from a class_name with no package name, as both cases have a NULL return value
 452   static const char* package_from_name(const char* const class_name, bool* bad_class_name = NULL);
 453 
 454   static const char* modules_image_name() { return _modules_image_name; }
 455   static bool is_modules_image(const char* name) {
 456     if (Arguments::has_jimage()) {
 457       assert(_modules_image_name != NULL, "must be set");
 458       return string_ends_with(name, _modules_image_name);
 459     }
 460     return false;
 461   }
 462 
 463   // Debugging
 464   static void verify()              PRODUCT_RETURN;
 465 };
 466 
 467 // PerfClassTraceTime is used to measure time for class loading related events.
 468 // This class tracks cumulative time and exclusive time for specific event types.
 469 // During the execution of one event, other event types (e.g. class loading and
 470 // resolution) as well as recursive calls of the same event type could happen.
 471 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
 472 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
 473 // instances have been created as multiple events are happening.
 474 class PerfClassTraceTime {
 475  public:
 476   enum {
 477     CLASS_LOAD   = 0,
 478     PARSE_CLASS  = 1,
 479     CLASS_LINK   = 2,
 480     CLASS_VERIFY = 3,
 481     CLASS_CLINIT = 4,


< prev index next >