提交 9c948df7 编写于 作者: I iklam

8056971: Minor class loading clean-up

Summary: Misplacement of #if INCLUE_CDS, typos, unnecessary C string duplication
Reviewed-by: dholmes, ccheung
上级 1b2cc6ab
/*
* 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 @@ void ClassFileStream::truncated_file_error(TRAPS) {
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;
......
/*
* 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 @@ class ClassFileStream: public ResourceObj {
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) {
......
......@@ -204,9 +204,10 @@ bool ClassPathEntry::is_lazy() {
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 @@ ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) {
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 @@ void ClassPathZipEntry::contents_do(void f(const char* name, void* context), voi
}
}
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::check_shared_classpath(const char *path) {
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 @@ bool ClassLoader::check_shared_paths_misc_info(void *buf, int size) {
}
#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 @@ void ClassLoader::setup_search_path(char *class_path) {
}
}
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 @@ ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path) {
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 @@ void ClassLoader::add_to_list(ClassPathEntry *new_entry) {
}
// 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 @@ bool ClassLoader::update_class_path_entry_list(char *path,
if (DumpSharedSpaces) {
_shared_paths_misc_info->add_nonexist_path(path);
}
return false;
#endif
return false;
}
}
......@@ -1280,11 +1281,17 @@ void classLoader_init() {
}
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 {
......
......@@ -72,11 +72,11 @@ class ClassPathEntry: public CHeapObj<mtClass> {
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 @@ typedef struct {
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 @@ class ClassPathZipEntry: public ClassPathEntry {
// 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 @@ class LazyClassPathEntry: public ClassPathEntry {
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 @@ class ClassLoader: AllStatic {
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();
......
......@@ -59,8 +59,8 @@ public:
};
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() {}
......
......@@ -139,7 +139,7 @@ bool SharedPathsMiscInfo::check(jint type, const char* path) {
if (timestamp != st.st_mtime) {
return fail("Timestamp mismatch");
}
if (filesize != st.st_size) {
if (filesize != st.st_size) {
return fail("File size mismatch");
}
}
......
......@@ -165,7 +165,7 @@ public:
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();
......
......@@ -1244,7 +1244,6 @@ instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik,
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 @@ instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik,
classlist_file->flush();
}
}
#endif
// notify a class loaded from shared object
ClassLoadingService::notify_class_loaded(InstanceKlass::cast(ik()),
......@@ -1261,7 +1259,7 @@ instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik,
}
return ik;
}
#endif
#endif // INCLUDE_CDS
instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
instanceKlassHandle nh = instanceKlassHandle(); // null Handle
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册