Mercurial > hg > truffle
changeset 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 | 14b8221771dc d2c5fee67143 |
files | src/share/vm/classfile/classFileStream.cpp src/share/vm/classfile/classFileStream.hpp src/share/vm/classfile/classLoader.cpp src/share/vm/classfile/classLoader.hpp src/share/vm/classfile/classLoaderExt.hpp src/share/vm/classfile/sharedPathsMiscInfo.cpp src/share/vm/classfile/sharedPathsMiscInfo.hpp src/share/vm/classfile/systemDictionary.cpp |
diffstat | 8 files changed, 49 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/vm/classfile/classFileStream.cpp Thu Aug 21 13:57:51 2014 -0700 +++ b/src/share/vm/classfile/classFileStream.cpp Tue Sep 02 14:02:57 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;
--- a/src/share/vm/classfile/classFileStream.hpp Thu Aug 21 13:57:51 2014 -0700 +++ b/src/share/vm/classfile/classFileStream.hpp Tue Sep 02 14:02:57 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 @@ -53,20 +53,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) {
--- 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 {
--- a/src/share/vm/classfile/classLoader.hpp Thu Aug 21 13:57:51 2014 -0700 +++ b/src/share/vm/classfile/classLoader.hpp Tue Sep 02 14:02:57 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; } @@ -123,7 +123,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; @@ -133,7 +133,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); u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS); ClassFileStream* open_stream(const char* name, TRAPS); void set_meta_index(MetaIndex* meta_index) { _meta_index = meta_index; } @@ -218,17 +218,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();
--- a/src/share/vm/classfile/classLoaderExt.hpp Thu Aug 21 13:57:51 2014 -0700 +++ b/src/share/vm/classfile/classLoaderExt.hpp Tue Sep 02 14:02:57 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() {}
--- a/src/share/vm/classfile/sharedPathsMiscInfo.cpp Thu Aug 21 13:57:51 2014 -0700 +++ b/src/share/vm/classfile/sharedPathsMiscInfo.cpp Tue Sep 02 14:02:57 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"); } }
--- a/src/share/vm/classfile/sharedPathsMiscInfo.hpp Thu Aug 21 13:57:51 2014 -0700 +++ b/src/share/vm/classfile/sharedPathsMiscInfo.hpp Tue Sep 02 14:02:57 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();
--- a/src/share/vm/classfile/systemDictionary.cpp Thu Aug 21 13:57:51 2014 -0700 +++ b/src/share/vm/classfile/systemDictionary.cpp Tue Sep 02 14:02:57 2014 -0700 @@ -1244,7 +1244,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)) { @@ -1253,7 +1252,6 @@ classlist_file->flush(); } } -#endif // notify a class loaded from shared object ClassLoadingService::notify_class_loaded(InstanceKlass::cast(ik()), @@ -1261,7 +1259,7 @@ } return ik; } -#endif +#endif // INCLUDE_CDS instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) { instanceKlassHandle nh = instanceKlassHandle(); // null Handle