# HG changeset patch # User iklam # Date 1409676684 25200 # Node ID 25abc4a3285c7750c71b8684c92d9c5b462de581 # Parent 16ac9bcf600a09b803126440a01a28f6124c9a1a 8056971: Minor class loading clean-up Summary: Misplacement of #if INCLUE_CDS, typos, unnecessary C string duplication Reviewed-by: dholmes, ccheung diff -r 16ac9bcf600a -r 25abc4a3285c hotspot/src/share/vm/classfile/classFileStream.cpp --- a/hotspot/src/share/vm/classfile/classFileStream.cpp Fri Aug 29 11:35:03 2014 -0700 +++ b/hotspot/src/share/vm/classfile/classFileStream.cpp Tue Sep 02 09:51:24 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,7 +30,7 @@ THROW_MSG(vmSymbols::java_lang_ClassFormatError(), "Truncated class file"); } -ClassFileStream::ClassFileStream(u1* buffer, int length, char* source) { +ClassFileStream::ClassFileStream(u1* buffer, int length, const char* source) { _buffer_start = buffer; _buffer_end = buffer + length; _current = buffer; diff -r 16ac9bcf600a -r 25abc4a3285c hotspot/src/share/vm/classfile/classFileStream.hpp --- a/hotspot/src/share/vm/classfile/classFileStream.hpp Fri Aug 29 11:35:03 2014 -0700 +++ b/hotspot/src/share/vm/classfile/classFileStream.hpp Tue Sep 02 09:51:24 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -39,20 +39,20 @@ u1* _buffer_start; // Buffer bottom u1* _buffer_end; // Buffer top (one past last element) u1* _current; // Current buffer position - char* _source; // Source of stream (directory name, ZIP/JAR archive name) + const char* _source; // Source of stream (directory name, ZIP/JAR archive name) bool _need_verify; // True if verification is on for the class file void truncated_file_error(TRAPS); public: // Constructor - ClassFileStream(u1* buffer, int length, char* source); + ClassFileStream(u1* buffer, int length, const char* source); // Buffer access u1* buffer() const { return _buffer_start; } int length() const { return _buffer_end - _buffer_start; } u1* current() const { return _current; } void set_current(u1* pos) { _current = pos; } - char* source() const { return _source; } + const char* source() const { return _source; } void set_verify(bool flag) { _need_verify = flag; } void check_truncated_file(bool b, TRAPS) { diff -r 16ac9bcf600a -r 25abc4a3285c hotspot/src/share/vm/classfile/classLoader.cpp --- 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 { diff -r 16ac9bcf600a -r 25abc4a3285c hotspot/src/share/vm/classfile/classLoader.hpp --- a/hotspot/src/share/vm/classfile/classLoader.hpp Fri Aug 29 11:35:03 2014 -0700 +++ b/hotspot/src/share/vm/classfile/classLoader.hpp Tue Sep 02 09:51:24 2014 -0700 @@ -72,11 +72,11 @@ class ClassPathDirEntry: public ClassPathEntry { private: - char* _dir; // Name of directory + const char* _dir; // Name of directory public: bool is_jar_file() { return false; } const char* name() { return _dir; } - ClassPathDirEntry(char* dir); + ClassPathDirEntry(const char* dir); ClassFileStream* open_stream(const char* name, TRAPS); // Debugging NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);) @@ -100,8 +100,8 @@ class ClassPathZipEntry: public ClassPathEntry { private: - jzfile* _zip; // The zip archive - char* _zip_name; // Name of zip archive + jzfile* _zip; // The zip archive + const char* _zip_name; // Name of zip archive public: bool is_jar_file() { return true; } const char* name() { return _zip_name; } @@ -119,7 +119,7 @@ // For lazier loading of boot class path entries class LazyClassPathEntry: public ClassPathEntry { private: - char* _path; // dir or file + const char* _path; // dir or file struct stat _st; MetaIndex* _meta_index; bool _has_error; @@ -129,7 +129,7 @@ public: bool is_jar_file(); const char* name() { return _path; } - LazyClassPathEntry(char* path, const struct stat* st, bool throw_exception); + LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception); virtual ~LazyClassPathEntry(); u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS); @@ -216,17 +216,17 @@ static void setup_meta_index(const char* meta_index_path, const char* meta_index_dir, int start_index); static void setup_bootstrap_search_path(); - static void setup_search_path(char *class_path); + static void setup_search_path(const char *class_path); static void load_zip_library(); - static ClassPathEntry* create_class_path_entry(char *path, const struct stat* st, + static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st, bool lazy, bool throw_exception, TRAPS); // Canonicalizes path names, so strcmp will work properly. This is mainly // to avoid confusing the zip library - static bool get_canonical_path(char* orig, char* out, int len); + static bool get_canonical_path(const char* orig, char* out, int len); public: - static bool update_class_path_entry_list(char *path, + static bool update_class_path_entry_list(const char *path, bool check_for_duplicates, bool throw_exception=true); static void print_bootclasspath(); diff -r 16ac9bcf600a -r 25abc4a3285c hotspot/src/share/vm/classfile/classLoaderExt.hpp --- a/hotspot/src/share/vm/classfile/classLoaderExt.hpp Fri Aug 29 11:35:03 2014 -0700 +++ b/hotspot/src/share/vm/classfile/classLoaderExt.hpp Tue Sep 02 09:51:24 2014 -0700 @@ -59,8 +59,8 @@ }; - static void add_class_path_entry(char* path, bool check_for_duplicates, - ClassPathEntry* new_entry) { + static void add_class_path_entry(const char* path, bool check_for_duplicates, + ClassPathEntry* new_entry) { ClassLoader::add_to_list(new_entry); } static void setup_search_paths() {} diff -r 16ac9bcf600a -r 25abc4a3285c hotspot/src/share/vm/classfile/sharedPathsMiscInfo.cpp --- a/hotspot/src/share/vm/classfile/sharedPathsMiscInfo.cpp Fri Aug 29 11:35:03 2014 -0700 +++ b/hotspot/src/share/vm/classfile/sharedPathsMiscInfo.cpp Tue Sep 02 09:51:24 2014 -0700 @@ -139,7 +139,7 @@ if (timestamp != st.st_mtime) { return fail("Timestamp mismatch"); } - if (filesize != st.st_size) { + if (filesize != st.st_size) { return fail("File size mismatch"); } } diff -r 16ac9bcf600a -r 25abc4a3285c hotspot/src/share/vm/classfile/sharedPathsMiscInfo.hpp --- a/hotspot/src/share/vm/classfile/sharedPathsMiscInfo.hpp Fri Aug 29 11:35:03 2014 -0700 +++ b/hotspot/src/share/vm/classfile/sharedPathsMiscInfo.hpp Tue Sep 02 09:51:24 2014 -0700 @@ -165,7 +165,7 @@ out->print("Expecting that %s does not exist", path); break; case REQUIRED: - out->print("Expecting that file %s must exist and not altered", path); + out->print("Expecting that file %s must exist and is not altered", path); break; default: ShouldNotReachHere(); diff -r 16ac9bcf600a -r 25abc4a3285c hotspot/src/share/vm/classfile/systemDictionary.cpp --- a/hotspot/src/share/vm/classfile/systemDictionary.cpp Fri Aug 29 11:35:03 2014 -0700 +++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp Tue Sep 02 09:51:24 2014 -0700 @@ -1243,7 +1243,6 @@ tty->print_cr("]"); } -#if INCLUDE_CDS if (DumpLoadedClassList != NULL && classlist_file->is_open()) { // Only dump the classes that can be stored into CDS archive if (SystemDictionaryShared::is_sharing_possible(loader_data)) { @@ -1252,7 +1251,6 @@ classlist_file->flush(); } } -#endif // notify a class loaded from shared object ClassLoadingService::notify_class_loaded(InstanceKlass::cast(ik()), @@ -1260,7 +1258,7 @@ } return ik; } -#endif +#endif // INCLUDE_CDS instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) { instanceKlassHandle nh = instanceKlassHandle(); // null Handle