author | mgerdin |
Thu, 23 Feb 2012 14:58:35 +0100 | |
changeset 12095 | cc3d6f08a4c4 |
parent 10565 | dc90c239f4ec |
child 13195 | be27e1b6a4b9 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
7397 | 2 |
* Copyright (c) 1998, 2010, 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" |
|
29 |
#include "runtime/vm_operations.hpp" |
|
30 |
#ifdef TARGET_OS_FAMILY_linux |
|
31 |
# include "thread_linux.inline.hpp" |
|
32 |
#endif |
|
33 |
#ifdef TARGET_OS_FAMILY_solaris |
|
34 |
# include "thread_solaris.inline.hpp" |
|
35 |
#endif |
|
36 |
#ifdef TARGET_OS_FAMILY_windows |
|
37 |
# include "thread_windows.inline.hpp" |
|
38 |
#endif |
|
10565 | 39 |
#ifdef TARGET_OS_FAMILY_bsd |
40 |
# include "thread_bsd.inline.hpp" |
|
41 |
#endif |
|
7397 | 42 |
|
1 | 43 |
// |
44 |
// Prioritized queue of VM operations. |
|
45 |
// |
|
46 |
// Encapsulates both queue management and |
|
47 |
// and priority policy |
|
48 |
// |
|
49 |
class VMOperationQueue : public CHeapObj { |
|
50 |
private: |
|
51 |
enum Priorities { |
|
52 |
SafepointPriority, // Highest priority (operation executed at a safepoint) |
|
53 |
MediumPriority, // Medium priority |
|
54 |
nof_priorities |
|
55 |
}; |
|
56 |
||
57 |
// We maintain a doubled linked list, with explicit count. |
|
58 |
int _queue_length[nof_priorities]; |
|
59 |
int _queue_counter; |
|
60 |
VM_Operation* _queue [nof_priorities]; |
|
61 |
// we also allow the vmThread to register the ops it has drained so we |
|
62 |
// can scan them from oops_do |
|
63 |
VM_Operation* _drain_list; |
|
64 |
||
65 |
// Double-linked non-empty list insert. |
|
66 |
void insert(VM_Operation* q,VM_Operation* n); |
|
67 |
void unlink(VM_Operation* q); |
|
68 |
||
69 |
// Basic queue manipulation |
|
70 |
bool queue_empty (int prio); |
|
71 |
void queue_add_front (int prio, VM_Operation *op); |
|
72 |
void queue_add_back (int prio, VM_Operation *op); |
|
73 |
VM_Operation* queue_remove_front(int prio); |
|
74 |
void queue_oops_do(int queue, OopClosure* f); |
|
75 |
void drain_list_oops_do(OopClosure* f); |
|
76 |
VM_Operation* queue_drain(int prio); |
|
77 |
// lock-free query: may return the wrong answer but must not break |
|
78 |
bool queue_peek(int prio) { return _queue_length[prio] > 0; } |
|
79 |
||
80 |
public: |
|
81 |
VMOperationQueue(); |
|
82 |
||
83 |
// Highlevel operations. Encapsulates policy |
|
84 |
bool add(VM_Operation *op); |
|
85 |
VM_Operation* remove_next(); // Returns next or null |
|
86 |
VM_Operation* remove_next_at_safepoint_priority() { return queue_remove_front(SafepointPriority); } |
|
87 |
VM_Operation* drain_at_safepoint_priority() { return queue_drain(SafepointPriority); } |
|
88 |
void set_drain_list(VM_Operation* list) { _drain_list = list; } |
|
89 |
bool peek_at_safepoint_priority() { return queue_peek(SafepointPriority); } |
|
90 |
||
91 |
// GC support |
|
92 |
void oops_do(OopClosure* f); |
|
93 |
||
94 |
void verify_queue(int prio) PRODUCT_RETURN; |
|
95 |
}; |
|
96 |
||
97 |
||
98 |
// |
|
99 |
// A single VMThread (the primordial thread) spawns all other threads |
|
100 |
// and is itself used by other threads to offload heavy vm operations |
|
101 |
// like scavenge, garbage_collect etc. |
|
102 |
// |
|
103 |
||
4489
514173c9a0c2
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
3908
diff
changeset
|
104 |
class VMThread: public NamedThread { |
1 | 105 |
private: |
106 |
static ThreadPriority _current_priority; |
|
107 |
||
108 |
static bool _should_terminate; |
|
109 |
static bool _terminated; |
|
110 |
static Monitor * _terminate_lock; |
|
111 |
static PerfCounter* _perf_accumulated_vm_operation_time; |
|
112 |
||
113 |
void evaluate_operation(VM_Operation* op); |
|
114 |
public: |
|
115 |
// Constructor |
|
116 |
VMThread(); |
|
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 |
|
123 |
void loop(); |
|
124 |
||
125 |
// Called to stop the VM thread |
|
126 |
static void wait_for_vm_thread_exit(); |
|
127 |
static bool should_terminate() { return _should_terminate; } |
|
128 |
static bool is_terminated() { return _terminated == true; } |
|
129 |
||
130 |
// Execution of vm operation |
|
131 |
static void execute(VM_Operation* op); |
|
132 |
||
133 |
// Returns the current vm operation if any. |
|
134 |
static VM_Operation* vm_operation() { return _cur_vm_operation; } |
|
135 |
||
136 |
// Returns the single instance of VMThread. |
|
137 |
static VMThread* vm_thread() { return _vm_thread; } |
|
138 |
||
139 |
// GC support |
|
3908 | 140 |
void oops_do(OopClosure* f, CodeBlobClosure* cf); |
1 | 141 |
|
142 |
// Debugging |
|
143 |
void print_on(outputStream* st) const; |
|
144 |
void print() const { print_on(tty); } |
|
145 |
void verify(); |
|
146 |
||
147 |
// Performance measurement |
|
148 |
static PerfCounter* perf_accumulated_vm_operation_time() { return _perf_accumulated_vm_operation_time; } |
|
149 |
||
150 |
// Entry for starting vm thread |
|
151 |
virtual void run(); |
|
152 |
||
153 |
// Creations/Destructions |
|
154 |
static void create(); |
|
155 |
static void destroy(); |
|
156 |
||
157 |
private: |
|
158 |
// VM_Operation support |
|
159 |
static VM_Operation* _cur_vm_operation; // Current VM operation |
|
160 |
static VMOperationQueue* _vm_queue; // Queue (w/ policy) of VM operations |
|
161 |
||
162 |
// Pointer to single-instance of VM thread |
|
163 |
static VMThread* _vm_thread; |
|
164 |
}; |
|
7397 | 165 |
|
166 |
#endif // SHARE_VM_RUNTIME_VMTHREAD_HPP |