1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   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_CLASSLOADER_HPP
  26 #define SHARE_VM_CLASSFILE_CLASSLOADER_HPP
  27 
  28 #include "jimage.hpp"
  29 #include "runtime/handles.hpp"
  30 #include "runtime/orderAccess.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
  39 #define  MODULES_IMAGE_NAME "modules"
  40 
  41 // Class path entry (directory or zip file)
  42 
  43 class JImageFile;
  44 class ClassFileStream;
  45 class PackageEntry;
  46 template <typename T> class GrowableArray;
  47 
  48 class ClassPathEntry : public CHeapObj<mtClass> {
  49 private:
  50   ClassPathEntry* volatile _next;
  51 public:
  52   // Next entry in class path
  53   ClassPathEntry* next() const { return OrderAccess::load_acquire(&_next); }
  54   virtual ~ClassPathEntry() {}
  55   void set_next(ClassPathEntry* next) {
  56     // may have unlocked readers, so ensure visibility.
  57     OrderAccess::release_store(&_next, next);
  58   }
  59   virtual bool is_modules_image() const = 0;
  60   virtual bool is_jar_file() const = 0;
  61   virtual const char* name() const = 0;
  62   virtual JImageFile* jimage() const = 0;
  63   // Constructor
  64   ClassPathEntry() : _next(NULL) {}
  65   // Attempt to locate file_name through this class path entry.
  66   // Returns a class file parsing stream if successfull.
  67   virtual ClassFileStream* open_stream(const char* name, TRAPS) = 0;
  68   // Debugging
  69   NOT_PRODUCT(virtual void compile_the_world(Handle loader, TRAPS) = 0;)
  70 };
  71 
  72 class ClassPathDirEntry: public ClassPathEntry {
  73  private:
  74   const char* _dir;           // Name of directory
  75  public:
  76   bool is_modules_image() const { return false; }
  77   bool is_jar_file() const { return false;  }
  78   const char* name() const { return _dir; }
  79   JImageFile* jimage() const { return NULL; }
  80   ClassPathDirEntry(const char* dir);
  81   virtual ~ClassPathDirEntry() {}
  82   ClassFileStream* open_stream(const char* name, TRAPS);
  83   // Debugging
  84   NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
  85 };
  86 
  87 
  88 // Type definitions for zip file and zip file entry
  89 typedef void* jzfile;
  90 typedef struct {
  91   char *name;                   /* entry name */
  92   jlong time;                   /* modification time */
  93   jlong size;                   /* size of uncompressed data */
  94   jlong csize;                  /* size of compressed data (zero if uncompressed) */
  95   jint crc;                     /* crc of uncompressed data */
  96   char *comment;                /* optional zip file comment */
  97   jbyte *extra;                 /* optional extra data */
  98   jlong pos;                    /* position of LOC header (if negative) or data */
  99 } jzentry;
 100 
 101 class ClassPathZipEntry: public ClassPathEntry {
 102  enum {
 103    _unknown = 0,
 104    _yes     = 1,
 105    _no      = 2
 106  };
 107  private:
 108   jzfile* _zip;              // The zip archive
 109   const char*   _zip_name;   // Name of zip archive
 110   bool _is_boot_append;      // entry coming from -Xbootclasspath/a
 111   u1 _multi_versioned;       // indicates if the jar file has multi-versioned entries.
 112                              // It can have value of "_unknown", "_yes", or "_no"
 113  public:
 114   bool is_modules_image() const { return false; }
 115   bool is_jar_file() const { return true;  }
 116   const char* name() const { return _zip_name; }
 117   JImageFile* jimage() const { return NULL; }
 118   ClassPathZipEntry(jzfile* zip, const char* zip_name, bool is_boot_append);
 119   virtual ~ClassPathZipEntry();
 120   u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
 121   u1* open_versioned_entry(const char* name, jint* filesize, TRAPS) NOT_CDS_RETURN_(NULL);
 122   ClassFileStream* open_stream(const char* name, TRAPS);
 123   void contents_do(void f(const char* name, void* context), void* context);
 124   bool is_multiple_versioned(TRAPS) NOT_CDS_RETURN_(false);
 125   // Debugging
 126   NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
 127 };
 128 
 129 
 130 // For java image files
 131 class ClassPathImageEntry: public ClassPathEntry {
 132 private:
 133   JImageFile* _jimage;
 134   const char* _name;
 135 public:
 136   bool is_modules_image() const;
 137   bool is_jar_file() const { return false; }
 138   bool is_open() const { return _jimage != NULL; }
 139   const char* name() const { return _name == NULL ? "" : _name; }
 140   JImageFile* jimage() const { return _jimage; }
 141   ClassPathImageEntry(JImageFile* jimage, const char* name);
 142   virtual ~ClassPathImageEntry();
 143   ClassFileStream* open_stream(const char* name, TRAPS);
 144 
 145   // Debugging
 146   NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
 147 };
 148 
 149 // ModuleClassPathList contains a linked list of ClassPathEntry's
 150 // that have been specified for a specific module.  Currently,
 151 // the only way to specify a module/path pair is via the --patch-module
 152 // command line option.
 153 class ModuleClassPathList : public CHeapObj<mtClass> {
 154 private:
 155   Symbol* _module_name;
 156   // First and last entries of class path entries for a specific module
 157   ClassPathEntry* _module_first_entry;
 158   ClassPathEntry* _module_last_entry;
 159 public:
 160   Symbol* module_name() const { return _module_name; }
 161   ClassPathEntry* module_first_entry() const { return _module_first_entry; }
 162   ModuleClassPathList(Symbol* module_name);
 163   ~ModuleClassPathList();
 164   void add_to_list(ClassPathEntry* new_entry);
 165 };
 166 
 167 class SharedPathsMiscInfo;
 168 
 169 class ClassLoader: AllStatic {
 170  public:
 171   enum ClassLoaderType {
 172     BOOT_LOADER = 1,      /* boot loader */
 173     PLATFORM_LOADER  = 2, /* PlatformClassLoader */
 174     APP_LOADER  = 3       /* AppClassLoader */
 175   };
 176  protected:
 177 
 178   // Performance counters
 179   static PerfCounter* _perf_accumulated_time;
 180   static PerfCounter* _perf_classes_inited;
 181   static PerfCounter* _perf_class_init_time;
 182   static PerfCounter* _perf_class_init_selftime;
 183   static PerfCounter* _perf_classes_verified;
 184   static PerfCounter* _perf_class_verify_time;
 185   static PerfCounter* _perf_class_verify_selftime;
 186   static PerfCounter* _perf_classes_linked;
 187   static PerfCounter* _perf_class_link_time;
 188   static PerfCounter* _perf_class_link_selftime;
 189   static PerfCounter* _perf_class_parse_time;
 190   static PerfCounter* _perf_class_parse_selftime;
 191   static PerfCounter* _perf_sys_class_lookup_time;
 192   static PerfCounter* _perf_shared_classload_time;
 193   static PerfCounter* _perf_sys_classload_time;
 194   static PerfCounter* _perf_app_classload_time;
 195   static PerfCounter* _perf_app_classload_selftime;
 196   static PerfCounter* _perf_app_classload_count;
 197   static PerfCounter* _perf_define_appclasses;
 198   static PerfCounter* _perf_define_appclass_time;
 199   static PerfCounter* _perf_define_appclass_selftime;
 200   static PerfCounter* _perf_app_classfile_bytes_read;
 201   static PerfCounter* _perf_sys_classfile_bytes_read;
 202 
 203   static PerfCounter* _sync_systemLoaderLockContentionRate;
 204   static PerfCounter* _sync_nonSystemLoaderLockContentionRate;
 205   static PerfCounter* _sync_JVMFindLoadedClassLockFreeCounter;
 206   static PerfCounter* _sync_JVMDefineClassLockFreeCounter;
 207   static PerfCounter* _sync_JNIDefineClassLockFreeCounter;
 208 
 209   static PerfCounter* _unsafe_defineClassCallCounter;
 210   static PerfCounter* _isUnsyncloadClass;
 211   static PerfCounter* _load_instance_class_failCounter;
 212 
 213   // The boot class path consists of 3 ordered pieces:
 214   //  1. the module/path pairs specified to --patch-module
 215   //    --patch-module=<module>=<file>(<pathsep><file>)*
 216   //  2. the base piece
 217   //    [jimage | build with exploded modules]
 218   //  3. boot loader append path
 219   //    [-Xbootclasspath/a]; [jvmti appended entries]
 220   //
 221   // The boot loader must obey this order when attempting
 222   // to load a class.
 223 
 224   // 1. Contains the module/path pairs specified to --patch-module
 225   static GrowableArray<ModuleClassPathList*>* _patch_mod_entries;
 226 
 227   // 2. the base piece
 228   //    Contains the ClassPathEntry of the modular java runtime image.
 229   //    If no java runtime image is present, this indicates a
 230   //    build with exploded modules is being used instead.
 231   static ClassPathEntry* _jrt_entry;
 232   static GrowableArray<ModuleClassPathList*>* _exploded_entries;
 233   enum { EXPLODED_ENTRY_SIZE = 80 }; // Initial number of exploded modules
 234 
 235   // 3. the boot loader's append path
 236   //    [-Xbootclasspath/a]; [jvmti appended entries]
 237   //    Note: boot loader append path does not support named modules.
 238   static ClassPathEntry* _first_append_entry;
 239   // Last entry in linked list of appended ClassPathEntry instances
 240   static ClassPathEntry* _last_append_entry;
 241 
 242   // Array of module names associated with the boot class loader
 243   CDS_ONLY(static GrowableArray<char*>* _boot_modules_array;)
 244 
 245   // Array of module names associated with the platform class loader
 246   CDS_ONLY(static GrowableArray<char*>* _platform_modules_array;)
 247 
 248   // Info used by CDS
 249   CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;)
 250 
 251   CDS_ONLY(static ClassPathEntry* _app_classpath_entries;)
 252   CDS_ONLY(static ClassPathEntry* _last_app_classpath_entry;)
 253   CDS_ONLY(static void setup_app_search_path(const char *class_path);)
 254   static void add_to_app_classpath_entries(const char* path,
 255                                            ClassPathEntry* entry,
 256                                            bool check_for_duplicates);
 257  public:
 258   CDS_ONLY(static ClassPathEntry* app_classpath_entries() {return _app_classpath_entries;})
 259 
 260  protected:
 261   // Initialization:
 262   //   - setup the boot loader's system class path
 263   //   - setup the boot loader's patch mod entries, if present
 264   //   - create the ModuleEntry for java.base
 265   static void setup_bootstrap_search_path();
 266   static void setup_boot_search_path(const char *class_path);
 267   static void setup_patch_mod_entries();
 268   static void create_javabase();
 269 
 270   static void load_zip_library();
 271   static void load_jimage_library();
 272   static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st,
 273                                                  bool throw_exception,
 274                                                  bool is_boot_append, TRAPS);
 275 
 276  public:
 277 
 278   // If the package for the fully qualified class name is in the boot
 279   // loader's package entry table then add_package() sets the classpath_index
 280   // field so that get_system_package() will know to return a non-null value
 281   // for the package's location.  And, so that the package will be added to
 282   // the list of packages returned by get_system_packages().
 283   // For packages whose classes are loaded from the boot loader class path, the
 284   // classpath_index indicates which entry on the boot loader class path.
 285   static bool add_package(const char *fullq_class_name, s2 classpath_index, TRAPS);
 286 
 287   // Canonicalizes path names, so strcmp will work properly. This is mainly
 288   // to avoid confusing the zip library
 289   static bool get_canonical_path(const char* orig, char* out, int len);
 290   static const char* file_name_for_class_name(const char* class_name,
 291                                               int class_name_len);
 292   static PackageEntry* get_package_entry(const char* class_name, ClassLoaderData* loader_data, TRAPS);
 293 
 294  public:
 295   static jboolean decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg);
 296   static int crc32(int crc, const char* buf, int len);
 297   static bool update_class_path_entry_list(const char *path,
 298                                            bool check_for_duplicates,
 299                                            bool is_boot_append,
 300                                            bool throw_exception=true);
 301   static void print_bootclasspath();
 302 
 303   // Timing
 304   static PerfCounter* perf_accumulated_time()         { return _perf_accumulated_time; }
 305   static PerfCounter* perf_classes_inited()           { return _perf_classes_inited; }
 306   static PerfCounter* perf_class_init_time()          { return _perf_class_init_time; }
 307   static PerfCounter* perf_class_init_selftime()      { return _perf_class_init_selftime; }
 308   static PerfCounter* perf_classes_verified()         { return _perf_classes_verified; }
 309   static PerfCounter* perf_class_verify_time()        { return _perf_class_verify_time; }
 310   static PerfCounter* perf_class_verify_selftime()    { return _perf_class_verify_selftime; }
 311   static PerfCounter* perf_classes_linked()           { return _perf_classes_linked; }
 312   static PerfCounter* perf_class_link_time()          { return _perf_class_link_time; }
 313   static PerfCounter* perf_class_link_selftime()      { return _perf_class_link_selftime; }
 314   static PerfCounter* perf_class_parse_time()         { return _perf_class_parse_time; }
 315   static PerfCounter* perf_class_parse_selftime()     { return _perf_class_parse_selftime; }
 316   static PerfCounter* perf_sys_class_lookup_time()    { return _perf_sys_class_lookup_time; }
 317   static PerfCounter* perf_shared_classload_time()    { return _perf_shared_classload_time; }
 318   static PerfCounter* perf_sys_classload_time()       { return _perf_sys_classload_time; }
 319   static PerfCounter* perf_app_classload_time()       { return _perf_app_classload_time; }
 320   static PerfCounter* perf_app_classload_selftime()   { return _perf_app_classload_selftime; }
 321   static PerfCounter* perf_app_classload_count()      { return _perf_app_classload_count; }
 322   static PerfCounter* perf_define_appclasses()        { return _perf_define_appclasses; }
 323   static PerfCounter* perf_define_appclass_time()     { return _perf_define_appclass_time; }
 324   static PerfCounter* perf_define_appclass_selftime() { return _perf_define_appclass_selftime; }
 325   static PerfCounter* perf_app_classfile_bytes_read() { return _perf_app_classfile_bytes_read; }
 326   static PerfCounter* perf_sys_classfile_bytes_read() { return _perf_sys_classfile_bytes_read; }
 327 
 328   // Record how often system loader lock object is contended
 329   static PerfCounter* sync_systemLoaderLockContentionRate() {
 330     return _sync_systemLoaderLockContentionRate;
 331   }
 332 
 333   // Record how often non system loader lock object is contended
 334   static PerfCounter* sync_nonSystemLoaderLockContentionRate() {
 335     return _sync_nonSystemLoaderLockContentionRate;
 336   }
 337 
 338   // Record how many calls to JVM_FindLoadedClass w/o holding a lock
 339   static PerfCounter* sync_JVMFindLoadedClassLockFreeCounter() {
 340     return _sync_JVMFindLoadedClassLockFreeCounter;
 341   }
 342 
 343   // Record how many calls to JVM_DefineClass w/o holding a lock
 344   static PerfCounter* sync_JVMDefineClassLockFreeCounter() {
 345     return _sync_JVMDefineClassLockFreeCounter;
 346   }
 347 
 348   // Record how many calls to jni_DefineClass w/o holding a lock
 349   static PerfCounter* sync_JNIDefineClassLockFreeCounter() {
 350     return _sync_JNIDefineClassLockFreeCounter;
 351   }
 352 
 353   // Record how many calls to Unsafe_DefineClass
 354   static PerfCounter* unsafe_defineClassCallCounter() {
 355     return _unsafe_defineClassCallCounter;
 356   }
 357 
 358   // Record how many times SystemDictionary::load_instance_class call
 359   // fails with linkageError when Unsyncloadclass flag is set.
 360   static PerfCounter* load_instance_class_failCounter() {
 361     return _load_instance_class_failCounter;
 362   }
 363 
 364   // Modular java runtime image is present vs. a build with exploded modules
 365   static bool has_jrt_entry() { return (_jrt_entry != NULL); }
 366   static ClassPathEntry* get_jrt_entry() { return _jrt_entry; }
 367 
 368   // Add a module's exploded directory to the boot loader's exploded module build list
 369   static void add_to_exploded_build_list(Symbol* module_name, TRAPS);
 370 
 371   // Attempt load of individual class from either the patched or exploded modules build lists
 372   static ClassFileStream* search_module_entries(const GrowableArray<ModuleClassPathList*>* const module_list,
 373                                                 const char* const class_name,
 374                                                 const char* const file_name, TRAPS);
 375 
 376   // Load individual .class file
 377   static InstanceKlass* load_class(Symbol* class_name, bool search_append_only, TRAPS);
 378 
 379   // If the specified package has been loaded by the system, then returns
 380   // the name of the directory or ZIP file that the package was loaded from.
 381   // Returns null if the package was not loaded.
 382   // Note: The specified name can either be the name of a class or package.
 383   // If a package name is specified, then it must be "/"-separator and also
 384   // end with a trailing "/".
 385   static oop get_system_package(const char* name, TRAPS);
 386 
 387   // Returns an array of Java strings representing all of the currently
 388   // loaded system packages.
 389   // Note: The package names returned are "/"-separated and end with a
 390   // trailing "/".
 391   static objArrayOop get_system_packages(TRAPS);
 392 
 393   // Initialization
 394   static void initialize();
 395   static void classLoader_init2(TRAPS);
 396   CDS_ONLY(static void initialize_shared_path();)
 397 
 398   static int compute_Object_vtable();
 399 
 400   static ClassPathEntry* classpath_entry(int n) {
 401     assert(n >= 0, "sanity");
 402     if (n == 0) {
 403       assert(has_jrt_entry(), "No class path entry at 0 for exploded module builds");
 404       return ClassLoader::_jrt_entry;
 405     } else {
 406       // The java runtime image is always the first entry
 407       // in the FileMapInfo::_classpath_entry_table. Even though
 408       // the _jrt_entry is not included in the _first_append_entry
 409       // linked list, it must be accounted for when comparing the
 410       // class path vs. the shared archive class path.
 411       ClassPathEntry* e = ClassLoader::_first_append_entry;
 412       while (--n >= 1) {
 413         assert(e != NULL, "Not that many classpath entries.");
 414         e = e->next();
 415       }
 416       return e;
 417     }
 418   }
 419 
 420   static bool is_in_patch_mod_entries(Symbol* module_name);
 421 
 422 #if INCLUDE_CDS
 423   // Sharing dump and restore
 424 
 425   // Helper function used by CDS code to get the number of boot classpath
 426   // entries during shared classpath setup time.
 427   static int num_boot_classpath_entries() {
 428     assert(DumpSharedSpaces, "Should only be called at CDS dump time");
 429     assert(has_jrt_entry(), "must have a java runtime image");
 430     int num_entries = 1; // count the runtime image
 431     ClassPathEntry* e = ClassLoader::_first_append_entry;
 432     while (e != NULL) {
 433       num_entries ++;
 434       e = e->next();
 435     }
 436     return num_entries;
 437   }
 438 
 439   static ClassPathEntry* get_next_boot_classpath_entry(ClassPathEntry* e) {
 440     if (e == ClassLoader::_jrt_entry) {
 441       return ClassLoader::_first_append_entry;
 442     } else {
 443       return e->next();
 444     }
 445   }
 446 
 447   // Helper function used by CDS code to get the number of app classpath
 448   // entries during shared classpath setup time.
 449   static int num_app_classpath_entries() {
 450     assert(DumpSharedSpaces, "Should only be called at CDS dump time");
 451     int num_entries = 0;
 452     ClassPathEntry* e= ClassLoader::_app_classpath_entries;
 453     while (e != NULL) {
 454       num_entries ++;
 455       e = e->next();
 456     }
 457     return num_entries;
 458   }
 459 
 460   static void  check_shared_classpath(const char *path);
 461   static void  finalize_shared_paths_misc_info();
 462   static int   get_shared_paths_misc_info_size();
 463   static void* get_shared_paths_misc_info();
 464   static bool  check_shared_paths_misc_info(void* info, int size);
 465   static void  exit_with_path_failure(const char* error, const char* message);
 466 
 467   static void record_result(InstanceKlass* ik, const ClassFileStream* stream);
 468 #endif
 469   static JImageLocationRef jimage_find_resource(JImageFile* jf, const char* module_name,
 470                                                 const char* file_name, jlong &size);
 471 
 472   static void  trace_class_path(const char* msg, const char* name = NULL);
 473 
 474   // VM monitoring and management support
 475   static jlong classloader_time_ms();
 476   static jlong class_method_total_size();
 477   static jlong class_init_count();
 478   static jlong class_init_time_ms();
 479   static jlong class_verify_time_ms();
 480   static jlong class_link_count();
 481   static jlong class_link_time_ms();
 482 
 483   // indicates if class path already contains a entry (exact match by name)
 484   static bool contains_append_entry(const char* name);
 485 
 486   // adds a class path to the boot append entries
 487   static void add_to_boot_append_entries(ClassPathEntry* new_entry);
 488 
 489   // creates a class path zip entry (returns NULL if JAR file cannot be opened)
 490   static ClassPathZipEntry* create_class_path_zip_entry(const char *apath, bool is_boot_append);
 491 
 492   static bool string_ends_with(const char* str, const char* str_to_find);
 493 
 494   // obtain package name from a fully qualified class name
 495   // *bad_class_name is set to true if there's a problem with parsing class_name, to
 496   // distinguish from a class_name with no package name, as both cases have a NULL return value
 497   static const char* package_from_name(const char* const class_name, bool* bad_class_name = NULL);
 498 
 499   static bool is_modules_image(const char* name) { return string_ends_with(name, MODULES_IMAGE_NAME); }
 500 
 501   // Debugging
 502   static void verify()              PRODUCT_RETURN;
 503 
 504   // Force compilation of all methods in all classes in bootstrap class path (stress test)
 505 #ifndef PRODUCT
 506  protected:
 507   static int _compile_the_world_class_counter;
 508   static int _compile_the_world_method_counter;
 509  public:
 510   static void compile_the_world();
 511   static void compile_the_world_in(char* name, Handle loader, TRAPS);
 512   static int  compile_the_world_counter() { return _compile_the_world_class_counter; }
 513 #endif //PRODUCT
 514 };
 515 
 516 // PerfClassTraceTime is used to measure time for class loading related events.
 517 // This class tracks cumulative time and exclusive time for specific event types.
 518 // During the execution of one event, other event types (e.g. class loading and
 519 // resolution) as well as recursive calls of the same event type could happen.
 520 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
 521 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
 522 // instances have been created as multiple events are happening.
 523 class PerfClassTraceTime {
 524  public:
 525   enum {
 526     CLASS_LOAD   = 0,
 527     PARSE_CLASS  = 1,
 528     CLASS_LINK   = 2,
 529     CLASS_VERIFY = 3,
 530     CLASS_CLINIT = 4,
 531     DEFINE_CLASS = 5,
 532     EVENT_TYPE_COUNT = 6
 533   };
 534  protected:
 535   // _t tracks time from initialization to destruction of this timer instance
 536   // including time for all other event types, and recursive calls of this type.
 537   // When a timer is called recursively, the elapsedTimer _t would not be used.
 538   elapsedTimer     _t;
 539   PerfLongCounter* _timep;
 540   PerfLongCounter* _selftimep;
 541   PerfLongCounter* _eventp;
 542   // pointer to thread-local recursion counter and timer array
 543   // The thread_local timers track cumulative time for specific event types
 544   // exclusive of time for other event types, but including recursive calls
 545   // of the same type.
 546   int*             _recursion_counters;
 547   elapsedTimer*    _timers;
 548   int              _event_type;
 549   int              _prev_active_event;
 550 
 551  public:
 552 
 553   inline PerfClassTraceTime(PerfLongCounter* timep,     /* counter incremented with inclusive time */
 554                             PerfLongCounter* selftimep, /* counter incremented with exclusive time */
 555                             PerfLongCounter* eventp,    /* event counter */
 556                             int* recursion_counters,    /* thread-local recursion counter array */
 557                             elapsedTimer* timers,       /* thread-local timer array */
 558                             int type                    /* event type */ ) :
 559       _timep(timep), _selftimep(selftimep), _eventp(eventp), _recursion_counters(recursion_counters), _timers(timers), _event_type(type) {
 560     initialize();
 561   }
 562 
 563   inline PerfClassTraceTime(PerfLongCounter* timep,     /* counter incremented with inclusive time */
 564                             elapsedTimer* timers,       /* thread-local timer array */
 565                             int type                    /* event type */ ) :
 566       _timep(timep), _selftimep(NULL), _eventp(NULL), _recursion_counters(NULL), _timers(timers), _event_type(type) {
 567     initialize();
 568   }
 569 
 570   inline void suspend() { _t.stop(); _timers[_event_type].stop(); }
 571   inline void resume()  { _t.start(); _timers[_event_type].start(); }
 572 
 573   ~PerfClassTraceTime();
 574   void initialize();
 575 };
 576 
 577 #endif // SHARE_VM_CLASSFILE_CLASSLOADER_HPP