Mercurial > hg > truffle
diff 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 |
line wrap: on
line diff
--- a/src/share/vm/classfile/classLoader.cpp Thu Aug 21 13:57:51 2014 -0700 +++ b/src/share/vm/classfile/classLoader.cpp Tue Sep 02 14:02:57 2014 -0700 @@ -204,9 +204,10 @@ return false; } -ClassPathDirEntry::ClassPathDirEntry(char* dir) : ClassPathEntry() { - _dir = NEW_C_HEAP_ARRAY(char, strlen(dir)+1, mtClass); - strcpy(_dir, dir); +ClassPathDirEntry::ClassPathDirEntry(const char* dir) : ClassPathEntry() { + char* copy = NEW_C_HEAP_ARRAY(char, strlen(dir)+1, mtClass); + strcpy(copy, dir); + _dir = copy; } @@ -250,8 +251,9 @@ ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name) : ClassPathEntry() { _zip = zip; - _zip_name = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1, mtClass); - strcpy(_zip_name, zip_name); + char *copy = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1, mtClass); + strcpy(copy, zip_name); + _zip_name = copy; } ClassPathZipEntry::~ClassPathZipEntry() { @@ -319,7 +321,7 @@ } } -LazyClassPathEntry::LazyClassPathEntry(char* path, const struct stat* st, bool throw_exception) : ClassPathEntry() { +LazyClassPathEntry::LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception) : ClassPathEntry() { _path = strdup(path); _st = *st; _meta_index = NULL; @@ -574,17 +576,19 @@ void ClassLoader::setup_bootstrap_search_path() { assert(_first_entry == NULL, "should not setup bootstrap class search path twice"); - char* sys_class_path = os::strdup(Arguments::get_sysclasspath()); - if (!PrintSharedArchiveAndExit) { + const char* sys_class_path = Arguments::get_sysclasspath(); + if (PrintSharedArchiveAndExit) { + // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily + // the same as the bootcp of the shared archive. + } else { trace_class_path("[Bootstrap loader class path=", sys_class_path); } #if INCLUDE_CDS if (DumpSharedSpaces) { - _shared_paths_misc_info->add_boot_classpath(Arguments::get_sysclasspath()); + _shared_paths_misc_info->add_boot_classpath(sys_class_path); } #endif setup_search_path(sys_class_path); - os::free(sys_class_path); } #if INCLUDE_CDS @@ -604,7 +608,7 @@ } #endif -void ClassLoader::setup_search_path(char *class_path) { +void ClassLoader::setup_search_path(const char *class_path) { int offset = 0; int len = (int)strlen(class_path); int end = 0; @@ -631,7 +635,7 @@ } } -ClassPathEntry* ClassLoader::create_class_path_entry(char *path, const struct stat* st, +ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const struct stat* st, bool lazy, bool throw_exception, TRAPS) { JavaThread* thread = JavaThread::current(); if (lazy) { @@ -698,11 +702,8 @@ struct stat st; if (os::stat(path, &st) == 0) { if ((st.st_mode & S_IFREG) == S_IFREG) { - char orig_path[JVM_MAXPATHLEN]; char canonical_path[JVM_MAXPATHLEN]; - - strcpy(orig_path, path); - if (get_canonical_path(orig_path, canonical_path, JVM_MAXPATHLEN)) { + if (get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) { char* error_msg = NULL; jzfile* zip; { @@ -748,7 +749,7 @@ } // Returns true IFF the file/dir exists and the entry was successfully created. -bool ClassLoader::update_class_path_entry_list(char *path, +bool ClassLoader::update_class_path_entry_list(const char *path, bool check_for_duplicates, bool throw_exception) { struct stat st; @@ -773,8 +774,8 @@ if (DumpSharedSpaces) { _shared_paths_misc_info->add_nonexist_path(path); } +#endif return false; -#endif } } @@ -1280,11 +1281,17 @@ } -bool ClassLoader::get_canonical_path(char* orig, char* out, int len) { +bool ClassLoader::get_canonical_path(const char* orig, char* out, int len) { assert(orig != NULL && out != NULL && len > 0, "bad arguments"); if (CanonicalizeEntry != NULL) { - JNIEnv* env = JavaThread::current()->jni_environment(); - if ((CanonicalizeEntry)(env, os::native_path(orig), out, len) < 0) { + JavaThread* THREAD = JavaThread::current(); + JNIEnv* env = THREAD->jni_environment(); + ResourceMark rm(THREAD); + + // os::native_path writes into orig_copy + char* orig_copy = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(orig)+1); + strcpy(orig_copy, orig); + if ((CanonicalizeEntry)(env, os::native_path(orig_copy), out, len) < 0) { return false; } } else {