Skip to content

Commit

Permalink
8325872: Make GuaranteedSafepointInterval default 0
Browse files Browse the repository at this point in the history
Reviewed-by: shade, eosterlund, dcubed
  • Loading branch information
coleenp committed Apr 18, 2024
1 parent b049609 commit 60b65e6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 44 deletions.
5 changes: 5 additions & 0 deletions src/hotspot/share/runtime/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions src/hotspot/share/runtime/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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) \
Expand Down
9 changes: 1 addition & 8 deletions src/hotspot/share/runtime/monitorDeflationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand All @@ -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);
}
Expand Down
43 changes: 14 additions & 29 deletions src/hotspot/share/runtime/vmThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/runtime/vmThread.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down

1 comment on commit 60b65e6

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.