Skip to content

Commit

Permalink
Merge branch 'master' of http://github.com/openjdk/jdk into JDK-8338201
Browse files Browse the repository at this point in the history
  • Loading branch information
jatin-bhateja committed Oct 17, 2024
2 parents 79ac29d + 236c71c commit d9a379b
Show file tree
Hide file tree
Showing 291 changed files with 4,601 additions and 1,607 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ address NativeCall::destination() const {
//
// Used in the runtime linkage of calls; see class CompiledIC.
void NativeCall::set_destination_mt_safe(address dest) {
assert((Patching_lock->is_locked() || SafepointSynchronize::is_at_safepoint()) ||
assert((CodeCache_lock->is_locked() || SafepointSynchronize::is_at_safepoint()) ||
CompiledICLocker::is_safe(addr_at(0)),
"concurrent code patching");

Expand Down
6 changes: 5 additions & 1 deletion src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ int LIR_Assembler::emit_unwind_handler() {
if (method()->is_synchronized()) {
monitor_address(0, FrameMap::R4_opr);
stub = new MonitorExitStub(FrameMap::R4_opr, true, 0);
__ unlock_object(R5, R6, R4, *stub->entry());
if (LockingMode == LM_MONITOR) {
__ b(*stub->entry());
} else {
__ unlock_object(R5, R6, R4, *stub->entry());
}
__ bind(*stub->continuation());
}

Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ void C1_MacroAssembler::lock_object(Register Rmark, Register Roop, Register Rbox
/*check without membar and ldarx first*/true);
// If compare/exchange succeeded we found an unlocked object and we now have locked it
// hence we are done.
} else {
assert(false, "Unhandled LockingMode:%d", LockingMode);
}
b(done);

Expand Down Expand Up @@ -168,6 +170,8 @@ void C1_MacroAssembler::unlock_object(Register Rmark, Register Roop, Register Rb
MacroAssembler::cmpxchgx_hint_release_lock(),
noreg,
&slow_int);
} else {
assert(false, "Unhandled LockingMode:%d", LockingMode);
}
b(done);
bind(slow_int);
Expand Down
53 changes: 34 additions & 19 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 @@ -2739,20 +2746,32 @@ void MacroAssembler::compiler_fast_unlock_object(ConditionRegister flag, Registe
// Check if there is a successor.
ld(temp, in_bytes(ObjectMonitor::succ_offset()), current_header);
cmpdi(flag, temp, 0);
bne(flag, success); // If so we are done.
// Invert equal bit
crnand(flag, Assembler::equal, flag, Assembler::equal);
beq(flag, success); // If there is a successor we are done.

// Save the monitor pointer in the current thread, so we can try
// to reacquire the lock in SharedRuntime::monitor_exit_helper().
std(current_header, in_bytes(JavaThread::unlocked_inflated_monitor_offset()), R16_thread);

crxor(flag, Assembler::equal, flag, Assembler::equal); // Set flag = NE => slow path
b(failure);
b(failure); // flag == NE

// flag == EQ indicates success, decrement held monitor count
// 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 Expand Up @@ -3053,7 +3072,6 @@ void MacroAssembler::compiler_fast_unlock_lightweight_object(ConditionRegister f

bind(not_recursive);

Label set_eq_unlocked;
const Register t2 = tmp2;

// Set owner to null.
Expand All @@ -3075,17 +3093,14 @@ void MacroAssembler::compiler_fast_unlock_lightweight_object(ConditionRegister f
// Check if there is a successor.
ld(t, in_bytes(ObjectMonitor::succ_offset()), monitor);
cmpdi(CCR0, t, 0);
bne(CCR0, set_eq_unlocked); // If so we are done.
// Invert equal bit
crnand(flag, Assembler::equal, flag, Assembler::equal);
beq(CCR0, unlocked); // If there is a successor we are done.

// Save the monitor pointer in the current thread, so we can try
// to reacquire the lock in SharedRuntime::monitor_exit_helper().
std(monitor, in_bytes(JavaThread::unlocked_inflated_monitor_offset()), R16_thread);

crxor(CCR0, Assembler::equal, CCR0, Assembler::equal); // Set flag = NE => slow path
b(slow_path);

bind(set_eq_unlocked);
crorc(CCR0, Assembler::equal, CCR0, Assembler::equal); // Set flag = EQ => fast path
b(slow_path); // flag == NE
}

bind(unlocked);
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/ppc/nativeInst_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ address NativeCall::destination() const {
// Used in the runtime linkage of calls; see class CompiledIC.
//
// Add parameter assert_lock to switch off assertion
// during code generation, where no patching lock is needed.
// during code generation, where no lock is needed.
void NativeCall::set_destination_mt_safe(address dest, bool assert_lock) {
assert(!assert_lock ||
(Patching_lock->is_locked() || SafepointSynchronize::is_at_safepoint()) ||
(CodeCache_lock->is_locked() || SafepointSynchronize::is_at_safepoint()) ||
CompiledICLocker::is_safe(addr_at(0)),
"concurrent code patching");

Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/cpu/riscv/nativeInst_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ void NativeShortCall::print() {
// Used in the runtime linkage of calls; see class CompiledIC.
//
// Add parameter assert_lock to switch off assertion
// during code generation, where no patching lock is needed.
// during code generation, where no lock is needed.
bool NativeShortCall::set_destination_mt_safe(address dest, bool assert_lock) {
assert(!assert_lock ||
(Patching_lock->is_locked() || SafepointSynchronize::is_at_safepoint()) ||
(CodeCache_lock->is_locked() || SafepointSynchronize::is_at_safepoint()) ||
CompiledICLocker::is_safe(instruction_address()),
"concurrent code patching");

Expand Down Expand Up @@ -386,7 +386,7 @@ void NativeFarCall::print() {
bool NativeFarCall::set_destination_mt_safe(address dest, bool assert_lock) {
assert(NativeFarCall::is_at(addr_at(0)), "unexpected code at call site");
assert(!assert_lock ||
(Patching_lock->is_locked() || SafepointSynchronize::is_at_safepoint()) ||
(CodeCache_lock->is_locked() || SafepointSynchronize::is_at_safepoint()) ||
CompiledICLocker::is_safe(addr_at(0)),
"concurrent code patching");

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/s390/nativeInst_s390.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,8 @@ void NativeGeneralJump::insert_unconditional(address code_pos, address entry) {

void NativeGeneralJump::replace_mt_safe(address instr_addr, address code_buffer) {
assert(((intptr_t)instr_addr & (BytesPerWord-1)) == 0, "requirement for mt safe patching");
// Bytes_after_jump cannot change, because we own the Patching_lock.
assert(Patching_lock->owned_by_self(), "must hold lock to patch instruction");
// Bytes_after_jump cannot change, because we own the CodeCache_lock.
assert(CodeCache_lock->owned_by_self(), "must hold lock to patch instruction");
intptr_t bytes_after_jump = (*(intptr_t*)instr_addr) & 0x000000000000ffffL; // 2 bytes after jump.
intptr_t load_const_bytes = (*(intptr_t*)code_buffer) & 0xffffffffffff0000L;
*(intptr_t*)instr_addr = load_const_bytes | bytes_after_jump;
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/x86/nativeInst_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void NativeCall::insert(address code_pos, address entry) {
// (spinlock). Then patches the last byte, and then atomically replaces
// the jmp's with the first 4 byte of the new instruction.
void NativeCall::replace_mt_safe(address instr_addr, address code_buffer) {
assert(Patching_lock->is_locked() ||
assert(CodeCache_lock->is_locked() ||
SafepointSynchronize::is_at_safepoint(), "concurrent code patching");
assert (instr_addr != nullptr, "illegal address for code patching");

Expand Down Expand Up @@ -144,7 +144,7 @@ void NativeCall::set_destination_mt_safe(address dest) {
debug_only(verify());
// Make sure patching code is locked. No two threads can patch at the same
// time but one may be executing this code.
assert(Patching_lock->is_locked() || SafepointSynchronize::is_at_safepoint() ||
assert(CodeCache_lock->is_locked() || SafepointSynchronize::is_at_safepoint() ||
CompiledICLocker::is_safe(instruction_address()), "concurrent code patching");
// Both C1 and C2 should now be generating code which aligns the patched address
// to be within a single cache line.
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
12 changes: 4 additions & 8 deletions src/hotspot/share/c1/c1_Runtime1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ static Klass* resolve_field_return_klass(const methodHandle& caller, int bci, TR
// movl reg, [reg1 + <const>] (for field offsets)
// jmp continue
// <being_init offset> <bytes to copy> <bytes to skip>
// patch_stub: jmp Runtim1::patch_code (through a runtime stub)
// patch_stub: jmp Runtime1::patch_code (through a runtime stub)
// jmp patch_site
//
// If the class is being initialized the patch body is rewritten and
Expand Down Expand Up @@ -1103,7 +1103,7 @@ JRT_ENTRY(void, Runtime1::patch_code(JavaThread* current, C1StubId stub_id ))
// Now copy code back

{
MutexLocker ml_patch (current, Patching_lock, Mutex::_no_safepoint_check_flag);
MutexLocker ml_code (current, CodeCache_lock, Mutex::_no_safepoint_check_flag);
//
// Deoptimization may have happened while we waited for the lock.
// In that case we don't bother to do any patching we just return
Expand Down Expand Up @@ -1268,12 +1268,8 @@ JRT_ENTRY(void, Runtime1::patch_code(JavaThread* current, C1StubId stub_id ))
}
}
}
}

// If we are patching in a non-perm oop, make sure the nmethod
// is on the right list.
{
MutexLocker ml_code (current, CodeCache_lock, Mutex::_no_safepoint_check_flag);
// If we are patching in a non-perm oop, make sure the nmethod
// is on the right list.
nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
guarantee(nm != nullptr, "only nmethods can contain non-perm oops");

Expand Down
Loading

0 comments on commit d9a379b

Please sign in to comment.