30
30
#include " runtime/task.hpp"
31
31
#include " runtime/vmOperations.hpp"
32
32
33
- class VM_QueueHead : public VM_None {
34
- public:
35
- VM_QueueHead () : VM_None(" QueueHead" ) {}
36
- };
37
-
38
- //
39
- // Prioritized queue of VM operations.
40
- //
41
- // Encapsulates both queue management and
42
- // and priority policy
43
- //
44
- class VMOperationQueue : public CHeapObj <mtInternal> {
45
- private:
46
- enum Priorities {
47
- SafepointPriority, // Highest priority (operation executed at a safepoint)
48
- MediumPriority, // Medium priority
49
- nof_priorities
50
- };
51
-
52
- // We maintain a doubled linked list, with explicit count.
53
- int _queue_length[nof_priorities];
54
- int _queue_counter;
55
- VM_Operation* _queue [nof_priorities];
56
-
57
- static VM_QueueHead _queue_head[nof_priorities];
58
-
59
- // Double-linked non-empty list insert.
60
- void insert (VM_Operation* q,VM_Operation* n);
61
- void unlink (VM_Operation* q);
62
-
63
- // Basic queue manipulation
64
- bool queue_empty (int prio);
65
- void queue_add (int prio, VM_Operation *op);
66
- VM_Operation* queue_remove_front (int prio);
67
- // lock-free query: may return the wrong answer but must not break
68
- bool queue_peek (int prio) { return _queue_length[prio] > 0 ; }
69
-
70
- public:
71
- VMOperationQueue ();
72
-
73
- // Highlevel operations. Encapsulates policy
74
- void add (VM_Operation *op);
75
- VM_Operation* remove_next (); // Returns next or null
76
- bool peek_at_safepoint_priority () { return queue_peek (SafepointPriority); }
77
- };
78
-
79
-
80
33
// VM operation timeout handling: warn or abort the VM when VM operation takes
81
34
// too long. Periodic tasks do not participate in safepoint protocol, and therefore
82
35
// can fire when application threads are stopped.
@@ -114,9 +67,12 @@ class VMThread: public NamedThread {
114
67
115
68
static VMOperationTimeoutTask* _timeout_task;
116
69
117
- static VM_Operation* no_op_safepoint ();
70
+ static bool handshake_alot ();
71
+ static void setup_periodic_safepoint_if_needed ();
118
72
119
73
void evaluate_operation (VM_Operation* op);
74
+ void inner_execute (VM_Operation* op);
75
+ void wait_for_operation ();
120
76
121
77
public:
122
78
// Constructor
@@ -143,16 +99,26 @@ class VMThread: public NamedThread {
143
99
static void execute (VM_Operation* op);
144
100
145
101
// Returns the current vm operation if any.
146
- static VM_Operation* vm_operation () { return _cur_vm_operation; }
147
- static VM_Operation::VMOp_Type vm_op_type () { return _cur_vm_operation->type (); }
102
+ static VM_Operation* vm_operation () {
103
+ assert (Thread::current ()->is_VM_thread (), " Must be" );
104
+ return _cur_vm_operation;
105
+ }
106
+
107
+ static VM_Operation::VMOp_Type vm_op_type () {
108
+ VM_Operation* op = vm_operation ();
109
+ assert (op != NULL , " sanity" );
110
+ return op->type ();
111
+ }
148
112
149
113
// Returns the single instance of VMThread.
150
114
static VMThread* vm_thread () { return _vm_thread; }
151
115
152
116
void verify ();
153
117
154
118
// Performance measurement
155
- static PerfCounter* perf_accumulated_vm_operation_time () { return _perf_accumulated_vm_operation_time; }
119
+ static PerfCounter* perf_accumulated_vm_operation_time () {
120
+ return _perf_accumulated_vm_operation_time;
121
+ }
156
122
157
123
// Entry for starting vm thread
158
124
virtual void run ();
@@ -161,10 +127,14 @@ class VMThread: public NamedThread {
161
127
static void create ();
162
128
static void destroy ();
163
129
130
+ static void wait_until_executed (VM_Operation* op);
131
+
164
132
private:
165
133
// VM_Operation support
166
134
static VM_Operation* _cur_vm_operation; // Current VM operation
167
- static VMOperationQueue* _vm_queue; // Queue (w/ policy) of VM operations
135
+ static VM_Operation* _next_vm_operation; // Next VM operation
136
+
137
+ bool set_next_operation (VM_Operation *op); // Set the _next_vm_operation if possible.
168
138
169
139
// Pointer to single-instance of VM thread
170
140
static VMThread* _vm_thread;
0 commit comments