30 #include "utilities/macros.hpp"
31
32 // The VM class loader.
33 #include <sys/stat.h>
34
35
36 // Class path entry (directory or zip file)
37
38 class ClassPathEntry: public CHeapObj<mtClass> {
39 private:
40 ClassPathEntry* _next;
41 public:
42 // Next entry in class path
43 ClassPathEntry* next() { return _next; }
44 void set_next(ClassPathEntry* next) {
45 // may have unlocked readers, so write atomically.
46 OrderAccess::release_store_ptr(&_next, next);
47 }
48 virtual bool is_jar_file() = 0;
49 virtual const char* name() = 0;
50 virtual bool is_lazy();
51 // Constructor
52 ClassPathEntry();
53 // Attempt to locate file_name through this class path entry.
54 // Returns a class file parsing stream if successfull.
55 virtual ClassFileStream* open_stream(const char* name, TRAPS) = 0;
56 // Debugging
57 NOT_PRODUCT(virtual void compile_the_world(Handle loader, TRAPS) = 0;)
58 NOT_PRODUCT(virtual bool is_jrt() = 0;)
59 };
60
61
62 class ClassPathDirEntry: public ClassPathEntry {
63 private:
64 const char* _dir; // Name of directory
65 public:
66 bool is_jar_file() { return false; }
67 const char* name() { return _dir; }
68 ClassPathDirEntry(const char* dir);
69 ClassFileStream* open_stream(const char* name, TRAPS);
70 // Debugging
88
89
90 class ClassPathZipEntry: public ClassPathEntry {
91 private:
92 jzfile* _zip; // The zip archive
93 const char* _zip_name; // Name of zip archive
94 public:
95 bool is_jar_file() { return true; }
96 const char* name() { return _zip_name; }
97 ClassPathZipEntry(jzfile* zip, const char* zip_name);
98 ~ClassPathZipEntry();
99 u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
100 ClassFileStream* open_stream(const char* name, TRAPS);
101 void contents_do(void f(const char* name, void* context), void* context);
102 // Debugging
103 NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
104 NOT_PRODUCT(bool is_jrt();)
105 };
106
107
108 // For lazier loading of boot class path entries
109 class LazyClassPathEntry: public ClassPathEntry {
110 private:
111 const char* _path; // dir or file
112 struct stat _st;
113 bool _has_error;
114 bool _throw_exception;
115 volatile ClassPathEntry* _resolved_entry;
116 ClassPathEntry* resolve_entry(TRAPS);
117 public:
118 bool is_jar_file();
119 const char* name() { return _path; }
120 LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception);
121 virtual ~LazyClassPathEntry();
122 u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
123
124 ClassFileStream* open_stream(const char* name, TRAPS);
125 virtual bool is_lazy();
126 // Debugging
127 NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
128 NOT_PRODUCT(bool is_jrt();)
129 };
130
131 // For java image files
132 class ImageFile;
133 class ClassPathImageEntry: public ClassPathEntry {
134 private:
135 ImageFile *_image;
136 public:
137 bool is_jar_file() { return false; }
138 bool is_open() { return _image != NULL; }
139 const char* name();
140 ClassPathImageEntry(char* name);
141 ~ClassPathImageEntry();
142 ClassFileStream* open_stream(const char* name, TRAPS);
143
144 // Debugging
145 NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
146 NOT_PRODUCT(bool is_jrt();)
147 };
148
149 class PackageHashtable;
150 class PackageInfo;
151 class SharedPathsMiscInfo;
152 template <MEMFLAGS F> class HashtableBucket;
153
154 class ClassLoader: AllStatic {
155 public:
156 enum SomeConstants {
157 package_hash_table_size = 31 // Number of buckets
158 };
159 protected:
160 friend class LazyClassPathEntry;
161
162 // Performance counters
163 static PerfCounter* _perf_accumulated_time;
164 static PerfCounter* _perf_classes_inited;
165 static PerfCounter* _perf_class_init_time;
166 static PerfCounter* _perf_class_init_selftime;
167 static PerfCounter* _perf_classes_verified;
168 static PerfCounter* _perf_class_verify_time;
169 static PerfCounter* _perf_class_verify_selftime;
170 static PerfCounter* _perf_classes_linked;
171 static PerfCounter* _perf_class_link_time;
172 static PerfCounter* _perf_class_link_selftime;
173 static PerfCounter* _perf_class_parse_time;
174 static PerfCounter* _perf_class_parse_selftime;
175 static PerfCounter* _perf_sys_class_lookup_time;
176 static PerfCounter* _perf_shared_classload_time;
177 static PerfCounter* _perf_sys_classload_time;
178 static PerfCounter* _perf_app_classload_time;
179 static PerfCounter* _perf_app_classload_selftime;
180 static PerfCounter* _perf_app_classload_count;
205 static const char* _shared_archive;
206
207 // Info used by CDS
208 CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;)
209
210 // Hash function
211 static unsigned int hash(const char *s, int n);
212 // Returns the package file name corresponding to the specified package
213 // or class name, or null if not found.
214 static PackageInfo* lookup_package(const char *pkgname);
215 // Adds a new package entry for the specified class or package name and
216 // corresponding directory or jar file name.
217 static bool add_package(const char *pkgname, int classpath_index, TRAPS);
218
219 // Initialization
220 static void setup_bootstrap_search_path();
221 static void setup_search_path(const char *class_path);
222
223 static void load_zip_library();
224 static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st,
225 bool lazy, bool throw_exception, TRAPS);
226
227 // Canonicalizes path names, so strcmp will work properly. This is mainly
228 // to avoid confusing the zip library
229 static bool get_canonical_path(const char* orig, char* out, int len);
230 public:
231 static jboolean decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg);
232 static int crc32(int crc, const char* buf, int len);
233 static bool update_class_path_entry_list(const char *path,
234 bool check_for_duplicates,
235 bool throw_exception=true);
236 static void print_bootclasspath();
237
238 // Timing
239 static PerfCounter* perf_accumulated_time() { return _perf_accumulated_time; }
240 static PerfCounter* perf_classes_inited() { return _perf_classes_inited; }
241 static PerfCounter* perf_class_init_time() { return _perf_class_init_time; }
242 static PerfCounter* perf_class_init_selftime() { return _perf_class_init_selftime; }
243 static PerfCounter* perf_classes_verified() { return _perf_classes_verified; }
244 static PerfCounter* perf_class_verify_time() { return _perf_class_verify_time; }
245 static PerfCounter* perf_class_verify_selftime() { return _perf_class_verify_selftime; }
|
30 #include "utilities/macros.hpp"
31
32 // The VM class loader.
33 #include <sys/stat.h>
34
35
36 // Class path entry (directory or zip file)
37
38 class ClassPathEntry: public CHeapObj<mtClass> {
39 private:
40 ClassPathEntry* _next;
41 public:
42 // Next entry in class path
43 ClassPathEntry* next() { return _next; }
44 void set_next(ClassPathEntry* next) {
45 // may have unlocked readers, so write atomically.
46 OrderAccess::release_store_ptr(&_next, next);
47 }
48 virtual bool is_jar_file() = 0;
49 virtual const char* name() = 0;
50 // Constructor
51 ClassPathEntry();
52 // Attempt to locate file_name through this class path entry.
53 // Returns a class file parsing stream if successfull.
54 virtual ClassFileStream* open_stream(const char* name, TRAPS) = 0;
55 // Debugging
56 NOT_PRODUCT(virtual void compile_the_world(Handle loader, TRAPS) = 0;)
57 NOT_PRODUCT(virtual bool is_jrt() = 0;)
58 };
59
60
61 class ClassPathDirEntry: public ClassPathEntry {
62 private:
63 const char* _dir; // Name of directory
64 public:
65 bool is_jar_file() { return false; }
66 const char* name() { return _dir; }
67 ClassPathDirEntry(const char* dir);
68 ClassFileStream* open_stream(const char* name, TRAPS);
69 // Debugging
87
88
89 class ClassPathZipEntry: public ClassPathEntry {
90 private:
91 jzfile* _zip; // The zip archive
92 const char* _zip_name; // Name of zip archive
93 public:
94 bool is_jar_file() { return true; }
95 const char* name() { return _zip_name; }
96 ClassPathZipEntry(jzfile* zip, const char* zip_name);
97 ~ClassPathZipEntry();
98 u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
99 ClassFileStream* open_stream(const char* name, TRAPS);
100 void contents_do(void f(const char* name, void* context), void* context);
101 // Debugging
102 NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
103 NOT_PRODUCT(bool is_jrt();)
104 };
105
106
107 // For java image files
108 class ImageFile;
109 class ClassPathImageEntry: public ClassPathEntry {
110 private:
111 ImageFile *_image;
112 public:
113 bool is_jar_file() { return false; }
114 bool is_open() { return _image != NULL; }
115 const char* name();
116 ClassPathImageEntry(char* name);
117 ~ClassPathImageEntry();
118 ClassFileStream* open_stream(const char* name, TRAPS);
119
120 // Debugging
121 NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
122 NOT_PRODUCT(bool is_jrt();)
123 };
124
125 class PackageHashtable;
126 class PackageInfo;
127 class SharedPathsMiscInfo;
128 template <MEMFLAGS F> class HashtableBucket;
129
130 class ClassLoader: AllStatic {
131 public:
132 enum SomeConstants {
133 package_hash_table_size = 31 // Number of buckets
134 };
135 protected:
136
137 // Performance counters
138 static PerfCounter* _perf_accumulated_time;
139 static PerfCounter* _perf_classes_inited;
140 static PerfCounter* _perf_class_init_time;
141 static PerfCounter* _perf_class_init_selftime;
142 static PerfCounter* _perf_classes_verified;
143 static PerfCounter* _perf_class_verify_time;
144 static PerfCounter* _perf_class_verify_selftime;
145 static PerfCounter* _perf_classes_linked;
146 static PerfCounter* _perf_class_link_time;
147 static PerfCounter* _perf_class_link_selftime;
148 static PerfCounter* _perf_class_parse_time;
149 static PerfCounter* _perf_class_parse_selftime;
150 static PerfCounter* _perf_sys_class_lookup_time;
151 static PerfCounter* _perf_shared_classload_time;
152 static PerfCounter* _perf_sys_classload_time;
153 static PerfCounter* _perf_app_classload_time;
154 static PerfCounter* _perf_app_classload_selftime;
155 static PerfCounter* _perf_app_classload_count;
180 static const char* _shared_archive;
181
182 // Info used by CDS
183 CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;)
184
185 // Hash function
186 static unsigned int hash(const char *s, int n);
187 // Returns the package file name corresponding to the specified package
188 // or class name, or null if not found.
189 static PackageInfo* lookup_package(const char *pkgname);
190 // Adds a new package entry for the specified class or package name and
191 // corresponding directory or jar file name.
192 static bool add_package(const char *pkgname, int classpath_index, TRAPS);
193
194 // Initialization
195 static void setup_bootstrap_search_path();
196 static void setup_search_path(const char *class_path);
197
198 static void load_zip_library();
199 static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st,
200 bool throw_exception, TRAPS);
201
202 // Canonicalizes path names, so strcmp will work properly. This is mainly
203 // to avoid confusing the zip library
204 static bool get_canonical_path(const char* orig, char* out, int len);
205 public:
206 static jboolean decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg);
207 static int crc32(int crc, const char* buf, int len);
208 static bool update_class_path_entry_list(const char *path,
209 bool check_for_duplicates,
210 bool throw_exception=true);
211 static void print_bootclasspath();
212
213 // Timing
214 static PerfCounter* perf_accumulated_time() { return _perf_accumulated_time; }
215 static PerfCounter* perf_classes_inited() { return _perf_classes_inited; }
216 static PerfCounter* perf_class_init_time() { return _perf_class_init_time; }
217 static PerfCounter* perf_class_init_selftime() { return _perf_class_init_selftime; }
218 static PerfCounter* perf_classes_verified() { return _perf_classes_verified; }
219 static PerfCounter* perf_class_verify_time() { return _perf_class_verify_time; }
220 static PerfCounter* perf_class_verify_selftime() { return _perf_class_verify_selftime; }
|