Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/hotspot/share/cds/aotClassLocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,7 @@ bool AOTClassLocationConfig::is_valid_classpath_index(int classpath_index, Insta
JavaThread* current = JavaThread::current();
ResourceMark rm(current);
const char* const class_name = ik->name()->as_C_string();
const char* const file_name = ClassLoader::file_name_for_class_name(class_name,
ik->name()->utf8_length());
const char* const file_name = ClassLoader::file_name_for_class_name(ik->name());
if (!zip->has_entry(current, file_name)) {
aot_log_warning(aot)("class %s cannot be archived because it was not defined from %s as claimed",
class_name, zip->name());
Expand Down
7 changes: 2 additions & 5 deletions src/hotspot/share/cds/filemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2091,10 +2091,7 @@ ClassFileStream* FileMapInfo::open_stream_for_jvmti(InstanceKlass* ik, Handle cl
ClassPathEntry* cpe = get_classpath_entry_for_jvmti(path_index, CHECK_NULL);
assert(cpe != nullptr, "must be");

Symbol* name = ik->name();
const char* const class_name = name->as_C_string();
const char* const file_name = ClassLoader::file_name_for_class_name(class_name,
name->utf8_length());
const char* const file_name = ClassLoader::file_name_for_class_name(ik->name());
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
const AOTClassLocation* cl = AOTClassLocationConfig::runtime()->class_location_at(path_index);
ClassFileStream* cfs;
Expand All @@ -2107,7 +2104,7 @@ ClassFileStream* FileMapInfo::open_stream_for_jvmti(InstanceKlass* ik, Handle cl
cfs = cpe->open_stream_for_loader(THREAD, file_name, loader_data);
}
assert(cfs != nullptr, "must be able to read the classfile data of shared classes for built-in loaders.");
log_debug(aot, jvmti)("classfile data for %s [%d: %s] = %d bytes", class_name, path_index,
log_debug(aot, jvmti)("classfile data for %s [%d: %s] = %d bytes", file_name, path_index,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming (hoping) that the exact format of this log is not expected to be important to anyone.

cfs->source(), cfs->length());
return cfs;
}
Expand Down
42 changes: 22 additions & 20 deletions src/hotspot/share/classfile/classLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,21 +986,28 @@ objArrayOop ClassLoader::get_system_packages(TRAPS) {
}

// caller needs ResourceMark
const char* ClassLoader::file_name_for_class_name(const char* class_name,
int class_name_len) {
char* ClassLoader::symbol_name_to_padded_buffer(const Symbol* symbol, int padding_len) {
assert(symbol != nullptr, "invariant");
assert(padding_len >= 0, "invariant");

// Include terminating nul.
int name_len = symbol->utf8_length() + 1;
char* const buffer = NEW_RESOURCE_ARRAY(char, name_len + padding_len);
symbol->as_C_string(buffer, name_len);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoids intermediate copy as happened in previous code.

return buffer;
}

// caller needs ResourceMark
const char* ClassLoader::file_name_for_class_name(const Symbol* class_name) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it's undocumented in the code, I'm assuming that the symbol name is <module>/path/to/ClassName (e.g. "java.base/java/lang/Integer").
This is because all the existing code does is append ".class" to the end.

assert(class_name != nullptr, "invariant");
assert((int)strlen(class_name) == class_name_len, "invariant");

static const char class_suffix[] = ".class";
size_t class_suffix_len = sizeof(class_suffix);

char* const file_name = NEW_RESOURCE_ARRAY(char,
class_name_len +
class_suffix_len); // includes term null

strncpy(file_name, class_name, class_name_len);
strncpy(&file_name[class_name_len], class_suffix, class_suffix_len);
static const int suffix_len = strlen(class_suffix);

// Just suffix length (a trailing nul is already accounted for in the copy).
char* const file_name = symbol_name_to_padded_buffer(class_name, suffix_len);
// Append over existing trailing nul, so need to copy a new one.
strncpy(&file_name[class_name->utf8_length()], class_suffix, suffix_len + 1);
return file_name;
}

Expand Down Expand Up @@ -1081,14 +1088,11 @@ InstanceKlass* ClassLoader::load_class(Symbol* name, PackageEntry* pkg_entry, bo
ResourceMark rm(THREAD);
HandleMark hm(THREAD);

const char* const class_name = name->as_C_string();

EventMarkClassLoading m("Loading class %s", class_name);

const char* const file_name = file_name_for_class_name(class_name,
name->utf8_length());
const char* const file_name = file_name_for_class_name(name);
assert(file_name != nullptr, "invariant");

EventMarkClassLoading m("Loading class %s", file_name);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure what's going on here, so someone needs to check that this looks sane.


// Lookup stream for parsing .class file
ClassFileStream* stream = nullptr;
s2 classpath_index = 0;
Expand Down Expand Up @@ -1347,9 +1351,7 @@ void ClassLoader::record_result(JavaThread* current, InstanceKlass* ik,
assert(classpath_index == -1, "sanity");
}

const char* const class_name = ik->name()->as_C_string();
const char* const file_name = file_name_for_class_name(class_name,
ik->name()->utf8_length());
const char* const file_name = file_name_for_class_name(ik->name());
assert(file_name != nullptr, "invariant");
record_result_for_builtin_loader(checked_cast<s2>(classpath_index), ik, redefined);
}
Expand Down
5 changes: 3 additions & 2 deletions src/hotspot/share/classfile/classLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ class ClassLoader: AllStatic {
// Canonicalizes path names, so strcmp will work properly. This is mainly
// to avoid confusing the zip library
static char* get_canonical_path(const char* orig, Thread* thread);
static const char* file_name_for_class_name(const char* class_name,
int class_name_len);

static char* symbol_name_to_padded_buffer(const Symbol* symbol, int padding_len);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should probably declare this private ...

static const char* file_name_for_class_name(const Symbol* class_name);
static PackageEntry* get_package_entry(Symbol* pkg_name, ClassLoaderData* loader_data);
static int crc32(int crc, const char* buf, int len);
static bool update_class_path_entry_list(JavaThread* current,
Expand Down