0N/A/*
2273N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_CLASSFILE_CLASSLOADER_HPP
1879N/A#define SHARE_VM_CLASSFILE_CLASSLOADER_HPP
1879N/A
1879N/A#include "classfile/classFileParser.hpp"
1879N/A#include "runtime/perfData.hpp"
1879N/A
0N/A// The VM class loader.
0N/A#include <sys/stat.h>
0N/A
0N/A
0N/A// Meta-index (optional, to be able to skip opening boot classpath jar files)
3863N/Aclass MetaIndex: public CHeapObj<mtClass> {
0N/A private:
0N/A char** _meta_package_names;
0N/A int _num_meta_package_names;
0N/A public:
0N/A MetaIndex(char** meta_package_names, int num_meta_package_names);
0N/A ~MetaIndex();
0N/A bool may_contain(const char* class_name);
0N/A};
0N/A
0N/A
0N/A// Class path entry (directory or zip file)
0N/A
3863N/Aclass ClassPathEntry: public CHeapObj<mtClass> {
0N/A private:
0N/A ClassPathEntry* _next;
0N/A public:
0N/A // Next entry in class path
0N/A ClassPathEntry* next() { return _next; }
0N/A void set_next(ClassPathEntry* next) {
0N/A // may have unlocked readers, so write atomically.
0N/A OrderAccess::release_store_ptr(&_next, next);
0N/A }
0N/A virtual bool is_jar_file() = 0;
0N/A virtual const char* name() = 0;
0N/A virtual bool is_lazy();
0N/A // Constructor
0N/A ClassPathEntry();
0N/A // Attempt to locate file_name through this class path entry.
0N/A // Returns a class file parsing stream if successfull.
0N/A virtual ClassFileStream* open_stream(const char* name) = 0;
0N/A // Debugging
0N/A NOT_PRODUCT(virtual void compile_the_world(Handle loader, TRAPS) = 0;)
0N/A NOT_PRODUCT(virtual bool is_rt_jar() = 0;)
0N/A};
0N/A
0N/A
0N/Aclass ClassPathDirEntry: public ClassPathEntry {
0N/A private:
0N/A char* _dir; // Name of directory
0N/A public:
0N/A bool is_jar_file() { return false; }
0N/A const char* name() { return _dir; }
0N/A ClassPathDirEntry(char* dir);
0N/A ClassFileStream* open_stream(const char* name);
0N/A // Debugging
0N/A NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
0N/A NOT_PRODUCT(bool is_rt_jar();)
0N/A};
0N/A
0N/A
0N/A// Type definitions for zip file and zip file entry
0N/Atypedef void* jzfile;
0N/Atypedef struct {
0N/A char *name; /* entry name */
0N/A jlong time; /* modification time */
0N/A jlong size; /* size of uncompressed data */
0N/A jlong csize; /* size of compressed data (zero if uncompressed) */
0N/A jint crc; /* crc of uncompressed data */
0N/A char *comment; /* optional zip file comment */
0N/A jbyte *extra; /* optional extra data */
0N/A jlong pos; /* position of LOC header (if negative) or data */
0N/A} jzentry;
0N/A
0N/A
0N/Aclass ClassPathZipEntry: public ClassPathEntry {
0N/A private:
0N/A jzfile* _zip; // The zip archive
0N/A char* _zip_name; // Name of zip archive
0N/A public:
0N/A bool is_jar_file() { return true; }
0N/A const char* name() { return _zip_name; }
0N/A ClassPathZipEntry(jzfile* zip, const char* zip_name);
0N/A ~ClassPathZipEntry();
0N/A ClassFileStream* open_stream(const char* name);
0N/A void contents_do(void f(const char* name, void* context), void* context);
0N/A // Debugging
0N/A NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
0N/A NOT_PRODUCT(void compile_the_world12(Handle loader, TRAPS);) // JDK 1.2 version
0N/A NOT_PRODUCT(void compile_the_world13(Handle loader, TRAPS);) // JDK 1.3 version
0N/A NOT_PRODUCT(bool is_rt_jar();)
0N/A NOT_PRODUCT(bool is_rt_jar12();)
0N/A NOT_PRODUCT(bool is_rt_jar13();)
0N/A};
0N/A
0N/A
0N/A// For lazier loading of boot class path entries
0N/Aclass LazyClassPathEntry: public ClassPathEntry {
0N/A private:
0N/A char* _path; // dir or file
0N/A struct stat _st;
0N/A MetaIndex* _meta_index;
0N/A volatile ClassPathEntry* _resolved_entry;
0N/A ClassPathEntry* resolve_entry();
0N/A public:
0N/A bool is_jar_file();
0N/A const char* name() { return _path; }
0N/A LazyClassPathEntry(char* path, struct stat st);
0N/A ClassFileStream* open_stream(const char* name);
0N/A void set_meta_index(MetaIndex* meta_index) { _meta_index = meta_index; }
0N/A virtual bool is_lazy();
0N/A // Debugging
0N/A NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
0N/A NOT_PRODUCT(bool is_rt_jar();)
0N/A};
0N/A
0N/Aclass PackageHashtable;
0N/Aclass PackageInfo;
3863N/Atemplate <MEMFLAGS F> class HashtableBucket;
0N/A
0N/Aclass ClassLoader: AllStatic {
0N/A public:
0N/A enum SomeConstants {
0N/A package_hash_table_size = 31 // Number of buckets
0N/A };
0N/A private:
0N/A friend class LazyClassPathEntry;
0N/A
0N/A // Performance counters
0N/A static PerfCounter* _perf_accumulated_time;
0N/A static PerfCounter* _perf_classes_inited;
0N/A static PerfCounter* _perf_class_init_time;
875N/A static PerfCounter* _perf_class_init_selftime;
875N/A static PerfCounter* _perf_classes_verified;
0N/A static PerfCounter* _perf_class_verify_time;
875N/A static PerfCounter* _perf_class_verify_selftime;
0N/A static PerfCounter* _perf_classes_linked;
0N/A static PerfCounter* _perf_class_link_time;
875N/A static PerfCounter* _perf_class_link_selftime;
875N/A static PerfCounter* _perf_class_parse_time;
875N/A static PerfCounter* _perf_class_parse_selftime;
875N/A static PerfCounter* _perf_sys_class_lookup_time;
875N/A static PerfCounter* _perf_shared_classload_time;
875N/A static PerfCounter* _perf_sys_classload_time;
875N/A static PerfCounter* _perf_app_classload_time;
875N/A static PerfCounter* _perf_app_classload_selftime;
875N/A static PerfCounter* _perf_app_classload_count;
875N/A static PerfCounter* _perf_define_appclasses;
875N/A static PerfCounter* _perf_define_appclass_time;
875N/A static PerfCounter* _perf_define_appclass_selftime;
875N/A static PerfCounter* _perf_app_classfile_bytes_read;
875N/A static PerfCounter* _perf_sys_classfile_bytes_read;
0N/A
0N/A static PerfCounter* _sync_systemLoaderLockContentionRate;
0N/A static PerfCounter* _sync_nonSystemLoaderLockContentionRate;
0N/A static PerfCounter* _sync_JVMFindLoadedClassLockFreeCounter;
0N/A static PerfCounter* _sync_JVMDefineClassLockFreeCounter;
0N/A static PerfCounter* _sync_JNIDefineClassLockFreeCounter;
0N/A
0N/A static PerfCounter* _unsafe_defineClassCallCounter;
0N/A static PerfCounter* _isUnsyncloadClass;
0N/A static PerfCounter* _load_instance_class_failCounter;
0N/A
0N/A // First entry in linked list of ClassPathEntry instances
0N/A static ClassPathEntry* _first_entry;
0N/A // Last entry in linked list of ClassPathEntry instances
0N/A static ClassPathEntry* _last_entry;
0N/A // Hash table used to keep track of loaded packages
0N/A static PackageHashtable* _package_hash_table;
0N/A static const char* _shared_archive;
0N/A
0N/A // Hash function
0N/A static unsigned int hash(const char *s, int n);
0N/A // Returns the package file name corresponding to the specified package
0N/A // or class name, or null if not found.
0N/A static PackageInfo* lookup_package(const char *pkgname);
0N/A // Adds a new package entry for the specified class or package name and
0N/A // corresponding directory or jar file name.
0N/A static bool add_package(const char *pkgname, int classpath_index, TRAPS);
0N/A
0N/A // Initialization
0N/A static void setup_meta_index();
0N/A static void setup_bootstrap_search_path();
0N/A static void load_zip_library();
0N/A static void create_class_path_entry(char *path, struct stat st, ClassPathEntry **new_entry, bool lazy);
0N/A
0N/A // Canonicalizes path names, so strcmp will work properly. This is mainly
0N/A // to avoid confusing the zip library
0N/A static bool get_canonical_path(char* orig, char* out, int len);
0N/A public:
0N/A // Used by the kernel jvm.
0N/A static void update_class_path_entry_list(const char *path,
0N/A bool check_for_duplicates);
0N/A static void print_bootclasspath();
0N/A
0N/A // Timing
875N/A static PerfCounter* perf_accumulated_time() { return _perf_accumulated_time; }
875N/A static PerfCounter* perf_classes_inited() { return _perf_classes_inited; }
875N/A static PerfCounter* perf_class_init_time() { return _perf_class_init_time; }
875N/A static PerfCounter* perf_class_init_selftime() { return _perf_class_init_selftime; }
875N/A static PerfCounter* perf_classes_verified() { return _perf_classes_verified; }
875N/A static PerfCounter* perf_class_verify_time() { return _perf_class_verify_time; }
875N/A static PerfCounter* perf_class_verify_selftime() { return _perf_class_verify_selftime; }
875N/A static PerfCounter* perf_classes_linked() { return _perf_classes_linked; }
875N/A static PerfCounter* perf_class_link_time() { return _perf_class_link_time; }
875N/A static PerfCounter* perf_class_link_selftime() { return _perf_class_link_selftime; }
875N/A static PerfCounter* perf_class_parse_time() { return _perf_class_parse_time; }
875N/A static PerfCounter* perf_class_parse_selftime() { return _perf_class_parse_selftime; }
875N/A static PerfCounter* perf_sys_class_lookup_time() { return _perf_sys_class_lookup_time; }
875N/A static PerfCounter* perf_shared_classload_time() { return _perf_shared_classload_time; }
875N/A static PerfCounter* perf_sys_classload_time() { return _perf_sys_classload_time; }
875N/A static PerfCounter* perf_app_classload_time() { return _perf_app_classload_time; }
875N/A static PerfCounter* perf_app_classload_selftime() { return _perf_app_classload_selftime; }
875N/A static PerfCounter* perf_app_classload_count() { return _perf_app_classload_count; }
875N/A static PerfCounter* perf_define_appclasses() { return _perf_define_appclasses; }
875N/A static PerfCounter* perf_define_appclass_time() { return _perf_define_appclass_time; }
875N/A static PerfCounter* perf_define_appclass_selftime() { return _perf_define_appclass_selftime; }
875N/A static PerfCounter* perf_app_classfile_bytes_read() { return _perf_app_classfile_bytes_read; }
875N/A static PerfCounter* perf_sys_classfile_bytes_read() { return _perf_sys_classfile_bytes_read; }
0N/A
0N/A // Record how often system loader lock object is contended
0N/A static PerfCounter* sync_systemLoaderLockContentionRate() {
0N/A return _sync_systemLoaderLockContentionRate;
0N/A }
0N/A
0N/A // Record how often non system loader lock object is contended
0N/A static PerfCounter* sync_nonSystemLoaderLockContentionRate() {
0N/A return _sync_nonSystemLoaderLockContentionRate;
0N/A }
0N/A
0N/A // Record how many calls to JVM_FindLoadedClass w/o holding a lock
0N/A static PerfCounter* sync_JVMFindLoadedClassLockFreeCounter() {
0N/A return _sync_JVMFindLoadedClassLockFreeCounter;
0N/A }
0N/A
0N/A // Record how many calls to JVM_DefineClass w/o holding a lock
0N/A static PerfCounter* sync_JVMDefineClassLockFreeCounter() {
0N/A return _sync_JVMDefineClassLockFreeCounter;
0N/A }
0N/A
0N/A // Record how many calls to jni_DefineClass w/o holding a lock
0N/A static PerfCounter* sync_JNIDefineClassLockFreeCounter() {
0N/A return _sync_JNIDefineClassLockFreeCounter;
0N/A }
0N/A
0N/A // Record how many calls to Unsafe_DefineClass
0N/A static PerfCounter* unsafe_defineClassCallCounter() {
0N/A return _unsafe_defineClassCallCounter;
0N/A }
0N/A
0N/A // Record how many times SystemDictionary::load_instance_class call
0N/A // fails with linkageError when Unsyncloadclass flag is set.
0N/A static PerfCounter* load_instance_class_failCounter() {
0N/A return _load_instance_class_failCounter;
0N/A }
0N/A
0N/A // Load individual .class file
2062N/A static instanceKlassHandle load_classfile(Symbol* h_name, TRAPS);
0N/A
0N/A // If the specified package has been loaded by the system, then returns
0N/A // the name of the directory or ZIP file that the package was loaded from.
0N/A // Returns null if the package was not loaded.
0N/A // Note: The specified name can either be the name of a class or package.
0N/A // If a package name is specified, then it must be "/"-separator and also
0N/A // end with a trailing "/".
0N/A static oop get_system_package(const char* name, TRAPS);
0N/A
0N/A // Returns an array of Java strings representing all of the currently
0N/A // loaded system packages.
0N/A // Note: The package names returned are "/"-separated and end with a
0N/A // trailing "/".
0N/A static objArrayOop get_system_packages(TRAPS);
0N/A
0N/A // Initialization
0N/A static void initialize();
0N/A static void create_package_info_table();
3863N/A static void create_package_info_table(HashtableBucket<mtClass> *t, int length,
0N/A int number_of_entries);
0N/A static int compute_Object_vtable();
0N/A
0N/A static ClassPathEntry* classpath_entry(int n) {
0N/A ClassPathEntry* e = ClassLoader::_first_entry;
0N/A while (--n >= 0) {
0N/A assert(e != NULL, "Not that many classpath entries.");
0N/A e = e->next();
0N/A }
0N/A return e;
0N/A }
0N/A
0N/A // Sharing dump and restore
0N/A static void copy_package_info_buckets(char** top, char* end);
0N/A static void copy_package_info_table(char** top, char* end);
0N/A
0N/A // VM monitoring and management support
0N/A static jlong classloader_time_ms();
0N/A static jlong class_method_total_size();
0N/A static jlong class_init_count();
0N/A static jlong class_init_time_ms();
0N/A static jlong class_verify_time_ms();
0N/A static jlong class_link_count();
0N/A static jlong class_link_time_ms();
0N/A
0N/A // indicates if class path already contains a entry (exact match by name)
0N/A static bool contains_entry(ClassPathEntry* entry);
0N/A
0N/A // adds a class path list
0N/A static void add_to_list(ClassPathEntry* new_entry);
0N/A
0N/A // creates a class path zip entry (returns NULL if JAR file cannot be opened)
0N/A static ClassPathZipEntry* create_class_path_zip_entry(const char *apath);
0N/A
0N/A // Debugging
0N/A static void verify() PRODUCT_RETURN;
0N/A
0N/A // Force compilation of all methods in all classes in bootstrap class path (stress test)
0N/A#ifndef PRODUCT
0N/A private:
0N/A static int _compile_the_world_counter;
0N/A public:
0N/A static void compile_the_world();
0N/A static void compile_the_world_in(char* name, Handle loader, TRAPS);
0N/A static int compile_the_world_counter() { return _compile_the_world_counter; }
0N/A#endif //PRODUCT
0N/A};
875N/A
875N/A// PerfClassTraceTime is used to measure time for class loading related events.
875N/A// This class tracks cumulative time and exclusive time for specific event types.
875N/A// During the execution of one event, other event types (e.g. class loading and
875N/A// resolution) as well as recursive calls of the same event type could happen.
875N/A// Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
875N/A// (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
875N/A// instances have been created as multiple events are happening.
875N/Aclass PerfClassTraceTime {
2024N/A public:
2024N/A enum {
2024N/A CLASS_LOAD = 0,
2024N/A PARSE_CLASS = 1,
2024N/A CLASS_LINK = 2,
2024N/A CLASS_VERIFY = 3,
2024N/A CLASS_CLINIT = 4,
2024N/A DEFINE_CLASS = 5,
2024N/A EVENT_TYPE_COUNT = 6
2024N/A };
2024N/A protected:
2024N/A // _t tracks time from initialization to destruction of this timer instance
2024N/A // including time for all other event types, and recursive calls of this type.
2024N/A // When a timer is called recursively, the elapsedTimer _t would not be used.
2024N/A elapsedTimer _t;
2024N/A PerfLongCounter* _timep;
2024N/A PerfLongCounter* _selftimep;
2024N/A PerfLongCounter* _eventp;
2024N/A // pointer to thread-local recursion counter and timer array
2024N/A // The thread_local timers track cumulative time for specific event types
2024N/A // exclusive of time for other event types, but including recursive calls
2024N/A // of the same type.
2024N/A int* _recursion_counters;
2024N/A elapsedTimer* _timers;
2024N/A int _event_type;
2024N/A int _prev_active_event;
875N/A
2024N/A public:
875N/A
2024N/A inline PerfClassTraceTime(PerfLongCounter* timep, /* counter incremented with inclusive time */
2024N/A PerfLongCounter* selftimep, /* counter incremented with exclusive time */
2024N/A PerfLongCounter* eventp, /* event counter */
2024N/A int* recursion_counters, /* thread-local recursion counter array */
2024N/A elapsedTimer* timers, /* thread-local timer array */
2024N/A int type /* event type */ ) :
2024N/A _timep(timep), _selftimep(selftimep), _eventp(eventp), _recursion_counters(recursion_counters), _timers(timers), _event_type(type) {
2024N/A initialize();
2024N/A }
875N/A
2024N/A inline PerfClassTraceTime(PerfLongCounter* timep, /* counter incremented with inclusive time */
2024N/A elapsedTimer* timers, /* thread-local timer array */
2024N/A int type /* event type */ ) :
2024N/A _timep(timep), _selftimep(NULL), _eventp(NULL), _recursion_counters(NULL), _timers(timers), _event_type(type) {
2024N/A initialize();
2024N/A }
875N/A
2024N/A inline void suspend() { _t.stop(); _timers[_event_type].stop(); }
2024N/A inline void resume() { _t.start(); _timers[_event_type].start(); }
875N/A
2024N/A ~PerfClassTraceTime();
2024N/A void initialize();
875N/A};
875N/A
1879N/A#endif // SHARE_VM_CLASSFILE_CLASSLOADER_HPP