mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8209976: Improve iteration over non-JavaThreads
Add NonJavaThread and move NamedThread iteration to new class. Reviewed-by: eosterlund, coleenp, rkennke
This commit is contained in:
parent
1ddabdf0dc
commit
e1059f1301
8 changed files with 107 additions and 121 deletions
|
@ -93,16 +93,21 @@ class WorkerThread;
|
|||
|
||||
// Class hierarchy
|
||||
// - Thread
|
||||
// - NamedThread
|
||||
// - VMThread
|
||||
// - ConcurrentGCThread
|
||||
// - WorkerThread
|
||||
// - GangWorker
|
||||
// - GCTaskThread
|
||||
// - JavaThread
|
||||
// - various subclasses eg CompilerThread, ServiceThread
|
||||
// - WatcherThread
|
||||
// - JfrSamplerThread
|
||||
// - NonJavaThread
|
||||
// - NamedThread
|
||||
// - VMThread
|
||||
// - ConcurrentGCThread
|
||||
// - WorkerThread
|
||||
// - GangWorker
|
||||
// - GCTaskThread
|
||||
// - WatcherThread
|
||||
// - JfrThreadSampler
|
||||
//
|
||||
// All Thread subclasses must be either JavaThread or NonJavaThread.
|
||||
// This means !t->is_Java_thread() iff t is a NonJavaThread, or t is
|
||||
// a partially constructed/destroyed Thread.
|
||||
|
||||
class Thread: public ThreadShadow {
|
||||
friend class VMStructs;
|
||||
|
@ -380,7 +385,7 @@ class Thread: public ThreadShadow {
|
|||
|
||||
// Constructor
|
||||
Thread();
|
||||
virtual ~Thread();
|
||||
virtual ~Thread() = 0; // Thread is abstract.
|
||||
|
||||
// Manage Thread::current()
|
||||
void initialize_thread_current();
|
||||
|
@ -764,9 +769,47 @@ inline Thread* Thread::current_or_null_safe() {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
class NonJavaThread: public Thread {
|
||||
friend class VMStructs;
|
||||
|
||||
NonJavaThread* volatile _next;
|
||||
|
||||
class List;
|
||||
static List _the_list;
|
||||
|
||||
public:
|
||||
NonJavaThread();
|
||||
~NonJavaThread();
|
||||
|
||||
class Iterator;
|
||||
};
|
||||
|
||||
// Provides iteration over the list of NonJavaThreads. Because list
|
||||
// management occurs in the NonJavaThread 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 NonJavaThread::Iterator : public StackObj {
|
||||
uint _protect_enter;
|
||||
NonJavaThread* _current;
|
||||
|
||||
// Noncopyable.
|
||||
Iterator(const Iterator&);
|
||||
Iterator& operator=(const Iterator&);
|
||||
|
||||
public:
|
||||
Iterator();
|
||||
~Iterator();
|
||||
|
||||
bool end() const { return _current == NULL; }
|
||||
NonJavaThread* current() const { return _current; }
|
||||
void step();
|
||||
};
|
||||
|
||||
// Name support for threads. non-JavaThread subclasses with multiple
|
||||
// uniquely named instances should derive from this.
|
||||
class NamedThread: public Thread {
|
||||
class NamedThread: public NonJavaThread {
|
||||
friend class VMStructs;
|
||||
enum {
|
||||
max_name_len = 64
|
||||
|
@ -776,10 +819,6 @@ 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();
|
||||
|
@ -795,31 +834,6 @@ 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.
|
||||
|
@ -840,7 +854,7 @@ class WorkerThread: public NamedThread {
|
|||
};
|
||||
|
||||
// A single WatcherThread is used for simulating timer interrupts.
|
||||
class WatcherThread: public Thread {
|
||||
class WatcherThread: public NonJavaThread {
|
||||
friend class VMStructs;
|
||||
public:
|
||||
virtual void run();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue