src/share/vm/classfile/classLoader.cpp
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File
*** old/src/share/vm/classfile/classLoader.cpp Thu Feb 12 09:40:24 2015
--- new/src/share/vm/classfile/classLoader.cpp Thu Feb 12 09:40:23 2015
*** 1,7 ****
--- 1,7 ----
/*
! * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
! * Copyright (c) 1997, 2015, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 150,193 ****
--- 150,159 ----
}
return (strncmp(str + (str_len - str_to_find_len), str_to_find, str_to_find_len) == 0);
}
MetaIndex::MetaIndex(char** meta_package_names, int num_meta_package_names) {
if (num_meta_package_names == 0) {
_meta_package_names = NULL;
_num_meta_package_names = 0;
} else {
_meta_package_names = NEW_C_HEAP_ARRAY(char*, num_meta_package_names, mtClass);
_num_meta_package_names = num_meta_package_names;
memcpy(_meta_package_names, meta_package_names, num_meta_package_names * sizeof(char*));
}
}
MetaIndex::~MetaIndex() {
FREE_C_HEAP_ARRAY(char*, _meta_package_names);
}
bool MetaIndex::may_contain(const char* class_name) {
if ( _num_meta_package_names == 0) {
return false;
}
size_t class_name_len = strlen(class_name);
for (int i = 0; i < _num_meta_package_names; i++) {
char* pkg = _meta_package_names[i];
size_t pkg_len = strlen(pkg);
size_t min_len = MIN2(class_name_len, pkg_len);
if (!strncmp(class_name, pkg, min_len)) {
return true;
}
}
return false;
}
ClassPathEntry::ClassPathEntry() {
set_next(NULL);
}
*** 313,323 ****
--- 279,288 ----
}
LazyClassPathEntry::LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception) : ClassPathEntry() {
_path = os::strdup_check_oom(path);
_st = *st;
_meta_index = NULL;
_resolved_entry = NULL;
_has_error = false;
_throw_exception = throw_exception;
}
*** 352,365 ****
--- 317,326 ----
delete new_entry;
return (ClassPathEntry*) _resolved_entry;
}
ClassFileStream* LazyClassPathEntry::open_stream(const char* name, TRAPS) {
if (_meta_index != NULL &&
!_meta_index->may_contain(name)) {
return NULL;
}
if (_has_error) {
return NULL;
}
ClassPathEntry* cpe = resolve_entry(THREAD);
if (cpe == NULL) {
*** 461,480 ****
--- 422,431 ----
bool ClassPathImageEntry::is_jrt() {
return string_ends_with(name(), "bootmodules.jimage");
}
#endif
static void print_meta_index(LazyClassPathEntry* entry,
GrowableArray<char*>& meta_packages) {
tty->print("[Meta index for %s=", entry->name());
for (int i = 0; i < meta_packages.length(); i++) {
if (i > 0) tty->print(" ");
tty->print("%s", meta_packages.at(i));
}
tty->print_cr("]");
}
#if INCLUDE_CDS
void ClassLoader::exit_with_path_failure(const char* error, const char* message) {
assert(DumpSharedSpaces, "only called at dump time");
tty->print_cr("Hint: enable -XX:+TraceClassPaths to diagnose the failure");
vm_exit_during_initialization(error, message);
*** 506,632 ****
--- 457,466 ----
} else {
tty->cr();
}
}
void ClassLoader::setup_bootstrap_meta_index() {
// Set up meta index which allows us to open boot jars lazily if
// class data sharing is enabled
const char* meta_index_path = Arguments::get_meta_index_path();
const char* meta_index_dir = Arguments::get_meta_index_dir();
setup_meta_index(meta_index_path, meta_index_dir, 0);
}
void ClassLoader::setup_meta_index(const char* meta_index_path, const char* meta_index_dir, int start_index) {
const char* known_version = "% VERSION 2";
FILE* file = fopen(meta_index_path, "r");
int line_no = 0;
#if INCLUDE_CDS
if (DumpSharedSpaces) {
if (file != NULL) {
_shared_paths_misc_info->add_required_file(meta_index_path);
} else {
_shared_paths_misc_info->add_nonexist_path(meta_index_path);
}
}
#endif
if (file != NULL) {
ResourceMark rm;
LazyClassPathEntry* cur_entry = NULL;
GrowableArray<char*> boot_class_path_packages(10);
char package_name[256];
bool skipCurrentJar = false;
while (fgets(package_name, sizeof(package_name), file) != NULL) {
++line_no;
// Remove trailing newline
package_name[strlen(package_name) - 1] = '\0';
switch(package_name[0]) {
case '%':
{
if ((line_no == 1) && (strcmp(package_name, known_version) != 0)) {
if (TraceClassLoading && Verbose) {
tty->print("[Unsupported meta index version]");
}
fclose(file);
return;
}
}
// These directives indicate jar files which contain only
// classes, only non-classfile resources, or a combination of
// the two. See src/share/classes/sun/misc/MetaIndex.java and
// make/tools/MetaIndex/BuildMetaIndex.java in the J2SE
// workspace.
case '#':
case '!':
case '@':
{
// Hand off current packages to current lazy entry (if any)
if ((cur_entry != NULL) &&
(boot_class_path_packages.length() > 0)) {
if ((TraceClassLoading || TraceClassPaths) && Verbose) {
print_meta_index(cur_entry, boot_class_path_packages);
}
MetaIndex* index = new MetaIndex(boot_class_path_packages.adr_at(0),
boot_class_path_packages.length());
cur_entry->set_meta_index(index);
}
cur_entry = NULL;
boot_class_path_packages.clear();
// Find lazy entry corresponding to this jar file
int count = 0;
for (ClassPathEntry* entry = _first_entry; entry != NULL; entry = entry->next(), count++) {
if (count >= start_index &&
entry->is_lazy() &&
string_starts_with(entry->name(), meta_index_dir) &&
string_ends_with(entry->name(), &package_name[2])) {
cur_entry = (LazyClassPathEntry*) entry;
break;
}
}
// If the first character is '@', it indicates the following jar
// file is a resource only jar file in which case, we should skip
// reading the subsequent entries since the resource loading is
// totally handled by J2SE side.
if (package_name[0] == '@') {
if (cur_entry != NULL) {
cur_entry->set_meta_index(new MetaIndex(NULL, 0));
}
cur_entry = NULL;
skipCurrentJar = true;
} else {
skipCurrentJar = false;
}
break;
}
default:
{
if (!skipCurrentJar && cur_entry != NULL) {
char* new_name = os::strdup_check_oom(package_name);
boot_class_path_packages.append(new_name);
}
}
}
}
// Hand off current packages to current lazy entry (if any)
if ((cur_entry != NULL) &&
(boot_class_path_packages.length() > 0)) {
if ((TraceClassLoading || TraceClassPaths) && Verbose) {
print_meta_index(cur_entry, boot_class_path_packages);
}
MetaIndex* index = new MetaIndex(boot_class_path_packages.adr_at(0),
boot_class_path_packages.length());
cur_entry->set_meta_index(index);
}
fclose(file);
}
}
#if INCLUDE_CDS
void ClassLoader::check_shared_classpath(const char *path) {
if (strcmp(path, "") == 0) {
exit_with_path_failure("Cannot have empty path in archived classpaths", NULL);
}
*** 1313,1326 ****
--- 1147,1156 ----
if (DumpSharedSpaces) {
_shared_paths_misc_info = SharedClassUtil::allocate_shared_paths_misc_info();
}
#endif
setup_bootstrap_search_path();
if (LazyBootClassLoader) {
// set up meta index which makes boot classpath initialization lazier
setup_bootstrap_meta_index();
}
}
#if INCLUDE_CDS
void ClassLoader::initialize_shared_path() {
if (DumpSharedSpaces) {
src/share/vm/classfile/classLoader.cpp
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File