diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index f8e9629d94a..9ff8b878692 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -3646,6 +3646,11 @@ jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) { apply_debugger_ergo(); + // The VMThread needs to stop now and then to execute these debug options. + if ((HandshakeALot || SafepointALot) && FLAG_IS_DEFAULT(GuaranteedSafepointInterval)) { + FLAG_SET_DEFAULT(GuaranteedSafepointInterval, 1000); + } + if (log_is_enabled(Info, arguments)) { LogStream st(Log(arguments)::info()); Arguments::print_on(&st); diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp index ef6c0dcd9f6..d62403a29d5 100644 --- a/src/hotspot/share/runtime/globals.hpp +++ b/src/hotspot/share/runtime/globals.hpp @@ -744,9 +744,8 @@ const int ObjectAlignmentInBytes = 8; \ product(int, MonitorUsedDeflationThreshold, 90, DIAGNOSTIC, \ "Percentage of used monitors before triggering deflation (0 is " \ - "off). The check is performed on GuaranteedSafepointInterval, " \ - "AsyncDeflationInterval or GuaranteedAsyncDeflationInterval, " \ - "whichever is lower.") \ + "off). The check is performed on AsyncDeflationInterval or " \ + "GuaranteedAsyncDeflationInterval, whichever is lower.") \ range(0, 100) \ \ product(uintx, NoAsyncDeflationProgressMax, 3, DIAGNOSTIC, \ @@ -1277,7 +1276,7 @@ const int ObjectAlignmentInBytes = 8; \ /* notice: the max range value here is max_jint, not max_intx */ \ /* because of overflow issue */ \ - product(intx, GuaranteedSafepointInterval, 1000, DIAGNOSTIC, \ + product(intx, GuaranteedSafepointInterval, 0, DIAGNOSTIC, \ "Guarantee a safepoint (at least) every so many milliseconds " \ "(0 means none)") \ range(0, max_jint) \ diff --git a/src/hotspot/share/runtime/monitorDeflationThread.cpp b/src/hotspot/share/runtime/monitorDeflationThread.cpp index d3109c07c16..128e1dd1a71 100644 --- a/src/hotspot/share/runtime/monitorDeflationThread.cpp +++ b/src/hotspot/share/runtime/monitorDeflationThread.cpp @@ -50,11 +50,7 @@ void MonitorDeflationThread::initialize() { void MonitorDeflationThread::monitor_deflation_thread_entry(JavaThread* jt, TRAPS) { - // We wait for the lowest of these three intervals: - // - GuaranteedSafepointInterval - // While deflation is not related to safepoint anymore, this keeps compatibility with - // the old behavior when deflation also happened at safepoints. Users who set this - // option to get more/less frequent deflations would be served with this option. + // We wait for the lowest of these two intervals: // - AsyncDeflationInterval // Normal threshold-based deflation heuristic checks the conditions at this interval. // See is_async_deflation_needed(). @@ -63,9 +59,6 @@ void MonitorDeflationThread::monitor_deflation_thread_entry(JavaThread* jt, TRAP // See is_async_deflation_needed(). // intx wait_time = max_intx; - if (GuaranteedSafepointInterval > 0) { - wait_time = MIN2(wait_time, GuaranteedSafepointInterval); - } if (AsyncDeflationInterval > 0) { wait_time = MIN2(wait_time, AsyncDeflationInterval); } diff --git a/src/hotspot/share/runtime/vmThread.cpp b/src/hotspot/share/runtime/vmThread.cpp index de0567ab037..8ed212d515a 100644 --- a/src/hotspot/share/runtime/vmThread.cpp +++ b/src/hotspot/share/runtime/vmThread.cpp @@ -308,40 +308,26 @@ class HandshakeALotClosure : public HandshakeClosure { } }; -bool VMThread::handshake_alot() { +bool VMThread::handshake_or_safepoint_alot() { assert(_cur_vm_operation == nullptr, "should not have an op yet"); assert(_next_vm_operation == nullptr, "should not have an op yet"); - if (!HandshakeALot) { + if (!HandshakeALot && !SafepointALot) { return false; } - static jlong last_halot_ms = 0; + static jlong last_alot_ms = 0; jlong now_ms = nanos_to_millis(os::javaTimeNanos()); - // If only HandshakeALot is set, but GuaranteedSafepointInterval is 0, - // we emit a handshake if it's been more than a second since the last one. + // If HandshakeALot or SafepointALot are set, but GuaranteedSafepointInterval is explicitly + // set to 0 on the command line, we emit the operation if it's been more than a second + // since the last one. jlong interval = GuaranteedSafepointInterval != 0 ? GuaranteedSafepointInterval : 1000; - jlong deadline_ms = interval + last_halot_ms; + jlong deadline_ms = interval + last_alot_ms; if (now_ms > deadline_ms) { - last_halot_ms = now_ms; + last_alot_ms = now_ms; return true; } return false; } -void VMThread::setup_periodic_safepoint_if_needed() { - assert(_cur_vm_operation == nullptr, "Already have an op"); - assert(_next_vm_operation == nullptr, "Already have an op"); - // Check for a cleanup before SafepointALot to keep stats correct. - jlong interval_ms = SafepointTracing::time_since_last_safepoint_ms(); - bool max_time_exceeded = GuaranteedSafepointInterval != 0 && - (interval_ms >= GuaranteedSafepointInterval); - if (!max_time_exceeded) { - return; - } - if (SafepointALot) { - _next_vm_operation = &safepointALot_op; - } -} - bool VMThread::set_next_operation(VM_Operation *op) { if (_next_vm_operation != nullptr) { return false; @@ -465,8 +451,8 @@ void VMThread::wait_for_operation() { if (_next_vm_operation != nullptr) { return; } - if (handshake_alot()) { - { + if (handshake_or_safepoint_alot()) { + if (HandshakeALot) { MutexUnlocker mul(VMOperation_lock); HandshakeALotClosure hal_cl; Handshake::execute(&hal_cl); @@ -475,15 +461,14 @@ void VMThread::wait_for_operation() { if (_next_vm_operation != nullptr) { return; } + if (SafepointALot) { + _next_vm_operation = &safepointALot_op; + return; + } } assert(_next_vm_operation == nullptr, "Must be"); assert(_cur_vm_operation == nullptr, "Must be"); - setup_periodic_safepoint_if_needed(); - if (_next_vm_operation != nullptr) { - return; - } - // We didn't find anything to execute, notify any waiter so they can install an op. ml_op_lock.notify_all(); ml_op_lock.wait(GuaranteedSafepointInterval); diff --git a/src/hotspot/share/runtime/vmThread.hpp b/src/hotspot/share/runtime/vmThread.hpp index 6c87544acab..668ea4ce4e2 100644 --- a/src/hotspot/share/runtime/vmThread.hpp +++ b/src/hotspot/share/runtime/vmThread.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2024, 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 @@ -70,8 +70,7 @@ class VMThread: public NamedThread { static VMOperationTimeoutTask* _timeout_task; - static bool handshake_alot(); - static void setup_periodic_safepoint_if_needed(); + static bool handshake_or_safepoint_alot(); void evaluate_operation(VM_Operation* op); void inner_execute(VM_Operation* op);