8292591: Experimentally add back barrier-less Java thread transitions
Reviewed-by: mdoerr, eosterlund, pchilanomate, dcubed
This commit is contained in:
parent
dfc16e047f
commit
1e1db5debd
src/hotspot
cpu
aarch64
ppc
x86
os
linux
windows
share
jfr/periodic/sampling
runtime
utilities
test/hotspot/jtreg/runtime/handshake
@ -31,6 +31,7 @@
|
||||
#include "logging/logStream.hpp"
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "prims/downcallLinker.hpp"
|
||||
#include "runtime/globals.hpp"
|
||||
#include "runtime/stubCodeGenerator.hpp"
|
||||
|
||||
#define __ _masm->
|
||||
@ -247,8 +248,10 @@ void DowncallStubGenerator::generate() {
|
||||
__ strw(tmp1, Address(rthread, JavaThread::thread_state_offset()));
|
||||
|
||||
// Force this write out before the read below
|
||||
__ membar(Assembler::LoadLoad | Assembler::LoadStore |
|
||||
Assembler::StoreLoad | Assembler::StoreStore);
|
||||
if (!UseSystemMemoryBarrier) {
|
||||
__ membar(Assembler::LoadLoad | Assembler::LoadStore |
|
||||
Assembler::StoreLoad | Assembler::StoreStore);
|
||||
}
|
||||
|
||||
__ verify_sve_vector_length(tmp1);
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "prims/methodHandles.hpp"
|
||||
#include "runtime/continuation.hpp"
|
||||
#include "runtime/continuationEntry.inline.hpp"
|
||||
#include "runtime/globals.hpp"
|
||||
#include "runtime/jniHandles.hpp"
|
||||
#include "runtime/safepointMechanism.hpp"
|
||||
#include "runtime/sharedRuntime.hpp"
|
||||
@ -1786,7 +1787,9 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
|
||||
__ strw(rscratch1, Address(rthread, JavaThread::thread_state_offset()));
|
||||
|
||||
// Force this write out before the read below
|
||||
__ dmb(Assembler::ISH);
|
||||
if (!UseSystemMemoryBarrier) {
|
||||
__ dmb(Assembler::ISH);
|
||||
}
|
||||
|
||||
__ verify_sve_vector_length();
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "runtime/arguments.hpp"
|
||||
#include "runtime/deoptimization.hpp"
|
||||
#include "runtime/frame.inline.hpp"
|
||||
#include "runtime/globals.hpp"
|
||||
#include "runtime/jniHandles.hpp"
|
||||
#include "runtime/sharedRuntime.hpp"
|
||||
#include "runtime/stubRoutines.hpp"
|
||||
@ -1343,7 +1344,9 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
|
||||
__ stlrw(rscratch1, rscratch2);
|
||||
|
||||
// Force this write out before the read below
|
||||
__ dmb(Assembler::ISH);
|
||||
if (!UseSystemMemoryBarrier) {
|
||||
__ dmb(Assembler::ISH);
|
||||
}
|
||||
|
||||
// check for safepoint operation in progress and/or pending suspend requests
|
||||
{
|
||||
|
@ -2147,7 +2147,9 @@ nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm,
|
||||
Label no_block, sync;
|
||||
|
||||
// Force this write out before the read below.
|
||||
__ fence();
|
||||
if (!UseSystemMemoryBarrier) {
|
||||
__ fence();
|
||||
}
|
||||
|
||||
Register sync_state_addr = r_temp_4;
|
||||
Register sync_state = r_temp_5;
|
||||
|
@ -1436,7 +1436,9 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
|
||||
__ li(R0/*thread_state*/, _thread_in_native_trans);
|
||||
__ release();
|
||||
__ stw(R0/*thread_state*/, thread_(thread_state));
|
||||
__ fence();
|
||||
if (!UseSystemMemoryBarrier) {
|
||||
__ fence();
|
||||
}
|
||||
|
||||
// Now before we return to java we must look for a current safepoint
|
||||
// (a new safepoint can not start since we entered native_trans).
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "prims/foreignGlobals.inline.hpp"
|
||||
#include "prims/downcallLinker.hpp"
|
||||
#include "runtime/globals.hpp"
|
||||
#include "runtime/sharedRuntime.hpp"
|
||||
#include "runtime/stubCodeGenerator.hpp"
|
||||
#include "utilities/formatBuffer.hpp"
|
||||
@ -251,9 +252,11 @@ void DowncallStubGenerator::generate() {
|
||||
__ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_native_trans);
|
||||
|
||||
// Force this write out before the read below
|
||||
__ membar(Assembler::Membar_mask_bits(
|
||||
Assembler::LoadLoad | Assembler::LoadStore |
|
||||
Assembler::StoreLoad | Assembler::StoreStore));
|
||||
if (!UseSystemMemoryBarrier) {
|
||||
__ membar(Assembler::Membar_mask_bits(
|
||||
Assembler::LoadLoad | Assembler::LoadStore |
|
||||
Assembler::StoreLoad | Assembler::StoreStore));
|
||||
}
|
||||
|
||||
Label L_after_safepoint_poll;
|
||||
Label L_safepoint_poll_slow_path;
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "prims/methodHandles.hpp"
|
||||
#include "runtime/continuation.hpp"
|
||||
#include "runtime/continuationEntry.inline.hpp"
|
||||
#include "runtime/globals.hpp"
|
||||
#include "runtime/jniHandles.hpp"
|
||||
#include "runtime/safepointMechanism.hpp"
|
||||
#include "runtime/sharedRuntime.hpp"
|
||||
@ -2118,9 +2119,11 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
|
||||
__ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_native_trans);
|
||||
|
||||
// Force this write out before the read below
|
||||
__ membar(Assembler::Membar_mask_bits(
|
||||
if (!UseSystemMemoryBarrier) {
|
||||
__ membar(Assembler::Membar_mask_bits(
|
||||
Assembler::LoadLoad | Assembler::LoadStore |
|
||||
Assembler::StoreLoad | Assembler::StoreStore));
|
||||
}
|
||||
|
||||
// check for safepoint operation in progress and/or pending suspend requests
|
||||
{
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "runtime/continuation.hpp"
|
||||
#include "runtime/deoptimization.hpp"
|
||||
#include "runtime/frame.inline.hpp"
|
||||
#include "runtime/globals.hpp"
|
||||
#include "runtime/jniHandles.hpp"
|
||||
#include "runtime/sharedRuntime.hpp"
|
||||
#include "runtime/stubRoutines.hpp"
|
||||
@ -1082,10 +1083,11 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
|
||||
_thread_in_native_trans);
|
||||
|
||||
// Force this write out before the read below
|
||||
__ membar(Assembler::Membar_mask_bits(
|
||||
Assembler::LoadLoad | Assembler::LoadStore |
|
||||
Assembler::StoreLoad | Assembler::StoreStore));
|
||||
|
||||
if (!UseSystemMemoryBarrier) {
|
||||
__ membar(Assembler::Membar_mask_bits(
|
||||
Assembler::LoadLoad | Assembler::LoadStore |
|
||||
Assembler::StoreLoad | Assembler::StoreStore));
|
||||
}
|
||||
#ifndef _LP64
|
||||
if (AlwaysRestoreFPU) {
|
||||
// Make sure the control word is correct.
|
||||
|
86
src/hotspot/os/linux/systemMemoryBarrier_linux.cpp
Normal file
86
src/hotspot/os/linux/systemMemoryBarrier_linux.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "logging/log.hpp"
|
||||
#include "runtime/os.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
#include "utilities/systemMemoryBarrier.hpp"
|
||||
|
||||
#include <sys/syscall.h>
|
||||
|
||||
// Syscall defined in kernel 4.3
|
||||
// Oracle x64 builds may use old sysroot (pre 4.3)
|
||||
#ifndef SYS_membarrier
|
||||
#if defined(AMD64)
|
||||
#define SYS_membarrier 324
|
||||
#elif defined(PPC64)
|
||||
#define SYS_membarrier 365
|
||||
#else
|
||||
#error define SYS_membarrier for the arch
|
||||
#endif
|
||||
#endif // SYS_membarrier
|
||||
|
||||
// Expedited defined in kernel 4.14
|
||||
// Therefore we define it here instead of including linux/membarrier.h
|
||||
enum membarrier_cmd {
|
||||
MEMBARRIER_CMD_QUERY = 0,
|
||||
MEMBARRIER_CMD_PRIVATE_EXPEDITED = (1 << 3),
|
||||
MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED = (1 << 4),
|
||||
};
|
||||
|
||||
#define check_with_errno(check_type, cond, msg) \
|
||||
do { \
|
||||
int err = errno; \
|
||||
check_type(cond, "%s: error='%s' (errno=%s)", msg, os::strerror(err), \
|
||||
os::errno_name(err)); \
|
||||
} while (false)
|
||||
|
||||
#define guarantee_with_errno(cond, msg) check_with_errno(guarantee, cond, msg)
|
||||
|
||||
static int membarrier(int cmd, unsigned int flags, int cpu_id) {
|
||||
return syscall(SYS_membarrier, cmd, flags, cpu_id); // cpu_id only on >= 5.10
|
||||
}
|
||||
|
||||
bool LinuxSystemMemoryBarrier::initialize() {
|
||||
int ret = membarrier(MEMBARRIER_CMD_QUERY, 0, 0);
|
||||
if (ret < 0) {
|
||||
log_error(os)("MEMBARRIER_CMD_QUERY unsupported");
|
||||
return false;
|
||||
}
|
||||
if (!(ret & MEMBARRIER_CMD_PRIVATE_EXPEDITED) ||
|
||||
!(ret & MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED)) {
|
||||
log_error(os)("MEMBARRIER PRIVATE_EXPEDITED unsupported");
|
||||
return false;
|
||||
}
|
||||
ret = membarrier(MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, 0, 0);
|
||||
guarantee_with_errno(ret == 0, "MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED failed");
|
||||
return true;
|
||||
}
|
||||
|
||||
void LinuxSystemMemoryBarrier::emit() {
|
||||
int s = membarrier(MEMBARRIER_CMD_PRIVATE_EXPEDITED, 0, 0);
|
||||
guarantee_with_errno(s >= 0, "MEMBARRIER_CMD_PRIVATE_EXPEDITED failed");
|
||||
}
|
||||
|
36
src/hotspot/os/linux/systemMemoryBarrier_linux.hpp
Normal file
36
src/hotspot/os/linux/systemMemoryBarrier_linux.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef OS_LINUX_SYSTEMMEMORYBARRIER_LINUX_HPP
|
||||
#define OS_LINUX_SYSTEMMEMORYBARRIER_LINUX_HPP
|
||||
|
||||
#include "memory/allStatic.hpp"
|
||||
|
||||
class LinuxSystemMemoryBarrier : public AllStatic {
|
||||
public:
|
||||
static bool initialize();
|
||||
static void emit();
|
||||
};
|
||||
|
||||
#endif // OS_LINUX_SYSTEMMEMORYBARRIER_LINUX_HPP
|
37
src/hotspot/os/windows/systemMemoryBarrier_windows.cpp
Normal file
37
src/hotspot/os/windows/systemMemoryBarrier_windows.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "systemMemoryBarrier_windows.hpp"
|
||||
|
||||
#include <windows.h>
|
||||
#include <processthreadsapi.h>
|
||||
|
||||
bool WindowsSystemMemoryBarrier::initialize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void WindowsSystemMemoryBarrier::emit() {
|
||||
FlushProcessWriteBuffers();
|
||||
}
|
36
src/hotspot/os/windows/systemMemoryBarrier_windows.hpp
Normal file
36
src/hotspot/os/windows/systemMemoryBarrier_windows.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef OS_LINUX_SYSTEMMEMORYBARRIER_WINDOWS_HPP
|
||||
#define OS_LINUX_SYSTEMMEMORYBARRIER_WINDOWS_HPP
|
||||
|
||||
#include "memory/allStatic.hpp"
|
||||
|
||||
class WindowsSystemMemoryBarrier : public AllStatic {
|
||||
public:
|
||||
static bool initialize();
|
||||
static void emit();
|
||||
};
|
||||
|
||||
#endif // OS_LINUX_SYSTEMMEMORYBARRIER_WINDOWS_HPP
|
@ -37,12 +37,14 @@
|
||||
#include "logging/log.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "runtime/frame.inline.hpp"
|
||||
#include "runtime/globals.hpp"
|
||||
#include "runtime/javaThread.inline.hpp"
|
||||
#include "runtime/os.hpp"
|
||||
#include "runtime/semaphore.hpp"
|
||||
#include "runtime/suspendedThreadTask.hpp"
|
||||
#include "runtime/threadCrashProtection.hpp"
|
||||
#include "runtime/threadSMR.hpp"
|
||||
#include "utilities/systemMemoryBarrier.hpp"
|
||||
|
||||
enum JfrSampleType {
|
||||
NO_SAMPLE = 0,
|
||||
@ -382,6 +384,9 @@ bool JfrThreadSampleClosure::do_sample_thread(JavaThread* thread, JfrStackFrame*
|
||||
|
||||
bool ret = false;
|
||||
thread->set_trace_flag(); // Provides StoreLoad, needed to keep read of thread state from floating up.
|
||||
if (UseSystemMemoryBarrier) {
|
||||
SystemMemoryBarrier::emit();
|
||||
}
|
||||
if (JAVA_SAMPLE == type) {
|
||||
if (thread_state_in_java(thread)) {
|
||||
ret = sample_thread_in_java(thread, frames, max_frames);
|
||||
|
@ -1294,6 +1294,9 @@ const int ObjectAlignmentInBytes = 8;
|
||||
"Delay in milliseconds for option SafepointTimeout") \
|
||||
range(0, max_intx LP64_ONLY(/MICROUNITS)) \
|
||||
\
|
||||
product(bool, UseSystemMemoryBarrier, false, EXPERIMENTAL, \
|
||||
"Try to enable system memory barrier") \
|
||||
\
|
||||
product(intx, NmethodSweepActivity, 4, \
|
||||
"Removes cold nmethods from code cache if > 0. Higher values " \
|
||||
"result in more aggressive sweeping") \
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "logging/logStream.hpp"
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "runtime/globals.hpp"
|
||||
#include "runtime/handshake.hpp"
|
||||
#include "runtime/interfaceSupport.inline.hpp"
|
||||
#include "runtime/javaThread.inline.hpp"
|
||||
@ -43,6 +44,7 @@
|
||||
#include "utilities/filterQueue.inline.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
#include "utilities/preserveException.hpp"
|
||||
#include "utilities/systemMemoryBarrier.hpp"
|
||||
|
||||
class HandshakeOperation : public CHeapObj<mtThread> {
|
||||
friend class HandshakeState;
|
||||
@ -248,6 +250,9 @@ class VM_HandshakeAllThreads: public VM_Operation {
|
||||
thr->handshake_state()->add_operation(_op);
|
||||
number_of_threads_issued++;
|
||||
}
|
||||
if (UseSystemMemoryBarrier) {
|
||||
SystemMemoryBarrier::emit();
|
||||
}
|
||||
|
||||
if (number_of_threads_issued < 1) {
|
||||
log_handshake_info(start_time_ns, _op->name(), 0, 0, "no threads alive");
|
||||
@ -370,6 +375,12 @@ void Handshake::execute(HandshakeClosure* hs_cl, ThreadsListHandle* tlh, JavaThr
|
||||
return;
|
||||
}
|
||||
|
||||
// Separate the arming of the poll in add_operation() above from
|
||||
// the read of JavaThread state in the try_process() call below.
|
||||
if (UseSystemMemoryBarrier) {
|
||||
SystemMemoryBarrier::emit();
|
||||
}
|
||||
|
||||
// Keeps count on how many of own emitted handshakes
|
||||
// this thread execute.
|
||||
int emitted_handshakes_executed = 0;
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "runtime/deoptimization.hpp"
|
||||
#include "runtime/frame.inline.hpp"
|
||||
#include "runtime/globals.hpp"
|
||||
#include "runtime/handles.inline.hpp"
|
||||
#include "runtime/interfaceSupport.inline.hpp"
|
||||
#include "runtime/javaThread.inline.hpp"
|
||||
@ -69,6 +70,7 @@
|
||||
#include "services/runtimeService.hpp"
|
||||
#include "utilities/events.hpp"
|
||||
#include "utilities/macros.hpp"
|
||||
#include "utilities/systemMemoryBarrier.hpp"
|
||||
|
||||
static void post_safepoint_begin_event(EventSafepointBegin& event,
|
||||
uint64_t safepoint_id,
|
||||
@ -339,8 +341,11 @@ void SafepointSynchronize::arm_safepoint() {
|
||||
// Make sure the threads start polling, it is time to yield.
|
||||
SafepointMechanism::arm_local_poll(cur);
|
||||
}
|
||||
|
||||
OrderAccess::fence(); // storestore|storeload, global state -> local state
|
||||
if (UseSystemMemoryBarrier) {
|
||||
SystemMemoryBarrier::emit(); // storestore|storeload, global state -> local state
|
||||
} else {
|
||||
OrderAccess::fence(); // storestore|storeload, global state -> local state
|
||||
}
|
||||
}
|
||||
|
||||
// Roll all threads forward to a safepoint and suspend them all
|
||||
|
@ -61,6 +61,7 @@
|
||||
#include "runtime/fieldDescriptor.inline.hpp"
|
||||
#include "runtime/flags/jvmFlagLimit.hpp"
|
||||
#include "runtime/handles.inline.hpp"
|
||||
#include "runtime/globals.hpp"
|
||||
#include "runtime/interfaceSupport.inline.hpp"
|
||||
#include "runtime/java.hpp"
|
||||
#include "runtime/javaCalls.hpp"
|
||||
@ -94,6 +95,7 @@
|
||||
#include "utilities/dtrace.hpp"
|
||||
#include "utilities/events.hpp"
|
||||
#include "utilities/macros.hpp"
|
||||
#include "utilities/systemMemoryBarrier.hpp"
|
||||
#include "utilities/vmError.hpp"
|
||||
#if INCLUDE_JVMCI
|
||||
#include "jvmci/jvmci.hpp"
|
||||
@ -552,6 +554,14 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
|
||||
// crash Linux VM, see notes in os_linux.cpp.
|
||||
main_thread->stack_overflow_state()->create_stack_guard_pages();
|
||||
|
||||
if (UseSystemMemoryBarrier) {
|
||||
if (!SystemMemoryBarrier::initialize()) {
|
||||
vm_shutdown_during_initialization("Failed to initialize the requested system memory barrier synchronization.");
|
||||
return JNI_EINVAL;
|
||||
}
|
||||
log_debug(os)("Using experimental system memory barrier synchronization");
|
||||
}
|
||||
|
||||
// Initialize Java-Level synchronization subsystem
|
||||
ObjectMonitor::Initialize();
|
||||
ObjectSynchronizer::initialize();
|
||||
|
60
src/hotspot/share/utilities/systemMemoryBarrier.hpp
Normal file
60
src/hotspot/share/utilities/systemMemoryBarrier.hpp
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SHARE_UTILITIES_SYSTEMMEMORYBARRIER_HPP
|
||||
#define SHARE_UTILITIES_SYSTEMMEMORYBARRIER_HPP
|
||||
|
||||
#include "logging/log.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
|
||||
#if defined(LINUX)
|
||||
#include "systemMemoryBarrier_linux.hpp"
|
||||
typedef LinuxSystemMemoryBarrier SystemMemoryBarrierDefault;
|
||||
#elif defined(_WINDOWS)
|
||||
#include "systemMemoryBarrier_windows.hpp"
|
||||
typedef WindowsSystemMemoryBarrier SystemMemoryBarrierDefault;
|
||||
#else
|
||||
class NoSystemMemoryBarrier {
|
||||
public:
|
||||
static bool initialize() {
|
||||
log_error(os)("SystemMemoryBarrier not supported on this platform");
|
||||
return false;
|
||||
}
|
||||
static void emit() {
|
||||
fatal("No system memory barrier available");
|
||||
}
|
||||
};
|
||||
typedef NoSystemMemoryBarrier SystemMemoryBarrierDefault;
|
||||
#endif
|
||||
|
||||
template <typename SystemMemoryBarrierImpl>
|
||||
class SystemMemoryBarrierType : public AllStatic {
|
||||
public:
|
||||
static bool initialize() { return SystemMemoryBarrierImpl::initialize(); }
|
||||
static void emit() { SystemMemoryBarrierImpl::emit(); }
|
||||
};
|
||||
|
||||
typedef SystemMemoryBarrierType<SystemMemoryBarrierDefault> SystemMemoryBarrier;
|
||||
|
||||
#endif // SHARE_UTILITIES_SYSTEMMEMORYBARRIER_HPP
|
@ -25,11 +25,13 @@
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test HandshakeTransitionTest
|
||||
* @summary This does a sanity test of the poll in the native wrapper.
|
||||
* @requires vm.debug
|
||||
* @library /testlibrary /test/lib
|
||||
* @build HandshakeTransitionTest
|
||||
* @run main/native HandshakeTransitionTest
|
||||
@ -39,17 +41,18 @@ public class HandshakeTransitionTest {
|
||||
public static native void someTime(int ms);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ProcessBuilder pb =
|
||||
ProcessTools.createTestJvm(
|
||||
"-Djava.library.path=" + Utils.TEST_NATIVE_PATH,
|
||||
"-XX:+SafepointALot",
|
||||
"-XX:+HandshakeALot",
|
||||
"-XX:GuaranteedSafepointInterval=20",
|
||||
"-Xlog:ergo*",
|
||||
"-XX:ParallelGCThreads=1",
|
||||
"-XX:ConcGCThreads=1",
|
||||
"-XX:CICompilerCount=2",
|
||||
"HandshakeTransitionTest$Test");
|
||||
List<String> commands = new ArrayList<>();
|
||||
commands.add("-Djava.library.path=" + Utils.TEST_NATIVE_PATH);
|
||||
commands.add("-XX:+UnlockDiagnosticVMOptions");
|
||||
commands.add("-XX:+SafepointALot");
|
||||
commands.add("-XX:+HandshakeALot");
|
||||
commands.add("-XX:GuaranteedSafepointInterval=20");
|
||||
commands.add("-XX:ParallelGCThreads=1");
|
||||
commands.add("-XX:ConcGCThreads=1");
|
||||
commands.add("-XX:CICompilerCount=2");
|
||||
commands.addAll(Arrays.asList(args));
|
||||
commands.add("HandshakeTransitionTest$Test");
|
||||
ProcessBuilder pb = ProcessTools.createTestJvm(commands);
|
||||
|
||||
OutputAnalyzer output = ProcessTools.executeProcess(pb);
|
||||
output.reportDiagnosticSummary();
|
||||
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test SystemMembarHandshakeTransitionTest
|
||||
* @summary This does a sanity test of the poll in the native wrapper.
|
||||
* @requires os.family == "linux" | os.family == "windows"
|
||||
* @library /testlibrary /test/lib
|
||||
* @build SystemMembarHandshakeTransitionTest HandshakeTransitionTest
|
||||
* @run main/native SystemMembarHandshakeTransitionTest
|
||||
*/
|
||||
|
||||
public class SystemMembarHandshakeTransitionTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
List<String> commands = new ArrayList<>();
|
||||
commands.add("-Djava.library.path=" + Utils.TEST_NATIVE_PATH);
|
||||
commands.add("-XX:+UnlockDiagnosticVMOptions");
|
||||
commands.add("-XX:+SafepointALot");
|
||||
commands.add("-XX:+HandshakeALot");
|
||||
commands.add("-XX:GuaranteedSafepointInterval=20");
|
||||
commands.add("-XX:ParallelGCThreads=1");
|
||||
commands.add("-XX:ConcGCThreads=1");
|
||||
commands.add("-XX:CICompilerCount=2");
|
||||
commands.add("-XX:+UnlockExperimentalVMOptions");
|
||||
commands.add("-XX:+UseSystemMemoryBarrier");
|
||||
commands.addAll(Arrays.asList(args));
|
||||
commands.add("HandshakeTransitionTest$Test");
|
||||
ProcessBuilder pb = ProcessTools.createTestJvm(commands);
|
||||
|
||||
OutputAnalyzer output = ProcessTools.executeProcess(pb);
|
||||
output.reportDiagnosticSummary();
|
||||
output.shouldMatch("(JOINED|Failed to initialize request system memory barrier synchronization.)");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user