--- a/hotspot/src/share/vm/classfile/classLoader.cpp Fri Aug 29 11:35:03 2014 -0700
+++ b/hotspot/src/share/vm/classfile/classLoader.cpp Tue Sep 02 09:51:24 2014 -0700
@@ -189,9 +189,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;
}
@@ -235,8 +236,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() {
@@ -304,7 +306,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 = os::strdup_check_oom(path);
_st = *st;
_meta_index = NULL;
@@ -314,7 +316,7 @@
}
LazyClassPathEntry::~LazyClassPathEntry() {
- os::free(_path);
+ os::free((void*)_path);
}
bool LazyClassPathEntry::is_jar_file() {
@@ -563,17 +565,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_check_oom(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
@@ -593,7 +597,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;
@@ -620,7 +624,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) {
@@ -687,11 +691,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;
{
@@ -737,7 +738,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;
@@ -762,8 +763,8 @@
if (DumpSharedSpaces) {
_shared_paths_misc_info->add_nonexist_path(path);
}
+#endif
return false;
-#endif
}
}
@@ -1269,11 +1270,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 {