Skip to content

Commit c338f11

Browse files
author
Daniel D. Daugherty
committed
8259349: -XX:AvgMonitorsPerThreadEstimate=1 does not work right
Reviewed-by: coleenp, dholmes
1 parent ccac7aa commit c338f11

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

src/hotspot/share/runtime/globals.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,12 +715,10 @@ const intx ObjectAlignmentInBytes = 8;
715715
"MonitorUsedDeflationThreshold is exceeded (0 is off).") \
716716
range(0, max_jint) \
717717
\
718-
/* notice: the max range value here is max_jint, not max_intx */ \
719-
/* because of overflow issue */ \
720-
product(intx, AvgMonitorsPerThreadEstimate, 1024, DIAGNOSTIC, \
718+
product(size_t, AvgMonitorsPerThreadEstimate, 1024, DIAGNOSTIC, \
721719
"Used to estimate a variable ceiling based on number of threads " \
722720
"for use with MonitorUsedDeflationThreshold (0 is off).") \
723-
range(0, max_jint) \
721+
range(0, max_uintx) \
724722
\
725723
/* notice: the max range value here is max_jint, not max_intx */ \
726724
/* because of overflow issue */ \

src/hotspot/share/runtime/synchronizer.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -235,6 +235,8 @@ void ObjectSynchronizer::initialize() {
235235
for (int i = 0; i < NINFLATIONLOCKS; i++) {
236236
gInflationLocks[i] = new os::PlatformMutex();
237237
}
238+
// Start the ceiling with the estimate for one thread.
239+
set_in_use_list_ceiling(AvgMonitorsPerThreadEstimate);
238240
}
239241

240242
static MonitorList _in_use_list;
@@ -249,10 +251,9 @@ static MonitorList _in_use_list;
249251
// of the thread count derived ceiling because we have used more
250252
// ObjectMonitors than the estimated average.
251253
//
252-
// Start the ceiling with the estimate for one thread.
253-
// This is a 'jint' because the range of AvgMonitorsPerThreadEstimate
254-
// is 0..max_jint:
255-
static jint _in_use_list_ceiling = AvgMonitorsPerThreadEstimate;
254+
// Start the ceiling with the estimate for one thread in initialize()
255+
// which is called after cmd line options are processed.
256+
static size_t _in_use_list_ceiling = 0;
256257
bool volatile ObjectSynchronizer::_is_async_deflation_requested = false;
257258
bool volatile ObjectSynchronizer::_is_final_audit = false;
258259
jlong ObjectSynchronizer::_last_async_deflation_time_ns = 0;
@@ -1159,22 +1160,19 @@ static bool monitors_used_above_threshold(MonitorList* list) {
11591160
}
11601161

11611162
size_t ObjectSynchronizer::in_use_list_ceiling() {
1162-
// _in_use_list_ceiling is a jint so this cast could lose precision,
1163-
// but in reality the ceiling should never get that high.
1164-
return (size_t)_in_use_list_ceiling;
1163+
return _in_use_list_ceiling;
11651164
}
11661165

11671166
void ObjectSynchronizer::dec_in_use_list_ceiling() {
1168-
Atomic::add(&_in_use_list_ceiling, (jint)-AvgMonitorsPerThreadEstimate);
1169-
#ifdef ASSERT
1170-
size_t l_in_use_list_ceiling = in_use_list_ceiling();
1171-
#endif
1172-
assert(l_in_use_list_ceiling > 0, "in_use_list_ceiling=" SIZE_FORMAT
1173-
": must be > 0", l_in_use_list_ceiling);
1167+
Atomic::add(&_in_use_list_ceiling, -AvgMonitorsPerThreadEstimate);
11741168
}
11751169

11761170
void ObjectSynchronizer::inc_in_use_list_ceiling() {
1177-
Atomic::add(&_in_use_list_ceiling, (jint)AvgMonitorsPerThreadEstimate);
1171+
Atomic::add(&_in_use_list_ceiling, AvgMonitorsPerThreadEstimate);
1172+
}
1173+
1174+
void ObjectSynchronizer::set_in_use_list_ceiling(size_t new_value) {
1175+
_in_use_list_ceiling = new_value;
11781176
}
11791177

11801178
bool ObjectSynchronizer::is_async_deflation_needed() {

src/hotspot/share/runtime/synchronizer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -131,6 +131,7 @@ class ObjectSynchronizer : AllStatic {
131131
static size_t in_use_list_ceiling();
132132
static void dec_in_use_list_ceiling();
133133
static void inc_in_use_list_ceiling();
134+
static void set_in_use_list_ceiling(size_t new_value);
134135
static bool is_async_deflation_needed();
135136
static bool is_async_deflation_requested() { return _is_async_deflation_requested; }
136137
static bool is_final_audit() { return _is_final_audit; }

0 commit comments

Comments
 (0)