Mercurial > hg > truffle
comparison src/share/vm/gc_implementation/shared/concurrentGCThread.hpp @ 20192:581e70386ec9
8039147: Cleanup SuspendibleThreadSet
Reviewed-by: brutisso, tschatzl, mgerdin
author | pliden |
---|---|
date | Fri, 11 Apr 2014 12:29:24 +0200 |
parents | 55fb97c4c58d |
children | 4e4ebe50c8e3 |
comparison
equal
deleted
inserted
replaced
20191:fd81a5764900 | 20192:581e70386ec9 |
---|---|
24 | 24 |
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP | 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP |
26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP | 26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP |
27 | 27 |
28 #include "utilities/macros.hpp" | 28 #include "utilities/macros.hpp" |
29 #if INCLUDE_ALL_GCS | 29 #include "gc_implementation/shared/suspendibleThreadSet.hpp" |
30 #include "runtime/thread.hpp" | 30 #include "runtime/thread.hpp" |
31 #endif // INCLUDE_ALL_GCS | |
32 | |
33 class VoidClosure; | |
34 | |
35 // A SuspendibleThreadSet is (obviously) a set of threads that can be | |
36 // suspended. A thread can join and later leave the set, and periodically | |
37 // yield. If some thread (not in the set) requests, via suspend_all, that | |
38 // the threads be suspended, then the requesting thread is blocked until | |
39 // all the threads in the set have yielded or left the set. (Threads may | |
40 // not enter the set when an attempted suspension is in progress.) The | |
41 // suspending thread later calls resume_all, allowing the suspended threads | |
42 // to continue. | |
43 | |
44 class SuspendibleThreadSet { | |
45 Monitor* _m; | |
46 int _async; | |
47 bool _async_stop; | |
48 int _async_stopped; | |
49 bool _initialized; | |
50 double _suspend_all_start; | |
51 | |
52 void initialize_work(); | |
53 | |
54 public: | |
55 SuspendibleThreadSet() : _initialized(false) {} | |
56 | |
57 // Add the current thread to the set. May block if a suspension | |
58 // is in progress. | |
59 void join(); | |
60 // Removes the current thread from the set. | |
61 void leave(); | |
62 // Returns "true" iff an suspension is in progress. | |
63 bool should_yield() { return _async_stop; } | |
64 // Suspends the current thread if a suspension is in progress (for | |
65 // the duration of the suspension.) | |
66 void yield(const char* id); | |
67 // Return when all threads in the set are suspended. | |
68 void suspend_all(); | |
69 // Allow suspended threads to resume. | |
70 void resume_all(); | |
71 // Redundant initializations okay. | |
72 void initialize() { | |
73 // Double-check dirty read idiom. | |
74 if (!_initialized) initialize_work(); | |
75 } | |
76 }; | |
77 | |
78 | 31 |
79 class ConcurrentGCThread: public NamedThread { | 32 class ConcurrentGCThread: public NamedThread { |
80 friend class VMStructs; | 33 friend class VMStructs; |
81 | 34 |
82 protected: | 35 protected: |
93 static int _CGC_flag; | 46 static int _CGC_flag; |
94 | 47 |
95 static bool CGC_flag_is_set(int b) { return (_CGC_flag & b) != 0; } | 48 static bool CGC_flag_is_set(int b) { return (_CGC_flag & b) != 0; } |
96 static int set_CGC_flag(int b) { return _CGC_flag |= b; } | 49 static int set_CGC_flag(int b) { return _CGC_flag |= b; } |
97 static int reset_CGC_flag(int b) { return _CGC_flag &= ~b; } | 50 static int reset_CGC_flag(int b) { return _CGC_flag &= ~b; } |
98 | |
99 // All instances share this one set. | |
100 static SuspendibleThreadSet _sts; | |
101 | 51 |
102 // Create and start the thread (setting it's priority high.) | 52 // Create and start the thread (setting it's priority high.) |
103 void create_and_start(); | 53 void create_and_start(); |
104 | 54 |
105 // Do initialization steps in the thread: record stack base and size, | 55 // Do initialization steps in the thread: record stack base and size, |
119 ConcurrentGCThread(); | 69 ConcurrentGCThread(); |
120 ~ConcurrentGCThread() {} // Exists to call NamedThread destructor. | 70 ~ConcurrentGCThread() {} // Exists to call NamedThread destructor. |
121 | 71 |
122 // Tester | 72 // Tester |
123 bool is_ConcurrentGC_thread() const { return true; } | 73 bool is_ConcurrentGC_thread() const { return true; } |
124 | |
125 static void safepoint_synchronize(); | |
126 static void safepoint_desynchronize(); | |
127 | |
128 // All overridings should probably do _sts::yield, but we allow | |
129 // overriding for distinguished debugging messages. Default is to do | |
130 // nothing. | |
131 virtual void yield() {} | |
132 | |
133 bool should_yield() { return _sts.should_yield(); } | |
134 | |
135 // they are prefixed by sts since there are already yield() and | |
136 // should_yield() (non-static) methods in this class and it was an | |
137 // easy way to differentiate them. | |
138 static void stsYield(const char* id); | |
139 static bool stsShouldYield(); | |
140 static void stsJoin(); | |
141 static void stsLeave(); | |
142 | |
143 }; | 74 }; |
144 | 75 |
145 // The SurrogateLockerThread is used by concurrent GC threads for | 76 // The SurrogateLockerThread is used by concurrent GC threads for |
146 // manipulating Java monitors, in particular, currently for | 77 // manipulating Java monitors, in particular, currently for |
147 // manipulating the pending_list_lock. XXX | 78 // manipulating the pending_list_lock. XXX |