Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EagerAppCDS] fix bugs related to EagerAppCDS #581

Merged
merged 1 commit into from
Jul 27, 2023
Merged
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
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 @@ -125,7 +125,7 @@
experimental(bool, UseWispMonitor, false, \
"yields to next coroutine when ObjectMonitor is contended") \
\
product(bool, UseWisp2, false, \
experimental(bool, UseWisp2, false, \
"Enable Wisp2") \
\
diagnostic(bool, VerboseWisp, false, \
Expand Down
64 changes: 41 additions & 23 deletions hotspot/src/share/vm/runtime/quickStart.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#include <limits.h>
#include <stdlib.h>
#include <strings.h>
#include "precompiled.hpp"
#include "classfile/vmSymbols.hpp"
#include "classfile/javaClasses.hpp"
#include "memory/resourceArea.hpp"
#include "memory/oopFactory.hpp"
#include "runtime/arguments.hpp"
#include "runtime/java.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/quickStart.hpp"
#include "runtime/vm_version.hpp"
#include "utilities/defaultStream.hpp"
#include "jfr/recorder/service/jfrOptionSet.hpp"
#include "runtime/globals_extension.hpp"
#include "runtime/handles.hpp"
#include "runtime/handles.inline.hpp"
#include "oops/oop.inline.hpp"
Expand Down Expand Up @@ -411,7 +410,7 @@ void QuickStart::check_features(const char* &str) {
if (str[end] == ',' || (exit = (str[end] == '\n'))) {
// handle feature
for (int i = 0; i < QuickStart::Count; i++) {
int len = MIN2(::strlen(&str[begin]), ::strlen(_opt_name[i]));
size_t len = MIN2(::strlen(&str[begin]), ::strlen(_opt_name[i]));
if (::strncmp(&str[begin], _opt_name[i], len) == 0) {
// find a feature which is enabled at tracer phase.
tracer_features[i] = true;
Expand Down Expand Up @@ -440,7 +439,7 @@ void QuickStart::check_features(const char* &str) {
}

bool QuickStart::load_and_validate(const JavaVMInitArgs* options_args) {
char line[PATH_MAX];
char line[JVM_MAXPATHLEN];
const char* tail = NULL;
bool feature_checked = false;
bool version_checked = false;
Expand Down Expand Up @@ -469,9 +468,9 @@ bool QuickStart::load_and_validate(const JavaVMInitArgs* options_args) {
continue;
}
// ignore \n
int size = strlen(tail) - 1;
size_t size = strlen(tail) - 1;
const char *image_ident = QuickStart::image_id();
int ident_size = image_ident != NULL ? strlen(image_ident) : 0;
size_t ident_size = image_ident != NULL ? strlen(image_ident) : 0;
if (size != ident_size) {
tty->print_cr("Container image isn't the same.");
return false;
Expand Down Expand Up @@ -575,8 +574,8 @@ void QuickStart::calculate_cache_path() {
tty->print_cr("Cannot get temp directory");
vm_exit(1);
}
char buf[PATH_MAX];
jio_snprintf(buf, PATH_MAX, "%s%s%s_%d_%ld", temp, os::file_separator(), DEFAULT_SHARED_DIRECTORY, os::current_process_id(), os::javaTimeMillis());
char buf[JVM_MAXPATHLEN];
jio_snprintf(buf, JVM_MAXPATHLEN, "%s%s%s_%d_%ld", temp, os::file_separator(), DEFAULT_SHARED_DIRECTORY, os::current_process_id(), os::javaTimeMillis());
_cache_path = os::strdup(buf);
} else {
const char* home = ::getenv("HOME");
Expand All @@ -588,8 +587,8 @@ void QuickStart::calculate_cache_path() {
vm_exit(1);
}
}
char buf[PATH_MAX];
jio_snprintf(buf, PATH_MAX, "%s%s%s", home, os::file_separator(), DEFAULT_SHARED_DIRECTORY);
char buf[JVM_MAXPATHLEN];
jio_snprintf(buf, JVM_MAXPATHLEN, "%s%s%s", home, os::file_separator(), DEFAULT_SHARED_DIRECTORY);
_cache_path = os::strdup(buf);
}
tty->print_cr("cache path is set as default with %s", _cache_path);
Expand Down Expand Up @@ -655,7 +654,11 @@ void QuickStart::setenv_for_roles() {
} else {
ShouldNotReachHere();
}
#if defined(_WINDOWS)
Unimplemented();
#else
setenv("ALIBABA_QUICKSTART_ROLE", role, 1);
#endif
}

void QuickStart::process_argument_for_optimization() {
Expand Down Expand Up @@ -740,8 +743,12 @@ void QuickStart::add_CDSDumpHook(TRAPS) {
}

bool QuickStart::determine_role(const JavaVMInitArgs* options_args) {
#if defined(_WINDOWS)
Unimplemented();
return false;
#else
struct stat st;
char buf[PATH_MAX];
char buf[JVM_MAXPATHLEN];
int ret = os::stat(_cache_path, &st);
if (ret != 0) {
if (_print_stat_enabled) {
Expand All @@ -761,23 +768,23 @@ bool QuickStart::determine_role(const JavaVMInitArgs* options_args) {
}

// check whether the metadata file exists.
jio_snprintf(buf, PATH_MAX, "%s%s%s", _cache_path, os::file_separator(), METADATA_FILE);
jio_snprintf(buf, JVM_MAXPATHLEN, "%s%s%s", _cache_path, os::file_separator(), METADATA_FILE);
_metadata_file_path = os::strdup(buf, mtInternal);
ret = os::stat(_metadata_file_path, &st);
if (ret < 0 && errno == ENOENT) {
if (_print_stat_enabled) {
print_stat(false);
}
// Create a LOCK file
jio_snprintf(buf, PATH_MAX, "%s%s%s", _cache_path, os::file_separator(), LOCK_FILE);
jio_snprintf(buf, JVM_MAXPATHLEN, "%s%s%s", _cache_path, os::file_separator(), LOCK_FILE);
_lock_path = os::strdup(buf, mtInternal);
// if the lock exists, it returns -1.
_lock_file_fd = os::create_binary_file(_lock_path, false);
if (_lock_file_fd == -1) {
tty->print_cr("Fail to create LOCK file");
return false;
}
jio_snprintf(buf, PATH_MAX, "%s%s%s", _cache_path, os::file_separator(), TEMP_METADATA_FILE);
jio_snprintf(buf, JVM_MAXPATHLEN, "%s%s%s", _cache_path, os::file_separator(), TEMP_METADATA_FILE);
_temp_metadata_file_path = os::strdup(buf, mtInternal);
ret = os::stat(buf, &st);
if (ret == 0) {
Expand Down Expand Up @@ -808,37 +815,43 @@ bool QuickStart::determine_role(const JavaVMInitArgs* options_args) {
return true;
}
return false;
#endif
}

bool QuickStart::prepare_dump(const JavaVMInitArgs *options_args) {
#if defined(_WINDOWS)
Unimplemented();
return false;
#else
struct stat st;
char buf[PATH_MAX];
char buf[JVM_MAXPATHLEN];
// check whether the metadata file exists.
// when run quickstart with profile,then dump.In the profile stage,the metadata.tmp not rename to metadata.
jio_snprintf(buf, PATH_MAX, "%s%s%s", _cache_path, os::file_separator(), TEMP_METADATA_FILE);
jio_snprintf(buf, JVM_MAXPATHLEN, "%s%s%s", _cache_path, os::file_separator(), TEMP_METADATA_FILE);
_temp_metadata_file_path = os::strdup(buf);
int ret = os::stat(_temp_metadata_file_path, &st);
if (ret < 0 && errno == ENOENT) {
tty->print_cr("The %s file not exists\n", _temp_metadata_file_path);
return false;
} else if (ret == 0 && check_integrity(options_args, _temp_metadata_file_path)) {
// Create a LOCK file
jio_snprintf(buf, PATH_MAX, "%s%s%s", _cache_path, os::file_separator(), LOCK_FILE);
jio_snprintf(buf, JVM_MAXPATHLEN, "%s%s%s", _cache_path, os::file_separator(), LOCK_FILE);
_lock_path = os::strdup(buf);
// if the lock exists, it returns -1.
_lock_file_fd = os::create_binary_file(_lock_path, false);
if (_lock_file_fd == -1) {
tty->print_cr("Fail to create LOCK file");
return false;
}
jio_snprintf(buf, PATH_MAX, "%s%s%s", _cache_path, os::file_separator(), METADATA_FILE);
jio_snprintf(buf, JVM_MAXPATHLEN, "%s%s%s", _cache_path, os::file_separator(), METADATA_FILE);
_metadata_file_path = os::strdup(buf);
_role = Dumper;
tty->print_cr("Running as dumper");
return true;
}
tty->print_cr("Cannot dump,maybe the %s is invalid!ret: %d", TEMP_METADATA_FILE, ret);
return false;
#endif
}
void QuickStart::settle_opt_pass_table() {
// If a feature is disabled by quickstart, we have no need to check it
Expand Down Expand Up @@ -896,9 +909,13 @@ void QuickStart::generate_metadata_file(bool rename_metafile) {
}

int QuickStart::remove_dir(const char* dir) {
#if defined(_WINDOWS)
Unimplemented();
return -1;
#else
char cur_dir[] = ".";
char up_dir[] = "..";
char dir_name[PATH_MAX];
char dir_name[JVM_MAXPATHLEN];
DIR *dirp = NULL;
struct dirent *dp;
struct stat dir_stat;
Expand All @@ -917,7 +934,7 @@ int QuickStart::remove_dir(const char* dir) {
if ((strcmp(cur_dir, dp->d_name) == 0) || (strcmp(up_dir, dp->d_name) == 0)) {
continue;
}
jio_snprintf(dir_name, PATH_MAX, "%s%s%s", dir, os::file_separator(), dp->d_name);
jio_snprintf(dir_name, JVM_MAXPATHLEN, "%s%s%s", dir, os::file_separator(), dp->d_name);
ret = remove_dir(dir_name);
if (ret != 0) {
break;
Expand All @@ -933,6 +950,7 @@ int QuickStart::remove_dir(const char* dir) {
tty->print_cr("unknow file type\n");
}
return ret;
#endif
}

void QuickStart::notify_dump() {
Expand Down Expand Up @@ -976,7 +994,7 @@ bool QuickStart::dump_cached_info(const JavaVMInitArgs* options_args) {
_temp_metadata_file->print_cr("%s", _identifier_name[ContainerImageID]);
}

int cp_len = strlen(Arguments::get_appclasspath());
int cp_len = (int)strlen(Arguments::get_appclasspath());
_temp_metadata_file->print_cr("%s%d", _identifier_name[ClassPathLength], cp_len);
_temp_metadata_file->write(Arguments::get_appclasspath(), cp_len);
_temp_metadata_file->cr();
Expand Down
6 changes: 6 additions & 0 deletions jdk/test/com/alibaba/cds/TestDumpAndLoadClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ static void dumpLoadedClasses(String[] expectedClasses) throws Exception {
"-XX:DumpLoadedClassList=" + CLASSLIST_FILE,
// trigger JVMCI runtime init so that JVMCI classes will be
// included in the classlist
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-cp",
TESTJAR,
Expand Down Expand Up @@ -116,6 +118,8 @@ static void dumpArchive() throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-cp",
TESTJAR,
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-XX:SharedClassListFile=" + CLASSLIST_FILE_2,
"-XX:SharedArchiveFile=" + ARCHIVE_FILE,
Expand All @@ -138,6 +142,8 @@ static void dumpArchive() throws Exception {
static void startWithJsa() throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-Dtest.classes=" + TEST_CLASS,
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-Xshare:on",
"-XX:SharedArchiveFile=" + ARCHIVE_FILE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ static void dumpLoadedClasses(String[] expectedClasses) throws Exception {
"-XX:DumpLoadedClassList=" + CLASSLIST_FILE,
// trigger JVMCI runtime init so that JVMCI classes will be
// included in the classlist
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-cp",
TESTJAR,
Expand All @@ -75,6 +77,8 @@ static void dumpArchive() throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-cp",
TESTJAR,
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-XX:SharedClassListFile=" + CLASSLIST_FILE_2,
"-XX:SharedArchiveFile=" + ARCHIVE_FILE,
Expand Down Expand Up @@ -107,6 +111,8 @@ static void changeSourcePath() throws Exception {
static void startWithJsa() throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-Dtest.classes=" + TEST_CLASS,
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-Xshare:on",
"-XX:SharedArchiveFile=" + ARCHIVE_FILE,
Expand Down
6 changes: 6 additions & 0 deletions jdk/test/com/alibaba/cds/TestDumpAndLoadClassWithNullURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ static void dumpLoadedClasses(String[] expectedClasses) throws Exception {
"-XX:DumpLoadedClassList=" + CLASSLIST_FILE,
// trigger JVMCI runtime init so that JVMCI classes will be
// included in the classlist
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-cp",
TESTJAR,
Expand All @@ -86,6 +88,8 @@ static void dumpArchive() throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-cp",
TESTJAR,
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-XX:SharedClassListFile=" + CLASSLIST_FILE_2,
"-XX:SharedArchiveFile=" + ARCHIVE_FILE,
Expand All @@ -108,6 +112,8 @@ static void dumpArchive() throws Exception {
static void startWithJsa() throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-Dtest.classes=" + TEST_CLASS,
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-Xshare:on",
"-XX:SharedArchiveFile=" + ARCHIVE_FILE,
Expand Down
9 changes: 9 additions & 0 deletions jdk/test/com/alibaba/cds/TestDumpAndLoadClassWithWisp.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ static void dumpLoadedClasses(String[] expectedClasses) throws Exception {
"-XX:DumpLoadedClassList=" + CLASSLIST_FILE,
// trigger JVMCI runtime init so that JVMCI classes will be
// included in the classlist
"-XX:+UnlockExperimentalVMOptions",
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-XX:+UseWisp2",
"-cp",
Expand Down Expand Up @@ -114,8 +117,11 @@ static void convertClassList() throws Exception {
}
static void dumpArchive() throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-XX:+UnlockExperimentalVMOptions",
"-cp",
TESTJAR,
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-XX:SharedClassListFile=" + CLASSLIST_FILE_2,
"-XX:SharedArchiveFile=" + ARCHIVE_FILE,
Expand All @@ -139,6 +145,9 @@ static void dumpArchive() throws Exception {
static void startWithJsa() throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-Dtest.classes=" + TEST_CLASS,
"-XX:+UnlockExperimentalVMOptions",
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-Xshare:on",
"-XX:SharedArchiveFile=" + ARCHIVE_FILE,
Expand Down
6 changes: 6 additions & 0 deletions jdk/test/com/alibaba/cds/TestDumpAndLoadNotFound.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ static void dumpLoadedClasses(String[] expectedClasses) throws Exception {
"-XX:DumpLoadedClassList=" + CLASSLIST_FILE,
// trigger JVMCI runtime init so that JVMCI classes will be
// included in the classlist
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-cp",
TESTJAR,
Expand Down Expand Up @@ -115,6 +117,8 @@ static void dumpArchive() throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-cp",
TESTJAR,
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-XX:SharedClassListFile=" + CLASSLIST_FILE_2,
"-XX:SharedArchiveFile=" + ARCHIVE_FILE,
Expand All @@ -137,6 +141,8 @@ static void dumpArchive() throws Exception {
static void startWithJsa() throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-Dtest.classes=" + TEST_CLASS,
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-Dcom.alibaba.cds.listPath=" + CLASSLIST_FILE_2,
"-Xshare:on",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ static void dumpLoadedClasses(String[] expectedClasses) throws Exception {
"-XX:DumpLoadedClassList=" + CLASSLIST_FILE,
// trigger JVMCI runtime init so that JVMCI classes will be
// included in the classlist
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-cp",
TESTJAR,
Expand Down Expand Up @@ -120,6 +122,8 @@ static void dumpArchive() throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-cp",
TESTJAR,
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-XX:SharedClassListFile=" + CLASSLIST_FILE_2,
"-XX:SharedArchiveFile=" + ARCHIVE_FILE,
Expand All @@ -142,6 +146,8 @@ static void dumpArchive() throws Exception {
static void startWithJsa() throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-Dtest.classes=" + TEST_CLASS,
"-XX:+UseCompressedOops",
"-XX:+UseCompressedClassPointers",
"-XX:+EagerAppCDS",
"-Dcom.alibaba.cds.listPath=" + CLASSLIST_FILE_2,
"-Xshare:on",
Expand Down
Loading
Loading