< 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:


 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_identity(), which gives the
  41 // canonical path 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 identity obtained from the canonical path.
 227   static const char* _modules_image_identity;
 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:


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


< prev index next >