Skip to content

Commit

Permalink
Merge branch 'master' into pr_macos_system_dump
Browse files Browse the repository at this point in the history
  • Loading branch information
stooke committed Oct 17, 2024
2 parents 6426da7 + 363327e commit 3050f9b
Show file tree
Hide file tree
Showing 234 changed files with 1,404 additions and 1,182 deletions.
33 changes: 26 additions & 7 deletions src/hotspot/cpu/ppc/macroAssembler_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2651,7 +2651,19 @@ void MacroAssembler::compiler_fast_lock_object(ConditionRegister flag, Register
// flag == NE indicates failure
bind(success);
inc_held_monitor_count(temp);
#ifdef ASSERT
// Check that unlocked label is reached with flag == EQ.
Label flag_correct;
beq(flag, flag_correct);
stop("compiler_fast_lock_object: Flag != EQ");
#endif
bind(failure);
#ifdef ASSERT
// Check that slow_path label is reached with flag == NE.
bne(flag, flag_correct);
stop("compiler_fast_lock_object: Flag != NE");
bind(flag_correct);
#endif
}

void MacroAssembler::compiler_fast_unlock_object(ConditionRegister flag, Register oop, Register box,
Expand Down Expand Up @@ -2701,17 +2713,12 @@ void MacroAssembler::compiler_fast_unlock_object(ConditionRegister flag, Registe
bind(object_has_monitor);
STATIC_ASSERT(markWord::monitor_value <= INT_MAX);
addi(current_header, current_header, -(int)markWord::monitor_value); // monitor
ld(temp, in_bytes(ObjectMonitor::owner_offset()), current_header);

// In case of LM_LIGHTWEIGHT, we may reach here with (temp & ObjectMonitor::ANONYMOUS_OWNER) != 0.
// This is handled like owner thread mismatches: We take the slow path.
cmpd(flag, temp, R16_thread);
bne(flag, failure);

ld(displaced_header, in_bytes(ObjectMonitor::recursions_offset()), current_header);

addic_(displaced_header, displaced_header, -1);
blt(CCR0, notRecursive); // Not recursive if negative after decrement.

// Recursive unlock
std(displaced_header, in_bytes(ObjectMonitor::recursions_offset()), current_header);
if (flag == CCR0) { // Otherwise, flag is already EQ, here.
crorc(CCR0, Assembler::equal, CCR0, Assembler::equal); // Set CCR0 EQ
Expand Down Expand Up @@ -2752,7 +2759,19 @@ void MacroAssembler::compiler_fast_unlock_object(ConditionRegister flag, Registe
// flag == NE indicates failure
bind(success);
dec_held_monitor_count(temp);
#ifdef ASSERT
// Check that unlocked label is reached with flag == EQ.
Label flag_correct;
beq(flag, flag_correct);
stop("compiler_fast_unlock_object: Flag != EQ");
#endif
bind(failure);
#ifdef ASSERT
// Check that slow_path label is reached with flag == NE.
bne(flag, flag_correct);
stop("compiler_fast_unlock_object: Flag != NE");
bind(flag_correct);
#endif
}

void MacroAssembler::compiler_fast_lock_lightweight_object(ConditionRegister flag, Register obj, Register box,
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/os/aix/os_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ void os::jvm_path(char *buf, jint buflen) {
Dl_info dlinfo;
int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
assert(ret != 0, "cannot locate libjvm");
char* rp = os::Posix::realpath((char *)dlinfo.dli_fname, buf, buflen);
char* rp = os::realpath((char *)dlinfo.dli_fname, buf, buflen);
assert(rp != nullptr, "error in realpath(): maybe the 'path' argument is too long?");

if (Arguments::sun_java_launcher_is_altjvm()) {
Expand Down Expand Up @@ -1324,7 +1324,7 @@ void os::jvm_path(char *buf, jint buflen) {
}
assert(strstr(p, "/libjvm") == p, "invalid library name");

rp = os::Posix::realpath(java_home_var, buf, buflen);
rp = os::realpath(java_home_var, buf, buflen);
if (rp == nullptr) {
return;
}
Expand All @@ -1345,7 +1345,7 @@ void os::jvm_path(char *buf, jint buflen) {
snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
} else {
// Go back to path of .so
rp = os::Posix::realpath((char *)dlinfo.dli_fname, buf, buflen);
rp = os::realpath((char *)dlinfo.dli_fname, buf, buflen);
if (rp == nullptr) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ void os::jvm_path(char *buf, jint buflen) {
assert(ret, "cannot locate libjvm");
char *rp = nullptr;
if (ret && dli_fname[0] != '\0') {
rp = os::Posix::realpath(dli_fname, buf, buflen);
rp = os::realpath(dli_fname, buf, buflen);
}
if (rp == nullptr) {
return;
Expand Down Expand Up @@ -1541,7 +1541,7 @@ void os::jvm_path(char *buf, jint buflen) {
p = strrchr(buf, '/');
assert(strstr(p, "/libjvm") == p, "invalid library name");

rp = os::Posix::realpath(java_home_var, buf, buflen);
rp = os::realpath(java_home_var, buf, buflen);
if (rp == nullptr) {
return;
}
Expand Down Expand Up @@ -1575,7 +1575,7 @@ void os::jvm_path(char *buf, jint buflen) {
snprintf(buf + len, buflen-len, "/libjvm%s", JNI_LIB_SUFFIX);
} else {
// Fall back to path of current library
rp = os::Posix::realpath(dli_fname, buf, buflen);
rp = os::realpath(dli_fname, buf, buflen);
if (rp == nullptr) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2763,7 +2763,7 @@ void os::jvm_path(char *buf, jint buflen) {
assert(ret, "cannot locate libjvm");
char *rp = nullptr;
if (ret && dli_fname[0] != '\0') {
rp = os::Posix::realpath(dli_fname, buf, buflen);
rp = os::realpath(dli_fname, buf, buflen);
}
if (rp == nullptr) {
return;
Expand Down Expand Up @@ -2797,7 +2797,7 @@ void os::jvm_path(char *buf, jint buflen) {
}
assert(strstr(p, "/libjvm") == p, "invalid library name");

rp = os::Posix::realpath(java_home_var, buf, buflen);
rp = os::realpath(java_home_var, buf, buflen);
if (rp == nullptr) {
return;
}
Expand All @@ -2818,7 +2818,7 @@ void os::jvm_path(char *buf, jint buflen) {
snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
} else {
// Go back to path of .so
rp = os::Posix::realpath(dli_fname, buf, buflen);
rp = os::realpath(dli_fname, buf, buflen);
if (rp == nullptr) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/os/linux/os_perf_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_exe_path() {

jio_snprintf(buffer, PATH_MAX, "/proc/%s/exe", _entry->d_name);
buffer[PATH_MAX - 1] = '\0';
return os::Posix::realpath(buffer, _exePath, PATH_MAX);
return os::realpath(buffer, _exePath, PATH_MAX);
}

char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/os/posix/os_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,10 +1029,10 @@ char* os::Posix::describe_pthread_attr(char* buf, size_t buflen, const pthread_a
return buf;
}

char* os::Posix::realpath(const char* filename, char* outbuf, size_t outbuflen) {
char* os::realpath(const char* filename, char* outbuf, size_t outbuflen) {

if (filename == nullptr || outbuf == nullptr || outbuflen < 1) {
assert(false, "os::Posix::realpath: invalid arguments.");
assert(false, "os::realpath: invalid arguments.");
errno = EINVAL;
return nullptr;
}
Expand Down Expand Up @@ -1067,7 +1067,6 @@ char* os::Posix::realpath(const char* filename, char* outbuf, size_t outbuflen)
}
}
return result;

}

int os::stat(const char *path, struct stat *sbuf) {
Expand Down
7 changes: 0 additions & 7 deletions src/hotspot/os/posix/os_posix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ class os::Posix {
// to buf with len buflen; buf is returned.
static char* describe_pthread_attr(char* buf, size_t buflen, const pthread_attr_t* attr);

// A safe implementation of realpath which will not cause a buffer overflow if the resolved path
// is longer than PATH_MAX.
// On success, returns 'outbuf', which now contains the path.
// On error, it will return null and set errno. The content of 'outbuf' is undefined.
// On truncation error ('outbuf' too small), it will return null and set errno to ENAMETOOLONG.
static char* realpath(const char* filename, char* outbuf, size_t outbuflen);

// Returns true if given uid is root.
static bool is_root(uid_t uid);

Expand Down
22 changes: 22 additions & 0 deletions src/hotspot/os/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5397,6 +5397,28 @@ void os::funlockfile(FILE* fp) {
_unlock_file(fp);
}

char* os::realpath(const char* filename, char* outbuf, size_t outbuflen) {

if (filename == nullptr || outbuf == nullptr || outbuflen < 1) {
assert(false, "os::realpath: invalid arguments.");
errno = EINVAL;
return nullptr;
}

char* result = nullptr;
ALLOW_C_FUNCTION(::_fullpath, char* p = ::_fullpath(nullptr, filename, 0);)
if (p != nullptr) {
if (strlen(p) < outbuflen) {
strcpy(outbuf, p);
result = outbuf;
} else {
errno = ENAMETOOLONG;
}
ALLOW_C_FUNCTION(::free, ::free(p);) // *not* os::free
}
return result;
}

// Map a block of memory.
char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
char *addr, size_t bytes, bool read_only,
Expand Down
23 changes: 13 additions & 10 deletions src/hotspot/share/cds/cdsProtectionDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,27 @@ Handle CDSProtectionDomain::get_shared_jar_manifest(int shared_path_index, TRAPS
Handle CDSProtectionDomain::get_shared_jar_url(int shared_path_index, TRAPS) {
Handle url_h;
if (shared_jar_url(shared_path_index) == nullptr) {
JavaValue result(T_OBJECT);
const char* path = FileMapInfo::shared_path_name(shared_path_index);
Handle path_string = java_lang_String::create_from_str(path, CHECK_(url_h));
Klass* classLoaders_klass =
vmClasses::jdk_internal_loader_ClassLoaders_klass();
JavaCalls::call_static(&result, classLoaders_klass,
vmSymbols::toFileURL_name(),
vmSymbols::toFileURL_signature(),
path_string, CHECK_(url_h));

atomic_set_shared_jar_url(shared_path_index, result.get_oop());
oop result_oop = to_file_URL(path, url_h, CHECK_(url_h));
atomic_set_shared_jar_url(shared_path_index, result_oop);
}

url_h = Handle(THREAD, shared_jar_url(shared_path_index));
assert(url_h.not_null(), "sanity");
return url_h;
}

oop CDSProtectionDomain::to_file_URL(const char* path, Handle url_h, TRAPS) {
JavaValue result(T_OBJECT);
Handle path_string = java_lang_String::create_from_str(path, CHECK_NULL);
JavaCalls::call_static(&result,
vmClasses::jdk_internal_loader_ClassLoaders_klass(),
vmSymbols::toFileURL_name(),
vmSymbols::toFileURL_signature(),
path_string, CHECK_NULL);
return result.get_oop();
}

// Get the ProtectionDomain associated with the CodeSource from the classloader.
Handle CDSProtectionDomain::get_protection_domain_from_classloader(Handle class_loader,
Handle url, TRAPS) {
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/cds/cdsProtectionDomain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CDSProtectionDomain : AllStatic {
static Handle create_jar_manifest(const char* man, size_t size, TRAPS);
static Handle get_shared_jar_manifest(int shared_path_index, TRAPS);
static Handle get_shared_jar_url(int shared_path_index, TRAPS);
static oop to_file_URL(const char* path, Handle url_h, TRAPS);
static Handle get_protection_domain_from_classloader(Handle class_loader,
Handle url, TRAPS);
static Handle get_shared_protection_domain(Handle class_loader,
Expand Down
25 changes: 12 additions & 13 deletions src/hotspot/share/cds/metaspaceShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,12 +751,21 @@ void MetaspaceShared::preload_classes(TRAPS) {
}
}

// Exercise the manifest processing code to ensure classes used by CDS at runtime
// are always archived
// Some classes are used at CDS runtime but are not loaded, and therefore archived, at
// dumptime. We can perform dummmy calls to these classes at dumptime to ensure they
// are archived.
exercise_runtime_cds_code(CHECK);

log_info(cds)("Loading classes to share: done.");
}

void MetaspaceShared::exercise_runtime_cds_code(TRAPS) {
// Exercise the manifest processing code
const char* dummy = "Manifest-Version: 1.0\n";
CDSProtectionDomain::create_jar_manifest(dummy, strlen(dummy), CHECK);

log_info(cds)("Loading classes to share: done.");
// Exercise FileSystem and URL code
CDSProtectionDomain::to_file_URL("dummy.jar", Handle(), CHECK);
}

void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) {
Expand Down Expand Up @@ -799,16 +808,6 @@ void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS
}
#endif

// Dummy call to load classes used at CDS runtime
JavaValue result(T_OBJECT);
Handle path_string = java_lang_String::create_from_str("dummy.jar", CHECK);
JavaCalls::call_static(&result,
vmClasses::jdk_internal_loader_ClassLoaders_klass(),
vmSymbols::toFileURL_name(),
vmSymbols::toFileURL_signature(),
path_string,
CHECK);

VM_PopulateDumpSharedSpace op(builder);
VMThread::execute(&op);

Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/cds/metaspaceShared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class MetaspaceShared : AllStatic {
#endif

private:
static void exercise_runtime_cds_code(TRAPS) NOT_CDS_RETURN;
static void preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) NOT_CDS_RETURN;
static void preload_classes(TRAPS) NOT_CDS_RETURN;

Expand Down
Loading

0 comments on commit 3050f9b

Please sign in to comment.