49 class ClassPathEntry: public CHeapObj<mtClass> {
50 private:
51 ClassPathEntry* _next;
52 public:
53 // Next entry in class path
54 ClassPathEntry* next() { return _next; }
55 void set_next(ClassPathEntry* next) {
56 // may have unlocked readers, so write atomically.
57 OrderAccess::release_store_ptr(&_next, next);
58 }
59 virtual bool is_jar_file() = 0;
60 virtual const char* name() = 0;
61 virtual bool is_lazy();
62 // Constructor
63 ClassPathEntry();
64 // Attempt to locate file_name through this class path entry.
65 // Returns a class file parsing stream if successfull.
66 virtual ClassFileStream* open_stream(const char* name, TRAPS) = 0;
67 // Debugging
68 NOT_PRODUCT(virtual void compile_the_world(Handle loader, TRAPS) = 0;)
69 NOT_PRODUCT(virtual bool is_rt_jar() = 0;)
70 };
71
72
73 class ClassPathDirEntry: public ClassPathEntry {
74 private:
75 const char* _dir; // Name of directory
76 public:
77 bool is_jar_file() { return false; }
78 const char* name() { return _dir; }
79 ClassPathDirEntry(const char* dir);
80 ClassFileStream* open_stream(const char* name, TRAPS);
81 // Debugging
82 NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
83 NOT_PRODUCT(bool is_rt_jar();)
84 };
85
86
87 // Type definitions for zip file and zip file entry
88 typedef void* jzfile;
89 typedef struct {
90 char *name; /* entry name */
91 jlong time; /* modification time */
92 jlong size; /* size of uncompressed data */
93 jlong csize; /* size of compressed data (zero if uncompressed) */
94 jint crc; /* crc of uncompressed data */
95 char *comment; /* optional zip file comment */
96 jbyte *extra; /* optional extra data */
97 jlong pos; /* position of LOC header (if negative) or data */
98 } jzentry;
99
100
101 class ClassPathZipEntry: public ClassPathEntry {
102 private:
103 jzfile* _zip; // The zip archive
104 const char* _zip_name; // Name of zip archive
105 public:
106 bool is_jar_file() { return true; }
107 const char* name() { return _zip_name; }
108 ClassPathZipEntry(jzfile* zip, const char* zip_name);
109 ~ClassPathZipEntry();
110 u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
111 ClassFileStream* open_stream(const char* name, TRAPS);
112 void contents_do(void f(const char* name, void* context), void* context);
113 // Debugging
114 NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
115 NOT_PRODUCT(bool is_rt_jar();)
116 };
117
118
119 // For lazier loading of boot class path entries
120 class LazyClassPathEntry: public ClassPathEntry {
121 private:
122 const char* _path; // dir or file
123 struct stat _st;
124 MetaIndex* _meta_index;
125 bool _has_error;
126 bool _throw_exception;
127 volatile ClassPathEntry* _resolved_entry;
128 ClassPathEntry* resolve_entry(TRAPS);
129 public:
130 bool is_jar_file();
131 const char* name() { return _path; }
132 LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception);
133 virtual ~LazyClassPathEntry();
134 u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
135
136 ClassFileStream* open_stream(const char* name, TRAPS);
137 void set_meta_index(MetaIndex* meta_index) { _meta_index = meta_index; }
138 virtual bool is_lazy();
139 // Debugging
140 NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
141 NOT_PRODUCT(bool is_rt_jar();)
142 };
143
144 class PackageHashtable;
145 class PackageInfo;
146 class SharedPathsMiscInfo;
147 template <MEMFLAGS F> class HashtableBucket;
148
149 class ClassLoader: AllStatic {
150 public:
151 enum SomeConstants {
152 package_hash_table_size = 31 // Number of buckets
153 };
154 protected:
155 friend class LazyClassPathEntry;
156
157 // Performance counters
158 static PerfCounter* _perf_accumulated_time;
159 static PerfCounter* _perf_classes_inited;
160 static PerfCounter* _perf_class_init_time;
161 static PerfCounter* _perf_class_init_selftime;
209 static PackageInfo* lookup_package(const char *pkgname);
210 // Adds a new package entry for the specified class or package name and
211 // corresponding directory or jar file name.
212 static bool add_package(const char *pkgname, int classpath_index, TRAPS);
213
214 // Initialization
215 static void setup_bootstrap_meta_index();
216 static void setup_meta_index(const char* meta_index_path, const char* meta_index_dir,
217 int start_index);
218 static void setup_bootstrap_search_path();
219 static void setup_search_path(const char *class_path);
220
221 static void load_zip_library();
222 static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st,
223 bool lazy, bool throw_exception, TRAPS);
224
225 // Canonicalizes path names, so strcmp will work properly. This is mainly
226 // to avoid confusing the zip library
227 static bool get_canonical_path(const char* orig, char* out, int len);
228 public:
229 static int crc32(int crc, const char* buf, int len);
230 static bool update_class_path_entry_list(const char *path,
231 bool check_for_duplicates,
232 bool throw_exception=true);
233 static void print_bootclasspath();
234
235 // Timing
236 static PerfCounter* perf_accumulated_time() { return _perf_accumulated_time; }
237 static PerfCounter* perf_classes_inited() { return _perf_classes_inited; }
238 static PerfCounter* perf_class_init_time() { return _perf_class_init_time; }
239 static PerfCounter* perf_class_init_selftime() { return _perf_class_init_selftime; }
240 static PerfCounter* perf_classes_verified() { return _perf_classes_verified; }
241 static PerfCounter* perf_class_verify_time() { return _perf_class_verify_time; }
242 static PerfCounter* perf_class_verify_selftime() { return _perf_class_verify_selftime; }
243 static PerfCounter* perf_classes_linked() { return _perf_classes_linked; }
244 static PerfCounter* perf_class_link_time() { return _perf_class_link_time; }
245 static PerfCounter* perf_class_link_selftime() { return _perf_class_link_selftime; }
246 static PerfCounter* perf_class_parse_time() { return _perf_class_parse_time; }
247 static PerfCounter* perf_class_parse_selftime() { return _perf_class_parse_selftime; }
248 static PerfCounter* perf_sys_class_lookup_time() { return _perf_sys_class_lookup_time; }
|
49 class ClassPathEntry: public CHeapObj<mtClass> {
50 private:
51 ClassPathEntry* _next;
52 public:
53 // Next entry in class path
54 ClassPathEntry* next() { return _next; }
55 void set_next(ClassPathEntry* next) {
56 // may have unlocked readers, so write atomically.
57 OrderAccess::release_store_ptr(&_next, next);
58 }
59 virtual bool is_jar_file() = 0;
60 virtual const char* name() = 0;
61 virtual bool is_lazy();
62 // Constructor
63 ClassPathEntry();
64 // Attempt to locate file_name through this class path entry.
65 // Returns a class file parsing stream if successfull.
66 virtual ClassFileStream* open_stream(const char* name, TRAPS) = 0;
67 // Debugging
68 NOT_PRODUCT(virtual void compile_the_world(Handle loader, TRAPS) = 0;)
69 NOT_PRODUCT(virtual bool is_jrt() = 0;)
70 };
71
72
73 class ClassPathDirEntry: public ClassPathEntry {
74 private:
75 const char* _dir; // Name of directory
76 public:
77 bool is_jar_file() { return false; }
78 const char* name() { return _dir; }
79 ClassPathDirEntry(const char* dir);
80 ClassFileStream* open_stream(const char* name, TRAPS);
81 // Debugging
82 NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
83 NOT_PRODUCT(bool is_jrt();)
84 };
85
86
87 // Type definitions for zip file and zip file entry
88 typedef void* jzfile;
89 typedef struct {
90 char *name; /* entry name */
91 jlong time; /* modification time */
92 jlong size; /* size of uncompressed data */
93 jlong csize; /* size of compressed data (zero if uncompressed) */
94 jint crc; /* crc of uncompressed data */
95 char *comment; /* optional zip file comment */
96 jbyte *extra; /* optional extra data */
97 jlong pos; /* position of LOC header (if negative) or data */
98 } jzentry;
99
100
101 class ClassPathZipEntry: public ClassPathEntry {
102 private:
103 jzfile* _zip; // The zip archive
104 const char* _zip_name; // Name of zip archive
105 public:
106 bool is_jar_file() { return true; }
107 const char* name() { return _zip_name; }
108 ClassPathZipEntry(jzfile* zip, const char* zip_name);
109 ~ClassPathZipEntry();
110 u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
111 ClassFileStream* open_stream(const char* name, TRAPS);
112 void contents_do(void f(const char* name, void* context), void* context);
113 // Debugging
114 NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
115 NOT_PRODUCT(bool is_jrt();)
116 };
117
118
119 // For lazier loading of boot class path entries
120 class LazyClassPathEntry: public ClassPathEntry {
121 private:
122 const char* _path; // dir or file
123 struct stat _st;
124 MetaIndex* _meta_index;
125 bool _has_error;
126 bool _throw_exception;
127 volatile ClassPathEntry* _resolved_entry;
128 ClassPathEntry* resolve_entry(TRAPS);
129 public:
130 bool is_jar_file();
131 const char* name() { return _path; }
132 LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception);
133 virtual ~LazyClassPathEntry();
134 u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
135
136 ClassFileStream* open_stream(const char* name, TRAPS);
137 void set_meta_index(MetaIndex* meta_index) { _meta_index = meta_index; }
138 virtual bool is_lazy();
139 // Debugging
140 NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
141 NOT_PRODUCT(bool is_jrt();)
142 };
143
144 // For java image files
145 class ImageFile;
146 class ClassPathImageEntry: public ClassPathEntry {
147 private:
148 ImageFile *_image;
149 public:
150 bool is_jar_file() { return false; }
151 bool is_open() { return _image != NULL; }
152 const char* name();
153 ClassPathImageEntry(char* name);
154 ~ClassPathImageEntry();
155 ClassFileStream* open_stream(const char* name, TRAPS);
156
157 // Debugging
158 NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
159 NOT_PRODUCT(bool is_jrt();)
160 };
161
162 class PackageHashtable;
163 class PackageInfo;
164 class SharedPathsMiscInfo;
165 template <MEMFLAGS F> class HashtableBucket;
166
167 class ClassLoader: AllStatic {
168 public:
169 enum SomeConstants {
170 package_hash_table_size = 31 // Number of buckets
171 };
172 protected:
173 friend class LazyClassPathEntry;
174
175 // Performance counters
176 static PerfCounter* _perf_accumulated_time;
177 static PerfCounter* _perf_classes_inited;
178 static PerfCounter* _perf_class_init_time;
179 static PerfCounter* _perf_class_init_selftime;
227 static PackageInfo* lookup_package(const char *pkgname);
228 // Adds a new package entry for the specified class or package name and
229 // corresponding directory or jar file name.
230 static bool add_package(const char *pkgname, int classpath_index, TRAPS);
231
232 // Initialization
233 static void setup_bootstrap_meta_index();
234 static void setup_meta_index(const char* meta_index_path, const char* meta_index_dir,
235 int start_index);
236 static void setup_bootstrap_search_path();
237 static void setup_search_path(const char *class_path);
238
239 static void load_zip_library();
240 static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st,
241 bool lazy, bool throw_exception, TRAPS);
242
243 // Canonicalizes path names, so strcmp will work properly. This is mainly
244 // to avoid confusing the zip library
245 static bool get_canonical_path(const char* orig, char* out, int len);
246 public:
247 static jboolean decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg);
248 static int crc32(int crc, const char* buf, int len);
249 static bool update_class_path_entry_list(const char *path,
250 bool check_for_duplicates,
251 bool throw_exception=true);
252 static void print_bootclasspath();
253
254 // Timing
255 static PerfCounter* perf_accumulated_time() { return _perf_accumulated_time; }
256 static PerfCounter* perf_classes_inited() { return _perf_classes_inited; }
257 static PerfCounter* perf_class_init_time() { return _perf_class_init_time; }
258 static PerfCounter* perf_class_init_selftime() { return _perf_class_init_selftime; }
259 static PerfCounter* perf_classes_verified() { return _perf_classes_verified; }
260 static PerfCounter* perf_class_verify_time() { return _perf_class_verify_time; }
261 static PerfCounter* perf_class_verify_selftime() { return _perf_class_verify_selftime; }
262 static PerfCounter* perf_classes_linked() { return _perf_classes_linked; }
263 static PerfCounter* perf_class_link_time() { return _perf_class_link_time; }
264 static PerfCounter* perf_class_link_selftime() { return _perf_class_link_selftime; }
265 static PerfCounter* perf_class_parse_time() { return _perf_class_parse_time; }
266 static PerfCounter* perf_class_parse_selftime() { return _perf_class_parse_selftime; }
267 static PerfCounter* perf_sys_class_lookup_time() { return _perf_sys_class_lookup_time; }
|