8303210: [linux, Windows] Make UseSystemMemoryBarrier available as product flag

Reviewed-by: dholmes, rehn
(cherry picked from commit 4de24cdbe6)
This commit is contained in:
Martin Doerr
2023-04-03 09:37:16 +00:00
committed by Vitaly Provodin
parent 32aa834c57
commit b5d7a5d133
13 changed files with 51 additions and 28 deletions

View File

@@ -1211,7 +1211,9 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
__ str_32(Rtemp, Address(Rthread, JavaThread::thread_state_offset()));
// make sure the store is observed before reading the SafepointSynchronize state and further mem refs
__ membar(MacroAssembler::Membar_mask_bits(MacroAssembler::StoreLoad | MacroAssembler::StoreStore), Rtemp);
if (!UseSystemMemoryBarrier) {
__ membar(MacroAssembler::Membar_mask_bits(MacroAssembler::StoreLoad | MacroAssembler::StoreStore), Rtemp);
}
__ safepoint_poll(R2, call_safepoint_runtime);
__ ldr_u32(R3, Address(Rthread, JavaThread::suspend_flags_offset()));

View File

@@ -1007,8 +1007,10 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
__ mov(Rtemp, _thread_in_native_trans);
__ str_32(Rtemp, Address(Rthread, JavaThread::thread_state_offset()));
// Force this write out before the read below
__ membar(MacroAssembler::StoreLoad, Rtemp);
// Force this write out before the read below
if (!UseSystemMemoryBarrier) {
__ membar(MacroAssembler::StoreLoad, Rtemp);
}
// Protect the return value in the interleaved code: save it to callee-save registers.
__ mov(Rsaved_result_lo, R0);

View File

@@ -265,7 +265,9 @@ void DowncallStubGenerator::generate() {
__ sw(t0, Address(xthread, JavaThread::thread_state_offset()));
// Force this write out before the read below
__ membar(MacroAssembler::AnyAny);
if (!UseSystemMemoryBarrier) {
__ membar(MacroAssembler::AnyAny);
}
Label L_after_safepoint_poll;
Label L_safepoint_poll_slow_path;

View File

@@ -44,6 +44,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"
@@ -1746,7 +1747,9 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
__ sw(t0, Address(xthread, JavaThread::thread_state_offset()));
// Force this write out before the read below
__ membar(MacroAssembler::AnyAny);
if (!UseSystemMemoryBarrier) {
__ membar(MacroAssembler::AnyAny);
}
// check for safepoint operation in progress and/or pending suspend requests
{

View File

@@ -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"
@@ -1159,7 +1160,9 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
__ sw(t0, Address(xthread, JavaThread::thread_state_offset()));
// Force this write out before the read below
__ membar(MacroAssembler::AnyAny);
if (!UseSystemMemoryBarrier) {
__ membar(MacroAssembler::AnyAny);
}
// check for safepoint operation in progress and/or pending suspend requests
{

View File

@@ -1838,7 +1838,9 @@ nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm,
save_native_result(masm, ret_type, workspace_slot_offset); // Make Z_R2 available as work reg.
// Force this write out before the read below.
__ z_fence();
if (!UseSystemMemoryBarrier) {
__ z_fence();
}
__ safepoint_poll(sync, Z_R1);

View File

@@ -1525,7 +1525,9 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
// synchronization is progress, and escapes.
__ set_thread_state(_thread_in_native_trans);
__ z_fence();
if (!UseSystemMemoryBarrier) {
__ z_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).

View File

@@ -1772,9 +1772,11 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
__ movl(Address(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));
}
if (AlwaysRestoreFPU) {
// Make sure the control word is correct.

View File

@@ -72,16 +72,17 @@ static int membarrier(int cmd, unsigned int flags, int cpu_id) {
bool LinuxSystemMemoryBarrier::initialize() {
int ret = membarrier(MEMBARRIER_CMD_QUERY, 0, 0);
if (ret < 0) {
log_error(os)("MEMBARRIER_CMD_QUERY unsupported");
log_info(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");
log_info(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");
log_info(os)("Using MEMBARRIER PRIVATE_EXPEDITED");
return true;
}
@@ -89,4 +90,3 @@ void LinuxSystemMemoryBarrier::emit() {
int s = membarrier(MEMBARRIER_CMD_PRIVATE_EXPEDITED, 0, 0);
guarantee_with_errno(s >= 0, "MEMBARRIER_CMD_PRIVATE_EXPEDITED failed");
}

View File

@@ -65,6 +65,7 @@
#include "utilities/parseInteger.hpp"
#include "utilities/powerOfTwo.hpp"
#include "utilities/stringUtils.hpp"
#include "utilities/systemMemoryBarrier.hpp"
#if INCLUDE_JFR
#include "jfr/jfr.hpp"
#endif
@@ -2190,6 +2191,8 @@ jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
os::init_container_support();
SystemMemoryBarrier::initialize();
// Do final processing now that all arguments have been parsed
result = finalize_vm_init_args(patch_mod_javabase);
if (result != JNI_OK) {

View File

@@ -1293,8 +1293,8 @@ 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(bool, UseSystemMemoryBarrier, false, \
"Try to enable system memory barrier if supported by OS") \
\
product(intx, NmethodSweepActivity, 4, \
"Removes cold nmethods from code cache if > 0. Higher values " \

View File

@@ -95,7 +95,6 @@
#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,14 +551,6 @@ 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();

View File

@@ -26,6 +26,8 @@
#define SHARE_UTILITIES_SYSTEMMEMORYBARRIER_HPP
#include "logging/log.hpp"
#include "runtime/globals.hpp"
#include "runtime/globals_extension.hpp"
#include "utilities/globalDefinitions.hpp"
#if defined(LINUX)
@@ -38,7 +40,7 @@ typedef WindowsSystemMemoryBarrier SystemMemoryBarrierDefault;
class NoSystemMemoryBarrier {
public:
static bool initialize() {
log_error(os)("SystemMemoryBarrier not supported on this platform");
log_info(os)("SystemMemoryBarrier not supported on this platform");
return false;
}
static void emit() {
@@ -51,8 +53,17 @@ typedef NoSystemMemoryBarrier SystemMemoryBarrierDefault;
template <typename SystemMemoryBarrierImpl>
class SystemMemoryBarrierType : public AllStatic {
public:
static bool initialize() { return SystemMemoryBarrierImpl::initialize(); }
static void emit() { SystemMemoryBarrierImpl::emit(); }
static void initialize() {
if (UseSystemMemoryBarrier) {
if (!SystemMemoryBarrierImpl::initialize()) {
if (!FLAG_IS_DEFAULT(UseSystemMemoryBarrier)) {
warning("UseSystemMemoryBarrier specified, but not supported on this OS version. Use -Xlog:os=info for details.");
}
FLAG_SET_ERGO(UseSystemMemoryBarrier, false);
}
}
}
static void emit() { SystemMemoryBarrierImpl::emit(); }
};
typedef SystemMemoryBarrierType<SystemMemoryBarrierDefault> SystemMemoryBarrier;