58 }
59
60 void ConcurrentGCThread::wait_for_universe_init() {
61 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
62 while (!is_init_completed() && !_should_terminate) {
63 CGC_lock->wait(Mutex::_no_safepoint_check_flag, 1);
64 }
65 }
66
67 void ConcurrentGCThread::terminate() {
68 assert(_should_terminate, "Should only be called on terminate request.");
69 // Signal that it is terminated
70 {
71 MutexLockerEx mu(Terminator_lock,
72 Mutex::_no_safepoint_check_flag);
73 _has_terminated = true;
74 Terminator_lock->notify();
75 }
76 }
77
78 static void _sltLoop(JavaThread* thread, TRAPS) {
79 SurrogateLockerThread* slt = (SurrogateLockerThread*)thread;
80 slt->loop();
81 }
82
83 SurrogateLockerThread::SurrogateLockerThread() :
84 JavaThread(&_sltLoop),
85 _monitor(Mutex::nonleaf, "SLTMonitor", false,
86 Monitor::_safepoint_check_sometimes),
87 _buffer(empty)
88 {}
89
90 SurrogateLockerThread* SurrogateLockerThread::make(TRAPS) {
91 Klass* k =
92 SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(),
93 true, CHECK_NULL);
94 instanceKlassHandle klass (THREAD, k);
95 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL);
96
97 const char thread_name[] = "Surrogate Locker Thread (Concurrent GC)";
|
58 }
59
60 void ConcurrentGCThread::wait_for_universe_init() {
61 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
62 while (!is_init_completed() && !_should_terminate) {
63 CGC_lock->wait(Mutex::_no_safepoint_check_flag, 1);
64 }
65 }
66
67 void ConcurrentGCThread::terminate() {
68 assert(_should_terminate, "Should only be called on terminate request.");
69 // Signal that it is terminated
70 {
71 MutexLockerEx mu(Terminator_lock,
72 Mutex::_no_safepoint_check_flag);
73 _has_terminated = true;
74 Terminator_lock->notify();
75 }
76 }
77
78 void ConcurrentGCThread::run() {
79 initialize_in_thread();
80 wait_for_universe_init();
81
82 run_service();
83
84 terminate();
85 }
86
87 void ConcurrentGCThread::stop() {
88 // it is ok to take late safepoints here, if needed
89 {
90 MutexLockerEx mu(Terminator_lock);
91 _should_terminate = true;
92 }
93
94 stop_service();
95
96 {
97 MutexLockerEx mu(Terminator_lock);
98 while (!_has_terminated) {
99 Terminator_lock->wait();
100 }
101 }
102 }
103
104 static void _sltLoop(JavaThread* thread, TRAPS) {
105 SurrogateLockerThread* slt = (SurrogateLockerThread*)thread;
106 slt->loop();
107 }
108
109 SurrogateLockerThread::SurrogateLockerThread() :
110 JavaThread(&_sltLoop),
111 _monitor(Mutex::nonleaf, "SLTMonitor", false,
112 Monitor::_safepoint_check_sometimes),
113 _buffer(empty)
114 {}
115
116 SurrogateLockerThread* SurrogateLockerThread::make(TRAPS) {
117 Klass* k =
118 SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(),
119 true, CHECK_NULL);
120 instanceKlassHandle klass (THREAD, k);
121 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL);
122
123 const char thread_name[] = "Surrogate Locker Thread (Concurrent GC)";
|