Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8234773: Fix ThreadsSMRSupport::_bootstrap_list #1921

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/hotspot/share/runtime/threadSMR.cpp
Expand Up @@ -76,7 +76,7 @@ volatile uint ThreadsSMRSupport::_deleted_thread_time_max = 0;
volatile uint ThreadsSMRSupport::_deleted_thread_times = 0;

// The bootstrap list is empty and cannot be freed.
ThreadsList ThreadsSMRSupport::_bootstrap_list = ThreadsList(0);
ThreadsList ThreadsSMRSupport::_bootstrap_list{0};
Copy link
Member

Choose a reason for hiding this comment

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

To anyone unfamiliar with the details of direct initialization this is very obscure. I don't know how to interpret this given a ThreadsList has four member fields. Wouldn't {} have the same effect of implicitly zero-initializing all the fields?
Stylistically I find this syntax jarring, an equals sign in there would look far more natural to me. :(


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

// 'entries + 1' so we always have at least one entry.
// Shared singleton data for all ThreadsList(0) instances.
// Used by _bootstrap_list to avoid static init time heap allocation.
// No real entries, just the final NULL terminator.
static JavaThread* const empty_threads_list_data[1] = {};

// Result has 'entries + 1' elements, with the last being the NULL terminator.
static JavaThread* const* make_threads_list_data(int entries) {
if (entries == 0) {
return empty_threads_list_data;
}
JavaThread** data = NEW_C_HEAP_ARRAY(JavaThread*, entries + 1, mtThread);
data[entries] = NULL; // Make sure the final entry is NULL.
return data;
}

ThreadsList::ThreadsList(int entries) :
_length(entries),
_next_list(NULL),
_threads(NEW_C_HEAP_ARRAY(JavaThread*, entries + 1, mtThread)),
_threads(make_threads_list_data(entries)),
_nested_handle_cnt(0)
{
*(JavaThread**)(_threads + entries) = NULL; // Make sure the extra entry is NULL.
}
{}

ThreadsList::~ThreadsList() {
FREE_C_HEAP_ARRAY(JavaThread*, _threads);
if (_threads != empty_threads_list_data) {
FREE_C_HEAP_ARRAY(JavaThread*, _threads);
}
}

// Add a JavaThread to a ThreadsList. The returned ThreadsList is a
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/runtime/threadSMR.hpp
Expand Up @@ -172,6 +172,8 @@ class ThreadsList : public CHeapObj<mtThread> {
JavaThread *const *const _threads;
volatile intx _nested_handle_cnt;

NONCOPYABLE(ThreadsList);

template <class T>
void threads_do_dispatch(T *cl, JavaThread *const thread) const;

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

public:
ThreadsList(int entries);
explicit ThreadsList(int entries);
~ThreadsList();

template <class T>
Expand Down