author | chagedorn |
Wed, 02 Oct 2019 08:27:17 +0200 | |
changeset 58438 | 1181f58f30e2 |
parent 55128 | 35192d9c2b76 |
child 59325 | 3636bab5e81e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53020
diff
changeset
|
2 |
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4489
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4489
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4489
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53020
diff
changeset
|
25 |
#ifndef SHARE_RUNTIME_VMTHREAD_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53020
diff
changeset
|
26 |
#define SHARE_RUNTIME_VMTHREAD_HPP |
7397 | 27 |
|
28 |
#include "runtime/perfData.hpp" |
|
37456 | 29 |
#include "runtime/thread.hpp" |
53020
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
30 |
#include "runtime/task.hpp" |
52877
9e041366c764
8214850: Rename vm_operations.?pp files to vmOperations.?pp files
tschatzl
parents:
47216
diff
changeset
|
31 |
#include "runtime/vmOperations.hpp" |
7397 | 32 |
|
1 | 33 |
// |
34 |
// Prioritized queue of VM operations. |
|
35 |
// |
|
36 |
// Encapsulates both queue management and |
|
37 |
// and priority policy |
|
38 |
// |
|
13195 | 39 |
class VMOperationQueue : public CHeapObj<mtInternal> { |
1 | 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]; |
|
51 |
// we also allow the vmThread to register the ops it has drained so we |
|
52 |
// can scan them from oops_do |
|
53 |
VM_Operation* _drain_list; |
|
54 |
||
55 |
// Double-linked non-empty list insert. |
|
56 |
void insert(VM_Operation* q,VM_Operation* n); |
|
57 |
void unlink(VM_Operation* q); |
|
58 |
||
59 |
// Basic queue manipulation |
|
60 |
bool queue_empty (int prio); |
|
61 |
void queue_add_front (int prio, VM_Operation *op); |
|
62 |
void queue_add_back (int prio, VM_Operation *op); |
|
63 |
VM_Operation* queue_remove_front(int prio); |
|
64 |
void queue_oops_do(int queue, OopClosure* f); |
|
65 |
void drain_list_oops_do(OopClosure* f); |
|
66 |
VM_Operation* queue_drain(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 |
|
55128
35192d9c2b76
8225016: Dead code due to VMOperationQueue::add() always returning true
pchilanomate
parents:
54278
diff
changeset
|
74 |
void add(VM_Operation *op); |
1 | 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 |
||
53020
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
88 |
// VM operation timeout handling: warn or abort the VM when VM operation takes |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
89 |
// too long. Periodic tasks do not participate in safepoint protocol, and therefore |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
90 |
// can fire when application threads are stopped. |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
91 |
|
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
92 |
class VMOperationTimeoutTask : public PeriodicTask { |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
93 |
private: |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
94 |
volatile int _armed; |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
95 |
jlong _arm_time; |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
96 |
|
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
97 |
public: |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
98 |
VMOperationTimeoutTask(size_t interval_time) : |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
99 |
PeriodicTask(interval_time), _armed(0), _arm_time(0) {} |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
100 |
|
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
101 |
virtual void task(); |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
102 |
|
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
103 |
bool is_armed(); |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
104 |
void arm(); |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
105 |
void disarm(); |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
106 |
}; |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
107 |
|
1 | 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 |
||
4489
514173c9a0c2
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
3908
diff
changeset
|
114 |
class VMThread: public NamedThread { |
1 | 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; |
|
53895 | 122 |
static uint64_t _coalesced_count; |
46496 | 123 |
|
53020
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
124 |
static VMOperationTimeoutTask* _timeout_task; |
c403f39ec349
8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents:
52877
diff
changeset
|
125 |
|
54278 | 126 |
static VM_Operation* no_op_safepoint(); |
46496 | 127 |
|
1 | 128 |
void evaluate_operation(VM_Operation* op); |
46496 | 129 |
|
1 | 130 |
public: |
131 |
// Constructor |
|
132 |
VMThread(); |
|
133 |
||
38290
6b194cfc1557
8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents:
38074
diff
changeset
|
134 |
// No destruction allowed |
6b194cfc1557
8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents:
38074
diff
changeset
|
135 |
~VMThread() { |
6b194cfc1557
8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents:
38074
diff
changeset
|
136 |
guarantee(false, "VMThread deletion must fix the race with VM termination"); |
6b194cfc1557
8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents:
38074
diff
changeset
|
137 |
} |
6b194cfc1557
8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents:
38074
diff
changeset
|
138 |
|
6b194cfc1557
8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents:
38074
diff
changeset
|
139 |
|
1 | 140 |
// Tester |
141 |
bool is_VM_thread() const { return true; } |
|
142 |
bool is_GC_thread() const { return true; } |
|
143 |
||
144 |
// The ever running loop for the VMThread |
|
145 |
void loop(); |
|
146 |
||
147 |
// Called to stop the VM thread |
|
148 |
static void wait_for_vm_thread_exit(); |
|
149 |
static bool should_terminate() { return _should_terminate; } |
|
150 |
static bool is_terminated() { return _terminated == true; } |
|
151 |
||
152 |
// Execution of vm operation |
|
153 |
static void execute(VM_Operation* op); |
|
154 |
||
155 |
// Returns the current vm operation if any. |
|
46496 | 156 |
static VM_Operation* vm_operation() { return _cur_vm_operation; } |
53895 | 157 |
static VM_Operation::VMOp_Type vm_op_type() { return _cur_vm_operation->type(); } |
158 |
static uint64_t get_coalesced_count() { return _coalesced_count; } |
|
1 | 159 |
|
160 |
// Returns the single instance of VMThread. |
|
161 |
static VMThread* vm_thread() { return _vm_thread; } |
|
162 |
||
163 |
// GC support |
|
38074
8475fdc6dcc3
8154580: Save mirror in interpreter frame to enable cleanups of CLDClosure
coleenp
parents:
37456
diff
changeset
|
164 |
void oops_do(OopClosure* f, CodeBlobClosure* cf); |
1 | 165 |
|
166 |
void verify(); |
|
167 |
||
168 |
// Performance measurement |
|
169 |
static PerfCounter* perf_accumulated_vm_operation_time() { return _perf_accumulated_vm_operation_time; } |
|
170 |
||
171 |
// Entry for starting vm thread |
|
172 |
virtual void run(); |
|
173 |
||
174 |
// Creations/Destructions |
|
175 |
static void create(); |
|
176 |
static void destroy(); |
|
177 |
||
178 |
private: |
|
179 |
// VM_Operation support |
|
180 |
static VM_Operation* _cur_vm_operation; // Current VM operation |
|
181 |
static VMOperationQueue* _vm_queue; // Queue (w/ policy) of VM operations |
|
182 |
||
183 |
// Pointer to single-instance of VM thread |
|
184 |
static VMThread* _vm_thread; |
|
185 |
}; |
|
7397 | 186 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53020
diff
changeset
|
187 |
#endif // SHARE_RUNTIME_VMTHREAD_HPP |