Mercurial > hg > truffle
comparison src/share/vm/classfile/classLoader.cpp @ 20376:bb239308be67
8056971: Minor class loading clean-up
Summary: Misplacement of #if INCLUE_CDS, typos, unnecessary C string duplication
Reviewed-by: dholmes, ccheung
author | iklam |
---|---|
date | Tue, 02 Sep 2014 14:02:57 -0700 |
parents | 6e0cb14ce59b |
children | 2e6106d44079 8cb56c8cb30d |
comparison
equal
deleted
inserted
replaced
20375:6e0cb14ce59b | 20376:bb239308be67 |
---|---|
202 | 202 |
203 bool ClassPathEntry::is_lazy() { | 203 bool ClassPathEntry::is_lazy() { |
204 return false; | 204 return false; |
205 } | 205 } |
206 | 206 |
207 ClassPathDirEntry::ClassPathDirEntry(char* dir) : ClassPathEntry() { | 207 ClassPathDirEntry::ClassPathDirEntry(const char* dir) : ClassPathEntry() { |
208 _dir = NEW_C_HEAP_ARRAY(char, strlen(dir)+1, mtClass); | 208 char* copy = NEW_C_HEAP_ARRAY(char, strlen(dir)+1, mtClass); |
209 strcpy(_dir, dir); | 209 strcpy(copy, dir); |
210 _dir = copy; | |
210 } | 211 } |
211 | 212 |
212 | 213 |
213 ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) { | 214 ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) { |
214 // construct full path name | 215 // construct full path name |
248 } | 249 } |
249 | 250 |
250 | 251 |
251 ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name) : ClassPathEntry() { | 252 ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name) : ClassPathEntry() { |
252 _zip = zip; | 253 _zip = zip; |
253 _zip_name = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1, mtClass); | 254 char *copy = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1, mtClass); |
254 strcpy(_zip_name, zip_name); | 255 strcpy(copy, zip_name); |
256 _zip_name = copy; | |
255 } | 257 } |
256 | 258 |
257 ClassPathZipEntry::~ClassPathZipEntry() { | 259 ClassPathZipEntry::~ClassPathZipEntry() { |
258 if (ZipClose != NULL) { | 260 if (ZipClose != NULL) { |
259 (*ZipClose)(_zip); | 261 (*ZipClose)(_zip); |
317 if (ze == NULL) break; | 319 if (ze == NULL) break; |
318 (*f)(ze->name, context); | 320 (*f)(ze->name, context); |
319 } | 321 } |
320 } | 322 } |
321 | 323 |
322 LazyClassPathEntry::LazyClassPathEntry(char* path, const struct stat* st, bool throw_exception) : ClassPathEntry() { | 324 LazyClassPathEntry::LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception) : ClassPathEntry() { |
323 _path = strdup(path); | 325 _path = strdup(path); |
324 _st = *st; | 326 _st = *st; |
325 _meta_index = NULL; | 327 _meta_index = NULL; |
326 _resolved_entry = NULL; | 328 _resolved_entry = NULL; |
327 _has_error = false; | 329 _has_error = false; |
572 } | 574 } |
573 #endif | 575 #endif |
574 | 576 |
575 void ClassLoader::setup_bootstrap_search_path() { | 577 void ClassLoader::setup_bootstrap_search_path() { |
576 assert(_first_entry == NULL, "should not setup bootstrap class search path twice"); | 578 assert(_first_entry == NULL, "should not setup bootstrap class search path twice"); |
577 char* sys_class_path = os::strdup(Arguments::get_sysclasspath()); | 579 const char* sys_class_path = Arguments::get_sysclasspath(); |
578 if (!PrintSharedArchiveAndExit) { | 580 if (PrintSharedArchiveAndExit) { |
581 // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily | |
582 // the same as the bootcp of the shared archive. | |
583 } else { | |
579 trace_class_path("[Bootstrap loader class path=", sys_class_path); | 584 trace_class_path("[Bootstrap loader class path=", sys_class_path); |
580 } | 585 } |
581 #if INCLUDE_CDS | 586 #if INCLUDE_CDS |
582 if (DumpSharedSpaces) { | 587 if (DumpSharedSpaces) { |
583 _shared_paths_misc_info->add_boot_classpath(Arguments::get_sysclasspath()); | 588 _shared_paths_misc_info->add_boot_classpath(sys_class_path); |
584 } | 589 } |
585 #endif | 590 #endif |
586 setup_search_path(sys_class_path); | 591 setup_search_path(sys_class_path); |
587 os::free(sys_class_path); | |
588 } | 592 } |
589 | 593 |
590 #if INCLUDE_CDS | 594 #if INCLUDE_CDS |
591 int ClassLoader::get_shared_paths_misc_info_size() { | 595 int ClassLoader::get_shared_paths_misc_info_size() { |
592 return _shared_paths_misc_info->get_used_bytes(); | 596 return _shared_paths_misc_info->get_used_bytes(); |
602 delete checker; | 606 delete checker; |
603 return result; | 607 return result; |
604 } | 608 } |
605 #endif | 609 #endif |
606 | 610 |
607 void ClassLoader::setup_search_path(char *class_path) { | 611 void ClassLoader::setup_search_path(const char *class_path) { |
608 int offset = 0; | 612 int offset = 0; |
609 int len = (int)strlen(class_path); | 613 int len = (int)strlen(class_path); |
610 int end = 0; | 614 int end = 0; |
611 | 615 |
612 // Iterate over class path entries | 616 // Iterate over class path entries |
629 end++; | 633 end++; |
630 } | 634 } |
631 } | 635 } |
632 } | 636 } |
633 | 637 |
634 ClassPathEntry* ClassLoader::create_class_path_entry(char *path, const struct stat* st, | 638 ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const struct stat* st, |
635 bool lazy, bool throw_exception, TRAPS) { | 639 bool lazy, bool throw_exception, TRAPS) { |
636 JavaThread* thread = JavaThread::current(); | 640 JavaThread* thread = JavaThread::current(); |
637 if (lazy) { | 641 if (lazy) { |
638 return new LazyClassPathEntry(path, st, throw_exception); | 642 return new LazyClassPathEntry(path, st, throw_exception); |
639 } | 643 } |
696 ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path) { | 700 ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path) { |
697 // check for a regular file | 701 // check for a regular file |
698 struct stat st; | 702 struct stat st; |
699 if (os::stat(path, &st) == 0) { | 703 if (os::stat(path, &st) == 0) { |
700 if ((st.st_mode & S_IFREG) == S_IFREG) { | 704 if ((st.st_mode & S_IFREG) == S_IFREG) { |
701 char orig_path[JVM_MAXPATHLEN]; | |
702 char canonical_path[JVM_MAXPATHLEN]; | 705 char canonical_path[JVM_MAXPATHLEN]; |
703 | 706 if (get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) { |
704 strcpy(orig_path, path); | |
705 if (get_canonical_path(orig_path, canonical_path, JVM_MAXPATHLEN)) { | |
706 char* error_msg = NULL; | 707 char* error_msg = NULL; |
707 jzfile* zip; | 708 jzfile* zip; |
708 { | 709 { |
709 // enable call to C land | 710 // enable call to C land |
710 JavaThread* thread = JavaThread::current(); | 711 JavaThread* thread = JavaThread::current(); |
746 } | 747 } |
747 _num_entries ++; | 748 _num_entries ++; |
748 } | 749 } |
749 | 750 |
750 // Returns true IFF the file/dir exists and the entry was successfully created. | 751 // Returns true IFF the file/dir exists and the entry was successfully created. |
751 bool ClassLoader::update_class_path_entry_list(char *path, | 752 bool ClassLoader::update_class_path_entry_list(const char *path, |
752 bool check_for_duplicates, | 753 bool check_for_duplicates, |
753 bool throw_exception) { | 754 bool throw_exception) { |
754 struct stat st; | 755 struct stat st; |
755 if (os::stat(path, &st) == 0) { | 756 if (os::stat(path, &st) == 0) { |
756 // File or directory found | 757 // File or directory found |
771 } else { | 772 } else { |
772 #if INCLUDE_CDS | 773 #if INCLUDE_CDS |
773 if (DumpSharedSpaces) { | 774 if (DumpSharedSpaces) { |
774 _shared_paths_misc_info->add_nonexist_path(path); | 775 _shared_paths_misc_info->add_nonexist_path(path); |
775 } | 776 } |
777 #endif | |
776 return false; | 778 return false; |
777 #endif | |
778 } | 779 } |
779 } | 780 } |
780 | 781 |
781 void ClassLoader::print_bootclasspath() { | 782 void ClassLoader::print_bootclasspath() { |
782 ClassPathEntry* e = _first_entry; | 783 ClassPathEntry* e = _first_entry; |
1278 void classLoader_init() { | 1279 void classLoader_init() { |
1279 ClassLoader::initialize(); | 1280 ClassLoader::initialize(); |
1280 } | 1281 } |
1281 | 1282 |
1282 | 1283 |
1283 bool ClassLoader::get_canonical_path(char* orig, char* out, int len) { | 1284 bool ClassLoader::get_canonical_path(const char* orig, char* out, int len) { |
1284 assert(orig != NULL && out != NULL && len > 0, "bad arguments"); | 1285 assert(orig != NULL && out != NULL && len > 0, "bad arguments"); |
1285 if (CanonicalizeEntry != NULL) { | 1286 if (CanonicalizeEntry != NULL) { |
1286 JNIEnv* env = JavaThread::current()->jni_environment(); | 1287 JavaThread* THREAD = JavaThread::current(); |
1287 if ((CanonicalizeEntry)(env, os::native_path(orig), out, len) < 0) { | 1288 JNIEnv* env = THREAD->jni_environment(); |
1289 ResourceMark rm(THREAD); | |
1290 | |
1291 // os::native_path writes into orig_copy | |
1292 char* orig_copy = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(orig)+1); | |
1293 strcpy(orig_copy, orig); | |
1294 if ((CanonicalizeEntry)(env, os::native_path(orig_copy), out, len) < 0) { | |
1288 return false; | 1295 return false; |
1289 } | 1296 } |
1290 } else { | 1297 } else { |
1291 // On JDK 1.2.2 the Canonicalize does not exist, so just do nothing | 1298 // On JDK 1.2.2 the Canonicalize does not exist, so just do nothing |
1292 strncpy(out, orig, len); | 1299 strncpy(out, orig, len); |