Skip to content

Commit 10a6b0d

Browse files
author
Kim Barrett
committedJan 8, 2021
8234773: Fix ThreadsSMRSupport::_bootstrap_list
Make ThreadsList noncopyable, direct initializing _bootstrap_list. Avoid C-heap allocation for _bootstrap_list. Reviewed-by: dholmes, dcubed
1 parent 6f7723b commit 10a6b0d

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed
 

‎src/hotspot/share/runtime/threadSMR.cpp

+21-7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ volatile uint ThreadsSMRSupport::_deleted_thread_time_max = 0;
7676
volatile uint ThreadsSMRSupport::_deleted_thread_times = 0;
7777

7878
// The bootstrap list is empty and cannot be freed.
79-
ThreadsList ThreadsSMRSupport::_bootstrap_list = ThreadsList(0);
79+
ThreadsList ThreadsSMRSupport::_bootstrap_list{0};
8080

8181
// This is the VM's current "threads list" and it contains all of
8282
// the JavaThreads the VM considers to be alive at this moment in
@@ -585,18 +585,32 @@ void SafeThreadsListPtr::verify_hazard_ptr_scanned() {
585585
#endif
586586
}
587587

588-
// 'entries + 1' so we always have at least one entry.
588+
// Shared singleton data for all ThreadsList(0) instances.
589+
// Used by _bootstrap_list to avoid static init time heap allocation.
590+
// No real entries, just the final NULL terminator.
591+
static JavaThread* const empty_threads_list_data[1] = {};
592+
593+
// Result has 'entries + 1' elements, with the last being the NULL terminator.
594+
static JavaThread* const* make_threads_list_data(int entries) {
595+
if (entries == 0) {
596+
return empty_threads_list_data;
597+
}
598+
JavaThread** data = NEW_C_HEAP_ARRAY(JavaThread*, entries + 1, mtThread);
599+
data[entries] = NULL; // Make sure the final entry is NULL.
600+
return data;
601+
}
602+
589603
ThreadsList::ThreadsList(int entries) :
590604
_length(entries),
591605
_next_list(NULL),
592-
_threads(NEW_C_HEAP_ARRAY(JavaThread*, entries + 1, mtThread)),
606+
_threads(make_threads_list_data(entries)),
593607
_nested_handle_cnt(0)
594-
{
595-
*(JavaThread**)(_threads + entries) = NULL; // Make sure the extra entry is NULL.
596-
}
608+
{}
597609

598610
ThreadsList::~ThreadsList() {
599-
FREE_C_HEAP_ARRAY(JavaThread*, _threads);
611+
if (_threads != empty_threads_list_data) {
612+
FREE_C_HEAP_ARRAY(JavaThread*, _threads);
613+
}
600614
}
601615

602616
// Add a JavaThread to a ThreadsList. The returned ThreadsList is a

‎src/hotspot/share/runtime/threadSMR.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ class ThreadsList : public CHeapObj<mtThread> {
172172
JavaThread *const *const _threads;
173173
volatile intx _nested_handle_cnt;
174174

175+
NONCOPYABLE(ThreadsList);
176+
175177
template <class T>
176178
void threads_do_dispatch(T *cl, JavaThread *const thread) const;
177179

@@ -185,7 +187,7 @@ class ThreadsList : public CHeapObj<mtThread> {
185187
static ThreadsList* remove_thread(ThreadsList* list, JavaThread* java_thread);
186188

187189
public:
188-
ThreadsList(int entries);
190+
explicit ThreadsList(int entries);
189191
~ThreadsList();
190192

191193
template <class T>

0 commit comments

Comments
 (0)
Please sign in to comment.