Skip to content

Commit

Permalink
[EagerAppCDS] 1. fix strlen usage 2. change the impl of bootclasspath…
Browse files Browse the repository at this point in the history
… check in cds

Summary: 1. strlen: conversion from 'size_t' to 'int', possible loss of data
2. change the impl of checking boot classpath value when replaying in cds

Test Plan: windows build
           ci jtreg cds

Reviewed-by: lei.yul, lingjun-cg

Issue: dragonwell-project#559

CR:
  • Loading branch information
jia-wei-tang committed Jul 14, 2023
1 parent 2d8d64e commit 3b4fdc4
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 77 deletions.
2 changes: 1 addition & 1 deletion hotspot/src/share/vm/classfile/classLoaderExt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ClassLoaderExt: public ClassLoader { // AllStatic
static void append_boot_classpath(ClassPathEntry* new_entry) {
#if INCLUDE_CDS
if (UseAppCDS) {
if (CDSIgnoreBootClasspathAppend) {
if (CDSIgnoreBootClasspathDiff) {
warning("AppCDS is still enabled, but bootstrap classpath has been appended");
} else {
warning("UseAppCDS is disabled because bootstrap classpath has been appended");
Expand Down
40 changes: 2 additions & 38 deletions hotspot/src/share/vm/classfile/sharedClassUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@
#include "runtime/java.hpp"
#include "runtime/os.hpp"

AgentEntry* SharedClassUtil::_agentlib_head = NULL;
AgentEntry* SharedClassUtil::_agentlib_tail = NULL;

AgentEntry::AgentEntry(const char* name) {
char* copy = NEW_C_HEAP_ARRAY(char, strlen(name)+1, mtInternal);
strcpy(copy, name);
_name = copy;
_next = NULL;
}

AgentEntry::~AgentEntry() {
FREE_C_HEAP_ARRAY(char, _name, mtInternal);
}

class ManifestStream: public ResourceObj {
private:
Expand Down Expand Up @@ -151,9 +138,9 @@ ClassPathSegment* SharedPathsMiscInfoExt::to_sorted_segments(const char* path, i
}
ClassPathSegment *cps = NEW_RESOURCE_ARRAY(ClassPathSegment, max_seg_num + 1);

int len = strlen(path);
size_t len = strlen(path);
//not use i < len,but use i<= len for processing the last segment conveniently
for (int i = 0, j = 0; i <= len; i++) {
for (uint i = 0, j = 0; i <= len; i++) {
if (i == len || path[i] == os::path_separator()[0]) {
//i == j mean a empty string
if (i != j) {
Expand Down Expand Up @@ -229,29 +216,6 @@ bool SharedPathsMiscInfoExt::check(jint type, const char* path) {
return true;
}

void SharedClassUtil::append_lib_in_bootclasspath(const char* path) {
if(*path == '\0') return;
AgentEntry* agent_entry = new AgentEntry(path);
if (_agentlib_head == NULL) {
_agentlib_head = agent_entry;
_agentlib_tail = agent_entry;
} else {
_agentlib_tail->set_next(agent_entry);
_agentlib_tail = agent_entry;
}
}

bool SharedClassUtil::is_appended_boot_cp(const char* path, int len) {
AgentEntry* e = _agentlib_head;
while(e != NULL) {
if (strncmp(e->name(), path, len) == 0) {
return true;
}
e = e->next();
}
return false;
}

void SharedClassUtil::update_shared_classpath(ClassPathEntry *cpe, SharedClassPathEntry* e,
time_t timestamp, long filesize, TRAPS) {
e->_timestamp = timestamp;
Expand Down
19 changes: 0 additions & 19 deletions hotspot/src/share/vm/classfile/sharedClassUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,9 @@ class SharedClassPathEntryExt: public SharedClassPathEntry {
}
};

class AgentEntry: public CHeapObj<mtInternal> {
private:
char* _name;
AgentEntry* _next;
public:
const char* name() { return _name; }
AgentEntry* next() { return _next; }
AgentEntry(const char* name);
void set_next(AgentEntry* entry) {
_next = entry;
}
~AgentEntry();
};

class SharedClassUtil : AllStatic {
private:
static AgentEntry* _agentlib_head;
static AgentEntry* _agentlib_tail;
public:
static void append_lib_in_bootclasspath(const char* path);
static bool is_appended_boot_cp(const char* path, int len);

static SharedPathsMiscInfo* allocate_shared_paths_misc_info() {
return new SharedPathsMiscInfoExt();
}
Expand Down
20 changes: 4 additions & 16 deletions hotspot/src/share/vm/classfile/sharedPathsMiscInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,11 @@ bool SharedPathsMiscInfo::check(jint type, const char* path) {
switch (type) {
case BOOT:
if (strcmp(path, Arguments::get_sysclasspath()) != 0) {
char* sys_cp = Arguments::get_sysclasspath();
int path_len = strlen(path);
int sys_cp_len = strlen(sys_cp);
if(path_len >= sys_cp_len || strncmp(path, sys_cp, path_len) != 0 || !EagerAppCDS || !CDSIgnoreBootClasspathAppend) {
return fail("[BOOT classpath mismatch, actual: -Dsun.boot.class.path=", sys_cp);
if(!EagerAppCDS || !CDSIgnoreBootClasspathDiff) {
return fail("[BOOT classpath mismatch, actual: -Dsun.boot.class.path=", Arguments::get_sysclasspath());
} else {
int start = path_len;
int end = start + 1;
while(end <= sys_cp_len) {
if(end == sys_cp_len || sys_cp[end] == os::path_separator()[0]) {
if (!SharedClassUtil::is_appended_boot_cp(sys_cp + start + 1, end - start - 1)) {
return fail("[BOOT classpath mismatch, actual: -Dsun.boot.class.path=", sys_cp);
}
}
start = end;
end++;
}
warning("The Boot classpath is different from the one used in profiling.");
return true;
}
}
break;
Expand Down
2 changes: 0 additions & 2 deletions hotspot/src/share/vm/prims/jvmtiEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ JvmtiEnv::AddToBootstrapClassLoaderSearch(const char* segment) {
jvmtiPhase phase = get_phase();
if (phase == JVMTI_PHASE_ONLOAD) {
Arguments::append_sysclasspath(segment);
SharedClassUtil::append_lib_in_bootclasspath(segment);
return JVMTI_ERROR_NONE;
} else if (use_version_1_0_semantics()) {
// This JvmtiEnv requested version 1.0 semantics and this function
Expand Down Expand Up @@ -479,7 +478,6 @@ JvmtiEnv::AddToBootstrapClassLoaderSearch(const char* segment) {
tty->print_cr("[Opened %s]", zip_entry->name());
}
ClassLoaderExt::append_boot_classpath(zip_entry);
SharedClassUtil::append_lib_in_bootclasspath(segment);
return JVMTI_ERROR_NONE;
} else {
return JVMTI_ERROR_WRONG_PHASE;
Expand Down
2 changes: 1 addition & 1 deletion hotspot/src/share/vm/runtime/globals_ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
\
product(bool, IgnoreAppCDSDirCheck, false, \
"Ignore non-empty dir check in AppCDS") \
product(bool, CDSIgnoreBootClasspathAppend, false, \
product(bool, CDSIgnoreBootClasspathDiff, false, \
"keep AppCDS on after appending boot classpath") \
\
product(bool, SuppressAppCDSErrors, false, \
Expand Down

0 comments on commit 3b4fdc4

Please sign in to comment.