10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_RUNTIME_VMTHREAD_HPP
26 #define SHARE_VM_RUNTIME_VMTHREAD_HPP
27
28 #include "runtime/perfData.hpp"
29 #include "runtime/thread.hpp"
30 #include "runtime/vm_operations.hpp"
31
32 //
33 // Prioritized queue of VM operations.
34 //
35 // Encapsulates both queue management and
36 // and priority policy
37 //
38 class VMOperationQueue : public CHeapObj<mtInternal> {
39 private:
40 enum Priorities {
41 SafepointPriority, // Highest priority (operation executed at a safepoint)
42 MediumPriority, // Medium priority
43 nof_priorities
44 };
45
46 // We maintain a doubled linked list, with explicit count.
47 int _queue_length[nof_priorities];
48 int _queue_counter;
49 VM_Operation* _queue [nof_priorities];
67 bool queue_peek(int prio) { return _queue_length[prio] > 0; }
68
69 public:
70 VMOperationQueue();
71
72 // Highlevel operations. Encapsulates policy
73 bool add(VM_Operation *op);
74 VM_Operation* remove_next(); // Returns next or null
75 VM_Operation* remove_next_at_safepoint_priority() { return queue_remove_front(SafepointPriority); }
76 VM_Operation* drain_at_safepoint_priority() { return queue_drain(SafepointPriority); }
77 void set_drain_list(VM_Operation* list) { _drain_list = list; }
78 bool peek_at_safepoint_priority() { return queue_peek(SafepointPriority); }
79
80 // GC support
81 void oops_do(OopClosure* f);
82
83 void verify_queue(int prio) PRODUCT_RETURN;
84 };
85
86
87 //
88 // A single VMThread (the primordial thread) spawns all other threads
89 // and is itself used by other threads to offload heavy vm operations
90 // like scavenge, garbage_collect etc.
91 //
92
93 class VMThread: public NamedThread {
94 private:
95 static ThreadPriority _current_priority;
96
97 static bool _should_terminate;
98 static bool _terminated;
99 static Monitor * _terminate_lock;
100 static PerfCounter* _perf_accumulated_vm_operation_time;
101
102 static const char* _no_op_reason;
103
104 static bool no_op_safepoint_needed(bool check_time);
105
106 void evaluate_operation(VM_Operation* op);
107
108 public:
109 // Constructor
110 VMThread();
111
112 // No destruction allowed
113 ~VMThread() {
114 guarantee(false, "VMThread deletion must fix the race with VM termination");
115 }
116
117
118 // Tester
119 bool is_VM_thread() const { return true; }
120 bool is_GC_thread() const { return true; }
121
122 // The ever running loop for the VMThread
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_RUNTIME_VMTHREAD_HPP
26 #define SHARE_VM_RUNTIME_VMTHREAD_HPP
27
28 #include "runtime/perfData.hpp"
29 #include "runtime/thread.hpp"
30 #include "runtime/task.hpp"
31 #include "runtime/vm_operations.hpp"
32
33 //
34 // Prioritized queue of VM operations.
35 //
36 // Encapsulates both queue management and
37 // and priority policy
38 //
39 class VMOperationQueue : public CHeapObj<mtInternal> {
40 private:
41 enum Priorities {
42 SafepointPriority, // Highest priority (operation executed at a safepoint)
43 MediumPriority, // Medium priority
44 nof_priorities
45 };
46
47 // We maintain a doubled linked list, with explicit count.
48 int _queue_length[nof_priorities];
49 int _queue_counter;
50 VM_Operation* _queue [nof_priorities];
68 bool queue_peek(int prio) { return _queue_length[prio] > 0; }
69
70 public:
71 VMOperationQueue();
72
73 // Highlevel operations. Encapsulates policy
74 bool add(VM_Operation *op);
75 VM_Operation* remove_next(); // Returns next or null
76 VM_Operation* remove_next_at_safepoint_priority() { return queue_remove_front(SafepointPriority); }
77 VM_Operation* drain_at_safepoint_priority() { return queue_drain(SafepointPriority); }
78 void set_drain_list(VM_Operation* list) { _drain_list = list; }
79 bool peek_at_safepoint_priority() { return queue_peek(SafepointPriority); }
80
81 // GC support
82 void oops_do(OopClosure* f);
83
84 void verify_queue(int prio) PRODUCT_RETURN;
85 };
86
87
88 // VM operation timeout handling: warn or abort the VM when VM operation takes
89 // too long. Periodic tasks do not participate in safepoint protocol, and therefore
90 // can fire when application threads are stopped.
91
92 class VMOperationTimeoutTask : public PeriodicTask {
93 private:
94 volatile int _armed;
95 jlong _arm_time;
96
97 public:
98 VMOperationTimeoutTask(size_t interval_time) :
99 PeriodicTask(interval_time), _armed(0), _arm_time(0) {}
100
101 virtual void task();
102
103 bool is_armed();
104 void arm();
105 void disarm();
106 };
107
108 //
109 // A single VMThread (the primordial thread) spawns all other threads
110 // and is itself used by other threads to offload heavy vm operations
111 // like scavenge, garbage_collect etc.
112 //
113
114 class VMThread: public NamedThread {
115 private:
116 static ThreadPriority _current_priority;
117
118 static bool _should_terminate;
119 static bool _terminated;
120 static Monitor * _terminate_lock;
121 static PerfCounter* _perf_accumulated_vm_operation_time;
122
123 static const char* _no_op_reason;
124
125 static VMOperationTimeoutTask* _timeout_task;
126
127 static bool no_op_safepoint_needed(bool check_time);
128
129 void evaluate_operation(VM_Operation* op);
130
131 public:
132 // Constructor
133 VMThread();
134
135 // No destruction allowed
136 ~VMThread() {
137 guarantee(false, "VMThread deletion must fix the race with VM termination");
138 }
139
140
141 // Tester
142 bool is_VM_thread() const { return true; }
143 bool is_GC_thread() const { return true; }
144
145 // The ever running loop for the VMThread
|