author | stefank |
Fri, 21 Feb 2014 10:01:20 +0100 | |
changeset 22899 | e2a6bf7f343a |
parent 14583 | d70ee55535f4 |
child 24331 | c0bc7e5653fb |
permissions | -rw-r--r-- |
1 | 1 |
/* |
13963
e5b53c306fb5
7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents:
13195
diff
changeset
|
2 |
* Copyright (c) 1998, 2012, 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 |
||
7397 | 25 |
#ifndef SHARE_VM_RUNTIME_VMTHREAD_HPP |
26 |
#define SHARE_VM_RUNTIME_VMTHREAD_HPP |
|
27 |
||
28 |
#include "runtime/perfData.hpp" |
|
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
14582
diff
changeset
|
29 |
#include "runtime/thread.inline.hpp" |
7397 | 30 |
#include "runtime/vm_operations.hpp" |
31 |
||
1 | 32 |
// |
33 |
// Prioritized queue of VM operations. |
|
34 |
// |
|
35 |
// Encapsulates both queue management and |
|
36 |
// and priority policy |
|
37 |
// |
|
13195 | 38 |
class VMOperationQueue : public CHeapObj<mtInternal> { |
1 | 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]; |
|
50 |
// we also allow the vmThread to register the ops it has drained so we |
|
51 |
// can scan them from oops_do |
|
52 |
VM_Operation* _drain_list; |
|
53 |
||
54 |
// Double-linked non-empty list insert. |
|
55 |
void insert(VM_Operation* q,VM_Operation* n); |
|
56 |
void unlink(VM_Operation* q); |
|
57 |
||
58 |
// Basic queue manipulation |
|
59 |
bool queue_empty (int prio); |
|
60 |
void queue_add_front (int prio, VM_Operation *op); |
|
61 |
void queue_add_back (int prio, VM_Operation *op); |
|
62 |
VM_Operation* queue_remove_front(int prio); |
|
63 |
void queue_oops_do(int queue, OopClosure* f); |
|
64 |
void drain_list_oops_do(OopClosure* f); |
|
65 |
VM_Operation* queue_drain(int prio); |
|
66 |
// lock-free query: may return the wrong answer but must not break |
|
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 |
||
4489
514173c9a0c2
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
3908
diff
changeset
|
93 |
class VMThread: public NamedThread { |
1 | 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 |
void evaluate_operation(VM_Operation* op); |
|
103 |
public: |
|
104 |
// Constructor |
|
105 |
VMThread(); |
|
106 |
||
107 |
// Tester |
|
108 |
bool is_VM_thread() const { return true; } |
|
109 |
bool is_GC_thread() const { return true; } |
|
110 |
||
111 |
// The ever running loop for the VMThread |
|
112 |
void loop(); |
|
113 |
||
114 |
// Called to stop the VM thread |
|
115 |
static void wait_for_vm_thread_exit(); |
|
116 |
static bool should_terminate() { return _should_terminate; } |
|
117 |
static bool is_terminated() { return _terminated == true; } |
|
118 |
||
119 |
// Execution of vm operation |
|
120 |
static void execute(VM_Operation* op); |
|
121 |
||
122 |
// Returns the current vm operation if any. |
|
123 |
static VM_Operation* vm_operation() { return _cur_vm_operation; } |
|
124 |
||
125 |
// Returns the single instance of VMThread. |
|
126 |
static VMThread* vm_thread() { return _vm_thread; } |
|
127 |
||
128 |
// GC support |
|
22899
e2a6bf7f343a
8035393: Use CLDClosure instead of CLDToOopClosure in frame::oops_interpreted_do
stefank
parents:
14583
diff
changeset
|
129 |
void oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf); |
1 | 130 |
|
131 |
// Debugging |
|
132 |
void print_on(outputStream* st) const; |
|
133 |
void print() const { print_on(tty); } |
|
134 |
void verify(); |
|
135 |
||
136 |
// Performance measurement |
|
137 |
static PerfCounter* perf_accumulated_vm_operation_time() { return _perf_accumulated_vm_operation_time; } |
|
138 |
||
139 |
// Entry for starting vm thread |
|
140 |
virtual void run(); |
|
141 |
||
142 |
// Creations/Destructions |
|
143 |
static void create(); |
|
144 |
static void destroy(); |
|
145 |
||
146 |
private: |
|
147 |
// VM_Operation support |
|
148 |
static VM_Operation* _cur_vm_operation; // Current VM operation |
|
149 |
static VMOperationQueue* _vm_queue; // Queue (w/ policy) of VM operations |
|
150 |
||
151 |
// Pointer to single-instance of VM thread |
|
152 |
static VMThread* _vm_thread; |
|
153 |
}; |
|
7397 | 154 |
|
155 |
#endif // SHARE_VM_RUNTIME_VMTHREAD_HPP |