8209850: Allow NamedThreads to use GlobalCounter critical sections

Add NamedThreads iterator and make GlobalCounter use it.

Reviewed-by: eosterlund, rehn
This commit is contained in:
Kim Barrett 2018-08-23 18:14:53 -04:00
parent 8b138c684a
commit 23f0fb4cde
11 changed files with 458 additions and 69 deletions

View file

@ -103,6 +103,7 @@ class WorkerThread;
// - JavaThread
// - various subclasses eg CompilerThread, ServiceThread
// - WatcherThread
// - JfrSamplerThread
class Thread: public ThreadShadow {
friend class VMStructs;
@ -776,6 +777,10 @@ class NamedThread: public Thread {
// log JavaThread being processed by oops_do
JavaThread* _processed_thread;
uint _gc_id; // The current GC id when a thread takes part in GC
NamedThread* volatile _next_named_thread;
class List;
static List _the_list;
public:
NamedThread();
@ -791,6 +796,31 @@ class NamedThread: public Thread {
void set_gc_id(uint gc_id) { _gc_id = gc_id; }
uint gc_id() { return _gc_id; }
class Iterator;
};
// Provides iteration over the list of NamedThreads. Because list
// management occurs in the NamedThread constructor and destructor,
// entries in the list may not be fully constructed instances of a
// derived class. Threads created after an iterator is constructed
// will not be visited by the iterator. The scope of an iterator is a
// critical section; there must be no safepoint checks in that scope.
class NamedThread::Iterator : public StackObj {
uint _protect_enter;
NamedThread* _current;
// Noncopyable.
Iterator(const Iterator&);
Iterator& operator=(const Iterator&);
public:
Iterator();
~Iterator();
bool end() const { return _current == NULL; }
NamedThread* current() const { return _current; }
void step();
};
// Worker threads are named and have an id of an assigned work.